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
This commit is contained in:
sotaro 2022-08-16 00:29:51 +00:00
parent 181da530ee
commit 2d4ee6fb00
13 changed files with 53 additions and 15 deletions

View File

@ -74,7 +74,7 @@ TextureClient* DcompSurfaceImage::GetTextureClient(
DcompSurfaceHandleHost::DcompSurfaceHandleHost(
TextureFlags aFlags, const SurfaceDescriptorDcompSurface& aDescriptor)
: TextureHost(aFlags),
: TextureHost(TextureHostType::DcompSurface, aFlags),
mHandle(const_cast<ipc::FileDescriptor&>(aDescriptor.handle())
.TakePlatformHandle()),
mSize(aDescriptor.size()),

View File

@ -806,6 +806,7 @@ void NativeLayerCA::AttachExternalImage(wr::RenderTextureHost* aExternalImage) {
MOZ_ASSERT(texture);
mTextureHost = texture;
if (!mTextureHost) {
gfxCriticalNoteOnce << "ExternalImage is not RenderMacIOSurfaceTextureHost";
return;
}

View File

@ -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

View File

@ -65,6 +65,8 @@ class GPUVideoTextureHost : public TextureHost {
bool IsWrappingBufferTextureHost() override;
TextureHostType GetTextureHostType() override;
protected:
GPUVideoTextureHost(TextureFlags aFlags,
const SurfaceDescriptorGPUVideo& aDescriptor);

View File

@ -347,8 +347,9 @@ already_AddRefed<TextureHost> 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: {

View File

@ -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<TextureHost> {
friend class AtomicRefCountedWithFinalize<TextureHost>;
public:
explicit TextureHost(TextureFlags aFlags);
TextureHost(TextureHostType aType, TextureFlags aFlags);
protected:
virtual ~TextureHost();
@ -671,6 +686,8 @@ class TextureHost : public AtomicRefCountedWithFinalize<TextureHost> {
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<TextureHost> {
// for Compositor.
void CallNotifyNotUsed();
TextureHostType mTextureHostType;
PTextureParent* mActor;
RefPtr<TextureReadLock> mReadLock;
TextureFlags mFlags;

View File

@ -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()),

View File

@ -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

View File

@ -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(),

View File

@ -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),

View File

@ -252,7 +252,9 @@ Maybe<TextureHost::ResourceUpdateOp> 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() &&

View File

@ -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

View File

@ -92,6 +92,8 @@ class WebRenderTextureHost : public TextureHost {
void MaybeNotifyForUse(wr::TransactionBuilder& aTxn);
TextureHostType GetTextureHostType() override;
const RefPtr<TextureHost> mWrappedTextureHost;
};