msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | #ifndef SkSampledCodec_DEFINED |
| 8 | #define SkSampledCodec_DEFINED |
| 9 | |
| 10 | #include "SkAndroidCodec.h" |
| 11 | #include "SkCodec.h" |
| 12 | |
| 13 | /** |
| 14 | * This class implements the functionality of SkAndroidCodec. Scaling will |
| 15 | * be provided by sampling if it cannot be provided by fCodec. |
| 16 | */ |
| 17 | class SkSampledCodec : public SkAndroidCodec { |
| 18 | public: |
| 19 | |
| 20 | explicit SkSampledCodec(SkCodec*); |
| 21 | |
| 22 | virtual ~SkSampledCodec() {} |
| 23 | |
| 24 | protected: |
| 25 | |
| 26 | SkEncodedFormat onGetEncodedFormat() const override { return fCodec->getEncodedFormat(); }; |
| 27 | |
| 28 | SkISize onGetSampledDimensions(int sampleSize) const override; |
| 29 | |
| 30 | bool onGetSupportedSubset(SkIRect* desiredSubset) const override { return true; } |
| 31 | |
| 32 | SkCodec::Result onGetAndroidPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, |
| 33 | AndroidOptions& options) override; |
| 34 | |
| 35 | private: |
scroggo | 501b734 | 2015-11-03 07:55:11 -0800 | [diff] [blame] | 36 | /** |
| 37 | * Find the best way to account for native scaling. |
| 38 | * |
| 39 | * Return a size that fCodec can scale to, and adjust sampleSize to finish scaling. |
| 40 | * |
| 41 | * @param sampleSize As an input, the requested sample size. |
| 42 | * As an output, sampling needed after letting fCodec |
| 43 | * scale to the returned dimensions. |
| 44 | * @param nativeSampleSize Optional output parameter. Will be set to the |
| 45 | * effective sample size done by fCodec. |
| 46 | * @return SkISize The size that fCodec should scale to. |
| 47 | */ |
| 48 | SkISize accountForNativeScaling(int* sampleSize, int* nativeSampleSize = nullptr) const; |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 49 | |
| 50 | /** |
| 51 | * This fulfills the same contract as onGetAndroidPixels(). |
| 52 | * |
| 53 | * We call this function from onGetAndroidPixels() if we have determined |
| 54 | * that fCodec does not support the requested scale, and we need to |
| 55 | * provide the scale by sampling. |
| 56 | */ |
| 57 | SkCodec::Result sampledDecode(const SkImageInfo& info, void* pixels, size_t rowBytes, |
| 58 | AndroidOptions& options); |
| 59 | |
| 60 | SkAutoTDelete<SkCodec> fCodec; |
| 61 | |
| 62 | typedef SkAndroidCodec INHERITED; |
| 63 | }; |
| 64 | #endif // SkSampledCodec_DEFINED |