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
13class GrGeometryProcessor;
14class GrTextStrike;
15
16/*
17 * This class implements GrTextContext using distance field fonts
18 */
19class GrDistanceFieldTextContext : public GrTextContext {
20public:
21    GrDistanceFieldTextContext(GrContext*, const SkDeviceProperties&, bool enable);
22    virtual ~GrDistanceFieldTextContext();
23
24    virtual void drawText(const GrPaint&, const SkPaint&, const char text[], size_t byteLength,
25                          SkScalar x, SkScalar y) SK_OVERRIDE;
26    virtual void drawPosText(const GrPaint&, const SkPaint&,
27                             const char text[], size_t byteLength,
28                             const SkScalar pos[], SkScalar constY,
29                             int scalarsPerPosition) SK_OVERRIDE;
30
31    virtual bool canDraw(const SkPaint& paint) SK_OVERRIDE;
32
33private:
34    GrTextStrike*                      fStrike;
35    SkScalar                           fTextRatio;
36    bool                               fUseLCDText;
37    bool                               fEnableDFRendering;
38    SkAutoTUnref<GrGeometryProcessor>  fCachedGeometryProcessor;
39    // Used to check whether fCachedEffect is still valid.
40    uint32_t                fEffectTextureUniqueID;
41    SkColor                 fEffectColor;
42    uint32_t                fEffectFlags;
43    GrTexture*              fGammaTexture;
44
45    void init(const GrPaint&, const SkPaint&);
46    void drawPackedGlyph(GrGlyph::PackedID, SkFixed left, SkFixed top, GrFontScaler*);
47    void flushGlyphs();                 // automatically called by destructor
48    void setupCoverageEffect(const SkColor& filteredColor);
49    void finish();
50
51    enum {
52        kMinRequestedGlyphs      = 1,
53        kDefaultRequestedGlyphs  = 64,
54        kMinRequestedVerts       = kMinRequestedGlyphs * 4,
55        kDefaultRequestedVerts   = kDefaultRequestedGlyphs * 4,
56    };
57
58    void*                   fVertices;
59    int32_t                 fMaxVertices;
60    GrTexture*              fCurrTexture;
61    int                     fCurrVertex;
62    SkRect                  fVertexBounds;
63};
64
65#endif
66