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*); |
reed@google.com | f0b5e11 | 2011-09-07 11:57:34 +0000 | [diff] [blame^] | 49 | virtual void drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, |
| 50 | const SkRect& dst, const SkPaint*); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 51 | 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.com | cb60844 | 2009-12-04 21:32:27 +0000 | [diff] [blame] | 68 | virtual void drawData(const void*, size_t); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 69 | |
| 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 | |
| 94 | private: |
| 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.com | f0b5e11 | 2011-09-07 11:57:34 +0000 | [diff] [blame^] | 121 | void addIRect(const SkIRect& rect); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 122 | 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 |
| 134 | public: |
| 135 | void dumpMatrices(); |
| 136 | void dumpPaints(); |
| 137 | #endif |
| 138 | |
| 139 | #ifdef SK_DEBUG_SIZE |
| 140 | public: |
| 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 |
| 154 | public: |
| 155 | void validate() const; |
| 156 | private: |
| 157 | void validateBitmaps() const; |
| 158 | void validateMatrices() const; |
| 159 | void validatePaints() const; |
| 160 | void validatePaths() const; |
| 161 | void validateRegions() const; |
| 162 | #else |
| 163 | public: |
| 164 | void validate() const {} |
| 165 | #endif |
| 166 | |
| 167 | private: |
| 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.com | 09b84a0 | 2009-06-26 20:22:26 +0000 | [diff] [blame] | 180 | // we ref each item in these arrays |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 181 | SkTDArray<SkPicture*> fPictureRefs; |
| 182 | |
mike@reedtribe.org | e9e08cc | 2011-04-29 01:44:52 +0000 | [diff] [blame] | 183 | SkRefCntSet fRCSet; |
| 184 | SkRefCntSet fTFSet; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 185 | |
reed@android.com | ae814c8 | 2009-02-13 14:56:09 +0000 | [diff] [blame] | 186 | uint32_t fRecordFlags; |
| 187 | |
reed@google.com | 45482d1 | 2011-08-29 19:02:39 +0000 | [diff] [blame] | 188 | // helper function to handle save/restore culling offsets |
| 189 | void recordOffsetForRestore(SkRegion::Op op); |
| 190 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 191 | friend class SkPicturePlayback; |
| 192 | |
| 193 | typedef SkCanvas INHERITED; |
| 194 | }; |
| 195 | |
| 196 | #endif |