vcl/Library_vclplug_qt5.mk       |    2 +
 vcl/inc/qt5/Qt5Frame.hxx         |   23 ++++++------
 vcl/inc/qt5/Qt5SvpGraphics.hxx   |   46 ++++++++++++++++++++++++
 vcl/inc/qt5/Qt5SvpSurface.hxx    |   46 ++++++++++++++++++++++++
 vcl/qt5/Qt5Frame.cxx             |   32 +++++++++++------
 vcl/qt5/Qt5SvpGraphics.cxx       |   52 +++++++++++++++++++++++++++
 vcl/qt5/Qt5SvpSurface.cxx        |   73 +++++++++++++++++++++++++++++++++++++++
 vcl/qt5/Qt5Widget.cxx            |    2 -
 vcl/unx/kde5/KDE5SalFrame.cxx    |    4 --
 vcl/unx/kde5/KDE5SalGraphics.cxx |    2 -
 vcl/unx/kde5/KDE5SalGraphics.hxx |    3 +
 11 files changed, 259 insertions(+), 26 deletions(-)

New commits:
commit 7c54b11e98a7b8705eb2fc0ad41a6ec25f8e62e7
Author:     Jan-Marek Glogowski <glo...@fbihome.de>
AuthorDate: Fri May 24 15:36:39 2019 +0000
Commit:     Katarina Behrens <katarina.behr...@cib.de>
CommitDate: Thu Jun 13 13:52:27 2019 +0200

    Qt5 implement SalSurface support for cairo
    
    Current qt5+cairo uses the plain VCL canvas. This patch is just a
    copy of Gtk3Surface (minus comments) with a different update call.
    This way the Cairo path now uses the Cairo canvas instead.
    
    It fixes at least tdf#122668 for me, but other Impress bugs might
    be fixed this way too.
    
    Reviewed-on: https://gerrit.libreoffice.org/72921
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>
    Tested-by: Jenkins
    Reviewed-by: Aleksei Nikiforov <darktemp...@basealt.ru>
    (cherry picked from commit 86cab846c1a122dd4dd5f5c4ca5750a0fc397c6b)
    
    [This also squashes the backport of commit 
cc237438f6d1c7ee3a391b51402aaa71cd347b6b
    ("qt5: Make it compile with '-Werror=shadow'") in to the same commit.]
    
    Change-Id: Iba511c851001753328293c28e53eaa4acc4315d0
    Reviewed-on: https://gerrit.libreoffice.org/73198
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>
    Tested-by: Jenkins
    Reviewed-by: Katarina Behrens <katarina.behr...@cib.de>

