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