Directory: | ./ |
---|---|
File: | server/linux_dmabuf_v1.h |
Date: | 2024-01-22 17:25:27 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 15 | 15 | 100.0% |
Branches: | 4 | 6 | 66.7% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | /******************************************************************** | ||
2 | Copyright © 2018 Fredrik Höglund <fredrik@kde.org> | ||
3 | Copyright © 2019-2020 Roman Gilg <subdiff@gmail.com> | ||
4 | |||
5 | This library is free software; you can redistribute it and/or | ||
6 | modify it under the terms of the GNU Lesser General Public | ||
7 | License as published by the Free Software Foundation; either | ||
8 | version 2.1 of the License, or (at your option) version 3, or any | ||
9 | later version accepted by the membership of KDE e.V. (or its | ||
10 | successor approved by the membership of KDE e.V.), which shall | ||
11 | act as a proxy defined in Section 6 of version 3 of the license. | ||
12 | |||
13 | This library is distributed in the hope that it will be useful, | ||
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
16 | Lesser General Public License for more details. | ||
17 | |||
18 | You should have received a copy of the GNU Lesser General Public | ||
19 | License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
20 | *********************************************************************/ | ||
21 | #pragma once | ||
22 | |||
23 | #include <Wrapland/Server/wraplandserver_export.h> | ||
24 | |||
25 | #include <QObject> | ||
26 | #include <QSize> | ||
27 | |||
28 | #include <functional> | ||
29 | #include <memory> | ||
30 | #include <unistd.h> | ||
31 | #include <unordered_set> | ||
32 | #include <vector> | ||
33 | |||
34 | namespace Wrapland::Server | ||
35 | { | ||
36 | |||
37 | class Buffer; | ||
38 | class Display; | ||
39 | |||
40 | struct drm_format { | ||
41 | uint32_t format; | ||
42 | std::unordered_set<uint64_t> modifiers; | ||
43 | }; | ||
44 | |||
45 | enum class linux_dmabuf_flag_v1 { | ||
46 | y_inverted = 0x1, | ||
47 | interlaced = 0x2, | ||
48 | bottom_field_first = 0x4, | ||
49 | }; | ||
50 | |||
51 | Q_DECLARE_FLAGS(linux_dmabuf_flags_v1, linux_dmabuf_flag_v1) | ||
52 | |||
53 | struct linux_dmabuf_plane_v1 { | ||
54 | int fd; | ||
55 | uint32_t offset; | ||
56 | uint32_t stride; | ||
57 | }; | ||
58 | |||
59 | class linux_dmabuf_buffer_v1 | ||
60 | { | ||
61 | public: | ||
62 | 1 | linux_dmabuf_buffer_v1(std::vector<linux_dmabuf_plane_v1> planes, | |
63 | uint32_t format, | ||
64 | uint64_t modifier, | ||
65 | QSize const& size, | ||
66 | linux_dmabuf_flags_v1 flags) | ||
67 | 1 | : planes{std::move(planes)} | |
68 | 1 | , format{format} | |
69 | 1 | , modifier{modifier} | |
70 | 1 | , size{size} | |
71 | 1 | , flags{flags} | |
72 | 1 | { | |
73 | 1 | } | |
74 | 2 | virtual ~linux_dmabuf_buffer_v1() | |
75 | 2 | { | |
76 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 | for (auto& plane : planes) { |
77 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (plane.fd != -1) { |
78 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | ::close(plane.fd); |
79 | 1 | } | |
80 | } | ||
81 | 2 | } | |
82 | |||
83 | std::vector<linux_dmabuf_plane_v1> planes; | ||
84 | uint32_t format; | ||
85 | uint64_t modifier; | ||
86 | QSize size; | ||
87 | linux_dmabuf_flags_v1 flags; | ||
88 | }; | ||
89 | |||
90 | using linux_dmabuf_import_v1 = std::function<std::unique_ptr<linux_dmabuf_buffer_v1>( | ||
91 | std::vector<linux_dmabuf_plane_v1> const& planes, | ||
92 | uint32_t format, | ||
93 | uint64_t modifier, | ||
94 | QSize const& size, | ||
95 | linux_dmabuf_flags_v1 flags)>; | ||
96 | |||
97 | class WRAPLANDSERVER_EXPORT linux_dmabuf_v1 : public QObject | ||
98 | { | ||
99 | Q_OBJECT | ||
100 | public: | ||
101 | linux_dmabuf_v1(Display* display, linux_dmabuf_import_v1 import); | ||
102 | ~linux_dmabuf_v1() override; | ||
103 | |||
104 | void set_formats(std::vector<drm_format> const& formats); | ||
105 | |||
106 | private: | ||
107 | friend class Buffer; | ||
108 | friend class linux_dmabuf_params_v1; | ||
109 | friend class linux_dmabuf_params_v1_impl; | ||
110 | |||
111 | class Private; | ||
112 | std::unique_ptr<Private> d_ptr; | ||
113 | }; | ||
114 | |||
115 | } | ||
116 | |||
117 | Q_DECLARE_METATYPE(Wrapland::Server::linux_dmabuf_v1*) | ||
118 | Q_DECLARE_OPERATORS_FOR_FLAGS(Wrapland::Server::linux_dmabuf_flags_v1) | ||
119 |