diff --git a/gfx/layers/ImageContainer.cpp b/gfx/layers/ImageContainer.cpp index 8d51ce7c6944..e977f69143be 100644 --- a/gfx/layers/ImageContainer.cpp +++ b/gfx/layers/ImageContainer.cpp @@ -490,14 +490,17 @@ PlanarYCbCrImage::CopyData(const Data& aData) mData = aData; // update buffer size - mBufferSize = mData.mCbCrStride * mData.mCbCrSize.height * 2 + + size_t size = mData.mCbCrStride * mData.mCbCrSize.height * 2 + mData.mYStride * mData.mYSize.height; // get new buffer - mBuffer = AllocateBuffer(mBufferSize); + mBuffer = AllocateBuffer(size); if (!mBuffer) return; + // update buffer size + mBufferSize = size; + mData.mYChannel = mBuffer; mData.mCbChannel = mData.mYChannel + mData.mYStride * mData.mYSize.height; mData.mCrChannel = mData.mCbChannel + mData.mCbCrStride * mData.mCbCrSize.height; @@ -536,11 +539,12 @@ PlanarYCbCrImage::SetDataNoCopy(const Data &aData) uint8_t* PlanarYCbCrImage::AllocateAndGetNewBuffer(uint32_t aSize) { - // update buffer size - mBufferSize = aSize; - // get new buffer - mBuffer = AllocateBuffer(mBufferSize); + mBuffer = AllocateBuffer(aSize); + if (mBuffer) { + // update buffer size + mBufferSize = aSize; + } return mBuffer; } diff --git a/gfx/layers/ipc/SharedPlanarYCbCrImage.cpp b/gfx/layers/ipc/SharedPlanarYCbCrImage.cpp index a842f5d7ee00..3f7e969a1cf6 100644 --- a/gfx/layers/ipc/SharedPlanarYCbCrImage.cpp +++ b/gfx/layers/ipc/SharedPlanarYCbCrImage.cpp @@ -126,14 +126,16 @@ SharedPlanarYCbCrImage::AllocateAndGetNewBuffer(uint32_t aSize) { NS_ABORT_IF_FALSE(!mTextureClient->IsAllocated(), "This image already has allocated data"); size_t size = YCbCrImageDataSerializer::ComputeMinBufferSize(aSize); + + // get new buffer _without_ setting mBuffer. + if (!mTextureClient->Allocate(size)) { + return nullptr; + } + // update buffer size mBufferSize = size; - // get new buffer _without_ setting mBuffer. - bool status = mTextureClient->Allocate(mBufferSize); - MOZ_ASSERT(status); YCbCrImageDataSerializer serializer(mTextureClient->GetBuffer()); - return serializer.GetData(); } @@ -248,17 +250,19 @@ DeprecatedSharedPlanarYCbCrImage::AllocateAndGetNewBuffer(uint32_t aSize) { NS_ABORT_IF_FALSE(!mAllocated, "This image already has allocated data"); size_t size = YCbCrImageDataSerializer::ComputeMinBufferSize(aSize); + + // get new buffer _without_ setting mBuffer. + if (!AllocateBuffer(size)) { + return nullptr; + } + // update buffer size mBufferSize = size; - // get new buffer _without_ setting mBuffer. - AllocateBuffer(mBufferSize); YCbCrImageDataSerializer serializer(mShmem.get()); - return serializer.GetData(); } - void DeprecatedSharedPlanarYCbCrImage::SetDataNoCopy(const Data &aData) {