kkinnunen | c6cb56f | 2014-06-24 00:12:27 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 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 GrStencilAndCoverTextContext_DEFINED |
| 9 | #define GrStencilAndCoverTextContext_DEFINED |
| 10 | |
| 11 | #include "GrTextContext.h" |
cdalton | b2808cd | 2014-07-25 14:13:57 -0700 | [diff] [blame] | 12 | #include "GrDrawTarget.h" |
kkinnunen | 50b58e6 | 2015-05-18 23:02:07 -0700 | [diff] [blame] | 13 | #include "GrStrokeInfo.h" |
kkinnunen | c6cb56f | 2014-06-24 00:12:27 -0700 | [diff] [blame] | 14 | |
| 15 | class GrTextStrike; |
| 16 | class GrPath; |
cdalton | 855d83f | 2014-09-18 13:51:53 -0700 | [diff] [blame] | 17 | class GrPathRange; |
robertphillips | fcf7829 | 2015-06-19 11:49:52 -0700 | [diff] [blame] | 18 | class SkSurfaceProps; |
kkinnunen | c6cb56f | 2014-06-24 00:12:27 -0700 | [diff] [blame] | 19 | |
| 20 | /* |
| 21 | * This class implements text rendering using stencil and cover path rendering |
| 22 | * (by the means of GrDrawTarget::drawPath). |
| 23 | * This class exposes the functionality through GrTextContext interface. |
| 24 | */ |
| 25 | class GrStencilAndCoverTextContext : public GrTextContext { |
| 26 | public: |
robertphillips | f6703fa | 2015-09-01 05:36:47 -0700 | [diff] [blame] | 27 | static GrStencilAndCoverTextContext* Create(GrContext*, const SkSurfaceProps&); |
jvanverth | 8c27a18 | 2014-10-14 08:45:50 -0700 | [diff] [blame] | 28 | |
kkinnunen | c6cb56f | 2014-06-24 00:12:27 -0700 | [diff] [blame] | 29 | virtual ~GrStencilAndCoverTextContext(); |
| 30 | |
kkinnunen | c6cb56f | 2014-06-24 00:12:27 -0700 | [diff] [blame] | 31 | private: |
robertphillips | f6703fa | 2015-09-01 05:36:47 -0700 | [diff] [blame] | 32 | GrStencilAndCoverTextContext(GrContext*, const SkSurfaceProps&); |
jvanverth | 8c27a18 | 2014-10-14 08:45:50 -0700 | [diff] [blame] | 33 | |
cdalton | e68f736 | 2015-03-25 14:02:37 -0700 | [diff] [blame] | 34 | bool canDraw(const GrRenderTarget*, const GrClip&, const GrPaint&, |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 35 | const SkPaint&, const SkMatrix& viewMatrix) override; |
jvanverth | 8c27a18 | 2014-10-14 08:45:50 -0700 | [diff] [blame] | 36 | |
robertphillips | f6703fa | 2015-09-01 05:36:47 -0700 | [diff] [blame] | 37 | void onDrawText(GrDrawContext*, GrRenderTarget*, const GrClip&, const GrPaint&, const SkPaint&, |
cdalton | e68f736 | 2015-03-25 14:02:37 -0700 | [diff] [blame] | 38 | const SkMatrix& viewMatrix, |
| 39 | const char text[], size_t byteLength, |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 40 | SkScalar x, SkScalar y, const SkIRect& regionClipBounds) override; |
robertphillips | f6703fa | 2015-09-01 05:36:47 -0700 | [diff] [blame] | 41 | void onDrawPosText(GrDrawContext*, GrRenderTarget*, |
| 42 | const GrClip&, const GrPaint&, const SkPaint&, |
cdalton | e68f736 | 2015-03-25 14:02:37 -0700 | [diff] [blame] | 43 | const SkMatrix& viewMatrix, |
| 44 | const char text[], size_t byteLength, |
| 45 | const SkScalar pos[], int scalarsPerPosition, |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 46 | const SkPoint& offset, const SkIRect& regionClipBounds) override; |
jvanverth | 8c27a18 | 2014-10-14 08:45:50 -0700 | [diff] [blame] | 47 | |
cdalton | 3bd909a | 2015-10-05 14:57:20 -0700 | [diff] [blame^] | 48 | class TextRun { |
| 49 | public: |
| 50 | TextRun(const SkPaint& fontAndStroke); |
| 51 | ~TextRun(); |
| 52 | |
| 53 | void setText(const char text[], size_t byteLength, SkScalar x, SkScalar y, |
| 54 | GrContext*, const SkSurfaceProps*); |
| 55 | |
| 56 | void setPosText(const char text[], size_t byteLength, |
| 57 | const SkScalar pos[], int scalarsPerPosition, const SkPoint& offset, |
| 58 | GrContext*, const SkSurfaceProps*); |
| 59 | |
| 60 | void draw(GrDrawContext*, GrRenderTarget*, const GrClip&, const GrPaint&, const SkMatrix&, |
| 61 | const SkIRect& regionClipBounds, GrTextContext* fallbackTextContext, |
| 62 | const SkPaint& originalSkPaint) const; |
| 63 | |
| 64 | private: |
| 65 | GrPathRange* createGlyphs(GrContext*, SkGlyphCache*); |
| 66 | |
| 67 | void appendGlyph(const SkGlyph&, const SkPoint&); |
| 68 | |
| 69 | GrStrokeInfo fStroke; |
| 70 | SkPaint fFont; |
| 71 | SkScalar fTextRatio; |
| 72 | float fTextInverseRatio; |
| 73 | SkMatrix fLocalMatrix; |
| 74 | bool fUsingRawGlyphPaths; |
| 75 | SkAutoTUnref<GrPathRangeDraw> fDraw; |
| 76 | SkSTArray<32, uint16_t, true> fFallbackIndices; |
| 77 | SkSTArray<32, SkPoint, true> fFallbackPositions; |
| 78 | }; |
kkinnunen | c6cb56f | 2014-06-24 00:12:27 -0700 | [diff] [blame] | 79 | |
bsalomon | 1fcc01c | 2015-09-09 09:48:06 -0700 | [diff] [blame] | 80 | typedef GrTextContext INHERITED; |
kkinnunen | c6cb56f | 2014-06-24 00:12:27 -0700 | [diff] [blame] | 81 | }; |
| 82 | |
| 83 | #endif |