Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "SkPathEffect.h" | 8 #include "SkPathEffect.h" |
| 9 #include "SkShadowPaintFilterCanvas.h" | 9 #include "SkShadowPaintFilterCanvas.h" |
| 10 | 10 |
| 11 #ifdef SK_EXPERIMENTAL_SHADOWING | 11 #ifdef SK_EXPERIMENTAL_SHADOWING |
| 12 | 12 |
| 13 SkShadowPaintFilterCanvas::SkShadowPaintFilterCanvas(SkCanvas *canvas) | 13 SkShadowPaintFilterCanvas::SkShadowPaintFilterCanvas(SkCanvas *canvas) |
| 14 : SkPaintFilterCanvas(canvas) { } | 14 : SkPaintFilterCanvas(canvas) { |
| 15 fShType.fShadowRadius = 0.0f; | |
| 16 fShType.fBlurAlgorithm = SkShadowType::kNoBlur_BlurAlgorithm; | |
| 17 fShType.fBiasingConstant = 0.0f; | |
| 18 fShType.fMinVariance = 0.0f; | |
| 19 } | |
| 15 | 20 |
| 16 // TODO use a shader instead | 21 // TODO use a shader instead |
| 17 bool SkShadowPaintFilterCanvas::onFilter(SkTCopyOnFirstWrite<SkPaint>* paint, Ty pe type) const { | 22 bool SkShadowPaintFilterCanvas::onFilter(SkTCopyOnFirstWrite<SkPaint>* paint, Ty pe type) const { |
| 18 if (*paint) { | 23 if (*paint) { |
| 19 int z = this->getZ(); | 24 int z = this->getZ(); |
| 20 SkASSERT(z <= 0xFF && z >= 0x00); | 25 SkASSERT(z <= 0xFF && z >= 0x00); |
| 21 | 26 |
| 22 SkPaint newPaint; | 27 SkPaint newPaint; |
| 23 newPaint.setPathEffect(sk_ref_sp<SkPathEffect>((*paint)->getPathEffect() )); | 28 newPaint.setPathEffect(sk_ref_sp<SkPathEffect>((*paint)->getPathEffect() )); |
| 24 | 29 |
| 25 SkColor color = 0xFF000000; // init color to opaque black | 30 SkColor color = 0xFF000000; // init color to opaque black |
| 26 color |= z; // Put the index into the blue component | 31 color |= z; // Put the index into the blue component |
| 32 | |
| 33 if (fShType.fBlurAlgorithm == SkShadowType::kVariance_BlurAlgorithm) { | |
| 34 int z2 = z * z; | |
| 35 if (z2 > 255 * 256) { | |
| 36 color |= (255) << 8; | |
| 37 } else { | |
| 38 color |= (z2 / 256) << 8; | |
|
jvanverth1
2016/08/12 17:39:09
I think (z2/256) << 8 is the same as (z2 & ~0xff).
vjiaoblack
2016/08/12 19:07:42
Done.
| |
| 39 } | |
| 40 } | |
| 27 newPaint.setColor(color); | 41 newPaint.setColor(color); |
| 28 | 42 |
| 29 *paint->writable() = newPaint; | 43 *paint->writable() = newPaint; |
| 30 } | 44 } |
| 31 | 45 |
| 32 return true; | 46 return true; |
| 33 } | 47 } |
| 34 | 48 |
| 35 SkISize SkShadowPaintFilterCanvas::ComputeDepthMapSize(const SkLights::Light& li ght, int maxDepth, | 49 SkISize SkShadowPaintFilterCanvas::ComputeDepthMapSize(const SkLights::Light& li ght, int maxDepth, |
| 36 int width, int height) { | 50 int width, int height) { |
| 37 SkASSERT(light.type() != SkLights::Light::kAmbient_LightType); | 51 SkASSERT(light.type() != SkLights::Light::kAmbient_LightType); |
| 38 int dMapWidth = SkMin32(maxDepth * fabs(light.dir().fX) + width, | 52 int dMapWidth = SkMin32(maxDepth * fabs(light.dir().fX) + width, |
| 39 width * 2); | 53 width * 2); |
| 40 int dMapHeight = SkMin32(maxDepth * fabs(light.dir().fY) + height, | 54 int dMapHeight = SkMin32(maxDepth * fabs(light.dir().fY) + height, |
| 41 height * 2); | 55 height * 2); |
| 42 return SkISize::Make(dMapWidth, dMapHeight); | 56 return SkISize::Make(dMapWidth, dMapHeight); |
| 43 } | 57 } |
| 44 | 58 |
| 59 void SkShadowPaintFilterCanvas::setShadowType(SkShadowType sType) { | |
| 60 fShType = sType; | |
| 61 } | |
| 45 | 62 |
| 46 void SkShadowPaintFilterCanvas::onDrawPicture(const SkPicture *picture, const Sk Matrix *matrix, | 63 void SkShadowPaintFilterCanvas::onDrawPicture(const SkPicture *picture, const Sk Matrix *matrix, |
| 47 const SkPaint *paint) { | 64 const SkPaint *paint) { |
| 48 SkTCopyOnFirstWrite<SkPaint> filteredPaint(paint); | 65 SkTCopyOnFirstWrite<SkPaint> filteredPaint(paint); |
| 49 if (this->onFilter(&filteredPaint, kPicture_Type)) { | 66 if (this->onFilter(&filteredPaint, kPicture_Type)) { |
| 50 SkCanvas::onDrawPicture(picture, matrix, filteredPaint); | 67 SkCanvas::onDrawPicture(picture, matrix, filteredPaint); |
| 51 } | 68 } |
| 52 } | 69 } |
| 53 | 70 |
| 54 void SkShadowPaintFilterCanvas::updateMatrix() { | 71 void SkShadowPaintFilterCanvas::updateMatrix() { |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 212 } | 229 } |
| 213 | 230 |
| 214 void SkShadowPaintFilterCanvas::onDrawTextBlob(const SkTextBlob *blob, SkScalar x, SkScalar y, | 231 void SkShadowPaintFilterCanvas::onDrawTextBlob(const SkTextBlob *blob, SkScalar x, SkScalar y, |
| 215 const SkPaint &paint) { | 232 const SkPaint &paint) { |
| 216 this->updateMatrix(); | 233 this->updateMatrix(); |
| 217 this->INHERITED::onDrawTextBlob(blob, x, y, paint); | 234 this->INHERITED::onDrawTextBlob(blob, x, y, paint); |
| 218 this->restore(); | 235 this->restore(); |
| 219 } | 236 } |
| 220 | 237 |
| 221 #endif | 238 #endif |
| OLD | NEW |