Commit 04a1be36 authored by epenner@chromium.org's avatar epenner@chromium.org

Reland "GPU: Reduce MakeCurrent calls to fix Orange San Diego""

This patch now also always calls MakeVirtuallyCurrent during initialize and
MakeCurrent, such that the next context will always restore. The context state is
restored only if the API has changed or the virtually current context has changed,
so we should never skip calling MakeVirtuallyCurrent.

BUG=241188

Review URL: https://chromiumcodereview.appspot.com/15841002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@202561 0039d316-1c4b-4281-b951-d872f2087c98
parent bcf60fea
...@@ -30,12 +30,20 @@ bool GLContextVirtual::Initialize( ...@@ -30,12 +30,20 @@ bool GLContextVirtual::Initialize(
display_ = static_cast<gfx::Display*>(compatible_surface->GetDisplay()); display_ = static_cast<gfx::Display*>(compatible_surface->GetDisplay());
if (!shared_context_->MakeCurrent(compatible_surface)) // Virtual contexts obviously can't make a context that is compatible
return false; // 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_->SetupForVirtualization();
shared_context_->MakeVirtuallyCurrent(this, compatible_surface);
shared_context_->ReleaseCurrent(compatible_surface);
return true; return true;
} }
...@@ -46,9 +54,12 @@ void GLContextVirtual::Destroy() { ...@@ -46,9 +54,12 @@ void GLContextVirtual::Destroy() {
} }
bool GLContextVirtual::MakeCurrent(gfx::GLSurface* surface) { 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); shared_context_->MakeVirtuallyCurrent(this, surface);
else else if (!IsCurrent(surface))
shared_context_->MakeCurrent(surface); shared_context_->MakeCurrent(surface);
return true; return true;
} }
...@@ -59,18 +70,14 @@ void GLContextVirtual::ReleaseCurrent(gfx::GLSurface* surface) { ...@@ -59,18 +70,14 @@ void GLContextVirtual::ReleaseCurrent(gfx::GLSurface* surface) {
} }
bool GLContextVirtual::IsCurrent(gfx::GLSurface* surface) { bool GLContextVirtual::IsCurrent(gfx::GLSurface* surface) {
bool context_current = shared_context_->IsCurrent(NULL); // If it's a real surface it needs to be current.
if (!context_current) if (surface &&
return false; !surface->GetBackingFrameBufferObject() &&
!surface->IsOffscreen())
if (!surface) return shared_context_->IsCurrent(surface);
return true;
// Otherwise, only insure the context itself is current.
gfx::GLSurface* current_surface = gfx::GLSurface::GetCurrent(); return shared_context_->IsCurrent(NULL);
return surface->GetBackingFrameBufferObject() ||
surface->IsOffscreen() ||
(current_surface &&
current_surface->GetHandle() == surface->GetHandle());
} }
void* GLContextVirtual::GetHandle() { void* GLContextVirtual::GetHandle() {
......
...@@ -16,6 +16,11 @@ GLStateRestorerImpl::GLStateRestorerImpl( ...@@ -16,6 +16,11 @@ GLStateRestorerImpl::GLStateRestorerImpl(
GLStateRestorerImpl::~GLStateRestorerImpl() { GLStateRestorerImpl::~GLStateRestorerImpl() {
} }
bool GLStateRestorerImpl::IsInitialized() {
DCHECK(decoder_.get());
return decoder_->initialized();
}
void GLStateRestorerImpl::RestoreState() { void GLStateRestorerImpl::RestoreState() {
DCHECK(decoder_.get()); DCHECK(decoder_.get());
decoder_->RestoreState(); decoder_->RestoreState();
......
...@@ -23,6 +23,7 @@ class GPU_EXPORT GLStateRestorerImpl : public gfx::GLStateRestorer { ...@@ -23,6 +23,7 @@ class GPU_EXPORT GLStateRestorerImpl : public gfx::GLStateRestorer {
explicit GLStateRestorerImpl(base::WeakPtr<gles2::GLES2Decoder> decoder); explicit GLStateRestorerImpl(base::WeakPtr<gles2::GLES2Decoder> decoder);
virtual ~GLStateRestorerImpl(); virtual ~GLStateRestorerImpl();
virtual bool IsInitialized() OVERRIDE;
virtual void RestoreState() OVERRIDE; virtual void RestoreState() OVERRIDE;
virtual void RestoreAllTextureUnitBindings() OVERRIDE; virtual void RestoreAllTextureUnitBindings() OVERRIDE;
virtual void RestoreFramebufferBindings() OVERRIDE; virtual void RestoreFramebufferBindings() OVERRIDE;
......
...@@ -285,7 +285,8 @@ bool VirtualGLApi::MakeCurrent(GLContext* virtual_context, GLSurface* surface) { ...@@ -285,7 +285,8 @@ bool VirtualGLApi::MakeCurrent(GLContext* virtual_context, GLSurface* surface) {
// needed for individual GL calls. // needed for individual GL calls.
GLApi* temp = GetCurrentGLApi(); GLApi* temp = GetCurrentGLApi();
SetGLToRealGLApi(); SetGLToRealGLApi();
virtual_context->GetGLStateRestorer()->RestoreState(); if (virtual_context->GetGLStateRestorer()->IsInitialized())
virtual_context->GetGLStateRestorer()->RestoreState();
SetGLApi(temp); SetGLApi(temp);
} }
SetGLApi(this); SetGLApi(this);
......
...@@ -17,6 +17,7 @@ class GL_EXPORT GLStateRestorer { ...@@ -17,6 +17,7 @@ class GL_EXPORT GLStateRestorer {
GLStateRestorer(); GLStateRestorer();
virtual ~GLStateRestorer(); virtual ~GLStateRestorer();
virtual bool IsInitialized() = 0;
virtual void RestoreState() = 0; virtual void RestoreState() = 0;
virtual void RestoreAllTextureUnitBindings() = 0; virtual void RestoreAllTextureUnitBindings() = 0;
virtual void RestoreFramebufferBindings() = 0; virtual void RestoreFramebufferBindings() = 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment