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

Side by Side Diff: tools/bench_record.cpp

Issue 238273012: Staged removal of SkPicture-derived classes (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: have SkPicture only friend SkPictureRecorder once Created 6 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 | « tools/PictureRenderingFlags.cpp ('k') | tools/filtermain.cpp » ('j') | 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 2014 Google Inc. 2 * Copyright 2014 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 "SkCommandLineFlags.h" 8 #include "SkCommandLineFlags.h"
9 #include "SkForceLinking.h" 9 #include "SkForceLinking.h"
10 #include "SkGraphics.h" 10 #include "SkGraphics.h"
(...skipping 16 matching lines...) Expand all
27 27
28 DEFINE_string2(skps, r, "skps", "Directory containing SKPs to read and re-record ."); 28 DEFINE_string2(skps, r, "skps", "Directory containing SKPs to read and re-record .");
29 DEFINE_int32(loops, 900, "Number of times to re-record each SKP."); 29 DEFINE_int32(loops, 900, "Number of times to re-record each SKP.");
30 DEFINE_int32(flags, SkPicture::kUsePathBoundsForClip_RecordingFlag, "RecordingFl ags to use."); 30 DEFINE_int32(flags, SkPicture::kUsePathBoundsForClip_RecordingFlag, "RecordingFl ags to use.");
31 DEFINE_bool(endRecording, true, "If false, don't time SkPicture::endRecording()" ); 31 DEFINE_bool(endRecording, true, "If false, don't time SkPicture::endRecording()" );
32 DEFINE_int32(nullSize, 1000, "Pretend dimension of null source picture."); 32 DEFINE_int32(nullSize, 1000, "Pretend dimension of null source picture.");
33 DEFINE_int32(tileGridSize, 512, "Set the tile grid size. Has no effect if bbh is not set to tilegrid."); 33 DEFINE_int32(tileGridSize, 512, "Set the tile grid size. Has no effect if bbh is not set to tilegrid.");
34 DEFINE_string(bbh, "", "Turn on the bbh and select the type, one of rtree, tileg rid, quadtree"); 34 DEFINE_string(bbh, "", "Turn on the bbh and select the type, one of rtree, tileg rid, quadtree");
35 DEFINE_bool(skr, false, "Record SKR instead of SKP."); 35 DEFINE_bool(skr, false, "Record SKR instead of SKP.");
36 36
37 typedef SkPictureFactory* (*PictureFactory)(); 37 static SkBBHFactory* parse_FLAGS_bbh() {
38
39 static SkPictureFactory* vanilla_factory() {
40 return NULL;
41 }
42
43 static SkPictureFactory* rtree_factory() {
44 return SkNEW(SkRTreePictureFactory);
45 }
46
47 static SkPictureFactory* tilegrid_factory() {
48 SkTileGridPicture::TileGridInfo info;
49 info.fTileInterval.set(FLAGS_tileGridSize, FLAGS_tileGridSize);
50 info.fMargin.setEmpty();
51 info.fOffset.setZero();
52 return SkNEW_ARGS(SkTileGridPictureFactory, (info));
53 }
54
55 static SkPictureFactory* quadtree_factory() {
56 return SkNEW(SkQuadTreePictureFactory);
57 }
58
59 static PictureFactory parse_FLAGS_bbh() {
60 if (FLAGS_bbh.isEmpty()) { 38 if (FLAGS_bbh.isEmpty()) {
61 return &vanilla_factory;
62 }
63 if (FLAGS_bbh.count() != 1) {
64 SkDebugf("Multiple bbh arguments supplied.\n");
65 return NULL; 39 return NULL;
66 } 40 }
41
67 if (FLAGS_bbh.contains("rtree")) { 42 if (FLAGS_bbh.contains("rtree")) {
68 return rtree_factory; 43 return SkNEW(SkRTreeFactory);
69 } 44 }
70 if (FLAGS_bbh.contains("tilegrid")) { 45 if (FLAGS_bbh.contains("tilegrid")) {
71 return tilegrid_factory; 46 SkTileGridFactory::TileGridInfo info;
47 info.fTileInterval.set(FLAGS_tileGridSize, FLAGS_tileGridSize);
48 info.fMargin.setEmpty();
49 info.fOffset.setZero();
50 return SkNEW_ARGS(SkTileGridFactory, (info));
72 } 51 }
73 if (FLAGS_bbh.contains("quadtree")) { 52 if (FLAGS_bbh.contains("quadtree")) {
74 return quadtree_factory; 53 return SkNEW(SkQuadTreeFactory);
75 } 54 }
76 SkDebugf("Invalid bbh type %s, must be one of rtree, tilegrid, quadtree.\n", FLAGS_bbh[0]); 55 SkDebugf("Invalid bbh type %s, must be one of rtree, tilegrid, quadtree.\n", FLAGS_bbh[0]);
77 return NULL; 56 return NULL;
78 } 57 }
79 58
80 static void bench_record(SkPicture* src, const char* name, PictureFactory pictur eFactory) { 59 static void bench_record(SkPicture* src, const char* name, SkBBHFactory* bbhFact ory) {
81 const SkMSec start = SkTime::GetMSecs(); 60 const SkMSec start = SkTime::GetMSecs();
82 const int width = src ? src->width() : FLAGS_nullSize; 61 const int width = src ? src->width() : FLAGS_nullSize;
83 const int height = src ? src->height() : FLAGS_nullSize; 62 const int height = src ? src->height() : FLAGS_nullSize;
84 63
85 for (int i = 0; i < FLAGS_loops; i++) { 64 for (int i = 0; i < FLAGS_loops; i++) {
86 if (FLAGS_skr) { 65 if (FLAGS_skr) {
87 using EXPERIMENTAL::SkRecording; 66 using EXPERIMENTAL::SkRecording;
88 SkRecording* recording = SkRecording::Create(width, height); 67 SkRecording* recording = SkRecording::Create(width, height);
89 if (NULL != src) { 68 if (NULL != src) {
90 src->draw(recording->canvas()); 69 src->draw(recording->canvas());
91 } 70 }
92 SkDELETE(SkRecording::Delete(recording)); // delete the SkPlayback* . 71 SkDELETE(SkRecording::Delete(recording)); // delete the SkPlayback* .
93 } else { 72 } else {
94 int recordingFlags = FLAGS_flags; 73 SkPictureRecorder recorder;
95 SkAutoTUnref<SkPictureFactory> factory(pictureFactory()); 74 SkCanvas* canvas = recorder.beginRecording(width, height, bbhFactory , FLAGS_flags);
96 SkPictureRecorder recorder(factory);
97 SkCanvas* canvas = recorder.beginRecording(width, height, recordingF lags);
98 if (NULL != src) { 75 if (NULL != src) {
99 src->draw(canvas); 76 src->draw(canvas);
100 } 77 }
101 if (FLAGS_endRecording) { 78 if (FLAGS_endRecording) {
102 SkAutoTUnref<SkPicture> dst(recorder.endRecording()); 79 SkAutoTUnref<SkPicture> dst(recorder.endRecording());
103 } 80 }
104 } 81 }
105 } 82 }
106 83
107 const SkMSec elapsed = SkTime::GetMSecs() - start; 84 const SkMSec elapsed = SkTime::GetMSecs() - start;
108 const double msPerLoop = elapsed / (double)FLAGS_loops; 85 const double msPerLoop = elapsed / (double)FLAGS_loops;
109 printf("%.2g\t%s\n", msPerLoop, name); 86 printf("%.2g\t%s\n", msPerLoop, name);
110 } 87 }
111 88
112 int tool_main(int argc, char** argv); 89 int tool_main(int argc, char** argv);
113 int tool_main(int argc, char** argv) { 90 int tool_main(int argc, char** argv) {
114 SkCommandLineFlags::Parse(argc, argv); 91 SkCommandLineFlags::Parse(argc, argv);
115 SkAutoGraphics autoGraphics; 92 SkAutoGraphics autoGraphics;
116 93
117 PictureFactory pictureFactory = parse_FLAGS_bbh(); 94 if (FLAGS_bbh.count() > 1) {
118 if (pictureFactory == NULL) { 95 SkDebugf("Multiple bbh arguments supplied.\n");
119 return 1; 96 return 1;
120 } 97 }
121 bench_record(NULL, "NULL", pictureFactory); 98
99 SkAutoTDelete<SkBBHFactory> bbhFactory(parse_FLAGS_bbh());
100 bench_record(NULL, "NULL", bbhFactory.get());
122 if (FLAGS_skps.isEmpty()) { 101 if (FLAGS_skps.isEmpty()) {
123 return 0; 102 return 0;
124 } 103 }
125 104
126 SkOSFile::Iter it(FLAGS_skps[0], ".skp"); 105 SkOSFile::Iter it(FLAGS_skps[0], ".skp");
127 SkString filename; 106 SkString filename;
128 bool failed = false; 107 bool failed = false;
129 while (it.next(&filename)) { 108 while (it.next(&filename)) {
130 const SkString path = SkOSPath::SkPathJoin(FLAGS_skps[0], filename.c_str ()); 109 const SkString path = SkOSPath::SkPathJoin(FLAGS_skps[0], filename.c_str ());
131 110
132 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path.c_str())); 111 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path.c_str()));
133 if (!stream) { 112 if (!stream) {
134 SkDebugf("Could not read %s.\n", path.c_str()); 113 SkDebugf("Could not read %s.\n", path.c_str());
135 failed = true; 114 failed = true;
136 continue; 115 continue;
137 } 116 }
138 SkAutoTUnref<SkPicture> src( 117 SkAutoTUnref<SkPicture> src(
139 SkPicture::CreateFromStream(stream, sk_tools::LazyDecodeBitmap)); 118 SkPicture::CreateFromStream(stream, sk_tools::LazyDecodeBitmap));
140 if (!src) { 119 if (!src) {
141 SkDebugf("Could not read %s as an SkPicture.\n", path.c_str()); 120 SkDebugf("Could not read %s as an SkPicture.\n", path.c_str());
142 failed = true; 121 failed = true;
143 continue; 122 continue;
144 } 123 }
145 bench_record(src, filename.c_str(), pictureFactory); 124 bench_record(src, filename.c_str(), bbhFactory.get());
146 } 125 }
147 return failed ? 1 : 0; 126 return failed ? 1 : 0;
148 } 127 }
149 128
150 #if !defined SK_BUILD_FOR_IOS 129 #if !defined SK_BUILD_FOR_IOS
151 int main(int argc, char * const argv[]) { 130 int main(int argc, char * const argv[]) {
152 return tool_main(argc, (char**) argv); 131 return tool_main(argc, (char**) argv);
153 } 132 }
154 #endif 133 #endif
OLDNEW
« no previous file with comments | « tools/PictureRenderingFlags.cpp ('k') | tools/filtermain.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698