1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the Qt Compositor.
8 ** $QT_BEGIN_LICENSE:BSD$
9 ** You may use this file under the terms of the BSD license as follows:
11 ** "Redistribution and use in source and binary forms, with or without
12 ** modification, are permitted provided that the following conditions are
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
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
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."
39 ****************************************************************************/
44 #include "waylandexport.h"
46 #include "wlsurfacebuffer.h"
47 #include "waylandsurface.h"
49 #include "waylandobject.h"
51 #include <QtCore/QRect>
52 #include <QtGui/QImage>
54 #include <QtCore/QTextStream>
55 #include <QtCore/QMetaType>
57 #ifdef QT_COMPOSITOR_WAYLAND_GL
58 #include <QtGui/QOpenGLContext>
59 #include <QtGui/qopengl.h>
62 #include <wayland-util.h>
70 class ExtendedSurface;
74 class Q_COMPOSITOR_EXPORT Surface : public Object<struct wl_surface>
77 Surface(struct wl_client *client, uint32_t id, Compositor *compositor);
80 WaylandSurface::Type type() const;
81 bool isYInverted() const;
85 uint id() const { return base()->resource.object.id; }
88 QPointF nonAdjustedPos() const;
89 void setPos(const QPointF &pos);
92 void setSize(const QSize &size);
94 QRegion inputRegion() const;
95 QRegion opaqueRegion() const;
99 #ifdef QT_COMPOSITOR_WAYLAND_GL
100 GLuint textureId(QOpenGLContext *context) const;
103 void sendFrameCallback();
105 void frameFinished();
107 WaylandSurface *waylandSurface() const;
109 QPoint lastMousePos() const;
111 void setExtendedSurface(ExtendedSurface *extendedSurface);
112 ExtendedSurface *extendedSurface() const;
114 void setSubSurface(SubSurface *subSurface);
115 SubSurface *subSurface() const;
117 void setShellSurface(ShellSurface *shellSurface);
118 ShellSurface *shellSurface() const;
120 Compositor *compositor() const;
122 void damage(const QRect &rect);
124 static const struct wl_surface_interface surface_interface;
126 QString title() const { return m_title; }
127 void setTitle(const QString &title);
129 bool transientInactive() const { return m_transientInactive; }
130 void setTransientInactive(bool v) { m_transientInactive = v; }
133 Q_DISABLE_COPY(Surface)
135 Compositor *m_compositor;
136 WaylandSurface *m_waylandSurface;
138 SurfaceBuffer *m_backBuffer;
139 SurfaceBuffer *m_frontBuffer;
140 QList<SurfaceBuffer *> m_bufferQueue;
141 bool m_surfaceMapped;
143 QPoint m_lastLocalMousePos;
144 QPoint m_lastGlobalMousePos;
146 struct wl_list m_frame_callback_list;
148 ExtendedSurface *m_extendedSurface;
149 SubSurface *m_subSurface;
150 ShellSurface *m_shellSurface;
152 QRegion m_inputRegion;
153 QRegion m_opaqueRegion;
155 static const int buffer_pool_size = 3;
156 SurfaceBuffer *m_bufferPool[buffer_pool_size];
161 bool m_transientInactive;
163 inline SurfaceBuffer *currentSurfaceBuffer() const;
164 bool advanceBufferQueue();
166 SurfaceBuffer *createSurfaceBuffer(struct wl_buffer *buffer);
167 void frameFinishedInternal();
170 void attach(struct wl_buffer *buffer);
172 static void surface_destroy(struct wl_client *client, struct wl_resource *_surface);
173 static void surface_attach(struct wl_client *client, struct wl_resource *surface,
174 struct wl_resource *buffer, int x, int y);
175 static void surface_damage(struct wl_client *client, struct wl_resource *_surface,
176 int32_t x, int32_t y, int32_t width, int32_t height);
177 static void surface_frame(struct wl_client *client, struct wl_resource *resource,
179 static void surface_set_opaque_region(struct wl_client *client, struct wl_resource *resource,
180 struct wl_resource *region);
181 static void surface_set_input_region(struct wl_client *client, struct wl_resource *resource,
182 struct wl_resource *region);
186 inline SurfaceBuffer *Surface::currentSurfaceBuffer() const {
187 return m_backBuffer? m_backBuffer : m_frontBuffer;
192 #endif //WL_SURFACE_H