2 * Copyright 2010 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #ifndef GrGlyph_DEFINED
9 #define GrGlyph_DEFINED
16 /* Need this to be quad-state:
19 - failed to get image, but has metrics
20 - failed to get metrics
23 typedef uint32_t PackedID;
29 GrIPoint16 fAtlasLocation;
31 void init(GrGlyph::PackedID packed, const SkIRect& bounds) {
36 fAtlasLocation.set(0, 0);
46 int width() const { return fBounds.width(); }
47 int height() const { return fBounds.height(); }
48 bool isEmpty() const { return fBounds.isEmpty(); }
49 uint16_t glyphID() const { return UnpackID(fPackedID); }
51 ///////////////////////////////////////////////////////////////////////////
53 static inline unsigned ExtractSubPixelBitsFromFixed(SkFixed pos) {
54 // two most significant fraction bits from fixed-point
55 return (pos >> 14) & 3;
58 static inline PackedID Pack(uint16_t glyphID, SkFixed x, SkFixed y) {
59 x = ExtractSubPixelBitsFromFixed(x);
60 y = ExtractSubPixelBitsFromFixed(y);
61 return (x << 18) | (y << 16) | glyphID;
64 static inline SkFixed UnpackFixedX(PackedID packed) {
65 return ((packed >> 18) & 3) << 14;
68 static inline SkFixed UnpackFixedY(PackedID packed) {
69 return ((packed >> 16) & 3) << 14;
72 static inline uint16_t UnpackID(PackedID packed) {
73 return (uint16_t)packed;