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" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 13 | |
commit-bot@chromium.org | 7d330eb | 2013-09-27 19:39:38 +0000 | [diff] [blame] | 14 | class GrPlot; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 15 | |
| 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 | */ |
| 22 | struct GrGlyph { |
| 23 | typedef uint32_t PackedID; |
| 24 | |
commit-bot@chromium.org | 7d330eb | 2013-09-27 19:39:38 +0000 | [diff] [blame] | 25 | GrPlot* fPlot; |
bsalomon@google.com | 8d033a1 | 2012-04-27 15:52:53 +0000 | [diff] [blame] | 26 | SkPath* fPath; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 27 | PackedID fPackedID; |
| 28 | GrIRect16 fBounds; |
robertphillips | d537341 | 2014-06-02 10:20:14 -0700 | [diff] [blame] | 29 | SkIPoint16 fAtlasLocation; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 30 | |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 31 | void init(GrGlyph::PackedID packed, const SkIRect& bounds) { |
commit-bot@chromium.org | 7d330eb | 2013-09-27 19:39:38 +0000 | [diff] [blame] | 32 | fPlot = NULL; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 33 | fPath = NULL; |
| 34 | fPackedID = packed; |
| 35 | fBounds.set(bounds); |
| 36 | fAtlasLocation.set(0, 0); |
| 37 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 38 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 39 | void free() { |
| 40 | if (fPath) { |
| 41 | delete fPath; |
| 42 | fPath = NULL; |
| 43 | } |
| 44 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 45 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 46 | 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.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 52 | |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 53 | static inline unsigned ExtractSubPixelBitsFromFixed(SkFixed pos) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 54 | // two most significant fraction bits from fixed-point |
| 55 | return (pos >> 14) & 3; |
| 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 PackedID Pack(uint16_t glyphID, SkFixed x, SkFixed y) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 59 | x = ExtractSubPixelBitsFromFixed(x); |
| 60 | y = ExtractSubPixelBitsFromFixed(y); |
| 61 | return (x << 18) | (y << 16) | glyphID; |
| 62 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 63 | |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 64 | static inline SkFixed UnpackFixedX(PackedID packed) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 65 | return ((packed >> 18) & 3) << 14; |
| 66 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 67 | |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 68 | static inline SkFixed UnpackFixedY(PackedID packed) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 69 | return ((packed >> 16) & 3) << 14; |
| 70 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 71 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 72 | static inline uint16_t UnpackID(PackedID packed) { |
| 73 | return (uint16_t)packed; |
| 74 | } |
| 75 | }; |
| 76 | |
| 77 | |
| 78 | #endif |