blob: dabd3b388de04127440b7adedcf75e2ac2cdaf9c [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"
cdaltonb2808cd2014-07-25 14:13:57 -070012#include "GrDrawTarget.h"
kkinnunenc6cb56f2014-06-24 00:12:27 -070013#include "SkStrokeRec.h"
14
15class GrTextStrike;
16class GrPath;
cdalton855d83f2014-09-18 13:51:53 -070017class GrPathRange;
kkinnunenc6cb56f2014-06-24 00:12:27 -070018
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 */
24class GrStencilAndCoverTextContext : public GrTextContext {
25public:
jvanverth8c27a182014-10-14 08:45:50 -070026 static GrStencilAndCoverTextContext* Create(GrContext*, const SkDeviceProperties&);
27
kkinnunenc6cb56f2014-06-24 00:12:27 -070028 virtual ~GrStencilAndCoverTextContext();
29
kkinnunenc6cb56f2014-06-24 00:12:27 -070030private:
cdaltonb85a0aa2014-07-21 15:32:44 -070031 static const int kGlyphBufferSize = 1024;
32
cdalton855d83f2014-09-18 13:51:53 -070033 enum RenderMode {
34 /**
35 * This is the render mode used by drawText(), which is mainly used by
36 * the Skia unit tests. It tries match the other text backends exactly,
37 * with the exception of not implementing LCD text, and doing anti-
38 * aliasing with the built-in MSAA.
39 */
40 kMaxAccuracy_RenderMode,
41
42 /**
43 * This is the render mode used by drawPosText(). It ignores hinting and
44 * LCD text, even if the client provided positions for hinted glyphs,
45 * and renders from a canonically-sized, generic set of paths for the
46 * given typeface. In the future we should work out a system for the
47 * client to know it should not provide hinted glyph positions. This
48 * render mode also tries to use GPU stroking for fake bold, even when
49 * SK_USE_FREETYPE_EMBOLDEN is set.
50 */
51 kMaxPerformance_RenderMode,
cdaltonb2808cd2014-07-25 14:13:57 -070052 };
cdalton855d83f2014-09-18 13:51:53 -070053
joshualitt9853cce2014-11-17 14:22:48 -080054 GrDrawState fDrawState;
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];
jvanverth0fedb192014-10-08 09:07:27 -070062 int fPendingGlyphCount;
63 SkMatrix fContextInitialMatrix;
64 bool fNeedsDeviceSpaceGlyphs;
65
jvanverth8c27a182014-10-14 08:45:50 -070066 GrStencilAndCoverTextContext(GrContext*, const SkDeviceProperties&);
67
68 virtual bool canDraw(const SkPaint& paint) SK_OVERRIDE;
69
jvanverthaab626c2014-10-16 08:04:39 -070070 virtual void onDrawText(const GrPaint&, const SkPaint&, const char text[],
71 size_t byteLength,
72 SkScalar x, SkScalar y) SK_OVERRIDE;
jvanverth8c27a182014-10-14 08:45:50 -070073 virtual void onDrawPosText(const GrPaint&, const SkPaint&,
74 const char text[], size_t byteLength,
75 const SkScalar pos[], int scalarsPerPosition,
76 const SkPoint& offset) SK_OVERRIDE;
77
cdalton38e13ad2014-11-07 06:02:15 -080078 void init(const GrPaint&, const SkPaint&, size_t textByteLength, RenderMode);
cdaltonb85a0aa2014-07-21 15:32:44 -070079 void appendGlyph(uint16_t glyphID, float x, float y);
80 void flush();
kkinnunenc6cb56f2014-06-24 00:12:27 -070081 void finish();
82
kkinnunenc6cb56f2014-06-24 00:12:27 -070083};
84
85#endif