OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ui/gl/init/gl_initializer.h" |
| 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" |
| 13 #include "ui/gl/gl_surface.h" |
| 14 #include "ui/gl/init/gl_factory.h" |
| 15 |
| 16 namespace gl { |
| 17 namespace init { |
| 18 |
| 19 bool InitializeGLOneOff() { |
| 20 TRACE_EVENT0("gpu,startup", "gl::init::InitializeOneOff"); |
| 21 |
| 22 DCHECK_EQ(kGLImplementationNone, GetGLImplementation()); |
| 23 |
| 24 std::vector<GLImplementation> allowed_impls; |
| 25 GetAllowedGLImplementations(&allowed_impls); |
| 26 DCHECK(!allowed_impls.empty()); |
| 27 |
| 28 base::CommandLine* cmd = base::CommandLine::ForCurrentProcess(); |
| 29 |
| 30 // The default implementation is always the first one in list. |
| 31 GLImplementation impl = allowed_impls[0]; |
| 32 bool fallback_to_osmesa = false; |
| 33 if (cmd->HasSwitch(switches::kOverrideUseGLWithOSMesaForTests)) { |
| 34 impl = kGLImplementationOSMesaGL; |
| 35 } else if (cmd->HasSwitch(switches::kUseGL)) { |
| 36 std::string requested_implementation_name = |
| 37 cmd->GetSwitchValueASCII(switches::kUseGL); |
| 38 if (requested_implementation_name == "any") { |
| 39 fallback_to_osmesa = true; |
| 40 } else if (requested_implementation_name == |
| 41 kGLImplementationSwiftShaderName || |
| 42 requested_implementation_name == kGLImplementationANGLEName) { |
| 43 impl = kGLImplementationEGLGLES2; |
| 44 } else { |
| 45 impl = GetNamedGLImplementation(requested_implementation_name); |
| 46 if (!ContainsValue(allowed_impls, impl)) { |
| 47 LOG(ERROR) << "Requested GL implementation is not available."; |
| 48 return false; |
| 49 } |
| 50 } |
| 51 } |
| 52 |
| 53 bool gpu_service_logging = cmd->HasSwitch(switches::kEnableGPUServiceLogging); |
| 54 bool disable_gl_drawing = cmd->HasSwitch(switches::kDisableGLDrawingForTests); |
| 55 |
| 56 return GLInitializer::InitializeOneOffImplementation( |
| 57 impl, fallback_to_osmesa, gpu_service_logging, disable_gl_drawing); |
| 58 } |
| 59 |
| 60 // static |
| 61 bool GLInitializer::InitializeOneOffImplementation(GLImplementation impl, |
| 62 bool fallback_to_osmesa, |
| 63 bool gpu_service_logging, |
| 64 bool disable_gl_drawing) { |
| 65 bool initialized = |
| 66 InitializeStaticGLBindings(impl) && InitializeOneOffPlatform(); |
| 67 if (!initialized && fallback_to_osmesa) { |
| 68 ClearGLBindings(); |
| 69 initialized = InitializeStaticGLBindings(kGLImplementationOSMesaGL) && |
| 70 InitializeOneOffPlatform(); |
| 71 } |
| 72 if (!initialized) |
| 73 ClearGLBindings(); |
| 74 |
| 75 if (initialized) { |
| 76 DVLOG(1) << "Using " << GetGLImplementationName(GetGLImplementation()) |
| 77 << " GL implementation."; |
| 78 if (gpu_service_logging) |
| 79 InitializeDebugGLBindings(); |
| 80 if (disable_gl_drawing) |
| 81 InitializeNullDrawGLBindings(); |
| 82 } |
| 83 return initialized; |
| 84 } |
| 85 |
| 86 } // namespace init |
| 87 } // namespace gl |
OLD | NEW |