Chromium Code Reviews| Index: src/utils/SkShadowPaintFilterCanvas.cpp |
| diff --git a/src/utils/SkShadowPaintFilterCanvas.cpp b/src/utils/SkShadowPaintFilterCanvas.cpp |
| index 31b7661296151023a8266cf67d5d74468b181dc5..a821edd6f059ef7de8cc441653dfd679f42c2e29 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(SkShadowType sType) { |
|
jvanverth1
2016/08/15 16:37:17
const &
vjiaoblack
2016/08/15 17:43:31
Done.
|
| + fShadowType = sType; |
| +} |
| void SkShadowPaintFilterCanvas::onDrawPicture(const SkPicture *picture, const SkMatrix *matrix, |
| const SkPaint *paint) { |