OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 #include "gm.h" | 7 #include "gm.h" |
8 #include "SkCanvas.h" | 8 #include "SkCanvas.h" |
9 #include "SkPaint.h" | 9 #include "SkPaint.h" |
10 #include "Sk1DPathEffect.h" | 10 #include "Sk1DPathEffect.h" |
(...skipping 30 matching lines...) Expand all Loading... |
41 compose_pe(paint); | 41 compose_pe(paint); |
42 } | 42 } |
43 | 43 |
44 static void dash_pe(SkPaint* paint) { | 44 static void dash_pe(SkPaint* paint) { |
45 SkScalar inter[] = { 20, 10, 10, 10 }; | 45 SkScalar inter[] = { 20, 10, 10, 10 }; |
46 paint->setStrokeWidth(12); | 46 paint->setStrokeWidth(12); |
47 paint->setPathEffect(SkDashPathEffect::Make(inter, SK_ARRAY_COUNT(inter), 0)
); | 47 paint->setPathEffect(SkDashPathEffect::Make(inter, SK_ARRAY_COUNT(inter), 0)
); |
48 compose_pe(paint); | 48 compose_pe(paint); |
49 } | 49 } |
50 | 50 |
51 static const int gXY[] = { | 51 constexpr int gXY[] = { |
52 4, 0, 0, -4, 8, -4, 12, 0, 8, 4, 0, 4 | 52 4, 0, 0, -4, 8, -4, 12, 0, 8, 4, 0, 4 |
53 }; | 53 }; |
54 | 54 |
55 static void scale(SkPath* path, SkScalar scale) { | 55 static void scale(SkPath* path, SkScalar scale) { |
56 SkMatrix m; | 56 SkMatrix m; |
57 m.setScale(scale, scale); | 57 m.setScale(scale, scale); |
58 path->transform(m); | 58 path->transform(m); |
59 } | 59 } |
60 | 60 |
61 static void one_d_pe(SkPaint* paint) { | 61 static void one_d_pe(SkPaint* paint) { |
62 SkPath path; | 62 SkPath path; |
63 path.moveTo(SkIntToScalar(gXY[0]), SkIntToScalar(gXY[1])); | 63 path.moveTo(SkIntToScalar(gXY[0]), SkIntToScalar(gXY[1])); |
64 for (unsigned i = 2; i < SK_ARRAY_COUNT(gXY); i += 2) | 64 for (unsigned i = 2; i < SK_ARRAY_COUNT(gXY); i += 2) |
65 path.lineTo(SkIntToScalar(gXY[i]), SkIntToScalar(gXY[i+1])); | 65 path.lineTo(SkIntToScalar(gXY[i]), SkIntToScalar(gXY[i+1])); |
66 path.close(); | 66 path.close(); |
67 path.offset(SkIntToScalar(-6), 0); | 67 path.offset(SkIntToScalar(-6), 0); |
68 scale(&path, 1.5f); | 68 scale(&path, 1.5f); |
69 | 69 |
70 paint->setPathEffect(SkPath1DPathEffect::Make(path, SkIntToScalar(21), 0, | 70 paint->setPathEffect(SkPath1DPathEffect::Make(path, SkIntToScalar(21), 0, |
71 SkPath1DPathEffect::kRotate_St
yle)); | 71 SkPath1DPathEffect::kRotate_St
yle)); |
72 compose_pe(paint); | 72 compose_pe(paint); |
73 } | 73 } |
74 | 74 |
75 typedef void (*PE_Proc)(SkPaint*); | 75 typedef void (*PE_Proc)(SkPaint*); |
76 static const PE_Proc gPE[] = { hair_pe, hair2_pe, stroke_pe, dash_pe, one_d_pe }
; | 76 constexpr PE_Proc gPE[] = { hair_pe, hair2_pe, stroke_pe, dash_pe, one_d_pe }; |
77 | 77 |
78 static void fill_pe(SkPaint* paint) { | 78 static void fill_pe(SkPaint* paint) { |
79 paint->setStyle(SkPaint::kFill_Style); | 79 paint->setStyle(SkPaint::kFill_Style); |
80 paint->setPathEffect(nullptr); | 80 paint->setPathEffect(nullptr); |
81 } | 81 } |
82 | 82 |
83 static void discrete_pe(SkPaint* paint) { | 83 static void discrete_pe(SkPaint* paint) { |
84 paint->setPathEffect(SkDiscretePathEffect::Make(10, 4)); | 84 paint->setPathEffect(SkDiscretePathEffect::Make(10, 4)); |
85 } | 85 } |
86 | 86 |
87 static sk_sp<SkPathEffect> MakeTileEffect() { | 87 static sk_sp<SkPathEffect> MakeTileEffect() { |
88 SkMatrix m; | 88 SkMatrix m; |
89 m.setScale(SkIntToScalar(12), SkIntToScalar(12)); | 89 m.setScale(SkIntToScalar(12), SkIntToScalar(12)); |
90 | 90 |
91 SkPath path; | 91 SkPath path; |
92 path.addCircle(0, 0, SkIntToScalar(5)); | 92 path.addCircle(0, 0, SkIntToScalar(5)); |
93 | 93 |
94 return SkPath2DPathEffect::Make(m, path); | 94 return SkPath2DPathEffect::Make(m, path); |
95 } | 95 } |
96 | 96 |
97 static void tile_pe(SkPaint* paint) { | 97 static void tile_pe(SkPaint* paint) { |
98 paint->setPathEffect(MakeTileEffect()); | 98 paint->setPathEffect(MakeTileEffect()); |
99 } | 99 } |
100 | 100 |
101 static const PE_Proc gPE2[] = { fill_pe, discrete_pe, tile_pe }; | 101 constexpr PE_Proc gPE2[] = { fill_pe, discrete_pe, tile_pe }; |
102 | 102 |
103 class PathEffectGM : public GM { | 103 class PathEffectGM : public GM { |
104 public: | 104 public: |
105 PathEffectGM() {} | 105 PathEffectGM() {} |
106 | 106 |
107 protected: | 107 protected: |
108 | 108 |
109 SkString onShortName() override { | 109 SkString onShortName() override { |
110 return SkString("patheffect"); | 110 return SkString("patheffect"); |
111 } | 111 } |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 private: | 160 private: |
161 typedef GM INHERITED; | 161 typedef GM INHERITED; |
162 }; | 162 }; |
163 | 163 |
164 ////////////////////////////////////////////////////////////////////////////// | 164 ////////////////////////////////////////////////////////////////////////////// |
165 | 165 |
166 static GM* PathEffectFactory(void*) { return new PathEffectGM; } | 166 static GM* PathEffectFactory(void*) { return new PathEffectGM; } |
167 static GMRegistry regPathEffect(PathEffectFactory); | 167 static GMRegistry regPathEffect(PathEffectFactory); |
168 | 168 |
169 } | 169 } |
OLD | NEW |