Bug 1413230 - Ensure we are attached to the GL context in SurfaceTextureHostOGL::PrepareTextureSource() r=jnicol,nical
MozReview-Commit-ID: BxDng9OG3RF
--- a/gfx/layers/opengl/TextureHostOGL.cpp
+++ b/gfx/layers/opengl/TextureHostOGL.cpp
@@ -448,45 +448,62 @@ SurfaceTextureHost::~SurfaceTextureHost(
mSurfTex->DecrementUse();
mSurfTex = nullptr;
}
}
void
SurfaceTextureHost::PrepareTextureSource(CompositableTextureSourceRef& aTexture)
{
- GLContext* gl = this->gl();
- if (!gl || !gl->MakeCurrent()) {
- return;
- }
+ if (!mContinuousUpdate && mSurfTex) {
+ if (!EnsureAttached()) {
+ return;
+ }
- if (!mContinuousUpdate && mSurfTex) {
// UpdateTexImage() advances the internal buffer queue, so we only want to call this
// once per transactionwhen we are not in continuous mode (as we are here). Otherwise,
// the SurfaceTexture content will be de-synced from the rest of the page in subsequent
// compositor passes.
mSurfTex->UpdateTexImage();
}
}
gl::GLContext*
SurfaceTextureHost::gl() const
{
return mProvider ? mProvider->GetGLContext() : nullptr;
}
bool
-SurfaceTextureHost::Lock()
+SurfaceTextureHost::EnsureAttached()
{
+ GLContext* gl = this->gl();
+ if (!gl || !gl->MakeCurrent()) {
+ return false;
+ }
+
if (!mSurfTex) {
return false;
}
- GLContext* gl = this->gl();
- if (!gl || !gl->MakeCurrent()) {
+ if (!mSurfTex->IsAttachedToGLContext((int64_t)gl)) {
+ GLuint texName;
+ gl->fGenTextures(1, &texName);
+ if (NS_FAILED(mSurfTex->AttachToGLContext((int64_t)gl, texName))) {
+ return false;
+ }
+ }
+
+ return true;
+}
+
+bool
+SurfaceTextureHost::Lock()
+{
+ if (!EnsureAttached()) {
return false;
}
if (mContinuousUpdate) {
mSurfTex->UpdateTexImage();
}
if (!mTextureSource) {
@@ -496,24 +513,16 @@ SurfaceTextureHost::Lock()
mSurfTex,
mFormat,
target,
wrapMode,
mSize,
mIgnoreTransform);
}
- if (!mSurfTex->IsAttachedToGLContext((int64_t)gl)) {
- GLuint texName;
- gl->fGenTextures(1, &texName);
- if (NS_FAILED(mSurfTex->AttachToGLContext((int64_t)gl, texName))) {
- return false;
- }
- }
-
return true;
}
void
SurfaceTextureHost::SetTextureSourceProvider(TextureSourceProvider* aProvider)
{
if (mProvider != aProvider) {
if (!aProvider || !aProvider->GetGLContext()) {
--- a/gfx/layers/opengl/TextureHostOGL.h
+++ b/gfx/layers/opengl/TextureHostOGL.h
@@ -424,16 +424,18 @@ public:
gl::GLContext* gl() const;
virtual gfx::IntSize GetSize() const override { return mSize; }
virtual const char* Name() override { return "SurfaceTextureHost"; }
protected:
+ bool EnsureAttached();
+
mozilla::java::GeckoSurfaceTexture::GlobalRef mSurfTex;
const gfx::IntSize mSize;
const gfx::SurfaceFormat mFormat;
bool mContinuousUpdate;
const bool mIgnoreTransform;
RefPtr<CompositorOGL> mCompositor;
RefPtr<SurfaceTextureSource> mTextureSource;
};