| 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 "SkTLazy.h" | 9 #include "SkTLazy.h" |
| 10 #include "SkLazyPtr.h" | 10 #include "SkLazyPtr.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 SkRect fCull; | 55 SkRect fCull; |
| 56 T fOp; | 56 T fOp; |
| 57 }; | 57 }; |
| 58 | 58 |
| 59 | 59 |
| 60 SkMiniRecorder::SkMiniRecorder() : fState(State::kEmpty) {} | 60 SkMiniRecorder::SkMiniRecorder() : fState(State::kEmpty) {} |
| 61 SkMiniRecorder::~SkMiniRecorder() { | 61 SkMiniRecorder::~SkMiniRecorder() { |
| 62 if (fState != State::kEmpty) { | 62 if (fState != State::kEmpty) { |
| 63 // We have internal state pending. | 63 // We have internal state pending. |
| 64 // Detaching then deleting a picture is an easy way to clean up. | 64 // Detaching then deleting a picture is an easy way to clean up. |
| 65 SkDELETE(this->detachAsPicture(SkRect::MakeEmpty())); | 65 delete this->detachAsPicture(SkRect::MakeEmpty()); |
| 66 } | 66 } |
| 67 SkASSERT(fState == State::kEmpty); | 67 SkASSERT(fState == State::kEmpty); |
| 68 } | 68 } |
| 69 | 69 |
| 70 #define TRY_TO_STORE(Type, ...) \ | 70 #define TRY_TO_STORE(Type, ...) \ |
| 71 if (fState != State::kEmpty) { return false; } \ | 71 if (fState != State::kEmpty) { return false; } \ |
| 72 fState = State::k##Type; \ | 72 fState = State::k##Type; \ |
| 73 new (fBuffer.get()) Type(__VA_ARGS__); \ | 73 new (fBuffer.get()) Type(__VA_ARGS__); \ |
| 74 return true | 74 return true |
| 75 | 75 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 95 TRY_TO_STORE(DrawPath, paint, path); | 95 TRY_TO_STORE(DrawPath, paint, path); |
| 96 } | 96 } |
| 97 | 97 |
| 98 bool SkMiniRecorder::drawTextBlob(const SkTextBlob* b, SkScalar x, SkScalar y, c
onst SkPaint& p) { | 98 bool SkMiniRecorder::drawTextBlob(const SkTextBlob* b, SkScalar x, SkScalar y, c
onst SkPaint& p) { |
| 99 TRY_TO_STORE(DrawTextBlob, p, b, x, y); | 99 TRY_TO_STORE(DrawTextBlob, p, b, x, y); |
| 100 } | 100 } |
| 101 #undef TRY_TO_STORE | 101 #undef TRY_TO_STORE |
| 102 | 102 |
| 103 | 103 |
| 104 SkPicture* SkMiniRecorder::detachAsPicture(const SkRect& cull) { | 104 SkPicture* SkMiniRecorder::detachAsPicture(const SkRect& cull) { |
| 105 #define CASE(Type) \ | 105 #define CASE(Type) \ |
| 106 case State::k##Type: \ | 106 case State::k##Type: \ |
| 107 fState = State::kEmpty; \ | 107 fState = State::kEmpty; \ |
| 108 return SkNEW_ARGS(SkMiniPicture<Type>, (cull, reinterpret_cast<Type*>(fB
uffer.get()))) | 108 return new SkMiniPicture<Type>(cull, reinterpret_cast<Type*>(fBuffer.get
())) |
| 109 | 109 |
| 110 switch (fState) { | 110 switch (fState) { |
| 111 case State::kEmpty: return SkRef(gEmptyPicture.get()); | 111 case State::kEmpty: return SkRef(gEmptyPicture.get()); |
| 112 CASE(DrawBitmapRectFixedSize); | 112 CASE(DrawBitmapRectFixedSize); |
| 113 CASE(DrawPath); | 113 CASE(DrawPath); |
| 114 CASE(DrawRect); | 114 CASE(DrawRect); |
| 115 CASE(DrawTextBlob); | 115 CASE(DrawTextBlob); |
| 116 } | 116 } |
| 117 SkASSERT(false); | 117 SkASSERT(false); |
| 118 return nullptr; | 118 return nullptr; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 131 switch (fState) { | 131 switch (fState) { |
| 132 case State::kEmpty: return; | 132 case State::kEmpty: return; |
| 133 CASE(DrawBitmapRectFixedSize); | 133 CASE(DrawBitmapRectFixedSize); |
| 134 CASE(DrawPath); | 134 CASE(DrawPath); |
| 135 CASE(DrawRect); | 135 CASE(DrawRect); |
| 136 CASE(DrawTextBlob); | 136 CASE(DrawTextBlob); |
| 137 } | 137 } |
| 138 SkASSERT(false); | 138 SkASSERT(false); |
| 139 #undef CASE | 139 #undef CASE |
| 140 } | 140 } |
| OLD | NEW |