| 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/base_paths.h" |
| 6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
| 7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/native_library.h" | 9 #include "base/native_library.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| 11 #include "ui/gl/gl_bindings.h" | 11 #include "ui/gl/gl_bindings.h" |
| 12 #include "ui/gl/gl_context_stub_with_extensions.h" | 12 #include "ui/gl/gl_context_stub_with_extensions.h" |
| 13 #include "ui/gl/gl_egl_api_implementation.h" | 13 #include "ui/gl/gl_egl_api_implementation.h" |
| 14 #include "ui/gl/gl_gl_api_implementation.h" | 14 #include "ui/gl/gl_gl_api_implementation.h" |
| 15 #include "ui/gl/gl_implementation.h" | 15 #include "ui/gl/gl_implementation.h" |
| 16 #include "ui/gl/gl_implementation_osmesa.h" |
| 16 #include "ui/gl/gl_osmesa_api_implementation.h" | 17 #include "ui/gl/gl_osmesa_api_implementation.h" |
| 17 | 18 |
| 18 namespace gfx { | 19 namespace gfx { |
| 19 | 20 |
| 20 namespace { | 21 namespace { |
| 21 | 22 |
| 22 void GL_BINDING_CALL MarshalClearDepthToClearDepthf(GLclampd depth) { | 23 void GL_BINDING_CALL MarshalClearDepthToClearDepthf(GLclampd depth) { |
| 23 glClearDepthf(static_cast<GLclampf>(depth)); | 24 glClearDepthf(static_cast<GLclampf>(depth)); |
| 24 } | 25 } |
| 25 | 26 |
| 26 void GL_BINDING_CALL MarshalDepthRangeToDepthRangef(GLclampd z_near, | 27 void GL_BINDING_CALL MarshalDepthRangeToDepthRangef(GLclampd z_near, |
| 27 GLclampd z_far) { | 28 GLclampd z_far) { |
| 28 glDepthRangef(static_cast<GLclampf>(z_near), static_cast<GLclampf>(z_far)); | 29 glDepthRangef(static_cast<GLclampf>(z_near), static_cast<GLclampf>(z_far)); |
| 29 } | 30 } |
| 30 | 31 |
| 31 base::NativeLibrary LoadLibrary(const base::FilePath& filename) { | |
| 32 std::string error; | |
| 33 base::NativeLibrary library = base::LoadNativeLibrary(filename, &error); | |
| 34 if (!library) { | |
| 35 DVLOG(1) << "Failed to load " << filename.MaybeAsASCII() << ": " << error; | |
| 36 return NULL; | |
| 37 } | |
| 38 return library; | |
| 39 } | |
| 40 | |
| 41 base::NativeLibrary LoadLibrary(const char* filename) { | |
| 42 return LoadLibrary(base::FilePath(filename)); | |
| 43 } | |
| 44 | |
| 45 } // namespace | 32 } // namespace |
| 46 | 33 |
| 47 void GetAllowedGLImplementations(std::vector<GLImplementation>* impls) { | 34 void GetAllowedGLImplementations(std::vector<GLImplementation>* impls) { |
| 48 impls->push_back(kGLImplementationEGLGLES2); | 35 impls->push_back(kGLImplementationEGLGLES2); |
| 36 impls->push_back(kGLImplementationOSMesaGL); |
| 49 } | 37 } |
| 50 | 38 |
| 51 bool InitializeStaticGLBindings(GLImplementation implementation) { | 39 bool InitializeStaticGLBindings(GLImplementation implementation) { |
| 52 // Prevent reinitialization with a different implementation. Once the gpu | 40 // Prevent reinitialization with a different implementation. Once the gpu |
| 53 // unit tests have initialized with kGLImplementationMock, we don't want to | 41 // unit tests have initialized with kGLImplementationMock, we don't want to |
| 54 // later switch to another GL implementation. | 42 // later switch to another GL implementation. |
| 55 DCHECK_EQ(kGLImplementationNone, GetGLImplementation()); | 43 DCHECK_EQ(kGLImplementationNone, GetGLImplementation()); |
| 56 | 44 |
| 57 switch (implementation) { | 45 switch (implementation) { |
| 58 case kGLImplementationEGLGLES2: { | 46 case kGLImplementationEGLGLES2: { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 86 | 74 |
| 87 InitializeStaticGLBindingsGL(); | 75 InitializeStaticGLBindingsGL(); |
| 88 InitializeStaticGLBindingsEGL(); | 76 InitializeStaticGLBindingsEGL(); |
| 89 | 77 |
| 90 // These two functions take single precision float rather than double | 78 // These two functions take single precision float rather than double |
| 91 // precision float parameters in GLES. | 79 // precision float parameters in GLES. |
| 92 ::gfx::g_driver_gl.fn.glClearDepthFn = MarshalClearDepthToClearDepthf; | 80 ::gfx::g_driver_gl.fn.glClearDepthFn = MarshalClearDepthToClearDepthf; |
| 93 ::gfx::g_driver_gl.fn.glDepthRangeFn = MarshalDepthRangeToDepthRangef; | 81 ::gfx::g_driver_gl.fn.glDepthRangeFn = MarshalDepthRangeToDepthRangef; |
| 94 break; | 82 break; |
| 95 } | 83 } |
| 84 case kGLImplementationOSMesaGL: |
| 85 InitializeStaticGLBindingsOSMesaGL(); |
| 86 break; |
| 96 case kGLImplementationMockGL: { | 87 case kGLImplementationMockGL: { |
| 97 SetGLImplementation(kGLImplementationMockGL); | 88 SetGLImplementation(kGLImplementationMockGL); |
| 98 InitializeStaticGLBindingsGL(); | 89 InitializeStaticGLBindingsGL(); |
| 99 break; | 90 break; |
| 100 } | 91 } |
| 101 default: | 92 default: |
| 102 NOTIMPLEMENTED() << "InitializeStaticGLBindings on Android"; | 93 NOTIMPLEMENTED() << "InitializeStaticGLBindings on Android"; |
| 103 return false; | 94 return false; |
| 104 } | 95 } |
| 105 | 96 |
| 106 return true; | 97 return true; |
| 107 } | 98 } |
| 108 | 99 |
| 109 bool InitializeDynamicGLBindings(GLImplementation implementation, | 100 bool InitializeDynamicGLBindings(GLImplementation implementation, |
| 110 GLContext* context) { | 101 GLContext* context) { |
| 111 switch (implementation) { | 102 switch (implementation) { |
| 112 case kGLImplementationEGLGLES2: | 103 case kGLImplementationEGLGLES2: |
| 113 InitializeDynamicGLBindingsGL(context); | 104 InitializeDynamicGLBindingsGL(context); |
| 114 InitializeDynamicGLBindingsEGL(context); | 105 InitializeDynamicGLBindingsEGL(context); |
| 115 break; | 106 break; |
| 107 case kGLImplementationOSMesaGL: |
| 108 InitializeDynamicGLBindingsGL(context); |
| 109 InitializeDynamicGLBindingsOSMESA(context); |
| 110 break; |
| 116 case kGLImplementationMockGL: | 111 case kGLImplementationMockGL: |
| 117 if (!context) { | 112 if (!context) { |
| 118 scoped_refptr<GLContextStubWithExtensions> mock_context( | 113 scoped_refptr<GLContextStubWithExtensions> mock_context( |
| 119 new GLContextStubWithExtensions()); | 114 new GLContextStubWithExtensions()); |
| 120 mock_context->SetGLVersionString("opengl es 3.0"); | 115 mock_context->SetGLVersionString("opengl es 3.0"); |
| 121 InitializeDynamicGLBindingsGL(mock_context.get()); | 116 InitializeDynamicGLBindingsGL(mock_context.get()); |
| 122 } else | 117 } else |
| 123 InitializeDynamicGLBindingsGL(context); | 118 InitializeDynamicGLBindingsGL(context); |
| 124 break; | 119 break; |
| 125 default: | 120 default: |
| 126 NOTREACHED() << "InitializeDynamicGLBindings on Android"; | 121 NOTREACHED() << "InitializeDynamicGLBindings on Android"; |
| 127 return false; | 122 return false; |
| 128 } | 123 } |
| 129 | 124 |
| 130 return true; | 125 return true; |
| 131 } | 126 } |
| 132 | 127 |
| 133 void InitializeDebugGLBindings() { | 128 void InitializeDebugGLBindings() { |
| 134 InitializeDebugGLBindingsEGL(); | 129 InitializeDebugGLBindingsEGL(); |
| 135 InitializeDebugGLBindingsGL(); | 130 InitializeDebugGLBindingsGL(); |
| 131 InitializeDebugGLBindingsOSMESA(); |
| 136 } | 132 } |
| 137 | 133 |
| 138 void ClearGLBindings() { | 134 void ClearGLBindings() { |
| 139 ClearGLBindingsEGL(); | 135 ClearGLBindingsEGL(); |
| 140 ClearGLBindingsGL(); | 136 ClearGLBindingsGL(); |
| 137 ClearGLBindingsOSMESA(); |
| 141 SetGLImplementation(kGLImplementationNone); | 138 SetGLImplementation(kGLImplementationNone); |
| 142 | 139 |
| 143 UnloadGLNativeLibraries(); | 140 UnloadGLNativeLibraries(); |
| 144 } | 141 } |
| 145 | 142 |
| 146 bool GetGLWindowSystemBindingInfo(GLWindowSystemBindingInfo* info) { | 143 bool GetGLWindowSystemBindingInfo(GLWindowSystemBindingInfo* info) { |
| 147 switch (GetGLImplementation()) { | 144 switch (GetGLImplementation()) { |
| 148 case kGLImplementationEGLGLES2: | 145 case kGLImplementationEGLGLES2: |
| 149 return GetGLWindowSystemBindingInfoEGL(info); | 146 return GetGLWindowSystemBindingInfoEGL(info); |
| 150 default: | 147 default: |
| 151 return false; | 148 return false; |
| 152 } | 149 } |
| 153 return false; | 150 return false; |
| 154 } | 151 } |
| 155 | 152 |
| 156 } // namespace gfx | 153 } // namespace gfx |
| OLD | NEW |