Title: [284991] trunk
Revision
284991
Author
timothy_hor...@apple.com
Date
2021-10-28 10:18:21 -0700 (Thu, 28 Oct 2021)

Log Message

DOM GPUP: Yahoo.com has fragments of wrongly-scaled content throughout
https://bugs.webkit.org/show_bug.cgi?id=232356
<rdar://83884813>

Reviewed by Simon Fraser.

Source/WebCore:

* platform/graphics/ConcreteImageBuffer.h:
* platform/graphics/ImageBufferBackend.cpp:
(WebCore::ImageBufferBackend::calculateBaseTransform):
Delegate baseTransform computation to the backend, so that it
can also compute it itself when applyBaseTransformToContext() is called.

Multiply resolutionScale into the base transform.

(WebCore::ImageBufferBackend::applyBaseTransformToContext const):
Apply the base transform to the context via recordable GraphicsContext
methods, so that getCTM() returns an accurate CTM that matches the one
on the replay side.

Also, apply the device scale factor like setupContext() used to do,
but *before* setting the CTM so that we don't double-scale.
In the future we should consider making applyDeviceScaleFactor() *not*
actually scale the context, instead only touching the CG base CTM;
I went the opposite direction in r284902 in order to reduce change
to non-DisplayList clients, but this is a bit messy.

* platform/graphics/ImageBufferBackend.h:
(WebCore::ImageBufferBackend::originAtBottomLeftCorner const):
Add a virtual originAtBottomLeftCorner getter; oddly we need it both
dynamically (from ImageBufferBackend::calculateBaseTransform) and
statically (from ConcreteImageBuffer::baseTransform(), which has to
be callable before the backend is actually realized), so we have both
this virtual method and the existing static bit.

* platform/graphics/cg/ImageBufferCGBackend.cpp:
(WebCore::ImageBufferCGBackend::setupContext const): Deleted.
* platform/graphics/cg/ImageBufferCGBackend.h:
* platform/graphics/cg/ImageBufferCGBitmapBackend.cpp:
(WebCore::ImageBufferCGBitmapBackend::ImageBufferCGBitmapBackend):
* platform/graphics/cg/ImageBufferIOSurfaceBackend.cpp:
(WebCore::ImageBufferIOSurfaceBackend::ImageBufferIOSurfaceBackend):
(WebCore::ImageBufferIOSurfaceBackend::context const):
Replace setupContext() with a call to applyBaseTransformToContext(),
which supercedes it.

* platform/graphics/displaylists/DisplayListRecorder.cpp:
(WebCore::DisplayList::Recorder::Recorder):
Map the initial clip back out to base coordinates through the initialCTM;
I missed this in r284888 because the initialCTM was just a flip, but
now that it includes a scale this is critical.

Source/WebKit:

* WebProcess/GPU/graphics/cocoa/ImageBufferShareableIOSurfaceBackend.cpp:
(WebKit::ImageBufferShareableIOSurfaceBackend::backendSize const):
Implement backendSize() so that ImageBufferShareableIOSurfaceBackend
doesn't always report itself as being 0x0.
* WebProcess/GPU/graphics/cocoa/ImageBufferShareableIOSurfaceBackend.h:

LayoutTests:

* fast/transforms/interleaved-2d-transforms-with-gpu-process-expected.html: Added.
* fast/transforms/interleaved-2d-transforms-with-gpu-process.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (284990 => 284991)


