KWin
Loading...
Searching...
No Matches
tearingcontrol_v1.cpp
Go to the documentation of this file.
1/*
2 SPDX-FileCopyrightText: 2022 Xaver Hugl <xaver.hugl@gmail.com>
3
4 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5*/
6#include "tearingcontrol_v1.h"
7#include "display.h"
8#include "surface_p.h"
9
10namespace KWin
11{
12
13static constexpr uint32_t s_version = 1;
14
15class TearingControlManagerV1InterfacePrivate : public QtWaylandServer::wp_tearing_control_manager_v1
16{
17public:
19
20private:
21 void wp_tearing_control_manager_v1_destroy(Resource *resource) override;
22 void wp_tearing_control_manager_v1_get_tearing_control(Resource *resource, uint32_t id, struct ::wl_resource *surface) override;
23};
24
25class TearingControlV1Interface : private QtWaylandServer::wp_tearing_control_v1
26{
27public:
28 TearingControlV1Interface(SurfaceInterface *surface, wl_client *client, uint32_t id);
30
31private:
32 void wp_tearing_control_v1_set_presentation_hint(Resource *resource, uint32_t hint) override;
33 void wp_tearing_control_v1_destroy(Resource *resource) override;
34 void wp_tearing_control_v1_destroy_resource(Resource *resource) override;
35
36 const QPointer<SurfaceInterface> m_surface;
37};
38
40 : QObject(parent)
42{
43}
44
46
48 : QtWaylandServer::wp_tearing_control_manager_v1(*display, s_version)
49{
50}
51
52void TearingControlManagerV1InterfacePrivate::wp_tearing_control_manager_v1_destroy(Resource *resource)
53{
54 wl_resource_destroy(resource->handle);
55}
56
57void TearingControlManagerV1InterfacePrivate::wp_tearing_control_manager_v1_get_tearing_control(Resource *resource, uint32_t id, struct ::wl_resource *wlSurface)
58{
59 SurfaceInterface *surface = SurfaceInterface::get(wlSurface);
60 if (SurfaceInterfacePrivate::get(surface)->tearing) {
61 wl_resource_post_error(resource->handle, QtWaylandServer::wp_tearing_control_manager_v1::error_tearing_control_exists, "Surface already has a wp_surface_tearing_control_v1");
62 return;
63 }
64 SurfaceInterfacePrivate::get(surface)->tearing = new TearingControlV1Interface(surface, resource->client(), id);
65}
66
68 : QtWaylandServer::wp_tearing_control_v1(client, id, s_version)
69 , m_surface(surface)
70{
71}
72
74{
75 if (m_surface) {
76 SurfaceInterfacePrivate *surfacePrivate = SurfaceInterfacePrivate::get(m_surface);
77 surfacePrivate->pending->presentationHint = PresentationModeHint::VSync;
78 surfacePrivate->pending->presentationModeHintIsSet = true;
79 surfacePrivate->tearing = nullptr;
80 }
81}
82
83void TearingControlV1Interface::wp_tearing_control_v1_set_presentation_hint(Resource *resource, uint32_t hint)
84{
85 if (m_surface) {
86 SurfaceInterfacePrivate *surfacePrivate = SurfaceInterfacePrivate::get(m_surface);
87 if (hint == presentation_hint::presentation_hint_async) {
88 surfacePrivate->pending->presentationHint = PresentationModeHint::Async;
89 } else {
90 surfacePrivate->pending->presentationHint = PresentationModeHint::VSync;
91 }
92 surfacePrivate->pending->presentationModeHintIsSet = true;
93 }
94}
95
96void TearingControlV1Interface::wp_tearing_control_v1_destroy(Resource *resource)
97{
98 wl_resource_destroy(resource->handle);
99}
100
101void TearingControlV1Interface::wp_tearing_control_v1_destroy_resource(Resource *resource)
102{
103 delete this;
104}
105}
106
107#include "moc_tearingcontrol_v1.cpp"
Class holding the Wayland server display loop.
Definition display.h:34
Resource representing a wl_surface.
Definition surface.h:80
static SurfaceInterface * get(wl_resource *native)
Definition surface.cpp:819
std::unique_ptr< SurfaceState > pending
Definition surface_p.h:137
static SurfaceInterfacePrivate * get(SurfaceInterface *surface)
Definition surface_p.h:99
TearingControlV1Interface * tearing
Definition surface_p.h:170
TearingControlManagerV1Interface(Display *display, QObject *parent=nullptr)
TearingControlV1Interface(SurfaceInterface *surface, wl_client *client, uint32_t id)