Bug 1855886 - Destroy RenderTextureHost by the created TextureHost r=gfx-reviewers,lsalzman

Both WebRenderTextureHost and its wrapped TextureHost try to destroy RenderTextureHost. It is redundant.

WebRenderTextureHost does not create RenderTextureHost, then WebRenderTextureHost does not need to destroy the RenderTextureHost.

And added some asserts for checking.

Differential Revision: https://phabricator.services.mozilla.com/D189616
This commit is contained in:
sotaro 2023-10-02 00:29:00 +00:00
Родитель df05d0641c
Коммит 630d2c45fc
11 изменённых файлов: 34 добавлений и 13 удалений

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

@ -88,6 +88,7 @@ DcompSurfaceHandleHost::~DcompSurfaceHandleHost() {
void DcompSurfaceHandleHost::CreateRenderTexture(
const wr::ExternalImageId& aExternalImageId) {
MOZ_ASSERT(mExternalImageId.isSome());
LOG("DcompSurfaceHandleHost %p CreateRenderTexture, ext-id=%" PRIu64, this,
wr::AsUint64(aExternalImageId));
RefPtr<wr::RenderTextureHost> texture =

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

@ -136,12 +136,16 @@ void GPUVideoTextureHost::CreateRenderTexture(
}
void GPUVideoTextureHost::MaybeDestroyRenderTexture() {
if (mExternalImageId.isNothing() || !mWrappedTextureHost) {
if (mExternalImageId.isNothing()) {
// RenderTextureHost was not created
return;
}
// When GPUVideoTextureHost created RenderTextureHost, delete it here.
TextureHost::DestroyRenderTexture(mExternalImageId.ref());
if (mExternalImageId.isSome() && mWrappedTextureHost) {
// When GPUVideoTextureHost created RenderTextureHost, delete it here.
TextureHost::DestroyRenderTexture(mExternalImageId.ref());
}
mExternalImageId = Nothing();
}
uint32_t GPUVideoTextureHost::NumSubTextures() {

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

@ -116,14 +116,6 @@ void RemoteTextureHostWrapper::CreateRenderTexture(
}
}
void RemoteTextureHostWrapper::MaybeDestroyRenderTexture() {
if (mExternalImageId.isNothing() || !mRemoteTextureForDisplayList) {
// RenderTextureHost was not created
return;
}
TextureHost::DestroyRenderTexture(mExternalImageId.ref());
}
uint32_t RemoteTextureHostWrapper::NumSubTextures() {
if (!mRemoteTextureForDisplayList) {
return 0;

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

@ -47,8 +47,6 @@ class RemoteTextureHostWrapper : public TextureHost {
void CreateRenderTexture(
const wr::ExternalImageId& aExternalImageId) override;
void MaybeDestroyRenderTexture() override;
uint32_t NumSubTextures() override;
void PushResourceUpdates(wr::TransactionBuilder& aResources,

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

@ -364,6 +364,8 @@ TextureHost::TextureHost(TextureHostType aType, TextureFlags aFlags)
mReadLocked(false) {}
TextureHost::~TextureHost() {
MOZ_ASSERT(mExternalImageId.isNothing());
if (mReadLocked) {
// If we still have a ReadLock, unlock it. At this point we don't care about
// the texture client being written into on the other side since it should
@ -506,6 +508,8 @@ void BufferTextureHost::DeallocateDeviceData() {}
void BufferTextureHost::CreateRenderTexture(
const wr::ExternalImageId& aExternalImageId) {
MOZ_ASSERT(mExternalImageId.isSome());
RefPtr<wr::RenderTextureHost> texture;
if (UseExternalTextures()) {

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

@ -939,6 +939,8 @@ void DXGITextureHostD3D11::UnlockInternal() {
void DXGITextureHostD3D11::CreateRenderTexture(
const wr::ExternalImageId& aExternalImageId) {
MOZ_ASSERT(mExternalImageId.isSome());
RefPtr<wr::RenderDXGITextureHost> texture = new wr::RenderDXGITextureHost(
mHandle, mGpuProcessTextureId, mArrayIndex, mFormat, mColorSpace,
mColorRange, mSize, mHasKeyedMutex);
@ -1175,6 +1177,8 @@ bool DXGIYCbCrTextureHostD3D11::EnsureTextureSource() { return false; }
void DXGIYCbCrTextureHostD3D11::CreateRenderTexture(
const wr::ExternalImageId& aExternalImageId) {
MOZ_ASSERT(mExternalImageId.isSome());
RefPtr<wr::RenderTextureHost> texture = new wr::RenderDXGIYCbCrTextureHost(
mHandles, mYUVColorSpace, mColorDepth, mColorRange, mSizeY, mSizeCbCr);

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

@ -65,6 +65,8 @@ gl::GLContext* DMABUFTextureHostOGL::gl() const { return nullptr; }
void DMABUFTextureHostOGL::CreateRenderTexture(
const wr::ExternalImageId& aExternalImageId) {
MOZ_ASSERT(mExternalImageId.isSome());
if (!mSurface) {
return;
}

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

@ -72,6 +72,8 @@ gfx::ColorRange MacIOSurfaceTextureHostOGL::GetColorRange() const {
void MacIOSurfaceTextureHostOGL::CreateRenderTexture(
const wr::ExternalImageId& aExternalImageId) {
MOZ_ASSERT(mExternalImageId.isSome());
RefPtr<wr::RenderTextureHost> texture =
new wr::RenderMacIOSurfaceTextureHost(GetMacIOSurface());

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

@ -536,6 +536,8 @@ void SurfaceTextureHost::DeallocateDeviceData() {
void SurfaceTextureHost::CreateRenderTexture(
const wr::ExternalImageId& aExternalImageId) {
MOZ_ASSERT(mExternalImageId.isSome());
bool isRemoteTexture = !!(mFlags & TextureFlags::REMOTE_TEXTURE);
RefPtr<wr::RenderTextureHost> texture =
new wr::RenderAndroidSurfaceTextureHost(
@ -828,6 +830,8 @@ AndroidHardwareBufferTextureHost::GetAndResetReleaseFence() {
void AndroidHardwareBufferTextureHost::CreateRenderTexture(
const wr::ExternalImageId& aExternalImageId) {
MOZ_ASSERT(mExternalImageId.isSome());
RefPtr<wr::RenderTextureHost> texture =
new wr::RenderAndroidHardwareBufferTextureHost(mAndroidHardwareBuffer);
wr::RenderThread::Get()->RegisterExternalImage(aExternalImageId,
@ -987,6 +991,8 @@ gfx::SurfaceFormat EGLImageTextureHost::GetFormat() const {
void EGLImageTextureHost::CreateRenderTexture(
const wr::ExternalImageId& aExternalImageId) {
MOZ_ASSERT(mExternalImageId.isSome());
RefPtr<wr::RenderTextureHost> texture =
new wr::RenderEGLImageTextureHost(mImage, mSync, mSize);
wr::RenderThread::Get()->RegisterExternalImage(aExternalImageId,

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

@ -99,6 +99,12 @@ gfx::SurfaceFormat WebRenderTextureHost::GetFormat() const {
return mWrappedTextureHost->GetFormat();
}
void WebRenderTextureHost::MaybeDestroyRenderTexture() {
// WebRenderTextureHost does not create RenderTexture, then
// WebRenderTextureHost does not need to destroy RenderTexture.
mExternalImageId = Nothing();
}
void WebRenderTextureHost::NotifyNotUsed() {
#ifdef MOZ_WIDGET_ANDROID
// When SurfaceTextureHost is wrapped by RemoteTextureHostWrapper,

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

@ -55,6 +55,8 @@ class WebRenderTextureHost : public TextureHost {
const char* Name() override { return "WebRenderTextureHost"; }
#endif
void MaybeDestroyRenderTexture() override;
WebRenderTextureHost* AsWebRenderTextureHost() override { return this; }
RemoteTextureHostWrapper* AsRemoteTextureHostWrapper() override {