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 | c6cb56f | 2014-06-24 00:12:27 -0700 | [diff] [blame] | 13 | #include "SkStrokeRec.h" |
| 14 | |
| 15 | class GrTextStrike; |
| 16 | class GrPath; |
cdalton | 855d83f | 2014-09-18 13:51:53 -0700 | [diff] [blame] | 17 | class GrPathRange; |
kkinnunen | c6cb56f | 2014-06-24 00:12:27 -0700 | [diff] [blame] | 18 | |
| 19 | /* |
| 20 | * This class implements text rendering using stencil and cover path rendering |
| 21 | * (by the means of GrDrawTarget::drawPath). |
| 22 | * This class exposes the functionality through GrTextContext interface. |
| 23 | */ |
| 24 | class GrStencilAndCoverTextContext : public GrTextContext { |
| 25 | public: |
jvanverth | 8c27a18 | 2014-10-14 08:45:50 -0700 | [diff] [blame] | 26 | static GrStencilAndCoverTextContext* Create(GrContext*, const SkDeviceProperties&); |
| 27 | |
kkinnunen | c6cb56f | 2014-06-24 00:12:27 -0700 | [diff] [blame] | 28 | virtual ~GrStencilAndCoverTextContext(); |
| 29 | |
kkinnunen | c6cb56f | 2014-06-24 00:12:27 -0700 | [diff] [blame] | 30 | private: |
cdalton | b85a0aa | 2014-07-21 15:32:44 -0700 | [diff] [blame] | 31 | static const int kGlyphBufferSize = 1024; |
| 32 | |
cdalton | 855d83f | 2014-09-18 13:51:53 -0700 | [diff] [blame] | 33 | enum RenderMode { |
| 34 | /** |
| 35 | * This is the render mode used by drawText(), which is mainly used by |
| 36 | * the Skia unit tests. It tries match the other text backends exactly, |
| 37 | * with the exception of not implementing LCD text, and doing anti- |
| 38 | * aliasing with the built-in MSAA. |
| 39 | */ |
| 40 | kMaxAccuracy_RenderMode, |
| 41 | |
| 42 | /** |
| 43 | * This is the render mode used by drawPosText(). It ignores hinting and |
| 44 | * LCD text, even if the client provided positions for hinted glyphs, |
| 45 | * and renders from a canonically-sized, generic set of paths for the |
| 46 | * given typeface. In the future we should work out a system for the |
| 47 | * client to know it should not provide hinted glyph positions. This |
| 48 | * render mode also tries to use GPU stroking for fake bold, even when |
| 49 | * SK_USE_FREETYPE_EMBOLDEN is set. |
| 50 | */ |
| 51 | kMaxPerformance_RenderMode, |
cdalton | b2808cd | 2014-07-25 14:13:57 -0700 | [diff] [blame] | 52 | }; |
cdalton | 855d83f | 2014-09-18 13:51:53 -0700 | [diff] [blame] | 53 | |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 54 | GrDrawState fDrawState; |
jvanverth | 0fedb19 | 2014-10-08 09:07:27 -0700 | [diff] [blame] | 55 | GrDrawState::AutoRestoreEffects fStateRestore; |
| 56 | SkScalar fTextRatio; |
| 57 | float fTextInverseRatio; |
| 58 | SkGlyphCache* fGlyphCache; |
| 59 | GrPathRange* fGlyphs; |
| 60 | uint32_t fIndexBuffer[kGlyphBufferSize]; |
| 61 | float fTransformBuffer[2 * kGlyphBufferSize]; |
jvanverth | 0fedb19 | 2014-10-08 09:07:27 -0700 | [diff] [blame] | 62 | int fPendingGlyphCount; |
| 63 | SkMatrix fContextInitialMatrix; |
| 64 | bool fNeedsDeviceSpaceGlyphs; |
| 65 | |
jvanverth | 8c27a18 | 2014-10-14 08:45:50 -0700 | [diff] [blame] | 66 | GrStencilAndCoverTextContext(GrContext*, const SkDeviceProperties&); |
| 67 | |
| 68 | virtual bool canDraw(const SkPaint& paint) SK_OVERRIDE; |
| 69 | |
jvanverth | aab626c | 2014-10-16 08:04:39 -0700 | [diff] [blame] | 70 | virtual void onDrawText(const GrPaint&, const SkPaint&, const char text[], |
| 71 | size_t byteLength, |
| 72 | SkScalar x, SkScalar y) SK_OVERRIDE; |
jvanverth | 8c27a18 | 2014-10-14 08:45:50 -0700 | [diff] [blame] | 73 | virtual void onDrawPosText(const GrPaint&, const SkPaint&, |
| 74 | const char text[], size_t byteLength, |
| 75 | const SkScalar pos[], int scalarsPerPosition, |
| 76 | const SkPoint& offset) SK_OVERRIDE; |
| 77 | |
cdalton | 38e13ad | 2014-11-07 06:02:15 -0800 | [diff] [blame] | 78 | void init(const GrPaint&, const SkPaint&, size_t textByteLength, RenderMode); |
cdalton | b85a0aa | 2014-07-21 15:32:44 -0700 | [diff] [blame] | 79 | void appendGlyph(uint16_t glyphID, float x, float y); |
| 80 | void flush(); |
kkinnunen | c6cb56f | 2014-06-24 00:12:27 -0700 | [diff] [blame] | 81 | void finish(); |
| 82 | |
kkinnunen | c6cb56f | 2014-06-24 00:12:27 -0700 | [diff] [blame] | 83 | }; |
| 84 | |
| 85 | #endif |