aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/codec/SkCodec.h
diff options
context:
space:
mode:
authorGravatar Leon Scroggins III <scroggo@google.com>2017-07-14 16:32:31 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-07-14 21:14:06 +0000
commit588fb040b3ad410cdb10c87f9a7884b6eb825e90 (patch)
tree954314604fe306c899e5d44417cc1019a0a078f5 /include/codec/SkCodec.h
parent0274b30feeacae0bcd12f03ae96cb4721c1393a2 (diff)
Report error on failure to create SkCodec
Update NewFromStream to report an error on failure to create an SkCodec, so that a client can distinguish between - not enough data - invalid data In Chromium, this will allow blink::ImageDecoder to call SetFailed if the stream is invalid early and we never create an SkCodec. Without this, ImageDecoder will keep trying to create an SkCodec when it receives more data. Change-Id: I4f505c56d91c982be36a828fd0f7db17b1596588 Reviewed-on: https://skia-review.googlesource.com/22642 Commit-Queue: Leon Scroggins <scroggo@google.com> Reviewed-by: Derek Sollenberger <djsollen@google.com> Reviewed-by: Chris Blume <cblume@chromium.org>
Diffstat (limited to 'include/codec/SkCodec.h')
-rw-r--r--include/codec/SkCodec.h110
1 files changed, 58 insertions, 52 deletions
diff --git a/include/codec/SkCodec.h b/include/codec/SkCodec.h
index b78ec69c74..bb780f0906 100644
--- a/include/codec/SkCodec.h
+++ b/include/codec/SkCodec.h
@@ -53,6 +53,59 @@ public:
static size_t MinBufferedBytesNeeded();
/**
+ * Error codes for various SkCodec methods.
+ */
+ enum Result {
+ /**
+ * General return value for success.
+ */
+ kSuccess,
+ /**
+ * The input is incomplete. A partial image was generated.
+ */
+ kIncompleteInput,
+ /**
+ * Like kIncompleteInput, except the input had an error.
+ *
+ * If returned from an incremental decode, decoding cannot continue,
+ * even with more data.
+ */
+ kErrorInInput,
+ /**
+ * The generator cannot convert to match the request, ignoring
+ * dimensions.
+ */
+ kInvalidConversion,
+ /**
+ * The generator cannot scale to requested size.
+ */
+ kInvalidScale,
+ /**
+ * Parameters (besides info) are invalid. e.g. NULL pixels, rowBytes
+ * too small, etc.
+ */
+ kInvalidParameters,
+ /**
+ * The input did not contain a valid image.
+ */
+ kInvalidInput,
+ /**
+ * Fulfilling this request requires rewinding the input, which is not
+ * supported for this input.
+ */
+ kCouldNotRewind,
+ /**
+ * An internal error, such as OOM.
+ */
+ kInternalError,
+ /**
+ * This method is not implemented by this codec.
+ * FIXME: Perhaps this should be kUnsupported?
+ */
+ kUnimplemented,
+ };
+
+ /**
* If this stream represents an encoded image that we know how to decode,
* return an SkCodec that can decode it. Otherwise return NULL.
*
@@ -65,6 +118,9 @@ public:
* returns zero bytes, this call will instead attempt to read(). This
* will require that the stream can be rewind()ed.
*
+ * If Result is not NULL, it will be set to either kSuccess if an SkCodec
+ * is returned or a reason for the failure if NULL is returned.
+ *
* If SkPngChunkReader is not NULL, take a ref and pass it to libpng if
* the image is a png.
*
@@ -83,7 +139,8 @@ public:
* 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 SkCodec* NewFromStream(SkStream*, SkPngChunkReader* = NULL);
+ static SkCodec* NewFromStream(SkStream*, Result* = nullptr,
+ SkPngChunkReader* = nullptr);
/**
* If this data represents an encoded image that we know how to decode,
@@ -181,57 +238,6 @@ public:
SkEncodedImageFormat getEncodedFormat() const { return this->onGetEncodedFormat(); }
/**
- * Used to describe the result of a call to getPixels().
- *
- * Result is the union of possible results from subclasses.
- */
- enum Result {
- /**
- * General return value for success.
- */
- kSuccess,
- /**
- * The input is incomplete. A partial image was generated.
- */
- kIncompleteInput,
- /**
- * Like kIncompleteInput, except the input had an error.
- *
- * If returned from an incremental decode, decoding cannot continue,
- * even with more data.
- */
- kErrorInInput,
- /**
- * The generator cannot convert to match the request, ignoring
- * dimensions.
- */
- kInvalidConversion,
- /**
- * The generator cannot scale to requested size.
- */
- kInvalidScale,
- /**
- * Parameters (besides info) are invalid. e.g. NULL pixels, rowBytes
- * too small, etc.
- */
- kInvalidParameters,
- /**
- * The input did not contain a valid image.
- */
- kInvalidInput,
- /**
- * Fulfilling this request requires rewinding the input, which is not
- * supported for this input.
- */
- kCouldNotRewind,
- /**
- * This method is not implemented by this codec.
- * FIXME: Perhaps this should be kUnsupported?
- */
- kUnimplemented,
- };
-
- /**
* Whether or not the memory passed to getPixels is zero initialized.
*/
enum ZeroInitialized {