| 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/base_paths.h" | 5 #include "base/bind.h" |
| 6 #include "base/command_line.h" | |
| 7 #include "base/files/file_path.h" | |
| 8 #include "base/logging.h" | |
| 9 #include "base/native_library.h" | |
| 10 #include "ui/gl/gl_bindings.h" | 6 #include "ui/gl/gl_bindings.h" |
| 11 #include "ui/gl/gl_context_stub_with_extensions.h" | 7 #include "ui/gl/gl_context_stub_with_extensions.h" |
| 12 #include "ui/gl/gl_egl_api_implementation.h" | 8 #include "ui/gl/gl_egl_api_implementation.h" |
| 13 #include "ui/gl/gl_gl_api_implementation.h" | 9 #include "ui/gl/gl_gl_api_implementation.h" |
| 14 #include "ui/gl/gl_implementation.h" | 10 #include "ui/gl/gl_implementation.h" |
| 15 #include "ui/gl/gl_implementation_osmesa.h" | 11 #include "ui/gl/gl_implementation_osmesa.h" |
| 16 #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" |
| 17 | 15 |
| 18 namespace gfx { | 16 namespace gfx { |
| 19 | 17 |
| 20 namespace { | 18 namespace { |
| 21 | 19 |
| 22 void GL_BINDING_CALL MarshalClearDepthToClearDepthf(GLclampd depth) { | 20 void GL_BINDING_CALL MarshalClearDepthToClearDepthf(GLclampd depth) { |
| 23 glClearDepthf(static_cast<GLclampf>(depth)); | 21 glClearDepthf(static_cast<GLclampf>(depth)); |
| 24 } | 22 } |
| 25 | 23 |
| 26 void GL_BINDING_CALL MarshalDepthRangeToDepthRangef(GLclampd z_near, | 24 void GL_BINDING_CALL MarshalDepthRangeToDepthRangef(GLclampd z_near, |
| 27 GLclampd z_far) { | 25 GLclampd z_far) { |
| 28 glDepthRangef(static_cast<GLclampf>(z_near), static_cast<GLclampf>(z_far)); | 26 glDepthRangef(static_cast<GLclampf>(z_near), static_cast<GLclampf>(z_far)); |
| 29 } | 27 } |
| 30 | 28 |
| 31 } // namespace | 29 } // namespace |
| 32 | 30 |
| 33 void GetAllowedGLImplementations(std::vector<GLImplementation>* impls) { | 31 void GetAllowedGLImplementations(std::vector<GLImplementation>* impls) { |
| 34 impls->push_back(kGLImplementationEGLGLES2); | 32 impls->push_back(kGLImplementationEGLGLES2); |
| 35 impls->push_back(kGLImplementationOSMesaGL); | 33 impls->push_back(kGLImplementationOSMesaGL); |
| 36 } | 34 } |
| 37 | 35 |
| 38 bool InitializeStaticGLBindings(GLImplementation implementation) { | 36 bool InitializeStaticGLBindings(GLImplementation implementation) { |
| 39 // Prevent reinitialization with a different implementation. Once the gpu | 37 // Prevent reinitialization with a different implementation. Once the gpu |
| 40 // unit tests have initialized with kGLImplementationMock, we don't want to | 38 // unit tests have initialized with kGLImplementationMock, we don't want to |
| 41 // later switch to another GL implementation. | 39 // later switch to another GL implementation. |
| 42 DCHECK_EQ(kGLImplementationNone, GetGLImplementation()); | 40 DCHECK_EQ(kGLImplementationNone, GetGLImplementation()); |
| 41 ui::OzonePlatform::InitializeForGPU(); |
| 43 | 42 |
| 44 switch (implementation) { | 43 switch (implementation) { |
| 45 case kGLImplementationEGLGLES2: { | 44 case kGLImplementationOSMesaGL: |
| 46 base::NativeLibrary gles_library = | 45 return InitializeStaticGLBindingsOSMesaGL(); |
| 47 LoadLibraryAndPrintError("libGLESv2.so"); | 46 case kGLImplementationEGLGLES2: |
| 48 if (!gles_library) | 47 if (!ui::SurfaceFactoryOzone::GetInstance()->LoadEGLGLES2Bindings( |
| 48 base::Bind(&AddGLNativeLibrary), |
| 49 base::Bind(&SetGLGetProcAddressProc))) |
| 49 return false; | 50 return false; |
| 50 base::NativeLibrary egl_library = LoadLibraryAndPrintError("libEGL.so"); | |
| 51 if (!egl_library) { | |
| 52 base::UnloadNativeLibrary(gles_library); | |
| 53 return false; | |
| 54 } | |
| 55 | |
| 56 GLGetProcAddressProc get_proc_address = | |
| 57 reinterpret_cast<GLGetProcAddressProc>( | |
| 58 base::GetFunctionPointerFromNativeLibrary( | |
| 59 egl_library, "eglGetProcAddress")); | |
| 60 if (!get_proc_address) { | |
| 61 LOG(ERROR) << "eglGetProcAddress not found."; | |
| 62 base::UnloadNativeLibrary(egl_library); | |
| 63 base::UnloadNativeLibrary(gles_library); | |
| 64 return false; | |
| 65 } | |
| 66 | |
| 67 SetGLGetProcAddressProc(get_proc_address); | |
| 68 AddGLNativeLibrary(egl_library); | |
| 69 AddGLNativeLibrary(gles_library); | |
| 70 SetGLImplementation(kGLImplementationEGLGLES2); | 51 SetGLImplementation(kGLImplementationEGLGLES2); |
| 71 | |
| 72 InitializeStaticGLBindingsGL(); | 52 InitializeStaticGLBindingsGL(); |
| 73 InitializeStaticGLBindingsEGL(); | 53 InitializeStaticGLBindingsEGL(); |
| 74 | 54 |
| 75 // These two functions take single precision float rather than double | 55 // These two functions take single precision float rather than double |
| 76 // precision float parameters in GLES. | 56 // precision float parameters in GLES. |
| 77 ::gfx::g_driver_gl.fn.glClearDepthFn = MarshalClearDepthToClearDepthf; | 57 ::gfx::g_driver_gl.fn.glClearDepthFn = MarshalClearDepthToClearDepthf; |
| 78 ::gfx::g_driver_gl.fn.glDepthRangeFn = MarshalDepthRangeToDepthRangef; | 58 ::gfx::g_driver_gl.fn.glDepthRangeFn = MarshalDepthRangeToDepthRangef; |
| 79 break; | 59 break; |
| 80 } | |
| 81 case kGLImplementationOSMesaGL: | |
| 82 InitializeStaticGLBindingsOSMesaGL(); | |
| 83 break; | |
| 84 case kGLImplementationMockGL: { | 60 case kGLImplementationMockGL: { |
| 85 SetGLImplementation(kGLImplementationMockGL); | 61 SetGLImplementation(kGLImplementationMockGL); |
| 86 InitializeStaticGLBindingsGL(); | 62 InitializeStaticGLBindingsGL(); |
| 87 break; | 63 break; |
| 88 } | 64 } |
| 89 default: | 65 default: |
| 90 NOTIMPLEMENTED() << "InitializeStaticGLBindings on Android"; | 66 NOTIMPLEMENTED() |
| 67 << "Unsupported GL type for Ozone surface implementation"; |
| 91 return false; | 68 return false; |
| 92 } | 69 } |
| 93 | 70 |
| 94 return true; | 71 return true; |
| 95 } | 72 } |
| 96 | 73 |
| 97 bool InitializeDynamicGLBindings(GLImplementation implementation, | 74 bool InitializeDynamicGLBindings(GLImplementation implementation, |
| 98 GLContext* context) { | 75 GLContext* context) { |
| 99 switch (implementation) { | 76 switch (implementation) { |
| 77 case kGLImplementationOSMesaGL: |
| 78 InitializeDynamicGLBindingsGL(context); |
| 79 InitializeDynamicGLBindingsOSMESA(context); |
| 80 break; |
| 100 case kGLImplementationEGLGLES2: | 81 case kGLImplementationEGLGLES2: |
| 101 InitializeDynamicGLBindingsGL(context); | 82 InitializeDynamicGLBindingsGL(context); |
| 102 InitializeDynamicGLBindingsEGL(context); | 83 InitializeDynamicGLBindingsEGL(context); |
| 103 break; | 84 break; |
| 104 case kGLImplementationOSMesaGL: | |
| 105 InitializeDynamicGLBindingsGL(context); | |
| 106 InitializeDynamicGLBindingsOSMESA(context); | |
| 107 break; | |
| 108 case kGLImplementationMockGL: | 85 case kGLImplementationMockGL: |
| 109 if (!context) { | 86 if (!context) { |
| 110 scoped_refptr<GLContextStubWithExtensions> mock_context( | 87 scoped_refptr<GLContextStubWithExtensions> mock_context( |
| 111 new GLContextStubWithExtensions()); | 88 new GLContextStubWithExtensions()); |
| 112 mock_context->SetGLVersionString("opengl es 3.0"); | 89 mock_context->SetGLVersionString("3.0"); |
| 113 InitializeDynamicGLBindingsGL(mock_context.get()); | 90 InitializeDynamicGLBindingsGL(mock_context.get()); |
| 114 } else | 91 } else |
| 115 InitializeDynamicGLBindingsGL(context); | 92 InitializeDynamicGLBindingsGL(context); |
| 116 break; | 93 break; |
| 117 default: | 94 default: |
| 118 NOTREACHED() << "InitializeDynamicGLBindings on Android"; | |
| 119 return false; | 95 return false; |
| 120 } | 96 } |
| 121 | 97 |
| 122 return true; | 98 return true; |
| 123 } | 99 } |
| 124 | 100 |
| 125 void InitializeDebugGLBindings() { | 101 void InitializeDebugGLBindings() { |
| 126 InitializeDebugGLBindingsEGL(); | |
| 127 InitializeDebugGLBindingsGL(); | |
| 128 InitializeDebugGLBindingsOSMESA(); | |
| 129 } | 102 } |
| 130 | 103 |
| 131 void ClearGLBindings() { | 104 void ClearGLBindings() { |
| 132 ClearGLBindingsEGL(); | 105 ClearGLBindingsEGL(); |
| 133 ClearGLBindingsGL(); | 106 ClearGLBindingsGL(); |
| 134 ClearGLBindingsOSMESA(); | |
| 135 SetGLImplementation(kGLImplementationNone); | 107 SetGLImplementation(kGLImplementationNone); |
| 136 | |
| 137 UnloadGLNativeLibraries(); | 108 UnloadGLNativeLibraries(); |
| 138 } | 109 } |
| 139 | 110 |
| 140 bool GetGLWindowSystemBindingInfo(GLWindowSystemBindingInfo* info) { | 111 bool GetGLWindowSystemBindingInfo(GLWindowSystemBindingInfo* info) { |
| 141 switch (GetGLImplementation()) { | 112 switch (GetGLImplementation()) { |
| 142 case kGLImplementationEGLGLES2: | 113 case kGLImplementationEGLGLES2: |
| 143 return GetGLWindowSystemBindingInfoEGL(info); | 114 return GetGLWindowSystemBindingInfoEGL(info); |
| 144 default: | 115 default: |
| 145 return false; | 116 return false; |
| 146 } | 117 } |
| 147 return false; | 118 return false; |
| 148 } | 119 } |
| 149 | 120 |
| 150 } // namespace gfx | 121 } // namespace gfx |
| OLD | NEW |