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" |
11 #include "SkNullCanvas.h" | 11 #include "SkNullCanvas.h" |
12 #include "SkPaint.h" | 12 #include "SkPaint.h" |
13 #include "SkPicture.h" | 13 #include "SkPicture.h" |
14 #include "SkPictureRecorder.h" | 14 #include "SkPictureRecorder.h" |
15 #include "SkString.h" | 15 #include "SkString.h" |
16 | 16 |
17 class PictureNesting : public Benchmark { | 17 class PictureNesting : public Benchmark { |
18 public: | 18 public: |
19 PictureNesting(const char* name, int maxLevel, int maxPictureLevel) | 19 PictureNesting(const char* name, int maxLevel, int maxPictureLevel) |
20 : fMaxLevel(maxLevel) | 20 : fMaxLevel(maxLevel) |
21 , fMaxPictureLevel(maxPictureLevel) { | 21 , fMaxPictureLevel(maxPictureLevel) { |
22 fName.printf("picture_nesting_%s_%d", name, this->countPics()); | 22 fName.printf("picture_nesting_%s_%d", name, this->countPics()); |
23 fPaint.setColor(SK_ColorRED); | 23 fPaint.setColor(SK_ColorRED); |
24 fPaint.setAntiAlias(true); | 24 fPaint.setAntiAlias(true); |
25 fPaint.setStyle(SkPaint::kStroke_Style); | 25 fPaint.setStyle(SkPaint::kStroke_Style); |
26 } | 26 } |
27 | 27 |
28 protected: | 28 protected: |
29 virtual const char* onGetName() SK_OVERRIDE { | 29 const char* onGetName() SK_OVERRIDE { |
30 return fName.c_str(); | 30 return fName.c_str(); |
31 } | 31 } |
32 | 32 |
33 void doDraw(SkCanvas* canvas) { | 33 void doDraw(SkCanvas* canvas) { |
34 SkIPoint canvasSize = onGetSize(); | 34 SkIPoint canvasSize = onGetSize(); |
35 canvas->save(); | 35 canvas->save(); |
36 canvas->scale(SkIntToScalar(canvasSize.x()), SkIntToScalar(canvasSize.y(
))); | 36 canvas->scale(SkIntToScalar(canvasSize.x()), SkIntToScalar(canvasSize.y(
))); |
37 | 37 |
38 SkDEBUGCODE(int pics = ) this->sierpinsky(canvas, 0, fPaint); | 38 SkDEBUGCODE(int pics = ) this->sierpinsky(canvas, 0, fPaint); |
39 SkASSERT(pics == this->countPics()); | 39 SkASSERT(pics == this->countPics()); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 private: | 132 private: |
133 typedef PictureNesting INHERITED; | 133 typedef PictureNesting INHERITED; |
134 }; | 134 }; |
135 | 135 |
136 class PictureNestingPlayback : public PictureNesting { | 136 class PictureNestingPlayback : public PictureNesting { |
137 public: | 137 public: |
138 PictureNestingPlayback(int maxLevel, int maxPictureLevel) | 138 PictureNestingPlayback(int maxLevel, int maxPictureLevel) |
139 : INHERITED("playback", maxLevel, maxPictureLevel) { | 139 : INHERITED("playback", maxLevel, maxPictureLevel) { |
140 } | 140 } |
141 protected: | 141 protected: |
142 virtual void onPreDraw() SK_OVERRIDE { | 142 void onPreDraw() SK_OVERRIDE { |
143 this->INHERITED::onPreDraw(); | 143 this->INHERITED::onPreDraw(); |
144 | 144 |
145 SkIPoint canvasSize = onGetSize(); | 145 SkIPoint canvasSize = onGetSize(); |
146 SkPictureRecorder recorder; | 146 SkPictureRecorder recorder; |
147 SkCanvas* c = recorder.beginRecording(SkIntToScalar(canvasSize.x()), | 147 SkCanvas* c = recorder.beginRecording(SkIntToScalar(canvasSize.x()), |
148 SkIntToScalar(canvasSize.y())); | 148 SkIntToScalar(canvasSize.y())); |
149 | 149 |
150 this->doDraw(c); | 150 this->doDraw(c); |
151 fPicture.reset(recorder.endRecording()); | 151 fPicture.reset(recorder.endRecording()); |
152 } | 152 } |
(...skipping 22 matching lines...) Expand all Loading... |
175 | 175 |
176 DEF_BENCH( return new PictureNestingPlayback(8, 0); ) | 176 DEF_BENCH( return new PictureNestingPlayback(8, 0); ) |
177 DEF_BENCH( return new PictureNestingPlayback(8, 1); ) | 177 DEF_BENCH( return new PictureNestingPlayback(8, 1); ) |
178 DEF_BENCH( return new PictureNestingPlayback(8, 2); ) | 178 DEF_BENCH( return new PictureNestingPlayback(8, 2); ) |
179 DEF_BENCH( return new PictureNestingPlayback(8, 3); ) | 179 DEF_BENCH( return new PictureNestingPlayback(8, 3); ) |
180 DEF_BENCH( return new PictureNestingPlayback(8, 4); ) | 180 DEF_BENCH( return new PictureNestingPlayback(8, 4); ) |
181 DEF_BENCH( return new PictureNestingPlayback(8, 5); ) | 181 DEF_BENCH( return new PictureNestingPlayback(8, 5); ) |
182 DEF_BENCH( return new PictureNestingPlayback(8, 6); ) | 182 DEF_BENCH( return new PictureNestingPlayback(8, 6); ) |
183 DEF_BENCH( return new PictureNestingPlayback(8, 7); ) | 183 DEF_BENCH( return new PictureNestingPlayback(8, 7); ) |
184 DEF_BENCH( return new PictureNestingPlayback(8, 8); ) | 184 DEF_BENCH( return new PictureNestingPlayback(8, 8); ) |
OLD | NEW |