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