Chromium Code Reviews| 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 | |
| 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, | |
|
robertphillips
2016/08/04 18:16:06
line these guys up with the '(' ?
vjiaoblack
2016/08/04 18:55:49
Done.
| |
| 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() { | |
|
robertphillips
2016/08/04 18:16:06
this->save()
vjiaoblack
2016/08/04 18:55:49
Done.
| |
| 55 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 | |
| 69 void SkShadowPaintFilterCanvas::onDrawPaint(const SkPaint &paint) { | |
| 70 this->updateMatrix(); | |
| 71 this->INHERITED::onDrawPaint(paint); | |
| 72 this->restore(); | |
| 73 } | |
| 74 | |
| 75 void SkShadowPaintFilterCanvas::onDrawPoints(PointMode mode, size_t count, const SkPoint pts[], | |
| 76 const SkPaint &paint) { | |
| 77 this->updateMatrix(); | |
| 78 this->INHERITED::onDrawPoints(mode, count, pts, paint); | |
| 79 this->restore(); | |
| 80 } | |
| 81 | |
| 82 void SkShadowPaintFilterCanvas::onDrawRect(const SkRect &rect, const SkPaint &pa int) { | |
| 83 this->updateMatrix(); | |
| 84 this->INHERITED::onDrawRect(rect, paint); | |
| 85 this->restore(); | |
| 86 } | |
| 87 | |
| 88 void SkShadowPaintFilterCanvas::onDrawRRect(const SkRRect &rrect, const SkPaint &paint) { | |
| 89 this->updateMatrix(); | |
| 90 this->INHERITED::onDrawRRect(rrect, paint); | |
| 91 this->restore(); | |
| 92 } | |
| 93 | |
| 94 void SkShadowPaintFilterCanvas::onDrawDRRect(const SkRRect &outer, const SkRRect &inner, | |
| 95 const SkPaint &paint) { | |
| 96 this->updateMatrix(); | |
| 97 this->INHERITED::onDrawDRRect(outer, inner, paint); | |
| 98 this->restore(); | |
| 99 } | |
| 100 | |
| 101 void SkShadowPaintFilterCanvas::onDrawOval(const SkRect &rect, const SkPaint &pa int) { | |
| 102 this->updateMatrix(); | |
| 103 this->INHERITED::onDrawOval(rect, paint); | |
| 104 this->restore(); | |
| 105 } | |
| 106 | |
| 107 void SkShadowPaintFilterCanvas::onDrawPath(const SkPath &path, const SkPaint &pa int) { | |
| 108 this->updateMatrix(); | |
| 109 this->INHERITED::onDrawPath(path, paint); | |
| 110 this->restore(); | |
| 111 } | |
| 112 | |
| 113 void SkShadowPaintFilterCanvas::onDrawBitmap(const SkBitmap &bm, SkScalar left, SkScalar top, | |
| 114 const SkPaint *paint) { | |
| 115 this->updateMatrix(); | |
| 116 this->INHERITED::onDrawBitmap(bm, left, top, paint); | |
| 117 this->restore(); | |
| 118 } | |
| 119 | |
| 120 void SkShadowPaintFilterCanvas::onDrawBitmapRect(const SkBitmap &bm, const SkRec t *src, | |
| 121 const SkRect &dst, const SkPain t *paint, | |
| 122 SrcRectConstraint constraint) { | |
| 123 this->updateMatrix(); | |
| 124 this->INHERITED::onDrawBitmapRect(bm, src, dst, paint, constraint); | |
| 125 this->restore(); | |
| 126 } | |
| 127 | |
| 128 void SkShadowPaintFilterCanvas::onDrawBitmapNine(const SkBitmap &bm, const SkIRe ct ¢er, | |
| 129 const SkRect &dst, const SkPain t *paint) { | |
| 130 this->updateMatrix(); | |
| 131 this->INHERITED::onDrawBitmapNine(bm, center, dst, paint); | |
| 132 this->restore(); | |
| 133 } | |
| 134 | |
| 135 void SkShadowPaintFilterCanvas::onDrawImage(const SkImage *image, SkScalar left, | |
| 136 SkScalar top, const SkPaint *paint) { | |
| 137 this->updateMatrix(); | |
| 138 this->INHERITED::onDrawImage(image, left, top, paint); | |
| 139 this->restore(); | |
| 140 } | |
| 141 | |
| 142 void SkShadowPaintFilterCanvas::onDrawImageRect(const SkImage *image, const SkRe ct *src, | |
| 143 const SkRect &dst, const SkPaint *paint, | |
| 144 SrcRectConstraint constraint) { | |
| 145 this->updateMatrix(); | |
| 146 this->INHERITED::onDrawImageRect(image, src, dst, paint, constraint); | |
| 147 this->restore(); | |
| 148 } | |
| 149 | |
| 150 void SkShadowPaintFilterCanvas::onDrawImageNine(const SkImage *image, const SkIR ect ¢er, | |
| 151 const SkRect &dst, const SkPaint *paint) { | |
| 152 this->updateMatrix(); | |
| 153 this->INHERITED::onDrawImageNine(image, center, dst, paint); | |
| 154 this->restore(); | |
| 155 } | |
| 156 | |
| 157 | |
| 158 void SkShadowPaintFilterCanvas::onDrawVertices(VertexMode vmode, int vertexCount , | |
| 159 const SkPoint vertices[], const S kPoint texs[], | |
| 160 const SkColor colors[], SkXfermod e *xmode, | |
| 161 const uint16_t indices[], int ind exCount, | |
| 162 const SkPaint &paint) { | |
| 163 this->updateMatrix(); | |
| 164 this->INHERITED::onDrawVertices(vmode, vertexCount, vertices, texs, colors, | |
| 165 xmode, indices, indexCount, paint); | |
| 166 this->restore(); | |
| 167 } | |
| 168 | |
| 169 void SkShadowPaintFilterCanvas::onDrawPatch(const SkPoint cubics[], const SkColo r colors[], | |
| 170 const SkPoint texCoords[], SkXfermod e *xmode, | |
| 171 const SkPaint &paint) { | |
| 172 this->updateMatrix(); | |
| 173 this->INHERITED::onDrawPatch(cubics, colors, texCoords, xmode, paint); | |
| 174 this->restore(); | |
| 175 } | |
| 176 | |
| 177 void SkShadowPaintFilterCanvas::onDrawText(const void *text, size_t byteLength, SkScalar x, | |
| 178 SkScalar y, const SkPaint &paint) { | |
| 179 this->updateMatrix(); | |
| 180 this->INHERITED::onDrawText(text, byteLength, x, y, paint); | |
| 181 this->restore(); | |
| 182 } | |
| 183 | |
| 184 void SkShadowPaintFilterCanvas::onDrawPosText(const void *text, size_t byteLengt h, | |
| 185 const SkPoint pos[], const SkPaint &paint) { | |
| 186 this->updateMatrix(); | |
| 187 this->INHERITED::onDrawPosText(text, byteLength, pos, paint); | |
| 188 this->restore(); | |
| 189 } | |
| 190 | |
| 191 void SkShadowPaintFilterCanvas::onDrawPosTextH(const void *text, size_t byteLeng th, | |
| 192 const SkScalar xpos[], | |
| 193 SkScalar constY, const SkPaint &p aint) { | |
| 194 this->updateMatrix(); | |
| 195 this->INHERITED::onDrawPosTextH(text, byteLength, xpos, constY, paint); | |
| 196 this->restore(); | |
| 197 } | |
| 198 | |
| 199 void SkShadowPaintFilterCanvas::onDrawTextOnPath(const void *text, size_t byteLe ngth, | |
| 200 const SkPath &path, const SkMat rix *matrix, | |
| 201 const SkPaint &paint) { | |
| 202 this->updateMatrix(); | |
| 203 this->INHERITED::onDrawTextOnPath(text, byteLength, path, matrix, paint); | |
| 204 this->restore(); | |
| 205 } | |
| 206 | |
| 207 void SkShadowPaintFilterCanvas::onDrawTextRSXform(const void *text, size_t byteL ength, | |
| 208 const SkRSXform xform[], const SkRect *cull, | |
| 209 const SkPaint &paint) { | |
| 210 this->updateMatrix(); | |
| 211 this->INHERITED::onDrawTextRSXform(text, byteLength, xform, cull, paint); | |
| 212 this->restore(); | |
| 213 } | |
| 214 | |
| 215 void SkShadowPaintFilterCanvas::onDrawTextBlob(const SkTextBlob *blob, SkScalar x, SkScalar y, | |
| 216 const SkPaint &paint) { | |
| 217 this->updateMatrix(); | |
| 218 this->INHERITED::onDrawTextBlob(blob, x, y, paint); | |
| 219 this->restore(); | |
| 220 } | |
| 221 | |
| 222 #endif | |
| OLD | NEW |