Added surface_extension and output_extension
[profile/ivi/qtwayland.git] / src / compositor / wayland_wrapper / wlcompositor.h
1 /****************************************************************************
2 **
3 ** This file is part of QtCompositor**
4 **
5 ** Copyright © 2010 Nokia Corporation and/or its subsidiary(-ies).
6 ** All rights reserved.
7 **
8 ** Contact:  Nokia Corporation qt-info@nokia.com
9 **
10 ** You may use this file under the terms of the BSD license as follows:
11 **
12 ** Redistribution and use in source and binary forms, with or without
13 ** modification, are permitted provided that the following conditions are
14 ** met:
15 **
16 ** Redistributions of source code must retain the above copyright
17 ** notice, this list of conditions and the following disclaimer.
18 **
19 ** Redistributions in binary form must reproduce the above copyright
20 ** notice, this list of conditions and the following disclaimer in the
21 ** documentation and/or other materials provided with the distribution.
22 **
23 ** Neither the name of Nokia Corporation and its Subsidiary(-ies) nor the
24 ** names of its contributors may be used to endorse or promote products
25 ** derived from this software without specific prior written permission.
26 **
27 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
30 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
32 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
33 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
34 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
35 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
36 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
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 #include "wlshell.h"
52
53 #include <wayland-server.h>
54
55 class WaylandCompositor;
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
68 class Q_COMPOSITOR_EXPORT Compositor : public QObject
69 {
70     Q_OBJECT
71
72 public:
73     Compositor(WaylandCompositor *qt_compositor);
74     ~Compositor();
75
76     void frameFinished(Surface *surface = 0);
77     void setInputFocus(Surface *surface);
78     void setKeyFocus(Surface *surface);
79     Surface *keyFocus() const;
80     void setPointerFocus(Surface *surface, const QPoint &point = QPoint());
81     Surface *pointerFocus() const;
82
83     Surface *getSurfaceFromWinId(uint winId) const;
84     struct wl_client *getClientFromWinId(uint winId) const;
85     QImage image(uint winId) const;
86
87     InputDevice *inputDevice() { return m_input; }
88     InputDevice *defaultInputDevice();
89
90     void createSurface(struct wl_client *client, int id);
91     void surfaceDestroyed(Surface *surface);
92     void markSurfaceAsDirty(Surface *surface);
93
94     void destroyClientForSurface(Surface *surface);
95
96     static uint currentTimeMsecs();
97
98     QWindow *window() const;
99
100     GraphicsHardwareIntegration *graphicsHWIntegration() const;
101     void initializeHardwareIntegration();
102     void initializeWindowManagerProtocol();
103     bool setDirectRenderSurface(Surface *surface);
104     Surface *directRenderSurface() const {return m_directRenderSurface;}
105
106     QList<Surface*> surfacesForClient(wl_client* client);
107
108     WaylandCompositor *qtCompositor() 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     void setOutputGeometry(const QRect &geometry);
120
121     bool isDragging() const;
122     void sendDragMoveEvent(const QPoint &global, const QPoint &local, Surface *surface);
123     void sendDragEndEvent();
124
125     typedef void (*RetainedSelectionFunc)(QMimeData *, void *);
126     void setRetainedSelectionWatcher(RetainedSelectionFunc func, void *param);
127     void overrideSelection(QMimeData *data);
128
129     bool wantsRetainedSelection() const;
130     void feedRetainedSelectionData(QMimeData *data);
131
132 public slots:
133     void releaseBuffer(void*);
134
135 signals:
136     void clientAdded(wl_client *client);
137
138 private slots:
139     void processWaylandEvents();
140
141 private:
142     Display *m_display;
143
144     /* Input */
145     InputDevice *m_input;
146
147     /* Output */
148     //make this a list of the available screens
149     OutputGlobal m_output_global;
150
151     Shell m_shell;
152
153     /* shm/*/
154     ShmHandler m_shm;
155
156     DataDeviceManager *m_data_device_manager;
157
158     QList<Surface *> m_surfaces;
159     QSet<Surface *> m_dirty_surfaces;
160
161     /* Render state */
162     uint32_t m_current_frame;
163     int m_last_queued_buf;
164
165     wl_event_loop *m_loop;
166
167     WaylandCompositor *m_qt_compositor;
168     Qt::ScreenOrientation m_orientation;
169
170     Surface *m_pointerFocusSurface;
171     Surface *m_keyFocusSurface;
172     Surface *m_directRenderSurface;
173
174 #ifdef QT_COMPOSITOR_WAYLAND_GL
175     GraphicsHardwareIntegration *m_graphics_hw_integration;
176 #endif
177
178     //extensions
179     WindowManagerServerIntegration *m_windowManagerIntegration;
180
181     OutputExtensionGlobal *m_outputExtension;
182     SurfaceExtensionGlobal *m_surfaceExtension;
183
184     static void bind_func(struct wl_client *client, void *data,
185                           uint32_t version, uint32_t id);
186
187     RetainedSelectionFunc m_retainNotify;
188     void *m_retainNotifyParam;
189 };
190
191 }
192
193 #endif //WL_COMPOSITOR_H