Changeset 208020 in webkit


Ignore:
Timestamp:
Oct 27, 2016 5:50:53 PM (7 years ago)
Author:
commit-queue@webkit.org
Message:

Add support for wide gamut for ShareableBitmap for image popovers
https://bugs.webkit.org/show_bug.cgi?id=164001

Patch by Megan Gardner <Megan Gardner> on 2016-10-27
Reviewed by Simon Fraser.

Source/WebCore:

Add a function to return a CGColorSpaceRef for extended sRGB.

This is currently untestable, so no tests added.

  • platform/graphics/cg/GraphicsContextCG.cpp:

(WebCore::extendedSRGBColorSpaceRef):

Source/WebKit2:

Added suppport for wide gamut in ShareableBitmap. SharableBitmaps now know the size of their pixels,
and that data is passed back and forth between the processes. The callers of SharedBitmap will determine
if their image should support wide gamut, but ShareableBitmap will override a set flag on a device that
is incapbable of supporting a wide gamut image.
This makes it possible to show wide gamut images in image popovers on iOS.
This is currently untestable, so no tests added.

  • Platform/IPC/Decoder.cpp:

(IPC::Decoder::decode):

  • Platform/IPC/Decoder.h:
  • Platform/IPC/Encoder.cpp:

(IPC::Encoder::encode):

  • Platform/IPC/Encoder.h:
  • Shared/ShareableBitmap.cpp:

(WebKit::bytesPerPixel):
(WebKit::ShareableBitmap::Handle::encode):
(WebKit::ShareableBitmap::Handle::decode):
(WebKit::ShareableBitmap::Handle::clear):
(WebKit::ShareableBitmap::create):
(WebKit::ShareableBitmap::createShareable):
(WebKit::ShareableBitmap::createHandle):
(WebKit::ShareableBitmap::ShareableBitmap):

  • Shared/ShareableBitmap.h:

(WebKit::ShareableBitmap::numBytesForSize):
(WebKit::ShareableBitmap::sizeInBytes):

  • Shared/cg/ShareableBitmapCG.cpp:

(WebKit::bitmapInfo):
(WebKit::ShareableBitmap::createGraphicsContext):
(WebKit::ShareableBitmap::createCGImage):

  • WebProcess/WebPage/ios/WebPageIOS.mm:

(WebKit::WebPage::getPositionInformation):

