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 | |
rileya@google.com | 9f5898d | 2012-09-11 20:21:44 +0000 | [diff] [blame] | 19 | class SkPictureStateTree; |
| 20 | class SkBBoxHierarchy; |
| 21 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 22 | class SkPictureRecord : public SkCanvas { |
| 23 | public: |
reed@google.com | d86e7ab | 2012-09-27 20:31:31 +0000 | [diff] [blame] | 24 | SkPictureRecord(uint32_t recordFlags, SkDevice*); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 25 | virtual ~SkPictureRecord(); |
| 26 | |
junov@chromium.org | 4e6dfa5 | 2012-07-16 14:04:59 +0000 | [diff] [blame] | 27 | virtual SkDevice* setDevice(SkDevice* device) SK_OVERRIDE; |
| 28 | |
reed@google.com | 2d4297c | 2011-10-06 13:14:12 +0000 | [diff] [blame] | 29 | virtual int save(SaveFlags) SK_OVERRIDE; |
| 30 | virtual int saveLayer(const SkRect* bounds, const SkPaint*, SaveFlags) SK_OVERRIDE; |
| 31 | virtual void restore() SK_OVERRIDE; |
| 32 | virtual bool translate(SkScalar dx, SkScalar dy) SK_OVERRIDE; |
| 33 | virtual bool scale(SkScalar sx, SkScalar sy) SK_OVERRIDE; |
| 34 | virtual bool rotate(SkScalar degrees) SK_OVERRIDE; |
| 35 | virtual bool skew(SkScalar sx, SkScalar sy) SK_OVERRIDE; |
| 36 | virtual bool concat(const SkMatrix& matrix) SK_OVERRIDE; |
| 37 | virtual void setMatrix(const SkMatrix& matrix) SK_OVERRIDE; |
reed@google.com | 071eef9 | 2011-10-12 11:52:53 +0000 | [diff] [blame] | 38 | virtual bool clipRect(const SkRect&, SkRegion::Op, bool) SK_OVERRIDE; |
| 39 | virtual bool clipPath(const SkPath&, SkRegion::Op, bool) SK_OVERRIDE; |
reed@google.com | 2d4297c | 2011-10-06 13:14:12 +0000 | [diff] [blame] | 40 | virtual bool clipRegion(const SkRegion& region, SkRegion::Op op) SK_OVERRIDE; |
| 41 | virtual void clear(SkColor) SK_OVERRIDE; |
| 42 | virtual void drawPaint(const SkPaint& paint) SK_OVERRIDE; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 43 | virtual void drawPoints(PointMode, size_t count, const SkPoint pts[], |
reed@google.com | 2d4297c | 2011-10-06 13:14:12 +0000 | [diff] [blame] | 44 | const SkPaint&) SK_OVERRIDE; |
| 45 | virtual void drawRect(const SkRect& rect, const SkPaint&) SK_OVERRIDE; |
| 46 | virtual void drawPath(const SkPath& path, const SkPaint&) SK_OVERRIDE; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 47 | virtual void drawBitmap(const SkBitmap&, SkScalar left, SkScalar top, |
reed@google.com | 2d4297c | 2011-10-06 13:14:12 +0000 | [diff] [blame] | 48 | const SkPaint*) SK_OVERRIDE; |
reed@google.com | 7112173 | 2012-09-18 15:14:33 +0000 | [diff] [blame] | 49 | virtual void drawBitmapRectToRect(const SkBitmap&, const SkRect* src, |
| 50 | const SkRect& dst, const SkPaint*) SK_OVERRIDE; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 51 | virtual void drawBitmapMatrix(const SkBitmap&, const SkMatrix&, |
reed@google.com | 2d4297c | 2011-10-06 13:14:12 +0000 | [diff] [blame] | 52 | const SkPaint*) SK_OVERRIDE; |
reed@google.com | f0b5e11 | 2011-09-07 11:57:34 +0000 | [diff] [blame] | 53 | virtual void drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, |
reed@google.com | 2d4297c | 2011-10-06 13:14:12 +0000 | [diff] [blame] | 54 | const SkRect& dst, const SkPaint*) SK_OVERRIDE; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 55 | virtual void drawSprite(const SkBitmap&, int left, int top, |
reed@google.com | 2d4297c | 2011-10-06 13:14:12 +0000 | [diff] [blame] | 56 | const SkPaint*) SK_OVERRIDE; |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 57 | virtual void drawText(const void* text, size_t byteLength, SkScalar x, |
reed@google.com | 2d4297c | 2011-10-06 13:14:12 +0000 | [diff] [blame] | 58 | SkScalar y, const SkPaint&) SK_OVERRIDE; |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 59 | virtual void drawPosText(const void* text, size_t byteLength, |
reed@google.com | 2d4297c | 2011-10-06 13:14:12 +0000 | [diff] [blame] | 60 | const SkPoint pos[], const SkPaint&) SK_OVERRIDE; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 61 | virtual void drawPosTextH(const void* text, size_t byteLength, |
reed@google.com | 2d4297c | 2011-10-06 13:14:12 +0000 | [diff] [blame] | 62 | const SkScalar xpos[], SkScalar constY, const SkPaint&) SK_OVERRIDE; |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 63 | virtual void drawTextOnPath(const void* text, size_t byteLength, |
| 64 | const SkPath& path, const SkMatrix* matrix, |
reed@google.com | 2d4297c | 2011-10-06 13:14:12 +0000 | [diff] [blame] | 65 | const SkPaint&) SK_OVERRIDE; |
| 66 | virtual void drawPicture(SkPicture& picture) SK_OVERRIDE; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 67 | virtual void drawVertices(VertexMode, int vertexCount, |
| 68 | const SkPoint vertices[], const SkPoint texs[], |
| 69 | const SkColor colors[], SkXfermode*, |
| 70 | const uint16_t indices[], int indexCount, |
reed@google.com | 2d4297c | 2011-10-06 13:14:12 +0000 | [diff] [blame] | 71 | const SkPaint&) SK_OVERRIDE; |
| 72 | virtual void drawData(const void*, size_t) SK_OVERRIDE; |
junov@chromium.org | 8f9ecbd | 2012-02-13 21:53:45 +0000 | [diff] [blame] | 73 | virtual bool isDrawingToLayer() const SK_OVERRIDE; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 74 | |
reed@google.com | 9efd9a0 | 2012-01-30 15:41:43 +0000 | [diff] [blame] | 75 | void addFontMetricsTopBottom(const SkPaint& paint, SkScalar minY, SkScalar maxY); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 76 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 77 | const SkTDArray<SkPicture* >& getPictureRefs() const { |
| 78 | return fPictureRefs; |
| 79 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 80 | |
junov@chromium.org | 4866cc0 | 2012-06-01 21:23:07 +0000 | [diff] [blame] | 81 | void setFlags(uint32_t recordFlags) { |
| 82 | fRecordFlags = recordFlags; |
| 83 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 84 | |
| 85 | const SkWriter32& writeStream() const { |
| 86 | return fWriter; |
| 87 | } |
| 88 | |
reed@google.com | d86e7ab | 2012-09-27 20:31:31 +0000 | [diff] [blame] | 89 | void beginRecording(); |
junov@chromium.org | a6c9e0e | 2012-07-12 17:47:34 +0000 | [diff] [blame] | 90 | void endRecording(); |
reed@google.com | d86e7ab | 2012-09-27 20:31:31 +0000 | [diff] [blame] | 91 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 92 | private: |
junov@chromium.org | e3dbedb | 2012-07-09 16:03:55 +0000 | [diff] [blame] | 93 | void recordRestoreOffsetPlaceholder(SkRegion::Op); |
| 94 | void fillRestoreOffsetPlaceholdersForCurrentStackLevel( |
| 95 | uint32_t restoreOffset); |
| 96 | |
reed@google.com | ffacd3c | 2012-08-30 15:31:23 +0000 | [diff] [blame] | 97 | SkTDArray<int32_t> fRestoreOffsetStack; |
junov@chromium.org | 8f9ecbd | 2012-02-13 21:53:45 +0000 | [diff] [blame] | 98 | int fFirstSavedLayerIndex; |
| 99 | enum { |
| 100 | kNoSavedLayerIndex = -1 |
| 101 | }; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 102 | |
| 103 | void addDraw(DrawType drawType) { |
reed@google.com | 97af1a6 | 2012-08-28 12:19:02 +0000 | [diff] [blame] | 104 | this->predrawNotify(); |
| 105 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 106 | #ifdef SK_DEBUG_TRACE |
| 107 | SkDebugf("add %s\n", DrawTypeToString(drawType)); |
| 108 | #endif |
| 109 | fWriter.writeInt(drawType); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 110 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 111 | void addInt(int value) { |
| 112 | fWriter.writeInt(value); |
| 113 | } |
| 114 | void addScalar(SkScalar scalar) { |
| 115 | fWriter.writeScalar(scalar); |
| 116 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 117 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 118 | void addBitmap(const SkBitmap& bitmap); |
| 119 | void addMatrix(const SkMatrix& matrix); |
| 120 | void addMatrixPtr(const SkMatrix* matrix); |
| 121 | void addPaint(const SkPaint& paint); |
| 122 | void addPaintPtr(const SkPaint* paint); |
| 123 | void addPath(const SkPath& path); |
| 124 | void addPicture(SkPicture& picture); |
| 125 | void addPoint(const SkPoint& point); |
| 126 | void addPoints(const SkPoint pts[], int count); |
| 127 | void addRect(const SkRect& rect); |
| 128 | void addRectPtr(const SkRect* rect); |
reed@google.com | f0b5e11 | 2011-09-07 11:57:34 +0000 | [diff] [blame] | 129 | void addIRect(const SkIRect& rect); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 130 | void addIRectPtr(const SkIRect* rect); |
| 131 | void addRegion(const SkRegion& region); |
| 132 | void addText(const void* text, size_t byteLength); |
| 133 | |
junov@chromium.org | 4866cc0 | 2012-06-01 21:23:07 +0000 | [diff] [blame] | 134 | int find(const SkBitmap& bitmap); |
| 135 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 136 | #ifdef SK_DEBUG_DUMP |
| 137 | public: |
| 138 | void dumpMatrices(); |
| 139 | void dumpPaints(); |
| 140 | #endif |
| 141 | |
| 142 | #ifdef SK_DEBUG_SIZE |
| 143 | public: |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 144 | size_t size() const; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 145 | int bitmaps(size_t* size) const; |
| 146 | int matrices(size_t* size) const; |
| 147 | int paints(size_t* size) const; |
| 148 | int paths(size_t* size) const; |
| 149 | int regions(size_t* size) const; |
| 150 | size_t streamlen() const; |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 151 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 152 | size_t fPointBytes, fRectBytes, fTextBytes; |
| 153 | int fPointWrites, fRectWrites, fTextWrites; |
| 154 | #endif |
| 155 | |
| 156 | #ifdef SK_DEBUG_VALIDATE |
| 157 | public: |
| 158 | void validate() const; |
| 159 | private: |
| 160 | void validateBitmaps() const; |
| 161 | void validateMatrices() const; |
| 162 | void validatePaints() const; |
| 163 | void validatePaths() const; |
| 164 | void validateRegions() const; |
| 165 | #else |
| 166 | public: |
| 167 | void validate() const {} |
| 168 | #endif |
| 169 | |
rileya@google.com | 9f5898d | 2012-09-11 20:21:44 +0000 | [diff] [blame] | 170 | protected: |
| 171 | |
| 172 | // These are set to NULL in our constructor, but may be changed by |
| 173 | // subclasses, in which case they will be SkSafeUnref'd in our destructor. |
| 174 | SkBBoxHierarchy* fBoundingHierarchy; |
| 175 | SkPictureStateTree* fStateTree; |
| 176 | |
robertphillips@google.com | 801cee1 | 2012-10-19 19:06:11 +0000 | [diff] [blame^] | 177 | // Allocated in the constructor and managed by this class. |
djsollen@google.com | c9ab987 | 2012-08-29 18:52:07 +0000 | [diff] [blame] | 178 | SkBitmapHeap* fBitmapHeap; |
robertphillips@google.com | 801cee1 | 2012-10-19 19:06:11 +0000 | [diff] [blame^] | 179 | |
| 180 | private: |
djsollen@google.com | 21830d9 | 2012-08-07 19:49:41 +0000 | [diff] [blame] | 181 | SkChunkFlatController fFlattenableHeap; |
junov@chromium.org | 4866cc0 | 2012-06-01 21:23:07 +0000 | [diff] [blame] | 182 | |
djsollen@google.com | d2700ee | 2012-05-30 16:54:13 +0000 | [diff] [blame] | 183 | SkMatrixDictionary fMatrices; |
| 184 | SkPaintDictionary fPaints; |
| 185 | SkRegionDictionary fRegions; |
| 186 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 187 | SkPathHeap* fPathHeap; // reference counted |
| 188 | SkWriter32 fWriter; |
| 189 | |
reed@android.com | 09b84a0 | 2009-06-26 20:22:26 +0000 | [diff] [blame] | 190 | // we ref each item in these arrays |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 191 | SkTDArray<SkPicture*> fPictureRefs; |
| 192 | |
reed@android.com | ae814c8 | 2009-02-13 14:56:09 +0000 | [diff] [blame] | 193 | uint32_t fRecordFlags; |
junov@chromium.org | 4e6dfa5 | 2012-07-16 14:04:59 +0000 | [diff] [blame] | 194 | int fInitialSaveCount; |
reed@android.com | ae814c8 | 2009-02-13 14:56:09 +0000 | [diff] [blame] | 195 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 196 | friend class SkPicturePlayback; |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 197 | friend class SkPictureTester; // for unit testing |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 198 | |
| 199 | typedef SkCanvas INHERITED; |
| 200 | }; |
| 201 | |
| 202 | #endif |