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

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: 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
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 typedef SkTRegistry<SkImageDecoder*(*)(SkStream*)> DecodeReg;
18 18
19 // N.B. You can't use "DecodeReg::gHead here" due to complex C++ 19 // N.B. You can't use "DecodeReg::gHead here" due to complex C++
20 // corner cases. 20 // corner cases.
21 template DecodeReg* SkTRegistry<SkImageDecoder*, SkStream*>::gHead; 21 template DecodeReg* SkTRegistry<SkImageDecoder*(*)(SkStream*)>::gHead;
22 22
23 SkImageDecoder* image_decoder_from_stream(SkStream*); 23 SkImageDecoder* image_decoder_from_stream(SkStream*);
24 24
25 SkImageDecoder* image_decoder_from_stream(SkStream* stream) { 25 SkImageDecoder* image_decoder_from_stream(SkStream* stream) {
26 SkImageDecoder* codec = NULL; 26 SkImageDecoder* codec = NULL;
27 const DecodeReg* curr = DecodeReg::Head(); 27 const DecodeReg* curr = DecodeReg::Head();
28 while (curr) { 28 while (curr) {
29 codec = curr->factory()(stream); 29 codec = curr->data()(stream);
30 // we rewind here, because we promise later when we call "decode", that 30 // we rewind here, because we promise later when we call "decode", that
31 // the stream will be at its beginning. 31 // the stream will be at its beginning.
32 bool rewindSuceeded = stream->rewind(); 32 bool rewindSuceeded = stream->rewind();
33 33
34 // our image decoder's require that rewind is supported so we fail early 34 // 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. 35 // if we are given a stream that does not support rewinding.
36 if (!rewindSuceeded) { 36 if (!rewindSuceeded) {
37 SkDEBUGF(("Unable to rewind the image stream.")); 37 SkDEBUGF(("Unable to rewind the image stream."));
38 SkDELETE(codec); 38 SkDELETE(codec);
39 return NULL; 39 return NULL;
40 } 40 }
41 41
42 if (codec) { 42 if (codec) {
43 return codec; 43 return codec;
44 } 44 }
45 curr = curr->next(); 45 curr = curr->next();
46 } 46 }
47 return NULL; 47 return NULL;
48 } 48 }
49 49
50 typedef SkTRegistry<SkImageDecoder::Format, SkStream*> FormatReg; 50 typedef SkTRegistry<SkImageDecoder::Format(*)(SkStream*)> FormatReg;
51 51
52 template FormatReg* SkTRegistry<SkImageDecoder::Format, SkStream*>::gHead; 52 template FormatReg* SkTRegistry<SkImageDecoder::Format(*)(SkStream*)>::gHead;
53 53
54 SkImageDecoder::Format SkImageDecoder::GetStreamFormat(SkStream* stream) { 54 SkImageDecoder::Format SkImageDecoder::GetStreamFormat(SkStream* stream) {
55 const FormatReg* curr = FormatReg::Head(); 55 const FormatReg* curr = FormatReg::Head();
56 while (curr != NULL) { 56 while (curr != NULL) {
57 Format format = curr->factory()(stream); 57 Format format = curr->data()(stream);
58 if (!stream->rewind()) { 58 if (!stream->rewind()) {
59 SkErrorInternals::SetError(kInvalidOperation_SkError, 59 SkErrorInternals::SetError(kInvalidOperation_SkError,
60 "Unable to rewind the image stream\n"); 60 "Unable to rewind the image stream\n");
61 return kUnknown_Format; 61 return kUnknown_Format;
62 } 62 }
63 if (format != kUnknown_Format) { 63 if (format != kUnknown_Format) {
64 return format; 64 return format;
65 } 65 }
66 curr = curr->next(); 66 curr = curr->next();
67 } 67 }
68 return kUnknown_Format; 68 return kUnknown_Format;
69 } 69 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698