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