Inform the platform plugin when direct rendering is active
[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 #include <QtGui/QWindow>
48
49 #include "wloutput.h"
50 #include "wldisplay.h"
51
52 #include <wayland-server.h>
53
54 class WaylandCompositor;
55 class WaylandInputDevice;
56 class GraphicsHardwareIntegration;
57 class WindowManagerServerIntegration;
58 class QMimeData;
59 class QPlatformScreenPageFlipper;
60 class QPlatformScreenBuffer;
61
62 namespace Wayland {
63
64 class Surface;
65 class SurfaceBuffer;
66 class InputDevice;
67 class DataDeviceManager;
68 class OutputExtensionGlobal;
69 class SurfaceExtensionGlobal;
70 class SubSurfaceExtensionGlobal;
71 class Shell;
72 class TouchExtensionGlobal;
73 class QtKeyExtensionGlobal;
74
75 class Q_COMPOSITOR_EXPORT Compositor : public QObject
76 {
77     Q_OBJECT
78
79 public:
80     Compositor(WaylandCompositor *qt_compositor);
81     ~Compositor();
82
83     void frameFinished(Surface *surface = 0);
84
85     //these 3 functions will be removed if noone steps up soon.
86     Surface *getSurfaceFromWinId(uint winId) const;
87     struct wl_client *getClientFromWinId(uint winId) const;
88     QImage image(uint winId) const;
89
90     InputDevice *defaultInputDevice(); //we just have 1 default device for now (since QPA doesn't give us anything else)
91
92     void createSurface(struct wl_client *client, uint32_t id);
93     void surfaceDestroyed(Surface *surface);
94     void markSurfaceAsDirty(Surface *surface);
95
96     void destroyClient(WaylandClient *client);
97
98     static uint currentTimeMsecs();
99
100     QWindow *window() const;
101
102     GraphicsHardwareIntegration *graphicsHWIntegration() const;
103     void initializeHardwareIntegration();
104     void initializeDefaultInputDevice();
105     void initializeWindowManagerProtocol();
106     void enableSubSurfaceExtension();
107     bool setDirectRenderSurface(Surface *surface, QOpenGLContext *context);
108     Surface *directRenderSurface() const {return m_directRenderSurface;}
109     QOpenGLContext *directRenderContext() const {return m_directRenderContext;}
110     QPlatformScreenPageFlipper *pageFlipper() const { return m_pageFlipper; }
111     void setDirectRenderingActive(bool active);
112
113     QList<Surface*> surfaces() const { return m_surfaces; }
114     QList<Surface*> surfacesForClient(wl_client* client);
115     WaylandCompositor *waylandCompositor() const { return m_qt_compositor; }
116
117     struct wl_display *wl_display() const { return m_display->handle(); }
118
119     static Compositor *instance();
120
121     QList<struct wl_client *> clients() const;
122
123     WindowManagerServerIntegration *windowManagerIntegration() const { return m_windowManagerIntegration; }
124
125     void setScreenOrientation(Qt::ScreenOrientation orientation);
126     Qt::ScreenOrientation screenOrientation() const;
127     void setOutputGeometry(const QRect &geometry);
128     QRect outputGeometry() const;
129     void setOutputRefreshRate(int rate);
130     int outputRefreshRate() const;
131
132     void setClientFullScreenHint(bool value);
133
134     TouchExtensionGlobal *touchExtension() { return m_touchExtension; }
135     void configureTouchExtension(int flags);
136
137     QtKeyExtensionGlobal *qtkeyExtension() { return m_qtkeyExtension; }
138
139     bool isDragging() const;
140     void sendDragMoveEvent(const QPoint &global, const QPoint &local, Surface *surface);
141     void sendDragEndEvent();
142
143     typedef void (*RetainedSelectionFunc)(QMimeData *, void *);
144     void setRetainedSelectionWatcher(RetainedSelectionFunc func, void *param);
145     void overrideSelection(QMimeData *data);
146
147     bool wantsRetainedSelection() const;
148     void feedRetainedSelectionData(QMimeData *data);
149
150     void scheduleReleaseBuffer(SurfaceBuffer *screenBuffer);
151 private slots:
152
153     void releaseBuffer(SurfaceBuffer *screenBuffer);
154     void processWaylandEvents();
155
156 private:
157     Display *m_display;
158
159     /* Input */
160     WaylandInputDevice *m_default_wayland_input_device;
161     InputDevice *m_default_input_device;
162
163     /* Output */
164     //make this a list of the available screens
165     OutputGlobal m_output_global;
166     //This one should be part of the outputs
167     QPlatformScreenPageFlipper *m_pageFlipper;
168
169     DataDeviceManager *m_data_device_manager;
170
171     QList<Surface *> m_surfaces;
172     QSet<Surface *> m_dirty_surfaces;
173
174     /* Render state */
175     uint32_t m_current_frame;
176     int m_last_queued_buf;
177
178     wl_event_loop *m_loop;
179
180     WaylandCompositor *m_qt_compositor;
181     Qt::ScreenOrientation m_orientation;
182
183     Surface *m_directRenderSurface;
184     QOpenGLContext *m_directRenderContext;
185     bool m_directRenderActive;
186
187 #ifdef QT_COMPOSITOR_WAYLAND_GL
188     GraphicsHardwareIntegration *m_graphics_hw_integration;
189 #endif
190
191     //extensions
192     WindowManagerServerIntegration *m_windowManagerIntegration;
193
194     Shell *m_shell;
195     OutputExtensionGlobal *m_outputExtension;
196     SurfaceExtensionGlobal *m_surfaceExtension;
197     SubSurfaceExtensionGlobal *m_subSurfaceExtension;
198     TouchExtensionGlobal *m_touchExtension;
199     QtKeyExtensionGlobal *m_qtkeyExtension;
200
201     static void bind_func(struct wl_client *client, void *data,
202                           uint32_t version, uint32_t id);
203
204     RetainedSelectionFunc m_retainNotify;
205     void *m_retainNotifyParam;
206 };
207
208 }
209
210 #endif //WL_COMPOSITOR_H