| OLD | NEW |
| (Empty) |
| 1 | |
| 2 /* | |
| 3 * Copyright 2006 The Android Open Source Project | |
| 4 * | |
| 5 * Use of this source code is governed by a BSD-style license that can be | |
| 6 * found in the LICENSE file. | |
| 7 */ | |
| 8 | |
| 9 | |
| 10 #include "SkImageDecoder.h" | |
| 11 #include "SkMovie.h" | |
| 12 #include "SkStream.h" | |
| 13 #include "SkTRegistry.h" | |
| 14 | |
| 15 typedef SkTRegistry<SkImageDecoder*, SkStream*> DecodeReg; | |
| 16 | |
| 17 // N.B. You can't use "DecodeReg::gHead here" due to complex C++ | |
| 18 // corner cases. | |
| 19 template DecodeReg* SkTRegistry<SkImageDecoder*, SkStream*>::gHead; | |
| 20 | |
| 21 SkImageDecoder* SkImageDecoder::Factory(SkStream* stream) { | |
| 22 SkImageDecoder* codec = NULL; | |
| 23 const DecodeReg* curr = DecodeReg::Head(); | |
| 24 while (curr) { | |
| 25 codec = curr->factory()(stream); | |
| 26 // we rewind here, because we promise later when we call "decode", that | |
| 27 // the stream will be at its beginning. | |
| 28 bool rewindSuceeded = stream->rewind(); | |
| 29 | |
| 30 // our image decoder's require that rewind is supported so we fail early | |
| 31 // if we are given a stream that does not support rewinding. | |
| 32 if (!rewindSuceeded) { | |
| 33 SkDEBUGF(("Unable to rewind the image stream.")); | |
| 34 SkDELETE(codec); | |
| 35 return NULL; | |
| 36 } | |
| 37 | |
| 38 if (codec) { | |
| 39 return codec; | |
| 40 } | |
| 41 curr = curr->next(); | |
| 42 } | |
| 43 return NULL; | |
| 44 } | |
| 45 | |
| 46 ///////////////////////////////////////////////////////////////////////// | |
| 47 | |
| 48 typedef SkTRegistry<SkMovie*, SkStream*> MovieReg; | |
| 49 | |
| 50 SkMovie* SkMovie::DecodeStream(SkStream* stream) { | |
| 51 const MovieReg* curr = MovieReg::Head(); | |
| 52 while (curr) { | |
| 53 SkMovie* movie = curr->factory()(stream); | |
| 54 if (movie) { | |
| 55 return movie; | |
| 56 } | |
| 57 // we must rewind only if we got NULL, since we gave the stream to the | |
| 58 // movie, who may have already started reading from it | |
| 59 stream->rewind(); | |
| 60 curr = curr->next(); | |
| 61 } | |
| 62 return NULL; | |
| 63 } | |
| OLD | NEW |