File indexing completed on 2025-04-20 10:57:36
0001 /* 0002 KWin - the KDE window manager 0003 This file is part of the KDE project. 0004 0005 SPDX-FileCopyrightText: 2015 Martin Gräßlin <mgraesslin@kde.org> 0006 SPDX-FileCopyrightText: 2019 Vlad Zahorodnii <vlad.zahorodnii@kde.org> 0007 0008 SPDX-License-Identifier: GPL-2.0-or-later 0009 */ 0010 #pragma once 0011 0012 #include <memory> 0013 #include <xf86drm.h> 0014 #include <xf86drmMode.h> 0015 0016 namespace KWin 0017 { 0018 0019 template<typename T> 0020 struct DrmDeleter; 0021 0022 template<> 0023 struct DrmDeleter<drmVersion> 0024 { 0025 void operator()(drmVersion *version) 0026 { 0027 drmFreeVersion(version); 0028 } 0029 }; 0030 0031 template<> 0032 struct DrmDeleter<drmModeAtomicReq> 0033 { 0034 void operator()(drmModeAtomicReq *req) 0035 { 0036 drmModeAtomicFree(req); 0037 } 0038 }; 0039 0040 template<> 0041 struct DrmDeleter<drmModeConnector> 0042 { 0043 void operator()(drmModeConnector *connector) 0044 { 0045 drmModeFreeConnector(connector); 0046 } 0047 }; 0048 0049 template<> 0050 struct DrmDeleter<drmModeCrtc> 0051 { 0052 void operator()(drmModeCrtc *crtc) 0053 { 0054 drmModeFreeCrtc(crtc); 0055 } 0056 }; 0057 0058 template<> 0059 struct DrmDeleter<drmModeFB> 0060 { 0061 void operator()(drmModeFB *fb) 0062 { 0063 drmModeFreeFB(fb); 0064 } 0065 }; 0066 0067 template<> 0068 struct DrmDeleter<drmModeEncoder> 0069 { 0070 void operator()(drmModeEncoder *encoder) 0071 { 0072 drmModeFreeEncoder(encoder); 0073 } 0074 }; 0075 0076 template<> 0077 struct DrmDeleter<drmModeModeInfo> 0078 { 0079 void operator()(drmModeModeInfo *info) 0080 { 0081 drmModeFreeModeInfo(info); 0082 } 0083 }; 0084 0085 template<> 0086 struct DrmDeleter<drmModeObjectProperties> 0087 { 0088 void operator()(drmModeObjectProperties *properties) 0089 { 0090 drmModeFreeObjectProperties(properties); 0091 } 0092 }; 0093 0094 template<> 0095 struct DrmDeleter<drmModePlane> 0096 { 0097 void operator()(drmModePlane *plane) 0098 { 0099 drmModeFreePlane(plane); 0100 } 0101 }; 0102 0103 template<> 0104 struct DrmDeleter<drmModePlaneRes> 0105 { 0106 void operator()(drmModePlaneRes *resources) 0107 { 0108 drmModeFreePlaneResources(resources); 0109 } 0110 }; 0111 0112 template<> 0113 struct DrmDeleter<drmModePropertyRes> 0114 { 0115 void operator()(drmModePropertyRes *property) 0116 { 0117 drmModeFreeProperty(property); 0118 } 0119 }; 0120 0121 template<> 0122 struct DrmDeleter<drmModePropertyBlobRes> 0123 { 0124 void operator()(drmModePropertyBlobRes *blob) 0125 { 0126 drmModeFreePropertyBlob(blob); 0127 } 0128 }; 0129 0130 template<> 0131 struct DrmDeleter<drmModeRes> 0132 { 0133 void operator()(drmModeRes *resources) 0134 { 0135 drmModeFreeResources(resources); 0136 } 0137 }; 0138 0139 template<> 0140 struct DrmDeleter<drmModeLesseeListRes> 0141 { 0142 void operator()(drmModeLesseeListRes *ptr) 0143 { 0144 drmFree(ptr); 0145 } 0146 }; 0147 0148 template<typename T> 0149 using DrmUniquePtr = std::unique_ptr<T, DrmDeleter<T>>; 0150 }