Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(130)

Side by Side Diff: src/core/SkMiniRecorder.cpp

Issue 1811703002: return pictures as sk_sp (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rely on RVO in picturerecorder Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/core/SkDrawable.cpp ('k') | src/core/SkPicture.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "SkMiniRecorder.h" 10 #include "SkMiniRecorder.h"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 delete this->detachAsPicture(SkRect::MakeEmpty()); 65 (void)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 18 matching lines...) Expand all
94 bool SkMiniRecorder::drawPath(const SkPath& path, const SkPaint& paint) { 94 bool SkMiniRecorder::drawPath(const SkPath& path, const SkPaint& paint) {
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 sk_sp<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 new SkMiniPicture<Type>(cull, reinterpret_cast<Type*>(fBuffer.get ())) 108 return sk_make_sp<SkMiniPicture<Type>>(cull, reinterpret_cast<Type*>(fBu ffer.get()))
109 109
110 switch (fState) { 110 switch (fState) {
111 case State::kEmpty: return SkRef(gEmptyPicture.get([]{ return new SkEmpt yPicture; })); 111 case State::kEmpty: return sk_ref_sp(gEmptyPicture.get([]{ return new Sk EmptyPicture; }));
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;
119 #undef CASE 119 #undef CASE
120 } 120 }
121 121
122 void SkMiniRecorder::flushAndReset(SkCanvas* canvas) { 122 void SkMiniRecorder::flushAndReset(SkCanvas* canvas) {
123 #define CASE(Type) \ 123 #define CASE(Type) \
124 case State::k##Type: { \ 124 case State::k##Type: { \
125 fState = State::kEmpty; \ 125 fState = State::kEmpty; \
126 Type* op = reinterpret_cast<Type*>(fBuffer.get()); \ 126 Type* op = reinterpret_cast<Type*>(fBuffer.get()); \
127 SkRecords::Draw(canvas, nullptr, nullptr, 0, nullptr)(*op); \ 127 SkRecords::Draw(canvas, nullptr, nullptr, 0, nullptr)(*op); \
128 op->~Type(); \ 128 op->~Type(); \
129 } return 129 } return
130 130
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 }
OLDNEW
« no previous file with comments | « src/core/SkDrawable.cpp ('k') | src/core/SkPicture.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698