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 | */ |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 7 | #include "SampleCode.h" |
robertphillips@google.com | b706117 | 2013-09-06 14:16:12 +0000 | [diff] [blame] | 8 | #include "SkBlurMask.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 9 | #include "SkCanvas.h" |
| 10 | #include "SkView.h" |
| 11 | #include "Sk1DPathEffect.h" |
| 12 | #include "Sk2DPathEffect.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 13 | #include "SkBlurMaskFilter.h" |
reed | 0daf5dd | 2016-01-11 12:34:04 -0800 | [diff] [blame] | 14 | #include "SkColorMatrixFilter.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 15 | #include "SkColorPriv.h" |
| 16 | #include "SkCornerPathEffect.h" |
| 17 | #include "SkDashPathEffect.h" |
| 18 | #include "SkDiscretePathEffect.h" |
| 19 | #include "SkEmbossMaskFilter.h" |
commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +0000 | [diff] [blame] | 20 | #include "SkReadBuffer.h" |
| 21 | #include "SkWriteBuffer.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 22 | #include "SkGradientShader.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 23 | #include "SkLayerRasterizer.h" |
| 24 | #include "SkMath.h" |
| 25 | #include "SkPath.h" |
robertphillips@google.com | 770963f | 2014-04-18 18:04:41 +0000 | [diff] [blame] | 26 | #include "SkPictureRecorder.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 27 | #include "SkRegion.h" |
| 28 | #include "SkShader.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 29 | #include "SkCornerPathEffect.h" |
| 30 | #include "SkPathMeasure.h" |
| 31 | #include "SkPicture.h" |
| 32 | #include "SkRandom.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 33 | #include "SkTypeface.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 34 | #include "SkUtils.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 35 | |
| 36 | #include <math.h> |
msarett | d15750c | 2016-03-18 15:48:49 -0700 | [diff] [blame] | 37 | #include "DecodeFile.h" |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 38 | |
commit-bot@chromium.org | f792a1b | 2014-02-26 13:27:37 +0000 | [diff] [blame] | 39 | static void r0(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p) { |
reed | efdfd51 | 2016-04-04 10:02:58 -0700 | [diff] [blame] | 40 | p.setMaskFilter(SkBlurMaskFilter::Make(kNormal_SkBlurStyle, |
| 41 | SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(3)), |
| 42 | SkBlurMaskFilter::kNone_BlurFlag)); |
commit-bot@chromium.org | f792a1b | 2014-02-26 13:27:37 +0000 | [diff] [blame] | 43 | rastBuilder->addLayer(p, SkIntToScalar(3), SkIntToScalar(3)); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 44 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 45 | p.setMaskFilter(nullptr); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 46 | p.setStyle(SkPaint::kStroke_Style); |
| 47 | p.setStrokeWidth(SK_Scalar1); |
commit-bot@chromium.org | f792a1b | 2014-02-26 13:27:37 +0000 | [diff] [blame] | 48 | rastBuilder->addLayer(p); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 49 | |
| 50 | p.setAlpha(0x11); |
| 51 | p.setStyle(SkPaint::kFill_Style); |
reed | 374772b | 2016-10-05 17:33:02 -0700 | [diff] [blame] | 52 | p.setBlendMode(SkBlendMode::kSrc); |
commit-bot@chromium.org | f792a1b | 2014-02-26 13:27:37 +0000 | [diff] [blame] | 53 | rastBuilder->addLayer(p); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 54 | } |
| 55 | |
commit-bot@chromium.org | f792a1b | 2014-02-26 13:27:37 +0000 | [diff] [blame] | 56 | static void r1(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p) { |
| 57 | rastBuilder->addLayer(p); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 58 | |
| 59 | p.setAlpha(0x40); |
reed | 374772b | 2016-10-05 17:33:02 -0700 | [diff] [blame] | 60 | p.setBlendMode(SkBlendMode::kSrc); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 61 | p.setStyle(SkPaint::kStroke_Style); |
| 62 | p.setStrokeWidth(SK_Scalar1*2); |
commit-bot@chromium.org | f792a1b | 2014-02-26 13:27:37 +0000 | [diff] [blame] | 63 | rastBuilder->addLayer(p); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 64 | } |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 65 | |
commit-bot@chromium.org | f792a1b | 2014-02-26 13:27:37 +0000 | [diff] [blame] | 66 | static void r2(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 67 | p.setStyle(SkPaint::kStrokeAndFill_Style); |
| 68 | p.setStrokeWidth(SK_Scalar1*4); |
commit-bot@chromium.org | f792a1b | 2014-02-26 13:27:37 +0000 | [diff] [blame] | 69 | rastBuilder->addLayer(p); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 70 | |
| 71 | p.setStyle(SkPaint::kStroke_Style); |
| 72 | p.setStrokeWidth(SK_Scalar1*3/2); |
reed | 374772b | 2016-10-05 17:33:02 -0700 | [diff] [blame] | 73 | p.setBlendMode(SkBlendMode::kClear); |
commit-bot@chromium.org | f792a1b | 2014-02-26 13:27:37 +0000 | [diff] [blame] | 74 | rastBuilder->addLayer(p); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 75 | } |
| 76 | |
commit-bot@chromium.org | f792a1b | 2014-02-26 13:27:37 +0000 | [diff] [blame] | 77 | static void r3(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 78 | p.setStyle(SkPaint::kStroke_Style); |
| 79 | p.setStrokeWidth(SK_Scalar1*3); |
commit-bot@chromium.org | f792a1b | 2014-02-26 13:27:37 +0000 | [diff] [blame] | 80 | rastBuilder->addLayer(p); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 81 | |
| 82 | p.setAlpha(0x20); |
| 83 | p.setStyle(SkPaint::kFill_Style); |
reed | 374772b | 2016-10-05 17:33:02 -0700 | [diff] [blame] | 84 | p.setBlendMode(SkBlendMode::kSrc); |
commit-bot@chromium.org | f792a1b | 2014-02-26 13:27:37 +0000 | [diff] [blame] | 85 | rastBuilder->addLayer(p); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 86 | } |
| 87 | |
commit-bot@chromium.org | f792a1b | 2014-02-26 13:27:37 +0000 | [diff] [blame] | 88 | static void r4(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 89 | p.setAlpha(0x60); |
commit-bot@chromium.org | f792a1b | 2014-02-26 13:27:37 +0000 | [diff] [blame] | 90 | rastBuilder->addLayer(p, SkIntToScalar(3), SkIntToScalar(3)); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 91 | |
| 92 | p.setAlpha(0xFF); |
reed | 374772b | 2016-10-05 17:33:02 -0700 | [diff] [blame] | 93 | p.setBlendMode(SkBlendMode::kClear); |
commit-bot@chromium.org | f792a1b | 2014-02-26 13:27:37 +0000 | [diff] [blame] | 94 | rastBuilder->addLayer(p, SK_Scalar1*3/2, SK_Scalar1*3/2); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 95 | |
reed | 374772b | 2016-10-05 17:33:02 -0700 | [diff] [blame] | 96 | p.setBlendMode(SkBlendMode::kSrcOver); |
commit-bot@chromium.org | f792a1b | 2014-02-26 13:27:37 +0000 | [diff] [blame] | 97 | rastBuilder->addLayer(p); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 98 | } |
| 99 | |
commit-bot@chromium.org | f792a1b | 2014-02-26 13:27:37 +0000 | [diff] [blame] | 100 | static void r5(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p) { |
| 101 | rastBuilder->addLayer(p); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 102 | |
reed | a439334 | 2016-03-18 11:22:57 -0700 | [diff] [blame] | 103 | p.setPathEffect(SkDiscretePathEffect::Make(SK_Scalar1*4, SK_Scalar1*3)); |
reed | 374772b | 2016-10-05 17:33:02 -0700 | [diff] [blame] | 104 | p.setBlendMode(SkBlendMode::kSrcOut); |
commit-bot@chromium.org | f792a1b | 2014-02-26 13:27:37 +0000 | [diff] [blame] | 105 | rastBuilder->addLayer(p); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 106 | } |
| 107 | |
commit-bot@chromium.org | f792a1b | 2014-02-26 13:27:37 +0000 | [diff] [blame] | 108 | static void r6(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p) { |
| 109 | rastBuilder->addLayer(p); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 110 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 111 | p.setAntiAlias(false); |
commit-bot@chromium.org | f792a1b | 2014-02-26 13:27:37 +0000 | [diff] [blame] | 112 | SkLayerRasterizer::Builder rastBuilder2; |
| 113 | r5(&rastBuilder2, p); |
reed | 7b380d0 | 2016-03-21 13:25:16 -0700 | [diff] [blame] | 114 | p.setRasterizer(rastBuilder2.detach()); |
reed | 374772b | 2016-10-05 17:33:02 -0700 | [diff] [blame] | 115 | p.setBlendMode(SkBlendMode::kClear); |
commit-bot@chromium.org | f792a1b | 2014-02-26 13:27:37 +0000 | [diff] [blame] | 116 | rastBuilder->addLayer(p); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | class Dot2DPathEffect : public Sk2DPathEffect { |
| 120 | public: |
| 121 | Dot2DPathEffect(SkScalar radius, const SkMatrix& matrix) |
| 122 | : Sk2DPathEffect(matrix), fRadius(radius) {} |
| 123 | |
djsollen@google.com | ba28d03 | 2012-03-26 17:57:35 +0000 | [diff] [blame] | 124 | SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(Dot2DPathEffect) |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 125 | |
| 126 | protected: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 127 | void next(const SkPoint& loc, int u, int v, SkPath* dst) const override { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 128 | dst->addCircle(loc.fX, loc.fY, fRadius); |
| 129 | } |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 130 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 131 | void flatten(SkWriteBuffer& buffer) const override { |
djsollen@google.com | 5492424 | 2012-03-29 15:18:04 +0000 | [diff] [blame] | 132 | this->INHERITED::flatten(buffer); |
| 133 | buffer.writeScalar(fRadius); |
| 134 | } |
| 135 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 136 | private: |
| 137 | SkScalar fRadius; |
| 138 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 139 | typedef Sk2DPathEffect INHERITED; |
| 140 | }; |
| 141 | |
commit-bot@chromium.org | f792a1b | 2014-02-26 13:27:37 +0000 | [diff] [blame] | 142 | static void r7(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 143 | SkMatrix lattice; |
| 144 | lattice.setScale(SK_Scalar1*6, SK_Scalar1*6, 0, 0); |
| 145 | lattice.postSkew(SK_Scalar1/3, 0, 0, 0); |
reed | a439334 | 2016-03-18 11:22:57 -0700 | [diff] [blame] | 146 | p.setPathEffect(sk_make_sp<Dot2DPathEffect>(SK_Scalar1*4, lattice)); |
commit-bot@chromium.org | f792a1b | 2014-02-26 13:27:37 +0000 | [diff] [blame] | 147 | rastBuilder->addLayer(p); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 148 | } |
| 149 | |
commit-bot@chromium.org | f792a1b | 2014-02-26 13:27:37 +0000 | [diff] [blame] | 150 | static void r8(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p) { |
| 151 | rastBuilder->addLayer(p); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 152 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 153 | SkMatrix lattice; |
| 154 | lattice.setScale(SK_Scalar1*6, SK_Scalar1*6, 0, 0); |
| 155 | lattice.postSkew(SK_Scalar1/3, 0, 0, 0); |
reed | a439334 | 2016-03-18 11:22:57 -0700 | [diff] [blame] | 156 | p.setPathEffect(sk_make_sp<Dot2DPathEffect>(SK_Scalar1*2, lattice)); |
reed | 374772b | 2016-10-05 17:33:02 -0700 | [diff] [blame] | 157 | p.setBlendMode(SkBlendMode::kClear); |
commit-bot@chromium.org | f792a1b | 2014-02-26 13:27:37 +0000 | [diff] [blame] | 158 | rastBuilder->addLayer(p); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 159 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 160 | p.setPathEffect(nullptr); |
reed | 374772b | 2016-10-05 17:33:02 -0700 | [diff] [blame] | 161 | p.setBlendMode(SkBlendMode::kSrcOver); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 162 | p.setStyle(SkPaint::kStroke_Style); |
| 163 | p.setStrokeWidth(SK_Scalar1); |
commit-bot@chromium.org | f792a1b | 2014-02-26 13:27:37 +0000 | [diff] [blame] | 164 | rastBuilder->addLayer(p); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 165 | } |
| 166 | |
commit-bot@chromium.org | f792a1b | 2014-02-26 13:27:37 +0000 | [diff] [blame] | 167 | static void r9(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p) { |
| 168 | rastBuilder->addLayer(p); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 169 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 170 | SkMatrix lattice; |
| 171 | lattice.setScale(SK_Scalar1, SK_Scalar1*6, 0, 0); |
| 172 | lattice.postRotate(SkIntToScalar(30), 0, 0); |
reed | a439334 | 2016-03-18 11:22:57 -0700 | [diff] [blame] | 173 | p.setPathEffect(SkLine2DPathEffect::Make(SK_Scalar1*2, lattice)); |
reed | 374772b | 2016-10-05 17:33:02 -0700 | [diff] [blame] | 174 | p.setBlendMode(SkBlendMode::kClear); |
commit-bot@chromium.org | f792a1b | 2014-02-26 13:27:37 +0000 | [diff] [blame] | 175 | rastBuilder->addLayer(p); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 176 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 177 | p.setPathEffect(nullptr); |
reed | 374772b | 2016-10-05 17:33:02 -0700 | [diff] [blame] | 178 | p.setBlendMode(SkBlendMode::kSrcOver); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 179 | p.setStyle(SkPaint::kStroke_Style); |
| 180 | p.setStrokeWidth(SK_Scalar1); |
commit-bot@chromium.org | f792a1b | 2014-02-26 13:27:37 +0000 | [diff] [blame] | 181 | rastBuilder->addLayer(p); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 182 | } |
| 183 | |
commit-bot@chromium.org | f792a1b | 2014-02-26 13:27:37 +0000 | [diff] [blame] | 184 | typedef void (*raster_proc)(SkLayerRasterizer::Builder*, SkPaint&); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 185 | |
| 186 | static const raster_proc gRastProcs[] = { |
| 187 | r0, r1, r2, r3, r4, r5, r6, r7, r8, r9 |
| 188 | }; |
| 189 | |
| 190 | static const struct { |
| 191 | SkColor fMul, fAdd; |
| 192 | } gLightingColors[] = { |
| 193 | { 0x808080, 0x800000 }, // general case |
| 194 | { 0x707070, 0x707070 }, // no-pin case |
| 195 | { 0xFFFFFF, 0x800000 }, // just-add case |
| 196 | { 0x808080, 0x000000 }, // just-mul case |
| 197 | { 0xFFFFFF, 0x000000 } // identity case |
| 198 | }; |
| 199 | |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 200 | static void apply_shader(SkPaint* paint, int index) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 201 | raster_proc proc = gRastProcs[index]; |
mike@reedtribe.org | 5fd9243 | 2011-05-05 01:59:48 +0000 | [diff] [blame] | 202 | if (proc) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 203 | SkPaint p; |
commit-bot@chromium.org | f792a1b | 2014-02-26 13:27:37 +0000 | [diff] [blame] | 204 | SkLayerRasterizer::Builder rastBuilder; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 205 | |
| 206 | p.setAntiAlias(true); |
commit-bot@chromium.org | f792a1b | 2014-02-26 13:27:37 +0000 | [diff] [blame] | 207 | proc(&rastBuilder, p); |
reed | 7b380d0 | 2016-03-21 13:25:16 -0700 | [diff] [blame] | 208 | paint->setRasterizer(rastBuilder.detach()); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 209 | } |
| 210 | |
Mike Reed | fd87be8 | 2016-12-07 13:41:57 -0500 | [diff] [blame] | 211 | #ifdef SK_SUPPORT_LEGACY_EMBOSSMASKFILTER |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 212 | SkScalar dir[] = { SK_Scalar1, SK_Scalar1, SK_Scalar1 }; |
reed | efdfd51 | 2016-04-04 10:02:58 -0700 | [diff] [blame] | 213 | paint->setMaskFilter(SkBlurMaskFilter::MakeEmboss( |
robertphillips@google.com | b706117 | 2013-09-06 14:16:12 +0000 | [diff] [blame] | 214 | SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(3)), dir, |
reed | efdfd51 | 2016-04-04 10:02:58 -0700 | [diff] [blame] | 215 | SK_Scalar1/4, SkIntToScalar(4))); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 216 | paint->setColor(SK_ColorBLUE); |
| 217 | #endif |
| 218 | } |
| 219 | |
mike@reedtribe.org | 5fd9243 | 2011-05-05 01:59:48 +0000 | [diff] [blame] | 220 | class DemoView : public SampleView { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 221 | public: |
reed@google.com | 2f3dc9d | 2011-05-02 17:33:45 +0000 | [diff] [blame] | 222 | DemoView() {} |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 223 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 224 | protected: |
| 225 | // overrides from SkEventSink |
mike@reedtribe.org | 5fd9243 | 2011-05-05 01:59:48 +0000 | [diff] [blame] | 226 | virtual bool onQuery(SkEvent* evt) { |
| 227 | if (SampleCode::TitleQ(*evt)) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 228 | SampleCode::TitleR(evt, "Demo"); |
| 229 | return true; |
| 230 | } |
| 231 | return this->INHERITED::onQuery(evt); |
| 232 | } |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 233 | |
mike@reedtribe.org | 5fd9243 | 2011-05-05 01:59:48 +0000 | [diff] [blame] | 234 | virtual bool onClick(Click* click) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 235 | return this->INHERITED::onClick(click); |
| 236 | } |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 237 | |
mike@reedtribe.org | 5fd9243 | 2011-05-05 01:59:48 +0000 | [diff] [blame] | 238 | void makePath(SkPath& path) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 239 | path.addCircle(SkIntToScalar(20), SkIntToScalar(20), SkIntToScalar(20), |
| 240 | SkPath::kCCW_Direction); |
| 241 | for (int index = 0; index < 10; index++) { |
commit-bot@chromium.org | 4b413c8 | 2013-11-25 19:44:07 +0000 | [diff] [blame] | 242 | SkScalar x = (float) cos(index / 10.0f * 2 * 3.1415925358f); |
| 243 | SkScalar y = (float) sin(index / 10.0f * 2 * 3.1415925358f); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 244 | x *= index & 1 ? 7 : 14; |
| 245 | y *= index & 1 ? 7 : 14; |
| 246 | x += SkIntToScalar(20); |
| 247 | y += SkIntToScalar(20); |
| 248 | if (index == 0) |
| 249 | path.moveTo(x, y); |
| 250 | else |
| 251 | path.lineTo(x, y); |
| 252 | } |
| 253 | path.close(); |
| 254 | } |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 255 | |
mike@reedtribe.org | 5fd9243 | 2011-05-05 01:59:48 +0000 | [diff] [blame] | 256 | virtual void onDrawContent(SkCanvas* canvas) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 257 | canvas->save(); |
robertphillips@google.com | 84b18c7 | 2014-04-13 19:09:42 +0000 | [diff] [blame] | 258 | this->drawPicture(canvas, 0); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 259 | canvas->restore(); |
| 260 | |
| 261 | { |
robertphillips@google.com | 84b18c7 | 2014-04-13 19:09:42 +0000 | [diff] [blame] | 262 | SkPictureRecorder recorder; |
| 263 | { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 264 | SkCanvas* record = recorder.beginRecording(320, 480, nullptr, 0); |
robertphillips@google.com | 84b18c7 | 2014-04-13 19:09:42 +0000 | [diff] [blame] | 265 | this->drawPicture(record, 120); |
| 266 | } |
reed | ca2622b | 2016-03-18 07:25:55 -0700 | [diff] [blame] | 267 | sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture()); |
robertphillips@google.com | 84b18c7 | 2014-04-13 19:09:42 +0000 | [diff] [blame] | 268 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 269 | canvas->translate(0, SkIntToScalar(120)); |
| 270 | |
| 271 | SkRect clip; |
| 272 | clip.set(0, 0, SkIntToScalar(160), SkIntToScalar(160)); |
| 273 | do { |
| 274 | canvas->save(); |
| 275 | canvas->clipRect(clip); |
robertphillips | c5ba71d | 2014-09-04 08:42:50 -0700 | [diff] [blame] | 276 | picture->playback(canvas); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 277 | canvas->restore(); |
| 278 | if (clip.fRight < SkIntToScalar(320)) |
| 279 | clip.offset(SkIntToScalar(160), 0); |
| 280 | else if (clip.fBottom < SkIntToScalar(480)) |
| 281 | clip.offset(-SkIntToScalar(320), SkIntToScalar(160)); |
| 282 | else |
| 283 | break; |
| 284 | } while (true); |
| 285 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 286 | } |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 287 | |
mike@reedtribe.org | 5fd9243 | 2011-05-05 01:59:48 +0000 | [diff] [blame] | 288 | void drawPicture(SkCanvas* canvas, int spriteOffset) { |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 289 | SkMatrix matrix; matrix.reset(); |
| 290 | SkPaint paint; |
| 291 | SkPath path; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 292 | SkPoint start = {0, 0}; |
| 293 | SkPoint stop = { SkIntToScalar(40), SkIntToScalar(40) }; |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 294 | SkRect rect = {0, 0, SkIntToScalar(40), SkIntToScalar(40) }; |
| 295 | SkRect rect2 = {0, 0, SkIntToScalar(65), SkIntToScalar(20) }; |
| 296 | SkScalar left = 0, top = 0, x = 0, y = 0; |
reed@google.com | 7fa2a65 | 2014-01-27 13:42:58 +0000 | [diff] [blame] | 297 | int index; |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 298 | |
| 299 | char ascii[] = "ascii..."; |
reed@google.com | 7fa2a65 | 2014-01-27 13:42:58 +0000 | [diff] [blame] | 300 | int asciiLength = sizeof(ascii) - 1; |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 301 | char utf8[] = "utf8" "\xe2\x80\xa6"; |
| 302 | short utf16[] = {'u', 't', 'f', '1', '6', 0x2026 }; |
| 303 | short utf16simple[] = {'u', 't', 'f', '1', '6', '!' }; |
| 304 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 305 | makePath(path); |
| 306 | SkTDArray<SkPoint>(pos); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 307 | pos.setCount(asciiLength); |
| 308 | for (index = 0; index < asciiLength; index++) |
| 309 | pos[index].set(SkIntToScalar((unsigned int)index * 10), |
tomhudson@google.com | ffe39bd | 2012-05-17 15:38:00 +0000 | [diff] [blame] | 310 | SkIntToScalar((unsigned int)index * 2)); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 311 | SkTDArray<SkPoint>(pos2); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 312 | pos2.setCount(asciiLength); |
| 313 | for (index = 0; index < asciiLength; index++) |
| 314 | pos2[index].set(SkIntToScalar((unsigned int)index * 10), |
tomhudson@google.com | ffe39bd | 2012-05-17 15:38:00 +0000 | [diff] [blame] | 315 | SkIntToScalar(20)); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 316 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 317 | // shaders |
senorblanco@chromium.org | 64cc579 | 2011-05-19 19:58:58 +0000 | [diff] [blame] | 318 | SkPoint linearPoints[] = { { 0, 0, }, { SkIntToScalar(40), SkIntToScalar(40) } }; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 319 | SkColor linearColors[] = { SK_ColorRED, SK_ColorBLUE }; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 320 | SkScalar* linearPos = nullptr; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 321 | int linearCount = 2; |
| 322 | SkShader::TileMode linearMode = SkShader::kMirror_TileMode; |
reed | 8a21c9f | 2016-03-08 18:50:00 -0800 | [diff] [blame] | 323 | auto linear = SkGradientShader::MakeLinear(linearPoints, |
commit-bot@chromium.org | 83f23d8 | 2014-05-22 12:27:41 +0000 | [diff] [blame] | 324 | linearColors, linearPos, linearCount, linearMode); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 325 | |
| 326 | SkPoint radialCenter = { SkIntToScalar(25), SkIntToScalar(25) }; |
| 327 | SkScalar radialRadius = SkIntToScalar(25); |
| 328 | SkColor radialColors[] = { SK_ColorGREEN, SK_ColorGRAY, SK_ColorRED }; |
| 329 | SkScalar radialPos[] = { 0, SkIntToScalar(3) / 5, SkIntToScalar(1)}; |
| 330 | int radialCount = 3; |
| 331 | SkShader::TileMode radialMode = SkShader::kRepeat_TileMode; |
reed | 8a21c9f | 2016-03-08 18:50:00 -0800 | [diff] [blame] | 332 | auto radial = SkGradientShader::MakeRadial(radialCenter, |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 333 | radialRadius, radialColors, radialPos, radialCount, |
commit-bot@chromium.org | 83f23d8 | 2014-05-22 12:27:41 +0000 | [diff] [blame] | 334 | radialMode); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 335 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 336 | SkEmbossMaskFilter::Light light; |
| 337 | light.fDirection[0] = SK_Scalar1/2; |
| 338 | light.fDirection[1] = SK_Scalar1/2; |
| 339 | light.fDirection[2] = SK_Scalar1/3; |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 340 | light.fAmbient = 0x48; |
| 341 | light.fSpecular = 0x80; |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 342 | |
reed | d053ce9 | 2016-03-22 10:17:23 -0700 | [diff] [blame] | 343 | auto lightingFilter = SkColorMatrixFilter::MakeLightingFilter( |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 344 | 0xff89bc45, 0xff112233); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 345 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 346 | canvas->save(); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 347 | canvas->translate(SkIntToScalar(0), SkIntToScalar(5)); |
reed@google.com | 9cfc83c | 2013-07-22 17:18:18 +0000 | [diff] [blame] | 348 | paint.setAntiAlias(true); |
reed | 93a1215 | 2015-03-16 10:08:34 -0700 | [diff] [blame] | 349 | paint.setFilterQuality(kLow_SkFilterQuality); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 350 | // !!! draw through a clip |
| 351 | paint.setColor(SK_ColorLTGRAY); |
| 352 | paint.setStyle(SkPaint::kFill_Style); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 353 | SkRect clip = {0, 0, SkIntToScalar(320), SkIntToScalar(120)}; |
| 354 | canvas->clipRect(clip); |
reed | 8a21c9f | 2016-03-08 18:50:00 -0800 | [diff] [blame] | 355 | paint.setShader(SkShader::MakeBitmapShader(fTx, |
| 356 | SkShader::kMirror_TileMode, SkShader::kRepeat_TileMode)); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 357 | canvas->drawPaint(paint); |
| 358 | canvas->save(); |
| 359 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 360 | // line (exercises xfermode, colorShader, colorFilter, filterShader) |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 361 | paint.setColor(SK_ColorGREEN); |
| 362 | paint.setStrokeWidth(SkIntToScalar(10)); |
| 363 | paint.setStyle(SkPaint::kStroke_Style); |
reed | 374772b | 2016-10-05 17:33:02 -0700 | [diff] [blame] | 364 | paint.setBlendMode(SkBlendMode::kXor); |
reed | d053ce9 | 2016-03-22 10:17:23 -0700 | [diff] [blame] | 365 | paint.setColorFilter(lightingFilter); |
Hal Canary | 23e474c | 2017-05-15 13:35:35 -0400 | [diff] [blame] | 366 | canvas->drawLine(start, stop, paint); // should not be green |
reed | 374772b | 2016-10-05 17:33:02 -0700 | [diff] [blame] | 367 | paint.setBlendMode(SkBlendMode::kSrcOver); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 368 | paint.setColorFilter(nullptr); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 369 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 370 | // rectangle |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 371 | paint.setStyle(SkPaint::kFill_Style); |
| 372 | canvas->translate(SkIntToScalar(50), 0); |
| 373 | paint.setColor(SK_ColorYELLOW); |
reed | 8a21c9f | 2016-03-08 18:50:00 -0800 | [diff] [blame] | 374 | paint.setShader(linear); |
reed | a439334 | 2016-03-18 11:22:57 -0700 | [diff] [blame] | 375 | paint.setPathEffect(pathEffectTest()); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 376 | canvas->drawRect(rect, paint); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 377 | paint.setPathEffect(nullptr); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 378 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 379 | // circle w/ emboss & transparent (exercises 3dshader) |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 380 | canvas->translate(SkIntToScalar(50), 0); |
reed | efdfd51 | 2016-04-04 10:02:58 -0700 | [diff] [blame] | 381 | paint.setMaskFilter(SkEmbossMaskFilter::Make( |
| 382 | SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(12)/5), light)); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 383 | canvas->drawOval(rect, paint); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 384 | canvas->translate(SkIntToScalar(10), SkIntToScalar(10)); |
reed | 56263c7 | 2015-06-05 11:31:26 -0700 | [diff] [blame] | 385 | // paint.setShader(transparentShader)->unref(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 386 | canvas->drawOval(rect, paint); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 387 | canvas->translate(0, SkIntToScalar(-10)); |
| 388 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 389 | // path |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 390 | canvas->translate(SkIntToScalar(50), 0); |
| 391 | paint.setColor(SK_ColorRED); |
| 392 | paint.setStyle(SkPaint::kStroke_Style); |
| 393 | paint.setStrokeWidth(SkIntToScalar(5)); |
reed | 8a21c9f | 2016-03-08 18:50:00 -0800 | [diff] [blame] | 394 | paint.setShader(radial); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 395 | paint.setMaskFilter(nullptr); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 396 | canvas->drawPath(path, paint); |
| 397 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 398 | paint.setShader(nullptr); |
reed | 6f45c17 | 2015-11-04 08:34:07 -0800 | [diff] [blame] | 399 | // bitmap |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 400 | canvas->translate(SkIntToScalar(50), 0); |
| 401 | paint.setStyle(SkPaint::kFill_Style); |
| 402 | canvas->drawBitmap(fBug, left, top, &paint); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 403 | |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 404 | canvas->translate(-SkIntToScalar(30), SkIntToScalar(30)); |
reed | 8a21c9f | 2016-03-08 18:50:00 -0800 | [diff] [blame] | 405 | paint.setShader(shaderTest()); // test compose shader |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 406 | canvas->drawRect(rect2, paint); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 407 | paint.setShader(nullptr); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 408 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 409 | canvas->restore(); |
| 410 | // text |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 411 | canvas->translate(0, SkIntToScalar(60)); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 412 | canvas->save(); |
| 413 | paint.setColor(SK_ColorGRAY); |
| 414 | canvas->drawPosText(ascii, asciiLength, pos.begin(), paint); |
| 415 | canvas->drawPosText(ascii, asciiLength, pos2.begin(), paint); |
| 416 | |
| 417 | canvas->translate(SkIntToScalar(50), 0); |
| 418 | paint.setColor(SK_ColorCYAN); |
| 419 | canvas->drawText(utf8, sizeof(utf8) - 1, x, y, paint); |
| 420 | |
| 421 | canvas->translate(SkIntToScalar(30), 0); |
| 422 | paint.setColor(SK_ColorMAGENTA); |
| 423 | paint.setTextEncoding(SkPaint::kUTF16_TextEncoding); |
| 424 | matrix.setTranslate(SkIntToScalar(10), SkIntToScalar(10)); |
| 425 | canvas->drawTextOnPath((void*) utf16, sizeof(utf16), path, &matrix, paint); |
| 426 | canvas->translate(0, SkIntToScalar(20)); |
| 427 | canvas->drawTextOnPath((void*) utf16simple, sizeof(utf16simple), path, &matrix, paint); |
| 428 | canvas->restore(); |
| 429 | |
| 430 | canvas->translate(0, SkIntToScalar(60)); |
| 431 | paint.setTextEncoding(SkPaint::kUTF8_TextEncoding); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 432 | canvas->restore(); |
| 433 | } |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 434 | |
reed@google.com | 4d5c26d | 2013-01-08 16:17:50 +0000 | [diff] [blame] | 435 | virtual SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned modi) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 436 | fClickPt.set(x, y); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 437 | this->inval(nullptr); |
reed@google.com | 4d5c26d | 2013-01-08 16:17:50 +0000 | [diff] [blame] | 438 | return this->INHERITED::onFindClickHandler(x, y, modi); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 439 | } |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 440 | |
reed | a439334 | 2016-03-18 11:22:57 -0700 | [diff] [blame] | 441 | sk_sp<SkPathEffect> pathEffectTest() { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 442 | static const int gXY[] = { 1, 0, 0, -1, 2, -1, 3, 0, 2, 1, 0, 1 }; |
| 443 | SkScalar gPhase = 0; |
| 444 | SkPath path; |
| 445 | path.moveTo(SkIntToScalar(gXY[0]), SkIntToScalar(gXY[1])); |
| 446 | for (unsigned i = 2; i < SK_ARRAY_COUNT(gXY); i += 2) |
| 447 | path.lineTo(SkIntToScalar(gXY[i]), SkIntToScalar(gXY[i+1])); |
| 448 | path.close(); |
| 449 | path.offset(SkIntToScalar(-6), 0); |
reed | a439334 | 2016-03-18 11:22:57 -0700 | [diff] [blame] | 450 | auto outer = SkPath1DPathEffect::Make(path, SkIntToScalar(12), |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 451 | gPhase, SkPath1DPathEffect::kRotate_Style); |
reed | a439334 | 2016-03-18 11:22:57 -0700 | [diff] [blame] | 452 | auto inner = SkDiscretePathEffect::Make(SkIntToScalar(2), |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 453 | SkIntToScalar(1)/10); // SkCornerPathEffect(SkIntToScalar(2)); |
Mike Reed | a07741a | 2017-02-25 22:34:32 -0500 | [diff] [blame] | 454 | return SkPathEffect::MakeCompose(outer, inner); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 455 | } |
reed@google.com | 963a8fa | 2012-05-10 13:04:59 +0000 | [diff] [blame] | 456 | |
reed | 8a21c9f | 2016-03-08 18:50:00 -0800 | [diff] [blame] | 457 | sk_sp<SkShader> shaderTest() { |
senorblanco@chromium.org | 64cc579 | 2011-05-19 19:58:58 +0000 | [diff] [blame] | 458 | SkPoint pts[] = { { 0, 0, }, { SkIntToScalar(100), 0 } }; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 459 | SkColor colors[] = { SK_ColorRED, SK_ColorBLUE }; |
reed | 8a21c9f | 2016-03-08 18:50:00 -0800 | [diff] [blame] | 460 | auto shaderA = SkGradientShader::MakeLinear(pts, colors, nullptr, |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 461 | 2, SkShader::kClamp_TileMode); |
| 462 | pts[1].set(0, SkIntToScalar(100)); |
| 463 | SkColor colors2[] = {SK_ColorBLACK, SkColorSetARGB(0x80, 0, 0, 0)}; |
reed | 8a21c9f | 2016-03-08 18:50:00 -0800 | [diff] [blame] | 464 | auto shaderB = SkGradientShader::MakeLinear(pts, colors2, nullptr, |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 465 | 2, SkShader::kClamp_TileMode); |
reed | cfb6bdf | 2016-03-29 11:32:50 -0700 | [diff] [blame] | 466 | return SkShader::MakeComposeShader(std::move(shaderA), std::move(shaderB), |
Mike Reed | 7d954ad | 2016-10-28 15:42:34 -0400 | [diff] [blame] | 467 | SkBlendMode::kDstIn); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 468 | } |
| 469 | |
| 470 | virtual void startTest() { |
msarett | d15750c | 2016-03-18 15:48:49 -0700 | [diff] [blame] | 471 | decode_file("/Users/caryclark/Desktop/bugcirc.gif", &fBug); |
| 472 | decode_file("/Users/caryclark/Desktop/tbcirc.gif", &fTb); |
| 473 | decode_file("/Users/caryclark/Desktop/05psp04.gif", &fTx); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 474 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 475 | |
mike@reedtribe.org | 5fd9243 | 2011-05-05 01:59:48 +0000 | [diff] [blame] | 476 | void drawRaster(SkCanvas* canvas) { |
senorblanco@chromium.org | 64cc579 | 2011-05-19 19:58:58 +0000 | [diff] [blame] | 477 | for (size_t index = 0; index < SK_ARRAY_COUNT(gRastProcs); index++) |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 478 | drawOneRaster(canvas); |
| 479 | } |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 480 | |
mike@reedtribe.org | 5fd9243 | 2011-05-05 01:59:48 +0000 | [diff] [blame] | 481 | void drawOneRaster(SkCanvas* canvas) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 482 | canvas->save(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 483 | |
| 484 | SkScalar x = SkIntToScalar(20); |
| 485 | SkScalar y = SkIntToScalar(40); |
| 486 | SkPaint paint; |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 487 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 488 | paint.setAntiAlias(true); |
| 489 | paint.setTextSize(SkIntToScalar(48)); |
mboc | ee6a991 | 2016-05-31 11:42:36 -0700 | [diff] [blame] | 490 | paint.setTypeface(SkTypeface::MakeFromName("sans-serif", |
| 491 | SkFontStyle::FromOldStyle(SkTypeface::kBold))); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 492 | |
| 493 | SkString str("GOOGLE"); |
| 494 | |
senorblanco@chromium.org | 64cc579 | 2011-05-19 19:58:58 +0000 | [diff] [blame] | 495 | for (size_t i = 0; i < SK_ARRAY_COUNT(gRastProcs); i++) { |
reed@google.com | 7fa2a65 | 2014-01-27 13:42:58 +0000 | [diff] [blame] | 496 | apply_shader(&paint, (int)i); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 497 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 498 | // paint.setMaskFilter(nullptr); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 499 | // paint.setColor(SK_ColorBLACK); |
| 500 | |
| 501 | #if 01 |
| 502 | int index = i % SK_ARRAY_COUNT(gLightingColors); |
reed | d053ce9 | 2016-03-22 10:17:23 -0700 | [diff] [blame] | 503 | paint.setColorFilter(SkColorMatrixFilter::MakeLightingFilter( |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 504 | gLightingColors[index].fMul, |
reed | d053ce9 | 2016-03-22 10:17:23 -0700 | [diff] [blame] | 505 | gLightingColors[index].fAdd)); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 506 | #endif |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 507 | |
Cary Clark | 2a475ea | 2017-04-28 15:35:12 -0400 | [diff] [blame] | 508 | canvas->drawString(str, x, y, paint); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 509 | SkRect oval = { x, y - SkIntToScalar(40), x + SkIntToScalar(40), y }; |
| 510 | paint.setStyle(SkPaint::kStroke_Style); |
| 511 | canvas->drawOval(oval, paint); |
| 512 | paint.setStyle(SkPaint::kFill_Style); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 513 | |
| 514 | y += paint.getFontSpacing(); |
| 515 | } |
| 516 | |
| 517 | canvas->restore(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 518 | } |
| 519 | |
| 520 | private: |
| 521 | SkPoint fClickPt; |
| 522 | SkBitmap fBug, fTb, fTx; |
mike@reedtribe.org | 5fd9243 | 2011-05-05 01:59:48 +0000 | [diff] [blame] | 523 | typedef SampleView INHERITED; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 524 | }; |
| 525 | |
| 526 | ////////////////////////////////////////////////////////////////////////////// |
| 527 | |
| 528 | static SkView* MyFactory() { return new DemoView; } |
| 529 | static SkViewRegister reg(MyFactory); |