[platforms/drm] Rework ScopedDrmPointer
Summary: Currently there is no any good reason for keeping ScopedDrmPointer; providing our own deleter for QScopedPointer would make more sense. Given that we already have type that acts as a scoped pointer for drm objects we can improve it a bit and make simpler, e.g. DrmScopedPointer<drmModeConnector> connector; is much simpler than ScopedDrmPointer<_drmModeConnector, &drmModeFreeConnector> connector; Reviewers: #kwin, davidedmundson Reviewed By: #kwin, davidedmundson Subscribers: apol, kwin Tags: #kwin Differential Revision: https://phabricator.kde.org/D19905
This commit is contained in:
parent
efc62941ee
commit
02a5a08a6c
8 changed files with 131 additions and 24 deletions
|
@ -278,7 +278,7 @@ void DrmBackend::openDrm()
|
|||
qCDebug(KWIN_DRM) << "Using Atomic Mode Setting.";
|
||||
m_atomicModeSetting = true;
|
||||
|
||||
ScopedDrmPointer<drmModePlaneRes, &drmModeFreePlaneResources> planeResources(drmModeGetPlaneResources(m_fd));
|
||||
DrmScopedPointer<drmModePlaneRes> 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<drmModeRes> 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<drmModeRes> 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<drmModeConnector> connector(drmModeGetConnector(m_fd, con->id()));
|
||||
if (!connector) {
|
||||
continue;
|
||||
}
|
||||
|
@ -430,7 +430,7 @@ void DrmBackend::updateOutputs()
|
|||
|
||||
QVector<uint32_t> encoders = con->encoders();
|
||||
for (auto encId : qAsConst(encoders)) {
|
||||
ScopedDrmPointer<_drmModeEncoder, &drmModeFreeEncoder> encoder(drmModeGetEncoder(m_fd, encId));
|
||||
DrmScopedPointer<drmModeEncoder> 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<drmModeCrtc> modeCrtc(drmModeGetCrtc(m_fd, crtc->id()));
|
||||
if (!modeCrtc) {
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ void DrmObject::setPropertyNames(QVector<QByteArray> &&vector)
|
|||
void DrmObject::initProp(int n, drmModeObjectProperties *properties, QVector<QByteArray> enumNames)
|
||||
{
|
||||
for (unsigned int i = 0; i < properties->count_props; ++i) {
|
||||
ScopedDrmPointer<drmModePropertyRes, drmModeFreeProperty> prop(
|
||||
DrmScopedPointer<drmModePropertyRes> prop(
|
||||
drmModeGetProperty(fd(), properties->props[i]));
|
||||
if (!prop) {
|
||||
continue;
|
||||
|
|
|
@ -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<drmModeConnector> con(drmModeGetConnector(fd, connector_id));
|
||||
if (!con) {
|
||||
return;
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ bool DrmConnector::initProps()
|
|||
QByteArrayLiteral("CRTC_ID"),
|
||||
});
|
||||
|
||||
ScopedDrmPointer<drmModeObjectProperties, drmModeFreeObjectProperties> properties(
|
||||
DrmScopedPointer<drmModeObjectProperties> 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<drmModeConnector> con(drmModeGetConnector(fd(), m_id));
|
||||
if (!con) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -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<drmModeCrtc> modeCrtc(drmModeGetCrtc(backend->fd(), crtc_id));
|
||||
if (modeCrtc) {
|
||||
m_gammaRampSize = modeCrtc->gamma_size;
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ bool DrmCrtc::initProps()
|
|||
QByteArrayLiteral("ACTIVE"),
|
||||
});
|
||||
|
||||
ScopedDrmPointer<drmModeObjectProperties, drmModeFreeObjectProperties> properties(
|
||||
DrmScopedPointer<drmModeObjectProperties> properties(
|
||||
drmModeObjectGetProperties(fd(), m_id, DRM_MODE_OBJECT_CRTC));
|
||||
if (!properties) {
|
||||
qCWarning(KWIN_DRM) << "Failed to get properties for crtc " << m_id ;
|
||||
|
|
|
@ -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<drmModePlane> 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<drmModeObjectProperties, drmModeFreeObjectProperties> properties(
|
||||
DrmScopedPointer<drmModeObjectProperties> properties(
|
||||
drmModeObjectGetProperties(fd(), m_id, DRM_MODE_OBJECT_PLANE));
|
||||
if (!properties){
|
||||
qCWarning(KWIN_DRM) << "Failed to get properties for plane " << m_id ;
|
||||
|
|
|
@ -484,9 +484,9 @@ static QSize extractPhysicalSize(drmModePropertyBlobPtr edid)
|
|||
|
||||
void DrmOutput::initEdid(drmModeConnector *connector)
|
||||
{
|
||||
ScopedDrmPointer<_drmModePropertyBlob, &drmModeFreePropertyBlob> edid;
|
||||
DrmScopedPointer<drmModePropertyBlobRes> edid;
|
||||
for (int i = 0; i < connector->count_props; ++i) {
|
||||
ScopedDrmPointer<_drmModeProperty, &drmModeFreeProperty> property(drmModeGetProperty(m_backend->fd(), connector->props[i]));
|
||||
DrmScopedPointer<drmModePropertyRes> 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<drmModePropertyRes> 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<drmModeConnector> connector(drmModeGetConnector(m_backend->fd(), m_conn->id()));
|
||||
if (connector->count_modes <= modeIndex) {
|
||||
// TODO: error?
|
||||
return;
|
||||
|
|
|
@ -135,7 +135,7 @@ private:
|
|||
bool m_lastGbm = false;
|
||||
drmModeModeInfo m_mode;
|
||||
Edid m_edid;
|
||||
KWin::ScopedDrmPointer<_drmModeProperty, &drmModeFreeProperty> m_dpms;
|
||||
DrmScopedPointer<drmModePropertyRes> m_dpms;
|
||||
DpmsMode m_dpmsMode = DpmsMode::On;
|
||||
DpmsMode m_dpmsModePending = DpmsMode::On;
|
||||
QByteArray m_uuid;
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
This file is part of the KDE project.
|
||||
|
||||
Copyright (C) 2015 Martin Gräßlin <mgraesslin@kde.org>
|
||||
Copyright (C) 2019 Vlad Zagorodniy <vladzzag@gmail.com>
|
||||
|
||||
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 <http://www.gnu.org/licenses/>.
|
|||
|
||||
#include <QScopedPointer>
|
||||
|
||||
#include <xf86drmMode.h>
|
||||
|
||||
namespace KWin
|
||||
{
|
||||
|
||||
template <typename Pointer, void (*cleanupFunc)(Pointer*)>
|
||||
struct DrmCleanup
|
||||
template <typename T>
|
||||
struct DrmDeleter;
|
||||
|
||||
template <>
|
||||
struct DrmDeleter<drmModeAtomicReq>
|
||||
{
|
||||
static inline void cleanup(Pointer *ptr)
|
||||
static void cleanup(drmModeAtomicReq *req)
|
||||
{
|
||||
cleanupFunc(ptr);
|
||||
drmModeAtomicFree(req);
|
||||
}
|
||||
};
|
||||
template <typename T, void (*cleanupFunc)(T*)> using ScopedDrmPointer = QScopedPointer<T, DrmCleanup<T, cleanupFunc>>;
|
||||
|
||||
template <>
|
||||
struct DrmDeleter<drmModeConnector>
|
||||
{
|
||||
static void cleanup(drmModeConnector *connector)
|
||||
{
|
||||
drmModeFreeConnector(connector);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct DrmDeleter<drmModeCrtc>
|
||||
{
|
||||
static void cleanup(drmModeCrtc *crtc)
|
||||
{
|
||||
drmModeFreeCrtc(crtc);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct DrmDeleter<drmModeFB>
|
||||
{
|
||||
static void cleanup(drmModeFB *fb)
|
||||
{
|
||||
drmModeFreeFB(fb);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct DrmDeleter<drmModeEncoder>
|
||||
{
|
||||
static void cleanup(drmModeEncoder *encoder)
|
||||
{
|
||||
drmModeFreeEncoder(encoder);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct DrmDeleter<drmModeModeInfo>
|
||||
{
|
||||
static void cleanup(drmModeModeInfo *info)
|
||||
{
|
||||
drmModeFreeModeInfo(info);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct DrmDeleter<drmModeObjectProperties>
|
||||
{
|
||||
static void cleanup(drmModeObjectProperties *properties)
|
||||
{
|
||||
drmModeFreeObjectProperties(properties);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct DrmDeleter<drmModePlane>
|
||||
{
|
||||
static void cleanup(drmModePlane *plane)
|
||||
{
|
||||
drmModeFreePlane(plane);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct DrmDeleter<drmModePlaneRes>
|
||||
{
|
||||
static void cleanup(drmModePlaneRes *resources)
|
||||
{
|
||||
drmModeFreePlaneResources(resources);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct DrmDeleter<drmModePropertyRes>
|
||||
{
|
||||
static void cleanup(drmModePropertyRes *property)
|
||||
{
|
||||
drmModeFreeProperty(property);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct DrmDeleter<drmModePropertyBlobRes>
|
||||
{
|
||||
static void cleanup(drmModePropertyBlobRes *blob)
|
||||
{
|
||||
drmModeFreePropertyBlob(blob);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct DrmDeleter<drmModeRes>
|
||||
{
|
||||
static void cleanup(drmModeRes *resources)
|
||||
{
|
||||
drmModeFreeResources(resources);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
using DrmScopedPointer = QScopedPointer<T, DrmDeleter<T>>;
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue