michael@0: /* michael@0: * Copyright 2010 Google Inc. michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: #ifndef GrGlyph_DEFINED michael@0: #define GrGlyph_DEFINED michael@0: michael@0: #include "GrRect.h" michael@0: #include "SkPath.h" michael@0: michael@0: class GrPlot; michael@0: michael@0: /* Need this to be quad-state: michael@0: - complete w/ image michael@0: - just metrics michael@0: - failed to get image, but has metrics michael@0: - failed to get metrics michael@0: */ michael@0: struct GrGlyph { michael@0: typedef uint32_t PackedID; michael@0: michael@0: GrPlot* fPlot; michael@0: SkPath* fPath; michael@0: PackedID fPackedID; michael@0: GrIRect16 fBounds; michael@0: GrIPoint16 fAtlasLocation; michael@0: michael@0: void init(GrGlyph::PackedID packed, const SkIRect& bounds) { michael@0: fPlot = NULL; michael@0: fPath = NULL; michael@0: fPackedID = packed; michael@0: fBounds.set(bounds); michael@0: fAtlasLocation.set(0, 0); michael@0: } michael@0: michael@0: void free() { michael@0: if (fPath) { michael@0: delete fPath; michael@0: fPath = NULL; michael@0: } michael@0: } michael@0: michael@0: int width() const { return fBounds.width(); } michael@0: int height() const { return fBounds.height(); } michael@0: bool isEmpty() const { return fBounds.isEmpty(); } michael@0: uint16_t glyphID() const { return UnpackID(fPackedID); } michael@0: michael@0: /////////////////////////////////////////////////////////////////////////// michael@0: michael@0: static inline unsigned ExtractSubPixelBitsFromFixed(GrFixed pos) { michael@0: // two most significant fraction bits from fixed-point michael@0: return (pos >> 14) & 3; michael@0: } michael@0: michael@0: static inline PackedID Pack(uint16_t glyphID, GrFixed x, GrFixed y) { michael@0: x = ExtractSubPixelBitsFromFixed(x); michael@0: y = ExtractSubPixelBitsFromFixed(y); michael@0: return (x << 18) | (y << 16) | glyphID; michael@0: } michael@0: michael@0: static inline GrFixed UnpackFixedX(PackedID packed) { michael@0: return ((packed >> 18) & 3) << 14; michael@0: } michael@0: michael@0: static inline GrFixed UnpackFixedY(PackedID packed) { michael@0: return ((packed >> 16) & 3) << 14; michael@0: } michael@0: michael@0: static inline uint16_t UnpackID(PackedID packed) { michael@0: return (uint16_t)packed; michael@0: } michael@0: }; michael@0: michael@0: michael@0: #endif