| 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 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 template <typename T> | 164 template <typename T> |
| 165 SK_WHEN(!HasMember_paint<T>, void) operator()(const T& op) { /* do nothing *
/ } | 165 SK_WHEN(!HasMember_paint<T>, void) operator()(const T& op) { /* do nothing *
/ } |
| 166 | 166 |
| 167 | 167 |
| 168 int numPaintWithPathEffectUses; | 168 int numPaintWithPathEffectUses; |
| 169 int numFastPathDashEffects; | 169 int numFastPathDashEffects; |
| 170 int numAAConcavePaths; | 170 int numAAConcavePaths; |
| 171 int numAAHairlineConcavePaths; | 171 int numAAHairlineConcavePaths; |
| 172 }; | 172 }; |
| 173 | 173 |
| 174 // SkRecord visitor to find recorded text. |
| 175 struct TextHunter { |
| 176 // All ops with text have that text as a char array member named "text". |
| 177 SK_CREATE_MEMBER_DETECTOR(text); |
| 178 template <typename T> SK_WHEN(HasMember_text<T>, bool) operator()(const T&)
{ return true; } |
| 179 template <typename T> SK_WHEN(!HasMember_text<T>, bool) operator()(const T&)
{ return false; } |
| 180 }; |
| 181 |
| 174 } // namespace | 182 } // namespace |
| 175 | 183 |
| 176 void SkPicture::Analysis::init(const SkRecord& record) { | 184 SkPicture::Analysis::Analysis(const SkRecord& record) { |
| 177 | |
| 178 fWillPlaybackBitmaps = WillPlaybackBitmaps(record); | 185 fWillPlaybackBitmaps = WillPlaybackBitmaps(record); |
| 179 | 186 |
| 180 PathCounter counter; | 187 PathCounter counter; |
| 181 for (unsigned i = 0; i < record.count(); i++) { | 188 for (unsigned i = 0; i < record.count(); i++) { |
| 182 record.visit<void>(i, counter); | 189 record.visit<void>(i, counter); |
| 183 } | 190 } |
| 184 fNumPaintWithPathEffectUses = counter.numPaintWithPathEffectUses; | 191 fNumPaintWithPathEffectUses = counter.numPaintWithPathEffectUses; |
| 185 fNumFastPathDashEffects = counter.numFastPathDashEffects; | 192 fNumFastPathDashEffects = counter.numFastPathDashEffects; |
| 186 fNumAAConcavePaths = counter.numAAConcavePaths; | 193 fNumAAConcavePaths = counter.numAAConcavePaths; |
| 187 fNumAAHairlineConcavePaths = counter.numAAHairlineConcavePaths; | 194 fNumAAHairlineConcavePaths = counter.numAAHairlineConcavePaths; |
| 195 |
| 196 TextHunter text; |
| 197 for (unsigned i = 0; i < record.count(); i++) { |
| 198 if (record.visit<bool>(i, text)) { |
| 199 fHasText = true; |
| 200 break; |
| 201 } |
| 202 } |
| 188 } | 203 } |
| 189 | 204 |
| 190 bool SkPicture::Analysis::suitableForGpuRasterization(const char** reason, | 205 bool SkPicture::Analysis::suitableForGpuRasterization(const char** reason, |
| 191 int sampleCount) const { | 206 int sampleCount) const { |
| 192 // TODO: the heuristic used here needs to be refined | 207 // TODO: the heuristic used here needs to be refined |
| 193 static const int kNumPaintWithPathEffectsUsesTol = 1; | 208 static const int kNumPaintWithPathEffectsUsesTol = 1; |
| 194 static const int kNumAAConcavePathsTol = 5; | 209 static const int kNumAAConcavePathsTol = 5; |
| 195 | 210 |
| 196 int numNonDashedPathEffects = fNumPaintWithPathEffectUses - | 211 int numNonDashedPathEffects = fNumPaintWithPathEffectUses - |
| 197 fNumFastPathDashEffects; | 212 fNumFastPathDashEffects; |
| (...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 568 if (NULL != reason) { | 583 if (NULL != reason) { |
| 569 *reason = "Missing internal data."; | 584 *reason = "Missing internal data."; |
| 570 } | 585 } |
| 571 return false; | 586 return false; |
| 572 } | 587 } |
| 573 | 588 |
| 574 return fData->suitableForGpuRasterization(context, reason); | 589 return fData->suitableForGpuRasterization(context, reason); |
| 575 } | 590 } |
| 576 #endif | 591 #endif |
| 577 | 592 |
| 578 // fRecord TODO | 593 // fRecord OK |
| 579 bool SkPicture::hasText() const { | 594 bool SkPicture::hasText() const { |
| 580 return fData.get() && fData->hasText(); | 595 if (fRecord.get()) { |
| 596 return fAnalysis.fHasText; |
| 597 } |
| 598 if (fData.get()) { |
| 599 return fData->hasText(); |
| 600 } |
| 601 SkFAIL("Unreachable"); |
| 602 return false; |
| 581 } | 603 } |
| 582 | 604 |
| 583 // fRecord OK | 605 // fRecord OK |
| 584 bool SkPicture::willPlayBackBitmaps() const { | 606 bool SkPicture::willPlayBackBitmaps() const { |
| 585 if (fRecord.get()) { | 607 if (fRecord.get()) { |
| 586 return fAnalysis.fWillPlaybackBitmaps; | 608 return fAnalysis.fWillPlaybackBitmaps; |
| 587 } | 609 } |
| 588 if (!fData.get()) { | 610 if (fData.get()) { |
| 589 return false; | 611 return fData->containsBitmaps(); |
| 590 } | 612 } |
| 591 return fData->containsBitmaps(); | 613 SkFAIL("Unreachable"); |
| 614 return false; |
| 592 } | 615 } |
| 593 | 616 |
| 594 // fRecord OK | 617 // fRecord OK |
| 595 static int32_t next_picture_generation_id() { | 618 static int32_t next_picture_generation_id() { |
| 596 static int32_t gPictureGenerationID = 0; | 619 static int32_t gPictureGenerationID = 0; |
| 597 // do a loop in case our global wraps around, as we never want to | 620 // do a loop in case our global wraps around, as we never want to |
| 598 // return a 0 | 621 // return a 0 |
| 599 int32_t genID; | 622 int32_t genID; |
| 600 do { | 623 do { |
| 601 genID = sk_atomic_inc(&gPictureGenerationID) + 1; | 624 genID = sk_atomic_inc(&gPictureGenerationID) + 1; |
| 602 } while (SK_InvalidGenID == genID); | 625 } while (SK_InvalidGenID == genID); |
| 603 return genID; | 626 return genID; |
| 604 } | 627 } |
| 605 | 628 |
| 606 // fRecord OK | 629 // fRecord OK |
| 607 uint32_t SkPicture::uniqueID() const { | 630 uint32_t SkPicture::uniqueID() const { |
| 608 if (SK_InvalidGenID == fUniqueID) { | 631 if (SK_InvalidGenID == fUniqueID) { |
| 609 fUniqueID = next_picture_generation_id(); | 632 fUniqueID = next_picture_generation_id(); |
| 610 } | 633 } |
| 611 return fUniqueID; | 634 return fUniqueID; |
| 612 } | 635 } |
| 613 | 636 |
| 614 // fRecord OK | 637 // fRecord OK |
| 615 SkPicture::SkPicture(int width, int height, SkRecord* record, SkBBoxHierarchy* b
bh) | 638 SkPicture::SkPicture(int width, int height, SkRecord* record, SkBBoxHierarchy* b
bh) |
| 616 : fWidth(width) | 639 : fWidth(width) |
| 617 , fHeight(height) | 640 , fHeight(height) |
| 618 , fRecord(record) | 641 , fRecord(record) |
| 619 , fBBH(SkSafeRef(bbh)) | 642 , fBBH(SkSafeRef(bbh)) |
| 620 , fAnalysis() { | 643 , fAnalysis(*record) { |
| 621 // TODO: delay as much of this work until just before first playback? | 644 // TODO: delay as much of this work until just before first playback? |
| 622 | |
| 623 const_cast<Analysis*>(&fAnalysis)->init(*record); | |
| 624 if (fBBH.get()) { | 645 if (fBBH.get()) { |
| 625 SkRecordFillBounds(*record, fBBH.get()); | 646 SkRecordFillBounds(*record, fBBH.get()); |
| 626 } | 647 } |
| 627 this->needsNewGenID(); | 648 this->needsNewGenID(); |
| 628 } | 649 } |
| 629 | 650 |
| 630 // Note that we are assuming that this entry point will only be called from | 651 // Note that we are assuming that this entry point will only be called from |
| 631 // one thread. Currently the only client of this method is | 652 // one thread. Currently the only client of this method is |
| 632 // SkGpuDevice::EXPERIMENTAL_optimize which should be only called from a single | 653 // SkGpuDevice::EXPERIMENTAL_optimize which should be only called from a single |
| 633 // thread. | 654 // thread. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 649 int SkPicture::approximateOpCount() const { | 670 int SkPicture::approximateOpCount() const { |
| 650 SkASSERT(fRecord.get() || fData.get()); | 671 SkASSERT(fRecord.get() || fData.get()); |
| 651 if (fRecord.get()) { | 672 if (fRecord.get()) { |
| 652 return fRecord->count(); | 673 return fRecord->count(); |
| 653 } | 674 } |
| 654 if (fData.get()) { | 675 if (fData.get()) { |
| 655 return fData->opCount(); | 676 return fData->opCount(); |
| 656 } | 677 } |
| 657 return 0; | 678 return 0; |
| 658 } | 679 } |
| OLD | NEW |