| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/bind.h" | 5 #include "ui/gl/gl_implementation.h" |
| 6 #include "ui/gl/gl_bindings.h" | 6 |
| 7 #include "ui/gl/gl_context_stub_with_extensions.h" | 7 #include "ui/gl/gl_context_stub_with_extensions.h" |
| 8 #include "ui/gl/gl_egl_api_implementation.h" | 8 #include "ui/gl/gl_egl_api_implementation.h" |
| 9 #include "ui/gl/gl_gl_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_osmesa.h" | 10 #include "ui/gl/gl_implementation_osmesa.h" |
| 12 #include "ui/gl/gl_osmesa_api_implementation.h" | 11 #include "ui/gl/gl_osmesa_api_implementation.h" |
| 13 #include "ui/ozone/public/ozone_platform.h" | |
| 14 #include "ui/ozone/public/surface_factory_ozone.h" | |
| 15 | 12 |
| 16 namespace gl { | 13 namespace gl { |
| 17 | 14 |
| 18 namespace { | |
| 19 | |
| 20 void GL_BINDING_CALL MarshalClearDepthToClearDepthf(GLclampd depth) { | |
| 21 glClearDepthf(static_cast<GLclampf>(depth)); | |
| 22 } | |
| 23 | |
| 24 void GL_BINDING_CALL MarshalDepthRangeToDepthRangef(GLclampd z_near, | |
| 25 GLclampd z_far) { | |
| 26 glDepthRangef(static_cast<GLclampf>(z_near), static_cast<GLclampf>(z_far)); | |
| 27 } | |
| 28 | |
| 29 } // namespace | |
| 30 | |
| 31 void GetAllowedGLImplementations(std::vector<GLImplementation>* impls) { | 15 void GetAllowedGLImplementations(std::vector<GLImplementation>* impls) { |
| 32 impls->push_back(kGLImplementationEGLGLES2); | 16 impls->push_back(kGLImplementationEGLGLES2); |
| 33 impls->push_back(kGLImplementationOSMesaGL); | 17 impls->push_back(kGLImplementationOSMesaGL); |
| 34 } | 18 } |
| 35 | 19 |
| 36 bool InitializeStaticGLBindings(GLImplementation implementation) { | |
| 37 // Prevent reinitialization with a different implementation. Once the gpu | |
| 38 // unit tests have initialized with kGLImplementationMock, we don't want to | |
| 39 // later switch to another GL implementation. | |
| 40 DCHECK_EQ(kGLImplementationNone, GetGLImplementation()); | |
| 41 ui::OzonePlatform::InitializeForGPU(); | |
| 42 | |
| 43 switch (implementation) { | |
| 44 case kGLImplementationOSMesaGL: | |
| 45 return InitializeStaticGLBindingsOSMesaGL(); | |
| 46 case kGLImplementationEGLGLES2: | |
| 47 if (!ui::OzonePlatform::GetInstance() | |
| 48 ->GetSurfaceFactoryOzone() | |
| 49 ->LoadEGLGLES2Bindings(base::Bind(&AddGLNativeLibrary), | |
| 50 base::Bind(&SetGLGetProcAddressProc))) | |
| 51 return false; | |
| 52 SetGLImplementation(kGLImplementationEGLGLES2); | |
| 53 InitializeStaticGLBindingsGL(); | |
| 54 InitializeStaticGLBindingsEGL(); | |
| 55 | |
| 56 // These two functions take single precision float rather than double | |
| 57 // precision float parameters in GLES. | |
| 58 ::gl::g_driver_gl.fn.glClearDepthFn = MarshalClearDepthToClearDepthf; | |
| 59 ::gl::g_driver_gl.fn.glDepthRangeFn = MarshalDepthRangeToDepthRangef; | |
| 60 break; | |
| 61 case kGLImplementationMockGL: { | |
| 62 SetGLImplementation(kGLImplementationMockGL); | |
| 63 InitializeStaticGLBindingsGL(); | |
| 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 InitializeDynamicGLBindings(GLImplementation implementation, | 20 bool InitializeDynamicGLBindings(GLImplementation implementation, |
| 76 GLContext* context) { | 21 GLContext* context) { |
| 77 switch (implementation) { | 22 switch (implementation) { |
| 78 case kGLImplementationOSMesaGL: | 23 case kGLImplementationOSMesaGL: |
| 79 case kGLImplementationEGLGLES2: | 24 case kGLImplementationEGLGLES2: |
| 80 InitializeDynamicGLBindingsGL(context); | 25 InitializeDynamicGLBindingsGL(context); |
| 81 break; | 26 break; |
| 82 case kGLImplementationMockGL: | 27 case kGLImplementationMockGL: |
| 83 if (!context) { | 28 if (!context) { |
| 84 scoped_refptr<GLContextStubWithExtensions> mock_context( | 29 scoped_refptr<GLContextStubWithExtensions> mock_context( |
| 85 new GLContextStubWithExtensions()); | 30 new GLContextStubWithExtensions()); |
| 86 mock_context->SetGLVersionString("3.0"); | 31 mock_context->SetGLVersionString("3.0"); |
| 87 InitializeDynamicGLBindingsGL(mock_context.get()); | 32 InitializeDynamicGLBindingsGL(mock_context.get()); |
| 88 } else { | 33 } else { |
| 89 InitializeDynamicGLBindingsGL(context); | 34 InitializeDynamicGLBindingsGL(context); |
| 90 } | 35 } |
| 91 break; | 36 break; |
| 92 default: | 37 default: |
| 93 return false; | 38 return false; |
| 94 } | 39 } |
| 95 | 40 |
| 96 return true; | 41 return true; |
| 97 } | 42 } |
| 98 | 43 |
| 99 void InitializeDebugGLBindings() { | |
| 100 InitializeDebugGLBindingsEGL(); | |
| 101 InitializeDebugGLBindingsGL(); | |
| 102 InitializeDebugGLBindingsOSMESA(); | |
| 103 } | |
| 104 | |
| 105 void ClearGLBindings() { | |
| 106 ClearGLBindingsEGL(); | |
| 107 ClearGLBindingsGL(); | |
| 108 ClearGLBindingsOSMESA(); | |
| 109 SetGLImplementation(kGLImplementationNone); | |
| 110 UnloadGLNativeLibraries(); | |
| 111 } | |
| 112 | |
| 113 bool GetGLWindowSystemBindingInfo(GLWindowSystemBindingInfo* info) { | 44 bool GetGLWindowSystemBindingInfo(GLWindowSystemBindingInfo* info) { |
| 114 switch (GetGLImplementation()) { | 45 switch (GetGLImplementation()) { |
| 115 case kGLImplementationEGLGLES2: | 46 case kGLImplementationEGLGLES2: |
| 116 return GetGLWindowSystemBindingInfoEGL(info); | 47 return GetGLWindowSystemBindingInfoEGL(info); |
| 117 default: | 48 default: |
| 118 return false; | 49 return false; |
| 119 } | 50 } |
| 120 return false; | 51 return false; |
| 121 } | 52 } |
| 122 | 53 |
| 123 } // namespace gl | 54 } // namespace gl |
| OLD | NEW |