msarett | edd2dcf | 2016-01-14 13:12:26 -0800 | [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 | */ |
Hal Canary | 03a7f5f | 2017-02-10 09:06:38 -0500 | [diff] [blame] | 7 | #ifndef SkCodecImageGenerator_DEFINED |
| 8 | #define SkCodecImageGenerator_DEFINED |
msarett | edd2dcf | 2016-01-14 13:12:26 -0800 | [diff] [blame] | 9 | |
| 10 | #include "SkCodec.h" |
Leon Scroggins III | 20a7ecc | 2016-12-19 15:04:06 -0500 | [diff] [blame] | 11 | #include "SkColorTable.h" |
msarett | edd2dcf | 2016-01-14 13:12:26 -0800 | [diff] [blame] | 12 | #include "SkData.h" |
| 13 | #include "SkImageGenerator.h" |
| 14 | |
| 15 | class SkCodecImageGenerator : public SkImageGenerator { |
| 16 | public: |
| 17 | /* |
| 18 | * If this data represents an encoded image that we know how to decode, |
| 19 | * return an SkCodecImageGenerator. Otherwise return nullptr. |
msarett | edd2dcf | 2016-01-14 13:12:26 -0800 | [diff] [blame] | 20 | */ |
reed | 42943c8 | 2016-09-12 12:01:44 -0700 | [diff] [blame] | 21 | static SkImageGenerator* NewFromEncodedCodec(sk_sp<SkData>); |
| 22 | static SkImageGenerator* NewFromEncodedCodec(SkData* data) { |
| 23 | return NewFromEncodedCodec(sk_ref_sp(data)); |
| 24 | } |
msarett | edd2dcf | 2016-01-14 13:12:26 -0800 | [diff] [blame] | 25 | |
| 26 | protected: |
Mike Reed | df8599a | 2016-12-08 13:41:10 -0500 | [diff] [blame] | 27 | SkData* onRefEncodedData(GrContext* ctx) override; |
msarett | edd2dcf | 2016-01-14 13:12:26 -0800 | [diff] [blame] | 28 | |
| 29 | bool onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, SkPMColor ctable[], |
| 30 | int* ctableCount) override; |
| 31 | |
msarett | 4984c3c | 2016-03-10 05:44:43 -0800 | [diff] [blame] | 32 | bool onQueryYUV8(SkYUVSizeInfo*, SkYUVColorSpace*) const override; |
| 33 | |
| 34 | bool onGetYUV8Planes(const SkYUVSizeInfo&, void* planes[3]) override; |
msarett | edd2dcf | 2016-01-14 13:12:26 -0800 | [diff] [blame] | 35 | |
Leon Scroggins III | 20a7ecc | 2016-12-19 15:04:06 -0500 | [diff] [blame] | 36 | bool onComputeScaledDimensions(SkScalar, SupportedSizes*) override; |
| 37 | |
| 38 | bool onGenerateScaledPixels(const SkPixmap&) override; |
| 39 | |
msarett | edd2dcf | 2016-01-14 13:12:26 -0800 | [diff] [blame] | 40 | private: |
| 41 | /* |
| 42 | * Takes ownership of codec |
msarett | edd2dcf | 2016-01-14 13:12:26 -0800 | [diff] [blame] | 43 | */ |
reed | 42943c8 | 2016-09-12 12:01:44 -0700 | [diff] [blame] | 44 | SkCodecImageGenerator(SkCodec* codec, sk_sp<SkData>); |
msarett | edd2dcf | 2016-01-14 13:12:26 -0800 | [diff] [blame] | 45 | |
Ben Wagner | 145dbcd | 2016-11-03 14:40:50 -0400 | [diff] [blame] | 46 | std::unique_ptr<SkCodec> fCodec; |
bungeman | ffae30d | 2016-08-03 13:32:32 -0700 | [diff] [blame] | 47 | sk_sp<SkData> fData; |
Leon Scroggins III | 20a7ecc | 2016-12-19 15:04:06 -0500 | [diff] [blame] | 48 | sk_sp<SkColorTable> fColorTable; |
msarett | edd2dcf | 2016-01-14 13:12:26 -0800 | [diff] [blame] | 49 | |
msarett | edd2dcf | 2016-01-14 13:12:26 -0800 | [diff] [blame] | 50 | typedef SkImageGenerator INHERITED; |
| 51 | }; |
Hal Canary | 03a7f5f | 2017-02-10 09:06:38 -0500 | [diff] [blame] | 52 | #endif // SkCodecImageGenerator_DEFINED |