diff --git a/vcl/qa/cppunit/GraphicTest.cxx b/vcl/qa/cppunit/GraphicTest.cxx index b4c3ca6f1c2d..ab43554e4009 100644 --- a/vcl/qa/cppunit/GraphicTest.cxx +++ b/vcl/qa/cppunit/GraphicTest.cxx @@ -1359,6 +1359,25 @@ CPPUNIT_TEST_FIXTURE(GraphicTest, testColorChangeToTransparent) rBitmapAfter.GetPixelColor(410, 140)); } +CPPUNIT_TEST_FIXTURE(GraphicTest, testSwappedOutGraphicKeepsSizeAfterThreadedLoad) +{ + // Given a PNG graphic that was loaded once and then swapped out: + Graphic aGraphic = makeUnloadedGraphic(u"png"); + CPPUNIT_ASSERT(aGraphic.makeAvailable()); + CPPUNIT_ASSERT(aGraphic.ImplGetImpGraphic()->swapOut()); + + // When it is loaded again by the threaded loader and swapped out once more: + std::vector aGraphics{ &aGraphic }; + GraphicFilter::GetGraphicFilter().MakeGraphicsAvailableThreaded(aGraphics); + CPPUNIT_ASSERT(aGraphic.isAvailable()); + CPPUNIT_ASSERT(aGraphic.ImplGetImpGraphic()->swapOut()); + + // Then it still reports its size, so it does not look like an empty graphic. + // Without the fix in place, this test would have failed, the graphic reported a size of 0 + // bytes. + CPPUNIT_ASSERT(aGraphic.GetSizeBytes() > 0); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/source/gdi/impgraph.cxx b/vcl/source/gdi/impgraph.cxx index 03801668c2d4..32078ac09d6c 100644 --- a/vcl/source/gdi/impgraph.cxx +++ b/vcl/source/gdi/impgraph.cxx @@ -1412,6 +1412,10 @@ void ImpGraphic::updateFromLoadedGraphic(const ImpGraphic* pGraphic) mbSwapOut = false; } + + // The loaded content is measured while it is in memory, so the graphic still knows its size + // after it is swapped out again. + ensureCurrentSizeInBytes(); } void ImpGraphic::dumpState(rtl::OStringBuffer &rState)