Title: [272549] trunk
Revision
272549
Author
[email protected]
Date
2021-02-08 14:23:12 -0800 (Mon, 08 Feb 2021)

Log 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.

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (272548 => 272549)


--- trunk/LayoutTests/ChangeLog	2021-02-08 22:04:10 UTC (rev 272548)
+++ trunk/LayoutTests/ChangeLog	2021-02-08 22:23:12 UTC (rev 272549)
@@ -1,3 +1,17 @@
+2021-02-08  Said Abou-Hallawa  <[email protected]>
+
+        A Pattern with an SVG image is not rendered correctly
+        https://bugs.webkit.org/show_bug.cgi?id=221550
+
+        Reviewed by Simon Fraser.
+
+        * 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. 
+
 2021-02-08  Jonathan Bedard  <[email protected]>
 
         [LayoutTests] Convert xmlhttprequest php to Python

Modified: trunk/LayoutTests/imported/blink/svg/canvas/canvas-draw-pattern-size-expected.html (272548 => 272549)


--- trunk/LayoutTests/imported/blink/svg/canvas/canvas-draw-pattern-size-expected.html	2021-02-08 22:04:10 UTC (rev 272548)
+++ trunk/LayoutTests/imported/blink/svg/canvas/canvas-draw-pattern-size-expected.html	2021-02-08 22:23:12 UTC (rev 272549)
@@ -1,26 +1,15 @@
 <!DOCTYPE html>
 <html>
 <head>
-<script>
-function runTest() {
-  var context = document.getElementsByTagName('canvas')[0].getContext('2d');
-  var forceLayout = document.body.offsetWidth;
-
-  var domImage = document.getElementsByTagName('img')[0];
-  context.drawImage(domImage, 10, 10, 80, 80);
-
-  var newImage = new Image();
-  newImage.src = ""
-  context.fillStyle = context.createPattern(newImage, 'repeat');
-  context.fillRect(10, 10, 180, 80);
-
-  domImage.parentNode.removeChild(domImage);
-}
-</script>
 </head>
-<body _onload_='runTest()'>
+<body>
 Test for crbug.com/227481: This test passes if there is a green rectangle with a two blue circles.<br/>
-<canvas width="200px" height="100px"></canvas>
-<img style="width: 50px;" src="" 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>" >
+<img style="width: 200px; height: 100px;" src=""
+    <svg xmlns='http://www.w3.org/2000/svg' width='200' height='100'>
+        <rect x='10' y='10' width='180' height='80' fill='green'/>
+        <rect x='15' y='15' width='30' height='30' fill='blue' />
+        <rect x='115' y='15' width='30' height='30' fill='blue' />
+    </svg>" >
 </body>
+</body>
 </html>

Modified: trunk/LayoutTests/imported/blink/svg/canvas/canvas-draw-pattern-size.html (272548 => 272549)


--- trunk/LayoutTests/imported/blink/svg/canvas/canvas-draw-pattern-size.html	2021-02-08 22:04:10 UTC (rev 272548)
+++ trunk/LayoutTests/imported/blink/svg/canvas/canvas-draw-pattern-size.html	2021-02-08 22:23:12 UTC (rev 272549)
@@ -1,6 +1,11 @@
 <!DOCTYPE html>
 <html>
 <head>
+<style>
+    canvas {
+        image-rendering: pixelated;
+    }
+</style>
 <script>
 function runTest() {
   var context = document.getElementsByTagName('canvas')[0].getContext('2d');
@@ -21,6 +26,10 @@
 <body _onload_='runTest()'>
 Test for crbug.com/227481: This test passes if there is a green rectangle with a two blue circles.<br/>
 <canvas width="200px" height="100px"></canvas>
-<img style="width: 30px;" src="" 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>" >
+<img style="width: 30px;" src=""
+    <svg xmlns='http://www.w3.org/2000/svg' width='100' height='100'>
+        <rect width='100' height='100' fill='green'/>
+        <rect x='15' y='15' width='30' height='30' fill='blue'/>
+    </svg>" >
 </body>
 </html>

Modified: trunk/Source/WebCore/ChangeLog (272548 => 272549)


--- trunk/Source/WebCore/ChangeLog	2021-02-08 22:04:10 UTC (rev 272548)
+++ trunk/Source/WebCore/ChangeLog	2021-02-08 22:23:12 UTC (rev 272549)
@@ -1,3 +1,19 @@
+2021-02-08  Said Abou-Hallawa  <[email protected]>
+
+        A Pattern with an SVG image is not rendered correctly
+        https://bugs.webkit.org/show_bug.cgi?id=221550
+
+        Reviewed by Simon Fraser.
+
+        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:
+
 2021-02-08  Eric Carlson  <[email protected]>
 
         [Mac] Connect MediaSession with MediaRemote and NowPlaying

Modified: trunk/Source/WebCore/svg/graphics/SVGImage.cpp (272548 => 272549)


--- trunk/Source/WebCore/svg/graphics/SVGImage.cpp	2021-02-08 22:04:10 UTC (rev 272548)
+++ trunk/Source/WebCore/svg/graphics/SVGImage.cpp	2021-02-08 22:23:12 UTC (rev 272549)
@@ -208,60 +208,30 @@
     return result;
 }
 
