| 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 "SkCanvas.h" | 8 #include "SkCanvas.h" |
| 9 #include "SkLazyPtr.h" |
| 9 #include "SkMiniRecorder.h" | 10 #include "SkMiniRecorder.h" |
| 10 #include "SkPicture.h" | 11 #include "SkPicture.h" |
| 11 #include "SkPictureCommon.h" | 12 #include "SkPictureCommon.h" |
| 12 #include "SkRecordDraw.h" | 13 #include "SkRecordDraw.h" |
| 13 #include "SkTextBlob.h" | 14 #include "SkTextBlob.h" |
| 14 | 15 |
| 15 using namespace SkRecords; | 16 using namespace SkRecords; |
| 16 | 17 |
| 17 // SkEmptyPicture could logically be a singleton, but that plays badly with Blin
k's | |
| 18 // Debug-only adopted() / requireAdoption() tracking in sk_ref_cnt_ext_debug.h. | |
| 19 // TODO(mtklein): modify sk_ref_cnt_ext_debug.h to play better with non-new'd ob
jects. | |
| 20 class SkEmptyPicture final : public SkPicture { | 18 class SkEmptyPicture final : public SkPicture { |
| 21 public: | 19 public: |
| 22 void playback(SkCanvas*, AbortCallback*) const override { } | 20 void playback(SkCanvas*, AbortCallback*) const override { } |
| 23 | 21 |
| 24 size_t approximateBytesUsed() const override { return sizeof(*this); } | 22 size_t approximateBytesUsed() const override { return sizeof(*this); } |
| 25 int approximateOpCount() const override { return 0; } | 23 int approximateOpCount() const override { return 0; } |
| 26 SkRect cullRect() const override { return SkRect::MakeEmpty(); } | 24 SkRect cullRect() const override { return SkRect::MakeEmpty(); } |
| 27 bool hasText() const override { return false; } | 25 bool hasText() const override { return false; } |
| 28 int numSlowPaths() const override { return 0; } | 26 int numSlowPaths() const override { return 0; } |
| 29 bool willPlayBackBitmaps() const override { return false; } | 27 bool willPlayBackBitmaps() const override { return false; } |
| 30 }; | 28 }; |
| 29 SK_DECLARE_STATIC_LAZY_PTR(SkEmptyPicture, gEmptyPicture); |
| 31 | 30 |
| 32 template <typename T> | 31 template <typename T> |
| 33 class SkMiniPicture final : public SkPicture { | 32 class SkMiniPicture final : public SkPicture { |
| 34 public: | 33 public: |
| 35 SkMiniPicture(SkRect cull, T* op) : fCull(cull) { | 34 SkMiniPicture(SkRect cull, T* op) : fCull(cull) { |
| 36 memcpy(&fOp, op, sizeof(fOp)); // We take ownership of op's guts. | 35 memcpy(&fOp, op, sizeof(fOp)); // We take ownership of op's guts. |
| 37 } | 36 } |
| 38 | 37 |
| 39 void playback(SkCanvas* c, AbortCallback*) const override { | 38 void playback(SkCanvas* c, AbortCallback*) const override { |
| 40 SkRecords::Draw(c, nullptr, nullptr, 0, nullptr)(fOp); | 39 SkRecords::Draw(c, nullptr, nullptr, 0, nullptr)(fOp); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 #undef TRY_TO_STORE | 86 #undef TRY_TO_STORE |
| 88 | 87 |
| 89 | 88 |
| 90 SkPicture* SkMiniRecorder::detachAsPicture(const SkRect& cull) { | 89 SkPicture* SkMiniRecorder::detachAsPicture(const SkRect& cull) { |
| 91 #define CASE(Type) \ | 90 #define CASE(Type) \ |
| 92 case State::k##Type: \ | 91 case State::k##Type: \ |
| 93 fState = State::kEmpty; \ | 92 fState = State::kEmpty; \ |
| 94 return SkNEW_ARGS(SkMiniPicture<Type>, (cull, reinterpret_cast<Type*>(fB
uffer.get()))) | 93 return SkNEW_ARGS(SkMiniPicture<Type>, (cull, reinterpret_cast<Type*>(fB
uffer.get()))) |
| 95 | 94 |
| 96 switch (fState) { | 95 switch (fState) { |
| 97 case State::kEmpty: return SkNEW(SkEmptyPicture); | 96 case State::kEmpty: return SkRef(gEmptyPicture.get()); |
| 98 CASE(DrawPath); | 97 CASE(DrawPath); |
| 99 CASE(DrawRect); | 98 CASE(DrawRect); |
| 100 CASE(DrawTextBlob); | 99 CASE(DrawTextBlob); |
| 101 } | 100 } |
| 102 SkASSERT(false); | 101 SkASSERT(false); |
| 103 return nullptr; | 102 return nullptr; |
| 104 #undef CASE | 103 #undef CASE |
| 105 } | 104 } |
| 106 | 105 |
| 107 void SkMiniRecorder::flushAndReset(SkCanvas* canvas) { | 106 void SkMiniRecorder::flushAndReset(SkCanvas* canvas) { |
| 108 #define CASE(Type) \ | 107 #define CASE(Type) \ |
| 109 case State::k##Type: { \ | 108 case State::k##Type: { \ |
| 110 fState = State::kEmpty; \ | 109 fState = State::kEmpty; \ |
| 111 Type* op = reinterpret_cast<Type*>(fBuffer.get()); \ | 110 Type* op = reinterpret_cast<Type*>(fBuffer.get()); \ |
| 112 SkRecords::Draw(canvas, nullptr, nullptr, 0, nullptr)(*op); \ | 111 SkRecords::Draw(canvas, nullptr, nullptr, 0, nullptr)(*op); \ |
| 113 op->~Type(); \ | 112 op->~Type(); \ |
| 114 } return | 113 } return |
| 115 | 114 |
| 116 switch (fState) { | 115 switch (fState) { |
| 117 case State::kEmpty: return; | 116 case State::kEmpty: return; |
| 118 CASE(DrawPath); | 117 CASE(DrawPath); |
| 119 CASE(DrawRect); | 118 CASE(DrawRect); |
| 120 CASE(DrawTextBlob); | 119 CASE(DrawTextBlob); |
| 121 } | 120 } |
| 122 SkASSERT(false); | 121 SkASSERT(false); |
| 123 #undef CASE | 122 #undef CASE |
| 124 } | 123 } |
| OLD | NEW |