Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / skia / src / gpu / GrDistanceFieldTextContext.h
1 /*
2  * Copyright 2013 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 GrDistanceFieldTextContext_DEFINED
9 #define GrDistanceFieldTextContext_DEFINED
10
11 #include "GrTextContext.h"
12
13 class GrGeometryProcessor;
14 class GrTextStrike;
15
16 /*
17  * This class implements GrTextContext using distance field fonts
18  */
19 class GrDistanceFieldTextContext : public GrTextContext {
20 public:
21     static GrDistanceFieldTextContext* Create(GrContext*, const SkDeviceProperties&, bool enable);
22
23     virtual ~GrDistanceFieldTextContext();
24
25 private:
26     enum {
27         kMinRequestedGlyphs      = 1,
28         kDefaultRequestedGlyphs  = 64,
29         kMinRequestedVerts       = kMinRequestedGlyphs * 4,
30         kDefaultRequestedVerts   = kDefaultRequestedGlyphs * 4,
31     };
32
33     GrTextStrike*                      fStrike;
34     SkScalar                           fTextRatio;
35     bool                               fUseLCDText;
36     bool                               fEnableDFRendering;
37     SkAutoTUnref<GrGeometryProcessor>  fCachedGeometryProcessor;
38     // Used to check whether fCachedEffect is still valid.
39     uint32_t                           fEffectTextureUniqueID;
40     SkColor                            fEffectColor;
41     uint32_t                           fEffectFlags;
42     GrTexture*                         fGammaTexture;
43     void*                              fVertices;
44     int                                fCurrVertex;
45     int                                fAllocVertexCount;
46     int                                fTotalVertexCount;
47     GrTexture*                         fCurrTexture;
48     SkRect                             fVertexBounds;
49
50     GrDistanceFieldTextContext(GrContext*, const SkDeviceProperties&, bool enable);
51
52     virtual bool canDraw(const SkPaint& paint) SK_OVERRIDE;
53
54     virtual void onDrawText(const GrPaint&, const SkPaint&, const char text[], size_t byteLength,
55                             SkScalar x, SkScalar y) SK_OVERRIDE;
56     virtual void onDrawPosText(const GrPaint&, const SkPaint&,
57                                const char text[], size_t byteLength,
58                                const SkScalar pos[], int scalarsPerPosition,
59                                const SkPoint& offset) SK_OVERRIDE;
60
61     void init(const GrPaint&, const SkPaint&);
62     bool appendGlyph(GrGlyph::PackedID, SkScalar left, SkScalar top, GrFontScaler*);
63     void setupCoverageEffect(const SkColor& filteredColor);
64     void flush();                 // automatically called by destructor
65     void finish();
66 };
67
68 #endif