Bug 1753575 - Make BufferTextureData of ffmpeg decoded video recycled again r=gfx-reviewers,nical

Before Bug 1713276  fix, BufferTextureData of ffmpeg decoded video was recycled.
ShmemTextureData::CropYCbCrPlanes() changed BufferDescriptor. And it blocks the BufferTextureData to be recycled. The BufferDescriptor needs to be restored to original value before recycling.

Differential Revision: https://phabricator.services.mozilla.com/D137829
This commit is contained in:
sotaro
2022-02-07 23:15:25 +00:00
parent 4f80c5a4b0
commit 2c6d59afb0
5 changed files with 48 additions and 2 deletions

View File

@@ -98,8 +98,12 @@ class ShmemTextureData : public BufferTextureData {
bool CropYCbCrPlanes(const gfx::IntSize& aYSize,
const gfx::IntSize& aCbCrSize) override;
// Restore original descriptor that might be changed by CropYCbCrPlanes();
void RestoreOriginalDescriptor() override;
protected:
mozilla::ipc::Shmem mShmem;
Maybe<BufferDescriptor> mOrigDescriptor;
};
BufferTextureData* BufferTextureData::Create(
@@ -193,6 +197,10 @@ gfx::IntRect BufferTextureData::GetPictureRect() const {
return ImageDataSerializer::RectFromBufferDescriptor(mDescriptor);
}
Maybe<gfx::IntSize> BufferTextureData::GetYSize() const {
return ImageDataSerializer::YSizeFromBufferDescriptor(mDescriptor);
}
Maybe<gfx::IntSize> BufferTextureData::GetCbCrSize() const {
return ImageDataSerializer::CbCrSizeFromBufferDescriptor(mDescriptor);
}
@@ -521,6 +529,10 @@ bool ShmemTextureData::CropYCbCrPlanes(const gfx::IntSize& aYSize,
return false;
}
MOZ_ASSERT(mOrigDescriptor.isNothing());
// Store original descriptor.
mOrigDescriptor = Some(current);
auto newDescritor = YCbCrDescriptor(
current.display(), aYSize, current.yStride(), aCbCrSize,
current.cbCrStride(), current.yOffset(), current.cbOffset(),
@@ -530,5 +542,13 @@ bool ShmemTextureData::CropYCbCrPlanes(const gfx::IntSize& aYSize,
return true;
}
void ShmemTextureData::RestoreOriginalDescriptor() {
if (mOrigDescriptor.isNothing()) {
return;
}
mDescriptor = mOrigDescriptor.ref();
mOrigDescriptor = Nothing();
}
} // namespace layers
} // namespace mozilla

View File

@@ -54,6 +54,10 @@ class BufferTextureData : public TextureData {
BufferTextureData* AsBufferTextureData() override { return this; }
virtual void RestoreOriginalDescriptor() {}
Maybe<gfx::IntSize> GetYSize() const;
Maybe<gfx::IntSize> GetCbCrSize() const;
Maybe<int32_t> GetYStride() const;
@@ -66,9 +70,10 @@ class BufferTextureData : public TextureData {
Maybe<StereoMode> GetStereoMode() const;
gfx::IntRect GetPictureRect() const;
protected:
gfx::IntSize GetSize() const;
gfx::IntRect GetPictureRect() const;
gfx::SurfaceFormat GetFormat() const;

View File

@@ -160,6 +160,18 @@ gfx::IntRect RectFromBufferDescriptor(const BufferDescriptor& aDescriptor) {
}
}
Maybe<gfx::IntSize> YSizeFromBufferDescriptor(
const BufferDescriptor& aDescriptor) {
switch (aDescriptor.type()) {
case BufferDescriptor::TRGBDescriptor:
return Nothing();
case BufferDescriptor::TYCbCrDescriptor:
return Some(aDescriptor.get_YCbCrDescriptor().ySize());
default:
MOZ_CRASH("GFX: YSizeFromBufferDescriptor");
}
}
Maybe<gfx::IntSize> CbCrSizeFromBufferDescriptor(
const BufferDescriptor& aDescriptor) {
switch (aDescriptor.type()) {

View File

@@ -60,6 +60,9 @@ gfx::IntSize SizeFromBufferDescriptor(const BufferDescriptor& aDescriptor);
gfx::IntRect RectFromBufferDescriptor(const BufferDescriptor& aDescriptor);
Maybe<gfx::IntSize> YSizeFromBufferDescriptor(
const BufferDescriptor& aDescriptor);
Maybe<gfx::IntSize> CbCrSizeFromBufferDescriptor(
const BufferDescriptor& aDescriptor);

View File

@@ -80,7 +80,13 @@ bool YCbCrTextureClientAllocationHelper::IsCompatible(
BufferTextureData* bufferData =
aTextureClient->GetInternalData()->AsBufferTextureData();
if (!bufferData || aTextureClient->GetSize() != mData.mYSize ||
bufferData->RestoreOriginalDescriptor();
if (!bufferData ||
!bufferData->GetPictureRect().IsEqualEdges(mData.GetPictureRect()) ||
bufferData->GetYSize().isNothing() ||
bufferData->GetYSize().ref() != mData.mYSize ||
bufferData->GetCbCrSize().isNothing() ||
bufferData->GetCbCrSize().ref() != mData.mCbCrSize ||
bufferData->GetYStride().isNothing() ||