Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Side by Side Diff: ui/gl/gl_surface.cc

Issue 145293007: ui: No more TestCompositor. Use NullDraw contexts in unit tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: testsnulldraw: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 #include "ui/gl/gl_switches.h"
18 18
19 #if defined(USE_X11)
20 #include <X11/Xlib.h>
21 #endif
22
19 namespace gfx { 23 namespace gfx {
20 24
21 namespace { 25 namespace {
22 base::LazyInstance<base::ThreadLocalPointer<GLSurface> >::Leaky 26 base::LazyInstance<base::ThreadLocalPointer<GLSurface> >::Leaky
23 current_surface_ = LAZY_INSTANCE_INITIALIZER; 27 current_surface_ = LAZY_INSTANCE_INITIALIZER;
24 } // namespace 28 } // namespace
25 29
26 // static 30 // static
27 bool GLSurface::InitializeOneOff() { 31 bool GLSurface::InitializeOneOff() {
28 DCHECK_EQ(kGLImplementationNone, GetGLImplementation()); 32 DCHECK_EQ(kGLImplementationNone, GetGLImplementation());
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 if (gpu_service_logging) 89 if (gpu_service_logging)
86 InitializeDebugGLBindings(); 90 InitializeDebugGLBindings();
87 if (disable_gl_drawing) 91 if (disable_gl_drawing)
88 InitializeNullDrawGLBindings(); 92 InitializeNullDrawGLBindings();
89 } 93 }
90 return initialized; 94 return initialized;
91 } 95 }
92 96
93 // static 97 // static
94 void GLSurface::InitializeOneOffForTests() { 98 void GLSurface::InitializeOneOffForTests() {
99 #if defined(USE_X11)
100 XInitThreads();
101 #endif
102
95 bool use_osmesa = true; 103 bool use_osmesa = true;
96 104
97 #if defined(OS_ANDROID) 105 #if defined(OS_ANDROID)
98 // On Android we always use hardware GL. 106 // On Android we always use hardware GL.
99 use_osmesa = false; 107 use_osmesa = false;
100 #endif 108 #endif
101 109
102 std::vector<GLImplementation> allowed_impls; 110 std::vector<GLImplementation> allowed_impls;
103 GetAllowedGLImplementations(&allowed_impls); 111 GetAllowedGLImplementations(&allowed_impls);
104 DCHECK(!allowed_impls.empty()); 112 DCHECK(!allowed_impls.empty());
105 113
106 GLImplementation impl = allowed_impls[0]; 114 GLImplementation impl = allowed_impls[0];
107 if (use_osmesa) 115 if (use_osmesa)
108 impl = kGLImplementationOSMesaGL; 116 impl = kGLImplementationOSMesaGL;
109 117
110 DCHECK(!CommandLine::ForCurrentProcess()->HasSwitch(switches::kUseGL)) 118 DCHECK(!CommandLine::ForCurrentProcess()->HasSwitch(switches::kUseGL))
111 << "kUseGL has not effect in tests"; 119 << "kUseGL has not effect in tests";
112 120
113 bool fallback_to_osmesa = false; 121 bool fallback_to_osmesa = false;
114 bool gpu_service_logging = false; 122 bool gpu_service_logging = false;
115 bool disable_gl_drawing = false; 123 // Unit tests do not produce pixel output by default.
116 // TODO(danakj): Unit tests do not produce pixel output by default. 124 bool disable_gl_drawing = true;
117 // bool disable_gl_drawing = true;
118 125
119 CHECK(InitializeOneOffImplementation( 126 CHECK(InitializeOneOffImplementation(
120 impl, fallback_to_osmesa, gpu_service_logging, disable_gl_drawing)); 127 impl, fallback_to_osmesa, gpu_service_logging, disable_gl_drawing));
121 } 128 }
122 129
123 // static 130 // static
124 void GLSurface::InitializeOneOffWithMockBindingsForTests() { 131 void GLSurface::InitializeOneOffWithMockBindingsForTests() {
125 DCHECK(!CommandLine::ForCurrentProcess()->HasSwitch(switches::kUseGL)) 132 DCHECK(!CommandLine::ForCurrentProcess()->HasSwitch(switches::kUseGL))
126 << "kUseGL has not effect in tests"; 133 << "kUseGL has not effect in tests";
127 134
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 return surface_->GetFormat(); 332 return surface_->GetFormat();
326 } 333 }
327 334
328 VSyncProvider* GLSurfaceAdapter::GetVSyncProvider() { 335 VSyncProvider* GLSurfaceAdapter::GetVSyncProvider() {
329 return surface_->GetVSyncProvider(); 336 return surface_->GetVSyncProvider();
330 } 337 }
331 338
332 GLSurfaceAdapter::~GLSurfaceAdapter() {} 339 GLSurfaceAdapter::~GLSurfaceAdapter() {}
333 340
334 } // namespace gfx 341 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698