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 | |
joshualitt | 374b2f7 | 2015-07-21 08:05:03 -0700 | [diff] [blame] | 11 | #include "GrAtlasTextBlob.h" |
joshualitt | 1acabf3 | 2015-12-10 09:10:10 -0800 | [diff] [blame] | 12 | #include "GrDistanceFieldAdjustTable.h" |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 13 | #include "GrGeometryProcessor.h" |
halcanary | 3377975 | 2015-10-27 14:01:05 -0700 | [diff] [blame] | 14 | #include "SkTextBlobRunIterator.h" |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 15 | |
joshualitt | 79dfb2b | 2015-05-11 08:58:08 -0700 | [diff] [blame] | 16 | #ifdef GR_TEST_UTILS |
| 17 | #include "GrBatchTest.h" |
| 18 | #endif |
| 19 | |
bsalomon | abd30f5 | 2015-08-13 13:34:48 -0700 | [diff] [blame] | 20 | class GrDrawBatch; |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 21 | class GrDrawContext; |
robertphillips | 2334fb6 | 2015-06-17 05:43:33 -0700 | [diff] [blame] | 22 | class GrDrawTarget; |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 23 | class GrPipelineBuilder; |
joshualitt | b7133be | 2015-04-08 09:08:31 -0700 | [diff] [blame] | 24 | class GrTextBlobCache; |
joshualitt | 6c2c2b0 | 2015-07-24 10:37:00 -0700 | [diff] [blame] | 25 | class SkGlyph; |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 26 | |
| 27 | /* |
joshualitt | 8e84a1e | 2016-02-16 11:09:25 -0800 | [diff] [blame] | 28 | * Renders text using some kind of an atlas, ie BitmapText or DistanceField text |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 29 | */ |
joshualitt | 8e84a1e | 2016-02-16 11:09:25 -0800 | [diff] [blame] | 30 | class GrAtlasTextContext { |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 31 | public: |
joshualitt | 27004b7 | 2016-02-11 12:00:33 -0800 | [diff] [blame] | 32 | static GrAtlasTextContext* Create(); |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 33 | |
joshualitt | 27004b7 | 2016-02-11 12:00:33 -0800 | [diff] [blame] | 34 | bool canDraw(const SkPaint&, const SkMatrix& viewMatrix, const SkSurfaceProps&, |
| 35 | const GrShaderCaps&); |
| 36 | void drawText(GrContext*, GrDrawContext*, const GrClip&, const GrPaint&, const SkPaint&, |
joshualitt | 2c89bc1 | 2016-02-11 05:42:30 -0800 | [diff] [blame] | 37 | const SkMatrix& viewMatrix, const SkSurfaceProps&, const char text[], |
| 38 | size_t byteLength, SkScalar x, SkScalar y, |
joshualitt | 8e84a1e | 2016-02-16 11:09:25 -0800 | [diff] [blame] | 39 | const SkIRect& regionClipBounds); |
joshualitt | 27004b7 | 2016-02-11 12:00:33 -0800 | [diff] [blame] | 40 | void drawPosText(GrContext*, GrDrawContext*, const GrClip&, const GrPaint&, |
joshualitt | 2c89bc1 | 2016-02-11 05:42:30 -0800 | [diff] [blame] | 41 | const SkPaint&, const SkMatrix& viewMatrix, const SkSurfaceProps&, |
joshualitt | e55750e | 2016-02-10 12:52:21 -0800 | [diff] [blame] | 42 | const char text[], size_t byteLength, |
| 43 | const SkScalar pos[], int scalarsPerPosition, |
joshualitt | 8e84a1e | 2016-02-16 11:09:25 -0800 | [diff] [blame] | 44 | const SkPoint& offset, const SkIRect& regionClipBounds); |
joshualitt | 27004b7 | 2016-02-11 12:00:33 -0800 | [diff] [blame] | 45 | void drawTextBlob(GrContext*, GrDrawContext*, const GrClip&, const SkPaint&, |
joshualitt | 2c89bc1 | 2016-02-11 05:42:30 -0800 | [diff] [blame] | 46 | const SkMatrix& viewMatrix, const SkSurfaceProps&, const SkTextBlob*, |
| 47 | SkScalar x, SkScalar y, |
joshualitt | 8e84a1e | 2016-02-16 11:09:25 -0800 | [diff] [blame] | 48 | SkDrawFilter*, const SkIRect& clipBounds); |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 49 | |
joshualitt | e55750e | 2016-02-10 12:52:21 -0800 | [diff] [blame] | 50 | private: |
joshualitt | 27004b7 | 2016-02-11 12:00:33 -0800 | [diff] [blame] | 51 | GrAtlasTextContext(); |
joshualitt | e55750e | 2016-02-10 12:52:21 -0800 | [diff] [blame] | 52 | |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 53 | // 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] | 54 | inline static GrColor ComputeCanonicalColor(const SkPaint&, bool lcd); |
joshualitt | 27004b7 | 2016-02-11 12:00:33 -0800 | [diff] [blame] | 55 | static void RegenerateTextBlob(GrAtlasTextBlob* bmp, |
| 56 | GrBatchFontCache*, |
| 57 | const GrShaderCaps&, |
| 58 | const SkPaint& skPaint, GrColor, |
| 59 | const SkMatrix& viewMatrix, |
| 60 | const SkSurfaceProps&, |
| 61 | const SkTextBlob* blob, SkScalar x, SkScalar y, |
| 62 | SkDrawFilter* drawFilter); |
joshualitt | 9e36c1a | 2015-04-14 12:17:27 -0700 | [diff] [blame] | 63 | inline static bool HasLCD(const SkTextBlob*); |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 64 | |
joshualitt | 27004b7 | 2016-02-11 12:00:33 -0800 | [diff] [blame] | 65 | static inline GrAtlasTextBlob* CreateDrawTextBlob(GrTextBlobCache*, |
| 66 | GrBatchFontCache*, const GrShaderCaps&, |
| 67 | const GrPaint&, |
| 68 | const SkPaint&, const SkMatrix& viewMatrix, |
| 69 | const SkSurfaceProps&, |
| 70 | const char text[], size_t byteLength, |
| 71 | SkScalar x, SkScalar y); |
| 72 | static inline GrAtlasTextBlob* CreateDrawPosTextBlob(GrTextBlobCache*, GrBatchFontCache*, |
| 73 | const GrShaderCaps&, |
| 74 | const GrPaint&, |
| 75 | const SkPaint&, const SkMatrix& viewMatrix, |
| 76 | const SkSurfaceProps&, |
| 77 | const char text[], size_t byteLength, |
| 78 | const SkScalar pos[], |
| 79 | int scalarsPerPosition, |
| 80 | const SkPoint& offset); |
joshualitt | 2e2202e | 2015-12-10 11:22:08 -0800 | [diff] [blame] | 81 | const GrDistanceFieldAdjustTable* dfAdjustTable() const { return fDistanceAdjustTable; } |
joshualitt | 79dfb2b | 2015-05-11 08:58:08 -0700 | [diff] [blame] | 82 | |
joshualitt | 1acabf3 | 2015-12-10 09:10:10 -0800 | [diff] [blame] | 83 | SkAutoTUnref<const GrDistanceFieldAdjustTable> fDistanceAdjustTable; |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 84 | |
joshualitt | 79dfb2b | 2015-05-11 08:58:08 -0700 | [diff] [blame] | 85 | #ifdef GR_TEST_UTILS |
bsalomon | abd30f5 | 2015-08-13 13:34:48 -0700 | [diff] [blame] | 86 | DRAW_BATCH_TEST_FRIEND(TextBlobBatch); |
joshualitt | 79dfb2b | 2015-05-11 08:58:08 -0700 | [diff] [blame] | 87 | #endif |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 88 | }; |
| 89 | |
| 90 | #endif |