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 | #include "SkPictureRecord.h" |
junov@chromium.org | d575eed | 2013-05-08 15:39:13 +0000 | [diff] [blame] | 9 | #include "SkDevice.h" |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 10 | #include "SkPatchUtils.h" |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 11 | #include "SkPixelRef.h" |
| 12 | #include "SkRRect.h" |
fmalita | b742517 | 2014-08-26 07:56:44 -0700 | [diff] [blame] | 13 | #include "SkTextBlob.h" |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 14 | #include "SkTSearch.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 15 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 16 | #define HEAP_BLOCK_SIZE 4096 |
| 17 | |
junov@chromium.org | 4e6dfa5 | 2012-07-16 14:04:59 +0000 | [diff] [blame] | 18 | enum { |
reed@google.com | d86e7ab | 2012-09-27 20:31:31 +0000 | [diff] [blame] | 19 | // just need a value that save or getSaveCount would never return |
junov@chromium.org | 4e6dfa5 | 2012-07-16 14:04:59 +0000 | [diff] [blame] | 20 | kNoInitialSave = -1, |
| 21 | }; |
| 22 | |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 23 | // A lot of basic types get stored as a uint32_t: bools, ints, paint indices, etc. |
| 24 | static int const kUInt32Size = 4; |
| 25 | |
Florin Malita | 5f6102d | 2014-06-30 10:13:28 -0400 | [diff] [blame] | 26 | static const uint32_t kSaveSize = kUInt32Size; |
robertphillips@google.com | e37ad35 | 2013-03-01 19:44:30 +0000 | [diff] [blame] | 27 | static const uint32_t kSaveLayerNoBoundsSize = 4 * kUInt32Size; |
| 28 | static const uint32_t kSaveLayerWithBoundsSize = 4 * kUInt32Size + sizeof(SkRect); |
| 29 | |
robertphillips | 0bdbea7 | 2014-06-11 11:37:55 -0700 | [diff] [blame] | 30 | SkPictureRecord::SkPictureRecord(const SkISize& dimensions, uint32_t flags) |
commit-bot@chromium.org | 19fafef | 2014-02-17 15:28:00 +0000 | [diff] [blame] | 31 | : INHERITED(dimensions.width(), dimensions.height()) |
robertphillips@google.com | 5a63f24 | 2014-02-04 20:07:50 +0000 | [diff] [blame] | 32 | , fFlattenableHeap(HEAP_BLOCK_SIZE) |
| 33 | , fPaints(&fFlattenableHeap) |
mtklein | 46616af | 2014-09-30 14:47:10 -0700 | [diff] [blame^] | 34 | , fRecordFlags(flags) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 35 | |
djsollen@google.com | c9ab987 | 2012-08-29 18:52:07 +0000 | [diff] [blame] | 36 | fBitmapHeap = SkNEW(SkBitmapHeap); |
| 37 | fFlattenableHeap.setBitmapStorage(fBitmapHeap); |
commit-bot@chromium.org | 8016f79 | 2014-03-07 15:53:01 +0000 | [diff] [blame] | 38 | |
junov@chromium.org | 8f9ecbd | 2012-02-13 21:53:45 +0000 | [diff] [blame] | 39 | fFirstSavedLayerIndex = kNoSavedLayerIndex; |
reed@google.com | d86e7ab | 2012-09-27 20:31:31 +0000 | [diff] [blame] | 40 | fInitialSaveCount = kNoInitialSave; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | SkPictureRecord::~SkPictureRecord() { |
djsollen@google.com | c9ab987 | 2012-08-29 18:52:07 +0000 | [diff] [blame] | 44 | SkSafeUnref(fBitmapHeap); |
djsollen@google.com | 21830d9 | 2012-08-07 19:49:41 +0000 | [diff] [blame] | 45 | fFlattenableHeap.setBitmapStorage(NULL); |
| 46 | fPictureRefs.unrefAll(); |
fmalita | b742517 | 2014-08-26 07:56:44 -0700 | [diff] [blame] | 47 | fTextBlobRefs.unrefAll(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | /////////////////////////////////////////////////////////////////////////////// |
| 51 | |
robertphillips@google.com | e37ad35 | 2013-03-01 19:44:30 +0000 | [diff] [blame] | 52 | // Return the offset of the paint inside a given op's byte stream. A zero |
| 53 | // return value means there is no paint (and you really shouldn't be calling |
| 54 | // this method) |
commit-bot@chromium.org | dcecb16 | 2014-04-22 17:54:29 +0000 | [diff] [blame] | 55 | static inline size_t getPaintOffset(DrawType op, size_t opSize) { |
robertphillips@google.com | e37ad35 | 2013-03-01 19:44:30 +0000 | [diff] [blame] | 56 | // These offsets are where the paint would be if the op size doesn't overflow |
fmalita | 9f49cfd | 2014-08-12 12:24:17 -0700 | [diff] [blame] | 57 | static const uint8_t gPaintOffsets[] = { |
robertphillips@google.com | e37ad35 | 2013-03-01 19:44:30 +0000 | [diff] [blame] | 58 | 0, // UNUSED - no paint |
| 59 | 0, // CLIP_PATH - no paint |
| 60 | 0, // CLIP_REGION - no paint |
| 61 | 0, // CLIP_RECT - no paint |
| 62 | 0, // CLIP_RRECT - no paint |
| 63 | 0, // CONCAT - no paint |
| 64 | 1, // DRAW_BITMAP - right after op code |
| 65 | 1, // DRAW_BITMAP_MATRIX - right after op code |
| 66 | 1, // DRAW_BITMAP_NINE - right after op code |
| 67 | 1, // DRAW_BITMAP_RECT_TO_RECT - right after op code |
| 68 | 0, // DRAW_CLEAR - no paint |
| 69 | 0, // DRAW_DATA - no paint |
| 70 | 1, // DRAW_OVAL - right after op code |
| 71 | 1, // DRAW_PAINT - right after op code |
| 72 | 1, // DRAW_PATH - right after op code |
| 73 | 0, // DRAW_PICTURE - no paint |
| 74 | 1, // DRAW_POINTS - right after op code |
| 75 | 1, // DRAW_POS_TEXT - right after op code |
| 76 | 1, // DRAW_POS_TEXT_TOP_BOTTOM - right after op code |
| 77 | 1, // DRAW_POS_TEXT_H - right after op code |
| 78 | 1, // DRAW_POS_TEXT_H_TOP_BOTTOM - right after op code |
| 79 | 1, // DRAW_RECT - right after op code |
| 80 | 1, // DRAW_RRECT - right after op code |
| 81 | 1, // DRAW_SPRITE - right after op code |
| 82 | 1, // DRAW_TEXT - right after op code |
| 83 | 1, // DRAW_TEXT_ON_PATH - right after op code |
| 84 | 1, // DRAW_TEXT_TOP_BOTTOM - right after op code |
| 85 | 1, // DRAW_VERTICES - right after op code |
| 86 | 0, // RESTORE - no paint |
| 87 | 0, // ROTATE - no paint |
| 88 | 0, // SAVE - no paint |
skia.committer@gmail.com | f140f18 | 2013-03-02 07:01:56 +0000 | [diff] [blame] | 89 | 0, // SAVE_LAYER - see below - this paint's location varies |
robertphillips@google.com | e37ad35 | 2013-03-01 19:44:30 +0000 | [diff] [blame] | 90 | 0, // SCALE - no paint |
| 91 | 0, // SET_MATRIX - no paint |
| 92 | 0, // SKEW - no paint |
| 93 | 0, // TRANSLATE - no paint |
| 94 | 0, // NOOP - no paint |
robertphillips@google.com | 0a4805e | 2013-05-29 13:24:23 +0000 | [diff] [blame] | 95 | 0, // BEGIN_GROUP - no paint |
| 96 | 0, // COMMENT - no paint |
| 97 | 0, // END_GROUP - no paint |
commit-bot@chromium.org | ed9806f | 2014-02-21 02:32:36 +0000 | [diff] [blame] | 98 | 1, // DRAWDRRECT - right after op code |
commit-bot@chromium.org | 210ae2a | 2014-02-27 17:40:13 +0000 | [diff] [blame] | 99 | 0, // PUSH_CULL - no paint |
| 100 | 0, // POP_CULL - no paint |
dandov | 963137b | 2014-08-07 07:49:53 -0700 | [diff] [blame] | 101 | 1, // DRAW_PATCH - right after op code |
fmalita | 9f49cfd | 2014-08-12 12:24:17 -0700 | [diff] [blame] | 102 | 1, // DRAW_PICTURE_MATRIX_PAINT - right after op code |
fmalita | b742517 | 2014-08-26 07:56:44 -0700 | [diff] [blame] | 103 | 1, // DRAW_TEXT_BLOB- right after op code |
skia.committer@gmail.com | f140f18 | 2013-03-02 07:01:56 +0000 | [diff] [blame] | 104 | }; |
robertphillips@google.com | e37ad35 | 2013-03-01 19:44:30 +0000 | [diff] [blame] | 105 | |
commit-bot@chromium.org | ed9806f | 2014-02-21 02:32:36 +0000 | [diff] [blame] | 106 | SK_COMPILE_ASSERT(sizeof(gPaintOffsets) == LAST_DRAWTYPE_ENUM + 1, |
| 107 | need_to_be_in_sync); |
robertphillips@google.com | e37ad35 | 2013-03-01 19:44:30 +0000 | [diff] [blame] | 108 | SkASSERT((unsigned)op <= (unsigned)LAST_DRAWTYPE_ENUM); |
| 109 | |
| 110 | int overflow = 0; |
| 111 | if (0 != (opSize & ~MASK_24) || opSize == MASK_24) { |
| 112 | // This op's size overflows so an extra uint32_t will be written |
| 113 | // after the op code |
| 114 | overflow = sizeof(uint32_t); |
| 115 | } |
| 116 | |
| 117 | if (SAVE_LAYER == op) { |
| 118 | static const uint32_t kSaveLayerNoBoundsPaintOffset = 2 * kUInt32Size; |
| 119 | static const uint32_t kSaveLayerWithBoundsPaintOffset = 2 * kUInt32Size + sizeof(SkRect); |
| 120 | |
| 121 | if (kSaveLayerNoBoundsSize == opSize) { |
| 122 | return kSaveLayerNoBoundsPaintOffset + overflow; |
| 123 | } else { |
| 124 | SkASSERT(kSaveLayerWithBoundsSize == opSize); |
| 125 | return kSaveLayerWithBoundsPaintOffset + overflow; |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | SkASSERT(0 != gPaintOffsets[op]); // really shouldn't be calling this method |
| 130 | return gPaintOffsets[op] * sizeof(uint32_t) + overflow; |
| 131 | } |
| 132 | |
Florin Malita | 5f6102d | 2014-06-30 10:13:28 -0400 | [diff] [blame] | 133 | void SkPictureRecord::willSave() { |
reed@google.com | ffacd3c | 2012-08-30 15:31:23 +0000 | [diff] [blame] | 134 | // record the offset to us, making it non-positive to distinguish a save |
| 135 | // from a clip entry. |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 136 | fRestoreOffsetStack.push(-(int32_t)fWriter.bytesWritten()); |
Florin Malita | 5f6102d | 2014-06-30 10:13:28 -0400 | [diff] [blame] | 137 | this->recordSave(); |
commit-bot@chromium.org | e54a23f | 2014-03-12 20:21:48 +0000 | [diff] [blame] | 138 | |
Florin Malita | 5f6102d | 2014-06-30 10:13:28 -0400 | [diff] [blame] | 139 | this->INHERITED::willSave(); |
robertphillips@google.com | 5a63f24 | 2014-02-04 20:07:50 +0000 | [diff] [blame] | 140 | } |
skia.committer@gmail.com | 11f8692 | 2012-08-31 17:14:46 +0000 | [diff] [blame] | 141 | |
Florin Malita | 5f6102d | 2014-06-30 10:13:28 -0400 | [diff] [blame] | 142 | void SkPictureRecord::recordSave() { |
robertphillips | c019ec4 | 2014-08-12 05:35:58 -0700 | [diff] [blame] | 143 | fContentInfo.onSave(); |
| 144 | |
Florin Malita | 5f6102d | 2014-06-30 10:13:28 -0400 | [diff] [blame] | 145 | // op only |
commit-bot@chromium.org | dcecb16 | 2014-04-22 17:54:29 +0000 | [diff] [blame] | 146 | size_t size = kSaveSize; |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 147 | size_t initialOffset = this->addDraw(SAVE, &size); |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 148 | |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 149 | this->validate(initialOffset, size); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 150 | } |
| 151 | |
commit-bot@chromium.org | e54a23f | 2014-03-12 20:21:48 +0000 | [diff] [blame] | 152 | SkCanvas::SaveLayerStrategy SkPictureRecord::willSaveLayer(const SkRect* bounds, |
| 153 | const SkPaint* paint, SaveFlags flags) { |
reed@google.com | ffacd3c | 2012-08-30 15:31:23 +0000 | [diff] [blame] | 154 | // record the offset to us, making it non-positive to distinguish a save |
| 155 | // from a clip entry. |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 156 | fRestoreOffsetStack.push(-(int32_t)fWriter.bytesWritten()); |
robertphillips@google.com | 5a63f24 | 2014-02-04 20:07:50 +0000 | [diff] [blame] | 157 | this->recordSaveLayer(bounds, paint, flags); |
| 158 | if (kNoSavedLayerIndex == fFirstSavedLayerIndex) { |
| 159 | fFirstSavedLayerIndex = fRestoreOffsetStack.count(); |
| 160 | } |
skia.committer@gmail.com | 11f8692 | 2012-08-31 17:14:46 +0000 | [diff] [blame] | 161 | |
commit-bot@chromium.org | e54a23f | 2014-03-12 20:21:48 +0000 | [diff] [blame] | 162 | this->INHERITED::willSaveLayer(bounds, paint, flags); |
| 163 | /* No need for a (potentially very big) layer which we don't actually need |
robertphillips@google.com | 5a63f24 | 2014-02-04 20:07:50 +0000 | [diff] [blame] | 164 | at this time (and may not be able to afford since during record our |
| 165 | clip starts out the size of the picture, which is often much larger |
| 166 | than the size of the actual device we'll use during playback). |
| 167 | */ |
commit-bot@chromium.org | e54a23f | 2014-03-12 20:21:48 +0000 | [diff] [blame] | 168 | return kNoLayer_SaveLayerStrategy; |
robertphillips@google.com | 5a63f24 | 2014-02-04 20:07:50 +0000 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | void SkPictureRecord::recordSaveLayer(const SkRect* bounds, const SkPaint* paint, |
robertphillips@google.com | 105a4a5 | 2014-02-11 15:10:40 +0000 | [diff] [blame] | 172 | SaveFlags flags) { |
robertphillips | c019ec4 | 2014-08-12 05:35:58 -0700 | [diff] [blame] | 173 | fContentInfo.onSaveLayer(); |
| 174 | |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 175 | // op + bool for 'bounds' |
commit-bot@chromium.org | dcecb16 | 2014-04-22 17:54:29 +0000 | [diff] [blame] | 176 | size_t size = 2 * kUInt32Size; |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 177 | if (bounds) { |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 178 | size += sizeof(*bounds); // + rect |
| 179 | } |
| 180 | // + paint index + flags |
| 181 | size += 2 * kUInt32Size; |
| 182 | |
robertphillips@google.com | e37ad35 | 2013-03-01 19:44:30 +0000 | [diff] [blame] | 183 | SkASSERT(kSaveLayerNoBoundsSize == size || kSaveLayerWithBoundsSize == size); |
| 184 | |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 185 | size_t initialOffset = this->addDraw(SAVE_LAYER, &size); |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 186 | this->addRectPtr(bounds); |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 187 | SkASSERT(initialOffset+getPaintOffset(SAVE_LAYER, size) == fWriter.bytesWritten()); |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 188 | this->addPaintPtr(paint); |
| 189 | this->addInt(flags); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 190 | |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 191 | this->validate(initialOffset, size); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 192 | } |
| 193 | |
junov@chromium.org | 8f9ecbd | 2012-02-13 21:53:45 +0000 | [diff] [blame] | 194 | bool SkPictureRecord::isDrawingToLayer() const { |
| 195 | return fFirstSavedLayerIndex != kNoSavedLayerIndex; |
| 196 | } |
| 197 | |
commit-bot@chromium.org | 210ae2a | 2014-02-27 17:40:13 +0000 | [diff] [blame] | 198 | #ifdef SK_DEBUG |
commit-bot@chromium.org | 210ae2a | 2014-02-27 17:40:13 +0000 | [diff] [blame] | 199 | /* |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 200 | * Read the op code from 'offset' in 'writer' and extract the size too. |
| 201 | */ |
commit-bot@chromium.org | dcecb16 | 2014-04-22 17:54:29 +0000 | [diff] [blame] | 202 | static DrawType peek_op_and_size(SkWriter32* writer, size_t offset, uint32_t* size) { |
commit-bot@chromium.org | 536ac5e | 2014-02-11 22:38:51 +0000 | [diff] [blame] | 203 | uint32_t peek = writer->readTAt<uint32_t>(offset); |
reed@google.com | ffacd3c | 2012-08-30 15:31:23 +0000 | [diff] [blame] | 204 | |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 205 | uint32_t op; |
commit-bot@chromium.org | c6d3c44 | 2014-01-31 16:22:57 +0000 | [diff] [blame] | 206 | UNPACK_8_24(peek, op, *size); |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 207 | if (MASK_24 == *size) { |
| 208 | // size required its own slot right after the op code |
commit-bot@chromium.org | 536ac5e | 2014-02-11 22:38:51 +0000 | [diff] [blame] | 209 | *size = writer->readTAt<uint32_t>(offset + kUInt32Size); |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 210 | } |
| 211 | return (DrawType) op; |
reed@google.com | ffacd3c | 2012-08-30 15:31:23 +0000 | [diff] [blame] | 212 | } |
mtklein | 46616af | 2014-09-30 14:47:10 -0700 | [diff] [blame^] | 213 | #endif//SK_DEBUG |
commit-bot@chromium.org | 4b32bd5 | 2013-03-15 15:06:03 +0000 | [diff] [blame] | 214 | |
commit-bot@chromium.org | e54a23f | 2014-03-12 20:21:48 +0000 | [diff] [blame] | 215 | void SkPictureRecord::willRestore() { |
junov@chromium.org | 4e6dfa5 | 2012-07-16 14:04:59 +0000 | [diff] [blame] | 216 | // FIXME: SkDeferredCanvas needs to be refactored to respect |
| 217 | // save/restore balancing so that the following test can be |
| 218 | // turned on permanently. |
| 219 | #if 0 |
| 220 | SkASSERT(fRestoreOffsetStack.count() > 1); |
| 221 | #endif |
| 222 | |
reed@android.com | b4e22d6 | 2009-07-09 15:20:25 +0000 | [diff] [blame] | 223 | // check for underflow |
| 224 | if (fRestoreOffsetStack.count() == 0) { |
| 225 | return; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 226 | } |
reed@android.com | b4e22d6 | 2009-07-09 15:20:25 +0000 | [diff] [blame] | 227 | |
junov@chromium.org | 8f9ecbd | 2012-02-13 21:53:45 +0000 | [diff] [blame] | 228 | if (fRestoreOffsetStack.count() == fFirstSavedLayerIndex) { |
| 229 | fFirstSavedLayerIndex = kNoSavedLayerIndex; |
| 230 | } |
| 231 | |
mtklein | 46616af | 2014-09-30 14:47:10 -0700 | [diff] [blame^] | 232 | this->recordRestore(); |
reed@google.com | ffacd3c | 2012-08-30 15:31:23 +0000 | [diff] [blame] | 233 | |
reed@android.com | b4e22d6 | 2009-07-09 15:20:25 +0000 | [diff] [blame] | 234 | fRestoreOffsetStack.pop(); |
reed@android.com | 32a4249 | 2009-07-10 03:33:52 +0000 | [diff] [blame] | 235 | |
commit-bot@chromium.org | e54a23f | 2014-03-12 20:21:48 +0000 | [diff] [blame] | 236 | this->INHERITED::willRestore(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 237 | } |
| 238 | |
robertphillips@google.com | 105a4a5 | 2014-02-11 15:10:40 +0000 | [diff] [blame] | 239 | void SkPictureRecord::recordRestore(bool fillInSkips) { |
robertphillips | c019ec4 | 2014-08-12 05:35:58 -0700 | [diff] [blame] | 240 | fContentInfo.onRestore(); |
| 241 | |
robertphillips@google.com | 105a4a5 | 2014-02-11 15:10:40 +0000 | [diff] [blame] | 242 | if (fillInSkips) { |
| 243 | this->fillRestoreOffsetPlaceholdersForCurrentStackLevel((uint32_t)fWriter.bytesWritten()); |
| 244 | } |
commit-bot@chromium.org | dcecb16 | 2014-04-22 17:54:29 +0000 | [diff] [blame] | 245 | size_t size = 1 * kUInt32Size; // RESTORE consists solely of 1 op code |
| 246 | size_t initialOffset = this->addDraw(RESTORE, &size); |
robertphillips@google.com | 5a63f24 | 2014-02-04 20:07:50 +0000 | [diff] [blame] | 247 | this->validate(initialOffset, size); |
| 248 | } |
| 249 | |
commit-bot@chromium.org | d9ea09e | 2014-03-25 17:32:26 +0000 | [diff] [blame] | 250 | void SkPictureRecord::recordTranslate(const SkMatrix& m) { |
| 251 | SkASSERT(SkMatrix::kTranslate_Mask == m.getType()); |
| 252 | |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 253 | // op + dx + dy |
commit-bot@chromium.org | dcecb16 | 2014-04-22 17:54:29 +0000 | [diff] [blame] | 254 | size_t size = 1 * kUInt32Size + 2 * sizeof(SkScalar); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 255 | size_t initialOffset = this->addDraw(TRANSLATE, &size); |
commit-bot@chromium.org | d9ea09e | 2014-03-25 17:32:26 +0000 | [diff] [blame] | 256 | this->addScalar(m.getTranslateX()); |
| 257 | this->addScalar(m.getTranslateY()); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 258 | this->validate(initialOffset, size); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 259 | } |
| 260 | |
commit-bot@chromium.org | d9ea09e | 2014-03-25 17:32:26 +0000 | [diff] [blame] | 261 | void SkPictureRecord::recordScale(const SkMatrix& m) { |
| 262 | SkASSERT(SkMatrix::kScale_Mask == m.getType()); |
robertphillips@google.com | 105a4a5 | 2014-02-11 15:10:40 +0000 | [diff] [blame] | 263 | |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 264 | // op + sx + sy |
commit-bot@chromium.org | dcecb16 | 2014-04-22 17:54:29 +0000 | [diff] [blame] | 265 | size_t size = 1 * kUInt32Size + 2 * sizeof(SkScalar); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 266 | size_t initialOffset = this->addDraw(SCALE, &size); |
commit-bot@chromium.org | d9ea09e | 2014-03-25 17:32:26 +0000 | [diff] [blame] | 267 | this->addScalar(m.getScaleX()); |
| 268 | this->addScalar(m.getScaleY()); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 269 | this->validate(initialOffset, size); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 270 | } |
| 271 | |
commit-bot@chromium.org | 44c48d0 | 2014-03-13 20:03:58 +0000 | [diff] [blame] | 272 | void SkPictureRecord::didConcat(const SkMatrix& matrix) { |
commit-bot@chromium.org | d9ea09e | 2014-03-25 17:32:26 +0000 | [diff] [blame] | 273 | switch (matrix.getType()) { |
| 274 | case SkMatrix::kTranslate_Mask: |
| 275 | this->recordTranslate(matrix); |
| 276 | break; |
| 277 | case SkMatrix::kScale_Mask: |
| 278 | this->recordScale(matrix); |
| 279 | break; |
| 280 | default: |
| 281 | this->recordConcat(matrix); |
| 282 | break; |
| 283 | } |
commit-bot@chromium.org | 44c48d0 | 2014-03-13 20:03:58 +0000 | [diff] [blame] | 284 | this->INHERITED::didConcat(matrix); |
robertphillips@google.com | 5a63f24 | 2014-02-04 20:07:50 +0000 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | void SkPictureRecord::recordConcat(const SkMatrix& matrix) { |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 288 | this->validate(fWriter.bytesWritten(), 0); |
commit-bot@chromium.org | fed2ab6 | 2014-01-23 15:16:05 +0000 | [diff] [blame] | 289 | // op + matrix |
commit-bot@chromium.org | dcecb16 | 2014-04-22 17:54:29 +0000 | [diff] [blame] | 290 | size_t size = kUInt32Size + matrix.writeToMemory(NULL); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 291 | size_t initialOffset = this->addDraw(CONCAT, &size); |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 292 | this->addMatrix(matrix); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 293 | this->validate(initialOffset, size); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 294 | } |
| 295 | |
commit-bot@chromium.org | 44c48d0 | 2014-03-13 20:03:58 +0000 | [diff] [blame] | 296 | void SkPictureRecord::didSetMatrix(const SkMatrix& matrix) { |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 297 | this->validate(fWriter.bytesWritten(), 0); |
commit-bot@chromium.org | fed2ab6 | 2014-01-23 15:16:05 +0000 | [diff] [blame] | 298 | // op + matrix |
commit-bot@chromium.org | dcecb16 | 2014-04-22 17:54:29 +0000 | [diff] [blame] | 299 | size_t size = kUInt32Size + matrix.writeToMemory(NULL); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 300 | size_t initialOffset = this->addDraw(SET_MATRIX, &size); |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 301 | this->addMatrix(matrix); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 302 | this->validate(initialOffset, size); |
commit-bot@chromium.org | 44c48d0 | 2014-03-13 20:03:58 +0000 | [diff] [blame] | 303 | this->INHERITED::didSetMatrix(matrix); |
reed@android.com | 6e073b9 | 2009-01-06 15:03:30 +0000 | [diff] [blame] | 304 | } |
| 305 | |
reed@google.com | 45482d1 | 2011-08-29 19:02:39 +0000 | [diff] [blame] | 306 | static bool regionOpExpands(SkRegion::Op op) { |
| 307 | switch (op) { |
| 308 | case SkRegion::kUnion_Op: |
| 309 | case SkRegion::kXOR_Op: |
| 310 | case SkRegion::kReverseDifference_Op: |
| 311 | case SkRegion::kReplace_Op: |
| 312 | return true; |
| 313 | case SkRegion::kIntersect_Op: |
| 314 | case SkRegion::kDifference_Op: |
| 315 | return false; |
| 316 | default: |
tomhudson@google.com | 0c00f21 | 2011-12-28 14:59:50 +0000 | [diff] [blame] | 317 | SkDEBUGFAIL("unknown region op"); |
reed@google.com | 45482d1 | 2011-08-29 19:02:39 +0000 | [diff] [blame] | 318 | return false; |
| 319 | } |
| 320 | } |
| 321 | |
robertphillips@google.com | e37ad35 | 2013-03-01 19:44:30 +0000 | [diff] [blame] | 322 | void SkPictureRecord::fillRestoreOffsetPlaceholdersForCurrentStackLevel(uint32_t restoreOffset) { |
reed@google.com | ffacd3c | 2012-08-30 15:31:23 +0000 | [diff] [blame] | 323 | int32_t offset = fRestoreOffsetStack.top(); |
| 324 | while (offset > 0) { |
commit-bot@chromium.org | 536ac5e | 2014-02-11 22:38:51 +0000 | [diff] [blame] | 325 | uint32_t peek = fWriter.readTAt<uint32_t>(offset); |
| 326 | fWriter.overwriteTAt(offset, restoreOffset); |
commit-bot@chromium.org | c6d3c44 | 2014-01-31 16:22:57 +0000 | [diff] [blame] | 327 | offset = peek; |
junov@chromium.org | e3dbedb | 2012-07-09 16:03:55 +0000 | [diff] [blame] | 328 | } |
skia.committer@gmail.com | 11f8692 | 2012-08-31 17:14:46 +0000 | [diff] [blame] | 329 | |
reed@google.com | ffacd3c | 2012-08-30 15:31:23 +0000 | [diff] [blame] | 330 | #ifdef SK_DEBUG |
| 331 | // assert that the final offset value points to a save verb |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 332 | uint32_t opSize; |
| 333 | DrawType drawOp = peek_op_and_size(&fWriter, -offset, &opSize); |
reed@google.com | ffacd3c | 2012-08-30 15:31:23 +0000 | [diff] [blame] | 334 | SkASSERT(SAVE == drawOp || SAVE_LAYER == drawOp); |
| 335 | #endif |
junov@chromium.org | e3dbedb | 2012-07-09 16:03:55 +0000 | [diff] [blame] | 336 | } |
| 337 | |
reed@google.com | d86e7ab | 2012-09-27 20:31:31 +0000 | [diff] [blame] | 338 | void SkPictureRecord::beginRecording() { |
| 339 | // we have to call this *after* our constructor, to ensure that it gets |
| 340 | // recorded. This is balanced by restoreToCount() call from endRecording, |
| 341 | // which in-turn calls our overridden restore(), so those get recorded too. |
commit-bot@chromium.org | 091a594 | 2014-04-18 14:19:31 +0000 | [diff] [blame] | 342 | fInitialSaveCount = this->save(); |
reed@google.com | d86e7ab | 2012-09-27 20:31:31 +0000 | [diff] [blame] | 343 | } |
| 344 | |
junov@chromium.org | a6c9e0e | 2012-07-12 17:47:34 +0000 | [diff] [blame] | 345 | void SkPictureRecord::endRecording() { |
junov@chromium.org | 4e6dfa5 | 2012-07-16 14:04:59 +0000 | [diff] [blame] | 346 | SkASSERT(kNoInitialSave != fInitialSaveCount); |
| 347 | this->restoreToCount(fInitialSaveCount); |
junov@chromium.org | a6c9e0e | 2012-07-12 17:47:34 +0000 | [diff] [blame] | 348 | } |
| 349 | |
commit-bot@chromium.org | dcecb16 | 2014-04-22 17:54:29 +0000 | [diff] [blame] | 350 | size_t SkPictureRecord::recordRestoreOffsetPlaceholder(SkRegion::Op op) { |
reed@google.com | 21b519d | 2012-10-02 17:42:15 +0000 | [diff] [blame] | 351 | if (fRestoreOffsetStack.isEmpty()) { |
robertphillips@google.com | 5a63f24 | 2014-02-04 20:07:50 +0000 | [diff] [blame] | 352 | return -1; |
reed@google.com | 21b519d | 2012-10-02 17:42:15 +0000 | [diff] [blame] | 353 | } |
| 354 | |
fmalita@google.com | d0f1a4f | 2013-08-27 15:50:19 +0000 | [diff] [blame] | 355 | // The RestoreOffset field is initially filled with a placeholder |
| 356 | // value that points to the offset of the previous RestoreOffset |
| 357 | // in the current stack level, thus forming a linked list so that |
| 358 | // the restore offsets can be filled in when the corresponding |
| 359 | // restore command is recorded. |
| 360 | int32_t prevOffset = fRestoreOffsetStack.top(); |
| 361 | |
reed@google.com | 45482d1 | 2011-08-29 19:02:39 +0000 | [diff] [blame] | 362 | if (regionOpExpands(op)) { |
| 363 | // Run back through any previous clip ops, and mark their offset to |
| 364 | // be 0, disabling their ability to trigger a jump-to-restore, otherwise |
| 365 | // they could hide this clips ability to expand the clip (i.e. go from |
| 366 | // empty to non-empty). |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 367 | this->fillRestoreOffsetPlaceholdersForCurrentStackLevel(0); |
fmalita@google.com | d0f1a4f | 2013-08-27 15:50:19 +0000 | [diff] [blame] | 368 | |
| 369 | // Reset the pointer back to the previous clip so that subsequent |
| 370 | // restores don't overwrite the offsets we just cleared. |
| 371 | prevOffset = 0; |
reed@google.com | 45482d1 | 2011-08-29 19:02:39 +0000 | [diff] [blame] | 372 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 373 | |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 374 | size_t offset = fWriter.bytesWritten(); |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 375 | this->addInt(prevOffset); |
commit-bot@chromium.org | dcecb16 | 2014-04-22 17:54:29 +0000 | [diff] [blame] | 376 | fRestoreOffsetStack.top() = SkToU32(offset); |
robertphillips@google.com | 5a63f24 | 2014-02-04 20:07:50 +0000 | [diff] [blame] | 377 | return offset; |
reed@google.com | 45482d1 | 2011-08-29 19:02:39 +0000 | [diff] [blame] | 378 | } |
| 379 | |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame] | 380 | void SkPictureRecord::onClipRect(const SkRect& rect, SkRegion::Op op, ClipEdgeStyle edgeStyle) { |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame] | 381 | this->recordClipRect(rect, op, kSoft_ClipEdgeStyle == edgeStyle); |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame] | 382 | this->INHERITED::onClipRect(rect, op, edgeStyle); |
robertphillips@google.com | 5a63f24 | 2014-02-04 20:07:50 +0000 | [diff] [blame] | 383 | } |
| 384 | |
commit-bot@chromium.org | dcecb16 | 2014-04-22 17:54:29 +0000 | [diff] [blame] | 385 | size_t SkPictureRecord::recordClipRect(const SkRect& rect, SkRegion::Op op, bool doAA) { |
robertphillips@google.com | f929150 | 2013-02-15 15:13:27 +0000 | [diff] [blame] | 386 | // id + rect + clip params |
commit-bot@chromium.org | dcecb16 | 2014-04-22 17:54:29 +0000 | [diff] [blame] | 387 | size_t size = 1 * kUInt32Size + sizeof(rect) + 1 * kUInt32Size; |
robertphillips@google.com | 4310c66 | 2013-03-01 14:17:58 +0000 | [diff] [blame] | 388 | // recordRestoreOffsetPlaceholder doesn't always write an offset |
robertphillips@google.com | f929150 | 2013-02-15 15:13:27 +0000 | [diff] [blame] | 389 | if (!fRestoreOffsetStack.isEmpty()) { |
| 390 | // + restore offset |
| 391 | size += kUInt32Size; |
| 392 | } |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 393 | size_t initialOffset = this->addDraw(CLIP_RECT, &size); |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 394 | this->addRect(rect); |
| 395 | this->addInt(ClipParams_pack(op, doAA)); |
commit-bot@chromium.org | dcecb16 | 2014-04-22 17:54:29 +0000 | [diff] [blame] | 396 | size_t offset = this->recordRestoreOffsetPlaceholder(op); |
skia.committer@gmail.com | 306ab9d | 2012-12-13 02:01:33 +0000 | [diff] [blame] | 397 | |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 398 | this->validate(initialOffset, size); |
robertphillips@google.com | 5a63f24 | 2014-02-04 20:07:50 +0000 | [diff] [blame] | 399 | return offset; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 400 | } |
| 401 | |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame] | 402 | void SkPictureRecord::onClipRRect(const SkRRect& rrect, SkRegion::Op op, ClipEdgeStyle edgeStyle) { |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame] | 403 | this->recordClipRRect(rrect, op, kSoft_ClipEdgeStyle == edgeStyle); |
reed | d954498 | 2014-09-09 18:46:22 -0700 | [diff] [blame] | 404 | this->INHERITED::onClipRRect(rrect, op, edgeStyle); |
robertphillips@google.com | 5a63f24 | 2014-02-04 20:07:50 +0000 | [diff] [blame] | 405 | } |
| 406 | |
commit-bot@chromium.org | dcecb16 | 2014-04-22 17:54:29 +0000 | [diff] [blame] | 407 | size_t SkPictureRecord::recordClipRRect(const SkRRect& rrect, SkRegion::Op op, bool doAA) { |
robertphillips@google.com | f929150 | 2013-02-15 15:13:27 +0000 | [diff] [blame] | 408 | // op + rrect + clip params |
commit-bot@chromium.org | dcecb16 | 2014-04-22 17:54:29 +0000 | [diff] [blame] | 409 | size_t size = 1 * kUInt32Size + SkRRect::kSizeInMemory + 1 * kUInt32Size; |
robertphillips@google.com | 4310c66 | 2013-03-01 14:17:58 +0000 | [diff] [blame] | 410 | // recordRestoreOffsetPlaceholder doesn't always write an offset |
robertphillips@google.com | f929150 | 2013-02-15 15:13:27 +0000 | [diff] [blame] | 411 | if (!fRestoreOffsetStack.isEmpty()) { |
| 412 | // + restore offset |
| 413 | size += kUInt32Size; |
| 414 | } |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 415 | size_t initialOffset = this->addDraw(CLIP_RRECT, &size); |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 416 | this->addRRect(rrect); |
| 417 | this->addInt(ClipParams_pack(op, doAA)); |
commit-bot@chromium.org | dcecb16 | 2014-04-22 17:54:29 +0000 | [diff] [blame] | 418 | size_t offset = recordRestoreOffsetPlaceholder(op); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 419 | this->validate(initialOffset, size); |
robertphillips@google.com | 5a63f24 | 2014-02-04 20:07:50 +0000 | [diff] [blame] | 420 | return offset; |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 421 | } |
| 422 | |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame] | 423 | void SkPictureRecord::onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeStyle edgeStyle) { |
robertphillips@google.com | 5a63f24 | 2014-02-04 20:07:50 +0000 | [diff] [blame] | 424 | int pathID = this->addPathToHeap(path); |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame] | 425 | this->recordClipPath(pathID, op, kSoft_ClipEdgeStyle == edgeStyle); |
reed | d954498 | 2014-09-09 18:46:22 -0700 | [diff] [blame] | 426 | this->INHERITED::onClipPath(path, op, edgeStyle); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 427 | } |
| 428 | |
commit-bot@chromium.org | dcecb16 | 2014-04-22 17:54:29 +0000 | [diff] [blame] | 429 | size_t SkPictureRecord::recordClipPath(int pathID, SkRegion::Op op, bool doAA) { |
robertphillips@google.com | 5a63f24 | 2014-02-04 20:07:50 +0000 | [diff] [blame] | 430 | // op + path index + clip params |
commit-bot@chromium.org | dcecb16 | 2014-04-22 17:54:29 +0000 | [diff] [blame] | 431 | size_t size = 3 * kUInt32Size; |
robertphillips@google.com | 5a63f24 | 2014-02-04 20:07:50 +0000 | [diff] [blame] | 432 | // recordRestoreOffsetPlaceholder doesn't always write an offset |
| 433 | if (!fRestoreOffsetStack.isEmpty()) { |
| 434 | // + restore offset |
| 435 | size += kUInt32Size; |
| 436 | } |
| 437 | size_t initialOffset = this->addDraw(CLIP_PATH, &size); |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 438 | this->addInt(pathID); |
| 439 | this->addInt(ClipParams_pack(op, doAA)); |
commit-bot@chromium.org | dcecb16 | 2014-04-22 17:54:29 +0000 | [diff] [blame] | 440 | size_t offset = recordRestoreOffsetPlaceholder(op); |
robertphillips@google.com | 5a63f24 | 2014-02-04 20:07:50 +0000 | [diff] [blame] | 441 | this->validate(initialOffset, size); |
| 442 | return offset; |
| 443 | } |
| 444 | |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame] | 445 | void SkPictureRecord::onClipRegion(const SkRegion& region, SkRegion::Op op) { |
robertphillips@google.com | 5a63f24 | 2014-02-04 20:07:50 +0000 | [diff] [blame] | 446 | this->recordClipRegion(region, op); |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame] | 447 | this->INHERITED::onClipRegion(region, op); |
robertphillips@google.com | 5a63f24 | 2014-02-04 20:07:50 +0000 | [diff] [blame] | 448 | } |
| 449 | |
commit-bot@chromium.org | dcecb16 | 2014-04-22 17:54:29 +0000 | [diff] [blame] | 450 | size_t SkPictureRecord::recordClipRegion(const SkRegion& region, SkRegion::Op op) { |
commit-bot@chromium.org | fed2ab6 | 2014-01-23 15:16:05 +0000 | [diff] [blame] | 451 | // op + clip params + region |
commit-bot@chromium.org | dcecb16 | 2014-04-22 17:54:29 +0000 | [diff] [blame] | 452 | size_t size = 2 * kUInt32Size + region.writeToMemory(NULL); |
robertphillips@google.com | 4310c66 | 2013-03-01 14:17:58 +0000 | [diff] [blame] | 453 | // recordRestoreOffsetPlaceholder doesn't always write an offset |
robertphillips@google.com | f929150 | 2013-02-15 15:13:27 +0000 | [diff] [blame] | 454 | if (!fRestoreOffsetStack.isEmpty()) { |
| 455 | // + restore offset |
| 456 | size += kUInt32Size; |
| 457 | } |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 458 | size_t initialOffset = this->addDraw(CLIP_REGION, &size); |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 459 | this->addRegion(region); |
| 460 | this->addInt(ClipParams_pack(op, false)); |
commit-bot@chromium.org | dcecb16 | 2014-04-22 17:54:29 +0000 | [diff] [blame] | 461 | size_t offset = this->recordRestoreOffsetPlaceholder(op); |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 462 | |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 463 | this->validate(initialOffset, size); |
robertphillips@google.com | 5a63f24 | 2014-02-04 20:07:50 +0000 | [diff] [blame] | 464 | return offset; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 465 | } |
| 466 | |
reed@google.com | 2a98181 | 2011-04-14 18:59:28 +0000 | [diff] [blame] | 467 | void SkPictureRecord::clear(SkColor color) { |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 468 | // op + color |
commit-bot@chromium.org | dcecb16 | 2014-04-22 17:54:29 +0000 | [diff] [blame] | 469 | size_t size = 2 * kUInt32Size; |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 470 | size_t initialOffset = this->addDraw(DRAW_CLEAR, &size); |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 471 | this->addInt(color); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 472 | this->validate(initialOffset, size); |
reed@google.com | 2a98181 | 2011-04-14 18:59:28 +0000 | [diff] [blame] | 473 | } |
| 474 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 475 | void SkPictureRecord::drawPaint(const SkPaint& paint) { |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 476 | // op + paint index |
commit-bot@chromium.org | dcecb16 | 2014-04-22 17:54:29 +0000 | [diff] [blame] | 477 | size_t size = 2 * kUInt32Size; |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 478 | size_t initialOffset = this->addDraw(DRAW_PAINT, &size); |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 479 | SkASSERT(initialOffset+getPaintOffset(DRAW_PAINT, size) == fWriter.bytesWritten()); |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 480 | this->addPaint(paint); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 481 | this->validate(initialOffset, size); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 482 | } |
| 483 | |
| 484 | void SkPictureRecord::drawPoints(PointMode mode, size_t count, const SkPoint pts[], |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 485 | const SkPaint& paint) { |
hendrikw | afdada2 | 2014-08-08 10:44:33 -0700 | [diff] [blame] | 486 | fContentInfo.onDrawPoints(count, paint); |
robertphillips@google.com | 105a4a5 | 2014-02-11 15:10:40 +0000 | [diff] [blame] | 487 | |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 488 | // op + paint index + mode + count + point data |
commit-bot@chromium.org | dcecb16 | 2014-04-22 17:54:29 +0000 | [diff] [blame] | 489 | size_t size = 4 * kUInt32Size + count * sizeof(SkPoint); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 490 | size_t initialOffset = this->addDraw(DRAW_POINTS, &size); |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 491 | SkASSERT(initialOffset+getPaintOffset(DRAW_POINTS, size) == fWriter.bytesWritten()); |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 492 | this->addPaint(paint); |
hendrikw | afdada2 | 2014-08-08 10:44:33 -0700 | [diff] [blame] | 493 | |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 494 | this->addInt(mode); |
commit-bot@chromium.org | dcecb16 | 2014-04-22 17:54:29 +0000 | [diff] [blame] | 495 | this->addInt(SkToInt(count)); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 496 | fWriter.writeMul4(pts, count * sizeof(SkPoint)); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 497 | this->validate(initialOffset, size); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 498 | } |
| 499 | |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 500 | void SkPictureRecord::drawOval(const SkRect& oval, const SkPaint& paint) { |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 501 | // op + paint index + rect |
commit-bot@chromium.org | dcecb16 | 2014-04-22 17:54:29 +0000 | [diff] [blame] | 502 | size_t size = 2 * kUInt32Size + sizeof(oval); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 503 | size_t initialOffset = this->addDraw(DRAW_OVAL, &size); |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 504 | SkASSERT(initialOffset+getPaintOffset(DRAW_OVAL, size) == fWriter.bytesWritten()); |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 505 | this->addPaint(paint); |
| 506 | this->addRect(oval); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 507 | this->validate(initialOffset, size); |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 508 | } |
| 509 | |
bsalomon@google.com | 7ce564c | 2013-10-22 16:54:15 +0000 | [diff] [blame] | 510 | void SkPictureRecord::drawRect(const SkRect& rect, const SkPaint& paint) { |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 511 | // op + paint index + rect |
commit-bot@chromium.org | dcecb16 | 2014-04-22 17:54:29 +0000 | [diff] [blame] | 512 | size_t size = 2 * kUInt32Size + sizeof(rect); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 513 | size_t initialOffset = this->addDraw(DRAW_RECT, &size); |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 514 | SkASSERT(initialOffset+getPaintOffset(DRAW_RECT, size) == fWriter.bytesWritten()); |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 515 | this->addPaint(paint); |
| 516 | this->addRect(rect); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 517 | this->validate(initialOffset, size); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 518 | } |
| 519 | |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 520 | void SkPictureRecord::drawRRect(const SkRRect& rrect, const SkPaint& paint) { |
mtklein | 46616af | 2014-09-30 14:47:10 -0700 | [diff] [blame^] | 521 | // op + paint index + rrect |
| 522 | size_t size = 2 * kUInt32Size + SkRRect::kSizeInMemory; |
| 523 | size_t initialOffset = this->addDraw(DRAW_RRECT, &size); |
| 524 | SkASSERT(initialOffset+getPaintOffset(DRAW_RRECT, size) == fWriter.bytesWritten()); |
| 525 | this->addPaint(paint); |
| 526 | this->addRRect(rrect); |
| 527 | this->validate(initialOffset, size); |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 528 | } |
| 529 | |
commit-bot@chromium.org | ed9806f | 2014-02-21 02:32:36 +0000 | [diff] [blame] | 530 | void SkPictureRecord::onDrawDRRect(const SkRRect& outer, const SkRRect& inner, |
| 531 | const SkPaint& paint) { |
commit-bot@chromium.org | ed9806f | 2014-02-21 02:32:36 +0000 | [diff] [blame] | 532 | // op + paint index + rrects |
commit-bot@chromium.org | dcecb16 | 2014-04-22 17:54:29 +0000 | [diff] [blame] | 533 | size_t size = 2 * kUInt32Size + SkRRect::kSizeInMemory * 2; |
| 534 | size_t initialOffset = this->addDraw(DRAW_DRRECT, &size); |
commit-bot@chromium.org | ed9806f | 2014-02-21 02:32:36 +0000 | [diff] [blame] | 535 | SkASSERT(initialOffset+getPaintOffset(DRAW_DRRECT, size) == fWriter.bytesWritten()); |
| 536 | this->addPaint(paint); |
| 537 | this->addRRect(outer); |
| 538 | this->addRRect(inner); |
| 539 | this->validate(initialOffset, size); |
| 540 | } |
| 541 | |
bsalomon@google.com | 7ce564c | 2013-10-22 16:54:15 +0000 | [diff] [blame] | 542 | void SkPictureRecord::drawPath(const SkPath& path, const SkPaint& paint) { |
hendrikw | afdada2 | 2014-08-08 10:44:33 -0700 | [diff] [blame] | 543 | fContentInfo.onDrawPath(path, paint); |
commit-bot@chromium.org | e2cb12a | 2014-04-24 21:53:13 +0000 | [diff] [blame] | 544 | |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 545 | // op + paint index + path index |
commit-bot@chromium.org | dcecb16 | 2014-04-22 17:54:29 +0000 | [diff] [blame] | 546 | size_t size = 3 * kUInt32Size; |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 547 | size_t initialOffset = this->addDraw(DRAW_PATH, &size); |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 548 | SkASSERT(initialOffset+getPaintOffset(DRAW_PATH, size) == fWriter.bytesWritten()); |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 549 | this->addPaint(paint); |
| 550 | this->addPath(path); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 551 | this->validate(initialOffset, size); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 552 | } |
| 553 | |
| 554 | void SkPictureRecord::drawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top, |
commit-bot@chromium.org | 50b393a | 2014-02-10 18:29:10 +0000 | [diff] [blame] | 555 | const SkPaint* paint = NULL) { |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 556 | // op + paint index + bitmap index + left + top |
commit-bot@chromium.org | dcecb16 | 2014-04-22 17:54:29 +0000 | [diff] [blame] | 557 | size_t size = 3 * kUInt32Size + 2 * sizeof(SkScalar); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 558 | size_t initialOffset = this->addDraw(DRAW_BITMAP, &size); |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 559 | SkASSERT(initialOffset+getPaintOffset(DRAW_BITMAP, size) == fWriter.bytesWritten()); |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 560 | this->addPaintPtr(paint); |
commit-bot@chromium.org | f6a5afb | 2014-04-14 15:02:50 +0000 | [diff] [blame] | 561 | this->addBitmap(bitmap); |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 562 | this->addScalar(left); |
| 563 | this->addScalar(top); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 564 | this->validate(initialOffset, size); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 565 | } |
| 566 | |
reed@google.com | 7112173 | 2012-09-18 15:14:33 +0000 | [diff] [blame] | 567 | void SkPictureRecord::drawBitmapRectToRect(const SkBitmap& bitmap, const SkRect* src, |
commit-bot@chromium.org | eed779d | 2013-08-16 10:24:37 +0000 | [diff] [blame] | 568 | const SkRect& dst, const SkPaint* paint, |
| 569 | DrawBitmapRectFlags flags) { |
| 570 | // id + paint index + bitmap index + bool for 'src' + flags |
commit-bot@chromium.org | dcecb16 | 2014-04-22 17:54:29 +0000 | [diff] [blame] | 571 | size_t size = 5 * kUInt32Size; |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 572 | if (src) { |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 573 | size += sizeof(*src); // + rect |
| 574 | } |
| 575 | size += sizeof(dst); // + rect |
| 576 | |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 577 | size_t initialOffset = this->addDraw(DRAW_BITMAP_RECT_TO_RECT, &size); |
commit-bot@chromium.org | 50b393a | 2014-02-10 18:29:10 +0000 | [diff] [blame] | 578 | SkASSERT(initialOffset+getPaintOffset(DRAW_BITMAP_RECT_TO_RECT, size) |
| 579 | == fWriter.bytesWritten()); |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 580 | this->addPaintPtr(paint); |
commit-bot@chromium.org | f6a5afb | 2014-04-14 15:02:50 +0000 | [diff] [blame] | 581 | this->addBitmap(bitmap); |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 582 | this->addRectPtr(src); // may be null |
| 583 | this->addRect(dst); |
| 584 | this->addInt(flags); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 585 | this->validate(initialOffset, size); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 586 | } |
| 587 | |
| 588 | void SkPictureRecord::drawBitmapMatrix(const SkBitmap& bitmap, const SkMatrix& matrix, |
reed@google.com | f0b5e11 | 2011-09-07 11:57:34 +0000 | [diff] [blame] | 589 | const SkPaint* paint) { |
commit-bot@chromium.org | fed2ab6 | 2014-01-23 15:16:05 +0000 | [diff] [blame] | 590 | // id + paint index + bitmap index + matrix |
commit-bot@chromium.org | dcecb16 | 2014-04-22 17:54:29 +0000 | [diff] [blame] | 591 | size_t size = 3 * kUInt32Size + matrix.writeToMemory(NULL); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 592 | size_t initialOffset = this->addDraw(DRAW_BITMAP_MATRIX, &size); |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 593 | SkASSERT(initialOffset+getPaintOffset(DRAW_BITMAP_MATRIX, size) == fWriter.bytesWritten()); |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 594 | this->addPaintPtr(paint); |
commit-bot@chromium.org | f6a5afb | 2014-04-14 15:02:50 +0000 | [diff] [blame] | 595 | this->addBitmap(bitmap); |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 596 | this->addMatrix(matrix); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 597 | this->validate(initialOffset, size); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 598 | } |
| 599 | |
reed@google.com | f0b5e11 | 2011-09-07 11:57:34 +0000 | [diff] [blame] | 600 | void SkPictureRecord::drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, |
| 601 | const SkRect& dst, const SkPaint* paint) { |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 602 | // op + paint index + bitmap id + center + dst rect |
commit-bot@chromium.org | dcecb16 | 2014-04-22 17:54:29 +0000 | [diff] [blame] | 603 | size_t size = 3 * kUInt32Size + sizeof(center) + sizeof(dst); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 604 | size_t initialOffset = this->addDraw(DRAW_BITMAP_NINE, &size); |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 605 | SkASSERT(initialOffset+getPaintOffset(DRAW_BITMAP_NINE, size) == fWriter.bytesWritten()); |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 606 | this->addPaintPtr(paint); |
commit-bot@chromium.org | f6a5afb | 2014-04-14 15:02:50 +0000 | [diff] [blame] | 607 | this->addBitmap(bitmap); |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 608 | this->addIRect(center); |
| 609 | this->addRect(dst); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 610 | this->validate(initialOffset, size); |
reed@google.com | f0b5e11 | 2011-09-07 11:57:34 +0000 | [diff] [blame] | 611 | } |
| 612 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 613 | void SkPictureRecord::drawSprite(const SkBitmap& bitmap, int left, int top, |
commit-bot@chromium.org | 50b393a | 2014-02-10 18:29:10 +0000 | [diff] [blame] | 614 | const SkPaint* paint = NULL) { |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 615 | // op + paint index + bitmap index + left + top |
commit-bot@chromium.org | dcecb16 | 2014-04-22 17:54:29 +0000 | [diff] [blame] | 616 | size_t size = 5 * kUInt32Size; |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 617 | size_t initialOffset = this->addDraw(DRAW_SPRITE, &size); |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 618 | SkASSERT(initialOffset+getPaintOffset(DRAW_SPRITE, size) == fWriter.bytesWritten()); |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 619 | this->addPaintPtr(paint); |
commit-bot@chromium.org | f6a5afb | 2014-04-14 15:02:50 +0000 | [diff] [blame] | 620 | this->addBitmap(bitmap); |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 621 | this->addInt(left); |
| 622 | this->addInt(top); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 623 | this->validate(initialOffset, size); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 624 | } |
| 625 | |
reed@google.com | e0d9ce8 | 2014-04-23 04:00:17 +0000 | [diff] [blame] | 626 | void SkPictureRecord::onDrawText(const void* text, size_t byteLength, SkScalar x, SkScalar y, |
| 627 | const SkPaint& paint) { |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 628 | // op + paint index + length + 'length' worth of chars + x + y |
commit-bot@chromium.org | dcecb16 | 2014-04-22 17:54:29 +0000 | [diff] [blame] | 629 | size_t size = 3 * kUInt32Size + SkAlign4(byteLength) + 2 * sizeof(SkScalar); |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 630 | |
mtklein | 46616af | 2014-09-30 14:47:10 -0700 | [diff] [blame^] | 631 | DrawType op = DRAW_TEXT; |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 632 | size_t initialOffset = this->addDraw(op, &size); |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 633 | SkASSERT(initialOffset+getPaintOffset(op, size) == fWriter.bytesWritten()); |
mtklein | 46616af | 2014-09-30 14:47:10 -0700 | [diff] [blame^] | 634 | this->addPaint(paint); |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 635 | this->addText(text, byteLength); |
| 636 | this->addScalar(x); |
| 637 | this->addScalar(y); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 638 | this->validate(initialOffset, size); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 639 | } |
| 640 | |
reed@google.com | e0d9ce8 | 2014-04-23 04:00:17 +0000 | [diff] [blame] | 641 | void SkPictureRecord::onDrawPosText(const void* text, size_t byteLength, const SkPoint pos[], |
| 642 | const SkPaint& paint) { |
commit-bot@chromium.org | dcecb16 | 2014-04-22 17:54:29 +0000 | [diff] [blame] | 643 | int points = paint.countText(text, byteLength); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 644 | |
mtklein | 46616af | 2014-09-30 14:47:10 -0700 | [diff] [blame^] | 645 | // op + paint index + length + 'length' worth of data + num points + x&y point data |
| 646 | size_t size = 3 * kUInt32Size + SkAlign4(byteLength) + kUInt32Size + points * sizeof(SkPoint); |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 647 | |
mtklein | 46616af | 2014-09-30 14:47:10 -0700 | [diff] [blame^] | 648 | DrawType op = DRAW_POS_TEXT; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 649 | |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 650 | size_t initialOffset = this->addDraw(op, &size); |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 651 | SkASSERT(initialOffset+getPaintOffset(op, size) == fWriter.bytesWritten()); |
mtklein | 46616af | 2014-09-30 14:47:10 -0700 | [diff] [blame^] | 652 | this->addPaint(paint); |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 653 | this->addText(text, byteLength); |
| 654 | this->addInt(points); |
mtklein | 46616af | 2014-09-30 14:47:10 -0700 | [diff] [blame^] | 655 | fWriter.writeMul4(pos, points * sizeof(SkPoint)); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 656 | this->validate(initialOffset, size); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 657 | } |
| 658 | |
reed@google.com | e0d9ce8 | 2014-04-23 04:00:17 +0000 | [diff] [blame] | 659 | void SkPictureRecord::onDrawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[], |
| 660 | SkScalar constY, const SkPaint& paint) { |
commit-bot@chromium.org | dcecb16 | 2014-04-22 17:54:29 +0000 | [diff] [blame] | 661 | int points = paint.countText(text, byteLength); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 662 | |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 663 | // op + paint index + length + 'length' worth of data + num points |
commit-bot@chromium.org | dcecb16 | 2014-04-22 17:54:29 +0000 | [diff] [blame] | 664 | size_t size = 3 * kUInt32Size + SkAlign4(byteLength) + 1 * kUInt32Size; |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 665 | // + y + the actual points |
| 666 | size += 1 * kUInt32Size + points * sizeof(SkScalar); |
commit-bot@chromium.org | cf7be95 | 2013-08-22 17:19:52 +0000 | [diff] [blame] | 667 | |
mtklein | 46616af | 2014-09-30 14:47:10 -0700 | [diff] [blame^] | 668 | size_t initialOffset = this->addDraw(DRAW_POS_TEXT_H, &size); |
| 669 | this->addPaint(paint); |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 670 | this->addText(text, byteLength); |
| 671 | this->addInt(points); |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 672 | this->addScalar(constY); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 673 | fWriter.writeMul4(xpos, points * sizeof(SkScalar)); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 674 | this->validate(initialOffset, size); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 675 | } |
| 676 | |
reed@google.com | e0d9ce8 | 2014-04-23 04:00:17 +0000 | [diff] [blame] | 677 | void SkPictureRecord::onDrawTextOnPath(const void* text, size_t byteLength, const SkPath& path, |
| 678 | const SkMatrix* matrix, const SkPaint& paint) { |
commit-bot@chromium.org | fed2ab6 | 2014-01-23 15:16:05 +0000 | [diff] [blame] | 679 | // op + paint index + length + 'length' worth of data + path index + matrix |
| 680 | const SkMatrix& m = matrix ? *matrix : SkMatrix::I(); |
commit-bot@chromium.org | dcecb16 | 2014-04-22 17:54:29 +0000 | [diff] [blame] | 681 | size_t size = 3 * kUInt32Size + SkAlign4(byteLength) + kUInt32Size + m.writeToMemory(NULL); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 682 | size_t initialOffset = this->addDraw(DRAW_TEXT_ON_PATH, &size); |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 683 | SkASSERT(initialOffset+getPaintOffset(DRAW_TEXT_ON_PATH, size) == fWriter.bytesWritten()); |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 684 | this->addPaint(paint); |
| 685 | this->addText(text, byteLength); |
| 686 | this->addPath(path); |
| 687 | this->addMatrix(m); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 688 | this->validate(initialOffset, size); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 689 | } |
| 690 | |
fmalita | b742517 | 2014-08-26 07:56:44 -0700 | [diff] [blame] | 691 | void SkPictureRecord::onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y, |
| 692 | const SkPaint& paint) { |
| 693 | |
| 694 | // op + paint index + blob index + x/y |
| 695 | size_t size = 3 * kUInt32Size + 2 * sizeof(SkScalar); |
| 696 | size_t initialOffset = this->addDraw(DRAW_TEXT_BLOB, &size); |
| 697 | SkASSERT(initialOffset + getPaintOffset(DRAW_TEXT_BLOB, size) == fWriter.bytesWritten()); |
| 698 | |
| 699 | this->addPaint(paint); |
| 700 | this->addTextBlob(blob); |
| 701 | this->addScalar(x); |
| 702 | this->addScalar(y); |
| 703 | |
| 704 | this->validate(initialOffset, size); |
| 705 | } |
| 706 | |
reed | d5fa1a4 | 2014-08-09 11:08:05 -0700 | [diff] [blame] | 707 | void SkPictureRecord::onDrawPicture(const SkPicture* picture, const SkMatrix* matrix, |
| 708 | const SkPaint* paint) { |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 709 | // op + picture index |
commit-bot@chromium.org | dcecb16 | 2014-04-22 17:54:29 +0000 | [diff] [blame] | 710 | size_t size = 2 * kUInt32Size; |
reed | d5fa1a4 | 2014-08-09 11:08:05 -0700 | [diff] [blame] | 711 | size_t initialOffset; |
| 712 | |
| 713 | if (NULL == matrix && NULL == paint) { |
| 714 | initialOffset = this->addDraw(DRAW_PICTURE, &size); |
| 715 | this->addPicture(picture); |
| 716 | } else { |
| 717 | const SkMatrix& m = matrix ? *matrix : SkMatrix::I(); |
| 718 | size += m.writeToMemory(NULL) + kUInt32Size; // matrix + paint |
| 719 | initialOffset = this->addDraw(DRAW_PICTURE_MATRIX_PAINT, &size); |
fmalita | 9f49cfd | 2014-08-12 12:24:17 -0700 | [diff] [blame] | 720 | SkASSERT(initialOffset + getPaintOffset(DRAW_PICTURE_MATRIX_PAINT, size) |
| 721 | == fWriter.bytesWritten()); |
reed | d5fa1a4 | 2014-08-09 11:08:05 -0700 | [diff] [blame] | 722 | this->addPaintPtr(paint); |
fmalita | 9f49cfd | 2014-08-12 12:24:17 -0700 | [diff] [blame] | 723 | this->addMatrix(m); |
| 724 | this->addPicture(picture); |
reed | d5fa1a4 | 2014-08-09 11:08:05 -0700 | [diff] [blame] | 725 | } |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 726 | this->validate(initialOffset, size); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 727 | } |
| 728 | |
| 729 | void SkPictureRecord::drawVertices(VertexMode vmode, int vertexCount, |
| 730 | const SkPoint vertices[], const SkPoint texs[], |
reed@google.com | 85e143c | 2013-12-30 15:51:25 +0000 | [diff] [blame] | 731 | const SkColor colors[], SkXfermode* xfer, |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 732 | const uint16_t indices[], int indexCount, |
| 733 | const SkPaint& paint) { |
| 734 | uint32_t flags = 0; |
| 735 | if (texs) { |
| 736 | flags |= DRAW_VERTICES_HAS_TEXS; |
| 737 | } |
| 738 | if (colors) { |
| 739 | flags |= DRAW_VERTICES_HAS_COLORS; |
| 740 | } |
| 741 | if (indexCount > 0) { |
| 742 | flags |= DRAW_VERTICES_HAS_INDICES; |
| 743 | } |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 744 | if (xfer) { |
reed@google.com | 85e143c | 2013-12-30 15:51:25 +0000 | [diff] [blame] | 745 | SkXfermode::Mode mode; |
| 746 | if (xfer->asMode(&mode) && SkXfermode::kModulate_Mode != mode) { |
| 747 | flags |= DRAW_VERTICES_HAS_XFER; |
| 748 | } |
| 749 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 750 | |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 751 | // op + paint index + flags + vmode + vCount + vertices |
commit-bot@chromium.org | dcecb16 | 2014-04-22 17:54:29 +0000 | [diff] [blame] | 752 | size_t size = 5 * kUInt32Size + vertexCount * sizeof(SkPoint); |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 753 | if (flags & DRAW_VERTICES_HAS_TEXS) { |
| 754 | size += vertexCount * sizeof(SkPoint); // + uvs |
| 755 | } |
| 756 | if (flags & DRAW_VERTICES_HAS_COLORS) { |
| 757 | size += vertexCount * sizeof(SkColor); // + vert colors |
| 758 | } |
| 759 | if (flags & DRAW_VERTICES_HAS_INDICES) { |
| 760 | // + num indices + indices |
| 761 | size += 1 * kUInt32Size + SkAlign4(indexCount * sizeof(uint16_t)); |
| 762 | } |
reed@google.com | 85e143c | 2013-12-30 15:51:25 +0000 | [diff] [blame] | 763 | if (flags & DRAW_VERTICES_HAS_XFER) { |
| 764 | size += kUInt32Size; // mode enum |
| 765 | } |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 766 | |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 767 | size_t initialOffset = this->addDraw(DRAW_VERTICES, &size); |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 768 | SkASSERT(initialOffset+getPaintOffset(DRAW_VERTICES, size) == fWriter.bytesWritten()); |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 769 | this->addPaint(paint); |
| 770 | this->addInt(flags); |
| 771 | this->addInt(vmode); |
| 772 | this->addInt(vertexCount); |
| 773 | this->addPoints(vertices, vertexCount); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 774 | if (flags & DRAW_VERTICES_HAS_TEXS) { |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 775 | this->addPoints(texs, vertexCount); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 776 | } |
| 777 | if (flags & DRAW_VERTICES_HAS_COLORS) { |
| 778 | fWriter.writeMul4(colors, vertexCount * sizeof(SkColor)); |
| 779 | } |
| 780 | if (flags & DRAW_VERTICES_HAS_INDICES) { |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 781 | this->addInt(indexCount); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 782 | fWriter.writePad(indices, indexCount * sizeof(uint16_t)); |
| 783 | } |
reed@google.com | 85e143c | 2013-12-30 15:51:25 +0000 | [diff] [blame] | 784 | if (flags & DRAW_VERTICES_HAS_XFER) { |
| 785 | SkXfermode::Mode mode = SkXfermode::kModulate_Mode; |
| 786 | (void)xfer->asMode(&mode); |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 787 | this->addInt(mode); |
reed@google.com | 85e143c | 2013-12-30 15:51:25 +0000 | [diff] [blame] | 788 | } |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 789 | this->validate(initialOffset, size); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 790 | } |
| 791 | |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 792 | void SkPictureRecord::onDrawPatch(const SkPoint cubics[12], const SkColor colors[4], |
| 793 | const SkPoint texCoords[4], SkXfermode* xmode, |
| 794 | const SkPaint& paint) { |
| 795 | // op + paint index + patch 12 control points + flag + patch 4 colors + 4 texture coordinates |
| 796 | size_t size = 2 * kUInt32Size + SkPatchUtils::kNumCtrlPts * sizeof(SkPoint) + kUInt32Size; |
| 797 | uint32_t flag = 0; |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 798 | if (colors) { |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 799 | flag |= DRAW_VERTICES_HAS_COLORS; |
| 800 | size += SkPatchUtils::kNumCorners * sizeof(SkColor); |
| 801 | } |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 802 | if (texCoords) { |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 803 | flag |= DRAW_VERTICES_HAS_TEXS; |
| 804 | size += SkPatchUtils::kNumCorners * sizeof(SkPoint); |
| 805 | } |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 806 | if (xmode) { |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 807 | SkXfermode::Mode mode; |
| 808 | if (xmode->asMode(&mode) && SkXfermode::kModulate_Mode != mode) { |
| 809 | flag |= DRAW_VERTICES_HAS_XFER; |
| 810 | size += kUInt32Size; |
| 811 | } |
| 812 | } |
mtklein | 46616af | 2014-09-30 14:47:10 -0700 | [diff] [blame^] | 813 | |
dandov | 963137b | 2014-08-07 07:49:53 -0700 | [diff] [blame] | 814 | size_t initialOffset = this->addDraw(DRAW_PATCH, &size); |
| 815 | SkASSERT(initialOffset+getPaintOffset(DRAW_PATCH, size) == fWriter.bytesWritten()); |
| 816 | this->addPaint(paint); |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 817 | this->addPatch(cubics); |
| 818 | this->addInt(flag); |
mtklein | 46616af | 2014-09-30 14:47:10 -0700 | [diff] [blame^] | 819 | |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 820 | // write optional parameters |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 821 | if (colors) { |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 822 | fWriter.write(colors, SkPatchUtils::kNumCorners * sizeof(SkColor)); |
| 823 | } |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 824 | if (texCoords) { |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 825 | fWriter.write(texCoords, SkPatchUtils::kNumCorners * sizeof(SkPoint)); |
| 826 | } |
| 827 | if (flag & DRAW_VERTICES_HAS_XFER) { |
| 828 | SkXfermode::Mode mode = SkXfermode::kModulate_Mode; |
| 829 | xmode->asMode(&mode); |
| 830 | this->addInt(mode); |
| 831 | } |
dandov | 963137b | 2014-08-07 07:49:53 -0700 | [diff] [blame] | 832 | this->validate(initialOffset, size); |
| 833 | } |
| 834 | |
reed@android.com | cb60844 | 2009-12-04 21:32:27 +0000 | [diff] [blame] | 835 | void SkPictureRecord::drawData(const void* data, size_t length) { |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 836 | // op + length + 'length' worth of data |
commit-bot@chromium.org | dcecb16 | 2014-04-22 17:54:29 +0000 | [diff] [blame] | 837 | size_t size = 2 * kUInt32Size + SkAlign4(length); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 838 | size_t initialOffset = this->addDraw(DRAW_DATA, &size); |
commit-bot@chromium.org | dcecb16 | 2014-04-22 17:54:29 +0000 | [diff] [blame] | 839 | this->addInt(SkToInt(length)); |
reed@android.com | cb60844 | 2009-12-04 21:32:27 +0000 | [diff] [blame] | 840 | fWriter.writePad(data, length); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 841 | this->validate(initialOffset, size); |
reed@android.com | cb60844 | 2009-12-04 21:32:27 +0000 | [diff] [blame] | 842 | } |
| 843 | |
robertphillips@google.com | 0a4805e | 2013-05-29 13:24:23 +0000 | [diff] [blame] | 844 | void SkPictureRecord::beginCommentGroup(const char* description) { |
| 845 | // op/size + length of string + \0 terminated chars |
commit-bot@chromium.org | dcecb16 | 2014-04-22 17:54:29 +0000 | [diff] [blame] | 846 | size_t length = strlen(description); |
| 847 | size_t size = 2 * kUInt32Size + SkAlign4(length + 1); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 848 | size_t initialOffset = this->addDraw(BEGIN_COMMENT_GROUP, &size); |
robertphillips@google.com | 0a4805e | 2013-05-29 13:24:23 +0000 | [diff] [blame] | 849 | fWriter.writeString(description, length); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 850 | this->validate(initialOffset, size); |
robertphillips@google.com | 0a4805e | 2013-05-29 13:24:23 +0000 | [diff] [blame] | 851 | } |
| 852 | |
| 853 | void SkPictureRecord::addComment(const char* kywd, const char* value) { |
| 854 | // op/size + 2x length of string + 2x \0 terminated chars |
commit-bot@chromium.org | dcecb16 | 2014-04-22 17:54:29 +0000 | [diff] [blame] | 855 | size_t kywdLen = strlen(kywd); |
| 856 | size_t valueLen = strlen(value); |
| 857 | size_t size = 3 * kUInt32Size + SkAlign4(kywdLen + 1) + SkAlign4(valueLen + 1); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 858 | size_t initialOffset = this->addDraw(COMMENT, &size); |
robertphillips@google.com | 0a4805e | 2013-05-29 13:24:23 +0000 | [diff] [blame] | 859 | fWriter.writeString(kywd, kywdLen); |
| 860 | fWriter.writeString(value, valueLen); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 861 | this->validate(initialOffset, size); |
robertphillips@google.com | 0a4805e | 2013-05-29 13:24:23 +0000 | [diff] [blame] | 862 | } |
| 863 | |
| 864 | void SkPictureRecord::endCommentGroup() { |
| 865 | // op/size |
commit-bot@chromium.org | dcecb16 | 2014-04-22 17:54:29 +0000 | [diff] [blame] | 866 | size_t size = 1 * kUInt32Size; |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 867 | size_t initialOffset = this->addDraw(END_COMMENT_GROUP, &size); |
| 868 | this->validate(initialOffset, size); |
robertphillips@google.com | 0a4805e | 2013-05-29 13:24:23 +0000 | [diff] [blame] | 869 | } |
| 870 | |
commit-bot@chromium.org | 210ae2a | 2014-02-27 17:40:13 +0000 | [diff] [blame] | 871 | // [op/size] [rect] [skip offset] |
| 872 | static const uint32_t kPushCullOpSize = 2 * kUInt32Size + sizeof(SkRect); |
| 873 | void SkPictureRecord::onPushCull(const SkRect& cullRect) { |
commit-bot@chromium.org | dcecb16 | 2014-04-22 17:54:29 +0000 | [diff] [blame] | 874 | size_t size = kPushCullOpSize; |
commit-bot@chromium.org | 210ae2a | 2014-02-27 17:40:13 +0000 | [diff] [blame] | 875 | size_t initialOffset = this->addDraw(PUSH_CULL, &size); |
| 876 | // PUSH_CULL's size should stay constant (used to rewind). |
| 877 | SkASSERT(size == kPushCullOpSize); |
| 878 | |
| 879 | this->addRect(cullRect); |
commit-bot@chromium.org | dcecb16 | 2014-04-22 17:54:29 +0000 | [diff] [blame] | 880 | fCullOffsetStack.push(SkToU32(fWriter.bytesWritten())); |
commit-bot@chromium.org | 210ae2a | 2014-02-27 17:40:13 +0000 | [diff] [blame] | 881 | this->addInt(0); |
| 882 | this->validate(initialOffset, size); |
| 883 | } |
| 884 | |
| 885 | void SkPictureRecord::onPopCull() { |
| 886 | SkASSERT(!fCullOffsetStack.isEmpty()); |
| 887 | |
| 888 | uint32_t cullSkipOffset = fCullOffsetStack.top(); |
| 889 | fCullOffsetStack.pop(); |
| 890 | |
commit-bot@chromium.org | 210ae2a | 2014-02-27 17:40:13 +0000 | [diff] [blame] | 891 | // op only |
commit-bot@chromium.org | dcecb16 | 2014-04-22 17:54:29 +0000 | [diff] [blame] | 892 | size_t size = kUInt32Size; |
commit-bot@chromium.org | 210ae2a | 2014-02-27 17:40:13 +0000 | [diff] [blame] | 893 | size_t initialOffset = this->addDraw(POP_CULL, &size); |
| 894 | |
| 895 | // update the cull skip offset to point past this op. |
commit-bot@chromium.org | dcecb16 | 2014-04-22 17:54:29 +0000 | [diff] [blame] | 896 | fWriter.overwriteTAt<uint32_t>(cullSkipOffset, SkToU32(fWriter.bytesWritten())); |
commit-bot@chromium.org | 210ae2a | 2014-02-27 17:40:13 +0000 | [diff] [blame] | 897 | |
| 898 | this->validate(initialOffset, size); |
| 899 | } |
| 900 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 901 | /////////////////////////////////////////////////////////////////////////////// |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 902 | |
reed | 4a8126e | 2014-09-22 07:29:03 -0700 | [diff] [blame] | 903 | SkSurface* SkPictureRecord::onNewSurface(const SkImageInfo& info, const SkSurfaceProps&) { |
commit-bot@chromium.org | cae54f1 | 2014-04-11 18:34:35 +0000 | [diff] [blame] | 904 | return NULL; |
reed@google.com | 76f10a3 | 2014-02-05 15:32:21 +0000 | [diff] [blame] | 905 | } |
| 906 | |
commit-bot@chromium.org | 8016f79 | 2014-03-07 15:53:01 +0000 | [diff] [blame] | 907 | int SkPictureRecord::addBitmap(const SkBitmap& bitmap) { |
scroggo@google.com | 4b90b11 | 2012-12-04 15:08:56 +0000 | [diff] [blame] | 908 | const int index = fBitmapHeap->insert(bitmap); |
| 909 | // In debug builds, a bad return value from insert() will crash, allowing for debugging. In |
| 910 | // release builds, the invalid value will be recorded so that the reader will know that there |
| 911 | // was a problem. |
| 912 | SkASSERT(index != SkBitmapHeap::INVALID_SLOT); |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 913 | this->addInt(index); |
commit-bot@chromium.org | 8016f79 | 2014-03-07 15:53:01 +0000 | [diff] [blame] | 914 | return index; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 915 | } |
| 916 | |
| 917 | void SkPictureRecord::addMatrix(const SkMatrix& matrix) { |
commit-bot@chromium.org | fed2ab6 | 2014-01-23 15:16:05 +0000 | [diff] [blame] | 918 | fWriter.writeMatrix(matrix); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 919 | } |
| 920 | |
mtklein | 46616af | 2014-09-30 14:47:10 -0700 | [diff] [blame^] | 921 | void SkPictureRecord::addPaintPtr(const SkPaint* paint) { |
hendrikw | afdada2 | 2014-08-08 10:44:33 -0700 | [diff] [blame] | 922 | fContentInfo.onAddPaintPtr(paint); |
commit-bot@chromium.org | e2cb12a | 2014-04-24 21:53:13 +0000 | [diff] [blame] | 923 | |
mtklein | 46616af | 2014-09-30 14:47:10 -0700 | [diff] [blame^] | 924 | if (paint) { |
| 925 | const SkFlatData* flat = fPaints.findAndReturnFlat(*paint); |
| 926 | SkASSERT(flat && flat->index() != 0); |
| 927 | this->addInt(flat->index()); |
| 928 | } else { |
| 929 | this->addInt(0); |
| 930 | } |
commit-bot@chromium.org | cf7be95 | 2013-08-22 17:19:52 +0000 | [diff] [blame] | 931 | } |
| 932 | |
robertphillips@google.com | 5a63f24 | 2014-02-04 20:07:50 +0000 | [diff] [blame] | 933 | int SkPictureRecord::addPathToHeap(const SkPath& path) { |
robertphillips | 0bdbea7 | 2014-06-11 11:37:55 -0700 | [diff] [blame] | 934 | if (NULL == fPathHeap) { |
| 935 | fPathHeap.reset(SkNEW(SkPathHeap)); |
| 936 | } |
| 937 | #ifdef SK_DEDUP_PICTURE_PATHS |
| 938 | return fPathHeap->insert(path); |
| 939 | #else |
| 940 | return fPathHeap->append(path); |
| 941 | #endif |
robertphillips@google.com | 5a63f24 | 2014-02-04 20:07:50 +0000 | [diff] [blame] | 942 | } |
| 943 | |
| 944 | void SkPictureRecord::addPath(const SkPath& path) { |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 945 | this->addInt(this->addPathToHeap(path)); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 946 | } |
| 947 | |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 948 | void SkPictureRecord::addPatch(const SkPoint cubics[12]) { |
| 949 | fWriter.write(cubics, SkPatchUtils::kNumCtrlPts * sizeof(SkPoint)); |
dandov | 963137b | 2014-08-07 07:49:53 -0700 | [diff] [blame] | 950 | } |
| 951 | |
robertphillips | 9b14f26 | 2014-06-04 05:40:44 -0700 | [diff] [blame] | 952 | void SkPictureRecord::addPicture(const SkPicture* picture) { |
| 953 | int index = fPictureRefs.find(picture); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 954 | if (index < 0) { // not found |
| 955 | index = fPictureRefs.count(); |
robertphillips | 9b14f26 | 2014-06-04 05:40:44 -0700 | [diff] [blame] | 956 | *fPictureRefs.append() = picture; |
| 957 | picture->ref(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 958 | } |
| 959 | // follow the convention of recording a 1-based index |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 960 | this->addInt(index + 1); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 961 | } |
| 962 | |
| 963 | void SkPictureRecord::addPoint(const SkPoint& point) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 964 | fWriter.writePoint(point); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 965 | } |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 966 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 967 | void SkPictureRecord::addPoints(const SkPoint pts[], int count) { |
| 968 | fWriter.writeMul4(pts, count * sizeof(SkPoint)); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 969 | } |
| 970 | |
senorblanco@chromium.org | 68250c8 | 2014-05-06 22:52:55 +0000 | [diff] [blame] | 971 | void SkPictureRecord::addNoOp() { |
| 972 | size_t size = kUInt32Size; // op |
| 973 | this->addDraw(NOOP, &size); |
| 974 | } |
| 975 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 976 | void SkPictureRecord::addRect(const SkRect& rect) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 977 | fWriter.writeRect(rect); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 978 | } |
| 979 | |
| 980 | void SkPictureRecord::addRectPtr(const SkRect* rect) { |
| 981 | if (fWriter.writeBool(rect != NULL)) { |
| 982 | fWriter.writeRect(*rect); |
| 983 | } |
| 984 | } |
| 985 | |
reed@google.com | f0b5e11 | 2011-09-07 11:57:34 +0000 | [diff] [blame] | 986 | void SkPictureRecord::addIRect(const SkIRect& rect) { |
| 987 | fWriter.write(&rect, sizeof(rect)); |
| 988 | } |
| 989 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 990 | void SkPictureRecord::addIRectPtr(const SkIRect* rect) { |
| 991 | if (fWriter.writeBool(rect != NULL)) { |
| 992 | *(SkIRect*)fWriter.reserve(sizeof(SkIRect)) = *rect; |
| 993 | } |
| 994 | } |
| 995 | |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 996 | void SkPictureRecord::addRRect(const SkRRect& rrect) { |
| 997 | fWriter.writeRRect(rrect); |
| 998 | } |
| 999 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1000 | void SkPictureRecord::addRegion(const SkRegion& region) { |
commit-bot@chromium.org | fed2ab6 | 2014-01-23 15:16:05 +0000 | [diff] [blame] | 1001 | fWriter.writeRegion(region); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1002 | } |
| 1003 | |
| 1004 | void SkPictureRecord::addText(const void* text, size_t byteLength) { |
hendrikw | afdada2 | 2014-08-08 10:44:33 -0700 | [diff] [blame] | 1005 | fContentInfo.onDrawText(); |
commit-bot@chromium.org | dcecb16 | 2014-04-22 17:54:29 +0000 | [diff] [blame] | 1006 | addInt(SkToInt(byteLength)); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1007 | fWriter.writePad(text, byteLength); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1008 | } |
| 1009 | |
fmalita | b742517 | 2014-08-26 07:56:44 -0700 | [diff] [blame] | 1010 | void SkPictureRecord::addTextBlob(const SkTextBlob *blob) { |
jbroman | dd1e9f7 | 2014-09-08 13:24:33 -0700 | [diff] [blame] | 1011 | int index = fTextBlobRefs.count(); |
| 1012 | *fTextBlobRefs.append() = blob; |
| 1013 | blob->ref(); |
fmalita | b742517 | 2014-08-26 07:56:44 -0700 | [diff] [blame] | 1014 | // follow the convention of recording a 1-based index |
| 1015 | this->addInt(index + 1); |
| 1016 | } |
| 1017 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1018 | /////////////////////////////////////////////////////////////////////////////// |
| 1019 | |