sc/source/core/opencl/formulagroupcl.cxx | 19 +++++---- sc/source/core/tool/formulagroup.cxx | 62 ++++++++++++++++++++++--------- 2 files changed, 54 insertions(+), 27 deletions(-)
New commits: commit 0b28477226793fca61edee5156c34d4879d7f0e3 Author: Kohei Yoshida <kohei.yosh...@collabora.com> Date: Wed Sep 11 12:33:02 2013 -0400 Dynamically load the opencl group interpreter code at run time. Change-Id: I0e2b393ecf068b57bfe653663be0a788caa22a36 diff --git a/sc/source/core/opencl/formulagroupcl.cxx b/sc/source/core/opencl/formulagroupcl.cxx index dada7e0..d958b1b 100644 --- a/sc/source/core/opencl/formulagroupcl.cxx +++ b/sc/source/core/opencl/formulagroupcl.cxx @@ -27,9 +27,6 @@ namespace sc { namespace opencl { -// A single public entry point for a factory function: -extern sc::FormulaGroupInterpreter *createFormulaGroupInterpreter(); - /////time test dbg double getTimeDiff(const TimeValue& t1, const TimeValue& t2) { @@ -1067,21 +1064,25 @@ bool FormulaGroupInterpreterGroundwater::interpret(ScDocument& rDoc, const ScAdd #endif -sc::FormulaGroupInterpreter *createFormulaGroupInterpreter() +} // namespace opencl + +} // namespace sc + +extern "C" { + +SAL_DLLPUBLIC_EXPORT sc::FormulaGroupInterpreter* SAL_CALL createFormulaGroupOpenCLInterpreter() { if (getenv("SC_SOFTWARE")) return NULL; #if USE_GROUNDWATER_INTERPRETER if (getenv("SC_GROUNDWATER")) - return new FormulaGroupInterpreterGroundwater(); + return new sc::opencl::FormulaGroupInterpreterGroundwater(); #endif - return new FormulaGroupInterpreterOpenCL(); + return new sc::opencl::FormulaGroupInterpreterOpenCL(); } -} // namespace opencl - -} // namespace sc +} /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/core/tool/formulagroup.cxx b/sc/source/core/tool/formulagroup.cxx index 98ef4a9..3b929fa 100644 --- a/sc/source/core/tool/formulagroup.cxx +++ b/sc/source/core/tool/formulagroup.cxx @@ -27,6 +27,12 @@ #include <cstdio> #endif +#ifdef DISABLE_DYNLOADING + +extern sc::FormulaGroupInterpreter* SAL_CALL createFormulaGroupOpenCLInterpreter(); + +#endif + namespace sc { rtl_uString* FormulaGroupContext::intern( const OUString& rStr ) @@ -128,15 +134,6 @@ void fillMatrix( ScMatrix& rMat, size_t nCol, rtl_uString** pStrs, size_t nLen ) } -class FormulaGroupInterpreterOpenCLMissing : public FormulaGroupInterpreter -{ -public: - FormulaGroupInterpreterOpenCLMissing() : FormulaGroupInterpreter() {} - virtual ~FormulaGroupInterpreterOpenCLMissing() {} - virtual ScMatrixRef inverseMatrix(const ScMatrix&) { return ScMatrixRef(); } - virtual bool interpret(ScDocument&, const ScAddress&, const ScFormulaCellGroupRef&, ScTokenArray&) { return false; } -}; - ScMatrixRef FormulaGroupInterpreterSoftware::inverseMatrix(const ScMatrix& /*rMat*/) { return ScMatrixRef(); @@ -278,12 +275,6 @@ bool FormulaGroupInterpreterSoftware::interpret(ScDocument& rDoc, const ScAddres return true; } -// TODO: load module, hook symbol out, check it works, UI on failure etc. -namespace opencl { - extern sc::FormulaGroupInterpreter *createFormulaGroupInterpreter(); -} -FormulaGroupInterpreter *FormulaGroupInterpreter::msInstance = NULL; - #if USE_DUMMY_INTERPRETER class FormulaGroupInterpreterDummy : public FormulaGroupInterpreter { @@ -322,8 +313,28 @@ public: return true; } }; + #endif +#ifndef DISABLE_DYNLOADING + +class FormulaGroupInterpreterOpenCLMissing : public FormulaGroupInterpreter +{ +public: + FormulaGroupInterpreterOpenCLMissing() : FormulaGroupInterpreter() {} + virtual ~FormulaGroupInterpreterOpenCLMissing() {} + virtual ScMatrixRef inverseMatrix(const ScMatrix&) { return ScMatrixRef(); } + virtual bool interpret(ScDocument&, const ScAddress&, const ScFormulaCellGroupRef&, ScTokenArray&) { return false; } +}; + +static void SAL_CALL thisModule() {} + +typedef FormulaGroupInterpreter* (*LoaderFn)(void); + +#endif + +FormulaGroupInterpreter *FormulaGroupInterpreter::msInstance = NULL; + /// load and/or configure the correct formula group interpreter FormulaGroupInterpreter *FormulaGroupInterpreter::getStatic() { @@ -351,10 +362,25 @@ FormulaGroupInterpreter *FormulaGroupInterpreter::getStatic() if ( ScInterpreter::GetGlobalConfig().mbOpenCLEnabled ) { #ifdef DISABLE_DYNLOADING - msInstance = sc::opencl::createFormulaGroupInterpreter(); + msInstance = createFormulaGroupOpenCLInterpreter(); #else - // TODO : Dynamically load scopencl shared object, and instantiate the opencl interpreter. - msInstance = new sc::FormulaGroupInterpreterOpenCLMissing(); + // Dynamically load scopencl shared object, and instantiate the opencl interpreter. + + OUString aLibName(SVLIBRARY("scopencl")); + static osl::Module aModule; + bool bLoaded = aModule.loadRelative(&thisModule, aLibName); + if (!bLoaded) + bLoaded = aModule.load(aLibName); + + if (bLoaded) + { + oslGenericFunction fn = aModule.getFunctionSymbol("createFormulaGroupOpenCLInterpreter"); + if (fn) + msInstance = reinterpret_cast<LoaderFn>(fn)(); + } + + if (!msInstance) + msInstance = new sc::FormulaGroupInterpreterOpenCLMissing(); #endif } #endif _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits