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

Side by Side Diff: bench/PictureRecordBench.cpp

Issue 23876006: Refactoring: get rid of the SkBenchmark void* parameter. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: sync to head Created 7 years, 3 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
« no previous file with comments | « bench/PicturePlaybackBench.cpp ('k') | bench/PremulAndUnpremulAlphaOpsBench.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2012 Google Inc. 2 * Copyright 2012 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 #include "SkBenchmark.h" 7 #include "SkBenchmark.h"
8 #include "SkCanvas.h" 8 #include "SkCanvas.h"
9 #include "SkColor.h" 9 #include "SkColor.h"
10 #include "SkPaint.h" 10 #include "SkPaint.h"
11 #include "SkPicture.h" 11 #include "SkPicture.h"
12 #include "SkPoint.h" 12 #include "SkPoint.h"
13 #include "SkRandom.h" 13 #include "SkRandom.h"
14 #include "SkRect.h" 14 #include "SkRect.h"
15 #include "SkString.h" 15 #include "SkString.h"
16 16
17 class PictureRecordBench : public SkBenchmark { 17 class PictureRecordBench : public SkBenchmark {
18 public: 18 public:
19 PictureRecordBench(void* param, const char name[]) : INHERITED(param) { 19 PictureRecordBench(const char name[]) {
20 fName.printf("picture_record_%s", name); 20 fName.printf("picture_record_%s", name);
21 fPictureWidth = SkIntToScalar(PICTURE_WIDTH); 21 fPictureWidth = SkIntToScalar(PICTURE_WIDTH);
22 fPictureHeight = SkIntToScalar(PICTURE_HEIGHT); 22 fPictureHeight = SkIntToScalar(PICTURE_HEIGHT);
23 fIsRendering = false; 23 fIsRendering = false;
24 } 24 }
25 25
26 enum { 26 enum {
27 PICTURE_WIDTH = 1000, 27 PICTURE_WIDTH = 1000,
28 PICTURE_HEIGHT = 4000, 28 PICTURE_HEIGHT = 4000,
29 }; 29 };
(...skipping 24 matching lines...) Expand all
54 typedef SkBenchmark INHERITED; 54 typedef SkBenchmark INHERITED;
55 }; 55 };
56 56
57 /* 57 /*
58 * An SkPicture has internal dictionaries to store bitmaps, matrices, paints, 58 * An SkPicture has internal dictionaries to store bitmaps, matrices, paints,
59 * and regions. This bench populates those dictionaries to test the speed of 59 * and regions. This bench populates those dictionaries to test the speed of
60 * reading and writing to those particular dictionary data structures. 60 * reading and writing to those particular dictionary data structures.
61 */ 61 */
62 class DictionaryRecordBench : public PictureRecordBench { 62 class DictionaryRecordBench : public PictureRecordBench {
63 public: 63 public:
64 DictionaryRecordBench(void* param) 64 DictionaryRecordBench()
65 : INHERITED(param, "dictionaries") { } 65 : INHERITED("dictionaries") { }
66 66
67 protected: 67 protected:
68 virtual void recordCanvas(SkCanvas* canvas) { 68 virtual void recordCanvas(SkCanvas* canvas) {
69 69
70 const SkPoint translateDelta = getTranslateDelta(this->getLoops()); 70 const SkPoint translateDelta = getTranslateDelta(this->getLoops());
71 71
72 for (int i = 0; i < this->getLoops(); i++) { 72 for (int i = 0; i < this->getLoops(); i++) {
73 73
74 SkColor color = SK_ColorYELLOW + (i % 255); 74 SkColor color = SK_ColorYELLOW + (i % 255);
75 SkIRect rect = SkIRect::MakeWH(i % PICTURE_WIDTH, i % PICTURE_HEIGHT ); 75 SkIRect rect = SkIRect::MakeWH(i % PICTURE_WIDTH, i % PICTURE_HEIGHT );
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 private: 116 private:
117 typedef PictureRecordBench INHERITED; 117 typedef PictureRecordBench INHERITED;
118 }; 118 };
119 119
120 /* 120 /*
121 * Populates the SkPaint dictionary with a large number of unique paint 121 * Populates the SkPaint dictionary with a large number of unique paint
122 * objects that differ only by color 122 * objects that differ only by color
123 */ 123 */
124 class UniquePaintDictionaryRecordBench : public PictureRecordBench { 124 class UniquePaintDictionaryRecordBench : public PictureRecordBench {
125 public: 125 public:
126 UniquePaintDictionaryRecordBench(void* param) 126 UniquePaintDictionaryRecordBench()
127 : INHERITED(param, "unique_paint_dictionary") { } 127 : INHERITED("unique_paint_dictionary") { }
128 128
129 protected: 129 protected:
130 virtual void recordCanvas(SkCanvas* canvas) { 130 virtual void recordCanvas(SkCanvas* canvas) {
131 SkRandom rand; 131 SkRandom rand;
132 for (int i = 0; i < this->getLoops(); i++) { 132 for (int i = 0; i < this->getLoops(); i++) {
133 SkPaint paint; 133 SkPaint paint;
134 paint.setColor(rand.nextU()); 134 paint.setColor(rand.nextU());
135 canvas->drawPaint(paint); 135 canvas->drawPaint(paint);
136 } 136 }
137 } 137 }
138 138
139 private: 139 private:
140 typedef PictureRecordBench INHERITED; 140 typedef PictureRecordBench INHERITED;
141 }; 141 };
142 142
143 /* 143 /*
144 * Populates the SkPaint dictionary with a number of unique paint 144 * Populates the SkPaint dictionary with a number of unique paint
145 * objects that get reused repeatedly. 145 * objects that get reused repeatedly.
146 * 146 *
147 * Re-creating the paint objects in the inner loop slows the benchmark down 10% . 147 * Re-creating the paint objects in the inner loop slows the benchmark down 10% .
148 * Using setColor(i % objCount) instead of a random color creates a very high r ate 148 * Using setColor(i % objCount) instead of a random color creates a very high r ate
149 * of hash conflicts, slowing us down 12%. 149 * of hash conflicts, slowing us down 12%.
150 */ 150 */
151 class RecurringPaintDictionaryRecordBench : public PictureRecordBench { 151 class RecurringPaintDictionaryRecordBench : public PictureRecordBench {
152 public: 152 public:
153 RecurringPaintDictionaryRecordBench(void* param) 153 RecurringPaintDictionaryRecordBench()
154 : INHERITED(param, "recurring_paint_dictionary") { 154 : INHERITED("recurring_paint_dictionary") {
155 SkRandom rand; 155 SkRandom rand;
156 for (int i = 0; i < ObjCount; i++) { 156 for (int i = 0; i < ObjCount; i++) {
157 fPaint[i].setColor(rand.nextU()); 157 fPaint[i].setColor(rand.nextU());
158 } 158 }
159 } 159 }
160 160
161 enum { 161 enum {
162 ObjCount = 100, // number of unique paint objects 162 ObjCount = 100, // number of unique paint objects
163 }; 163 };
164 protected: 164 protected:
165 virtual void recordCanvas(SkCanvas* canvas) { 165 virtual void recordCanvas(SkCanvas* canvas) {
166 166
167 for (int i = 0; i < this->getLoops(); i++) { 167 for (int i = 0; i < this->getLoops(); i++) {
168 canvas->drawPaint(fPaint[i % ObjCount]); 168 canvas->drawPaint(fPaint[i % ObjCount]);
169 } 169 }
170 } 170 }
171 171
172 private: 172 private:
173 SkPaint fPaint [ObjCount]; 173 SkPaint fPaint [ObjCount];
174 typedef PictureRecordBench INHERITED; 174 typedef PictureRecordBench INHERITED;
175 }; 175 };
176 176
177 /////////////////////////////////////////////////////////////////////////////// 177 ///////////////////////////////////////////////////////////////////////////////
178 178
179 static SkBenchmark* Fact0(void* p) { return new DictionaryRecordBench(p); } 179 DEF_BENCH( return new DictionaryRecordBench(); )
180 static SkBenchmark* Fact1(void* p) { return new UniquePaintDictionaryRecordBench (p); } 180 DEF_BENCH( return new UniquePaintDictionaryRecordBench(); )
181 static SkBenchmark* Fact2(void* p) { return new RecurringPaintDictionaryRecordBe nch(p); } 181 DEF_BENCH( return new RecurringPaintDictionaryRecordBench(); )
182
183 static BenchRegistry gReg0(Fact0);
184 static BenchRegistry gReg1(Fact1);
185 static BenchRegistry gReg2(Fact2);
OLDNEW
« no previous file with comments | « bench/PicturePlaybackBench.cpp ('k') | bench/PremulAndUnpremulAlphaOpsBench.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698