| 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 #ifndef SkMiniRecorder_DEFINED | 8 #ifndef SkMiniRecorder_DEFINED |
| 9 #define SkMiniRecorder_DEFINED | 9 #define SkMiniRecorder_DEFINED |
| 10 | 10 |
| 11 #include "SkRecords.h" | 11 #include "SkRecords.h" |
| 12 #include "SkScalar.h" | 12 #include "SkScalar.h" |
| 13 #include "SkTypes.h" | 13 #include "SkTypes.h" |
| 14 class SkCanvas; | 14 class SkCanvas; |
| 15 | 15 |
| 16 // Records small pictures, but only a limited subset of the canvas API, and may
fail. | 16 // Records small pictures, but only a limited subset of the canvas API, and may
fail. |
| 17 class SkMiniRecorder : SkNoncopyable { | 17 class SkMiniRecorder : SkNoncopyable { |
| 18 public: | 18 public: |
| 19 SkMiniRecorder(); | 19 SkMiniRecorder(); |
| 20 ~SkMiniRecorder(); | 20 ~SkMiniRecorder(); |
| 21 | 21 |
| 22 // Try to record an op. Returns false on failure. | 22 // Try to record an op. Returns false on failure. |
| 23 bool drawBitmapRectToRect(const SkBitmap&, const SkRect* src, const SkRect&
dst, |
| 24 const SkPaint*, SkCanvas::DrawBitmapRectFlags); |
| 23 bool drawPath(const SkPath&, const SkPaint&); | 25 bool drawPath(const SkPath&, const SkPaint&); |
| 24 bool drawRect(const SkRect&, const SkPaint&); | 26 bool drawRect(const SkRect&, const SkPaint&); |
| 25 bool drawTextBlob(const SkTextBlob*, SkScalar x, SkScalar y, const SkPaint&)
; | 27 bool drawTextBlob(const SkTextBlob*, SkScalar x, SkScalar y, const SkPaint&)
; |
| 26 | 28 |
| 27 // Detach anything we've recorded as a picture, resetting this SkMiniRecorde
r. | 29 // Detach anything we've recorded as a picture, resetting this SkMiniRecorde
r. |
| 28 SkPicture* detachAsPicture(const SkRect& cull); | 30 SkPicture* detachAsPicture(const SkRect& cull); |
| 29 | 31 |
| 30 // Flush anything we've recorded to the canvas, resetting this SkMiniRecorde
r. | 32 // Flush anything we've recorded to the canvas, resetting this SkMiniRecorde
r. |
| 31 // This is logically the same as but rather more efficient than: | 33 // This is logically the same as but rather more efficient than: |
| 32 // SkAutoTUnref<SkPicture> pic(this->detachAsPicture(SkRect::MakeEmpty())
); | 34 // SkAutoTUnref<SkPicture> pic(this->detachAsPicture(SkRect::MakeEmpty())
); |
| 33 // pic->playback(canvas); | 35 // pic->playback(canvas); |
| 34 void flushAndReset(SkCanvas*); | 36 void flushAndReset(SkCanvas*); |
| 35 | 37 |
| 36 private: | 38 private: |
| 37 enum class State { kEmpty, kDrawPath, kDrawRect, kDrawTextBlob }; | 39 enum class State { |
| 40 kEmpty, |
| 41 kDrawBitmapRectToRectFixedSize, |
| 42 kDrawPath, |
| 43 kDrawRect, |
| 44 kDrawTextBlob, |
| 45 }; |
| 38 | 46 |
| 39 State fState; | 47 State fState; |
| 40 | 48 |
| 41 template <size_t A, size_t B> | 49 template <size_t A, size_t B> |
| 42 struct Max { static const size_t val = A > B ? A : B; }; | 50 struct Max { static const size_t val = A > B ? A : B; }; |
| 43 | 51 |
| 44 static const size_t kInlineStorage = Max<sizeof(SkRecords::DrawPath), | 52 static const size_t kInlineStorage = |
| 45 Max<sizeof(SkRecords::DrawRect), | 53 Max<sizeof(SkRecords::DrawBitmapRectToRectFixedSize), |
| 46 sizeof(SkRecords::DrawTextBlob)>::v
al>::val; | 54 Max<sizeof(SkRecords::DrawPath), |
| 55 Max<sizeof(SkRecords::DrawRect), |
| 56 sizeof(SkRecords::DrawTextBlob)>::val>::val>::val; |
| 47 SkAlignedSStorage<kInlineStorage> fBuffer; | 57 SkAlignedSStorage<kInlineStorage> fBuffer; |
| 48 }; | 58 }; |
| 49 | 59 |
| 50 #endif//SkMiniRecorder_DEFINED | 60 #endif//SkMiniRecorder_DEFINED |
| OLD | NEW |