Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: tools/filtermain.cpp

Issue 13405003: Add before and after command count to filter tool (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Remove debugging cruft Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2012 Google Inc. 2 * Copyright 2012 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkDebugCanvas.h" 8 #include "SkDebugCanvas.h"
9 #include "SkDevice.h" 9 #include "SkDevice.h"
10 #include "SkGraphics.h" 10 #include "SkGraphics.h"
11 #include "SkImageDecoder.h" 11 #include "SkImageDecoder.h"
12 #include "SkImageEncoder.h" 12 #include "SkImageEncoder.h"
13 #include "SkOSFile.h" 13 #include "SkOSFile.h"
14 #include "SkPicture.h" 14 #include "SkPicture.h"
15 #include "SkPicturePlayback.h" 15 #include "SkPicturePlayback.h"
16 #include "SkPictureRecord.h" 16 #include "SkPictureRecord.h"
17 #include "SkStream.h" 17 #include "SkStream.h"
18 #include "picture_utils.h" 18 #include "picture_utils.h"
19 #include "path_utils.h" 19 #include "path_utils.h"
20 20
21 static void usage() { 21 static void usage() {
22 SkDebugf("Usage: filter -i inFile [-o outFile] [--input-dir path] [--output- dir path]\n"); 22 SkDebugf("Usage: filter -i inFile [-o outFile] [--input-dir path] [--output- dir path]\n");
23 SkDebugf(" [-h|--help]\n\n"); 23 SkDebugf(" [-h|--help]\n\n");
24 SkDebugf(" -i inFile : file to file.\n"); 24 SkDebugf(" -i inFile : file to filter.\n");
25 SkDebugf(" -o outFile : result of filtering.\n"); 25 SkDebugf(" -o outFile : result of filtering.\n");
26 SkDebugf(" --input-dir : process all files in dir with .skp extension.\n" ); 26 SkDebugf(" --input-dir : process all files in dir with .skp extension.\n" );
27 SkDebugf(" --output-dir : results of filtering the input dir.\n"); 27 SkDebugf(" --output-dir : results of filtering the input dir.\n");
28 SkDebugf(" -h|--help : Show this help message.\n"); 28 SkDebugf(" -h|--help : Show this help message.\n");
29 } 29 }
30 30
31 // Is the supplied paint simply a color? 31 // Is the supplied paint simply a color?
32 static bool is_simple(const SkPaint& p) { 32 static bool is_simple(const SkPaint& p) {
33 return NULL == p.getPathEffect() && 33 return NULL == p.getPathEffect() &&
34 NULL == p.getShader() && 34 NULL == p.getShader() &&
(...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after
647 inPicture->draw(&debugCanvas); 647 inPicture->draw(&debugCanvas);
648 648
649 // delete the initial save and restore since replaying the commands will 649 // delete the initial save and restore since replaying the commands will
650 // re-add them 650 // re-add them
651 if (debugCanvas.getSize() > 1) { 651 if (debugCanvas.getSize() > 1) {
652 debugCanvas.deleteDrawCommandAt(0); 652 debugCanvas.deleteDrawCommandAt(0);
653 debugCanvas.deleteDrawCommandAt(debugCanvas.getSize()-1); 653 debugCanvas.deleteDrawCommandAt(debugCanvas.getSize()-1);
654 } 654 }
655 655
656 bool changed = true; 656 bool changed = true;
657 int numBefore = debugCanvas.getSize();
657 658
658 while (changed) { 659 while (changed) {
659 changed = false; 660 changed = false;
660 for (int i = 0; i < debugCanvas.getSize(); ++i) { 661 for (int i = 0; i < debugCanvas.getSize(); ++i) {
661 for (size_t opt = 0; opt < SK_ARRAY_COUNT(gOptTable); ++opt) { 662 for (size_t opt = 0; opt < SK_ARRAY_COUNT(gOptTable); ++opt) {
662 if ((*gOptTable[opt].fCheck)(&debugCanvas, i)) { 663 if ((*gOptTable[opt].fCheck)(&debugCanvas, i)) {
663 (*gOptTable[opt].fApply)(&debugCanvas, i); 664 (*gOptTable[opt].fApply)(&debugCanvas, i);
664 665
665 ++gOptTable[opt].fNumTimesApplied; 666 ++gOptTable[opt].fNumTimesApplied;
666 ++localCount[opt]; 667 ++localCount[opt];
667 668
668 if (debugCanvas.getSize() == i) { 669 if (debugCanvas.getSize() == i) {
669 // the optimization removed all the remaining operations 670 // the optimization removed all the remaining operations
670 break; 671 break;
671 } 672 }
672 673
673 opt = 0; // try all the opts all over again 674 opt = 0; // try all the opts all over again
674 changed = true; 675 changed = true;
675 } 676 }
676 } 677 }
677 } 678 }
678 } 679 }
679 680
681 int numAfter = debugCanvas.getSize();
682
680 if (!outFile.isEmpty()) { 683 if (!outFile.isEmpty()) {
681 SkPicture outPicture; 684 SkPicture outPicture;
682 685
683 SkCanvas* canvas = outPicture.beginRecording(inPicture->width(), inPictu re->height()); 686 SkCanvas* canvas = outPicture.beginRecording(inPicture->width(), inPictu re->height());
684 debugCanvas.draw(canvas); 687 debugCanvas.draw(canvas);
685 outPicture.endRecording(); 688 outPicture.endRecording();
686 689
687 SkFILEWStream outStream(outFile.c_str()); 690 SkFILEWStream outStream(outFile.c_str());
688 691
689 outPicture.serialize(&outStream); 692 outPicture.serialize(&outStream);
690 } 693 }
691 694
692 bool someOptFired = false; 695 bool someOptFired = false;
693 for (size_t opt = 0; opt < SK_ARRAY_COUNT(gOptTable); ++opt) { 696 for (size_t opt = 0; opt < SK_ARRAY_COUNT(gOptTable); ++opt) {
694 if (0 != localCount[opt]) { 697 if (0 != localCount[opt]) {
695 SkDebugf("%d: %d ", opt, localCount[opt]); 698 SkDebugf("%d: %d ", opt, localCount[opt]);
696 someOptFired = true; 699 someOptFired = true;
697 } 700 }
698 } 701 }
699 702
700 if (!someOptFired) { 703 if (!someOptFired) {
701 SkDebugf("No opts fired\n"); 704 SkDebugf("No opts fired\n");
702 } else { 705 } else {
703 SkDebugf("\n"); 706 SkDebugf("\t before: %d after: %d delta: %d\n",
707 numBefore, numAfter, numBefore-numAfter);
704 } 708 }
705 709
706 return 0; 710 return 0;
707 } 711 }
708 712
709 // This function is not marked as 'static' so it can be referenced externally 713 // This function is not marked as 'static' so it can be referenced externally
710 // in the iOS build. 714 // in the iOS build.
711 int tool_main(int argc, char** argv); // suppress a warning on mac 715 int tool_main(int argc, char** argv); // suppress a warning on mac
712 716
713 int tool_main(int argc, char** argv) { 717 int tool_main(int argc, char** argv) {
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
795 799
796 SkGraphics::Term(); 800 SkGraphics::Term();
797 return 0; 801 return 0;
798 } 802 }
799 803
800 #if !defined SK_BUILD_FOR_IOS 804 #if !defined SK_BUILD_FOR_IOS
801 int main(int argc, char * const argv[]) { 805 int main(int argc, char * const argv[]) {
802 return tool_main(argc, (char**) argv); 806 return tool_main(argc, (char**) argv);
803 } 807 }
804 #endif 808 #endif
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698