diff options
author | Jason Sams <rjsams@android.com> | 2009-09-25 16:37:33 -0700 |
---|---|---|
committer | Jason Sams <rjsams@android.com> | 2009-09-25 16:37:33 -0700 |
commit | 61f08d6fa7c7657e9fbcd17e9a1c5b9114bb3844 (patch) | |
tree | e836663efc3047198d5aef1723cee4e5556fe8c4 | |
parent | 66b2771d745aa66df5cf80b300b5ba0f936ff22e (diff) | |
download | frameworks_base-61f08d6fa7c7657e9fbcd17e9a1c5b9114bb3844.zip frameworks_base-61f08d6fa7c7657e9fbcd17e9a1c5b9114bb3844.tar.gz frameworks_base-61f08d6fa7c7657e9fbcd17e9a1c5b9114bb3844.tar.bz2 |
Improved object lifecycle tracking and fix leaks.
-rw-r--r-- | libs/rs/rsAdapter.cpp | 8 | ||||
-rw-r--r-- | libs/rs/rsAllocation.cpp | 2 | ||||
-rw-r--r-- | libs/rs/rsComponent.cpp | 4 | ||||
-rw-r--r-- | libs/rs/rsContext.cpp | 13 | ||||
-rw-r--r-- | libs/rs/rsElement.cpp | 4 | ||||
-rw-r--r-- | libs/rs/rsLight.cpp | 2 | ||||
-rw-r--r-- | libs/rs/rsMesh.cpp | 2 | ||||
-rw-r--r-- | libs/rs/rsObjectBase.cpp | 34 | ||||
-rw-r--r-- | libs/rs/rsObjectBase.h | 6 | ||||
-rw-r--r-- | libs/rs/rsProgram.cpp | 5 | ||||
-rw-r--r-- | libs/rs/rsProgramFragment.cpp | 8 | ||||
-rw-r--r-- | libs/rs/rsProgramFragment.h | 1 | ||||
-rw-r--r-- | libs/rs/rsProgramFragmentStore.cpp | 8 | ||||
-rw-r--r-- | libs/rs/rsProgramFragmentStore.h | 1 | ||||
-rw-r--r-- | libs/rs/rsProgramRaster.cpp | 8 | ||||
-rw-r--r-- | libs/rs/rsProgramRaster.h | 1 | ||||
-rw-r--r-- | libs/rs/rsProgramVertex.cpp | 16 | ||||
-rw-r--r-- | libs/rs/rsProgramVertex.h | 3 | ||||
-rw-r--r-- | libs/rs/rsSampler.cpp | 4 | ||||
-rw-r--r-- | libs/rs/rsScript.cpp | 2 | ||||
-rw-r--r-- | libs/rs/rsScriptC.cpp | 2 | ||||
-rw-r--r-- | libs/rs/rsSimpleMesh.cpp | 4 | ||||
-rw-r--r-- | libs/rs/rsType.cpp | 2 |
23 files changed, 123 insertions, 17 deletions
diff --git a/libs/rs/rsAdapter.cpp b/libs/rs/rsAdapter.cpp index 9a3bbb1..0d31fac 100644 --- a/libs/rs/rsAdapter.cpp +++ b/libs/rs/rsAdapter.cpp @@ -23,11 +23,15 @@ using namespace android::renderscript; Adapter1D::Adapter1D(Context *rsc) : ObjectBase(rsc) { + mAllocFile = __FILE__; + mAllocLine = __LINE__; reset(); } Adapter1D::Adapter1D(Context *rsc, Allocation *a) : ObjectBase(rsc) { + mAllocFile = __FILE__; + mAllocLine = __LINE__; reset(); setAllocation(a); } @@ -127,11 +131,15 @@ void rsi_Adapter1DData(Context *rsc, RsAdapter1D va, const void *data) Adapter2D::Adapter2D(Context *rsc) : ObjectBase(rsc) { + mAllocFile = __FILE__; + mAllocLine = __LINE__; reset(); } Adapter2D::Adapter2D(Context *rsc, Allocation *a) : ObjectBase(rsc) { + mAllocFile = __FILE__; + mAllocLine = __LINE__; reset(); setAllocation(a); } diff --git a/libs/rs/rsAllocation.cpp b/libs/rs/rsAllocation.cpp index 96e128b..8ee6e5a 100644 --- a/libs/rs/rsAllocation.cpp +++ b/libs/rs/rsAllocation.cpp @@ -24,6 +24,8 @@ using namespace android::renderscript; Allocation::Allocation(Context *rsc, const Type *type) : ObjectBase(rsc) { + mAllocFile = __FILE__; + mAllocLine = __LINE__; mPtr = NULL; mCpuWrite = false; diff --git a/libs/rs/rsComponent.cpp b/libs/rs/rsComponent.cpp index 67184ff..42e2e4f 100644 --- a/libs/rs/rsComponent.cpp +++ b/libs/rs/rsComponent.cpp @@ -23,6 +23,8 @@ using namespace android::renderscript; Component::Component(Context *rsc) : ObjectBase(rsc) { + mAllocFile = __FILE__; + mAllocLine = __LINE__; mType = FLOAT; mKind = USER; mIsNormalized = false; @@ -33,6 +35,8 @@ Component::Component(Context *rsc, DataKind dk, DataType dt, bool isNormalized, uint32_t bits, const char * name) : ObjectBase(rsc) { + mAllocFile = __FILE__; + mAllocLine = __LINE__; mType = dt; mKind = dk; mIsNormalized = isNormalized; diff --git a/libs/rs/rsContext.cpp b/libs/rs/rsContext.cpp index 653d427..70add92 100644 --- a/libs/rs/rsContext.cpp +++ b/libs/rs/rsContext.cpp @@ -269,11 +269,16 @@ void * Context::threadProc(void *vrsc) } LOGV("RS Thread exiting"); + rsc->mRaster.clear(); + rsc->mFragment.clear(); + rsc->mVertex.clear(); + rsc->mFragmentStore.clear(); + rsc->mRootScript.clear(); + rsc->mStateRaster.deinit(rsc); + rsc->mStateVertex.deinit(rsc); + rsc->mStateFragment.deinit(rsc); + rsc->mStateFragmentStore.deinit(rsc); ObjectBase::zeroAllUserRef(rsc); - rsc->mRaster.set(NULL); - rsc->mFragment.set(NULL); - rsc->mVertex.set(NULL); - rsc->mFragmentStore.set(NULL); glClearColor(0,0,0,0); glClear(GL_COLOR_BUFFER_BIT); diff --git a/libs/rs/rsElement.cpp b/libs/rs/rsElement.cpp index e7ae247..a00fb52 100644 --- a/libs/rs/rsElement.cpp +++ b/libs/rs/rsElement.cpp @@ -24,12 +24,16 @@ using namespace android::renderscript; Element::Element(Context *rsc) : ObjectBase(rsc) { + mAllocFile = __FILE__; + mAllocLine = __LINE__; mComponents = NULL; mComponentCount = 0; } Element::Element(Context *rsc, uint32_t count) : ObjectBase(rsc) { + mAllocFile = __FILE__; + mAllocLine = __LINE__; mComponents = new ObjectBaseRef<Component> [count]; mComponentCount = count; } diff --git a/libs/rs/rsLight.cpp b/libs/rs/rsLight.cpp index e9b8ef9..6f2cf3e 100644 --- a/libs/rs/rsLight.cpp +++ b/libs/rs/rsLight.cpp @@ -24,6 +24,8 @@ using namespace android::renderscript; Light::Light(Context *rsc, bool isLocal, bool isMono) : ObjectBase(rsc) { + mAllocFile = __FILE__; + mAllocLine = __LINE__; mIsLocal = isLocal; mIsMono = isMono; diff --git a/libs/rs/rsMesh.cpp b/libs/rs/rsMesh.cpp index 73aef62..d595b4e 100644 --- a/libs/rs/rsMesh.cpp +++ b/libs/rs/rsMesh.cpp @@ -24,6 +24,8 @@ using namespace android::renderscript; Mesh::Mesh(Context *rsc) : ObjectBase(rsc) { + mAllocFile = __FILE__; + mAllocLine = __LINE__; mVerticies = NULL; mVerticiesCount = 0; mPrimitives = NULL; diff --git a/libs/rs/rsObjectBase.cpp b/libs/rs/rsObjectBase.cpp index 83fa482..720e8fc 100644 --- a/libs/rs/rsObjectBase.cpp +++ b/libs/rs/rsObjectBase.cpp @@ -28,6 +28,8 @@ ObjectBase::ObjectBase(Context *rsc) mRSC = NULL; mNext = NULL; mPrev = NULL; + mAllocFile = __FILE__; + mAllocLine = __LINE__; setContext(rsc); } @@ -39,6 +41,17 @@ ObjectBase::~ObjectBase() remove(); } +void ObjectBase::dumpObj(const char *op) const +{ + if (mName) { + LOGV("%s RSobj %p, name %s, refs %i,%i from %s,%i links %p,%p,%p", + op, this, mName, mUserRefCount, mSysRefCount, mAllocFile, mAllocLine, mNext, mPrev, mRSC); + } else { + LOGV("%s RSobj %p, no-name, refs %i,%i from %s,%i links %p,%p,%p", + op, this, mUserRefCount, mSysRefCount, mAllocFile, mAllocLine, mNext, mPrev, mRSC); + } +} + void ObjectBase::setContext(Context *rsc) { if (mRSC) { @@ -66,11 +79,7 @@ bool ObjectBase::checkDelete() const { if (!(mSysRefCount | mUserRefCount)) { if (mRSC && mRSC->props.mLogObjects) { - if (mName) { - LOGV("Deleting RS object %p, name %s", this, mName); - } else { - LOGV("Deleting RS object %p, no name", this); - } + dumpObj("checkDelete"); } delete this; return true; @@ -82,14 +91,14 @@ bool ObjectBase::decUserRef() const { rsAssert(mUserRefCount > 0); mUserRefCount --; - //LOGV("ObjectBase %p dec ref %i", this, mRefCount); + //dumpObj("decUserRef"); return checkDelete(); } bool ObjectBase::zeroUserRef() const { mUserRefCount = 0; - //LOGV("ObjectBase %p dec ref %i", this, mRefCount); + //dumpObj("zeroUserRef"); return checkDelete(); } @@ -97,7 +106,7 @@ bool ObjectBase::decSysRef() const { rsAssert(mSysRefCount > 0); mSysRefCount --; - //LOGV("ObjectBase %p dec ref %i", this, mRefCount); + //dumpObj("decSysRef"); return checkDelete(); } @@ -174,5 +183,14 @@ void ObjectBase::zeroAllUserRef(Context *rsc) //LOGE("o next %p", o); } } + + if (rsc->props.mLogObjects) { + LOGV("Objects remaining."); + o = rsc->mObjHead; + while (o) { + o->dumpObj(" "); + o = o->mNext; + } + } } diff --git a/libs/rs/rsObjectBase.h b/libs/rs/rsObjectBase.h index be400ca..ea5e37c 100644 --- a/libs/rs/rsObjectBase.h +++ b/libs/rs/rsObjectBase.h @@ -50,6 +50,12 @@ public: static void zeroAllUserRef(Context *rsc); + void dumpObj(const char *op) const; + +protected: + const char *mAllocFile; + uint32_t mAllocLine; + private: void add() const; void remove() const; diff --git a/libs/rs/rsProgram.cpp b/libs/rs/rsProgram.cpp index 051483f..5f2a609 100644 --- a/libs/rs/rsProgram.cpp +++ b/libs/rs/rsProgram.cpp @@ -23,10 +23,11 @@ using namespace android::renderscript; Program::Program(Context *rsc, Element *in, Element *out) : ObjectBase(rsc) { + mAllocFile = __FILE__; + mAllocLine = __LINE__; + mElementIn.set(in); mElementOut.set(out); - - } Program::~Program() diff --git a/libs/rs/rsProgramFragment.cpp b/libs/rs/rsProgramFragment.cpp index 5f685ff..708a0e0 100644 --- a/libs/rs/rsProgramFragment.cpp +++ b/libs/rs/rsProgramFragment.cpp @@ -27,6 +27,8 @@ using namespace android::renderscript; ProgramFragment::ProgramFragment(Context *rsc, Element *in, Element *out, bool pointSpriteEnable) : Program(rsc, in, out) { + mAllocFile = __FILE__; + mAllocLine = __LINE__; for (uint32_t ct=0; ct < MAX_TEXTURE; ct++) { mEnvModes[ct] = RS_TEX_ENV_MODE_REPLACE; mTextureDimensions[ct] = 2; @@ -190,6 +192,12 @@ void ProgramFragmentState::init(Context *rsc, int32_t w, int32_t h) mDefault.set(pf); } +void ProgramFragmentState::deinit(Context *rsc) +{ + mDefault.clear(); + mLast.clear(); +} + namespace android { namespace renderscript { diff --git a/libs/rs/rsProgramFragment.h b/libs/rs/rsProgramFragment.h index d783c0d..e26c6e8 100644 --- a/libs/rs/rsProgramFragment.h +++ b/libs/rs/rsProgramFragment.h @@ -75,6 +75,7 @@ public: ProgramFragment *mPF; void init(Context *rsc, int32_t w, int32_t h); + void deinit(Context *rsc); ObjectBaseRef<Type> mTextureTypes[ProgramFragment::MAX_TEXTURE]; ObjectBaseRef<ProgramFragment> mDefault; diff --git a/libs/rs/rsProgramFragmentStore.cpp b/libs/rs/rsProgramFragmentStore.cpp index 39802c7..de33d9c 100644 --- a/libs/rs/rsProgramFragmentStore.cpp +++ b/libs/rs/rsProgramFragmentStore.cpp @@ -27,6 +27,8 @@ using namespace android::renderscript; ProgramFragmentStore::ProgramFragmentStore(Context *rsc, Element *in, Element *out) : Program(rsc, in, out) { + mAllocFile = __FILE__; + mAllocLine = __LINE__; mDitherEnable = true; mBlendEnable = false; mColorRWriteEnable = true; @@ -217,6 +219,12 @@ void ProgramFragmentStoreState::init(Context *rsc, int32_t w, int32_t h) mDefault.set(pfs); } +void ProgramFragmentStoreState::deinit(Context *rsc) +{ + mDefault.clear(); + mLast.clear(); +} + namespace android { namespace renderscript { diff --git a/libs/rs/rsProgramFragmentStore.h b/libs/rs/rsProgramFragmentStore.h index b71e35f..a344387 100644 --- a/libs/rs/rsProgramFragmentStore.h +++ b/libs/rs/rsProgramFragmentStore.h @@ -65,6 +65,7 @@ public: ProgramFragmentStoreState(); ~ProgramFragmentStoreState(); void init(Context *rsc, int32_t w, int32_t h); + void deinit(Context *rsc); ObjectBaseRef<ProgramFragmentStore> mDefault; ObjectBaseRef<ProgramFragmentStore> mLast; diff --git a/libs/rs/rsProgramRaster.cpp b/libs/rs/rsProgramRaster.cpp index 2a9c4ab..fcf6824 100644 --- a/libs/rs/rsProgramRaster.cpp +++ b/libs/rs/rsProgramRaster.cpp @@ -32,6 +32,8 @@ ProgramRaster::ProgramRaster(Context *rsc, bool pointSprite) : Program(rsc, in, out) { + mAllocFile = __FILE__; + mAllocLine = __LINE__; mPointSmooth = pointSmooth; mLineSmooth = lineSmooth; mPointSprite = pointSprite; @@ -100,6 +102,12 @@ void ProgramRasterState::init(Context *rsc, int32_t w, int32_t h) mDefault.set(pr); } +void ProgramRasterState::deinit(Context *rsc) +{ + mDefault.clear(); + mLast.clear(); +} + namespace android { namespace renderscript { diff --git a/libs/rs/rsProgramRaster.h b/libs/rs/rsProgramRaster.h index da68f67..a6d5ba8 100644 --- a/libs/rs/rsProgramRaster.h +++ b/libs/rs/rsProgramRaster.h @@ -58,6 +58,7 @@ public: ProgramRasterState(); ~ProgramRasterState(); void init(Context *rsc, int32_t w, int32_t h); + void deinit(Context *rsc); ObjectBaseRef<ProgramRaster> mDefault; ObjectBaseRef<ProgramRaster> mLast; diff --git a/libs/rs/rsProgramVertex.cpp b/libs/rs/rsProgramVertex.cpp index 9eb32ff..9bfa602 100644 --- a/libs/rs/rsProgramVertex.cpp +++ b/libs/rs/rsProgramVertex.cpp @@ -27,6 +27,8 @@ using namespace android::renderscript; ProgramVertex::ProgramVertex(Context *rsc, Element *in, Element *out) : Program(rsc, in, out) { + mAllocFile = __FILE__; + mAllocLine = __LINE__; mTextureMatrixEnable = false; mLightCount = 0; } @@ -139,10 +141,10 @@ void ProgramVertexState::init(Context *rsc, int32_t w, int32_t h) rsi_TypeBegin(rsc, e); rsi_TypeAdd(rsc, RS_DIMENSION_X, 48); - mAllocType = rsi_TypeCreate(rsc); + mAllocType.set((Type *)rsi_TypeCreate(rsc)); ProgramVertex *pv = new ProgramVertex(rsc, NULL, NULL); - Allocation *alloc = (Allocation *)rsi_AllocationCreateTyped(rsc, mAllocType); + Allocation *alloc = (Allocation *)rsi_AllocationCreateTyped(rsc, mAllocType.get()); mDefaultAlloc.set(alloc); mDefault.set(pv); @@ -156,6 +158,16 @@ void ProgramVertexState::init(Context *rsc, int32_t w, int32_t h) alloc->subData(RS_PROGRAM_VERTEX_MODELVIEW_OFFSET, 16, &m.m[0], 16*4); } +void ProgramVertexState::deinit(Context *rsc) +{ + mDefaultAlloc.clear(); + mDefault.clear(); + mAllocType.clear(); + mLast.clear(); + delete mPV; + mPV = NULL; +} + namespace android { namespace renderscript { diff --git a/libs/rs/rsProgramVertex.h b/libs/rs/rsProgramVertex.h index b3a8b8d..e198f23 100644 --- a/libs/rs/rsProgramVertex.h +++ b/libs/rs/rsProgramVertex.h @@ -59,12 +59,13 @@ public: ~ProgramVertexState(); void init(Context *rsc, int32_t w, int32_t h); + void deinit(Context *rsc); ObjectBaseRef<ProgramVertex> mDefault; ObjectBaseRef<ProgramVertex> mLast; ObjectBaseRef<Allocation> mDefaultAlloc; - RsType mAllocType; + ObjectBaseRef<Type> mAllocType; ProgramVertex *mPV; diff --git a/libs/rs/rsSampler.cpp b/libs/rs/rsSampler.cpp index 99091a9..b793750 100644 --- a/libs/rs/rsSampler.cpp +++ b/libs/rs/rsSampler.cpp @@ -27,6 +27,8 @@ using namespace android::renderscript; Sampler::Sampler(Context *rsc) : ObjectBase(rsc) { + mAllocFile = __FILE__; + mAllocLine = __LINE__; // Should not get called. rsAssert(0); } @@ -38,6 +40,8 @@ Sampler::Sampler(Context *rsc, RsSamplerValue wrapT, RsSamplerValue wrapR) : ObjectBase(rsc) { + mAllocFile = __FILE__; + mAllocLine = __LINE__; mMagFilter = magFilter; mMinFilter = minFilter; mWrapS = wrapS; diff --git a/libs/rs/rsScript.cpp b/libs/rs/rsScript.cpp index f9526fe..cb1436b 100644 --- a/libs/rs/rsScript.cpp +++ b/libs/rs/rsScript.cpp @@ -21,6 +21,8 @@ using namespace android::renderscript; Script::Script(Context *rsc) : ObjectBase(rsc) { + mAllocFile = __FILE__; + mAllocLine = __LINE__; memset(&mEnviroment, 0, sizeof(mEnviroment)); mEnviroment.mClearColor[0] = 0; mEnviroment.mClearColor[1] = 0; diff --git a/libs/rs/rsScriptC.cpp b/libs/rs/rsScriptC.cpp index fb8180f..e63ed24 100644 --- a/libs/rs/rsScriptC.cpp +++ b/libs/rs/rsScriptC.cpp @@ -35,6 +35,8 @@ using namespace android::renderscript; ScriptC::ScriptC(Context *rsc) : Script(rsc) { + mAllocFile = __FILE__; + mAllocLine = __LINE__; mAccScript = NULL; memset(&mProgram, 0, sizeof(mProgram)); } diff --git a/libs/rs/rsSimpleMesh.cpp b/libs/rs/rsSimpleMesh.cpp index fe06e0c..b082fd7 100644 --- a/libs/rs/rsSimpleMesh.cpp +++ b/libs/rs/rsSimpleMesh.cpp @@ -24,10 +24,14 @@ using namespace android::renderscript; SimpleMesh::SimpleMesh(Context *rsc) : ObjectBase(rsc) { + mAllocFile = __FILE__; + mAllocLine = __LINE__; } SimpleMesh::~SimpleMesh() { + delete[] mVertexTypes; + delete[] mVertexBuffers; } void SimpleMesh::render() const diff --git a/libs/rs/rsType.cpp b/libs/rs/rsType.cpp index 010e49b..4edd0d4 100644 --- a/libs/rs/rsType.cpp +++ b/libs/rs/rsType.cpp @@ -22,6 +22,8 @@ using namespace android::renderscript; Type::Type(Context *rsc) : ObjectBase(rsc) { + mAllocFile = __FILE__; + mAllocLine = __LINE__; mLODs = 0; mLODCount = 0; memset(&mGL, 0, sizeof(mGL)); |