Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SkImageGenerator.h
Go to the documentation of this file.
1/*
2 * Copyright 2013 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#ifndef SkImageGenerator_DEFINED
9#define SkImageGenerator_DEFINED
10
11#include "include/core/SkData.h"
17
18#if defined(SK_GRAPHITE)
21#endif
22
23#include <cstddef>
24#include <cstdint>
25
27
29public:
30 /**
31 * The PixelRef which takes ownership of this SkImageGenerator
32 * will call the image generator's destructor.
33 */
34 virtual ~SkImageGenerator() { }
35
36 uint32_t uniqueID() const { return fUniqueID; }
37
38 /**
39 * Return a ref to the encoded (i.e. compressed) representation
40 * of this data.
41 *
42 * If non-NULL is returned, the caller is responsible for calling
43 * unref() on the data when it is finished.
44 */
46 return this->onRefEncodedData();
47 }
48
49 /**
50 * Return the ImageInfo associated with this generator.
51 */
52 const SkImageInfo& getInfo() const { return fInfo; }
53
54 /**
55 * Can this generator be used to produce images that will be drawable to the specified context
56 * (or to CPU, if context is nullptr)?
57 */
58 bool isValid(GrRecordingContext* context) const {
59 return this->onIsValid(context);
60 }
61
62 /**
63 * Will this generator produce protected content
64 */
65 bool isProtected() const {
66 return this->onIsProtected();
67 }
68
69 /**
70 * Decode into the given pixels, a block of memory of size at
71 * least (info.fHeight - 1) * rowBytes + (info.fWidth *
72 * bytesPerPixel)
73 *
74 * Repeated calls to this function should give the same results,
75 * allowing the PixelRef to be immutable.
76 *
77 * @param info A description of the format
78 * expected by the caller. This can simply be identical
79 * to the info returned by getInfo().
80 *
81 * This contract also allows the caller to specify
82 * different output-configs, which the implementation can
83 * decide to support or not.
84 *
85 * A size that does not match getInfo() implies a request
86 * to scale. If the generator cannot perform this scale,
87 * it will return false.
88 *
89 * @return true on success.
90 */
91 bool getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes);
92
93 bool getPixels(const SkPixmap& pm) {
94 return this->getPixels(pm.info(), pm.writable_addr(), pm.rowBytes());
95 }
96
97 /**
98 * If decoding to YUV is supported, this returns true. Otherwise, this
99 * returns false and the caller will ignore output parameter yuvaPixmapInfo.
100 *
101 * @param supportedDataTypes Indicates the data type/planar config combinations that are
102 * supported by the caller. If the generator supports decoding to
103 * YUV(A), but not as a type in supportedDataTypes, this method
104 * returns false.
105 * @param yuvaPixmapInfo Output parameter that specifies the planar configuration, subsampling,
106 * orientation, chroma siting, plane color types, and row bytes.
107 */
108 bool queryYUVAInfo(const SkYUVAPixmapInfo::SupportedDataTypes& supportedDataTypes,
109 SkYUVAPixmapInfo* yuvaPixmapInfo) const;
110
111 /**
112 * Returns true on success and false on failure.
113 * This always attempts to perform a full decode. To get the planar
114 * configuration without decoding use queryYUVAInfo().
115 *
116 * @param yuvaPixmaps Contains preallocated pixmaps configured according to a successful call
117 * to queryYUVAInfo().
118 */
119 bool getYUVAPlanes(const SkYUVAPixmaps& yuvaPixmaps);
120
121 virtual bool isTextureGenerator() const { return false; }
122
123protected:
124 static constexpr int kNeedNewImageUniqueID = 0;
125
126 SkImageGenerator(const SkImageInfo& info, uint32_t uniqueId = kNeedNewImageUniqueID);
127
128 virtual sk_sp<SkData> onRefEncodedData() { return nullptr; }
129 struct Options {};
130 virtual bool onGetPixels(const SkImageInfo&, void*, size_t, const Options&) { return false; }
131 virtual bool onIsValid(GrRecordingContext*) const { return true; }
132 virtual bool onIsProtected() const { return false; }
134 SkYUVAPixmapInfo*) const { return false; }
135 virtual bool onGetYUVAPlanes(const SkYUVAPixmaps&) { return false; }
136
138
139private:
140 const uint32_t fUniqueID;
141
143 SkImageGenerator(const SkImageGenerator&) = delete;
144 SkImageGenerator& operator=(SkImageGenerator&&) = delete;
145 SkImageGenerator& operator=(const SkImageGenerator&) = delete;
146};
147
148#endif // SkImageGenerator_DEFINED
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
#define SK_API
Definition SkAPI.h:35
@ kNeedNewImageUniqueID
virtual bool isTextureGenerator() const
const SkImageInfo & getInfo() const
virtual bool onIsValid(GrRecordingContext *) const
virtual sk_sp< SkData > onRefEncodedData()
virtual bool onGetYUVAPlanes(const SkYUVAPixmaps &)
virtual ~SkImageGenerator()
virtual bool onQueryYUVAInfo(const SkYUVAPixmapInfo::SupportedDataTypes &, SkYUVAPixmapInfo *) const
virtual bool onGetPixels(const SkImageInfo &, void *, size_t, const Options &)
bool isValid(GrRecordingContext *context) const
bool getPixels(const SkPixmap &pm)
sk_sp< SkData > refEncodedData()
const SkImageInfo fInfo
virtual bool onIsProtected() const
bool isProtected() const
uint32_t uniqueID() const
size_t rowBytes() const
Definition SkPixmap.h:145
const SkImageInfo & info() const
Definition SkPixmap.h:135
void * writable_addr() const
Definition SkPixmap.h:483