Skip to content

Commit

Permalink
Make Context current before destroying a texture.
Browse files Browse the repository at this point in the history
Make context current in ~AbstractTextureImplOnSharedContextPassthrough()
before destroying the |texture_| since the destructor is not guaranteed
to be called from the same context on which the |texture_| was created.

Bug: 1054865
Change-Id: I1647d1ec8aede954031aae70692943c2f14920e2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2068892
Commit-Queue: Khushal <khushalsagar@chromium.org>
Reviewed-by: Khushal <khushalsagar@chromium.org>
Auto-Submit: vikas soni <vikassoni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#743809}
  • Loading branch information
vikaschromie authored and Commit Bot committed Feb 22, 2020
1 parent be37ca1 commit 7bb331d
Showing 1 changed file with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "gpu/command_buffer/service/context_state.h"
#include "gpu/command_buffer/service/texture_manager.h"
#include "ui/gl/gl_context.h"
#include "ui/gl/gl_surface.h"
#include "ui/gl/scoped_binders.h"
#include "ui/gl/scoped_make_current.h"

Expand Down Expand Up @@ -155,6 +156,30 @@ AbstractTextureImplOnSharedContextPassthrough::
~AbstractTextureImplOnSharedContextPassthrough() {
if (cleanup_cb_)
std::move(cleanup_cb_).Run(this);

// Save the current context and make it current again after deleting the
// |texture_|.
scoped_refptr<gl::GLContext> previous_context = gl::GLContext::GetCurrent();
scoped_refptr<gl::GLSurface> previous_surface = gl::GLSurface::GetCurrent();

// If the shared context is lost, |shared_context_state_| will be null and the
// |texture_| is already marked to have lost its context.
if (shared_context_state_) {
// Make the |shared_context_state_|'s context current before destroying the
// |texture_| since
// destructor is not guaranteed to be called on the context on which the
// |texture_| was created.
if (!shared_context_state_->IsCurrent(nullptr)) {
shared_context_state_->MakeCurrent(shared_context_state_->surface(),
true /* needs_gl */);
}
shared_context_state_->RemoveContextLostObserver(this);
}
texture_.reset();

// Make the previous context current again.
if (!previous_context->IsCurrent(previous_surface.get()))
previous_context->MakeCurrent(previous_surface.get());
}

TextureBase* AbstractTextureImplOnSharedContextPassthrough::GetTextureBase()
Expand Down

0 comments on commit 7bb331d

Please sign in to comment.