diff --git a/plugins/platforms/drm/drm_backend.cpp b/plugins/platforms/drm/drm_backend.cpp index 32b2384294..4f07d8c4cb 100644 --- a/plugins/platforms/drm/drm_backend.cpp +++ b/plugins/platforms/drm/drm_backend.cpp @@ -278,7 +278,7 @@ void DrmBackend::openDrm() qCDebug(KWIN_DRM) << "Using Atomic Mode Setting."; m_atomicModeSetting = true; - ScopedDrmPointer planeResources(drmModeGetPlaneResources(m_fd)); + DrmScopedPointer planeResources(drmModeGetPlaneResources(m_fd)); if (!planeResources) { qCWarning(KWIN_DRM) << "Failed to get plane resources. Falling back to legacy mode"; m_atomicModeSetting = false; @@ -311,7 +311,7 @@ void DrmBackend::openDrm() } } - ScopedDrmPointer<_drmModeRes, &drmModeFreeResources> resources(drmModeGetResources(m_fd)); + DrmScopedPointer resources(drmModeGetResources(m_fd)); drmModeRes *res = resources.data(); if (!resources) { qCWarning(KWIN_DRM) << "drmModeGetResources failed"; @@ -381,7 +381,7 @@ void DrmBackend::updateOutputs() return; } - ScopedDrmPointer<_drmModeRes, &drmModeFreeResources> resources(drmModeGetResources(m_fd)); + DrmScopedPointer resources(drmModeGetResources(m_fd)); if (!resources) { qCWarning(KWIN_DRM) << "drmModeGetResources failed"; return; @@ -419,7 +419,7 @@ void DrmBackend::updateOutputs() // now check new connections for (DrmConnector *con : qAsConst(pendingConnectors)) { - ScopedDrmPointer<_drmModeConnector, &drmModeFreeConnector> connector(drmModeGetConnector(m_fd, con->id())); + DrmScopedPointer connector(drmModeGetConnector(m_fd, con->id())); if (!connector) { continue; } @@ -430,7 +430,7 @@ void DrmBackend::updateOutputs() QVector encoders = con->encoders(); for (auto encId : qAsConst(encoders)) { - ScopedDrmPointer<_drmModeEncoder, &drmModeFreeEncoder> encoder(drmModeGetEncoder(m_fd, encId)); + DrmScopedPointer encoder(drmModeGetEncoder(m_fd, encId)); if (!encoder) { continue; } @@ -451,7 +451,7 @@ void DrmBackend::updateOutputs() // we found a suitable encoder+crtc // TODO: we could avoid these lib drm calls if we store all struct data in DrmCrtc and DrmConnector in the beginning - ScopedDrmPointer<_drmModeCrtc, &drmModeFreeCrtc> modeCrtc(drmModeGetCrtc(m_fd, crtc->id())); + DrmScopedPointer modeCrtc(drmModeGetCrtc(m_fd, crtc->id())); if (!modeCrtc) { continue; } diff --git a/plugins/platforms/drm/drm_object.cpp b/plugins/platforms/drm/drm_object.cpp index 1932bf76e8..b7fb77d918 100644 --- a/plugins/platforms/drm/drm_object.cpp +++ b/plugins/platforms/drm/drm_object.cpp @@ -50,7 +50,7 @@ void DrmObject::setPropertyNames(QVector &&vector) void DrmObject::initProp(int n, drmModeObjectProperties *properties, QVector enumNames) { for (unsigned int i = 0; i < properties->count_props; ++i) { - ScopedDrmPointer prop( + DrmScopedPointer prop( drmModeGetProperty(fd(), properties->props[i])); if (!prop) { continue; diff --git a/plugins/platforms/drm/drm_object_connector.cpp b/plugins/platforms/drm/drm_object_connector.cpp index 27acff4310..146770fc55 100644 --- a/plugins/platforms/drm/drm_object_connector.cpp +++ b/plugins/platforms/drm/drm_object_connector.cpp @@ -27,7 +27,7 @@ namespace KWin DrmConnector::DrmConnector(uint32_t connector_id, int fd) : DrmObject(connector_id, fd) { - ScopedDrmPointer<_drmModeConnector, &drmModeFreeConnector> con(drmModeGetConnector(fd, connector_id)); + DrmScopedPointer con(drmModeGetConnector(fd, connector_id)); if (!con) { return; } @@ -54,7 +54,7 @@ bool DrmConnector::initProps() QByteArrayLiteral("CRTC_ID"), }); - ScopedDrmPointer properties( + DrmScopedPointer properties( drmModeObjectGetProperties(fd(), m_id, DRM_MODE_OBJECT_CONNECTOR)); if (!properties) { qCWarning(KWIN_DRM) << "Failed to get properties for connector " << m_id ; @@ -71,7 +71,7 @@ bool DrmConnector::initProps() bool DrmConnector::isConnected() { - ScopedDrmPointer<_drmModeConnector, &drmModeFreeConnector> con(drmModeGetConnector(fd(), m_id)); + DrmScopedPointer con(drmModeGetConnector(fd(), m_id)); if (!con) { return false; } diff --git a/plugins/platforms/drm/drm_object_crtc.cpp b/plugins/platforms/drm/drm_object_crtc.cpp index 341d80a074..245734fd0a 100644 --- a/plugins/platforms/drm/drm_object_crtc.cpp +++ b/plugins/platforms/drm/drm_object_crtc.cpp @@ -33,7 +33,7 @@ DrmCrtc::DrmCrtc(uint32_t crtc_id, DrmBackend *backend, int resIndex) m_resIndex(resIndex), m_backend(backend) { - ScopedDrmPointer<_drmModeCrtc, &drmModeFreeCrtc> modeCrtc(drmModeGetCrtc(backend->fd(), crtc_id)); + DrmScopedPointer modeCrtc(drmModeGetCrtc(backend->fd(), crtc_id)); if (modeCrtc) { m_gammaRampSize = modeCrtc->gamma_size; } @@ -60,7 +60,7 @@ bool DrmCrtc::initProps() QByteArrayLiteral("ACTIVE"), }); - ScopedDrmPointer properties( + DrmScopedPointer properties( drmModeObjectGetProperties(fd(), m_id, DRM_MODE_OBJECT_CRTC)); if (!properties) { qCWarning(KWIN_DRM) << "Failed to get properties for crtc " << m_id ; diff --git a/plugins/platforms/drm/drm_object_plane.cpp b/plugins/platforms/drm/drm_object_plane.cpp index 19d8abaa9d..d3ce080272 100644 --- a/plugins/platforms/drm/drm_object_plane.cpp +++ b/plugins/platforms/drm/drm_object_plane.cpp @@ -39,7 +39,7 @@ DrmPlane::~DrmPlane() bool DrmPlane::atomicInit() { qCDebug(KWIN_DRM) << "Atomic init for plane:" << m_id; - ScopedDrmPointer<_drmModePlane, &drmModeFreePlane> p(drmModeGetPlane(fd(), m_id)); + DrmScopedPointer p(drmModeGetPlane(fd(), m_id)); if (!p) { qCWarning(KWIN_DRM) << "Failed to get kernel plane" << m_id; @@ -92,7 +92,7 @@ bool DrmPlane::initProps() QByteArrayLiteral("reflect-y") }; - ScopedDrmPointer properties( + DrmScopedPointer properties( drmModeObjectGetProperties(fd(), m_id, DRM_MODE_OBJECT_PLANE)); if (!properties){ qCWarning(KWIN_DRM) << "Failed to get properties for plane " << m_id ; diff --git a/plugins/platforms/drm/drm_output.cpp b/plugins/platforms/drm/drm_output.cpp index 825e69c94c..5c049ce5d5 100644 --- a/plugins/platforms/drm/drm_output.cpp +++ b/plugins/platforms/drm/drm_output.cpp @@ -484,9 +484,9 @@ static QSize extractPhysicalSize(drmModePropertyBlobPtr edid) void DrmOutput::initEdid(drmModeConnector *connector) { - ScopedDrmPointer<_drmModePropertyBlob, &drmModeFreePropertyBlob> edid; + DrmScopedPointer edid; for (int i = 0; i < connector->count_props; ++i) { - ScopedDrmPointer<_drmModeProperty, &drmModeFreeProperty> property(drmModeGetProperty(m_backend->fd(), connector->props[i])); + DrmScopedPointer property(drmModeGetProperty(m_backend->fd(), connector->props[i])); if (!property) { continue; } @@ -587,7 +587,7 @@ bool DrmOutput::initCursor(const QSize &cursorSize) void DrmOutput::initDpms(drmModeConnector *connector) { for (int i = 0; i < connector->count_props; ++i) { - ScopedDrmPointer<_drmModeProperty, &drmModeFreeProperty> property(drmModeGetProperty(m_backend->fd(), connector->props[i])); + DrmScopedPointer property(drmModeGetProperty(m_backend->fd(), connector->props[i])); if (!property) { continue; } @@ -788,7 +788,7 @@ void DrmOutput::transform(KWayland::Server::OutputDeviceInterface::Transform tra void DrmOutput::updateMode(int modeIndex) { // get all modes on the connector - ScopedDrmPointer<_drmModeConnector, &drmModeFreeConnector> connector(drmModeGetConnector(m_backend->fd(), m_conn->id())); + DrmScopedPointer connector(drmModeGetConnector(m_backend->fd(), m_conn->id())); if (connector->count_modes <= modeIndex) { // TODO: error? return; diff --git a/plugins/platforms/drm/drm_output.h b/plugins/platforms/drm/drm_output.h index bcf438c795..de3e75699f 100644 --- a/plugins/platforms/drm/drm_output.h +++ b/plugins/platforms/drm/drm_output.h @@ -135,7 +135,7 @@ private: bool m_lastGbm = false; drmModeModeInfo m_mode; Edid m_edid; - KWin::ScopedDrmPointer<_drmModeProperty, &drmModeFreeProperty> m_dpms; + DrmScopedPointer m_dpms; DpmsMode m_dpmsMode = DpmsMode::On; DpmsMode m_dpmsModePending = DpmsMode::On; QByteArray m_uuid; diff --git a/plugins/platforms/drm/drm_pointer.h b/plugins/platforms/drm/drm_pointer.h index a6ec477511..3c0aea0d0d 100644 --- a/plugins/platforms/drm/drm_pointer.h +++ b/plugins/platforms/drm/drm_pointer.h @@ -3,6 +3,7 @@ This file is part of the KDE project. Copyright (C) 2015 Martin Gräßlin +Copyright (C) 2019 Vlad Zagorodniy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -22,18 +23,124 @@ along with this program. If not, see . #include +#include + namespace KWin { -template -struct DrmCleanup +template +struct DrmDeleter; + +template <> +struct DrmDeleter { - static inline void cleanup(Pointer *ptr) + static void cleanup(drmModeAtomicReq *req) { - cleanupFunc(ptr); + drmModeAtomicFree(req); } }; -template using ScopedDrmPointer = QScopedPointer>; + +template <> +struct DrmDeleter +{ + static void cleanup(drmModeConnector *connector) + { + drmModeFreeConnector(connector); + } +}; + +template <> +struct DrmDeleter +{ + static void cleanup(drmModeCrtc *crtc) + { + drmModeFreeCrtc(crtc); + } +}; + +template <> +struct DrmDeleter +{ + static void cleanup(drmModeFB *fb) + { + drmModeFreeFB(fb); + } +}; + +template <> +struct DrmDeleter +{ + static void cleanup(drmModeEncoder *encoder) + { + drmModeFreeEncoder(encoder); + } +}; + +template <> +struct DrmDeleter +{ + static void cleanup(drmModeModeInfo *info) + { + drmModeFreeModeInfo(info); + } +}; + +template <> +struct DrmDeleter +{ + static void cleanup(drmModeObjectProperties *properties) + { + drmModeFreeObjectProperties(properties); + } +}; + +template <> +struct DrmDeleter +{ + static void cleanup(drmModePlane *plane) + { + drmModeFreePlane(plane); + } +}; + +template <> +struct DrmDeleter +{ + static void cleanup(drmModePlaneRes *resources) + { + drmModeFreePlaneResources(resources); + } +}; + +template <> +struct DrmDeleter +{ + static void cleanup(drmModePropertyRes *property) + { + drmModeFreeProperty(property); + } +}; + +template <> +struct DrmDeleter +{ + static void cleanup(drmModePropertyBlobRes *blob) + { + drmModeFreePropertyBlob(blob); + } +}; + +template <> +struct DrmDeleter +{ + static void cleanup(drmModeRes *resources) + { + drmModeFreeResources(resources); + } +}; + +template +using DrmScopedPointer = QScopedPointer>; }