Flutter Engine
The Flutter Engine
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)
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:494
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
Definition: switches.h:126
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63

◆ 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
Definition: SkDescriptor.h:103
void computeChecksum()
const void * findEntry(uint32_t tag, uint32_t *length) const
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
SkTypefaceID fTypefaceID

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