Moved A2B0 profile parsing before XYZ

This allows us to correctly display images with both a A2B0 tag
and *XYZ/*TRC tags, instead of ignoring the A2B0 information.

BUG=skia:

Change-Id: Icd63db5a55692ef4c5b3f098d963e7e3f583f9a4
Reviewed-on: https://skia-review.googlesource.com/5230
Commit-Queue: Robert Aftias <raftias@google.com>
Reviewed-by: Matt Sarett <msarett@google.com>
diff --git a/src/core/SkColorSpace_ICC.cpp b/src/core/SkColorSpace_ICC.cpp
index 5c5cfe0..5fe066a 100644
--- a/src/core/SkColorSpace_ICC.cpp
+++ b/src/core/SkColorSpace_ICC.cpp
@@ -1259,6 +1259,23 @@
 
     switch (header.fInputColorSpace) {
         case kRGB_ColorSpace: {
+            // Recognize color profile specified by A2B0 tag.
+            // this must be done before XYZ profile checking, as a profile can have both
+            // in which case we should use the A2B case to be accurate
+            // (XYZ is there as a fallback / quick preview)
+            const ICCTag* a2b0 = ICCTag::Find(tags.get(), tagCount, kTAG_A2B0);
+            if (a2b0) {
+                const SkColorSpace_A2B::PCS pcs = kXYZ_PCSSpace == header.fPCS
+                                                ? SkColorSpace_A2B::PCS::kXYZ
+                                                : SkColorSpace_A2B::PCS::kLAB;
+                std::vector<SkColorSpace_A2B::Element> elements;
+                if (load_a2b0(&elements, a2b0->addr(base), a2b0->fLength, pcs)) {
+                    return sk_sp<SkColorSpace>(new SkColorSpace_A2B(pcs, std::move(data),
+                                                                    std::move(elements)));
+                }
+                SkColorSpacePrintf("Ignoring malformed A2B0 tag.\n");
+            }
+
             // Recognize the rXYZ, gXYZ, and bXYZ tags.
             const ICCTag* r = ICCTag::Find(tags.get(), tagCount, kTAG_rXYZ);
             const ICCTag* g = ICCTag::Find(tags.get(), tagCount, kTAG_gXYZ);
@@ -1400,20 +1417,6 @@
 
                 return SkColorSpace_Base::MakeRGB(gammaNamed, mat);
             }
-
-            // Recognize color profile specified by A2B0 tag.
-            const ICCTag* a2b0 = ICCTag::Find(tags.get(), tagCount, kTAG_A2B0);
-            if (a2b0) {
-                const SkColorSpace_A2B::PCS pcs = kXYZ_PCSSpace == header.fPCS
-                                                ? SkColorSpace_A2B::PCS::kXYZ
-                                                : SkColorSpace_A2B::PCS::kLAB;
-                std::vector<SkColorSpace_A2B::Element> elements;
-                if (!load_a2b0(&elements, a2b0->addr(base), a2b0->fLength, pcs)) {
-                    return_null("Failed to parse A2B0 tag");
-                }
-                return sk_sp<SkColorSpace>(new SkColorSpace_A2B(pcs, std::move(data),
-                                                                std::move(elements)));
-            }
         }
         default:
             break;