Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(12)

Side by Side Diff: src/utils/SkShadowPaintFilterCanvas.cpp

Issue 2198933002: Making a sample for shadow maps for more intensive development (Closed) Base URL: https://skia.googlesource.com/skia@shadow-gm
Patch Set: argh fixed utils include error Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/utils/SkShadowPaintFilterCanvas.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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
8 #include "SkPathEffect.h"
9 #include "SkShadowPaintFilterCanvas.h"
10
11 #ifdef SK_EXPERIMENTAL_SHADOWING
12
13 SkShadowPaintFilterCanvas::SkShadowPaintFilterCanvas(SkCanvas *canvas)
14 : SkPaintFilterCanvas(canvas) { }
15
16 // TODO use a shader instead
17 bool SkShadowPaintFilterCanvas::onFilter(SkTCopyOnFirstWrite<SkPaint>* paint, Ty pe type) const {
18 if (*paint) {
19 int z = this->getZ();
20 SkASSERT(z <= 0xFF && z >= 0x00);
21
22 SkPaint newPaint;
23 newPaint.setPathEffect(sk_ref_sp<SkPathEffect>((*paint)->getPathEffect() ));
24
25 SkColor color = 0xFF000000; // init color to opaque black
26 color |= z; // Put the index into the blue component
27 newPaint.setColor(color);
28
29 *paint->writable() = newPaint;
30 }
31
32 return true;
33 }
34
35 SkISize SkShadowPaintFilterCanvas::ComputeDepthMapSize(const SkLights::Light& li ght, int maxDepth,
36 int width, int height) {
37 SkASSERT(light.type() != SkLights::Light::kAmbient_LightType);
38 int dMapWidth = SkMin32(maxDepth * fabs(light.dir().fX) + width,
39 width * 2);
40 int dMapHeight = SkMin32(maxDepth * fabs(light.dir().fY) + height,
41 height * 2);
42 return SkISize::Make(dMapWidth, dMapHeight);
43 }
44
45
46 void SkShadowPaintFilterCanvas::onDrawPicture(const SkPicture *picture, const Sk Matrix *matrix,
47 const SkPaint *paint) {
48 SkTCopyOnFirstWrite<SkPaint> filteredPaint(paint);
49 if (this->onFilter(&filteredPaint, kPicture_Type)) {
50 SkCanvas::onDrawPicture(picture, matrix, filteredPaint);
51 }
52 }
53
54 void SkShadowPaintFilterCanvas::updateMatrix() {
55 this->save();
56
57 // 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.
59 if (this->fLights->light(0).type() != SkLights::Light::kAmbient_LightType) {
60 const SkVector3& lightDir = this->fLights->light(0).dir();
61 SkScalar x = lightDir.fX * this->getZ();
62 SkScalar y = lightDir.fY * this->getZ();
63
64 this->translate(x, y);
65 }
66 }
67
68 void SkShadowPaintFilterCanvas::onDrawPaint(const SkPaint &paint) {
69 this->updateMatrix();
70 this->INHERITED::onDrawPaint(paint);
71 this->restore();
72 }
73
74 void SkShadowPaintFilterCanvas::onDrawPoints(PointMode mode, size_t count, const SkPoint pts[],
75 const SkPaint &paint) {
76 this->updateMatrix();
77 this->INHERITED::onDrawPoints(mode, count, pts, paint);
78 this->restore();
79 }
80
81 void SkShadowPaintFilterCanvas::onDrawRect(const SkRect &rect, const SkPaint &pa int) {
82 this->updateMatrix();
83 this->INHERITED::onDrawRect(rect, paint);
84 this->restore();
85 }
86
87 void SkShadowPaintFilterCanvas::onDrawRRect(const SkRRect &rrect, const SkPaint &paint) {
88 this->updateMatrix();
89 this->INHERITED::onDrawRRect(rrect, paint);
90 this->restore();
91 }
92
93 void SkShadowPaintFilterCanvas::onDrawDRRect(const SkRRect &outer, const SkRRect &inner,
94 const SkPaint &paint) {
95 this->updateMatrix();
96 this->INHERITED::onDrawDRRect(outer, inner, paint);
97 this->restore();
98 }
99
100 void SkShadowPaintFilterCanvas::onDrawOval(const SkRect &rect, const SkPaint &pa int) {
101 this->updateMatrix();
102 this->INHERITED::onDrawOval(rect, paint);
103 this->restore();
104 }
105
106 void SkShadowPaintFilterCanvas::onDrawPath(const SkPath &path, const SkPaint &pa int) {
107 this->updateMatrix();
108 this->INHERITED::onDrawPath(path, paint);
109 this->restore();
110 }
111
112 void SkShadowPaintFilterCanvas::onDrawBitmap(const SkBitmap &bm, SkScalar left, SkScalar top,
113 const SkPaint *paint) {
114 this->updateMatrix();
115 this->INHERITED::onDrawBitmap(bm, left, top, paint);
116 this->restore();
117 }
118
119 void SkShadowPaintFilterCanvas::onDrawBitmapRect(const SkBitmap &bm, const SkRec t *src,
120 const SkRect &dst, const SkPain t *paint,
121 SrcRectConstraint constraint) {
122 this->updateMatrix();
123 this->INHERITED::onDrawBitmapRect(bm, src, dst, paint, constraint);
124 this->restore();
125 }
126
127 void SkShadowPaintFilterCanvas::onDrawBitmapNine(const SkBitmap &bm, const SkIRe ct &center,
128 const SkRect &dst, const SkPain t *paint) {
129 this->updateMatrix();
130 this->INHERITED::onDrawBitmapNine(bm, center, dst, paint);
131 this->restore();
132 }
133
134 void SkShadowPaintFilterCanvas::onDrawImage(const SkImage *image, SkScalar left,
135 SkScalar top, const SkPaint *paint) {
136 this->updateMatrix();
137 this->INHERITED::onDrawImage(image, left, top, paint);
138 this->restore();
139 }
140
141 void SkShadowPaintFilterCanvas::onDrawImageRect(const SkImage *image, const SkRe ct *src,
142 const SkRect &dst, const SkPaint *paint,
143 SrcRectConstraint constraint) {
144 this->updateMatrix();
145 this->INHERITED::onDrawImageRect(image, src, dst, paint, constraint);
146 this->restore();
147 }
148
149 void SkShadowPaintFilterCanvas::onDrawImageNine(const SkImage *image, const SkIR ect &center,
150 const SkRect &dst, const SkPaint *paint) {
151 this->updateMatrix();
152 this->INHERITED::onDrawImageNine(image, center, dst, paint);
153 this->restore();
154 }
155
156
157 void SkShadowPaintFilterCanvas::onDrawVertices(VertexMode vmode, int vertexCount ,
158 const SkPoint vertices[], const S kPoint texs[],
159 const SkColor colors[], SkXfermod e *xmode,
160 const uint16_t indices[], int ind exCount,
161 const SkPaint &paint) {
162 this->updateMatrix();
163 this->INHERITED::onDrawVertices(vmode, vertexCount, vertices, texs, colors,
164 xmode, indices, indexCount, paint);
165 this->restore();
166 }
167
168 void SkShadowPaintFilterCanvas::onDrawPatch(const SkPoint cubics[], const SkColo r colors[],
169 const SkPoint texCoords[], SkXfermod e *xmode,
170 const SkPaint &paint) {
171 this->updateMatrix();
172 this->INHERITED::onDrawPatch(cubics, colors, texCoords, xmode, paint);
173 this->restore();
174 }
175
176 void SkShadowPaintFilterCanvas::onDrawText(const void *text, size_t byteLength, SkScalar x,
177 SkScalar y, const SkPaint &paint) {
178 this->updateMatrix();
179 this->INHERITED::onDrawText(text, byteLength, x, y, paint);
180 this->restore();
181 }
182
183 void SkShadowPaintFilterCanvas::onDrawPosText(const void *text, size_t byteLengt h,
184 const SkPoint pos[], const SkPaint &paint) {
185 this->updateMatrix();
186 this->INHERITED::onDrawPosText(text, byteLength, pos, paint);
187 this->restore();
188 }
189
190 void SkShadowPaintFilterCanvas::onDrawPosTextH(const void *text, size_t byteLeng th,
191 const SkScalar xpos[],
192 SkScalar constY, const SkPaint &p aint) {
193 this->updateMatrix();
194 this->INHERITED::onDrawPosTextH(text, byteLength, xpos, constY, paint);
195 this->restore();
196 }
197
198 void SkShadowPaintFilterCanvas::onDrawTextOnPath(const void *text, size_t byteLe ngth,
199 const SkPath &path, const SkMat rix *matrix,
200 const SkPaint &paint) {
201 this->updateMatrix();
202 this->INHERITED::onDrawTextOnPath(text, byteLength, path, matrix, paint);
203 this->restore();
204 }
205
206 void SkShadowPaintFilterCanvas::onDrawTextRSXform(const void *text, size_t byteL ength,
207 const SkRSXform xform[], const SkRect *cull,
208 const SkPaint &paint) {
209 this->updateMatrix();
210 this->INHERITED::onDrawTextRSXform(text, byteLength, xform, cull, paint);
211 this->restore();
212 }
213
214 void SkShadowPaintFilterCanvas::onDrawTextBlob(const SkTextBlob *blob, SkScalar x, SkScalar y,
215 const SkPaint &paint) {
216 this->updateMatrix();
217 this->INHERITED::onDrawTextBlob(blob, x, y, paint);
218 this->restore();
219 }
220
221 #endif
OLDNEW
« no previous file with comments | « src/utils/SkShadowPaintFilterCanvas.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698