diff options
author | scroggo <scroggo@google.com> | 2015-10-02 13:14:46 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-10-02 13:14:46 -0700 |
commit | e7fc14b55bb8c41ba054abf0bfa09cdd6ec84671 (patch) | |
tree | 81525743c2c436a60f4127cf04f0f96d5dc3bed5 /include | |
parent | 65f7c9fa7ed028159a4a2c792ccc1dcdf718eed2 (diff) |
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
Diffstat (limited to 'include')
-rw-r--r-- | include/codec/SkCodec.h | 35 | ||||
-rw-r--r-- | include/codec/SkScaledCodec.h | 19 |
2 files changed, 37 insertions, 17 deletions
diff --git a/include/codec/SkCodec.h b/include/codec/SkCodec.h index c0cce853a3..7300a5c732 100644 --- a/include/codec/SkCodec.h +++ b/include/codec/SkCodec.h @@ -17,6 +17,7 @@ #include "SkTypes.h" class SkData; +class SkSampler; /** * Abstraction layer directly on top of an image codec. @@ -382,6 +383,15 @@ protected: return this->getInfo().dimensions(); } + // FIXME: What to do about subsets?? + /** + * Subclasses should override if they support dimensions other than the + * srcInfo's. + */ + virtual bool onDimensionsSupported(const SkISize&) { + return false; + } + virtual SkEncodedFormat onGetEncodedFormat() const = 0; virtual Result onGetPixels(const SkImageInfo& info, @@ -455,6 +465,19 @@ private: SkCodec::Options fOptions; int fCurrScanline; + /** + * Return whether these dimensions are supported as a scale. + * + * The codec may choose to cache the information about scale and subset. + * Either way, the same information will be passed to onGetPixels/onStart + * on success. + * + * This must return true for a size returned from getScaledDimensions. + */ + bool dimensionsSupported(const SkISize& dim) { + return dim == fSrcInfo.dimensions() || this->onDimensionsSupported(dim); + } + // Methods for scanline decoding. virtual SkCodec::Result onStartScanlineDecode(const SkImageInfo& dstInfo, const SkCodec::Options& options, SkPMColor ctable[], int* ctableCount) { @@ -477,5 +500,17 @@ private: return kUnimplemented; } + /** + * Return an object which will allow forcing scanline decodes to sample in X. + * + * May create a sampler, if one is not currently being used. Otherwise, does + * not affect ownership. + * + * Only valid during scanline decoding. + */ + virtual SkSampler* getSampler() { return nullptr; } + + // Needed to call getSampler and dimensionsSupported. + friend class SkScaledCodec; }; #endif // SkCodec_DEFINED diff --git a/include/codec/SkScaledCodec.h b/include/codec/SkScaledCodec.h index 20428d8d73..92ef19e74f 100644 --- a/include/codec/SkScaledCodec.h +++ b/include/codec/SkScaledCodec.h @@ -22,23 +22,7 @@ public: virtual ~SkScaledCodec(); - /** - * returns whether a destination's dimensions are supported for down sampling - */ - static bool DimensionsSupportedForSampling(const SkImageInfo& srcInfo, - const SkImageInfo& dstInfo) { - // heights must be equal as no native y sampling is supported - if (dstInfo.height() != srcInfo.height()) { - return false; - } - // only support down sampling, dstWidth cannot be larger that srcWidth - if(dstInfo.width() > srcInfo.width()) { - return false; - } - return true; - } - - static void ComputeSampleSize(const SkImageInfo& dstInfo, const SkImageInfo& srcInfo, + static void ComputeSampleSize(const SkISize& dstDim, const SkISize& srcDim, int* sampleSizeX, int* sampleSizeY); protected: @@ -46,6 +30,7 @@ protected: * Recommend a set of destination dimensions given a requested scale */ SkISize onGetScaledDimensions(float desiredScale) const override; + bool onDimensionsSupported(const SkISize&) override; Result onGetPixels(const SkImageInfo&, void*, size_t, const Options&, SkPMColor*, int*) override; |