--- trunk/LayoutTests/ChangeLog	2021-10-28 17:02:13 UTC (rev 284990)
+++ trunk/LayoutTests/ChangeLog	2021-10-28 17:18:21 UTC (rev 284991)
@@ -1,3 +1,14 @@
+2021-10-28  Tim Horton  <timothy_hor...@apple.com>
+
+        DOM GPUP: Yahoo.com has fragments of wrongly-scaled content throughout
+        https://bugs.webkit.org/show_bug.cgi?id=232356
+        <rdar://83884813>
+
+        Reviewed by Simon Fraser.
+
+        * fast/transforms/interleaved-2d-transforms-with-gpu-process-expected.html: Added.
+        * fast/transforms/interleaved-2d-transforms-with-gpu-process.html: Added.
+
 2021-10-28  Aditya Keerthi  <akeer...@apple.com>
 
         REGRESSION (r282451): [iOS] Cannot override background of search inputs with 'appearance: textfield'

Added: trunk/LayoutTests/fast/transforms/interleaved-2d-transforms-with-gpu-process-expected.html (0 => 284991)


--- trunk/LayoutTests/fast/transforms/interleaved-2d-transforms-with-gpu-process-expected.html	                        (rev 0)
+++ trunk/LayoutTests/fast/transforms/interleaved-2d-transforms-with-gpu-process-expected.html	2021-10-28 17:18:21 UTC (rev 284991)
@@ -0,0 +1,17 @@
+<style>
+body
+{
+    margin: 0;
+}
+
+div
+{
+    position: absolute;
+    width: 200px;
+    height: 200px;
+    top: 50px;
+    left: 50px;
+}
+</style>
+The test passes if there is a green square with no red.
+<div style="background-color: green;"></div>

Added: trunk/LayoutTests/fast/transforms/interleaved-2d-transforms-with-gpu-process.html (0 => 284991)


--- trunk/LayoutTests/fast/transforms/interleaved-2d-transforms-with-gpu-process.html	                        (rev 0)
+++ trunk/LayoutTests/fast/transforms/interleaved-2d-transforms-with-gpu-process.html	2021-10-28 17:18:21 UTC (rev 284991)
@@ -0,0 +1,19 @@
+<!-- webkit-test-runner [ UseGPUProcessForDOMRenderingEnabled=true ] -->
+<style>
+body
+{
+    margin: 0;
+}
+
+div
+{
+    position: absolute;
+    width: 200px;
+    height: 100px;
+}
+</style>
+The test passes if there is a green square with no red.
+<div style="background-color: red; top: 0px; left: 0px; transform: translate(50px, 50px);"></div>
+<div style="background-color: green; top: 50px; left: 50px;"></div>
+<div style="background-color: red; top: 0px; left: 0px; transform: translate(50px, 150px);"></div>
+<div style="background-color: green; top: 150px; left: 50px;"></div>
\ No newline at end of file

Modified: trunk/Source/WebCore/ChangeLog (284990 => 284991)


