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

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

Issue 23453031: Rewrite SkTRegistry to take any trivially-copyable type. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: reed+scroggo Created 7 years, 3 months 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 | Annotate | Revision Log
« no previous file with comments | « src/images/SkImageDecoder_FactoryDefault.cpp ('k') | src/images/SkImageDecoder_libbmp.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2013 The Android Open Source Project 2 * Copyright 2013 The Android Open Source Project
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkErrorInternals.h" 8 #include "SkErrorInternals.h"
9 #include "SkImageDecoder.h" 9 #include "SkImageDecoder.h"
10 #include "SkStream.h" 10 #include "SkStream.h"
11 #include "SkTRegistry.h" 11 #include "SkTRegistry.h"
12 12
13 // This file is used for registration of SkImageDecoders. It also holds a functi on 13 // This file is used for registration of SkImageDecoders. It also holds a functi on
14 // for checking all the the registered SkImageDecoders for one that matches an 14 // for checking all the the registered SkImageDecoders for one that matches an
15 // input SkStream. 15 // input SkStream.
16 16
17 typedef SkTRegistry<SkImageDecoder*, SkStream*> DecodeReg; 17 template SkImageDecoder_DecodeReg* SkImageDecoder_DecodeReg::gHead;
18
19 // N.B. You can't use "DecodeReg::gHead here" due to complex C++
20 // corner cases.
21 template DecodeReg* SkTRegistry<SkImageDecoder*, SkStream*>::gHead;
22 18
23 SkImageDecoder* image_decoder_from_stream(SkStream*); 19 SkImageDecoder* image_decoder_from_stream(SkStream*);
24 20
25 SkImageDecoder* image_decoder_from_stream(SkStream* stream) { 21 SkImageDecoder* image_decoder_from_stream(SkStream* stream) {
26 SkImageDecoder* codec = NULL; 22 SkImageDecoder* codec = NULL;
27 const DecodeReg* curr = DecodeReg::Head(); 23 const SkImageDecoder_DecodeReg* curr = SkImageDecoder_DecodeReg::Head();
28 while (curr) { 24 while (curr) {
29 codec = curr->factory()(stream); 25 codec = curr->factory()(stream);
30 // we rewind here, because we promise later when we call "decode", that 26 // we rewind here, because we promise later when we call "decode", that
31 // the stream will be at its beginning. 27 // the stream will be at its beginning.
32 bool rewindSuceeded = stream->rewind(); 28 bool rewindSuceeded = stream->rewind();
33 29
34 // our image decoder's require that rewind is supported so we fail early 30 // our image decoder's require that rewind is supported so we fail early
35 // if we are given a stream that does not support rewinding. 31 // if we are given a stream that does not support rewinding.
36 if (!rewindSuceeded) { 32 if (!rewindSuceeded) {
37 SkDEBUGF(("Unable to rewind the image stream.")); 33 SkDEBUGF(("Unable to rewind the image stream."));
38 SkDELETE(codec); 34 SkDELETE(codec);
39 return NULL; 35 return NULL;
40 } 36 }
41 37
42 if (codec) { 38 if (codec) {
43 return codec; 39 return codec;
44 } 40 }
45 curr = curr->next(); 41 curr = curr->next();
46 } 42 }
47 return NULL; 43 return NULL;
48 } 44 }
49 45
50 typedef SkTRegistry<SkImageDecoder::Format, SkStream*> FormatReg; 46 template SkImageDecoder_FormatReg* SkImageDecoder_FormatReg::gHead;
51
52 template FormatReg* SkTRegistry<SkImageDecoder::Format, SkStream*>::gHead;
53 47
54 SkImageDecoder::Format SkImageDecoder::GetStreamFormat(SkStream* stream) { 48 SkImageDecoder::Format SkImageDecoder::GetStreamFormat(SkStream* stream) {
55 const FormatReg* curr = FormatReg::Head(); 49 const SkImageDecoder_FormatReg* curr = SkImageDecoder_FormatReg::Head();
56 while (curr != NULL) { 50 while (curr != NULL) {
57 Format format = curr->factory()(stream); 51 Format format = curr->factory()(stream);
58 if (!stream->rewind()) { 52 if (!stream->rewind()) {
59 SkErrorInternals::SetError(kInvalidOperation_SkError, 53 SkErrorInternals::SetError(kInvalidOperation_SkError,
60 "Unable to rewind the image stream\n"); 54 "Unable to rewind the image stream\n");
61 return kUnknown_Format; 55 return kUnknown_Format;
62 } 56 }
63 if (format != kUnknown_Format) { 57 if (format != kUnknown_Format) {
64 return format; 58 return format;
65 } 59 }
66 curr = curr->next(); 60 curr = curr->next();
67 } 61 }
68 return kUnknown_Format; 62 return kUnknown_Format;
69 } 63 }
OLDNEW
« no previous file with comments | « src/images/SkImageDecoder_FactoryDefault.cpp ('k') | src/images/SkImageDecoder_libbmp.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698