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

Side by Side Diff: bench/PicturePlaybackBench.cpp

Issue 1811703002: return pictures as sk_sp (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rely on RVO in picturerecorder Created 4 years, 9 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
« no previous file with comments | « bench/PictureOverheadBench.cpp ('k') | bench/RecordingBench.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 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"
(...skipping 24 matching lines...) Expand all
35 protected: 35 protected:
36 virtual const char* onGetName() { 36 virtual const char* onGetName() {
37 return fName.c_str(); 37 return fName.c_str();
38 } 38 }
39 39
40 virtual void onDraw(int loops, SkCanvas* canvas) { 40 virtual void onDraw(int loops, SkCanvas* canvas) {
41 41
42 SkPictureRecorder recorder; 42 SkPictureRecorder recorder;
43 SkCanvas* pCanvas = recorder.beginRecording(PICTURE_WIDTH, PICTURE_HEIGH T, nullptr, 0); 43 SkCanvas* pCanvas = recorder.beginRecording(PICTURE_WIDTH, PICTURE_HEIGH T, nullptr, 0);
44 this->recordCanvas(pCanvas); 44 this->recordCanvas(pCanvas);
45 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); 45 sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture());
46 46
47 const SkPoint translateDelta = getTranslateDelta(loops); 47 const SkPoint translateDelta = getTranslateDelta(loops);
48 48
49 for (int i = 0; i < loops; i++) { 49 for (int i = 0; i < loops; i++) {
50 picture->playback(canvas); 50 picture->playback(canvas);
51 canvas->translate(translateDelta.fX, translateDelta.fY); 51 canvas->translate(translateDelta.fX, translateDelta.fY);
52 } 52 }
53 } 53 }
54 54
55 virtual void recordCanvas(SkCanvas* canvas) = 0; 55 virtual void recordCanvas(SkCanvas* canvas) = 0;
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 for (int i = 0; i < 10000; i++) { 175 for (int i = 0; i < 10000; i++) {
176 SkScalar x = rand.nextRangeScalar(0, 1024), 176 SkScalar x = rand.nextRangeScalar(0, 1024),
177 y = rand.nextRangeScalar(0, 1024), 177 y = rand.nextRangeScalar(0, 1024),
178 w = rand.nextRangeScalar(0, 128), 178 w = rand.nextRangeScalar(0, 128),
179 h = rand.nextRangeScalar(0, 128); 179 h = rand.nextRangeScalar(0, 128);
180 SkPaint paint; 180 SkPaint paint;
181 paint.setColor(rand.nextU()); 181 paint.setColor(rand.nextU());
182 paint.setAlpha(0xFF); 182 paint.setAlpha(0xFF);
183 canvas->drawRect(SkRect::MakeXYWH(x,y,w,h), paint); 183 canvas->drawRect(SkRect::MakeXYWH(x,y,w,h), paint);
184 } 184 }
185 fPic.reset(recorder.endRecording()); 185 fPic = recorder.finishRecordingAsPicture();
186 } 186 }
187 187
188 void onDraw(int loops, SkCanvas* canvas) override { 188 void onDraw(int loops, SkCanvas* canvas) override {
189 for (int i = 0; i < loops; i++) { 189 for (int i = 0; i < loops; i++) {
190 // This inner loop guarantees we make the same choices for all bench variants. 190 // This inner loop guarantees we make the same choices for all bench variants.
191 SkRandom rand; 191 SkRandom rand;
192 for (int j = 0; j < 10; j++) { 192 for (int j = 0; j < 10; j++) {
193 SkScalar x = 0, y = 0; 193 SkScalar x = 0, y = 0;
194 switch (fMode) { 194 switch (fMode) {
195 case kTiled: x = SkScalar(256 * rand.nextULessThan(4)); 195 case kTiled: x = SkScalar(256 * rand.nextULessThan(4));
196 y = SkScalar(256 * rand.nextULessThan(4)); 196 y = SkScalar(256 * rand.nextULessThan(4));
197 break; 197 break;
198 case kRandom: x = rand.nextRangeScalar(0, 768); 198 case kRandom: x = rand.nextRangeScalar(0, 768);
199 y = rand.nextRangeScalar(0, 768); 199 y = rand.nextRangeScalar(0, 768);
200 break; 200 break;
201 } 201 }
202 SkAutoCanvasRestore ar(canvas, true/*save now*/); 202 SkAutoCanvasRestore ar(canvas, true/*save now*/);
203 canvas->clipRect(SkRect::MakeXYWH(x,y,256,256)); 203 canvas->clipRect(SkRect::MakeXYWH(x,y,256,256));
204 fPic->playback(canvas); 204 fPic->playback(canvas);
205 } 205 }
206 } 206 }
207 } 207 }
208 208
209 private: 209 private:
210 BBH fBBH; 210 BBH fBBH;
211 Mode fMode; 211 Mode fMode;
212 SkString fName; 212 SkString fName;
213 SkAutoTUnref<SkPicture> fPic; 213 sk_sp<SkPicture> fPic;
214 }; 214 };
215 215
216 DEF_BENCH( return new TiledPlaybackBench(kNone, kRandom); ) 216 DEF_BENCH( return new TiledPlaybackBench(kNone, kRandom); )
217 DEF_BENCH( return new TiledPlaybackBench(kNone, kTiled ); ) 217 DEF_BENCH( return new TiledPlaybackBench(kNone, kTiled ); )
218 DEF_BENCH( return new TiledPlaybackBench(kRTree, kRandom); ) 218 DEF_BENCH( return new TiledPlaybackBench(kRTree, kRandom); )
219 DEF_BENCH( return new TiledPlaybackBench(kRTree, kTiled ); ) 219 DEF_BENCH( return new TiledPlaybackBench(kRTree, kTiled ); )
OLDNEW
« no previous file with comments | « bench/PictureOverheadBench.cpp ('k') | bench/RecordingBench.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698