From 2534e5f046654c69173b84d040013b7e1c6c3f1e Mon Sep 17 00:00:00 2001 From: Marco Cecchetti Date: Thu, 26 May 2016 21:28:35 +0200 Subject: tdf#100160 - Changing OpenCL state doesn't update sheet now we re-check for vectorization state of formula token each time OpenCL is enabled or disabled Change-Id: I652397dd154f5fbf788cb511c70e53a47cc94293 Reviewed-on: https://gerrit.libreoffice.org/25727 Reviewed-by: Jan Holesovsky Tested-by: Michael Meeks Reviewed-by: Michael Meeks --- sc/inc/column.hxx | 1 + sc/inc/document.hxx | 1 + sc/inc/table.hxx | 1 + sc/inc/tokenarray.hxx | 1 + sc/source/core/data/column.cxx | 29 +++++++++++++++++++++++++++++ sc/source/core/data/document.cxx | 13 +++++++++++++ sc/source/core/data/table2.cxx | 8 ++++++++ sc/source/ui/unoobj/docuno.cxx | 9 +++++++++ 8 files changed, 63 insertions(+) diff --git a/sc/inc/column.hxx b/sc/inc/column.hxx index 69cb0366fccb..5b319d5177cd 100644 --- a/sc/inc/column.hxx +++ b/sc/inc/column.hxx @@ -375,6 +375,7 @@ public: bool IsFormulaDirty( SCROW nRow ) const; + void CheckVectorizationState(); void SetAllFormulasDirty( const sc::SetFormulaDirtyContext& rCxt ); void SetDirtyFromClip( SCROW nRow1, SCROW nRow2, sc::ColumnSpanSet& rBroadcastSpans ); void SetDirty( SCROW nRow1, SCROW nRow2, BroadcastMode ); diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx index 4cb2de412885..194fc7d319d7 100644 --- a/sc/inc/document.hxx +++ b/sc/inc/document.hxx @@ -1036,6 +1036,7 @@ public: void ResetChanged( const ScRange& rRange ); + void CheckVectorizationState(); void SetAllFormulasDirty( const sc::SetFormulaDirtyContext& rCxt ); void SetDirty( const ScRange&, bool bIncludeEmptyCells ); void SetTableOpDirty( const ScRange& ); // for Interpreter TableOp diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx index da2876f5a366..9efd590469c2 100644 --- a/sc/inc/table.hxx +++ b/sc/inc/table.hxx @@ -526,6 +526,7 @@ public: void ResetChanged( const ScRange& rRange ); + void CheckVectorizationState(); void SetAllFormulasDirty( const sc::SetFormulaDirtyContext& rCxt ); void SetDirty( const ScRange&, ScColumn::BroadcastMode ); void SetDirtyAfterLoad(); diff --git a/sc/inc/tokenarray.hxx b/sc/inc/tokenarray.hxx index 1644264fdc0f..9808b8b4f65a 100644 --- a/sc/inc/tokenarray.hxx +++ b/sc/inc/tokenarray.hxx @@ -65,6 +65,7 @@ public: size_t GetHash() const { return mnHashValue;} ScFormulaVectorState GetVectorState() const { return meVectorState;} + void ResetVectorState() { meVectorState = FormulaVectorEnabled; } /** * If the array contains at least one relative row reference or named diff --git a/sc/source/core/data/column.cxx b/sc/source/core/data/column.cxx index 5f562ca22712..d4b5a2e0b4e7 100644 --- a/sc/source/core/data/column.cxx +++ b/sc/source/core/data/column.cxx @@ -2646,6 +2646,28 @@ public: } }; +class CheckVectorizationHandler +{ +public: + CheckVectorizationHandler() + {} + + void operator() (size_t /*nRow*/, ScFormulaCell* p) + { + ScTokenArray* pCode = p->GetCode(); + if (pCode != nullptr && pCode->GetVectorState() == FormulaVectorDisabled) + { + pCode->ResetVectorState(); + FormulaToken* pFT = pCode->First(); + while (pFT != nullptr) + { + pCode->CheckToken(*pFT); + pFT = pCode->Next(); + } + } + } +}; + struct SetDirtyVarHandler { void operator() (size_t /*nRow*/, ScFormulaCell* p) @@ -3089,6 +3111,13 @@ bool ScColumn::IsFormulaDirty( SCROW nRow ) const return p->GetDirty(); } +void ScColumn::CheckVectorizationState() +{ + sc::AutoCalcSwitch aSwitch(*pDocument, false); + CheckVectorizationHandler aFunc; + sc::ProcessFormula(maCells, aFunc); +} + void ScColumn::SetAllFormulasDirty( const sc::SetFormulaDirtyContext& rCxt ) { // is only done documentwide, no FormulaTracking diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx index ca63d82dae16..c0f4fa3a57e2 100644 --- a/sc/source/core/data/document.cxx +++ b/sc/source/core/data/document.cxx @@ -3716,6 +3716,19 @@ bool ScDocument::HasSelectionData( SCCOL nCol, SCROW nRow, SCTAB nTab ) const return HasStringCells( ScRange( nCol, 0, nTab, nCol, MAXROW, nTab ) ); } +void ScDocument::CheckVectorizationState() +{ + bool bOldAutoCalc = GetAutoCalc(); + bAutoCalc = false; // no mulitple calculations + + TableContainer::iterator it = maTabs.begin(); + for (; it != maTabs.end(); ++it) + if (*it) + (*it)->CheckVectorizationState(); + + SetAutoCalc(bOldAutoCalc); +} + void ScDocument::SetAllFormulasDirty( const sc::SetFormulaDirtyContext& rCxt ) { bool bOldAutoCalc = GetAutoCalc(); diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx index 453ba0a96708..5d43a3728844 100644 --- a/sc/source/core/data/table2.cxx +++ b/sc/source/core/data/table2.cxx @@ -1700,6 +1700,14 @@ void ScTable::SetDirtyVar() aCol[i].SetDirtyVar(); } +void ScTable::CheckVectorizationState() +{ + sc::AutoCalcSwitch aACSwitch(*pDocument, false); + + for (SCCOL i = 0; i <= MAXCOL; i++) + aCol[i].CheckVectorizationState(); +} + void ScTable::SetAllFormulasDirty( const sc::SetFormulaDirtyContext& rCxt ) { sc::AutoCalcSwitch aACSwitch(*pDocument, false); diff --git a/sc/source/ui/unoobj/docuno.cxx b/sc/source/ui/unoobj/docuno.cxx index 7a7b0644ef5e..728cd89b3004 100644 --- a/sc/source/ui/unoobj/docuno.cxx +++ b/sc/source/ui/unoobj/docuno.cxx @@ -2811,6 +2811,9 @@ sal_Bool ScModelObj::isOpenCLEnabled() void ScModelObj::enableOpenCL(sal_Bool bEnable) throw (uno::RuntimeException, std::exception) { + if (ScCalcConfig::isOpenCLEnabled() == static_cast(bEnable)) + return; + std::shared_ptr batch(comphelper::ConfigurationChanges::create()); officecfg::Office::Common::Misc::UseOpenCL::set(bEnable, batch); batch->commit(); @@ -2819,6 +2822,12 @@ void ScModelObj::enableOpenCL(sal_Bool bEnable) if (bEnable) aConfig.setOpenCLConfigToDefault(); ScInterpreter::SetGlobalConfig(aConfig); + + sc::FormulaGroupInterpreter::switchOpenCLDevice(OUString(), true, false); + + ScDocument* pDoc = GetDocument(); + pDoc->CheckVectorizationState(); + } void ScModelObj::enableAutomaticDeviceSelection(sal_Bool bForce) -- cgit v1.2.3