Title: [279885] trunk
Revision
279885
Author
s...@apple.com
Date
2021-07-13 12:38:32 -0700 (Tue, 13 Jul 2021)

Log Message

[CG] REGRESSION(r278863): The destination rectangle is truncated when the sub-image is used
https://bugs.webkit.org/show_bug.cgi?id=227614
<rdar://79840643>

Reviewed by Simon Fraser.

Source/WebCore:

This patch gets the calculation of the destRect in the case of the sub-
image as it was before r278863.

The size of the destRect has to be equal to the backend size of the
ImageBuffer in logical coordinates.

* platform/graphics/cg/GraphicsContextCG.cpp:
(WebCore::GraphicsContextCG::drawNativeImage):

Tools:

Add an API test to test drawing an ImageBuffer into another and both
have the logicalSize scaled such that they have pixels.

* TestWebKitAPI/Tests/WebCore/ImageBufferTests.cpp:
(TestWebKitAPI::TEST):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (279884 => 279885)


--- trunk/Source/WebCore/ChangeLog	2021-07-13 19:35:38 UTC (rev 279884)
+++ trunk/Source/WebCore/ChangeLog	2021-07-13 19:38:32 UTC (rev 279885)
@@ -1,3 +1,20 @@
+2021-07-13  Said Abou-Hallawa  <s...@apple.com>
+
+        [CG] REGRESSION(r278863): The destination rectangle is truncated when the sub-image is used
+        https://bugs.webkit.org/show_bug.cgi?id=227614
+        <rdar://79840643>
+
+        Reviewed by Simon Fraser.
+
+        This patch gets the calculation of the destRect in the case of the sub-
+        image as it was before r278863.
+
+        The size of the destRect has to be equal to the backend size of the
+        ImageBuffer in logical coordinates.
+
+        * platform/graphics/cg/GraphicsContextCG.cpp:
+        (WebCore::GraphicsContextCG::drawNativeImage):
+
 2021-07-13  Kyle Piddington  <kpidding...@apple.com>
 
         rAF driven WebGL submits excessive amount of GPU work when frames are slow

Modified: trunk/Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp (279884 => 279885)


--- trunk/Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp	2021-07-13 19:35:38 UTC (rev 279884)
+++ trunk/Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp	2021-07-13 19:38:32 UTC (rev 279885)
@@ -297,8 +297,10 @@
             // interpolation smoothes sharp edges, causing pixels from outside the source rect to bleed
             // into the destination rect. See <rdar://problem/6112909>.
             subImage = getSubimage(subImage.get(), imageSize, subimageRect, options);
-            adjustedDestRect = enclosingIntRect(adjustedDestRect);
 
+            auto subPixelPadding = normalizedSrcRect.location() - subimageRect.location();
+            adjustedDestRect = { adjustedDestRect.location() - subPixelPadding * scale, subimageRect.size() * scale };
+
             // If the image is only partially loaded, then shrink the destination rect that we're drawing
             // into accordingly.
             if (currentImageSize.height() < normalizedSrcRect.maxY()) {

Modified: trunk/Tools/ChangeLog (279884 => 279885)


--- trunk/Tools/ChangeLog	2021-07-13 19:35:38 UTC (rev 279884)
+++ trunk/Tools/ChangeLog	2021-07-13 19:38:32 UTC (rev 279885)
@@ -1,3 +1,17 @@
+2021-07-13  Said Abou-Hallawa  <s...@apple.com>
+
+        [CG] REGRESSION(r278863): The destination rectangle is truncated when the sub-image is used
+        https://bugs.webkit.org/show_bug.cgi?id=227614
+        <rdar://79840643>
+
+        Reviewed by Simon Fraser.
+
+        Add an API test to test drawing an ImageBuffer into another and both
+        have the logicalSize scaled such that they have pixels.
+
+        * TestWebKitAPI/Tests/WebCore/ImageBufferTests.cpp:
+        (TestWebKitAPI::TEST):
+
 2021-07-13  Kevin Neal  <kevin_n...@apple.com>
 
         [results.webkit.org] linkify urls in commit messages

Modified: trunk/Tools/TestWebKitAPI/Tests/WebCore/ImageBufferTests.cpp (279884 => 279885)


--- trunk/Tools/TestWebKitAPI/Tests/WebCore/ImageBufferTests.cpp	2021-07-13 19:35:38 UTC (rev 279884)
+++ trunk/Tools/TestWebKitAPI/Tests/WebCore/ImageBufferTests.cpp	2021-07-13 19:38:32 UTC (rev 279885)
@@ -49,4 +49,56 @@
     EXPECT_NE(nullptr, displayListUnaccelerated);
 }
 
