1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the config.tests of the Qt Toolkit.
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
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.
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.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
40 ****************************************************************************/
42 #include "qwaylandwindow.h"
44 #include "qwaylanddisplay.h"
45 #include "qwaylandscreen.h"
46 #include "qwaylandbuffer.h"
48 #include <QtGui/QWidget>
49 #include <QtGui/QWindowSystemInterface>
53 QWaylandWindow::QWaylandWindow(QWidget *window)
54 : QPlatformWindow(window)
55 , mDisplay(QWaylandScreen::waylandScreenFromWidget(window)->display())
57 , mWaitingForFrameSync(false)
62 mSurface = mDisplay->createSurface(this);
65 QWaylandWindow::~QWaylandWindow()
68 wl_surface_destroy(mSurface);
71 WId QWaylandWindow::winId() const
76 void QWaylandWindow::setParent(const QPlatformWindow *parent)
79 qWarning("Sub window is not supported");
82 void QWaylandWindow::setVisible(bool visible)
84 if (!mSurface && visible) {
85 mSurface = mDisplay->createSurface(this);
90 wl_surface_map_toplevel(mSurface);
92 wl_surface_destroy(mSurface);
97 void QWaylandWindow::configure(uint32_t time, uint32_t edges,
99 int32_t width, int32_t height)
103 QRect geometry = QRect(x, y, width, height);
105 setGeometry(geometry);
107 QWindowSystemInterface::handleGeometryChange(widget(), geometry);
110 void QWaylandWindow::attach(QWaylandBuffer *buffer)
114 wl_surface_attach(mSurface, buffer->buffer(),0,0);
119 void QWaylandWindow::damage(const QRegion ®ion)
121 //We have to do sync stuff before calling damage, or we might
122 //get a frame callback before we get the timestamp
123 mDisplay->frameCallback(QWaylandWindow::frameCallback, this);
124 mWaitingForFrameSync = true;
126 QVector<QRect> rects = region.rects();
127 for (int i = 0; i < rects.size(); i++) {
128 const QRect rect = rects.at(i);
129 wl_surface_damage(mSurface,
130 rect.x(), rect.y(), rect.width(), rect.height());
134 void QWaylandWindow::newSurfaceCreated()
137 wl_surface_attach(mSurface,mBuffer->buffer(),0,0);
141 void QWaylandWindow::frameCallback(void *data, uint32_t time)
144 QWaylandWindow *self = static_cast<QWaylandWindow*>(data);
145 self->mWaitingForFrameSync = false;
148 void QWaylandWindow::waitForFrameSync()
150 mDisplay->flushRequests();
151 while (mWaitingForFrameSync)
152 mDisplay->readEvents();