Call initializeColorXform inside SkCodec

Make initializeColorXform private, and only call in the base class.
Add virtual method to skip initializeColorXform, for classes that do
not need one.

Change SkCodec::FrameInfo's SkAlphaType to an SkEncodedInfo::Alpha.
This allows proper checking internally whether SkCodec needs to do a
color correct premultiply.

Depends on https://chromium-review.googlesource.com/c/620947, for this
API change.

(Separated from review.skia.org/25746)

Bug: skia:5609
Bug: skia:6839
Change-Id: Icb0d46659c546060c34d32eaf792c86708726c7a
Reviewed-on: https://skia-review.googlesource.com/35880
Reviewed-by: Chris Blume <cblume@chromium.org>
Reviewed-by: Derek Sollenberger <djsollen@google.com>
Reviewed-by: Mike Klein <mtklein@google.com>
Commit-Queue: Leon Scroggins <scroggo@google.com>
diff --git a/tests/CodecAnimTest.cpp b/tests/CodecAnimTest.cpp
index 612a0fa..d28da08 100644
--- a/tests/CodecAnimTest.cpp
+++ b/tests/CodecAnimTest.cpp
@@ -67,8 +67,9 @@
 }
 
 DEF_TEST(Codec_frames, r) {
-    #define kOpaque         kOpaque_SkAlphaType
-    #define kUnpremul       kUnpremul_SkAlphaType
+    #define kOpaque         SkEncodedInfo::kOpaque_Alpha
+    #define kUnpremul       SkEncodedInfo::kUnpremul_Alpha
+    #define kBinary         SkEncodedInfo::kBinary_Alpha
     #define kKeep           SkCodecAnimation::DisposalMethod::kKeep
     #define kRestoreBG      SkCodecAnimation::DisposalMethod::kRestoreBGColor
     #define kRestorePrev    SkCodecAnimation::DisposalMethod::kRestorePrevious
@@ -78,8 +79,8 @@
         // One less than fFramecount, since the first frame is always
         // independent.
         std::vector<int>                              fRequiredFrames;
-        // Same, since the first frame should match getInfo.
-        std::vector<SkAlphaType>                      fAlphaTypes;
+        // Same, since the first frame should match getEncodedInfo
+        std::vector<SkEncodedInfo::Alpha>             fAlphas;
         // The size of this one should match fFrameCount for animated, empty
         // otherwise.
         std::vector<int>                              fDurations;
@@ -88,15 +89,15 @@
     } gRecs[] = {
         { "required.gif", 7,
             { 0, 1, 1, SkCodec::kNone, 4, 4 },
-            { kOpaque, kUnpremul, kUnpremul, kOpaque, kOpaque, kOpaque },
+            { kOpaque, kBinary, kBinary, kOpaque, kOpaque, kOpaque },
             { 100, 100, 100, 100, 100, 100, 100 },
             0,
             { kKeep, kRestoreBG, kKeep, kKeep, kKeep, kRestoreBG, kKeep } },
         { "alphabetAnim.gif", 13,
             { SkCodec::kNone, 0, 0, 0, 0, 5, 6, SkCodec::kNone,
               SkCodec::kNone, SkCodec::kNone, 10, 11 },
-            { kUnpremul, kUnpremul, kUnpremul, kUnpremul, kUnpremul, kUnpremul,
-              kUnpremul, kUnpremul, kUnpremul, kOpaque, kOpaque, kUnpremul },
+            { kBinary, kBinary, kBinary, kBinary, kBinary, kBinary,
+              kBinary, kBinary, kBinary, kOpaque, kOpaque, kBinary },
             { 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100 },
             0,
             { kKeep, kRestorePrev, kRestorePrev, kRestorePrev, kRestorePrev,
@@ -115,8 +116,8 @@
         { "randPixelsAnim.gif", 13,
             // required frames
             { SkCodec::kNone, 1, 2, 3, 4, 3, 6, 7, 7, 7, 9, 9 },
-            { kUnpremul, kUnpremul, kUnpremul, kUnpremul, kUnpremul, kUnpremul,
-              kUnpremul, kUnpremul, kUnpremul, kUnpremul, kUnpremul, kUnpremul },
+            { kBinary, kBinary, kBinary, kBinary, kBinary, kBinary,
+              kBinary, kBinary, kBinary, kBinary, kBinary, kBinary },
             // durations
             { 0, 1000, 170, 40, 220, 7770, 90, 90, 90, 90, 90, 90, 90 },
             // repetition count
@@ -160,6 +161,7 @@
     };
     #undef kOpaque
     #undef kUnpremul
+    #undef kBinary
     #undef kKeep
     #undef kRestorePrev
     #undef kRestoreBG
@@ -204,9 +206,9 @@
                 continue;
             }
 
-            if (rec.fAlphaTypes.size() + 1 != static_cast<size_t>(expected)) {
-                ERRORF(r, "'%s' has wrong number entries in fAlphaTypes; expected: %i\tactual: %i",
-                       rec.fName, expected - 1, rec.fAlphaTypes.size());
+            if (rec.fAlphas.size() + 1 != static_cast<size_t>(expected)) {
+                ERRORF(r, "'%s' has wrong number entries in fAlphas; expected: %i\tactual: %i",
+                       rec.fName, expected - 1, rec.fAlphas.size());
                 continue;
             }
 
@@ -268,19 +270,22 @@
                            rec.fName, i, rec.fDurations[i], frameInfo.fDuration);
                 }
 
-                auto to_string = [](SkAlphaType type) {
-                    switch (type) {
-                        case kUnpremul_SkAlphaType:
+                auto to_string = [](SkEncodedInfo::Alpha alpha) {
+                    switch (alpha) {
+                        case SkEncodedInfo::kUnpremul_Alpha:
                             return "unpremul";
-                        case kOpaque_SkAlphaType:
+                        case SkEncodedInfo::kOpaque_Alpha:
                             return "opaque";
+                        case SkEncodedInfo::kBinary_Alpha:
+                            return "binary";
                         default:
-                            return "other";
+                            SkASSERT(false);
+                            return "unknown";
                     }
                 };
 
-                auto expectedAlpha = 0 == i ? codec->getInfo().alphaType() : rec.fAlphaTypes[i-1];
-                auto alpha = frameInfo.fAlphaType;
+                auto expectedAlpha = 0 == i ? codec->getEncodedInfo().alpha() : rec.fAlphas[i-1];
+                auto alpha = frameInfo.fAlpha;
                 if (expectedAlpha != alpha) {
                     ERRORF(r, "%s's frame %i has wrong alpha type! expected: %s\tactual: %s",
                            rec.fName, i, to_string(expectedAlpha), to_string(alpha));
@@ -314,7 +319,9 @@
             auto decode = [&](SkBitmap* bm, int index, int cachedIndex) {
                 auto decodeInfo = info;
                 if (index > 0) {
-                    decodeInfo = info.makeAlphaType(frameInfos[index].fAlphaType);
+                    auto alphaType = frameInfos[index].fAlpha == SkEncodedInfo::kOpaque_Alpha
+                        ? kOpaque_SkAlphaType : kPremul_SkAlphaType;
+                    decodeInfo = info.makeAlphaType(alphaType);
                 }
                 bm->allocPixels(decodeInfo);
                 if (cachedIndex != SkCodec::kNone) {