[Windows] Optionally invert colors when drawing to a WebView's backing store.
authoraestes@apple.com <aestes@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 30 Jan 2012 20:01:39 +0000 (20:01 +0000)
committeraestes@apple.com <aestes@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 30 Jan 2012 20:01:39 +0000 (20:01 +0000)
https://bugs.webkit.org/show_bug.cgi?id=77168

Reviewed by Sam Weinig.

Source/WebCore:

* css/CSSPrimitiveValueMappings.h: Assert that CompositeDifference is
not converted to a CSS value. Exposing a new compositing operation to
CSS is outside the scope of this patch.
(WebCore::CSSPrimitiveValue::CSSPrimitiveValue):
* platform/graphics/GraphicsTypes.h: Add CompositeDifference as a
CompositeOperator. Also, remove an outdated comment.
* platform/graphics/cg/GraphicsContextCG.cpp:
(WebCore::GraphicsContext::setPlatformCompositeOperation): Map
CompositeDifference to kCGBlendModeDifference.

Source/WebKit/win:

* WebView.cpp:
(WebView::WebView): Initialize m_shouldInvertColors to false.
(WebView::paintIntoBackingStore): If m_shouldInvertColors is true, draw
an opaque white quad using the CompositeDifference blend mode. This
blend operation instructs CoreGraphics to take the difference between
the source pixel (white) and the background pixel, resulting in an
inverted pixel.
* WebView.h: Define m_shouldInvertColors.

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

Source/WebCore/ChangeLog
Source/WebCore/css/CSSPrimitiveValueMappings.h
Source/WebCore/platform/graphics/GraphicsTypes.h
Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp
Source/WebKit/win/ChangeLog
Source/WebKit/win/WebView.cpp
Source/WebKit/win/WebView.h

index fabb415..f163e53 100644 (file)
@@ -1,3 +1,20 @@
+2012-01-26  Andy Estes  <aestes@apple.com>
+
+        [Windows] Optionally invert colors when drawing to a WebView's backing store.
+        https://bugs.webkit.org/show_bug.cgi?id=77168
+
+        Reviewed by Sam Weinig.
+
+        * css/CSSPrimitiveValueMappings.h: Assert that CompositeDifference is
+        not converted to a CSS value. Exposing a new compositing operation to
+        CSS is outside the scope of this patch.
+        (WebCore::CSSPrimitiveValue::CSSPrimitiveValue):
+        * platform/graphics/GraphicsTypes.h: Add CompositeDifference as a
+        CompositeOperator. Also, remove an outdated comment.
+        * platform/graphics/cg/GraphicsContextCG.cpp:
+        (WebCore::GraphicsContext::setPlatformCompositeOperation): Map
+        CompositeDifference to kCGBlendModeDifference.
+
 2012-01-28  Matthew Delaney  <mdelaney@apple.com>
 
         Limit the shadow offset CG hack to just SL and Lion
index 6096d93..c591646 100644 (file)
@@ -285,6 +285,9 @@ template<> inline CSSPrimitiveValue::CSSPrimitiveValue(CompositeOperator e)
         case CompositePlusLighter:
             m_value.ident = CSSValuePlusLighter;
             break;
+        case CompositeDifference:
+            ASSERT_NOT_REACHED();
+            break;
     }
 }
 
index 1a07f00..e6596d9 100644 (file)
@@ -30,9 +30,6 @@
 
 namespace WebCore {
 
-    // Note: These constants exactly match the NSCompositeOperator constants of
-    // AppKit on Mac OS X Tiger. If these ever change, we'll need to change the
-    // Mac OS X Tiger platform code to map one to the other.
     enum CompositeOperator {
         CompositeClear,
         CompositeCopy,
@@ -46,7 +43,8 @@ namespace WebCore {
         CompositeDestinationAtop,
         CompositeXOR,
         CompositePlusDarker,
-        CompositePlusLighter
+        CompositePlusLighter,
+        CompositeDifference
     };
 
     enum GradientSpreadMethod {
index 7e9f53b..4b6192f 100644 (file)
@@ -1603,6 +1603,9 @@ void GraphicsContext::setPlatformCompositeOperation(CompositeOperator mode)
     case CompositePlusLighter:
         target = kCGBlendModePlusLighter;
         break;
+    case CompositeDifference:
+        target = kCGBlendModeDifference;
+        break;
     }
     CGContextSetBlendMode(platformContext(), target);
 }
index cc55727..2d4b1f5 100644 (file)
@@ -1,3 +1,19 @@
+2012-01-26  Andy Estes  <aestes@apple.com>
+
+        [Windows] Optionally invert colors when drawing to a WebView's backing store.
+        https://bugs.webkit.org/show_bug.cgi?id=77168
+
+        Reviewed by Sam Weinig.
+
+        * WebView.cpp:
+        (WebView::WebView): Initialize m_shouldInvertColors to false.
+        (WebView::paintIntoBackingStore): If m_shouldInvertColors is true, draw
+        an opaque white quad using the CompositeDifference blend mode. This
+        blend operation instructs CoreGraphics to take the difference between
+        the source pixel (white) and the background pixel, resulting in an
+        inverted pixel.
+        * WebView.h: Define m_shouldInvertColors.
+
 2012-01-23  Simon Fraser  <simon.fraser@apple.com>
 
         Show layer borders for scrollbar layers
index 926dc82..57acc13 100644 (file)
@@ -332,6 +332,7 @@ bool WebView::s_allowSiteSpecificHacks = false;
 
 WebView::WebView()
     : m_refCount(0)
+    , m_shouldInvertColors(false)
 #if !ASSERT_DISABLED
     , m_deletionHasBegun(false)
 #endif
@@ -1154,6 +1155,8 @@ void WebView::paintIntoBackingStore(FrameView* frameView, HDC bitmapDC, const In
     if (frameView && frameView->frame() && frameView->frame()->contentRenderer()) {
         gc.clip(dirtyRect);
         frameView->paint(&gc, dirtyRect);
+        if (m_shouldInvertColors)
+            gc.fillRect(dirtyRect, Color::white, ColorSpaceDeviceRGB, CompositeDifference);
     }
     gc.restore();
 }
index 38230cb..7d2a6e2 100644 (file)
@@ -1001,6 +1001,8 @@ private:
     virtual void flushPendingGraphicsLayerChanges();
 #endif
 
+    bool m_shouldInvertColors;
+
 protected:
     static bool registerWebViewWindowClass();
     static LRESULT CALLBACK WebViewWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);