| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2007 The Android Open Source Project | 3 * Copyright 2007 The Android Open Source Project |
| 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 | 8 |
| 9 | 9 |
| 10 #include "SkPictureFlat.h" | 10 #include "SkPictureFlat.h" |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 int numNonDashedPathEffects = fNumPaintWithPathEffectUses - | 227 int numNonDashedPathEffects = fNumPaintWithPathEffectUses - |
| 228 fNumFastPathDashEffects; | 228 fNumFastPathDashEffects; |
| 229 bool suitableForDash = (0 == fNumPaintWithPathEffectUses) || | 229 bool suitableForDash = (0 == fNumPaintWithPathEffectUses) || |
| 230 (numNonDashedPathEffects < kNumPaintWithPathEffectsUs
esTol | 230 (numNonDashedPathEffects < kNumPaintWithPathEffectsUs
esTol |
| 231 && 0 == sampleCount); | 231 && 0 == sampleCount); |
| 232 | 232 |
| 233 bool ret = suitableForDash && | 233 bool ret = suitableForDash && |
| 234 (fNumAAConcavePaths - fNumAAHairlineConcavePaths) | 234 (fNumAAConcavePaths - fNumAAHairlineConcavePaths) |
| 235 < kNumAAConcavePathsTol; | 235 < kNumAAConcavePathsTol; |
| 236 | 236 |
| 237 if (!ret && NULL != reason) { | 237 if (!ret && reason) { |
| 238 if (!suitableForDash) { | 238 if (!suitableForDash) { |
| 239 if (0 != sampleCount) { | 239 if (0 != sampleCount) { |
| 240 *reason = "Can't use multisample on dash effect."; | 240 *reason = "Can't use multisample on dash effect."; |
| 241 } else { | 241 } else { |
| 242 *reason = "Too many non dashed path effects."; | 242 *reason = "Too many non dashed path effects."; |
| 243 } | 243 } |
| 244 } else if ((fNumAAConcavePaths - fNumAAHairlineConcavePaths) | 244 } else if ((fNumAAConcavePaths - fNumAAHairlineConcavePaths) |
| 245 >= kNumAAConcavePathsTol) | 245 >= kNumAAConcavePathsTol) |
| 246 *reason = "Too many anti-aliased concave paths."; | 246 *reason = "Too many anti-aliased concave paths."; |
| 247 else | 247 else |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 #endif//SK_SUPPORT_LEGACY_PICTURE_CLONE | 289 #endif//SK_SUPPORT_LEGACY_PICTURE_CLONE |
| 290 | 290 |
| 291 // fRecord OK | 291 // fRecord OK |
| 292 void SkPicture::EXPERIMENTAL_addAccelData(const SkPicture::AccelData* data) cons
t { | 292 void SkPicture::EXPERIMENTAL_addAccelData(const SkPicture::AccelData* data) cons
t { |
| 293 fAccelData.reset(SkRef(data)); | 293 fAccelData.reset(SkRef(data)); |
| 294 } | 294 } |
| 295 | 295 |
| 296 // fRecord OK | 296 // fRecord OK |
| 297 const SkPicture::AccelData* SkPicture::EXPERIMENTAL_getAccelData( | 297 const SkPicture::AccelData* SkPicture::EXPERIMENTAL_getAccelData( |
| 298 SkPicture::AccelData::Key key) const { | 298 SkPicture::AccelData::Key key) const { |
| 299 if (NULL != fAccelData.get() && fAccelData->getKey() == key) { | 299 if (fAccelData.get() && fAccelData->getKey() == key) { |
| 300 return fAccelData.get(); | 300 return fAccelData.get(); |
| 301 } | 301 } |
| 302 return NULL; | 302 return NULL; |
| 303 } | 303 } |
| 304 | 304 |
| 305 // fRecord OK | 305 // fRecord OK |
| 306 SkPicture::AccelData::Domain SkPicture::AccelData::GenerateDomain() { | 306 SkPicture::AccelData::Domain SkPicture::AccelData::GenerateDomain() { |
| 307 static int32_t gNextID = 0; | 307 static int32_t gNextID = 0; |
| 308 | 308 |
| 309 int32_t id = sk_atomic_inc(&gNextID); | 309 int32_t id = sk_atomic_inc(&gNextID); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 321 return ((SkPictureStateTree::Draw*)fOps[index])->fOffset; | 321 return ((SkPictureStateTree::Draw*)fOps[index])->fOffset; |
| 322 } | 322 } |
| 323 | 323 |
| 324 const SkMatrix& SkPicture::OperationList::matrix(int index) const { | 324 const SkMatrix& SkPicture::OperationList::matrix(int index) const { |
| 325 SkASSERT(index < fOps.count()); | 325 SkASSERT(index < fOps.count()); |
| 326 return *((SkPictureStateTree::Draw*)fOps[index])->fMatrix; | 326 return *((SkPictureStateTree::Draw*)fOps[index])->fMatrix; |
| 327 } | 327 } |
| 328 | 328 |
| 329 // fRecord OK | 329 // fRecord OK |
| 330 void SkPicture::playback(SkCanvas* canvas, SkDrawPictureCallback* callback) cons
t { | 330 void SkPicture::playback(SkCanvas* canvas, SkDrawPictureCallback* callback) cons
t { |
| 331 SkASSERT(NULL != canvas); | 331 SkASSERT(canvas); |
| 332 SkASSERT(NULL != fData.get() || NULL != fRecord.get()); | 332 SkASSERT(fData.get() || fRecord.get()); |
| 333 | 333 |
| 334 // If the query contains the whole picture, don't bother with the BBH. | 334 // If the query contains the whole picture, don't bother with the BBH. |
| 335 SkRect clipBounds = { 0, 0, 0, 0 }; | 335 SkRect clipBounds = { 0, 0, 0, 0 }; |
| 336 (void)canvas->getClipBounds(&clipBounds); | 336 (void)canvas->getClipBounds(&clipBounds); |
| 337 const bool useBBH = !clipBounds.contains(this->cullRect()); | 337 const bool useBBH = !clipBounds.contains(this->cullRect()); |
| 338 | 338 |
| 339 if (NULL != fData.get()) { | 339 if (fData.get()) { |
| 340 SkPicturePlayback playback(this); | 340 SkPicturePlayback playback(this); |
| 341 playback.setUseBBH(useBBH); | 341 playback.setUseBBH(useBBH); |
| 342 playback.draw(canvas, callback); | 342 playback.draw(canvas, callback); |
| 343 } | 343 } |
| 344 if (NULL != fRecord.get()) { | 344 if (fRecord.get()) { |
| 345 SkRecordDraw(*fRecord, canvas, useBBH ? fBBH.get() : NULL, callback); | 345 SkRecordDraw(*fRecord, canvas, useBBH ? fBBH.get() : NULL, callback); |
| 346 } | 346 } |
| 347 } | 347 } |
| 348 | 348 |
| 349 /////////////////////////////////////////////////////////////////////////////// | 349 /////////////////////////////////////////////////////////////////////////////// |
| 350 | 350 |
| 351 #include "SkStream.h" | 351 #include "SkStream.h" |
| 352 | 352 |
| 353 static const char kMagic[] = { 's', 'k', 'i', 'a', 'p', 'i', 'c', 't' }; | 353 static const char kMagic[] = { 's', 'k', 'i', 'a', 'p', 'i', 'c', 't' }; |
| 354 | 354 |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 524 info->fFlags |= SkPictInfo::kPtrIs64Bit_Flag; | 524 info->fFlags |= SkPictInfo::kPtrIs64Bit_Flag; |
| 525 } | 525 } |
| 526 } | 526 } |
| 527 | 527 |
| 528 // fRecord OK | 528 // fRecord OK |
| 529 void SkPicture::serialize(SkWStream* stream, EncodeBitmap encoder) const { | 529 void SkPicture::serialize(SkWStream* stream, EncodeBitmap encoder) const { |
| 530 const SkPictureData* data = fData.get(); | 530 const SkPictureData* data = fData.get(); |
| 531 | 531 |
| 532 // If we're a new-format picture, backport to old format for serialization. | 532 // If we're a new-format picture, backport to old format for serialization. |
| 533 SkAutoTDelete<SkPicture> oldFormat; | 533 SkAutoTDelete<SkPicture> oldFormat; |
| 534 if (NULL == data && NULL != fRecord.get()) { | 534 if (NULL == data && fRecord.get()) { |
| 535 oldFormat.reset(backport(*fRecord, this->cullRect())); | 535 oldFormat.reset(backport(*fRecord, this->cullRect())); |
| 536 data = oldFormat->fData.get(); | 536 data = oldFormat->fData.get(); |
| 537 SkASSERT(NULL != data); | 537 SkASSERT(data); |
| 538 } | 538 } |
| 539 | 539 |
| 540 SkPictInfo info; | 540 SkPictInfo info; |
| 541 this->createHeader(&info); | 541 this->createHeader(&info); |
| 542 SkASSERT(sizeof(SkPictInfo) == 32); | 542 SkASSERT(sizeof(SkPictInfo) == 32); |
| 543 stream->write(&info, sizeof(info)); | 543 stream->write(&info, sizeof(info)); |
| 544 | 544 |
| 545 if (NULL != data) { | 545 if (data) { |
| 546 stream->writeBool(true); | 546 stream->writeBool(true); |
| 547 data->serialize(stream, encoder); | 547 data->serialize(stream, encoder); |
| 548 } else { | 548 } else { |
| 549 stream->writeBool(false); | 549 stream->writeBool(false); |
| 550 } | 550 } |
| 551 } | 551 } |
| 552 | 552 |
| 553 // fRecord OK | 553 // fRecord OK |
| 554 void SkPicture::flatten(SkWriteBuffer& buffer) const { | 554 void SkPicture::flatten(SkWriteBuffer& buffer) const { |
| 555 const SkPictureData* data = fData.get(); | 555 const SkPictureData* data = fData.get(); |
| 556 | 556 |
| 557 // If we're a new-format picture, backport to old format for serialization. | 557 // If we're a new-format picture, backport to old format for serialization. |
| 558 SkAutoTDelete<SkPicture> oldFormat; | 558 SkAutoTDelete<SkPicture> oldFormat; |
| 559 if (NULL == data && NULL != fRecord.get()) { | 559 if (NULL == data && fRecord.get()) { |
| 560 oldFormat.reset(backport(*fRecord, this->cullRect())); | 560 oldFormat.reset(backport(*fRecord, this->cullRect())); |
| 561 data = oldFormat->fData.get(); | 561 data = oldFormat->fData.get(); |
| 562 SkASSERT(NULL != data); | 562 SkASSERT(data); |
| 563 } | 563 } |
| 564 | 564 |
| 565 SkPictInfo info; | 565 SkPictInfo info; |
| 566 this->createHeader(&info); | 566 this->createHeader(&info); |
| 567 buffer.writeByteArray(&info.fMagic, sizeof(info.fMagic)); | 567 buffer.writeByteArray(&info.fMagic, sizeof(info.fMagic)); |
| 568 buffer.writeUInt(info.fVersion); | 568 buffer.writeUInt(info.fVersion); |
| 569 buffer.writeRect(info.fCullRect); | 569 buffer.writeRect(info.fCullRect); |
| 570 buffer.writeUInt(info.fFlags); | 570 buffer.writeUInt(info.fFlags); |
| 571 | 571 |
| 572 if (NULL != data) { | 572 if (data) { |
| 573 buffer.writeBool(true); | 573 buffer.writeBool(true); |
| 574 data->flatten(buffer); | 574 data->flatten(buffer); |
| 575 } else { | 575 } else { |
| 576 buffer.writeBool(false); | 576 buffer.writeBool(false); |
| 577 } | 577 } |
| 578 } | 578 } |
| 579 | 579 |
| 580 #if SK_SUPPORT_GPU | 580 #if SK_SUPPORT_GPU |
| 581 // fRecord OK | 581 // fRecord OK |
| 582 bool SkPicture::suitableForGpuRasterization(GrContext* context, const char **rea
son) const { | 582 bool SkPicture::suitableForGpuRasterization(GrContext* context, const char **rea
son) const { |
| 583 if (fRecord.get()) { | 583 if (fRecord.get()) { |
| 584 return fAnalysis.suitableForGpuRasterization(reason, 0); | 584 return fAnalysis.suitableForGpuRasterization(reason, 0); |
| 585 } | 585 } |
| 586 if (NULL == fData.get()) { | 586 if (NULL == fData.get()) { |
| 587 if (NULL != reason) { | 587 if (reason) { |
| 588 *reason = "Missing internal data."; | 588 *reason = "Missing internal data."; |
| 589 } | 589 } |
| 590 return false; | 590 return false; |
| 591 } | 591 } |
| 592 | 592 |
| 593 return fData->suitableForGpuRasterization(context, reason); | 593 return fData->suitableForGpuRasterization(context, reason); |
| 594 } | 594 } |
| 595 #endif | 595 #endif |
| 596 | 596 |
| 597 // fRecord OK | 597 // fRecord OK |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 650 SkRecordFillBounds(*record, fBBH.get()); | 650 SkRecordFillBounds(*record, fBBH.get()); |
| 651 } | 651 } |
| 652 this->needsNewGenID(); | 652 this->needsNewGenID(); |
| 653 } | 653 } |
| 654 | 654 |
| 655 // Note that we are assuming that this entry point will only be called from | 655 // Note that we are assuming that this entry point will only be called from |
| 656 // one thread. Currently the only client of this method is | 656 // one thread. Currently the only client of this method is |
| 657 // SkGpuDevice::EXPERIMENTAL_optimize which should be only called from a single | 657 // SkGpuDevice::EXPERIMENTAL_optimize which should be only called from a single |
| 658 // thread. | 658 // thread. |
| 659 void SkPicture::addDeletionListener(DeletionListener* listener) const { | 659 void SkPicture::addDeletionListener(DeletionListener* listener) const { |
| 660 SkASSERT(NULL != listener); | 660 SkASSERT(listener); |
| 661 | 661 |
| 662 *fDeletionListeners.append() = SkRef(listener); | 662 *fDeletionListeners.append() = SkRef(listener); |
| 663 } | 663 } |
| 664 | 664 |
| 665 void SkPicture::callDeletionListeners() { | 665 void SkPicture::callDeletionListeners() { |
| 666 for (int i = 0; i < fDeletionListeners.count(); ++i) { | 666 for (int i = 0; i < fDeletionListeners.count(); ++i) { |
| 667 fDeletionListeners[i]->onDeletion(this->uniqueID()); | 667 fDeletionListeners[i]->onDeletion(this->uniqueID()); |
| 668 } | 668 } |
| 669 | 669 |
| 670 fDeletionListeners.unrefAll(); | 670 fDeletionListeners.unrefAll(); |
| 671 } | 671 } |
| 672 | 672 |
| 673 // fRecord OK | 673 // fRecord OK |
| 674 int SkPicture::approximateOpCount() const { | 674 int SkPicture::approximateOpCount() const { |
| 675 SkASSERT(fRecord.get() || fData.get()); | 675 SkASSERT(fRecord.get() || fData.get()); |
| 676 if (fRecord.get()) { | 676 if (fRecord.get()) { |
| 677 return fRecord->count(); | 677 return fRecord->count(); |
| 678 } | 678 } |
| 679 if (fData.get()) { | 679 if (fData.get()) { |
| 680 return fData->opCount(); | 680 return fData->opCount(); |
| 681 } | 681 } |
| 682 return 0; | 682 return 0; |
| 683 } | 683 } |
| OLD | NEW |