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

Side by Side Diff: bench/PictureRecordBench.cpp

Issue 23478013: Major bench refactoring. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: merge with head agani 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(void* param, const char name[]) : INHERITED(param) {
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 N = SkBENCHLOOP(25), // number of times to create the picture
28 PICTURE_WIDTH = 1000, 27 PICTURE_WIDTH = 1000,
29 PICTURE_HEIGHT = 4000, 28 PICTURE_HEIGHT = 4000,
30 }; 29 };
31 protected: 30 protected:
32 virtual const char* onGetName() { 31 virtual const char* onGetName() {
33 return fName.c_str(); 32 return fName.c_str();
34 } 33 }
35 34
36 virtual void onDraw(SkCanvas*) { 35 virtual void onDraw(SkCanvas*) {
37 int n = (int)(N * this->innerLoopScale()); 36 SkPicture picture;
38 n = SkMax32(1, n);
39 37
40 for (int i = 0; i < n; i++) { 38 SkCanvas* pCanvas = picture.beginRecording(PICTURE_WIDTH, PICTURE_HEIGHT );
39 recordCanvas(pCanvas);
41 40
42 SkPicture picture; 41 // we don't need to draw the picture as the endRecording step will
43 42 // do the work of transferring the recorded content into a playback
44 SkCanvas* pCanvas = picture.beginRecording(PICTURE_WIDTH, PICTURE_HE IGHT); 43 // object.
45 recordCanvas(pCanvas); 44 picture.endRecording();
46
47 // we don't need to draw the picture as the endRecording step will
48 // do the work of transferring the recorded content into a playback
49 // object.
50 picture.endRecording();
51 }
52 } 45 }
53 46
54 virtual void recordCanvas(SkCanvas* canvas) = 0; 47 virtual void recordCanvas(SkCanvas* canvas) = 0;
55 virtual float innerLoopScale() const { return 1; }
56 48
57 SkString fName; 49 SkString fName;
58 SkScalar fPictureWidth; 50 SkScalar fPictureWidth;
59 SkScalar fPictureHeight; 51 SkScalar fPictureHeight;
60 SkScalar fTextSize; 52 SkScalar fTextSize;
61 private: 53 private:
62 typedef SkBenchmark INHERITED; 54 typedef SkBenchmark INHERITED;
63 }; 55 };
64 56
65 /* 57 /*
66 * An SkPicture has internal dictionaries to store bitmaps, matrices, paints, 58 * An SkPicture has internal dictionaries to store bitmaps, matrices, paints,
67 * 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
68 * reading and writing to those particular dictionary data structures. 60 * reading and writing to those particular dictionary data structures.
69 */ 61 */
70 class DictionaryRecordBench : public PictureRecordBench { 62 class DictionaryRecordBench : public PictureRecordBench {
71 public: 63 public:
72 DictionaryRecordBench(void* param) 64 DictionaryRecordBench(void* param)
73 : INHERITED(param, "dictionaries") { } 65 : INHERITED(param, "dictionaries") { }
74 66
75 enum {
76 M = SkBENCHLOOP(100), // number of elements in each dictionary
77 };
78 protected: 67 protected:
79 virtual void recordCanvas(SkCanvas* canvas) { 68 virtual void recordCanvas(SkCanvas* canvas) {
80 69
81 const SkPoint translateDelta = getTranslateDelta(); 70 const SkPoint translateDelta = getTranslateDelta(this->getLoops());
82 71
83 for (int i = 0; i < M; i++) { 72 for (int i = 0; i < this->getLoops(); i++) {
84 73
85 SkColor color = SK_ColorYELLOW + (i % 255); 74 SkColor color = SK_ColorYELLOW + (i % 255);
86 SkIRect rect = SkIRect::MakeWH(i,i); 75 SkIRect rect = SkIRect::MakeWH(i % PICTURE_WIDTH, i % PICTURE_HEIGHT );
87 76
88 canvas->save(); 77 canvas->save();
89 78
90 // set the clip to the given region 79 // set the clip to the given region
91 SkRegion region; 80 SkRegion region;
92 region.setRect(rect); 81 region.setRect(rect);
93 canvas->clipRegion(region); 82 canvas->clipRegion(region);
94 83
95 // fill the clip with a color 84 // fill the clip with a color
96 SkPaint paint; 85 SkPaint paint;
(...skipping 15 matching lines...) Expand all
112 bitmapCanvas.drawColor(SkColorSetA(color, i % 255)); 101 bitmapCanvas.drawColor(SkColorSetA(color, i % 255));
113 102
114 // draw the bitmap onto the canvas 103 // draw the bitmap onto the canvas
115 canvas->drawBitmapMatrix(bitmap, matrix); 104 canvas->drawBitmapMatrix(bitmap, matrix);
116 105
117 canvas->restore(); 106 canvas->restore();
118 canvas->translate(translateDelta.fX, translateDelta.fY); 107 canvas->translate(translateDelta.fX, translateDelta.fY);
119 } 108 }
120 } 109 }
121 110
122 SkPoint getTranslateDelta() { 111 SkPoint getTranslateDelta(int M) {
123 SkIPoint canvasSize = onGetSize(); 112 SkIPoint canvasSize = onGetSize();
124 return SkPoint::Make(SkIntToScalar((PICTURE_WIDTH - canvasSize.fX)/M), 113 return SkPoint::Make(SkIntToScalar((PICTURE_WIDTH - canvasSize.fX)/M),
125 SkIntToScalar((PICTURE_HEIGHT- canvasSize.fY)/M)); 114 SkIntToScalar((PICTURE_HEIGHT- canvasSize.fY)/M));
126 } 115 }
127 private: 116 private:
128 typedef PictureRecordBench INHERITED; 117 typedef PictureRecordBench INHERITED;
129 }; 118 };
130 119
131 /* 120 /*
132 * Populates the SkPaint dictionary with a large number of unique paint 121 * Populates the SkPaint dictionary with a large number of unique paint
133 * objects that differ only by color 122 * objects that differ only by color
134 */ 123 */
135 class UniquePaintDictionaryRecordBench : public PictureRecordBench { 124 class UniquePaintDictionaryRecordBench : public PictureRecordBench {
136 public: 125 public:
137 UniquePaintDictionaryRecordBench(void* param) 126 UniquePaintDictionaryRecordBench(void* param)
138 : INHERITED(param, "unique_paint_dictionary") { } 127 : INHERITED(param, "unique_paint_dictionary") { }
139 128
140 enum {
141 M = SkBENCHLOOP(15000), // number of unique paint objects
142 };
143 protected: 129 protected:
144 virtual float innerLoopScale() const SK_OVERRIDE { return 0.1f; }
145 virtual void recordCanvas(SkCanvas* canvas) { 130 virtual void recordCanvas(SkCanvas* canvas) {
146 SkRandom rand; 131 SkRandom rand;
147 for (int i = 0; i < M; i++) { 132 for (int i = 0; i < this->getLoops(); i++) {
148 SkPaint paint; 133 SkPaint paint;
149 paint.setColor(rand.nextU()); 134 paint.setColor(rand.nextU());
150 canvas->drawPaint(paint); 135 canvas->drawPaint(paint);
151 } 136 }
152 } 137 }
153 138
154 private: 139 private:
155 typedef PictureRecordBench INHERITED; 140 typedef PictureRecordBench INHERITED;
156 }; 141 };
157 142
158 /* 143 /*
159 * Populates the SkPaint dictionary with a number of unique paint 144 * Populates the SkPaint dictionary with a number of unique paint
160 * objects that get reused repeatedly. 145 * objects that get reused repeatedly.
161 * 146 *
162 * 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% .
163 * 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
164 * of hash conflicts, slowing us down 12%. 149 * of hash conflicts, slowing us down 12%.
165 */ 150 */
166 class RecurringPaintDictionaryRecordBench : public PictureRecordBench { 151 class RecurringPaintDictionaryRecordBench : public PictureRecordBench {
167 public: 152 public:
168 RecurringPaintDictionaryRecordBench(void* param) 153 RecurringPaintDictionaryRecordBench(void* param)
169 : INHERITED(param, "recurring_paint_dictionary") { 154 : INHERITED(param, "recurring_paint_dictionary") {
170 SkRandom rand; 155 SkRandom rand;
171 for (int i = 0; i < ObjCount; i++) { 156 for (int i = 0; i < ObjCount; i++) {
172 fPaint[i].setColor(rand.nextU()); 157 fPaint[i].setColor(rand.nextU());
173 } 158 }
174 } 159 }
175 160
176 enum { 161 enum {
177 ObjCount = 100, // number of unique paint objects 162 ObjCount = 100, // number of unique paint objects
178 M = SkBENCHLOOP(50000), // number of draw iterations
179 }; 163 };
180 protected: 164 protected:
181 virtual float innerLoopScale() const SK_OVERRIDE { return 0.1f; }
182 virtual void recordCanvas(SkCanvas* canvas) { 165 virtual void recordCanvas(SkCanvas* canvas) {
183 166
184 for (int i = 0; i < M; i++) { 167 for (int i = 0; i < this->getLoops(); i++) {
185 canvas->drawPaint(fPaint[i % ObjCount]); 168 canvas->drawPaint(fPaint[i % ObjCount]);
186 } 169 }
187 } 170 }
188 171
189 private: 172 private:
190 SkPaint fPaint [ObjCount]; 173 SkPaint fPaint [ObjCount];
191 typedef PictureRecordBench INHERITED; 174 typedef PictureRecordBench INHERITED;
192 }; 175 };
193 176
194 /////////////////////////////////////////////////////////////////////////////// 177 ///////////////////////////////////////////////////////////////////////////////
195 178
196 static SkBenchmark* Fact0(void* p) { return new DictionaryRecordBench(p); } 179 static SkBenchmark* Fact0(void* p) { return new DictionaryRecordBench(p); }
197 static SkBenchmark* Fact1(void* p) { return new UniquePaintDictionaryRecordBench (p); } 180 static SkBenchmark* Fact1(void* p) { return new UniquePaintDictionaryRecordBench (p); }
198 static SkBenchmark* Fact2(void* p) { return new RecurringPaintDictionaryRecordBe nch(p); } 181 static SkBenchmark* Fact2(void* p) { return new RecurringPaintDictionaryRecordBe nch(p); }
199 182
200 static BenchRegistry gReg0(Fact0); 183 static BenchRegistry gReg0(Fact0);
201 static BenchRegistry gReg1(Fact1); 184 static BenchRegistry gReg1(Fact1);
202 static BenchRegistry gReg2(Fact2); 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