| 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 17 matching lines...) Expand all Loading... |
| 28 | 28 |
| 29 *paint->writable() = newPaint; | 29 *paint->writable() = newPaint; |
| 30 } | 30 } |
| 31 | 31 |
| 32 return true; | 32 return true; |
| 33 } | 33 } |
| 34 | 34 |
| 35 SkISize SkShadowPaintFilterCanvas::ComputeDepthMapSize(const SkLights::Light& li
ght, int maxDepth, | 35 SkISize SkShadowPaintFilterCanvas::ComputeDepthMapSize(const SkLights::Light& li
ght, int maxDepth, |
| 36 int width, int height) { | 36 int width, int height) { |
| 37 SkASSERT(light.type() != SkLights::Light::kAmbient_LightType); | 37 SkASSERT(light.type() != SkLights::Light::kAmbient_LightType); |
| 38 if (light.type() != SkLights::Light::kDirectional_LightType) { |
| 39 return SkISize::Make(width *2 , height * 2); |
| 40 } |
| 41 |
| 38 int dMapWidth = SkMin32(maxDepth * fabs(light.dir().fX) + width, | 42 int dMapWidth = SkMin32(maxDepth * fabs(light.dir().fX) + width, |
| 39 width * 2); | 43 width * 2); |
| 40 int dMapHeight = SkMin32(maxDepth * fabs(light.dir().fY) + height, | 44 int dMapHeight = SkMin32(maxDepth * fabs(light.dir().fY) + height, |
| 41 height * 2); | 45 height * 2); |
| 42 return SkISize::Make(dMapWidth, dMapHeight); | 46 return SkISize::Make(dMapWidth, dMapHeight); |
| 43 } | 47 } |
| 44 | 48 |
| 45 | 49 |
| 46 void SkShadowPaintFilterCanvas::onDrawPicture(const SkPicture *picture, const Sk
Matrix *matrix, | 50 void SkShadowPaintFilterCanvas::onDrawPicture(const SkPicture *picture, const Sk
Matrix *matrix, |
| 47 const SkPaint *paint) { | 51 const SkPaint *paint) { |
| 48 SkTCopyOnFirstWrite<SkPaint> filteredPaint(paint); | 52 SkTCopyOnFirstWrite<SkPaint> filteredPaint(paint); |
| 49 if (this->onFilter(&filteredPaint, kPicture_Type)) { | 53 if (this->onFilter(&filteredPaint, kPicture_Type)) { |
| 50 SkCanvas::onDrawPicture(picture, matrix, filteredPaint); | 54 SkCanvas::onDrawPicture(picture, matrix, filteredPaint); |
| 51 } | 55 } |
| 52 } | 56 } |
| 53 | 57 |
| 54 void SkShadowPaintFilterCanvas::updateMatrix() { | 58 void SkShadowPaintFilterCanvas::updateMatrix() { |
| 55 this->save(); | 59 this->save(); |
| 56 | 60 |
| 57 // It is up to the user to set the 0th light in fLights to | 61 // It is up to the user to set the 0th light in fLights to |
| 58 // the light the want to render the depth map with. | 62 // the light the want to render the depth map with. |
| 59 if (this->fLights->light(0).type() != SkLights::Light::kAmbient_LightType) { | 63 if (this->fLights->light(0).type() == SkLights::Light::kDirectional_LightTyp
e) { |
| 60 const SkVector3& lightDir = this->fLights->light(0).dir(); | 64 const SkVector3& lightDir = this->fLights->light(0).dir(); |
| 61 SkScalar x = lightDir.fX * this->getZ(); | 65 SkScalar x = lightDir.fX * this->getZ(); |
| 62 SkScalar y = lightDir.fY * this->getZ(); | 66 SkScalar y = lightDir.fY * this->getZ(); |
| 63 | 67 |
| 64 this->translate(x, y); | 68 this->translate(x, y); |
| 65 } | 69 } |
| 66 } | 70 } |
| 67 | 71 |
| 68 void SkShadowPaintFilterCanvas::onDrawPaint(const SkPaint &paint) { | 72 void SkShadowPaintFilterCanvas::onDrawPaint(const SkPaint &paint) { |
| 69 this->updateMatrix(); | 73 this->updateMatrix(); |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 } | 216 } |
| 213 | 217 |
| 214 void SkShadowPaintFilterCanvas::onDrawTextBlob(const SkTextBlob *blob, SkScalar
x, SkScalar y, | 218 void SkShadowPaintFilterCanvas::onDrawTextBlob(const SkTextBlob *blob, SkScalar
x, SkScalar y, |
| 215 const SkPaint &paint) { | 219 const SkPaint &paint) { |
| 216 this->updateMatrix(); | 220 this->updateMatrix(); |
| 217 this->INHERITED::onDrawTextBlob(blob, x, y, paint); | 221 this->INHERITED::onDrawTextBlob(blob, x, y, paint); |
| 218 this->restore(); | 222 this->restore(); |
| 219 } | 223 } |
| 220 | 224 |
| 221 #endif | 225 #endif |
| OLD | NEW |