 Chromium Code Reviews
 Chromium Code Reviews Issue 670453002:
  Remove image decoder and encoder autoregistration  (Closed) 
  Base URL: https://skia.googlesource.com/skia.git@separate-image-decoder-01-skpicture
    
  
    Issue 670453002:
  Remove image decoder and encoder autoregistration  (Closed) 
  Base URL: https://skia.googlesource.com/skia.git@separate-image-decoder-01-skpicture| Index: src/images/SkImageDecoder_Factory.cpp | 
| diff --git a/src/images/SkImageDecoder_Factory.cpp b/src/images/SkImageDecoder_Factory.cpp | 
| new file mode 100644 | 
| index 0000000000000000000000000000000000000000..9018ff6429101db1cfb748e37ace50cf8c26fa3a | 
| --- /dev/null | 
| +++ b/src/images/SkImageDecoder_Factory.cpp | 
| @@ -0,0 +1,117 @@ | 
| +/* | 
| + * Copyright 2013 The Android Open Source Project | 
| 
scroggo
2014/11/12 18:00:12
2014 Google Inc
 
Kimmo Kinnunen
2014/11/18 08:29:44
Done.
 | 
| + * | 
| + * Use of this source code is governed by a BSD-style license that can be | 
| + * found in the LICENSE file. | 
| + */ | 
| + | 
| +#include "SkErrorInternals.h" | 
| +#include "SkImageDecoder.h" | 
| +#include "SkStream.h" | 
| + | 
| +#include "SkImageDecoder_libjpeg.h" | 
| +#include "SkImageDecoder_libwebp.h" | 
| +#include "SkImageDecoder_libico.h" | 
| +#include "SkImageDecoder_libbmp.h" | 
| +#include "SkImageDecoder_wbmp.h" | 
| + | 
| +#if defined(SK_BUILD_FOR_WIN) | 
| +#include "SkImageDecoder_WIC.h" | 
| +#endif | 
| +#if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS) | 
| +#include "SkImageDecoder_CG.h" | 
| +#endif | 
| +#if !defined(SK_BUILD_FOR_MAC) && !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_WIN) | 
| +#include "SkImageDecoder_libpng.h" | 
| +#endif | 
| +#if !defined(SK_BUILD_FOR_MAC) && !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_WIN) && !defined(SK_BUILD_FOR_NACL) | 
| 
scroggo
2014/11/12 18:00:12
line too long.
 
Kimmo Kinnunen
2014/11/18 08:29:44
Done. Sorry about the whitespace problems, I've fi
 | 
