blob: 0b08b5986c154d5a776530ee8d02b115cd1074c6 [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
joshualittb0a8a372014-09-23 09:50:21 -070013class GrGeometryProcessor;
jvanverth@google.comd830d132013-11-11 20:54:09 +000014class GrTextStrike;
15
16/*
17 * This class implements GrTextContext using distance field fonts
18 */
19class GrDistanceFieldTextContext : public GrTextContext {
20public:
commit-bot@chromium.org6fcd1ef2014-05-02 12:39:41 +000021 GrDistanceFieldTextContext(GrContext*, const SkDeviceProperties&, bool enable);
commit-bot@chromium.orgcbbc4812014-01-30 22:05:47 +000022 virtual ~GrDistanceFieldTextContext();
23
skia.committer@gmail.com4c18e9f2014-01-31 03:01:59 +000024 virtual void drawText(const GrPaint&, const SkPaint&, const char text[], size_t byteLength,
commit-bot@chromium.orgcbbc4812014-01-30 22:05:47 +000025 SkScalar x, SkScalar y) SK_OVERRIDE;
skia.committer@gmail.com4c18e9f2014-01-31 03:01:59 +000026 virtual void drawPosText(const GrPaint&, const SkPaint&,
commit-bot@chromium.orgcbbc4812014-01-30 22:05:47 +000027 const char text[], size_t byteLength,
fmalita05c4a432014-09-29 06:29:53 -070028 const SkScalar pos[], int scalarsPerPosition,
29 const SkPoint& offset) SK_OVERRIDE;
skia.committer@gmail.com4c18e9f2014-01-31 03:01:59 +000030
commit-bot@chromium.orgcbbc4812014-01-30 22:05:47 +000031 virtual bool canDraw(const SkPaint& paint) SK_OVERRIDE;
commit-bot@chromium.org8128d8c2013-12-19 16:12:25 +000032
jvanverth@google.comd830d132013-11-11 20:54:09 +000033private:
joshualittb0a8a372014-09-23 09:50:21 -070034 GrTextStrike* fStrike;
35 SkScalar fTextRatio;
36 bool fUseLCDText;
37 bool fEnableDFRendering;
38 SkAutoTUnref<GrGeometryProcessor> fCachedGeometryProcessor;
Mike Klein6a25bd02014-08-29 10:03:59 -040039 // Used to check whether fCachedEffect is still valid.
40 uint32_t fEffectTextureUniqueID;
41 SkColor fEffectColor;
42 uint32_t fEffectFlags;
43 GrTexture* fGammaTexture;
44
commit-bot@chromium.orgcbbc4812014-01-30 22:05:47 +000045 void init(const GrPaint&, const SkPaint&);
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +000046 void drawPackedGlyph(GrGlyph::PackedID, SkFixed left, SkFixed top, GrFontScaler*);
jvanverth@google.comd830d132013-11-11 20:54:09 +000047 void flushGlyphs(); // automatically called by destructor
jvanverth78f07182014-07-30 06:17:59 -070048 void setupCoverageEffect(const SkColor& filteredColor);
commit-bot@chromium.orgcbbc4812014-01-30 22:05:47 +000049 void finish();
jvanverth@google.comd830d132013-11-11 20:54:09 +000050
51 enum {
52 kMinRequestedGlyphs = 1,
53 kDefaultRequestedGlyphs = 64,
54 kMinRequestedVerts = kMinRequestedGlyphs * 4,
55 kDefaultRequestedVerts = kDefaultRequestedGlyphs * 4,
56 };
57
jvanverthf17bc6c2014-07-25 16:46:53 -070058 void* fVertices;
Mike Klein6a25bd02014-08-29 10:03:59 -040059 int32_t fMaxVertices;
60 GrTexture* fCurrTexture;
jvanverth@google.comd830d132013-11-11 20:54:09 +000061 int fCurrVertex;
jvanverth1723bfc2014-07-30 09:16:33 -070062 SkRect fVertexBounds;
jvanverth@google.comd830d132013-11-11 20:54:09 +000063};
64
65#endif