Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Public Member Functions | List of all members
SkStrikeClientImpl Class Reference

Public Member Functions

 SkStrikeClientImpl (sk_sp< SkStrikeClient::DiscardableHandleManager >, bool isLogging=true, SkStrikeCache *strikeCache=nullptr)
 
bool readStrikeData (const volatile void *memory, size_t memorySize)
 
bool translateTypefaceID (SkAutoDescriptor *descriptor) const
 
sk_sp< SkTypefaceretrieveTypefaceUsingServerID (SkTypefaceID) const
 

Detailed Description

Definition at line 585 of file SkChromeRemoteGlyphCache.cpp.

Constructor & Destructor Documentation

◆ SkStrikeClientImpl()

SkStrikeClientImpl::SkStrikeClientImpl ( sk_sp< SkStrikeClient::DiscardableHandleManager discardableManager,
bool  isLogging = true,
SkStrikeCache strikeCache = nullptr 
)
explicit

Definition at line 616 of file SkChromeRemoteGlyphCache.cpp.

621 : fDiscardableHandleManager(std::move(discardableManager)),
622 fStrikeCache{strikeCache ? strikeCache : SkStrikeCache::GlobalStrikeCache()},
623 fIsLogging{isLogging} {}
static SkStrikeCache * GlobalStrikeCache()

Member Function Documentation

◆ readStrikeData()

bool SkStrikeClientImpl::readStrikeData ( const volatile void *  memory,
size_t  memorySize 
)

Definition at line 637 of file SkChromeRemoteGlyphCache.cpp.

637 {
638 SkASSERT(memorySize != 0);
639 SkASSERT(memory != nullptr);
640
641 // We do not need to set any SkDeserialProcs here because SkStrikeServerImpl::writeStrikeData
642 // did not encode any SkImages.
643 SkReadBuffer buffer{const_cast<const void*>(memory), memorySize};
644 // Limit the kinds of effects that appear in a glyph's drawable (crbug.com/1442140):
645 buffer.setAllowSkSL(false);
646
647 int curTypeface = 0,
648 curStrike = 0;
649
650 auto postError = [&](int line) {
651 SkDebugf("Read Error Posted %s : %d", __FILE__, line);
653 memorySize,
654 buffer.offset(),
655 SkTo<uint64_t>(curTypeface),
656 SkTo<uint64_t>(curStrike),
657 SkTo<uint64_t>(0),
658 SkTo<uint64_t>(0)};
659 fDiscardableHandleManager->notifyReadFailure(data);
660 };
661
662 // Read the number of typefaces sent.
663 const int typefaceCount = buffer.readInt();
664 for (curTypeface = 0; curTypeface < typefaceCount; ++curTypeface) {
666 if (proto) {
667 this->addTypeface(proto.value());
668 } else {
669 postError(__LINE__);
670 return false;
671 }
672 }
673
674 // Read the number of strikes sent.
675 const int stirkeCount = buffer.readInt();
676 for (curStrike = 0; curStrike < stirkeCount; ++curStrike) {
677
678 const SkTypefaceID serverTypefaceID = buffer.readUInt();
679 if (serverTypefaceID == 0 && !buffer.isValid()) {
680 postError(__LINE__);
681 return false;
682 }
683
684 const SkDiscardableHandleId discardableHandleID = buffer.readUInt();
685 if (discardableHandleID == 0 && !buffer.isValid()) {
686 postError(__LINE__);
687 return false;
688 }
689
690 std::optional<SkAutoDescriptor> serverDescriptor = SkAutoDescriptor::MakeFromBuffer(buffer);
691 if (!buffer.validate(serverDescriptor.has_value())) {
692 postError(__LINE__);
693 return false;
694 }
695
696 const bool fontMetricsInitialized = buffer.readBool();
697 if (!fontMetricsInitialized && !buffer.isValid()) {
698 postError(__LINE__);
699 return false;
700 }
701
702 std::optional<SkFontMetrics> fontMetrics;
703 if (!fontMetricsInitialized) {
705 if (!fontMetrics || !buffer.isValid()) {
706 postError(__LINE__);
707 return false;
708 }
709 }
710
711 auto* clientTypeface = fServerTypefaceIdToTypeface.find(serverTypefaceID);
712 if (clientTypeface == nullptr) {
713 postError(__LINE__);
714 return false;
715 }
716
717 if (!this->translateTypefaceID(&serverDescriptor.value())) {
718 postError(__LINE__);
719 return false;
720 }
721
722 SkDescriptor* clientDescriptor = serverDescriptor->getDesc();
723 auto strike = fStrikeCache->findStrike(*clientDescriptor);
724
725 if (strike == nullptr) {
726 // Metrics are only sent the first time. If creating a new strike, then the metrics
727 // are not initialized.
728 if (fontMetricsInitialized) {
729 postError(__LINE__);
730 return false;
731 }
732 SkStrikeSpec strikeSpec{*clientDescriptor, *clientTypeface};
733 strike = fStrikeCache->createStrike(
734 strikeSpec, &fontMetrics.value(),
735 std::make_unique<DiscardableStrikePinner>(
736 discardableHandleID, fDiscardableHandleManager));
737 }
738
739 // Make sure this strike is pinned on the GPU side.
740 strike->verifyPinnedStrike();
741
742 if (!strike->mergeFromBuffer(buffer)) {
743 postError(__LINE__);
744 return false;
745 }
746 }
747
748 return true;
749}
#define SkASSERT(cond)
Definition SkAssert.h:116
uint32_t SkDiscardableHandleId
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
uint32_t SkTypefaceID
Definition SkTypeface.h:38
static std::optional< SkAutoDescriptor > MakeFromBuffer(SkReadBuffer &buffer)
static std::optional< SkFontMetrics > MakeFromBuffer(SkReadBuffer &buffer)
void setAllowSkSL(bool allow)
sk_sp< SkStrike > createStrike(const SkStrikeSpec &strikeSpec, SkFontMetrics *maybeMetrics=nullptr, std::unique_ptr< SkStrikePinner >=nullptr) SK_EXCLUDES(fLock)
sk_sp< SkStrike > findStrike(const SkDescriptor &desc) SK_EXCLUDES(fLock)
bool translateTypefaceID(SkAutoDescriptor *descriptor) const
virtual void notifyReadFailure(const ReadFailureData &data)
void verifyPinnedStrike() const
Definition SkStrike.h:125
static std::optional< SkTypefaceProxyPrototype > MakeFromBuffer(SkReadBuffer &buffer)
V * find(const K &key) const
Definition SkTHash.h:479
static const uint8_t buffer[]
AutoTArray< uint8_t > data((int) size)

