| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2010 Google Inc. | 2 * Copyright 2010 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 | 8 |
| 9 | 9 |
| 10 #include "GrTextContext.h" | 10 #include "GrTextContext.h" |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 this->flushGlyphs(); | 103 this->flushGlyphs(); |
| 104 if (fDrawTarget) { | 104 if (fDrawTarget) { |
| 105 fDrawTarget->drawState()->disableStages(); | 105 fDrawTarget->drawState()->disableStages(); |
| 106 } | 106 } |
| 107 } | 107 } |
| 108 | 108 |
| 109 void GrTextContext::flush() { | 109 void GrTextContext::flush() { |
| 110 this->flushGlyphs(); | 110 this->flushGlyphs(); |
| 111 } | 111 } |
| 112 | 112 |
| 113 namespace { |
| 114 |
| 115 // position + texture coord |
| 116 extern const GrVertexAttrib gTextVertexAttribs[] = { |
| 117 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding
}, |
| 118 {kVec2f_GrVertexAttribType, sizeof(GrPoint), kEffect_GrVertexAttribBinding} |
| 119 }; |
| 120 |
| 121 }; |
| 122 |
| 113 void GrTextContext::drawPackedGlyph(GrGlyph::PackedID packed, | 123 void GrTextContext::drawPackedGlyph(GrGlyph::PackedID packed, |
| 114 GrFixed vx, GrFixed vy, | 124 GrFixed vx, GrFixed vy, |
| 115 GrFontScaler* scaler) { | 125 GrFontScaler* scaler) { |
| 116 if (NULL == fStrike) { | 126 if (NULL == fStrike) { |
| 117 fStrike = fContext->getFontCache()->getStrike(scaler); | 127 fStrike = fContext->getFontCache()->getStrike(scaler); |
| 118 } | 128 } |
| 119 | 129 |
| 120 GrGlyph* glyph = fStrike->getGlyph(packed, scaler); | 130 GrGlyph* glyph = fStrike->getGlyph(packed, scaler); |
| 121 if (NULL == glyph || glyph->fBounds.isEmpty()) { | 131 if (NULL == glyph || glyph->fBounds.isEmpty()) { |
| 122 return; | 132 return; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 GrTexture* texture = glyph->fAtlas->texture(); | 195 GrTexture* texture = glyph->fAtlas->texture(); |
| 186 GrAssert(texture); | 196 GrAssert(texture); |
| 187 | 197 |
| 188 if (fCurrTexture != texture || fCurrVertex + 4 > fMaxVertices) { | 198 if (fCurrTexture != texture || fCurrVertex + 4 > fMaxVertices) { |
| 189 this->flushGlyphs(); | 199 this->flushGlyphs(); |
| 190 fCurrTexture = texture; | 200 fCurrTexture = texture; |
| 191 fCurrTexture->ref(); | 201 fCurrTexture->ref(); |
| 192 } | 202 } |
| 193 | 203 |
| 194 if (NULL == fVertices) { | 204 if (NULL == fVertices) { |
| 195 // position + texture coord | |
| 196 static const GrVertexAttrib kVertexAttribs[] = { | |
| 197 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttri
bBinding}, | |
| 198 {kVec2f_GrVertexAttribType, sizeof(GrPoint), kEffect_GrVertexAttribB
inding} | |
| 199 }; | |
| 200 | |
| 201 // If we need to reserve vertices allow the draw target to suggest | 205 // If we need to reserve vertices allow the draw target to suggest |
| 202 // a number of verts to reserve and whether to perform a flush. | 206 // a number of verts to reserve and whether to perform a flush. |
| 203 fMaxVertices = kMinRequestedVerts; | 207 fMaxVertices = kMinRequestedVerts; |
| 204 bool flush = false; | 208 bool flush = false; |
| 205 fDrawTarget = fContext->getTextTarget(fPaint); | 209 fDrawTarget = fContext->getTextTarget(fPaint); |
| 206 if (NULL != fDrawTarget) { | 210 if (NULL != fDrawTarget) { |
| 207 fDrawTarget->drawState()->setVertexAttribs(kVertexAttribs, SK_ARRAY_
COUNT(kVertexAttribs)); | 211 fDrawTarget->drawState()->setVertexAttribs<gTextVertexAttribs>(SK_AR
RAY_COUNT(gTextVertexAttribs)); |
| 208 flush = fDrawTarget->geometryHints(&fMaxVertices, NULL); | 212 flush = fDrawTarget->geometryHints(&fMaxVertices, NULL); |
| 209 } | 213 } |
| 210 if (flush) { | 214 if (flush) { |
| 211 this->flushGlyphs(); | 215 this->flushGlyphs(); |
| 212 fContext->flush(); | 216 fContext->flush(); |
| 213 // flushGlyphs() will reset fDrawTarget to NULL. | 217 // flushGlyphs() will reset fDrawTarget to NULL. |
| 214 fDrawTarget = fContext->getTextTarget(fPaint); | 218 fDrawTarget = fContext->getTextTarget(fPaint); |
| 215 fDrawTarget->drawState()->setVertexAttribs(kVertexAttribs, SK_ARRAY_
COUNT(kVertexAttribs)); | 219 fDrawTarget->drawState()->setVertexAttribs<gTextVertexAttribs>(SK_AR
RAY_COUNT(gTextVertexAttribs)); |
| 216 } | 220 } |
| 217 fMaxVertices = kDefaultRequestedVerts; | 221 fMaxVertices = kDefaultRequestedVerts; |
| 218 // ignore return, no point in flushing again. | 222 // ignore return, no point in flushing again. |
| 219 fDrawTarget->geometryHints(&fMaxVertices, NULL); | 223 fDrawTarget->geometryHints(&fMaxVertices, NULL); |
| 220 | 224 |
| 221 int maxQuadVertices = 4 * fContext->getQuadIndexBuffer()->maxQuads(); | 225 int maxQuadVertices = 4 * fContext->getQuadIndexBuffer()->maxQuads(); |
| 222 if (fMaxVertices < kMinRequestedVerts) { | 226 if (fMaxVertices < kMinRequestedVerts) { |
| 223 fMaxVertices = kDefaultRequestedVerts; | 227 fMaxVertices = kDefaultRequestedVerts; |
| 224 } else if (fMaxVertices > maxQuadVertices) { | 228 } else if (fMaxVertices > maxQuadVertices) { |
| 225 // don't exceed the limit of the index buffer | 229 // don't exceed the limit of the index buffer |
| (...skipping 16 matching lines...) Expand all Loading... |
| 242 SkFixedToFloat(vx + width), | 246 SkFixedToFloat(vx + width), |
| 243 SkFixedToFloat(vy + height), | 247 SkFixedToFloat(vy + height), |
| 244 2 * sizeof(SkPoint)); | 248 2 * sizeof(SkPoint)); |
| 245 fVertices[2*fCurrVertex+1].setRectFan(SkFixedToFloat(texture->normalizeFixed
X(tx)), | 249 fVertices[2*fCurrVertex+1].setRectFan(SkFixedToFloat(texture->normalizeFixed
X(tx)), |
| 246 SkFixedToFloat(texture->normalizeFixed
Y(ty)), | 250 SkFixedToFloat(texture->normalizeFixed
Y(ty)), |
| 247 SkFixedToFloat(texture->normalizeFixed
X(tx + width)), | 251 SkFixedToFloat(texture->normalizeFixed
X(tx + width)), |
| 248 SkFixedToFloat(texture->normalizeFixed
Y(ty + height)), | 252 SkFixedToFloat(texture->normalizeFixed
Y(ty + height)), |
| 249 2 * sizeof(SkPoint)); | 253 2 * sizeof(SkPoint)); |
| 250 fCurrVertex += 4; | 254 fCurrVertex += 4; |
| 251 } | 255 } |
| OLD | NEW |