From a6ba08ef1eeeaac4325ddbc9b4cf214dad32ed1e Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Tue, 14 Feb 2012 16:33:29 +0100 Subject: [PATCH] Compositor memory leak fixes MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Change-Id: Ia0510e00ffc925cde98ec5345a8129d1979c478c Reviewed-by: Jørgen Lind --- src/compositor/compositor_api/waylandinput.cpp | 5 +++++ src/compositor/compositor_api/waylandinput.h | 1 + .../graphicshardwareintegration.h | 1 + .../xcomposite_glx/xcompositeglxintegration.cpp | 10 ++++++++-- .../xcomposite_glx/xcompositeglxintegration.h | 4 ++++ src/compositor/wayland_wrapper/wlcompositor.cpp | 20 +++++++++++++++----- src/compositor/wayland_wrapper/wlcompositor.h | 2 ++ src/compositor/wayland_wrapper/wlinputdevice.cpp | 13 ++++++++++--- src/compositor/wayland_wrapper/wlinputdevice.h | 3 ++- src/compositor/wayland_wrapper/wloutput.cpp | 12 ++++++++++++ src/compositor/wayland_wrapper/wloutput.h | 5 ++++- src/compositor/wayland_wrapper/wlsurface.cpp | 4 ++++ .../waylandwindowmanagerintegration.cpp | 13 +++++++++++-- .../waylandwindowmanagerintegration.h | 2 ++ 14 files changed, 81 insertions(+), 14 deletions(-) diff --git a/src/compositor/compositor_api/waylandinput.cpp b/src/compositor/compositor_api/waylandinput.cpp index d0c45e9..2ae0604 100644 --- a/src/compositor/compositor_api/waylandinput.cpp +++ b/src/compositor/compositor_api/waylandinput.cpp @@ -50,6 +50,11 @@ WaylandInputDevice::WaylandInputDevice(WaylandCompositor *compositor) { } +WaylandInputDevice::~WaylandInputDevice() +{ + delete d; +} + void WaylandInputDevice::sendMousePressEvent(Qt::MouseButton button, const QPoint &localPos, const QPoint &globalPos) { d->sendMousePressEvent(button,localPos,globalPos); diff --git a/src/compositor/compositor_api/waylandinput.h b/src/compositor/compositor_api/waylandinput.h index 272d4c3..5f86b10 100644 --- a/src/compositor/compositor_api/waylandinput.h +++ b/src/compositor/compositor_api/waylandinput.h @@ -58,6 +58,7 @@ class Q_COMPOSITOR_EXPORT WaylandInputDevice { public: WaylandInputDevice(WaylandCompositor *compositor); + ~WaylandInputDevice(); void sendMousePressEvent(Qt::MouseButton button, const QPoint &localPos, const QPoint &globalPos = QPoint()); void sendMouseReleaseEvent(Qt::MouseButton button, const QPoint &localPos, const QPoint &globalPos = QPoint()); diff --git a/src/compositor/hardware_integration/graphicshardwareintegration.h b/src/compositor/hardware_integration/graphicshardwareintegration.h index aea1645..cad2882 100644 --- a/src/compositor/hardware_integration/graphicshardwareintegration.h +++ b/src/compositor/hardware_integration/graphicshardwareintegration.h @@ -52,6 +52,7 @@ class GraphicsHardwareIntegration { public: GraphicsHardwareIntegration(WaylandCompositor *compositor); + virtual ~GraphicsHardwareIntegration() { } virtual void initializeHardware(Wayland::Display *waylandDisplay) = 0; diff --git a/src/compositor/hardware_integration/xcomposite_glx/xcompositeglxintegration.cpp b/src/compositor/hardware_integration/xcomposite_glx/xcompositeglxintegration.cpp index faf7beb..a841826 100644 --- a/src/compositor/hardware_integration/xcomposite_glx/xcompositeglxintegration.cpp +++ b/src/compositor/hardware_integration/xcomposite_glx/xcompositeglxintegration.cpp @@ -81,6 +81,7 @@ GraphicsHardwareIntegration *GraphicsHardwareIntegration::createGraphicsHardware XCompositeGLXIntegration::XCompositeGLXIntegration(WaylandCompositor *compositor) : GraphicsHardwareIntegration(compositor) , mDisplay(0) + , mHandler(0) { QPlatformNativeInterface *nativeInterface = QGuiApplicationPrivate::platformIntegration()->nativeInterface(); if (nativeInterface) { @@ -93,10 +94,15 @@ XCompositeGLXIntegration::XCompositeGLXIntegration(WaylandCompositor *compositor mScreen = XDefaultScreen(mDisplay); } +XCompositeGLXIntegration::~XCompositeGLXIntegration() +{ + delete mHandler; +} + void XCompositeGLXIntegration::initializeHardware(Wayland::Display *waylandDisplay) { - XCompositeHandler *handler = new XCompositeHandler(m_compositor->handle(),mDisplay,m_compositor->window()); - wl_display_add_global(waylandDisplay->handle(),&wl_xcomposite_interface,handler,XCompositeHandler::xcomposite_bind_func); + mHandler = new XCompositeHandler(m_compositor->handle(),mDisplay,m_compositor->window()); + wl_display_add_global(waylandDisplay->handle(),&wl_xcomposite_interface,mHandler,XCompositeHandler::xcomposite_bind_func); QOpenGLContext *glContext = new QOpenGLContext(); glContext->create(); diff --git a/src/compositor/hardware_integration/xcomposite_glx/xcompositeglxintegration.h b/src/compositor/hardware_integration/xcomposite_glx/xcompositeglxintegration.h index e77e1f0..913a69a 100644 --- a/src/compositor/hardware_integration/xcomposite_glx/xcompositeglxintegration.h +++ b/src/compositor/hardware_integration/xcomposite_glx/xcompositeglxintegration.h @@ -49,10 +49,13 @@ #include #include +class XCompositeHandler; + class XCompositeGLXIntegration : public GraphicsHardwareIntegration { public: XCompositeGLXIntegration(WaylandCompositor *compositor); + ~XCompositeGLXIntegration(); void initializeHardware(Wayland::Display *waylandDisplay); @@ -65,6 +68,7 @@ private: Display *mDisplay; int mScreen; + XCompositeHandler *mHandler; }; #endif // XCOMPOSITEGLXINTEGRATION_H diff --git a/src/compositor/wayland_wrapper/wlcompositor.cpp b/src/compositor/wayland_wrapper/wlcompositor.cpp index 1e1765b..bd02b67 100644 --- a/src/compositor/wayland_wrapper/wlcompositor.cpp +++ b/src/compositor/wayland_wrapper/wlcompositor.cpp @@ -136,9 +136,9 @@ Compositor::Compositor(WaylandCompositor *qt_compositor) wl_display_add_global(m_display->handle(),&wl_output_interface, &m_output_global,OutputGlobal::output_bind_func); - wl_display_add_global(m_display->handle(), &wl_shell_interface, &m_shell, Shell::bind_func); - m_shell = new Shell(); + wl_display_add_global(m_display->handle(), &wl_shell_interface, m_shell, Shell::bind_func); + m_outputExtension = new OutputExtensionGlobal(this); m_surfaceExtension = new SurfaceExtensionGlobal(this); @@ -159,9 +159,19 @@ Compositor::Compositor(WaylandCompositor *qt_compositor) Compositor::~Compositor() { - delete m_default_input_device; + delete m_shell; + delete m_outputExtension; + delete m_surfaceExtension; + delete m_subSurfaceExtension; + delete m_touchExtension; + + delete m_default_wayland_input_device; delete m_data_device_manager; +#ifdef QT_COMPOSITOR_WAYLAND_GL + delete m_graphics_hw_integration; +#endif + delete m_display; } @@ -296,8 +306,8 @@ void Compositor::initializeHardwareIntegration() void Compositor::initializeDefaultInputDevice() { - WaylandInputDevice *defaultInput = new WaylandInputDevice(m_qt_compositor); - m_default_input_device = defaultInput->handle(); + m_default_wayland_input_device = new WaylandInputDevice(m_qt_compositor); + m_default_input_device = m_default_wayland_input_device->handle(); } void Compositor::initializeWindowManagerProtocol() diff --git a/src/compositor/wayland_wrapper/wlcompositor.h b/src/compositor/wayland_wrapper/wlcompositor.h index b2d4ef6..d8acad2 100644 --- a/src/compositor/wayland_wrapper/wlcompositor.h +++ b/src/compositor/wayland_wrapper/wlcompositor.h @@ -52,6 +52,7 @@ #include class WaylandCompositor; +class WaylandInputDevice; class GraphicsHardwareIntegration; class WindowManagerServerIntegration; class QMimeData; @@ -144,6 +145,7 @@ private: Display *m_display; /* Input */ + WaylandInputDevice *m_default_wayland_input_device; InputDevice *m_default_input_device; /* Output */ diff --git a/src/compositor/wayland_wrapper/wlinputdevice.cpp b/src/compositor/wayland_wrapper/wlinputdevice.cpp index b1c5cb7..edf55d7 100644 --- a/src/compositor/wayland_wrapper/wlinputdevice.cpp +++ b/src/compositor/wayland_wrapper/wlinputdevice.cpp @@ -61,6 +61,11 @@ InputDevice::InputDevice(WaylandInputDevice *handle, Compositor *compositor) wl_display_add_global(compositor->wl_display(),&wl_input_device_interface,this,InputDevice::bind_func); } +InputDevice::~InputDevice() +{ + qDeleteAll(m_data_devices); +} + void InputDevice::sendMousePressEvent(Qt::MouseButton button, const QPoint &localPos, const QPoint &globalPos) { sendMouseMoveEvent(localPos,globalPos); @@ -225,12 +230,14 @@ void InputDevice::setMouseFocus(Surface *surface, const QPoint &globalPos, const localPos.x(), localPos.y()); } -void InputDevice::cleanupDataDeviceForClient(struct wl_client *client) +void InputDevice::cleanupDataDeviceForClient(struct wl_client *client, bool destroyDev) { for (int i = 0; i < m_data_devices.size(); i++) { struct wl_resource *data_device_resource = m_data_devices.at(i)->dataDeviceResource(); if (data_device_resource->client == client) { + if (destroyDev) + delete m_data_devices.at(i); m_data_devices.removeAt(i); break; } @@ -239,7 +246,7 @@ void InputDevice::cleanupDataDeviceForClient(struct wl_client *client) void InputDevice::clientRequestedDataDevice(DataDeviceManager *data_device_manager, struct wl_client *client, uint32_t id) { - cleanupDataDeviceForClient(client); + cleanupDataDeviceForClient(client, false); DataDevice *dataDevice = new DataDevice(data_device_manager,client,id); m_data_devices.append(dataDevice); } @@ -337,7 +344,7 @@ void InputDevice::destroy_resource(wl_resource *resource) input_device->base()->pointer_focus_resource = 0; } - input_device->cleanupDataDeviceForClient(resource->client); + input_device->cleanupDataDeviceForClient(resource->client, true); wl_list_remove(&resource->link); diff --git a/src/compositor/wayland_wrapper/wlinputdevice.h b/src/compositor/wayland_wrapper/wlinputdevice.h index 05980b6..0519b75 100644 --- a/src/compositor/wayland_wrapper/wlinputdevice.h +++ b/src/compositor/wayland_wrapper/wlinputdevice.h @@ -62,6 +62,7 @@ class InputDevice : public Object { public: InputDevice(WaylandInputDevice *handle, Compositor *compositor); + ~InputDevice(); void sendMousePressEvent(Qt::MouseButton button, const QPoint &localPos, const QPoint &globalPos = QPoint()); void sendMouseReleaseEvent(Qt::MouseButton button, const QPoint &localPos, const QPoint &globalPos = QPoint()); @@ -91,7 +92,7 @@ public: WaylandInputDevice *handle() const; private: - void cleanupDataDeviceForClient(struct wl_client *client); + void cleanupDataDeviceForClient(struct wl_client *client, bool destroyDev); WaylandInputDevice *m_handle; Compositor *m_compositor; diff --git a/src/compositor/wayland_wrapper/wloutput.cpp b/src/compositor/wayland_wrapper/wloutput.cpp index 86b4d5b..deae56d 100644 --- a/src/compositor/wayland_wrapper/wloutput.cpp +++ b/src/compositor/wayland_wrapper/wloutput.cpp @@ -39,6 +39,7 @@ ****************************************************************************/ #include "wloutput.h" +#include "wlextendedoutput.h" #include #include #include @@ -53,6 +54,11 @@ OutputGlobal::OutputGlobal() m_geometry = QRect(QPoint(0, 0), screen->availableGeometry().size()); } +OutputGlobal::~OutputGlobal() +{ + qDeleteAll(m_outputs); +} + void OutputGlobal::setGeometry(const QRect &geometry) { m_geometry = geometry; @@ -71,6 +77,7 @@ void OutputGlobal::output_bind_func(struct wl_client *client, void *data, Output *output = new Output(output_global,client,version,id); output_global->registerResource(output->handle()); + output_global->m_outputs.append(output); } @@ -89,6 +96,11 @@ Output::Output(OutputGlobal *outputGlobal, wl_client *client, uint32_t version, } +Output::~Output() +{ + delete m_extended_output; +} + ExtendedOutput *Output::extendedOutput() const { return m_extended_output; diff --git a/src/compositor/wayland_wrapper/wloutput.h b/src/compositor/wayland_wrapper/wloutput.h index b637d2d..df7534f 100644 --- a/src/compositor/wayland_wrapper/wloutput.h +++ b/src/compositor/wayland_wrapper/wloutput.h @@ -44,7 +44,7 @@ #include "waylandresourcecollection.h" #include - +#include namespace Wayland { @@ -55,6 +55,7 @@ class OutputGlobal : public ResourceCollection { public: OutputGlobal(); + ~OutputGlobal(); void setGeometry(const QRect &geometry); QRect geometry() const { return m_geometry; } @@ -71,6 +72,7 @@ private: QRect m_geometry; int m_displayId; int m_numQueued; + QList m_outputs; }; @@ -78,6 +80,7 @@ class Output { public: Output(OutputGlobal *outputGlobal, wl_client *client, uint32_t version, uint32_t id); + ~Output(); OutputGlobal *outputGlobal() const; diff --git a/src/compositor/wayland_wrapper/wlsurface.cpp b/src/compositor/wayland_wrapper/wlsurface.cpp index 5d65849..2d96d6d 100644 --- a/src/compositor/wayland_wrapper/wlsurface.cpp +++ b/src/compositor/wayland_wrapper/wlsurface.cpp @@ -48,6 +48,7 @@ #include "wlextendedsurface.h" #include "wlsubsurface.h" #include "wlsurfacebuffer.h" +#include "wlshellsurface.h" #include #include @@ -90,6 +91,9 @@ Surface::Surface(struct wl_client *client, uint32_t id, Compositor *compositor) Surface::~Surface() { delete m_waylandSurface; + delete m_extendedSurface; + delete m_subSurface; + delete m_shellSurface; } WaylandSurface::Type Surface::type() const diff --git a/src/compositor/windowmanagerprotocol/waylandwindowmanagerintegration.cpp b/src/compositor/windowmanagerprotocol/waylandwindowmanagerintegration.cpp index 1bec03c..f7e08c8 100644 --- a/src/compositor/windowmanagerprotocol/waylandwindowmanagerintegration.cpp +++ b/src/compositor/windowmanagerprotocol/waylandwindowmanagerintegration.cpp @@ -51,6 +51,11 @@ WindowManagerServerIntegration::WindowManagerServerIntegration(QObject *parent) { } +WindowManagerServerIntegration::~WindowManagerServerIntegration() +{ + qDeleteAll(m_managedClients); +} + void WindowManagerServerIntegration::initialize(Wayland::Display *waylandDisplay) { wl_display_add_global(waylandDisplay->handle(),&wl_windowmanager_interface,this,WindowManagerServerIntegration::bind_func); @@ -69,7 +74,9 @@ WaylandManagedClient *WindowManagerServerIntegration::managedClient(wl_client *c void WindowManagerServerIntegration::mapClientToProcess(wl_client *client, uint32_t processId) { - WaylandManagedClient *managedClient = m_managedClients.value(client, new WaylandManagedClient); + WaylandManagedClient *managedClient = m_managedClients.value(client); + if (!managedClient) + managedClient = new WaylandManagedClient; managedClient->m_processId = processId; m_managedClients.insert(client, managedClient); } @@ -78,7 +85,9 @@ void WindowManagerServerIntegration::authenticateWithToken(wl_client *client, co { Q_ASSERT(token != 0 && *token != 0); - WaylandManagedClient *managedClient = m_managedClients.value(client, new WaylandManagedClient); + WaylandManagedClient *managedClient = m_managedClients.value(client); + if (!managedClient) + managedClient = new WaylandManagedClient; managedClient->m_authenticationToken = QByteArray(token); m_managedClients.insert(client, managedClient); diff --git a/src/compositor/windowmanagerprotocol/waylandwindowmanagerintegration.h b/src/compositor/windowmanagerprotocol/waylandwindowmanagerintegration.h index 1b49a47..2077a73 100644 --- a/src/compositor/windowmanagerprotocol/waylandwindowmanagerintegration.h +++ b/src/compositor/windowmanagerprotocol/waylandwindowmanagerintegration.h @@ -66,6 +66,8 @@ class Q_COMPOSITOR_EXPORT WindowManagerServerIntegration : public QObject, priva Q_OBJECT public: WindowManagerServerIntegration(QObject *parent = 0); + ~WindowManagerServerIntegration(); + void initialize(Wayland::Display *waylandDisplay); void removeClient(wl_client *client); -- 2.7.4