2020-08-02 22:22:19 +00:00
|
|
|
/*
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
2015-08-14 14:52:40 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-FileCopyrightText: 2015 Martin Gräßlin <mgraesslin@kde.org>
|
|
|
|
SPDX-FileCopyrightText: 2019 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
|
2015-08-14 14:52:40 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2015-08-14 14:52:40 +00:00
|
|
|
#include "window.h"
|
2019-01-11 22:48:04 +00:00
|
|
|
#include "screens.h"
|
2019-08-26 07:44:04 +00:00
|
|
|
|
|
|
|
#include "internal_client.h"
|
|
|
|
|
2016-07-18 14:34:03 +00:00
|
|
|
#include <logging.h>
|
2015-08-14 14:52:40 +00:00
|
|
|
|
|
|
|
#include <QOpenGLFramebufferObject>
|
2016-05-09 12:48:10 +00:00
|
|
|
#include <qpa/qwindowsysteminterface.h>
|
2015-08-14 14:52:40 +00:00
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
namespace QPA
|
|
|
|
{
|
|
|
|
static quint32 s_windowId = 0;
|
|
|
|
|
2019-08-26 07:44:04 +00:00
|
|
|
Window::Window(QWindow *window)
|
2015-08-14 14:52:40 +00:00
|
|
|
: QPlatformWindow(window)
|
|
|
|
, m_windowId(++s_windowId)
|
2019-01-11 22:48:04 +00:00
|
|
|
, m_scale(screens()->maxScale())
|
2015-08-14 14:52:40 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Window::~Window()
|
|
|
|
{
|
|
|
|
unmap();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Window::setVisible(bool visible)
|
|
|
|
{
|
2019-08-26 07:44:04 +00:00
|
|
|
if (visible) {
|
|
|
|
map();
|
|
|
|
} else {
|
2015-08-14 14:52:40 +00:00
|
|
|
unmap();
|
|
|
|
}
|
2019-08-26 07:44:04 +00:00
|
|
|
|
2015-08-14 14:52:40 +00:00
|
|
|
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());
|
|
|
|
}
|
2019-01-11 22:48:04 +00:00
|
|
|
|
|
|
|
const QSize nativeSize = rect.size() * m_scale;
|
|
|
|
|
2015-08-14 14:52:40 +00:00
|
|
|
if (m_contentFBO) {
|
2019-01-11 22:48:04 +00:00
|
|
|
if (m_contentFBO->size() != nativeSize) {
|
2015-08-14 14:52:40 +00:00
|
|
|
m_resized = true;
|
|
|
|
}
|
|
|
|
}
|
2016-05-09 12:48:10 +00:00
|
|
|
QWindowSystemInterface::handleGeometryChange(window(), geometry());
|
2015-08-14 14:52:40 +00:00
|
|
|
}
|
|
|
|
|
2019-08-26 07:44:04 +00:00
|
|
|
WId Window::winId() const
|
2015-08-14 14:52:40 +00:00
|
|
|
{
|
2019-08-26 07:44:04 +00:00
|
|
|
return m_windowId;
|
|
|
|
}
|
|
|
|
|
|
|
|
qreal Window::devicePixelRatio() const
|
|
|
|
{
|
|
|
|
return m_scale;
|
2015-08-14 14:52:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Window::bindContentFBO()
|
|
|
|
{
|
|
|
|
if (m_resized || !m_contentFBO) {
|
|
|
|
createFBO();
|
|
|
|
}
|
|
|
|
m_contentFBO->bind();
|
|
|
|
}
|
|
|
|
|
2019-08-26 07:44:04 +00:00
|
|
|
const QSharedPointer<QOpenGLFramebufferObject> &Window::contentFBO() const
|
|
|
|
{
|
|
|
|
return m_contentFBO;
|
|
|
|
}
|
|
|
|
|
2015-08-14 14:52:40 +00:00
|
|
|
QSharedPointer<QOpenGLFramebufferObject> Window::swapFBO()
|
|
|
|
{
|
2019-08-26 07:44:04 +00:00
|
|
|
QSharedPointer<QOpenGLFramebufferObject> fbo = m_contentFBO;
|
2015-08-14 14:52:40 +00:00
|
|
|
m_contentFBO.clear();
|
|
|
|
return fbo;
|
|
|
|
}
|
|
|
|
|
2019-08-26 07:44:04 +00:00
|
|
|
InternalClient *Window::client() const
|
|
|
|
{
|
|
|
|
return m_handle;
|
|
|
|
}
|
|
|
|
|
2015-08-14 14:52:40 +00:00
|
|
|
void Window::createFBO()
|
|
|
|
{
|
|
|
|
const QRect &r = geometry();
|
2017-04-13 19:23:40 +00:00
|
|
|
if (m_contentFBO && r.size().isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
2019-01-11 22:48:04 +00:00
|
|
|
const QSize nativeSize = r.size() * m_scale;
|
|
|
|
m_contentFBO.reset(new QOpenGLFramebufferObject(nativeSize.width(), nativeSize.height(), QOpenGLFramebufferObject::CombinedDepthStencil));
|
2016-07-18 14:34:03 +00:00
|
|
|
if (!m_contentFBO->isValid()) {
|
|
|
|
qCWarning(KWIN_QPA) << "Content FBO is not valid";
|
|
|
|
}
|
2015-08-14 14:52:40 +00:00
|
|
|
m_resized = false;
|
|
|
|
}
|
|
|
|
|
2019-08-26 07:44:04 +00:00
|
|
|
void Window::map()
|
2015-08-14 14:52:40 +00:00
|
|
|
{
|
2019-08-26 07:44:04 +00:00
|
|
|
if (m_handle) {
|
|
|
|
return;
|
2015-08-14 14:52:40 +00:00
|
|
|
}
|
|
|
|
|
2019-08-26 07:44:04 +00:00
|
|
|
m_handle = new InternalClient(window());
|
2019-01-11 22:48:04 +00:00
|
|
|
}
|
|
|
|
|
2019-08-26 07:44:04 +00:00
|
|
|
void Window::unmap()
|
2019-01-11 22:48:04 +00:00
|
|
|
{
|
2019-08-26 07:44:04 +00:00
|
|
|
if (!m_handle) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_handle->destroyClient();
|
|
|
|
m_handle = nullptr;
|
|
|
|
|
|
|
|
m_contentFBO = nullptr;
|
2019-01-11 22:48:04 +00:00
|
|
|
}
|
|
|
|
|
2015-08-14 14:52:40 +00:00
|
|
|
}
|
|
|
|
}
|