Changeset 241840 in webkit


Ignore:
Timestamp:
Feb 20, 2019 2:28:13 PM (5 years ago)
Author:
commit-queue@webkit.org
Message:

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

Patch by Said Abou-Hallawa <sabouhallawa@apple.com> on 2019-02-20
Reviewed by Dean Jackson.

Source/WebCore:

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:

LayoutTests:

  • fast/canvas/canvas-drawImage-composite-copy-expected.html: Added.
  • fast/canvas/canvas-drawImage-composite-copy.html: Added.
Location:
trunk
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r241836 r241840  
     12019-02-20  Said Abou-Hallawa  <sabouhallawa@apple.com>
     2
     3        drawImage() clears the canvas if it's the source of the image and globalCompositeOperation is "copy"
     4        https://bugs.webkit.org/show_bug.cgi?id=194746
     5
     6        Reviewed by Dean Jackson.
     7
     8        * fast/canvas/canvas-drawImage-composite-copy-expected.html: Added.
     9        * fast/canvas/canvas-drawImage-composite-copy.html: Added.
     10
    1112019-02-20  Shawn Roberts  <sroberts@apple.com>
    212
  • trunk/Source/WebCore/ChangeLog

    r241830 r241840  
     12019-02-20  Said Abou-Hallawa  <sabouhallawa@apple.com>
     2
     3        drawImage() clears the canvas if it's the source of the image and globalCompositeOperation is "copy"
     4        https://bugs.webkit.org/show_bug.cgi?id=194746
     5
     6        Reviewed by Dean Jackson.
     7
     8        Test: fast/canvas/canvas-drawImage-composite-copy.html
     9
     10        If the source canvas of drawImage() is the same as the destination and
     11        globalCompositeOperation is set to "copy", copy the srcRect from the
     12        canvas to a temporary buffer before calling clearCanvas() then drawImage
     13        from this temporary buffer.
     14
     15        * html/canvas/CanvasRenderingContext2DBase.cpp:
     16        (WebCore::CanvasRenderingContext2DBase::drawImage):
     17        * platform/graphics/ImageBuffer.cpp:
     18        (WebCore::ImageBuffer::copyRectToBuffer):
     19        * platform/graphics/ImageBuffer.h:
     20
    1212019-02-20  Simon Fraser  <simon.fraser@apple.com>
    222
  • trunk/Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp

    r239461 r241840  
    16441644        didDrawEntireCanvas();
    16451645    } else if (state().globalComposite == CompositeCopy) {
    1646         clearCanvas();
    1647         c->drawImageBuffer(*buffer, dstRect, srcRect, ImagePaintingOptions(state().globalComposite, state().globalBlend));
     1646        if (&sourceCanvas == &canvasBase()) {
     1647            if (auto copy = buffer->copyRectToBuffer(srcRect, ColorSpaceSRGB, *c)) {
     1648                clearCanvas();
     1649                c->drawImageBuffer(*copy, dstRect, { { }, srcRect.size() }, ImagePaintingOptions(state().globalComposite, state().globalBlend));
     1650            }
     1651        } else {
     1652            clearCanvas();
     1653            c->drawImageBuffer(*buffer, dstRect, srcRect, ImagePaintingOptions(state().globalComposite, state().globalBlend));
     1654        }
    16481655        didDrawEntireCanvas();
    16491656    } else {
  • trunk/Source/WebCore/platform/graphics/ImageBuffer.cpp

    r237977 r241840  
    195195#endif
    196196
     197std::unique_ptr<ImageBuffer> ImageBuffer::copyRectToBuffer(const FloatRect& rect, ColorSpace colorSpace, const GraphicsContext& context)
     198{
     199    if (rect.isEmpty())
     200        return nullptr;
     201
     202    IntSize scaledSize = ImageBuffer::compatibleBufferSize(rect.size(), context);
     203
     204    auto buffer = ImageBuffer::createCompatibleBuffer(scaledSize, 1, colorSpace, context);
     205    if (!buffer)
     206        return nullptr;
     207
     208    buffer->context().drawImageBuffer(*this, -rect.location());
     209    return buffer;
     210}
     211
    197212std::unique_ptr<ImageBuffer> ImageBuffer::createCompatibleBuffer(const FloatSize& size, ColorSpace colorSpace, const GraphicsContext& context)
    198213{
  • trunk/Source/WebCore/platform/graphics/ImageBuffer.h

    r239427 r241840  
    7171    WEBCORE_EXPORT static std::unique_ptr<ImageBuffer> create(const FloatSize&, RenderingMode, const GraphicsContext*, float resolutionScale = 1, ColorSpace = ColorSpaceSRGB, const HostWindow* = nullptr);
    7272#endif
     73
     74    // Create an image buffer compatible with the context and copy rect from this buffer into this new one.
     75    std::unique_ptr<ImageBuffer> copyRectToBuffer(const FloatRect&, ColorSpace, const GraphicsContext&);
    7376
    7477    // Create an image buffer compatible with the context, with suitable resolution for drawing into the buffer and then into this context.
Note: See TracChangeset for help on using the changeset viewer.