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