diff --git a/vcl/Library_vclplug_qt5.mk b/vcl/Library_vclplug_qt5.mk
index d51175756009..6e23c0d496da 100644
--- a/vcl/Library_vclplug_qt5.mk
+++ b/vcl/Library_vclplug_qt5.mk
@@ -102,6 +102,8 @@ $(eval $(call gb_Library_add_exception_objects,vclplug_qt5,\
     vcl/qt5/Qt5OpenGLContext \
     vcl/qt5/Qt5Painter \
     vcl/qt5/Qt5Printer \
+    vcl/qt5/Qt5SvpGraphics \
+    vcl/qt5/Qt5SvpSurface \
     vcl/qt5/Qt5System \
     vcl/qt5/Qt5Timer \
     vcl/qt5/Qt5Tools \
diff --git a/vcl/inc/qt5/Qt5Frame.hxx b/vcl/inc/qt5/Qt5Frame.hxx
index 07a53972ee9b..26d44cb80c8e 100644
--- a/vcl/inc/qt5/Qt5Frame.hxx
+++ b/vcl/inc/qt5/Qt5Frame.hxx
@@ -30,18 +30,19 @@
 
 #include <QtCore/QObject>
 
+class Qt5DragSource;
+class Qt5DropTarget;
 class Qt5Graphics;
 class Qt5Instance;
-class Qt5Menu;
-class QWidget;
 class Qt5MainWindow;
-class Qt5DragSource;
-class Qt5DropTarget;
+class Qt5Menu;
+class Qt5SvpGraphics;
+
+class QImage;
 class QMimeData;
 class QPaintDevice;
 class QScreen;
-class QImage;
-class SvpSalGraphics;
+class QWidget;
 
 class VCLPLUG_QT5_PUBLIC Qt5Frame : public QObject, public SalFrame
 {
@@ -56,11 +57,11 @@ class VCLPLUG_QT5_PUBLIC Qt5Frame : public QObject, public 
SalFrame
     std::unique_ptr<QImage> m_pQImage;
     std::unique_ptr<Qt5Graphics> m_pQt5Graphics;
     UniqueCairoSurface m_pSurface;
-    std::unique_ptr<SvpSalGraphics> m_pOurSvpGraphics;
+    std::unique_ptr<Qt5SvpGraphics> m_pOurSvpGraphics;
     // in base class, this ptr is the same as m_pOurSvpGraphic
     // in derived class, it can point to a derivative
-    // of SvpSalGraphics (which the derived class then owns)
-    SvpSalGraphics* m_pSvpGraphics;
+    // of Qt5SvpGraphics (which the derived class then owns)
+    Qt5SvpGraphics* m_pSvpGraphics;
     DamageHandler m_aDamageHandler;
     QRegion m_aRegion;
     bool m_bNullRegion;
@@ -125,7 +126,7 @@ public:
     void Damage(sal_Int32 nExtentsX, sal_Int32 nExtentsY, sal_Int32 
nExtentsWidth,
                 sal_Int32 nExtentsHeight) const;
 
-    virtual void InitSvpSalGraphics(SvpSalGraphics* pSvpSalGraphics);
+    void InitQt5SvpGraphics(Qt5SvpGraphics* pQt5SvpGraphics);
     virtual SalGraphics* AcquireGraphics() override;
     virtual void ReleaseGraphics(SalGraphics* pGraphics) override;
 
@@ -190,6 +191,8 @@ public:
     virtual void SetApplicationID(const OUString&) override;
 
     inline bool CallCallback(SalEvent nEvent, const void* pEvent) const;
+
+    cairo_t* getCairoContext() const;
 };
 
 inline bool Qt5Frame::CallCallback(SalEvent nEvent, const void* pEvent) const
diff --git a/vcl/inc/qt5/Qt5SvpGraphics.hxx b/vcl/inc/qt5/Qt5SvpGraphics.hxx
new file mode 100644
index 000000000000..e6a931b77f55
--- /dev/null
+++ b/vcl/inc/qt5/Qt5SvpGraphics.hxx
@@ -0,0 +1,46 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ *   Licensed to the Apache Software Foundation (ASF) under one or more
+ *   contributor license agreements. See the NOTICE file distributed
+ *   with this work for additional information regarding copyright
+ *   ownership. The ASF licenses this file to you under the Apache
+ *   License, Version 2.0 (the "License"); you may not use this file
+ *   except in compliance with the License. You may obtain a copy of
+ *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#pragma once
+
+#include <vclpluginapi.h>
+#include <headless/svpgdi.hxx>
+
+class QWidget;
+
+class VCLPLUG_QT5_PUBLIC Qt5SvpGraphics : public SvpSalGraphics
+{
+    QWidget* m_pQWidget;
+
+public:
+    Qt5SvpGraphics(QWidget* pQWidget);
+    ~Qt5SvpGraphics() override;
+
+    void updateQWidget() const;
+
+#if ENABLE_CAIRO_CANVAS
+    bool SupportsCairo() const override;
+    cairo::SurfaceSharedPtr
+    CreateSurface(const cairo::CairoSurfaceSharedPtr& rSurface) const override;
+    cairo::SurfaceSharedPtr CreateSurface(const OutputDevice& rRefDevice, int 
x, int y, int width,
+                                          int height) const override;
+#endif // ENABLE_CAIRO_CANVAS
+};
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/inc/qt5/Qt5SvpSurface.hxx b/vcl/inc/qt5/Qt5SvpSurface.hxx
new file mode 100644
index 000000000000..196e2bbfa22c
--- /dev/null
+++ b/vcl/inc/qt5/Qt5SvpSurface.hxx
@@ -0,0 +1,46 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#pragma once
+
+#include <sal/config.h>
+
+#include <sal/types.h>
+
+#include <vcl/cairo.hxx>
+
+class Qt5SvpGraphics;
+class OutputDevice;
+
+namespace cairo
+{
+class Qt5SvpSurface : public Surface
+{
+    const Qt5SvpGraphics* m_pGraphics;
+    cairo_t* const m_pCairoContext;
+    CairoSurfaceSharedPtr m_pSurface;
+
+public:
+    /// takes over ownership of passed cairo_surface
+    explicit Qt5SvpSurface(const CairoSurfaceSharedPtr& pSurface);
+    /// create surface on subarea of given drawable
+    explicit Qt5SvpSurface(const Qt5SvpGraphics* pGraphics, int x, int y, int 
width, int height);
+    ~Qt5SvpSurface() override;
+
+    // Surface interface
+    CairoSharedPtr getCairo() const override;
+    CairoSurfaceSharedPtr getCairoSurface() const override { return 
m_pSurface; }
+    SurfaceSharedPtr getSimilar(int nContentType, int width, int height) const 
override;
+
+    VclPtr<VirtualDevice> createVirtualDevice() const override;
+    void flush() const override;
+};
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/qt5/Qt5Frame.cxx b/vcl/qt5/Qt5Frame.cxx
index 27d0828539f5..a47d39211ee5 100644
--- a/vcl/qt5/Qt5Frame.cxx
+++ b/vcl/qt5/Qt5Frame.cxx
@@ -20,14 +20,15 @@
 #include <Qt5Frame.hxx>
 #include <Qt5Frame.moc>
 
-#include <Qt5Tools.hxx>
-#include <Qt5Instance.hxx>
+#include <Qt5Data.hxx>
+#include <Qt5DragAndDrop.hxx>
 #include <Qt5Graphics.hxx>
-#include <Qt5Widget.hxx>
+#include <Qt5Instance.hxx>
 #include <Qt5MainWindow.hxx>
-#include <Qt5Data.hxx>
 #include <Qt5Menu.hxx>
-#include <Qt5DragAndDrop.hxx>
+#include <Qt5SvpGraphics.hxx>
+#include <Qt5Tools.hxx>
+#include <Qt5Widget.hxx>
 
 #include <QtCore/QMimeData>
 #include <QtCore/QPoint>
@@ -241,14 +242,14 @@ void Qt5Frame::TriggerPaintEvent(QRect aRect)
     CallCallback(SalEvent::Paint, &aPaintEvt);
 }
 
-void Qt5Frame::InitSvpSalGraphics(SvpSalGraphics* pSvpSalGraphics)
+void Qt5Frame::InitQt5SvpGraphics(Qt5SvpGraphics* pQt5SvpGraphics)
 {
     int width = 640;
     int height = 480;
-    m_pSvpGraphics = pSvpSalGraphics;
+    m_pSvpGraphics = pQt5SvpGraphics;
     m_pSurface.reset(cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, 
height));
     m_pSvpGraphics->setSurface(m_pSurface.get(), basegfx::B2IVector(width, 
height));
-    cairo_surface_set_user_data(m_pSurface.get(), 
SvpSalGraphics::getDamageKey(), &m_aDamageHandler,
+    cairo_surface_set_user_data(m_pSurface.get(), 
Qt5SvpGraphics::getDamageKey(), &m_aDamageHandler,
                                 nullptr);
 }
 
@@ -263,8 +264,8 @@ SalGraphics* Qt5Frame::AcquireGraphics()
     {
         if (!m_pOurSvpGraphics.get())
         {
-            m_pOurSvpGraphics.reset(new SvpSalGraphics());
-            InitSvpSalGraphics(m_pOurSvpGraphics.get());
+            m_pOurSvpGraphics.reset(new Qt5SvpGraphics(m_pQWidget));
+            InitQt5SvpGraphics(m_pOurSvpGraphics.get());
         }
         return m_pOurSvpGraphics.get();
     }
@@ -1257,4 +1258,15 @@ void Qt5Frame::dropping(const int x, const int y, const 
QMimeData* pQMimeData)
     }
 }
 
