aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/GrBatchedTextContext.h
blob: c0a136ba2663a3fe861e4be646787897c310019b (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

/*
 * Copyright 2010 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */



#ifndef GrBatchedTextContext_DEFINED
#define GrBatchedTextContext_DEFINED

#include "GrPaint.h"
#include "GrTextContext.h"

class GrDrawTarget;
class GrTexture;

/**
 * Base class for TextContexts that can batch multiple glyphs into single draw.
 *
 * Every glyph is encoded on a single texture.
 * Every glyph is enclosed within a quad (formed by triangle fan) represented
 * by 4 vertices.
 */
class GrBatchedTextContext: public GrTextContext {
public:
    virtual ~GrBatchedTextContext();

protected:
    enum {
        kMinRequestedGlyphs      = 1,
        kDefaultRequestedGlyphs  = 64,
        kMinRequestedVerts       = kMinRequestedGlyphs * 4,
        kDefaultRequestedVerts   = kDefaultRequestedGlyphs * 4,
        kGlyphMaskStage          = GrPaint::kTotalStages,
    };

    GrPaint         fGrPaint;
    GrDrawTarget*   fDrawTarget;

    int32_t     fMaxVertices;
    GrTexture*  fCurrTexture;
    int         fCurrVertex;

    GrBatchedTextContext();
    virtual void init(GrContext* context, const GrPaint&,
                      const GrMatrix* extMatrix) SK_OVERRIDE;
    virtual void finish() SK_OVERRIDE;

    /**
     * Prepare to add another glyph to buffer. The glyph is encoded on the
     * texture provided. Make sure we are using the right texture (or switch
     * to a new texture) and that our buffer is big enough.
     */
    void prepareForGlyph(GrTexture*);

    /**
     * Flush the buffer. Called when switching textures.
     * Must be called in finish() method of all derived classes.
     */
    virtual void flush() = 0;

    /**
     * Set up a buffer to hold vertices of given layout.
     * If NULL != *vertexBuff, don't do anything.
     * Might cause flushing, if draw target suggests it.
     */
    void setupVertexBuff(void** vertexBuff, GrVertexLayout vertexLayout);

    /**
     * Reset after flushing.
     */
    void reset();

private:

    typedef GrTextContext INHERITED;
};

#endif