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