desktop/qa/desktop_lib/test_desktop_lib.cxx |   28 ++++++++++++++++++++++++++++
 desktop/source/lib/init.cxx                 |    9 +++++++++
 2 files changed, 37 insertions(+)

New commits:
commit 356a5f63b18045746c1c974d6041b635c4ea99a7
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Thu Apr 17 15:04:47 2025 +0200
Commit:     Caolán McNamara <caolan.mcnam...@collabora.com>
CommitDate: Thu Apr 17 17:04:32 2025 +0200

    tdf#166218 desktop lok: fix paintTile()
    
    This went wrong in commit bc2d1922e26bcf4e243150c3d439226743c6c2ba
    (cool#11254 desktop lok: avoid invalidations if no tiles are sent,
    2025-03-05), where I changed doc_paintPartTile(), but forgot to adapt
    paintTile() accordingly.
    
    Change-Id: I25fcbbc6681c6b6283ebe051037f3abbfdc34040
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/184335
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>

diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx 
b/desktop/qa/desktop_lib/test_desktop_lib.cxx
index bb957e0611a5..8fd22a443926 100644
--- a/desktop/qa/desktop_lib/test_desktop_lib.cxx
+++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx
@@ -180,6 +180,7 @@ public:
     void testBinaryCallback();
     void testOmitInvalidate();
     void test2ViewsOmitInvalidate();
+    void testPaintTileOmitInvalidate();
     void testInput();
     void testRedlineWriter();
     void testRedlineCalc();
@@ -254,6 +255,7 @@ public:
     CPPUNIT_TEST(testBinaryCallback);
     CPPUNIT_TEST(testOmitInvalidate);
     CPPUNIT_TEST(test2ViewsOmitInvalidate);
+    CPPUNIT_TEST(testPaintTileOmitInvalidate);
     CPPUNIT_TEST(testInput);
     CPPUNIT_TEST(testRedlineWriter);
     CPPUNIT_TEST(testRedlineCalc);
@@ -2348,6 +2350,32 @@ void DesktopLOKTest::testPaintPartTile()
     //CPPUNIT_ASSERT(aView1.m_bTilesInvalidated);
 }
 
+void DesktopLOKTest::testPaintTileOmitInvalidate()
+{
+    // Given a painted tile:
+    comphelper::LibreOfficeKit::setPartInInvalidation(true);
+    comphelper::ScopeGuard aGuard([]()
+    {
+        comphelper::LibreOfficeKit::setPartInInvalidation(false);
+    });
+    LibLODocument_Impl* pDocument = loadDoc("blank_text.odt");
+    ViewCallback aView(pDocument);
+    const int nCanvasWidth = 256;
+    const int nCanvasHeight = 256;
+    std::array<sal_uInt8, nCanvasWidth * nCanvasHeight * 4> aPixels;
+    pDocument->m_pDocumentClass->paintTile(pDocument, aPixels.data(), 
nCanvasWidth, nCanvasHeight, 0, 0, 3840, 3840);
+    Scheduler::ProcessEventsToIdle();
+    aView.m_bTilesInvalidated = false;
+
+    // When pressing a key:
+    pDocument->pClass->postKeyEvent(pDocument, LOK_KEYEVENT_KEYINPUT, 'x', 0);
+    pDocument->pClass->postKeyEvent(pDocument, LOK_KEYEVENT_KEYUP, 'x', 0);
+    Scheduler::ProcessEventsToIdle();
+
+    // Then make sure we get an invalidation:
+    CPPUNIT_ASSERT(aView.m_bTilesInvalidated);
+}
+
 void DesktopLOKTest::testPaintPartTileDifferentSchemes()
 {
     Color aDarkColor(0x1c, 0x1c, 0x1c);
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index 98b390d91dcc..35cab1a34ebd 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -4292,6 +4292,15 @@ static void doc_paintTile(LibreOfficeKitDocument* pThis,
 #else
     (void) pBuffer;
 #endif
+
+    // Inform all views with the same view render state about the paint, so 
they know if makes sense
+    // to invalidate those areas later.
+    LibLODocument_Impl* pDocument = static_cast<LibLODocument_Impl*>(pThis);
+    int nOrigViewId = doc_getView(pThis);
+    int nPart = pDoc->getPart();
+    int nMode = pDoc->getEditMode();
+    tools::Rectangle aRectangle{Point(nTilePosX, nTilePosY), Size(nTileWidth, 
nTileHeight)};
+    pDocument->updateViewsForPaintedTile(nOrigViewId, nPart, nMode, 
aRectangle);
 }
 
 inline static ITiledRenderable* getDocumentPointer(LibreOfficeKitDocument* 
pThis)

Reply via email to