Merge "Correctly free resouces bound to scripts when the scripts are deleted." into honeycomb
This commit is contained in:
committed by
Android (Google) Code Review
commit
55f8f12119
@@ -528,6 +528,7 @@ void * Context::threadProc(void *vrsc) {
|
|||||||
|
|
||||||
void Context::destroyWorkerThreadResources() {
|
void Context::destroyWorkerThreadResources() {
|
||||||
//LOGV("destroyWorkerThreadResources 1");
|
//LOGV("destroyWorkerThreadResources 1");
|
||||||
|
ObjectBase::zeroAllUserRef(this);
|
||||||
if (mIsGraphicsContext) {
|
if (mIsGraphicsContext) {
|
||||||
mRaster.clear();
|
mRaster.clear();
|
||||||
mFragment.clear();
|
mFragment.clear();
|
||||||
@@ -542,7 +543,6 @@ void Context::destroyWorkerThreadResources() {
|
|||||||
mStateFont.deinit(this);
|
mStateFont.deinit(this);
|
||||||
mShaderCache.cleanupAll();
|
mShaderCache.cleanupAll();
|
||||||
}
|
}
|
||||||
ObjectBase::zeroAllUserRef(this);
|
|
||||||
//LOGV("destroyWorkerThreadResources 2");
|
//LOGV("destroyWorkerThreadResources 2");
|
||||||
mExit = true;
|
mExit = true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -74,6 +74,15 @@ bool Font::init(const char *name, float fontSize, uint32_t dpi, const void *data
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Font::preDestroy() const {
|
||||||
|
for (uint32_t ct = 0; ct < mRSC->mStateFont.mActiveFonts.size(); ct++) {
|
||||||
|
if (mRSC->mStateFont.mActiveFonts[ct] == this) {
|
||||||
|
mRSC->mStateFont.mActiveFonts.removeAt(ct);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Font::invalidateTextureCache() {
|
void Font::invalidateTextureCache() {
|
||||||
for (uint32_t i = 0; i < mCachedGlyphs.size(); i ++) {
|
for (uint32_t i = 0; i < mCachedGlyphs.size(); i ++) {
|
||||||
mCachedGlyphs.valueAt(i)->mIsValid = false;
|
mCachedGlyphs.valueAt(i)->mIsValid = false;
|
||||||
@@ -309,13 +318,6 @@ Font::~Font() {
|
|||||||
FT_Done_Face(mFace);
|
FT_Done_Face(mFace);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (uint32_t ct = 0; ct < mRSC->mStateFont.mActiveFonts.size(); ct++) {
|
|
||||||
if (mRSC->mStateFont.mActiveFonts[ct] == this) {
|
|
||||||
mRSC->mStateFont.mActiveFonts.removeAt(ct);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (uint32_t i = 0; i < mCachedGlyphs.size(); i ++) {
|
for (uint32_t i = 0; i < mCachedGlyphs.size(); i ++) {
|
||||||
CachedGlyphInfo *glyph = mCachedGlyphs.valueAt(i);
|
CachedGlyphInfo *glyph = mCachedGlyphs.valueAt(i);
|
||||||
delete glyph;
|
delete glyph;
|
||||||
@@ -799,11 +801,6 @@ void FontState::deinit(Context *rsc) {
|
|||||||
|
|
||||||
mDefault.clear();
|
mDefault.clear();
|
||||||
|
|
||||||
Vector<Font*> fontsToDereference = mActiveFonts;
|
|
||||||
for (uint32_t i = 0; i < fontsToDereference.size(); i ++) {
|
|
||||||
fontsToDereference[i]->zeroUserRef();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mLibrary) {
|
if (mLibrary) {
|
||||||
FT_Done_FreeType( mLibrary );
|
FT_Done_FreeType( mLibrary );
|
||||||
mLibrary = NULL;
|
mLibrary = NULL;
|
||||||
|
|||||||
@@ -119,6 +119,7 @@ protected:
|
|||||||
Font(Context *rsc);
|
Font(Context *rsc);
|
||||||
bool init(const char *name, float fontSize, uint32_t dpi, const void *data = NULL, uint32_t dataLen = 0);
|
bool init(const char *name, float fontSize, uint32_t dpi, const void *data = NULL, uint32_t dataLen = 0);
|
||||||
|
|
||||||
|
virtual void preDestroy() const;
|
||||||
FT_Face mFace;
|
FT_Face mFace;
|
||||||
bool mInitialized;
|
bool mInitialized;
|
||||||
bool mHasKerning;
|
bool mHasKerning;
|
||||||
|
|||||||
@@ -78,8 +78,6 @@ void Script::setVarObj(uint32_t slot, ObjectBase *val) {
|
|||||||
(*destPtr)->decSysRef();
|
(*destPtr)->decSysRef();
|
||||||
}
|
}
|
||||||
*destPtr = val;
|
*destPtr = val;
|
||||||
} else {
|
|
||||||
LOGV("Calling setVarObj on slot = %i which is null. This is dangerous because the script will not hold a ref count on the object.", slot);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -94,16 +94,24 @@ char *genCacheFileName(const char *cacheDir,
|
|||||||
}
|
}
|
||||||
|
|
||||||
ScriptC::ScriptC(Context *rsc) : Script(rsc) {
|
ScriptC::ScriptC(Context *rsc) : Script(rsc) {
|
||||||
LOGD(">>>> ScriptC ctor called, obj=%p", this);
|
|
||||||
mBccScript = NULL;
|
mBccScript = NULL;
|
||||||
memset(&mProgram, 0, sizeof(mProgram));
|
memset(&mProgram, 0, sizeof(mProgram));
|
||||||
}
|
}
|
||||||
|
|
||||||
ScriptC::~ScriptC() {
|
ScriptC::~ScriptC() {
|
||||||
LOGD(">>>> ~ScriptC() mBccScript = %p", mBccScript);
|
|
||||||
if (mBccScript) {
|
if (mBccScript) {
|
||||||
|
if (mProgram.mObjectSlotList) {
|
||||||
|
for (size_t ct=0; ct < mProgram.mObjectSlotCount; ct++) {
|
||||||
|
setVarObj(mProgram.mObjectSlotList[ct], NULL);
|
||||||
|
}
|
||||||
|
delete [] mProgram.mObjectSlotList;
|
||||||
|
mProgram.mObjectSlotList = NULL;
|
||||||
|
mProgram.mObjectSlotCount = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
LOGD(">>>> ~ScriptC bccDisposeScript(%p)", mBccScript);
|
||||||
bccDisposeScript(mBccScript);
|
bccDisposeScript(mBccScript);
|
||||||
LOGD(">>>> ~ScriptC(mBCCScript)");
|
|
||||||
}
|
}
|
||||||
free(mEnviroment.mScriptText);
|
free(mEnviroment.mScriptText);
|
||||||
mEnviroment.mScriptText = NULL;
|
mEnviroment.mScriptText = NULL;
|
||||||
@@ -589,6 +597,16 @@ bool ScriptCState::runCompiler(Context *rsc,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t objectSlotCount = bccGetObjectSlotCount(s->mBccScript);
|
||||||
|
uint32_t *objectSlots = NULL;
|
||||||
|
if (objectSlotCount) {
|
||||||
|
objectSlots = new uint32_t[objectSlotCount];
|
||||||
|
bccGetObjectSlotList(s->mBccScript, objectSlotCount, objectSlots);
|
||||||
|
s->mProgram.mObjectSlotList = objectSlots;
|
||||||
|
s->mProgram.mObjectSlotCount = objectSlotCount;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -42,8 +42,12 @@ public:
|
|||||||
|
|
||||||
RunScript_t mRoot;
|
RunScript_t mRoot;
|
||||||
VoidFunc_t mInit;
|
VoidFunc_t mInit;
|
||||||
|
|
||||||
|
uint32_t * mObjectSlotList;
|
||||||
|
uint32_t mObjectSlotCount;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
Program_t mProgram;
|
Program_t mProgram;
|
||||||
|
|
||||||
BCCScriptRef mBccScript;
|
BCCScriptRef mBccScript;
|
||||||
|
|||||||
Reference in New Issue
Block a user