• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #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 
12 class SkPictureRecord : public SkCanvas {
13 public:
14     SkPictureRecord(uint32_t recordFlags);
15     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);
26     virtual void setMatrix(const SkMatrix& matrix);
27     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 clear(SkColor);
31     virtual void drawPaint(const SkPaint& paint);
32     virtual void drawPoints(PointMode, size_t count, const SkPoint pts[],
33                             const SkPaint&);
34     virtual void drawRect(const SkRect& rect, const SkPaint&);
35     virtual void drawPath(const SkPath& path, const SkPaint&);
36     virtual void drawBitmap(const SkBitmap&, SkScalar left, SkScalar top,
37                             const SkPaint*);
38     virtual void drawBitmapRect(const SkBitmap&, const SkIRect* src,
39                                 const SkRect& dst, const SkPaint*);
40     virtual void drawBitmapMatrix(const SkBitmap&, const SkMatrix&,
41                                   const SkPaint*);
42     virtual void drawSprite(const SkBitmap&, int left, int top,
43                             const SkPaint*);
44     virtual void drawText(const void* text, size_t byteLength, SkScalar x,
45                           SkScalar y, const SkPaint&);
46     virtual void drawPosText(const void* text, size_t byteLength,
47                              const SkPoint pos[], const SkPaint&);
48     virtual void drawPosTextH(const void* text, size_t byteLength,
49                       const SkScalar xpos[], SkScalar constY, const SkPaint&);
50     virtual void drawTextOnPath(const void* text, size_t byteLength,
51                             const SkPath& path, const SkMatrix* matrix,
52                                 const SkPaint&);
53     virtual void drawPicture(SkPicture& picture);
54     virtual void drawShape(SkShape*);
55     virtual void drawVertices(VertexMode, int vertexCount,
56                           const SkPoint vertices[], const SkPoint texs[],
57                           const SkColor colors[], SkXfermode*,
58                           const uint16_t indices[], int indexCount,
59                               const SkPaint&);
60     virtual void drawData(const void*, size_t);
61 
62     void addFontMetricsTopBottom(const SkPaint& paint, SkScalar baselineY);
63 
getBitmaps()64     const SkTDArray<const SkFlatBitmap* >& getBitmaps() const {
65         return fBitmaps;
66     }
getMatrices()67     const SkTDArray<const SkFlatMatrix* >& getMatrices() const {
68         return fMatrices;
69     }
getPaints()70     const SkTDArray<const SkFlatPaint* >& getPaints() const {
71         return fPaints;
72     }
getPictureRefs()73     const SkTDArray<SkPicture* >& getPictureRefs() const {
74         return fPictureRefs;
75     }
getShapes()76     const SkTDArray<SkShape* >& getShapes() const {
77         return fShapes;
78     }
getRegions()79     const SkTDArray<const SkFlatRegion* >& getRegions() const {
80         return fRegions;
81     }
82 
83     void reset();
84 
writeStream()85     const SkWriter32& writeStream() const {
86         return fWriter;
87     }
88 
89 private:
90     SkTDArray<uint32_t> fRestoreOffsetStack;
91 
addDraw(DrawType drawType)92     void addDraw(DrawType drawType) {
93 #ifdef SK_DEBUG_TRACE
94         SkDebugf("add %s\n", DrawTypeToString(drawType));
95 #endif
96         fWriter.writeInt(drawType);
97     }
addInt(int value)98     void addInt(int value) {
99         fWriter.writeInt(value);
100     }
addScalar(SkScalar scalar)101     void addScalar(SkScalar scalar) {
102         fWriter.writeScalar(scalar);
103     }
104 
105     void addBitmap(const SkBitmap& bitmap);
106     void addMatrix(const SkMatrix& matrix);
107     void addMatrixPtr(const SkMatrix* matrix);
108     void addPaint(const SkPaint& paint);
109     void addPaintPtr(const SkPaint* paint);
110     void addPath(const SkPath& path);
111     void addPicture(SkPicture& picture);
112     void addPoint(const SkPoint& point);
113     void addPoints(const SkPoint pts[], int count);
114     void addRect(const SkRect& rect);
115     void addRectPtr(const SkRect* rect);
116     void addIRectPtr(const SkIRect* rect);
117     void addRegion(const SkRegion& region);
118     void addText(const void* text, size_t byteLength);
119 
120     int find(SkTDArray<const SkFlatBitmap* >& bitmaps,
121                    const SkBitmap& bitmap);
122     int find(SkTDArray<const SkFlatMatrix* >& matrices,
123                    const SkMatrix* matrix);
124     int find(SkTDArray<const SkFlatPaint* >& paints, const SkPaint* paint);
125     int find(SkTDArray<const SkFlatRegion* >& regions, const SkRegion& region);
126 
127 #ifdef SK_DEBUG_DUMP
128 public:
129     void dumpMatrices();
130     void dumpPaints();
131 #endif
132 
133 #ifdef SK_DEBUG_SIZE
134 public:
135     size_t size() const;
136     int bitmaps(size_t* size) const;
137     int matrices(size_t* size) const;
138     int paints(size_t* size) const;
139     int paths(size_t* size) const;
140     int regions(size_t* size) const;
141     size_t streamlen() const;
142 
143     size_t fPointBytes, fRectBytes, fTextBytes;
144     int fPointWrites, fRectWrites, fTextWrites;
145 #endif
146 
147 #ifdef SK_DEBUG_VALIDATE
148 public:
149     void validate() const;
150 private:
151     void validateBitmaps() const;
152     void validateMatrices() const;
153     void validatePaints() const;
154     void validatePaths() const;
155     void validateRegions() const;
156 #else
157 public:
validate()158     void validate() const {}
159 #endif
160 
161 private:
162     SkChunkAlloc fHeap;
163     int fBitmapIndex;
164     SkTDArray<const SkFlatBitmap* > fBitmaps;
165     int fMatrixIndex;
166     SkTDArray<const SkFlatMatrix* > fMatrices;
167     int fPaintIndex;
168     SkTDArray<const SkFlatPaint* > fPaints;
169     int fRegionIndex;
170     SkTDArray<const SkFlatRegion* > fRegions;
171     SkPathHeap* fPathHeap;  // reference counted
172     SkWriter32 fWriter;
173 
174     // we ref each item in these arrays
175     SkTDArray<SkPicture*> fPictureRefs;
176     SkTDArray<SkShape*> fShapes;
177 
178     SkRefCntSet fRCSet;
179     SkRefCntSet fTFSet;
180 
181     uint32_t fRecordFlags;
182 
183     friend class SkPicturePlayback;
184 
185     typedef SkCanvas INHERITED;
186 };
187 
188 #endif
189