OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright 2015 Google Inc. | |
3 * | |
4 * Use of this source code is governed by a BSD-style license that can be | |
5 * found in the LICENSE file. | |
6 * | |
7 */ | |
8 | |
9 #include <VisualBench/VisualBenchmarkStream.h> | |
10 #include "GMBench.h" | |
11 #include "SkOSFile.h" | |
12 #include "SkPictureRecorder.h" | |
13 #include "SkStream.h" | |
14 #include "VisualSKPBench.h" | |
15 | |
16 DEFINE_string2(match, m, NULL, | |
17 "[~][^]substring[$] [...] of GM name to run.\n" | |
bsalomon
2015/06/29 21:04:06
update?
| |
18 "Multiple matches may be separated by spaces.\n" | |
19 "~ causes a matching GM to always be skipped\n" | |
20 "^ requires the start of the GM to match\n" | |
21 "$ requires the end of the GM to match\n" | |
22 "^ and $ requires an exact match\n" | |
23 "If a GM does not match any list entry,\n" | |
24 "it is skipped unless some list entry starts with ~"); | |
25 DEFINE_string(skps, "skps", "Directory to read skps from."); | |
26 | |
27 VisualBenchmarkStream::VisualBenchmarkStream() | |
28 : fBenches(BenchRegistry::Head()) | |
29 , fGMs(skiagm::GMRegistry::Head()) | |
30 , fSourceType(NULL) | |
31 , fBenchType(NULL) | |
32 , fCurrentSKP(0) { | |
33 for (int i = 0; i < FLAGS_skps.count(); i++) { | |
34 if (SkStrEndsWith(FLAGS_skps[i], ".skp")) { | |
35 fSKPs.push_back() = FLAGS_skps[i]; | |
36 } else { | |
37 SkOSFile::Iter it(FLAGS_skps[i], ".skp"); | |
38 SkString path; | |
39 while (it.next(&path)) { | |
40 fSKPs.push_back() = SkOSPath::Join(FLAGS_skps[0], path.c_str()); | |
41 } | |
42 } | |
43 } | |
44 } | |
45 | |
46 bool VisualBenchmarkStream::ReadPicture(const char* path, SkAutoTUnref<SkPicture >* pic) { | |
47 // Not strictly necessary, as it will be checked again later, | |
48 // but helps to avoid a lot of pointless work if we're going to skip it. | |
49 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, path)) { | |
50 return false; | |
51 } | |
52 | |
53 SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(path)); | |
54 if (stream.get() == NULL) { | |
55 SkDebugf("Could not read %s.\n", path); | |
56 return false; | |
57 } | |
58 | |
59 pic->reset(SkPicture::CreateFromStream(stream.get())); | |
60 if (pic->get() == NULL) { | |
61 SkDebugf("Could not read %s as an SkPicture.\n", path); | |
62 return false; | |
63 } | |
64 return true; | |
65 } | |
66 | |
67 Benchmark* VisualBenchmarkStream::next() { | |
68 while (fBenches) { | |
69 Benchmark* bench = fBenches->factory()(NULL); | |
70 fBenches = fBenches->next(); | |
71 if (bench->isVisual()) { | |
72 fSourceType = "bench"; | |
73 fBenchType = "micro"; | |
74 return bench; | |
75 } | |
76 } | |
77 | |
78 while (fGMs) { | |
79 SkAutoTDelete<skiagm::GM> gm(fGMs->factory()(NULL)); | |
80 fGMs = fGMs->next(); | |
81 if (gm->runAsBench()) { | |
82 fSourceType = "gm"; | |
83 fBenchType = "micro"; | |
84 return SkNEW_ARGS(GMBench, (gm.detach())); | |
85 } | |
86 } | |
87 | |
88 // Render skps | |
89 while (fCurrentSKP < fSKPs.count()) { | |
90 const SkString& path = fSKPs[fCurrentSKP++]; | |
91 SkAutoTUnref<SkPicture> pic; | |
92 if (!ReadPicture(path.c_str(), &pic)) { | |
93 continue; | |
94 } | |
95 | |
96 SkString name = SkOSPath::Basename(path.c_str()); | |
97 fSourceType = "skp"; | |
98 fBenchType = "playback"; | |
99 return SkNEW_ARGS(VisualSKPBench, (name.c_str(), pic.get())); | |
100 } | |
101 | |
102 return NULL; | |
103 } | |
OLD | NEW |