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; |
bsalomon | 1fcc01c | 2015-09-09 09:48:06 -0700 | [diff] [blame] | 18 | class GrPathRangeDraw; |
robertphillips | fcf7829 | 2015-06-19 11:49:52 -0700 | [diff] [blame] | 19 | class SkSurfaceProps; |
kkinnunen | c6cb56f | 2014-06-24 00:12:27 -0700 | [diff] [blame] | 20 | |
| 21 | /* |
| 22 | * This class implements text rendering using stencil and cover path rendering |
| 23 | * (by the means of GrDrawTarget::drawPath). |
| 24 | * This class exposes the functionality through GrTextContext interface. |
| 25 | */ |
| 26 | class GrStencilAndCoverTextContext : public GrTextContext { |
| 27 | public: |
robertphillips | f6703fa | 2015-09-01 05:36:47 -0700 | [diff] [blame] | 28 | static GrStencilAndCoverTextContext* Create(GrContext*, const SkSurfaceProps&); |
jvanverth | 8c27a18 | 2014-10-14 08:45:50 -0700 | [diff] [blame] | 29 | |
kkinnunen | c6cb56f | 2014-06-24 00:12:27 -0700 | [diff] [blame] | 30 | virtual ~GrStencilAndCoverTextContext(); |
| 31 | |
kkinnunen | c6cb56f | 2014-06-24 00:12:27 -0700 | [diff] [blame] | 32 | private: |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 33 | SkScalar fTextRatio; |
| 34 | float fTextInverseRatio; |
| 35 | SkGlyphCache* fGlyphCache; |
bsalomon | 1fcc01c | 2015-09-09 09:48:06 -0700 | [diff] [blame] | 36 | |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 37 | GrPathRange* fGlyphs; |
bsalomon | 1fcc01c | 2015-09-09 09:48:06 -0700 | [diff] [blame] | 38 | GrPathRangeDraw* fDraw; |
kkinnunen | 50b58e6 | 2015-05-18 23:02:07 -0700 | [diff] [blame] | 39 | GrStrokeInfo fStroke; |
bsalomon | 1fcc01c | 2015-09-09 09:48:06 -0700 | [diff] [blame] | 40 | SkSTArray<32, uint16_t, true> fFallbackIndices; |
| 41 | SkSTArray<32, SkPoint, true> fFallbackPositions; |
| 42 | |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 43 | SkMatrix fViewMatrix; |
| 44 | SkMatrix fLocalMatrix; |
joshualitt | 9df4659 | 2015-07-09 10:55:28 -0700 | [diff] [blame] | 45 | SkAutoTUnref<GrRenderTarget> fRenderTarget; |
| 46 | GrClip fClip; |
| 47 | SkIRect fClipRect; |
| 48 | SkIRect fRegionClipBounds; |
| 49 | GrPaint fPaint; |
| 50 | SkPaint fSkPaint; |
jvanverth | 0fedb19 | 2014-10-08 09:07:27 -0700 | [diff] [blame] | 51 | |
robertphillips | f6703fa | 2015-09-01 05:36:47 -0700 | [diff] [blame] | 52 | GrStencilAndCoverTextContext(GrContext*, const SkSurfaceProps&); |
jvanverth | 8c27a18 | 2014-10-14 08:45:50 -0700 | [diff] [blame] | 53 | |
cdalton | e68f736 | 2015-03-25 14:02:37 -0700 | [diff] [blame] | 54 | bool canDraw(const GrRenderTarget*, const GrClip&, const GrPaint&, |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 55 | const SkPaint&, const SkMatrix& viewMatrix) override; |
jvanverth | 8c27a18 | 2014-10-14 08:45:50 -0700 | [diff] [blame] | 56 | |
robertphillips | f6703fa | 2015-09-01 05:36:47 -0700 | [diff] [blame] | 57 | void onDrawText(GrDrawContext*, GrRenderTarget*, const GrClip&, const GrPaint&, const SkPaint&, |
cdalton | e68f736 | 2015-03-25 14:02:37 -0700 | [diff] [blame] | 58 | const SkMatrix& viewMatrix, |
| 59 | const char text[], size_t byteLength, |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 60 | SkScalar x, SkScalar y, const SkIRect& regionClipBounds) override; |
robertphillips | f6703fa | 2015-09-01 05:36:47 -0700 | [diff] [blame] | 61 | void onDrawPosText(GrDrawContext*, GrRenderTarget*, |
| 62 | const GrClip&, const GrPaint&, const SkPaint&, |
cdalton | e68f736 | 2015-03-25 14:02:37 -0700 | [diff] [blame] | 63 | const SkMatrix& viewMatrix, |
| 64 | const char text[], size_t byteLength, |
| 65 | const SkScalar pos[], int scalarsPerPosition, |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 66 | const SkPoint& offset, const SkIRect& regionClipBounds) override; |
jvanverth | 8c27a18 | 2014-10-14 08:45:50 -0700 | [diff] [blame] | 67 | |
cdalton | 7d5c950 | 2015-10-03 13:28:35 -0700 | [diff] [blame] | 68 | void init(GrRenderTarget*, const GrClip&, const GrPaint&, const SkPaint&, size_t textByteLength, |
| 69 | const SkMatrix& viewMatrix, const SkIRect& regionClipBounds); |
bsalomon | 1fcc01c | 2015-09-09 09:48:06 -0700 | [diff] [blame] | 70 | void appendGlyph(const SkGlyph&, const SkPoint&); |
robertphillips | f6703fa | 2015-09-01 05:36:47 -0700 | [diff] [blame] | 71 | void flush(GrDrawContext* dc); |
| 72 | void finish(GrDrawContext* dc); |
kkinnunen | c6cb56f | 2014-06-24 00:12:27 -0700 | [diff] [blame] | 73 | |
bsalomon | 1fcc01c | 2015-09-09 09:48:06 -0700 | [diff] [blame] | 74 | typedef GrTextContext INHERITED; |
kkinnunen | c6cb56f | 2014-06-24 00:12:27 -0700 | [diff] [blame] | 75 | }; |
| 76 | |
| 77 | #endif |