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