backends/drm: move makeContextCurrent into GbmSurface

This commit is contained in:
Xaver Hugl 2021-12-21 12:21:47 +01:00 committed by Vlad Zahorodnii
parent 00f2dc1d88
commit c498d31aa7
4 changed files with 20 additions and 25 deletions

View file

@ -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<ShadowBuffer>::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();
}

View file

@ -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);

View file

@ -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<DrmGbmBuffer> GbmSurface::swapBuffersForDrm()
{

View file

@ -28,9 +28,10 @@ public:
explicit GbmSurface(DrmGpu *gpu, const QSize &size, uint32_t format, QVector<uint64_t> modifiers, EGLConfig config);
~GbmSurface();
bool makeContextCurrent() const;
QSharedPointer<DrmGbmBuffer> swapBuffersForDrm();
QSharedPointer<GbmBuffer> swapBuffers();
void releaseBuffer(GbmBuffer *buffer);
QSharedPointer<GbmBuffer> currentBuffer() const;