Rewrite SkTRegistry to take any trivially-copyable type.

Obviously these are all currently function pointers of type T(*)(P) for various
T and P.  In bench refactoring, I'm trying to register a function pointer of
type T(*)(), which can't be done as is (passing P=void doesn't work).  This
also lets us register things like primitives, which is conceivable useful.

BUG=
R=reed@google.com, scroggo@google.com

Review URL: https://codereview.chromium.org/23453031

git-svn-id: http://skia.googlecode.com/svn/trunk/include@11082 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/core/SkImageDecoder.h b/core/SkImageDecoder.h
index 7bdaaa8..a8cbe63 100644
--- a/core/SkImageDecoder.h
+++ b/core/SkImageDecoder.h
@@ -15,6 +15,7 @@
 #include "SkImage.h"
 #include "SkRect.h"
 #include "SkRefCnt.h"
+#include "SkTRegistry.h"
 #include "SkTypes.h"
 
 class SkStream;
@@ -557,4 +558,10 @@
 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
diff --git a/core/SkImageEncoder.h b/core/SkImageEncoder.h
index b990aff..5622eee 100644
--- a/core/SkImageEncoder.h
+++ b/core/SkImageEncoder.h
@@ -9,6 +9,7 @@
 #define SkImageEncoder_DEFINED
 
 #include "SkTypes.h"
+#include "SkTRegistry.h"
 
 class SkBitmap;
 class SkData;
@@ -97,4 +98,7 @@
 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
diff --git a/core/SkTRegistry.h b/core/SkTRegistry.h
index 34fcffd..0994c99 100644
--- a/core/SkTRegistry.h
+++ b/core/SkTRegistry.h
@@ -16,11 +16,11 @@
     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
         {
@@ -33,15 +33,14 @@
             }
         }
 #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;
@@ -51,6 +50,6 @@
 };
 
 // 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