2011-09-14 02:03:34 +00:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
2016-01-22 12:24:00 +00:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2011-09-14 02:03:34 +00:00
|
|
|
**
|
|
|
|
** This file is part of the examples of the Qt Toolkit.
|
|
|
|
**
|
|
|
|
** $QT_BEGIN_LICENSE:BSD$
|
2016-01-22 12:24:00 +00:00
|
|
|
** Commercial License Usage
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
|
|
|
**
|
|
|
|
** BSD License Usage
|
|
|
|
** Alternatively, you may use this file under the terms of the BSD license
|
|
|
|
** as follows:
|
2011-09-14 02:03:34 +00:00
|
|
|
**
|
|
|
|
** "Redistribution and use in source and binary forms, with or without
|
|
|
|
** modification, are permitted provided that the following conditions are
|
|
|
|
** met:
|
|
|
|
** * Redistributions of source code must retain the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer.
|
|
|
|
** * Redistributions in binary form must reproduce the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer in
|
|
|
|
** the documentation and/or other materials provided with the
|
|
|
|
** distribution.
|
2015-02-13 11:15:33 +00:00
|
|
|
** * Neither the name of The Qt Company Ltd nor the names of its
|
|
|
|
** contributors may be used to endorse or promote products derived
|
|
|
|
** from this software without specific prior written permission.
|
2012-09-19 12:28:29 +00:00
|
|
|
**
|
2011-09-14 02:03:34 +00:00
|
|
|
**
|
|
|
|
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
2012-01-24 06:17:24 +00:00
|
|
|
**
|
2011-09-14 02:03:34 +00:00
|
|
|
** $QT_END_LICENSE$
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
2012-12-19 10:27:10 +00:00
|
|
|
#include "hellowindow.h"
|
|
|
|
|
Expose QPA API under qpa/*
The main reasons for doing this are:
1. _qpa.h end up in the master QtGui include file. QtGui is meant for
userland applications. qpa code is neither binary nor source compatible.
Inadvertant use of QPA api makes the user code binary-incompatible.
2. syncqt creates forwarding headers for non-private header files. This
gives people the impression that this is public API.
As discussed on the mailing list, even though QPA api is internal and subject
to change, it needs to treated differently from private headers since they
will be used by in-qtbase and out-of-qtbase plugins.
This commit does the following:
1. The _qpa in QPA header files is dropped.
2. syncqt now treats any file with qplatform prefix as a special file and
moves it to qpa/ directory. The recommended way of using QPA API in plugins
is: #include <qpa/qplatformfoo.h>. This allows the user include QPA API
from multiple modules (for example, qplatformfoo might be in QtPrintSupport)
3. The user needs to explicitly add QT += <module>-private to get access to
the qpa api.
4. Creates compat headers for the olden style qplatformfoo_qpa.h and QPlatformFoo
includes.
This commit does not change the cpp filenames. This requires a more careful
merging of existing non qpa cpp files and existing cpp files on a case by
case basis. This can be done at anytime.
The following files are not renamed as part of this changed but will be fixed
as part of a future change:
src/gui/kernel/qgenericpluginfactory_qpa.h
src/gui/kernel/qgenericplugin_qpa.h
src/gui/kernel/qwindowsysteminterface_qpa.h
files were renamed using
for x in `find . -name "qplatform*_qpa.h"`; do git mv $x "${x/_qpa.h/.h}"; done
for x in `find . -name "qplatform*_qpa_p.h"`; do git mv $x "${x/_qpa_p.h/_p.h}"; done
includes were renamed using script
for file in `find . -name "*.h" -or -name "*.cpp" -or -name "*.mm"`; do
sed -i -e 's,.*#.*include.*<\(Qt.*/\)\?\(QPlatform.*\)>,#include <qpa/\L\2.h>,g' \
-e 's,.*#.*include.*"\(Qt.*/\)\?\(QPlatform.*\)",#include <qpa/\L\2.h>,g' \
-e 's,.*#.*include.* "\(qplatform.*\)_qpa.h",#include <qpa/\L\1.h>,g' \
-e 's,.*#.*include.*"\(qplatform.*\)_qpa_p.h",#include <qpa/\L\1_p.h>,g' \
-e 's,.*#.*include.*<\(Qt.*/\|Qt.*/private/\|private/\)\?\(qplatform.*\)_qpa\(.*\)>,#include <qpa/\2\3>,g' \
-e 's,.*#.*include.*"\(Qt.*/\|Qt.*/private/\|private/\)\?\(qplatform.*\)_qpa\(.*\)",#include <qpa/\2\3>,g' \
$file
done
Change-Id: I04a350314a45746e3911f54b3b21ad03315afb67
Reviewed-by: Morten Johan Sørvig <morten.sorvig@nokia.com>
Reviewed-by: Samuel Rødal <samuel.rodal@nokia.com>
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@nokia.com>
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
Reviewed-by: Gunnar Sletta <gunnar.sletta@nokia.com>
2012-04-26 23:33:35 +00:00
|
|
|
#include <qpa/qplatformintegration.h>
|
2012-12-19 10:27:10 +00:00
|
|
|
|
|
|
|
#include <QGuiApplication>
|
2011-08-18 08:50:18 +00:00
|
|
|
#include <QScreen>
|
|
|
|
#include <QThread>
|
2011-04-27 15:49:30 +00:00
|
|
|
|
2012-12-19 10:27:10 +00:00
|
|
|
int main(int argc, char *argv[])
|
2011-04-27 15:49:30 +00:00
|
|
|
{
|
|
|
|
QGuiApplication app(argc, argv);
|
|
|
|
|
2014-10-16 11:35:33 +00:00
|
|
|
// Some platforms can only have one window per screen. Therefore we need to differentiate.
|
2014-08-02 17:42:15 +00:00
|
|
|
const bool multipleWindows = QGuiApplication::arguments().contains(QStringLiteral("--multiple"));
|
2014-10-16 11:35:33 +00:00
|
|
|
const bool multipleScreens = QGuiApplication::arguments().contains(QStringLiteral("--multiscreen"));
|
2011-11-21 11:18:15 +00:00
|
|
|
|
2011-08-18 08:50:18 +00:00
|
|
|
QScreen *screen = QGuiApplication::primaryScreen();
|
2011-06-07 15:25:22 +00:00
|
|
|
|
2011-08-18 08:50:18 +00:00
|
|
|
QRect screenGeometry = screen->availableGeometry();
|
|
|
|
|
|
|
|
QSurfaceFormat format;
|
|
|
|
format.setDepthBufferSize(16);
|
2013-09-10 13:15:56 +00:00
|
|
|
if (QGuiApplication::arguments().contains(QStringLiteral("--multisample")))
|
|
|
|
format.setSamples(4);
|
2011-08-18 08:50:18 +00:00
|
|
|
|
|
|
|
QPoint center = QPoint(screenGeometry.center().x(), screenGeometry.top() + 80);
|
|
|
|
QSize windowSize(400, 320);
|
|
|
|
int delta = 40;
|
|
|
|
|
2012-05-25 10:50:21 +00:00
|
|
|
QList<QWindow *> windows;
|
|
|
|
QSharedPointer<Renderer> rendererA(new Renderer(format));
|
|
|
|
|
2011-11-21 11:18:15 +00:00
|
|
|
HelloWindow *windowA = new HelloWindow(rendererA);
|
|
|
|
windowA->setGeometry(QRect(center, windowSize).translated(-windowSize.width() - delta / 2, 0));
|
2012-12-19 10:27:10 +00:00
|
|
|
windowA->setTitle(QStringLiteral("Thread A - Context A"));
|
2011-11-21 11:18:15 +00:00
|
|
|
windowA->setVisible(true);
|
2012-05-25 10:50:21 +00:00
|
|
|
windows.prepend(windowA);
|
2011-08-18 08:50:18 +00:00
|
|
|
|
2011-12-06 11:54:16 +00:00
|
|
|
QList<QThread *> renderThreads;
|
2011-11-21 11:18:15 +00:00
|
|
|
if (multipleWindows) {
|
2012-05-25 10:50:21 +00:00
|
|
|
QSharedPointer<Renderer> rendererB(new Renderer(format, rendererA.data()));
|
2011-08-18 08:50:18 +00:00
|
|
|
|
2011-12-06 11:54:16 +00:00
|
|
|
QThread *renderThread = new QThread;
|
2011-11-21 11:18:15 +00:00
|
|
|
rendererB->moveToThread(renderThread);
|
2011-12-06 11:54:16 +00:00
|
|
|
renderThreads << renderThread;
|
2011-06-07 15:25:22 +00:00
|
|
|
|
2011-11-21 11:18:15 +00:00
|
|
|
HelloWindow *windowB = new HelloWindow(rendererA);
|
|
|
|
windowB->setGeometry(QRect(center, windowSize).translated(delta / 2, 0));
|
2012-12-19 10:27:10 +00:00
|
|
|
windowB->setTitle(QStringLiteral("Thread A - Context A"));
|
2011-11-21 11:18:15 +00:00
|
|
|
windowB->setVisible(true);
|
2012-05-25 10:50:21 +00:00
|
|
|
windows.prepend(windowB);
|
2011-04-27 15:49:30 +00:00
|
|
|
|
2011-11-21 11:18:15 +00:00
|
|
|
HelloWindow *windowC = new HelloWindow(rendererB);
|
|
|
|
windowC->setGeometry(QRect(center, windowSize).translated(-windowSize.width() / 2, windowSize.height() + delta));
|
2012-12-19 10:27:10 +00:00
|
|
|
windowC->setTitle(QStringLiteral("Thread B - Context B"));
|
2011-11-21 11:18:15 +00:00
|
|
|
windowC->setVisible(true);
|
2012-05-25 10:50:21 +00:00
|
|
|
windows.prepend(windowC);
|
2014-10-16 11:35:33 +00:00
|
|
|
}
|
|
|
|
if (multipleScreens) {
|
2011-12-06 11:54:16 +00:00
|
|
|
for (int i = 1; i < QGuiApplication::screens().size(); ++i) {
|
|
|
|
QScreen *screen = QGuiApplication::screens().at(i);
|
2012-05-25 10:50:21 +00:00
|
|
|
QSharedPointer<Renderer> renderer(new Renderer(format, rendererA.data(), screen));
|
2011-12-06 11:54:16 +00:00
|
|
|
|
2014-10-16 11:35:33 +00:00
|
|
|
QThread *renderThread = new QThread;
|
2011-12-06 11:54:16 +00:00
|
|
|
renderer->moveToThread(renderThread);
|
2012-05-25 10:50:21 +00:00
|
|
|
renderThreads.prepend(renderThread);
|
2011-12-06 11:54:16 +00:00
|
|
|
|
|
|
|
QRect screenGeometry = screen->availableGeometry();
|
|
|
|
QPoint center = screenGeometry.center();
|
|
|
|
|
|
|
|
QSize windowSize = screenGeometry.size() * 0.8;
|
|
|
|
|
2014-10-16 11:35:33 +00:00
|
|
|
HelloWindow *window = new HelloWindow(renderer, screen);
|
2011-12-06 11:54:16 +00:00
|
|
|
window->setGeometry(QRect(center, windowSize).translated(-windowSize.width() / 2, -windowSize.height() / 2));
|
|
|
|
|
|
|
|
QChar id = QChar('B' + i);
|
2012-12-19 10:27:10 +00:00
|
|
|
window->setTitle(QStringLiteral("Thread ") + id + QStringLiteral(" - Context ") + id);
|
2011-12-06 11:54:16 +00:00
|
|
|
window->setVisible(true);
|
2012-05-25 10:50:21 +00:00
|
|
|
windows.prepend(window);
|
2011-12-06 11:54:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < renderThreads.size(); ++i) {
|
2015-08-28 13:16:57 +00:00
|
|
|
QObject::connect(qGuiApp, &QGuiApplication::lastWindowClosed, renderThreads.at(i), &QThread::quit);
|
2011-12-06 11:54:16 +00:00
|
|
|
renderThreads.at(i)->start();
|
2011-11-21 11:18:15 +00:00
|
|
|
}
|
2011-08-18 08:50:18 +00:00
|
|
|
|
2014-10-16 11:35:33 +00:00
|
|
|
// Quit after 10 seconds. For platforms that do not have windows that are closeable.
|
|
|
|
if (QCoreApplication::arguments().contains(QStringLiteral("--timeout")))
|
2015-08-28 13:16:57 +00:00
|
|
|
QTimer::singleShot(10000, qGuiApp, &QCoreApplication::quit);
|
2014-10-16 11:35:33 +00:00
|
|
|
|
2012-05-25 10:50:21 +00:00
|
|
|
const int exitValue = app.exec();
|
2011-08-18 08:50:18 +00:00
|
|
|
|
2014-10-16 11:35:33 +00:00
|
|
|
for (int i = 0; i < renderThreads.size(); ++i) {
|
|
|
|
renderThreads.at(i)->quit(); // some platforms may not have windows to close so ensure quit()
|
2011-12-06 11:54:16 +00:00
|
|
|
renderThreads.at(i)->wait();
|
2014-10-16 11:35:33 +00:00
|
|
|
}
|
2012-12-19 10:27:10 +00:00
|
|
|
|
2012-05-25 10:50:21 +00:00
|
|
|
qDeleteAll(windows);
|
|
|
|
qDeleteAll(renderThreads);
|
|
|
|
|
|
|
|
return exitValue;
|
2011-04-27 15:49:30 +00:00
|
|
|
}
|