blob: 05761afd0b8199eeade510a2b6ef49f2a197e658 [file] [log] [blame]
reed@android.com8a1c16f2008-12-17 15:59:43 +00001#ifndef SkPictureRecord_DEFINED
2#define SkPictureRecord_DEFINED
3
4#include "SkCanvas.h"
5#include "SkFlattenable.h"
6#include "SkPathHeap.h"
7#include "SkPicture.h"
8#include "SkPictureFlat.h"
9#include "SkTemplates.h"
10#include "SkWriter32.h"
11
12class SkPictureRecord : public SkCanvas {
13public:
reed@android.comae814c82009-02-13 14:56:09 +000014 SkPictureRecord(uint32_t recordFlags);
reed@android.com8a1c16f2008-12-17 15:59:43 +000015 virtual ~SkPictureRecord();
16
17 // overrides from SkCanvas
18 virtual int save(SaveFlags);
19 virtual int saveLayer(const SkRect* bounds, const SkPaint*, SaveFlags);
20 virtual void restore();
21 virtual bool translate(SkScalar dx, SkScalar dy);
22 virtual bool scale(SkScalar sx, SkScalar sy);
23 virtual bool rotate(SkScalar degrees);
24 virtual bool skew(SkScalar sx, SkScalar sy);
25 virtual bool concat(const SkMatrix& matrix);
reed@android.com6e073b92009-01-06 15:03:30 +000026 virtual void setMatrix(const SkMatrix& matrix);
reed@android.com8a1c16f2008-12-17 15:59:43 +000027 virtual bool clipRect(const SkRect& rect, SkRegion::Op op);
28 virtual bool clipPath(const SkPath& path, SkRegion::Op op);
29 virtual bool clipRegion(const SkRegion& region, SkRegion::Op op);
30 virtual void drawPaint(const SkPaint& paint);
31 virtual void drawPoints(PointMode, size_t count, const SkPoint pts[],
32 const SkPaint&);
33 virtual void drawRect(const SkRect& rect, const SkPaint&);
34 virtual void drawPath(const SkPath& path, const SkPaint&);
35 virtual void drawBitmap(const SkBitmap&, SkScalar left, SkScalar top,
36 const SkPaint*);
37 virtual void drawBitmapRect(const SkBitmap&, const SkIRect* src,
38 const SkRect& dst, const SkPaint*);
39 virtual void drawBitmapMatrix(const SkBitmap&, const SkMatrix&,
40 const SkPaint*);
41 virtual void drawSprite(const SkBitmap&, int left, int top,
42 const SkPaint*);
43 virtual void drawText(const void* text, size_t byteLength, SkScalar x,
44 SkScalar y, const SkPaint&);
45 virtual void drawPosText(const void* text, size_t byteLength,
46 const SkPoint pos[], const SkPaint&);
47 virtual void drawPosTextH(const void* text, size_t byteLength,
48 const SkScalar xpos[], SkScalar constY, const SkPaint&);
49 virtual void drawTextOnPath(const void* text, size_t byteLength,
50 const SkPath& path, const SkMatrix* matrix,
51 const SkPaint&);
52 virtual void drawPicture(SkPicture& picture);
reed@android.com09b84a02009-06-26 20:22:26 +000053 virtual void drawShape(SkShape*);
reed@android.com8a1c16f2008-12-17 15:59:43 +000054 virtual void drawVertices(VertexMode, int vertexCount,
55 const SkPoint vertices[], const SkPoint texs[],
56 const SkColor colors[], SkXfermode*,
57 const uint16_t indices[], int indexCount,
58 const SkPaint&);
59
60 void addFontMetricsTopBottom(const SkPaint& paint, SkScalar baselineY);
61
62 const SkTDArray<const SkFlatBitmap* >& getBitmaps() const {
63 return fBitmaps;
64 }
65 const SkTDArray<const SkFlatMatrix* >& getMatrices() const {
66 return fMatrices;
67 }
68 const SkTDArray<const SkFlatPaint* >& getPaints() const {
69 return fPaints;
70 }
71 const SkTDArray<SkPicture* >& getPictureRefs() const {
72 return fPictureRefs;
73 }
reed@android.com09b84a02009-06-26 20:22:26 +000074 const SkTDArray<SkShape* >& getShapes() const {
75 return fShapes;
76 }
reed@android.com8a1c16f2008-12-17 15:59:43 +000077 const SkTDArray<const SkFlatRegion* >& getRegions() const {
78 return fRegions;
79 }
80
81 void reset();
82
83 const SkWriter32& writeStream() const {
84 return fWriter;
85 }
86
87private:
88 SkTDArray<uint32_t> fRestoreOffsetStack;
89
90 void addDraw(DrawType drawType) {
91#ifdef SK_DEBUG_TRACE
92 SkDebugf("add %s\n", DrawTypeToString(drawType));
93#endif
94 fWriter.writeInt(drawType);
95 }
96 void addInt(int value) {
97 fWriter.writeInt(value);
98 }
99 void addScalar(SkScalar scalar) {
100 fWriter.writeScalar(scalar);
101 }
102
103 void addBitmap(const SkBitmap& bitmap);
104 void addMatrix(const SkMatrix& matrix);
105 void addMatrixPtr(const SkMatrix* matrix);
106 void addPaint(const SkPaint& paint);
107 void addPaintPtr(const SkPaint* paint);
108 void addPath(const SkPath& path);
109 void addPicture(SkPicture& picture);
110 void addPoint(const SkPoint& point);
111 void addPoints(const SkPoint pts[], int count);
112 void addRect(const SkRect& rect);
113 void addRectPtr(const SkRect* rect);
114 void addIRectPtr(const SkIRect* rect);
115 void addRegion(const SkRegion& region);
116 void addText(const void* text, size_t byteLength);
117
118 int find(SkTDArray<const SkFlatBitmap* >& bitmaps,
119 const SkBitmap& bitmap);
120 int find(SkTDArray<const SkFlatMatrix* >& matrices,
121 const SkMatrix* matrix);
122 int find(SkTDArray<const SkFlatPaint* >& paints, const SkPaint* paint);
123 int find(SkTDArray<const SkFlatRegion* >& regions, const SkRegion& region);
124
125#ifdef SK_DEBUG_DUMP
126public:
127 void dumpMatrices();
128 void dumpPaints();
129#endif
130
131#ifdef SK_DEBUG_SIZE
132public:
133 size_t size() const;
134 int bitmaps(size_t* size) const;
135 int matrices(size_t* size) const;
136 int paints(size_t* size) const;
137 int paths(size_t* size) const;
138 int regions(size_t* size) const;
139 size_t streamlen() const;
140
141 size_t fPointBytes, fRectBytes, fTextBytes;
142 int fPointWrites, fRectWrites, fTextWrites;
143#endif
144
145#ifdef SK_DEBUG_VALIDATE
146public:
147 void validate() const;
148private:
149 void validateBitmaps() const;
150 void validateMatrices() const;
151 void validatePaints() const;
152 void validatePaths() const;
153 void validateRegions() const;
154#else
155public:
156 void validate() const {}
157#endif
158
159private:
160 SkChunkAlloc fHeap;
161 int fBitmapIndex;
162 SkTDArray<const SkFlatBitmap* > fBitmaps;
163 int fMatrixIndex;
164 SkTDArray<const SkFlatMatrix* > fMatrices;
165 int fPaintIndex;
166 SkTDArray<const SkFlatPaint* > fPaints;
167 int fRegionIndex;
168 SkTDArray<const SkFlatRegion* > fRegions;
169 SkPathHeap* fPathHeap; // reference counted
170 SkWriter32 fWriter;
171
reed@android.com09b84a02009-06-26 20:22:26 +0000172 // we ref each item in these arrays
reed@android.com8a1c16f2008-12-17 15:59:43 +0000173 SkTDArray<SkPicture*> fPictureRefs;
reed@android.com09b84a02009-06-26 20:22:26 +0000174 SkTDArray<SkShape*> fShapes;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000175
176 SkRefCntRecorder fRCRecorder;
177 SkRefCntRecorder fTFRecorder;
178
reed@android.comae814c82009-02-13 14:56:09 +0000179 uint32_t fRecordFlags;
180
reed@android.com8a1c16f2008-12-17 15:59:43 +0000181 friend class SkPicturePlayback;
182
183 typedef SkCanvas INHERITED;
184};
185
186#endif