1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2016 Pelagicore AG |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the plugins of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:LGPL$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU Lesser General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
21 | ** packaging of this file. Please review the following information to |
22 | ** ensure the GNU Lesser General Public License version 3 requirements |
23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
24 | ** |
25 | ** GNU General Public License Usage |
26 | ** Alternatively, this file may be used under the terms of the GNU |
27 | ** General Public License version 2.0 or (at your option) the GNU General |
28 | ** Public license version 3 or any later version approved by the KDE Free |
29 | ** Qt Foundation. The licenses are as published by the Free Software |
30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
31 | ** included in the packaging of this file. Please review the following |
32 | ** information to ensure the GNU General Public License requirements will |
33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
35 | ** |
36 | ** $QT_END_LICENSE$ |
37 | ** |
38 | ****************************************************************************/ |
39 | |
40 | #include "qeglfskmsegldevicescreen.h" |
41 | #include "qeglfskmsegldevice.h" |
42 | #include <QGuiApplication> |
43 | #include <QLoggingCategory> |
44 | #include <errno.h> |
45 | |
46 | QT_BEGIN_NAMESPACE |
47 | |
48 | Q_DECLARE_LOGGING_CATEGORY(qLcEglfsKmsDebug) |
49 | |
50 | QEglFSKmsEglDeviceScreen::QEglFSKmsEglDeviceScreen(QEglFSKmsDevice *device, const QKmsOutput &output) |
51 | : QEglFSKmsScreen(device, output) |
52 | { |
53 | } |
54 | |
55 | QEglFSKmsEglDeviceScreen::~QEglFSKmsEglDeviceScreen() |
56 | { |
57 | const int remainingScreenCount = qGuiApp->screens().count(); |
58 | qCDebug(qLcEglfsKmsDebug, "Screen dtor. Remaining screens: %d" , remainingScreenCount); |
59 | if (!remainingScreenCount && !device()->screenConfig()->separateScreens()) |
60 | static_cast<QEglFSKmsEglDevice *>(device())->destroyGlobalCursor(); |
61 | } |
62 | |
63 | QPlatformCursor *QEglFSKmsEglDeviceScreen::cursor() const |
64 | { |
65 | // The base class creates a cursor via integration->createCursor() |
66 | // in its ctor. With separateScreens just use that. Otherwise |
67 | // there's a virtual desktop and the device has a global cursor |
68 | // and the base class has no dedicated cursor at all. |
69 | // config->hwCursor() is ignored for now, just use the standard OpenGL cursor. |
70 | return device()->screenConfig()->separateScreens() |
71 | ? QEglFSScreen::cursor() |
72 | : static_cast<QEglFSKmsEglDevice *>(device())->globalCursor(); |
73 | } |
74 | |
75 | void QEglFSKmsEglDeviceScreen::waitForFlip() |
76 | { |
77 | QKmsOutput &op(output()); |
78 | const int fd = device()->fd(); |
79 | const uint32_t w = op.modes[op.mode].hdisplay; |
80 | const uint32_t h = op.modes[op.mode].vdisplay; |
81 | |
82 | if (!op.mode_set) { |
83 | op.mode_set = true; |
84 | |
85 | drmModeCrtcPtr currentMode = drmModeGetCrtc(fd, op.crtc_id); |
86 | const bool alreadySet = currentMode && currentMode->width == w && currentMode->height == h; |
87 | if (currentMode) |
88 | drmModeFreeCrtc(currentMode); |
89 | if (alreadySet) { |
90 | // Maybe detecting the DPMS mode could help here, but there are no properties |
91 | // exposed on the connector apparently. So rely on an env var for now. |
92 | static bool alwaysDoSet = qEnvironmentVariableIntValue("QT_QPA_EGLFS_ALWAYS_SET_MODE" ); |
93 | if (!alwaysDoSet) { |
94 | qCDebug(qLcEglfsKmsDebug, "Mode already set" ); |
95 | return; |
96 | } |
97 | } |
98 | |
99 | qCDebug(qLcEglfsKmsDebug, "Setting mode" ); |
100 | int ret = drmModeSetCrtc(fd, op.crtc_id, |
101 | uint32_t(-1), 0, 0, |
102 | &op.connector_id, 1, |
103 | &op.modes[op.mode]); |
104 | if (ret) |
105 | qErrnoWarning(errno, "drmModeSetCrtc failed" ); |
106 | } |
107 | |
108 | if (!op.forced_plane_set) { |
109 | op.forced_plane_set = true; |
110 | |
111 | if (op.wants_forced_plane) { |
112 | qCDebug(qLcEglfsKmsDebug, "Setting plane %u" , op.forced_plane_id); |
113 | int ret = drmModeSetPlane(fd, op.forced_plane_id, op.crtc_id, uint32_t(-1), 0, |
114 | 0, 0, w, h, |
115 | 0 << 16, 0 << 16, op.size.width() << 16, op.size.height() << 16); |
116 | if (ret == -1) |
117 | qErrnoWarning(errno, "drmModeSetPlane failed" ); |
118 | } |
119 | } |
120 | } |
121 | |
122 | QT_END_NAMESPACE |
123 | |