| 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 // Note that ~SkTDArray is not virtual. This inherits privately to bar using thi
s as a SkTDArray*. |
| 37 class RefCntArray : private SkTDArray<SkRefCnt*> { |
| 38 public: |
| 39 SkRefCnt** append() { return this->INHERITED::append(); } |
| 40 ~RefCntArray() { this->unrefAll(); } |
| 41 private: |
| 42 typedef SkTDArray<SkRefCnt*> INHERITED; |
| 43 }; |
| 44 |
| 45 class GMBenchFactory : public SkBenchmarkFactory { |
| 46 public: |
| 47 GMBenchFactory(const skiagm::GMRegistry* gmreg) |
| 48 : fGMFactory(gmreg->factory()) { |
| 49 fSelfRegistry = SkNEW_ARGS(BenchRegistry, (this)); |
| 50 } |
| 51 |
| 52 virtual ~GMBenchFactory() { SkDELETE(fSelfRegistry); } |
| 53 |
| 54 virtual SkBenchmark* operator()() const SK_OVERRIDE { |
| 55 skiagm::GM* gm = fGMFactory(NULL); |
| 56 return SkNEW_ARGS(SkGMBench, (gm)); |
| 57 } |
| 58 |
| 59 private: |
| 60 skiagm::GMRegistry::Factory fGMFactory; |
| 61 BenchRegistry* fSelfRegistry; |
| 62 }; |
| 63 |
| 64 static void register_gm_benches() { |
| 65 static bool gOnce; |
| 66 static RefCntArray gGMBenchFactories; |
| 67 |
| 68 if (!gOnce) { |
| 69 const skiagm::GMRegistry* gmreg = skiagm::GMRegistry::Head(); |
| 70 while (gmreg) { |
| 71 skiagm::GM* gm = gmreg->factory()(NULL); |
| 72 if (NULL != gm && skiagm::GM::kAsBench_Flag & gm->getFlags()) { |
| 73 *gGMBenchFactories.append() = SkNEW_ARGS(GMBenchFactory, (gmreg)
); |
| 74 } |
| 75 SkDELETE(gm); |
| 76 gmreg = gmreg->next(); |
| 77 } |
| 78 gOnce = true; |
| 79 } |
| 80 } |
| 81 |
| 35 enum BenchMode { | 82 enum BenchMode { |
| 36 kNormal_BenchMode, | 83 kNormal_BenchMode, |
| 37 kDeferred_BenchMode, | 84 kDeferred_BenchMode, |
| 38 kDeferredSilent_BenchMode, | 85 kDeferredSilent_BenchMode, |
| 39 kRecord_BenchMode, | 86 kRecord_BenchMode, |
| 40 kPictureRecord_BenchMode | 87 kPictureRecord_BenchMode |
| 41 }; | 88 }; |
| 42 const char* BenchMode_Name[] = { | 89 const char* BenchMode_Name[] = { |
| 43 "normal", "deferred", "deferredSilent", "record", "picturerecord" | 90 "normal", "deferred", "deferredSilent", "record", "picturerecord" |
| 44 }; | 91 }; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 56 } | 103 } |
| 57 | 104 |
| 58 class Iter { | 105 class Iter { |
| 59 public: | 106 public: |
| 60 Iter() : fBench(BenchRegistry::Head()) {} | 107 Iter() : fBench(BenchRegistry::Head()) {} |
| 61 | 108 |
| 62 SkBenchmark* next() { | 109 SkBenchmark* next() { |
| 63 if (fBench) { | 110 if (fBench) { |
| 64 BenchRegistry::Factory f = fBench->factory(); | 111 BenchRegistry::Factory f = fBench->factory(); |
| 65 fBench = fBench->next(); | 112 fBench = fBench->next(); |
| 66 return f(); | 113 return (*f)(); |
| 67 } | 114 } |
| 68 return NULL; | 115 return NULL; |
| 69 } | 116 } |
| 70 | 117 |
| 71 private: | 118 private: |
| 72 const BenchRegistry* fBench; | 119 const BenchRegistry* fBench; |
| 73 }; | 120 }; |
| 74 | 121 |
| 75 class AutoPrePostDraw { | 122 class AutoPrePostDraw { |
| 76 public: | 123 public: |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 if (currRaw < FLAGS_minMs) { | 335 if (currRaw < FLAGS_minMs) { |
| 289 return false; | 336 return false; |
| 290 } | 337 } |
| 291 const double low = 1 - FLAGS_error, high = 1 + FLAGS_error; | 338 const double low = 1 - FLAGS_error, high = 1 + FLAGS_error; |
| 292 const double ratio = currPerLoop / prevPerLoop; | 339 const double ratio = currPerLoop / prevPerLoop; |
| 293 return low < ratio && ratio < high; | 340 return low < ratio && ratio < high; |
| 294 } | 341 } |
| 295 | 342 |
| 296 int tool_main(int argc, char** argv); | 343 int tool_main(int argc, char** argv); |
| 297 int tool_main(int argc, char** argv) { | 344 int tool_main(int argc, char** argv) { |
| 345 register_gm_benches(); |
| 298 SkCommandLineFlags::Parse(argc, argv); | 346 SkCommandLineFlags::Parse(argc, argv); |
| 299 #if SK_ENABLE_INST_COUNT | 347 #if SK_ENABLE_INST_COUNT |
| 300 if (FLAGS_leaks) { | 348 if (FLAGS_leaks) { |
| 301 gPrintInstCount = true; | 349 gPrintInstCount = true; |
| 302 } | 350 } |
| 303 #endif | 351 #endif |
| 304 SkAutoGraphics ag; | 352 SkAutoGraphics ag; |
| 305 | 353 |
| 306 // First, parse some flags. | 354 // First, parse some flags. |
| 307 SkBenchLogger logger; | 355 SkBenchLogger logger; |
| (...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 693 gContextFactory.destroyContexts(); | 741 gContextFactory.destroyContexts(); |
| 694 #endif | 742 #endif |
| 695 return 0; | 743 return 0; |
| 696 } | 744 } |
| 697 | 745 |
| 698 #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL) | 746 #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL) |
| 699 int main(int argc, char * const argv[]) { | 747 int main(int argc, char * const argv[]) { |
| 700 return tool_main(argc, (char**) argv); | 748 return tool_main(argc, (char**) argv); |
| 701 } | 749 } |
| 702 #endif | 750 #endif |
| OLD | NEW |