aboutsummaryrefslogtreecommitdiffhomepage
path: root/dm/DMSrcSink.cpp
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 /dm/DMSrcSink.cpp
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 'dm/DMSrcSink.cpp')
-rw-r--r--dm/DMSrcSink.cpp14
1 files changed, 7 insertions, 7 deletions
diff --git a/dm/DMSrcSink.cpp b/dm/DMSrcSink.cpp
index f7daad7b63..38597b6946 100644
--- a/dm/DMSrcSink.cpp
+++ b/dm/DMSrcSink.cpp
@@ -158,8 +158,8 @@ Error CodecSrc::draw(SkCanvas* canvas) const {
break;
}
case kScanline_Mode: {
- SkScanlineDecoder* scanlineDecoder = codec->getScanlineDecoder(decodeInfo, NULL,
- colorPtr, colorCountPtr);
+ SkAutoTDelete<SkScanlineDecoder> scanlineDecoder(codec->getScanlineDecoder(
+ decodeInfo, NULL, colorPtr, colorCountPtr));
if (NULL == scanlineDecoder) {
return Error::Nonfatal("Cannot use scanline decoder for all images");
}
@@ -220,8 +220,8 @@ Error CodecSrc::draw(SkCanvas* canvas) const {
subsetHeight + extraY : subsetHeight;
const int y = row * subsetHeight;
//create scanline decoder for each subset
- SkScanlineDecoder* subsetScanlineDecoder = codec->getScanlineDecoder(decodeInfo,
- NULL, colorPtr, colorCountPtr);
+ SkAutoTDelete<SkScanlineDecoder> subsetScanlineDecoder(
+ codec->getScanlineDecoder(decodeInfo, NULL, colorPtr, colorCountPtr));
if (NULL == subsetScanlineDecoder) {
if (x == 0 && y == 0) {
//first try, image may not be compatible
@@ -287,8 +287,8 @@ Error CodecSrc::draw(SkCanvas* canvas) const {
const int numStripes = (height + stripeHeight - 1) / stripeHeight;
// Decode odd stripes
- SkScanlineDecoder* decoder = codec->getScanlineDecoder(decodeInfo, NULL, colorPtr,
- colorCountPtr);
+ SkAutoTDelete<SkScanlineDecoder> decoder(
+ codec->getScanlineDecoder(decodeInfo, NULL, colorPtr, colorCountPtr));
if (NULL == decoder) {
return Error::Nonfatal("Cannot use scanline decoder for all images");
}
@@ -321,7 +321,7 @@ Error CodecSrc::draw(SkCanvas* canvas) const {
}
// Decode even stripes
- decoder = codec->getScanlineDecoder(decodeInfo, NULL, colorPtr, colorCountPtr);
+ decoder.reset(codec->getScanlineDecoder(decodeInfo, NULL, colorPtr, colorCountPtr));
if (NULL == decoder) {
return "Failed to create second scanline decoder.";
}