| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "SampleCode.h" | 8 #include "SampleCode.h" |
| 9 #include "SkAnimTimer.h" | 9 #include "SkAnimTimer.h" |
| 10 #include "SkView.h" | 10 #include "SkView.h" |
| 11 #include "SkCanvas.h" | 11 #include "SkCanvas.h" |
| 12 #include "SkGradientShader.h" | 12 #include "SkGradientShader.h" |
| 13 #include "SkPath.h" | 13 #include "SkPath.h" |
| 14 #include "SkRegion.h" | 14 #include "SkRegion.h" |
| 15 #include "SkShader.h" | 15 #include "SkShader.h" |
| 16 #include "SkUtils.h" | 16 #include "SkUtils.h" |
| 17 #include "Sk1DPathEffect.h" | 17 #include "Sk1DPathEffect.h" |
| 18 #include "SkCornerPathEffect.h" | 18 #include "SkCornerPathEffect.h" |
| 19 #include "SkPathMeasure.h" | 19 #include "SkPathMeasure.h" |
| 20 #include "SkRandom.h" | 20 #include "SkRandom.h" |
| 21 #include "SkColorPriv.h" | 21 #include "SkColorPriv.h" |
| 22 | 22 |
| 23 #define CORNER_RADIUS 12 | 23 #define CORNER_RADIUS 12 |
| 24 | 24 |
| 25 static const int gXY[] = { | 25 static const int gXY[] = { |
| 26 4, 0, 0, -4, 8, -4, 12, 0, 8, 4, 0, 4 | 26 4, 0, 0, -4, 8, -4, 12, 0, 8, 4, 0, 4 |
| 27 }; | 27 }; |
| 28 | 28 |
| 29 static SkPathEffect* make_pe(int flags, SkScalar phase) { | 29 static sk_sp<SkPathEffect> make_pe(int flags, SkScalar phase) { |
| 30 if (flags == 1) | 30 if (flags == 1) { |
| 31 return SkCornerPathEffect::Create(SkIntToScalar(CORNER_RADIUS)); | 31 return SkCornerPathEffect::Make(SkIntToScalar(CORNER_RADIUS)); |
| 32 } |
| 32 | 33 |
| 33 SkPath path; | 34 SkPath path; |
| 34 path.moveTo(SkIntToScalar(gXY[0]), SkIntToScalar(gXY[1])); | 35 path.moveTo(SkIntToScalar(gXY[0]), SkIntToScalar(gXY[1])); |
| 35 for (unsigned i = 2; i < SK_ARRAY_COUNT(gXY); i += 2) | 36 for (unsigned i = 2; i < SK_ARRAY_COUNT(gXY); i += 2) |
| 36 path.lineTo(SkIntToScalar(gXY[i]), SkIntToScalar(gXY[i+1])); | 37 path.lineTo(SkIntToScalar(gXY[i]), SkIntToScalar(gXY[i+1])); |
| 37 path.close(); | 38 path.close(); |
| 38 path.offset(SkIntToScalar(-6), 0); | 39 path.offset(SkIntToScalar(-6), 0); |
| 39 | 40 |
| 40 SkPathEffect* outer = SkPath1DPathEffect::Create(path, 12, phase, | 41 auto outer = SkPath1DPathEffect::Make(path, 12, phase, SkPath1DPathEffect::k
Rotate_Style); |
| 41 SkPath1DPathEffect::kRotate
_Style); | |
| 42 | 42 |
| 43 if (flags == 2) | 43 if (flags == 2) |
| 44 return outer; | 44 return outer; |
| 45 | 45 |
| 46 SkPathEffect* inner = SkCornerPathEffect::Create(SkIntToScalar(CORNER_RADIUS
)); | 46 auto inner = SkCornerPathEffect::Make(SkIntToScalar(CORNER_RADIUS)); |
| 47 | 47 |
| 48 SkPathEffect* pe = SkComposePathEffect::Create(outer, inner); | 48 return SkComposePathEffect::Make(outer, inner); |
| 49 outer->unref(); | |
| 50 inner->unref(); | |
| 51 return pe; | |
| 52 } | 49 } |
| 53 | 50 |
| 54 static SkPathEffect* make_warp_pe(SkScalar phase) { | 51 static sk_sp<SkPathEffect> make_warp_pe(SkScalar phase) { |
| 55 SkPath path; | 52 SkPath path; |
| 56 path.moveTo(SkIntToScalar(gXY[0]), SkIntToScalar(gXY[1])); | 53 path.moveTo(SkIntToScalar(gXY[0]), SkIntToScalar(gXY[1])); |
| 57 for (unsigned i = 2; i < SK_ARRAY_COUNT(gXY); i += 2) | 54 for (unsigned i = 2; i < SK_ARRAY_COUNT(gXY); i += 2) { |
| 58 path.lineTo(SkIntToScalar(gXY[i]), SkIntToScalar(gXY[i+1])); | 55 path.lineTo(SkIntToScalar(gXY[i]), SkIntToScalar(gXY[i+1])); |
| 56 } |
| 59 path.close(); | 57 path.close(); |
| 60 path.offset(SkIntToScalar(-6), 0); | 58 path.offset(SkIntToScalar(-6), 0); |
| 61 | 59 |
| 62 SkPathEffect* outer = SkPath1DPathEffect::Create( | 60 auto outer = SkPath1DPathEffect::Make( |
| 63 path, 12, phase, SkPath1DPathEffect::kMorph_Style); | 61 path, 12, phase, SkPath1DPathEffect::kMorph_Style); |
| 64 SkPathEffect* inner = SkCornerPathEffect::Create(SkIntToScalar(CORNER_RADIUS
)); | 62 auto inner = SkCornerPathEffect::Make(SkIntToScalar(CORNER_RADIUS)); |
| 65 | 63 |
| 66 SkPathEffect* pe = SkComposePathEffect::Create(outer, inner); | 64 return SkComposePathEffect::Make(outer, inner); |
| 67 outer->unref(); | |
| 68 inner->unref(); | |
| 69 return pe; | |
| 70 } | 65 } |
| 71 | 66 |
| 72 /////////////////////////////////////////////////////////// | 67 /////////////////////////////////////////////////////////// |
| 73 | 68 |
| 74 #include "SkColorFilter.h" | 69 #include "SkColorFilter.h" |
| 75 #include "SkLayerRasterizer.h" | 70 #include "SkLayerRasterizer.h" |
| 76 | 71 |
| 77 class TestRastBuilder : public SkLayerRasterizer::Builder { | 72 class TestRastBuilder : public SkLayerRasterizer::Builder { |
| 78 public: | 73 public: |
| 79 TestRastBuilder() { | 74 TestRastBuilder() { |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 } | 131 } |
| 137 return this->INHERITED::onQuery(evt); | 132 return this->INHERITED::onQuery(evt); |
| 138 } | 133 } |
| 139 | 134 |
| 140 void onDrawContent(SkCanvas* canvas) override { | 135 void onDrawContent(SkCanvas* canvas) override { |
| 141 SkPaint paint; | 136 SkPaint paint; |
| 142 | 137 |
| 143 canvas->translate(0, 50); | 138 canvas->translate(0, 50); |
| 144 | 139 |
| 145 paint.setColor(SK_ColorBLUE); | 140 paint.setColor(SK_ColorBLUE); |
| 146 paint.setPathEffect(make_pe(2, fPhase))->unref(); | 141 paint.setPathEffect(make_pe(2, fPhase)); |
| 147 canvas->drawPath(fPath, paint); | 142 canvas->drawPath(fPath, paint); |
| 148 | 143 |
| 149 canvas->translate(0, 50); | 144 canvas->translate(0, 50); |
| 150 | 145 |
| 151 paint.setARGB(0xFF, 0, 0xBB, 0); | 146 paint.setARGB(0xFF, 0, 0xBB, 0); |
| 152 paint.setPathEffect(make_pe(3, fPhase))->unref(); | 147 paint.setPathEffect(make_pe(3, fPhase)); |
| 153 canvas->drawPath(fPath, paint); | 148 canvas->drawPath(fPath, paint); |
| 154 | 149 |
| 155 canvas->translate(0, 50); | 150 canvas->translate(0, 50); |
| 156 | 151 |
| 157 paint.setARGB(0xFF, 0, 0, 0); | 152 paint.setARGB(0xFF, 0, 0, 0); |
| 158 paint.setPathEffect(make_warp_pe(fPhase))->unref(); | 153 paint.setPathEffect(make_warp_pe(fPhase)); |
| 159 TestRastBuilder testRastBuilder; | 154 TestRastBuilder testRastBuilder; |
| 160 paint.setRasterizer(testRastBuilder.detachRasterizer())->unref(); | 155 paint.setRasterizer(testRastBuilder.detachRasterizer())->unref(); |
| 161 canvas->drawPath(fPath, paint); | 156 canvas->drawPath(fPath, paint); |
| 162 } | 157 } |
| 163 | 158 |
| 164 bool onAnimate(const SkAnimTimer& timer) override { | 159 bool onAnimate(const SkAnimTimer& timer) override { |
| 165 fPhase = timer.scaled(40); | 160 fPhase = timer.scaled(40); |
| 166 return true; | 161 return true; |
| 167 } | 162 } |
| 168 | 163 |
| 169 private: | 164 private: |
| 170 typedef SampleView INHERITED; | 165 typedef SampleView INHERITED; |
| 171 }; | 166 }; |
| 172 | 167 |
| 173 ////////////////////////////////////////////////////////////////////////////// | 168 ////////////////////////////////////////////////////////////////////////////// |
| 174 | 169 |
| 175 static SkView* MyFactory() { return new PathEffectView; } | 170 static SkView* MyFactory() { return new PathEffectView; } |
| 176 static SkViewRegister reg(MyFactory); | 171 static SkViewRegister reg(MyFactory); |
| OLD | NEW |