~saviq/qtubuntu/revert-occlude-lp1620297

« back to all changes in this revision

Viewing changes to src/ubuntumirclient/integration.cpp

  • Committer: CI Train Bot
  • Author(s): Michael Terry
  • Date: 2016-05-27 13:05:24 UTC
  • mfrom: (316.3.4 arm64)
  • Revision ID: ci-train-bot@canonical.com-20160527130524-4m0pe3k6ekiozl11
Build qtubuntu for arm64, and drop ancient qthybris transition package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
#include "window.h"
29
29
 
30
30
// Qt
31
 
#include <QFileInfo>
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)
79
79
{
80
 
    {
81
 
        QStringList args = QCoreApplication::arguments();
82
 
        setupOptions(args);
83
 
        QByteArray sessionName = generateSessionName(args);
84
 
        setupDescription(sessionName);
85
 
    }
 
80
    setupOptions();
 
81
    setupDescription();
86
82
 
87
83
    // Create new application instance
88
84
    mInstance = u_application_instance_new_from_description_with_options(mDesc, mOptions);
94
90
 
95
91
    mMirConnection = u_application_instance_get_mir_connection(mInstance);
96
92
 
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);
103
 
 
104
93
    // Initialize EGL.
 
94
    ASSERT(eglBindAPI(EGL_OPENGL_ES_API) == EGL_TRUE);
 
95
 
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);
 
99
 
 
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");
 
110
    }
 
111
#ifdef QTUBUNTU_USE_OPENGL
 
112
    mSurfaceFormat.setRenderableType(QSurfaceFormat::OpenGL);
 
113
#else
 
114
    mSurfaceFormat.setRenderableType(QSurfaceFormat::OpenGLES);
 
115
#endif
 
116
 
 
117
    mEglConfig = q_configFromGLFormat(mEglDisplay, mSurfaceFormat, true);
108
118
}
109
119
 
110
120
void UbuntuClientIntegration::initialize()
151
161
    return mServices;
152
162
}
153
163
 
154
 
void UbuntuClientIntegration::setupOptions(QStringList &args)
 
164
void UbuntuClientIntegration::setupOptions()
155
165
{
 
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++)
166
177
    delete [] argv;
167
178
}
168
179
 
169
 
void UbuntuClientIntegration::setupDescription(QByteArray &sessionName)
 
180
void UbuntuClientIntegration::setupDescription()
170
181
{
171
182
    mDesc = u_application_description_new();
172
 
 
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);
175
185
 
176
186
    UApplicationLifecycleDelegate* delegate = u_application_lifecycle_delegate_new();
180
190
    u_application_description_set_application_lifecycle_delegate(mDesc, delegate);
181
191
}
182
192
 
183
 
QByteArray UbuntuClientIntegration::generateSessionName(QStringList &args)
184
 
{
185
 
    // Try to come up with some meaningful session name to uniquely identify this session,
186
 
    // helping with shell debugging
187
 
 
188
 
    if (args.count() == 0) {
189
 
        return QByteArray("QtUbuntu");
190
 
    } if (args[0].contains("qmlscene")) {
191
 
        return generateSessionNameFromQmlFile(args);
192
 
    } else {
193
 
        // use the executable name
194
 
        QFileInfo fileInfo(args[0]);
195
 
        return fileInfo.fileName().toLocal8Bit();
196
 
    }
197
 
}
198
 
 
199
 
QByteArray UbuntuClientIntegration::generateSessionNameFromQmlFile(QStringList &args)
200
 
{
201
 
    Q_FOREACH (QString arg, args) {
202
 
        if (arg.endsWith(".qml")) {
203
 
            QFileInfo fileInfo(arg);
204
 
            return fileInfo.fileName().toLocal8Bit();
205
 
        }
206
 
    }
207
 
 
208
 
    // give up
209
 
    return "qmlscene";
210
 
}
211
 
 
212
193
QPlatformWindow* UbuntuClientIntegration::createPlatformWindow(QWindow* window) const
213
194
{
214
 
    return new UbuntuWindow(window, mClipboard, mInput, mNativeInterface, mEglDisplay, mMirConnection);
 
195
    return const_cast<UbuntuClientIntegration*>(this)->createPlatformWindow(window);
 
196
}
 
197
 
 
198
QPlatformWindow* UbuntuClientIntegration::createPlatformWindow(QWindow* window)
 
199
{
 
200
    return new UbuntuWindow(window, mClipboard, mInput, mNativeInterface, mEglDisplay, mEglConfig, mMirConnection);
215
201
}
216
202
 
217
203
bool UbuntuClientIntegration::hasCapability(QPlatformIntegration::Capability cap) const
254
240
QPlatformOpenGLContext* UbuntuClientIntegration::createPlatformOpenGLContext(
255
241
        QOpenGLContext* context) const
256
242
{
257
 
    QSurfaceFormat format(context->format());
 
243
    return const_cast<UbuntuClientIntegration*>(this)->createPlatformOpenGLContext(context);
 
244
}
258
245
 
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"));
267
 
        if (isMesa) {
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);
273
 
        }
274
 
    }
275
 
    return platformContext;
 
246
QPlatformOpenGLContext* UbuntuClientIntegration::createPlatformOpenGLContext(
 
247
        QOpenGLContext* context)
 
248
{
 
249
    return new UbuntuOpenGLContext(mSurfaceFormat, static_cast<UbuntuOpenGLContext*>(context->shareHandle()),
 
250
                                   mEglDisplay, mEglConfig);
276
251
}
277
252
 
278
253
QStringList UbuntuClientIntegration::themeNames() const