Line data Source code
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:
21 0 : SkPicturePlayback(const SkPictureData* data)
22 0 : : fPictureData(data)
23 0 : , fCurOffset(0) {
24 0 : }
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.
31 : size_t curOpID() const { return fCurOffset; }
32 0 : 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:
50 0 : AutoResetOpID(SkPicturePlayback* playback) : fPlayback(playback) { }
51 0 : ~AutoResetOpID() {
52 0 : if (fPlayback) {
53 0 : fPlayback->resetOpID();
54 : }
55 0 : }
56 :
57 : private:
58 : SkPicturePlayback* fPlayback;
59 : };
60 :
61 : private:
62 : typedef SkNoncopyable INHERITED;
63 : };
64 :
65 : #endif
|