Account for offsets when creating buffers for image textures.

This commit is contained in:
wolfbeast 2018-06-07 06:21:57 +02:00 committed by Roy Tam
commit 14c6f518ce
4 changed files with 45 additions and 4 deletions

View file

@ -83,6 +83,41 @@ ComputeYCbCrBufferSize(const gfx::IntSize& aYSize, const gfx::IntSize& aCbCrSize
return ComputeYCbCrBufferSize(aYSize, aYSize.width, aCbCrSize, aCbCrSize.width);
}
uint32_t
ComputeYCbCrBufferSize(const gfx::IntSize& aYSize, const gfx::IntSize& aCbCrSize,
uint32_t aYOffset, uint32_t aCbOffset, uint32_t aCrOffset)
{
MOZ_ASSERT(aYSize.height >= 0 && aYSize.width >= 0);
int32_t yStride = aYSize.width;
int32_t cbCrStride = aCbCrSize.width;
if (aYSize.height < 0 || aYSize.width < 0 || aCbCrSize.height < 0 || aCbCrSize.width < 0 ||
!gfx::Factory::AllowedSurfaceSize(IntSize(yStride, aYSize.height)) ||
!gfx::Factory::AllowedSurfaceSize(IntSize(cbCrStride, aCbCrSize.height))) {
return 0;
}
uint32_t yLength = GetAlignedStride<4>(yStride, aYSize.height);
uint32_t cbCrLength = GetAlignedStride<4>(cbCrStride, aCbCrSize.height);
if (yLength == 0 || cbCrLength == 0) {
return 0;
}
CheckedInt<uint32_t> yEnd = aYOffset;
yEnd += yLength;
CheckedInt<uint32_t> cbEnd = aCbOffset;
cbEnd += cbCrLength;
CheckedInt<uint32_t> crEnd = aCrOffset;
crEnd += cbCrLength;
if (!yEnd.isValid() || !cbEnd.isValid() || !crEnd.isValid() ||
yEnd.value() > aCbOffset || cbEnd.value() > aCrOffset) {
return 0;
}
return crEnd.value();
}
uint32_t
ComputeYCbCrBufferSize(uint32_t aBufferSize)
{