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

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

Issue 920333003: Revert of Use uint16s for texture coordinates when rendering text. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 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/GrAADistanceFieldPathRenderer.cpp ('k') | src/gpu/GrDistanceFieldTextContext.cpp » ('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 "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
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 = sizeof(SkPoint) + sizeof(SkIPoint16); 37 static const size_t kLCDTextVASize = 2 * sizeof(SkPoint);
38 38
39 // position + local coord 39 // position + local coord
40 static const size_t kColorTextVASize = sizeof(SkPoint) + sizeof(SkIPoint16); 40 static const size_t kColorTextVASize = 2 * sizeof(SkPoint);
41 41
42 static const size_t kGrayTextVASize = sizeof(SkPoint) + sizeof(GrColor) + sizeof (SkIPoint16); 42 static const size_t kGrayTextVASize = 2 * sizeof(SkPoint) + sizeof(GrColor);
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
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 int width = glyph->fBounds.width(); 424 SkFixed width = glyph->fBounds.width();
425 int height = glyph->fBounds.height(); 425 SkFixed 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
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
466 // the current texture/maskformat must match what the glyph needs 470 // the current texture/maskformat must match what the glyph needs
467 GrTexture* texture = glyph->fPlot->texture(); 471 GrTexture* texture = glyph->fPlot->texture();
468 SkASSERT(texture); 472 SkASSERT(texture);
469 473
470 if (fCurrTexture != texture || fCurrVertex + kVerticesPerGlyph > fAllocVerte xCount) { 474 if (fCurrTexture != texture || fCurrVertex + kVerticesPerGlyph > fAllocVerte xCount) {
471 this->flush(); 475 this->flush();
472 fCurrTexture = texture; 476 fCurrTexture = texture;
473 fCurrTexture->ref(); 477 fCurrTexture->ref();
474 fCurrMaskFormat = glyph->fMaskFormat; 478 fCurrMaskFormat = glyph->fMaskFormat;
475 } 479 }
476 480
477 if (NULL == fVertices) { 481 if (NULL == fVertices) {
478 int maxQuadVertices = kVerticesPerGlyph * fContext->getQuadIndexBuffer() ->maxQuads(); 482 int maxQuadVertices = kVerticesPerGlyph * fContext->getQuadIndexBuffer() ->maxQuads();
479 fAllocVertexCount = SkMin32(fTotalVertexCount, maxQuadVertices); 483 fAllocVertexCount = SkMin32(fTotalVertexCount, maxQuadVertices);
480 fVertices = alloc_vertices(fDrawTarget, fAllocVertexCount, fCurrMaskForm at); 484 fVertices = alloc_vertices(fDrawTarget, fAllocVertexCount, fCurrMaskForm at);
481 } 485 }
482 486
487 SkFixed tx = SkIntToFixed(glyph->fAtlasLocation.fX);
488 SkFixed ty = SkIntToFixed(glyph->fAtlasLocation.fY);
489
483 SkRect r; 490 SkRect r;
484 r.fLeft = SkFixedToFloat(vx); 491 r.fLeft = SkFixedToFloat(vx);
485 r.fTop = SkFixedToFloat(vy); 492 r.fTop = SkFixedToFloat(vy);
486 r.fRight = r.fLeft + width; 493 r.fRight = SkFixedToFloat(vx + width);
487 r.fBottom = r.fTop + height; 494 r.fBottom = SkFixedToFloat(vy + height);
488 495
489 fVertexBounds.joinNonEmptyArg(r); 496 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;
495 497
496 size_t vertSize = get_vertex_stride(fCurrMaskFormat); 498 size_t vertSize = get_vertex_stride(fCurrMaskFormat);
497 intptr_t vertex = reinterpret_cast<intptr_t>(fVertices) + vertSize * fCurrVe rtex;
498 499
499 // V0 500 SkPoint* positions = reinterpret_cast<SkPoint*>(
500 SkPoint* position = reinterpret_cast<SkPoint*>(vertex); 501 reinterpret_cast<intptr_t>(fVertices) + vertSize * fCurrVertex);
501 position->set(r.fLeft, r.fTop); 502 positions->setRectFan(r.fLeft, r.fTop, r.fRight, r.fBottom, vertSize);
503
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);
502 if (kA8_GrMaskFormat == fCurrMaskFormat) { 512 if (kA8_GrMaskFormat == fCurrMaskFormat) {
503 SkColor* color = reinterpret_cast<SkColor*>(vertex + sizeof(SkPoint)); 513 // color comes after position.
504 *color = fPaint.getColor(); 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 }
505 } 519 }
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);
542
543 fCurrVertex += 4; 520 fCurrVertex += 4;
544 } 521 }
545 522
546 void GrBitmapTextContext::flush() { 523 void GrBitmapTextContext::flush() {
547 if (NULL == fDrawTarget) { 524 if (NULL == fDrawTarget) {
548 return; 525 return;
549 } 526 }
550 527
551 if (fCurrVertex > 0) { 528 if (fCurrVertex > 0) {
552 GrPipelineBuilder pipelineBuilder; 529 GrPipelineBuilder pipelineBuilder;
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
620 } 597 }
621 } 598 }
622 599
623 inline void GrBitmapTextContext::finish() { 600 inline void GrBitmapTextContext::finish() {
624 this->flush(); 601 this->flush();
625 fTotalVertexCount = 0; 602 fTotalVertexCount = 0;
626 603
627 GrTextContext::finish(); 604 GrTextContext::finish();
628 } 605 }
629 606
OLDNEW
« no previous file with comments | « src/gpu/GrAADistanceFieldPathRenderer.cpp ('k') | src/gpu/GrDistanceFieldTextContext.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698