Add looping over optimizations to filter tool
authorrobertphillips@google.com <robertphillips@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Mon, 1 Apr 2013 19:10:21 +0000 (19:10 +0000)
committerrobertphillips@google.com <robertphillips@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Mon, 1 Apr 2013 19:10:21 +0000 (19:10 +0000)
https://codereview.chromium.org/13261018/

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

tools/filtermain.cpp

index 24887c5..00cf6f0 100644 (file)
@@ -536,12 +536,26 @@ static int filter_picture(const SkString& inFile, const SkString& outFile) {
         debugCanvas.deleteDrawCommandAt(debugCanvas.getSize()-1);
     }
 
-    for (int i = 0; i < debugCanvas.getSize(); ++i) {
-        for (size_t opt = 0; opt < SK_ARRAY_COUNT(gOptTable); ++opt) {
-            if ((*gOptTable[opt].fCheck)(&debugCanvas, i)) {
-                (*gOptTable[opt].fApply)(&debugCanvas, i);
-                ++gOptTable[opt].fNumTimesApplied;
-                ++localCount[opt];
+    bool changed = true;
+
+    while (changed) {
+        changed = false;
+        for (int i = 0; i < debugCanvas.getSize(); ++i) {
+            for (size_t opt = 0; opt < SK_ARRAY_COUNT(gOptTable); ++opt) {
+                if ((*gOptTable[opt].fCheck)(&debugCanvas, i)) {
+                    (*gOptTable[opt].fApply)(&debugCanvas, i);
+
+                    ++gOptTable[opt].fNumTimesApplied;
+                    ++localCount[opt];
+
+                    if (debugCanvas.getSize() == i) {
+                        // the optimization removed all the remaining operations
+                        break;
+                    }
+
+                    opt = 0;          // try all the opts all over again
+                    changed = true;
+                }
             }
         }
     }