OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2010 Google Inc. | 2 * Copyright 2010 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef GrFontScaler_DEFINED | 8 #ifndef GrFontScaler_DEFINED |
9 #define GrFontScaler_DEFINED | 9 #define GrFontScaler_DEFINED |
10 | 10 |
11 #include "GrGlyph.h" | 11 #include "GrGlyph.h" |
12 #include "GrKey.h" | 12 #include "GrTypes.h" |
| 13 |
| 14 #include "SkDescriptor.h" |
13 | 15 |
14 class SkPath; | 16 class SkPath; |
15 | 17 |
16 /** | 18 /* |
17 * This is a virtual base class which Gr's interface to the host platform's | 19 * Wrapper class to turn a font cache descriptor into a key |
18 * font scaler. | 20 * for GrFontScaler-related lookups |
| 21 */ |
| 22 class GrFontDescKey : public SkRefCnt { |
| 23 public: |
| 24 SK_DECLARE_INST_COUNT(SkGrDescKey) |
| 25 |
| 26 typedef uint32_t Hash; |
| 27 |
| 28 explicit GrFontDescKey(const SkDescriptor& desc); |
| 29 virtual ~GrFontDescKey(); |
| 30 |
| 31 Hash getHash() const { return fHash; } |
| 32 |
| 33 bool operator<(const GrFontDescKey& rh) const { |
| 34 return fHash < rh.fHash || (fHash == rh.fHash && this->lt(rh)); |
| 35 } |
| 36 bool operator==(const GrFontDescKey& rh) const { |
| 37 return fHash == rh.fHash && this->eq(rh); |
| 38 } |
| 39 |
| 40 private: |
| 41 // helper functions for comparisons |
| 42 bool lt(const GrFontDescKey& rh) const; |
| 43 bool eq(const GrFontDescKey& rh) const; |
| 44 |
| 45 SkDescriptor* fDesc; |
| 46 enum { |
| 47 kMaxStorageInts = 16 |
| 48 }; |
| 49 uint32_t fStorage[kMaxStorageInts]; |
| 50 const Hash fHash; |
| 51 |
| 52 typedef SkRefCnt INHERITED; |
| 53 }; |
| 54 |
| 55 /* |
| 56 * This is Gr's interface to the host platform's font scaler. |
19 * | 57 * |
20 * The client is responsible for subclassing, and instantiating this. The | 58 * The client is responsible for instantiating this. The instance is created |
21 * instance is created for a specific font+size+matrix. | 59 * for a specific font+size+matrix. |
22 */ | 60 */ |
23 class GrFontScaler : public SkRefCnt { | 61 class GrFontScaler : public SkRefCnt { |
24 public: | 62 public: |
25 SK_DECLARE_INST_COUNT(GrFontScaler) | 63 SK_DECLARE_INST_COUNT(GrFontScaler) |
26 | 64 |
27 virtual const GrKey* getKey() = 0; | 65 explicit GrFontScaler(SkGlyphCache* strike); |
28 virtual GrMaskFormat getMaskFormat() = 0; | 66 virtual ~GrFontScaler(); |
29 virtual bool getPackedGlyphBounds(GrGlyph::PackedID, SkIRect* bounds) = 0; | 67 |
30 virtual bool getPackedGlyphImage(GrGlyph::PackedID, int width, int height, | 68 const GrFontDescKey* getKey(); |
31 int rowBytes, void* image) = 0; | 69 GrMaskFormat getMaskFormat(); |
32 // get bounds for distance field associated with packed ID | 70 bool getPackedGlyphBounds(GrGlyph::PackedID, SkIRect* bounds); |
33 virtual bool getPackedGlyphDFBounds(GrGlyph::PackedID, SkIRect* bounds) = 0; | 71 bool getPackedGlyphImage(GrGlyph::PackedID, int width, int height, |
34 // copies distance field bytes into pre-allocated dfImage | 72 int rowBytes, void* image); |
35 // (should be width*height bytes in size) | 73 bool getPackedGlyphDFBounds(GrGlyph::PackedID, SkIRect* bounds); |
36 virtual bool getPackedGlyphDFImage(GrGlyph::PackedID, int width, int height, | 74 bool getPackedGlyphDFImage(GrGlyph::PackedID, int width, int height, |
37 void* dfImage) = 0; | 75 void* image); |
38 virtual bool getGlyphPath(uint16_t glyphID, SkPath*) = 0; | 76 bool getGlyphPath(uint16_t glyphID, SkPath*); |
39 | 77 |
40 private: | 78 private: |
| 79 SkGlyphCache* fStrike; |
| 80 GrFontDescKey* fKey; |
| 81 |
41 typedef SkRefCnt INHERITED; | 82 typedef SkRefCnt INHERITED; |
42 }; | 83 }; |
43 | 84 |
44 #endif | 85 #endif |
OLD | NEW |