| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 #include "GrDistanceFieldTextContext.h" | 8 #include "GrDistanceFieldTextContext.h" |
| 9 #include "GrAtlas.h" | 9 #include "GrAtlas.h" |
| 10 #include "GrBitmapTextContext.h" | 10 #include "GrBitmapTextContext.h" |
| 11 #include "GrDrawTarget.h" | 11 #include "GrDrawTarget.h" |
| 12 #include "GrDrawTargetCaps.h" | 12 #include "GrDrawTargetCaps.h" |
| 13 #include "GrFontCache.h" |
| 13 #include "GrFontScaler.h" | 14 #include "GrFontScaler.h" |
| 14 #include "GrGpu.h" | 15 #include "GrGpu.h" |
| 15 #include "GrIndexBuffer.h" | 16 #include "GrIndexBuffer.h" |
| 16 #include "GrStrokeInfo.h" | 17 #include "GrStrokeInfo.h" |
| 17 #include "GrTexturePriv.h" | 18 #include "GrTexturePriv.h" |
| 18 #include "GrTextStrike.h" | |
| 19 #include "GrTextStrike_impl.h" | |
| 20 | 19 |
| 21 #include "SkAutoKern.h" | 20 #include "SkAutoKern.h" |
| 22 #include "SkColorFilter.h" | 21 #include "SkColorFilter.h" |
| 23 #include "SkDistanceFieldGen.h" | 22 #include "SkDistanceFieldGen.h" |
| 24 #include "SkDraw.h" | 23 #include "SkDraw.h" |
| 25 #include "SkGlyphCache.h" | 24 #include "SkGlyphCache.h" |
| 26 #include "SkGpuDevice.h" | 25 #include "SkGpuDevice.h" |
| 27 #include "SkPath.h" | 26 #include "SkPath.h" |
| 28 #include "SkRTConf.h" | 27 #include "SkRTConf.h" |
| 29 #include "SkStrokeRec.h" | 28 #include "SkStrokeRec.h" |
| (...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 428
params, flags)); | 427
params, flags)); |
| 429 #endif | 428 #endif |
| 430 } | 429 } |
| 431 fEffectTextureUniqueID = textureUniqueID; | 430 fEffectTextureUniqueID = textureUniqueID; |
| 432 fEffectColor = filteredColor; | 431 fEffectColor = filteredColor; |
| 433 fEffectFlags = flags; | 432 fEffectFlags = flags; |
| 434 } | 433 } |
| 435 | 434 |
| 436 } | 435 } |
| 437 | 436 |
| 437 inline bool GrDistanceFieldTextContext::uploadGlyph(GrGlyph* glyph, GrFontScaler
* scaler) { |
| 438 if (!fStrike->glyphTooLargeForAtlas(glyph)) { |
| 439 if (fStrike->addGlyphToAtlas(glyph, scaler)) { |
| 440 return true; |
| 441 } |
| 442 |
| 443 // try to clear out an unused plot before we flush |
| 444 if (fContext->getFontCache()->freeUnusedPlot(fStrike, glyph) && |
| 445 fStrike->addGlyphToAtlas(glyph, scaler)) { |
| 446 return true; |
| 447 } |
| 448 |
| 449 if (c_DumpFontCache) { |
| 450 #ifdef SK_DEVELOPER |
| 451 fContext->getFontCache()->dump(); |
| 452 #endif |
| 453 } |
| 454 |
| 455 // before we purge the cache, we must flush any accumulated draws |
| 456 this->flush(); |
| 457 fContext->flush(); |
| 458 |
| 459 // we should have an unused plot now |
| 460 if (fContext->getFontCache()->freeUnusedPlot(fStrike, glyph) && |
| 461 fStrike->addGlyphToAtlas(glyph, scaler)) { |
| 462 return true; |
| 463 } |
| 464 |
| 465 // we should never get here |
| 466 SkASSERT(false); |
| 467 } |
| 468 |
| 469 return false; |
| 470 } |
| 471 |
| 472 |
| 438 // Returns true if this method handled the glyph, false if needs to be passed to
fallback | 473 // Returns true if this method handled the glyph, false if needs to be passed to
fallback |
| 439 // | 474 // |
| 440 bool GrDistanceFieldTextContext::appendGlyph(GrGlyph::PackedID packed, | 475 bool GrDistanceFieldTextContext::appendGlyph(GrGlyph::PackedID packed, |
| 441 SkScalar sx, SkScalar sy, | 476 SkScalar sx, SkScalar sy, |
| 442 GrFontScaler* scaler) { | 477 GrFontScaler* scaler) { |
| 443 if (NULL == fDrawTarget) { | 478 if (NULL == fDrawTarget) { |
| 444 return true; | 479 return true; |
| 445 } | 480 } |
| 446 | 481 |
| 447 if (NULL == fStrike) { | 482 if (NULL == fStrike) { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 477 const SkMatrix& ctm = fContext->getMatrix(); | 512 const SkMatrix& ctm = fContext->getMatrix(); |
| 478 (void) ctm.mapRect(&dstRect, glyphRect); | 513 (void) ctm.mapRect(&dstRect, glyphRect); |
| 479 if (fClipRect.quickReject(SkScalarTruncToInt(dstRect.left()), | 514 if (fClipRect.quickReject(SkScalarTruncToInt(dstRect.left()), |
| 480 SkScalarTruncToInt(dstRect.top()), | 515 SkScalarTruncToInt(dstRect.top()), |
| 481 SkScalarTruncToInt(dstRect.right()), | 516 SkScalarTruncToInt(dstRect.right()), |
| 482 SkScalarTruncToInt(dstRect.bottom()))) { | 517 SkScalarTruncToInt(dstRect.bottom()))) { |
| 483 // SkCLZ(3); // so we can set a break-point in the debugger | 518 // SkCLZ(3); // so we can set a break-point in the debugger |
| 484 return true; | 519 return true; |
| 485 } | 520 } |
| 486 | 521 |
| 487 if (NULL == glyph->fPlot) { | 522 if (NULL == glyph->fPlot && !uploadGlyph(glyph, scaler)) { |
| 488 if (!fStrike->glyphTooLargeForAtlas(glyph)) { | |
| 489 if (fStrike->addGlyphToAtlas(glyph, scaler)) { | |
| 490 goto HAS_ATLAS; | |
| 491 } | |
| 492 | |
| 493 // try to clear out an unused plot before we flush | |
| 494 if (fContext->getFontCache()->freeUnusedPlot(fStrike, glyph) && | |
| 495 fStrike->addGlyphToAtlas(glyph, scaler)) { | |
| 496 goto HAS_ATLAS; | |
| 497 } | |
| 498 | |
| 499 if (c_DumpFontCache) { | |
| 500 #ifdef SK_DEVELOPER | |
| 501 fContext->getFontCache()->dump(); | |
| 502 #endif | |
| 503 } | |
| 504 | |
| 505 // before we purge the cache, we must flush any accumulated draws | |
| 506 this->flush(); | |
| 507 fContext->flush(); | |
| 508 | |
| 509 // we should have an unused plot now | |
| 510 if (fContext->getFontCache()->freeUnusedPlot(fStrike, glyph) && | |
| 511 fStrike->addGlyphToAtlas(glyph, scaler)) { | |
| 512 goto HAS_ATLAS; | |
| 513 } | |
| 514 } | |
| 515 | |
| 516 if (NULL == glyph->fPath) { | 523 if (NULL == glyph->fPath) { |
| 517 SkPath* path = SkNEW(SkPath); | 524 SkPath* path = SkNEW(SkPath); |
| 518 if (!scaler->getGlyphPath(glyph->glyphID(), path)) { | 525 if (!scaler->getGlyphPath(glyph->glyphID(), path)) { |
| 519 // flag the glyph as being dead? | 526 // flag the glyph as being dead? |
| 520 delete path; | 527 delete path; |
| 521 return true; | 528 return true; |
| 522 } | 529 } |
| 523 glyph->fPath = path; | 530 glyph->fPath = path; |
| 524 } | 531 } |
| 525 | 532 |
| 526 // flush any accumulated draws before drawing this glyph as a path. | 533 // flush any accumulated draws before drawing this glyph as a path. |
| 527 this->flush(); | 534 this->flush(); |
| 528 | 535 |
| 529 GrContext::AutoMatrix am; | 536 GrContext::AutoMatrix am; |
| 530 SkMatrix ctm; | 537 SkMatrix ctm; |
| 531 ctm.setScale(fTextRatio, fTextRatio); | 538 ctm.setScale(fTextRatio, fTextRatio); |
| 532 ctm.postTranslate(sx - dx, sy - dy); | 539 ctm.postTranslate(sx - dx, sy - dy); |
| 533 GrPaint tmpPaint(fPaint); | 540 GrPaint tmpPaint(fPaint); |
| 534 am.setPreConcat(fContext, ctm, &tmpPaint); | 541 am.setPreConcat(fContext, ctm, &tmpPaint); |
| 535 GrStrokeInfo strokeInfo(SkStrokeRec::kFill_InitStyle); | 542 GrStrokeInfo strokeInfo(SkStrokeRec::kFill_InitStyle); |
| 536 fContext->drawPath(tmpPaint, *glyph->fPath, strokeInfo); | 543 fContext->drawPath(tmpPaint, *glyph->fPath, strokeInfo); |
| 537 | 544 |
| 538 // remove this glyph from the vertices we need to allocate | 545 // remove this glyph from the vertices we need to allocate |
| 539 fTotalVertexCount -= kVerticesPerGlyph; | 546 fTotalVertexCount -= kVerticesPerGlyph; |
| 540 return true; | 547 return true; |
| 541 } | 548 } |
| 542 | 549 |
| 543 HAS_ATLAS: | |
| 544 SkASSERT(glyph->fPlot); | 550 SkASSERT(glyph->fPlot); |
| 545 GrDrawTarget::DrawToken drawToken = fDrawTarget->getCurrentDrawToken(); | 551 GrDrawTarget::DrawToken drawToken = fDrawTarget->getCurrentDrawToken(); |
| 546 glyph->fPlot->setDrawToken(drawToken); | 552 glyph->fPlot->setDrawToken(drawToken); |
| 547 | 553 |
| 548 GrTexture* texture = glyph->fPlot->texture(); | 554 GrTexture* texture = glyph->fPlot->texture(); |
| 549 SkASSERT(texture); | 555 SkASSERT(texture); |
| 550 | 556 |
| 551 if (fCurrTexture != texture || fCurrVertex + kVerticesPerGlyph > fTotalVerte
xCount) { | 557 if (fCurrTexture != texture || fCurrVertex + kVerticesPerGlyph > fTotalVerte
xCount) { |
| 552 this->flush(); | 558 this->flush(); |
| 553 fCurrTexture = texture; | 559 fCurrTexture = texture; |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 672 } | 678 } |
| 673 } | 679 } |
| 674 | 680 |
| 675 inline void GrDistanceFieldTextContext::finish() { | 681 inline void GrDistanceFieldTextContext::finish() { |
| 676 this->flush(); | 682 this->flush(); |
| 677 fTotalVertexCount = 0; | 683 fTotalVertexCount = 0; |
| 678 | 684 |
| 679 GrTextContext::finish(); | 685 GrTextContext::finish(); |
| 680 } | 686 } |
| 681 | 687 |
| OLD | NEW |