blob: 3e4e47fcd7d36ed71dc7c26f087c32c7f14902a7 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
2/*
3 * Copyright 2011 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
reed@android.com8a1c16f2008-12-17 15:59:43 +00008#ifndef SkPictureRecord_DEFINED
9#define SkPictureRecord_DEFINED
10
11#include "SkCanvas.h"
12#include "SkFlattenable.h"
13#include "SkPathHeap.h"
14#include "SkPicture.h"
15#include "SkPictureFlat.h"
16#include "SkTemplates.h"
17#include "SkWriter32.h"
18
19class SkPictureRecord : public SkCanvas {
20public:
reed@android.comae814c82009-02-13 14:56:09 +000021 SkPictureRecord(uint32_t recordFlags);
reed@android.com8a1c16f2008-12-17 15:59:43 +000022 virtual ~SkPictureRecord();
23
24 // overrides from SkCanvas
25 virtual int save(SaveFlags);
26 virtual int saveLayer(const SkRect* bounds, const SkPaint*, SaveFlags);
27 virtual void restore();
28 virtual bool translate(SkScalar dx, SkScalar dy);
29 virtual bool scale(SkScalar sx, SkScalar sy);
30 virtual bool rotate(SkScalar degrees);
31 virtual bool skew(SkScalar sx, SkScalar sy);
32 virtual bool concat(const SkMatrix& matrix);
reed@android.com6e073b92009-01-06 15:03:30 +000033 virtual void setMatrix(const SkMatrix& matrix);
reed@android.com8a1c16f2008-12-17 15:59:43 +000034 virtual bool clipRect(const SkRect& rect, SkRegion::Op op);
35 virtual bool clipPath(const SkPath& path, SkRegion::Op op);
36 virtual bool clipRegion(const SkRegion& region, SkRegion::Op op);
reed@google.com2a981812011-04-14 18:59:28 +000037 virtual void clear(SkColor);
reed@android.com8a1c16f2008-12-17 15:59:43 +000038 virtual void drawPaint(const SkPaint& paint);
39 virtual void drawPoints(PointMode, size_t count, const SkPoint pts[],
40 const SkPaint&);
41 virtual void drawRect(const SkRect& rect, const SkPaint&);
42 virtual void drawPath(const SkPath& path, const SkPaint&);
43 virtual void drawBitmap(const SkBitmap&, SkScalar left, SkScalar top,
44 const SkPaint*);
45 virtual void drawBitmapRect(const SkBitmap&, const SkIRect* src,
46 const SkRect& dst, const SkPaint*);
47 virtual void drawBitmapMatrix(const SkBitmap&, const SkMatrix&,
48 const SkPaint*);
reed@google.comf0b5e112011-09-07 11:57:34 +000049 virtual void drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center,
50 const SkRect& dst, const SkPaint*);
reed@android.com8a1c16f2008-12-17 15:59:43 +000051 virtual void drawSprite(const SkBitmap&, int left, int top,
52 const SkPaint*);
53 virtual void drawText(const void* text, size_t byteLength, SkScalar x,
54 SkScalar y, const SkPaint&);
55 virtual void drawPosText(const void* text, size_t byteLength,
56 const SkPoint pos[], const SkPaint&);
57 virtual void drawPosTextH(const void* text, size_t byteLength,
58 const SkScalar xpos[], SkScalar constY, const SkPaint&);
59 virtual void drawTextOnPath(const void* text, size_t byteLength,
60 const SkPath& path, const SkMatrix* matrix,
61 const SkPaint&);
62 virtual void drawPicture(SkPicture& picture);
63 virtual void drawVertices(VertexMode, int vertexCount,
64 const SkPoint vertices[], const SkPoint texs[],
65 const SkColor colors[], SkXfermode*,
66 const uint16_t indices[], int indexCount,
67 const SkPaint&);
reed@android.comcb608442009-12-04 21:32:27 +000068 virtual void drawData(const void*, size_t);
reed@android.com8a1c16f2008-12-17 15:59:43 +000069
70 void addFontMetricsTopBottom(const SkPaint& paint, SkScalar baselineY);
71
72 const SkTDArray<const SkFlatBitmap* >& getBitmaps() const {
73 return fBitmaps;
74 }
75 const SkTDArray<const SkFlatMatrix* >& getMatrices() const {
76 return fMatrices;
77 }
78 const SkTDArray<const SkFlatPaint* >& getPaints() const {
79 return fPaints;
80 }
81 const SkTDArray<SkPicture* >& getPictureRefs() const {
82 return fPictureRefs;
83 }
84 const SkTDArray<const SkFlatRegion* >& getRegions() const {
85 return fRegions;
86 }
87
88 void reset();
89
90 const SkWriter32& writeStream() const {
91 return fWriter;
92 }
93
94private:
95 SkTDArray<uint32_t> fRestoreOffsetStack;
96
97 void addDraw(DrawType drawType) {
98#ifdef SK_DEBUG_TRACE
99 SkDebugf("add %s\n", DrawTypeToString(drawType));
100#endif
101 fWriter.writeInt(drawType);
102 }
103 void addInt(int value) {
104 fWriter.writeInt(value);
105 }
106 void addScalar(SkScalar scalar) {
107 fWriter.writeScalar(scalar);
108 }
109
110 void addBitmap(const SkBitmap& bitmap);
111 void addMatrix(const SkMatrix& matrix);
112 void addMatrixPtr(const SkMatrix* matrix);
113 void addPaint(const SkPaint& paint);
114 void addPaintPtr(const SkPaint* paint);
115 void addPath(const SkPath& path);
116 void addPicture(SkPicture& picture);
117 void addPoint(const SkPoint& point);
118 void addPoints(const SkPoint pts[], int count);
119 void addRect(const SkRect& rect);
120 void addRectPtr(const SkRect* rect);
reed@google.comf0b5e112011-09-07 11:57:34 +0000121 void addIRect(const SkIRect& rect);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000122 void addIRectPtr(const SkIRect* rect);
123 void addRegion(const SkRegion& region);
124 void addText(const void* text, size_t byteLength);
125
126 int find(SkTDArray<const SkFlatBitmap* >& bitmaps,
127 const SkBitmap& bitmap);
128 int find(SkTDArray<const SkFlatMatrix* >& matrices,
129 const SkMatrix* matrix);
130 int find(SkTDArray<const SkFlatPaint* >& paints, const SkPaint* paint);
131 int find(SkTDArray<const SkFlatRegion* >& regions, const SkRegion& region);
132
133#ifdef SK_DEBUG_DUMP
134public:
135 void dumpMatrices();
136 void dumpPaints();
137#endif
138
139#ifdef SK_DEBUG_SIZE
140public:
141 size_t size() const;
142 int bitmaps(size_t* size) const;
143 int matrices(size_t* size) const;
144 int paints(size_t* size) const;
145 int paths(size_t* size) const;
146 int regions(size_t* size) const;
147 size_t streamlen() const;
148
149 size_t fPointBytes, fRectBytes, fTextBytes;
150 int fPointWrites, fRectWrites, fTextWrites;
151#endif
152
153#ifdef SK_DEBUG_VALIDATE
154public:
155 void validate() const;
156private:
157 void validateBitmaps() const;
158 void validateMatrices() const;
159 void validatePaints() const;
160 void validatePaths() const;
161 void validateRegions() const;
162#else
163public:
164 void validate() const {}
165#endif
166
167private:
168 SkChunkAlloc fHeap;
169 int fBitmapIndex;
170 SkTDArray<const SkFlatBitmap* > fBitmaps;
171 int fMatrixIndex;
172 SkTDArray<const SkFlatMatrix* > fMatrices;
173 int fPaintIndex;
174 SkTDArray<const SkFlatPaint* > fPaints;
175 int fRegionIndex;
176 SkTDArray<const SkFlatRegion* > fRegions;
177 SkPathHeap* fPathHeap; // reference counted
178 SkWriter32 fWriter;
179
reed@android.com09b84a02009-06-26 20:22:26 +0000180 // we ref each item in these arrays
reed@android.com8a1c16f2008-12-17 15:59:43 +0000181 SkTDArray<SkPicture*> fPictureRefs;
182
mike@reedtribe.orge9e08cc2011-04-29 01:44:52 +0000183 SkRefCntSet fRCSet;
184 SkRefCntSet fTFSet;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000185
reed@android.comae814c82009-02-13 14:56:09 +0000186 uint32_t fRecordFlags;
187
reed@google.com45482d12011-08-29 19:02:39 +0000188 // helper function to handle save/restore culling offsets
189 void recordOffsetForRestore(SkRegion::Op op);
190
reed@android.com8a1c16f2008-12-17 15:59:43 +0000191 friend class SkPicturePlayback;
192
193 typedef SkCanvas INHERITED;
194};
195
196#endif