Title: [264615] trunk/Source/WebCore
Revision
264615
Author
[email protected]
Date
2020-07-20 13:18:29 -0700 (Mon, 20 Jul 2020)

Log Message

[CG] Flushing ImageBuffer IOSurface cached image can happen when creating an image for encoding only
https://bugs.webkit.org/show_bug.cgi?id=214515
<rdar://problem/65735991>

Patch by Said Abou-Hallawa <[email protected]> on 2020-07-20
Reviewed by Simon Fraser.

Drawing an empty rectangle after changing the bytes of the IOSurface was
a hack to force CG to regenerate the IOSurface cached image. This hack
was added to solve the bug in which we were getting stale data url from
the ImageBuffer after calling its putImageData() function.

Drawing the ImageBuffer to a GraphicsContext or getting its data url starts
by getting a native image from the IOSurface. The stale cached image problem
was seen only in getting the data url but when not drawing the ImageBuffer.

So to save the cost of flushing the cached image, we will delay doing the
empty rectangle hack till toCFData() is called. toCFData() is called for
all ImageBuffer data retrieval functions including toDataURL().

This gives a 15% progression to the Images test on MacBookPro15,2 because
the Images test does not call toDataURL() so it does not require flushing
the IOSurface cached image. It calls getImageData(), alter the image data
and then calls putImageData().

* platform/graphics/cg/ImageBufferIOSurfaceBackend.cpp:
(WebCore::ImageBufferIOSurfaceBackend::toCFData const):
(WebCore::ImageBufferIOSurfaceBackend::putImageData):
* platform/graphics/cg/ImageBufferIOSurfaceBackend.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (264614 => 264615)


--- trunk/Source/WebCore/ChangeLog	2020-07-20 20:16:40 UTC (rev 264614)
+++ trunk/Source/WebCore/ChangeLog	2020-07-20 20:18:29 UTC (rev 264615)
@@ -1,3 +1,34 @@
+2020-07-20  Said Abou-Hallawa  <[email protected]>
+
+        [CG] Flushing ImageBuffer IOSurface cached image can happen when creating an image for encoding only
+        https://bugs.webkit.org/show_bug.cgi?id=214515
+        <rdar://problem/65735991>
+
+        Reviewed by Simon Fraser.
+
+        Drawing an empty rectangle after changing the bytes of the IOSurface was
+        a hack to force CG to regenerate the IOSurface cached image. This hack
+        was added to solve the bug in which we were getting stale data url from
+        the ImageBuffer after calling its putImageData() function.
+
+        Drawing the ImageBuffer to a GraphicsContext or getting its data url starts
+        by getting a native image from the IOSurface. The stale cached image problem
+        was seen only in getting the data url but when not drawing the ImageBuffer.
+
+        So to save the cost of flushing the cached image, we will delay doing the
+        empty rectangle hack till toCFData() is called. toCFData() is called for
+        all ImageBuffer data retrieval functions including toDataURL().
+
+        This gives a 15% progression to the Images test on MacBookPro15,2 because
+        the Images test does not call toDataURL() so it does not require flushing
+        the IOSurface cached image. It calls getImageData(), alter the image data
+        and then calls putImageData().
+
+        * platform/graphics/cg/ImageBufferIOSurfaceBackend.cpp:
+        (WebCore::ImageBufferIOSurfaceBackend::toCFData const):
+        (WebCore::ImageBufferIOSurfaceBackend::putImageData):
+        * platform/graphics/cg/ImageBufferIOSurfaceBackend.h:
+
 2020-07-20  Darin Adler  <[email protected]>
 
         Streamline URLDecomposition::setHash

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


--- trunk/Source/WebCore/platform/graphics/cg/ImageBufferIOSurfaceBackend.cpp	2020-07-20 20:16:40 UTC (rev 264614)
+++ trunk/Source/WebCore/platform/graphics/cg/ImageBufferIOSurfaceBackend.cpp	2020-07-20 20:18:29 UTC (rev 264615)
@@ -154,6 +154,17 @@
         destContext.drawNativeImage(image.get(), m_backendSize, destRect, adjustedSrcRect, options);
 }
 
+RetainPtr<CFDataRef> ImageBufferIOSurfaceBackend::toCFData(const String& mimeType, Optional<double> quality, PreserveResolution preserveResolution) const
+{
+    if (m_requiresDrawAfterPutImageData) {
+        // Force recreating the IOSurface cached image.
+        // See https://bugs.webkit.org/show_bug.cgi?id=157966 for explaining why this is necessary.
+        context().fillRect(FloatRect(1, 1, 0, 0));
+        m_requiresDrawAfterPutImageData = false;
+    }
+    return ImageBufferCGBackend::toCFData(mimeType, quality, preserveResolution);
+}
+
 Vector<uint8_t> ImageBufferIOSurfaceBackend::toBGRAData() const
 {
     IOSurface::Locker lock(*m_surface);
@@ -170,10 +181,7 @@
 {
     IOSurface::Locker lock(*m_surface, IOSurface::Locker::AccessMode::ReadWrite);
     ImageBufferBackend::putImageData(inputFormat, imageData, srcRect, destPoint, lock.surfaceBaseAddress());
-
-    // Force recreating the IOSurface cached image.
-    // See https://bugs.webkit.org/show_bug.cgi?id=157966 for explaining why this is necessary.
-    context().fillRect(FloatRect(1, 1, 0, 0));
+    m_requiresDrawAfterPutImageData = true;
 }
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/platform/graphics/cg/ImageBufferIOSurfaceBackend.h (264614 => 264615)


--- trunk/Source/WebCore/platform/graphics/cg/ImageBufferIOSurfaceBackend.h	2020-07-20 20:16:40 UTC (rev 264614)
+++ trunk/Source/WebCore/platform/graphics/cg/ImageBufferIOSurfaceBackend.h	2020-07-20 20:18:29 UTC (rev 264615)
@@ -56,6 +56,7 @@
 
     void drawConsuming(GraphicsContext&, const FloatRect& destRect, const FloatRect& srcRect, const ImagePaintingOptions&) override;
 
+    RetainPtr<CFDataRef> toCFData(const String& mimeType, Optional<double> quality, PreserveResolution) const override;
     Vector<uint8_t> toBGRAData() const override;
 
     RefPtr<ImageData> getImageData(AlphaPremultiplication outputFormat, const IntRect&) const override;
@@ -67,6 +68,7 @@
     ColorFormat backendColorFormat() const override;
 
     std::unique_ptr<IOSurface> m_surface;
+    mutable bool m_requiresDrawAfterPutImageData { false };
 };
 
 } // namespace WebCore
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to