+cairo_t* Qt5Frame::getCairoContext() const
+{
+    cairo_t* cr = nullptr;
+    if (m_bUseCairo)
+    {
+        cr = cairo_create(m_pSurface.get());
+        assert(cr);
+    }
+    return cr;
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/qt5/Qt5SvpGraphics.cxx b/vcl/qt5/Qt5SvpGraphics.cxx
new file mode 100644
index 000000000000..f746381e6561
--- /dev/null
+++ b/vcl/qt5/Qt5SvpGraphics.cxx
@@ -0,0 +1,52 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <sal/config.h>
+#include <sal/log.hxx>
+
+#include <config_cairo_canvas.h>
+
+#include <Qt5SvpGraphics.hxx>
+#include <Qt5SvpSurface.hxx>
+
+#include <QtWidgets/QWidget>
+
+Qt5SvpGraphics::Qt5SvpGraphics(QWidget* pQWidget)
+    : SvpSalGraphics()
+    , m_pQWidget(pQWidget)
+{
+}
+
+Qt5SvpGraphics::~Qt5SvpGraphics() {}
+
+void Qt5SvpGraphics::updateQWidget() const
+{
+    if (m_pQWidget)
+        m_pQWidget->update(m_pQWidget->rect());
+}
+
+#if ENABLE_CAIRO_CANVAS
+
+bool Qt5SvpGraphics::SupportsCairo() const { return true; }
+
+cairo::SurfaceSharedPtr
+Qt5SvpGraphics::CreateSurface(const cairo::CairoSurfaceSharedPtr& rSurface) 
const
+{
+    return cairo::SurfaceSharedPtr(new cairo::Qt5SvpSurface(rSurface));
+}
+
+cairo::SurfaceSharedPtr Qt5SvpGraphics::CreateSurface(const OutputDevice& 
/*rRefDevice*/, int x,
+                                                      int y, int width, int 
height) const
+{
+    return cairo::SurfaceSharedPtr(new cairo::Qt5SvpSurface(this, x, y, width, 
height));
+}
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/qt5/Qt5SvpSurface.cxx b/vcl/qt5/Qt5SvpSurface.cxx
new file mode 100644
index 000000000000..00f6004bd2a0
--- /dev/null
+++ b/vcl/qt5/Qt5SvpSurface.cxx
@@ -0,0 +1,73 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <utility>
+
+#include <Qt5SvpSurface.hxx>
+
+#include <Qt5SvpGraphics.hxx>
+
+#include <vcl/sysdata.hxx>
+#include <vcl/bitmap.hxx>
+#include <vcl/virdev.hxx>
+#include <vcl/window.hxx>
+#include <basegfx/vector/b2isize.hxx>
+
+namespace cairo
+{
+Qt5SvpSurface::Qt5SvpSurface(const CairoSurfaceSharedPtr& pSurface)
+    : m_pGraphics(nullptr)
+    , m_pCairoContext(nullptr)
+    , m_pSurface(pSurface)
+{
+}
+
+Qt5SvpSurface::Qt5SvpSurface(const Qt5SvpGraphics* pGraphics, int x, int y, 
int width, int height)
+    : m_pGraphics(pGraphics)
+    , m_pCairoContext(pGraphics->getCairoContext(false))
+{
+    cairo_surface_t* surface = cairo_get_target(m_pCairoContext);
+    m_pSurface.reset(cairo_surface_create_for_rectangle(surface, x, y, width, 
height),
+                     &cairo_surface_destroy);
+}
+
+Qt5SvpSurface::~Qt5SvpSurface()
+{
+    if (m_pCairoContext)
+        cairo_destroy(m_pCairoContext);
+}
+
+CairoSharedPtr Qt5SvpSurface::getCairo() const
+{
+    return CairoSharedPtr(cairo_create(m_pSurface.get()), &cairo_destroy);
+}
+
+SurfaceSharedPtr Qt5SvpSurface::getSimilar(int cairo_content_type, int width, 
int height) const
+{
+    return SurfaceSharedPtr(new Qt5SvpSurface(CairoSurfaceSharedPtr(
+        cairo_surface_create_similar(
+            m_pSurface.get(), 
static_cast<cairo_content_t>(cairo_content_type), width, height),
+        &cairo_surface_destroy)));
+}
+
+void Qt5SvpSurface::flush() const
+{
+    cairo_surface_flush(m_pSurface.get());
+    if (m_pGraphics)
+        m_pGraphics->updateQWidget();
+}
+
+VclPtr<VirtualDevice> Qt5SvpSurface::createVirtualDevice() const
+{
+    return VclPtrInstance<VirtualDevice>(nullptr, Size(1, 1), 
DeviceFormat::DEFAULT);
+}
+
+} // namespace cairo
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/qt5/Qt5Widget.cxx b/vcl/qt5/Qt5Widget.cxx
index 2137109beac7..44b62c48150d 100644
--- a/vcl/qt5/Qt5Widget.cxx
+++ b/vcl/qt5/Qt5Widget.cxx
@@ -22,6 +22,7 @@
 
 #include <Qt5Frame.hxx>
 #include <Qt5Graphics.hxx>
+#include <Qt5SvpGraphics.hxx>
 #include <Qt5Tools.hxx>
 
 #include <QtCore/QMimeData>
@@ -41,7 +42,6 @@
 #include <QtWidgets/QWidget>
 
 #include <cairo.h>
-#include <headless/svpgdi.hxx>
 #include <vcl/commandevent.hxx>
 
 void Qt5Widget::paintEvent(QPaintEvent* pEvent)
diff --git a/vcl/unx/kde5/KDE5SalFrame.cxx b/vcl/unx/kde5/KDE5SalFrame.cxx
index d3a13968237f..c195b641e119 100644
--- a/vcl/unx/kde5/KDE5SalFrame.cxx
+++ b/vcl/unx/kde5/KDE5SalFrame.cxx
@@ -30,8 +30,6 @@
 #include <KConfigGroup>
 #include <KSharedConfig>
 
-#undef Region
-
 #include "KDE5SalFrame.hxx"
 #include "KDE5SalGraphics.hxx"
 
@@ -211,7 +209,7 @@ SalGraphics* KDE5SalFrame::AcquireGraphics()
     if (!m_pKDE5Graphics.get())
     {
         m_pKDE5Graphics.reset(new KDE5SalGraphics(this));
-        Qt5Frame::InitSvpSalGraphics(m_pKDE5Graphics.get());
+        Qt5Frame::InitQt5SvpGraphics(m_pKDE5Graphics.get());
     }
 
     return m_pKDE5Graphics.get();
diff --git a/vcl/unx/kde5/KDE5SalGraphics.cxx b/vcl/unx/kde5/KDE5SalGraphics.cxx
index 0b4b4283f0da..6e30b9599740 100644
--- a/vcl/unx/kde5/KDE5SalGraphics.cxx
+++ b/vcl/unx/kde5/KDE5SalGraphics.cxx
@@ -40,7 +40,7 @@ static void QImage2BitmapBuffer(QImage* pImg, BitmapBuffer* 
pBuf)
 }
 
 KDE5SalGraphics::KDE5SalGraphics(Qt5Frame* pFrame)
-    : SvpSalGraphics()
+    : Qt5SvpGraphics(pFrame->GetQWidget())
     , m_pFrame(pFrame)
 {
 }
diff --git a/vcl/unx/kde5/KDE5SalGraphics.hxx b/vcl/unx/kde5/KDE5SalGraphics.hxx
index 109a0fa8ac29..1b12d890278c 100644
--- a/vcl/unx/kde5/KDE5SalGraphics.hxx
+++ b/vcl/unx/kde5/KDE5SalGraphics.hxx
@@ -25,6 +25,7 @@
 #include <headless/svpgdi.hxx>
 
 #include <Qt5Graphics_Controls.hxx>
+#include <Qt5SvpGraphics.hxx>
 
 #include <QtGui/QImage>
 #include <QtWidgets/QPushButton>
@@ -34,7 +35,7 @@ class Qt5Frame;
 /**
  * Handles native graphics requests and performs the needed drawing operations.
  */
-class KDE5SalGraphics : public SvpSalGraphics
+class KDE5SalGraphics : public Qt5SvpGraphics
 {
 public:
     KDE5SalGraphics(Qt5Frame* pFrame);
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to