◆ retrieveTypefaceUsingServerID()

sk_sp< SkTypeface > SkStrikeClientImpl::retrieveTypefaceUsingServerID ( SkTypefaceID  typefaceID) const

Definition at line 776 of file SkChromeRemoteGlyphCache.cpp.

776 {
777 auto* tfPtr = fServerTypefaceIdToTypeface.find(typefaceID);
778 return tfPtr != nullptr ? *tfPtr : nullptr;
779}

◆ translateTypefaceID()

bool SkStrikeClientImpl::translateTypefaceID ( SkAutoDescriptor descriptor) const

Definition at line 751 of file SkChromeRemoteGlyphCache.cpp.

751 {
752 SkDescriptor& descriptor = *toChange->getDesc();
753
754 // Rewrite the typefaceID in the rec.
755 {
756 uint32_t size;
757 // findEntry returns a const void*, remove the const in order to update in place.
758 void* ptr = const_cast<void *>(descriptor.findEntry(kRec_SkDescriptorTag, &size));
760 if (!ptr || size != sizeof(rec)) { return false; }
761 std::memcpy((void*)&rec, ptr, size);
762 // Get the local typeface from remote typefaceID.
763 auto* tfPtr = fServerTypefaceIdToTypeface.find(rec.fTypefaceID);
764 // Received a strike for a typeface which doesn't exist.
765 if (!tfPtr) { return false; }
766 // Update the typeface id to work with the client side.
767 rec.fTypefaceID = tfPtr->get()->uniqueID();
768 std::memcpy(ptr, &rec, size);
769 }
770
771 descriptor.computeChecksum();
772
773 return true;
774}
#define kRec_SkDescriptorTag
SkDescriptor * getDesc() const
void computeChecksum()
const void * findEntry(uint32_t tag, uint32_t *length) const
SkTypefaceID fTypefaceID

The documentation for this class was generated from the following file: