summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorParis Oplopoios <paris.oplopoios@collabora.com>2023-03-22 16:12:14 +0200
committerMiklos Vajna <vmiklos@collabora.com>2023-05-02 08:37:41 +0200
commitb42f3d450d861ecf7b8867ad2ad38537bf888888 (patch)
treed4da2d4a32983765329a8d64789be2af221f879c /sw
parentff307906ce794173e4f26dcad84518d010668ea3 (diff)
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/+/149324 Tested-by: Jenkins Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'sw')
-rw-r--r--sw/qa/extras/tiledrendering/tiledrendering.cxx96
1 files changed, 96 insertions, 0 deletions
diff --git a/sw/qa/extras/tiledrendering/tiledrendering.cxx b/sw/qa/extras/tiledrendering/tiledrendering.cxx
index 06b9ee25a64c..c292647db850 100644
--- a/sw/qa/extras/tiledrendering/tiledrendering.cxx
+++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx
@@ -1677,6 +1677,102 @@ CPPUNIT_TEST_FIXTURE(SwTiledRenderingTest, testGetViewRenderState)
CPPUNIT_ASSERT_EQUAL(OString("PS;Default"), 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::WITHOUT_ALPHA);
+ 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)
+{
+ Color aDarkColor(0x1c, 0x1c, 0x1c);
+ // Add a minimal dark scheme
+ {
+ svtools::EditableColorConfig aColorConfig;
+ svtools::ColorConfigValue aValue;
+ aValue.bIsVisible = true;
+ aValue.nColor = aDarkColor;
+ aColorConfig.SetColorValue(svtools::DOCCOLOR, aValue);
+ aColorConfig.AddScheme(u"Dark");
+ }
+ // Add a minimal light scheme
+ {
+ svtools::EditableColorConfig aColorConfig;
+ svtools::ColorConfigValue aValue;
+ aValue.bIsVisible = true;
+ aValue.nColor = COL_WHITE;
+ aColorConfig.SetColorValue(svtools::DOCCOLOR, aValue);
+ aColorConfig.AddScheme(u"Light");
+ }
+ SwXTextDocument* pXTextDocument = createDoc();
+ int nFirstViewId = SfxLokHelper::getView();
+ ViewCallback aView1;
+ // Set first view to light scheme
+ {
+ 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("Light")) },
+ }
+ );
+ comphelper::dispatchCommand(".uno:ChangeTheme", xFrame, aPropertyValues);
+ }
+ // First view is in light scheme
+ assertTilePixelColor(pXTextDocument, 255, 255, COL_WHITE);
+ // Create second view
+ SfxLokHelper::createView();
+ int nSecondViewId = SfxLokHelper::getView();
+ ViewCallback aView2;
+ // Set second view to dark scheme
+ {
+ 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("Dark")) },
+ }
+ );
+ comphelper::dispatchCommand(".uno:ChangeTheme", xFrame, aPropertyValues);
+ }
+ assertTilePixelColor(pXTextDocument, 255, 255, aDarkColor);
+ // First view still in light scheme
+ SfxLokHelper::setView(nFirstViewId);
+ assertTilePixelColor(pXTextDocument, 255, 255, COL_WHITE);
+ // Second view still in dark scheme
+ SfxLokHelper::setView(nSecondViewId);
+ assertTilePixelColor(pXTextDocument, 255, 255, aDarkColor);
+ // Switch second view back to light scheme
+ {
+ 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("Light")) },
+ }
+ );
+ comphelper::dispatchCommand(".uno:ChangeTheme", xFrame, aPropertyValues);
+ }
+ // Now in light scheme
+ assertTilePixelColor(pXTextDocument, 255, 255, COL_WHITE);
+}
+
CPPUNIT_TEST_FIXTURE(SwTiledRenderingTest, testSetViewGraphicSelection)
{
// Load a document.