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 #include "GrAtlasTextContext.h" | 7 #include "GrAtlasTextContext.h" |
8 | 8 |
9 #include "GrDrawContext.h" | 9 #include "GrDrawContext.h" |
10 #include "GrDrawTarget.h" | 10 #include "GrDrawTarget.h" |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 return; | 143 return; |
144 } | 144 } |
145 | 145 |
146 if (cacheBlob) { | 146 if (cacheBlob) { |
147 if (cacheBlob->mustRegenerate(&transX, &transY, skPaint, grPaint.getColo
r(), blurRec, | 147 if (cacheBlob->mustRegenerate(&transX, &transY, skPaint, grPaint.getColo
r(), blurRec, |
148 viewMatrix, x, y)) { | 148 viewMatrix, x, y)) { |
149 // We have to remake the blob because changes may invalidate our mas
ks. | 149 // We have to remake the blob because changes may invalidate our mas
ks. |
150 // TODO we could probably get away reuse most of the time if the poi
nter is unique, | 150 // TODO we could probably get away reuse most of the time if the poi
nter is unique, |
151 // but we'd have to clear the subrun information | 151 // but we'd have to clear the subrun information |
152 fCache->remove(cacheBlob); | 152 fCache->remove(cacheBlob); |
153 cacheBlob.reset(SkRef(fCache->createCachedBlob(blob, key, blurRec, s
kPaint, | 153 cacheBlob.reset(SkRef(fCache->createCachedBlob(blob, key, blurRec, s
kPaint))); |
154 GrAtlasTextBlob::kGra
yTextVASize))); | |
155 this->regenerateTextBlob(cacheBlob, skPaint, grPaint.getColor(), vie
wMatrix, | 154 this->regenerateTextBlob(cacheBlob, skPaint, grPaint.getColor(), vie
wMatrix, |
156 blob, x, y, drawFilter); | 155 blob, x, y, drawFilter); |
157 } else { | 156 } else { |
158 fCache->makeMRU(cacheBlob); | 157 fCache->makeMRU(cacheBlob); |
159 | 158 |
160 if (CACHE_SANITY_CHECK) { | 159 if (CACHE_SANITY_CHECK) { |
161 int glyphCount = 0; | 160 int glyphCount = 0; |
162 int runCount = 0; | 161 int runCount = 0; |
163 GrTextBlobCache::BlobGlyphCount(&glyphCount, &runCount, blob); | 162 GrTextBlobCache::BlobGlyphCount(&glyphCount, &runCount, blob); |
164 SkAutoTUnref<GrAtlasTextBlob> sanityBlob( | 163 SkAutoTUnref<GrAtlasTextBlob> sanityBlob(fCache->createBlob(glyp
hCount, runCount)); |
165 fCache->createBlob(glyphCount, runCount, GrAtlasTextBlob::kG
rayTextVASize)); | 164 sanityBlob->setupKey(key, blurRec, skPaint); |
166 GrTextBlobCache::SetupCacheBlobKey(sanityBlob, key, blurRec, skP
aint); | |
167 this->regenerateTextBlob(sanityBlob, skPaint, grPaint.getColor()
, viewMatrix, | 165 this->regenerateTextBlob(sanityBlob, skPaint, grPaint.getColor()
, viewMatrix, |
168 blob, x, y, drawFilter); | 166 blob, x, y, drawFilter); |
169 GrAtlasTextBlob::AssertEqual(*sanityBlob, *cacheBlob); | 167 GrAtlasTextBlob::AssertEqual(*sanityBlob, *cacheBlob); |
170 } | 168 } |
171 } | 169 } |
172 } else { | 170 } else { |
173 if (canCache) { | 171 if (canCache) { |
174 cacheBlob.reset(SkRef(fCache->createCachedBlob(blob, key, blurRec, s
kPaint, | 172 cacheBlob.reset(SkRef(fCache->createCachedBlob(blob, key, blurRec, s
kPaint))); |
175 GrAtlasTextBlob::kGra
yTextVASize))); | |
176 } else { | 173 } else { |
177 cacheBlob.reset(fCache->createBlob(blob, GrAtlasTextBlob::kGrayTextV
ASize)); | 174 cacheBlob.reset(fCache->createBlob(blob)); |
178 } | 175 } |
179 this->regenerateTextBlob(cacheBlob, skPaint, grPaint.getColor(), viewMat
rix, | 176 this->regenerateTextBlob(cacheBlob, skPaint, grPaint.getColor(), viewMat
rix, |
180 blob, x, y, drawFilter); | 177 blob, x, y, drawFilter); |
181 } | 178 } |
182 | 179 |
183 cacheBlob->flushCached(fContext, dc, blob, fSurfaceProps, fDistanceAdjustTab
le, skPaint, | 180 cacheBlob->flushCached(fContext, dc, blob, fSurfaceProps, fDistanceAdjustTab
le, skPaint, |
184 grPaint, drawFilter, clip, viewMatrix, clipBounds, x,
y, transX, transY); | 181 grPaint, drawFilter, clip, viewMatrix, clipBounds, x,
y, transX, transY); |
185 } | 182 } |
186 | 183 |
187 void GrAtlasTextContext::regenerateTextBlob(GrAtlasTextBlob* cacheBlob, | 184 void GrAtlasTextContext::regenerateTextBlob(GrAtlasTextBlob* cacheBlob, |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 } | 268 } |
272 } | 269 } |
273 | 270 |
274 inline GrAtlasTextBlob* | 271 inline GrAtlasTextBlob* |
275 GrAtlasTextContext::createDrawTextBlob(const GrPaint& paint, const SkPaint& skPa
int, | 272 GrAtlasTextContext::createDrawTextBlob(const GrPaint& paint, const SkPaint& skPa
int, |
276 const SkMatrix& viewMatrix, | 273 const SkMatrix& viewMatrix, |
277 const char text[], size_t byteLength, | 274 const char text[], size_t byteLength, |
278 SkScalar x, SkScalar y) { | 275 SkScalar x, SkScalar y) { |
279 int glyphCount = skPaint.countText(text, byteLength); | 276 int glyphCount = skPaint.countText(text, byteLength); |
280 | 277 |
281 GrAtlasTextBlob* blob = fCache->createBlob(glyphCount, 1, GrAtlasTextBlob::k
GrayTextVASize); | 278 GrAtlasTextBlob* blob = fCache->createBlob(glyphCount, 1); |
282 blob->initThrowawayBlob(viewMatrix, x, y); | 279 blob->initThrowawayBlob(viewMatrix, x, y); |
283 | 280 |
284 if (GrTextUtils::CanDrawAsDistanceFields(skPaint, viewMatrix, fSurfaceProps, | 281 if (GrTextUtils::CanDrawAsDistanceFields(skPaint, viewMatrix, fSurfaceProps, |
285 *fContext->caps()->shaderCaps())) { | 282 *fContext->caps()->shaderCaps())) { |
286 GrTextUtils::DrawDFText(blob, 0, fContext->getBatchFontCache(), fSurface
Props, | 283 GrTextUtils::DrawDFText(blob, 0, fContext->getBatchFontCache(), fSurface
Props, |
287 skPaint, paint.getColor(), viewMatrix, text, | 284 skPaint, paint.getColor(), viewMatrix, text, |
288 byteLength, x, y); | 285 byteLength, x, y); |
289 } else { | 286 } else { |
290 GrTextUtils::DrawBmpText(blob, 0, fContext->getBatchFontCache(), fSurfac
eProps, skPaint, | 287 GrTextUtils::DrawBmpText(blob, 0, fContext->getBatchFontCache(), fSurfac
eProps, skPaint, |
291 paint.getColor(), viewMatrix, text, byteLength,
x, y); | 288 paint.getColor(), viewMatrix, text, byteLength,
x, y); |
292 } | 289 } |
293 return blob; | 290 return blob; |
294 } | 291 } |
295 | 292 |
296 inline GrAtlasTextBlob* | 293 inline GrAtlasTextBlob* |
297 GrAtlasTextContext::createDrawPosTextBlob(const GrPaint& paint, const SkPaint& s
kPaint, | 294 GrAtlasTextContext::createDrawPosTextBlob(const GrPaint& paint, const SkPaint& s
kPaint, |
298 const SkMatrix& viewMatrix, | 295 const SkMatrix& viewMatrix, |
299 const char text[], size_t byteLength, | 296 const char text[], size_t byteLength, |
300 const SkScalar pos[], int scalarsPerPo
sition, | 297 const SkScalar pos[], int scalarsPerPo
sition, |
301 const SkPoint& offset) { | 298 const SkPoint& offset) { |
302 int glyphCount = skPaint.countText(text, byteLength); | 299 int glyphCount = skPaint.countText(text, byteLength); |
303 | 300 |
304 GrAtlasTextBlob* blob = fCache->createBlob(glyphCount, 1, GrAtlasTextBlob::k
GrayTextVASize); | 301 GrAtlasTextBlob* blob = fCache->createBlob(glyphCount, 1); |
305 blob->initThrowawayBlob(viewMatrix, offset.x(), offset.y()); | 302 blob->initThrowawayBlob(viewMatrix, offset.x(), offset.y()); |
306 | 303 |
307 if (GrTextUtils::CanDrawAsDistanceFields(skPaint, viewMatrix, fSurfaceProps, | 304 if (GrTextUtils::CanDrawAsDistanceFields(skPaint, viewMatrix, fSurfaceProps, |
308 *fContext->caps()->shaderCaps())) { | 305 *fContext->caps()->shaderCaps())) { |
309 GrTextUtils::DrawDFPosText(blob, 0, fContext->getBatchFontCache(), fSurf
aceProps, | 306 GrTextUtils::DrawDFPosText(blob, 0, fContext->getBatchFontCache(), fSurf
aceProps, |
310 skPaint, paint.getColor(), viewMatrix, text, | 307 skPaint, paint.getColor(), viewMatrix, text, |
311 byteLength, pos, scalarsPerPosition, offset); | 308 byteLength, pos, scalarsPerPosition, offset); |
312 } else { | 309 } else { |
313 GrTextUtils::DrawBmpPosText(blob, 0, fContext->getBatchFontCache(), fSur
faceProps, skPaint, | 310 GrTextUtils::DrawBmpPosText(blob, 0, fContext->getBatchFontCache(), fSur
faceProps, skPaint, |
314 paint.getColor(), viewMatrix, text, | 311 paint.getColor(), viewMatrix, text, |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 // We'd like to be able to test this with random translations, but currently
the vertex | 391 // We'd like to be able to test this with random translations, but currently
the vertex |
395 // bounds and vertices will get out of sync | 392 // bounds and vertices will get out of sync |
396 SkScalar transX = 0.f;//SkIntToScalar(random->nextU()); | 393 SkScalar transX = 0.f;//SkIntToScalar(random->nextU()); |
397 SkScalar transY = 0.f;//SkIntToScalar(random->nextU()); | 394 SkScalar transY = 0.f;//SkIntToScalar(random->nextU()); |
398 return blob->test_createBatch(textLen, 0, 0, color, transX, transY, skPaint, | 395 return blob->test_createBatch(textLen, 0, 0, color, transX, transY, skPaint, |
399 gSurfaceProps, gTextContext->dfAdjustTable(), | 396 gSurfaceProps, gTextContext->dfAdjustTable(), |
400 context->getBatchFontCache()); | 397 context->getBatchFontCache()); |
401 } | 398 } |
402 | 399 |
403 #endif | 400 #endif |
OLD | NEW |