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

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

Issue 221433004: gpu: Bind dummy GL API when no context is current (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix two gpu unittests Created 6 years, 8 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
« no previous file with comments | « ui/gl/gl_gl_api_implementation.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_gl_api_implementation.h" 5 #include "ui/gl/gl_gl_api_implementation.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/strings/string_util.h" 11 #include "base/strings/string_util.h"
12 #include "ui/gl/gl_context.h" 12 #include "ui/gl/gl_context.h"
13 #include "ui/gl/gl_implementation.h" 13 #include "ui/gl/gl_implementation.h"
14 #include "ui/gl/gl_state_restorer.h" 14 #include "ui/gl/gl_state_restorer.h"
15 #include "ui/gl/gl_surface.h" 15 #include "ui/gl/gl_surface.h"
16 #include "ui/gl/gl_switches.h" 16 #include "ui/gl/gl_switches.h"
17 #include "ui/gl/gl_version_info.h" 17 #include "ui/gl/gl_version_info.h"
18 18
19 namespace gfx { 19 namespace gfx {
20 20
21 // The GL Api being used. This could be g_real_gl or gl_trace_gl 21 // The GL Api being used. This could be g_real_gl or gl_trace_gl
22 static GLApi* g_gl; 22 static GLApi* g_gl;
23 // A GL Api that calls directly into the driver. 23 // A GL Api that calls directly into the driver.
24 static RealGLApi* g_real_gl; 24 static RealGLApi* g_real_gl;
25 // A GL Api that does nothing but warn about illegal GL calls without a context
26 // current.
27 static NoContextGLApi* g_no_context_gl;
25 // A GL Api that calls TRACE and then calls another GL api. 28 // A GL Api that calls TRACE and then calls another GL api.
26 static TraceGLApi* g_trace_gl; 29 static TraceGLApi* g_trace_gl;
27 // GL version used when initializing dynamic bindings. 30 // GL version used when initializing dynamic bindings.
28 static GLVersionInfo* g_version_info = NULL; 31 static GLVersionInfo* g_version_info = NULL;
29 32
30 namespace { 33 namespace {
31 34
32 static inline GLenum GetInternalFormat(GLenum internal_format) { 35 static inline GLenum GetInternalFormat(GLenum internal_format) {
33 if (gfx::GetGLImplementation() != gfx::kGLImplementationEGLGLES2) { 36 if (gfx::GetGLImplementation() != gfx::kGLImplementationEGLGLES2) {
34 if (internal_format == GL_BGRA_EXT || internal_format == GL_BGRA8_EXT) 37 if (internal_format == GL_BGRA_EXT || internal_format == GL_BGRA8_EXT)
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 null_draw_bindings_enabled = enabled; 254 null_draw_bindings_enabled = enabled;
252 return before; 255 return before;
253 } 256 }
254 257
255 void InitializeStaticGLBindingsGL() { 258 void InitializeStaticGLBindingsGL() {
256 g_current_gl_context_tls = new base::ThreadLocalPointer<GLApi>; 259 g_current_gl_context_tls = new base::ThreadLocalPointer<GLApi>;
257 g_driver_gl.InitializeStaticBindings(); 260 g_driver_gl.InitializeStaticBindings();
258 if (!g_real_gl) { 261 if (!g_real_gl) {
259 g_real_gl = new RealGLApi(); 262 g_real_gl = new RealGLApi();
260 g_trace_gl = new TraceGLApi(g_real_gl); 263 g_trace_gl = new TraceGLApi(g_real_gl);
264 g_no_context_gl = new NoContextGLApi();
261 } 265 }
262 g_real_gl->Initialize(&g_driver_gl); 266 g_real_gl->Initialize(&g_driver_gl);
263 g_gl = g_real_gl; 267 g_gl = g_real_gl;
264 if (CommandLine::ForCurrentProcess()->HasSwitch( 268 if (CommandLine::ForCurrentProcess()->HasSwitch(
265 switches::kEnableGPUServiceTracing)) { 269 switches::kEnableGPUServiceTracing)) {
266 g_gl = g_trace_gl; 270 g_gl = g_trace_gl;
267 } 271 }
268 SetGLToRealGLApi(); 272 SetGLToRealGLApi();
269 } 273 }
270 274
271 GLApi* GetCurrentGLApi() { 275 GLApi* GetCurrentGLApi() {
272 return g_current_gl_context_tls->Get(); 276 return g_current_gl_context_tls->Get();
273 } 277 }
274 278
275 void SetGLApi(GLApi* api) { 279 void SetGLApi(GLApi* api) {
276 g_current_gl_context_tls->Set(api); 280 g_current_gl_context_tls->Set(api);
277 } 281 }
278 282
279 void SetGLToRealGLApi() { 283 void SetGLToRealGLApi() {
280 SetGLApi(g_gl); 284 SetGLApi(g_gl);
281 } 285 }
282 286
287 void SetGLApiToNoContext() {
288 SetGLApi(g_no_context_gl);
289 }
290
283 void InitializeDynamicGLBindingsGL(GLContext* context) { 291 void InitializeDynamicGLBindingsGL(GLContext* context) {
284 g_driver_gl.InitializeCustomDynamicBindings(context); 292 g_driver_gl.InitializeCustomDynamicBindings(context);
285 DCHECK(context && context->IsCurrent(NULL) && !g_version_info); 293 DCHECK(context && context->IsCurrent(NULL) && !g_version_info);
286 g_version_info = new GLVersionInfo(context->GetGLVersion().c_str(), 294 g_version_info = new GLVersionInfo(context->GetGLVersion().c_str(),
287 context->GetGLRenderer().c_str()); 295 context->GetGLRenderer().c_str());
288 } 296 }
289 297
290 void InitializeDebugGLBindingsGL() { 298 void InitializeDebugGLBindingsGL() {
291 g_driver_gl.InitializeDebugBindings(); 299 g_driver_gl.InitializeDebugBindings();
292 } 300 }
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 RealGLApi::~RealGLApi() { 357 RealGLApi::~RealGLApi() {
350 } 358 }
351 359
352 void RealGLApi::Initialize(DriverGL* driver) { 360 void RealGLApi::Initialize(DriverGL* driver) {
353 InitializeBase(driver); 361 InitializeBase(driver);
354 } 362 }
355 363
356 TraceGLApi::~TraceGLApi() { 364 TraceGLApi::~TraceGLApi() {
357 } 365 }
358 366
367 NoContextGLApi::NoContextGLApi() {
368 }
369
370 NoContextGLApi::~NoContextGLApi() {
371 }
372
359 VirtualGLApi::VirtualGLApi() 373 VirtualGLApi::VirtualGLApi()
360 : real_context_(NULL), 374 : real_context_(NULL),
361 current_context_(NULL) { 375 current_context_(NULL) {
362 } 376 }
363 377
364 VirtualGLApi::~VirtualGLApi() { 378 VirtualGLApi::~VirtualGLApi() {
365 } 379 }
366 380
367 void VirtualGLApi::Initialize(DriverGL* driver, GLContext* real_context) { 381 void VirtualGLApi::Initialize(DriverGL* driver, GLContext* real_context) {
368 InitializeBase(driver); 382 InitializeBase(driver);
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 const GLubyte* VirtualGLApi::glGetStringFn(GLenum name) { 453 const GLubyte* VirtualGLApi::glGetStringFn(GLenum name) {
440 switch (name) { 454 switch (name) {
441 case GL_EXTENSIONS: 455 case GL_EXTENSIONS:
442 return reinterpret_cast<const GLubyte*>(extensions_.c_str()); 456 return reinterpret_cast<const GLubyte*>(extensions_.c_str());
443 default: 457 default:
444 return driver_->fn.glGetStringFn(name); 458 return driver_->fn.glGetStringFn(name);
445 } 459 }
446 } 460 }
447 461
448 } // namespace gfx 462 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gl/gl_gl_api_implementation.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698