blob: b76be3d1ec5b76e9c70b36fab5dabcba96926fe9 [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:
joshualitt6e8cd962015-03-20 10:30:14 -070021 static GrDistanceFieldTextContext* Create(GrContext*, SkGpuDevice*, const SkDeviceProperties&,
22 bool enable);
jvanverth8c27a182014-10-14 08:45:50 -070023
commit-bot@chromium.orgcbbc4812014-01-30 22:05:47 +000024 virtual ~GrDistanceFieldTextContext();
25
jvanverth@google.comd830d132013-11-11 20:54:09 +000026private:
jvanverth@google.comd830d132013-11-11 20:54:09 +000027 enum {
28 kMinRequestedGlyphs = 1,
29 kDefaultRequestedGlyphs = 64,
30 kMinRequestedVerts = kMinRequestedGlyphs * 4,
31 kDefaultRequestedVerts = kDefaultRequestedGlyphs * 4,
32 };
33
jvanverth0fedb192014-10-08 09:07:27 -070034 GrTextStrike* fStrike;
35 SkScalar fTextRatio;
36 bool fUseLCDText;
37 bool fEnableDFRendering;
38 SkAutoTUnref<GrGeometryProcessor> fCachedGeometryProcessor;
39 // Used to check whether fCachedEffect is still valid.
40 uint32_t fEffectTextureUniqueID;
41 SkColor fEffectColor;
42 uint32_t fEffectFlags;
43 GrTexture* fGammaTexture;
44 void* fVertices;
jvanverth0fedb192014-10-08 09:07:27 -070045 int fCurrVertex;
jvanverth73f10532014-10-23 11:57:12 -070046 int fAllocVertexCount;
47 int fTotalVertexCount;
48 GrTexture* fCurrTexture;
jvanverth0fedb192014-10-08 09:07:27 -070049 SkRect fVertexBounds;
joshualitt5531d512014-12-17 15:50:11 -080050 SkMatrix fViewMatrix;
jvanverth0fedb192014-10-08 09:07:27 -070051
joshualitt6e8cd962015-03-20 10:30:14 -070052 GrDistanceFieldTextContext(GrContext*, SkGpuDevice*, const SkDeviceProperties&, bool enable);
jvanverth8c27a182014-10-14 08:45:50 -070053
cdaltone68f7362015-03-25 14:02:37 -070054 bool canDraw(const GrRenderTarget*, const GrClip&, const GrPaint&,
mtklein36352bf2015-03-25 18:17:31 -070055 const SkPaint&, const SkMatrix& viewMatrix) override;
jvanverth8c27a182014-10-14 08:45:50 -070056
cdaltone68f7362015-03-25 14:02:37 -070057 void onDrawText(GrRenderTarget*, const GrClip&, const GrPaint&, const SkPaint&,
58 const SkMatrix& viewMatrix,
59 const char text[], size_t byteLength,
mtklein36352bf2015-03-25 18:17:31 -070060 SkScalar x, SkScalar y, const SkIRect& regionClipBounds) override;
cdaltone68f7362015-03-25 14:02:37 -070061 void onDrawPosText(GrRenderTarget*, const GrClip&, const GrPaint&, const SkPaint&,
62 const SkMatrix& viewMatrix,
63 const char text[], size_t byteLength,
64 const SkScalar pos[], int scalarsPerPosition,
mtklein36352bf2015-03-25 18:17:31 -070065 const SkPoint& offset, const SkIRect& regionClipBounds) override;
jvanverth8c27a182014-10-14 08:45:50 -070066
joshualitt6e8cd962015-03-20 10:30:14 -070067 void init(GrRenderTarget*, const GrClip&, const GrPaint&, const SkPaint&,
68 const SkIRect& regionClipBounds);
djsollen058f01e2014-10-30 11:54:43 -070069 bool appendGlyph(GrGlyph::PackedID, SkScalar left, SkScalar top, GrFontScaler*);
jvanverth787cdf92014-12-04 10:46:50 -080070 bool uploadGlyph(GrGlyph*, GrFontScaler*);
jvanverth0fedb192014-10-08 09:07:27 -070071 void setupCoverageEffect(const SkColor& filteredColor);
72 void flush(); // automatically called by destructor
73 void finish();
jvanverth@google.comd830d132013-11-11 20:54:09 +000074};
75
76#endif