| 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 22 matching lines...) Expand all Loading... |
| 33 static const int kGlyphCoordsNoColorAttributeIndex = 1; | 33 static const int kGlyphCoordsNoColorAttributeIndex = 1; |
| 34 static const int kGlyphCoordsWithColorAttributeIndex = 2; | 34 static const int kGlyphCoordsWithColorAttributeIndex = 2; |
| 35 | 35 |
| 36 namespace { | 36 namespace { |
| 37 // position + texture coord | 37 // position + texture coord |
| 38 extern const GrVertexAttrib gTextVertexAttribs[] = { | 38 extern const GrVertexAttrib gTextVertexAttribs[] = { |
| 39 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding
}, | 39 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding
}, |
| 40 {kVec2f_GrVertexAttribType, sizeof(SkPoint) , kEffect_GrVertexAttribBinding} | 40 {kVec2f_GrVertexAttribType, sizeof(SkPoint) , kEffect_GrVertexAttribBinding} |
| 41 }; | 41 }; |
| 42 | 42 |
| 43 static const size_t kTextVASize = 2 * sizeof(SkPoint); |
| 44 |
| 43 // position + color + texture coord | 45 // position + color + texture coord |
| 44 extern const GrVertexAttrib gTextVertexWithColorAttribs[] = { | 46 extern const GrVertexAttrib gTextVertexWithColorAttribs[] = { |
| 45 {kVec2f_GrVertexAttribType, 0, kPosition_Gr
VertexAttribBinding}, | 47 {kVec2f_GrVertexAttribType, 0, kPosition_Gr
VertexAttribBinding}, |
| 46 {kVec4ub_GrVertexAttribType, sizeof(SkPoint), kColor_GrVer
texAttribBinding}, | 48 {kVec4ub_GrVertexAttribType, sizeof(SkPoint), kColor_GrVer
texAttribBinding}, |
| 47 {kVec2f_GrVertexAttribType, sizeof(SkPoint) + sizeof(GrColor), kEffect_GrVe
rtexAttribBinding} | 49 {kVec2f_GrVertexAttribType, sizeof(SkPoint) + sizeof(GrColor), kEffect_GrVe
rtexAttribBinding} |
| 48 }; | 50 }; |
| 49 | 51 |
| 52 static const size_t kTextVAColorSize = 2 * sizeof(SkPoint) + sizeof(GrColor); |
| 53 |
| 50 }; | 54 }; |
| 51 | 55 |
| 52 GrBitmapTextContext::GrBitmapTextContext(GrContext* context, | 56 GrBitmapTextContext::GrBitmapTextContext(GrContext* context, |
| 53 const SkDeviceProperties& properties) | 57 const SkDeviceProperties& properties) |
| 54 : GrTextContext(context, properties) { | 58 : GrTextContext(context, properties) { |
| 55 fStrike = NULL; | 59 fStrike = NULL; |
| 56 | 60 |
| 57 fCurrTexture = NULL; | 61 fCurrTexture = NULL; |
| 58 fCurrVertex = 0; | 62 fCurrVertex = 0; |
| 59 fEffectTextureUniqueID = SK_InvalidUniqueID; | 63 fEffectTextureUniqueID = SK_InvalidUniqueID; |
| (...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 521 } | 525 } |
| 522 | 526 |
| 523 bool useColorVerts = kA8_GrMaskFormat == fStrike->getMaskFormat(); | 527 bool useColorVerts = kA8_GrMaskFormat == fStrike->getMaskFormat(); |
| 524 | 528 |
| 525 if (NULL == fVertices) { | 529 if (NULL == fVertices) { |
| 526 // If we need to reserve vertices allow the draw target to suggest | 530 // 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. | 531 // a number of verts to reserve and whether to perform a flush. |
| 528 fMaxVertices = kMinRequestedVerts; | 532 fMaxVertices = kMinRequestedVerts; |
| 529 if (useColorVerts) { | 533 if (useColorVerts) { |
| 530 fDrawTarget->drawState()->setVertexAttribs<gTextVertexWithColorAttri
bs>( | 534 fDrawTarget->drawState()->setVertexAttribs<gTextVertexWithColorAttri
bs>( |
| 531 SK_ARRAY_COUNT(gTextVertexWithColorAttribs)); | 535 SK_ARRAY_COUNT(gTextVertexWithColorAttribs), kTextVAColorSize); |
| 532 } else { | 536 } else { |
| 533 fDrawTarget->drawState()->setVertexAttribs<gTextVertexAttribs>( | 537 fDrawTarget->drawState()->setVertexAttribs<gTextVertexAttribs>( |
| 534 SK_ARRAY_COUNT(gTextVertexAttribs)); | 538 SK_ARRAY_COUNT(gTextVertexAttribs), kTextVASize); |
| 535 } | 539 } |
| 536 bool flush = fDrawTarget->geometryHints(&fMaxVertices, NULL); | 540 bool flush = fDrawTarget->geometryHints(&fMaxVertices, NULL); |
| 537 if (flush) { | 541 if (flush) { |
| 538 this->flushGlyphs(); | 542 this->flushGlyphs(); |
| 539 fContext->flush(); | 543 fContext->flush(); |
| 540 if (useColorVerts) { | 544 if (useColorVerts) { |
| 541 fDrawTarget->drawState()->setVertexAttribs<gTextVertexWithColorA
ttribs>( | 545 fDrawTarget->drawState()->setVertexAttribs<gTextVertexWithColorA
ttribs>( |
| 542 SK_ARRAY_COUNT(gTextVertexWithColorAttribs)); | 546 SK_ARRAY_COUNT(gTextVertexWithColorAttribs), kTextVAColorSiz
e); |
| 543 } else { | 547 } else { |
| 544 fDrawTarget->drawState()->setVertexAttribs<gTextVertexAttribs>( | 548 fDrawTarget->drawState()->setVertexAttribs<gTextVertexAttribs>( |
| 545 SK_ARRAY_COUNT(gTextVertexAttribs)); | 549 SK_ARRAY_COUNT(gTextVertexAttribs), kTextVASize); |
| 546 } | 550 } |
| 547 } | 551 } |
| 548 fMaxVertices = kDefaultRequestedVerts; | 552 fMaxVertices = kDefaultRequestedVerts; |
| 549 // ignore return, no point in flushing again. | 553 // ignore return, no point in flushing again. |
| 550 fDrawTarget->geometryHints(&fMaxVertices, NULL); | 554 fDrawTarget->geometryHints(&fMaxVertices, NULL); |
| 551 | 555 |
| 552 int maxQuadVertices = 4 * fContext->getQuadIndexBuffer()->maxQuads(); | 556 int maxQuadVertices = 4 * fContext->getQuadIndexBuffer()->maxQuads(); |
| 553 if (fMaxVertices < kMinRequestedVerts) { | 557 if (fMaxVertices < kMinRequestedVerts) { |
| 554 fMaxVertices = kDefaultRequestedVerts; | 558 fMaxVertices = kDefaultRequestedVerts; |
| 555 } else if (fMaxVertices > maxQuadVertices) { | 559 } else if (fMaxVertices > maxQuadVertices) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 570 r.fLeft = SkFixedToFloat(vx); | 574 r.fLeft = SkFixedToFloat(vx); |
| 571 r.fTop = SkFixedToFloat(vy); | 575 r.fTop = SkFixedToFloat(vy); |
| 572 r.fRight = SkFixedToFloat(vx + width); | 576 r.fRight = SkFixedToFloat(vx + width); |
| 573 r.fBottom = SkFixedToFloat(vy + height); | 577 r.fBottom = SkFixedToFloat(vy + height); |
| 574 | 578 |
| 575 fVertexBounds.growToInclude(r); | 579 fVertexBounds.growToInclude(r); |
| 576 | 580 |
| 577 size_t vertSize = useColorVerts ? (2 * sizeof(SkPoint) + sizeof(GrColor)) : | 581 size_t vertSize = useColorVerts ? (2 * sizeof(SkPoint) + sizeof(GrColor)) : |
| 578 (2 * sizeof(SkPoint)); | 582 (2 * sizeof(SkPoint)); |
| 579 | 583 |
| 580 SkASSERT(vertSize == fDrawTarget->getDrawState().getVertexSize()); | 584 SkASSERT(vertSize == fDrawTarget->getDrawState().getVertexStride()); |
| 581 | 585 |
| 582 SkPoint* positions = reinterpret_cast<SkPoint*>( | 586 SkPoint* positions = reinterpret_cast<SkPoint*>( |
| 583 reinterpret_cast<intptr_t>(fVertices) + vertSize * fCurrVertex); | 587 reinterpret_cast<intptr_t>(fVertices) + vertSize * fCurrVertex); |
| 584 positions->setRectFan(r.fLeft, r.fTop, r.fRight, r.fBottom, vertSize); | 588 positions->setRectFan(r.fLeft, r.fTop, r.fRight, r.fBottom, vertSize); |
| 585 | 589 |
| 586 // The texture coords are last in both the with and without color vertex lay
outs. | 590 // The texture coords are last in both the with and without color vertex lay
outs. |
| 587 SkPoint* textureCoords = reinterpret_cast<SkPoint*>( | 591 SkPoint* textureCoords = reinterpret_cast<SkPoint*>( |
| 588 reinterpret_cast<intptr_t>(positions) + vertSize - sizeof(SkPoint))
; | 592 reinterpret_cast<intptr_t>(positions) + vertSize - sizeof(SkPoint))
; |
| 589 textureCoords->setRectFan(SkFixedToFloat(texture->normalizeFixedX(tx)), | 593 textureCoords->setRectFan(SkFixedToFloat(texture->normalizeFixedX(tx)), |
| 590 SkFixedToFloat(texture->normalizeFixedY(ty)), | 594 SkFixedToFloat(texture->normalizeFixedY(ty)), |
| 591 SkFixedToFloat(texture->normalizeFixedX(tx + width
)), | 595 SkFixedToFloat(texture->normalizeFixedX(tx + width
)), |
| 592 SkFixedToFloat(texture->normalizeFixedY(ty + heigh
t)), | 596 SkFixedToFloat(texture->normalizeFixedY(ty + heigh
t)), |
| 593 vertSize); | 597 vertSize); |
| 594 if (useColorVerts) { | 598 if (useColorVerts) { |
| 595 if (0xFF == GrColorUnpackA(fPaint.getColor())) { | 599 if (0xFF == GrColorUnpackA(fPaint.getColor())) { |
| 596 fDrawTarget->drawState()->setHint(GrDrawState::kVertexColorsAreOpaqu
e_Hint, true); | 600 fDrawTarget->drawState()->setHint(GrDrawState::kVertexColorsAreOpaqu
e_Hint, true); |
| 597 } | 601 } |
| 598 // color comes after position. | 602 // color comes after position. |
| 599 GrColor* colors = reinterpret_cast<GrColor*>(positions + 1); | 603 GrColor* colors = reinterpret_cast<GrColor*>(positions + 1); |
| 600 for (int i = 0; i < 4; ++i) { | 604 for (int i = 0; i < 4; ++i) { |
| 601 *colors = fPaint.getColor(); | 605 *colors = fPaint.getColor(); |
| 602 colors = reinterpret_cast<GrColor*>(reinterpret_cast<intptr_t>(colors
) + vertSize); | 606 colors = reinterpret_cast<GrColor*>(reinterpret_cast<intptr_t>(colors
) + vertSize); |
| 603 } | 607 } |
| 604 } | 608 } |
| 605 fCurrVertex += 4; | 609 fCurrVertex += 4; |
| 606 } | 610 } |
| OLD | NEW |