Kaydet (Commit) 86cab846 authored tarafından Jan-Marek Glogowski's avatar Jan-Marek Glogowski

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.

Change-Id: Iba511c851001753328293c28e53eaa4acc4315d0
Reviewed-on: https://gerrit.libreoffice.org/72921Reviewed-by: 's avatarMichael Weghorn <m.weghorn@posteo.de>
Tested-by: Jenkins
Reviewed-by: 's avatarAleksei Nikiforov <darktemplar@basealt.ru>
üst ee2a9436
......@@ -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 \
......
......@@ -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;
......@@ -124,7 +125,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
......
/* -*- 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: */
/* -*- 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: */
......@@ -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>
......@@ -218,14 +219,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);
}
......@@ -240,8 +241,8 @@ SalGraphics* Qt5Frame::AcquireGraphics()
{
if (!m_pOurSvpGraphics.get() || m_bGraphicsInvalid)
{
m_pOurSvpGraphics.reset(new SvpSalGraphics());
InitSvpSalGraphics(m_pOurSvpGraphics.get());
m_pOurSvpGraphics.reset(new Qt5SvpGraphics(m_pQWidget));
InitQt5SvpGraphics(m_pOurSvpGraphics.get());
m_bGraphicsInvalid = false;
}
return m_pOurSvpGraphics.get();
......@@ -1250,4 +1251,15 @@ void Qt5Frame::dropping(const int x, const int y, Qt::KeyboardModifiers eKeyMod,
}
}
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: */
/* -*- 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: */
/* -*- 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& m_pSurface)
: m_pGraphics(nullptr)
, m_pCairoContext(nullptr)
, m_pSurface(m_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: */
......@@ -23,6 +23,7 @@
#include <Qt5Frame.hxx>
#include <Qt5Graphics.hxx>
#include <Qt5Instance.hxx>
#include <Qt5SvpGraphics.hxx>
#include <Qt5Tools.hxx>
#include <QtCore/QMimeData>
......@@ -43,7 +44,6 @@
#include <QtWidgets/QWidget>
#include <cairo.h>
#include <headless/svpgdi.hxx>
#include <vcl/commandevent.hxx>
#include <vcl/event.hxx>
#include <window.h>
......
......@@ -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();
......
......@@ -40,7 +40,7 @@ static void QImage2BitmapBuffer(QImage* pImg, BitmapBuffer* pBuf)
}
KDE5SalGraphics::KDE5SalGraphics(Qt5Frame* pFrame)
: SvpSalGraphics()
: Qt5SvpGraphics(pFrame->GetQWidget())
, m_pFrame(pFrame)
{
}
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment