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

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

Issue 383733002: Split SkPictureReplacementPlayback out of SkPicturePlayback (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Added comment 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 | « include/core/SkPicture.h ('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
1 /* 1 /*
2 * Copyright 2014 Google Inc. 2 * Copyright 2014 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 #ifndef SkPicturePlayback_DEFINED 8 #ifndef SkPicturePlayback_DEFINED
9 #define SkPicturePlayback_DEFINED 9 #define SkPicturePlayback_DEFINED
10 10
11 #include "SkPictureFlat.h" // for DrawType 11 #include "SkPictureFlat.h" // for DrawType
12 #include "SkPictureStateTree.h" 12 #include "SkPictureStateTree.h"
13 13
14 class SkBitmap; 14 class SkBitmap;
15 class SkCanvas; 15 class SkCanvas;
16 class SkDrawPictureCallback; 16 class SkDrawPictureCallback;
17 class SkPaint; 17 class SkPaint;
18 class SkPictureData; 18 class SkPictureData;
19 19
20 // The basic picture playback class replays the provided picture into a canvas.
21 // If the picture was generated with a BBH it is used to accelerate drawing
22 // unless disabled via setUseBBH.
20 class SkPicturePlayback : SkNoncopyable { 23 class SkPicturePlayback : SkNoncopyable {
21 public: 24 public:
22 SkPicturePlayback(const SkPicture* picture) 25 SkPicturePlayback(const SkPicture* picture)
23 : fPictureData(picture->fData.get()) 26 : fPictureData(picture->fData.get())
24 , fCurOffset(0) 27 , fCurOffset(0)
25 , fUseBBH(true) 28 , fUseBBH(true) {
26 , fReplacements(NULL) {
27 } 29 }
28 virtual ~SkPicturePlayback() { } 30 virtual ~SkPicturePlayback() { }
29 31
30 virtual void draw(SkCanvas* canvas, SkDrawPictureCallback*); 32 virtual void draw(SkCanvas* canvas, SkDrawPictureCallback*);
31 33
34 // TODO: remove the curOp calls after cleaning up GrGatherDevice
32 // Return the ID of the operation currently being executed when playing 35 // Return the ID of the operation currently being executed when playing
33 // back. 0 indicates no call is active. 36 // back. 0 indicates no call is active.
34 size_t curOpID() const { return fCurOffset; } 37 size_t curOpID() const { return fCurOffset; }
35 void resetOpID() { fCurOffset = 0; } 38 void resetOpID() { fCurOffset = 0; }
36 39
40 // TODO: remove setUseBBH after cleaning up GrGatherCanvas
37 void setUseBBH(bool useBBH) { fUseBBH = useBBH; } 41 void setUseBBH(bool useBBH) { fUseBBH = useBBH; }
38 42
39 // PlaybackReplacements collects op ranges that can be replaced with
40 // a single drawBitmap call (using a precomputed bitmap).
41 class PlaybackReplacements {
42 public:
43 // All the operations between fStart and fStop (inclusive) will be repla ced with
44 // a single drawBitmap call using fPos, fBM and fPaint.
45 // fPaint will be NULL if the picture's paint wasn't copyable
46 struct ReplacementInfo {
47 size_t fStart;
48 size_t fStop;
49 SkIPoint fPos;
50 SkBitmap* fBM; // fBM is allocated so ReplacementInfo can remain POD
51 const SkPaint* fPaint; // Note: this object doesn't own the paint
52
53 SkIRect fSrcRect;
54 };
55
56 ~PlaybackReplacements() { this->freeAll(); }
57
58 // Add a new replacement range. The replacement ranges should be
59 // sorted in increasing order and non-overlapping (esp. no nested
60 // saveLayers).
61 ReplacementInfo* push();
62
63 private:
64 friend class SkPicturePlayback; // for access to lookupByStart
65
66 // look up a replacement range by its start offset
67 ReplacementInfo* lookupByStart(size_t start);
68
69 void freeAll();
70
71 #ifdef SK_DEBUG
72 void validate() const;
73 #endif
74
75 SkTDArray<ReplacementInfo> fReplacements;
76 };
77
78 // Replace all the draw ops in the replacement ranges in 'replacements' with
79 // the associated drawBitmap call
80 // Draw replacing cannot be enabled at the same time as draw limiting
81 void setReplacements(PlaybackReplacements* replacements) {
82 fReplacements = replacements;
83 }
84
85 protected: 43 protected:
86 const SkPictureData* fPictureData; 44 const SkPictureData* fPictureData;
87 45
88 // The offset of the current operation when within the draw method 46 // The offset of the current operation when within the draw method
89 size_t fCurOffset; 47 size_t fCurOffset;
90 48
91 bool fUseBBH; 49 bool fUseBBH;
92 PlaybackReplacements* fReplacements;
93 50
94 void handleOp(SkReader32* reader, 51 void handleOp(SkReader32* reader,
95 DrawType op, 52 DrawType op,
96 uint32_t size, 53 uint32_t size,
97 SkCanvas* canvas, 54 SkCanvas* canvas,
98 const SkMatrix& initialMatrix); 55 const SkMatrix& initialMatrix);
99 56
100 const SkPicture::OperationList* getActiveOps(const SkCanvas* canvas); 57 const SkPicture::OperationList* getActiveOps(const SkCanvas* canvas);
101 bool initIterator(SkPictureStateTree::Iterator* iter, 58 bool initIterator(SkPictureStateTree::Iterator* iter,
102 SkCanvas* canvas, 59 SkCanvas* canvas,
103 const SkPicture::OperationList *activeOpsList); 60 const SkPicture::OperationList *activeOpsList);
104 static void StepIterator(SkPictureStateTree::Iterator* iter, SkReader32* rea der); 61 static void StepIterator(SkPictureStateTree::Iterator* iter, SkReader32* rea der);
105 static void SkipIterTo(SkPictureStateTree::Iterator* iter, 62 static void SkipIterTo(SkPictureStateTree::Iterator* iter,
106 SkReader32* reader, uint32_t skipTo); 63 SkReader32* reader, uint32_t skipTo);
107 bool replaceOps(SkPictureStateTree::Iterator* iter,
108 SkReader32* reader,
109 SkCanvas* canvas,
110 const SkMatrix& initialMatrix);
111 64
112 static DrawType ReadOpAndSize(SkReader32* reader, uint32_t* size); 65 static DrawType ReadOpAndSize(SkReader32* reader, uint32_t* size);
113 66
114 class AutoResetOpID { 67 class AutoResetOpID {
115 public: 68 public:
116 AutoResetOpID(SkPicturePlayback* playback) : fPlayback(playback) { } 69 AutoResetOpID(SkPicturePlayback* playback) : fPlayback(playback) { }
117 ~AutoResetOpID() { 70 ~AutoResetOpID() {
118 if (NULL != fPlayback) { 71 if (NULL != fPlayback) {
119 fPlayback->resetOpID(); 72 fPlayback->resetOpID();
120 } 73 }
121 } 74 }
122 75
123 private: 76 private:
124 SkPicturePlayback* fPlayback; 77 SkPicturePlayback* fPlayback;
125 }; 78 };
126 79
127 private: 80 private:
128 typedef SkNoncopyable INHERITED; 81 typedef SkNoncopyable INHERITED;
129 }; 82 };
130 83
131 #endif 84 #endif
OLDNEW
« no previous file with comments | « include/core/SkPicture.h ('k') | src/core/SkPicturePlayback.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698