| 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 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 newPaint.setColor(color); | 43 newPaint.setColor(color); |
| 44 | 44 |
| 45 *paint->writable() = newPaint; | 45 *paint->writable() = newPaint; |
| 46 } | 46 } |
| 47 | 47 |
| 48 return true; | 48 return true; |
| 49 } | 49 } |
| 50 | 50 |
| 51 SkISize SkShadowPaintFilterCanvas::ComputeDepthMapSize(const SkLights::Light& li
ght, int maxDepth, | 51 SkISize SkShadowPaintFilterCanvas::ComputeDepthMapSize(const SkLights::Light& li
ght, int maxDepth, |
| 52 int width, int height) { | 52 int width, int height) { |
| 53 SkASSERT(light.type() != SkLights::Light::kAmbient_LightType); | |
| 54 int dMapWidth = SkMin32(maxDepth * fabs(light.dir().fX) + width, | 53 int dMapWidth = SkMin32(maxDepth * fabs(light.dir().fX) + width, |
| 55 width * 2); | 54 width * 2); |
| 56 int dMapHeight = SkMin32(maxDepth * fabs(light.dir().fY) + height, | 55 int dMapHeight = SkMin32(maxDepth * fabs(light.dir().fY) + height, |
| 57 height * 2); | 56 height * 2); |
| 58 return SkISize::Make(dMapWidth, dMapHeight); | 57 return SkISize::Make(dMapWidth, dMapHeight); |
| 59 } | 58 } |
| 60 | 59 |
| 61 void SkShadowPaintFilterCanvas::setShadowParams(const SkShadowParams ¶ms) { | 60 void SkShadowPaintFilterCanvas::setShadowParams(const SkShadowParams ¶ms) { |
| 62 fShadowParams = params; | 61 fShadowParams = params; |
| 63 } | 62 } |
| 64 | 63 |
| 65 void SkShadowPaintFilterCanvas::onDrawPicture(const SkPicture *picture, const Sk
Matrix *matrix, | 64 void SkShadowPaintFilterCanvas::onDrawPicture(const SkPicture *picture, const Sk
Matrix *matrix, |
| 66 const SkPaint *paint) { | 65 const SkPaint *paint) { |
| 67 SkTCopyOnFirstWrite<SkPaint> filteredPaint(paint); | 66 SkTCopyOnFirstWrite<SkPaint> filteredPaint(paint); |
| 68 if (this->onFilter(&filteredPaint, kPicture_Type)) { | 67 if (this->onFilter(&filteredPaint, kPicture_Type)) { |
| 69 SkCanvas::onDrawPicture(picture, matrix, filteredPaint); | 68 SkCanvas::onDrawPicture(picture, matrix, filteredPaint); |
| 70 } | 69 } |
| 71 } | 70 } |
| 72 | 71 |
| 73 void SkShadowPaintFilterCanvas::updateMatrix() { | 72 void SkShadowPaintFilterCanvas::updateMatrix() { |
| 74 this->save(); | 73 this->save(); |
| 75 | 74 |
| 76 // It is up to the user to set the 0th light in fLights to | 75 // It is up to the user to set the 0th light in fLights to |
| 77 // the light the want to render the depth map with. | 76 // the light the want to render the depth map with. |
| 78 if (this->fLights->light(0).type() != SkLights::Light::kAmbient_LightType) { | 77 const SkVector3& lightDir = this->fLights->light(0).dir(); |
| 79 const SkVector3& lightDir = this->fLights->light(0).dir(); | 78 SkScalar x = lightDir.fX * this->getZ(); |
| 80 SkScalar x = lightDir.fX * this->getZ(); | 79 SkScalar y = lightDir.fY * this->getZ(); |
| 81 SkScalar y = lightDir.fY * this->getZ(); | |
| 82 | 80 |
| 83 this->translate(x, y); | 81 this->translate(x, y); |
| 84 } | |
| 85 } | 82 } |
| 86 | 83 |
| 87 void SkShadowPaintFilterCanvas::onDrawPaint(const SkPaint &paint) { | 84 void SkShadowPaintFilterCanvas::onDrawPaint(const SkPaint &paint) { |
| 88 this->updateMatrix(); | 85 this->updateMatrix(); |
| 89 this->INHERITED::onDrawPaint(paint); | 86 this->INHERITED::onDrawPaint(paint); |
| 90 this->restore(); | 87 this->restore(); |
| 91 } | 88 } |
| 92 | 89 |
| 93 void SkShadowPaintFilterCanvas::onDrawPoints(PointMode mode, size_t count, const
SkPoint pts[], | 90 void SkShadowPaintFilterCanvas::onDrawPoints(PointMode mode, size_t count, const
SkPoint pts[], |
| 94 const SkPaint &paint) { | 91 const SkPaint &paint) { |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 } | 236 } |
| 240 | 237 |
| 241 void SkShadowPaintFilterCanvas::onDrawTextBlob(const SkTextBlob *blob, SkScalar
x, SkScalar y, | 238 void SkShadowPaintFilterCanvas::onDrawTextBlob(const SkTextBlob *blob, SkScalar
x, SkScalar y, |
| 242 const SkPaint &paint) { | 239 const SkPaint &paint) { |
| 243 this->updateMatrix(); | 240 this->updateMatrix(); |
| 244 this->INHERITED::onDrawTextBlob(blob, x, y, paint); | 241 this->INHERITED::onDrawTextBlob(blob, x, y, paint); |
| 245 this->restore(); | 242 this->restore(); |
| 246 } | 243 } |
| 247 | 244 |
| 248 #endif | 245 #endif |
| OLD | NEW |