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 static GrStencilAndCoverTextContext* Create(GrContext*, const SkDeviceProperties&);
29 virtual ~GrStencilAndCoverTextContext();
32 static const int kGlyphBufferSize = 1024;
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.
41 kMaxAccuracy_RenderMode,
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.
52 kMaxPerformance_RenderMode,
55 GrDrawState::AutoRestoreEffects fStateRestore;
57 float fTextInverseRatio;
58 SkGlyphCache* fGlyphCache;
60 uint32_t fIndexBuffer[kGlyphBufferSize];
61 float fTransformBuffer[2 * kGlyphBufferSize];
62 GrDrawTarget::PathTransformType fTransformType;
63 int fPendingGlyphCount;
64 SkMatrix fContextInitialMatrix;
65 bool fNeedsDeviceSpaceGlyphs;
67 GrStencilAndCoverTextContext(GrContext*, const SkDeviceProperties&);
69 virtual bool canDraw(const SkPaint& paint) SK_OVERRIDE;
71 virtual void onDrawText(const GrPaint&, const SkPaint&, const char text[],
73 SkScalar x, SkScalar y) SK_OVERRIDE;
74 virtual void onDrawPosText(const GrPaint&, const SkPaint&,
75 const char text[], size_t byteLength,
76 const SkScalar pos[], int scalarsPerPosition,
77 const SkPoint& offset) SK_OVERRIDE;
79 void init(const GrPaint&, const SkPaint&, size_t textByteLength,
80 RenderMode, const SkPoint& textTranslate);
81 void initGlyphs(SkGlyphCache* cache);
82 void appendGlyph(uint16_t glyphID, float x);
83 void appendGlyph(uint16_t glyphID, float x, float y);