[libkwineffects] Introduce API to easily show a QtQuick scene in an effect

Summary:
EffectQuickView/Scene is a convenient class to render a QtQuick
scenegraph into an effect.

Current methods (such as present windows) involve creating an underlying
platform window which is expensive, causes a headache to filter out
again in the rest of the code, and only works as an overlay.

The new class exposes things more natively to an effect where we don't
mess with real windows, we can perform the painting anywhere in the view
and we don't have issues with hiding/closing.

QtQuick has both software and hardware accelerated modes, and kwin also
has 3 render backends. Every combination is supported.

* When used in OpenGL mode for both, we render into an FBO export the
texture ID then it's up to the effect to render that into a scene.

* When using software QtQuick rendering we blit into an image, upload
that into a KWinGLTexture which serves as an abstraction layer and
render that into the scene.

* When using GL for QtQuick and XRender/QPainter in kwin everything is
rendered into the internal FBO, blit and exported as an image.

* When using software rendering for both an image gets passed directly.

Mouse and keyboard events can be forwarded, only if the effect
intercepts them.

The class is meant to be generic enough that we can remove all the
QtQuick code from Aurorae.

The intention is also to replace EffectFrameImpl using this backend and
we can kill all of the EffectFrame code throughout the scenes.

The close button in present windows will also be ported to this,
simplifiying that code base.

Classes that handle the rendering and handling QML are intentionally
split so that in the future we can have a declarative effects API create
overlays from within the same context. Similar to how one can
instantiate windows from a typical QML scene.

Notes:
I don't like how I pass the kwin GL context from the backends into the
effect, but I need something that works with the library separation. It
also currently has wayland problem if I create a QOpenGLContext before
the QPA is set up with a scene - but I don't have anything better?

I know for the EffectFrame we need an API to push things through the
effects stack to handle blur/invert etc. Will deal with that when we
port the EffectFrame.

Test Plan: Used in an effect

Reviewers: #kwin, zzag

Reviewed By: #kwin, zzag

Subscribers: zzag, kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D24215
This commit is contained in:
David Edmundson 2019-09-27 16:06:37 +01:00
parent a161c508c8
commit 40b0296d5c
16 changed files with 634 additions and 4 deletions

View file

@ -278,6 +278,9 @@ public:
KSharedConfigPtr config() const override;
KSharedConfigPtr inputConfig() const override;
void renderEffectQuickView(KWin::EffectQuickView *quickView) const override {
Q_UNUSED(quickView);
}
private:
bool m_animationsSuported = true;

View file

@ -46,9 +46,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "window_property_notify_x11_filter.h"
#include "workspace.h"
#include "kwinglutils.h"
#include "kwineffectquickview.h"
#include <QDebug>
#include <QDesktopWidget>
#include <Plasma/Theme>
@ -1702,6 +1702,14 @@ Effect *EffectsHandlerImpl::findEffect(const QString &name) const
return (*it).second;
}
void EffectsHandlerImpl::renderEffectQuickView(EffectQuickView *w) const
{
if (!w->isVisible()) {
return;
}
scene()->paintEffectQuickView(w);
}
//****************************************
// EffectWindowImpl
//****************************************

View file

@ -273,6 +273,8 @@ public:
*/
Effect *findEffect(const QString &name) const;
void renderEffectQuickView(EffectQuickView *effectQuickView) const override;
public Q_SLOTS:
void slotCurrentTabAboutToChange(EffectWindow* from, EffectWindow* to);
void slotTabAdded(EffectWindow* from, EffectWindow* to);

View file

