summaryrefslogtreecommitdiff
path: root/dom/canvas
diff options
context:
space:
mode:
authorMoonchild <moonchild@palemoon.org>2022-06-01 09:48:54 +0000
committerMoonchild <moonchild@palemoon.org>2022-06-01 09:48:54 +0000
commit9551e4c9bc05cab0e8ba4c20401debe20830fb85 (patch)
tree3b8b059b9439eb8397addf9ea56f442e1af9697f /dom/canvas
parent193b14528a6b8618f49be7954844be135fefe40f (diff)
downloaduxp-9551e4c9bc05cab0e8ba4c20401debe20830fb85.tar.gz
[DOM] Clip image data transfers.
Diffstat (limited to 'dom/canvas')
-rw-r--r--dom/canvas/CanvasRenderingContext2D.cpp31
1 files changed, 21 insertions, 10 deletions
diff --git a/dom/canvas/CanvasRenderingContext2D.cpp b/dom/canvas/CanvasRenderingContext2D.cpp
index 3965d40f83..5ea9c9cea1 100644
--- a/dom/canvas/CanvasRenderingContext2D.cpp
+++ b/dom/canvas/CanvasRenderingContext2D.cpp
@@ -5752,6 +5752,18 @@ inline uint8_t PoisonValue(uint8_t v)
return v + rand() %3 -1;
}
+static IntRect ClipImageDataTransfer(IntRect& aSrc,
+ const IntPoint& aDestOffset,
+ const IntSize& aDestBounds)
+{
+ IntRect dest = aSrc;
+ dest.SafeMoveBy(aDestOffset);
+ dest = IntRect(IntPoint(0, 0), aDestBounds).SafeIntersect(dest);
+
+ aSrc = aSrc.SafeIntersect(dest - aDestOffset);
+ return aSrc + aDestOffset;
+}
+
nsresult
CanvasRenderingContext2D::GetImageDataArray(JSContext* aCx,
int32_t aX,
@@ -5792,9 +5804,11 @@ CanvasRenderingContext2D::GetImageDataArray(JSContext* aCx,
return NS_OK;
}
- IntRect srcRect(0, 0, mWidth, mHeight);
- IntRect destRect(aX, aY, aWidth, aHeight);
- IntRect srcReadRect = srcRect.Intersect(destRect);
+ IntRect dstWriteRect(0, 0, aWidth, aHeight);
+ IntRect srcReadRect = ClipImageDataTransfer(dstWriteRect,
+ IntPoint(aX, aY),
+ IntSize(mWidth, mHeight));
+
RefPtr<DataSourceSurface> readback;
DataSourceSurface::MappedSurface rawData;
if (!srcReadRect.IsEmpty()) {
@@ -5822,9 +5836,6 @@ CanvasRenderingContext2D::GetImageDataArray(JSContext* aCx,
}
}
- IntRect dstWriteRect = srcReadRect;
- dstWriteRect.MoveBy(-aX, -aY);
-
JS::AutoCheckCannotGC nogc;
bool isShared;
uint8_t* data = JS_GetUint8ClampedArrayData(darray, &isShared, nogc);
@@ -6025,10 +6036,10 @@ CanvasRenderingContext2D::PutImageData_explicit(int32_t aX, int32_t aY, uint32_t
dirtyRect = imageDataRect;
}
- dirtyRect.MoveBy(IntPoint(aX, aY));
- dirtyRect = IntRect(0, 0, mWidth, mHeight).Intersect(dirtyRect);
-
- if (dirtyRect.Width() <= 0 || dirtyRect.Height() <= 0) {
+ IntRect srcRect = dirtyRect;
+ dirtyRect = ClipImageDataTransfer(srcRect, IntPoint(aX, aY),
+ IntSize(mWidth, mHeight));
+ if (dirtyRect.IsEmpty()) {
return NS_OK;
}