OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 SkCodec_DEFINED | 8 #ifndef SkCodec_DEFINED |
9 #define SkCodec_DEFINED | 9 #define SkCodec_DEFINED |
10 | 10 |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 void* pixels, size_t rowBytes, const Options&, | 226 void* pixels, size_t rowBytes, const Options&, |
227 SkPMColor ctable[], int* ctableCount) = 0; | 227 SkPMColor ctable[], int* ctableCount) = 0; |
228 | 228 |
229 virtual bool onGetValidSubset(SkIRect* /* desiredSubset */) const { | 229 virtual bool onGetValidSubset(SkIRect* /* desiredSubset */) const { |
230 // By default, subsets are not supported. | 230 // By default, subsets are not supported. |
231 return false; | 231 return false; |
232 } | 232 } |
233 | 233 |
234 virtual bool onReallyHasAlpha() const { return false; } | 234 virtual bool onReallyHasAlpha() const { return false; } |
235 | 235 |
236 enum RewindState { | |
237 kRewound_RewindState, | |
238 kNoRewindNecessary_RewindState, | |
239 kCouldNotRewind_RewindState | |
240 }; | |
241 /** | 236 /** |
242 * If the stream was previously read, attempt to rewind. | 237 * If the stream was previously read, attempt to rewind. |
243 * @returns: | 238 * |
244 * kRewound if the stream needed to be rewound, and the | 239 * If the stream needed to be rewound, call onRewind. |
245 * rewind succeeded. | 240 * @returns true if the codec is at the right position and can be used. |
246 * kNoRewindNecessary if the stream did not need to be | 241 * false if there was a failure to rewind. |
247 * rewound. | |
248 * kCouldNotRewind if the stream needed to be rewound, and | |
249 * rewind failed. | |
250 * | 242 * |
251 * Subclasses MUST call this function before reading the stream (e.g. in | 243 * Subclasses MUST call this function before reading the stream (e.g. in |
252 * onGetPixels). If it returns false, onGetPixels should return | 244 * onGetPixels). If it returns false, onGetPixels should return |
253 * kCouldNotRewind. | 245 * kCouldNotRewind. |
254 */ | 246 */ |
255 RewindState SK_WARN_UNUSED_RESULT rewindIfNeeded(); | 247 bool SK_WARN_UNUSED_RESULT rewindIfNeeded(); |
| 248 |
| 249 /** |
| 250 * Called by rewindIfNeeded, if the stream needed to be rewound. |
| 251 * |
| 252 * Subclasses should do any set up needed after a rewind. |
| 253 */ |
| 254 virtual bool onRewind() { |
| 255 return true; |
| 256 } |
256 | 257 |
257 /** | 258 /** |
258 * Get method for the input stream | 259 * Get method for the input stream |
259 */ | 260 */ |
260 SkStream* stream() { | 261 SkStream* stream() { |
261 return fStream.get(); | 262 return fStream.get(); |
262 } | 263 } |
263 | 264 |
264 private: | 265 private: |
265 const SkImageInfo fInfo; | 266 const SkImageInfo fInfo; |
266 SkAutoTDelete<SkStream> fStream; | 267 SkAutoTDelete<SkStream> fStream; |
267 bool fNeedsRewind; | 268 bool fNeedsRewind; |
268 }; | 269 }; |
269 #endif // SkCodec_DEFINED | 270 #endif // SkCodec_DEFINED |
OLD | NEW |