Add SkCodec, including PNG implementation.

DM:
Add a flag to use SkCodec instead of SkImageDecoder.

SkCodec:
Base class for codecs, allowing creation from an SkStream or an SkData.
An SkCodec, on creation, knows properties of the data like its width and height. Further calls can be used to generate the image.
TODO: Add scanline iterator

SkPngCodec:
New decoder for png. Wraps libpng. The code has been repurposed from SkImageDecoder_libpng.
TODO: Handle other destination colortypes
TODO: Substitute the transpose color
TODO: Allow silencing warnings
TODO: Use RGB instead of filler?
TODO: sRGB

SkSwizzler:
Simplified version of SkScaledSampler. Unlike the sampler, this object does no sampling.
TODO: Implement other swizzles.

Requires a gclient sync to pull down libpng.

BUG=skia:3257

Committed: https://skia.googlesource.com/skia/+/ca358852b4fed656d11107b2aaf28318a4518b49
(and then reverted)

Review URL: https://codereview.chromium.org/930283002
diff --git a/dm/DMSrcSink.cpp b/dm/DMSrcSink.cpp
index e67d435..67f8ac6 100644
--- a/dm/DMSrcSink.cpp
+++ b/dm/DMSrcSink.cpp
@@ -1,6 +1,7 @@
 #include "DMSrcSink.h"
 #include "SamplePipeControllers.h"
 #include "SkCommonFlags.h"
+#include "SkCodec.h"
 #include "SkDocument.h"
 #include "SkError.h"
 #include "SkMultiPictureDraw.h"
@@ -12,6 +13,8 @@
 #include "SkStream.h"
 #include "SkXMLWriter.h"
 
+DEFINE_bool(codec, false, "Use SkCodec instead of SkImageDecoder");
+
 namespace DM {
 
 GMSrc::GMSrc(skiagm::GMRegistry::Factory factory) : fFactory(factory) {}
@@ -46,9 +49,35 @@
     if (fDivisor == 0) {
         // Decode the full image.
         SkBitmap bitmap;
-        if (!SkImageDecoder::DecodeMemory(encoded->data(), encoded->size(), &bitmap,
-                                          dstColorType, SkImageDecoder::kDecodePixels_Mode)) {
-            return SkStringPrintf("Couldn't decode %s.", fPath.c_str());
+        if (FLAGS_codec) {
+            SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded));
+            if (!codec) {
+                return SkStringPrintf("Couldn't decode %s.", fPath.c_str());
+            }
+            SkImageInfo info;
+            if (!codec->getInfo(&info)) {
+                return SkStringPrintf("Couldn't getInfo %s.", fPath.c_str());
+            }
+            info = info.makeColorType(dstColorType);
+            if (info.alphaType() == kUnpremul_SkAlphaType) {
+                // FIXME: Currently we cannot draw unpremultiplied sources.
+                info = info.makeAlphaType(kPremul_SkAlphaType);
+            }
+            if (!bitmap.tryAllocPixels(info)) {
+                return SkStringPrintf("Image(%s) is too large (%d x %d)\n", fPath.c_str(),
+                                      info.width(), info.height());
+            }
+            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());
+            }
+        } else {
+            if (!SkImageDecoder::DecodeMemory(encoded->data(), encoded->size(), &bitmap,
+                                              dstColorType, SkImageDecoder::kDecodePixels_Mode)) {
+                return SkStringPrintf("Couldn't decode %s.", fPath.c_str());
+            }
         }
         encoded.reset((SkData*)NULL);  // Might as well drop this when we're done with it.
         canvas->drawBitmap(bitmap, 0,0);