+TEST(ImageBufferTests, ImageBufferSubPixelDrawing)
+{
+    auto colorSpace = DestinationColorSpace::SRGB();
+    auto pixelFormat = PixelFormat::BGRA8;
+    FloatSize logicalSize { 392, 44 };
+    float scale = 1.91326535;
+    auto frontImageBuffer = ImageBuffer::create(logicalSize, RenderingMode::Accelerated, scale, colorSpace, pixelFormat, nullptr);
+    auto backImageBuffer = ImageBuffer::create(logicalSize, RenderingMode::Accelerated, scale, colorSpace, pixelFormat, nullptr);
+    
+    auto strokeRect = FloatRect { { }, logicalSize };
+    strokeRect.inflate(-0.5);
+    auto fillRect = strokeRect;
+    fillRect.inflate(-1);
+
+    auto& frontContext = frontImageBuffer->context();
+    auto& backContext = backImageBuffer->context();
+
+    frontContext.setShouldAntialias(false);
+    backContext.setShouldAntialias(false);
+
+    frontContext.setStrokeColor(Color::red);
+    frontContext.strokeRect(strokeRect, 1);
+    
+    frontContext.fillRect(fillRect, Color::green);
+
+    for (int i = 0; i < 1000; ++i) {
+        backContext.drawImageBuffer(*frontImageBuffer, WebCore::FloatPoint { }, { WebCore::CompositeOperator::Copy });
+        frontContext.drawImageBuffer(*backImageBuffer, WebCore::FloatPoint { }, { WebCore::CompositeOperator::Copy });
+    }
+
+    auto checkGreenPixel = [&](ImageBuffer& imageBuffer, int x, int y) {
+        PixelBufferFormat format { AlphaPremultiplication::Unpremultiplied, PixelFormat::RGBA8, colorSpace };
+        auto frontPixelBuffer = imageBuffer.getPixelBuffer(format, { x, y, 1, 1 });
+        auto& data = ""
+
+        EXPECT_EQ(data.item(0), 0x00);
+        EXPECT_EQ(data.item(1), 0xff);
+        EXPECT_EQ(data.item(2), 0x00);
+        EXPECT_EQ(data.item(3), 0xff);
+    };
+
+    checkGreenPixel(*frontImageBuffer, fillRect.x()    + 1, fillRect.y()    + 1);
+    checkGreenPixel(*frontImageBuffer, fillRect.maxX() - 1, fillRect.y()    + 1);
+    checkGreenPixel(*frontImageBuffer, fillRect.x()    + 1, fillRect.maxY() - 1);
+    checkGreenPixel(*frontImageBuffer, fillRect.maxX() - 1, fillRect.maxY() - 1);
+
+    checkGreenPixel(*backImageBuffer, fillRect.x()    + 1, fillRect.y()    + 1);
+    checkGreenPixel(*backImageBuffer, fillRect.maxX() - 1, fillRect.y()    + 1);
+    checkGreenPixel(*backImageBuffer, fillRect.x()    + 1, fillRect.maxY() - 1);
+    checkGreenPixel(*backImageBuffer, fillRect.maxX() - 1, fillRect.maxY() - 1);
 }
+
+}
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to