Changeset View
Changeset View
Standalone View
Standalone View
plugins/qpa/window.cpp
Show All 14 Lines | |||||
15 | GNU General Public License for more details. | 15 | GNU General Public License for more details. | ||
16 | 16 | | |||
17 | You should have received a copy of the GNU General Public License | 17 | You should have received a copy of the GNU General Public License | ||
18 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
19 | *********************************************************************/ | 19 | *********************************************************************/ | ||
20 | #define WL_EGL_PLATFORM 1 | 20 | #define WL_EGL_PLATFORM 1 | ||
21 | #include "integration.h" | 21 | #include "integration.h" | ||
22 | #include "window.h" | 22 | #include "window.h" | ||
23 | #include "screens.h" | ||||
23 | #include "../../shell_client.h" | 24 | #include "../../shell_client.h" | ||
24 | #include "../../wayland_server.h" | 25 | #include "../../wayland_server.h" | ||
25 | #include <logging.h> | 26 | #include <logging.h> | ||
26 | 27 | | |||
27 | #include <QOpenGLFramebufferObject> | 28 | #include <QOpenGLFramebufferObject> | ||
28 | #include <qpa/qwindowsysteminterface.h> | 29 | #include <qpa/qwindowsysteminterface.h> | ||
29 | 30 | | |||
30 | #include <KWayland/Client/buffer.h> | 31 | #include <KWayland/Client/buffer.h> | ||
31 | #include <KWayland/Client/connection_thread.h> | 32 | #include <KWayland/Client/connection_thread.h> | ||
32 | #include <KWayland/Client/shell.h> | 33 | #include <KWayland/Client/shell.h> | ||
33 | #include <KWayland/Client/surface.h> | 34 | #include <KWayland/Client/surface.h> | ||
34 | 35 | | |||
35 | namespace KWin | 36 | namespace KWin | ||
36 | { | 37 | { | ||
37 | namespace QPA | 38 | namespace QPA | ||
38 | { | 39 | { | ||
39 | static quint32 s_windowId = 0; | 40 | static quint32 s_windowId = 0; | ||
40 | 41 | | |||
41 | Window::Window(QWindow *window, KWayland::Client::Surface *surface, KWayland::Client::ShellSurface *shellSurface, const Integration *integration) | 42 | Window::Window(QWindow *window, KWayland::Client::Surface *surface, KWayland::Client::ShellSurface *shellSurface, const Integration *integration) | ||
42 | : QPlatformWindow(window) | 43 | : QPlatformWindow(window) | ||
43 | , m_surface(surface) | 44 | , m_surface(surface) | ||
44 | , m_shellSurface(shellSurface) | 45 | , m_shellSurface(shellSurface) | ||
45 | , m_windowId(++s_windowId) | 46 | , m_windowId(++s_windowId) | ||
46 | , m_integration(integration) | 47 | , m_integration(integration) | ||
48 | , m_scale(screens()->maxScale()) | ||||
47 | { | 49 | { | ||
50 | m_surface->setScale(m_scale); | ||||
51 | | ||||
48 | QObject::connect(m_surface, &QObject::destroyed, window, [this] { m_surface = nullptr;}); | 52 | QObject::connect(m_surface, &QObject::destroyed, window, [this] { m_surface = nullptr;}); | ||
49 | QObject::connect(m_shellSurface, &QObject::destroyed, window, [this] { m_shellSurface = nullptr;}); | 53 | QObject::connect(m_shellSurface, &QObject::destroyed, window, [this] { m_shellSurface = nullptr;}); | ||
50 | waylandServer()->internalClientConection()->flush(); | 54 | waylandServer()->internalClientConection()->flush(); | ||
51 | } | 55 | } | ||
52 | 56 | | |||
53 | Window::~Window() | 57 | Window::~Window() | ||
54 | { | 58 | { | ||
55 | unmap(); | 59 | unmap(); | ||
Show All 33 Lines | 92 | if (rect.y() != oldRect.y()) { | |||
89 | emit window()->yChanged(rect.y()); | 93 | emit window()->yChanged(rect.y()); | ||
90 | } | 94 | } | ||
91 | if (rect.width() != oldRect.width()) { | 95 | if (rect.width() != oldRect.width()) { | ||
92 | emit window()->widthChanged(rect.width()); | 96 | emit window()->widthChanged(rect.width()); | ||
93 | } | 97 | } | ||
94 | if (rect.height() != oldRect.height()) { | 98 | if (rect.height() != oldRect.height()) { | ||
95 | emit window()->heightChanged(rect.height()); | 99 | emit window()->heightChanged(rect.height()); | ||
96 | } | 100 | } | ||
101 | | ||||
102 | const QSize nativeSize = rect.size() * m_scale; | ||||
103 | | ||||
97 | if (m_contentFBO) { | 104 | if (m_contentFBO) { | ||
98 | if (m_contentFBO->width() != geometry().width() || m_contentFBO->height() != geometry().height()) { | 105 | if (m_contentFBO->size() != nativeSize) { | ||
zzag: Should it be floored or rounded? | |||||
davidedmundson: Everything is an int | |||||
Oh, shoot, I always think of scale as qreal, sorry. More simpler version: if (m_contentFBO->size() != geometry().size() * m_scale) { zzag: Oh, shoot, I always think of scale as qreal, sorry. More simpler version:
```lang=cpp
if… | |||||
99 | m_resized = true; | 106 | m_resized = true; | ||
100 | } | 107 | } | ||
101 | } | 108 | } | ||
102 | #if HAVE_WAYLAND_EGL | 109 | #if HAVE_WAYLAND_EGL | ||
103 | if (m_eglWaylandWindow) { | 110 | if (m_eglWaylandWindow) { | ||
104 | wl_egl_window_resize(m_eglWaylandWindow, geometry().width(), geometry().height(), 0, 0); | 111 | wl_egl_window_resize(m_eglWaylandWindow, nativeSize.width(), nativeSize.height(), 0, 0); | ||
105 | } | 112 | } | ||
106 | #endif | 113 | #endif | ||
107 | QWindowSystemInterface::handleGeometryChange(window(), geometry()); | 114 | QWindowSystemInterface::handleGeometryChange(window(), geometry()); | ||
108 | } | 115 | } | ||
109 | 116 | | |||
110 | void Window::unmap() | 117 | void Window::unmap() | ||
111 | { | 118 | { | ||
112 | if (m_shellClient) { | 119 | if (m_shellClient) { | ||
113 | m_shellClient->setInternalFramebufferObject(QSharedPointer<QOpenGLFramebufferObject>()); | 120 | m_shellClient->setInternalFramebufferObject(QSharedPointer<QOpenGLFramebufferObject>()); | ||
114 | } | 121 | } | ||
115 | if (m_surface) { | 122 | if (m_surface) { | ||
116 | m_surface->attachBuffer(KWayland::Client::Buffer::Ptr()); | 123 | m_surface->attachBuffer(KWayland::Client::Buffer::Ptr()); | ||
117 | m_surface->commit(KWayland::Client::Surface::CommitFlag::None); | 124 | m_surface->commit(KWayland::Client::Surface::CommitFlag::None); | ||
118 | } | 125 | } | ||
119 | if (waylandServer()->internalClientConection()) { | 126 | if (waylandServer()->internalClientConection()) { | ||
120 | waylandServer()->internalClientConection()->flush(); | 127 | waylandServer()->internalClientConection()->flush(); | ||
121 | } | 128 | } | ||
122 | } | 129 | } | ||
123 | 130 | | |||
124 | void Window::createEglSurface(EGLDisplay dpy, EGLConfig config) | 131 | void Window::createEglSurface(EGLDisplay dpy, EGLConfig config) | ||
125 | { | 132 | { | ||
126 | #if HAVE_WAYLAND_EGL | 133 | #if HAVE_WAYLAND_EGL | ||
127 | const QSize size = window()->size(); | 134 | const QSize size = window()->size() * m_scale; | ||
128 | m_eglWaylandWindow = wl_egl_window_create(*m_surface, size.width(), size.height()); | 135 | m_eglWaylandWindow = wl_egl_window_create(*m_surface, size.width(), size.height()); | ||
129 | if (!m_eglWaylandWindow) { | 136 | if (!m_eglWaylandWindow) { | ||
130 | return; | 137 | return; | ||
131 | } | 138 | } | ||
132 | m_eglSurface = eglCreateWindowSurface(dpy, config, m_eglWaylandWindow, nullptr); | 139 | m_eglSurface = eglCreateWindowSurface(dpy, config, m_eglWaylandWindow, nullptr); | ||
133 | #else | 140 | #else | ||
134 | Q_UNUSED(dpy) | 141 | Q_UNUSED(dpy) | ||
135 | Q_UNUSED(config) | 142 | Q_UNUSED(config) | ||
Show All 17 Lines | |||||
153 | } | 160 | } | ||
154 | 161 | | |||
155 | void Window::createFBO() | 162 | void Window::createFBO() | ||
156 | { | 163 | { | ||
157 | const QRect &r = geometry(); | 164 | const QRect &r = geometry(); | ||
158 | if (m_contentFBO && r.size().isEmpty()) { | 165 | if (m_contentFBO && r.size().isEmpty()) { | ||
159 | return; | 166 | return; | ||
160 | } | 167 | } | ||
161 | m_contentFBO.reset(new QOpenGLFramebufferObject(r.width(), r.height(), QOpenGLFramebufferObject::CombinedDepthStencil)); | 168 | const QSize nativeSize = r.size() * m_scale; | ||
169 | m_contentFBO.reset(new QOpenGLFramebufferObject(nativeSize.width(), nativeSize.height(), QOpenGLFramebufferObject::CombinedDepthStencil)); | ||||
162 | if (!m_contentFBO->isValid()) { | 170 | if (!m_contentFBO->isValid()) { | ||
163 | qCWarning(KWIN_QPA) << "Content FBO is not valid"; | 171 | qCWarning(KWIN_QPA) << "Content FBO is not valid"; | ||
164 | } | 172 | } | ||
165 | m_resized = false; | 173 | m_resized = false; | ||
166 | } | 174 | } | ||
167 | 175 | | |||
168 | ShellClient *Window::shellClient() | 176 | ShellClient *Window::shellClient() | ||
169 | { | 177 | { | ||
170 | if (!m_shellClient) { | 178 | if (!m_shellClient) { | ||
171 | waylandServer()->dispatch(); | 179 | waylandServer()->dispatch(); | ||
172 | m_shellClient = waylandServer()->findClient(window()); | 180 | m_shellClient = waylandServer()->findClient(window()); | ||
173 | } | 181 | } | ||
174 | return m_shellClient; | 182 | return m_shellClient; | ||
175 | } | 183 | } | ||
176 | 184 | | |||
185 | int Window::scale() const | ||||
186 | { | ||||
187 | return m_scale; | ||||
188 | } | ||||
189 | | ||||
190 | qreal Window::devicePixelRatio() const | ||||
191 | { | ||||
192 | return m_scale; | ||||
193 | } | ||||
194 | | ||||
177 | } | 195 | } | ||
178 | } | 196 | } |
Should it be floored or rounded?