Bug 17269: Deobfuscate CanvasRenderingContext2D.cpp
authoroliver@apple.com <oliver@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 13 Feb 2008 02:11:55 +0000 (02:11 +0000)
committeroliver@apple.com <oliver@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 13 Feb 2008 02:11:55 +0000 (02:11 +0000)
Remove ifdef's from canvas paint code

Reviewed by Eric S.

By making GraphicsContext aware of the crossplatform ImageBuffer
type we can migrate the ifdef-ified paint code in HTMLCanvasElement
into platform implementations of GraphicsContext.

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

WebCore/ChangeLog
WebCore/html/HTMLCanvasElement.cpp
WebCore/platform/graphics/GraphicsContext.h
WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp
WebCore/platform/graphics/cg/GraphicsContextCG.cpp
WebCore/platform/graphics/qt/GraphicsContextQt.cpp

index f1b78b3..7500745 100644 (file)
@@ -1,3 +1,24 @@
+2008-02-12  Oliver Hunt  <oliver@apple.com>
+
+        Reviewed by Eric S.
+
+        Bug 17269: Deobfuscate CanvasRenderingContext2D.cpp
+        Remove ifdef's from canvas paint code
+
+        By making GraphicsContext aware of the crossplatform ImageBuffer
+        type we can migrate the ifdef-ified paint code in HTMLCanvasElement
+        into platform implementations of GraphicsContext.
+
+        * html/HTMLCanvasElement.cpp:
+        (WebCore::HTMLCanvasElement::paint):
+        * platform/graphics/GraphicsContext.h:
+        * platform/graphics/cairo/GraphicsContextCairo.cpp:
+        (WebCore::GraphicsContext::paintBuffer):
+        * platform/graphics/cg/GraphicsContextCG.cpp:
+        (WebCore::GraphicsContext::paintBuffer):
+        * platform/graphics/qt/GraphicsContextQt.cpp:
+        (WebCore::GraphicsContext::paintBuffer):
+
 2008-02-12  Brady Eidson  <beidson@apple.com>
 
         Reviewed by Darin Adler
index f9f3c60..37fb021 100644 (file)
@@ -184,40 +184,9 @@ void HTMLCanvasElement::paint(GraphicsContext* p, const IntRect& r)
 {
     if (p->paintingDisabled())
         return;
-#if PLATFORM(CG)
-    if (CGImageRef image = createPlatformImage()) {
-        CGContextDrawImage(p->platformContext(), p->roundToDevicePixels(r), image);
-        CGImageRelease(image);
-    }
-#elif PLATFORM(QT)
-    QPixmap pixmap = createPlatformImage();
-    if (!pixmap.isNull()) {
-        QPainter* painter = p->platformContext();
-        QPen currentPen = painter->pen();
-        qreal currentOpacity = painter->opacity();
-        QBrush currentBrush = painter->brush();
-        QBrush currentBackground = painter->background();
-        if (painter->isActive())
-            painter->end();
-        static_cast<QPainter*>(p->platformContext())->drawPixmap(r, pixmap);
-        painter->begin(&pixmap);
-        painter->setPen(currentPen);
-        painter->setBrush(currentBrush);
-        painter->setOpacity(currentOpacity);
-        painter->setBackground(currentBackground);
-    }
-#elif PLATFORM(CAIRO)
-    if (cairo_surface_t* image = createPlatformImage()) {
-        cairo_t* cr = p->platformContext();
-        cairo_save(cr);
-        cairo_translate(cr, r.x(), r.y());
-        cairo_set_source_surface(cr, image, 0, 0);
-        cairo_surface_destroy(image);
-        cairo_rectangle(cr, 0, 0, r.width(), r.height());
-        cairo_fill(cr);
-        cairo_restore(cr);
-    }
-#endif
+    
+    if (m_data)
+        p->paintBuffer(m_data.get(), r);
 }
 
 void HTMLCanvasElement::createDrawingContext() const
