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 bool InitializeStaticEGLInternal() { |
| 25 base::NativeLibrary gles_library = LoadLibraryAndPrintError("libGLESv2.so"); |
| 26 if (!gles_library) |
| 27 return false; |
| 28 base::NativeLibrary egl_library = LoadLibraryAndPrintError("libEGL.so"); |
| 29 if (!egl_library) { |
| 30 base::UnloadNativeLibrary(gles_library); |
| 31 return false; |
| 32 } |
| 33 |
| 34 GLGetProcAddressProc get_proc_address = |
| 35 reinterpret_cast<GLGetProcAddressProc>( |
| 36 base::GetFunctionPointerFromNativeLibrary(egl_library, |
| 37 "eglGetProcAddress")); |
| 38 if (!get_proc_address) { |
| 39 LOG(ERROR) << "eglGetProcAddress not found."; |
| 40 base::UnloadNativeLibrary(egl_library); |
| 41 base::UnloadNativeLibrary(gles_library); |
| 42 return false; |
| 43 } |
| 44 |
| 45 SetGLGetProcAddressProc(get_proc_address); |
| 46 AddGLNativeLibrary(egl_library); |
| 47 AddGLNativeLibrary(gles_library); |
| 48 SetGLImplementation(kGLImplementationEGLGLES2); |
| 49 |
| 50 InitializeStaticGLBindingsGL(); |
| 51 InitializeStaticGLBindingsEGL(); |
| 52 |
| 53 return true; |
| 54 } |
| 55 |
| 56 } // namespace |
| 57 |
14 bool InitializeGLOneOffPlatform() { | 58 bool InitializeGLOneOffPlatform() { |
15 switch (GetGLImplementation()) { | 59 switch (GetGLImplementation()) { |
16 case kGLImplementationEGLGLES2: | 60 case kGLImplementationEGLGLES2: |
17 if (!GLSurfaceEGL::InitializeOneOff()) { | 61 if (!GLSurfaceEGL::InitializeOneOff()) { |
18 LOG(ERROR) << "GLSurfaceEGL::InitializeOneOff failed."; | 62 LOG(ERROR) << "GLSurfaceEGL::InitializeOneOff failed."; |
19 return false; | 63 return false; |
20 } | 64 } |
21 return true; | 65 return true; |
22 default: | 66 default: |
23 return true; | 67 return true; |
24 } | 68 } |
25 } | 69 } |
26 | 70 |
| 71 bool InitializeStaticGLBindings(GLImplementation implementation) { |
| 72 // Prevent reinitialization with a different implementation. Once the gpu |
| 73 // unit tests have initialized with kGLImplementationMock, we don't want to |
| 74 // later switch to another GL implementation. |
| 75 DCHECK_EQ(kGLImplementationNone, GetGLImplementation()); |
| 76 |
| 77 switch (implementation) { |
| 78 case kGLImplementationEGLGLES2: |
| 79 return InitializeStaticEGLInternal(); |
| 80 case kGLImplementationOSMesaGL: |
| 81 return InitializeStaticGLBindingsOSMesaGL(); |
| 82 case kGLImplementationMockGL: |
| 83 SetGLImplementation(kGLImplementationMockGL); |
| 84 InitializeStaticGLBindingsGL(); |
| 85 return true; |
| 86 default: |
| 87 NOTREACHED(); |
| 88 } |
| 89 |
| 90 return false; |
| 91 } |
| 92 |
| 93 void InitializeDebugGLBindings() { |
| 94 InitializeDebugGLBindingsEGL(); |
| 95 InitializeDebugGLBindingsGL(); |
| 96 InitializeDebugGLBindingsOSMESA(); |
| 97 } |
| 98 |
| 99 void ClearGLBindingsPlatform() { |
| 100 ClearGLBindingsEGL(); |
| 101 ClearGLBindingsGL(); |
| 102 ClearGLBindingsOSMESA(); |
| 103 } |
| 104 |
27 } // namespace init | 105 } // namespace init |
28 } // namespace gl | 106 } // namespace gl |
OLD | NEW |