blob: c9fe82d2e571237ed587de66f3e38b423328ae4f [file] [log] [blame]
jvanverth@google.comd830d132013-11-11 20:54:09 +00001/*
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 GrTextStrike;
14
15/*
16 * This class implements GrTextContext using distance field fonts
17 */
18class GrDistanceFieldTextContext : public GrTextContext {
19public:
commit-bot@chromium.org6fcd1ef2014-05-02 12:39:41 +000020 GrDistanceFieldTextContext(GrContext*, const SkDeviceProperties&, bool enable);
commit-bot@chromium.orgcbbc4812014-01-30 22:05:47 +000021 virtual ~GrDistanceFieldTextContext();
22
skia.committer@gmail.com4c18e9f2014-01-31 03:01:59 +000023 virtual void drawText(const GrPaint&, const SkPaint&, const char text[], size_t byteLength,
commit-bot@chromium.orgcbbc4812014-01-30 22:05:47 +000024 SkScalar x, SkScalar y) SK_OVERRIDE;
skia.committer@gmail.com4c18e9f2014-01-31 03:01:59 +000025 virtual void drawPosText(const GrPaint&, const SkPaint&,
commit-bot@chromium.orgcbbc4812014-01-30 22:05:47 +000026 const char text[], size_t byteLength,
commit-bot@chromium.orge8612d92014-01-28 22:02:07 +000027 const SkScalar pos[], SkScalar constY,
28 int scalarsPerPosition) SK_OVERRIDE;
skia.committer@gmail.com4c18e9f2014-01-31 03:01:59 +000029
commit-bot@chromium.orgcbbc4812014-01-30 22:05:47 +000030 virtual bool canDraw(const SkPaint& paint) SK_OVERRIDE;
commit-bot@chromium.org8128d8c2013-12-19 16:12:25 +000031
jvanverth@google.comd830d132013-11-11 20:54:09 +000032private:
commit-bot@chromium.orgcbbc4812014-01-30 22:05:47 +000033 void init(const GrPaint&, const SkPaint&);
jvanverth63b9dc82014-08-28 10:39:40 -070034 void allocateVertices(const char text[], size_t byteLength);
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +000035 void drawPackedGlyph(GrGlyph::PackedID, SkFixed left, SkFixed top, GrFontScaler*);
jvanverth@google.comd830d132013-11-11 20:54:09 +000036 void flushGlyphs(); // automatically called by destructor
jvanverth78f07182014-07-30 06:17:59 -070037 void setupCoverageEffect(const SkColor& filteredColor);
commit-bot@chromium.orgcbbc4812014-01-30 22:05:47 +000038 void finish();
jvanverth@google.comd830d132013-11-11 20:54:09 +000039
40 enum {
41 kMinRequestedGlyphs = 1,
42 kDefaultRequestedGlyphs = 64,
43 kMinRequestedVerts = kMinRequestedGlyphs * 4,
44 kDefaultRequestedVerts = kDefaultRequestedGlyphs * 4,
45 };
46
jvanverth63b9dc82014-08-28 10:39:40 -070047 GrTextStrike* fStrike;
48 SkScalar fTextRatio;
49 bool fUseLCDText;
50 bool fEnableDFRendering;
51 SkAutoTUnref<GrEffect> fCachedEffect;
52 // Used to check whether fCachedEffect is still valid.
53 uint32_t fEffectTextureUniqueID;
54 SkColor fEffectColor;
55 uint32_t fEffectFlags;
56 GrTexture* fGammaTexture;
57
jvanverthf17bc6c2014-07-25 16:46:53 -070058 void* fVertices;
jvanverth63b9dc82014-08-28 10:39:40 -070059 int fVertexCount;
jvanverth@google.comd830d132013-11-11 20:54:09 +000060 int fCurrVertex;
jvanverth1723bfc2014-07-30 09:16:33 -070061 SkRect fVertexBounds;
jvanverth@google.comd830d132013-11-11 20:54:09 +000062};
63
64#endif