From 3d619c995b888612b4d7fe46b34203f86c0081a8 Mon Sep 17 00:00:00 2001 From: David Edmundson Date: Wed, 11 Oct 2017 20:03:07 +0200 Subject: [PATCH] Fix DRM EGL crash regression Summary: In 47343fb we made GBM buffer shared. What we wanted to do was: Unbox the shared_pointer to give us a GBMSurface* object Call the gbm_surface*() on that operator Then cast that to a void* for eglCreatePlatformWindowSurfaceEXT What we did: Cast the std::shared_ptr to a gbm_surface* then cast that to void*. This is just a garbage value and it crashes in Mesa when we do our first paint. I've replaced that with an explicit method then we can use shared_ptr's -> operator rather than get() which does the right thing in a readable way. Test Plan: It crashed after rebasing to master (for Aleix too) No longer crashes Reviewers: #plasma Subscribers: plasma-devel, kwin, #kwin Tags: #kwin Differential Revision: https://phabricator.kde.org/D8251 --- autotests/test_gbm_surface.cpp | 4 ++-- plugins/platforms/drm/egl_gbm_backend.cpp | 2 +- plugins/platforms/drm/gbm_surface.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/autotests/test_gbm_surface.cpp b/autotests/test_gbm_surface.cpp index 95ee363865..17268c9c1e 100644 --- a/autotests/test_gbm_surface.cpp +++ b/autotests/test_gbm_surface.cpp @@ -78,7 +78,7 @@ private Q_SLOTS: void GbmSurfaceTest::testCreate() { GbmSurface surface(nullptr, 2, 3, 4, 5); - gbm_surface *native = surface; + gbm_surface *native = surface.surface(); QVERIFY(surface); QCOMPARE(native->width, 2u); QCOMPARE(native->height, 3u); @@ -91,7 +91,7 @@ void GbmSurfaceTest::testCreateFailure() gbm_device dev{true}; GbmSurface surface(&dev, 2, 3, 4, 5); QVERIFY(!surface); - gbm_surface *native = surface; + gbm_surface *native = surface.surface(); QVERIFY(!native); } diff --git a/plugins/platforms/drm/egl_gbm_backend.cpp b/plugins/platforms/drm/egl_gbm_backend.cpp index 02e57d0bfa..891f0017c4 100644 --- a/plugins/platforms/drm/egl_gbm_backend.cpp +++ b/plugins/platforms/drm/egl_gbm_backend.cpp @@ -162,7 +162,7 @@ void EglGbmBackend::createOutput(DrmOutput *drmOutput) qCCritical(KWIN_DRM) << "Create gbm surface failed"; return; } - o.eglSurface = eglCreatePlatformWindowSurfaceEXT(eglDisplay(), config(), (void *)((gbm_surface*)o.gbmSurface.get()), nullptr); + o.eglSurface = eglCreatePlatformWindowSurfaceEXT(eglDisplay(), config(), (void *)(o.gbmSurface->surface()), nullptr); if (o.eglSurface == EGL_NO_SURFACE) { qCCritical(KWIN_DRM) << "Create Window Surface failed"; o.gbmSurface.reset(); diff --git a/plugins/platforms/drm/gbm_surface.h b/plugins/platforms/drm/gbm_surface.h index 6877a926c0..5eaa4c908b 100644 --- a/plugins/platforms/drm/gbm_surface.h +++ b/plugins/platforms/drm/gbm_surface.h @@ -42,7 +42,7 @@ public: return m_surface != nullptr; } - operator gbm_surface*() const { + gbm_surface* surface() const { return m_surface; }