[Cocoa] Support wide gamut for Drag Image UI
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 11 Nov 2016 18:54:21 +0000 (18:54 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 11 Nov 2016 18:54:21 +0000 (18:54 +0000)
https://bugs.webkit.org/show_bug.cgi?id=164490

Patch by Megan Gardner <megan_gardner@apple.com> on 2016-11-11
Reviewed by Tim Horton.

Source/WebCore:

Fixed an error in the support define for wide gamut on Mac.

The testing infrastructure to test this does not exist, and will be landing in another patch.

* platform/graphics/cg/GraphicsContextCG.cpp:
(WebCore::extendedSRGBColorSpaceRef):

Source/WebKit2:

Fixed an error in the gating for the new wide gamut support in ShareableBitmap.
We should always respect the flags straight out, and not make decisions later, it can lead to mismatched data and data storage.
Added support for wide gamut in createCGImage.

* Shared/cg/ShareableBitmapCG.cpp:
(WebKit::bitmapInfo):
(WebKit::colorSpace):
(WebKit::ShareableBitmap::createGraphicsContext):
(WebKit::ShareableBitmap::createCGImage):
* WebProcess/WebCoreSupport/mac/WebDragClientMac.mm:
(WebKit::convertImageToBitmap):
(WebKit::WebDragClient::startDrag):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208596 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp
Source/WebKit2/ChangeLog
Source/WebKit2/Shared/cg/ShareableBitmapCG.cpp
Source/WebKit2/WebProcess/WebCoreSupport/mac/WebDragClientMac.mm

index 2a8677a..d878322 100644 (file)
@@ -1,3 +1,17 @@
+2016-11-11  Megan Gardner  <megan_gardner@apple.com>
+
+        [Cocoa] Support wide gamut for Drag Image UI
+        https://bugs.webkit.org/show_bug.cgi?id=164490
+
+        Reviewed by Tim Horton.
+
+        Fixed an error in the support define for wide gamut on Mac.
+
+        The testing infrastructure to test this does not exist, and will be landing in another patch.
+
+        * platform/graphics/cg/GraphicsContextCG.cpp:
+        (WebCore::extendedSRGBColorSpaceRef):
+
 2016-11-11  Beth Dakin  <bdakin@apple.com>
 
         Get touch bar code building for open source builds
index 1b11ed3..c2d227b 100644 (file)
@@ -97,7 +97,7 @@ CGColorSpaceRef sRGBColorSpaceRef()
 CGColorSpaceRef extendedSRGBColorSpaceRef()
 {
     static CGColorSpaceRef extendedSRGBSpace;
-#if (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 100000) || (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED > 101200)
+#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.
index 5a7a2f5..f6be75e 100644 (file)
@@ -1,3 +1,23 @@
+2016-11-11  Megan Gardner  <megan_gardner@apple.com>
+
+        [Cocoa] Support wide gamut for Drag Image UI
+        https://bugs.webkit.org/show_bug.cgi?id=164490
+
+        Reviewed by Tim Horton.
+
+        Fixed an error in the gating for the new wide gamut support in ShareableBitmap.
+        We should always respect the flags straight out, and not make decisions later, it can lead to mismatched data and data storage.
+        Added support for wide gamut in createCGImage.
+
+        * Shared/cg/ShareableBitmapCG.cpp:
+        (WebKit::bitmapInfo):
+        (WebKit::colorSpace):
+        (WebKit::ShareableBitmap::createGraphicsContext):
+        (WebKit::ShareableBitmap::createCGImage):
+        * WebProcess/WebCoreSupport/mac/WebDragClientMac.mm:
+        (WebKit::convertImageToBitmap):
+        (WebKit::WebDragClient::startDrag):
+
 2016-11-11  Beth Dakin  <bdakin@apple.com>
 
         Get touch bar code building for open source builds
index 74624b2..9fe0fab 100644 (file)
@@ -39,7 +39,7 @@ namespace WebKit {
 static CGBitmapInfo bitmapInfo(ShareableBitmap::Flags flags)
 {
     CGBitmapInfo info = 0;
-    if ((flags & ShareableBitmap::SupportsExtendedColor) && screenSupportsExtendedColor()) {
+    if (flags & ShareableBitmap::SupportsExtendedColor) {
         info |= kCGBitmapFloatComponents | kCGBitmapByteOrder16Host;
         
         if (flags & ShareableBitmap::SupportsAlpha)
@@ -58,18 +58,19 @@ static CGBitmapInfo bitmapInfo(ShareableBitmap::Flags flags)
     
     return info;
 }
+    
+static CGColorSpaceRef colorSpace(ShareableBitmap::Flags flags)
+{
+    if (flags & ShareableBitmap::SupportsExtendedColor)
+        return extendedSRGBColorSpaceRef();
+    return sRGBColorSpaceRef();
+}
 
 std::unique_ptr<GraphicsContext> ShareableBitmap::createGraphicsContext()
 {
     ref(); // Balanced by deref in releaseBitmapContextData.
     
-    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));
+    RetainPtr<CGContextRef> bitmapContext = adoptCF(CGBitmapContextCreateWithData(data(), m_size.width(), m_size.height(), m_bytesPerPixel * 8 / 4, m_size.width() * m_bytesPerPixel, colorSpace(m_flags), bitmapInfo(m_flags), releaseBitmapContextData, this));
     
     ASSERT(bitmapContext.get());
 
@@ -107,8 +108,7 @@ RetainPtr<CGImageRef> ShareableBitmap::makeCGImage()
 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));
+    RetainPtr<CGImageRef> image = adoptCF(CGImageCreate(m_size.width(), m_size.height(), m_bytesPerPixel * 8 / 4, m_bytesPerPixel * 8, m_size.width() * m_bytesPerPixel, colorSpace(m_flags), bitmapInfo(m_flags), dataProvider, 0, false, kCGRenderingIntentDefault));
     return image;
 }
 
index af2695f..88ad5dc 100644 (file)
@@ -39,6 +39,7 @@
 #import <WebCore/FrameView.h>
 #import <WebCore/GraphicsContext.h>
 #import <WebCore/LegacyWebArchive.h>
+#import <WebCore/MainFrame.h>
 #import <WebCore/WebCoreNSURLExtras.h>
 #import <WebCore/Page.h>
 #import <WebCore/RenderImage.h>
@@ -52,9 +53,12 @@ using namespace WebKit;
 
 namespace WebKit {
 
-static PassRefPtr<ShareableBitmap> convertImageToBitmap(NSImage *image, const IntSize& size)
+static PassRefPtr<ShareableBitmap> convertImageToBitmap(NSImage *image, const IntSize& size, Frame& frame)
 {
-    auto bitmap = ShareableBitmap::createShareable(size, ShareableBitmap::SupportsAlpha);
+    ShareableBitmap::Flags flags = ShareableBitmap::SupportsAlpha;
+    if (screenSupportsExtendedColor(frame.mainFrame().view()))
+        flags |= ShareableBitmap::SupportsExtendedColor;
+    auto bitmap = ShareableBitmap::createShareable(size, flags);
     if (!bitmap)
         return nullptr;
 
@@ -73,7 +77,7 @@ static PassRefPtr<ShareableBitmap> convertImageToBitmap(NSImage *image, const In
 void WebDragClient::startDrag(RetainPtr<NSImage> image, const IntPoint& point, const IntPoint&, DataTransfer&, Frame& frame, bool linkDrag)
 {
     IntSize bitmapSize([image size]);
-    RefPtr<ShareableBitmap> bitmap = convertImageToBitmap(image.get(), bitmapSize);
+    RefPtr<ShareableBitmap> bitmap = convertImageToBitmap(image.get(), bitmapSize, frame);
     ShareableBitmap::Handle handle;
     if (!bitmap || !bitmap->createHandle(handle))
         return;