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