sw/qa/extras/tiledrendering/tiledrendering.cxx |   65 +++++++++++++++++++++++++
 1 file changed, 65 insertions(+)

New commits:
commit cc5038f07291b034641b75bfcefa70f0ac6e1897
Author:     Paris Oplopoios <paris.oplopo...@collabora.com>
AuthorDate: Wed Mar 22 16:12:14 2023 +0200
Commit:     Paris Oplopoios <parisop...@gmail.com>
CommitDate: Thu Mar 23 23:14:06 2023 +0000

    Test tiled rendering view separation
    
    Make sure that changing the theme in one view doesn't change it in
    another view when doing tiled rendering
    
    Change-Id: I0a21dc36bfb825337fe74a11099ecc728b99c861
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/149441
    Tested-by: Paris Oplopoios <parisop...@gmail.com>
    Reviewed-by: Paris Oplopoios <parisop...@gmail.com>

diff --git a/sw/qa/extras/tiledrendering/tiledrendering.cxx 
b/sw/qa/extras/tiledrendering/tiledrendering.cxx
index 7fcdeb0644d4..317d77f0b29b 100644
--- a/sw/qa/extras/tiledrendering/tiledrendering.cxx
+++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx
@@ -1719,6 +1719,71 @@ CPPUNIT_TEST_FIXTURE(SwTiledRenderingTest, 
testGetViewRenderState)
     CPPUNIT_ASSERT_EQUAL(OString("PS"), pXTextDocument->getViewRenderState());
 }
 
+// Helper function to get a tile to a bitmap and check the pixel color
+static void assertTilePixelColor(SwXTextDocument* pXTextDocument, int nPixelX, 
int nPixelY, Color aColor)
+{
+    size_t nCanvasSize = 1024;
+    size_t nTileSize = 256;
+    std::vector<unsigned char> aPixmap(nCanvasSize * nCanvasSize * 4, 0);
+    ScopedVclPtrInstance<VirtualDevice> pDevice(DeviceFormat::DEFAULT);
+    pDevice->SetBackground(Wallpaper(COL_TRANSPARENT));
+    pDevice->SetOutputSizePixelScaleOffsetAndLOKBuffer(Size(nCanvasSize, 
nCanvasSize),
+            Fraction(1.0), Point(), aPixmap.data());
+    pXTextDocument->paintTile(*pDevice, nCanvasSize, nCanvasSize, 0, 0, 15360, 
7680);
+    pDevice->EnableMapMode(false);
+    Bitmap aBitmap = pDevice->GetBitmap(Point(0, 0), Size(nTileSize, 
nTileSize));
+    Bitmap::ScopedReadAccess pAccess(aBitmap);
+    Color aActualColor(pAccess->GetPixel(nPixelX, nPixelY));
+    CPPUNIT_ASSERT_EQUAL(aColor, aActualColor);
+}
+
+// Test that changing the theme in one view doesn't change it in the other view
+CPPUNIT_TEST_FIXTURE(SwTiledRenderingTest, testThemeViewSeparation)
+{
+    SwXTextDocument* pXTextDocument = createDoc();
+    int nFirstViewId = SfxLokHelper::getView();
+    ViewCallback aView1;
+    // First view is at light mode
+    assertTilePixelColor(pXTextDocument, 255, 255, COL_WHITE);
+    // Create second view
+    SfxLokHelper::createView();
+    int nSecondViewId = SfxLokHelper::getView();
+    ViewCallback aView2;
+    // Set second view to dark mode
+    {
+        SwDoc* pDoc = pXTextDocument->GetDocShell()->GetDoc();
+        SwView* pView = pDoc->GetDocShell()->GetView();
+        uno::Reference<frame::XFrame> xFrame = 
pView->GetViewFrame()->GetFrame().GetFrameInterface();
+        uno::Sequence<beans::PropertyValue> aPropertyValues = 
comphelper::InitPropertySequence(
+            {
+                { "NewTheme", 
uno::Any(OUString("COLOR_SCHEME_LIBREOFFICE_DARK")) },
+            }
+        );
+        comphelper::dispatchCommand(".uno:ChangeTheme", xFrame, 
aPropertyValues);
+    }
+    assertTilePixelColor(pXTextDocument, 255, 255, Color(0x1c, 0x1c, 0x1c));
+    // First view still in light mode
+    SfxLokHelper::setView(nFirstViewId);
+    assertTilePixelColor(pXTextDocument, 255, 255, COL_WHITE);
+    // Second view still in dark mode
+    SfxLokHelper::setView(nSecondViewId);
+    assertTilePixelColor(pXTextDocument, 255, 255, Color(0x1c, 0x1c, 0x1c));
+    // Switch second view back to light mode
+    {
+        SwDoc* pDoc = pXTextDocument->GetDocShell()->GetDoc();
+        SwView* pView = pDoc->GetDocShell()->GetView();
+        uno::Reference<frame::XFrame> xFrame = 
pView->GetViewFrame()->GetFrame().GetFrameInterface();
+        uno::Sequence<beans::PropertyValue> aPropertyValues = 
comphelper::InitPropertySequence(
+            {
+                { "NewTheme", 
uno::Any(OUString("COLOR_SCHEME_LIBREOFFICE_AUTOMATIC")) },
+            }
+        );
+        comphelper::dispatchCommand(".uno:ChangeTheme", xFrame, 
aPropertyValues);
+    }
+    // Now in light mode
+    assertTilePixelColor(pXTextDocument, 255, 255, COL_WHITE);
+}
+
 CPPUNIT_TEST_FIXTURE(SwTiledRenderingTest, testSetViewGraphicSelection)
 {
     // Load a document.

Reply via email to