Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / skia / src / gpu / GrStencilAndCoverTextContext.h
1 /*
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"
13 #include "GrDrawTarget.h"
14 #include "SkStrokeRec.h"
15
16 class GrTextStrike;
17 class GrPath;
18 class GrPathRange;
19
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  */
25 class GrStencilAndCoverTextContext : public GrTextContext {
26 public:
27     static GrStencilAndCoverTextContext* Create(GrContext*, const SkDeviceProperties&);
28
29     virtual ~GrStencilAndCoverTextContext();
30
31 private:
32     static const int kGlyphBufferSize = 1024;
33
34     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,
53     };
54
55     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
67     GrStencilAndCoverTextContext(GrContext*, const SkDeviceProperties&);
68
69     virtual bool canDraw(const SkPaint& paint) SK_OVERRIDE;
70
71     virtual void onDrawText(const GrPaint&, const SkPaint&, const char text[],
72                             size_t byteLength,
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;
78
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);
84     void flush();
85     void finish();
86
87 };
88
89 #endif