diff options
author | Matt A. Tobin <email@mattatobin.com> | 2022-06-07 20:20:19 -0500 |
---|---|---|
committer | Matt A. Tobin <email@mattatobin.com> | 2022-06-07 20:20:19 -0500 |
commit | 878ab758d5d4c1ef7badf2bc20ebc7c67dc2165b (patch) | |
tree | 3683d6df35e3618c0e7b456de7c749ca4c8c21a6 /dom/canvas | |
parent | a621951327b0c19c0c24dfd9fd973f7bd13ae68f (diff) | |
parent | cfb9884423faf741de03c5fcc72bf9ac8c6ada4d (diff) | |
download | aura-central-878ab758d5d4c1ef7badf2bc20ebc7c67dc2165b.tar.gz |
Merge branch 'TRUNK' into ARE-5.0
Diffstat (limited to 'dom/canvas')
-rw-r--r-- | dom/canvas/CanvasRenderingContext2D.cpp | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/dom/canvas/CanvasRenderingContext2D.cpp b/dom/canvas/CanvasRenderingContext2D.cpp index 7d00b2cb2..8cb14a1f3 100644 --- a/dom/canvas/CanvasRenderingContext2D.cpp +++ b/dom/canvas/CanvasRenderingContext2D.cpp @@ -5745,6 +5745,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, @@ -5785,9 +5797,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()) { @@ -5815,9 +5829,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); @@ -6018,10 +6029,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; } |