--- trunk/Source/WebCore/ChangeLog	2021-10-28 17:02:13 UTC (rev 284990)
+++ trunk/Source/WebCore/ChangeLog	2021-10-28 17:18:21 UTC (rev 284991)
@@ -1,3 +1,56 @@
+2021-10-28  Tim Horton  <timothy_hor...@apple.com>
+
+        DOM GPUP: Yahoo.com has fragments of wrongly-scaled content throughout
+        https://bugs.webkit.org/show_bug.cgi?id=232356
+        <rdar://83884813>
+
+        Reviewed by Simon Fraser.
+
+        * platform/graphics/ConcreteImageBuffer.h:
+        * platform/graphics/ImageBufferBackend.cpp:
+        (WebCore::ImageBufferBackend::calculateBaseTransform):
+        Delegate baseTransform computation to the backend, so that it
+        can also compute it itself when applyBaseTransformToContext() is called.
+
+        Multiply resolutionScale into the base transform.
+
+        (WebCore::ImageBufferBackend::applyBaseTransformToContext const):
+        Apply the base transform to the context via recordable GraphicsContext
+        methods, so that getCTM() returns an accurate CTM that matches the one
+        on the replay side.
+
+        Also, apply the device scale factor like setupContext() used to do,
+        but *before* setting the CTM so that we don't double-scale.
+        In the future we should consider making applyDeviceScaleFactor() *not*
+        actually scale the context, instead only touching the CG base CTM;
+        I went the opposite direction in r284902 in order to reduce change
+        to non-DisplayList clients, but this is a bit messy.
+
+        * platform/graphics/ImageBufferBackend.h:
+        (WebCore::ImageBufferBackend::originAtBottomLeftCorner const):
+        Add a virtual originAtBottomLeftCorner getter; oddly we need it both
+        dynamically (from ImageBufferBackend::calculateBaseTransform) and
+        statically (from ConcreteImageBuffer::baseTransform(), which has to
+        be callable before the backend is actually realized), so we have both
+        this virtual method and the existing static bit.
+
+        * platform/graphics/cg/ImageBufferCGBackend.cpp:
+        (WebCore::ImageBufferCGBackend::setupContext const): Deleted.
+        * platform/graphics/cg/ImageBufferCGBackend.h:
+        * platform/graphics/cg/ImageBufferCGBitmapBackend.cpp:
+        (WebCore::ImageBufferCGBitmapBackend::ImageBufferCGBitmapBackend):
+        * platform/graphics/cg/ImageBufferIOSurfaceBackend.cpp:
+        (WebCore::ImageBufferIOSurfaceBackend::ImageBufferIOSurfaceBackend):
+        (WebCore::ImageBufferIOSurfaceBackend::context const):
+        Replace setupContext() with a call to applyBaseTransformToContext(),
+        which supercedes it.
+
+        * platform/graphics/displaylists/DisplayListRecorder.cpp:
+        (WebCore::DisplayList::Recorder::Recorder):
+        Map the initial clip back out to base coordinates through the initialCTM;
+        I missed this in r284888 because the initialCTM was just a flip, but
+        now that it includes a scale this is critical.
+
 2021-10-28  Myles C. Maxfield  <mmaxfi...@apple.com>
 
         [watchOS] Fix logging

Modified: trunk/Source/WebCore/platform/graphics/ConcreteImageBuffer.h (284990 => 284991)


--- trunk/Source/WebCore/platform/graphics/ConcreteImageBuffer.h	2021-10-28 17:02:13 UTC (rev 284990)
+++ trunk/Source/WebCore/platform/graphics/ConcreteImageBuffer.h	2021-10-28 17:18:21 UTC (rev 284991)
@@ -105,9 +105,7 @@
 
     AffineTransform baseTransform() const override
     {
-        if (BackendType::isOriginAtBottomLeftCorner)
-            return AffineTransform(1, 0, 0, -1, 0, logicalSize().height());
-        return { };
+        return BackendType::calculateBaseTransform(m_parameters, BackendType::isOriginAtBottomLeftCorner);
     }
 
     size_t memoryCost() const override

Modified: trunk/Source/WebCore/platform/graphics/ImageBufferBackend.cpp (284990 => 284991)


--- trunk/Source/WebCore/platform/graphics/ImageBufferBackend.cpp	2021-10-28 17:02:13 UTC (rev 284990)
+++ trunk/Source/WebCore/platform/graphics/ImageBufferBackend.cpp	2021-10-28 17:18:21 UTC (rev 284991)
@@ -26,6 +26,7 @@
 #include "config.h"
 #include "ImageBufferBackend.h"
 
+#include "GraphicsContext.h"
 #include "Image.h"
 #include "PixelBuffer.h"
 #include "PixelBufferConversion.h"
@@ -165,4 +166,25 @@
     convertImagePixels(source, destination, destinationRect.size());
 }
 
