OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/gl_surface.h" | 5 #include "ui/gl/gl_surface.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
13 #include "base/threading/thread_local.h" | 13 #include "base/threading/thread_local.h" |
14 #include "base/trace_event/trace_event.h" | 14 #include "base/trace_event/trace_event.h" |
15 #include "ui/gfx/swap_result.h" | 15 #include "ui/gfx/swap_result.h" |
16 #include "ui/gl/gl_context.h" | 16 #include "ui/gl/gl_context.h" |
17 #include "ui/gl/gl_implementation.h" | 17 #include "ui/gl/gl_implementation.h" |
18 #include "ui/gl/gl_switches.h" | 18 #include "ui/gl/gl_switches.h" |
19 | 19 |
20 namespace gl { | 20 namespace gl { |
21 | 21 |
22 namespace { | 22 namespace { |
23 base::LazyInstance<base::ThreadLocalPointer<GLSurface> >::Leaky | 23 base::LazyInstance<base::ThreadLocalPointer<GLSurface> >::Leaky |
24 current_surface_ = LAZY_INSTANCE_INITIALIZER; | 24 current_surface_ = LAZY_INSTANCE_INITIALIZER; |
25 } // namespace | 25 } // namespace |
26 | 26 |
27 // static | |
28 bool GLSurface::InitializeOneOff() { | |
29 DCHECK_EQ(kGLImplementationNone, GetGLImplementation()); | |
30 | |
31 TRACE_EVENT0("gpu,startup", "GLSurface::InitializeOneOff"); | |
32 | |
33 std::vector<GLImplementation> allowed_impls; | |
34 GetAllowedGLImplementations(&allowed_impls); | |
35 DCHECK(!allowed_impls.empty()); | |
36 | |
37 base::CommandLine* cmd = base::CommandLine::ForCurrentProcess(); | |
38 | |
39 // The default implementation is always the first one in list. | |
40 GLImplementation impl = allowed_impls[0]; | |
41 bool fallback_to_osmesa = false; | |
42 if (cmd->HasSwitch(switches::kOverrideUseGLWithOSMesaForTests)) { | |
43 impl = kGLImplementationOSMesaGL; | |
44 } else if (cmd->HasSwitch(switches::kUseGL)) { | |
45 std::string requested_implementation_name = | |
46 cmd->GetSwitchValueASCII(switches::kUseGL); | |
47 if (requested_implementation_name == "any") { | |
48 fallback_to_osmesa = true; | |
49 } else if (requested_implementation_name == | |
50 kGLImplementationSwiftShaderName || | |
51 requested_implementation_name == kGLImplementationANGLEName) { | |
52 impl = kGLImplementationEGLGLES2; | |
53 } else { | |
54 impl = GetNamedGLImplementation(requested_implementation_name); | |
55 if (!ContainsValue(allowed_impls, impl)) { | |
56 LOG(ERROR) << "Requested GL implementation is not available."; | |
57 return false; | |
58 } | |
59 } | |
60 } | |
61 | |
62 bool gpu_service_logging = cmd->HasSwitch(switches::kEnableGPUServiceLogging); | |
63 bool disable_gl_drawing = cmd->HasSwitch(switches::kDisableGLDrawingForTests); | |
64 | |
65 return InitializeOneOffImplementation( | |
66 impl, fallback_to_osmesa, gpu_service_logging, disable_gl_drawing); | |
67 } | |
68 | |
69 // static | |
70 bool GLSurface::InitializeOneOffImplementation(GLImplementation impl, | |
71 bool fallback_to_osmesa, | |
72 bool gpu_service_logging, | |
73 bool disable_gl_drawing) { | |
74 bool initialized = | |
75 InitializeStaticGLBindings(impl) && InitializeOneOffInternal(); | |
76 if (!initialized && fallback_to_osmesa) { | |
77 ClearGLBindings(); | |
78 initialized = InitializeStaticGLBindings(kGLImplementationOSMesaGL) && | |
79 InitializeOneOffInternal(); | |
80 } | |
81 if (!initialized) | |
82 ClearGLBindings(); | |
83 | |
84 if (initialized) { | |
85 DVLOG(1) << "Using " | |
86 << GetGLImplementationName(GetGLImplementation()) | |
87 << " GL implementation."; | |
88 if (gpu_service_logging) | |
89 InitializeDebugGLBindings(); | |
90 if (disable_gl_drawing) | |
91 InitializeNullDrawGLBindings(); | |
92 } | |
93 return initialized; | |
94 } | |
95 | |
96 GLSurface::GLSurface() {} | 27 GLSurface::GLSurface() {} |
97 | 28 |
98 bool GLSurface::Initialize() { | 29 bool GLSurface::Initialize() { |
99 return Initialize(SURFACE_DEFAULT); | 30 return Initialize(SURFACE_DEFAULT); |
100 } | 31 } |
101 | 32 |
102 bool GLSurface::Initialize(GLSurface::Format format) { | 33 bool GLSurface::Initialize(GLSurface::Format format) { |
103 return true; | 34 return true; |
104 } | 35 } |
105 | 36 |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 return surface_->FlipsVertically(); | 327 return surface_->FlipsVertically(); |
397 } | 328 } |
398 | 329 |
399 bool GLSurfaceAdapter::BuffersFlipped() const { | 330 bool GLSurfaceAdapter::BuffersFlipped() const { |
400 return surface_->BuffersFlipped(); | 331 return surface_->BuffersFlipped(); |
401 } | 332 } |
402 | 333 |
403 GLSurfaceAdapter::~GLSurfaceAdapter() {} | 334 GLSurfaceAdapter::~GLSurfaceAdapter() {} |
404 | 335 |
405 } // namespace gl | 336 } // namespace gl |
OLD | NEW |