From 2d4ee6fb002672ded900f9a376b1067790bdf2e9 Mon Sep 17 00:00:00 2001 From: sotaro Date: Tue, 16 Aug 2022 00:29:51 +0000 Subject: [PATCH] Bug 1769254 - Add TextureHost type check for using update in AsyncImagePipelineManager::UpdateImageKeys() r=gfx-reviewers,lsalzman The UpdateImageKeys() did not detect TextureHost change from MacIOSurfaceTextureHostOGL to ShmemTextureHost with same format and size. If we want to use TransactionBuilder::UpdateExternalImage(), TextureHost type needs to be same. Differential Revision: https://phabricator.services.mozilla.com/D154495 --- gfx/layers/DcompSurfaceImage.cpp | 2 +- gfx/layers/NativeLayerCA.mm | 1 + gfx/layers/composite/GPUVideoTextureHost.cpp | 9 ++++++++- gfx/layers/composite/GPUVideoTextureHost.h | 2 ++ gfx/layers/composite/TextureHost.cpp | 5 +++-- gfx/layers/composite/TextureHost.h | 20 ++++++++++++++++++- gfx/layers/d3d11/TextureD3D11.cpp | 4 ++-- gfx/layers/opengl/DMABUFTextureHostOGL.cpp | 2 +- .../opengl/MacIOSurfaceTextureHostOGL.cpp | 2 +- gfx/layers/opengl/TextureHostOGL.cpp | 8 ++++---- gfx/layers/wr/AsyncImagePipelineManager.cpp | 4 +++- gfx/layers/wr/WebRenderTextureHost.cpp | 7 ++++++- gfx/layers/wr/WebRenderTextureHost.h | 2 ++ 13 files changed, 53 insertions(+), 15 deletions(-) diff --git a/gfx/layers/DcompSurfaceImage.cpp b/gfx/layers/DcompSurfaceImage.cpp index dd0c432b148c..70458fd8f04d 100644 --- a/gfx/layers/DcompSurfaceImage.cpp +++ b/gfx/layers/DcompSurfaceImage.cpp @@ -74,7 +74,7 @@ TextureClient* DcompSurfaceImage::GetTextureClient( DcompSurfaceHandleHost::DcompSurfaceHandleHost( TextureFlags aFlags, const SurfaceDescriptorDcompSurface& aDescriptor) - : TextureHost(aFlags), + : TextureHost(TextureHostType::DcompSurface, aFlags), mHandle(const_cast(aDescriptor.handle()) .TakePlatformHandle()), mSize(aDescriptor.size()), diff --git a/gfx/layers/NativeLayerCA.mm b/gfx/layers/NativeLayerCA.mm index d7be9c320445..5cbeeaffe47c 100644 --- a/gfx/layers/NativeLayerCA.mm +++ b/gfx/layers/NativeLayerCA.mm @@ -806,6 +806,7 @@ void NativeLayerCA::AttachExternalImage(wr::RenderTextureHost* aExternalImage) { MOZ_ASSERT(texture); mTextureHost = texture; if (!mTextureHost) { + gfxCriticalNoteOnce << "ExternalImage is not RenderMacIOSurfaceTextureHost"; return; } diff --git a/gfx/layers/composite/GPUVideoTextureHost.cpp b/gfx/layers/composite/GPUVideoTextureHost.cpp index 222af8bfbb70..bf56f12e4ad8 100644 --- a/gfx/layers/composite/GPUVideoTextureHost.cpp +++ b/gfx/layers/composite/GPUVideoTextureHost.cpp @@ -18,7 +18,7 @@ namespace layers { GPUVideoTextureHost::GPUVideoTextureHost( TextureFlags aFlags, const SurfaceDescriptorGPUVideo& aDescriptor) - : TextureHost(aFlags), mDescriptor(aDescriptor) { + : TextureHost(TextureHostType::Unknown, aFlags), mDescriptor(aDescriptor) { MOZ_COUNT_CTOR(GPUVideoTextureHost); } @@ -206,5 +206,12 @@ bool GPUVideoTextureHost::IsWrappingBufferTextureHost() { return false; } +TextureHostType GPUVideoTextureHost::GetTextureHostType() { + if (!mWrappedTextureHost) { + return TextureHostType::Unknown; + } + return mWrappedTextureHost->GetTextureHostType(); +} + } // namespace layers } // namespace mozilla diff --git a/gfx/layers/composite/GPUVideoTextureHost.h b/gfx/layers/composite/GPUVideoTextureHost.h index ce1f655ceec3..299a2019bc12 100644 --- a/gfx/layers/composite/GPUVideoTextureHost.h +++ b/gfx/layers/composite/GPUVideoTextureHost.h @@ -65,6 +65,8 @@ class GPUVideoTextureHost : public TextureHost { bool IsWrappingBufferTextureHost() override; + TextureHostType GetTextureHostType() override; + protected: GPUVideoTextureHost(TextureFlags aFlags, const SurfaceDescriptorGPUVideo& aDescriptor); diff --git a/gfx/layers/composite/TextureHost.cpp b/gfx/layers/composite/TextureHost.cpp index 48194871eb85..e4df3ed2591d 100644 --- a/gfx/layers/composite/TextureHost.cpp +++ b/gfx/layers/composite/TextureHost.cpp @@ -347,8 +347,9 @@ already_AddRefed CreateBackendIndependentTextureHost( return result.forget(); } -TextureHost::TextureHost(TextureFlags aFlags) +TextureHost::TextureHost(TextureHostType aType, TextureFlags aFlags) : AtomicRefCountedWithFinalize("TextureHost"), + mTextureHostType(aType), mActor(nullptr), mFlags(aFlags), mCompositableCount(0), @@ -454,7 +455,7 @@ TextureSource::TextureSource() : mCompositableCount(0) {} TextureSource::~TextureSource() = default; BufferTextureHost::BufferTextureHost(const BufferDescriptor& aDesc, TextureFlags aFlags) - : TextureHost(aFlags), mLocked(false) { + : TextureHost(TextureHostType::Buffer, aFlags), mLocked(false) { mDescriptor = aDesc; switch (mDescriptor.type()) { case BufferDescriptor::TYCbCrDescriptor: { diff --git a/gfx/layers/composite/TextureHost.h b/gfx/layers/composite/TextureHost.h index 964215108042..22f19909319a 100644 --- a/gfx/layers/composite/TextureHost.h +++ b/gfx/layers/composite/TextureHost.h @@ -349,6 +349,21 @@ class DataTextureSource : public TextureSource { uint32_t mUpdateSerial; }; +enum class TextureHostType : int8_t { + Unknown = 0, + Buffer, + DXGI, + DXGIYCbCr, + DcompSurface, + DMABUF, + MacIOSurface, + AndroidSurfaceTexture, + AndroidHardwareBuffer, + EGLImage, + GLTexture, + Last +}; + /** * TextureHost is a thin abstraction over texture data that need to be shared * between the content process and the compositor process. It is the @@ -389,7 +404,7 @@ class TextureHost : public AtomicRefCountedWithFinalize { friend class AtomicRefCountedWithFinalize; public: - explicit TextureHost(TextureFlags aFlags); + TextureHost(TextureHostType aType, TextureFlags aFlags); protected: virtual ~TextureHost(); @@ -671,6 +686,8 @@ class TextureHost : public AtomicRefCountedWithFinalize { return false; } + virtual TextureHostType GetTextureHostType() { return mTextureHostType; } + // Our WebRender backend may impose restrictions on whether textures are // prepared as native textures or not, or it may have no restriction at // all. This enumerates those possibilities. @@ -715,6 +732,7 @@ class TextureHost : public AtomicRefCountedWithFinalize { // for Compositor. void CallNotifyNotUsed(); + TextureHostType mTextureHostType; PTextureParent* mActor; RefPtr mReadLock; TextureFlags mFlags; diff --git a/gfx/layers/d3d11/TextureD3D11.cpp b/gfx/layers/d3d11/TextureD3D11.cpp index 788153ee307d..fc30ee50a89b 100644 --- a/gfx/layers/d3d11/TextureD3D11.cpp +++ b/gfx/layers/d3d11/TextureD3D11.cpp @@ -806,7 +806,7 @@ bool D3D11TextureData::UpdateFromSurface(gfx::SourceSurface* aSurface) { DXGITextureHostD3D11::DXGITextureHostD3D11( TextureFlags aFlags, const SurfaceDescriptorD3D10& aDescriptor) - : TextureHost(aFlags), + : TextureHost(TextureHostType::DXGI, aFlags), mGpuProcessTextureId(aDescriptor.gpuProcessTextureId()), mArrayIndex(aDescriptor.arrayIndex()), mSize(aDescriptor.size()), @@ -1118,7 +1118,7 @@ bool DXGITextureHostD3D11::SupportsExternalCompositing( DXGIYCbCrTextureHostD3D11::DXGIYCbCrTextureHostD3D11( TextureFlags aFlags, const SurfaceDescriptorDXGIYCbCr& aDescriptor) - : TextureHost(aFlags), + : TextureHost(TextureHostType::DXGIYCbCr, aFlags), mSize(aDescriptor.size()), mSizeY(aDescriptor.sizeY()), mSizeCbCr(aDescriptor.sizeCbCr()), diff --git a/gfx/layers/opengl/DMABUFTextureHostOGL.cpp b/gfx/layers/opengl/DMABUFTextureHostOGL.cpp index dff6455d6415..19202038e82f 100644 --- a/gfx/layers/opengl/DMABUFTextureHostOGL.cpp +++ b/gfx/layers/opengl/DMABUFTextureHostOGL.cpp @@ -15,7 +15,7 @@ namespace mozilla::layers { DMABUFTextureHostOGL::DMABUFTextureHostOGL(TextureFlags aFlags, const SurfaceDescriptor& aDesc) - : TextureHost(aFlags) { + : TextureHost(TextureHostType::DMABUF, aFlags) { MOZ_COUNT_CTOR(DMABUFTextureHostOGL); // DMABufSurface::CreateDMABufSurface() can fail, for instance when we're run diff --git a/gfx/layers/opengl/MacIOSurfaceTextureHostOGL.cpp b/gfx/layers/opengl/MacIOSurfaceTextureHostOGL.cpp index 072619f31760..7f2800549953 100644 --- a/gfx/layers/opengl/MacIOSurfaceTextureHostOGL.cpp +++ b/gfx/layers/opengl/MacIOSurfaceTextureHostOGL.cpp @@ -17,7 +17,7 @@ namespace layers { MacIOSurfaceTextureHostOGL::MacIOSurfaceTextureHostOGL( TextureFlags aFlags, const SurfaceDescriptorMacIOSurface& aDescriptor) - : TextureHost(aFlags) { + : TextureHost(TextureHostType::MacIOSurface, aFlags) { MOZ_COUNT_CTOR(MacIOSurfaceTextureHostOGL); mSurface = MacIOSurface::LookupSurface(aDescriptor.surfaceId(), !aDescriptor.isOpaque(), diff --git a/gfx/layers/opengl/TextureHostOGL.cpp b/gfx/layers/opengl/TextureHostOGL.cpp index 5bdd1b669d5a..66ef93202940 100644 --- a/gfx/layers/opengl/TextureHostOGL.cpp +++ b/gfx/layers/opengl/TextureHostOGL.cpp @@ -489,7 +489,7 @@ SurfaceTextureHost::SurfaceTextureHost( TextureFlags aFlags, mozilla::java::GeckoSurfaceTexture::Ref& aSurfTex, gfx::IntSize aSize, gfx::SurfaceFormat aFormat, bool aContinuousUpdate, bool aIgnoreTransform) - : TextureHost(aFlags), + : TextureHost(TextureHostType::AndroidSurfaceTexture, aFlags), mSurfTex(aSurfTex), mSize(aSize), mFormat(aFormat), @@ -662,7 +662,7 @@ AndroidHardwareBufferTextureHost::Create( AndroidHardwareBufferTextureHost::AndroidHardwareBufferTextureHost( TextureFlags aFlags, AndroidHardwareBuffer* aAndroidHardwareBuffer) - : TextureHost(aFlags), + : TextureHost(TextureHostType::AndroidHardwareBuffer, aFlags), mAndroidHardwareBuffer(aAndroidHardwareBuffer), mEGLImage(EGL_NO_IMAGE) {} @@ -857,7 +857,7 @@ gfx::Matrix4x4 EGLImageTextureSource::GetTextureTransform() { EGLImageTextureHost::EGLImageTextureHost(TextureFlags aFlags, EGLImage aImage, EGLSync aSync, gfx::IntSize aSize, bool hasAlpha) - : TextureHost(aFlags), + : TextureHost(TextureHostType::EGLImage, aFlags), mImage(aImage), mSync(aSync), mSize(aSize), @@ -920,7 +920,7 @@ void EGLImageTextureHost::PushDisplayItems( GLTextureHost::GLTextureHost(TextureFlags aFlags, GLuint aTextureHandle, GLenum aTarget, GLsync aSync, gfx::IntSize aSize, bool aHasAlpha) - : TextureHost(aFlags), + : TextureHost(TextureHostType::GLTexture, aFlags), mTexture(aTextureHandle), mTarget(aTarget), mSync(aSync), diff --git a/gfx/layers/wr/AsyncImagePipelineManager.cpp b/gfx/layers/wr/AsyncImagePipelineManager.cpp index c1c8bb39cac2..2793b178f078 100644 --- a/gfx/layers/wr/AsyncImagePipelineManager.cpp +++ b/gfx/layers/wr/AsyncImagePipelineManager.cpp @@ -252,7 +252,9 @@ Maybe AsyncImagePipelineManager::UpdateImageKeys( // the image keys than create new ones. auto backend = aSceneBuilderTxn.GetBackendType(); bool canUpdate = - !!previousTexture && previousTexture->GetSize() == texture->GetSize() && + !!previousTexture && + previousTexture->GetTextureHostType() == texture->GetTextureHostType() && + previousTexture->GetSize() == texture->GetSize() && previousTexture->GetFormat() == texture->GetFormat() && previousTexture->GetColorDepth() == texture->GetColorDepth() && previousTexture->NeedsYFlip() == texture->NeedsYFlip() && diff --git a/gfx/layers/wr/WebRenderTextureHost.cpp b/gfx/layers/wr/WebRenderTextureHost.cpp index 22eee09cbccc..d21602b7107d 100644 --- a/gfx/layers/wr/WebRenderTextureHost.cpp +++ b/gfx/layers/wr/WebRenderTextureHost.cpp @@ -37,7 +37,8 @@ class ScheduleHandleRenderTextureOps : public wr::NotificationHandler { WebRenderTextureHost::WebRenderTextureHost( TextureFlags aFlags, TextureHost* aTexture, const wr::ExternalImageId& aExternalImageId) - : TextureHost(aFlags), mWrappedTextureHost(aTexture) { + : TextureHost(TextureHostType::Unknown, aFlags), + mWrappedTextureHost(aTexture) { MOZ_ASSERT(mWrappedTextureHost); // The wrapped textureHost will be used in WebRender, and the WebRender could // run at another thread. It's hard to control the life-time when gecko @@ -195,4 +196,8 @@ AndroidHardwareBuffer* WebRenderTextureHost::GetAndroidHardwareBuffer() const { return mWrappedTextureHost->GetAndroidHardwareBuffer(); } +TextureHostType WebRenderTextureHost::GetTextureHostType() { + return mWrappedTextureHost->GetTextureHostType(); +} + } // namespace mozilla::layers diff --git a/gfx/layers/wr/WebRenderTextureHost.h b/gfx/layers/wr/WebRenderTextureHost.h index 8acfcbf3259c..af2ce1f2916a 100644 --- a/gfx/layers/wr/WebRenderTextureHost.h +++ b/gfx/layers/wr/WebRenderTextureHost.h @@ -92,6 +92,8 @@ class WebRenderTextureHost : public TextureHost { void MaybeNotifyForUse(wr::TransactionBuilder& aTxn); + TextureHostType GetTextureHostType() override; + const RefPtr mWrappedTextureHost; };