1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "base/bind.h" 6 #include "ui/gfx/ozone/surface_factory_ozone.h" 7 #include "ui/gl/gl_bindings.h" 8 #include "ui/gl/gl_egl_api_implementation.h" 9 #include "ui/gl/gl_gl_api_implementation.h" 10 #include "ui/gl/gl_implementation.h" 11 #include "ui/gl/gl_implementation_linux.h" 12 #include "ui/gl/gl_osmesa_api_implementation.h" 13 #include "ui/ozone/ozone_platform.h" 14 15 namespace gfx { 16 17 namespace { 18 19 void GL_BINDING_CALL MarshalClearDepthToClearDepthf(GLclampd depth) { 20 glClearDepthf(static_cast<GLclampf>(depth)); 21 } 22 23 void GL_BINDING_CALL MarshalDepthRangeToDepthRangef(GLclampd z_near, 24 GLclampd z_far) { 25 glDepthRangef(static_cast<GLclampf>(z_near), static_cast<GLclampf>(z_far)); 26 } 27 28 } // namespace 29 30 void GetAllowedGLImplementations(std::vector<GLImplementation>* impls) { 31 impls->push_back(kGLImplementationEGLGLES2); 32 impls->push_back(kGLImplementationOSMesaGL); 33 } 34 35 bool InitializeGLBindings(GLImplementation implementation) { 36 // Prevent reinitialization with a different implementation. Once the gpu 37 // unit tests have initialized with kGLImplementationMock, we don't want to 38 // later switch to another GL implementation. 39 if (GetGLImplementation() != kGLImplementationNone) 40 return true; 41 42 switch (implementation) { 43 case kGLImplementationOSMesaGL: 44 return InitializeGLBindingsOSMesaGL(); 45 case kGLImplementationEGLGLES2: 46 ui::OzonePlatform::Initialize(); 47 if (!gfx::SurfaceFactoryOzone::GetInstance()->LoadEGLGLES2Bindings( 48 base::Bind(&AddGLNativeLibrary), 49 base::Bind(&SetGLGetProcAddressProc))) 50 return false; 51 SetGLImplementation(kGLImplementationEGLGLES2); 52 InitializeGLBindingsGL(); 53 InitializeGLBindingsEGL(); 54 55 // These two functions take single precision float rather than double 56 // precision float parameters in GLES. 57 ::gfx::g_driver_gl.fn.glClearDepthFn = MarshalClearDepthToClearDepthf; 58 ::gfx::g_driver_gl.fn.glDepthRangeFn = MarshalDepthRangeToDepthRangef; 59 break; 60 case kGLImplementationMockGL: { 61 SetGLGetProcAddressProc(GetMockGLProcAddress); 62 SetGLImplementation(kGLImplementationMockGL); 63 InitializeGLBindingsGL(); 64 break; 65 } 66 default: 67 NOTIMPLEMENTED() 68 << "Unsupported GL type for Ozone surface implementation"; 69 return false; 70 } 71 72 return true; 73 } 74 75 bool InitializeGLExtensionBindings(GLImplementation implementation, 76 GLContext* context) { 77 switch (implementation) { 78 case kGLImplementationOSMesaGL: 79 InitializeGLExtensionBindingsGL(context); 80 InitializeGLExtensionBindingsOSMESA(context); 81 break; 82 case kGLImplementationEGLGLES2: 83 InitializeGLExtensionBindingsGL(context); 84 InitializeGLExtensionBindingsEGL(context); 85 break; 86 case kGLImplementationMockGL: 87 InitializeGLExtensionBindingsGL(context); 88 break; 89 default: 90 return false; 91 } 92 93 return true; 94 } 95 96 void InitializeDebugGLBindings() { 97 } 98 99 void ClearGLBindings() { 100 ClearGLBindingsEGL(); 101 ClearGLBindingsGL(); 102 SetGLImplementation(kGLImplementationNone); 103 UnloadGLNativeLibraries(); 104 } 105 106 bool GetGLWindowSystemBindingInfo(GLWindowSystemBindingInfo* info) { 107 switch (GetGLImplementation()) { 108 case kGLImplementationEGLGLES2: 109 return GetGLWindowSystemBindingInfoEGL(info); 110 default: 111 return false; 112 } 113 return false; 114 } 115 116 } // namespace gfx 117