WebKit Bugzilla
Attachment 362445 Details for
Bug 194746
: drawImage() clears the canvas if it's the source of the image and globalCompositeOperation is "copy"
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch
bug-194746-20190219153040.patch (text/plain), 6.34 KB, created by
Said Abou-Hallawa
on 2019-02-19 15:30:41 PST
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Said Abou-Hallawa
Created:
2019-02-19 15:30:41 PST
Size:
6.34 KB
patch
obsolete
>Index: Source/WebCore/ChangeLog >=================================================================== >--- Source/WebCore/ChangeLog (revision 241779) >+++ Source/WebCore/ChangeLog (working copy) >@@ -1,3 +1,21 @@ >+2019-02-19 Said Abou-Hallawa <sabouhallawa@apple.com> >+ >+ drawImage() clears the canvas if it's the source of the image and globalCompositeOperation is "copy" >+ https://bugs.webkit.org/show_bug.cgi?id=194746 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ Test: fast/canvas/canvas-drawImage-composite-copy.html >+ >+ If the canvas if it's the source of the image and globalCompositeOperation >+ is set to "copy", copy the srcRect from the canvas to a temporary buffer >+ before calling clearCanvas(). >+ >+ * html/canvas/CanvasRenderingContext2DBase.cpp: >+ (WebCore::CanvasRenderingContext2DBase::drawCanvasToBuffer const): >+ (WebCore::CanvasRenderingContext2DBase::drawImage): >+ * html/canvas/CanvasRenderingContext2DBase.h: >+ > 2019-02-19 Zalan Bujtas <zalan@apple.com> > > Fix post-commit feedback. >Index: Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp >=================================================================== >--- Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp (revision 241779) >+++ Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp (working copy) >@@ -1599,6 +1599,22 @@ ExceptionOr<void> CanvasRenderingContext > return { }; > } > >+std::unique_ptr<ImageBuffer> CanvasRenderingContext2DBase::drawCanvasToBuffer(const FloatRect& srcRect) const >+{ >+ auto dstBuffer = ImageBuffer::create(srcRect.size(), drawingContext() ? drawingContext()->renderingMode() : Accelerated); >+ if (!dstBuffer) >+ return nullptr; >+ >+ auto& canvas = downcast<HTMLCanvasElement>(canvasBase()); >+ ImageBuffer* srcBuffer = canvas.buffer(); >+ if (!srcBuffer) >+ return nullptr; >+ >+ GraphicsContext& dstContext = dstBuffer->context(); >+ dstContext.drawImageBuffer(*srcBuffer, -srcRect.location()); >+ return dstBuffer; >+} >+ > ExceptionOr<void> CanvasRenderingContext2DBase::drawImage(HTMLCanvasElement& sourceCanvas, const FloatRect& srcRect, const FloatRect& dstRect) > { > FloatRect srcCanvasRect = FloatRect(FloatPoint(), sourceCanvas.size()); >@@ -1643,8 +1659,14 @@ ExceptionOr<void> CanvasRenderingContext > fullCanvasCompositedDrawImage(*buffer, dstRect, srcRect, state().globalComposite); > didDrawEntireCanvas(); > } else if (state().globalComposite == CompositeCopy) { >- clearCanvas(); >- c->drawImageBuffer(*buffer, dstRect, srcRect, ImagePaintingOptions(state().globalComposite, state().globalBlend)); >+ if (&sourceCanvas == &canvasBase()) { >+ auto imageBuffer = drawCanvasToBuffer(srcRect); >+ clearCanvas(); >+ c->drawImageBuffer(*imageBuffer, dstRect, { { }, srcRect.size() }, ImagePaintingOptions(state().globalComposite, state().globalBlend)); >+ } else { >+ clearCanvas(); >+ c->drawImageBuffer(*buffer, dstRect, srcRect, ImagePaintingOptions(state().globalComposite, state().globalBlend)); >+ } > didDrawEntireCanvas(); > } else { > c->drawImageBuffer(*buffer, dstRect, srcRect, ImagePaintingOptions(state().globalComposite, state().globalBlend)); >Index: Source/WebCore/html/canvas/CanvasRenderingContext2DBase.h >=================================================================== >--- Source/WebCore/html/canvas/CanvasRenderingContext2DBase.h (revision 241779) >+++ Source/WebCore/html/canvas/CanvasRenderingContext2DBase.h (working copy) >@@ -367,6 +367,8 @@ protected: > > void prepareGradientForDashboard(CanvasGradient&) const; > >+ std::unique_ptr<ImageBuffer> drawCanvasToBuffer(const FloatRect&) const; >+ > ExceptionOr<RefPtr<ImageData>> getImageData(ImageBuffer::CoordinateSystem, float sx, float sy, float sw, float sh) const; > void putImageData(ImageData&, ImageBuffer::CoordinateSystem, float dx, float dy, float dirtyX, float dirtyY, float dirtyWidth, float dirtyHeight); > >Index: LayoutTests/ChangeLog >=================================================================== >--- LayoutTests/ChangeLog (revision 241779) >+++ LayoutTests/ChangeLog (working copy) >@@ -1,3 +1,13 @@ >+2019-02-19 Said Abou-Hallawa <sabouhallawa@apple.com> >+ >+ drawImage() clears the canvas if it's the source of the image and globalCompositeOperation is "copy" >+ https://bugs.webkit.org/show_bug.cgi?id=194746 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ * fast/canvas/canvas-drawImage-composite-copy-expected.html: Added. >+ * fast/canvas/canvas-drawImage-composite-copy.html: Added. >+ > 2019-02-19 Truitt Savell <tsavell@apple.com> > > [ iOS ] Layout Tests in editing/pasteboard/data-transfer-set-data-* are flaky Timeouts >Index: LayoutTests/fast/canvas/canvas-drawImage-composite-copy-expected.html >=================================================================== >--- LayoutTests/fast/canvas/canvas-drawImage-composite-copy-expected.html (nonexistent) >+++ LayoutTests/fast/canvas/canvas-drawImage-composite-copy-expected.html (working copy) >@@ -0,0 +1,12 @@ >+<body> >+ <canvas id="canvas" width="200" height="200"></canvas> >+ <script> >+ const canvas = document.getElementById("canvas"); >+ const ctx = canvas.getContext("2d"); >+ const width = canvas.width; >+ const height = canvas.height; >+ >+ ctx.fillStyle = "green"; >+ ctx.fillRect(0, 0, width / 2, height / 2); >+ </script> >+</body> >Index: LayoutTests/fast/canvas/canvas-drawImage-composite-copy.html >=================================================================== >--- LayoutTests/fast/canvas/canvas-drawImage-composite-copy.html (nonexistent) >+++ LayoutTests/fast/canvas/canvas-drawImage-composite-copy.html (working copy) >@@ -0,0 +1,21 @@ >+<body> >+ <canvas id="canvas" width="200" height="200"></canvas> >+ <script> >+ const canvas = document.getElementById("canvas"); >+ const ctx = canvas.getContext("2d"); >+ const width = canvas.width; >+ const height = canvas.height; >+ >+ ctx.fillStyle = "green"; >+ ctx.fillRect(width / 2, height / 2, width / 2, height / 2); >+ >+ ctx.globalCompositeOperation = "copy"; >+ ctx.imageSmoothingEnabled = false; >+ >+ ctx.drawImage( >+ canvas, >+ width / 2, height / 2, width / 2, height / 2, >+ 0, 0, width / 2, height / 2 >+ ); >+ </script> >+</body>
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 194746
:
362445
|
362522