blob: 40d38c2375d7a3a64808870fafa62e751b52f6b1 [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:
jvanverth8c27a182014-10-14 08:45:50 -070027 static GrStencilAndCoverTextContext* Create(GrContext*, const SkDeviceProperties&);
28
kkinnunenc6cb56f2014-06-24 00:12:27 -070029 virtual ~GrStencilAndCoverTextContext();
30
kkinnunenc6cb56f2014-06-24 00:12:27 -070031private:
cdaltonb85a0aa2014-07-21 15:32:44 -070032 static const int kGlyphBufferSize = 1024;
33
cdalton855d83f2014-09-18 13:51:53 -070034 enum RenderMode {
35 /**
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.
40 */
41 kMaxAccuracy_RenderMode,
42
43 /**
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.
51 */
52 kMaxPerformance_RenderMode,
cdaltonb2808cd2014-07-25 14:13:57 -070053 };
cdalton855d83f2014-09-18 13:51:53 -070054
jvanverth0fedb192014-10-08 09:07:27 -070055 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];
62 GrDrawTarget::PathTransformType fTransformType;
63 int fPendingGlyphCount;
64 SkMatrix fContextInitialMatrix;
65 bool fNeedsDeviceSpaceGlyphs;
66
jvanverth8c27a182014-10-14 08:45:50 -070067 GrStencilAndCoverTextContext(GrContext*, const SkDeviceProperties&);
68
69 virtual bool canDraw(const SkPaint& paint) SK_OVERRIDE;
70
jvanverthaab626c2014-10-16 08:04:39 -070071 virtual void onDrawText(const GrPaint&, const SkPaint&, const char text[],
72 size_t byteLength,
73 SkScalar x, SkScalar y) SK_OVERRIDE;
jvanverth8c27a182014-10-14 08:45:50 -070074 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;
78
cdaltonb2808cd2014-07-25 14:13:57 -070079 void init(const GrPaint&, const SkPaint&, size_t textByteLength,
fmalita05c4a432014-09-29 06:29:53 -070080 RenderMode, const SkPoint& textTranslate);
cdaltonb85a0aa2014-07-21 15:32:44 -070081 void initGlyphs(SkGlyphCache* cache);
cdaltonb2808cd2014-07-25 14:13:57 -070082 void appendGlyph(uint16_t glyphID, float x);
cdaltonb85a0aa2014-07-21 15:32:44 -070083 void appendGlyph(uint16_t glyphID, float x, float y);
84 void flush();
kkinnunenc6cb56f2014-06-24 00:12:27 -070085 void finish();
86
kkinnunenc6cb56f2014-06-24 00:12:27 -070087};
88
89#endif