reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 2 | * 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.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 8 | #ifndef GrGlyph_DEFINED |
| 9 | #define GrGlyph_DEFINED |
| 10 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 11 | #include "GrRect.h" |
jvanverth | 294c326 | 2014-10-10 11:36:12 -0700 | [diff] [blame] | 12 | #include "GrTypes.h" |
| 13 | |
jvanverth | e817dbb | 2014-10-10 08:52:03 -0700 | [diff] [blame] | 14 | #include "SkChecksum.h" |
jvanverth | 294c326 | 2014-10-10 11:36:12 -0700 | [diff] [blame] | 15 | #include "SkPath.h" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 16 | |
commit-bot@chromium.org | 7d330eb | 2013-09-27 19:39:38 +0000 | [diff] [blame] | 17 | class GrPlot; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 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 | |
jvanverth | 294c326 | 2014-10-10 11:36:12 -0700 | [diff] [blame] | 28 | GrPlot* fPlot; |
| 29 | SkPath* fPath; |
| 30 | PackedID fPackedID; |
| 31 | GrMaskFormat fMaskFormat; |
| 32 | GrIRect16 fBounds; |
| 33 | SkIPoint16 fAtlasLocation; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 34 | |
jvanverth | 294c326 | 2014-10-10 11:36:12 -0700 | [diff] [blame] | 35 | void init(GrGlyph::PackedID packed, const SkIRect& bounds, GrMaskFormat format) { |
commit-bot@chromium.org | 7d330eb | 2013-09-27 19:39:38 +0000 | [diff] [blame] | 36 | fPlot = NULL; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 37 | fPath = NULL; |
| 38 | fPackedID = packed; |
| 39 | fBounds.set(bounds); |
jvanverth | 294c326 | 2014-10-10 11:36:12 -0700 | [diff] [blame] | 40 | fMaskFormat = format; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 41 | fAtlasLocation.set(0, 0); |
| 42 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 43 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 44 | void free() { |
| 45 | if (fPath) { |
| 46 | delete fPath; |
| 47 | fPath = NULL; |
| 48 | } |
| 49 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 50 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 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); } |
| 55 | |
| 56 | /////////////////////////////////////////////////////////////////////////// |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 57 | |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 58 | static inline unsigned ExtractSubPixelBitsFromFixed(SkFixed pos) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 59 | // two most significant fraction bits from fixed-point |
| 60 | return (pos >> 14) & 3; |
| 61 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 62 | |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 63 | static inline PackedID Pack(uint16_t glyphID, SkFixed x, SkFixed y) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 64 | x = ExtractSubPixelBitsFromFixed(x); |
| 65 | y = ExtractSubPixelBitsFromFixed(y); |
| 66 | return (x << 18) | (y << 16) | glyphID; |
| 67 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 68 | |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 69 | static inline SkFixed UnpackFixedX(PackedID packed) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 70 | return ((packed >> 18) & 3) << 14; |
| 71 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 72 | |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 73 | static inline SkFixed UnpackFixedY(PackedID packed) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 74 | return ((packed >> 16) & 3) << 14; |
| 75 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 76 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 77 | static inline uint16_t UnpackID(PackedID packed) { |
| 78 | return (uint16_t)packed; |
| 79 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 80 | |
jvanverth | dd6d227 | 2014-07-22 13:25:26 -0700 | [diff] [blame] | 81 | static inline const GrGlyph::PackedID& GetKey(const GrGlyph& glyph) { |
| 82 | return glyph.fPackedID; |
| 83 | } |
| 84 | |
| 85 | static inline uint32_t Hash(GrGlyph::PackedID key) { |
| 86 | return SkChecksum::Murmur3(&key, sizeof(key)); |
| 87 | } |
| 88 | }; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 89 | |
| 90 | #endif |