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 <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/debug/trace_event.h" | 11 #include "base/debug/trace_event.h" |
12 #include "base/lazy_instance.h" | 12 #include "base/lazy_instance.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/threading/thread_local.h" | 14 #include "base/threading/thread_local.h" |
15 #include "ui/gl/gl_context.h" | 15 #include "ui/gl/gl_context.h" |
16 #include "ui/gl/gl_implementation.h" | 16 #include "ui/gl/gl_implementation.h" |
17 #include "ui/gl/gl_switches.h" | |
17 | 18 |
18 namespace gfx { | 19 namespace gfx { |
19 | 20 |
20 namespace { | 21 namespace { |
21 base::LazyInstance<base::ThreadLocalPointer<GLSurface> >::Leaky | 22 base::LazyInstance<base::ThreadLocalPointer<GLSurface> >::Leaky |
22 current_surface_ = LAZY_INSTANCE_INITIALIZER; | 23 current_surface_ = LAZY_INSTANCE_INITIALIZER; |
23 } // namespace | 24 } // namespace |
24 | 25 |
25 // static | 26 // static |
26 bool GLSurface::InitializeOneOff() { | 27 bool GLSurface::InitializeOneOff() { |
27 static bool initialized = false; | 28 DCHECK_EQ(kGLImplementationNone, GetGLImplementation()); |
28 if (initialized) | |
29 return true; | |
30 | 29 |
31 TRACE_EVENT0("gpu", "GLSurface::InitializeOneOff"); | 30 TRACE_EVENT0("gpu", "GLSurface::InitializeOneOff"); |
32 | 31 |
33 std::vector<GLImplementation> allowed_impls; | 32 std::vector<GLImplementation> allowed_impls; |
34 GetAllowedGLImplementations(&allowed_impls); | 33 GetAllowedGLImplementations(&allowed_impls); |
35 DCHECK(!allowed_impls.empty()); | 34 DCHECK(!allowed_impls.empty()); |
36 | 35 |
37 // The default implementation is always the first one in list. | 36 // The default implementation is always the first one in list. |
38 GLImplementation impl = allowed_impls[0]; | 37 GLImplementation impl = allowed_impls[0]; |
39 bool fallback_to_osmesa = false; | 38 bool fallback_to_osmesa = false; |
40 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kUseGL)) { | 39 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kUseGL)) { |
41 std::string requested_implementation_name = | 40 std::string requested_implementation_name = |
42 CommandLine::ForCurrentProcess()->GetSwitchValueASCII(switches::kUseGL); | 41 CommandLine::ForCurrentProcess()->GetSwitchValueASCII(switches::kUseGL); |
43 if (requested_implementation_name == "any") { | 42 if (requested_implementation_name == "any") { |
44 fallback_to_osmesa = true; | 43 fallback_to_osmesa = true; |
45 } else if (requested_implementation_name == "swiftshader") { | 44 } else if (requested_implementation_name == "swiftshader") { |
46 impl = kGLImplementationEGLGLES2; | 45 impl = kGLImplementationEGLGLES2; |
46 } else if (requested_implementation_name == kGLImplementationMockName) { | |
47 impl = kGLImplementationMockGL; | |
47 } else { | 48 } else { |
48 impl = GetNamedGLImplementation(requested_implementation_name); | 49 impl = GetNamedGLImplementation(requested_implementation_name); |
49 if (std::find(allowed_impls.begin(), | 50 if (std::find(allowed_impls.begin(), |
50 allowed_impls.end(), | 51 allowed_impls.end(), |
51 impl) == allowed_impls.end()) { | 52 impl) == allowed_impls.end()) { |
52 LOG(ERROR) << "Requested GL implementation is not available."; | 53 LOG(ERROR) << "Requested GL implementation is not available."; |
53 return false; | 54 return false; |
54 } | 55 } |
55 } | 56 } |
56 } | 57 } |
57 | 58 |
58 initialized = InitializeStaticGLBindings(impl) && InitializeOneOffInternal(); | 59 bool initialized = |
60 InitializeStaticGLBindings(impl) && InitializeOneOffInternal(); | |
59 if (!initialized && fallback_to_osmesa) { | 61 if (!initialized && fallback_to_osmesa) { |
60 ClearGLBindings(); | 62 ClearGLBindings(); |
61 initialized = InitializeStaticGLBindings(kGLImplementationOSMesaGL) && | 63 initialized = InitializeStaticGLBindings(kGLImplementationOSMesaGL) && |
62 InitializeOneOffInternal(); | 64 InitializeOneOffInternal(); |
63 } | 65 } |
66 if (!initialized) | |
67 ClearGLBindings(); | |
64 | 68 |
65 if (initialized) { | 69 if (initialized) { |
66 DVLOG(1) << "Using " | 70 DVLOG(1) << "Using " |
67 << GetGLImplementationName(GetGLImplementation()) | 71 << GetGLImplementationName(GetGLImplementation()) |
68 << " GL implementation."; | 72 << " GL implementation."; |
69 if (CommandLine::ForCurrentProcess()->HasSwitch( | 73 if (CommandLine::ForCurrentProcess()->HasSwitch( |
70 switches::kEnableGPUServiceLogging)) | 74 switches::kEnableGPUServiceLogging)) |
71 InitializeDebugGLBindings(); | 75 InitializeDebugGLBindings(); |
72 if (CommandLine::ForCurrentProcess()->HasSwitch( | 76 if (CommandLine::ForCurrentProcess()->HasSwitch( |
73 switches::kDisableGLDrawingForTests)) | 77 switches::kDisableGLDrawingForTests)) |
74 InitializeNullDrawGLBindings(); | 78 InitializeNullDrawGLBindings(); |
75 } | 79 } |
76 return initialized; | 80 return initialized; |
77 } | 81 } |
78 | 82 |
83 // static | |
84 void GLSurface::InitializeOneOffForTests() { | |
85 CommandLine* cmd = CommandLine::ForCurrentProcess(); | |
86 | |
87 bool use_osmesa = true; | |
88 | |
89 #if defined(OS_ANDROID) | |
90 // On Android we always use hardware GL. | |
91 use_osmesa = false; | |
92 #endif | |
93 | |
94 if (use_osmesa) { | |
95 if (cmd->HasSwitch(switches::kUseGL)) { | |
96 DCHECK(cmd->GetSwitchValueASCII(switches::kUseGL) == | |
piman
2014/01/24 19:22:23
nit: maybe CHECK with an error message, so that na
danakj
2014/01/24 20:17:23
kk
| |
97 kGLImplementationOSMesaName); | |
98 } else { | |
99 cmd->AppendSwitchASCII(switches::kUseGL, kGLImplementationOSMesaName); | |
100 } | |
101 } else { | |
102 DCHECK(!cmd->HasSwitch(switches::kUseGL)); | |
103 } | |
104 | |
105 // TODO(danakj): Unit tests do not produce pixel output by default. | |
106 // cmd->AppendSwitch(switches::kDisableGLDrawingForTests); | |
107 | |
108 CHECK(InitializeOneOff()); | |
109 } | |
110 | |
111 // static | |
112 void GLSurface::InitializeOneOffWithMockBindingsForTests() { | |
113 CommandLine* cmd = CommandLine::ForCurrentProcess(); | |
114 if (cmd->HasSwitch(switches::kUseGL)) { | |
115 DCHECK(cmd->GetSwitchValueASCII(switches::kUseGL) == | |
116 kGLImplementationMockName); | |
117 } else { | |
118 cmd->AppendSwitchASCII(switches::kUseGL, kGLImplementationMockName); | |
119 } | |
120 | |
121 // This method may be called multiple times in the same process to set up | |
122 // mock bindings in different ways. | |
123 ClearGLBindings(); | |
124 | |
125 CHECK(InitializeOneOff()); | |
126 } | |
127 | |
128 // static | |
129 void GLSurface::InitializeDynamicMockBindingsForTests(GLContext* context) { | |
130 CHECK(InitializeDynamicGLBindings(kGLImplementationMockGL, context)); | |
131 } | |
132 | |
79 GLSurface::GLSurface() {} | 133 GLSurface::GLSurface() {} |
80 | 134 |
81 bool GLSurface::Initialize() { | 135 bool GLSurface::Initialize() { |
82 return true; | 136 return true; |
83 } | 137 } |
84 | 138 |
85 bool GLSurface::Resize(const gfx::Size& size) { | 139 bool GLSurface::Resize(const gfx::Size& size) { |
86 NOTIMPLEMENTED(); | 140 NOTIMPLEMENTED(); |
87 return false; | 141 return false; |
88 } | 142 } |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
257 return surface_->GetFormat(); | 311 return surface_->GetFormat(); |
258 } | 312 } |
259 | 313 |
260 VSyncProvider* GLSurfaceAdapter::GetVSyncProvider() { | 314 VSyncProvider* GLSurfaceAdapter::GetVSyncProvider() { |
261 return surface_->GetVSyncProvider(); | 315 return surface_->GetVSyncProvider(); |
262 } | 316 } |
263 | 317 |
264 GLSurfaceAdapter::~GLSurfaceAdapter() {} | 318 GLSurfaceAdapter::~GLSurfaceAdapter() {} |
265 | 319 |
266 } // namespace gfx | 320 } // namespace gfx |
OLD | NEW |