OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 | 7 |
8 #include "Benchmark.h" | 8 #include "Benchmark.h" |
9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkColor.h" | 10 #include "SkColor.h" |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 pics += this->sierpinsky(c, lvl, paint); | 67 pics += this->sierpinsky(c, lvl, paint); |
68 | 68 |
69 c->translate(1, 0); | 69 c->translate(1, 0); |
70 pics += this->sierpinsky(c, lvl, paint); | 70 pics += this->sierpinsky(c, lvl, paint); |
71 | 71 |
72 c->translate(-0.5, -1); | 72 c->translate(-0.5, -1); |
73 pics += this->sierpinsky(c, lvl, paint); | 73 pics += this->sierpinsky(c, lvl, paint); |
74 c->restore(); | 74 c->restore(); |
75 | 75 |
76 if (recordPicture) { | 76 if (recordPicture) { |
77 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | 77 canvas->drawPicture(recorder.finishRecordingAsPicture()); |
78 canvas->drawPicture(picture); | |
79 } | 78 } |
80 | 79 |
81 return pics; | 80 return pics; |
82 } | 81 } |
83 | 82 |
84 int fMaxLevel; | 83 int fMaxLevel; |
85 int fMaxPictureLevel; | 84 int fMaxPictureLevel; |
86 | 85 |
87 private: | 86 private: |
88 int countPics() const { | 87 int countPics() const { |
(...skipping 29 matching lines...) Expand all Loading... |
118 } | 117 } |
119 | 118 |
120 void onDraw(int loops, SkCanvas*) override { | 119 void onDraw(int loops, SkCanvas*) override { |
121 SkIPoint canvasSize = onGetSize(); | 120 SkIPoint canvasSize = onGetSize(); |
122 SkPictureRecorder recorder; | 121 SkPictureRecorder recorder; |
123 | 122 |
124 for (int i = 0; i < loops; i++) { | 123 for (int i = 0; i < loops; i++) { |
125 SkCanvas* c = recorder.beginRecording(SkIntToScalar(canvasSize.x()), | 124 SkCanvas* c = recorder.beginRecording(SkIntToScalar(canvasSize.x()), |
126 SkIntToScalar(canvasSize.y()))
; | 125 SkIntToScalar(canvasSize.y()))
; |
127 this->doDraw(c); | 126 this->doDraw(c); |
128 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | 127 (void)recorder.finishRecordingAsPicture(); |
129 } | 128 } |
130 } | 129 } |
131 | 130 |
132 private: | 131 private: |
133 typedef PictureNesting INHERITED; | 132 typedef PictureNesting INHERITED; |
134 }; | 133 }; |
135 | 134 |
136 class PictureNestingPlayback : public PictureNesting { | 135 class PictureNestingPlayback : public PictureNesting { |
137 public: | 136 public: |
138 PictureNestingPlayback(int maxLevel, int maxPictureLevel) | 137 PictureNestingPlayback(int maxLevel, int maxPictureLevel) |
139 : INHERITED("playback", maxLevel, maxPictureLevel) { | 138 : INHERITED("playback", maxLevel, maxPictureLevel) { |
140 } | 139 } |
141 protected: | 140 protected: |
142 void onDelayedSetup() override { | 141 void onDelayedSetup() override { |
143 this->INHERITED::onDelayedSetup(); | 142 this->INHERITED::onDelayedSetup(); |
144 | 143 |
145 SkIPoint canvasSize = onGetSize(); | 144 SkIPoint canvasSize = onGetSize(); |
146 SkPictureRecorder recorder; | 145 SkPictureRecorder recorder; |
147 SkCanvas* c = recorder.beginRecording(SkIntToScalar(canvasSize.x()), | 146 SkCanvas* c = recorder.beginRecording(SkIntToScalar(canvasSize.x()), |
148 SkIntToScalar(canvasSize.y())); | 147 SkIntToScalar(canvasSize.y())); |
149 | 148 |
150 this->doDraw(c); | 149 this->doDraw(c); |
151 fPicture.reset(recorder.endRecording()); | 150 fPicture = recorder.finishRecordingAsPicture(); |
152 } | 151 } |
153 | 152 |
154 void onDraw(int loops, SkCanvas* canvas) override { | 153 void onDraw(int loops, SkCanvas* canvas) override { |
155 for (int i = 0; i < loops; i++) { | 154 for (int i = 0; i < loops; i++) { |
156 canvas->drawPicture(fPicture); | 155 canvas->drawPicture(fPicture); |
157 } | 156 } |
158 } | 157 } |
159 | 158 |
160 private: | 159 private: |
161 SkAutoTUnref<SkPicture> fPicture; | 160 sk_sp<SkPicture> fPicture; |
162 | 161 |
163 typedef PictureNesting INHERITED; | 162 typedef PictureNesting INHERITED; |
164 }; | 163 }; |
165 | 164 |
166 DEF_BENCH( return new PictureNestingRecording(8, 0); ) | 165 DEF_BENCH( return new PictureNestingRecording(8, 0); ) |
167 DEF_BENCH( return new PictureNestingRecording(8, 1); ) | 166 DEF_BENCH( return new PictureNestingRecording(8, 1); ) |
168 DEF_BENCH( return new PictureNestingRecording(8, 2); ) | 167 DEF_BENCH( return new PictureNestingRecording(8, 2); ) |
169 DEF_BENCH( return new PictureNestingRecording(8, 3); ) | 168 DEF_BENCH( return new PictureNestingRecording(8, 3); ) |
170 DEF_BENCH( return new PictureNestingRecording(8, 4); ) | 169 DEF_BENCH( return new PictureNestingRecording(8, 4); ) |
171 DEF_BENCH( return new PictureNestingRecording(8, 5); ) | 170 DEF_BENCH( return new PictureNestingRecording(8, 5); ) |
172 DEF_BENCH( return new PictureNestingRecording(8, 6); ) | 171 DEF_BENCH( return new PictureNestingRecording(8, 6); ) |
173 DEF_BENCH( return new PictureNestingRecording(8, 7); ) | 172 DEF_BENCH( return new PictureNestingRecording(8, 7); ) |
174 DEF_BENCH( return new PictureNestingRecording(8, 8); ) | 173 DEF_BENCH( return new PictureNestingRecording(8, 8); ) |
175 | 174 |
176 DEF_BENCH( return new PictureNestingPlayback(8, 0); ) | 175 DEF_BENCH( return new PictureNestingPlayback(8, 0); ) |
177 DEF_BENCH( return new PictureNestingPlayback(8, 1); ) | 176 DEF_BENCH( return new PictureNestingPlayback(8, 1); ) |
178 DEF_BENCH( return new PictureNestingPlayback(8, 2); ) | 177 DEF_BENCH( return new PictureNestingPlayback(8, 2); ) |
179 DEF_BENCH( return new PictureNestingPlayback(8, 3); ) | 178 DEF_BENCH( return new PictureNestingPlayback(8, 3); ) |
180 DEF_BENCH( return new PictureNestingPlayback(8, 4); ) | 179 DEF_BENCH( return new PictureNestingPlayback(8, 4); ) |
181 DEF_BENCH( return new PictureNestingPlayback(8, 5); ) | 180 DEF_BENCH( return new PictureNestingPlayback(8, 5); ) |
182 DEF_BENCH( return new PictureNestingPlayback(8, 6); ) | 181 DEF_BENCH( return new PictureNestingPlayback(8, 6); ) |
183 DEF_BENCH( return new PictureNestingPlayback(8, 7); ) | 182 DEF_BENCH( return new PictureNestingPlayback(8, 7); ) |
184 DEF_BENCH( return new PictureNestingPlayback(8, 8); ) | 183 DEF_BENCH( return new PictureNestingPlayback(8, 8); ) |
OLD | NEW |