Compositor memory leak fixes
[profile/ivi/qtwayland.git] / src / compositor / wayland_wrapper / wlcompositor.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the Qt Compositor.
7 **
8 ** $QT_BEGIN_LICENSE:BSD$
9 ** You may use this file under the terms of the BSD license as follows:
10 **
11 ** "Redistribution and use in source and binary forms, with or without
12 ** modification, are permitted provided that the following conditions are
13 ** met:
14 **   * Redistributions of source code must retain the above copyright
15 **     notice, this list of conditions and the following disclaimer.
16 **   * Redistributions in binary form must reproduce the above copyright
17 **     notice, this list of conditions and the following disclaimer in
18 **     the documentation and/or other materials provided with the
19 **     distribution.
20 **   * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
21 **     the names of its contributors may be used to endorse or promote
22 **     products derived from this software without specific prior written
23 **     permission.
24 **
25 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
36 **
37 ** $QT_END_LICENSE$
38 **
39 ****************************************************************************/
40
41 #ifndef WL_COMPOSITOR_H
42 #define WL_COMPOSITOR_H
43
44 #include "waylandexport.h"
45
46 #include <QtCore/QSet>
47
48 #include "wloutput.h"
49 #include "wldisplay.h"
50 #include "wlshmbuffer.h"
51
52 #include <wayland-server.h>
53
54 class WaylandCompositor;
55 class WaylandInputDevice;
56 class GraphicsHardwareIntegration;
57 class WindowManagerServerIntegration;
58 class QMimeData;
59
60 namespace Wayland {
61
62 class Surface;
63 class InputDevice;
64 class DataDeviceManager;
65 class OutputExtensionGlobal;
66 class SurfaceExtensionGlobal;
67 class SubSurfaceExtensionGlobal;
68 class Shell;
69 class TouchExtensionGlobal;
70
71 class Q_COMPOSITOR_EXPORT Compositor : public QObject
72 {
73     Q_OBJECT
74
75 public:
76     Compositor(WaylandCompositor *qt_compositor);
77     ~Compositor();
78
79     void frameFinished(Surface *surface = 0);
80
81     //these 3 functions will be removed if noone steps up soon.
82     Surface *getSurfaceFromWinId(uint winId) const;
83     struct wl_client *getClientFromWinId(uint winId) const;
84     QImage image(uint winId) const;
85
86     InputDevice *defaultInputDevice(); //we just have 1 default device for now (since QPA doesn't give us anything else)
87
88     void createSurface(struct wl_client *client, uint32_t id);
89     void surfaceDestroyed(Surface *surface);
90     void markSurfaceAsDirty(Surface *surface);
91
92     void destroyClientForSurface(Surface *surface);
93
94     static uint currentTimeMsecs();
95
96     QWindow *window() const;
97
98     GraphicsHardwareIntegration *graphicsHWIntegration() const;
99     void initializeHardwareIntegration();
100     void initializeDefaultInputDevice();
101     void initializeWindowManagerProtocol();
102     void enableSubSurfaceExtension();
103     bool setDirectRenderSurface(Surface *surface);
104     Surface *directRenderSurface() const {return m_directRenderSurface;}
105
106     QList<Surface*> surfacesForClient(wl_client* client);
107
108     WaylandCompositor *waylandCompositor() const { return m_qt_compositor; }
109
110     struct wl_display *wl_display() const { return m_display->handle(); }
111
112     static Compositor *instance();
113
114     QList<struct wl_client *> clients() const;
115
116     WindowManagerServerIntegration *windowManagerIntegration() const { return m_windowManagerIntegration; }
117
118     void setScreenOrientation(Qt::ScreenOrientation orientation);
119     Qt::ScreenOrientation screenOrientation() const;
120     void setOutputGeometry(const QRect &geometry);
121     QRect outputGeometry() const;
122
123     void enableTouchExtension();
124     TouchExtensionGlobal *touchExtension() { return m_touchExtension; }
125     void configureTouchExtension(int flags);
126
127     bool isDragging() const;
128     void sendDragMoveEvent(const QPoint &global, const QPoint &local, Surface *surface);
129     void sendDragEndEvent();
130
131     typedef void (*RetainedSelectionFunc)(QMimeData *, void *);
132     void setRetainedSelectionWatcher(RetainedSelectionFunc func, void *param);
133     void overrideSelection(QMimeData *data);
134
135     bool wantsRetainedSelection() const;
136     void feedRetainedSelectionData(QMimeData *data);
137
138 public slots:
139     void releaseBuffer(void*);
140
141 private slots:
142     void processWaylandEvents();
143
144 private:
145     Display *m_display;
146
147     /* Input */
148     WaylandInputDevice *m_default_wayland_input_device;
149     InputDevice *m_default_input_device;
150
151     /* Output */
152     //make this a list of the available screens
153     OutputGlobal m_output_global;
154     /* shm/*/
155     ShmHandler m_shm;
156
157     DataDeviceManager *m_data_device_manager;
158
159     QList<Surface *> m_surfaces;
160     QSet<Surface *> m_dirty_surfaces;
161
162     /* Render state */
163     uint32_t m_current_frame;
164     int m_last_queued_buf;
165
166     wl_event_loop *m_loop;
167
168     WaylandCompositor *m_qt_compositor;
169     Qt::ScreenOrientation m_orientation;
170
171     Surface *m_directRenderSurface;
172
173 #ifdef QT_COMPOSITOR_WAYLAND_GL
174     GraphicsHardwareIntegration *m_graphics_hw_integration;
175 #endif
176
177     //extensions
178     WindowManagerServerIntegration *m_windowManagerIntegration;
179
180
181     Shell *m_shell;
182     OutputExtensionGlobal *m_outputExtension;
183     SurfaceExtensionGlobal *m_surfaceExtension;
184     SubSurfaceExtensionGlobal *m_subSurfaceExtension;
185     TouchExtensionGlobal *m_touchExtension;
186
187     static void bind_func(struct wl_client *client, void *data,
188                           uint32_t version, uint32_t id);
189
190     RetainedSelectionFunc m_retainNotify;
191     void *m_retainNotifyParam;
192 };
193
194 }
195
196 #endif //WL_COMPOSITOR_H