| OLD | NEW |
| 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 "SkDrawPictureCallback.h" | 9 #include "SkDrawPictureCallback.h" |
| 10 #include "SkPictureData.h" | 10 #include "SkPictureData.h" |
| (...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 * its dependents: FACTORY_TAG and TYPEFACE_TAG. These two are not required | 383 * its dependents: FACTORY_TAG and TYPEFACE_TAG. These two are not required |
| 384 * but if they are present, they need to have been seen before the buffer. | 384 * but if they are present, they need to have been seen before the buffer. |
| 385 * | 385 * |
| 386 * We assert that if/when we see either of these, that we have not yet seen | 386 * We assert that if/when we see either of these, that we have not yet seen |
| 387 * the buffer tag, because if we have, then its too-late to deal with the | 387 * the buffer tag, because if we have, then its too-late to deal with the |
| 388 * factories or typefaces. | 388 * factories or typefaces. |
| 389 */ | 389 */ |
| 390 SkDEBUGCODE(bool haveBuffer = false;) | 390 SkDEBUGCODE(bool haveBuffer = false;) |
| 391 | 391 |
| 392 switch (tag) { | 392 switch (tag) { |
| 393 case SK_PICT_READER_TAG: { | 393 case SK_PICT_READER_TAG: |
| 394 SkAutoMalloc storage(size); | 394 SkASSERT(NULL == fOpData); |
| 395 if (stream->read(storage.get(), size) != size) { | 395 fOpData = stream->readIntoData(size); |
| 396 if (!fOpData) { |
| 396 return false; | 397 return false; |
| 397 } | 398 } |
| 398 SkASSERT(NULL == fOpData); | 399 break; |
| 399 fOpData = SkData::NewFromMalloc(storage.detach(), size); | |
| 400 } break; | |
| 401 case SK_PICT_FACTORY_TAG: { | 400 case SK_PICT_FACTORY_TAG: { |
| 402 SkASSERT(!haveBuffer); | 401 SkASSERT(!haveBuffer); |
| 403 // Remove this code when v21 and below are no longer supported. At the | 402 // Remove this code when v21 and below are no longer supported. At the |
| 404 // same time add a new 'count' variable and use it rather then reusing '
size'. | 403 // same time add a new 'count' variable and use it rather then reusing '
size'. |
| 405 #ifndef DISABLE_V21_COMPATIBILITY_CODE | 404 #ifndef DISABLE_V21_COMPATIBILITY_CODE |
| 406 if (fInfo.fVersion >= 22) { | 405 if (fInfo.fVersion >= 22) { |
| 407 // in v22 this tag's size represents the size of the chunk in by
tes | 406 // in v22 this tag's size represents the size of the chunk in by
tes |
| 408 // and the number of factory strings is written out separately | 407 // and the number of factory strings is written out separately |
| 409 #endif | 408 #endif |
| 410 size = stream->readU32(); | 409 size = stream->readU32(); |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 531 fTextBlobRefs[j]->unref(); | 530 fTextBlobRefs[j]->unref(); |
| 532 } | 531 } |
| 533 // Delete the array | 532 // Delete the array |
| 534 SkDELETE_ARRAY(fTextBlobRefs); | 533 SkDELETE_ARRAY(fTextBlobRefs); |
| 535 fTextBlobRefs = NULL; | 534 fTextBlobRefs = NULL; |
| 536 fTextBlobCount = 0; | 535 fTextBlobCount = 0; |
| 537 return false; | 536 return false; |
| 538 } | 537 } |
| 539 } break; | 538 } break; |
| 540 case SK_PICT_READER_TAG: { | 539 case SK_PICT_READER_TAG: { |
| 541 SkAutoMalloc storage(size); | 540 SkAutoDataUnref data(SkData::NewUninitialized(size)); |
| 542 if (!buffer.readByteArray(storage.get(), size) || | 541 if (!buffer.readByteArray(data->writable_data(), size) || |
| 543 !buffer.validate(NULL == fOpData)) { | 542 !buffer.validate(NULL == fOpData)) { |
| 544 return false; | 543 return false; |
| 545 } | 544 } |
| 546 SkASSERT(NULL == fOpData); | 545 SkASSERT(NULL == fOpData); |
| 547 fOpData = SkData::NewFromMalloc(storage.detach(), size); | 546 fOpData = data.detach(); |
| 548 } break; | 547 } break; |
| 549 case SK_PICT_PICTURE_TAG: { | 548 case SK_PICT_PICTURE_TAG: { |
| 550 if (!buffer.validate((0 == fPictureCount) && (NULL == fPictureRefs))
) { | 549 if (!buffer.validate((0 == fPictureCount) && (NULL == fPictureRefs))
) { |
| 551 return false; | 550 return false; |
| 552 } | 551 } |
| 553 fPictureCount = size; | 552 fPictureCount = size; |
| 554 fPictureRefs = SkNEW_ARRAY(const SkPicture*, fPictureCount); | 553 fPictureRefs = SkNEW_ARRAY(const SkPicture*, fPictureCount); |
| 555 bool success = true; | 554 bool success = true; |
| 556 int i = 0; | 555 int i = 0; |
| 557 for ( ; i < fPictureCount; i++) { | 556 for ( ; i < fPictureCount; i++) { |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 662 } | 661 } |
| 663 } | 662 } |
| 664 | 663 |
| 665 bool SkPictureData::suitableForLayerOptimization() const { | 664 bool SkPictureData::suitableForLayerOptimization() const { |
| 666 return fContentInfo.numLayers() > 0; | 665 return fContentInfo.numLayers() > 0; |
| 667 } | 666 } |
| 668 #endif | 667 #endif |
| 669 /////////////////////////////////////////////////////////////////////////////// | 668 /////////////////////////////////////////////////////////////////////////////// |
| 670 | 669 |
| 671 | 670 |
| OLD | NEW |