Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(33)

Side by Side Diff: src/core/SkPictureRecord.cpp

Issue 139093003: Collapse matrix & clip stack in PictureRecord (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: update to ToT Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/core/SkPictureRecord.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2011 Google Inc. 3 * Copyright 2011 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 #include "SkPictureRecord.h" 8 #include "SkPictureRecord.h"
9 #include "SkTSearch.h" 9 #include "SkTSearch.h"
10 #include "SkPixelRef.h" 10 #include "SkPixelRef.h"
11 #include "SkRRect.h" 11 #include "SkRRect.h"
12 #include "SkBBoxHierarchy.h" 12 #include "SkBBoxHierarchy.h"
13 #include "SkDevice.h" 13 #include "SkDevice.h"
14 #include "SkPictureStateTree.h" 14 #include "SkPictureStateTree.h"
15 15
16 #ifdef COLLAPSE_MATRIX_CLIP_STATE
17 bool MatrixClipState::ClipInfo::clipPath(SkPictureRecord* picRecord,
18 const SkPath& path,
19 SkRegion::Op op,
20 bool doAA,
21 const SkMatrix& matrix) {
22 int pathID = picRecord->addPathToHeap(path);
23
24 ClipOp* newClip = fClips.append();
25 newClip->fClipType = kPath_ClipType;
26 newClip->fGeom.fPathID = pathID;
27 newClip->fOp = op;
28 newClip->fDoAA = doAA;
29 newClip->fMatrix = matrix;
30 newClip->fOffset = kInvalidJumpOffset;
31 return false;
32 }
33
34 bool MatrixClipState::ClipInfo::clipRegion(SkPictureRecord* picRecord, const SkR egion& region,
35 SkRegion::Op op, const SkMatrix& matr ix) {
36 ClipOp* newClip = fClips.append();
37 newClip->fClipType = kRegion_ClipType;
38 newClip->fGeom.fRegion = SkNEW(SkRegion(region));
39 newClip->fOp = op;
40 newClip->fDoAA = true; // not necessary but sanity preserving
41 newClip->fMatrix = matrix;
42 newClip->fOffset = kInvalidJumpOffset;
43 return false;
44 }
45
46 void MatrixClipState::ClipInfo::writeClip(SkMatrix* curMat, SkPictureRecord* pic Record,
47 bool* overrideFirstOp) {
48
49 for (int i = 0; i < fClips.count(); ++i) {
50 ClipOp& curClip = fClips[i];
51
52 SkRegion::Op op = curClip.fOp;
53 if (*overrideFirstOp) {
54 op = SkRegion::kReplace_Op;
55 *overrideFirstOp = false;
56 }
57
58 if (*curMat != curClip.fMatrix) {
59 picRecord->setMatrixImpl(curClip.fMatrix);
60 *curMat = curClip.fMatrix;
61 }
62
63 switch (curClip.fClipType) {
64 case kRect_ClipType:
65 curClip.fOffset = picRecord->clipRectImpl(curClip.fGeom.fRRect.rect( ),
66 op, curClip.fDoAA);
67 break;
68 case kRRect_ClipType:
69 curClip.fOffset = picRecord->clipRRectImpl(curClip.fGeom.fRRect, op,
70 curClip.fDoAA);
71 break;
72 case kPath_ClipType:
73 curClip.fOffset = picRecord->clipPathImpl(curClip.fGeom.fPathID, op,
74 curClip.fDoAA);
75 break;
76 case kRegion_ClipType:
77 curClip.fOffset = picRecord->clipRegionImpl(*curClip.fGeom.fRegion, op);
78 break;
79 default:
80 SkASSERT(0);
81 }
82 }
83 }
84
85 void MatrixClipState::ClipInfo::fillInSkips(SkWriter32* writer, int32_t restoreO ffset) {
86 for (int i = 0; i < fClips.count(); ++i) {
87 const ClipOp& curClip = fClips[i];
88
89 SkASSERT(-1 != curClip.fOffset);
90 uint32_t* peek = writer->peek32(curClip.fOffset);
91 SkASSERT(-1 == *peek);
92 *peek = restoreOffset;
93 }
94 }
95
96 MatrixClipStateMgr::MatrixClipStateMgr()
97 : fPicRecord(NULL)
98 , fMatrixClipStack(sizeof(MatrixClipState),
99 fMatrixClipStackStorage,
100 sizeof(fMatrixClipStackStorage)) {
101 fCurMCState = (MatrixClipState*)fMatrixClipStack.push_back();
102 new (fCurMCState) MatrixClipState(NULL, 0); // balanced in restore()
103 }
104
105 void MatrixClipStateMgr::restore() {
106 if (fCurMCState->fIsSaveLayer) {
107 fPicRecord->restoreImpl();
108 }
109
110 fCurMCState->~MatrixClipState(); // balanced in save()
111 fMatrixClipStack.pop_back();
112 fCurMCState = (MatrixClipState*)fMatrixClipStack.back();
113 }
114
115 void MatrixClipStateMgr::call(CallType callType) {
116 if (fCurMCState->fIsCurrent || kOther_CallType != callType) {
117 return;
118 }
119
120 if (fCurMCState->fWroteSave) {
121 fCurMCState->fWroteSave = false;
122 fPicRecord->restoreImpl();
123 }
124
125 // write out save
126 fPicRecord->saveImpl(SkCanvas::kMatrixClip_SaveFlag);
127
128 // write out matrix
129 fPicRecord->setMatrixImpl(fCurMCState->fMatrixInfo->fMatrix);
130
131 // write out clips
132 SkDeque::F2BIter iter(fMatrixClipStack);
133 bool firstClip = true;
134
135 SkMatrix curMat = fCurMCState->fMatrixInfo->fMatrix;
136 for (const MatrixClipState* state = (const MatrixClipState*) iter.next();
137 state != NULL;
138 state = (const MatrixClipState*) iter.next()) {
139 state->fClipInfo->writeClip(&curMat, fPicRecord, &firstClip);
140 }
141
142 fCurMCState->fWroteSave = true;
143 fCurMCState->fIsCurrent = true;
144 }
145 #endif
146
16 #define HEAP_BLOCK_SIZE 4096 147 #define HEAP_BLOCK_SIZE 4096
17 148
18 enum { 149 enum {
19 // just need a value that save or getSaveCount would never return 150 // just need a value that save or getSaveCount would never return
20 kNoInitialSave = -1, 151 kNoInitialSave = -1,
21 }; 152 };
22 153
23 // A lot of basic types get stored as a uint32_t: bools, ints, paint indices, et c. 154 // A lot of basic types get stored as a uint32_t: bools, ints, paint indices, et c.
24 static int const kUInt32Size = 4; 155 static int const kUInt32Size = 4;
25 156
26 static const uint32_t kSaveSize = 2 * kUInt32Size; 157 static const uint32_t kSaveSize = 2 * kUInt32Size;
27 static const uint32_t kSaveLayerNoBoundsSize = 4 * kUInt32Size; 158 static const uint32_t kSaveLayerNoBoundsSize = 4 * kUInt32Size;
28 static const uint32_t kSaveLayerWithBoundsSize = 4 * kUInt32Size + sizeof(SkRect ); 159 static const uint32_t kSaveLayerWithBoundsSize = 4 * kUInt32Size + sizeof(SkRect );
29 160
30 SkPictureRecord::SkPictureRecord(uint32_t flags, SkBaseDevice* device) : 161 SkPictureRecord::SkPictureRecord(uint32_t flags, SkBaseDevice* device)
31 INHERITED(device), 162 : INHERITED(device)
32 fBoundingHierarchy(NULL), 163 , fBoundingHierarchy(NULL)
33 fStateTree(NULL), 164 , fStateTree(NULL)
34 fFlattenableHeap(HEAP_BLOCK_SIZE), 165 , fFlattenableHeap(HEAP_BLOCK_SIZE)
35 fPaints(&fFlattenableHeap), 166 , fPaints(&fFlattenableHeap)
36 fRecordFlags(flags) { 167 , fRecordFlags(flags) {
37 #ifdef SK_DEBUG_SIZE 168 #ifdef SK_DEBUG_SIZE
38 fPointBytes = fRectBytes = fTextBytes = 0; 169 fPointBytes = fRectBytes = fTextBytes = 0;
39 fPointWrites = fRectWrites = fTextWrites = 0; 170 fPointWrites = fRectWrites = fTextWrites = 0;
40 #endif 171 #endif
41 172
42 fBitmapHeap = SkNEW(SkBitmapHeap); 173 fBitmapHeap = SkNEW(SkBitmapHeap);
43 fFlattenableHeap.setBitmapStorage(fBitmapHeap); 174 fFlattenableHeap.setBitmapStorage(fBitmapHeap);
44 fPathHeap = NULL; // lazy allocate 175 fPathHeap = NULL; // lazy allocate
176 #ifndef COLLAPSE_MATRIX_CLIP_STATE
45 fFirstSavedLayerIndex = kNoSavedLayerIndex; 177 fFirstSavedLayerIndex = kNoSavedLayerIndex;
178 #endif
46 179
47 fInitialSaveCount = kNoInitialSave; 180 fInitialSaveCount = kNoInitialSave;
181
182 #ifdef COLLAPSE_MATRIX_CLIP_STATE
183 fMCMgr.init(this);
184 #endif
48 } 185 }
49 186
50 SkPictureRecord::~SkPictureRecord() { 187 SkPictureRecord::~SkPictureRecord() {
51 SkSafeUnref(fBitmapHeap); 188 SkSafeUnref(fBitmapHeap);
52 SkSafeUnref(fPathHeap); 189 SkSafeUnref(fPathHeap);
53 SkSafeUnref(fBoundingHierarchy); 190 SkSafeUnref(fBoundingHierarchy);
54 SkSafeUnref(fStateTree); 191 SkSafeUnref(fStateTree);
55 fFlattenableHeap.setBitmapStorage(NULL); 192 fFlattenableHeap.setBitmapStorage(NULL);
56 fPictureRefs.unrefAll(); 193 fPictureRefs.unrefAll();
57 } 194 }
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 SkASSERT(0 != gPaintOffsets[op]); // really shouldn't be calling this meth od 268 SkASSERT(0 != gPaintOffsets[op]); // really shouldn't be calling this meth od
132 return gPaintOffsets[op] * sizeof(uint32_t) + overflow; 269 return gPaintOffsets[op] * sizeof(uint32_t) + overflow;
133 } 270 }
134 271
135 SkBaseDevice* SkPictureRecord::setDevice(SkBaseDevice* device) { 272 SkBaseDevice* SkPictureRecord::setDevice(SkBaseDevice* device) {
136 SkDEBUGFAIL("eeek, don't try to change the device on a recording canvas"); 273 SkDEBUGFAIL("eeek, don't try to change the device on a recording canvas");
137 return this->INHERITED::setDevice(device); 274 return this->INHERITED::setDevice(device);
138 } 275 }
139 276
140 int SkPictureRecord::save(SaveFlags flags) { 277 int SkPictureRecord::save(SaveFlags flags) {
278
279 #ifdef COLLAPSE_MATRIX_CLIP_STATE
280 // TODO: need to skip saving "save" to op stream & replace restore stack
281 fMCMgr.save(flags);
282 #else
141 // record the offset to us, making it non-positive to distinguish a save 283 // record the offset to us, making it non-positive to distinguish a save
142 // from a clip entry. 284 // from a clip entry.
143 fRestoreOffsetStack.push(-(int32_t)fWriter.bytesWritten()); 285 fRestoreOffsetStack.push(-(int32_t)fWriter.bytesWritten());
286 this->saveImpl(flags);
287 #endif
288 return this->INHERITED::save(flags);
289 }
144 290
291 void SkPictureRecord::saveImpl(SaveFlags flags) {
145 // op + flags 292 // op + flags
146 uint32_t size = kSaveSize; 293 uint32_t size = kSaveSize;
147 size_t initialOffset = this->addDraw(SAVE, &size); 294 size_t initialOffset = this->addDraw(SAVE, &size);
148 addInt(flags); 295 addInt(flags);
149 296
150 this->validate(initialOffset, size); 297 this->validate(initialOffset, size);
151 return this->INHERITED::save(flags);
152 } 298 }
153 299
154 int SkPictureRecord::saveLayer(const SkRect* bounds, const SkPaint* paint, 300 int SkPictureRecord::saveLayer(const SkRect* bounds, const SkPaint* paint,
155 SaveFlags flags) { 301 SaveFlags flags) {
302
303 int count;
304 #ifdef COLLAPSE_MATRIX_CLIP_STATE
305 // TODO: need to replace restore stack mechanism
306 count = fMCMgr.saveLayer(bounds, paint, flags);
307 #else
156 // record the offset to us, making it non-positive to distinguish a save 308 // record the offset to us, making it non-positive to distinguish a save
157 // from a clip entry. 309 // from a clip entry.
158 fRestoreOffsetStack.push(-(int32_t)fWriter.bytesWritten()); 310 fRestoreOffsetStack.push(-(int32_t)fWriter.bytesWritten());
311 #endif
159 312
160 // op + bool for 'bounds' 313 // op + bool for 'bounds'
161 uint32_t size = 2 * kUInt32Size; 314 uint32_t size = 2 * kUInt32Size;
162 if (NULL != bounds) { 315 if (NULL != bounds) {
163 size += sizeof(*bounds); // + rect 316 size += sizeof(*bounds); // + rect
164 } 317 }
165 // + paint index + flags 318 // + paint index + flags
166 size += 2 * kUInt32Size; 319 size += 2 * kUInt32Size;
167 320
168 SkASSERT(kSaveLayerNoBoundsSize == size || kSaveLayerWithBoundsSize == size) ; 321 SkASSERT(kSaveLayerNoBoundsSize == size || kSaveLayerWithBoundsSize == size) ;
169 322
170 size_t initialOffset = this->addDraw(SAVE_LAYER, &size); 323 size_t initialOffset = this->addDraw(SAVE_LAYER, &size);
171 addRectPtr(bounds); 324 addRectPtr(bounds);
172 SkASSERT(initialOffset+getPaintOffset(SAVE_LAYER, size) == fWriter.bytesWrit ten()); 325 SkASSERT(initialOffset+getPaintOffset(SAVE_LAYER, size) == fWriter.bytesWrit ten());
173 addPaintPtr(paint); 326 addPaintPtr(paint);
174 addInt(flags); 327 addInt(flags);
175 328
329 #ifndef COLLAPSE_MATRIX_CLIP_STATE
176 if (kNoSavedLayerIndex == fFirstSavedLayerIndex) { 330 if (kNoSavedLayerIndex == fFirstSavedLayerIndex) {
177 fFirstSavedLayerIndex = fRestoreOffsetStack.count(); 331 fFirstSavedLayerIndex = fRestoreOffsetStack.count();
178 } 332 }
333 #endif
179 334
180 this->validate(initialOffset, size); 335 this->validate(initialOffset, size);
181 /* Don't actually call saveLayer, because that will try to allocate an 336 /* Don't actually call saveLayer, because that will try to allocate an
182 offscreen device (potentially very big) which we don't actually need 337 offscreen device (potentially very big) which we don't actually need
183 at this time (and may not be able to afford since during record our 338 at this time (and may not be able to afford since during record our
184 clip starts out the size of the picture, which is often much larger 339 clip starts out the size of the picture, which is often much larger
185 than the size of the actual device we'll use during playback). 340 than the size of the actual device we'll use during playback).
186 */ 341 */
187 int count = this->INHERITED::save(flags); 342 count = this->INHERITED::save(flags);
188 this->clipRectBounds(bounds, flags, NULL); 343 this->clipRectBounds(bounds, flags, NULL);
189 return count; 344 return count;
190 } 345 }
191 346
192 bool SkPictureRecord::isDrawingToLayer() const { 347 bool SkPictureRecord::isDrawingToLayer() const {
348 #ifdef COLLAPSE_MATRIX_CLIP_STATE
349 return fMCMgr.isDrawingToLayer();
350 #else
193 return fFirstSavedLayerIndex != kNoSavedLayerIndex; 351 return fFirstSavedLayerIndex != kNoSavedLayerIndex;
352 #endif
194 } 353 }
195 354
196 /* 355 /*
197 * Read the op code from 'offset' in 'writer' and extract the size too. 356 * Read the op code from 'offset' in 'writer' and extract the size too.
198 */ 357 */
199 static DrawType peek_op_and_size(SkWriter32* writer, int32_t offset, uint32_t* s ize) { 358 static DrawType peek_op_and_size(SkWriter32* writer, int32_t offset, uint32_t* s ize) {
200 uint32_t* peek = writer->peek32(offset); 359 uint32_t* peek = writer->peek32(offset);
201 360
202 uint32_t op; 361 uint32_t op;
203 UNPACK_8_24(*peek, op, *size); 362 UNPACK_8_24(*peek, op, *size);
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 473
315 if (!match(writer, -offset, pattern, result, SK_ARRAY_COUNT(pattern))) { 474 if (!match(writer, -offset, pattern, result, SK_ARRAY_COUNT(pattern))) {
316 return false; 475 return false;
317 } 476 }
318 477
319 if (kSaveLayerWithBoundsSize == result[0].fSize) { 478 if (kSaveLayerWithBoundsSize == result[0].fSize) {
320 // The saveLayer's bound can offset where the dbm is drawn 479 // The saveLayer's bound can offset where the dbm is drawn
321 return false; 480 return false;
322 } 481 }
323 482
324
325 return merge_savelayer_paint_into_drawbitmp(writer, paintDict, 483 return merge_savelayer_paint_into_drawbitmp(writer, paintDict,
326 result[0], result[1]); 484 result[0], result[1]);
327 } 485 }
328 486
329 /* 487 /*
330 * Convert the command code located at 'offset' to a NOOP. Leave the size 488 * Convert the command code located at 'offset' to a NOOP. Leave the size
331 * field alone so the NOOP can be skipped later. 489 * field alone so the NOOP can be skipped later.
332 */ 490 */
333 static void convert_command_to_noop(SkWriter32* writer, uint32_t offset) { 491 static void convert_command_to_noop(SkWriter32* writer, uint32_t offset) {
334 uint32_t* ptr = writer->peek32(offset); 492 uint32_t* ptr = writer->peek32(offset);
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 } 725 }
568 726
569 void SkPictureRecord::restore() { 727 void SkPictureRecord::restore() {
570 // FIXME: SkDeferredCanvas needs to be refactored to respect 728 // FIXME: SkDeferredCanvas needs to be refactored to respect
571 // save/restore balancing so that the following test can be 729 // save/restore balancing so that the following test can be
572 // turned on permanently. 730 // turned on permanently.
573 #if 0 731 #if 0
574 SkASSERT(fRestoreOffsetStack.count() > 1); 732 SkASSERT(fRestoreOffsetStack.count() > 1);
575 #endif 733 #endif
576 734
735 #ifdef COLLAPSE_MATRIX_CLIP_STATE
736 if (fMCMgr.getSaveCount() == 1) {
737 return;
738 }
739
740 // TODO: don't write the restore to the op stream for normal saves
741 fMCMgr.restore();
742 #else
577 // check for underflow 743 // check for underflow
578 if (fRestoreOffsetStack.count() == 0) { 744 if (fRestoreOffsetStack.count() == 0) {
579 return; 745 return;
580 } 746 }
581 747
582 if (fRestoreOffsetStack.count() == fFirstSavedLayerIndex) { 748 if (fRestoreOffsetStack.count() == fFirstSavedLayerIndex) {
583 fFirstSavedLayerIndex = kNoSavedLayerIndex; 749 fFirstSavedLayerIndex = kNoSavedLayerIndex;
584 } 750 }
585 751
586 uint32_t initialOffset, size; 752 uint32_t initialOffset, size;
587 size_t opt = 0; 753 size_t opt = 0;
754 // TODO: need to bring optimization back to life in new world
588 if (!(fRecordFlags & SkPicture::kDisableRecordOptimizations_RecordingFlag)) { 755 if (!(fRecordFlags & SkPicture::kDisableRecordOptimizations_RecordingFlag)) {
589 for (opt = 0; opt < SK_ARRAY_COUNT(gPictureRecordOpts); ++opt) { 756 for (opt = 0; opt < SK_ARRAY_COUNT(gPictureRecordOpts); ++opt) {
590 if (0 != (gPictureRecordOpts[opt].fFlags & kSkipIfBBoxHierarchy_Flag ) 757 if (0 != (gPictureRecordOpts[opt].fFlags & kSkipIfBBoxHierarchy_Flag )
591 && NULL != fBoundingHierarchy) { 758 && NULL != fBoundingHierarchy) {
592 continue; 759 continue;
593 } 760 }
594 if ((*gPictureRecordOpts[opt].fProc)(&fWriter, fRestoreOffsetStack.t op(), &fPaints)) { 761 if ((*gPictureRecordOpts[opt].fProc)(&fWriter, fRestoreOffsetStack.t op(), &fPaints)) {
595 // Some optimization fired so don't add the RESTORE 762 // Some optimization fired so don't add the RESTORE
596 size = 0; 763 size = 0;
597 initialOffset = fWriter.bytesWritten(); 764 initialOffset = fWriter.bytesWritten();
598 apply_optimization_to_bbh(gPictureRecordOpts[opt].fType, 765 apply_optimization_to_bbh(gPictureRecordOpts[opt].fType,
599 fStateTree, fBoundingHierarchy); 766 fStateTree, fBoundingHierarchy);
600 break; 767 break;
601 } 768 }
602 } 769 }
603 } 770 }
604 771
605 if ((fRecordFlags & SkPicture::kDisableRecordOptimizations_RecordingFlag) || 772 if ((fRecordFlags & SkPicture::kDisableRecordOptimizations_RecordingFlag) ||
606 SK_ARRAY_COUNT(gPictureRecordOpts) == opt) { 773 SK_ARRAY_COUNT(gPictureRecordOpts) == opt) {
607 // No optimization fired so add the RESTORE 774 // No optimization fired so add the RESTORE
608 fillRestoreOffsetPlaceholdersForCurrentStackLevel((uint32_t)fWriter.byte sWritten()); 775 this->restoreImpl();
609 size = 1 * kUInt32Size; // RESTORE consists solely of 1 op code
610 initialOffset = this->addDraw(RESTORE, &size);
611 } 776 }
612 777
613 fRestoreOffsetStack.pop(); 778 fRestoreOffsetStack.pop();
779 #endif
614 780
615 this->validate(initialOffset, size);
616 return this->INHERITED::restore(); 781 return this->INHERITED::restore();
617 } 782 }
618 783
784 void SkPictureRecord::restoreImpl() {
785 uint32_t initialOffset, size;
786 this->fillRestoreOffsetPlaceholdersForCurrentStackLevel((uint32_t)fWriter.by tesWritten());
787 size = 1 * kUInt32Size; // RESTORE consists solely of 1 op code
788 initialOffset = this->addDraw(RESTORE, &size);
789 this->validate(initialOffset, size);
790 }
791
619 bool SkPictureRecord::translate(SkScalar dx, SkScalar dy) { 792 bool SkPictureRecord::translate(SkScalar dx, SkScalar dy) {
793
794 if (0 == dx && 0 == dy) {
795 return true;
796 }
797
798 #ifdef COLLAPSE_MATRIX_CLIP_STATE
799 fMCMgr.translate(dx, dy);
800 #else
620 // op + dx + dy 801 // op + dx + dy
621 uint32_t size = 1 * kUInt32Size + 2 * sizeof(SkScalar); 802 uint32_t size = 1 * kUInt32Size + 2 * sizeof(SkScalar);
622 size_t initialOffset = this->addDraw(TRANSLATE, &size); 803 size_t initialOffset = this->addDraw(TRANSLATE, &size);
623 addScalar(dx); 804 addScalar(dx);
624 addScalar(dy); 805 addScalar(dy);
625 this->validate(initialOffset, size); 806 this->validate(initialOffset, size);
807 #endif
626 return this->INHERITED::translate(dx, dy); 808 return this->INHERITED::translate(dx, dy);
627 } 809 }
628 810
629 bool SkPictureRecord::scale(SkScalar sx, SkScalar sy) { 811 bool SkPictureRecord::scale(SkScalar sx, SkScalar sy) {
812
813 #ifdef COLLAPSE_MATRIX_CLIP_STATE
814 fMCMgr.scale(sx, sy);
815 #else
630 // op + sx + sy 816 // op + sx + sy
631 uint32_t size = 1 * kUInt32Size + 2 * sizeof(SkScalar); 817 uint32_t size = 1 * kUInt32Size + 2 * sizeof(SkScalar);
632 size_t initialOffset = this->addDraw(SCALE, &size); 818 size_t initialOffset = this->addDraw(SCALE, &size);
633 addScalar(sx); 819 addScalar(sx);
634 addScalar(sy); 820 addScalar(sy);
635 this->validate(initialOffset, size); 821 this->validate(initialOffset, size);
822 #endif
636 return this->INHERITED::scale(sx, sy); 823 return this->INHERITED::scale(sx, sy);
637 } 824 }
638 825
639 bool SkPictureRecord::rotate(SkScalar degrees) { 826 bool SkPictureRecord::rotate(SkScalar degrees) {
827
828 #ifdef COLLAPSE_MATRIX_CLIP_STATE
829 fMCMgr.rotate(degrees);
830 #else
640 // op + degrees 831 // op + degrees
641 uint32_t size = 1 * kUInt32Size + sizeof(SkScalar); 832 uint32_t size = 1 * kUInt32Size + sizeof(SkScalar);
642 size_t initialOffset = this->addDraw(ROTATE, &size); 833 size_t initialOffset = this->addDraw(ROTATE, &size);
643 addScalar(degrees); 834 addScalar(degrees);
644 this->validate(initialOffset, size); 835 this->validate(initialOffset, size);
836 #endif
645 return this->INHERITED::rotate(degrees); 837 return this->INHERITED::rotate(degrees);
646 } 838 }
647 839
648 bool SkPictureRecord::skew(SkScalar sx, SkScalar sy) { 840 bool SkPictureRecord::skew(SkScalar sx, SkScalar sy) {
841
842 #ifdef COLLAPSE_MATRIX_CLIP_STATE
843 fMCMgr.skew(sx, sy);
844 #else
649 // op + sx + sy 845 // op + sx + sy
650 uint32_t size = 1 * kUInt32Size + 2 * sizeof(SkScalar); 846 uint32_t size = 1 * kUInt32Size + 2 * sizeof(SkScalar);
651 size_t initialOffset = this->addDraw(SKEW, &size); 847 size_t initialOffset = this->addDraw(SKEW, &size);
652 addScalar(sx); 848 addScalar(sx);
653 addScalar(sy); 849 addScalar(sy);
654 this->validate(initialOffset, size); 850 this->validate(initialOffset, size);
851 #endif
655 return this->INHERITED::skew(sx, sy); 852 return this->INHERITED::skew(sx, sy);
656 } 853 }
657 854
658 bool SkPictureRecord::concat(const SkMatrix& matrix) { 855 bool SkPictureRecord::concat(const SkMatrix& matrix) {
856
857 #ifdef COLLAPSE_MATRIX_CLIP_STATE
858 fMCMgr.concat(matrix);
859 #else
860 this->concatImpl(matrix);
861 #endif
862 return this->INHERITED::concat(matrix);
863 }
864
865 void SkPictureRecord::concatImpl(const SkMatrix& matrix) {
659 this->validate(fWriter.bytesWritten(), 0); 866 this->validate(fWriter.bytesWritten(), 0);
660 // op + matrix 867 // op + matrix
661 uint32_t size = kUInt32Size + matrix.writeToMemory(NULL); 868 uint32_t size = kUInt32Size + matrix.writeToMemory(NULL);
662 size_t initialOffset = this->addDraw(CONCAT, &size); 869 size_t initialOffset = this->addDraw(CONCAT, &size);
663 addMatrix(matrix); 870 this->addMatrix(matrix);
664 this->validate(initialOffset, size); 871 this->validate(initialOffset, size);
665 return this->INHERITED::concat(matrix);
666 } 872 }
667 873
668 void SkPictureRecord::setMatrix(const SkMatrix& matrix) { 874 void SkPictureRecord::setMatrix(const SkMatrix& matrix) {
875
876 #ifdef COLLAPSE_MATRIX_CLIP_STATE
877 fMCMgr.setMatrix(matrix);
878 #else
879 this->setMatrixImpl(matrix);
880 #endif
881 this->INHERITED::setMatrix(matrix);
882 }
883
884 void SkPictureRecord::setMatrixImpl(const SkMatrix& matrix) {
669 this->validate(fWriter.bytesWritten(), 0); 885 this->validate(fWriter.bytesWritten(), 0);
670 // op + matrix 886 // op + matrix
671 uint32_t size = kUInt32Size + matrix.writeToMemory(NULL); 887 uint32_t size = kUInt32Size + matrix.writeToMemory(NULL);
672 size_t initialOffset = this->addDraw(SET_MATRIX, &size); 888 size_t initialOffset = this->addDraw(SET_MATRIX, &size);
673 addMatrix(matrix); 889 this->addMatrix(matrix);
674 this->validate(initialOffset, size); 890 this->validate(initialOffset, size);
675 this->INHERITED::setMatrix(matrix);
676 } 891 }
677 892
678 static bool regionOpExpands(SkRegion::Op op) { 893 static bool regionOpExpands(SkRegion::Op op) {
679 switch (op) { 894 switch (op) {
680 case SkRegion::kUnion_Op: 895 case SkRegion::kUnion_Op:
681 case SkRegion::kXOR_Op: 896 case SkRegion::kXOR_Op:
682 case SkRegion::kReverseDifference_Op: 897 case SkRegion::kReverseDifference_Op:
683 case SkRegion::kReplace_Op: 898 case SkRegion::kReplace_Op:
684 return true; 899 return true;
685 case SkRegion::kIntersect_Op: 900 case SkRegion::kIntersect_Op:
686 case SkRegion::kDifference_Op: 901 case SkRegion::kDifference_Op:
687 return false; 902 return false;
688 default: 903 default:
689 SkDEBUGFAIL("unknown region op"); 904 SkDEBUGFAIL("unknown region op");
690 return false; 905 return false;
691 } 906 }
692 } 907 }
693 908
909 #ifdef COLLAPSE_MATRIX_CLIP_STATE
910 void SkPictureRecord::fillRestoreOffsetPlaceholdersForCurrentStackLevel(uint32_t restoreOffset) {
911 fMCMgr.fillInSkips(&fWriter, restoreOffset);
912 }
913 #else
694 void SkPictureRecord::fillRestoreOffsetPlaceholdersForCurrentStackLevel(uint32_t restoreOffset) { 914 void SkPictureRecord::fillRestoreOffsetPlaceholdersForCurrentStackLevel(uint32_t restoreOffset) {
695 int32_t offset = fRestoreOffsetStack.top(); 915 int32_t offset = fRestoreOffsetStack.top();
696 while (offset > 0) { 916 while (offset > 0) {
697 uint32_t* peek = fWriter.peek32(offset); 917 uint32_t* peek = fWriter.peek32(offset);
698 offset = *peek; 918 offset = *peek;
699 *peek = restoreOffset; 919 *peek = restoreOffset;
700 } 920 }
701 921
702 #ifdef SK_DEBUG 922 #ifdef SK_DEBUG
703 // assert that the final offset value points to a save verb 923 // assert that the final offset value points to a save verb
704 uint32_t opSize; 924 uint32_t opSize;
705 DrawType drawOp = peek_op_and_size(&fWriter, -offset, &opSize); 925 DrawType drawOp = peek_op_and_size(&fWriter, -offset, &opSize);
706 SkASSERT(SAVE == drawOp || SAVE_LAYER == drawOp); 926 SkASSERT(SAVE == drawOp || SAVE_LAYER == drawOp);
707 #endif 927 #endif
708 } 928 }
929 #endif
709 930
710 void SkPictureRecord::beginRecording() { 931 void SkPictureRecord::beginRecording() {
711 // we have to call this *after* our constructor, to ensure that it gets 932 // we have to call this *after* our constructor, to ensure that it gets
712 // recorded. This is balanced by restoreToCount() call from endRecording, 933 // recorded. This is balanced by restoreToCount() call from endRecording,
713 // which in-turn calls our overridden restore(), so those get recorded too. 934 // which in-turn calls our overridden restore(), so those get recorded too.
714 fInitialSaveCount = this->save(kMatrixClip_SaveFlag); 935 fInitialSaveCount = this->save(kMatrixClip_SaveFlag);
715 } 936 }
716 937
717 void SkPictureRecord::endRecording() { 938 void SkPictureRecord::endRecording() {
718 SkASSERT(kNoInitialSave != fInitialSaveCount); 939 SkASSERT(kNoInitialSave != fInitialSaveCount);
719 this->restoreToCount(fInitialSaveCount); 940 this->restoreToCount(fInitialSaveCount);
941 #ifdef COLLAPSE_MATRIX_CLIP_STATE
942 fMCMgr.finish1();
943 #endif
720 } 944 }
721 945
722 void SkPictureRecord::recordRestoreOffsetPlaceholder(SkRegion::Op op) { 946 #ifdef COLLAPSE_MATRIX_CLIP_STATE
947 int SkPictureRecord::recordRestoreOffsetPlaceholder(SkRegion::Op op) {
948 size_t offset = fWriter.bytesWritten();
949 this->addInt(0);
950 return offset;
951 }
952 #else
953 int SkPictureRecord::recordRestoreOffsetPlaceholder(SkRegion::Op op) {
723 if (fRestoreOffsetStack.isEmpty()) { 954 if (fRestoreOffsetStack.isEmpty()) {
724 return; 955 return -1;
725 } 956 }
726 957
727 // The RestoreOffset field is initially filled with a placeholder 958 // The RestoreOffset field is initially filled with a placeholder
728 // value that points to the offset of the previous RestoreOffset 959 // value that points to the offset of the previous RestoreOffset
729 // in the current stack level, thus forming a linked list so that 960 // in the current stack level, thus forming a linked list so that
730 // the restore offsets can be filled in when the corresponding 961 // the restore offsets can be filled in when the corresponding
731 // restore command is recorded. 962 // restore command is recorded.
732 int32_t prevOffset = fRestoreOffsetStack.top(); 963 int32_t prevOffset = fRestoreOffsetStack.top();
733 964
734 if (regionOpExpands(op)) { 965 if (regionOpExpands(op)) {
735 // Run back through any previous clip ops, and mark their offset to 966 // Run back through any previous clip ops, and mark their offset to
736 // be 0, disabling their ability to trigger a jump-to-restore, otherwise 967 // be 0, disabling their ability to trigger a jump-to-restore, otherwise
737 // they could hide this clips ability to expand the clip (i.e. go from 968 // they could hide this clips ability to expand the clip (i.e. go from
738 // empty to non-empty). 969 // empty to non-empty).
739 fillRestoreOffsetPlaceholdersForCurrentStackLevel(0); 970 fillRestoreOffsetPlaceholdersForCurrentStackLevel(0);
740 971
741 // Reset the pointer back to the previous clip so that subsequent 972 // Reset the pointer back to the previous clip so that subsequent
742 // restores don't overwrite the offsets we just cleared. 973 // restores don't overwrite the offsets we just cleared.
743 prevOffset = 0; 974 prevOffset = 0;
744 } 975 }
745 976
746 size_t offset = fWriter.bytesWritten(); 977 size_t offset = fWriter.bytesWritten();
747 addInt(prevOffset); 978 this->addInt(prevOffset);
748 fRestoreOffsetStack.top() = offset; 979 fRestoreOffsetStack.top() = offset;
980 return offset;
981 }
982 #endif
983
984 bool SkPictureRecord::clipRect(const SkRect& rect, SkRegion::Op op, bool doAA) {
985
986 #ifdef COLLAPSE_MATRIX_CLIP_STATE
987 fMCMgr.clipRect(rect, op, doAA);
988 #else
989 this->clipRectImpl(rect, op, doAA);
990 #endif
991 return this->INHERITED::clipRect(rect, op, doAA);
749 } 992 }
750 993
751 bool SkPictureRecord::clipRect(const SkRect& rect, SkRegion::Op op, bool doAA) { 994 int SkPictureRecord::clipRectImpl(const SkRect& rect, SkRegion::Op op, bool doAA ) {
995
752 // id + rect + clip params 996 // id + rect + clip params
753 uint32_t size = 1 * kUInt32Size + sizeof(rect) + 1 * kUInt32Size; 997 uint32_t size = 1 * kUInt32Size + sizeof(rect) + 1 * kUInt32Size;
998 #ifdef COLLAPSE_MATRIX_CLIP_STATE
999 size += kUInt32Size;
1000 #else
754 // recordRestoreOffsetPlaceholder doesn't always write an offset 1001 // recordRestoreOffsetPlaceholder doesn't always write an offset
755 if (!fRestoreOffsetStack.isEmpty()) { 1002 if (!fRestoreOffsetStack.isEmpty()) {
756 // + restore offset 1003 // + restore offset
757 size += kUInt32Size; 1004 size += kUInt32Size;
758 } 1005 }
1006 #endif
1007
759 size_t initialOffset = this->addDraw(CLIP_RECT, &size); 1008 size_t initialOffset = this->addDraw(CLIP_RECT, &size);
760 addRect(rect); 1009 this->addRect(rect);
761 addInt(ClipParams_pack(op, doAA)); 1010 this->addInt(ClipParams_pack(op, doAA));
762 recordRestoreOffsetPlaceholder(op); 1011 int offset = this->recordRestoreOffsetPlaceholder(op);
763 1012
764 this->validate(initialOffset, size); 1013 this->validate(initialOffset, size);
765 return this->INHERITED::clipRect(rect, op, doAA); 1014 return offset;
766 } 1015 }
767 1016
768 bool SkPictureRecord::clipRRect(const SkRRect& rrect, SkRegion::Op op, bool doAA ) { 1017 bool SkPictureRecord::clipRRect(const SkRRect& rrect, SkRegion::Op op, bool doAA ) {
769 if (rrect.isRect()) { 1018 if (rrect.isRect()) {
770 return this->SkPictureRecord::clipRect(rrect.getBounds(), op, doAA); 1019 return this->SkPictureRecord::clipRect(rrect.getBounds(), op, doAA);
771 } 1020 }
772 1021
773 // op + rrect + clip params 1022 #ifdef COLLAPSE_MATRIX_CLIP_STATE
774 uint32_t size = 1 * kUInt32Size + SkRRect::kSizeInMemory + 1 * kUInt32Size; 1023 fMCMgr.clipRRect(rrect, op, doAA);
775 // recordRestoreOffsetPlaceholder doesn't always write an offset 1024 #else
776 if (!fRestoreOffsetStack.isEmpty()) { 1025 this->clipRRectImpl(rrect, op, doAA);
777 // + restore offset 1026 #endif
778 size += kUInt32Size;
779 }
780 size_t initialOffset = this->addDraw(CLIP_RRECT, &size);
781 addRRect(rrect);
782 addInt(ClipParams_pack(op, doAA));
783 recordRestoreOffsetPlaceholder(op);
784
785 this->validate(initialOffset, size);
786
787 if (fRecordFlags & SkPicture::kUsePathBoundsForClip_RecordingFlag) { 1027 if (fRecordFlags & SkPicture::kUsePathBoundsForClip_RecordingFlag) {
788 return this->updateClipConservativelyUsingBounds(rrect.getBounds(), op, false); 1028 return this->updateClipConservativelyUsingBounds(rrect.getBounds(), op, false);
789 } else { 1029 } else {
790 return this->INHERITED::clipRRect(rrect, op, doAA); 1030 return this->INHERITED::clipRRect(rrect, op, doAA);
791 } 1031 }
792 } 1032 }
793 1033
1034 int SkPictureRecord::clipRRectImpl(const SkRRect& rrect, SkRegion::Op op, bool d oAA) {
1035
1036 // op + rrect + clip params
1037 uint32_t size = 1 * kUInt32Size + SkRRect::kSizeInMemory + 1 * kUInt32Size;
1038 #ifdef COLLAPSE_MATRIX_CLIP_STATE
1039 size += kUInt32Size;
1040 #else
1041 // recordRestoreOffsetPlaceholder doesn't always write an offset
1042 if (!fRestoreOffsetStack.isEmpty()) {
1043 // + restore offset
1044 size += kUInt32Size;
1045 }
1046 #endif
1047 size_t initialOffset = this->addDraw(CLIP_RRECT, &size);
1048 addRRect(rrect);
1049 addInt(ClipParams_pack(op, doAA));
1050 int offset = recordRestoreOffsetPlaceholder(op);
1051
1052 this->validate(initialOffset, size);
1053 return offset;
1054 }
1055
794 bool SkPictureRecord::clipPath(const SkPath& path, SkRegion::Op op, bool doAA) { 1056 bool SkPictureRecord::clipPath(const SkPath& path, SkRegion::Op op, bool doAA) {
795 1057
796 SkRect r; 1058 SkRect r;
797 if (!path.isInverseFillType() && path.isRect(&r)) { 1059 if (!path.isInverseFillType() && path.isRect(&r)) {
798 return this->clipRect(r, op, doAA); 1060 return this->clipRect(r, op, doAA);
799 } 1061 }
800 1062
801 // op + path index + clip params 1063 #ifdef COLLAPSE_MATRIX_CLIP_STATE
802 uint32_t size = 3 * kUInt32Size; 1064 fMCMgr.clipPath(path, op, doAA);
803 // recordRestoreOffsetPlaceholder doesn't always write an offset 1065 #else
804 if (!fRestoreOffsetStack.isEmpty()) { 1066 int pathID = this->addPathToHeap(path);
805 // + restore offset 1067 this->clipPathImpl(pathID, op, doAA);
806 size += kUInt32Size; 1068 #endif
807 }
808 size_t initialOffset = this->addDraw(CLIP_PATH, &size);
809 addPath(path);
810 addInt(ClipParams_pack(op, doAA));
811 recordRestoreOffsetPlaceholder(op);
812
813 this->validate(initialOffset, size);
814 1069
815 if (fRecordFlags & SkPicture::kUsePathBoundsForClip_RecordingFlag) { 1070 if (fRecordFlags & SkPicture::kUsePathBoundsForClip_RecordingFlag) {
816 return this->updateClipConservativelyUsingBounds(path.getBounds(), op, 1071 return this->updateClipConservativelyUsingBounds(path.getBounds(), op,
817 path.isInverseFillType( )); 1072 path.isInverseFillType( ));
818 } else { 1073 } else {
819 return this->INHERITED::clipPath(path, op, doAA); 1074 return this->INHERITED::clipPath(path, op, doAA);
820 } 1075 }
821 } 1076 }
822 1077
823 bool SkPictureRecord::clipRegion(const SkRegion& region, SkRegion::Op op) { 1078 int SkPictureRecord::clipPathImpl(int pathID, SkRegion::Op op, bool doAA) {
824 // op + clip params + region 1079
825 uint32_t size = 2 * kUInt32Size + region.writeToMemory(NULL); 1080 // op + path index + clip params
1081 uint32_t size = 3 * kUInt32Size;
1082 #ifdef COLLAPSE_MATRIX_CLIP_STATE
1083 size += kUInt32Size;
1084 #else
826 // recordRestoreOffsetPlaceholder doesn't always write an offset 1085 // recordRestoreOffsetPlaceholder doesn't always write an offset
827 if (!fRestoreOffsetStack.isEmpty()) { 1086 if (!fRestoreOffsetStack.isEmpty()) {
828 // + restore offset 1087 // + restore offset
829 size += kUInt32Size; 1088 size += kUInt32Size;
830 } 1089 }
831 size_t initialOffset = this->addDraw(CLIP_REGION, &size); 1090 #endif
832 addRegion(region); 1091 size_t initialOffset = this->addDraw(CLIP_PATH, &size);
833 addInt(ClipParams_pack(op, false)); 1092 this->addInt(pathID);
834 recordRestoreOffsetPlaceholder(op); 1093 addInt(ClipParams_pack(op, doAA));
1094 int offset = recordRestoreOffsetPlaceholder(op);
835 1095
836 this->validate(initialOffset, size); 1096 this->validate(initialOffset, size);
1097 return offset;
1098 }
1099
1100 bool SkPictureRecord::clipRegion(const SkRegion& region, SkRegion::Op op) {
1101
1102 #ifdef COLLAPSE_MATRIX_CLIP_STATE
1103 fMCMgr.clipRegion(region, op);
1104 #else
1105 this->clipRegionImpl(region, op);
1106 #endif
837 return this->INHERITED::clipRegion(region, op); 1107 return this->INHERITED::clipRegion(region, op);
838 } 1108 }
839 1109
1110 int SkPictureRecord::clipRegionImpl(const SkRegion& region, SkRegion::Op op) {
1111 // op + clip params + region
1112 uint32_t size = 2 * kUInt32Size + region.writeToMemory(NULL);
1113 #ifdef COLLAPSE_MATRIX_CLIP_STATE
1114 // + restore offset
1115 size += kUInt32Size;
1116 #else
1117 // recordRestoreOffsetPlaceholder doesn't always write an offset
1118 if (!fRestoreOffsetStack.isEmpty()) {
1119 // + restore offset
1120 size += kUInt32Size;
1121 }
1122 #endif
1123 size_t initialOffset = this->addDraw(CLIP_REGION, &size);
1124 this->addRegion(region);
1125 this->addInt(ClipParams_pack(op, false));
1126 int offset = recordRestoreOffsetPlaceholder(op);
1127
1128 this->validate(initialOffset, size);
1129 return offset;
1130 }
1131
840 void SkPictureRecord::clear(SkColor color) { 1132 void SkPictureRecord::clear(SkColor color) {
1133
1134 #ifdef COLLAPSE_MATRIX_CLIP_STATE
1135 fMCMgr.call(MatrixClipStateMgr::kOther_CallType);
1136 #endif
1137
841 // op + color 1138 // op + color
842 uint32_t size = 2 * kUInt32Size; 1139 uint32_t size = 2 * kUInt32Size;
843 size_t initialOffset = this->addDraw(DRAW_CLEAR, &size); 1140 size_t initialOffset = this->addDraw(DRAW_CLEAR, &size);
844 addInt(color); 1141 addInt(color);
845 this->validate(initialOffset, size); 1142 this->validate(initialOffset, size);
846 } 1143 }
847 1144
848 void SkPictureRecord::drawPaint(const SkPaint& paint) { 1145 void SkPictureRecord::drawPaint(const SkPaint& paint) {
1146
1147 #ifdef COLLAPSE_MATRIX_CLIP_STATE
1148 fMCMgr.call(MatrixClipStateMgr::kOther_CallType);
1149 #endif
1150
849 // op + paint index 1151 // op + paint index
850 uint32_t size = 2 * kUInt32Size; 1152 uint32_t size = 2 * kUInt32Size;
851 size_t initialOffset = this->addDraw(DRAW_PAINT, &size); 1153 size_t initialOffset = this->addDraw(DRAW_PAINT, &size);
852 SkASSERT(initialOffset+getPaintOffset(DRAW_PAINT, size) == fWriter.bytesWrit ten()); 1154 SkASSERT(initialOffset+getPaintOffset(DRAW_PAINT, size) == fWriter.bytesWrit ten());
853 addPaint(paint); 1155 addPaint(paint);
854 this->validate(initialOffset, size); 1156 this->validate(initialOffset, size);
855 } 1157 }
856 1158
857 void SkPictureRecord::drawPoints(PointMode mode, size_t count, const SkPoint pts [], 1159 void SkPictureRecord::drawPoints(PointMode mode, size_t count, const SkPoint pts [],
858 const SkPaint& paint) { 1160 const SkPaint& paint) {
1161
1162 #ifdef COLLAPSE_MATRIX_CLIP_STATE
1163 fMCMgr.call(MatrixClipStateMgr::kOther_CallType);
1164 #endif
1165
859 // op + paint index + mode + count + point data 1166 // op + paint index + mode + count + point data
860 uint32_t size = 4 * kUInt32Size + count * sizeof(SkPoint); 1167 uint32_t size = 4 * kUInt32Size + count * sizeof(SkPoint);
861 size_t initialOffset = this->addDraw(DRAW_POINTS, &size); 1168 size_t initialOffset = this->addDraw(DRAW_POINTS, &size);
862 SkASSERT(initialOffset+getPaintOffset(DRAW_POINTS, size) == fWriter.bytesWri tten()); 1169 SkASSERT(initialOffset+getPaintOffset(DRAW_POINTS, size) == fWriter.bytesWri tten());
863 addPaint(paint); 1170 addPaint(paint);
864 addInt(mode); 1171 addInt(mode);
865 addInt(count); 1172 addInt(count);
866 fWriter.writeMul4(pts, count * sizeof(SkPoint)); 1173 fWriter.writeMul4(pts, count * sizeof(SkPoint));
867 this->validate(initialOffset, size); 1174 this->validate(initialOffset, size);
868 } 1175 }
869 1176
870 void SkPictureRecord::drawOval(const SkRect& oval, const SkPaint& paint) { 1177 void SkPictureRecord::drawOval(const SkRect& oval, const SkPaint& paint) {
1178
1179 #ifdef COLLAPSE_MATRIX_CLIP_STATE
1180 fMCMgr.call(MatrixClipStateMgr::kOther_CallType);
1181 #endif
1182
871 // op + paint index + rect 1183 // op + paint index + rect
872 uint32_t size = 2 * kUInt32Size + sizeof(oval); 1184 uint32_t size = 2 * kUInt32Size + sizeof(oval);
873 size_t initialOffset = this->addDraw(DRAW_OVAL, &size); 1185 size_t initialOffset = this->addDraw(DRAW_OVAL, &size);
874 SkASSERT(initialOffset+getPaintOffset(DRAW_OVAL, size) == fWriter.bytesWritt en()); 1186 SkASSERT(initialOffset+getPaintOffset(DRAW_OVAL, size) == fWriter.bytesWritt en());
875 addPaint(paint); 1187 addPaint(paint);
876 addRect(oval); 1188 addRect(oval);
877 this->validate(initialOffset, size); 1189 this->validate(initialOffset, size);
878 } 1190 }
879 1191
880 void SkPictureRecord::drawRect(const SkRect& rect, const SkPaint& paint) { 1192 void SkPictureRecord::drawRect(const SkRect& rect, const SkPaint& paint) {
1193
1194 #ifdef COLLAPSE_MATRIX_CLIP_STATE
1195 fMCMgr.call(MatrixClipStateMgr::kOther_CallType);
1196 #endif
1197
881 // op + paint index + rect 1198 // op + paint index + rect
882 uint32_t size = 2 * kUInt32Size + sizeof(rect); 1199 uint32_t size = 2 * kUInt32Size + sizeof(rect);
883 size_t initialOffset = this->addDraw(DRAW_RECT, &size); 1200 size_t initialOffset = this->addDraw(DRAW_RECT, &size);
884 SkASSERT(initialOffset+getPaintOffset(DRAW_RECT, size) == fWriter.bytesWritt en()); 1201 SkASSERT(initialOffset+getPaintOffset(DRAW_RECT, size) == fWriter.bytesWritt en());
885 addPaint(paint); 1202 addPaint(paint);
886 addRect(rect); 1203 addRect(rect);
887 this->validate(initialOffset, size); 1204 this->validate(initialOffset, size);
888 } 1205 }
889 1206
890 void SkPictureRecord::drawRRect(const SkRRect& rrect, const SkPaint& paint) { 1207 void SkPictureRecord::drawRRect(const SkRRect& rrect, const SkPaint& paint) {
1208
1209 #ifdef COLLAPSE_MATRIX_CLIP_STATE
1210 fMCMgr.call(MatrixClipStateMgr::kOther_CallType);
1211 #endif
1212
891 if (rrect.isRect()) { 1213 if (rrect.isRect()) {
892 this->SkPictureRecord::drawRect(rrect.getBounds(), paint); 1214 this->SkPictureRecord::drawRect(rrect.getBounds(), paint);
893 } else if (rrect.isOval()) { 1215 } else if (rrect.isOval()) {
894 this->SkPictureRecord::drawOval(rrect.getBounds(), paint); 1216 this->SkPictureRecord::drawOval(rrect.getBounds(), paint);
895 } else { 1217 } else {
896 // op + paint index + rrect 1218 // op + paint index + rrect
897 uint32_t initialOffset, size; 1219 uint32_t initialOffset, size;
898 size = 2 * kUInt32Size + SkRRect::kSizeInMemory; 1220 size = 2 * kUInt32Size + SkRRect::kSizeInMemory;
899 initialOffset = this->addDraw(DRAW_RRECT, &size); 1221 initialOffset = this->addDraw(DRAW_RRECT, &size);
900 SkASSERT(initialOffset+getPaintOffset(DRAW_RRECT, size) == fWriter.bytes Written()); 1222 SkASSERT(initialOffset+getPaintOffset(DRAW_RRECT, size) == fWriter.bytes Written());
901 addPaint(paint); 1223 addPaint(paint);
902 addRRect(rrect); 1224 addRRect(rrect);
903 this->validate(initialOffset, size); 1225 this->validate(initialOffset, size);
904 } 1226 }
905 } 1227 }
906 1228
907 void SkPictureRecord::drawPath(const SkPath& path, const SkPaint& paint) { 1229 void SkPictureRecord::drawPath(const SkPath& path, const SkPaint& paint) {
1230
1231 #ifdef COLLAPSE_MATRIX_CLIP_STATE
1232 fMCMgr.call(MatrixClipStateMgr::kOther_CallType);
1233 #endif
1234
908 // op + paint index + path index 1235 // op + paint index + path index
909 uint32_t size = 3 * kUInt32Size; 1236 uint32_t size = 3 * kUInt32Size;
910 size_t initialOffset = this->addDraw(DRAW_PATH, &size); 1237 size_t initialOffset = this->addDraw(DRAW_PATH, &size);
911 SkASSERT(initialOffset+getPaintOffset(DRAW_PATH, size) == fWriter.bytesWritt en()); 1238 SkASSERT(initialOffset+getPaintOffset(DRAW_PATH, size) == fWriter.bytesWritt en());
912 addPaint(paint); 1239 this->addPaint(paint);
913 addPath(path); 1240 this->addPath(path);
914 this->validate(initialOffset, size); 1241 this->validate(initialOffset, size);
915 } 1242 }
916 1243
917 void SkPictureRecord::drawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top, 1244 void SkPictureRecord::drawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top,
918 const SkPaint* paint = NULL) { 1245 const SkPaint* paint = NULL) {
1246
1247 #ifdef COLLAPSE_MATRIX_CLIP_STATE
1248 fMCMgr.call(MatrixClipStateMgr::kOther_CallType);
1249 #endif
1250
919 // op + paint index + bitmap index + left + top 1251 // op + paint index + bitmap index + left + top
920 uint32_t size = 3 * kUInt32Size + 2 * sizeof(SkScalar); 1252 uint32_t size = 3 * kUInt32Size + 2 * sizeof(SkScalar);
921 size_t initialOffset = this->addDraw(DRAW_BITMAP, &size); 1253 size_t initialOffset = this->addDraw(DRAW_BITMAP, &size);
922 SkASSERT(initialOffset+getPaintOffset(DRAW_BITMAP, size) == fWriter.bytesWri tten()); 1254 SkASSERT(initialOffset+getPaintOffset(DRAW_BITMAP, size) == fWriter.bytesWri tten());
923 addPaintPtr(paint); 1255 addPaintPtr(paint);
924 addBitmap(bitmap); 1256 addBitmap(bitmap);
925 addScalar(left); 1257 addScalar(left);
926 addScalar(top); 1258 addScalar(top);
927 this->validate(initialOffset, size); 1259 this->validate(initialOffset, size);
928 } 1260 }
929 1261
930 void SkPictureRecord::drawBitmapRectToRect(const SkBitmap& bitmap, const SkRect* src, 1262 void SkPictureRecord::drawBitmapRectToRect(const SkBitmap& bitmap, const SkRect* src,
931 const SkRect& dst, const SkPaint* pai nt, 1263 const SkRect& dst, const SkPaint* pai nt,
932 DrawBitmapRectFlags flags) { 1264 DrawBitmapRectFlags flags) {
1265
1266 #ifdef COLLAPSE_MATRIX_CLIP_STATE
1267 fMCMgr.call(MatrixClipStateMgr::kOther_CallType);
1268 #endif
1269
933 // id + paint index + bitmap index + bool for 'src' + flags 1270 // id + paint index + bitmap index + bool for 'src' + flags
934 uint32_t size = 5 * kUInt32Size; 1271 uint32_t size = 5 * kUInt32Size;
935 if (NULL != src) { 1272 if (NULL != src) {
936 size += sizeof(*src); // + rect 1273 size += sizeof(*src); // + rect
937 } 1274 }
938 size += sizeof(dst); // + rect 1275 size += sizeof(dst); // + rect
939 1276
940 size_t initialOffset = this->addDraw(DRAW_BITMAP_RECT_TO_RECT, &size); 1277 size_t initialOffset = this->addDraw(DRAW_BITMAP_RECT_TO_RECT, &size);
941 SkASSERT(initialOffset+getPaintOffset(DRAW_BITMAP_RECT_TO_RECT, size) == fWr iter.bytesWritten()); 1278 SkASSERT(initialOffset+getPaintOffset(DRAW_BITMAP_RECT_TO_RECT, size) == fWr iter.bytesWritten());
942 addPaintPtr(paint); 1279 addPaintPtr(paint);
943 addBitmap(bitmap); 1280 addBitmap(bitmap);
944 addRectPtr(src); // may be null 1281 addRectPtr(src); // may be null
945 addRect(dst); 1282 addRect(dst);
946 addInt(flags); 1283 addInt(flags);
947 this->validate(initialOffset, size); 1284 this->validate(initialOffset, size);
948 } 1285 }
949 1286
950 void SkPictureRecord::drawBitmapMatrix(const SkBitmap& bitmap, const SkMatrix& m atrix, 1287 void SkPictureRecord::drawBitmapMatrix(const SkBitmap& bitmap, const SkMatrix& m atrix,
951 const SkPaint* paint) { 1288 const SkPaint* paint) {
1289 #ifdef COLLAPSE_MATRIX_CLIP_STATE
1290 fMCMgr.call(MatrixClipStateMgr::kOther_CallType);
1291 #endif
1292
952 // id + paint index + bitmap index + matrix 1293 // id + paint index + bitmap index + matrix
953 uint32_t size = 3 * kUInt32Size + matrix.writeToMemory(NULL); 1294 uint32_t size = 3 * kUInt32Size + matrix.writeToMemory(NULL);
1295
954 size_t initialOffset = this->addDraw(DRAW_BITMAP_MATRIX, &size); 1296 size_t initialOffset = this->addDraw(DRAW_BITMAP_MATRIX, &size);
955 SkASSERT(initialOffset+getPaintOffset(DRAW_BITMAP_MATRIX, size) == fWriter.b ytesWritten()); 1297 SkASSERT(initialOffset+getPaintOffset(DRAW_BITMAP_MATRIX, size) == fWriter.b ytesWritten());
956 addPaintPtr(paint); 1298 this->addPaintPtr(paint);
957 addBitmap(bitmap); 1299 this->addBitmap(bitmap);
958 addMatrix(matrix); 1300 this->addMatrix(matrix);
959 this->validate(initialOffset, size); 1301 this->validate(initialOffset, size);
960 } 1302 }
961 1303
962 void SkPictureRecord::drawBitmapNine(const SkBitmap& bitmap, const SkIRect& cent er, 1304 void SkPictureRecord::drawBitmapNine(const SkBitmap& bitmap, const SkIRect& cent er,
963 const SkRect& dst, const SkPaint* paint) { 1305 const SkRect& dst, const SkPaint* paint) {
1306
1307 #ifdef COLLAPSE_MATRIX_CLIP_STATE
1308 fMCMgr.call(MatrixClipStateMgr::kOther_CallType);
1309 #endif
1310
964 // op + paint index + bitmap id + center + dst rect 1311 // op + paint index + bitmap id + center + dst rect
965 uint32_t size = 3 * kUInt32Size + sizeof(center) + sizeof(dst); 1312 uint32_t size = 3 * kUInt32Size + sizeof(center) + sizeof(dst);
966 size_t initialOffset = this->addDraw(DRAW_BITMAP_NINE, &size); 1313 size_t initialOffset = this->addDraw(DRAW_BITMAP_NINE, &size);
967 SkASSERT(initialOffset+getPaintOffset(DRAW_BITMAP_NINE, size) == fWriter.byt esWritten()); 1314 SkASSERT(initialOffset+getPaintOffset(DRAW_BITMAP_NINE, size) == fWriter.byt esWritten());
968 addPaintPtr(paint); 1315 addPaintPtr(paint);
969 addBitmap(bitmap); 1316 addBitmap(bitmap);
970 addIRect(center); 1317 addIRect(center);
971 addRect(dst); 1318 addRect(dst);
972 this->validate(initialOffset, size); 1319 this->validate(initialOffset, size);
973 } 1320 }
974 1321
975 void SkPictureRecord::drawSprite(const SkBitmap& bitmap, int left, int top, 1322 void SkPictureRecord::drawSprite(const SkBitmap& bitmap, int left, int top,
976 const SkPaint* paint = NULL) { 1323 const SkPaint* paint = NULL) {
1324
1325 #ifdef COLLAPSE_MATRIX_CLIP_STATE
1326 fMCMgr.call(MatrixClipStateMgr::kOther_CallType);
1327 #endif
1328
977 // op + paint index + bitmap index + left + top 1329 // op + paint index + bitmap index + left + top
978 uint32_t size = 5 * kUInt32Size; 1330 uint32_t size = 5 * kUInt32Size;
979 size_t initialOffset = this->addDraw(DRAW_SPRITE, &size); 1331 size_t initialOffset = this->addDraw(DRAW_SPRITE, &size);
980 SkASSERT(initialOffset+getPaintOffset(DRAW_SPRITE, size) == fWriter.bytesWri tten()); 1332 SkASSERT(initialOffset+getPaintOffset(DRAW_SPRITE, size) == fWriter.bytesWri tten());
981 addPaintPtr(paint); 1333 addPaintPtr(paint);
982 addBitmap(bitmap); 1334 addBitmap(bitmap);
983 addInt(left); 1335 addInt(left);
984 addInt(top); 1336 addInt(top);
985 this->validate(initialOffset, size); 1337 this->validate(initialOffset, size);
986 } 1338 }
(...skipping 12 matching lines...) Expand all
999 1351
1000 void SkPictureRecord::addFontMetricsTopBottom(const SkPaint& paint, const SkFlat Data& flat, 1352 void SkPictureRecord::addFontMetricsTopBottom(const SkPaint& paint, const SkFlat Data& flat,
1001 SkScalar minY, SkScalar maxY) { 1353 SkScalar minY, SkScalar maxY) {
1002 WriteTopBot(paint, flat); 1354 WriteTopBot(paint, flat);
1003 addScalar(flat.topBot()[0] + minY); 1355 addScalar(flat.topBot()[0] + minY);
1004 addScalar(flat.topBot()[1] + maxY); 1356 addScalar(flat.topBot()[1] + maxY);
1005 } 1357 }
1006 1358
1007 void SkPictureRecord::drawText(const void* text, size_t byteLength, SkScalar x, 1359 void SkPictureRecord::drawText(const void* text, size_t byteLength, SkScalar x,
1008 SkScalar y, const SkPaint& paint) { 1360 SkScalar y, const SkPaint& paint) {
1361
1362 #ifdef COLLAPSE_MATRIX_CLIP_STATE
1363 fMCMgr.call(MatrixClipStateMgr::kOther_CallType);
1364 #endif
1365
1009 bool fast = !paint.isVerticalText() && paint.canComputeFastBounds(); 1366 bool fast = !paint.isVerticalText() && paint.canComputeFastBounds();
1010 1367
1011 // op + paint index + length + 'length' worth of chars + x + y 1368 // op + paint index + length + 'length' worth of chars + x + y
1012 uint32_t size = 3 * kUInt32Size + SkAlign4(byteLength) + 2 * sizeof(SkScalar ); 1369 uint32_t size = 3 * kUInt32Size + SkAlign4(byteLength) + 2 * sizeof(SkScalar );
1013 if (fast) { 1370 if (fast) {
1014 size += 2 * sizeof(SkScalar); // + top & bottom 1371 size += 2 * sizeof(SkScalar); // + top & bottom
1015 } 1372 }
1016 1373
1017 DrawType op = fast ? DRAW_TEXT_TOP_BOTTOM : DRAW_TEXT; 1374 DrawType op = fast ? DRAW_TEXT_TOP_BOTTOM : DRAW_TEXT;
1018 size_t initialOffset = this->addDraw(op, &size); 1375 size_t initialOffset = this->addDraw(op, &size);
1019 SkASSERT(initialOffset+getPaintOffset(op, size) == fWriter.bytesWritten()); 1376 SkASSERT(initialOffset+getPaintOffset(op, size) == fWriter.bytesWritten());
1020 const SkFlatData* flatPaintData = addPaint(paint); 1377 const SkFlatData* flatPaintData = addPaint(paint);
1021 SkASSERT(flatPaintData); 1378 SkASSERT(flatPaintData);
1022 addText(text, byteLength); 1379 addText(text, byteLength);
1023 addScalar(x); 1380 addScalar(x);
1024 addScalar(y); 1381 addScalar(y);
1025 if (fast) { 1382 if (fast) {
1026 addFontMetricsTopBottom(paint, *flatPaintData, y, y); 1383 addFontMetricsTopBottom(paint, *flatPaintData, y, y);
1027 } 1384 }
1028 this->validate(initialOffset, size); 1385 this->validate(initialOffset, size);
1029 } 1386 }
1030 1387
1031 void SkPictureRecord::drawPosText(const void* text, size_t byteLength, 1388 void SkPictureRecord::drawPosText(const void* text, size_t byteLength,
1032 const SkPoint pos[], const SkPaint& paint) { 1389 const SkPoint pos[], const SkPaint& paint) {
1390
1391 #ifdef COLLAPSE_MATRIX_CLIP_STATE
1392 fMCMgr.call(MatrixClipStateMgr::kOther_CallType);
1393 #endif
1394
1033 size_t points = paint.countText(text, byteLength); 1395 size_t points = paint.countText(text, byteLength);
1034 if (0 == points) 1396 if (0 == points)
1035 return; 1397 return;
1036 1398
1037 bool canUseDrawH = true; 1399 bool canUseDrawH = true;
1038 SkScalar minY = pos[0].fY; 1400 SkScalar minY = pos[0].fY;
1039 SkScalar maxY = pos[0].fY; 1401 SkScalar maxY = pos[0].fY;
1040 // check if the caller really should have used drawPosTextH() 1402 // check if the caller really should have used drawPosTextH()
1041 { 1403 {
1042 const SkScalar firstY = pos[0].fY; 1404 const SkScalar firstY = pos[0].fY;
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1109 fPointBytes += fWriter.bytesWritten() - start; 1471 fPointBytes += fWriter.bytesWritten() - start;
1110 fPointWrites += points; 1472 fPointWrites += points;
1111 #endif 1473 #endif
1112 this->validate(initialOffset, size); 1474 this->validate(initialOffset, size);
1113 } 1475 }
1114 1476
1115 void SkPictureRecord::drawPosTextH(const void* text, size_t byteLength, 1477 void SkPictureRecord::drawPosTextH(const void* text, size_t byteLength,
1116 const SkScalar xpos[], SkScalar constY, 1478 const SkScalar xpos[], SkScalar constY,
1117 const SkPaint& paint) { 1479 const SkPaint& paint) {
1118 1480
1481 #ifdef COLLAPSE_MATRIX_CLIP_STATE
1482 fMCMgr.call(MatrixClipStateMgr::kOther_CallType);
1483 #endif
1484
1119 const SkFlatData* flatPaintData = this->getFlatPaintData(paint); 1485 const SkFlatData* flatPaintData = this->getFlatPaintData(paint);
1120 drawPosTextHImpl(text, byteLength, xpos, constY, paint, flatPaintData); 1486 this->drawPosTextHImpl(text, byteLength, xpos, constY, paint, flatPaintData) ;
1121 } 1487 }
1122 1488
1123 void SkPictureRecord::drawPosTextHImpl(const void* text, size_t byteLength, 1489 void SkPictureRecord::drawPosTextHImpl(const void* text, size_t byteLength,
1124 const SkScalar xpos[], SkScalar constY, 1490 const SkScalar xpos[], SkScalar constY,
1125 const SkPaint& paint, const SkFlatData* flatPaintData) { 1491 const SkPaint& paint, const SkFlatData* flatPaintData) {
1126 size_t points = paint.countText(text, byteLength); 1492 size_t points = paint.countText(text, byteLength);
1127 if (0 == points) 1493 if (0 == points)
1128 return; 1494 return;
1129 1495
1130 bool fast = !paint.isVerticalText() && paint.canComputeFastBounds(); 1496 bool fast = !paint.isVerticalText() && paint.canComputeFastBounds();
(...skipping 24 matching lines...) Expand all
1155 #ifdef SK_DEBUG_SIZE 1521 #ifdef SK_DEBUG_SIZE
1156 fPointBytes += fWriter.bytesWritten() - start; 1522 fPointBytes += fWriter.bytesWritten() - start;
1157 fPointWrites += points; 1523 fPointWrites += points;
1158 #endif 1524 #endif
1159 this->validate(initialOffset, size); 1525 this->validate(initialOffset, size);
1160 } 1526 }
1161 1527
1162 void SkPictureRecord::drawTextOnPath(const void* text, size_t byteLength, 1528 void SkPictureRecord::drawTextOnPath(const void* text, size_t byteLength,
1163 const SkPath& path, const SkMatrix* matrix, 1529 const SkPath& path, const SkMatrix* matrix,
1164 const SkPaint& paint) { 1530 const SkPaint& paint) {
1531
1532 #ifdef COLLAPSE_MATRIX_CLIP_STATE
1533 fMCMgr.call(MatrixClipStateMgr::kOther_CallType);
1534 #endif
1535
1165 // op + paint index + length + 'length' worth of data + path index + matrix 1536 // op + paint index + length + 'length' worth of data + path index + matrix
1166 const SkMatrix& m = matrix ? *matrix : SkMatrix::I(); 1537 const SkMatrix& m = matrix ? *matrix : SkMatrix::I();
1167 uint32_t size = 3 * kUInt32Size + SkAlign4(byteLength) + kUInt32Size + m.wri teToMemory(NULL); 1538 uint32_t size = 3 * kUInt32Size + SkAlign4(byteLength) + kUInt32Size + m.wri teToMemory(NULL);
1539
1168 size_t initialOffset = this->addDraw(DRAW_TEXT_ON_PATH, &size); 1540 size_t initialOffset = this->addDraw(DRAW_TEXT_ON_PATH, &size);
1169 SkASSERT(initialOffset+getPaintOffset(DRAW_TEXT_ON_PATH, size) == fWriter.by tesWritten()); 1541 SkASSERT(initialOffset+getPaintOffset(DRAW_TEXT_ON_PATH, size) == fWriter.by tesWritten());
1170 addPaint(paint); 1542 this->addPaint(paint);
1171 addText(text, byteLength); 1543 this->addText(text, byteLength);
1172 addPath(path); 1544 this->addPath(path);
1173 addMatrix(m); 1545 this->addMatrix(m);
1174 this->validate(initialOffset, size); 1546 this->validate(initialOffset, size);
1175 } 1547 }
1176 1548
1177 void SkPictureRecord::drawPicture(SkPicture& picture) { 1549 void SkPictureRecord::drawPicture(SkPicture& picture) {
1550
1551 #ifdef COLLAPSE_MATRIX_CLIP_STATE
1552 fMCMgr.call(MatrixClipStateMgr::kOther_CallType);
1553 #endif
1554
1178 // op + picture index 1555 // op + picture index
1179 uint32_t size = 2 * kUInt32Size; 1556 uint32_t size = 2 * kUInt32Size;
1180 size_t initialOffset = this->addDraw(DRAW_PICTURE, &size); 1557 size_t initialOffset = this->addDraw(DRAW_PICTURE, &size);
1181 addPicture(picture); 1558 addPicture(picture);
1182 this->validate(initialOffset, size); 1559 this->validate(initialOffset, size);
1183 } 1560 }
1184 1561
1185 void SkPictureRecord::drawVertices(VertexMode vmode, int vertexCount, 1562 void SkPictureRecord::drawVertices(VertexMode vmode, int vertexCount,
1186 const SkPoint vertices[], const SkPoint texs[], 1563 const SkPoint vertices[], const SkPoint texs[],
1187 const SkColor colors[], SkXfermode* xfer, 1564 const SkColor colors[], SkXfermode* xfer,
1188 const uint16_t indices[], int indexCount, 1565 const uint16_t indices[], int indexCount,
1189 const SkPaint& paint) { 1566 const SkPaint& paint) {
1567
1568 #ifdef COLLAPSE_MATRIX_CLIP_STATE
1569 fMCMgr.call(MatrixClipStateMgr::kOther_CallType);
1570 #endif
1571
1190 uint32_t flags = 0; 1572 uint32_t flags = 0;
1191 if (texs) { 1573 if (texs) {
1192 flags |= DRAW_VERTICES_HAS_TEXS; 1574 flags |= DRAW_VERTICES_HAS_TEXS;
1193 } 1575 }
1194 if (colors) { 1576 if (colors) {
1195 flags |= DRAW_VERTICES_HAS_COLORS; 1577 flags |= DRAW_VERTICES_HAS_COLORS;
1196 } 1578 }
1197 if (indexCount > 0) { 1579 if (indexCount > 0) {
1198 flags |= DRAW_VERTICES_HAS_INDICES; 1580 flags |= DRAW_VERTICES_HAS_INDICES;
1199 } 1581 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1239 } 1621 }
1240 if (flags & DRAW_VERTICES_HAS_XFER) { 1622 if (flags & DRAW_VERTICES_HAS_XFER) {
1241 SkXfermode::Mode mode = SkXfermode::kModulate_Mode; 1623 SkXfermode::Mode mode = SkXfermode::kModulate_Mode;
1242 (void)xfer->asMode(&mode); 1624 (void)xfer->asMode(&mode);
1243 addInt(mode); 1625 addInt(mode);
1244 } 1626 }
1245 this->validate(initialOffset, size); 1627 this->validate(initialOffset, size);
1246 } 1628 }
1247 1629
1248 void SkPictureRecord::drawData(const void* data, size_t length) { 1630 void SkPictureRecord::drawData(const void* data, size_t length) {
1631
1632 #ifdef COLLAPSE_MATRIX_CLIP_STATE
1633 fMCMgr.call(MatrixClipStateMgr::kOther_CallType);
1634 #endif
1635
1249 // op + length + 'length' worth of data 1636 // op + length + 'length' worth of data
1250 uint32_t size = 2 * kUInt32Size + SkAlign4(length); 1637 uint32_t size = 2 * kUInt32Size + SkAlign4(length);
1251 size_t initialOffset = this->addDraw(DRAW_DATA, &size); 1638 size_t initialOffset = this->addDraw(DRAW_DATA, &size);
1252 addInt(length); 1639 addInt(length);
1253 fWriter.writePad(data, length); 1640 fWriter.writePad(data, length);
1254 this->validate(initialOffset, size); 1641 this->validate(initialOffset, size);
1255 } 1642 }
1256 1643
1257 void SkPictureRecord::beginCommentGroup(const char* description) { 1644 void SkPictureRecord::beginCommentGroup(const char* description) {
1258 // op/size + length of string + \0 terminated chars 1645 // op/size + length of string + \0 terminated chars
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1304 const SkFlatData* data = paint ? getFlatPaintData(*paint) : NULL; 1691 const SkFlatData* data = paint ? getFlatPaintData(*paint) : NULL;
1305 this->addFlatPaint(data); 1692 this->addFlatPaint(data);
1306 return data; 1693 return data;
1307 } 1694 }
1308 1695
1309 void SkPictureRecord::addFlatPaint(const SkFlatData* flatPaint) { 1696 void SkPictureRecord::addFlatPaint(const SkFlatData* flatPaint) {
1310 int index = flatPaint ? flatPaint->index() : 0; 1697 int index = flatPaint ? flatPaint->index() : 0;
1311 this->addInt(index); 1698 this->addInt(index);
1312 } 1699 }
1313 1700
1314 void SkPictureRecord::addPath(const SkPath& path) { 1701 int SkPictureRecord::addPathToHeap(const SkPath& path) {
1315 if (NULL == fPathHeap) { 1702 if (NULL == fPathHeap) {
1316 fPathHeap = SkNEW(SkPathHeap); 1703 fPathHeap = SkNEW(SkPathHeap);
1317 } 1704 }
1318 addInt(fPathHeap->append(path)); 1705 return fPathHeap->append(path);
1706 }
1707
1708 void SkPictureRecord::addPath(const SkPath& path) {
1709 this->addInt(this->addPathToHeap(path));
1319 } 1710 }
1320 1711
1321 void SkPictureRecord::addPicture(SkPicture& picture) { 1712 void SkPictureRecord::addPicture(SkPicture& picture) {
1322 int index = fPictureRefs.find(&picture); 1713 int index = fPictureRefs.find(&picture);
1323 if (index < 0) { // not found 1714 if (index < 0) { // not found
1324 index = fPictureRefs.count(); 1715 index = fPictureRefs.count();
1325 *fPictureRefs.append() = &picture; 1716 *fPictureRefs.append() = &picture;
1326 picture.ref(); 1717 picture.ref();
1327 } 1718 }
1328 // follow the convention of recording a 1-based index 1719 // follow the convention of recording a 1-based index
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
1521 void SkPictureRecord::validateRegions() const { 1912 void SkPictureRecord::validateRegions() const {
1522 int count = fRegions.count(); 1913 int count = fRegions.count();
1523 SkASSERT((unsigned) count < 0x1000); 1914 SkASSERT((unsigned) count < 0x1000);
1524 for (int index = 0; index < count; index++) { 1915 for (int index = 0; index < count; index++) {
1525 const SkFlatData* region = fRegions[index]; 1916 const SkFlatData* region = fRegions[index];
1526 SkASSERT(region); 1917 SkASSERT(region);
1527 // region->validate(); 1918 // region->validate();
1528 } 1919 }
1529 } 1920 }
1530 #endif 1921 #endif
OLDNEW
« no previous file with comments | « src/core/SkPictureRecord.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698