aboutsummaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorGravatar scroggo <scroggo@chromium.org>2015-07-10 12:07:02 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-07-10 12:07:02 -0700
commit9b2cdbf4811477487f107a78edc130c733b309ea (patch)
treee3ba5000eb9c2ce6f2e2c07e2fc76d6178b2a672 /include
parentf9c5db26b401dcff83d39275ba78c36360cd6dc1 (diff)
Allow creating multiple scanline decoders.
Make getScanlineDecoder return a new object each time, which is owned by the caller, and independent from any existing scanline decoders and the SkCodec itself. Since the SkCodec already contains the entire state machine, and it is used by the scanline decoders, simply create a new SkCodec which is now owned by the scanline decoder. Move code that cleans up after using a scanline decoder into its destructor One side effect is that creating the first scanline decoder requires a duplication of the stream and re-reading the header. (With some more complexity/changes, we could pass the state machine to the scanline decoder and make the SkCodec recreate its own state machine instead.) The typical client of the scanline decoder (region decoder) uses an SkMemoryStream, so the duplication is cheap, although we should consider the extra time to reread the header/recreate the state machine. (If/when we use the scanline decoder for other purposes, where the stream may not be cheaply duplicated, we should consider passing the state machine.) One (intended) result of this change is that a client can create a new scanline decoder in a new thread, and decode different pieces of the image simultaneously. In SkPngCodec::decodePalette, use fBitDepth rather than a parameter. Review URL: https://codereview.chromium.org/1230033004
Diffstat (limited to 'include')
-rw-r--r--include/codec/SkCodec.h47
-rw-r--r--include/codec/SkScanlineDecoder.h7
2 files changed, 7 insertions, 47 deletions
diff --git a/include/codec/SkCodec.h b/include/codec/SkCodec.h
index 54bd6ff5d6..cc635e012c 100644
--- a/include/codec/SkCodec.h
+++ b/include/codec/SkCodec.h
@@ -172,15 +172,11 @@ public:
Result getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes);
/**
- * Return an object which can be used to decode individual scanlines.
+ * Create a new object which can be used to decode individual scanlines.
*
- * This object is owned by the SkCodec, which will handle its lifetime. The
- * returned object is only valid until the SkCodec is deleted or the next
- * call to getScanlineDecoder, whichever comes first.
- *
- * Calling a second time will rewind and replace the existing one with a
- * new one. If the stream cannot be rewound, this will delete the existing
- * one and return NULL.
+ * The returned object has its own state, independent of the SkCodec, or any
+ * previously spawned SkScanlineDecoders. At creation, it will be ready to
+ * return the first scanline.
*
* @param dstInfo Info of the destination. If the dimensions do not match
* those of getInfo, this implies a scale.
@@ -195,11 +191,7 @@ public:
* decoding the palette.
* @return New SkScanlineDecoder, or NULL on failure.
*
- * NOTE: If any rows were previously decoded, this requires rewinding the
- * SkStream.
- *
- * NOTE: The scanline decoder is owned by the SkCodec and will delete it
- * when the SkCodec is deleted.
+ * NOTE: This requires duplicating the SkStream.
*/
SkScanlineDecoder* getScanlineDecoder(const SkImageInfo& dstInfo, const Options* options,
SkPMColor ctable[], int* ctableCount);
@@ -239,9 +231,6 @@ protected:
/**
* Override if your codec supports scanline decoding.
*
- * As in onGetPixels(), the implementation must call rewindIfNeeded() and
- * handle as appropriate.
- *
* @param dstInfo Info of the destination. If the dimensions do not match
* those of getInfo, this implies a scale.
* @param options Contains decoding options, including if memory is zero
@@ -253,8 +242,8 @@ protected:
* dstInfo.colorType() is kIndex8, this should be non-NULL. It will
* be modified to the true size of the color table (<= 256) after
* decoding the palette.
- * @return New SkScanlineDecoder on success, NULL otherwise. The SkCodec
- * will take ownership of the returned scanline decoder.
+ * @return New SkScanlineDecoder on success, NULL otherwise. The caller is
+ * responsible for deleting the returned object.
*/
virtual SkScanlineDecoder* onGetScanlineDecoder(const SkImageInfo& dstInfo,
const Options& options,
@@ -293,31 +282,9 @@ protected:
return fStream.get();
}
- /**
- * If the codec has a scanline decoder, return it (no ownership change occurs)
- * else return NULL.
- * The returned decoder is valid while the codec exists and the client has not
- * created a new scanline decoder.
- */
- SkScanlineDecoder* scanlineDecoder() {
- return fScanlineDecoder;
- }
-
- /**
- * Allow the codec subclass to detach and take ownership of the scanline decoder.
- * This will likely be used when the scanline decoder needs to be destroyed
- * in the destructor of the subclass.
- */
- SkScanlineDecoder* detachScanlineDecoder() {
- SkScanlineDecoder* scanlineDecoder = fScanlineDecoder;
- fScanlineDecoder = NULL;
- return scanlineDecoder;
- }
-
private:
const SkImageInfo fInfo;
SkAutoTDelete<SkStream> fStream;
bool fNeedsRewind;
- SkScanlineDecoder* fScanlineDecoder;
};
#endif // SkCodec_DEFINED
diff --git a/include/codec/SkScanlineDecoder.h b/include/codec/SkScanlineDecoder.h
index 942c1b986f..8376e57c09 100644
--- a/include/codec/SkScanlineDecoder.h
+++ b/include/codec/SkScanlineDecoder.h
@@ -21,13 +21,6 @@ public:
* It is possible that not all scanlines will have been read/skipped. In
* fact, in the case of subset decodes, it is likely that there will be
* scanlines at the bottom of the image that have been ignored.
- *
- * Note for implementations: An SkScanlineDecoder will be deleted by (and
- * therefore *before*) its associated SkCodec, in case the order matters.
- * However, while the SkCodec base class maintains ownership of the
- * SkScanlineDecoder, the subclass will be deleted before the scanline
- * decoder. If this is an issue, detachScanlineDecoder() provides
- * a means for the subclass to take ownership of the SkScanlineDecoder.
*/
virtual ~SkScanlineDecoder() {}