Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(313)

Side by Side Diff: src/images/SkImageDecoder_Factory.cpp

Issue 670453002: Remove image decoder and encoder autoregistration (Closed) Base URL: https://skia.googlesource.com/skia.git@separate-image-decoder-01-skpicture
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/images/SkForceLinking.cpp ('k') | src/images/SkImageDecoder_FactoryDefault.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2014 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "SkErrorInternals.h"
9 #include "SkImageDecoder.h"
10 #include "SkImageDecoder_libjpeg.h"
11 #include "SkImageDecoder_libwebp.h"
12 #include "SkImageDecoder_libico.h"
13 #include "SkImageDecoder_libbmp.h"
14 #include "SkImageDecoder_wbmp.h"
15 #include "SkMovie.h"
16 #include "SkStream.h"
17
18 #if defined(SK_BUILD_FOR_WIN)
19 #include "SkImageDecoder_WIC.h"
20 #endif
21 #if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS)
22 #include "SkImageDecoder_CG.h"
23 #endif
24 #if !defined(SK_BUILD_FOR_MAC) && !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUIL D_FOR_WIN)
25 #include "SkImageDecoder_libpng.h"
26 #endif
27 #if !defined(SK_BUILD_FOR_MAC) && !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUIL D_FOR_WIN) && \
28 !defined(SK_BUILD_FOR_NACL)
29 #include "SkImageDecoder_libgif.h"
30 #include "SkMovie_gif.h"
31 #endif
32 #if !defined(SK_BUILD_FOR_ANDROID_FRAMEWORK)
33 #include "SkImageDecoder_astc.h"
34 #include "SkImageDecoder_ktx.h"
35 #include "SkImageDecoder_pkm.h"
36 #endif
37
38 // This file is used for registration of SkImageDecoders. It also holds a functi on for checking all
39 // the the registered SkImageDecoders for one that matches an input SkStreamRewi ndable.
40
41 // The order of the factory functions defines the order image decoders are teste d when decoding a
42 // stream. The first function is the first one tested, so the functions should b e listed in order
43 // from the most likely to be used, to the least likely. JPEG and PNG should be the first two, for
44 // instance.
45
46 typedef SkImageDecoder* (*FactoryCreateFunc)(SkImageDecoder::Format);
47 typedef SkImageDecoder::Format (*FactoryDetectFormatFunc)(SkStreamRewindable*);
48 static const struct {
49 const FactoryCreateFunc createFunc;
50 const FactoryDetectFormatFunc detectFormatFunc;
51 } gDecoderFactoryFuncs[] = {
52 #if !defined(SK_BUILD_FOR_MAC) && !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUIL D_FOR_WIN)
53 { SkCreatePNGImageDecoder, SkDetectFormatPNGImageDecoder },
54 #endif
55 { SkCreateJPEGImageDecoder, SkDetectFormatJPEGImageDecoder },
56 { SkCreateWEBPImageDecoder, SkDetectFormatWEBPImageDecoder },
57 { SkCreateICOImageDecoder, SkDetectFormatICOImageDecoder },
58 #if !defined(SK_BUILD_FOR_MAC) && !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUIL D_FOR_WIN) && \
59 !defined(SK_BUILD_FOR_NACL)
60 { SkCreateGIFImageDecoder, SkDetectFormatGIFImageDecoder },
61 #endif
62 { SkCreateBMPImageDecoder, SkDetectFormatBMPImageDecoder },
63 #if !defined(SK_BUILD_FOR_ANDROID_FRAMEWORK)
64 { SkCreateASTCImageDecoder, SkDetectFormatASTCImageDecoder },
65 { SkCreateKTXImageDecoder, SkDetectFormatKTXImageDecoder },
66 { SkCreatePKMImageDecoder, SkDetectFormatPKMImageDecoder },
67 #endif
68 { SkCreateWBMPImageDecoder, SkDetectFormatWBMPImageDecoder },
69 #if defined(SK_BUILD_FOR_WIN)
70 { SkCreateImageDecoder_WIC, SkDetectFormatImageDecoder_WIC }
71 #elif defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS)
72 { SkCreateImageDecoder_CG, SkDetectFormatImageDecoder_CG }
73 #endif
74 };
75
76 SkImageDecoder* SkImageDecoder::Factory(SkStreamRewindable* stream) {
77 for (size_t i = 0; i < SK_ARRAY_COUNT(gDecoderFactoryFuncs); ++i) {
78 FactoryDetectFormatFunc detectFormatFunc = gDecoderFactoryFuncs[i].detec tFormatFunc;
79 Format format = detectFormatFunc(stream);
80
81 // We rewind here, because we promise later when we call "decode", that the stream will be
82 // at its beginning.
83 bool rewindSuceeded = stream->rewind();
84
85 // Our image decoders require that rewind is supported so we fail early if we are given a
86 // stream that does not support rewinding.
87 if (!rewindSuceeded) {
88 SkDEBUGF(("Unable to rewind the image stream."));
89 return NULL;
90 }
91
92 if (SkImageDecoder::kUnknown_Format != format) {
93 FactoryCreateFunc createFunc = gDecoderFactoryFuncs[i].createFunc;
94 SkImageDecoder* codec = createFunc(format);
95 SkASSERT(NULL != codec);
96 return codec;
97 }
98 }
99 return NULL;
100 }
101
102 SkImageDecoder::Format SkImageDecoder::GetStreamFormat(SkStreamRewindable* strea m) {
103 for (size_t i = 0; i < SK_ARRAY_COUNT(gDecoderFactoryFuncs); ++i) {
104 FactoryDetectFormatFunc detectFormatFunc = gDecoderFactoryFuncs[i].detec tFormatFunc;
105 Format format = detectFormatFunc(stream);
106 if (!stream->rewind()) {
107 SkErrorInternals::SetError(kInvalidOperation_SkError,
108 "Unable to rewind the image stream\n");
109 return kUnknown_Format;
110 }
111 if (format != kUnknown_Format) {
112 return format;
113 }
114 }
115 return kUnknown_Format;
116 }
117
118 SkMovie* SkMovie::DecodeStream(SkStreamRewindable* stream) {
119 SkMovie* movie = NULL;
120 #if !defined(SK_BUILD_FOR_MAC) && !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUIL D_FOR_WIN) && \
121 !defined(SK_BUILD_FOR_NACL)
122 movie = SkGIFMovieCreate(stream);
123 if (NULL == movie) {
124 stream->rewind();
125 }
126 #endif
127 return movie;
128 }
OLDNEW
« no previous file with comments | « src/images/SkForceLinking.cpp ('k') | src/images/SkImageDecoder_FactoryDefault.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698