+AffineTransform ImageBufferBackend::calculateBaseTransform(const Parameters& parameters, bool originAtBottomLeftCorner)
+{
+    AffineTransform baseTransform;
+
+    if (originAtBottomLeftCorner) {
+        baseTransform.scale(1, -1);
+        baseTransform.translate(0, -calculateBackendSize(parameters).height());
+    }
+
+    baseTransform.scale(parameters.resolutionScale);
+
+    return baseTransform;
+}
+
+void ImageBufferBackend::applyBaseTransformToContext() const
+{
+    auto& context = this->context();
+    context.applyDeviceScaleFactor(m_parameters.resolutionScale);
+    context.setCTM(calculateBaseTransform(m_parameters, originAtBottomLeftCorner()));
+}
+
 } // namespace WebCore

Modified: trunk/Source/WebCore/platform/graphics/ImageBufferBackend.h (284990 => 284991)


--- trunk/Source/WebCore/platform/graphics/ImageBufferBackend.h	2021-10-28 17:02:13 UTC (rev 284990)
+++ trunk/Source/WebCore/platform/graphics/ImageBufferBackend.h	2021-10-28 17:18:21 UTC (rev 284991)
@@ -83,6 +83,7 @@
     WEBCORE_EXPORT static IntSize calculateBackendSize(const Parameters&);
     WEBCORE_EXPORT static size_t calculateMemoryCost(const IntSize& backendSize, unsigned bytesPerRow);
     static size_t calculateExternalMemoryCost(const Parameters&) { return 0; }
+    WEBCORE_EXPORT static AffineTransform calculateBaseTransform(const Parameters&, bool originAtBottomLeftCorner);
 
     virtual GraphicsContext& context() const = 0;
     virtual void flushContext() { }
@@ -120,7 +121,11 @@
 
     virtual std::unique_ptr<ThreadSafeImageBufferFlusher> createFlusher() { return nullptr; }
 
+    void applyBaseTransformToContext() const;
+
     static constexpr bool isOriginAtBottomLeftCorner = false;
+    virtual bool originAtBottomLeftCorner() const { return isOriginAtBottomLeftCorner; }
+
     static constexpr bool canMapBackingStore = true;
     static constexpr RenderingMode renderingMode = RenderingMode::Unaccelerated;
 

Modified: trunk/Source/WebCore/platform/graphics/cg/ImageBufferCGBackend.cpp (284990 => 284991)


--- trunk/Source/WebCore/platform/graphics/cg/ImageBufferCGBackend.cpp	2021-10-28 17:02:13 UTC (rev 284990)
+++ trunk/Source/WebCore/platform/graphics/cg/ImageBufferCGBackend.cpp	2021-10-28 17:18:21 UTC (rev 284991)
@@ -78,14 +78,6 @@
 #endif
 }
 
-void ImageBufferCGBackend::setupContext() const
-{
-    // The initial CTM matches DisplayList::Recorder::clipToDrawingCommands()'s initial CTM.
-    context().scale(FloatSize(1, -1));
-    context().translate(0, -backendSize().height());
-    context().applyDeviceScaleFactor(resolutionScale());
-}
-
 static RetainPtr<CGImageRef> createCroppedImageIfNecessary(CGImageRef image, const IntSize& backendSize)
 {
     if (image && (CGImageGetWidth(image) != static_cast<size_t>(backendSize.width()) || CGImageGetHeight(image) != static_cast<size_t>(backendSize.height())))
@@ -260,6 +252,11 @@
 {
 }
 
+bool ImageBufferCGBackend::originAtBottomLeftCorner() const
+{
+    return isOriginAtBottomLeftCorner;
+}
+
 } // namespace WebCore
 
 #endif // USE(CG)

Modified: trunk/Source/WebCore/platform/graphics/cg/ImageBufferCGBackend.h (284990 => 284991)


--- trunk/Source/WebCore/platform/graphics/cg/ImageBufferCGBackend.h	2021-10-28 17:02:13 UTC (rev 284990)
+++ trunk/Source/WebCore/platform/graphics/cg/ImageBufferCGBackend.h	2021-10-28 17:18:21 UTC (rev 284991)
@@ -52,12 +52,12 @@
     std::unique_ptr<ThreadSafeImageBufferFlusher> createFlusher() override;
 
     static constexpr bool isOriginAtBottomLeftCorner = true;
