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: |
cdalton | b85a0aa | 2014-07-21 15:32:44 -0700 | [diff] [blame] | 32 | static const int kGlyphBufferSize = 1024; |
| 33 | |
cdalton | 855d83f | 2014-09-18 13:51:53 -0700 | [diff] [blame] | 34 | enum RenderMode { |
| 35 | /** |
| 36 | * This is the render mode used by drawText(), which is mainly used by |
| 37 | * the Skia unit tests. It tries match the other text backends exactly, |
| 38 | * with the exception of not implementing LCD text, and doing anti- |
| 39 | * aliasing with the built-in MSAA. |
| 40 | */ |
| 41 | kMaxAccuracy_RenderMode, |
| 42 | |
| 43 | /** |
| 44 | * This is the render mode used by drawPosText(). It ignores hinting and |
| 45 | * LCD text, even if the client provided positions for hinted glyphs, |
| 46 | * and renders from a canonically-sized, generic set of paths for the |
| 47 | * given typeface. In the future we should work out a system for the |
| 48 | * client to know it should not provide hinted glyph positions. This |
| 49 | * render mode also tries to use GPU stroking for fake bold, even when |
| 50 | * SK_USE_FREETYPE_EMBOLDEN is set. |
| 51 | */ |
| 52 | kMaxPerformance_RenderMode, |
cdalton | b2808cd | 2014-07-25 14:13:57 -0700 | [diff] [blame] | 53 | }; |
cdalton | 855d83f | 2014-09-18 13:51:53 -0700 | [diff] [blame] | 54 | |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 55 | SkScalar fTextRatio; |
| 56 | float fTextInverseRatio; |
| 57 | SkGlyphCache* fGlyphCache; |
| 58 | GrPathRange* fGlyphs; |
kkinnunen | 50b58e6 | 2015-05-18 23:02:07 -0700 | [diff] [blame] | 59 | GrStrokeInfo fStroke; |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 60 | uint16_t fGlyphIndices[kGlyphBufferSize]; |
| 61 | SkPoint fGlyphPositions[kGlyphBufferSize]; |
| 62 | int fQueuedGlyphCount; |
| 63 | int fFallbackGlyphsIdx; |
| 64 | SkMatrix fContextInitialMatrix; |
| 65 | SkMatrix fViewMatrix; |
| 66 | SkMatrix fLocalMatrix; |
| 67 | bool fUsingDeviceSpaceGlyphs; |
joshualitt | 9df4659 | 2015-07-09 10:55:28 -0700 | [diff] [blame] | 68 | SkAutoTUnref<GrRenderTarget> fRenderTarget; |
| 69 | GrClip fClip; |
| 70 | SkIRect fClipRect; |
| 71 | SkIRect fRegionClipBounds; |
| 72 | GrPaint fPaint; |
| 73 | SkPaint fSkPaint; |
jvanverth | 0fedb19 | 2014-10-08 09:07:27 -0700 | [diff] [blame] | 74 | |
robertphillips | f6703fa | 2015-09-01 05:36:47 -0700 | [diff] [blame^] | 75 | GrStencilAndCoverTextContext(GrContext*, const SkSurfaceProps&); |
jvanverth | 8c27a18 | 2014-10-14 08:45:50 -0700 | [diff] [blame] | 76 | |
cdalton | e68f736 | 2015-03-25 14:02:37 -0700 | [diff] [blame] | 77 | bool canDraw(const GrRenderTarget*, const GrClip&, const GrPaint&, |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 78 | const SkPaint&, const SkMatrix& viewMatrix) override; |
jvanverth | 8c27a18 | 2014-10-14 08:45:50 -0700 | [diff] [blame] | 79 | |
robertphillips | f6703fa | 2015-09-01 05:36:47 -0700 | [diff] [blame^] | 80 | void onDrawText(GrDrawContext*, GrRenderTarget*, const GrClip&, const GrPaint&, const SkPaint&, |
cdalton | e68f736 | 2015-03-25 14:02:37 -0700 | [diff] [blame] | 81 | const SkMatrix& viewMatrix, |
| 82 | const char text[], size_t byteLength, |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 83 | SkScalar x, SkScalar y, const SkIRect& regionClipBounds) override; |
robertphillips | f6703fa | 2015-09-01 05:36:47 -0700 | [diff] [blame^] | 84 | void onDrawPosText(GrDrawContext*, GrRenderTarget*, |
| 85 | const GrClip&, const GrPaint&, const SkPaint&, |
cdalton | e68f736 | 2015-03-25 14:02:37 -0700 | [diff] [blame] | 86 | const SkMatrix& viewMatrix, |
| 87 | const char text[], size_t byteLength, |
| 88 | const SkScalar pos[], int scalarsPerPosition, |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 89 | const SkPoint& offset, const SkIRect& regionClipBounds) override; |
jvanverth | 8c27a18 | 2014-10-14 08:45:50 -0700 | [diff] [blame] | 90 | |
joshualitt | 570d2f8 | 2015-02-25 13:19:48 -0800 | [diff] [blame] | 91 | void init(GrRenderTarget*, const GrClip&, const GrPaint&, const SkPaint&, |
joshualitt | 6e8cd96 | 2015-03-20 10:30:14 -0700 | [diff] [blame] | 92 | size_t textByteLength, RenderMode, const SkMatrix& viewMatrix, |
| 93 | const SkIRect& regionClipBounds); |
joshualitt | 5531d51 | 2014-12-17 15:50:11 -0800 | [diff] [blame] | 94 | bool mapToFallbackContext(SkMatrix* inverse); |
robertphillips | f6703fa | 2015-09-01 05:36:47 -0700 | [diff] [blame^] | 95 | void appendGlyph(GrDrawContext* dc, const SkGlyph&, const SkPoint&); |
| 96 | void flush(GrDrawContext* dc); |
| 97 | void finish(GrDrawContext* dc); |
kkinnunen | c6cb56f | 2014-06-24 00:12:27 -0700 | [diff] [blame] | 98 | |
kkinnunen | c6cb56f | 2014-06-24 00:12:27 -0700 | [diff] [blame] | 99 | }; |
| 100 | |
| 101 | #endif |