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

Side by Side Diff: src/core/SkPicturePlayback.h

Issue 377623002: Split SkPicturePlayback out of SkPictureData (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Add virtual dtor for SkPicturePlayback Created 6 years, 5 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/SkPictureData.cpp ('k') | src/core/SkPicturePlayback.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 2014 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 #ifndef SkPicturePlayback_DEFINED
9 #define SkPicturePlayback_DEFINED
10
11 #include "SkTypes.h"
12
13 class SkBitmap;
14 class SkCanvas;
15 class SkDrawPictureCallback;
16 class SkPaint;
17 class SkPictureData;
18
19 class SkPicturePlayback : SkNoncopyable {
20 public:
21 SkPicturePlayback(const SkPicture* picture)
22 : fPictureData(picture->fData.get())
23 , fCurOffset(0)
24 , fUseBBH(true)
25 , fStart(0)
26 , fStop(0)
27 , fReplacements(NULL) {
28 }
29 virtual ~SkPicturePlayback() { }
30
31 void draw(SkCanvas* canvas, SkDrawPictureCallback*);
32
33 // Return the ID of the operation currently being executed when playing
34 // back. 0 indicates no call is active.
35 size_t curOpID() const { return fCurOffset; }
36 void resetOpID() { fCurOffset = 0; }
37
38 void setUseBBH(bool useBBH) { fUseBBH = useBBH; }
39
40 // Limit the opcode playback to be between the offsets 'start' and 'stop'.
41 // The opcode at 'start' should be a saveLayer while the opcode at
42 // 'stop' should be a restore. Neither of those commands will be issued.
43 // Set both start & stop to 0 to disable draw limiting
44 // Draw limiting cannot be enabled at the same time as draw replacing
45 void setDrawLimits(size_t start, size_t stop) {
46 SkASSERT(NULL == fReplacements);
47 fStart = start;
48 fStop = stop;
49 }
50
51 // PlaybackReplacements collects op ranges that can be replaced with
52 // a single drawBitmap call (using a precomputed bitmap).
53 class PlaybackReplacements {
54 public:
55 // All the operations between fStart and fStop (inclusive) will be repla ced with
56 // a single drawBitmap call using fPos, fBM and fPaint.
57 // fPaint will be NULL if the picture's paint wasn't copyable
58 struct ReplacementInfo {
59 size_t fStart;
60 size_t fStop;
61 SkIPoint fPos;
62 SkBitmap* fBM; // fBM is allocated so ReplacementInfo can remain POD
63 const SkPaint* fPaint; // Note: this object doesn't own the paint
64
65 SkIRect fSrcRect;
66 };
67
68 ~PlaybackReplacements() { this->freeAll(); }
69
70 // Add a new replacement range. The replacement ranges should be
71 // sorted in increasing order and non-overlapping (esp. no nested
72 // saveLayers).
73 ReplacementInfo* push();
74
75 private:
76 friend class SkPicturePlayback; // for access to lookupByStart
77
78 // look up a replacement range by its start offset
79 ReplacementInfo* lookupByStart(size_t start);
80
81 void freeAll();
82
83 #ifdef SK_DEBUG
84 void validate() const;
85 #endif
86
87 SkTDArray<ReplacementInfo> fReplacements;
88 };
89
90 // Replace all the draw ops in the replacement ranges in 'replacements' with
91 // the associated drawBitmap call
92 // Draw replacing cannot be enabled at the same time as draw limiting
93 void setReplacements(PlaybackReplacements* replacements) {
94 SkASSERT(fStart == 0 && fStop == 0);
95 fReplacements = replacements;
96 }
97
98 protected:
99 const SkPictureData* fPictureData;
100
101 // The offset of the current operation when within the draw method
102 size_t fCurOffset;
103
104 bool fUseBBH;
105 size_t fStart;
106 size_t fStop;
107 PlaybackReplacements* fReplacements;
108
109 #ifdef SK_DEVELOPER
110 virtual bool preDraw(int opIndex, int type) { return false; }
111 virtual void postDraw(int opIndex) { }
112 #endif
113
114 private:
115 typedef SkNoncopyable INHERITED;
116 };
117
118 #endif
OLDNEW
« no previous file with comments | « src/core/SkPictureData.cpp ('k') | src/core/SkPicturePlayback.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698