DM: Use the new non-fatal errors for invalid color conversions.
authorscroggo <scroggo@google.com>
Thu, 5 Mar 2015 19:46:40 +0000 (11:46 -0800)
committerCommit bot <commit-bot@chromium.org>
Thu, 5 Mar 2015 19:46:40 +0000 (11:46 -0800)
Also allow incomplete to be considered successful.

Do not attempt to draw transparent images on 565.

BUG=skia:3475

Review URL: https://codereview.chromium.org/978413002

dm/DMSrcSink.cpp

index d99f011..5ca66c5 100644 (file)
@@ -70,14 +70,27 @@ Error ImageSrc::draw(SkCanvas* canvas) const {
             SkAutoLockPixels alp(bitmap);
             const SkImageGenerator::Result result = codec->getPixels(info, bitmap.getPixels(),
                                                                      bitmap.rowBytes());
-            if (result != SkImageGenerator::kSuccess) {
-                return SkStringPrintf("Couldn't getPixels %s.", fPath.c_str());
+            switch (result) {
+                case SkImageGenerator::kSuccess:
+                // We consider incomplete to be valid, since we should still decode what is
+                // available.
+                case SkImageGenerator::kIncompleteInput:
+                    break;
+                case SkImageGenerator::kInvalidConversion:
+                    return Error::Nonfatal("Incompatible colortype conversion");
+                default:
+                    // Everything else is considered a failure.
+                    return SkStringPrintf("Couldn't getPixels %s.", fPath.c_str());
             }
         } else {
             if (!SkImageDecoder::DecodeMemory(encoded->data(), encoded->size(), &bitmap,
                                               dstColorType, SkImageDecoder::kDecodePixels_Mode)) {
                 return SkStringPrintf("Couldn't decode %s.", fPath.c_str());
             }
+            if (kRGB_565_SkColorType == dstColorType && !bitmap.isOpaque()) {
+                // Do not draw a bitmap with alpha to a destination without alpha.
+                return Error::Nonfatal("Uninteresting to decode image with alpha into 565.");
+            }
         }
         encoded.reset((SkData*)NULL);  // Might as well drop this when we're done with it.
         canvas->drawBitmap(bitmap, 0,0);
@@ -110,6 +123,15 @@ Error ImageSrc::draw(SkCanvas* canvas) const {
                 return SkStringPrintf("Could not decode subset (%d, %d, %d, %d).",
                                       x, y, x+subsetWidth, y+subsetHeight);
             }
+            if (kRGB_565_SkColorType == dstColorType && !subset.isOpaque()) {
+                // Do not draw a bitmap with alpha to a destination without alpha.
+                // This is not an error, but there is nothing interesting to show.
+
+                // This should only happen on the first iteration through the loop.
+                SkASSERT(0 == x && 0 == y);
+
+                return Error::Nonfatal("Uninteresting to decode image with alpha into 565.");
+            }
             canvas->drawBitmap(subset, SkIntToScalar(x), SkIntToScalar(y));
         }
     }