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 |
robertphillips
2016/08/10 14:23:18
Add parameter
vjiaoblack
2016/08/11 18:28:51
Done.
| |
13 SkShadowPaintFilterCanvas::SkShadowPaintFilterCanvas(SkCanvas *canvas) | 13 SkShadowPaintFilterCanvas::SkShadowPaintFilterCanvas(SkCanvas *canvas) |
14 : SkPaintFilterCanvas(canvas) { } | 14 : SkPaintFilterCanvas(canvas) { } |
15 | 15 |
16 // TODO use a shader instead | 16 // TODO use a shader instead |
17 bool SkShadowPaintFilterCanvas::onFilter(SkTCopyOnFirstWrite<SkPaint>* paint, Ty pe type) const { | 17 bool SkShadowPaintFilterCanvas::onFilter(SkTCopyOnFirstWrite<SkPaint>* paint, Ty pe type) const { |
18 if (*paint) { | 18 if (*paint) { |
19 int z = this->getZ(); | 19 int z = this->getZ(); |
20 SkASSERT(z <= 0xFF && z >= 0x00); | 20 SkASSERT(z <= 0xFF && z >= 0x00); |
21 | 21 |
22 SkPaint newPaint; | 22 SkPaint newPaint; |
23 newPaint.setPathEffect(sk_ref_sp<SkPathEffect>((*paint)->getPathEffect() )); | 23 newPaint.setPathEffect(sk_ref_sp<SkPathEffect>((*paint)->getPathEffect() )); |
24 | 24 |
25 SkColor color = 0xFF000000; // init color to opaque black | 25 SkColor color = 0xFF000000; // init color to opaque black |
26 color |= z; // Put the index into the blue component | 26 color |= z; // Put the index into the blue component |
27 | |
robertphillips
2016/08/10 14:23:18
parameterize & comment
vjiaoblack
2016/08/11 18:28:51
Done.
| |
28 int z2 = z * z; | |
29 if (z2 > 255 * 256) { | |
30 color |= (255) << 8; | |
31 } else { | |
32 color |= (z2 / 256) << 8; | |
33 } | |
34 // color |= (z * z / 256) << 8; | |
27 newPaint.setColor(color); | 35 newPaint.setColor(color); |
28 | 36 |
29 *paint->writable() = newPaint; | 37 *paint->writable() = newPaint; |
30 } | 38 } |
31 | 39 |
32 return true; | 40 return true; |
33 } | 41 } |
34 | 42 |
35 SkISize SkShadowPaintFilterCanvas::ComputeDepthMapSize(const SkLights::Light& li ght, int maxDepth, | 43 SkISize SkShadowPaintFilterCanvas::ComputeDepthMapSize(const SkLights::Light& li ght, int maxDepth, |
36 int width, int height) { | 44 int width, int height) { |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
212 } | 220 } |
213 | 221 |
214 void SkShadowPaintFilterCanvas::onDrawTextBlob(const SkTextBlob *blob, SkScalar x, SkScalar y, | 222 void SkShadowPaintFilterCanvas::onDrawTextBlob(const SkTextBlob *blob, SkScalar x, SkScalar y, |
215 const SkPaint &paint) { | 223 const SkPaint &paint) { |
216 this->updateMatrix(); | 224 this->updateMatrix(); |
217 this->INHERITED::onDrawTextBlob(blob, x, y, paint); | 225 this->INHERITED::onDrawTextBlob(blob, x, y, paint); |
218 this->restore(); | 226 this->restore(); |
219 } | 227 } |
220 | 228 |
221 #endif | 229 #endif |
OLD | NEW |