| 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" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 #include "GrContextFactory.h" | 28 #include "GrContextFactory.h" |
| 29 #include "GrRenderTarget.h" | 29 #include "GrRenderTarget.h" |
| 30 #include "SkGpuDevice.h" | 30 #include "SkGpuDevice.h" |
| 31 #include "gl/GrGLDefines.h" | 31 #include "gl/GrGLDefines.h" |
| 32 #else | 32 #else |
| 33 class GrContext; | 33 class GrContext; |
| 34 #endif // SK_SUPPORT_GPU | 34 #endif // SK_SUPPORT_GPU |
| 35 | 35 |
| 36 #include <limits> | 36 #include <limits> |
| 37 | 37 |
| 38 // Note that ~SkTDArray is not virtual. This inherits privately to bar using thi
s as a SkTDArray*. | |
| 39 class RefCntArray : private SkTDArray<SkRefCnt*> { | |
| 40 public: | |
| 41 SkRefCnt** append() { return this->INHERITED::append(); } | |
| 42 ~RefCntArray() { this->unrefAll(); } | |
| 43 private: | |
| 44 typedef SkTDArray<SkRefCnt*> INHERITED; | |
| 45 }; | |
| 46 | |
| 47 class GMBenchFactory : public SkBenchmarkFactory { | |
| 48 public: | |
| 49 GMBenchFactory(const skiagm::GMRegistry* gmreg) | |
| 50 : fGMFactory(gmreg->factory()) { | |
| 51 fSelfRegistry = SkNEW_ARGS(BenchRegistry, (this)); | |
| 52 } | |
| 53 | |
| 54 virtual ~GMBenchFactory() { SkDELETE(fSelfRegistry); } | |
| 55 | |
| 56 virtual SkBenchmark* operator()() const SK_OVERRIDE { | |
| 57 skiagm::GM* gm = fGMFactory(NULL); | |
| 58 gm->setMode(skiagm::GM::kBench_Mode); | |
| 59 return SkNEW_ARGS(SkGMBench, (gm)); | |
| 60 } | |
| 61 | |
| 62 private: | |
| 63 skiagm::GMRegistry::Factory fGMFactory; | |
| 64 BenchRegistry* fSelfRegistry; | |
| 65 }; | |
| 66 | |
| 67 static void register_gm_benches() { | |
| 68 static bool gOnce; | |
| 69 static RefCntArray gGMBenchFactories; | |
| 70 | |
| 71 if (!gOnce) { | |
| 72 const skiagm::GMRegistry* gmreg = skiagm::GMRegistry::Head(); | |
| 73 while (gmreg) { | |
| 74 skiagm::GM* gm = gmreg->factory()(NULL); | |
| 75 if (NULL != gm && skiagm::GM::kAsBench_Flag & gm->getFlags()) { | |
| 76 *gGMBenchFactories.append() = SkNEW_ARGS(GMBenchFactory, (gmreg)
); | |
| 77 } | |
| 78 SkDELETE(gm); | |
| 79 gmreg = gmreg->next(); | |
| 80 } | |
| 81 gOnce = true; | |
| 82 } | |
| 83 } | |
| 84 | |
| 85 enum BenchMode { | 38 enum BenchMode { |
| 86 kNormal_BenchMode, | 39 kNormal_BenchMode, |
| 87 kDeferred_BenchMode, | 40 kDeferred_BenchMode, |
| 88 kDeferredSilent_BenchMode, | 41 kDeferredSilent_BenchMode, |
| 89 kRecord_BenchMode, | 42 kRecord_BenchMode, |
| 90 kPictureRecord_BenchMode | 43 kPictureRecord_BenchMode |
| 91 }; | 44 }; |
| 92 const char* BenchMode_Name[] = { | 45 const char* BenchMode_Name[] = { |
| 93 "normal", "deferred", "deferredSilent", "record", "picturerecord" | 46 "normal", "deferred", "deferredSilent", "record", "picturerecord" |
| 94 }; | 47 }; |
| 95 | 48 |
| 96 static const char kDefaultsConfigStr[] = "defaults"; | 49 static const char kDefaultsConfigStr[] = "defaults"; |
| 97 | 50 |
| 98 /////////////////////////////////////////////////////////////////////////////// | 51 /////////////////////////////////////////////////////////////////////////////// |
| 99 | 52 |
| 100 class Iter { | 53 class Iter { |
| 101 public: | 54 public: |
| 102 Iter() : fBench(BenchRegistry::Head()) {} | 55 Iter() : fBenches(BenchRegistry::Head()), fGMs(skiagm::GMRegistry::Head()) {
} |
| 103 | 56 |
| 104 SkBenchmark* next() { | 57 SkBenchmark* next() { |
| 105 if (fBench) { | 58 if (fBenches) { |
| 106 BenchRegistry::Factory f = fBench->factory(); | 59 BenchRegistry::Factory f = fBenches->factory(); |
| 107 fBench = fBench->next(); | 60 fBenches = fBenches->next(); |
| 108 return (*f)(); | 61 return (*f)(); |
| 109 } | 62 } |
| 63 |
| 64 while (fGMs) { |
| 65 SkAutoTDelete<skiagm::GM> gm(fGMs->factory()(NULL)); |
| 66 fGMs = fGMs->next(); |
| 67 if (gm->getFlags() & skiagm::GM::kAsBench_Flag) { |
| 68 return SkNEW_ARGS(SkGMBench, (gm.detach())); |
| 69 } |
| 70 } |
| 71 |
| 110 return NULL; | 72 return NULL; |
| 111 } | 73 } |
| 112 | 74 |
| 113 private: | 75 private: |
| 114 const BenchRegistry* fBench; | 76 const BenchRegistry* fBenches; |
| 77 const skiagm::GMRegistry* fGMs; |
| 115 }; | 78 }; |
| 116 | 79 |
| 117 class AutoPrePostDraw { | 80 class AutoPrePostDraw { |
| 118 public: | 81 public: |
| 119 AutoPrePostDraw(SkBenchmark* bench) : fBench(bench) { | 82 AutoPrePostDraw(SkBenchmark* bench) : fBench(bench) { |
| 120 fBench->preDraw(); | 83 fBench->preDraw(); |
| 121 } | 84 } |
| 122 ~AutoPrePostDraw() { | 85 ~AutoPrePostDraw() { |
| 123 fBench->postDraw(); | 86 fBench->postDraw(); |
| 124 } | 87 } |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 if (currRaw < FLAGS_minMs) { | 273 if (currRaw < FLAGS_minMs) { |
| 311 return false; | 274 return false; |
| 312 } | 275 } |
| 313 const double low = 1 - FLAGS_error, high = 1 + FLAGS_error; | 276 const double low = 1 - FLAGS_error, high = 1 + FLAGS_error; |
| 314 const double ratio = currPerLoop / prevPerLoop; | 277 const double ratio = currPerLoop / prevPerLoop; |
| 315 return low < ratio && ratio < high; | 278 return low < ratio && ratio < high; |
| 316 } | 279 } |
| 317 | 280 |
| 318 int tool_main(int argc, char** argv); | 281 int tool_main(int argc, char** argv); |
| 319 int tool_main(int argc, char** argv) { | 282 int tool_main(int argc, char** argv) { |
| 320 register_gm_benches(); | |
| 321 SkCommandLineFlags::Parse(argc, argv); | 283 SkCommandLineFlags::Parse(argc, argv); |
| 322 #if SK_ENABLE_INST_COUNT | 284 #if SK_ENABLE_INST_COUNT |
| 323 if (FLAGS_leaks) { | 285 if (FLAGS_leaks) { |
| 324 gPrintInstCount = true; | 286 gPrintInstCount = true; |
| 325 } | 287 } |
| 326 #endif | 288 #endif |
| 327 SkAutoGraphics ag; | 289 SkAutoGraphics ag; |
| 328 | 290 |
| 329 // First, parse some flags. | 291 // First, parse some flags. |
| 330 SkBenchLogger logger; | 292 SkBenchLogger logger; |
| (...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 718 gContextFactory.destroyContexts(); | 680 gContextFactory.destroyContexts(); |
| 719 #endif | 681 #endif |
| 720 return 0; | 682 return 0; |
| 721 } | 683 } |
| 722 | 684 |
| 723 #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL) | 685 #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL) |
| 724 int main(int argc, char * const argv[]) { | 686 int main(int argc, char * const argv[]) { |
| 725 return tool_main(argc, (char**) argv); | 687 return tool_main(argc, (char**) argv); |
| 726 } | 688 } |
| 727 #endif | 689 #endif |
| OLD | NEW |