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" |
Hal Canary | c640d0d | 2018-06-13 09:59:02 -0400 | [diff] [blame] | 9 | |
Mike Reed | 7c9c9e4 | 2018-01-03 09:23:34 -0500 | [diff] [blame] | 10 | #include "SkCanvasPriv.h" |
Hal Canary | c640d0d | 2018-06-13 09:59:02 -0400 | [diff] [blame] | 11 | #include "SkClipOpPriv.h" |
Jim Van Verth | 1af03d4 | 2017-07-31 09:34:58 -0400 | [diff] [blame] | 12 | #include "SkDrawShadowInfo.h" |
reed | a85d4d0 | 2015-05-06 12:56:48 -0700 | [diff] [blame] | 13 | #include "SkImage_Base.h" |
Cary Clark | 6d6d603 | 2017-10-20 12:14:33 -0400 | [diff] [blame] | 14 | #include "SkMatrixPriv.h" |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 15 | #include "SkPatchUtils.h" |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 16 | #include "SkRRect.h" |
reed | 71c3c76 | 2015-06-24 10:29:17 -0700 | [diff] [blame] | 17 | #include "SkRSXform.h" |
Hal Canary | fdcfb8b | 2018-06-13 09:42:32 -0400 | [diff] [blame] | 18 | #include "SkTSearch.h" |
Hal Canary | c640d0d | 2018-06-13 09:59:02 -0400 | [diff] [blame] | 19 | #include "SkTextBlob.h" |
| 20 | #include "SkTo.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 21 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 22 | #define HEAP_BLOCK_SIZE 4096 |
| 23 | |
junov@chromium.org | 4e6dfa5 | 2012-07-16 14:04:59 +0000 | [diff] [blame] | 24 | enum { |
reed@google.com | d86e7ab | 2012-09-27 20:31:31 +0000 | [diff] [blame] | 25 | // just need a value that save or getSaveCount would never return |
junov@chromium.org | 4e6dfa5 | 2012-07-16 14:04:59 +0000 | [diff] [blame] | 26 | kNoInitialSave = -1, |
| 27 | }; |
| 28 | |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 29 | // A lot of basic types get stored as a uint32_t: bools, ints, paint indices, etc. |
| 30 | static int const kUInt32Size = 4; |
| 31 | |
robertphillips | 0bdbea7 | 2014-06-11 11:37:55 -0700 | [diff] [blame] | 32 | SkPictureRecord::SkPictureRecord(const SkISize& dimensions, uint32_t flags) |
commit-bot@chromium.org | 19fafef | 2014-02-17 15:28:00 +0000 | [diff] [blame] | 33 | : INHERITED(dimensions.width(), dimensions.height()) |
mtklein | 71a2363 | 2014-11-12 10:24:55 -0800 | [diff] [blame] | 34 | , fRecordFlags(flags) |
| 35 | , fInitialSaveCount(kNoInitialSave) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 36 | } |
| 37 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 38 | /////////////////////////////////////////////////////////////////////////////// |
| 39 | |
Mike Klein | 7cc49d6 | 2017-08-14 10:39:28 -0400 | [diff] [blame] | 40 | void SkPictureRecord::onFlush() { |
| 41 | size_t size = sizeof(kUInt32Size); |
| 42 | size_t initialOffset = this->addDraw(FLUSH, &size); |
| 43 | this->validate(initialOffset, size); |
| 44 | } |
| 45 | |
Florin Malita | 5f6102d | 2014-06-30 10:13:28 -0400 | [diff] [blame] | 46 | void SkPictureRecord::willSave() { |
reed@google.com | ffacd3c | 2012-08-30 15:31:23 +0000 | [diff] [blame] | 47 | // record the offset to us, making it non-positive to distinguish a save |
| 48 | // from a clip entry. |
Mike Reed | 5edcd31 | 2018-08-08 11:23:41 -0400 | [diff] [blame] | 49 | fRestoreOffsetStack.push_back(-(int32_t)fWriter.bytesWritten()); |
Florin Malita | 5f6102d | 2014-06-30 10:13:28 -0400 | [diff] [blame] | 50 | this->recordSave(); |
commit-bot@chromium.org | e54a23f | 2014-03-12 20:21:48 +0000 | [diff] [blame] | 51 | |
Florin Malita | 5f6102d | 2014-06-30 10:13:28 -0400 | [diff] [blame] | 52 | this->INHERITED::willSave(); |
robertphillips@google.com | 5a63f24 | 2014-02-04 20:07:50 +0000 | [diff] [blame] | 53 | } |
skia.committer@gmail.com | 11f8692 | 2012-08-31 17:14:46 +0000 | [diff] [blame] | 54 | |
Florin Malita | 5f6102d | 2014-06-30 10:13:28 -0400 | [diff] [blame] | 55 | void SkPictureRecord::recordSave() { |
| 56 | // op only |
reed | 512f3e3 | 2016-01-04 14:11:31 -0800 | [diff] [blame] | 57 | size_t size = sizeof(kUInt32Size); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 58 | size_t initialOffset = this->addDraw(SAVE, &size); |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 59 | |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 60 | this->validate(initialOffset, size); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 61 | } |
| 62 | |
reed | 4960eee | 2015-12-18 07:09:18 -0800 | [diff] [blame] | 63 | SkCanvas::SaveLayerStrategy SkPictureRecord::getSaveLayerStrategy(const SaveLayerRec& rec) { |
reed@google.com | ffacd3c | 2012-08-30 15:31:23 +0000 | [diff] [blame] | 64 | // record the offset to us, making it non-positive to distinguish a save |
| 65 | // from a clip entry. |
Mike Reed | 5edcd31 | 2018-08-08 11:23:41 -0400 | [diff] [blame] | 66 | fRestoreOffsetStack.push_back(-(int32_t)fWriter.bytesWritten()); |
reed | 4960eee | 2015-12-18 07:09:18 -0800 | [diff] [blame] | 67 | this->recordSaveLayer(rec); |
skia.committer@gmail.com | 11f8692 | 2012-08-31 17:14:46 +0000 | [diff] [blame] | 68 | |
reed | 4960eee | 2015-12-18 07:09:18 -0800 | [diff] [blame] | 69 | (void)this->INHERITED::getSaveLayerStrategy(rec); |
commit-bot@chromium.org | e54a23f | 2014-03-12 20:21:48 +0000 | [diff] [blame] | 70 | /* 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] | 71 | at this time (and may not be able to afford since during record our |
| 72 | clip starts out the size of the picture, which is often much larger |
| 73 | than the size of the actual device we'll use during playback). |
| 74 | */ |
commit-bot@chromium.org | e54a23f | 2014-03-12 20:21:48 +0000 | [diff] [blame] | 75 | return kNoLayer_SaveLayerStrategy; |
robertphillips@google.com | 5a63f24 | 2014-02-04 20:07:50 +0000 | [diff] [blame] | 76 | } |
| 77 | |
Mike Reed | 148b7fd | 2018-12-18 17:38:18 -0500 | [diff] [blame] | 78 | bool SkPictureRecord::onDoSaveBehind(const SkRect* subset) { |
| 79 | fRestoreOffsetStack.push_back(-(int32_t)fWriter.bytesWritten()); |
| 80 | |
| 81 | size_t size = sizeof(kUInt32Size) + sizeof(uint32_t); // op + flags |
| 82 | uint32_t flags = 0; |
| 83 | if (subset) { |
| 84 | flags |= SAVEBEHIND_HAS_SUBSET; |
| 85 | size += sizeof(*subset); |
| 86 | } |
| 87 | |
| 88 | size_t initialOffset = this->addDraw(SAVE_BEHIND, &size); |
| 89 | this->addInt(flags); |
| 90 | if (subset) { |
| 91 | this->addRect(*subset); |
| 92 | } |
| 93 | |
| 94 | this->validate(initialOffset, size); |
| 95 | return false; |
| 96 | } |
| 97 | |
reed | 4960eee | 2015-12-18 07:09:18 -0800 | [diff] [blame] | 98 | void SkPictureRecord::recordSaveLayer(const SaveLayerRec& rec) { |
reed | bfd5f17 | 2016-01-07 11:28:08 -0800 | [diff] [blame] | 99 | // op + flatflags |
commit-bot@chromium.org | dcecb16 | 2014-04-22 17:54:29 +0000 | [diff] [blame] | 100 | size_t size = 2 * kUInt32Size; |
reed | bfd5f17 | 2016-01-07 11:28:08 -0800 | [diff] [blame] | 101 | uint32_t flatFlags = 0; |
| 102 | |
reed | 4960eee | 2015-12-18 07:09:18 -0800 | [diff] [blame] | 103 | if (rec.fBounds) { |
reed | bfd5f17 | 2016-01-07 11:28:08 -0800 | [diff] [blame] | 104 | flatFlags |= SAVELAYERREC_HAS_BOUNDS; |
| 105 | size += sizeof(*rec.fBounds); |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 106 | } |
reed | bfd5f17 | 2016-01-07 11:28:08 -0800 | [diff] [blame] | 107 | if (rec.fPaint) { |
| 108 | flatFlags |= SAVELAYERREC_HAS_PAINT; |
| 109 | size += sizeof(uint32_t); // index |
| 110 | } |
| 111 | if (rec.fBackdrop) { |
| 112 | flatFlags |= SAVELAYERREC_HAS_BACKDROP; |
| 113 | size += sizeof(uint32_t); // (paint) index |
| 114 | } |
| 115 | if (rec.fSaveLayerFlags) { |
| 116 | flatFlags |= SAVELAYERREC_HAS_FLAGS; |
| 117 | size += sizeof(uint32_t); |
| 118 | } |
Florin Malita | 53f77bd | 2017-04-28 13:48:37 -0400 | [diff] [blame] | 119 | if (rec.fClipMask) { |
| 120 | flatFlags |= SAVELAYERREC_HAS_CLIPMASK; |
| 121 | size += sizeof(uint32_t); // clip image index |
| 122 | } |
| 123 | if (rec.fClipMatrix) { |
| 124 | flatFlags |= SAVELAYERREC_HAS_CLIPMATRIX; |
Cary Clark | 6d6d603 | 2017-10-20 12:14:33 -0400 | [diff] [blame] | 125 | size += SkMatrixPriv::WriteToMemory(*rec.fClipMatrix, nullptr); |
Florin Malita | 53f77bd | 2017-04-28 13:48:37 -0400 | [diff] [blame] | 126 | } |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 127 | |
reed | bfd5f17 | 2016-01-07 11:28:08 -0800 | [diff] [blame] | 128 | const size_t initialOffset = this->addDraw(SAVE_LAYER_SAVELAYERREC, &size); |
| 129 | this->addInt(flatFlags); |
| 130 | if (flatFlags & SAVELAYERREC_HAS_BOUNDS) { |
| 131 | this->addRect(*rec.fBounds); |
| 132 | } |
| 133 | if (flatFlags & SAVELAYERREC_HAS_PAINT) { |
| 134 | this->addPaintPtr(rec.fPaint); |
| 135 | } |
| 136 | if (flatFlags & SAVELAYERREC_HAS_BACKDROP) { |
| 137 | // overkill, but we didn't already track single flattenables, so using a paint for that |
| 138 | SkPaint paint; |
Mike Reed | 5e25717 | 2016-11-01 11:22:05 -0400 | [diff] [blame] | 139 | paint.setImageFilter(sk_ref_sp(const_cast<SkImageFilter*>(rec.fBackdrop))); |
reed | bfd5f17 | 2016-01-07 11:28:08 -0800 | [diff] [blame] | 140 | this->addPaint(paint); |
| 141 | } |
| 142 | if (flatFlags & SAVELAYERREC_HAS_FLAGS) { |
| 143 | this->addInt(rec.fSaveLayerFlags); |
| 144 | } |
Florin Malita | 53f77bd | 2017-04-28 13:48:37 -0400 | [diff] [blame] | 145 | if (flatFlags & SAVELAYERREC_HAS_CLIPMASK) { |
Mike Klein | b34ab04 | 2017-05-01 21:34:14 +0000 | [diff] [blame] | 146 | this->addImage(rec.fClipMask); |
Florin Malita | 53f77bd | 2017-04-28 13:48:37 -0400 | [diff] [blame] | 147 | } |
| 148 | if (flatFlags & SAVELAYERREC_HAS_CLIPMATRIX) { |
| 149 | this->addMatrix(*rec.fClipMatrix); |
| 150 | } |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 151 | this->validate(initialOffset, size); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 152 | } |
| 153 | |
commit-bot@chromium.org | 210ae2a | 2014-02-27 17:40:13 +0000 | [diff] [blame] | 154 | #ifdef SK_DEBUG |
commit-bot@chromium.org | 210ae2a | 2014-02-27 17:40:13 +0000 | [diff] [blame] | 155 | /* |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 156 | * Read the op code from 'offset' in 'writer' and extract the size too. |
| 157 | */ |
commit-bot@chromium.org | dcecb16 | 2014-04-22 17:54:29 +0000 | [diff] [blame] | 158 | 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] | 159 | uint32_t peek = writer->readTAt<uint32_t>(offset); |
reed@google.com | ffacd3c | 2012-08-30 15:31:23 +0000 | [diff] [blame] | 160 | |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 161 | uint32_t op; |
commit-bot@chromium.org | c6d3c44 | 2014-01-31 16:22:57 +0000 | [diff] [blame] | 162 | UNPACK_8_24(peek, op, *size); |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 163 | if (MASK_24 == *size) { |
| 164 | // size required its own slot right after the op code |
commit-bot@chromium.org | 536ac5e | 2014-02-11 22:38:51 +0000 | [diff] [blame] | 165 | *size = writer->readTAt<uint32_t>(offset + kUInt32Size); |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 166 | } |
| 167 | return (DrawType) op; |
reed@google.com | ffacd3c | 2012-08-30 15:31:23 +0000 | [diff] [blame] | 168 | } |
mtklein | 46616af | 2014-09-30 14:47:10 -0700 | [diff] [blame] | 169 | #endif//SK_DEBUG |
commit-bot@chromium.org | 4b32bd5 | 2013-03-15 15:06:03 +0000 | [diff] [blame] | 170 | |
commit-bot@chromium.org | e54a23f | 2014-03-12 20:21:48 +0000 | [diff] [blame] | 171 | void SkPictureRecord::willRestore() { |
junov@chromium.org | 4e6dfa5 | 2012-07-16 14:04:59 +0000 | [diff] [blame] | 172 | #if 0 |
| 173 | SkASSERT(fRestoreOffsetStack.count() > 1); |
| 174 | #endif |
| 175 | |
reed@android.com | b4e22d6 | 2009-07-09 15:20:25 +0000 | [diff] [blame] | 176 | // check for underflow |
| 177 | if (fRestoreOffsetStack.count() == 0) { |
| 178 | return; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 179 | } |
reed@android.com | b4e22d6 | 2009-07-09 15:20:25 +0000 | [diff] [blame] | 180 | |
mtklein | 46616af | 2014-09-30 14:47:10 -0700 | [diff] [blame] | 181 | this->recordRestore(); |
reed@google.com | ffacd3c | 2012-08-30 15:31:23 +0000 | [diff] [blame] | 182 | |
reed@android.com | b4e22d6 | 2009-07-09 15:20:25 +0000 | [diff] [blame] | 183 | fRestoreOffsetStack.pop(); |
reed@android.com | 32a4249 | 2009-07-10 03:33:52 +0000 | [diff] [blame] | 184 | |
commit-bot@chromium.org | e54a23f | 2014-03-12 20:21:48 +0000 | [diff] [blame] | 185 | this->INHERITED::willRestore(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 186 | } |
| 187 | |
robertphillips@google.com | 105a4a5 | 2014-02-11 15:10:40 +0000 | [diff] [blame] | 188 | void SkPictureRecord::recordRestore(bool fillInSkips) { |
robertphillips@google.com | 105a4a5 | 2014-02-11 15:10:40 +0000 | [diff] [blame] | 189 | if (fillInSkips) { |
| 190 | this->fillRestoreOffsetPlaceholdersForCurrentStackLevel((uint32_t)fWriter.bytesWritten()); |
| 191 | } |
commit-bot@chromium.org | dcecb16 | 2014-04-22 17:54:29 +0000 | [diff] [blame] | 192 | size_t size = 1 * kUInt32Size; // RESTORE consists solely of 1 op code |
| 193 | size_t initialOffset = this->addDraw(RESTORE, &size); |
robertphillips@google.com | 5a63f24 | 2014-02-04 20:07:50 +0000 | [diff] [blame] | 194 | this->validate(initialOffset, size); |
| 195 | } |
| 196 | |
commit-bot@chromium.org | d9ea09e | 2014-03-25 17:32:26 +0000 | [diff] [blame] | 197 | void SkPictureRecord::recordTranslate(const SkMatrix& m) { |
| 198 | SkASSERT(SkMatrix::kTranslate_Mask == m.getType()); |
| 199 | |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 200 | // op + dx + dy |
commit-bot@chromium.org | dcecb16 | 2014-04-22 17:54:29 +0000 | [diff] [blame] | 201 | size_t size = 1 * kUInt32Size + 2 * sizeof(SkScalar); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 202 | size_t initialOffset = this->addDraw(TRANSLATE, &size); |
commit-bot@chromium.org | d9ea09e | 2014-03-25 17:32:26 +0000 | [diff] [blame] | 203 | this->addScalar(m.getTranslateX()); |
| 204 | this->addScalar(m.getTranslateY()); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 205 | this->validate(initialOffset, size); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 206 | } |
| 207 | |
commit-bot@chromium.org | d9ea09e | 2014-03-25 17:32:26 +0000 | [diff] [blame] | 208 | void SkPictureRecord::recordScale(const SkMatrix& m) { |
| 209 | SkASSERT(SkMatrix::kScale_Mask == m.getType()); |
robertphillips@google.com | 105a4a5 | 2014-02-11 15:10:40 +0000 | [diff] [blame] | 210 | |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 211 | // op + sx + sy |
commit-bot@chromium.org | dcecb16 | 2014-04-22 17:54:29 +0000 | [diff] [blame] | 212 | size_t size = 1 * kUInt32Size + 2 * sizeof(SkScalar); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 213 | size_t initialOffset = this->addDraw(SCALE, &size); |
commit-bot@chromium.org | d9ea09e | 2014-03-25 17:32:26 +0000 | [diff] [blame] | 214 | this->addScalar(m.getScaleX()); |
| 215 | this->addScalar(m.getScaleY()); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 216 | this->validate(initialOffset, size); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 217 | } |
| 218 | |
commit-bot@chromium.org | 44c48d0 | 2014-03-13 20:03:58 +0000 | [diff] [blame] | 219 | void SkPictureRecord::didConcat(const SkMatrix& matrix) { |
commit-bot@chromium.org | d9ea09e | 2014-03-25 17:32:26 +0000 | [diff] [blame] | 220 | switch (matrix.getType()) { |
| 221 | case SkMatrix::kTranslate_Mask: |
| 222 | this->recordTranslate(matrix); |
| 223 | break; |
| 224 | case SkMatrix::kScale_Mask: |
| 225 | this->recordScale(matrix); |
| 226 | break; |
| 227 | default: |
| 228 | this->recordConcat(matrix); |
| 229 | break; |
| 230 | } |
commit-bot@chromium.org | 44c48d0 | 2014-03-13 20:03:58 +0000 | [diff] [blame] | 231 | this->INHERITED::didConcat(matrix); |
robertphillips@google.com | 5a63f24 | 2014-02-04 20:07:50 +0000 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | void SkPictureRecord::recordConcat(const SkMatrix& matrix) { |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 235 | this->validate(fWriter.bytesWritten(), 0); |
commit-bot@chromium.org | fed2ab6 | 2014-01-23 15:16:05 +0000 | [diff] [blame] | 236 | // op + matrix |
Cary Clark | 6d6d603 | 2017-10-20 12:14:33 -0400 | [diff] [blame] | 237 | size_t size = kUInt32Size + SkMatrixPriv::WriteToMemory(matrix, nullptr); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 238 | size_t initialOffset = this->addDraw(CONCAT, &size); |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 239 | this->addMatrix(matrix); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 240 | this->validate(initialOffset, size); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 241 | } |
| 242 | |
commit-bot@chromium.org | 44c48d0 | 2014-03-13 20:03:58 +0000 | [diff] [blame] | 243 | void SkPictureRecord::didSetMatrix(const SkMatrix& matrix) { |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 244 | this->validate(fWriter.bytesWritten(), 0); |
commit-bot@chromium.org | fed2ab6 | 2014-01-23 15:16:05 +0000 | [diff] [blame] | 245 | // op + matrix |
Cary Clark | 6d6d603 | 2017-10-20 12:14:33 -0400 | [diff] [blame] | 246 | size_t size = kUInt32Size + SkMatrixPriv::WriteToMemory(matrix, nullptr); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 247 | size_t initialOffset = this->addDraw(SET_MATRIX, &size); |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 248 | this->addMatrix(matrix); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 249 | this->validate(initialOffset, size); |
commit-bot@chromium.org | 44c48d0 | 2014-03-13 20:03:58 +0000 | [diff] [blame] | 250 | this->INHERITED::didSetMatrix(matrix); |
reed@android.com | 6e073b9 | 2009-01-06 15:03:30 +0000 | [diff] [blame] | 251 | } |
| 252 | |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 253 | static bool clipOpExpands(SkClipOp op) { |
reed@google.com | 45482d1 | 2011-08-29 19:02:39 +0000 | [diff] [blame] | 254 | switch (op) { |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 255 | case kUnion_SkClipOp: |
| 256 | case kXOR_SkClipOp: |
| 257 | case kReverseDifference_SkClipOp: |
| 258 | case kReplace_SkClipOp: |
reed@google.com | 45482d1 | 2011-08-29 19:02:39 +0000 | [diff] [blame] | 259 | return true; |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 260 | case kIntersect_SkClipOp: |
| 261 | case kDifference_SkClipOp: |
reed@google.com | 45482d1 | 2011-08-29 19:02:39 +0000 | [diff] [blame] | 262 | return false; |
| 263 | default: |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 264 | SkDEBUGFAIL("unknown clipop"); |
reed@google.com | 45482d1 | 2011-08-29 19:02:39 +0000 | [diff] [blame] | 265 | return false; |
| 266 | } |
| 267 | } |
| 268 | |
robertphillips@google.com | e37ad35 | 2013-03-01 19:44:30 +0000 | [diff] [blame] | 269 | void SkPictureRecord::fillRestoreOffsetPlaceholdersForCurrentStackLevel(uint32_t restoreOffset) { |
reed@google.com | ffacd3c | 2012-08-30 15:31:23 +0000 | [diff] [blame] | 270 | int32_t offset = fRestoreOffsetStack.top(); |
| 271 | while (offset > 0) { |
commit-bot@chromium.org | 536ac5e | 2014-02-11 22:38:51 +0000 | [diff] [blame] | 272 | uint32_t peek = fWriter.readTAt<uint32_t>(offset); |
| 273 | fWriter.overwriteTAt(offset, restoreOffset); |
commit-bot@chromium.org | c6d3c44 | 2014-01-31 16:22:57 +0000 | [diff] [blame] | 274 | offset = peek; |
junov@chromium.org | e3dbedb | 2012-07-09 16:03:55 +0000 | [diff] [blame] | 275 | } |
skia.committer@gmail.com | 11f8692 | 2012-08-31 17:14:46 +0000 | [diff] [blame] | 276 | |
reed@google.com | ffacd3c | 2012-08-30 15:31:23 +0000 | [diff] [blame] | 277 | #ifdef SK_DEBUG |
reed | 2ff1fce | 2014-12-11 07:07:37 -0800 | [diff] [blame] | 278 | // offset of 0 has been disabled, so we skip it |
| 279 | if (offset > 0) { |
| 280 | // assert that the final offset value points to a save verb |
| 281 | uint32_t opSize; |
| 282 | DrawType drawOp = peek_op_and_size(&fWriter, -offset, &opSize); |
reed | bfd5f17 | 2016-01-07 11:28:08 -0800 | [diff] [blame] | 283 | SkASSERT(SAVE == drawOp || SAVE_LAYER_SAVELAYERREC == drawOp); |
reed | 2ff1fce | 2014-12-11 07:07:37 -0800 | [diff] [blame] | 284 | } |
reed@google.com | ffacd3c | 2012-08-30 15:31:23 +0000 | [diff] [blame] | 285 | #endif |
junov@chromium.org | e3dbedb | 2012-07-09 16:03:55 +0000 | [diff] [blame] | 286 | } |
| 287 | |
reed@google.com | d86e7ab | 2012-09-27 20:31:31 +0000 | [diff] [blame] | 288 | void SkPictureRecord::beginRecording() { |
| 289 | // we have to call this *after* our constructor, to ensure that it gets |
| 290 | // recorded. This is balanced by restoreToCount() call from endRecording, |
| 291 | // 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] | 292 | fInitialSaveCount = this->save(); |
reed@google.com | d86e7ab | 2012-09-27 20:31:31 +0000 | [diff] [blame] | 293 | } |
| 294 | |
junov@chromium.org | a6c9e0e | 2012-07-12 17:47:34 +0000 | [diff] [blame] | 295 | void SkPictureRecord::endRecording() { |
junov@chromium.org | 4e6dfa5 | 2012-07-16 14:04:59 +0000 | [diff] [blame] | 296 | SkASSERT(kNoInitialSave != fInitialSaveCount); |
| 297 | this->restoreToCount(fInitialSaveCount); |
junov@chromium.org | a6c9e0e | 2012-07-12 17:47:34 +0000 | [diff] [blame] | 298 | } |
| 299 | |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 300 | size_t SkPictureRecord::recordRestoreOffsetPlaceholder(SkClipOp op) { |
reed@google.com | 21b519d | 2012-10-02 17:42:15 +0000 | [diff] [blame] | 301 | if (fRestoreOffsetStack.isEmpty()) { |
robertphillips@google.com | 5a63f24 | 2014-02-04 20:07:50 +0000 | [diff] [blame] | 302 | return -1; |
reed@google.com | 21b519d | 2012-10-02 17:42:15 +0000 | [diff] [blame] | 303 | } |
| 304 | |
fmalita@google.com | d0f1a4f | 2013-08-27 15:50:19 +0000 | [diff] [blame] | 305 | // The RestoreOffset field is initially filled with a placeholder |
| 306 | // value that points to the offset of the previous RestoreOffset |
| 307 | // in the current stack level, thus forming a linked list so that |
| 308 | // the restore offsets can be filled in when the corresponding |
| 309 | // restore command is recorded. |
| 310 | int32_t prevOffset = fRestoreOffsetStack.top(); |
| 311 | |
reed | 73603f3 | 2016-09-20 08:42:38 -0700 | [diff] [blame] | 312 | if (clipOpExpands(op)) { |
reed@google.com | 45482d1 | 2011-08-29 19:02:39 +0000 | [diff] [blame] | 313 | // Run back through any previous clip ops, and mark their offset to |
| 314 | // be 0, disabling their ability to trigger a jump-to-restore, otherwise |
| 315 | // they could hide this clips ability to expand the clip (i.e. go from |
| 316 | // empty to non-empty). |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 317 | this->fillRestoreOffsetPlaceholdersForCurrentStackLevel(0); |
fmalita@google.com | d0f1a4f | 2013-08-27 15:50:19 +0000 | [diff] [blame] | 318 | |
| 319 | // Reset the pointer back to the previous clip so that subsequent |
| 320 | // restores don't overwrite the offsets we just cleared. |
| 321 | prevOffset = 0; |
reed@google.com | 45482d1 | 2011-08-29 19:02:39 +0000 | [diff] [blame] | 322 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 323 | |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 324 | size_t offset = fWriter.bytesWritten(); |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 325 | this->addInt(prevOffset); |
commit-bot@chromium.org | dcecb16 | 2014-04-22 17:54:29 +0000 | [diff] [blame] | 326 | fRestoreOffsetStack.top() = SkToU32(offset); |
robertphillips@google.com | 5a63f24 | 2014-02-04 20:07:50 +0000 | [diff] [blame] | 327 | return offset; |
reed@google.com | 45482d1 | 2011-08-29 19:02:39 +0000 | [diff] [blame] | 328 | } |
| 329 | |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 330 | void SkPictureRecord::onClipRect(const SkRect& rect, SkClipOp op, ClipEdgeStyle edgeStyle) { |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame] | 331 | this->recordClipRect(rect, op, kSoft_ClipEdgeStyle == edgeStyle); |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame] | 332 | this->INHERITED::onClipRect(rect, op, edgeStyle); |
robertphillips@google.com | 5a63f24 | 2014-02-04 20:07:50 +0000 | [diff] [blame] | 333 | } |
| 334 | |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 335 | size_t SkPictureRecord::recordClipRect(const SkRect& rect, SkClipOp op, bool doAA) { |
robertphillips@google.com | f929150 | 2013-02-15 15:13:27 +0000 | [diff] [blame] | 336 | // id + rect + clip params |
commit-bot@chromium.org | dcecb16 | 2014-04-22 17:54:29 +0000 | [diff] [blame] | 337 | size_t size = 1 * kUInt32Size + sizeof(rect) + 1 * kUInt32Size; |
robertphillips@google.com | 4310c66 | 2013-03-01 14:17:58 +0000 | [diff] [blame] | 338 | // recordRestoreOffsetPlaceholder doesn't always write an offset |
robertphillips@google.com | f929150 | 2013-02-15 15:13:27 +0000 | [diff] [blame] | 339 | if (!fRestoreOffsetStack.isEmpty()) { |
| 340 | // + restore offset |
| 341 | size += kUInt32Size; |
| 342 | } |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 343 | size_t initialOffset = this->addDraw(CLIP_RECT, &size); |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 344 | this->addRect(rect); |
| 345 | this->addInt(ClipParams_pack(op, doAA)); |
commit-bot@chromium.org | dcecb16 | 2014-04-22 17:54:29 +0000 | [diff] [blame] | 346 | size_t offset = this->recordRestoreOffsetPlaceholder(op); |
skia.committer@gmail.com | 306ab9d | 2012-12-13 02:01:33 +0000 | [diff] [blame] | 347 | |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 348 | this->validate(initialOffset, size); |
robertphillips@google.com | 5a63f24 | 2014-02-04 20:07:50 +0000 | [diff] [blame] | 349 | return offset; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 350 | } |
| 351 | |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 352 | void SkPictureRecord::onClipRRect(const SkRRect& rrect, SkClipOp op, ClipEdgeStyle edgeStyle) { |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame] | 353 | this->recordClipRRect(rrect, op, kSoft_ClipEdgeStyle == edgeStyle); |
reed | d954498 | 2014-09-09 18:46:22 -0700 | [diff] [blame] | 354 | this->INHERITED::onClipRRect(rrect, op, edgeStyle); |
robertphillips@google.com | 5a63f24 | 2014-02-04 20:07:50 +0000 | [diff] [blame] | 355 | } |
| 356 | |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 357 | size_t SkPictureRecord::recordClipRRect(const SkRRect& rrect, SkClipOp op, bool doAA) { |
robertphillips@google.com | f929150 | 2013-02-15 15:13:27 +0000 | [diff] [blame] | 358 | // op + rrect + clip params |
commit-bot@chromium.org | dcecb16 | 2014-04-22 17:54:29 +0000 | [diff] [blame] | 359 | size_t size = 1 * kUInt32Size + SkRRect::kSizeInMemory + 1 * kUInt32Size; |
robertphillips@google.com | 4310c66 | 2013-03-01 14:17:58 +0000 | [diff] [blame] | 360 | // recordRestoreOffsetPlaceholder doesn't always write an offset |
robertphillips@google.com | f929150 | 2013-02-15 15:13:27 +0000 | [diff] [blame] | 361 | if (!fRestoreOffsetStack.isEmpty()) { |
| 362 | // + restore offset |
| 363 | size += kUInt32Size; |
| 364 | } |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 365 | size_t initialOffset = this->addDraw(CLIP_RRECT, &size); |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 366 | this->addRRect(rrect); |
| 367 | this->addInt(ClipParams_pack(op, doAA)); |
commit-bot@chromium.org | dcecb16 | 2014-04-22 17:54:29 +0000 | [diff] [blame] | 368 | size_t offset = recordRestoreOffsetPlaceholder(op); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 369 | this->validate(initialOffset, size); |
robertphillips@google.com | 5a63f24 | 2014-02-04 20:07:50 +0000 | [diff] [blame] | 370 | return offset; |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 371 | } |
| 372 | |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 373 | void SkPictureRecord::onClipPath(const SkPath& path, SkClipOp op, ClipEdgeStyle edgeStyle) { |
robertphillips@google.com | 5a63f24 | 2014-02-04 20:07:50 +0000 | [diff] [blame] | 374 | int pathID = this->addPathToHeap(path); |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame] | 375 | this->recordClipPath(pathID, op, kSoft_ClipEdgeStyle == edgeStyle); |
reed | d954498 | 2014-09-09 18:46:22 -0700 | [diff] [blame] | 376 | this->INHERITED::onClipPath(path, op, edgeStyle); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 377 | } |
| 378 | |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 379 | size_t SkPictureRecord::recordClipPath(int pathID, SkClipOp op, bool doAA) { |
robertphillips@google.com | 5a63f24 | 2014-02-04 20:07:50 +0000 | [diff] [blame] | 380 | // op + path index + clip params |
commit-bot@chromium.org | dcecb16 | 2014-04-22 17:54:29 +0000 | [diff] [blame] | 381 | size_t size = 3 * kUInt32Size; |
robertphillips@google.com | 5a63f24 | 2014-02-04 20:07:50 +0000 | [diff] [blame] | 382 | // recordRestoreOffsetPlaceholder doesn't always write an offset |
| 383 | if (!fRestoreOffsetStack.isEmpty()) { |
| 384 | // + restore offset |
| 385 | size += kUInt32Size; |
| 386 | } |
| 387 | size_t initialOffset = this->addDraw(CLIP_PATH, &size); |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 388 | this->addInt(pathID); |
| 389 | this->addInt(ClipParams_pack(op, doAA)); |
commit-bot@chromium.org | dcecb16 | 2014-04-22 17:54:29 +0000 | [diff] [blame] | 390 | size_t offset = recordRestoreOffsetPlaceholder(op); |
robertphillips@google.com | 5a63f24 | 2014-02-04 20:07:50 +0000 | [diff] [blame] | 391 | this->validate(initialOffset, size); |
| 392 | return offset; |
| 393 | } |
| 394 | |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 395 | void SkPictureRecord::onClipRegion(const SkRegion& region, SkClipOp op) { |
robertphillips@google.com | 5a63f24 | 2014-02-04 20:07:50 +0000 | [diff] [blame] | 396 | this->recordClipRegion(region, op); |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame] | 397 | this->INHERITED::onClipRegion(region, op); |
robertphillips@google.com | 5a63f24 | 2014-02-04 20:07:50 +0000 | [diff] [blame] | 398 | } |
| 399 | |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 400 | size_t SkPictureRecord::recordClipRegion(const SkRegion& region, SkClipOp op) { |
commit-bot@chromium.org | fed2ab6 | 2014-01-23 15:16:05 +0000 | [diff] [blame] | 401 | // op + clip params + region |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 402 | size_t size = 2 * kUInt32Size + region.writeToMemory(nullptr); |
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_REGION, &size); |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 409 | this->addRegion(region); |
| 410 | this->addInt(ClipParams_pack(op, false)); |
commit-bot@chromium.org | dcecb16 | 2014-04-22 17:54:29 +0000 | [diff] [blame] | 411 | size_t offset = this->recordRestoreOffsetPlaceholder(op); |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 412 | |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 413 | this->validate(initialOffset, size); |
robertphillips@google.com | 5a63f24 | 2014-02-04 20:07:50 +0000 | [diff] [blame] | 414 | return offset; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 415 | } |
| 416 | |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 417 | void SkPictureRecord::onDrawPaint(const SkPaint& paint) { |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 418 | // op + paint index |
commit-bot@chromium.org | dcecb16 | 2014-04-22 17:54:29 +0000 | [diff] [blame] | 419 | size_t size = 2 * kUInt32Size; |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 420 | size_t initialOffset = this->addDraw(DRAW_PAINT, &size); |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 421 | this->addPaint(paint); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 422 | this->validate(initialOffset, size); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 423 | } |
| 424 | |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 425 | void SkPictureRecord::onDrawPoints(PointMode mode, size_t count, const SkPoint pts[], |
| 426 | const SkPaint& paint) { |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 427 | // op + paint index + mode + count + point data |
commit-bot@chromium.org | dcecb16 | 2014-04-22 17:54:29 +0000 | [diff] [blame] | 428 | size_t size = 4 * kUInt32Size + count * sizeof(SkPoint); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 429 | size_t initialOffset = this->addDraw(DRAW_POINTS, &size); |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 430 | this->addPaint(paint); |
hendrikw | afdada2 | 2014-08-08 10:44:33 -0700 | [diff] [blame] | 431 | |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 432 | this->addInt(mode); |
commit-bot@chromium.org | dcecb16 | 2014-04-22 17:54:29 +0000 | [diff] [blame] | 433 | this->addInt(SkToInt(count)); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 434 | fWriter.writeMul4(pts, count * sizeof(SkPoint)); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 435 | this->validate(initialOffset, size); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 436 | } |
| 437 | |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 438 | void SkPictureRecord::onDrawOval(const SkRect& oval, const SkPaint& paint) { |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 439 | // op + paint index + rect |
commit-bot@chromium.org | dcecb16 | 2014-04-22 17:54:29 +0000 | [diff] [blame] | 440 | size_t size = 2 * kUInt32Size + sizeof(oval); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 441 | size_t initialOffset = this->addDraw(DRAW_OVAL, &size); |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 442 | this->addPaint(paint); |
| 443 | this->addRect(oval); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 444 | this->validate(initialOffset, size); |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 445 | } |
| 446 | |
bsalomon | ac3aa24 | 2016-08-19 11:25:19 -0700 | [diff] [blame] | 447 | void SkPictureRecord::onDrawArc(const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle, |
| 448 | bool useCenter, const SkPaint& paint) { |
| 449 | // op + paint index + rect + start + sweep + bool (as int) |
| 450 | size_t size = 2 * kUInt32Size + sizeof(oval) + sizeof(startAngle) + sizeof(sweepAngle) + |
| 451 | sizeof(int); |
| 452 | size_t initialOffset = this->addDraw(DRAW_ARC, &size); |
| 453 | this->addPaint(paint); |
| 454 | this->addRect(oval); |
| 455 | this->addScalar(startAngle); |
| 456 | this->addScalar(sweepAngle); |
| 457 | this->addInt(useCenter); |
| 458 | this->validate(initialOffset, size); |
| 459 | } |
| 460 | |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 461 | void SkPictureRecord::onDrawRect(const SkRect& rect, const SkPaint& paint) { |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 462 | // op + paint index + rect |
commit-bot@chromium.org | dcecb16 | 2014-04-22 17:54:29 +0000 | [diff] [blame] | 463 | size_t size = 2 * kUInt32Size + sizeof(rect); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 464 | size_t initialOffset = this->addDraw(DRAW_RECT, &size); |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 465 | this->addPaint(paint); |
| 466 | this->addRect(rect); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 467 | this->validate(initialOffset, size); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 468 | } |
| 469 | |
msarett | 44df651 | 2016-08-25 13:54:30 -0700 | [diff] [blame] | 470 | void SkPictureRecord::onDrawRegion(const SkRegion& region, const SkPaint& paint) { |
| 471 | // op + paint index + region |
| 472 | size_t regionBytes = region.writeToMemory(nullptr); |
| 473 | size_t size = 2 * kUInt32Size + regionBytes; |
| 474 | size_t initialOffset = this->addDraw(DRAW_REGION, &size); |
| 475 | this->addPaint(paint); |
| 476 | fWriter.writeRegion(region); |
| 477 | this->validate(initialOffset, size); |
| 478 | } |
| 479 | |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 480 | void SkPictureRecord::onDrawRRect(const SkRRect& rrect, const SkPaint& paint) { |
mtklein | 46616af | 2014-09-30 14:47:10 -0700 | [diff] [blame] | 481 | // op + paint index + rrect |
| 482 | size_t size = 2 * kUInt32Size + SkRRect::kSizeInMemory; |
| 483 | size_t initialOffset = this->addDraw(DRAW_RRECT, &size); |
mtklein | 46616af | 2014-09-30 14:47:10 -0700 | [diff] [blame] | 484 | this->addPaint(paint); |
| 485 | this->addRRect(rrect); |
| 486 | this->validate(initialOffset, size); |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 487 | } |
| 488 | |
commit-bot@chromium.org | ed9806f | 2014-02-21 02:32:36 +0000 | [diff] [blame] | 489 | void SkPictureRecord::onDrawDRRect(const SkRRect& outer, const SkRRect& inner, |
| 490 | const SkPaint& paint) { |
commit-bot@chromium.org | ed9806f | 2014-02-21 02:32:36 +0000 | [diff] [blame] | 491 | // op + paint index + rrects |
commit-bot@chromium.org | dcecb16 | 2014-04-22 17:54:29 +0000 | [diff] [blame] | 492 | size_t size = 2 * kUInt32Size + SkRRect::kSizeInMemory * 2; |
| 493 | size_t initialOffset = this->addDraw(DRAW_DRRECT, &size); |
commit-bot@chromium.org | ed9806f | 2014-02-21 02:32:36 +0000 | [diff] [blame] | 494 | this->addPaint(paint); |
| 495 | this->addRRect(outer); |
| 496 | this->addRRect(inner); |
| 497 | this->validate(initialOffset, size); |
| 498 | } |
| 499 | |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 500 | void SkPictureRecord::onDrawPath(const SkPath& path, const SkPaint& paint) { |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 501 | // op + paint index + path index |
commit-bot@chromium.org | dcecb16 | 2014-04-22 17:54:29 +0000 | [diff] [blame] | 502 | size_t size = 3 * kUInt32Size; |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 503 | size_t initialOffset = this->addDraw(DRAW_PATH, &size); |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 504 | this->addPaint(paint); |
| 505 | this->addPath(path); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 506 | this->validate(initialOffset, size); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 507 | } |
| 508 | |
reed | a85d4d0 | 2015-05-06 12:56:48 -0700 | [diff] [blame] | 509 | void SkPictureRecord::onDrawImage(const SkImage* image, SkScalar x, SkScalar y, |
| 510 | const SkPaint* paint) { |
reed | 871872f | 2015-06-22 12:48:26 -0700 | [diff] [blame] | 511 | // op + paint_index + image_index + x + y |
| 512 | size_t size = 3 * kUInt32Size + 2 * sizeof(SkScalar); |
| 513 | size_t initialOffset = this->addDraw(DRAW_IMAGE, &size); |
reed | 871872f | 2015-06-22 12:48:26 -0700 | [diff] [blame] | 514 | this->addPaintPtr(paint); |
| 515 | this->addImage(image); |
| 516 | this->addScalar(x); |
| 517 | this->addScalar(y); |
| 518 | this->validate(initialOffset, size); |
reed | a85d4d0 | 2015-05-06 12:56:48 -0700 | [diff] [blame] | 519 | } |
| 520 | |
| 521 | void SkPictureRecord::onDrawImageRect(const SkImage* image, const SkRect* src, const SkRect& dst, |
reed | 562fe47 | 2015-07-28 07:35:14 -0700 | [diff] [blame] | 522 | const SkPaint* paint, SrcRectConstraint constraint) { |
reed | a5517e2 | 2015-07-14 10:54:12 -0700 | [diff] [blame] | 523 | // id + paint_index + image_index + bool_for_src + constraint |
| 524 | size_t size = 5 * kUInt32Size; |
reed | 871872f | 2015-06-22 12:48:26 -0700 | [diff] [blame] | 525 | if (src) { |
| 526 | size += sizeof(*src); // + rect |
reed | a85d4d0 | 2015-05-06 12:56:48 -0700 | [diff] [blame] | 527 | } |
reed | 871872f | 2015-06-22 12:48:26 -0700 | [diff] [blame] | 528 | size += sizeof(dst); // + rect |
mtklein | c2e2977 | 2015-10-30 05:24:58 -0700 | [diff] [blame] | 529 | |
reed | 871872f | 2015-06-22 12:48:26 -0700 | [diff] [blame] | 530 | size_t initialOffset = this->addDraw(DRAW_IMAGE_RECT, &size); |
reed | 871872f | 2015-06-22 12:48:26 -0700 | [diff] [blame] | 531 | this->addPaintPtr(paint); |
| 532 | this->addImage(image); |
| 533 | this->addRectPtr(src); // may be null |
| 534 | this->addRect(dst); |
reed | a5517e2 | 2015-07-14 10:54:12 -0700 | [diff] [blame] | 535 | this->addInt(constraint); |
reed | 871872f | 2015-06-22 12:48:26 -0700 | [diff] [blame] | 536 | this->validate(initialOffset, size); |
reed | a85d4d0 | 2015-05-06 12:56:48 -0700 | [diff] [blame] | 537 | } |
| 538 | |
reed | 4c21dc5 | 2015-06-25 12:32:03 -0700 | [diff] [blame] | 539 | void SkPictureRecord::onDrawImageNine(const SkImage* img, const SkIRect& center, const SkRect& dst, |
| 540 | const SkPaint* paint) { |
| 541 | // id + paint_index + image_index + center + dst |
| 542 | size_t size = 3 * kUInt32Size + sizeof(SkIRect) + sizeof(SkRect); |
mtklein | c2e2977 | 2015-10-30 05:24:58 -0700 | [diff] [blame] | 543 | |
reed | 4c21dc5 | 2015-06-25 12:32:03 -0700 | [diff] [blame] | 544 | size_t initialOffset = this->addDraw(DRAW_IMAGE_NINE, &size); |
reed | 4c21dc5 | 2015-06-25 12:32:03 -0700 | [diff] [blame] | 545 | this->addPaintPtr(paint); |
| 546 | this->addImage(img); |
| 547 | this->addIRect(center); |
| 548 | this->addRect(dst); |
| 549 | this->validate(initialOffset, size); |
| 550 | } |
| 551 | |
msarett | 1688206 | 2016-08-16 09:31:08 -0700 | [diff] [blame] | 552 | void SkPictureRecord::onDrawImageLattice(const SkImage* image, const Lattice& lattice, |
| 553 | const SkRect& dst, const SkPaint* paint) { |
Mike Reed | 7c9c9e4 | 2018-01-03 09:23:34 -0500 | [diff] [blame] | 554 | size_t latticeSize = SkCanvasPriv::WriteLattice(nullptr, lattice); |
msarett | 1688206 | 2016-08-16 09:31:08 -0700 | [diff] [blame] | 555 | // op + paint index + image index + lattice + dst rect |
| 556 | size_t size = 3 * kUInt32Size + latticeSize + sizeof(dst); |
| 557 | size_t initialOffset = this->addDraw(DRAW_IMAGE_LATTICE, &size); |
| 558 | this->addPaintPtr(paint); |
| 559 | this->addImage(image); |
Mike Reed | 7c9c9e4 | 2018-01-03 09:23:34 -0500 | [diff] [blame] | 560 | (void)SkCanvasPriv::WriteLattice(fWriter.reservePad(latticeSize), lattice); |
msarett | 1688206 | 2016-08-16 09:31:08 -0700 | [diff] [blame] | 561 | this->addRect(dst); |
| 562 | this->validate(initialOffset, size); |
| 563 | } |
| 564 | |
Brian Salomon | d003d22 | 2018-11-26 13:25:05 -0500 | [diff] [blame] | 565 | void SkPictureRecord::onDrawImageSet(const SkCanvas::ImageSetEntry set[], int count, |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 566 | SkFilterQuality filterQuality, SkBlendMode mode) { |
Brian Salomon | 1da5cad | 2018-11-21 09:21:18 -0500 | [diff] [blame] | 567 | // op + count + alpha + fq + mode + (image index, src rect, dst rect, alpha, aa flags) * cnt |
Brian Salomon | d003d22 | 2018-11-26 13:25:05 -0500 | [diff] [blame] | 568 | size_t size = |
| 569 | 4 * kUInt32Size + (2 * kUInt32Size + 2 * sizeof(SkRect) + sizeof(SkScalar)) * count; |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 570 | size_t initialOffset = this->addDraw(DRAW_IMAGE_SET, &size); |
| 571 | this->addInt(count); |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 572 | this->addInt((int)filterQuality); |
| 573 | this->addInt((int)mode); |
| 574 | for (int i = 0; i < count; ++i) { |
| 575 | this->addImage(set[i].fImage.get()); |
| 576 | this->addRect(set[i].fSrcRect); |
| 577 | this->addRect(set[i].fDstRect); |
Brian Salomon | 1da5cad | 2018-11-21 09:21:18 -0500 | [diff] [blame] | 578 | this->addScalar(set[i].fAlpha); |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 579 | this->addInt((int)set[i].fAAFlags); |
| 580 | } |
| 581 | this->validate(initialOffset, size); |
| 582 | } |
| 583 | |
fmalita | b742517 | 2014-08-26 07:56:44 -0700 | [diff] [blame] | 584 | void SkPictureRecord::onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y, |
| 585 | const SkPaint& paint) { |
| 586 | |
| 587 | // op + paint index + blob index + x/y |
| 588 | size_t size = 3 * kUInt32Size + 2 * sizeof(SkScalar); |
| 589 | size_t initialOffset = this->addDraw(DRAW_TEXT_BLOB, &size); |
fmalita | b742517 | 2014-08-26 07:56:44 -0700 | [diff] [blame] | 590 | |
| 591 | this->addPaint(paint); |
| 592 | this->addTextBlob(blob); |
| 593 | this->addScalar(x); |
| 594 | this->addScalar(y); |
| 595 | |
| 596 | this->validate(initialOffset, size); |
| 597 | } |
| 598 | |
reed | d5fa1a4 | 2014-08-09 11:08:05 -0700 | [diff] [blame] | 599 | void SkPictureRecord::onDrawPicture(const SkPicture* picture, const SkMatrix* matrix, |
| 600 | const SkPaint* paint) { |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 601 | // op + picture index |
commit-bot@chromium.org | dcecb16 | 2014-04-22 17:54:29 +0000 | [diff] [blame] | 602 | size_t size = 2 * kUInt32Size; |
reed | d5fa1a4 | 2014-08-09 11:08:05 -0700 | [diff] [blame] | 603 | size_t initialOffset; |
| 604 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 605 | if (nullptr == matrix && nullptr == paint) { |
reed | d5fa1a4 | 2014-08-09 11:08:05 -0700 | [diff] [blame] | 606 | initialOffset = this->addDraw(DRAW_PICTURE, &size); |
| 607 | this->addPicture(picture); |
| 608 | } else { |
| 609 | const SkMatrix& m = matrix ? *matrix : SkMatrix::I(); |
Cary Clark | 6d6d603 | 2017-10-20 12:14:33 -0400 | [diff] [blame] | 610 | size += SkMatrixPriv::WriteToMemory(m, nullptr) + kUInt32Size; // matrix + paint |
reed | d5fa1a4 | 2014-08-09 11:08:05 -0700 | [diff] [blame] | 611 | initialOffset = this->addDraw(DRAW_PICTURE_MATRIX_PAINT, &size); |
reed | d5fa1a4 | 2014-08-09 11:08:05 -0700 | [diff] [blame] | 612 | this->addPaintPtr(paint); |
fmalita | 9f49cfd | 2014-08-12 12:24:17 -0700 | [diff] [blame] | 613 | this->addMatrix(m); |
| 614 | this->addPicture(picture); |
reed | d5fa1a4 | 2014-08-09 11:08:05 -0700 | [diff] [blame] | 615 | } |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 616 | this->validate(initialOffset, size); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 617 | } |
| 618 | |
msarett | 95416f4 | 2016-04-27 13:51:20 -0700 | [diff] [blame] | 619 | void SkPictureRecord::onDrawDrawable(SkDrawable* drawable, const SkMatrix* matrix) { |
| 620 | // op + drawable index |
| 621 | size_t size = 2 * kUInt32Size; |
| 622 | size_t initialOffset; |
| 623 | |
| 624 | if (nullptr == matrix) { |
| 625 | initialOffset = this->addDraw(DRAW_DRAWABLE, &size); |
| 626 | this->addDrawable(drawable); |
| 627 | } else { |
Cary Clark | 6d6d603 | 2017-10-20 12:14:33 -0400 | [diff] [blame] | 628 | size += SkMatrixPriv::WriteToMemory(*matrix, nullptr); // matrix |
msarett | 95416f4 | 2016-04-27 13:51:20 -0700 | [diff] [blame] | 629 | initialOffset = this->addDraw(DRAW_DRAWABLE_MATRIX, &size); |
| 630 | this->addMatrix(*matrix); |
| 631 | this->addDrawable(drawable); |
| 632 | } |
| 633 | this->validate(initialOffset, size); |
| 634 | } |
| 635 | |
Ruiqi Mao | c97a339 | 2018-08-15 10:44:19 -0400 | [diff] [blame] | 636 | void SkPictureRecord::onDrawVerticesObject(const SkVertices* vertices, |
| 637 | const SkVertices::Bone bones[], int boneCount, |
| 638 | SkBlendMode mode, const SkPaint& paint) { |
Ruiqi Mao | f510149 | 2018-06-29 14:32:21 -0400 | [diff] [blame] | 639 | // op + paint index + vertices index + number of bones + bone matrices + mode |
Ruiqi Mao | c97a339 | 2018-08-15 10:44:19 -0400 | [diff] [blame] | 640 | size_t size = 5 * kUInt32Size + boneCount * sizeof(SkVertices::Bone); |
Mike Reed | e88a1cb | 2017-03-17 09:50:46 -0400 | [diff] [blame] | 641 | size_t initialOffset = this->addDraw(DRAW_VERTICES_OBJECT, &size); |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 642 | |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 643 | this->addPaint(paint); |
Mike Reed | e88a1cb | 2017-03-17 09:50:46 -0400 | [diff] [blame] | 644 | this->addVertices(vertices); |
Ruiqi Mao | f510149 | 2018-06-29 14:32:21 -0400 | [diff] [blame] | 645 | this->addInt(boneCount); |
Ruiqi Mao | c97a339 | 2018-08-15 10:44:19 -0400 | [diff] [blame] | 646 | fWriter.write(bones, boneCount * sizeof(SkVertices::Bone)); |
Mike Reed | e88a1cb | 2017-03-17 09:50:46 -0400 | [diff] [blame] | 647 | this->addInt(static_cast<uint32_t>(mode)); |
| 648 | |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 649 | this->validate(initialOffset, size); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 650 | } |
| 651 | |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 652 | void SkPictureRecord::onDrawPatch(const SkPoint cubics[12], const SkColor colors[4], |
Mike Reed | faba371 | 2016-11-03 14:45:31 -0400 | [diff] [blame] | 653 | const SkPoint texCoords[4], SkBlendMode bmode, |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 654 | const SkPaint& paint) { |
| 655 | // op + paint index + patch 12 control points + flag + patch 4 colors + 4 texture coordinates |
| 656 | size_t size = 2 * kUInt32Size + SkPatchUtils::kNumCtrlPts * sizeof(SkPoint) + kUInt32Size; |
| 657 | uint32_t flag = 0; |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 658 | if (colors) { |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 659 | flag |= DRAW_VERTICES_HAS_COLORS; |
| 660 | size += SkPatchUtils::kNumCorners * sizeof(SkColor); |
| 661 | } |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 662 | if (texCoords) { |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 663 | flag |= DRAW_VERTICES_HAS_TEXS; |
| 664 | size += SkPatchUtils::kNumCorners * sizeof(SkPoint); |
| 665 | } |
Mike Reed | 7d954ad | 2016-10-28 15:42:34 -0400 | [diff] [blame] | 666 | if (SkBlendMode::kModulate != bmode) { |
| 667 | flag |= DRAW_VERTICES_HAS_XFER; |
| 668 | size += kUInt32Size; |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 669 | } |
mtklein | 46616af | 2014-09-30 14:47:10 -0700 | [diff] [blame] | 670 | |
dandov | 963137b | 2014-08-07 07:49:53 -0700 | [diff] [blame] | 671 | size_t initialOffset = this->addDraw(DRAW_PATCH, &size); |
dandov | 963137b | 2014-08-07 07:49:53 -0700 | [diff] [blame] | 672 | this->addPaint(paint); |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 673 | this->addPatch(cubics); |
| 674 | this->addInt(flag); |
mtklein | 46616af | 2014-09-30 14:47:10 -0700 | [diff] [blame] | 675 | |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 676 | // write optional parameters |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 677 | if (colors) { |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 678 | fWriter.write(colors, SkPatchUtils::kNumCorners * sizeof(SkColor)); |
| 679 | } |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 680 | if (texCoords) { |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 681 | fWriter.write(texCoords, SkPatchUtils::kNumCorners * sizeof(SkPoint)); |
| 682 | } |
| 683 | if (flag & DRAW_VERTICES_HAS_XFER) { |
Mike Reed | 7d954ad | 2016-10-28 15:42:34 -0400 | [diff] [blame] | 684 | this->addInt((int)bmode); |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 685 | } |
dandov | 963137b | 2014-08-07 07:49:53 -0700 | [diff] [blame] | 686 | this->validate(initialOffset, size); |
| 687 | } |
| 688 | |
reed | 71c3c76 | 2015-06-24 10:29:17 -0700 | [diff] [blame] | 689 | void SkPictureRecord::onDrawAtlas(const SkImage* atlas, const SkRSXform xform[], const SkRect tex[], |
Mike Reed | faba371 | 2016-11-03 14:45:31 -0400 | [diff] [blame] | 690 | const SkColor colors[], int count, SkBlendMode mode, |
reed | 71c3c76 | 2015-06-24 10:29:17 -0700 | [diff] [blame] | 691 | const SkRect* cull, const SkPaint* paint) { |
| 692 | // [op + paint-index + atlas-index + flags + count] + [xform] + [tex] + [*colors + mode] + cull |
| 693 | size_t size = 5 * kUInt32Size + count * sizeof(SkRSXform) + count * sizeof(SkRect); |
| 694 | uint32_t flags = 0; |
| 695 | if (colors) { |
| 696 | flags |= DRAW_ATLAS_HAS_COLORS; |
| 697 | size += count * sizeof(SkColor); |
| 698 | size += sizeof(uint32_t); // xfermode::mode |
| 699 | } |
| 700 | if (cull) { |
| 701 | flags |= DRAW_ATLAS_HAS_CULL; |
| 702 | size += sizeof(SkRect); |
| 703 | } |
mtklein | c2e2977 | 2015-10-30 05:24:58 -0700 | [diff] [blame] | 704 | |
reed | 71c3c76 | 2015-06-24 10:29:17 -0700 | [diff] [blame] | 705 | size_t initialOffset = this->addDraw(DRAW_ATLAS, &size); |
reed | 71c3c76 | 2015-06-24 10:29:17 -0700 | [diff] [blame] | 706 | this->addPaintPtr(paint); |
| 707 | this->addImage(atlas); |
| 708 | this->addInt(flags); |
| 709 | this->addInt(count); |
| 710 | fWriter.write(xform, count * sizeof(SkRSXform)); |
| 711 | fWriter.write(tex, count * sizeof(SkRect)); |
| 712 | |
| 713 | // write optional parameters |
| 714 | if (colors) { |
| 715 | fWriter.write(colors, count * sizeof(SkColor)); |
Mike Reed | 7d954ad | 2016-10-28 15:42:34 -0400 | [diff] [blame] | 716 | this->addInt((int)mode); |
reed | 71c3c76 | 2015-06-24 10:29:17 -0700 | [diff] [blame] | 717 | } |
| 718 | if (cull) { |
| 719 | fWriter.write(cull, sizeof(SkRect)); |
| 720 | } |
| 721 | this->validate(initialOffset, size); |
| 722 | } |
| 723 | |
Jim Van Verth | 4123d0f | 2017-05-22 12:02:21 -0400 | [diff] [blame] | 724 | void SkPictureRecord::onDrawShadowRec(const SkPath& path, const SkDrawShadowRec& rec) { |
| 725 | // op + path index + zParams + lightPos + lightRadius + spot/ambient alphas + color + flags |
Mike Reed | 04f8b79 | 2018-01-24 13:48:08 -0500 | [diff] [blame] | 726 | size_t size = 2 * kUInt32Size + 2 * sizeof(SkPoint3) + 1 * sizeof(SkScalar) + 3 * kUInt32Size; |
Jim Van Verth | 4123d0f | 2017-05-22 12:02:21 -0400 | [diff] [blame] | 727 | size_t initialOffset = this->addDraw(DRAW_SHADOW_REC, &size); |
| 728 | |
| 729 | this->addPath(path); |
| 730 | |
| 731 | fWriter.writePoint3(rec.fZPlaneParams); |
| 732 | fWriter.writePoint3(rec.fLightPos); |
| 733 | fWriter.writeScalar(rec.fLightRadius); |
Jim Van Verth | b1b80f7 | 2018-01-18 15:19:13 -0500 | [diff] [blame] | 734 | fWriter.write32(rec.fAmbientColor); |
| 735 | fWriter.write32(rec.fSpotColor); |
Jim Van Verth | 4123d0f | 2017-05-22 12:02:21 -0400 | [diff] [blame] | 736 | fWriter.write32(rec.fFlags); |
| 737 | |
| 738 | this->validate(initialOffset, size); |
| 739 | } |
| 740 | |
reed | f70b531 | 2016-03-04 16:36:20 -0800 | [diff] [blame] | 741 | void SkPictureRecord::onDrawAnnotation(const SkRect& rect, const char key[], SkData* value) { |
| 742 | size_t keyLen = fWriter.WriteStringSize(key); |
| 743 | size_t valueLen = fWriter.WriteDataSize(value); |
| 744 | size_t size = 4 + sizeof(SkRect) + keyLen + valueLen; |
| 745 | |
| 746 | size_t initialOffset = this->addDraw(DRAW_ANNOTATION, &size); |
| 747 | this->addRect(rect); |
| 748 | fWriter.writeString(key); |
| 749 | fWriter.writeData(value); |
| 750 | this->validate(initialOffset, size); |
| 751 | } |
| 752 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 753 | /////////////////////////////////////////////////////////////////////////////// |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 754 | |
Florin Malita | 8fd15d8 | 2018-05-15 14:57:12 -0400 | [diff] [blame] | 755 | // De-duping helper. |
| 756 | |
| 757 | template <typename T> |
| 758 | static bool equals(T* a, T* b) { return a->uniqueID() == b->uniqueID(); } |
| 759 | |
| 760 | template <> |
| 761 | bool equals(SkDrawable* a, SkDrawable* b) { |
| 762 | // SkDrawable's generationID is not a stable unique identifier. |
| 763 | return a == b; |
| 764 | } |
| 765 | |
| 766 | template <typename T> |
| 767 | static int find_or_append(SkTArray<sk_sp<T>>& array, T* obj) { |
Mike Klein | bd000a1 | 2018-04-19 09:24:57 -0400 | [diff] [blame] | 768 | for (int i = 0; i < array.count(); i++) { |
Florin Malita | 8fd15d8 | 2018-05-15 14:57:12 -0400 | [diff] [blame] | 769 | if (equals(array[i].get(), obj)) { |
Mike Klein | bd000a1 | 2018-04-19 09:24:57 -0400 | [diff] [blame] | 770 | return i; |
| 771 | } |
reed | 22b2af1 | 2016-08-29 07:52:13 -0700 | [diff] [blame] | 772 | } |
Florin Malita | 8fd15d8 | 2018-05-15 14:57:12 -0400 | [diff] [blame] | 773 | |
| 774 | array.push_back(sk_ref_sp(obj)); |
| 775 | |
| 776 | return array.count() - 1; |
reed | 22b2af1 | 2016-08-29 07:52:13 -0700 | [diff] [blame] | 777 | } |
| 778 | |
reed | e8f3062 | 2016-03-23 18:59:25 -0700 | [diff] [blame] | 779 | sk_sp<SkSurface> SkPictureRecord::onNewSurface(const SkImageInfo& info, const SkSurfaceProps&) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 780 | return nullptr; |
reed@google.com | 76f10a3 | 2014-02-05 15:32:21 +0000 | [diff] [blame] | 781 | } |
| 782 | |
reed | 871872f | 2015-06-22 12:48:26 -0700 | [diff] [blame] | 783 | void SkPictureRecord::addImage(const SkImage* image) { |
reed | 22b2af1 | 2016-08-29 07:52:13 -0700 | [diff] [blame] | 784 | // convention for images is 0-based index |
Florin Malita | 8fd15d8 | 2018-05-15 14:57:12 -0400 | [diff] [blame] | 785 | this->addInt(find_or_append(fImages, image)); |
reed | 871872f | 2015-06-22 12:48:26 -0700 | [diff] [blame] | 786 | } |
| 787 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 788 | void SkPictureRecord::addMatrix(const SkMatrix& matrix) { |
commit-bot@chromium.org | fed2ab6 | 2014-01-23 15:16:05 +0000 | [diff] [blame] | 789 | fWriter.writeMatrix(matrix); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 790 | } |
| 791 | |
mtklein | 46616af | 2014-09-30 14:47:10 -0700 | [diff] [blame] | 792 | void SkPictureRecord::addPaintPtr(const SkPaint* paint) { |
mtklein | 46616af | 2014-09-30 14:47:10 -0700 | [diff] [blame] | 793 | if (paint) { |
mtklein | a74ce85 | 2014-11-12 09:19:02 -0800 | [diff] [blame] | 794 | fPaints.push_back(*paint); |
| 795 | this->addInt(fPaints.count()); |
mtklein | 46616af | 2014-09-30 14:47:10 -0700 | [diff] [blame] | 796 | } else { |
| 797 | this->addInt(0); |
| 798 | } |
commit-bot@chromium.org | cf7be95 | 2013-08-22 17:19:52 +0000 | [diff] [blame] | 799 | } |
| 800 | |
robertphillips@google.com | 5a63f24 | 2014-02-04 20:07:50 +0000 | [diff] [blame] | 801 | int SkPictureRecord::addPathToHeap(const SkPath& path) { |
mtklein | c2e2977 | 2015-10-30 05:24:58 -0700 | [diff] [blame] | 802 | if (int* n = fPaths.find(path)) { |
| 803 | return *n; |
| 804 | } |
| 805 | int n = fPaths.count() + 1; // 0 is reserved for null / error. |
| 806 | fPaths.set(path, n); |
| 807 | return n; |
robertphillips@google.com | 5a63f24 | 2014-02-04 20:07:50 +0000 | [diff] [blame] | 808 | } |
| 809 | |
| 810 | void SkPictureRecord::addPath(const SkPath& path) { |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 811 | this->addInt(this->addPathToHeap(path)); |
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::addPatch(const SkPoint cubics[12]) { |
| 815 | fWriter.write(cubics, SkPatchUtils::kNumCtrlPts * sizeof(SkPoint)); |
dandov | 963137b | 2014-08-07 07:49:53 -0700 | [diff] [blame] | 816 | } |
| 817 | |
robertphillips | 9b14f26 | 2014-06-04 05:40:44 -0700 | [diff] [blame] | 818 | void SkPictureRecord::addPicture(const SkPicture* picture) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 819 | // follow the convention of recording a 1-based index |
Florin Malita | 8fd15d8 | 2018-05-15 14:57:12 -0400 | [diff] [blame] | 820 | this->addInt(find_or_append(fPictures, picture) + 1); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 821 | } |
| 822 | |
msarett | 95416f4 | 2016-04-27 13:51:20 -0700 | [diff] [blame] | 823 | void SkPictureRecord::addDrawable(SkDrawable* drawable) { |
msarett | 95416f4 | 2016-04-27 13:51:20 -0700 | [diff] [blame] | 824 | // follow the convention of recording a 1-based index |
Florin Malita | 8fd15d8 | 2018-05-15 14:57:12 -0400 | [diff] [blame] | 825 | this->addInt(find_or_append(fDrawables, drawable) + 1); |
msarett | 95416f4 | 2016-04-27 13:51:20 -0700 | [diff] [blame] | 826 | } |
| 827 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 828 | void SkPictureRecord::addPoint(const SkPoint& point) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 829 | fWriter.writePoint(point); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 830 | } |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 831 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 832 | void SkPictureRecord::addPoints(const SkPoint pts[], int count) { |
| 833 | fWriter.writeMul4(pts, count * sizeof(SkPoint)); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 834 | } |
| 835 | |
senorblanco@chromium.org | 68250c8 | 2014-05-06 22:52:55 +0000 | [diff] [blame] | 836 | void SkPictureRecord::addNoOp() { |
| 837 | size_t size = kUInt32Size; // op |
| 838 | this->addDraw(NOOP, &size); |
| 839 | } |
| 840 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 841 | void SkPictureRecord::addRect(const SkRect& rect) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 842 | fWriter.writeRect(rect); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 843 | } |
| 844 | |
| 845 | void SkPictureRecord::addRectPtr(const SkRect* rect) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 846 | if (fWriter.writeBool(rect != nullptr)) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 847 | fWriter.writeRect(*rect); |
| 848 | } |
| 849 | } |
| 850 | |
reed@google.com | f0b5e11 | 2011-09-07 11:57:34 +0000 | [diff] [blame] | 851 | void SkPictureRecord::addIRect(const SkIRect& rect) { |
| 852 | fWriter.write(&rect, sizeof(rect)); |
| 853 | } |
| 854 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 855 | void SkPictureRecord::addIRectPtr(const SkIRect* rect) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 856 | if (fWriter.writeBool(rect != nullptr)) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 857 | *(SkIRect*)fWriter.reserve(sizeof(SkIRect)) = *rect; |
| 858 | } |
| 859 | } |
| 860 | |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 861 | void SkPictureRecord::addRRect(const SkRRect& rrect) { |
| 862 | fWriter.writeRRect(rrect); |
| 863 | } |
| 864 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 865 | void SkPictureRecord::addRegion(const SkRegion& region) { |
commit-bot@chromium.org | fed2ab6 | 2014-01-23 15:16:05 +0000 | [diff] [blame] | 866 | fWriter.writeRegion(region); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 867 | } |
| 868 | |
| 869 | void SkPictureRecord::addText(const void* text, size_t byteLength) { |
commit-bot@chromium.org | dcecb16 | 2014-04-22 17:54:29 +0000 | [diff] [blame] | 870 | addInt(SkToInt(byteLength)); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 871 | fWriter.writePad(text, byteLength); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 872 | } |
| 873 | |
reed | 22b2af1 | 2016-08-29 07:52:13 -0700 | [diff] [blame] | 874 | void SkPictureRecord::addTextBlob(const SkTextBlob* blob) { |
fmalita | b742517 | 2014-08-26 07:56:44 -0700 | [diff] [blame] | 875 | // follow the convention of recording a 1-based index |
Florin Malita | 8fd15d8 | 2018-05-15 14:57:12 -0400 | [diff] [blame] | 876 | this->addInt(find_or_append(fTextBlobs, blob) + 1); |
fmalita | b742517 | 2014-08-26 07:56:44 -0700 | [diff] [blame] | 877 | } |
| 878 | |
Mike Reed | e88a1cb | 2017-03-17 09:50:46 -0400 | [diff] [blame] | 879 | void SkPictureRecord::addVertices(const SkVertices* vertices) { |
| 880 | // follow the convention of recording a 1-based index |
Florin Malita | 8fd15d8 | 2018-05-15 14:57:12 -0400 | [diff] [blame] | 881 | this->addInt(find_or_append(fVertices, vertices) + 1); |
Mike Reed | e88a1cb | 2017-03-17 09:50:46 -0400 | [diff] [blame] | 882 | } |
| 883 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 884 | /////////////////////////////////////////////////////////////////////////////// |