| 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" |
| 11 #include "Sk2DPathEffect.h" | 11 #include "Sk2DPathEffect.h" |
| 12 #include "SkCornerPathEffect.h" | 12 #include "SkCornerPathEffect.h" |
| 13 #include "SkDashPathEffect.h" | 13 #include "SkDashPathEffect.h" |
| 14 #include "SkDiscretePathEffect.h" | 14 #include "SkDiscretePathEffect.h" |
| 15 | 15 |
| 16 namespace skiagm { | 16 namespace skiagm { |
| 17 | 17 |
| 18 static void compose_pe(SkPaint* paint) { | 18 static void compose_pe(SkPaint* paint) { |
| 19 SkPathEffect* pe = paint->getPathEffect(); | 19 SkPathEffect* pe = paint->getPathEffect(); |
| 20 sk_sp<SkPathEffect> corner = SkCornerPathEffect::Make(25); | 20 SkPathEffect* corner = SkCornerPathEffect::Create(25); |
| 21 sk_sp<SkPathEffect> compose; | 21 SkPathEffect* compose; |
| 22 if (pe) { | 22 if (pe) { |
| 23 compose = SkComposePathEffect::Make(sk_ref_sp(pe), corner); | 23 compose = SkComposePathEffect::Create(pe, corner); |
| 24 corner->unref(); |
| 24 } else { | 25 } else { |
| 25 compose = corner; | 26 compose = corner; |
| 26 } | 27 } |
| 27 paint->setPathEffect(compose); | 28 paint->setPathEffect(compose)->unref(); |
| 28 } | 29 } |
| 29 | 30 |
| 30 static void hair_pe(SkPaint* paint) { | 31 static void hair_pe(SkPaint* paint) { |
| 31 paint->setStrokeWidth(0); | 32 paint->setStrokeWidth(0); |
| 32 } | 33 } |
| 33 | 34 |
| 34 static void hair2_pe(SkPaint* paint) { | 35 static void hair2_pe(SkPaint* paint) { |
| 35 paint->setStrokeWidth(0); | 36 paint->setStrokeWidth(0); |
| 36 compose_pe(paint); | 37 compose_pe(paint); |
| 37 } | 38 } |
| 38 | 39 |
| 39 static void stroke_pe(SkPaint* paint) { | 40 static void stroke_pe(SkPaint* paint) { |
| 40 paint->setStrokeWidth(12); | 41 paint->setStrokeWidth(12); |
| 41 compose_pe(paint); | 42 compose_pe(paint); |
| 42 } | 43 } |
| 43 | 44 |
| 44 static void dash_pe(SkPaint* paint) { | 45 static void dash_pe(SkPaint* paint) { |
| 45 SkScalar inter[] = { 20, 10, 10, 10 }; | 46 SkScalar inter[] = { 20, 10, 10, 10 }; |
| 46 paint->setStrokeWidth(12); | 47 paint->setStrokeWidth(12); |
| 47 paint->setPathEffect(SkDashPathEffect::Make(inter, SK_ARRAY_COUNT(inter), 0)
); | 48 paint->setPathEffect(SkDashPathEffect::Create(inter, SK_ARRAY_COUNT(inter), |
| 49 0))->unref(); |
| 48 compose_pe(paint); | 50 compose_pe(paint); |
| 49 } | 51 } |
| 50 | 52 |
| 51 static const int gXY[] = { | 53 static const int gXY[] = { |
| 52 4, 0, 0, -4, 8, -4, 12, 0, 8, 4, 0, 4 | 54 4, 0, 0, -4, 8, -4, 12, 0, 8, 4, 0, 4 |
| 53 }; | 55 }; |
| 54 | 56 |
| 55 static void scale(SkPath* path, SkScalar scale) { | 57 static void scale(SkPath* path, SkScalar scale) { |
| 56 SkMatrix m; | 58 SkMatrix m; |
| 57 m.setScale(scale, scale); | 59 m.setScale(scale, scale); |
| 58 path->transform(m); | 60 path->transform(m); |
| 59 } | 61 } |
| 60 | 62 |
| 61 static void one_d_pe(SkPaint* paint) { | 63 static void one_d_pe(SkPaint* paint) { |
| 62 SkPath path; | 64 SkPath path; |
| 63 path.moveTo(SkIntToScalar(gXY[0]), SkIntToScalar(gXY[1])); | 65 path.moveTo(SkIntToScalar(gXY[0]), SkIntToScalar(gXY[1])); |
| 64 for (unsigned i = 2; i < SK_ARRAY_COUNT(gXY); i += 2) | 66 for (unsigned i = 2; i < SK_ARRAY_COUNT(gXY); i += 2) |
| 65 path.lineTo(SkIntToScalar(gXY[i]), SkIntToScalar(gXY[i+1])); | 67 path.lineTo(SkIntToScalar(gXY[i]), SkIntToScalar(gXY[i+1])); |
| 66 path.close(); | 68 path.close(); |
| 67 path.offset(SkIntToScalar(-6), 0); | 69 path.offset(SkIntToScalar(-6), 0); |
| 68 scale(&path, 1.5f); | 70 scale(&path, 1.5f); |
| 69 | 71 |
| 70 paint->setPathEffect(SkPath1DPathEffect::Make(path, SkIntToScalar(21), 0, | 72 paint->setPathEffect(SkPath1DPathEffect::Create(path, SkIntToScalar(21), 0, |
| 71 SkPath1DPathEffect::kRotate_St
yle)); | 73 SkPath1DPathEffect::kRotate_Style))->unref(); |
| 72 compose_pe(paint); | 74 compose_pe(paint); |
| 73 } | 75 } |
| 74 | 76 |
| 75 typedef void (*PE_Proc)(SkPaint*); | 77 typedef void (*PE_Proc)(SkPaint*); |
| 76 static const PE_Proc gPE[] = { hair_pe, hair2_pe, stroke_pe, dash_pe, one_d_pe }
; | 78 static const PE_Proc gPE[] = { hair_pe, hair2_pe, stroke_pe, dash_pe, one_d_pe }
; |
| 77 | 79 |
| 78 static void fill_pe(SkPaint* paint) { | 80 static void fill_pe(SkPaint* paint) { |
| 79 paint->setStyle(SkPaint::kFill_Style); | 81 paint->setStyle(SkPaint::kFill_Style); |
| 80 paint->setPathEffect(nullptr); | 82 paint->setPathEffect(nullptr); |
| 81 } | 83 } |
| 82 | 84 |
| 83 static void discrete_pe(SkPaint* paint) { | 85 static void discrete_pe(SkPaint* paint) { |
| 84 paint->setPathEffect(SkDiscretePathEffect::Make(10, 4)); | 86 paint->setPathEffect(SkDiscretePathEffect::Create(10, 4))->unref(); |
| 85 } | 87 } |
| 86 | 88 |
| 87 static sk_sp<SkPathEffect> MakeTileEffect() { | 89 static SkPathEffect* MakeTileEffect() { |
| 88 SkMatrix m; | 90 SkMatrix m; |
| 89 m.setScale(SkIntToScalar(12), SkIntToScalar(12)); | 91 m.setScale(SkIntToScalar(12), SkIntToScalar(12)); |
| 90 | 92 |
| 91 SkPath path; | 93 SkPath path; |
| 92 path.addCircle(0, 0, SkIntToScalar(5)); | 94 path.addCircle(0, 0, SkIntToScalar(5)); |
| 93 | 95 |
| 94 return SkPath2DPathEffect::Make(m, path); | 96 return SkPath2DPathEffect::Create(m, path); |
| 95 } | 97 } |
| 96 | 98 |
| 97 static void tile_pe(SkPaint* paint) { | 99 static void tile_pe(SkPaint* paint) { |
| 98 paint->setPathEffect(MakeTileEffect()); | 100 paint->setPathEffect(MakeTileEffect())->unref(); |
| 99 } | 101 } |
| 100 | 102 |
| 101 static const PE_Proc gPE2[] = { fill_pe, discrete_pe, tile_pe }; | 103 static const PE_Proc gPE2[] = { fill_pe, discrete_pe, tile_pe }; |
| 102 | 104 |
| 103 class PathEffectGM : public GM { | 105 class PathEffectGM : public GM { |
| 104 public: | 106 public: |
| 105 PathEffectGM() {} | 107 PathEffectGM() {} |
| 106 | 108 |
| 107 protected: | 109 protected: |
| 108 | 110 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 private: | 162 private: |
| 161 typedef GM INHERITED; | 163 typedef GM INHERITED; |
| 162 }; | 164 }; |
| 163 | 165 |
| 164 ////////////////////////////////////////////////////////////////////////////// | 166 ////////////////////////////////////////////////////////////////////////////// |
| 165 | 167 |
| 166 static GM* PathEffectFactory(void*) { return new PathEffectGM; } | 168 static GM* PathEffectFactory(void*) { return new PathEffectGM; } |
| 167 static GMRegistry regPathEffect(PathEffectFactory); | 169 static GMRegistry regPathEffect(PathEffectFactory); |
| 168 | 170 |
| 169 } | 171 } |
| OLD | NEW |