| 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_factory.h" | 5 #include "ui/gl/init/gl_factory.h" |
| 6 | 6 |
| 7 #include <string> |
| 8 #include <vector> |
| 9 |
| 10 #include "base/command_line.h" |
| 11 #include "base/logging.h" |
| 12 #include "base/trace_event/trace_event.h" |
| 7 #include "ui/gl/gl_context.h" | 13 #include "ui/gl/gl_context.h" |
| 8 #include "ui/gl/gl_share_group.h" | 14 #include "ui/gl/gl_share_group.h" |
| 9 #include "ui/gl/gl_surface.h" | 15 #include "ui/gl/gl_surface.h" |
| 16 #include "ui/gl/init/gl_initializer.h" |
| 10 | 17 |
| 11 namespace gl { | 18 namespace gl { |
| 12 namespace init { | 19 namespace init { |
| 13 | 20 |
| 14 // TODO(kylechar): This file should be replaced with a platform specific | 21 bool InitializeGLOneOff() { |
| 15 // version for X11, Ozone, Windows, Mac and Android. The implementation of each | 22 TRACE_EVENT0("gpu,startup", "gl::init::InitializeOneOff"); |
| 16 // factory function should be moved into that file and the original static | |
| 17 // methods should be removed from GLSurface and GLContext. This file can then | |
| 18 // be deleted. | |
| 19 | 23 |
| 20 bool InitializeGLOneOff() { | 24 DCHECK_EQ(kGLImplementationNone, GetGLImplementation()); |
| 21 return GLSurface::InitializeOneOff(); | 25 |
| 26 std::vector<GLImplementation> allowed_impls; |
| 27 GetAllowedGLImplementations(&allowed_impls); |
| 28 DCHECK(!allowed_impls.empty()); |
| 29 |
| 30 base::CommandLine* cmd = base::CommandLine::ForCurrentProcess(); |
| 31 |
| 32 // The default implementation is always the first one in list. |
| 33 GLImplementation impl = allowed_impls[0]; |
| 34 bool fallback_to_osmesa = false; |
| 35 if (cmd->HasSwitch(switches::kOverrideUseGLWithOSMesaForTests)) { |
| 36 impl = kGLImplementationOSMesaGL; |
| 37 } else if (cmd->HasSwitch(switches::kUseGL)) { |
| 38 std::string requested_implementation_name = |
| 39 cmd->GetSwitchValueASCII(switches::kUseGL); |
| 40 if (requested_implementation_name == "any") { |
| 41 fallback_to_osmesa = true; |
| 42 } else if (requested_implementation_name == |
| 43 kGLImplementationSwiftShaderName || |
| 44 requested_implementation_name == kGLImplementationANGLEName) { |
| 45 impl = kGLImplementationEGLGLES2; |
| 46 } else { |
| 47 impl = GetNamedGLImplementation(requested_implementation_name); |
| 48 if (!ContainsValue(allowed_impls, impl)) { |
| 49 LOG(ERROR) << "Requested GL implementation is not available."; |
| 50 return false; |
| 51 } |
| 52 } |
| 53 } |
| 54 |
| 55 bool gpu_service_logging = cmd->HasSwitch(switches::kEnableGPUServiceLogging); |
| 56 bool disable_gl_drawing = cmd->HasSwitch(switches::kDisableGLDrawingForTests); |
| 57 |
| 58 return InitializeGLOneOffImplementation( |
| 59 impl, fallback_to_osmesa, gpu_service_logging, disable_gl_drawing); |
| 22 } | 60 } |
| 23 | 61 |
| 62 bool InitializeGLOneOffImplementation(GLImplementation impl, |
| 63 bool fallback_to_osmesa, |
| 64 bool gpu_service_logging, |
| 65 bool disable_gl_drawing) { |
| 66 bool initialized = |
| 67 InitializeStaticGLBindings(impl) && InitializeGLOneOffPlatform(); |
| 68 if (!initialized && fallback_to_osmesa) { |
| 69 ClearGLBindings(); |
| 70 initialized = InitializeStaticGLBindings(kGLImplementationOSMesaGL) && |
| 71 InitializeGLOneOffPlatform(); |
| 72 } |
| 73 if (!initialized) |
| 74 ClearGLBindings(); |
| 75 |
| 76 if (initialized) { |
| 77 DVLOG(1) << "Using " << GetGLImplementationName(GetGLImplementation()) |
| 78 << " GL implementation."; |
| 79 if (gpu_service_logging) |
| 80 InitializeDebugGLBindings(); |
| 81 if (disable_gl_drawing) |
| 82 InitializeNullDrawGLBindings(); |
| 83 } |
| 84 return initialized; |
| 85 } |
| 86 |
| 87 // TODO(kylechar): The functions below should be replaced with a platform |
| 88 // specific version for X11, Ozone, Windows, Mac and Android. The implementation |
| 89 // of each function should be moved into a platform specific file and the |
| 90 // original static functions should be removed from GLSurface and GLContext. |
| 91 |
| 24 scoped_refptr<GLContext> CreateGLContext(GLShareGroup* share_group, | 92 scoped_refptr<GLContext> CreateGLContext(GLShareGroup* share_group, |
| 25 GLSurface* compatible_surface, | 93 GLSurface* compatible_surface, |
| 26 GpuPreference gpu_preference) { | 94 GpuPreference gpu_preference) { |
| 27 return GLContext::CreateGLContext(share_group, compatible_surface, | 95 return GLContext::CreateGLContext(share_group, compatible_surface, |
| 28 gpu_preference); | 96 gpu_preference); |
| 29 } | 97 } |
| 30 | 98 |
| 31 scoped_refptr<GLSurface> CreateViewGLSurface(gfx::AcceleratedWidget window) { | 99 scoped_refptr<GLSurface> CreateViewGLSurface(gfx::AcceleratedWidget window) { |
| 32 return GLSurface::CreateViewGLSurface(window); | 100 return GLSurface::CreateViewGLSurface(window); |
| 33 } | 101 } |
| 34 | 102 |
| 35 #if defined(USE_OZONE) | 103 #if defined(USE_OZONE) |
| 36 scoped_refptr<GLSurface> CreateSurfacelessViewGLSurface( | 104 scoped_refptr<GLSurface> CreateSurfacelessViewGLSurface( |
| 37 gfx::AcceleratedWidget window) { | 105 gfx::AcceleratedWidget window) { |
| 38 return GLSurface::CreateSurfacelessViewGLSurface(window); | 106 return GLSurface::CreateSurfacelessViewGLSurface(window); |
| 39 } | 107 } |
| 40 #endif // defined(USE_OZONE) | 108 #endif // defined(USE_OZONE) |
| 41 | 109 |
| 42 scoped_refptr<GLSurface> CreateOffscreenGLSurface(const gfx::Size& size) { | 110 scoped_refptr<GLSurface> CreateOffscreenGLSurface(const gfx::Size& size) { |
| 43 return GLSurface::CreateOffscreenGLSurface(size); | 111 return GLSurface::CreateOffscreenGLSurface(size); |
| 44 } | 112 } |
| 45 | 113 |
| 46 } // namespace init | 114 } // namespace init |
| 47 } // namespace gl | 115 } // namespace gl |
| OLD | NEW |