OLD | NEW |
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" | |
13 | 12 |
14 class SkBitmap; | 13 class SkBitmap; |
15 class SkCanvas; | 14 class SkCanvas; |
16 class SkDrawPictureCallback; | 15 class SkDrawPictureCallback; |
17 class SkPaint; | 16 class SkPaint; |
18 class SkPictureData; | 17 class SkPictureData; |
19 | 18 |
20 // The basic picture playback class replays the provided picture into a canvas. | 19 // 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. | |
23 class SkPicturePlayback : SkNoncopyable { | 20 class SkPicturePlayback : SkNoncopyable { |
24 public: | 21 public: |
25 SkPicturePlayback(const SkPicture* picture) | 22 SkPicturePlayback(const SkPicture* picture) |
26 : fPictureData(picture->fData.get()) | 23 : fPictureData(picture->fData.get()) |
27 , fCurOffset(0) | 24 , fCurOffset(0) { |
28 , fUseBBH(true) { | |
29 } | 25 } |
30 virtual ~SkPicturePlayback() { } | 26 virtual ~SkPicturePlayback() { } |
31 | 27 |
32 virtual void draw(SkCanvas* canvas, SkDrawPictureCallback*); | 28 virtual void draw(SkCanvas* canvas, SkDrawPictureCallback*); |
33 | 29 |
34 // TODO: remove the curOp calls after cleaning up GrGatherDevice | 30 // TODO: remove the curOp calls after cleaning up GrGatherDevice |
35 // Return the ID of the operation currently being executed when playing | 31 // Return the ID of the operation currently being executed when playing |
36 // back. 0 indicates no call is active. | 32 // back. 0 indicates no call is active. |
37 size_t curOpID() const { return fCurOffset; } | 33 size_t curOpID() const { return fCurOffset; } |
38 void resetOpID() { fCurOffset = 0; } | 34 void resetOpID() { fCurOffset = 0; } |
39 | 35 |
40 // TODO: remove setUseBBH after cleaning up GrGatherCanvas | |
41 void setUseBBH(bool useBBH) { fUseBBH = useBBH; } | |
42 | |
43 protected: | 36 protected: |
44 const SkPictureData* fPictureData; | 37 const SkPictureData* fPictureData; |
45 | 38 |
46 // The offset of the current operation when within the draw method | 39 // The offset of the current operation when within the draw method |
47 size_t fCurOffset; | 40 size_t fCurOffset; |
48 | 41 |
49 bool fUseBBH; | 42 void handleOp(SkReader32* reader, |
50 | 43 DrawType op, |
51 void handleOp(SkReader32* reader, | 44 uint32_t size, |
52 DrawType op, | |
53 uint32_t size, | |
54 SkCanvas* canvas, | 45 SkCanvas* canvas, |
55 const SkMatrix& initialMatrix); | 46 const SkMatrix& initialMatrix); |
56 | 47 |
57 const SkPicture::OperationList* getActiveOps(const SkCanvas* canvas); | |
58 bool initIterator(SkPictureStateTree::Iterator* iter, | |
59 SkCanvas* canvas, | |
60 const SkPicture::OperationList *activeOpsList); | |
61 static void StepIterator(SkPictureStateTree::Iterator* iter, SkReader32* rea
der); | |
62 static void SkipIterTo(SkPictureStateTree::Iterator* iter, | |
63 SkReader32* reader, uint32_t skipTo); | |
64 | |
65 static DrawType ReadOpAndSize(SkReader32* reader, uint32_t* size); | 48 static DrawType ReadOpAndSize(SkReader32* reader, uint32_t* size); |
66 | 49 |
67 class AutoResetOpID { | 50 class AutoResetOpID { |
68 public: | 51 public: |
69 AutoResetOpID(SkPicturePlayback* playback) : fPlayback(playback) { } | 52 AutoResetOpID(SkPicturePlayback* playback) : fPlayback(playback) { } |
70 ~AutoResetOpID() { | 53 ~AutoResetOpID() { |
71 if (fPlayback) { | 54 if (fPlayback) { |
72 fPlayback->resetOpID(); | 55 fPlayback->resetOpID(); |
73 } | 56 } |
74 } | 57 } |
75 | 58 |
76 private: | 59 private: |
77 SkPicturePlayback* fPlayback; | 60 SkPicturePlayback* fPlayback; |
78 }; | 61 }; |
79 | 62 |
80 private: | 63 private: |
81 typedef SkNoncopyable INHERITED; | 64 typedef SkNoncopyable INHERITED; |
82 }; | 65 }; |
83 | 66 |
84 #endif | 67 #endif |
OLD | NEW |