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