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