aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core/SkBitmap.cpp19
-rw-r--r--src/core/SkGraphics.cpp1
-rw-r--r--src/core/SkMallocPixelRef.cpp4
-rw-r--r--src/core/SkPixelRef.cpp71
-rw-r--r--src/images/SkFlipPixelRef.cpp8
-rw-r--r--src/images/SkImageRef.cpp2
-rw-r--r--src/images/SkImageRef_GlobalPool.cpp6
-rw-r--r--src/ports/SkGlobalInitialization_chromium.cpp5
-rw-r--r--src/ports/SkGlobalInitialization_default.cpp12
-rw-r--r--src/ports/SkImageRef_ashmem.cpp4
-rw-r--r--src/ports/SkImageRef_ashmem.h8
11 files changed, 25 insertions, 115 deletions
diff --git a/src/core/SkBitmap.cpp b/src/core/SkBitmap.cpp
index e292f39a73..da87e77159 100644
--- a/src/core/SkBitmap.cpp
+++ b/src/core/SkBitmap.cpp
@@ -1418,16 +1418,11 @@ void SkBitmap::flatten(SkFlattenableWriteBuffer& buffer) const {
}
if (fPixelRef) {
- SkPixelRef::Factory fact = fPixelRef->getFactory();
- if (fact) {
- const char* name = SkPixelRef::FactoryToName(fact);
- if (name && *name) {
- buffer.write8(SERIALIZE_PIXELTYPE_REF_DATA);
- buffer.write32(fPixelRefOffset);
- buffer.writeString(name);
- fPixelRef->flatten(buffer);
- return;
- }
+ if (fPixelRef->getFactory()) {
+ buffer.write8(SERIALIZE_PIXELTYPE_REF_DATA);
+ buffer.write32(fPixelRefOffset);
+ buffer.writeFlattenable(fPixelRef);
+ return;
}
// if we get here, we can't record the pixels
buffer.write8(SERIALIZE_PIXELTYPE_NONE);
@@ -1472,9 +1467,7 @@ void SkBitmap::unflatten(SkFlattenableReadBuffer& buffer) {
}
case SERIALIZE_PIXELTYPE_REF_DATA: {
size_t offset = buffer.readU32();
- const char* factoryName = buffer.readString();
- SkPixelRef::Factory fact = SkPixelRef::NameToFactory(factoryName);
- SkPixelRef* pr = fact(buffer);
+ SkPixelRef* pr = static_cast<SkPixelRef*>(buffer.readFlattenable());
SkSafeUnref(this->setPixelRef(pr, offset));
break;
}
diff --git a/src/core/SkGraphics.cpp b/src/core/SkGraphics.cpp
index ff38f8591c..db1c9be311 100644
--- a/src/core/SkGraphics.cpp
+++ b/src/core/SkGraphics.cpp
@@ -54,7 +54,6 @@ void SkGraphics::GetVersion(int32_t* major, int32_t* minor, int32_t* patch) {
void SkGraphics::Init() {
#if !SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
SkFlattenable::InitializeFlattenables();
- SkPixelRef::InitializeFlattenables();
#endif
#ifdef BUILD_EMBOSS_TABLE
SkEmbossMask_BuildTable();
diff --git a/src/core/SkMallocPixelRef.cpp b/src/core/SkMallocPixelRef.cpp
index 3e220756dd..1cf64a1db0 100644
--- a/src/core/SkMallocPixelRef.cpp
+++ b/src/core/SkMallocPixelRef.cpp
@@ -34,7 +34,7 @@ void SkMallocPixelRef::onUnlockPixels() {
// nothing to do
}
-void SkMallocPixelRef::flatten(SkFlattenableWriteBuffer& buffer) const {
+void SkMallocPixelRef::flatten(SkFlattenableWriteBuffer& buffer) {
this->INHERITED::flatten(buffer);
buffer.write32(fSize);
@@ -59,4 +59,4 @@ SkMallocPixelRef::SkMallocPixelRef(SkFlattenableReadBuffer& buffer)
}
}
-SK_DEFINE_PIXEL_REF_REGISTRAR(SkMallocPixelRef)
+SK_DEFINE_FLATTENABLE_REGISTRAR(SkMallocPixelRef)
diff --git a/src/core/SkPixelRef.cpp b/src/core/SkPixelRef.cpp
index d5e1b81525..2d4daae781 100644
--- a/src/core/SkPixelRef.cpp
+++ b/src/core/SkPixelRef.cpp
@@ -36,7 +36,8 @@ SkPixelRef::SkPixelRef(SkBaseMutex* mutex) {
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 @@ SkPixelRef::SkPixelRef(SkFlattenableReadBuffer& buffer, SkBaseMutex* mutex) {
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 @@ bool SkPixelRef::onReadPixels(SkBitmap* dst, const SkIRect* subset) {
///////////////////////////////////////////////////////////////////////////////
-#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();
diff --git a/src/images/SkFlipPixelRef.cpp b/src/images/SkFlipPixelRef.cpp
index e81c83cef5..768a67dc4f 100644
--- a/src/images/SkFlipPixelRef.cpp
+++ b/src/images/SkFlipPixelRef.cpp
@@ -60,7 +60,7 @@ void SkFlipPixelRef::swapPages() {
fMutex.release();
}
-void SkFlipPixelRef::flatten(SkFlattenableWriteBuffer& buffer) const {
+void SkFlipPixelRef::flatten(SkFlattenableWriteBuffer& buffer) {
this->INHERITED::flatten(buffer);
buffer.write32(fSize);
@@ -77,11 +77,7 @@ SkFlipPixelRef::SkFlipPixelRef(SkFlattenableReadBuffer& buffer)
buffer.read(fPage0, fSize);
}
-SkPixelRef* SkFlipPixelRef::Create(SkFlattenableReadBuffer& buffer) {
- return SkNEW_ARGS(SkFlipPixelRef, (buffer));
-}
-
-SK_DEFINE_PIXEL_REF_REGISTRAR(SkFlipPixelRef)
+SK_DEFINE_FLATTENABLE_REGISTRAR(SkFlipPixelRef)
///////////////////////////////////////////////////////////////////////////////
diff --git a/src/images/SkImageRef.cpp b/src/images/SkImageRef.cpp
index 1d6b270d6c..cdd80e76c3 100644
--- a/src/images/SkImageRef.cpp
+++ b/src/images/SkImageRef.cpp
@@ -189,7 +189,7 @@ SkImageRef::SkImageRef(SkFlattenableReadBuffer& buffer)
fFactory = NULL;
}
-void SkImageRef::flatten(SkFlattenableWriteBuffer& buffer) const {
+void SkImageRef::flatten(SkFlattenableWriteBuffer& buffer) {
this->INHERITED::flatten(buffer);
buffer.write8(fConfig);
diff --git a/src/images/SkImageRef_GlobalPool.cpp b/src/images/SkImageRef_GlobalPool.cpp
index b774023956..bd63f729be 100644
--- a/src/images/SkImageRef_GlobalPool.cpp
+++ b/src/images/SkImageRef_GlobalPool.cpp
@@ -71,11 +71,7 @@ SkImageRef_GlobalPool::SkImageRef_GlobalPool(SkFlattenableReadBuffer& buffer)
this->mutex()->release();
}
-SkPixelRef* SkImageRef_GlobalPool::Create(SkFlattenableReadBuffer& buffer) {
- return SkNEW_ARGS(SkImageRef_GlobalPool, (buffer));
-}
-
-SK_DEFINE_PIXEL_REF_REGISTRAR(SkImageRef_GlobalPool)
+SK_DEFINE_FLATTENABLE_REGISTRAR(SkImageRef_GlobalPool)
///////////////////////////////////////////////////////////////////////////////
// global imagerefpool wrappers
diff --git a/src/ports/SkGlobalInitialization_chromium.cpp b/src/ports/SkGlobalInitialization_chromium.cpp
index 5a2119e5dd..08e83dc05d 100644
--- a/src/ports/SkGlobalInitialization_chromium.cpp
+++ b/src/ports/SkGlobalInitialization_chromium.cpp
@@ -23,13 +23,10 @@ void SkFlattenable::InitializeFlattenables() {
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkCornerPathEffect)
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDashPathEffect)
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkLayerDrawLooper)
+ SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkMallocPixelRef)
SkBlurMaskFilter::InitializeFlattenables();
SkColorFilter::InitializeFlattenables();
SkGradientShader::InitializeFlattenables();
SkXfermode::InitializeFlattenables();
}
-
-void SkPixelRef::InitializeFlattenables() {
- SkMallocPixelRef::Init();
-}
diff --git a/src/ports/SkGlobalInitialization_default.cpp b/src/ports/SkGlobalInitialization_default.cpp
index a03b922000..8b8a2a71a7 100644
--- a/src/ports/SkGlobalInitialization_default.cpp
+++ b/src/ports/SkGlobalInitialization_default.cpp
@@ -76,19 +76,15 @@ void SkFlattenable::InitializeFlattenables() {
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkColorFilterImageFilter)
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDownSampleImageFilter)
+ SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkFlipPixelRef)
+ SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkImageRef_GlobalPool)
+ SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkMallocPixelRef)
+
SkBlurMaskFilter::InitializeFlattenables();
SkColorFilter::InitializeFlattenables();
SkGradientShader::InitializeFlattenables();
SkTableColorFilter::InitializeFlattenables();
SkXfermode::InitializeFlattenables();
-
-
-}
-
-void SkPixelRef::InitializeFlattenables() {
- SkFlipPixelRef::Init();
- SkImageRef_GlobalPool::Init();
- SkMallocPixelRef::Init();
}
#endif
diff --git a/src/ports/SkImageRef_ashmem.cpp b/src/ports/SkImageRef_ashmem.cpp
index f9c6aff715..a9208e8680 100644
--- a/src/ports/SkImageRef_ashmem.cpp
+++ b/src/ports/SkImageRef_ashmem.cpp
@@ -210,7 +210,7 @@ void SkImageRef_ashmem::onUnlockPixels() {
fBitmap.setPixels(NULL, NULL);
}
-void SkImageRef_ashmem::flatten(SkFlattenableWriteBuffer& buffer) const {
+void SkImageRef_ashmem::flatten(SkFlattenableWriteBuffer& buffer) {
this->INHERITED::flatten(buffer);
const char* uri = getURI();
if (uri) {
@@ -241,4 +241,4 @@ SkPixelRef* SkImageRef_ashmem::Create(SkFlattenableReadBuffer& buffer) {
return SkNEW_ARGS(SkImageRef_ashmem, (buffer));
}
-SK_DEFINE_PIXEL_REF_REGISTRAR(SkImageRef_ashmem)
+SK_DEFINE_FLATTENABLE_REGISTRAR(SkImageRef_ashmem)
diff --git a/src/ports/SkImageRef_ashmem.h b/src/ports/SkImageRef_ashmem.h
index f50ea80c6a..38442f6ce8 100644
--- a/src/ports/SkImageRef_ashmem.h
+++ b/src/ports/SkImageRef_ashmem.h
@@ -23,13 +23,9 @@ public:
virtual ~SkImageRef_ashmem();
// overrides
- virtual void flatten(SkFlattenableWriteBuffer&) const;
- virtual Factory getFactory() const {
- return Create;
- }
- static SkPixelRef* Create(SkFlattenableReadBuffer&);
+ virtual void flatten(SkFlattenableWriteBuffer&);
+ SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkImageRef_ashmem)
- SK_DECLARE_PIXEL_REF_REGISTRAR()
protected:
virtual bool onDecode(SkImageDecoder* codec, SkStream* stream,
SkBitmap* bitmap, SkBitmap::Config config,