2
* Copyright (C) 2013-2016 Canonical, Ltd.
4
* This program is free software: you can redistribute it and/or modify it under
5
* the terms of the GNU Lesser General Public License version 3, as published by
6
* the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful, but WITHOUT
9
* ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10
* SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
* Lesser General Public License for more details.
13
* You should have received a copy of the GNU Lesser General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17
#include "screenwindow.h"
21
#include <mir/geometry/size.h>
22
#include <mir/graphics/display_buffer.h>
25
#include <qpa/qwindowsysteminterface.h>
26
#include <qpa/qplatformscreen.h>
27
#include <QQuickWindow>
28
#include <QtQuick/private/qsgrenderloop_p.h>
37
if (id == std::numeric_limits<WId>::max())
38
qWarning("MirServer QPA: Out of window IDs");
43
ScreenWindow::ScreenWindow(QWindow *window)
44
: QPlatformWindow(window)
48
// Note: window->screen() is set to the primaryScreen(), if not specified explicitly.
49
const auto myScreen = static_cast<Screen *>(window->screen()->handle());
50
myScreen->setWindow(this);
51
qCDebug(QTMIR_SCREENS) << "ScreenWindow" << this << "with window ID" << uint(m_winId) << "backed by" << myScreen << "with ID" << myScreen->outputId().as_value();
53
QRect screenGeometry(screen()->availableGeometry());
54
if (window->geometry() != screenGeometry) {
55
setGeometry(screenGeometry);
56
window->setGeometry(screenGeometry);
58
window->setSurfaceType(QSurface::OpenGLSurface);
61
ScreenWindow::~ScreenWindow()
63
qCDebug(QTMIR_SCREENS) << "Destroying ScreenWindow" << this;
64
static_cast<Screen *>(screen())->setWindow(nullptr);
67
bool ScreenWindow::isExposed() const
72
void ScreenWindow::setExposed(const bool exposed)
74
qCDebug(QTMIR_SCREENS) << "ScreenWindow::setExposed" << this << exposed << screen();
75
if (m_exposed == exposed)
82
// If backing a QQuickWindow, need to stop/start its renderer immediately
83
auto quickWindow = static_cast<QQuickWindow *>(window());
87
auto renderer = QSGRenderLoop::instance();
89
renderer->show(quickWindow);
90
QWindowSystemInterface::handleExposeEvent(window(), geometry()); // else it won't redraw
91
QWindowSystemInterface::handleWindowActivated(window(), Qt::ActiveWindowFocusReason);
93
quickWindow->setPersistentOpenGLContext(false);
94
quickWindow->setPersistentSceneGraph(false);
95
renderer->hide(quickWindow); // ExposeEvent will arrive too late, need to stop compositor immediately
99
void ScreenWindow::setScreen(QPlatformScreen *newScreen)
101
// Dis-associate the old screen
103
static_cast<Screen *>(screen())->setWindow(nullptr);
106
// Associate new screen and announce to Qt
107
auto myScreen = static_cast<Screen *>(newScreen);
109
myScreen->setWindow(this);
111
QWindowSystemInterface::handleWindowScreenChanged(window(), myScreen->screen());
112
setExposed(true); //GERRY - assumption setScreen only called while compositor running
114
qCDebug(QTMIR_SCREENS) << "ScreenWindow" << this << "with window ID" << uint(m_winId) << "NEWLY backed by" << myScreen;
117
void ScreenWindow::swapBuffers()
119
static_cast<Screen *>(screen())->swapBuffers();
122
void ScreenWindow::makeCurrent()
124
static_cast<Screen *>(screen())->makeCurrent();
127
void ScreenWindow::doneCurrent()
129
static_cast<Screen *>(screen())->doneCurrent();