Index: src/codec/SkScaledCodec.cpp |
diff --git a/src/codec/SkScaledCodec.cpp b/src/codec/SkScaledCodec.cpp |
index 36aeda98cf495ff2a84f1103d0612bb26d91ada1..b4f78f4238b57e41a62a0cb3f04e0221106f0d0b 100644 |
--- a/src/codec/SkScaledCodec.cpp |
+++ b/src/codec/SkScaledCodec.cpp |
@@ -178,12 +178,13 @@ void SkScaledCodec::ComputeSampleSize(const SkImageInfo& dstInfo, const SkImageI |
SkCodec::Result SkScaledCodec::onGetPixels(const SkImageInfo& requestedInfo, void* dst, |
size_t rowBytes, const Options& options, |
- SkPMColor ctable[], int* ctableCount) { |
+ SkPMColor ctable[], int* ctableCount, |
+ int* rowsDecoded) { |
if (options.fSubset) { |
// Subsets are not supported. |
return kUnimplemented; |
- } |
+ } |
// FIXME: If no scaling/subsets are requested, we can call fCodec->getPixels. |
Result result = fCodec->startScanlineDecode(requestedInfo, &options, ctable, ctableCount); |
@@ -193,19 +194,23 @@ SkCodec::Result SkScaledCodec::onGetPixels(const SkImageInfo& requestedInfo, voi |
case SkCodec::kTopDown_SkScanlineOrder: |
case SkCodec::kBottomUp_SkScanlineOrder: |
case SkCodec::kNone_SkScanlineOrder: |
- return fCodec->getScanlines(dst, requestedInfo.height(), rowBytes); |
+ if (fCodec->getScanlines(dst, requestedInfo.height(), rowBytes) != |
+ requestedInfo.height()) { |
+ // fCodec has already handled filling uninitialized memory. |
+ *rowsDecoded = requestedInfo.height(); |
+ return kIncompleteInput; |
+ } |
+ return kSuccess; |
case SkCodec::kOutOfOrder_SkScanlineOrder: { |
for (int y = 0; y < requestedInfo.height(); y++) { |
int dstY = fCodec->nextScanline(); |
void* dstPtr = SkTAddOffset<void>(dst, rowBytes * dstY); |
- result = fCodec->getScanlines(dstPtr, 1, rowBytes); |
- // FIXME (msarett): Make the SkCodec base class take care of filling |
- // uninitialized pixels so we can return immediately on kIncompleteInput. |
- if (kSuccess != result && kIncompleteInput != result) { |
- return result; |
+ if (1 != fCodec->getScanlines(dstPtr, 1, rowBytes)) { |
+ *rowsDecoded = y + 1; |
scroggo
2015/10/01 14:48:32
Why is this y+1 and not y? (Same for other instanc
msarett
2015/10/01 18:14:14
The failed call to getScanlines(1) will fill the s
|
+ return kIncompleteInput; |
} |
} |
- return result; |
+ return kSuccess; |
} |
} |
} |
@@ -241,61 +246,95 @@ SkCodec::Result SkScaledCodec::onGetPixels(const SkImageInfo& requestedInfo, voi |
switch(fCodec->getScanlineOrder()) { |
case SkCodec::kTopDown_SkScanlineOrder: { |
- result = fCodec->skipScanlines(Y0); |
- if (kSuccess != result && kIncompleteInput != result) { |
- return result; |
+ if (!fCodec->skipScanlines(Y0)) { |
+ *rowsDecoded = 0; |
+ return kIncompleteInput; |
} |
for (int y = 0; y < dstHeight; y++) { |
- result = fCodec->getScanlines(dst, 1, rowBytes); |
- if (kSuccess != result && kIncompleteInput != result) { |
- return result; |
+ if (1 != fCodec->getScanlines(dst, 1, rowBytes)) { |
+ *rowsDecoded = y + 1; |
+ return kIncompleteInput; |
} |
if (y < dstHeight - 1) { |
- result = fCodec->skipScanlines(sampleY - 1); |
- if (kSuccess != result && kIncompleteInput != result) { |
- return result; |
+ if (!fCodec->skipScanlines(sampleY - 1)) { |
+ *rowsDecoded = y + 1; |
+ return kIncompleteInput; |
} |
} |
dst = SkTAddOffset<void>(dst, rowBytes); |
} |
- return result; |
+ return kSuccess; |
} |
case SkCodec::kBottomUp_SkScanlineOrder: |
case SkCodec::kOutOfOrder_SkScanlineOrder: { |
- for (int y = 0; y < srcHeight; y++) { |
+ Result result = kSuccess; |
+ int y; |
+ for (y = 0; y < srcHeight; y++) { |
int srcY = fCodec->nextScanline(); |
if (is_coord_necessary(srcY, sampleY, dstHeight)) { |
void* dstPtr = SkTAddOffset<void>(dst, rowBytes * get_dst_coord(srcY, sampleY)); |
- result = fCodec->getScanlines(dstPtr, 1, rowBytes); |
- if (kSuccess != result && kIncompleteInput != result) { |
- return result; |
+ if (1 != fCodec->getScanlines(dstPtr, 1, rowBytes)) { |
+ result = kIncompleteInput; |
+ break; |
} |
} else { |
- result = fCodec->skipScanlines(1); |
- if (kSuccess != result && kIncompleteInput != result) { |
- return result; |
+ if (!fCodec->skipScanlines(1)) { |
+ result = kIncompleteInput; |
+ break; |
+ } |
+ } |
+ } |
+ |
+ // We handle filling uninitialized memory here instead of in the parent class. |
+ // The parent class does not know that we are sampling. |
+ if (kIncompleteInput == result) { |
+ const SkImageInfo fillInfo = requestedInfo.makeWH(requestedInfo.width(), 1); |
+ const uint32_t fillValue = this->getFillValue(fillInfo.colorType(), |
+ fillInfo.alphaType()); |
+ for (; y < srcHeight; y++) { |
+ int srcY = fCodec->nextScanline(y); |
+ if (is_coord_necessary(srcY, sampleY, dstHeight)) { |
+ void* dstRow = SkTAddOffset<void>(dst, |
+ rowBytes * get_dst_coord(srcY, sampleY)); |
+ SkSwizzler::Fill(dstRow, fillInfo, rowBytes, fillValue, |
+ options.fZeroInitialized); |
} |
} |
+ *rowsDecoded = dstHeight; |
} |
return result; |
} |
case SkCodec::kNone_SkScanlineOrder: { |
SkAutoMalloc storage(srcHeight * rowBytes); |
uint8_t* storagePtr = static_cast<uint8_t*>(storage.get()); |
- result = fCodec->getScanlines(storagePtr, srcHeight, rowBytes); |
- if (kSuccess != result && kIncompleteInput != result) { |
- return result; |
- } |
+ int scanlines = (int) fCodec->getScanlines(storagePtr, srcHeight, rowBytes); |
scroggo
2015/10/01 14:48:32
It's weird to me that getScanlines returns one typ
msarett
2015/10/01 18:14:14
Yeah I also thought this was strange.
I feel stro
scroggo
2015/10/01 20:48:57
+1 to consistency. I'm not sure why width and heig
|
storagePtr += Y0 * rowBytes; |
- for (int y = 0; y < dstHeight; y++) { |
+ scanlines -= Y0; |
+ int y = 0; |
+ while(y < dstHeight && scanlines > 0) { |
memcpy(dst, storagePtr, rowBytes); |
storagePtr += sampleY * rowBytes; |
dst = SkTAddOffset<void>(dst, rowBytes); |
+ scanlines -= sampleY; |
+ y++; |
} |
- return result; |
+ if (y < dstHeight) { |
+ // fCodec has already handled filling uninitialized memory. |
+ *rowsDecoded = dstHeight; |
+ return kIncompleteInput; |
+ } |
+ return kSuccess; |
} |
default: |
SkASSERT(false); |
return kUnimplemented; |
} |
} |
+ |
+uint32_t SkScaledCodec::onGetFillValue(SkColorType colorType, SkAlphaType alphaType) const { |
+ return fCodec->getFillValue(colorType, alphaType); |
+} |
+ |
+SkCodec::SkScanlineOrder SkScaledCodec::onGetScanlineOrder() const { |
+ return fCodec->getScanlineOrder(); |
+} |