First step of Bug 3781: Animation via canvas could be faster
authoroliver@apple.com <oliver@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 30 Dec 2008 12:19:23 +0000 (12:19 +0000)
committeroliver@apple.com <oliver@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 30 Dec 2008 12:19:23 +0000 (12:19 +0000)
Reviewed by Antti Koivisto.

Amortise the cost of calling repaint by coalescing repaint rects
while the canvas is drawn to.  In a later step we'll stop calling
repaint() directly, and instead have all dirty canvases repaint
at the end of JS execution.

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

WebCore/ChangeLog
WebCore/html/HTMLCanvasElement.cpp
WebCore/html/HTMLCanvasElement.h

index 9c0e5b4..a58269b 100644 (file)
@@ -1,3 +1,19 @@
+2008-12-30  Oliver Hunt  <oliver@apple.com>
+
+        Reviewed by Antti Koivisto.
+
+        First step of Bug 3781: Animation via canvas could be faster
+
+        Amortise the cost of calling repaint by coalescing repaint rects
+        while the canvas is drawn to.  In a later step we'll stop calling
+        repaint() directly, and instead have all dirty canvases repaint
+        at the end of JS execution.
+
+        * html/HTMLCanvasElement.cpp:
+        (WebCore::HTMLCanvasElement::willDraw):
+        (WebCore::HTMLCanvasElement::paint):
+        * html/HTMLCanvasElement.h:
+
 2008-12-30  Cameron Zwarich  <cwzwarich@uwaterloo.ca>
 
         Reviewed by Antti Koivisto.
index e34880e..933745f 100644 (file)
@@ -161,10 +161,14 @@ void HTMLCanvasElement::willDraw(const FloatRect& rect)
         float widthScale = static_cast<float>(ro->width()) / static_cast<float>(m_size.width());
         float heightScale = static_cast<float>(ro->height()) / static_cast<float>(m_size.height());
         FloatRect r(rect.x() * widthScale, rect.y() * heightScale, rect.width() * widthScale, rect.height() * heightScale);
-        ro->repaintRectangle(enclosingIntRect(r));
 #else
-        ro->repaint();
+        FloatRect r(0, 0, ro->width(), ro->height());  
 #endif
+        if (m_dirtyRect.contains(r))
+            return;
+
+        m_dirtyRect.unite(r);
+        ro->repaintRectangle(enclosingIntRect(m_dirtyRect));
     }
     
     if (m_observer)
@@ -207,6 +211,9 @@ void HTMLCanvasElement::reset()
 
 void HTMLCanvasElement::paint(GraphicsContext* context, const IntRect& r)
 {
+    // Clear the dirty rect
+    m_dirtyRect = FloatRect();
+
     if (context->paintingDisabled())
         return;
     
index 2f1a6e9..3c71936 100644 (file)
@@ -28,6 +28,7 @@
 #define HTMLCanvasElement_h
 
 #include "AffineTransform.h"
+#include "FloatRect.h"
 #include "HTMLElement.h"
 #include "IntSize.h"
 
@@ -42,7 +43,6 @@ class GraphicsContext;
 class HTMLCanvasElement;
 class ImageBuffer;
 class IntPoint;
-class InttRect;
 class IntSize;
 
 class CanvasObserver {
@@ -119,6 +119,7 @@ private:
 
     bool m_originClean;
     bool m_ignoreReset;
+    FloatRect m_dirtyRect;
 
     // m_createdImageBuffer means we tried to malloc the buffer.  We didn't necessarily get it.
     mutable bool m_createdImageBuffer;