Consolidate PixelRef flattables with the standard impl
The flatten method on these functions can no longer be
const as SkFlattenables declaration is not const and
would result in the const methods only being called when
the reference to the object was const.
Review URL: https://codereview.appspot.com/5941043
git-svn-id: http://skia.googlecode.com/svn/trunk@3533 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/core/SkPixelRef.cpp b/src/core/SkPixelRef.cpp
index d5e1b81..2d4daae 100644
--- a/src/core/SkPixelRef.cpp
+++ b/src/core/SkPixelRef.cpp
@@ -36,7 +36,8 @@
fIsImmutable = false;
}
-SkPixelRef::SkPixelRef(SkFlattenableReadBuffer& buffer, SkBaseMutex* mutex) {
+SkPixelRef::SkPixelRef(SkFlattenableReadBuffer& buffer, SkBaseMutex* mutex)
+ : INHERITED(buffer) {
if (NULL == mutex) {
mutex = &gPixelRefMutex;
}
@@ -48,7 +49,8 @@
fIsImmutable = buffer.readBool();
}
-void SkPixelRef::flatten(SkFlattenableWriteBuffer& buffer) const {
+void SkPixelRef::flatten(SkFlattenableWriteBuffer& buffer) {
+ this->INHERITED::flatten(buffer);
buffer.writeBool(fIsImmutable);
}
@@ -110,71 +112,6 @@
///////////////////////////////////////////////////////////////////////////////
-#define MAX_PAIR_COUNT 16
-
-struct Pair {
- const char* fName;
- SkPixelRef::Factory fFactory;
-};
-
-static int gCount;
-static Pair gPairs[MAX_PAIR_COUNT];
-
-void SkPixelRef::Register(const char name[], Factory factory) {
- SkASSERT(name);
- SkASSERT(factory);
-
- static bool gOnce;
- if (!gOnce) {
- gCount = 0;
- gOnce = true;
- }
-
- SkASSERT(gCount < MAX_PAIR_COUNT);
-
- gPairs[gCount].fName = name;
- gPairs[gCount].fFactory = factory;
- gCount += 1;
-}
-
-#if !SK_ALLOW_STATIC_GLOBAL_INITIALIZERS && defined(SK_DEBUG)
-static void report_no_entries(const char* functionName) {
- if (!gCount) {
- SkDebugf("%s has no registered name/factory pairs."
- " Call SkGraphics::Init() at process initialization time.",
- functionName);
- }
-}
-#endif
-
-SkPixelRef::Factory SkPixelRef::NameToFactory(const char name[]) {
-#if !SK_ALLOW_STATIC_GLOBAL_INITIALIZERS && defined(SK_DEBUG)
- report_no_entries(__FUNCTION__);
-#endif
- const Pair* pairs = gPairs;
- for (int i = gCount - 1; i >= 0; --i) {
- if (strcmp(pairs[i].fName, name) == 0) {
- return pairs[i].fFactory;
- }
- }
- return NULL;
-}
-
-const char* SkPixelRef::FactoryToName(Factory fact) {
-#if !SK_ALLOW_STATIC_GLOBAL_INITIALIZERS && defined(SK_DEBUG)
- report_no_entries(__FUNCTION__);
-#endif
- const Pair* pairs = gPairs;
- for (int i = gCount - 1; i >= 0; --i) {
- if (pairs[i].fFactory == fact) {
- return pairs[i].fName;
- }
- }
- return NULL;
-}
-
-///////////////////////////////////////////////////////////////////////////////
-
#ifdef SK_BUILD_FOR_ANDROID
void SkPixelRef::globalRef(void* data) {
this->ref();