1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
|
/*
* Copyright 2011 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "SkPictureRecord.h"
#include "SkTSearch.h"
#include "SkPixelRef.h"
#define MIN_WRITER_SIZE 16384
#define HEAP_BLOCK_SIZE 4096
enum {
kNoInitialSave = -1,
};
SkPictureRecord::SkPictureRecord(uint32_t flags) :
fHeap(HEAP_BLOCK_SIZE),
fBitmaps(&fHeap, &fRCSet),
fMatrices(&fHeap),
fPaints(&fHeap, &fRCSet, &fTFSet),
fRegions(&fHeap),
fWriter(MIN_WRITER_SIZE),
fRecordFlags(flags) {
#ifdef SK_DEBUG_SIZE
fPointBytes = fRectBytes = fTextBytes = 0;
fPointWrites = fRectWrites = fTextWrites = 0;
#endif
fRestoreOffsetStack.setReserve(32);
fInitialSaveCount = kNoInitialSave;
fPathHeap = NULL; // lazy allocate
fFirstSavedLayerIndex = kNoSavedLayerIndex;
}
SkPictureRecord::~SkPictureRecord() {
reset();
}
///////////////////////////////////////////////////////////////////////////////
SkDevice* SkPictureRecord::setDevice(SkDevice* device) {
SkASSERT(kNoInitialSave == fInitialSaveCount);
this->INHERITED::setDevice(device);
// The bracketting save() call needs to be recorded after setting the
// device otherwise the clip stack will get messed-up
fInitialSaveCount = this->save(SkCanvas::kMatrixClip_SaveFlag);
return device;
}
int SkPictureRecord::save(SaveFlags flags) {
addDraw(SAVE);
addInt(flags);
fRestoreOffsetStack.push(0);
validate();
return this->INHERITED::save(flags);
}
int SkPictureRecord::saveLayer(const SkRect* bounds, const SkPaint* paint,
SaveFlags flags) {
addDraw(SAVE_LAYER);
addRectPtr(bounds);
addPaintPtr(paint);
addInt(flags);
fRestoreOffsetStack.push(0);
if (kNoSavedLayerIndex == fFirstSavedLayerIndex) {
fFirstSavedLayerIndex = fRestoreOffsetStack.count();
}
validate();
/* Don't actually call saveLayer, because that will try to allocate an
offscreen device (potentially very big) which we don't actually need
at this time (and may not be able to afford since during record our
clip starts out the size of the picture, which is often much larger
than the size of the actual device we'll use during playback).
*/
int count = this->INHERITED::save(flags);
this->clipRectBounds(bounds, flags, NULL);
return count;
}
bool SkPictureRecord::isDrawingToLayer() const {
return fFirstSavedLayerIndex != kNoSavedLayerIndex;
}
void SkPictureRecord::restore() {
// FIXME: SkDeferredCanvas needs to be refactored to respect
// save/restore balancing so that the following test can be
// turned on permanently.
#if 0
SkASSERT(fRestoreOffsetStack.count() > 1);
#endif
// check for underflow
if (fRestoreOffsetStack.count() == 0) {
return;
}
fillRestoreOffsetPlaceholdersForCurrentStackLevel(
(uint32_t)fWriter.size());
if (fRestoreOffsetStack.count() == fFirstSavedLayerIndex) {
fFirstSavedLayerIndex = kNoSavedLayerIndex;
}
fRestoreOffsetStack.pop();
addDraw(RESTORE);
validate();
return this->INHERITED::restore();
}
bool SkPictureRecord::translate(SkScalar dx, SkScalar dy) {
addDraw(TRANSLATE);
addScalar(dx);
addScalar(dy);
validate();
return this->INHERITED::translate(dx, dy);
}
bool SkPictureRecord::scale(SkScalar sx, SkScalar sy) {
addDraw(SCALE);
addScalar(sx);
addScalar(sy);
validate();
return this->INHERITED::scale(sx, sy);
}
bool SkPictureRecord::rotate(SkScalar degrees) {
addDraw(ROTATE);
addScalar(degrees);
validate();
return this->INHERITED::rotate(degrees);
}
bool SkPictureRecord::skew(SkScalar sx, SkScalar sy) {
addDraw(SKEW);
addScalar(sx);
addScalar(sy);
validate();
return this->INHERITED::skew(sx, sy);
}
bool SkPictureRecord::concat(const SkMatrix& matrix) {
validate();
addDraw(CONCAT);
addMatrix(matrix);
validate();
return this->INHERITED::concat(matrix);
}
void SkPictureRecord::setMatrix(const SkMatrix& matrix) {
validate();
addDraw(SET_MATRIX);
addMatrix(matrix);
validate();
this->INHERITED::setMatrix(matrix);
}
static bool regionOpExpands(SkRegion::Op op) {
switch (op) {
case SkRegion::kUnion_Op:
case SkRegion::kXOR_Op:
case SkRegion::kReverseDifference_Op:
case SkRegion::kReplace_Op:
return true;
case SkRegion::kIntersect_Op:
case SkRegion::kDifference_Op:
return false;
default:
SkDEBUGFAIL("unknown region op");
return false;
}
}
void SkPictureRecord::fillRestoreOffsetPlaceholdersForCurrentStackLevel(
uint32_t restoreOffset) {
uint32_t offset = fRestoreOffsetStack.top();
while (offset) {
uint32_t* peek = fWriter.peek32(offset);
offset = *peek;
*peek = restoreOffset;
}
}
void SkPictureRecord::endRecording() {
SkASSERT(kNoInitialSave != fInitialSaveCount);
this->restoreToCount(fInitialSaveCount);
}
void SkPictureRecord::recordRestoreOffsetPlaceholder(SkRegion::Op op) {
if (regionOpExpands(op)) {
// Run back through any previous clip ops, and mark their offset to
// be 0, disabling their ability to trigger a jump-to-restore, otherwise
// they could hide this clips ability to expand the clip (i.e. go from
// empty to non-empty).
fillRestoreOffsetPlaceholdersForCurrentStackLevel(0);
}
size_t offset = fWriter.size();
// The RestoreOffset field is initially filled with a placeholder
// value that points to the offset of the previous RestoreOffset
// in the current stack level, thus forming a linked list so that
// the restore offsets can be filled in when the corresponding
// restore command is recorded.
addInt(fRestoreOffsetStack.top());
fRestoreOffsetStack.top() = offset;
}
bool SkPictureRecord::clipRect(const SkRect& rect, SkRegion::Op op, bool doAA) {
addDraw(CLIP_RECT);
addRect(rect);
addInt(ClipParams_pack(op, doAA));
recordRestoreOffsetPlaceholder(op);
validate();
return this->INHERITED::clipRect(rect, op, doAA);
}
bool SkPictureRecord::clipPath(const SkPath& path, SkRegion::Op op, bool doAA) {
addDraw(CLIP_PATH);
addPath(path);
addInt(ClipParams_pack(op, doAA));
recordRestoreOffsetPlaceholder(op);
validate();
if (fRecordFlags & SkPicture::kUsePathBoundsForClip_RecordingFlag) {
return this->INHERITED::clipRect(path.getBounds(), op, doAA);
} else {
return this->INHERITED::clipPath(path, op, doAA);
}
}
bool SkPictureRecord::clipRegion(const SkRegion& region, SkRegion::Op op) {
addDraw(CLIP_REGION);
addRegion(region);
addInt(ClipParams_pack(op, false));
recordRestoreOffsetPlaceholder(op);
validate();
return this->INHERITED::clipRegion(region, op);
}
void SkPictureRecord::clear(SkColor color) {
addDraw(DRAW_CLEAR);
addInt(color);
validate();
}
void SkPictureRecord::drawPaint(const SkPaint& paint) {
addDraw(DRAW_PAINT);
addPaint(paint);
validate();
}
void SkPictureRecord::drawPoints(PointMode mode, size_t count, const SkPoint pts[],
const SkPaint& paint) {
addDraw(DRAW_POINTS);
addPaint(paint);
addInt(mode);
addInt(count);
fWriter.writeMul4(pts, count * sizeof(SkPoint));
validate();
}
void SkPictureRecord::drawRect(const SkRect& rect, const SkPaint& paint) {
addDraw(DRAW_RECT);
addPaint(paint);
addRect(rect);
validate();
}
void SkPictureRecord::drawPath(const SkPath& path, const SkPaint& paint) {
addDraw(DRAW_PATH);
addPaint(paint);
addPath(path);
validate();
}
void SkPictureRecord::drawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top,
const SkPaint* paint = NULL) {
addDraw(DRAW_BITMAP);
addPaintPtr(paint);
addBitmap(bitmap);
addScalar(left);
addScalar(top);
validate();
}
void SkPictureRecord::drawBitmapRect(const SkBitmap& bitmap, const SkIRect* src,
const SkRect& dst, const SkPaint* paint) {
addDraw(DRAW_BITMAP_RECT);
addPaintPtr(paint);
addBitmap(bitmap);
addIRectPtr(src); // may be null
addRect(dst);
validate();
}
void SkPictureRecord::drawBitmapMatrix(const SkBitmap& bitmap, const SkMatrix& matrix,
const SkPaint* paint) {
addDraw(DRAW_BITMAP_MATRIX);
addPaintPtr(paint);
addBitmap(bitmap);
addMatrix(matrix);
validate();
}
void SkPictureRecord::drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center,
const SkRect& dst, const SkPaint* paint) {
addDraw(DRAW_BITMAP_NINE);
addPaintPtr(paint);
addBitmap(bitmap);
addIRect(center);
addRect(dst);
validate();
}
void SkPictureRecord::drawSprite(const SkBitmap& bitmap, int left, int top,
const SkPaint* paint = NULL) {
addDraw(DRAW_SPRITE);
addPaintPtr(paint);
addBitmap(bitmap);
addInt(left);
addInt(top);
validate();
}
void SkPictureRecord::addFontMetricsTopBottom(const SkPaint& paint,
SkScalar minY, SkScalar maxY) {
SkPaint::FontMetrics metrics;
paint.getFontMetrics(&metrics);
SkRect bounds;
// construct a rect so we can see any adjustments from the paint.
// we use 0,1 for left,right, just so the rect isn't empty
bounds.set(0, metrics.fTop + minY,
SK_Scalar1, metrics.fBottom + maxY);
(void)paint.computeFastBounds(bounds, &bounds);
// now record the top and bottom
addScalar(bounds.fTop);
addScalar(bounds.fBottom);
}
void SkPictureRecord::drawText(const void* text, size_t byteLength, SkScalar x,
SkScalar y, const SkPaint& paint) {
bool fast = !paint.isVerticalText() && paint.canComputeFastBounds();
addDraw(fast ? DRAW_TEXT_TOP_BOTTOM : DRAW_TEXT);
addPaint(paint);
addText(text, byteLength);
addScalar(x);
addScalar(y);
if (fast) {
addFontMetricsTopBottom(paint, y, y);
}
validate();
}
void SkPictureRecord::drawPosText(const void* text, size_t byteLength,
const SkPoint pos[], const SkPaint& paint) {
size_t points = paint.countText(text, byteLength);
if (0 == points)
return;
bool canUseDrawH = true;
SkScalar minY = pos[0].fY;
SkScalar maxY = pos[0].fY;
// check if the caller really should have used drawPosTextH()
{
const SkScalar firstY = pos[0].fY;
for (size_t index = 1; index < points; index++) {
if (pos[index].fY != firstY) {
canUseDrawH = false;
if (pos[index].fY < minY) {
minY = pos[index].fY;
} else if (pos[index].fY > maxY) {
maxY = pos[index].fY;
}
}
}
}
bool fastBounds = !paint.isVerticalText() && paint.canComputeFastBounds();
bool fast = canUseDrawH && fastBounds;
if (fast) {
addDraw(DRAW_POS_TEXT_H_TOP_BOTTOM);
} else if (canUseDrawH) {
addDraw(DRAW_POS_TEXT_H);
} else if (fastBounds) {
addDraw(DRAW_POS_TEXT_TOP_BOTTOM);
} else {
addDraw(DRAW_POS_TEXT);
}
addPaint(paint);
addText(text, byteLength);
addInt(points);
#ifdef SK_DEBUG_SIZE
size_t start = fWriter.size();
#endif
if (canUseDrawH) {
if (fast) {
addFontMetricsTopBottom(paint, pos[0].fY, pos[0].fY);
}
addScalar(pos[0].fY);
SkScalar* xptr = (SkScalar*)fWriter.reserve(points * sizeof(SkScalar));
for (size_t index = 0; index < points; index++)
*xptr++ = pos[index].fX;
}
else {
fWriter.writeMul4(pos, points * sizeof(SkPoint));
if (fastBounds) {
addFontMetricsTopBottom(paint, minY, maxY);
}
}
#ifdef SK_DEBUG_SIZE
fPointBytes += fWriter.size() - start;
fPointWrites += points;
#endif
validate();
}
void SkPictureRecord::drawPosTextH(const void* text, size_t byteLength,
const SkScalar xpos[], SkScalar constY,
const SkPaint& paint) {
size_t points = paint.countText(text, byteLength);
if (0 == points)
return;
bool fast = !paint.isVerticalText() && paint.canComputeFastBounds();
addDraw(fast ? DRAW_POS_TEXT_H_TOP_BOTTOM : DRAW_POS_TEXT_H);
addPaint(paint);
addText(text, byteLength);
addInt(points);
#ifdef SK_DEBUG_SIZE
size_t start = fWriter.size();
#endif
if (fast) {
addFontMetricsTopBottom(paint, constY, constY);
}
addScalar(constY);
fWriter.writeMul4(xpos, points * sizeof(SkScalar));
#ifdef SK_DEBUG_SIZE
fPointBytes += fWriter.size() - start;
fPointWrites += points;
#endif
validate();
}
void SkPictureRecord::drawTextOnPath(const void* text, size_t byteLength,
const SkPath& path, const SkMatrix* matrix,
const SkPaint& paint) {
addDraw(DRAW_TEXT_ON_PATH);
addPaint(paint);
addText(text, byteLength);
addPath(path);
addMatrixPtr(matrix);
validate();
}
void SkPictureRecord::drawPicture(SkPicture& picture) {
addDraw(DRAW_PICTURE);
addPicture(picture);
validate();
}
void SkPictureRecord::drawVertices(VertexMode vmode, int vertexCount,
const SkPoint vertices[], const SkPoint texs[],
const SkColor colors[], SkXfermode*,
const uint16_t indices[], int indexCount,
const SkPaint& paint) {
uint32_t flags = 0;
if (texs) {
flags |= DRAW_VERTICES_HAS_TEXS;
}
if (colors) {
flags |= DRAW_VERTICES_HAS_COLORS;
}
if (indexCount > 0) {
flags |= DRAW_VERTICES_HAS_INDICES;
}
addDraw(DRAW_VERTICES);
addPaint(paint);
addInt(flags);
addInt(vmode);
addInt(vertexCount);
addPoints(vertices, vertexCount);
if (flags & DRAW_VERTICES_HAS_TEXS) {
addPoints(texs, vertexCount);
}
if (flags & DRAW_VERTICES_HAS_COLORS) {
fWriter.writeMul4(colors, vertexCount * sizeof(SkColor));
}
if (flags & DRAW_VERTICES_HAS_INDICES) {
addInt(indexCount);
fWriter.writePad(indices, indexCount * sizeof(uint16_t));
}
}
void SkPictureRecord::drawData(const void* data, size_t length) {
addDraw(DRAW_DATA);
addInt(length);
fWriter.writePad(data, length);
}
///////////////////////////////////////////////////////////////////////////////
void SkPictureRecord::reset() {
SkSafeUnref(fPathHeap);
fPathHeap = NULL;
fBitmaps.reset();
fBitmapIndexCache.reset();
fMatrices.reset();
fPaints.reset();
fPictureRefs.unrefAll();
fRegions.reset();
fWriter.reset();
fHeap.reset();
fRestoreOffsetStack.setCount(1);
fRestoreOffsetStack.top() = 0;
fRCSet.reset();
fTFSet.reset();
}
void SkPictureRecord::addBitmap(const SkBitmap& bitmap) {
addInt(find(bitmap));
}
void SkPictureRecord::addMatrix(const SkMatrix& matrix) {
addMatrixPtr(&matrix);
}
void SkPictureRecord::addMatrixPtr(const SkMatrix* matrix) {
this->addInt(matrix ? fMatrices.find(*matrix) : 0);
}
void SkPictureRecord::addPaint(const SkPaint& paint) {
addPaintPtr(&paint);
}
void SkPictureRecord::addPaintPtr(const SkPaint* paint) {
this->addInt(paint ? fPaints.find(*paint) : 0);
}
void SkPictureRecord::addPath(const SkPath& path) {
if (NULL == fPathHeap) {
fPathHeap = SkNEW(SkPathHeap);
}
addInt(fPathHeap->append(path));
}
void SkPictureRecord::addPicture(SkPicture& picture) {
int index = fPictureRefs.find(&picture);
if (index < 0) { // not found
index = fPictureRefs.count();
*fPictureRefs.append() = &picture;
picture.ref();
}
// follow the convention of recording a 1-based index
addInt(index + 1);
}
void SkPictureRecord::addPoint(const SkPoint& point) {
#ifdef SK_DEBUG_SIZE
size_t start = fWriter.size();
#endif
fWriter.writePoint(point);
#ifdef SK_DEBUG_SIZE
fPointBytes += fWriter.size() - start;
fPointWrites++;
#endif
}
void SkPictureRecord::addPoints(const SkPoint pts[], int count) {
fWriter.writeMul4(pts, count * sizeof(SkPoint));
#ifdef SK_DEBUG_SIZE
fPointBytes += count * sizeof(SkPoint);
fPointWrites++;
#endif
}
void SkPictureRecord::addRect(const SkRect& rect) {
#ifdef SK_DEBUG_SIZE
size_t start = fWriter.size();
#endif
fWriter.writeRect(rect);
#ifdef SK_DEBUG_SIZE
fRectBytes += fWriter.size() - start;
fRectWrites++;
#endif
}
void SkPictureRecord::addRectPtr(const SkRect* rect) {
if (fWriter.writeBool(rect != NULL)) {
fWriter.writeRect(*rect);
}
}
void SkPictureRecord::addIRect(const SkIRect& rect) {
fWriter.write(&rect, sizeof(rect));
}
void SkPictureRecord::addIRectPtr(const SkIRect* rect) {
if (fWriter.writeBool(rect != NULL)) {
*(SkIRect*)fWriter.reserve(sizeof(SkIRect)) = *rect;
}
}
void SkPictureRecord::addRegion(const SkRegion& region) {
addInt(fRegions.find(region));
}
void SkPictureRecord::addText(const void* text, size_t byteLength) {
#ifdef SK_DEBUG_SIZE
size_t start = fWriter.size();
#endif
addInt(byteLength);
fWriter.writePad(text, byteLength);
#ifdef SK_DEBUG_SIZE
fTextBytes += fWriter.size() - start;
fTextWrites++;
#endif
}
///////////////////////////////////////////////////////////////////////////////
int SkPictureRecord::find(const SkBitmap& bitmap) {
int dictionaryIndex = 0;
BitmapIndexCacheEntry entry;
const bool flattenPixels = !bitmap.isImmutable();
if (flattenPixels) {
// Flattened bitmap may be very large. First attempt a fast lookup
// based on generation ID to avoid unnecessary flattening in
// fBitmaps.find()
entry.fGenerationId = bitmap.getGenerationID();
entry.fPixelOffset = bitmap.pixelRefOffset();
entry.fWidth = bitmap.width();
entry.fHeight = bitmap.height();
dictionaryIndex =
SkTSearch<const BitmapIndexCacheEntry>(fBitmapIndexCache.begin(),
fBitmapIndexCache.count(), entry, sizeof(entry));
if (dictionaryIndex >= 0) {
return fBitmapIndexCache[dictionaryIndex].fIndex;
}
}
uint32_t writeFlags = flattenPixels ?
SkFlattenableWriteBuffer::kForceFlattenBitmapPixels_Flag : 0;
int index = fBitmaps.find(bitmap, writeFlags);
if (flattenPixels) {
entry.fIndex = index;
dictionaryIndex = ~dictionaryIndex;
*fBitmapIndexCache.insert(dictionaryIndex) = entry;
}
return index;
}
#ifdef SK_DEBUG_SIZE
size_t SkPictureRecord::size() const {
size_t result = 0;
size_t sizeData;
bitmaps(&sizeData);
result += sizeData;
matrices(&sizeData);
result += sizeData;
paints(&sizeData);
result += sizeData;
paths(&sizeData);
result += sizeData;
pictures(&sizeData);
result += sizeData;
regions(&sizeData);
result += sizeData;
result += streamlen();
return result;
}
int SkPictureRecord::bitmaps(size_t* size) const {
size_t result = 0;
int count = fBitmaps.count();
for (int index = 0; index < count; index++)
result += sizeof(fBitmaps[index]) + fBitmaps[index]->size();
*size = result;
return count;
}
int SkPictureRecord::matrices(size_t* size) const {
int count = fMatrices.count();
*size = sizeof(fMatrices[0]) * count;
return count;
}
int SkPictureRecord::paints(size_t* size) const {
size_t result = 0;
int count = fPaints.count();
for (int index = 0; index < count; index++)
result += sizeof(fPaints[index]) + fPaints[index]->size();
*size = result;
return count;
}
int SkPictureRecord::paths(size_t* size) const {
size_t result = 0;
int count = fPaths.count();
for (int index = 0; index < count; index++)
result += sizeof(fPaths[index]) + fPaths[index]->size();
*size = result;
return count;
}
int SkPictureRecord::regions(size_t* size) const {
size_t result = 0;
int count = fRegions.count();
for (int index = 0; index < count; index++)
result += sizeof(fRegions[index]) + fRegions[index]->size();
*size = result;
return count;
}
size_t SkPictureRecord::streamlen() const {
return fWriter.size();
}
#endif
#ifdef SK_DEBUG_VALIDATE
void SkPictureRecord::validate() const {
validateBitmaps();
validateMatrices();
validatePaints();
validatePaths();
validatePictures();
validateRegions();
}
void SkPictureRecord::validateBitmaps() const {
int count = fBitmaps.count();
SkASSERT((unsigned) count < 0x1000);
for (int index = 0; index < count; index++) {
const SkFlatBitmap* bitPtr = fBitmaps[index];
SkASSERT(bitPtr);
bitPtr->validate();
}
}
void SkPictureRecord::validateMatrices() const {
int count = fMatrices.count();
SkASSERT((unsigned) count < 0x1000);
for (int index = 0; index < count; index++) {
const SkFlatMatrix* matrix = fMatrices[index];
SkASSERT(matrix);
matrix->validate();
}
}
void SkPictureRecord::validatePaints() const {
int count = fPaints.count();
SkASSERT((unsigned) count < 0x1000);
for (int index = 0; index < count; index++) {
const SkFlatPaint* paint = fPaints[index];
SkASSERT(paint);
// paint->validate();
}
}
void SkPictureRecord::validatePaths() const {
int count = fPaths.count();
SkASSERT((unsigned) count < 0x1000);
for (int index = 0; index < count; index++) {
const SkFlatPath* path = fPaths[index];
SkASSERT(path);
path->validate();
}
}
void SkPictureRecord::validateRegions() const {
int count = fRegions.count();
SkASSERT((unsigned) count < 0x1000);
for (int index = 0; index < count; index++) {
const SkFlatRegion* region = fRegions[index];
SkASSERT(region);
region->validate();
}
}
#endif
|