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