| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 #ifndef SkNoSaveLayerCanvas_DEFINED | 8 #ifndef SkNoSaveLayerCanvas_DEFINED |
| 9 #define SkNoSaveLayerCanvas_DEFINED | 9 #define SkNoSaveLayerCanvas_DEFINED |
| 10 | 10 |
| 11 #include "SkCanvas.h" | 11 #include "SkCanvas.h" |
| 12 #include "SkRRect.h" | 12 #include "SkRRect.h" |
| 13 | 13 |
| 14 // The NoSaveLayerCanvas is used to play back SkPictures when the saveLayer | 14 // The NoSaveLayerCanvas is used to play back SkPictures when the saveLayer |
| 15 // functionality isn't required (e.g., during analysis of the draw calls). | 15 // functionality isn't required (e.g., during analysis of the draw calls). |
| 16 // It also simplifies the clipping calls to only use rectangles. | 16 // It also simplifies the clipping calls to only use rectangles. |
| 17 class SkNoSaveLayerCanvas : public SkCanvas { | 17 class SkNoSaveLayerCanvas : public SkCanvas { |
| 18 public: | 18 public: |
| 19 SkNoSaveLayerCanvas(SkBaseDevice* device) : INHERITED(device) {} | 19 SkNoSaveLayerCanvas(SkBaseDevice* device) : INHERITED(device) {} |
| 20 | 20 |
| 21 // turn saveLayer() into save() for speed, should not affect correctness. | 21 protected: |
| 22 virtual int saveLayer(const SkRect* bounds, | 22 virtual bool onSaveLayer(const SkRect* bounds, const SkPaint* paint, SaveFla
gs flags) |
| 23 const SkPaint* paint, | 23 SK_OVERRIDE { |
| 24 SaveFlags flags) SK_OVERRIDE { | 24 this->INHERITED::onSaveLayer(bounds, paint, flags); |
| 25 | 25 return false; |
| 26 // Like SkPictureRecord, we don't want to create layers, but we do need | |
| 27 // to respect the save and (possibly) its rect-clip. | |
| 28 int count = this->INHERITED::save(flags); | |
| 29 if (NULL != bounds) { | |
| 30 this->INHERITED::clipRectBounds(bounds, flags, NULL); | |
| 31 } | |
| 32 return count; | |
| 33 } | 26 } |
| 34 | 27 |
| 35 protected: | |
| 36 // disable aa for speed | 28 // disable aa for speed |
| 37 virtual void onClipRect(const SkRect& rect, SkRegion::Op op, ClipEdgeStyle)
SK_OVERRIDE { | 29 virtual void onClipRect(const SkRect& rect, SkRegion::Op op, ClipEdgeStyle)
SK_OVERRIDE { |
| 38 this->INHERITED::onClipRect(rect, op, kHard_ClipEdgeStyle); | 30 this->INHERITED::onClipRect(rect, op, kHard_ClipEdgeStyle); |
| 39 } | 31 } |
| 40 | 32 |
| 41 // for speed, just respect the bounds, and disable AA. May give us a few | 33 // for speed, just respect the bounds, and disable AA. May give us a few |
| 42 // false positives and negatives. | 34 // false positives and negatives. |
| 43 virtual void onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeStyle)
SK_OVERRIDE { | 35 virtual void onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeStyle)
SK_OVERRIDE { |
| 44 this->updateClipConservativelyUsingBounds(path.getBounds(), op, | 36 this->updateClipConservativelyUsingBounds(path.getBounds(), op, |
| 45 path.isInverseFillType()); | 37 path.isInverseFillType()); |
| 46 } | 38 } |
| 47 virtual void onClipRRect(const SkRRect& rrect, SkRegion::Op op, ClipEdgeStyl
e) SK_OVERRIDE { | 39 virtual void onClipRRect(const SkRRect& rrect, SkRegion::Op op, ClipEdgeStyl
e) SK_OVERRIDE { |
| 48 this->updateClipConservativelyUsingBounds(rrect.getBounds(), op, false); | 40 this->updateClipConservativelyUsingBounds(rrect.getBounds(), op, false); |
| 49 } | 41 } |
| 50 | 42 |
| 51 private: | 43 private: |
| 52 typedef SkCanvas INHERITED; | 44 typedef SkCanvas INHERITED; |
| 53 }; | 45 }; |
| 54 | 46 |
| 55 #endif // SkNoSaveLayerCanvas_DEFINED | 47 #endif // SkNoSaveLayerCanvas_DEFINED |
| OLD | NEW |