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 |
(...skipping 10 matching lines...) Expand all Loading... | |
21 class GrBatchTextStrike; | 21 class GrBatchTextStrike; |
22 class GrPipelineBuilder; | 22 class GrPipelineBuilder; |
23 class GrTextBlobCache; | 23 class GrTextBlobCache; |
24 | 24 |
25 /* | 25 /* |
26 * This class implements GrTextContext using standard bitmap fonts, and can also process textblobs. | 26 * This class implements GrTextContext using standard bitmap fonts, and can also process textblobs. |
27 * TODO replace GrBitmapTextContext | 27 * TODO replace GrBitmapTextContext |
28 */ | 28 */ |
29 class GrAtlasTextContext : public GrTextContext { | 29 class GrAtlasTextContext : public GrTextContext { |
30 public: | 30 public: |
31 static GrAtlasTextContext* Create(GrContext*, SkGpuDevice*, const SkDevicePr operties&); | 31 static GrAtlasTextContext* Create(GrContext*, SkGpuDevice*, const SkDevicePr operties&, |
32 bool enableDistanceFields); | |
bsalomon
2015/04/16 15:03:55
Maybe more a question for Jim: Should DF enable be
jvanverth1
2015/04/16 15:26:54
SkDeviceProperties is tied more to the physical de
| |
32 | 33 |
33 private: | 34 private: |
34 GrAtlasTextContext(GrContext*, SkGpuDevice*, const SkDeviceProperties&); | 35 GrAtlasTextContext(GrContext*, SkGpuDevice*, const SkDeviceProperties&, |
36 bool enableDistanceFields); | |
37 ~GrAtlasTextContext() {} | |
bsalomon
2015/04/16 15:03:55
override?
joshualitt
2015/04/16 15:36:12
Acknowledged.
| |
35 | 38 |
36 bool canDraw(const GrRenderTarget*, const GrClip&, const GrPaint&, | 39 bool canDraw(const GrRenderTarget*, const GrClip&, const GrPaint&, |
37 const SkPaint&, const SkMatrix& viewMatrix) override; | 40 const SkPaint&, const SkMatrix& viewMatrix) override; |
38 | 41 |
39 void onDrawText(GrRenderTarget*, const GrClip&, const GrPaint&, const SkPain t&, | 42 void onDrawText(GrRenderTarget*, const GrClip&, const GrPaint&, const SkPain t&, |
40 const SkMatrix& viewMatrix, const char text[], size_t byteLe ngth, | 43 const SkMatrix& viewMatrix, const char text[], size_t byteLe ngth, |
41 SkScalar x, SkScalar y, const SkIRect& regionClipBounds) ove rride; | 44 SkScalar x, SkScalar y, const SkIRect& regionClipBounds) ove rride; |
42 void onDrawPosText(GrRenderTarget*, const GrClip&, const GrPaint&, const SkP aint&, | 45 void onDrawPosText(GrRenderTarget*, const GrClip&, const GrPaint&, const SkP aint&, |
43 const SkMatrix& viewMatrix, | 46 const SkMatrix& viewMatrix, |
44 const char text[], size_t byteLength, | 47 const char text[], size_t byteLength, |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
78 * Finally, for runs where the entire thing is too large for the GrAtlas TextContext to | 81 * Finally, for runs where the entire thing is too large for the GrAtlas TextContext to |
79 * handle, we have a bit to mark the run as flusahable via rendering as paths. It is worth | 82 * handle, we have a bit to mark the run as flusahable via rendering as paths. It is worth |
80 * pointing. It would be a bit expensive to figure out ahead of time whe ther or not a run | 83 * pointing. It would be a bit expensive to figure out ahead of time whe ther or not a run |
81 * can flush in this manner, so we always allocate vertices for the run, regardless of | 84 * can flush in this manner, so we always allocate vertices for the run, regardless of |
82 * whether or not it is too large. The benefit of this strategy is that we can always reuse | 85 * whether or not it is too large. The benefit of this strategy is that we can always reuse |
83 * a blob allocation regardless of viewmatrix changes. We could store p ositions for these | 86 * a blob allocation regardless of viewmatrix changes. We could store p ositions for these |
84 * glyphs. However, its not clear if this is a win because we'd still h ave to either go the | 87 * glyphs. However, its not clear if this is a win because we'd still h ave to either go the |
85 * glyph cache to get the path at flush time, or hold onto the path in t he cache, which | 88 * glyph cache to get the path at flush time, or hold onto the path in t he cache, which |
86 * would greatly increase the memory of these cached items. | 89 * would greatly increase the memory of these cached items. |
87 */ | 90 */ |
88 struct Run { | 91 struct Run { |
bsalomon
2015/04/16 15:03:55
How much of Run and nested classes really needs to
joshualitt
2015/04/16 15:36:12
I think they have to be in the header because they
| |
89 Run() | 92 Run() |
90 : fColor(GrColor_ILLEGAL) | 93 : fColor(GrColor_ILLEGAL) |
91 , fInitialized(false) | 94 , fInitialized(false) |
92 , fDrawAsPaths(false) { | 95 , fDrawAsPaths(false){ |
bsalomon
2015/04/16 15:03:55
I liked that space before "{"
joshualitt
2015/04/16 15:36:12
Acknowledged.
| |
93 fVertexBounds.setLargestInverted(); | 96 fVertexBounds.setLargestInverted(); |
94 } | 97 } |
95 struct SubRunInfo { | 98 struct SubRunInfo { |
96 SubRunInfo() | 99 SubRunInfo() |
97 : fAtlasGeneration(GrBatchAtlas::kInvalidAtlasGeneration) | 100 : fAtlasGeneration(GrBatchAtlas::kInvalidAtlasGeneration) |
98 , fGlyphStartIndex(0) | 101 , fGlyphStartIndex(0) |
99 , fGlyphEndIndex(0) | 102 , fGlyphEndIndex(0) |
100 , fVertexStartIndex(0) | 103 , fVertexStartIndex(0) |
101 , fVertexEndIndex(0) {} | 104 , fVertexEndIndex(0) |
105 , fDrawAsDistanceFields(false) {} | |
102 GrMaskFormat fMaskFormat; | 106 GrMaskFormat fMaskFormat; |
103 uint64_t fAtlasGeneration; | 107 uint64_t fAtlasGeneration; |
104 uint32_t fGlyphStartIndex; | 108 uint32_t fGlyphStartIndex; |
105 uint32_t fGlyphEndIndex; | 109 uint32_t fGlyphEndIndex; |
106 size_t fVertexStartIndex; | 110 size_t fVertexStartIndex; |
107 size_t fVertexEndIndex; | 111 size_t fVertexEndIndex; |
108 GrBatchAtlas::BulkUseTokenUpdater fBulkUseToken; | 112 GrBatchAtlas::BulkUseTokenUpdater fBulkUseToken; |
113 | |
114 // distance field properties | |
115 bool fDrawAsDistanceFields; | |
116 bool fUseLCDText; | |
109 }; | 117 }; |
110 | 118 |
111 class SubRunInfoArray { | 119 class SubRunInfoArray { |
112 public: | 120 public: |
113 SubRunInfoArray() | 121 SubRunInfoArray() |
114 : fSubRunCount(0) | 122 : fSubRunCount(0) |
115 , fSubRunAllocation(kMinSubRuns) { | 123 , fSubRunAllocation(kMinSubRuns) { |
116 fPtr = reinterpret_cast<SubRunInfo*>(fSubRunStorage.get()); | 124 fPtr = reinterpret_cast<SubRunInfo*>(fSubRunStorage.get()); |
117 this->push_back(); | 125 this->push_back(); |
118 } | 126 } |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
220 | 228 |
221 void* operator new(size_t, void* p) { return p; } | 229 void* operator new(size_t, void* p) { return p; } |
222 void operator delete(void* target, void* placement) { | 230 void operator delete(void* target, void* placement) { |
223 ::operator delete(target, placement); | 231 ::operator delete(target, placement); |
224 } | 232 } |
225 }; | 233 }; |
226 | 234 |
227 typedef BitmapTextBlob::Run Run; | 235 typedef BitmapTextBlob::Run Run; |
228 typedef Run::SubRunInfo PerSubRunInfo; | 236 typedef Run::SubRunInfo PerSubRunInfo; |
229 | 237 |
230 void appendGlyph(BitmapTextBlob*, int runIndex, GrGlyph::PackedID, int left, int top, | 238 inline bool canDrawAsDistanceFields(const SkPaint&, const SkMatrix& viewMatr ix); |
231 GrColor color, GrFontScaler*, const SkIRect& clipRect); | 239 BitmapTextBlob* setupDfBlob(size_t glyphCount, const SkPaint& origPaint, |
bsalomon
2015/04/16 15:03:55
DFBlob? With few exceptions I think we usually cap
jvanverth1
2015/04/16 15:26:54
I agree, DF rather than Df.
joshualitt
2015/04/16 15:36:12
Acknowledged.
| |
240 const SkMatrix& viewMatrix, SkGlyphCache** cache , | |
241 SkPaint* dfPaint, SkScalar* textRatio); | |
242 void bmpAppendGlyph(BitmapTextBlob*, int runIndex, GrGlyph::PackedID, int le ft, int top, | |
243 GrColor color, GrFontScaler*, const SkIRect& clipRect); | |
244 bool dfAppendGlyph(BitmapTextBlob*, int runIndex, GrGlyph::PackedID, SkScala r sx, SkScalar sy, | |
245 GrColor color, GrFontScaler*, const SkIRect& clipRect, Sk Scalar textRatio, | |
246 const SkMatrix& viewMatrix); | |
247 inline void appendBigGlyph(BitmapTextBlob* blob, GrGlyph* glyph, | |
bsalomon
2015/04/16 15:03:55
Does "big" mean path?
joshualitt
2015/04/16 15:36:12
yes
| |
248 GrFontScaler* scaler, int x, int y); | |
249 inline void innerAppendGlyph(BitmapTextBlob*, Run*, Run::SubRunInfo*, | |
bsalomon
2015/04/16 15:03:55
appendGlyphCommon?
joshualitt
2015/04/16 15:36:12
Acknowledged.
| |
250 const SkRect& positions, GrColor color, | |
251 size_t vertexStride, bool useVertexColor, | |
252 GrGlyph::PackedID); | |
232 | 253 |
233 inline void flushRunAsPaths(const SkTextBlob::RunIterator&, const SkPaint&, SkDrawFilter*, | 254 inline void flushRunAsPaths(const SkTextBlob::RunIterator&, const SkPaint&, SkDrawFilter*, |
234 const SkMatrix& viewMatrix, const SkIRect& clipB ounds, SkScalar x, | 255 const SkMatrix& viewMatrix, const SkIRect& clipB ounds, SkScalar x, |
235 SkScalar y); | 256 SkScalar y); |
236 inline void flushRun(GrDrawTarget*, GrPipelineBuilder*, BitmapTextBlob*, int run, GrColor, | 257 inline void flushRun(GrDrawTarget*, GrPipelineBuilder*, BitmapTextBlob*, int run, GrColor, |
237 uint8_t paintAlpha, SkScalar transX, SkScalar transY); | 258 SkScalar transX, SkScalar transY, const SkPaint&); |
238 inline void flushBigGlyphs(BitmapTextBlob* cacheBlob, GrRenderTarget* rt, | 259 inline void flushBigGlyphs(BitmapTextBlob* cacheBlob, GrRenderTarget* rt, |
239 const GrPaint& grPaint, const GrClip& clip, | 260 const GrPaint& grPaint, const GrClip& clip, |
240 SkScalar transX, SkScalar transY); | 261 SkScalar transX, SkScalar transY); |
241 | 262 |
242 // We have to flush SkTextBlobs differently from drawText / drawPosText | 263 // We have to flush SkTextBlobs differently from drawText / drawPosText |
243 void flush(GrDrawTarget*, const SkTextBlob*, BitmapTextBlob*, GrRenderTarget *, const SkPaint&, | 264 void flush(GrDrawTarget*, const SkTextBlob*, BitmapTextBlob*, GrRenderTarget *, const SkPaint&, |
244 const GrPaint&, SkDrawFilter*, const GrClip&, const SkMatrix& vie wMatrix, | 265 const GrPaint&, SkDrawFilter*, const GrClip&, const SkMatrix& vie wMatrix, |
245 const SkIRect& clipBounds, SkScalar x, SkScalar y, SkScalar trans X, SkScalar transY); | 266 const SkIRect& clipBounds, SkScalar x, SkScalar y, SkScalar trans X, SkScalar transY); |
246 void flush(GrDrawTarget*, BitmapTextBlob*, GrRenderTarget*, const SkPaint&, | 267 void flush(GrDrawTarget*, BitmapTextBlob*, GrRenderTarget*, const SkPaint&, |
247 const GrPaint&, const GrClip&, const SkMatrix& viewMatrix); | 268 const GrPaint&, const GrClip&); |
248 | 269 |
249 void internalDrawText(BitmapTextBlob*, int runIndex, SkGlyphCache*, const Sk Paint&, | 270 // A helper for drawing BitmapText in a run of distance fields |
250 GrColor color, const SkMatrix& viewMatrix, | 271 inline void fallbackDrawPosText(GrRenderTarget*, const GrClip&, |
251 const char text[], size_t byteLength, | 272 const GrPaint&, |
252 SkScalar x, SkScalar y, const SkIRect& clipRect); | 273 const SkPaint&, const SkMatrix& viewMatrix, |
253 void internalDrawPosText(BitmapTextBlob*, int runIndex, SkGlyphCache*, const SkPaint&, | 274 const SkTArray<char>& fallbackTxt, |
275 const SkTArray<SkScalar>& fallbackPos, | |
276 int scalarsPerPosition, | |
277 const SkPoint& offset, | |
278 const SkIRect& clipRect); | |
279 | |
280 void internalDrawBmpText(BitmapTextBlob*, int runIndex, SkGlyphCache*, const SkPaint&, | |
254 GrColor color, const SkMatrix& viewMatrix, | 281 GrColor color, const SkMatrix& viewMatrix, |
255 const char text[], size_t byteLength, | 282 const char text[], size_t byteLength, |
256 const SkScalar pos[], int scalarsPerPosition, | 283 SkScalar x, SkScalar y, const SkIRect& clipRect); |
257 const SkPoint& offset, const SkIRect& clipRect); | 284 void internalDrawBmpPosText(BitmapTextBlob*, int runIndex, SkGlyphCache*, co nst SkPaint&, |
285 GrColor color, const SkMatrix& viewMatrix, | |
286 const char text[], size_t byteLength, | |
287 const SkScalar pos[], int scalarsPerPosition, | |
288 const SkPoint& offset, const SkIRect& clipRect); | |
289 | |
290 void internalDrawDfText(BitmapTextBlob*, int runIndex, SkGlyphCache*, const SkPaint&, | |
291 GrColor color, const SkMatrix& viewMatrix, | |
292 const char text[], size_t byteLength, | |
293 SkScalar x, SkScalar y, const SkIRect& clipRect, | |
294 SkScalar textRatio, | |
295 SkTArray<char>* fallbackTxt, | |
296 SkTArray<SkScalar>* fallbackPos, | |
297 SkPoint* offset, const SkPaint& origPaint); | |
298 void internalDrawDfPosText(BitmapTextBlob*, int runIndex, SkGlyphCache*, con st SkPaint&, | |
299 GrColor color, const SkMatrix& viewMatrix, | |
300 const char text[], size_t byteLength, | |
301 const SkScalar pos[], int scalarsPerPosition, | |
302 const SkPoint& offset, const SkIRect& clipRect, | |
303 SkScalar textRatio, | |
304 SkTArray<char>* fallbackTxt, | |
305 SkTArray<SkScalar>* fallbackPos); | |
258 | 306 |
259 // sets up the descriptor on the blob and returns a detached cache. Client must attach | 307 // sets up the descriptor on the blob and returns a detached cache. Client must attach |
260 inline static GrColor ComputeCanonicalColor(const SkPaint&, bool lcd); | 308 inline static GrColor ComputeCanonicalColor(const SkPaint&, bool lcd); |
261 inline SkGlyphCache* setupCache(Run*, const SkPaint&, const SkMatrix& viewMa trix); | 309 inline SkGlyphCache* setupCache(Run*, const SkPaint&, const SkMatrix* viewMa trix, bool noGamma); |
262 static inline bool MustRegenerateBlob(SkScalar* outTransX, SkScalar* outTran sY, | 310 static inline bool MustRegenerateBlob(SkScalar* outTransX, SkScalar* outTran sY, |
263 const BitmapTextBlob&, const SkPaint&, | 311 const BitmapTextBlob&, const SkPaint&, |
264 const SkMaskFilter::BlurRec&, | 312 const SkMaskFilter::BlurRec&, |
265 const SkMatrix& viewMatrix, SkScalar x , SkScalar y); | 313 const SkMatrix& viewMatrix, SkScalar x , SkScalar y); |
266 void regenerateTextBlob(BitmapTextBlob* bmp, const SkPaint& skPaint, GrColor , | 314 void regenerateTextBlob(BitmapTextBlob* bmp, const SkPaint& skPaint, GrColor , |
267 const SkMatrix& viewMatrix, | 315 const SkMatrix& viewMatrix, |
268 const SkTextBlob* blob, SkScalar x, SkScalar y, | 316 const SkTextBlob* blob, SkScalar x, SkScalar y, |
269 SkDrawFilter* drawFilter, const SkIRect& clipRect); | 317 SkDrawFilter* drawFilter, const SkIRect& clipRect); |
270 inline static bool HasLCD(const SkTextBlob*); | 318 inline static bool HasLCD(const SkTextBlob*); |
319 inline void initDistanceFieldPaint(SkPaint*, SkScalar* textRatio, const SkMa trix&); | |
320 | |
321 // Distance field text needs this table to compute a value for use in the fr agment shader. | |
322 // Because the GrAtlasTextContext can go out of scope before the final flush , this needs to be | |
323 // refcnted and malloced | |
324 struct DistanceAdjustTable : public SkNVRefCnt<DistanceAdjustTable> { | |
325 DistanceAdjustTable(float gamma) { this->buildDistanceAdjustTable(gamma) ; } | |
326 ~DistanceAdjustTable() { SkDELETE_ARRAY(fTable); } | |
327 | |
328 void buildDistanceAdjustTable(float gamma); | |
329 | |
330 SkScalar& operator[] (int i) { | |
331 return fTable[i]; | |
332 } | |
333 | |
334 const SkScalar& operator[] (int i) const { | |
335 return fTable[i]; | |
336 } | |
337 | |
338 SkScalar* fTable; | |
339 }; | |
271 | 340 |
272 GrBatchTextStrike* fCurrStrike; | 341 GrBatchTextStrike* fCurrStrike; |
273 GrTextBlobCache* fCache; | 342 GrTextBlobCache* fCache; |
343 bool fEnableDFRendering; | |
344 SkAutoTUnref<DistanceAdjustTable> fDistanceAdjustTable; | |
274 | 345 |
275 friend class GrTextBlobCache; | 346 friend class GrTextBlobCache; |
276 friend class BitmapTextBatch; | 347 friend class BitmapTextBatch; |
277 | 348 |
278 typedef GrTextContext INHERITED; | 349 typedef GrTextContext INHERITED; |
279 }; | 350 }; |
280 | 351 |
281 #endif | 352 #endif |
OLD | NEW |