• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "src/core/SkPictureFlat.h"
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 SkM44& initialMatrix);
45 
46     class AutoResetOpID {
47     public:
AutoResetOpID(SkPicturePlayback * playback)48         AutoResetOpID(SkPicturePlayback* playback) : fPlayback(playback) { }
~AutoResetOpID()49         ~AutoResetOpID() {
50             if (fPlayback) {
51                 fPlayback->resetOpID();
52             }
53         }
54 
55     private:
56         SkPicturePlayback* fPlayback;
57     };
58 
59 private:
60     using INHERITED = SkNoncopyable;
61 };
62 
63 #endif
64