| 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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 if (NULL == fDrawTarget) { | 62 if (NULL == fDrawTarget) { |
| 63 return; | 63 return; |
| 64 } | 64 } |
| 65 | 65 |
| 66 GrDrawState* drawState = fDrawTarget->drawState(); | 66 GrDrawState* drawState = fDrawTarget->drawState(); |
| 67 GrDrawState::AutoRestoreEffects are(drawState); | 67 GrDrawState::AutoRestoreEffects are(drawState); |
| 68 drawState->setFromPaint(fPaint, SkMatrix::I(), fContext->getRenderTarget()); | 68 drawState->setFromPaint(fPaint, SkMatrix::I(), fContext->getRenderTarget()); |
| 69 | 69 |
| 70 if (fCurrVertex > 0) { | 70 if (fCurrVertex > 0) { |
| 71 // setup our sampler state for our text texture/atlas | 71 // setup our sampler state for our text texture/atlas |
| 72 SkASSERT(GrIsALIGN4(fCurrVertex)); | 72 SkASSERT(SkIsAlign4(fCurrVertex)); |
| 73 SkASSERT(fCurrTexture); | 73 SkASSERT(fCurrTexture); |
| 74 GrTextureParams params(SkShader::kRepeat_TileMode, GrTextureParams::kNon
e_FilterMode); | 74 GrTextureParams params(SkShader::kRepeat_TileMode, GrTextureParams::kNon
e_FilterMode); |
| 75 | 75 |
| 76 // This effect could be stored with one of the cache objects (atlas?) | 76 // This effect could be stored with one of the cache objects (atlas?) |
| 77 drawState->addCoverageEffect( | 77 drawState->addCoverageEffect( |
| 78 GrCustomCoordsTextureEffect::Create(fCurrTexture
, params), | 78 GrCustomCoordsTextureEffect::Create(fCurrTexture
, params), |
| 79 kGlyphCoordsAttributeIndex)->unref(); | 79 kGlyphCoordsAttributeIndex)->unref(); |
| 80 | 80 |
| 81 if (NULL != fStrike && kARGB_GrMaskFormat == fStrike->getMaskFormat()) { | 81 if (NULL != fStrike && kARGB_GrMaskFormat == fStrike->getMaskFormat()) { |
| 82 drawState->setBlendFunc(fPaint.getSrcBlendCoeff(), fPaint.getDstBlen
dCoeff()); | 82 drawState->setBlendFunc(fPaint.getSrcBlendCoeff(), fPaint.getDstBlen
dCoeff()); |
| (...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 468 } | 468 } |
| 469 | 469 |
| 470 this->finish(); | 470 this->finish(); |
| 471 } | 471 } |
| 472 | 472 |
| 473 namespace { | 473 namespace { |
| 474 | 474 |
| 475 // position + texture coord | 475 // position + texture coord |
| 476 extern const GrVertexAttrib gTextVertexAttribs[] = { | 476 extern const GrVertexAttrib gTextVertexAttribs[] = { |
| 477 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding
}, | 477 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding
}, |
| 478 {kVec2f_GrVertexAttribType, sizeof(GrPoint), kEffect_GrVertexAttribBinding} | 478 {kVec2f_GrVertexAttribType, sizeof(SkPoint), kEffect_GrVertexAttribBinding} |
| 479 }; | 479 }; |
| 480 | 480 |
| 481 }; | 481 }; |
| 482 | 482 |
| 483 void GrBitmapTextContext::drawPackedGlyph(GrGlyph::PackedID packed, | 483 void GrBitmapTextContext::drawPackedGlyph(GrGlyph::PackedID packed, |
| 484 GrFixed vx, GrFixed vy, | 484 SkFixed vx, SkFixed vy, |
| 485 GrFontScaler* scaler) { | 485 GrFontScaler* scaler) { |
| 486 if (NULL == fDrawTarget) { | 486 if (NULL == fDrawTarget) { |
| 487 return; | 487 return; |
| 488 } | 488 } |
| 489 | 489 |
| 490 if (NULL == fStrike) { | 490 if (NULL == fStrike) { |
| 491 fStrike = fContext->getFontCache()->getStrike(scaler, false); | 491 fStrike = fContext->getFontCache()->getStrike(scaler, false); |
| 492 } | 492 } |
| 493 | 493 |
| 494 GrGlyph* glyph = fStrike->getGlyph(packed, scaler); | 494 GrGlyph* glyph = fStrike->getGlyph(packed, scaler); |
| 495 if (NULL == glyph || glyph->fBounds.isEmpty()) { | 495 if (NULL == glyph || glyph->fBounds.isEmpty()) { |
| 496 return; | 496 return; |
| 497 } | 497 } |
| 498 | 498 |
| 499 vx += SkIntToFixed(glyph->fBounds.fLeft); | 499 vx += SkIntToFixed(glyph->fBounds.fLeft); |
| 500 vy += SkIntToFixed(glyph->fBounds.fTop); | 500 vy += SkIntToFixed(glyph->fBounds.fTop); |
| 501 | 501 |
| 502 // keep them as ints until we've done the clip-test | 502 // keep them as ints until we've done the clip-test |
| 503 GrFixed width = glyph->fBounds.width(); | 503 SkFixed width = glyph->fBounds.width(); |
| 504 GrFixed height = glyph->fBounds.height(); | 504 SkFixed height = glyph->fBounds.height(); |
| 505 | 505 |
| 506 // check if we clipped out | 506 // check if we clipped out |
| 507 if (true || NULL == glyph->fPlot) { | 507 if (true || NULL == glyph->fPlot) { |
| 508 int x = vx >> 16; | 508 int x = vx >> 16; |
| 509 int y = vy >> 16; | 509 int y = vy >> 16; |
| 510 if (fClipRect.quickReject(x, y, x + width, y + height)) { | 510 if (fClipRect.quickReject(x, y, x + width, y + height)) { |
| 511 // SkCLZ(3); // so we can set a break-point in the debugger | 511 // SkCLZ(3); // so we can set a break-point in the debugger |
| 512 return; | 512 return; |
| 513 } | 513 } |
| 514 } | 514 } |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 601 fMaxVertices = kDefaultRequestedVerts; | 601 fMaxVertices = kDefaultRequestedVerts; |
| 602 } else if (fMaxVertices > maxQuadVertices) { | 602 } else if (fMaxVertices > maxQuadVertices) { |
| 603 // don't exceed the limit of the index buffer | 603 // don't exceed the limit of the index buffer |
| 604 fMaxVertices = maxQuadVertices; | 604 fMaxVertices = maxQuadVertices; |
| 605 } | 605 } |
| 606 bool success = fDrawTarget->reserveVertexAndIndexSpace(fMaxVertices, | 606 bool success = fDrawTarget->reserveVertexAndIndexSpace(fMaxVertices, |
| 607 0, | 607 0, |
| 608 GrTCast<void**>(&
fVertices), | 608 GrTCast<void**>(&
fVertices), |
| 609 NULL); | 609 NULL); |
| 610 GrAlwaysAssert(success); | 610 GrAlwaysAssert(success); |
| 611 SkASSERT(2*sizeof(GrPoint) == fDrawTarget->getDrawState().getVertexSize(
)); | 611 SkASSERT(2*sizeof(SkPoint) == fDrawTarget->getDrawState().getVertexSize(
)); |
| 612 } | 612 } |
| 613 | 613 |
| 614 GrFixed tx = SkIntToFixed(glyph->fAtlasLocation.fX); | 614 SkFixed tx = SkIntToFixed(glyph->fAtlasLocation.fX); |
| 615 GrFixed ty = SkIntToFixed(glyph->fAtlasLocation.fY); | 615 SkFixed ty = SkIntToFixed(glyph->fAtlasLocation.fY); |
| 616 | 616 |
| 617 SkRect r; | 617 SkRect r; |
| 618 r.fLeft = SkFixedToFloat(vx); | 618 r.fLeft = SkFixedToFloat(vx); |
| 619 r.fTop = SkFixedToFloat(vy); | 619 r.fTop = SkFixedToFloat(vy); |
| 620 r.fRight = SkFixedToFloat(vx + width); | 620 r.fRight = SkFixedToFloat(vx + width); |
| 621 r.fBottom = SkFixedToFloat(vy + height); | 621 r.fBottom = SkFixedToFloat(vy + height); |
| 622 | 622 |
| 623 fVertexBounds.growToInclude(r); | 623 fVertexBounds.growToInclude(r); |
| 624 | 624 |
| 625 fVertices[2*fCurrVertex].setRectFan(r.fLeft, r.fTop, r.fRight, r.fBottom, | 625 fVertices[2*fCurrVertex].setRectFan(r.fLeft, r.fTop, r.fRight, r.fBottom, |
| 626 2 * sizeof(SkPoint)); | 626 2 * sizeof(SkPoint)); |
| 627 fVertices[2*fCurrVertex+1].setRectFan(SkFixedToFloat(texture->normalizeFixed
X(tx)), | 627 fVertices[2*fCurrVertex+1].setRectFan(SkFixedToFloat(texture->normalizeFixed
X(tx)), |
| 628 SkFixedToFloat(texture->normalizeFixed
Y(ty)), | 628 SkFixedToFloat(texture->normalizeFixed
Y(ty)), |
| 629 SkFixedToFloat(texture->normalizeFixed
X(tx + width)), | 629 SkFixedToFloat(texture->normalizeFixed
X(tx + width)), |
| 630 SkFixedToFloat(texture->normalizeFixed
Y(ty + height)), | 630 SkFixedToFloat(texture->normalizeFixed
Y(ty + height)), |
| 631 2 * sizeof(SkPoint)); | 631 2 * sizeof(SkPoint)); |
| 632 fCurrVertex += 4; | 632 fCurrVertex += 4; |
| 633 } | 633 } |
| OLD | NEW |