Changeset 272549 in webkit


Ignore:
Timestamp:
Feb 8, 2021 2:23:12 PM (18 months ago)
Author:
Said Abou-Hallawa
Message:

A Pattern with an SVG image is not rendered correctly
https://bugs.webkit.org/show_bug.cgi?id=221550

Reviewed by Simon Fraser.

Source/WebCore:

Implement SVGImage::nativeImage() and nativeImageForCurrentFrame() for
all platforms. This will make Pattern::createPlatformPattern() creates
CGPatternRef with a valid CGImageRef.

  • svg/graphics/SVGImage.cpp:

(WebCore::SVGImage::nativeImageForCurrentFrame):
(WebCore::SVGImage::nativeImage):

  • svg/graphics/SVGImage.h:

LayoutTests:

  • imported/blink/svg/canvas/canvas-draw-pattern-size-expected.html:

Change the expected result to not use the pattern in its drawing.

  • imported/blink/svg/canvas/canvas-draw-pattern-size.html:

Use a rectangle instead of a circle to avoid differences with the expected
result due to the edge smoothing.

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r272548 r272549  
     12021-02-08  Said Abou-Hallawa  <said@apple.com>
     2
     3        A Pattern with an SVG image is not rendered correctly
     4        https://bugs.webkit.org/show_bug.cgi?id=221550
     5
     6        Reviewed by Simon Fraser.
     7
     8        * imported/blink/svg/canvas/canvas-draw-pattern-size-expected.html:
     9        Change the expected result to not use the pattern in its drawing.
     10
     11        * imported/blink/svg/canvas/canvas-draw-pattern-size.html:
     12        Use a rectangle instead of a circle to avoid differences with the expected
     13        result due to the edge smoothing.
     14
    1152021-02-08  Jonathan Bedard  <jbedard@apple.com>
    216
  • trunk/LayoutTests/imported/blink/svg/canvas/canvas-draw-pattern-size-expected.html

    r190629 r272549  
    22<html>
    33<head>
    4 <script>
    5 function runTest() {
    6   var context = document.getElementsByTagName('canvas')[0].getContext('2d');
    7   var forceLayout = document.body.offsetWidth;
    8 
    9   var domImage = document.getElementsByTagName('img')[0];
    10   context.drawImage(domImage, 10, 10, 80, 80);
    11 
    12   var newImage = new Image();
    13   newImage.src = domImage.src;
    14   context.fillStyle = context.createPattern(newImage, 'repeat');
    15   context.fillRect(10, 10, 180, 80);
    16 
    17   domImage.parentNode.removeChild(domImage);
    18 }
    19 </script>
    204</head>
    21 <body onload='runTest()'>
     5<body>
    226Test for crbug.com/227481: This test passes if there is a green rectangle with a two blue circles.<br/>
    23 <canvas width="200px" height="100px"></canvas>
    24 <img style="width: 50px;" src="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' width='100' height='100'><rect width='100' height='100' fill='green' /><circle cx='30' cy='30' r='15' fill='blue'/></svg>" >
     7<img style="width: 200px; height: 100px;" src="data:image/svg+xml,
     8    <svg xmlns='http://www.w3.org/2000/svg' width='200' height='100'>
     9        <rect x='10' y='10' width='180' height='80' fill='green'/>
     10        <rect x='15' y='15' width='30' height='30' fill='blue' />
     11        <rect x='115' y='15' width='30' height='30' fill='blue' />
     12    </svg>" >
     13</body>
    2514</body>
    2615</html>
  • trunk/LayoutTests/imported/blink/svg/canvas/canvas-draw-pattern-size.html

    r190629 r272549  
    22<html>
    33<head>
     4<style>
     5    canvas {
     6        image-rendering: pixelated;
     7    }
     8</style>
    49<script>
    510function runTest() {
     
    2227Test for crbug.com/227481: This test passes if there is a green rectangle with a two blue circles.<br/>
    2328<canvas width="200px" height="100px"></canvas>
    24 <img style="width: 30px;" src="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' width='100' height='100'><rect width='100' height='100' fill='green' /><circle cx='30' cy='30' r='15' fill='blue'/></svg>" >
     29<img style="width: 30px;" src="data:image/svg+xml,
     30    <svg xmlns='http://www.w3.org/2000/svg' width='100' height='100'>
     31        <rect width='100' height='100' fill='green'/>
     32        <rect x='15' y='15' width='30' height='30' fill='blue'/>
     33    </svg>" >
    2534</body>
    2635</html>
  • trunk/Source/WebCore/ChangeLog

    r272547 r272549  
     12021-02-08  Said Abou-Hallawa  <said@apple.com>
     2
     3        A Pattern with an SVG image is not rendered correctly
     4        https://bugs.webkit.org/show_bug.cgi?id=221550
     5
     6        Reviewed by Simon Fraser.
     7
     8        Implement SVGImage::nativeImage() and nativeImageForCurrentFrame() for
     9        all platforms. This will make Pattern::createPlatformPattern() creates
     10        CGPatternRef with a valid CGImageRef.
     11
     12        * svg/graphics/SVGImage.cpp:
     13        (WebCore::SVGImage::nativeImageForCurrentFrame):
     14        (WebCore::SVGImage::nativeImage):
     15        * svg/graphics/SVGImage.h:
     16
    1172021-02-08  Eric Carlson  <eric.carlson@apple.com>
    218
  • trunk/Source/WebCore/svg/graphics/SVGImage.cpp

    r272475 r272549  
    209209}
    210210
    211 #if USE(CAIRO)
    212 // Passes ownership of the native image to the caller so NativeImage needs
    213 // to be a smart pointer type.
    214 RefPtr<NativeImage> SVGImage::nativeImageForCurrentFrame(const GraphicsContext*)
     211RefPtr<NativeImage> SVGImage::nativeImageForCurrentFrame(const GraphicsContext* targetContext)
     212{
     213    return nativeImage(targetContext);
     214}
     215
     216RefPtr<NativeImage> SVGImage::nativeImage(const GraphicsContext*)
    215217{
    216218    if (!m_page)
    217219        return nullptr;
    218220
    219     // Cairo does not use the accelerated drawing flag, so it's OK to make an unconditionally unaccelerated buffer.
    220     auto buffer = ImageBuffer::create(size(), RenderingMode::Unaccelerated);
    221     if (!buffer) // failed to allocate image
     221    auto imageBuffer = ImageBuffer::create(size(), RenderingMode::Unaccelerated);
     222    if (!imageBuffer)
    222223        return nullptr;
    223224
    224     draw(buffer->context(), rect(), rect());
    225 
    226     // FIXME: WK(Bug 113657): We should use DontCopyBackingStore here.
    227     return buffer->copyImage(CopyBackingStore)->nativeImageForCurrentFrame();
    228 }
    229 #endif
    230 
    231 #if USE(DIRECT2D)
    232 RefPtr<NativeImage> SVGImage::nativeImage(const GraphicsContext* targetContext)
    233 {
    234     ASSERT(targetContext);
    235     if (!m_page || !targetContext)
    236         return nullptr;
    237 
    238     ASSERT(targetContext->hasPlatformContext());
    239     auto* renderTarget = targetContext->platformContext()->renderTarget();
    240 
    241     IntSize bitmapSize(size().width(), size().height());
    242     auto nativeImageTarget = Direct2D::createBitmapRenderTargetOfSize(bitmapSize, renderTarget, 1.0);
    243     if (!nativeImageTarget)
    244         return nullptr;
    245 
    246     PlatformContextDirect2D platformContext(nativeImageTarget.get());
    247     GraphicsContext localContext(&platformContext, GraphicsContext::BitmapRenderingContextType::GPUMemory);
    248 
    249     draw(localContext, rect(), rect(), { CompositeOperator::SourceOver, BlendMode::Normal, DecodingMode::Synchronous, ImageOrientation::None });
    250 
    251     COMPtr<ID2D1Bitmap> nativeImage;
    252     HRESULT hr = nativeImageTarget->GetBitmap(&nativeImage);
    253     if (!SUCCEEDED(hr))
    254         return nullptr;
    255 
    256 #if ASSERT_ENABLED
    257     auto nativeImageSize = nativeImage->GetPixelSize();
    258     ASSERT(nativeImageSize.height = rect().size().height());
    259     ASSERT(nativeImageSize.width = rect().size().width());
    260 #endif
    261 
    262     return nativeImage;
    263 }
    264 #endif
     225    ImageObserver* observer = imageObserver();
     226
     227    setImageObserver(nullptr);
     228    setContainerSize(size());
     229
     230    imageBuffer->context().drawImage(*this, FloatPoint(0, 0));
     231
     232    setImageObserver(observer);
     233    return ImageBuffer::sinkIntoNativeImage(WTFMove(imageBuffer));
     234}
    265235
    266236void SVGImage::drawPatternForContainer(GraphicsContext& context, const FloatSize& containerSize, float containerZoom, const URL& initialFragmentURL, const FloatRect& srcRect,
  • trunk/Source/WebCore/svg/graphics/SVGImage.h

    r269614 r272549  
    6363    void scheduleStartAnimation();
    6464
    65 #if USE(CAIRO)
    66     RefPtr<NativeImage> nativeImageForCurrentFrame(const GraphicsContext* = nullptr) final;
    67 #endif
    68 #if USE(DIRECT2D)
    69     RefPtr<NativeImage> nativeImage(const GraphicsContext* = nullptr) final;
    70 #endif
    71    
    7265    Page* internalPage() { return m_page.get(); }
    7366
     
    9487    bool currentFrameKnownToBeOpaque() const final { return false; }
    9588
     89    RefPtr<NativeImage> nativeImageForCurrentFrame(const GraphicsContext* = nullptr) final;
     90    RefPtr<NativeImage> nativeImage(const GraphicsContext* = nullptr) final;
     91
    9692    void startAnimationTimerFired();
    9793
Note: See TracChangeset for help on using the changeset viewer.