Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(155)

Side by Side Diff: bench/benchmain.cpp

Issue 151843002: Allow GMs ato be used as benchmarks. Make convex_poly_clip opt in. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Make inheritance private, use SkNEW_ARGS() Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 RefCntArray() {}
reed1 2014/02/03 14:09:57 nit: do you even need this empty constructor?
bsalomon 2014/02/03 14:34:29 Done.
40 SkRefCnt** append() { return this->INHERITED::append(); }
41 ~RefCntArray() { this->unrefAll(); }
42 private:
43 typedef SkTDArray<SkRefCnt*> INHERITED;
44 };
45
46 class GMBenchFactory : public SkBenchmarkFactory {
47 public:
48 GMBenchFactory(const skiagm::GMRegistry* gmreg)
49 : fGMFactory(gmreg->factory()) {
50 fSelfRegistry = SkNEW_ARGS(BenchRegistry, (this));
51 }
52
53 virtual ~GMBenchFactory() { SkDELETE(fSelfRegistry); }
54
55 virtual SkBenchmark* operator()() const SK_OVERRIDE {
56 skiagm::GM* gm = fGMFactory(NULL);
57 return SkNEW_ARGS(SkGMBench, (gm));
58 }
59
60 private:
61 skiagm::GMRegistry::Factory fGMFactory;
62 BenchRegistry* fSelfRegistry;
63 };
64
65 static void register_gm_benches() {
66 static bool gOnce;
67 static RefCntArray gGMBenchFactories;
68
69 if (!gOnce) {
70 const skiagm::GMRegistry* gmreg = skiagm::GMRegistry::Head();
71 while (gmreg) {
72 skiagm::GM* gm = gmreg->factory()(NULL);
73 if (NULL != gm && skiagm::GM::kAsBench_Flag & gm->getFlags()) {
74 *gGMBenchFactories.append() = SkNEW_ARGS(GMBenchFactory, (gmreg) );
75 }
76 SkDELETE(gm);
77 gmreg = gmreg->next();
78 }
79 gOnce = true;
80 }
81 }
82
35 enum BenchMode { 83 enum BenchMode {
36 kNormal_BenchMode, 84 kNormal_BenchMode,
37 kDeferred_BenchMode, 85 kDeferred_BenchMode,
38 kDeferredSilent_BenchMode, 86 kDeferredSilent_BenchMode,
39 kRecord_BenchMode, 87 kRecord_BenchMode,
40 kPictureRecord_BenchMode 88 kPictureRecord_BenchMode
41 }; 89 };
42 const char* BenchMode_Name[] = { 90 const char* BenchMode_Name[] = {
43 "normal", "deferred", "deferredSilent", "record", "picturerecord" 91 "normal", "deferred", "deferredSilent", "record", "picturerecord"
44 }; 92 };
(...skipping 11 matching lines...) Expand all
56 } 104 }
57 105
58 class Iter { 106 class Iter {
59 public: 107 public:
60 Iter() : fBench(BenchRegistry::Head()) {} 108 Iter() : fBench(BenchRegistry::Head()) {}
61 109
62 SkBenchmark* next() { 110 SkBenchmark* next() {
63 if (fBench) { 111 if (fBench) {
64 BenchRegistry::Factory f = fBench->factory(); 112 BenchRegistry::Factory f = fBench->factory();
65 fBench = fBench->next(); 113 fBench = fBench->next();
66 return f(); 114 return (*f)();
67 } 115 }
68 return NULL; 116 return NULL;
69 } 117 }
70 118
71 private: 119 private:
72 const BenchRegistry* fBench; 120 const BenchRegistry* fBench;
73 }; 121 };
74 122
75 class AutoPrePostDraw { 123 class AutoPrePostDraw {
76 public: 124 public:
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 if (currRaw < FLAGS_minMs) { 336 if (currRaw < FLAGS_minMs) {
289 return false; 337 return false;
290 } 338 }
291 const double low = 1 - FLAGS_error, high = 1 + FLAGS_error; 339 const double low = 1 - FLAGS_error, high = 1 + FLAGS_error;
292 const double ratio = currPerLoop / prevPerLoop; 340 const double ratio = currPerLoop / prevPerLoop;
293 return low < ratio && ratio < high; 341 return low < ratio && ratio < high;
294 } 342 }
295 343
296 int tool_main(int argc, char** argv); 344 int tool_main(int argc, char** argv);
297 int tool_main(int argc, char** argv) { 345 int tool_main(int argc, char** argv) {
346 register_gm_benches();
298 SkCommandLineFlags::Parse(argc, argv); 347 SkCommandLineFlags::Parse(argc, argv);
299 #if SK_ENABLE_INST_COUNT 348 #if SK_ENABLE_INST_COUNT
300 if (FLAGS_leaks) { 349 if (FLAGS_leaks) {
301 gPrintInstCount = true; 350 gPrintInstCount = true;
302 } 351 }
303 #endif 352 #endif
304 SkAutoGraphics ag; 353 SkAutoGraphics ag;
305 354
306 // First, parse some flags. 355 // First, parse some flags.
307 SkBenchLogger logger; 356 SkBenchLogger logger;
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after
693 gContextFactory.destroyContexts(); 742 gContextFactory.destroyContexts();
694 #endif 743 #endif
695 return 0; 744 return 0;
696 } 745 }
697 746
698 #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL) 747 #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL)
699 int main(int argc, char * const argv[]) { 748 int main(int argc, char * const argv[]) {
700 return tool_main(argc, (char**) argv); 749 return tool_main(argc, (char**) argv);
701 } 750 }
702 #endif 751 #endif
OLDNEW
« bench/SkGMBench.cpp ('K') | « bench/SkGMBench.cpp ('k') | gm/convexpolyclip.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698