Title: [153941] trunk
Revision
153941
Author
[email protected]
Date
2013-08-12 05:18:00 -0700 (Mon, 12 Aug 2013)

Log Message

[Qt] Add Support for canvas blend modes
https://bugs.webkit.org/show_bug.cgi?id=100072

Reviewed by Jocelyn Turcotte.

Source/WebCore:

Implement basic support for the blend-modes supported by QPainter.

Covered by existing tests.

* platform/graphics/qt/GraphicsContextQt.cpp:
(WebCore::toQtCompositionMode):
(WebCore::GraphicsContext::setPlatformCompositeOperation):
* platform/graphics/qt/ImageBufferQt.cpp:
(WebCore::ImageBuffer::draw):
* platform/graphics/qt/ImageQt.cpp:
(WebCore::BitmapImage::draw):
* platform/graphics/qt/StillImageQt.cpp:
(WebCore::StillImage::draw):

LayoutTests:

Unskip tests that now passes.

* platform/qt/TestExpectations:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (153940 => 153941)


--- trunk/LayoutTests/ChangeLog	2013-08-12 11:40:24 UTC (rev 153940)
+++ trunk/LayoutTests/ChangeLog	2013-08-12 12:18:00 UTC (rev 153941)
@@ -1,3 +1,14 @@
+2013-08-12  Allan Sandfeld Jensen  <[email protected]>
+
+        [Qt] Add Support for canvas blend modes
+        https://bugs.webkit.org/show_bug.cgi?id=100072
+
+        Reviewed by Jocelyn Turcotte.
+
+        Unskip tests that now passes.
+
+        * platform/qt/TestExpectations:
+
 2013-08-12  Zoltan Arvai  <[email protected]>
 
         [Qt] Unreviewed gardening. Rebaselining after r153903.

Modified: trunk/LayoutTests/platform/qt/TestExpectations (153940 => 153941)


--- trunk/LayoutTests/platform/qt/TestExpectations	2013-08-12 11:40:24 UTC (rev 153940)
+++ trunk/LayoutTests/platform/qt/TestExpectations	2013-08-12 12:18:00 UTC (rev 153941)
@@ -481,48 +481,13 @@
 # CSS.regionOversetChanged is not implemented.
 webkit.org/b/117833 inspector/styles/protocol-css-regions-commands.html [ Skip ]
 
-# CSS -webkit-background-blend-mode not supported yet.
-css3/compositing/background-blend-mode-background-attachement-fixed.html
-css3/compositing/background-blend-mode-background-clip-content-box.html
-css3/compositing/background-blend-mode-background-clip-padding-box.html
-css3/compositing/background-blend-mode-background-origin-border-box.html
-css3/compositing/background-blend-mode-background-position-percentage.html
-css3/compositing/background-blend-mode-background-repeat-no-repeat.html
-css3/compositing/background-blend-mode-background-size-contain.html
-css3/compositing/background-blend-mode-background-size-cover.html
+# The following tests fail because blend-modes are only partially supported.
 css3/compositing/background-blend-mode-default-value.html
 css3/compositing/background-blend-mode-different-image-formats.html
 css3/compositing/background-blend-mode-image-color.html
 css3/compositing/background-blend-mode-image-image.html
 css3/compositing/background-blend-mode-single-layer-no-blending.html
 
-# The following test fail because canvas blending is not yet supported.
-# https://bugs.webkit.org/show_bug.cgi?id=100072
-fast/canvas/canvas-blend-image.html
-fast/canvas/canvas-blend-solid.html
-fast/canvas/canvas-blending-clipping.html
-fast/canvas/canvas-blending-color-over-color.html
-fast/canvas/canvas-blending-color-over-gradient.html
-fast/canvas/canvas-blending-color-over-image.html
-fast/canvas/canvas-blending-color-over-pattern.html
-fast/canvas/canvas-blending-fill-style.html
-fast/canvas/canvas-blending-global-alpha.html
-fast/canvas/canvas-blending-gradient-over-color.html
-fast/canvas/canvas-blending-gradient-over-gradient.html
-fast/canvas/canvas-blending-gradient-over-image.html
-fast/canvas/canvas-blending-gradient-over-pattern.html
-fast/canvas/canvas-blending-image-over-color.html
-fast/canvas/canvas-blending-image-over-gradient.html
-fast/canvas/canvas-blending-image-over-image.html
-fast/canvas/canvas-blending-image-over-pattern.html
-fast/canvas/canvas-blending-pattern-over-color.html
-fast/canvas/canvas-blending-pattern-over-gradient.html
-fast/canvas/canvas-blending-pattern-over-image.html
-fast/canvas/canvas-blending-pattern-over-pattern.html
-fast/canvas/canvas-blending-shadow.html
-fast/canvas/canvas-blending-text.html
-fast/canvas/canvas-blending-transforms.html
-
 # =========================================================================== #
 #       Drag and Drop Support in DRT.                                         #
 # =========================================================================== #
@@ -1296,6 +1261,10 @@
 # Missing testRunner.setHandlesAuthenticationChallenges() implementation
 http/tests/misc/authentication-redirect-4/authentication-sent-to-redirect-same-origin-url.html
 
