OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef GrStencilAndCoverTextContext_DEFINED | 8 #ifndef GrStencilAndCoverTextContext_DEFINED |
9 #define GrStencilAndCoverTextContext_DEFINED | 9 #define GrStencilAndCoverTextContext_DEFINED |
10 | 10 |
11 #include "GrTextContext.h" | 11 #include "GrTextContext.h" |
12 #include "GrDrawTarget.h" | 12 #include "GrDrawTarget.h" |
13 #include "GrStrokeInfo.h" | 13 #include "GrStrokeInfo.h" |
| 14 #include "SkTHash.h" |
| 15 #include "SkTInternalLList.h" |
| 16 #include "SkTLList.h" |
14 | 17 |
15 class GrTextStrike; | 18 class GrTextStrike; |
16 class GrPath; | 19 class GrPath; |
17 class GrPathRange; | 20 class GrPathRange; |
18 class SkSurfaceProps; | 21 class SkSurfaceProps; |
19 | 22 |
20 /* | 23 /* |
21 * This class implements text rendering using stencil and cover path rendering | 24 * This class implements text rendering using stencil and cover path rendering |
22 * (by the means of GrDrawTarget::drawPath). | 25 * (by the means of GrDrawTarget::drawPath). |
23 * This class exposes the functionality through GrTextContext interface. | 26 * This class exposes the functionality through GrTextContext interface. |
24 */ | 27 */ |
25 class GrStencilAndCoverTextContext : public GrTextContext { | 28 class GrStencilAndCoverTextContext : public GrTextContext { |
26 public: | 29 public: |
27 static GrStencilAndCoverTextContext* Create(GrContext*, const SkSurfaceProps
&); | 30 static GrStencilAndCoverTextContext* Create(GrContext*, const SkSurfaceProps
&); |
28 | 31 |
29 virtual ~GrStencilAndCoverTextContext(); | 32 virtual ~GrStencilAndCoverTextContext(); |
30 | 33 |
31 private: | 34 private: |
32 GrStencilAndCoverTextContext(GrContext*, const SkSurfaceProps&); | 35 GrStencilAndCoverTextContext(GrContext*, const SkSurfaceProps&); |
33 | 36 |
34 bool canDraw(const GrRenderTarget*, const GrClip&, const GrPaint&, | 37 bool canDraw(const GrRenderTarget*, const GrClip&, const GrPaint&, const SkP
aint& skPaint, |
35 const SkPaint&, const SkMatrix& viewMatrix) override; | 38 const SkMatrix&) override { return this->internalCanDraw(skPain
t); } |
| 39 |
| 40 bool internalCanDraw(const SkPaint&); |
36 | 41 |
37 void onDrawText(GrDrawContext*, GrRenderTarget*, const GrClip&, const GrPain
t&, const SkPaint&, | 42 void onDrawText(GrDrawContext*, GrRenderTarget*, const GrClip&, const GrPain
t&, const SkPaint&, |
38 const SkMatrix& viewMatrix, | 43 const SkMatrix& viewMatrix, |
39 const char text[], size_t byteLength, | 44 const char text[], size_t byteLength, |
40 SkScalar x, SkScalar y, const SkIRect& regionClipBounds) ove
rride; | 45 SkScalar x, SkScalar y, const SkIRect& clipBounds) override; |
41 void onDrawPosText(GrDrawContext*, GrRenderTarget*, | 46 void onDrawPosText(GrDrawContext*, GrRenderTarget*, |
42 const GrClip&, const GrPaint&, const SkPaint&, | 47 const GrClip&, const GrPaint&, const SkPaint&, |
43 const SkMatrix& viewMatrix, | 48 const SkMatrix& viewMatrix, |
44 const char text[], size_t byteLength, | 49 const char text[], size_t byteLength, |
45 const SkScalar pos[], int scalarsPerPosition, | 50 const SkScalar pos[], int scalarsPerPosition, |
46 const SkPoint& offset, const SkIRect& regionClipBounds) o
verride; | 51 const SkPoint& offset, const SkIRect& clipBounds) overrid
e; |
| 52 void drawTextBlob(GrDrawContext*, GrRenderTarget*, const GrClip&, const SkPa
int&, |
| 53 const SkMatrix& viewMatrix, const SkTextBlob*, SkScalar x,
SkScalar y, |
| 54 SkDrawFilter*, const SkIRect& clipBounds) override; |
47 | 55 |
48 class FallbackBlobBuilder; | 56 class FallbackBlobBuilder; |
49 | 57 |
50 class TextRun { | 58 class TextRun { |
51 public: | 59 public: |
52 TextRun(const SkPaint& fontAndStroke); | 60 TextRun(const SkPaint& fontAndStroke); |
53 ~TextRun(); | 61 ~TextRun(); |
54 | 62 |
55 void setText(const char text[], size_t byteLength, SkScalar x, SkScalar
y, | 63 void setText(const char text[], size_t byteLength, SkScalar x, SkScalar
y, |
56 GrContext*, const SkSurfaceProps*); | 64 GrContext*, const SkSurfaceProps*); |
57 | 65 |
58 void setPosText(const char text[], size_t byteLength, | 66 void setPosText(const char text[], size_t byteLength, |
59 const SkScalar pos[], int scalarsPerPosition, const SkPo
int& offset, | 67 const SkScalar pos[], int scalarsPerPosition, const SkPo
int& offset, |
60 GrContext*, const SkSurfaceProps*); | 68 GrContext*, const SkSurfaceProps*); |
61 | 69 |
62 void draw(GrDrawContext*, GrRenderTarget*, const GrClip&, const GrPaint&
, const SkMatrix&, | 70 void draw(GrDrawContext*, GrPipelineBuilder*, GrColor, const SkMatrix&, |
63 const SkIRect& regionClipBounds, GrTextContext* fallbackTextCo
ntext, | 71 SkScalar x, SkScalar y, const SkIRect& clipBounds, |
64 const SkPaint& originalSkPaint) const; | 72 GrTextContext* fallbackTextContext, const SkPaint& originalSkP
aint) const; |
| 73 |
| 74 int cpuMemorySize() const; |
65 | 75 |
66 private: | 76 private: |
67 GrPathRange* createGlyphs(GrContext*, SkGlyphCache*); | 77 GrPathRange* createGlyphs(GrContext*, SkGlyphCache*); |
68 | 78 |
69 void appendGlyph(const SkGlyph&, const SkPoint&, FallbackBlobBuilder*); | 79 void appendGlyph(const SkGlyph&, const SkPoint&, FallbackBlobBuilder*); |
70 | 80 |
71 GrStrokeInfo fStroke; | 81 GrStrokeInfo fStroke; |
72 SkPaint fFont; | 82 SkPaint fFont; |
73 SkScalar fTextRatio; | 83 SkScalar fTextRatio; |
74 float fTextInverseRatio; | 84 float fTextInverseRatio; |
75 SkMatrix fLocalMatrix; | |
76 bool fUsingRawGlyphPaths; | 85 bool fUsingRawGlyphPaths; |
| 86 int fTotalGlyphCount; |
77 SkAutoTUnref<GrPathRangeDraw> fDraw; | 87 SkAutoTUnref<GrPathRangeDraw> fDraw; |
78 SkAutoTUnref<const SkTextBlob> fFallbackTextBlob; | 88 SkAutoTUnref<const SkTextBlob> fFallbackTextBlob; |
| 89 mutable SkMatrix fLocalMatrixTemplate; |
79 }; | 90 }; |
80 | 91 |
| 92 // Text blobs/caches. |
| 93 |
| 94 class TextBlob : public SkTLList<TextRun> { |
| 95 public: |
| 96 typedef SkTArray<uint32_t, true> Key; |
| 97 |
| 98 static const Key& GetKey(const TextBlob* blob) { return blob->key(); } |
| 99 |
| 100 static uint32_t Hash(const Key& key) { |
| 101 SkASSERT(key.count() > 1); // 1-length keys should be using the blob
-id hash map. |
| 102 return SkChecksum::Murmur3(key.begin(), sizeof(uint32_t) * key.count
()); |
| 103 } |
| 104 |
| 105 TextBlob(uint32_t blobId, const SkTextBlob* skBlob, const SkPaint& skPai
nt, |
| 106 GrContext* ctx, const SkSurfaceProps* props) |
| 107 : fKey(&blobId, 1) { this->init(skBlob, skPaint, ctx, props); } |
| 108 |
| 109 TextBlob(const Key& key, const SkTextBlob* skBlob, const SkPaint& skPain
t, |
| 110 GrContext* ctx, const SkSurfaceProps* props) |
| 111 : fKey(key) { |
| 112 // 1-length keys are unterstood to be the blob id and must use the o
ther constructor. |
| 113 SkASSERT(fKey.count() > 1); |
| 114 this->init(skBlob, skPaint, ctx, props); |
| 115 } |
| 116 |
| 117 const Key& key() const { return fKey; } |
| 118 |
| 119 int cpuMemorySize() const { return fCpuMemorySize; } |
| 120 |
| 121 private: |
| 122 void init(const SkTextBlob*, const SkPaint&, GrContext*, const SkSurface
Props*); |
| 123 |
| 124 const SkSTArray<1, uint32_t, true> fKey; |
| 125 int fCpuMemorySize; |
| 126 |
| 127 SK_DECLARE_INTERNAL_LLIST_INTERFACE(TextBlob); |
| 128 }; |
| 129 |
| 130 const TextBlob& findOrCreateTextBlob(const SkTextBlob*, const SkPaint&); |
| 131 void purgeToFit(const TextBlob&); |
| 132 |
| 133 SkTHashMap<uint32_t, TextBlob*> fBlobIdCache; |
| 134 SkTHashTable<TextBlob*, const TextBlob::Key&, TextBlob> fBlobKeyCache; |
| 135 SkTInternalLList<TextBlob> fLRUList; |
| 136 int fCacheSize; |
| 137 |
81 typedef GrTextContext INHERITED; | 138 typedef GrTextContext INHERITED; |
82 }; | 139 }; |
83 | 140 |
84 #endif | 141 #endif |
OLD | NEW |