typedef SkRefCnt INHERITED;
};
-typedef SkTRegistry<SkBenchmark*, void*> BenchRegistry;
+typedef SkTRegistry<SkBenchmark*(*)(void*)> BenchRegistry;
#endif
SkString getName() { return fName; };
// Use this public registry to tell the world about your sample.
- typedef SkTRegistry<SkExample*, SkExampleWindow*> Registry;
+ typedef SkTRegistry<SkExample*(*)(SkExampleWindow*)> Registry;
protected:
SkExampleWindow* fWindow;
}
// need to explicitly declare this, or we get some weird infinite loop llist
-template GMRegistry* SkTRegistry<GM*, void*>::gHead;
+template GMRegistry* SkTRegistry<GM*(*)(void*)>::gHead;
bool fHaveCalledOnceBeforeDraw;
};
- typedef SkTRegistry<GM*, void*> GMRegistry;
+ typedef SkTRegistry<GM*(*)(void*)> GMRegistry;
}
#endif
#include "SkImage.h"
#include "SkRect.h"
#include "SkRefCnt.h"
+#include "SkTRegistry.h"
#include "SkTypes.h"
class SkStream;
DECLARE_DECODER_CREATOR(WBMPImageDecoder);
DECLARE_DECODER_CREATOR(WEBPImageDecoder);
+
+// Typedefs to make registering decoder and formatter callbacks easier.
+// These have to be defined outside SkImageDecoder. :(
+typedef SkTRegistry<SkImageDecoder*(*)(SkStream*)> SkImageDecoder_DecodeReg;
+typedef SkTRegistry<SkImageDecoder::Format(*)(SkStream*)> SkImageDecoder_FormatReg;
+
#endif
#define SkImageEncoder_DEFINED
#include "SkTypes.h"
+#include "SkTRegistry.h"
class SkBitmap;
class SkData;
DECLARE_ENCODER_CREATOR(PNGImageEncoder);
DECLARE_ENCODER_CREATOR(WEBPImageEncoder);
+// Typedef to make registering encoder callback easier
+// This has to be defined outside SkImageEncoder. :(
+typedef SkTRegistry<SkImageEncoder*(*)(SkImageEncoder::Type)> SkImageEncoder_EncodeReg;
#endif
and provides a function-pointer. This can be used to auto-register a set of
services, e.g. a set of image codecs.
*/
-template <typename T, typename P> class SkTRegistry : SkNoncopyable {
+template <typename T> class SkTRegistry : SkNoncopyable {
public:
- typedef T (*Factory)(P);
+ typedef T Factory;
- SkTRegistry(Factory fact) {
+ explicit SkTRegistry(T fact) : fFact(fact) {
#ifdef SK_BUILD_FOR_ANDROID
// work-around for double-initialization bug
{
}
}
#endif
- fFact = fact;
fChain = gHead;
- gHead = this;
+ gHead = this;
}
static const SkTRegistry* Head() { return gHead; }
const SkTRegistry* next() const { return fChain; }
- Factory factory() const { return fFact; }
+ const Factory& factory() const { return fFact; }
private:
Factory fFact;
};
// The caller still needs to declare an instance of this somewhere
-template <typename T, typename P> SkTRegistry<T, P>* SkTRegistry<T, P>::gHead;
+template <typename T> SkTRegistry<T>* SkTRegistry<T>::gHead;
#endif
#include "SkImageDecoder.h"
#include "SkMovie.h"
#include "SkStream.h"
-#include "SkTRegistry.h"
extern SkImageDecoder* image_decoder_from_stream(SkStream*);
/////////////////////////////////////////////////////////////////////////
-typedef SkTRegistry<SkMovie*, SkStream*> MovieReg;
+typedef SkTRegistry<SkMovie*(*)(SkStream*)> MovieReg;
SkMovie* SkMovie::DecodeStream(SkStream* stream) {
const MovieReg* curr = MovieReg::Head();
// for checking all the the registered SkImageDecoders for one that matches an
// input SkStream.
-typedef SkTRegistry<SkImageDecoder*, SkStream*> DecodeReg;
-
-// N.B. You can't use "DecodeReg::gHead here" due to complex C++
-// corner cases.
-template DecodeReg* SkTRegistry<SkImageDecoder*, SkStream*>::gHead;
+template SkImageDecoder_DecodeReg* SkImageDecoder_DecodeReg::gHead;
SkImageDecoder* image_decoder_from_stream(SkStream*);
SkImageDecoder* image_decoder_from_stream(SkStream* stream) {
SkImageDecoder* codec = NULL;
- const DecodeReg* curr = DecodeReg::Head();
+ const SkImageDecoder_DecodeReg* curr = SkImageDecoder_DecodeReg::Head();
while (curr) {
codec = curr->factory()(stream);
// we rewind here, because we promise later when we call "decode", that
return NULL;
}
-typedef SkTRegistry<SkImageDecoder::Format, SkStream*> FormatReg;
-
-template FormatReg* SkTRegistry<SkImageDecoder::Format, SkStream*>::gHead;
+template SkImageDecoder_FormatReg* SkImageDecoder_FormatReg::gHead;
SkImageDecoder::Format SkImageDecoder::GetStreamFormat(SkStream* stream) {
- const FormatReg* curr = FormatReg::Head();
+ const SkImageDecoder_FormatReg* curr = SkImageDecoder_FormatReg::Head();
while (curr != NULL) {
Format format = curr->factory()(stream);
if (!stream->rewind()) {
#include "SkStream.h"
#include "SkStreamHelpers.h"
#include "SkTDArray.h"
-#include "SkTRegistry.h"
class SkBMPImageDecoder : public SkImageDecoder {
public:
return NULL;
}
-static SkTRegistry<SkImageDecoder*, SkStream*> gReg(sk_libbmp_dfactory);
+static SkImageDecoder_DecodeReg gReg(sk_libbmp_dfactory);
static SkImageDecoder::Format get_format_bmp(SkStream* stream) {
if (is_bmp(stream)) {
return SkImageDecoder::kUnknown_Format;
}
-static SkTRegistry<SkImageDecoder::Format, SkStream*> gFormatReg(get_format_bmp);
+static SkImageDecoder_FormatReg gFormatReg(get_format_bmp);
///////////////////////////////////////////////////////////////////////////////
return false;
}
-#include "SkTRegistry.h"
-
static SkImageDecoder* sk_libgif_dfactory(SkStream* stream) {
if (is_gif(stream)) {
return SkNEW(SkGIFImageDecoder);
return NULL;
}
-static SkTRegistry<SkImageDecoder*, SkStream*> gReg(sk_libgif_dfactory);
+static SkImageDecoder_DecodeReg gReg(sk_libgif_dfactory);
static SkImageDecoder::Format get_format_gif(SkStream* stream) {
if (is_gif(stream)) {
return SkImageDecoder::kUnknown_Format;
}
-static SkTRegistry<SkImageDecoder::Format, SkStream*> gFormatReg(get_format_gif);
+static SkImageDecoder_FormatReg gFormatReg(get_format_gif);
return true;
}
-#include "SkTRegistry.h"
-
static SkImageDecoder* sk_libico_dfactory(SkStream* stream) {
if (is_ico(stream)) {
return SkNEW(SkICOImageDecoder);
return NULL;
}
-static SkTRegistry<SkImageDecoder*, SkStream*> gReg(sk_libico_dfactory);
+static SkImageDecoder_DecodeReg gReg(sk_libico_dfactory);
static SkImageDecoder::Format get_format_ico(SkStream* stream) {
if (is_ico(stream)) {
return SkImageDecoder::kUnknown_Format;
}
-static SkTRegistry<SkImageDecoder::Format, SkStream*> gFormatReg(get_format_ico);
+static SkImageDecoder_FormatReg gFormatReg(get_format_ico);
return true;
}
-#include "SkTRegistry.h"
-
static SkImageDecoder* sk_libjpeg_dfactory(SkStream* stream) {
if (is_jpeg(stream)) {
return SkNEW(SkJPEGImageDecoder);
}
-static SkTRegistry<SkImageDecoder*, SkStream*> gDReg(sk_libjpeg_dfactory);
-static SkTRegistry<SkImageDecoder::Format, SkStream*> gFormatReg(get_format_jpeg);
-static SkTRegistry<SkImageEncoder*, SkImageEncoder::Type> gEReg(sk_libjpeg_efactory);
+static SkImageDecoder_DecodeReg gDReg(sk_libjpeg_dfactory);
+static SkImageDecoder_FormatReg gFormatReg(get_format_jpeg);
+static SkImageEncoder_EncodeReg gEReg(sk_libjpeg_efactory);
DEFINE_ENCODER_CREATOR(PNGImageEncoder);
///////////////////////////////////////////////////////////////////////////////
-#include "SkTRegistry.h"
-
static bool is_png(SkStream* stream) {
char buf[PNG_BYTES_TO_CHECK];
if (stream->read(buf, PNG_BYTES_TO_CHECK) == PNG_BYTES_TO_CHECK &&
return (SkImageEncoder::kPNG_Type == t) ? SkNEW(SkPNGImageEncoder) : NULL;
}
-static SkTRegistry<SkImageEncoder*, SkImageEncoder::Type> gEReg(sk_libpng_efactory);
-static SkTRegistry<SkImageDecoder::Format, SkStream*> gFormatReg(get_format_png);
-static SkTRegistry<SkImageDecoder*, SkStream*> gDReg(sk_libpng_dfactory);
+static SkImageDecoder_DecodeReg gDReg(sk_libpng_dfactory);
+static SkImageDecoder_FormatReg gFormatReg(get_format_png);
+static SkImageEncoder_EncodeReg gEReg(sk_libpng_efactory);
DEFINE_ENCODER_CREATOR(WEBPImageEncoder);
///////////////////////////////////////////////////////////////////////////////
-#include "SkTRegistry.h"
-
static SkImageDecoder* sk_libwebp_dfactory(SkStream* stream) {
int width, height, hasAlpha;
if (!webp_parse_header(stream, &width, &height, &hasAlpha)) {
return (SkImageEncoder::kWEBP_Type == t) ? SkNEW(SkWEBPImageEncoder) : NULL;
}
-static SkTRegistry<SkImageDecoder*, SkStream*> gDReg(sk_libwebp_dfactory);
-static SkTRegistry<SkImageDecoder::Format, SkStream*> gFormatReg(get_format_webp);
-static SkTRegistry<SkImageEncoder*, SkImageEncoder::Type> gEReg(sk_libwebp_efactory);
+static SkImageDecoder_DecodeReg gDReg(sk_libwebp_dfactory);
+static SkImageDecoder_FormatReg gFormatReg(get_format_webp);
+static SkImageEncoder_EncodeReg gEReg(sk_libwebp_efactory);
DEFINE_DECODER_CREATOR(WBMPImageDecoder);
///////////////////////////////////////////////////////////////////////////////
-#include "SkTRegistry.h"
-
static SkImageDecoder* sk_wbmp_dfactory(SkStream* stream) {
wbmp_head head;
return SkImageDecoder::kUnknown_Format;
}
-static SkTRegistry<SkImageDecoder*, SkStream*> gReg(sk_wbmp_dfactory);
-static SkTRegistry<SkImageDecoder::Format, SkStream*> gFormatReg(get_format_wbmp);
+static SkImageDecoder_DecodeReg gDReg(sk_wbmp_dfactory);
+static SkImageDecoder_FormatReg gFormatReg(get_format_wbmp);
* found in the LICENSE file.
*/
-
#include "SkImageEncoder.h"
-#include "SkTRegistry.h"
-
-typedef SkTRegistry<SkImageEncoder*, SkImageEncoder::Type> EncodeReg;
-// Can't use the typedef here because of complex C++ corner cases
-template EncodeReg* SkTRegistry<SkImageEncoder*, SkImageEncoder::Type>::gHead;
+template SkImageEncoder_EncodeReg* SkImageEncoder_EncodeReg::gHead;
SkImageEncoder* SkImageEncoder::Create(Type t) {
SkImageEncoder* codec = NULL;
- const EncodeReg* curr = EncodeReg::Head();
+ const SkImageEncoder_EncodeReg* curr = SkImageEncoder_EncodeReg::Head();
while (curr) {
if ((codec = curr->factory()(t)) != NULL) {
return codec;
return NULL;
}
-static SkTRegistry<SkMovie*, SkStream*> gReg(Factory);
+static SkTRegistry<SkMovie*(*)(SkStream*)> gReg(Factory);
return SkNEW_ARGS(SkImageEncoder_CG, (t));
}
-static SkTRegistry<SkImageEncoder*, SkImageEncoder::Type> gEReg(sk_imageencoder_cg_factory);
+static SkTRegistry<SkImageEncoder*(*)(SkImageEncoder::Type)> gEReg(sk_imageencoder_cg_factory);
struct FormatConversion {
CFStringRef fUTType;
return UTType_to_Format(name);
}
-static SkTRegistry<SkImageDecoder::Format, SkStream*> gFormatReg(get_format_cg);
+static SkTRegistry<SkImageDecoder::Format(*)(SkStream*)> gFormatReg(get_format_cg);
return SkNEW_ARGS(SkImageEncoder_WIC, (t));
}
-static SkTRegistry<SkImageEncoder*, SkImageEncoder::Type> gEReg(sk_imageencoder_wic_factory);
+static SkTRegistry<SkImageEncoder*(*)(SkImageEncoder::Type)> gEReg(sk_imageencoder_wic_factory);
static SkImageDecoder::Format get_format_wic(SkStream* stream) {
SkImageDecoder::Format format;
return format;
}
-static SkTRegistry<SkImageDecoder::Format, SkStream*> gFormatReg(get_format_wic);
+static SkTRegistry<SkImageDecoder::Format(*)(SkStream*)> gFormatReg(get_format_wic);
private:
};
- typedef SkTRegistry<Test*, void*> TestRegistry;
+ typedef SkTRegistry<Test*(*)(void*)> TestRegistry;
}
#define REPORTER_ASSERT(r, cond) \