aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/utils
diff options
context:
space:
mode:
authorGravatar Jim Van Verth <jvanverth@google.com>2017-05-10 14:13:24 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-05-10 19:27:39 +0000
commit37c5a96bbdeac2000c8b31d40f4786b31c39f2dd (patch)
treea9f582e9f528d332441fc47288af9f2861287c5c /include/utils
parent77ced29102c8bc3b8c067e56504ad8411c1176a8 (diff)
Unify ShadowUtils interface
Bug: skia: Change-Id: I116bec82783d297e91ef061217b5e61f7ff16a76 Reviewed-on: https://skia-review.googlesource.com/16371 Reviewed-by: Mike Reed <reed@google.com> Commit-Queue: Jim Van Verth <jvanverth@google.com>
Diffstat (limited to 'include/utils')
-rw-r--r--include/utils/SkShadowUtils.h74
1 files changed, 39 insertions, 35 deletions
diff --git a/include/utils/SkShadowUtils.h b/include/utils/SkShadowUtils.h
index 4a497bb397..bf804a581f 100644
--- a/include/utils/SkShadowUtils.h
+++ b/include/utils/SkShadowUtils.h
@@ -21,12 +21,14 @@ class SkShadowUtils {
public:
/**
* Draw an offset spot shadow and outlining ambient shadow for the given path using a disc
- * light.
+ * light. The shadow may be cached, depending on the path type and canvas matrix. If the
+ * matrix is perspective or the path is volatile, it will not be cached.
*
* @param canvas The canvas on which to draw the shadows.
* @param path The occluder used to generate the shadows.
- * @param occluderHeight The vertical offset of the occluder from the canvas. This is
- * independent of the canvas's current matrix.
+ * @param zPlaneParams Values for the plane function which returns the Z offset of the
+ * occluder from the canvas based on local x and y values (the current matrix is not applied).
+ * If the canvas matrix is not perspective, then only zPlaneParams.fZ is used.
* @param lightPos The 3D position of the light relative to the canvas plane. This is
* independent of the canvas's current matrix.
* @param lightRadius The radius of the disc light.
@@ -35,20 +37,47 @@ public:
* @param color The shadow color.
* @param flags Options controlling opaque occluder optimizations and shadow appearance. See
* SkShadowFlags.
- * @param cache Used for testing purposes. Clients should pass nullptr (default).
*/
+ static void DrawShadow(SkCanvas* canvas, const SkPath& path, const SkPoint3& zPlaneParams,
+ const SkPoint3& lightPos, SkScalar lightRadius, SkScalar ambientAlpha,
+ SkScalar spotAlpha, SkColor color,
+ uint32_t flags = SkShadowFlags::kNone_ShadowFlag);
+
+ /**
+ * Draw an offset spot shadow and outlining ambient shadow for the given path using a disc
+ * light.
+ *
+ * Deprecated version with height value (to be removed when Android and Flutter are updated).
+ *
+ * @param canvas The canvas on which to draw the shadows.
+ * @param path The occluder used to generate the shadows.
+ * @param occluderHeight The vertical offset of the occluder from the canvas. This is
+ * independent of the canvas's current matrix.
+ * @param lightPos The 3D position of the light relative to the canvas plane. This is
+ * independent of the canvas's current matrix.
+ * @param lightRadius The radius of the disc light.
+ * @param ambientAlpha The maximum alpha of the ambient shadow.
+ * @param spotAlpha The maxium alpha of the spot shadow.
+ * @param color The shadow color.
+ * @param flags Options controlling opaque occluder optimizations and shadow appearance. See
+ * SkShadowFlags.
+ */
static void DrawShadow(SkCanvas* canvas, const SkPath& path, SkScalar occluderHeight,
const SkPoint3& lightPos, SkScalar lightRadius, SkScalar ambientAlpha,
SkScalar spotAlpha, SkColor color,
- uint32_t flags = SkShadowFlags::kNone_ShadowFlag,
- SkResourceCache* cache = nullptr);
+ uint32_t flags = SkShadowFlags::kNone_ShadowFlag) {
+ SkPoint3 zPlane = SkPoint3::Make(0, 0, occluderHeight);
+ DrawShadow(canvas, path, zPlane, lightPos, lightRadius, ambientAlpha, spotAlpha,
+ color, flags);
+ }
+#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
/**
* Draw an offset spot shadow and outlining ambient shadow for the given path using a disc
* light. Takes a function to vary the z value based on the local x and y position.
* This shadow will not be cached, as the assumption is that this will be used for animation.
*
- * Deprecated version with height functor (to be removed when Android is updated).
+ * Deprecated (to be removed when Android is updated).
*
* @param canvas The canvas on which to draw the shadows.
* @param path The occluder used to generate the shadows.
@@ -73,35 +102,10 @@ public:
zPlane.fX = heightFunc(1, 0) - zPlane.fZ;
zPlane.fY = heightFunc(0, 1) - zPlane.fZ;
- DrawUncachedShadow(canvas, path, zPlane, lightPos, lightRadius, ambientAlpha, spotAlpha,
- color, flags);
+ DrawShadow(canvas, path, zPlane, lightPos, lightRadius, ambientAlpha, spotAlpha,
+ color, flags);
}
-
- /**
- * Draw an offset spot shadow and outlining ambient shadow for the given path using a disc
- * light. Uses a plane function to vary the z value based on the local x and y position.
- * This shadow will not be cached, as the assumption is that this will be used for animation.
- *
- * @param canvas The canvas on which to draw the shadows.
- * @param path The occluder used to generate the shadows.
- * @param zPlaneParams Values for the plane function which returns the Z offset of the
- * occluder from the canvas based on local x and y values (the current matrix is not applied).
- * @param lightPos The 3D position of the light relative to the canvas plane. This is
- * independent of the canvas's current matrix.
- * @param lightRadius The radius of the disc light.
- * @param ambientAlpha The maximum alpha of the ambient shadow.
- * @param spotAlpha The maxium alpha of the spot shadow.
- * @param color The shadow color.
- * @param flags Options controlling opaque occluder optimizations and shadow appearance. See
- * SkShadowFlags.
- */
- static void DrawUncachedShadow(SkCanvas* canvas, const SkPath& path,
- const SkPoint3& zPlaneParams,
- const SkPoint3& lightPos, SkScalar lightRadius,
- SkScalar ambientAlpha, SkScalar spotAlpha, SkColor color,
- uint32_t flags = SkShadowFlags::kNone_ShadowFlag);
-
-
+#endif
};
#endif