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