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

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: Fix one last type 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
Index: src/core/SkGlyphCache.h
diff --git a/src/core/SkGlyphCache.h b/src/core/SkGlyphCache.h
index f3a946c7d3e0470811074557a572cab18ebba62e..e51bda0f59f51eb37b9fc9deea4084dd9990a611 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
@@ -183,7 +179,7 @@ private:
struct CharGlyphRec {
uint32_t fID; // unichar + subpixel
- uint16_t fGlyphIndex;
+ uint32_t fGlyphAndPositionID;
};
struct AuxProcRec {
@@ -199,23 +195,19 @@ 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* lookupByGlyphAndPositionID(uint32_t glyphAndPositionID, 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(uint32_t glyphAndPositionID, 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;
- }
void invokeAndRemoveAuxProcs();
@@ -226,28 +218,16 @@ private:
SkScalerContext* 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, uint32_t, SkGlyph::GlyphHashTraits> 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;
- // 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> fCharToGlyphAndPositionIDHash;
// 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
-
AuxProcRec* fAuxProcList;
};
« no previous file with comments | « src/core/SkGlyph.h ('k') | src/core/SkGlyphCache.cpp » ('j') | src/core/SkGlyphCache.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698