OLD | NEW |
---|---|
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 Loading... | |
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 | |
145 enum BBH { kNone, kRTree, kTileGrid }; | |
146 enum Mode { kTiled, kRandom }; | |
147 class TiledPlaybackBench : public Benchmark { | |
148 public: | |
149 TiledPlaybackBench(BBH bbh, Mode mode) : fBBH(bbh), fMode(mode), fName("tile d_playback") { | |
150 switch (fBBH) { | |
151 case kNone: fName.append("_none" ); break; | |
152 case kRTree: fName.append("_rtree" ); break; | |
153 case kTileGrid: fName.append("_tilegrid"); break; | |
154 } | |
155 switch (fMode) { | |
156 case kTiled: fName.append("_tiled" ); break; | |
157 case kRandom: fName.append("_random"); break; | |
158 } | |
159 } | |
160 | |
161 virtual const char* onGetName() SK_OVERRIDE { return fName.c_str(); } | |
162 virtual SkIPoint onGetSize() SK_OVERRIDE { return SkIPoint::Make(1024,1024); } | |
163 | |
164 virtual void onPreDraw() SK_OVERRIDE { | |
165 SkTileGridFactory::TileGridInfo info = { { 256, 256 }, {0,0}, {0,0} }; | |
166 SkAutoTDelete<SkBBHFactory> factory; | |
167 switch (fBBH) { | |
168 case kNone: break; | |
169 case kRTree: factory.reset(new SkRTreeFactory); | |
robertphillips
2014/11/07 18:29:39
break; ?
mtklein
2014/11/07 18:45:28
Duh! Well that's why they performed so eerily sim
| |
170 case kTileGrid: factory.reset(new SkTileGridFactory(info)); | |
robertphillips
2014/11/07 18:29:39
break; ?
| |
171 } | |
172 | |
173 SkPictureRecorder recorder; | |
174 SkCanvas* canvas = recorder.beginRecording(1024, 1024, factory); | |
175 SkRandom rand; | |
176 for (int i = 0; i < 10000; i++) { | |
177 int x = rand.nextULessThan(1024), | |
178 y = rand.nextULessThan(1024), | |
179 w = rand.nextULessThan(128), | |
180 h = rand.nextULessThan(128); | |
181 SkPaint paint; | |
182 paint.setColor(rand.nextU()); | |
183 paint.setAlpha(0xFF); | |
184 canvas->drawRect(SkRect::MakeXYWH(x,y,w,h), paint); | |
185 } | |
186 fPic.reset(recorder.endRecording()); | |
187 } | |
188 | |
189 virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { | |
190 for (int i = 0; i < loops; i++) { | |
191 // This inner loop guarantees we make the same choices for all bench variants. | |
192 SkRandom rand; | |
193 for (int j = 0; j < 10; j++) { | |
194 int x,y; | |
195 switch (fMode) { | |
196 case kTiled: x = 256 * rand.nextULessThan(4); | |
197 y = 256 * rand.nextULessThan(4); | |
198 break; | |
199 case kRandom: x = rand.nextULessThan(768), | |
200 y = rand.nextULessThan(768); | |
201 break; | |
202 } | |
203 SkAutoCanvasRestore ar(canvas, true/*save now*/); | |
204 canvas->clipRect(SkRect::MakeXYWH(x,y,256,256)); | |
205 fPic->playback(canvas); | |
206 } | |
207 } | |
208 } | |
209 | |
210 private: | |
211 BBH fBBH; | |
212 Mode fMode; | |
213 SkString fName; | |
214 SkAutoTDelete<SkPicture> fPic; | |
215 }; | |
216 | |
217 DEF_BENCH( return new TiledPlaybackBench(kNone, kRandom); ) | |
218 DEF_BENCH( return new TiledPlaybackBench(kNone, kTiled ); ) | |
219 DEF_BENCH( return new TiledPlaybackBench(kRTree, kRandom); ) | |
220 DEF_BENCH( return new TiledPlaybackBench(kRTree, kTiled ); ) | |
221 DEF_BENCH( return new TiledPlaybackBench(kTileGrid, kRandom); ) | |
222 DEF_BENCH( return new TiledPlaybackBench(kTileGrid, kTiled ); ) | |
OLD | NEW |