From 11925224a53a46837d3a32b126ff2be55c96fb13 Mon Sep 17 00:00:00 2001 From: Luboš Luňák Date: Thu, 27 May 2021 20:22:51 +0200 Subject: avoid possible repeated cairo surface creation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- vcl/headless/svpframe.cxx | 26 +++++++++++++++----------- vcl/inc/headless/svpframe.hxx | 2 ++ 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 -- cgit v1.2.3