jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 13 | class GrGeometryProcessor; |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 14 | class GrTextStrike; |
| 15 | |
| 16 | /* |
| 17 | * This class implements GrTextContext using distance field fonts |
| 18 | */ |
| 19 | class GrDistanceFieldTextContext : public GrTextContext { |
| 20 | public: |
jvanverth | 8c27a18 | 2014-10-14 08:45:50 -0700 | [diff] [blame] | 21 | static GrDistanceFieldTextContext* Create(GrContext*, const SkDeviceProperties&, bool enable); |
| 22 | |
commit-bot@chromium.org | cbbc481 | 2014-01-30 22:05:47 +0000 | [diff] [blame] | 23 | virtual ~GrDistanceFieldTextContext(); |
| 24 | |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 25 | private: |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 26 | enum { |
| 27 | kMinRequestedGlyphs = 1, |
| 28 | kDefaultRequestedGlyphs = 64, |
| 29 | kMinRequestedVerts = kMinRequestedGlyphs * 4, |
| 30 | kDefaultRequestedVerts = kDefaultRequestedGlyphs * 4, |
| 31 | }; |
| 32 | |
jvanverth | 0fedb19 | 2014-10-08 09:07:27 -0700 | [diff] [blame] | 33 | 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; |
jvanverth | 0fedb19 | 2014-10-08 09:07:27 -0700 | [diff] [blame] | 44 | int fCurrVertex; |
jvanverth | 73f1053 | 2014-10-23 11:57:12 -0700 | [diff] [blame] | 45 | int fAllocVertexCount; |
| 46 | int fTotalVertexCount; |
| 47 | GrTexture* fCurrTexture; |
jvanverth | 0fedb19 | 2014-10-08 09:07:27 -0700 | [diff] [blame] | 48 | SkRect fVertexBounds; |
| 49 | |
jvanverth | 8c27a18 | 2014-10-14 08:45:50 -0700 | [diff] [blame] | 50 | GrDistanceFieldTextContext(GrContext*, const SkDeviceProperties&, bool enable); |
| 51 | |
| 52 | virtual bool canDraw(const SkPaint& paint) SK_OVERRIDE; |
| 53 | |
jvanverth | aab626c | 2014-10-16 08:04:39 -0700 | [diff] [blame] | 54 | virtual void onDrawText(const GrPaint&, const SkPaint&, const char text[], size_t byteLength, |
| 55 | SkScalar x, SkScalar y) SK_OVERRIDE; |
jvanverth | 8c27a18 | 2014-10-14 08:45:50 -0700 | [diff] [blame] | 56 | 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 | |
jvanverth | 0fedb19 | 2014-10-08 09:07:27 -0700 | [diff] [blame] | 61 | void init(const GrPaint&, const SkPaint&); |
jvanverth | fca302c | 2014-10-20 13:12:54 -0700 | [diff] [blame] | 62 | bool appendGlyph(GrGlyph::PackedID, SkFixed left, SkFixed top, GrFontScaler*); |
jvanverth | 0fedb19 | 2014-10-08 09:07:27 -0700 | [diff] [blame] | 63 | void setupCoverageEffect(const SkColor& filteredColor); |
| 64 | void flush(); // automatically called by destructor |
| 65 | void finish(); |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 66 | }; |
| 67 | |
| 68 | #endif |