Jim Van Verth | 43475ad | 2017-01-13 14:37:37 -0500 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2017 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 7 | */ |
| 8 | #ifndef SkShadowUtils_DEFINED |
| 9 | #define SkShadowUtils_DEFINED |
| 10 | |
| 11 | #include "SkColor.h" |
Mike Reed | 54518ac | 2017-07-22 08:29:48 -0400 | [diff] [blame] | 12 | #include "SkPoint3.h" |
Jim Van Verth | 43475ad | 2017-01-13 14:37:37 -0500 | [diff] [blame] | 13 | #include "SkScalar.h" |
Jim Van Verth | 2103cf0 | 2017-01-16 13:03:37 -0500 | [diff] [blame] | 14 | #include "../private/SkShadowFlags.h" |
Jim Van Verth | 43475ad | 2017-01-13 14:37:37 -0500 | [diff] [blame] | 15 | |
| 16 | class SkCanvas; |
| 17 | class SkPath; |
Brian Salomon | 804e091 | 2017-02-23 09:34:03 -0500 | [diff] [blame] | 18 | class SkResourceCache; |
Jim Van Verth | 43475ad | 2017-01-13 14:37:37 -0500 | [diff] [blame] | 19 | |
Derek Sollenberger | 2fbf1bc | 2017-09-20 15:51:08 -0400 | [diff] [blame] | 20 | class SK_API SkShadowUtils { |
Jim Van Verth | 43475ad | 2017-01-13 14:37:37 -0500 | [diff] [blame] | 21 | public: |
Brian Salomon | 804e091 | 2017-02-23 09:34:03 -0500 | [diff] [blame] | 22 | /** |
| 23 | * Draw an offset spot shadow and outlining ambient shadow for the given path using a disc |
Jim Van Verth | 37c5a96 | 2017-05-10 14:13:24 -0400 | [diff] [blame] | 24 | * light. The shadow may be cached, depending on the path type and canvas matrix. If the |
| 25 | * matrix is perspective or the path is volatile, it will not be cached. |
Brian Salomon | 804e091 | 2017-02-23 09:34:03 -0500 | [diff] [blame] | 26 | * |
| 27 | * @param canvas The canvas on which to draw the shadows. |
| 28 | * @param path The occluder used to generate the shadows. |
Jim Van Verth | 37c5a96 | 2017-05-10 14:13:24 -0400 | [diff] [blame] | 29 | * @param zPlaneParams Values for the plane function which returns the Z offset of the |
| 30 | * occluder from the canvas based on local x and y values (the current matrix is not applied). |
Brian Salomon | 804e091 | 2017-02-23 09:34:03 -0500 | [diff] [blame] | 31 | * @param lightPos The 3D position of the light relative to the canvas plane. This is |
| 32 | * independent of the canvas's current matrix. |
| 33 | * @param lightRadius The radius of the disc light. |
Jim Van Verth | b1b80f7 | 2018-01-18 15:19:13 -0500 | [diff] [blame] | 34 | * @param ambientColor The color of the ambient shadow. |
| 35 | * @param spotColor The color of the spot shadow. |
| 36 | * @param flags Options controlling opaque occluder optimizations and shadow appearance. See |
| 37 | * SkShadowFlags. |
| 38 | */ |
| 39 | static void DrawShadow(SkCanvas* canvas, const SkPath& path, const SkPoint3& zPlaneParams, |
| 40 | const SkPoint3& lightPos, SkScalar lightRadius, |
| 41 | SkColor ambientColor, SkColor spotColor, |
| 42 | uint32_t flags = SkShadowFlags::kNone_ShadowFlag); |
| 43 | |
| 44 | /** |
Jim Van Verth | a556684 | 2018-02-22 10:58:34 -0500 | [diff] [blame] | 45 | * Helper routine to compute color values for one-pass tonal alpha. |
Jim Van Verth | b1b80f7 | 2018-01-18 15:19:13 -0500 | [diff] [blame] | 46 | * |
Jim Van Verth | a556684 | 2018-02-22 10:58:34 -0500 | [diff] [blame] | 47 | * @param inAmbientColor Original ambient color |
| 48 | * @param inSpotColor Original spot color |
| 49 | * @param outAmbientColor Modified ambient color |
| 50 | * @param outSpotColor Modified spot color |
Brian Salomon | 804e091 | 2017-02-23 09:34:03 -0500 | [diff] [blame] | 51 | */ |
Jim Van Verth | b1b80f7 | 2018-01-18 15:19:13 -0500 | [diff] [blame] | 52 | static void ComputeTonalColors(SkColor inAmbientColor, SkColor inSpotColor, |
| 53 | SkColor* outAmbientColor, SkColor* outSpotColor); |
Jim Van Verth | 43475ad | 2017-01-13 14:37:37 -0500 | [diff] [blame] | 54 | }; |
| 55 | |
| 56 | #endif |