summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMathias Agopian <mathias@google.com>2011-06-12 18:05:53 -0700
committerMathias Agopian <mathias@google.com>2011-06-13 13:58:34 -0700
commitafffa8fa9f82a7343e1158bf921931fd3e3df615 (patch)
tree04e6d9721d21895ca93b209f98db8b5b65ab9991
parentd027329cd6105c05c157e3858a170e4f04eb0e3e (diff)
downloadandroid_frameworks_base-afffa8fa9f82a7343e1158bf921931fd3e3df615.tar.gz
android_frameworks_base-afffa8fa9f82a7343e1158bf921931fd3e3df615.tar.bz2
android_frameworks_base-afffa8fa9f82a7343e1158bf921931fd3e3df615.zip
fix RefBase so it retains binary-compatibility with gingerbread (DO NOT MERGE)
Bug: 4595257 Change-Id: I4773cf4fe59b2509db0ed733739eb6961d473b25
-rw-r--r--include/utils/RefBase.h20
-rw-r--r--libs/utils/RefBase.cpp34
-rw-r--r--services/surfaceflinger/Layer.cpp5
-rw-r--r--services/surfaceflinger/Layer.h4
4 files changed, 43 insertions, 20 deletions
diff --git a/include/utils/RefBase.h b/include/utils/RefBase.h
index 1b4a310008a..d92cfb03d71 100644
--- a/include/utils/RefBase.h
+++ b/include/utils/RefBase.h
@@ -112,16 +112,22 @@ public:
getWeakRefs()->trackMe(enable, retain);
}
-protected:
- RefBase();
- virtual ~RefBase();
+ // used to override the RefBase destruction.
+ class Destroyer {
+ friend class RefBase;
+ public:
+ virtual ~Destroyer();
+ private:
+ virtual void destroy(RefBase const* base) = 0;
+ };
- // called when the last reference goes away. this is responsible for
- // calling the destructor. The default implementation just does
- // "delete this;".
// Make sure to never acquire a strong reference from this function. The
// same restrictions than for destructors apply.
- virtual void destroy() const;
+ void setDestroyer(Destroyer* destroyer);
+
+protected:
+ RefBase();
+ virtual ~RefBase();
//! Flags for extendObjectLifetime()
enum {
diff --git a/libs/utils/RefBase.cpp b/libs/utils/RefBase.cpp
index 1c870cf7835..47ef546dfb5 100644
--- a/libs/utils/RefBase.cpp
+++ b/libs/utils/RefBase.cpp
@@ -48,6 +48,11 @@ namespace android {
// ---------------------------------------------------------------------------
+RefBase::Destroyer::~Destroyer() {
+}
+
+// ---------------------------------------------------------------------------
+
class RefBase::weakref_impl : public RefBase::weakref_type
{
public:
@@ -55,7 +60,7 @@ public:
volatile int32_t mWeak;
RefBase* const mBase;
volatile int32_t mFlags;
-
+ Destroyer* mDestroyer;
#if !DEBUG_REFS
@@ -64,6 +69,7 @@ public:
, mWeak(0)
, mBase(base)
, mFlags(0)
+ , mDestroyer(0)
{
}
@@ -298,10 +304,6 @@ void RefBase::incStrong(const void* id) const
const_cast<RefBase*>(this)->onFirstRef();
}
-void RefBase::destroy() const {
- delete this;
-}
-
void RefBase::decStrong(const void* id) const
{
weakref_impl* const refs = mRefs;
@@ -314,7 +316,11 @@ void RefBase::decStrong(const void* id) const
if (c == 1) {
const_cast<RefBase*>(this)->onLastStrongRef(id);
if ((refs->mFlags&OBJECT_LIFETIME_WEAK) != OBJECT_LIFETIME_WEAK) {
- destroy();
+ if (refs->mDestroyer) {
+ refs->mDestroyer->destroy(this);
+ } else {
+ delete this;
+ }
}
}
refs->removeWeakRef(id);
@@ -349,7 +355,9 @@ int32_t RefBase::getStrongCount() const
return mRefs->mStrong;
}
-
+void RefBase::setDestroyer(RefBase::Destroyer* destroyer) {
+ mRefs->mDestroyer = destroyer;
+}
RefBase* RefBase::weakref_type::refBase() const
{
@@ -375,7 +383,11 @@ void RefBase::weakref_type::decWeak(const void* id)
if ((impl->mFlags&OBJECT_LIFETIME_WEAK) != OBJECT_LIFETIME_WEAK) {
if (impl->mStrong == INITIAL_STRONG_VALUE) {
if (impl->mBase) {
- impl->mBase->destroy();
+ if (impl->mDestroyer) {
+ impl->mDestroyer->destroy(impl->mBase);
+ } else {
+ delete impl->mBase;
+ }
}
} else {
// LOGV("Freeing refs %p of old RefBase %p\n", this, impl->mBase);
@@ -385,7 +397,11 @@ void RefBase::weakref_type::decWeak(const void* id)
impl->mBase->onLastWeakRef(id);
if ((impl->mFlags&OBJECT_LIFETIME_FOREVER) != OBJECT_LIFETIME_FOREVER) {
if (impl->mBase) {
- impl->mBase->destroy();
+ if (impl->mDestroyer) {
+ impl->mDestroyer->destroy(impl->mBase);
+ } else {
+ delete impl->mBase;
+ }
}
}
}
diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp
index 4739cc3072c..0087fd5e32f 100644
--- a/services/surfaceflinger/Layer.cpp
+++ b/services/surfaceflinger/Layer.cpp
@@ -60,6 +60,7 @@ Layer::Layer(SurfaceFlinger* flinger,
mWidth(0), mHeight(0), mNeedsScaling(false), mFixedSize(false),
mBypassState(false)
{
+ setDestroyer(this);
}
Layer::~Layer()
@@ -76,8 +77,8 @@ Layer::~Layer()
}
}
-void Layer::destroy() const {
- mFlinger->destroyLayer(this);
+void Layer::destroy(RefBase const* base) {
+ mFlinger->destroyLayer(static_cast<LayerBase const*>(base));
}
status_t Layer::setToken(const sp<UserClient>& userClient,
diff --git a/services/surfaceflinger/Layer.h b/services/surfaceflinger/Layer.h
index 51b52f9eb10..2c4f756b48e 100644
--- a/services/surfaceflinger/Layer.h
+++ b/services/surfaceflinger/Layer.h
@@ -44,7 +44,7 @@ class UserClient;
// ---------------------------------------------------------------------------
-class Layer : public LayerBaseClient
+class Layer : public LayerBaseClient, private RefBase::Destroyer
{
public:
Layer(SurfaceFlinger* flinger, DisplayID display,
@@ -94,7 +94,7 @@ public:
return mFreezeLock; }
protected:
- virtual void destroy() const;
+ virtual void destroy(RefBase const* base);
virtual void dump(String8& result, char* scratch, size_t size) const;
private: