Title: [99257] trunk/Source/WebCore
Revision
99257
Author
[email protected]
Date
2011-11-03 18:55:30 -0700 (Thu, 03 Nov 2011)

Log Message

Optimize canvas fills / drawImage when covering entire canvas
https://bugs.webkit.org/show_bug.cgi?id=70789

Patch by Ben Wells <[email protected]> on 2011-11-03
Reviewed by Stephen White.

If we're filling a rect or drawing an image, and it covers the entire canvas, we don't
need to worry about clearing outside the area updated by the operation if we're in
a composite mode that requires this (such as source-in, copy, etc.). In this case we
can take the simple path through the code and save a clear (for copy) or a temporary
image buffer (for the other modes).

No new tests - optimization, behaviour is unchanged and covered by existing tests.

* html/canvas/CanvasRenderingContext2D.cpp:
(WebCore::CanvasRenderingContext2D::fillRect):
(WebCore::CanvasRenderingContext2D::drawImage):
(WebCore::CanvasRenderingContext2D::rectContainsCanvas):
* html/canvas/CanvasRenderingContext2D.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (99256 => 99257)


--- trunk/Source/WebCore/ChangeLog	2011-11-04 01:32:18 UTC (rev 99256)
+++ trunk/Source/WebCore/ChangeLog	2011-11-04 01:55:30 UTC (rev 99257)
@@ -1,3 +1,24 @@
+2011-11-03  Ben Wells  <[email protected]>
+
+        Optimize canvas fills / drawImage when covering entire canvas
+        https://bugs.webkit.org/show_bug.cgi?id=70789
+
+        Reviewed by Stephen White.
+
+        If we're filling a rect or drawing an image, and it covers the entire canvas, we don't
+        need to worry about clearing outside the area updated by the operation if we're in
+        a composite mode that requires this (such as source-in, copy, etc.). In this case we
+        can take the simple path through the code and save a clear (for copy) or a temporary
+        image buffer (for the other modes).
+
+        No new tests - optimization, behaviour is unchanged and covered by existing tests.
+
+        * html/canvas/CanvasRenderingContext2D.cpp:
+        (WebCore::CanvasRenderingContext2D::fillRect):
+        (WebCore::CanvasRenderingContext2D::drawImage):
+        (WebCore::CanvasRenderingContext2D::rectContainsCanvas):
+        * html/canvas/CanvasRenderingContext2D.h:
+
 2011-11-03  Mark Hahnenberg  <[email protected]>
 
         De-virtualize JSObject::getPropertyNames

Modified: trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp (99256 => 99257)


--- trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp	2011-11-04 01:32:18 UTC (rev 99256)
+++ trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp	2011-11-04 01:55:30 UTC (rev 99257)
@@ -44,6 +44,7 @@
 #include "Console.h"
 #include "ExceptionCode.h"
 #include "FloatConversion.h"
+#include "FloatQuad.h"
 #include "FontCache.h"
 #include "GraphicsContext.h"
 #include "HTMLCanvasElement.h"
@@ -1055,7 +1056,10 @@
 
     FloatRect rect(x, y, width, height);
 
-    if (isFullCanvasCompositeMode(state().m_globalComposite)) {
+    if (rectContainsCanvas(rect)) {
+        c->fillRect(rect);
+        didDrawEntireCanvas();
+    } else if (isFullCanvasCompositeMode(state().m_globalComposite)) {
         fullCanvasCompositedFill(rect);
         didDrawEntireCanvas();
     } else if (state().m_globalComposite == CompositeCopy) {
@@ -1336,7 +1340,10 @@
 
     checkOrigin(image);
 
-    if (isFullCanvasCompositeMode(op)) {
+    if (rectContainsCanvas(normalizedDstRect)) {
+        c->drawImage(cachedImage->imageForRenderer(image->renderer()), ColorSpaceDeviceRGB, normalizedDstRect, normalizedSrcRect, op);
+        didDrawEntireCanvas();
+    } else if (isFullCanvasCompositeMode(op)) {
         fullCanvasCompositedDrawImage(cachedImage->imageForRenderer(image->renderer()), ColorSpaceDeviceRGB, normalizedDstRect, normalizedSrcRect, op);
         didDrawEntireCanvas();
     } else if (op == CompositeCopy) {
@@ -1549,6 +1556,13 @@
     return transformAreaToDevice(path);
 }
 
+bool CanvasRenderingContext2D::rectContainsCanvas(const FloatRect& rect) const
+{
+    FloatQuad quad(rect);
+    FloatQuad canvasQuad(FloatRect(0, 0, canvas()->width(), canvas()->height()));
+    return state().m_transform.mapQuad(quad).containsQuad(canvasQuad);
+}
+
 template<class T> IntRect CanvasRenderingContext2D::calculateCompositingBufferRect(const T& area, IntSize* croppedOffset)
 {
     IntRect canvasRect(0, 0, canvas()->width(), canvas()->height());

Modified: trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.h (99256 => 99257)


--- trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.h	2011-11-04 01:32:18 UTC (rev 99256)
+++ trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.h	2011-11-04 01:55:30 UTC (rev 99257)
@@ -300,6 +300,7 @@
     void clearCanvas();
     Path transformAreaToDevice(const Path&) const;
     Path transformAreaToDevice(const FloatRect&) const;
+    bool rectContainsCanvas(const FloatRect&) const;
 
     template<class T> IntRect calculateCompositingBufferRect(const T&, IntSize*);
     PassOwnPtr<ImageBuffer> createCompositingBuffer(const IntRect&);
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to