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