aboutsummaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorGravatar djsollen@google.com <djsollen@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-03-28 20:47:01 +0000
committerGravatar djsollen@google.com <djsollen@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-03-28 20:47:01 +0000
commit5370cd969d8f3957e4306068e6195ac1bca3d6cd (patch)
treecf1639cfb2dcc013e992f75b86056455bbe8ad18 /include
parenta728e35edcffd99216e3965a4b908ad0df7f69c2 (diff)
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
Diffstat (limited to 'include')
-rw-r--r--include/core/SkMallocPixelRef.h12
-rw-r--r--include/core/SkPixelRef.h46
-rw-r--r--include/gpu/SkGrTexturePixelRef.h4
-rw-r--r--include/images/SkFlipPixelRef.h25
-rw-r--r--include/images/SkImageRef.h2
-rw-r--r--include/images/SkImageRef_GlobalPool.h8
6 files changed, 22 insertions, 75 deletions
diff --git a/include/core/SkMallocPixelRef.h b/include/core/SkMallocPixelRef.h
index 903bad334d..cdfec75873 100644
--- a/include/core/SkMallocPixelRef.h
+++ b/include/core/SkMallocPixelRef.h
@@ -29,15 +29,9 @@ public:
void* getAddr() const { return fStorage; }
// overrides from SkPixelRef
- virtual void flatten(SkFlattenableWriteBuffer&) const;
- virtual Factory getFactory() const {
- return Create;
- }
- static SkPixelRef* Create(SkFlattenableReadBuffer& buffer) {
- return SkNEW_ARGS(SkMallocPixelRef, (buffer));
- }
-
- SK_DECLARE_PIXEL_REF_REGISTRAR()
+ virtual void flatten(SkFlattenableWriteBuffer&);
+ SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkMallocPixelRef)
+
protected:
// overrides from SkPixelRef
virtual void* onLockPixels(SkColorTable**);
diff --git a/include/core/SkPixelRef.h b/include/core/SkPixelRef.h
index d5f6ab2b6e..d84c285877 100644
--- a/include/core/SkPixelRef.h
+++ b/include/core/SkPixelRef.h
@@ -13,35 +13,15 @@
#include "SkBitmap.h"
#include "SkRefCnt.h"
#include "SkString.h"
+#include "SkFlattenable.h"
class SkColorTable;
struct SkIRect;
class SkMutex;
-class SkFlattenableReadBuffer;
-class SkFlattenableWriteBuffer;
// this is an opaque class, not interpreted by skia
class SkGpuTexture;
-#if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
-
-#define SK_DECLARE_PIXEL_REF_REGISTRAR()
-
-#define SK_DEFINE_PIXEL_REF_REGISTRAR(pixelRef) \
- static SkPixelRef::Registrar g##pixelRef##Reg(#pixelRef, \
- pixelRef::Create);
-
-#else
-
-#define SK_DECLARE_PIXEL_REF_REGISTRAR() static void Init();
-
-#define SK_DEFINE_PIXEL_REF_REGISTRAR(pixelRef) \
- void pixelRef::Init() { \
- SkPixelRef::Registrar(#pixelRef, Create); \
- }
-
-#endif
-
/** \class SkPixelRef
This class is the smart container for pixel memory, and is used with
@@ -50,7 +30,7 @@ class SkGpuTexture;
This class can be shared/accessed between multiple threads.
*/
-class SK_API SkPixelRef : public SkRefCnt {
+class SK_API SkPixelRef : public SkFlattenable {
public:
explicit SkPixelRef(SkBaseMutex* mutex = NULL);
@@ -143,11 +123,7 @@ public:
virtual SkPixelRef* deepCopy(SkBitmap::Config config) { return NULL; }
// serialization
-
- typedef SkPixelRef* (*Factory)(SkFlattenableReadBuffer&);
-
- virtual Factory getFactory() const { return NULL; }
- virtual void flatten(SkFlattenableWriteBuffer&) const;
+ virtual void flatten(SkFlattenableWriteBuffer&);
#ifdef SK_BUILD_FOR_ANDROID
/**
@@ -165,17 +141,6 @@ public:
virtual void globalUnref();
#endif
- static Factory NameToFactory(const char name[]);
- static const char* FactoryToName(Factory);
- static void Register(const char name[], Factory);
-
- class Registrar {
- public:
- Registrar(const char name[], Factory factory) {
- SkPixelRef::Register(name, factory);
- }
- };
-
protected:
/** Called when the lockCount goes from 0 to 1. The caller will have already
acquire a mutex for thread safety, so this method need not do that.
@@ -206,9 +171,6 @@ protected:
SkPixelRef(SkFlattenableReadBuffer&, SkBaseMutex*);
private:
-#if !SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
- static void InitializeFlattenables();
-#endif
SkBaseMutex* fMutex; // must remain in scope for the life of this object
void* fPixels;
@@ -222,7 +184,7 @@ private:
// can go from false to true, but never from true to false
bool fIsImmutable;
- friend class SkGraphics;
+ typedef SkFlattenable INHERITED;
};
#endif
diff --git a/include/gpu/SkGrTexturePixelRef.h b/include/gpu/SkGrTexturePixelRef.h
index ab92eff49c..fd0e750ec1 100644
--- a/include/gpu/SkGrTexturePixelRef.h
+++ b/include/gpu/SkGrTexturePixelRef.h
@@ -48,6 +48,8 @@ public:
// override from SkPixelRef
virtual SkGpuTexture* getTexture();
+ SK_DECLARE_UNFLATTENABLE_OBJECT()
+
protected:
// override from SkPixelRef
virtual bool onReadPixels(SkBitmap* dst, const SkIRect* subset);
@@ -71,6 +73,8 @@ public:
// override from SkPixelRef
virtual SkGpuTexture* getTexture();
+ SK_DECLARE_UNFLATTENABLE_OBJECT()
+
protected:
// override from SkPixelRef
virtual bool onReadPixels(SkBitmap* dst, const SkIRect* subset);
diff --git a/include/images/SkFlipPixelRef.h b/include/images/SkFlipPixelRef.h
index 455a3dace3..c9ba026878 100644
--- a/include/images/SkFlipPixelRef.h
+++ b/include/images/SkFlipPixelRef.h
@@ -32,6 +32,15 @@ public:
const SkRegion& beginUpdate(SkBitmap* device);
void endUpdate();
+
+ virtual void flatten(SkFlattenableWriteBuffer&);
+ SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkFlipPixelRef)
+
+protected:
+ virtual void* onLockPixels(SkColorTable**);
+ virtual void onUnlockPixels();
+
+ SkFlipPixelRef(SkFlattenableReadBuffer&);
private:
void getFrontBack(const void** front, void** back) const {
@@ -50,22 +59,6 @@ private:
static void CopyBitsFromAddr(const SkBitmap& dst, const SkRegion& clip,
const void* srcAddr);
- // serialization
-
-public:
- virtual Factory getFactory() const { return Create; }
- virtual void flatten(SkFlattenableWriteBuffer&) const;
- static SkPixelRef* Create(SkFlattenableReadBuffer& buffer);
-
- SK_DECLARE_PIXEL_REF_REGISTRAR()
-
-protected:
- virtual void* onLockPixels(SkColorTable**);
- virtual void onUnlockPixels();
-
- SkFlipPixelRef(SkFlattenableReadBuffer&);
-
-private:
SkMutex fMutex;
SkPageFlipper fFlipper;
diff --git a/include/images/SkImageRef.h b/include/images/SkImageRef.h
index f0f06b60f2..8fc4754e92 100644
--- a/include/images/SkImageRef.h
+++ b/include/images/SkImageRef.h
@@ -61,7 +61,7 @@ public:
SkImageDecoderFactory* setDecoderFactory(SkImageDecoderFactory*);
// overrides
- virtual void flatten(SkFlattenableWriteBuffer&) const;
+ virtual void flatten(SkFlattenableWriteBuffer&);
protected:
/** Override if you want to install a custom allocator.
diff --git a/include/images/SkImageRef_GlobalPool.h b/include/images/SkImageRef_GlobalPool.h
index 909ee71050..03c23673c6 100644
--- a/include/images/SkImageRef_GlobalPool.h
+++ b/include/images/SkImageRef_GlobalPool.h
@@ -18,13 +18,7 @@ public:
SkImageRef_GlobalPool(SkStream*, SkBitmap::Config, int sampleSize = 1);
virtual ~SkImageRef_GlobalPool();
- // overrides
- virtual Factory getFactory() const {
- return Create;
- }
- static SkPixelRef* Create(SkFlattenableReadBuffer&);
-
- SK_DECLARE_PIXEL_REF_REGISTRAR()
+ SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkImageRef_GlobalPool)
// API to control the global pool