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