From f80d5dae7a3780e4e665e74a880e9e1816204b45 Mon Sep 17 00:00:00 2001 From: "aestes@apple.com" Date: Mon, 30 Jan 2012 20:01:39 +0000 Subject: [PATCH] [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. 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 | 17 +++++++++++++++++ Source/WebCore/css/CSSPrimitiveValueMappings.h | 3 +++ Source/WebCore/platform/graphics/GraphicsTypes.h | 6 ++---- .../WebCore/platform/graphics/cg/GraphicsContextCG.cpp | 3 +++ Source/WebKit/win/ChangeLog | 16 ++++++++++++++++ Source/WebKit/win/WebView.cpp | 3 +++ Source/WebKit/win/WebView.h | 2 ++ 7 files changed, 46 insertions(+), 4 deletions(-) diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog index fabb415..f163e53 100644 --- a/Source/WebCore/ChangeLog +++ b/Source/WebCore/ChangeLog @@ -1,3 +1,20 @@ +2012-01-26 Andy Estes + + [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 Limit the shadow offset CG hack to just SL and Lion diff --git a/Source/WebCore/css/CSSPrimitiveValueMappings.h b/Source/WebCore/css/CSSPrimitiveValueMappings.h index 6096d93..c591646 100644 --- a/Source/WebCore/css/CSSPrimitiveValueMappings.h +++ b/Source/WebCore/css/CSSPrimitiveValueMappings.h @@ -285,6 +285,9 @@ template<> inline CSSPrimitiveValue::CSSPrimitiveValue(CompositeOperator e) case CompositePlusLighter: m_value.ident = CSSValuePlusLighter; break; + case CompositeDifference: + ASSERT_NOT_REACHED(); + break; } } diff --git a/Source/WebCore/platform/graphics/GraphicsTypes.h b/Source/WebCore/platform/graphics/GraphicsTypes.h index 1a07f00..e6596d9 100644 --- a/Source/WebCore/platform/graphics/GraphicsTypes.h +++ b/Source/WebCore/platform/graphics/GraphicsTypes.h @@ -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 { diff --git a/Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp b/Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp index 7e9f53b..4b6192f 100644 --- a/Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp +++ b/Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp @@ -1603,6 +1603,9 @@ void GraphicsContext::setPlatformCompositeOperation(CompositeOperator mode) case CompositePlusLighter: target = kCGBlendModePlusLighter; break; + case CompositeDifference: + target = kCGBlendModeDifference; + break; } CGContextSetBlendMode(platformContext(), target); } diff --git a/Source/WebKit/win/ChangeLog b/Source/WebKit/win/ChangeLog index cc55727..2d4b1f5 100644 --- a/Source/WebKit/win/ChangeLog +++ b/Source/WebKit/win/ChangeLog @@ -1,3 +1,19 @@ +2012-01-26 Andy Estes + + [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 Show layer borders for scrollbar layers diff --git a/Source/WebKit/win/WebView.cpp b/Source/WebKit/win/WebView.cpp index 926dc82..57acc13 100644 --- a/Source/WebKit/win/WebView.cpp +++ b/Source/WebKit/win/WebView.cpp @@ -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(); } diff --git a/Source/WebKit/win/WebView.h b/Source/WebKit/win/WebView.h index 38230cb..7d2a6e2 100644 --- a/Source/WebKit/win/WebView.h +++ b/Source/WebKit/win/WebView.h @@ -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); -- 2.7.4