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() { |