diff options
author | vjiaoblack <vjiaoblack@google.com> | 2016-08-25 06:30:23 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-08-25 06:30:23 -0700 |
commit | e6f5d5623160a69e1585f5121a3695092327dfe0 (patch) | |
tree | 44a73f37db340157c73e005841207e52210e78d0 /src/utils | |
parent | 199a2ea665a088dafb2fd364f3aa6a642bfa2fef (diff) |
Made shadows blurry (thru implementing variance mapping)
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2224163005
Review-Url: https://codereview.chromium.org/2224163005
Diffstat (limited to 'src/utils')
-rw-r--r-- | src/utils/SkShadowPaintFilterCanvas.cpp | 21 | ||||
-rw-r--r-- | src/utils/SkShadowPaintFilterCanvas.h | 2 |
2 files changed, 22 insertions, 1 deletions
diff --git a/src/utils/SkShadowPaintFilterCanvas.cpp b/src/utils/SkShadowPaintFilterCanvas.cpp index f59facb17c..2a090b78e2 100644 --- a/src/utils/SkShadowPaintFilterCanvas.cpp +++ b/src/utils/SkShadowPaintFilterCanvas.cpp @@ -11,7 +11,12 @@ #ifdef SK_EXPERIMENTAL_SHADOWING SkShadowPaintFilterCanvas::SkShadowPaintFilterCanvas(SkCanvas *canvas) - : SkPaintFilterCanvas(canvas) { } + : SkPaintFilterCanvas(canvas) { + fShadowParams.fShadowRadius = 0.0f; + fShadowParams.fType = SkShadowParams::kNoBlur_ShadowType; + fShadowParams.fBiasingConstant = 0.0f; + fShadowParams.fMinVariance = 0.0f; +} // TODO use a shader instead bool SkShadowPaintFilterCanvas::onFilter(SkTCopyOnFirstWrite<SkPaint>* paint, Type type) const { @@ -24,6 +29,17 @@ bool SkShadowPaintFilterCanvas::onFilter(SkTCopyOnFirstWrite<SkPaint>* paint, Ty SkColor color = 0xFF000000; // init color to opaque black color |= z; // Put the index into the blue component + + if (fShadowParams.fType == SkShadowParams::kVariance_ShadowType) { + int z2 = z * z; + if (z2 > 255 * 256) { + color |= 0xff00; + } else { + // Let's only store the more significant bits of z2 to save space. + // In practice, this should barely impact shadow blur quality. + color |= z2 & 0x0000ff00; + } + } newPaint.setColor(color); *paint->writable() = newPaint; @@ -42,6 +58,9 @@ SkISize SkShadowPaintFilterCanvas::ComputeDepthMapSize(const SkLights::Light& li return SkISize::Make(dMapWidth, dMapHeight); } +void SkShadowPaintFilterCanvas::setShadowParams(const SkShadowParams ¶ms) { + fShadowParams = params; +} void SkShadowPaintFilterCanvas::onDrawPicture(const SkPicture *picture, const SkMatrix *matrix, const SkPaint *paint) { diff --git a/src/utils/SkShadowPaintFilterCanvas.h b/src/utils/SkShadowPaintFilterCanvas.h index 892ec556e5..698f6e1173 100644 --- a/src/utils/SkShadowPaintFilterCanvas.h +++ b/src/utils/SkShadowPaintFilterCanvas.h @@ -35,6 +35,7 @@ public: static SkISize ComputeDepthMapSize(const SkLights::Light& light, int maxDepth, int width, int height); + void setShadowParams(const SkShadowParams ¶ms); protected: void onDrawPicture(const SkPicture *picture, const SkMatrix *matrix, const SkPaint *paint) override; @@ -107,6 +108,7 @@ protected: void onDrawTextBlob(const SkTextBlob *blob, SkScalar x, SkScalar y, const SkPaint &paint) override; private: + SkShadowParams fShadowParams; typedef SkPaintFilterCanvas INHERITED; }; |