forge
Explore
Log in

Don't you dare go Hollow

Fix blurry rounded corners on high scales

Browse files at this commit

66202992c9536c0e01395813f9a611aa111e5dedIvan MolodetskikhParent: eb59b10
niri-visual-tests/src/cases/gradient_angle.rsmodified+1 -0
@@ -70,6 +70,7 @@ impl TestCase for GradientAngle {
70 Rectangle::from_loc_and_size((0., 0.), area.size),70 Rectangle::from_loc_and_size((0., 0.), area.size),
71 0.,71 0.,
72 CornerRadius::default(),72 CornerRadius::default(),
73+ 1.,
73 )74 )
74 .with_location(area.loc)]75 .with_location(area.loc)]
75 .into_iter()76 .into_iter()
niri-visual-tests/src/cases/gradient_area.rsmodified+1 -0
@@ -110,6 +110,7 @@ impl TestCase for GradientArea {
110 Rectangle::from_loc_and_size((0, 0), rect_size).to_f64(),110 Rectangle::from_loc_and_size((0, 0), rect_size).to_f64(),
111 0.,111 0.,
112 CornerRadius::default(),112 CornerRadius::default(),
113+ 1.,
113 )114 )
114 .with_location(area.loc)]115 .with_location(area.loc)]
115 .into_iter()116 .into_iter()
src/layout/closing_window.rsmodified+1 -0
@@ -164,6 +164,7 @@ impl ClosingWindow {
164 ProgramType::Close,164 ProgramType::Close,
165 view_rect.size,165 view_rect.size,
166 None,166 None,
167+ scale.x as f32,
167 1.,168 1.,
168 vec![169 vec![
169 mat3_uniform("niri_input_to_geo", input_to_geo),170 mat3_uniform("niri_input_to_geo", input_to_geo),
src/layout/focus_ring.rsmodified+2 -0
@@ -184,6 +184,7 @@ impl FocusRing {
184 Rectangle::from_loc_and_size(full_rect.loc - loc, full_rect.size),184 Rectangle::from_loc_and_size(full_rect.loc - loc, full_rect.size),
185 rounded_corner_border_width,185 rounded_corner_border_width,
186 radius,186 radius,
187+ scale as f32,
187 );188 );
188 }189 }
189 } else {190 } else {
@@ -203,6 +204,7 @@ impl FocusRing {
203 Rectangle::from_loc_and_size(full_rect.loc - self.locations[0], full_rect.size),204 Rectangle::from_loc_and_size(full_rect.loc - self.locations[0], full_rect.size),
204 rounded_corner_border_width,205 rounded_corner_border_width,
205 radius,206 radius,
207+ scale as f32,
206 );208 );
207 }209 }
208 210
src/layout/opening_window.rsmodified+1 -0
@@ -106,6 +106,7 @@ impl OpenAnimation {
106 ProgramType::Open,106 ProgramType::Open,
107 area.size,107 area.size,
108 None,108 None,
109+ scale.x as f32,
109 1.,110 1.,
110 vec![111 vec![
111 mat3_uniform("niri_input_to_geo", input_to_geo),112 mat3_uniform("niri_input_to_geo", input_to_geo),
src/layout/tile.rsmodified+1 -0
@@ -763,6 +763,7 @@ impl<W: LayoutElement> Tile<W> {
763 Rectangle::from_loc_and_size((0., 0.), geo.size),763 Rectangle::from_loc_and_size((0., 0.), geo.size),
764 0.,764 0.,
765 radius,765 radius,
766+ scale.x as f32,
766 )767 )
767 .with_location(geo.loc)768 .with_location(geo.loc)
768 .into();769 .into();
src/render_helpers/border.rsmodified+9 -0
@@ -34,6 +34,8 @@ struct Parameters {
34 geometry: Rectangle<f64, Logical>,34 geometry: Rectangle<f64, Logical>,
35 border_width: f32,35 border_width: f32,
36 corner_radius: CornerRadius,36 corner_radius: CornerRadius,
37+ // Should only be used for visual improvements, i.e. corner radius anti-aliasing.
38+ scale: f32,
37 }39 }
38 40
39 impl BorderRenderElement {41 impl BorderRenderElement {
@@ -47,6 +49,7 @@ impl BorderRenderElement {
47 geometry: Rectangle<f64, Logical>,49 geometry: Rectangle<f64, Logical>,
48 border_width: f32,50 border_width: f32,
49 corner_radius: CornerRadius,51 corner_radius: CornerRadius,
52+ scale: f32,
50 ) -> Self {53 ) -> Self {
51 let inner = ShaderRenderElement::empty(ProgramType::Border, Kind::Unspecified);54 let inner = ShaderRenderElement::empty(ProgramType::Border, Kind::Unspecified);
52 let mut rv = Self {55 let mut rv = Self {
@@ -60,6 +63,7 @@ impl BorderRenderElement {
60 geometry,63 geometry,
61 border_width,64 border_width,
62 corner_radius,65 corner_radius,
66+ scale,
63 },67 },
64 };68 };
65 rv.update_inner();69 rv.update_inner();
@@ -79,6 +83,7 @@ impl BorderRenderElement {
79 geometry: Default::default(),83 geometry: Default::default(),
80 border_width: 0.,84 border_width: 0.,
81 corner_radius: Default::default(),85 corner_radius: Default::default(),
86+ scale: 1.,
82 },87 },
83 }88 }
84 }89 }
@@ -98,6 +103,7 @@ impl BorderRenderElement {
98 geometry: Rectangle<f64, Logical>,103 geometry: Rectangle<f64, Logical>,
99 border_width: f32,104 border_width: f32,
100 corner_radius: CornerRadius,105 corner_radius: CornerRadius,
106+ scale: f32,
101 ) {107 ) {
102 let params = Parameters {108 let params = Parameters {
103 size,109 size,
@@ -108,6 +114,7 @@ impl BorderRenderElement {
108 geometry,114 geometry,
109 border_width,115 border_width,
110 corner_radius,116 corner_radius,
117+ scale,
111 };118 };
112 if self.params == params {119 if self.params == params {
113 return;120 return;
@@ -127,6 +134,7 @@ impl BorderRenderElement {
127 geometry,134 geometry,
128 border_width,135 border_width,
129 corner_radius,136 corner_radius,
137+ scale,
130 } = self.params;138 } = self.params;
131 139
132 let grad_offset = geometry.loc - gradient_area.loc;140 let grad_offset = geometry.loc - gradient_area.loc;
@@ -157,6 +165,7 @@ impl BorderRenderElement {
157 self.inner.update(165 self.inner.update(
158 size,166 size,
159 None,167 None,
168+ scale,
160 vec![169 vec![
161 Uniform::new("color_from", color_from),170 Uniform::new("color_from", color_from),
162 Uniform::new("color_to", color_to),171 Uniform::new("color_to", color_to),
src/render_helpers/clipped_surface.rsmodified+4 -0
@@ -20,6 +20,8 @@ pub struct ClippedSurfaceRenderElement<R: NiriRenderer> {
20 corner_radius: CornerRadius,20 corner_radius: CornerRadius,
21 geometry: Rectangle<f64, Logical>,21 geometry: Rectangle<f64, Logical>,
22 input_to_geo: Mat3,22 input_to_geo: Mat3,
23+ // Should only be used for visual improvements, i.e. corner radius anti-aliasing.
24+ scale: f32,
23 }25 }
24 26
25 #[derive(Debug, Default, Clone)]27 #[derive(Debug, Default, Clone)]
@@ -76,6 +78,7 @@ impl<R: NiriRenderer> ClippedSurfaceRenderElement<R> {
76 corner_radius,78 corner_radius,
77 geometry,79 geometry,
78 input_to_geo,80 input_to_geo,
81+ scale: scale.x as f32,
79 }82 }
80 }83 }
81 84
@@ -220,6 +223,7 @@ impl RenderElement<GlesRenderer> for ClippedSurfaceRenderElement<GlesRenderer> {
220 frame.override_default_tex_program(223 frame.override_default_tex_program(
221 self.program.clone(),224 self.program.clone(),
222 vec![225 vec![
226+ Uniform::new("niri_scale", self.scale),
223 Uniform::new(227 Uniform::new(
224 "geo_size",228 "geo_size",
225 (self.geometry.size.w as f32, self.geometry.size.h as f32),229 (self.geometry.size.w as f32, self.geometry.size.h as f32),
src/render_helpers/resize.rsmodified+1 -0
@@ -87,6 +87,7 @@ impl ResizeRenderElement {
87 ProgramType::Resize,87 ProgramType::Resize,
88 area.size,88 area.size,
89 None,89 None,
90+ scale.x,
90 result_alpha,91 result_alpha,
91 vec![92 vec![
92 mat3_uniform("niri_input_to_curr_geo", input_to_curr_geo),93 mat3_uniform("niri_input_to_curr_geo", input_to_curr_geo),
src/render_helpers/shader_element.rsmodified+15 -0
@@ -25,6 +25,8 @@ pub struct ShaderRenderElement {
25 commit_counter: CommitCounter,25 commit_counter: CommitCounter,
26 area: Rectangle<f64, Logical>,26 area: Rectangle<f64, Logical>,
27 opaque_regions: Vec<Rectangle<f64, Logical>>,27 opaque_regions: Vec<Rectangle<f64, Logical>>,
28+ // Should only be used for visual improvements, i.e. corner radius anti-aliasing.
29+ scale: f32,
28 alpha: f32,30 alpha: f32,
29 additional_uniforms: Vec<Uniform<'static>>,31 additional_uniforms: Vec<Uniform<'static>>,
30 textures: HashMap<String, GlesTexture>,32 textures: HashMap<String, GlesTexture>,
@@ -47,6 +49,7 @@ struct ShaderProgramInternal {
47 uniform_tex_matrix: ffi::types::GLint,49 uniform_tex_matrix: ffi::types::GLint,
48 uniform_matrix: ffi::types::GLint,50 uniform_matrix: ffi::types::GLint,
49 uniform_size: ffi::types::GLint,51 uniform_size: ffi::types::GLint,
52+ uniform_scale: ffi::types::GLint,
50 uniform_alpha: ffi::types::GLint,53 uniform_alpha: ffi::types::GLint,
51 attrib_vert: ffi::types::GLint,54 attrib_vert: ffi::types::GLint,
52 attrib_vert_position: ffi::types::GLint,55 attrib_vert_position: ffi::types::GLint,
@@ -78,6 +81,7 @@ unsafe fn compile_program(
78 let matrix = CStr::from_bytes_with_nul(b"matrix\0").expect("NULL terminated");81 let matrix = CStr::from_bytes_with_nul(b"matrix\0").expect("NULL terminated");
79 let tex_matrix = CStr::from_bytes_with_nul(b"tex_matrix\0").expect("NULL terminated");82 let tex_matrix = CStr::from_bytes_with_nul(b"tex_matrix\0").expect("NULL terminated");
80 let size = CStr::from_bytes_with_nul(b"niri_size\0").expect("NULL terminated");83 let size = CStr::from_bytes_with_nul(b"niri_size\0").expect("NULL terminated");
84+ let scale = CStr::from_bytes_with_nul(b"niri_scale\0").expect("NULL terminated");
81 let alpha = CStr::from_bytes_with_nul(b"niri_alpha\0").expect("NULL terminated");85 let alpha = CStr::from_bytes_with_nul(b"niri_alpha\0").expect("NULL terminated");
82 let tint = CStr::from_bytes_with_nul(b"niri_tint\0").expect("NULL terminated");86 let tint = CStr::from_bytes_with_nul(b"niri_tint\0").expect("NULL terminated");
83 87
@@ -90,6 +94,8 @@ unsafe fn compile_program(
90 .GetUniformLocation(program, tex_matrix.as_ptr() as *const ffi::types::GLchar),94 .GetUniformLocation(program, tex_matrix.as_ptr() as *const ffi::types::GLchar),
91 uniform_size: gl95 uniform_size: gl
92 .GetUniformLocation(program, size.as_ptr() as *const ffi::types::GLchar),96 .GetUniformLocation(program, size.as_ptr() as *const ffi::types::GLchar),
97+ uniform_scale: gl
98+ .GetUniformLocation(program, scale.as_ptr() as *const ffi::types::GLchar),
93 uniform_alpha: gl99 uniform_alpha: gl
94 .GetUniformLocation(program, alpha.as_ptr() as *const ffi::types::GLchar),100 .GetUniformLocation(program, alpha.as_ptr() as *const ffi::types::GLchar),
95 attrib_vert: gl.GetAttribLocation(program, vert.as_ptr() as *const ffi::types::GLchar),101 attrib_vert: gl.GetAttribLocation(program, vert.as_ptr() as *const ffi::types::GLchar),
@@ -131,6 +137,8 @@ unsafe fn compile_program(
131 ),137 ),
132 uniform_size: gl138 uniform_size: gl
133 .GetUniformLocation(debug_program, size.as_ptr() as *const ffi::types::GLchar),139 .GetUniformLocation(debug_program, size.as_ptr() as *const ffi::types::GLchar),
140+ uniform_scale: gl
141+ .GetUniformLocation(debug_program, scale.as_ptr() as *const ffi::types::GLchar),
134 uniform_alpha: gl142 uniform_alpha: gl
135 .GetUniformLocation(debug_program, alpha.as_ptr() as *const ffi::types::GLchar),143 .GetUniformLocation(debug_program, alpha.as_ptr() as *const ffi::types::GLchar),
136 attrib_vert: gl144 attrib_vert: gl
@@ -200,6 +208,8 @@ impl ShaderRenderElement {
200 program: ProgramType,208 program: ProgramType,
201 size: Size<f64, Logical>,209 size: Size<f64, Logical>,
202 opaque_regions: Option<Vec<Rectangle<f64, Logical>>>,210 opaque_regions: Option<Vec<Rectangle<f64, Logical>>>,
211+ // Should only be used for visual improvements, i.e. corner radius anti-aliasing.
212+ scale: f32,
203 alpha: f32,213 alpha: f32,
204 uniforms: Vec<Uniform<'_>>,214 uniforms: Vec<Uniform<'_>>,
205 textures: HashMap<String, GlesTexture>,215 textures: HashMap<String, GlesTexture>,
@@ -211,6 +221,7 @@ impl ShaderRenderElement {
211 commit_counter: CommitCounter::default(),221 commit_counter: CommitCounter::default(),
212 area: Rectangle::from_loc_and_size((0., 0.), size),222 area: Rectangle::from_loc_and_size((0., 0.), size),
213 opaque_regions: opaque_regions.unwrap_or_default(),223 opaque_regions: opaque_regions.unwrap_or_default(),
224+ scale,
214 alpha,225 alpha,
215 additional_uniforms: uniforms.into_iter().map(|u| u.into_owned()).collect(),226 additional_uniforms: uniforms.into_iter().map(|u| u.into_owned()).collect(),
216 textures,227 textures,
@@ -225,6 +236,7 @@ impl ShaderRenderElement {
225 commit_counter: CommitCounter::default(),236 commit_counter: CommitCounter::default(),
226 area: Rectangle::default(),237 area: Rectangle::default(),
227 opaque_regions: vec![],238 opaque_regions: vec![],
239+ scale: 1.,
228 alpha: 1.,240 alpha: 1.,
229 additional_uniforms: vec![],241 additional_uniforms: vec![],
230 textures: HashMap::new(),242 textures: HashMap::new(),
@@ -240,11 +252,13 @@ impl ShaderRenderElement {
240 &mut self,252 &mut self,
241 size: Size<f64, Logical>,253 size: Size<f64, Logical>,
242 opaque_regions: Option<Vec<Rectangle<f64, Logical>>>,254 opaque_regions: Option<Vec<Rectangle<f64, Logical>>>,
255+ scale: f32,
243 uniforms: Vec<Uniform<'_>>,256 uniforms: Vec<Uniform<'_>>,
244 textures: HashMap<String, GlesTexture>,257 textures: HashMap<String, GlesTexture>,
245 ) {258 ) {
246 self.area.size = size;259 self.area.size = size;
247 self.opaque_regions = opaque_regions.unwrap_or_default();260 self.opaque_regions = opaque_regions.unwrap_or_default();
261+ self.scale = scale;
248 self.additional_uniforms = uniforms.into_iter().map(|u| u.into_owned()).collect();262 self.additional_uniforms = uniforms.into_iter().map(|u| u.into_owned()).collect();
249 self.textures = textures;263 self.textures = textures;
250 264
@@ -422,6 +436,7 @@ impl RenderElement<GlesRenderer> for ShaderRenderElement {
422 tex_matrix.as_ref().as_ptr(),436 tex_matrix.as_ref().as_ptr(),
423 );437 );
424 gl.Uniform2f(program.uniform_size, dest.size.w as f32, dest.size.h as f32);438 gl.Uniform2f(program.uniform_size, dest.size.w as f32, dest.size.h as f32);
439+ gl.Uniform1f(program.uniform_scale, self.scale);
425 gl.Uniform1f(program.uniform_alpha, self.alpha);440 gl.Uniform1f(program.uniform_alpha, self.alpha);
426 441
427 let tint = if has_tint { 1.0f32 } else { 0.0f32 };442 let tint = if has_tint { 1.0f32 } else { 0.0f32 };
src/render_helpers/shaders/border.fragmodified+3 -1
@@ -5,6 +5,7 @@ uniform float niri_tint;
5 #endif5 #endif
6 6
7 uniform float niri_alpha;7 uniform float niri_alpha;
8+uniform float niri_scale;
8 9
9 uniform vec2 niri_size;10 uniform vec2 niri_size;
10 varying vec2 niri_v_coords;11 varying vec2 niri_v_coords;
@@ -56,7 +57,8 @@ float rounding_alpha(vec2 coords, vec2 size, vec4 corner_radius) {
56 }57 }
57 58
58 float dist = distance(coords, center);59 float dist = distance(coords, center);
59- return 1.0 - smoothstep(radius - 0.5, radius + 0.5, dist);60+ float half_px = 0.5 / niri_scale;
61+ return 1.0 - smoothstep(radius - half_px, radius + half_px, dist);
60 }62 }
61 63
62 void main() {64 void main() {
src/render_helpers/shaders/clipped_surface.fragmodified+4 -1
@@ -20,6 +20,8 @@ varying vec2 v_coords;
20 uniform float tint;20 uniform float tint;
21 #endif21 #endif
22 22
23+uniform float niri_scale;
24+
23 uniform vec2 geo_size;25 uniform vec2 geo_size;
24 uniform vec4 corner_radius;26 uniform vec4 corner_radius;
25 uniform mat3 input_to_geo;27 uniform mat3 input_to_geo;
@@ -45,7 +47,8 @@ float rounding_alpha(vec2 coords, vec2 size) {
45 }47 }
46 48
47 float dist = distance(coords, center);49 float dist = distance(coords, center);
48- return 1.0 - smoothstep(radius - 0.5, radius + 0.5, dist);50+ float half_px = 0.5 / niri_scale;
51+ return 1.0 - smoothstep(radius - half_px, radius + half_px, dist);
49 }52 }
50 53
51 void main() {54 void main() {
src/render_helpers/shaders/close_prelude.fragmodified+1 -0
@@ -18,4 +18,5 @@ uniform float niri_clamped_progress;
18 uniform float niri_random_seed;18 uniform float niri_random_seed;
19 19
20 uniform float niri_alpha;20 uniform float niri_alpha;
21+uniform float niri_scale;
21 22
src/render_helpers/shaders/mod.rsmodified+1 -0
@@ -55,6 +55,7 @@ impl Shaders {
55 .compile_custom_texture_shader(55 .compile_custom_texture_shader(
56 include_str!("clipped_surface.frag"),56 include_str!("clipped_surface.frag"),
57 &[57 &[
58+ UniformName::new("niri_scale", UniformType::_1f),
58 UniformName::new("geo_size", UniformType::_2f),59 UniformName::new("geo_size", UniformType::_2f),
59 UniformName::new("corner_radius", UniformType::_4f),60 UniformName::new("corner_radius", UniformType::_4f),
60 UniformName::new("input_to_geo", UniformType::Matrix3x3),61 UniformName::new("input_to_geo", UniformType::Matrix3x3),
src/render_helpers/shaders/open_prelude.fragmodified+1 -0
@@ -18,4 +18,5 @@ uniform float niri_clamped_progress;
18 uniform float niri_random_seed;18 uniform float niri_random_seed;
19 19
20 uniform float niri_alpha;20 uniform float niri_alpha;
21+uniform float niri_scale;
21 22
src/render_helpers/shaders/resize_prelude.fragmodified+3 -1
@@ -25,6 +25,7 @@ uniform vec4 niri_corner_radius;
25 uniform float niri_clip_to_geometry;25 uniform float niri_clip_to_geometry;
26 26
27 uniform float niri_alpha;27 uniform float niri_alpha;
28+uniform float niri_scale;
28 29
29 float niri_rounding_alpha(vec2 coords, vec2 size) {30 float niri_rounding_alpha(vec2 coords, vec2 size) {
30 vec2 center;31 vec2 center;
@@ -47,5 +48,6 @@ float niri_rounding_alpha(vec2 coords, vec2 size) {
47 }48 }
48 49
49 float dist = distance(coords, center);50 float dist = distance(coords, center);
50- return 1.0 - smoothstep(radius - 0.5, radius + 0.5, dist);51+ float half_px = 0.5 / niri_scale;
52+ return 1.0 - smoothstep(radius - half_px, radius + half_px, dist);
51 }53 }