diff --git a/src/core/SkChromeRemoteGlyphCache.cpp b/src/core/SkChromeRemoteGlyphCache.cpp index b04b582d9e..ef015d098c 100644 --- a/src/core/SkChromeRemoteGlyphCache.cpp +++ b/src/core/SkChromeRemoteGlyphCache.cpp @@ -291,7 +291,7 @@ private: LowerRangeBitVector fSentLowGlyphIDs; // The masks and paths that currently reside in the GPU process. - SkTHashTable fSentGlyphs; + SkTHashMap fSentGlyphs; SkTHashTable fSentPaths; SkTHashTable fSentDrawables; @@ -438,7 +438,7 @@ void RemoteStrike::commonMaskLoop( SkDrawableGlyphBuffer* accepted, SkSourceGlyphBuffer* rejected, Rejector&& reject) { accepted->forEachInput( [&](size_t i, SkPackedGlyphID packedID, SkPoint position) { - SkGlyphDigest* digest = fSentGlyphs.find(packedID.value()); + SkGlyphDigest* digest = fSentGlyphs.find(packedID); if (digest == nullptr) { // Put the new SkGlyph in the glyphs to send. this->ensureScalerContext(); @@ -446,7 +446,7 @@ void RemoteStrike::commonMaskLoop( SkGlyph* glyph = &fMasksToSend.back(); SkGlyphDigest newDigest{0, *glyph}; - digest = fSentGlyphs.set(newDigest); + digest = fSentGlyphs.set(packedID, newDigest); } // Reject things that are too big. @@ -462,14 +462,14 @@ void RemoteStrike::prepareForMaskDrawing( SkPackedGlyphID packedID = variant.packedID(); if (fSentLowGlyphIDs.test(packedID)) { #ifdef SK_DEBUG - SkGlyphDigest* digest = fSentGlyphs.find(packedID.value()); + SkGlyphDigest* digest = fSentGlyphs.find(packedID); SkASSERT(digest != nullptr); SkASSERT(digest->canDrawAsMask() && digest->canDrawAsSDFT()); #endif continue; } - SkGlyphDigest* digest = fSentGlyphs.find(packedID.value()); + SkGlyphDigest* digest = fSentGlyphs.find(packedID); if (digest == nullptr) { // Put the new SkGlyph in the glyphs to send. @@ -479,7 +479,7 @@ void RemoteStrike::prepareForMaskDrawing( SkGlyphDigest newDigest{0, *glyph}; - digest = fSentGlyphs.set(newDigest); + digest = fSentGlyphs.set(packedID, newDigest); if (digest->canDrawAsMask() && digest->canDrawAsSDFT()) { fSentLowGlyphIDs.setIfLower(packedID); diff --git a/src/core/SkGlyph.cpp b/src/core/SkGlyph.cpp index 79bcbcbe47..182087cfde 100644 --- a/src/core/SkGlyph.cpp +++ b/src/core/SkGlyph.cpp @@ -397,8 +397,7 @@ void SkGlyph::ensureIntercepts(const SkScalar* bounds, SkScalar scale, SkScalar } SkGlyphDigest::SkGlyphDigest(size_t index, const SkGlyph& glyph) - : fPackedGlyphID{glyph.getPackedID().value()} - , fIndex{SkTo(index)} + : fIndex{SkTo(index)} , fIsEmpty(glyph.isEmpty()) , fIsColor(glyph.isColor()) , fCanDrawAsMask{SkStrikeForGPU::CanDrawAsMask(glyph)} diff --git a/src/core/SkGlyph.h b/src/core/SkGlyph.h index d725511756..e346b68ffc 100644 --- a/src/core/SkGlyph.h +++ b/src/core/SkGlyph.h @@ -46,11 +46,17 @@ struct SkPackedGlyphID { kFixedPointSubPixelPosBits = kFixedPointBinaryPointPos - kSubPixelPosLen, }; - inline static constexpr SkScalar kSubpixelRound = + inline static const constexpr SkScalar kSubpixelRound = 1.f / (1u << (SkPackedGlyphID::kSubPixelPosLen + 1)); - inline static constexpr SkIPoint kXYFieldMask{kSubPixelPosMask << kSubPixelX, - kSubPixelPosMask << kSubPixelY}; + inline static const constexpr SkIPoint kXYFieldMask{kSubPixelPosMask << kSubPixelX, + kSubPixelPosMask << kSubPixelY}; + + struct Hash { + uint32_t operator() (SkPackedGlyphID packedID) const { + return packedID.hash(); + } + }; constexpr explicit SkPackedGlyphID(SkGlyphID glyphID) : fID{(uint32_t)glyphID << kGlyphID} { } @@ -256,20 +262,10 @@ public: bool isColor() const {return fIsColor; } bool canDrawAsMask() const {return fCanDrawAsMask;} bool canDrawAsSDFT() const {return fCanDrawAsSDFT;} - uint32_t packedGlyphID() const {return fPackedGlyphID;} uint16_t maxDimension() const {return fMaxDimension; } - // Support mapping from SkPackedGlyphID stored in the digest. - static uint32_t GetKey(SkGlyphDigest digest) { - return digest.packedGlyphID(); - } - static uint32_t Hash(uint32_t packedGlyphID) { - return SkGoodHash()(packedGlyphID); - } - private: static_assert(SkPackedGlyphID::kEndData == 20); - uint64_t fPackedGlyphID : SkPackedGlyphID::kEndData; uint64_t fIndex : SkPackedGlyphID::kEndData; uint64_t fIsEmpty : 1; uint64_t fIsColor : 1; diff --git a/src/core/SkScalerCache.cpp b/src/core/SkScalerCache.cpp index 73a679c250..030ee23008 100644 --- a/src/core/SkScalerCache.cpp +++ b/src/core/SkScalerCache.cpp @@ -41,7 +41,7 @@ std::tuple SkScalerCache::glyph(SkPackedGlyphID packedGlyphID) } std::tuple SkScalerCache::digest(SkPackedGlyphID packedGlyphID) { - SkGlyphDigest* digest = fDigestForPackedGlyphID.find(packedGlyphID.value()); + SkGlyphDigest* digest = fDigestForPackedGlyphID.find(packedGlyphID); if (digest != nullptr) { return {*digest, 0}; @@ -54,7 +54,7 @@ std::tuple SkScalerCache::digest(SkPackedGlyphID packedGl SkGlyphDigest SkScalerCache::addGlyph(SkGlyph* glyph) { size_t index = fGlyphForIndex.size(); SkGlyphDigest digest = SkGlyphDigest{index, *glyph}; - fDigestForPackedGlyphID.set(digest); + fDigestForPackedGlyphID.set(glyph->getPackedID(), digest); fGlyphForIndex.push_back(glyph); return digest; } @@ -137,7 +137,7 @@ std::tuple SkScalerCache::mergeGlyphAndImage( SkPackedGlyphID toID, const SkGlyph& from) { SkAutoMutexExclusive lock{fMu}; // TODO(herb): remove finding the glyph when setting the metrics and image are separated - SkGlyphDigest* digest = fDigestForPackedGlyphID.find(toID.value()); + SkGlyphDigest* digest = fDigestForPackedGlyphID.find(toID); if (digest != nullptr) { SkGlyph* to = fGlyphForIndex[digest->index()]; size_t delta = 0; diff --git a/src/core/SkScalerCache.h b/src/core/SkScalerCache.h index d9898703cc..ba538c81fc 100644 --- a/src/core/SkScalerCache.h +++ b/src/core/SkScalerCache.h @@ -134,7 +134,8 @@ private: // SkGlyphDigest's fIndex field stores the index. This pointer provides an unchanging // reference to the SkGlyph as long as the strike is alive, and fGlyphForIndex // provides a dense index for glyphs. - SkTHashTable fDigestForPackedGlyphID SK_GUARDED_BY(fMu); + SkTHashMap + fDigestForPackedGlyphID SK_GUARDED_BY(fMu); std::vector fGlyphForIndex SK_GUARDED_BY(fMu); // so we don't grow our arrays a lot