28
28
#include "window.h"
32
31
#include <QGuiApplication>
32
#include <private/qguiapplication_p.h>
33
33
#include <qpa/qplatformnativeinterface.h>
34
34
#include <qpa/qplatforminputcontextfactory_p.h>
35
35
#include <qpa/qplatforminputcontext.h>
77
77
, mClipboard(new UbuntuClipboard)
78
78
, mScaleFactor(1.0)
81
QStringList args = QCoreApplication::arguments();
83
QByteArray sessionName = generateSessionName(args);
84
setupDescription(sessionName);
87
83
// Create new application instance
88
84
mInstance = u_application_instance_new_from_description_with_options(mDesc, mOptions);
95
91
mMirConnection = u_application_instance_get_mir_connection(mInstance);
97
// Choose the default surface format suited to the Mir platform
98
QSurfaceFormat defaultFormat;
99
defaultFormat.setRedBufferSize(8);
100
defaultFormat.setGreenBufferSize(8);
101
defaultFormat.setBlueBufferSize(8);
102
QSurfaceFormat::setDefaultFormat(defaultFormat);
104
93
// Initialize EGL.
94
ASSERT(eglBindAPI(EGL_OPENGL_ES_API) == EGL_TRUE);
105
96
mEglNativeDisplay = mir_connection_get_egl_native_display(mMirConnection);
106
97
ASSERT((mEglDisplay = eglGetDisplay(mEglNativeDisplay)) != EGL_NO_DISPLAY);
107
98
ASSERT(eglInitialize(mEglDisplay, nullptr, nullptr) == EGL_TRUE);
100
// Configure EGL buffers format for all Windows.
101
mSurfaceFormat.setRedBufferSize(8);
102
mSurfaceFormat.setGreenBufferSize(8);
103
mSurfaceFormat.setBlueBufferSize(8);
104
mSurfaceFormat.setAlphaBufferSize(8);
105
mSurfaceFormat.setDepthBufferSize(24);
106
mSurfaceFormat.setStencilBufferSize(8);
107
if (!qEnvironmentVariableIsEmpty("QTUBUNTU_MULTISAMPLE")) {
108
mSurfaceFormat.setSamples(4);
109
qCDebug(ubuntumirclient, "setting MSAA to 4 samples");
111
#ifdef QTUBUNTU_USE_OPENGL
112
mSurfaceFormat.setRenderableType(QSurfaceFormat::OpenGL);
114
mSurfaceFormat.setRenderableType(QSurfaceFormat::OpenGLES);
117
mEglConfig = q_configFromGLFormat(mEglDisplay, mSurfaceFormat, true);
110
120
void UbuntuClientIntegration::initialize()
151
161
return mServices;
154
void UbuntuClientIntegration::setupOptions(QStringList &args)
164
void UbuntuClientIntegration::setupOptions()
166
QStringList args = QCoreApplication::arguments();
156
167
int argc = args.size() + 1;
157
168
char **argv = new char*[argc];
158
169
for (int i = 0; i < argc - 1; i++)
169
void UbuntuClientIntegration::setupDescription(QByteArray &sessionName)
180
void UbuntuClientIntegration::setupDescription()
171
182
mDesc = u_application_description_new();
173
UApplicationId* id = u_application_id_new_from_stringn(sessionName.data(), sessionName.count());
183
UApplicationId* id = u_application_id_new_from_stringn("QtUbuntu", 8);
174
184
u_application_description_set_application_id(mDesc, id);
176
186
UApplicationLifecycleDelegate* delegate = u_application_lifecycle_delegate_new();
180
190
u_application_description_set_application_lifecycle_delegate(mDesc, delegate);
183
QByteArray UbuntuClientIntegration::generateSessionName(QStringList &args)
185
// Try to come up with some meaningful session name to uniquely identify this session,
186
// helping with shell debugging
188
if (args.count() == 0) {
189
return QByteArray("QtUbuntu");
190
} if (args[0].contains("qmlscene")) {
191
return generateSessionNameFromQmlFile(args);
193
// use the executable name
194
QFileInfo fileInfo(args[0]);
195
return fileInfo.fileName().toLocal8Bit();
199
QByteArray UbuntuClientIntegration::generateSessionNameFromQmlFile(QStringList &args)
201
Q_FOREACH (QString arg, args) {
202
if (arg.endsWith(".qml")) {
203
QFileInfo fileInfo(arg);
204
return fileInfo.fileName().toLocal8Bit();
212
193
QPlatformWindow* UbuntuClientIntegration::createPlatformWindow(QWindow* window) const
214
return new UbuntuWindow(window, mClipboard, mInput, mNativeInterface, mEglDisplay, mMirConnection);
195
return const_cast<UbuntuClientIntegration*>(this)->createPlatformWindow(window);
198
QPlatformWindow* UbuntuClientIntegration::createPlatformWindow(QWindow* window)
200
return new UbuntuWindow(window, mClipboard, mInput, mNativeInterface, mEglDisplay, mEglConfig, mMirConnection);
217
203
bool UbuntuClientIntegration::hasCapability(QPlatformIntegration::Capability cap) const
254
240
QPlatformOpenGLContext* UbuntuClientIntegration::createPlatformOpenGLContext(
255
241
QOpenGLContext* context) const
257
QSurfaceFormat format(context->format());
243
return const_cast<UbuntuClientIntegration*>(this)->createPlatformOpenGLContext(context);
259
auto platformContext = new UbuntuOpenGLContext(format, context->shareHandle(), mEglDisplay);
260
if (!platformContext->isValid()) {
261
// Older Intel Atom-based devices only support OpenGL 1.4 compatibility profile but by default
262
// QML asks for at least OpenGL 2.0. The XCB GLX backend ignores this request and returns a
263
// 1.4 context, but the XCB EGL backend tries to honour it, and fails. The 1.4 context appears to
264
// have sufficient capabilities on MESA (i915) to render correctly however. So reduce the default
265
// requested OpenGL version to 1.0 to ensure EGL will give us a working context (lp:1549455).
266
static const bool isMesa = QString(eglQueryString(mEglDisplay, EGL_VENDOR)).contains(QStringLiteral("Mesa"));
268
qCDebug(ubuntumirclient, "Attempting to choose OpenGL 1.4 context which may suit Mesa");
269
format.setMajorVersion(1);
270
format.setMinorVersion(4);
271
delete platformContext;
272
platformContext = new UbuntuOpenGLContext(format, context->shareHandle(), mEglDisplay);
275
return platformContext;
246
QPlatformOpenGLContext* UbuntuClientIntegration::createPlatformOpenGLContext(
247
QOpenGLContext* context)
249
return new UbuntuOpenGLContext(mSurfaceFormat, static_cast<UbuntuOpenGLContext*>(context->shareHandle()),
250
mEglDisplay, mEglConfig);
278
253
QStringList UbuntuClientIntegration::themeNames() const