1 /* 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 15 class SkMatrix; 16 class SkPath; 17 struct SkRect; 18 19 struct SkDrawShadowRec { 20 SkPoint3 fZPlaneParams; 21 SkPoint3 fLightPos; 22 SkScalar fLightRadius; 23 SkColor fAmbientColor; 24 SkColor fSpotColor; 25 uint32_t fFlags; 26 }; 27 28 namespace SkDrawShadowMetrics { 29 30 static constexpr auto kAmbientHeightFactor = 1.0f / 128.0f; 31 static constexpr auto kAmbientGeomFactor = 64.0f; 32 33 inline SkScalar AmbientBlurRadius(SkScalar height) { 34 return height*kAmbientHeightFactor*kAmbientGeomFactor; 35 } 36 37 inline SkScalar AmbientRecipAlpha(SkScalar height) { 38 return 1.0f + SkTMax(height*kAmbientHeightFactor, 0.0f); 39 } 40 41 inline SkScalar SpotBlurRadius(SkScalar occluderZ, SkScalar lightZ, SkScalar lightRadius) { 42 return lightRadius*SkTPin(occluderZ / (lightZ - occluderZ), 0.0f, 0.95f); 43 } 44 45 inline void GetSpotParams(SkScalar occluderZ, SkScalar lightX, SkScalar lightY, SkScalar lightZ, 46 SkScalar lightRadius, 47 SkScalar* blurRadius, SkScalar* scale, SkVector* translate) { 48 SkScalar zRatio = SkTPin(occluderZ / (lightZ - occluderZ), 0.0f, 0.95f); 49 *blurRadius = lightRadius*zRatio; 50 *scale = SkTMax(lightZ / (lightZ - occluderZ), 1.0f); 51 *translate = SkVector::Make(-zRatio * lightX, -zRatio * lightY); 52 } 53 54 // get bounds prior to the ctm being applied 55 void GetLocalBounds(const SkPath&, const SkDrawShadowRec&, const SkMatrix& ctm, SkRect* bounds); 56 57 } 58 59 #endif 60