+# TestRunner::overridePreference() does not support the 'WebKitCanvasUsesAcceleratedDrawing' preference
+fast/canvas/canvas-blend-image.html
+fast/canvas/canvas-blend-solid.html
+
 # ============================================================================= #
 # Failing SVG tests
 # ============================================================================= #

Modified: trunk/Source/WebCore/ChangeLog (153940 => 153941)


--- trunk/Source/WebCore/ChangeLog	2013-08-12 11:40:24 UTC (rev 153940)
+++ trunk/Source/WebCore/ChangeLog	2013-08-12 12:18:00 UTC (rev 153941)
@@ -1,3 +1,24 @@
+2013-08-12  Allan Sandfeld Jensen  <[email protected]>
+
+        [Qt] Add Support for canvas blend modes
+        https://bugs.webkit.org/show_bug.cgi?id=100072
+
+        Reviewed by Jocelyn Turcotte.
+
+        Implement basic support for the blend-modes supported by QPainter.
+
+        Covered by existing tests.
+
+        * platform/graphics/qt/GraphicsContextQt.cpp:
+        (WebCore::toQtCompositionMode):
+        (WebCore::GraphicsContext::setPlatformCompositeOperation):
+        * platform/graphics/qt/ImageBufferQt.cpp:
+        (WebCore::ImageBuffer::draw):
+        * platform/graphics/qt/ImageQt.cpp:
+        (WebCore::BitmapImage::draw):
+        * platform/graphics/qt/StillImageQt.cpp:
+        (WebCore::StillImage::draw):
+
 2013-08-12  Gabor Abraham  <[email protected]>
 
         Buildfix for !ENABLE(SVG). Fix warning by adding guard after r153901:

Modified: trunk/Source/WebCore/platform/graphics/qt/GraphicsContextQt.cpp (153940 => 153941)


--- trunk/Source/WebCore/platform/graphics/qt/GraphicsContextQt.cpp	2013-08-12 11:40:24 UTC (rev 153940)
+++ trunk/Source/WebCore/platform/graphics/qt/GraphicsContextQt.cpp	2013-08-12 12:18:00 UTC (rev 153941)
@@ -121,6 +121,46 @@
     return QPainter::CompositionMode_SourceOver;
 }
 
