blob: f0b1e8f4d79b37d7c8877cc2e8d6a01e0a15206d [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"
Brian Salomon5e689522017-02-01 12:07:17 -050026#if SK_SUPPORT_GPU
27#include "GrShape.h"
28#include "effects/GrBlurredEdgeFragmentProcessor.h"
Mike Reed4204da22017-05-17 08:53:36 -040029#endif
Jim Van Verthefe3ded2017-01-30 13:11:45 -050030
31/**
32* Gaussian color filter -- produces a Gaussian ramp based on the color's B value,
33* then blends with the color's G value.
34* Final result is black with alpha of Gaussian(B)*G.
35* The assumption is that the original color's alpha is 1.
36*/
Mike Reed57c2b8b2017-12-31 15:23:54 -050037class SkGaussianColorFilter : public SkColorFilter {
Jim Van Verthefe3ded2017-01-30 13:11:45 -050038public:
39 static sk_sp<SkColorFilter> Make() {
40 return sk_sp<SkColorFilter>(new SkGaussianColorFilter);
41 }
42
Jim Van Verthefe3ded2017-01-30 13:11:45 -050043#if SK_SUPPORT_GPU
Brian Salomon4cbb6e62017-10-25 15:12:19 -040044 std::unique_ptr<GrFragmentProcessor> asFragmentProcessor(
45 GrContext*, const GrColorSpaceInfo&) const override;
Jim Van Verthefe3ded2017-01-30 13:11:45 -050046#endif
47
Jim Van Verthefe3ded2017-01-30 13:11:45 -050048 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkGaussianColorFilter)
49
50protected:
51 void flatten(SkWriteBuffer&) const override {}
Mike Reed65331592017-05-24 16:45:34 -040052 void onAppendStages(SkRasterPipeline* pipeline, SkColorSpace* dstCS, SkArenaAlloc* alloc,
53 bool shaderIsOpaque) const override {
54 pipeline->append(SkRasterPipeline::gauss_a_to_rgba);
55 }
Jim Van Verthefe3ded2017-01-30 13:11:45 -050056private:
57 SkGaussianColorFilter() : INHERITED() {}
58
59 typedef SkColorFilter INHERITED;
60};
61
Jim Van Verthefe3ded2017-01-30 13:11:45 -050062sk_sp<SkFlattenable> SkGaussianColorFilter::CreateProc(SkReadBuffer&) {
63 return Make();
64}
65
Jim Van Verthefe3ded2017-01-30 13:11:45 -050066#if SK_SUPPORT_GPU
Jim Van Verthefe3ded2017-01-30 13:11:45 -050067
Brian Salomonaff329b2017-08-11 09:40:37 -040068std::unique_ptr<GrFragmentProcessor> SkGaussianColorFilter::asFragmentProcessor(
Brian Salomon4cbb6e62017-10-25 15:12:19 -040069 GrContext*, const GrColorSpaceInfo&) const {
Ethan Nicholasaae47c82017-11-10 15:34:03 -050070 return GrBlurredEdgeFragmentProcessor::Make(GrBlurredEdgeFragmentProcessor::Mode::kGaussian);
Jim Van Verthefe3ded2017-01-30 13:11:45 -050071}
72#endif
73
74///////////////////////////////////////////////////////////////////////////////////////////////////
Brian Salomon5e689522017-02-01 12:07:17 -050075
76namespace {
77
Brian Salomonbc9956d2017-02-22 13:49:09 -050078uint64_t resource_cache_shared_id() {
79 return 0x2020776f64616873llu; // 'shadow '
80}
81
Brian Salomond1ac9822017-02-03 14:25:02 -050082/** Factory for an ambient shadow mesh with particular shadow properties. */
Brian Salomon5e689522017-02-01 12:07:17 -050083struct AmbientVerticesFactory {
Jim Van Verthb4366552017-03-27 14:25:29 -040084 SkScalar fOccluderHeight = SK_ScalarNaN; // NaN so that isCompatible will fail until init'ed.
Brian Salomon5e689522017-02-01 12:07:17 -050085 bool fTransparent;
Jim Van Verth8793e382017-05-22 15:52:21 -040086 SkVector fOffset;
Brian Salomon5e689522017-02-01 12:07:17 -050087
Brian Salomond1ac9822017-02-03 14:25:02 -050088 bool isCompatible(const AmbientVerticesFactory& that, SkVector* translate) const {
Jim Van Verth060d9822017-05-04 09:58:17 -040089 if (fOccluderHeight != that.fOccluderHeight || fTransparent != that.fTransparent) {
Brian Salomond1ac9822017-02-03 14:25:02 -050090 return false;
91 }
Jim Van Verth8793e382017-05-22 15:52:21 -040092 *translate = that.fOffset;
Brian Salomond1ac9822017-02-03 14:25:02 -050093 return true;
Brian Salomon5e689522017-02-01 12:07:17 -050094 }
Brian Salomon5e689522017-02-01 12:07:17 -050095
Jim Van Verth8793e382017-05-22 15:52:21 -040096 sk_sp<SkVertices> makeVertices(const SkPath& path, const SkMatrix& ctm,
97 SkVector* translate) const {
Jim Van Verthe308a122017-05-08 14:19:30 -040098 SkPoint3 zParams = SkPoint3::Make(0, 0, fOccluderHeight);
Jim Van Verth8793e382017-05-22 15:52:21 -040099 // pick a canonical place to generate shadow
100 SkMatrix noTrans(ctm);
101 if (!ctm.hasPerspective()) {
102 noTrans[SkMatrix::kMTransX] = 0;
103 noTrans[SkMatrix::kMTransY] = 0;
104 }
105 *translate = fOffset;
106 return SkShadowTessellator::MakeAmbient(path, noTrans, zParams, fTransparent);
Brian Salomon5e689522017-02-01 12:07:17 -0500107 }
108};
109
Brian Salomond1ac9822017-02-03 14:25:02 -0500110/** Factory for an spot shadow mesh with particular shadow properties. */
Brian Salomon5e689522017-02-01 12:07:17 -0500111struct SpotVerticesFactory {
Brian Salomond1ac9822017-02-03 14:25:02 -0500112 enum class OccluderType {
Jim Van Verth8793e382017-05-22 15:52:21 -0400113 // The umbra cannot be dropped out because either the occluder is not opaque,
114 // or the center of the umbra is visible.
Brian Salomond1ac9822017-02-03 14:25:02 -0500115 kTransparent,
116 // The umbra can be dropped where it is occluded.
Jim Van Verth78c8f302017-05-15 10:44:22 -0400117 kOpaquePartialUmbra,
Brian Salomond1ac9822017-02-03 14:25:02 -0500118 // It is known that the entire umbra is occluded.
Jim Van Verth78c8f302017-05-15 10:44:22 -0400119 kOpaqueNoUmbra
Brian Salomond1ac9822017-02-03 14:25:02 -0500120 };
121
Brian Salomon5e689522017-02-01 12:07:17 -0500122 SkVector fOffset;
Jim Van Verth8793e382017-05-22 15:52:21 -0400123 SkPoint fLocalCenter;
Jim Van Verthb4366552017-03-27 14:25:29 -0400124 SkScalar fOccluderHeight = SK_ScalarNaN; // NaN so that isCompatible will fail until init'ed.
125 SkPoint3 fDevLightPos;
126 SkScalar fLightRadius;
Brian Salomond1ac9822017-02-03 14:25:02 -0500127 OccluderType fOccluderType;
Brian Salomon5e689522017-02-01 12:07:17 -0500128
Brian Salomond1ac9822017-02-03 14:25:02 -0500129 bool isCompatible(const SpotVerticesFactory& that, SkVector* translate) const {
Jim Van Verthb4366552017-03-27 14:25:29 -0400130 if (fOccluderHeight != that.fOccluderHeight || fDevLightPos.fZ != that.fDevLightPos.fZ ||
Jim Van Verth060d9822017-05-04 09:58:17 -0400131 fLightRadius != that.fLightRadius || fOccluderType != that.fOccluderType) {
Brian Salomond1ac9822017-02-03 14:25:02 -0500132 return false;
133 }
134 switch (fOccluderType) {
135 case OccluderType::kTransparent:
Jim Van Verth78c8f302017-05-15 10:44:22 -0400136 case OccluderType::kOpaqueNoUmbra:
Brian Salomond1ac9822017-02-03 14:25:02 -0500137 // 'this' and 'that' will either both have no umbra removed or both have all the
138 // umbra removed.
Jim Van Verth8793e382017-05-22 15:52:21 -0400139 *translate = that.fOffset;
Brian Salomond1ac9822017-02-03 14:25:02 -0500140 return true;
Jim Van Verth78c8f302017-05-15 10:44:22 -0400141 case OccluderType::kOpaquePartialUmbra:
Brian Salomond1ac9822017-02-03 14:25:02 -0500142 // In this case we partially remove the umbra differently for 'this' and 'that'
143 // if the offsets don't match.
144 if (fOffset == that.fOffset) {
145 translate->set(0, 0);
146 return true;
147 }
148 return false;
149 }
Ben Wagnerb4aab9a2017-08-16 10:53:04 -0400150 SK_ABORT("Uninitialized occluder type?");
Brian Salomond1ac9822017-02-03 14:25:02 -0500151 return false;
Brian Salomon5e689522017-02-01 12:07:17 -0500152 }
Brian Salomon5e689522017-02-01 12:07:17 -0500153
Jim Van Verth8793e382017-05-22 15:52:21 -0400154 sk_sp<SkVertices> makeVertices(const SkPath& path, const SkMatrix& ctm,
155 SkVector* translate) const {
Brian Salomond1ac9822017-02-03 14:25:02 -0500156 bool transparent = OccluderType::kTransparent == fOccluderType;
Jim Van Verthe308a122017-05-08 14:19:30 -0400157 SkPoint3 zParams = SkPoint3::Make(0, 0, fOccluderHeight);
Jim Van Verth8793e382017-05-22 15:52:21 -0400158 if (ctm.hasPerspective() || OccluderType::kOpaquePartialUmbra == fOccluderType) {
159 translate->set(0, 0);
160 return SkShadowTessellator::MakeSpot(path, ctm, zParams,
161 fDevLightPos, fLightRadius, transparent);
162 } else {
163 // pick a canonical place to generate shadow, with light centered over path
164 SkMatrix noTrans(ctm);
165 noTrans[SkMatrix::kMTransX] = 0;
166 noTrans[SkMatrix::kMTransY] = 0;
167 SkPoint devCenter(fLocalCenter);
168 noTrans.mapPoints(&devCenter, 1);
169 SkPoint3 centerLightPos = SkPoint3::Make(devCenter.fX, devCenter.fY, fDevLightPos.fZ);
170 *translate = fOffset;
171 return SkShadowTessellator::MakeSpot(path, noTrans, zParams,
172 centerLightPos, fLightRadius, transparent);
173 }
Brian Salomon5e689522017-02-01 12:07:17 -0500174 }
175};
176
177/**
Brian Salomond1ac9822017-02-03 14:25:02 -0500178 * This manages a set of tessellations for a given shape in the cache. Because SkResourceCache
179 * 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 -0400180 * the FindVisitor and let the cache destroy the Rec. We'll update the tessellations and then add
Brian Salomond1ac9822017-02-03 14:25:02 -0500181 * a new Rec with an adjusted size for any deletions/additions.
Brian Salomon5e689522017-02-01 12:07:17 -0500182 */
Brian Salomond1ac9822017-02-03 14:25:02 -0500183class CachedTessellations : public SkRefCnt {
Brian Salomon5e689522017-02-01 12:07:17 -0500184public:
Brian Salomond1ac9822017-02-03 14:25:02 -0500185 size_t size() const { return fAmbientSet.size() + fSpotSet.size(); }
186
Brian Salomonaff27a22017-02-06 15:47:44 -0500187 sk_sp<SkVertices> find(const AmbientVerticesFactory& ambient, const SkMatrix& matrix,
188 SkVector* translate) const {
Brian Salomond1ac9822017-02-03 14:25:02 -0500189 return fAmbientSet.find(ambient, matrix, translate);
190 }
191
Brian Salomonaff27a22017-02-06 15:47:44 -0500192 sk_sp<SkVertices> add(const SkPath& devPath, const AmbientVerticesFactory& ambient,
Jim Van Verth8793e382017-05-22 15:52:21 -0400193 const SkMatrix& matrix, SkVector* translate) {
194 return fAmbientSet.add(devPath, ambient, matrix, translate);
Brian Salomond1ac9822017-02-03 14:25:02 -0500195 }
196
Brian Salomonaff27a22017-02-06 15:47:44 -0500197 sk_sp<SkVertices> find(const SpotVerticesFactory& spot, const SkMatrix& matrix,
198 SkVector* translate) const {
Brian Salomond1ac9822017-02-03 14:25:02 -0500199 return fSpotSet.find(spot, matrix, translate);
200 }
201
Brian Salomonaff27a22017-02-06 15:47:44 -0500202 sk_sp<SkVertices> add(const SkPath& devPath, const SpotVerticesFactory& spot,
Jim Van Verth8793e382017-05-22 15:52:21 -0400203 const SkMatrix& matrix, SkVector* translate) {
204 return fSpotSet.add(devPath, spot, matrix, translate);
Brian Salomond1ac9822017-02-03 14:25:02 -0500205 }
206
207private:
208 template <typename FACTORY, int MAX_ENTRIES>
209 class Set {
210 public:
211 size_t size() const { return fSize; }
212
Brian Salomonaff27a22017-02-06 15:47:44 -0500213 sk_sp<SkVertices> find(const FACTORY& factory, const SkMatrix& matrix,
214 SkVector* translate) const {
Brian Salomond1ac9822017-02-03 14:25:02 -0500215 for (int i = 0; i < MAX_ENTRIES; ++i) {
216 if (fEntries[i].fFactory.isCompatible(factory, translate)) {
217 const SkMatrix& m = fEntries[i].fMatrix;
218 if (matrix.hasPerspective() || m.hasPerspective()) {
219 if (matrix != fEntries[i].fMatrix) {
220 continue;
221 }
222 } else if (matrix.getScaleX() != m.getScaleX() ||
223 matrix.getSkewX() != m.getSkewX() ||
224 matrix.getScaleY() != m.getScaleY() ||
225 matrix.getSkewY() != m.getSkewY()) {
226 continue;
227 }
Brian Salomond1ac9822017-02-03 14:25:02 -0500228 return fEntries[i].fVertices;
229 }
230 }
231 return nullptr;
232 }
233
Jim Van Verth8793e382017-05-22 15:52:21 -0400234 sk_sp<SkVertices> add(const SkPath& path, const FACTORY& factory, const SkMatrix& matrix,
235 SkVector* translate) {
236 sk_sp<SkVertices> vertices = factory.makeVertices(path, matrix, translate);
Brian Salomond1ac9822017-02-03 14:25:02 -0500237 if (!vertices) {
238 return nullptr;
239 }
240 int i;
241 if (fCount < MAX_ENTRIES) {
242 i = fCount++;
243 } else {
Jim Van Vertheb63eb72017-05-23 09:40:02 -0400244 i = fRandom.nextULessThan(MAX_ENTRIES);
Mike Reedaa9e3322017-03-16 14:38:48 -0400245 fSize -= fEntries[i].fVertices->approximateSize();
Brian Salomond1ac9822017-02-03 14:25:02 -0500246 }
247 fEntries[i].fFactory = factory;
248 fEntries[i].fVertices = vertices;
249 fEntries[i].fMatrix = matrix;
Mike Reedaa9e3322017-03-16 14:38:48 -0400250 fSize += vertices->approximateSize();
Brian Salomond1ac9822017-02-03 14:25:02 -0500251 return vertices;
252 }
253
254 private:
255 struct Entry {
256 FACTORY fFactory;
Brian Salomonaff27a22017-02-06 15:47:44 -0500257 sk_sp<SkVertices> fVertices;
Brian Salomond1ac9822017-02-03 14:25:02 -0500258 SkMatrix fMatrix;
259 };
260 Entry fEntries[MAX_ENTRIES];
261 int fCount = 0;
262 size_t fSize = 0;
Jim Van Vertheb63eb72017-05-23 09:40:02 -0400263 SkRandom fRandom;
Brian Salomond1ac9822017-02-03 14:25:02 -0500264 };
265
266 Set<AmbientVerticesFactory, 4> fAmbientSet;
267 Set<SpotVerticesFactory, 4> fSpotSet;
Brian Salomond1ac9822017-02-03 14:25:02 -0500268};
269
Brian Salomond1ac9822017-02-03 14:25:02 -0500270/**
271 * A record of shadow vertices stored in SkResourceCache of CachedTessellations for a particular
272 * path. The key represents the path's geometry and not any shadow params.
273 */
274class CachedTessellationsRec : public SkResourceCache::Rec {
275public:
276 CachedTessellationsRec(const SkResourceCache::Key& key,
277 sk_sp<CachedTessellations> tessellations)
278 : fTessellations(std::move(tessellations)) {
Brian Salomon5e689522017-02-01 12:07:17 -0500279 fKey.reset(new uint8_t[key.size()]);
280 memcpy(fKey.get(), &key, key.size());
281 }
282
283 const Key& getKey() const override {
284 return *reinterpret_cast<SkResourceCache::Key*>(fKey.get());
285 }
Brian Salomon5e689522017-02-01 12:07:17 -0500286
Brian Salomond1ac9822017-02-03 14:25:02 -0500287 size_t bytesUsed() const override { return fTessellations->size(); }
Brian Salomon5e689522017-02-01 12:07:17 -0500288
Brian Salomond1ac9822017-02-03 14:25:02 -0500289 const char* getCategory() const override { return "tessellated shadow masks"; }
Brian Salomon5e689522017-02-01 12:07:17 -0500290
Brian Salomond1ac9822017-02-03 14:25:02 -0500291 sk_sp<CachedTessellations> refTessellations() const { return fTessellations; }
Brian Salomon5e689522017-02-01 12:07:17 -0500292
Brian Salomond1ac9822017-02-03 14:25:02 -0500293 template <typename FACTORY>
Brian Salomonaff27a22017-02-06 15:47:44 -0500294 sk_sp<SkVertices> find(const FACTORY& factory, const SkMatrix& matrix,
295 SkVector* translate) const {
Brian Salomond1ac9822017-02-03 14:25:02 -0500296 return fTessellations->find(factory, matrix, translate);
297 }
Brian Salomon5e689522017-02-01 12:07:17 -0500298
299private:
300 std::unique_ptr<uint8_t[]> fKey;
Brian Salomond1ac9822017-02-03 14:25:02 -0500301 sk_sp<CachedTessellations> fTessellations;
Brian Salomon5e689522017-02-01 12:07:17 -0500302};
303
304/**
305 * Used by FindVisitor to determine whether a cache entry can be reused and if so returns the
Brian Salomond1ac9822017-02-03 14:25:02 -0500306 * vertices and a translation vector. If the CachedTessellations does not contain a suitable
307 * mesh then we inform SkResourceCache to destroy the Rec and we return the CachedTessellations
308 * to the caller. The caller will update it and reinsert it back into the cache.
Brian Salomon5e689522017-02-01 12:07:17 -0500309 */
310template <typename FACTORY>
311struct FindContext {
312 FindContext(const SkMatrix* viewMatrix, const FACTORY* factory)
313 : fViewMatrix(viewMatrix), fFactory(factory) {}
Brian Salomond1ac9822017-02-03 14:25:02 -0500314 const SkMatrix* const fViewMatrix;
315 // If this is valid after Find is called then we found the vertices and they should be drawn
316 // with fTranslate applied.
Brian Salomonaff27a22017-02-06 15:47:44 -0500317 sk_sp<SkVertices> fVertices;
Brian Salomond1ac9822017-02-03 14:25:02 -0500318 SkVector fTranslate = {0, 0};
319
320 // If this is valid after Find then the caller should add the vertices to the tessellation set
321 // and create a new CachedTessellationsRec and insert it into SkResourceCache.
322 sk_sp<CachedTessellations> fTessellationsOnFailure;
323
Brian Salomon5e689522017-02-01 12:07:17 -0500324 const FACTORY* fFactory;
325};
326
327/**
328 * Function called by SkResourceCache when a matching cache key is found. The FACTORY and matrix of
329 * the FindContext are used to determine if the vertices are reusable. If so the vertices and
330 * necessary translation vector are set on the FindContext.
331 */
332template <typename FACTORY>
333bool FindVisitor(const SkResourceCache::Rec& baseRec, void* ctx) {
334 FindContext<FACTORY>* findContext = (FindContext<FACTORY>*)ctx;
Brian Salomond1ac9822017-02-03 14:25:02 -0500335 const CachedTessellationsRec& rec = static_cast<const CachedTessellationsRec&>(baseRec);
336 findContext->fVertices =
337 rec.find(*findContext->fFactory, *findContext->fViewMatrix, &findContext->fTranslate);
338 if (findContext->fVertices) {
339 return true;
Brian Salomon5e689522017-02-01 12:07:17 -0500340 }
Brian Salomond1ac9822017-02-03 14:25:02 -0500341 // We ref the tessellations and let the cache destroy the Rec. Once the tessellations have been
342 // manipulated we will add a new Rec.
343 findContext->fTessellationsOnFailure = rec.refTessellations();
344 return false;
Brian Salomon5e689522017-02-01 12:07:17 -0500345}
346
347class ShadowedPath {
348public:
349 ShadowedPath(const SkPath* path, const SkMatrix* viewMatrix)
Jim Van Vertha84898d2017-02-06 13:38:23 -0500350 : fPath(path)
Brian Salomon5e689522017-02-01 12:07:17 -0500351 , fViewMatrix(viewMatrix)
352#if SK_SUPPORT_GPU
353 , fShapeForKey(*path, GrStyle::SimpleFill())
354#endif
355 {}
356
Jim Van Vertha84898d2017-02-06 13:38:23 -0500357 const SkPath& path() const { return *fPath; }
Brian Salomon5e689522017-02-01 12:07:17 -0500358 const SkMatrix& viewMatrix() const { return *fViewMatrix; }
359#if SK_SUPPORT_GPU
360 /** Negative means the vertices should not be cached for this path. */
361 int keyBytes() const { return fShapeForKey.unstyledKeySize() * sizeof(uint32_t); }
362 void writeKey(void* key) const {
363 fShapeForKey.writeUnstyledKey(reinterpret_cast<uint32_t*>(key));
364 }
Brian Salomond1ac9822017-02-03 14:25:02 -0500365 bool isRRect(SkRRect* rrect) { return fShapeForKey.asRRect(rrect, nullptr, nullptr, nullptr); }
Brian Salomon5e689522017-02-01 12:07:17 -0500366#else
367 int keyBytes() const { return -1; }
Ben Wagnerb4aab9a2017-08-16 10:53:04 -0400368 void writeKey(void* key) const { SK_ABORT("Should never be called"); }
Brian Salomond1ac9822017-02-03 14:25:02 -0500369 bool isRRect(SkRRect* rrect) { return false; }
Brian Salomon5e689522017-02-01 12:07:17 -0500370#endif
371
372private:
Jim Van Vertha84898d2017-02-06 13:38:23 -0500373 const SkPath* fPath;
Brian Salomon5e689522017-02-01 12:07:17 -0500374 const SkMatrix* fViewMatrix;
375#if SK_SUPPORT_GPU
376 GrShape fShapeForKey;
377#endif
Brian Salomon5e689522017-02-01 12:07:17 -0500378};
379
Brian Salomond1ac9822017-02-03 14:25:02 -0500380// This creates a domain of keys in SkResourceCache used by this file.
381static void* kNamespace;
382
Brian Salomon5e689522017-02-01 12:07:17 -0500383/**
384 * Draws a shadow to 'canvas'. The vertices used to draw the shadow are created by 'factory' unless
385 * they are first found in SkResourceCache.
386 */
387template <typename FACTORY>
Jim Van Verth22526362018-02-28 14:51:19 -0500388bool draw_shadow(const FACTORY& factory,
389 std::function<void(const SkVertices*, SkBlendMode, const SkPaint&,
390 SkScalar tx, SkScalar ty)> drawProc, ShadowedPath& path, SkColor color) {
Brian Salomon5e689522017-02-01 12:07:17 -0500391 FindContext<FACTORY> context(&path.viewMatrix(), &factory);
Brian Salomon5e689522017-02-01 12:07:17 -0500392
393 SkResourceCache::Key* key = nullptr;
394 SkAutoSTArray<32 * 4, uint8_t> keyStorage;
395 int keyDataBytes = path.keyBytes();
396 if (keyDataBytes >= 0) {
397 keyStorage.reset(keyDataBytes + sizeof(SkResourceCache::Key));
398 key = new (keyStorage.begin()) SkResourceCache::Key();
399 path.writeKey((uint32_t*)(keyStorage.begin() + sizeof(*key)));
Brian Salomonbc9956d2017-02-22 13:49:09 -0500400 key->init(&kNamespace, resource_cache_shared_id(), keyDataBytes);
Jim Van Verth37c5a962017-05-10 14:13:24 -0400401 SkResourceCache::Find(*key, FindVisitor<FACTORY>, &context);
Brian Salomon5e689522017-02-01 12:07:17 -0500402 }
403
Brian Salomonaff27a22017-02-06 15:47:44 -0500404 sk_sp<SkVertices> vertices;
Brian Salomon5e689522017-02-01 12:07:17 -0500405 bool foundInCache = SkToBool(context.fVertices);
406 if (foundInCache) {
407 vertices = std::move(context.fVertices);
Brian Salomon5e689522017-02-01 12:07:17 -0500408 } else {
409 // TODO: handle transforming the path as part of the tessellator
Brian Salomond1ac9822017-02-03 14:25:02 -0500410 if (key) {
411 // Update or initialize a tessellation set and add it to the cache.
412 sk_sp<CachedTessellations> tessellations;
413 if (context.fTessellationsOnFailure) {
414 tessellations = std::move(context.fTessellationsOnFailure);
415 } else {
416 tessellations.reset(new CachedTessellations());
417 }
Jim Van Verth8793e382017-05-22 15:52:21 -0400418 vertices = tessellations->add(path.path(), factory, path.viewMatrix(),
419 &context.fTranslate);
Brian Salomond1ac9822017-02-03 14:25:02 -0500420 if (!vertices) {
Jim Van Verth22526362018-02-28 14:51:19 -0500421 return false;
Brian Salomond1ac9822017-02-03 14:25:02 -0500422 }
Brian Salomon804e0912017-02-23 09:34:03 -0500423 auto rec = new CachedTessellationsRec(*key, std::move(tessellations));
Jim Van Verth37c5a962017-05-10 14:13:24 -0400424 SkResourceCache::Add(rec);
Brian Salomond1ac9822017-02-03 14:25:02 -0500425 } else {
Jim Van Verth8793e382017-05-22 15:52:21 -0400426 vertices = factory.makeVertices(path.path(), path.viewMatrix(),
427 &context.fTranslate);
Brian Salomond1ac9822017-02-03 14:25:02 -0500428 if (!vertices) {
Jim Van Verth22526362018-02-28 14:51:19 -0500429 return false;
Brian Salomond1ac9822017-02-03 14:25:02 -0500430 }
Brian Salomon0dda9cb2017-02-03 10:33:25 -0500431 }
Brian Salomon5e689522017-02-01 12:07:17 -0500432 }
433
434 SkPaint paint;
Brian Salomon0bd699e2017-02-01 12:23:25 -0500435 // Run the vertex color through a GaussianColorFilter and then modulate the grayscale result of
436 // that against our 'color' param.
Mike Reed19d7bd62018-02-19 14:10:57 -0500437 paint.setColorFilter(
438 SkColorFilter::MakeModeFilter(color, SkBlendMode::kModulate)->makeComposed(
439 SkGaussianColorFilter::Make()));
Mike Reed4204da22017-05-17 08:53:36 -0400440
Jim Van Verth8793e382017-05-22 15:52:21 -0400441 drawProc(vertices.get(), SkBlendMode::kModulate, paint,
442 context.fTranslate.fX, context.fTranslate.fY);
Jim Van Verth22526362018-02-28 14:51:19 -0500443
444 return true;
Brian Salomon5e689522017-02-01 12:07:17 -0500445}
446}
447
Mike Reed4204da22017-05-17 08:53:36 -0400448static bool tilted(const SkPoint3& zPlaneParams) {
449 return !SkScalarNearlyZero(zPlaneParams.fX) || !SkScalarNearlyZero(zPlaneParams.fY);
450}
Jim Van Verthe7e1d9d2017-05-01 16:06:48 -0400451
Mike Reed4204da22017-05-17 08:53:36 -0400452static SkPoint3 map(const SkMatrix& m, const SkPoint3& pt) {
453 SkPoint3 result;
454 m.mapXY(pt.fX, pt.fY, (SkPoint*)&result.fX);
455 result.fZ = pt.fZ;
456 return result;
457}
458
Jim Van Verthb1b80f72018-01-18 15:19:13 -0500459void SkShadowUtils::ComputeTonalColors(SkColor inAmbientColor, SkColor inSpotColor,
460 SkColor* outAmbientColor, SkColor* outSpotColor) {
461 // For tonal color we only compute color values for the spot shadow.
462 // The ambient shadow is greyscale only.
Jim Van Verth34d6e4b2017-06-09 11:09:03 -0400463
Jim Van Verthb1b80f72018-01-18 15:19:13 -0500464 // Ambient
465 *outAmbientColor = SkColorSetARGB(SkColorGetA(inAmbientColor), 0, 0, 0);
Jim Van Verth34d6e4b2017-06-09 11:09:03 -0400466
Jim Van Verthb1b80f72018-01-18 15:19:13 -0500467 // Spot
468 int spotR = SkColorGetR(inSpotColor);
469 int spotG = SkColorGetG(inSpotColor);
470 int spotB = SkColorGetB(inSpotColor);
471 int max = SkTMax(SkTMax(spotR, spotG), spotB);
472 int min = SkTMin(SkTMin(spotR, spotG), spotB);
473 SkScalar luminance = 0.5f*(max + min)/255.f;
474 SkScalar origA = SkColorGetA(inSpotColor)/255.f;
475
476 // We compute a color alpha value based on the luminance of the color, scaled by an
477 // adjusted alpha value. We want the following properties to match the UX examples
478 // (assuming a = 0.25) and to ensure that we have reasonable results when the color
479 // is black and/or the alpha is 0:
480 // f(0, a) = 0
481 // f(luminance, 0) = 0
482 // f(1, 0.25) = .5
483 // f(0.5, 0.25) = .4
484 // f(1, 1) = 1
485 // The following functions match this as closely as possible.
486 SkScalar alphaAdjust = (2.6f + (-2.66667f + 1.06667f*origA)*origA)*origA;
487 SkScalar colorAlpha = (3.544762f + (-4.891428f + 2.3466f*luminance)*luminance)*luminance;
488 colorAlpha = SkTPin(alphaAdjust*colorAlpha, 0.0f, 1.0f);
489
490 // Similarly, we set the greyscale alpha based on luminance and alpha so that
491 // f(0, a) = a
492 // f(luminance, 0) = 0
493 // f(1, 0.25) = 0.15
494 SkScalar greyscaleAlpha = SkTPin(origA*(1 - 0.4f*luminance), 0.0f, 1.0f);
495
496 // The final color we want to emulate is generated by rendering a color shadow (C_rgb) using an
497 // alpha computed from the color's luminance (C_a), and then a black shadow with alpha (S_a)
498 // which is an adjusted value of 'a'. Assuming SrcOver, a background color of B_rgb, and
499 // ignoring edge falloff, this becomes
500 //
501 // (C_a - S_a*C_a)*C_rgb + (1 - (S_a + C_a - S_a*C_a))*B_rgb
502 //
503 // Assuming premultiplied alpha, this means we scale the color by (C_a - S_a*C_a) and
504 // set the alpha to (S_a + C_a - S_a*C_a).
505 SkScalar colorScale = colorAlpha*(SK_Scalar1 - greyscaleAlpha);
506 SkScalar tonalAlpha = colorScale + greyscaleAlpha;
507 SkScalar unPremulScale = colorScale / tonalAlpha;
508 *outSpotColor = SkColorSetARGB(tonalAlpha*255.999f,
509 unPremulScale*spotR,
510 unPremulScale*spotG,
511 unPremulScale*spotB);
Jim Van Verth060d9822017-05-04 09:58:17 -0400512}
513
Jim Van Verth43475ad2017-01-13 14:37:37 -0500514// Draw an offset spot shadow and outlining ambient shadow for the given path.
Jim Van Verth37c5a962017-05-10 14:13:24 -0400515void SkShadowUtils::DrawShadow(SkCanvas* canvas, const SkPath& path, const SkPoint3& zPlaneParams,
Brian Salomon0bd699e2017-02-01 12:23:25 -0500516 const SkPoint3& devLightPos, SkScalar lightRadius,
Jim Van Verthb1b80f72018-01-18 15:19:13 -0500517 SkColor ambientColor, SkColor spotColor,
Jim Van Verth37c5a962017-05-10 14:13:24 -0400518 uint32_t flags) {
Mike Reed4204da22017-05-17 08:53:36 -0400519 SkMatrix inverse;
520 if (!canvas->getTotalMatrix().invert(&inverse)) {
Jim Van Verthcf40e302017-03-02 11:28:43 -0500521 return;
522 }
Mike Reed4204da22017-05-17 08:53:36 -0400523 SkPoint pt = inverse.mapXY(devLightPos.fX, devLightPos.fY);
Jim Van Verthcf40e302017-03-02 11:28:43 -0500524
Mike Reed4204da22017-05-17 08:53:36 -0400525 SkDrawShadowRec rec;
526 rec.fZPlaneParams = zPlaneParams;
527 rec.fLightPos = { pt.fX, pt.fY, devLightPos.fZ };
528 rec.fLightRadius = lightRadius;
Jim Van Verthb1b80f72018-01-18 15:19:13 -0500529 rec.fAmbientColor = ambientColor;
530 rec.fSpotColor = spotColor;
Mike Reed4204da22017-05-17 08:53:36 -0400531 rec.fFlags = flags;
532
533 canvas->private_draw_shadow_rec(path, rec);
534}
535
Jim Van Vertha947e292018-02-26 13:54:34 -0500536static bool validate_rec(const SkDrawShadowRec& rec) {
537 return rec.fLightPos.isFinite() && rec.fZPlaneParams.isFinite() &&
538 SkScalarIsFinite(rec.fLightRadius);
539}
540
Mike Reed4204da22017-05-17 08:53:36 -0400541void SkBaseDevice::drawShadow(const SkPath& path, const SkDrawShadowRec& rec) {
542 auto drawVertsProc = [this](const SkVertices* vertices, SkBlendMode mode, const SkPaint& paint,
543 SkScalar tx, SkScalar ty) {
544 SkAutoDeviceCTMRestore adr(this, SkMatrix::Concat(this->ctm(),
545 SkMatrix::MakeTrans(tx, ty)));
546 this->drawVertices(vertices, mode, paint);
547 };
548
Jim Van Vertha947e292018-02-26 13:54:34 -0500549 if (!validate_rec(rec)) {
550 return;
551 }
552
Mike Reed4204da22017-05-17 08:53:36 -0400553 SkMatrix viewMatrix = this->ctm();
554 SkAutoDeviceCTMRestore adr(this, SkMatrix::I());
Jim Van Verthefe3ded2017-01-30 13:11:45 -0500555
Brian Salomon5e689522017-02-01 12:07:17 -0500556 ShadowedPath shadowedPath(&path, &viewMatrix);
557
Mike Reed4204da22017-05-17 08:53:36 -0400558 bool tiltZPlane = tilted(rec.fZPlaneParams);
559 bool transparent = SkToBool(rec.fFlags & SkShadowFlags::kTransparentOccluder_ShadowFlag);
Jim Van Verth4c9b8932017-05-15 13:49:21 -0400560 bool uncached = tiltZPlane || path.isVolatile();
Brian Salomon958fbc42017-01-30 17:01:28 -0500561
Mike Reed4204da22017-05-17 08:53:36 -0400562 SkPoint3 zPlaneParams = rec.fZPlaneParams;
563 SkPoint3 devLightPos = map(viewMatrix, rec.fLightPos);
564 float lightRadius = rec.fLightRadius;
565
Jim Van Verthb1b80f72018-01-18 15:19:13 -0500566 if (SkColorGetA(rec.fAmbientColor) > 0) {
Jim Van Verth22526362018-02-28 14:51:19 -0500567 bool success = false;
Jim Van Verth37c5a962017-05-10 14:13:24 -0400568 if (uncached) {
569 sk_sp<SkVertices> vertices = SkShadowTessellator::MakeAmbient(path, viewMatrix,
570 zPlaneParams,
571 transparent);
Jim Van Verth7d8955e2017-07-13 15:13:52 -0400572 if (vertices) {
573 SkPaint paint;
574 // Run the vertex color through a GaussianColorFilter and then modulate the
575 // grayscale result of that against our 'color' param.
Mike Reed19d7bd62018-02-19 14:10:57 -0500576 paint.setColorFilter(
577 SkColorFilter::MakeModeFilter(rec.fAmbientColor,
578 SkBlendMode::kModulate)->makeComposed(
579 SkGaussianColorFilter::Make()));
Jim Van Verth7d8955e2017-07-13 15:13:52 -0400580 this->drawVertices(vertices.get(), SkBlendMode::kModulate, paint);
Jim Van Verth22526362018-02-28 14:51:19 -0500581 success = true;
Jim Van Verth7d8955e2017-07-13 15:13:52 -0400582 }
Jim Van Verth22526362018-02-28 14:51:19 -0500583 }
584
585 if (!success) {
Jim Van Verth37c5a962017-05-10 14:13:24 -0400586 AmbientVerticesFactory factory;
587 factory.fOccluderHeight = zPlaneParams.fZ;
588 factory.fTransparent = transparent;
Jim Van Verth8793e382017-05-22 15:52:21 -0400589 if (viewMatrix.hasPerspective()) {
590 factory.fOffset.set(0, 0);
591 } else {
592 factory.fOffset.fX = viewMatrix.getTranslateX();
593 factory.fOffset.fY = viewMatrix.getTranslateY();
594 }
Jim Van Verth37c5a962017-05-10 14:13:24 -0400595
Jim Van Verth22526362018-02-28 14:51:19 -0500596 if (!draw_shadow(factory, drawVertsProc, shadowedPath, rec.fAmbientColor)) {
597 // Pretransform the path to avoid transforming the stroke, below.
598 SkPath devSpacePath;
599 path.transform(viewMatrix, &devSpacePath);
600
601 // The tesselator outsets by AmbientBlurRadius (or 'r') to get the outer ring of
602 // the tesselation, uses the original path as the inner ring, and sets the alpha
603 // of the inner ring to 1/AmbientRecipAlpha (or 'a').
604 //
605 // We want to emulate this with a blur. The full blur width (2*blurRadius or 'f')
606 // can be calculated by interpolating:
607 //
608 // original edge outer edge
609 // | |<---------- r ------>|
610 // |<------|--- f -------------->|
611 // | | |
612 // alpha = 1 alpha = a alpha = 0
613 //
614 // Taking ratios, f/1 = r/a, so f = r/a and blurRadius = f/2.
615 //
616 // We now need to outset the path to place the new edge in the center of the
617 // blur region:
618 //
619 // original new
620 // | |<------|--- r ------>|
621 // |<------|--- f -|------------>|
622 // | |<- o ->|<--- f/2 --->|
623 //
624 // r = o + f/2, so o = r - f/2
625 //
626 // We outset by using the stroker, so the strokeWidth is o/2.
627 //
628 SkScalar devSpaceOutset = SkDrawShadowMetrics::AmbientBlurRadius(zPlaneParams.fZ);
629 SkScalar oneOverA = SkDrawShadowMetrics::AmbientRecipAlpha(zPlaneParams.fZ);
630 SkScalar blurRadius = 0.5f*devSpaceOutset*oneOverA;
631 SkScalar strokeWidth = 0.5f*(devSpaceOutset - blurRadius);
632
633 // Now draw with blur
634 SkPaint paint;
635 paint.setColor(rec.fAmbientColor);
636 paint.setStrokeWidth(strokeWidth);
637 paint.setStyle(SkPaint::kStrokeAndFill_Style);
Mike Reed8e03f692018-03-09 16:18:56 -0500638 SkScalar sigma = SkBlurMask::ConvertRadiusToSigma(blurRadius);
Mike Reed18e75562018-03-12 14:03:47 -0400639 bool respectCTM = false;
640 paint.setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle, sigma, respectCTM));
Jim Van Verth22526362018-02-28 14:51:19 -0500641 this->drawPath(devSpacePath, paint);
642 }
Brian Salomond1ac9822017-02-03 14:25:02 -0500643 }
Jim Van Verthb4366552017-03-27 14:25:29 -0400644 }
645
Jim Van Verthb1b80f72018-01-18 15:19:13 -0500646 if (SkColorGetA(rec.fSpotColor) > 0) {
Jim Van Verth22526362018-02-28 14:51:19 -0500647 bool success = false;
Jim Van Verth37c5a962017-05-10 14:13:24 -0400648 if (uncached) {
649 sk_sp<SkVertices> vertices = SkShadowTessellator::MakeSpot(path, viewMatrix,
650 zPlaneParams,
651 devLightPos, lightRadius,
652 transparent);
Jim Van Verth7d8955e2017-07-13 15:13:52 -0400653 if (vertices) {
654 SkPaint paint;
655 // Run the vertex color through a GaussianColorFilter and then modulate the
656 // grayscale result of that against our 'color' param.
Mike Reed19d7bd62018-02-19 14:10:57 -0500657 paint.setColorFilter(
658 SkColorFilter::MakeModeFilter(rec.fSpotColor,
659 SkBlendMode::kModulate)->makeComposed(
Jim Van Verth22526362018-02-28 14:51:19 -0500660 SkGaussianColorFilter::Make()));
Jim Van Verth7d8955e2017-07-13 15:13:52 -0400661 this->drawVertices(vertices.get(), SkBlendMode::kModulate, paint);
Jim Van Verth22526362018-02-28 14:51:19 -0500662 success = true;
Jim Van Verth7d8955e2017-07-13 15:13:52 -0400663 }
Jim Van Verth22526362018-02-28 14:51:19 -0500664 }
Jim Van Vertha783c362017-05-11 17:05:28 -0400665
Jim Van Verth22526362018-02-28 14:51:19 -0500666 if (!success) {
667 SpotVerticesFactory factory;
668 factory.fOccluderHeight = zPlaneParams.fZ;
669 factory.fDevLightPos = devLightPos;
670 factory.fLightRadius = lightRadius;
671
Jim Van Verth37c5a962017-05-10 14:13:24 -0400672 SkPoint center = SkPoint::Make(path.getBounds().centerX(), path.getBounds().centerY());
Jim Van Verth8793e382017-05-22 15:52:21 -0400673 factory.fLocalCenter = center;
Jim Van Verth37c5a962017-05-10 14:13:24 -0400674 viewMatrix.mapPoints(&center, 1);
Jim Van Verth22526362018-02-28 14:51:19 -0500675 SkScalar radius, scale;
676 SkDrawShadowMetrics::GetSpotParams(zPlaneParams.fZ, devLightPos.fX - center.fX,
677 devLightPos.fY - center.fY, devLightPos.fZ,
678 lightRadius, &radius, &scale, &factory.fOffset);
Jim Van Vertha783c362017-05-11 17:05:28 -0400679 SkRect devBounds;
680 viewMatrix.mapRect(&devBounds, path.getBounds());
Jim Van Verth8793e382017-05-22 15:52:21 -0400681 if (transparent ||
682 SkTAbs(factory.fOffset.fX) > 0.5f*devBounds.width() ||
683 SkTAbs(factory.fOffset.fY) > 0.5f*devBounds.height()) {
Jim Van Verth78c8f302017-05-15 10:44:22 -0400684 // if the translation of the shadow is big enough we're going to end up
685 // filling the entire umbra, so we can treat these as all the same
Jim Van Verth8793e382017-05-22 15:52:21 -0400686 factory.fOccluderType = SpotVerticesFactory::OccluderType::kTransparent;
Jim Van Verth78c8f302017-05-15 10:44:22 -0400687 } else if (factory.fOffset.length()*scale + scale < radius) {
Jim Van Vertha783c362017-05-11 17:05:28 -0400688 // if we don't translate more than the blur distance, can assume umbra is covered
Jim Van Verth78c8f302017-05-15 10:44:22 -0400689 factory.fOccluderType = SpotVerticesFactory::OccluderType::kOpaqueNoUmbra;
Jim Van Vertha783c362017-05-11 17:05:28 -0400690 } else {
Jim Van Verth78c8f302017-05-15 10:44:22 -0400691 factory.fOccluderType = SpotVerticesFactory::OccluderType::kOpaquePartialUmbra;
Jim Van Vertha783c362017-05-11 17:05:28 -0400692 }
Jim Van Verth8793e382017-05-22 15:52:21 -0400693 // need to add this after we classify the shadow
694 factory.fOffset.fX += viewMatrix.getTranslateX();
695 factory.fOffset.fY += viewMatrix.getTranslateY();
Jim Van Verth22526362018-02-28 14:51:19 -0500696
697 SkColor color = rec.fSpotColor;
Jim Van Vertha783c362017-05-11 17:05:28 -0400698#ifdef DEBUG_SHADOW_CHECKS
699 switch (factory.fOccluderType) {
700 case SpotVerticesFactory::OccluderType::kTransparent:
701 color = 0xFFD2B48C; // tan for transparent
702 break;
Jim Van Verth78c8f302017-05-15 10:44:22 -0400703 case SpotVerticesFactory::OccluderType::kOpaquePartialUmbra:
Jim Van Vertha783c362017-05-11 17:05:28 -0400704 color = 0xFFFFA500; // orange for opaque
705 break;
Jim Van Verth78c8f302017-05-15 10:44:22 -0400706 case SpotVerticesFactory::OccluderType::kOpaqueNoUmbra:
707 color = 0xFFE5E500; // corn yellow for covered
Jim Van Vertha783c362017-05-11 17:05:28 -0400708 break;
709 }
710#endif
Jim Van Verth22526362018-02-28 14:51:19 -0500711 if (!draw_shadow(factory, drawVertsProc, shadowedPath, color)) {
712 // draw with blur
713 SkVector translate;
714 SkDrawShadowMetrics::GetSpotParams(zPlaneParams.fZ, devLightPos.fX,
715 devLightPos.fY, devLightPos.fZ,
716 lightRadius, &radius, &scale, &translate);
717 SkMatrix shadowMatrix;
718 shadowMatrix.setScaleTranslate(scale, scale, translate.fX, translate.fY);
719 SkAutoDeviceCTMRestore adr(this, SkMatrix::Concat(shadowMatrix, viewMatrix));
720
721 SkPaint paint;
722 paint.setColor(rec.fSpotColor);
Mike Reed8e03f692018-03-09 16:18:56 -0500723 SkScalar sigma = SkBlurMask::ConvertRadiusToSigma(radius);
Mike Reed18e75562018-03-12 14:03:47 -0400724 bool respectCTM = false;
725 paint.setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle, sigma, respectCTM));
Jim Van Verth22526362018-02-28 14:51:19 -0500726 this->drawPath(path, paint);
727 }
Jim Van Verth37c5a962017-05-10 14:13:24 -0400728 }
Jim Van Verthb4366552017-03-27 14:25:29 -0400729 }
730}