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 void GL_BINDING_CALL MarshalClearDepthToClearDepthf(GLclampd depth) { |
| 24 glClearDepthf(static_cast<GLclampf>(depth)); |
| 25 } |
| 26 |
| 27 void GL_BINDING_CALL MarshalDepthRangeToDepthRangef(GLclampd z_near, |
| 28 GLclampd z_far) { |
| 29 glDepthRangef(static_cast<GLclampf>(z_near), static_cast<GLclampf>(z_far)); |
| 30 } |
| 31 |
| 32 bool InitializeStaticEGLInternal() { |
| 33 auto surface_factory = |
| 34 ui::OzonePlatform::GetInstance()->GetSurfaceFactoryOzone(); |
| 35 if (!surface_factory->LoadEGLGLES2Bindings( |
| 36 base::Bind(&AddGLNativeLibrary), |
| 37 base::Bind(&SetGLGetProcAddressProc))) { |
| 38 return false; |
| 39 } |
| 40 |
| 41 SetGLImplementation(kGLImplementationEGLGLES2); |
| 42 InitializeStaticGLBindingsGL(); |
| 43 InitializeStaticGLBindingsEGL(); |
| 44 |
| 45 // These two functions take single precision float rather than double |
| 46 // precision float parameters in GLES. |
| 47 ::gl::g_driver_gl.fn.glClearDepthFn = MarshalClearDepthToClearDepthf; |
| 48 ::gl::g_driver_gl.fn.glDepthRangeFn = MarshalDepthRangeToDepthRangef; |
| 49 |
| 50 return true; |
| 51 } |
| 52 |
| 53 } // namespace |
| 54 |
14 bool InitializeGLOneOffPlatform() { | 55 bool InitializeGLOneOffPlatform() { |
15 switch (GetGLImplementation()) { | 56 switch (GetGLImplementation()) { |
16 case kGLImplementationEGLGLES2: | 57 case kGLImplementationEGLGLES2: |
17 if (!GLSurfaceEGL::InitializeOneOff()) { | 58 if (!GLSurfaceEGL::InitializeOneOff()) { |
18 LOG(ERROR) << "GLSurfaceEGL::InitializeOneOff failed."; | 59 LOG(ERROR) << "GLSurfaceEGL::InitializeOneOff failed."; |
19 return false; | 60 return false; |
20 } | 61 } |
21 return true; | 62 return true; |
22 case kGLImplementationOSMesaGL: | 63 case kGLImplementationOSMesaGL: |
23 case kGLImplementationMockGL: | 64 case kGLImplementationMockGL: |
24 return true; | 65 return true; |
25 default: | 66 default: |
26 return false; | 67 return false; |
27 } | 68 } |
28 } | 69 } |
29 | 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 ui::OzonePlatform::InitializeForGPU(); |
| 77 |
| 78 switch (implementation) { |
| 79 case kGLImplementationOSMesaGL: |
| 80 return InitializeStaticGLBindingsOSMesaGL(); |
| 81 case kGLImplementationEGLGLES2: |
| 82 return InitializeStaticEGLInternal(); |
| 83 case kGLImplementationMockGL: |
| 84 SetGLImplementation(kGLImplementationMockGL); |
| 85 InitializeStaticGLBindingsGL(); |
| 86 return true; |
| 87 default: |
| 88 NOTREACHED(); |
| 89 } |
| 90 |
| 91 return false; |
| 92 } |
| 93 |
| 94 void InitializeDebugGLBindings() { |
| 95 InitializeDebugGLBindingsEGL(); |
| 96 InitializeDebugGLBindingsGL(); |
| 97 InitializeDebugGLBindingsOSMESA(); |
| 98 } |
| 99 |
| 100 void ClearGLBindingsPlatform() { |
| 101 ClearGLBindingsEGL(); |
| 102 ClearGLBindingsGL(); |
| 103 ClearGLBindingsOSMESA(); |
| 104 } |
| 105 |
30 } // namespace init | 106 } // namespace init |
31 } // namespace gl | 107 } // namespace gl |
OLD | NEW |