diff options
author | 2014-07-11 19:45:16 -0700 | |
---|---|---|
committer | 2014-07-11 19:45:16 -0700 | |
commit | 733f5f5dbca10fc6385ec3c77b3e9ff78227dac7 (patch) | |
tree | d9ffdb538bf85fa2d56e977d5081e32e7f4f3ee7 /include/gpu/GrFontScaler.h | |
parent | 93de7a27e05004e1ff3171b43d89d36890f9f868 (diff) |
Refactor SkGrFontScaler and SkGrFontKey into non-virtual versions.
This is a pre-cleanup for another change, but has the side benefit of making
the code simpler in general.
No perf increase, despite removing virtual functions.
R=bsalomon@google.com, egdaniel@google.com
Author: jvanverth@google.com
Review URL: https://codereview.chromium.org/385263002
Diffstat (limited to 'include/gpu/GrFontScaler.h')
-rw-r--r-- | include/gpu/GrFontScaler.h | 79 |
1 files changed, 60 insertions, 19 deletions
diff --git a/include/gpu/GrFontScaler.h b/include/gpu/GrFontScaler.h index 0132d51304..d90708de8f 100644 --- a/include/gpu/GrFontScaler.h +++ b/include/gpu/GrFontScaler.h @@ -9,35 +9,76 @@ #define GrFontScaler_DEFINED #include "GrGlyph.h" -#include "GrKey.h" +#include "GrTypes.h" + +#include "SkDescriptor.h" class SkPath; -/** - * This is a virtual base class which Gr's interface to the host platform's - * font scaler. +/* + * Wrapper class to turn a font cache descriptor into a key + * for GrFontScaler-related lookups + */ +class GrFontDescKey : public SkRefCnt { +public: + SK_DECLARE_INST_COUNT(SkGrDescKey) + + typedef uint32_t Hash; + + explicit GrFontDescKey(const SkDescriptor& desc); + virtual ~GrFontDescKey(); + + Hash getHash() const { return fHash; } + + bool operator<(const GrFontDescKey& rh) const { + return fHash < rh.fHash || (fHash == rh.fHash && this->lt(rh)); + } + bool operator==(const GrFontDescKey& rh) const { + return fHash == rh.fHash && this->eq(rh); + } + +private: + // helper functions for comparisons + bool lt(const GrFontDescKey& rh) const; + bool eq(const GrFontDescKey& rh) const; + + SkDescriptor* fDesc; + enum { + kMaxStorageInts = 16 + }; + uint32_t fStorage[kMaxStorageInts]; + const Hash fHash; + + typedef SkRefCnt INHERITED; +}; + +/* + * This is Gr's interface to the host platform's font scaler. * - * The client is responsible for subclassing, and instantiating this. The - * instance is created for a specific font+size+matrix. + * The client is responsible for instantiating this. The instance is created + * for a specific font+size+matrix. */ class GrFontScaler : public SkRefCnt { public: SK_DECLARE_INST_COUNT(GrFontScaler) - virtual const GrKey* getKey() = 0; - virtual GrMaskFormat getMaskFormat() = 0; - virtual bool getPackedGlyphBounds(GrGlyph::PackedID, SkIRect* bounds) = 0; - virtual bool getPackedGlyphImage(GrGlyph::PackedID, int width, int height, - int rowBytes, void* image) = 0; - // get bounds for distance field associated with packed ID - virtual bool getPackedGlyphDFBounds(GrGlyph::PackedID, SkIRect* bounds) = 0; - // copies distance field bytes into pre-allocated dfImage - // (should be width*height bytes in size) - virtual bool getPackedGlyphDFImage(GrGlyph::PackedID, int width, int height, - void* dfImage) = 0; - virtual bool getGlyphPath(uint16_t glyphID, SkPath*) = 0; - + explicit GrFontScaler(SkGlyphCache* strike); + virtual ~GrFontScaler(); + + const GrFontDescKey* getKey(); + GrMaskFormat getMaskFormat(); + bool getPackedGlyphBounds(GrGlyph::PackedID, SkIRect* bounds); + bool getPackedGlyphImage(GrGlyph::PackedID, int width, int height, + int rowBytes, void* image); + bool getPackedGlyphDFBounds(GrGlyph::PackedID, SkIRect* bounds); + bool getPackedGlyphDFImage(GrGlyph::PackedID, int width, int height, + void* image); + bool getGlyphPath(uint16_t glyphID, SkPath*); + private: + SkGlyphCache* fStrike; + GrFontDescKey* fKey; + typedef SkRefCnt INHERITED; }; |