epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2011 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 7 | #include "include/core/SkCanvas.h" |
| 8 | #include "include/core/SkPaint.h" |
| 9 | #include "include/effects/SkColorMatrixFilter.h" |
| 10 | #include "include/effects/SkDiscretePathEffect.h" |
| 11 | #include "include/effects/SkGradientShader.h" |
| 12 | #include "samplecode/Sample.h" |
| 13 | #include "src/core/SkBlurMask.h" |
| 14 | #include "src/effects/SkEmbossMaskFilter.h" |
robertphillips@google.com | b706117 | 2013-09-06 14:16:12 +0000 | [diff] [blame] | 15 | |
reed@android.com | ba974cc | 2009-05-22 13:48:35 +0000 | [diff] [blame] | 16 | |
| 17 | //#define COLOR 0xFFFF8844 |
| 18 | #define COLOR 0xFF888888 |
| 19 | |
sugoi@google.com | 93c7ee3 | 2013-03-12 14:36:57 +0000 | [diff] [blame] | 20 | static void paint_proc0(SkPaint*) { |
reed@android.com | ba974cc | 2009-05-22 13:48:35 +0000 | [diff] [blame] | 21 | } |
| 22 | |
| 23 | static void paint_proc1(SkPaint* paint) { |
Mike Reed | 1be1f8d | 2018-03-14 13:01:17 -0400 | [diff] [blame] | 24 | paint->setMaskFilter(SkMaskFilter::MakeBlur( |
commit-bot@chromium.org | e396455 | 2014-04-28 16:25:35 +0000 | [diff] [blame] | 25 | kNormal_SkBlurStyle, |
reed | efdfd51 | 2016-04-04 10:02:58 -0700 | [diff] [blame] | 26 | SkBlurMask::ConvertRadiusToSigma(2))); |
reed@android.com | ba974cc | 2009-05-22 13:48:35 +0000 | [diff] [blame] | 27 | } |
| 28 | |
| 29 | static void paint_proc2(SkPaint* paint) { |
Ben Wagner | 339b84e | 2017-11-10 16:24:50 -0500 | [diff] [blame] | 30 | paint->setMaskFilter(SkEmbossMaskFilter::Make( |
| 31 | SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(1)), |
| 32 | { { SK_Scalar1, SK_Scalar1, SK_Scalar1 }, 0, 64, 16 })); |
reed@android.com | ba974cc | 2009-05-22 13:48:35 +0000 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | static void paint_proc3(SkPaint* paint) { |
| 36 | SkColor colors[] = { SK_ColorRED, COLOR, SK_ColorBLUE }; |
senorblanco@chromium.org | 64cc579 | 2011-05-19 19:58:58 +0000 | [diff] [blame] | 37 | SkPoint pts[] = { { 3, 0 }, { 7, 5 } }; |
reed | 8a21c9f | 2016-03-08 18:50:00 -0800 | [diff] [blame] | 38 | paint->setShader(SkGradientShader::MakeLinear(pts, colors, nullptr, SK_ARRAY_COUNT(colors), |
Mike Reed | fae8fce | 2019-04-03 10:27:45 -0400 | [diff] [blame] | 39 | SkTileMode::kMirror)); |
reed@android.com | ba974cc | 2009-05-22 13:48:35 +0000 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | static void paint_proc5(SkPaint* paint) { |
| 43 | paint_proc3(paint); |
| 44 | paint_proc2(paint); |
| 45 | } |
| 46 | |
| 47 | typedef void (*PaintProc)(SkPaint*); |
| 48 | const PaintProc gPaintProcs[] = { |
| 49 | paint_proc0, |
| 50 | paint_proc1, |
| 51 | paint_proc2, |
| 52 | paint_proc3, |
| 53 | paint_proc5, |
| 54 | }; |
| 55 | |
| 56 | /////////////////////////////////////////////////////////////////////////////// |
| 57 | |
Ben Wagner | b2c4ea6 | 2018-08-08 11:36:17 -0400 | [diff] [blame] | 58 | class EffectsView : public Sample { |
reed@android.com | ba974cc | 2009-05-22 13:48:35 +0000 | [diff] [blame] | 59 | public: |
| 60 | SkPath fPath; |
| 61 | SkPaint fPaint[SK_ARRAY_COUNT(gPaintProcs)]; |
| 62 | |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 63 | EffectsView() { |
reed@android.com | ba974cc | 2009-05-22 13:48:35 +0000 | [diff] [blame] | 64 | size_t i; |
| 65 | const float pts[] = { |
| 66 | 0, 0, |
| 67 | 10, 0, |
| 68 | 10, 5, |
| 69 | 20, -5, |
| 70 | 10, -15, |
| 71 | 10, -10, |
| 72 | 0, -10 |
| 73 | }; |
| 74 | fPath.moveTo(pts[0], pts[1]); |
| 75 | for (i = 2; i < SK_ARRAY_COUNT(pts); i += 2) { |
| 76 | fPath.lineTo(pts[i], pts[i+1]); |
| 77 | } |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 78 | |
reed@android.com | ba974cc | 2009-05-22 13:48:35 +0000 | [diff] [blame] | 79 | for (i = 0; i < SK_ARRAY_COUNT(gPaintProcs); i++) { |
| 80 | fPaint[i].setAntiAlias(true); |
| 81 | fPaint[i].setColor(COLOR); |
| 82 | gPaintProcs[i](&fPaint[i]); |
| 83 | } |
reed@android.com | 7d970c7 | 2010-04-22 16:07:49 +0000 | [diff] [blame] | 84 | |
mike@reedtribe.org | 5fd9243 | 2011-05-05 01:59:48 +0000 | [diff] [blame] | 85 | this->setBGColor(0xFFDDDDDD); |
reed@android.com | ba974cc | 2009-05-22 13:48:35 +0000 | [diff] [blame] | 86 | } |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 87 | |
reed@android.com | ba974cc | 2009-05-22 13:48:35 +0000 | [diff] [blame] | 88 | protected: |
Hal Canary | 8a02731 | 2019-07-03 10:55:44 -0400 | [diff] [blame] | 89 | virtual SkString name() { return SkString("Effects"); } |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 90 | |
mike@reedtribe.org | 5fd9243 | 2011-05-05 01:59:48 +0000 | [diff] [blame] | 91 | virtual void onDrawContent(SkCanvas* canvas) { |
reed@android.com | ba974cc | 2009-05-22 13:48:35 +0000 | [diff] [blame] | 92 | canvas->scale(3, 3); |
| 93 | canvas->translate(10, 30); |
| 94 | for (size_t i = 0; i < SK_ARRAY_COUNT(fPaint); i++) { |
| 95 | canvas->drawPath(fPath, fPaint[i]); |
| 96 | canvas->translate(32, 0); |
| 97 | } |
| 98 | } |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 99 | |
reed@android.com | ba974cc | 2009-05-22 13:48:35 +0000 | [diff] [blame] | 100 | private: |
Ben Wagner | b2c4ea6 | 2018-08-08 11:36:17 -0400 | [diff] [blame] | 101 | typedef Sample INHERITED; |
reed@android.com | ba974cc | 2009-05-22 13:48:35 +0000 | [diff] [blame] | 102 | }; |
| 103 | |
| 104 | /////////////////////////////////////////////////////////////////////////////// |
| 105 | |
Ben Wagner | b2c4ea6 | 2018-08-08 11:36:17 -0400 | [diff] [blame] | 106 | DEF_SAMPLE( return new EffectsView(); ) |