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

Side by Side Diff: bench/PictureNestingBench.cpp

Issue 566393002: Nested picture nanobench (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: Win build fix. Created 6 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
« no previous file with comments | « no previous file | gyp/bench.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2014 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "Benchmark.h"
9 #include "SkCanvas.h"
10 #include "SkColor.h"
11 #include "SkNullCanvas.h"
12 #include "SkPaint.h"
13 #include "SkPicture.h"
14 #include "SkPictureRecorder.h"
15 #include "SkString.h"
16
17 static int spinsky(SkCanvas* canvas, int lvl, const SkPaint& paint, int maxLevel ,
mtklein 2014/09/15 20:38:39 lvl, maxLevel... and maybe consider spelling it s
f(malita) 2014/09/15 22:09:25 Converted to a protected method & dropped the max
18 int maxPictureLevel) {
19 if (++lvl > maxLevel) {
20 return 0;
21 }
22
23 int pics = 0;
24 SkPictureRecorder recorder;
25 SkCanvas* c = canvas;
26
27 if (lvl <= maxPictureLevel) {
28 c = recorder.beginRecording(1, 1);
29 pics++;
30 }
31
32 c->drawLine(0.5, 0, 0, 1, paint);
33 c->drawLine(0.5, 0, 1, 1, paint);
34 c->drawLine(0, 1, 1, 1, paint);
35
36 c->save();
37 c->scale(0.5, 0.5);
38
39 c->translate(0, 1);
40 pics += spinsky(c, lvl, paint, maxLevel, maxPictureLevel);
41
42 c->translate(1, 0);
43 pics += spinsky(c, lvl, paint, maxLevel, maxPictureLevel);
44
45 c->translate(-0.5, -1);
46 pics += spinsky(c, lvl, paint, maxLevel, maxPictureLevel);
47 c->restore();
48
49 if (lvl <= maxPictureLevel) {
50 SkAutoTUnref<SkPicture> picture(recorder.endRecording());
51 canvas->drawPicture(picture);
52 }
53
54 return pics;
55 }
56
57 class PictureNesting : public Benchmark {
58 public:
59 PictureNesting(const char* name, int maxLevel, int maxPictureLevel)
60 : fMaxLevel(maxLevel)
61 , fMaxPictureLevel(maxPictureLevel) {
62
63 fPaint.setColor(SK_ColorRED);
64 fPaint.setAntiAlias(true);
65 fPaint.setStyle(SkPaint::kStroke_Style);
66 fName.printf("picture_nesting_%s_%d", name,
67 spinsky(SkCreateNullCanvas(), 0, fPaint, maxLevel, maxPictu reLevel));
68 }
69
70 protected:
71 virtual const char* onGetName() SK_OVERRIDE {
72 return fName.c_str();
73 }
74
75 void doDraw(SkCanvas* canvas) {
76 SkIPoint canvasSize = onGetSize();
77 canvas->save();
78 canvas->scale(SkIntToScalar(canvasSize.x()), SkIntToScalar(canvasSize.y( )));
79
80 spinsky(canvas, 0, fPaint, fMaxLevel, fMaxPictureLevel);
81
82 canvas->restore();
83 }
84
85 int fMaxLevel;
86 int fMaxPictureLevel;
87
88 private:
89 SkString fName;
90 SkPaint fPaint;
91
92 typedef Benchmark INHERITED;
93 };
94
95 class PictureNestingRecording : public PictureNesting {
96 public:
97 PictureNestingRecording(int maxLevel, int maxPictureLevel)
98 : INHERITED("recording", maxLevel, maxPictureLevel) {
99 }
100
101 protected:
102 virtual void onDraw(const int loops, SkCanvas* canvas) {
103 SkIPoint canvasSize = onGetSize();
104 SkPictureRecorder recorder;
105
106 for (int i = 0; i < loops; i++) {
107 SkCanvas* c = recorder.beginRecording(SkIntToScalar(canvasSize.x()),
108 SkIntToScalar(canvasSize.y())) ;
109 this->doDraw(c);
110 SkAutoTUnref<SkPicture> picture(recorder.endRecording());
111 }
112 }
113
114 private:
115 typedef PictureNesting INHERITED;
116 };
117
118 class PictureNestingPlayback : public PictureNesting {
119 public:
120 PictureNestingPlayback(int maxLevel, int maxPictureLevel)
121 : INHERITED("playback", maxLevel, maxPictureLevel) {
122
123 SkIPoint canvasSize = onGetSize();
124 SkPictureRecorder recorder;
125 SkCanvas* c = recorder.beginRecording(SkIntToScalar(canvasSize.x()),
126 SkIntToScalar(canvasSize.y()));
127
128 this->doDraw(c);
129 fPicture.reset(recorder.endRecording());
130 }
131
132 protected:
133 virtual void onDraw(const int loops, SkCanvas* canvas) {
134 for (int i = 0; i < loops; i++) {
135 canvas->drawPicture(fPicture);
136 }
137 }
138
139 private:
140 SkAutoTUnref<SkPicture> fPicture;
141
142 typedef PictureNesting INHERITED;
143 };
144
145 DEF_BENCH( return new PictureNestingRecording(8, 0); )
146 DEF_BENCH( return new PictureNestingRecording(8, 1); )
147 DEF_BENCH( return new PictureNestingRecording(8, 2); )
148 DEF_BENCH( return new PictureNestingRecording(8, 3); )
149 DEF_BENCH( return new PictureNestingRecording(8, 4); )
150 DEF_BENCH( return new PictureNestingRecording(8, 5); )
151 DEF_BENCH( return new PictureNestingRecording(8, 6); )
152 DEF_BENCH( return new PictureNestingRecording(8, 7); )
153 DEF_BENCH( return new PictureNestingRecording(8, 8); )
154
155 DEF_BENCH( return new PictureNestingPlayback(8, 0); )
156 DEF_BENCH( return new PictureNestingPlayback(8, 1); )
157 DEF_BENCH( return new PictureNestingPlayback(8, 2); )
158 DEF_BENCH( return new PictureNestingPlayback(8, 3); )
159 DEF_BENCH( return new PictureNestingPlayback(8, 4); )
160 DEF_BENCH( return new PictureNestingPlayback(8, 5); )
161 DEF_BENCH( return new PictureNestingPlayback(8, 6); )
162 DEF_BENCH( return new PictureNestingPlayback(8, 7); )
163 DEF_BENCH( return new PictureNestingPlayback(8, 8); )
OLDNEW
« no previous file with comments | « no previous file | gyp/bench.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698