2022-05-10 10:06:48 +00:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
2011-09-14 02:03:34 +00:00
|
|
|
|
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
|
|
|
|
2017-08-29 14:21:17 +00:00
|
|
|
#include <QCommandLineParser>
|
|
|
|
#include <QCommandLineOption>
|
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);
|
|
|
|
|
2017-08-29 14:21:17 +00:00
|
|
|
QCoreApplication::setApplicationName("Qt HelloWindow GL Example");
|
|
|
|
QCoreApplication::setOrganizationName("QtProject");
|
|
|
|
QCoreApplication::setApplicationVersion(QT_VERSION_STR);
|
|
|
|
QCommandLineParser parser;
|
|
|
|
parser.setApplicationDescription(QCoreApplication::applicationName());
|
|
|
|
parser.addHelpOption();
|
|
|
|
parser.addVersionOption();
|
|
|
|
QCommandLineOption multipleOption("multiple", "Create multiple windows");
|
|
|
|
parser.addOption(multipleOption);
|
|
|
|
QCommandLineOption multipleSampleOption("multisample", "Multisampling");
|
|
|
|
parser.addOption(multipleSampleOption);
|
|
|
|
QCommandLineOption multipleScreenOption("multiscreen", "Run on multiple screens");
|
|
|
|
parser.addOption(multipleScreenOption);
|
|
|
|
QCommandLineOption timeoutOption("timeout", "Close after 10s");
|
|
|
|
parser.addOption(timeoutOption);
|
|
|
|
parser.process(app);
|
|
|
|
|
2014-10-16 11:35:33 +00:00
|
|
|
// Some platforms can only have one window per screen. Therefore we need to differentiate.
|
2017-08-29 14:21:17 +00:00
|
|
|
const bool multipleWindows = parser.isSet(multipleOption);
|
|
|
|
const bool multipleScreens = parser.isSet(multipleScreenOption);
|
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);
|
2017-08-29 14:21:17 +00:00
|
|
|
if (parser.isSet(multipleSampleOption))
|
2013-09-10 13:15:56 +00:00
|
|
|
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.
|
2017-08-29 14:21:17 +00:00
|
|
|
if (parser.isSet(timeoutOption))
|
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
|
|
|
}
|