~alan-griffiths/miral/fix-1645284

« back to all changes in this revision

Viewing changes to miral-qt/src/platforms/mirserver/screenwindow.cpp

  • Committer: Alan Griffiths
  • Date: 2016-11-07 17:59:19 UTC
  • mfrom: (436.1.1 miral2)
  • Revision ID: alan@octopull.co.uk-20161107175919-stbb64i7j1htgog2
[miral-qt] delete all as qtmir work on MirAL has shifted to lp:~unity-team/qtmir/miral-qt-integration and this is a needless distration

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright (C) 2013-2016 Canonical, Ltd.
3
 
 *
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.
7
 
 *
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.
12
 
 *
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/>.
15
 
 */
16
 
 
17
 
#include "screenwindow.h"
18
 
#include "screen.h"
19
 
 
20
 
// Mir
21
 
#include <mir/geometry/size.h>
22
 
#include <mir/graphics/display_buffer.h>
23
 
 
24
 
// Qt
25
 
#include <qpa/qwindowsysteminterface.h>
26
 
#include <qpa/qplatformscreen.h>
27
 
#include <QQuickWindow>
28
 
#include <QtQuick/private/qsgrenderloop_p.h>
29
 
#include <QDebug>
30
 
 
31
 
#include "logging.h"
32
 
 
33
 
static WId newWId()
34
 
{
35
 
    static WId id = 0;
36
 
 
37
 
    if (id == std::numeric_limits<WId>::max())
38
 
        qWarning("MirServer QPA: Out of window IDs");
39
 
 
40
 
    return ++id;
41
 
}
42
 
 
43
 
ScreenWindow::ScreenWindow(QWindow *window)
44
 
    : QPlatformWindow(window)
45
 
    , m_exposed(false)
46
 
    , m_winId(newWId())
47
 
{
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();
52
 
 
53
 
    QRect screenGeometry(screen()->availableGeometry());
54
 
    if (window->geometry() != screenGeometry) {
55
 
        setGeometry(screenGeometry);
56
 
        window->setGeometry(screenGeometry);
57
 
    }
58
 
    window->setSurfaceType(QSurface::OpenGLSurface);
59
 
}
60
 
 
61
 
ScreenWindow::~ScreenWindow()
62
 
{
63
 
    qCDebug(QTMIR_SCREENS) << "Destroying ScreenWindow" << this;
64
 
    static_cast<Screen *>(screen())->setWindow(nullptr);
65
 
}
66
 
 
67
 
bool ScreenWindow::isExposed() const
68
 
{
69
 
    return m_exposed;
70
 
}
71
 
 
72
 
void ScreenWindow::setExposed(const bool exposed)
73
 
{
74
 
    qCDebug(QTMIR_SCREENS) << "ScreenWindow::setExposed" << this << exposed << screen();
75
 
    if (m_exposed == exposed)
76
 
        return;
77
 
 
78
 
    m_exposed = exposed;
79
 
    if (!window())
80
 
        return;
81
 
 
82
 
    // If backing a QQuickWindow, need to stop/start its renderer immediately
83
 
    auto quickWindow = static_cast<QQuickWindow *>(window());
84
 
    if (!quickWindow)
85
 
        return;
86
 
 
87
 
    auto renderer = QSGRenderLoop::instance();
88
 
    if (exposed) {
89
 
        renderer->show(quickWindow);
90
 
        QWindowSystemInterface::handleExposeEvent(window(), geometry()); // else it won't redraw
91
 
        QWindowSystemInterface::handleWindowActivated(window(), Qt::ActiveWindowFocusReason);
92
 
    } else {
93
 
        quickWindow->setPersistentOpenGLContext(false);
94
 
        quickWindow->setPersistentSceneGraph(false);
95
 
        renderer->hide(quickWindow); // ExposeEvent will arrive too late, need to stop compositor immediately
96
 
    }
97
 
}
98
 
 
99
 
void ScreenWindow::setScreen(QPlatformScreen *newScreen)
100
 
{
101
 
    // Dis-associate the old screen
102
 
    if (screen()) {
103
 
        static_cast<Screen *>(screen())->setWindow(nullptr);
104
 
    }
105
 
 
106
 
    // Associate new screen and announce to Qt
107
 
    auto myScreen = static_cast<Screen *>(newScreen);
108
 
    Q_ASSERT(myScreen);
109
 
    myScreen->setWindow(this);
110
 
 
111
 
    QWindowSystemInterface::handleWindowScreenChanged(window(), myScreen->screen());
112
 
    setExposed(true); //GERRY - assumption setScreen only called while compositor running
113
 
 
114
 
    qCDebug(QTMIR_SCREENS) << "ScreenWindow" << this << "with window ID" << uint(m_winId) << "NEWLY backed by" << myScreen;
115
 
}
116
 
 
117
 
void ScreenWindow::swapBuffers()
118
 
{
119
 
    static_cast<Screen *>(screen())->swapBuffers();
120
 
}
121
 
 
122
 
void ScreenWindow::makeCurrent()
123
 
{
124
 
    static_cast<Screen *>(screen())->makeCurrent();
125
 
}
126
 
 
127
 
void ScreenWindow::doneCurrent()
128
 
{
129
 
    static_cast<Screen *>(screen())->doneCurrent();
130
 
}