• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 GrTextStrike;
14 
15 /*
16  * This class implements GrTextContext using distance field fonts
17  */
18 class GrDistanceFieldTextContext : public GrTextContext {
19 public:
20     GrDistanceFieldTextContext(GrContext*, const SkDeviceProperties&, bool enable);
21     virtual ~GrDistanceFieldTextContext();
22 
23     virtual void drawText(const GrPaint&, const SkPaint&, const char text[], size_t byteLength,
24                           SkScalar x, SkScalar y) SK_OVERRIDE;
25     virtual void drawPosText(const GrPaint&, const SkPaint&,
26                              const char text[], size_t byteLength,
27                              const SkScalar pos[], SkScalar constY,
28                              int scalarsPerPosition) SK_OVERRIDE;
29 
30     virtual bool canDraw(const SkPaint& paint) SK_OVERRIDE;
31 
32 private:
33     GrTextStrike*           fStrike;
34     SkScalar                fTextRatio;
35     bool                    fUseLCDText;
36     bool                    fEnableDFRendering;
37     GrTexture*              fGammaTexture;
38 
39     void init(const GrPaint&, const SkPaint&);
40     void drawPackedGlyph(GrGlyph::PackedID, SkFixed left, SkFixed top, GrFontScaler*);
41     void flushGlyphs();                 // automatically called by destructor
42     void finish();
43 
44     enum {
45         kMinRequestedGlyphs      = 1,
46         kDefaultRequestedGlyphs  = 64,
47         kMinRequestedVerts       = kMinRequestedGlyphs * 4,
48         kDefaultRequestedVerts   = kDefaultRequestedGlyphs * 4,
49     };
50 
51     SkPoint*                fVertices;
52     int32_t                 fMaxVertices;
53     GrTexture*              fCurrTexture;
54     int                     fCurrVertex;
55 };
56 
57 #endif
58