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 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); 53 virtual void drawShape(SkShape*); 54 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 getBitmaps()62 const SkTDArray<const SkFlatBitmap* >& getBitmaps() const { 63 return fBitmaps; 64 } getMatrices()65 const SkTDArray<const SkFlatMatrix* >& getMatrices() const { 66 return fMatrices; 67 } getPaints()68 const SkTDArray<const SkFlatPaint* >& getPaints() const { 69 return fPaints; 70 } getPictureRefs()71 const SkTDArray<SkPicture* >& getPictureRefs() const { 72 return fPictureRefs; 73 } getShapes()74 const SkTDArray<SkShape* >& getShapes() const { 75 return fShapes; 76 } getRegions()77 const SkTDArray<const SkFlatRegion* >& getRegions() const { 78 return fRegions; 79 } 80 81 void reset(); 82 writeStream()83 const SkWriter32& writeStream() const { 84 return fWriter; 85 } 86 87 private: 88 SkTDArray<uint32_t> fRestoreOffsetStack; 89 addDraw(DrawType drawType)90 void addDraw(DrawType drawType) { 91 #ifdef SK_DEBUG_TRACE 92 SkDebugf("add %s\n", DrawTypeToString(drawType)); 93 #endif 94 fWriter.writeInt(drawType); 95 } addInt(int value)96 void addInt(int value) { 97 fWriter.writeInt(value); 98 } addScalar(SkScalar scalar)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 126 public: 127 void dumpMatrices(); 128 void dumpPaints(); 129 #endif 130 131 #ifdef SK_DEBUG_SIZE 132 public: 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 146 public: 147 void validate() const; 148 private: 149 void validateBitmaps() const; 150 void validateMatrices() const; 151 void validatePaints() const; 152 void validatePaths() const; 153 void validateRegions() const; 154 #else 155 public: validate()156 void validate() const {} 157 #endif 158 159 private: 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 172 // we ref each item in these arrays 173 SkTDArray<SkPicture*> fPictureRefs; 174 SkTDArray<SkShape*> fShapes; 175 176 SkRefCntRecorder fRCRecorder; 177 SkRefCntRecorder fTFRecorder; 178 179 uint32_t fRecordFlags; 180 181 friend class SkPicturePlayback; 182 183 typedef SkCanvas INHERITED; 184 }; 185 186 #endif 187