Bug 1543846 - Call GeckoSurfaceTexture::UpdateTexImage() at correct timing during video callback in RenderAndroidSurfaceTextureHostOGL r=nical

During playing a video, one GeckoSurfaceTexture is used for all RenderAndroidSurfaceTextureHostOGLs of the video. GeckoSurfaceTexture owns multiple buffers. UpdateTexImage() needs to be called at the correct timing for adjusting SurfaceTexture's buffer status.

Differential Revision: https://phabricator.services.mozilla.com/D27467

--HG--
extra : moz-landing-system : lando
This commit is contained in:
sotaro 2019-04-15 09:51:59 +00:00
Родитель da79779db2
Коммит 61d191f94b
2 изменённых файлов: 34 добавлений и 14 удалений

Просмотреть файл

@ -19,7 +19,7 @@ RenderAndroidSurfaceTextureHostOGL::RenderAndroidSurfaceTextureHostOGL(
: mSurfTex(aSurfTex),
mSize(aSize),
mContinuousUpdate(aContinuousUpdate),
mIsPrepared(false),
mPrepareStatus(STATUS_NONE),
mAttachedToGLContext(false) {
MOZ_COUNT_CTOR_INHERITED(RenderAndroidSurfaceTextureHostOGL,
RenderTextureHostOGL);
@ -27,10 +27,6 @@ RenderAndroidSurfaceTextureHostOGL::RenderAndroidSurfaceTextureHostOGL(
if (mSurfTex) {
mSurfTex->IncrementUse();
}
if (mSurfTex && !mSurfTex->IsSingleBuffer()) {
mIsPrepared = true;
}
}
RenderAndroidSurfaceTextureHostOGL::~RenderAndroidSurfaceTextureHostOGL() {
@ -87,10 +83,13 @@ wr::WrExternalImage RenderAndroidSurfaceTextureHostOGL::Lock(
if (mContinuousUpdate) {
MOZ_ASSERT(!mSurfTex->IsSingleBuffer());
mSurfTex->UpdateTexImage();
} else if (!mSurfTex->IsSingleBuffer()) {
// Always calling UpdateTexImage() is not good.
// XXX Bug 1543846 will update this.
} else if (mPrepareStatus == STATUS_PREPARE_NEEDED) {
MOZ_ASSERT(!mSurfTex->IsSingleBuffer());
// When SurfaceTexture is not single buffer mode, call UpdateTexImage() once
// just before rendering. During playing video, one SurfaceTexture is used
// for all RenderAndroidSurfaceTextureHostOGLs of video.
mSurfTex->UpdateTexImage();
mPrepareStatus = STATUS_PREPARED;
}
return NativeTextureToWrExternalImage(mSurfTex->GetTexName(), 0, 0,
@ -135,19 +134,28 @@ bool RenderAndroidSurfaceTextureHostOGL::EnsureAttachedToGLContext() {
}
void RenderAndroidSurfaceTextureHostOGL::PrepareForUse() {
// When SurfaceTexture is single buffer mode, UpdateTexImage neeeds to be
// When SurfaceTexture is single buffer mode, UpdateTexImage needs to be
// called only once for each publish. If UpdateTexImage is called more
// than once, it causes hang on puglish side. And UpdateTexImage needs to
// be called on render thread, since the SurfaceTexture is consumed on render
// thread.
MOZ_ASSERT(RenderThread::IsInRenderThread());
MOZ_ASSERT(mPrepareStatus == STATUS_NONE);
EnsureAttachedToGLContext();
if (mSurfTex && mSurfTex->IsSingleBuffer() && !mIsPrepared) {
if (mContinuousUpdate) {
return;
}
mPrepareStatus = STATUS_PREPARE_NEEDED;
if (mSurfTex && mSurfTex->IsSingleBuffer()) {
// When SurfaceTexture is single buffer mode, it is OK to call
// UpdateTexImage() here.
mSurfTex->UpdateTexImage();
mIsPrepared = true;
mPrepareStatus = STATUS_PREPARED;
}
}
@ -156,11 +164,19 @@ void RenderAndroidSurfaceTextureHostOGL::NotifyNotUsed() {
EnsureAttachedToGLContext();
if (mSurfTex && mSurfTex->IsSingleBuffer() && mIsPrepared) {
if (mSurfTex && mSurfTex->IsSingleBuffer() &&
mPrepareStatus == STATUS_PREPARED) {
// Release SurfaceTexture's buffer to client side.
mGL->MakeCurrent();
mSurfTex->ReleaseTexImage();
mIsPrepared = false;
} else if (mSurfTex && mPrepareStatus == STATUS_PREPARE_NEEDED) {
// This could happen when video frame was skipped. UpdateTexImage() neeeds
// to be called for adjusting SurfaceTexture's buffer status.
MOZ_ASSERT(!mSurfTex->IsSingleBuffer());
mSurfTex->UpdateTexImage();
}
mPrepareStatus = STATUS_NONE;
}
} // namespace wr

Просмотреть файл

@ -36,11 +36,15 @@ class RenderAndroidSurfaceTextureHostOGL final : public RenderTextureHostOGL {
void DeleteTextureHandle();
bool EnsureAttachedToGLContext();
enum PrepareStatus { STATUS_NONE, STATUS_PREPARE_NEEDED, STATUS_PREPARED };
const mozilla::java::GeckoSurfaceTexture::GlobalRef mSurfTex;
const gfx::IntSize mSize;
// mContinuousUpdate was used for rendering video in the past.
// It is not used on current gecko.
const bool mContinuousUpdate;
// XXX const bool mIgnoreTransform;
bool mIsPrepared;
PrepareStatus mPrepareStatus;
bool mAttachedToGLContext;
RefPtr<gl::GLContext> mGL;