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

Unified Diff: gpu/command_buffer/service/gl_context_virtual.cc

Issue 15841002: gpu: Fix corrupted state due to virtual MakeCurrent race. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Reland patch. Created 7 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | gpu/command_buffer/service/gl_state_restorer_impl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gpu/command_buffer/service/gl_context_virtual.cc
diff --git a/gpu/command_buffer/service/gl_context_virtual.cc b/gpu/command_buffer/service/gl_context_virtual.cc
index 938d811d50be5d04ad98485b9aadc1ebf77b729c..8051e06c3b935105f84f1863a7c524fb04783183 100644
--- a/gpu/command_buffer/service/gl_context_virtual.cc
+++ b/gpu/command_buffer/service/gl_context_virtual.cc
@@ -30,12 +30,20 @@ bool GLContextVirtual::Initialize(
display_ = static_cast<gfx::Display*>(compatible_surface->GetDisplay());
- if (!shared_context_->MakeCurrent(compatible_surface))
- return false;
+ // Virtual contexts obviously can't make a context that is compatible
+ // with the surface (the context already exists), but we do need to
+ // make a context current for SetupForVirtualization() below.
+ if (!IsCurrent(compatible_surface)) {
+ if (!shared_context_->MakeCurrent(compatible_surface)) {
+ // This is likely an error. The real context should be made as
+ // compatible with all required surfaces when it was created.
+ LOG(ERROR) << "Failed MakeCurrent(compatible_surface)";
+ return false;
+ }
+ }
shared_context_->SetupForVirtualization();
-
- shared_context_->ReleaseCurrent(compatible_surface);
+ shared_context_->MakeVirtuallyCurrent(this, compatible_surface);
return true;
}
@@ -46,9 +54,12 @@ void GLContextVirtual::Destroy() {
}
bool GLContextVirtual::MakeCurrent(gfx::GLSurface* surface) {
- if (decoder_.get() && decoder_->initialized())
+ // TODO(epenner): We should avoid bypassing MakeVirtuallyCurrent() below
+ // (return false or DCHECK when !decoder). To do this we must reorder
+ // tear-down in GpuCommandBufferStub::Destroy().
+ if (decoder_.get())
shared_context_->MakeVirtuallyCurrent(this, surface);
- else
+ else if (!IsCurrent(surface))
shared_context_->MakeCurrent(surface);
return true;
}
@@ -59,18 +70,14 @@ void GLContextVirtual::ReleaseCurrent(gfx::GLSurface* surface) {
}
bool GLContextVirtual::IsCurrent(gfx::GLSurface* surface) {
- bool context_current = shared_context_->IsCurrent(NULL);
- if (!context_current)
- return false;
-
- if (!surface)
- return true;
-
- gfx::GLSurface* current_surface = gfx::GLSurface::GetCurrent();
- return surface->GetBackingFrameBufferObject() ||
- surface->IsOffscreen() ||
- (current_surface &&
- current_surface->GetHandle() == surface->GetHandle());
+ // If it's a real surface it needs to be current.
+ if (surface &&
+ !surface->GetBackingFrameBufferObject() &&
+ !surface->IsOffscreen())
+ return shared_context_->IsCurrent(surface);
+
+ // Otherwise, only insure the context itself is current.
+ return shared_context_->IsCurrent(NULL);
}
void* GLContextVirtual::GetHandle() {
« no previous file with comments | « no previous file | gpu/command_buffer/service/gl_state_restorer_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698