| +#include "SkImageDecoder_libgif.h" | 
| +#include "SkMovie_gif.h" | 
| +#endif | 
| +#if !defined(SK_BUILD_FOR_ANDROID_FRAMEWORK) | 
| +#include "SkImageDecoder_astc.h" | 
| +#include "SkImageDecoder_ktx.h" | 
| +#include "SkImageDecoder_pkm.h" | 
| +#endif | 
| + | 
| +// This file is used for registration of SkImageDecoders. It also holds a function | 
| +// for checking all the the registered SkImageDecoders for one that matches an | 
| +// input SkStreamRewindable. | 
| + | 
| +typedef SkImageDecoder* (*FactoryCreateFunc)(SkStreamRewindable*); | 
| +typedef SkImageDecoder::Format (*FactoryDetectFormatFunc)(SkStreamRewindable*); | 
| +static const struct { | 
| + FactoryCreateFunc createFunc; | 
| + FactoryDetectFormatFunc getFormatFunc; | 
| +} gDecoderFactoryFuncs[] = { | 
| 
scroggo
2014/11/12 18:00:12
Could you add a comment here that the order is mea
 
Kimmo Kinnunen
2014/11/18 08:29:44
Done.
 | 
| +#if defined(SK_BUILD_FOR_WIN) | 
| + { SkCreateImageDecoder_WIC, SkDetectFormatImageDecoder_WIC }, | 
| +#endif | 
| +#if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS) | 
| + { SkCreateImageDecoder_CG, SkDetectFormatImageDecoder_CG }, | 
| +#endif | 
| +#if !defined(SK_BUILD_FOR_MAC) && !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_WIN) | 
| + { SkCreatePNGImageDecoder, SkDetectFormatPNGImageDecoder }, | 
| +#endif | 
| + { SkCreateJPEGImageDecoder, SkDetectFormatJPEGImageDecoder }, | 
| + { SkCreateWEBPImageDecoder, SkDetectFormatWEBPImageDecoder }, | 
| + { SkCreateICOImageDecoder, SkDetectFormatICOImageDecoder }, | 
| +#if !defined(SK_BUILD_FOR_MAC) && !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_WIN) && !defined(SK_BUILD_FOR_NACL) | 
| 
scroggo
2014/11/12 18:00:12
line too long
 
Kimmo Kinnunen
2014/11/18 08:29:44
Done.
 | 
| + { SkCreateGIFImageDecoder, SkDetectFormatGIFImageDecoder }, | 
| +#endif | 
| + { SkCreateBMPImageDecoder, SkDetectFormatBMPImageDecoder }, | 
| +#if !defined(SK_BUILD_FOR_ANDROID_FRAMEWORK) | 
| + { SkCreateASTCImageDecoder, SkDetectFormatASTCImageDecoder }, | 
| + { SkCreateKTXImageDecoder, SkDetectFormatKTXImageDecoder }, | 
| + { SkCreatePKMImageDecoder, SkDetectFormatPKMImageDecoder }, | 
| +#endif | 
| + { SkCreateWBMPImageDecoder, SkDetectFormatWBMPImageDecoder } | 
| +}; | 
| + | 
| +SkImageDecoder* SkImageDecoder::Factory(SkStreamRewindable* stream) { | 
| + SkImageDecoder* codec = NULL; | 
| + for (size_t i = 0; i < SK_ARRAY_COUNT(gDecoderFactoryFuncs); ++i) { | 
| + FactoryCreateFunc createFunc = gDecoderFactoryFuncs[i].createFunc; | 
| 
scroggo
2014/11/12 18:00:12
Here's a thought:
I notice that in every one of t
 
Kimmo Kinnunen
2014/11/18 08:29:44
...
 
scroggo
2014/11/18 16:52:23
The issue isn't so much having two three-line func
 | 
| + codec = createFunc(stream); | 
| + // we rewind here, because we promise later when we call "decode", that | 
| + // the stream will be at its beginning. | 
| + bool rewindSuceeded = stream->rewind(); | 
| + | 
| + // our image decoder's require that rewind is supported so we fail early | 
| 
scroggo
2014/11/12 18:00:12
decoders*
(I know this duplicating an old typo, b
 
Kimmo Kinnunen
2014/11/18 08:29:44
Done.
 | 
| + // if we are given a stream that does not support rewinding. | 
| + if (!rewindSuceeded) { | 
| + SkDEBUGF(("Unable to rewind the image stream.")); | 
| + SkDELETE(codec); | 
| + return NULL; | 
| + } | 
| + | 
| + if (codec) { | 
| + return codec; | 
| + } | 
| + } | 
| + return NULL; | 
| +} | 
| + | 
| +SkImageDecoder::Format SkImageDecoder::GetStreamFormat(SkStreamRewindable* stream) { | 
| + for (size_t i = 0; i < SK_ARRAY_COUNT(gDecoderFactoryFuncs); ++i) { | 
| + FactoryDetectFormatFunc detectFormatFunc = gDecoderFactoryFuncs[i].getFormatFunc; | 
| + Format format = detectFormatFunc(stream); | 
| + if (!stream->rewind()) { | 
| + SkErrorInternals::SetError(kInvalidOperation_SkError, | 
| + "Unable to rewind the image stream\n"); | 
| + return kUnknown_Format; | 
| + } | 
| + if (format != kUnknown_Format) { | 
| + return format; | 
| + } | 
| + } | 
| + return kUnknown_Format; | 
| +} | 
| + | 
| +SkMovie* SkMovie::DecodeStream(SkStreamRewindable* stream) { | 
| + SkMovie* movie = NULL; | 
| +#if !defined(SK_BUILD_FOR_MAC) && !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_WIN) && !defined(SK_BUILD_FOR_NACL) | 
| 
scroggo
2014/11/12 18:00:12
line too long
 
Kimmo Kinnunen
2014/11/18 08:29:45
Done.
 | 
| + movie = SkGIFMovieCreate(stream); | 
| 
scroggo
2014/11/12 18:00:12
The old code does a rewind if movie is null.
 
Kimmo Kinnunen
2014/11/18 08:29:45
Done.
 | 
| +#endif | 
| + return movie; | 
| +} |