Compositor memory leak fixes
authorLaszlo Agocs <laszlo.p.agocs@nokia.com>
Tue, 14 Feb 2012 15:33:29 +0000 (16:33 +0100)
committerJørgen Lind <jorgen.lind@nokia.com>
Wed, 15 Feb 2012 19:37:14 +0000 (20:37 +0100)
Change-Id: Ia0510e00ffc925cde98ec5345a8129d1979c478c
Reviewed-by: Jørgen Lind <jorgen.lind@nokia.com>
14 files changed:
src/compositor/compositor_api/waylandinput.cpp
src/compositor/compositor_api/waylandinput.h
src/compositor/hardware_integration/graphicshardwareintegration.h
src/compositor/hardware_integration/xcomposite_glx/xcompositeglxintegration.cpp
src/compositor/hardware_integration/xcomposite_glx/xcompositeglxintegration.h
src/compositor/wayland_wrapper/wlcompositor.cpp
src/compositor/wayland_wrapper/wlcompositor.h
src/compositor/wayland_wrapper/wlinputdevice.cpp
src/compositor/wayland_wrapper/wlinputdevice.h
src/compositor/wayland_wrapper/wloutput.cpp
src/compositor/wayland_wrapper/wloutput.h
src/compositor/wayland_wrapper/wlsurface.cpp
src/compositor/windowmanagerprotocol/waylandwindowmanagerintegration.cpp
src/compositor/windowmanagerprotocol/waylandwindowmanagerintegration.h

index d0c45e9..2ae0604 100644 (file)
@@ -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);
index 272d4c3..5f86b10 100644 (file)
@@ -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());
index aea1645..cad2882 100644 (file)
@@ -52,6 +52,7 @@ class GraphicsHardwareIntegration
 {
 public:
     GraphicsHardwareIntegration(WaylandCompositor *compositor);
+    virtual ~GraphicsHardwareIntegration() { }
 
     virtual void initializeHardware(Wayland::Display *waylandDisplay) = 0;
 
index faf7beb..a841826 100644 (file)
@@ -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();
index e77e1f0..913a69a 100644 (file)
 #include <GL/glx.h>
 #include <GL/glxext.h>
 
+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
index 1e1765b..bd02b67 100644 (file)
@@ -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()
index b2d4ef6..d8acad2 100644 (file)
@@ -52,6 +52,7 @@
 #include <wayland-server.h>
 
 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 */
index b1c5cb7..edf55d7 100644 (file)
@@ -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);
 
index 05980b6..0519b75 100644 (file)
@@ -62,6 +62,7 @@ class InputDevice : public Object<struct wl_input_device>
 {
 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;
index 86b4d5b..deae56d 100644 (file)
@@ -39,6 +39,7 @@
 ****************************************************************************/
 
 #include "wloutput.h"
+#include "wlextendedoutput.h"
 #include <QGuiApplication>
 #include <QtGui/QScreen>
 #include <QRect>
@@ -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;
index b637d2d..df7534f 100644 (file)
@@ -44,7 +44,7 @@
 #include "waylandresourcecollection.h"
 
 #include <QtCore/QRect>
-
+#include <QtCore/QList>
 
 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<Output *> 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;
 
index 5d65849..2d96d6d 100644 (file)
@@ -48,6 +48,7 @@
 #include "wlextendedsurface.h"
 #include "wlsubsurface.h"
 #include "wlsurfacebuffer.h"
+#include "wlshellsurface.h"
 
 #include <QtCore/QDebug>
 #include <QTouchEvent>
@@ -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
index 1bec03c..f7e08c8 100644 (file)
@@ -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);
 
index 1b49a47..2077a73 100644 (file)
@@ -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);