Changeset View
Changeset View
Standalone View
Standalone View
plugins/platforms/drm/drm_pointer.h
1 | /******************************************************************** | 1 | /******************************************************************** | ||
---|---|---|---|---|---|
2 | KWin - the KDE window manager | 2 | KWin - the KDE window manager | ||
3 | This file is part of the KDE project. | 3 | This file is part of the KDE project. | ||
4 | 4 | | |||
5 | Copyright (C) 2015 Martin Gräßlin <mgraesslin@kde.org> | 5 | Copyright (C) 2015 Martin Gräßlin <mgraesslin@kde.org> | ||
6 | Copyright (C) 2019 Vlad Zagorodniy <vladzzag@gmail.com> | ||||
6 | 7 | | |||
7 | This program is free software; you can redistribute it and/or modify | 8 | This program is free software; you can redistribute it and/or modify | ||
8 | it under the terms of the GNU General Public License as published by | 9 | it under the terms of the GNU General Public License as published by | ||
9 | the Free Software Foundation; either version 2 of the License, or | 10 | the Free Software Foundation; either version 2 of the License, or | ||
10 | (at your option) any later version. | 11 | (at your option) any later version. | ||
11 | 12 | | |||
12 | This program is distributed in the hope that it will be useful, | 13 | This program is distributed in the hope that it will be useful, | ||
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | GNU General Public License for more details. | 16 | GNU General Public License for more details. | ||
16 | 17 | | |||
17 | You should have received a copy of the GNU General Public License | 18 | 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/>. | 19 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
19 | *********************************************************************/ | 20 | *********************************************************************/ | ||
20 | #ifndef KWIN_DRM_POINTER_H | 21 | #ifndef KWIN_DRM_POINTER_H | ||
21 | #define KWIN_DRM_POINTER_H | 22 | #define KWIN_DRM_POINTER_H | ||
22 | 23 | | |||
23 | #include <QScopedPointer> | 24 | #include <QScopedPointer> | ||
24 | 25 | | |||
26 | #include <xf86drmMode.h> | ||||
27 | | ||||
25 | namespace KWin | 28 | namespace KWin | ||
26 | { | 29 | { | ||
27 | 30 | | |||
28 | template <typename Pointer, void (*cleanupFunc)(Pointer*)> | 31 | template <typename T> | ||
29 | struct DrmCleanup | 32 | struct DrmDeleter; | ||
33 | | ||||
34 | template <> | ||||
35 | struct DrmDeleter<drmModeAtomicReq> | ||||
36 | { | ||||
37 | static void cleanup(drmModeAtomicReq *req) | ||||
38 | { | ||||
39 | drmModeAtomicFree(req); | ||||
40 | } | ||||
41 | }; | ||||
42 | | ||||
43 | template <> | ||||
44 | struct DrmDeleter<drmModeConnector> | ||||
45 | { | ||||
46 | static void cleanup(drmModeConnector *connector) | ||||
47 | { | ||||
48 | drmModeFreeConnector(connector); | ||||
49 | } | ||||
50 | }; | ||||
51 | | ||||
52 | template <> | ||||
53 | struct DrmDeleter<drmModeCrtc> | ||||
54 | { | ||||
55 | static void cleanup(drmModeCrtc *crtc) | ||||
56 | { | ||||
57 | drmModeFreeCrtc(crtc); | ||||
58 | } | ||||
59 | }; | ||||
60 | | ||||
61 | template <> | ||||
62 | struct DrmDeleter<drmModeFB> | ||||
63 | { | ||||
64 | static void cleanup(drmModeFB *fb) | ||||
65 | { | ||||
66 | drmModeFreeFB(fb); | ||||
67 | } | ||||
68 | }; | ||||
69 | | ||||
70 | template <> | ||||
71 | struct DrmDeleter<drmModeEncoder> | ||||
72 | { | ||||
73 | static void cleanup(drmModeEncoder *encoder) | ||||
74 | { | ||||
75 | drmModeFreeEncoder(encoder); | ||||
76 | } | ||||
77 | }; | ||||
78 | | ||||
79 | template <> | ||||
80 | struct DrmDeleter<drmModeModeInfo> | ||||
81 | { | ||||
82 | static void cleanup(drmModeModeInfo *info) | ||||
83 | { | ||||
84 | drmModeFreeModeInfo(info); | ||||
85 | } | ||||
86 | }; | ||||
87 | | ||||
88 | template <> | ||||
89 | struct DrmDeleter<drmModeObjectProperties> | ||||
90 | { | ||||
91 | static void cleanup(drmModeObjectProperties *properties) | ||||
92 | { | ||||
93 | drmModeFreeObjectProperties(properties); | ||||
94 | } | ||||
95 | }; | ||||
96 | | ||||
97 | template <> | ||||
98 | struct DrmDeleter<drmModePlane> | ||||
30 | { | 99 | { | ||
31 | static inline void cleanup(Pointer *ptr) | 100 | static void cleanup(drmModePlane *plane) | ||
32 | { | 101 | { | ||
33 | cleanupFunc(ptr); | 102 | drmModeFreePlane(plane); | ||
34 | } | 103 | } | ||
35 | }; | 104 | }; | ||
36 | template <typename T, void (*cleanupFunc)(T*)> using ScopedDrmPointer = QScopedPointer<T, DrmCleanup<T, cleanupFunc>>; | 105 | | ||
106 | template <> | ||||
107 | struct DrmDeleter<drmModePlaneRes> | ||||
108 | { | ||||
109 | static void cleanup(drmModePlaneRes *resources) | ||||
110 | { | ||||
111 | drmModeFreePlaneResources(resources); | ||||
112 | } | ||||
113 | }; | ||||
114 | | ||||
115 | template <> | ||||
116 | struct DrmDeleter<drmModePropertyRes> | ||||
117 | { | ||||
118 | static void cleanup(drmModePropertyRes *property) | ||||
119 | { | ||||
120 | drmModeFreeProperty(property); | ||||
121 | } | ||||
122 | }; | ||||
123 | | ||||
124 | template <> | ||||
125 | struct DrmDeleter<drmModePropertyBlobRes> | ||||
126 | { | ||||
127 | static void cleanup(drmModePropertyBlobRes *blob) | ||||
128 | { | ||||
129 | drmModeFreePropertyBlob(blob); | ||||
130 | } | ||||
131 | }; | ||||
132 | | ||||
133 | template <> | ||||
134 | struct DrmDeleter<drmModeRes> | ||||
135 | { | ||||
136 | static void cleanup(drmModeRes *resources) | ||||
137 | { | ||||
138 | drmModeFreeResources(resources); | ||||
139 | } | ||||
140 | }; | ||||
141 | | ||||
142 | template <typename T> | ||||
143 | using DrmScopedPointer = QScopedPointer<T, DrmDeleter<T>>; | ||||
37 | 144 | | |||
38 | } | 145 | } | ||
39 | 146 | | |||
40 | #endif | 147 | #endif | ||
41 | 148 | |