OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright 2016 Google Inc. | |
3 * | |
4 * Use of this source code is governed by a BSD-style license that can be | |
5 * found in the LICENSE file. | |
6 */ | |
7 | |
robertphillips
2016/08/03 18:47:48
I think we only need the "SkShadowPaintFilterCanva
vjiaoblack
2016/08/04 13:36:22
Done.
| |
8 #include "SkCanvas.h" | |
9 #include "SkNWayCanvas.h" | |
10 #include "SkPaintFilterCanvas.h" | |
11 #include "SkShadowPaintFilterCanvas.h" | |
12 | |
13 #ifdef SK_EXPERIMENTAL_SHADOWING | |
14 | |
15 SkShadowPaintFilterCanvas::SkShadowPaintFilterCanvas(SkCanvas *canvas) | |
16 : SkPaintFilterCanvas(canvas) { } | |
17 | |
18 // TODO use a shader instead | |
19 bool SkShadowPaintFilterCanvas::onFilter(SkTCopyOnFirstWrite<SkPaint>* paint, Ty pe type) const { | |
20 if (*paint) { | |
21 int z = this->getZ(); | |
22 SkASSERT(z <= 0xFF && z >= 0x00); | |
23 | |
24 SkPaint newPaint; | |
25 newPaint.setPathEffect(sk_ref_sp<SkPathEffect>((*paint)->getPathEffect() )); | |
26 | |
27 SkColor color = 0xFF000000; // init color to opaque black | |
28 color |= z; // Put the index into the blue component | |
29 newPaint.setColor(color); | |
30 | |
31 *paint->writable() = newPaint; | |
32 } | |
33 | |
34 return true; | |
35 } | |
36 | |
37 void SkShadowPaintFilterCanvas::onDrawPicture(const SkPicture *picture, const Sk Matrix *matrix, | |
38 const SkPaint *paint) { | |
39 SkTCopyOnFirstWrite<SkPaint> filteredPaint(paint); | |
40 if (onFilter(&filteredPaint, kPicture_Type)) | |
robertphillips
2016/08/03 18:47:48
Add brackets around this call
vjiaoblack
2016/08/04 13:36:22
Done.
| |
41 SkCanvas::onDrawPicture(picture, matrix, filteredPaint); | |
42 } | |
43 | |
44 void SkShadowPaintFilterCanvas::updateMatrix() { | |
45 save(); | |
46 | |
47 // It is up to the user to set the 0th light in fLights to | |
48 // the light the want to render the depth map with. | |
49 if (this->fLights->light(0).type() != SkLights::Light::kAmbient_LightType) { | |
robertphillips
2016/08/03 18:47:48
const SkVector3& lightDir = ... ?
vjiaoblack
2016/08/04 13:36:22
Done.
vjiaoblack
2016/08/04 18:03:58
Done.
| |
50 SkVector3 lightDir = this->fLights->light(0).dir(); | |
51 SkScalar x = lightDir.fX * this->getZ(); | |
52 SkScalar y = lightDir.fY * this->getZ(); | |
53 | |
54 this->translate(x, y); | |
55 } | |
56 | |
57 } | |
58 | |
59 void SkShadowPaintFilterCanvas::onDrawPaint(const SkPaint &paint) { | |
robertphillips
2016/08/03 18:47:48
add this-> to member function calls here and elsew
vjiaoblack
2016/08/04 13:36:22
Done.
vjiaoblack
2016/08/04 18:03:58
Done.
| |
60 updateMatrix(); | |
61 this->INHERITED::onDrawPaint(paint); | |
62 restore(); | |
63 } | |
64 | |
65 void SkShadowPaintFilterCanvas::onDrawPoints(PointMode mode, size_t count, const SkPoint pts[], | |
66 const SkPaint &paint) { | |
67 updateMatrix(); | |
68 this->INHERITED::onDrawPoints(mode, count, pts, paint); | |
69 restore(); | |
70 } | |
71 | |
72 void SkShadowPaintFilterCanvas::onDrawRect(const SkRect &rect, const SkPaint &pa int) { | |
73 updateMatrix(); | |
74 this->INHERITED::onDrawRect(rect, paint); | |
75 restore(); | |
76 } | |
77 | |
78 void SkShadowPaintFilterCanvas::onDrawRRect(const SkRRect &rrect, const SkPaint &paint) { | |
79 updateMatrix(); | |
80 this->INHERITED::onDrawRRect(rrect, paint); | |
81 restore(); | |
82 } | |
83 | |
84 void SkShadowPaintFilterCanvas::onDrawDRRect(const SkRRect &outer, const SkRRect &inner, | |
85 const SkPaint &paint) { | |
86 updateMatrix(); | |
87 this->INHERITED::onDrawDRRect(outer, inner, paint); | |
88 restore(); | |
89 } | |
90 | |
91 void SkShadowPaintFilterCanvas::onDrawOval(const SkRect &rect, const SkPaint &pa int) { | |
92 updateMatrix(); | |
93 this->INHERITED::onDrawOval(rect, paint); | |
94 restore(); | |
95 } | |
96 | |
97 void SkShadowPaintFilterCanvas::onDrawPath(const SkPath &path, const SkPaint &pa int) { | |
98 updateMatrix(); | |
99 this->INHERITED::onDrawPath(path, paint); | |
100 restore(); | |
101 } | |
102 | |
103 void SkShadowPaintFilterCanvas::onDrawBitmap(const SkBitmap &bm, SkScalar left, SkScalar top, | |
104 const SkPaint *paint) { | |
105 updateMatrix(); | |
106 this->INHERITED::onDrawBitmap(bm, left, top, paint); | |
107 restore(); | |
108 } | |
109 | |
110 void SkShadowPaintFilterCanvas::onDrawBitmapRect(const SkBitmap &bm, const SkRec t *src, | |
111 const SkRect &dst, const SkPain t *paint, | |
112 SrcRectConstraint constraint) { | |
113 updateMatrix(); | |
114 this->INHERITED::onDrawBitmapRect(bm, src, dst, paint, constraint); | |
115 restore(); | |
116 } | |
117 | |
118 void SkShadowPaintFilterCanvas::onDrawBitmapNine(const SkBitmap &bm, const SkIRe ct ¢er, | |
119 const SkRect &dst, const SkPain t *paint) { | |
120 updateMatrix(); | |
121 this->INHERITED::onDrawBitmapNine(bm, center, dst, paint); | |
122 restore(); | |
123 } | |
124 | |
125 void SkShadowPaintFilterCanvas::onDrawImage(const SkImage *image, SkScalar left, | |
126 SkScalar top, const SkPaint *paint) { | |
127 updateMatrix(); | |
128 this->INHERITED::onDrawImage(image, left, top, paint); | |
129 restore(); | |
130 } | |
131 | |
132 void SkShadowPaintFilterCanvas::onDrawImageRect(const SkImage *image, const SkRe ct *src, | |
133 const SkRect &dst, const SkPaint *paint, | |
134 SrcRectConstraint constraint) { | |
135 updateMatrix(); | |
136 this->INHERITED::onDrawImageRect(image, src, dst, paint, constraint); | |
137 restore(); | |
138 } | |
139 | |
140 void SkShadowPaintFilterCanvas::onDrawImageNine(const SkImage *image, const SkIR ect ¢er, | |
141 const SkRect &dst, const SkPaint *paint) { | |
142 updateMatrix(); | |
143 this->INHERITED::onDrawImageNine(image, center, dst, paint); | |
144 restore(); | |
145 } | |
146 | |
147 | |
148 void SkShadowPaintFilterCanvas::onDrawVertices(VertexMode vmode, int vertexCount , | |
149 const SkPoint vertices[], const S kPoint texs[], | |
150 const SkColor colors[], SkXfermod e *xmode, | |
151 const uint16_t indices[], int ind exCount, | |
152 const SkPaint &paint) { | |
153 updateMatrix(); | |
154 this->INHERITED::onDrawVertices(vmode, vertexCount, vertices, texs, colors, | |
155 xmode, indices, indexCount, paint); | |
156 restore(); | |
157 } | |
158 | |
159 void SkShadowPaintFilterCanvas::onDrawPatch(const SkPoint cubics[], const SkColo r colors[], | |
160 const SkPoint texCoords[], SkXfermod e *xmode, | |
161 const SkPaint &paint) { | |
162 updateMatrix(); | |
163 this->INHERITED::onDrawPatch(cubics, colors, texCoords, xmode, paint); | |
164 restore(); | |
165 } | |
166 | |
167 void SkShadowPaintFilterCanvas::onDrawText(const void *text, size_t byteLength, SkScalar x, | |
168 SkScalar y, const SkPaint &paint) { | |
169 updateMatrix(); | |
170 this->INHERITED::onDrawText(text, byteLength, x, y, paint); | |
171 restore(); | |
172 } | |
173 | |
174 void SkShadowPaintFilterCanvas::onDrawPosText(const void *text, size_t byteLengt h, | |
175 const SkPoint pos[], const SkPaint &paint) { | |
176 updateMatrix(); | |
177 this->INHERITED::onDrawPosText(text, byteLength, pos, paint); | |
178 restore(); | |
179 } | |
180 | |
181 void SkShadowPaintFilterCanvas::onDrawPosTextH(const void *text, size_t byteLeng th, | |
182 const SkScalar xpos[], | |
183 SkScalar constY, const SkPaint &p aint) { | |
184 updateMatrix(); | |
185 this->INHERITED::onDrawPosTextH(text, byteLength, xpos, constY, paint); | |
186 restore(); | |
187 } | |
188 | |
189 void SkShadowPaintFilterCanvas::onDrawTextOnPath(const void *text, size_t byteLe ngth, | |
190 const SkPath &path, const SkMat rix *matrix, | |
191 const SkPaint &paint) { | |
192 updateMatrix(); | |
193 this->INHERITED::onDrawTextOnPath(text, byteLength, path, matrix, paint); | |
194 restore(); | |
195 } | |
196 | |
197 void SkShadowPaintFilterCanvas::onDrawTextRSXform(const void *text, size_t byteL ength, | |
198 const SkRSXform xform[], const SkRect *cull, | |
199 const SkPaint &paint) { | |
200 updateMatrix(); | |
201 this->INHERITED::onDrawTextRSXform(text, byteLength, xform, cull, paint); | |
202 restore(); | |
203 } | |
204 | |
205 void SkShadowPaintFilterCanvas::onDrawTextBlob(const SkTextBlob *blob, SkScalar x, SkScalar y, | |
206 const SkPaint &paint) { | |
207 updateMatrix(); | |
208 this->INHERITED::onDrawTextBlob(blob, x, y, paint); | |
209 restore(); | |
210 } | |
211 | |
212 #endif | |
OLD | NEW |