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

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

Issue 1945293004: Revert of SkOncePtr -> SkOnce (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 7 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/SkMessageBus.h ('k') | src/core/SkPathRef.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"
11 #include "SkOnce.h" 11 #include "SkOncePtr.h"
12 #include "SkPicture.h" 12 #include "SkPicture.h"
13 #include "SkPictureCommon.h" 13 #include "SkPictureCommon.h"
14 #include "SkRecordDraw.h" 14 #include "SkRecordDraw.h"
15 #include "SkTextBlob.h" 15 #include "SkTextBlob.h"
16 16
17 using namespace SkRecords; 17 using namespace SkRecords;
18 18
19 class SkEmptyPicture final : public SkPicture { 19 class SkEmptyPicture final : public SkPicture {
20 public: 20 public:
21 void playback(SkCanvas*, AbortCallback*) const override { } 21 void playback(SkCanvas*, AbortCallback*) const override { }
22 22
23 size_t approximateBytesUsed() const override { return sizeof(*this); } 23 size_t approximateBytesUsed() const override { return sizeof(*this); }
24 int approximateOpCount() const override { return 0; } 24 int approximateOpCount() const override { return 0; }
25 SkRect cullRect() const override { return SkRect::MakeEmpty(); } 25 SkRect cullRect() const override { return SkRect::MakeEmpty(); }
26 bool hasText() const override { return false; } 26 bool hasText() const override { return false; }
27 int numSlowPaths() const override { return 0; } 27 int numSlowPaths() const override { return 0; }
28 bool willPlayBackBitmaps() const override { return false; } 28 bool willPlayBackBitmaps() const override { return false; }
29 }; 29 };
30 SK_DECLARE_STATIC_ONCE_PTR(SkEmptyPicture, gEmptyPicture);
30 31
31 template <typename T> 32 template <typename T>
32 class SkMiniPicture final : public SkPicture { 33 class SkMiniPicture final : public SkPicture {
33 public: 34 public:
34 SkMiniPicture(SkRect cull, T* op) : fCull(cull) { 35 SkMiniPicture(SkRect cull, T* op) : fCull(cull) {
35 memcpy(&fOp, op, sizeof(fOp)); // We take ownership of op's guts. 36 memcpy(&fOp, op, sizeof(fOp)); // We take ownership of op's guts.
36 } 37 }
37 38
38 void playback(SkCanvas* c, AbortCallback*) const override { 39 void playback(SkCanvas* c, AbortCallback*) const override {
39 SkRecords::Draw(c, nullptr, nullptr, 0, nullptr)(fOp); 40 SkRecords::Draw(c, nullptr, nullptr, 0, nullptr)(fOp);
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 } 100 }
100 #undef TRY_TO_STORE 101 #undef TRY_TO_STORE
101 102
102 103
103 sk_sp<SkPicture> SkMiniRecorder::detachAsPicture(const SkRect& cull) { 104 sk_sp<SkPicture> SkMiniRecorder::detachAsPicture(const SkRect& cull) {
104 #define CASE(Type) \ 105 #define CASE(Type) \
105 case State::k##Type: \ 106 case State::k##Type: \
106 fState = State::kEmpty; \ 107 fState = State::kEmpty; \
107 return sk_make_sp<SkMiniPicture<Type>>(cull, reinterpret_cast<Type*>(fBu ffer.get())) 108 return sk_make_sp<SkMiniPicture<Type>>(cull, reinterpret_cast<Type*>(fBu ffer.get()))
108 109
109 static SkOnce once;
110 static SkPicture* empty;
111
112 switch (fState) { 110 switch (fState) {
113 case State::kEmpty: 111 case State::kEmpty: return sk_ref_sp(gEmptyPicture.get([]{ return new Sk EmptyPicture; }));
114 once([]{ empty = new SkEmptyPicture; });
115 return sk_ref_sp(empty);
116 CASE(DrawBitmapRectFixedSize); 112 CASE(DrawBitmapRectFixedSize);
117 CASE(DrawPath); 113 CASE(DrawPath);
118 CASE(DrawRect); 114 CASE(DrawRect);
119 CASE(DrawTextBlob); 115 CASE(DrawTextBlob);
120 } 116 }
121 SkASSERT(false); 117 SkASSERT(false);
122 return nullptr; 118 return nullptr;
123 #undef CASE 119 #undef CASE
124 } 120 }
125 121
126 void SkMiniRecorder::flushAndReset(SkCanvas* canvas) { 122 void SkMiniRecorder::flushAndReset(SkCanvas* canvas) {
127 #define CASE(Type) \ 123 #define CASE(Type) \
128 case State::k##Type: { \ 124 case State::k##Type: { \
129 fState = State::kEmpty; \ 125 fState = State::kEmpty; \
130 Type* op = reinterpret_cast<Type*>(fBuffer.get()); \ 126 Type* op = reinterpret_cast<Type*>(fBuffer.get()); \
131 SkRecords::Draw(canvas, nullptr, nullptr, 0, nullptr)(*op); \ 127 SkRecords::Draw(canvas, nullptr, nullptr, 0, nullptr)(*op); \
132 op->~Type(); \ 128 op->~Type(); \
133 } return 129 } return
134 130
135 switch (fState) { 131 switch (fState) {
136 case State::kEmpty: return; 132 case State::kEmpty: return;
137 CASE(DrawBitmapRectFixedSize); 133 CASE(DrawBitmapRectFixedSize);
138 CASE(DrawPath); 134 CASE(DrawPath);
139 CASE(DrawRect); 135 CASE(DrawRect);
140 CASE(DrawTextBlob); 136 CASE(DrawTextBlob);
141 } 137 }
142 SkASSERT(false); 138 SkASSERT(false);
143 #undef CASE 139 #undef CASE
144 } 140 }
OLDNEW
« no previous file with comments | « src/core/SkMessageBus.h ('k') | src/core/SkPathRef.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698