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 "GrMemoryPool.h" |
15 #include "SkDescriptor.h" | 15 #include "SkDescriptor.h" |
16 #include "SkMaskFilter.h" | 16 #include "SkMaskFilter.h" |
17 #include "SkSurfaceProps.h" | 17 #include "SkSurfaceProps.h" |
18 #include "SkTInternalLList.h" | 18 #include "SkTInternalLList.h" |
19 | 19 |
20 struct GrDistanceFieldAdjustTable; | 20 struct GrDistanceFieldAdjustTable; |
| 21 class GrMemoryPool; |
21 class GrTextContext; | 22 class GrTextContext; |
22 class SkDrawFilter; | 23 class SkDrawFilter; |
23 class SkTextBlob; | 24 class SkTextBlob; |
24 class SkTextBlobRunIterator; | 25 class SkTextBlobRunIterator; |
25 | 26 |
26 // With this flag enabled, the GrAtlasTextContext will, as a sanity check, regen
erate every blob | 27 // With this flag enabled, the GrAtlasTextContext will, as a sanity check, regen
erate every blob |
27 // that comes in to verify the integrity of its cache | 28 // that comes in to verify the integrity of its cache |
28 #define CACHE_SANITY_CHECK 0 | 29 #define CACHE_SANITY_CHECK 0 |
29 | 30 |
30 /* | 31 /* |
31 * A GrAtlasTextBlob contains a fully processed SkTextBlob, suitable for nearly
immediate drawing | 32 * A GrAtlasTextBlob contains a fully processed SkTextBlob, suitable for nearly
immediate drawing |
32 * on the GPU. These are initially created with valid positions and colors, but
invalid | 33 * on the GPU. These are initially created with valid positions and colors, but
invalid |
33 * texture coordinates. The GrAtlasTextBlob itself has a few Blob-wide properti
es, and also | 34 * texture coordinates. The GrAtlasTextBlob itself has a few Blob-wide properti
es, and also |
34 * consists of a number of runs. Runs inside a blob are flushed individually so
they can be | 35 * consists of a number of runs. Runs inside a blob are flushed individually so
they can be |
35 * reordered. | 36 * reordered. |
36 * | 37 * |
37 * The only thing(aside from a memcopy) required to flush a GrAtlasTextBlob is t
o ensure that | 38 * The only thing(aside from a memcopy) required to flush a GrAtlasTextBlob is t
o ensure that |
38 * the GrAtlas will not evict anything the Blob needs. | 39 * the GrAtlas will not evict anything the Blob needs. |
39 * | 40 * |
40 * Note: This struct should really be named GrCachedAtasTextBlob, but that is to
o verbose. | 41 * Note: This struct should really be named GrCachedAtasTextBlob, but that is to
o verbose. |
41 * | 42 * |
42 * *WARNING* If you add new fields to this struct, then you may need to to updat
e AssertEqual | 43 * *WARNING* If you add new fields to this struct, then you may need to to updat
e AssertEqual |
43 */ | 44 */ |
44 class GrAtlasTextBlob : public SkNVRefCnt<GrAtlasTextBlob> { | 45 class GrAtlasTextBlob : public SkNVRefCnt<GrAtlasTextBlob> { |
45 public: | 46 public: |
46 SK_DECLARE_INTERNAL_LLIST_INTERFACE(GrAtlasTextBlob); | 47 SK_DECLARE_INTERNAL_LLIST_INTERFACE(GrAtlasTextBlob); |
47 | 48 |
48 GrAtlasTextBlob() | 49 static GrAtlasTextBlob* Create(GrMemoryPool* pool, int glyphCount, int runCo
unt); |
49 : fMaxMinScale(-SK_ScalarMax) | |
50 , fMinMaxScale(SK_ScalarMax) | |
51 , fTextType(0) {} | |
52 | |
53 ~GrAtlasTextBlob() { | |
54 for (int i = 0; i < fRunCount; i++) { | |
55 fRuns[i].~Run(); | |
56 } | |
57 } | |
58 | 50 |
59 struct Key { | 51 struct Key { |
60 Key() { | 52 Key() { |
61 sk_bzero(this, sizeof(Key)); | 53 sk_bzero(this, sizeof(Key)); |
62 } | 54 } |
63 uint32_t fUniqueID; | 55 uint32_t fUniqueID; |
64 // Color may affect the gamma of the mask we generate, but in a fairly l
imited way. | 56 // Color may affect the gamma of the mask we generate, but in a fairly l
imited way. |
65 // Each color is assigned to on of a fixed number of buckets based on it
s | 57 // Each color is assigned to on of a fixed number of buckets based on it
s |
66 // luminance. For each luminance bucket there is a "canonical color" tha
t | 58 // luminance. For each luminance bucket there is a "canonical color" tha
t |
67 // represents the bucket. This functionality is currently only supporte
d for A8 | 59 // represents the bucket. This functionality is currently only supporte
d for A8 |
68 SkColor fCanonicalColor; | 60 SkColor fCanonicalColor; |
69 SkPaint::Style fStyle; | 61 SkPaint::Style fStyle; |
70 SkPixelGeometry fPixelGeometry; | 62 SkPixelGeometry fPixelGeometry; |
71 bool fHasBlur; | 63 bool fHasBlur; |
72 | 64 |
73 bool operator==(const Key& other) const { | 65 bool operator==(const Key& other) const { |
74 return 0 == memcmp(this, &other, sizeof(Key)); | 66 return 0 == memcmp(this, &other, sizeof(Key)); |
75 } | 67 } |
76 }; | 68 }; |
77 | 69 |
| 70 void setupKey(const GrAtlasTextBlob::Key& key, |
| 71 const SkMaskFilter::BlurRec& blurRec, |
| 72 const SkPaint& paint) { |
| 73 fKey = key; |
| 74 if (key.fHasBlur) { |
| 75 fBlurRec = blurRec; |
| 76 } |
| 77 if (key.fStyle != SkPaint::kFill_Style) { |
| 78 fStrokeInfo.fFrameWidth = paint.getStrokeWidth(); |
| 79 fStrokeInfo.fMiterLimit = paint.getStrokeMiter(); |
| 80 fStrokeInfo.fJoin = paint.getStrokeJoin(); |
| 81 } |
| 82 } |
| 83 |
78 static const Key& GetKey(const GrAtlasTextBlob& blob) { | 84 static const Key& GetKey(const GrAtlasTextBlob& blob) { |
79 return blob.fKey; | 85 return blob.fKey; |
80 } | 86 } |
81 | 87 |
82 static uint32_t Hash(const Key& key) { | 88 static uint32_t Hash(const Key& key) { |
83 return SkChecksum::Murmur3(&key, sizeof(Key)); | 89 return SkChecksum::Murmur3(&key, sizeof(Key)); |
84 } | 90 } |
85 | 91 |
86 void operator delete(void* p) { | 92 void operator delete(void* p) { |
87 GrAtlasTextBlob* blob = reinterpret_cast<GrAtlasTextBlob*>(p); | 93 GrAtlasTextBlob* blob = reinterpret_cast<GrAtlasTextBlob*>(p); |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 const GrDistanceFieldAdjustTable* distanceAdjustTable, | 197 const GrDistanceFieldAdjustTable* distanceAdjustTable, |
192 const SkPaint& skPaint, | 198 const SkPaint& skPaint, |
193 const GrPaint& grPaint, | 199 const GrPaint& grPaint, |
194 const GrClip& clip, | 200 const GrClip& clip, |
195 const SkIRect& clipBounds); | 201 const SkIRect& clipBounds); |
196 | 202 |
197 // position + local coord | 203 // position + local coord |
198 static const size_t kColorTextVASize = sizeof(SkPoint) + sizeof(SkIPoint16); | 204 static const size_t kColorTextVASize = sizeof(SkPoint) + sizeof(SkIPoint16); |
199 static const size_t kGrayTextVASize = sizeof(SkPoint) + sizeof(GrColor) + si
zeof(SkIPoint16); | 205 static const size_t kGrayTextVASize = sizeof(SkPoint) + sizeof(GrColor) + si
zeof(SkIPoint16); |
200 static const size_t kLCDTextVASize = kGrayTextVASize; | 206 static const size_t kLCDTextVASize = kGrayTextVASize; |
| 207 static const size_t kMaxVASize = kGrayTextVASize; |
201 static const int kVerticesPerGlyph = 4; | 208 static const int kVerticesPerGlyph = 4; |
202 | 209 |
203 static void AssertEqual(const GrAtlasTextBlob&, const GrAtlasTextBlob&); | 210 static void AssertEqual(const GrAtlasTextBlob&, const GrAtlasTextBlob&); |
204 | 211 |
205 // The color here is the GrPaint color, and it is used to determine whether
we | 212 // The color here is the GrPaint color, and it is used to determine whether
we |
206 // have to regenerate LCD text blobs. | 213 // have to regenerate LCD text blobs. |
207 // We use this color vs the SkPaint color because it has the colorfilter app
lied. | 214 // We use this color vs the SkPaint color because it has the colorfilter app
lied. |
208 void initReusableBlob(GrColor color, const SkMatrix& viewMatrix, SkScalar x,
SkScalar y) { | 215 void initReusableBlob(GrColor color, const SkMatrix& viewMatrix, SkScalar x,
SkScalar y) { |
209 fPaintColor = color; | 216 fPaintColor = color; |
210 this->setupViewMatrix(viewMatrix, x, y); | 217 this->setupViewMatrix(viewMatrix, x, y); |
211 } | 218 } |
212 | 219 |
213 void initThrowawayBlob(const SkMatrix& viewMatrix, SkScalar x, SkScalar y) { | 220 void initThrowawayBlob(const SkMatrix& viewMatrix, SkScalar x, SkScalar y) { |
214 this->setupViewMatrix(viewMatrix, x, y); | 221 this->setupViewMatrix(viewMatrix, x, y); |
215 } | 222 } |
216 | 223 |
217 GrDrawBatch* test_createBatch(int glyphCount, int run, int subRun, | 224 GrDrawBatch* test_createBatch(int glyphCount, int run, int subRun, |
218 GrColor color, SkScalar transX, SkScalar trans
Y, | 225 GrColor color, SkScalar transX, SkScalar trans
Y, |
219 const SkPaint& skPaint, const SkSurfaceProps&
props, | 226 const SkPaint& skPaint, const SkSurfaceProps&
props, |
220 const GrDistanceFieldAdjustTable* distanceAdju
stTable, | 227 const GrDistanceFieldAdjustTable* distanceAdju
stTable, |
221 GrBatchFontCache* cache); | 228 GrBatchFontCache* cache); |
222 | 229 |
| 230 const Key& key() const { return fKey; } |
| 231 |
| 232 ~GrAtlasTextBlob() { |
| 233 for (int i = 0; i < fRunCount; i++) { |
| 234 fRuns[i].~Run(); |
| 235 } |
| 236 } |
| 237 |
223 private: | 238 private: |
| 239 GrAtlasTextBlob() |
| 240 : fMaxMinScale(-SK_ScalarMax) |
| 241 , fMinMaxScale(SK_ScalarMax) |
| 242 , fTextType(0) {} |
| 243 |
224 void appendLargeGlyph(GrGlyph* glyph, GrFontScaler* scaler, const SkGlyph& s
kGlyph, | 244 void appendLargeGlyph(GrGlyph* glyph, GrFontScaler* scaler, const SkGlyph& s
kGlyph, |
225 SkScalar x, SkScalar y, SkScalar scale, bool applyVM); | 245 SkScalar x, SkScalar y, SkScalar scale, bool applyVM); |
226 | 246 |
227 inline void flushRun(GrDrawContext* dc, GrPipelineBuilder* pipelineBuilder, | 247 inline void flushRun(GrDrawContext* dc, GrPipelineBuilder* pipelineBuilder, |
228 int run, GrColor color, | 248 int run, GrColor color, |
229 SkScalar transX, SkScalar transY, | 249 SkScalar transX, SkScalar transY, |
230 const SkPaint& skPaint, const SkSurfaceProps& props, | 250 const SkPaint& skPaint, const SkSurfaceProps& props, |
231 const GrDistanceFieldAdjustTable* distanceAdjustTable, | 251 const GrDistanceFieldAdjustTable* distanceAdjustTable, |
232 GrBatchFontCache* cache); | 252 GrBatchFontCache* cache); |
233 | 253 |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
449 | 469 |
450 // We can reuse distance field text, but only if the new viewmatrix would no
t result in | 470 // We can reuse distance field text, but only if the new viewmatrix would no
t result in |
451 // a mip change. Because there can be multiple runs in a blob, we track the
overall | 471 // a mip change. Because there can be multiple runs in a blob, we track the
overall |
452 // maximum minimum scale, and minimum maximum scale, we can support before w
e need to regen | 472 // maximum minimum scale, and minimum maximum scale, we can support before w
e need to regen |
453 SkScalar fMaxMinScale; | 473 SkScalar fMaxMinScale; |
454 SkScalar fMinMaxScale; | 474 SkScalar fMinMaxScale; |
455 int fRunCount; | 475 int fRunCount; |
456 uint8_t fTextType; | 476 uint8_t fTextType; |
457 | 477 |
458 friend class GrAtlasTextBatch; // We might be able to get rid of this friend
ing | 478 friend class GrAtlasTextBatch; // We might be able to get rid of this friend
ing |
459 friend class GrTextBlobCache; // Needs to access the key | |
460 }; | 479 }; |
461 | 480 |
462 #endif | 481 #endif |
OLD | NEW |