Sat, 03 Jan 2015 20:18:00 +0100
Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.
2 /*
3 * Copyright 2011 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8 #include <new>
9 #include "SkBBoxHierarchy.h"
10 #include "SkOffsetTable.h"
11 #include "SkPicturePlayback.h"
12 #include "SkPictureRecord.h"
13 #include "SkPictureStateTree.h"
14 #include "SkReadBuffer.h"
15 #include "SkTypeface.h"
16 #include "SkTSort.h"
17 #include "SkWriteBuffer.h"
19 template <typename T> int SafeCount(const T* obj) {
20 return obj ? obj->count() : 0;
21 }
23 /* Define this to spew out a debug statement whenever we skip the remainder of
24 a save/restore block because a clip... command returned false (empty).
25 */
26 #define SPEW_CLIP_SKIPPINGx
28 SkPicturePlayback::SkPicturePlayback() {
29 this->init();
30 }
32 SkPicturePlayback::SkPicturePlayback(const SkPictureRecord& record, bool deepCopy) {
33 #ifdef SK_DEBUG_SIZE
34 size_t overallBytes, bitmapBytes, matricesBytes,
35 paintBytes, pathBytes, pictureBytes, regionBytes;
36 int bitmaps = record.bitmaps(&bitmapBytes);
37 int matrices = record.matrices(&matricesBytes);
38 int paints = record.paints(&paintBytes);
39 int paths = record.paths(&pathBytes);
40 int pictures = record.pictures(&pictureBytes);
41 int regions = record.regions(®ionBytes);
42 SkDebugf("picture record mem used %zd (stream %zd) ", record.size(),
43 record.streamlen());
44 if (bitmaps != 0)
45 SkDebugf("bitmaps size %zd (bitmaps:%d) ", bitmapBytes, bitmaps);
46 if (matrices != 0)
47 SkDebugf("matrices size %zd (matrices:%d) ", matricesBytes, matrices);
48 if (paints != 0)
49 SkDebugf("paints size %zd (paints:%d) ", paintBytes, paints);
50 if (paths != 0)
51 SkDebugf("paths size %zd (paths:%d) ", pathBytes, paths);
52 if (pictures != 0)
53 SkDebugf("pictures size %zd (pictures:%d) ", pictureBytes, pictures);
54 if (regions != 0)
55 SkDebugf("regions size %zd (regions:%d) ", regionBytes, regions);
56 if (record.fPointWrites != 0)
57 SkDebugf("points size %zd (points:%d) ", record.fPointBytes, record.fPointWrites);
58 if (record.fRectWrites != 0)
59 SkDebugf("rects size %zd (rects:%d) ", record.fRectBytes, record.fRectWrites);
60 if (record.fTextWrites != 0)
61 SkDebugf("text size %zd (text strings:%d) ", record.fTextBytes, record.fTextWrites);
63 SkDebugf("\n");
64 #endif
65 #ifdef SK_DEBUG_DUMP
66 record.dumpMatrices();
67 record.dumpPaints();
68 #endif
70 record.validate(record.writeStream().bytesWritten(), 0);
71 const SkWriter32& writer = record.writeStream();
72 init();
73 SkASSERT(!fOpData);
74 if (writer.bytesWritten() == 0) {
75 fOpData = SkData::NewEmpty();
76 return;
77 }
78 fOpData = writer.snapshotAsData();
80 fBoundingHierarchy = record.fBoundingHierarchy;
81 fStateTree = record.fStateTree;
83 SkSafeRef(fBoundingHierarchy);
84 SkSafeRef(fStateTree);
86 if (NULL != fBoundingHierarchy) {
87 fBoundingHierarchy->flushDeferredInserts();
88 }
90 // copy over the refcnt dictionary to our reader
91 record.fFlattenableHeap.setupPlaybacks();
93 fBitmaps = record.fBitmapHeap->extractBitmaps();
94 fPaints = record.fPaints.unflattenToArray();
96 fBitmapHeap.reset(SkSafeRef(record.fBitmapHeap));
97 fPathHeap.reset(SkSafeRef(record.fPathHeap));
99 fBitmapUseOffsets.reset(SkSafeRef(record.fBitmapUseOffsets.get()));
101 // ensure that the paths bounds are pre-computed
102 if (fPathHeap.get()) {
103 for (int i = 0; i < fPathHeap->count(); i++) {
104 (*fPathHeap)[i].updateBoundsCache();
105 }
106 }
108 const SkTDArray<SkPicture* >& pictures = record.getPictureRefs();
109 fPictureCount = pictures.count();
110 if (fPictureCount > 0) {
111 fPictureRefs = SkNEW_ARRAY(SkPicture*, fPictureCount);
112 for (int i = 0; i < fPictureCount; i++) {
113 if (deepCopy) {
114 fPictureRefs[i] = pictures[i]->clone();
115 } else {
116 fPictureRefs[i] = pictures[i];
117 fPictureRefs[i]->ref();
118 }
119 }
120 }
122 #ifdef SK_DEBUG_SIZE
123 int overall = fPlayback->size(&overallBytes);
124 bitmaps = fPlayback->bitmaps(&bitmapBytes);
125 paints = fPlayback->paints(&paintBytes);
126 paths = fPlayback->paths(&pathBytes);
127 pictures = fPlayback->pictures(&pictureBytes);
128 regions = fPlayback->regions(®ionBytes);
129 SkDebugf("playback size %zd (objects:%d) ", overallBytes, overall);
130 if (bitmaps != 0)
131 SkDebugf("bitmaps size %zd (bitmaps:%d) ", bitmapBytes, bitmaps);
132 if (paints != 0)
133 SkDebugf("paints size %zd (paints:%d) ", paintBytes, paints);
134 if (paths != 0)
135 SkDebugf("paths size %zd (paths:%d) ", pathBytes, paths);
136 if (pictures != 0)
137 SkDebugf("pictures size %zd (pictures:%d) ", pictureBytes, pictures);
138 if (regions != 0)
139 SkDebugf("regions size %zd (regions:%d) ", regionBytes, regions);
140 SkDebugf("\n");
141 #endif
142 }
144 static bool needs_deep_copy(const SkPaint& paint) {
145 /*
146 * These fields are known to be immutable, and so can be shallow-copied
147 *
148 * getTypeface()
149 * getAnnotation()
150 * paint.getColorFilter()
151 * getXfermode()
152 */
154 return paint.getPathEffect() ||
155 paint.getShader() ||
156 paint.getMaskFilter() ||
157 paint.getRasterizer() ||
158 paint.getLooper() ||
159 paint.getImageFilter();
160 }
162 SkPicturePlayback::SkPicturePlayback(const SkPicturePlayback& src, SkPictCopyInfo* deepCopyInfo) {
163 this->init();
165 fBitmapHeap.reset(SkSafeRef(src.fBitmapHeap.get()));
166 fPathHeap.reset(SkSafeRef(src.fPathHeap.get()));
168 fOpData = SkSafeRef(src.fOpData);
170 fBoundingHierarchy = src.fBoundingHierarchy;
171 fStateTree = src.fStateTree;
173 SkSafeRef(fBoundingHierarchy);
174 SkSafeRef(fStateTree);
176 if (deepCopyInfo) {
177 int paintCount = SafeCount(src.fPaints);
179 if (src.fBitmaps) {
180 fBitmaps = SkTRefArray<SkBitmap>::Create(src.fBitmaps->begin(), src.fBitmaps->count());
181 }
183 if (!deepCopyInfo->initialized) {
184 /* The alternative to doing this is to have a clone method on the paint and have it make
185 * the deep copy of its internal structures as needed. The holdup to doing that is at
186 * this point we would need to pass the SkBitmapHeap so that we don't unnecessarily
187 * flatten the pixels in a bitmap shader.
188 */
189 deepCopyInfo->paintData.setCount(paintCount);
191 /* Use an SkBitmapHeap to avoid flattening bitmaps in shaders. If there already is one,
192 * use it. If this SkPicturePlayback was created from a stream, fBitmapHeap will be
193 * NULL, so create a new one.
194 */
195 if (fBitmapHeap.get() == NULL) {
196 // FIXME: Put this on the stack inside SkPicture::clone. Further, is it possible to
197 // do the rest of this initialization in SkPicture::clone as well?
198 SkBitmapHeap* heap = SkNEW(SkBitmapHeap);
199 deepCopyInfo->controller.setBitmapStorage(heap);
200 heap->unref();
201 } else {
202 deepCopyInfo->controller.setBitmapStorage(fBitmapHeap);
203 }
205 SkDEBUGCODE(int heapSize = SafeCount(fBitmapHeap.get());)
206 for (int i = 0; i < paintCount; i++) {
207 if (needs_deep_copy(src.fPaints->at(i))) {
208 deepCopyInfo->paintData[i] =
209 SkFlatData::Create<SkPaint::FlatteningTraits>(&deepCopyInfo->controller,
210 src.fPaints->at(i), 0);
212 } else {
213 // this is our sentinel, which we use in the unflatten loop
214 deepCopyInfo->paintData[i] = NULL;
215 }
216 }
217 SkASSERT(SafeCount(fBitmapHeap.get()) == heapSize);
219 // needed to create typeface playback
220 deepCopyInfo->controller.setupPlaybacks();
221 deepCopyInfo->initialized = true;
222 }
224 fPaints = SkTRefArray<SkPaint>::Create(paintCount);
225 SkASSERT(deepCopyInfo->paintData.count() == paintCount);
226 SkBitmapHeap* bmHeap = deepCopyInfo->controller.getBitmapHeap();
227 SkTypefacePlayback* tfPlayback = deepCopyInfo->controller.getTypefacePlayback();
228 for (int i = 0; i < paintCount; i++) {
229 if (deepCopyInfo->paintData[i]) {
230 deepCopyInfo->paintData[i]->unflatten<SkPaint::FlatteningTraits>(
231 &fPaints->writableAt(i), bmHeap, tfPlayback);
232 } else {
233 // needs_deep_copy was false, so just need to assign
234 fPaints->writableAt(i) = src.fPaints->at(i);
235 }
236 }
238 } else {
239 fBitmaps = SkSafeRef(src.fBitmaps);
240 fPaints = SkSafeRef(src.fPaints);
241 }
243 fPictureCount = src.fPictureCount;
244 fPictureRefs = SkNEW_ARRAY(SkPicture*, fPictureCount);
245 for (int i = 0; i < fPictureCount; i++) {
246 if (deepCopyInfo) {
247 fPictureRefs[i] = src.fPictureRefs[i]->clone();
248 } else {
249 fPictureRefs[i] = src.fPictureRefs[i];
250 fPictureRefs[i]->ref();
251 }
252 }
253 }
255 void SkPicturePlayback::init() {
256 fBitmaps = NULL;
257 fPaints = NULL;
258 fPictureRefs = NULL;
259 fPictureCount = 0;
260 fOpData = NULL;
261 fFactoryPlayback = NULL;
262 fBoundingHierarchy = NULL;
263 fStateTree = NULL;
264 }
266 SkPicturePlayback::~SkPicturePlayback() {
267 SkSafeUnref(fOpData);
269 SkSafeUnref(fBitmaps);
270 SkSafeUnref(fPaints);
271 SkSafeUnref(fBoundingHierarchy);
272 SkSafeUnref(fStateTree);
274 for (int i = 0; i < fPictureCount; i++) {
275 fPictureRefs[i]->unref();
276 }
277 SkDELETE_ARRAY(fPictureRefs);
279 SkDELETE(fFactoryPlayback);
280 }
282 void SkPicturePlayback::dumpSize() const {
283 SkDebugf("--- picture size: ops=%d bitmaps=%d [%d] paints=%d [%d] paths=%d\n",
284 fOpData->size(),
285 SafeCount(fBitmaps), SafeCount(fBitmaps) * sizeof(SkBitmap),
286 SafeCount(fPaints), SafeCount(fPaints) * sizeof(SkPaint),
287 SafeCount(fPathHeap.get()));
288 }
290 bool SkPicturePlayback::containsBitmaps() const {
291 if (fBitmaps && fBitmaps->count() > 0) {
292 return true;
293 }
294 for (int i = 0; i < fPictureCount; ++i) {
295 if (fPictureRefs[i]->willPlayBackBitmaps()) {
296 return true;
297 }
298 }
299 return false;
300 }
302 ///////////////////////////////////////////////////////////////////////////////
303 ///////////////////////////////////////////////////////////////////////////////
305 #include "SkStream.h"
307 static void write_tag_size(SkWriteBuffer& buffer, uint32_t tag, uint32_t size) {
308 buffer.writeUInt(tag);
309 buffer.writeUInt(size);
310 }
312 static void write_tag_size(SkWStream* stream, uint32_t tag, uint32_t size) {
313 stream->write32(tag);
314 stream->write32(size);
315 }
317 static size_t compute_chunk_size(SkFlattenable::Factory* array, int count) {
318 size_t size = 4; // for 'count'
320 for (int i = 0; i < count; i++) {
321 const char* name = SkFlattenable::FactoryToName(array[i]);
322 if (NULL == name || 0 == *name) {
323 size += SkWStream::SizeOfPackedUInt(0);
324 } else {
325 size_t len = strlen(name);
326 size += SkWStream::SizeOfPackedUInt(len);
327 size += len;
328 }
329 }
331 return size;
332 }
334 static void write_factories(SkWStream* stream, const SkFactorySet& rec) {
335 int count = rec.count();
337 SkAutoSTMalloc<16, SkFlattenable::Factory> storage(count);
338 SkFlattenable::Factory* array = (SkFlattenable::Factory*)storage.get();
339 rec.copyToArray(array);
341 size_t size = compute_chunk_size(array, count);
343 // TODO: write_tag_size should really take a size_t
344 write_tag_size(stream, SK_PICT_FACTORY_TAG, (uint32_t) size);
345 SkDEBUGCODE(size_t start = stream->bytesWritten());
346 stream->write32(count);
348 for (int i = 0; i < count; i++) {
349 const char* name = SkFlattenable::FactoryToName(array[i]);
350 // SkDebugf("---- write factories [%d] %p <%s>\n", i, array[i], name);
351 if (NULL == name || 0 == *name) {
352 stream->writePackedUInt(0);
353 } else {
354 uint32_t len = strlen(name);
355 stream->writePackedUInt(len);
356 stream->write(name, len);
357 }
358 }
360 SkASSERT(size == (stream->bytesWritten() - start));
361 }
363 static void write_typefaces(SkWStream* stream, const SkRefCntSet& rec) {
364 int count = rec.count();
366 write_tag_size(stream, SK_PICT_TYPEFACE_TAG, count);
368 SkAutoSTMalloc<16, SkTypeface*> storage(count);
369 SkTypeface** array = (SkTypeface**)storage.get();
370 rec.copyToArray((SkRefCnt**)array);
372 for (int i = 0; i < count; i++) {
373 array[i]->serialize(stream);
374 }
375 }
377 void SkPicturePlayback::flattenToBuffer(SkWriteBuffer& buffer) const {
378 int i, n;
380 if ((n = SafeCount(fBitmaps)) > 0) {
381 write_tag_size(buffer, SK_PICT_BITMAP_BUFFER_TAG, n);
382 for (i = 0; i < n; i++) {
383 buffer.writeBitmap((*fBitmaps)[i]);
384 }
385 }
387 if ((n = SafeCount(fPaints)) > 0) {
388 write_tag_size(buffer, SK_PICT_PAINT_BUFFER_TAG, n);
389 for (i = 0; i < n; i++) {
390 buffer.writePaint((*fPaints)[i]);
391 }
392 }
394 if ((n = SafeCount(fPathHeap.get())) > 0) {
395 write_tag_size(buffer, SK_PICT_PATH_BUFFER_TAG, n);
396 fPathHeap->flatten(buffer);
397 }
398 }
400 void SkPicturePlayback::serialize(SkWStream* stream,
401 SkPicture::EncodeBitmap encoder) const {
402 write_tag_size(stream, SK_PICT_READER_TAG, fOpData->size());
403 stream->write(fOpData->bytes(), fOpData->size());
405 if (fPictureCount > 0) {
406 write_tag_size(stream, SK_PICT_PICTURE_TAG, fPictureCount);
407 for (int i = 0; i < fPictureCount; i++) {
408 fPictureRefs[i]->serialize(stream, encoder);
409 }
410 }
412 // Write some of our data into a writebuffer, and then serialize that
413 // into our stream
414 {
415 SkRefCntSet typefaceSet;
416 SkFactorySet factSet;
418 SkWriteBuffer buffer(SkWriteBuffer::kCrossProcess_Flag);
419 buffer.setTypefaceRecorder(&typefaceSet);
420 buffer.setFactoryRecorder(&factSet);
421 buffer.setBitmapEncoder(encoder);
423 this->flattenToBuffer(buffer);
425 // We have to write these two sets into the stream *before* we write
426 // the buffer, since parsing that buffer will require that we already
427 // have these sets available to use.
428 write_factories(stream, factSet);
429 write_typefaces(stream, typefaceSet);
431 write_tag_size(stream, SK_PICT_BUFFER_SIZE_TAG, buffer.bytesWritten());
432 buffer.writeToStream(stream);
433 }
435 stream->write32(SK_PICT_EOF_TAG);
436 }
438 void SkPicturePlayback::flatten(SkWriteBuffer& buffer) const {
439 write_tag_size(buffer, SK_PICT_READER_TAG, fOpData->size());
440 buffer.writeByteArray(fOpData->bytes(), fOpData->size());
442 if (fPictureCount > 0) {
443 write_tag_size(buffer, SK_PICT_PICTURE_TAG, fPictureCount);
444 for (int i = 0; i < fPictureCount; i++) {
445 fPictureRefs[i]->flatten(buffer);
446 }
447 }
449 // Write this picture playback's data into a writebuffer
450 this->flattenToBuffer(buffer);
451 buffer.write32(SK_PICT_EOF_TAG);
452 }
454 ///////////////////////////////////////////////////////////////////////////////
456 /**
457 * Return the corresponding SkReadBuffer flags, given a set of
458 * SkPictInfo flags.
459 */
460 static uint32_t pictInfoFlagsToReadBufferFlags(uint32_t pictInfoFlags) {
461 static const struct {
462 uint32_t fSrc;
463 uint32_t fDst;
464 } gSD[] = {
465 { SkPictInfo::kCrossProcess_Flag, SkReadBuffer::kCrossProcess_Flag },
466 { SkPictInfo::kScalarIsFloat_Flag, SkReadBuffer::kScalarIsFloat_Flag },
467 { SkPictInfo::kPtrIs64Bit_Flag, SkReadBuffer::kPtrIs64Bit_Flag },
468 };
470 uint32_t rbMask = 0;
471 for (size_t i = 0; i < SK_ARRAY_COUNT(gSD); ++i) {
472 if (pictInfoFlags & gSD[i].fSrc) {
473 rbMask |= gSD[i].fDst;
474 }
475 }
476 return rbMask;
477 }
479 bool SkPicturePlayback::parseStreamTag(SkStream* stream, const SkPictInfo& info, uint32_t tag,
480 size_t size, SkPicture::InstallPixelRefProc proc) {
481 /*
482 * By the time we encounter BUFFER_SIZE_TAG, we need to have already seen
483 * its dependents: FACTORY_TAG and TYPEFACE_TAG. These two are not required
484 * but if they are present, they need to have been seen before the buffer.
485 *
486 * We assert that if/when we see either of these, that we have not yet seen
487 * the buffer tag, because if we have, then its too-late to deal with the
488 * factories or typefaces.
489 */
490 SkDEBUGCODE(bool haveBuffer = false;)
492 switch (tag) {
493 case SK_PICT_READER_TAG: {
494 SkAutoMalloc storage(size);
495 if (stream->read(storage.get(), size) != size) {
496 return false;
497 }
498 SkASSERT(NULL == fOpData);
499 fOpData = SkData::NewFromMalloc(storage.detach(), size);
500 } break;
501 case SK_PICT_FACTORY_TAG: {
502 SkASSERT(!haveBuffer);
503 // Remove this code when v21 and below are no longer supported. At the
504 // same time add a new 'count' variable and use it rather then reusing 'size'.
505 #ifndef DISABLE_V21_COMPATIBILITY_CODE
506 if (info.fVersion >= 22) {
507 // in v22 this tag's size represents the size of the chunk in bytes
508 // and the number of factory strings is written out separately
509 #endif
510 size = stream->readU32();
511 #ifndef DISABLE_V21_COMPATIBILITY_CODE
512 }
513 #endif
514 fFactoryPlayback = SkNEW_ARGS(SkFactoryPlayback, (size));
515 for (size_t i = 0; i < size; i++) {
516 SkString str;
517 const size_t len = stream->readPackedUInt();
518 str.resize(len);
519 if (stream->read(str.writable_str(), len) != len) {
520 return false;
521 }
522 fFactoryPlayback->base()[i] = SkFlattenable::NameToFactory(str.c_str());
523 }
524 } break;
525 case SK_PICT_TYPEFACE_TAG: {
526 SkASSERT(!haveBuffer);
527 fTFPlayback.setCount(size);
528 for (size_t i = 0; i < size; i++) {
529 SkAutoTUnref<SkTypeface> tf(SkTypeface::Deserialize(stream));
530 if (!tf.get()) { // failed to deserialize
531 // fTFPlayback asserts it never has a null, so we plop in
532 // the default here.
533 tf.reset(SkTypeface::RefDefault());
534 }
535 fTFPlayback.set(i, tf);
536 }
537 } break;
538 case SK_PICT_PICTURE_TAG: {
539 fPictureCount = size;
540 fPictureRefs = SkNEW_ARRAY(SkPicture*, fPictureCount);
541 bool success = true;
542 int i = 0;
543 for ( ; i < fPictureCount; i++) {
544 fPictureRefs[i] = SkPicture::CreateFromStream(stream, proc);
545 if (NULL == fPictureRefs[i]) {
546 success = false;
547 break;
548 }
549 }
550 if (!success) {
551 // Delete all of the pictures that were already created (up to but excluding i):
552 for (int j = 0; j < i; j++) {
553 fPictureRefs[j]->unref();
554 }
555 // Delete the array
556 SkDELETE_ARRAY(fPictureRefs);
557 fPictureCount = 0;
558 return false;
559 }
560 } break;
561 case SK_PICT_BUFFER_SIZE_TAG: {
562 SkAutoMalloc storage(size);
563 if (stream->read(storage.get(), size) != size) {
564 return false;
565 }
567 SkReadBuffer buffer(storage.get(), size);
568 buffer.setFlags(pictInfoFlagsToReadBufferFlags(info.fFlags));
570 fFactoryPlayback->setupBuffer(buffer);
571 fTFPlayback.setupBuffer(buffer);
572 buffer.setBitmapDecoder(proc);
574 while (!buffer.eof()) {
575 tag = buffer.readUInt();
576 size = buffer.readUInt();
577 if (!this->parseBufferTag(buffer, tag, size)) {
578 return false;
579 }
580 }
581 SkDEBUGCODE(haveBuffer = true;)
582 } break;
583 }
584 return true; // success
585 }
587 bool SkPicturePlayback::parseBufferTag(SkReadBuffer& buffer,
588 uint32_t tag, size_t size) {
589 switch (tag) {
590 case SK_PICT_BITMAP_BUFFER_TAG: {
591 fBitmaps = SkTRefArray<SkBitmap>::Create(size);
592 for (size_t i = 0; i < size; ++i) {
593 SkBitmap* bm = &fBitmaps->writableAt(i);
594 buffer.readBitmap(bm);
595 bm->setImmutable();
596 }
597 } break;
598 case SK_PICT_PAINT_BUFFER_TAG: {
599 fPaints = SkTRefArray<SkPaint>::Create(size);
600 for (size_t i = 0; i < size; ++i) {
601 buffer.readPaint(&fPaints->writableAt(i));
602 }
603 } break;
604 case SK_PICT_PATH_BUFFER_TAG:
605 if (size > 0) {
606 fPathHeap.reset(SkNEW_ARGS(SkPathHeap, (buffer)));
607 }
608 break;
609 case SK_PICT_READER_TAG: {
610 SkAutoMalloc storage(size);
611 if (!buffer.readByteArray(storage.get(), size) ||
612 !buffer.validate(NULL == fOpData)) {
613 return false;
614 }
615 SkASSERT(NULL == fOpData);
616 fOpData = SkData::NewFromMalloc(storage.detach(), size);
617 } break;
618 case SK_PICT_PICTURE_TAG: {
619 if (!buffer.validate((0 == fPictureCount) && (NULL == fPictureRefs))) {
620 return false;
621 }
622 fPictureCount = size;
623 fPictureRefs = SkNEW_ARRAY(SkPicture*, fPictureCount);
624 bool success = true;
625 int i = 0;
626 for ( ; i < fPictureCount; i++) {
627 fPictureRefs[i] = SkPicture::CreateFromBuffer(buffer);
628 if (NULL == fPictureRefs[i]) {
629 success = false;
630 break;
631 }
632 }
633 if (!success) {
634 // Delete all of the pictures that were already created (up to but excluding i):
635 for (int j = 0; j < i; j++) {
636 fPictureRefs[j]->unref();
637 }
638 // Delete the array
639 SkDELETE_ARRAY(fPictureRefs);
640 fPictureCount = 0;
641 return false;
642 }
643 } break;
644 default:
645 // The tag was invalid.
646 return false;
647 }
648 return true; // success
649 }
651 SkPicturePlayback* SkPicturePlayback::CreateFromStream(SkStream* stream,
652 const SkPictInfo& info,
653 SkPicture::InstallPixelRefProc proc) {
654 SkAutoTDelete<SkPicturePlayback> playback(SkNEW(SkPicturePlayback));
656 if (!playback->parseStream(stream, info, proc)) {
657 return NULL;
658 }
659 return playback.detach();
660 }
662 SkPicturePlayback* SkPicturePlayback::CreateFromBuffer(SkReadBuffer& buffer) {
663 SkAutoTDelete<SkPicturePlayback> playback(SkNEW(SkPicturePlayback));
665 if (!playback->parseBuffer(buffer)) {
666 return NULL;
667 }
668 return playback.detach();
669 }
671 bool SkPicturePlayback::parseStream(SkStream* stream, const SkPictInfo& info,
672 SkPicture::InstallPixelRefProc proc) {
673 for (;;) {
674 uint32_t tag = stream->readU32();
675 if (SK_PICT_EOF_TAG == tag) {
676 break;
677 }
679 uint32_t size = stream->readU32();
680 if (!this->parseStreamTag(stream, info, tag, size, proc)) {
681 return false; // we're invalid
682 }
683 }
684 return true;
685 }
687 bool SkPicturePlayback::parseBuffer(SkReadBuffer& buffer) {
688 for (;;) {
689 uint32_t tag = buffer.readUInt();
690 if (SK_PICT_EOF_TAG == tag) {
691 break;
692 }
694 uint32_t size = buffer.readUInt();
695 if (!this->parseBufferTag(buffer, tag, size)) {
696 return false; // we're invalid
697 }
698 }
699 return true;
700 }
702 ///////////////////////////////////////////////////////////////////////////////
703 ///////////////////////////////////////////////////////////////////////////////
705 #ifdef SPEW_CLIP_SKIPPING
706 struct SkipClipRec {
707 int fCount;
708 size_t fSize;
710 SkipClipRec() {
711 fCount = 0;
712 fSize = 0;
713 }
715 void recordSkip(size_t bytes) {
716 fCount += 1;
717 fSize += bytes;
718 }
719 };
720 #endif
722 #ifdef SK_DEVELOPER
723 bool SkPicturePlayback::preDraw(int opIndex, int type) {
724 return false;
725 }
727 void SkPicturePlayback::postDraw(int opIndex) {
728 }
729 #endif
731 /*
732 * Read the next op code and chunk size from 'reader'. The returned size
733 * is the entire size of the chunk (including the opcode). Thus, the
734 * offset just prior to calling read_op_and_size + 'size' is the offset
735 * to the next chunk's op code. This also means that the size of a chunk
736 * with no arguments (just an opcode) will be 4.
737 */
738 static DrawType read_op_and_size(SkReader32* reader, uint32_t* size) {
739 uint32_t temp = reader->readInt();
740 uint32_t op;
741 if (((uint8_t) temp) == temp) {
742 // old skp file - no size information
743 op = temp;
744 *size = 0;
745 } else {
746 UNPACK_8_24(temp, op, *size);
747 if (MASK_24 == *size) {
748 *size = reader->readInt();
749 }
750 }
751 return (DrawType) op;
752 }
754 // The activeOps parameter is actually "const SkTDArray<SkPictureStateTree::Draw*>&".
755 // It represents the operations about to be drawn, as generated by some spatial
756 // subdivision helper class. It should already be in 'fOffset' sorted order.
757 void SkPicturePlayback::preLoadBitmaps(const SkTDArray<void*>& activeOps) {
758 if (0 == activeOps.count() || NULL == fBitmapUseOffsets) {
759 return;
760 }
762 SkTDArray<int> active;
764 SkAutoTDeleteArray<bool> needToCheck(new bool[fBitmapUseOffsets->numIDs()]);
765 for (int i = 0; i < fBitmapUseOffsets->numIDs(); ++i) {
766 needToCheck.get()[i] = true;
767 }
769 uint32_t max = ((SkPictureStateTree::Draw*)activeOps[activeOps.count()-1])->fOffset;
771 for (int i = 0; i < activeOps.count(); ++i) {
772 SkPictureStateTree::Draw* draw = (SkPictureStateTree::Draw*) activeOps[i];
774 for (int j = 0; j < fBitmapUseOffsets->numIDs(); ++j) {
775 if (!needToCheck.get()[j]) {
776 continue;
777 }
779 if (!fBitmapUseOffsets->overlap(j, draw->fOffset, max)) {
780 needToCheck.get()[j] = false;
781 continue;
782 }
784 if (!fBitmapUseOffsets->includes(j, draw->fOffset)) {
785 continue;
786 }
788 *active.append() = j;
789 needToCheck.get()[j] = false;
790 }
791 }
793 for (int i = 0; i < active.count(); ++i) {
794 SkDebugf("preload texture %d\n", active[i]);
795 }
796 }
798 void SkPicturePlayback::draw(SkCanvas& canvas, SkDrawPictureCallback* callback) {
799 #ifdef ENABLE_TIME_DRAW
800 SkAutoTime at("SkPicture::draw", 50);
801 #endif
803 #ifdef SPEW_CLIP_SKIPPING
804 SkipClipRec skipRect, skipRRect, skipRegion, skipPath, skipCull;
805 int opCount = 0;
806 #endif
808 #ifdef SK_BUILD_FOR_ANDROID
809 SkAutoMutexAcquire autoMutex(fDrawMutex);
810 #endif
812 // kDrawComplete will be the signal that we have reached the end of
813 // the command stream
814 static const uint32_t kDrawComplete = SK_MaxU32;
816 SkReader32 reader(fOpData->bytes(), fOpData->size());
817 TextContainer text;
818 SkTDArray<void*> activeOps;
820 if (NULL != fStateTree && NULL != fBoundingHierarchy) {
821 SkRect clipBounds;
822 if (canvas.getClipBounds(&clipBounds)) {
823 SkIRect query;
824 clipBounds.roundOut(&query);
825 fBoundingHierarchy->search(query, &activeOps);
826 if (activeOps.count() == 0) {
827 return;
828 }
829 SkTQSort<SkPictureStateTree::Draw>(
830 reinterpret_cast<SkPictureStateTree::Draw**>(activeOps.begin()),
831 reinterpret_cast<SkPictureStateTree::Draw**>(activeOps.end()-1));
832 }
833 }
835 SkPictureStateTree::Iterator it = (NULL == fStateTree) ?
836 SkPictureStateTree::Iterator() :
837 fStateTree->getIterator(activeOps, &canvas);
839 if (it.isValid()) {
840 uint32_t skipTo = it.draw();
841 if (kDrawComplete == skipTo) {
842 return;
843 }
844 reader.setOffset(skipTo);
845 }
847 this->preLoadBitmaps(activeOps);
849 // Record this, so we can concat w/ it if we encounter a setMatrix()
850 SkMatrix initialMatrix = canvas.getTotalMatrix();
851 int originalSaveCount = canvas.getSaveCount();
853 #ifdef SK_BUILD_FOR_ANDROID
854 fAbortCurrentPlayback = false;
855 #endif
857 #ifdef SK_DEVELOPER
858 int opIndex = -1;
859 #endif
861 while (!reader.eof()) {
862 if (callback && callback->abortDrawing()) {
863 canvas.restoreToCount(originalSaveCount);
864 return;
865 }
866 #ifdef SK_BUILD_FOR_ANDROID
867 if (fAbortCurrentPlayback) {
868 return;
869 }
870 #endif
872 #ifdef SPEW_CLIP_SKIPPING
873 opCount++;
874 #endif
876 size_t curOffset = reader.offset();
877 uint32_t size;
878 DrawType op = read_op_and_size(&reader, &size);
879 size_t skipTo = 0;
880 if (NOOP == op) {
881 // NOOPs are to be ignored - do not propagate them any further
882 skipTo = curOffset + size;
883 #ifdef SK_DEVELOPER
884 } else {
885 opIndex++;
886 if (this->preDraw(opIndex, op)) {
887 skipTo = curOffset + size;
888 }
889 #endif
890 }
892 if (0 != skipTo) {
893 if (it.isValid()) {
894 // If using a bounding box hierarchy, advance the state tree
895 // iterator until at or after skipTo
896 uint32_t adjustedSkipTo;
897 do {
898 adjustedSkipTo = it.draw();
899 } while (adjustedSkipTo < skipTo);
900 skipTo = adjustedSkipTo;
901 }
902 if (kDrawComplete == skipTo) {
903 break;
904 }
905 reader.setOffset(skipTo);
906 continue;
907 }
909 switch (op) {
910 case CLIP_PATH: {
911 const SkPath& path = getPath(reader);
912 uint32_t packed = reader.readInt();
913 SkRegion::Op regionOp = ClipParams_unpackRegionOp(packed);
914 bool doAA = ClipParams_unpackDoAA(packed);
915 size_t offsetToRestore = reader.readInt();
916 SkASSERT(!offsetToRestore || \
917 offsetToRestore >= reader.offset());
918 canvas.clipPath(path, regionOp, doAA);
919 if (canvas.isClipEmpty() && offsetToRestore) {
920 #ifdef SPEW_CLIP_SKIPPING
921 skipPath.recordSkip(offsetToRestore - reader.offset());
922 #endif
923 reader.setOffset(offsetToRestore);
924 }
925 } break;
926 case CLIP_REGION: {
927 SkRegion region;
928 this->getRegion(reader, ®ion);
929 uint32_t packed = reader.readInt();
930 SkRegion::Op regionOp = ClipParams_unpackRegionOp(packed);
931 size_t offsetToRestore = reader.readInt();
932 SkASSERT(!offsetToRestore || \
933 offsetToRestore >= reader.offset());
934 canvas.clipRegion(region, regionOp);
935 if (canvas.isClipEmpty() && offsetToRestore) {
936 #ifdef SPEW_CLIP_SKIPPING
937 skipRegion.recordSkip(offsetToRestore - reader.offset());
938 #endif
939 reader.setOffset(offsetToRestore);
940 }
941 } break;
942 case CLIP_RECT: {
943 const SkRect& rect = reader.skipT<SkRect>();
944 uint32_t packed = reader.readInt();
945 SkRegion::Op regionOp = ClipParams_unpackRegionOp(packed);
946 bool doAA = ClipParams_unpackDoAA(packed);
947 size_t offsetToRestore = reader.readInt();
948 SkASSERT(!offsetToRestore || \
949 offsetToRestore >= reader.offset());
950 canvas.clipRect(rect, regionOp, doAA);
951 if (canvas.isClipEmpty() && offsetToRestore) {
952 #ifdef SPEW_CLIP_SKIPPING
953 skipRect.recordSkip(offsetToRestore - reader.offset());
954 #endif
955 reader.setOffset(offsetToRestore);
956 }
957 } break;
958 case CLIP_RRECT: {
959 SkRRect rrect;
960 reader.readRRect(&rrect);
961 uint32_t packed = reader.readInt();
962 SkRegion::Op regionOp = ClipParams_unpackRegionOp(packed);
963 bool doAA = ClipParams_unpackDoAA(packed);
964 size_t offsetToRestore = reader.readInt();
965 SkASSERT(!offsetToRestore || \
966 offsetToRestore >= reader.offset());
967 canvas.clipRRect(rrect, regionOp, doAA);
968 if (canvas.isClipEmpty() && offsetToRestore) {
969 #ifdef SPEW_CLIP_SKIPPING
970 skipRRect.recordSkip(offsetToRestore - reader.offset());
971 #endif
972 reader.setOffset(offsetToRestore);
973 }
974 } break;
975 case PUSH_CULL: {
976 const SkRect& cullRect = reader.skipT<SkRect>();
977 size_t offsetToRestore = reader.readInt();
978 if (offsetToRestore && canvas.quickReject(cullRect)) {
979 #ifdef SPEW_CLIP_SKIPPING
980 skipCull.recordSkip(offsetToRestore - reader.offset());
981 #endif
982 reader.setOffset(offsetToRestore);
983 } else {
984 canvas.pushCull(cullRect);
985 }
986 } break;
987 case POP_CULL:
988 canvas.popCull();
989 break;
990 case CONCAT: {
991 SkMatrix matrix;
992 this->getMatrix(reader, &matrix);
993 canvas.concat(matrix);
994 break;
995 }
996 case DRAW_BITMAP: {
997 const SkPaint* paint = this->getPaint(reader);
998 const SkBitmap& bitmap = this->getBitmap(reader);
999 const SkPoint& loc = reader.skipT<SkPoint>();
1000 canvas.drawBitmap(bitmap, loc.fX, loc.fY, paint);
1001 } break;
1002 case DRAW_BITMAP_RECT_TO_RECT: {
1003 const SkPaint* paint = this->getPaint(reader);
1004 const SkBitmap& bitmap = this->getBitmap(reader);
1005 const SkRect* src = this->getRectPtr(reader); // may be null
1006 const SkRect& dst = reader.skipT<SkRect>(); // required
1007 SkCanvas::DrawBitmapRectFlags flags;
1008 flags = (SkCanvas::DrawBitmapRectFlags) reader.readInt();
1009 canvas.drawBitmapRectToRect(bitmap, src, dst, paint, flags);
1010 } break;
1011 case DRAW_BITMAP_MATRIX: {
1012 const SkPaint* paint = this->getPaint(reader);
1013 const SkBitmap& bitmap = this->getBitmap(reader);
1014 SkMatrix matrix;
1015 this->getMatrix(reader, &matrix);
1016 canvas.drawBitmapMatrix(bitmap, matrix, paint);
1017 } break;
1018 case DRAW_BITMAP_NINE: {
1019 const SkPaint* paint = this->getPaint(reader);
1020 const SkBitmap& bitmap = this->getBitmap(reader);
1021 const SkIRect& src = reader.skipT<SkIRect>();
1022 const SkRect& dst = reader.skipT<SkRect>();
1023 canvas.drawBitmapNine(bitmap, src, dst, paint);
1024 } break;
1025 case DRAW_CLEAR:
1026 canvas.clear(reader.readInt());
1027 break;
1028 case DRAW_DATA: {
1029 size_t length = reader.readInt();
1030 canvas.drawData(reader.skip(length), length);
1031 // skip handles padding the read out to a multiple of 4
1032 } break;
1033 case DRAW_DRRECT: {
1034 const SkPaint& paint = *this->getPaint(reader);
1035 SkRRect outer, inner;
1036 reader.readRRect(&outer);
1037 reader.readRRect(&inner);
1038 canvas.drawDRRect(outer, inner, paint);
1039 } break;
1040 case BEGIN_COMMENT_GROUP: {
1041 const char* desc = reader.readString();
1042 canvas.beginCommentGroup(desc);
1043 } break;
1044 case COMMENT: {
1045 const char* kywd = reader.readString();
1046 const char* value = reader.readString();
1047 canvas.addComment(kywd, value);
1048 } break;
1049 case END_COMMENT_GROUP: {
1050 canvas.endCommentGroup();
1051 } break;
1052 case DRAW_OVAL: {
1053 const SkPaint& paint = *this->getPaint(reader);
1054 canvas.drawOval(reader.skipT<SkRect>(), paint);
1055 } break;
1056 case DRAW_PAINT:
1057 canvas.drawPaint(*this->getPaint(reader));
1058 break;
1059 case DRAW_PATH: {
1060 const SkPaint& paint = *this->getPaint(reader);
1061 canvas.drawPath(getPath(reader), paint);
1062 } break;
1063 case DRAW_PICTURE:
1064 canvas.drawPicture(this->getPicture(reader));
1065 break;
1066 case DRAW_POINTS: {
1067 const SkPaint& paint = *this->getPaint(reader);
1068 SkCanvas::PointMode mode = (SkCanvas::PointMode)reader.readInt();
1069 size_t count = reader.readInt();
1070 const SkPoint* pts = (const SkPoint*)reader.skip(sizeof(SkPoint) * count);
1071 canvas.drawPoints(mode, count, pts, paint);
1072 } break;
1073 case DRAW_POS_TEXT: {
1074 const SkPaint& paint = *this->getPaint(reader);
1075 getText(reader, &text);
1076 size_t points = reader.readInt();
1077 const SkPoint* pos = (const SkPoint*)reader.skip(points * sizeof(SkPoint));
1078 canvas.drawPosText(text.text(), text.length(), pos, paint);
1079 } break;
1080 case DRAW_POS_TEXT_TOP_BOTTOM: {
1081 const SkPaint& paint = *this->getPaint(reader);
1082 getText(reader, &text);
1083 size_t points = reader.readInt();
1084 const SkPoint* pos = (const SkPoint*)reader.skip(points * sizeof(SkPoint));
1085 const SkScalar top = reader.readScalar();
1086 const SkScalar bottom = reader.readScalar();
1087 if (!canvas.quickRejectY(top, bottom)) {
1088 canvas.drawPosText(text.text(), text.length(), pos, paint);
1089 }
1090 } break;
1091 case DRAW_POS_TEXT_H: {
1092 const SkPaint& paint = *this->getPaint(reader);
1093 getText(reader, &text);
1094 size_t xCount = reader.readInt();
1095 const SkScalar constY = reader.readScalar();
1096 const SkScalar* xpos = (const SkScalar*)reader.skip(xCount * sizeof(SkScalar));
1097 canvas.drawPosTextH(text.text(), text.length(), xpos, constY,
1098 paint);
1099 } break;
1100 case DRAW_POS_TEXT_H_TOP_BOTTOM: {
1101 const SkPaint& paint = *this->getPaint(reader);
1102 getText(reader, &text);
1103 size_t xCount = reader.readInt();
1104 const SkScalar* xpos = (const SkScalar*)reader.skip((3 + xCount) * sizeof(SkScalar));
1105 const SkScalar top = *xpos++;
1106 const SkScalar bottom = *xpos++;
1107 const SkScalar constY = *xpos++;
1108 if (!canvas.quickRejectY(top, bottom)) {
1109 canvas.drawPosTextH(text.text(), text.length(), xpos,
1110 constY, paint);
1111 }
1112 } break;
1113 case DRAW_RECT: {
1114 const SkPaint& paint = *this->getPaint(reader);
1115 canvas.drawRect(reader.skipT<SkRect>(), paint);
1116 } break;
1117 case DRAW_RRECT: {
1118 const SkPaint& paint = *this->getPaint(reader);
1119 SkRRect rrect;
1120 reader.readRRect(&rrect);
1121 canvas.drawRRect(rrect, paint);
1122 } break;
1123 case DRAW_SPRITE: {
1124 const SkPaint* paint = this->getPaint(reader);
1125 const SkBitmap& bitmap = this->getBitmap(reader);
1126 int left = reader.readInt();
1127 int top = reader.readInt();
1128 canvas.drawSprite(bitmap, left, top, paint);
1129 } break;
1130 case DRAW_TEXT: {
1131 const SkPaint& paint = *this->getPaint(reader);
1132 this->getText(reader, &text);
1133 SkScalar x = reader.readScalar();
1134 SkScalar y = reader.readScalar();
1135 canvas.drawText(text.text(), text.length(), x, y, paint);
1136 } break;
1137 case DRAW_TEXT_TOP_BOTTOM: {
1138 const SkPaint& paint = *this->getPaint(reader);
1139 this->getText(reader, &text);
1140 const SkScalar* ptr = (const SkScalar*)reader.skip(4 * sizeof(SkScalar));
1141 // ptr[0] == x
1142 // ptr[1] == y
1143 // ptr[2] == top
1144 // ptr[3] == bottom
1145 if (!canvas.quickRejectY(ptr[2], ptr[3])) {
1146 canvas.drawText(text.text(), text.length(), ptr[0], ptr[1],
1147 paint);
1148 }
1149 } break;
1150 case DRAW_TEXT_ON_PATH: {
1151 const SkPaint& paint = *this->getPaint(reader);
1152 getText(reader, &text);
1153 const SkPath& path = this->getPath(reader);
1154 SkMatrix matrix;
1155 this->getMatrix(reader, &matrix);
1156 canvas.drawTextOnPath(text.text(), text.length(), path, &matrix, paint);
1157 } break;
1158 case DRAW_VERTICES: {
1159 SkAutoTUnref<SkXfermode> xfer;
1160 const SkPaint& paint = *this->getPaint(reader);
1161 DrawVertexFlags flags = (DrawVertexFlags)reader.readInt();
1162 SkCanvas::VertexMode vmode = (SkCanvas::VertexMode)reader.readInt();
1163 int vCount = reader.readInt();
1164 const SkPoint* verts = (const SkPoint*)reader.skip(
1165 vCount * sizeof(SkPoint));
1166 const SkPoint* texs = NULL;
1167 const SkColor* colors = NULL;
1168 const uint16_t* indices = NULL;
1169 int iCount = 0;
1170 if (flags & DRAW_VERTICES_HAS_TEXS) {
1171 texs = (const SkPoint*)reader.skip(
1172 vCount * sizeof(SkPoint));
1173 }
1174 if (flags & DRAW_VERTICES_HAS_COLORS) {
1175 colors = (const SkColor*)reader.skip(
1176 vCount * sizeof(SkColor));
1177 }
1178 if (flags & DRAW_VERTICES_HAS_INDICES) {
1179 iCount = reader.readInt();
1180 indices = (const uint16_t*)reader.skip(
1181 iCount * sizeof(uint16_t));
1182 }
1183 if (flags & DRAW_VERTICES_HAS_XFER) {
1184 int mode = reader.readInt();
1185 if (mode < 0 || mode > SkXfermode::kLastMode) {
1186 mode = SkXfermode::kModulate_Mode;
1187 }
1188 xfer.reset(SkXfermode::Create((SkXfermode::Mode)mode));
1189 }
1190 canvas.drawVertices(vmode, vCount, verts, texs, colors, xfer,
1191 indices, iCount, paint);
1192 } break;
1193 case RESTORE:
1194 canvas.restore();
1195 break;
1196 case ROTATE:
1197 canvas.rotate(reader.readScalar());
1198 break;
1199 case SAVE:
1200 canvas.save((SkCanvas::SaveFlags) reader.readInt());
1201 break;
1202 case SAVE_LAYER: {
1203 const SkRect* boundsPtr = this->getRectPtr(reader);
1204 const SkPaint* paint = this->getPaint(reader);
1205 canvas.saveLayer(boundsPtr, paint, (SkCanvas::SaveFlags) reader.readInt());
1206 } break;
1207 case SCALE: {
1208 SkScalar sx = reader.readScalar();
1209 SkScalar sy = reader.readScalar();
1210 canvas.scale(sx, sy);
1211 } break;
1212 case SET_MATRIX: {
1213 SkMatrix matrix;
1214 this->getMatrix(reader, &matrix);
1215 matrix.postConcat(initialMatrix);
1216 canvas.setMatrix(matrix);
1217 } break;
1218 case SKEW: {
1219 SkScalar sx = reader.readScalar();
1220 SkScalar sy = reader.readScalar();
1221 canvas.skew(sx, sy);
1222 } break;
1223 case TRANSLATE: {
1224 SkScalar dx = reader.readScalar();
1225 SkScalar dy = reader.readScalar();
1226 canvas.translate(dx, dy);
1227 } break;
1228 default:
1229 SkASSERT(0);
1230 }
1232 #ifdef SK_DEVELOPER
1233 this->postDraw(opIndex);
1234 #endif
1236 if (it.isValid()) {
1237 uint32_t skipTo = it.draw();
1238 if (kDrawComplete == skipTo) {
1239 break;
1240 }
1241 reader.setOffset(skipTo);
1242 }
1243 }
1245 #ifdef SPEW_CLIP_SKIPPING
1246 {
1247 size_t size = skipRect.fSize + skipRRect.fSize + skipPath.fSize + skipRegion.fSize +
1248 skipCull.fSize;
1249 SkDebugf("--- Clip skips %d%% rect:%d rrect:%d path:%d rgn:%d cull:%d\n",
1250 size * 100 / reader.offset(), skipRect.fCount, skipRRect.fCount,
1251 skipPath.fCount, skipRegion.fCount, skipCull.fCount);
1252 SkDebugf("--- Total ops: %d\n", opCount);
1253 }
1254 #endif
1255 // this->dumpSize();
1256 }
1258 ///////////////////////////////////////////////////////////////////////////////
1260 #ifdef SK_DEBUG_SIZE
1261 int SkPicturePlayback::size(size_t* sizePtr) {
1262 int objects = bitmaps(sizePtr);
1263 objects += paints(sizePtr);
1264 objects += paths(sizePtr);
1265 objects += pictures(sizePtr);
1266 objects += regions(sizePtr);
1267 *sizePtr = fOpData.size();
1268 return objects;
1269 }
1271 int SkPicturePlayback::bitmaps(size_t* size) {
1272 size_t result = 0;
1273 for (int index = 0; index < fBitmapCount; index++) {
1274 // const SkBitmap& bitmap = fBitmaps[index];
1275 result += sizeof(SkBitmap); // bitmap->size();
1276 }
1277 *size = result;
1278 return fBitmapCount;
1279 }
1281 int SkPicturePlayback::paints(size_t* size) {
1282 size_t result = 0;
1283 for (int index = 0; index < fPaintCount; index++) {
1284 // const SkPaint& paint = fPaints[index];
1285 result += sizeof(SkPaint); // paint->size();
1286 }
1287 *size = result;
1288 return fPaintCount;
1289 }
1291 int SkPicturePlayback::paths(size_t* size) {
1292 size_t result = 0;
1293 for (int index = 0; index < fPathCount; index++) {
1294 const SkPath& path = fPaths[index];
1295 result += path.flatten(NULL);
1296 }
1297 *size = result;
1298 return fPathCount;
1299 }
1300 #endif
1302 #ifdef SK_DEBUG_DUMP
1303 void SkPicturePlayback::dumpBitmap(const SkBitmap& bitmap) const {
1304 char pBuffer[DUMP_BUFFER_SIZE];
1305 char* bufferPtr = pBuffer;
1306 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
1307 "BitmapData bitmap%p = {", &bitmap);
1308 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
1309 "{kWidth, %d}, ", bitmap.width());
1310 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
1311 "{kHeight, %d}, ", bitmap.height());
1312 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
1313 "{kRowBytes, %d}, ", bitmap.rowBytes());
1314 // start here;
1315 SkDebugf("%s{0}};\n", pBuffer);
1316 }
1318 void dumpMatrix(const SkMatrix& matrix) const {
1319 SkMatrix defaultMatrix;
1320 defaultMatrix.reset();
1321 char pBuffer[DUMP_BUFFER_SIZE];
1322 char* bufferPtr = pBuffer;
1323 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
1324 "MatrixData matrix%p = {", &matrix);
1325 SkScalar scaleX = matrix.getScaleX();
1326 if (scaleX != defaultMatrix.getScaleX())
1327 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
1328 "{kScaleX, %g}, ", SkScalarToFloat(scaleX));
1329 SkScalar scaleY = matrix.getScaleY();
1330 if (scaleY != defaultMatrix.getScaleY())
1331 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
1332 "{kScaleY, %g}, ", SkScalarToFloat(scaleY));
1333 SkScalar skewX = matrix.getSkewX();
1334 if (skewX != defaultMatrix.getSkewX())
1335 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
1336 "{kSkewX, %g}, ", SkScalarToFloat(skewX));
1337 SkScalar skewY = matrix.getSkewY();
1338 if (skewY != defaultMatrix.getSkewY())
1339 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
1340 "{kSkewY, %g}, ", SkScalarToFloat(skewY));
1341 SkScalar translateX = matrix.getTranslateX();
1342 if (translateX != defaultMatrix.getTranslateX())
1343 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
1344 "{kTranslateX, %g}, ", SkScalarToFloat(translateX));
1345 SkScalar translateY = matrix.getTranslateY();
1346 if (translateY != defaultMatrix.getTranslateY())
1347 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
1348 "{kTranslateY, %g}, ", SkScalarToFloat(translateY));
1349 SkScalar perspX = matrix.getPerspX();
1350 if (perspX != defaultMatrix.getPerspX())
1351 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
1352 "{kPerspX, %g}, ", perspX);
1353 SkScalar perspY = matrix.getPerspY();
1354 if (perspY != defaultMatrix.getPerspY())
1355 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
1356 "{kPerspY, %g}, ", perspY);
1357 SkDebugf("%s{0}};\n", pBuffer);
1358 }
1360 void dumpPaint(const SkPaint& paint) const {
1361 SkPaint defaultPaint;
1362 char pBuffer[DUMP_BUFFER_SIZE];
1363 char* bufferPtr = pBuffer;
1364 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
1365 "PaintPointers paintPtrs%p = {", &paint);
1366 const SkTypeface* typeface = paint.getTypeface();
1367 if (typeface != defaultPaint.getTypeface())
1368 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
1369 "{kTypeface, %p}, ", typeface);
1370 const SkPathEffect* pathEffect = paint.getPathEffect();
1371 if (pathEffect != defaultPaint.getPathEffect())
1372 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
1373 "{kPathEffect, %p}, ", pathEffect);
1374 const SkShader* shader = paint.getShader();
1375 if (shader != defaultPaint.getShader())
1376 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
1377 "{kShader, %p}, ", shader);
1378 const SkXfermode* xfermode = paint.getXfermode();
1379 if (xfermode != defaultPaint.getXfermode())
1380 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
1381 "{kXfermode, %p}, ", xfermode);
1382 const SkMaskFilter* maskFilter = paint.getMaskFilter();
1383 if (maskFilter != defaultPaint.getMaskFilter())
1384 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
1385 "{kMaskFilter, %p}, ", maskFilter);
1386 const SkColorFilter* colorFilter = paint.getColorFilter();
1387 if (colorFilter != defaultPaint.getColorFilter())
1388 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
1389 "{kColorFilter, %p}, ", colorFilter);
1390 const SkRasterizer* rasterizer = paint.getRasterizer();
1391 if (rasterizer != defaultPaint.getRasterizer())
1392 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
1393 "{kRasterizer, %p}, ", rasterizer);
1394 const SkDrawLooper* drawLooper = paint.getLooper();
1395 if (drawLooper != defaultPaint.getLooper())
1396 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
1397 "{kDrawLooper, %p}, ", drawLooper);
1398 SkDebugf("%s{0}};\n", pBuffer);
1399 bufferPtr = pBuffer;
1400 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
1401 "PaintScalars paintScalars%p = {", &paint);
1402 SkScalar textSize = paint.getTextSize();
1403 if (textSize != defaultPaint.getTextSize())
1404 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
1405 "{kTextSize, %g}, ", SkScalarToFloat(textSize));
1406 SkScalar textScaleX = paint.getTextScaleX();
1407 if (textScaleX != defaultPaint.getTextScaleX())
1408 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
1409 "{kTextScaleX, %g}, ", SkScalarToFloat(textScaleX));
1410 SkScalar textSkewX = paint.getTextSkewX();
1411 if (textSkewX != defaultPaint.getTextSkewX())
1412 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
1413 "{kTextSkewX, %g}, ", SkScalarToFloat(textSkewX));
1414 SkScalar strokeWidth = paint.getStrokeWidth();
1415 if (strokeWidth != defaultPaint.getStrokeWidth())
1416 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
1417 "{kStrokeWidth, %g}, ", SkScalarToFloat(strokeWidth));
1418 SkScalar strokeMiter = paint.getStrokeMiter();
1419 if (strokeMiter != defaultPaint.getStrokeMiter())
1420 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
1421 "{kStrokeMiter, %g}, ", SkScalarToFloat(strokeMiter));
1422 SkDebugf("%s{0}};\n", pBuffer);
1423 bufferPtr = pBuffer;
1424 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
1425 "PaintInts = paintInts%p = {", &paint);
1426 unsigned color = paint.getColor();
1427 if (color != defaultPaint.getColor())
1428 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
1429 "{kColor, 0x%x}, ", color);
1430 unsigned flags = paint.getFlags();
1431 if (flags != defaultPaint.getFlags())
1432 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
1433 "{kFlags, 0x%x}, ", flags);
1434 int align = paint.getTextAlign();
1435 if (align != defaultPaint.getTextAlign())
1436 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
1437 "{kAlign, 0x%x}, ", align);
1438 int strokeCap = paint.getStrokeCap();
1439 if (strokeCap != defaultPaint.getStrokeCap())
1440 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
1441 "{kStrokeCap, 0x%x}, ", strokeCap);
1442 int strokeJoin = paint.getStrokeJoin();
1443 if (strokeJoin != defaultPaint.getStrokeJoin())
1444 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
1445 "{kAlign, 0x%x}, ", strokeJoin);
1446 int style = paint.getStyle();
1447 if (style != defaultPaint.getStyle())
1448 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
1449 "{kStyle, 0x%x}, ", style);
1450 int textEncoding = paint.getTextEncoding();
1451 if (textEncoding != defaultPaint.getTextEncoding())
1452 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
1453 "{kTextEncoding, 0x%x}, ", textEncoding);
1454 SkDebugf("%s{0}};\n", pBuffer);
1456 SkDebugf("PaintData paint%p = {paintPtrs%p, paintScalars%p, paintInts%p};\n",
1457 &paint, &paint, &paint, &paint);
1458 }
1460 void SkPicturePlayback::dumpPath(const SkPath& path) const {
1461 SkDebugf("path dump unimplemented\n");
1462 }
1464 void SkPicturePlayback::dumpPicture(const SkPicture& picture) const {
1465 SkDebugf("picture dump unimplemented\n");
1466 }
1468 void SkPicturePlayback::dumpRegion(const SkRegion& region) const {
1469 SkDebugf("region dump unimplemented\n");
1470 }
1472 int SkPicturePlayback::dumpDrawType(char* bufferPtr, char* buffer, DrawType drawType) {
1473 return snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - buffer),
1474 "k%s, ", DrawTypeToString(drawType));
1475 }
1477 int SkPicturePlayback::dumpInt(char* bufferPtr, char* buffer, char* name) {
1478 return snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - buffer),
1479 "%s:%d, ", name, getInt());
1480 }
1482 int SkPicturePlayback::dumpRect(char* bufferPtr, char* buffer, char* name) {
1483 const SkRect* rect = fReader.skipRect();
1484 return snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - buffer),
1485 "%s:{l:%g t:%g r:%g b:%g}, ", name, SkScalarToFloat(rect.fLeft),
1486 SkScalarToFloat(rect.fTop),
1487 SkScalarToFloat(rect.fRight), SkScalarToFloat(rect.fBottom));
1488 }
1490 int SkPicturePlayback::dumpPoint(char* bufferPtr, char* buffer, char* name) {
1491 SkPoint pt;
1492 getPoint(&pt);
1493 return snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - buffer),
1494 "%s:{x:%g y:%g}, ", name, SkScalarToFloat(pt.fX),
1495 SkScalarToFloat(pt.fY));
1496 }
1498 void SkPicturePlayback::dumpPointArray(char** bufferPtrPtr, char* buffer, int count) {
1499 char* bufferPtr = *bufferPtrPtr;
1500 const SkPoint* pts = (const SkPoint*)fReadStream.getAtPos();
1501 fReadStream.skip(sizeof(SkPoint) * count);
1502 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - buffer),
1503 "count:%d {", count);
1504 for (int index = 0; index < count; index++)
1505 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - buffer),
1506 "{x:%g y:%g}, ", SkScalarToFloat(pts[index].fX),
1507 SkScalarToFloat(pts[index].fY));
1508 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - buffer),
1509 "} ");
1510 *bufferPtrPtr = bufferPtr;
1511 }
1513 int SkPicturePlayback::dumpPtr(char* bufferPtr, char* buffer, char* name, void* ptr) {
1514 return snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - buffer),
1515 "%s:%p, ", name, ptr);
1516 }
1518 int SkPicturePlayback::dumpRectPtr(char* bufferPtr, char* buffer, char* name) {
1519 char result;
1520 fReadStream.read(&result, sizeof(result));
1521 if (result)
1522 return dumpRect(bufferPtr, buffer, name);
1523 else
1524 return snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - buffer),
1525 "%s:NULL, ", name);
1526 }
1528 int SkPicturePlayback::dumpScalar(char* bufferPtr, char* buffer, char* name) {
1529 return snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - buffer),
1530 "%s:%d, ", name, getScalar());
1531 }
1533 void SkPicturePlayback::dumpText(char** bufferPtrPtr, char* buffer) {
1534 char* bufferPtr = *bufferPtrPtr;
1535 int length = getInt();
1536 bufferPtr += dumpDrawType(bufferPtr, buffer);
1537 fReadStream.skipToAlign4();
1538 char* text = (char*) fReadStream.getAtPos();
1539 fReadStream.skip(length);
1540 bufferPtr += dumpInt(bufferPtr, buffer, "length");
1541 int limit = DUMP_BUFFER_SIZE - (bufferPtr - buffer) - 2;
1542 length >>= 1;
1543 if (limit > length)
1544 limit = length;
1545 if (limit > 0) {
1546 *bufferPtr++ = '"';
1547 for (int index = 0; index < limit; index++) {
1548 *bufferPtr++ = *(unsigned short*) text;
1549 text += sizeof(unsigned short);
1550 }
1551 *bufferPtr++ = '"';
1552 }
1553 *bufferPtrPtr = bufferPtr;
1554 }
1556 #define DUMP_DRAWTYPE(drawType) \
1557 bufferPtr += dumpDrawType(bufferPtr, buffer, drawType)
1559 #define DUMP_INT(name) \
1560 bufferPtr += dumpInt(bufferPtr, buffer, #name)
1562 #define DUMP_RECT_PTR(name) \
1563 bufferPtr += dumpRectPtr(bufferPtr, buffer, #name)
1565 #define DUMP_POINT(name) \
1566 bufferPtr += dumpRect(bufferPtr, buffer, #name)
1568 #define DUMP_RECT(name) \
1569 bufferPtr += dumpRect(bufferPtr, buffer, #name)
1571 #define DUMP_POINT_ARRAY(count) \
1572 dumpPointArray(&bufferPtr, buffer, count)
1574 #define DUMP_PTR(name, ptr) \
1575 bufferPtr += dumpPtr(bufferPtr, buffer, #name, (void*) ptr)
1577 #define DUMP_SCALAR(name) \
1578 bufferPtr += dumpScalar(bufferPtr, buffer, #name)
1580 #define DUMP_TEXT() \
1581 dumpText(&bufferPtr, buffer)
1583 void SkPicturePlayback::dumpStream() {
1584 SkDebugf("RecordStream stream = {\n");
1585 DrawType drawType;
1586 TextContainer text;
1587 fReadStream.rewind();
1588 char buffer[DUMP_BUFFER_SIZE], * bufferPtr;
1589 while (fReadStream.read(&drawType, sizeof(drawType))) {
1590 bufferPtr = buffer;
1591 DUMP_DRAWTYPE(drawType);
1592 switch (drawType) {
1593 case CLIP_PATH: {
1594 DUMP_PTR(SkPath, &getPath());
1595 DUMP_INT(SkRegion::Op);
1596 DUMP_INT(offsetToRestore);
1597 } break;
1598 case CLIP_REGION: {
1599 DUMP_INT(SkRegion::Op);
1600 DUMP_INT(offsetToRestore);
1601 } break;
1602 case CLIP_RECT: {
1603 DUMP_RECT(rect);
1604 DUMP_INT(SkRegion::Op);
1605 DUMP_INT(offsetToRestore);
1606 } break;
1607 case CONCAT:
1608 break;
1609 case DRAW_BITMAP: {
1610 DUMP_PTR(SkPaint, getPaint());
1611 DUMP_PTR(SkBitmap, &getBitmap());
1612 DUMP_SCALAR(left);
1613 DUMP_SCALAR(top);
1614 } break;
1615 case DRAW_PAINT:
1616 DUMP_PTR(SkPaint, getPaint());
1617 break;
1618 case DRAW_PATH: {
1619 DUMP_PTR(SkPaint, getPaint());
1620 DUMP_PTR(SkPath, &getPath());
1621 } break;
1622 case DRAW_PICTURE: {
1623 DUMP_PTR(SkPicture, &getPicture());
1624 } break;
1625 case DRAW_POINTS: {
1626 DUMP_PTR(SkPaint, getPaint());
1627 (void)getInt(); // PointMode
1628 size_t count = getInt();
1629 fReadStream.skipToAlign4();
1630 DUMP_POINT_ARRAY(count);
1631 } break;
1632 case DRAW_POS_TEXT: {
1633 DUMP_PTR(SkPaint, getPaint());
1634 DUMP_TEXT();
1635 size_t points = getInt();
1636 fReadStream.skipToAlign4();
1637 DUMP_POINT_ARRAY(points);
1638 } break;
1639 case DRAW_POS_TEXT_H: {
1640 DUMP_PTR(SkPaint, getPaint());
1641 DUMP_TEXT();
1642 size_t points = getInt();
1643 fReadStream.skipToAlign4();
1644 DUMP_SCALAR(top);
1645 DUMP_SCALAR(bottom);
1646 DUMP_SCALAR(constY);
1647 DUMP_POINT_ARRAY(points);
1648 } break;
1649 case DRAW_RECT: {
1650 DUMP_PTR(SkPaint, getPaint());
1651 DUMP_RECT(rect);
1652 } break;
1653 case DRAW_SPRITE: {
1654 DUMP_PTR(SkPaint, getPaint());
1655 DUMP_PTR(SkBitmap, &getBitmap());
1656 DUMP_SCALAR(left);
1657 DUMP_SCALAR(top);
1658 } break;
1659 case DRAW_TEXT: {
1660 DUMP_PTR(SkPaint, getPaint());
1661 DUMP_TEXT();
1662 DUMP_SCALAR(x);
1663 DUMP_SCALAR(y);
1664 } break;
1665 case DRAW_TEXT_ON_PATH: {
1666 DUMP_PTR(SkPaint, getPaint());
1667 DUMP_TEXT();
1668 DUMP_PTR(SkPath, &getPath());
1669 } break;
1670 case RESTORE:
1671 break;
1672 case ROTATE:
1673 DUMP_SCALAR(rotate);
1674 break;
1675 case SAVE:
1676 DUMP_INT(SkCanvas::SaveFlags);
1677 break;
1678 case SAVE_LAYER: {
1679 DUMP_RECT_PTR(layer);
1680 DUMP_PTR(SkPaint, getPaint());
1681 DUMP_INT(SkCanvas::SaveFlags);
1682 } break;
1683 case SCALE: {
1684 DUMP_SCALAR(sx);
1685 DUMP_SCALAR(sy);
1686 } break;
1687 case SKEW: {
1688 DUMP_SCALAR(sx);
1689 DUMP_SCALAR(sy);
1690 } break;
1691 case TRANSLATE: {
1692 DUMP_SCALAR(dx);
1693 DUMP_SCALAR(dy);
1694 } break;
1695 default:
1696 SkASSERT(0);
1697 }
1698 SkDebugf("%s\n", buffer);
1699 }
1700 }
1702 void SkPicturePlayback::dump() const {
1703 char pBuffer[DUMP_BUFFER_SIZE];
1704 char* bufferPtr = pBuffer;
1705 int index;
1706 if (fBitmapCount > 0)
1707 SkDebugf("// bitmaps (%d)\n", fBitmapCount);
1708 for (index = 0; index < fBitmapCount; index++) {
1709 const SkBitmap& bitmap = fBitmaps[index];
1710 dumpBitmap(bitmap);
1711 }
1712 if (fBitmapCount > 0)
1713 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
1714 "Bitmaps bitmaps = {");
1715 for (index = 0; index < fBitmapCount; index++)
1716 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
1717 "bitmap%p, ", &fBitmaps[index]);
1718 if (fBitmapCount > 0)
1719 SkDebugf("%s0};\n", pBuffer);
1722 if (fPaintCount > 0)
1723 SkDebugf("// paints (%d)\n", fPaintCount);
1724 for (index = 0; index < fPaintCount; index++) {
1725 const SkPaint& paint = fPaints[index];
1726 dumpPaint(paint);
1727 }
1728 bufferPtr = pBuffer;
1729 if (fPaintCount > 0)
1730 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
1731 "Paints paints = {");
1732 for (index = 0; index < fPaintCount; index++)
1733 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
1734 "paint%p, ", &fPaints[index]);
1735 if (fPaintCount > 0)
1736 SkDebugf("%s0};\n", pBuffer);
1738 for (index = 0; index < fPathCount; index++) {
1739 const SkPath& path = fPaths[index];
1740 dumpPath(path);
1741 }
1742 bufferPtr = pBuffer;
1743 if (fPathCount > 0)
1744 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
1745 "Paths paths = {");
1746 for (index = 0; index < fPathCount; index++)
1747 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
1748 "path%p, ", &fPaths[index]);
1749 if (fPathCount > 0)
1750 SkDebugf("%s0};\n", pBuffer);
1752 for (index = 0; index < fPictureCount; index++) {
1753 dumpPicture(*fPictureRefs[index]);
1754 }
1755 bufferPtr = pBuffer;
1756 if (fPictureCount > 0)
1757 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
1758 "Pictures pictures = {");
1759 for (index = 0; index < fPictureCount; index++)
1760 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
1761 "picture%p, ", fPictureRefs[index]);
1762 if (fPictureCount > 0)
1763 SkDebugf("%s0};\n", pBuffer);
1765 const_cast<SkPicturePlayback*>(this)->dumpStream();
1766 }
1768 #endif