blob: 51086eb0a89ed948083440dc3122a61bbca9dc18 [file] [log] [blame]
msarettedd2dcf2016-01-14 13:12:26 -08001/*
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 Canary03a7f5f2017-02-10 09:06:38 -05007#ifndef SkCodecImageGenerator_DEFINED
8#define SkCodecImageGenerator_DEFINED
msarettedd2dcf2016-01-14 13:12:26 -08009
10#include "SkCodec.h"
Leon Scroggins III20a7ecc2016-12-19 15:04:06 -050011#include "SkColorTable.h"
msarettedd2dcf2016-01-14 13:12:26 -080012#include "SkData.h"
13#include "SkImageGenerator.h"
14
15class SkCodecImageGenerator : public SkImageGenerator {
16public:
17 /*
18 * If this data represents an encoded image that we know how to decode,
19 * return an SkCodecImageGenerator. Otherwise return nullptr.
msarettedd2dcf2016-01-14 13:12:26 -080020 */
reed42943c82016-09-12 12:01:44 -070021 static SkImageGenerator* NewFromEncodedCodec(sk_sp<SkData>);
22 static SkImageGenerator* NewFromEncodedCodec(SkData* data) {
23 return NewFromEncodedCodec(sk_ref_sp(data));
24 }
msarettedd2dcf2016-01-14 13:12:26 -080025
26protected:
Mike Reeddf8599a2016-12-08 13:41:10 -050027 SkData* onRefEncodedData(GrContext* ctx) override;
msarettedd2dcf2016-01-14 13:12:26 -080028
29 bool onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, SkPMColor ctable[],
30 int* ctableCount) override;
31
msarett4984c3c2016-03-10 05:44:43 -080032 bool onQueryYUV8(SkYUVSizeInfo*, SkYUVColorSpace*) const override;
33
34 bool onGetYUV8Planes(const SkYUVSizeInfo&, void* planes[3]) override;
msarettedd2dcf2016-01-14 13:12:26 -080035
Leon Scroggins III20a7ecc2016-12-19 15:04:06 -050036 bool onComputeScaledDimensions(SkScalar, SupportedSizes*) override;
37
38 bool onGenerateScaledPixels(const SkPixmap&) override;
39
msarettedd2dcf2016-01-14 13:12:26 -080040private:
41 /*
42 * Takes ownership of codec
msarettedd2dcf2016-01-14 13:12:26 -080043 */
reed42943c82016-09-12 12:01:44 -070044 SkCodecImageGenerator(SkCodec* codec, sk_sp<SkData>);
msarettedd2dcf2016-01-14 13:12:26 -080045
Ben Wagner145dbcd2016-11-03 14:40:50 -040046 std::unique_ptr<SkCodec> fCodec;
bungemanffae30d2016-08-03 13:32:32 -070047 sk_sp<SkData> fData;
Leon Scroggins III20a7ecc2016-12-19 15:04:06 -050048 sk_sp<SkColorTable> fColorTable;
msarettedd2dcf2016-01-14 13:12:26 -080049
msarettedd2dcf2016-01-14 13:12:26 -080050 typedef SkImageGenerator INHERITED;
51};
Hal Canary03a7f5f2017-02-10 09:06:38 -050052#endif // SkCodecImageGenerator_DEFINED