blob: 4945f2a58a750b31da74bc355bb2c65ec47bae67 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
reed@google.comac10a2d2010-12-22 21:39:39 +00002/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00003 * Copyright 2010 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
reed@google.comac10a2d2010-12-22 21:39:39 +00007 */
8
9
epoger@google.comec3ed6a2011-07-28 14:26:00 +000010
reed@google.comac10a2d2010-12-22 21:39:39 +000011#ifndef GrGlyph_DEFINED
12#define GrGlyph_DEFINED
13
reed@google.comac10a2d2010-12-22 21:39:39 +000014#include "GrRect.h"
bsalomon@google.com8d033a12012-04-27 15:52:53 +000015#include "SkPath.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000016
17class GrAtlas;
18
19/* Need this to be quad-state:
20 - complete w/ image
21 - just metrics
22 - failed to get image, but has metrics
23 - failed to get metrics
24 */
25struct GrGlyph {
26 typedef uint32_t PackedID;
27
28 GrAtlas* fAtlas;
bsalomon@google.com8d033a12012-04-27 15:52:53 +000029 SkPath* fPath;
reed@google.comac10a2d2010-12-22 21:39:39 +000030 PackedID fPackedID;
31 GrIRect16 fBounds;
32 GrIPoint16 fAtlasLocation;
33
34 void init(GrGlyph::PackedID packed, const GrIRect& bounds) {
35 fAtlas = NULL;
36 fPath = NULL;
37 fPackedID = packed;
38 fBounds.set(bounds);
39 fAtlasLocation.set(0, 0);
40 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +000041
reed@google.comac10a2d2010-12-22 21:39:39 +000042 void free() {
43 if (fPath) {
44 delete fPath;
45 fPath = NULL;
46 }
47 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +000048
reed@google.comac10a2d2010-12-22 21:39:39 +000049 int width() const { return fBounds.width(); }
50 int height() const { return fBounds.height(); }
51 bool isEmpty() const { return fBounds.isEmpty(); }
52 uint16_t glyphID() const { return UnpackID(fPackedID); }
53
54 ///////////////////////////////////////////////////////////////////////////
rmistry@google.comfbfcd562012-08-23 18:09:54 +000055
reed@google.comac10a2d2010-12-22 21:39:39 +000056 static inline unsigned ExtractSubPixelBitsFromFixed(GrFixed pos) {
57 // two most significant fraction bits from fixed-point
58 return (pos >> 14) & 3;
59 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +000060
reed@google.comac10a2d2010-12-22 21:39:39 +000061 static inline PackedID Pack(uint16_t glyphID, GrFixed x, GrFixed y) {
62 x = ExtractSubPixelBitsFromFixed(x);
63 y = ExtractSubPixelBitsFromFixed(y);
64 return (x << 18) | (y << 16) | glyphID;
65 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +000066
reed@google.comac10a2d2010-12-22 21:39:39 +000067 static inline GrFixed UnpackFixedX(PackedID packed) {
68 return ((packed >> 18) & 3) << 14;
69 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +000070
reed@google.comac10a2d2010-12-22 21:39:39 +000071 static inline GrFixed UnpackFixedY(PackedID packed) {
72 return ((packed >> 16) & 3) << 14;
73 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +000074
reed@google.comac10a2d2010-12-22 21:39:39 +000075 static inline uint16_t UnpackID(PackedID packed) {
76 return (uint16_t)packed;
77 }
78};
79
80
81#endif