Blame SOURCES/0001-bubble-the-original-gtk-surface-type-through-renderi.patch

91334d
From 0533dd425a46fb8344c12eead0b7ac21fe7db047 Mon Sep 17 00:00:00 2001
91334d
From: rpmbuild <rpmbuild@fedoraproject.org>
91334d
Date: Fri, 18 Aug 2017 12:12:40 +0100
91334d
Subject: [PATCH] bubble the original gtk surface type through rendering
91334d
91334d
this makes presenting from a hidpi internal monitor to non-hidpi external
91334d
monitor use the correct sizes
91334d
91334d
and this may make scrolling a tad faster in general
91334d
---
91334d
 vcl/headless/svpframe.cxx     |   4 +-
91334d
 vcl/headless/svpgdi.cxx       | 135 ++++++++++++++++++++++++++----------------
91334d
 vcl/headless/svpvd.cxx        |  21 +++----
91334d
 vcl/inc/headless/svpgdi.hxx   |   5 +-
91334d
 vcl/inc/headless/svpvd.hxx    |   1 +
91334d
 vcl/inc/unx/gtk/gtkframe.hxx  |   2 +
91334d
 vcl/unx/gtk3/gtk3gtkframe.cxx |  50 +++++++---------
91334d
 7 files changed, 128 insertions(+), 90 deletions(-)
