Title: [221149] trunk/Source/WebKit
Revision
221149
Author
timothy_hor...@apple.com
Date
2017-08-24 11:11:16 -0700 (Thu, 24 Aug 2017)

Log Message

_WKThumbnailView snapshots have to be copied by CA on first commit due to bad row alignment
https://bugs.webkit.org/show_bug.cgi?id=175898
<rdar://problem/34029673>

Reviewed by Sam Weinig.

In order to avoid copying, CGImages used as layer contents need to have certain
alignment requirements fulfilled. Align the row stride to the desired value.

* Shared/ShareableBitmap.cpp:
(WebKit::ShareableBitmap::create):
(WebKit::ShareableBitmap::createShareable):
(WebKit::ShareableBitmap::numBytesForSize):
(WebKit::ShareableBitmap::calculateBytesPerPixel): Deleted.
* Shared/ShareableBitmap.h:
(WebKit::ShareableBitmap::sizeInBytes const):
(WebKit::ShareableBitmap::numBytesForSize): Deleted.
Merge the interfaces of numBytesPerSize and sizeInBytes between the platforms.
numBytesForSize now makes use of the new calculateBytesPerRow, which is
implemented by each platform ShareableBitmap implementation to do the
requisite alignment for that platform.

* Shared/cairo/ShareableBitmapCairo.cpp:
(WebKit::ShareableBitmap::calculateBytesPerRow):
(WebKit::ShareableBitmap::calculateBytesPerPixel):
(WebKit::createSurfaceFromData):
(WebKit::ShareableBitmap::numBytesForSize): Deleted.
Implement calculateBytesPerRow (which used to be hidden inside of numBytesForSize)
and get rid of the now-duplicative numBytesForSize.

* Shared/cg/ShareableBitmapCG.cpp:
(WebKit::ShareableBitmap::calculateBytesPerRow):
(WebKit::ShareableBitmap::createGraphicsContext):
(WebKit::ShareableBitmap::createCGImage const):
Implement calculateBytesPerRow and make use of it when providing a row stride
to CoreGraphics.

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (221148 => 221149)


--- trunk/Source/WebKit/ChangeLog	2017-08-24 18:00:09 UTC (rev 221148)
+++ trunk/Source/WebKit/ChangeLog	2017-08-24 18:11:16 UTC (rev 221149)
@@ -1,3 +1,42 @@
+2017-08-24  Tim Horton  <timothy_hor...@apple.com>
+
+        _WKThumbnailView snapshots have to be copied by CA on first commit due to bad row alignment
+        https://bugs.webkit.org/show_bug.cgi?id=175898
+        <rdar://problem/34029673>
+
+        Reviewed by Sam Weinig.
+
+        In order to avoid copying, CGImages used as layer contents need to have certain
+        alignment requirements fulfilled. Align the row stride to the desired value.
+
+        * Shared/ShareableBitmap.cpp:
+        (WebKit::ShareableBitmap::create):
+        (WebKit::ShareableBitmap::createShareable):
+        (WebKit::ShareableBitmap::numBytesForSize):
+        (WebKit::ShareableBitmap::calculateBytesPerPixel): Deleted.
+        * Shared/ShareableBitmap.h:
+        (WebKit::ShareableBitmap::sizeInBytes const):
+        (WebKit::ShareableBitmap::numBytesForSize): Deleted.
+        Merge the interfaces of numBytesPerSize and sizeInBytes between the platforms.
+        numBytesForSize now makes use of the new calculateBytesPerRow, which is
+        implemented by each platform ShareableBitmap implementation to do the
+        requisite alignment for that platform.
+
+        * Shared/cairo/ShareableBitmapCairo.cpp:
+        (WebKit::ShareableBitmap::calculateBytesPerRow):
+        (WebKit::ShareableBitmap::calculateBytesPerPixel):
+        (WebKit::createSurfaceFromData):
+        (WebKit::ShareableBitmap::numBytesForSize): Deleted.
+        Implement calculateBytesPerRow (which used to be hidden inside of numBytesForSize)
+        and get rid of the now-duplicative numBytesForSize.
+
+        * Shared/cg/ShareableBitmapCG.cpp:
+        (WebKit::ShareableBitmap::calculateBytesPerRow):
+        (WebKit::ShareableBitmap::createGraphicsContext):
+        (WebKit::ShareableBitmap::createCGImage const):
+        Implement calculateBytesPerRow and make use of it when providing a row stride
+        to CoreGraphics.
+
 2017-08-24  Chris Dumez  <cdu...@apple.com>
 
         [iOS] ViewServices started by StoreKitUIService may get suspended unexpectedly

