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 void SkShadowPaintFilterCanvas::onDrawPicture(const SkPicture *picture, const Sk Matrix *matrix, | |
| 36 const SkPaint *paint) { | |
| 37 SkTCopyOnFirstWrite<SkPaint> filteredPaint(paint); | |
|
robertphillips
2016/08/04 15:17:35
this->onFilter
vjiaoblack
2016/08/04 18:03:59
Done.
| |
| 38 if (onFilter(&filteredPaint, kPicture_Type)) { | |
| 39 SkCanvas::onDrawPicture(picture, matrix, filteredPaint); | |
| 40 } | |
| 41 } | |
| 42 | |
| 43 void SkShadowPaintFilterCanvas::updateMatrix() { | |
| 44 save(); | |
| 45 | |
| 46 // It is up to the user to set the 0th light in fLights to | |
| 47 // the light the want to render the depth map with. | |
| 48 if (this->fLights->light(0).type() != SkLights::Light::kAmbient_LightType) { | |
| 49 const SkVector3& lightDir = this->fLights->light(0).dir(); | |
| 50 SkScalar x = lightDir.fX * this->getZ(); | |
| 51 SkScalar y = lightDir.fY * this->getZ(); | |
| 52 | |
| 53 this->translate(x, y); | |
| 54 } | |
| 55 | |
| 56 } | |
| 57 | |
| 58 void SkShadowPaintFilterCanvas::onDrawPaint(const SkPaint &paint) { | |
| 59 this->updateMatrix(); | |
| 60 this->INHERITED::onDrawPaint(paint); | |
| 61 this->restore(); | |
| 62 } | |
| 63 | |
| 64 void SkShadowPaintFilterCanvas::onDrawPoints(PointMode mode, size_t count, const SkPoint pts[], | |
| 65 const SkPaint &paint) { | |
| 66 this->updateMatrix(); | |
| 67 this->INHERITED::onDrawPoints(mode, count, pts, paint); | |
| 68 this->restore(); | |
| 69 } | |
| 70 | |
| 71 void SkShadowPaintFilterCanvas::onDrawRect(const SkRect &rect, const SkPaint &pa int) { | |
| 72 this->updateMatrix(); | |
| 73 this->INHERITED::onDrawRect(rect, paint); | |
| 74 this->restore(); | |
| 75 } | |
| 76 | |
| 77 void SkShadowPaintFilterCanvas::onDrawRRect(const SkRRect &rrect, const SkPaint &paint) { | |
| 78 this->updateMatrix(); | |
| 79 this->INHERITED::onDrawRRect(rrect, paint); | |
| 80 this->restore(); | |
| 81 } | |
| 82 | |
| 83 void SkShadowPaintFilterCanvas::onDrawDRRect(const SkRRect &outer, const SkRRect &inner, | |
| 84 const SkPaint &paint) { | |
| 85 this->updateMatrix(); | |
| 86 this->INHERITED::onDrawDRRect(outer, inner, paint); | |
| 87 this->restore(); | |
| 88 } | |
| 89 | |
| 90 void SkShadowPaintFilterCanvas::onDrawOval(const SkRect &rect, const SkPaint &pa int) { | |
| 91 this->updateMatrix(); | |
| 92 this->INHERITED::onDrawOval(rect, paint); | |
| 93 this->restore(); | |
| 94 } | |
| 95 | |
| 96 void SkShadowPaintFilterCanvas::onDrawPath(const SkPath &path, const SkPaint &pa int) { | |
| 97 this->updateMatrix(); | |
| 98 this->INHERITED::onDrawPath(path, paint); | |
| 99 this->restore(); | |
| 100 } | |
| 101 | |
| 102 void SkShadowPaintFilterCanvas::onDrawBitmap(const SkBitmap &bm, SkScalar left, SkScalar top, | |
| 103 const SkPaint *paint) { | |
| 104 this->updateMatrix(); | |
| 105 this->INHERITED::onDrawBitmap(bm, left, top, paint); | |
| 106 this->restore(); | |
| 107 } | |
| 108 | |
| 109 void SkShadowPaintFilterCanvas::onDrawBitmapRect(const SkBitmap &bm, const SkRec t *src, | |
| 110 const SkRect &dst, const SkPain t *paint, | |
| 111 SrcRectConstraint constraint) { | |
| 112 this->updateMatrix(); | |
| 113 this->INHERITED::onDrawBitmapRect(bm, src, dst, paint, constraint); | |
| 114 this->restore(); | |
| 115 } | |
| 116 | |
| 117 void SkShadowPaintFilterCanvas::onDrawBitmapNine(const SkBitmap &bm, const SkIRe ct ¢er, | |
| 118 const SkRect &dst, const SkPain t *paint) { | |
| 119 this->updateMatrix(); | |
| 120 this->INHERITED::onDrawBitmapNine(bm, center, dst, paint); | |
| 121 this->restore(); | |
| 122 } | |
| 123 | |
| 124 void SkShadowPaintFilterCanvas::onDrawImage(const SkImage *image, SkScalar left, | |
| 125 SkScalar top, const SkPaint *paint) { | |
| 126 this->updateMatrix(); | |
| 127 this->INHERITED::onDrawImage(image, left, top, paint); | |
| 128 this->restore(); | |
| 129 } | |
| 130 | |
| 131 void SkShadowPaintFilterCanvas::onDrawImageRect(const SkImage *image, const SkRe ct *src, | |
| 132 const SkRect &dst, const SkPaint *paint, | |
| 133 SrcRectConstraint constraint) { | |
| 134 this->updateMatrix(); | |
| 135 this->INHERITED::onDrawImageRect(image, src, dst, paint, constraint); | |
| 136 this->restore(); | |
| 137 } | |
| 138 | |
| 139 void SkShadowPaintFilterCanvas::onDrawImageNine(const SkImage *image, const SkIR ect ¢er, | |
| 140 const SkRect &dst, const SkPaint *paint) { | |
| 141 this->updateMatrix(); | |
| 142 this->INHERITED::onDrawImageNine(image, center, dst, paint); | |
| 143 this->restore(); | |
| 144 } | |
| 145 | |
| 146 | |
| 147 void SkShadowPaintFilterCanvas::onDrawVertices(VertexMode vmode, int vertexCount , | |
| 148 const SkPoint vertices[], const S kPoint texs[], | |
| 149 const SkColor colors[], SkXfermod e *xmode, | |
| 150 const uint16_t indices[], int ind exCount, | |
| 151 const SkPaint &paint) { | |
| 152 this->updateMatrix(); | |
| 153 this->INHERITED::onDrawVertices(vmode, vertexCount, vertices, texs, colors, | |
| 154 xmode, indices, indexCount, paint); | |
| 155 this->restore(); | |
| 156 } | |
| 157 | |
| 158 void SkShadowPaintFilterCanvas::onDrawPatch(const SkPoint cubics[], const SkColo r colors[], | |
| 159 const SkPoint texCoords[], SkXfermod e *xmode, | |
| 160 const SkPaint &paint) { | |
| 161 this->updateMatrix(); | |
| 162 this->INHERITED::onDrawPatch(cubics, colors, texCoords, xmode, paint); | |
| 163 this->restore(); | |
| 164 } | |
| 165 | |
| 166 void SkShadowPaintFilterCanvas::onDrawText(const void *text, size_t byteLength, SkScalar x, | |
| 167 SkScalar y, const SkPaint &paint) { | |
| 168 this->updateMatrix(); | |
| 169 this->INHERITED::onDrawText(text, byteLength, x, y, paint); | |
| 170 this->restore(); | |
| 171 } | |
| 172 | |
| 173 void SkShadowPaintFilterCanvas::onDrawPosText(const void *text, size_t byteLengt h, | |
| 174 const SkPoint pos[], const SkPaint &paint) { | |
| 175 this->updateMatrix(); | |
| 176 this->INHERITED::onDrawPosText(text, byteLength, pos, paint); | |
| 177 this->restore(); | |
| 178 } | |
| 179 | |
| 180 void SkShadowPaintFilterCanvas::onDrawPosTextH(const void *text, size_t byteLeng th, | |
| 181 const SkScalar xpos[], | |
| 182 SkScalar constY, const SkPaint &p aint) { | |
| 183 this->updateMatrix(); | |
| 184 this->INHERITED::onDrawPosTextH(text, byteLength, xpos, constY, paint); | |
| 185 this->restore(); | |
| 186 } | |
| 187 | |
| 188 void SkShadowPaintFilterCanvas::onDrawTextOnPath(const void *text, size_t byteLe ngth, | |
| 189 const SkPath &path, const SkMat rix *matrix, | |
| 190 const SkPaint &paint) { | |
| 191 this->updateMatrix(); | |
| 192 this->INHERITED::onDrawTextOnPath(text, byteLength, path, matrix, paint); | |
| 193 this->restore(); | |
| 194 } | |
| 195 | |
| 196 void SkShadowPaintFilterCanvas::onDrawTextRSXform(const void *text, size_t byteL ength, | |
| 197 const SkRSXform xform[], const SkRect *cull, | |
| 198 const SkPaint &paint) { | |
| 199 this->updateMatrix(); | |
| 200 this->INHERITED::onDrawTextRSXform(text, byteLength, xform, cull, paint); | |
| 201 this->restore(); | |
| 202 } | |
| 203 | |
| 204 void SkShadowPaintFilterCanvas::onDrawTextBlob(const SkTextBlob *blob, SkScalar x, SkScalar y, | |
| 205 const SkPaint &paint) { | |
| 206 this->updateMatrix(); | |
| 207 this->INHERITED::onDrawTextBlob(blob, x, y, paint); | |
| 208 this->restore(); | |
| 209 } | |
| 210 | |
| 211 #endif | |
| OLD | NEW |