Make QPlatformIntegration not have a factory for eventdispatcher
[profile/ivi/qtwayland.git] / src / plugins / platforms / wayland / qwaylanddisplay.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
6 **
7 ** This file is part of the plugins of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 **
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 **
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
29 **
30 ** Other Usage
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef QWAYLANDDISPLAY_H
43 #define QWAYLANDDISPLAY_H
44
45 #include <QtCore/QObject>
46 #include <QtCore/QRect>
47
48 #include <QtCore/QWaitCondition>
49
50 #include <wayland-client.h>
51
52 class QAbstractEventDispatcher;
53 class QWaylandInputDevice;
54 class QSocketNotifier;
55 class QWaylandBuffer;
56 class QPlatformScreen;
57 class QWaylandScreen;
58 class QWaylandGLIntegration;
59 class QWaylandWindowManagerIntegration;
60
61 class QWaylandDisplay : public QObject {
62     Q_OBJECT
63
64 public:
65     QWaylandDisplay(void);
66     ~QWaylandDisplay(void);
67
68     QList<QPlatformScreen *> screens() const { return mScreens; }
69     struct wl_surface *createSurface(void *handle);
70     struct wl_buffer *createShmBuffer(int fd, int width, int height,
71                                       uint32_t stride,
72                                       struct wl_visual *visual);
73     struct wl_visual *rgbVisual();
74     struct wl_visual *argbVisual();
75     struct wl_visual *argbPremultipliedVisual();
76
77 #ifdef QT_WAYLAND_GL_SUPPORT
78     QWaylandGLIntegration *eglIntegration();
79 #endif
80
81 #ifdef QT_WAYLAND_WINDOWMANAGER_SUPPORT
82     QWaylandWindowManagerIntegration *windowManagerIntegration();
83 #endif
84
85     void setCursor(QWaylandBuffer *buffer, int32_t x, int32_t y);
86
87     void syncCallback(wl_display_sync_func_t func, void *data);
88     void frameCallback(wl_display_frame_func_t func, struct wl_surface *surface, void *data);
89
90     struct wl_display *wl_display() const { return mDisplay; }
91     struct wl_shell *wl_shell() const { return mShell; }
92
93     QList<QWaylandInputDevice *> inputDevices() const { return mInputDevices; }
94
95 public slots:
96     void createNewScreen(struct wl_output *output, QRect geometry);
97     void readEvents();
98     void blockingReadEvents();
99     void flushRequests();
100
101 private:
102     void waitForScreens();
103     void displayHandleGlobal(uint32_t id,
104                              const QByteArray &interface,
105                              uint32_t version);
106
107     struct wl_display *mDisplay;
108     struct wl_compositor *mCompositor;
109     struct wl_shm *mShm;
110     struct wl_shell *mShell;
111     QList<QPlatformScreen *> mScreens;
112     QList<QWaylandInputDevice *> mInputDevices;
113
114     QSocketNotifier *mReadNotifier;
115     int mFd;
116     bool mScreensInitialized;
117
118     uint32_t mSocketMask;
119
120     struct wl_visual *argb_visual, *premultiplied_argb_visual, *rgb_visual;
121
122     static const struct wl_output_listener outputListener;
123     static const struct wl_compositor_listener compositorListener;
124     static int sourceUpdate(uint32_t mask, void *data);
125     static void displayHandleGlobal(struct wl_display *display,
126                                     uint32_t id,
127                                     const char *interface,
128                                     uint32_t version, void *data);
129     static void outputHandleGeometry(void *data,
130                                      struct wl_output *output,
131                                      int32_t x, int32_t y,
132                                      int32_t width, int32_t height,
133                                      int subpixel,
134                                      const char *make,
135                                      const char *model);
136     static void mode(void *data,
137                      struct wl_output *wl_output,
138                      uint32_t flags,
139                      int width,
140                      int height,
141                      int refresh);
142
143     static void handleVisual(void *data,
144                                        struct wl_compositor *compositor,
145                                        uint32_t id, uint32_t token);
146
147 #ifdef QT_WAYLAND_GL_SUPPORT
148     QWaylandGLIntegration *mEglIntegration;
149 #endif
150
151 #ifdef QT_WAYLAND_WINDOWMANAGER_SUPPORT
152     QWaylandWindowManagerIntegration *mWindowManagerIntegration;
153 #endif
154
155     static void shellHandleConfigure(void *data, struct wl_shell *shell,
156                                      uint32_t time, uint32_t edges,
157                                      struct wl_surface *surface,
158                                      int32_t width, int32_t height);
159
160     static const struct wl_shell_listener shellListener;
161 };
162
163 #endif // QWAYLANDDISPLAY_H