kwin/plugins/qpa/window.cpp
Vlad Zagorodniy bebe81209c Port QPA away from Wayland
Summary:
So far wayland was used by internal clients to submit raster buffers
and position themselves on the screen. While we didn't have issues with
submitting raster buffers, there were some problems with positioning
task switchers. Mostly, because we had effectively two paths that may
alter geometry.

A better approach to deal with internal clients is to let our QPA use
kwin core api directly. This way we can eliminate unnecessary roundtrips
as well make geometry handling much easier and comprehensible.

The last missing piece is shadows. Both Plasma::Dialog and Breeze widget
style use platform-specific APIs to set and unset shadows. We need to
add shadows API to KWindowSystem. Even though some internal clients lack
drop-shadows at the moment, I don't consider it to be a blocker. We can
add shadows back later on.

CCBUG: 386304

Reviewers: #kwin, davidedmundson, romangg

Reviewed By: #kwin, romangg

Subscribers: romangg, kwin

Tags: #kwin

Maniphest Tasks: T9600

Differential Revision: https://phabricator.kde.org/D22810
2019-09-23 17:28:56 +03:00

158 lines
3.5 KiB
C++

/********************************************************************
KWin - the KDE window manager
This file is part of the KDE project.
Copyright (C) 2015 Martin Gräßlin <mgraesslin@kde.org>
Copyright (C) 2019 Vlad Zagorodniy <vladzzag@gmail.com>
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 "window.h"
#include "screens.h"
#include "internal_client.h"
#include <logging.h>
#include <QOpenGLFramebufferObject>
#include <qpa/qwindowsysteminterface.h>
namespace KWin
{
namespace QPA
{
static quint32 s_windowId = 0;
Window::Window(QWindow *window)
: QPlatformWindow(window)
, m_windowId(++s_windowId)
, m_scale(screens()->maxScale())
{
}
Window::~Window()
{
unmap();
}
void Window::setVisible(bool visible)
{
if (visible) {
map();
} else {
unmap();
}
QPlatformWindow::setVisible(visible);
}
void Window::setGeometry(const QRect &rect)
{
const QRect &oldRect = geometry();
QPlatformWindow::setGeometry(rect);
if (rect.x() != oldRect.x()) {
emit window()->xChanged(rect.x());
}
if (rect.y() != oldRect.y()) {
emit window()->yChanged(rect.y());
}
if (rect.width() != oldRect.width()) {
emit window()->widthChanged(rect.width());
}
if (rect.height() != oldRect.height()) {
emit window()->heightChanged(rect.height());
}
const QSize nativeSize = rect.size() * m_scale;
if (m_contentFBO) {
if (m_contentFBO->size() != nativeSize) {
m_resized = true;
}
}
QWindowSystemInterface::handleGeometryChange(window(), geometry());
}
WId Window::winId() const
{
return m_windowId;
}
qreal Window::devicePixelRatio() const
{
return m_scale;
}
void Window::bindContentFBO()
{
if (m_resized || !m_contentFBO) {
createFBO();
}
m_contentFBO->bind();
}
const QSharedPointer<QOpenGLFramebufferObject> &Window::contentFBO() const
{
return m_contentFBO;
}
QSharedPointer<QOpenGLFramebufferObject> Window::swapFBO()
{
QSharedPointer<QOpenGLFramebufferObject> fbo = m_contentFBO;
m_contentFBO.clear();
return fbo;
}
InternalClient *Window::client() const
{
return m_handle;
}
void Window::createFBO()
{
const QRect &r = geometry();
if (m_contentFBO && r.size().isEmpty()) {
return;
}
const QSize nativeSize = r.size() * m_scale;
m_contentFBO.reset(new QOpenGLFramebufferObject(nativeSize.width(), nativeSize.height(), QOpenGLFramebufferObject::CombinedDepthStencil));
if (!m_contentFBO->isValid()) {
qCWarning(KWIN_QPA) << "Content FBO is not valid";
}
m_resized = false;
}
void Window::map()
{
if (m_handle) {
return;
}
m_handle = new InternalClient(window());
}
void Window::unmap()
{
if (!m_handle) {
return;
}
m_handle->destroyClient();
m_handle = nullptr;
m_contentFBO = nullptr;
}
}
}