Make wayland actually a module
[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 <QtCore/QSet>
45
46 #include "wloutput.h"
47 #include "wldisplay.h"
48 #include "wlshmbuffer.h"
49 #include "wlshell.h"
50
51 #include <wayland-server.h>
52
53 class WaylandCompositor;
54 class GraphicsHardwareIntegration;
55 class WindowManagerServerIntegration;
56
57 namespace Wayland {
58
59 class Surface;
60 class InputDevice;
61 class DataDeviceManager;
62
63 class Compositor : public QObject
64 {
65     Q_OBJECT
66
67 public:
68     Compositor(WaylandCompositor *qt_compositor);
69     ~Compositor();
70
71     void frameFinished(Surface *surface = 0);
72     void setInputFocus(Surface *surface);
73     void setKeyFocus(Surface *surface);
74     Surface *keyFocus() const;
75     void setPointerFocus(Surface *surface, const QPoint &point = QPoint());
76     Surface *pointerFocus() const;
77
78     Surface *getSurfaceFromWinId(uint winId) const;
79     struct wl_client *getClientFromWinId(uint winId) const;
80     QImage image(uint winId) const;
81
82     InputDevice *inputDevice() { return m_input; }
83     InputDevice *defaultInputDevice();
84
85     void createSurface(struct wl_client *client, int id);
86     void surfaceDestroyed(Surface *surface);
87     void markSurfaceAsDirty(Surface *surface);
88
89     void destroyClientForSurface(Surface *surface);
90
91     static uint currentTimeMsecs();
92
93     QWindow *window() const;
94
95     GraphicsHardwareIntegration *graphicsHWIntegration() const;
96     void initializeHardwareIntegration();
97     void initializeWindowManagerProtocol();
98     bool setDirectRenderSurface(Surface *surface);
99     Surface *directRenderSurface() const {return m_directRenderSurface;}
100
101     QList<Surface*> surfacesForClient(wl_client* client);
102
103     WaylandCompositor *qtCompositor() const { return m_qt_compositor; }
104
105     struct wl_display *wl_display() { return m_display->handle(); }
106
107     static Compositor *instance();
108
109     QList<struct wl_client *> clients() const;
110
111     void setScreenOrientation(Qt::ScreenOrientation orientation);
112     void setOutputGeometry(const QRect &geometry);
113
114     bool isDragging() const;
115     void sendDragMoveEvent(const QPoint &global, const QPoint &local, Surface *surface);
116     void sendDragEndEvent();
117
118 public slots:
119     void releaseBuffer(void*);
120
121 signals:
122     void clientAdded(wl_client *client);
123
124 private slots:
125     void processWaylandEvents();
126     void windowPropertyChanged(wl_client *client, wl_surface *surface, const QString &name, const QVariant &value);
127
128 private:
129     Display *m_display;
130
131     /* Input */
132     InputDevice *m_input;
133
134     /* Output */
135     //make this a list of the available screens
136     Output m_output;
137
138     Shell m_shell;
139
140     /* shm/*/
141     ShmHandler m_shm;
142
143     DataDeviceManager *m_data_device_manager;
144
145     QList<Surface *> m_surfaces;
146     QSet<Surface *> m_dirty_surfaces;
147
148     /* Render state */
149     uint32_t m_current_frame;
150     int m_last_queued_buf;
151
152     wl_event_loop *m_loop;
153
154     WaylandCompositor *m_qt_compositor;
155     Qt::ScreenOrientation m_orientation;
156
157     Surface *m_pointerFocusSurface;
158     Surface *m_keyFocusSurface;
159     Surface *m_directRenderSurface;
160
161 #ifdef QT_COMPOSITOR_WAYLAND_GL
162     GraphicsHardwareIntegration *m_graphics_hw_integration;
163 #endif
164     WindowManagerServerIntegration *m_windowManagerWaylandProtocol;
165
166     static void bind_func(struct wl_client *client, void *data,
167                           uint32_t version, uint32_t id);
168 };
169
170 }
171
172 #endif //WL_COMPOSITOR_H