| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 "SkPaintFilterCanvas.h" | 8 #include "SkPaintFilterCanvas.h" |
| 9 | 9 |
| 10 #include "SkPaint.h" | 10 #include "SkPaint.h" |
| 11 #include "SkTLazy.h" | 11 #include "SkTLazy.h" |
| 12 | 12 |
| 13 class SkPaintFilterCanvas::AutoPaintFilter { | 13 class SkPaintFilterCanvas::AutoPaintFilter { |
| 14 public: | 14 public: |
| 15 AutoPaintFilter(const SkPaintFilterCanvas* canvas, Type type, const SkPaint*
paint) | 15 AutoPaintFilter(const SkPaintFilterCanvas* canvas, Type type, const SkPaint*
paint) |
| 16 : fOrigPaint(paint) { | 16 : fPaint(paint) { |
| 17 fShouldDraw = canvas->onFilter(fOrigPaint, type, &fFilteredPaint); | 17 fShouldDraw = canvas->onFilter(&fPaint, type); |
| 18 } | 18 } |
| 19 | 19 |
| 20 AutoPaintFilter(const SkPaintFilterCanvas* canvas, Type type, const SkPaint&
paint) | 20 AutoPaintFilter(const SkPaintFilterCanvas* canvas, Type type, const SkPaint&
paint) |
| 21 : AutoPaintFilter(canvas, type, &paint) { } | 21 : AutoPaintFilter(canvas, type, &paint) { } |
| 22 | 22 |
| 23 const SkPaint* paint() const { | 23 const SkPaint* paint() const { return fPaint; } |
| 24 return fFilteredPaint.isValid() ? fFilteredPaint.get() : fOrigPaint; | |
| 25 } | |
| 26 | 24 |
| 27 bool shouldDraw() const { return fShouldDraw; } | 25 bool shouldDraw() const { return fShouldDraw; } |
| 28 | 26 |
| 29 private: | 27 private: |
| 30 const SkPaint* fOrigPaint; | 28 SkTCopyOnFirstWrite<SkPaint> fPaint; |
| 31 SkTLazy<SkPaint> fFilteredPaint; | 29 bool fShouldDraw; |
| 32 bool fShouldDraw; | |
| 33 }; | 30 }; |
| 34 | 31 |
| 35 SkPaintFilterCanvas::SkPaintFilterCanvas(int width, int height) : INHERITED(widt
h, height) { } | 32 SkPaintFilterCanvas::SkPaintFilterCanvas(int width, int height) : INHERITED(widt
h, height) { } |
| 36 | 33 |
| 37 SkPaintFilterCanvas::SkPaintFilterCanvas(SkCanvas *canvas) | 34 SkPaintFilterCanvas::SkPaintFilterCanvas(SkCanvas *canvas) |
| 38 : INHERITED(canvas->imageInfo().width(), canvas->imageInfo().height()) { | 35 : INHERITED(canvas->imageInfo().width(), canvas->imageInfo().height()) { |
| 39 | 36 |
| 40 // Transfer matrix & clip state before adding the target canvas. | 37 // Transfer matrix & clip state before adding the target canvas. |
| 41 SkIRect devClip; | 38 SkIRect devClip; |
| 42 canvas->getClipDeviceBounds(&devClip); | 39 canvas->getClipDeviceBounds(&devClip); |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 } | 204 } |
| 208 } | 205 } |
| 209 | 206 |
| 210 void SkPaintFilterCanvas::onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkS
calar y, | 207 void SkPaintFilterCanvas::onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkS
calar y, |
| 211 const SkPaint& paint) { | 208 const SkPaint& paint) { |
| 212 AutoPaintFilter apf(this, kTextBlob_Type, paint); | 209 AutoPaintFilter apf(this, kTextBlob_Type, paint); |
| 213 if (apf.shouldDraw()) { | 210 if (apf.shouldDraw()) { |
| 214 this->INHERITED::onDrawTextBlob(blob, x, y, *apf.paint()); | 211 this->INHERITED::onDrawTextBlob(blob, x, y, *apf.paint()); |
| 215 } | 212 } |
| 216 } | 213 } |
| OLD | NEW |