OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 "SkBenchmark.h" | 8 #include "SkBenchmark.h" |
9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkPaint.h" | 10 #include "SkPaint.h" |
11 #include "SkRandom.h" | 11 #include "SkRandom.h" |
12 #include "SkBlurMaskFilter.h" | 12 #include "SkBlurMaskFilter.h" |
13 #include "SkLayerDrawLooper.h" | 13 #include "SkLayerDrawLooper.h" |
14 | 14 |
15 // This bench replicates a problematic use case of a draw looper used | 15 // This bench replicates a problematic use case of a draw looper used |
16 // to create an inner blurred rect | 16 // to create an inner blurred rect |
17 class RectoriBench : public SkBenchmark { | 17 class RectoriBench : public SkBenchmark { |
18 public: | 18 public: |
19 RectoriBench(void* param) : INHERITED(param) {} | 19 RectoriBench(void* param) : INHERITED(param) {} |
20 | 20 |
21 protected: | 21 protected: |
22 | 22 |
23 virtual const char* onGetName() { | 23 virtual const char* onGetName() { |
24 return "rectori"; | 24 return "rectori"; |
25 } | 25 } |
26 | 26 |
27 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { | 27 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
28 SkMWCRandom Random; | 28 SkMWCRandom Random; |
29 | 29 |
30 for (int i = 0; i < N; i++) { | 30 for (int i = 0; i < this->getLoops(); i++) { |
31 SkScalar blurRad = Random.nextRangeScalar(1.5f, 25.0f); | 31 SkScalar blurRad = Random.nextRangeScalar(1.5f, 25.0f); |
32 SkScalar size = Random.nextRangeScalar(20*blurRad, 50*blurRad); | 32 SkScalar size = Random.nextRangeScalar(20*blurRad, 50*blurRad); |
33 | 33 |
34 SkScalar x = Random.nextRangeScalar(0.0f, W - size); | 34 SkScalar x = Random.nextRangeScalar(0.0f, W - size); |
35 SkScalar y = Random.nextRangeScalar(0.0f, H - size); | 35 SkScalar y = Random.nextRangeScalar(0.0f, H - size); |
36 | 36 |
37 SkRect inner = { x, y, x + size, y + size }; | 37 SkRect inner = { x, y, x + size, y + size }; |
38 | 38 |
39 SkRect outer(inner); | 39 SkRect outer(inner); |
40 // outer is always outset either 2x or 4x the blur radius (we go wit
h 2x) | 40 // outer is always outset either 2x or 4x the blur radius (we go wit
h 2x) |
(...skipping 22 matching lines...) Expand all Loading... |
63 canvas->restore(); | 63 canvas->restore(); |
64 } | 64 } |
65 } | 65 } |
66 | 66 |
67 private: | 67 private: |
68 enum { | 68 enum { |
69 W = 640, | 69 W = 640, |
70 H = 480, | 70 H = 480, |
71 }; | 71 }; |
72 | 72 |
73 enum { N = SkBENCHLOOP(100) }; | |
74 | |
75 SkLayerDrawLooper* createLooper(SkScalar xOff, SkScalar radius) { | 73 SkLayerDrawLooper* createLooper(SkScalar xOff, SkScalar radius) { |
76 SkLayerDrawLooper* looper = new SkLayerDrawLooper; | 74 SkLayerDrawLooper* looper = new SkLayerDrawLooper; |
77 | 75 |
78 //----------------------------------------------- | 76 //----------------------------------------------- |
79 SkLayerDrawLooper::LayerInfo info; | 77 SkLayerDrawLooper::LayerInfo info; |
80 | 78 |
81 info.fFlagsMask = 0; | 79 info.fFlagsMask = 0; |
82 // TODO: add a color filter to better match what is seen in the wild | 80 // TODO: add a color filter to better match what is seen in the wild |
83 info.fPaintBits = /* SkLayerDrawLooper::kColorFilter_Bit |*/ | 81 info.fPaintBits = /* SkLayerDrawLooper::kColorFilter_Bit |*/ |
84 SkLayerDrawLooper::kMaskFilter_Bit; | 82 SkLayerDrawLooper::kMaskFilter_Bit; |
(...skipping 14 matching lines...) Expand all Loading... |
99 | 97 |
100 paint = looper->addLayer(info); | 98 paint = looper->addLayer(info); |
101 return looper; | 99 return looper; |
102 } | 100 } |
103 | 101 |
104 typedef SkBenchmark INHERITED; | 102 typedef SkBenchmark INHERITED; |
105 }; | 103 }; |
106 | 104 |
107 | 105 |
108 DEF_BENCH( return SkNEW_ARGS(RectoriBench, (p)); ) | 106 DEF_BENCH( return SkNEW_ARGS(RectoriBench, (p)); ) |
OLD | NEW |