joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 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. |
| 6 | */ |
| 7 | |
Herb Derby | 8624059 | 2018-05-24 16:12:31 -0400 | [diff] [blame] | 8 | #ifndef GrTextContext_DEFINED |
| 9 | #define GrTextContext_DEFINED |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 10 | |
joshualitt | 1acabf3 | 2015-12-10 09:10:10 -0800 | [diff] [blame] | 11 | #include "GrDistanceFieldAdjustTable.h" |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 12 | #include "GrGeometryProcessor.h" |
Herb Derby | c1b482c | 2018-08-09 15:02:27 -0400 | [diff] [blame] | 13 | #include "GrTextTarget.h" |
Herb Derby | 46dbfbb | 2018-07-27 15:36:49 -0400 | [diff] [blame] | 14 | #include "SkGlyphRun.h" |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 15 | |
Hal Canary | 6f6961e | 2017-01-31 13:50:44 -0500 | [diff] [blame] | 16 | #if GR_TEST_UTILS |
Brian Salomon | 5ec9def | 2016-12-20 15:34:05 -0500 | [diff] [blame] | 17 | #include "GrDrawOpTest.h" |
joshualitt | 79dfb2b | 2015-05-11 08:58:08 -0700 | [diff] [blame] | 18 | #endif |
| 19 | |
Brian Salomon | 9afd371 | 2016-12-01 10:59:09 -0500 | [diff] [blame] | 20 | class GrDrawOp; |
Robert Phillips | b97da53 | 2019-02-12 15:24:12 -0500 | [diff] [blame^] | 21 | class GrRecordingContext; |
joshualitt | b7133be | 2015-04-08 09:08:31 -0700 | [diff] [blame] | 22 | class GrTextBlobCache; |
joshualitt | 6c2c2b0 | 2015-07-24 10:37:00 -0700 | [diff] [blame] | 23 | class SkGlyph; |
Herb Derby | dc214c2 | 2018-11-08 13:31:39 -0500 | [diff] [blame] | 24 | class GrTextBlob; |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 25 | |
| 26 | /* |
joshualitt | 8e84a1e | 2016-02-16 11:09:25 -0800 | [diff] [blame] | 27 | * Renders text using some kind of an atlas, ie BitmapText or DistanceField text |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 28 | */ |
Herb Derby | 26cbe51 | 2018-05-24 14:39:01 -0400 | [diff] [blame] | 29 | class GrTextContext { |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 30 | public: |
Brian Salomon | af59748 | 2017-11-07 16:23:34 -0500 | [diff] [blame] | 31 | struct Options { |
| 32 | /** |
| 33 | * Below this size (in device space) distance field text will not be used. Negative means |
| 34 | * use a default value. |
| 35 | */ |
| 36 | SkScalar fMinDistanceFieldFontSize = -1.f; |
| 37 | /** |
| 38 | * Above this size (in device space) distance field text will not be used and glyphs will |
| 39 | * be rendered from outline as individual paths. Negative means use a default value. |
| 40 | */ |
| 41 | SkScalar fMaxDistanceFieldFontSize = -1.f; |
Brian Salomon | b508696 | 2017-12-13 10:59:33 -0500 | [diff] [blame] | 42 | /** Forces all distance field vertices to use 3 components, not just when in perspective. */ |
| 43 | bool fDistanceFieldVerticesAlwaysHaveW = false; |
Brian Salomon | af59748 | 2017-11-07 16:23:34 -0500 | [diff] [blame] | 44 | }; |
| 45 | |
Herb Derby | 26cbe51 | 2018-05-24 14:39:01 -0400 | [diff] [blame] | 46 | static std::unique_ptr<GrTextContext> Make(const Options& options); |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 47 | |
Herb Derby | c1b482c | 2018-08-09 15:02:27 -0400 | [diff] [blame] | 48 | void drawGlyphRunList(GrContext*, GrTextTarget*, const GrClip&, |
Robert Phillips | e4643cc | 2018-08-14 13:01:29 -0400 | [diff] [blame] | 49 | const SkMatrix& viewMatrix, const SkSurfaceProps&, const SkGlyphRunList&); |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 50 | |
Robert Phillips | b97da53 | 2019-02-12 15:24:12 -0500 | [diff] [blame^] | 51 | std::unique_ptr<GrDrawOp> createOp_TestingOnly(GrRecordingContext*, |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 52 | GrTextContext*, |
| 53 | GrRenderTargetContext*, |
Mike Reed | 191e64b | 2019-01-02 15:35:29 -0500 | [diff] [blame] | 54 | const SkPaint&, const SkFont&, |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 55 | const SkMatrix& viewMatrix, |
| 56 | const char* text, |
| 57 | int x, |
| 58 | int y); |
Robert Phillips | d2e9f76 | 2018-03-07 11:54:37 -0500 | [diff] [blame] | 59 | |
Khushal | 3e7548c | 2018-05-23 15:45:01 -0700 | [diff] [blame] | 60 | static void SanitizeOptions(Options* options); |
Mike Reed | f2b074e | 2018-12-03 16:52:59 -0500 | [diff] [blame] | 61 | static bool CanDrawAsDistanceFields(const SkPaint&, const SkFont&, const SkMatrix& viewMatrix, |
Khushal | 3e7548c | 2018-05-23 15:45:01 -0700 | [diff] [blame] | 62 | const SkSurfaceProps& props, |
| 63 | bool contextSupportsDistanceFieldText, |
| 64 | const Options& options); |
Herb Derby | 6f27489 | 2018-12-17 17:30:07 -0500 | [diff] [blame] | 65 | static void InitDistanceFieldPaint(SkScalar textSize, |
Khushal | 3e7548c | 2018-05-23 15:45:01 -0700 | [diff] [blame] | 66 | const SkMatrix& viewMatrix, |
| 67 | const Options& options, |
Herb Derby | 6f27489 | 2018-12-17 17:30:07 -0500 | [diff] [blame] | 68 | GrTextBlob* blob, |
| 69 | SkPaint* skPaint, |
| 70 | SkFont* skFont, |
Khushal | 3e7548c | 2018-05-23 15:45:01 -0700 | [diff] [blame] | 71 | SkScalar* textRatio, |
| 72 | SkScalerContextFlags* flags); |
| 73 | |
Khushal | fa8ff09 | 2018-06-06 17:46:38 -0700 | [diff] [blame] | 74 | private: |
| 75 | GrTextContext(const Options& options); |
| 76 | |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 77 | // sets up the descriptor on the blob and returns a detached cache. Client must attach |
Herb Derby | d8327a8 | 2018-01-22 14:39:27 -0500 | [diff] [blame] | 78 | static SkColor ComputeCanonicalColor(const SkPaint&, bool lcd); |
brianosman | a1e8f8d | 2016-04-08 06:47:54 -0700 | [diff] [blame] | 79 | // Determines if we need to use fake gamma (and contrast boost): |
Herb Derby | d8327a8 | 2018-01-22 14:39:27 -0500 | [diff] [blame] | 80 | static SkScalerContextFlags ComputeScalerContextFlags(const GrColorSpaceInfo&); |
Herb Derby | cddab25 | 2018-07-16 11:19:04 -0400 | [diff] [blame] | 81 | |
Hal Canary | 144caf5 | 2016-11-07 17:57:18 -0500 | [diff] [blame] | 82 | const GrDistanceFieldAdjustTable* dfAdjustTable() const { return fDistanceAdjustTable.get(); } |
joshualitt | 79dfb2b | 2015-05-11 08:58:08 -0700 | [diff] [blame] | 83 | |
Hal Canary | 144caf5 | 2016-11-07 17:57:18 -0500 | [diff] [blame] | 84 | sk_sp<const GrDistanceFieldAdjustTable> fDistanceAdjustTable; |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 85 | |
Khushal | 3e7548c | 2018-05-23 15:45:01 -0700 | [diff] [blame] | 86 | Options fOptions; |
Brian Salomon | af59748 | 2017-11-07 16:23:34 -0500 | [diff] [blame] | 87 | |
Hal Canary | 6f6961e | 2017-01-31 13:50:44 -0500 | [diff] [blame] | 88 | #if GR_TEST_UTILS |
Herb Derby | d8327a8 | 2018-01-22 14:39:27 -0500 | [diff] [blame] | 89 | static const SkScalerContextFlags kTextBlobOpScalerContextFlags = |
| 90 | SkScalerContextFlags::kFakeGammaAndBoostContrast; |
Brian Salomon | 44acb5b | 2017-07-18 19:59:24 -0400 | [diff] [blame] | 91 | GR_DRAW_OP_TEST_FRIEND(GrAtlasTextOp); |
joshualitt | 79dfb2b | 2015-05-11 08:58:08 -0700 | [diff] [blame] | 92 | #endif |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 93 | }; |
| 94 | |
Herb Derby | 8624059 | 2018-05-24 16:12:31 -0400 | [diff] [blame] | 95 | #endif // GrTextContext_DEFINED |