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
14 #include "SkChecksum.h"
19 /* Need this to be quad-state:
22 - failed to get image, but has metrics
23 - failed to get metrics
26 typedef uint32_t PackedID;
31 GrMaskFormat fMaskFormat;
33 SkIPoint16 fAtlasLocation;
35 void init(GrGlyph::PackedID packed, const SkIRect& bounds, GrMaskFormat format) {
41 fAtlasLocation.set(0, 0);
51 int width() const { return fBounds.width(); }
52 int height() const { return fBounds.height(); }
53 bool isEmpty() const { return fBounds.isEmpty(); }
54 uint16_t glyphID() const { return UnpackID(fPackedID); }
56 ///////////////////////////////////////////////////////////////////////////
58 static inline unsigned ExtractSubPixelBitsFromFixed(SkFixed pos) {
59 // two most significant fraction bits from fixed-point
60 return (pos >> 14) & 3;
63 static inline PackedID Pack(uint16_t glyphID, SkFixed x, SkFixed y) {
64 x = ExtractSubPixelBitsFromFixed(x);
65 y = ExtractSubPixelBitsFromFixed(y);
66 return (x << 18) | (y << 16) | glyphID;
69 static inline SkFixed UnpackFixedX(PackedID packed) {
70 return ((packed >> 18) & 3) << 14;
73 static inline SkFixed UnpackFixedY(PackedID packed) {
74 return ((packed >> 16) & 3) << 14;
77 static inline uint16_t UnpackID(PackedID packed) {
78 return (uint16_t)packed;
81 static inline const GrGlyph::PackedID& GetKey(const GrGlyph& glyph) {
82 return glyph.fPackedID;
85 static inline uint32_t Hash(GrGlyph::PackedID key) {
86 return SkChecksum::Murmur3(&key, sizeof(key));