OLD | NEW |
---|---|
(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 { | |
mtklein
2014/07/07 19:32:08
: SkNoncopyable ?
robertphillips
2014/07/07 19:55:54
Done.
| |
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 | |
30 void draw(SkCanvas* canvas, SkDrawPictureCallback*); | |
31 | |
32 // Return the ID of the operation currently being executed when playing | |
33 // back. 0 indicates no call is active. | |
34 size_t curOpID() const { return fCurOffset; } | |
35 void resetOpID() { fCurOffset = 0; } | |
36 | |
37 void setUseBBH(bool useBBH) { fUseBBH = useBBH; } | |
38 | |
39 // Limit the opcode playback to be between the offsets 'start' and 'stop'. | |
40 // The opcode at 'start' should be a saveLayer while the opcode at | |
41 // 'stop' should be a restore. Neither of those commands will be issued. | |
42 // Set both start & stop to 0 to disable draw limiting | |
43 // Draw limiting cannot be enabled at the same time as draw replacing | |
44 void setDrawLimits(size_t start, size_t stop) { | |
45 SkASSERT(NULL == fReplacements); | |
46 fStart = start; | |
47 fStop = stop; | |
48 } | |
49 | |
50 // PlaybackReplacements collects op ranges that can be replaced with | |
51 // a single drawBitmap call (using a precomputed bitmap). | |
52 class PlaybackReplacements { | |
53 public: | |
54 // All the operations between fStart and fStop (inclusive) will be repla ced with | |
55 // a single drawBitmap call using fPos, fBM and fPaint. | |
56 // fPaint will be NULL if the picture's paint wasn't copyable | |
57 struct ReplacementInfo { | |
58 size_t fStart; | |
59 size_t fStop; | |
60 SkIPoint fPos; | |
61 SkBitmap* fBM; // fBM is allocated so ReplacementInfo can remain POD | |
62 const SkPaint* fPaint; // Note: this object doesn't own the paint | |
63 | |
64 SkIRect fSrcRect; | |
65 }; | |
66 | |
67 ~PlaybackReplacements() { this->freeAll(); } | |
68 | |
69 // Add a new replacement range. The replacement ranges should be | |
70 // sorted in increasing order and non-overlapping (esp. no nested | |
71 // saveLayers). | |
72 ReplacementInfo* push(); | |
73 | |
74 private: | |
75 friend class SkPicturePlayback; // for access to lookupByStart | |
76 | |
77 // look up a replacement range by its start offset | |
78 ReplacementInfo* lookupByStart(size_t start); | |
79 | |
80 void freeAll(); | |
81 | |
82 #ifdef SK_DEBUG | |
83 void validate() const; | |
84 #endif | |
85 | |
86 SkTDArray<ReplacementInfo> fReplacements; | |
87 }; | |
88 | |
89 // Replace all the draw ops in the replacement ranges in 'replacements' with | |
90 // the associated drawBitmap call | |
91 // Draw replacing cannot be enabled at the same time as draw limiting | |
92 void setReplacements(PlaybackReplacements* replacements) { | |
93 SkASSERT(fStart == 0 && fStop == 0); | |
94 fReplacements = replacements; | |
95 } | |
96 | |
97 protected: | |
98 const SkPictureData* fPictureData; | |
99 | |
100 // The offset of the current operation when within the draw method | |
101 size_t fCurOffset; | |
102 | |
103 bool fUseBBH; | |
104 size_t fStart; | |
105 size_t fStop; | |
106 PlaybackReplacements* fReplacements; | |
107 | |
108 #ifdef SK_DEVELOPER | |
109 virtual bool preDraw(int opIndex, int type) { return false; } | |
110 virtual void postDraw(int opIndex) { } | |
111 #endif | |
112 | |
113 }; | |
114 | |
115 #endif | |
OLD | NEW |