joshualitt | 0a42e68 | 2015-12-10 13:20:58 -0800 | [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 | |
| 8 | #ifndef GrTextUtils_DEFINED |
| 9 | #define GrTextUtils_DEFINED |
| 10 | |
joshualitt | 2967798 | 2015-12-11 06:08:59 -0800 | [diff] [blame] | 11 | #include "GrColor.h" |
brianosman | 32f7782 | 2016-04-07 06:25:45 -0700 | [diff] [blame] | 12 | #include "SkPaint.h" |
joshualitt | 0a42e68 | 2015-12-10 13:20:58 -0800 | [diff] [blame] | 13 | #include "SkScalar.h" |
| 14 | |
Brian Salomon | f856fd1 | 2016-12-16 14:24:34 -0500 | [diff] [blame] | 15 | class GrAtlasGlyphCache; |
joshualitt | 2967798 | 2015-12-11 06:08:59 -0800 | [diff] [blame] | 16 | class GrAtlasTextBlob; |
Brian Salomon | f856fd1 | 2016-12-16 14:24:34 -0500 | [diff] [blame] | 17 | class GrAtlasTextStrike; |
joshualitt | 0a42e68 | 2015-12-10 13:20:58 -0800 | [diff] [blame] | 18 | class GrClip; |
| 19 | class GrContext; |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 20 | class GrRenderTargetContext; |
joshualitt | 0d2199b | 2016-01-20 06:36:09 -0800 | [diff] [blame] | 21 | class GrShaderCaps; |
joshualitt | 2967798 | 2015-12-11 06:08:59 -0800 | [diff] [blame] | 22 | class SkGlyph; |
joshualitt | 0a42e68 | 2015-12-10 13:20:58 -0800 | [diff] [blame] | 23 | class SkMatrix; |
| 24 | struct SkIRect; |
joshualitt | 0a42e68 | 2015-12-10 13:20:58 -0800 | [diff] [blame] | 25 | struct SkPoint; |
joshualitt | 2967798 | 2015-12-11 06:08:59 -0800 | [diff] [blame] | 26 | class SkGlyphCache; |
joshualitt | 0a42e68 | 2015-12-10 13:20:58 -0800 | [diff] [blame] | 27 | class SkSurfaceProps; |
| 28 | |
| 29 | /* |
| 30 | * A class to house a bunch of common text utilities. This class should *ONLY* have static |
| 31 | * functions. It is not a namespace only because we wish to friend SkPaint |
| 32 | * |
| 33 | */ |
| 34 | class GrTextUtils { |
| 35 | public: |
joshualitt | 2967798 | 2015-12-11 06:08:59 -0800 | [diff] [blame] | 36 | // Functions for appending BMP text to GrAtlasTextBlob |
| 37 | static void DrawBmpText(GrAtlasTextBlob*, int runIndex, |
Brian Salomon | f856fd1 | 2016-12-16 14:24:34 -0500 | [diff] [blame] | 38 | GrAtlasGlyphCache*, const SkSurfaceProps&, |
joshualitt | e76b4bb3 | 2015-12-28 07:23:58 -0800 | [diff] [blame] | 39 | const SkPaint&, |
brianosman | a1e8f8d | 2016-04-08 06:47:54 -0700 | [diff] [blame] | 40 | GrColor, uint32_t scalerContextFlags, const SkMatrix& viewMatrix, |
joshualitt | 2967798 | 2015-12-11 06:08:59 -0800 | [diff] [blame] | 41 | const char text[], size_t byteLength, |
| 42 | SkScalar x, SkScalar y); |
joshualitt | 0a42e68 | 2015-12-10 13:20:58 -0800 | [diff] [blame] | 43 | |
joshualitt | 2967798 | 2015-12-11 06:08:59 -0800 | [diff] [blame] | 44 | static void DrawBmpPosText(GrAtlasTextBlob*, int runIndex, |
Brian Salomon | f856fd1 | 2016-12-16 14:24:34 -0500 | [diff] [blame] | 45 | GrAtlasGlyphCache*, const SkSurfaceProps&, const SkPaint&, |
brianosman | a1e8f8d | 2016-04-08 06:47:54 -0700 | [diff] [blame] | 46 | GrColor, uint32_t scalerContextFlags, const SkMatrix& viewMatrix, |
joshualitt | 2967798 | 2015-12-11 06:08:59 -0800 | [diff] [blame] | 47 | const char text[], size_t byteLength, |
| 48 | const SkScalar pos[], int scalarsPerPosition, |
| 49 | const SkPoint& offset); |
joshualitt | 0a42e68 | 2015-12-10 13:20:58 -0800 | [diff] [blame] | 50 | |
joshualitt | 0d2199b | 2016-01-20 06:36:09 -0800 | [diff] [blame] | 51 | // functions for appending distance field text |
| 52 | static bool CanDrawAsDistanceFields(const SkPaint& skPaint, const SkMatrix& viewMatrix, |
| 53 | const SkSurfaceProps& props, const GrShaderCaps& caps); |
| 54 | |
| 55 | static void DrawDFText(GrAtlasTextBlob* blob, int runIndex, |
Brian Salomon | f856fd1 | 2016-12-16 14:24:34 -0500 | [diff] [blame] | 56 | GrAtlasGlyphCache*, const SkSurfaceProps&, |
brianosman | a1e8f8d | 2016-04-08 06:47:54 -0700 | [diff] [blame] | 57 | const SkPaint& skPaint, GrColor color, uint32_t scalerContextFlags, |
joshualitt | 0d2199b | 2016-01-20 06:36:09 -0800 | [diff] [blame] | 58 | const SkMatrix& viewMatrix, |
| 59 | const char text[], size_t byteLength, |
| 60 | SkScalar x, SkScalar y); |
| 61 | |
| 62 | static void DrawDFPosText(GrAtlasTextBlob* blob, int runIndex, |
Brian Salomon | f856fd1 | 2016-12-16 14:24:34 -0500 | [diff] [blame] | 63 | GrAtlasGlyphCache*, const SkSurfaceProps&, const SkPaint&, |
brianosman | a1e8f8d | 2016-04-08 06:47:54 -0700 | [diff] [blame] | 64 | GrColor color, uint32_t scalerContextFlags, |
| 65 | const SkMatrix& viewMatrix, |
joshualitt | 0d2199b | 2016-01-20 06:36:09 -0800 | [diff] [blame] | 66 | const char text[], size_t byteLength, |
| 67 | const SkScalar pos[], int scalarsPerPosition, |
| 68 | const SkPoint& offset); |
| 69 | |
joshualitt | 2967798 | 2015-12-11 06:08:59 -0800 | [diff] [blame] | 70 | // Functions for drawing text as paths |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 71 | static void DrawTextAsPath(GrContext*, GrRenderTargetContext*, const GrClip& clip, |
joshualitt | 2967798 | 2015-12-11 06:08:59 -0800 | [diff] [blame] | 72 | const SkPaint& origPaint, const SkMatrix& viewMatrix, |
| 73 | const char text[], size_t byteLength, SkScalar x, SkScalar y, |
| 74 | const SkIRect& clipBounds); |
| 75 | |
| 76 | static void DrawPosTextAsPath(GrContext* context, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 77 | GrRenderTargetContext* rtc, |
joshualitt | 2967798 | 2015-12-11 06:08:59 -0800 | [diff] [blame] | 78 | const SkSurfaceProps& props, |
| 79 | const GrClip& clip, |
| 80 | const SkPaint& origPaint, const SkMatrix& viewMatrix, |
| 81 | const char text[], size_t byteLength, |
| 82 | const SkScalar pos[], int scalarsPerPosition, |
| 83 | const SkPoint& offset, const SkIRect& clipBounds); |
joshualitt | 8e84a1e | 2016-02-16 11:09:25 -0800 | [diff] [blame] | 84 | |
| 85 | static bool ShouldDisableLCD(const SkPaint& paint); |
| 86 | |
joshualitt | 8e84a1e | 2016-02-16 11:09:25 -0800 | [diff] [blame] | 87 | static uint32_t FilterTextFlags(const SkSurfaceProps& surfaceProps, const SkPaint& paint); |
| 88 | |
joshualitt | 2967798 | 2015-12-11 06:08:59 -0800 | [diff] [blame] | 89 | private: |
joshualitt | 0d2199b | 2016-01-20 06:36:09 -0800 | [diff] [blame] | 90 | static void InitDistanceFieldPaint(GrAtlasTextBlob* blob, |
| 91 | SkPaint* skPaint, |
| 92 | SkScalar* textRatio, |
| 93 | const SkMatrix& viewMatrix); |
| 94 | |
Brian Salomon | f856fd1 | 2016-12-16 14:24:34 -0500 | [diff] [blame] | 95 | static void BmpAppendGlyph(GrAtlasTextBlob*, int runIndex, GrAtlasGlyphCache*, |
| 96 | GrAtlasTextStrike**, const SkGlyph&, int left, int top, |
bsalomon | c2878e2 | 2016-05-17 13:18:03 -0700 | [diff] [blame] | 97 | GrColor color, SkGlyphCache*); |
joshualitt | 0d2199b | 2016-01-20 06:36:09 -0800 | [diff] [blame] | 98 | |
Brian Salomon | f856fd1 | 2016-12-16 14:24:34 -0500 | [diff] [blame] | 99 | static bool DfAppendGlyph(GrAtlasTextBlob*, int runIndex, GrAtlasGlyphCache*, |
| 100 | GrAtlasTextStrike**, const SkGlyph&, |
joshualitt | 0d2199b | 2016-01-20 06:36:09 -0800 | [diff] [blame] | 101 | SkScalar sx, SkScalar sy, GrColor color, |
bsalomon | c2878e2 | 2016-05-17 13:18:03 -0700 | [diff] [blame] | 102 | SkGlyphCache* cache, |
joshualitt | 0d2199b | 2016-01-20 06:36:09 -0800 | [diff] [blame] | 103 | SkScalar textRatio, const SkMatrix& viewMatrix); |
joshualitt | 0a42e68 | 2015-12-10 13:20:58 -0800 | [diff] [blame] | 104 | }; |
| 105 | |
| 106 | #endif |