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

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: Use float uvs for distance field paths 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
« no previous file with comments | « src/gpu/GrBitmapTextContext.cpp ('k') | src/gpu/GrFontAtlasSizes.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 fCachedGeometryProcessor.reset(GrDistanceFieldTextureEffect::Create( color, 436 fCachedGeometryProcessor.reset(GrDistanceFieldTextureEffect::Create( color,
437 fViewMatrix, 437 fViewMatrix,
438 fCurrTexture, 438 fCurrTexture,
439 params, 439 params,
440 fGammaTexture, 440 fGammaTexture,
441 gammaParams, 441 gammaParams,
442 lum/255.f, 442 lum/255.f,
443 flags, 443 flags,
444 opaque)); 444 opaque));
445 #else 445 #else
446 fCachedGeometryProcessor.reset(GrDistanceFieldNoGammaTextureEffect:: Create(color, 446 fCachedGeometryProcessor.reset(GrDistanceFieldTextureEffect::Create( color,
447 fViewMatrix, 447 fViewMatrix,
448 fCurrTexture, 448 fCurrTexture,
449 params, 449 params,
450 flags, 450 flags,
451 opaque)); 451 opaque));
452 #endif 452 #endif
453 } 453 }
454 fEffectTextureUniqueID = textureUniqueID; 454 fEffectTextureUniqueID = textureUniqueID;
455 fEffectColor = filteredColor; 455 fEffectColor = filteredColor;
456 fEffectFlags = flags; 456 fEffectFlags = flags;
457 } 457 }
458 458
459 } 459 }
460 460
461 inline bool GrDistanceFieldTextContext::uploadGlyph(GrGlyph* glyph, GrFontScaler * scaler) { 461 inline bool GrDistanceFieldTextContext::uploadGlyph(GrGlyph* glyph, GrFontScaler * scaler) {
(...skipping 131 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 }
620 SkIPoint16* textureCoords = reinterpret_cast<SkIPoint16*>(vertex + vertSize -
621 sizeof(SkIPoint16) );
622 textureCoords->set(u0, v0);
623 vertex += vertSize;
616 624
617 // The texture coords are last in both the with and without color vertex lay outs. 625 // V1
618 SkPoint* textureCoords = reinterpret_cast<SkPoint*>( 626 position = reinterpret_cast<SkPoint*>(vertex);
619 reinterpret_cast<intptr_t>(positions) + vertSize - sizeof(SkPoint)); 627 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) { 628 if (useColorVerts) {
626 // color comes after position. 629 SkColor* color = reinterpret_cast<SkColor*>(vertex + sizeof(SkPoint));
627 GrColor* colors = reinterpret_cast<GrColor*>(positions + 1); 630 *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 } 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);
633 656
634 fCurrVertex += 4; 657 fCurrVertex += 4;
635 658
636 return true; 659 return true;
637 } 660 }
638 661
639 void GrDistanceFieldTextContext::flush() { 662 void GrDistanceFieldTextContext::flush() {
640 if (NULL == fDrawTarget) { 663 if (NULL == fDrawTarget) {
641 return; 664 return;
642 } 665 }
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
690 } 713 }
691 } 714 }
692 715
693 inline void GrDistanceFieldTextContext::finish() { 716 inline void GrDistanceFieldTextContext::finish() {
694 this->flush(); 717 this->flush();
695 fTotalVertexCount = 0; 718 fTotalVertexCount = 0;
696 719
697 GrTextContext::finish(); 720 GrTextContext::finish();
698 } 721 }
699 722
OLDNEW
« no previous file with comments | « src/gpu/GrBitmapTextContext.cpp ('k') | src/gpu/GrFontAtlasSizes.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698