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