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/bind.h" |
7 #include "base/logging.h" | 8 #include "base/logging.h" |
8 #include "ui/gl/gl_implementation.h" | 9 #include "ui/gl/gl_bindings.h" |
| 10 #include "ui/gl/gl_egl_api_implementation.h" |
| 11 #include "ui/gl/gl_gl_api_implementation.h" |
| 12 #include "ui/gl/gl_implementation_osmesa.h" |
| 13 #include "ui/gl/gl_osmesa_api_implementation.h" |
9 #include "ui/gl/gl_surface_egl.h" | 14 #include "ui/gl/gl_surface_egl.h" |
| 15 #include "ui/ozone/public/ozone_platform.h" |
| 16 #include "ui/ozone/public/surface_factory_ozone.h" |
10 | 17 |
11 namespace gl { | 18 namespace gl { |
12 namespace init { | 19 namespace init { |
13 | 20 |
| 21 namespace { |
| 22 |
| 23 bool InitializeStaticEGLInternal() { |
| 24 auto surface_factory = |
| 25 ui::OzonePlatform::GetInstance()->GetSurfaceFactoryOzone(); |
| 26 if (!surface_factory->LoadEGLGLES2Bindings( |
| 27 base::Bind(&AddGLNativeLibrary), |
| 28 base::Bind(&SetGLGetProcAddressProc))) { |
| 29 return false; |
| 30 } |
| 31 |
| 32 SetGLImplementation(kGLImplementationEGLGLES2); |
| 33 InitializeStaticGLBindingsGL(); |
| 34 InitializeStaticGLBindingsEGL(); |
| 35 |
| 36 return true; |
| 37 } |
| 38 |
| 39 } // namespace |
| 40 |
14 bool InitializeGLOneOffPlatform() { | 41 bool InitializeGLOneOffPlatform() { |
15 switch (GetGLImplementation()) { | 42 switch (GetGLImplementation()) { |
16 case kGLImplementationEGLGLES2: | 43 case kGLImplementationEGLGLES2: |
17 if (!GLSurfaceEGL::InitializeOneOff()) { | 44 if (!GLSurfaceEGL::InitializeOneOff()) { |
18 LOG(ERROR) << "GLSurfaceEGL::InitializeOneOff failed."; | 45 LOG(ERROR) << "GLSurfaceEGL::InitializeOneOff failed."; |
19 return false; | 46 return false; |
20 } | 47 } |
21 return true; | 48 return true; |
22 case kGLImplementationOSMesaGL: | 49 case kGLImplementationOSMesaGL: |
23 case kGLImplementationMockGL: | 50 case kGLImplementationMockGL: |
24 return true; | 51 return true; |
25 default: | 52 default: |
26 return false; | 53 return false; |
27 } | 54 } |
28 } | 55 } |
29 | 56 |
| 57 bool InitializeStaticGLBindings(GLImplementation implementation) { |
| 58 // Prevent reinitialization with a different implementation. Once the gpu |
| 59 // unit tests have initialized with kGLImplementationMock, we don't want to |
| 60 // later switch to another GL implementation. |
| 61 DCHECK_EQ(kGLImplementationNone, GetGLImplementation()); |
| 62 ui::OzonePlatform::InitializeForGPU(); |
| 63 |
| 64 switch (implementation) { |
| 65 case kGLImplementationOSMesaGL: |
| 66 return InitializeStaticGLBindingsOSMesaGL(); |
| 67 case kGLImplementationEGLGLES2: |
| 68 return InitializeStaticEGLInternal(); |
| 69 case kGLImplementationMockGL: |
| 70 SetGLImplementation(kGLImplementationMockGL); |
| 71 InitializeStaticGLBindingsGL(); |
| 72 return true; |
| 73 default: |
| 74 NOTREACHED(); |
| 75 } |
| 76 |
| 77 return false; |
| 78 } |
| 79 |
| 80 void InitializeDebugGLBindings() { |
| 81 InitializeDebugGLBindingsEGL(); |
| 82 InitializeDebugGLBindingsGL(); |
| 83 InitializeDebugGLBindingsOSMESA(); |
| 84 } |
| 85 |
| 86 void ClearGLBindingsPlatform() { |
| 87 ClearGLBindingsEGL(); |
| 88 ClearGLBindingsGL(); |
| 89 ClearGLBindingsOSMESA(); |
| 90 } |
| 91 |
30 } // namespace init | 92 } // namespace init |
31 } // namespace gl | 93 } // namespace gl |
OLD | NEW |