backends: port from QScopedPointer to std::unique_ptr

This commit is contained in:
Xaver Hugl 2022-06-01 12:12:19 +02:00
parent 1112c29eb4
commit 4cab9c4fc7
31 changed files with 131 additions and 100 deletions

View file

@ -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;

View file

@ -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;

View file

@ -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()

View file

@ -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;

View file

@ -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;

View file

@ -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();

View file

@ -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

View file

@ -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;

View file

@ -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

View file

@ -67,7 +67,7 @@ private:
int m_bufferAge = 0;
DamageJournal m_damageJournal;
QScopedPointer<GLFramebuffer> m_fbo;
std::unique_ptr<GLFramebuffer> m_fbo;
};
}

View file

@ -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

View file

@ -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;
};

View file

@ -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

View file

@ -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();

View file

@ -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;
};

View file

@ -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,
};
}

View file

@ -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;

View file

@ -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()

View file

@ -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;

View file

@ -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)))
{
}

View file

@ -19,6 +19,8 @@
// XCB
#include <xcb/render.h>
#include <memory>
class QImage;
/** @addtogroup kwineffects */
@ -58,7 +60,7 @@ public:
private:
void fromImage(const QImage &img);
QExplicitlySharedDataPointer<XRenderPictureData> d;
std::unique_ptr<XRenderPictureData> d;
};
inline XRenderPictureData::XRenderPictureData(xcb_render_picture_t pic)
@ -72,7 +74,7 @@ inline xcb_render_picture_t XRenderPictureData::value()
}
inline XRenderPicture::XRenderPicture(xcb_render_picture_t pic)
: d(new XRenderPictureData(pic))
: d(std::make_unique<XRenderPictureData>(pic))
{
}

View file

@ -45,7 +45,7 @@ bool EglLayer::endFrame(const QRegion &renderedRegion, const QRegion &damagedReg
EglBackend::EglBackend(Display *display, X11StandalonePlatform *backend)
: EglOnXBackend(display)
, m_backend(backend)
, m_layer(new EglLayer(this))
, m_layer(std::make_unique<EglLayer>(this))
{
// There is no any way to determine when a buffer swap completes with EGL. Fallback
// to software vblank events. Could we use the Present extension to get notified when
@ -134,9 +134,9 @@ OutputLayerBeginFrameInfo EglBackend::beginFrame()
eglWaitNative(EGL_CORE_NATIVE_ENGINE);
// Push the default framebuffer to the render target stack.
GLFramebuffer::pushFramebuffer(m_fbo.data());
GLFramebuffer::pushFramebuffer(m_fbo.get());
return OutputLayerBeginFrameInfo{
.renderTarget = RenderTarget(m_fbo.data()),
.renderTarget = RenderTarget(m_fbo.get()),
.repaint = repaint,
};
}

View file

@ -58,10 +58,10 @@ private:
X11StandalonePlatform *m_backend;
SoftwareVsyncMonitor *m_vsyncMonitor;
DamageJournal m_damageJournal;
QScopedPointer<GLFramebuffer> m_fbo;
std::unique_ptr<GLFramebuffer> m_fbo;
int m_bufferAge = 0;
QRegion m_lastRenderedRegion;
QScopedPointer<EglLayer> m_layer;
std::unique_ptr<EglLayer> m_layer;
};
class EglPixmapTexture : public GLTexture

View file

