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

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

Issue 334493002: Remove SkPicture pointer from SkPicturePlayback (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: clean up Created 6 years, 6 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
OLDNEW
1 /* 1 /*
2 * Copyright 2011 Google Inc. 2 * Copyright 2011 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 #include <new> 7 #include <new>
8 #include "SkBBoxHierarchy.h" 8 #include "SkBBoxHierarchy.h"
9 #include "SkPicturePlayback.h" 9 #include "SkPicturePlayback.h"
10 #include "SkPictureRecord.h" 10 #include "SkPictureRecord.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 SkASSERT(fReplacements[0].fStart < fReplacements[0].fStop); 43 SkASSERT(fReplacements[0].fStart < fReplacements[0].fStop);
44 44
45 for (int i = 1; i < fReplacements.count(); ++i) { 45 for (int i = 1; i < fReplacements.count(); ++i) {
46 SkASSERT(fReplacements[i].fStart < fReplacements[i].fStop); 46 SkASSERT(fReplacements[i].fStart < fReplacements[i].fStop);
47 SkASSERT(fReplacements[i-1].fStop < fReplacements[i].fStart); 47 SkASSERT(fReplacements[i-1].fStop < fReplacements[i].fStart);
48 } 48 }
49 } 49 }
50 } 50 }
51 #endif 51 #endif
52 52
53 SkPicturePlayback::SkPicturePlayback(const SkPicture* picture, const SkPictInfo& info) 53 SkPicturePlayback::SkPicturePlayback(const SkPictInfo& info)
54 : fPicture(picture) 54 : fInfo(info) {
55 , fInfo(info) {
56 this->init(); 55 this->init();
57 } 56 }
58 57
59 SkPicturePlayback::SkPicturePlayback(const SkPicture* picture, 58 void SkPicturePlayback::initForPlayback() const {
60 const SkPictureRecord& record, 59 // ensure that the paths bounds are pre-computed
60 if (NULL != fPathHeap.get()) {
61 for (int i = 0; i < fPathHeap->count(); i++) {
62 (*fPathHeap.get())[i].updateBoundsCache();
63 }
64 }
65 }
66
67 SkPicturePlayback::SkPicturePlayback(const SkPictureRecord& record,
61 const SkPictInfo& info, 68 const SkPictInfo& info,
62 bool deepCopyOps) 69 bool deepCopyOps)
63 : fPicture(picture) 70 : fInfo(info) {
64 , fInfo(info) {
65 #ifdef SK_DEBUG_SIZE 71 #ifdef SK_DEBUG_SIZE
66 size_t overallBytes, bitmapBytes, matricesBytes, 72 size_t overallBytes, bitmapBytes, matricesBytes,
67 paintBytes, pathBytes, pictureBytes, regionBytes; 73 paintBytes, pathBytes, pictureBytes, regionBytes;
68 int bitmaps = record.bitmaps(&bitmapBytes); 74 int bitmaps = record.bitmaps(&bitmapBytes);
69 int matrices = record.matrices(&matricesBytes); 75 int matrices = record.matrices(&matricesBytes);
70 int paints = record.paints(&paintBytes); 76 int paints = record.paints(&paintBytes);
71 int paths = record.paths(&pathBytes); 77 int paths = record.paths(&pathBytes);
72 int pictures = record.pictures(&pictureBytes); 78 int pictures = record.pictures(&pictureBytes);
73 int regions = record.regions(&regionBytes); 79 int regions = record.regions(&regionBytes);
74 SkDebugf("picture record mem used %zd (stream %zd) ", record.size(), 80 SkDebugf("picture record mem used %zd (stream %zd) ", record.size(),
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 fBoundingHierarchy->flushDeferredInserts(); 120 fBoundingHierarchy->flushDeferredInserts();
115 } 121 }
116 122
117 // copy over the refcnt dictionary to our reader 123 // copy over the refcnt dictionary to our reader
118 record.fFlattenableHeap.setupPlaybacks(); 124 record.fFlattenableHeap.setupPlaybacks();
119 125
120 fBitmaps = record.fBitmapHeap->extractBitmaps(); 126 fBitmaps = record.fBitmapHeap->extractBitmaps();
121 fPaints = record.fPaints.unflattenToArray(); 127 fPaints = record.fPaints.unflattenToArray();
122 128
123 fBitmapHeap.reset(SkSafeRef(record.fBitmapHeap)); 129 fBitmapHeap.reset(SkSafeRef(record.fBitmapHeap));
130 fPathHeap.reset(SkSafeRef(record.pathHeap()));
124 131
125 picture->initForPlayback(); 132 this->initForPlayback();
126 133
127 const SkTDArray<const SkPicture* >& pictures = record.getPictureRefs(); 134 const SkTDArray<const SkPicture* >& pictures = record.getPictureRefs();
128 fPictureCount = pictures.count(); 135 fPictureCount = pictures.count();
129 if (fPictureCount > 0) { 136 if (fPictureCount > 0) {
130 fPictureRefs = SkNEW_ARRAY(const SkPicture*, fPictureCount); 137 fPictureRefs = SkNEW_ARRAY(const SkPicture*, fPictureCount);
131 for (int i = 0; i < fPictureCount; i++) { 138 for (int i = 0; i < fPictureCount; i++) {
132 fPictureRefs[i] = pictures[i]; 139 fPictureRefs[i] = pictures[i];
133 fPictureRefs[i]->ref(); 140 fPictureRefs[i]->ref();
134 } 141 }
135 } 142 }
(...skipping 13 matching lines...) Expand all
149 if (paths != 0) 156 if (paths != 0)
150 SkDebugf("paths size %zd (paths:%d) ", pathBytes, paths); 157 SkDebugf("paths size %zd (paths:%d) ", pathBytes, paths);
151 if (pictures != 0) 158 if (pictures != 0)
152 SkDebugf("pictures size %zd (pictures:%d) ", pictureBytes, pictures); 159 SkDebugf("pictures size %zd (pictures:%d) ", pictureBytes, pictures);
153 if (regions != 0) 160 if (regions != 0)
154 SkDebugf("regions size %zd (regions:%d) ", regionBytes, regions); 161 SkDebugf("regions size %zd (regions:%d) ", regionBytes, regions);
155 SkDebugf("\n"); 162 SkDebugf("\n");
156 #endif 163 #endif
157 } 164 }
158 165
159 SkPicturePlayback::SkPicturePlayback(const SkPicture* picture, 166 SkPicturePlayback::SkPicturePlayback(const SkPicturePlayback& src, SkPictCopyInf o* deepCopyInfo)
160 const SkPicturePlayback& src, 167 : fInfo(src.fInfo) {
161 SkPictCopyInfo* deepCopyInfo)
162 : fPicture(picture)
163 , fInfo(src.fInfo) {
164 this->init(); 168 this->init();
165 169
166 fBitmapHeap.reset(SkSafeRef(src.fBitmapHeap.get())); 170 fBitmapHeap.reset(SkSafeRef(src.fBitmapHeap.get()));
171 fPathHeap.reset(SkSafeRef(src.fPathHeap.get()));
167 172
168 fOpData = SkSafeRef(src.fOpData); 173 fOpData = SkSafeRef(src.fOpData);
169 174
170 fBoundingHierarchy = src.fBoundingHierarchy; 175 fBoundingHierarchy = src.fBoundingHierarchy;
171 fStateTree = src.fStateTree; 176 fStateTree = src.fStateTree;
172 fContentInfo.set(src.fContentInfo); 177 fContentInfo.set(src.fContentInfo);
173 178
174 SkSafeRef(fBoundingHierarchy); 179 SkSafeRef(fBoundingHierarchy);
175 SkSafeRef(fStateTree); 180 SkSafeRef(fStateTree);
176 181
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 SkDELETE_ARRAY(fPictureRefs); 252 SkDELETE_ARRAY(fPictureRefs);
248 253
249 SkDELETE(fFactoryPlayback); 254 SkDELETE(fFactoryPlayback);
250 } 255 }
251 256
252 void SkPicturePlayback::dumpSize() const { 257 void SkPicturePlayback::dumpSize() const {
253 SkDebugf("--- picture size: ops=%d bitmaps=%d [%d] paints=%d [%d]\n", 258 SkDebugf("--- picture size: ops=%d bitmaps=%d [%d] paints=%d [%d]\n",
254 fOpData->size(), 259 fOpData->size(),
255 SafeCount(fBitmaps), SafeCount(fBitmaps) * sizeof(SkBitmap), 260 SafeCount(fBitmaps), SafeCount(fBitmaps) * sizeof(SkBitmap),
256 SafeCount(fPaints), SafeCount(fPaints) * sizeof(SkPaint)); 261 SafeCount(fPaints), SafeCount(fPaints) * sizeof(SkPaint));
257 fPicture->dumpSize(); 262 SkDebugf("--- picture size: paths=%d\n",
263 SafeCount(fPathHeap.get()));
258 } 264 }
259 265
260 bool SkPicturePlayback::containsBitmaps() const { 266 bool SkPicturePlayback::containsBitmaps() const {
261 if (fBitmaps && fBitmaps->count() > 0) { 267 if (fBitmaps && fBitmaps->count() > 0) {
262 return true; 268 return true;
263 } 269 }
264 for (int i = 0; i < fPictureCount; ++i) { 270 for (int i = 0; i < fPictureCount; ++i) {
265 if (fPictureRefs[i]->willPlayBackBitmaps()) { 271 if (fPictureRefs[i]->willPlayBackBitmaps()) {
266 return true; 272 return true;
267 } 273 }
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 } 350 }
345 } 351 }
346 352
347 if ((n = SafeCount(fPaints)) > 0) { 353 if ((n = SafeCount(fPaints)) > 0) {
348 SkPicture::WriteTagSize(buffer, SK_PICT_PAINT_BUFFER_TAG, n); 354 SkPicture::WriteTagSize(buffer, SK_PICT_PAINT_BUFFER_TAG, n);
349 for (i = 0; i < n; i++) { 355 for (i = 0; i < n; i++) {
350 buffer.writePaint((*fPaints)[i]); 356 buffer.writePaint((*fPaints)[i]);
351 } 357 }
352 } 358 }
353 359
354 fPicture->flattenToBuffer(buffer); 360 if ((n = SafeCount(fPathHeap.get())) > 0) {
361 SkPicture::WriteTagSize(buffer, SK_PICT_PATH_BUFFER_TAG, n);
362 fPathHeap->flatten(buffer);
363 }
355 } 364 }
356 365
357 void SkPicturePlayback::serialize(SkWStream* stream, 366 void SkPicturePlayback::serialize(SkWStream* stream,
358 SkPicture::EncodeBitmap encoder) const { 367 SkPicture::EncodeBitmap encoder) const {
359 SkPicture::WriteTagSize(stream, SK_PICT_READER_TAG, fOpData->size()); 368 SkPicture::WriteTagSize(stream, SK_PICT_READER_TAG, fOpData->size());
360 stream->write(fOpData->bytes(), fOpData->size()); 369 stream->write(fOpData->bytes(), fOpData->size());
361 370
362 if (fPictureCount > 0) { 371 if (fPictureCount > 0) {
363 SkPicture::WriteTagSize(stream, SK_PICT_PICTURE_TAG, fPictureCount); 372 SkPicture::WriteTagSize(stream, SK_PICT_PICTURE_TAG, fPictureCount);
364 for (int i = 0; i < fPictureCount; i++) { 373 for (int i = 0; i < fPictureCount; i++) {
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 435
427 uint32_t rbMask = 0; 436 uint32_t rbMask = 0;
428 for (size_t i = 0; i < SK_ARRAY_COUNT(gSD); ++i) { 437 for (size_t i = 0; i < SK_ARRAY_COUNT(gSD); ++i) {
429 if (pictInfoFlags & gSD[i].fSrc) { 438 if (pictInfoFlags & gSD[i].fSrc) {
430 rbMask |= gSD[i].fDst; 439 rbMask |= gSD[i].fDst;
431 } 440 }
432 } 441 }
433 return rbMask; 442 return rbMask;
434 } 443 }
435 444
436 bool SkPicturePlayback::parseStreamTag(SkPicture* picture, 445 bool SkPicturePlayback::parseStreamTag(SkStream* stream,
437 SkStream* stream,
438 uint32_t tag, 446 uint32_t tag,
439 uint32_t size, 447 uint32_t size,
440 SkPicture::InstallPixelRefProc proc) { 448 SkPicture::InstallPixelRefProc proc) {
441 /* 449 /*
442 * By the time we encounter BUFFER_SIZE_TAG, we need to have already seen 450 * By the time we encounter BUFFER_SIZE_TAG, we need to have already seen
443 * its dependents: FACTORY_TAG and TYPEFACE_TAG. These two are not required 451 * its dependents: FACTORY_TAG and TYPEFACE_TAG. These two are not required
444 * but if they are present, they need to have been seen before the buffer. 452 * but if they are present, they need to have been seen before the buffer.
445 * 453 *
446 * We assert that if/when we see either of these, that we have not yet seen 454 * We assert that if/when we see either of these, that we have not yet seen
447 * the buffer tag, because if we have, then its too-late to deal with the 455 * the buffer tag, because if we have, then its too-late to deal with the
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 buffer.setFlags(pictInfoFlagsToReadBufferFlags(fInfo.fFlags)); 537 buffer.setFlags(pictInfoFlagsToReadBufferFlags(fInfo.fFlags));
530 buffer.setVersion(fInfo.fVersion); 538 buffer.setVersion(fInfo.fVersion);
531 539
532 fFactoryPlayback->setupBuffer(buffer); 540 fFactoryPlayback->setupBuffer(buffer);
533 fTFPlayback.setupBuffer(buffer); 541 fTFPlayback.setupBuffer(buffer);
534 buffer.setBitmapDecoder(proc); 542 buffer.setBitmapDecoder(proc);
535 543
536 while (!buffer.eof()) { 544 while (!buffer.eof()) {
537 tag = buffer.readUInt(); 545 tag = buffer.readUInt();
538 size = buffer.readUInt(); 546 size = buffer.readUInt();
539 if (!this->parseBufferTag(picture, buffer, tag, size)) { 547 if (!this->parseBufferTag(buffer, tag, size)) {
540 return false; 548 return false;
541 } 549 }
542 } 550 }
543 SkDEBUGCODE(haveBuffer = true;) 551 SkDEBUGCODE(haveBuffer = true;)
544 } break; 552 } break;
545 } 553 }
546 return true; // success 554 return true; // success
547 } 555 }
548 556
549 bool SkPicturePlayback::parseBufferTag(SkPicture* picture, 557 bool SkPicturePlayback::parseBufferTag(SkReadBuffer& buffer,
550 SkReadBuffer& buffer,
551 uint32_t tag, uint32_t size) { 558 uint32_t tag, uint32_t size) {
552 switch (tag) { 559 switch (tag) {
553 case SK_PICT_BITMAP_BUFFER_TAG: { 560 case SK_PICT_BITMAP_BUFFER_TAG: {
554 const int count = SkToInt(size); 561 const int count = SkToInt(size);
555 fBitmaps = SkTRefArray<SkBitmap>::Create(size); 562 fBitmaps = SkTRefArray<SkBitmap>::Create(size);
556 for (int i = 0; i < count; ++i) { 563 for (int i = 0; i < count; ++i) {
557 SkBitmap* bm = &fBitmaps->writableAt(i); 564 SkBitmap* bm = &fBitmaps->writableAt(i);
558 buffer.readBitmap(bm); 565 buffer.readBitmap(bm);
559 bm->setImmutable(); 566 bm->setImmutable();
560 } 567 }
561 } break; 568 } break;
562 case SK_PICT_PAINT_BUFFER_TAG: { 569 case SK_PICT_PAINT_BUFFER_TAG: {
563 const int count = SkToInt(size); 570 const int count = SkToInt(size);
564 fPaints = SkTRefArray<SkPaint>::Create(size); 571 fPaints = SkTRefArray<SkPaint>::Create(size);
565 for (int i = 0; i < count; ++i) { 572 for (int i = 0; i < count; ++i) {
566 buffer.readPaint(&fPaints->writableAt(i)); 573 buffer.readPaint(&fPaints->writableAt(i));
567 } 574 }
568 } break; 575 } break;
569 case SK_PICT_PATH_BUFFER_TAG: 576 case SK_PICT_PATH_BUFFER_TAG:
570 picture->parseBufferTag(buffer, tag, size); 577 if (size > 0) {
578 fPathHeap.reset(SkNEW_ARGS(SkPathHeap, (buffer)));
579 }
571 break; 580 break;
572 case SK_PICT_READER_TAG: { 581 case SK_PICT_READER_TAG: {
573 SkAutoMalloc storage(size); 582 SkAutoMalloc storage(size);
574 if (!buffer.readByteArray(storage.get(), size) || 583 if (!buffer.readByteArray(storage.get(), size) ||
575 !buffer.validate(NULL == fOpData)) { 584 !buffer.validate(NULL == fOpData)) {
576 return false; 585 return false;
577 } 586 }
578 SkASSERT(NULL == fOpData); 587 SkASSERT(NULL == fOpData);
579 fOpData = SkData::NewFromMalloc(storage.detach(), size); 588 fOpData = SkData::NewFromMalloc(storage.detach(), size);
580 } break; 589 } break;
(...skipping 23 matching lines...) Expand all
604 return false; 613 return false;
605 } 614 }
606 } break; 615 } break;
607 default: 616 default:
608 // The tag was invalid. 617 // The tag was invalid.
609 return false; 618 return false;
610 } 619 }
611 return true; // success 620 return true; // success
612 } 621 }
613 622
614 SkPicturePlayback* SkPicturePlayback::CreateFromStream(SkPicture* picture, 623 SkPicturePlayback* SkPicturePlayback::CreateFromStream(SkStream* stream,
615 SkStream* stream,
616 const SkPictInfo& info, 624 const SkPictInfo& info,
617 SkPicture::InstallPixelRe fProc proc) { 625 SkPicture::InstallPixelRe fProc proc) {
618 SkAutoTDelete<SkPicturePlayback> playback(SkNEW_ARGS(SkPicturePlayback, (pic ture, info))); 626 SkAutoTDelete<SkPicturePlayback> playback(SkNEW_ARGS(SkPicturePlayback, (inf o)));
619 627
620 if (!playback->parseStream(picture, stream, proc)) { 628 if (!playback->parseStream(stream, proc)) {
621 return NULL; 629 return NULL;
622 } 630 }
623 return playback.detach(); 631 return playback.detach();
624 } 632 }
625 633
626 SkPicturePlayback* SkPicturePlayback::CreateFromBuffer(SkPicture* picture, 634 SkPicturePlayback* SkPicturePlayback::CreateFromBuffer(SkReadBuffer& buffer,
627 SkReadBuffer& buffer,
628 const SkPictInfo& info) { 635 const SkPictInfo& info) {
629 SkAutoTDelete<SkPicturePlayback> playback(SkNEW_ARGS(SkPicturePlayback, (pic ture, info))); 636 SkAutoTDelete<SkPicturePlayback> playback(SkNEW_ARGS(SkPicturePlayback, (inf o)));
630 buffer.setVersion(info.fVersion); 637 buffer.setVersion(info.fVersion);
631 638
632 if (!playback->parseBuffer(picture, buffer)) { 639 if (!playback->parseBuffer(buffer)) {
633 return NULL; 640 return NULL;
634 } 641 }
635 return playback.detach(); 642 return playback.detach();
636 } 643 }
637 644
638 bool SkPicturePlayback::parseStream(SkPicture* picture, 645 bool SkPicturePlayback::parseStream(SkStream* stream,
639 SkStream* stream,
640 SkPicture::InstallPixelRefProc proc) { 646 SkPicture::InstallPixelRefProc proc) {
641 for (;;) { 647 for (;;) {
642 uint32_t tag = stream->readU32(); 648 uint32_t tag = stream->readU32();
643 if (SK_PICT_EOF_TAG == tag) { 649 if (SK_PICT_EOF_TAG == tag) {
644 break; 650 break;
645 } 651 }
646 652
647 uint32_t size = stream->readU32(); 653 uint32_t size = stream->readU32();
648 if (!this->parseStreamTag(picture, stream, tag, size, proc)) { 654 if (!this->parseStreamTag(stream, tag, size, proc)) {
649 return false; // we're invalid 655 return false; // we're invalid
650 } 656 }
651 } 657 }
652 return true; 658 return true;
653 } 659 }
654 660
655 bool SkPicturePlayback::parseBuffer(SkPicture* picture, SkReadBuffer& buffer) { 661 bool SkPicturePlayback::parseBuffer(SkReadBuffer& buffer) {
656 for (;;) { 662 for (;;) {
657 uint32_t tag = buffer.readUInt(); 663 uint32_t tag = buffer.readUInt();
658 if (SK_PICT_EOF_TAG == tag) { 664 if (SK_PICT_EOF_TAG == tag) {
659 break; 665 break;
660 } 666 }
661 667
662 uint32_t size = buffer.readUInt(); 668 uint32_t size = buffer.readUInt();
663 if (!this->parseBufferTag(picture, buffer, tag, size)) { 669 if (!this->parseBufferTag(buffer, tag, size)) {
664 return false; // we're invalid 670 return false; // we're invalid
665 } 671 }
666 } 672 }
667 return true; 673 return true;
668 } 674 }
669 675
670 /////////////////////////////////////////////////////////////////////////////// 676 ///////////////////////////////////////////////////////////////////////////////
671 /////////////////////////////////////////////////////////////////////////////// 677 ///////////////////////////////////////////////////////////////////////////////
672 678
673 #ifdef SPEW_CLIP_SKIPPING 679 #ifdef SPEW_CLIP_SKIPPING
(...skipping 1181 matching lines...) Expand 10 before | Expand all | Expand 10 after
1855 for (index = 0; index < fPictureCount; index++) 1861 for (index = 0; index < fPictureCount; index++)
1856 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer ), 1862 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer ),
1857 "picture%p, ", fPictureRefs[index]); 1863 "picture%p, ", fPictureRefs[index]);
1858 if (fPictureCount > 0) 1864 if (fPictureCount > 0)
1859 SkDebugf("%s0};\n", pBuffer); 1865 SkDebugf("%s0};\n", pBuffer);
1860 1866
1861 const_cast<SkPicturePlayback*>(this)->dumpStream(); 1867 const_cast<SkPicturePlayback*>(this)->dumpStream();
1862 } 1868 }
1863 1869
1864 #endif 1870 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698