• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "include/core/SkColor.h"
12 #include "include/core/SkPoint3.h"
13 #include "include/core/SkScalar.h"
14 #include "include/private/SkShadowFlags.h"
15 
16 class SkCanvas;
17 class SkPath;
18 class SkResourceCache;
19 
20 class SK_API SkShadowUtils {
21 public:
22     /**
23      * Draw an offset spot shadow and outlining ambient shadow for the given path using a disc
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.
26      *
27      * @param canvas  The canvas on which to draw the shadows.
28      * @param path  The occluder used to generate the shadows.
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).
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.
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     /**
45      * Helper routine to compute color values for one-pass tonal alpha.
46      *
47      * @param inAmbientColor  Original ambient color
48      * @param inSpotColor  Original spot color
49      * @param outAmbientColor  Modified ambient color
50      * @param outSpotColor  Modified spot color
51      */
52     static void ComputeTonalColors(SkColor inAmbientColor, SkColor inSpotColor,
53                                    SkColor* outAmbientColor, SkColor* outSpotColor);
54 };
55 
56 #endif
57