Allow SkAndroidCodec to use SkPngChunkReader
authormsarett <msarett@google.com>
Wed, 2 Dec 2015 15:02:41 +0000 (07:02 -0800)
committerCommit bot <commit-bot@chromium.org>
Wed, 2 Dec 2015 15:02:41 +0000 (07:02 -0800)
Also update documentation of SkPngChunkReader
in SkCodec.

BUG=skia:

Review URL: https://codereview.chromium.org/1487583003

include/codec/SkAndroidCodec.h
include/codec/SkCodec.h
src/codec/SkAndroidCodec.cpp

index e33116f..f979886 100644 (file)
@@ -23,18 +23,24 @@ public:
      *  If this stream represents an encoded image that we know how to decode,
      *  return an SkAndroidCodec that can decode it. Otherwise return NULL.
      *
+     *  The SkPngChunkReader handles unknown chunks in PNGs.
+     *  See SkCodec.h for more details.
+     *
      *  If NULL is returned, the stream is deleted immediately. Otherwise, the
      *  SkCodec takes ownership of it, and will delete it when done with it.
      */
-    static SkAndroidCodec* NewFromStream(SkStream*);
+    static SkAndroidCodec* NewFromStream(SkStream*, SkPngChunkReader* = NULL);
 
     /**
      *  If this data represents an encoded image that we know how to decode,
      *  return an SkAndroidCodec that can decode it. Otherwise return NULL.
      *
+     *  The SkPngChunkReader handles unknown chunks in PNGs.
+     *  See SkCodec.h for more details.
+     *
      *  Will take a ref if it returns a codec, else will not affect the data.
      */
-    static SkAndroidCodec* NewFromData(SkData*);
+    static SkAndroidCodec* NewFromData(SkData*, SkPngChunkReader* = NULL);
 
     virtual ~SkAndroidCodec() {}
 
index dffab6b..9f28af0 100644 (file)
@@ -29,8 +29,17 @@ public:
      *  If this stream represents an encoded image that we know how to decode,
      *  return an SkCodec that can decode it. Otherwise return NULL.
      *
-     *  If SkPngChunkReader is not NULL, take a ref and pass it to libpng if
-     *  the image is a png.
+     *  If the SkPngChunkReader is not NULL then:
+     *      If the image is not a PNG, the SkPngChunkReader will be ignored.
+     *      If the image is a PNG, the SkPngChunkReader will be reffed.
+     *      If the PNG has unknown chunks, the SkPngChunkReader will be used
+     *      to handle these chunks.  SkPngChunkReader will be called to read
+     *      any unknown chunk at any point during the creation of the codec
+     *      or the decode.  Note that if SkPngChunkReader fails to read a
+     *      chunk, this could result in a failure to create the codec or a
+     *      failure to decode the image.
+     *      If the PNG does not contain unknown chunks, the SkPngChunkReader
+     *      will not be used or modified.
      *
      *  If NULL is returned, the stream is deleted immediately. Otherwise, the
      *  SkCodec takes ownership of it, and will delete it when done with it.
@@ -41,8 +50,17 @@ public:
      *  If this data represents an encoded image that we know how to decode,
      *  return an SkCodec that can decode it. Otherwise return NULL.
      *
-     *  If SkPngChunkReader is not NULL, take a ref and pass it to libpng if
-     *  the image is a png.
+     *  If the SkPngChunkReader is not NULL then:
+     *      If the image is not a PNG, the SkPngChunkReader will be ignored.
+     *      If the image is a PNG, the SkPngChunkReader will be reffed.
+     *      If the PNG has unknown chunks, the SkPngChunkReader will be used
+     *      to handle these chunks.  SkPngChunkReader will be called to read
+     *      any unknown chunk at any point during the creation of the codec
+     *      or the decode.  Note that if SkPngChunkReader fails to read a
+     *      chunk, this could result in a failure to create the codec or a
+     *      failure to decode the image.
+     *      If the PNG does not contain unknown chunks, the SkPngChunkReader
+     *      will not be used or modified.
      *
      *  Will take a ref if it returns a codec, else will not affect the data.
      */
index 86c0675..cf6e253 100644 (file)
@@ -20,8 +20,8 @@ SkAndroidCodec::SkAndroidCodec(const SkImageInfo& info)
     : fInfo(info)
 {}
 
-SkAndroidCodec* SkAndroidCodec::NewFromStream(SkStream* stream) {
-    SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream));
+SkAndroidCodec* SkAndroidCodec::NewFromStream(SkStream* stream, SkPngChunkReader* chunkReader) {
+    SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream, chunkReader));
     if (nullptr == codec) {
         return nullptr;
     }
@@ -43,12 +43,12 @@ SkAndroidCodec* SkAndroidCodec::NewFromStream(SkStream* stream) {
     }
 }
 
-SkAndroidCodec* SkAndroidCodec::NewFromData(SkData* data) {
+SkAndroidCodec* SkAndroidCodec::NewFromData(SkData* data, SkPngChunkReader* chunkReader) {
     if (!data) {
         return nullptr;
     }
 
-    return NewFromStream(new SkMemoryStream(data));
+    return NewFromStream(new SkMemoryStream(data), chunkReader);
 }
 
 SkISize SkAndroidCodec::getSampledDimensions(int sampleSize) const {