OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 GrAtlasTextContext_DEFINED | 8 #ifndef GrAtlasTextContext_DEFINED |
9 #define GrAtlasTextContext_DEFINED | 9 #define GrAtlasTextContext_DEFINED |
10 | 10 |
11 #include "GrTextContext.h" | 11 #include "GrTextContext.h" |
12 | 12 |
13 #include "GrBatchAtlas.h" | 13 #include "GrBatchAtlas.h" |
14 #include "GrGeometryProcessor.h" | 14 #include "GrGeometryProcessor.h" |
15 #include "SkDescriptor.h" | 15 #include "SkDescriptor.h" |
| 16 #include "GrMemoryPool.h" |
16 #include "SkTextBlob.h" | 17 #include "SkTextBlob.h" |
17 #include "SkTDynamicHash.h" | |
18 #include "SkTInternalLList.h" | 18 #include "SkTInternalLList.h" |
19 | 19 |
20 class GrBatchTextStrike; | 20 class GrBatchTextStrike; |
21 class GrPipelineBuilder; | 21 class GrPipelineBuilder; |
| 22 class GrTextBlobCache; |
22 | 23 |
23 /* | 24 /* |
24 * This class implements GrTextContext using standard bitmap fonts, and can also
process textblobs. | 25 * This class implements GrTextContext using standard bitmap fonts, and can also
process textblobs. |
25 * TODO replace GrBitmapTextContext | 26 * TODO replace GrBitmapTextContext |
26 */ | 27 */ |
27 class GrAtlasTextContext : public GrTextContext { | 28 class GrAtlasTextContext : public GrTextContext { |
28 public: | 29 public: |
29 static GrAtlasTextContext* Create(GrContext*, SkGpuDevice*, const SkDevicePr
operties&); | 30 static GrAtlasTextContext* Create(GrContext*, SkGpuDevice*, const SkDevicePr
operties&); |
30 | 31 |
31 virtual ~GrAtlasTextContext(); | |
32 | |
33 private: | 32 private: |
34 GrAtlasTextContext(GrContext*, SkGpuDevice*, const SkDeviceProperties&); | 33 GrAtlasTextContext(GrContext*, SkGpuDevice*, const SkDeviceProperties&); |
35 | 34 |
36 bool canDraw(const GrRenderTarget*, const GrClip&, const GrPaint&, | 35 bool canDraw(const GrRenderTarget*, const GrClip&, const GrPaint&, |
37 const SkPaint&, const SkMatrix& viewMatrix) override; | 36 const SkPaint&, const SkMatrix& viewMatrix) override; |
38 | 37 |
39 void onDrawText(GrRenderTarget*, const GrClip&, const GrPaint&, const SkPain
t&, | 38 void onDrawText(GrRenderTarget*, const GrClip&, const GrPaint&, const SkPain
t&, |
40 const SkMatrix& viewMatrix, const char text[], size_t byteLe
ngth, | 39 const SkMatrix& viewMatrix, const char text[], size_t byteLe
ngth, |
41 SkScalar x, SkScalar y, const SkIRect& regionClipBounds) ove
rride; | 40 SkScalar x, SkScalar y, const SkIRect& regionClipBounds) ove
rride; |
42 void onDrawPosText(GrRenderTarget*, const GrClip&, const GrPaint&, const SkP
aint&, | 41 void onDrawPosText(GrRenderTarget*, const GrClip&, const GrPaint&, const SkP
aint&, |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 }; | 118 }; |
120 | 119 |
121 struct BigGlyph { | 120 struct BigGlyph { |
122 BigGlyph(const SkPath& path, int vx, int vy) : fPath(path), fVx(vx),
fVy(vy) {} | 121 BigGlyph(const SkPath& path, int vx, int vy) : fPath(path), fVx(vx),
fVy(vy) {} |
123 SkPath fPath; | 122 SkPath fPath; |
124 int fVx; | 123 int fVx; |
125 int fVy; | 124 int fVy; |
126 }; | 125 }; |
127 | 126 |
128 SkTArray<BigGlyph> fBigGlyphs; | 127 SkTArray<BigGlyph> fBigGlyphs; |
| 128 GrColor fColor; // the original color on the paint |
129 SkMatrix fViewMatrix; | 129 SkMatrix fViewMatrix; |
130 SkScalar fX; | 130 SkScalar fX; |
131 SkScalar fY; | 131 SkScalar fY; |
132 SkPaint::Style fStyle; | 132 SkPaint::Style fStyle; |
133 int fRunCount; | 133 int fRunCount; |
134 uint32_t fUniqueID; | 134 uint32_t fUniqueID; |
135 size_t fSize; | |
136 GrMemoryPool* fPool; | 135 GrMemoryPool* fPool; |
137 | 136 |
138 // all glyph / vertex offsets are into these pools. | 137 // all glyph / vertex offsets are into these pools. |
139 unsigned char* fVertices; | 138 unsigned char* fVertices; |
140 GrGlyph::PackedID* fGlyphIDs; | 139 GrGlyph::PackedID* fGlyphIDs; |
141 Run* fRuns; | 140 Run* fRuns; |
142 | 141 |
143 static const uint32_t& GetKey(const BitmapTextBlob& blob) { | 142 static const uint32_t& GetKey(const BitmapTextBlob& blob) { |
144 return blob.fUniqueID; | 143 return blob.fUniqueID; |
145 } | 144 } |
(...skipping 13 matching lines...) Expand all Loading... |
159 | 158 |
160 void* operator new(size_t, void* p) { return p; } | 159 void* operator new(size_t, void* p) { return p; } |
161 void operator delete(void* target, void* placement) { | 160 void operator delete(void* target, void* placement) { |
162 ::operator delete(target, placement); | 161 ::operator delete(target, placement); |
163 } | 162 } |
164 }; | 163 }; |
165 | 164 |
166 typedef BitmapTextBlob::Run Run; | 165 typedef BitmapTextBlob::Run Run; |
167 typedef Run::SubRunInfo PerSubRunInfo; | 166 typedef Run::SubRunInfo PerSubRunInfo; |
168 | 167 |
169 BitmapTextBlob* CreateBlob(int glyphCount, int runCount, GrMemoryPool*); | |
170 | |
171 void appendGlyph(BitmapTextBlob*, int runIndex, GrGlyph::PackedID, int left,
int top, | 168 void appendGlyph(BitmapTextBlob*, int runIndex, GrGlyph::PackedID, int left,
int top, |
172 GrColor color, GrFontScaler*, const SkIRect& clipRect); | 169 GrColor color, GrFontScaler*, const SkIRect& clipRect); |
173 | 170 |
174 inline void flushRunAsPaths(const SkTextBlob::RunIterator&, const SkPaint&,
SkDrawFilter*, | 171 inline void flushRunAsPaths(const SkTextBlob::RunIterator&, const SkPaint&,
SkDrawFilter*, |
175 const SkMatrix& viewMatrix, const SkIRect& clipB
ounds, SkScalar x, | 172 const SkMatrix& viewMatrix, const SkIRect& clipB
ounds, SkScalar x, |
176 SkScalar y); | 173 SkScalar y); |
177 inline void flushRun(GrDrawTarget*, GrPipelineBuilder*, BitmapTextBlob*, int
run, GrColor, | 174 inline void flushRun(GrDrawTarget*, GrPipelineBuilder*, BitmapTextBlob*, int
run, GrColor, |
178 uint8_t paintAlpha); | 175 uint8_t paintAlpha, SkScalar transX, SkScalar transY); |
179 inline void flushBigGlyphs(BitmapTextBlob* cacheBlob, GrRenderTarget* rt, | 176 inline void flushBigGlyphs(BitmapTextBlob* cacheBlob, GrRenderTarget* rt, |
180 const GrPaint& grPaint, const GrClip& clip); | 177 const GrPaint& grPaint, const GrClip& clip, |
| 178 SkScalar transX, SkScalar transY); |
181 | 179 |
182 // We have to flush SkTextBlobs differently from drawText / drawPosText | 180 // We have to flush SkTextBlobs differently from drawText / drawPosText |
183 void flush(GrDrawTarget*, const SkTextBlob*, BitmapTextBlob*, GrRenderTarget
*, const SkPaint&, | 181 void flush(GrDrawTarget*, const SkTextBlob*, BitmapTextBlob*, GrRenderTarget
*, const SkPaint&, |
184 const GrPaint&, SkDrawFilter*, const GrClip&, const SkMatrix& vie
wMatrix, | 182 const GrPaint&, SkDrawFilter*, const GrClip&, const SkMatrix& vie
wMatrix, |
185 const SkIRect& clipBounds, SkScalar x, SkScalar y); | 183 const SkIRect& clipBounds, SkScalar x, SkScalar y, SkScalar trans
X, SkScalar transY); |
186 void flush(GrDrawTarget*, BitmapTextBlob*, GrRenderTarget*, const SkPaint&, | 184 void flush(GrDrawTarget*, BitmapTextBlob*, GrRenderTarget*, const SkPaint&, |
187 const GrPaint&, const GrClip&, const SkMatrix& viewMatrix); | 185 const GrPaint&, const GrClip&, const SkMatrix& viewMatrix); |
188 | 186 |
189 void internalDrawText(BitmapTextBlob*, int runIndex, SkGlyphCache*, const Sk
Paint&, | 187 void internalDrawText(BitmapTextBlob*, int runIndex, SkGlyphCache*, const Sk
Paint&, |
190 const SkMatrix& viewMatrix, const char text[], size_t
byteLength, | 188 const SkMatrix& viewMatrix, const char text[], size_t
byteLength, |
191 SkScalar x, SkScalar y, const SkIRect& clipRect); | 189 SkScalar x, SkScalar y, const SkIRect& clipRect); |
192 void internalDrawPosText(BitmapTextBlob*, int runIndex, SkGlyphCache*, const
SkPaint&, | 190 void internalDrawPosText(BitmapTextBlob*, int runIndex, SkGlyphCache*, const
SkPaint&, |
193 const SkMatrix& viewMatrix, | 191 const SkMatrix& viewMatrix, |
194 const char text[], size_t byteLength, | 192 const char text[], size_t byteLength, |
195 const SkScalar pos[], int scalarsPerPosition, | 193 const SkScalar pos[], int scalarsPerPosition, |
196 const SkPoint& offset, const SkIRect& clipRect); | 194 const SkPoint& offset, const SkIRect& clipRect); |
197 | 195 |
198 // sets up the descriptor on the blob and returns a detached cache. Client
must attach | 196 // sets up the descriptor on the blob and returns a detached cache. Client
must attach |
199 inline SkGlyphCache* setupCache(Run*, const SkPaint&, const SkMatrix& viewMa
trix); | 197 inline SkGlyphCache* setupCache(Run*, const SkPaint&, const SkMatrix& viewMa
trix); |
200 static inline bool MustRegenerateBlob(const BitmapTextBlob&, const SkPaint&, | 198 static inline bool MustRegenerateBlob(SkScalar* outTransX, SkScalar* outTran
sY, |
| 199 const BitmapTextBlob&, const SkPaint&, |
201 const SkMatrix& viewMatrix, SkScalar x
, SkScalar y); | 200 const SkMatrix& viewMatrix, SkScalar x
, SkScalar y); |
202 void regenerateTextBlob(BitmapTextBlob* bmp, const SkPaint& skPaint, const S
kMatrix& viewMatrix, | 201 void regenerateTextBlob(BitmapTextBlob* bmp, const SkPaint& skPaint, const S
kMatrix& viewMatrix, |
203 const SkTextBlob* blob, SkScalar x, SkScalar y, | 202 const SkTextBlob* blob, SkScalar x, SkScalar y, |
204 SkDrawFilter* drawFilter, const SkIRect& clipRect); | 203 SkDrawFilter* drawFilter, const SkIRect& clipRect); |
205 | 204 |
206 // TODO this currently only uses the public interface of SkTextBlob, however
, I may need to add | |
207 // functionality to it while looping over the runs so I'm putting this here
for the time being. | |
208 // If this lands in Chrome without changes, move it to SkTextBlob. | |
209 static inline void BlobGlyphCount(int* glyphCount, int* runCount, const SkTe
xtBlob*); | |
210 | |
211 GrBatchTextStrike* fCurrStrike; | 205 GrBatchTextStrike* fCurrStrike; |
| 206 GrTextBlobCache* fCache; |
212 | 207 |
213 friend class GrTextBlobCache; | 208 friend class GrTextBlobCache; |
214 friend class BitmapTextBatch; | 209 friend class BitmapTextBatch; |
215 | 210 |
216 typedef GrTextContext INHERITED; | 211 typedef GrTextContext INHERITED; |
217 }; | 212 }; |
218 | 213 |
219 #endif | 214 #endif |
OLD | NEW |