91334d
91334d
diff --git a/vcl/headless/svpframe.cxx b/vcl/headless/svpframe.cxx
91334d
index 0ce76cf..962cea0 100644
91334d
--- a/vcl/headless/svpframe.cxx
91334d
+++ b/vcl/headless/svpframe.cxx
91334d
@@ -150,7 +150,7 @@ SalGraphics* SvpSalFrame::AcquireGraphics()
91334d
 {
91334d
     SvpSalGraphics* pGraphics = new SvpSalGraphics();
91334d
 #ifndef IOS
91334d
-    pGraphics->setSurface( m_pSurface );
91334d
+    pGraphics->setSurface(m_pSurface, B2IVector(maGeometry.nWidth, maGeometry.nHeight));
91334d
 #endif
91334d
     m_aGraphics.push_back( pGraphics );
91334d
     return pGraphics;
91334d
@@ -281,7 +281,7 @@ void SvpSalFrame::SetPosSize( long nX, long nY, long nWidth, long nHeight, sal_u
91334d
         for( std::list< SvpSalGraphics* >::iterator it = m_aGraphics.begin();
91334d
              it != m_aGraphics.end(); ++it )
91334d
         {
91334d
-             (*it)->setSurface(m_pSurface);
91334d
+             (*it)->setSurface(m_pSurface, aFrameSize);
91334d
         }
91334d
     }
91334d
     if( m_bVisible )
91334d
diff --git a/vcl/headless/svpgdi.cxx b/vcl/headless/svpgdi.cxx
91334d
index bcc1df9..242cc13 100644
91334d
--- a/vcl/headless/svpgdi.cxx
91334d
+++ b/vcl/headless/svpgdi.cxx
91334d
@@ -133,6 +133,22 @@ namespace
91334d
         {
91334d
             return source;
91334d
         }
91334d
+        void mark_dirty()
91334d
+        {
91334d
+            cairo_surface_mark_dirty(source);
91334d
+        }
91334d
+        unsigned char* getBits(sal_Int32 &rStride)
91334d
+        {
91334d
+            cairo_surface_flush(source);
91334d
+
91334d
+            unsigned char *mask_data = cairo_image_surface_get_data(source);
91334d
+
91334d
+            cairo_format_t nFormat = cairo_image_surface_get_format(source);
91334d
+            assert(nFormat == CAIRO_FORMAT_ARGB32 && "need to implement CAIRO_FORMAT_A1 after all here");
91334d
+            rStride = cairo_format_stride_for_width(nFormat, cairo_image_surface_get_width(source));
91334d
+
91334d
+            return mask_data;
91334d
+        }
91334d
     private:
91334d
         SvpSalBitmap aTmpBmp;
91334d
         cairo_surface_t* source;
91334d
@@ -386,9 +402,10 @@ SvpSalGraphics::~SvpSalGraphics()
91334d
 {
91334d
 }
91334d
 
91334d
-void SvpSalGraphics::setSurface(cairo_surface_t* pSurface)
91334d
+void SvpSalGraphics::setSurface(cairo_surface_t* pSurface, const basegfx::B2IVector& rSize)
91334d
 {
91334d
     m_pSurface = pSurface;
91334d
+    m_aFrameSize = rSize;
91334d
 #if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 14, 0)
91334d
     cairo_surface_get_device_scale(pSurface, &m_fScale, nullptr);
91334d
 #endif
91334d
@@ -402,14 +419,14 @@ void SvpSalGraphics::GetResolution( sal_Int32& rDPIX, sal_Int32& rDPIY )
91334d
 
91334d
 sal_uInt16 SvpSalGraphics::GetBitCount() const
91334d
 {
91334d
-    if (CAIRO_FORMAT_A1 == cairo_image_surface_get_format(m_pSurface))
91334d
+    if (cairo_surface_get_content(m_pSurface) != CAIRO_CONTENT_COLOR_ALPHA)
91334d
         return 1;
91334d
     return 32;
91334d
 }
91334d
 
91334d
 long SvpSalGraphics::GetGraphicsWidth() const
91334d
 {
91334d
-    return m_pSurface ? cairo_image_surface_get_width(m_pSurface) / m_fScale : 0;
91334d
+    return m_pSurface ? m_aFrameSize.getX() : 0;
91334d
 }
91334d
 
91334d
 void SvpSalGraphics::ResetClipRegion()
91334d
@@ -885,7 +902,7 @@ bool SvpSalGraphics::drawPolyPolygon(const basegfx::B2DPolyPolygon& rPolyPoly, d
91334d
 
91334d
 void SvpSalGraphics::applyColor(cairo_t *cr, SalColor aColor)
91334d
 {
91334d
-    if (CAIRO_FORMAT_ARGB32 == cairo_image_surface_get_format(m_pSurface))
91334d
+    if (cairo_surface_get_content(m_pSurface) == CAIRO_CONTENT_COLOR_ALPHA)
91334d
     {
91334d
         cairo_set_source_rgba(cr, SALCOLOR_RED(aColor)/255.0,
91334d
                                   SALCOLOR_GREEN(aColor)/255.0,
91334d
@@ -982,17 +999,10 @@ void SvpSalGraphics::copyBits( const SalTwoRect& rTR,
91334d
     if (pSrc == this)
91334d
     {
91334d
         //self copy is a problem, so dup source in that case
91334d
-#if CAIRO_VERSION < CAIRO_VERSION_ENCODE(1, 12, 0)
91334d
         pCopy = cairo_surface_create_similar(source,
91334d
                                             cairo_surface_get_content(m_pSurface),
91334d
                                             aTR.mnSrcWidth * m_fScale,
91334d
                                             aTR.mnSrcHeight * m_fScale);
91334d
-#else
91334d
-        pCopy = cairo_surface_create_similar_image(source,
91334d
-                                            cairo_image_surface_get_format(m_pSurface),
91334d
-                                            aTR.mnSrcWidth * m_fScale,
91334d
-                                            aTR.mnSrcHeight * m_fScale);
91334d
-#endif
91334d
 #if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 14, 0)
91334d
         cairo_surface_set_device_scale(pCopy, m_fScale, m_fScale);
91334d
 #endif
91334d
@@ -1049,16 +1059,8 @@ void SvpSalGraphics::drawMask( const SalTwoRect& rTR,
91334d
     /** creates an image from the given rectangle, replacing all black pixels
91334d
      *  with nMaskColor and make all other full transparent */
91334d
     SourceHelper aSurface(rSalBitmap);
91334d
-    cairo_surface_t* mask = aSurface.getSurface();
91334d
-
91334d
-    cairo_surface_flush(mask);
91334d
-
91334d
-    unsigned char *mask_data = cairo_image_surface_get_data(mask);
91334d
-
91334d
-    cairo_format_t nFormat = cairo_image_surface_get_format(mask);
91334d
-    assert(nFormat == CAIRO_FORMAT_ARGB32 && "need to implement CAIRO_FORMAT_A1 after all here");
91334d
-    sal_Int32 nStride = cairo_format_stride_for_width(nFormat,
91334d
-                                                      cairo_image_surface_get_width(mask));
91334d
+    sal_Int32 nStride;
91334d
+    unsigned char *mask_data = aSurface.getBits(nStride);
91334d
     for (sal_Int32 y = rTR.mnSrcY ; y < rTR.mnSrcY + rTR.mnSrcHeight; ++y)
91334d
     {
91334d
         unsigned char *row = mask_data + (nStride*y);
91334d
@@ -1085,7 +1087,7 @@ void SvpSalGraphics::drawMask( const SalTwoRect& rTR,
91334d
             data+=4;
91334d
         }
91334d
     }
91334d
-    cairo_surface_mark_dirty(mask);
91334d
+    aSurface.mark_dirty();
91334d
 
91334d
     cairo_t* cr = getCairoContext(false);
91334d
     clipRegion(cr);
91334d
@@ -1098,7 +1100,7 @@ void SvpSalGraphics::drawMask( const SalTwoRect& rTR,
91334d
 
91334d
     cairo_translate(cr, rTR.mnDestX, rTR.mnDestY);
91334d
     cairo_scale(cr, (double)(rTR.mnDestWidth)/rTR.mnSrcWidth, ((double)rTR.mnDestHeight)/rTR.mnSrcHeight);
91334d
-    cairo_set_source_surface(cr, mask, -rTR.mnSrcX, -rTR.mnSrcY);
91334d
+    cairo_set_source_surface(cr, aSurface.getSurface(), -rTR.mnSrcX, -rTR.mnSrcY);
91334d
     cairo_paint(cr);
91334d
 
91334d
     releaseCairoContext(cr, false, extents);
91334d
@@ -1123,18 +1125,24 @@ SalBitmap* SvpSalGraphics::getBitmap( long nX, long nY, long nWidth, long nHeigh
91334d
 
91334d
 SalColor SvpSalGraphics::getPixel( long nX, long nY )
91334d
 {
91334d
-    cairo_surface_flush(m_pSurface);
91334d
-    cairo_format_t nFormat = cairo_image_surface_get_format(m_pSurface);
91334d
-    assert(nFormat == CAIRO_FORMAT_ARGB32 && "need to implement CAIRO_FORMAT_A1 after all here");
91334d
-    sal_Int32 nStride = cairo_format_stride_for_width(nFormat,
91334d
-                                                      cairo_image_surface_get_width(m_pSurface));
91334d
-    unsigned char *surface_data = cairo_image_surface_get_data(m_pSurface);
91334d
-    unsigned char *row = surface_data + (nStride*nY);
91334d
-    unsigned char *data = row + (nX * 4);
91334d
+    cairo_surface_t *target = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 1, 1);
91334d
+    cairo_t* cr = cairo_create(target);
91334d
+
91334d
+    cairo_rectangle(cr, 0, 0, 1, 1);
91334d
+    cairo_set_source_surface(cr, m_pSurface, -nX, -nY);
91334d
+    cairo_paint(cr);
91334d
+    cairo_destroy(cr);
91334d
+
91334d
+    cairo_surface_flush(target);
91334d
+    unsigned char *data = cairo_image_surface_get_data(target);
91334d
     sal_uInt8 b = unpremultiply(data[SVP_CAIRO_BLUE], data[SVP_CAIRO_ALPHA]);
91334d
     sal_uInt8 g = unpremultiply(data[SVP_CAIRO_GREEN], data[SVP_CAIRO_ALPHA]);
91334d
     sal_uInt8 r = unpremultiply(data[SVP_CAIRO_RED], data[SVP_CAIRO_ALPHA]);
91334d
-    return MAKE_SALCOLOR(r, g, b);
91334d
+    SalColor nRet = MAKE_SALCOLOR(r, g, b);
91334d
+
91334d
+    cairo_surface_destroy(target);
91334d
+
91334d
+    return nRet;
91334d
 }
91334d
 
91334d
 namespace
91334d
@@ -1268,17 +1276,15 @@ cairo_surface_t* SvpSalGraphics::createCairoSurface(const BitmapBuffer *pBuffer)
91334d
     return target;
91334d
 }
91334d
 
91334d
-static cairo_t* createTmpCompatibleCairoContext(cairo_surface_t* pSurface, double fScale)
91334d
+cairo_t* SvpSalGraphics::createTmpCompatibleCairoContext() const
91334d
 {
91334d
-    cairo_surface_t *target = cairo_image_surface_create(
91334d
-                                cairo_image_surface_get_format(pSurface),
91334d
-                                cairo_image_surface_get_width(pSurface),
91334d
-                                cairo_image_surface_get_height(pSurface));
91334d
+    cairo_surface_t *target = cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
91334d
+                                                         m_aFrameSize.getX() * m_fScale,
91334d
+                                                         m_aFrameSize.getY() * m_fScale);
91334d
 #if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 14, 0)
91334d
-    cairo_surface_set_device_scale(target, fScale, fScale);
91334d
-#else
91334d
-    (void)fScale;
91334d
+    cairo_surface_set_device_scale(target, m_fScale, m_fScale);
91334d
 #endif
91334d
+
91334d
     return cairo_create(target);
91334d
 }
91334d
 
91334d
@@ -1286,7 +1292,7 @@ cairo_t* SvpSalGraphics::getCairoContext(bool bXorModeAllowed) const
91334d
 {
91334d
     cairo_t* cr;
91334d
     if (m_ePaintMode == XOR && bXorModeAllowed)
91334d
-        cr = createTmpCompatibleCairoContext(m_pSurface, m_fScale);
91334d
+        cr = createTmpCompatibleCairoContext();
91334d
     else
91334d
         cr = cairo_create(m_pSurface);
91334d
     cairo_set_line_width(cr, 1);
91334d
@@ -1316,8 +1322,8 @@ void SvpSalGraphics::releaseCairoContext(cairo_t* cr, bool bXorModeAllowed, cons
91334d
 
91334d
     sal_Int32 nExtentsLeft(rExtents.getMinX()), nExtentsTop(rExtents.getMinY());
91334d
     sal_Int32 nExtentsRight(rExtents.getMaxX()), nExtentsBottom(rExtents.getMaxY());
91334d
-    sal_Int32 nWidth = cairo_image_surface_get_width(m_pSurface);
91334d
-    sal_Int32 nHeight = cairo_image_surface_get_height(m_pSurface);
91334d
+    sal_Int32 nWidth = m_aFrameSize.getX();
91334d
+    sal_Int32 nHeight = m_aFrameSize.getY();
91334d
     nExtentsLeft = std::max<sal_Int32>(nExtentsLeft, 0);
91334d
     nExtentsTop = std::max<sal_Int32>(nExtentsTop, 0);
91334d
     nExtentsRight = std::min<sal_Int32>(nExtentsRight, nWidth);
91334d
@@ -1331,21 +1337,35 @@ void SvpSalGraphics::releaseCairoContext(cairo_t* cr, bool bXorModeAllowed, cons
91334d
     //emulate it (slowly) here.
91334d
     if (m_ePaintMode == XOR && bXorModeAllowed)
91334d
     {
91334d
-        cairo_surface_t* true_surface = m_pSurface;
91334d
-        cairo_surface_flush(true_surface);
91334d
-        unsigned char *true_surface_data = cairo_image_surface_get_data(true_surface);
91334d
+        cairo_surface_t* target_surface = m_pSurface;
91334d
+        if (cairo_surface_get_type(target_surface) != CAIRO_SURFACE_TYPE_IMAGE)
91334d
+        {
91334d
+            //in the unlikely case we can't use m_pSurface directly, copy contents
91334d
+            //to another temp image surface
91334d
+            cairo_t* copycr = createTmpCompatibleCairoContext();
91334d
+            cairo_rectangle(copycr, nExtentsLeft, nExtentsTop,
91334d
+                                    nExtentsRight - nExtentsLeft,
91334d
+                                    nExtentsBottom - nExtentsTop);
91334d
+            cairo_set_source_surface(copycr, m_pSurface, 0, 0);
91334d
+            cairo_paint(copycr);
91334d
+            target_surface = cairo_get_target(copycr);
91334d
+            cairo_destroy(copycr);
91334d
+        }
91334d
+
91334d
+        cairo_surface_flush(target_surface);
91334d
+        unsigned char *target_surface_data = cairo_image_surface_get_data(target_surface);
91334d
         unsigned char *xor_surface_data = cairo_image_surface_get_data(surface);
91334d
 
91334d
-        cairo_format_t nFormat = cairo_image_surface_get_format(m_pSurface);
91334d
+        cairo_format_t nFormat = cairo_image_surface_get_format(target_surface);
91334d
         assert(nFormat == CAIRO_FORMAT_ARGB32 && "need to implement CAIRO_FORMAT_A1 after all here");
91334d
-        sal_Int32 nStride = cairo_format_stride_for_width(nFormat, nWidth);
91334d
+        sal_Int32 nStride = cairo_format_stride_for_width(nFormat, nWidth * m_fScale);
91334d
         sal_Int32 nUnscaledExtentsLeft = nExtentsLeft * m_fScale;
91334d
         sal_Int32 nUnscaledExtentsRight = nExtentsRight * m_fScale;
91334d
         sal_Int32 nUnscaledExtentsTop = nExtentsTop * m_fScale;
91334d
         sal_Int32 nUnscaledExtentsBottom = nExtentsBottom * m_fScale;
91334d
         for (sal_Int32 y = nUnscaledExtentsTop; y < nUnscaledExtentsBottom; ++y)
91334d
         {
91334d
-            unsigned char *true_row = true_surface_data + (nStride*y);
91334d
+            unsigned char *true_row = target_surface_data + (nStride*y);
91334d
             unsigned char *xor_row = xor_surface_data + (nStride*y);
91334d
             unsigned char *true_data = true_row + (nUnscaledExtentsLeft * 4);
91334d
             unsigned char *xor_data = xor_row + (nUnscaledExtentsLeft * 4);
91334d
@@ -1364,7 +1384,22 @@ void SvpSalGraphics::releaseCairoContext(cairo_t* cr, bool bXorModeAllowed, cons
91334d
                 xor_data+=4;
91334d
             }
91334d
         }
91334d
-        cairo_surface_mark_dirty(true_surface);
91334d
+        cairo_surface_mark_dirty(target_surface);
91334d
+
91334d
+        if (target_surface != m_pSurface)
91334d
+        {
91334d
+            cairo_t* copycr = cairo_create(m_pSurface);
91334d
+            //unlikely case we couldn't use m_pSurface directly, copy contents
91334d
+            //back from image surface
91334d
+            cairo_rectangle(copycr, nExtentsLeft, nExtentsTop,
91334d
+                                    nExtentsRight - nExtentsLeft,
91334d
+                                    nExtentsBottom - nExtentsTop);
91334d
+            cairo_set_source_surface(copycr, target_surface, 0, 0);
91334d
+            cairo_paint(copycr);
91334d
+            cairo_destroy(copycr);
91334d
+            cairo_surface_destroy(target_surface);
91334d
+        }
91334d
+
91334d
         cairo_surface_destroy(surface);
91334d
     }
91334d
 
91334d
diff --git a/vcl/headless/svpvd.cxx b/vcl/headless/svpvd.cxx
91334d
index ca28a52..b5ab755 100644
91334d
--- a/vcl/headless/svpvd.cxx
91334d
+++ b/vcl/headless/svpvd.cxx
91334d
@@ -38,7 +38,7 @@ SvpSalVirtualDevice::~SvpSalVirtualDevice()
91334d
 SalGraphics* SvpSalVirtualDevice::AcquireGraphics()
91334d
 {
91334d
     SvpSalGraphics* pGraphics = new SvpSalGraphics();
91334d
-    pGraphics->setSurface(m_pSurface);
91334d
+    pGraphics->setSurface(m_pSurface, m_aFrameSize);
91334d
     m_aGraphics.push_back( pGraphics );
91334d
     return pGraphics;
91334d
 }
91334d
@@ -62,12 +62,14 @@ bool SvpSalVirtualDevice::SetSizeUsingBuffer( long nNewDX, long nNewDY,
91334d
     if (nNewDY == 0)
91334d
         nNewDY = 1;
91334d
 
91334d
-    nNewDX *= m_fScale;
91334d
-    nNewDY *= m_fScale;
91334d
-
91334d
-    if (!m_pSurface || cairo_image_surface_get_width(m_pSurface) != nNewDX ||
91334d
-                       cairo_image_surface_get_height(m_pSurface) != nNewDY )
91334d
+    if (!m_pSurface || m_aFrameSize.getX() != nNewDX ||
91334d
+                       m_aFrameSize.getY() != nNewDY )
91334d
     {
91334d
+        m_aFrameSize = basegfx::B2IVector(nNewDX, nNewDY);
91334d
+
91334d
+        nNewDX *= m_fScale;
91334d
+        nNewDY *= m_fScale;
91334d
+
91334d
         if (m_pSurface)
91334d
         {
91334d
             cairo_surface_destroy(m_pSurface);
91334d
@@ -96,20 +98,19 @@ bool SvpSalVirtualDevice::SetSizeUsingBuffer( long nNewDX, long nNewDY,
91334d
         // update device in existing graphics
91334d
         for( std::list< SvpSalGraphics* >::iterator it = m_aGraphics.begin();
91334d
              it != m_aGraphics.end(); ++it )
91334d
-            (*it)->setSurface(m_pSurface);
91334d
-
91334d
+            (*it)->setSurface(m_pSurface, m_aFrameSize);
91334d
     }
91334d
     return true;
91334d
 }
91334d
 
91334d
 long SvpSalVirtualDevice::GetWidth() const
91334d
 {
91334d
-    return m_pSurface ? cairo_image_surface_get_width(m_pSurface) : 0;
91334d
+    return m_pSurface ? m_aFrameSize.getX() : 0;
91334d
 }
91334d
 
91334d
 long SvpSalVirtualDevice::GetHeight() const
91334d
 {
91334d
-    return m_pSurface ? cairo_image_surface_get_height(m_pSurface) : 0;
91334d
+    return m_pSurface ? m_aFrameSize.getY() : 0;
91334d
 }
91334d
 
91334d
 #endif
91334d
diff --git a/vcl/inc/headless/svpgdi.hxx b/vcl/inc/headless/svpgdi.hxx
91334d
index 97fd678..0f46c5f 100644
91334d
--- a/vcl/inc/headless/svpgdi.hxx
91334d
+++ b/vcl/inc/headless/svpgdi.hxx
91334d
@@ -80,6 +80,7 @@ struct VCL_DLLPUBLIC DamageHandler
91334d
 class VCL_DLLPUBLIC SvpSalGraphics : public SalGraphics
91334d
 {
91334d
     cairo_surface_t*               m_pSurface;
91334d
+    basegfx::B2IVector             m_aFrameSize;
91334d
     double                         m_fScale;
91334d
     SalColor                       m_aLineColor;
91334d
     SalColor                       m_aFillColor;
91334d
@@ -87,7 +88,7 @@ class VCL_DLLPUBLIC SvpSalGraphics : public SalGraphics
91334d
 
91334d
 public:
91334d
     static GlyphCache& getPlatformGlyphCache();
91334d
-    void setSurface(cairo_surface_t* pSurface);
91334d
+    void setSurface(cairo_surface_t* pSurface, const basegfx::B2IVector& rSize);
91334d
     static cairo_user_data_key_t* getDamageKey();
91334d
 
91334d
 private:
91334d
@@ -115,6 +116,8 @@ protected:
91334d
         const SalBitmap* pAlphaBitmap) override;
91334d
     virtual bool drawAlphaRect( long nX, long nY, long nWidth, long nHeight, sal_uInt8 nTransparency ) override;
91334d
 
91334d
+    cairo_t* createTmpCompatibleCairoContext() const;
91334d
+
91334d
 public:
91334d
     SvpSalGraphics();
91334d
     virtual ~SvpSalGraphics() override;
91334d
diff --git a/vcl/inc/headless/svpvd.hxx b/vcl/inc/headless/svpvd.hxx
91334d
index 882f36d..7ac1563 100644
91334d
--- a/vcl/inc/headless/svpvd.hxx
91334d
+++ b/vcl/inc/headless/svpvd.hxx
91334d
@@ -31,6 +31,7 @@ class VCL_DLLPUBLIC SvpSalVirtualDevice : public SalVirtualDevice
91334d
 {
91334d
     DeviceFormat                        m_eFormat;
91334d
     cairo_surface_t*                    m_pSurface;
91334d
+    basegfx::B2IVector                  m_aFrameSize;
91334d
     double                              m_fScale;
91334d
     std::list< SvpSalGraphics* >        m_aGraphics;
91334d
 
91334d
diff --git a/vcl/inc/unx/gtk/gtkframe.hxx b/vcl/inc/unx/gtk/gtkframe.hxx
91334d
index f263160..8f60671 100644
91334d
--- a/vcl/inc/unx/gtk/gtkframe.hxx
91334d
+++ b/vcl/inc/unx/gtk/gtkframe.hxx
91334d
@@ -246,6 +246,7 @@ class GtkSalFrame : public SalFrame
91334d
 #endif
91334d
 #if GTK_CHECK_VERSION(3,0,0)
91334d
     static gboolean     signalDraw( GtkWidget*, cairo_t *cr, gpointer );
91334d
+    static void         signalRealize(GtkWidget*, gpointer frame);
91334d
     static void         sizeAllocated(GtkWidget*, GdkRectangle *pAllocation, gpointer frame);
91334d
     static gboolean     signalTooltipQuery(GtkWidget*, gint x, gint y,
91334d
                                      gboolean keyboard_mode, GtkTooltip *tooltip,
91334d
@@ -346,6 +347,7 @@ class GtkSalFrame : public SalFrame
91334d
 public:
91334d
 #if GTK_CHECK_VERSION(3,0,0)
91334d
     cairo_surface_t*                m_pSurface;
91334d
+    basegfx::B2IVector              m_aFrameSize;
91334d
     DamageHandler                   m_aDamageHandler;
91334d
     std::vector<GdkEvent*>          m_aPendingScrollEvents;
91334d
     Idle                            m_aSmoothScrollIdle;
91334d
diff --git a/vcl/unx/gtk3/gtk3gtkframe.cxx b/vcl/unx/gtk3/gtk3gtkframe.cxx
91334d
index 9be38dd..dc9d83b 100644
91334d
--- a/vcl/unx/gtk3/gtk3gtkframe.cxx
91334d
+++ b/vcl/unx/gtk3/gtk3gtkframe.cxx
91334d
@@ -1045,6 +1045,7 @@ void GtkSalFrame::InitCommon()
91334d
     m_aMouseSignalIds.push_back(g_signal_connect( G_OBJECT(pEventWidget), "scroll-event", G_CALLBACK(signalScroll), this ));
91334d
 
91334d
     g_signal_connect( G_OBJECT(m_pFixedContainer), "draw", G_CALLBACK(signalDraw), this );
91334d
+    g_signal_connect( G_OBJECT(m_pFixedContainer), "realize", G_CALLBACK(signalRealize), this );
91334d
     g_signal_connect( G_OBJECT(m_pFixedContainer), "size-allocate", G_CALLBACK(sizeAllocated), this );
91334d
 #if GTK_CHECK_VERSION(3,14,0)
91334d
     GtkGesture *pSwipe = gtk_gesture_swipe_new(pEventWidget);
91334d
@@ -1340,7 +1341,7 @@ SalGraphics* GtkSalFrame::AcquireGraphics()
91334d
             AllocateFrame();
91334d
             TriggerPaintEvent();
91334d
         }
91334d
-        m_pGraphics->setSurface(m_pSurface);
91334d
+        m_pGraphics->setSurface(m_pSurface, m_aFrameSize);
91334d
     }
91334d
     m_bGraphics = true;
91334d
     return m_pGraphics;
91334d
@@ -1587,13 +1588,11 @@ void GtkSalFrame::SetMinClientSize( long nWidth, long nHeight )
91334d
     }
91334d
 }
91334d
 
91334d
-// FIXME: we should really be an SvpSalFrame sub-class, and
91334d
-// share their AllocateFrame !
91334d
 void GtkSalFrame::AllocateFrame()
91334d
 {
91334d
     basegfx::B2IVector aFrameSize( maGeometry.nWidth, maGeometry.nHeight );
91334d
-    if (!m_pSurface || cairo_image_surface_get_width(m_pSurface) != aFrameSize.getX() ||
91334d
-                       cairo_image_surface_get_height(m_pSurface) != aFrameSize.getY() )
91334d
+    if (!m_pSurface || m_aFrameSize.getX() != aFrameSize.getX() ||
91334d
+                       m_aFrameSize.getY() != aFrameSize.getY() )
91334d
     {
91334d
         if( aFrameSize.getX() == 0 )
91334d
             aFrameSize.setX( 1 );
91334d
@@ -1603,30 +1602,17 @@ void GtkSalFrame::AllocateFrame()
91334d
         if (m_pSurface)
91334d
             cairo_surface_destroy(m_pSurface);
91334d
 
91334d
-#if GTK_CHECK_VERSION(3,10,0)
91334d
-#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 14, 0)
91334d
-        int scale = gtk_widget_get_scale_factor(m_pWindow);
91334d
-#else
91334d
-        int scale = 1;
91334d
-#endif
91334d
-        m_pSurface = gdk_window_create_similar_image_surface(widget_get_window(m_pWindow),
91334d
-                                                             CAIRO_FORMAT_ARGB32,
91334d
-                                                             aFrameSize.getX() * scale,
91334d
-                                                             aFrameSize.getY() * scale,
91334d
-                                                             scale);
91334d
-#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 14, 0)
91334d
-        cairo_surface_set_device_scale(m_pSurface, scale, scale);
91334d
-#endif
91334d
-#else
91334d
-        m_pSurface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
91334d
-                                                aFrameSize.getX(),
91334d
-                                                aFrameSize.getY());
91334d
-#endif
91334d
+        m_pSurface = gdk_window_create_similar_surface(widget_get_window(m_pWindow),
91334d
+                                                       CAIRO_CONTENT_COLOR_ALPHA,
91334d
+                                                       aFrameSize.getX(),
91334d
+                                                       aFrameSize.getY());
91334d
+        m_aFrameSize = aFrameSize;
91334d
+
91334d
         cairo_surface_set_user_data(m_pSurface, SvpSalGraphics::getDamageKey(), &m_aDamageHandler, nullptr);
91334d
         SAL_INFO("vcl.gtk3", "allocated Frame size of " << maGeometry.nWidth << " x " << maGeometry.nHeight);
91334d
 
91334d
         if (m_pGraphics)
91334d
-            m_pGraphics->setSurface(m_pSurface);
91334d
+            m_pGraphics->setSurface(m_pSurface, m_aFrameSize);
91334d
     }
91334d
 }
91334d
 
91334d
@@ -2967,13 +2953,23 @@ gboolean GtkSalFrame::signalDraw(GtkWidget*, cairo_t *cr, gpointer frame)
91334d
     return false;
91334d
 }
91334d
 
91334d
-void GtkSalFrame::sizeAllocated(GtkWidget*, GdkRectangle *pAllocation, gpointer frame)
91334d
+void GtkSalFrame::sizeAllocated(GtkWidget* pWidget, GdkRectangle *pAllocation, gpointer frame)
91334d
 {
91334d
     GtkSalFrame* pThis = static_cast<GtkSalFrame*>(frame);
91334d
     pThis->maGeometry.nWidth = pAllocation->width;
91334d
     pThis->maGeometry.nHeight = pAllocation->height;
91334d
-    pThis->AllocateFrame();
91334d
+    bool bRealized = gtk_widget_get_realized(pWidget);
91334d
+    if (bRealized)
91334d
+        pThis->AllocateFrame();
91334d
     pThis->CallCallbackExc( SalEvent::Resize, nullptr );
91334d
+    if (bRealized && !pThis->m_bSalObjectSetPosSize)
91334d
+        pThis->TriggerPaintEvent();
91334d
+}
91334d
+
91334d
+void GtkSalFrame::signalRealize(GtkWidget*, gpointer frame)
91334d
+{
91334d
+    GtkSalFrame* pThis = static_cast<GtkSalFrame*>(frame);
91334d
+    pThis->AllocateFrame();
91334d
     if (pThis->m_bSalObjectSetPosSize)
91334d
         return;
91334d
     pThis->TriggerPaintEvent();
91334d
-- 
91334d
2.13.0
91334d