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

Side by Side Diff: bench/PictureRecordBench.cpp

Issue 23513065: also limit loops-per-canvas in picture_record_dictionaries, which has the same problem as unique_pa… (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: override 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 | « no previous file | no next file » | 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(const char name[]) { 19 PictureRecordBench(const char name[]) {
20 fName.printf("picture_record_%s", name); 20 fName.printf("picture_record_%s", name);
21 fIsRendering = false; 21 fIsRendering = false;
22 } 22 }
23 23
24 enum { 24 enum {
25 PICTURE_WIDTH = 1000, 25 PICTURE_WIDTH = 1000,
26 PICTURE_HEIGHT = 4000, 26 PICTURE_HEIGHT = 4000,
27 }; 27 };
28 protected: 28 protected:
29 virtual const char* onGetName() { 29 virtual const char* onGetName() SK_OVERRIDE {
30 return fName.c_str(); 30 return fName.c_str();
31 } 31 }
32 32 private:
33 virtual void onDraw(SkCanvas*) {
34 SkPicture picture;
35
36 SkCanvas* pCanvas = picture.beginRecording(PICTURE_WIDTH, PICTURE_HEIGHT );
37 recordCanvas(pCanvas);
38
39 // we don't need to draw the picture as the endRecording step will
40 // do the work of transferring the recorded content into a playback
41 // object.
42 picture.endRecording();
43 }
44
45 virtual void recordCanvas(SkCanvas* canvas) = 0;
46
47 SkString fName; 33 SkString fName;
48 private:
49 typedef SkBenchmark INHERITED; 34 typedef SkBenchmark INHERITED;
50 }; 35 };
51 36
37
38 static const int kMaxLoopsPerCanvas = 10000;
39
52 /* 40 /*
53 * An SkPicture has internal dictionaries to store bitmaps, matrices, paints, 41 * An SkPicture has internal dictionaries to store bitmaps, matrices, paints,
54 * and regions. This bench populates those dictionaries to test the speed of 42 * and regions. This bench populates those dictionaries to test the speed of
55 * reading and writing to those particular dictionary data structures. 43 * reading and writing to those particular dictionary data structures.
56 */ 44 */
57 class DictionaryRecordBench : public PictureRecordBench { 45 class DictionaryRecordBench : public PictureRecordBench {
58 public: 46 public:
59 DictionaryRecordBench() 47 DictionaryRecordBench() : INHERITED("dictionaries") {}
60 : INHERITED("dictionaries") { }
61 48
62 protected: 49 protected:
63 virtual void recordCanvas(SkCanvas* canvas) { 50 virtual void onDraw(SkCanvas*) SK_OVERRIDE {
51 SkAutoTDelete<SkPicture> picture;
52 SkCanvas* canvas = NULL;
64 53
65 const SkPoint translateDelta = getTranslateDelta(this->getLoops()); 54 const SkPoint translateDelta = getTranslateDelta(this->getLoops());
66 55
67 for (int i = 0; i < this->getLoops(); i++) { 56 for (int i = 0; i < this->getLoops(); i++) {
57 if (0 == i % kMaxLoopsPerCanvas) {
58 picture.reset(SkNEW(SkPicture));
59 canvas = picture->beginRecording(PICTURE_WIDTH, PICTURE_HEIGHT);
60 }
68 61
69 SkColor color = SK_ColorYELLOW + (i % 255); 62 SkColor color = SK_ColorYELLOW + (i % 255);
70 SkIRect rect = SkIRect::MakeWH(i % PICTURE_WIDTH, i % PICTURE_HEIGHT ); 63 SkIRect rect = SkIRect::MakeWH(i % PICTURE_WIDTH, i % PICTURE_HEIGHT );
71 64
72 canvas->save(); 65 canvas->save();
73 66
74 // set the clip to the given region 67 // set the clip to the given region
75 SkRegion region; 68 SkRegion region;
76 region.setRect(rect); 69 region.setRect(rect);
77 canvas->clipRegion(region); 70 canvas->clipRegion(region);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 private: 104 private:
112 typedef PictureRecordBench INHERITED; 105 typedef PictureRecordBench INHERITED;
113 }; 106 };
114 107
115 /* 108 /*
116 * Populates the SkPaint dictionary with a large number of unique paint 109 * Populates the SkPaint dictionary with a large number of unique paint
117 * objects that differ only by color 110 * objects that differ only by color
118 */ 111 */
119 class UniquePaintDictionaryRecordBench : public PictureRecordBench { 112 class UniquePaintDictionaryRecordBench : public PictureRecordBench {
120 public: 113 public:
121 UniquePaintDictionaryRecordBench() 114 UniquePaintDictionaryRecordBench() : INHERITED("unique_paint_dictionary") { }
122 : INHERITED("unique_paint_dictionary") { }
123 115
124 protected: 116 protected:
125 virtual void recordCanvas(SkCanvas* /*ignored*/) { 117 virtual void onDraw(SkCanvas*) SK_OVERRIDE {
126 // We ignore the parent's canvas (which is just there for our
127 // convenience) because we've got to have more careful control over it.
128 // We start a new one every so often to prevent unbounded memory growth.
129
130 SkRandom rand; 118 SkRandom rand;
131 SkPaint paint; 119 SkPaint paint;
132 SkAutoTDelete<SkPicture> picture; 120 SkAutoTDelete<SkPicture> picture;
133 SkCanvas* canvas = NULL; 121 SkCanvas* canvas = NULL;
134 const int kMaxPaintsPerCanvas = 10000;
135 for (int i = 0; i < this->getLoops(); i++) { 122 for (int i = 0; i < this->getLoops(); i++) {
136 if (0 == i % kMaxPaintsPerCanvas) { 123 if (0 == i % kMaxLoopsPerCanvas) {
137 picture.reset(SkNEW(SkPicture)); 124 picture.reset(SkNEW(SkPicture));
138 canvas = picture->beginRecording(PICTURE_WIDTH, PICTURE_HEIGHT); 125 canvas = picture->beginRecording(PICTURE_WIDTH, PICTURE_HEIGHT);
139 } 126 }
140 paint.setColor(rand.nextU()); 127 paint.setColor(rand.nextU());
141 canvas->drawPaint(paint); 128 canvas->drawPaint(paint);
142 } 129 }
143 } 130 }
144 131
145 private: 132 private:
146 typedef PictureRecordBench INHERITED; 133 typedef PictureRecordBench INHERITED;
147 }; 134 };
148 135
149 /* 136 /*
150 * Populates the SkPaint dictionary with a number of unique paint 137 * Populates the SkPaint dictionary with a number of unique paint
151 * objects that get reused repeatedly. 138 * objects that get reused repeatedly.
152 * 139 *
153 * Re-creating the paint objects in the inner loop slows the benchmark down 10% . 140 * Re-creating the paint objects in the inner loop slows the benchmark down 10% .
154 * Using setColor(i % objCount) instead of a random color creates a very high r ate 141 * Using setColor(i % objCount) instead of a random color creates a very high r ate
155 * of hash conflicts, slowing us down 12%. 142 * of hash conflicts, slowing us down 12%.
156 */ 143 */
157 class RecurringPaintDictionaryRecordBench : public PictureRecordBench { 144 class RecurringPaintDictionaryRecordBench : public PictureRecordBench {
158 public: 145 public:
159 RecurringPaintDictionaryRecordBench() 146 RecurringPaintDictionaryRecordBench() : INHERITED("recurring_paint_dictionar y") {
160 : INHERITED("recurring_paint_dictionary") {
161 SkRandom rand; 147 SkRandom rand;
162 for (int i = 0; i < ObjCount; i++) { 148 for (int i = 0; i < ObjCount; i++) {
163 fPaint[i].setColor(rand.nextU()); 149 fPaint[i].setColor(rand.nextU());
164 } 150 }
165 } 151 }
166 152
167 enum { 153 enum {
168 ObjCount = 100, // number of unique paint objects 154 ObjCount = 100, // number of unique paint objects
169 }; 155 };
170 protected: 156 protected:
171 virtual void recordCanvas(SkCanvas* canvas) { 157 virtual void onDraw(SkCanvas*) SK_OVERRIDE {
172 158 SkPicture picture;
159 SkCanvas* canvas = picture.beginRecording(PICTURE_WIDTH, PICTURE_HEIGHT) ;
173 for (int i = 0; i < this->getLoops(); i++) { 160 for (int i = 0; i < this->getLoops(); i++) {
174 canvas->drawPaint(fPaint[i % ObjCount]); 161 canvas->drawPaint(fPaint[i % ObjCount]);
175 } 162 }
176 } 163 }
177 164
178 private: 165 private:
179 SkPaint fPaint [ObjCount]; 166 SkPaint fPaint [ObjCount];
180 typedef PictureRecordBench INHERITED; 167 typedef PictureRecordBench INHERITED;
181 }; 168 };
182 169
183 /////////////////////////////////////////////////////////////////////////////// 170 ///////////////////////////////////////////////////////////////////////////////
184 171
185 DEF_BENCH( return new DictionaryRecordBench(); ) 172 DEF_BENCH( return new DictionaryRecordBench(); )
186 DEF_BENCH( return new UniquePaintDictionaryRecordBench(); ) 173 DEF_BENCH( return new UniquePaintDictionaryRecordBench(); )
187 DEF_BENCH( return new RecurringPaintDictionaryRecordBench(); ) 174 DEF_BENCH( return new RecurringPaintDictionaryRecordBench(); )
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698