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