blob: a7d834153f4407bb781e7a79721e0aa48be3b51b [file] [log] [blame]
reed@google.comac10a2d2010-12-22 21:39:39 +00001/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00002 * Copyright 2010 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
reed@google.comac10a2d2010-12-22 21:39:39 +00006 */
7
reed@google.comac10a2d2010-12-22 21:39:39 +00008#ifndef GrGlyph_DEFINED
9#define GrGlyph_DEFINED
10
reed@google.comac10a2d2010-12-22 21:39:39 +000011#include "GrRect.h"
bsalomon@google.com8d033a12012-04-27 15:52:53 +000012#include "SkPath.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000013
commit-bot@chromium.org7d330eb2013-09-27 19:39:38 +000014class GrPlot;
reed@google.comac10a2d2010-12-22 21:39:39 +000015
16/* Need this to be quad-state:
17 - complete w/ image
18 - just metrics
19 - failed to get image, but has metrics
20 - failed to get metrics
21 */
22struct GrGlyph {
23 typedef uint32_t PackedID;
24
commit-bot@chromium.org7d330eb2013-09-27 19:39:38 +000025 GrPlot* fPlot;
bsalomon@google.com8d033a12012-04-27 15:52:53 +000026 SkPath* fPath;
reed@google.comac10a2d2010-12-22 21:39:39 +000027 PackedID fPackedID;
28 GrIRect16 fBounds;
robertphillipsd5373412014-06-02 10:20:14 -070029 SkIPoint16 fAtlasLocation;
reed@google.comac10a2d2010-12-22 21:39:39 +000030
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +000031 void init(GrGlyph::PackedID packed, const SkIRect& bounds) {
commit-bot@chromium.org7d330eb2013-09-27 19:39:38 +000032 fPlot = NULL;
reed@google.comac10a2d2010-12-22 21:39:39 +000033 fPath = NULL;
34 fPackedID = packed;
35 fBounds.set(bounds);
36 fAtlasLocation.set(0, 0);
37 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +000038
reed@google.comac10a2d2010-12-22 21:39:39 +000039 void free() {
40 if (fPath) {
41 delete fPath;
42 fPath = NULL;
43 }
44 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +000045
reed@google.comac10a2d2010-12-22 21:39:39 +000046 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); }
50
51 ///////////////////////////////////////////////////////////////////////////
rmistry@google.comfbfcd562012-08-23 18:09:54 +000052
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +000053 static inline unsigned ExtractSubPixelBitsFromFixed(SkFixed pos) {
reed@google.comac10a2d2010-12-22 21:39:39 +000054 // two most significant fraction bits from fixed-point
55 return (pos >> 14) & 3;
56 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +000057
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +000058 static inline PackedID Pack(uint16_t glyphID, SkFixed x, SkFixed y) {
reed@google.comac10a2d2010-12-22 21:39:39 +000059 x = ExtractSubPixelBitsFromFixed(x);
60 y = ExtractSubPixelBitsFromFixed(y);
61 return (x << 18) | (y << 16) | glyphID;
62 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +000063
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +000064 static inline SkFixed UnpackFixedX(PackedID packed) {
reed@google.comac10a2d2010-12-22 21:39:39 +000065 return ((packed >> 18) & 3) << 14;
66 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +000067
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +000068 static inline SkFixed UnpackFixedY(PackedID packed) {
reed@google.comac10a2d2010-12-22 21:39:39 +000069 return ((packed >> 16) & 3) << 14;
70 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +000071
reed@google.comac10a2d2010-12-22 21:39:39 +000072 static inline uint16_t UnpackID(PackedID packed) {
73 return (uint16_t)packed;
74 }
75};
76
77
78#endif