From 51cb1baf1b84b44c2236b8af7bae478662dd5ddd Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Fri, 30 Aug 2024 00:20:38 +0300 Subject: [PATCH] plugins/backgroundcontrast: Fix a crash The updateContrastRegion() creates an ItemEffect() object to block direct scanout. However, it doesn't take into account that the surface item can be null when a window is added. It can happen with Xwayland windows. The contrast effect creates an ItemEffect object for the SurfaceItem, which is reasonable. But on the other hand, the contrast effect still operates per window. So this change simply makes the contrast effect register an ItemEffect with the WindowItem. When proper per item effects are supported, this can be changed (the contrast effect would need to monitor the wl_surface getting added and removed). --- src/plugins/backgroundcontrast/contrast.cpp | 2 +- src/plugins/backgroundcontrast/contrast.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/plugins/backgroundcontrast/contrast.cpp b/src/plugins/backgroundcontrast/contrast.cpp index 31fc4e08cb..3c7ea6bac9 100644 --- a/src/plugins/backgroundcontrast/contrast.cpp +++ b/src/plugins/backgroundcontrast/contrast.cpp @@ -176,7 +176,7 @@ void ContrastEffect::updateContrastRegion(EffectWindow *w) Data &data = m_windowData[w]; data.colorMatrix = matrix; data.contrastRegion = region; - data.surfaceEffect = ItemEffect(w->windowItem()->surfaceItem()); + data.windowEffect = ItemEffect(w->windowItem()); } else { if (auto it = m_windowData.find(w); it != m_windowData.end()) { effects->makeOpenGLContextCurrent(); diff --git a/src/plugins/backgroundcontrast/contrast.h b/src/plugins/backgroundcontrast/contrast.h index 5bc8f85c45..608afe42d7 100644 --- a/src/plugins/backgroundcontrast/contrast.h +++ b/src/plugins/backgroundcontrast/contrast.h @@ -76,7 +76,7 @@ private: QRegion contrastRegion; std::unique_ptr texture; std::unique_ptr fbo; - ItemEffect surfaceEffect; + ItemEffect windowEffect; }; std::unordered_map m_windowData; static ContrastManagerInterface *s_contrastManager;