Prevented crash due to dangling pointer in QWaylandInputDevice.
[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 ** No Commercial Usage
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
14 ** this package.
15 **
16 ** GNU Lesser General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU Lesser
18 ** General Public License version 2.1 as published by the Free Software
19 ** Foundation and appearing in the file LICENSE.LGPL included in the
20 ** packaging of this file.  Please review the following information to
21 ** ensure the GNU Lesser General Public License version 2.1 requirements
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23 **
24 ** In addition, as a special exception, Nokia gives you certain additional
25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27 **
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
30 **
31 **
32 **
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 QWaylandInputDevice;
53 class QSocketNotifier;
54 class QWaylandBuffer;
55 class QPlatformScreen;
56 class QWaylandScreen;
57 class QWaylandGLIntegration;
58 class QWaylandDisplay : public QObject {
59     Q_OBJECT
60
61 public:
62     QWaylandDisplay(void);
63     ~QWaylandDisplay(void);
64
65     QList<QPlatformScreen *> screens() const { return mScreens; }
66     struct wl_surface *createSurface(void *handle);
67     struct wl_buffer *createShmBuffer(int fd, int width, int height,
68                                       uint32_t stride,
69                                       struct wl_visual *visual);
70     struct wl_visual *rgbVisual();
71     struct wl_visual *argbVisual();
72     struct wl_visual *argbPremultipliedVisual();
73
74 #ifdef QT_WAYLAND_GL_SUPPORT
75     QWaylandGLIntegration *eglIntegration();
76 #endif
77     void setCursor(QWaylandBuffer *buffer, int32_t x, int32_t y);
78
79     void syncCallback(wl_display_sync_func_t func, void *data);
80     void frameCallback(wl_display_frame_func_t func, void *data);
81
82     struct wl_display *wl_display() const { return mDisplay; }
83
84     QList<QWaylandInputDevice *> inputDevices() const { return mInputDevices; }
85
86 public slots:
87     void createNewScreen(struct wl_output *output, QRect geometry);
88     void readEvents();
89     void flushRequests();
90
91 private:
92     void waitForScreens();
93     void displayHandleGlobal(uint32_t id,
94                              const QByteArray &interface,
95                              uint32_t version);
96
97     struct wl_display *mDisplay;
98     struct wl_compositor *mCompositor;
99     struct wl_shm *mShm;
100     struct wl_shell *mShell;
101     QList<QPlatformScreen *> mScreens;
102     QList<QWaylandInputDevice *> mInputDevices;
103
104     QSocketNotifier *mReadNotifier;
105     int mFd;
106     bool mScreensInitialized;
107
108     uint32_t mSocketMask;
109
110     static const struct wl_output_listener outputListener;
111     static int sourceUpdate(uint32_t mask, void *data);
112     static void displayHandleGlobal(struct wl_display *display,
113                                     uint32_t id,
114                                     const char *interface,
115                                     uint32_t version, void *data);
116     static void outputHandleGeometry(void *data,
117                                      struct wl_output *output,
118                                      int32_t x, int32_t y,
119                                      int32_t width, int32_t height);
120
121 #ifdef QT_WAYLAND_GL_SUPPORT
122     QWaylandGLIntegration *mEglIntegration;
123 #endif
124
125     static void shellHandleConfigure(void *data, struct wl_shell *shell,
126                                      uint32_t time, uint32_t edges,
127                                      struct wl_surface *surface,
128                                      int32_t width, int32_t height);
129
130     static const struct wl_shell_listener shellListener;
131 };
132
133 #endif // QWAYLANDDISPLAY_H