WebKit Bugzilla
Attachment 362522 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-20190220120436.patch (text/plain), 6.97 KB, created by
Said Abou-Hallawa
on 2019-02-20 12:04:37 PST
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Said Abou-Hallawa
Created:
2019-02-20 12:04:37 PST
Size:
6.97 KB
patch
obsolete
>Index: Source/WebCore/ChangeLog >=================================================================== >--- Source/WebCore/ChangeLog (revision 241826) >+++ Source/WebCore/ChangeLog (working copy) >@@ -1,3 +1,23 @@ >+2019-02-20 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 Dean Jackson. >+ >+ Test: fast/canvas/canvas-drawImage-composite-copy.html >+ >+ If the source canvas of drawImage() is the same as the destination and >+ globalCompositeOperation is set to "copy", copy the srcRect from the >+ canvas to a temporary buffer before calling clearCanvas() then drawImage >+ from this temporary buffer. >+ >+ * html/canvas/CanvasRenderingContext2DBase.cpp: >+ (WebCore::CanvasRenderingContext2DBase::drawImage): >+ * platform/graphics/ImageBuffer.cpp: >+ (WebCore::ImageBuffer::copyRectToBuffer): >+ * platform/graphics/ImageBuffer.h: >+ > 2019-02-20 Timothy Hatcher <timothy@apple.com> > > RenderThemeIOS should use RenderTheme's color cache instead of its own. >Index: Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp >=================================================================== >--- Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp (revision 241821) >+++ Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp (working copy) >@@ -1643,8 +1643,15 @@ 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()) { >+ if (auto copy = buffer->copyRectToBuffer(srcRect, ColorSpaceSRGB, *c)) { >+ clearCanvas(); >+ c->drawImageBuffer(*copy, 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/platform/graphics/ImageBuffer.cpp >=================================================================== >--- Source/WebCore/platform/graphics/ImageBuffer.cpp (revision 241821) >+++ Source/WebCore/platform/graphics/ImageBuffer.cpp (working copy) >@@ -194,6 +194,21 @@ bool ImageBuffer::copyToPlatformTexture( > } > #endif > >+std::unique_ptr<ImageBuffer> ImageBuffer::copyRectToBuffer(const FloatRect& rect, ColorSpace colorSpace, const GraphicsContext& context) >+{ >+ if (rect.isEmpty()) >+ return nullptr; >+ >+ IntSize scaledSize = ImageBuffer::compatibleBufferSize(rect.size(), context); >+ >+ auto buffer = ImageBuffer::createCompatibleBuffer(scaledSize, 1, colorSpace, context); >+ if (!buffer) >+ return nullptr; >+ >+ buffer->context().drawImageBuffer(*this, -rect.location()); >+ return buffer; >+} >+ > std::unique_ptr<ImageBuffer> ImageBuffer::createCompatibleBuffer(const FloatSize& size, ColorSpace colorSpace, const GraphicsContext& context) > { > if (size.isEmpty()) >Index: Source/WebCore/platform/graphics/ImageBuffer.h >=================================================================== >--- Source/WebCore/platform/graphics/ImageBuffer.h (revision 241821) >+++ Source/WebCore/platform/graphics/ImageBuffer.h (working copy) >@@ -71,6 +71,9 @@ public: > WEBCORE_EXPORT static std::unique_ptr<ImageBuffer> create(const FloatSize&, RenderingMode, const GraphicsContext*, float resolutionScale = 1, ColorSpace = ColorSpaceSRGB, const HostWindow* = nullptr); > #endif > >+ // Create an image buffer compatible with the context and copy rect from this buffer into this new one. >+ std::unique_ptr<ImageBuffer> copyRectToBuffer(const FloatRect&, ColorSpace, const GraphicsContext&); >+ > // Create an image buffer compatible with the context, with suitable resolution for drawing into the buffer and then into this context. > static std::unique_ptr<ImageBuffer> createCompatibleBuffer(const FloatSize&, const GraphicsContext&); > static std::unique_ptr<ImageBuffer> createCompatibleBuffer(const FloatSize&, ColorSpace, const GraphicsContext&); >Index: LayoutTests/ChangeLog >=================================================================== >--- LayoutTests/ChangeLog (revision 241821) >+++ LayoutTests/ChangeLog (working copy) >@@ -1,3 +1,13 @@ >+2019-02-20 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 Dean Jackson. >+ >+ * fast/canvas/canvas-drawImage-composite-copy-expected.html: Added. >+ * fast/canvas/canvas-drawImage-composite-copy.html: Added. >+ > 2019-02-20 Shawn Roberts <sroberts@apple.com> > > REGRESSION (r240727) [ Mac iOS ] Layout Test http/tests/workers/service/basic-register-exceptions.html is flaky >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