Changeset 221149 in webkit


Ignore:
Timestamp:
Aug 24, 2017 11:11:16 AM (7 years ago)
Author:
timothy_horton@apple.com
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.

Location:
trunk/Source/WebKit
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r221138 r221149  
     12017-08-24  Tim Horton  <timothy_horton@apple.com>
     2
     3        _WKThumbnailView snapshots have to be copied by CA on first commit due to bad row alignment
     4        https://bugs.webkit.org/show_bug.cgi?id=175898
     5        <rdar://problem/34029673>
     6
     7        Reviewed by Sam Weinig.
     8
     9        In order to avoid copying, CGImages used as layer contents need to have certain
     10        alignment requirements fulfilled. Align the row stride to the desired value.
     11
     12        * Shared/ShareableBitmap.cpp:
     13        (WebKit::ShareableBitmap::create):
     14        (WebKit::ShareableBitmap::createShareable):
     15        (WebKit::ShareableBitmap::numBytesForSize):
     16        (WebKit::ShareableBitmap::calculateBytesPerPixel): Deleted.
     17        * Shared/ShareableBitmap.h:
     18        (WebKit::ShareableBitmap::sizeInBytes const):
     19        (WebKit::ShareableBitmap::numBytesForSize): Deleted.
     20        Merge the interfaces of numBytesPerSize and sizeInBytes between the platforms.
     21        numBytesForSize now makes use of the new calculateBytesPerRow, which is
     22        implemented by each platform ShareableBitmap implementation to do the
     23        requisite alignment for that platform.
     24
     25        * Shared/cairo/ShareableBitmapCairo.cpp:
     26        (WebKit::ShareableBitmap::calculateBytesPerRow):
     27        (WebKit::ShareableBitmap::calculateBytesPerPixel):
     28        (WebKit::createSurfaceFromData):
     29        (WebKit::ShareableBitmap::numBytesForSize): Deleted.
     30        Implement calculateBytesPerRow (which used to be hidden inside of numBytesForSize)
     31        and get rid of the now-duplicative numBytesForSize.
     32
     33        * Shared/cg/ShareableBitmapCG.cpp:
     34        (WebKit::ShareableBitmap::calculateBytesPerRow):
     35        (WebKit::ShareableBitmap::createGraphicsContext):
     36        (WebKit::ShareableBitmap::createCGImage const):
     37        Implement calculateBytesPerRow and make use of it when providing a row stride
     38        to CoreGraphics.
     39
    1402017-08-24  Chris Dumez  <cdumez@apple.com>
    241
  • trunk/Source/WebKit/Shared/ShareableBitmap.cpp

    r221068 r221149  
    8585RefPtr<ShareableBitmap> ShareableBitmap::create(const IntSize& size, Configuration configuration)
    8686{
    87     auto numBytes = numBytesForSize(size, calculateBytesPerPixel(configuration));
     87    auto numBytes = numBytesForSize(size, configuration);
    8888    if (numBytes.hasOverflowed())
    8989        return nullptr;
     
    9898RefPtr<ShareableBitmap> ShareableBitmap::createShareable(const IntSize& size, Configuration configuration)
    9999{
    100     auto numBytes = numBytesForSize(size, calculateBytesPerPixel(configuration));
     100    auto numBytes = numBytesForSize(size, configuration);
    101101    if (numBytes.hasOverflowed())
    102102        return nullptr;
     
    113113    ASSERT(sharedMemory);
    114114
    115     auto numBytes = numBytesForSize(size, calculateBytesPerPixel(configuration));
     115    auto numBytes = numBytesForSize(size, configuration);
    116116    if (numBytes.hasOverflowed())
    117117        return nullptr;
     
    175175}
    176176
    177 #if !USE(CG)
    178 unsigned ShareableBitmap::calculateBytesPerPixel(const Configuration&)
     177Checked<unsigned, RecordOverflow> ShareableBitmap::numBytesForSize(WebCore::IntSize size, const ShareableBitmap::Configuration& configuration)
    179178{
    180     return 4;
     179    return calculateBytesPerRow(size, configuration) * size.height();
    181180}
    182 #endif
    183181
    184182} // namespace WebKit
  • trunk/Source/WebKit/Shared/ShareableBitmap.h

    r221068 r221149  
    130130    ShareableBitmap(const WebCore::IntSize&, Configuration, RefPtr<SharedMemory>);
    131131
    132 #if USE(CAIRO)
    133     static Checked<unsigned, RecordOverflow> numBytesForSize(const WebCore::IntSize&);
    134     static Checked<unsigned, RecordOverflow> numBytesForSize(const WebCore::IntSize& size, unsigned bytesPerPixel) { return numBytesForSize(size); }
    135 #else
    136     static Checked<unsigned, RecordOverflow> numBytesForSize(const WebCore::IntSize& size, unsigned bytesPerPixel) { return size.area<RecordOverflow>() * bytesPerPixel; }
    137 #endif
     132    static Checked<unsigned, RecordOverflow> numBytesForSize(WebCore::IntSize, const ShareableBitmap::Configuration&);
     133    static Checked<unsigned, RecordOverflow> calculateBytesPerRow(WebCore::IntSize, const Configuration&);
     134    static unsigned calculateBytesPerPixel(const Configuration&);
    138135
    139136#if USE(CG)
     
    148145
    149146    void* data() const;
    150 #if USE(CAIRO)
    151     size_t sizeInBytes() const { return numBytesForSize(m_size).unsafeGet(); }
    152 #else
    153     size_t sizeInBytes() const { return numBytesForSize(m_size, calculateBytesPerPixel(m_configuration)).unsafeGet(); }
    154 #endif
    155 
    156     static unsigned calculateBytesPerPixel(const Configuration&);
     147    size_t sizeInBytes() const { return numBytesForSize(m_size, m_configuration).unsafeGet(); }
    157148
    158149    WebCore::IntSize m_size;
  • trunk/Source/WebKit/Shared/cairo/ShareableBitmapCairo.cpp

    r216833 r221149  
    4141static const cairo_format_t cairoFormat = CAIRO_FORMAT_ARGB32;
    4242
    43 Checked<unsigned, RecordOverflow> ShareableBitmap::numBytesForSize(const WebCore::IntSize& size)
     43Checked<unsigned, RecordOverflow> ShareableBitmap::calculateBytesPerRow(WebCore::IntSize size, const Configuration&)
    4444{
    45     return Checked<unsigned, RecordOverflow>(cairo_format_stride_for_width(cairoFormat, size.width())) * size.height();
     45    return cairo_format_stride_for_width(cairoFormat, size.width());
     46}
     47
     48unsigned ShareableBitmap::calculateBytesPerPixel(const Configuration&)
     49{
     50    return 4;
    4651}
    4752
  • trunk/Source/WebKit/Shared/cg/ShareableBitmapCG.cpp

    r221068 r221149  
    3131#include <WebCore/PlatformScreen.h>
    3232#include <pal/spi/cg/CoreGraphicsSPI.h>
     33#include <pal/spi/cocoa/IOSurfaceSPI.h>
    3334#include <wtf/RetainPtr.h>
    3435#include "CGUtilities.h"
     
    7576}
    7677
     78Checked<unsigned, RecordOverflow> ShareableBitmap::calculateBytesPerRow(WebCore::IntSize size, const Configuration& configuration)
     79{
     80    unsigned bytesPerRow = calculateBytesPerPixel(configuration) * size.width();
     81#if USE(IOSURFACE)
     82    return IOSurfaceAlignProperty(kIOSurfaceBytesPerRow, bytesPerRow);
     83#else
     84    return bytesPerRow;
     85#endif
     86}
     87
    7788unsigned ShareableBitmap::calculateBytesPerPixel(const Configuration& configuration)
    7889{
     
    8596
    8697    unsigned bytesPerPixel = calculateBytesPerPixel(m_configuration);
    87     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));
     98    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));
    8899   
    89100    ASSERT(bitmapContext.get());
     
    124135    ASSERT_ARG(dataProvider, dataProvider);
    125136    unsigned bytesPerPixel = calculateBytesPerPixel(m_configuration);
    126     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));
     137    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));
    127138    return image;
    128139}
Note: See TracChangeset for help on using the changeset viewer.