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 "SkMiniRecorder.h" | 9 #include "SkMiniRecorder.h" |
10 #include "SkPicture.h" | 10 #include "SkPicture.h" |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 | 79 |
80 bool SkMiniRecorder::drawPath(const SkPath& path, const SkPaint& paint) { | 80 bool SkMiniRecorder::drawPath(const SkPath& path, const SkPaint& paint) { |
81 TRY_TO_STORE(DrawPath, paint, path); | 81 TRY_TO_STORE(DrawPath, paint, path); |
82 } | 82 } |
83 | 83 |
84 bool SkMiniRecorder::drawTextBlob(const SkTextBlob* b, SkScalar x, SkScalar y, c
onst SkPaint& p) { | 84 bool SkMiniRecorder::drawTextBlob(const SkTextBlob* b, SkScalar x, SkScalar y, c
onst SkPaint& p) { |
85 TRY_TO_STORE(DrawTextBlob, p, b, x, y); | 85 TRY_TO_STORE(DrawTextBlob, p, b, x, y); |
86 } | 86 } |
87 #undef TRY_TO_STORE | 87 #undef TRY_TO_STORE |
88 | 88 |
| 89 |
| 90 SkPicture* SkMiniRecorder::detachAsPicture(const SkRect& cull) { |
89 #define CASE(Type) \ | 91 #define CASE(Type) \ |
90 case State::k##Type: \ | 92 case State::k##Type: \ |
91 fState = State::kEmpty; \ | 93 fState = State::kEmpty; \ |
92 return SkNEW_ARGS(SkMiniPicture<Type>, (cull, reinterpret_cast<Type*>(fB
uffer.get()))) | 94 return SkNEW_ARGS(SkMiniPicture<Type>, (cull, reinterpret_cast<Type*>(fB
uffer.get()))) |
93 | 95 |
94 SkPicture* SkMiniRecorder::detachAsPicture(const SkRect& cull) { | |
95 switch (fState) { | 96 switch (fState) { |
96 case State::kEmpty: return SkNEW(SkEmptyPicture); | 97 case State::kEmpty: return SkNEW(SkEmptyPicture); |
97 CASE(DrawPath); | 98 CASE(DrawPath); |
98 CASE(DrawRect); | 99 CASE(DrawRect); |
99 CASE(DrawTextBlob); | 100 CASE(DrawTextBlob); |
100 } | 101 } |
101 SkASSERT(false); | 102 SkASSERT(false); |
102 return NULL; | 103 return nullptr; |
| 104 #undef CASE |
103 } | 105 } |
| 106 |
| 107 void SkMiniRecorder::flushAndReset(SkCanvas* canvas) { |
| 108 #define CASE(Type) \ |
| 109 case State::k##Type: { \ |
| 110 fState = State::kEmpty; \ |
| 111 Type* op = reinterpret_cast<Type*>(fBuffer.get()); \ |
| 112 SkRecords::Draw(canvas, nullptr, nullptr, 0, nullptr)(*op); \ |
| 113 op->~Type(); \ |
| 114 } return |
| 115 |
| 116 switch (fState) { |
| 117 case State::kEmpty: return; |
| 118 CASE(DrawPath); |
| 119 CASE(DrawRect); |
| 120 CASE(DrawTextBlob); |
| 121 } |
| 122 SkASSERT(false); |
104 #undef CASE | 123 #undef CASE |
| 124 } |
OLD | NEW |