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

Side by Side Diff: ui/gl/gl_gl_api_implementation.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: Nix unnecessary changes. 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
« no previous file with comments | « ui/gl/gl_context_wgl.cc ('k') | ui/gl/gl_surface_egl.cc » ('j') | 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"
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 if (it != ext.end()) 247 if (it != ext.end())
248 ext.erase(it); 248 ext.erase(it);
249 249
250 extensions_ = JoinString(ext, " "); 250 extensions_ = JoinString(ext, " ");
251 } 251 }
252 252
253 bool VirtualGLApi::MakeCurrent(GLContext* virtual_context, GLSurface* surface) { 253 bool VirtualGLApi::MakeCurrent(GLContext* virtual_context, GLSurface* surface) {
254 bool switched_contexts = g_current_gl_context != this; 254 bool switched_contexts = g_current_gl_context != this;
255 GLSurface* current_surface = GLSurface::GetCurrent(); 255 GLSurface* current_surface = GLSurface::GetCurrent();
256 if (switched_contexts || surface != current_surface) { 256 if (switched_contexts || surface != current_surface) {
257 if (!switched_contexts && current_surface && 257 // MakeCurrent 'lite' path that avoids potentially expensive MakeCurrent()
258 virtual_context->IsCurrent(surface)) { 258 // calls if the GLSurface uses the same underlying surface or renders to
259 // MakeCurrent 'lite' path that avoids potentially expensive MakeCurrent() 259 // an FBO.
260 // calls if the GLSurface uses the same underlying surface or renders to 260 if (switched_contexts || !current_surface ||
261 // an FBO. 261 !virtual_context->IsCurrent(surface)) {
262 if (!surface->OnMakeCurrent(real_context_)) { 262 if (!real_context_->MakeCurrent(surface)) {
263 LOG(ERROR) << "Could not make GLSurface current.";
264 return false; 263 return false;
265 } 264 }
266 } else if (!real_context_->MakeCurrent(surface)) {
267 return false;
268 } 265 }
269 } 266 }
270 267
271 DCHECK(GLSurface::GetCurrent()); 268 DCHECK_EQ(real_context_, GLContext::GetRealCurrent());
272 DCHECK(real_context_->IsCurrent(GLSurface::GetCurrent())); 269 DCHECK(real_context_->IsCurrent(NULL));
273 DCHECK(virtual_context->IsCurrent(surface)); 270 DCHECK(virtual_context->IsCurrent(surface));
274 271
275 if (switched_contexts || virtual_context != current_context_) { 272 if (switched_contexts || virtual_context != current_context_) {
276 // There should be no errors from the previous context leaking into the 273 // There should be no errors from the previous context leaking into the
277 // new context. 274 // new context.
278 DCHECK_EQ(glGetErrorFn(), static_cast<GLenum>(GL_NO_ERROR)); 275 DCHECK_EQ(glGetErrorFn(), static_cast<GLenum>(GL_NO_ERROR));
279 276
280 current_context_ = virtual_context; 277 current_context_ = virtual_context;
281 // Set all state that is different from the real state 278 // Set all state that is different from the real state
282 // NOTE: !!! This is a temporary implementation that just restores all 279 // NOTE: !!! This is a temporary implementation that just restores all
283 // state to let us test that it works. 280 // state to let us test that it works.
284 // TODO: ASAP, change this to something that only restores the state 281 // TODO: ASAP, change this to something that only restores the state
285 // needed for individual GL calls. 282 // needed for individual GL calls.
286 GLApi* temp = GetCurrentGLApi(); 283 GLApi* temp = GetCurrentGLApi();
287 SetGLToRealGLApi(); 284 SetGLToRealGLApi();
288 if (virtual_context->GetGLStateRestorer()->IsInitialized()) 285 if (virtual_context->GetGLStateRestorer()->IsInitialized())
289 virtual_context->GetGLStateRestorer()->RestoreState(); 286 virtual_context->GetGLStateRestorer()->RestoreState();
290 SetGLApi(temp); 287 SetGLApi(temp);
291 } 288 }
292 SetGLApi(this); 289 SetGLApi(this);
290
291 virtual_context->SetCurrent(surface);
292 if (!surface->OnMakeCurrent(virtual_context)) {
293 LOG(ERROR) << "Could not make GLSurface current.";
294 return false;
295 }
293 return true; 296 return true;
294 } 297 }
295 298
296 void VirtualGLApi::OnReleaseVirtuallyCurrent(GLContext* virtual_context) { 299 void VirtualGLApi::OnReleaseVirtuallyCurrent(GLContext* virtual_context) {
297 if (current_context_ == virtual_context) 300 if (current_context_ == virtual_context)
298 current_context_ = NULL; 301 current_context_ = NULL;
299 } 302 }
300 303
301 const GLubyte* VirtualGLApi::glGetStringFn(GLenum name) { 304 const GLubyte* VirtualGLApi::glGetStringFn(GLenum name) {
302 switch (name) { 305 switch (name) {
303 case GL_EXTENSIONS: 306 case GL_EXTENSIONS:
304 return reinterpret_cast<const GLubyte*>(extensions_.c_str()); 307 return reinterpret_cast<const GLubyte*>(extensions_.c_str());
305 default: 308 default:
306 return driver_->fn.glGetStringFn(name); 309 return driver_->fn.glGetStringFn(name);
307 } 310 }
308 } 311 }
309 312
310 } // namespace gfx 313 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gl/gl_context_wgl.cc ('k') | ui/gl/gl_surface_egl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698