Chromium Code Reviews| 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 510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 521 } | 521 } |
| 522 | 522 |
| 523 bool useColorVerts = kA8_GrMaskFormat == fStrike->getMaskFormat(); | 523 bool useColorVerts = kA8_GrMaskFormat == fStrike->getMaskFormat(); |
| 524 | 524 |
| 525 if (NULL == fVertices) { | 525 if (NULL == fVertices) { |
| 526 // If we need to reserve vertices allow the draw target to suggest | 526 // If we need to reserve vertices allow the draw target to suggest |
| 527 // a number of verts to reserve and whether to perform a flush. | 527 // a number of verts to reserve and whether to perform a flush. |
| 528 fMaxVertices = kMinRequestedVerts; | 528 fMaxVertices = kMinRequestedVerts; |
| 529 if (useColorVerts) { | 529 if (useColorVerts) { |
| 530 fDrawTarget->drawState()->setVertexAttribs<gTextVertexWithColorAttri bs>( | 530 fDrawTarget->drawState()->setVertexAttribs<gTextVertexWithColorAttri bs>( |
| 531 SK_ARRAY_COUNT(gTextVertexWithColorAttribs)); | 531 SK_ARRAY_COUNT(gTextVertexWithColorAttribs), 2 * sizeof(SkPoint) + sizeof(GrColor)); |
|
bsalomon
2014/08/27 17:46:27
Maybe capture these in some static consts with gTe
egdaniel
2014/08/27 18:33:55
Done.
| |
| 532 } else { | 532 } else { |
| 533 fDrawTarget->drawState()->setVertexAttribs<gTextVertexAttribs>( | 533 fDrawTarget->drawState()->setVertexAttribs<gTextVertexAttribs>( |
| 534 SK_ARRAY_COUNT(gTextVertexAttribs)); | 534 SK_ARRAY_COUNT(gTextVertexAttribs), 2 * sizeof(SkPoint)); |
| 535 } | 535 } |
| 536 bool flush = fDrawTarget->geometryHints(&fMaxVertices, NULL); | 536 bool flush = fDrawTarget->geometryHints(&fMaxVertices, NULL); |
| 537 if (flush) { | 537 if (flush) { |
| 538 this->flushGlyphs(); | 538 this->flushGlyphs(); |
| 539 fContext->flush(); | 539 fContext->flush(); |
| 540 if (useColorVerts) { | 540 if (useColorVerts) { |
| 541 fDrawTarget->drawState()->setVertexAttribs<gTextVertexWithColorA ttribs>( | 541 fDrawTarget->drawState()->setVertexAttribs<gTextVertexWithColorA ttribs>( |
| 542 SK_ARRAY_COUNT(gTextVertexWithColorAttribs)); | 542 SK_ARRAY_COUNT(gTextVertexWithColorAttribs), 2 * sizeof(SkPo int) + sizeof(GrColor)); |
| 543 } else { | 543 } else { |
| 544 fDrawTarget->drawState()->setVertexAttribs<gTextVertexAttribs>( | 544 fDrawTarget->drawState()->setVertexAttribs<gTextVertexAttribs>( |
| 545 SK_ARRAY_COUNT(gTextVertexAttribs)); | 545 SK_ARRAY_COUNT(gTextVertexAttribs), 2 * sizeof(SkPoint)); |
| 546 } | 546 } |
| 547 } | 547 } |
| 548 fMaxVertices = kDefaultRequestedVerts; | 548 fMaxVertices = kDefaultRequestedVerts; |
| 549 // ignore return, no point in flushing again. | 549 // ignore return, no point in flushing again. |
| 550 fDrawTarget->geometryHints(&fMaxVertices, NULL); | 550 fDrawTarget->geometryHints(&fMaxVertices, NULL); |
| 551 | 551 |
| 552 int maxQuadVertices = 4 * fContext->getQuadIndexBuffer()->maxQuads(); | 552 int maxQuadVertices = 4 * fContext->getQuadIndexBuffer()->maxQuads(); |
| 553 if (fMaxVertices < kMinRequestedVerts) { | 553 if (fMaxVertices < kMinRequestedVerts) { |
| 554 fMaxVertices = kDefaultRequestedVerts; | 554 fMaxVertices = kDefaultRequestedVerts; |
| 555 } else if (fMaxVertices > maxQuadVertices) { | 555 } else if (fMaxVertices > maxQuadVertices) { |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 570 r.fLeft = SkFixedToFloat(vx); | 570 r.fLeft = SkFixedToFloat(vx); |
| 571 r.fTop = SkFixedToFloat(vy); | 571 r.fTop = SkFixedToFloat(vy); |
| 572 r.fRight = SkFixedToFloat(vx + width); | 572 r.fRight = SkFixedToFloat(vx + width); |
| 573 r.fBottom = SkFixedToFloat(vy + height); | 573 r.fBottom = SkFixedToFloat(vy + height); |
| 574 | 574 |
| 575 fVertexBounds.growToInclude(r); | 575 fVertexBounds.growToInclude(r); |
| 576 | 576 |
| 577 size_t vertSize = useColorVerts ? (2 * sizeof(SkPoint) + sizeof(GrColor)) : | 577 size_t vertSize = useColorVerts ? (2 * sizeof(SkPoint) + sizeof(GrColor)) : |
| 578 (2 * sizeof(SkPoint)); | 578 (2 * sizeof(SkPoint)); |
| 579 | 579 |
| 580 SkASSERT(vertSize == fDrawTarget->getDrawState().getVertexSize()); | 580 SkASSERT(vertSize == fDrawTarget->getDrawState().getVertexStride()); |
| 581 | 581 |
| 582 SkPoint* positions = reinterpret_cast<SkPoint*>( | 582 SkPoint* positions = reinterpret_cast<SkPoint*>( |
| 583 reinterpret_cast<intptr_t>(fVertices) + vertSize * fCurrVertex); | 583 reinterpret_cast<intptr_t>(fVertices) + vertSize * fCurrVertex); |
| 584 positions->setRectFan(r.fLeft, r.fTop, r.fRight, r.fBottom, vertSize); | 584 positions->setRectFan(r.fLeft, r.fTop, r.fRight, r.fBottom, vertSize); |
| 585 | 585 |
| 586 // The texture coords are last in both the with and without color vertex lay outs. | 586 // The texture coords are last in both the with and without color vertex lay outs. |
| 587 SkPoint* textureCoords = reinterpret_cast<SkPoint*>( | 587 SkPoint* textureCoords = reinterpret_cast<SkPoint*>( |
| 588 reinterpret_cast<intptr_t>(positions) + vertSize - sizeof(SkPoint)) ; | 588 reinterpret_cast<intptr_t>(positions) + vertSize - sizeof(SkPoint)) ; |
| 589 textureCoords->setRectFan(SkFixedToFloat(texture->normalizeFixedX(tx)), | 589 textureCoords->setRectFan(SkFixedToFloat(texture->normalizeFixedX(tx)), |
| 590 SkFixedToFloat(texture->normalizeFixedY(ty)), | 590 SkFixedToFloat(texture->normalizeFixedY(ty)), |
| 591 SkFixedToFloat(texture->normalizeFixedX(tx + width )), | 591 SkFixedToFloat(texture->normalizeFixedX(tx + width )), |
| 592 SkFixedToFloat(texture->normalizeFixedY(ty + heigh t)), | 592 SkFixedToFloat(texture->normalizeFixedY(ty + heigh t)), |
| 593 vertSize); | 593 vertSize); |
| 594 if (useColorVerts) { | 594 if (useColorVerts) { |
| 595 if (0xFF == GrColorUnpackA(fPaint.getColor())) { | 595 if (0xFF == GrColorUnpackA(fPaint.getColor())) { |
| 596 fDrawTarget->drawState()->setHint(GrDrawState::kVertexColorsAreOpaqu e_Hint, true); | 596 fDrawTarget->drawState()->setHint(GrDrawState::kVertexColorsAreOpaqu e_Hint, true); |
| 597 } | 597 } |
| 598 // color comes after position. | 598 // color comes after position. |
| 599 GrColor* colors = reinterpret_cast<GrColor*>(positions + 1); | 599 GrColor* colors = reinterpret_cast<GrColor*>(positions + 1); |
| 600 for (int i = 0; i < 4; ++i) { | 600 for (int i = 0; i < 4; ++i) { |
| 601 *colors = fPaint.getColor(); | 601 *colors = fPaint.getColor(); |
| 602 colors = reinterpret_cast<GrColor*>(reinterpret_cast<intptr_t>(colors ) + vertSize); | 602 colors = reinterpret_cast<GrColor*>(reinterpret_cast<intptr_t>(colors ) + vertSize); |
| 603 } | 603 } |
| 604 } | 604 } |
| 605 fCurrVertex += 4; | 605 fCurrVertex += 4; |
| 606 } | 606 } |
| OLD | NEW |