Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(132)

Unified Diff: src/core/SkGlyphCache.h

Issue 1216983003: Move the GlyphCache to use a hash table instead of doing its own ad-hoc (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Address mtklein's comments Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/core/SkGlyph.h ('k') | src/core/SkGlyphCache.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkGlyphCache.h
diff --git a/src/core/SkGlyphCache.h b/src/core/SkGlyphCache.h
index f3a946c7d3e0470811074557a572cab18ebba62e..1c985bf6715070bd1ff520535919aec3786429d2 100644
--- a/src/core/SkGlyphCache.h
+++ b/src/core/SkGlyphCache.h
@@ -8,10 +8,10 @@
#define SkGlyphCache_DEFINED
#include "SkBitmap.h"
-#include "SkChecksum.h"
#include "SkChunkAlloc.h"
#include "SkDescriptor.h"
#include "SkGlyph.h"
+#include "SkTHash.h"
#include "SkScalerContext.h"
#include "SkTemplates.h"
#include "SkTDArray.h"
@@ -20,10 +20,6 @@ class SkPaint;
class SkGlyphCache_Globals;
-// Enable this locally to add stats for hash-table hit rates. It also extends the dump() output
-// to show those stats.
-//#define SK_GLYPHCACHE_TRACK_HASH_STATS
-
/** \class SkGlyphCache
This class represents a strike: a specific combination of typeface, size, matrix, etc., and
@@ -181,9 +177,12 @@ private:
kHashMask = kHashCount - 1
};
+ typedef uint32_t PackedGlyphID; // glyph-index + subpixel-pos
+ typedef uint32_t PackedUnicharID; // unichar + subpixel-pos
+
struct CharGlyphRec {
- uint32_t fID; // unichar + subpixel
- uint16_t fGlyphIndex;
+ PackedUnicharID fPackedUnicharID;
+ PackedGlyphID fPackedGlyphID;
};
struct AuxProcRec {
@@ -199,56 +198,42 @@ private:
// Return the SkGlyph* associated with MakeID. The id parameter is the
// combined glyph/x/y id generated by MakeID. If it is just a glyph id
// then x and y are assumed to be zero.
- SkGlyph* lookupByCombinedID(uint32_t id, MetricsType type);
+ SkGlyph* lookupByPackedGlyphID(PackedGlyphID packedGlyphID, MetricsType type);
// Return a SkGlyph* associated with unicode id and position x and y.
SkGlyph* lookupByChar(SkUnichar id, MetricsType type, SkFixed x = 0, SkFixed y = 0);
- // Return the index of id in the fGlyphArray. If it does not exist,
- // create a new one using MetricsType.
- uint16_t lookupMetrics(uint32_t id, MetricsType type);
+ // Return a new SkGlyph for the glyph ID and subpixel position id. Limit the amount
+ // of work
+ // using type.
+ SkGlyph* allocateNewGlyph(PackedGlyphID packedGlyphID, MetricsType type);
+
static bool DetachProc(const SkGlyphCache*, void*) { return true; }
// The id arg is a combined id generated by MakeID.
- CharGlyphRec* getCharGlyphRec(uint32_t id);
- void adjustCaches(int insertion_index);
-
- static inline unsigned ID2HashIndex(uint32_t h) {
- return SkChecksum::CheapMix(h) & kHashMask;
- }
+ CharGlyphRec* getCharGlyphRec(PackedUnicharID id);
void invokeAndRemoveAuxProcs();
inline static SkGlyphCache* FindTail(SkGlyphCache* head);
- SkGlyphCache* fNext, *fPrev;
- SkDescriptor* fDesc;
- SkScalerContext* fScalerContext;
- SkPaint::FontMetrics fFontMetrics;
+ SkGlyphCache* fNext;
+ SkGlyphCache* fPrev;
+ SkDescriptor* const fDesc;
+ SkScalerContext* const fScalerContext;
+ SkPaint::FontMetrics fFontMetrics;
- // A quick lookup to avoid the binary search looking for glyphs in fGlyphArray.
- uint16_t fGlyphHash[kHashCount];
+ // Map from a combined GlyphID and sub-pixel position to a SkGlyph.
+ SkTHashTable<SkGlyph, PackedGlyphID, SkGlyph::HashTraits> fGlyphMap;
- // Contains the SkGlyphs that are used by fGlyphHash and fCharToGlyphHash. The ~0 element is
- // reserved for a sentinel SkGlyph that reduces the logic to check for collisions in the hash
- // arrays. The ~0 element has an fID of SkGlyph::kImpossibleID which never matches any
- // combined id generated for a char or a glyph.
- SkTDArray<SkGlyph> fGlyphArray;
- SkChunkAlloc fGlyphAlloc;
+ SkChunkAlloc fGlyphAlloc;
- // no reason to use the same kHashCount as fGlyphHash, but we do for now
- // Dynamically allocated when chars are encountered.
- SkAutoTArray<CharGlyphRec> fCharToGlyphHash;
+ SkAutoTArray<CharGlyphRec> fPackedUnicharIDToPackedGlyphID;
// used to track (approx) how much ram is tied-up in this cache
- size_t fMemoryUsed;
-
-#ifdef SK_GLYPHCACHE_TRACK_HASH_STATS
- int fHashHitCount;
- int fHashMissCount;
-#endif
+ size_t fMemoryUsed;
- AuxProcRec* fAuxProcList;
+ AuxProcRec* fAuxProcList;
};
class SkAutoGlyphCacheBase {
« no previous file with comments | « src/core/SkGlyph.h ('k') | src/core/SkGlyphCache.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698