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