Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "BenchTimer.h" | 8 #include "BenchTimer.h" |
| 9 #include "ResultsWriter.h" | 9 #include "ResultsWriter.h" |
| 10 #include "SkBenchLogger.h" | 10 #include "SkBenchLogger.h" |
| 11 #include "SkBenchmark.h" | 11 #include "SkBenchmark.h" |
| 12 #include "SkBitmapDevice.h" | 12 #include "SkBitmapDevice.h" |
| 13 #include "SkCanvas.h" | 13 #include "SkCanvas.h" |
| 14 #include "SkColorPriv.h" | 14 #include "SkColorPriv.h" |
| 15 #include "SkCommandLineFlags.h" | 15 #include "SkCommandLineFlags.h" |
| 16 #include "SkDeferredCanvas.h" | 16 #include "SkDeferredCanvas.h" |
| 17 #include "SkGMBench.h" | |
| 17 #include "SkGraphics.h" | 18 #include "SkGraphics.h" |
| 18 #include "SkImageEncoder.h" | 19 #include "SkImageEncoder.h" |
| 19 #include "SkOSFile.h" | 20 #include "SkOSFile.h" |
| 20 #include "SkPicture.h" | 21 #include "SkPicture.h" |
| 21 #include "SkString.h" | 22 #include "SkString.h" |
| 22 | 23 |
| 23 #if SK_SUPPORT_GPU | 24 #if SK_SUPPORT_GPU |
| 24 #include "GrContext.h" | 25 #include "GrContext.h" |
| 25 #include "GrContextFactory.h" | 26 #include "GrContextFactory.h" |
| 26 #include "GrRenderTarget.h" | 27 #include "GrRenderTarget.h" |
| 27 #include "SkGpuDevice.h" | 28 #include "SkGpuDevice.h" |
| 28 #include "gl/GrGLDefines.h" | 29 #include "gl/GrGLDefines.h" |
| 29 #else | 30 #else |
| 30 class GrContext; | 31 class GrContext; |
| 31 #endif // SK_SUPPORT_GPU | 32 #endif // SK_SUPPORT_GPU |
| 32 | 33 |
| 33 #include <limits> | 34 #include <limits> |
| 34 | 35 |
| 36 class AutoUnrefArray { | |
|
reed1
2014/02/03 13:20:42
Does this need a new class from scratch? Can you u
bsalomon
2014/02/03 14:02:45
Done. Inherited in order to override the destructo
| |
| 37 public: | |
| 38 AutoUnrefArray() {} | |
| 39 ~AutoUnrefArray() { | |
| 40 int count = fObjs.count(); | |
| 41 for (int i = 0; i < count; ++i) { | |
| 42 fObjs[i]->unref(); | |
| 43 } | |
| 44 } | |
| 45 const SkRefCnt*& push_back() { return *fObjs.append(); } | |
| 46 | |
| 47 private: | |
| 48 SkTDArray<const SkRefCnt*> fObjs; | |
| 49 }; | |
| 50 | |
| 51 class GMBenchFactory : public SkBenchmarkFactory { | |
| 52 public: | |
| 53 GMBenchFactory(const skiagm::GMRegistry* gmreg) | |
| 54 : fGMFactory(gmreg->factory()) | |
| 55 , fSelfRegistry(this) { | |
| 56 } | |
| 57 | |
| 58 virtual SkBenchmark* operator()() const SK_OVERRIDE { | |
| 59 skiagm::GM* gm = fGMFactory(NULL); | |
| 60 return new SkGMBench(gm); | |
| 61 } | |
| 62 | |
| 63 private: | |
| 64 skiagm::GMRegistry::Factory fGMFactory; | |
| 65 BenchRegistry fSelfRegistry; | |
| 66 }; | |
| 67 | |
| 68 static void register_gm_benches() { | |
| 69 static bool gOnce; | |
| 70 static AutoUnrefArray gUnreffer; | |
| 71 | |
| 72 if (!gOnce) { | |
| 73 const skiagm::GMRegistry* gmreg = skiagm::GMRegistry::Head(); | |
| 74 while (gmreg) { | |
| 75 skiagm::GM* gm = gmreg->factory()(NULL); | |
| 76 if (NULL != gm && skiagm::GM::kAsBench_Flag & gm->getFlags()) { | |
| 77 gUnreffer.push_back() = SkNEW_ARGS(GMBenchFactory, (gmreg)); | |
| 78 } | |
| 79 SkDELETE(gm); | |
| 80 gmreg = gmreg->next(); | |
| 81 } | |
| 82 gOnce = true; | |
| 83 } | |
| 84 } | |
| 85 | |
| 35 enum BenchMode { | 86 enum BenchMode { |
| 36 kNormal_BenchMode, | 87 kNormal_BenchMode, |
| 37 kDeferred_BenchMode, | 88 kDeferred_BenchMode, |
| 38 kDeferredSilent_BenchMode, | 89 kDeferredSilent_BenchMode, |
| 39 kRecord_BenchMode, | 90 kRecord_BenchMode, |
| 40 kPictureRecord_BenchMode | 91 kPictureRecord_BenchMode |
| 41 }; | 92 }; |
| 42 const char* BenchMode_Name[] = { | 93 const char* BenchMode_Name[] = { |
| 43 "normal", "deferred", "deferredSilent", "record", "picturerecord" | 94 "normal", "deferred", "deferredSilent", "record", "picturerecord" |
| 44 }; | 95 }; |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 56 } | 107 } |
| 57 | 108 |
| 58 class Iter { | 109 class Iter { |
| 59 public: | 110 public: |
| 60 Iter() : fBench(BenchRegistry::Head()) {} | 111 Iter() : fBench(BenchRegistry::Head()) {} |
| 61 | 112 |
| 62 SkBenchmark* next() { | 113 SkBenchmark* next() { |
| 63 if (fBench) { | 114 if (fBench) { |
| 64 BenchRegistry::Factory f = fBench->factory(); | 115 BenchRegistry::Factory f = fBench->factory(); |
| 65 fBench = fBench->next(); | 116 fBench = fBench->next(); |
| 66 return f(); | 117 return (*f)(); |
| 67 } | 118 } |
| 68 return NULL; | 119 return NULL; |
| 69 } | 120 } |
| 70 | 121 |
| 71 private: | 122 private: |
| 72 const BenchRegistry* fBench; | 123 const BenchRegistry* fBench; |
| 73 }; | 124 }; |
| 74 | 125 |
| 75 class AutoPrePostDraw { | 126 class AutoPrePostDraw { |
| 76 public: | 127 public: |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 288 if (currRaw < FLAGS_minMs) { | 339 if (currRaw < FLAGS_minMs) { |
| 289 return false; | 340 return false; |
| 290 } | 341 } |
| 291 const double low = 1 - FLAGS_error, high = 1 + FLAGS_error; | 342 const double low = 1 - FLAGS_error, high = 1 + FLAGS_error; |
| 292 const double ratio = currPerLoop / prevPerLoop; | 343 const double ratio = currPerLoop / prevPerLoop; |
| 293 return low < ratio && ratio < high; | 344 return low < ratio && ratio < high; |
| 294 } | 345 } |
| 295 | 346 |
| 296 int tool_main(int argc, char** argv); | 347 int tool_main(int argc, char** argv); |
| 297 int tool_main(int argc, char** argv) { | 348 int tool_main(int argc, char** argv) { |
| 349 register_gm_benches(); | |
| 298 SkCommandLineFlags::Parse(argc, argv); | 350 SkCommandLineFlags::Parse(argc, argv); |
| 299 #if SK_ENABLE_INST_COUNT | 351 #if SK_ENABLE_INST_COUNT |
| 300 if (FLAGS_leaks) { | 352 if (FLAGS_leaks) { |
| 301 gPrintInstCount = true; | 353 gPrintInstCount = true; |
| 302 } | 354 } |
| 303 #endif | 355 #endif |
| 304 SkAutoGraphics ag; | 356 SkAutoGraphics ag; |
| 305 | 357 |
| 306 // First, parse some flags. | 358 // First, parse some flags. |
| 307 SkBenchLogger logger; | 359 SkBenchLogger logger; |
| (...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 693 gContextFactory.destroyContexts(); | 745 gContextFactory.destroyContexts(); |
| 694 #endif | 746 #endif |
| 695 return 0; | 747 return 0; |
| 696 } | 748 } |
| 697 | 749 |
| 698 #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL) | 750 #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL) |
| 699 int main(int argc, char * const argv[]) { | 751 int main(int argc, char * const argv[]) { |
| 700 return tool_main(argc, (char**) argv); | 752 return tool_main(argc, (char**) argv); |
| 701 } | 753 } |
| 702 #endif | 754 #endif |
| OLD | NEW |