gfx/skia/trunk/src/images/SkImageDecoder_FactoryRegistrar.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /*
     2  * Copyright 2013 The Android Open Source Project
     3  *
     4  * Use of this source code is governed by a BSD-style license that can be
     5  * found in the LICENSE file.
     6  */
     8 #include "SkErrorInternals.h"
     9 #include "SkImageDecoder.h"
    10 #include "SkStream.h"
    11 #include "SkTRegistry.h"
    13 // This file is used for registration of SkImageDecoders. It also holds a function
    14 // for checking all the the registered SkImageDecoders for one that matches an
    15 // input SkStreamRewindable.
    17 template SkImageDecoder_DecodeReg* SkImageDecoder_DecodeReg::gHead;
    19 SkImageDecoder* image_decoder_from_stream(SkStreamRewindable*);
    21 SkImageDecoder* image_decoder_from_stream(SkStreamRewindable* stream) {
    22     SkImageDecoder* codec = NULL;
    23     const SkImageDecoder_DecodeReg* curr = SkImageDecoder_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();
    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         }
    38         if (codec) {
    39             return codec;
    40         }
    41         curr = curr->next();
    42     }
    43     return NULL;
    44 }
    46 template SkImageDecoder_FormatReg* SkImageDecoder_FormatReg::gHead;
    48 SkImageDecoder::Format SkImageDecoder::GetStreamFormat(SkStreamRewindable* stream) {
    49     const SkImageDecoder_FormatReg* curr = SkImageDecoder_FormatReg::Head();
    50     while (curr != NULL) {
    51         Format format = curr->factory()(stream);
    52         if (!stream->rewind()) {
    53             SkErrorInternals::SetError(kInvalidOperation_SkError,
    54                                        "Unable to rewind the image stream\n");
    55             return kUnknown_Format;
    56         }
    57         if (format != kUnknown_Format) {
    58             return format;
    59         }
    60         curr = curr->next();
    61     }
    62     return kUnknown_Format;
    63 }

mercurial