Home | History | Annotate | Download | only in images
      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"
     21 #include "SkTRegistry.h"
     22 
     23 typedef SkTRegistry<SkImageDecoder*, SkStream*> DecodeReg;
     24 
     25 template DecodeReg* DecodeReg::gHead;
     26 
     27 SkImageDecoder* SkImageDecoder::Factory(SkStream* stream) {
     28     const DecodeReg* curr = DecodeReg::Head();
     29     while (curr) {
     30         SkImageDecoder* codec = curr->factory()(stream);
     31         // we rewind here, because we promise later when we call "decode", that
     32         // the stream will be at its beginning.
     33         stream->rewind();
     34         if (codec) {
     35             return codec;
     36         }
     37         curr = curr->next();
     38     }
     39     return NULL;
     40 }
     41 
     42 /////////////////////////////////////////////////////////////////////////
     43 
     44 typedef SkTRegistry<SkMovie*, SkStream*> MovieReg;
     45 
     46 SkMovie* SkMovie::DecodeStream(SkStream* stream) {
     47     const MovieReg* curr = MovieReg::Head();
     48     while (curr) {
     49         SkMovie* movie = curr->factory()(stream);
     50         if (movie) {
     51             return movie;
     52         }
     53         // we must rewind only if we got NULL, since we gave the stream to the
     54         // movie, who may have already started reading from it
     55         stream->rewind();
     56         curr = curr->next();
     57     }
     58     return NULL;
     59 }
     60 
     61