blob: a08256b8cdea856a621efea7d180ff68028cf357 [file] [log] [blame]
Jim Van Verth1af03d42017-07-31 09:34:58 -04001/*
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#ifndef SkDrawShadowInfo_DEFINED
9#define SkDrawShadowInfo_DEFINED
10
11#include "SkColor.h"
12#include "SkPoint.h"
13#include "SkPoint3.h"
14
15class SkMatrix;
16class SkPath;
17struct SkRect;
18
19struct SkDrawShadowRec {
20 SkPoint3 fZPlaneParams;
21 SkPoint3 fLightPos;
22 SkScalar fLightRadius;
23 SkScalar fAmbientAlpha;
24 SkScalar fSpotAlpha;
25 SkColor fColor;
26 uint32_t fFlags;
27};
28
29namespace SkDrawShadowMetrics {
30
31static constexpr auto kAmbientHeightFactor = 1.0f / 128.0f;
32static constexpr auto kAmbientGeomFactor = 64.0f;
33
34inline SkScalar AmbientBlurRadius(SkScalar height) {
35 return height*kAmbientHeightFactor*kAmbientGeomFactor;
36}
37
38inline SkScalar AmbientRecipAlpha(SkScalar height) {
39 return 1.0f + SkTMax(height*kAmbientHeightFactor, 0.0f);
40}
41
42inline SkScalar SpotBlurRadius(SkScalar occluderZ, SkScalar lightZ, SkScalar lightRadius) {
43 return lightRadius*SkTPin(occluderZ / (lightZ - occluderZ), 0.0f, 0.95f);
44}
45
46inline void GetSpotParams(SkScalar occluderZ, SkScalar lightX, SkScalar lightY, SkScalar lightZ,
47 SkScalar lightRadius,
48 SkScalar* blurRadius, SkScalar* scale, SkVector* translate) {
49 SkScalar zRatio = SkTPin(occluderZ / (lightZ - occluderZ), 0.0f, 0.95f);
50 *blurRadius = lightRadius*zRatio;
51 *scale = SkTMax(lightZ / (lightZ - occluderZ), 1.0f);
52 *translate = SkVector::Make(-zRatio * lightX, -zRatio * lightY);
53}
54
55// get bounds prior to the ctm being applied
56void GetLocalBounds(const SkPath&, const SkDrawShadowRec&, const SkMatrix& ctm, SkRect* bounds);
57
58}
59
60#endif