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 "GrBatch.h" | 9 #include "GrBatch.h" |
10 #include "GrBatchFontCache.h" | 10 #include "GrBatchFontCache.h" |
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 // TODO we could probably get away reuse most of the time if the poi
nter is unique, | 403 // TODO we could probably get away reuse most of the time if the poi
nter is unique, |
404 // but we'd have to clear the subrun information | 404 // but we'd have to clear the subrun information |
405 fCache->remove(cacheBlob); | 405 fCache->remove(cacheBlob); |
406 cacheBlob.reset(SkRef(fCache->createCachedBlob(blob, key, blurRec, s
kPaint, | 406 cacheBlob.reset(SkRef(fCache->createCachedBlob(blob, key, blurRec, s
kPaint, |
407 kGrayTextVASize))); | 407 kGrayTextVASize))); |
408 this->regenerateTextBlob(cacheBlob, skPaint, grPaint.getColor(), vie
wMatrix, | 408 this->regenerateTextBlob(cacheBlob, skPaint, grPaint.getColor(), vie
wMatrix, |
409 blob, x, y, drawFilter, clipRect, rt, clip,
grPaint); | 409 blob, x, y, drawFilter, clipRect, rt, clip,
grPaint); |
410 } else { | 410 } else { |
411 // If we can reuse the blob, then make sure we update the blob's vie
wmatrix, and x/y | 411 // If we can reuse the blob, then make sure we update the blob's vie
wmatrix, and x/y |
412 // offsets | 412 // offsets |
| 413 // TODO bounds are wrong |
413 cacheBlob->fViewMatrix = viewMatrix; | 414 cacheBlob->fViewMatrix = viewMatrix; |
414 cacheBlob->fX = x; | 415 cacheBlob->fX = x; |
415 cacheBlob->fY = y; | 416 cacheBlob->fY = y; |
416 fCache->makeMRU(cacheBlob); | 417 fCache->makeMRU(cacheBlob); |
| 418 #ifdef CACHE_SANITY_CHECK |
| 419 { |
| 420 int glyphCount = 0; |
| 421 int runCount = 0; |
| 422 GrTextBlobCache::BlobGlyphCount(&glyphCount, &runCount, blob); |
| 423 SkAutoTUnref<GrAtlasTextBlob> sanityBlob(fCache->createBlob(glyp
hCount, runCount, |
| 424 kGra
yTextVASize)); |
| 425 GrTextBlobCache::SetupCacheBlobKey(sanityBlob, key, blurRec, skP
aint); |
| 426 this->regenerateTextBlob(sanityBlob, skPaint, grPaint.getColor()
, viewMatrix, |
| 427 blob, x, y, drawFilter, clipRect, rt, c
lip, grPaint); |
| 428 GrAtlasTextBlob::AssertEqual(*sanityBlob, *cacheBlob); |
| 429 } |
| 430 |
| 431 #endif |
417 } | 432 } |
418 } else { | 433 } else { |
419 if (canCache) { | 434 if (canCache) { |
420 cacheBlob.reset(SkRef(fCache->createCachedBlob(blob, key, blurRec, s
kPaint, | 435 cacheBlob.reset(SkRef(fCache->createCachedBlob(blob, key, blurRec, s
kPaint, |
421 kGrayTextVASize))); | 436 kGrayTextVASize))); |
422 } else { | 437 } else { |
423 cacheBlob.reset(fCache->createBlob(blob, kGrayTextVASize)); | 438 cacheBlob.reset(fCache->createBlob(blob, kGrayTextVASize)); |
424 } | 439 } |
425 this->regenerateTextBlob(cacheBlob, skPaint, grPaint.getColor(), viewMat
rix, | 440 this->regenerateTextBlob(cacheBlob, skPaint, grPaint.getColor(), viewMat
rix, |
426 blob, x, y, drawFilter, clipRect, rt, clip, grP
aint); | 441 blob, x, y, drawFilter, clipRect, rt, clip, grP
aint); |
427 } | 442 } |
428 | 443 |
429 cacheBlob->fPaintColor = skPaint.getColor(); | |
430 this->flush(blob, cacheBlob, rt, skPaint, grPaint, drawFilter, | 444 this->flush(blob, cacheBlob, rt, skPaint, grPaint, drawFilter, |
431 clip, viewMatrix, clipBounds, x, y, transX, transY); | 445 clip, viewMatrix, clipBounds, x, y, transX, transY); |
432 } | 446 } |
433 | 447 |
434 inline bool GrAtlasTextContext::canDrawAsDistanceFields(const SkPaint& skPaint, | 448 inline bool GrAtlasTextContext::canDrawAsDistanceFields(const SkPaint& skPaint, |
435 const SkMatrix& viewMatr
ix) { | 449 const SkMatrix& viewMatr
ix) { |
436 // TODO: support perspective (need getMaxScale replacement) | 450 // TODO: support perspective (need getMaxScale replacement) |
437 if (viewMatrix.hasPerspective()) { | 451 if (viewMatrix.hasPerspective()) { |
438 return false; | 452 return false; |
439 } | 453 } |
(...skipping 30 matching lines...) Expand all Loading... |
470 return true; | 484 return true; |
471 } | 485 } |
472 | 486 |
473 void GrAtlasTextContext::regenerateTextBlob(GrAtlasTextBlob* cacheBlob, | 487 void GrAtlasTextContext::regenerateTextBlob(GrAtlasTextBlob* cacheBlob, |
474 const SkPaint& skPaint, GrColor colo
r, | 488 const SkPaint& skPaint, GrColor colo
r, |
475 const SkMatrix& viewMatrix, | 489 const SkMatrix& viewMatrix, |
476 const SkTextBlob* blob, SkScalar x,
SkScalar y, | 490 const SkTextBlob* blob, SkScalar x,
SkScalar y, |
477 SkDrawFilter* drawFilter, const SkIR
ect& clipRect, | 491 SkDrawFilter* drawFilter, const SkIR
ect& clipRect, |
478 GrRenderTarget* rt, const GrClip& cl
ip, | 492 GrRenderTarget* rt, const GrClip& cl
ip, |
479 const GrPaint& paint) { | 493 const GrPaint& paint) { |
| 494 cacheBlob->fPaintColor = skPaint.getColor(); |
480 cacheBlob->fViewMatrix = viewMatrix; | 495 cacheBlob->fViewMatrix = viewMatrix; |
481 cacheBlob->fX = x; | 496 cacheBlob->fX = x; |
482 cacheBlob->fY = y; | 497 cacheBlob->fY = y; |
483 | 498 |
484 // Regenerate textblob | 499 // Regenerate textblob |
485 SkPaint runPaint = skPaint; | 500 SkPaint runPaint = skPaint; |
486 SkTextBlob::RunIterator it(blob); | 501 SkTextBlob::RunIterator it(blob); |
487 for (int run = 0; !it.done(); it.next(), run++) { | 502 for (int run = 0; !it.done(); it.next(), run++) { |
488 int glyphCount = it.glyphCount(); | 503 int glyphCount = it.glyphCount(); |
489 size_t textLen = glyphCount * sizeof(uint16_t); | 504 size_t textLen = glyphCount * sizeof(uint16_t); |
(...skipping 1779 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2269 gTextContext->createDrawTextBlob(rt, clip, grPaint, skPaint, viewMat
rix, text, | 2284 gTextContext->createDrawTextBlob(rt, clip, grPaint, skPaint, viewMat
rix, text, |
2270 static_cast<size_t>(textLen), 0, 0,
noClip)); | 2285 static_cast<size_t>(textLen), 0, 0,
noClip)); |
2271 | 2286 |
2272 SkScalar transX = static_cast<SkScalar>(random->nextU()); | 2287 SkScalar transX = static_cast<SkScalar>(random->nextU()); |
2273 SkScalar transY = static_cast<SkScalar>(random->nextU()); | 2288 SkScalar transY = static_cast<SkScalar>(random->nextU()); |
2274 const GrAtlasTextBlob::Run::SubRunInfo& info = blob->fRuns[0].fSubRunInfo[0]
; | 2289 const GrAtlasTextBlob::Run::SubRunInfo& info = blob->fRuns[0].fSubRunInfo[0]
; |
2275 return gTextContext->createBatch(blob, info, textLen, 0, 0, color, transX, t
ransY, skPaint); | 2290 return gTextContext->createBatch(blob, info, textLen, 0, 0, color, transX, t
ransY, skPaint); |
2276 } | 2291 } |
2277 | 2292 |
2278 #endif | 2293 #endif |
OLD | NEW |