@ -129,7 +129,7 @@ GlxBackend::GlxBackend(Display *display, X11StandalonePlatform *backend)
, m_bufferAge(0)
, m_x11Display(display)
, m_backend(backend)
, m_layer(new GlxLayer(this))
, m_layer(std::make_unique<GlxLayer>(this))
{
// Force initialization of GLX integration in the Qt's xcb backend
// to make it call XESetWireToEvent callbacks, which is required
@ -231,7 +231,7 @@ void GlxBackend::init()
glPlatform->printResults();
initGL(&getProcAddress);
m_fbo.reset(new GLFramebuffer(0, screens()->size()));
m_fbo = std::make_unique<GLFramebuffer>(0, screens()->size());
bool supportsSwapEvent = false;
@ -772,7 +772,7 @@ void GlxBackend::screenGeometryChanged()
// The back buffer contents are now undefined
m_bufferAge = 0;
m_fbo.reset(new GLFramebuffer(0, size));
m_fbo = std::make_unique<GLFramebuffer>(0, size);
}
SurfaceTexture *GlxBackend::createSurfaceTextureX11(SurfacePixmapX11 *pixmap)
@ -785,7 +785,7 @@ OutputLayerBeginFrameInfo GlxBackend::beginFrame()
QRegion repaint;
makeCurrent();
GLFramebuffer::pushFramebuffer(m_fbo.data());
GLFramebuffer::pushFramebuffer(m_fbo.get());
if (supportsBufferAge()) {
repaint = m_damageJournal.accumulate(m_bufferAge, infiniteRegion());
}
@ -793,7 +793,7 @@ OutputLayerBeginFrameInfo GlxBackend::beginFrame()
glXWaitX();
return OutputLayerBeginFrameInfo{
.renderTarget = RenderTarget(m_fbo.data()),
.renderTarget = RenderTarget(m_fbo.get()),
.repaint = repaint,
};
}

View file

@ -123,7 +123,7 @@ private:
QHash<xcb_visualid_t, FBConfigInfo *> m_fbconfigHash;
QHash<xcb_visualid_t, int> m_visualDepthHash;
std::unique_ptr<SwapEventFilter> m_swapEventFilter;
QScopedPointer<GLFramebuffer> m_fbo;
std::unique_ptr<GLFramebuffer> m_fbo;
DamageJournal m_damageJournal;
QRegion m_lastRenderedRegion;
int m_bufferAge;
@ -134,7 +134,7 @@ private:
Display *m_x11Display;
X11StandalonePlatform *m_backend;
VsyncMonitor *m_vsyncMonitor = nullptr;
QScopedPointer<GlxLayer> m_layer;
std::unique_ptr<GlxLayer> m_layer;
friend class GlxPixmapTexturePrivate;
};

View file

