Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 #include "SkPicturePlayback.h" | 8 #include "SkPicturePlayback.h" |
| 9 #include "SkPictureRecord.h" | 9 #include "SkPictureRecord.h" |
| 10 #include "SkTypeface.h" | 10 #include "SkTypeface.h" |
| (...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 466 | 466 |
| 467 uint32_t rbMask = 0; | 467 uint32_t rbMask = 0; |
| 468 for (size_t i = 0; i < SK_ARRAY_COUNT(gSD); ++i) { | 468 for (size_t i = 0; i < SK_ARRAY_COUNT(gSD); ++i) { |
| 469 if (pictInfoFlags & gSD[i].fSrc) { | 469 if (pictInfoFlags & gSD[i].fSrc) { |
| 470 rbMask |= gSD[i].fDst; | 470 rbMask |= gSD[i].fDst; |
| 471 } | 471 } |
| 472 } | 472 } |
| 473 return rbMask; | 473 return rbMask; |
| 474 } | 474 } |
| 475 | 475 |
| 476 void SkPicturePlayback::parseStreamTag(SkStream* stream, const SkPictInfo& info, uint32_t tag, | 476 bool SkPicturePlayback::parseStreamTag(SkStream* stream, const SkPictInfo& info, uint32_t tag, |
| 477 size_t size, SkPicture::InstallPixelRefPr oc proc) { | 477 size_t size, SkPicture::InstallPixelRefPr oc proc) { |
| 478 /* | 478 /* |
| 479 * By the time we encounter BUFFER_SIZE_TAG, we need to have already seen | 479 * By the time we encounter BUFFER_SIZE_TAG, we need to have already seen |
| 480 * its dependents: FACTORY_TAG and TYPEFACE_TAG. These two are not required | 480 * its dependents: FACTORY_TAG and TYPEFACE_TAG. These two are not required |
| 481 * but if they are present, they need to have been seen before the buffer. | 481 * but if they are present, they need to have been seen before the buffer. |
| 482 * | 482 * |
| 483 * We assert that if/when we see either of these, that we have not yet seen | 483 * We assert that if/when we see either of these, that we have not yet seen |
| 484 * the buffer tag, because if we have, then its too-late to deal with the | 484 * the buffer tag, because if we have, then its too-late to deal with the |
| 485 * factories or typefaces. | 485 * factories or typefaces. |
| 486 */ | 486 */ |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 513 // fTFPlayback asserts it never has a null, so we plop in | 513 // fTFPlayback asserts it never has a null, so we plop in |
| 514 // the default here. | 514 // the default here. |
| 515 tf.reset(SkTypeface::RefDefault()); | 515 tf.reset(SkTypeface::RefDefault()); |
| 516 } | 516 } |
| 517 fTFPlayback.set(i, tf); | 517 fTFPlayback.set(i, tf); |
| 518 } | 518 } |
| 519 } break; | 519 } break; |
| 520 case PICT_PICTURE_TAG: { | 520 case PICT_PICTURE_TAG: { |
| 521 fPictureCount = size; | 521 fPictureCount = size; |
| 522 fPictureRefs = SkNEW_ARRAY(SkPicture*, fPictureCount); | 522 fPictureRefs = SkNEW_ARRAY(SkPicture*, fPictureCount); |
| 523 for (int i = 0; i < fPictureCount; i++) { | 523 bool success = true; |
| 524 int i = 0; | |
| 525 for ( ; i < fPictureCount; i++) { | |
| 524 fPictureRefs[i] = SkPicture::CreateFromStream(stream, proc); | 526 fPictureRefs[i] = SkPicture::CreateFromStream(stream, proc); |
| 525 // CreateFromStream can only fail if PICTURE_VERSION does not ma tch | 527 if (NULL == fPictureRefs[i]) { |
|
scroggo
2013/09/26 21:06:28
This bit is slightly different from a straight rev
| |
| 526 // (which should never happen from here, since a sub picture wil l | 528 success = false; |
| 527 // have the same PICTURE_VERSION as its parent) or if stream->re ad | 529 break; |
| 528 // returns 0. In the latter case, we have a bug when writing the | 530 } |
| 529 // picture to begin with, which will be alerted to here. | 531 } |
| 530 SkASSERT(fPictureRefs[i] != NULL); | 532 if (!success) { |
| 533 // Delete all of the pictures that were already created (up to b ut excluding i): | |
| 534 for (int j = 0; j < i; j++) { | |
| 535 fPictureRefs[j]->unref(); | |
| 536 } | |
| 537 // Delete the array | |
| 538 SkDELETE_ARRAY(fPictureRefs); | |
| 539 fPictureCount = 0; | |
| 540 return false; | |
| 531 } | 541 } |
| 532 } break; | 542 } break; |
| 533 case PICT_BUFFER_SIZE_TAG: { | 543 case PICT_BUFFER_SIZE_TAG: { |
| 534 SkAutoMalloc storage(size); | 544 SkAutoMalloc storage(size); |
| 535 stream->read(storage.get(), size); | 545 stream->read(storage.get(), size); |
| 536 | 546 |
| 537 SkOrderedReadBuffer buffer(storage.get(), size); | 547 SkOrderedReadBuffer buffer(storage.get(), size); |
| 538 buffer.setFlags(pictInfoFlagsToReadBufferFlags(info.fFlags)); | 548 buffer.setFlags(pictInfoFlagsToReadBufferFlags(info.fFlags)); |
| 539 | 549 |
| 540 fFactoryPlayback->setupBuffer(buffer); | 550 fFactoryPlayback->setupBuffer(buffer); |
| 541 fTFPlayback.setupBuffer(buffer); | 551 fTFPlayback.setupBuffer(buffer); |
| 542 buffer.setBitmapDecoder(proc); | 552 buffer.setBitmapDecoder(proc); |
| 543 | 553 |
| 544 while (!buffer.eof()) { | 554 while (!buffer.eof()) { |
| 545 tag = buffer.readUInt(); | 555 tag = buffer.readUInt(); |
| 546 size = buffer.readUInt(); | 556 size = buffer.readUInt(); |
| 547 this->parseBufferTag(buffer, tag, size); | 557 if (!this->parseBufferTag(buffer, tag, size)) { |
| 558 return false; | |
| 559 } | |
| 548 } | 560 } |
| 549 SkDEBUGCODE(haveBuffer = true;) | 561 SkDEBUGCODE(haveBuffer = true;) |
| 550 } break; | 562 } break; |
| 551 } | 563 } |
| 564 return true; // success | |
| 552 } | 565 } |
| 553 | 566 |
| 554 void SkPicturePlayback::parseBufferTag(SkOrderedReadBuffer& buffer, | 567 bool SkPicturePlayback::parseBufferTag(SkOrderedReadBuffer& buffer, |
| 555 uint32_t tag, size_t size) { | 568 uint32_t tag, size_t size) { |
| 556 switch (tag) { | 569 switch (tag) { |
| 557 case PICT_BITMAP_BUFFER_TAG: { | 570 case PICT_BITMAP_BUFFER_TAG: { |
| 558 fBitmaps = SkTRefArray<SkBitmap>::Create(size); | 571 fBitmaps = SkTRefArray<SkBitmap>::Create(size); |
| 559 for (size_t i = 0; i < size; ++i) { | 572 for (size_t i = 0; i < size; ++i) { |
| 560 SkBitmap* bm = &fBitmaps->writableAt(i); | 573 SkBitmap* bm = &fBitmaps->writableAt(i); |
| 561 buffer.readBitmap(bm); | 574 buffer.readBitmap(bm); |
| 562 bm->setImmutable(); | 575 bm->setImmutable(); |
| 563 } | 576 } |
| 564 } break; | 577 } break; |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 579 fPathHeap.reset(SkNEW_ARGS(SkPathHeap, (buffer))); | 592 fPathHeap.reset(SkNEW_ARGS(SkPathHeap, (buffer))); |
| 580 } | 593 } |
| 581 break; | 594 break; |
| 582 case PICT_REGION_BUFFER_TAG: { | 595 case PICT_REGION_BUFFER_TAG: { |
| 583 fRegions = SkTRefArray<SkRegion>::Create(size); | 596 fRegions = SkTRefArray<SkRegion>::Create(size); |
| 584 for (size_t i = 0; i < size; ++i) { | 597 for (size_t i = 0; i < size; ++i) { |
| 585 buffer.readRegion(&fRegions->writableAt(i)); | 598 buffer.readRegion(&fRegions->writableAt(i)); |
| 586 } | 599 } |
| 587 } break; | 600 } break; |
| 588 } | 601 } |
| 602 return true; // success | |
| 589 } | 603 } |
| 590 | 604 |
| 591 SkPicturePlayback::SkPicturePlayback(SkStream* stream, const SkPictInfo& info, | 605 SkPicturePlayback::SkPicturePlayback(SkStream* stream, const SkPictInfo& info, b ool* isValid, |
| 592 SkPicture::InstallPixelRefProc proc) { | 606 SkPicture::InstallPixelRefProc proc) { |
| 593 this->init(); | 607 this->init(); |
| 594 | 608 |
| 609 *isValid = false; // wait until we're done parsing to mark as true | |
| 595 for (;;) { | 610 for (;;) { |
| 596 uint32_t tag = stream->readU32(); | 611 uint32_t tag = stream->readU32(); |
| 597 if (PICT_EOF_TAG == tag) { | 612 if (PICT_EOF_TAG == tag) { |
| 598 break; | 613 break; |
| 599 } | 614 } |
| 600 | 615 |
| 601 uint32_t size = stream->readU32(); | 616 uint32_t size = stream->readU32(); |
| 602 this->parseStreamTag(stream, info, tag, size, proc); | 617 if (!this->parseStreamTag(stream, info, tag, size, proc)) { |
| 618 return; // we're invalid | |
| 619 } | |
| 603 } | 620 } |
| 621 *isValid = true; | |
| 604 } | 622 } |
| 605 | 623 |
| 606 /////////////////////////////////////////////////////////////////////////////// | 624 /////////////////////////////////////////////////////////////////////////////// |
| 607 /////////////////////////////////////////////////////////////////////////////// | 625 /////////////////////////////////////////////////////////////////////////////// |
| 608 | 626 |
| 609 #ifdef SPEW_CLIP_SKIPPING | 627 #ifdef SPEW_CLIP_SKIPPING |
| 610 struct SkipClipRec { | 628 struct SkipClipRec { |
| 611 int fCount; | 629 int fCount; |
| 612 size_t fSize; | 630 size_t fSize; |
| 613 | 631 |
| (...skipping 1008 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1622 for (index = 0; index < fRegionCount; index++) | 1640 for (index = 0; index < fRegionCount; index++) |
| 1623 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer ), | 1641 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer ), |
| 1624 "region%p, ", &fRegions[index]); | 1642 "region%p, ", &fRegions[index]); |
| 1625 if (fRegionCount > 0) | 1643 if (fRegionCount > 0) |
| 1626 SkDebugf("%s0};\n", pBuffer); | 1644 SkDebugf("%s0};\n", pBuffer); |
| 1627 | 1645 |
| 1628 const_cast<SkPicturePlayback*>(this)->dumpStream(); | 1646 const_cast<SkPicturePlayback*>(this)->dumpStream(); |
| 1629 } | 1647 } |
| 1630 | 1648 |
| 1631 #endif | 1649 #endif |
| OLD | NEW |