blob: 3fe44888ce47a91be85f0d11407168311e8e30f1 [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
mtklein72c9faa2015-01-09 10:06:39 -080054 bool canDraw(const SkPaint& paint, const SkMatrix& viewMatrix) SK_OVERRIDE;
jvanverth8c27a182014-10-14 08:45:50 -070055
joshualitt570d2f82015-02-25 13:19:48 -080056 virtual void onDrawText(GrRenderTarget*, const GrClip&, const GrPaint&, const SkPaint&,
joshualitt25d9c152015-02-18 12:29:52 -080057 const SkMatrix& viewMatrix,
joshualitt5531d512014-12-17 15:50:11 -080058 const char text[], size_t byteLength,
joshualitt6e8cd962015-03-20 10:30:14 -070059 SkScalar x, SkScalar y, const SkIRect& regionClipBounds) SK_OVERRIDE;
joshualitt570d2f82015-02-25 13:19:48 -080060 virtual void onDrawPosText(GrRenderTarget*, const GrClip&, const GrPaint&, const SkPaint&,
joshualitt25d9c152015-02-18 12:29:52 -080061 const SkMatrix& viewMatrix,
jvanverth8c27a182014-10-14 08:45:50 -070062 const char text[], size_t byteLength,
63 const SkScalar pos[], int scalarsPerPosition,
joshualitt6e8cd962015-03-20 10:30:14 -070064 const SkPoint& offset, const SkIRect& regionClipBounds) SK_OVERRIDE;
jvanverth8c27a182014-10-14 08:45:50 -070065
joshualitt6e8cd962015-03-20 10:30:14 -070066 void init(GrRenderTarget*, const GrClip&, const GrPaint&, const SkPaint&,
67 const SkIRect& regionClipBounds);
djsollen058f01e2014-10-30 11:54:43 -070068 bool appendGlyph(GrGlyph::PackedID, SkScalar left, SkScalar top, GrFontScaler*);
jvanverth787cdf92014-12-04 10:46:50 -080069 bool uploadGlyph(GrGlyph*, GrFontScaler*);
jvanverth0fedb192014-10-08 09:07:27 -070070 void setupCoverageEffect(const SkColor& filteredColor);
71 void flush(); // automatically called by destructor
72 void finish();
jvanverth@google.comd830d132013-11-11 20:54:09 +000073};
74
75#endif