| 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" |
| bsalomon@google.com | 8d033a1 | 2012-04-27 15:52:53 +0000 | [diff] [blame] | 12 | #include "SkPath.h" |
| jvanverth | dd6d227 | 2014-07-22 13:25:26 -0700 | [diff] [blame] | 13 | #include "SkChecksum.h" |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 14 | |
| commit-bot@chromium.org | 7d330eb | 2013-09-27 19:39:38 +0000 | [diff] [blame] | 15 | class GrPlot; |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 16 | |
| 17 | /* Need this to be quad-state: |
| 18 | - complete w/ image |
| 19 | - just metrics |
| 20 | - failed to get image, but has metrics |
| 21 | - failed to get metrics |
| 22 | */ |
| 23 | struct GrGlyph { |
| 24 | typedef uint32_t PackedID; |
| 25 | |
| commit-bot@chromium.org | 7d330eb | 2013-09-27 19:39:38 +0000 | [diff] [blame] | 26 | GrPlot* fPlot; |
| bsalomon@google.com | 8d033a1 | 2012-04-27 15:52:53 +0000 | [diff] [blame] | 27 | SkPath* fPath; |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 28 | PackedID fPackedID; |
| 29 | GrIRect16 fBounds; |
| robertphillips | d537341 | 2014-06-02 10:20:14 -0700 | [diff] [blame] | 30 | SkIPoint16 fAtlasLocation; |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 31 | |
| commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 32 | void init(GrGlyph::PackedID packed, const SkIRect& bounds) { |
| commit-bot@chromium.org | 7d330eb | 2013-09-27 19:39:38 +0000 | [diff] [blame] | 33 | fPlot = NULL; |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 34 | fPath = NULL; |
| 35 | fPackedID = packed; |
| 36 | fBounds.set(bounds); |
| 37 | fAtlasLocation.set(0, 0); |
| 38 | } |
| rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 39 | |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 40 | void free() { |
| 41 | if (fPath) { |
| 42 | delete fPath; |
| 43 | fPath = NULL; |
| 44 | } |
| 45 | } |
| rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 46 | |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 47 | int width() const { return fBounds.width(); } |
| 48 | int height() const { return fBounds.height(); } |
| 49 | bool isEmpty() const { return fBounds.isEmpty(); } |
| 50 | uint16_t glyphID() const { return UnpackID(fPackedID); } |
| 51 | |
| 52 | /////////////////////////////////////////////////////////////////////////// |
| rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 53 | |
| commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 54 | static inline unsigned ExtractSubPixelBitsFromFixed(SkFixed pos) { |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 55 | // two most significant fraction bits from fixed-point |
| 56 | return (pos >> 14) & 3; |
| 57 | } |
| rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 58 | |
| commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 59 | static inline PackedID Pack(uint16_t glyphID, SkFixed x, SkFixed y) { |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 60 | x = ExtractSubPixelBitsFromFixed(x); |
| 61 | y = ExtractSubPixelBitsFromFixed(y); |
| 62 | return (x << 18) | (y << 16) | glyphID; |
| 63 | } |
| rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 64 | |
| commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 65 | static inline SkFixed UnpackFixedX(PackedID packed) { |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 66 | return ((packed >> 18) & 3) << 14; |
| 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 UnpackFixedY(PackedID packed) { |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 70 | return ((packed >> 16) & 3) << 14; |
| 71 | } |
| rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 72 | |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 73 | static inline uint16_t UnpackID(PackedID packed) { |
| 74 | return (uint16_t)packed; |
| 75 | } |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 76 | |
| jvanverth | dd6d227 | 2014-07-22 13:25:26 -0700 | [diff] [blame] | 77 | static inline const GrGlyph::PackedID& GetKey(const GrGlyph& glyph) { |
| 78 | return glyph.fPackedID; |
| 79 | } |
| 80 | |
| 81 | static inline uint32_t Hash(GrGlyph::PackedID key) { |
| 82 | return SkChecksum::Murmur3(&key, sizeof(key)); |
| 83 | } |
| 84 | }; |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 85 | |
| 86 | #endif |