OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 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 "gm.h" | 8 #include "gm.h" |
9 #include "SkBlurMaskFilter.h" | 9 #include "SkBlurMaskFilter.h" |
10 #include "SkRRect.h" | 10 #include "SkRRect.h" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 // draw the geometry of the occluding rect | 58 // draw the geometry of the occluding rect |
59 stroke.setColor(strokeColor); | 59 stroke.setColor(strokeColor); |
60 canvas->drawRect(occRect, stroke); | 60 canvas->drawRect(occRect, stroke); |
61 } | 61 } |
62 | 62 |
63 static void draw_45(SkCanvas* canvas, SkRRect::Corner corner, | 63 static void draw_45(SkCanvas* canvas, SkRRect::Corner corner, |
64 SkScalar dist, const SkPoint& center) { | 64 SkScalar dist, const SkPoint& center) { |
65 SkRRect::Corner left = SkRRect::kUpperLeft_Corner, right = SkRRect::kUpperLe
ft_Corner; | 65 SkRRect::Corner left = SkRRect::kUpperLeft_Corner, right = SkRRect::kUpperLe
ft_Corner; |
66 SkVector dir = { 0, 0 }; | 66 SkVector dir = { 0, 0 }; |
67 | 67 |
68 static const SkScalar kSize = 64.0f / SK_ScalarSqrt2; | 68 constexpr SkScalar kSize = 64.0f / SK_ScalarSqrt2; |
69 | 69 |
70 switch (corner) { | 70 switch (corner) { |
71 case SkRRect::kUpperLeft_Corner: | 71 case SkRRect::kUpperLeft_Corner: |
72 left = SkRRect::kUpperRight_Corner; | 72 left = SkRRect::kUpperRight_Corner; |
73 right = SkRRect::kLowerLeft_Corner; | 73 right = SkRRect::kLowerLeft_Corner; |
74 | 74 |
75 dir.set(-SK_ScalarRoot2Over2, -SK_ScalarRoot2Over2); | 75 dir.set(-SK_ScalarRoot2Over2, -SK_ScalarRoot2Over2); |
76 break; | 76 break; |
77 case SkRRect::kUpperRight_Corner: | 77 case SkRRect::kUpperRight_Corner: |
78 left = SkRRect::kUpperLeft_Corner; | 78 left = SkRRect::kUpperLeft_Corner; |
79 right = SkRRect::kLowerRight_Corner; | 79 right = SkRRect::kLowerRight_Corner; |
80 dir.set(SK_ScalarRoot2Over2, -SK_ScalarRoot2Over2); | 80 dir.set(SK_ScalarRoot2Over2, -SK_ScalarRoot2Over2); |
81 break; | 81 break; |
82 case SkRRect::kLowerRight_Corner: | 82 case SkRRect::kLowerRight_Corner: |
83 left = SkRRect::kLowerLeft_Corner; | 83 left = SkRRect::kLowerLeft_Corner; |
84 right = SkRRect::kUpperRight_Corner; | 84 right = SkRRect::kUpperRight_Corner; |
85 dir.set(SK_ScalarRoot2Over2, SK_ScalarRoot2Over2); | 85 dir.set(SK_ScalarRoot2Over2, SK_ScalarRoot2Over2); |
86 break; | 86 break; |
87 case SkRRect::kLowerLeft_Corner: | 87 case SkRRect::kLowerLeft_Corner: |
88 left = SkRRect::kLowerRight_Corner; | 88 left = SkRRect::kLowerRight_Corner; |
89 right = SkRRect::kUpperLeft_Corner; | 89 right = SkRRect::kUpperLeft_Corner; |
90 dir.set(-SK_ScalarRoot2Over2, SK_ScalarRoot2Over2); | 90 dir.set(-SK_ScalarRoot2Over2, SK_ScalarRoot2Over2); |
91 break; | 91 break; |
92 default: | 92 default: |
93 SkFAIL("Invalid shape."); | 93 SkFAIL("Invalid shape."); |
94 } | 94 } |
95 | 95 |
96 SkRect r = SkRect::MakeWH(kSize, kSize); | 96 SkRect r = SkRect::MakeWH(kSize, kSize); |
97 // UL, UR, LR, LL | 97 // UL, UR, LR, LL |
98 SkVector radii[4] = { { 0.0f, 0.0f }, { 0.0f, 0.0f }, { 0.0f, 0.0f }, { 0.0f
, 0.0f } }; | 98 SkVector radii[4] = { { 0.0f, 0.0f }, { 0.0f, 0.0f }, { 0.0f, 0.0f }, { 0.0f
, 0.0f } }; |
99 radii[left] = SkVector::Make(kSize, kSize); | 99 radii[left] = SkVector::Make(kSize, kSize); |
100 radii[right] = SkVector::Make(kSize, kSize); | 100 radii[right] = SkVector::Make(kSize, kSize); |
101 SkRRect rr; | 101 SkRRect rr; |
102 rr.setRectRadii( | 102 rr.setRectRadii( |
103 offset_center_to(r.roundOut(), center.fX + dist*dir.fX, center.fY +
dist*dir.fY), | 103 offset_center_to(r.roundOut(), center.fX + dist*dir.fX, center.fY +
dist*dir.fY), |
104 radii); | 104 radii); |
105 | 105 |
106 SkRRect occRR; | 106 SkRRect occRR; |
107 dist -= 10.0f; | 107 dist -= 10.0f; |
108 occRR.setRectRadii( | 108 occRR.setRectRadii( |
109 offset_center_to(r.roundOut(), center.fX + dist*dir.fX, center.fY +
dist*dir.fY), | 109 offset_center_to(r.roundOut(), center.fX + dist*dir.fX, center.fY +
dist*dir.fY), |
110 radii); | 110 radii); |
111 | 111 |
112 draw_rrect(canvas, rr, occRR); | 112 draw_rrect(canvas, rr, occRR); |
113 } | 113 } |
114 | 114 |
115 static void draw_45_simple(SkCanvas* canvas, const SkVector& v, | 115 static void draw_45_simple(SkCanvas* canvas, const SkVector& v, |
116 SkScalar dist, const SkPoint& center) { | 116 SkScalar dist, const SkPoint& center) { |
117 SkIRect r = SkIRect::MakeWH(64, 64); | 117 SkIRect r = SkIRect::MakeWH(64, 64); |
118 SkRRect rr = SkRRect::MakeRectXY( | 118 SkRRect rr = SkRRect::MakeRectXY( |
119 offset_center_to(r, center.fX + dist*v.fX, center.fY
+ dist*v.fY), | 119 offset_center_to(r, center.fX + dist*v.fX, center.fY
+ dist*v.fY), |
120 8, 8); | 120 8, 8); |
121 | 121 |
122 dist -= 10.0f; | 122 dist -= 10.0f; |
123 SkRRect occRR = SkRRect::MakeRectXY( | 123 SkRRect occRR = SkRRect::MakeRectXY( |
124 offset_center_to(r, center.fX + dist*v.fX, center.fY
+ dist*v.fY), | 124 offset_center_to(r, center.fX + dist*v.fX, center.fY
+ dist*v.fY), |
125 8, 8); | 125 8, 8); |
126 | 126 |
127 draw_rrect(canvas, rr, occRR); | 127 draw_rrect(canvas, rr, occRR); |
128 } | 128 } |
129 | 129 |
130 static void draw_90(SkCanvas* canvas, const SkVector& v, SkScalar dist, const Sk
Point& center) { | 130 static void draw_90(SkCanvas* canvas, const SkVector& v, SkScalar dist, const Sk
Point& center) { |
131 static const int kWidth = 25; | 131 constexpr int kWidth = 25; |
132 | 132 |
133 SkIRect r; | 133 SkIRect r; |
134 if (fabs(v.fX) < fabs(v.fY)) { | 134 if (fabs(v.fX) < fabs(v.fY)) { |
135 r = SkIRect::MakeWH(kWidth, 64); | 135 r = SkIRect::MakeWH(kWidth, 64); |
136 } else { | 136 } else { |
137 r = SkIRect::MakeWH(64, kWidth); | 137 r = SkIRect::MakeWH(64, kWidth); |
138 } | 138 } |
139 SkRRect rr = SkRRect::MakeOval( | 139 SkRRect rr = SkRRect::MakeOval( |
140 offset_center_to(r, center.fX + dist*v.fX, center.fY
+ dist*v.fY)); | 140 offset_center_to(r, center.fX + dist*v.fX, center.fY
+ dist*v.fY)); |
141 | 141 |
142 dist -= 10.0f; | 142 dist -= 10.0f; |
143 SkRRect occRR = SkRRect::MakeOval( | 143 SkRRect occRR = SkRRect::MakeOval( |
144 offset_center_to(r, center.fX + dist*v.fX, center.fY
+ dist*v.fY)); | 144 offset_center_to(r, center.fX + dist*v.fX, center.fY
+ dist*v.fY)); |
145 | 145 |
146 draw_rrect(canvas, rr, occRR); | 146 draw_rrect(canvas, rr, occRR); |
147 } | 147 } |
148 | 148 |
149 static void draw_90_simple(SkCanvas* canvas, const SkVector& v, | 149 static void draw_90_simple(SkCanvas* canvas, const SkVector& v, |
150 SkScalar dist, const SkPoint& center) { | 150 SkScalar dist, const SkPoint& center) { |
151 static const int kLength = 128; | 151 constexpr int kLength = 128; |
152 // The width needs to be larger than 2*3*blurRadii+2*cornerRadius for the an
alytic | 152 // The width needs to be larger than 2*3*blurRadii+2*cornerRadius for the an
alytic |
153 // RRect blur to kick in | 153 // RRect blur to kick in |
154 static const int kWidth = 47; | 154 constexpr int kWidth = 47; |
155 | 155 |
156 SkIRect r; | 156 SkIRect r; |
157 if (fabs(v.fX) < fabs(v.fY)) { | 157 if (fabs(v.fX) < fabs(v.fY)) { |
158 r = SkIRect::MakeWH(kLength, kWidth); | 158 r = SkIRect::MakeWH(kLength, kWidth); |
159 } else { | 159 } else { |
160 r = SkIRect::MakeWH(kWidth, kLength); | 160 r = SkIRect::MakeWH(kWidth, kLength); |
161 } | 161 } |
162 SkRRect rr = SkRRect::MakeRectXY( | 162 SkRRect rr = SkRRect::MakeRectXY( |
163 offset_center_to(r, center.fX + dist*v.fX, center.fY
+ dist*v.fY), | 163 offset_center_to(r, center.fX + dist*v.fX, center.fY
+ dist*v.fY), |
164 8, 8); | 164 8, 8); |
165 | 165 |
166 dist -= 10.0f; | 166 dist -= 10.0f; |
167 SkRRect occRR = SkRRect::MakeRectXY( | 167 SkRRect occRR = SkRRect::MakeRectXY( |
168 offset_center_to(r, center.fX + dist*v.fX, center.fY
+ dist*v.fY), | 168 offset_center_to(r, center.fX + dist*v.fX, center.fY
+ dist*v.fY), |
169 8, 8); | 169 8, 8); |
170 | 170 |
171 draw_rrect(canvas, rr, occRR); | 171 draw_rrect(canvas, rr, occRR); |
172 } | 172 } |
173 | 173 |
174 static void draw_30_60(SkCanvas* canvas, SkRRect::Corner corner, const SkVector&
v, | 174 static void draw_30_60(SkCanvas* canvas, SkRRect::Corner corner, const SkVector&
v, |
175 SkScalar dist, const SkPoint& center) { | 175 SkScalar dist, const SkPoint& center) { |
176 SkRRect::Corner left = SkRRect::kUpperLeft_Corner, right = SkRRect::kUpperLe
ft_Corner; | 176 SkRRect::Corner left = SkRRect::kUpperLeft_Corner, right = SkRRect::kUpperLe
ft_Corner; |
177 | 177 |
178 static const int kLength = 64; | 178 constexpr int kLength = 64; |
179 static const int kWidth = 30; | 179 constexpr int kWidth = 30; |
180 | 180 |
181 switch (corner) { | 181 switch (corner) { |
182 case SkRRect::kUpperLeft_Corner: | 182 case SkRRect::kUpperLeft_Corner: |
183 left = SkRRect::kUpperRight_Corner; | 183 left = SkRRect::kUpperRight_Corner; |
184 right = SkRRect::kLowerLeft_Corner; | 184 right = SkRRect::kLowerLeft_Corner; |
185 break; | 185 break; |
186 case SkRRect::kUpperRight_Corner: | 186 case SkRRect::kUpperRight_Corner: |
187 left = SkRRect::kUpperLeft_Corner; | 187 left = SkRRect::kUpperLeft_Corner; |
188 right = SkRRect::kLowerRight_Corner; | 188 right = SkRRect::kLowerRight_Corner; |
189 break; | 189 break; |
190 case SkRRect::kLowerRight_Corner: | 190 case SkRRect::kLowerRight_Corner: |
191 left = SkRRect::kLowerLeft_Corner; | 191 left = SkRRect::kLowerLeft_Corner; |
192 right = SkRRect::kUpperRight_Corner; | 192 right = SkRRect::kUpperRight_Corner; |
193 break; | 193 break; |
194 case SkRRect::kLowerLeft_Corner: | 194 case SkRRect::kLowerLeft_Corner: |
195 left = SkRRect::kLowerRight_Corner; | 195 left = SkRRect::kLowerRight_Corner; |
196 right = SkRRect::kUpperLeft_Corner; | 196 right = SkRRect::kUpperLeft_Corner; |
197 break; | 197 break; |
198 default: | 198 default: |
199 SkFAIL("Invalid shape."); | 199 SkFAIL("Invalid shape."); |
200 } | 200 } |
201 | 201 |
202 SkIRect r; | 202 SkIRect r; |
203 if (fabs(v.fX) < fabs(v.fY)) { | 203 if (fabs(v.fX) < fabs(v.fY)) { |
204 r = SkIRect::MakeWH(kLength, kWidth); | 204 r = SkIRect::MakeWH(kLength, kWidth); |
205 } else { | 205 } else { |
206 r = SkIRect::MakeWH(kWidth, kLength); | 206 r = SkIRect::MakeWH(kWidth, kLength); |
207 } | 207 } |
208 // UL, UR, LR, LL | 208 // UL, UR, LR, LL |
209 SkVector radii[4] = { { 0.0f, 0.0f }, { 0.0f, 0.0f }, { 0.0f, 0.0f }, { 0.0f
, 0.0f } }; | 209 SkVector radii[4] = { { 0.0f, 0.0f }, { 0.0f, 0.0f }, { 0.0f, 0.0f }, { 0.0f
, 0.0f } }; |
210 radii[left] = SkVector::Make(SkIntToScalar(kWidth), SkIntToScalar(kWidth)); | 210 radii[left] = SkVector::Make(SkIntToScalar(kWidth), SkIntToScalar(kWidth)); |
211 radii[right] = SkVector::Make(SkIntToScalar(kWidth), SkIntToScalar(kWidth)); | 211 radii[right] = SkVector::Make(SkIntToScalar(kWidth), SkIntToScalar(kWidth)); |
212 SkRRect rr; | 212 SkRRect rr; |
213 rr.setRectRadii(offset_center_to(r, center.fX + dist*v.fX, center.fY + dist*
v.fY), radii); | 213 rr.setRectRadii(offset_center_to(r, center.fX + dist*v.fX, center.fY + dist*
v.fY), radii); |
214 | 214 |
215 dist -= 10.0f; | 215 dist -= 10.0f; |
216 SkRRect occRR; | 216 SkRRect occRR; |
217 occRR.setRectRadii(offset_center_to(r, center.fX + dist*v.fX, center.fY + di
st*v.fY), radii); | 217 occRR.setRectRadii(offset_center_to(r, center.fX + dist*v.fX, center.fY + di
st*v.fY), radii); |
218 draw_rrect(canvas, rr, occRR); | 218 draw_rrect(canvas, rr, occRR); |
219 } | 219 } |
220 | 220 |
221 namespace skiagm { | 221 namespace skiagm { |
222 | 222 |
223 class OccludedRRectBlurGM : public GM { | 223 class OccludedRRectBlurGM : public GM { |
224 public: | 224 public: |
225 OccludedRRectBlurGM() { | 225 OccludedRRectBlurGM() { |
226 this->setBGColor(sk_tool_utils::color_to_565(0xFFCCCCCC)); | 226 this->setBGColor(sk_tool_utils::color_to_565(0xFFCCCCCC)); |
227 } | 227 } |
228 | 228 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 draw_45(canvas, SkRRect::kUpperLeft_Corner, 64, center); | 265 draw_45(canvas, SkRRect::kUpperLeft_Corner, 64, center); |
266 draw_45(canvas, SkRRect::kUpperRight_Corner, 64, center); | 266 draw_45(canvas, SkRRect::kUpperRight_Corner, 64, center); |
267 draw_45(canvas, SkRRect::kLowerRight_Corner, 64, center); | 267 draw_45(canvas, SkRRect::kLowerRight_Corner, 64, center); |
268 draw_45(canvas, SkRRect::kLowerLeft_Corner, 64, center); | 268 draw_45(canvas, SkRRect::kLowerLeft_Corner, 64, center); |
269 | 269 |
270 draw_90(canvas, SkVector::Make(-1.0f, 0.0f), 64, center); | 270 draw_90(canvas, SkVector::Make(-1.0f, 0.0f), 64, center); |
271 draw_90(canvas, SkVector::Make(0.0f, -1.0f), 64, center); | 271 draw_90(canvas, SkVector::Make(0.0f, -1.0f), 64, center); |
272 draw_90(canvas, SkVector::Make(1.0f, 0.0f), 64, center); | 272 draw_90(canvas, SkVector::Make(1.0f, 0.0f), 64, center); |
273 draw_90(canvas, SkVector::Make(0.0f, 1.0f), 64, center); | 273 draw_90(canvas, SkVector::Make(0.0f, 1.0f), 64, center); |
274 | 274 |
275 static const SkScalar kRoot3Over2 = 0.8660254037844386f; | 275 constexpr SkScalar kRoot3Over2 = 0.8660254037844386f; |
276 | 276 |
277 draw_30_60(canvas, SkRRect::kLowerLeft_Corner, | 277 draw_30_60(canvas, SkRRect::kLowerLeft_Corner, |
278 SkVector::Make(0.5f, kRoot3Over2), 120, center); | 278 SkVector::Make(0.5f, kRoot3Over2), 120, center); |
279 draw_30_60(canvas, SkRRect::kUpperRight_Corner, | 279 draw_30_60(canvas, SkRRect::kUpperRight_Corner, |
280 SkVector::Make(kRoot3Over2, 0.5f), 120, center); | 280 SkVector::Make(kRoot3Over2, 0.5f), 120, center); |
281 | 281 |
282 draw_30_60(canvas, SkRRect::kUpperLeft_Corner, | 282 draw_30_60(canvas, SkRRect::kUpperLeft_Corner, |
283 SkVector::Make(-0.5f, kRoot3Over2), 120, center); | 283 SkVector::Make(-0.5f, kRoot3Over2), 120, center); |
284 draw_30_60(canvas, SkRRect::kLowerRight_Corner, | 284 draw_30_60(canvas, SkRRect::kLowerRight_Corner, |
285 SkVector::Make(-kRoot3Over2, 0.5f), 120, center); | 285 SkVector::Make(-kRoot3Over2, 0.5f), 120, center); |
(...skipping 17 matching lines...) Expand all Loading... |
303 draw_45_simple(canvas, SkVector::Make(-SK_ScalarRoot2Over2, SK_ScalarRoo
t2Over2), | 303 draw_45_simple(canvas, SkVector::Make(-SK_ScalarRoot2Over2, SK_ScalarRoo
t2Over2), |
304 210, center); | 304 210, center); |
305 | 305 |
306 draw_90_simple(canvas, SkVector::Make(-1.0f, 0.0f), 160, center); | 306 draw_90_simple(canvas, SkVector::Make(-1.0f, 0.0f), 160, center); |
307 draw_90_simple(canvas, SkVector::Make(0.0f, -1.0f), 160, center); | 307 draw_90_simple(canvas, SkVector::Make(0.0f, -1.0f), 160, center); |
308 draw_90_simple(canvas, SkVector::Make(1.0f, 0.0f), 160, center); | 308 draw_90_simple(canvas, SkVector::Make(1.0f, 0.0f), 160, center); |
309 draw_90_simple(canvas, SkVector::Make(0.0f, 1.0f), 160, center); | 309 draw_90_simple(canvas, SkVector::Make(0.0f, 1.0f), 160, center); |
310 } | 310 } |
311 | 311 |
312 private: | 312 private: |
313 static const int kWidth = 440; | 313 static constexpr int kWidth = 440; |
314 static const int kHeight = 440; | 314 static constexpr int kHeight = 440; |
315 | 315 |
316 typedef GM INHERITED; | 316 typedef GM INHERITED; |
317 }; | 317 }; |
318 | 318 |
319 ////////////////////////////////////////////////////////////////////////////// | 319 ////////////////////////////////////////////////////////////////////////////// |
320 | 320 |
321 DEF_GM(return new OccludedRRectBlurGM;) | 321 DEF_GM(return new OccludedRRectBlurGM;) |
322 } | 322 } |
OLD | NEW |