index e4a98e4..075caf4 100644 (file)
@@ -83,6 +83,7 @@ namespace WebCore {
     class Font;
     class GraphicsContextPrivate;
     class GraphicsContextPlatformPrivate;
+    class ImageBuffer;
     class KURL;
     class Path;
     class TextRun;
@@ -149,6 +150,7 @@ namespace WebCore {
         void drawTiledImage(Image*, const IntRect& destRect, const IntRect& srcRect, 
                             Image::TileRule hRule = Image::StretchTile, Image::TileRule vRule = Image::StretchTile,
                             CompositeOperator = CompositeSourceOver);
+        void paintBuffer(ImageBuffer*, const IntRect&);
 #if PLATFORM(CG)
         void setUseLowQualityImageInterpolation(bool = true);
         bool useLowQualityImageInterpolation() const;
index 08e8616..5fd8817 100644 (file)
@@ -889,6 +889,23 @@ void GraphicsContext::setUseAntialiasing(bool enable)
     cairo_set_antialias(m_data->cr, enable ? CAIRO_ANTIALIAS_DEFAULT : CAIRO_ANTIALIAS_NONE);
 }
 
+void GraphicsContext::paintBuffer(ImageBuffer* buffer, const IntRect& r)
+{
+    cairo_surface_t* image = buffer->surface();
+    if (!image)
+        return;
+    cairo_surface_flush(image);
+    cairo_surface_reference(image);
+    cairo_t* cr = platformContext();
+    cairo_save(cr);
+    cairo_translate(cr, r.x(), r.y());
+    cairo_set_source_surface(cr, image, 0, 0);
+    cairo_surface_destroy(image);
+    cairo_rectangle(cr, 0, 0, r.width(), r.height());
+    cairo_fill(cr);
+    cairo_restore(cr);
+}
+
 } // namespace WebCore
 
 #endif // PLATFORM(CAIRO)
index c490dcb..1d5a4d5 100644 (file)
 #include "AffineTransform.h"
 #include "FloatConversion.h"
 #include "GraphicsContextPlatformPrivateCG.h"
+#include "ImageBuffer.h"
 #include "KURL.h"
 #include "Path.h"
+#include <CoreGraphics/CGBitmapContext.h>
 #include <CoreGraphics/CGPDFContext.h>
 #include <wtf/MathExtras.h>
 
@@ -924,6 +926,14 @@ void GraphicsContext::setCompositeOperation(CompositeOperator mode)
     CGContextSetBlendMode(platformContext(), target);
 }
 #endif
+
+void GraphicsContext::paintBuffer(ImageBuffer* buffer, const IntRect& r)
+{
+    if (CGImageRef image = CGBitmapContextCreateImage(buffer->context()->platformContext())) {
+        CGContextDrawImage(platformContext(), roundToDevicePixels(r), image);
+        CGImageRelease(image);
+    }
+}
     
 }
 
index cf097c8..e168d16 100644 (file)
@@ -45,6 +45,7 @@
 #include <QPolygonF>
 #include <QPainterPath>
 #include <QPaintDevice>
+#include <QPixmap>
 #include <QDebug>
 
 #ifndef M_PI
@@ -905,6 +906,26 @@ void GraphicsContext::setUseAntialiasing(bool enable)
     m_data->p()->setRenderHint(QPainter::Antialiasing, enable);
 }
 
+void GraphicsContext::paintBuffer(ImageBuffer* buffer, const IntRect& r)
+{
+    QPixmap pixmap = *buffer->pixmap();
+    if (!pixmap.isNull()) {
+        QPainter* painter = platformContext();
+        QPen currentPen = painter->pen();
+        qreal currentOpacity = painter->opacity();
+        QBrush currentBrush = painter->brush();
+        QBrush currentBackground = painter->background();
+        if (painter->isActive())
+            painter->end();
+        static_cast<QPainter*>(painter)->drawPixmap(r, pixmap);
+        painter->begin(&pixmap);
+        painter->setPen(currentPen);
+        painter->setBrush(currentBrush);
+        painter->setOpacity(currentOpacity);
+        painter->setBackground(currentBackground);
+    }
+}
+
 }
 
 // vim: ts=4 sw=4 et