Summary: Not needed except for X11/non-composited usage, so should be in the plugin instead of core. Platform API is extended to create a decoration renderer. Reviewers: #kwin, #plasma Subscribers: plasma-devel, kwin Tags: #kwin Differential Revision: https://phabricator.kde.org/D7444remotes/origin/scene-opengl-plugin
parent
535b107969
commit
23ef40e638
10 changed files with 199 additions and 102 deletions
@ -0,0 +1,109 @@ |
||||
/********************************************************************
|
||||
KWin - the KDE window manager |
||||
This file is part of the KDE project. |
||||
|
||||
Copyright (C) 2014 Martin Gräßlin <mgraesslin@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 "x11_decoration_renderer.h" |
||||
#include "decorations/decoratedclient.h" |
||||
#include "client.h" |
||||
#include "deleted.h" |
||||
|
||||
#include <kwinglobals.h> |
||||
|
||||
#include <KDecoration2/Decoration> |
||||
#include <KDecoration2/DecoratedClient> |
||||
|
||||
#include <QTimer> |
||||
|
||||
namespace KWin |
||||
{ |
||||
namespace Decoration |
||||
{ |
||||
|
||||
X11Renderer::X11Renderer(DecoratedClientImpl *client) |
||||
: Renderer(client) |
||||
, m_scheduleTimer(new QTimer(this)) |
||||
, m_gc(XCB_NONE) |
||||
{ |
||||
// delay any rendering to end of event cycle to catch multiple updates per cycle
|
||||
m_scheduleTimer->setSingleShot(true); |
||||
m_scheduleTimer->setInterval(0); |
||||
connect(m_scheduleTimer, &QTimer::timeout, this, &X11Renderer::render); |
||||
connect(this, &Renderer::renderScheduled, m_scheduleTimer, static_cast<void (QTimer::*)()>(&QTimer::start)); |
||||
} |
||||
|
||||
X11Renderer::~X11Renderer() |
||||
{ |
||||
if (m_gc != XCB_NONE) { |
||||
xcb_free_gc(connection(), m_gc); |
||||
} |
||||
} |
||||
|
||||
void X11Renderer::reparent(Deleted *deleted) |
||||
{ |
||||
if (m_scheduleTimer->isActive()) { |
||||
m_scheduleTimer->stop(); |
||||
} |
||||
disconnect(m_scheduleTimer, &QTimer::timeout, this, &X11Renderer::render); |
||||
disconnect(this, &Renderer::renderScheduled, m_scheduleTimer, static_cast<void (QTimer::*)()>(&QTimer::start)); |
||||
Renderer::reparent(deleted); |
||||
} |
||||
|
||||
void X11Renderer::render() |
||||
{ |
||||
if (!client()) { |
||||
return; |
||||
} |
||||
const QRegion scheduled = getScheduled(); |
||||
if (scheduled.isEmpty()) { |
||||
return; |
||||
} |
||||
xcb_connection_t *c = connection(); |
||||
if (m_gc == XCB_NONE) { |
||||
m_gc = xcb_generate_id(c); |
||||
xcb_create_gc(c, m_gc, client()->client()->frameId(), 0, nullptr); |
||||
} |
||||
|
||||
QRect left, top, right, bottom; |
||||
client()->client()->layoutDecorationRects(left, top, right, bottom); |
||||
|
||||
const QRect geometry = scheduled.boundingRect(); |
||||
left = left.intersected(geometry); |
||||
top = top.intersected(geometry); |
||||
right = right.intersected(geometry); |
||||
bottom = bottom.intersected(geometry); |
||||
|
||||
auto renderPart = [this, c](const QRect &geo) { |
||||
if (geo.isNull()) { |
||||
return; |
||||
} |
||||
QImage image = renderToImage(geo); |
||||
xcb_put_image(c, XCB_IMAGE_FORMAT_Z_PIXMAP, client()->client()->frameId(), m_gc, |
||||
image.width(), image.height(), geo.x(), geo.y(), 0, client()->client()->depth(), |
||||
image.byteCount(), image.constBits()); |
||||
}; |
||||
renderPart(left); |
||||
renderPart(top); |
||||
renderPart(right); |
||||
renderPart(bottom); |
||||
|
||||
xcb_flush(c); |
||||
resetImageSizesDirty(); |
||||
} |
||||
|
||||
} |
||||
} |
||||
@ -0,0 +1,55 @@ |
||||
/********************************************************************
|
||||
KWin - the KDE window manager |
||||
This file is part of the KDE project. |
||||
|
||||
Copyright (C) 2014 Martin Gräßlin <mgraesslin@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/>.
|
||||
*********************************************************************/ |
||||
#ifndef KWIN_DECORATION_X11_RENDERER_H |
||||
#define KWIN_DECORATION_X11_RENDERER_H |
||||
|
||||
#include "decorations/decorationrenderer.h" |
||||
|
||||
#include <xcb/xcb.h> |
||||
|
||||
class QTimer; |
||||
|
||||
namespace KWin |
||||
{ |
||||
|
||||
namespace Decoration |
||||
{ |
||||
|
||||
class X11Renderer : public Renderer |
||||
{ |
||||
Q_OBJECT |
||||
public: |
||||
explicit X11Renderer(DecoratedClientImpl *client); |
||||
virtual ~X11Renderer(); |
||||
|
||||
void reparent(Deleted *deleted) override; |
||||
|
||||
protected: |
||||
void render() override; |
||||
|
||||
private: |
||||
QTimer *m_scheduleTimer; |
||||
xcb_gcontext_t m_gc; |
||||
}; |
||||
|
||||
} |
||||
} |
||||
|
||||
#endif |
||||
Loading…
Reference in new issue