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

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

Issue 1130283004: Revert of Sketch splitting SkPicture into an interface and SkBigPicture. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 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/SkMiniRecorder.h ('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
(Empty)
1 /*
2 * Copyright 2015 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "SkCanvas.h"
9 #include "SkLazyPtr.h"
10 #include "SkMiniRecorder.h"
11 #include "SkPicture.h"
12 #include "SkPictureCommon.h"
13 #include "SkRecordDraw.h"
14 #include "SkTextBlob.h"
15
16 using namespace SkRecords;
17
18 class SkEmptyPicture final : public SkPicture {
19 public:
20 void playback(SkCanvas*, AbortCallback*) const override { }
21
22 size_t approximateBytesUsed() const override { return sizeof(*this); }
23 int approximateOpCount() const override { return 0; }
24 SkRect cullRect() const override { return SkRect::MakeEmpty(); }
25 bool hasText() const override { return false; }
26 int numSlowPaths() const override { return 0; }
27 bool willPlayBackBitmaps() const override { return false; }
28 };
29 SK_DECLARE_STATIC_LAZY_PTR(SkEmptyPicture, gEmptyPicture);
30
31 template <typename T>
32 class SkMiniPicture final : public SkPicture {
33 public:
34 SkMiniPicture(SkRect cull, T* op) : fCull(cull) {
35 memcpy(&fOp, op, sizeof(fOp)); // We take ownership of op's guts.
36 }
37
38 void playback(SkCanvas* c, AbortCallback*) const override {
39 SkRecords::Draw(c, nullptr, nullptr, 0, nullptr)(fOp);
40 }
41
42 size_t approximateBytesUsed() const override { return sizeof(*this); }
43 int approximateOpCount() const override { return 1; }
44 SkRect cullRect() const override { return fCull; }
45 bool hasText() const override { return SkTextHunter()(fOp); }
46 bool willPlayBackBitmaps() const override { return SkBitmapHunter()(fOp); }
47 int numSlowPaths() const override {
48 SkPathCounter counter;
49 counter(fOp);
50 return counter.fNumSlowPathsAndDashEffects;
51 }
52
53 private:
54 SkRect fCull;
55 T fOp;
56 };
57
58
59 SkMiniRecorder::SkMiniRecorder() : fState(State::kEmpty) {}
60 SkMiniRecorder::~SkMiniRecorder() {
61 if (fState != State::kEmpty) {
62 // We have internal state pending.
63 // Detaching then deleting a picture is an easy way to clean up.
64 SkDELETE(this->detachAsPicture(SkRect::MakeEmpty()));
65 }
66 SkASSERT(fState == State::kEmpty);
67 }
68
69 #define TRY_TO_STORE(Type, ...) \
70 if (fState != State::kEmpty) { return false; } \
71 fState = State::k##Type; \
72 new (fBuffer.get()) Type(__VA_ARGS__); \
73 return true
74
75 bool SkMiniRecorder::drawRect(const SkRect& rect, const SkPaint& paint) {
76 TRY_TO_STORE(DrawRect, paint, rect);
77 }
78
79 bool SkMiniRecorder::drawPath(const SkPath& path, const SkPaint& paint) {
80 TRY_TO_STORE(DrawPath, paint, path);
81 }
82
83 bool SkMiniRecorder::drawTextBlob(const SkTextBlob* b, SkScalar x, SkScalar y, c onst SkPaint& p) {
84 TRY_TO_STORE(DrawTextBlob, p, b, x, y);
85 }
86 #undef TRY_TO_STORE
87
88 #define CASE(Type) \
89 case State::k##Type: \
90 fState = State::kEmpty; \
91 return SkNEW_ARGS(SkMiniPicture<Type>, (cull, reinterpret_cast<Type*>(fB uffer.get())))
92
93 SkPicture* SkMiniRecorder::detachAsPicture(const SkRect& cull) {
94 switch (fState) {
95 case State::kEmpty: return SkRef(gEmptyPicture.get());
96 CASE(DrawPath);
97 CASE(DrawRect);
98 CASE(DrawTextBlob);
99 }
100 SkASSERT(false);
101 return NULL;
102 }
103 #undef CASE
OLDNEW
« no previous file with comments | « src/core/SkMiniRecorder.h ('k') | src/core/SkPicture.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698