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"
|
2020-10-16 16:20:58 +00:00
|
|
|
#include "eglhelpers.h"
|
2020-10-12 06:27:27 +00:00
|
|
|
#include "platform.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)
|
2020-10-16 16:20:58 +00:00
|
|
|
, m_eglDisplay(kwinApp()->platform()->sceneEglDisplay())
|
2015-08-14 14:52:40 +00:00
|
|
|
, m_windowId(++s_windowId)
|
2019-01-11 22:48:04 +00:00
|
|
|
, m_scale(screens()->maxScale())
|
2015-08-14 14:52:40 +00:00
|
|
|
{
|
2020-10-16 16:20:58 +00:00
|
|
|
if (window->surfaceType() == QSurface::OpenGLSurface) {
|
|
|
|
// The window will use OpenGL for drawing.
|
|
|
|
if (!kwinApp()->platform()->supportsSurfacelessContext()) {
|
|
|
|
createPbuffer();
|
|
|
|
}
|
|
|
|
}
|
2015-08-14 14:52:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Window::~Window()
|
|
|
|
{
|
2020-10-16 16:20:58 +00:00
|
|
|
if (m_eglSurface != EGL_NO_SURFACE) {
|
|
|
|
eglDestroySurface(m_eglDisplay, m_eglSurface);
|
|
|
|
}
|
2015-08-14 14:52:40 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2020-10-16 16:20:58 +00:00
|
|
|
QSurfaceFormat Window::format() const
|
|
|
|
{
|
|
|
|
return m_format;
|
|
|
|
}
|
|
|
|
|
2015-08-14 14:52:40 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2020-10-16 16:20:58 +00:00
|
|
|
void Window::createPbuffer()
|
|
|
|
{
|
|
|
|
const QSurfaceFormat requestedFormat = window()->requestedFormat();
|
|
|
|
const EGLConfig config = configFromFormat(m_eglDisplay,
|
|
|
|
requestedFormat,
|
|
|
|
EGL_PBUFFER_BIT);
|
|
|
|
if (config == EGL_NO_CONFIG_KHR) {
|
|
|
|
qCWarning(KWIN_QPA) << "Could not find any EGL config for:" << requestedFormat;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The size doesn't matter as we render into a framebuffer object.
|
|
|
|
const EGLint attribs[] = {
|
|
|
|
EGL_WIDTH, 16,
|
|
|
|
EGL_HEIGHT, 16,
|
|
|
|
EGL_NONE
|
|
|
|
};
|
|
|
|
|
|
|
|
m_eglSurface = eglCreatePbufferSurface(m_eglDisplay, config, attribs);
|
|
|
|
if (m_eglSurface != EGL_NO_SURFACE) {
|
|
|
|
m_format = formatFromConfig(m_eglDisplay, config);
|
|
|
|
} else {
|
|
|
|
qCWarning(KWIN_QPA, "Failed to create a pbuffer for window: 0x%x", eglGetError());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2020-10-12 06:27:27 +00:00
|
|
|
EGLSurface Window::eglSurface() const
|
|
|
|
{
|
2020-10-16 16:20:58 +00:00
|
|
|
return m_eglSurface;
|
2020-10-12 06:27:27 +00:00
|
|
|
}
|
|
|
|
|
2015-08-14 14:52:40 +00:00
|
|
|
}
|
|
|
|
}
|