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