Move all knowledge of X sampling into SkScaledCodec
Prior to this CL, each SkCodec subclass that allows sampling does an
extra check in onStartScanlineDecode to determine whether the X dimension
is supported for sampling. Remove this check, and provide a way for
SkScaledCodec to directly access the SkSwizzler, and update it to do
sampling. This way, the SkCodec knows nothing of sampling, but we can
still save the extra step of sampling afterwards.
FIXME: SkBmpRLECodec still calls SkScaledCodec::DimensionsSupported. It
seems like it could directly support sampling, rather than dealing with
SkScaledCodec (partially).
Add a new base class for SkSwizzler. It allows updating the swizzler
after it was created, which is done by SkScaledCodec. Modify SkSwizzler's
constructor/factory function to stop taking any info about sampling,
assume the sample size is one, and move modifying that into a virtual
function overridden from the base class.
BUG=skia:4284
Review URL: https://codereview.chromium.org/1372973002
diff --git a/src/codec/SkMaskSwizzler.cpp b/src/codec/SkMaskSwizzler.cpp
index 6ca9b58..9772d87 100644
--- a/src/codec/SkMaskSwizzler.cpp
+++ b/src/codec/SkMaskSwizzler.cpp
@@ -352,11 +352,7 @@
return nullptr;
}
- // Get the sample size
- int sampleX;
- SkScaledCodec::ComputeSampleSize(dstInfo, srcInfo, &sampleX, NULL);
-
- return new SkMaskSwizzler(dstInfo, masks, proc, sampleX);
+ return new SkMaskSwizzler(dstInfo.width(), masks, proc);
}
/*
@@ -364,15 +360,28 @@
* Constructor for mask swizzler
*
*/
-SkMaskSwizzler::SkMaskSwizzler(const SkImageInfo& dstInfo, SkMasks* masks,
- RowProc proc, uint32_t sampleX)
- : fDstInfo(dstInfo)
- , fMasks(masks)
+SkMaskSwizzler::SkMaskSwizzler(int width, SkMasks* masks, RowProc proc)
+ : fMasks(masks)
, fRowProc(proc)
- , fSampleX(sampleX)
- , fStartX(get_start_coord(sampleX))
+ , fSrcWidth(width)
+ , fDstWidth(width)
+ , fSampleX(1)
+ , fX0(0)
{}
+int SkMaskSwizzler::onSetSampleX(int sampleX) {
+ // FIXME: Share this function with SkSwizzler?
+ SkASSERT(sampleX > 0); // Surely there is an upper limit? Should there be
+ // way to report failure?
+ fSampleX = sampleX;
+ fX0 = get_start_coord(sampleX);
+ fDstWidth = get_scaled_dimension(fSrcWidth, sampleX);
+
+ // check that fX0 is less than original width
+ SkASSERT(fX0 >= 0 && fX0 < fSrcWidth);
+ return fDstWidth;
+}
+
/*
*
* Swizzle the specified row
@@ -380,5 +389,5 @@
*/
SkSwizzler::ResultAlpha SkMaskSwizzler::swizzle(void* dst, const uint8_t* SK_RESTRICT src) {
SkASSERT(nullptr != dst && nullptr != src);
- return fRowProc(dst, src, fDstInfo.width(), fMasks, fStartX, fSampleX);
+ return fRowProc(dst, src, fDstWidth, fMasks, fX0, fSampleX);
}