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).
This commit is contained in:
Vlad Zahorodnii 2024-08-30 00:20:38 +03:00
parent 8f40b5b554
commit 51cb1baf1b
2 changed files with 2 additions and 2 deletions

View file

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

View file

@ -76,7 +76,7 @@ private:
QRegion contrastRegion;
std::unique_ptr<GLTexture> texture;
std::unique_ptr<GLFramebuffer> fbo;
ItemEffect surfaceEffect;
ItemEffect windowEffect;
};
std::unordered_map<const EffectWindow *, Data> m_windowData;
static ContrastManagerInterface *s_contrastManager;