[Libreoffice-commits] core.git: vcl/headless vcl/inc vcl/unx

Caolán McNamara (via logerrit) logerrit at kemper.freedesktop.org
Thu Apr 4 10:12:41 UTC 2019


 vcl/headless/svpgdi.cxx      |   40 ++++++++++++++++++++++++++++------------
 vcl/headless/svpvd.cxx       |    8 ++------
 vcl/inc/headless/svpgdi.hxx  |    3 +++
 vcl/unx/gtk3/gtk3gtkinst.cxx |    2 +-
 4 files changed, 34 insertions(+), 19 deletions(-)

New commits:
commit cb7ff6bc57b542a27f6bdcfcaacc2cdf66cdb456
Author:     Caolán McNamara <caolanm at redhat.com>
AuthorDate: Thu Apr 4 09:38:47 2019 +0100
Commit:     Caolán McNamara <caolanm at redhat.com>
CommitDate: Thu Apr 4 12:12:12 2019 +0200

    Resolves: tdf#124219 check at runtime for availability of cairo functions
    
    Change-Id: I0ab3055760d8be690bdfff560212db368a0fa261
    Reviewed-on: https://gerrit.libreoffice.org/70240
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/vcl/headless/svpgdi.cxx b/vcl/headless/svpgdi.cxx
index 3ec663c8706b..2cf49ca17696 100644
--- a/vcl/headless/svpgdi.cxx
+++ b/vcl/headless/svpgdi.cxx
@@ -45,6 +45,7 @@
 #include <basegfx/matrix/b2dhommatrixtools.hxx>
 #include <comphelper/lok.hxx>
 #include <unx/gendata.hxx>
+#include <dlfcn.h>
 
 #if ENABLE_CAIRO_CANVAS
 #   if defined CAIRO_VERSION && CAIRO_VERSION < CAIRO_VERSION_ENCODE(1, 10, 0)
@@ -614,9 +615,7 @@ void SvpSalGraphics::setSurface(cairo_surface_t* pSurface, const basegfx::B2IVec
 {
     m_pSurface = pSurface;
     m_aFrameSize = rSize;
-#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 14, 0)
-    cairo_surface_get_device_scale(pSurface, &m_fScale, nullptr);
-#endif
+    dl_cairo_surface_get_device_scale(pSurface, &m_fScale, nullptr);
     ResetClipRegion();
 }
 
@@ -1599,9 +1598,7 @@ void SvpSalGraphics::copyBits( const SalTwoRect& rTR,
                                             cairo_surface_get_content(m_pSurface),
                                             aTR.mnSrcWidth * m_fScale,
                                             aTR.mnSrcHeight * m_fScale);
-#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 14, 0)
-        cairo_surface_set_device_scale(pCopy, m_fScale, m_fScale);
-#endif
+        dl_cairo_surface_set_device_scale(pCopy, m_fScale, m_fScale);
         cairo_t* cr = cairo_create(pCopy);
         cairo_set_source_surface(cr, source, -aTR.mnSrcX, -aTR.mnSrcY);
         cairo_rectangle(cr, 0, 0, aTR.mnSrcWidth, aTR.mnSrcHeight);
@@ -1848,9 +1845,7 @@ void SvpSalGraphics::invert(const basegfx::B2DPolygon &rPoly, SalInvert nFlags)
                                                                     extents.getWidth() * m_fScale,
                                                                     extents.getHeight() * m_fScale);
 
-#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 14, 0)
-            cairo_surface_set_device_scale(surface, m_fScale, m_fScale);
-#endif
+            dl_cairo_surface_set_device_scale(surface, m_fScale, m_fScale);
             cairo_t* stipple_cr = cairo_create(surface);
             cairo_set_source_rgb(stipple_cr, 1.0, 1.0, 1.0);
             cairo_mask(stipple_cr, pattern);
@@ -2004,9 +1999,7 @@ cairo_t* SvpSalGraphics::createTmpCompatibleCairoContext() const
             m_aFrameSize.getX() * m_fScale,
             m_aFrameSize.getY() * m_fScale);
 
-#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 14, 0)
-    cairo_surface_set_device_scale(target, m_fScale, m_fScale);
-#endif
+    dl_cairo_surface_set_device_scale(target, m_fScale, m_fScale);
 
     return cairo_create(target);
 }
