epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2011 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
reed@google.com | 76f10a3 | 2014-02-05 15:32:21 +0000 | [diff] [blame] | 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" |
robertphillips@google.com | 105a4a5 | 2014-02-11 15:10:40 +0000 | [diff] [blame] | 13 | #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE |
| 14 | #include "SkMatrixClipStateMgr.h" |
| 15 | #endif |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 16 | #include "SkPathHeap.h" |
| 17 | #include "SkPicture.h" |
robertphillips | db53990 | 2014-07-01 08:47:04 -0700 | [diff] [blame] | 18 | #include "SkPictureData.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 19 | #include "SkPictureFlat.h" |
| 20 | #include "SkTemplates.h" |
| 21 | #include "SkWriter32.h" |
| 22 | |
rileya@google.com | 9f5898d | 2012-09-11 20:21:44 +0000 | [diff] [blame] | 23 | class SkBBoxHierarchy; |
commit-bot@chromium.org | 8016f79 | 2014-03-07 15:53:01 +0000 | [diff] [blame] | 24 | class SkPictureStateTree; |
rileya@google.com | 9f5898d | 2012-09-11 20:21:44 +0000 | [diff] [blame] | 25 | |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 26 | // These macros help with packing and unpacking a single byte value and |
| 27 | // a 3 byte value into/out of a uint32_t |
| 28 | #define MASK_24 0x00FFFFFF |
| 29 | #define UNPACK_8_24(combined, small, large) \ |
| 30 | small = (combined >> 24) & 0xFF; \ |
| 31 | large = combined & MASK_24; |
| 32 | #define PACK_8_24(small, large) ((small << 24) | large) |
| 33 | |
| 34 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 35 | class SkPictureRecord : public SkCanvas { |
| 36 | public: |
robertphillips | 0bdbea7 | 2014-06-11 11:37:55 -0700 | [diff] [blame] | 37 | SkPictureRecord(const SkISize& dimensions, uint32_t recordFlags); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 38 | virtual ~SkPictureRecord(); |
| 39 | |
reed@google.com | 2d4297c | 2011-10-06 13:14:12 +0000 | [diff] [blame] | 40 | virtual void clear(SkColor) SK_OVERRIDE; |
| 41 | virtual void drawPaint(const SkPaint& paint) SK_OVERRIDE; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 42 | virtual void drawPoints(PointMode, size_t count, const SkPoint pts[], |
reed@google.com | 2d4297c | 2011-10-06 13:14:12 +0000 | [diff] [blame] | 43 | const SkPaint&) SK_OVERRIDE; |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 44 | virtual void drawOval(const SkRect&, const SkPaint&) SK_OVERRIDE; |
bsalomon@google.com | 7ce564c | 2013-10-22 16:54:15 +0000 | [diff] [blame] | 45 | virtual void drawRect(const SkRect&, const SkPaint&) SK_OVERRIDE; |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 46 | virtual void drawRRect(const SkRRect&, const SkPaint&) SK_OVERRIDE; |
bsalomon@google.com | 7ce564c | 2013-10-22 16:54:15 +0000 | [diff] [blame] | 47 | virtual void drawPath(const SkPath& path, const SkPaint&) SK_OVERRIDE; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 48 | virtual void drawBitmap(const SkBitmap&, SkScalar left, SkScalar top, |
reed@google.com | 2d4297c | 2011-10-06 13:14:12 +0000 | [diff] [blame] | 49 | const SkPaint*) SK_OVERRIDE; |
reed@google.com | 7112173 | 2012-09-18 15:14:33 +0000 | [diff] [blame] | 50 | virtual void drawBitmapRectToRect(const SkBitmap&, const SkRect* src, |
skia.committer@gmail.com | 7475811 | 2013-08-17 07:01:54 +0000 | [diff] [blame] | 51 | const SkRect& dst, const SkPaint* paint, |
commit-bot@chromium.org | eed779d | 2013-08-16 10:24:37 +0000 | [diff] [blame] | 52 | DrawBitmapRectFlags flags) SK_OVERRIDE; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 53 | virtual void drawBitmapMatrix(const SkBitmap&, const SkMatrix&, |
reed@google.com | 2d4297c | 2011-10-06 13:14:12 +0000 | [diff] [blame] | 54 | const SkPaint*) SK_OVERRIDE; |
reed@google.com | f0b5e11 | 2011-09-07 11:57:34 +0000 | [diff] [blame] | 55 | virtual void drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, |
reed@google.com | 2d4297c | 2011-10-06 13:14:12 +0000 | [diff] [blame] | 56 | const SkRect& dst, const SkPaint*) SK_OVERRIDE; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 57 | virtual void drawSprite(const SkBitmap&, int left, int top, |
reed@google.com | 2d4297c | 2011-10-06 13:14:12 +0000 | [diff] [blame] | 58 | const SkPaint*) SK_OVERRIDE; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 59 | virtual void drawVertices(VertexMode, int vertexCount, |
| 60 | const SkPoint vertices[], const SkPoint texs[], |
| 61 | const SkColor colors[], SkXfermode*, |
| 62 | const uint16_t indices[], int indexCount, |
reed@google.com | 2d4297c | 2011-10-06 13:14:12 +0000 | [diff] [blame] | 63 | const SkPaint&) SK_OVERRIDE; |
| 64 | virtual void drawData(const void*, size_t) SK_OVERRIDE; |
robertphillips@google.com | 0a4805e | 2013-05-29 13:24:23 +0000 | [diff] [blame] | 65 | virtual void beginCommentGroup(const char* description) SK_OVERRIDE; |
| 66 | virtual void addComment(const char* kywd, const char* value) SK_OVERRIDE; |
| 67 | virtual void endCommentGroup() SK_OVERRIDE; |
junov@chromium.org | 8f9ecbd | 2012-02-13 21:53:45 +0000 | [diff] [blame] | 68 | virtual bool isDrawingToLayer() const SK_OVERRIDE; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 69 | |
junov@chromium.org | 3f5ecd6 | 2013-01-22 18:01:26 +0000 | [diff] [blame] | 70 | void addFontMetricsTopBottom(const SkPaint& paint, const SkFlatData&, |
reed@google.com | 4595426 | 2012-12-07 17:14:40 +0000 | [diff] [blame] | 71 | SkScalar minY, SkScalar maxY); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 72 | |
robertphillips | 9b14f26 | 2014-06-04 05:40:44 -0700 | [diff] [blame] | 73 | const SkTDArray<const SkPicture* >& getPictureRefs() const { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 74 | return fPictureRefs; |
| 75 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 76 | |
robertphillips | 0bdbea7 | 2014-06-11 11:37:55 -0700 | [diff] [blame] | 77 | SkData* opData(bool deepCopy) const { |
| 78 | this->validate(fWriter.bytesWritten(), 0); |
| 79 | |
| 80 | if (fWriter.bytesWritten() == 0) { |
| 81 | return SkData::NewEmpty(); |
| 82 | } |
| 83 | |
| 84 | if (deepCopy) { |
| 85 | return SkData::NewWithCopy(fWriter.contiguousArray(), fWriter.bytesWritten()); |
| 86 | } |
| 87 | |
| 88 | return fWriter.snapshotAsData(); |
| 89 | } |
| 90 | |
robertphillips | e26e65e | 2014-06-12 05:51:22 -0700 | [diff] [blame] | 91 | const SkPathHeap* pathHeap() const { |
| 92 | return fPathHeap.get(); |
robertphillips | 0bdbea7 | 2014-06-11 11:37:55 -0700 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | const SkPictureContentInfo& contentInfo() const { |
| 96 | return fContentInfo; |
| 97 | } |
| 98 | |
junov@chromium.org | 4866cc0 | 2012-06-01 21:23:07 +0000 | [diff] [blame] | 99 | void setFlags(uint32_t recordFlags) { |
| 100 | fRecordFlags = recordFlags; |
| 101 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 102 | |
| 103 | const SkWriter32& writeStream() const { |
| 104 | return fWriter; |
| 105 | } |
| 106 | |
reed@google.com | d86e7ab | 2012-09-27 20:31:31 +0000 | [diff] [blame] | 107 | void beginRecording(); |
junov@chromium.org | a6c9e0e | 2012-07-12 17:47:34 +0000 | [diff] [blame] | 108 | void endRecording(); |
reed@google.com | d86e7ab | 2012-09-27 20:31:31 +0000 | [diff] [blame] | 109 | |
commit-bot@chromium.org | e494dbd | 2014-03-04 19:08:57 +0000 | [diff] [blame] | 110 | void internalOnly_EnableOpts(bool optsEnabled) { |
| 111 | fOptsEnabled = optsEnabled; |
| 112 | } |
| 113 | |
senorblanco@chromium.org | 68250c8 | 2014-05-06 22:52:55 +0000 | [diff] [blame] | 114 | protected: |
| 115 | void addNoOp(); |
| 116 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 117 | private: |
commit-bot@chromium.org | 4b32bd5 | 2013-03-15 15:06:03 +0000 | [diff] [blame] | 118 | void handleOptimization(int opt); |
commit-bot@chromium.org | dcecb16 | 2014-04-22 17:54:29 +0000 | [diff] [blame] | 119 | size_t recordRestoreOffsetPlaceholder(SkRegion::Op); |
robertphillips@google.com | 5a63f24 | 2014-02-04 20:07:50 +0000 | [diff] [blame] | 120 | void fillRestoreOffsetPlaceholdersForCurrentStackLevel(uint32_t restoreOffset); |
junov@chromium.org | e3dbedb | 2012-07-09 16:03:55 +0000 | [diff] [blame] | 121 | |
robertphillips@google.com | 105a4a5 | 2014-02-11 15:10:40 +0000 | [diff] [blame] | 122 | #ifndef SK_COLLAPSE_MATRIX_CLIP_STATE |
reed@google.com | ffacd3c | 2012-08-30 15:31:23 +0000 | [diff] [blame] | 123 | SkTDArray<int32_t> fRestoreOffsetStack; |
junov@chromium.org | 8f9ecbd | 2012-02-13 21:53:45 +0000 | [diff] [blame] | 124 | int fFirstSavedLayerIndex; |
| 125 | enum { |
| 126 | kNoSavedLayerIndex = -1 |
| 127 | }; |
robertphillips@google.com | 105a4a5 | 2014-02-11 15:10:40 +0000 | [diff] [blame] | 128 | #endif |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 129 | |
commit-bot@chromium.org | 210ae2a | 2014-02-27 17:40:13 +0000 | [diff] [blame] | 130 | SkTDArray<uint32_t> fCullOffsetStack; |
| 131 | |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 132 | /* |
| 133 | * Write the 'drawType' operation and chunk size to the skp. 'size' |
skia.committer@gmail.com | ce8343d | 2013-02-16 07:01:31 +0000 | [diff] [blame] | 134 | * can potentially be increased if the chunk size needs its own storage |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 135 | * location (i.e., it overflows 24 bits). |
| 136 | * Returns the start offset of the chunk. This is the location at which |
| 137 | * the opcode & size are stored. |
skia.committer@gmail.com | ce8343d | 2013-02-16 07:01:31 +0000 | [diff] [blame] | 138 | * TODO: since we are handing the size into here we could call reserve |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 139 | * and then return a pointer to the memory storage. This could decrease |
| 140 | * allocation overhead but could lead to more wasted space (the tail |
| 141 | * end of blocks could go unused). Possibly add a second addDraw that |
| 142 | * operates in this manner. |
| 143 | */ |
commit-bot@chromium.org | dcecb16 | 2014-04-22 17:54:29 +0000 | [diff] [blame] | 144 | size_t addDraw(DrawType drawType, size_t* size) { |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 145 | size_t offset = fWriter.bytesWritten(); |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 146 | |
reed@google.com | 97af1a6 | 2012-08-28 12:19:02 +0000 | [diff] [blame] | 147 | this->predrawNotify(); |
| 148 | |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 149 | #ifdef SK_DEBUG_TRACE |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 150 | SkDebugf("add %s\n", DrawTypeToString(drawType)); |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 151 | #endif |
| 152 | |
| 153 | SkASSERT(0 != *size); |
| 154 | SkASSERT(((uint8_t) drawType) == drawType); |
| 155 | |
| 156 | if (0 != (*size & ~MASK_24) || *size == MASK_24) { |
| 157 | fWriter.writeInt(PACK_8_24(drawType, MASK_24)); |
| 158 | *size += 1; |
commit-bot@chromium.org | dcecb16 | 2014-04-22 17:54:29 +0000 | [diff] [blame] | 159 | fWriter.writeInt(SkToU32(*size)); |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 160 | } else { |
commit-bot@chromium.org | dcecb16 | 2014-04-22 17:54:29 +0000 | [diff] [blame] | 161 | fWriter.writeInt(PACK_8_24(drawType, SkToU32(*size))); |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | return offset; |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 165 | } |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 166 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 167 | void addInt(int value) { |
| 168 | fWriter.writeInt(value); |
| 169 | } |
| 170 | void addScalar(SkScalar scalar) { |
| 171 | fWriter.writeScalar(scalar); |
| 172 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 173 | |
commit-bot@chromium.org | 8016f79 | 2014-03-07 15:53:01 +0000 | [diff] [blame] | 174 | // The command at 'offset' in the skp uses the specified bitmap |
commit-bot@chromium.org | 8016f79 | 2014-03-07 15:53:01 +0000 | [diff] [blame] | 175 | int addBitmap(const SkBitmap& bitmap); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 176 | void addMatrix(const SkMatrix& matrix); |
junov@chromium.org | f3b1223 | 2013-01-22 17:50:47 +0000 | [diff] [blame] | 177 | const SkFlatData* addPaint(const SkPaint& paint) { return this->addPaintPtr(&paint); } |
| 178 | const SkFlatData* addPaintPtr(const SkPaint* paint); |
commit-bot@chromium.org | cf7be95 | 2013-08-22 17:19:52 +0000 | [diff] [blame] | 179 | void addFlatPaint(const SkFlatData* flatPaint); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 180 | void addPath(const SkPath& path); |
robertphillips | 9b14f26 | 2014-06-04 05:40:44 -0700 | [diff] [blame] | 181 | void addPicture(const SkPicture* picture); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 182 | void addPoint(const SkPoint& point); |
| 183 | void addPoints(const SkPoint pts[], int count); |
| 184 | void addRect(const SkRect& rect); |
| 185 | void addRectPtr(const SkRect* rect); |
reed@google.com | f0b5e11 | 2011-09-07 11:57:34 +0000 | [diff] [blame] | 186 | void addIRect(const SkIRect& rect); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 187 | void addIRectPtr(const SkIRect* rect); |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 188 | void addRRect(const SkRRect&); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 189 | void addRegion(const SkRegion& region); |
| 190 | void addText(const void* text, size_t byteLength); |
| 191 | |
junov@chromium.org | 4866cc0 | 2012-06-01 21:23:07 +0000 | [diff] [blame] | 192 | int find(const SkBitmap& bitmap); |
| 193 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 194 | #ifdef SK_DEBUG_DUMP |
| 195 | public: |
| 196 | void dumpMatrices(); |
| 197 | void dumpPaints(); |
| 198 | #endif |
| 199 | |
| 200 | #ifdef SK_DEBUG_SIZE |
| 201 | public: |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 202 | size_t size() const; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 203 | int bitmaps(size_t* size) const; |
| 204 | int matrices(size_t* size) const; |
| 205 | int paints(size_t* size) const; |
| 206 | int paths(size_t* size) const; |
| 207 | int regions(size_t* size) const; |
| 208 | size_t streamlen() const; |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 209 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 210 | size_t fPointBytes, fRectBytes, fTextBytes; |
| 211 | int fPointWrites, fRectWrites, fTextWrites; |
| 212 | #endif |
| 213 | |
| 214 | #ifdef SK_DEBUG_VALIDATE |
| 215 | public: |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 216 | void validate(size_t initialOffset, uint32_t size) const; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 217 | private: |
| 218 | void validateBitmaps() const; |
| 219 | void validateMatrices() const; |
| 220 | void validatePaints() const; |
| 221 | void validatePaths() const; |
| 222 | void validateRegions() const; |
| 223 | #else |
| 224 | public: |
commit-bot@chromium.org | dcecb16 | 2014-04-22 17:54:29 +0000 | [diff] [blame] | 225 | void validate(size_t initialOffset, size_t size) const { |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 226 | SkASSERT(fWriter.bytesWritten() == initialOffset + size); |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 227 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 228 | #endif |
| 229 | |
rileya@google.com | 9f5898d | 2012-09-11 20:21:44 +0000 | [diff] [blame] | 230 | protected: |
reed@google.com | 76f10a3 | 2014-02-05 15:32:21 +0000 | [diff] [blame] | 231 | virtual SkSurface* onNewSurface(const SkImageInfo&) SK_OVERRIDE; |
commit-bot@chromium.org | c3bd8af | 2014-02-13 17:14:46 +0000 | [diff] [blame] | 232 | const void* onPeekPixels(SkImageInfo*, size_t*) SK_OVERRIDE { |
| 233 | return NULL; |
| 234 | } |
commit-bot@chromium.org | e54a23f | 2014-03-12 20:21:48 +0000 | [diff] [blame] | 235 | |
Florin Malita | 5f6102d | 2014-06-30 10:13:28 -0400 | [diff] [blame] | 236 | virtual void willSave() SK_OVERRIDE; |
commit-bot@chromium.org | e54a23f | 2014-03-12 20:21:48 +0000 | [diff] [blame] | 237 | virtual SaveLayerStrategy willSaveLayer(const SkRect*, const SkPaint*, SaveFlags) SK_OVERRIDE; |
| 238 | virtual void willRestore() SK_OVERRIDE; |
| 239 | |
commit-bot@chromium.org | 44c48d0 | 2014-03-13 20:03:58 +0000 | [diff] [blame] | 240 | virtual void didConcat(const SkMatrix&) SK_OVERRIDE; |
| 241 | virtual void didSetMatrix(const SkMatrix&) SK_OVERRIDE; |
| 242 | |
commit-bot@chromium.org | ed9806f | 2014-02-21 02:32:36 +0000 | [diff] [blame] | 243 | virtual void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) SK_OVERRIDE; |
commit-bot@chromium.org | 210ae2a | 2014-02-27 17:40:13 +0000 | [diff] [blame] | 244 | virtual void onPushCull(const SkRect&) SK_OVERRIDE; |
| 245 | virtual void onPopCull() SK_OVERRIDE; |
reed@google.com | 76f10a3 | 2014-02-05 15:32:21 +0000 | [diff] [blame] | 246 | |
reed@google.com | e0d9ce8 | 2014-04-23 04:00:17 +0000 | [diff] [blame] | 247 | virtual void onDrawText(const void* text, size_t byteLength, SkScalar x, SkScalar y, |
| 248 | const SkPaint&) SK_OVERRIDE; |
| 249 | virtual void onDrawPosText(const void* text, size_t byteLength, const SkPoint pos[], |
| 250 | const SkPaint&) SK_OVERRIDE; |
| 251 | virtual void onDrawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[], |
| 252 | SkScalar constY, const SkPaint&) SK_OVERRIDE; |
| 253 | virtual void onDrawTextOnPath(const void* text, size_t byteLength, const SkPath& path, |
| 254 | const SkMatrix* matrix, const SkPaint&) SK_OVERRIDE; |
| 255 | |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame] | 256 | virtual void onClipRect(const SkRect&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE; |
| 257 | virtual void onClipRRect(const SkRRect&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE; |
| 258 | virtual void onClipPath(const SkPath&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE; |
| 259 | virtual void onClipRegion(const SkRegion&, SkRegion::Op) SK_OVERRIDE; |
| 260 | |
robertphillips | 9b14f26 | 2014-06-04 05:40:44 -0700 | [diff] [blame] | 261 | virtual void onDrawPicture(const SkPicture* picture) SK_OVERRIDE; |
| 262 | |
commit-bot@chromium.org | cf7be95 | 2013-08-22 17:19:52 +0000 | [diff] [blame] | 263 | // Return fontmetrics.fTop,fBottom in topbot[0,1], after they have been |
| 264 | // tweaked by paint.computeFastBounds(). |
| 265 | static void ComputeFontMetricsTopBottom(const SkPaint& paint, SkScalar topbot[2]); |
| 266 | |
| 267 | // Make sure that flat has fTopBot written. |
| 268 | static void WriteTopBot(const SkPaint& paint, const SkFlatData& flat) { |
| 269 | if (!flat.isTopBotWritten()) { |
| 270 | ComputeFontMetricsTopBottom(paint, flat.writableTopBot()); |
| 271 | SkASSERT(flat.isTopBotWritten()); |
| 272 | } |
| 273 | } |
| 274 | // Will return a cached version when possible. |
| 275 | const SkFlatData* getFlatPaintData(const SkPaint& paint); |
| 276 | /** |
| 277 | * SkBBoxRecord::drawPosTextH gets a flat paint and uses it, |
| 278 | * then it calls this, using the extra parameter, to avoid duplication. |
| 279 | */ |
| 280 | void drawPosTextHImpl(const void* text, size_t byteLength, |
| 281 | const SkScalar xpos[], SkScalar constY, |
| 282 | const SkPaint& paint, const SkFlatData* flatPaintData); |
rileya@google.com | 9f5898d | 2012-09-11 20:21:44 +0000 | [diff] [blame] | 283 | |
robertphillips@google.com | 5a63f24 | 2014-02-04 20:07:50 +0000 | [diff] [blame] | 284 | int addPathToHeap(const SkPath& path); // does not write to ops stream |
| 285 | |
skia.committer@gmail.com | 1dab403 | 2014-02-05 03:01:48 +0000 | [diff] [blame] | 286 | // These entry points allow the writing of matrices, clips, saves & |
robertphillips@google.com | 5a63f24 | 2014-02-04 20:07:50 +0000 | [diff] [blame] | 287 | // restores to be deferred (e.g., if the MC state is being collapsed and |
| 288 | // only written out as needed). |
| 289 | void recordConcat(const SkMatrix& matrix); |
commit-bot@chromium.org | d9ea09e | 2014-03-25 17:32:26 +0000 | [diff] [blame] | 290 | void recordTranslate(const SkMatrix& matrix); |
| 291 | void recordScale(const SkMatrix& matrix); |
commit-bot@chromium.org | dcecb16 | 2014-04-22 17:54:29 +0000 | [diff] [blame] | 292 | size_t recordClipRect(const SkRect& rect, SkRegion::Op op, bool doAA); |
| 293 | size_t recordClipRRect(const SkRRect& rrect, SkRegion::Op op, bool doAA); |
| 294 | size_t recordClipPath(int pathID, SkRegion::Op op, bool doAA); |
| 295 | size_t recordClipRegion(const SkRegion& region, SkRegion::Op op); |
Florin Malita | 5f6102d | 2014-06-30 10:13:28 -0400 | [diff] [blame] | 296 | void recordSave(); |
robertphillips@google.com | 5a63f24 | 2014-02-04 20:07:50 +0000 | [diff] [blame] | 297 | void recordSaveLayer(const SkRect* bounds, const SkPaint* paint, SaveFlags flags); |
robertphillips@google.com | 105a4a5 | 2014-02-11 15:10:40 +0000 | [diff] [blame] | 298 | void recordRestore(bool fillInSkips = true); |
robertphillips@google.com | 5a63f24 | 2014-02-04 20:07:50 +0000 | [diff] [blame] | 299 | |
rileya@google.com | 9f5898d | 2012-09-11 20:21:44 +0000 | [diff] [blame] | 300 | // These are set to NULL in our constructor, but may be changed by |
| 301 | // subclasses, in which case they will be SkSafeUnref'd in our destructor. |
| 302 | SkBBoxHierarchy* fBoundingHierarchy; |
| 303 | SkPictureStateTree* fStateTree; |
| 304 | |
robertphillips@google.com | 801cee1 | 2012-10-19 19:06:11 +0000 | [diff] [blame] | 305 | // Allocated in the constructor and managed by this class. |
djsollen@google.com | c9ab987 | 2012-08-29 18:52:07 +0000 | [diff] [blame] | 306 | SkBitmapHeap* fBitmapHeap; |
robertphillips@google.com | 801cee1 | 2012-10-19 19:06:11 +0000 | [diff] [blame] | 307 | |
| 308 | private: |
robertphillips@google.com | 105a4a5 | 2014-02-11 15:10:40 +0000 | [diff] [blame] | 309 | friend class MatrixClipState; // for access to *Impl methods |
| 310 | friend class SkMatrixClipStateMgr; // for access to *Impl methods |
| 311 | |
robertphillips | 0bdbea7 | 2014-06-11 11:37:55 -0700 | [diff] [blame] | 312 | SkPictureContentInfo fContentInfo; |
| 313 | SkAutoTUnref<SkPathHeap> fPathHeap; |
| 314 | |
djsollen@google.com | 21830d9 | 2012-08-07 19:49:41 +0000 | [diff] [blame] | 315 | SkChunkFlatController fFlattenableHeap; |
junov@chromium.org | 4866cc0 | 2012-06-01 21:23:07 +0000 | [diff] [blame] | 316 | |
djsollen@google.com | d2700ee | 2012-05-30 16:54:13 +0000 | [diff] [blame] | 317 | SkPaintDictionary fPaints; |
djsollen@google.com | d2700ee | 2012-05-30 16:54:13 +0000 | [diff] [blame] | 318 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 319 | SkWriter32 fWriter; |
| 320 | |
reed@android.com | 09b84a0 | 2009-06-26 20:22:26 +0000 | [diff] [blame] | 321 | // we ref each item in these arrays |
robertphillips | 9b14f26 | 2014-06-04 05:40:44 -0700 | [diff] [blame] | 322 | SkTDArray<const SkPicture*> fPictureRefs; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 323 | |
reed@android.com | ae814c8 | 2009-02-13 14:56:09 +0000 | [diff] [blame] | 324 | uint32_t fRecordFlags; |
commit-bot@chromium.org | e494dbd | 2014-03-04 19:08:57 +0000 | [diff] [blame] | 325 | bool fOptsEnabled; |
| 326 | int fInitialSaveCount; |
reed@android.com | ae814c8 | 2009-02-13 14:56:09 +0000 | [diff] [blame] | 327 | |
robertphillips | 6142609 | 2014-07-10 09:35:12 -0700 | [diff] [blame^] | 328 | friend class SkPictureData; // for SkPictureData's SkPictureRecord-based constructor |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 329 | friend class SkPictureTester; // for unit testing |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 330 | |
robertphillips@google.com | 105a4a5 | 2014-02-11 15:10:40 +0000 | [diff] [blame] | 331 | #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE |
| 332 | SkMatrixClipStateMgr fMCMgr; |
| 333 | #endif |
| 334 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 335 | typedef SkCanvas INHERITED; |
| 336 | }; |
| 337 | |
| 338 | #endif |