vcl/qt5/QtWidget.cxx |   47 ++++++++++++++++++++++-------------------------
 1 file changed, 22 insertions(+), 25 deletions(-)

New commits:
commit cd2ea94969b9c63b24e35e9b8e546cea0f62340e
Author:     Jan-Marek Glogowski <glo...@fbihome.de>
AuthorDate: Tue May 31 21:03:39 2022 +0200
Commit:     Jan-Marek Glogowski <glo...@fbihome.de>
CommitDate: Wed Jun 1 00:16:32 2022 +0200

    Qt just resize the backing store on size change
    
    ... and if there is no need to create a Cairo surface if it
    doesn't exists, there is no need for a fresh QImage either.
    
    Change-Id: If607e03d246f3c31d66953b1e07a7af55659e64b
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135209
    Tested-by: Jenkins
    Reviewed-by: Jan-Marek Glogowski <glo...@fbihome.de>

diff --git a/vcl/qt5/QtWidget.cxx b/vcl/qt5/QtWidget.cxx
index 74adcc4e974c..b2451123e7e6 100644
--- a/vcl/qt5/QtWidget.cxx
+++ b/vcl/qt5/QtWidget.cxx
@@ -98,38 +98,35 @@ void QtWidget::resizeEvent(QResizeEvent* pEvent)
 
     if (m_rFrame.m_bUseCairo)
     {
-        if (m_rFrame.m_pSvpGraphics)
+        if (m_rFrame.m_pSurface)
         {
-            cairo_surface_t* pSurface
-                = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, nWidth, 
nHeight);
-            cairo_surface_set_user_data(pSurface, 
SvpSalGraphics::getDamageKey(),
-                                        &m_rFrame.m_aDamageHandler, nullptr);
-            m_rFrame.m_pSvpGraphics->setSurface(pSurface, 
basegfx::B2IVector(nWidth, nHeight));
-            UniqueCairoSurface old_surface(m_rFrame.m_pSurface.release());
-            m_rFrame.m_pSurface.reset(pSurface);
-
-            int min_width = 
qMin(cairo_image_surface_get_width(old_surface.get()), nWidth);
-            int min_height = 
qMin(cairo_image_surface_get_height(old_surface.get()), nHeight);
-
-            SalTwoRect rect(0, 0, min_width, min_height, 0, 0, min_width, 
min_height);
-
-            m_rFrame.m_pSvpGraphics->copySource(rect, old_surface.get());
+            const int nOldWidth = 
cairo_image_surface_get_width(m_rFrame.m_pSurface.get());
+            const int nOldHeight = 
cairo_image_surface_get_height(m_rFrame.m_pSurface.get());
+            if (nOldWidth != nWidth || nOldHeight != nHeight)
+            {
+                cairo_surface_t* pSurface
+                    = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, nWidth, 
nHeight);
+                cairo_surface_set_user_data(pSurface, 
SvpSalGraphics::getDamageKey(),
+                                            &m_rFrame.m_aDamageHandler, 
nullptr);
+                m_rFrame.m_pSvpGraphics->setSurface(pSurface, 
basegfx::B2IVector(nWidth, nHeight));
+                UniqueCairoSurface old_surface(m_rFrame.m_pSurface.release());
+                m_rFrame.m_pSurface.reset(pSurface);
+
+                const int nMinWidth = qMin(nOldWidth, nWidth);
+                const int nMinHeight = qMin(nOldHeight, nHeight);
+                SalTwoRect rect(0, 0, nMinWidth, nMinHeight, 0, 0, nMinWidth, 
nMinHeight);
+                m_rFrame.m_pSvpGraphics->copySource(rect, old_surface.get());
+            }
         }
     }
     else
     {
-        QImage* pImage = nullptr;
-
-        if (m_rFrame.m_pQImage)
-            pImage = new QImage(m_rFrame.m_pQImage->copy(0, 0, nWidth, 
nHeight));
-        else
+        if (m_rFrame.m_pQImage && m_rFrame.m_pQImage->size() != QSize(nWidth, 
nHeight))
         {
-            pImage = new QImage(nWidth, nHeight, Qt_DefaultFormat32);
-            pImage->fill(Qt::transparent);
+            QImage* pImage = new QImage(m_rFrame.m_pQImage->copy(0, 0, nWidth, 
nHeight));
+            m_rFrame.m_pQtGraphics->ChangeQImage(pImage);
+            m_rFrame.m_pQImage.reset(pImage);
         }
-
-        m_rFrame.m_pQtGraphics->ChangeQImage(pImage);
-        m_rFrame.m_pQImage.reset(pImage);
     }
 
     m_rFrame.CallCallback(SalEvent::Resize, nullptr);

Reply via email to