reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1 | /* libs/graphics/ports/SkImageDecoder_Factory.cpp |
| 2 | ** |
| 3 | ** Copyright 2006, The Android Open Source Project |
| 4 | ** |
| 5 | ** Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | ** you may not use this file except in compliance with the License. |
| 7 | ** You may obtain a copy of the License at |
| 8 | ** |
| 9 | ** http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | ** |
| 11 | ** Unless required by applicable law or agreed to in writing, software |
| 12 | ** distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | ** See the License for the specific language governing permissions and |
| 15 | ** limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | #include "SkImageDecoder.h" |
| 19 | #include "SkMovie.h" |
| 20 | #include "SkStream.h" |
reed@android.com | 00bf85a | 2009-01-22 13:04:56 +0000 | [diff] [blame] | 21 | #include "SkTRegistry.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 22 | |
reed@android.com | 00bf85a | 2009-01-22 13:04:56 +0000 | [diff] [blame] | 23 | typedef SkTRegistry<SkImageDecoder*, SkStream*> DecodeReg; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 24 | |
agl@chromium.org | 39d39c2 | 2010-05-10 21:20:58 +0000 | [diff] [blame] | 25 | template<> DecodeReg* DecodeReg::gHead; |
reed@android.com | 3c2b7e8 | 2009-01-27 01:43:36 +0000 | [diff] [blame] | 26 | |
reed@android.com | dfee579 | 2010-04-15 14:24:50 +0000 | [diff] [blame] | 27 | #ifdef SK_ENABLE_LIBPNG |
| 28 | extern SkImageDecoder* sk_libpng_dfactory(SkStream*); |
| 29 | #endif |
| 30 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 31 | SkImageDecoder* SkImageDecoder::Factory(SkStream* stream) { |
reed@android.com | dfee579 | 2010-04-15 14:24:50 +0000 | [diff] [blame] | 32 | SkImageDecoder* codec = NULL; |
reed@android.com | 00bf85a | 2009-01-22 13:04:56 +0000 | [diff] [blame] | 33 | const DecodeReg* curr = DecodeReg::Head(); |
| 34 | while (curr) { |
reed@android.com | dfee579 | 2010-04-15 14:24:50 +0000 | [diff] [blame] | 35 | codec = curr->factory()(stream); |
reed@android.com | a16cb97 | 2009-06-18 20:26:58 +0000 | [diff] [blame] | 36 | // we rewind here, because we promise later when we call "decode", that |
| 37 | // the stream will be at its beginning. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 38 | stream->rewind(); |
reed@android.com | 00bf85a | 2009-01-22 13:04:56 +0000 | [diff] [blame] | 39 | if (codec) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 40 | return codec; |
| 41 | } |
reed@android.com | 00bf85a | 2009-01-22 13:04:56 +0000 | [diff] [blame] | 42 | curr = curr->next(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 43 | } |
reed@android.com | dfee579 | 2010-04-15 14:24:50 +0000 | [diff] [blame] | 44 | #ifdef SK_ENABLE_LIBPNG |
| 45 | codec = sk_libpng_dfactory(stream); |
| 46 | stream->rewind(); |
| 47 | if (codec) { |
| 48 | return codec; |
| 49 | } |
| 50 | #endif |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 51 | return NULL; |
| 52 | } |
| 53 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 54 | ///////////////////////////////////////////////////////////////////////// |
| 55 | |
reed@android.com | 00bf85a | 2009-01-22 13:04:56 +0000 | [diff] [blame] | 56 | typedef SkTRegistry<SkMovie*, SkStream*> MovieReg; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 57 | |
| 58 | SkMovie* SkMovie::DecodeStream(SkStream* stream) { |
reed@android.com | 00bf85a | 2009-01-22 13:04:56 +0000 | [diff] [blame] | 59 | const MovieReg* curr = MovieReg::Head(); |
| 60 | while (curr) { |
| 61 | SkMovie* movie = curr->factory()(stream); |
| 62 | if (movie) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 63 | return movie; |
| 64 | } |
reed@android.com | a16cb97 | 2009-06-18 20:26:58 +0000 | [diff] [blame] | 65 | // we must rewind only if we got NULL, since we gave the stream to the |
| 66 | // movie, who may have already started reading from it |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 67 | stream->rewind(); |
reed@android.com | 00bf85a | 2009-01-22 13:04:56 +0000 | [diff] [blame] | 68 | curr = curr->next(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 69 | } |
| 70 | return NULL; |
| 71 | } |
| 72 | |