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

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

Issue 689923004: Use Color Processor for color bitmap text draws on gpu. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Clean up Created 6 years, 1 month 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 | « gyp/gmslides.gypi ('k') | no next file » | 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 "GrDrawTarget.h" 10 #include "GrDrawTarget.h"
11 #include "GrFontScaler.h" 11 #include "GrFontScaler.h"
12 #include "GrIndexBuffer.h" 12 #include "GrIndexBuffer.h"
13 #include "GrStrokeInfo.h" 13 #include "GrStrokeInfo.h"
14 #include "GrTexturePriv.h" 14 #include "GrTexturePriv.h"
15 #include "GrTextStrike.h" 15 #include "GrTextStrike.h"
16 #include "GrTextStrike_impl.h" 16 #include "GrTextStrike_impl.h"
17 #include "effects/GrCustomCoordsTextureEffect.h" 17 #include "effects/GrCustomCoordsTextureEffect.h"
18 #include "effects/GrSimpleTextureEffect.h"
18 19
19 #include "SkAutoKern.h" 20 #include "SkAutoKern.h"
20 #include "SkColorPriv.h" 21 #include "SkColorPriv.h"
21 #include "SkDraw.h" 22 #include "SkDraw.h"
22 #include "SkDrawProcs.h" 23 #include "SkDrawProcs.h"
23 #include "SkGlyphCache.h" 24 #include "SkGlyphCache.h"
24 #include "SkGpuDevice.h" 25 #include "SkGpuDevice.h"
25 #include "SkGr.h" 26 #include "SkGr.h"
26 #include "SkPath.h" 27 #include "SkPath.h"
27 #include "SkRTConf.h" 28 #include "SkRTConf.h"
28 #include "SkStrokeRec.h" 29 #include "SkStrokeRec.h"
29 #include "SkTextMapStateProc.h" 30 #include "SkTextMapStateProc.h"
30 31
31 SK_CONF_DECLARE(bool, c_DumpFontCache, "gpu.dumpFontCache", false, 32 SK_CONF_DECLARE(bool, c_DumpFontCache, "gpu.dumpFontCache", false,
32 "Dump the contents of the font cache before every purge."); 33 "Dump the contents of the font cache before every purge.");
33 34
34 namespace { 35 namespace {
35 // position + texture coord 36 // position + texture coord
36 extern const GrVertexAttrib gTextVertexAttribs[] = { 37 extern const GrVertexAttrib gTextVertexAttribs[] = {
37 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding }, 38 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding },
38 {kVec2f_GrVertexAttribType, sizeof(SkPoint), kGeometryProcessor_GrVertexAttr ibBinding} 39 {kVec2f_GrVertexAttribType, sizeof(SkPoint), kGeometryProcessor_GrVertexAttr ibBinding}
39 }; 40 };
40 41
41 static const size_t kTextVASize = 2 * sizeof(SkPoint); 42 static const size_t kTextVASize = 2 * sizeof(SkPoint);
43
44 // position + local coord
45 extern const GrVertexAttrib gTextVertexWithLCAttribs[] = {
bsalomon 2014/10/30 15:31:11 gBmpTextVertexAttribs?
jvanverth1 2014/10/30 18:19:43 I think it's more consistent the way it is.
egdaniel 2014/10/30 19:22:20 I'm in agreement with jim. The way the old names w
46 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding },
47 {kVec2f_GrVertexAttribType, sizeof(SkPoint), kLocalCoord_GrVertexAttribBindi ng}
48 };
49
50 static const size_t kTextVALCSize = 2 * sizeof(SkPoint);
42 51
43 // position + color + texture coord 52 // position + color + texture coord
44 extern const GrVertexAttrib gTextVertexWithColorAttribs[] = { 53 extern const GrVertexAttrib gTextVertexWithColorAttribs[] = {
45 {kVec2f_GrVertexAttribType, 0, kPosition_Gr VertexAttribBinding}, 54 {kVec2f_GrVertexAttribType, 0, kPosition_Gr VertexAttribBinding},
46 {kVec4ub_GrVertexAttribType, sizeof(SkPoint), kColor_GrVer texAttribBinding}, 55 {kVec4ub_GrVertexAttribType, sizeof(SkPoint), kColor_GrVer texAttribBinding},
47 {kVec2f_GrVertexAttribType, sizeof(SkPoint) + sizeof(GrColor), kGeometryPro cessor_GrVertexAttribBinding} 56 {kVec2f_GrVertexAttribType, sizeof(SkPoint) + sizeof(GrColor), kGeometryPro cessor_GrVertexAttribBinding}
48 }; 57 };
49 58
50 static const size_t kTextVAColorSize = 2 * sizeof(SkPoint) + sizeof(GrColor); 59 static const size_t kTextVAColorSize = 2 * sizeof(SkPoint) + sizeof(GrColor);
51 60
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 fontScaler); 347 fontScaler);
339 } 348 }
340 pos += scalarsPerPosition; 349 pos += scalarsPerPosition;
341 } 350 }
342 } 351 }
343 } 352 }
344 353
345 this->finish(); 354 this->finish();
346 } 355 }
347 356
348 static void* alloc_vertices(GrDrawTarget* drawTarget, int numVertices, bool useC olorVerts) { 357 static void* alloc_vertices(GrDrawTarget* drawTarget, int numVertices, GrMaskFor mat maskFormat) {
349 if (numVertices <= 0) { 358 if (numVertices <= 0) {
350 return NULL; 359 return NULL;
351 } 360 }
352 361
353 // set up attributes 362 // set up attributes
354 if (useColorVerts) { 363 if (kA8_GrMaskFormat == maskFormat) {
355 drawTarget->drawState()->setVertexAttribs<gTextVertexWithColorAttribs>( 364 drawTarget->drawState()->setVertexAttribs<gTextVertexWithColorAttribs>(
356 SK_ARRAY_COUNT(gTextVertexWithColorAttribs), kTextVAColorSize); 365 SK_ARRAY_COUNT(gTextVertexWithColorAttribs), kTextVAColorSize);
366 } else if (kARGB_GrMaskFormat == maskFormat) {
367 drawTarget->drawState()->setVertexAttribs<gTextVertexWithLCAttribs>(
368 SK_ARRAY_COUNT(gTextVertexWithLCAttribs), kT extVALCSize);
357 } else { 369 } else {
358 drawTarget->drawState()->setVertexAttribs<gTextVertexAttribs>( 370 drawTarget->drawState()->setVertexAttribs<gTextVertexAttribs>(
359 SK_ARRAY_COUNT(gTextVertexAttribs), kTextVAS ize); 371 SK_ARRAY_COUNT(gTextVertexAttribs), kTextVAS ize);
360 } 372 }
361 void* vertices = NULL; 373 void* vertices = NULL;
362 bool success = drawTarget->reserveVertexAndIndexSpace(numVertices, 374 bool success = drawTarget->reserveVertexAndIndexSpace(numVertices,
363 0, 375 0,
364 &vertices, 376 &vertices,
365 NULL); 377 NULL);
366 GrAlwaysAssert(success); 378 GrAlwaysAssert(success);
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 GrTexture* texture = glyph->fPlot->texture(); 481 GrTexture* texture = glyph->fPlot->texture();
470 SkASSERT(texture); 482 SkASSERT(texture);
471 483
472 if (fCurrTexture != texture || fCurrVertex + kVerticesPerGlyph > fAllocVerte xCount) { 484 if (fCurrTexture != texture || fCurrVertex + kVerticesPerGlyph > fAllocVerte xCount) {
473 this->flush(); 485 this->flush();
474 fCurrTexture = texture; 486 fCurrTexture = texture;
475 fCurrTexture->ref(); 487 fCurrTexture->ref();
476 fCurrMaskFormat = glyph->fMaskFormat; 488 fCurrMaskFormat = glyph->fMaskFormat;
477 } 489 }
478 490
479 bool useColorVerts = kA8_GrMaskFormat == fCurrMaskFormat;
480
481 if (NULL == fVertices) { 491 if (NULL == fVertices) {
482 int maxQuadVertices = kVerticesPerGlyph * fContext->getQuadIndexBuffer() ->maxQuads(); 492 int maxQuadVertices = kVerticesPerGlyph * fContext->getQuadIndexBuffer() ->maxQuads();
483 fAllocVertexCount = SkMin32(fTotalVertexCount, maxQuadVertices); 493 fAllocVertexCount = SkMin32(fTotalVertexCount, maxQuadVertices);
484 fVertices = alloc_vertices(fDrawTarget, fAllocVertexCount, useColorVerts ); 494 fVertices = alloc_vertices(fDrawTarget, fAllocVertexCount, fCurrMaskForm at);
485 } 495 }
486 496
487 SkFixed tx = SkIntToFixed(glyph->fAtlasLocation.fX); 497 SkFixed tx = SkIntToFixed(glyph->fAtlasLocation.fX);
488 SkFixed ty = SkIntToFixed(glyph->fAtlasLocation.fY); 498 SkFixed ty = SkIntToFixed(glyph->fAtlasLocation.fY);
489 499
490 SkRect r; 500 SkRect r;
491 r.fLeft = SkFixedToFloat(vx); 501 r.fLeft = SkFixedToFloat(vx);
492 r.fTop = SkFixedToFloat(vy); 502 r.fTop = SkFixedToFloat(vy);
493 r.fRight = SkFixedToFloat(vx + width); 503 r.fRight = SkFixedToFloat(vx + width);
494 r.fBottom = SkFixedToFloat(vy + height); 504 r.fBottom = SkFixedToFloat(vy + height);
495 505
496 fVertexBounds.joinNonEmptyArg(r); 506 fVertexBounds.joinNonEmptyArg(r);
497 507
498 size_t vertSize = useColorVerts ? (2 * sizeof(SkPoint) + sizeof(GrColor)) : 508 size_t vertSize;
499 (2 * sizeof(SkPoint)); 509 switch (fCurrMaskFormat) {
510 case kA8_GrMaskFormat:
511 vertSize = kTextVAColorSize;
512 break;
513 case kARGB_GrMaskFormat:
514 vertSize = kTextVALCSize;
515 default:
516 vertSize = kTextVASize;
517 }
500 518
501 SkASSERT(vertSize == fDrawTarget->getDrawState().getVertexStride()); 519 SkASSERT(vertSize == fDrawTarget->getDrawState().getVertexStride());
502 520
503 SkPoint* positions = reinterpret_cast<SkPoint*>( 521 SkPoint* positions = reinterpret_cast<SkPoint*>(
504 reinterpret_cast<intptr_t>(fVertices) + vertSize * fCurrVertex); 522 reinterpret_cast<intptr_t>(fVertices) + vertSize * fCurrVertex);
505 positions->setRectFan(r.fLeft, r.fTop, r.fRight, r.fBottom, vertSize); 523 positions->setRectFan(r.fLeft, r.fTop, r.fRight, r.fBottom, vertSize);
506 524
507 // The texture coords are last in both the with and without color vertex lay outs. 525 // The texture coords are last in both the with and without color vertex lay outs.
508 SkPoint* textureCoords = reinterpret_cast<SkPoint*>( 526 SkPoint* textureCoords = reinterpret_cast<SkPoint*>(
509 reinterpret_cast<intptr_t>(positions) + vertSize - sizeof(SkPoint)) ; 527 reinterpret_cast<intptr_t>(positions) + vertSize - sizeof(SkPoint)) ;
510 textureCoords->setRectFan(SkFixedToFloat(texture->texturePriv().normalizeFix edX(tx)), 528 textureCoords->setRectFan(SkFixedToFloat(texture->texturePriv().normalizeFix edX(tx)),
511 SkFixedToFloat(texture->texturePriv().normalizeFix edY(ty)), 529 SkFixedToFloat(texture->texturePriv().normalizeFix edY(ty)),
512 SkFixedToFloat(texture->texturePriv().normalizeFix edX(tx + width)), 530 SkFixedToFloat(texture->texturePriv().normalizeFix edX(tx + width)),
513 SkFixedToFloat(texture->texturePriv().normalizeFix edY(ty + height)), 531 SkFixedToFloat(texture->texturePriv().normalizeFix edY(ty + height)),
514 vertSize); 532 vertSize);
515 if (useColorVerts) { 533 if (kA8_GrMaskFormat == fCurrMaskFormat) {
516 if (0xFF == GrColorUnpackA(fPaint.getColor())) { 534 if (0xFF == GrColorUnpackA(fPaint.getColor())) {
517 fDrawTarget->drawState()->setHint(GrDrawState::kVertexColorsAreOpaqu e_Hint, true); 535 fDrawTarget->drawState()->setHint(GrDrawState::kVertexColorsAreOpaqu e_Hint, true);
518 } 536 }
519 // color comes after position. 537 // color comes after position.
520 GrColor* colors = reinterpret_cast<GrColor*>(positions + 1); 538 GrColor* colors = reinterpret_cast<GrColor*>(positions + 1);
521 for (int i = 0; i < 4; ++i) { 539 for (int i = 0; i < 4; ++i) {
522 *colors = fPaint.getColor(); 540 *colors = fPaint.getColor();
523 colors = reinterpret_cast<GrColor*>(reinterpret_cast<intptr_t>(colors ) + vertSize); 541 colors = reinterpret_cast<GrColor*>(reinterpret_cast<intptr_t>(colors ) + vertSize);
524 } 542 }
525 } 543 }
(...skipping 15 matching lines...) Expand all
541 GrDrawState* drawState = fDrawTarget->drawState(); 559 GrDrawState* drawState = fDrawTarget->drawState();
542 GrDrawState::AutoRestoreEffects are(drawState); 560 GrDrawState::AutoRestoreEffects are(drawState);
543 drawState->setFromPaint(fPaint, SkMatrix::I(), fContext->getRenderTarget()); 561 drawState->setFromPaint(fPaint, SkMatrix::I(), fContext->getRenderTarget());
544 562
545 if (fCurrVertex > 0) { 563 if (fCurrVertex > 0) {
546 // setup our sampler state for our text texture/atlas 564 // setup our sampler state for our text texture/atlas
547 SkASSERT(SkIsAlign4(fCurrVertex)); 565 SkASSERT(SkIsAlign4(fCurrVertex));
548 SkASSERT(fCurrTexture); 566 SkASSERT(fCurrTexture);
549 GrTextureParams params(SkShader::kRepeat_TileMode, GrTextureParams::kNon e_FilterMode); 567 GrTextureParams params(SkShader::kRepeat_TileMode, GrTextureParams::kNon e_FilterMode);
550 568
551 uint32_t textureUniqueID = fCurrTexture->getUniqueID(); 569 // This effect could be stored with one of the cache objects (atlas?)
570 if (kARGB_GrMaskFormat != fCurrMaskFormat) {
bsalomon 2014/10/30 15:31:11 Switch the sense of this? Seems easier to read i
571 uint32_t textureUniqueID = fCurrTexture->getUniqueID();
572 if (textureUniqueID != fEffectTextureUniqueID) {
573 fCachedGeometryProcessor.reset(GrCustomCoordsTextureEffect::Crea te(fCurrTexture,
574 params));
575 fEffectTextureUniqueID = textureUniqueID;
576 }
552 577
553 if (textureUniqueID != fEffectTextureUniqueID) { 578 drawState->setGeometryProcessor(fCachedGeometryProcessor.get());
554 fCachedGeometryProcessor.reset(GrCustomCoordsTextureEffect::Create(f CurrTexture, 579 } else {
555 p arams)); 580 SkMatrix matrix;
556 fEffectTextureUniqueID = textureUniqueID; 581 matrix.reset();
582 GrFragmentProcessor* fragProcessor = GrSimpleTextureEffect::Create(f CurrTexture,
583 m atrix,
jvanverth1 2014/10/30 18:19:42 I think you can use SkMatrix::I() instead of havin
584 p arams);
585 drawState->addColorProcessor(fragProcessor)->unref();
557 } 586 }
558 587
559 // This effect could be stored with one of the cache objects (atlas?)
560 drawState->setGeometryProcessor(fCachedGeometryProcessor.get());
561 SkASSERT(fStrike); 588 SkASSERT(fStrike);
562 switch (fCurrMaskFormat) { 589 switch (fCurrMaskFormat) {
563 // Color bitmap text 590 // Color bitmap text
564 case kARGB_GrMaskFormat: 591 case kARGB_GrMaskFormat:
565 SkASSERT(!drawState->hasColorVertexAttribute()); 592 SkASSERT(!drawState->hasColorVertexAttribute());
566 drawState->setBlendFunc(fPaint.getSrcBlendCoeff(), fPaint.getDst BlendCoeff()); 593 drawState->setBlendFunc(fPaint.getSrcBlendCoeff(), fPaint.getDst BlendCoeff());
567 drawState->setAlpha(fSkPaint.getAlpha()); 594 drawState->setAlpha(fSkPaint.getAlpha());
568 break; 595 break;
569 // LCD text 596 // LCD text
570 case kA888_GrMaskFormat: 597 case kA888_GrMaskFormat:
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
614 } 641 }
615 } 642 }
616 643
617 inline void GrBitmapTextContext::finish() { 644 inline void GrBitmapTextContext::finish() {
618 this->flush(); 645 this->flush();
619 fTotalVertexCount = 0; 646 fTotalVertexCount = 0;
620 647
621 GrTextContext::finish(); 648 GrTextContext::finish();
622 } 649 }
623 650
OLDNEW
« no previous file with comments | « gyp/gmslides.gypi ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698