| 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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); | 53 SkASSERT(light.type() != SkLights::Light::kAmbient_LightType); |
| 54 if (light.type() != SkLights::Light::kDirectional_LightType) { |
| 55 return SkISize::Make(width *2 , height * 2); |
| 56 } |
| 57 |
| 54 int dMapWidth = SkMin32(maxDepth * fabs(light.dir().fX) + width, | 58 int dMapWidth = SkMin32(maxDepth * fabs(light.dir().fX) + width, |
| 55 width * 2); | 59 width * 2); |
| 56 int dMapHeight = SkMin32(maxDepth * fabs(light.dir().fY) + height, | 60 int dMapHeight = SkMin32(maxDepth * fabs(light.dir().fY) + height, |
| 57 height * 2); | 61 height * 2); |
| 58 return SkISize::Make(dMapWidth, dMapHeight); | 62 return SkISize::Make(dMapWidth, dMapHeight); |
| 59 } | 63 } |
| 60 | 64 |
| 61 void SkShadowPaintFilterCanvas::setShadowParams(const SkShadowParams ¶ms) { | 65 void SkShadowPaintFilterCanvas::setShadowParams(const SkShadowParams ¶ms) { |
| 62 fShadowParams = params; | 66 fShadowParams = params; |
| 63 } | 67 } |
| 64 | 68 |
| 65 void SkShadowPaintFilterCanvas::onDrawPicture(const SkPicture *picture, const Sk
Matrix *matrix, | 69 void SkShadowPaintFilterCanvas::onDrawPicture(const SkPicture *picture, const Sk
Matrix *matrix, |
| 66 const SkPaint *paint) { | 70 const SkPaint *paint) { |
| 67 SkTCopyOnFirstWrite<SkPaint> filteredPaint(paint); | 71 SkTCopyOnFirstWrite<SkPaint> filteredPaint(paint); |
| 68 if (this->onFilter(&filteredPaint, kPicture_Type)) { | 72 if (this->onFilter(&filteredPaint, kPicture_Type)) { |
| 69 SkCanvas::onDrawPicture(picture, matrix, filteredPaint); | 73 SkCanvas::onDrawPicture(picture, matrix, filteredPaint); |
| 70 } | 74 } |
| 71 } | 75 } |
| 72 | 76 |
| 73 void SkShadowPaintFilterCanvas::updateMatrix() { | 77 void SkShadowPaintFilterCanvas::updateMatrix() { |
| 74 this->save(); | 78 this->save(); |
| 75 | 79 |
| 76 // It is up to the user to set the 0th light in fLights to | 80 // 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. | 81 // the light the want to render the depth map with. |
| 78 if (this->fLights->light(0).type() != SkLights::Light::kAmbient_LightType) { | 82 if (this->fLights->light(0).type() == SkLights::Light::kDirectional_LightTyp
e) { |
| 79 const SkVector3& lightDir = this->fLights->light(0).dir(); | 83 const SkVector3& lightDir = this->fLights->light(0).dir(); |
| 80 SkScalar x = lightDir.fX * this->getZ(); | 84 SkScalar x = lightDir.fX * this->getZ(); |
| 81 SkScalar y = lightDir.fY * this->getZ(); | 85 SkScalar y = lightDir.fY * this->getZ(); |
| 82 | 86 |
| 83 this->translate(x, y); | 87 this->translate(x, y); |
| 84 } | 88 } |
| 85 } | 89 } |
| 86 | 90 |
| 87 void SkShadowPaintFilterCanvas::onDrawPaint(const SkPaint &paint) { | 91 void SkShadowPaintFilterCanvas::onDrawPaint(const SkPaint &paint) { |
| 88 this->updateMatrix(); | 92 this->updateMatrix(); |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 } | 243 } |
| 240 | 244 |
| 241 void SkShadowPaintFilterCanvas::onDrawTextBlob(const SkTextBlob *blob, SkScalar
x, SkScalar y, | 245 void SkShadowPaintFilterCanvas::onDrawTextBlob(const SkTextBlob *blob, SkScalar
x, SkScalar y, |
| 242 const SkPaint &paint) { | 246 const SkPaint &paint) { |
| 243 this->updateMatrix(); | 247 this->updateMatrix(); |
| 244 this->INHERITED::onDrawTextBlob(blob, x, y, paint); | 248 this->INHERITED::onDrawTextBlob(blob, x, y, paint); |
| 245 this->restore(); | 249 this->restore(); |
| 246 } | 250 } |
| 247 | 251 |
| 248 #endif | 252 #endif |
| OLD | NEW |