summaryrefslogtreecommitdiffstats
path: root/gfx/layers/ImageDataSerializer.cpp
diff options
context:
space:
mode:
authorwolfbeast <mcwerewolf@gmail.com>2018-06-07 06:21:57 +0200
committerwolfbeast <mcwerewolf@gmail.com>2018-06-07 06:21:57 +0200
commitbd0e550e63c646dc5c515caf52aedad8bc29f9bd (patch)
tree2a5131e409e23f73ef5a8f79fd3d53484c3f7a7f /gfx/layers/ImageDataSerializer.cpp
parente810c8a5c0b116d7214c786186f0478a7f70ff64 (diff)
downloadUXP-bd0e550e63c646dc5c515caf52aedad8bc29f9bd.tar
UXP-bd0e550e63c646dc5c515caf52aedad8bc29f9bd.tar.gz
UXP-bd0e550e63c646dc5c515caf52aedad8bc29f9bd.tar.lz
UXP-bd0e550e63c646dc5c515caf52aedad8bc29f9bd.tar.xz
UXP-bd0e550e63c646dc5c515caf52aedad8bc29f9bd.zip
Account for offsets when creating buffers for image textures.
Diffstat (limited to 'gfx/layers/ImageDataSerializer.cpp')
-rw-r--r--gfx/layers/ImageDataSerializer.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/gfx/layers/ImageDataSerializer.cpp b/gfx/layers/ImageDataSerializer.cpp
index 08ed83bd9..db11e903c 100644
--- a/gfx/layers/ImageDataSerializer.cpp
+++ b/gfx/layers/ImageDataSerializer.cpp
@@ -84,6 +84,41 @@ ComputeYCbCrBufferSize(const gfx::IntSize& aYSize, const gfx::IntSize& aCbCrSize
}
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)
{
return GetAlignedStride<4>(aBufferSize, 1);