@ -31,6 +31,7 @@
#include "overlaywindow_x11.h"
#include "renderloop.h"
#include "screenedges_filter.h"
#include "utils/c_ptr.h"
#include "utils/xcbutils.h"
#include "window.h"
#include "workspace.h"
@ -180,8 +181,8 @@ OpenGLBackend *X11StandalonePlatform::createOpenGLBackend()
Edge *X11StandalonePlatform::createScreenEdge(ScreenEdges *edges)
{
if (m_screenEdgesFilter.isNull()) {
m_screenEdgesFilter.reset(new ScreenEdgesFilter);
if (!m_screenEdgesFilter) {
m_screenEdgesFilter = std::make_unique<ScreenEdgesFilter>();
}
return new WindowBasedEdge(edges);
}
@ -328,15 +329,15 @@ void X11StandalonePlatform::createOpenGLSafePoint(OpenGLSafePoint safePoint)
PlatformCursorImage X11StandalonePlatform::cursorImage() const
{
auto c = kwinApp()->x11Connection();
QScopedPointer<xcb_xfixes_get_cursor_image_reply_t, QScopedPointerPodDeleter> cursor(
UniqueCPtr<xcb_xfixes_get_cursor_image_reply_t> cursor(
xcb_xfixes_get_cursor_image_reply(c,
xcb_xfixes_get_cursor_image_unchecked(c),
nullptr));
if (cursor.isNull()) {
if (!cursor) {
return PlatformCursorImage();
}
QImage qcursorimg((uchar *)xcb_xfixes_get_cursor_image_cursor_image(cursor.data()), cursor->width, cursor->height,
QImage qcursorimg((uchar *)xcb_xfixes_get_cursor_image_cursor_image(cursor.get()), cursor->width, cursor->height,
QImage::Format_ARGB32_Premultiplied);
// deep copy of image as the data is going to be freed
return PlatformCursorImage(qcursorimg.copy(), QPoint(cursor->xhot, cursor->yhot));
@ -353,7 +354,7 @@ void X11StandalonePlatform::updateCursor()
void X11StandalonePlatform::startInteractiveWindowSelection(std::function<void(KWin::Window *)> callback, const QByteArray &cursorName)
{
if (m_windowSelector.isNull()) {
if (!m_windowSelector) {
m_windowSelector.reset(new WindowSelector);
}
m_windowSelector->start(callback, cursorName);
@ -361,7 +362,7 @@ void X11StandalonePlatform::startInteractiveWindowSelection(std::function<void(K
void X11StandalonePlatform::startInteractivePositionSelection(std::function<void(const QPoint &)> callback)
{
if (m_windowSelector.isNull()) {
if (!m_windowSelector) {
m_windowSelector.reset(new WindowSelector);
}
m_windowSelector->start(callback);

View file

@ -93,9 +93,9 @@ private:
QTimer *m_openGLFreezeProtection = nullptr;
QTimer *m_updateOutputsTimer = nullptr;
Display *m_x11Display;
QScopedPointer<WindowSelector> m_windowSelector;
QScopedPointer<X11EventFilter> m_screenEdgesFilter;
QScopedPointer<X11EventFilter> m_randrEventFilter;
std::unique_ptr<WindowSelector> m_windowSelector;
std::unique_ptr<X11EventFilter> m_screenEdgesFilter;
std::unique_ptr<X11EventFilter> m_randrEventFilter;
RenderLoop *m_renderLoop;
QVector<Output *> m_outputs;
};

View file

@ -11,7 +11,7 @@
#include <QObject>
#include <QPointer>
#include <QScopedPointer>
#include <memory>
typedef struct _XDisplay Display;
namespace KWin
@ -50,9 +50,9 @@ private:
QPointer<X11Cursor> m_x11Cursor;
Display *m_x11Display;
QScopedPointer<XInputEventFilter> m_xiEventFilter;
QScopedPointer<XKeyPressReleaseEventFilter> m_keyPressFilter;
QScopedPointer<XKeyPressReleaseEventFilter> m_keyReleaseFilter;
std::unique_ptr<XInputEventFilter> m_xiEventFilter;
std::unique_ptr<XKeyPressReleaseEventFilter> m_keyPressFilter;
std::unique_ptr<XKeyPressReleaseEventFilter> m_keyReleaseFilter;
};
}

View file

@ -44,9 +44,9 @@ OutputLayerBeginFrameInfo EglX11Output::beginFrame()
{
eglMakeCurrent(m_backend->eglDisplay(), m_eglSurface, m_eglSurface, m_backend->context());
ensureFbo();
GLFramebuffer::pushFramebuffer(m_fbo.data());
GLFramebuffer::pushFramebuffer(m_fbo.get());
return OutputLayerBeginFrameInfo{
.renderTarget = RenderTarget(m_fbo.data()),
.renderTarget = RenderTarget(m_fbo.get()),
.repaint = m_output->rect(),
};
}

View file

@ -35,7 +35,7 @@ private:
void ensureFbo();
EGLSurface m_eglSurface;
QScopedPointer<GLFramebuffer> m_fbo;
std::unique_ptr<GLFramebuffer> m_fbo;
QRegion m_lastDamage;
Output *const m_output;

30
src/utils/c_ptr.h Normal file
View file

@ -0,0 +1,30 @@
/*
KWin - the KDE window manager
This file is part of the KDE project.
SPDX-FileCopyrightText: 2022 Xaver Hugl <xaver.hugl@gmail.com>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#pragma once
#include <memory>
namespace KWin
{
struct CDeleter
{
template<typename T>
void operator()(T *ptr)
{
if (ptr) {
free(ptr);
}
}
};
template<typename T>
using UniqueCPtr = std::unique_ptr<T, CDeleter>;
}