| 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 "ui/gl/gl_implementation.h" | 5 #include "base/bind.h" |
| 6 | 6 #include "ui/gl/gl_bindings.h" |
| 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" |
| 10 #include "ui/gl/gl_implementation_osmesa.h" | 11 #include "ui/gl/gl_implementation_osmesa.h" |
| 11 #include "ui/gl/gl_osmesa_api_implementation.h" | 12 #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" |
| 12 | 15 |
| 13 namespace gl { | 16 namespace gl { |
| 14 | 17 |
| 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 |
| 15 void GetAllowedGLImplementations(std::vector<GLImplementation>* impls) { | 31 void GetAllowedGLImplementations(std::vector<GLImplementation>* impls) { |
| 16 impls->push_back(kGLImplementationEGLGLES2); | 32 impls->push_back(kGLImplementationEGLGLES2); |
| 17 impls->push_back(kGLImplementationOSMesaGL); | 33 impls->push_back(kGLImplementationOSMesaGL); |
| 18 } | 34 } |
| 19 | 35 |
| 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 |
| 20 bool InitializeDynamicGLBindings(GLImplementation implementation, | 75 bool InitializeDynamicGLBindings(GLImplementation implementation, |
| 21 GLContext* context) { | 76 GLContext* context) { |
| 22 switch (implementation) { | 77 switch (implementation) { |
| 23 case kGLImplementationOSMesaGL: | 78 case kGLImplementationOSMesaGL: |
| 24 case kGLImplementationEGLGLES2: | 79 case kGLImplementationEGLGLES2: |
| 25 InitializeDynamicGLBindingsGL(context); | 80 InitializeDynamicGLBindingsGL(context); |
| 26 break; | 81 break; |
| 27 case kGLImplementationMockGL: | 82 case kGLImplementationMockGL: |
| 28 if (!context) { | 83 if (!context) { |
| 29 scoped_refptr<GLContextStubWithExtensions> mock_context( | 84 scoped_refptr<GLContextStubWithExtensions> mock_context( |
| 30 new GLContextStubWithExtensions()); | 85 new GLContextStubWithExtensions()); |
| 31 mock_context->SetGLVersionString("3.0"); | 86 mock_context->SetGLVersionString("3.0"); |
| 32 InitializeDynamicGLBindingsGL(mock_context.get()); | 87 InitializeDynamicGLBindingsGL(mock_context.get()); |
| 33 } else { | 88 } else { |
| 34 InitializeDynamicGLBindingsGL(context); | 89 InitializeDynamicGLBindingsGL(context); |
| 35 } | 90 } |
| 36 break; | 91 break; |
| 37 default: | 92 default: |
| 38 return false; | 93 return false; |
| 39 } | 94 } |
| 40 | 95 |
| 41 return true; | 96 return true; |
| 42 } | 97 } |
| 43 | 98 |
| 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 |
| 44 bool GetGLWindowSystemBindingInfo(GLWindowSystemBindingInfo* info) { | 113 bool GetGLWindowSystemBindingInfo(GLWindowSystemBindingInfo* info) { |
| 45 switch (GetGLImplementation()) { | 114 switch (GetGLImplementation()) { |
| 46 case kGLImplementationEGLGLES2: | 115 case kGLImplementationEGLGLES2: |
| 47 return GetGLWindowSystemBindingInfoEGL(info); | 116 return GetGLWindowSystemBindingInfoEGL(info); |
| 48 default: | 117 default: |
| 49 return false; | 118 return false; |
| 50 } | 119 } |
| 51 return false; | 120 return false; |
| 52 } | 121 } |
| 53 | 122 |
| 54 } // namespace gl | 123 } // namespace gl |
| OLD | NEW |