Commit 13d079cd authored by Xaver Hugl's avatar Xaver Hugl
Browse files

backends/x11: do less manual memory management

parent e745577b
......@@ -58,11 +58,8 @@ EglOnXBackend::~EglOnXBackend()
}
cleanup();
if (m_overlayWindow) {
if (overlayWindow()->window()) {
overlayWindow()->destroy();
}
delete m_overlayWindow;
if (m_overlayWindow && m_overlayWindow->window()) {
m_overlayWindow->destroy();
}
}
......@@ -280,7 +277,7 @@ bool EglOnXBackend::initBufferConfigs()
OverlayWindow *EglOnXBackend::overlayWindow() const
{
return m_overlayWindow;
return m_overlayWindow.get();
}
bool EglOnXBackend::makeContextCurrent(const EGLSurface &surface)
......
......@@ -55,7 +55,7 @@ private:
/**
* @brief The OverlayWindow used by this Backend.
*/
OverlayWindow *m_overlayWindow;
std::unique_ptr<OverlayWindow> m_overlayWindow;
int surfaceHasSubPost;
xcb_connection_t *m_connection;
Display *m_x11Display;
......
......@@ -167,11 +167,7 @@ GlxBackend::~GlxBackend()
XDestroyWindow(display(), window);
}
qDeleteAll(m_fbconfigHash);
m_fbconfigHash.clear();
overlayWindow()->destroy();
delete m_overlayWindow;
m_overlayWindow->destroy();
}
typedef void (*glXFuncPtr)();
......@@ -572,20 +568,20 @@ static inline int bitCount(uint32_t mask)
#endif
}
FBConfigInfo *GlxBackend::infoForVisual(xcb_visualid_t visual)
const FBConfigInfo &GlxBackend::infoForVisual(xcb_visualid_t visual)
{
auto it = m_fbconfigHash.constFind(visual);
if (it != m_fbconfigHash.constEnd()) {
return it.value();
auto it = m_fbconfigHash.find(visual);
if (it != m_fbconfigHash.cend()) {
return *it;
}
FBConfigInfo *info = new FBConfigInfo;
m_fbconfigHash.insert(visual, info);
info->fbconfig = nullptr;
info->bind_texture_format = 0;
info->texture_targets = 0;
info->y_inverted = 0;
info->mipmap = 0;
m_fbconfigHash[visual] = FBConfigInfo{
.fbconfig = nullptr,
.bind_texture_format = 0,
.texture_targets = 0,
.y_inverted = 0,
.mipmap = 0,
};
FBConfigInfo &info = m_fbconfigHash[visual];
const xcb_render_pictformat_t format = XRenderUtils::findPictFormat(visual);
const xcb_render_directformat_t *direct = XRenderUtils::findPictFormatInfo(format);
......@@ -700,19 +696,21 @@ FBConfigInfo *GlxBackend::infoForVisual(xcb_visualid_t visual)
glXGetFBConfigAttrib(display(), candidate.config, GLX_BIND_TO_TEXTURE_TARGETS_EXT, &texture_targets);
glXGetFBConfigAttrib(display(), candidate.config, GLX_Y_INVERTED_EXT, &y_inverted);
info->fbconfig = candidate.config;
info->bind_texture_format = candidate.format;
info->texture_targets = texture_targets;
info->y_inverted = y_inverted;
info->mipmap = 0;
info = FBConfigInfo{
.fbconfig = candidate.config,
.bind_texture_format = candidate.format,
.texture_targets = texture_targets,
.y_inverted = y_inverted,
.mipmap = 0,
};
}
if (info->fbconfig) {
if (info.fbconfig) {
int fbc_id = 0;
int visual_id = 0;
glXGetFBConfigAttrib(display(), info->fbconfig, GLX_FBCONFIG_ID, &fbc_id);
glXGetFBConfigAttrib(display(), info->fbconfig, GLX_VISUAL_ID, &visual_id);
glXGetFBConfigAttrib(display(), info.fbconfig, GLX_FBCONFIG_ID, &fbc_id);
glXGetFBConfigAttrib(display(), info.fbconfig, GLX_VISUAL_ID, &visual_id);
qCDebug(KWIN_X11STANDALONE).nospace() << "Using FBConfig 0x" << Qt::hex << fbc_id << " for visual 0x" << Qt::hex << visual_id;
}
......@@ -858,7 +856,7 @@ void GlxBackend::doneCurrent()
OverlayWindow *GlxBackend::overlayWindow() const
{
return m_overlayWindow;
return m_overlayWindow.get();
}
OutputLayer *GlxBackend::primaryLayer(Output *output)
......@@ -932,17 +930,17 @@ bool GlxPixmapTexturePrivate::create(SurfacePixmapX11 *texture)
return false;
}
const FBConfigInfo *info = m_backend->infoForVisual(texture->visual());
if (!info || info->fbconfig == nullptr) {
const FBConfigInfo &info = m_backend->infoForVisual(texture->visual());
if (info.fbconfig == nullptr) {
return false;
}
if (info->texture_targets & GLX_TEXTURE_2D_BIT_EXT) {
if (info.texture_targets & GLX_TEXTURE_2D_BIT_EXT) {
m_target = GL_TEXTURE_2D;
m_scale.setWidth(1.0f / m_size.width());
m_scale.setHeight(1.0f / m_size.height());
} else {
Q_ASSERT(info->texture_targets & GLX_TEXTURE_RECTANGLE_BIT_EXT);
Q_ASSERT(info.texture_targets & GLX_TEXTURE_RECTANGLE_BIT_EXT);
m_target = GL_TEXTURE_RECTANGLE;
m_scale.setWidth(1.0f);
......@@ -950,14 +948,14 @@ bool GlxPixmapTexturePrivate::create(SurfacePixmapX11 *texture)
}
const int attrs[] = {
GLX_TEXTURE_FORMAT_EXT, info->bind_texture_format,
GLX_TEXTURE_FORMAT_EXT, info.bind_texture_format,
GLX_MIPMAP_TEXTURE_EXT, false,
GLX_TEXTURE_TARGET_EXT, m_target == GL_TEXTURE_2D ? GLX_TEXTURE_2D_EXT : GLX_TEXTURE_RECTANGLE_EXT,
0};
m_glxPixmap = glXCreatePixmap(m_backend->display(), info->fbconfig, texture->pixmap(), attrs);
m_glxPixmap = glXCreatePixmap(m_backend->display(), info.fbconfig, texture->pixmap(), attrs);
m_size = texture->size();
m_yInverted = info->y_inverted ? true : false;
m_yInverted = info.y_inverted ? true : false;
m_canUseMipmaps = false;
glGenTextures(1, &m_texture);
......
......@@ -23,6 +23,7 @@
#include <QHash>
#include <map>
#include <memory>
namespace KWin
......@@ -110,17 +111,17 @@ private:
void screenGeometryChanged();
int visualDepth(xcb_visualid_t visual) const;
FBConfigInfo *infoForVisual(xcb_visualid_t visual);
const FBConfigInfo &infoForVisual(xcb_visualid_t visual);
/**
* @brief The OverlayWindow used by this Backend.
*/
OverlayWindow *m_overlayWindow;
std::unique_ptr<OverlayWindow> m_overlayWindow;
::Window window;
GLXFBConfig fbconfig;
GLXWindow glxWindow;
GLXContext ctx;
QHash<xcb_visualid_t, FBConfigInfo *> m_fbconfigHash;
QHash<xcb_visualid_t, FBConfigInfo> m_fbconfigHash;
QHash<xcb_visualid_t, int> m_visualDepthHash;
std::unique_ptr<SwapEventFilter> m_swapEventFilter;
std::unique_ptr<GLFramebuffer> m_fbo;
......
......@@ -105,13 +105,12 @@ X11StandalonePlatform::X11StandalonePlatform(QObject *parent)
{
#if HAVE_X11_XINPUT
if (!qEnvironmentVariableIsSet("KWIN_NO_XI2")) {
m_xinputIntegration = new XInputIntegration(m_x11Display, this);
m_xinputIntegration = std::make_unique<XInputIntegration>(m_x11Display, this);
m_xinputIntegration->init();
if (!m_xinputIntegration->hasXinput()) {
delete m_xinputIntegration;
m_xinputIntegration = nullptr;
m_xinputIntegration.reset();
} else {
connect(kwinApp(), &Application::workspaceCreated, m_xinputIntegration, &XInputIntegration::startListening);
connect(kwinApp(), &Application::workspaceCreated, m_xinputIntegration.get(), &XInputIntegration::startListening);
}
}
#endif
......@@ -385,9 +384,9 @@ void X11StandalonePlatform::setupActionForGlobalAccel(QAction *action)
});
}
OverlayWindow *X11StandalonePlatform::createOverlayWindow()
std::unique_ptr<OverlayWindow> X11StandalonePlatform::createOverlayWindow()
{
return new OverlayWindowX11();
return std::make_unique<OverlayWindowX11>();
}
OutlineVisual *X11StandalonePlatform::createOutline(Outline *outline)
......
......@@ -53,7 +53,7 @@ public:
void setupActionForGlobalAccel(QAction *action) override;
OverlayWindow *createOverlayWindow() override;
std::unique_ptr<OverlayWindow> createOverlayWindow() override;
OutlineVisual *createOutline(Outline *outline) override;
void invertScreen() override;
......@@ -88,7 +88,7 @@ private:
void updateCursor();
Session *m_session;
XInputIntegration *m_xinputIntegration = nullptr;
std::unique_ptr<XInputIntegration> m_xinputIntegration;
QThread *m_openGLFreezeProtectionThread = nullptr;
QTimer *m_openGLFreezeProtection = nullptr;
QTimer *m_updateOutputsTimer = nullptr;
......
......@@ -46,7 +46,6 @@ X11WindowedOutput::~X11WindowedOutput()
{
xcb_unmap_window(m_backend->connection(), m_window);
xcb_destroy_window(m_backend->connection(), m_window);
delete m_winInfo;
xcb_flush(m_backend->connection());
}
......@@ -98,10 +97,8 @@ void X11WindowedOutput::init(const QPoint &logicalPosition, const QSize &pixelSi
// select xinput 2 events
initXInputForWindow();
m_winInfo = new NETWinInfo(m_backend->connection(),
m_window,
m_backend->screen()->root,
NET::WMWindowType, NET::Properties2());
m_winInfo = std::make_unique<NETWinInfo>(m_backend->connection(), m_window, m_backend->screen()->root,
NET::WMWindowType, NET::Properties2());
m_winInfo->setWindowType(NET::Normal);
m_winInfo->setPid(QCoreApplication::applicationPid());
......
......@@ -74,7 +74,7 @@ private:
void vblank(std::chrono::nanoseconds timestamp);
xcb_window_t m_window = XCB_WINDOW_NONE;
NETWinInfo *m_winInfo = nullptr;
std::unique_ptr<NETWinInfo> m_winInfo;
RenderLoop *m_renderLoop;
std::unique_ptr<SoftwareVsyncMonitor> m_vsyncMonitor;
QPoint m_hostPosition;
......
......@@ -342,7 +342,7 @@ void Platform::setupActionForGlobalAccel(QAction *action)
Q_UNUSED(action)
}
OverlayWindow *Platform::createOverlayWindow()
std::unique_ptr<OverlayWindow> Platform::createOverlayWindow()
{
return nullptr;
}
......
......@@ -262,7 +262,7 @@ public:
* Creates the OverlayWindow required for X11 based compositors.
* Default implementation returns @c nullptr.
*/
virtual OverlayWindow *createOverlayWindow();
virtual std::unique_ptr<OverlayWindow> createOverlayWindow();
/**
* Queries the current X11 time stamp of the X server.
......
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