blob: b6e23bdb3feeb0b2bd5667d0c235716a22485ddb [file] [log] [blame]
kkinnunenc6cb56f2014-06-24 00:12:27 -07001/*
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"
cdaltonb2808cd2014-07-25 14:13:57 -070013#include "GrDrawTarget.h"
kkinnunenc6cb56f2014-06-24 00:12:27 -070014#include "SkStrokeRec.h"
15
16class GrTextStrike;
17class GrPath;
cdalton855d83f2014-09-18 13:51:53 -070018class GrPathRange;
kkinnunenc6cb56f2014-06-24 00:12:27 -070019
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 */
25class GrStencilAndCoverTextContext : public GrTextContext {
26public:
27 GrStencilAndCoverTextContext(GrContext*, const SkDeviceProperties&);
28 virtual ~GrStencilAndCoverTextContext();
29
30 virtual void drawText(const GrPaint&, const SkPaint&, const char text[],
31 size_t byteLength,
32 SkScalar x, SkScalar y) SK_OVERRIDE;
33 virtual void drawPosText(const GrPaint&, const SkPaint&,
34 const char text[], size_t byteLength,
fmalita05c4a432014-09-29 06:29:53 -070035 const SkScalar pos[], int scalarsPerPosition,
36 const SkPoint& offset) SK_OVERRIDE;
kkinnunenc6cb56f2014-06-24 00:12:27 -070037
38 virtual bool canDraw(const SkPaint& paint) SK_OVERRIDE;
39
40private:
cdaltonb85a0aa2014-07-21 15:32:44 -070041 static const int kGlyphBufferSize = 1024;
42
cdalton855d83f2014-09-18 13:51:53 -070043 enum RenderMode {
44 /**
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.
49 */
50 kMaxAccuracy_RenderMode,
51
52 /**
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.
60 */
61 kMaxPerformance_RenderMode,
cdaltonb2808cd2014-07-25 14:13:57 -070062 };
cdalton855d83f2014-09-18 13:51:53 -070063
cdaltonb2808cd2014-07-25 14:13:57 -070064 void init(const GrPaint&, const SkPaint&, size_t textByteLength,
fmalita05c4a432014-09-29 06:29:53 -070065 RenderMode, const SkPoint& textTranslate);
cdaltonb85a0aa2014-07-21 15:32:44 -070066 void initGlyphs(SkGlyphCache* cache);
cdaltonb2808cd2014-07-25 14:13:57 -070067 void appendGlyph(uint16_t glyphID, float x);
cdaltonb85a0aa2014-07-21 15:32:44 -070068 void appendGlyph(uint16_t glyphID, float x, float y);
69 void flush();
kkinnunenc6cb56f2014-06-24 00:12:27 -070070 void finish();
71
72 GrDrawState::AutoRestoreEffects fStateRestore;
73 SkScalar fTextRatio;
cdaltonb2808cd2014-07-25 14:13:57 -070074 float fTextInverseRatio;
cdaltonb85a0aa2014-07-21 15:32:44 -070075 SkGlyphCache* fGlyphCache;
cdalton855d83f2014-09-18 13:51:53 -070076 GrPathRange* fGlyphs;
cdaltonb85a0aa2014-07-21 15:32:44 -070077 uint32_t fIndexBuffer[kGlyphBufferSize];
cdaltonb2808cd2014-07-25 14:13:57 -070078 float fTransformBuffer[2 * kGlyphBufferSize];
79 GrDrawTarget::PathTransformType fTransformType;
cdaltonb85a0aa2014-07-21 15:32:44 -070080 int fPendingGlyphCount;
cdaltonb2808cd2014-07-25 14:13:57 -070081 SkMatrix fContextInitialMatrix;
kkinnunenc6cb56f2014-06-24 00:12:27 -070082 bool fNeedsDeviceSpaceGlyphs;
83};
84
85#endif