[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-5.1' - comphelper/source include/comphelper include/sfx2 sfx2/source sw/qa sw/source

Miklos Vajna vmiklos at collabora.co.uk
Tue Oct 4 13:21:32 UTC 2016


 comphelper/source/misc/lok.cxx                 |   12 ++++++
 include/comphelper/lok.hxx                     |    5 ++
 include/sfx2/viewsh.hxx                        |    6 ---
 sfx2/source/view/viewsh.cxx                    |   18 ----------
 sw/qa/extras/tiledrendering/tiledrendering.cxx |   44 ++++++++++++++++++++++++-
 sw/source/core/view/viewsh.cxx                 |    4 +-
 sw/source/uibase/docvw/PostItMgr.cxx           |    6 +--
 sw/source/uibase/docvw/SidebarWin.cxx          |    6 +--
 8 files changed, 69 insertions(+), 32 deletions(-)

New commits:
commit dfc9a744a536fb822ad067683c957143bc81c5b4
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Tue Oct 4 10:56:55 2016 +0200

    comphelper: move setTiledPainting() from SfxViewShell
    
    And make it a static one. The primary point of that member function is
    to prevent invalidations during paint, and since multiple views are
    allowed, it wasn't extended to filter out invalidations from all views,
    not just from the current one. (Same goes for other callback types.)
    
    (cherry picked from commit 59e38e946f19ab59370f8e52370b7a7b861cc558)
    
    Conflicts:
    	include/sfx2/viewsh.hxx
    	sfx2/source/view/viewsh.cxx
    
    Change-Id: I23e6b2c2ff94227f2b72c481148b2d8279ae2905

diff --git a/comphelper/source/misc/lok.cxx b/comphelper/source/misc/lok.cxx
index e1a099d..cf776f0 100644
--- a/comphelper/source/misc/lok.cxx
+++ b/comphelper/source/misc/lok.cxx
@@ -19,6 +19,8 @@ static bool g_bActive(false);
 
 static bool g_bPartInInvalidation(false);
 
+static bool g_bTiledPainting(false);
+
 void setActive(bool bActive)
 {
     g_bActive = bActive;
@@ -39,6 +41,16 @@ bool isPartInInvalidation()
     return g_bPartInInvalidation;
 }
 
+void setTiledPainting(bool bTiledPainting)
+{
+    g_bTiledPainting = bTiledPainting;
+}
+
+bool isTiledPainting()
+{
+    return g_bTiledPainting;
+}
+
 static bool g_bLocalRendering(false);
 
 void setLocalRendering(bool bLocalRendering)
diff --git a/include/comphelper/lok.hxx b/include/comphelper/lok.hxx
index 529694c..ca9f87f 100644
--- a/include/comphelper/lok.hxx
+++ b/include/comphelper/lok.hxx
@@ -48,6 +48,11 @@ COMPHELPER_DLLPUBLIC bool isPartInInvalidation();
 /// Set whether clients want a part number in an invalidation payload.
 COMPHELPER_DLLPUBLIC void setPartInInvalidation(bool bPartInInvalidation);
 
+/// Check if we are doing tiled painting.
+COMPHELPER_DLLPUBLIC bool isTiledPainting();
+/// Set if we are doing tiled painting.
+COMPHELPER_DLLPUBLIC void setTiledPainting(bool bTiledPainting);
+
 // Status indicator handling. Even if in theory there could be several status indicators active at
 // the same time, in practice there is only one at a time, so we don't handle any identification of
 // status indicator in this API.
diff --git a/include/sfx2/viewsh.hxx b/include/sfx2/viewsh.hxx
index fb93674..e2c0b75 100644
--- a/include/sfx2/viewsh.hxx
+++ b/include/sfx2/viewsh.hxx
@@ -331,12 +331,6 @@ public:
     void setTiledSearching(bool bTiledSearching);
     /// Are we doing tiled searching?
     bool isTiledSearching() const;
-    /// Set if we are doing tiled painting.
-    void setTiledPainting(bool bTiledPainting);
-    /// Are we doing tiled painting?
-    bool isTiledPainting() const;
-    /// Get if we are doing tiled painting.
-    bool getTiledPainting() const;
     /// See lok::Document::getPart().
     virtual int getPart() const;
     virtual void dumpAsXml(struct _xmlTextWriter* pWriter) const;
diff --git a/sfx2/source/view/viewsh.cxx b/sfx2/source/view/viewsh.cxx
index ad04649..e308a1b 100644
--- a/sfx2/source/view/viewsh.cxx
+++ b/sfx2/source/view/viewsh.cxx
@@ -316,7 +316,6 @@ SfxViewShell_Impl::SfxViewShell_Impl(SfxViewShellFlags const nFlags)
 ,   m_pLibreOfficeKitViewCallback(nullptr)
 ,   m_pLibreOfficeKitViewData(nullptr)
 ,   m_bTiledSearching(false)
-,   m_bTiledPainting(false)
 ,   m_nViewShellId(SfxViewShell_Impl::m_nLastViewShellId++)
 {}
 
@@ -1620,7 +1619,7 @@ void SfxViewShell::registerLibreOfficeKitViewCallback(LibreOfficeKitCallback pCa
 
 void SfxViewShell::libreOfficeKitViewCallback(int nType, const char* pPayload) const
 {
-    if (pImp->m_bTiledPainting)
+    if (comphelper::LibreOfficeKit::isTiledPainting())
         return;
 
     if (pImp->m_bTiledSearching)
@@ -1655,21 +1654,6 @@ bool SfxViewShell::isTiledSearching() const
     return pImp->m_bTiledSearching;
 }
 
-void SfxViewShell::setTiledPainting(bool bTiledPainting)
-{
-    pImp->m_bTiledPainting = bTiledPainting;
-}
-
-bool SfxViewShell::isTiledPainting() const
-{
-    return pImp->m_bTiledPainting;
-}
-
-bool SfxViewShell::getTiledPainting() const
-{
-    return pImp->m_bTiledPainting;
-}
-
 int SfxViewShell::getPart() const
 {
     return 0;
diff --git a/sw/qa/extras/tiledrendering/tiledrendering.cxx b/sw/qa/extras/tiledrendering/tiledrendering.cxx
index e7b78b7..eb64e9f 100644
--- a/sw/qa/extras/tiledrendering/tiledrendering.cxx
+++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx
@@ -78,6 +78,7 @@ public:
     void testRedlineColors();
     void testCommentEndTextEdit();
     void testCursorPosition();
+    void testPaintCallbacks();
 
     CPPUNIT_TEST_SUITE(SwTiledRenderingTest);
     CPPUNIT_TEST(testRegisterCallback);
@@ -119,6 +120,7 @@ public:
     CPPUNIT_TEST(testRedlineColors);
     CPPUNIT_TEST(testCommentEndTextEdit);
     CPPUNIT_TEST(testCursorPosition);
+    CPPUNIT_TEST(testPaintCallbacks);
     CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -641,6 +643,8 @@ public:
     bool m_bGraphicViewSelection;
     bool m_bGraphicSelection;
     bool m_bViewLock;
+    /// Set if any callback was invoked.
+    bool m_bCalled;
 
     ViewCallback()
         : m_bOwnCursorInvalidated(false),
@@ -652,7 +656,8 @@ public:
           m_bViewCursorVisible(false),
           m_bGraphicViewSelection(false),
           m_bGraphicSelection(false),
-          m_bViewLock(false)
+          m_bViewLock(false),
+          m_bCalled(false)
     {
     }
 
@@ -664,6 +669,7 @@ public:
     void callbackImpl(int nType, const char* pPayload)
     {
         OString aPayload(pPayload);
+        m_bCalled = true;
         switch (nType)
         {
         case LOK_CALLBACK_INVALIDATE_TILES:
@@ -1530,6 +1536,42 @@ void SwTiledRenderingTest::testCursorPosition()
     comphelper::LibreOfficeKit::setActive(false);
 }
 
+template<typename T>
+struct NoDelete
+{
+   void operator()(T* /* p */) {}
+};
+
+void SwTiledRenderingTest::testPaintCallbacks()
+{
+    // Test that paintTile() never results in callbacks, which can cause a
+    // paint <-> invalidate loop.
+
+    // Load a document and register a callback for the first view.
+    comphelper::LibreOfficeKit::setActive();
+    SwXTextDocument* pXTextDocument = createDoc();
+    ViewCallback aView1;
+    SfxViewShell::Current()->registerLibreOfficeKitViewCallback(&ViewCallback::callback, &aView1);
+
+    // Create a second view and paint a tile on that second view.
+    SfxLokHelper::createView();
+    int nCanvasWidth = 256;
+    int nCanvasHeight = 256;
+    std::vector<unsigned char> aBuffer(nCanvasWidth * nCanvasHeight * 4);
+    ScopedVclPtrInstance<VirtualDevice> pDevice(nullptr, Size(1, 1), DeviceFormat::DEFAULT);
+    boost::shared_array<sal_uInt8> aSharedBuffer(aBuffer.data(), NoDelete<sal_uInt8>());
+    pDevice->SetOutputSizePixelScaleOffsetAndBuffer(Size(nCanvasWidth, nCanvasHeight), Fraction(1.0), Point(), aSharedBuffer);
+    // Make sure that painting a tile in the second view doesn't invoke
+    // callbacks on the first view.
+    aView1.m_bCalled = false;
+    pXTextDocument->paintTile(*pDevice.get(), nCanvasWidth, nCanvasHeight, /*nTilePosX=*/0, /*nTilePosY=*/0, /*nTileWidth=*/3840, /*nTileHeight=*/3840);
+    CPPUNIT_ASSERT(!aView1.m_bCalled);
+
+    mxComponent->dispose();
+    mxComponent.clear();
+    comphelper::LibreOfficeKit::setActive(false);
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(SwTiledRenderingTest);
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sw/source/core/view/viewsh.cxx b/sw/source/core/view/viewsh.cxx
index 2a518cd..52dcfb4 100644
--- a/sw/source/core/view/viewsh.cxx
+++ b/sw/source/core/view/viewsh.cxx
@@ -1843,7 +1843,7 @@ void SwViewShell::PaintTile(VirtualDevice &rDevice, int contextWidth, int contex
     // TODO clean up SwViewShell's approach to output devices (the many of
     // them - mpBufferedOut, mpOut, mpWin, ...)
     OutputDevice *pSaveOut = mpOut;
-    GetSfxViewShell()->setTiledPainting(true);
+    comphelper::LibreOfficeKit::setTiledPainting(true);
     mpOut = &rDevice;
 
     // resizes the virtual device so to contain the entries context
@@ -1896,7 +1896,7 @@ void SwViewShell::PaintTile(VirtualDevice &rDevice, int contextWidth, int contex
 
     // SwViewShell's output device tear down
     mpOut = pSaveOut;
-    GetSfxViewShell()->setTiledPainting(false);
+    comphelper::LibreOfficeKit::setTiledPainting(false);
 }
 
 void SwViewShell::SetBrowseBorder( const Size& rNew )
diff --git a/sw/source/uibase/docvw/PostItMgr.cxx b/sw/source/uibase/docvw/PostItMgr.cxx
index e3e6b6a..62dd7cc 100644
--- a/sw/source/uibase/docvw/PostItMgr.cxx
+++ b/sw/source/uibase/docvw/PostItMgr.cxx
@@ -737,13 +737,13 @@ void SwPostItMgr::LayoutPostIts()
                             // view that has the comment focus emits callbacks,
                             // so the editing view jumps to the comment, but
                             // not the others.
-                            bool bTiledPainting = mpView->getTiledPainting();
+                            bool bTiledPainting = comphelper::LibreOfficeKit::isTiledPainting();
                             if (!bTiledPainting)
                                 // No focus -> disable callbacks.
-                                mpView->setTiledPainting(!(*i)->HasChildPathFocus());
+                                comphelper::LibreOfficeKit::setTiledPainting(!(*i)->HasChildPathFocus());
                             (*i)->ShowNote();
                             if (!bTiledPainting)
-                                mpView->setTiledPainting(bTiledPainting);
+                                comphelper::LibreOfficeKit::setTiledPainting(bTiledPainting);
                         }
                         else
                         {
diff --git a/sw/source/uibase/docvw/SidebarWin.cxx b/sw/source/uibase/docvw/SidebarWin.cxx
index d6eafd3..20cab03 100644
--- a/sw/source/uibase/docvw/SidebarWin.cxx
+++ b/sw/source/uibase/docvw/SidebarWin.cxx
@@ -1269,11 +1269,11 @@ void SwSidebarWin::DeactivatePostIt()
     // Make sure this view doesn't emit LOK callbacks during the update, as the
     // sidebar window's SidebarTextControl doesn't have a valid twip offset
     // (map mode origin) during that operation.
-    bool bTiledPainting = mrView.getTiledPainting();
-    mrView.setTiledPainting(true);
+    bool bTiledPainting = comphelper::LibreOfficeKit::isTiledPainting();
+    comphelper::LibreOfficeKit::setTiledPainting(true);
     // write the visible text back into the SwField
     UpdateData();
-    mrView.setTiledPainting(bTiledPainting);
+    comphelper::LibreOfficeKit::setTiledPainting(bTiledPainting);
 
     if ( !Application::GetSettings().GetStyleSettings().GetHighContrastMode() )
         GetOutlinerView()->SetBackgroundColor(COL_TRANSPARENT);


More information about the Libreoffice-commits mailing list