[platforms/drm] Use more ScopedDrmPointer

Test Plan: Standalone KWin/Wayland still works.

Reviewers: #kwin, graesslin

Reviewed By: #kwin, graesslin

Subscribers: kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D18863
icc-effect-5.17.5
Vlad Zagorodniy 2019-02-08 21:49:11 +02:00
parent 6006dab41c
commit 5047449a55
4 changed files with 18 additions and 14 deletions

View File

@ -18,6 +18,7 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
#include "drm_object.h"
#include "drm_pointer.h"
#include "logging.h"
@ -49,16 +50,16 @@ 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) {
drmModePropertyRes *prop = drmModeGetProperty(fd(), properties->props[i]);
ScopedDrmPointer<drmModePropertyRes, drmModeFreeProperty> prop(
drmModeGetProperty(fd(), properties->props[i]));
if (!prop) {
continue;
}
if (prop->name == m_propsNames[n]) {
qCDebug(KWIN_DRM).nospace() << m_id << ": " << prop->name << "' (id " << prop->prop_id
<< "): " << properties->prop_values[i];
m_props[n] = new Property(prop, properties->prop_values[i], enumNames);
m_props[n] = new Property(prop.data(), properties->prop_values[i], enumNames);
}
drmModeFreeProperty(prop);
}
}

View File

@ -54,7 +54,8 @@ bool DrmConnector::initProps()
QByteArrayLiteral("CRTC_ID"),
});
drmModeObjectProperties *properties = drmModeObjectGetProperties(fd(), m_id, DRM_MODE_OBJECT_CONNECTOR);
ScopedDrmPointer<drmModeObjectProperties, drmModeFreeObjectProperties> properties(
drmModeObjectGetProperties(fd(), m_id, DRM_MODE_OBJECT_CONNECTOR));
if (!properties) {
qCWarning(KWIN_DRM) << "Failed to get properties for connector " << m_id ;
return false;
@ -62,9 +63,9 @@ bool DrmConnector::initProps()
int propCount = int(PropertyIndex::Count);
for (int j = 0; j < propCount; ++j) {
initProp(j, properties);
initProp(j, properties.data());
}
drmModeFreeObjectProperties(properties);
return true;
}

View File

@ -21,6 +21,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "drm_backend.h"
#include "drm_output.h"
#include "drm_buffer.h"
#include "drm_pointer.h"
#include "logging.h"
#include <colorcorrection/gammaramp.h>
@ -59,7 +60,8 @@ bool DrmCrtc::initProps()
QByteArrayLiteral("ACTIVE"),
});
drmModeObjectProperties *properties = drmModeObjectGetProperties(fd(), m_id, DRM_MODE_OBJECT_CRTC);
ScopedDrmPointer<drmModeObjectProperties, drmModeFreeObjectProperties> properties(
drmModeObjectGetProperties(fd(), m_id, DRM_MODE_OBJECT_CRTC));
if (!properties) {
qCWarning(KWIN_DRM) << "Failed to get properties for crtc " << m_id ;
return false;
@ -67,9 +69,9 @@ bool DrmCrtc::initProps()
int propCount = int(PropertyIndex::Count);
for (int j = 0; j < propCount; ++j) {
initProp(j, properties);
initProp(j, properties.data());
}
drmModeFreeObjectProperties(properties);
return true;
}

View File

@ -92,7 +92,8 @@ bool DrmPlane::initProps()
QByteArrayLiteral("reflect-y")
};
drmModeObjectProperties *properties = drmModeObjectGetProperties(fd(), m_id, DRM_MODE_OBJECT_PLANE);
ScopedDrmPointer<drmModeObjectProperties, drmModeFreeObjectProperties> properties(
drmModeObjectGetProperties(fd(), m_id, DRM_MODE_OBJECT_PLANE));
if (!properties){
qCWarning(KWIN_DRM) << "Failed to get properties for plane " << m_id ;
return false;
@ -101,9 +102,9 @@ bool DrmPlane::initProps()
int propCount = int(PropertyIndex::Count);
for (int j = 0; j < propCount; ++j) {
if (j == int(PropertyIndex::Type)) {
initProp(j, properties, typeNames);
initProp(j, properties.data(), typeNames);
} else if (j == int(PropertyIndex::Rotation)) {
initProp(j, properties, rotationNames);
initProp(j, properties.data(), rotationNames);
m_supportedTransformations = Transformations();
auto testTransform = [j, this] (uint64_t value, Transformation t) {
if (propHasEnum(j, value)) {
@ -118,11 +119,10 @@ bool DrmPlane::initProps()
testTransform(5, Transformation::ReflectY);
qCDebug(KWIN_DRM) << "Supported Transformations: " << m_supportedTransformations << " on plane " << m_id;
} else {
initProp(j, properties);
initProp(j, properties.data());
}
}
drmModeFreeObjectProperties(properties);
return true;
}