Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(139)

Side by Side Diff: src/gpu/GrDistanceFieldTextContext.cpp

Issue 917373002: Use uint16s for texture coordinates when rendering text. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Rebase to ToT Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 ? (2 * sizeof(SkPoint) + sizeof(GrColor)) : 377 return useColorVerts ? (sizeof(SkPoint) + sizeof(GrColor) + sizeof(SkIPoint1 6)) :
378 (2 * sizeof(SkPoint)); 378 (sizeof(SkPoint) + sizeof(SkIPoint16));
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
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
608 fVertexBounds.joinNonEmptyArg(glyphRect); 603 fVertexBounds.joinNonEmptyArg(glyphRect);
609 604
605 int u0 = glyph->fAtlasLocation.fX + SK_DistanceFieldInset;
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
610 size_t vertSize = get_vertex_stride(useColorVerts); 610 size_t vertSize = get_vertex_stride(useColorVerts);
611 intptr_t vertex = reinterpret_cast<intptr_t>(fVertices) + vertSize * fCurrVe rtex;
611 612
612 SkPoint* positions = reinterpret_cast<SkPoint*>( 613 // V0
613 reinterpret_cast<intptr_t>(fVertices) + vertSize * fCurrVertex); 614 SkPoint* position = reinterpret_cast<SkPoint*>(vertex);
614 positions->setRectFan(glyphRect.fLeft, glyphRect.fTop, glyphRect.fRight, gly phRect.fBottom, 615 position->set(glyphRect.fLeft, glyphRect.fTop);
615 vertSize); 616 if (useColorVerts) {
617 SkColor* color = reinterpret_cast<SkColor*>(vertex + sizeof(SkPoint));
618 *color = fPaint.getColor();
619 }
robertphillips 2015/02/13 16:10:42 overlength ?
jvanverth1 2015/02/13 19:58:56 Done.
620 SkIPoint16* textureCoords = reinterpret_cast<SkIPoint16*>(vertex + vertSize - sizeof(SkIPoint16));
621 textureCoords->set(u0, v0);
622 vertex += vertSize;
616 623
617 // The texture coords are last in both the with and without color vertex lay outs. 624 // V1
618 SkPoint* textureCoords = reinterpret_cast<SkPoint*>( 625 position = reinterpret_cast<SkPoint*>(vertex);
619 reinterpret_cast<intptr_t>(positions) + vertSize - sizeof(SkPoint)); 626 position->set(glyphRect.fLeft, glyphRect.fBottom);
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);
625 if (useColorVerts) { 627 if (useColorVerts) {
626 // color comes after position. 628 SkColor* color = reinterpret_cast<SkColor*>(vertex + sizeof(SkPoint));
627 GrColor* colors = reinterpret_cast<GrColor*>(positions + 1); 629 *color = fPaint.getColor();
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 }
632 } 630 }
631 textureCoords = reinterpret_cast<SkIPoint16*>(vertex + vertSize - sizeof(Sk IPoint16));
632 textureCoords->set(u0, v1);
633 vertex += vertSize;
634
635 // V2
636 position = reinterpret_cast<SkPoint*>(vertex);
637 position->set(glyphRect.fRight, glyphRect.fBottom);
638 if (useColorVerts) {
639 SkColor* color = reinterpret_cast<SkColor*>(vertex + sizeof(SkPoint));
640 *color = fPaint.getColor();
641 }
642 textureCoords = reinterpret_cast<SkIPoint16*>(vertex + vertSize - sizeof(Sk IPoint16));
643 textureCoords->set(u1, v1);
644 vertex += vertSize;
645
646 // V3
647 position = reinterpret_cast<SkPoint*>(vertex);
648 position->set(glyphRect.fRight, glyphRect.fTop);
649 if (useColorVerts) {
650 SkColor* color = reinterpret_cast<SkColor*>(vertex + sizeof(SkPoint));
651 *color = fPaint.getColor();
652 }
653 textureCoords = reinterpret_cast<SkIPoint16*>(vertex + vertSize - sizeof(Sk IPoint16));
654 textureCoords->set(u1, v0);
633 655
634 fCurrVertex += 4; 656 fCurrVertex += 4;
635 657
636 return true; 658 return true;
637 } 659 }
638 660
639 void GrDistanceFieldTextContext::flush() { 661 void GrDistanceFieldTextContext::flush() {
640 if (NULL == fDrawTarget) { 662 if (NULL == fDrawTarget) {
641 return; 663 return;
642 } 664 }
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
690 } 712 }
691 } 713 }
692 714
693 inline void GrDistanceFieldTextContext::finish() { 715 inline void GrDistanceFieldTextContext::finish() {
694 this->flush(); 716 this->flush();
695 fTotalVertexCount = 0; 717 fTotalVertexCount = 0;
696 718
697 GrTextContext::finish(); 719 GrTextContext::finish();
698 } 720 }
699 721
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698