| 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 "GrBitmapTextContext.h" | 8 #include "GrBitmapTextContext.h" | 
| 9 #include "GrAtlas.h" | 9 #include "GrAtlas.h" | 
| 10 #include "GrDrawTarget.h" | 10 #include "GrDrawTarget.h" | 
| (...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 363         } | 363         } | 
| 364     } | 364     } | 
| 365 | 365 | 
| 366     if (NULL == glyph->fPlot) { | 366     if (NULL == glyph->fPlot) { | 
| 367         if (!fStrike->glyphTooLargeForAtlas(glyph)) { | 367         if (!fStrike->glyphTooLargeForAtlas(glyph)) { | 
| 368             if (fStrike->addGlyphToAtlas(glyph, scaler)) { | 368             if (fStrike->addGlyphToAtlas(glyph, scaler)) { | 
| 369                 goto HAS_ATLAS; | 369                 goto HAS_ATLAS; | 
| 370             } | 370             } | 
| 371 | 371 | 
| 372             // try to clear out an unused plot before we flush | 372             // try to clear out an unused plot before we flush | 
| 373             if (fContext->getFontCache()->freeUnusedPlot(fStrike) && | 373             if (fContext->getFontCache()->freeUnusedPlot(fStrike, glyph) && | 
| 374                 fStrike->addGlyphToAtlas(glyph, scaler)) { | 374                 fStrike->addGlyphToAtlas(glyph, scaler)) { | 
| 375                 goto HAS_ATLAS; | 375                 goto HAS_ATLAS; | 
| 376             } | 376             } | 
| 377 | 377 | 
| 378             if (c_DumpFontCache) { | 378             if (c_DumpFontCache) { | 
| 379 #ifdef SK_DEVELOPER | 379 #ifdef SK_DEVELOPER | 
| 380                 fContext->getFontCache()->dump(); | 380                 fContext->getFontCache()->dump(); | 
| 381 #endif | 381 #endif | 
| 382             } | 382             } | 
| 383 | 383 | 
| 384             // flush any accumulated draws to allow us to free up a plot | 384             // flush any accumulated draws to allow us to free up a plot | 
| 385             this->flush(); | 385             this->flush(); | 
| 386             fContext->flush(); | 386             fContext->flush(); | 
| 387 | 387 | 
| 388             // we should have an unused plot now | 388             // we should have an unused plot now | 
| 389             if (fContext->getFontCache()->freeUnusedPlot(fStrike) && | 389             if (fContext->getFontCache()->freeUnusedPlot(fStrike, glyph) && | 
| 390                 fStrike->addGlyphToAtlas(glyph, scaler)) { | 390                 fStrike->addGlyphToAtlas(glyph, scaler)) { | 
| 391                 goto HAS_ATLAS; | 391                 goto HAS_ATLAS; | 
| 392             } | 392             } | 
| 393         } | 393         } | 
| 394 | 394 | 
| 395         if (NULL == glyph->fPath) { | 395         if (NULL == glyph->fPath) { | 
| 396             SkPath* path = SkNEW(SkPath); | 396             SkPath* path = SkNEW(SkPath); | 
| 397             if (!scaler->getGlyphPath(glyph->glyphID(), path)) { | 397             if (!scaler->getGlyphPath(glyph->glyphID(), path)) { | 
| 398                 // flag the glyph as being dead? | 398                 // flag the glyph as being dead? | 
| 399                 delete path; | 399                 delete path; | 
| (...skipping 15 matching lines...) Expand all  Loading... | 
| 415 | 415 | 
| 416 HAS_ATLAS: | 416 HAS_ATLAS: | 
| 417     SkASSERT(glyph->fPlot); | 417     SkASSERT(glyph->fPlot); | 
| 418     GrDrawTarget::DrawToken drawToken = fDrawTarget->getCurrentDrawToken(); | 418     GrDrawTarget::DrawToken drawToken = fDrawTarget->getCurrentDrawToken(); | 
| 419     glyph->fPlot->setDrawToken(drawToken); | 419     glyph->fPlot->setDrawToken(drawToken); | 
| 420 | 420 | 
| 421     // now promote them to fixed (TODO: Rethink using fixed pt). | 421     // now promote them to fixed (TODO: Rethink using fixed pt). | 
| 422     width = SkIntToFixed(width); | 422     width = SkIntToFixed(width); | 
| 423     height = SkIntToFixed(height); | 423     height = SkIntToFixed(height); | 
| 424 | 424 | 
|  | 425     // the current texture/maskformat must match what the glyph needs | 
| 425     GrTexture* texture = glyph->fPlot->texture(); | 426     GrTexture* texture = glyph->fPlot->texture(); | 
| 426     SkASSERT(texture); | 427     SkASSERT(texture); | 
| 427 | 428 | 
| 428     if (fCurrTexture != texture || fCurrVertex + 4 > fMaxVertices) { | 429     if (fCurrTexture != texture || fCurrVertex + 4 > fMaxVertices) { | 
| 429         this->flush(); | 430         this->flush(); | 
| 430         fCurrTexture = texture; | 431         fCurrTexture = texture; | 
| 431         fCurrTexture->ref(); | 432         fCurrTexture->ref(); | 
|  | 433         fCurrMaskFormat = glyph->fMaskFormat; | 
| 432     } | 434     } | 
| 433 | 435 | 
| 434     bool useColorVerts = kA8_GrMaskFormat == fStrike->getMaskFormat(); | 436     bool useColorVerts = kA8_GrMaskFormat == fCurrMaskFormat; | 
| 435 | 437 | 
| 436     if (NULL == fVertices) { | 438     if (NULL == fVertices) { | 
| 437        // If we need to reserve vertices allow the draw target to suggest | 439        // If we need to reserve vertices allow the draw target to suggest | 
| 438         // a number of verts to reserve and whether to perform a flush. | 440         // a number of verts to reserve and whether to perform a flush. | 
| 439         fMaxVertices = kMinRequestedVerts; | 441         fMaxVertices = kMinRequestedVerts; | 
| 440         if (useColorVerts) { | 442         if (useColorVerts) { | 
| 441             fDrawTarget->drawState()->setVertexAttribs<gTextVertexWithColorAttri
     bs>( | 443             fDrawTarget->drawState()->setVertexAttribs<gTextVertexWithColorAttri
     bs>( | 
| 442                 SK_ARRAY_COUNT(gTextVertexWithColorAttribs), kTextVAColorSize); | 444                 SK_ARRAY_COUNT(gTextVertexWithColorAttribs), kTextVAColorSize); | 
| 443         } else { | 445         } else { | 
| 444             fDrawTarget->drawState()->setVertexAttribs<gTextVertexAttribs>( | 446             fDrawTarget->drawState()->setVertexAttribs<gTextVertexAttribs>( | 
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 542 | 544 | 
| 543         if (textureUniqueID != fEffectTextureUniqueID) { | 545         if (textureUniqueID != fEffectTextureUniqueID) { | 
| 544             fCachedGeometryProcessor.reset(GrCustomCoordsTextureEffect::Create(f
     CurrTexture, | 546             fCachedGeometryProcessor.reset(GrCustomCoordsTextureEffect::Create(f
     CurrTexture, | 
| 545                                                                                p
     arams)); | 547                                                                                p
     arams)); | 
| 546             fEffectTextureUniqueID = textureUniqueID; | 548             fEffectTextureUniqueID = textureUniqueID; | 
| 547         } | 549         } | 
| 548 | 550 | 
| 549         // This effect could be stored with one of the cache objects (atlas?) | 551         // This effect could be stored with one of the cache objects (atlas?) | 
| 550         drawState->setGeometryProcessor(fCachedGeometryProcessor.get()); | 552         drawState->setGeometryProcessor(fCachedGeometryProcessor.get()); | 
| 551         SkASSERT(fStrike); | 553         SkASSERT(fStrike); | 
| 552         switch (fStrike->getMaskFormat()) { | 554         switch (fCurrMaskFormat) { | 
| 553                 // Color bitmap text | 555                 // Color bitmap text | 
| 554             case kARGB_GrMaskFormat: | 556             case kARGB_GrMaskFormat: | 
| 555                 SkASSERT(!drawState->hasColorVertexAttribute()); | 557                 SkASSERT(!drawState->hasColorVertexAttribute()); | 
| 556                 drawState->setBlendFunc(fPaint.getSrcBlendCoeff(), fPaint.getDst
     BlendCoeff()); | 558                 drawState->setBlendFunc(fPaint.getSrcBlendCoeff(), fPaint.getDst
     BlendCoeff()); | 
| 557                 drawState->setColor(0xffffffff); | 559                 drawState->setAlpha(fSkPaint.getAlpha()); | 
| 558                 break; | 560                 break; | 
| 559                 // LCD text | 561                 // LCD text | 
| 560             case kA888_GrMaskFormat: | 562             case kA888_GrMaskFormat: | 
| 561             case kA565_GrMaskFormat: { | 563             case kA565_GrMaskFormat: { | 
| 562                 if (kOne_GrBlendCoeff != fPaint.getSrcBlendCoeff() || | 564                 if (kOne_GrBlendCoeff != fPaint.getSrcBlendCoeff() || | 
| 563                     kISA_GrBlendCoeff != fPaint.getDstBlendCoeff() || | 565                     kISA_GrBlendCoeff != fPaint.getDstBlendCoeff() || | 
| 564                     fPaint.numColorStages()) { | 566                     fPaint.numColorStages()) { | 
| 565                     GrPrintf("LCD Text will not draw correctly.\n"); | 567                     GrPrintf("LCD Text will not draw correctly.\n"); | 
| 566                 } | 568                 } | 
| 567                 SkASSERT(!drawState->hasColorVertexAttribute()); | 569                 SkASSERT(!drawState->hasColorVertexAttribute()); | 
| (...skipping 10 matching lines...) Expand all  Loading... | 
| 578                 break; | 580                 break; | 
| 579             } | 581             } | 
| 580                 // Grayscale/BW text | 582                 // Grayscale/BW text | 
| 581             case kA8_GrMaskFormat: | 583             case kA8_GrMaskFormat: | 
| 582                 // set back to normal in case we took LCD path previously. | 584                 // set back to normal in case we took LCD path previously. | 
| 583                 drawState->setBlendFunc(fPaint.getSrcBlendCoeff(), fPaint.getDst
     BlendCoeff()); | 585                 drawState->setBlendFunc(fPaint.getSrcBlendCoeff(), fPaint.getDst
     BlendCoeff()); | 
| 584                 // We're using per-vertex color. | 586                 // We're using per-vertex color. | 
| 585                 SkASSERT(drawState->hasColorVertexAttribute()); | 587                 SkASSERT(drawState->hasColorVertexAttribute()); | 
| 586                 break; | 588                 break; | 
| 587             default: | 589             default: | 
| 588                 SkFAIL("Unexepected mask format."); | 590                 SkFAIL("Unexpected mask format."); | 
| 589         } | 591         } | 
| 590         int nGlyphs = fCurrVertex / 4; | 592         int nGlyphs = fCurrVertex / 4; | 
| 591         fDrawTarget->setIndexSourceToBuffer(fContext->getQuadIndexBuffer()); | 593         fDrawTarget->setIndexSourceToBuffer(fContext->getQuadIndexBuffer()); | 
| 592         fDrawTarget->drawIndexedInstances(kTriangles_GrPrimitiveType, | 594         fDrawTarget->drawIndexedInstances(kTriangles_GrPrimitiveType, | 
| 593                                           nGlyphs, | 595                                           nGlyphs, | 
| 594                                           4, 6, &fVertexBounds); | 596                                           4, 6, &fVertexBounds); | 
| 595 | 597 | 
| 596         fDrawTarget->resetVertexSource(); | 598         fDrawTarget->resetVertexSource(); | 
| 597         fVertices = NULL; | 599         fVertices = NULL; | 
| 598         fMaxVertices = 0; | 600         fMaxVertices = 0; | 
| 599         fCurrVertex = 0; | 601         fCurrVertex = 0; | 
| 600         fVertexBounds.setLargestInverted(); | 602         fVertexBounds.setLargestInverted(); | 
| 601         SkSafeSetNull(fCurrTexture); | 603         SkSafeSetNull(fCurrTexture); | 
| 602     } | 604     } | 
| 603 } | 605 } | 
| 604 | 606 | 
| 605 inline void GrBitmapTextContext::finish() { | 607 inline void GrBitmapTextContext::finish() { | 
| 606     this->flush(); | 608     this->flush(); | 
| 607 | 609 | 
| 608     GrTextContext::finish(); | 610     GrTextContext::finish(); | 
| 609 } | 611 } | 
| 610 | 612 | 
| OLD | NEW | 
|---|