[plugins/qpa] Support SharingPlatformContext on the existing eglSurface and eglconfig
Summary: So far SharingPlatformContext was only used if the OpenGL context supports EGL_KHR_surfaceless_context. If not supported, KWin tried to create a context through the Wayland API. Unfortunately on hwcomposer platform this results in a crash as libhybris only supports the init of EGLDisplay for one native platform. This change tries to also use the SharingPlatformContext if there is an OpenGL context in general. It reuses the native EGLSurface created for the compositing scene and makes its own OpenGL context current on that surface, too. As KWin creates an FBO, it never renders to it, so it shouldn't matter at all. In order to prevent EGL_BAD_MATCH errors when making Qt's OpenGL context current also the EGLConfig from the scene is used to create the context. Test Plan: Tested on Nexus5 with qtvirtualkeyboard in KWin Reviewers: #kwin, #plasma_on_wayland Subscribers: plasma-devel, kwin Tags: #plasma_on_wayland, #kwin Differential Revision: https://phabricator.kde.org/D2231icc-effect-5.14.5
parent
9d7ef58b2b
commit
44843f462f
|
@ -39,17 +39,17 @@ public:
|
|||
EGLContext context() const {
|
||||
return m_context;
|
||||
}
|
||||
|
||||
static void unbindWaylandDisplay();
|
||||
|
||||
protected:
|
||||
AbstractEglBackend();
|
||||
EGLSurface surface() const {
|
||||
return m_surface;
|
||||
}
|
||||
EGLConfig config() const {
|
||||
return m_config;
|
||||
}
|
||||
|
||||
static void unbindWaylandDisplay();
|
||||
|
||||
protected:
|
||||
AbstractEglBackend();
|
||||
void setEglDisplay(const EGLDisplay &display);
|
||||
void setSurface(const EGLSurface &surface) {
|
||||
m_surface = surface;
|
||||
|
|
20
platform.cpp
20
platform.cpp
|
@ -274,6 +274,26 @@ EGLContext Platform::sceneEglContext() const
|
|||
return EGL_NO_CONTEXT;
|
||||
}
|
||||
|
||||
EGLSurface Platform::sceneEglSurface() const
|
||||
{
|
||||
if (Compositor *c = Compositor::self()) {
|
||||
if (SceneOpenGL *s = dynamic_cast<SceneOpenGL*>(c->scene())) {
|
||||
return static_cast<AbstractEglBackend*>(s->backend())->surface();
|
||||
}
|
||||
}
|
||||
return EGL_NO_SURFACE;
|
||||
}
|
||||
|
||||
EGLConfig Platform::sceneEglConfig() const
|
||||
{
|
||||
if (Compositor *c = Compositor::self()) {
|
||||
if (SceneOpenGL *s = dynamic_cast<SceneOpenGL*>(c->scene())) {
|
||||
return static_cast<AbstractEglBackend*>(s->backend())->config();
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
QSize Platform::screenSize() const
|
||||
{
|
||||
return QSize();
|
||||
|
|
|
@ -71,6 +71,15 @@ public:
|
|||
* The EGLContext used by the compositing scene.
|
||||
**/
|
||||
virtual EGLContext sceneEglContext() const;
|
||||
/**
|
||||
* The first (in case of multiple) EGLSurface used by the compositing scene.
|
||||
**/
|
||||
EGLSurface sceneEglSurface() const;
|
||||
|
||||
/**
|
||||
* The EglConfig used by the compositing scene.
|
||||
**/
|
||||
EGLConfig sceneEglConfig() const;
|
||||
|
||||
/**
|
||||
* Implementing subclasses should provide a size in case the backend represents
|
||||
|
|
|
@ -93,11 +93,11 @@ static QSurfaceFormat formatFromConfig(EGLDisplay dpy, EGLConfig config)
|
|||
return format;
|
||||
}
|
||||
|
||||
AbstractPlatformContext::AbstractPlatformContext(QOpenGLContext *context, Integration *integration, EGLDisplay display)
|
||||
AbstractPlatformContext::AbstractPlatformContext(QOpenGLContext *context, Integration *integration, EGLDisplay display, EGLConfig config)
|
||||
: QPlatformOpenGLContext()
|
||||
, m_integration(integration)
|
||||
, m_eglDisplay(display)
|
||||
, m_config(configFromGLFormat(m_eglDisplay, context->format()))
|
||||
, m_config(config ? config :configFromGLFormat(m_eglDisplay, context->format()))
|
||||
, m_format(formatFromConfig(m_eglDisplay, m_config))
|
||||
{
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ class Integration;
|
|||
class AbstractPlatformContext : public QPlatformOpenGLContext
|
||||
{
|
||||
public:
|
||||
explicit AbstractPlatformContext(QOpenGLContext *context, Integration *integration, EGLDisplay display);
|
||||
explicit AbstractPlatformContext(QOpenGLContext *context, Integration *integration, EGLDisplay display, EGLConfig config = nullptr);
|
||||
virtual ~AbstractPlatformContext();
|
||||
|
||||
void doneCurrent() override;
|
||||
|
|
|
@ -180,6 +180,13 @@ QPlatformOpenGLContext *Integration::createPlatformOpenGLContext(QOpenGLContext
|
|||
if (kwinApp()->platform()->supportsQpaContext()) {
|
||||
return new SharingPlatformContext(context, const_cast<Integration*>(this));
|
||||
}
|
||||
if (kwinApp()->platform()->sceneEglDisplay() != EGL_NO_DISPLAY) {
|
||||
auto s = kwinApp()->platform()->sceneEglSurface();
|
||||
if (s != EGL_NO_SURFACE) {
|
||||
// try a SharingPlatformContext with a created surface
|
||||
return new SharingPlatformContext(context, const_cast<Integration*>(this), s, kwinApp()->platform()->sceneEglConfig());
|
||||
}
|
||||
}
|
||||
if (m_eglDisplay == EGL_NO_DISPLAY) {
|
||||
const_cast<Integration*>(this)->initEgl();
|
||||
}
|
||||
|
|
|
@ -34,7 +34,13 @@ namespace QPA
|
|||
{
|
||||
|
||||
SharingPlatformContext::SharingPlatformContext(QOpenGLContext *context, Integration *integration)
|
||||
: AbstractPlatformContext(context, integration, kwinApp()->platform()->sceneEglDisplay())
|
||||
: SharingPlatformContext(context, integration, EGL_NO_SURFACE)
|
||||
{
|
||||
}
|
||||
|
||||
SharingPlatformContext::SharingPlatformContext(QOpenGLContext *context, Integration *integration, const EGLSurface &surface, EGLConfig config)
|
||||
: AbstractPlatformContext(context, integration, kwinApp()->platform()->sceneEglDisplay(), config)
|
||||
, m_surface(surface)
|
||||
{
|
||||
create();
|
||||
}
|
||||
|
@ -42,7 +48,7 @@ SharingPlatformContext::SharingPlatformContext(QOpenGLContext *context, Integrat
|
|||
bool SharingPlatformContext::makeCurrent(QPlatformSurface *surface)
|
||||
{
|
||||
Window *window = static_cast<Window*>(surface);
|
||||
if (eglMakeCurrent(eglDisplay(), EGL_NO_SURFACE, EGL_NO_SURFACE, context())) {
|
||||
if (eglMakeCurrent(eglDisplay(), m_surface, m_surface, context())) {
|
||||
window->bindContentFBO();
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@ class SharingPlatformContext : public AbstractPlatformContext
|
|||
{
|
||||
public:
|
||||
explicit SharingPlatformContext(QOpenGLContext *context, Integration *integration);
|
||||
explicit SharingPlatformContext(QOpenGLContext *context, Integration *integration, const EGLSurface &surface, EGLConfig config = nullptr);
|
||||
|
||||
void swapBuffers(QPlatformSurface *surface) override;
|
||||
|
||||
|
@ -43,6 +44,8 @@ public:
|
|||
|
||||
private:
|
||||
void create();
|
||||
|
||||
EGLSurface m_surface;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue