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