blob: 6d5b7e16b48a8b3bf98d430f8e64fde64cac269e [file] [log] [blame]
Jim Van Verth43475ad2017-01-13 14:37:37 -05001/*
2* Copyright 2017 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*/
7
8#include "SkShadowUtils.h"
Mike Reed8e03f692018-03-09 16:18:56 -05009#include "SkBlurMask.h"
Jim Van Verth43475ad2017-01-13 14:37:37 -050010#include "SkCanvas.h"
Jim Van Verthefe3ded2017-01-30 13:11:45 -050011#include "SkColorFilter.h"
Cary Clarka4083c92017-09-15 11:59:23 -040012#include "SkColorData.h"
Mike Reed4204da22017-05-17 08:53:36 -040013#include "SkDevice.h"
Jim Van Verth1af03d42017-07-31 09:34:58 -040014#include "SkDrawShadowInfo.h"
Cary Clark4dc5a452018-05-21 11:56:57 -040015#include "SkFlattenablePriv.h"
Mike Reed18e75562018-03-12 14:03:47 -040016#include "SkMaskFilter.h"
Jim Van Verthefe3ded2017-01-30 13:11:45 -050017#include "SkPath.h"
Mike Reedb9641bd2017-05-04 10:57:40 -040018#include "SkPM4f.h"
Brian Salomond1ac9822017-02-03 14:25:02 -050019#include "SkRandom.h"
Mike Reed65331592017-05-24 16:45:34 -040020#include "SkRasterPipeline.h"
Brian Salomon5e689522017-02-01 12:07:17 -050021#include "SkResourceCache.h"
Jim Van Verthefe3ded2017-01-30 13:11:45 -050022#include "SkShadowTessellator.h"
Ben Wagner4d1955c2017-03-10 13:08:15 -050023#include "SkString.h"
Brian Salomon5e689522017-02-01 12:07:17 -050024#include "SkTLazy.h"
Brian Salomonaff27a22017-02-06 15:47:44 -050025#include "SkVertices.h"
Mike Klein79aea6a2018-06-11 10:45:26 -040026#include <new>
Brian Salomon5e689522017-02-01 12:07:17 -050027#if SK_SUPPORT_GPU
28#include "GrShape.h"
29#include "effects/GrBlurredEdgeFragmentProcessor.h"
Mike Reed4204da22017-05-17 08:53:36 -040030#endif
Jim Van Verthefe3ded2017-01-30 13:11:45 -050031
32/**
33* Gaussian color filter -- produces a Gaussian ramp based on the color's B value,
34* then blends with the color's G value.
35* Final result is black with alpha of Gaussian(B)*G.
36* The assumption is that the original color's alpha is 1.
37*/
Mike Reed57c2b8b2017-12-31 15:23:54 -050038class SkGaussianColorFilter : public SkColorFilter {
Jim Van Verthefe3ded2017-01-30 13:11:45 -050039public:
40 static sk_sp<SkColorFilter> Make() {
41 return sk_sp<SkColorFilter>(new SkGaussianColorFilter);
42 }
43
Jim Van Verthefe3ded2017-01-30 13:11:45 -050044#if SK_SUPPORT_GPU
Brian Salomon4cbb6e62017-10-25 15:12:19 -040045 std::unique_ptr<GrFragmentProcessor> asFragmentProcessor(
46 GrContext*, const GrColorSpaceInfo&) const override;
Jim Van Verthefe3ded2017-01-30 13:11:45 -050047#endif
48
Jim Van Verthefe3ded2017-01-30 13:11:45 -050049 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkGaussianColorFilter)
50
51protected:
52 void flatten(SkWriteBuffer&) const override {}
Mike Reed65331592017-05-24 16:45:34 -040053 void onAppendStages(SkRasterPipeline* pipeline, SkColorSpace* dstCS, SkArenaAlloc* alloc,
54 bool shaderIsOpaque) const override {
55 pipeline->append(SkRasterPipeline::gauss_a_to_rgba);
56 }
Jim Van Verthefe3ded2017-01-30 13:11:45 -050057private:
58 SkGaussianColorFilter() : INHERITED() {}
59
60 typedef SkColorFilter INHERITED;
61};
62
Jim Van Verthefe3ded2017-01-30 13:11:45 -050063sk_sp<SkFlattenable> SkGaussianColorFilter::CreateProc(SkReadBuffer&) {
64 return Make();
65}
66
Jim Van Verthefe3ded2017-01-30 13:11:45 -050067#if SK_SUPPORT_GPU
Jim Van Verthefe3ded2017-01-30 13:11:45 -050068
Brian Salomonaff329b2017-08-11 09:40:37 -040069std::unique_ptr<GrFragmentProcessor> SkGaussianColorFilter::asFragmentProcessor(
Brian Salomon4cbb6e62017-10-25 15:12:19 -040070 GrContext*, const GrColorSpaceInfo&) const {
Ethan Nicholasaae47c82017-11-10 15:34:03 -050071 return GrBlurredEdgeFragmentProcessor::Make(GrBlurredEdgeFragmentProcessor::Mode::kGaussian);
Jim Van Verthefe3ded2017-01-30 13:11:45 -050072}
73#endif
74
75///////////////////////////////////////////////////////////////////////////////////////////////////
Brian Salomon5e689522017-02-01 12:07:17 -050076
77namespace {
78
Brian Salomonbc9956d2017-02-22 13:49:09 -050079uint64_t resource_cache_shared_id() {
80 return 0x2020776f64616873llu; // 'shadow '
81}
82
Brian Salomond1ac9822017-02-03 14:25:02 -050083/** Factory for an ambient shadow mesh with particular shadow properties. */
Brian Salomon5e689522017-02-01 12:07:17 -050084struct AmbientVerticesFactory {
Jim Van Verthb4366552017-03-27 14:25:29 -040085 SkScalar fOccluderHeight = SK_ScalarNaN; // NaN so that isCompatible will fail until init'ed.
Brian Salomon5e689522017-02-01 12:07:17 -050086 bool fTransparent;
Jim Van Verth8793e382017-05-22 15:52:21 -040087 SkVector fOffset;
Brian Salomon5e689522017-02-01 12:07:17 -050088
Brian Salomond1ac9822017-02-03 14:25:02 -050089 bool isCompatible(const AmbientVerticesFactory& that, SkVector* translate) const {
Jim Van Verth060d9822017-05-04 09:58:17 -040090 if (fOccluderHeight != that.fOccluderHeight || fTransparent != that.fTransparent) {
Brian Salomond1ac9822017-02-03 14:25:02 -050091 return false;
92 }
Jim Van Verth8793e382017-05-22 15:52:21 -040093 *translate = that.fOffset;
Brian Salomond1ac9822017-02-03 14:25:02 -050094 return true;
Brian Salomon5e689522017-02-01 12:07:17 -050095 }
Brian Salomon5e689522017-02-01 12:07:17 -050096
Jim Van Verth8793e382017-05-22 15:52:21 -040097 sk_sp<SkVertices> makeVertices(const SkPath& path, const SkMatrix& ctm,
98 SkVector* translate) const {
Jim Van Verthe308a122017-05-08 14:19:30 -040099 SkPoint3 zParams = SkPoint3::Make(0, 0, fOccluderHeight);
Jim Van Verth8793e382017-05-22 15:52:21 -0400100 // pick a canonical place to generate shadow
101 SkMatrix noTrans(ctm);
102 if (!ctm.hasPerspective()) {
103 noTrans[SkMatrix::kMTransX] = 0;
104 noTrans[SkMatrix::kMTransY] = 0;
105 }
106 *translate = fOffset;
107 return SkShadowTessellator::MakeAmbient(path, noTrans, zParams, fTransparent);
Brian Salomon5e689522017-02-01 12:07:17 -0500108 }
109};
110
Brian Salomond1ac9822017-02-03 14:25:02 -0500111/** Factory for an spot shadow mesh with particular shadow properties. */
Brian Salomon5e689522017-02-01 12:07:17 -0500112struct SpotVerticesFactory {
Brian Salomond1ac9822017-02-03 14:25:02 -0500113 enum class OccluderType {
Jim Van Verth8793e382017-05-22 15:52:21 -0400114 // The umbra cannot be dropped out because either the occluder is not opaque,
115 // or the center of the umbra is visible.
Brian Salomond1ac9822017-02-03 14:25:02 -0500116 kTransparent,
117 // The umbra can be dropped where it is occluded.
Jim Van Verth78c8f302017-05-15 10:44:22 -0400118 kOpaquePartialUmbra,
Brian Salomond1ac9822017-02-03 14:25:02 -0500119 // It is known that the entire umbra is occluded.
Jim Van Verth78c8f302017-05-15 10:44:22 -0400120 kOpaqueNoUmbra
Brian Salomond1ac9822017-02-03 14:25:02 -0500121 };
122
Brian Salomon5e689522017-02-01 12:07:17 -0500123 SkVector fOffset;
Jim Van Verth8793e382017-05-22 15:52:21 -0400124 SkPoint fLocalCenter;
Jim Van Verthb4366552017-03-27 14:25:29 -0400125 SkScalar fOccluderHeight = SK_ScalarNaN; // NaN so that isCompatible will fail until init'ed.
126 SkPoint3 fDevLightPos;
127 SkScalar fLightRadius;
Brian Salomond1ac9822017-02-03 14:25:02 -0500128 OccluderType fOccluderType;
Brian Salomon5e689522017-02-01 12:07:17 -0500129
Brian Salomond1ac9822017-02-03 14:25:02 -0500130 bool isCompatible(const SpotVerticesFactory& that, SkVector* translate) const {
Jim Van Verthb4366552017-03-27 14:25:29 -0400131 if (fOccluderHeight != that.fOccluderHeight || fDevLightPos.fZ != that.fDevLightPos.fZ ||
Jim Van Verth060d9822017-05-04 09:58:17 -0400132 fLightRadius != that.fLightRadius || fOccluderType != that.fOccluderType) {
Brian Salomond1ac9822017-02-03 14:25:02 -0500133 return false;
134 }
135 switch (fOccluderType) {
136 case OccluderType::kTransparent:
Jim Van Verth78c8f302017-05-15 10:44:22 -0400137 case OccluderType::kOpaqueNoUmbra:
Brian Salomond1ac9822017-02-03 14:25:02 -0500138 // 'this' and 'that' will either both have no umbra removed or both have all the
139 // umbra removed.
Jim Van Verth8793e382017-05-22 15:52:21 -0400140 *translate = that.fOffset;
Brian Salomond1ac9822017-02-03 14:25:02 -0500141 return true;
Jim Van Verth78c8f302017-05-15 10:44:22 -0400142 case OccluderType::kOpaquePartialUmbra:
Brian Salomond1ac9822017-02-03 14:25:02 -0500143 // In this case we partially remove the umbra differently for 'this' and 'that'
144 // if the offsets don't match.
145 if (fOffset == that.fOffset) {
146 translate->set(0, 0);
147 return true;
148 }
149 return false;
150 }
Ben Wagnerb4aab9a2017-08-16 10:53:04 -0400151 SK_ABORT("Uninitialized occluder type?");
Brian Salomond1ac9822017-02-03 14:25:02 -0500152 return false;
Brian Salomon5e689522017-02-01 12:07:17 -0500153 }
Brian Salomon5e689522017-02-01 12:07:17 -0500154
Jim Van Verth8793e382017-05-22 15:52:21 -0400155 sk_sp<SkVertices> makeVertices(const SkPath& path, const SkMatrix& ctm,
156 SkVector* translate) const {
Brian Salomond1ac9822017-02-03 14:25:02 -0500157 bool transparent = OccluderType::kTransparent == fOccluderType;
Jim Van Verthe308a122017-05-08 14:19:30 -0400158 SkPoint3 zParams = SkPoint3::Make(0, 0, fOccluderHeight);
Jim Van Verth8793e382017-05-22 15:52:21 -0400159 if (ctm.hasPerspective() || OccluderType::kOpaquePartialUmbra == fOccluderType) {
160 translate->set(0, 0);
161 return SkShadowTessellator::MakeSpot(path, ctm, zParams,
162 fDevLightPos, fLightRadius, transparent);
163 } else {
164 // pick a canonical place to generate shadow, with light centered over path
165 SkMatrix noTrans(ctm);
166 noTrans[SkMatrix::kMTransX] = 0;
167 noTrans[SkMatrix::kMTransY] = 0;
168 SkPoint devCenter(fLocalCenter);
169 noTrans.mapPoints(&devCenter, 1);
170 SkPoint3 centerLightPos = SkPoint3::Make(devCenter.fX, devCenter.fY, fDevLightPos.fZ);
171 *translate = fOffset;
172 return SkShadowTessellator::MakeSpot(path, noTrans, zParams,
173 centerLightPos, fLightRadius, transparent);
174 }
Brian Salomon5e689522017-02-01 12:07:17 -0500175 }
176};
177
178/**
Brian Salomond1ac9822017-02-03 14:25:02 -0500179 * This manages a set of tessellations for a given shape in the cache. Because SkResourceCache
180 * records are immutable this is not itself a Rec. When we need to update it we return this on
Jim Van Vertheb63eb72017-05-23 09:40:02 -0400181 * the FindVisitor and let the cache destroy the Rec. We'll update the tessellations and then add
Brian Salomond1ac9822017-02-03 14:25:02 -0500182 * a new Rec with an adjusted size for any deletions/additions.
Brian Salomon5e689522017-02-01 12:07:17 -0500183 */
Brian Salomond1ac9822017-02-03 14:25:02 -0500184class CachedTessellations : public SkRefCnt {
Brian Salomon5e689522017-02-01 12:07:17 -0500185public:
Brian Salomond1ac9822017-02-03 14:25:02 -0500186 size_t size() const { return fAmbientSet.size() + fSpotSet.size(); }
187
Brian Salomonaff27a22017-02-06 15:47:44 -0500188 sk_sp<SkVertices> find(const AmbientVerticesFactory& ambient, const SkMatrix& matrix,
189 SkVector* translate) const {
Brian Salomond1ac9822017-02-03 14:25:02 -0500190 return fAmbientSet.find(ambient, matrix, translate);
191 }
192
Brian Salomonaff27a22017-02-06 15:47:44 -0500193 sk_sp<SkVertices> add(const SkPath& devPath, const AmbientVerticesFactory& ambient,
Jim Van Verth8793e382017-05-22 15:52:21 -0400194 const SkMatrix& matrix, SkVector* translate) {
195 return fAmbientSet.add(devPath, ambient, matrix, translate);
Brian Salomond1ac9822017-02-03 14:25:02 -0500196 }
197
Brian Salomonaff27a22017-02-06 15:47:44 -0500198 sk_sp<SkVertices> find(const SpotVerticesFactory& spot, const SkMatrix& matrix,
199 SkVector* translate) const {
Brian Salomond1ac9822017-02-03 14:25:02 -0500200 return fSpotSet.find(spot, matrix, translate);
201 }
202
Brian Salomonaff27a22017-02-06 15:47:44 -0500203 sk_sp<SkVertices> add(const SkPath& devPath, const SpotVerticesFactory& spot,
Jim Van Verth8793e382017-05-22 15:52:21 -0400204 const SkMatrix& matrix, SkVector* translate) {
205 return fSpotSet.add(devPath, spot, matrix, translate);
Brian Salomond1ac9822017-02-03 14:25:02 -0500206 }
207
208private:
209 template <typename FACTORY, int MAX_ENTRIES>
210 class Set {
211 public:
212 size_t size() const { return fSize; }
213
Brian Salomonaff27a22017-02-06 15:47:44 -0500214 sk_sp<SkVertices> find(const FACTORY& factory, const SkMatrix& matrix,
215 SkVector* translate) const {
Brian Salomond1ac9822017-02-03 14:25:02 -0500216 for (int i = 0; i < MAX_ENTRIES; ++i) {
217 if (fEntries[i].fFactory.isCompatible(factory, translate)) {
218 const SkMatrix& m = fEntries[i].fMatrix;
219 if (matrix.hasPerspective() || m.hasPerspective()) {
220 if (matrix != fEntries[i].fMatrix) {
221 continue;
222 }
223 } else if (matrix.getScaleX() != m.getScaleX() ||
224 matrix.getSkewX() != m.getSkewX() ||
225 matrix.getScaleY() != m.getScaleY() ||
226 matrix.getSkewY() != m.getSkewY()) {
227 continue;
228 }
Brian Salomond1ac9822017-02-03 14:25:02 -0500229 return fEntries[i].fVertices;
230 }
231 }
232 return nullptr;
233 }
234
Jim Van Verth8793e382017-05-22 15:52:21 -0400235 sk_sp<SkVertices> add(const SkPath& path, const FACTORY& factory, const SkMatrix& matrix,
236 SkVector* translate) {
237 sk_sp<SkVertices> vertices = factory.makeVertices(path, matrix, translate);
Brian Salomond1ac9822017-02-03 14:25:02 -0500238 if (!vertices) {
239 return nullptr;
240 }
241 int i;
242 if (fCount < MAX_ENTRIES) {
243 i = fCount++;
244 } else {
Jim Van Vertheb63eb72017-05-23 09:40:02 -0400245 i = fRandom.nextULessThan(MAX_ENTRIES);
Mike Reedaa9e3322017-03-16 14:38:48 -0400246 fSize -= fEntries[i].fVertices->approximateSize();
Brian Salomond1ac9822017-02-03 14:25:02 -0500247 }
248 fEntries[i].fFactory = factory;
249 fEntries[i].fVertices = vertices;
250 fEntries[i].fMatrix = matrix;
Mike Reedaa9e3322017-03-16 14:38:48 -0400251 fSize += vertices->approximateSize();
Brian Salomond1ac9822017-02-03 14:25:02 -0500252 return vertices;
253 }
254
255 private:
256 struct Entry {
257 FACTORY fFactory;
Brian Salomonaff27a22017-02-06 15:47:44 -0500258 sk_sp<SkVertices> fVertices;
Brian Salomond1ac9822017-02-03 14:25:02 -0500259 SkMatrix fMatrix;
260 };
261 Entry fEntries[MAX_ENTRIES];
262 int fCount = 0;
263 size_t fSize = 0;
Jim Van Vertheb63eb72017-05-23 09:40:02 -0400264 SkRandom fRandom;
Brian Salomond1ac9822017-02-03 14:25:02 -0500265 };
266
267 Set<AmbientVerticesFactory, 4> fAmbientSet;
268 Set<SpotVerticesFactory, 4> fSpotSet;
Brian Salomond1ac9822017-02-03 14:25:02 -0500269};
270
Brian Salomond1ac9822017-02-03 14:25:02 -0500271/**
272 * A record of shadow vertices stored in SkResourceCache of CachedTessellations for a particular
273 * path. The key represents the path's geometry and not any shadow params.
274 */
275class CachedTessellationsRec : public SkResourceCache::Rec {
276public:
277 CachedTessellationsRec(const SkResourceCache::Key& key,
278 sk_sp<CachedTessellations> tessellations)
279 : fTessellations(std::move(tessellations)) {
Brian Salomon5e689522017-02-01 12:07:17 -0500280 fKey.reset(new uint8_t[key.size()]);
281 memcpy(fKey.get(), &key, key.size());
282 }
283
284 const Key& getKey() const override {
285 return *reinterpret_cast<SkResourceCache::Key*>(fKey.get());
286 }
Brian Salomon5e689522017-02-01 12:07:17 -0500287
Brian Salomond1ac9822017-02-03 14:25:02 -0500288 size_t bytesUsed() const override { return fTessellations->size(); }
Brian Salomon5e689522017-02-01 12:07:17 -0500289
Brian Salomond1ac9822017-02-03 14:25:02 -0500290 const char* getCategory() const override { return "tessellated shadow masks"; }
Brian Salomon5e689522017-02-01 12:07:17 -0500291
Brian Salomond1ac9822017-02-03 14:25:02 -0500292 sk_sp<CachedTessellations> refTessellations() const { return fTessellations; }
Brian Salomon5e689522017-02-01 12:07:17 -0500293
Brian Salomond1ac9822017-02-03 14:25:02 -0500294 template <typename FACTORY>
Brian Salomonaff27a22017-02-06 15:47:44 -0500295 sk_sp<SkVertices> find(const FACTORY& factory, const SkMatrix& matrix,
296 SkVector* translate) const {
Brian Salomond1ac9822017-02-03 14:25:02 -0500297 return fTessellations->find(factory, matrix, translate);
298 }
Brian Salomon5e689522017-02-01 12:07:17 -0500299
300private:
301 std::unique_ptr<uint8_t[]> fKey;
Brian Salomond1ac9822017-02-03 14:25:02 -0500302 sk_sp<CachedTessellations> fTessellations;
Brian Salomon5e689522017-02-01 12:07:17 -0500303};
304
305/**
306 * Used by FindVisitor to determine whether a cache entry can be reused and if so returns the
Brian Salomond1ac9822017-02-03 14:25:02 -0500307 * vertices and a translation vector. If the CachedTessellations does not contain a suitable
308 * mesh then we inform SkResourceCache to destroy the Rec and we return the CachedTessellations
309 * to the caller. The caller will update it and reinsert it back into the cache.
Brian Salomon5e689522017-02-01 12:07:17 -0500310 */
311template <typename FACTORY>
312struct FindContext {
313 FindContext(const SkMatrix* viewMatrix, const FACTORY* factory)
314 : fViewMatrix(viewMatrix), fFactory(factory) {}
Brian Salomond1ac9822017-02-03 14:25:02 -0500315 const SkMatrix* const fViewMatrix;
316 // If this is valid after Find is called then we found the vertices and they should be drawn
317 // with fTranslate applied.
Brian Salomonaff27a22017-02-06 15:47:44 -0500318 sk_sp<SkVertices> fVertices;
Brian Salomond1ac9822017-02-03 14:25:02 -0500319 SkVector fTranslate = {0, 0};
320
321 // If this is valid after Find then the caller should add the vertices to the tessellation set
322 // and create a new CachedTessellationsRec and insert it into SkResourceCache.
323 sk_sp<CachedTessellations> fTessellationsOnFailure;
324
Brian Salomon5e689522017-02-01 12:07:17 -0500325 const FACTORY* fFactory;
326};
327
328/**
329 * Function called by SkResourceCache when a matching cache key is found. The FACTORY and matrix of
330 * the FindContext are used to determine if the vertices are reusable. If so the vertices and
331 * necessary translation vector are set on the FindContext.
332 */
333template <typename FACTORY>
334bool FindVisitor(const SkResourceCache::Rec& baseRec, void* ctx) {
335 FindContext<FACTORY>* findContext = (FindContext<FACTORY>*)ctx;
Brian Salomond1ac9822017-02-03 14:25:02 -0500336 const CachedTessellationsRec& rec = static_cast<const CachedTessellationsRec&>(baseRec);
337 findContext->fVertices =
338 rec.find(*findContext->fFactory, *findContext->fViewMatrix, &findContext->fTranslate);
339 if (findContext->fVertices) {
340 return true;
Brian Salomon5e689522017-02-01 12:07:17 -0500341 }
Brian Salomond1ac9822017-02-03 14:25:02 -0500342 // We ref the tessellations and let the cache destroy the Rec. Once the tessellations have been
343 // manipulated we will add a new Rec.
344 findContext->fTessellationsOnFailure = rec.refTessellations();
345 return false;
Brian Salomon5e689522017-02-01 12:07:17 -0500346}
347
348class ShadowedPath {
349public:
350 ShadowedPath(const SkPath* path, const SkMatrix* viewMatrix)
Jim Van Vertha84898d2017-02-06 13:38:23 -0500351 : fPath(path)
Brian Salomon5e689522017-02-01 12:07:17 -0500352 , fViewMatrix(viewMatrix)
353#if SK_SUPPORT_GPU
354 , fShapeForKey(*path, GrStyle::SimpleFill())
355#endif
356 {}
357
Jim Van Vertha84898d2017-02-06 13:38:23 -0500358 const SkPath& path() const { return *fPath; }
Brian Salomon5e689522017-02-01 12:07:17 -0500359 const SkMatrix& viewMatrix() const { return *fViewMatrix; }
360#if SK_SUPPORT_GPU
361 /** Negative means the vertices should not be cached for this path. */
362 int keyBytes() const { return fShapeForKey.unstyledKeySize() * sizeof(uint32_t); }
363 void writeKey(void* key) const {
364 fShapeForKey.writeUnstyledKey(reinterpret_cast<uint32_t*>(key));
365 }
Brian Salomond1ac9822017-02-03 14:25:02 -0500366 bool isRRect(SkRRect* rrect) { return fShapeForKey.asRRect(rrect, nullptr, nullptr, nullptr); }
Brian Salomon5e689522017-02-01 12:07:17 -0500367#else
368 int keyBytes() const { return -1; }
Ben Wagnerb4aab9a2017-08-16 10:53:04 -0400369 void writeKey(void* key) const { SK_ABORT("Should never be called"); }
Brian Salomond1ac9822017-02-03 14:25:02 -0500370 bool isRRect(SkRRect* rrect) { return false; }
Brian Salomon5e689522017-02-01 12:07:17 -0500371#endif
372
373private:
Jim Van Vertha84898d2017-02-06 13:38:23 -0500374 const SkPath* fPath;
Brian Salomon5e689522017-02-01 12:07:17 -0500375 const SkMatrix* fViewMatrix;
376#if SK_SUPPORT_GPU
377 GrShape fShapeForKey;
378#endif
Brian Salomon5e689522017-02-01 12:07:17 -0500379};
380
Brian Salomond1ac9822017-02-03 14:25:02 -0500381// This creates a domain of keys in SkResourceCache used by this file.
382static void* kNamespace;
383
Brian Salomon5e689522017-02-01 12:07:17 -0500384/**
385 * Draws a shadow to 'canvas'. The vertices used to draw the shadow are created by 'factory' unless
386 * they are first found in SkResourceCache.
387 */
388template <typename FACTORY>
Jim Van Verth22526362018-02-28 14:51:19 -0500389bool draw_shadow(const FACTORY& factory,
390 std::function<void(const SkVertices*, SkBlendMode, const SkPaint&,
391 SkScalar tx, SkScalar ty)> drawProc, ShadowedPath& path, SkColor color) {
Brian Salomon5e689522017-02-01 12:07:17 -0500392 FindContext<FACTORY> context(&path.viewMatrix(), &factory);
Brian Salomon5e689522017-02-01 12:07:17 -0500393
394 SkResourceCache::Key* key = nullptr;
395 SkAutoSTArray<32 * 4, uint8_t> keyStorage;
396 int keyDataBytes = path.keyBytes();
397 if (keyDataBytes >= 0) {
398 keyStorage.reset(keyDataBytes + sizeof(SkResourceCache::Key));
399 key = new (keyStorage.begin()) SkResourceCache::Key();
400 path.writeKey((uint32_t*)(keyStorage.begin() + sizeof(*key)));
Brian Salomonbc9956d2017-02-22 13:49:09 -0500401 key->init(&kNamespace, resource_cache_shared_id(), keyDataBytes);
Jim Van Verth37c5a962017-05-10 14:13:24 -0400402 SkResourceCache::Find(*key, FindVisitor<FACTORY>, &context);
Brian Salomon5e689522017-02-01 12:07:17 -0500403 }
404
Brian Salomonaff27a22017-02-06 15:47:44 -0500405 sk_sp<SkVertices> vertices;
Brian Salomon5e689522017-02-01 12:07:17 -0500406 bool foundInCache = SkToBool(context.fVertices);
407 if (foundInCache) {
408 vertices = std::move(context.fVertices);
Brian Salomon5e689522017-02-01 12:07:17 -0500409 } else {
410 // TODO: handle transforming the path as part of the tessellator
Brian Salomond1ac9822017-02-03 14:25:02 -0500411 if (key) {
412 // Update or initialize a tessellation set and add it to the cache.
413 sk_sp<CachedTessellations> tessellations;
414 if (context.fTessellationsOnFailure) {
415 tessellations = std::move(context.fTessellationsOnFailure);
416 } else {
417 tessellations.reset(new CachedTessellations());
418 }
Jim Van Verth8793e382017-05-22 15:52:21 -0400419 vertices = tessellations->add(path.path(), factory, path.viewMatrix(),
420 &context.fTranslate);
Brian Salomond1ac9822017-02-03 14:25:02 -0500421 if (!vertices) {
Jim Van Verth22526362018-02-28 14:51:19 -0500422 return false;
Brian Salomond1ac9822017-02-03 14:25:02 -0500423 }
Brian Salomon804e0912017-02-23 09:34:03 -0500424 auto rec = new CachedTessellationsRec(*key, std::move(tessellations));
Jim Van Verth37c5a962017-05-10 14:13:24 -0400425 SkResourceCache::Add(rec);
Brian Salomond1ac9822017-02-03 14:25:02 -0500426 } else {
Jim Van Verth8793e382017-05-22 15:52:21 -0400427 vertices = factory.makeVertices(path.path(), path.viewMatrix(),
428 &context.fTranslate);
Brian Salomond1ac9822017-02-03 14:25:02 -0500429 if (!vertices) {
Jim Van Verth22526362018-02-28 14:51:19 -0500430 return false;
Brian Salomond1ac9822017-02-03 14:25:02 -0500431 }
Brian Salomon0dda9cb2017-02-03 10:33:25 -0500432 }
Brian Salomon5e689522017-02-01 12:07:17 -0500433 }
434
435 SkPaint paint;
Brian Salomon0bd699e2017-02-01 12:23:25 -0500436 // Run the vertex color through a GaussianColorFilter and then modulate the grayscale result of
437 // that against our 'color' param.
Mike Reed19d7bd62018-02-19 14:10:57 -0500438 paint.setColorFilter(
439 SkColorFilter::MakeModeFilter(color, SkBlendMode::kModulate)->makeComposed(
440 SkGaussianColorFilter::Make()));
Mike Reed4204da22017-05-17 08:53:36 -0400441
Jim Van Verth8793e382017-05-22 15:52:21 -0400442 drawProc(vertices.get(), SkBlendMode::kModulate, paint,
443 context.fTranslate.fX, context.fTranslate.fY);
Jim Van Verth22526362018-02-28 14:51:19 -0500444
445 return true;
Brian Salomon5e689522017-02-01 12:07:17 -0500446}
447}
448
Mike Reed4204da22017-05-17 08:53:36 -0400449static bool tilted(const SkPoint3& zPlaneParams) {
450 return !SkScalarNearlyZero(zPlaneParams.fX) || !SkScalarNearlyZero(zPlaneParams.fY);
451}
Jim Van Verthe7e1d9d2017-05-01 16:06:48 -0400452
Mike Reed4204da22017-05-17 08:53:36 -0400453static SkPoint3 map(const SkMatrix& m, const SkPoint3& pt) {
454 SkPoint3 result;
455 m.mapXY(pt.fX, pt.fY, (SkPoint*)&result.fX);
456 result.fZ = pt.fZ;
457 return result;
458}
459
Jim Van Verthb1b80f72018-01-18 15:19:13 -0500460void SkShadowUtils::ComputeTonalColors(SkColor inAmbientColor, SkColor inSpotColor,
461 SkColor* outAmbientColor, SkColor* outSpotColor) {
462 // For tonal color we only compute color values for the spot shadow.
463 // The ambient shadow is greyscale only.
Jim Van Verth34d6e4b2017-06-09 11:09:03 -0400464
Jim Van Verthb1b80f72018-01-18 15:19:13 -0500465 // Ambient
466 *outAmbientColor = SkColorSetARGB(SkColorGetA(inAmbientColor), 0, 0, 0);
Jim Van Verth34d6e4b2017-06-09 11:09:03 -0400467
Jim Van Verthb1b80f72018-01-18 15:19:13 -0500468 // Spot
469 int spotR = SkColorGetR(inSpotColor);
470 int spotG = SkColorGetG(inSpotColor);
471 int spotB = SkColorGetB(inSpotColor);
472 int max = SkTMax(SkTMax(spotR, spotG), spotB);
473 int min = SkTMin(SkTMin(spotR, spotG), spotB);
474 SkScalar luminance = 0.5f*(max + min)/255.f;
475 SkScalar origA = SkColorGetA(inSpotColor)/255.f;
476
477 // We compute a color alpha value based on the luminance of the color, scaled by an
478 // adjusted alpha value. We want the following properties to match the UX examples
479 // (assuming a = 0.25) and to ensure that we have reasonable results when the color
480 // is black and/or the alpha is 0:
481 // f(0, a) = 0
482 // f(luminance, 0) = 0
483 // f(1, 0.25) = .5
484 // f(0.5, 0.25) = .4
485 // f(1, 1) = 1
486 // The following functions match this as closely as possible.
487 SkScalar alphaAdjust = (2.6f + (-2.66667f + 1.06667f*origA)*origA)*origA;
488 SkScalar colorAlpha = (3.544762f + (-4.891428f + 2.3466f*luminance)*luminance)*luminance;
489 colorAlpha = SkTPin(alphaAdjust*colorAlpha, 0.0f, 1.0f);
490
491 // Similarly, we set the greyscale alpha based on luminance and alpha so that
492 // f(0, a) = a
493 // f(luminance, 0) = 0
494 // f(1, 0.25) = 0.15
495 SkScalar greyscaleAlpha = SkTPin(origA*(1 - 0.4f*luminance), 0.0f, 1.0f);
496
497 // The final color we want to emulate is generated by rendering a color shadow (C_rgb) using an
498 // alpha computed from the color's luminance (C_a), and then a black shadow with alpha (S_a)
499 // which is an adjusted value of 'a'. Assuming SrcOver, a background color of B_rgb, and
500 // ignoring edge falloff, this becomes
501 //
502 // (C_a - S_a*C_a)*C_rgb + (1 - (S_a + C_a - S_a*C_a))*B_rgb
503 //
504 // Assuming premultiplied alpha, this means we scale the color by (C_a - S_a*C_a) and
505 // set the alpha to (S_a + C_a - S_a*C_a).
506 SkScalar colorScale = colorAlpha*(SK_Scalar1 - greyscaleAlpha);
507 SkScalar tonalAlpha = colorScale + greyscaleAlpha;
508 SkScalar unPremulScale = colorScale / tonalAlpha;
509 *outSpotColor = SkColorSetARGB(tonalAlpha*255.999f,
510 unPremulScale*spotR,
511 unPremulScale*spotG,
512 unPremulScale*spotB);
Jim Van Verth060d9822017-05-04 09:58:17 -0400513}
514
Jim Van Verth43475ad2017-01-13 14:37:37 -0500515// Draw an offset spot shadow and outlining ambient shadow for the given path.
Jim Van Verth37c5a962017-05-10 14:13:24 -0400516void SkShadowUtils::DrawShadow(SkCanvas* canvas, const SkPath& path, const SkPoint3& zPlaneParams,
Brian Salomon0bd699e2017-02-01 12:23:25 -0500517 const SkPoint3& devLightPos, SkScalar lightRadius,
Jim Van Verthb1b80f72018-01-18 15:19:13 -0500518 SkColor ambientColor, SkColor spotColor,
Jim Van Verth37c5a962017-05-10 14:13:24 -0400519 uint32_t flags) {
Mike Reed4204da22017-05-17 08:53:36 -0400520 SkMatrix inverse;
521 if (!canvas->getTotalMatrix().invert(&inverse)) {
Jim Van Verthcf40e302017-03-02 11:28:43 -0500522 return;
523 }
Mike Reed4204da22017-05-17 08:53:36 -0400524 SkPoint pt = inverse.mapXY(devLightPos.fX, devLightPos.fY);
Jim Van Verthcf40e302017-03-02 11:28:43 -0500525
Mike Reed4204da22017-05-17 08:53:36 -0400526 SkDrawShadowRec rec;
527 rec.fZPlaneParams = zPlaneParams;
528 rec.fLightPos = { pt.fX, pt.fY, devLightPos.fZ };
529 rec.fLightRadius = lightRadius;
Jim Van Verthb1b80f72018-01-18 15:19:13 -0500530 rec.fAmbientColor = ambientColor;
531 rec.fSpotColor = spotColor;
Mike Reed4204da22017-05-17 08:53:36 -0400532 rec.fFlags = flags;
533
534 canvas->private_draw_shadow_rec(path, rec);
535}
536
Jim Van Vertha947e292018-02-26 13:54:34 -0500537static bool validate_rec(const SkDrawShadowRec& rec) {
538 return rec.fLightPos.isFinite() && rec.fZPlaneParams.isFinite() &&
539 SkScalarIsFinite(rec.fLightRadius);
540}
541
Mike Reed4204da22017-05-17 08:53:36 -0400542void SkBaseDevice::drawShadow(const SkPath& path, const SkDrawShadowRec& rec) {
543 auto drawVertsProc = [this](const SkVertices* vertices, SkBlendMode mode, const SkPaint& paint,
544 SkScalar tx, SkScalar ty) {
Jim Van Verth8664a1d2018-06-28 16:26:50 -0400545 if (vertices->vertexCount()) {
546 SkAutoDeviceCTMRestore adr(this, SkMatrix::Concat(this->ctm(),
547 SkMatrix::MakeTrans(tx, ty)));
548 this->drawVertices(vertices, mode, paint);
549 }
Mike Reed4204da22017-05-17 08:53:36 -0400550 };
551
Jim Van Vertha947e292018-02-26 13:54:34 -0500552 if (!validate_rec(rec)) {
553 return;
554 }
555
Mike Reed4204da22017-05-17 08:53:36 -0400556 SkMatrix viewMatrix = this->ctm();
557 SkAutoDeviceCTMRestore adr(this, SkMatrix::I());
Jim Van Verthefe3ded2017-01-30 13:11:45 -0500558
Brian Salomon5e689522017-02-01 12:07:17 -0500559 ShadowedPath shadowedPath(&path, &viewMatrix);
560
Mike Reed4204da22017-05-17 08:53:36 -0400561 bool tiltZPlane = tilted(rec.fZPlaneParams);
562 bool transparent = SkToBool(rec.fFlags & SkShadowFlags::kTransparentOccluder_ShadowFlag);
Jim Van Verth4c9b8932017-05-15 13:49:21 -0400563 bool uncached = tiltZPlane || path.isVolatile();
Brian Salomon958fbc42017-01-30 17:01:28 -0500564
Mike Reed4204da22017-05-17 08:53:36 -0400565 SkPoint3 zPlaneParams = rec.fZPlaneParams;
566 SkPoint3 devLightPos = map(viewMatrix, rec.fLightPos);
567 float lightRadius = rec.fLightRadius;
568
Jim Van Verthb1b80f72018-01-18 15:19:13 -0500569 if (SkColorGetA(rec.fAmbientColor) > 0) {
Jim Van Verth22526362018-02-28 14:51:19 -0500570 bool success = false;
Jim Van Verth37c5a962017-05-10 14:13:24 -0400571 if (uncached) {
572 sk_sp<SkVertices> vertices = SkShadowTessellator::MakeAmbient(path, viewMatrix,
573 zPlaneParams,
574 transparent);
Jim Van Verth7d8955e2017-07-13 15:13:52 -0400575 if (vertices) {
576 SkPaint paint;
577 // Run the vertex color through a GaussianColorFilter and then modulate the
578 // grayscale result of that against our 'color' param.
Mike Reed19d7bd62018-02-19 14:10:57 -0500579 paint.setColorFilter(
580 SkColorFilter::MakeModeFilter(rec.fAmbientColor,
581 SkBlendMode::kModulate)->makeComposed(
582 SkGaussianColorFilter::Make()));
Jim Van Verth7d8955e2017-07-13 15:13:52 -0400583 this->drawVertices(vertices.get(), SkBlendMode::kModulate, paint);
Jim Van Verth22526362018-02-28 14:51:19 -0500584 success = true;
Jim Van Verth7d8955e2017-07-13 15:13:52 -0400585 }
Jim Van Verth22526362018-02-28 14:51:19 -0500586 }
587
588 if (!success) {
Jim Van Verth37c5a962017-05-10 14:13:24 -0400589 AmbientVerticesFactory factory;
590 factory.fOccluderHeight = zPlaneParams.fZ;
591 factory.fTransparent = transparent;
Jim Van Verth8793e382017-05-22 15:52:21 -0400592 if (viewMatrix.hasPerspective()) {
593 factory.fOffset.set(0, 0);
594 } else {
595 factory.fOffset.fX = viewMatrix.getTranslateX();
596 factory.fOffset.fY = viewMatrix.getTranslateY();
597 }
Jim Van Verth37c5a962017-05-10 14:13:24 -0400598
Jim Van Verth22526362018-02-28 14:51:19 -0500599 if (!draw_shadow(factory, drawVertsProc, shadowedPath, rec.fAmbientColor)) {
600 // Pretransform the path to avoid transforming the stroke, below.
601 SkPath devSpacePath;
602 path.transform(viewMatrix, &devSpacePath);
603
604 // The tesselator outsets by AmbientBlurRadius (or 'r') to get the outer ring of
605 // the tesselation, uses the original path as the inner ring, and sets the alpha
606 // of the inner ring to 1/AmbientRecipAlpha (or 'a').
607 //
608 // We want to emulate this with a blur. The full blur width (2*blurRadius or 'f')
609 // can be calculated by interpolating:
610 //
611 // original edge outer edge
612 // | |<---------- r ------>|
613 // |<------|--- f -------------->|
614 // | | |
615 // alpha = 1 alpha = a alpha = 0
616 //
617 // Taking ratios, f/1 = r/a, so f = r/a and blurRadius = f/2.
618 //
619 // We now need to outset the path to place the new edge in the center of the
620 // blur region:
621 //
622 // original new
623 // | |<------|--- r ------>|
624 // |<------|--- f -|------------>|
625 // | |<- o ->|<--- f/2 --->|
626 //
627 // r = o + f/2, so o = r - f/2
628 //
629 // We outset by using the stroker, so the strokeWidth is o/2.
630 //
631 SkScalar devSpaceOutset = SkDrawShadowMetrics::AmbientBlurRadius(zPlaneParams.fZ);
632 SkScalar oneOverA = SkDrawShadowMetrics::AmbientRecipAlpha(zPlaneParams.fZ);
633 SkScalar blurRadius = 0.5f*devSpaceOutset*oneOverA;
634 SkScalar strokeWidth = 0.5f*(devSpaceOutset - blurRadius);
635
636 // Now draw with blur
637 SkPaint paint;
638 paint.setColor(rec.fAmbientColor);
639 paint.setStrokeWidth(strokeWidth);
640 paint.setStyle(SkPaint::kStrokeAndFill_Style);
Mike Reed8e03f692018-03-09 16:18:56 -0500641 SkScalar sigma = SkBlurMask::ConvertRadiusToSigma(blurRadius);
Mike Reed18e75562018-03-12 14:03:47 -0400642 bool respectCTM = false;
643 paint.setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle, sigma, respectCTM));
Jim Van Verth22526362018-02-28 14:51:19 -0500644 this->drawPath(devSpacePath, paint);
645 }
Brian Salomond1ac9822017-02-03 14:25:02 -0500646 }
Jim Van Verthb4366552017-03-27 14:25:29 -0400647 }
648
Jim Van Verthb1b80f72018-01-18 15:19:13 -0500649 if (SkColorGetA(rec.fSpotColor) > 0) {
Jim Van Verth22526362018-02-28 14:51:19 -0500650 bool success = false;
Jim Van Verth37c5a962017-05-10 14:13:24 -0400651 if (uncached) {
652 sk_sp<SkVertices> vertices = SkShadowTessellator::MakeSpot(path, viewMatrix,
653 zPlaneParams,
654 devLightPos, lightRadius,
655 transparent);
Jim Van Verth7d8955e2017-07-13 15:13:52 -0400656 if (vertices) {
657 SkPaint paint;
658 // Run the vertex color through a GaussianColorFilter and then modulate the
659 // grayscale result of that against our 'color' param.
Mike Reed19d7bd62018-02-19 14:10:57 -0500660 paint.setColorFilter(
661 SkColorFilter::MakeModeFilter(rec.fSpotColor,
662 SkBlendMode::kModulate)->makeComposed(
Jim Van Verth22526362018-02-28 14:51:19 -0500663 SkGaussianColorFilter::Make()));
Jim Van Verth7d8955e2017-07-13 15:13:52 -0400664 this->drawVertices(vertices.get(), SkBlendMode::kModulate, paint);
Jim Van Verth22526362018-02-28 14:51:19 -0500665 success = true;
Jim Van Verth7d8955e2017-07-13 15:13:52 -0400666 }
Jim Van Verth22526362018-02-28 14:51:19 -0500667 }
Jim Van Vertha783c362017-05-11 17:05:28 -0400668
Jim Van Verth22526362018-02-28 14:51:19 -0500669 if (!success) {
670 SpotVerticesFactory factory;
671 factory.fOccluderHeight = zPlaneParams.fZ;
672 factory.fDevLightPos = devLightPos;
673 factory.fLightRadius = lightRadius;
674
Jim Van Verth37c5a962017-05-10 14:13:24 -0400675 SkPoint center = SkPoint::Make(path.getBounds().centerX(), path.getBounds().centerY());
Jim Van Verth8793e382017-05-22 15:52:21 -0400676 factory.fLocalCenter = center;
Jim Van Verth37c5a962017-05-10 14:13:24 -0400677 viewMatrix.mapPoints(&center, 1);
Jim Van Verth22526362018-02-28 14:51:19 -0500678 SkScalar radius, scale;
679 SkDrawShadowMetrics::GetSpotParams(zPlaneParams.fZ, devLightPos.fX - center.fX,
680 devLightPos.fY - center.fY, devLightPos.fZ,
681 lightRadius, &radius, &scale, &factory.fOffset);
Jim Van Vertha783c362017-05-11 17:05:28 -0400682 SkRect devBounds;
683 viewMatrix.mapRect(&devBounds, path.getBounds());
Jim Van Verth8793e382017-05-22 15:52:21 -0400684 if (transparent ||
685 SkTAbs(factory.fOffset.fX) > 0.5f*devBounds.width() ||
686 SkTAbs(factory.fOffset.fY) > 0.5f*devBounds.height()) {
Jim Van Verth78c8f302017-05-15 10:44:22 -0400687 // if the translation of the shadow is big enough we're going to end up
688 // filling the entire umbra, so we can treat these as all the same
Jim Van Verth8793e382017-05-22 15:52:21 -0400689 factory.fOccluderType = SpotVerticesFactory::OccluderType::kTransparent;
Jim Van Verth78c8f302017-05-15 10:44:22 -0400690 } else if (factory.fOffset.length()*scale + scale < radius) {
Jim Van Vertha783c362017-05-11 17:05:28 -0400691 // if we don't translate more than the blur distance, can assume umbra is covered
Jim Van Verth78c8f302017-05-15 10:44:22 -0400692 factory.fOccluderType = SpotVerticesFactory::OccluderType::kOpaqueNoUmbra;
Jim Van Verth8760e2f2018-06-12 14:21:38 -0400693 } else if (path.isConvex()) {
Jim Van Verth78c8f302017-05-15 10:44:22 -0400694 factory.fOccluderType = SpotVerticesFactory::OccluderType::kOpaquePartialUmbra;
Jim Van Verth8760e2f2018-06-12 14:21:38 -0400695 } else {
696 factory.fOccluderType = SpotVerticesFactory::OccluderType::kTransparent;
Jim Van Vertha783c362017-05-11 17:05:28 -0400697 }
Jim Van Verth8793e382017-05-22 15:52:21 -0400698 // need to add this after we classify the shadow
699 factory.fOffset.fX += viewMatrix.getTranslateX();
700 factory.fOffset.fY += viewMatrix.getTranslateY();
Jim Van Verth22526362018-02-28 14:51:19 -0500701
702 SkColor color = rec.fSpotColor;
Jim Van Vertha783c362017-05-11 17:05:28 -0400703#ifdef DEBUG_SHADOW_CHECKS
704 switch (factory.fOccluderType) {
705 case SpotVerticesFactory::OccluderType::kTransparent:
706 color = 0xFFD2B48C; // tan for transparent
707 break;
Jim Van Verth78c8f302017-05-15 10:44:22 -0400708 case SpotVerticesFactory::OccluderType::kOpaquePartialUmbra:
Jim Van Vertha783c362017-05-11 17:05:28 -0400709 color = 0xFFFFA500; // orange for opaque
710 break;
Jim Van Verth78c8f302017-05-15 10:44:22 -0400711 case SpotVerticesFactory::OccluderType::kOpaqueNoUmbra:
712 color = 0xFFE5E500; // corn yellow for covered
Jim Van Vertha783c362017-05-11 17:05:28 -0400713 break;
714 }
715#endif
Jim Van Verth22526362018-02-28 14:51:19 -0500716 if (!draw_shadow(factory, drawVertsProc, shadowedPath, color)) {
717 // draw with blur
718 SkVector translate;
719 SkDrawShadowMetrics::GetSpotParams(zPlaneParams.fZ, devLightPos.fX,
720 devLightPos.fY, devLightPos.fZ,
721 lightRadius, &radius, &scale, &translate);
722 SkMatrix shadowMatrix;
723 shadowMatrix.setScaleTranslate(scale, scale, translate.fX, translate.fY);
724 SkAutoDeviceCTMRestore adr(this, SkMatrix::Concat(shadowMatrix, viewMatrix));
725
726 SkPaint paint;
727 paint.setColor(rec.fSpotColor);
Mike Reed8e03f692018-03-09 16:18:56 -0500728 SkScalar sigma = SkBlurMask::ConvertRadiusToSigma(radius);
Mike Reed18e75562018-03-12 14:03:47 -0400729 bool respectCTM = false;
730 paint.setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle, sigma, respectCTM));
Jim Van Verth22526362018-02-28 14:51:19 -0500731 this->drawPath(path, paint);
732 }
Jim Van Verth37c5a962017-05-10 14:13:24 -0400733 }
Jim Van Verthb4366552017-03-27 14:25:29 -0400734 }
735}