OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 #include "SampleCode.h" | 8 #include "SampleCode.h" |
| 9 #include "SkBlurMask.h" |
| 10 #include "SkBlurMaskFilter.h" |
9 #include "SkCanvas.h" | 11 #include "SkCanvas.h" |
10 #include "SkParsePath.h" | 12 #include "SkParsePath.h" |
11 #include "SkPath.h" | 13 #include "SkPath.h" |
12 #include "SkRandom.h" | 14 #include "SkRandom.h" |
13 #include "SkView.h" | 15 #include "SkView.h" |
14 | 16 |
15 #include "SkBlurMaskFilter.h" | |
16 | 17 |
17 static void test_huge_stroke(SkCanvas* canvas) { | 18 static void test_huge_stroke(SkCanvas* canvas) { |
18 SkRect srcR = { 0, 0, 72000, 54000 }; | 19 SkRect srcR = { 0, 0, 72000, 54000 }; |
19 SkRect dstR = { 0, 0, 640, 480 }; | 20 SkRect dstR = { 0, 0, 640, 480 }; |
20 | 21 |
21 SkPath path; | 22 SkPath path; |
22 path.moveTo(17600, 8000); | 23 path.moveTo(17600, 8000); |
23 path.lineTo(52800, 8000); | 24 path.lineTo(52800, 8000); |
24 path.lineTo(52800, 41600); | 25 path.lineTo(52800, 41600); |
25 path.lineTo(17600, 41600); | 26 path.lineTo(17600, 41600); |
26 path.close(); | 27 path.close(); |
27 | 28 |
28 SkPaint paint; | 29 SkPaint paint; |
29 paint.setAntiAlias(true); | 30 paint.setAntiAlias(true); |
30 paint.setStrokeWidth(8000); | 31 paint.setStrokeWidth(8000); |
31 paint.setStrokeMiter(10); | 32 paint.setStrokeMiter(10); |
32 paint.setStrokeCap(SkPaint::kButt_Cap); | 33 paint.setStrokeCap(SkPaint::kButt_Cap); |
33 paint.setStrokeJoin(SkPaint::kRound_Join); | 34 paint.setStrokeJoin(SkPaint::kRound_Join); |
34 paint.setStyle(SkPaint::kStroke_Style); | 35 paint.setStyle(SkPaint::kStroke_Style); |
35 | 36 |
36 SkMatrix matrix; | 37 SkMatrix matrix; |
37 matrix.setRectToRect(srcR, dstR, SkMatrix::kCenter_ScaleToFit); | 38 matrix.setRectToRect(srcR, dstR, SkMatrix::kCenter_ScaleToFit); |
38 canvas->concat(matrix); | 39 canvas->concat(matrix); |
39 | 40 |
40 canvas->drawPath(path, paint); | 41 canvas->drawPath(path, paint); |
41 } | 42 } |
42 | 43 |
43 #if 0 | 44 #if 0 |
44 #include "SkBlurMask.h" | |
45 static void test_blur() { | 45 static void test_blur() { |
46 uint8_t cell[9]; | 46 uint8_t cell[9]; |
47 memset(cell, 0xFF, sizeof(cell)); | 47 memset(cell, 0xFF, sizeof(cell)); |
48 SkMask src; | 48 SkMask src; |
49 src.fImage = cell; | 49 src.fImage = cell; |
50 src.fFormat = SkMask::kA8_Format; | 50 src.fFormat = SkMask::kA8_Format; |
51 SkMask dst; | 51 SkMask dst; |
52 | 52 |
53 for (int y = 1; y <= 3; y++) { | 53 for (int y = 1; y <= 3; y++) { |
54 for (int x = 1; x <= 3; x++) { | 54 for (int x = 1; x <= 3; x++) { |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 canvas->translate(10, 30); | 161 canvas->translate(10, 30); |
162 | 162 |
163 static const SkBlurMaskFilter::BlurStyle gStyle[] = { | 163 static const SkBlurMaskFilter::BlurStyle gStyle[] = { |
164 SkBlurMaskFilter::kNormal_BlurStyle, | 164 SkBlurMaskFilter::kNormal_BlurStyle, |
165 SkBlurMaskFilter::kInner_BlurStyle, | 165 SkBlurMaskFilter::kInner_BlurStyle, |
166 SkBlurMaskFilter::kOuter_BlurStyle, | 166 SkBlurMaskFilter::kOuter_BlurStyle, |
167 SkBlurMaskFilter::kSolid_BlurStyle, | 167 SkBlurMaskFilter::kSolid_BlurStyle, |
168 }; | 168 }; |
169 for (int x = 0; x < 5; x++) { | 169 for (int x = 0; x < 5; x++) { |
170 SkMaskFilter* mf; | 170 SkMaskFilter* mf; |
171 SkScalar radius = 4; | 171 SkScalar sigma = SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(
4)); |
172 for (int y = 0; y < 10; y++) { | 172 for (int y = 0; y < 10; y++) { |
173 if (x) { | 173 if (x) { |
174 mf = SkBlurMaskFilter::Create(radius, gStyle[x - 1]); | 174 mf = SkBlurMaskFilter::Create(gStyle[x - 1], sigma); |
175 paint.setMaskFilter(mf)->unref(); | 175 paint.setMaskFilter(mf)->unref(); |
176 } | 176 } |
177 canvas->drawText("Title Bar", 9, x*SkIntToScalar(100), y*SkI
ntToScalar(30), paint); | 177 canvas->drawText("Title Bar", 9, x*SkIntToScalar(100), y*SkI
ntToScalar(30), paint); |
178 radius *= 0.75f; | 178 sigma *= 0.75f; |
179 } | 179 } |
180 | 180 |
181 } | 181 } |
182 return; | 182 return; |
183 } | 183 } |
184 | 184 |
185 paint.setColor(SK_ColorBLUE); | 185 paint.setColor(SK_ColorBLUE); |
186 | 186 |
187 #if 1 | 187 #if 1 |
188 SkPath p; | 188 SkPath p; |
(...skipping 26 matching lines...) Expand all Loading... |
215 return this->INHERITED::onFindClickHandler(x, y, modi); | 215 return this->INHERITED::onFindClickHandler(x, y, modi); |
216 } | 216 } |
217 private: | 217 private: |
218 typedef SampleView INHERITED; | 218 typedef SampleView INHERITED; |
219 }; | 219 }; |
220 | 220 |
221 ////////////////////////////////////////////////////////////////////////////// | 221 ////////////////////////////////////////////////////////////////////////////// |
222 | 222 |
223 static SkView* MyFactory() { return new StrokePathView; } | 223 static SkView* MyFactory() { return new StrokePathView; } |
224 static SkViewRegister reg(MyFactory); | 224 static SkViewRegister reg(MyFactory); |
OLD | NEW |