diff --git a/src/backends/drm/egl_gbm_backend.cpp b/src/backends/drm/egl_gbm_backend.cpp index 50b0fde98c..9bdf1514e9 100644 --- a/src/backends/drm/egl_gbm_backend.cpp +++ b/src/backends/drm/egl_gbm_backend.cpp @@ -69,12 +69,12 @@ void EglGbmBackend::cleanupSurfaces() void EglGbmBackend::cleanupRenderData(Output::RenderData &render) { - render.gbmSurface = nullptr; - render.importSwapchain = nullptr; if (render.shadowBuffer) { - makeContextCurrent(render); + render.gbmSurface->makeContextCurrent(); render.shadowBuffer = nullptr; } + render.importSwapchain = nullptr; + render.gbmSurface = nullptr; } bool EglGbmBackend::initializeEgl() @@ -198,7 +198,7 @@ bool EglGbmBackend::resetOutput(Output &output) if (!output.output->needsSoftwareTransformation()) { output.current.shadowBuffer = nullptr; } else { - makeContextCurrent(output.current); + output.current.gbmSurface->makeContextCurrent(); output.current.shadowBuffer = QSharedPointer::create(output.output->sourceSize(), output.current.format); if (!output.current.shadowBuffer->isComplete()) { return false; @@ -359,27 +359,10 @@ void EglGbmBackend::renderFramebufferToSurface(Output &output) // No additional render target. return; } - makeContextCurrent(output.current); + output.current.gbmSurface->makeContextCurrent(); output.current.shadowBuffer->render(output.output); } -bool EglGbmBackend::makeContextCurrent(const Output::RenderData &render) const -{ - Q_ASSERT(isPrimary()); - const auto surface = render.gbmSurface; - if (!surface) { - return false; - } - if (eglMakeCurrent(eglDisplay(), surface->eglSurface(), surface->eglSurface(), context()) == EGL_FALSE) { - qCCritical(KWIN_DRM) << "eglMakeCurrent failed:" << getEglErrorString(); - return false; - } - if (!GLPlatform::instance()->isGLES()) { - glDrawBuffer(GL_BACK); - } - return true; -} - bool EglGbmBackend::initBufferConfigs() { const EGLint config_attribs[] = { @@ -578,7 +561,7 @@ QRegion EglGbmBackend::prepareRenderingForOutput(Output &output) resetOutput(output); } } - makeContextCurrent(output.current); + output.current.gbmSurface->makeContextCurrent(); if (output.current.shadowBuffer) { output.current.shadowBuffer->bind(); } diff --git a/src/backends/drm/egl_gbm_backend.h b/src/backends/drm/egl_gbm_backend.h index b7633fe70b..258991cde7 100644 --- a/src/backends/drm/egl_gbm_backend.h +++ b/src/backends/drm/egl_gbm_backend.h @@ -121,7 +121,6 @@ private: bool addOutput(DrmAbstractOutput *output); void removeOutput(DrmAbstractOutput *output); - bool makeContextCurrent(const Output::RenderData &output) const; void setViewport(const Output &output) const; void renderFramebufferToSurface(Output &output); diff --git a/src/backends/drm/gbm_surface.cpp b/src/backends/drm/gbm_surface.cpp index c0248c10e4..0a338e5b84 100644 --- a/src/backends/drm/gbm_surface.cpp +++ b/src/backends/drm/gbm_surface.cpp @@ -15,6 +15,7 @@ #include "drm_gpu.h" #include "logging.h" #include "kwineglutils_p.h" +#include "kwinglplatform.h" namespace KWin { @@ -65,6 +66,17 @@ GbmSurface::~GbmSurface() gbm_surface_destroy(m_surface); } } +bool GbmSurface::makeContextCurrent() const +{ + if (eglMakeCurrent(m_gpu->eglDisplay(), m_eglSurface, m_eglSurface, m_gpu->eglBackend()->context()) == EGL_FALSE) { + qCCritical(KWIN_DRM) << "eglMakeCurrent failed:" << getEglErrorString(); + return false; + } + if (!GLPlatform::instance()->isGLES()) { + glDrawBuffer(GL_BACK); + } + return true; +} QSharedPointer GbmSurface::swapBuffersForDrm() { diff --git a/src/backends/drm/gbm_surface.h b/src/backends/drm/gbm_surface.h index f2e8a51f1c..b1de371fea 100644 --- a/src/backends/drm/gbm_surface.h +++ b/src/backends/drm/gbm_surface.h @@ -28,9 +28,10 @@ public: explicit GbmSurface(DrmGpu *gpu, const QSize &size, uint32_t format, QVector modifiers, EGLConfig config); ~GbmSurface(); + bool makeContextCurrent() const; + QSharedPointer swapBuffersForDrm(); QSharedPointer swapBuffers(); - void releaseBuffer(GbmBuffer *buffer); QSharedPointer currentBuffer() const;