Flutter Engine
The Flutter Engine
SkShadowUtils.h
Go to the documentation of this file.
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
14
15#include <cstdint>
16
17class SkCanvas;
18class SkMatrix;
19class SkPath;
20struct SkPoint3;
21struct SkRect;
22
25 /** The occluding object is not opaque. Knowing that the occluder is opaque allows
26 * us to cull shadow geometry behind it and improve performance. */
28 /** Don't try to use analytic shadows. */
30 /** Light position represents a direction, light radius is blur radius at elevation 1 */
32 /** Concave paths will only use blur to generate the shadow */
34 /** mask for all shadow flags */
35 kAll_ShadowFlag = 0x0F
36};
37
39public:
40 /**
41 * Draw an offset spot shadow and outlining ambient shadow for the given path using a disc
42 * light. The shadow may be cached, depending on the path type and canvas matrix. If the
43 * matrix is perspective or the path is volatile, it will not be cached.
44 *
45 * @param canvas The canvas on which to draw the shadows.
46 * @param path The occluder used to generate the shadows.
47 * @param zPlaneParams Values for the plane function which returns the Z offset of the
48 * occluder from the canvas based on local x and y values (the current matrix is not applied).
49 * @param lightPos Generally, the 3D position of the light relative to the canvas plane.
50 * If kDirectionalLight_ShadowFlag is set, this specifies a vector pointing
51 * towards the light.
52 * @param lightRadius Generally, the radius of the disc light.
53 * If DirectionalLight_ShadowFlag is set, this specifies the amount of
54 * blur when the occluder is at Z offset == 1. The blur will grow linearly
55 * as the Z value increases.
56 * @param ambientColor The color of the ambient shadow.
57 * @param spotColor The color of the spot shadow.
58 * @param flags Options controlling opaque occluder optimizations, shadow appearance,
59 * and light position. See SkShadowFlags.
60 */
61 static void DrawShadow(SkCanvas* canvas, const SkPath& path, const SkPoint3& zPlaneParams,
62 const SkPoint3& lightPos, SkScalar lightRadius,
63 SkColor ambientColor, SkColor spotColor,
65
66 /**
67 * Generate bounding box for shadows relative to path. Includes both the ambient and spot
68 * shadow bounds.
69 *
70 * @param ctm Current transformation matrix to device space.
71 * @param path The occluder used to generate the shadows.
72 * @param zPlaneParams Values for the plane function which returns the Z offset of the
73 * occluder from the canvas based on local x and y values (the current matrix is not applied).
74 * @param lightPos Generally, the 3D position of the light relative to the canvas plane.
75 * If kDirectionalLight_ShadowFlag is set, this specifies a vector pointing
76 * towards the light.
77 * @param lightRadius Generally, the radius of the disc light.
78 * If DirectionalLight_ShadowFlag is set, this specifies the amount of
79 * blur when the occluder is at Z offset == 1. The blur will grow linearly
80 * as the Z value increases.
81 * @param flags Options controlling opaque occluder optimizations, shadow appearance,
82 * and light position. See SkShadowFlags.
83 * @param bounds Return value for shadow bounding box.
84 * @return Returns true if successful, false otherwise.
85 */
86 static bool GetLocalBounds(const SkMatrix& ctm, const SkPath& path,
87 const SkPoint3& zPlaneParams, const SkPoint3& lightPos,
88 SkScalar lightRadius, uint32_t flags, SkRect* bounds);
89
90 /**
91 * Helper routine to compute color values for one-pass tonal alpha.
92 *
93 * @param inAmbientColor Original ambient color
94 * @param inSpotColor Original spot color
95 * @param outAmbientColor Modified ambient color
96 * @param outSpotColor Modified spot color
97 */
98 static void ComputeTonalColors(SkColor inAmbientColor, SkColor inSpotColor,
99 SkColor* outAmbientColor, SkColor* outSpotColor);
100};
101
102#endif
#define SK_API
Definition: SkAPI.h:35
uint32_t SkColor
Definition: SkColor.h:37
SkShadowFlags
Definition: SkShadowUtils.h:23
@ kAll_ShadowFlag
Definition: SkShadowUtils.h:35
@ kDirectionalLight_ShadowFlag
Definition: SkShadowUtils.h:31
@ kConcaveBlurOnly_ShadowFlag
Definition: SkShadowUtils.h:33
@ kGeometricOnly_ShadowFlag
Definition: SkShadowUtils.h:29
@ kTransparentOccluder_ShadowFlag
Definition: SkShadowUtils.h:27
@ kNone_ShadowFlag
Definition: SkShadowUtils.h:24
Definition: SkPath.h:59
float SkScalar
Definition: extension.cpp:12
FlutterSemanticsFlag flags
void GetLocalBounds(const SkPath &path, const SkDrawShadowRec &rec, const SkMatrix &ctm, SkRect *bounds)
Optional< SkRect > bounds
Definition: SkRecords.h:189
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57