Merge change 27169 into eclair

* changes:
  Improved object lifecycle tracking and fix leaks.
This commit is contained in:
Android (Google) Code Review
2009-09-25 19:38:40 -04:00
23 changed files with 123 additions and 17 deletions

View File

@@ -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);
}

View File

@@ -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;

View File

@@ -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;

View File

@@ -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);

View File

@@ -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;
}

View File

@@ -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;

View File

@@ -24,6 +24,8 @@ using namespace android::renderscript;
Mesh::Mesh(Context *rsc) : ObjectBase(rsc)
{
mAllocFile = __FILE__;
mAllocLine = __LINE__;
mVerticies = NULL;
mVerticiesCount = 0;
mPrimitives = NULL;

View File

@@ -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;
}
}
}

View File

@@ -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;

View File

@@ -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()

View File

@@ -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 {

View File

@@ -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;

View File

@@ -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 {

View File

@@ -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;

View File

@@ -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 {

View File

@@ -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;

View File

@@ -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 {

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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));
}

View File

@@ -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

View File

@@ -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));