summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/offscreen/qoffscreenintegration.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/platforms/offscreen/qoffscreenintegration.cpp')
-rw-r--r--src/plugins/platforms/offscreen/qoffscreenintegration.cpp112
1 files changed, 106 insertions, 6 deletions
diff --git a/src/plugins/platforms/offscreen/qoffscreenintegration.cpp b/src/plugins/platforms/offscreen/qoffscreenintegration.cpp
index 811e025f62..c9f97ce46a 100644
--- a/src/plugins/platforms/offscreen/qoffscreenintegration.cpp
+++ b/src/plugins/platforms/offscreen/qoffscreenintegration.cpp
@@ -54,6 +54,11 @@
#include <QtCore/private/qeventdispatcher_win_p.h>
#endif
+#include <QtCore/qfile.h>
+#include <QtCore/qjsonarray.h>
+#include <QtCore/qjsondocument.h>
+#include <QtCore/qjsonobject.h>
+#include <QtCore/qjsonvalue.h>
#include <QtGui/private/qpixmap_raster_p.h>
#include <QtGui/private/qguiapplication_p.h>
#include <qpa/qplatforminputcontextfactory_p.h>
@@ -104,14 +109,98 @@ QOffscreenIntegration::QOffscreenIntegration()
m_drag.reset(new QOffscreenDrag);
#endif
m_services.reset(new QPlatformServices);
-
- QWindowSystemInterface::handleScreenAdded(new QOffscreenScreen);
}
QOffscreenIntegration::~QOffscreenIntegration()
{
}
+/*
+ The offscren platform plugin is configurable with a JSON configuration
+ file. Write the config to disk and pass the file path as a platform argument:
+
+ ./myapp -platform offscreen:configfile=/path/to/config.json
+
+ The supported top-level config keys are:
+ {
+ "synchronousWindowSystemEvents": <bool>
+ "windowFrameMargins": <bool>,
+ "screens": [<screens>],
+ }
+
+ Screen:
+ {
+ "name" : string,
+ "x": int,
+ "y": int,
+ "width": int,
+ "height": int,
+ "logicalDpi": int,
+ "logicalBaseDpi": int,
+ "dpr": double,
+ }
+*/
+void QOffscreenIntegration::configure(const QStringList& paramList)
+{
+ // Use config file configuring platform plugin, if one was specified
+ bool hasConfigFile = false;
+ QString configFilePath;
+ for (const QString &param : paramList) {
+ // Look for "configfile=/path/to/file/"
+ QString configPrefix(QLatin1String("configfile="));
+ if (param.startsWith(configPrefix)) {
+ hasConfigFile = true;
+ configFilePath= param.mid(configPrefix.length());
+ }
+ }
+
+ // Create the default screen if there was no config file
+ if (!hasConfigFile) {
+ QOffscreenScreen *offscreenScreen = new QOffscreenScreen(this);
+ m_screens.append(offscreenScreen);
+ QWindowSystemInterface::handleScreenAdded(offscreenScreen);
+ return;
+ }
+
+ // Read config file
+ if (configFilePath.isEmpty())
+ qFatal("Missing file path for -configfile platform option");
+ QFile configFile(configFilePath);
+ if (!configFile.exists())
+ qFatal("Could not find platform config file %s", qPrintable(configFilePath));
+ if (!configFile.open(QIODevice::ReadOnly))
+ qFatal("Could not open platform config file for reading %s, %s", qPrintable(configFilePath), qPrintable(configFile.errorString()));
+
+ QByteArray json = configFile.readAll();
+ QJsonParseError error;
+ QJsonDocument config = QJsonDocument::fromJson(json, &error);
+ if (config.isNull())
+ qFatal("Platform config file parse error: %s", qPrintable(error.errorString()));
+
+ // Apply configuration (create screens)
+ bool synchronousWindowSystemEvents = config["synchronousWindowSystemEvents"].toBool(false);
+ QWindowSystemInterface::setSynchronousWindowSystemEvents(synchronousWindowSystemEvents);
+ m_windowFrameMarginsEnabled = config["windowFrameMargins"].toBool(true);
+ QJsonArray screens = config["screens"].toArray();
+ for (QJsonValue screenValue : screens) {
+ QJsonObject screen = screenValue.toObject();
+ if (screen.isEmpty()) {
+ qWarning("QOffscreenIntegration::initializeWithPlatformArguments: empty screen object");
+ continue;
+ }
+ QOffscreenScreen *offscreenScreen = new QOffscreenScreen(this);
+ offscreenScreen->m_name = screen["name"].toString();
+ offscreenScreen->m_geometry = QRect(screen["x"].toInt(0), screen["y"].toInt(0),
+ screen["width"].toInt(640), screen["height"].toInt(480));
+ offscreenScreen->m_logicalDpi = screen["logicalDpi"].toInt(96);
+ offscreenScreen->m_logicalBaseDpi = screen["logicalBaseDpi"].toInt(96);
+ offscreenScreen->m_dpr = screen["dpr"].toDouble(1.0);
+
+ m_screens.append(offscreenScreen);
+ QWindowSystemInterface::handleScreenAdded(offscreenScreen);
+ }
+}
+
void QOffscreenIntegration::initialize()
{
m_inputContext.reset(QPlatformInputContextFactory::create());
@@ -134,7 +223,7 @@ bool QOffscreenIntegration::hasCapability(QPlatformIntegration::Capability cap)
QPlatformWindow *QOffscreenIntegration::createPlatformWindow(QWindow *window) const
{
Q_UNUSED(window);
- QPlatformWindow *w = new QOffscreenWindow(window);
+ QPlatformWindow *w = new QOffscreenWindow(window, m_windowFrameMarginsEnabled);
w->requestActivateWindow();
return w;
}
@@ -203,14 +292,25 @@ QPlatformServices *QOffscreenIntegration::services() const
return m_services.data();
}
-QOffscreenIntegration *QOffscreenIntegration::createOffscreenIntegration()
+QOffscreenIntegration *QOffscreenIntegration::createOffscreenIntegration(const QStringList& paramList)
{
+ QOffscreenIntegration *offscreenIntegration = nullptr;
+
#if QT_CONFIG(xlib) && QT_CONFIG(opengl) && !QT_CONFIG(opengles2)
QByteArray glx = qgetenv("QT_QPA_OFFSCREEN_NO_GLX");
if (glx.isEmpty())
- return new QOffscreenX11Integration;
+ offscreenIntegration = new QOffscreenX11Integration;
+#else
+ offscreenIntegration = new QOffscreenIntegration;
#endif
- return new QOffscreenIntegration;
+
+ offscreenIntegration->configure(paramList);
+ return offscreenIntegration;
+}
+
+QList<QPlatformScreen *> QOffscreenIntegration::screens() const
+{
+ return m_screens;
}
QT_END_NAMESPACE