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" |
(...skipping 16 matching lines...) Expand all Loading... |
27 #include "SkStrokeRec.h" | 27 #include "SkStrokeRec.h" |
28 #include "SkTextMapStateProc.h" | 28 #include "SkTextMapStateProc.h" |
29 | 29 |
30 #include "effects/GrBitmapTextGeoProc.h" | 30 #include "effects/GrBitmapTextGeoProc.h" |
31 #include "effects/GrSimpleTextureEffect.h" | 31 #include "effects/GrSimpleTextureEffect.h" |
32 | 32 |
33 SK_CONF_DECLARE(bool, c_DumpFontCache, "gpu.dumpFontCache", false, | 33 SK_CONF_DECLARE(bool, c_DumpFontCache, "gpu.dumpFontCache", false, |
34 "Dump the contents of the font cache before every purge."); | 34 "Dump the contents of the font cache before every purge."); |
35 | 35 |
36 namespace { | 36 namespace { |
37 static const size_t kLCDTextVASize = 2 * sizeof(SkPoint); | 37 static const size_t kLCDTextVASize = sizeof(SkPoint) + sizeof(SkIPoint16); |
38 | 38 |
39 // position + local coord | 39 // position + local coord |
40 static const size_t kColorTextVASize = 2 * sizeof(SkPoint); | 40 static const size_t kColorTextVASize = sizeof(SkPoint) + sizeof(SkIPoint16); |
41 | 41 |
42 static const size_t kGrayTextVASize = 2 * sizeof(SkPoint) + sizeof(GrColor); | 42 static const size_t kGrayTextVASize = sizeof(SkPoint) + sizeof(GrColor) + sizeof
(SkIPoint16); |
43 | 43 |
44 static const int kVerticesPerGlyph = 4; | 44 static const int kVerticesPerGlyph = 4; |
45 static const int kIndicesPerGlyph = 6; | 45 static const int kIndicesPerGlyph = 6; |
46 }; | 46 }; |
47 | 47 |
48 GrBitmapTextContext::GrBitmapTextContext(GrContext* context, | 48 GrBitmapTextContext::GrBitmapTextContext(GrContext* context, |
49 const SkDeviceProperties& properties) | 49 const SkDeviceProperties& properties) |
50 : GrTextContext(context, properties) { | 50 : GrTextContext(context, properties) { |
51 fStrike = NULL; | 51 fStrike = NULL; |
52 | 52 |
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 | 414 |
415 GrGlyph* glyph = fStrike->getGlyph(packed, scaler); | 415 GrGlyph* glyph = fStrike->getGlyph(packed, scaler); |
416 if (NULL == glyph || glyph->fBounds.isEmpty()) { | 416 if (NULL == glyph || glyph->fBounds.isEmpty()) { |
417 return; | 417 return; |
418 } | 418 } |
419 | 419 |
420 vx += SkIntToFixed(glyph->fBounds.fLeft); | 420 vx += SkIntToFixed(glyph->fBounds.fLeft); |
421 vy += SkIntToFixed(glyph->fBounds.fTop); | 421 vy += SkIntToFixed(glyph->fBounds.fTop); |
422 | 422 |
423 // keep them as ints until we've done the clip-test | 423 // keep them as ints until we've done the clip-test |
424 SkFixed width = glyph->fBounds.width(); | 424 int width = glyph->fBounds.width(); |
425 SkFixed height = glyph->fBounds.height(); | 425 int height = glyph->fBounds.height(); |
426 | 426 |
427 // check if we clipped out | 427 // check if we clipped out |
428 int x = vx >> 16; | 428 int x = vx >> 16; |
429 int y = vy >> 16; | 429 int y = vy >> 16; |
430 if (fClipRect.quickReject(x, y, x + width, y + height)) { | 430 if (fClipRect.quickReject(x, y, x + width, y + height)) { |
431 return; | 431 return; |
432 } | 432 } |
433 | 433 |
434 // If the glyph is too large we fall back to paths | 434 // If the glyph is too large we fall back to paths |
435 if (NULL == glyph->fPlot && !uploadGlyph(glyph, scaler)) { | 435 if (NULL == glyph->fPlot && !uploadGlyph(glyph, scaler)) { |
(...skipping 20 matching lines...) Expand all Loading... |
456 | 456 |
457 // remove this glyph from the vertices we need to allocate | 457 // remove this glyph from the vertices we need to allocate |
458 fTotalVertexCount -= kVerticesPerGlyph; | 458 fTotalVertexCount -= kVerticesPerGlyph; |
459 return; | 459 return; |
460 } | 460 } |
461 | 461 |
462 SkASSERT(glyph->fPlot); | 462 SkASSERT(glyph->fPlot); |
463 GrDrawTarget::DrawToken drawToken = fDrawTarget->getCurrentDrawToken(); | 463 GrDrawTarget::DrawToken drawToken = fDrawTarget->getCurrentDrawToken(); |
464 glyph->fPlot->setDrawToken(drawToken); | 464 glyph->fPlot->setDrawToken(drawToken); |
465 | 465 |
466 // now promote them to fixed (TODO: Rethink using fixed pt). | |
467 width = SkIntToFixed(width); | |
468 height = SkIntToFixed(height); | |
469 | |
470 // the current texture/maskformat must match what the glyph needs | 466 // the current texture/maskformat must match what the glyph needs |
471 GrTexture* texture = glyph->fPlot->texture(); | 467 GrTexture* texture = glyph->fPlot->texture(); |
472 SkASSERT(texture); | 468 SkASSERT(texture); |
473 | 469 |
474 if (fCurrTexture != texture || fCurrVertex + kVerticesPerGlyph > fAllocVerte
xCount) { | 470 if (fCurrTexture != texture || fCurrVertex + kVerticesPerGlyph > fAllocVerte
xCount) { |
475 this->flush(); | 471 this->flush(); |
476 fCurrTexture = texture; | 472 fCurrTexture = texture; |
477 fCurrTexture->ref(); | 473 fCurrTexture->ref(); |
478 fCurrMaskFormat = glyph->fMaskFormat; | 474 fCurrMaskFormat = glyph->fMaskFormat; |
479 } | 475 } |
480 | 476 |
481 if (NULL == fVertices) { | 477 if (NULL == fVertices) { |
482 int maxQuadVertices = kVerticesPerGlyph * fContext->getQuadIndexBuffer()
->maxQuads(); | 478 int maxQuadVertices = kVerticesPerGlyph * fContext->getQuadIndexBuffer()
->maxQuads(); |
483 fAllocVertexCount = SkMin32(fTotalVertexCount, maxQuadVertices); | 479 fAllocVertexCount = SkMin32(fTotalVertexCount, maxQuadVertices); |
484 fVertices = alloc_vertices(fDrawTarget, fAllocVertexCount, fCurrMaskForm
at); | 480 fVertices = alloc_vertices(fDrawTarget, fAllocVertexCount, fCurrMaskForm
at); |
485 } | 481 } |
486 | 482 |
487 SkFixed tx = SkIntToFixed(glyph->fAtlasLocation.fX); | |
488 SkFixed ty = SkIntToFixed(glyph->fAtlasLocation.fY); | |
489 | |
490 SkRect r; | 483 SkRect r; |
491 r.fLeft = SkFixedToFloat(vx); | 484 r.fLeft = SkFixedToFloat(vx); |
492 r.fTop = SkFixedToFloat(vy); | 485 r.fTop = SkFixedToFloat(vy); |
493 r.fRight = SkFixedToFloat(vx + width); | 486 r.fRight = r.fLeft + width; |
494 r.fBottom = SkFixedToFloat(vy + height); | 487 r.fBottom = r.fTop + height; |
495 | 488 |
496 fVertexBounds.joinNonEmptyArg(r); | 489 fVertexBounds.joinNonEmptyArg(r); |
| 490 |
| 491 int u0 = glyph->fAtlasLocation.fX; |
| 492 int v0 = glyph->fAtlasLocation.fY; |
| 493 int u1 = u0 + width; |
| 494 int v1 = v0 + height; |
497 | 495 |
498 size_t vertSize = get_vertex_stride(fCurrMaskFormat); | 496 size_t vertSize = get_vertex_stride(fCurrMaskFormat); |
| 497 intptr_t vertex = reinterpret_cast<intptr_t>(fVertices) + vertSize * fCurrVe
rtex; |
499 | 498 |
500 SkPoint* positions = reinterpret_cast<SkPoint*>( | 499 // V0 |
501 reinterpret_cast<intptr_t>(fVertices) + vertSize * fCurrVertex); | 500 SkPoint* position = reinterpret_cast<SkPoint*>(vertex); |
502 positions->setRectFan(r.fLeft, r.fTop, r.fRight, r.fBottom, vertSize); | 501 position->set(r.fLeft, r.fTop); |
| 502 if (kA8_GrMaskFormat == fCurrMaskFormat) { |
| 503 SkColor* color = reinterpret_cast<SkColor*>(vertex + sizeof(SkPoint)); |
| 504 *color = fPaint.getColor(); |
| 505 } |
| 506 SkIPoint16* textureCoords = reinterpret_cast<SkIPoint16*>(vertex + vertSize
- |
| 507 sizeof(SkIPoint16)
); |
| 508 textureCoords->set(u0, v0); |
| 509 vertex += vertSize; |
| 510 |
| 511 // V1 |
| 512 position = reinterpret_cast<SkPoint*>(vertex); |
| 513 position->set(r.fLeft, r.fBottom); |
| 514 if (kA8_GrMaskFormat == fCurrMaskFormat) { |
| 515 SkColor* color = reinterpret_cast<SkColor*>(vertex + sizeof(SkPoint)); |
| 516 *color = fPaint.getColor(); |
| 517 } |
| 518 textureCoords = reinterpret_cast<SkIPoint16*>(vertex + vertSize - sizeof(Sk
IPoint16)); |
| 519 textureCoords->set(u0, v1); |
| 520 vertex += vertSize; |
| 521 |
| 522 // V2 |
| 523 position = reinterpret_cast<SkPoint*>(vertex); |
| 524 position->set(r.fRight, r.fBottom); |
| 525 if (kA8_GrMaskFormat == fCurrMaskFormat) { |
| 526 SkColor* color = reinterpret_cast<SkColor*>(vertex + sizeof(SkPoint)); |
| 527 *color = fPaint.getColor(); |
| 528 } |
| 529 textureCoords = reinterpret_cast<SkIPoint16*>(vertex + vertSize - sizeof(Sk
IPoint16)); |
| 530 textureCoords->set(u1, v1); |
| 531 vertex += vertSize; |
| 532 |
| 533 // V3 |
| 534 position = reinterpret_cast<SkPoint*>(vertex); |
| 535 position->set(r.fRight, r.fTop); |
| 536 if (kA8_GrMaskFormat == fCurrMaskFormat) { |
| 537 SkColor* color = reinterpret_cast<SkColor*>(vertex + sizeof(SkPoint)); |
| 538 *color = fPaint.getColor(); |
| 539 } |
| 540 textureCoords = reinterpret_cast<SkIPoint16*>(vertex + vertSize - sizeof(Sk
IPoint16)); |
| 541 textureCoords->set(u1, v0); |
503 | 542 |
504 // The texture coords are last in both the with and without color vertex lay
outs. | |
505 SkPoint* textureCoords = reinterpret_cast<SkPoint*>( | |
506 reinterpret_cast<intptr_t>(positions) + vertSize - sizeof(SkPoint))
; | |
507 textureCoords->setRectFan(SkFixedToFloat(texture->texturePriv().normalizeFix
edX(tx)), | |
508 SkFixedToFloat(texture->texturePriv().normalizeFix
edY(ty)), | |
509 SkFixedToFloat(texture->texturePriv().normalizeFix
edX(tx + width)), | |
510 SkFixedToFloat(texture->texturePriv().normalizeFix
edY(ty + height)), | |
511 vertSize); | |
512 if (kA8_GrMaskFormat == fCurrMaskFormat) { | |
513 // color comes after position. | |
514 GrColor* colors = reinterpret_cast<GrColor*>(positions + 1); | |
515 for (int i = 0; i < 4; ++i) { | |
516 *colors = fPaint.getColor(); | |
517 colors = reinterpret_cast<GrColor*>(reinterpret_cast<intptr_t>(colors
) + vertSize); | |
518 } | |
519 } | |
520 fCurrVertex += 4; | 543 fCurrVertex += 4; |
521 } | 544 } |
522 | 545 |
523 void GrBitmapTextContext::flush() { | 546 void GrBitmapTextContext::flush() { |
524 if (NULL == fDrawTarget) { | 547 if (NULL == fDrawTarget) { |
525 return; | 548 return; |
526 } | 549 } |
527 | 550 |
528 if (fCurrVertex > 0) { | 551 if (fCurrVertex > 0) { |
529 GrPipelineBuilder pipelineBuilder; | 552 GrPipelineBuilder pipelineBuilder; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
597 } | 620 } |
598 } | 621 } |
599 | 622 |
600 inline void GrBitmapTextContext::finish() { | 623 inline void GrBitmapTextContext::finish() { |
601 this->flush(); | 624 this->flush(); |
602 fTotalVertexCount = 0; | 625 fTotalVertexCount = 0; |
603 | 626 |
604 GrTextContext::finish(); | 627 GrTextContext::finish(); |
605 } | 628 } |
606 | 629 |
OLD | NEW |