Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/init/gl_initializer.h" | 5 #include "ui/gl/init/gl_initializer.h" |
| 6 | 6 |
| 7 #include "base/base_paths.h" | |
| 8 #include "base/command_line.h" | |
| 9 #include "base/files/file_path.h" | |
| 7 #include "base/logging.h" | 10 #include "base/logging.h" |
| 8 #include "ui/gl/gl_implementation.h" | 11 #include "base/native_library.h" |
| 12 #include "ui/gl/gl_bindings.h" | |
| 13 #include "ui/gl/gl_egl_api_implementation.h" | |
| 14 #include "ui/gl/gl_gl_api_implementation.h" | |
| 15 #include "ui/gl/gl_implementation_osmesa.h" | |
| 16 #include "ui/gl/gl_osmesa_api_implementation.h" | |
| 9 #include "ui/gl/gl_surface_egl.h" | 17 #include "ui/gl/gl_surface_egl.h" |
| 10 | 18 |
| 11 namespace gl { | 19 namespace gl { |
| 12 namespace init { | 20 namespace init { |
| 13 | 21 |
| 22 namespace { | |
| 23 | |
| 24 void GL_BINDING_CALL MarshalClearDepthToClearDepthf(GLclampd depth) { | |
| 25 glClearDepthf(static_cast<GLclampf>(depth)); | |
| 26 } | |
| 27 | |
| 28 void GL_BINDING_CALL MarshalDepthRangeToDepthRangef(GLclampd z_near, | |
| 29 GLclampd z_far) { | |
| 30 glDepthRangef(static_cast<GLclampf>(z_near), static_cast<GLclampf>(z_far)); | |
| 31 } | |
| 32 | |
| 33 bool InitializeStaticEGLInternal() { | |
| 34 base::NativeLibrary gles_library = LoadLibraryAndPrintError("libGLESv2.so"); | |
| 35 if (!gles_library) | |
| 36 return false; | |
| 37 base::NativeLibrary egl_library = LoadLibraryAndPrintError("libEGL.so"); | |
| 38 if (!egl_library) { | |
| 39 base::UnloadNativeLibrary(gles_library); | |
| 40 return false; | |
| 41 } | |
| 42 | |
| 43 GLGetProcAddressProc get_proc_address = | |
| 44 reinterpret_cast<GLGetProcAddressProc>( | |
| 45 base::GetFunctionPointerFromNativeLibrary(egl_library, | |
| 46 "eglGetProcAddress")); | |
| 47 if (!get_proc_address) { | |
| 48 LOG(ERROR) << "eglGetProcAddress not found."; | |
| 49 base::UnloadNativeLibrary(egl_library); | |
| 50 base::UnloadNativeLibrary(gles_library); | |
| 51 return false; | |
| 52 } | |
| 53 | |
| 54 SetGLGetProcAddressProc(get_proc_address); | |
| 55 AddGLNativeLibrary(egl_library); | |
| 56 AddGLNativeLibrary(gles_library); | |
| 57 SetGLImplementation(kGLImplementationEGLGLES2); | |
| 58 | |
| 59 InitializeStaticGLBindingsGL(); | |
| 60 InitializeStaticGLBindingsEGL(); | |
| 61 | |
| 62 // These two functions take single precision float rather than double | |
| 63 // precision float parameters in GLES. | |
| 64 ::gl::g_driver_gl.fn.glClearDepthFn = MarshalClearDepthToClearDepthf; | |
| 65 ::gl::g_driver_gl.fn.glDepthRangeFn = MarshalDepthRangeToDepthRangef; | |
|
piman
2016/06/24 19:13:21
nit: all the EGL platforms have to do this, and th
kylechar
2016/06/27 13:35:22
Good idea, done.
| |
| 66 | |
| 67 return true; | |
| 68 } | |
| 69 | |
| 70 } // namespace | |
| 71 | |
| 14 bool InitializeGLOneOffPlatform() { | 72 bool InitializeGLOneOffPlatform() { |
| 15 switch (GetGLImplementation()) { | 73 switch (GetGLImplementation()) { |
| 16 case kGLImplementationEGLGLES2: | 74 case kGLImplementationEGLGLES2: |
| 17 if (!GLSurfaceEGL::InitializeOneOff()) { | 75 if (!GLSurfaceEGL::InitializeOneOff()) { |
| 18 LOG(ERROR) << "GLSurfaceEGL::InitializeOneOff failed."; | 76 LOG(ERROR) << "GLSurfaceEGL::InitializeOneOff failed."; |
| 19 return false; | 77 return false; |
| 20 } | 78 } |
| 21 return true; | 79 return true; |
| 22 default: | 80 default: |
| 23 return true; | 81 return true; |
| 24 } | 82 } |
| 25 } | 83 } |
| 26 | 84 |
| 85 bool InitializeStaticGLBindings(GLImplementation implementation) { | |
| 86 // Prevent reinitialization with a different implementation. Once the gpu | |
| 87 // unit tests have initialized with kGLImplementationMock, we don't want to | |
| 88 // later switch to another GL implementation. | |
| 89 DCHECK_EQ(kGLImplementationNone, GetGLImplementation()); | |
| 90 | |
| 91 switch (implementation) { | |
| 92 case kGLImplementationEGLGLES2: | |
| 93 return InitializeStaticEGLInternal(); | |
| 94 case kGLImplementationOSMesaGL: | |
| 95 return InitializeStaticGLBindingsOSMesaGL(); | |
| 96 case kGLImplementationMockGL: | |
| 97 SetGLImplementation(kGLImplementationMockGL); | |
| 98 InitializeStaticGLBindingsGL(); | |
| 99 return true; | |
| 100 default: | |
| 101 NOTREACHED(); | |
| 102 } | |
| 103 | |
| 104 return false; | |
| 105 } | |
| 106 | |
| 107 void InitializeDebugGLBindings() { | |
| 108 InitializeDebugGLBindingsEGL(); | |
| 109 InitializeDebugGLBindingsGL(); | |
| 110 InitializeDebugGLBindingsOSMESA(); | |
| 111 } | |
| 112 | |
| 113 void ClearGLBindingsPlatform() { | |
| 114 ClearGLBindingsEGL(); | |
| 115 ClearGLBindingsGL(); | |
| 116 ClearGLBindingsOSMESA(); | |
| 117 } | |
| 118 | |
| 27 } // namespace init | 119 } // namespace init |
| 28 } // namespace gl | 120 } // namespace gl |
| OLD | NEW |