| 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 {kVec4ub_GrVertexAttribType, sizeof(SkPoint), kColor_GrVer
texAttribBinding}, | 48 {kVec4ub_GrVertexAttribType, sizeof(SkPoint), kColor_GrVer
texAttribBinding}, |
| 49 {kVec2f_GrVertexAttribType, sizeof(SkPoint) + sizeof(GrColor), kEffect_GrVe
rtexAttribBinding} | 49 {kVec2f_GrVertexAttribType, sizeof(SkPoint) + sizeof(GrColor), kEffect_GrVe
rtexAttribBinding} |
| 50 }; | 50 }; |
| 51 | 51 |
| 52 static const size_t kTextVAColorSize = 2 * sizeof(SkPoint) + sizeof(GrColor); | 52 static const size_t kTextVAColorSize = 2 * sizeof(SkPoint) + sizeof(GrColor); |
| 53 | 53 |
| 54 }; | 54 }; |
| 55 | 55 |
| 56 GrBitmapTextContext::GrBitmapTextContext(GrContext* context, | 56 GrBitmapTextContext::GrBitmapTextContext(GrContext* context, |
| 57 const SkDeviceProperties& properties) | 57 const SkDeviceProperties& properties) |
| 58 : GrTextContext(context, properties) | 58 : GrTextContext(context, properties) { |
| 59 , fStrike(NULL) | 59 fStrike = NULL; |
| 60 , fEffectTextureUniqueID(SK_InvalidUnique
ID) | 60 |
| 61 , fVertices(NULL) | 61 fCurrTexture = NULL; |
| 62 , fVertexCount(0) | 62 fCurrVertex = 0; |
| 63 , fCurrVertex(0) { | 63 fEffectTextureUniqueID = SK_InvalidUniqueID; |
| 64 |
| 65 fVertices = NULL; |
| 66 fMaxVertices = 0; |
| 67 |
| 64 fVertexBounds.setLargestInverted(); | 68 fVertexBounds.setLargestInverted(); |
| 65 } | 69 } |
| 66 | 70 |
| 67 GrBitmapTextContext::~GrBitmapTextContext() { | 71 GrBitmapTextContext::~GrBitmapTextContext() { |
| 68 this->flushGlyphs(); | 72 this->flushGlyphs(); |
| 69 } | 73 } |
| 70 | 74 |
| 71 bool GrBitmapTextContext::canDraw(const SkPaint& paint) { | 75 bool GrBitmapTextContext::canDraw(const SkPaint& paint) { |
| 72 return !SkDraw::ShouldDrawTextAsPaths(paint, fContext->getMatrix()); | 76 return !SkDraw::ShouldDrawTextAsPaths(paint, fContext->getMatrix()); |
| 73 } | 77 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 84 return; | 88 return; |
| 85 } | 89 } |
| 86 | 90 |
| 87 GrDrawState* drawState = fDrawTarget->drawState(); | 91 GrDrawState* drawState = fDrawTarget->drawState(); |
| 88 GrDrawState::AutoRestoreEffects are(drawState); | 92 GrDrawState::AutoRestoreEffects are(drawState); |
| 89 drawState->setFromPaint(fPaint, SkMatrix::I(), fContext->getRenderTarget()); | 93 drawState->setFromPaint(fPaint, SkMatrix::I(), fContext->getRenderTarget()); |
| 90 | 94 |
| 91 if (fCurrVertex > 0) { | 95 if (fCurrVertex > 0) { |
| 92 // setup our sampler state for our text texture/atlas | 96 // setup our sampler state for our text texture/atlas |
| 93 SkASSERT(SkIsAlign4(fCurrVertex)); | 97 SkASSERT(SkIsAlign4(fCurrVertex)); |
| 98 SkASSERT(fCurrTexture); |
| 94 GrTextureParams params(SkShader::kRepeat_TileMode, GrTextureParams::kNon
e_FilterMode); | 99 GrTextureParams params(SkShader::kRepeat_TileMode, GrTextureParams::kNon
e_FilterMode); |
| 95 | 100 |
| 96 GrTexture* currTexture = fStrike->getTexture(); | 101 uint32_t textureUniqueID = fCurrTexture->getUniqueID(); |
| 97 SkASSERT(currTexture); | |
| 98 uint32_t textureUniqueID = currTexture->getUniqueID(); | |
| 99 | 102 |
| 100 if (textureUniqueID != fEffectTextureUniqueID) { | 103 if (textureUniqueID != fEffectTextureUniqueID) { |
| 101 fCachedEffect.reset(GrCustomCoordsTextureEffect::Create(currTexture,
params)); | 104 fCachedEffect.reset(GrCustomCoordsTextureEffect::Create(fCurrTexture
, params)); |
| 102 fEffectTextureUniqueID = textureUniqueID; | 105 fEffectTextureUniqueID = textureUniqueID; |
| 103 } | 106 } |
| 104 | 107 |
| 105 // This effect could be stored with one of the cache objects (atlas?) | 108 // This effect could be stored with one of the cache objects (atlas?) |
| 106 int coordsIdx = drawState->hasColorVertexAttribute() ? kGlyphCoordsWithC
olorAttributeIndex : | 109 int coordsIdx = drawState->hasColorVertexAttribute() ? kGlyphCoordsWithC
olorAttributeIndex : |
| 107 kGlyphCoordsNoCol
orAttributeIndex; | 110 kGlyphCoordsNoCol
orAttributeIndex; |
| 108 drawState->addCoverageEffect(fCachedEffect.get(), coordsIdx); | 111 drawState->addCoverageEffect(fCachedEffect.get(), coordsIdx); |
| 109 SkASSERT(NULL != fStrike); | 112 SkASSERT(NULL != fStrike); |
| 110 switch (fStrike->getMaskFormat()) { | 113 switch (fStrike->getMaskFormat()) { |
| 111 // Color bitmap text | 114 // Color bitmap text |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 SkASSERT(drawState->hasColorVertexAttribute()); | 146 SkASSERT(drawState->hasColorVertexAttribute()); |
| 144 break; | 147 break; |
| 145 default: | 148 default: |
| 146 SkFAIL("Unexepected mask format."); | 149 SkFAIL("Unexepected mask format."); |
| 147 } | 150 } |
| 148 int nGlyphs = fCurrVertex / 4; | 151 int nGlyphs = fCurrVertex / 4; |
| 149 fDrawTarget->setIndexSourceToBuffer(fContext->getQuadIndexBuffer()); | 152 fDrawTarget->setIndexSourceToBuffer(fContext->getQuadIndexBuffer()); |
| 150 fDrawTarget->drawIndexedInstances(kTriangles_GrPrimitiveType, | 153 fDrawTarget->drawIndexedInstances(kTriangles_GrPrimitiveType, |
| 151 nGlyphs, | 154 nGlyphs, |
| 152 4, 6, &fVertexBounds); | 155 4, 6, &fVertexBounds); |
| 153 fVertexCount = 0; | 156 |
| 157 fDrawTarget->resetVertexSource(); |
| 158 fVertices = NULL; |
| 159 fMaxVertices = 0; |
| 154 fCurrVertex = 0; | 160 fCurrVertex = 0; |
| 155 fVertexBounds.setLargestInverted(); | 161 fVertexBounds.setLargestInverted(); |
| 162 SkSafeSetNull(fCurrTexture); |
| 156 } | 163 } |
| 157 | |
| 158 fDrawTarget->resetVertexSource(); | |
| 159 fVertices = NULL; | |
| 160 } | 164 } |
| 161 | 165 |
| 162 inline void GrBitmapTextContext::init(const GrPaint& paint, const SkPaint& skPai
nt) { | 166 inline void GrBitmapTextContext::init(const GrPaint& paint, const SkPaint& skPai
nt) { |
| 163 GrTextContext::init(paint, skPaint); | 167 GrTextContext::init(paint, skPaint); |
| 164 | 168 |
| 165 fStrike = NULL; | 169 fStrike = NULL; |
| 166 | 170 |
| 171 fCurrTexture = NULL; |
| 172 fCurrVertex = 0; |
| 173 |
| 167 fVertices = NULL; | 174 fVertices = NULL; |
| 168 fVertexCount = 0; | 175 fMaxVertices = 0; |
| 169 fCurrVertex = 0; | |
| 170 } | 176 } |
| 171 | 177 |
| 172 inline void GrBitmapTextContext::finish() { | 178 inline void GrBitmapTextContext::finish() { |
| 173 this->flushGlyphs(); | 179 this->flushGlyphs(); |
| 174 | 180 |
| 175 GrTextContext::finish(); | 181 GrTextContext::finish(); |
| 176 } | 182 } |
| 177 | 183 |
| 178 void GrBitmapTextContext::allocateVertices(const char text[], size_t byteLength)
{ | |
| 179 SkASSERT(NULL == fVertices); | |
| 180 bool useColorVerts = kA8_GrMaskFormat == fStrike->getMaskFormat(); | |
| 181 if (useColorVerts) { | |
| 182 fDrawTarget->drawState()->setVertexAttribs<gTextVertexWithColorAttribs>( | |
| 183 SK_ARRAY_COUNT(gTextVertexWi
thColorAttribs), | |
| 184 kTextVAColorSize); | |
| 185 } else { | |
| 186 fDrawTarget->drawState()->setVertexAttribs<gTextVertexAttribs>( | |
| 187 SK_ARRAY_COUNT(gTextVertexAt
tribs), | |
| 188 kTextVASize); | |
| 189 } | |
| 190 fVertexCount = 4*fSkPaint.textToGlyphs(text, byteLength, NULL); | |
| 191 bool success = fDrawTarget->reserveVertexAndIndexSpace(fVertexCount, | |
| 192 0, | |
| 193 &fVertices, | |
| 194 NULL); | |
| 195 GrAlwaysAssert(success); | |
| 196 } | |
| 197 | |
| 198 void GrBitmapTextContext::drawText(const GrPaint& paint, const SkPaint& skPaint, | 184 void GrBitmapTextContext::drawText(const GrPaint& paint, const SkPaint& skPaint, |
| 199 const char text[], size_t byteLength, | 185 const char text[], size_t byteLength, |
| 200 SkScalar x, SkScalar y) { | 186 SkScalar x, SkScalar y) { |
| 201 SkASSERT(byteLength == 0 || text != NULL); | 187 SkASSERT(byteLength == 0 || text != NULL); |
| 202 | 188 |
| 203 // nothing to draw | 189 // nothing to draw |
| 204 if (text == NULL || byteLength == 0 /*|| fRC->isEmpty()*/) { | 190 if (text == NULL || byteLength == 0 /*|| fRC->isEmpty()*/) { |
| 205 return; | 191 return; |
| 206 } | 192 } |
| 207 | 193 |
| 208 this->init(paint, skPaint); | 194 this->init(paint, skPaint); |
| 209 | |
| 210 if (NULL == fDrawTarget) { | |
| 211 return; | |
| 212 } | |
| 213 | 195 |
| 214 SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc(); | 196 SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc(); |
| 215 | 197 |
| 216 SkAutoGlyphCache autoCache(fSkPaint, &fDeviceProperties, &fContext->getMa
trix()); | 198 SkAutoGlyphCache autoCache(fSkPaint, &fDeviceProperties, &fContext->getMa
trix()); |
| 217 SkGlyphCache* cache = autoCache.getCache(); | 199 SkGlyphCache* cache = autoCache.getCache(); |
| 218 GrFontScaler* fontScaler = GetGrFontScaler(cache); | 200 GrFontScaler* fontScaler = GetGrFontScaler(cache); |
| 219 if (NULL == fStrike) { | 201 |
| 220 fStrike = fContext->getFontCache()->getStrike(fontScaler, false); | |
| 221 } | |
| 222 | |
| 223 // transform our starting point | 202 // transform our starting point |
| 224 { | 203 { |
| 225 SkPoint loc; | 204 SkPoint loc; |
| 226 fContext->getMatrix().mapXY(x, y, &loc); | 205 fContext->getMatrix().mapXY(x, y, &loc); |
| 227 x = loc.fX; | 206 x = loc.fX; |
| 228 y = loc.fY; | 207 y = loc.fY; |
| 229 } | 208 } |
| 230 | 209 |
| 231 // need to measure first | 210 // need to measure first |
| 232 if (fSkPaint.getTextAlign() != SkPaint::kLeft_Align) { | 211 if (fSkPaint.getTextAlign() != SkPaint::kLeft_Align) { |
| 233 SkVector stop; | 212 SkVector stop; |
| 234 | 213 |
| 235 MeasureText(cache, glyphCacheProc, text, byteLength, &stop); | 214 MeasureText(cache, glyphCacheProc, text, byteLength, &stop); |
| 236 | 215 |
| 237 SkScalar stopX = stop.fX; | 216 SkScalar stopX = stop.fX; |
| 238 SkScalar stopY = stop.fY; | 217 SkScalar stopY = stop.fY; |
| 239 | 218 |
| 240 if (fSkPaint.getTextAlign() == SkPaint::kCenter_Align) { | 219 if (fSkPaint.getTextAlign() == SkPaint::kCenter_Align) { |
| 241 stopX = SkScalarHalf(stopX); | 220 stopX = SkScalarHalf(stopX); |
| 242 stopY = SkScalarHalf(stopY); | 221 stopY = SkScalarHalf(stopY); |
| 243 } | 222 } |
| 244 x -= stopX; | 223 x -= stopX; |
| 245 y -= stopY; | 224 y -= stopY; |
| 246 } | 225 } |
| 247 | 226 |
| 248 const char* stop = text + byteLength; | 227 const char* stop = text + byteLength; |
| 249 | 228 |
| 250 this->allocateVertices(text, byteLength); | 229 SkAutoKern autokern; |
| 251 | 230 |
| 252 SkFixed fxMask = ~0; | 231 SkFixed fxMask = ~0; |
| 253 SkFixed fyMask = ~0; | 232 SkFixed fyMask = ~0; |
| 254 SkFixed halfSampleX, halfSampleY; | 233 SkFixed halfSampleX, halfSampleY; |
| 255 if (cache->isSubpixel()) { | 234 if (cache->isSubpixel()) { |
| 256 halfSampleX = halfSampleY = (SK_FixedHalf >> SkGlyph::kSubBits); | 235 halfSampleX = halfSampleY = (SK_FixedHalf >> SkGlyph::kSubBits); |
| 257 SkAxisAlignment baseline = SkComputeAxisAlignmentForHText(fContext->getM
atrix()); | 236 SkAxisAlignment baseline = SkComputeAxisAlignmentForHText(fContext->getM
atrix()); |
| 258 if (kX_SkAxisAlignment == baseline) { | 237 if (kX_SkAxisAlignment == baseline) { |
| 259 fyMask = 0; | 238 fyMask = 0; |
| 260 halfSampleY = SK_FixedHalf; | 239 halfSampleY = SK_FixedHalf; |
| 261 } else if (kY_SkAxisAlignment == baseline) { | 240 } else if (kY_SkAxisAlignment == baseline) { |
| 262 fxMask = 0; | 241 fxMask = 0; |
| 263 halfSampleX = SK_FixedHalf; | 242 halfSampleX = SK_FixedHalf; |
| 264 } | 243 } |
| 265 } else { | 244 } else { |
| 266 halfSampleX = halfSampleY = SK_FixedHalf; | 245 halfSampleX = halfSampleY = SK_FixedHalf; |
| 267 } | 246 } |
| 268 | 247 |
| 269 SkFixed fx = SkScalarToFixed(x) + halfSampleX; | 248 SkFixed fx = SkScalarToFixed(x) + halfSampleX; |
| 270 SkFixed fy = SkScalarToFixed(y) + halfSampleY; | 249 SkFixed fy = SkScalarToFixed(y) + halfSampleY; |
| 271 | 250 |
| 272 GrContext::AutoMatrix autoMatrix; | 251 GrContext::AutoMatrix autoMatrix; |
| 273 autoMatrix.setIdentity(fContext, &fPaint); | 252 autoMatrix.setIdentity(fContext, &fPaint); |
| 274 | 253 |
| 275 SkAutoKern autokern; | |
| 276 while (text < stop) { | 254 while (text < stop) { |
| 277 const SkGlyph& glyph = glyphCacheProc(cache, &text, fx & fxMask, fy & fy
Mask); | 255 const SkGlyph& glyph = glyphCacheProc(cache, &text, fx & fxMask, fy & fy
Mask); |
| 278 | 256 |
| 279 fx += autokern.adjust(glyph); | 257 fx += autokern.adjust(glyph); |
| 280 | 258 |
| 281 if (glyph.fWidth) { | 259 if (glyph.fWidth) { |
| 282 this->drawPackedGlyph(GrGlyph::Pack(glyph.getGlyphID(), | 260 this->drawPackedGlyph(GrGlyph::Pack(glyph.getGlyphID(), |
| 283 glyph.getSubXFixed(), | 261 glyph.getSubXFixed(), |
| 284 glyph.getSubYFixed()), | 262 glyph.getSubYFixed()), |
| 285 SkFixedFloorToFixed(fx), | 263 SkFixedFloorToFixed(fx), |
| (...skipping 15 matching lines...) Expand all Loading... |
| 301 SkASSERT(byteLength == 0 || text != NULL); | 279 SkASSERT(byteLength == 0 || text != NULL); |
| 302 SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition); | 280 SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition); |
| 303 | 281 |
| 304 // nothing to draw | 282 // nothing to draw |
| 305 if (text == NULL || byteLength == 0/* || fRC->isEmpty()*/) { | 283 if (text == NULL || byteLength == 0/* || fRC->isEmpty()*/) { |
| 306 return; | 284 return; |
| 307 } | 285 } |
| 308 | 286 |
| 309 this->init(paint, skPaint); | 287 this->init(paint, skPaint); |
| 310 | 288 |
| 311 if (NULL == fDrawTarget) { | |
| 312 return; | |
| 313 } | |
| 314 | |
| 315 SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc(); | 289 SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc(); |
| 316 | 290 |
| 317 SkAutoGlyphCache autoCache(fSkPaint, &fDeviceProperties, &fContext->getMa
trix()); | 291 SkAutoGlyphCache autoCache(fSkPaint, &fDeviceProperties, &fContext->getMa
trix()); |
| 318 SkGlyphCache* cache = autoCache.getCache(); | 292 SkGlyphCache* cache = autoCache.getCache(); |
| 319 GrFontScaler* fontScaler = GetGrFontScaler(cache); | 293 GrFontScaler* fontScaler = GetGrFontScaler(cache); |
| 320 if (NULL == fStrike) { | |
| 321 fStrike = fContext->getFontCache()->getStrike(fontScaler, false); | |
| 322 } | |
| 323 | 294 |
| 324 // store original matrix before we reset, so we can use it to transform posi
tions | 295 // store original matrix before we reset, so we can use it to transform posi
tions |
| 325 SkMatrix ctm = fContext->getMatrix(); | 296 SkMatrix ctm = fContext->getMatrix(); |
| 326 GrContext::AutoMatrix autoMatrix; | 297 GrContext::AutoMatrix autoMatrix; |
| 327 autoMatrix.setIdentity(fContext, &fPaint); | 298 autoMatrix.setIdentity(fContext, &fPaint); |
| 328 | 299 |
| 329 this->allocateVertices(text, byteLength); | |
| 330 | |
| 331 const char* stop = text + byteLength; | 300 const char* stop = text + byteLength; |
| 332 SkTextAlignProc alignProc(fSkPaint.getTextAlign()); | 301 SkTextAlignProc alignProc(fSkPaint.getTextAlign()); |
| 333 SkTextMapStateProc tmsProc(ctm, constY, scalarsPerPosition); | 302 SkTextMapStateProc tmsProc(ctm, constY, scalarsPerPosition); |
| 334 SkFixed halfSampleX = 0, halfSampleY = 0; | 303 SkFixed halfSampleX = 0, halfSampleY = 0; |
| 335 | 304 |
| 336 if (cache->isSubpixel()) { | 305 if (cache->isSubpixel()) { |
| 337 // maybe we should skip the rounding if linearText is set | 306 // maybe we should skip the rounding if linearText is set |
| 338 SkAxisAlignment baseline = SkComputeAxisAlignmentForHText(ctm); | 307 SkAxisAlignment baseline = SkComputeAxisAlignmentForHText(ctm); |
| 339 | 308 |
| 340 SkFixed fxMask = ~0; | 309 SkFixed fxMask = ~0; |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 452 } | 421 } |
| 453 } | 422 } |
| 454 } | 423 } |
| 455 | 424 |
| 456 this->finish(); | 425 this->finish(); |
| 457 } | 426 } |
| 458 | 427 |
| 459 void GrBitmapTextContext::drawPackedGlyph(GrGlyph::PackedID packed, | 428 void GrBitmapTextContext::drawPackedGlyph(GrGlyph::PackedID packed, |
| 460 SkFixed vx, SkFixed vy, | 429 SkFixed vx, SkFixed vy, |
| 461 GrFontScaler* scaler) { | 430 GrFontScaler* scaler) { |
| 431 if (NULL == fDrawTarget) { |
| 432 return; |
| 433 } |
| 434 |
| 435 if (NULL == fStrike) { |
| 436 fStrike = fContext->getFontCache()->getStrike(scaler, false); |
| 437 } |
| 438 |
| 462 GrGlyph* glyph = fStrike->getGlyph(packed, scaler); | 439 GrGlyph* glyph = fStrike->getGlyph(packed, scaler); |
| 463 if (NULL == glyph || glyph->fBounds.isEmpty()) { | 440 if (NULL == glyph || glyph->fBounds.isEmpty()) { |
| 464 return; | 441 return; |
| 465 } | 442 } |
| 466 | 443 |
| 467 vx += SkIntToFixed(glyph->fBounds.fLeft); | 444 vx += SkIntToFixed(glyph->fBounds.fLeft); |
| 468 vy += SkIntToFixed(glyph->fBounds.fTop); | 445 vy += SkIntToFixed(glyph->fBounds.fTop); |
| 469 | 446 |
| 470 // keep them as ints until we've done the clip-test | 447 // keep them as ints until we've done the clip-test |
| 471 SkFixed width = glyph->fBounds.width(); | 448 SkFixed width = glyph->fBounds.width(); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 492 goto HAS_ATLAS; | 469 goto HAS_ATLAS; |
| 493 } | 470 } |
| 494 | 471 |
| 495 if (c_DumpFontCache) { | 472 if (c_DumpFontCache) { |
| 496 #ifdef SK_DEVELOPER | 473 #ifdef SK_DEVELOPER |
| 497 fContext->getFontCache()->dump(); | 474 fContext->getFontCache()->dump(); |
| 498 #endif | 475 #endif |
| 499 } | 476 } |
| 500 | 477 |
| 501 // flush any accumulated draws to allow us to free up a plot | 478 // flush any accumulated draws to allow us to free up a plot |
| 502 int remainingVertexCount = fVertexCount - fCurrVertex; | |
| 503 this->flushGlyphs(); | 479 this->flushGlyphs(); |
| 504 fContext->flush(); | 480 fContext->flush(); |
| 505 | 481 |
| 506 // need to reallocate the vertex buffer for the remaining glyphs | |
| 507 fVertexCount = remainingVertexCount; | |
| 508 bool success = fDrawTarget->reserveVertexAndIndexSpace(fVertexCount, | |
| 509 0, | |
| 510 &fVertices, | |
| 511 NULL); | |
| 512 GrAlwaysAssert(success); | |
| 513 | |
| 514 // we should have an unused plot now | 482 // we should have an unused plot now |
| 515 if (fContext->getFontCache()->freeUnusedPlot(fStrike) && | 483 if (fContext->getFontCache()->freeUnusedPlot(fStrike) && |
| 516 fStrike->addGlyphToAtlas(glyph, scaler)) { | 484 fStrike->addGlyphToAtlas(glyph, scaler)) { |
| 517 goto HAS_ATLAS; | 485 goto HAS_ATLAS; |
| 518 } | 486 } |
| 519 | 487 |
| 520 if (NULL == glyph->fPath) { | 488 if (NULL == glyph->fPath) { |
| 521 SkPath* path = SkNEW(SkPath); | 489 SkPath* path = SkNEW(SkPath); |
| 522 if (!scaler->getGlyphPath(glyph->glyphID(), path)) { | 490 if (!scaler->getGlyphPath(glyph->glyphID(), path)) { |
| 523 // flag the glyph as being dead? | 491 // flag the glyph as being dead? |
| (...skipping 19 matching lines...) Expand all Loading... |
| 543 GrDrawTarget::DrawToken drawToken = fDrawTarget->getCurrentDrawToken(); | 511 GrDrawTarget::DrawToken drawToken = fDrawTarget->getCurrentDrawToken(); |
| 544 glyph->fPlot->setDrawToken(drawToken); | 512 glyph->fPlot->setDrawToken(drawToken); |
| 545 | 513 |
| 546 // now promote them to fixed (TODO: Rethink using fixed pt). | 514 // now promote them to fixed (TODO: Rethink using fixed pt). |
| 547 width = SkIntToFixed(width); | 515 width = SkIntToFixed(width); |
| 548 height = SkIntToFixed(height); | 516 height = SkIntToFixed(height); |
| 549 | 517 |
| 550 GrTexture* texture = glyph->fPlot->texture(); | 518 GrTexture* texture = glyph->fPlot->texture(); |
| 551 SkASSERT(texture); | 519 SkASSERT(texture); |
| 552 | 520 |
| 521 if (fCurrTexture != texture || fCurrVertex + 4 > fMaxVertices) { |
| 522 this->flushGlyphs(); |
| 523 fCurrTexture = texture; |
| 524 fCurrTexture->ref(); |
| 525 } |
| 526 |
| 527 bool useColorVerts = kA8_GrMaskFormat == fStrike->getMaskFormat(); |
| 528 |
| 529 if (NULL == fVertices) { |
| 530 // If we need to reserve vertices allow the draw target to suggest |
| 531 // a number of verts to reserve and whether to perform a flush. |
| 532 fMaxVertices = kMinRequestedVerts; |
| 533 if (useColorVerts) { |
| 534 fDrawTarget->drawState()->setVertexAttribs<gTextVertexWithColorAttri
bs>( |
| 535 SK_ARRAY_COUNT(gTextVertexWithColorAttribs), kTextVAColorSize); |
| 536 } else { |
| 537 fDrawTarget->drawState()->setVertexAttribs<gTextVertexAttribs>( |
| 538 SK_ARRAY_COUNT(gTextVertexAttribs), kTextVASize); |
| 539 } |
| 540 bool flush = fDrawTarget->geometryHints(&fMaxVertices, NULL); |
| 541 if (flush) { |
| 542 this->flushGlyphs(); |
| 543 fContext->flush(); |
| 544 if (useColorVerts) { |
| 545 fDrawTarget->drawState()->setVertexAttribs<gTextVertexWithColorA
ttribs>( |
| 546 SK_ARRAY_COUNT(gTextVertexWithColorAttribs), kTextVAColorSiz
e); |
| 547 } else { |
| 548 fDrawTarget->drawState()->setVertexAttribs<gTextVertexAttribs>( |
| 549 SK_ARRAY_COUNT(gTextVertexAttribs), kTextVASize); |
| 550 } |
| 551 } |
| 552 fMaxVertices = kDefaultRequestedVerts; |
| 553 // ignore return, no point in flushing again. |
| 554 fDrawTarget->geometryHints(&fMaxVertices, NULL); |
| 555 |
| 556 int maxQuadVertices = 4 * fContext->getQuadIndexBuffer()->maxQuads(); |
| 557 if (fMaxVertices < kMinRequestedVerts) { |
| 558 fMaxVertices = kDefaultRequestedVerts; |
| 559 } else if (fMaxVertices > maxQuadVertices) { |
| 560 // don't exceed the limit of the index buffer |
| 561 fMaxVertices = maxQuadVertices; |
| 562 } |
| 563 bool success = fDrawTarget->reserveVertexAndIndexSpace(fMaxVertices, |
| 564 0, |
| 565 &fVertices, |
| 566 NULL); |
| 567 GrAlwaysAssert(success); |
| 568 } |
| 569 |
| 553 SkFixed tx = SkIntToFixed(glyph->fAtlasLocation.fX); | 570 SkFixed tx = SkIntToFixed(glyph->fAtlasLocation.fX); |
| 554 SkFixed ty = SkIntToFixed(glyph->fAtlasLocation.fY); | 571 SkFixed ty = SkIntToFixed(glyph->fAtlasLocation.fY); |
| 555 | 572 |
| 556 SkRect r; | 573 SkRect r; |
| 557 r.fLeft = SkFixedToFloat(vx); | 574 r.fLeft = SkFixedToFloat(vx); |
| 558 r.fTop = SkFixedToFloat(vy); | 575 r.fTop = SkFixedToFloat(vy); |
| 559 r.fRight = SkFixedToFloat(vx + width); | 576 r.fRight = SkFixedToFloat(vx + width); |
| 560 r.fBottom = SkFixedToFloat(vy + height); | 577 r.fBottom = SkFixedToFloat(vy + height); |
| 561 | 578 |
| 562 fVertexBounds.growToInclude(r); | 579 fVertexBounds.growToInclude(r); |
| 563 | 580 |
| 564 bool useColorVerts = kA8_GrMaskFormat == fStrike->getMaskFormat(); | |
| 565 size_t vertSize = useColorVerts ? (2 * sizeof(SkPoint) + sizeof(GrColor)) : | 581 size_t vertSize = useColorVerts ? (2 * sizeof(SkPoint) + sizeof(GrColor)) : |
| 566 (2 * sizeof(SkPoint)); | 582 (2 * sizeof(SkPoint)); |
| 567 | 583 |
| 568 SkASSERT(vertSize == fDrawTarget->getDrawState().getVertexStride()); | 584 SkASSERT(vertSize == fDrawTarget->getDrawState().getVertexStride()); |
| 569 | 585 |
| 570 SkPoint* positions = reinterpret_cast<SkPoint*>( | 586 SkPoint* positions = reinterpret_cast<SkPoint*>( |
| 571 reinterpret_cast<intptr_t>(fVertices) + vertSize * fCurrVertex); | 587 reinterpret_cast<intptr_t>(fVertices) + vertSize * fCurrVertex); |
| 572 positions->setRectFan(r.fLeft, r.fTop, r.fRight, r.fBottom, vertSize); | 588 positions->setRectFan(r.fLeft, r.fTop, r.fRight, r.fBottom, vertSize); |
| 573 | 589 |
| 574 // 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. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 585 } | 601 } |
| 586 // color comes after position. | 602 // color comes after position. |
| 587 GrColor* colors = reinterpret_cast<GrColor*>(positions + 1); | 603 GrColor* colors = reinterpret_cast<GrColor*>(positions + 1); |
| 588 for (int i = 0; i < 4; ++i) { | 604 for (int i = 0; i < 4; ++i) { |
| 589 *colors = fPaint.getColor(); | 605 *colors = fPaint.getColor(); |
| 590 colors = reinterpret_cast<GrColor*>(reinterpret_cast<intptr_t>(colors
) + vertSize); | 606 colors = reinterpret_cast<GrColor*>(reinterpret_cast<intptr_t>(colors
) + vertSize); |
| 591 } | 607 } |
| 592 } | 608 } |
| 593 fCurrVertex += 4; | 609 fCurrVertex += 4; |
| 594 } | 610 } |
| OLD | NEW |