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 GrAtlasTextBlob_DEFINED | 8 #ifndef GrAtlasTextBlob_DEFINED |
9 #define GrAtlasTextBlob_DEFINED | 9 #define GrAtlasTextBlob_DEFINED |
10 | 10 |
11 #include "GrBatchAtlas.h" | 11 #include "GrBatchAtlas.h" |
12 #include "GrBatchFontCache.h" | 12 #include "GrBatchFontCache.h" |
13 #include "GrColor.h" | 13 #include "GrColor.h" |
| 14 #include "GrMemoryPool.h" |
14 #include "SkDescriptor.h" | 15 #include "SkDescriptor.h" |
15 #include "SkMaskFilter.h" | 16 #include "SkMaskFilter.h" |
16 #include "GrMemoryPool.h" | |
17 #include "SkSurfaceProps.h" | 17 #include "SkSurfaceProps.h" |
18 #include "SkTInternalLList.h" | 18 #include "SkTInternalLList.h" |
19 | 19 |
| 20 struct GrDistanceFieldAdjustTable; |
| 21 class GrTextContext; |
| 22 class SkDrawFilter; |
| 23 class SkTextBlob; |
| 24 class SkTextBlobRunIterator; |
| 25 |
20 // With this flag enabled, the GrAtlasTextContext will, as a sanity check, regen
erate every blob | 26 // With this flag enabled, the GrAtlasTextContext will, as a sanity check, regen
erate every blob |
21 // that comes in to verify the integrity of its cache | 27 // that comes in to verify the integrity of its cache |
22 //#define CACHE_SANITY_CHECK // VERY SLOW | 28 //#define CACHE_SANITY_CHECK // VERY SLOW |
23 | 29 |
24 /* | 30 /* |
25 * A GrAtlasTextBlob contains a fully processed SkTextBlob, suitable for nearly
immediate drawing | 31 * A GrAtlasTextBlob contains a fully processed SkTextBlob, suitable for nearly
immediate drawing |
26 * on the GPU. These are initially created with valid positions and colors, but
invalid | 32 * on the GPU. These are initially created with valid positions and colors, but
invalid |
27 * texture coordinates. The GrAtlasTextBlob itself has a few Blob-wide properti
es, and also | 33 * texture coordinates. The GrAtlasTextBlob itself has a few Blob-wide properti
es, and also |
28 * consists of a number of runs. Runs inside a blob are flushed individually so
they can be | 34 * consists of a number of runs. Runs inside a blob are flushed individually so
they can be |
29 * reordered. | 35 * reordered. |
30 * | 36 * |
31 * The only thing(aside from a memcopy) required to flush a GrAtlasTextBlob is t
o ensure that | 37 * The only thing(aside from a memcopy) required to flush a GrAtlasTextBlob is t
o ensure that |
32 * the GrAtlas will not evict anything the Blob needs. | 38 * the GrAtlas will not evict anything the Blob needs. |
33 * | 39 * |
34 * Note: This struct should really be named GrCachedAtasTextBlob, but that is to
o verbose. | 40 * Note: This struct should really be named GrCachedAtasTextBlob, but that is to
o verbose. |
35 * | 41 * |
36 * *WARNING* If you add new fields to this struct, then you may need to to updat
e AssertEqual | 42 * *WARNING* If you add new fields to this struct, then you may need to to updat
e AssertEqual |
37 */ | 43 */ |
38 struct GrAtlasTextBlob : public SkNVRefCnt<GrAtlasTextBlob> { | 44 class GrAtlasTextBlob : public SkNVRefCnt<GrAtlasTextBlob> { |
| 45 public: |
39 SK_DECLARE_INTERNAL_LLIST_INTERFACE(GrAtlasTextBlob); | 46 SK_DECLARE_INTERNAL_LLIST_INTERFACE(GrAtlasTextBlob); |
40 | 47 |
41 /* | 48 /* |
42 * Each Run inside of the blob can have its texture coordinates regenerated
if required. | 49 * Each Run inside of the blob can have its texture coordinates regenerated
if required. |
43 * To determine if regeneration is necessary, fAtlasGeneration is used. If
there have been | 50 * To determine if regeneration is necessary, fAtlasGeneration is used. If
there have been |
44 * any evictions inside of the atlas, then we will simply regenerate Runs.
We could track | 51 * any evictions inside of the atlas, then we will simply regenerate Runs.
We could track |
45 * this at a more fine grained level, but its not clear if this is worth it,
as evictions | 52 * this at a more fine grained level, but its not clear if this is worth it,
as evictions |
46 * should be fairly rare. | 53 * should be fairly rare. |
47 * | 54 * |
48 * One additional point, each run can contain glyphs with any of the three m
ask formats. | 55 * One additional point, each run can contain glyphs with any of the three m
ask formats. |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 return kColorTextVASize; | 308 return kColorTextVASize; |
302 default: | 309 default: |
303 return kLCDTextVASize; | 310 return kLCDTextVASize; |
304 } | 311 } |
305 } | 312 } |
306 | 313 |
307 bool mustRegenerate(SkScalar* outTransX, SkScalar* outTransY, const SkPaint&
paint, | 314 bool mustRegenerate(SkScalar* outTransX, SkScalar* outTransY, const SkPaint&
paint, |
308 GrColor color, const SkMaskFilter::BlurRec& blurRec, | 315 GrColor color, const SkMaskFilter::BlurRec& blurRec, |
309 const SkMatrix& viewMatrix, SkScalar x, SkScalar y); | 316 const SkMatrix& viewMatrix, SkScalar x, SkScalar y); |
310 | 317 |
| 318 // flush a GrAtlasTextBlob associated with a SkTextBlob |
| 319 void flushCached(const SkTextBlob* blob, |
| 320 GrContext* context, |
| 321 GrDrawContext* dc, |
| 322 GrTextContext* textContext, |
| 323 const SkSurfaceProps& props, |
| 324 const GrDistanceFieldAdjustTable* distanceAdjustTable, |
| 325 const SkPaint& skPaint, |
| 326 const GrPaint& grPaint, |
| 327 SkDrawFilter* drawFilter, |
| 328 const GrClip& clip, |
| 329 const SkMatrix& viewMatrix, |
| 330 const SkIRect& clipBounds, |
| 331 SkScalar x, SkScalar y, |
| 332 SkScalar transX, SkScalar transY); |
| 333 |
| 334 // flush a throwaway GrAtlasTextBlob *not* associated with an SkTextBlob |
| 335 void flushThrowaway(GrContext* context, |
| 336 GrDrawContext* dc, |
| 337 const SkSurfaceProps& props, |
| 338 const GrDistanceFieldAdjustTable* distanceAdjustTable, |
| 339 const SkPaint& skPaint, |
| 340 const GrPaint& grPaint, |
| 341 const GrClip& clip, |
| 342 const SkIRect& clipBounds); |
| 343 |
311 // position + local coord | 344 // position + local coord |
312 static const size_t kColorTextVASize = sizeof(SkPoint) + sizeof(SkIPoint16); | 345 static const size_t kColorTextVASize = sizeof(SkPoint) + sizeof(SkIPoint16); |
313 static const size_t kGrayTextVASize = sizeof(SkPoint) + sizeof(GrColor) + si
zeof(SkIPoint16); | 346 static const size_t kGrayTextVASize = sizeof(SkPoint) + sizeof(GrColor) + si
zeof(SkIPoint16); |
314 static const size_t kLCDTextVASize = kGrayTextVASize; | 347 static const size_t kLCDTextVASize = kGrayTextVASize; |
315 static const int kVerticesPerGlyph = 4; | 348 static const int kVerticesPerGlyph = 4; |
316 | 349 |
317 #ifdef CACHE_SANITY_CHECK | 350 #ifdef CACHE_SANITY_CHECK |
318 static void AssertEqual(const GrAtlasTextBlob&, const GrAtlasTextBlob&); | 351 static void AssertEqual(const GrAtlasTextBlob&, const GrAtlasTextBlob&); |
319 size_t fSize; | 352 size_t fSize; |
320 #endif | 353 #endif |
| 354 |
| 355 // We'd like to inline this and make it private, but there is some test code
which calls it. |
| 356 // TODO refactor this |
| 357 GrDrawBatch* createBatch(const Run::SubRunInfo& info, |
| 358 int glyphCount, int run, int subRun, |
| 359 GrColor color, SkScalar transX, SkScalar transY, |
| 360 const SkPaint& skPaint, const SkSurfaceProps& props
, |
| 361 const GrDistanceFieldAdjustTable* distanceAdjustTab
le, |
| 362 GrBatchFontCache* cache); |
| 363 |
321 private: | 364 private: |
322 void appendLargeGlyph(GrGlyph* glyph, GrFontScaler* scaler, const SkGlyph& s
kGlyph, | 365 void appendLargeGlyph(GrGlyph* glyph, GrFontScaler* scaler, const SkGlyph& s
kGlyph, |
323 SkScalar x, SkScalar y, SkScalar scale, bool applyVM); | 366 SkScalar x, SkScalar y, SkScalar scale, bool applyVM); |
| 367 |
| 368 inline void flushRun(GrDrawContext* dc, GrPipelineBuilder* pipelineBuilder, |
| 369 int run, GrColor color, |
| 370 SkScalar transX, SkScalar transY, |
| 371 const SkPaint& skPaint, const SkSurfaceProps& props, |
| 372 const GrDistanceFieldAdjustTable* distanceAdjustTable, |
| 373 GrBatchFontCache* cache); |
| 374 |
| 375 void flushBigGlyphs(GrContext* context, GrDrawContext* dc, |
| 376 const GrClip& clip, const SkPaint& skPaint, |
| 377 SkScalar transX, SkScalar transY, |
| 378 const SkIRect& clipBounds); |
| 379 |
| 380 void flushRunAsPaths(GrDrawContext* dc, |
| 381 GrTextContext* textContext, |
| 382 const SkSurfaceProps& props, |
| 383 const SkTextBlobRunIterator& it, |
| 384 const GrClip& clip, const SkPaint& skPaint, |
| 385 SkDrawFilter* drawFilter, const SkMatrix& viewMatrix, |
| 386 const SkIRect& clipBounds, SkScalar x, SkScalar y); |
324 }; | 387 }; |
325 | 388 |
326 #endif | 389 #endif |
OLD | NEW |