Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / third_party / skia / src / record / SkRecorder.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 SkRecorder_DEFINED
9 #define SkRecorder_DEFINED
10
11 #include "SkCanvas.h"
12 #include "SkRecord.h"
13 #include "SkRecords.h"
14
15 // SkRecorder provides an SkCanvas interface for recording into an SkRecord.
16
17 class SkRecorder : public SkCanvas {
18 public:
19     // SkRecorder can work in two modes:
20     //   write-only: only a core subset of SkCanvas operations (save/restore, clip, transform, draw)
21     //   are supported, and all of the readback methods on SkCanvas will probably fail or lie.
22     //
23     //   read-write: all methods should behave with similar semantics to SkCanvas.
24     //
25     // Write-only averages 10-20% faster, but you can't sensibly inspect the canvas while recording.
26     enum Mode { kWriteOnly_Mode, kReadWrite_Mode };
27
28     // Does not take ownership of the SkRecord.
29     SkRecorder(Mode mode, SkRecord*, int width, int height);
30
31     // Make SkRecorder forget entirely about its SkRecord*; all calls to SkRecorder will fail.
32     void forgetRecord();
33
34     void clear(SkColor) SK_OVERRIDE;
35     void drawPaint(const SkPaint& paint) SK_OVERRIDE;
36     void drawPoints(PointMode mode,
37                     size_t count,
38                     const SkPoint pts[],
39                     const SkPaint& paint) SK_OVERRIDE;
40     void drawRect(const SkRect& rect, const SkPaint& paint) SK_OVERRIDE;
41     void drawOval(const SkRect& oval, const SkPaint&) SK_OVERRIDE;
42     void drawRRect(const SkRRect& rrect, const SkPaint& paint) SK_OVERRIDE;
43     void drawPath(const SkPath& path, const SkPaint& paint) SK_OVERRIDE;
44     void drawBitmap(const SkBitmap& bitmap,
45                     SkScalar left,
46                     SkScalar top,
47                     const SkPaint* paint = NULL) SK_OVERRIDE;
48     void drawBitmapRectToRect(const SkBitmap& bitmap,
49                               const SkRect* src,
50                               const SkRect& dst,
51                               const SkPaint* paint = NULL,
52                               DrawBitmapRectFlags flags = kNone_DrawBitmapRectFlag) SK_OVERRIDE;
53     void drawBitmapMatrix(const SkBitmap& bitmap,
54                           const SkMatrix& m,
55                           const SkPaint* paint = NULL) SK_OVERRIDE;
56     void drawBitmapNine(const SkBitmap& bitmap,
57                         const SkIRect& center,
58                         const SkRect& dst,
59                         const SkPaint* paint = NULL) SK_OVERRIDE;
60     void drawSprite(const SkBitmap& bitmap,
61                     int left,
62                     int top,
63                     const SkPaint* paint = NULL) SK_OVERRIDE;
64     void drawPicture(SkPicture& picture) SK_OVERRIDE;
65     void drawVertices(VertexMode vmode,
66                       int vertexCount,
67                       const SkPoint vertices[],
68                       const SkPoint texs[],
69                       const SkColor colors[],
70                       SkXfermode* xmode,
71                       const uint16_t indices[],
72                       int indexCount,
73                       const SkPaint& paint) SK_OVERRIDE;
74
75     void willSave(SkCanvas::SaveFlags) SK_OVERRIDE;
76     SaveLayerStrategy willSaveLayer(const SkRect*, const SkPaint*, SkCanvas::SaveFlags) SK_OVERRIDE;
77     void willRestore() SK_OVERRIDE;
78
79     void didConcat(const SkMatrix&) SK_OVERRIDE;
80     void didSetMatrix(const SkMatrix&) SK_OVERRIDE;
81
82     void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) SK_OVERRIDE;
83     void onDrawText(const void* text,
84                     size_t byteLength,
85                     SkScalar x,
86                     SkScalar y,
87                     const SkPaint& paint) SK_OVERRIDE;
88     void onDrawPosText(const void* text,
89                        size_t byteLength,
90                        const SkPoint pos[],
91                        const SkPaint& paint) SK_OVERRIDE;
92     void onDrawPosTextH(const void* text,
93                         size_t byteLength,
94                         const SkScalar xpos[],
95                         SkScalar constY,
96                         const SkPaint& paint) SK_OVERRIDE;
97     void onDrawTextOnPath(const void* text,
98                           size_t byteLength,
99                           const SkPath& path,
100                           const SkMatrix* matrix,
101                           const SkPaint& paint) SK_OVERRIDE;
102     void onClipRect(const SkRect& rect, SkRegion::Op op, ClipEdgeStyle edgeStyle) SK_OVERRIDE;
103     void onClipRRect(const SkRRect& rrect, SkRegion::Op op, ClipEdgeStyle edgeStyle) SK_OVERRIDE;
104     void onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeStyle edgeStyle) SK_OVERRIDE;
105     void onClipRegion(const SkRegion& deviceRgn, SkRegion::Op op) SK_OVERRIDE;
106
107     void onPushCull(const SkRect& cullRect) SK_OVERRIDE;
108     void onPopCull() SK_OVERRIDE;
109
110 private:
111     template <typename T>
112     T* copy(const T*);
113
114     template <typename T>
115     T* copy(const T[], unsigned count);
116
117     const Mode fMode;
118     SkRecord* fRecord;
119 };
120
121 #endif//SkRecorder_DEFINED