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

Unified Diff: src/gpu/GrBitmapTextContext.cpp

Issue 783763002: Initial CL to move color / coverage off of drawstate (Closed) Base URL: https://skia.googlesource.com/skia.git@no-static-gp
Patch Set: todo added Created 6 years 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 side-by-side diff with in-line comments
Download patch
Index: src/gpu/GrBitmapTextContext.cpp
diff --git a/src/gpu/GrBitmapTextContext.cpp b/src/gpu/GrBitmapTextContext.cpp
index e509e024377101face82f8f64a9929bb262d8fb5..92b7d7432e815a88b196419e2ea6bda264bb58d9 100755
--- a/src/gpu/GrBitmapTextContext.cpp
+++ b/src/gpu/GrBitmapTextContext.cpp
@@ -535,34 +535,15 @@ void GrBitmapTextContext::flush() {
SkASSERT(SkIsAlign4(fCurrVertex));
SkASSERT(fCurrTexture);
- // This effect could be stored with one of the cache objects (atlas?)
- GrTextureParams params(SkShader::kRepeat_TileMode, GrTextureParams::kNone_FilterMode);
- if (kARGB_GrMaskFormat == fCurrMaskFormat) {
- uint32_t flags = GrDefaultGeoProcFactory::kLocalCoord_GPType;
- drawState.setGeometryProcessor(GrDefaultGeoProcFactory::Create(flags))->unref();
- GrFragmentProcessor* fragProcessor = GrSimpleTextureEffect::Create(fCurrTexture,
- SkMatrix::I(),
- params);
- drawState.addColorProcessor(fragProcessor)->unref();
- } else {
- uint32_t textureUniqueID = fCurrTexture->getUniqueID();
- if (textureUniqueID != fEffectTextureUniqueID) {
- bool hasColor = kA8_GrMaskFormat == fCurrMaskFormat;
- fCachedGeometryProcessor.reset(GrCustomCoordsTextureEffect::Create(fCurrTexture,
- params,
- hasColor));
- fEffectTextureUniqueID = textureUniqueID;
- }
- drawState.setGeometryProcessor(fCachedGeometryProcessor.get());
- }
-
SkASSERT(fStrike);
+ GrColor color;
switch (fCurrMaskFormat) {
// Color bitmap text
- case kARGB_GrMaskFormat:
- SkASSERT(!drawState.hasColorVertexAttribute());
- drawState.setAlpha(fSkPaint.getAlpha());
+ case kARGB_GrMaskFormat: {
+ int a = fSkPaint.getAlpha();
+ color = SkColorSetARGB(a, a, a, a);
break;
+ }
// LCD text
case kA565_GrMaskFormat: {
// TODO: move supportsRGBCoverage check to setupCoverageEffect and only add LCD
@@ -571,19 +552,53 @@ void GrBitmapTextContext::flush() {
if (!drawState.getXPFactory()->supportsRGBCoverage(0, kRGBA_GrColorComponentFlags)) {
SkDebugf("LCD Text will not draw correctly.\n");
}
- SkASSERT(!drawState.hasColorVertexAttribute());
+ // We don't use the GrPaint's color in this case because it's been premultiplied by
+ // alpha. Instead we feed in a non-premultiplied color, and multiply its alpha by
+ // the mask texture color. The end result is that we get
+ // mask*paintAlpha*paintColor + (1-mask*paintAlpha)*dstColor
+ int a = SkColorGetA(fSkPaint.getColor());
+ // paintAlpha
+ color = SkColorSetARGB(a, a, a, a);
break;
}
// Grayscale/BW text
case kA8_GrMaskFormat:
drawState.setHint(GrDrawState::kVertexColorsAreOpaque_Hint,
0xFF == GrColorUnpackA(fPaint.getColor()));
- // We're using per-vertex color.
- SkASSERT(drawState.hasColorVertexAttribute());
+ color = fPaint.getColor();
break;
default:
SkFAIL("Unexpected mask format.");
}
+
+ GrTextureParams params(SkShader::kRepeat_TileMode, GrTextureParams::kNone_FilterMode);
+ // TODO cache these GPs
+ if (kARGB_GrMaskFormat == fCurrMaskFormat) {
+ uint32_t textureUniqueID = fCurrTexture->getUniqueID();
+ if (textureUniqueID != fEffectTextureUniqueID ||
+ fCachedGeometryProcessor->getColor() != color) {
+ uint32_t flags = GrDefaultGeoProcFactory::kLocalCoord_GPType;
+ fCachedGeometryProcessor.reset(GrDefaultGeoProcFactory::Create(color, flags));
+ fCachedTextureProcessor.reset(GrSimpleTextureEffect::Create(fCurrTexture,
+ SkMatrix::I(),
+ params));
+ }
+ drawState.setGeometryProcessor(fCachedGeometryProcessor.get());
+ drawState.addColorProcessor(fCachedTextureProcessor.get());
+ } else {
+ uint32_t textureUniqueID = fCurrTexture->getUniqueID();
+ if (textureUniqueID != fEffectTextureUniqueID ||
+ fCachedGeometryProcessor->getColor() != color) {
+ bool hasColor = kA8_GrMaskFormat == fCurrMaskFormat;
+ fCachedGeometryProcessor.reset(GrCustomCoordsTextureEffect::Create(color,
+ fCurrTexture,
+ params,
+ hasColor));
+ fEffectTextureUniqueID = textureUniqueID;
+ }
+ drawState.setGeometryProcessor(fCachedGeometryProcessor.get());
+ }
+
int nGlyphs = fCurrVertex / kVerticesPerGlyph;
fDrawTarget->setIndexSourceToBuffer(fContext->getQuadIndexBuffer());
fDrawTarget->drawIndexedInstances(&drawState,

Powered by Google App Engine
This is Rietveld 408576698