From b179383df08a9f1e3c8e58e6e41dddb7de85266e Mon Sep 17 00:00:00 2001 From: Dennis Francis Date: Tue, 23 Jun 2020 21:15:40 +0530 Subject: paintTile: Try to find a view that matches the tile-zoom requested... by iterating over first few shells to avoid switching of zooms in ScGridWindow::PaintTile and hence avoid grid-offset recomputation on all shapes which is not cheap. Change-Id: Ib086112ebd504087d80c6d6f2879a69dca8ce44f Reviewed-on: https://gerrit.libreoffice.org/c/core/+/98168 Tested-by: Jenkins CollaboraOffice Reviewed-by: Dennis Francis (cherry picked from commit f54d3aa9bee7bc794b18b968835c6d6393f350ea) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/98163 Tested-by: Jenkins --- sc/source/ui/unoobj/docuno.cxx | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/sc/source/ui/unoobj/docuno.cxx b/sc/source/ui/unoobj/docuno.cxx index a3e3f8c603b4..50749096ec9c 100644 --- a/sc/source/ui/unoobj/docuno.cxx +++ b/sc/source/ui/unoobj/docuno.cxx @@ -500,6 +500,32 @@ void ScModelObj::RepaintRange( const ScRangeList& rRange ) pDocShell->PostPaint( rRange, PaintPartFlags::Grid ); } +static ScViewData* lcl_getViewMatchingDocZoomTab(const Fraction& rZoomX, + const Fraction& rZoomY, + const SCTAB nTab, + const ViewShellDocId& rDocId, + const size_t nMaxIter = 5) +{ + size_t nIter = 0; + for (SfxViewShell* pViewShell = SfxViewShell::GetFirst(); + pViewShell && nIter < nMaxIter; + (pViewShell = SfxViewShell::GetNext(*pViewShell)), ++nIter) + { + if (pViewShell->GetDocId() != rDocId) + continue; + + ScTabViewShell* pTabViewShell = dynamic_cast(pViewShell); + if (!pTabViewShell) + continue; + + ScViewData& rData = pTabViewShell->GetViewData(); + if (rData.GetTabNo() == nTab && rData.GetZoomX() == rZoomX && rData.GetZoomY() == rZoomY) + return &rData; + } + + return nullptr; +} + void ScModelObj::paintTile( VirtualDevice& rDevice, int nOutputWidth, int nOutputHeight, int nTilePosX, int nTilePosY, @@ -511,7 +537,17 @@ void ScModelObj::paintTile( VirtualDevice& rDevice, if (!pViewShell) return; - ScViewData* pViewData = &pViewShell->GetViewData(); + ScViewData* pActiveViewData = &pViewShell->GetViewData(); + Fraction aFracX(long(nOutputWidth * TWIPS_PER_PIXEL), nTileWidth); + Fraction aFracY(long(nOutputHeight * TWIPS_PER_PIXEL), nTileHeight); + + // Try to find a view that matches the tile-zoom requested by iterating over + // first few shells. This is to avoid switching of zooms in ScGridWindow::PaintTile + // and hence avoid grid-offset recomputation on all shapes which is not cheap. + ScViewData* pViewData = lcl_getViewMatchingDocZoomTab(aFracX, aFracY, + pActiveViewData->GetTabNo(), pViewShell->GetDocId()); + if (!pViewData) + pViewData = pActiveViewData; ScGridWindow* pGridWindow = pViewData->GetActiveWin(); -- cgit