Title: [208020] trunk/Source
Revision
208020
Author
commit-qu...@webkit.org
Date
2016-10-27 17:50:53 -0700 (Thu, 27 Oct 2016)

Log 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_gard...@apple.com> 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):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (208019 => 208020)


--- trunk/Source/WebCore/ChangeLog	2016-10-28 00:21:31 UTC (rev 208019)
+++ trunk/Source/WebCore/ChangeLog	2016-10-28 00:50:53 UTC (rev 208020)
@@ -1,3 +1,17 @@
+2016-10-27  Megan Gardner  <megan_gard...@apple.com>
+
+        Add support for wide gamut for ShareableBitmap for image popovers
+        https://bugs.webkit.org/show_bug.cgi?id=164001
+
+        Reviewed by Simon Fraser.
+
+        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):
+
 2016-10-25  Brent Fulgham  <bfulg...@apple.com>
 
         [Win][Direct2D] Create a RAII Helper Class for the Render Target

Modified: trunk/Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp (208019 => 208020)


--- trunk/Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp	2016-10-28 00:21:31 UTC (rev 208019)
+++ trunk/Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp	2016-10-28 00:50:53 UTC (rev 208020)
@@ -93,6 +93,18 @@
 #endif // PLATFORM(WIN)
     return sRGBSpace;
 }
+    
+CGColorSpaceRef extendedSRGBColorSpaceRef()
+{
+    static CGColorSpaceRef extendedSRGBSpace;
+#if (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 100000) || (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED > 101200)
+    extendedSRGBSpace = CGColorSpaceCreateWithName(kCGColorSpaceExtendedSRGB);
+#endif
+    // If there is no support for exteneded sRGB, fall back to sRGB.
+    if (!extendedSRGBSpace)
+        extendedSRGBSpace = sRGBColorSpaceRef();
+    return extendedSRGBSpace;
+}
 
 CGColorSpaceRef displayP3ColorSpaceRef()
 {

Modified: trunk/Source/WebCore/platform/graphics/cg/GraphicsContextCG.h (208019 => 208020)


--- trunk/Source/WebCore/platform/graphics/cg/GraphicsContextCG.h	2016-10-28 00:21:31 UTC (rev 208019)
+++ trunk/Source/WebCore/platform/graphics/cg/GraphicsContextCG.h	2016-10-28 00:50:53 UTC (rev 208020)
@@ -34,6 +34,7 @@
 
 CGColorSpaceRef deviceRGBColorSpaceRef();
 WEBCORE_EXPORT CGColorSpaceRef sRGBColorSpaceRef();
+WEBCORE_EXPORT CGColorSpaceRef extendedSRGBColorSpaceRef();
 WEBCORE_EXPORT CGColorSpaceRef displayP3ColorSpaceRef();
 CGColorSpaceRef linearRGBColorSpaceRef();
 

Modified: trunk/Source/WebKit2/ChangeLog (208019 => 208020)


--- trunk/Source/WebKit2/ChangeLog	2016-10-28 00:21:31 UTC (rev 208019)
+++ trunk/Source/WebKit2/ChangeLog	2016-10-28 00:50:53 UTC (rev 208020)
@@ -1,3 +1,42 @@
+2016-10-27  Megan Gardner  <megan_gard...@apple.com>
+
+        Add support for wide gamut for ShareableBitmap for image popovers
+        https://bugs.webkit.org/show_bug.cgi?id=164001
+
+        Reviewed by Simon Fraser.
+
+        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):
+
 2016-10-27  Wenson Hsieh  <wenson_hs...@apple.com>
 
         Support "insertFromDrop" and "deleteByDrag" for the InputEvent spec

Modified: trunk/Source/WebKit2/Shared/ShareableBitmap.cpp (208019 => 208020)


--- trunk/Source/WebKit2/Shared/ShareableBitmap.cpp	2016-10-28 00:21:31 UTC (rev 208019)
+++ trunk/Source/WebKit2/Shared/ShareableBitmap.cpp	2016-10-28 00:50:53 UTC (rev 208020)
@@ -33,6 +33,13 @@
 using namespace WebCore;
 
 namespace WebKit {
+    
+static unsigned calculateBytesPerPixel(ShareableBitmap::Flags flags)
+{
+    if (flags & ShareableBitmap::SupportsExtendedColor)
+        return 8; // for extended color, we are using half-float representations
+    return 4;
+}
 
 ShareableBitmap::Handle::Handle()
     : m_flags(0)
@@ -54,6 +61,7 @@
         return false;
     if (!decoder.decode(handle.m_flags))
         return false;
+    handle.m_bytesPerPixel = calculateBytesPerPixel(handle.m_flags);
     return true;
 }
 