+    bool originAtBottomLeftCorner() const override;
 
 protected:
     using ImageBufferBackend::ImageBufferBackend;
 
     static RetainPtr<CGColorSpaceRef> contextColorSpace(const GraphicsContext&);
-    void setupContext() const;
 
     virtual void prepareToDrawIntoContext(GraphicsContext&);
 

Modified: trunk/Source/WebCore/platform/graphics/cg/ImageBufferCGBitmapBackend.cpp (284990 => 284991)


--- trunk/Source/WebCore/platform/graphics/cg/ImageBufferCGBitmapBackend.cpp	2021-10-28 17:02:13 UTC (rev 284990)
+++ trunk/Source/WebCore/platform/graphics/cg/ImageBufferCGBitmapBackend.cpp	2021-10-28 17:18:21 UTC (rev 284991)
@@ -115,7 +115,7 @@
     ASSERT(m_data);
     ASSERT(m_dataProvider);
     ASSERT(m_context);
-    setupContext();
+    applyBaseTransformToContext();
 }
 
 GraphicsContext& ImageBufferCGBitmapBackend::context() const

Modified: trunk/Source/WebCore/platform/graphics/cg/ImageBufferIOSurfaceBackend.cpp (284990 => 284991)


--- trunk/Source/WebCore/platform/graphics/cg/ImageBufferIOSurfaceBackend.cpp	2021-10-28 17:02:13 UTC (rev 284990)
+++ trunk/Source/WebCore/platform/graphics/cg/ImageBufferIOSurfaceBackend.cpp	2021-10-28 17:18:21 UTC (rev 284991)
@@ -117,7 +117,7 @@
     , m_surface(WTFMove(surface))
 {
     ASSERT(m_surface);
-    setupContext();
+    applyBaseTransformToContext();
 }
 
 GraphicsContext& ImageBufferIOSurfaceBackend::context() const
@@ -125,7 +125,7 @@
     GraphicsContext& context = m_surface->ensureGraphicsContext();
     if (m_needsSetupContext) {
         m_needsSetupContext = false;
-        setupContext();
+        applyBaseTransformToContext();
     }
     return context;
 }

Modified: trunk/Source/WebCore/platform/graphics/displaylists/DisplayListRecorder.cpp (284990 => 284991)


--- trunk/Source/WebCore/platform/graphics/displaylists/DisplayListRecorder.cpp	2021-10-28 17:02:13 UTC (rev 284990)
+++ trunk/Source/WebCore/platform/graphics/displaylists/DisplayListRecorder.cpp	2021-10-28 17:18:21 UTC (rev 284991)
@@ -43,13 +43,13 @@
 Recorder::Recorder(const GraphicsContextState& state, const FloatRect& initialClip, const AffineTransform& initialCTM, DrawGlyphsRecorder::DeconstructDrawGlyphs deconstructDrawGlyphs)
     : m_drawGlyphsRecorder(*this, deconstructDrawGlyphs)
 {
-    m_stateStack.append({ state, initialCTM, initialClip });
+    m_stateStack.append({ state, initialCTM, initialCTM.mapRect(initialClip) });
 }
 
 Recorder::Recorder(Recorder& parent, const GraphicsContextState& state, const FloatRect& initialClip, const AffineTransform& initialCTM)
     : m_drawGlyphsRecorder(*this, parent.m_drawGlyphsRecorder.deconstructDrawGlyphs())
 {
-    m_stateStack.append({ state, initialCTM, initialClip });
+    m_stateStack.append({ state, initialCTM, initialCTM.mapRect(initialClip) });
 }
 
 Recorder::~Recorder()

Modified: trunk/Source/WebKit/ChangeLog (284990 => 284991)


