From a914f340ae5b267dc3ab36c1156c795b8fa18f5d Mon Sep 17 00:00:00 2001 From: Shih-wei Liao Date: Mon, 8 Nov 2010 01:33:59 -0800 Subject: Add caching support of BCC binaries. Change-Id: I1e75bb84d88319cb6f1bbe6d907cf6e8ed546142 --- libs/rs/rsScriptC.cpp | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) (limited to 'libs/rs/rsScriptC.cpp') diff --git a/libs/rs/rsScriptC.cpp b/libs/rs/rsScriptC.cpp index ec7780e13a63..6587b51627db 100644 --- a/libs/rs/rsScriptC.cpp +++ b/libs/rs/rsScriptC.cpp @@ -396,15 +396,25 @@ static BCCvoid* symbolLookup(BCCvoid* pContext, const BCCchar* name) { extern const char rs_runtime_lib_bc[]; extern unsigned rs_runtime_lib_bc_size; -void ScriptCState::runCompiler(Context *rsc, ScriptC *s) { +void ScriptCState::runCompiler(Context *rsc, ScriptC *s, const char *resName) { { - StopWatch compileTimer("RenderScript compile time"); s->mBccScript = bccCreateScript(); s->mEnviroment.mIsThreadable = true; - bccScriptBitcode(s->mBccScript, s->mEnviroment.mScriptText, s->mEnviroment.mScriptTextLength); - //bccLinkBitcode(s->mBccScript, rs_runtime_lib_bc, rs_runtime_lib_bc_size); bccRegisterSymbolCallback(s->mBccScript, symbolLookup, s); - bccCompileScript(s->mBccScript); + // bccReadBC() reads in the BitCode, if no cache file corresponding to + // the resName is found. Otherwise, bccReadBC() returns a negative value + // and the "else" branch will be taken. + if (bccReadBC(s->mBccScript, + s->mEnviroment.mScriptText, + s->mEnviroment.mScriptTextLength, + resName) >= 0) { + //bccLinkBC(s->mBccScript, rs_runtime_lib_bc, rs_runtime_lib_bc_size); + bccCompileBC(s->mBccScript); + } else { + // bccReadBC returns a neagative value: Didn't read any script, + // So, use cached binary instead + bccLoadBinary(s->mBccScript); + } bccGetScriptLabel(s->mBccScript, "root", (BCCvoid**) &s->mProgram.mRoot); bccGetScriptLabel(s->mBccScript, "init", (BCCvoid**) &s->mProgram.mInit); } @@ -518,14 +528,15 @@ void rsi_ScriptCSetText(Context *rsc, const char *text, uint32_t len) { ss->mScript->mEnviroment.mScriptTextLength = len; } -RsScript rsi_ScriptCCreate(Context * rsc) { +RsScript rsi_ScriptCCreate(Context * rsc, const char *resName) +{ ScriptCState *ss = &rsc->mScriptC; ObjectBaseRef s(ss->mScript); ss->mScript.clear(); s->incUserRef(); - ss->runCompiler(rsc, s.get()); + ss->runCompiler(rsc, s.get(), resName); ss->clear(rsc); return s.get(); } -- cgit v1.2.3-59-g8ed1b