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