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