| 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 "SkTypes.h" | 11 #include "SkPictureFlat.h" // for DrawType |
| 12 | 12 |
| 13 class SkBitmap; | 13 class SkBitmap; |
| 14 class SkCanvas; | 14 class SkCanvas; |
| 15 class SkDrawPictureCallback; | 15 class SkDrawPictureCallback; |
| 16 class SkPaint; | 16 class SkPaint; |
| 17 class SkPictureData; | 17 class SkPictureData; |
| 18 | 18 |
| 19 class SkPicturePlayback : SkNoncopyable { | 19 class SkPicturePlayback : SkNoncopyable { |
| 20 public: | 20 public: |
| 21 SkPicturePlayback(const SkPicture* picture) | 21 SkPicturePlayback(const SkPicture* picture) |
| 22 : fPictureData(picture->fData.get()) | 22 : fPictureData(picture->fData.get()) |
| 23 , fCurOffset(0) | 23 , fCurOffset(0) |
| 24 , fUseBBH(true) | 24 , fUseBBH(true) |
| 25 , fStart(0) | |
| 26 , fStop(0) | |
| 27 , fReplacements(NULL) { | 25 , fReplacements(NULL) { |
| 28 } | 26 } |
| 29 virtual ~SkPicturePlayback() { } | 27 virtual ~SkPicturePlayback() { } |
| 30 | 28 |
| 31 void draw(SkCanvas* canvas, SkDrawPictureCallback*); | 29 virtual void draw(SkCanvas* canvas, SkDrawPictureCallback*); |
| 32 | 30 |
| 33 // Return the ID of the operation currently being executed when playing | 31 // Return the ID of the operation currently being executed when playing |
| 34 // back. 0 indicates no call is active. | 32 // back. 0 indicates no call is active. |
| 35 size_t curOpID() const { return fCurOffset; } | 33 size_t curOpID() const { return fCurOffset; } |
| 36 void resetOpID() { fCurOffset = 0; } | 34 void resetOpID() { fCurOffset = 0; } |
| 37 | 35 |
| 38 void setUseBBH(bool useBBH) { fUseBBH = useBBH; } | 36 void setUseBBH(bool useBBH) { fUseBBH = useBBH; } |
| 39 | 37 |
| 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 | 38 // PlaybackReplacements collects op ranges that can be replaced with |
| 52 // a single drawBitmap call (using a precomputed bitmap). | 39 // a single drawBitmap call (using a precomputed bitmap). |
| 53 class PlaybackReplacements { | 40 class PlaybackReplacements { |
| 54 public: | 41 public: |
| 55 // All the operations between fStart and fStop (inclusive) will be repla
ced with | 42 // All the operations between fStart and fStop (inclusive) will be repla
ced with |
| 56 // a single drawBitmap call using fPos, fBM and fPaint. | 43 // a single drawBitmap call using fPos, fBM and fPaint. |
| 57 // fPaint will be NULL if the picture's paint wasn't copyable | 44 // fPaint will be NULL if the picture's paint wasn't copyable |
| 58 struct ReplacementInfo { | 45 struct ReplacementInfo { |
| 59 size_t fStart; | 46 size_t fStart; |
| 60 size_t fStop; | 47 size_t fStop; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 84 void validate() const; | 71 void validate() const; |
| 85 #endif | 72 #endif |
| 86 | 73 |
| 87 SkTDArray<ReplacementInfo> fReplacements; | 74 SkTDArray<ReplacementInfo> fReplacements; |
| 88 }; | 75 }; |
| 89 | 76 |
| 90 // Replace all the draw ops in the replacement ranges in 'replacements' with | 77 // Replace all the draw ops in the replacement ranges in 'replacements' with |
| 91 // the associated drawBitmap call | 78 // the associated drawBitmap call |
| 92 // Draw replacing cannot be enabled at the same time as draw limiting | 79 // Draw replacing cannot be enabled at the same time as draw limiting |
| 93 void setReplacements(PlaybackReplacements* replacements) { | 80 void setReplacements(PlaybackReplacements* replacements) { |
| 94 SkASSERT(fStart == 0 && fStop == 0); | |
| 95 fReplacements = replacements; | 81 fReplacements = replacements; |
| 96 } | 82 } |
| 97 | 83 |
| 98 protected: | 84 protected: |
| 99 const SkPictureData* fPictureData; | 85 const SkPictureData* fPictureData; |
| 100 | 86 |
| 101 // The offset of the current operation when within the draw method | 87 // The offset of the current operation when within the draw method |
| 102 size_t fCurOffset; | 88 size_t fCurOffset; |
| 103 | 89 |
| 104 bool fUseBBH; | 90 bool fUseBBH; |
| 105 size_t fStart; | |
| 106 size_t fStop; | |
| 107 PlaybackReplacements* fReplacements; | 91 PlaybackReplacements* fReplacements; |
| 108 | 92 |
| 109 void handleOp(SkReader32* reader, | 93 void handleOp(SkReader32* reader, |
| 110 DrawType op, | 94 DrawType op, |
| 111 uint32_t size, | 95 uint32_t size, |
| 112 SkCanvas* canvas, | 96 SkCanvas* canvas, |
| 113 const SkMatrix& initialMatrix); | 97 const SkMatrix& initialMatrix); |
| 114 | 98 |
| 115 #ifdef SK_DEVELOPER | 99 #ifdef SK_DEVELOPER |
| 116 virtual bool preDraw(int opIndex, int type) { return false; } | 100 virtual bool preDraw(int opIndex, int type) { return false; } |
| 117 virtual void postDraw(int opIndex) { } | 101 virtual void postDraw(int opIndex) { } |
| 118 #endif | 102 #endif |
| 119 | 103 |
| 104 static DrawType ReadOpAndSize(SkReader32* reader, uint32_t* size); |
| 105 |
| 106 class AutoResetOpID { |
| 107 public: |
| 108 AutoResetOpID(SkPicturePlayback* playback) : fPlayback(playback) { } |
| 109 ~AutoResetOpID() { |
| 110 if (NULL != fPlayback) { |
| 111 fPlayback->resetOpID(); |
| 112 } |
| 113 } |
| 114 |
| 115 private: |
| 116 SkPicturePlayback* fPlayback; |
| 117 }; |
| 118 |
| 120 private: | 119 private: |
| 121 typedef SkNoncopyable INHERITED; | 120 typedef SkNoncopyable INHERITED; |
| 122 }; | 121 }; |
| 123 | 122 |
| 124 #endif | 123 #endif |
| OLD | NEW |