aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--gn/effects.gni2
-rw-r--r--gn/utils.gni2
-rwxr-xr-xinclude/utils/SkShadowUtils.h39
-rw-r--r--samplecode/SampleAndroidShadows.cpp15
-rwxr-xr-xsrc/effects/SkShadowMaskFilter.cpp2
-rwxr-xr-xsrc/effects/SkShadowMaskFilter.h (renamed from include/effects/SkShadowMaskFilter.h)0
-rwxr-xr-xsrc/utils/SkShadowUtils.cpp23
7 files changed, 72 insertions, 11 deletions
diff --git a/gn/effects.gni b/gn/effects.gni
index 30e36b22d8..b8bc2b16cc 100644
--- a/gn/effects.gni
+++ b/gn/effects.gni
@@ -59,6 +59,7 @@ skia_effects_sources = [
"$_src/effects/SkPictureImageFilter.cpp",
"$_src/effects/SkRRectsGaussianEdgeMaskFilter.cpp",
"$_src/effects/SkShadowMaskFilter.cpp",
+ "$_src/effects/SkShadowMaskFilter.h",
"$_src/effects/SkTableColorFilter.cpp",
"$_src/effects/SkTableMaskFilter.cpp",
"$_src/effects/SkTileImageFilter.cpp",
@@ -118,7 +119,6 @@ skia_effects_sources = [
"$_include/effects/SkPaintImageFilter.h",
"$_include/effects/SkPerlinNoiseShader.h",
"$_include/effects/SkRRectsGaussianEdgeMaskFilter.h",
- "$_include/effects/SkShadowMaskFilter.h",
"$_include/effects/SkTableColorFilter.h",
"$_include/effects/SkTableMaskFilter.h",
"$_include/effects/SkTileImageFilter.h",
diff --git a/gn/utils.gni b/gn/utils.gni
index 432f48cbda..068881f605 100644
--- a/gn/utils.gni
+++ b/gn/utils.gni
@@ -25,6 +25,7 @@ skia_utils_sources = [
"$_include/utils/SkParsePath.h",
"$_include/utils/SkPictureUtils.h",
"$_include/utils/SkRandom.h",
+ "$_include/utils/SkShadowUtils.h",
"$_include/utils/SkTextBox.h",
"$_src/utils/SkBase64.cpp",
@@ -68,6 +69,7 @@ skia_utils_sources = [
"$_src/utils/SkRGBAToYUV.h",
"$_src/utils/SkShadowPaintFilterCanvas.cpp",
"$_src/utils/SkShadowPaintFilterCanvas.h",
+ "$_src/utils/SkShadowUtils.cpp",
"$_src/utils/SkTextBox.cpp",
"$_src/utils/SkTextureCompressor.cpp",
"$_src/utils/SkTextureCompressor.h",
diff --git a/include/utils/SkShadowUtils.h b/include/utils/SkShadowUtils.h
new file mode 100755
index 0000000000..c3809295fb
--- /dev/null
+++ b/include/utils/SkShadowUtils.h
@@ -0,0 +1,39 @@
+
+/*
+ * Copyright 2017 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+#ifndef SkShadowUtils_DEFINED
+#define SkShadowUtils_DEFINED
+
+#include "SkColor.h"
+#include "SkScalar.h"
+
+class SkCanvas;
+class SkPath;
+
+class SkShadowUtils {
+public:
+ enum ShadowFlags {
+ kNone_ShadowFlag = 0x00,
+ /** The occluding object is not opaque. Knowing that the occluder is opaque allows
+ * us to cull shadow geometry behind it and improve performance. */
+ kTransparentOccluder_ShadowFlag = 0x01,
+ /** Use a larger umbra for a darker shadow */
+ kLargerUmbra_ShadowFlag = 0x02,
+ /** Use a Gaussian for the edge function rather than smoothstep */
+ kGaussianEdge_ShadowFlag = 0x04,
+ /** mask for all shadow flags */
+ kAll_ShadowFlag = 0x07
+ };
+
+ // Draw an offset spot shadow and outlining ambient shadow for the given path.
+ static void DrawShadow(SkCanvas*, const SkPath& path, SkScalar occluderHeight,
+ const SkPoint3& lightPos, SkScalar lightRadius,
+ SkScalar ambientAlpha, SkScalar spotAlpha, SkColor color,
+ uint32_t flags = kNone_ShadowFlag);
+};
+
+#endif
diff --git a/samplecode/SampleAndroidShadows.cpp b/samplecode/SampleAndroidShadows.cpp
index 87fa0510fe..d9e513b5c4 100644
--- a/samplecode/SampleAndroidShadows.cpp
+++ b/samplecode/SampleAndroidShadows.cpp
@@ -12,11 +12,13 @@
#include "SkGaussianEdgeShader.h"
#include "SkPath.h"
#include "SkPoint3.h"
-#include "SkShadowMaskFilter.h"
+#include "SkShadowUtils.h"
#include "SkUtils.h"
#include "SkView.h"
#include "sk_tool_utils.h"
+#define USE_SHADOW_UTILS
+
////////////////////////////////////////////////////////////////////////////
class ShadowsView : public SampleView {
@@ -367,7 +369,7 @@ protected:
void drawShadowedPath(SkCanvas* canvas, const SkPath& path, SkScalar zValue,
const SkPaint& paint, SkScalar ambientAlpha,
const SkPoint3& lightPos, SkScalar lightWidth, SkScalar spotAlpha) {
-#ifdef USE_MASK_FILTER
+#ifdef USE_SHADOW_UTILS
if (fUseAlt) {
if (fShowAmbient) {
this->drawAmbientShadowAlt(canvas, path, zValue, ambientAlpha);
@@ -376,19 +378,14 @@ protected:
this->drawSpotShadowAlt(canvas, path, zValue, lightPos, lightWidth, spotAlpha);
}
} else {
- SkPaint newPaint;
- newPaint.setColor(SK_ColorBLACK);
if (!fShowAmbient) {
ambientAlpha = 0;
}
if (!fShowSpot) {
spotAlpha = 0;
}
-
- newPaint.setMaskFilter(SkShadowMaskFilter::Make(zValue, lightPos, lightWidth,
- ambientAlpha, spotAlpha));
-
- canvas->drawPath(path, newPaint);
+ SkShadowUtils::DrawShadow(canvas, path, zValue, lightPos, lightWidth,
+ ambientAlpha, spotAlpha, SK_ColorBLACK);
}
#else
if (fShowAmbient) {
diff --git a/src/effects/SkShadowMaskFilter.cpp b/src/effects/SkShadowMaskFilter.cpp
index f1012f5e0f..61a93b8982 100755
--- a/src/effects/SkShadowMaskFilter.cpp
+++ b/src/effects/SkShadowMaskFilter.cpp
@@ -234,7 +234,7 @@ bool SkShadowMaskFilterImpl::directFilterRRectMaskGPU(GrContext*,
static const float kGeomFactor = 64.0f;
SkScalar srcSpaceAmbientRadius = fOccluderHeight * kHeightFactor * kGeomFactor;
- const float umbraAlpha = 1.0f / (1.0f + SkTMax(fOccluderHeight * kHeightFactor, 0.0f));
+ const float umbraAlpha = (1.0f + SkTMax(fOccluderHeight * kHeightFactor, 0.0f));
const SkScalar ambientOffset = srcSpaceAmbientRadius * umbraAlpha;
// For the ambient rrect, we inset the offset rect by half the srcSpaceAmbientRadius
diff --git a/include/effects/SkShadowMaskFilter.h b/src/effects/SkShadowMaskFilter.h
index a85da63db9..a85da63db9 100755
--- a/include/effects/SkShadowMaskFilter.h
+++ b/src/effects/SkShadowMaskFilter.h
diff --git a/src/utils/SkShadowUtils.cpp b/src/utils/SkShadowUtils.cpp
new file mode 100755
index 0000000000..e8a1f831d3
--- /dev/null
+++ b/src/utils/SkShadowUtils.cpp
@@ -0,0 +1,23 @@
+/*
+* Copyright 2017 Google Inc.
+*
+* Use of this source code is governed by a BSD-style license that can be
+* found in the LICENSE file.
+*/
+
+#include "SkShadowUtils.h"
+#include "SkCanvas.h"
+#include "../effects/SkShadowMaskFilter.h"
+
+// Draw an offset spot shadow and outlining ambient shadow for the given path.
+void SkShadowUtils::DrawShadow(SkCanvas* canvas, const SkPath& path, SkScalar occluderHeight,
+ const SkPoint3& lightPos, SkScalar lightRadius,
+ SkScalar ambientAlpha, SkScalar spotAlpha, SkColor color,
+ uint32_t flags) {
+ SkPaint newPaint;
+ newPaint.setColor(color);
+ newPaint.setMaskFilter(SkShadowMaskFilter::Make(occluderHeight, lightPos, lightRadius,
+ ambientAlpha, spotAlpha, flags));
+
+ canvas->drawPath(path, newPaint);
+}