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 | |
Brian Salomon | d3b6597 | 2017-03-22 12:05:03 -0400 | [diff] [blame] | 22 | ~SkSampledCodec() override {} |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 23 | |
| 24 | protected: |
| 25 | |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 26 | SkISize onGetSampledDimensions(int sampleSize) const override; |
| 27 | |
| 28 | bool onGetSupportedSubset(SkIRect* desiredSubset) const override { return true; } |
| 29 | |
| 30 | SkCodec::Result onGetAndroidPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, |
scroggo | e95a068 | 2015-11-04 04:31:12 -0800 | [diff] [blame] | 31 | const AndroidOptions& options) override; |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 32 | |
| 33 | private: |
scroggo | 501b734 | 2015-11-03 07:55:11 -0800 | [diff] [blame] | 34 | /** |
| 35 | * Find the best way to account for native scaling. |
| 36 | * |
| 37 | * Return a size that fCodec can scale to, and adjust sampleSize to finish scaling. |
| 38 | * |
| 39 | * @param sampleSize As an input, the requested sample size. |
| 40 | * As an output, sampling needed after letting fCodec |
| 41 | * scale to the returned dimensions. |
| 42 | * @param nativeSampleSize Optional output parameter. Will be set to the |
| 43 | * effective sample size done by fCodec. |
| 44 | * @return SkISize The size that fCodec should scale to. |
| 45 | */ |
| 46 | SkISize accountForNativeScaling(int* sampleSize, int* nativeSampleSize = nullptr) const; |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 47 | |
| 48 | /** |
| 49 | * This fulfills the same contract as onGetAndroidPixels(). |
| 50 | * |
| 51 | * We call this function from onGetAndroidPixels() if we have determined |
| 52 | * that fCodec does not support the requested scale, and we need to |
| 53 | * provide the scale by sampling. |
| 54 | */ |
| 55 | SkCodec::Result sampledDecode(const SkImageInfo& info, void* pixels, size_t rowBytes, |
scroggo | e95a068 | 2015-11-04 04:31:12 -0800 | [diff] [blame] | 56 | const AndroidOptions& options); |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 57 | |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 58 | typedef SkAndroidCodec INHERITED; |
| 59 | }; |
| 60 | #endif // SkSampledCodec_DEFINED |