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 SkPictureReplacementPlayback_DEFINED |
| 9 #define SkPictureReplacementPlayback_DEFINED |
| 10 |
| 11 #include "SkPicturePlayback.h" |
| 12 |
| 13 // This playback class replaces complete "saveLayer ... restore" runs with a |
| 14 // single drawBitmap call. |
| 15 class SkPictureReplacementPlayback : public SkPicturePlayback { |
| 16 public: |
| 17 // PlaybackReplacements collects op ranges that can be replaced with |
| 18 // a single drawBitmap call (using a precomputed bitmap). |
| 19 class PlaybackReplacements { |
| 20 public: |
| 21 // All the operations between fStart and fStop (inclusive) will be repla
ced with |
| 22 // a single drawBitmap call using fPos, fBM and fPaint. |
| 23 // fPaint will be NULL if the picture's paint wasn't copyable |
| 24 struct ReplacementInfo { |
| 25 size_t fStart; |
| 26 size_t fStop; |
| 27 SkIPoint fPos; |
| 28 SkBitmap* fBM; // fBM is allocated so ReplacementInfo can
remain POD |
| 29 const SkPaint* fPaint; // Note: this object doesn't own the paint |
| 30 |
| 31 SkIRect fSrcRect; |
| 32 }; |
| 33 |
| 34 ~PlaybackReplacements() { this->freeAll(); } |
| 35 |
| 36 // Add a new replacement range. The replacement ranges should be |
| 37 // sorted in increasing order and non-overlapping (esp. no nested |
| 38 // saveLayers). |
| 39 ReplacementInfo* push(); |
| 40 |
| 41 // look up a replacement range by its start offset |
| 42 ReplacementInfo* lookupByStart(size_t start); |
| 43 |
| 44 private: |
| 45 SkTDArray<ReplacementInfo> fReplacements; |
| 46 |
| 47 void freeAll(); |
| 48 |
| 49 #ifdef SK_DEBUG |
| 50 void validate() const; |
| 51 #endif |
| 52 }; |
| 53 |
| 54 // This class doesn't take ownership of either 'replacements' or 'activeOpsL
ist' |
| 55 // The caller must guarantee they exist across any calls to 'draw'. |
| 56 // 'activeOpsList' can be NULL but in that case BBH acceleration will not |
| 57 // be used ('replacements' can be NULL too but that defeats the purpose |
| 58 // of using this class). |
| 59 SkPictureReplacementPlayback(const SkPicture* picture, |
| 60 PlaybackReplacements* replacements, |
| 61 const SkPicture::OperationList* activeOpsList) |
| 62 : INHERITED(picture) |
| 63 , fReplacements(replacements) |
| 64 , fActiveOpsList(activeOpsList) { |
| 65 } |
| 66 |
| 67 virtual void draw(SkCanvas* canvas, SkDrawPictureCallback*) SK_OVERRIDE; |
| 68 |
| 69 private: |
| 70 PlaybackReplacements* fReplacements; |
| 71 const SkPicture::OperationList* fActiveOpsList; |
| 72 |
| 73 // This method checks if the current op pointed at by 'iter' and 'reader' |
| 74 // is within a replacement range. If so, it issues the drawBitmap call, |
| 75 // updates 'iter' and 'reader' to be after the restore operation, and |
| 76 // returns true. If the operation is not in a replacement range (and thus |
| 77 // needs to be drawn normally) false is returned. |
| 78 bool replaceOps(SkPictureStateTree::Iterator* iter, |
| 79 SkReader32* reader, |
| 80 SkCanvas* canvas, |
| 81 const SkMatrix& initialMatrix); |
| 82 |
| 83 typedef SkPicturePlayback INHERITED; |
| 84 }; |
| 85 |
| 86 #endif |
OLD | NEW |