| 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" | |
| 10 #include "base/logging.h" | 7 #include "base/logging.h" |
| 11 #include "base/native_library.h" | 8 #include "ui/gl/gl_implementation.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" | |
| 17 #include "ui/gl/gl_surface_egl.h" | 9 #include "ui/gl/gl_surface_egl.h" |
| 18 | 10 |
| 19 namespace gl { | 11 namespace gl { |
| 20 namespace init { | 12 namespace init { |
| 21 | 13 |
| 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 | |
| 58 bool InitializeGLOneOffPlatform() { | 14 bool InitializeGLOneOffPlatform() { |
| 59 switch (GetGLImplementation()) { | 15 switch (GetGLImplementation()) { |
| 60 case kGLImplementationEGLGLES2: | 16 case kGLImplementationEGLGLES2: |
| 61 if (!GLSurfaceEGL::InitializeOneOff()) { | 17 if (!GLSurfaceEGL::InitializeOneOff()) { |
| 62 LOG(ERROR) << "GLSurfaceEGL::InitializeOneOff failed."; | 18 LOG(ERROR) << "GLSurfaceEGL::InitializeOneOff failed."; |
| 63 return false; | 19 return false; |
| 64 } | 20 } |
| 65 return true; | 21 return true; |
| 66 default: | 22 default: |
| 67 return true; | 23 return true; |
| 68 } | 24 } |
| 69 } | 25 } |
| 70 | 26 |
| 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 | |
| 105 } // namespace init | 27 } // namespace init |
| 106 } // namespace gl | 28 } // namespace gl |
| OLD | NEW |