2 * Copyright 2014 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #ifndef GrStencilAndCoverTextContext_DEFINED
9 #define GrStencilAndCoverTextContext_DEFINED
11 #include "GrTextContext.h"
12 #include "GrDrawState.h"
13 #include "GrDrawTarget.h"
14 #include "SkStrokeRec.h"
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.
25 class GrStencilAndCoverTextContext : public GrTextContext {
27 GrStencilAndCoverTextContext(GrContext*, const SkDeviceProperties&);
28 virtual ~GrStencilAndCoverTextContext();
30 virtual void drawText(const GrPaint&, const SkPaint&, const char text[],
32 SkScalar x, SkScalar y) SK_OVERRIDE;
33 virtual void drawPosText(const GrPaint&, const SkPaint&,
34 const char text[], size_t byteLength,
35 const SkScalar pos[], SkScalar constY,
36 int scalarsPerPosition) SK_OVERRIDE;
38 virtual bool canDraw(const SkPaint& paint) SK_OVERRIDE;
41 static const int kGlyphBufferSize = 1024;
45 * This is the render mode used by drawText(), which is mainly used by
46 * the Skia unit tests. It tries match the other text backends exactly,
47 * with the exception of not implementing LCD text, and doing anti-
48 * aliasing with the built-in MSAA.
50 kMaxAccuracy_RenderMode,
53 * This is the render mode used by drawPosText(). It ignores hinting and
54 * LCD text, even if the client provided positions for hinted glyphs,
55 * and renders from a canonically-sized, generic set of paths for the
56 * given typeface. In the future we should work out a system for the
57 * client to know it should not provide hinted glyph positions. This
58 * render mode also tries to use GPU stroking for fake bold, even when
59 * SK_USE_FREETYPE_EMBOLDEN is set.
61 kMaxPerformance_RenderMode,
64 void init(const GrPaint&, const SkPaint&, size_t textByteLength,
65 RenderMode, SkScalar textTranslateY = 0);
66 void initGlyphs(SkGlyphCache* cache);
67 void appendGlyph(uint16_t glyphID, float x);
68 void appendGlyph(uint16_t glyphID, float x, float y);
72 GrDrawState::AutoRestoreEffects fStateRestore;
74 float fTextInverseRatio;
75 SkGlyphCache* fGlyphCache;
77 uint32_t fIndexBuffer[kGlyphBufferSize];
78 float fTransformBuffer[2 * kGlyphBufferSize];
79 GrDrawTarget::PathTransformType fTransformType;
80 int fPendingGlyphCount;
81 SkMatrix fContextInitialMatrix;
82 bool fNeedsDeviceSpaceGlyphs;