blob: 08d7526b7e390d20e70ef86a75645abad70da2f8 [file] [log] [blame]
kkinnunenc6cb56f2014-06-24 00:12:27 -07001/*
2 * Copyright 2014 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 GrStencilAndCoverTextContext_DEFINED
9#define GrStencilAndCoverTextContext_DEFINED
10
11#include "GrTextContext.h"
12#include "GrDrawState.h"
cdaltonb2808cd2014-07-25 14:13:57 -070013#include "GrDrawTarget.h"
kkinnunenc6cb56f2014-06-24 00:12:27 -070014#include "SkStrokeRec.h"
15
16class GrTextStrike;
17class GrPath;
18
19/*
20 * This class implements text rendering using stencil and cover path rendering
21 * (by the means of GrDrawTarget::drawPath).
22 * This class exposes the functionality through GrTextContext interface.
23 */
24class GrStencilAndCoverTextContext : public GrTextContext {
25public:
26 GrStencilAndCoverTextContext(GrContext*, const SkDeviceProperties&);
27 virtual ~GrStencilAndCoverTextContext();
28
29 virtual void drawText(const GrPaint&, const SkPaint&, const char text[],
30 size_t byteLength,
31 SkScalar x, SkScalar y) SK_OVERRIDE;
32 virtual void drawPosText(const GrPaint&, const SkPaint&,
33 const char text[], size_t byteLength,
34 const SkScalar pos[], SkScalar constY,
35 int scalarsPerPosition) SK_OVERRIDE;
36
37 virtual bool canDraw(const SkPaint& paint) SK_OVERRIDE;
38
39private:
cdaltonb85a0aa2014-07-21 15:32:44 -070040 class GlyphPathRange;
41 static const int kGlyphBufferSize = 1024;
42
cdaltonb2808cd2014-07-25 14:13:57 -070043 enum DeviceSpaceGlyphsBehavior {
44 kUseIfNeeded_DeviceSpaceGlyphsBehavior,
45 kDoNotUse_DeviceSpaceGlyphsBehavior,
46 };
47 void init(const GrPaint&, const SkPaint&, size_t textByteLength,
48 DeviceSpaceGlyphsBehavior, SkScalar textTranslateY = 0);
cdaltonb85a0aa2014-07-21 15:32:44 -070049 void initGlyphs(SkGlyphCache* cache);
cdaltonb2808cd2014-07-25 14:13:57 -070050 void appendGlyph(uint16_t glyphID, float x);
cdaltonb85a0aa2014-07-21 15:32:44 -070051 void appendGlyph(uint16_t glyphID, float x, float y);
52 void flush();
kkinnunenc6cb56f2014-06-24 00:12:27 -070053 void finish();
54
55 GrDrawState::AutoRestoreEffects fStateRestore;
56 SkScalar fTextRatio;
cdaltonb2808cd2014-07-25 14:13:57 -070057 float fTextInverseRatio;
kkinnunenc6cb56f2014-06-24 00:12:27 -070058 SkStrokeRec fStroke;
cdaltonb85a0aa2014-07-21 15:32:44 -070059 SkGlyphCache* fGlyphCache;
60 GlyphPathRange* fGlyphs;
61 uint32_t fIndexBuffer[kGlyphBufferSize];
cdaltonb2808cd2014-07-25 14:13:57 -070062 float fTransformBuffer[2 * kGlyphBufferSize];
63 GrDrawTarget::PathTransformType fTransformType;
cdaltonb85a0aa2014-07-21 15:32:44 -070064 int fPendingGlyphCount;
cdaltonb2808cd2014-07-25 14:13:57 -070065 SkMatrix fContextInitialMatrix;
kkinnunenc6cb56f2014-06-24 00:12:27 -070066 bool fNeedsDeviceSpaceGlyphs;
67};
68
69#endif