Support decoding opaque to *premul

If a client requests unpremul or premul from an opaque SkCodec,
support it. The opaque image can be treated as any of them, though
it will be less efficient to draw than if the client had used
opaque.

Change the filling code (i.e. for incomplete images) to base its color on
the source alpha type. Prior to adding the support to decode opaque to
any, it was fine to use either source or dest (which would have yielded
the same result). If the client requests non-opaque, we do not want this
to switch the fill value from black to transparent. This also allows
simplifying the signatures for getFillValue and onGetFillValue.

In CodexTest, expect the same result when decoding opaque to *premul,
and compare to the opaque version.

BUG=skia:4616
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1641273003

Review URL: https://codereview.chromium.org/1641273003
diff --git a/dm/DM.cpp b/dm/DM.cpp
index eb40113..e5a6e4d 100644
--- a/dm/DM.cpp
+++ b/dm/DM.cpp
@@ -225,7 +225,7 @@
 }
 
 static void push_codec_src(Path path, CodecSrc::Mode mode, CodecSrc::DstColorType dstColorType,
-        float scale) {
+        SkAlphaType dstAlphaType, float scale) {
     SkString folder;
     switch (mode) {
         case CodecSrc::kCodec_Mode:
@@ -259,16 +259,30 @@
             break;
     }
 
+    switch (dstAlphaType) {
+        case kOpaque_SkAlphaType:
+            folder.append("_opaque");
+            break;
+        case kPremul_SkAlphaType:
+            folder.append("_premul");
+            break;
+        case kUnpremul_SkAlphaType:
+            folder.append("_unpremul");
+            break;
+        default:
+            break;
+    }
+
     if (1.0f != scale) {
         folder.appendf("_%.3f", scale);
     }
 
-    CodecSrc* src = new CodecSrc(path, mode, dstColorType, scale);
+    CodecSrc* src = new CodecSrc(path, mode, dstColorType, dstAlphaType, scale);
     push_src("image", folder, src);
 }
 
 static void push_android_codec_src(Path path, AndroidCodecSrc::Mode mode,
-        CodecSrc::DstColorType dstColorType, int sampleSize) {
+        CodecSrc::DstColorType dstColorType, SkAlphaType dstAlphaType, int sampleSize) {
     SkString folder;
     switch (mode) {
         case AndroidCodecSrc::kFullImage_Mode:
@@ -290,11 +304,22 @@
             break;
     }
 
+    switch (dstAlphaType) {
+        case kOpaque_SkAlphaType:
+            folder.append("_opaque");
+            break;
+        case kPremul_SkAlphaType:
+            folder.append("_premul");
+            break;
+        default:
+            break;
+    }
+
     if (1 != sampleSize) {
         folder.appendf("_%.3f", 1.0f / (float) sampleSize);
     }
 
-    AndroidCodecSrc* src = new AndroidCodecSrc(path, mode, dstColorType, sampleSize);
+    AndroidCodecSrc* src = new AndroidCodecSrc(path, mode, dstColorType, dstAlphaType, sampleSize);
     push_src("image", folder, src);
 }
 
@@ -344,6 +369,13 @@
             break;
     }
 
+    SkTArray<SkAlphaType> alphaModes;
+    alphaModes.push_back(kPremul_SkAlphaType);
+    // FIXME: Currently we cannot draw unpremultiplied sources. skbug.com/3338 and skbug.com/3339
+    // alphaModes.push_back(kUnpremul_SkAlphaType);
+    if (codec->getInfo().alphaType() == kOpaque_SkAlphaType) {
+        alphaModes.push_back(kOpaque_SkAlphaType);
+    }
 
     for (CodecSrc::Mode mode : nativeModes) {
         // SkCodecImageGenerator only runs for the default colorType
@@ -353,14 +385,17 @@
         if (CodecSrc::kGen_Mode == mode) {
             // FIXME: The gpu backend does not draw kGray sources correctly. (skbug.com/4822)
             if (kGray_8_SkColorType != codec->getInfo().colorType()) {
-                push_codec_src(path, mode, CodecSrc::kGetFromCanvas_DstColorType, 1.0f);
+                push_codec_src(path, mode, CodecSrc::kGetFromCanvas_DstColorType,
+                               codec->getInfo().alphaType(), 1.0f);
             }
             continue;
         }
 
         for (float scale : nativeScales) {
             for (uint32_t i = 0; i < numColorTypes; i++) {
-                push_codec_src(path, mode, colorTypes[i], scale);
+                for (SkAlphaType alphaType : alphaModes) {
+                    push_codec_src(path, mode, colorTypes[i], alphaType, scale);
+                }
             }
         }
     }
@@ -384,11 +419,13 @@
 
     for (int sampleSize : sampleSizes) {
         for (uint32_t i = 0; i < numColorTypes; i++) {
-            push_android_codec_src(path, AndroidCodecSrc::kFullImage_Mode, colorTypes[i],
-                    sampleSize);
-            if (subset) {
-                push_android_codec_src(path, AndroidCodecSrc::kDivisor_Mode, colorTypes[i],
-                        sampleSize);
+            for (SkAlphaType alphaType : alphaModes) {
+                push_android_codec_src(path, AndroidCodecSrc::kFullImage_Mode, colorTypes[i],
+                        alphaType, sampleSize);
+                if (subset) {
+                    push_android_codec_src(path, AndroidCodecSrc::kDivisor_Mode, colorTypes[i],
+                            alphaType, sampleSize);
+                }
             }
         }
     }