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