@ -40,6 +40,7 @@ install(TARGETS kwinxrenderutils EXPORT kdeworkspaceLibraryTargets ${INSTALL_TAR
set(kwin_EFFECTSLIB_SRCS
anidata.cpp
kwinanimationeffect.cpp
kwineffectquickview.cpp
kwineffects.cpp
logging.cpp
)
@ -47,12 +48,14 @@ set(kwin_EFFECTSLIB_SRCS
set(kwineffects_QT_LIBS
Qt5::DBus
Qt5::Widgets
Qt5::Quick
)
set(kwineffects_KDE_LIBS
KF5::ConfigCore
KF5::CoreAddons
KF5::WindowSystem
KF5::Declarative
)
set(kwineffects_XCB_LIBS
@ -66,6 +69,7 @@ target_link_libraries(kwineffects
${kwineffects_QT_LIBS}
${kwineffects_KDE_LIBS}
${kwineffects_XCB_LIBS}
kwinglutils
)
if (KWIN_HAVE_XRENDER_COMPOSITING)
target_link_libraries(kwineffects PRIVATE kwinxrenderutils XCB::XFIXES)
@ -112,6 +116,7 @@ install(FILES
${CMAKE_CURRENT_BINARY_DIR}/kwinglutils_export.h
${CMAKE_CURRENT_BINARY_DIR}/kwinxrenderutils_export.h
kwinanimationeffect.h
kwineffectquickview.h
kwineffects.h
kwinglobals.h
kwinglplatform.h

View file

@ -0,0 +1,357 @@
/********************************************************************
KWin - the KDE window manager
This file is part of the KDE project.
Copyright (C) 2019 David Edmundson <davidedmundson@kde.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
#include "kwineffectquickview.h"
#include "kwinglutils.h"
#include "kwineffects.h"
#include "logging_p.h"
#include <QQmlEngine>
#include <QQuickItem>
#include <QQmlContext>
#include <QQmlComponent>
#include <QQuickView>
#include <QQuickRenderControl>
#include <QUrl>
#include <QOffscreenSurface>
#include <QOpenGLContext>
#include <QOpenGLFramebufferObject>
#include <QTimer>
#include <KDeclarative/QmlObjectSharedEngine>
using namespace KWin;
static std::unique_ptr<QOpenGLContext> s_shareContext;
class Q_DECL_HIDDEN EffectQuickView::Private
{
public:
QQuickWindow *m_view;
QQuickRenderControl *m_renderControl;
QScopedPointer<QOpenGLContext> m_glcontext;
QScopedPointer<QOffscreenSurface> m_offscreenSurface;
QScopedPointer<QOpenGLFramebufferObject> m_fbo;
QImage m_image;
QScopedPointer<GLTexture> m_textureExport;
// if we should capture a QImage after rendering into our BO.
// Used for either software QtQuick rendering and nonGL kwin rendering
bool m_useBlit = false;
bool m_visible = true;
void releaseResources();
};
class Q_DECL_HIDDEN EffectQuickScene::Private
{
public:
KDeclarative::QmlObjectSharedEngine *qmlObject = nullptr;
};
EffectQuickView::EffectQuickView(QObject *parent)
: EffectQuickView(parent, effects->isOpenGLCompositing() ? ExportMode::Texture : ExportMode::Image)
{
}
EffectQuickView::EffectQuickView(QObject *parent, ExportMode exportMode)
: QObject(parent)
, d(new EffectQuickView::Private)
{
d->m_renderControl = new QQuickRenderControl(this);
d->m_view = new QQuickWindow(d->m_renderControl);
d->m_view->setFlags(Qt::FramelessWindowHint);
d->m_view->setColor(Qt::transparent);
if (exportMode == ExportMode::Image) {
d->m_useBlit = true;
}
const bool usingGl = d->m_view->rendererInterface()->graphicsApi() == QSGRendererInterface::OpenGL;
if (!usingGl) {
qCDebug(LIBKWINEFFECTS) << "QtQuick Software rendering mode detected";
d->m_useBlit = true;
d->m_renderControl->initialize(nullptr);
} else {
QSurfaceFormat format;
format.setOption(QSurfaceFormat::ResetNotification);
format.setDepthBufferSize(16);
format.setStencilBufferSize(8);
d->m_glcontext.reset(new QOpenGLContext);
d->m_glcontext->setShareContext(s_shareContext.get());
d->m_glcontext->setFormat(format);
d->m_glcontext->create();
// and the offscreen surface
d->m_offscreenSurface.reset(new QOffscreenSurface);
d->m_offscreenSurface->setFormat(d->m_glcontext->format());
d->m_offscreenSurface->create();
d->m_glcontext->makeCurrent(d->m_offscreenSurface.data());
d->m_renderControl->initialize(d->m_glcontext.data());
d->m_glcontext->doneCurrent();
if (!d->m_glcontext->shareContext()) {
qCDebug(LIBKWINEFFECTS) << "Failed to create a shared context, falling back to raster rendering";
qCDebug(LIBKWINEFFECTS) << "Extra debug:";
qCDebug(LIBKWINEFFECTS) << "our context:" << d->m_glcontext.data();
qCDebug(LIBKWINEFFECTS) << "share context:" << s_shareContext.get();
// still render via GL, but blit for presentation
d->m_useBlit = true;
}
}
auto updateSize = [this]() { contentItem()->setSize(d->m_view->size()); };
updateSize();
connect(d->m_view, &QWindow::widthChanged, this, updateSize);
connect(d->m_view, &QWindow::heightChanged, this, updateSize);
QTimer *t = new QTimer(this);
t->setSingleShot(true);
t->setInterval(10);
connect(t, &QTimer::timeout, this, &EffectQuickView::update);
connect(d->m_renderControl, &QQuickRenderControl::renderRequested, t, [t]() { t->start(); });
connect(d->m_renderControl, &QQuickRenderControl::sceneChanged, t, [t]() { t->start(); });
}
EffectQuickView::~EffectQuickView()
{
if (d->m_glcontext) {
d->m_glcontext->makeCurrent(d->m_offscreenSurface.data());
d->m_renderControl->invalidate();
d->m_glcontext->doneCurrent();
}
}
void EffectQuickView::update()
{
if (!d->m_visible) {
return;
}
if (d->m_view->size().isEmpty()) {
return;
}
bool usingGl = d->m_glcontext;
if (usingGl) {
if (!d->m_glcontext->makeCurrent(d->m_offscreenSurface.data())) {
// probably a context loss event, kwin is about to reset all the effects anyway
return;
}
if (d->m_fbo.isNull() || d->m_fbo->size() != d->m_view->size()) {
d->m_textureExport.reset(nullptr);
d->m_fbo.reset(new QOpenGLFramebufferObject(d->m_view->size(), QOpenGLFramebufferObject::CombinedDepthStencil));
if (!d->m_fbo->isValid()) {
d->m_fbo.reset();
d->m_glcontext->doneCurrent();
return;
}
}
d->m_view->setRenderTarget(d->m_fbo.data());
}
d->m_renderControl->polishItems();
d->m_renderControl->sync();
d->m_renderControl->render();
if (usingGl) {
d->m_view->resetOpenGLState();
}
if (d->m_useBlit) {
d->m_image = d->m_renderControl->grab();
}
if (usingGl) {
QOpenGLFramebufferObject::bindDefault();
d->m_glcontext->doneCurrent();
}
emit repaintNeeded();
}
void EffectQuickView::forwardMouseEvent(QEvent *e)
{
if (!d->m_visible) {
return;
}
QMouseEvent *me = static_cast<QMouseEvent *>(e);
const QPoint widgetPos = d->m_view->mapFromGlobal(me->pos());
QMouseEvent cloneEvent(me->type(), widgetPos, me->pos(), me->button(), me->buttons(), me->modifiers());
QCoreApplication::sendEvent(d->m_view, &cloneEvent);
e->setAccepted(cloneEvent.isAccepted());
}
void EffectQuickView::forwardKeyEvent(QKeyEvent *keyEvent)
{
if (!d->m_visible) {
return;
}
QCoreApplication::sendEvent(d->m_view, keyEvent);
}
void EffectQuickView::setShareContext(std::unique_ptr<QOpenGLContext> context)
{
s_shareContext = std::move(context);
}
QRect EffectQuickView::geometry() const
{
return d->m_view->geometry();
}
QQuickItem *EffectQuickView::contentItem() const
{
return d->m_view->contentItem();
}
void EffectQuickView::setVisible(bool visible)
{
if (d->m_visible == visible) {
return;
}
d->m_visible = visible;
if (visible){
d->m_renderControl->renderRequested();
} else {
// deferred to not change GL context
QTimer::singleShot(0, this, [this]() {
d->releaseResources();
});
}
}
bool EffectQuickView::isVisible() const
{
return d->m_visible;
}
void EffectQuickView::show()
{
setVisible(true);
}
void EffectQuickView::hide()
{
setVisible(false);
}
GLTexture *EffectQuickView::bufferAsTexture()
{
if (d->m_useBlit) {
if (d->m_image.isNull()) {
return nullptr;
}
d->m_textureExport.reset(new GLTexture(d->m_image));
} else {
if (!d->m_fbo) {
return nullptr;
}
if (!d->m_textureExport) {
d->m_textureExport.reset(new GLTexture(d->m_fbo->texture(), d->m_fbo->format().internalTextureFormat(), d->m_fbo->size()));
}
}
return d->m_textureExport.data();
}
QImage EffectQuickView::bufferAsImage() const
{
return d->m_image;
}
QSize EffectQuickView::size() const
{
return d->m_view->geometry().size();
}
void EffectQuickView::setGeometry(const QRect &rect)
{
const QRect oldGeometry = d->m_view->geometry();
d->m_view->setGeometry(rect);
emit geometryChanged(oldGeometry, rect);
}
void EffectQuickView::Private::releaseResources()
{
if (m_glcontext) {
m_glcontext->makeCurrent(m_offscreenSurface.data());
m_view->releaseResources();
m_glcontext->doneCurrent();
} else {
m_view->releaseResources();
}
}
EffectQuickScene::EffectQuickScene(QObject *parent)
: EffectQuickView(parent)
, d(new EffectQuickScene::Private)
{
}
EffectQuickScene::EffectQuickScene(QObject *parent, EffectQuickView::ExportMode exportMode)
: EffectQuickView(parent, exportMode)
, d(new EffectQuickScene::Private)
{
}
EffectQuickScene::~EffectQuickScene()
{
}
void EffectQuickScene::setSource(const QUrl &source)
{
if (!d->qmlObject) {
d->qmlObject = new KDeclarative::QmlObjectSharedEngine(this);
}
d->qmlObject->setSource(source);
QQuickItem *item = rootItem();
if (!item) {
qCDebug(LIBKWINEFFECTS) << "Could not load effect quick view" << source;
return;
}
item->setParentItem(contentItem());
auto updateSize = [item, this]() { item->setSize(contentItem()->size()); };
updateSize();
connect(contentItem(), &QQuickItem::widthChanged, item, updateSize);
connect(contentItem(), &QQuickItem::heightChanged, item, updateSize);
}
QQmlContext *EffectQuickScene::rootContext() const
{
return d->qmlObject->rootContext();
}
QQuickItem *EffectQuickScene::rootItem() const
{
return qobject_cast<QQuickItem *>(d->qmlObject->rootObject());
}

View file

@ -0,0 +1,179 @@
/********************************************************************
KWin - the KDE window manager
This file is part of the KDE project.
Copyright (C) 2019 David Edmundson <davidedmundson@kde.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
#pragma once
#include <QObject>
#include <QUrl>
#include <QRect>
#include <kwineffects_export.h>
#include "kwineffects.h"
#include <memory>
class QKeyEvent;
class QMouseEvent;
class QOpenGLContext;
class QMouseEvent;
class QKeyEvent;
class QQmlContext;
class QQuickItem;
namespace KWin
{
class GLTexture;
class EffectQuickView;
/**
* @brief The KwinQuickView class provides a convenient API for exporting
* QtQuick scenes as buffers that can be composited in any other fashion.
*
* Contents can be fetched as a GL Texture or as a QImage
* If data is to be fetched as an image, it should be specified upfront as
* blitting is performed when we update our FBO to keep kwin's render loop
* as fast as possible.
*/
class KWINEFFECTS_EXPORT EffectQuickView : public QObject
{
Q_OBJECT
public:
static void setShareContext(std::unique_ptr<QOpenGLContext> context);
enum class ExportMode {
/** The contents will be available as a texture in the shared contexts. Image will be blank*/
Texture,
/** The contents will be blit during the update into a QImage buffer. */
Image
};
/**
* Construct a new KWinQuickView
* Export mode will be determined by the current effectsHandler
*/
EffectQuickView(QObject *parent);
/**
* Construct a new KWinQuickView explicitly stating an export mode
*/
EffectQuickView(QObject *parent, ExportMode exportMode);
/**
* Note that this may change the current GL Context
*/
~EffectQuickView();
QSize size() const;
/**
* The geometry of the current view
* This may be out of sync with the current buffer size if an update is pending
*/
void setGeometry(const QRect &rect);
QRect geometry() const;
/**
* Render the current scene graph into the FBO.
* This is typically done automatically when the scene changes
* albeit deffered by a timer
*
* It can be manually invoked to update the contents immediately.
* Note this will change the GL context
*/
void update();
/** The invisble root item of the window*/
QQuickItem *contentItem() const;
/**
* @brief Marks the window as visible/invisible
* This can be used to release resources used by the window
* The default is true.
*/
void setVisible(bool visible);
bool isVisible() const;
void show();
void hide();
/**
* Returns the current output of the scene graph
* @note The render context must valid at the time of calling
*/
GLTexture *bufferAsTexture();
/**
* Returns the current output of the scene graph
*/
QImage bufferAsImage() const;
/**
* Inject any mouse event into the QQuickWindow.
* Local co-ordinates are transformed
* If it is handled the event will be accepted
*/
void forwardMouseEvent(QEvent *mouseEvent);
/**
* Inject a key event into the window.
* If it is handled the event will be accepted
*/
void forwardKeyEvent(QKeyEvent *keyEvent);
Q_SIGNALS:
/**
* The frame buffer has changed, contents need re-rendering on screen
*/
void repaintNeeded();
void geometryChanged(const QRect &oldGeometry, const QRect &newGeometry);
private:
class Private;
QScopedPointer<Private> d;
};
/**
* The KWinQuickScene class extends KWinQuickView
* adding QML support. This will represent a context
* powered by an engine
*/
class KWINEFFECTS_EXPORT EffectQuickScene : public EffectQuickView
{
public:
EffectQuickScene(QObject *parent);
EffectQuickScene(QObject *parent, ExportMode exportMode);
~EffectQuickScene();
QQmlContext *rootContext() const;
/** top level item in the given source*/
QQuickItem *rootItem() const;
void setSource(const QUrl &source);
private:
class Private;
QScopedPointer<Private> d;
};
}

View file

@ -82,6 +82,7 @@ class EffectWindow;
class EffectWindowGroup;
class EffectFrame;
class EffectFramePrivate;
class EffectQuickView;
class Effect;
class WindowQuad;
class GLShader;
@ -187,7 +188,7 @@ X-KDE-Library=kwin4_effect_cooleffect
#define KWIN_EFFECT_API_MAKE_VERSION( major, minor ) (( major ) << 8 | ( minor ))
#define KWIN_EFFECT_API_VERSION_MAJOR 0
#define KWIN_EFFECT_API_VERSION_MINOR 228
#define KWIN_EFFECT_API_VERSION_MINOR 229
#define KWIN_EFFECT_API_VERSION KWIN_EFFECT_API_MAKE_VERSION( \
KWIN_EFFECT_API_VERSION_MAJOR, KWIN_EFFECT_API_VERSION_MINOR )
@ -1359,6 +1360,13 @@ public:
*/
virtual bool hasActiveFullScreenEffect() const = 0;
/**
* Render the supplied EffectQuickView onto the scene
* It can be called at any point during the scene rendering
* @since 5.18
*/
virtual void renderEffectQuickView(EffectQuickView *effectQuickView) const = 0;
Q_SIGNALS:
/**
* Signal emitted when the current desktop changed.

View file

@ -28,7 +28,7 @@ include_directories(${CMAKE_SOURCE_DIR}/platformsupport/scenes/opengl)
add_library(KWinX11Platform MODULE ${X11PLATFORM_SOURCES})
set_target_properties(KWinX11Platform PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/org.kde.kwin.platforms/")
target_link_libraries(KWinX11Platform eglx11common kwin kwinxrenderutils SceneOpenGLBackend Qt5::X11Extras XCB::CURSOR KF5::Crash)
target_link_libraries(KWinX11Platform eglx11common kwin kwinxrenderutils SceneOpenGLBackend Qt5::X11Extras XCB::CURSOR KF5::Crash )
if (X11_Xinput_FOUND)
target_link_libraries(KWinX11Platform ${X11_Xinput_LIB})
endif()

View file

@ -38,11 +38,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
// kwin libs
#include <kwinglplatform.h>
#include <kwinglutils.h>
#include <kwineffectquickview.h>
#include <kwinxrenderutils.h>
// Qt
#include <QDebug>
#include <QOpenGLContext>
#include <QX11Info>
#include <QtPlatformHeaders/QGLXNativeContext>
// system
#include <unistd.h>
@ -137,6 +139,7 @@ GlxBackend::~GlxBackend()
// do cleanup after initBuffer()
cleanupGL();
doneCurrent();
EffectQuickView::setShareContext(nullptr);
gs_tripleBufferUndetected = true;
gs_tripleBufferNeedsDetection = false;
@ -359,6 +362,12 @@ bool GlxBackend::initRenderingContext()
return false;
}
auto qtContext = new QOpenGLContext;
QGLXNativeContext native(ctx, display());
qtContext->setNativeHandle(QVariant::fromValue(native));
qtContext->create();
EffectQuickView::setShareContext(std::unique_ptr<QOpenGLContext>(qtContext));
return true;
}

View file

@ -33,6 +33,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "platformsupport/scenes/opengl/texture.h"
#include <kwinglplatform.h>
#include <kwineffectquickview.h>
#include "utils.h"
#include "x11client.h"
@ -858,6 +859,30 @@ void SceneOpenGL::paintDesktop(int desktop, int mask, const QRegion &region, Scr
glDisable(GL_SCISSOR_TEST);
}
void SceneOpenGL::paintEffectQuickView(EffectQuickView *w)
{
GLShader *shader = ShaderManager::instance()->pushShader(ShaderTrait::MapTexture);
const QRect rect = w->geometry();
GLTexture *t = w->bufferAsTexture();
if (!t) {
return;
}
QMatrix4x4 mvp(projectionMatrix());
mvp.translate(rect.x(), rect.y());
shader->setUniform(GLShader::ModelViewProjectionMatrix, mvp);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
t->bind();
t->render(QRegion(infiniteRegion()), w->geometry());
t->unbind();
glDisable(GL_BLEND);
return;
}
bool SceneOpenGL::makeOpenGLContextCurrent()
{
return m_backend->makeCurrent();

View file

@ -90,6 +90,7 @@ protected:
void extendPaintRegion(QRegion &region, bool opaqueFullscreen) override;
QMatrix4x4 transformation(int mask, const ScreenPaintData &data) const;
void paintDesktop(int desktop, int mask, const QRegion &region, ScreenPaintData &data) override;
void paintEffectQuickView(EffectQuickView *w) override;
void handleGraphicsReset(GLenum status);

View file

@ -29,6 +29,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "toplevel.h"
#include "platform.h"
#include "wayland_server.h"
#include <kwineffectquickview.h>
#include <KWayland/Server/buffer_interface.h>
#include <KWayland/Server/subcompositor_interface.h>
#include <KWayland/Server/surface_interface.h>
@ -173,6 +176,16 @@ void SceneQPainter::paintCursor()
kwinApp()->platform()->markCursorAsRendered();
}
void SceneQPainter::paintEffectQuickView(EffectQuickView *w)
{
QPainter *painter = effects->scenePainter();
const QImage buffer = w->bufferAsImage();
if (buffer.isNull()) {
return;
}
painter->drawImage(w->geometry(), buffer);
}
Scene::Window *SceneQPainter::createWindow(Toplevel *toplevel)
{
return new SceneQPainter::Window(this, toplevel);

View file

@ -62,6 +62,7 @@ protected:
void paintBackground(QRegion region) override;
Scene::Window *createWindow(Toplevel *toplevel) override;
void paintCursor() override;
void paintEffectQuickView(EffectQuickView *w) override;
private:
explicit SceneQPainter(QPainterBackend *backend, QObject *parent = nullptr);

View file

@ -36,9 +36,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "platform.h"
#include "screens.h"
#include "xcbutils.h"
#include "kwinxrenderutils.h"
#include "decorations/decoratedclient.h"
#include <kwineffectquickview.h>
#include <kwinxrenderutils.h>
#include <xcb/xfixes.h>
#include <QDebug>
@ -1329,3 +1331,16 @@ void KWin::SceneXrender::paintCursor()
{
}
void KWin::SceneXrender::paintEffectQuickView(KWin::EffectQuickView *w)
{
const QImage buffer = w->bufferAsImage();
if (buffer.isNull()) {
return;
}
XRenderPicture picture(buffer);
xcb_render_composite(connection(), XCB_RENDER_PICT_OP_OVER, picture, XCB_RENDER_PICTURE_NONE,
effects->xrenderBufferPicture(),
0, 0, 0, 0, w->geometry().x(), w->geometry().y(),
w->geometry().width(), w->geometry().height());
}

View file

@ -178,6 +178,7 @@ protected:
void paintGenericScreen(int mask, ScreenPaintData data) override;
void paintDesktop(int desktop, int mask, const QRegion &region, ScreenPaintData &data) override;
void paintCursor() override;
void paintEffectQuickView(EffectQuickView *w) override;
private:
explicit SceneXrender(XRenderBackend *backend, QObject *parent = nullptr);
static ScreenPaintData screen_paint;

View file

@ -236,6 +236,9 @@ protected:
// the default is NOOP
virtual void extendPaintRegion(QRegion &region, bool opaqueFullscreen);
virtual void paintDesktop(int desktop, int mask, const QRegion &region, ScreenPaintData &data);
virtual void paintEffectQuickView(EffectQuickView *w) = 0;
// compute time since the last repaint
void updateTimeDiff();
// saved data for 2nd pass of optimized screen painting