blob: c2d0b6d1ceafe0680e0602479f45d97a23c9a8de [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;
joshualitt5531d512014-12-17 15:50:11 -080049 SkMatrix fViewMatrix;
jvanverth0fedb192014-10-08 09:07:27 -070050
jvanverth8c27a182014-10-14 08:45:50 -070051 GrDistanceFieldTextContext(GrContext*, const SkDeviceProperties&, bool enable);
52
mtklein72c9faa2015-01-09 10:06:39 -080053 bool canDraw(const SkPaint& paint, const SkMatrix& viewMatrix) SK_OVERRIDE;
jvanverth8c27a182014-10-14 08:45:50 -070054
joshualitt5531d512014-12-17 15:50:11 -080055 virtual void onDrawText(const GrPaint&, const SkPaint&, const SkMatrix& viewMatrix,
56 const char text[], size_t byteLength,
jvanverthaab626c2014-10-16 08:04:39 -070057 SkScalar x, SkScalar y) SK_OVERRIDE;
joshualitt5531d512014-12-17 15:50:11 -080058 virtual void onDrawPosText(const GrPaint&, const SkPaint&, const SkMatrix& viewMatrix,
jvanverth8c27a182014-10-14 08:45:50 -070059 const char text[], size_t byteLength,
60 const SkScalar pos[], int scalarsPerPosition,
61 const SkPoint& offset) SK_OVERRIDE;
62
jvanverth0fedb192014-10-08 09:07:27 -070063 void init(const GrPaint&, const SkPaint&);
djsollen058f01e2014-10-30 11:54:43 -070064 bool appendGlyph(GrGlyph::PackedID, SkScalar left, SkScalar top, GrFontScaler*);
jvanverth787cdf92014-12-04 10:46:50 -080065 bool uploadGlyph(GrGlyph*, GrFontScaler*);
jvanverth0fedb192014-10-08 09:07:27 -070066 void setupCoverageEffect(const SkColor& filteredColor);
67 void flush(); // automatically called by destructor
68 void finish();
jvanverth@google.comd830d132013-11-11 20:54:09 +000069};
70
71#endif