Bug 1322650 - Use SurfaceTexture for WebGL on Android in E10S r=jgilbert

The main advantage here is that it works cross-process.

MozReview-Commit-ID: 7YUTVB4Bydg
This commit is contained in:
James Willcox
2017-03-03 15:14:27 -06:00
parent b1a00e377d
commit 9f0c7ce5fc
19 changed files with 372 additions and 67 deletions

View File

@@ -56,8 +56,12 @@ CreateTextureHostOGL(const SurfaceDescriptor& aDesc,
#ifdef MOZ_WIDGET_ANDROID
case SurfaceDescriptor::TSurfaceTextureDescriptor: {
const SurfaceTextureDescriptor& desc = aDesc.get_SurfaceTextureDescriptor();
java::GeckoSurfaceTexture::LocalRef surfaceTexture = java::GeckoSurfaceTexture::Lookup(desc.handle());
MOZ_RELEASE_ASSERT(surfaceTexture);
result = new SurfaceTextureHost(aFlags,
(AndroidSurfaceTexture*)desc.surfTex(),
surfaceTexture,
desc.size());
break;
}
@@ -335,7 +339,7 @@ GLTextureSource::IsValid() const
#ifdef MOZ_WIDGET_ANDROID
SurfaceTextureSource::SurfaceTextureSource(TextureSourceProvider* aProvider,
AndroidSurfaceTexture* aSurfTex,
mozilla::java::GeckoSurfaceTexture::Ref& aSurfTex,
gfx::SurfaceFormat aFormat,
GLenum aTarget,
GLenum aWrapMode,
@@ -361,12 +365,7 @@ SurfaceTextureSource::BindTexture(GLenum aTextureUnit,
}
gl->fActiveTexture(aTextureUnit);
// SurfaceTexture spams us if there are any existing GL errors, so
// we'll clear them here in order to avoid that.
gl->FlushErrors();
mSurfTex->UpdateTexImage();
gl->fBindTexture(mTextureTarget, mSurfTex->GetTexName());
ApplySamplingFilterToBoundTexture(gl, aSamplingFilter, mTextureTarget);
}
@@ -395,7 +394,9 @@ SurfaceTextureSource::GetTextureTransform()
MOZ_ASSERT(mSurfTex);
gfx::Matrix4x4 ret;
mSurfTex->GetTransformMatrix(ret);
const auto& surf = java::sdk::SurfaceTexture::LocalRef(java::sdk::SurfaceTexture::Ref::From(mSurfTex));
AndroidSurfaceTexture::GetTransformMatrix(surf, ret);
return ret;
}
@@ -409,7 +410,7 @@ SurfaceTextureSource::DeallocateDeviceData()
////////////////////////////////////////////////////////////////////////
SurfaceTextureHost::SurfaceTextureHost(TextureFlags aFlags,
AndroidSurfaceTexture* aSurfTex,
mozilla::java::GeckoSurfaceTexture::Ref& aSurfTex,
gfx::IntSize aSize)
: TextureHost(aFlags)
, mSurfTex(aSurfTex)
@@ -421,6 +422,19 @@ SurfaceTextureHost::~SurfaceTextureHost()
{
}
void
SurfaceTextureHost::PrepareTextureSource(CompositableTextureSourceRef& aTexture)
{
GLContext* gl = this->gl();
if (!gl || !gl->MakeCurrent()) {
return;
}
// This advances the SurfaceTexture's internal buffer queue. We only want to do this
// once per transaction. We can then composite that texture as many times as needed.
mSurfTex->UpdateTexImage();
}
gl::GLContext*
SurfaceTextureHost::gl() const
{
@@ -438,7 +452,7 @@ SurfaceTextureHost::Lock()
if (!mTextureSource) {
gfx::SurfaceFormat format = gfx::SurfaceFormat::R8G8B8A8;
GLenum target = LOCAL_GL_TEXTURE_EXTERNAL;
GLenum target = LOCAL_GL_TEXTURE_EXTERNAL; // This is required by SurfaceTexture
GLenum wrapMode = LOCAL_GL_CLAMP_TO_EDGE;
mTextureSource = new SurfaceTextureSource(mProvider,
mSurfTex,
@@ -448,14 +462,7 @@ SurfaceTextureHost::Lock()
mSize);
}
return NS_SUCCEEDED(mSurfTex->Attach(gl));
}
void
SurfaceTextureHost::Unlock()
{
MOZ_ASSERT(mSurfTex);
mSurfTex->Detach();
return true;
}
void
@@ -474,6 +481,16 @@ SurfaceTextureHost::SetTextureSourceProvider(TextureSourceProvider* aProvider)
}
}
void
SurfaceTextureHost::NotifyNotUsed()
{
if (mSurfTex->IsSingleBuffer()) {
mSurfTex->ReleaseTexImage();
}
TextureHost::NotifyNotUsed();
}
gfx::SurfaceFormat
SurfaceTextureHost::GetFormat() const
{