Commit 4cab9c4f authored by Xaver Hugl's avatar Xaver Hugl
Browse files

backends: port from QScopedPointer to std::unique_ptr

parent 1112c29e
......@@ -77,7 +77,7 @@ DrmGpu::DrmGpu(DrmBackend *backend, const QString &devNode, int fd, dev_t device
qCDebug(KWIN_DRM) << "drmModeAddFB2WithModifiers is" << (m_addFB2ModifiersSupported ? "supported" : "not supported") << "on GPU" << m_devNode;
// find out what driver this kms device is using
DrmScopedPointer<drmVersion> version(drmGetVersion(fd));
DrmUniquePtr<drmVersion> version(drmGetVersion(fd));
m_isNVidia = strstr(version->name, "nvidia-drm");
m_isVirtualMachine = strstr(version->name, "virtio") || strstr(version->name, "qxl")
|| strstr(version->name, "vmwgfx") || strstr(version->name, "vboxvideo");
......@@ -160,13 +160,13 @@ void DrmGpu::initDrmResources()
} else if (drmSetClientCap(m_fd, DRM_CLIENT_CAP_ATOMIC, 1) != 0) {
qCWarning(KWIN_DRM) << "drmSetClientCap for Atomic Mode Setting failed. Using legacy mode on GPU" << m_devNode;
} else {
DrmScopedPointer<drmModePlaneRes> planeResources(drmModeGetPlaneResources(m_fd));
DrmUniquePtr<drmModePlaneRes> planeResources(drmModeGetPlaneResources(m_fd));
if (planeResources) {
qCDebug(KWIN_DRM) << "Using Atomic Mode Setting on gpu" << m_devNode;
qCDebug(KWIN_DRM) << "Number of planes on GPU" << m_devNode << ":" << planeResources->count_planes;
// create the plane objects
for (unsigned int i = 0; i < planeResources->count_planes; ++i) {
DrmScopedPointer<drmModePlane> kplane(drmModeGetPlane(m_fd, planeResources->planes[i]));
DrmUniquePtr<drmModePlane> kplane(drmModeGetPlane(m_fd, planeResources->planes[i]));
DrmPlane *p = new DrmPlane(this, kplane->plane_id);
if (p->init()) {
m_planes << p;
......@@ -184,7 +184,7 @@ void DrmGpu::initDrmResources()
}
m_atomicModeSetting = !m_planes.isEmpty();
DrmScopedPointer<drmModeRes> resources(drmModeGetResources(m_fd));
DrmUniquePtr<drmModeRes> resources(drmModeGetResources(m_fd));
if (!resources) {
qCCritical(KWIN_DRM) << "drmModeGetResources for getting CRTCs failed on GPU" << m_devNode;
return;
......@@ -225,7 +225,7 @@ void DrmGpu::initDrmResources()
bool DrmGpu::updateOutputs()
{
waitIdle();
DrmScopedPointer<drmModeRes> resources(drmModeGetResources(m_fd));
DrmUniquePtr<drmModeRes> resources(drmModeGetResources(m_fd));
if (!resources) {
qCWarning(KWIN_DRM) << "drmModeGetResources failed";
return false;
......
......@@ -134,7 +134,7 @@ bool DrmObject::needsCommit() const
bool DrmObject::updateProperties()
{
DrmScopedPointer<drmModeObjectProperties> properties(drmModeObjectGetProperties(m_gpu->fd(), m_id, m_objectType));
DrmUniquePtr<drmModeObjectProperties> properties(drmModeObjectGetProperties(m_gpu->fd(), m_id, m_objectType));
if (!properties) {
qCWarning(KWIN_DRM) << "Failed to get properties for object" << m_id;
return false;
......@@ -143,7 +143,7 @@ bool DrmObject::updateProperties()
const PropertyDefinition &def = m_propertyDefinitions[propIndex];
bool found = false;
for (uint32_t drmPropIndex = 0; drmPropIndex < properties->count_props; drmPropIndex++) {
DrmScopedPointer<drmModePropertyRes> prop(drmModeGetProperty(m_gpu->fd(), properties->props[drmPropIndex]));
DrmUniquePtr<drmModePropertyRes> prop(drmModeGetProperty(m_gpu->fd(), properties->props[drmPropIndex]));
if (!prop) {
qCWarning(KWIN_DRM, "Getting property %d of object %d failed!", drmPropIndex, m_id);
continue;
......@@ -152,7 +152,7 @@ bool DrmObject::updateProperties()
if (m_props[propIndex]) {
m_props[propIndex]->setCurrent(properties->prop_values[drmPropIndex]);
} else {
m_props[propIndex] = new DrmProperty(this, prop.data(), properties->prop_values[drmPropIndex], def.enumNames);
m_props[propIndex] = new DrmProperty(this, prop.get(), properties->prop_values[drmPropIndex], def.enumNames);
}
found = true;
break;
......
......@@ -118,7 +118,7 @@ DrmConnector::DrmConnector(DrmGpu *gpu, uint32_t connectorId)
{
if (m_conn) {
for (int i = 0; i < m_conn->count_encoders; ++i) {
DrmScopedPointer<drmModeEncoder> enc(drmModeGetEncoder(gpu->fd(), m_conn->encoders[i]));
DrmUniquePtr<drmModeEncoder> enc(drmModeGetEncoder(gpu->fd(), m_conn->encoders[i]));
if (!enc) {
qCWarning(KWIN_DRM) << "failed to get encoder" << m_conn->encoders[i];
continue;
......@@ -380,7 +380,7 @@ const Edid *DrmConnector::edid() const
DrmPipeline *DrmConnector::pipeline() const
{
return m_pipeline.data();
return m_pipeline.get();
}
void DrmConnector::disable()
......
......@@ -108,8 +108,8 @@ private:
QList<std::shared_ptr<DrmConnectorMode>> generateCommonModes();
std::shared_ptr<DrmConnectorMode> generateMode(const QSize &size, uint32_t refreshRate);
QScopedPointer<DrmPipeline> m_pipeline;
DrmScopedPointer<drmModeConnector> m_conn;
std::unique_ptr<DrmPipeline> m_pipeline;
DrmUniquePtr<drmModeConnector> m_conn;
Edid m_edid;
QSize m_physicalSize = QSize(-1, -1);
QList<std::shared_ptr<DrmConnectorMode>> m_driverModes;
......
......@@ -56,7 +56,7 @@ public:
void releaseBuffers();
private:
DrmScopedPointer<drmModeCrtc> m_crtc;
DrmUniquePtr<drmModeCrtc> m_crtc;
std::shared_ptr<DrmFramebuffer> m_currentBuffer;
std::shared_ptr<DrmFramebuffer> m_nextBuffer;
int m_pipeIndex;
......
......@@ -42,7 +42,7 @@ DrmPlane::DrmPlane(DrmGpu *gpu, uint32_t planeId)
bool DrmPlane::init()
{
DrmScopedPointer<drmModePlane> p(drmModeGetPlane(gpu()->fd(), id()));
DrmUniquePtr<drmModePlane> p(drmModeGetPlane(gpu()->fd(), id()));
if (!p) {
qCWarning(KWIN_DRM) << "Failed to get kernel plane" << id();
......
......@@ -10,8 +10,7 @@
#ifndef KWIN_DRM_POINTER_H
#define KWIN_DRM_POINTER_H
#include <QScopedPointer>
#include <memory>
#include <xf86drm.h>
#include <xf86drmMode.h>
......@@ -24,7 +23,7 @@ struct DrmDeleter;
template<>
struct DrmDeleter<drmVersion>
{
static void cleanup(drmVersion *version)
void operator()(drmVersion *version)
{
drmFreeVersion(version);
}
......@@ -33,7 +32,7 @@ struct DrmDeleter<drmVersion>
template<>
struct DrmDeleter<drmModeAtomicReq>
{
static void cleanup(drmModeAtomicReq *req)
void operator()(drmModeAtomicReq *req)
{
drmModeAtomicFree(req);
}
......@@ -42,7 +41,7 @@ struct DrmDeleter<drmModeAtomicReq>
template<>
struct DrmDeleter<drmModeConnector>
{
static void cleanup(drmModeConnector *connector)
void operator()(drmModeConnector *connector)
{
drmModeFreeConnector(connector);
}
......@@ -51,7 +50,7 @@ struct DrmDeleter<drmModeConnector>
template<>
struct DrmDeleter<drmModeCrtc>
{
static void cleanup(drmModeCrtc *crtc)
void operator()(drmModeCrtc *crtc)
{
drmModeFreeCrtc(crtc);
}
......@@ -60,7 +59,7 @@ struct DrmDeleter<drmModeCrtc>
template<>
struct DrmDeleter<drmModeFB>
{
static void cleanup(drmModeFB *fb)
void operator()(drmModeFB *fb)
{
drmModeFreeFB(fb);
}
......@@ -69,7 +68,7 @@ struct DrmDeleter<drmModeFB>
template<>
struct DrmDeleter<drmModeEncoder>
{
static void cleanup(drmModeEncoder *encoder)
void operator()(drmModeEncoder *encoder)
{
drmModeFreeEncoder(encoder);
}
......@@ -78,7 +77,7 @@ struct DrmDeleter<drmModeEncoder>
template<>
struct DrmDeleter<drmModeModeInfo>
{
static void cleanup(drmModeModeInfo *info)
void operator()(drmModeModeInfo *info)
{
drmModeFreeModeInfo(info);
}
......@@ -87,7 +86,7 @@ struct DrmDeleter<drmModeModeInfo>
template<>
struct DrmDeleter<drmModeObjectProperties>
{
static void cleanup(drmModeObjectProperties *properties)
void operator()(drmModeObjectProperties *properties)
{
drmModeFreeObjectProperties(properties);
}
......@@ -96,7 +95,7 @@ struct DrmDeleter<drmModeObjectProperties>
template<>
struct DrmDeleter<drmModePlane>
{
static void cleanup(drmModePlane *plane)
void operator()(drmModePlane *plane)
{
drmModeFreePlane(plane);
}
......@@ -105,7 +104,7 @@ struct DrmDeleter<drmModePlane>
template<>
struct DrmDeleter<drmModePlaneRes>
{
static void cleanup(drmModePlaneRes *resources)
void operator()(drmModePlaneRes *resources)
{
drmModeFreePlaneResources(resources);
}
......@@ -114,7 +113,7 @@ struct DrmDeleter<drmModePlaneRes>
template<>
struct DrmDeleter<drmModePropertyRes>
{
static void cleanup(drmModePropertyRes *property)
void operator()(drmModePropertyRes *property)
{
drmModeFreeProperty(property);
}
......@@ -123,7 +122,7 @@ struct DrmDeleter<drmModePropertyRes>
template<>
struct DrmDeleter<drmModePropertyBlobRes>
{
static void cleanup(drmModePropertyBlobRes *blob)
void operator()(drmModePropertyBlobRes *blob)
{
drmModeFreePropertyBlob(blob);
}
......@@ -132,15 +131,14 @@ struct DrmDeleter<drmModePropertyBlobRes>
template<>
struct DrmDeleter<drmModeRes>
{
static void cleanup(drmModeRes *resources)
void operator()(drmModeRes *resources)
{
drmModeFreeResources(resources);
}
};
template<typename T>
using DrmScopedPointer = QScopedPointer<T, DrmDeleter<T>>;
using DrmUniquePtr = std::unique_ptr<T, DrmDeleter<T>>;
}
#endif
......@@ -96,7 +96,7 @@ private:
uint64_t m_next = 0;
// the value currently set for or by the kernel
uint64_t m_current = 0;
DrmScopedPointer<drmModePropertyBlobRes> m_immutableBlob;
DrmUniquePtr<drmModePropertyBlobRes> m_immutableBlob;
uint64_t m_minValue = -1;
uint64_t m_maxValue = -1;
......
......@@ -83,7 +83,7 @@ void GbmSurface::releaseBuffer(GbmBuffer *buffer)
GLFramebuffer *GbmSurface::fbo() const
{
return m_fbo.data();
return m_fbo.get();
}
EGLSurface GbmSurface::eglSurface() const
......
......@@ -67,7 +67,7 @@ private:
int m_bufferAge = 0;
DamageJournal m_damageJournal;
QScopedPointer<GLFramebuffer> m_fbo;
std::unique_ptr<GLFramebuffer> m_fbo;
};
}
......@@ -88,7 +88,7 @@ void ShadowBuffer::render(DrmPlane::Transformations transform)
GLFramebuffer *ShadowBuffer::fbo() const
{
return m_fbo.data();
return m_fbo.get();
}
std::shared_ptr<GLTexture> ShadowBuffer::texture() const
......
......@@ -33,8 +33,8 @@ public:
private:
GLint internalFormat(const GbmFormat &format) const;
std::shared_ptr<GLTexture> m_texture;
QScopedPointer<GLFramebuffer> m_fbo;
QScopedPointer<GLVertexBuffer> m_vbo;
std::unique_ptr<GLFramebuffer> m_fbo;
std::unique_ptr<GLVertexBuffer> m_vbo;
const QSize m_size;
const uint32_t m_drmFormat;
};
......
......@@ -56,7 +56,7 @@ private:
GLTexture *m_backBuffer = nullptr;
GLFramebuffer *m_fbo = nullptr;
int m_frameCounter = 0;
QScopedPointer<VirtualOutputLayer> m_layer;
std::unique_ptr<VirtualOutputLayer> m_layer;
};
} // namespace
......
......@@ -34,7 +34,7 @@ VirtualBackend::VirtualBackend(QObject *parent)
if (!m_screenshotDir->isValid()) {
m_screenshotDir.reset();
}
if (!m_screenshotDir.isNull()) {
if (m_screenshotDir) {
qDebug() << "Screenshots saved to: " << m_screenshotDir->path();
}
}
......@@ -80,7 +80,7 @@ bool VirtualBackend::initialize()
QString VirtualBackend::screenshotDirPath() const
{
if (m_screenshotDir.isNull()) {
if (!m_screenshotDir) {
return QString();
}
return m_screenshotDir->path();
......
......@@ -38,7 +38,7 @@ public:
bool saveFrames() const
{
return !m_screenshotDir.isNull();
return m_screenshotDir != nullptr;
}
QString screenshotDirPath() const;
......@@ -69,7 +69,7 @@ Q_SIGNALS:
private:
QVector<VirtualOutput *> m_outputs;
QVector<VirtualOutput *> m_outputsEnabled;
QScopedPointer<QTemporaryDir> m_screenshotDir;
std::unique_ptr<QTemporaryDir> m_screenshotDir;
Session *m_session;
};
......
......@@ -110,7 +110,7 @@ EglWaylandOutput::~EglWaylandOutput()
GLFramebuffer *EglWaylandOutput::fbo() const
{
return m_fbo.data();
return m_fbo.get();
}
void EglWaylandOutput::updateSize()
......@@ -156,7 +156,7 @@ OutputLayerBeginFrameInfo EglWaylandOutput::beginFrame()
GLFramebuffer::pushFramebuffer(m_fbo.get());
return OutputLayerBeginFrameInfo{
.renderTarget = RenderTarget(m_fbo.data()),
.renderTarget = RenderTarget(m_fbo.get()),
.repaint = repair,
};
}
......
......@@ -59,7 +59,7 @@ private:
EGLSurface m_eglSurface = EGL_NO_SURFACE;
int m_bufferAge = 0;
DamageJournal m_damageJournal;
QScopedPointer<GLFramebuffer> m_fbo;
std::unique_ptr<GLFramebuffer> m_fbo;
EglWaylandBackend *const m_backend;
friend class EglWaylandBackend;
......
......@@ -281,36 +281,36 @@ WaylandInputDevice::WaylandInputDevice(KWayland::Client::Pointer *pointer, Wayla
KWayland::Client::PointerGestures *pointerGestures = m_seat->backend()->pointerGestures();
if (pointerGestures) {
m_pinchGesture.reset(pointerGestures->createPinchGesture(m_pointer.data(), this));
connect(m_pinchGesture.data(), &PointerPinchGesture::started, this, [this](quint32 serial, quint32 time) {
m_pinchGesture.reset(pointerGestures->createPinchGesture(m_pointer.get(), this));
connect(m_pinchGesture.get(), &PointerPinchGesture::started, this, [this](quint32 serial, quint32 time) {
Q_UNUSED(serial);
Q_EMIT pinchGestureBegin(m_pinchGesture->fingerCount(), time, this);
});
connect(m_pinchGesture.data(), &PointerPinchGesture::updated, this, [this](const QSizeF &delta, qreal scale, qreal rotation, quint32 time) {
connect(m_pinchGesture.get(), &PointerPinchGesture::updated, this, [this](const QSizeF &delta, qreal scale, qreal rotation, quint32 time) {
Q_EMIT pinchGestureUpdate(scale, rotation, delta, time, this);
});
connect(m_pinchGesture.data(), &PointerPinchGesture::ended, this, [this](quint32 serial, quint32 time) {
connect(m_pinchGesture.get(), &PointerPinchGesture::ended, this, [this](quint32 serial, quint32 time) {
Q_UNUSED(serial)
Q_EMIT pinchGestureEnd(time, this);
});
connect(m_pinchGesture.data(), &PointerPinchGesture::cancelled, this, [this](quint32 serial, quint32 time) {
connect(m_pinchGesture.get(), &PointerPinchGesture::cancelled, this, [this](quint32 serial, quint32 time) {
Q_UNUSED(serial)
Q_EMIT pinchGestureCancelled(time, this);
});
m_swipeGesture.reset(pointerGestures->createSwipeGesture(m_pointer.data(), this));
connect(m_swipeGesture.data(), &PointerSwipeGesture::started, this, [this](quint32 serial, quint32 time) {
m_swipeGesture.reset(pointerGestures->createSwipeGesture(m_pointer.get(), this));
connect(m_swipeGesture.get(), &PointerSwipeGesture::started, this, [this](quint32 serial, quint32 time) {
Q_UNUSED(serial)
Q_EMIT swipeGestureBegin(m_swipeGesture->fingerCount(), time, this);
});
connect(m_swipeGesture.data(), &PointerSwipeGesture::updated, this, [this](const QSizeF &delta, quint32 time) {
connect(m_swipeGesture.get(), &PointerSwipeGesture::updated, this, [this](const QSizeF &delta, quint32 time) {
Q_EMIT swipeGestureUpdate(delta, time, this);
});
connect(m_swipeGesture.data(), &PointerSwipeGesture::ended, this, [this](quint32 serial, quint32 time) {
connect(m_swipeGesture.get(), &PointerSwipeGesture::ended, this, [this](quint32 serial, quint32 time) {
Q_UNUSED(serial)
Q_EMIT swipeGestureEnd(time, this);
});
connect(m_swipeGesture.data(), &PointerSwipeGesture::cancelled, this, [this](quint32 serial, quint32 time) {
connect(m_swipeGesture.get(), &PointerSwipeGesture::cancelled, this, [this](quint32 serial, quint32 time) {
Q_UNUSED(serial)
Q_EMIT swipeGestureCancelled(time, this);
});
......@@ -388,12 +388,12 @@ void WaylandInputDevice::setLeds(LEDs leds)
bool WaylandInputDevice::isKeyboard() const
{
return !m_keyboard.isNull();
return m_keyboard != nullptr;
}
bool WaylandInputDevice::isAlphaNumericKeyboard() const
{
return !m_keyboard.isNull();
return m_keyboard != nullptr;
}
bool WaylandInputDevice::isPointer() const
......@@ -408,7 +408,7 @@ bool WaylandInputDevice::isTouchpad() const
bool WaylandInputDevice::isTouch() const
{
return !m_touch.isNull();
return m_touch != nullptr;
}
bool WaylandInputDevice::isTabletTool() const
......@@ -433,7 +433,7 @@ bool WaylandInputDevice::isLidSwitch() const
KWayland::Client::Pointer *WaylandInputDevice::nativePointer() const
{
return m_pointer.data();
return m_pointer.get();
}
WaylandInputBackend::WaylandInputBackend(WaylandBackend *backend, QObject *parent)
......@@ -987,7 +987,7 @@ void WaylandBackend::createDpmsFilter()
return;
}
m_dpmsFilter.reset(new DpmsInputEventFilter);
input()->prependInputEventFilter(m_dpmsFilter.data());
input()->prependInputEventFilter(m_dpmsFilter.get());
}
void WaylandBackend::clearDpmsFilter()
......
......@@ -160,12 +160,12 @@ public:
private:
WaylandSeat *m_seat;
QScopedPointer<KWayland::Client::Keyboard> m_keyboard;
QScopedPointer<KWayland::Client::Touch> m_touch;
QScopedPointer<KWayland::Client::RelativePointer> m_relativePointer;
QScopedPointer<KWayland::Client::Pointer> m_pointer;
QScopedPointer<KWayland::Client::PointerPinchGesture> m_pinchGesture;
QScopedPointer<KWayland::Client::PointerSwipeGesture> m_swipeGesture;
std::unique_ptr<KWayland::Client::Keyboard> m_keyboard;
std::unique_ptr<KWayland::Client::Touch> m_touch;
std::unique_ptr<KWayland::Client::RelativePointer> m_relativePointer;
std::unique_ptr<KWayland::Client::Pointer> m_pointer;
std::unique_ptr<KWayland::Client::PointerPinchGesture> m_pinchGesture;
std::unique_ptr<KWayland::Client::PointerSwipeGesture> m_swipeGesture;
uint32_t m_enteredSerial = 0;
};
......@@ -353,7 +353,7 @@ private:
WaylandCursor *m_waylandCursor = nullptr;
QScopedPointer<DpmsInputEventFilter> m_dpmsFilter;
std::unique_ptr<DpmsInputEventFilter> m_dpmsFilter;
bool m_pointerLockRequested = false;
KWayland::Client::ServerSideDecorationManager *m_ssdManager = nullptr;
......
......@@ -87,12 +87,12 @@ void XRenderPicture::fromImage(const QImage &img)
0, 0, 0, depth, img.sizeInBytes(), img.constBits());
xcb_free_gc(c, cid);
d = new XRenderPictureData(createPicture(xpix, depth));
d = std::make_unique<XRenderPictureData>(createPicture(xpix, depth));
xcb_free_pixmap(c, xpix);
}
XRenderPicture::XRenderPicture(xcb_pixmap_t pix, int depth)
: d(new XRenderPictureData(createPicture(pix, depth)))
: d(std::make_unique<XRenderPictureData>(createPicture(pix, depth)))
{
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment