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 | |
| 8 | #ifndef GrAtlasTextContext_DEFINED |
| 9 | #define GrAtlasTextContext_DEFINED |
| 10 | |
| 11 | #include "GrTextContext.h" |
| 12 | |
joshualitt | 374b2f7 | 2015-07-21 08:05:03 -0700 | [diff] [blame] | 13 | #include "GrAtlasTextBlob.h" |
joshualitt | 1acabf3 | 2015-12-10 09:10:10 -0800 | [diff] [blame] | 14 | #include "GrDistanceFieldAdjustTable.h" |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 15 | #include "GrGeometryProcessor.h" |
halcanary | 3377975 | 2015-10-27 14:01:05 -0700 | [diff] [blame] | 16 | #include "SkTextBlobRunIterator.h" |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 17 | |
joshualitt | 79dfb2b | 2015-05-11 08:58:08 -0700 | [diff] [blame] | 18 | #ifdef GR_TEST_UTILS |
| 19 | #include "GrBatchTest.h" |
| 20 | #endif |
| 21 | |
bsalomon | abd30f5 | 2015-08-13 13:34:48 -0700 | [diff] [blame] | 22 | class GrDrawBatch; |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 23 | class GrDrawContext; |
robertphillips | 2334fb6 | 2015-06-17 05:43:33 -0700 | [diff] [blame] | 24 | class GrDrawTarget; |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 25 | class GrPipelineBuilder; |
joshualitt | b7133be | 2015-04-08 09:08:31 -0700 | [diff] [blame] | 26 | class GrTextBlobCache; |
joshualitt | 6c2c2b0 | 2015-07-24 10:37:00 -0700 | [diff] [blame] | 27 | class SkGlyph; |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 28 | |
| 29 | /* |
| 30 | * This class implements GrTextContext using standard bitmap fonts, and can also process textblobs. |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 31 | */ |
joshualitt | dbd3593 | 2015-04-02 09:19:04 -0700 | [diff] [blame] | 32 | class GrAtlasTextContext : public GrTextContext { |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 33 | public: |
robertphillips | f6703fa | 2015-09-01 05:36:47 -0700 | [diff] [blame] | 34 | static GrAtlasTextContext* Create(GrContext*, const SkSurfaceProps&); |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 35 | |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 36 | private: |
robertphillips | f6703fa | 2015-09-01 05:36:47 -0700 | [diff] [blame] | 37 | GrAtlasTextContext(GrContext*, const SkSurfaceProps&); |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 38 | ~GrAtlasTextContext() override {} |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 39 | |
robertphillips | 6ee690e | 2015-12-02 08:57:50 -0800 | [diff] [blame] | 40 | bool canDraw(const SkPaint&, const SkMatrix& viewMatrix) override; |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 41 | |
robertphillips | 433625e | 2015-12-04 06:58:16 -0800 | [diff] [blame] | 42 | void onDrawText(GrDrawContext*, const GrClip&, const GrPaint&, const SkPaint&, |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 43 | const SkMatrix& viewMatrix, const char text[], size_t byteLength, |
| 44 | SkScalar x, SkScalar y, const SkIRect& regionClipBounds) override; |
robertphillips | 433625e | 2015-12-04 06:58:16 -0800 | [diff] [blame] | 45 | void onDrawPosText(GrDrawContext*, const GrClip&, const GrPaint&, |
robertphillips | ccb1b57 | 2015-05-27 11:02:55 -0700 | [diff] [blame] | 46 | const SkPaint&, const SkMatrix& viewMatrix, |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 47 | const char text[], size_t byteLength, |
| 48 | const SkScalar pos[], int scalarsPerPosition, |
| 49 | const SkPoint& offset, const SkIRect& regionClipBounds) override; |
robertphillips | 433625e | 2015-12-04 06:58:16 -0800 | [diff] [blame] | 50 | void drawTextBlob(GrDrawContext*, const GrClip&, const SkPaint&, |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 51 | const SkMatrix& viewMatrix, const SkTextBlob*, SkScalar x, SkScalar y, |
| 52 | SkDrawFilter*, const SkIRect& clipBounds) override; |
| 53 | |
joshualitt | 374b2f7 | 2015-07-21 08:05:03 -0700 | [diff] [blame] | 54 | typedef GrAtlasTextBlob::Run Run; |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 55 | typedef Run::SubRunInfo PerSubRunInfo; |
| 56 | |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 57 | inline bool canDrawAsDistanceFields(const SkPaint&, const SkMatrix& viewMatrix); |
joshualitt | 374b2f7 | 2015-07-21 08:05:03 -0700 | [diff] [blame] | 58 | GrAtlasTextBlob* setupDFBlob(int glyphCount, const SkPaint& origPaint, |
jvanverth | 157e648 | 2015-09-09 08:05:12 -0700 | [diff] [blame] | 59 | const SkMatrix& viewMatrix, SkPaint* dfPaint, |
| 60 | SkScalar* textRatio); |
joshualitt | 6c2c2b0 | 2015-07-24 10:37:00 -0700 | [diff] [blame] | 61 | void bmpAppendGlyph(GrAtlasTextBlob*, int runIndex, const SkGlyph&, int left, int top, |
robertphillips | 6ee690e | 2015-12-02 08:57:50 -0800 | [diff] [blame] | 62 | GrColor color, GrFontScaler*); |
joshualitt | 6c2c2b0 | 2015-07-24 10:37:00 -0700 | [diff] [blame] | 63 | bool dfAppendGlyph(GrAtlasTextBlob*, int runIndex, const SkGlyph&, SkScalar sx, SkScalar sy, |
robertphillips | 6ee690e | 2015-12-02 08:57:50 -0800 | [diff] [blame] | 64 | GrColor color, GrFontScaler*, SkScalar textRatio, |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 65 | const SkMatrix& viewMatrix); |
joshualitt | 9a27e63 | 2015-04-06 10:53:36 -0700 | [diff] [blame] | 66 | |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 67 | // A helper for drawing BitmapText in a run of distance fields |
joshualitt | 374b2f7 | 2015-07-21 08:05:03 -0700 | [diff] [blame] | 68 | inline void fallbackDrawPosText(GrAtlasTextBlob*, int runIndex, |
robertphillips | 6ee690e | 2015-12-02 08:57:50 -0800 | [diff] [blame] | 69 | const GrClip&, GrColor color, |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 70 | const SkPaint&, const SkMatrix& viewMatrix, |
| 71 | const SkTDArray<char>& fallbackTxt, |
| 72 | const SkTDArray<SkScalar>& fallbackPos, |
| 73 | int scalarsPerPosition, |
robertphillips | 6ee690e | 2015-12-02 08:57:50 -0800 | [diff] [blame] | 74 | const SkPoint& offset); |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 75 | |
joshualitt | 374b2f7 | 2015-07-21 08:05:03 -0700 | [diff] [blame] | 76 | void internalDrawBMPText(GrAtlasTextBlob*, int runIndex, SkGlyphCache*, const SkPaint&, |
joshualitt | 9e36c1a | 2015-04-14 12:17:27 -0700 | [diff] [blame] | 77 | GrColor color, const SkMatrix& viewMatrix, |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 78 | const char text[], size_t byteLength, |
robertphillips | 6ee690e | 2015-12-02 08:57:50 -0800 | [diff] [blame] | 79 | SkScalar x, SkScalar y); |
joshualitt | 374b2f7 | 2015-07-21 08:05:03 -0700 | [diff] [blame] | 80 | void internalDrawBMPPosText(GrAtlasTextBlob*, int runIndex, SkGlyphCache*, const SkPaint&, |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 81 | GrColor color, const SkMatrix& viewMatrix, |
| 82 | const char text[], size_t byteLength, |
| 83 | const SkScalar pos[], int scalarsPerPosition, |
robertphillips | 6ee690e | 2015-12-02 08:57:50 -0800 | [diff] [blame] | 84 | const SkPoint& offset); |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 85 | |
jvanverth | 157e648 | 2015-09-09 08:05:12 -0700 | [diff] [blame] | 86 | void internalDrawDFText(GrAtlasTextBlob*, int runIndex, const SkPaint&, |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 87 | GrColor color, const SkMatrix& viewMatrix, |
| 88 | const char text[], size_t byteLength, |
robertphillips | 6ee690e | 2015-12-02 08:57:50 -0800 | [diff] [blame] | 89 | SkScalar x, SkScalar y, |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 90 | SkScalar textRatio, |
| 91 | SkTDArray<char>* fallbackTxt, |
| 92 | SkTDArray<SkScalar>* fallbackPos, |
| 93 | SkPoint* offset, const SkPaint& origPaint); |
jvanverth | 157e648 | 2015-09-09 08:05:12 -0700 | [diff] [blame] | 94 | void internalDrawDFPosText(GrAtlasTextBlob*, int runIndex, const SkPaint&, |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 95 | GrColor color, const SkMatrix& viewMatrix, |
| 96 | const char text[], size_t byteLength, |
| 97 | const SkScalar pos[], int scalarsPerPosition, |
robertphillips | 6ee690e | 2015-12-02 08:57:50 -0800 | [diff] [blame] | 98 | const SkPoint& offset, |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 99 | SkScalar textRatio, |
| 100 | SkTDArray<char>* fallbackTxt, |
| 101 | SkTDArray<SkScalar>* fallbackPos); |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 102 | |
| 103 | // sets up the descriptor on the blob and returns a detached cache. Client must attach |
joshualitt | 9e36c1a | 2015-04-14 12:17:27 -0700 | [diff] [blame] | 104 | inline static GrColor ComputeCanonicalColor(const SkPaint&, bool lcd); |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 105 | inline SkGlyphCache* setupCache(Run*, const SkPaint&, const SkMatrix* viewMatrix, bool noGamma); |
joshualitt | 374b2f7 | 2015-07-21 08:05:03 -0700 | [diff] [blame] | 106 | void regenerateTextBlob(GrAtlasTextBlob* bmp, const SkPaint& skPaint, GrColor, |
joshualitt | 9e36c1a | 2015-04-14 12:17:27 -0700 | [diff] [blame] | 107 | const SkMatrix& viewMatrix, |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 108 | const SkTextBlob* blob, SkScalar x, SkScalar y, |
robertphillips | 6ee690e | 2015-12-02 08:57:50 -0800 | [diff] [blame] | 109 | SkDrawFilter* drawFilter, |
jvanverth | 0628a52 | 2015-08-18 07:44:22 -0700 | [diff] [blame] | 110 | const GrClip&); |
joshualitt | 9e36c1a | 2015-04-14 12:17:27 -0700 | [diff] [blame] | 111 | inline static bool HasLCD(const SkTextBlob*); |
joshualitt | 374b2f7 | 2015-07-21 08:05:03 -0700 | [diff] [blame] | 112 | inline void initDistanceFieldPaint(GrAtlasTextBlob*, SkPaint*, SkScalar* textRatio, |
joshualitt | 64c99cc | 2015-04-21 09:43:03 -0700 | [diff] [blame] | 113 | const SkMatrix&); |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 114 | |
joshualitt | 79dfb2b | 2015-05-11 08:58:08 -0700 | [diff] [blame] | 115 | // Test methods |
| 116 | // TODO this is really ugly. It'd be much nicer if positioning could be moved to batch |
robertphillips | 6ee690e | 2015-12-02 08:57:50 -0800 | [diff] [blame] | 117 | inline GrAtlasTextBlob* createDrawTextBlob(const GrClip&, const GrPaint&, |
| 118 | const SkPaint&, const SkMatrix& viewMatrix, |
| 119 | const char text[], size_t byteLength, |
| 120 | SkScalar x, SkScalar y, |
| 121 | const SkIRect& regionClipBounds); |
| 122 | inline GrAtlasTextBlob* createDrawPosTextBlob(const GrClip&, const GrPaint&, |
| 123 | const SkPaint&, const SkMatrix& viewMatrix, |
| 124 | const char text[], size_t byteLength, |
| 125 | const SkScalar pos[], int scalarsPerPosition, |
| 126 | const SkPoint& offset, |
| 127 | const SkIRect& regionClipBounds); |
joshualitt | 2e2202e | 2015-12-10 11:22:08 -0800 | [diff] [blame^] | 128 | const GrDistanceFieldAdjustTable* dfAdjustTable() const { return fDistanceAdjustTable; } |
joshualitt | 79dfb2b | 2015-05-11 08:58:08 -0700 | [diff] [blame] | 129 | |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 130 | GrBatchTextStrike* fCurrStrike; |
joshualitt | b7133be | 2015-04-08 09:08:31 -0700 | [diff] [blame] | 131 | GrTextBlobCache* fCache; |
joshualitt | 1acabf3 | 2015-12-10 09:10:10 -0800 | [diff] [blame] | 132 | SkAutoTUnref<const GrDistanceFieldAdjustTable> fDistanceAdjustTable; |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 133 | |
joshualitt | 79dfb2b | 2015-05-11 08:58:08 -0700 | [diff] [blame] | 134 | #ifdef GR_TEST_UTILS |
bsalomon | abd30f5 | 2015-08-13 13:34:48 -0700 | [diff] [blame] | 135 | DRAW_BATCH_TEST_FRIEND(TextBlobBatch); |
joshualitt | 79dfb2b | 2015-05-11 08:58:08 -0700 | [diff] [blame] | 136 | #endif |
| 137 | |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 138 | typedef GrTextContext INHERITED; |
| 139 | }; |
| 140 | |
| 141 | #endif |