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

Side by Side Diff: bench/PicturePlaybackBench.cpp

Issue 699313006: Add benchmark to compare different BBH query patterns. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: windows Created 6 years, 1 month 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
« 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 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 #include "Benchmark.h" 7 #include "Benchmark.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 "SkPictureRecorder.h" 12 #include "SkPictureRecorder.h"
13 #include "SkPoint.h" 13 #include "SkPoint.h"
14 #include "SkRandom.h"
14 #include "SkRect.h" 15 #include "SkRect.h"
15 #include "SkString.h" 16 #include "SkString.h"
16 17
17 // This is designed to emulate about 4 screens of textual content 18 // This is designed to emulate about 4 screens of textual content
18 19
19 20
20 class PicturePlaybackBench : public Benchmark { 21 class PicturePlaybackBench : public Benchmark {
21 public: 22 public:
22 PicturePlaybackBench(const char name[]) { 23 PicturePlaybackBench(const char name[]) {
23 fName.printf("picture_playback_%s", name); 24 fName.printf("picture_playback_%s", name);
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 bool fDrawPosH; 133 bool fDrawPosH;
133 typedef PicturePlaybackBench INHERITED; 134 typedef PicturePlaybackBench INHERITED;
134 }; 135 };
135 136
136 137
137 /////////////////////////////////////////////////////////////////////////////// 138 ///////////////////////////////////////////////////////////////////////////////
138 139
139 DEF_BENCH( return new TextPlaybackBench(); ) 140 DEF_BENCH( return new TextPlaybackBench(); )
140 DEF_BENCH( return new PosTextPlaybackBench(true); ) 141 DEF_BENCH( return new PosTextPlaybackBench(true); )
141 DEF_BENCH( return new PosTextPlaybackBench(false); ) 142 DEF_BENCH( return new PosTextPlaybackBench(false); )
143
144 // Chrome draws into small tiles with impl-side painting.
145 // This benchmark measures the relative performance of our bounding-box hierarch ies,
146 // both when querying tiles perfectly and when not.
147 enum BBH { kNone, kRTree, kTileGrid };
148 enum Mode { kTiled, kRandom };
149 class TiledPlaybackBench : public Benchmark {
150 public:
151 TiledPlaybackBench(BBH bbh, Mode mode) : fBBH(bbh), fMode(mode), fName("tile d_playback") {
152 switch (fBBH) {
153 case kNone: fName.append("_none" ); break;
154 case kRTree: fName.append("_rtree" ); break;
155 case kTileGrid: fName.append("_tilegrid"); break;
156 }
157 switch (fMode) {
158 case kTiled: fName.append("_tiled" ); break;
159 case kRandom: fName.append("_random"); break;
160 }
161 }
162
163 virtual const char* onGetName() SK_OVERRIDE { return fName.c_str(); }
164 virtual SkIPoint onGetSize() SK_OVERRIDE { return SkIPoint::Make(1024,1024); }
165
166 virtual void onPreDraw() SK_OVERRIDE {
167 SkTileGridFactory::TileGridInfo info = { { 256, 256 }, {0,0}, {0,0} };
168 SkAutoTDelete<SkBBHFactory> factory;
169 switch (fBBH) {
170 case kNone: break;
171 case kRTree: factory.reset(new SkRTreeFactory); break;
172 case kTileGrid: factory.reset(new SkTileGridFactory(info)); break;
173 }
174
175 SkPictureRecorder recorder;
176 SkCanvas* canvas = recorder.beginRecording(1024, 1024, factory);
177 SkRandom rand;
178 for (int i = 0; i < 10000; i++) {
179 SkScalar x = rand.nextRangeScalar(0, 1024),
180 y = rand.nextRangeScalar(0, 1024),
181 w = rand.nextRangeScalar(0, 128),
182 h = rand.nextRangeScalar(0, 128);
183 SkPaint paint;
184 paint.setColor(rand.nextU());
185 paint.setAlpha(0xFF);
186 canvas->drawRect(SkRect::MakeXYWH(x,y,w,h), paint);
187 }
188 fPic.reset(recorder.endRecording());
189 }
190
191 virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE {
192 for (int i = 0; i < loops; i++) {
193 // This inner loop guarantees we make the same choices for all bench variants.
194 SkRandom rand;
195 for (int j = 0; j < 10; j++) {
196 SkScalar x = 0, y = 0;
197 switch (fMode) {
198 case kTiled: x = SkScalar(256 * rand.nextULessThan(4));
199 y = SkScalar(256 * rand.nextULessThan(4));
200 break;
201 case kRandom: x = rand.nextRangeScalar(0, 768);
202 y = rand.nextRangeScalar(0, 768);
203 break;
204 }
205 SkAutoCanvasRestore ar(canvas, true/*save now*/);
206 canvas->clipRect(SkRect::MakeXYWH(x,y,256,256));
207 fPic->playback(canvas);
208 }
209 }
210 }
211
212 private:
213 BBH fBBH;
214 Mode fMode;
215 SkString fName;
216 SkAutoTDelete<SkPicture> fPic;
217 };
218
219 DEF_BENCH( return new TiledPlaybackBench(kNone, kRandom); )
220 DEF_BENCH( return new TiledPlaybackBench(kNone, kTiled ); )
221 DEF_BENCH( return new TiledPlaybackBench(kRTree, kRandom); )
222 DEF_BENCH( return new TiledPlaybackBench(kRTree, kTiled ); )
223 DEF_BENCH( return new TiledPlaybackBench(kTileGrid, kRandom); )
224 DEF_BENCH( return new TiledPlaybackBench(kTileGrid, kTiled ); )
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