blob: 3eefd103d00da0df91d16c864223b7b71809e855 [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:
jvanverth8c27a182014-10-14 08:45:50 -070021 static GrDistanceFieldTextContext* Create(GrContext*, const SkDeviceProperties&, bool enable);
22
commit-bot@chromium.orgcbbc4812014-01-30 22:05:47 +000023 virtual ~GrDistanceFieldTextContext();
24
jvanverth@google.comd830d132013-11-11 20:54:09 +000025private:
jvanverth@google.comd830d132013-11-11 20:54:09 +000026 enum {
27 kMinRequestedGlyphs = 1,
28 kDefaultRequestedGlyphs = 64,
29 kMinRequestedVerts = kMinRequestedGlyphs * 4,
30 kDefaultRequestedVerts = kDefaultRequestedGlyphs * 4,
31 };
32
jvanverth0fedb192014-10-08 09:07:27 -070033 GrTextStrike* fStrike;
34 SkScalar fTextRatio;
35 bool fUseLCDText;
36 bool fEnableDFRendering;
37 SkAutoTUnref<GrGeometryProcessor> fCachedGeometryProcessor;
38 // Used to check whether fCachedEffect is still valid.
39 uint32_t fEffectTextureUniqueID;
40 SkColor fEffectColor;
41 uint32_t fEffectFlags;
42 GrTexture* fGammaTexture;
43 void* fVertices;
jvanverth0fedb192014-10-08 09:07:27 -070044 int fCurrVertex;
jvanverth73f10532014-10-23 11:57:12 -070045 int fAllocVertexCount;
46 int fTotalVertexCount;
47 GrTexture* fCurrTexture;
jvanverth0fedb192014-10-08 09:07:27 -070048 SkRect fVertexBounds;
49
jvanverth8c27a182014-10-14 08:45:50 -070050 GrDistanceFieldTextContext(GrContext*, const SkDeviceProperties&, bool enable);
51
52 virtual bool canDraw(const SkPaint& paint) SK_OVERRIDE;
53
jvanverthaab626c2014-10-16 08:04:39 -070054 virtual void onDrawText(const GrPaint&, const SkPaint&, const char text[], size_t byteLength,
55 SkScalar x, SkScalar y) SK_OVERRIDE;
jvanverth8c27a182014-10-14 08:45:50 -070056 virtual void onDrawPosText(const GrPaint&, const SkPaint&,
57 const char text[], size_t byteLength,
58 const SkScalar pos[], int scalarsPerPosition,
59 const SkPoint& offset) SK_OVERRIDE;
60
jvanverth0fedb192014-10-08 09:07:27 -070061 void init(const GrPaint&, const SkPaint&);
jvanverthfca302c2014-10-20 13:12:54 -070062 bool appendGlyph(GrGlyph::PackedID, SkFixed left, SkFixed top, GrFontScaler*);
jvanverth0fedb192014-10-08 09:07:27 -070063 void setupCoverageEffect(const SkColor& filteredColor);
64 void flush(); // automatically called by destructor
65 void finish();
jvanverth@google.comd830d132013-11-11 20:54:09 +000066};
67
68#endif