| 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 "GrDistanceFieldTextContext.h" | 8 #include "GrDistanceFieldTextContext.h" |
| 9 #include "GrAtlas.h" | 9 #include "GrAtlas.h" |
| 10 #include "GrBitmapTextContext.h" | 10 #include "GrBitmapTextContext.h" |
| (...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 } | 367 } |
| 368 | 368 |
| 369 static inline GrColor skcolor_to_grcolor_nopremultiply(SkColor c) { | 369 static inline GrColor skcolor_to_grcolor_nopremultiply(SkColor c) { |
| 370 unsigned r = SkColorGetR(c); | 370 unsigned r = SkColorGetR(c); |
| 371 unsigned g = SkColorGetG(c); | 371 unsigned g = SkColorGetG(c); |
| 372 unsigned b = SkColorGetB(c); | 372 unsigned b = SkColorGetB(c); |
| 373 return GrColorPackRGBA(r, g, b, 0xff); | 373 return GrColorPackRGBA(r, g, b, 0xff); |
| 374 } | 374 } |
| 375 | 375 |
| 376 static size_t get_vertex_stride(bool useColorVerts) { | 376 static size_t get_vertex_stride(bool useColorVerts) { |
| 377 return useColorVerts ? (sizeof(SkPoint) + sizeof(GrColor) + sizeof(SkIPoint1
6)) : | 377 return useColorVerts ? (2 * sizeof(SkPoint) + sizeof(GrColor)) : |
| 378 (sizeof(SkPoint) + sizeof(SkIPoint16)); | 378 (2 * sizeof(SkPoint)); |
| 379 } | 379 } |
| 380 | 380 |
| 381 static void* alloc_vertices(GrDrawTarget* drawTarget, | 381 static void* alloc_vertices(GrDrawTarget* drawTarget, |
| 382 int numVertices, | 382 int numVertices, |
| 383 bool useColorVerts) { | 383 bool useColorVerts) { |
| 384 if (numVertices <= 0) { | 384 if (numVertices <= 0) { |
| 385 return NULL; | 385 return NULL; |
| 386 } | 386 } |
| 387 | 387 |
| 388 void* vertices = NULL; | 388 void* vertices = NULL; |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 593 bool useColorVerts = !fUseLCDText; | 593 bool useColorVerts = !fUseLCDText; |
| 594 | 594 |
| 595 if (NULL == fVertices) { | 595 if (NULL == fVertices) { |
| 596 int maxQuadVertices = kVerticesPerGlyph * fContext->getQuadIndexBuffer()
->maxQuads(); | 596 int maxQuadVertices = kVerticesPerGlyph * fContext->getQuadIndexBuffer()
->maxQuads(); |
| 597 fAllocVertexCount = SkMin32(fTotalVertexCount, maxQuadVertices); | 597 fAllocVertexCount = SkMin32(fTotalVertexCount, maxQuadVertices); |
| 598 fVertices = alloc_vertices(fDrawTarget, | 598 fVertices = alloc_vertices(fDrawTarget, |
| 599 fAllocVertexCount, | 599 fAllocVertexCount, |
| 600 useColorVerts); | 600 useColorVerts); |
| 601 } | 601 } |
| 602 | 602 |
| 603 SkFixed tx = SkIntToFixed(glyph->fAtlasLocation.fX + SK_DistanceFieldInset); |
| 604 SkFixed ty = SkIntToFixed(glyph->fAtlasLocation.fY + SK_DistanceFieldInset); |
| 605 SkFixed tw = SkIntToFixed(glyph->fBounds.width() - 2*SK_DistanceFieldInset); |
| 606 SkFixed th = SkIntToFixed(glyph->fBounds.height() - 2*SK_DistanceFieldInset)
; |
| 607 |
| 603 fVertexBounds.joinNonEmptyArg(glyphRect); | 608 fVertexBounds.joinNonEmptyArg(glyphRect); |
| 604 | 609 |
| 605 int u0 = glyph->fAtlasLocation.fX + SK_DistanceFieldInset; | 610 size_t vertSize = get_vertex_stride(useColorVerts); |
| 606 int v0 = glyph->fAtlasLocation.fY + SK_DistanceFieldInset; | |
| 607 int u1 = u0 + glyph->fBounds.width() - 2*SK_DistanceFieldInset; | |
| 608 int v1 = v0 + glyph->fBounds.height() - 2*SK_DistanceFieldInset; | |
| 609 | 611 |
| 610 size_t vertSize = get_vertex_stride(useColorVerts); | 612 SkPoint* positions = reinterpret_cast<SkPoint*>( |
| 611 intptr_t vertex = reinterpret_cast<intptr_t>(fVertices) + vertSize * fCurrVe
rtex; | 613 reinterpret_cast<intptr_t>(fVertices) + vertSize
* fCurrVertex); |
| 614 positions->setRectFan(glyphRect.fLeft, glyphRect.fTop, glyphRect.fRight, gly
phRect.fBottom, |
| 615 vertSize); |
| 612 | 616 |
| 613 // V0 | 617 // The texture coords are last in both the with and without color vertex lay
outs. |
| 614 SkPoint* position = reinterpret_cast<SkPoint*>(vertex); | 618 SkPoint* textureCoords = reinterpret_cast<SkPoint*>( |
| 615 position->set(glyphRect.fLeft, glyphRect.fTop); | 619 reinterpret_cast<intptr_t>(positions) + vertSize
- sizeof(SkPoint)); |
| 620 textureCoords->setRectFan(SkFixedToFloat(texture->texturePriv().normalizeFix
edX(tx)), |
| 621 SkFixedToFloat(texture->texturePriv().normalizeFix
edY(ty)), |
| 622 SkFixedToFloat(texture->texturePriv().normalizeFix
edX(tx + tw)), |
| 623 SkFixedToFloat(texture->texturePriv().normalizeFix
edY(ty + th)), |
| 624 vertSize); |
| 616 if (useColorVerts) { | 625 if (useColorVerts) { |
| 617 SkColor* color = reinterpret_cast<SkColor*>(vertex + sizeof(SkPoint)); | 626 // color comes after position. |
| 618 *color = fPaint.getColor(); | 627 GrColor* colors = reinterpret_cast<GrColor*>(positions + 1); |
| 628 for (int i = 0; i < 4; ++i) { |
| 629 *colors = fPaint.getColor(); |
| 630 colors = reinterpret_cast<GrColor*>(reinterpret_cast<intptr_t>(color
s) + vertSize); |
| 631 } |
| 619 } | 632 } |
| 620 SkIPoint16* textureCoords = reinterpret_cast<SkIPoint16*>(vertex + vertSize
- | |
| 621 sizeof(SkIPoint16)
); | |
| 622 textureCoords->set(u0, v0); | |
| 623 vertex += vertSize; | |
| 624 | |
| 625 // V1 | |
| 626 position = reinterpret_cast<SkPoint*>(vertex); | |
| 627 position->set(glyphRect.fLeft, glyphRect.fBottom); | |
| 628 if (useColorVerts) { | |
| 629 SkColor* color = reinterpret_cast<SkColor*>(vertex + sizeof(SkPoint)); | |
| 630 *color = fPaint.getColor(); | |
| 631 } | |
| 632 textureCoords = reinterpret_cast<SkIPoint16*>(vertex + vertSize - sizeof(Sk
IPoint16)); | |
| 633 textureCoords->set(u0, v1); | |
| 634 vertex += vertSize; | |
| 635 | |
| 636 // V2 | |
| 637 position = reinterpret_cast<SkPoint*>(vertex); | |
| 638 position->set(glyphRect.fRight, glyphRect.fBottom); | |
| 639 if (useColorVerts) { | |
| 640 SkColor* color = reinterpret_cast<SkColor*>(vertex + sizeof(SkPoint)); | |
| 641 *color = fPaint.getColor(); | |
| 642 } | |
| 643 textureCoords = reinterpret_cast<SkIPoint16*>(vertex + vertSize - sizeof(Sk
IPoint16)); | |
| 644 textureCoords->set(u1, v1); | |
| 645 vertex += vertSize; | |
| 646 | |
| 647 // V3 | |
| 648 position = reinterpret_cast<SkPoint*>(vertex); | |
| 649 position->set(glyphRect.fRight, glyphRect.fTop); | |
| 650 if (useColorVerts) { | |
| 651 SkColor* color = reinterpret_cast<SkColor*>(vertex + sizeof(SkPoint)); | |
| 652 *color = fPaint.getColor(); | |
| 653 } | |
| 654 textureCoords = reinterpret_cast<SkIPoint16*>(vertex + vertSize - sizeof(Sk
IPoint16)); | |
| 655 textureCoords->set(u1, v0); | |
| 656 | 633 |
| 657 fCurrVertex += 4; | 634 fCurrVertex += 4; |
| 658 | 635 |
| 659 return true; | 636 return true; |
| 660 } | 637 } |
| 661 | 638 |
| 662 void GrDistanceFieldTextContext::flush() { | 639 void GrDistanceFieldTextContext::flush() { |
| 663 if (NULL == fDrawTarget) { | 640 if (NULL == fDrawTarget) { |
| 664 return; | 641 return; |
| 665 } | 642 } |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 713 } | 690 } |
| 714 } | 691 } |
| 715 | 692 |
| 716 inline void GrDistanceFieldTextContext::finish() { | 693 inline void GrDistanceFieldTextContext::finish() { |
| 717 this->flush(); | 694 this->flush(); |
| 718 fTotalVertexCount = 0; | 695 fTotalVertexCount = 0; |
| 719 | 696 |
| 720 GrTextContext::finish(); | 697 GrTextContext::finish(); |
| 721 } | 698 } |
| 722 | 699 |
| OLD | NEW |