From 6d4116acb85bf1e1055f6b9d8ec21ee3a99d4660 Mon Sep 17 00:00:00 2001 From: sotaro Date: Thu, 21 May 2020 18:53:42 +0000 Subject: [PATCH] Bug 1639874 - Fix YCbCrTextureClientAllocationHelper::IsCompatible() r=jrmuizel IsCompatible() also needs to check YStride and CbCrStride. They also affect to buffer size. Differential Revision: https://phabricator.services.mozilla.com/D76323 --- gfx/layers/BufferTexture.cpp | 8 ++++++ gfx/layers/BufferTexture.h | 4 +++ gfx/layers/ImageDataSerializer.cpp | 26 ++++++++++++++++++- gfx/layers/ImageDataSerializer.h | 5 ++++ .../client/TextureClientRecycleAllocator.cpp | 4 +++ gfx/layers/ipc/SharedPlanarYCbCrImage.cpp | 2 +- 6 files changed, 47 insertions(+), 2 deletions(-) diff --git a/gfx/layers/BufferTexture.cpp b/gfx/layers/BufferTexture.cpp index cbdc54611ae8..6881d071860e 100644 --- a/gfx/layers/BufferTexture.cpp +++ b/gfx/layers/BufferTexture.cpp @@ -227,6 +227,14 @@ Maybe BufferTextureData::GetCbCrSize() const { return ImageDataSerializer::CbCrSizeFromBufferDescriptor(mDescriptor); } +Maybe BufferTextureData::GetYStride() const { + return ImageDataSerializer::YStrideFromBufferDescriptor(mDescriptor); +} + +Maybe BufferTextureData::GetCbCrStride() const { + return ImageDataSerializer::CbCrStrideFromBufferDescriptor(mDescriptor); +} + Maybe BufferTextureData::GetYUVColorSpace() const { return ImageDataSerializer::YUVColorSpaceFromBufferDescriptor(mDescriptor); } diff --git a/gfx/layers/BufferTexture.h b/gfx/layers/BufferTexture.h index 50d6d1dc6ac7..eebc6707d98a 100644 --- a/gfx/layers/BufferTexture.h +++ b/gfx/layers/BufferTexture.h @@ -61,6 +61,10 @@ class BufferTextureData : public TextureData { Maybe GetCbCrSize() const; + Maybe GetYStride() const; + + Maybe GetCbCrStride() const; + Maybe GetYUVColorSpace() const; Maybe GetColorDepth() const; diff --git a/gfx/layers/ImageDataSerializer.cpp b/gfx/layers/ImageDataSerializer.cpp index 3098e9dbd319..5f1921bbdf8e 100644 --- a/gfx/layers/ImageDataSerializer.cpp +++ b/gfx/layers/ImageDataSerializer.cpp @@ -154,7 +154,31 @@ Maybe CbCrSizeFromBufferDescriptor( case BufferDescriptor::TYCbCrDescriptor: return Some(aDescriptor.get_YCbCrDescriptor().cbCrSize()); default: - MOZ_CRASH("GFX: CbCrSizeFromBufferDescriptor"); + MOZ_CRASH("GFX: CbCrSizeFromBufferDescriptor"); + } +} + +Maybe YStrideFromBufferDescriptor( + const BufferDescriptor& aDescriptor) { + switch (aDescriptor.type()) { + case BufferDescriptor::TRGBDescriptor: + return Nothing(); + case BufferDescriptor::TYCbCrDescriptor: + return Some(aDescriptor.get_YCbCrDescriptor().yStride()); + default: + MOZ_CRASH("GFX: YStrideFromBufferDescriptor"); + } +} + +Maybe CbCrStrideFromBufferDescriptor( + const BufferDescriptor& aDescriptor) { + switch (aDescriptor.type()) { + case BufferDescriptor::TRGBDescriptor: + return Nothing(); + case BufferDescriptor::TYCbCrDescriptor: + return Some(aDescriptor.get_YCbCrDescriptor().cbCrStride()); + default: + MOZ_CRASH("GFX: CbCrStrideFromBufferDescriptor"); } } diff --git a/gfx/layers/ImageDataSerializer.h b/gfx/layers/ImageDataSerializer.h index f30eb2a9a35c..a8223f8ca86e 100644 --- a/gfx/layers/ImageDataSerializer.h +++ b/gfx/layers/ImageDataSerializer.h @@ -60,6 +60,11 @@ gfx::IntSize SizeFromBufferDescriptor(const BufferDescriptor& aDescriptor); Maybe CbCrSizeFromBufferDescriptor( const BufferDescriptor& aDescriptor); +Maybe YStrideFromBufferDescriptor(const BufferDescriptor& aDescriptor); + +Maybe CbCrStrideFromBufferDescriptor( + const BufferDescriptor& aDescriptor); + Maybe YUVColorSpaceFromBufferDescriptor( const BufferDescriptor& aDescriptor); diff --git a/gfx/layers/client/TextureClientRecycleAllocator.cpp b/gfx/layers/client/TextureClientRecycleAllocator.cpp index f1f1aac82233..a754c5c8c4ca 100644 --- a/gfx/layers/client/TextureClientRecycleAllocator.cpp +++ b/gfx/layers/client/TextureClientRecycleAllocator.cpp @@ -83,6 +83,10 @@ bool YCbCrTextureClientAllocationHelper::IsCompatible( if (!bufferData || aTextureClient->GetSize() != mData.mYSize || bufferData->GetCbCrSize().isNothing() || bufferData->GetCbCrSize().ref() != mData.mCbCrSize || + bufferData->GetYStride().isNothing() || + bufferData->GetYStride().ref() != mData.mYStride || + bufferData->GetCbCrStride().isNothing() || + bufferData->GetCbCrStride().ref() != mData.mCbCrStride || bufferData->GetYUVColorSpace().isNothing() || bufferData->GetYUVColorSpace().ref() != mData.mYUVColorSpace || bufferData->GetColorDepth().isNothing() || diff --git a/gfx/layers/ipc/SharedPlanarYCbCrImage.cpp b/gfx/layers/ipc/SharedPlanarYCbCrImage.cpp index cdf37430924b..8beec0f02d58 100644 --- a/gfx/layers/ipc/SharedPlanarYCbCrImage.cpp +++ b/gfx/layers/ipc/SharedPlanarYCbCrImage.cpp @@ -46,7 +46,7 @@ SharedPlanarYCbCrImage::~SharedPlanarYCbCrImage() { TextureClientRecycleAllocator* SharedPlanarYCbCrImage::RecycleAllocator() { static const uint32_t MAX_POOLED_VIDEO_COUNT = 5; - if (!mRecycleAllocator && mCompositable && mCompositable) { + if (!mRecycleAllocator && mCompositable) { if (!mCompositable->HasTextureClientRecycler()) { // Initialize TextureClientRecycler mCompositable->GetTextureClientRecycler()->SetMaxPoolSize(