blob: c0a136ba2663a3fe861e4be646787897c310019b [file] [log] [blame]
bsalomon@google.comf4a9c822012-03-16 14:02:46 +00001
2/*
3 * Copyright 2010 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
9
10
11#ifndef GrBatchedTextContext_DEFINED
12#define GrBatchedTextContext_DEFINED
13
14#include "GrPaint.h"
15#include "GrTextContext.h"
16
17class GrDrawTarget;
18class GrTexture;
19
20/**
21 * Base class for TextContexts that can batch multiple glyphs into single draw.
22 *
23 * Every glyph is encoded on a single texture.
24 * Every glyph is enclosed within a quad (formed by triangle fan) represented
25 * by 4 vertices.
26 */
27class GrBatchedTextContext: public GrTextContext {
28public:
29 virtual ~GrBatchedTextContext();
30
31protected:
32 enum {
33 kMinRequestedGlyphs = 1,
34 kDefaultRequestedGlyphs = 64,
35 kMinRequestedVerts = kMinRequestedGlyphs * 4,
36 kDefaultRequestedVerts = kDefaultRequestedGlyphs * 4,
37 kGlyphMaskStage = GrPaint::kTotalStages,
38 };
39
40 GrPaint fGrPaint;
41 GrDrawTarget* fDrawTarget;
42
43 int32_t fMaxVertices;
44 GrTexture* fCurrTexture;
45 int fCurrVertex;
46
47 GrBatchedTextContext();
48 virtual void init(GrContext* context, const GrPaint&,
49 const GrMatrix* extMatrix) SK_OVERRIDE;
50 virtual void finish() SK_OVERRIDE;
51
52 /**
53 * Prepare to add another glyph to buffer. The glyph is encoded on the
54 * texture provided. Make sure we are using the right texture (or switch
55 * to a new texture) and that our buffer is big enough.
56 */
57 void prepareForGlyph(GrTexture*);
58
59 /**
60 * Flush the buffer. Called when switching textures.
61 * Must be called in finish() method of all derived classes.
62 */
63 virtual void flush() = 0;
64
65 /**
66 * Set up a buffer to hold vertices of given layout.
67 * If NULL != *vertexBuff, don't do anything.
68 * Might cause flushing, if draw target suggests it.
69 */
70 void setupVertexBuff(void** vertexBuff, GrVertexLayout vertexLayout);
71
72 /**
73 * Reset after flushing.
74 */
75 void reset();
76
77private:
78
79 typedef GrTextContext INHERITED;
80};
81
82#endif