blob: 77f7173faa08b7689df454891ca4dd5d855acbfa [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
reed@google.com2d4297c2011-10-06 13:14:12 +000024 virtual int save(SaveFlags) SK_OVERRIDE;
25 virtual int saveLayer(const SkRect* bounds, const SkPaint*, SaveFlags) SK_OVERRIDE;
26 virtual void restore() SK_OVERRIDE;
27 virtual bool translate(SkScalar dx, SkScalar dy) SK_OVERRIDE;
28 virtual bool scale(SkScalar sx, SkScalar sy) SK_OVERRIDE;
29 virtual bool rotate(SkScalar degrees) SK_OVERRIDE;
30 virtual bool skew(SkScalar sx, SkScalar sy) SK_OVERRIDE;
31 virtual bool concat(const SkMatrix& matrix) SK_OVERRIDE;
32 virtual void setMatrix(const SkMatrix& matrix) SK_OVERRIDE;
reed@google.com071eef92011-10-12 11:52:53 +000033 virtual bool clipRect(const SkRect&, SkRegion::Op, bool) SK_OVERRIDE;
34 virtual bool clipPath(const SkPath&, SkRegion::Op, bool) SK_OVERRIDE;
reed@google.com2d4297c2011-10-06 13:14:12 +000035 virtual bool clipRegion(const SkRegion& region, SkRegion::Op op) SK_OVERRIDE;
36 virtual void clear(SkColor) SK_OVERRIDE;
37 virtual void drawPaint(const SkPaint& paint) SK_OVERRIDE;
reed@android.com8a1c16f2008-12-17 15:59:43 +000038 virtual void drawPoints(PointMode, size_t count, const SkPoint pts[],
reed@google.com2d4297c2011-10-06 13:14:12 +000039 const SkPaint&) SK_OVERRIDE;
40 virtual void drawRect(const SkRect& rect, const SkPaint&) SK_OVERRIDE;
41 virtual void drawPath(const SkPath& path, const SkPaint&) SK_OVERRIDE;
reed@android.com8a1c16f2008-12-17 15:59:43 +000042 virtual void drawBitmap(const SkBitmap&, SkScalar left, SkScalar top,
reed@google.com2d4297c2011-10-06 13:14:12 +000043 const SkPaint*) SK_OVERRIDE;
reed@android.com8a1c16f2008-12-17 15:59:43 +000044 virtual void drawBitmapRect(const SkBitmap&, const SkIRect* src,
reed@google.com2d4297c2011-10-06 13:14:12 +000045 const SkRect& dst, const SkPaint*) SK_OVERRIDE;
reed@android.com8a1c16f2008-12-17 15:59:43 +000046 virtual void drawBitmapMatrix(const SkBitmap&, const SkMatrix&,
reed@google.com2d4297c2011-10-06 13:14:12 +000047 const SkPaint*) SK_OVERRIDE;
reed@google.comf0b5e112011-09-07 11:57:34 +000048 virtual void drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center,
reed@google.com2d4297c2011-10-06 13:14:12 +000049 const SkRect& dst, const SkPaint*) SK_OVERRIDE;
reed@android.com8a1c16f2008-12-17 15:59:43 +000050 virtual void drawSprite(const SkBitmap&, int left, int top,
reed@google.com2d4297c2011-10-06 13:14:12 +000051 const SkPaint*) SK_OVERRIDE;
vandebo@chromium.org74b46192012-01-28 01:45:11 +000052 virtual void drawText(const void* text, size_t byteLength, SkScalar x,
reed@google.com2d4297c2011-10-06 13:14:12 +000053 SkScalar y, const SkPaint&) SK_OVERRIDE;
vandebo@chromium.org74b46192012-01-28 01:45:11 +000054 virtual void drawPosText(const void* text, size_t byteLength,
reed@google.com2d4297c2011-10-06 13:14:12 +000055 const SkPoint pos[], const SkPaint&) SK_OVERRIDE;
reed@android.com8a1c16f2008-12-17 15:59:43 +000056 virtual void drawPosTextH(const void* text, size_t byteLength,
reed@google.com2d4297c2011-10-06 13:14:12 +000057 const SkScalar xpos[], SkScalar constY, const SkPaint&) SK_OVERRIDE;
vandebo@chromium.org74b46192012-01-28 01:45:11 +000058 virtual void drawTextOnPath(const void* text, size_t byteLength,
59 const SkPath& path, const SkMatrix* matrix,
reed@google.com2d4297c2011-10-06 13:14:12 +000060 const SkPaint&) SK_OVERRIDE;
61 virtual void drawPicture(SkPicture& picture) SK_OVERRIDE;
reed@android.com8a1c16f2008-12-17 15:59:43 +000062 virtual void drawVertices(VertexMode, int vertexCount,
63 const SkPoint vertices[], const SkPoint texs[],
64 const SkColor colors[], SkXfermode*,
65 const uint16_t indices[], int indexCount,
reed@google.com2d4297c2011-10-06 13:14:12 +000066 const SkPaint&) SK_OVERRIDE;
67 virtual void drawData(const void*, size_t) SK_OVERRIDE;
reed@android.com8a1c16f2008-12-17 15:59:43 +000068
69 void addFontMetricsTopBottom(const SkPaint& paint, SkScalar baselineY);
vandebo@chromium.org74b46192012-01-28 01:45:11 +000070
reed@android.com8a1c16f2008-12-17 15:59:43 +000071 const SkTDArray<const SkFlatBitmap* >& getBitmaps() const {
72 return fBitmaps;
73 }
74 const SkTDArray<const SkFlatMatrix* >& getMatrices() const {
75 return fMatrices;
76 }
77 const SkTDArray<const SkFlatPaint* >& getPaints() const {
78 return fPaints;
79 }
80 const SkTDArray<SkPicture* >& getPictureRefs() const {
81 return fPictureRefs;
82 }
83 const SkTDArray<const SkFlatRegion* >& getRegions() const {
84 return fRegions;
85 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +000086
reed@android.com8a1c16f2008-12-17 15:59:43 +000087 void reset();
88
89 const SkWriter32& writeStream() const {
90 return fWriter;
91 }
92
93private:
94 SkTDArray<uint32_t> fRestoreOffsetStack;
95
96 void addDraw(DrawType drawType) {
97#ifdef SK_DEBUG_TRACE
98 SkDebugf("add %s\n", DrawTypeToString(drawType));
99#endif
100 fWriter.writeInt(drawType);
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000101 }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000102 void addInt(int value) {
103 fWriter.writeInt(value);
104 }
105 void addScalar(SkScalar scalar) {
106 fWriter.writeScalar(scalar);
107 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000108
reed@android.com8a1c16f2008-12-17 15:59:43 +0000109 void addBitmap(const SkBitmap& bitmap);
110 void addMatrix(const SkMatrix& matrix);
111 void addMatrixPtr(const SkMatrix* matrix);
112 void addPaint(const SkPaint& paint);
113 void addPaintPtr(const SkPaint* paint);
114 void addPath(const SkPath& path);
115 void addPicture(SkPicture& picture);
116 void addPoint(const SkPoint& point);
117 void addPoints(const SkPoint pts[], int count);
118 void addRect(const SkRect& rect);
119 void addRectPtr(const SkRect* rect);
reed@google.comf0b5e112011-09-07 11:57:34 +0000120 void addIRect(const SkIRect& rect);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000121 void addIRectPtr(const SkIRect* rect);
122 void addRegion(const SkRegion& region);
123 void addText(const void* text, size_t byteLength);
124
125 int find(SkTDArray<const SkFlatBitmap* >& bitmaps,
126 const SkBitmap& bitmap);
127 int find(SkTDArray<const SkFlatMatrix* >& matrices,
128 const SkMatrix* matrix);
129 int find(SkTDArray<const SkFlatPaint* >& paints, const SkPaint* paint);
130 int find(SkTDArray<const SkFlatRegion* >& regions, const SkRegion& region);
131
132#ifdef SK_DEBUG_DUMP
133public:
134 void dumpMatrices();
135 void dumpPaints();
136#endif
137
138#ifdef SK_DEBUG_SIZE
139public:
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000140 size_t size() const;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000141 int bitmaps(size_t* size) const;
142 int matrices(size_t* size) const;
143 int paints(size_t* size) const;
144 int paths(size_t* size) const;
145 int regions(size_t* size) const;
146 size_t streamlen() const;
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000147
reed@android.com8a1c16f2008-12-17 15:59:43 +0000148 size_t fPointBytes, fRectBytes, fTextBytes;
149 int fPointWrites, fRectWrites, fTextWrites;
150#endif
151
152#ifdef SK_DEBUG_VALIDATE
153public:
154 void validate() const;
155private:
156 void validateBitmaps() const;
157 void validateMatrices() const;
158 void validatePaints() const;
159 void validatePaths() const;
160 void validateRegions() const;
161#else
162public:
163 void validate() const {}
164#endif
165
166private:
167 SkChunkAlloc fHeap;
168 int fBitmapIndex;
169 SkTDArray<const SkFlatBitmap* > fBitmaps;
170 int fMatrixIndex;
171 SkTDArray<const SkFlatMatrix* > fMatrices;
172 int fPaintIndex;
173 SkTDArray<const SkFlatPaint* > fPaints;
174 int fRegionIndex;
175 SkTDArray<const SkFlatRegion* > fRegions;
176 SkPathHeap* fPathHeap; // reference counted
177 SkWriter32 fWriter;
178
reed@android.com09b84a02009-06-26 20:22:26 +0000179 // we ref each item in these arrays
reed@android.com8a1c16f2008-12-17 15:59:43 +0000180 SkTDArray<SkPicture*> fPictureRefs;
181
mike@reedtribe.orge9e08cc2011-04-29 01:44:52 +0000182 SkRefCntSet fRCSet;
183 SkRefCntSet fTFSet;
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000184
reed@android.comae814c82009-02-13 14:56:09 +0000185 uint32_t fRecordFlags;
186
reed@google.com45482d12011-08-29 19:02:39 +0000187 // helper function to handle save/restore culling offsets
188 void recordOffsetForRestore(SkRegion::Op op);
189
reed@android.com8a1c16f2008-12-17 15:59:43 +0000190 friend class SkPicturePlayback;
191
192 typedef SkCanvas INHERITED;
193};
194
195#endif