From c8cd6007068ae112c1be8aa8eca2fa61e5df396a Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Fri, 27 Dec 2019 19:12:19 -0800 Subject: [PATCH] wayland: fix unintentional blend with other windows @jsgf mentioned this to me, and since I've started running "proper" wayland gnome-shell/mutter on my pixelbook go, I'm seeing it too. The issue is that the alpha values are potentially <1.0 when they are committed to the frame buffer and the mutter compositor is faithfully blending wezterm with the window behind it, leading to weird looking effects such as varying brightness of text, or for cases where the window behind wezterm is bright white, a halo effect that makes the text less sharp. This commit addresses this issue by asking glium to ask opengl to set the destination alpha to 1.0 in the final draw stage. --- src/frontend/gui/termwindow.rs | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/frontend/gui/termwindow.rs b/src/frontend/gui/termwindow.rs index 98ce54bb5..34b3cb196 100644 --- a/src/frontend/gui/termwindow.rs +++ b/src/frontend/gui/termwindow.rs @@ -14,7 +14,7 @@ use crate::mux::window::WindowId as MuxWindowId; use crate::mux::Mux; use ::window::bitmaps::atlas::{OutOfTextureSpace, SpriteSlice}; use ::window::bitmaps::Texture2d; -use ::window::glium::{uniform, Surface}; +use ::window::glium::{uniform, BlendingFunction, LinearBlendingFactor, Surface}; use ::window::*; use anyhow::{anyhow, bail, ensure}; use portable_pty::PtySize; @@ -1392,7 +1392,8 @@ impl TermWindow { .to_column_arrays(); let draw_params = glium::DrawParameters { - blend: glium::Blend::alpha_blending(), + // No alpha blending for the background layer: let's make + // sure that our background pixels are at 100% opacity. ..Default::default() }; @@ -1411,6 +1412,28 @@ impl TermWindow { &draw_params, )?; + let draw_params = glium::DrawParameters { + blend: glium::Blend { + color: BlendingFunction::Addition { + source: LinearBlendingFactor::SourceAlpha, + destination: LinearBlendingFactor::OneMinusSourceAlpha, + }, + alpha: BlendingFunction::Addition { + source: LinearBlendingFactor::SourceAlpha, + // On Wayland, the compositor takes the destination alpha + // value and blends with the window behind our own, which + // can make the text look brighter or less sharp. + // We set the destination alpha to 1.0 to prevent that + // from happening. + // (The normal alpha blending operation would set this to + // OneMinusSourceAlpha). + destination: LinearBlendingFactor::One, + }, + constant_value: (0.0, 0.0, 0.0, 0.0), + }, + ..Default::default() + }; + // Pass 2: Draw glyphs frame.draw( &*vb,