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 | |
45 // position + color + texture coord | 43 // position + color + texture coord |
46 extern const GrVertexAttrib gTextVertexWithColorAttribs[] = { | 44 extern const GrVertexAttrib gTextVertexWithColorAttribs[] = { |
47 {kVec2f_GrVertexAttribType, 0, kPosition_Gr
VertexAttribBinding}, | 45 {kVec2f_GrVertexAttribType, 0, kPosition_Gr
VertexAttribBinding}, |
48 {kVec4ub_GrVertexAttribType, sizeof(SkPoint), kColor_GrVer
texAttribBinding}, | 46 {kVec4ub_GrVertexAttribType, sizeof(SkPoint), kColor_GrVer
texAttribBinding}, |
49 {kVec2f_GrVertexAttribType, sizeof(SkPoint) + sizeof(GrColor), kEffect_GrVe
rtexAttribBinding} | 47 {kVec2f_GrVertexAttribType, sizeof(SkPoint) + sizeof(GrColor), kEffect_GrVe
rtexAttribBinding} |
50 }; | 48 }; |
51 | 49 |
52 static const size_t kTextVAColorSize = 2 * sizeof(SkPoint) + sizeof(GrColor); | |
53 | |
54 }; | 50 }; |
55 | 51 |
56 GrBitmapTextContext::GrBitmapTextContext(GrContext* context, | 52 GrBitmapTextContext::GrBitmapTextContext(GrContext* context, |
57 const SkDeviceProperties& properties) | 53 const SkDeviceProperties& properties) |
58 : GrTextContext(context, properties) | 54 : GrTextContext(context, properties) |
59 , fStrike(NULL) | 55 , fStrike(NULL) |
60 , fEffectTextureUniqueID(SK_InvalidUnique
ID) | 56 , fEffectTextureUniqueID(SK_InvalidUnique
ID) |
61 , fVertices(NULL) | 57 , fVertices(NULL) |
62 , fVertexCount(0) | 58 , fVertexCount(0) |
63 , fCurrVertex(0) { | 59 , fCurrVertex(0) { |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 this->flushGlyphs(); | 169 this->flushGlyphs(); |
174 | 170 |
175 GrTextContext::finish(); | 171 GrTextContext::finish(); |
176 } | 172 } |
177 | 173 |
178 void GrBitmapTextContext::allocateVertices(const char text[], size_t byteLength)
{ | 174 void GrBitmapTextContext::allocateVertices(const char text[], size_t byteLength)
{ |
179 SkASSERT(NULL == fVertices); | 175 SkASSERT(NULL == fVertices); |
180 bool useColorVerts = kA8_GrMaskFormat == fStrike->getMaskFormat(); | 176 bool useColorVerts = kA8_GrMaskFormat == fStrike->getMaskFormat(); |
181 if (useColorVerts) { | 177 if (useColorVerts) { |
182 fDrawTarget->drawState()->setVertexAttribs<gTextVertexWithColorAttribs>( | 178 fDrawTarget->drawState()->setVertexAttribs<gTextVertexWithColorAttribs>( |
183 SK_ARRAY_COUNT(gTextVertexWi
thColorAttribs), | 179 SK_ARRAY_COUNT(gTextVertexWi
thColorAttribs)); |
184 kTextVAColorSize); | |
185 } else { | 180 } else { |
186 fDrawTarget->drawState()->setVertexAttribs<gTextVertexAttribs>( | 181 fDrawTarget->drawState()->setVertexAttribs<gTextVertexAttribs>( |
187 SK_ARRAY_COUNT(gTextVertexAt
tribs), | 182 SK_ARRAY_COUNT(gTextVertexAt
tribs)); |
188 kTextVASize); | |
189 } | 183 } |
190 fVertexCount = 4*fSkPaint.textToGlyphs(text, byteLength, NULL); | 184 fVertexCount = 4*fSkPaint.textToGlyphs(text, byteLength, NULL); |
191 bool success = fDrawTarget->reserveVertexAndIndexSpace(fVertexCount, | 185 bool success = fDrawTarget->reserveVertexAndIndexSpace(fVertexCount, |
192 0, | 186 0, |
193 &fVertices, | 187 &fVertices, |
194 NULL); | 188 NULL); |
195 GrAlwaysAssert(success); | 189 GrAlwaysAssert(success); |
196 } | 190 } |
197 | 191 |
198 void GrBitmapTextContext::drawText(const GrPaint& paint, const SkPaint& skPaint, | 192 void GrBitmapTextContext::drawText(const GrPaint& paint, const SkPaint& skPaint, |
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
558 r.fTop = SkFixedToFloat(vy); | 552 r.fTop = SkFixedToFloat(vy); |
559 r.fRight = SkFixedToFloat(vx + width); | 553 r.fRight = SkFixedToFloat(vx + width); |
560 r.fBottom = SkFixedToFloat(vy + height); | 554 r.fBottom = SkFixedToFloat(vy + height); |
561 | 555 |
562 fVertexBounds.growToInclude(r); | 556 fVertexBounds.growToInclude(r); |
563 | 557 |
564 bool useColorVerts = kA8_GrMaskFormat == fStrike->getMaskFormat(); | 558 bool useColorVerts = kA8_GrMaskFormat == fStrike->getMaskFormat(); |
565 size_t vertSize = useColorVerts ? (2 * sizeof(SkPoint) + sizeof(GrColor)) : | 559 size_t vertSize = useColorVerts ? (2 * sizeof(SkPoint) + sizeof(GrColor)) : |
566 (2 * sizeof(SkPoint)); | 560 (2 * sizeof(SkPoint)); |
567 | 561 |
568 SkASSERT(vertSize == fDrawTarget->getDrawState().getVertexStride()); | 562 SkASSERT(vertSize == fDrawTarget->getDrawState().getVertexSize()); |
569 | 563 |
570 SkPoint* positions = reinterpret_cast<SkPoint*>( | 564 SkPoint* positions = reinterpret_cast<SkPoint*>( |
571 reinterpret_cast<intptr_t>(fVertices) + vertSize * fCurrVertex); | 565 reinterpret_cast<intptr_t>(fVertices) + vertSize * fCurrVertex); |
572 positions->setRectFan(r.fLeft, r.fTop, r.fRight, r.fBottom, vertSize); | 566 positions->setRectFan(r.fLeft, r.fTop, r.fRight, r.fBottom, vertSize); |
573 | 567 |
574 // The texture coords are last in both the with and without color vertex lay
outs. | 568 // The texture coords are last in both the with and without color vertex lay
outs. |
575 SkPoint* textureCoords = reinterpret_cast<SkPoint*>( | 569 SkPoint* textureCoords = reinterpret_cast<SkPoint*>( |
576 reinterpret_cast<intptr_t>(positions) + vertSize - sizeof(SkPoint))
; | 570 reinterpret_cast<intptr_t>(positions) + vertSize - sizeof(SkPoint))
; |
577 textureCoords->setRectFan(SkFixedToFloat(texture->normalizeFixedX(tx)), | 571 textureCoords->setRectFan(SkFixedToFloat(texture->normalizeFixedX(tx)), |
578 SkFixedToFloat(texture->normalizeFixedY(ty)), | 572 SkFixedToFloat(texture->normalizeFixedY(ty)), |
579 SkFixedToFloat(texture->normalizeFixedX(tx + width
)), | 573 SkFixedToFloat(texture->normalizeFixedX(tx + width
)), |
580 SkFixedToFloat(texture->normalizeFixedY(ty + heigh
t)), | 574 SkFixedToFloat(texture->normalizeFixedY(ty + heigh
t)), |
581 vertSize); | 575 vertSize); |
582 if (useColorVerts) { | 576 if (useColorVerts) { |
583 if (0xFF == GrColorUnpackA(fPaint.getColor())) { | 577 if (0xFF == GrColorUnpackA(fPaint.getColor())) { |
584 fDrawTarget->drawState()->setHint(GrDrawState::kVertexColorsAreOpaqu
e_Hint, true); | 578 fDrawTarget->drawState()->setHint(GrDrawState::kVertexColorsAreOpaqu
e_Hint, true); |
585 } | 579 } |
586 // color comes after position. | 580 // color comes after position. |
587 GrColor* colors = reinterpret_cast<GrColor*>(positions + 1); | 581 GrColor* colors = reinterpret_cast<GrColor*>(positions + 1); |
588 for (int i = 0; i < 4; ++i) { | 582 for (int i = 0; i < 4; ++i) { |
589 *colors = fPaint.getColor(); | 583 *colors = fPaint.getColor(); |
590 colors = reinterpret_cast<GrColor*>(reinterpret_cast<intptr_t>(colors
) + vertSize); | 584 colors = reinterpret_cast<GrColor*>(reinterpret_cast<intptr_t>(colors
) + vertSize); |
591 } | 585 } |
592 } | 586 } |
593 fCurrVertex += 4; | 587 fCurrVertex += 4; |
594 } | 588 } |
OLD | NEW |