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 SkPicturePlayback_DEFINED
9 #define SkPicturePlayback_DEFINED
10 
11 #include "SkPictureFlat.h"  // for DrawType
12 
13 class SkBitmap;
14 class SkCanvas;
15 class SkPaint;
16 class SkPictureData;
17 
18 // The basic picture playback class replays the provided picture into a canvas.
19 class SkPicturePlayback final : SkNoncopyable {
20 public:
SkPicturePlayback(const SkPictureData * data)21     SkPicturePlayback(const SkPictureData* data)
22         : fPictureData(data)
23         , fCurOffset(0) {
24     }
25 
26     void draw(SkCanvas* canvas, SkPicture::AbortCallback*, SkReadBuffer* buffer);
27 
28     // TODO: remove the curOp calls after cleaning up GrGatherDevice
29     // Return the ID of the operation currently being executed when playing
30     // back. 0 indicates no call is active.
curOpID()31     size_t curOpID() const { return fCurOffset; }
resetOpID()32     void resetOpID() { fCurOffset = 0; }
33 
34 protected:
35     const SkPictureData* fPictureData;
36 
37     // The offset of the current operation when within the draw method
38     size_t fCurOffset;
39 
40     void handleOp(SkReadBuffer* reader,
41                   DrawType op,
42                   uint32_t size,
43                   SkCanvas* canvas,
44                   const SkMatrix& initialMatrix);
45 
46     static DrawType ReadOpAndSize(SkReadBuffer* reader, uint32_t* size);
47 
48     class AutoResetOpID {
49     public:
AutoResetOpID(SkPicturePlayback * playback)50         AutoResetOpID(SkPicturePlayback* playback) : fPlayback(playback) { }
~AutoResetOpID()51         ~AutoResetOpID() {
52             if (fPlayback) {
53                 fPlayback->resetOpID();
54             }
55         }
56 
57     private:
58         SkPicturePlayback* fPlayback;
59     };
60 
61 private:
62     typedef SkNoncopyable INHERITED;
63 };
64 
65 #endif
66