More color space improvements to DM

Added P3 configs (tagged surface and SkColorSpaceXformCanvas)

Added logic to tag the output PNGs when using a xform canvas,
so the images look correct in Chrome (and work correctly with
skdiff).

We don't use the gamma_correct tag for much in gold, but only
set it for outputs with a linear transfer function.

Change-Id: Iee713682e5010b0bd3212538a6dcb201ae4e8592
Reviewed-on: https://skia-review.googlesource.com/142170
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
diff --git a/dm/DMSrcSink.cpp b/dm/DMSrcSink.cpp
index 4f139eb..d3f7ab6 100644
--- a/dm/DMSrcSink.cpp
+++ b/dm/DMSrcSink.cpp
@@ -18,6 +18,7 @@
 #include "Resources.h"
 #include "SkAndroidCodec.h"
 #include "SkAutoMalloc.h"
+#include "SkAutoPixmapStorage.h"
 #include "SkBase64.h"
 #include "SkCodec.h"
 #include "SkCodecImageGenerator.h"
@@ -2192,8 +2193,7 @@
     , fColorSpin(colorSpin) {}
 
 Error ViaCSXform::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkString* log) const {
-    return draw_to_canvas(fSink.get(), bitmap, stream, log, src.size(),
-                          [&](SkCanvas* canvas) -> Error {
+    Error err = draw_to_canvas(fSink.get(), bitmap, stream, log, src.size(), [&](SkCanvas* canvas) {
         {
             SkAutoCanvasRestore acr(canvas, true);
             auto proxy = SkCreateColorSpaceXformCanvas(canvas, fCS);
@@ -2219,8 +2219,25 @@
             canvas->drawBitmap(pixels, 0, 0, &rotateColors);
         }
 
-        return "";
+        return Error("");
     });
+
+    if (!err.isEmpty()) {
+        return err;
+    }
+
+    if (bitmap && !fColorSpin) {
+        // It should be possible to do this without all the copies, but that (I think) requires
+        // adding API to SkBitmap.
+        SkAutoPixmapStorage pmap;
+        pmap.alloc(bitmap->info());
+        bitmap->readPixels(pmap);
+        pmap.setColorSpace(fCS);
+        bitmap->allocPixels(pmap.info());
+        bitmap->writePixels(pmap);
+    }
+
+    return "";
 }
 
 }  // namespace DM