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" |
| 12 | #include "GrDrawState.h" |
cdalton | b2808cd | 2014-07-25 14:13:57 -0700 | [diff] [blame^] | 13 | #include "GrDrawTarget.h" |
kkinnunen | c6cb56f | 2014-06-24 00:12:27 -0700 | [diff] [blame] | 14 | #include "SkStrokeRec.h" |
| 15 | |
| 16 | class GrTextStrike; |
| 17 | class GrPath; |
| 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: |
| 26 | GrStencilAndCoverTextContext(GrContext*, const SkDeviceProperties&); |
| 27 | virtual ~GrStencilAndCoverTextContext(); |
| 28 | |
| 29 | virtual void drawText(const GrPaint&, const SkPaint&, const char text[], |
| 30 | size_t byteLength, |
| 31 | SkScalar x, SkScalar y) SK_OVERRIDE; |
| 32 | virtual void drawPosText(const GrPaint&, const SkPaint&, |
| 33 | const char text[], size_t byteLength, |
| 34 | const SkScalar pos[], SkScalar constY, |
| 35 | int scalarsPerPosition) SK_OVERRIDE; |
| 36 | |
| 37 | virtual bool canDraw(const SkPaint& paint) SK_OVERRIDE; |
| 38 | |
| 39 | private: |
cdalton | b85a0aa | 2014-07-21 15:32:44 -0700 | [diff] [blame] | 40 | class GlyphPathRange; |
| 41 | static const int kGlyphBufferSize = 1024; |
| 42 | |
cdalton | b2808cd | 2014-07-25 14:13:57 -0700 | [diff] [blame^] | 43 | enum DeviceSpaceGlyphsBehavior { |
| 44 | kUseIfNeeded_DeviceSpaceGlyphsBehavior, |
| 45 | kDoNotUse_DeviceSpaceGlyphsBehavior, |
| 46 | }; |
| 47 | void init(const GrPaint&, const SkPaint&, size_t textByteLength, |
| 48 | DeviceSpaceGlyphsBehavior, SkScalar textTranslateY = 0); |
cdalton | b85a0aa | 2014-07-21 15:32:44 -0700 | [diff] [blame] | 49 | void initGlyphs(SkGlyphCache* cache); |
cdalton | b2808cd | 2014-07-25 14:13:57 -0700 | [diff] [blame^] | 50 | void appendGlyph(uint16_t glyphID, float x); |
cdalton | b85a0aa | 2014-07-21 15:32:44 -0700 | [diff] [blame] | 51 | void appendGlyph(uint16_t glyphID, float x, float y); |
| 52 | void flush(); |
kkinnunen | c6cb56f | 2014-06-24 00:12:27 -0700 | [diff] [blame] | 53 | void finish(); |
| 54 | |
| 55 | GrDrawState::AutoRestoreEffects fStateRestore; |
| 56 | SkScalar fTextRatio; |
cdalton | b2808cd | 2014-07-25 14:13:57 -0700 | [diff] [blame^] | 57 | float fTextInverseRatio; |
kkinnunen | c6cb56f | 2014-06-24 00:12:27 -0700 | [diff] [blame] | 58 | SkStrokeRec fStroke; |
cdalton | b85a0aa | 2014-07-21 15:32:44 -0700 | [diff] [blame] | 59 | SkGlyphCache* fGlyphCache; |
| 60 | GlyphPathRange* fGlyphs; |
| 61 | uint32_t fIndexBuffer[kGlyphBufferSize]; |
cdalton | b2808cd | 2014-07-25 14:13:57 -0700 | [diff] [blame^] | 62 | float fTransformBuffer[2 * kGlyphBufferSize]; |
| 63 | GrDrawTarget::PathTransformType fTransformType; |
cdalton | b85a0aa | 2014-07-21 15:32:44 -0700 | [diff] [blame] | 64 | int fPendingGlyphCount; |
cdalton | b2808cd | 2014-07-25 14:13:57 -0700 | [diff] [blame^] | 65 | SkMatrix fContextInitialMatrix; |
kkinnunen | c6cb56f | 2014-06-24 00:12:27 -0700 | [diff] [blame] | 66 | bool fNeedsDeviceSpaceGlyphs; |
| 67 | }; |
| 68 | |
| 69 | #endif |