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

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

Issue 15928002: GPU: Keep track of the last real context and real surface made current. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix OSX Created 7 years, 6 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 17
18 namespace gfx { 18 namespace gfx {
19 19
20 namespace { 20 namespace {
21 base::LazyInstance<base::ThreadLocalPointer<GLContext> >::Leaky 21 base::LazyInstance<base::ThreadLocalPointer<GLContext> >::Leaky
22 current_context_ = LAZY_INSTANCE_INITIALIZER; 22 current_context_ = LAZY_INSTANCE_INITIALIZER;
23
24 base::LazyInstance<base::ThreadLocalPointer<GLContext> >::Leaky
25 current_real_context_ = LAZY_INSTANCE_INITIALIZER;
23 } // namespace 26 } // namespace
24 27
25 GLContext::GLContext(GLShareGroup* share_group) : share_group_(share_group) { 28 GLContext::GLContext(GLShareGroup* share_group) : share_group_(share_group) {
26 if (!share_group_.get()) 29 if (!share_group_.get())
27 share_group_ = new GLShareGroup; 30 share_group_ = new GLShareGroup;
28 31
29 share_group_->AddContext(this); 32 share_group_->AddContext(this);
30 } 33 }
31 34
32 GLContext::~GLContext() { 35 GLContext::~GLContext() {
33 share_group_->RemoveContext(this); 36 share_group_->RemoveContext(this);
34 if (GetCurrent() == this) { 37 if (GetCurrent() == this) {
35 SetCurrent(NULL, NULL); 38 SetCurrent(NULL);
36 } 39 }
37 } 40 }
38 41
39 bool GLContext::GetTotalGpuMemory(size_t* bytes) { 42 bool GLContext::GetTotalGpuMemory(size_t* bytes) {
40 DCHECK(bytes); 43 DCHECK(bytes);
41 *bytes = 0; 44 *bytes = 0;
42 return false; 45 return false;
43 } 46 }
44 47
45 void GLContext::SetSafeToForceGpuSwitch() { 48 void GLContext::SetSafeToForceGpuSwitch() {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 default: 86 default:
84 NOTREACHED(); 87 NOTREACHED();
85 return true; 88 return true;
86 } 89 }
87 } 90 }
88 91
89 GLContext* GLContext::GetCurrent() { 92 GLContext* GLContext::GetCurrent() {
90 return current_context_.Pointer()->Get(); 93 return current_context_.Pointer()->Get();
91 } 94 }
92 95
93 void GLContext::SetCurrent(GLContext* context, GLSurface* surface) { 96 GLContext* GLContext::GetRealCurrent() {
94 current_context_.Pointer()->Set(context); 97 return current_real_context_.Pointer()->Get();
98 }
99
100 void GLContext::SetCurrent(GLSurface* surface) {
101 current_context_.Pointer()->Set(surface ? this : NULL);
95 GLSurface::SetCurrent(surface); 102 GLSurface::SetCurrent(surface);
96 } 103 }
97 104
98 GLStateRestorer* GLContext::GetGLStateRestorer() { 105 GLStateRestorer* GLContext::GetGLStateRestorer() {
99 return state_restorer_.get(); 106 return state_restorer_.get();
100 } 107 }
101 108
102 void GLContext::SetGLStateRestorer(GLStateRestorer* state_restorer) { 109 void GLContext::SetGLStateRestorer(GLStateRestorer* state_restorer) {
103 state_restorer_ = make_scoped_ptr(state_restorer); 110 state_restorer_ = make_scoped_ptr(state_restorer);
104 } 111 }
(...skipping 16 matching lines...) Expand all
121 void GLContext::SetupForVirtualization() { 128 void GLContext::SetupForVirtualization() {
122 if (!virtual_gl_api_) { 129 if (!virtual_gl_api_) {
123 virtual_gl_api_.reset(new VirtualGLApi()); 130 virtual_gl_api_.reset(new VirtualGLApi());
124 virtual_gl_api_->Initialize(&g_driver_gl, this); 131 virtual_gl_api_->Initialize(&g_driver_gl, this);
125 } 132 }
126 } 133 }
127 134
128 bool GLContext::MakeVirtuallyCurrent( 135 bool GLContext::MakeVirtuallyCurrent(
129 GLContext* virtual_context, GLSurface* surface) { 136 GLContext* virtual_context, GLSurface* surface) {
130 DCHECK(virtual_gl_api_); 137 DCHECK(virtual_gl_api_);
131 return virtual_gl_api_->MakeCurrent(virtual_context, surface); 138 bool result = virtual_gl_api_->MakeCurrent(virtual_context, surface);
139 if (result) {
140 virtual_context->SetCurrent(surface);
141 surface->OnMakeCurrent(virtual_context);
no sievers 2013/06/04 23:47:20 Wait, why add a call to surface->OnMakeCurrent() h
jonathan.backer 2013/06/05 14:02:10 Most (all?) of the implementations of GLSurface::O
142 }
143 return result;
132 } 144 }
133 145
134 void GLContext::OnReleaseVirtuallyCurrent(GLContext* virtual_context) { 146 void GLContext::OnReleaseVirtuallyCurrent(GLContext* virtual_context) {
135 if (virtual_gl_api_) 147 if (virtual_gl_api_)
136 virtual_gl_api_->OnReleaseVirtuallyCurrent(virtual_context); 148 virtual_gl_api_->OnReleaseVirtuallyCurrent(virtual_context);
137 } 149 }
138 150
139 void GLContext::SetRealGLApi() { 151 void GLContext::SetRealGLApi() {
140 SetGLToRealGLApi(); 152 SetGLToRealGLApi();
141 } 153 }
142 154
155 GLContextReal::GLContextReal(GLShareGroup* share_group)
156 : GLContext(share_group) {}
157
158 GLContextReal::~GLContextReal() {}
159
160 void GLContextReal::SetCurrent(GLSurface* surface) {
161 GLContext::SetCurrent(surface);
162 current_real_context_.Pointer()->Set(surface ? this : NULL);
163 GLSurface::SetRealCurrent(surface);
164 }
165
143 } // namespace gfx 166 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698