Index: src/utils/SkShadowPaintFilterCanvas.cpp |
diff --git a/src/utils/SkShadowPaintFilterCanvas.cpp b/src/utils/SkShadowPaintFilterCanvas.cpp |
index 31b7661296151023a8266cf67d5d74468b181dc5..6990c71fdfb78f224971f82ddbd47f053f6ea7bc 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) { |
+ fShadowType.fShadowRadius = 0.0f; |
+ fShadowType.fBlurAlgorithm = SkShadowType::kNoBlur_BlurAlgorithm; |
+ fShadowType.fBiasingConstant = 0.0f; |
+ fShadowType.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 (fShadowType.fBlurAlgorithm == SkShadowType::kVariance_BlurAlgorithm) { |
+ 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::setShadowType(const SkShadowType& sType) { |
+ fShadowType = sType; |
+} |
void SkShadowPaintFilterCanvas::onDrawPicture(const SkPicture *picture, const SkMatrix *matrix, |
const SkPaint *paint) { |