epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 3 | * 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.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 10 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 11 | #ifndef GrGlyph_DEFINED |
| 12 | #define GrGlyph_DEFINED |
| 13 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 14 | #include "GrRect.h" |
bsalomon@google.com | 8d033a1 | 2012-04-27 15:52:53 +0000 | [diff] [blame^] | 15 | #include "SkPath.h" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 16 | |
| 17 | class 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 | */ |
| 25 | struct GrGlyph { |
| 26 | typedef uint32_t PackedID; |
| 27 | |
| 28 | GrAtlas* fAtlas; |
bsalomon@google.com | 8d033a1 | 2012-04-27 15:52:53 +0000 | [diff] [blame^] | 29 | SkPath* fPath; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 30 | 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 | } |
| 41 | |
| 42 | void free() { |
| 43 | if (fPath) { |
| 44 | delete fPath; |
| 45 | fPath = NULL; |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | 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 | /////////////////////////////////////////////////////////////////////////// |
| 55 | |
| 56 | static inline unsigned ExtractSubPixelBitsFromFixed(GrFixed pos) { |
| 57 | // two most significant fraction bits from fixed-point |
| 58 | return (pos >> 14) & 3; |
| 59 | } |
| 60 | |
| 61 | 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 | } |
| 66 | |
| 67 | static inline GrFixed UnpackFixedX(PackedID packed) { |
| 68 | return ((packed >> 18) & 3) << 14; |
| 69 | } |
| 70 | |
| 71 | static inline GrFixed UnpackFixedY(PackedID packed) { |
| 72 | return ((packed >> 16) & 3) << 14; |
| 73 | } |
| 74 | |
| 75 | static inline uint16_t UnpackID(PackedID packed) { |
| 76 | return (uint16_t)packed; |
| 77 | } |
| 78 | }; |
| 79 | |
| 80 | |
| 81 | #endif |
| 82 | |