@@ -62,11 +70,13 @@
     m_handle.clear();
     m_size = IntSize();
     m_flags = Flag::NoFlags;
+    m_bytesPerPixel = calculateBytesPerPixel(m_flags);
 }
 
 RefPtr<ShareableBitmap> ShareableBitmap::create(const IntSize& size, Flags flags)
 {
-    auto numBytes = numBytesForSize(size);
+    unsigned bytesPerPixel = calculateBytesPerPixel(flags);
+    auto numBytes = numBytesForSize(size, bytesPerPixel);
     if (numBytes.hasOverflowed())
         return nullptr;
 
@@ -79,7 +89,8 @@
 
 RefPtr<ShareableBitmap> ShareableBitmap::createShareable(const IntSize& size, Flags flags)
 {
-    auto numBytes = numBytesForSize(size);
+    unsigned bytesPerPixel = calculateBytesPerPixel(flags);
+    auto numBytes = numBytesForSize(size, bytesPerPixel);
     if (numBytes.hasOverflowed())
         return nullptr;
 
@@ -94,7 +105,8 @@
 {
     ASSERT(sharedMemory);
 
-    auto numBytes = numBytesForSize(size);
+    unsigned bytesPerPixel = calculateBytesPerPixel(flags);
+    auto numBytes = numBytesForSize(size, bytesPerPixel);
     if (numBytes.hasOverflowed())
         return nullptr;
     if (sharedMemory->size() < numBytes.unsafeGet()) {
@@ -101,7 +113,7 @@
         ASSERT_NOT_REACHED();
         return nullptr;
     }
-
+    
     return adoptRef(new ShareableBitmap(size, flags, sharedMemory));
 }
 
@@ -123,6 +135,7 @@
         return false;
     handle.m_size = m_size;
     handle.m_flags = m_flags;
+    handle.m_bytesPerPixel = m_bytesPerPixel;
     return true;
 }
 
@@ -131,6 +144,7 @@
     , m_flags(flags)
     , m_data(data)
 {
+    m_bytesPerPixel = calculateBytesPerPixel(flags);
 }
 
 ShareableBitmap::ShareableBitmap(const IntSize& size, Flags flags, RefPtr<SharedMemory> sharedMemory)
@@ -139,6 +153,7 @@
     , m_sharedMemory(sharedMemory)
     , m_data(0)
 {
+    m_bytesPerPixel = calculateBytesPerPixel(flags);
 }
 
 ShareableBitmap::~ShareableBitmap()

Modified: trunk/Source/WebKit2/Shared/ShareableBitmap.h (208019 => 208020)


--- trunk/Source/WebKit2/Shared/ShareableBitmap.h	2016-10-28 00:21:31 UTC (rev 208019)
+++ trunk/Source/WebKit2/Shared/ShareableBitmap.h	2016-10-28 00:50:53 UTC (rev 208020)
@@ -51,6 +51,7 @@
     enum Flag {
         NoFlags = 0,
         SupportsAlpha = 1 << 0,
+        SupportsExtendedColor = 1 << 1,
     };
     typedef unsigned Flags;
 
@@ -72,6 +73,7 @@
         mutable SharedMemory::Handle m_handle;
         WebCore::IntSize m_size;
         Flags m_flags;
+        unsigned m_bytesPerPixel;
     };
 
     // Create a shareable bitmap that uses malloced memory.
@@ -126,8 +128,9 @@
 
 #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) { return size.area<RecordOverflow>() * 4; }
+    static Checked<unsigned, RecordOverflow> numBytesForSize(const WebCore::IntSize& size, unsigned bytesPerPixel) { return size.area<RecordOverflow>() * bytesPerPixel; }
 #endif
 
 #if USE(CG)
@@ -141,10 +144,15 @@
 #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, m_bytesPerPixel).unsafeGet(); }
+#endif
+    
     WebCore::IntSize m_size;
     Flags m_flags;
+    unsigned m_bytesPerPixel;
 
     // If the shareable bitmap is backed by shared memory, this points to the shared memory object.
     RefPtr<SharedMemory> m_sharedMemory;

Modified: trunk/Source/WebKit2/Shared/cg/ShareableBitmapCG.cpp (208019 => 208020)