-#if USE(CAIRO)
-// Passes ownership of the native image to the caller so NativeImage needs
-// to be a smart pointer type.
-RefPtr<NativeImage> SVGImage::nativeImageForCurrentFrame(const GraphicsContext*)
+RefPtr<NativeImage> SVGImage::nativeImageForCurrentFrame(const GraphicsContext* targetContext)
 {
-    if (!m_page)
-        return nullptr;
-
-    // Cairo does not use the accelerated drawing flag, so it's OK to make an unconditionally unaccelerated buffer.
-    auto buffer = ImageBuffer::create(size(), RenderingMode::Unaccelerated);
-    if (!buffer) // failed to allocate image
-        return nullptr;
-
-    draw(buffer->context(), rect(), rect());
-
-    // FIXME: WK(Bug 113657): We should use DontCopyBackingStore here.
-    return buffer->copyImage(CopyBackingStore)->nativeImageForCurrentFrame();
+    return nativeImage(targetContext);
 }
-#endif
 
-#if USE(DIRECT2D)
-RefPtr<NativeImage> SVGImage::nativeImage(const GraphicsContext* targetContext)
+RefPtr<NativeImage> SVGImage::nativeImage(const GraphicsContext*)
 {
-    ASSERT(targetContext);
-    if (!m_page || !targetContext)
+    if (!m_page)
         return nullptr;
 
-    ASSERT(targetContext->hasPlatformContext());
-    auto* renderTarget = targetContext->platformContext()->renderTarget();
-
-    IntSize bitmapSize(size().width(), size().height());
-    auto nativeImageTarget = Direct2D::createBitmapRenderTargetOfSize(bitmapSize, renderTarget, 1.0);
-    if (!nativeImageTarget)
+    auto imageBuffer = ImageBuffer::create(size(), RenderingMode::Unaccelerated);
+    if (!imageBuffer)
         return nullptr;
 
-    PlatformContextDirect2D platformContext(nativeImageTarget.get());
-    GraphicsContext localContext(&platformContext, GraphicsContext::BitmapRenderingContextType::GPUMemory);
+    ImageObserver* observer = imageObserver();
 
-    draw(localContext, rect(), rect(), { CompositeOperator::SourceOver, BlendMode::Normal, DecodingMode::Synchronous, ImageOrientation::None });
+    setImageObserver(nullptr);
+    setContainerSize(size());
 
-    COMPtr<ID2D1Bitmap> nativeImage;
-    HRESULT hr = nativeImageTarget->GetBitmap(&nativeImage);
-    if (!SUCCEEDED(hr))
-        return nullptr;
+    imageBuffer->context().drawImage(*this, FloatPoint(0, 0));
 
-#if ASSERT_ENABLED
-    auto nativeImageSize = nativeImage->GetPixelSize();
-    ASSERT(nativeImageSize.height = rect().size().height());
-    ASSERT(nativeImageSize.width = rect().size().width());
-#endif
-
-    return nativeImage;
+    setImageObserver(observer);
+    return ImageBuffer::sinkIntoNativeImage(WTFMove(imageBuffer));
 }
-#endif
 
 void SVGImage::drawPatternForContainer(GraphicsContext& context, const FloatSize& containerSize, float containerZoom, const URL& initialFragmentURL, const FloatRect& srcRect,
     const AffineTransform& patternTransform, const FloatPoint& phase, const FloatSize& spacing, const FloatRect& dstRect, const ImagePaintingOptions& options)

Modified: trunk/Source/WebCore/svg/graphics/SVGImage.h (272548 => 272549)


--- trunk/Source/WebCore/svg/graphics/SVGImage.h	2021-02-08 22:04:10 UTC (rev 272548)
+++ trunk/Source/WebCore/svg/graphics/SVGImage.h	2021-02-08 22:23:12 UTC (rev 272549)
@@ -62,13 +62,6 @@
 
     void scheduleStartAnimation();
 
-#if USE(CAIRO)
-    RefPtr<NativeImage> nativeImageForCurrentFrame(const GraphicsContext* = nullptr) final;
-#endif
-#if USE(DIRECT2D)
-    RefPtr<NativeImage> nativeImage(const GraphicsContext* = nullptr) final;
-#endif
-    
     Page* internalPage() { return m_page.get(); }
 
 private:
@@ -93,6 +86,9 @@
     // FIXME: Implement this to be less conservative.
     bool currentFrameKnownToBeOpaque() const final { return false; }
 
+    RefPtr<NativeImage> nativeImageForCurrentFrame(const GraphicsContext* = nullptr) final;
+    RefPtr<NativeImage> nativeImage(const GraphicsContext* = nullptr) final;
+
     void startAnimationTimerFired();
 
     explicit SVGImage(ImageObserver&);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to