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

Unified Diff: tools/filtermain.cpp

Issue 13394014: Expand filter 0 to handle transparent drawBitmapRect paints (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Use SkMulDiv255Round Created 7 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/filtermain.cpp
===================================================================
--- tools/filtermain.cpp (revision 8478)
+++ tools/filtermain.cpp (working copy)
@@ -61,18 +61,15 @@
SkPaint* dbmrPaint = dbmr->paint();
// For this optimization we only fold the saveLayer and drawBitmapRect
- // together if the saveLayer's draw is simple (i.e., no fancy effects) and
- // and the only difference in the colors is that the saveLayer's can have
- // an alpha while the drawBitmapRect's is opaque.
- // TODO: it should be possible to fold them together even if they both
- // have different non-255 alphas but this is low priority since we have
- // never seen that case
- // If either operation lacks a paint then the collapse is trivial
+ // together if the saveLayer's draw is simple (i.e., no fancy effects)
+ // and the only difference in the colors is their alpha value
SkColor layerColor = saveLayerPaint->getColor() | 0xFF000000; // force opaque
+ SkColor dbmrColor = dbmrPaint->getColor() | 0xFF000000; // force opaque
+ // If either operation lacks a paint then the collapse is trivial
return NULL == saveLayerPaint ||
NULL == dbmrPaint ||
- (is_simple(*saveLayerPaint) && dbmrPaint->getColor() == layerColor);
+ (is_simple(*saveLayerPaint) && dbmrColor == layerColor);
}
// Fold the saveLayer's alpha into the drawBitmapRect and remove the saveLayer
@@ -90,8 +87,17 @@
// if the DBMR doesn't have a paint just use the saveLayer's
dbmr->setPaint(*saveLayerPaint);
} else if (NULL != saveLayerPaint) {
- SkColor newColor = SkColorSetA(dbmrPaint->getColor(),
- SkColorGetA(saveLayerPaint->getColor()));
+ // Both paints are present so their alphas need to be combined
+ SkColor color = saveLayerPaint->getColor();
+ int a0 = SkColorGetA(color);
+
+ color = dbmrPaint->getColor();
+ int a1 = SkColorGetA(color);
+
+ int newA = SkMulDiv255Round(a0, a1);
+ SkASSERT(newA <= 0xFF);
+
+ SkColor newColor = SkColorSetA(color, newA);
dbmrPaint->setColor(newColor);
}
}
@@ -457,7 +463,7 @@
a1 = 0xFF;
}
- int newA = (a0 * a1) / 255;
+ int newA = SkMulDiv255Round(a0, a1);
SkASSERT(newA <= 0xFF);
SkPaint* dbmrPaint = dbmr->paint();
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698