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 "GrDefaultGeoProcFactory.h" | 10 #include "GrDefaultGeoProcFactory.h" |
11 #include "GrDrawTarget.h" | 11 #include "GrDrawTarget.h" |
| 12 #include "GrFontCache.h" |
12 #include "GrFontScaler.h" | 13 #include "GrFontScaler.h" |
13 #include "GrIndexBuffer.h" | 14 #include "GrIndexBuffer.h" |
14 #include "GrStrokeInfo.h" | 15 #include "GrStrokeInfo.h" |
15 #include "GrTexturePriv.h" | 16 #include "GrTexturePriv.h" |
16 #include "GrTextStrike.h" | |
17 #include "GrTextStrike_impl.h" | |
18 | 17 |
19 #include "SkAutoKern.h" | 18 #include "SkAutoKern.h" |
20 #include "SkColorPriv.h" | 19 #include "SkColorPriv.h" |
21 #include "SkDraw.h" | 20 #include "SkDraw.h" |
22 #include "SkDrawProcs.h" | 21 #include "SkDrawProcs.h" |
23 #include "SkGlyphCache.h" | 22 #include "SkGlyphCache.h" |
24 #include "SkGpuDevice.h" | 23 #include "SkGpuDevice.h" |
25 #include "SkGr.h" | 24 #include "SkGr.h" |
26 #include "SkPath.h" | 25 #include "SkPath.h" |
27 #include "SkRTConf.h" | 26 #include "SkRTConf.h" |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 void* vertices = NULL; | 351 void* vertices = NULL; |
353 bool success = drawTarget->reserveVertexAndIndexSpace(numVertices, | 352 bool success = drawTarget->reserveVertexAndIndexSpace(numVertices, |
354 get_vertex_stride(mask
Format), | 353 get_vertex_stride(mask
Format), |
355 0, | 354 0, |
356 &vertices, | 355 &vertices, |
357 NULL); | 356 NULL); |
358 GrAlwaysAssert(success); | 357 GrAlwaysAssert(success); |
359 return vertices; | 358 return vertices; |
360 } | 359 } |
361 | 360 |
| 361 inline bool GrBitmapTextContext::uploadGlyph(GrGlyph* glyph, GrFontScaler* scale
r) { |
| 362 if (!fStrike->glyphTooLargeForAtlas(glyph)) { |
| 363 if (fStrike->addGlyphToAtlas(glyph, scaler)) { |
| 364 return true; |
| 365 } |
| 366 |
| 367 // try to clear out an unused plot before we flush |
| 368 if (fContext->getFontCache()->freeUnusedPlot(fStrike, glyph) && |
| 369 fStrike->addGlyphToAtlas(glyph, scaler)) { |
| 370 return true; |
| 371 } |
| 372 |
| 373 if (c_DumpFontCache) { |
| 374 #ifdef SK_DEVELOPER |
| 375 fContext->getFontCache()->dump(); |
| 376 #endif |
| 377 } |
| 378 |
| 379 // before we purge the cache, we must flush any accumulated draws |
| 380 this->flush(); |
| 381 fContext->flush(); |
| 382 |
| 383 // we should have an unused plot now |
| 384 if (fContext->getFontCache()->freeUnusedPlot(fStrike, glyph) && |
| 385 fStrike->addGlyphToAtlas(glyph, scaler)) { |
| 386 return true; |
| 387 } |
| 388 |
| 389 // we should never get here |
| 390 SkASSERT(false); |
| 391 } |
| 392 |
| 393 return false; |
| 394 } |
| 395 |
362 void GrBitmapTextContext::appendGlyph(GrGlyph::PackedID packed, | 396 void GrBitmapTextContext::appendGlyph(GrGlyph::PackedID packed, |
363 SkFixed vx, SkFixed vy, | 397 SkFixed vx, SkFixed vy, |
364 GrFontScaler* scaler) { | 398 GrFontScaler* scaler) { |
365 if (NULL == fDrawTarget) { | 399 if (NULL == fDrawTarget) { |
366 return; | 400 return; |
367 } | 401 } |
368 | 402 |
369 if (NULL == fStrike) { | 403 if (NULL == fStrike) { |
370 fStrike = fContext->getFontCache()->getStrike(scaler, false); | 404 fStrike = fContext->getFontCache()->getStrike(scaler, false); |
371 } | 405 } |
(...skipping 13 matching lines...) Expand all Loading... |
385 // check if we clipped out | 419 // check if we clipped out |
386 if (true || NULL == glyph->fPlot) { | 420 if (true || NULL == glyph->fPlot) { |
387 int x = vx >> 16; | 421 int x = vx >> 16; |
388 int y = vy >> 16; | 422 int y = vy >> 16; |
389 if (fClipRect.quickReject(x, y, x + width, y + height)) { | 423 if (fClipRect.quickReject(x, y, x + width, y + height)) { |
390 // SkCLZ(3); // so we can set a break-point in the debugger | 424 // SkCLZ(3); // so we can set a break-point in the debugger |
391 return; | 425 return; |
392 } | 426 } |
393 } | 427 } |
394 | 428 |
395 if (NULL == glyph->fPlot) { | 429 if (NULL == glyph->fPlot && !uploadGlyph(glyph, scaler)) { |
396 if (!fStrike->glyphTooLargeForAtlas(glyph)) { | |
397 if (fStrike->addGlyphToAtlas(glyph, scaler)) { | |
398 goto HAS_ATLAS; | |
399 } | |
400 | |
401 // try to clear out an unused plot before we flush | |
402 if (fContext->getFontCache()->freeUnusedPlot(fStrike, glyph) && | |
403 fStrike->addGlyphToAtlas(glyph, scaler)) { | |
404 goto HAS_ATLAS; | |
405 } | |
406 | |
407 if (c_DumpFontCache) { | |
408 #ifdef SK_DEVELOPER | |
409 fContext->getFontCache()->dump(); | |
410 #endif | |
411 } | |
412 | |
413 // flush any accumulated draws to allow us to free up a plot | |
414 this->flush(); | |
415 fContext->flush(); | |
416 | |
417 // we should have an unused plot now | |
418 if (fContext->getFontCache()->freeUnusedPlot(fStrike, glyph) && | |
419 fStrike->addGlyphToAtlas(glyph, scaler)) { | |
420 goto HAS_ATLAS; | |
421 } | |
422 } | |
423 | |
424 if (NULL == glyph->fPath) { | 430 if (NULL == glyph->fPath) { |
425 SkPath* path = SkNEW(SkPath); | 431 SkPath* path = SkNEW(SkPath); |
426 if (!scaler->getGlyphPath(glyph->glyphID(), path)) { | 432 if (!scaler->getGlyphPath(glyph->glyphID(), path)) { |
427 // flag the glyph as being dead? | 433 // flag the glyph as being dead? |
428 delete path; | 434 delete path; |
429 return; | 435 return; |
430 } | 436 } |
431 glyph->fPath = path; | 437 glyph->fPath = path; |
432 } | 438 } |
433 | 439 |
434 // flush any accumulated draws before drawing this glyph as a path. | 440 // flush any accumulated draws before drawing this glyph as a path. |
435 this->flush(); | 441 this->flush(); |
436 | 442 |
437 GrContext::AutoMatrix am; | 443 GrContext::AutoMatrix am; |
438 SkMatrix translate; | 444 SkMatrix translate; |
439 translate.setTranslate(SkFixedToScalar(vx - SkIntToFixed(glyph->fBounds.
fLeft)), | 445 translate.setTranslate(SkFixedToScalar(vx - SkIntToFixed(glyph->fBounds.
fLeft)), |
440 SkFixedToScalar(vy - SkIntToFixed(glyph->fBounds.
fTop))); | 446 SkFixedToScalar(vy - SkIntToFixed(glyph->fBounds.
fTop))); |
441 GrPaint tmpPaint(fPaint); | 447 GrPaint tmpPaint(fPaint); |
442 am.setPreConcat(fContext, translate, &tmpPaint); | 448 am.setPreConcat(fContext, translate, &tmpPaint); |
443 GrStrokeInfo strokeInfo(SkStrokeRec::kFill_InitStyle); | 449 GrStrokeInfo strokeInfo(SkStrokeRec::kFill_InitStyle); |
444 fContext->drawPath(tmpPaint, *glyph->fPath, strokeInfo); | 450 fContext->drawPath(tmpPaint, *glyph->fPath, strokeInfo); |
445 | 451 |
446 // remove this glyph from the vertices we need to allocate | 452 // remove this glyph from the vertices we need to allocate |
447 fTotalVertexCount -= kVerticesPerGlyph; | 453 fTotalVertexCount -= kVerticesPerGlyph; |
448 return; | 454 return; |
449 } | 455 } |
450 | 456 |
451 HAS_ATLAS: | |
452 SkASSERT(glyph->fPlot); | 457 SkASSERT(glyph->fPlot); |
453 GrDrawTarget::DrawToken drawToken = fDrawTarget->getCurrentDrawToken(); | 458 GrDrawTarget::DrawToken drawToken = fDrawTarget->getCurrentDrawToken(); |
454 glyph->fPlot->setDrawToken(drawToken); | 459 glyph->fPlot->setDrawToken(drawToken); |
455 | 460 |
456 // now promote them to fixed (TODO: Rethink using fixed pt). | 461 // now promote them to fixed (TODO: Rethink using fixed pt). |
457 width = SkIntToFixed(width); | 462 width = SkIntToFixed(width); |
458 height = SkIntToFixed(height); | 463 height = SkIntToFixed(height); |
459 | 464 |
460 // the current texture/maskformat must match what the glyph needs | 465 // the current texture/maskformat must match what the glyph needs |
461 GrTexture* texture = glyph->fPlot->texture(); | 466 GrTexture* texture = glyph->fPlot->texture(); |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
612 } | 617 } |
613 } | 618 } |
614 | 619 |
615 inline void GrBitmapTextContext::finish() { | 620 inline void GrBitmapTextContext::finish() { |
616 this->flush(); | 621 this->flush(); |
617 fTotalVertexCount = 0; | 622 fTotalVertexCount = 0; |
618 | 623 |
619 GrTextContext::finish(); | 624 GrTextContext::finish(); |
620 } | 625 } |
621 | 626 |
OLD | NEW |