@@ -2202,4 +2195,27 @@ GlyphCache& SvpSalGraphics::getPlatformGlyphCache()
     return *pSalData->GetGlyphCache();
 }
 
+void dl_cairo_surface_set_device_scale(cairo_surface_t *surface, double x_scale, double y_scale)
+{
+    static auto func = reinterpret_cast<void(*)(cairo_surface_t*, double, double)>(
+        dlsym(nullptr, "cairo_surface_set_device_scale"));
+    if (func)
+        func(surface, x_scale, y_scale);
+}
+
+void dl_cairo_surface_get_device_scale(cairo_surface_t *surface, double* x_scale, double* y_scale)
+{
+    static auto func = reinterpret_cast<void(*)(cairo_surface_t*, double*, double*)>(
+        dlsym(nullptr, "cairo_surface_get_device_scale"));
+    if (func)
+        func(surface, x_scale, y_scale);
+    else
+    {
+        if (x_scale)
+            *x_scale = 1.0;
+        if (y_scale)
+            *y_scale = 1.0;
+    }
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/headless/svpvd.cxx b/vcl/headless/svpvd.cxx
index 875f22a5d7fc..eeccf2c014a9 100644
--- a/vcl/headless/svpvd.cxx
+++ b/vcl/headless/svpvd.cxx
@@ -89,7 +89,6 @@ bool SvpSalVirtualDevice::SetSizeUsingBuffer( long nNewDX, long nNewDY,
         }
         else if (pBuffer)
         {
-#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 14, 0)
             double fXScale, fYScale;
             if (comphelper::LibreOfficeKit::isActive())
             {
@@ -98,18 +97,15 @@ bool SvpSalVirtualDevice::SetSizeUsingBuffer( long nNewDX, long nNewDY,
             }
             else
             {
-                cairo_surface_get_device_scale(m_pRefSurface, &fXScale, &fYScale);
+                dl_cairo_surface_get_device_scale(m_pRefSurface, &fXScale, &fYScale);
                 nNewDX *= fXScale;
                 nNewDY *= fYScale;
             }
-#endif
 
             m_pSurface = cairo_image_surface_create_for_data(pBuffer, CAIRO_FORMAT_ARGB32,
                                 nNewDX, nNewDY, cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, nNewDX));
 
-#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 14, 0)
-            cairo_surface_set_device_scale(m_pSurface, fXScale, fYScale);
-#endif
+            dl_cairo_surface_set_device_scale(m_pSurface, fXScale, fYScale);
         }
         else
         {
diff --git a/vcl/inc/headless/svpgdi.hxx b/vcl/inc/headless/svpgdi.hxx
index 1f00f21249e9..51b53f794cc9 100644
--- a/vcl/inc/headless/svpgdi.hxx
+++ b/vcl/inc/headless/svpgdi.hxx
@@ -71,6 +71,9 @@ typedef struct _cairo cairo_t;
 typedef struct _cairo_surface cairo_surface_t;
 typedef struct _cairo_user_data_key cairo_user_data_key_t;
 
+VCL_DLLPUBLIC void dl_cairo_surface_set_device_scale(cairo_surface_t *surface, double x_scale, double y_scale);
+VCL_DLLPUBLIC void dl_cairo_surface_get_device_scale(cairo_surface_t *surface, double *x_scale, double *y_scale);
+
 enum class PaintMode { Over, Xor };
 
 typedef void (*damageHandler)(void* handle,
diff --git a/vcl/unx/gtk3/gtk3gtkinst.cxx b/vcl/unx/gtk3/gtk3gtkinst.cxx
index cdf6829d896c..853b2827bb07 100644
--- a/vcl/unx/gtk3/gtk3gtkinst.cxx
+++ b/vcl/unx/gtk3/gtk3gtkinst.cxx
@@ -2104,7 +2104,7 @@ namespace
         Size aSize(rDevice.GetOutputSizePixel());
         cairo_surface_t* surface = get_underlying_cairo_surface(rDevice);
         double m_fXScale, m_fYScale;
-        cairo_surface_get_device_scale(surface, &m_fXScale, &m_fYScale);
+        dl_cairo_surface_get_device_scale(surface, &m_fXScale, &m_fYScale);
         return gdk_pixbuf_get_from_surface(surface, 0, 0, aSize.Width() * m_fXScale, aSize.Height() * m_fYScale);
     }
 


More information about the Libreoffice-commits mailing list