~saviq/qtubuntu/revert-occlude-lp1620297

« back to all changes in this revision

Viewing changes to src/ubuntumirclient/integration.cpp

  • Committer: Bileto Bot
  • Author(s): Gerry Boland
  • Date: 2016-08-09 23:00:16 UTC
  • mfrom: (328.3.4 eglconvenience-retry)
  • Revision ID: ci-train-bot@canonical.com-20160809230016-nutnvedrejhvzrdc
Reapply rev 324 plus fix: EGL convenience, plus workaround for hybris not supporting GLESv3. (LP: #1507817, #1594198)

Approved by: Daniel d'Andrada, Unity8 CI Bot

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
// Qt
31
31
#include <QFileInfo>
32
32
#include <QGuiApplication>
33
 
#include <private/qguiapplication_p.h>
34
33
#include <qpa/qplatformnativeinterface.h>
35
34
#include <qpa/qplatforminputcontextfactory_p.h>
36
35
#include <qpa/qplatforminputcontext.h>
95
94
 
96
95
    mMirConnection = u_application_instance_get_mir_connection(mInstance);
97
96
 
 
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
 
98
104
    // Initialize EGL.
99
 
    ASSERT(eglBindAPI(EGL_OPENGL_ES_API) == EGL_TRUE);
100
 
 
101
105
    mEglNativeDisplay = mir_connection_get_egl_native_display(mMirConnection);
102
106
    ASSERT((mEglDisplay = eglGetDisplay(mEglNativeDisplay)) != EGL_NO_DISPLAY);
103
107
    ASSERT(eglInitialize(mEglDisplay, nullptr, nullptr) == EGL_TRUE);
104
 
 
105
 
    // Configure EGL buffers format for all Windows.
106
 
    mSurfaceFormat.setRedBufferSize(8);
107
 
    mSurfaceFormat.setGreenBufferSize(8);
108
 
    mSurfaceFormat.setBlueBufferSize(8);
109
 
    mSurfaceFormat.setAlphaBufferSize(8);
110
 
    mSurfaceFormat.setDepthBufferSize(24);
111
 
    mSurfaceFormat.setStencilBufferSize(8);
112
 
    if (!qEnvironmentVariableIsEmpty("QTUBUNTU_MULTISAMPLE")) {
113
 
        mSurfaceFormat.setSamples(4);
114
 
        qCDebug(ubuntumirclient, "setting MSAA to 4 samples");
115
 
    }
116
 
#ifdef QTUBUNTU_USE_OPENGL
117
 
    mSurfaceFormat.setRenderableType(QSurfaceFormat::OpenGL);
118
 
#else
119
 
    mSurfaceFormat.setRenderableType(QSurfaceFormat::OpenGLES);
120
 
#endif
121
 
 
122
 
    mEglConfig = q_configFromGLFormat(mEglDisplay, mSurfaceFormat, true);
123
108
}
124
109
 
125
110
void UbuntuClientIntegration::initialize()
226
211
 
227
212
QPlatformWindow* UbuntuClientIntegration::createPlatformWindow(QWindow* window) const
228
213
{
229
 
    return new UbuntuWindow(window, mClipboard, mInput, mNativeInterface, mEglDisplay, mEglConfig, mMirConnection);
 
214
    return new UbuntuWindow(window, mClipboard, mInput, mNativeInterface, mEglDisplay, mMirConnection);
230
215
}
231
216
 
232
217
bool UbuntuClientIntegration::hasCapability(QPlatformIntegration::Capability cap) const
269
254
QPlatformOpenGLContext* UbuntuClientIntegration::createPlatformOpenGLContext(
270
255
        QOpenGLContext* context) const
271
256
{
272
 
    return new UbuntuOpenGLContext(mSurfaceFormat, static_cast<UbuntuOpenGLContext*>(context->shareHandle()),
273
 
                                   mEglDisplay, mEglConfig);
 
257
    QSurfaceFormat format(context->format());
 
258
 
 
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;
274
276
}
275
277
 
276
278
QStringList UbuntuClientIntegration::themeNames() const