2 * Copyright 2014 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #ifndef SkPictureReplacementPlayback_DEFINED
9 #define SkPictureReplacementPlayback_DEFINED
11 #include "SkPicturePlayback.h"
13 // This playback class replaces complete "saveLayer ... restore" runs with a
14 // single drawBitmap call.
15 class SkPictureReplacementPlayback : public SkPicturePlayback {
17 // PlaybackReplacements collects op ranges that can be replaced with
18 // a single drawBitmap call (using a precomputed bitmap).
19 class PlaybackReplacements {
21 // All the operations between fStart and fStop (inclusive) will be replaced 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 {
28 SkBitmap* fBM; // fBM is allocated so ReplacementInfo can remain POD
29 const SkPaint* fPaint; // Note: this object doesn't own the paint
34 ~PlaybackReplacements() { this->freeAll(); }
36 // Add a new replacement range. The replacement ranges should be
37 // sorted in increasing order and non-overlapping (esp. no nested
39 ReplacementInfo* push();
41 // look up a replacement range by its start offset
42 ReplacementInfo* lookupByStart(size_t start);
45 SkTDArray<ReplacementInfo> fReplacements;
50 void validate() const;
54 // This class doesn't take ownership of either 'replacements' or 'activeOpsList'
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)
63 , fReplacements(replacements)
64 , fActiveOpsList(activeOpsList) {
67 virtual void draw(SkCanvas* canvas, SkDrawPictureCallback*) SK_OVERRIDE;
70 PlaybackReplacements* fReplacements;
71 const SkPicture::OperationList* fActiveOpsList;
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,
81 const SkMatrix& initialMatrix);
83 typedef SkPicturePlayback INHERITED;