Location:
trunk/Source
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r208019 r208020  
     12016-10-27  Megan Gardner  <megan_gardner@apple.com>
     2
     3        Add support for wide gamut for ShareableBitmap for image popovers
     4        https://bugs.webkit.org/show_bug.cgi?id=164001
     5
     6        Reviewed by Simon Fraser.
     7
     8        Add a function to return a CGColorSpaceRef for extended sRGB.
     9
     10        This is currently untestable, so no tests added.
     11
     12        * platform/graphics/cg/GraphicsContextCG.cpp:
     13        (WebCore::extendedSRGBColorSpaceRef):
     14
    1152016-10-25  Brent Fulgham  <bfulgham@apple.com>
    216
  • trunk/Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp

    r207366 r208020  
    9393#endif // PLATFORM(WIN)
    9494    return sRGBSpace;
     95}
     96   
     97CGColorSpaceRef extendedSRGBColorSpaceRef()
     98{
     99    static CGColorSpaceRef extendedSRGBSpace;
     100#if (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 100000) || (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED > 101200)
     101    extendedSRGBSpace = CGColorSpaceCreateWithName(kCGColorSpaceExtendedSRGB);
     102#endif
     103    // If there is no support for exteneded sRGB, fall back to sRGB.
     104    if (!extendedSRGBSpace)
     105        extendedSRGBSpace = sRGBColorSpaceRef();
     106    return extendedSRGBSpace;
    95107}
    96108
  • trunk/Source/WebCore/platform/graphics/cg/GraphicsContextCG.h

    r207366 r208020  
    3535CGColorSpaceRef deviceRGBColorSpaceRef();
    3636WEBCORE_EXPORT CGColorSpaceRef sRGBColorSpaceRef();
     37WEBCORE_EXPORT CGColorSpaceRef extendedSRGBColorSpaceRef();
    3738WEBCORE_EXPORT CGColorSpaceRef displayP3ColorSpaceRef();
    3839CGColorSpaceRef linearRGBColorSpaceRef();
  • trunk/Source/WebKit2/ChangeLog

    r208014 r208020  
     12016-10-27  Megan Gardner  <megan_gardner@apple.com>
     2
     3        Add support for wide gamut for ShareableBitmap for image popovers
     4        https://bugs.webkit.org/show_bug.cgi?id=164001
     5
     6        Reviewed by Simon Fraser.
     7
     8        Added suppport for wide gamut in ShareableBitmap. SharableBitmaps now know the size of their pixels,
     9        and that data is passed back and forth between the processes. The callers of SharedBitmap will determine
     10        if their image should support wide gamut, but ShareableBitmap will override a set flag on a device that
     11        is incapbable of supporting a wide gamut image.
     12        This makes it possible to show wide gamut images in image popovers on iOS.
     13        This is currently untestable, so no tests added.
     14
     15        * Platform/IPC/Decoder.cpp:
     16        (IPC::Decoder::decode):
     17        * Platform/IPC/Decoder.h:
     18        * Platform/IPC/Encoder.cpp:
     19        (IPC::Encoder::encode):
     20        * Platform/IPC/Encoder.h:
     21        * Shared/ShareableBitmap.cpp:
     22        (WebKit::bytesPerPixel):
     23        (WebKit::ShareableBitmap::Handle::encode):
     24        (WebKit::ShareableBitmap::Handle::decode):
     25        (WebKit::ShareableBitmap::Handle::clear):
     26        (WebKit::ShareableBitmap::create):
     27        (WebKit::ShareableBitmap::createShareable):
     28        (WebKit::ShareableBitmap::createHandle):
     29        (WebKit::ShareableBitmap::ShareableBitmap):
     30        * Shared/ShareableBitmap.h:
     31        (WebKit::ShareableBitmap::numBytesForSize):
     32        (WebKit::ShareableBitmap::sizeInBytes):
     33        * Shared/cg/ShareableBitmapCG.cpp:
     34        (WebKit::bitmapInfo):
     35        (WebKit::ShareableBitmap::createGraphicsContext):
     36        (WebKit::ShareableBitmap::createCGImage):
     37        * WebProcess/WebPage/ios/WebPageIOS.mm:
     38        (WebKit::WebPage::getPositionInformation):
     39
    1402016-10-27  Wenson Hsieh  <wenson_hsieh@apple.com>
    241
  • trunk/Source/WebKit2/Shared/ShareableBitmap.cpp

    r207708 r208020  
    3434
    3535namespace WebKit {
     36   
     37static unsigned calculateBytesPerPixel(ShareableBitmap::Flags flags)
     38{
     39    if (flags & ShareableBitmap::SupportsExtendedColor)
     40        return 8; // for extended color, we are using half-float representations
     41    return 4;
     42}
    3643
    3744ShareableBitmap::Handle::Handle()
     
    5562    if (!decoder.decode(handle.m_flags))
    5663        return false;
     64    handle.m_bytesPerPixel = calculateBytesPerPixel(handle.m_flags);
    5765    return true;
    5866}
     
    6371    m_size = IntSize();
    6472    m_flags = Flag::NoFlags;
     73    m_bytesPerPixel = calculateBytesPerPixel(m_flags);
    6574}
    6675
    6776RefPtr<ShareableBitmap> ShareableBitmap::create(const IntSize& size, Flags flags)
    6877{
    69     auto numBytes = numBytesForSize(size);
     78    unsigned bytesPerPixel = calculateBytesPerPixel(flags);
     79    auto numBytes = numBytesForSize(size, bytesPerPixel);
    7080    if (numBytes.hasOverflowed())
    7181        return nullptr;
     
    8090RefPtr<ShareableBitmap> ShareableBitmap::createShareable(const IntSize& size, Flags flags)
    8191{
    82     auto numBytes = numBytesForSize(size);
     92    unsigned bytesPerPixel = calculateBytesPerPixel(flags);
     93    auto numBytes = numBytesForSize(size, bytesPerPixel);
    8394    if (numBytes.hasOverflowed())
    8495        return nullptr;
     
    95106    ASSERT(sharedMemory);
    96107
    97     auto numBytes = numBytesForSize(size);
     108    unsigned bytesPerPixel = calculateBytesPerPixel(flags);
     109    auto numBytes = numBytesForSize(size, bytesPerPixel);
    98110    if (numBytes.hasOverflowed())
    99111        return nullptr;
     
    102114        return nullptr;
    103115    }
    104 
     116   
    105117    return adoptRef(new ShareableBitmap(size, flags, sharedMemory));
    106118}
     
    124136    handle.m_size = m_size;
    125137    handle.m_flags = m_flags;
     138    handle.m_bytesPerPixel = m_bytesPerPixel;
    126139    return true;
    127140}
     
    132145    , m_data(data)
    133146{
     147    m_bytesPerPixel = calculateBytesPerPixel(flags);
    134148}
    135149
     
    140154    , m_data(0)
    141155{
     156    m_bytesPerPixel = calculateBytesPerPixel(flags);
    142157}
    143158
  • trunk/Source/WebKit2/Shared/ShareableBitmap.h

    r207708 r208020  
    5252        NoFlags = 0,
    5353        SupportsAlpha = 1 << 0,
     54        SupportsExtendedColor = 1 << 1,
    5455    };
    5556    typedef unsigned Flags;
     
    7374        WebCore::IntSize m_size;
    7475        Flags m_flags;
     76        unsigned m_bytesPerPixel;
    7577    };
    7678
     
    127129#if USE(CAIRO)
    128130    static Checked<unsigned, RecordOverflow> numBytesForSize(const WebCore::IntSize&);
     131    static Checked<unsigned, RecordOverflow> numBytesForSize(const WebCore::IntSize& size, unsigned bytesPerPixel) { return numBytesForSize(size); }
    129132#else
    130     static Checked<unsigned, RecordOverflow> numBytesForSize(const WebCore::IntSize& size) { return size.area<RecordOverflow>() * 4; }
     133    static Checked<unsigned, RecordOverflow> numBytesForSize(const WebCore::IntSize& size, unsigned bytesPerPixel) { return size.area<RecordOverflow>() * bytesPerPixel; }
    131134#endif
    132135
     
    142145
    143146    void* data() const;
     147#if USE(CAIRO)
    144148    size_t sizeInBytes() const { return numBytesForSize(m_size).unsafeGet(); }
    145 
     149#else
     150    size_t sizeInBytes() const { return numBytesForSize(m_size, m_bytesPerPixel).unsafeGet(); }
     151#endif
     152   
    146153    WebCore::IntSize m_size;
    147154    Flags m_flags;
     155    unsigned m_bytesPerPixel;
    148156
    149157    // If the shareable bitmap is backed by shared memory, this points to the shared memory object.
  • trunk/Source/WebKit2/Shared/cg/ShareableBitmapCG.cpp

    r198655 r208020  
    2929#include <WebCore/BitmapImage.h>
    3030#include <WebCore/GraphicsContextCG.h>
     31#include <WebCore/PlatformScreen.h>
    3132#include <wtf/RetainPtr.h>
    3233#include "CGUtilities.h"
     
    3839static CGBitmapInfo bitmapInfo(ShareableBitmap::Flags flags)
    3940{
    40     CGBitmapInfo info = kCGBitmapByteOrder32Host;
    41     if (flags & ShareableBitmap::SupportsAlpha)
    42         info |= kCGImageAlphaPremultipliedFirst;
    43     else
    44         info |= kCGImageAlphaNoneSkipFirst;
    45 
     41    CGBitmapInfo info = 0;
     42    if ((flags & ShareableBitmap::SupportsExtendedColor) && screenSupportsExtendedColor()) {
     43        info |= kCGBitmapFloatComponents | kCGBitmapByteOrder16Host;
     44       
     45        if (flags & ShareableBitmap::SupportsAlpha)
     46            info |= kCGImageAlphaPremultipliedLast;
     47        else
     48            info |= kCGImageAlphaNoneSkipLast;
     49       
     50    } else {
     51        info |= kCGBitmapByteOrder32Host;
     52       
     53        if (flags & ShareableBitmap::SupportsAlpha)
     54            info |= kCGImageAlphaPremultipliedFirst;
     55        else
     56            info |= kCGImageAlphaNoneSkipFirst;
     57    }
     58   
    4659    return info;
    4760}
     
    5063{
    5164    ref(); // Balanced by deref in releaseBitmapContextData.
    52     RetainPtr<CGContextRef> bitmapContext = adoptCF(CGBitmapContextCreateWithData(data(),
    53         m_size.width(), m_size.height(), 8, m_size.width() * 4, sRGBColorSpaceRef(),
    54         bitmapInfo(m_flags), releaseBitmapContextData, this));
     65   
     66    CGColorSpaceRef colorSpace;
     67    if (m_flags & ShareableBitmap::SupportsExtendedColor)
     68        colorSpace = extendedSRGBColorSpaceRef();
     69    else
     70        colorSpace = sRGBColorSpaceRef();
     71   
     72    RetainPtr<CGContextRef> bitmapContext = adoptCF(CGBitmapContextCreateWithData(data(), m_size.width(), m_size.height(), m_bytesPerPixel * 8 / 4, m_size.width() * m_bytesPerPixel, colorSpace, bitmapInfo(m_flags), releaseBitmapContextData, this));
     73   
     74    ASSERT(bitmapContext.get());
    5575
    5676    // We want the origin to be in the top left corner so we flip the backing store context.
     
    88108{
    89109    ASSERT_ARG(dataProvider, dataProvider);
    90 
     110    // FIXME: Make this use extended color, etc.
    91111    RetainPtr<CGImageRef> image = adoptCF(CGImageCreate(m_size.width(), m_size.height(), 8, 32, m_size.width() * 4, sRGBColorSpaceRef(), bitmapInfo(m_flags), dataProvider, 0, false, kCGRenderingIntentDefault));
    92112    return image;
  • trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm

    r206626 r208020  
    23582358                                FloatSize scaledSize = largestRectWithAspectRatioInsideRect(image->size().width() / image->size().height(), FloatRect(0, 0, screenSizeInPixels.width(), screenSizeInPixels.height())).size();
    23592359                                FloatSize bitmapSize = scaledSize.width() < image->size().width() ? scaledSize : image->size();
    2360                                 if (RefPtr<ShareableBitmap> sharedBitmap = ShareableBitmap::createShareable(IntSize(bitmapSize), ShareableBitmap::SupportsAlpha)) {
     2360                                // FIXME: Only select ExtendedColor on images known to need wide gamut
     2361                                ShareableBitmap::Flags flags = ShareableBitmap::SupportsAlpha;
     2362                                flags |= screenSupportsExtendedColor() ? ShareableBitmap::SupportsExtendedColor : 0;
     2363                                if (RefPtr<ShareableBitmap> sharedBitmap = ShareableBitmap::createShareable(IntSize(bitmapSize), flags)) {
    23612364                                    auto graphicsContext = sharedBitmap->createGraphicsContext();
    23622365                                    graphicsContext->drawImage(*image, FloatRect(0, 0, bitmapSize.width(), bitmapSize.height()));
Note: See TracChangeset for help on using the changeset viewer.