+static inline QPainter::CompositionMode toQtCompositionMode(BlendMode op)
+{
+    switch (op) {
+    case BlendModeNormal:
+        return QPainter::CompositionMode_SourceOver;
+    case BlendModeMultiply:
+        return QPainter::CompositionMode_Multiply;
+    case BlendModeScreen:
+        return QPainter::CompositionMode_Screen;
+    case BlendModeOverlay:
+        return QPainter::CompositionMode_Overlay;
+    case BlendModeDarken:
+        return QPainter::CompositionMode_Darken;
+    case BlendModeLighten:
+        return QPainter::CompositionMode_Lighten;
+    case BlendModeColorDodge:
+        return QPainter::CompositionMode_ColorDodge;
+    case BlendModeColorBurn:
+        return QPainter::CompositionMode_ColorBurn;
+    case BlendModeHardLight:
+        return QPainter::CompositionMode_HardLight;
+    case BlendModeSoftLight:
+        return QPainter::CompositionMode_SoftLight;
+    case BlendModeDifference:
+        return QPainter::CompositionMode_Difference;
+    case BlendModeExclusion:
+        return QPainter::CompositionMode_Exclusion;
+    case BlendModeHue:
+    case BlendModeSaturation:
+    case BlendModeColor:
+    case BlendModeLuminosity:
+        // Not supported.
+        break;
+    default:
+        ASSERT_NOT_REACHED();
+    }
+
+    return QPainter::CompositionMode_SourceOver;
+}
+
 static inline Qt::PenCapStyle toQtLineCap(LineCap lc)
 {
     switch (lc) {
@@ -1343,12 +1383,17 @@
     p->setOpacity(opacity);
 }
 
-void GraphicsContext::setPlatformCompositeOperation(CompositeOperator op, BlendMode)
+void GraphicsContext::setPlatformCompositeOperation(CompositeOperator op, BlendMode blendMode)
 {
     if (paintingDisabled())
         return;
 
-    m_data->p()->setCompositionMode(toQtCompositionMode(op));
+    ASSERT(op == WebCore::CompositeSourceOver || blendMode == WebCore::BlendModeNormal);
+
+    if (op == WebCore::CompositeSourceOver)
+        m_data->p()->setCompositionMode(toQtCompositionMode(blendMode));
+    else
+        m_data->p()->setCompositionMode(toQtCompositionMode(op));
 }
 
 void GraphicsContext::clip(const Path& path, WindRule windRule)

Modified: trunk/Source/WebCore/platform/graphics/qt/ImageBufferQt.cpp (153940 => 153941)


--- trunk/Source/WebCore/platform/graphics/qt/ImageBufferQt.cpp	2013-08-12 11:40:24 UTC (rev 153940)
+++ trunk/Source/WebCore/platform/graphics/qt/ImageBufferQt.cpp	2013-08-12 12:18:00 UTC (rev 153941)
@@ -131,14 +131,14 @@
 }
 
 void ImageBuffer::draw(GraphicsContext* destContext, ColorSpace styleColorSpace, const FloatRect& destRect, const FloatRect& srcRect,
-    CompositeOperator op, BlendMode, bool useLowQualityScale)
+    CompositeOperator op, BlendMode blendMode, bool useLowQualityScale)
 {
     if (destContext == context()) {
         // We're drawing into our own buffer.  In order for this to work, we need to copy the source buffer first.
         RefPtr<Image> copy = copyImage(CopyBackingStore);
-        destContext->drawImage(copy.get(), ColorSpaceDeviceRGB, destRect, srcRect, op, DoNotRespectImageOrientation, useLowQualityScale);
+        destContext->drawImage(copy.get(), ColorSpaceDeviceRGB, destRect, srcRect, op, blendMode, DoNotRespectImageOrientation, useLowQualityScale);
     } else
-        destContext->drawImage(m_data.m_image.get(), styleColorSpace, destRect, srcRect, op, DoNotRespectImageOrientation, useLowQualityScale);
+        destContext->drawImage(m_data.m_image.get(), styleColorSpace, destRect, srcRect, op, blendMode, DoNotRespectImageOrientation, useLowQualityScale);
 }
 
 void ImageBuffer::drawPattern(GraphicsContext* destContext, const FloatRect& srcRect, const AffineTransform& patternTransform,

Modified: trunk/Source/WebCore/platform/graphics/qt/ImageQt.cpp (153940 => 153941)


--- trunk/Source/WebCore/platform/graphics/qt/ImageQt.cpp	2013-08-12 11:40:24 UTC (rev 153940)
+++ trunk/Source/WebCore/platform/graphics/qt/ImageQt.cpp	2013-08-12 12:18:00 UTC (rev 153941)
@@ -276,7 +276,7 @@
 
 // Drawing Routines
 void BitmapImage::draw(GraphicsContext* ctxt, const FloatRect& dst,
-    const FloatRect& src, ColorSpace styleColorSpace, CompositeOperator op, BlendMode)
+    const FloatRect& src, ColorSpace styleColorSpace, CompositeOperator op, BlendMode blendMode)
 {
     QRectF normalizedDst = dst.normalized();
     QRectF normalizedSrc = src.normalized();
@@ -303,7 +303,8 @@
     image = prescaleImageIfRequired(ctxt->platformContext(), image, &prescaledBuffer, normalizedDst, &normalizedSrc);
 
     CompositeOperator previousOperator = ctxt->compositeOperation();
-    ctxt->setCompositeOperation(!image->hasAlpha() && op == CompositeSourceOver ? CompositeCopy : op);
+    BlendMode previousBlendMode = ctxt->blendModeOperation();
+    ctxt->setCompositeOperation(!image->hasAlpha() && op == CompositeSourceOver && blendMode == BlendModeNormal ? CompositeCopy : op, blendMode);
 
     if (ctxt->hasShadow()) {
         ShadowBlur shadow(ctxt->state());
@@ -317,7 +318,7 @@
 
     ctxt->platformContext()->drawPixmap(normalizedDst, *image, normalizedSrc);
 
-    ctxt->setCompositeOperation(previousOperator);
+    ctxt->setCompositeOperation(previousOperator, previousBlendMode);
 
     if (imageObserver())
         imageObserver()->didDraw(this);

Modified: trunk/Source/WebCore/platform/graphics/qt/StillImageQt.cpp (153940 => 153941)


--- trunk/Source/WebCore/platform/graphics/qt/StillImageQt.cpp	2013-08-12 11:40:24 UTC (rev 153940)
+++ trunk/Source/WebCore/platform/graphics/qt/StillImageQt.cpp	2013-08-12 12:18:00 UTC (rev 153941)
@@ -68,7 +68,7 @@
 }
 
 void StillImage::draw(GraphicsContext* ctxt, const FloatRect& dst,
-    const FloatRect& src, ColorSpace, CompositeOperator op, BlendMode)
+    const FloatRect& src, ColorSpace, CompositeOperator op, BlendMode blendMode)
 {
     if (m_pixmap->isNull())
         return;
@@ -77,7 +77,8 @@
     FloatRect normalizedDst = dst.normalized();
 
     CompositeOperator previousOperator = ctxt->compositeOperation();
-    ctxt->setCompositeOperation(op);
+    BlendMode previousBlendMode = ctxt->blendModeOperation();
+    ctxt->setCompositeOperation(op, blendMode);
 
     if (ctxt->hasShadow()) {
         ShadowBlur shadow(ctxt->state());
@@ -90,7 +91,7 @@
     }
 
     ctxt->platformContext()->drawPixmap(normalizedDst, *m_pixmap, normalizedSrc);
-    ctxt->setCompositeOperation(previousOperator);
+    ctxt->setCompositeOperation(previousOperator, previousBlendMode);
 }
 
 }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to