--- trunk/Source/WebKit/ChangeLog	2021-10-28 17:02:13 UTC (rev 284990)
+++ trunk/Source/WebKit/ChangeLog	2021-10-28 17:18:21 UTC (rev 284991)
@@ -1,3 +1,17 @@
+2021-10-28  Tim Horton  <timothy_hor...@apple.com>
+
+        DOM GPUP: Yahoo.com has fragments of wrongly-scaled content throughout
+        https://bugs.webkit.org/show_bug.cgi?id=232356
+        <rdar://83884813>
+
+        Reviewed by Simon Fraser.
+
+        * WebProcess/GPU/graphics/cocoa/ImageBufferShareableIOSurfaceBackend.cpp:
+        (WebKit::ImageBufferShareableIOSurfaceBackend::backendSize const):
+        Implement backendSize() so that ImageBufferShareableIOSurfaceBackend
+        doesn't always report itself as being 0x0.
+        * WebProcess/GPU/graphics/cocoa/ImageBufferShareableIOSurfaceBackend.h:
+
 2021-10-28  Daniel Kolesa  <dkol...@igalia.com>
 
         Non-unified build fixes

Modified: trunk/Source/WebKit/WebProcess/GPU/graphics/cocoa/ImageBufferShareableIOSurfaceBackend.cpp (284990 => 284991)


--- trunk/Source/WebKit/WebProcess/GPU/graphics/cocoa/ImageBufferShareableIOSurfaceBackend.cpp	2021-10-28 17:02:13 UTC (rev 284990)
+++ trunk/Source/WebKit/WebProcess/GPU/graphics/cocoa/ImageBufferShareableIOSurfaceBackend.cpp	2021-10-28 17:18:21 UTC (rev 284991)
@@ -74,6 +74,11 @@
     return *(GraphicsContext*)nullptr;
 }
 
+IntSize ImageBufferShareableIOSurfaceBackend::backendSize() const
+{
+    return calculateBackendSize(m_parameters);
+}
+
 unsigned ImageBufferShareableIOSurfaceBackend::bytesPerRow() const
 {
     IntSize backendSize = calculateBackendSize(m_parameters);

Modified: trunk/Source/WebKit/WebProcess/GPU/graphics/cocoa/ImageBufferShareableIOSurfaceBackend.h (284990 => 284991)


--- trunk/Source/WebKit/WebProcess/GPU/graphics/cocoa/ImageBufferShareableIOSurfaceBackend.h	2021-10-28 17:02:13 UTC (rev 284990)
+++ trunk/Source/WebKit/WebProcess/GPU/graphics/cocoa/ImageBufferShareableIOSurfaceBackend.h	2021-10-28 17:18:21 UTC (rev 284991)
@@ -53,6 +53,7 @@
     ImageBufferBackendHandle createImageBufferBackendHandle() const;
 
     WebCore::GraphicsContext& context() const override;
+    WebCore::IntSize backendSize() const override;
     RefPtr<WebCore::NativeImage> copyNativeImage(WebCore::BackingStoreCopy) const override;
     RefPtr<WebCore::Image> copyImage(WebCore::BackingStoreCopy, WebCore::PreserveResolution) const override;
     void draw(WebCore::GraphicsContext&, const WebCore::FloatRect& destRect, const WebCore::FloatRect& srcRect, const WebCore::ImagePaintingOptions&) override;
@@ -63,6 +64,8 @@
     void putPixelBuffer(const WebCore::PixelBuffer&, const WebCore::IntRect& srcRect, const WebCore::IntPoint& destPoint, WebCore::AlphaPremultiplication destFormat) override;
 
     static constexpr bool isOriginAtBottomLeftCorner = true;
+    bool originAtBottomLeftCorner() const override { return isOriginAtBottomLeftCorner; }
+
     static constexpr bool canMapBackingStore = false;
     static constexpr WebCore::RenderingMode renderingMode = WebCore::RenderingMode::Accelerated;
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to