| 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" | |
| 8 #include "base/logging.h" | 7 #include "base/logging.h" |
| 9 #include "ui/gl/gl_bindings.h" | 8 #include "ui/gl/gl_implementation.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" | |
| 14 #include "ui/gl/gl_surface_egl.h" | 9 #include "ui/gl/gl_surface_egl.h" |
| 15 #include "ui/ozone/public/ozone_platform.h" | |
| 16 #include "ui/ozone/public/surface_factory_ozone.h" | |
| 17 | 10 |
| 18 namespace gl { | 11 namespace gl { |
| 19 namespace init { | 12 namespace init { |
| 20 | 13 |
| 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 | |
| 41 bool InitializeGLOneOffPlatform() { | 14 bool InitializeGLOneOffPlatform() { |
| 42 switch (GetGLImplementation()) { | 15 switch (GetGLImplementation()) { |
| 43 case kGLImplementationEGLGLES2: | 16 case kGLImplementationEGLGLES2: |
| 44 if (!GLSurfaceEGL::InitializeOneOff()) { | 17 if (!GLSurfaceEGL::InitializeOneOff()) { |
| 45 LOG(ERROR) << "GLSurfaceEGL::InitializeOneOff failed."; | 18 LOG(ERROR) << "GLSurfaceEGL::InitializeOneOff failed."; |
| 46 return false; | 19 return false; |
| 47 } | 20 } |
| 48 return true; | 21 return true; |
| 49 case kGLImplementationOSMesaGL: | 22 case kGLImplementationOSMesaGL: |
| 50 case kGLImplementationMockGL: | 23 case kGLImplementationMockGL: |
| 51 return true; | 24 return true; |
| 52 default: | 25 default: |
| 53 return false; | 26 return false; |
| 54 } | 27 } |
| 55 } | 28 } |
| 56 | 29 |
| 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 | |
| 92 } // namespace init | 30 } // namespace init |
| 93 } // namespace gl | 31 } // namespace gl |
| OLD | NEW |