From: robertphillips@google.com Date: Wed, 13 Feb 2013 13:27:44 +0000 (+0000) Subject: Fix filter optimizations to take the paint's alpha into account X-Git-Tag: submit/tizen/20180928.044319~13457 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1780a3cc84b670f02d11858305598577cdea7730;p=platform%2Fupstream%2FlibSkiaSharp.git Fix filter optimizations to take the paint's alpha into account https://codereview.appspot.com/7312083/ git-svn-id: http://skia.googlecode.com/svn/trunk@7711 2bbb7eff-a529-9590-31e7-b0007b416f81 --- diff --git a/tools/filtermain.cpp b/tools/filtermain.cpp index cca96e417b..b7bbe69b93 100644 --- a/tools/filtermain.cpp +++ b/tools/filtermain.cpp @@ -58,12 +58,19 @@ static bool check_0(const SkTDArray& commands, int curCommand) { const SkPaint* saveLayerPaint = saveLayer->paint(); 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 + SkColor layerColor = saveLayerPaint->getColor() | 0xFF000000; // force opaque + return NULL == saveLayerPaint || NULL == dbmrPaint || - (is_simple(*saveLayerPaint) && - (SkColorGetR(saveLayerPaint->getColor()) == SkColorGetR(dbmrPaint->getColor())) && - (SkColorGetG(saveLayerPaint->getColor()) == SkColorGetG(dbmrPaint->getColor())) && - (SkColorGetB(saveLayerPaint->getColor()) == SkColorGetB(dbmrPaint->getColor()))); + (is_simple(*saveLayerPaint) && dbmrPaint->getColor() == layerColor); } // Fold the saveLayer's alpha into the drawBitmapRect and remove the saveLayer @@ -116,12 +123,19 @@ static bool check_1(const SkTDArray& commands, int curCommand) { const SkPaint* saveLayerPaint = saveLayer->paint(); 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 + SkColor layerColor = saveLayerPaint->getColor() | 0xFF000000; // force opaque + return NULL == saveLayerPaint || NULL == dbmrPaint || - (is_simple(*saveLayerPaint) && - (SkColorGetR(saveLayerPaint->getColor()) == SkColorGetR(dbmrPaint->getColor())) && - (SkColorGetG(saveLayerPaint->getColor()) == SkColorGetG(dbmrPaint->getColor())) && - (SkColorGetB(saveLayerPaint->getColor()) == SkColorGetB(dbmrPaint->getColor()))); + (is_simple(*saveLayerPaint) && dbmrPaint->getColor() == layerColor); } // Fold the saveLayer's alpha into the drawBitmapRect and remove the saveLayer