aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/GrStencilAndCoverTextContext.h
blob: 4c57d3cb81d251227ebc959b027515562a3027fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*
 * Copyright 2014 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#ifndef GrStencilAndCoverTextContext_DEFINED
#define GrStencilAndCoverTextContext_DEFINED

#include "GrTextContext.h"
#include "GrDrawTarget.h"
#include "GrStrokeInfo.h"

class GrTextStrike;
class GrPath;
class GrPathRange;
class GrPathRangeDraw;
class SkSurfaceProps;

/*
 * This class implements text rendering using stencil and cover path rendering
 * (by the means of GrDrawTarget::drawPath).
 * This class exposes the functionality through GrTextContext interface.
 */
class GrStencilAndCoverTextContext : public GrTextContext {
public:
    static GrStencilAndCoverTextContext* Create(GrContext*, const SkSurfaceProps&);

    virtual ~GrStencilAndCoverTextContext();

private:
    enum RenderMode {
        /**
         * This is the render mode used by drawText(), which is mainly used by
         * the Skia unit tests. It tries match the other text backends exactly,
         * with the exception of not implementing LCD text, and doing anti-
         * aliasing with the built-in MSAA.
         */
        kMaxAccuracy_RenderMode,

        /**
         * This is the render mode used by drawPosText(). It ignores hinting and
         * LCD text, even if the client provided positions for hinted glyphs,
         * and renders from a canonically-sized, generic set of paths for the
         * given typeface. In the future we should work out a system for the
         * client to know it should not provide hinted glyph positions. This
         * render mode also tries to use GPU stroking for fake bold, even when
         * SK_USE_FREETYPE_EMBOLDEN is set.
         */
        kMaxPerformance_RenderMode,
    };

    SkScalar                                            fTextRatio;
    float                                               fTextInverseRatio;
    SkGlyphCache*                                       fGlyphCache;

    GrPathRange*                                        fGlyphs;
    GrPathRangeDraw*                                    fDraw;
    GrStrokeInfo                                        fStroke;
    SkSTArray<32, uint16_t, true>                       fFallbackIndices;
    SkSTArray<32, SkPoint, true>                        fFallbackPositions;

    SkMatrix                                            fContextInitialMatrix;
    SkMatrix                                            fViewMatrix;
    SkMatrix                                            fLocalMatrix;
    bool                                                fUsingDeviceSpaceGlyphs;
    SkAutoTUnref<GrRenderTarget>                        fRenderTarget;
    GrClip                                              fClip;
    SkIRect                                             fClipRect;
    SkIRect                                             fRegionClipBounds;
    GrPaint                                             fPaint;
    SkPaint                                             fSkPaint;

    GrStencilAndCoverTextContext(GrContext*, const SkSurfaceProps&);

    bool canDraw(const GrRenderTarget*, const GrClip&, const GrPaint&,
                 const SkPaint&, const SkMatrix& viewMatrix) override;

    void onDrawText(GrDrawContext*, GrRenderTarget*, const GrClip&, const GrPaint&, const SkPaint&,
                    const SkMatrix& viewMatrix,
                    const char text[], size_t byteLength,
                    SkScalar x, SkScalar y, const SkIRect& regionClipBounds) override;
    void onDrawPosText(GrDrawContext*, GrRenderTarget*,
                       const GrClip&, const GrPaint&, const SkPaint&,
                       const SkMatrix& viewMatrix,
                       const char text[], size_t byteLength,
                       const SkScalar pos[], int scalarsPerPosition,
                       const SkPoint& offset, const SkIRect& regionClipBounds) override;

    void init(GrRenderTarget*, const GrClip&, const GrPaint&, const SkPaint&,
              size_t textByteLength, RenderMode, const SkMatrix& viewMatrix,
              const SkIRect& regionClipBounds);
    bool mapToFallbackContext(SkMatrix* inverse);
    void appendGlyph(const SkGlyph&, const SkPoint&);
    void flush(GrDrawContext* dc);
    void finish(GrDrawContext* dc);

    typedef GrTextContext INHERITED;
};

#endif