Modified: trunk/Source/WebKit/Shared/ShareableBitmap.cpp (221148 => 221149)


--- trunk/Source/WebKit/Shared/ShareableBitmap.cpp	2017-08-24 18:00:09 UTC (rev 221148)
+++ trunk/Source/WebKit/Shared/ShareableBitmap.cpp	2017-08-24 18:11:16 UTC (rev 221149)
@@ -84,7 +84,7 @@
 
 RefPtr<ShareableBitmap> ShareableBitmap::create(const IntSize& size, Configuration configuration)
 {
-    auto numBytes = numBytesForSize(size, calculateBytesPerPixel(configuration));
+    auto numBytes = numBytesForSize(size, configuration);
     if (numBytes.hasOverflowed())
         return nullptr;
 
@@ -97,7 +97,7 @@
 
 RefPtr<ShareableBitmap> ShareableBitmap::createShareable(const IntSize& size, Configuration configuration)
 {
-    auto numBytes = numBytesForSize(size, calculateBytesPerPixel(configuration));
+    auto numBytes = numBytesForSize(size, configuration);
     if (numBytes.hasOverflowed())
         return nullptr;
 
@@ -112,7 +112,7 @@
 {
     ASSERT(sharedMemory);
 
-    auto numBytes = numBytesForSize(size, calculateBytesPerPixel(configuration));
+    auto numBytes = numBytesForSize(size, configuration);
     if (numBytes.hasOverflowed())
         return nullptr;
     if (sharedMemory->size() < numBytes.unsafeGet()) {
@@ -174,11 +174,9 @@
     return m_data;
 }
 
-#if !USE(CG)
-unsigned ShareableBitmap::calculateBytesPerPixel(const Configuration&)
+Checked<unsigned, RecordOverflow> ShareableBitmap::numBytesForSize(WebCore::IntSize size, const ShareableBitmap::Configuration& configuration)
 {
-    return 4;
+    return calculateBytesPerRow(size, configuration) * size.height();
 }
-#endif
 
 } // namespace WebKit

Modified: trunk/Source/WebKit/Shared/ShareableBitmap.h (221148 => 221149)


--- trunk/Source/WebKit/Shared/ShareableBitmap.h	2017-08-24 18:00:09 UTC (rev 221148)
+++ trunk/Source/WebKit/Shared/ShareableBitmap.h	2017-08-24 18:11:16 UTC (rev 221149)
@@ -129,12 +129,9 @@
     ShareableBitmap(const WebCore::IntSize&, Configuration, void*);
     ShareableBitmap(const WebCore::IntSize&, Configuration, RefPtr<SharedMemory>);
 
-#if USE(CAIRO)
-    static Checked<unsigned, RecordOverflow> numBytesForSize(const WebCore::IntSize&);
-    static Checked<unsigned, RecordOverflow> numBytesForSize(const WebCore::IntSize& size, unsigned bytesPerPixel) { return numBytesForSize(size); }
-#else
-    static Checked<unsigned, RecordOverflow> numBytesForSize(const WebCore::IntSize& size, unsigned bytesPerPixel) { return size.area<RecordOverflow>() * bytesPerPixel; }
-#endif
+    static Checked<unsigned, RecordOverflow> numBytesForSize(WebCore::IntSize, const ShareableBitmap::Configuration&);
+    static Checked<unsigned, RecordOverflow> calculateBytesPerRow(WebCore::IntSize, const Configuration&);
+    static unsigned calculateBytesPerPixel(const Configuration&);
 
 #if USE(CG)
     RetainPtr<CGImageRef> createCGImage(CGDataProviderRef) const;
@@ -147,14 +144,8 @@
 #endif
 
     void* data() const;
-#if USE(CAIRO)
-    size_t sizeInBytes() const { return numBytesForSize(m_size).unsafeGet(); }
-#else
-    size_t sizeInBytes() const { return numBytesForSize(m_size, calculateBytesPerPixel(m_configuration)).unsafeGet(); }
-#endif
+    size_t sizeInBytes() const { return numBytesForSize(m_size, m_configuration).unsafeGet(); }
 
-    static unsigned calculateBytesPerPixel(const Configuration&);
-
     WebCore::IntSize m_size;
     Configuration m_configuration;
 

Modified: trunk/Source/WebKit/Shared/cairo/ShareableBitmapCairo.cpp (221148 => 221149)


--- trunk/Source/WebKit/Shared/cairo/ShareableBitmapCairo.cpp	2017-08-24 18:00:09 UTC (rev 221148)
+++ trunk/Source/WebKit/Shared/cairo/ShareableBitmapCairo.cpp	2017-08-24 18:11:16 UTC (rev 221149)
@@ -40,11 +40,16 @@
 
 static const cairo_format_t cairoFormat = CAIRO_FORMAT_ARGB32;
 
-Checked<unsigned, RecordOverflow> ShareableBitmap::numBytesForSize(const WebCore::IntSize& size)
+Checked<unsigned, RecordOverflow> ShareableBitmap::calculateBytesPerRow(WebCore::IntSize size, const Configuration&)
 {
-    return Checked<unsigned, RecordOverflow>(cairo_format_stride_for_width(cairoFormat, size.width())) * size.height();
+    return cairo_format_stride_for_width(cairoFormat, size.width());
 }
 
+unsigned ShareableBitmap::calculateBytesPerPixel(const Configuration&)
+{
+    return 4;
+}
+
 static inline RefPtr<cairo_surface_t> createSurfaceFromData(void* data, const WebCore::IntSize& size)
 {
     const int stride = cairo_format_stride_for_width(cairoFormat, size.width());

Modified: trunk/Source/WebKit/Shared/cg/ShareableBitmapCG.cpp (221148 => 221149)


--- trunk/Source/WebKit/Shared/cg/ShareableBitmapCG.cpp	2017-08-24 18:00:09 UTC (rev 221148)
+++ trunk/Source/WebKit/Shared/cg/ShareableBitmapCG.cpp	2017-08-24 18:11:16 UTC (rev 221149)
@@ -30,6 +30,7 @@
 #include <WebCore/GraphicsContextCG.h>
 #include <WebCore/PlatformScreen.h>
 #include <pal/spi/cg/CoreGraphicsSPI.h>
+#include <pal/spi/cocoa/IOSurfaceSPI.h>
 #include <wtf/RetainPtr.h>
 #include "CGUtilities.h"
 
@@ -74,6 +75,16 @@
     return info;
 }
 
+Checked<unsigned, RecordOverflow> ShareableBitmap::calculateBytesPerRow(WebCore::IntSize size, const Configuration& configuration)
+{
+    unsigned bytesPerRow = calculateBytesPerPixel(configuration) * size.width();
+#if USE(IOSURFACE)
+    return IOSurfaceAlignProperty(kIOSurfaceBytesPerRow, bytesPerRow);
+#else
+    return bytesPerRow;
+#endif
+}
+
 unsigned ShareableBitmap::calculateBytesPerPixel(const Configuration& configuration)
 {
     return wantsExtendedRange(configuration) ? 8 : 4;
@@ -84,7 +95,7 @@
     ref(); // Balanced by deref in releaseBitmapContextData.
 
     unsigned bytesPerPixel = calculateBytesPerPixel(m_configuration);
-    RetainPtr<CGContextRef> bitmapContext = adoptCF(CGBitmapContextCreateWithData(data(), m_size.width(), m_size.height(), bytesPerPixel * 8 / 4, m_size.width() * bytesPerPixel, colorSpace(m_configuration), bitmapInfo(m_configuration), releaseBitmapContextData, this));
+    RetainPtr<CGContextRef> bitmapContext = adoptCF(CGBitmapContextCreateWithData(data(), m_size.width(), m_size.height(), bytesPerPixel * 8 / 4, calculateBytesPerRow(m_size, m_configuration).unsafeGet(), colorSpace(m_configuration), bitmapInfo(m_configuration), releaseBitmapContextData, this));
     
     ASSERT(bitmapContext.get());
 
@@ -123,7 +134,7 @@
 {
     ASSERT_ARG(dataProvider, dataProvider);
     unsigned bytesPerPixel = calculateBytesPerPixel(m_configuration);
-    RetainPtr<CGImageRef> image = adoptCF(CGImageCreate(m_size.width(), m_size.height(), bytesPerPixel * 8 / 4, bytesPerPixel * 8, m_size.width() * bytesPerPixel, colorSpace(m_configuration), bitmapInfo(m_configuration), dataProvider, 0, false, kCGRenderingIntentDefault));
+    RetainPtr<CGImageRef> image = adoptCF(CGImageCreate(m_size.width(), m_size.height(), bytesPerPixel * 8 / 4, bytesPerPixel * 8, calculateBytesPerRow(m_size, m_configuration).unsafeGet(), colorSpace(m_configuration), bitmapInfo(m_configuration), dataProvider, 0, false, kCGRenderingIntentDefault));
     return image;
 }
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to