2011-01-21  Andreas Kling  <kling@webkit.org>

        Reviewed by Kenneth Rohde Christiansen.

        [Qt] Always set composition mode through GraphicsContext
        https://bugs.webkit.org/show_bug.cgi?id=52940

        GraphicsContext tracks the current composition mode so we should
        never call through to the QPainter directly.

        * platform/graphics/GraphicsContext.h:
        * platform/graphics/qt/GraphicsContextQt.cpp:
        (WebCore::toQtCompositionMode): Changed this method to a static inline
        since it's only used by GraphicsContextQt.cpp now.

        * platform/graphics/qt/ImageQt.cpp:
        (WebCore::Image::drawPattern):
        (WebCore::BitmapImage::draw):


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@76415 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog
index ab35d57..3cded15 100644
--- a/Source/WebCore/ChangeLog
+++ b/Source/WebCore/ChangeLog
@@ -1,3 +1,22 @@
+2011-01-21  Andreas Kling  <kling@webkit.org>
+
+        Reviewed by Kenneth Rohde Christiansen.
+
+        [Qt] Always set composition mode through GraphicsContext
+        https://bugs.webkit.org/show_bug.cgi?id=52940
+
+        GraphicsContext tracks the current composition mode so we should
+        never call through to the QPainter directly.
+
+        * platform/graphics/GraphicsContext.h:
+        * platform/graphics/qt/GraphicsContextQt.cpp:
+        (WebCore::toQtCompositionMode): Changed this method to a static inline
+        since it's only used by GraphicsContextQt.cpp now.
+
+        * platform/graphics/qt/ImageQt.cpp:
+        (WebCore::Image::drawPattern):
+        (WebCore::BitmapImage::draw):
+
 2011-01-21  Dan Bernstein  <mitz@apple.com>
 
         Reviewed by Adele Peterson.
diff --git a/Source/WebCore/platform/graphics/GraphicsContext.h b/Source/WebCore/platform/graphics/GraphicsContext.h
index 35824dc4..6d6c043 100644
--- a/Source/WebCore/platform/graphics/GraphicsContext.h
+++ b/Source/WebCore/platform/graphics/GraphicsContext.h
@@ -465,7 +465,6 @@
         bool inTransparencyLayer() const;
         void pushTransparencyLayerInternal(const QRect &rect, qreal opacity, QPixmap& alphaMask);
         void takeOwnershipOfPlatformContext();
-        static QPainter::CompositionMode toQtCompositionMode(CompositeOperator op);
 #endif
 
 #if PLATFORM(QT) || PLATFORM(CAIRO)
diff --git a/Source/WebCore/platform/graphics/qt/GraphicsContextQt.cpp b/Source/WebCore/platform/graphics/qt/GraphicsContextQt.cpp
index 4dabe0905..87cc87c 100644
--- a/Source/WebCore/platform/graphics/qt/GraphicsContextQt.cpp
+++ b/Source/WebCore/platform/graphics/qt/GraphicsContextQt.cpp
@@ -69,7 +69,7 @@
 
 namespace WebCore {
 
-QPainter::CompositionMode GraphicsContext::toQtCompositionMode(CompositeOperator op)
+static inline QPainter::CompositionMode toQtCompositionMode(CompositeOperator op)
 {
     switch (op) {
     case CompositeClear:
diff --git a/Source/WebCore/platform/graphics/qt/ImageQt.cpp b/Source/WebCore/platform/graphics/qt/ImageQt.cpp
index 58f82ef..0c8ce9ed 100644
--- a/Source/WebCore/platform/graphics/qt/ImageQt.cpp
+++ b/Source/WebCore/platform/graphics/qt/ImageQt.cpp
@@ -120,11 +120,9 @@
 
     CompositeOperator previousOperator = ctxt->compositeOperation();
 
-    ctxt->setCompositeOperation(op);
-    QPainter* p = ctxt->platformContext();
-    if (!pixmap.hasAlpha() && p->compositionMode() == QPainter::CompositionMode_SourceOver)
-        p->setCompositionMode(QPainter::CompositionMode_Source);
+    ctxt->setCompositeOperation(!pixmap.hasAlpha() && op == CompositeSourceOver ? CompositeCopy : op);
 
+    QPainter* p = ctxt->platformContext();
     QTransform transform(patternTransform);
 
     // If this would draw more than one scaled tile, we scale the pixmap first and then use the result to draw.
@@ -223,15 +221,8 @@
         return;
     }
 
-    QPainter* painter(ctxt->platformContext());
-
-    QPainter::CompositionMode compositionMode = GraphicsContext::toQtCompositionMode(op);
-
-    if (!image->hasAlpha() && painter->compositionMode() == QPainter::CompositionMode_SourceOver)
-        compositionMode = QPainter::CompositionMode_Source;
-
-    QPainter::CompositionMode lastCompositionMode = painter->compositionMode();
-    painter->setCompositionMode(compositionMode);
+    CompositeOperator previousOperator = ctxt->compositeOperation();
+    ctxt->setCompositeOperation(!image->hasAlpha() && op == CompositeSourceOver ? CompositeCopy : op);
 
     ContextShadow* shadow = ctxt->contextShadow();
     if (shadow->m_type != ContextShadow::NoShadow) {
@@ -243,11 +234,9 @@
         }
     }
 
-    // Test using example site at
-    // http://www.meyerweb.com/eric/css/edge/complexspiral/demo.html
-    painter->drawPixmap(normalizedDst, *image, normalizedSrc);
+    ctxt->platformContext()->drawPixmap(normalizedDst, *image, normalizedSrc);
 
-    painter->setCompositionMode(lastCompositionMode);
+    ctxt->setCompositeOperation(previousOperator);
 
     if (imageObserver())
         imageObserver()->didDraw(this);