reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 2 | * Copyright 2010 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 8 | #ifndef GrFontScaler_DEFINED |
| 9 | #define GrFontScaler_DEFINED |
| 10 | |
| 11 | #include "GrGlyph.h" |
jvanverth | 733f5f5 | 2014-07-11 19:45:16 -0700 | [diff] [blame] | 12 | #include "GrTypes.h" |
| 13 | |
| 14 | #include "SkDescriptor.h" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 15 | |
reed@google.com | 07f3ee1 | 2011-05-16 17:21:57 +0000 | [diff] [blame] | 16 | class SkPath; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 17 | |
jvanverth | 733f5f5 | 2014-07-11 19:45:16 -0700 | [diff] [blame] | 18 | /* |
| 19 | * Wrapper class to turn a font cache descriptor into a key |
| 20 | * for GrFontScaler-related lookups |
| 21 | */ |
| 22 | class GrFontDescKey : public SkRefCnt { |
| 23 | public: |
bungeman | d6aeb6d | 2014-07-25 11:52:47 -0700 | [diff] [blame] | 24 | SK_DECLARE_INST_COUNT(GrFontDescKey) |
jvanverth | 733f5f5 | 2014-07-11 19:45:16 -0700 | [diff] [blame] | 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. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 57 | * |
jvanverth | 733f5f5 | 2014-07-11 19:45:16 -0700 | [diff] [blame] | 58 | * The client is responsible for instantiating this. The instance is created |
| 59 | * for a specific font+size+matrix. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 60 | */ |
commit-bot@chromium.org | a4de8c2 | 2013-09-09 13:38:37 +0000 | [diff] [blame] | 61 | class GrFontScaler : public SkRefCnt { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 62 | public: |
reed@google.com | fa35e3d | 2012-06-26 20:16:17 +0000 | [diff] [blame] | 63 | SK_DECLARE_INST_COUNT(GrFontScaler) |
| 64 | |
jvanverth | 733f5f5 | 2014-07-11 19:45:16 -0700 | [diff] [blame] | 65 | explicit GrFontScaler(SkGlyphCache* strike); |
| 66 | virtual ~GrFontScaler(); |
| 67 | |
| 68 | const GrFontDescKey* getKey(); |
jvanverth | 294c326 | 2014-10-10 11:36:12 -0700 | [diff] [blame] | 69 | GrMaskFormat getMaskFormat() const; |
| 70 | GrMaskFormat getPackedGlyphMaskFormat(GrGlyph::PackedID) const; |
jvanverth | 733f5f5 | 2014-07-11 19:45:16 -0700 | [diff] [blame] | 71 | bool getPackedGlyphBounds(GrGlyph::PackedID, SkIRect* bounds); |
| 72 | bool getPackedGlyphImage(GrGlyph::PackedID, int width, int height, |
| 73 | int rowBytes, void* image); |
| 74 | bool getPackedGlyphDFBounds(GrGlyph::PackedID, SkIRect* bounds); |
| 75 | bool getPackedGlyphDFImage(GrGlyph::PackedID, int width, int height, |
| 76 | void* image); |
| 77 | bool getGlyphPath(uint16_t glyphID, SkPath*); |
| 78 | |
reed@google.com | fa35e3d | 2012-06-26 20:16:17 +0000 | [diff] [blame] | 79 | private: |
jvanverth | 733f5f5 | 2014-07-11 19:45:16 -0700 | [diff] [blame] | 80 | SkGlyphCache* fStrike; |
| 81 | GrFontDescKey* fKey; |
| 82 | |
commit-bot@chromium.org | a4de8c2 | 2013-09-09 13:38:37 +0000 | [diff] [blame] | 83 | typedef SkRefCnt INHERITED; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 84 | }; |
| 85 | |
| 86 | #endif |