OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef SkImageGenerator_DEFINED | 8 #ifndef SkImageGenerator_DEFINED |
9 #define SkImageGenerator_DEFINED | 9 #define SkImageGenerator_DEFINED |
10 | 10 |
11 #include "SkColor.h" | 11 #include "SkColor.h" |
12 #include "SkImageInfo.h" | 12 #include "SkImageInfo.h" |
13 | 13 |
14 class SkBitmap; | 14 class SkBitmap; |
15 class SkData; | 15 class SkData; |
16 class SkImageGenerator; | 16 class SkImageGenerator; |
17 | 17 |
| 18 //#define SK_LEGACY_IMAGE_GENERATOR_ENUMS_AND_OPTIONS |
| 19 |
18 /** | 20 /** |
19 * Takes ownership of SkImageGenerator. If this method fails for | 21 * Takes ownership of SkImageGenerator. If this method fails for |
20 * whatever reason, it will return false and immediatetely delete | 22 * whatever reason, it will return false and immediatetely delete |
21 * the generator. If it succeeds, it will modify destination | 23 * the generator. If it succeeds, it will modify destination |
22 * bitmap. | 24 * bitmap. |
23 * | 25 * |
24 * If generator is NULL, will safely return false. | 26 * If generator is NULL, will safely return false. |
25 * | 27 * |
26 * If this fails or when the SkDiscardablePixelRef that is | 28 * If this fails or when the SkDiscardablePixelRef that is |
27 * installed into destination is destroyed, it will call | 29 * installed into destination is destroyed, it will call |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 * If non-NULL is returned, the caller is responsible for calling | 62 * If non-NULL is returned, the caller is responsible for calling |
61 * unref() on the data when it is finished. | 63 * unref() on the data when it is finished. |
62 */ | 64 */ |
63 SkData* refEncodedData() { return this->onRefEncodedData(); } | 65 SkData* refEncodedData() { return this->onRefEncodedData(); } |
64 | 66 |
65 /** | 67 /** |
66 * Return the ImageInfo associated with this generator. | 68 * Return the ImageInfo associated with this generator. |
67 */ | 69 */ |
68 const SkImageInfo& getInfo() const { return fInfo; } | 70 const SkImageInfo& getInfo() const { return fInfo; } |
69 | 71 |
| 72 #ifdef SK_LEGACY_IMAGE_GENERATOR_ENUMS_AND_OPTIONS |
70 /** | 73 /** |
71 * Used to describe the result of a call to getPixels(). | 74 * Used to describe the result of a call to getPixels(). |
72 * | 75 * |
73 * Result is the union of possible results from subclasses. | 76 * Result is the union of possible results from subclasses. |
74 */ | 77 */ |
75 enum Result { | 78 enum Result { |
76 /** | 79 /** |
77 * General return value for success. | 80 * General return value for success. |
78 */ | 81 */ |
79 kSuccess, | 82 kSuccess, |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 | 133 |
131 /** | 134 /** |
132 * Additional options to pass to getPixels. | 135 * Additional options to pass to getPixels. |
133 */ | 136 */ |
134 struct Options { | 137 struct Options { |
135 Options() | 138 Options() |
136 : fZeroInitialized(kNo_ZeroInitialized) {} | 139 : fZeroInitialized(kNo_ZeroInitialized) {} |
137 | 140 |
138 ZeroInitialized fZeroInitialized; | 141 ZeroInitialized fZeroInitialized; |
139 }; | 142 }; |
| 143 #endif |
140 | 144 |
141 /** | 145 /** |
142 * Decode into the given pixels, a block of memory of size at | 146 * Decode into the given pixels, a block of memory of size at |
143 * least (info.fHeight - 1) * rowBytes + (info.fWidth * | 147 * least (info.fHeight - 1) * rowBytes + (info.fWidth * |
144 * bytesPerPixel) | 148 * bytesPerPixel) |
145 * | 149 * |
146 * Repeated calls to this function should give the same results, | 150 * Repeated calls to this function should give the same results, |
147 * allowing the PixelRef to be immutable. | 151 * allowing the PixelRef to be immutable. |
148 * | 152 * |
149 * @param info A description of the format (config, size) | 153 * @param info A description of the format (config, size) |
150 * expected by the caller. This can simply be identical | 154 * expected by the caller. This can simply be identical |
151 * to the info returned by getInfo(). | 155 * to the info returned by getInfo(). |
152 * | 156 * |
153 * This contract also allows the caller to specify | 157 * This contract also allows the caller to specify |
154 * different output-configs, which the implementation can | 158 * different output-configs, which the implementation can |
155 * decide to support or not. | 159 * decide to support or not. |
156 * | 160 * |
157 * A size that does not match getInfo() implies a request | 161 * A size that does not match getInfo() implies a request |
158 * to scale. If the generator cannot perform this scale, | 162 * to scale. If the generator cannot perform this scale, |
159 * it will return kInvalidScale. | 163 * it will return kInvalidScale. |
160 * | 164 * |
161 * If info is kIndex8_SkColorType, then the caller must provide storage for
up to 256 | 165 * If info is kIndex8_SkColorType, then the caller must provide storage for
up to 256 |
162 * SkPMColor values in ctable. On success the generator must copy N colors
into that storage, | 166 * SkPMColor values in ctable. On success the generator must copy N colors
into that storage, |
163 * (where N is the logical number of table entries) and set ctableCount to
N. | 167 * (where N is the logical number of table entries) and set ctableCount to
N. |
164 * | 168 * |
165 * If info is not kIndex8_SkColorType, then the last two parameters may be
NULL. If ctableCount | 169 * If info is not kIndex8_SkColorType, then the last two parameters may be
NULL. If ctableCount |
166 * is not null, it will be set to 0. | 170 * is not null, it will be set to 0. |
167 * | 171 * |
168 * @return Result kSuccess, or another value explaining the type of failure
. | 172 * @return true on success. |
169 */ | 173 */ |
170 Result getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, con
st Options*, | 174 bool getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, |
171 SkPMColor ctable[], int* ctableCount); | 175 SkPMColor ctable[], int* ctableCount); |
172 | 176 |
173 /** | 177 /** |
174 * Simplified version of getPixels() that asserts that info is NOT kIndex8_
SkColorType and | 178 * Simplified version of getPixels() that asserts that info is NOT kIndex8_
SkColorType and |
175 * uses the default Options. | 179 * uses the default Options. |
176 */ | 180 */ |
177 Result getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes); | 181 bool getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes); |
178 | 182 |
179 /** | 183 /** |
180 * If planes or rowBytes is NULL or if any entry in planes is NULL or if an
y entry in rowBytes | 184 * If planes or rowBytes is NULL or if any entry in planes is NULL or if an
y entry in rowBytes |
181 * is 0, this imagegenerator should output the sizes and return true if it
can efficiently | 185 * is 0, this imagegenerator should output the sizes and return true if it
can efficiently |
182 * return YUV planar data. If it cannot, it should return false. Note that
either planes and | 186 * return YUV planar data. If it cannot, it should return false. Note that
either planes and |
183 * rowBytes are both fully defined and non NULL/non 0 or they are both NULL
or have NULL or 0 | 187 * rowBytes are both fully defined and non NULL/non 0 or they are both NULL
or have NULL or 0 |
184 * entries only. Having only partial planes/rowBytes information is not sup
ported. | 188 * entries only. Having only partial planes/rowBytes information is not sup
ported. |
185 * | 189 * |
186 * If all planes and rowBytes entries are non NULL or non 0, then it should
copy the | 190 * If all planes and rowBytes entries are non NULL or non 0, then it should
copy the |
187 * associated YUV data into those planes of memory supplied by the caller.
It should validate | 191 * associated YUV data into those planes of memory supplied by the caller.
It should validate |
188 * that the sizes match what it expected. If the sizes do not match, it sho
uld return false. | 192 * that the sizes match what it expected. If the sizes do not match, it sho
uld return false. |
189 */ | 193 */ |
190 bool getYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBytes[3], | 194 bool getYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBytes[3], |
191 SkYUVColorSpace* colorSpace); | 195 SkYUVColorSpace* colorSpace); |
192 | 196 |
193 /** | 197 /** |
194 * If the default image decoder system can interpret the specified (encoded
) data, then | 198 * If the default image decoder system can interpret the specified (encoded
) data, then |
195 * this returns a new ImageGenerator for it. Otherwise this returns NULL. E
ither way | 199 * this returns a new ImageGenerator for it. Otherwise this returns NULL. E
ither way |
196 * the caller is still responsible for managing their ownership of the data
. | 200 * the caller is still responsible for managing their ownership of the data
. |
197 */ | 201 */ |
198 static SkImageGenerator* NewFromData(SkData*); | 202 static SkImageGenerator* NewFromData(SkData*); |
199 | 203 |
200 protected: | 204 protected: |
201 SkImageGenerator(const SkImageInfo& info) : fInfo(info) {} | 205 SkImageGenerator(const SkImageInfo& info) : fInfo(info) {} |
202 | 206 |
203 virtual SkData* onRefEncodedData(); | 207 virtual SkData* onRefEncodedData(); |
204 | 208 |
| 209 #ifdef SK_LEGACY_IMAGE_GENERATOR_ENUMS_AND_OPTIONS |
205 virtual Result onGetPixels(const SkImageInfo& info, | 210 virtual Result onGetPixels(const SkImageInfo& info, |
206 void* pixels, size_t rowBytes, const Options&, | 211 void* pixels, size_t rowBytes, const Options&, |
207 SkPMColor ctable[], int* ctableCount); | 212 SkPMColor ctable[], int* ctableCount); |
| 213 #else |
| 214 virtual bool onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBy
tes, |
| 215 SkPMColor ctable[], int* ctableCount); |
| 216 #endif |
208 virtual bool onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBy
tes[3]); | 217 virtual bool onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBy
tes[3]); |
209 virtual bool onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBy
tes[3], | 218 virtual bool onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBy
tes[3], |
210 SkYUVColorSpace* colorSpace); | 219 SkYUVColorSpace* colorSpace); |
211 | 220 |
212 private: | 221 private: |
213 const SkImageInfo fInfo; | 222 const SkImageInfo fInfo; |
214 }; | 223 }; |
215 | 224 |
216 #endif // SkImageGenerator_DEFINED | 225 #endif // SkImageGenerator_DEFINED |
OLD | NEW |