--- trunk/Source/WebKit2/Shared/cg/ShareableBitmapCG.cpp	2016-10-28 00:21:31 UTC (rev 208019)
+++ trunk/Source/WebKit2/Shared/cg/ShareableBitmapCG.cpp	2016-10-28 00:50:53 UTC (rev 208020)
@@ -28,6 +28,7 @@
 
 #include <WebCore/BitmapImage.h>
 #include <WebCore/GraphicsContextCG.h>
+#include <WebCore/PlatformScreen.h>
 #include <wtf/RetainPtr.h>
 #include "CGUtilities.h"
 
@@ -37,12 +38,24 @@
 
 static CGBitmapInfo bitmapInfo(ShareableBitmap::Flags flags)
 {
-    CGBitmapInfo info = kCGBitmapByteOrder32Host;
-    if (flags & ShareableBitmap::SupportsAlpha)
-        info |= kCGImageAlphaPremultipliedFirst;
-    else
-        info |= kCGImageAlphaNoneSkipFirst;
-
+    CGBitmapInfo info = 0;
+    if ((flags & ShareableBitmap::SupportsExtendedColor) && screenSupportsExtendedColor()) {
+        info |= kCGBitmapFloatComponents | kCGBitmapByteOrder16Host;
+        
+        if (flags & ShareableBitmap::SupportsAlpha)
+            info |= kCGImageAlphaPremultipliedLast;
+        else
+            info |= kCGImageAlphaNoneSkipLast;
+        
+    } else {
+        info |= kCGBitmapByteOrder32Host;
+        
+        if (flags & ShareableBitmap::SupportsAlpha)
+            info |= kCGImageAlphaPremultipliedFirst;
+        else
+            info |= kCGImageAlphaNoneSkipFirst;
+    }
+    
     return info;
 }
 
@@ -49,9 +62,16 @@
 std::unique_ptr<GraphicsContext> ShareableBitmap::createGraphicsContext()
 {
     ref(); // Balanced by deref in releaseBitmapContextData.
-    RetainPtr<CGContextRef> bitmapContext = adoptCF(CGBitmapContextCreateWithData(data(),
-        m_size.width(), m_size.height(), 8, m_size.width() * 4, sRGBColorSpaceRef(),
-        bitmapInfo(m_flags), releaseBitmapContextData, this));
+    
+    CGColorSpaceRef colorSpace;
+    if (m_flags & ShareableBitmap::SupportsExtendedColor)
+        colorSpace = extendedSRGBColorSpaceRef();
+    else
+        colorSpace = sRGBColorSpaceRef();
+    
+    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));
+    
+    ASSERT(bitmapContext.get());
 
     // We want the origin to be in the top left corner so we flip the backing store context.
     CGContextTranslateCTM(bitmapContext.get(), 0, m_size.height());
@@ -87,7 +107,7 @@
 RetainPtr<CGImageRef> ShareableBitmap::createCGImage(CGDataProviderRef dataProvider) const
 {
     ASSERT_ARG(dataProvider, dataProvider);
-
+    // FIXME: Make this use extended color, etc.
     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));
     return image;
 }

Modified: trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm (208019 => 208020)


--- trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm	2016-10-28 00:21:31 UTC (rev 208019)
+++ trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm	2016-10-28 00:50:53 UTC (rev 208020)
@@ -2357,7 +2357,10 @@
                                 screenSizeInPixels.scale(corePage()->deviceScaleFactor());
                                 FloatSize scaledSize = largestRectWithAspectRatioInsideRect(image->size().width() / image->size().height(), FloatRect(0, 0, screenSizeInPixels.width(), screenSizeInPixels.height())).size();
                                 FloatSize bitmapSize = scaledSize.width() < image->size().width() ? scaledSize : image->size();
-                                if (RefPtr<ShareableBitmap> sharedBitmap = ShareableBitmap::createShareable(IntSize(bitmapSize), ShareableBitmap::SupportsAlpha)) {
+                                // FIXME: Only select ExtendedColor on images known to need wide gamut
+                                ShareableBitmap::Flags flags = ShareableBitmap::SupportsAlpha;
+                                flags |= screenSupportsExtendedColor() ? ShareableBitmap::SupportsExtendedColor : 0;
+                                if (RefPtr<ShareableBitmap> sharedBitmap = ShareableBitmap::createShareable(IntSize(bitmapSize), flags)) {
                                     auto graphicsContext = sharedBitmap->createGraphicsContext();
                                     graphicsContext->drawImage(*image, FloatRect(0, 0, bitmapSize.width(), bitmapSize.height()));
                                     info.image = sharedBitmap;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to