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 GrGlyph_DEFINED | 8 #ifndef GrGlyph_DEFINED |
9 #define GrGlyph_DEFINED | 9 #define GrGlyph_DEFINED |
10 | 10 |
11 #include "GrRect.h" | 11 #include "GrRect.h" |
12 #include "GrTypes.h" | 12 #include "GrTypes.h" |
13 | 13 |
14 #include "SkChecksum.h" | 14 #include "SkChecksum.h" |
15 #include "SkPath.h" | 15 #include "SkPath.h" |
16 | 16 |
17 class GrPlot; | 17 class GrPlot; |
18 | 18 |
19 /* Need this to be quad-state: | 19 /* Need this to be quad-state: |
20 - complete w/ image | 20 - complete w/ image |
21 - just metrics | 21 - just metrics |
22 - failed to get image, but has metrics | 22 - failed to get image, but has metrics |
23 - failed to get metrics | 23 - failed to get metrics |
24 */ | 24 */ |
25 struct GrGlyph { | 25 struct GrGlyph { |
26 enum MaskStyle { | |
27 kCoverage_MaskStyle, | |
28 kDistance_MaskStyle | |
29 }; | |
30 | |
31 typedef uint32_t PackedID; | 26 typedef uint32_t PackedID; |
32 | 27 |
33 GrPlot* fPlot; | 28 GrPlot* fPlot; |
34 SkPath* fPath; | 29 SkPath* fPath; |
35 PackedID fPackedID; | 30 PackedID fPackedID; |
36 GrMaskFormat fMaskFormat; | 31 GrMaskFormat fMaskFormat; |
37 GrIRect16 fBounds; | 32 GrIRect16 fBounds; |
38 SkIPoint16 fAtlasLocation; | 33 SkIPoint16 fAtlasLocation; |
39 | 34 |
40 void init(GrGlyph::PackedID packed, const SkIRect& bounds, GrMaskFormat form
at) { | 35 void init(GrGlyph::PackedID packed, const SkIRect& bounds, GrMaskFormat form
at) { |
(...skipping 17 matching lines...) Expand all Loading... |
58 bool isEmpty() const { return fBounds.isEmpty(); } | 53 bool isEmpty() const { return fBounds.isEmpty(); } |
59 uint16_t glyphID() const { return UnpackID(fPackedID); } | 54 uint16_t glyphID() const { return UnpackID(fPackedID); } |
60 | 55 |
61 /////////////////////////////////////////////////////////////////////////// | 56 /////////////////////////////////////////////////////////////////////////// |
62 | 57 |
63 static inline unsigned ExtractSubPixelBitsFromFixed(SkFixed pos) { | 58 static inline unsigned ExtractSubPixelBitsFromFixed(SkFixed pos) { |
64 // two most significant fraction bits from fixed-point | 59 // two most significant fraction bits from fixed-point |
65 return (pos >> 14) & 3; | 60 return (pos >> 14) & 3; |
66 } | 61 } |
67 | 62 |
68 static inline PackedID Pack(uint16_t glyphID, SkFixed x, SkFixed y, MaskStyl
e ms) { | 63 static inline PackedID Pack(uint16_t glyphID, SkFixed x, SkFixed y) { |
69 x = ExtractSubPixelBitsFromFixed(x); | 64 x = ExtractSubPixelBitsFromFixed(x); |
70 y = ExtractSubPixelBitsFromFixed(y); | 65 y = ExtractSubPixelBitsFromFixed(y); |
71 int dfFlag = (ms == kDistance_MaskStyle) ? 0x1 : 0x0; | 66 return (x << 18) | (y << 16) | glyphID; |
72 return (dfFlag << 20) | (x << 18) | (y << 16) | glyphID; | |
73 } | 67 } |
74 | 68 |
75 static inline SkFixed UnpackFixedX(PackedID packed) { | 69 static inline SkFixed UnpackFixedX(PackedID packed) { |
76 return ((packed >> 18) & 3) << 14; | 70 return ((packed >> 18) & 3) << 14; |
77 } | 71 } |
78 | 72 |
79 static inline SkFixed UnpackFixedY(PackedID packed) { | 73 static inline SkFixed UnpackFixedY(PackedID packed) { |
80 return ((packed >> 16) & 3) << 14; | 74 return ((packed >> 16) & 3) << 14; |
81 } | 75 } |
82 | 76 |
83 static inline MaskStyle UnpackMaskStyle(PackedID packed) { | |
84 return ((packed >> 20) & 1) ? kDistance_MaskStyle : kCoverage_MaskStyle; | |
85 } | |
86 | |
87 static inline uint16_t UnpackID(PackedID packed) { | 77 static inline uint16_t UnpackID(PackedID packed) { |
88 return (uint16_t)packed; | 78 return (uint16_t)packed; |
89 } | 79 } |
90 | 80 |
91 static inline const GrGlyph::PackedID& GetKey(const GrGlyph& glyph) { | 81 static inline const GrGlyph::PackedID& GetKey(const GrGlyph& glyph) { |
92 return glyph.fPackedID; | 82 return glyph.fPackedID; |
93 } | 83 } |
94 | 84 |
95 static inline uint32_t Hash(GrGlyph::PackedID key) { | 85 static inline uint32_t Hash(GrGlyph::PackedID key) { |
96 return SkChecksum::Murmur3(&key, sizeof(key)); | 86 return SkChecksum::Murmur3(&key, sizeof(key)); |
97 } | 87 } |
98 }; | 88 }; |
99 | 89 |
100 #endif | 90 #endif |
OLD | NEW |