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 | |
joshualitt | 7c3a2f8 | 2015-03-31 13:32:05 -0700 | [diff] [blame] | 11 | #include "GrBatchAtlas.h" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 12 | #include "GrRect.h" |
jvanverth | 294c326 | 2014-10-10 11:36:12 -0700 | [diff] [blame] | 13 | #include "GrTypes.h" |
| 14 | |
jvanverth | e817dbb | 2014-10-10 08:52:03 -0700 | [diff] [blame] | 15 | #include "SkChecksum.h" |
benjaminwagner | 6c71e0a | 2016-04-07 08:49:31 -0700 | [diff] [blame^] | 16 | #include "SkFixed.h" |
jvanverth | 294c326 | 2014-10-10 11:36:12 -0700 | [diff] [blame] | 17 | #include "SkPath.h" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 18 | |
commit-bot@chromium.org | 7d330eb | 2013-09-27 19:39:38 +0000 | [diff] [blame] | 19 | class GrPlot; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 20 | |
| 21 | /* Need this to be quad-state: |
| 22 | - complete w/ image |
| 23 | - just metrics |
| 24 | - failed to get image, but has metrics |
| 25 | - failed to get metrics |
| 26 | */ |
| 27 | struct GrGlyph { |
jvanverth | a763461 | 2015-03-19 06:08:31 -0700 | [diff] [blame] | 28 | enum MaskStyle { |
| 29 | kCoverage_MaskStyle, |
| 30 | kDistance_MaskStyle |
| 31 | }; |
mtklein | 852f15d | 2016-03-17 10:51:27 -0700 | [diff] [blame] | 32 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 33 | typedef uint32_t PackedID; |
| 34 | |
joshualitt | 7c3a2f8 | 2015-03-31 13:32:05 -0700 | [diff] [blame] | 35 | GrBatchAtlas::AtlasID fID; |
joshualitt | 7c3a2f8 | 2015-03-31 13:32:05 -0700 | [diff] [blame] | 36 | SkPath* fPath; |
| 37 | PackedID fPackedID; |
| 38 | GrMaskFormat fMaskFormat; |
| 39 | GrIRect16 fBounds; |
| 40 | SkIPoint16 fAtlasLocation; |
joshualitt | 010db53 | 2015-04-21 10:07:26 -0700 | [diff] [blame] | 41 | bool fTooLargeForAtlas; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 42 | |
jvanverth | 294c326 | 2014-10-10 11:36:12 -0700 | [diff] [blame] | 43 | void init(GrGlyph::PackedID packed, const SkIRect& bounds, GrMaskFormat format) { |
joshualitt | 7c3a2f8 | 2015-03-31 13:32:05 -0700 | [diff] [blame] | 44 | fID = GrBatchAtlas::kInvalidAtlasID; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 45 | fPath = nullptr; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 46 | fPackedID = packed; |
| 47 | fBounds.set(bounds); |
jvanverth | 294c326 | 2014-10-10 11:36:12 -0700 | [diff] [blame] | 48 | fMaskFormat = format; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 49 | fAtlasLocation.set(0, 0); |
joshualitt | 010db53 | 2015-04-21 10:07:26 -0700 | [diff] [blame] | 50 | fTooLargeForAtlas = GrBatchAtlas::GlyphTooLargeForAtlas(bounds.width(), bounds.height()); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 51 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 52 | |
mtklein | 852f15d | 2016-03-17 10:51:27 -0700 | [diff] [blame] | 53 | void reset() { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 54 | if (fPath) { |
| 55 | delete fPath; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 56 | fPath = nullptr; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 57 | } |
| 58 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 59 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 60 | int width() const { return fBounds.width(); } |
| 61 | int height() const { return fBounds.height(); } |
| 62 | bool isEmpty() const { return fBounds.isEmpty(); } |
| 63 | uint16_t glyphID() const { return UnpackID(fPackedID); } |
| 64 | |
| 65 | /////////////////////////////////////////////////////////////////////////// |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 66 | |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 67 | static inline unsigned ExtractSubPixelBitsFromFixed(SkFixed pos) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 68 | // two most significant fraction bits from fixed-point |
| 69 | return (pos >> 14) & 3; |
| 70 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 71 | |
jvanverth | a763461 | 2015-03-19 06:08:31 -0700 | [diff] [blame] | 72 | static inline PackedID Pack(uint16_t glyphID, SkFixed x, SkFixed y, MaskStyle ms) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 73 | x = ExtractSubPixelBitsFromFixed(x); |
| 74 | y = ExtractSubPixelBitsFromFixed(y); |
jvanverth | a763461 | 2015-03-19 06:08:31 -0700 | [diff] [blame] | 75 | int dfFlag = (ms == kDistance_MaskStyle) ? 0x1 : 0x0; |
| 76 | return (dfFlag << 20) | (x << 18) | (y << 16) | glyphID; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 77 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 78 | |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 79 | static inline SkFixed UnpackFixedX(PackedID packed) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 80 | return ((packed >> 18) & 3) << 14; |
| 81 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 82 | |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 83 | static inline SkFixed UnpackFixedY(PackedID packed) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 84 | return ((packed >> 16) & 3) << 14; |
| 85 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 86 | |
jvanverth | a763461 | 2015-03-19 06:08:31 -0700 | [diff] [blame] | 87 | static inline MaskStyle UnpackMaskStyle(PackedID packed) { |
| 88 | return ((packed >> 20) & 1) ? kDistance_MaskStyle : kCoverage_MaskStyle; |
| 89 | } |
mtklein | 852f15d | 2016-03-17 10:51:27 -0700 | [diff] [blame] | 90 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 91 | static inline uint16_t UnpackID(PackedID packed) { |
| 92 | return (uint16_t)packed; |
| 93 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 94 | |
jvanverth | dd6d227 | 2014-07-22 13:25:26 -0700 | [diff] [blame] | 95 | static inline const GrGlyph::PackedID& GetKey(const GrGlyph& glyph) { |
| 96 | return glyph.fPackedID; |
| 97 | } |
| 98 | |
| 99 | static inline uint32_t Hash(GrGlyph::PackedID key) { |
joshualitt | 010db53 | 2015-04-21 10:07:26 -0700 | [diff] [blame] | 100 | return SkChecksum::Mix(key); |
jvanverth | dd6d227 | 2014-07-22 13:25:26 -0700 | [diff] [blame] | 101 | } |
| 102 | }; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 103 | |
| 104 | #endif |