blob: 672922d0d64f4dc935ccc248627ee059af332ddf [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:
33 GrTextStrike* fStrike;
34 SkScalar fTextRatio;
commit-bot@chromium.org609ced42014-04-03 18:25:48 +000035 bool fUseLCDText;
commit-bot@chromium.org6fcd1ef2014-05-02 12:39:41 +000036 bool fEnableDFRendering;
jvanverth78f07182014-07-30 06:17:59 -070037 SkAutoTUnref<GrEffect> fCachedEffect;
38 // Used to check whether fCachedEffect is still valid.
39 uint32_t fEffectTextureUniqueID;
40 SkColor fEffectColor;
41 uint32_t fEffectFlags;
jvanverth2d2a68c2014-06-10 06:42:56 -070042 GrTexture* fGammaTexture;
jvanverth@google.comd830d132013-11-11 20:54:09 +000043
commit-bot@chromium.orgcbbc4812014-01-30 22:05:47 +000044 void init(const GrPaint&, const SkPaint&);
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +000045 void drawPackedGlyph(GrGlyph::PackedID, SkFixed left, SkFixed top, GrFontScaler*);
jvanverth@google.comd830d132013-11-11 20:54:09 +000046 void flushGlyphs(); // automatically called by destructor
jvanverth78f07182014-07-30 06:17:59 -070047 void setupCoverageEffect(const SkColor& filteredColor);
commit-bot@chromium.orgcbbc4812014-01-30 22:05:47 +000048 void finish();
jvanverth@google.comd830d132013-11-11 20:54:09 +000049
50 enum {
51 kMinRequestedGlyphs = 1,
52 kDefaultRequestedGlyphs = 64,
53 kMinRequestedVerts = kMinRequestedGlyphs * 4,
54 kDefaultRequestedVerts = kDefaultRequestedGlyphs * 4,
55 };
56
jvanverthf17bc6c2014-07-25 16:46:53 -070057 void* fVertices;
jvanverth@google.comd830d132013-11-11 20:54:09 +000058 int fCurrVertex;
59};
60
61#endif