summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuboš Luňák <l.lunak@collabora.com>2021-05-27 20:22:51 +0200
committerLuboš Luňák <l.lunak@collabora.com>2021-06-10 11:22:22 +0200
commit11925224a53a46837d3a32b126ff2be55c96fb13 (patch)
tree84c5773a915e26632a7be19582bfb947bbef5b21
parenta292fb847dade1912d281adc44c92a9ba3e8b61d (diff)
avoid possible repeated cairo surface creation
Doing the frame size adjustments only after the if condition meant that in headless mode the surface could be destroyed and created again for the same size. Also AcquireGraphics() passed different frame size to SetGraphics() than SetPosSize(). Change-Id: I9d6884a3917dfbd7b2cfe4fcd4e350c8bc9f4305 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/116272 Tested-by: Jenkins Reviewed-by: Luboš Luňák <l.lunak@collabora.com>
-rw-r--r--vcl/headless/svpframe.cxx26
-rw-r--r--vcl/inc/headless/svpframe.hxx2
2 files changed, 17 insertions, 11 deletions
diff --git a/vcl/headless/svpframe.cxx b/vcl/headless/svpframe.cxx
index 3f79ead63783..fb7a81d08b7a 100644
--- a/vcl/headless/svpframe.cxx
+++ b/vcl/headless/svpframe.cxx
@@ -141,11 +141,24 @@ void SvpSalFrame::LoseFocus()
}
}
+basegfx::B2IVector SvpSalFrame::GetSurfaceFrameSize() const
+{
+ basegfx::B2IVector aFrameSize( maGeometry.nWidth, maGeometry.nHeight );
+ if( aFrameSize.getX() == 0 )
+ aFrameSize.setX( 1 );
+ if( aFrameSize.getY() == 0 )
+ aFrameSize.setY( 1 );
+ // Creating backing surfaces for invisible windows costs a big chunk of RAM.
+ if (Application::IsHeadlessModeEnabled())
+ aFrameSize = basegfx::B2IVector( 1, 1 );
+ return aFrameSize;
+}
+
SalGraphics* SvpSalFrame::AcquireGraphics()
{
SvpSalGraphics* pGraphics = new SvpSalGraphics();
#ifndef IOS
- pGraphics->setSurface(m_pSurface, basegfx::B2IVector(maGeometry.nWidth, maGeometry.nHeight));
+ pGraphics->setSurface(m_pSurface, GetSurfaceFrameSize());
#endif
m_aGraphics.push_back( pGraphics );
return pGraphics;
@@ -252,22 +265,13 @@ void SvpSalFrame::SetPosSize( tools::Long nX, tools::Long nY, tools::Long nWidth
maGeometry.nHeight = m_nMinHeight;
}
#ifndef IOS
- basegfx::B2IVector aFrameSize( maGeometry.nWidth, maGeometry.nHeight );
+ basegfx::B2IVector aFrameSize = GetSurfaceFrameSize();
if (!m_pSurface || cairo_image_surface_get_width(m_pSurface) != aFrameSize.getX() ||
cairo_image_surface_get_height(m_pSurface) != aFrameSize.getY() )
{
- if( aFrameSize.getX() == 0 )
- aFrameSize.setX( 1 );
- if( aFrameSize.getY() == 0 )
- aFrameSize.setY( 1 );
-
if (m_pSurface)
cairo_surface_destroy(m_pSurface);
- // Creating backing surfaces for invisible windows costs a big chunk of RAM.
- if (Application::IsHeadlessModeEnabled())
- aFrameSize = basegfx::B2IVector( 1, 1 );
-
m_pSurface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
aFrameSize.getX(),
aFrameSize.getY());
diff --git a/vcl/inc/headless/svpframe.hxx b/vcl/inc/headless/svpframe.hxx
index 6d003d545398..1d8622d586b9 100644
--- a/vcl/inc/headless/svpframe.hxx
+++ b/vcl/inc/headless/svpframe.hxx
@@ -116,6 +116,8 @@ public:
virtual void SetScreenNumber( unsigned int ) override {}
virtual void SetApplicationID(const OUString &) override {}
+private:
+ basegfx::B2IVector GetSurfaceFrameSize() const;
};
#endif // INCLUDED_VCL_INC_HEADLESS_SVPFRAME_HXX