save/restore the canvas around every bench draw call
authorcommit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>
Mon, 14 Oct 2013 15:28:01 +0000 (15:28 +0000)
committercommit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>
Mon, 14 Oct 2013 15:28:01 +0000 (15:28 +0000)
BUG=

Committed: http://code.google.com/p/skia/source/detail?r=11728

R=djsollen@google.com, reed@google.com

Author: mtklein@google.com

Review URL: https://codereview.chromium.org/26848013

git-svn-id: http://skia.googlecode.com/svn/trunk@11755 2bbb7eff-a529-9590-31e7-b0007b416f81

bench/benchmain.cpp
include/core/SkCanvas.h

index 6b52508163b79950f21e37f53b1a00f9b7a5002f..944b114c51e698b1078f1409a2de482b685170bf 100644 (file)
@@ -598,9 +598,9 @@ int tool_main(int argc, char** argv) {
                 // as we can flush and/or swap buffers to keep the GPU from
                 // queuing up too much work.
                 for (int loopCount = loopsPerIter; loopCount > 0; ) {
-                    if (NULL != canvas) {
-                        canvas->save();
-                    }
+                    // Save and restore around each call to draw() to guarantee a pristine canvas.
+                    SkAutoCanvasRestore saveRestore(canvas, true/*also save*/);
+
                     if (frameIntervalComputed && loopCount > loopsPerFrame) {
                         bench->setLoops(loopsPerFrame);
                         loopCount -= loopsPerFrame;
@@ -628,9 +628,6 @@ int tool_main(int argc, char** argv) {
                         glContext->swapBuffers();
                     }
 #endif
-                    if (NULL != canvas) {
-                        canvas->restore();
-                    }
                 }
 
 
index cfc252fccfc191c64804b4edfd172ba2e9b066e1..dc3953ed4b1df71634992a1bec5bd1d7a85450e3 100644 (file)
@@ -1145,11 +1145,12 @@ private:
 */
 class SkAutoCanvasRestore : SkNoncopyable {
 public:
-    SkAutoCanvasRestore(SkCanvas* canvas, bool doSave) : fCanvas(canvas) {
-        SkASSERT(canvas);
-        fSaveCount = canvas->getSaveCount();
-        if (doSave) {
-            canvas->save();
+    SkAutoCanvasRestore(SkCanvas* canvas, bool doSave) : fCanvas(canvas), fSaveCount(0) {
+        if (fCanvas) {
+            fSaveCount = canvas->getSaveCount();
+            if (doSave) {
+                canvas->save();
+            }
         }
     }
     ~SkAutoCanvasRestore() {