aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar robertphillips@google.com <robertphillips@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-03-23 18:13:47 +0000
committerGravatar robertphillips@google.com <robertphillips@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-03-23 18:13:47 +0000
commitec51cb863409e238b40c5beef458669d9a824481 (patch)
tree224efaf870e226bf8f95612ab3dda9bc03284ae8
parent34f10260adb55301572d4e67414b747c83ee015a (diff)
Improved codec link-forcing system by adding Encoder/Decoder creation entry points
-rw-r--r--gm/cmykjpeg.cpp4
-rw-r--r--include/images/SkImageDecoder.h20
-rw-r--r--include/images/SkImageEncoder.h17
-rw-r--r--src/images/SkImageDecoder_Factory.cpp31
-rw-r--r--src/images/SkImageDecoder_libbmp.cpp4
-rw-r--r--src/images/SkImageDecoder_libgif.cpp2
-rw-r--r--src/images/SkImageDecoder_libico.cpp2
-rw-r--r--src/images/SkImageDecoder_libjpeg.cpp5
-rw-r--r--src/images/SkImageDecoder_libpng.cpp3
-rw-r--r--src/images/SkImageDecoder_wbmp.cpp2
10 files changed, 58 insertions, 32 deletions
diff --git a/gm/cmykjpeg.cpp b/gm/cmykjpeg.cpp
index 67d2a60451..224aaecbbb 100644
--- a/gm/cmykjpeg.cpp
+++ b/gm/cmykjpeg.cpp
@@ -61,6 +61,10 @@ private:
typedef GM INHERITED;
};
+void forceLinking() {
+ SkImageDecoder *creator = CreateJPEGImageDecoder();
+}
+
//////////////////////////////////////////////////////////////////////////////
static GM* MyFactory(void*) { return new CMYKJpegGM; }
diff --git a/include/images/SkImageDecoder.h b/include/images/SkImageDecoder.h
index cbae8b1721..d0c4d21ddc 100644
--- a/include/images/SkImageDecoder.h
+++ b/include/images/SkImageDecoder.h
@@ -332,5 +332,25 @@ public:
}
};
+// This macro declares a global (i.e., non-class owned) creation entry point
+// for each decoder (e.g., CreateJPEGImageDecoder)
+#define DECLARE_DECODER_CREATOR(codec) \
+ SkImageDecoder *Create ## codec ();
+
+// This macro defines the global creation entry point for each decoder. Each
+// decoder implementation that registers with the decoder factory must call it.
+#define DEFINE_DECODER_CREATOR(codec) \
+ SkImageDecoder *Create ## codec () { \
+ return SkNEW( Sk ## codec ); \
+ }
+
+// All the decoders known by Skia. Note that, depending on the compiler settings,
+// not all of these will be available
+DECLARE_DECODER_CREATOR(BMPImageDecoder);
+DECLARE_DECODER_CREATOR(GIFImageDecoder);
+DECLARE_DECODER_CREATOR(ICOImageDecoder);
+DECLARE_DECODER_CREATOR(JPEGImageDecoder);
+DECLARE_DECODER_CREATOR(PNGImageDecoder);
+DECLARE_DECODER_CREATOR(WBMPImageDecoder);
#endif
diff --git a/include/images/SkImageEncoder.h b/include/images/SkImageEncoder.h
index b2f8cb67cc..907e28b9de 100644
--- a/include/images/SkImageEncoder.h
+++ b/include/images/SkImageEncoder.h
@@ -40,4 +40,21 @@ protected:
virtual bool onEncode(SkWStream*, const SkBitmap&, int quality) = 0;
};
+// This macro declares a global (i.e., non-class owned) creation entry point
+// for each encoder (e.g., CreateJPEGImageEncoder)
+#define DECLARE_ENCODER_CREATOR(codec) \
+ SkImageEncoder *Create ## codec ();
+
+// This macro defines the global creation entry point for each encoder. Each
+// encoder implementation that registers with the encoder factory must call it.
+#define DEFINE_ENCODER_CREATOR(codec) \
+ SkImageEncoder *Create ## codec () { \
+ return SkNEW( Sk ## codec ); \
+ }
+
+// All the encoders known by Skia. Note that, depending on the compiler settings,
+// not all of these will be available
+DECLARE_ENCODER_CREATOR(JPEGImageEncoder);
+DECLARE_ENCODER_CREATOR(PNGImageEncoder);
+
#endif
diff --git a/src/images/SkImageDecoder_Factory.cpp b/src/images/SkImageDecoder_Factory.cpp
index 2825f0d505..f3cb120a47 100644
--- a/src/images/SkImageDecoder_Factory.cpp
+++ b/src/images/SkImageDecoder_Factory.cpp
@@ -12,37 +12,6 @@
#include "SkStream.h"
#include "SkTRegistry.h"
-//extern SkImageDecoder* sk_libbmp_dfactory(SkStream*);
-//extern SkImageDecoder* sk_libgif_dfactory(SkStream*);
-//extern SkImageDecoder* sk_libico_dfactory(SkStream*);
-//extern SkImageDecoder* sk_libjpeg_dfactory(SkStream*);
-//extern SkImageDecoder* sk_libpng_dfactory(SkStream*);
-//extern SkImageDecoder* sk_wbmp_dfactory(SkStream*);
-
-// To get the various image decoding classes to register themselves
-// pre-main we need to ensure they are linked into the application.
-// Ultimately we need to move to using DLLs rather than tightly
-// coupling the factory with the file format classes.
-void ForceLinking()
-{
- SkImageDecoder* codec = NULL;
-
- // TODO: rather than force the linking here expose a
- // "Sk*ImageDecoderCreate" function for each codec
- // and let the app add these calls to force the linking.
- // Besides decoupling the codecs from the factory this
- // will also give the app the ability to circumvent the
- // factory and explicitly create a decoder w/o reaching
- // into Skia's guts
-
-// codec = sk_libbmp_dfactory(NULL);
-// codec = sk_libgif_dfactory(NULL);
-// codec = sk_libico_dfactory(NULL);
-// codec = sk_libjpeg_dfactory(NULL);
-// codec = sk_libpng_dfactory(NULL);
-// codec = sk_wbmp_dfactory(NULL);
-}
-
typedef SkTRegistry<SkImageDecoder*, SkStream*> DecodeReg;
// N.B. You can't use "DecodeReg::gHead here" due to complex C++
diff --git a/src/images/SkImageDecoder_libbmp.cpp b/src/images/SkImageDecoder_libbmp.cpp
index 8683e21a7f..fa752956ea 100644
--- a/src/images/SkImageDecoder_libbmp.cpp
+++ b/src/images/SkImageDecoder_libbmp.cpp
@@ -27,6 +27,10 @@ protected:
virtual bool onDecode(SkStream* stream, SkBitmap* bm, Mode mode);
};
+///////////////////////////////////////////////////////////////////////////////
+DEFINE_DECODER_CREATOR(BMPImageDecoder);
+///////////////////////////////////////////////////////////////////////////////
+
SkImageDecoder* sk_libbmp_dfactory(SkStream* stream) {
static const char kBmpMagic[] = { 'B', 'M' };
diff --git a/src/images/SkImageDecoder_libgif.cpp b/src/images/SkImageDecoder_libgif.cpp
index 3bc33c3d07..cd4ee223f5 100644
--- a/src/images/SkImageDecoder_libgif.cpp
+++ b/src/images/SkImageDecoder_libgif.cpp
@@ -327,6 +327,8 @@ DONE:
}
///////////////////////////////////////////////////////////////////////////////
+DEFINE_DECODER_CREATOR(GIFImageDecoder);
+///////////////////////////////////////////////////////////////////////////////
#include "SkTRegistry.h"
diff --git a/src/images/SkImageDecoder_libico.cpp b/src/images/SkImageDecoder_libico.cpp
index 226c84af54..347334430e 100644
--- a/src/images/SkImageDecoder_libico.cpp
+++ b/src/images/SkImageDecoder_libico.cpp
@@ -366,6 +366,8 @@ static void editPixelBit32(const int pixelNo, const unsigned char* buf,
*address = SkPreMultiplyARGB(alpha, red, green, blue);
}
+///////////////////////////////////////////////////////////////////////////////
+DEFINE_DECODER_CREATOR(ICOImageDecoder);
/////////////////////////////////////////////////////////////////////////////////////////
#include "SkTRegistry.h"
diff --git a/src/images/SkImageDecoder_libjpeg.cpp b/src/images/SkImageDecoder_libjpeg.cpp
index 5cb45a2e0a..8bc6f3d9bc 100644
--- a/src/images/SkImageDecoder_libjpeg.cpp
+++ b/src/images/SkImageDecoder_libjpeg.cpp
@@ -653,11 +653,14 @@ protected:
};
///////////////////////////////////////////////////////////////////////////////
+DEFINE_DECODER_CREATOR(JPEGImageDecoder);
+DEFINE_ENCODER_CREATOR(JPEGImageEncoder);
+///////////////////////////////////////////////////////////////////////////////
#include "SkTRegistry.h"
SkImageDecoder* sk_libjpeg_dfactory(SkStream* stream) {
- static const char gHeader[] = { 0xFF, 0xD8, 0xFF };
+ static const unsigned char gHeader[] = { 0xFF, 0xD8, 0xFF };
static const size_t HEADER_SIZE = sizeof(gHeader);
char buffer[HEADER_SIZE];
diff --git a/src/images/SkImageDecoder_libpng.cpp b/src/images/SkImageDecoder_libpng.cpp
index cefbe5e71c..8fe342301a 100644
--- a/src/images/SkImageDecoder_libpng.cpp
+++ b/src/images/SkImageDecoder_libpng.cpp
@@ -852,6 +852,9 @@ bool SkPNGImageEncoder::doEncode(SkWStream* stream, const SkBitmap& bitmap,
}
///////////////////////////////////////////////////////////////////////////////
+DEFINE_DECODER_CREATOR(PNGImageDecoder);
+DEFINE_ENCODER_CREATOR(PNGImageEncoder);
+///////////////////////////////////////////////////////////////////////////////
#include "SkTRegistry.h"
diff --git a/src/images/SkImageDecoder_wbmp.cpp b/src/images/SkImageDecoder_wbmp.cpp
index 262cf547cd..28a370550b 100644
--- a/src/images/SkImageDecoder_wbmp.cpp
+++ b/src/images/SkImageDecoder_wbmp.cpp
@@ -148,6 +148,8 @@ bool SkWBMPImageDecoder::onDecode(SkStream* stream, SkBitmap* decodedBitmap,
}
///////////////////////////////////////////////////////////////////////////////
+DEFINE_DECODER_CREATOR(WBMPImageDecoder);
+///////////////////////////////////////////////////////////////////////////////
#include "SkTRegistry.h"