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

Side by Side Diff: ui/gl/gl_context.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: 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
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 <string> 5 #include <string>
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/lazy_instance.h" 8 #include "base/lazy_instance.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/threading/thread_local.h" 10 #include "base/threading/thread_local.h"
11 #include "ui/gl/gl_bindings.h" 11 #include "ui/gl/gl_bindings.h"
12 #include "ui/gl/gl_context.h" 12 #include "ui/gl/gl_context.h"
13 #include "ui/gl/gl_gl_api_implementation.h" 13 #include "ui/gl/gl_gl_api_implementation.h"
14 #include "ui/gl/gl_implementation.h" 14 #include "ui/gl/gl_implementation.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 namespace { 21 namespace {
22 base::LazyInstance<base::ThreadLocalPointer<GLContext> >::Leaky 22 base::LazyInstance<base::ThreadLocalPointer<GLContext> >::Leaky
23 current_context_ = LAZY_INSTANCE_INITIALIZER; 23 current_context_ = LAZY_INSTANCE_INITIALIZER;
24 24
25 base::LazyInstance<base::ThreadLocalPointer<GLContext> >::Leaky 25 base::LazyInstance<base::ThreadLocalPointer<GLContext> >::Leaky
26 current_real_context_ = LAZY_INSTANCE_INITIALIZER; 26 current_real_context_ = LAZY_INSTANCE_INITIALIZER;
27 } // namespace 27 } // namespace
28 28
29 GLContext::ScopedReleaseCurrent::ScopedReleaseCurrent(GLContext* context,
30 GLSurface* surface)
31 : context_(context), surface_(surface) {
32 DCHECK(context && surface);
33 DCHECK(context->IsCurrent(surface));
34 }
35
36 GLContext::ScopedReleaseCurrent::~ScopedReleaseCurrent() {
37 if (surface_) {
38 DCHECK(context_);
39 context_->ReleaseCurrent(surface_);
40 }
41 }
42
43 void GLContext::ScopedReleaseCurrent::Release() {
44 context_ = NULL;
45 surface_ = NULL;
46 }
47
29 GLContext::GLContext(GLShareGroup* share_group) : share_group_(share_group) { 48 GLContext::GLContext(GLShareGroup* share_group) : share_group_(share_group) {
30 if (!share_group_.get()) 49 if (!share_group_.get())
31 share_group_ = new GLShareGroup; 50 share_group_ = new GLShareGroup;
32 51
33 share_group_->AddContext(this); 52 share_group_->AddContext(this);
34 } 53 }
35 54
36 GLContext::~GLContext() { 55 GLContext::~GLContext() {
37 share_group_->RemoveContext(this); 56 share_group_->RemoveContext(this);
38 if (GetCurrent() == this) { 57 if (GetCurrent() == this) {
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 return current_context_.Pointer()->Get(); 137 return current_context_.Pointer()->Get();
119 } 138 }
120 139
121 GLContext* GLContext::GetRealCurrent() { 140 GLContext* GLContext::GetRealCurrent() {
122 return current_real_context_.Pointer()->Get(); 141 return current_real_context_.Pointer()->Get();
123 } 142 }
124 143
125 void GLContext::SetCurrent(GLSurface* surface) { 144 void GLContext::SetCurrent(GLSurface* surface) {
126 current_context_.Pointer()->Set(surface ? this : NULL); 145 current_context_.Pointer()->Set(surface ? this : NULL);
127 GLSurface::SetCurrent(surface); 146 GLSurface::SetCurrent(surface);
147 if (!surface)
148 SetGLApiToNoContext();
128 } 149 }
129 150
130 GLStateRestorer* GLContext::GetGLStateRestorer() { 151 GLStateRestorer* GLContext::GetGLStateRestorer() {
131 return state_restorer_.get(); 152 return state_restorer_.get();
132 } 153 }
133 154
134 void GLContext::SetGLStateRestorer(GLStateRestorer* state_restorer) { 155 void GLContext::SetGLStateRestorer(GLStateRestorer* state_restorer) {
135 state_restorer_ = make_scoped_ptr(state_restorer); 156 state_restorer_ = make_scoped_ptr(state_restorer);
136 } 157 }
137 158
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 : GLContext(share_group) {} 197 : GLContext(share_group) {}
177 198
178 GLContextReal::~GLContextReal() {} 199 GLContextReal::~GLContextReal() {}
179 200
180 void GLContextReal::SetCurrent(GLSurface* surface) { 201 void GLContextReal::SetCurrent(GLSurface* surface) {
181 GLContext::SetCurrent(surface); 202 GLContext::SetCurrent(surface);
182 current_real_context_.Pointer()->Set(surface ? this : NULL); 203 current_real_context_.Pointer()->Set(surface ? this : NULL);
183 } 204 }
184 205
185 } // namespace gfx 206 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698