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" |
| 9 | #include "SkTSearch.h" |
junov@chromium.org | 4866cc0 | 2012-06-01 21:23:07 +0000 | [diff] [blame] | 10 | #include "SkPixelRef.h" |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 11 | #include "SkRRect.h" |
rileya@google.com | 9f5898d | 2012-09-11 20:21:44 +0000 | [diff] [blame] | 12 | #include "SkBBoxHierarchy.h" |
junov@chromium.org | d575eed | 2013-05-08 15:39:13 +0000 | [diff] [blame] | 13 | #include "SkDevice.h" |
rileya@google.com | 9f5898d | 2012-09-11 20:21:44 +0000 | [diff] [blame] | 14 | #include "SkPictureStateTree.h" |
reed@google.com | 76f10a3 | 2014-02-05 15:32:21 +0000 | [diff] [blame] | 15 | #include "SkSurface.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 16 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 17 | #define HEAP_BLOCK_SIZE 4096 |
| 18 | |
junov@chromium.org | 4e6dfa5 | 2012-07-16 14:04:59 +0000 | [diff] [blame] | 19 | enum { |
reed@google.com | d86e7ab | 2012-09-27 20:31:31 +0000 | [diff] [blame] | 20 | // just need a value that save or getSaveCount would never return |
junov@chromium.org | 4e6dfa5 | 2012-07-16 14:04:59 +0000 | [diff] [blame] | 21 | kNoInitialSave = -1, |
| 22 | }; |
| 23 | |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 24 | // A lot of basic types get stored as a uint32_t: bools, ints, paint indices, etc. |
| 25 | static int const kUInt32Size = 4; |
| 26 | |
djsollen@google.com | d423657 | 2013-08-13 14:29:06 +0000 | [diff] [blame] | 27 | static const uint32_t kSaveSize = 2 * kUInt32Size; |
robertphillips@google.com | e37ad35 | 2013-03-01 19:44:30 +0000 | [diff] [blame] | 28 | static const uint32_t kSaveLayerNoBoundsSize = 4 * kUInt32Size; |
| 29 | static const uint32_t kSaveLayerWithBoundsSize = 4 * kUInt32Size + sizeof(SkRect); |
| 30 | |
commit-bot@chromium.org | 19fafef | 2014-02-17 15:28:00 +0000 | [diff] [blame] | 31 | SkPictureRecord::SkPictureRecord(const SkISize& dimensions, uint32_t flags) |
| 32 | : INHERITED(dimensions.width(), dimensions.height()) |
robertphillips@google.com | 5a63f24 | 2014-02-04 20:07:50 +0000 | [diff] [blame] | 33 | , fBoundingHierarchy(NULL) |
| 34 | , fStateTree(NULL) |
| 35 | , fFlattenableHeap(HEAP_BLOCK_SIZE) |
| 36 | , fPaints(&fFlattenableHeap) |
| 37 | , fRecordFlags(flags) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 38 | #ifdef SK_DEBUG_SIZE |
| 39 | fPointBytes = fRectBytes = fTextBytes = 0; |
| 40 | fPointWrites = fRectWrites = fTextWrites = 0; |
| 41 | #endif |
| 42 | |
djsollen@google.com | c9ab987 | 2012-08-29 18:52:07 +0000 | [diff] [blame] | 43 | fBitmapHeap = SkNEW(SkBitmapHeap); |
| 44 | fFlattenableHeap.setBitmapStorage(fBitmapHeap); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 45 | fPathHeap = NULL; // lazy allocate |
robertphillips@google.com | 105a4a5 | 2014-02-11 15:10:40 +0000 | [diff] [blame] | 46 | #ifndef SK_COLLAPSE_MATRIX_CLIP_STATE |
junov@chromium.org | 8f9ecbd | 2012-02-13 21:53:45 +0000 | [diff] [blame] | 47 | fFirstSavedLayerIndex = kNoSavedLayerIndex; |
robertphillips@google.com | 105a4a5 | 2014-02-11 15:10:40 +0000 | [diff] [blame] | 48 | #endif |
reed@google.com | d86e7ab | 2012-09-27 20:31:31 +0000 | [diff] [blame] | 49 | |
| 50 | fInitialSaveCount = kNoInitialSave; |
robertphillips@google.com | 105a4a5 | 2014-02-11 15:10:40 +0000 | [diff] [blame] | 51 | |
| 52 | #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE |
| 53 | fMCMgr.init(this); |
| 54 | #endif |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | SkPictureRecord::~SkPictureRecord() { |
djsollen@google.com | c9ab987 | 2012-08-29 18:52:07 +0000 | [diff] [blame] | 58 | SkSafeUnref(fBitmapHeap); |
djsollen@google.com | 21830d9 | 2012-08-07 19:49:41 +0000 | [diff] [blame] | 59 | SkSafeUnref(fPathHeap); |
rileya@google.com | 9f5898d | 2012-09-11 20:21:44 +0000 | [diff] [blame] | 60 | SkSafeUnref(fBoundingHierarchy); |
| 61 | SkSafeUnref(fStateTree); |
djsollen@google.com | 21830d9 | 2012-08-07 19:49:41 +0000 | [diff] [blame] | 62 | fFlattenableHeap.setBitmapStorage(NULL); |
| 63 | fPictureRefs.unrefAll(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | /////////////////////////////////////////////////////////////////////////////// |
| 67 | |
robertphillips@google.com | e37ad35 | 2013-03-01 19:44:30 +0000 | [diff] [blame] | 68 | // Return the offset of the paint inside a given op's byte stream. A zero |
| 69 | // return value means there is no paint (and you really shouldn't be calling |
| 70 | // this method) |
| 71 | static inline uint32_t getPaintOffset(DrawType op, uint32_t opSize) { |
| 72 | // These offsets are where the paint would be if the op size doesn't overflow |
skia.committer@gmail.com | f140f18 | 2013-03-02 07:01:56 +0000 | [diff] [blame] | 73 | static const uint8_t gPaintOffsets[LAST_DRAWTYPE_ENUM + 1] = { |
robertphillips@google.com | e37ad35 | 2013-03-01 19:44:30 +0000 | [diff] [blame] | 74 | 0, // UNUSED - no paint |
| 75 | 0, // CLIP_PATH - no paint |
| 76 | 0, // CLIP_REGION - no paint |
| 77 | 0, // CLIP_RECT - no paint |
| 78 | 0, // CLIP_RRECT - no paint |
| 79 | 0, // CONCAT - no paint |
| 80 | 1, // DRAW_BITMAP - right after op code |
| 81 | 1, // DRAW_BITMAP_MATRIX - right after op code |
| 82 | 1, // DRAW_BITMAP_NINE - right after op code |
| 83 | 1, // DRAW_BITMAP_RECT_TO_RECT - right after op code |
| 84 | 0, // DRAW_CLEAR - no paint |
| 85 | 0, // DRAW_DATA - no paint |
| 86 | 1, // DRAW_OVAL - right after op code |
| 87 | 1, // DRAW_PAINT - right after op code |
| 88 | 1, // DRAW_PATH - right after op code |
| 89 | 0, // DRAW_PICTURE - no paint |
| 90 | 1, // DRAW_POINTS - right after op code |
| 91 | 1, // DRAW_POS_TEXT - right after op code |
| 92 | 1, // DRAW_POS_TEXT_TOP_BOTTOM - right after op code |
| 93 | 1, // DRAW_POS_TEXT_H - right after op code |
| 94 | 1, // DRAW_POS_TEXT_H_TOP_BOTTOM - right after op code |
| 95 | 1, // DRAW_RECT - right after op code |
| 96 | 1, // DRAW_RRECT - right after op code |
| 97 | 1, // DRAW_SPRITE - right after op code |
| 98 | 1, // DRAW_TEXT - right after op code |
| 99 | 1, // DRAW_TEXT_ON_PATH - right after op code |
| 100 | 1, // DRAW_TEXT_TOP_BOTTOM - right after op code |
| 101 | 1, // DRAW_VERTICES - right after op code |
| 102 | 0, // RESTORE - no paint |
| 103 | 0, // ROTATE - no paint |
| 104 | 0, // SAVE - no paint |
skia.committer@gmail.com | f140f18 | 2013-03-02 07:01:56 +0000 | [diff] [blame] | 105 | 0, // SAVE_LAYER - see below - this paint's location varies |
robertphillips@google.com | e37ad35 | 2013-03-01 19:44:30 +0000 | [diff] [blame] | 106 | 0, // SCALE - no paint |
| 107 | 0, // SET_MATRIX - no paint |
| 108 | 0, // SKEW - no paint |
| 109 | 0, // TRANSLATE - no paint |
| 110 | 0, // NOOP - no paint |
robertphillips@google.com | 0a4805e | 2013-05-29 13:24:23 +0000 | [diff] [blame] | 111 | 0, // BEGIN_GROUP - no paint |
| 112 | 0, // COMMENT - no paint |
| 113 | 0, // END_GROUP - no paint |
commit-bot@chromium.org | ed9806f | 2014-02-21 02:32:36 +0000 | [diff] [blame] | 114 | 1, // DRAWDRRECT - right after op code |
commit-bot@chromium.org | 210ae2a | 2014-02-27 17:40:13 +0000 | [diff] [blame] | 115 | 0, // PUSH_CULL - no paint |
| 116 | 0, // POP_CULL - no paint |
skia.committer@gmail.com | f140f18 | 2013-03-02 07:01:56 +0000 | [diff] [blame] | 117 | }; |
robertphillips@google.com | e37ad35 | 2013-03-01 19:44:30 +0000 | [diff] [blame] | 118 | |
commit-bot@chromium.org | ed9806f | 2014-02-21 02:32:36 +0000 | [diff] [blame] | 119 | SK_COMPILE_ASSERT(sizeof(gPaintOffsets) == LAST_DRAWTYPE_ENUM + 1, |
| 120 | need_to_be_in_sync); |
robertphillips@google.com | e37ad35 | 2013-03-01 19:44:30 +0000 | [diff] [blame] | 121 | SkASSERT((unsigned)op <= (unsigned)LAST_DRAWTYPE_ENUM); |
| 122 | |
| 123 | int overflow = 0; |
| 124 | if (0 != (opSize & ~MASK_24) || opSize == MASK_24) { |
| 125 | // This op's size overflows so an extra uint32_t will be written |
| 126 | // after the op code |
| 127 | overflow = sizeof(uint32_t); |
| 128 | } |
| 129 | |
| 130 | if (SAVE_LAYER == op) { |
| 131 | static const uint32_t kSaveLayerNoBoundsPaintOffset = 2 * kUInt32Size; |
| 132 | static const uint32_t kSaveLayerWithBoundsPaintOffset = 2 * kUInt32Size + sizeof(SkRect); |
| 133 | |
| 134 | if (kSaveLayerNoBoundsSize == opSize) { |
| 135 | return kSaveLayerNoBoundsPaintOffset + overflow; |
| 136 | } else { |
| 137 | SkASSERT(kSaveLayerWithBoundsSize == opSize); |
| 138 | return kSaveLayerWithBoundsPaintOffset + overflow; |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | SkASSERT(0 != gPaintOffsets[op]); // really shouldn't be calling this method |
| 143 | return gPaintOffsets[op] * sizeof(uint32_t) + overflow; |
| 144 | } |
| 145 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 146 | int SkPictureRecord::save(SaveFlags flags) { |
robertphillips@google.com | 105a4a5 | 2014-02-11 15:10:40 +0000 | [diff] [blame] | 147 | |
| 148 | #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE |
| 149 | fMCMgr.save(flags); |
| 150 | #else |
reed@google.com | ffacd3c | 2012-08-30 15:31:23 +0000 | [diff] [blame] | 151 | // record the offset to us, making it non-positive to distinguish a save |
| 152 | // from a clip entry. |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 153 | fRestoreOffsetStack.push(-(int32_t)fWriter.bytesWritten()); |
robertphillips@google.com | 5a63f24 | 2014-02-04 20:07:50 +0000 | [diff] [blame] | 154 | this->recordSave(flags); |
robertphillips@google.com | 105a4a5 | 2014-02-11 15:10:40 +0000 | [diff] [blame] | 155 | #endif |
robertphillips@google.com | 5a63f24 | 2014-02-04 20:07:50 +0000 | [diff] [blame] | 156 | return this->INHERITED::save(flags); |
| 157 | } |
skia.committer@gmail.com | 11f8692 | 2012-08-31 17:14:46 +0000 | [diff] [blame] | 158 | |
robertphillips@google.com | 5a63f24 | 2014-02-04 20:07:50 +0000 | [diff] [blame] | 159 | void SkPictureRecord::recordSave(SaveFlags flags) { |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 160 | // op + flags |
djsollen@google.com | d423657 | 2013-08-13 14:29:06 +0000 | [diff] [blame] | 161 | uint32_t size = kSaveSize; |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 162 | size_t initialOffset = this->addDraw(SAVE, &size); |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 163 | this->addInt(flags); |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 164 | |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 165 | this->validate(initialOffset, size); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | int SkPictureRecord::saveLayer(const SkRect* bounds, const SkPaint* paint, |
| 169 | SaveFlags flags) { |
robertphillips@google.com | 105a4a5 | 2014-02-11 15:10:40 +0000 | [diff] [blame] | 170 | |
| 171 | int count; |
| 172 | #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE |
| 173 | count = fMCMgr.saveLayer(bounds, paint, flags); |
| 174 | #else |
reed@google.com | ffacd3c | 2012-08-30 15:31:23 +0000 | [diff] [blame] | 175 | // record the offset to us, making it non-positive to distinguish a save |
| 176 | // from a clip entry. |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 177 | fRestoreOffsetStack.push(-(int32_t)fWriter.bytesWritten()); |
robertphillips@google.com | 5a63f24 | 2014-02-04 20:07:50 +0000 | [diff] [blame] | 178 | this->recordSaveLayer(bounds, paint, flags); |
| 179 | if (kNoSavedLayerIndex == fFirstSavedLayerIndex) { |
| 180 | fFirstSavedLayerIndex = fRestoreOffsetStack.count(); |
| 181 | } |
robertphillips@google.com | 105a4a5 | 2014-02-11 15:10:40 +0000 | [diff] [blame] | 182 | #endif |
skia.committer@gmail.com | 11f8692 | 2012-08-31 17:14:46 +0000 | [diff] [blame] | 183 | |
robertphillips@google.com | 5a63f24 | 2014-02-04 20:07:50 +0000 | [diff] [blame] | 184 | /* Don't actually call INHERITED::saveLayer, because that will try to allocate |
| 185 | an offscreen device (potentially very big) which we don't actually need |
| 186 | at this time (and may not be able to afford since during record our |
| 187 | clip starts out the size of the picture, which is often much larger |
| 188 | than the size of the actual device we'll use during playback). |
| 189 | */ |
robertphillips@google.com | 105a4a5 | 2014-02-11 15:10:40 +0000 | [diff] [blame] | 190 | count = this->INHERITED::save(flags); |
robertphillips@google.com | 5a63f24 | 2014-02-04 20:07:50 +0000 | [diff] [blame] | 191 | this->clipRectBounds(bounds, flags, NULL); |
| 192 | return count; |
| 193 | } |
| 194 | |
| 195 | void SkPictureRecord::recordSaveLayer(const SkRect* bounds, const SkPaint* paint, |
robertphillips@google.com | 105a4a5 | 2014-02-11 15:10:40 +0000 | [diff] [blame] | 196 | SaveFlags flags) { |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 197 | // op + bool for 'bounds' |
skia.committer@gmail.com | ce8343d | 2013-02-16 07:01:31 +0000 | [diff] [blame] | 198 | uint32_t size = 2 * kUInt32Size; |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 199 | if (NULL != bounds) { |
| 200 | size += sizeof(*bounds); // + rect |
| 201 | } |
| 202 | // + paint index + flags |
| 203 | size += 2 * kUInt32Size; |
| 204 | |
robertphillips@google.com | e37ad35 | 2013-03-01 19:44:30 +0000 | [diff] [blame] | 205 | SkASSERT(kSaveLayerNoBoundsSize == size || kSaveLayerWithBoundsSize == size); |
| 206 | |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 207 | size_t initialOffset = this->addDraw(SAVE_LAYER, &size); |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 208 | this->addRectPtr(bounds); |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 209 | SkASSERT(initialOffset+getPaintOffset(SAVE_LAYER, size) == fWriter.bytesWritten()); |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 210 | this->addPaintPtr(paint); |
| 211 | this->addInt(flags); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 212 | |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 213 | this->validate(initialOffset, size); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 214 | } |
| 215 | |
junov@chromium.org | 8f9ecbd | 2012-02-13 21:53:45 +0000 | [diff] [blame] | 216 | bool SkPictureRecord::isDrawingToLayer() const { |
robertphillips@google.com | 105a4a5 | 2014-02-11 15:10:40 +0000 | [diff] [blame] | 217 | #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE |
| 218 | return fMCMgr.isDrawingToLayer(); |
| 219 | #else |
junov@chromium.org | 8f9ecbd | 2012-02-13 21:53:45 +0000 | [diff] [blame] | 220 | return fFirstSavedLayerIndex != kNoSavedLayerIndex; |
robertphillips@google.com | 105a4a5 | 2014-02-11 15:10:40 +0000 | [diff] [blame] | 221 | #endif |
junov@chromium.org | 8f9ecbd | 2012-02-13 21:53:45 +0000 | [diff] [blame] | 222 | } |
| 223 | |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 224 | /* |
commit-bot@chromium.org | 210ae2a | 2014-02-27 17:40:13 +0000 | [diff] [blame] | 225 | * Read the op code from 'offset' in 'writer'. |
| 226 | */ |
| 227 | #ifdef SK_DEBUG |
| 228 | static DrawType peek_op(SkWriter32* writer, int32_t offset) { |
| 229 | return (DrawType)(writer->readTAt<uint32_t>(offset) >> 24); |
| 230 | } |
| 231 | #endif |
| 232 | |
| 233 | /* |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 234 | * Read the op code from 'offset' in 'writer' and extract the size too. |
| 235 | */ |
| 236 | static DrawType peek_op_and_size(SkWriter32* writer, int32_t offset, uint32_t* size) { |
commit-bot@chromium.org | 536ac5e | 2014-02-11 22:38:51 +0000 | [diff] [blame] | 237 | uint32_t peek = writer->readTAt<uint32_t>(offset); |
reed@google.com | ffacd3c | 2012-08-30 15:31:23 +0000 | [diff] [blame] | 238 | |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 239 | uint32_t op; |
commit-bot@chromium.org | c6d3c44 | 2014-01-31 16:22:57 +0000 | [diff] [blame] | 240 | UNPACK_8_24(peek, op, *size); |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 241 | if (MASK_24 == *size) { |
| 242 | // size required its own slot right after the op code |
commit-bot@chromium.org | 536ac5e | 2014-02-11 22:38:51 +0000 | [diff] [blame] | 243 | *size = writer->readTAt<uint32_t>(offset + kUInt32Size); |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 244 | } |
| 245 | return (DrawType) op; |
reed@google.com | ffacd3c | 2012-08-30 15:31:23 +0000 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | #ifdef TRACK_COLLAPSE_STATS |
| 249 | static int gCollapseCount, gCollapseCalls; |
| 250 | #endif |
| 251 | |
robertphillips@google.com | e37ad35 | 2013-03-01 19:44:30 +0000 | [diff] [blame] | 252 | // Is the supplied paint simply a color? |
| 253 | static bool is_simple(const SkPaint& p) { |
skia.committer@gmail.com | f140f18 | 2013-03-02 07:01:56 +0000 | [diff] [blame] | 254 | intptr_t orAccum = (intptr_t)p.getPathEffect() | |
robertphillips@google.com | e37ad35 | 2013-03-01 19:44:30 +0000 | [diff] [blame] | 255 | (intptr_t)p.getShader() | |
| 256 | (intptr_t)p.getXfermode() | |
| 257 | (intptr_t)p.getMaskFilter() | |
| 258 | (intptr_t)p.getColorFilter() | |
| 259 | (intptr_t)p.getRasterizer() | |
| 260 | (intptr_t)p.getLooper() | |
| 261 | (intptr_t)p.getImageFilter(); |
| 262 | return 0 == orAccum; |
| 263 | } |
| 264 | |
robertphillips@google.com | b8f9610 | 2013-03-12 15:39:44 +0000 | [diff] [blame] | 265 | // CommandInfos are fed to the 'match' method and filled in with command |
skia.committer@gmail.com | 91274b9 | 2013-03-13 07:01:04 +0000 | [diff] [blame] | 266 | // information. |
robertphillips@google.com | b8f9610 | 2013-03-12 15:39:44 +0000 | [diff] [blame] | 267 | struct CommandInfo { |
| 268 | DrawType fActualOp; |
| 269 | uint32_t fOffset; |
| 270 | uint32_t fSize; |
| 271 | }; |
| 272 | |
reed@google.com | ffacd3c | 2012-08-30 15:31:23 +0000 | [diff] [blame] | 273 | /* |
robertphillips@google.com | b8f9610 | 2013-03-12 15:39:44 +0000 | [diff] [blame] | 274 | * Attempt to match the provided pattern of commands starting at 'offset' |
skia.committer@gmail.com | 91274b9 | 2013-03-13 07:01:04 +0000 | [diff] [blame] | 275 | * in the byte stream and stopping at the end of the stream. Upon success, |
robertphillips@google.com | b8f9610 | 2013-03-12 15:39:44 +0000 | [diff] [blame] | 276 | * return true with all the pattern information filled out in the result |
| 277 | * array (i.e., actual ops, offsets and sizes). |
| 278 | * Note this method skips any NOOPs seen in the stream |
| 279 | */ |
| 280 | static bool match(SkWriter32* writer, uint32_t offset, |
| 281 | int* pattern, CommandInfo* result, int numCommands) { |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 282 | SkASSERT(offset < writer->bytesWritten()); |
robertphillips@google.com | b8f9610 | 2013-03-12 15:39:44 +0000 | [diff] [blame] | 283 | |
| 284 | uint32_t curOffset = offset; |
| 285 | uint32_t curSize = 0; |
robertphillips@google.com | c04987f | 2013-03-12 17:53:53 +0000 | [diff] [blame] | 286 | int numMatched; |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 287 | for (numMatched = 0; numMatched < numCommands && curOffset < writer->bytesWritten(); ++numMatched) { |
robertphillips@google.com | b8f9610 | 2013-03-12 15:39:44 +0000 | [diff] [blame] | 288 | DrawType op = peek_op_and_size(writer, curOffset, &curSize); |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 289 | while (NOOP == op && curOffset < writer->bytesWritten()) { |
robertphillips@google.com | b8f9610 | 2013-03-12 15:39:44 +0000 | [diff] [blame] | 290 | curOffset += curSize; |
| 291 | op = peek_op_and_size(writer, curOffset, &curSize); |
| 292 | } |
| 293 | |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 294 | if (curOffset >= writer->bytesWritten()) { |
robertphillips@google.com | b8f9610 | 2013-03-12 15:39:44 +0000 | [diff] [blame] | 295 | return false; // ran out of byte stream |
| 296 | } |
| 297 | |
robertphillips@google.com | c04987f | 2013-03-12 17:53:53 +0000 | [diff] [blame] | 298 | if (kDRAW_BITMAP_FLAVOR == pattern[numMatched]) { |
robertphillips@google.com | b8f9610 | 2013-03-12 15:39:44 +0000 | [diff] [blame] | 299 | if (DRAW_BITMAP != op && DRAW_BITMAP_MATRIX != op && |
| 300 | DRAW_BITMAP_NINE != op && DRAW_BITMAP_RECT_TO_RECT != op) { |
| 301 | return false; |
| 302 | } |
robertphillips@google.com | c04987f | 2013-03-12 17:53:53 +0000 | [diff] [blame] | 303 | } else if (op != pattern[numMatched]) { |
robertphillips@google.com | b8f9610 | 2013-03-12 15:39:44 +0000 | [diff] [blame] | 304 | return false; |
| 305 | } |
| 306 | |
robertphillips@google.com | c04987f | 2013-03-12 17:53:53 +0000 | [diff] [blame] | 307 | result[numMatched].fActualOp = op; |
| 308 | result[numMatched].fOffset = curOffset; |
| 309 | result[numMatched].fSize = curSize; |
robertphillips@google.com | b8f9610 | 2013-03-12 15:39:44 +0000 | [diff] [blame] | 310 | |
| 311 | curOffset += curSize; |
| 312 | } |
| 313 | |
robertphillips@google.com | c04987f | 2013-03-12 17:53:53 +0000 | [diff] [blame] | 314 | if (numMatched != numCommands) { |
| 315 | return false; |
| 316 | } |
| 317 | |
robertphillips@google.com | b8f9610 | 2013-03-12 15:39:44 +0000 | [diff] [blame] | 318 | curOffset += curSize; |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 319 | if (curOffset < writer->bytesWritten()) { |
robertphillips@google.com | b8f9610 | 2013-03-12 15:39:44 +0000 | [diff] [blame] | 320 | // Something else between the last command and the end of the stream |
| 321 | return false; |
| 322 | } |
| 323 | |
| 324 | return true; |
| 325 | } |
| 326 | |
| 327 | // temporarily here to make code review easier |
| 328 | static bool merge_savelayer_paint_into_drawbitmp(SkWriter32* writer, |
| 329 | SkPaintDictionary* paintDict, |
| 330 | const CommandInfo& saveLayerInfo, |
| 331 | const CommandInfo& dbmInfo); |
| 332 | |
| 333 | /* |
skia.committer@gmail.com | 91274b9 | 2013-03-13 07:01:04 +0000 | [diff] [blame] | 334 | * Restore has just been called (but not recorded), look back at the |
robertphillips@google.com | e37ad35 | 2013-03-01 19:44:30 +0000 | [diff] [blame] | 335 | * matching save* and see if we are in the configuration: |
| 336 | * SAVE_LAYER |
| 337 | * DRAW_BITMAP|DRAW_BITMAP_MATRIX|DRAW_BITMAP_NINE|DRAW_BITMAP_RECT_TO_RECT |
| 338 | * RESTORE |
| 339 | * where the saveLayer's color can be moved into the drawBitmap*'s paint |
| 340 | */ |
skia.committer@gmail.com | f140f18 | 2013-03-02 07:01:56 +0000 | [diff] [blame] | 341 | static bool remove_save_layer1(SkWriter32* writer, int32_t offset, |
robertphillips@google.com | e37ad35 | 2013-03-01 19:44:30 +0000 | [diff] [blame] | 342 | SkPaintDictionary* paintDict) { |
robertphillips@google.com | e37ad35 | 2013-03-01 19:44:30 +0000 | [diff] [blame] | 343 | // back up to the save block |
| 344 | // TODO: add a stack to track save*/restore offsets rather than searching backwards |
| 345 | while (offset > 0) { |
commit-bot@chromium.org | 536ac5e | 2014-02-11 22:38:51 +0000 | [diff] [blame] | 346 | offset = writer->readTAt<uint32_t>(offset); |
robertphillips@google.com | e37ad35 | 2013-03-01 19:44:30 +0000 | [diff] [blame] | 347 | } |
| 348 | |
robertphillips@google.com | b8f9610 | 2013-03-12 15:39:44 +0000 | [diff] [blame] | 349 | int pattern[] = { SAVE_LAYER, kDRAW_BITMAP_FLAVOR, /* RESTORE */ }; |
| 350 | CommandInfo result[SK_ARRAY_COUNT(pattern)]; |
| 351 | |
| 352 | if (!match(writer, -offset, pattern, result, SK_ARRAY_COUNT(pattern))) { |
| 353 | return false; |
robertphillips@google.com | e37ad35 | 2013-03-01 19:44:30 +0000 | [diff] [blame] | 354 | } |
| 355 | |
robertphillips@google.com | b8f9610 | 2013-03-12 15:39:44 +0000 | [diff] [blame] | 356 | if (kSaveLayerWithBoundsSize == result[0].fSize) { |
robertphillips@google.com | e37ad35 | 2013-03-01 19:44:30 +0000 | [diff] [blame] | 357 | // The saveLayer's bound can offset where the dbm is drawn |
| 358 | return false; |
| 359 | } |
| 360 | |
robertphillips@google.com | b8f9610 | 2013-03-12 15:39:44 +0000 | [diff] [blame] | 361 | return merge_savelayer_paint_into_drawbitmp(writer, paintDict, |
| 362 | result[0], result[1]); |
| 363 | } |
robertphillips@google.com | e37ad35 | 2013-03-01 19:44:30 +0000 | [diff] [blame] | 364 | |
robertphillips@google.com | b8f9610 | 2013-03-12 15:39:44 +0000 | [diff] [blame] | 365 | /* |
| 366 | * Convert the command code located at 'offset' to a NOOP. Leave the size |
| 367 | * field alone so the NOOP can be skipped later. |
| 368 | */ |
| 369 | static void convert_command_to_noop(SkWriter32* writer, uint32_t offset) { |
commit-bot@chromium.org | 536ac5e | 2014-02-11 22:38:51 +0000 | [diff] [blame] | 370 | uint32_t command = writer->readTAt<uint32_t>(offset); |
| 371 | writer->overwriteTAt(offset, (command & MASK_24) | (NOOP << 24)); |
robertphillips@google.com | b8f9610 | 2013-03-12 15:39:44 +0000 | [diff] [blame] | 372 | } |
robertphillips@google.com | e37ad35 | 2013-03-01 19:44:30 +0000 | [diff] [blame] | 373 | |
robertphillips@google.com | b8f9610 | 2013-03-12 15:39:44 +0000 | [diff] [blame] | 374 | /* |
| 375 | * Attempt to merge the saveLayer's paint into the drawBitmap*'s paint. |
| 376 | * Return true on success; false otherwise. |
| 377 | */ |
| 378 | static bool merge_savelayer_paint_into_drawbitmp(SkWriter32* writer, |
| 379 | SkPaintDictionary* paintDict, |
| 380 | const CommandInfo& saveLayerInfo, |
| 381 | const CommandInfo& dbmInfo) { |
| 382 | SkASSERT(SAVE_LAYER == saveLayerInfo.fActualOp); |
skia.committer@gmail.com | 91274b9 | 2013-03-13 07:01:04 +0000 | [diff] [blame] | 383 | SkASSERT(DRAW_BITMAP == dbmInfo.fActualOp || |
robertphillips@google.com | b8f9610 | 2013-03-12 15:39:44 +0000 | [diff] [blame] | 384 | DRAW_BITMAP_MATRIX == dbmInfo.fActualOp || |
skia.committer@gmail.com | 91274b9 | 2013-03-13 07:01:04 +0000 | [diff] [blame] | 385 | DRAW_BITMAP_NINE == dbmInfo.fActualOp || |
robertphillips@google.com | b8f9610 | 2013-03-12 15:39:44 +0000 | [diff] [blame] | 386 | DRAW_BITMAP_RECT_TO_RECT == dbmInfo.fActualOp); |
| 387 | |
| 388 | uint32_t dbmPaintOffset = getPaintOffset(dbmInfo.fActualOp, dbmInfo.fSize); |
| 389 | uint32_t slPaintOffset = getPaintOffset(SAVE_LAYER, saveLayerInfo.fSize); |
robertphillips@google.com | e37ad35 | 2013-03-01 19:44:30 +0000 | [diff] [blame] | 390 | |
| 391 | // we have a match, now we need to get the paints involved |
commit-bot@chromium.org | 536ac5e | 2014-02-11 22:38:51 +0000 | [diff] [blame] | 392 | uint32_t dbmPaintId = writer->readTAt<uint32_t>(dbmInfo.fOffset + dbmPaintOffset); |
| 393 | uint32_t saveLayerPaintId = writer->readTAt<uint32_t>(saveLayerInfo.fOffset + slPaintOffset); |
robertphillips@google.com | e37ad35 | 2013-03-01 19:44:30 +0000 | [diff] [blame] | 394 | |
| 395 | if (0 == saveLayerPaintId) { |
| 396 | // In this case the saveLayer/restore isn't needed at all - just kill the saveLayer |
| 397 | // and signal the caller (by returning true) to not add the RESTORE op |
robertphillips@google.com | b8f9610 | 2013-03-12 15:39:44 +0000 | [diff] [blame] | 398 | convert_command_to_noop(writer, saveLayerInfo.fOffset); |
robertphillips@google.com | e37ad35 | 2013-03-01 19:44:30 +0000 | [diff] [blame] | 399 | return true; |
skia.committer@gmail.com | f140f18 | 2013-03-02 07:01:56 +0000 | [diff] [blame] | 400 | } |
| 401 | |
robertphillips@google.com | e37ad35 | 2013-03-01 19:44:30 +0000 | [diff] [blame] | 402 | if (0 == dbmPaintId) { |
| 403 | // In this case just make the DBM* use the saveLayer's paint, kill the saveLayer |
| 404 | // and signal the caller (by returning true) to not add the RESTORE op |
robertphillips@google.com | b8f9610 | 2013-03-12 15:39:44 +0000 | [diff] [blame] | 405 | convert_command_to_noop(writer, saveLayerInfo.fOffset); |
commit-bot@chromium.org | 536ac5e | 2014-02-11 22:38:51 +0000 | [diff] [blame] | 406 | writer->overwriteTAt(dbmInfo.fOffset + dbmPaintOffset, saveLayerPaintId); |
robertphillips@google.com | e37ad35 | 2013-03-01 19:44:30 +0000 | [diff] [blame] | 407 | return true; |
skia.committer@gmail.com | f140f18 | 2013-03-02 07:01:56 +0000 | [diff] [blame] | 408 | } |
robertphillips@google.com | e37ad35 | 2013-03-01 19:44:30 +0000 | [diff] [blame] | 409 | |
| 410 | SkAutoTDelete<SkPaint> saveLayerPaint(paintDict->unflatten(saveLayerPaintId)); |
| 411 | if (NULL == saveLayerPaint.get() || !is_simple(*saveLayerPaint)) { |
| 412 | return false; |
| 413 | } |
| 414 | |
| 415 | // For this optimization we only fold the saveLayer and drawBitmapRect |
| 416 | // together if the saveLayer's draw is simple (i.e., no fancy effects) and |
| 417 | // and the only difference in the colors is that the saveLayer's can have |
| 418 | // an alpha while the drawBitmapRect's is opaque. |
| 419 | // TODO: it should be possible to fold them together even if they both |
| 420 | // have different non-255 alphas |
| 421 | SkColor layerColor = saveLayerPaint->getColor() | 0xFF000000; // force opaque |
| 422 | |
| 423 | SkAutoTDelete<SkPaint> dbmPaint(paintDict->unflatten(dbmPaintId)); |
| 424 | if (NULL == dbmPaint.get() || dbmPaint->getColor() != layerColor) { |
| 425 | return false; |
| 426 | } |
skia.committer@gmail.com | f140f18 | 2013-03-02 07:01:56 +0000 | [diff] [blame] | 427 | |
robertphillips@google.com | e37ad35 | 2013-03-01 19:44:30 +0000 | [diff] [blame] | 428 | SkColor newColor = SkColorSetA(dbmPaint->getColor(), |
| 429 | SkColorGetA(saveLayerPaint->getColor())); |
| 430 | dbmPaint->setColor(newColor); |
| 431 | |
commit-bot@chromium.org | cf7be95 | 2013-08-22 17:19:52 +0000 | [diff] [blame] | 432 | const SkFlatData* data = paintDict->findAndReturnFlat(*dbmPaint); |
| 433 | if (NULL == data) { |
| 434 | return false; |
| 435 | } |
robertphillips@google.com | e37ad35 | 2013-03-01 19:44:30 +0000 | [diff] [blame] | 436 | |
| 437 | // kill the saveLayer and alter the DBMR2R's paint to be the modified one |
robertphillips@google.com | b8f9610 | 2013-03-12 15:39:44 +0000 | [diff] [blame] | 438 | convert_command_to_noop(writer, saveLayerInfo.fOffset); |
commit-bot@chromium.org | 536ac5e | 2014-02-11 22:38:51 +0000 | [diff] [blame] | 439 | writer->overwriteTAt(dbmInfo.fOffset + dbmPaintOffset, data->index()); |
robertphillips@google.com | e37ad35 | 2013-03-01 19:44:30 +0000 | [diff] [blame] | 440 | return true; |
| 441 | } |
| 442 | |
robertphillips@google.com | b8f9610 | 2013-03-12 15:39:44 +0000 | [diff] [blame] | 443 | /* |
skia.committer@gmail.com | 91274b9 | 2013-03-13 07:01:04 +0000 | [diff] [blame] | 444 | * Restore has just been called (but not recorded), look back at the |
robertphillips@google.com | b8f9610 | 2013-03-12 15:39:44 +0000 | [diff] [blame] | 445 | * matching save* and see if we are in the configuration: |
robertphillips@google.com | ad7d481 | 2013-04-12 15:13:35 +0000 | [diff] [blame] | 446 | * SAVE_LAYER (with NULL == bounds) |
robertphillips@google.com | b8f9610 | 2013-03-12 15:39:44 +0000 | [diff] [blame] | 447 | * SAVE |
| 448 | * CLIP_RECT |
| 449 | * DRAW_BITMAP|DRAW_BITMAP_MATRIX|DRAW_BITMAP_NINE|DRAW_BITMAP_RECT_TO_RECT |
| 450 | * RESTORE |
| 451 | * RESTORE |
| 452 | * where the saveLayer's color can be moved into the drawBitmap*'s paint |
| 453 | */ |
| 454 | static bool remove_save_layer2(SkWriter32* writer, int32_t offset, |
| 455 | SkPaintDictionary* paintDict) { |
| 456 | |
| 457 | // back up to the save block |
| 458 | // TODO: add a stack to track save*/restore offsets rather than searching backwards |
| 459 | while (offset > 0) { |
commit-bot@chromium.org | 536ac5e | 2014-02-11 22:38:51 +0000 | [diff] [blame] | 460 | offset = writer->readTAt<uint32_t>(offset); |
robertphillips@google.com | b8f9610 | 2013-03-12 15:39:44 +0000 | [diff] [blame] | 461 | } |
| 462 | |
| 463 | int pattern[] = { SAVE_LAYER, SAVE, CLIP_RECT, kDRAW_BITMAP_FLAVOR, RESTORE, /* RESTORE */ }; |
| 464 | CommandInfo result[SK_ARRAY_COUNT(pattern)]; |
| 465 | |
| 466 | if (!match(writer, -offset, pattern, result, SK_ARRAY_COUNT(pattern))) { |
| 467 | return false; |
| 468 | } |
| 469 | |
| 470 | if (kSaveLayerWithBoundsSize == result[0].fSize) { |
| 471 | // The saveLayer's bound can offset where the dbm is drawn |
| 472 | return false; |
| 473 | } |
| 474 | |
| 475 | return merge_savelayer_paint_into_drawbitmp(writer, paintDict, |
| 476 | result[0], result[3]); |
| 477 | } |
robertphillips@google.com | e37ad35 | 2013-03-01 19:44:30 +0000 | [diff] [blame] | 478 | |
commit-bot@chromium.org | ed9806f | 2014-02-21 02:32:36 +0000 | [diff] [blame] | 479 | static bool is_drawing_op(DrawType op) { |
| 480 | return (op > CONCAT && op < ROTATE) || DRAW_DRRECT == op; |
| 481 | } |
| 482 | |
robertphillips@google.com | e37ad35 | 2013-03-01 19:44:30 +0000 | [diff] [blame] | 483 | /* |
| 484 | * Restore has just been called (but not recorded), so look back at the |
reed@google.com | ffacd3c | 2012-08-30 15:31:23 +0000 | [diff] [blame] | 485 | * matching save(), and see if we can eliminate the pair of them, due to no |
| 486 | * intervening matrix/clip calls. |
| 487 | * |
| 488 | * If so, update the writer and return true, in which case we won't even record |
| 489 | * the restore() call. If we still need the restore(), return false. |
| 490 | */ |
robertphillips@google.com | b8f9610 | 2013-03-12 15:39:44 +0000 | [diff] [blame] | 491 | static bool collapse_save_clip_restore(SkWriter32* writer, int32_t offset, |
| 492 | SkPaintDictionary* paintDict) { |
reed@google.com | ffacd3c | 2012-08-30 15:31:23 +0000 | [diff] [blame] | 493 | #ifdef TRACK_COLLAPSE_STATS |
| 494 | gCollapseCalls += 1; |
| 495 | #endif |
| 496 | |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 497 | int32_t restoreOffset = (int32_t)writer->bytesWritten(); |
reed@google.com | ffacd3c | 2012-08-30 15:31:23 +0000 | [diff] [blame] | 498 | |
| 499 | // back up to the save block |
| 500 | while (offset > 0) { |
commit-bot@chromium.org | 536ac5e | 2014-02-11 22:38:51 +0000 | [diff] [blame] | 501 | offset = writer->readTAt<uint32_t>(offset); |
reed@google.com | ffacd3c | 2012-08-30 15:31:23 +0000 | [diff] [blame] | 502 | } |
| 503 | |
| 504 | // now offset points to a save |
| 505 | offset = -offset; |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 506 | uint32_t opSize; |
| 507 | DrawType op = peek_op_and_size(writer, offset, &opSize); |
| 508 | if (SAVE_LAYER == op) { |
reed@google.com | ffacd3c | 2012-08-30 15:31:23 +0000 | [diff] [blame] | 509 | // not ready to cull these out yet (mrr) |
| 510 | return false; |
| 511 | } |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 512 | SkASSERT(SAVE == op); |
djsollen@google.com | d423657 | 2013-08-13 14:29:06 +0000 | [diff] [blame] | 513 | SkASSERT(kSaveSize == opSize); |
| 514 | |
| 515 | // get the save flag (last 4-bytes of the space allocated for the opSize) |
commit-bot@chromium.org | 536ac5e | 2014-02-11 22:38:51 +0000 | [diff] [blame] | 516 | SkCanvas::SaveFlags saveFlags = (SkCanvas::SaveFlags) writer->readTAt<uint32_t>(offset + 4); |
djsollen@google.com | d423657 | 2013-08-13 14:29:06 +0000 | [diff] [blame] | 517 | if (SkCanvas::kMatrixClip_SaveFlag != saveFlags) { |
| 518 | // This function's optimization is only correct for kMatrixClip style saves. |
| 519 | // TODO: set checkMatrix & checkClip booleans here and then check for the |
| 520 | // offending operations in the following loop. |
| 521 | return false; |
| 522 | } |
reed@google.com | ffacd3c | 2012-08-30 15:31:23 +0000 | [diff] [blame] | 523 | |
| 524 | // Walk forward until we get back to either a draw-verb (abort) or we hit |
| 525 | // our restore (success). |
| 526 | int32_t saveOffset = offset; |
| 527 | |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 528 | offset += opSize; |
reed@google.com | ffacd3c | 2012-08-30 15:31:23 +0000 | [diff] [blame] | 529 | while (offset < restoreOffset) { |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 530 | op = peek_op_and_size(writer, offset, &opSize); |
commit-bot@chromium.org | ed9806f | 2014-02-21 02:32:36 +0000 | [diff] [blame] | 531 | if (is_drawing_op(op) || (SAVE_LAYER == op)) { |
reed@google.com | ffacd3c | 2012-08-30 15:31:23 +0000 | [diff] [blame] | 532 | // drawing verb, abort |
| 533 | return false; |
| 534 | } |
| 535 | offset += opSize; |
| 536 | } |
skia.committer@gmail.com | 11f8692 | 2012-08-31 17:14:46 +0000 | [diff] [blame] | 537 | |
reed@google.com | ffacd3c | 2012-08-30 15:31:23 +0000 | [diff] [blame] | 538 | #ifdef TRACK_COLLAPSE_STATS |
| 539 | gCollapseCount += 1; |
| 540 | SkDebugf("Collapse [%d out of %d] %g%spn", gCollapseCount, gCollapseCalls, |
| 541 | (double)gCollapseCount / gCollapseCalls, "%"); |
| 542 | #endif |
| 543 | |
| 544 | writer->rewindToOffset(saveOffset); |
| 545 | return true; |
| 546 | } |
| 547 | |
robertphillips@google.com | b8f9610 | 2013-03-12 15:39:44 +0000 | [diff] [blame] | 548 | typedef bool (*PictureRecordOptProc)(SkWriter32* writer, int32_t offset, |
| 549 | SkPaintDictionary* paintDict); |
commit-bot@chromium.org | 4b32bd5 | 2013-03-15 15:06:03 +0000 | [diff] [blame] | 550 | enum PictureRecordOptType { |
| 551 | kRewind_OptType, // Optimization rewinds the command stream |
| 552 | kCollapseSaveLayer_OptType, // Optimization eliminates a save/restore pair |
| 553 | }; |
robertphillips@google.com | b8f9610 | 2013-03-12 15:39:44 +0000 | [diff] [blame] | 554 | |
commit-bot@chromium.org | 44e8657 | 2013-11-22 19:42:13 +0000 | [diff] [blame] | 555 | enum PictureRecordOptFlags { |
| 556 | kSkipIfBBoxHierarchy_Flag = 0x1, // Optimization should be skipped if the |
| 557 | // SkPicture has a bounding box hierarchy. |
| 558 | }; |
| 559 | |
commit-bot@chromium.org | 4b32bd5 | 2013-03-15 15:06:03 +0000 | [diff] [blame] | 560 | struct PictureRecordOpt { |
| 561 | PictureRecordOptProc fProc; |
| 562 | PictureRecordOptType fType; |
commit-bot@chromium.org | 44e8657 | 2013-11-22 19:42:13 +0000 | [diff] [blame] | 563 | unsigned fFlags; |
commit-bot@chromium.org | 4b32bd5 | 2013-03-15 15:06:03 +0000 | [diff] [blame] | 564 | }; |
robertphillips@google.com | b8f9610 | 2013-03-12 15:39:44 +0000 | [diff] [blame] | 565 | /* |
| 566 | * A list of the optimizations that are tried upon seeing a restore |
| 567 | * TODO: add a real API for such optimizations |
| 568 | * Add the ability to fire optimizations on any op (not just RESTORE) |
| 569 | */ |
commit-bot@chromium.org | 4b32bd5 | 2013-03-15 15:06:03 +0000 | [diff] [blame] | 570 | static const PictureRecordOpt gPictureRecordOpts[] = { |
commit-bot@chromium.org | 44e8657 | 2013-11-22 19:42:13 +0000 | [diff] [blame] | 571 | // 'collapse_save_clip_restore' is skipped if there is a BBoxHierarchy |
| 572 | // because it is redundant with the state traversal optimization in |
| 573 | // SkPictureStateTree, and applying the optimization introduces significant |
| 574 | // record time overhead because it requires rewinding contents that were |
| 575 | // recorded into the BBoxHierarchy. |
| 576 | { collapse_save_clip_restore, kRewind_OptType, kSkipIfBBoxHierarchy_Flag }, |
| 577 | { remove_save_layer1, kCollapseSaveLayer_OptType, 0 }, |
| 578 | { remove_save_layer2, kCollapseSaveLayer_OptType, 0 } |
robertphillips@google.com | b8f9610 | 2013-03-12 15:39:44 +0000 | [diff] [blame] | 579 | }; |
| 580 | |
commit-bot@chromium.org | 4b32bd5 | 2013-03-15 15:06:03 +0000 | [diff] [blame] | 581 | // This is called after an optimization has been applied to the command stream |
| 582 | // in order to adjust the contents and state of the bounding box hierarchy and |
| 583 | // state tree to reflect the optimization. |
| 584 | static void apply_optimization_to_bbh(PictureRecordOptType opt, SkPictureStateTree* stateTree, |
| 585 | SkBBoxHierarchy* boundingHierarchy) { |
| 586 | switch (opt) { |
| 587 | case kCollapseSaveLayer_OptType: |
robertphillips@google.com | 35e1563 | 2013-03-15 16:49:34 +0000 | [diff] [blame] | 588 | if (NULL != stateTree) { |
| 589 | stateTree->saveCollapsed(); |
| 590 | } |
commit-bot@chromium.org | 4b32bd5 | 2013-03-15 15:06:03 +0000 | [diff] [blame] | 591 | break; |
| 592 | case kRewind_OptType: |
| 593 | if (NULL != boundingHierarchy) { |
| 594 | boundingHierarchy->rewindInserts(); |
| 595 | } |
| 596 | // Note: No need to touch the state tree for this to work correctly. |
| 597 | // Unused branches do not burden the playback, and pruning the tree |
| 598 | // would be O(N^2), so it is best to leave it alone. |
| 599 | break; |
| 600 | default: |
| 601 | SkASSERT(0); |
| 602 | } |
| 603 | } |
| 604 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 605 | void SkPictureRecord::restore() { |
junov@chromium.org | 4e6dfa5 | 2012-07-16 14:04:59 +0000 | [diff] [blame] | 606 | // FIXME: SkDeferredCanvas needs to be refactored to respect |
| 607 | // save/restore balancing so that the following test can be |
| 608 | // turned on permanently. |
| 609 | #if 0 |
| 610 | SkASSERT(fRestoreOffsetStack.count() > 1); |
| 611 | #endif |
| 612 | |
robertphillips@google.com | 105a4a5 | 2014-02-11 15:10:40 +0000 | [diff] [blame] | 613 | #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE |
| 614 | if (fMCMgr.getSaveCount() == 1) { |
| 615 | return; |
| 616 | } |
| 617 | |
robertphillips@google.com | 105a4a5 | 2014-02-11 15:10:40 +0000 | [diff] [blame] | 618 | fMCMgr.restore(); |
| 619 | #else |
reed@android.com | b4e22d6 | 2009-07-09 15:20:25 +0000 | [diff] [blame] | 620 | // check for underflow |
| 621 | if (fRestoreOffsetStack.count() == 0) { |
| 622 | return; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 623 | } |
reed@android.com | b4e22d6 | 2009-07-09 15:20:25 +0000 | [diff] [blame] | 624 | |
junov@chromium.org | 8f9ecbd | 2012-02-13 21:53:45 +0000 | [diff] [blame] | 625 | if (fRestoreOffsetStack.count() == fFirstSavedLayerIndex) { |
| 626 | fFirstSavedLayerIndex = kNoSavedLayerIndex; |
| 627 | } |
| 628 | |
robertphillips@google.com | 31d8191 | 2013-04-12 15:24:29 +0000 | [diff] [blame] | 629 | size_t opt = 0; |
robertphillips@google.com | ad7d481 | 2013-04-12 15:13:35 +0000 | [diff] [blame] | 630 | if (!(fRecordFlags & SkPicture::kDisableRecordOptimizations_RecordingFlag)) { |
| 631 | for (opt = 0; opt < SK_ARRAY_COUNT(gPictureRecordOpts); ++opt) { |
commit-bot@chromium.org | 44e8657 | 2013-11-22 19:42:13 +0000 | [diff] [blame] | 632 | if (0 != (gPictureRecordOpts[opt].fFlags & kSkipIfBBoxHierarchy_Flag) |
| 633 | && NULL != fBoundingHierarchy) { |
| 634 | continue; |
| 635 | } |
robertphillips@google.com | ad7d481 | 2013-04-12 15:13:35 +0000 | [diff] [blame] | 636 | if ((*gPictureRecordOpts[opt].fProc)(&fWriter, fRestoreOffsetStack.top(), &fPaints)) { |
| 637 | // Some optimization fired so don't add the RESTORE |
robertphillips@google.com | ad7d481 | 2013-04-12 15:13:35 +0000 | [diff] [blame] | 638 | apply_optimization_to_bbh(gPictureRecordOpts[opt].fType, |
| 639 | fStateTree, fBoundingHierarchy); |
| 640 | break; |
| 641 | } |
robertphillips@google.com | b8f9610 | 2013-03-12 15:39:44 +0000 | [diff] [blame] | 642 | } |
skia.committer@gmail.com | 4bb50b2 | 2013-04-13 07:01:15 +0000 | [diff] [blame] | 643 | } |
robertphillips@google.com | b8f9610 | 2013-03-12 15:39:44 +0000 | [diff] [blame] | 644 | |
robertphillips@google.com | ad7d481 | 2013-04-12 15:13:35 +0000 | [diff] [blame] | 645 | if ((fRecordFlags & SkPicture::kDisableRecordOptimizations_RecordingFlag) || |
| 646 | SK_ARRAY_COUNT(gPictureRecordOpts) == opt) { |
robertphillips@google.com | b8f9610 | 2013-03-12 15:39:44 +0000 | [diff] [blame] | 647 | // No optimization fired so add the RESTORE |
robertphillips@google.com | 5a63f24 | 2014-02-04 20:07:50 +0000 | [diff] [blame] | 648 | this->recordRestore(); |
reed@google.com | ffacd3c | 2012-08-30 15:31:23 +0000 | [diff] [blame] | 649 | } |
| 650 | |
reed@android.com | b4e22d6 | 2009-07-09 15:20:25 +0000 | [diff] [blame] | 651 | fRestoreOffsetStack.pop(); |
robertphillips@google.com | 105a4a5 | 2014-02-11 15:10:40 +0000 | [diff] [blame] | 652 | #endif |
reed@android.com | 32a4249 | 2009-07-10 03:33:52 +0000 | [diff] [blame] | 653 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 654 | return this->INHERITED::restore(); |
| 655 | } |
| 656 | |
robertphillips@google.com | 105a4a5 | 2014-02-11 15:10:40 +0000 | [diff] [blame] | 657 | void SkPictureRecord::recordRestore(bool fillInSkips) { |
robertphillips@google.com | 5a63f24 | 2014-02-04 20:07:50 +0000 | [diff] [blame] | 658 | uint32_t initialOffset, size; |
robertphillips@google.com | 105a4a5 | 2014-02-11 15:10:40 +0000 | [diff] [blame] | 659 | if (fillInSkips) { |
| 660 | this->fillRestoreOffsetPlaceholdersForCurrentStackLevel((uint32_t)fWriter.bytesWritten()); |
| 661 | } |
robertphillips@google.com | 5a63f24 | 2014-02-04 20:07:50 +0000 | [diff] [blame] | 662 | size = 1 * kUInt32Size; // RESTORE consists solely of 1 op code |
| 663 | initialOffset = this->addDraw(RESTORE, &size); |
| 664 | this->validate(initialOffset, size); |
| 665 | } |
| 666 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 667 | bool SkPictureRecord::translate(SkScalar dx, SkScalar dy) { |
robertphillips@google.com | 105a4a5 | 2014-02-11 15:10:40 +0000 | [diff] [blame] | 668 | #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE |
| 669 | fMCMgr.translate(dx, dy); |
| 670 | #else |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 671 | // op + dx + dy |
| 672 | uint32_t size = 1 * kUInt32Size + 2 * sizeof(SkScalar); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 673 | size_t initialOffset = this->addDraw(TRANSLATE, &size); |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 674 | this->addScalar(dx); |
| 675 | this->addScalar(dy); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 676 | this->validate(initialOffset, size); |
robertphillips@google.com | 105a4a5 | 2014-02-11 15:10:40 +0000 | [diff] [blame] | 677 | #endif |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 678 | return this->INHERITED::translate(dx, dy); |
| 679 | } |
| 680 | |
| 681 | bool SkPictureRecord::scale(SkScalar sx, SkScalar sy) { |
robertphillips@google.com | 105a4a5 | 2014-02-11 15:10:40 +0000 | [diff] [blame] | 682 | |
| 683 | #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE |
| 684 | fMCMgr.scale(sx, sy); |
| 685 | #else |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 686 | // op + sx + sy |
| 687 | uint32_t size = 1 * kUInt32Size + 2 * sizeof(SkScalar); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 688 | size_t initialOffset = this->addDraw(SCALE, &size); |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 689 | this->addScalar(sx); |
| 690 | this->addScalar(sy); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 691 | this->validate(initialOffset, size); |
robertphillips@google.com | 105a4a5 | 2014-02-11 15:10:40 +0000 | [diff] [blame] | 692 | #endif |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 693 | return this->INHERITED::scale(sx, sy); |
| 694 | } |
| 695 | |
| 696 | bool SkPictureRecord::rotate(SkScalar degrees) { |
robertphillips@google.com | 105a4a5 | 2014-02-11 15:10:40 +0000 | [diff] [blame] | 697 | |
| 698 | #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE |
| 699 | fMCMgr.rotate(degrees); |
| 700 | #else |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 701 | // op + degrees |
| 702 | uint32_t size = 1 * kUInt32Size + sizeof(SkScalar); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 703 | size_t initialOffset = this->addDraw(ROTATE, &size); |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 704 | this->addScalar(degrees); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 705 | this->validate(initialOffset, size); |
robertphillips@google.com | 105a4a5 | 2014-02-11 15:10:40 +0000 | [diff] [blame] | 706 | #endif |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 707 | return this->INHERITED::rotate(degrees); |
| 708 | } |
| 709 | |
| 710 | bool SkPictureRecord::skew(SkScalar sx, SkScalar sy) { |
robertphillips@google.com | 105a4a5 | 2014-02-11 15:10:40 +0000 | [diff] [blame] | 711 | |
| 712 | #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE |
| 713 | fMCMgr.skew(sx, sy); |
| 714 | #else |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 715 | // op + sx + sy |
| 716 | uint32_t size = 1 * kUInt32Size + 2 * sizeof(SkScalar); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 717 | size_t initialOffset = this->addDraw(SKEW, &size); |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 718 | this->addScalar(sx); |
| 719 | this->addScalar(sy); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 720 | this->validate(initialOffset, size); |
robertphillips@google.com | 105a4a5 | 2014-02-11 15:10:40 +0000 | [diff] [blame] | 721 | #endif |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 722 | return this->INHERITED::skew(sx, sy); |
| 723 | } |
| 724 | |
| 725 | bool SkPictureRecord::concat(const SkMatrix& matrix) { |
robertphillips@google.com | 105a4a5 | 2014-02-11 15:10:40 +0000 | [diff] [blame] | 726 | |
| 727 | #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE |
| 728 | fMCMgr.concat(matrix); |
| 729 | #else |
robertphillips@google.com | 5a63f24 | 2014-02-04 20:07:50 +0000 | [diff] [blame] | 730 | this->recordConcat(matrix); |
robertphillips@google.com | 105a4a5 | 2014-02-11 15:10:40 +0000 | [diff] [blame] | 731 | #endif |
robertphillips@google.com | 5a63f24 | 2014-02-04 20:07:50 +0000 | [diff] [blame] | 732 | return this->INHERITED::concat(matrix); |
| 733 | } |
| 734 | |
| 735 | void SkPictureRecord::recordConcat(const SkMatrix& matrix) { |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 736 | this->validate(fWriter.bytesWritten(), 0); |
commit-bot@chromium.org | fed2ab6 | 2014-01-23 15:16:05 +0000 | [diff] [blame] | 737 | // op + matrix |
| 738 | uint32_t size = kUInt32Size + matrix.writeToMemory(NULL); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 739 | size_t initialOffset = this->addDraw(CONCAT, &size); |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 740 | this->addMatrix(matrix); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 741 | this->validate(initialOffset, size); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 742 | } |
| 743 | |
reed@android.com | 6e073b9 | 2009-01-06 15:03:30 +0000 | [diff] [blame] | 744 | void SkPictureRecord::setMatrix(const SkMatrix& matrix) { |
robertphillips@google.com | 105a4a5 | 2014-02-11 15:10:40 +0000 | [diff] [blame] | 745 | |
| 746 | #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE |
| 747 | fMCMgr.setMatrix(matrix); |
| 748 | #else |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 749 | this->validate(fWriter.bytesWritten(), 0); |
commit-bot@chromium.org | fed2ab6 | 2014-01-23 15:16:05 +0000 | [diff] [blame] | 750 | // op + matrix |
| 751 | uint32_t size = kUInt32Size + matrix.writeToMemory(NULL); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 752 | size_t initialOffset = this->addDraw(SET_MATRIX, &size); |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 753 | this->addMatrix(matrix); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 754 | this->validate(initialOffset, size); |
robertphillips@google.com | 105a4a5 | 2014-02-11 15:10:40 +0000 | [diff] [blame] | 755 | #endif |
reed@android.com | 6e073b9 | 2009-01-06 15:03:30 +0000 | [diff] [blame] | 756 | this->INHERITED::setMatrix(matrix); |
| 757 | } |
| 758 | |
reed@google.com | 45482d1 | 2011-08-29 19:02:39 +0000 | [diff] [blame] | 759 | static bool regionOpExpands(SkRegion::Op op) { |
| 760 | switch (op) { |
| 761 | case SkRegion::kUnion_Op: |
| 762 | case SkRegion::kXOR_Op: |
| 763 | case SkRegion::kReverseDifference_Op: |
| 764 | case SkRegion::kReplace_Op: |
| 765 | return true; |
| 766 | case SkRegion::kIntersect_Op: |
| 767 | case SkRegion::kDifference_Op: |
| 768 | return false; |
| 769 | default: |
tomhudson@google.com | 0c00f21 | 2011-12-28 14:59:50 +0000 | [diff] [blame] | 770 | SkDEBUGFAIL("unknown region op"); |
reed@google.com | 45482d1 | 2011-08-29 19:02:39 +0000 | [diff] [blame] | 771 | return false; |
| 772 | } |
| 773 | } |
| 774 | |
robertphillips@google.com | 105a4a5 | 2014-02-11 15:10:40 +0000 | [diff] [blame] | 775 | #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE |
| 776 | void SkPictureRecord::fillRestoreOffsetPlaceholdersForCurrentStackLevel(uint32_t restoreOffset) { |
| 777 | fMCMgr.fillInSkips(&fWriter, restoreOffset); |
| 778 | } |
| 779 | #else |
robertphillips@google.com | e37ad35 | 2013-03-01 19:44:30 +0000 | [diff] [blame] | 780 | void SkPictureRecord::fillRestoreOffsetPlaceholdersForCurrentStackLevel(uint32_t restoreOffset) { |
reed@google.com | ffacd3c | 2012-08-30 15:31:23 +0000 | [diff] [blame] | 781 | int32_t offset = fRestoreOffsetStack.top(); |
| 782 | while (offset > 0) { |
commit-bot@chromium.org | 536ac5e | 2014-02-11 22:38:51 +0000 | [diff] [blame] | 783 | uint32_t peek = fWriter.readTAt<uint32_t>(offset); |
| 784 | fWriter.overwriteTAt(offset, restoreOffset); |
commit-bot@chromium.org | c6d3c44 | 2014-01-31 16:22:57 +0000 | [diff] [blame] | 785 | offset = peek; |
junov@chromium.org | e3dbedb | 2012-07-09 16:03:55 +0000 | [diff] [blame] | 786 | } |
skia.committer@gmail.com | 11f8692 | 2012-08-31 17:14:46 +0000 | [diff] [blame] | 787 | |
reed@google.com | ffacd3c | 2012-08-30 15:31:23 +0000 | [diff] [blame] | 788 | #ifdef SK_DEBUG |
| 789 | // assert that the final offset value points to a save verb |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 790 | uint32_t opSize; |
| 791 | DrawType drawOp = peek_op_and_size(&fWriter, -offset, &opSize); |
reed@google.com | ffacd3c | 2012-08-30 15:31:23 +0000 | [diff] [blame] | 792 | SkASSERT(SAVE == drawOp || SAVE_LAYER == drawOp); |
| 793 | #endif |
junov@chromium.org | e3dbedb | 2012-07-09 16:03:55 +0000 | [diff] [blame] | 794 | } |
robertphillips@google.com | 105a4a5 | 2014-02-11 15:10:40 +0000 | [diff] [blame] | 795 | #endif |
junov@chromium.org | e3dbedb | 2012-07-09 16:03:55 +0000 | [diff] [blame] | 796 | |
reed@google.com | d86e7ab | 2012-09-27 20:31:31 +0000 | [diff] [blame] | 797 | void SkPictureRecord::beginRecording() { |
| 798 | // we have to call this *after* our constructor, to ensure that it gets |
| 799 | // recorded. This is balanced by restoreToCount() call from endRecording, |
| 800 | // which in-turn calls our overridden restore(), so those get recorded too. |
| 801 | fInitialSaveCount = this->save(kMatrixClip_SaveFlag); |
| 802 | } |
| 803 | |
junov@chromium.org | a6c9e0e | 2012-07-12 17:47:34 +0000 | [diff] [blame] | 804 | void SkPictureRecord::endRecording() { |
junov@chromium.org | 4e6dfa5 | 2012-07-16 14:04:59 +0000 | [diff] [blame] | 805 | SkASSERT(kNoInitialSave != fInitialSaveCount); |
| 806 | this->restoreToCount(fInitialSaveCount); |
robertphillips@google.com | 105a4a5 | 2014-02-11 15:10:40 +0000 | [diff] [blame] | 807 | #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE |
| 808 | fMCMgr.finish(); |
| 809 | #endif |
junov@chromium.org | a6c9e0e | 2012-07-12 17:47:34 +0000 | [diff] [blame] | 810 | } |
| 811 | |
robertphillips@google.com | 105a4a5 | 2014-02-11 15:10:40 +0000 | [diff] [blame] | 812 | #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE |
| 813 | int SkPictureRecord::recordRestoreOffsetPlaceholder(SkRegion::Op op) { |
| 814 | size_t offset = fWriter.bytesWritten(); |
| 815 | this->addInt(-1); |
| 816 | return offset; |
| 817 | } |
| 818 | #else |
robertphillips@google.com | 5a63f24 | 2014-02-04 20:07:50 +0000 | [diff] [blame] | 819 | int SkPictureRecord::recordRestoreOffsetPlaceholder(SkRegion::Op op) { |
reed@google.com | 21b519d | 2012-10-02 17:42:15 +0000 | [diff] [blame] | 820 | if (fRestoreOffsetStack.isEmpty()) { |
robertphillips@google.com | 5a63f24 | 2014-02-04 20:07:50 +0000 | [diff] [blame] | 821 | return -1; |
reed@google.com | 21b519d | 2012-10-02 17:42:15 +0000 | [diff] [blame] | 822 | } |
| 823 | |
fmalita@google.com | d0f1a4f | 2013-08-27 15:50:19 +0000 | [diff] [blame] | 824 | // The RestoreOffset field is initially filled with a placeholder |
| 825 | // value that points to the offset of the previous RestoreOffset |
| 826 | // in the current stack level, thus forming a linked list so that |
| 827 | // the restore offsets can be filled in when the corresponding |
| 828 | // restore command is recorded. |
| 829 | int32_t prevOffset = fRestoreOffsetStack.top(); |
| 830 | |
reed@google.com | 45482d1 | 2011-08-29 19:02:39 +0000 | [diff] [blame] | 831 | if (regionOpExpands(op)) { |
| 832 | // Run back through any previous clip ops, and mark their offset to |
| 833 | // be 0, disabling their ability to trigger a jump-to-restore, otherwise |
| 834 | // they could hide this clips ability to expand the clip (i.e. go from |
| 835 | // empty to non-empty). |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 836 | this->fillRestoreOffsetPlaceholdersForCurrentStackLevel(0); |
fmalita@google.com | d0f1a4f | 2013-08-27 15:50:19 +0000 | [diff] [blame] | 837 | |
| 838 | // Reset the pointer back to the previous clip so that subsequent |
| 839 | // restores don't overwrite the offsets we just cleared. |
| 840 | prevOffset = 0; |
reed@google.com | 45482d1 | 2011-08-29 19:02:39 +0000 | [diff] [blame] | 841 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 842 | |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 843 | size_t offset = fWriter.bytesWritten(); |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 844 | this->addInt(prevOffset); |
reed@google.com | 45482d1 | 2011-08-29 19:02:39 +0000 | [diff] [blame] | 845 | fRestoreOffsetStack.top() = offset; |
robertphillips@google.com | 5a63f24 | 2014-02-04 20:07:50 +0000 | [diff] [blame] | 846 | return offset; |
reed@google.com | 45482d1 | 2011-08-29 19:02:39 +0000 | [diff] [blame] | 847 | } |
robertphillips@google.com | 105a4a5 | 2014-02-11 15:10:40 +0000 | [diff] [blame] | 848 | #endif |
reed@google.com | 45482d1 | 2011-08-29 19:02:39 +0000 | [diff] [blame] | 849 | |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame^] | 850 | void SkPictureRecord::onClipRect(const SkRect& rect, SkRegion::Op op, ClipEdgeStyle edgeStyle) { |
robertphillips@google.com | 105a4a5 | 2014-02-11 15:10:40 +0000 | [diff] [blame] | 851 | |
| 852 | #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE |
| 853 | fMCMgr.clipRect(rect, op, doAA); |
| 854 | #else |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame^] | 855 | this->recordClipRect(rect, op, kSoft_ClipEdgeStyle == edgeStyle); |
robertphillips@google.com | 105a4a5 | 2014-02-11 15:10:40 +0000 | [diff] [blame] | 856 | #endif |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame^] | 857 | this->INHERITED::onClipRect(rect, op, edgeStyle); |
robertphillips@google.com | 5a63f24 | 2014-02-04 20:07:50 +0000 | [diff] [blame] | 858 | } |
| 859 | |
| 860 | int SkPictureRecord::recordClipRect(const SkRect& rect, SkRegion::Op op, bool doAA) { |
robertphillips@google.com | f929150 | 2013-02-15 15:13:27 +0000 | [diff] [blame] | 861 | // id + rect + clip params |
| 862 | uint32_t size = 1 * kUInt32Size + sizeof(rect) + 1 * kUInt32Size; |
robertphillips@google.com | 105a4a5 | 2014-02-11 15:10:40 +0000 | [diff] [blame] | 863 | #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE |
| 864 | size += kUInt32Size; // + restore offset |
| 865 | #else |
robertphillips@google.com | 4310c66 | 2013-03-01 14:17:58 +0000 | [diff] [blame] | 866 | // recordRestoreOffsetPlaceholder doesn't always write an offset |
robertphillips@google.com | f929150 | 2013-02-15 15:13:27 +0000 | [diff] [blame] | 867 | if (!fRestoreOffsetStack.isEmpty()) { |
| 868 | // + restore offset |
| 869 | size += kUInt32Size; |
| 870 | } |
robertphillips@google.com | 105a4a5 | 2014-02-11 15:10:40 +0000 | [diff] [blame] | 871 | #endif |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 872 | size_t initialOffset = this->addDraw(CLIP_RECT, &size); |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 873 | this->addRect(rect); |
| 874 | this->addInt(ClipParams_pack(op, doAA)); |
robertphillips@google.com | 5a63f24 | 2014-02-04 20:07:50 +0000 | [diff] [blame] | 875 | int offset = this->recordRestoreOffsetPlaceholder(op); |
skia.committer@gmail.com | 306ab9d | 2012-12-13 02:01:33 +0000 | [diff] [blame] | 876 | |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 877 | this->validate(initialOffset, size); |
robertphillips@google.com | 5a63f24 | 2014-02-04 20:07:50 +0000 | [diff] [blame] | 878 | return offset; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 879 | } |
| 880 | |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame^] | 881 | void SkPictureRecord::onClipRRect(const SkRRect& rrect, SkRegion::Op op, ClipEdgeStyle edgeStyle) { |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 882 | |
robertphillips@google.com | 105a4a5 | 2014-02-11 15:10:40 +0000 | [diff] [blame] | 883 | #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE |
| 884 | fMCMgr.clipRRect(rrect, op, doAA); |
| 885 | #else |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame^] | 886 | this->recordClipRRect(rrect, op, kSoft_ClipEdgeStyle == edgeStyle); |
robertphillips@google.com | 105a4a5 | 2014-02-11 15:10:40 +0000 | [diff] [blame] | 887 | #endif |
robertphillips@google.com | 5a63f24 | 2014-02-04 20:07:50 +0000 | [diff] [blame] | 888 | if (fRecordFlags & SkPicture::kUsePathBoundsForClip_RecordingFlag) { |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame^] | 889 | this->updateClipConservativelyUsingBounds(rrect.getBounds(), op, false); |
robertphillips@google.com | 5a63f24 | 2014-02-04 20:07:50 +0000 | [diff] [blame] | 890 | } else { |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame^] | 891 | this->INHERITED::onClipRRect(rrect, op, edgeStyle); |
robertphillips@google.com | 5a63f24 | 2014-02-04 20:07:50 +0000 | [diff] [blame] | 892 | } |
| 893 | } |
| 894 | |
| 895 | int SkPictureRecord::recordClipRRect(const SkRRect& rrect, SkRegion::Op op, bool doAA) { |
robertphillips@google.com | f929150 | 2013-02-15 15:13:27 +0000 | [diff] [blame] | 896 | // op + rrect + clip params |
| 897 | uint32_t size = 1 * kUInt32Size + SkRRect::kSizeInMemory + 1 * kUInt32Size; |
robertphillips@google.com | 105a4a5 | 2014-02-11 15:10:40 +0000 | [diff] [blame] | 898 | #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE |
| 899 | size += kUInt32Size; // + restore offset |
| 900 | #else |
robertphillips@google.com | 4310c66 | 2013-03-01 14:17:58 +0000 | [diff] [blame] | 901 | // recordRestoreOffsetPlaceholder doesn't always write an offset |
robertphillips@google.com | f929150 | 2013-02-15 15:13:27 +0000 | [diff] [blame] | 902 | if (!fRestoreOffsetStack.isEmpty()) { |
| 903 | // + restore offset |
| 904 | size += kUInt32Size; |
| 905 | } |
robertphillips@google.com | 105a4a5 | 2014-02-11 15:10:40 +0000 | [diff] [blame] | 906 | #endif |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 907 | size_t initialOffset = this->addDraw(CLIP_RRECT, &size); |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 908 | this->addRRect(rrect); |
| 909 | this->addInt(ClipParams_pack(op, doAA)); |
robertphillips@google.com | 5a63f24 | 2014-02-04 20:07:50 +0000 | [diff] [blame] | 910 | int offset = recordRestoreOffsetPlaceholder(op); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 911 | this->validate(initialOffset, size); |
robertphillips@google.com | 5a63f24 | 2014-02-04 20:07:50 +0000 | [diff] [blame] | 912 | return offset; |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 913 | } |
| 914 | |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame^] | 915 | void SkPictureRecord::onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeStyle edgeStyle) { |
robertphillips@google.com | 3302783 | 2012-11-07 13:01:25 +0000 | [diff] [blame] | 916 | |
robertphillips@google.com | 105a4a5 | 2014-02-11 15:10:40 +0000 | [diff] [blame] | 917 | #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE |
| 918 | fMCMgr.clipPath(path, op, doAA); |
| 919 | #else |
robertphillips@google.com | 5a63f24 | 2014-02-04 20:07:50 +0000 | [diff] [blame] | 920 | int pathID = this->addPathToHeap(path); |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame^] | 921 | this->recordClipPath(pathID, op, kSoft_ClipEdgeStyle == edgeStyle); |
robertphillips@google.com | 105a4a5 | 2014-02-11 15:10:40 +0000 | [diff] [blame] | 922 | #endif |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 923 | |
reed@android.com | ae814c8 | 2009-02-13 14:56:09 +0000 | [diff] [blame] | 924 | if (fRecordFlags & SkPicture::kUsePathBoundsForClip_RecordingFlag) { |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame^] | 925 | this->updateClipConservativelyUsingBounds(path.getBounds(), op, |
| 926 | path.isInverseFillType()); |
reed@android.com | ae814c8 | 2009-02-13 14:56:09 +0000 | [diff] [blame] | 927 | } else { |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame^] | 928 | this->INHERITED::onClipPath(path, op, edgeStyle); |
reed@android.com | ae814c8 | 2009-02-13 14:56:09 +0000 | [diff] [blame] | 929 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 930 | } |
| 931 | |
robertphillips@google.com | 5a63f24 | 2014-02-04 20:07:50 +0000 | [diff] [blame] | 932 | int SkPictureRecord::recordClipPath(int pathID, SkRegion::Op op, bool doAA) { |
robertphillips@google.com | 5a63f24 | 2014-02-04 20:07:50 +0000 | [diff] [blame] | 933 | // op + path index + clip params |
| 934 | uint32_t size = 3 * kUInt32Size; |
robertphillips@google.com | 105a4a5 | 2014-02-11 15:10:40 +0000 | [diff] [blame] | 935 | #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE |
| 936 | size += kUInt32Size; // + restore offset |
| 937 | #else |
robertphillips@google.com | 5a63f24 | 2014-02-04 20:07:50 +0000 | [diff] [blame] | 938 | // recordRestoreOffsetPlaceholder doesn't always write an offset |
| 939 | if (!fRestoreOffsetStack.isEmpty()) { |
| 940 | // + restore offset |
| 941 | size += kUInt32Size; |
| 942 | } |
robertphillips@google.com | 105a4a5 | 2014-02-11 15:10:40 +0000 | [diff] [blame] | 943 | #endif |
robertphillips@google.com | 5a63f24 | 2014-02-04 20:07:50 +0000 | [diff] [blame] | 944 | size_t initialOffset = this->addDraw(CLIP_PATH, &size); |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 945 | this->addInt(pathID); |
| 946 | this->addInt(ClipParams_pack(op, doAA)); |
robertphillips@google.com | 5a63f24 | 2014-02-04 20:07:50 +0000 | [diff] [blame] | 947 | int offset = recordRestoreOffsetPlaceholder(op); |
robertphillips@google.com | 5a63f24 | 2014-02-04 20:07:50 +0000 | [diff] [blame] | 948 | this->validate(initialOffset, size); |
| 949 | return offset; |
| 950 | } |
| 951 | |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame^] | 952 | void SkPictureRecord::onClipRegion(const SkRegion& region, SkRegion::Op op) { |
robertphillips@google.com | 105a4a5 | 2014-02-11 15:10:40 +0000 | [diff] [blame] | 953 | |
| 954 | #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE |
| 955 | fMCMgr.clipRegion(region, op); |
| 956 | #else |
robertphillips@google.com | 5a63f24 | 2014-02-04 20:07:50 +0000 | [diff] [blame] | 957 | this->recordClipRegion(region, op); |
robertphillips@google.com | 105a4a5 | 2014-02-11 15:10:40 +0000 | [diff] [blame] | 958 | #endif |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame^] | 959 | this->INHERITED::onClipRegion(region, op); |
robertphillips@google.com | 5a63f24 | 2014-02-04 20:07:50 +0000 | [diff] [blame] | 960 | } |
| 961 | |
| 962 | int SkPictureRecord::recordClipRegion(const SkRegion& region, SkRegion::Op op) { |
commit-bot@chromium.org | fed2ab6 | 2014-01-23 15:16:05 +0000 | [diff] [blame] | 963 | // op + clip params + region |
| 964 | uint32_t size = 2 * kUInt32Size + region.writeToMemory(NULL); |
robertphillips@google.com | 105a4a5 | 2014-02-11 15:10:40 +0000 | [diff] [blame] | 965 | #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE |
| 966 | size += kUInt32Size; // + restore offset |
| 967 | #else |
robertphillips@google.com | 4310c66 | 2013-03-01 14:17:58 +0000 | [diff] [blame] | 968 | // recordRestoreOffsetPlaceholder doesn't always write an offset |
robertphillips@google.com | f929150 | 2013-02-15 15:13:27 +0000 | [diff] [blame] | 969 | if (!fRestoreOffsetStack.isEmpty()) { |
| 970 | // + restore offset |
| 971 | size += kUInt32Size; |
| 972 | } |
robertphillips@google.com | 105a4a5 | 2014-02-11 15:10:40 +0000 | [diff] [blame] | 973 | #endif |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 974 | size_t initialOffset = this->addDraw(CLIP_REGION, &size); |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 975 | this->addRegion(region); |
| 976 | this->addInt(ClipParams_pack(op, false)); |
| 977 | int offset = this->recordRestoreOffsetPlaceholder(op); |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 978 | |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 979 | this->validate(initialOffset, size); |
robertphillips@google.com | 5a63f24 | 2014-02-04 20:07:50 +0000 | [diff] [blame] | 980 | return offset; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 981 | } |
| 982 | |
reed@google.com | 2a98181 | 2011-04-14 18:59:28 +0000 | [diff] [blame] | 983 | void SkPictureRecord::clear(SkColor color) { |
robertphillips@google.com | 105a4a5 | 2014-02-11 15:10:40 +0000 | [diff] [blame] | 984 | |
| 985 | #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE |
| 986 | fMCMgr.call(SkMatrixClipStateMgr::kOther_CallType); |
| 987 | #endif |
| 988 | |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 989 | // op + color |
| 990 | uint32_t size = 2 * kUInt32Size; |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 991 | size_t initialOffset = this->addDraw(DRAW_CLEAR, &size); |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 992 | this->addInt(color); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 993 | this->validate(initialOffset, size); |
reed@google.com | 2a98181 | 2011-04-14 18:59:28 +0000 | [diff] [blame] | 994 | } |
| 995 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 996 | void SkPictureRecord::drawPaint(const SkPaint& paint) { |
robertphillips@google.com | 105a4a5 | 2014-02-11 15:10:40 +0000 | [diff] [blame] | 997 | |
| 998 | #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE |
| 999 | fMCMgr.call(SkMatrixClipStateMgr::kOther_CallType); |
| 1000 | #endif |
| 1001 | |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 1002 | // op + paint index |
| 1003 | uint32_t size = 2 * kUInt32Size; |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 1004 | size_t initialOffset = this->addDraw(DRAW_PAINT, &size); |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 1005 | SkASSERT(initialOffset+getPaintOffset(DRAW_PAINT, size) == fWriter.bytesWritten()); |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 1006 | this->addPaint(paint); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 1007 | this->validate(initialOffset, size); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1008 | } |
| 1009 | |
| 1010 | void SkPictureRecord::drawPoints(PointMode mode, size_t count, const SkPoint pts[], |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 1011 | const SkPaint& paint) { |
robertphillips@google.com | 105a4a5 | 2014-02-11 15:10:40 +0000 | [diff] [blame] | 1012 | |
| 1013 | #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE |
| 1014 | fMCMgr.call(SkMatrixClipStateMgr::kOther_CallType); |
| 1015 | #endif |
| 1016 | |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 1017 | // op + paint index + mode + count + point data |
| 1018 | uint32_t size = 4 * kUInt32Size + count * sizeof(SkPoint); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 1019 | size_t initialOffset = this->addDraw(DRAW_POINTS, &size); |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 1020 | SkASSERT(initialOffset+getPaintOffset(DRAW_POINTS, size) == fWriter.bytesWritten()); |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 1021 | this->addPaint(paint); |
| 1022 | this->addInt(mode); |
| 1023 | this->addInt(count); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1024 | fWriter.writeMul4(pts, count * sizeof(SkPoint)); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 1025 | this->validate(initialOffset, size); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1026 | } |
| 1027 | |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 1028 | void SkPictureRecord::drawOval(const SkRect& oval, const SkPaint& paint) { |
robertphillips@google.com | 105a4a5 | 2014-02-11 15:10:40 +0000 | [diff] [blame] | 1029 | |
| 1030 | #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE |
| 1031 | fMCMgr.call(SkMatrixClipStateMgr::kOther_CallType); |
| 1032 | #endif |
| 1033 | |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 1034 | // op + paint index + rect |
| 1035 | uint32_t size = 2 * kUInt32Size + sizeof(oval); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 1036 | size_t initialOffset = this->addDraw(DRAW_OVAL, &size); |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 1037 | SkASSERT(initialOffset+getPaintOffset(DRAW_OVAL, size) == fWriter.bytesWritten()); |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 1038 | this->addPaint(paint); |
| 1039 | this->addRect(oval); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 1040 | this->validate(initialOffset, size); |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 1041 | } |
| 1042 | |
bsalomon@google.com | 7ce564c | 2013-10-22 16:54:15 +0000 | [diff] [blame] | 1043 | void SkPictureRecord::drawRect(const SkRect& rect, const SkPaint& paint) { |
robertphillips@google.com | 105a4a5 | 2014-02-11 15:10:40 +0000 | [diff] [blame] | 1044 | |
| 1045 | #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE |
| 1046 | fMCMgr.call(SkMatrixClipStateMgr::kOther_CallType); |
| 1047 | #endif |
| 1048 | |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 1049 | // op + paint index + rect |
| 1050 | uint32_t size = 2 * kUInt32Size + sizeof(rect); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 1051 | size_t initialOffset = this->addDraw(DRAW_RECT, &size); |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 1052 | SkASSERT(initialOffset+getPaintOffset(DRAW_RECT, size) == fWriter.bytesWritten()); |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 1053 | this->addPaint(paint); |
| 1054 | this->addRect(rect); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 1055 | this->validate(initialOffset, size); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1056 | } |
| 1057 | |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 1058 | void SkPictureRecord::drawRRect(const SkRRect& rrect, const SkPaint& paint) { |
robertphillips@google.com | 105a4a5 | 2014-02-11 15:10:40 +0000 | [diff] [blame] | 1059 | |
| 1060 | #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE |
| 1061 | fMCMgr.call(SkMatrixClipStateMgr::kOther_CallType); |
| 1062 | #endif |
| 1063 | |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 1064 | if (rrect.isRect()) { |
junov@chromium.org | 0ce0df7 | 2013-05-10 14:39:26 +0000 | [diff] [blame] | 1065 | this->SkPictureRecord::drawRect(rrect.getBounds(), paint); |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 1066 | } else if (rrect.isOval()) { |
junov@chromium.org | 0ce0df7 | 2013-05-10 14:39:26 +0000 | [diff] [blame] | 1067 | this->SkPictureRecord::drawOval(rrect.getBounds(), paint); |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 1068 | } else { |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 1069 | // op + paint index + rrect |
junov@chromium.org | 0ce0df7 | 2013-05-10 14:39:26 +0000 | [diff] [blame] | 1070 | uint32_t initialOffset, size; |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 1071 | size = 2 * kUInt32Size + SkRRect::kSizeInMemory; |
| 1072 | initialOffset = this->addDraw(DRAW_RRECT, &size); |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 1073 | SkASSERT(initialOffset+getPaintOffset(DRAW_RRECT, size) == fWriter.bytesWritten()); |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 1074 | this->addPaint(paint); |
| 1075 | this->addRRect(rrect); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 1076 | this->validate(initialOffset, size); |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 1077 | } |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 1078 | } |
| 1079 | |
commit-bot@chromium.org | ed9806f | 2014-02-21 02:32:36 +0000 | [diff] [blame] | 1080 | void SkPictureRecord::onDrawDRRect(const SkRRect& outer, const SkRRect& inner, |
| 1081 | const SkPaint& paint) { |
skia.committer@gmail.com | 25c7127 | 2014-02-21 03:02:02 +0000 | [diff] [blame] | 1082 | |
commit-bot@chromium.org | ed9806f | 2014-02-21 02:32:36 +0000 | [diff] [blame] | 1083 | #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE |
| 1084 | fMCMgr.call(SkMatrixClipStateMgr::kOther_CallType); |
| 1085 | #endif |
skia.committer@gmail.com | 25c7127 | 2014-02-21 03:02:02 +0000 | [diff] [blame] | 1086 | |
commit-bot@chromium.org | ed9806f | 2014-02-21 02:32:36 +0000 | [diff] [blame] | 1087 | // op + paint index + rrects |
| 1088 | uint32_t initialOffset, size; |
| 1089 | size = 2 * kUInt32Size + SkRRect::kSizeInMemory * 2; |
| 1090 | initialOffset = this->addDraw(DRAW_DRRECT, &size); |
| 1091 | SkASSERT(initialOffset+getPaintOffset(DRAW_DRRECT, size) == fWriter.bytesWritten()); |
| 1092 | this->addPaint(paint); |
| 1093 | this->addRRect(outer); |
| 1094 | this->addRRect(inner); |
| 1095 | this->validate(initialOffset, size); |
| 1096 | } |
| 1097 | |
bsalomon@google.com | 7ce564c | 2013-10-22 16:54:15 +0000 | [diff] [blame] | 1098 | void SkPictureRecord::drawPath(const SkPath& path, const SkPaint& paint) { |
robertphillips@google.com | 105a4a5 | 2014-02-11 15:10:40 +0000 | [diff] [blame] | 1099 | |
| 1100 | #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE |
| 1101 | fMCMgr.call(SkMatrixClipStateMgr::kOther_CallType); |
| 1102 | #endif |
| 1103 | |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 1104 | // op + paint index + path index |
| 1105 | uint32_t size = 3 * kUInt32Size; |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 1106 | size_t initialOffset = this->addDraw(DRAW_PATH, &size); |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 1107 | SkASSERT(initialOffset+getPaintOffset(DRAW_PATH, size) == fWriter.bytesWritten()); |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 1108 | this->addPaint(paint); |
| 1109 | this->addPath(path); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 1110 | this->validate(initialOffset, size); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1111 | } |
| 1112 | |
| 1113 | void SkPictureRecord::drawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top, |
commit-bot@chromium.org | 50b393a | 2014-02-10 18:29:10 +0000 | [diff] [blame] | 1114 | const SkPaint* paint = NULL) { |
| 1115 | if (bitmap.drawsNothing()) { |
| 1116 | return; |
| 1117 | } |
robertphillips@google.com | 105a4a5 | 2014-02-11 15:10:40 +0000 | [diff] [blame] | 1118 | |
| 1119 | #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE |
| 1120 | fMCMgr.call(SkMatrixClipStateMgr::kOther_CallType); |
| 1121 | #endif |
| 1122 | |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 1123 | // op + paint index + bitmap index + left + top |
| 1124 | uint32_t size = 3 * kUInt32Size + 2 * sizeof(SkScalar); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 1125 | size_t initialOffset = this->addDraw(DRAW_BITMAP, &size); |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 1126 | SkASSERT(initialOffset+getPaintOffset(DRAW_BITMAP, size) == fWriter.bytesWritten()); |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 1127 | this->addPaintPtr(paint); |
| 1128 | this->addBitmap(bitmap); |
| 1129 | this->addScalar(left); |
| 1130 | this->addScalar(top); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 1131 | this->validate(initialOffset, size); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1132 | } |
| 1133 | |
reed@google.com | 7112173 | 2012-09-18 15:14:33 +0000 | [diff] [blame] | 1134 | void SkPictureRecord::drawBitmapRectToRect(const SkBitmap& bitmap, const SkRect* src, |
commit-bot@chromium.org | eed779d | 2013-08-16 10:24:37 +0000 | [diff] [blame] | 1135 | const SkRect& dst, const SkPaint* paint, |
| 1136 | DrawBitmapRectFlags flags) { |
commit-bot@chromium.org | 50b393a | 2014-02-10 18:29:10 +0000 | [diff] [blame] | 1137 | if (bitmap.drawsNothing()) { |
| 1138 | return; |
| 1139 | } |
robertphillips@google.com | 105a4a5 | 2014-02-11 15:10:40 +0000 | [diff] [blame] | 1140 | |
| 1141 | #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE |
| 1142 | fMCMgr.call(SkMatrixClipStateMgr::kOther_CallType); |
| 1143 | #endif |
commit-bot@chromium.org | eed779d | 2013-08-16 10:24:37 +0000 | [diff] [blame] | 1144 | // id + paint index + bitmap index + bool for 'src' + flags |
| 1145 | uint32_t size = 5 * kUInt32Size; |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 1146 | if (NULL != src) { |
| 1147 | size += sizeof(*src); // + rect |
| 1148 | } |
| 1149 | size += sizeof(dst); // + rect |
| 1150 | |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 1151 | size_t initialOffset = this->addDraw(DRAW_BITMAP_RECT_TO_RECT, &size); |
commit-bot@chromium.org | 50b393a | 2014-02-10 18:29:10 +0000 | [diff] [blame] | 1152 | SkASSERT(initialOffset+getPaintOffset(DRAW_BITMAP_RECT_TO_RECT, size) |
| 1153 | == fWriter.bytesWritten()); |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 1154 | this->addPaintPtr(paint); |
| 1155 | this->addBitmap(bitmap); |
| 1156 | this->addRectPtr(src); // may be null |
| 1157 | this->addRect(dst); |
| 1158 | this->addInt(flags); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 1159 | this->validate(initialOffset, size); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1160 | } |
| 1161 | |
| 1162 | void SkPictureRecord::drawBitmapMatrix(const SkBitmap& bitmap, const SkMatrix& matrix, |
reed@google.com | f0b5e11 | 2011-09-07 11:57:34 +0000 | [diff] [blame] | 1163 | const SkPaint* paint) { |
commit-bot@chromium.org | 50b393a | 2014-02-10 18:29:10 +0000 | [diff] [blame] | 1164 | if (bitmap.drawsNothing()) { |
| 1165 | return; |
| 1166 | } |
robertphillips@google.com | 105a4a5 | 2014-02-11 15:10:40 +0000 | [diff] [blame] | 1167 | |
| 1168 | #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE |
| 1169 | fMCMgr.call(SkMatrixClipStateMgr::kOther_CallType); |
| 1170 | #endif |
| 1171 | |
commit-bot@chromium.org | fed2ab6 | 2014-01-23 15:16:05 +0000 | [diff] [blame] | 1172 | // id + paint index + bitmap index + matrix |
| 1173 | uint32_t size = 3 * kUInt32Size + matrix.writeToMemory(NULL); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 1174 | size_t initialOffset = this->addDraw(DRAW_BITMAP_MATRIX, &size); |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 1175 | SkASSERT(initialOffset+getPaintOffset(DRAW_BITMAP_MATRIX, size) == fWriter.bytesWritten()); |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 1176 | this->addPaintPtr(paint); |
| 1177 | this->addBitmap(bitmap); |
| 1178 | this->addMatrix(matrix); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 1179 | this->validate(initialOffset, size); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1180 | } |
| 1181 | |
reed@google.com | f0b5e11 | 2011-09-07 11:57:34 +0000 | [diff] [blame] | 1182 | void SkPictureRecord::drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, |
| 1183 | const SkRect& dst, const SkPaint* paint) { |
commit-bot@chromium.org | 50b393a | 2014-02-10 18:29:10 +0000 | [diff] [blame] | 1184 | if (bitmap.drawsNothing()) { |
| 1185 | return; |
| 1186 | } |
robertphillips@google.com | 105a4a5 | 2014-02-11 15:10:40 +0000 | [diff] [blame] | 1187 | |
| 1188 | #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE |
| 1189 | fMCMgr.call(SkMatrixClipStateMgr::kOther_CallType); |
| 1190 | #endif |
| 1191 | |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 1192 | // op + paint index + bitmap id + center + dst rect |
skia.committer@gmail.com | ce8343d | 2013-02-16 07:01:31 +0000 | [diff] [blame] | 1193 | uint32_t size = 3 * kUInt32Size + sizeof(center) + sizeof(dst); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 1194 | size_t initialOffset = this->addDraw(DRAW_BITMAP_NINE, &size); |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 1195 | SkASSERT(initialOffset+getPaintOffset(DRAW_BITMAP_NINE, size) == fWriter.bytesWritten()); |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 1196 | this->addPaintPtr(paint); |
| 1197 | this->addBitmap(bitmap); |
| 1198 | this->addIRect(center); |
| 1199 | this->addRect(dst); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 1200 | this->validate(initialOffset, size); |
reed@google.com | f0b5e11 | 2011-09-07 11:57:34 +0000 | [diff] [blame] | 1201 | } |
| 1202 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1203 | void SkPictureRecord::drawSprite(const SkBitmap& bitmap, int left, int top, |
commit-bot@chromium.org | 50b393a | 2014-02-10 18:29:10 +0000 | [diff] [blame] | 1204 | const SkPaint* paint = NULL) { |
| 1205 | if (bitmap.drawsNothing()) { |
| 1206 | return; |
| 1207 | } |
robertphillips@google.com | 105a4a5 | 2014-02-11 15:10:40 +0000 | [diff] [blame] | 1208 | |
| 1209 | #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE |
| 1210 | fMCMgr.call(SkMatrixClipStateMgr::kOther_CallType); |
| 1211 | #endif |
| 1212 | |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 1213 | // op + paint index + bitmap index + left + top |
| 1214 | uint32_t size = 5 * kUInt32Size; |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 1215 | size_t initialOffset = this->addDraw(DRAW_SPRITE, &size); |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 1216 | SkASSERT(initialOffset+getPaintOffset(DRAW_SPRITE, size) == fWriter.bytesWritten()); |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 1217 | this->addPaintPtr(paint); |
| 1218 | this->addBitmap(bitmap); |
| 1219 | this->addInt(left); |
| 1220 | this->addInt(top); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 1221 | this->validate(initialOffset, size); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1222 | } |
| 1223 | |
commit-bot@chromium.org | cf7be95 | 2013-08-22 17:19:52 +0000 | [diff] [blame] | 1224 | void SkPictureRecord::ComputeFontMetricsTopBottom(const SkPaint& paint, SkScalar topbot[2]) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1225 | SkPaint::FontMetrics metrics; |
| 1226 | paint.getFontMetrics(&metrics); |
| 1227 | SkRect bounds; |
| 1228 | // construct a rect so we can see any adjustments from the paint. |
| 1229 | // we use 0,1 for left,right, just so the rect isn't empty |
reed@google.com | 4595426 | 2012-12-07 17:14:40 +0000 | [diff] [blame] | 1230 | bounds.set(0, metrics.fTop, SK_Scalar1, metrics.fBottom); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1231 | (void)paint.computeFastBounds(bounds, &bounds); |
reed@google.com | 4595426 | 2012-12-07 17:14:40 +0000 | [diff] [blame] | 1232 | topbot[0] = bounds.fTop; |
| 1233 | topbot[1] = bounds.fBottom; |
| 1234 | } |
| 1235 | |
junov@chromium.org | f3b1223 | 2013-01-22 17:50:47 +0000 | [diff] [blame] | 1236 | void SkPictureRecord::addFontMetricsTopBottom(const SkPaint& paint, const SkFlatData& flat, |
reed@google.com | 4595426 | 2012-12-07 17:14:40 +0000 | [diff] [blame] | 1237 | SkScalar minY, SkScalar maxY) { |
commit-bot@chromium.org | cf7be95 | 2013-08-22 17:19:52 +0000 | [diff] [blame] | 1238 | WriteTopBot(paint, flat); |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 1239 | this->addScalar(flat.topBot()[0] + minY); |
| 1240 | this->addScalar(flat.topBot()[1] + maxY); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1241 | } |
| 1242 | |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 1243 | void SkPictureRecord::drawText(const void* text, size_t byteLength, SkScalar x, |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1244 | SkScalar y, const SkPaint& paint) { |
robertphillips@google.com | 105a4a5 | 2014-02-11 15:10:40 +0000 | [diff] [blame] | 1245 | |
| 1246 | #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE |
| 1247 | fMCMgr.call(SkMatrixClipStateMgr::kOther_CallType); |
| 1248 | #endif |
| 1249 | |
reed@google.com | 2eb5bb1 | 2012-04-12 14:27:42 +0000 | [diff] [blame] | 1250 | bool fast = !paint.isVerticalText() && paint.canComputeFastBounds(); |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 1251 | |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 1252 | // op + paint index + length + 'length' worth of chars + x + y |
| 1253 | uint32_t size = 3 * kUInt32Size + SkAlign4(byteLength) + 2 * sizeof(SkScalar); |
| 1254 | if (fast) { |
| 1255 | size += 2 * sizeof(SkScalar); // + top & bottom |
| 1256 | } |
| 1257 | |
robertphillips@google.com | e37ad35 | 2013-03-01 19:44:30 +0000 | [diff] [blame] | 1258 | DrawType op = fast ? DRAW_TEXT_TOP_BOTTOM : DRAW_TEXT; |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 1259 | size_t initialOffset = this->addDraw(op, &size); |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 1260 | SkASSERT(initialOffset+getPaintOffset(op, size) == fWriter.bytesWritten()); |
junov@chromium.org | f3b1223 | 2013-01-22 17:50:47 +0000 | [diff] [blame] | 1261 | const SkFlatData* flatPaintData = addPaint(paint); |
| 1262 | SkASSERT(flatPaintData); |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 1263 | this->addText(text, byteLength); |
| 1264 | this->addScalar(x); |
| 1265 | this->addScalar(y); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1266 | if (fast) { |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 1267 | this->addFontMetricsTopBottom(paint, *flatPaintData, y, y); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1268 | } |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 1269 | this->validate(initialOffset, size); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1270 | } |
| 1271 | |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 1272 | void SkPictureRecord::drawPosText(const void* text, size_t byteLength, |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1273 | const SkPoint pos[], const SkPaint& paint) { |
robertphillips@google.com | 105a4a5 | 2014-02-11 15:10:40 +0000 | [diff] [blame] | 1274 | |
| 1275 | #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE |
| 1276 | fMCMgr.call(SkMatrixClipStateMgr::kOther_CallType); |
| 1277 | #endif |
| 1278 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1279 | size_t points = paint.countText(text, byteLength); |
| 1280 | if (0 == points) |
| 1281 | return; |
| 1282 | |
| 1283 | bool canUseDrawH = true; |
reed@google.com | 9efd9a0 | 2012-01-30 15:41:43 +0000 | [diff] [blame] | 1284 | SkScalar minY = pos[0].fY; |
| 1285 | SkScalar maxY = pos[0].fY; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1286 | // check if the caller really should have used drawPosTextH() |
| 1287 | { |
| 1288 | const SkScalar firstY = pos[0].fY; |
| 1289 | for (size_t index = 1; index < points; index++) { |
| 1290 | if (pos[index].fY != firstY) { |
| 1291 | canUseDrawH = false; |
reed@google.com | 9efd9a0 | 2012-01-30 15:41:43 +0000 | [diff] [blame] | 1292 | if (pos[index].fY < minY) { |
| 1293 | minY = pos[index].fY; |
| 1294 | } else if (pos[index].fY > maxY) { |
| 1295 | maxY = pos[index].fY; |
| 1296 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1297 | } |
| 1298 | } |
| 1299 | } |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 1300 | |
reed@google.com | 2eb5bb1 | 2012-04-12 14:27:42 +0000 | [diff] [blame] | 1301 | bool fastBounds = !paint.isVerticalText() && paint.canComputeFastBounds(); |
reed@google.com | 9efd9a0 | 2012-01-30 15:41:43 +0000 | [diff] [blame] | 1302 | bool fast = canUseDrawH && fastBounds; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1303 | |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 1304 | // op + paint index + length + 'length' worth of data + num points |
| 1305 | uint32_t size = 3 * kUInt32Size + SkAlign4(byteLength) + 1 * kUInt32Size; |
| 1306 | if (canUseDrawH) { |
| 1307 | if (fast) { |
| 1308 | size += 2 * sizeof(SkScalar); // + top & bottom |
| 1309 | } |
| 1310 | // + y-pos + actual x-point data |
| 1311 | size += sizeof(SkScalar) + points * sizeof(SkScalar); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1312 | } else { |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 1313 | // + x&y point data |
| 1314 | size += points * sizeof(SkPoint); |
| 1315 | if (fastBounds) { |
| 1316 | size += 2 * sizeof(SkScalar); // + top & bottom |
| 1317 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1318 | } |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 1319 | |
| 1320 | DrawType op; |
| 1321 | if (fast) { |
| 1322 | op = DRAW_POS_TEXT_H_TOP_BOTTOM; |
| 1323 | } else if (canUseDrawH) { |
| 1324 | op = DRAW_POS_TEXT_H; |
| 1325 | } else if (fastBounds) { |
| 1326 | op = DRAW_POS_TEXT_TOP_BOTTOM; |
| 1327 | } else { |
| 1328 | op = DRAW_POS_TEXT; |
| 1329 | } |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 1330 | size_t initialOffset = this->addDraw(op, &size); |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 1331 | SkASSERT(initialOffset+getPaintOffset(op, size) == fWriter.bytesWritten()); |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 1332 | const SkFlatData* flatPaintData = this->addPaint(paint); |
junov@chromium.org | f3b1223 | 2013-01-22 17:50:47 +0000 | [diff] [blame] | 1333 | SkASSERT(flatPaintData); |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 1334 | this->addText(text, byteLength); |
| 1335 | this->addInt(points); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1336 | |
| 1337 | #ifdef SK_DEBUG_SIZE |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 1338 | size_t start = fWriter.bytesWritten(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1339 | #endif |
| 1340 | if (canUseDrawH) { |
| 1341 | if (fast) { |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 1342 | this->addFontMetricsTopBottom(paint, *flatPaintData, pos[0].fY, pos[0].fY); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1343 | } |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 1344 | this->addScalar(pos[0].fY); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1345 | SkScalar* xptr = (SkScalar*)fWriter.reserve(points * sizeof(SkScalar)); |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 1346 | for (size_t index = 0; index < points; index++) |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1347 | *xptr++ = pos[index].fX; |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 1348 | } else { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1349 | fWriter.writeMul4(pos, points * sizeof(SkPoint)); |
reed@google.com | 9efd9a0 | 2012-01-30 15:41:43 +0000 | [diff] [blame] | 1350 | if (fastBounds) { |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 1351 | this->addFontMetricsTopBottom(paint, *flatPaintData, minY, maxY); |
reed@google.com | 9efd9a0 | 2012-01-30 15:41:43 +0000 | [diff] [blame] | 1352 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1353 | } |
| 1354 | #ifdef SK_DEBUG_SIZE |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 1355 | fPointBytes += fWriter.bytesWritten() - start; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1356 | fPointWrites += points; |
| 1357 | #endif |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 1358 | this->validate(initialOffset, size); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1359 | } |
| 1360 | |
| 1361 | void SkPictureRecord::drawPosTextH(const void* text, size_t byteLength, |
| 1362 | const SkScalar xpos[], SkScalar constY, |
| 1363 | const SkPaint& paint) { |
commit-bot@chromium.org | cf7be95 | 2013-08-22 17:19:52 +0000 | [diff] [blame] | 1364 | |
robertphillips@google.com | 105a4a5 | 2014-02-11 15:10:40 +0000 | [diff] [blame] | 1365 | #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE |
| 1366 | fMCMgr.call(SkMatrixClipStateMgr::kOther_CallType); |
| 1367 | #endif |
| 1368 | |
commit-bot@chromium.org | cf7be95 | 2013-08-22 17:19:52 +0000 | [diff] [blame] | 1369 | const SkFlatData* flatPaintData = this->getFlatPaintData(paint); |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 1370 | this->drawPosTextHImpl(text, byteLength, xpos, constY, paint, flatPaintData); |
commit-bot@chromium.org | cf7be95 | 2013-08-22 17:19:52 +0000 | [diff] [blame] | 1371 | } |
| 1372 | |
| 1373 | void SkPictureRecord::drawPosTextHImpl(const void* text, size_t byteLength, |
| 1374 | const SkScalar xpos[], SkScalar constY, |
| 1375 | const SkPaint& paint, const SkFlatData* flatPaintData) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1376 | size_t points = paint.countText(text, byteLength); |
| 1377 | if (0 == points) |
| 1378 | return; |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 1379 | |
reed@google.com | 2eb5bb1 | 2012-04-12 14:27:42 +0000 | [diff] [blame] | 1380 | bool fast = !paint.isVerticalText() && paint.canComputeFastBounds(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1381 | |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 1382 | // op + paint index + length + 'length' worth of data + num points |
| 1383 | uint32_t size = 3 * kUInt32Size + SkAlign4(byteLength) + 1 * kUInt32Size; |
| 1384 | if (fast) { |
| 1385 | size += 2 * sizeof(SkScalar); // + top & bottom |
| 1386 | } |
| 1387 | // + y + the actual points |
| 1388 | size += 1 * kUInt32Size + points * sizeof(SkScalar); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 1389 | size_t initialOffset = this->addDraw(fast ? DRAW_POS_TEXT_H_TOP_BOTTOM : DRAW_POS_TEXT_H, |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 1390 | &size); |
junov@chromium.org | f3b1223 | 2013-01-22 17:50:47 +0000 | [diff] [blame] | 1391 | SkASSERT(flatPaintData); |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 1392 | this->addFlatPaint(flatPaintData); |
commit-bot@chromium.org | cf7be95 | 2013-08-22 17:19:52 +0000 | [diff] [blame] | 1393 | |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 1394 | this->addText(text, byteLength); |
| 1395 | this->addInt(points); |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 1396 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1397 | #ifdef SK_DEBUG_SIZE |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 1398 | size_t start = fWriter.bytesWritten(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1399 | #endif |
| 1400 | if (fast) { |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 1401 | this->addFontMetricsTopBottom(paint, *flatPaintData, constY, constY); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1402 | } |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 1403 | this->addScalar(constY); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1404 | fWriter.writeMul4(xpos, points * sizeof(SkScalar)); |
| 1405 | #ifdef SK_DEBUG_SIZE |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 1406 | fPointBytes += fWriter.bytesWritten() - start; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1407 | fPointWrites += points; |
| 1408 | #endif |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 1409 | this->validate(initialOffset, size); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1410 | } |
| 1411 | |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 1412 | void SkPictureRecord::drawTextOnPath(const void* text, size_t byteLength, |
| 1413 | const SkPath& path, const SkMatrix* matrix, |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1414 | const SkPaint& paint) { |
robertphillips@google.com | 105a4a5 | 2014-02-11 15:10:40 +0000 | [diff] [blame] | 1415 | |
| 1416 | #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE |
| 1417 | fMCMgr.call(SkMatrixClipStateMgr::kOther_CallType); |
| 1418 | #endif |
| 1419 | |
commit-bot@chromium.org | fed2ab6 | 2014-01-23 15:16:05 +0000 | [diff] [blame] | 1420 | // op + paint index + length + 'length' worth of data + path index + matrix |
| 1421 | const SkMatrix& m = matrix ? *matrix : SkMatrix::I(); |
| 1422 | uint32_t size = 3 * kUInt32Size + SkAlign4(byteLength) + kUInt32Size + m.writeToMemory(NULL); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 1423 | size_t initialOffset = this->addDraw(DRAW_TEXT_ON_PATH, &size); |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 1424 | SkASSERT(initialOffset+getPaintOffset(DRAW_TEXT_ON_PATH, size) == fWriter.bytesWritten()); |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 1425 | this->addPaint(paint); |
| 1426 | this->addText(text, byteLength); |
| 1427 | this->addPath(path); |
| 1428 | this->addMatrix(m); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 1429 | this->validate(initialOffset, size); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1430 | } |
| 1431 | |
| 1432 | void SkPictureRecord::drawPicture(SkPicture& picture) { |
robertphillips@google.com | 105a4a5 | 2014-02-11 15:10:40 +0000 | [diff] [blame] | 1433 | |
| 1434 | #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE |
| 1435 | fMCMgr.call(SkMatrixClipStateMgr::kOther_CallType); |
| 1436 | #endif |
| 1437 | |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 1438 | // op + picture index |
| 1439 | uint32_t size = 2 * kUInt32Size; |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 1440 | size_t initialOffset = this->addDraw(DRAW_PICTURE, &size); |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 1441 | this->addPicture(picture); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 1442 | this->validate(initialOffset, size); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1443 | } |
| 1444 | |
| 1445 | void SkPictureRecord::drawVertices(VertexMode vmode, int vertexCount, |
| 1446 | const SkPoint vertices[], const SkPoint texs[], |
reed@google.com | 85e143c | 2013-12-30 15:51:25 +0000 | [diff] [blame] | 1447 | const SkColor colors[], SkXfermode* xfer, |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1448 | const uint16_t indices[], int indexCount, |
| 1449 | const SkPaint& paint) { |
robertphillips@google.com | 105a4a5 | 2014-02-11 15:10:40 +0000 | [diff] [blame] | 1450 | |
| 1451 | #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE |
| 1452 | fMCMgr.call(SkMatrixClipStateMgr::kOther_CallType); |
| 1453 | #endif |
| 1454 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1455 | uint32_t flags = 0; |
| 1456 | if (texs) { |
| 1457 | flags |= DRAW_VERTICES_HAS_TEXS; |
| 1458 | } |
| 1459 | if (colors) { |
| 1460 | flags |= DRAW_VERTICES_HAS_COLORS; |
| 1461 | } |
| 1462 | if (indexCount > 0) { |
| 1463 | flags |= DRAW_VERTICES_HAS_INDICES; |
| 1464 | } |
reed@google.com | 85e143c | 2013-12-30 15:51:25 +0000 | [diff] [blame] | 1465 | if (NULL != xfer) { |
| 1466 | SkXfermode::Mode mode; |
| 1467 | if (xfer->asMode(&mode) && SkXfermode::kModulate_Mode != mode) { |
| 1468 | flags |= DRAW_VERTICES_HAS_XFER; |
| 1469 | } |
| 1470 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1471 | |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 1472 | // op + paint index + flags + vmode + vCount + vertices |
| 1473 | uint32_t size = 5 * kUInt32Size + vertexCount * sizeof(SkPoint); |
| 1474 | if (flags & DRAW_VERTICES_HAS_TEXS) { |
| 1475 | size += vertexCount * sizeof(SkPoint); // + uvs |
| 1476 | } |
| 1477 | if (flags & DRAW_VERTICES_HAS_COLORS) { |
| 1478 | size += vertexCount * sizeof(SkColor); // + vert colors |
| 1479 | } |
| 1480 | if (flags & DRAW_VERTICES_HAS_INDICES) { |
| 1481 | // + num indices + indices |
| 1482 | size += 1 * kUInt32Size + SkAlign4(indexCount * sizeof(uint16_t)); |
| 1483 | } |
reed@google.com | 85e143c | 2013-12-30 15:51:25 +0000 | [diff] [blame] | 1484 | if (flags & DRAW_VERTICES_HAS_XFER) { |
| 1485 | size += kUInt32Size; // mode enum |
| 1486 | } |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 1487 | |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 1488 | size_t initialOffset = this->addDraw(DRAW_VERTICES, &size); |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 1489 | SkASSERT(initialOffset+getPaintOffset(DRAW_VERTICES, size) == fWriter.bytesWritten()); |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 1490 | this->addPaint(paint); |
| 1491 | this->addInt(flags); |
| 1492 | this->addInt(vmode); |
| 1493 | this->addInt(vertexCount); |
| 1494 | this->addPoints(vertices, vertexCount); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1495 | if (flags & DRAW_VERTICES_HAS_TEXS) { |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 1496 | this->addPoints(texs, vertexCount); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1497 | } |
| 1498 | if (flags & DRAW_VERTICES_HAS_COLORS) { |
| 1499 | fWriter.writeMul4(colors, vertexCount * sizeof(SkColor)); |
| 1500 | } |
| 1501 | if (flags & DRAW_VERTICES_HAS_INDICES) { |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 1502 | this->addInt(indexCount); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1503 | fWriter.writePad(indices, indexCount * sizeof(uint16_t)); |
| 1504 | } |
reed@google.com | 85e143c | 2013-12-30 15:51:25 +0000 | [diff] [blame] | 1505 | if (flags & DRAW_VERTICES_HAS_XFER) { |
| 1506 | SkXfermode::Mode mode = SkXfermode::kModulate_Mode; |
| 1507 | (void)xfer->asMode(&mode); |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 1508 | this->addInt(mode); |
reed@google.com | 85e143c | 2013-12-30 15:51:25 +0000 | [diff] [blame] | 1509 | } |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 1510 | this->validate(initialOffset, size); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1511 | } |
| 1512 | |
reed@android.com | cb60844 | 2009-12-04 21:32:27 +0000 | [diff] [blame] | 1513 | void SkPictureRecord::drawData(const void* data, size_t length) { |
robertphillips@google.com | 105a4a5 | 2014-02-11 15:10:40 +0000 | [diff] [blame] | 1514 | |
| 1515 | #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE |
| 1516 | fMCMgr.call(SkMatrixClipStateMgr::kOther_CallType); |
| 1517 | #endif |
| 1518 | |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 1519 | // op + length + 'length' worth of data |
| 1520 | uint32_t size = 2 * kUInt32Size + SkAlign4(length); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 1521 | size_t initialOffset = this->addDraw(DRAW_DATA, &size); |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 1522 | this->addInt(length); |
reed@android.com | cb60844 | 2009-12-04 21:32:27 +0000 | [diff] [blame] | 1523 | fWriter.writePad(data, length); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 1524 | this->validate(initialOffset, size); |
reed@android.com | cb60844 | 2009-12-04 21:32:27 +0000 | [diff] [blame] | 1525 | } |
| 1526 | |
robertphillips@google.com | 0a4805e | 2013-05-29 13:24:23 +0000 | [diff] [blame] | 1527 | void SkPictureRecord::beginCommentGroup(const char* description) { |
| 1528 | // op/size + length of string + \0 terminated chars |
| 1529 | int length = strlen(description); |
| 1530 | uint32_t size = 2 * kUInt32Size + SkAlign4(length + 1); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 1531 | size_t initialOffset = this->addDraw(BEGIN_COMMENT_GROUP, &size); |
robertphillips@google.com | 0a4805e | 2013-05-29 13:24:23 +0000 | [diff] [blame] | 1532 | fWriter.writeString(description, length); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 1533 | this->validate(initialOffset, size); |
robertphillips@google.com | 0a4805e | 2013-05-29 13:24:23 +0000 | [diff] [blame] | 1534 | } |
| 1535 | |
| 1536 | void SkPictureRecord::addComment(const char* kywd, const char* value) { |
| 1537 | // op/size + 2x length of string + 2x \0 terminated chars |
| 1538 | int kywdLen = strlen(kywd); |
| 1539 | int valueLen = strlen(value); |
| 1540 | uint32_t size = 3 * kUInt32Size + SkAlign4(kywdLen + 1) + SkAlign4(valueLen + 1); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 1541 | size_t initialOffset = this->addDraw(COMMENT, &size); |
robertphillips@google.com | 0a4805e | 2013-05-29 13:24:23 +0000 | [diff] [blame] | 1542 | fWriter.writeString(kywd, kywdLen); |
| 1543 | fWriter.writeString(value, valueLen); |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 1544 | this->validate(initialOffset, size); |
robertphillips@google.com | 0a4805e | 2013-05-29 13:24:23 +0000 | [diff] [blame] | 1545 | } |
| 1546 | |
| 1547 | void SkPictureRecord::endCommentGroup() { |
| 1548 | // op/size |
| 1549 | uint32_t size = 1 * kUInt32Size; |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 1550 | size_t initialOffset = this->addDraw(END_COMMENT_GROUP, &size); |
| 1551 | this->validate(initialOffset, size); |
robertphillips@google.com | 0a4805e | 2013-05-29 13:24:23 +0000 | [diff] [blame] | 1552 | } |
| 1553 | |
commit-bot@chromium.org | 210ae2a | 2014-02-27 17:40:13 +0000 | [diff] [blame] | 1554 | // [op/size] [rect] [skip offset] |
| 1555 | static const uint32_t kPushCullOpSize = 2 * kUInt32Size + sizeof(SkRect); |
| 1556 | void SkPictureRecord::onPushCull(const SkRect& cullRect) { |
| 1557 | // Skip identical cull rects. |
| 1558 | if (!fCullOffsetStack.isEmpty()) { |
| 1559 | const SkRect& prevCull = fWriter.readTAt<SkRect>(fCullOffsetStack.top() - sizeof(SkRect)); |
| 1560 | if (prevCull == cullRect) { |
| 1561 | // Skipped culls are tracked on the stack, but they point to the previous offset. |
| 1562 | fCullOffsetStack.push(fCullOffsetStack.top()); |
| 1563 | return; |
| 1564 | } |
| 1565 | |
| 1566 | SkASSERT(prevCull.contains(cullRect)); |
| 1567 | } |
| 1568 | |
| 1569 | uint32_t size = kPushCullOpSize; |
| 1570 | size_t initialOffset = this->addDraw(PUSH_CULL, &size); |
| 1571 | // PUSH_CULL's size should stay constant (used to rewind). |
| 1572 | SkASSERT(size == kPushCullOpSize); |
| 1573 | |
| 1574 | this->addRect(cullRect); |
| 1575 | fCullOffsetStack.push(fWriter.bytesWritten()); |
| 1576 | this->addInt(0); |
| 1577 | this->validate(initialOffset, size); |
| 1578 | } |
| 1579 | |
| 1580 | void SkPictureRecord::onPopCull() { |
| 1581 | SkASSERT(!fCullOffsetStack.isEmpty()); |
| 1582 | |
| 1583 | uint32_t cullSkipOffset = fCullOffsetStack.top(); |
| 1584 | fCullOffsetStack.pop(); |
| 1585 | |
| 1586 | // Skipped push, do the same for pop. |
| 1587 | if (!fCullOffsetStack.isEmpty() && cullSkipOffset == fCullOffsetStack.top()) { |
| 1588 | return; |
| 1589 | } |
| 1590 | |
| 1591 | // Collapse empty push/pop pairs. |
| 1592 | if ((size_t)(cullSkipOffset + kUInt32Size) == fWriter.bytesWritten()) { |
| 1593 | SkASSERT(fWriter.bytesWritten() >= kPushCullOpSize); |
| 1594 | SkASSERT(PUSH_CULL == peek_op(&fWriter, fWriter.bytesWritten() - kPushCullOpSize)); |
| 1595 | fWriter.rewindToOffset(fWriter.bytesWritten() - kPushCullOpSize); |
| 1596 | return; |
| 1597 | } |
| 1598 | |
| 1599 | // op only |
| 1600 | uint32_t size = kUInt32Size; |
| 1601 | size_t initialOffset = this->addDraw(POP_CULL, &size); |
| 1602 | |
| 1603 | // update the cull skip offset to point past this op. |
| 1604 | fWriter.overwriteTAt<uint32_t>(cullSkipOffset, fWriter.bytesWritten()); |
| 1605 | |
| 1606 | this->validate(initialOffset, size); |
| 1607 | } |
| 1608 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1609 | /////////////////////////////////////////////////////////////////////////////// |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 1610 | |
reed@google.com | 76f10a3 | 2014-02-05 15:32:21 +0000 | [diff] [blame] | 1611 | SkSurface* SkPictureRecord::onNewSurface(const SkImageInfo& info) { |
| 1612 | return SkSurface::NewPicture(info.fWidth, info.fHeight); |
| 1613 | } |
| 1614 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1615 | void SkPictureRecord::addBitmap(const SkBitmap& bitmap) { |
scroggo@google.com | 4b90b11 | 2012-12-04 15:08:56 +0000 | [diff] [blame] | 1616 | const int index = fBitmapHeap->insert(bitmap); |
| 1617 | // In debug builds, a bad return value from insert() will crash, allowing for debugging. In |
| 1618 | // release builds, the invalid value will be recorded so that the reader will know that there |
| 1619 | // was a problem. |
| 1620 | SkASSERT(index != SkBitmapHeap::INVALID_SLOT); |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 1621 | this->addInt(index); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1622 | } |
| 1623 | |
| 1624 | void SkPictureRecord::addMatrix(const SkMatrix& matrix) { |
commit-bot@chromium.org | fed2ab6 | 2014-01-23 15:16:05 +0000 | [diff] [blame] | 1625 | fWriter.writeMatrix(matrix); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1626 | } |
| 1627 | |
commit-bot@chromium.org | cf7be95 | 2013-08-22 17:19:52 +0000 | [diff] [blame] | 1628 | const SkFlatData* SkPictureRecord::getFlatPaintData(const SkPaint& paint) { |
| 1629 | return fPaints.findAndReturnFlat(paint); |
| 1630 | } |
| 1631 | |
junov@chromium.org | f3b1223 | 2013-01-22 17:50:47 +0000 | [diff] [blame] | 1632 | const SkFlatData* SkPictureRecord::addPaintPtr(const SkPaint* paint) { |
commit-bot@chromium.org | cf7be95 | 2013-08-22 17:19:52 +0000 | [diff] [blame] | 1633 | const SkFlatData* data = paint ? getFlatPaintData(*paint) : NULL; |
| 1634 | this->addFlatPaint(data); |
junov@chromium.org | f3b1223 | 2013-01-22 17:50:47 +0000 | [diff] [blame] | 1635 | return data; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1636 | } |
| 1637 | |
commit-bot@chromium.org | cf7be95 | 2013-08-22 17:19:52 +0000 | [diff] [blame] | 1638 | void SkPictureRecord::addFlatPaint(const SkFlatData* flatPaint) { |
| 1639 | int index = flatPaint ? flatPaint->index() : 0; |
| 1640 | this->addInt(index); |
| 1641 | } |
| 1642 | |
robertphillips@google.com | 5a63f24 | 2014-02-04 20:07:50 +0000 | [diff] [blame] | 1643 | int SkPictureRecord::addPathToHeap(const SkPath& path) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1644 | if (NULL == fPathHeap) { |
| 1645 | fPathHeap = SkNEW(SkPathHeap); |
| 1646 | } |
robertphillips@google.com | 5a63f24 | 2014-02-04 20:07:50 +0000 | [diff] [blame] | 1647 | return fPathHeap->append(path); |
| 1648 | } |
| 1649 | |
| 1650 | void SkPictureRecord::addPath(const SkPath& path) { |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 1651 | this->addInt(this->addPathToHeap(path)); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1652 | } |
| 1653 | |
| 1654 | void SkPictureRecord::addPicture(SkPicture& picture) { |
| 1655 | int index = fPictureRefs.find(&picture); |
| 1656 | if (index < 0) { // not found |
| 1657 | index = fPictureRefs.count(); |
| 1658 | *fPictureRefs.append() = &picture; |
| 1659 | picture.ref(); |
| 1660 | } |
| 1661 | // follow the convention of recording a 1-based index |
robertphillips@google.com | cb6adec | 2014-02-05 14:05:38 +0000 | [diff] [blame] | 1662 | this->addInt(index + 1); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1663 | } |
| 1664 | |
| 1665 | void SkPictureRecord::addPoint(const SkPoint& point) { |
| 1666 | #ifdef SK_DEBUG_SIZE |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 1667 | size_t start = fWriter.bytesWritten(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1668 | #endif |
| 1669 | fWriter.writePoint(point); |
| 1670 | #ifdef SK_DEBUG_SIZE |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 1671 | fPointBytes += fWriter.bytesWritten() - start; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1672 | fPointWrites++; |
| 1673 | #endif |
| 1674 | } |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 1675 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1676 | void SkPictureRecord::addPoints(const SkPoint pts[], int count) { |
| 1677 | fWriter.writeMul4(pts, count * sizeof(SkPoint)); |
| 1678 | #ifdef SK_DEBUG_SIZE |
| 1679 | fPointBytes += count * sizeof(SkPoint); |
| 1680 | fPointWrites++; |
| 1681 | #endif |
| 1682 | } |
| 1683 | |
| 1684 | void SkPictureRecord::addRect(const SkRect& rect) { |
| 1685 | #ifdef SK_DEBUG_SIZE |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 1686 | size_t start = fWriter.bytesWritten(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1687 | #endif |
| 1688 | fWriter.writeRect(rect); |
| 1689 | #ifdef SK_DEBUG_SIZE |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 1690 | fRectBytes += fWriter.bytesWritten() - start; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1691 | fRectWrites++; |
| 1692 | #endif |
| 1693 | } |
| 1694 | |
| 1695 | void SkPictureRecord::addRectPtr(const SkRect* rect) { |
| 1696 | if (fWriter.writeBool(rect != NULL)) { |
| 1697 | fWriter.writeRect(*rect); |
| 1698 | } |
| 1699 | } |
| 1700 | |
reed@google.com | f0b5e11 | 2011-09-07 11:57:34 +0000 | [diff] [blame] | 1701 | void SkPictureRecord::addIRect(const SkIRect& rect) { |
| 1702 | fWriter.write(&rect, sizeof(rect)); |
| 1703 | } |
| 1704 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1705 | void SkPictureRecord::addIRectPtr(const SkIRect* rect) { |
| 1706 | if (fWriter.writeBool(rect != NULL)) { |
| 1707 | *(SkIRect*)fWriter.reserve(sizeof(SkIRect)) = *rect; |
| 1708 | } |
| 1709 | } |
| 1710 | |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 1711 | void SkPictureRecord::addRRect(const SkRRect& rrect) { |
| 1712 | fWriter.writeRRect(rrect); |
| 1713 | } |
| 1714 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1715 | void SkPictureRecord::addRegion(const SkRegion& region) { |
commit-bot@chromium.org | fed2ab6 | 2014-01-23 15:16:05 +0000 | [diff] [blame] | 1716 | fWriter.writeRegion(region); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1717 | } |
| 1718 | |
| 1719 | void SkPictureRecord::addText(const void* text, size_t byteLength) { |
| 1720 | #ifdef SK_DEBUG_SIZE |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 1721 | size_t start = fWriter.bytesWritten(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1722 | #endif |
| 1723 | addInt(byteLength); |
| 1724 | fWriter.writePad(text, byteLength); |
| 1725 | #ifdef SK_DEBUG_SIZE |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 1726 | fTextBytes += fWriter.bytesWritten() - start; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1727 | fTextWrites++; |
| 1728 | #endif |
| 1729 | } |
| 1730 | |
| 1731 | /////////////////////////////////////////////////////////////////////////////// |
| 1732 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1733 | #ifdef SK_DEBUG_SIZE |
| 1734 | size_t SkPictureRecord::size() const { |
| 1735 | size_t result = 0; |
| 1736 | size_t sizeData; |
| 1737 | bitmaps(&sizeData); |
| 1738 | result += sizeData; |
| 1739 | matrices(&sizeData); |
| 1740 | result += sizeData; |
| 1741 | paints(&sizeData); |
| 1742 | result += sizeData; |
| 1743 | paths(&sizeData); |
| 1744 | result += sizeData; |
| 1745 | pictures(&sizeData); |
| 1746 | result += sizeData; |
| 1747 | regions(&sizeData); |
| 1748 | result += sizeData; |
| 1749 | result += streamlen(); |
| 1750 | return result; |
| 1751 | } |
| 1752 | |
| 1753 | int SkPictureRecord::bitmaps(size_t* size) const { |
| 1754 | size_t result = 0; |
| 1755 | int count = fBitmaps.count(); |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 1756 | for (int index = 0; index < count; index++) |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1757 | result += sizeof(fBitmaps[index]) + fBitmaps[index]->size(); |
| 1758 | *size = result; |
| 1759 | return count; |
| 1760 | } |
| 1761 | |
| 1762 | int SkPictureRecord::matrices(size_t* size) const { |
| 1763 | int count = fMatrices.count(); |
| 1764 | *size = sizeof(fMatrices[0]) * count; |
| 1765 | return count; |
| 1766 | } |
| 1767 | |
| 1768 | int SkPictureRecord::paints(size_t* size) const { |
| 1769 | size_t result = 0; |
| 1770 | int count = fPaints.count(); |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 1771 | for (int index = 0; index < count; index++) |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1772 | result += sizeof(fPaints[index]) + fPaints[index]->size(); |
| 1773 | *size = result; |
| 1774 | return count; |
| 1775 | } |
| 1776 | |
| 1777 | int SkPictureRecord::paths(size_t* size) const { |
| 1778 | size_t result = 0; |
| 1779 | int count = fPaths.count(); |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 1780 | for (int index = 0; index < count; index++) |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1781 | result += sizeof(fPaths[index]) + fPaths[index]->size(); |
| 1782 | *size = result; |
| 1783 | return count; |
| 1784 | } |
| 1785 | |
| 1786 | int SkPictureRecord::regions(size_t* size) const { |
| 1787 | size_t result = 0; |
| 1788 | int count = fRegions.count(); |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 1789 | for (int index = 0; index < count; index++) |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1790 | result += sizeof(fRegions[index]) + fRegions[index]->size(); |
| 1791 | *size = result; |
| 1792 | return count; |
| 1793 | } |
| 1794 | |
| 1795 | size_t SkPictureRecord::streamlen() const { |
| 1796 | return fWriter.size(); |
| 1797 | } |
| 1798 | #endif |
| 1799 | |
| 1800 | #ifdef SK_DEBUG_VALIDATE |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 1801 | void SkPictureRecord::validate(uint32_t initialOffset, uint32_t size) const { |
| 1802 | SkASSERT(fWriter.size() == initialOffset + size); |
| 1803 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1804 | validateBitmaps(); |
| 1805 | validateMatrices(); |
| 1806 | validatePaints(); |
| 1807 | validatePaths(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1808 | validateRegions(); |
| 1809 | } |
| 1810 | |
| 1811 | void SkPictureRecord::validateBitmaps() const { |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 1812 | int count = fBitmapHeap->count(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1813 | SkASSERT((unsigned) count < 0x1000); |
| 1814 | for (int index = 0; index < count; index++) { |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 1815 | const SkBitmap* bitPtr = fBitmapHeap->getBitmap(index); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1816 | SkASSERT(bitPtr); |
| 1817 | bitPtr->validate(); |
| 1818 | } |
| 1819 | } |
| 1820 | |
| 1821 | void SkPictureRecord::validateMatrices() const { |
| 1822 | int count = fMatrices.count(); |
| 1823 | SkASSERT((unsigned) count < 0x1000); |
| 1824 | for (int index = 0; index < count; index++) { |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 1825 | const SkFlatData* matrix = fMatrices[index]; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1826 | SkASSERT(matrix); |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 1827 | // matrix->validate(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1828 | } |
| 1829 | } |
| 1830 | |
| 1831 | void SkPictureRecord::validatePaints() const { |
| 1832 | int count = fPaints.count(); |
| 1833 | SkASSERT((unsigned) count < 0x1000); |
| 1834 | for (int index = 0; index < count; index++) { |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 1835 | const SkFlatData* paint = fPaints[index]; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1836 | SkASSERT(paint); |
| 1837 | // paint->validate(); |
| 1838 | } |
| 1839 | } |
| 1840 | |
| 1841 | void SkPictureRecord::validatePaths() const { |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 1842 | if (NULL == fPathHeap) { |
| 1843 | return; |
| 1844 | } |
| 1845 | |
| 1846 | int count = fPathHeap->count(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1847 | SkASSERT((unsigned) count < 0x1000); |
| 1848 | for (int index = 0; index < count; index++) { |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 1849 | const SkPath& path = (*fPathHeap)[index]; |
| 1850 | path.validate(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1851 | } |
| 1852 | } |
| 1853 | |
| 1854 | void SkPictureRecord::validateRegions() const { |
| 1855 | int count = fRegions.count(); |
| 1856 | SkASSERT((unsigned) count < 0x1000); |
| 1857 | for (int index = 0; index < count; index++) { |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 1858 | const SkFlatData* region = fRegions[index]; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1859 | SkASSERT(region); |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 1860 | // region->validate(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1861 | } |
| 1862 | } |
| 1863 | #endif |