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