mirror of
https://github.com/niri-wm/niri.git
synced 2026-06-24 02:01:18 +07:00
Add alpha parameter to shaders
Lets us add extra opacity.
This commit is contained in:
@@ -63,6 +63,7 @@ impl TestCase for GradientAngle {
|
||||
0.,
|
||||
CornerRadius::default(),
|
||||
1.,
|
||||
1.,
|
||||
)
|
||||
.with_location(area.loc)]
|
||||
.into_iter()
|
||||
|
||||
@@ -84,6 +84,7 @@ impl TestCase for GradientArea {
|
||||
Rectangle::default(),
|
||||
CornerRadius::default(),
|
||||
1.,
|
||||
1.,
|
||||
);
|
||||
rv.extend(
|
||||
self.border
|
||||
@@ -103,6 +104,7 @@ impl TestCase for GradientArea {
|
||||
0.,
|
||||
CornerRadius::default(),
|
||||
1.,
|
||||
1.,
|
||||
)
|
||||
.with_location(area.loc)]
|
||||
.into_iter()
|
||||
|
||||
@@ -44,6 +44,7 @@ impl TestCase for GradientOklab {
|
||||
0.,
|
||||
CornerRadius::default(),
|
||||
1.,
|
||||
1.,
|
||||
)
|
||||
.with_location(area.loc)]
|
||||
.into_iter()
|
||||
|
||||
@@ -42,6 +42,7 @@ impl TestCase for GradientOklabAlpha {
|
||||
0.,
|
||||
CornerRadius::default(),
|
||||
1.,
|
||||
1.,
|
||||
)
|
||||
.with_location(area.loc)]
|
||||
.into_iter()
|
||||
|
||||
@@ -44,6 +44,7 @@ impl TestCase for GradientOklchAlpha {
|
||||
0.,
|
||||
CornerRadius::default(),
|
||||
1.,
|
||||
1.,
|
||||
)
|
||||
.with_location(area.loc)]
|
||||
.into_iter()
|
||||
|
||||
@@ -44,6 +44,7 @@ impl TestCase for GradientOklchDecreasing {
|
||||
0.,
|
||||
CornerRadius::default(),
|
||||
1.,
|
||||
1.,
|
||||
)
|
||||
.with_location(area.loc)]
|
||||
.into_iter()
|
||||
|
||||
@@ -44,6 +44,7 @@ impl TestCase for GradientOklchIncreasing {
|
||||
0.,
|
||||
CornerRadius::default(),
|
||||
1.,
|
||||
1.,
|
||||
)
|
||||
.with_location(area.loc)]
|
||||
.into_iter()
|
||||
|
||||
@@ -44,6 +44,7 @@ impl TestCase for GradientOklchLonger {
|
||||
0.,
|
||||
CornerRadius::default(),
|
||||
1.,
|
||||
1.,
|
||||
)
|
||||
.with_location(area.loc)]
|
||||
.into_iter()
|
||||
|
||||
@@ -44,6 +44,7 @@ impl TestCase for GradientOklchShorter {
|
||||
0.,
|
||||
CornerRadius::default(),
|
||||
1.,
|
||||
1.,
|
||||
)
|
||||
.with_location(area.loc)]
|
||||
.into_iter()
|
||||
|
||||
@@ -44,6 +44,7 @@ impl TestCase for GradientSrgb {
|
||||
0.,
|
||||
CornerRadius::default(),
|
||||
1.,
|
||||
1.,
|
||||
)
|
||||
.with_location(area.loc)]
|
||||
.into_iter()
|
||||
|
||||
@@ -42,6 +42,7 @@ impl TestCase for GradientSrgbAlpha {
|
||||
0.,
|
||||
CornerRadius::default(),
|
||||
1.,
|
||||
1.,
|
||||
)
|
||||
.with_location(area.loc)]
|
||||
.into_iter()
|
||||
|
||||
@@ -44,6 +44,7 @@ impl TestCase for GradientSrgbLinear {
|
||||
0.,
|
||||
CornerRadius::default(),
|
||||
1.,
|
||||
1.,
|
||||
)
|
||||
.with_location(area.loc)]
|
||||
.into_iter()
|
||||
|
||||
@@ -42,6 +42,7 @@ impl TestCase for GradientSrgbLinearAlpha {
|
||||
0.,
|
||||
CornerRadius::default(),
|
||||
1.,
|
||||
1.,
|
||||
)
|
||||
.with_location(area.loc)]
|
||||
.into_iter()
|
||||
|
||||
+1
-1
@@ -74,7 +74,7 @@ impl MappedLayer {
|
||||
let radius = self.rules.geometry_corner_radius.unwrap_or_default();
|
||||
// FIXME: is_active based on keyboard focus?
|
||||
self.shadow
|
||||
.update_render_elements(size, true, radius, scale.x);
|
||||
.update_render_elements(size, true, radius, scale.x, 1.);
|
||||
}
|
||||
|
||||
pub fn surface(&self) -> &LayerSurface {
|
||||
|
||||
@@ -2,7 +2,7 @@ use std::iter::zip;
|
||||
|
||||
use arrayvec::ArrayVec;
|
||||
use niri_config::{CornerRadius, Gradient, GradientRelativeTo};
|
||||
use smithay::backend::renderer::element::Kind;
|
||||
use smithay::backend::renderer::element::{Element as _, Kind};
|
||||
use smithay::utils::{Logical, Point, Rectangle, Size};
|
||||
|
||||
use crate::niri_render_elements;
|
||||
@@ -53,6 +53,7 @@ impl FocusRing {
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn update_render_elements(
|
||||
&mut self,
|
||||
win_size: Size<f64, Logical>,
|
||||
@@ -61,6 +62,7 @@ impl FocusRing {
|
||||
view_rect: Rectangle<f64, Logical>,
|
||||
radius: CornerRadius,
|
||||
scale: f64,
|
||||
alpha: f32,
|
||||
) {
|
||||
let width = self.config.width.0;
|
||||
self.full_size = win_size + Size::from((width, width)).upscale(2.);
|
||||
@@ -181,6 +183,7 @@ impl FocusRing {
|
||||
rounded_corner_border_width,
|
||||
radius,
|
||||
scale as f32,
|
||||
alpha,
|
||||
);
|
||||
}
|
||||
} else {
|
||||
@@ -199,6 +202,7 @@ impl FocusRing {
|
||||
rounded_corner_border_width,
|
||||
radius,
|
||||
scale as f32,
|
||||
alpha,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -229,7 +233,9 @@ impl FocusRing {
|
||||
let elem = if self.use_border_shader && has_border_shader {
|
||||
border.clone().with_location(location).into()
|
||||
} else {
|
||||
SolidColorRenderElement::from_buffer(buffer, location, 1., Kind::Unspecified).into()
|
||||
let alpha = border.alpha();
|
||||
SolidColorRenderElement::from_buffer(buffer, location, alpha, Kind::Unspecified)
|
||||
.into()
|
||||
};
|
||||
rv.push(elem);
|
||||
};
|
||||
|
||||
@@ -48,7 +48,7 @@ impl InsertHintElement {
|
||||
scale: f64,
|
||||
) {
|
||||
self.inner
|
||||
.update_render_elements(size, true, false, view_rect, radius, scale);
|
||||
.update_render_elements(size, true, false, view_rect, radius, scale, 1.);
|
||||
}
|
||||
|
||||
pub fn render(
|
||||
|
||||
@@ -38,6 +38,7 @@ impl Shadow {
|
||||
is_active: bool,
|
||||
radius: CornerRadius,
|
||||
scale: f64,
|
||||
alpha: f32,
|
||||
) {
|
||||
let ceil = |logical: f64| (logical * scale).ceil() / scale;
|
||||
|
||||
@@ -129,6 +130,7 @@ impl Shadow {
|
||||
scale as f32,
|
||||
Rectangle::new(window_geo.loc - offset - rect.loc, window_geo.size),
|
||||
win_radius,
|
||||
alpha,
|
||||
);
|
||||
|
||||
rect.loc += offset;
|
||||
@@ -147,6 +149,7 @@ impl Shadow {
|
||||
scale as f32,
|
||||
Rectangle::zero(),
|
||||
Default::default(),
|
||||
alpha,
|
||||
);
|
||||
|
||||
self.shader_rects[0].loc += offset;
|
||||
|
||||
@@ -336,6 +336,7 @@ impl<W: LayoutElement> Tile<W> {
|
||||
),
|
||||
radius,
|
||||
self.scale,
|
||||
1.,
|
||||
);
|
||||
|
||||
let radius = if self.is_fullscreen {
|
||||
@@ -350,6 +351,7 @@ impl<W: LayoutElement> Tile<W> {
|
||||
is_active,
|
||||
radius,
|
||||
self.scale,
|
||||
1.,
|
||||
);
|
||||
|
||||
let draw_focus_ring_with_background = if self.effective_border_width().is_some() {
|
||||
@@ -365,6 +367,7 @@ impl<W: LayoutElement> Tile<W> {
|
||||
view_rect,
|
||||
radius,
|
||||
self.scale,
|
||||
1.,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -880,6 +883,7 @@ impl<W: LayoutElement> Tile<W> {
|
||||
0.,
|
||||
radius,
|
||||
scale.x as f32,
|
||||
1.,
|
||||
)
|
||||
.with_location(geo.loc)
|
||||
.into();
|
||||
|
||||
@@ -39,6 +39,7 @@ struct Parameters {
|
||||
corner_radius: CornerRadius,
|
||||
// Should only be used for visual improvements, i.e. corner radius anti-aliasing.
|
||||
scale: f32,
|
||||
alpha: f32,
|
||||
}
|
||||
|
||||
impl BorderRenderElement {
|
||||
@@ -54,6 +55,7 @@ impl BorderRenderElement {
|
||||
border_width: f32,
|
||||
corner_radius: CornerRadius,
|
||||
scale: f32,
|
||||
alpha: f32,
|
||||
) -> Self {
|
||||
let inner = ShaderRenderElement::empty(ProgramType::Border, Kind::Unspecified);
|
||||
let mut rv = Self {
|
||||
@@ -69,6 +71,7 @@ impl BorderRenderElement {
|
||||
border_width,
|
||||
corner_radius,
|
||||
scale,
|
||||
alpha,
|
||||
},
|
||||
};
|
||||
rv.update_inner();
|
||||
@@ -90,6 +93,7 @@ impl BorderRenderElement {
|
||||
border_width: 0.,
|
||||
corner_radius: Default::default(),
|
||||
scale: 1.,
|
||||
alpha: 1.,
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -111,6 +115,7 @@ impl BorderRenderElement {
|
||||
border_width: f32,
|
||||
corner_radius: CornerRadius,
|
||||
scale: f32,
|
||||
alpha: f32,
|
||||
) {
|
||||
let params = Parameters {
|
||||
size,
|
||||
@@ -123,6 +128,7 @@ impl BorderRenderElement {
|
||||
border_width,
|
||||
corner_radius,
|
||||
scale,
|
||||
alpha,
|
||||
};
|
||||
if self.params == params {
|
||||
return;
|
||||
@@ -144,6 +150,7 @@ impl BorderRenderElement {
|
||||
border_width,
|
||||
corner_radius,
|
||||
scale,
|
||||
alpha,
|
||||
} = self.params;
|
||||
|
||||
let grad_offset = geometry.loc - gradient_area.loc;
|
||||
@@ -189,6 +196,7 @@ impl BorderRenderElement {
|
||||
size,
|
||||
None,
|
||||
scale,
|
||||
alpha,
|
||||
vec![
|
||||
Uniform::new("colorspace", colorspace),
|
||||
Uniform::new("hue_interpolation", hue_interpolation),
|
||||
|
||||
@@ -227,12 +227,14 @@ impl ShaderRenderElement {
|
||||
size: Size<f64, Logical>,
|
||||
opaque_regions: Option<Vec<Rectangle<f64, Logical>>>,
|
||||
scale: f32,
|
||||
alpha: f32,
|
||||
uniforms: Vec<Uniform<'static>>,
|
||||
textures: HashMap<String, GlesTexture>,
|
||||
) {
|
||||
self.area.size = size;
|
||||
self.opaque_regions = opaque_regions.unwrap_or_default();
|
||||
self.scale = scale;
|
||||
self.alpha = alpha;
|
||||
self.additional_uniforms = uniforms;
|
||||
self.textures = textures;
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ struct Parameters {
|
||||
corner_radius: CornerRadius,
|
||||
// Should only be used for visual improvements, i.e. corner radius anti-aliasing.
|
||||
scale: f32,
|
||||
alpha: f32,
|
||||
|
||||
window_geometry: Rectangle<f64, Logical>,
|
||||
window_corner_radius: CornerRadius,
|
||||
@@ -44,6 +45,7 @@ impl ShadowRenderElement {
|
||||
scale: f32,
|
||||
window_geometry: Rectangle<f64, Logical>,
|
||||
window_corner_radius: CornerRadius,
|
||||
alpha: f32,
|
||||
) -> Self {
|
||||
let inner = ShaderRenderElement::empty(ProgramType::Shadow, Kind::Unspecified);
|
||||
let mut rv = Self {
|
||||
@@ -55,6 +57,7 @@ impl ShadowRenderElement {
|
||||
sigma,
|
||||
corner_radius,
|
||||
scale,
|
||||
alpha,
|
||||
window_geometry,
|
||||
window_corner_radius,
|
||||
},
|
||||
@@ -74,6 +77,7 @@ impl ShadowRenderElement {
|
||||
sigma: 0.,
|
||||
corner_radius: Default::default(),
|
||||
scale: 1.,
|
||||
alpha: 1.,
|
||||
window_geometry: Default::default(),
|
||||
window_corner_radius: Default::default(),
|
||||
},
|
||||
@@ -95,12 +99,14 @@ impl ShadowRenderElement {
|
||||
scale: f32,
|
||||
window_geometry: Rectangle<f64, Logical>,
|
||||
window_corner_radius: CornerRadius,
|
||||
alpha: f32,
|
||||
) {
|
||||
let params = Parameters {
|
||||
size,
|
||||
geometry,
|
||||
color,
|
||||
sigma,
|
||||
alpha,
|
||||
corner_radius,
|
||||
scale,
|
||||
window_geometry,
|
||||
@@ -120,6 +126,7 @@ impl ShadowRenderElement {
|
||||
geometry,
|
||||
color,
|
||||
sigma,
|
||||
alpha,
|
||||
corner_radius,
|
||||
scale,
|
||||
window_geometry,
|
||||
@@ -145,6 +152,7 @@ impl ShadowRenderElement {
|
||||
size,
|
||||
None,
|
||||
scale,
|
||||
alpha,
|
||||
vec![
|
||||
Uniform::new("shadow_color", color.to_array_premul()),
|
||||
Uniform::new("sigma", sigma),
|
||||
|
||||
@@ -403,6 +403,7 @@ impl Mapped {
|
||||
0.,
|
||||
radius,
|
||||
scale.x as f32,
|
||||
1.,
|
||||
)
|
||||
.with_location(geo.loc)
|
||||
.into();
|
||||
|
||||
Reference in New Issue
Block a user