move the SkPackedGlyphID out of SkGlyphDigest
Move the packed glyph id out of the digest to make room for the glyph dimensions. Use SkTHashMap instead of SkTHashTable. Add a Hash function struct to SkPackedGlyphID. Bug: skia:13192 Change-Id: I1b59b47cb292402bf8b8e892b3b37edad9ecb9ea Reviewed-on: https://skia-review.googlesource.com/c/skia/+/529132 Reviewed-by: Ben Wagner <bungeman@google.com> Commit-Queue: Herb Derby <herb@google.com>
This commit is contained in:
parent
e853b8d2b5
commit
24a1344800
@ -291,7 +291,7 @@ private:
|
|||||||
LowerRangeBitVector fSentLowGlyphIDs;
|
LowerRangeBitVector fSentLowGlyphIDs;
|
||||||
|
|
||||||
// The masks and paths that currently reside in the GPU process.
|
// The masks and paths that currently reside in the GPU process.
|
||||||
SkTHashTable<SkGlyphDigest, uint32_t, SkGlyphDigest> fSentGlyphs;
|
SkTHashMap<SkPackedGlyphID, SkGlyphDigest, SkPackedGlyphID::Hash> fSentGlyphs;
|
||||||
SkTHashTable<PathSummary, SkPackedGlyphID, PathSummaryTraits> fSentPaths;
|
SkTHashTable<PathSummary, SkPackedGlyphID, PathSummaryTraits> fSentPaths;
|
||||||
SkTHashTable<DrawableSummary, SkGlyphID, DrawableSummaryTraits> fSentDrawables;
|
SkTHashTable<DrawableSummary, SkGlyphID, DrawableSummaryTraits> fSentDrawables;
|
||||||
|
|
||||||
@ -438,7 +438,7 @@ void RemoteStrike::commonMaskLoop(
|
|||||||
SkDrawableGlyphBuffer* accepted, SkSourceGlyphBuffer* rejected, Rejector&& reject) {
|
SkDrawableGlyphBuffer* accepted, SkSourceGlyphBuffer* rejected, Rejector&& reject) {
|
||||||
accepted->forEachInput(
|
accepted->forEachInput(
|
||||||
[&](size_t i, SkPackedGlyphID packedID, SkPoint position) {
|
[&](size_t i, SkPackedGlyphID packedID, SkPoint position) {
|
||||||
SkGlyphDigest* digest = fSentGlyphs.find(packedID.value());
|
SkGlyphDigest* digest = fSentGlyphs.find(packedID);
|
||||||
if (digest == nullptr) {
|
if (digest == nullptr) {
|
||||||
// Put the new SkGlyph in the glyphs to send.
|
// Put the new SkGlyph in the glyphs to send.
|
||||||
this->ensureScalerContext();
|
this->ensureScalerContext();
|
||||||
@ -446,7 +446,7 @@ void RemoteStrike::commonMaskLoop(
|
|||||||
SkGlyph* glyph = &fMasksToSend.back();
|
SkGlyph* glyph = &fMasksToSend.back();
|
||||||
|
|
||||||
SkGlyphDigest newDigest{0, *glyph};
|
SkGlyphDigest newDigest{0, *glyph};
|
||||||
digest = fSentGlyphs.set(newDigest);
|
digest = fSentGlyphs.set(packedID, newDigest);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reject things that are too big.
|
// Reject things that are too big.
|
||||||
@ -462,14 +462,14 @@ void RemoteStrike::prepareForMaskDrawing(
|
|||||||
SkPackedGlyphID packedID = variant.packedID();
|
SkPackedGlyphID packedID = variant.packedID();
|
||||||
if (fSentLowGlyphIDs.test(packedID)) {
|
if (fSentLowGlyphIDs.test(packedID)) {
|
||||||
#ifdef SK_DEBUG
|
#ifdef SK_DEBUG
|
||||||
SkGlyphDigest* digest = fSentGlyphs.find(packedID.value());
|
SkGlyphDigest* digest = fSentGlyphs.find(packedID);
|
||||||
SkASSERT(digest != nullptr);
|
SkASSERT(digest != nullptr);
|
||||||
SkASSERT(digest->canDrawAsMask() && digest->canDrawAsSDFT());
|
SkASSERT(digest->canDrawAsMask() && digest->canDrawAsSDFT());
|
||||||
#endif
|
#endif
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
SkGlyphDigest* digest = fSentGlyphs.find(packedID.value());
|
SkGlyphDigest* digest = fSentGlyphs.find(packedID);
|
||||||
if (digest == nullptr) {
|
if (digest == nullptr) {
|
||||||
|
|
||||||
// Put the new SkGlyph in the glyphs to send.
|
// Put the new SkGlyph in the glyphs to send.
|
||||||
@ -479,7 +479,7 @@ void RemoteStrike::prepareForMaskDrawing(
|
|||||||
|
|
||||||
SkGlyphDigest newDigest{0, *glyph};
|
SkGlyphDigest newDigest{0, *glyph};
|
||||||
|
|
||||||
digest = fSentGlyphs.set(newDigest);
|
digest = fSentGlyphs.set(packedID, newDigest);
|
||||||
|
|
||||||
if (digest->canDrawAsMask() && digest->canDrawAsSDFT()) {
|
if (digest->canDrawAsMask() && digest->canDrawAsSDFT()) {
|
||||||
fSentLowGlyphIDs.setIfLower(packedID);
|
fSentLowGlyphIDs.setIfLower(packedID);
|
||||||
|
@ -397,8 +397,7 @@ void SkGlyph::ensureIntercepts(const SkScalar* bounds, SkScalar scale, SkScalar
|
|||||||
}
|
}
|
||||||
|
|
||||||
SkGlyphDigest::SkGlyphDigest(size_t index, const SkGlyph& glyph)
|
SkGlyphDigest::SkGlyphDigest(size_t index, const SkGlyph& glyph)
|
||||||
: fPackedGlyphID{glyph.getPackedID().value()}
|
: fIndex{SkTo<uint32_t>(index)}
|
||||||
, fIndex{SkTo<uint32_t>(index)}
|
|
||||||
, fIsEmpty(glyph.isEmpty())
|
, fIsEmpty(glyph.isEmpty())
|
||||||
, fIsColor(glyph.isColor())
|
, fIsColor(glyph.isColor())
|
||||||
, fCanDrawAsMask{SkStrikeForGPU::CanDrawAsMask(glyph)}
|
, fCanDrawAsMask{SkStrikeForGPU::CanDrawAsMask(glyph)}
|
||||||
|
@ -46,11 +46,17 @@ struct SkPackedGlyphID {
|
|||||||
kFixedPointSubPixelPosBits = kFixedPointBinaryPointPos - kSubPixelPosLen,
|
kFixedPointSubPixelPosBits = kFixedPointBinaryPointPos - kSubPixelPosLen,
|
||||||
};
|
};
|
||||||
|
|
||||||
inline static constexpr SkScalar kSubpixelRound =
|
inline static const constexpr SkScalar kSubpixelRound =
|
||||||
1.f / (1u << (SkPackedGlyphID::kSubPixelPosLen + 1));
|
1.f / (1u << (SkPackedGlyphID::kSubPixelPosLen + 1));
|
||||||
|
|
||||||
inline static constexpr SkIPoint kXYFieldMask{kSubPixelPosMask << kSubPixelX,
|
inline static const constexpr SkIPoint kXYFieldMask{kSubPixelPosMask << kSubPixelX,
|
||||||
kSubPixelPosMask << kSubPixelY};
|
kSubPixelPosMask << kSubPixelY};
|
||||||
|
|
||||||
|
struct Hash {
|
||||||
|
uint32_t operator() (SkPackedGlyphID packedID) const {
|
||||||
|
return packedID.hash();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
constexpr explicit SkPackedGlyphID(SkGlyphID glyphID)
|
constexpr explicit SkPackedGlyphID(SkGlyphID glyphID)
|
||||||
: fID{(uint32_t)glyphID << kGlyphID} { }
|
: fID{(uint32_t)glyphID << kGlyphID} { }
|
||||||
@ -256,20 +262,10 @@ public:
|
|||||||
bool isColor() const {return fIsColor; }
|
bool isColor() const {return fIsColor; }
|
||||||
bool canDrawAsMask() const {return fCanDrawAsMask;}
|
bool canDrawAsMask() const {return fCanDrawAsMask;}
|
||||||
bool canDrawAsSDFT() const {return fCanDrawAsSDFT;}
|
bool canDrawAsSDFT() const {return fCanDrawAsSDFT;}
|
||||||
uint32_t packedGlyphID() const {return fPackedGlyphID;}
|
|
||||||
uint16_t maxDimension() const {return fMaxDimension; }
|
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:
|
private:
|
||||||
static_assert(SkPackedGlyphID::kEndData == 20);
|
static_assert(SkPackedGlyphID::kEndData == 20);
|
||||||
uint64_t fPackedGlyphID : SkPackedGlyphID::kEndData;
|
|
||||||
uint64_t fIndex : SkPackedGlyphID::kEndData;
|
uint64_t fIndex : SkPackedGlyphID::kEndData;
|
||||||
uint64_t fIsEmpty : 1;
|
uint64_t fIsEmpty : 1;
|
||||||
uint64_t fIsColor : 1;
|
uint64_t fIsColor : 1;
|
||||||
|
@ -41,7 +41,7 @@ std::tuple<SkGlyph*, size_t> SkScalerCache::glyph(SkPackedGlyphID packedGlyphID)
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::tuple<SkGlyphDigest, size_t> SkScalerCache::digest(SkPackedGlyphID packedGlyphID) {
|
std::tuple<SkGlyphDigest, size_t> SkScalerCache::digest(SkPackedGlyphID packedGlyphID) {
|
||||||
SkGlyphDigest* digest = fDigestForPackedGlyphID.find(packedGlyphID.value());
|
SkGlyphDigest* digest = fDigestForPackedGlyphID.find(packedGlyphID);
|
||||||
|
|
||||||
if (digest != nullptr) {
|
if (digest != nullptr) {
|
||||||
return {*digest, 0};
|
return {*digest, 0};
|
||||||
@ -54,7 +54,7 @@ std::tuple<SkGlyphDigest, size_t> SkScalerCache::digest(SkPackedGlyphID packedGl
|
|||||||
SkGlyphDigest SkScalerCache::addGlyph(SkGlyph* glyph) {
|
SkGlyphDigest SkScalerCache::addGlyph(SkGlyph* glyph) {
|
||||||
size_t index = fGlyphForIndex.size();
|
size_t index = fGlyphForIndex.size();
|
||||||
SkGlyphDigest digest = SkGlyphDigest{index, *glyph};
|
SkGlyphDigest digest = SkGlyphDigest{index, *glyph};
|
||||||
fDigestForPackedGlyphID.set(digest);
|
fDigestForPackedGlyphID.set(glyph->getPackedID(), digest);
|
||||||
fGlyphForIndex.push_back(glyph);
|
fGlyphForIndex.push_back(glyph);
|
||||||
return digest;
|
return digest;
|
||||||
}
|
}
|
||||||
@ -137,7 +137,7 @@ std::tuple<SkGlyph*, size_t> SkScalerCache::mergeGlyphAndImage(
|
|||||||
SkPackedGlyphID toID, const SkGlyph& from) {
|
SkPackedGlyphID toID, const SkGlyph& from) {
|
||||||
SkAutoMutexExclusive lock{fMu};
|
SkAutoMutexExclusive lock{fMu};
|
||||||
// TODO(herb): remove finding the glyph when setting the metrics and image are separated
|
// 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) {
|
if (digest != nullptr) {
|
||||||
SkGlyph* to = fGlyphForIndex[digest->index()];
|
SkGlyph* to = fGlyphForIndex[digest->index()];
|
||||||
size_t delta = 0;
|
size_t delta = 0;
|
||||||
|
@ -134,7 +134,8 @@ private:
|
|||||||
// SkGlyphDigest's fIndex field stores the index. This pointer provides an unchanging
|
// 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
|
// reference to the SkGlyph as long as the strike is alive, and fGlyphForIndex
|
||||||
// provides a dense index for glyphs.
|
// provides a dense index for glyphs.
|
||||||
SkTHashTable<SkGlyphDigest, uint32_t, SkGlyphDigest> fDigestForPackedGlyphID SK_GUARDED_BY(fMu);
|
SkTHashMap<SkPackedGlyphID, SkGlyphDigest, SkPackedGlyphID::Hash>
|
||||||
|
fDigestForPackedGlyphID SK_GUARDED_BY(fMu);
|
||||||
std::vector<SkGlyph*> fGlyphForIndex SK_GUARDED_BY(fMu);
|
std::vector<SkGlyph*> fGlyphForIndex SK_GUARDED_BY(fMu);
|
||||||
|
|
||||||
// so we don't grow our arrays a lot
|
// so we don't grow our arrays a lot
|
||||||
|
Loading…
Reference in New Issue
Block a user