Add panel-wide styles and the Morph hub (#26)
Panel appearance now applies to the whole panel, with seven styles: Floating, Capsules, Notch, Edge to edge, Fused islands, Adaptive and Morph. - Share composition, geometry, and motion through the renderer-independent `ferese-panel` crate, including native materials, input regions, and Settings previews. - Add the Morph hub with media, calendar, notifications, controls, workspace previews, hover feedback, and attached mode. Keep recording and low-battery status visible and respect window clearance. - Cache workspace preview geometry, draw thumbnails directly, centralize Morph transitions, and keep rendering settings local to each shell instance. - Put Record Screen in the Morph header and show the display control only when an external monitor is connected. Update panel documentation, the desktop screenshot, and native check style names. Local validation included 660 compositor tests, 191 shell tests, isolated preview-cache checks, GPU Morph captures at 1×/1.25×/1.5×, formatting, and Clippy with warnings denied. The final header change passed all 23 Morph tests. Release workflow jobs are skipped for this PR.
This commit is contained in:
1 parent
42c3b290dd
commit
e22f0ebef9
131 files changed
+12562
-1634
No files matched your search
@@ -183,6 +183,7 @@ pub(super) fn grouped_elements(
|
||||
output,
|
||||
surface,
|
||||
MaterialSurface {
|
||||
shape_origin: constrain.loc,
|
||||
geometry: constrain,
|
||||
corners,
|
||||
index: 0,
|
||||
|
||||
@@ -286,6 +286,105 @@ fn rasterize(renderer: &mut GlesRenderer, program: &GlesPixelProgram, uniforms:
|
||||
renderer.map_texture(&mapping).unwrap().to_vec()
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore = "requires an EGL rendering device"]
|
||||
fn panel_shader_matches_core_outlines_and_resets_for_popovers() {
|
||||
use ferese_panel::scene::{GroupBounds, Parameters, Scene, derive};
|
||||
use ferese_panel::shape::{PixelGrid, Style, ZonePosition};
|
||||
use smithay::backend::renderer::gles::UniformValue;
|
||||
let mut renderer = renderer();
|
||||
let mut resources = RenderResources::default();
|
||||
let program = material_program_for_corners(&mut resources, &mut renderer, CornerShape::Circular).unwrap();
|
||||
let bounds = ferese_layout::Rect::new(0., 0., 64., 64.);
|
||||
let groups = [
|
||||
GroupBounds {
|
||||
zone: ZonePosition::Start,
|
||||
bounds: ferese_layout::Rect::new(3., 0., 18., 16.),
|
||||
},
|
||||
GroupBounds {
|
||||
zone: ZonePosition::Start,
|
||||
bounds: ferese_layout::Rect::new(25., 0., 18., 16.),
|
||||
},
|
||||
];
|
||||
let mut scenes = Vec::new();
|
||||
for style in [
|
||||
Style::Floating,
|
||||
Style::Capsules,
|
||||
Style::Notch,
|
||||
Style::Fused,
|
||||
Style::Morph,
|
||||
Style::Flat,
|
||||
Style::Frame,
|
||||
Style::CornerWrap,
|
||||
] {
|
||||
for edge in [ferese_panel::Edge::Top, ferese_panel::Edge::Bottom] {
|
||||
for scale in [1., 1.25, 1.5] {
|
||||
scenes.push(
|
||||
derive(
|
||||
Parameters {
|
||||
style,
|
||||
edge,
|
||||
height: 16.,
|
||||
gap: 4.,
|
||||
frame_insets: [16., 4., 4., 4.],
|
||||
frame_radius: 10.,
|
||||
wrap_size: [40., 42.],
|
||||
wrap_width: 8.,
|
||||
fillet: 6.,
|
||||
..Default::default()
|
||||
},
|
||||
bounds,
|
||||
&groups,
|
||||
PixelGrid::new(scale).unwrap(),
|
||||
)
|
||||
.unwrap(),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
for scene in scenes.iter().chain(std::iter::once(&Scene::default())) {
|
||||
let matrices = scene
|
||||
.packets()
|
||||
.into_iter()
|
||||
.map(|p| [p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7], p[8] * 4. + p[9]])
|
||||
.collect::<Vec<_>>();
|
||||
let mut uniforms = vec![
|
||||
Uniform::new("visible_rect", [0.0f32, 0., 64., 64.]),
|
||||
Uniform::new("material_radii", [12.0f32; 4]),
|
||||
Uniform::new("tint", [1.0f32; 4]),
|
||||
Uniform::new("paint_mode", 0.0f32),
|
||||
Uniform::new("panel_count", matrices.len() as f32),
|
||||
Uniform::new("panel_fusion", scene.fusion as f32),
|
||||
];
|
||||
if !matrices.is_empty() {
|
||||
uniforms.push(Uniform::new(
|
||||
"panel_shapes[0]",
|
||||
UniformValue::Matrix3x3 {
|
||||
matrices,
|
||||
transpose: false,
|
||||
},
|
||||
));
|
||||
}
|
||||
let pixels = rasterize(&mut renderer, &program.0, &uniforms);
|
||||
for y in 0..64 {
|
||||
for x in 0..64 {
|
||||
let point = [x as f64 + 0.5, y as f64 + 0.5];
|
||||
let distance = if scene.paint.is_empty() {
|
||||
reference_distance(point, [0., 0., 64., 64.], 12., CornerShape::Circular)
|
||||
} else {
|
||||
scene.distance(point)
|
||||
};
|
||||
let expected = (coverage(distance) * 255.).round() as u8;
|
||||
let actual = pixels[(y * 64 + x) * 4 + 3];
|
||||
assert!(
|
||||
actual.abs_diff(expected) <= 2,
|
||||
"panel mask mismatch at ({x},{y}): {actual} != {expected}, {scene:?}"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore = "requires an EGL rendering device"]
|
||||
fn apple_window_fill_and_inset_border_match_path_reference_at_fractional_scales() {
|
||||
@@ -412,10 +511,8 @@ fn docked_panel_fill_covers_the_entire_attached_edge() {
|
||||
let mut renderer = renderer();
|
||||
let mut resources = RenderResources::default();
|
||||
let material = material_program_for_corners(&mut resources, &mut renderer, CornerShape::Circular).unwrap();
|
||||
for edge in [ferese_config::panel::Edge::Top, ferese_config::panel::Edge::Bottom] {
|
||||
let radii = ferese_config::panel::CornerRadii([14., 8., 12., 20.])
|
||||
.at_edge(edge, true)
|
||||
.0;
|
||||
for edge in [ferese_panel::Edge::Top, ferese_panel::Edge::Bottom] {
|
||||
let radii = ferese_panel::CornerRadii([14., 8., 12., 20.]).at_edge(edge, true).0;
|
||||
let pixels = rasterize(
|
||||
&mut renderer,
|
||||
&material.0,
|
||||
@@ -428,7 +525,7 @@ fn docked_panel_fill_covers_the_entire_attached_edge() {
|
||||
Uniform::new("shadow_values", [8.0f32, 1.0]),
|
||||
],
|
||||
);
|
||||
let (attached_row, free_row) = if edge == ferese_config::panel::Edge::Top {
|
||||
let (attached_row, free_row) = if edge == ferese_panel::Edge::Top {
|
||||
(0, 35)
|
||||
} else {
|
||||
(35, 0)
|
||||
|
||||
@@ -46,6 +46,7 @@ pub(super) fn append_material_surface(
|
||||
output,
|
||||
surface,
|
||||
MaterialSurface {
|
||||
shape_origin: content_origin,
|
||||
geometry: *rect,
|
||||
corners: *corners,
|
||||
index,
|
||||
@@ -148,6 +149,7 @@ fn framebuffer_corner_radii(radii: [f32; 4], transform: Transform) -> [f32; 4] {
|
||||
}
|
||||
|
||||
pub(super) struct MaterialSurface {
|
||||
pub shape_origin: Point<i32, Logical>,
|
||||
pub geometry: Rectangle<i32, Logical>,
|
||||
pub corners: RoundedRect,
|
||||
pub index: usize,
|
||||
@@ -177,6 +179,7 @@ fn resolve_surface_material(
|
||||
role: crate::effects::SemanticRole,
|
||||
settings: crate::config::ThemeSettings,
|
||||
panel_opacity: Option<f32>,
|
||||
panel_style: ferese_panel::PanelStyle,
|
||||
) -> crate::effects::ResolvedMaterial {
|
||||
let mut material = crate::effects::resolve_material(role, settings.material_style, settings.shell_opacity as f32);
|
||||
if role == crate::effects::SemanticRole::Panel {
|
||||
@@ -185,6 +188,9 @@ fn resolve_surface_material(
|
||||
panel_opacity,
|
||||
settings.reduce_transparency,
|
||||
);
|
||||
if panel_style == ferese_panel::PanelStyle::Morph {
|
||||
material.shadow = [0.; 3];
|
||||
}
|
||||
}
|
||||
material
|
||||
}
|
||||
@@ -198,13 +204,19 @@ pub(super) fn material_element_with_role(
|
||||
(role, generation, opacity): (crate::effects::SemanticRole, u64, f32),
|
||||
) -> Option<(AnimatedWindowRenderElement, AnimatedWindowRenderElement)> {
|
||||
let MaterialSurface {
|
||||
shape_origin,
|
||||
geometry,
|
||||
corners,
|
||||
index,
|
||||
capture_geometry,
|
||||
alpha,
|
||||
} = surface_geometry;
|
||||
let material = resolve_surface_material(role, state.theme_settings, state.panel_background_opacity);
|
||||
let material = resolve_surface_material(
|
||||
role,
|
||||
state.theme_settings,
|
||||
state.panel_background_opacity,
|
||||
state.panel_style,
|
||||
);
|
||||
let presentation_alpha = opacity * alpha;
|
||||
let mode = output.current_mode()?;
|
||||
let scale = output.current_scale().fractional_scale();
|
||||
@@ -214,6 +226,12 @@ pub(super) fn material_element_with_role(
|
||||
} else {
|
||||
state.theme_settings.surface_base_color
|
||||
};
|
||||
let morph = role == crate::effects::SemanticRole::Panel && state.panel_style == ferese_panel::PanelStyle::Morph;
|
||||
let background = if morph {
|
||||
state.theme_settings.surface_raised_color
|
||||
} else {
|
||||
background
|
||||
};
|
||||
let [red, green, blue, _] = background.0;
|
||||
let logical_radii = if role == crate::effects::SemanticRole::Panel {
|
||||
state.panel_corner_radius
|
||||
@@ -234,9 +252,9 @@ pub(super) fn material_element_with_role(
|
||||
let touches_top = role == crate::effects::SemanticRole::Panel && geometry.loc.y == 0;
|
||||
let touches_bottom =
|
||||
role == crate::effects::SemanticRole::Panel && geometry.loc.y + geometry.size.h >= output_size.h;
|
||||
let radii = ferese_config::panel::CornerRadii(radii)
|
||||
let radii = ferese_panel::CornerRadii(radii)
|
||||
.at_top_edge(touches_top)
|
||||
.at_edge(ferese_config::panel::Edge::Bottom, touches_bottom)
|
||||
.at_edge(ferese_panel::Edge::Bottom, touches_bottom)
|
||||
.0;
|
||||
let radius = radii.into_iter().fold(0., f32::max);
|
||||
let corner_radii = framebuffer_corner_radii(radii, transform);
|
||||
@@ -264,7 +282,13 @@ pub(super) fn material_element_with_role(
|
||||
let blur = material_blur_radius(material.style, material.opacity, state.theme_settings.backdrop_blur);
|
||||
let sample_geometry = expanded_blur_region(capture_geometry, blur.ceil() as i32, output_size);
|
||||
let sample_physical = sample_geometry.to_physical_precise_round(scale);
|
||||
let panel = (role == crate::effects::SemanticRole::Panel)
|
||||
.then(|| crate::effects::surface_panel_presentation(surface))
|
||||
.flatten()
|
||||
.map(|presentation| panel_matrices(&presentation, shape_origin, scale, mode.size, transform));
|
||||
let opaque = panel.is_none() && material.opacity == 1.0 && presentation_alpha == 1.0 && radius == 0.0;
|
||||
let mut parameters = MaterialParameters {
|
||||
panel,
|
||||
corner_radii,
|
||||
presentation_alpha,
|
||||
background_opacity,
|
||||
@@ -278,7 +302,7 @@ pub(super) fn material_element_with_role(
|
||||
geometry,
|
||||
tint: [red, green, blue, material.opacity * presentation_alpha],
|
||||
generation,
|
||||
opaque: material.opacity == 1.0 && presentation_alpha == 1.0 && radius == 0.0,
|
||||
opaque,
|
||||
visible_framebuffer: framebuffer_clip_rect(corners.rect, mode.size, transform),
|
||||
};
|
||||
let context = renderer.context_id().erased();
|
||||
@@ -377,6 +401,7 @@ pub(super) fn material_element_with_role(
|
||||
|| cached.parameters.shadow_bounds != parameters.shadow_bounds
|
||||
|| cached.parameters.corner_radii != parameters.corner_radii
|
||||
|| cached.parameters.visible_framebuffer != parameters.visible_framebuffer
|
||||
|| cached.parameters.panel != parameters.panel
|
||||
{
|
||||
cached.shadow.resize(parameters.shadow_bounds, None);
|
||||
cached.shadow.update_uniforms(decoration_uniforms(¶meters, 2.0));
|
||||
@@ -437,8 +462,8 @@ pub(super) fn blur_program(resources: &mut RenderResources, renderer: &mut GlesR
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn blur_uniform_names() -> [UniformName<'static>; 8] {
|
||||
[
|
||||
pub(super) fn blur_uniform_names() -> Vec<UniformName<'static>> {
|
||||
let mut names = vec![
|
||||
UniformName::new("visible_rect", UniformType::_4f),
|
||||
UniformName::new("material_radii", UniformType::_4f),
|
||||
UniformName::new("texture_size", UniformType::_2f),
|
||||
@@ -447,11 +472,13 @@ pub(super) fn blur_uniform_names() -> [UniformName<'static>; 8] {
|
||||
UniformName::new("presentation_alpha", UniformType::_1f),
|
||||
UniformName::new("background_opacity", UniformType::_1f),
|
||||
UniformName::new("tint", UniformType::_4f),
|
||||
]
|
||||
];
|
||||
names.extend(panel_uniform_names());
|
||||
names
|
||||
}
|
||||
|
||||
pub(super) fn blur_uniforms(p: &MaterialParameters) -> Vec<Uniform<'static>> {
|
||||
vec![
|
||||
let mut uniforms = vec![
|
||||
Uniform::new("visible_rect", p.visible_framebuffer),
|
||||
Uniform::new("material_radii", p.corner_radii),
|
||||
Uniform::new("texture_size", [p.sample_framebuffer[2], p.sample_framebuffer[3]]),
|
||||
@@ -460,7 +487,9 @@ pub(super) fn blur_uniforms(p: &MaterialParameters) -> Vec<Uniform<'static>> {
|
||||
Uniform::new("presentation_alpha", p.presentation_alpha),
|
||||
Uniform::new("background_opacity", p.background_opacity),
|
||||
Uniform::new("tint", p.tint),
|
||||
]
|
||||
];
|
||||
uniforms.extend(panel_uniforms(p));
|
||||
uniforms
|
||||
}
|
||||
|
||||
pub(super) fn framebuffer_capture_rect(rect: [f32; 4]) -> [i32; 4] {
|
||||
@@ -502,7 +531,7 @@ pub(super) fn material_program_for_corners(
|
||||
return Some(program.clone());
|
||||
}
|
||||
|
||||
let uniforms = [
|
||||
let mut uniforms = vec![
|
||||
UniformName::new("visible_rect", UniformType::_4f),
|
||||
UniformName::new("material_radii", UniformType::_4f),
|
||||
UniformName::new("tint", UniformType::_4f),
|
||||
@@ -510,6 +539,7 @@ pub(super) fn material_program_for_corners(
|
||||
UniformName::new("shadow_rect", UniformType::_4f),
|
||||
UniformName::new("shadow_values", UniformType::_2f),
|
||||
];
|
||||
uniforms.extend(panel_uniform_names());
|
||||
match renderer.compile_custom_pixel_shader(corner_shader_for(MATERIAL_SHADER, shape), &uniforms) {
|
||||
Ok(program) => {
|
||||
let program = MaterialProgram(program);
|
||||
@@ -532,16 +562,110 @@ pub(super) fn material_uniforms(parameters: &MaterialParameters) -> Vec<Uniform<
|
||||
}
|
||||
|
||||
pub(super) fn decoration_uniforms(parameters: &MaterialParameters, paint_mode: f32) -> Vec<Uniform<'static>> {
|
||||
vec![
|
||||
let mut uniforms = vec![
|
||||
Uniform::new("paint_mode", paint_mode),
|
||||
Uniform::new("shadow_rect", parameters.shadow_rect),
|
||||
Uniform::new("shadow_values", parameters.shadow_values),
|
||||
Uniform::new("visible_rect", parameters.visible_framebuffer),
|
||||
Uniform::new("material_radii", parameters.corner_radii),
|
||||
Uniform::new("tint", parameters.tint),
|
||||
];
|
||||
uniforms.extend(panel_uniforms(parameters));
|
||||
uniforms
|
||||
}
|
||||
|
||||
fn panel_uniform_names() -> [UniformName<'static>; 3] {
|
||||
[
|
||||
UniformName::new("panel_count", UniformType::_1f),
|
||||
UniformName::new("panel_fusion", UniformType::_1f),
|
||||
UniformName::new("panel_shapes[0]", UniformType::Matrix3x3),
|
||||
]
|
||||
}
|
||||
|
||||
fn panel_uniforms(parameters: &MaterialParameters) -> Vec<Uniform<'static>> {
|
||||
use smithay::backend::renderer::gles::UniformValue;
|
||||
let mut uniforms = vec![
|
||||
Uniform::new(
|
||||
"panel_count",
|
||||
parameters.panel.as_ref().map_or(0., |p| p.shapes.len() as f32),
|
||||
),
|
||||
Uniform::new("panel_fusion", parameters.panel.as_ref().map_or(0., |p| p.fusion)),
|
||||
];
|
||||
if let Some(panel) = ¶meters.panel
|
||||
&& !panel.shapes.is_empty()
|
||||
{
|
||||
uniforms.push(Uniform::new(
|
||||
"panel_shapes[0]",
|
||||
UniformValue::Matrix3x3 {
|
||||
matrices: panel.shapes.clone(),
|
||||
transpose: false,
|
||||
},
|
||||
));
|
||||
}
|
||||
uniforms
|
||||
}
|
||||
|
||||
fn panel_matrices(
|
||||
presentation: &crate::effects::PanelPresentation,
|
||||
origin: Point<i32, Logical>,
|
||||
scale: f64,
|
||||
size: Size<i32, Physical>,
|
||||
transform: Transform,
|
||||
) -> PanelMatrices {
|
||||
let permutation = framebuffer_corner_radii([0., 1., 2., 3.], transform);
|
||||
let shapes = presentation
|
||||
.shapes
|
||||
.iter()
|
||||
.map(|primitive| {
|
||||
let b = primitive.bounds;
|
||||
let left = ((b.x + f64::from(origin.x)) * scale).round() as i32;
|
||||
let top = ((b.y + f64::from(origin.y)) * scale).round() as i32;
|
||||
let right = ((b.x + b.width + f64::from(origin.x)) * scale).round() as i32;
|
||||
let bottom = ((b.y + b.height + f64::from(origin.y)) * scale).round() as i32;
|
||||
let physical = Rectangle::new((left, top).into(), (right - left, bottom - top).into());
|
||||
let rect = framebuffer_clip_rect(physical, size, transform);
|
||||
let radii = primitive.radii.0.map(|r| (f64::from(r) * scale) as f32);
|
||||
let radii = framebuffer_corner_radii(
|
||||
ferese_panel::CornerRadii(radii)
|
||||
.normalized(physical.size.w as f32, physical.size.h as f32)
|
||||
.0,
|
||||
transform,
|
||||
);
|
||||
let operation = if primitive.operation >= 2 {
|
||||
let old_corner = match primitive.operation {
|
||||
2 => 3,
|
||||
3 => 2,
|
||||
4 => 1,
|
||||
_ => 0,
|
||||
};
|
||||
match permutation.iter().position(|i| *i == old_corner as f32).unwrap() {
|
||||
0 => 5,
|
||||
1 => 4,
|
||||
2 => 3,
|
||||
_ => 2,
|
||||
}
|
||||
} else {
|
||||
primitive.operation
|
||||
};
|
||||
[
|
||||
rect[0],
|
||||
rect[1],
|
||||
rect[2],
|
||||
rect[3],
|
||||
radii[0],
|
||||
radii[1],
|
||||
radii[2],
|
||||
radii[3],
|
||||
f32::from(operation * 4 + primitive.blend_zone),
|
||||
]
|
||||
})
|
||||
.collect();
|
||||
PanelMatrices {
|
||||
shapes,
|
||||
fusion: (presentation.fusion * scale) as f32,
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn blur_damage(
|
||||
size: Size<i32, Physical>,
|
||||
current: CommitCounter,
|
||||
@@ -562,17 +686,18 @@ mod region_geometry_tests {
|
||||
#[test]
|
||||
fn reduce_transparency_wins_over_continuous_and_island_panel_materials() {
|
||||
use crate::effects::SemanticRole;
|
||||
for surface in ["solid", "none"] {
|
||||
for surface in ["flat", "floating", "morph"] {
|
||||
for opacity in [0., 0.4, 1.] {
|
||||
for reduce in [false, true] {
|
||||
let source = format!(
|
||||
"theme {{ material {{ style translucent; opacity 0.7; }}; accessibility {{ reduce-transparency #{reduce}; }}; }}; panel main {{ surface {surface}; group-surface island; background-opacity {opacity}; }}"
|
||||
"theme {{ material {{ style translucent; opacity 0.7; }}; accessibility {{ reduce-transparency #{reduce}; }}; }}; panel main {{ style {surface}; background-opacity {opacity}; }}"
|
||||
);
|
||||
let (_, runtime, candidate) = crate::theme::prepare(&source, std::path::Path::new("/tmp")).unwrap();
|
||||
let material = resolve_surface_material(
|
||||
SemanticRole::Panel,
|
||||
runtime.theme_settings,
|
||||
runtime.panel_background_opacity,
|
||||
runtime.panel_style,
|
||||
);
|
||||
assert_eq!(material.opacity, if reduce { 1. } else { opacity });
|
||||
assert_eq!(material.opacity, candidate.theme.panel_opacity(Some(opacity)));
|
||||
@@ -587,13 +712,43 @@ mod region_geometry_tests {
|
||||
if reduce {
|
||||
assert_eq!(runtime.theme_settings.backdrop_blur, 0.);
|
||||
}
|
||||
let popover = resolve_surface_material(SemanticRole::Popover, runtime.theme_settings, Some(0.));
|
||||
let popover = resolve_surface_material(
|
||||
SemanticRole::Popover,
|
||||
runtime.theme_settings,
|
||||
Some(0.),
|
||||
runtime.panel_style,
|
||||
);
|
||||
assert!((popover.opacity - if reduce { 1. } else { 0.7 }).abs() < 0.001);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn morph_inherits_translucency_and_blur_without_adding_a_shadow() {
|
||||
use crate::effects::SemanticRole;
|
||||
for reduce in [false, true] {
|
||||
let source = format!(
|
||||
"theme {{ material {{ style translucent; opacity 0.6; blur-radius 20; }}; accessibility {{ reduce-transparency #{reduce}; }}; }}; panel main {{ style morph; }}"
|
||||
);
|
||||
let (_, runtime, candidate) = crate::theme::prepare(&source, std::path::Path::new("/tmp")).unwrap();
|
||||
let material =
|
||||
resolve_surface_material(SemanticRole::Panel, runtime.theme_settings, None, runtime.panel_style);
|
||||
assert_eq!(material.shadow, [0.; 3]);
|
||||
assert_eq!(material.opacity, candidate.theme.panel_opacity(None));
|
||||
assert_eq!(
|
||||
material.style,
|
||||
if reduce {
|
||||
crate::config::MaterialStyle::Solid
|
||||
} else {
|
||||
crate::config::MaterialStyle::Translucent
|
||||
}
|
||||
);
|
||||
let blur = material_blur_radius(material.style, material.opacity, runtime.theme_settings.backdrop_blur);
|
||||
assert_eq!(blur > 0., !reduce);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn framebuffer_transforms_preserve_each_logical_corner() {
|
||||
let radii = [1., 2., 3., 4.];
|
||||
|
||||
@@ -136,6 +136,7 @@ fn corner_shader_for(source: &str, shape: CornerShape) -> String {
|
||||
.replace("precision mediump float;", "precision highp float;"),
|
||||
}
|
||||
.replace("//_MATERIAL_CORNERS_", include_str!("shaders/material_corners.glsl"))
|
||||
.replace("//_PANEL_MASK_", include_str!("shaders/panel_mask.glsl"))
|
||||
}
|
||||
|
||||
pub(crate) fn window_corner_shape(_window: &smithay::desktop::Window) -> CornerShape {
|
||||
@@ -338,8 +339,15 @@ pub(crate) struct OverviewScrim {
|
||||
#[derive(Clone, Debug)]
|
||||
pub(crate) struct MaterialProgram(GlesPixelProgram);
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
struct PanelMatrices {
|
||||
shapes: Vec<[f32; 9]>,
|
||||
fusion: f32,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
struct MaterialParameters {
|
||||
panel: Option<PanelMatrices>,
|
||||
corner_radii: [f32; 4],
|
||||
presentation_alpha: f32,
|
||||
background_opacity: f32,
|
||||
|
||||
@@ -328,6 +328,7 @@ fn scene_elements(
|
||||
output,
|
||||
surface,
|
||||
MaterialSurface {
|
||||
shape_origin: constrain.loc,
|
||||
geometry: constrain,
|
||||
corners,
|
||||
index: 0,
|
||||
|
||||
@@ -21,9 +21,10 @@ uniform vec4 tint;
|
||||
varying vec2 v_coords;
|
||||
//_CORNERS_
|
||||
//_MATERIAL_CORNERS_
|
||||
//_PANEL_MASK_
|
||||
|
||||
void main() {
|
||||
float sdf = rounded_rect_corners_distance(gl_FragCoord.xy, visible_rect, material_radii);
|
||||
float sdf = material_distance(gl_FragCoord.xy, visible_rect, material_radii);
|
||||
float coverage = alpha * presentation_alpha * edge_coverage(sdf);
|
||||
if (coverage <= 0.0) { gl_FragColor = vec4(0.0); return; }
|
||||
vec2 coords = (gl_FragCoord.xy - capture_origin) / texture_size;
|
||||
|
||||
@@ -11,15 +11,16 @@ varying vec2 v_coords;
|
||||
|
||||
//_CORNERS_
|
||||
//_MATERIAL_CORNERS_
|
||||
//_PANEL_MASK_
|
||||
|
||||
void main() {
|
||||
float sdf = rounded_rect_corners_distance(gl_FragCoord.xy, visible_rect, material_radii);
|
||||
float sdf = material_distance(gl_FragCoord.xy, visible_rect, material_radii);
|
||||
float coverage = edge_coverage(sdf);
|
||||
if (paint_mode > 0.5) {
|
||||
// The shadow pass is multiplied by (1 - coverage). Fully covered
|
||||
// pixels need neither a second contour solve nor a Gaussian sample.
|
||||
if (coverage >= 1.0) { gl_FragColor = vec4(0.0); return; }
|
||||
float distance = max(rounded_rect_corners_distance(gl_FragCoord.xy, shadow_rect, material_radii), 0.0);
|
||||
float distance = max(material_distance(gl_FragCoord.xy - (shadow_rect.xy - visible_rect.xy), visible_rect, material_radii), 0.0);
|
||||
float sigma = max(shadow_values.x * 0.5, 0.5);
|
||||
float opacity = exp(-0.5 * distance * distance / (sigma * sigma))
|
||||
* shadow_values.y * (1.0 - coverage) * alpha;
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
// The same signed-distance mask is used by tint, blur and shadow. Shapes are
|
||||
// bounded surface-local geometry transformed into framebuffer coordinates.
|
||||
uniform float panel_count;
|
||||
uniform float panel_fusion;
|
||||
uniform mat3 panel_shapes[32];
|
||||
|
||||
float panel_box_distance(vec2 p, vec4 b) {
|
||||
vec2 q = abs(p - b.xy - b.zw * 0.5) - b.zw * 0.5;
|
||||
return length(max(q, 0.0)) + min(max(q.x, q.y), 0.0);
|
||||
}
|
||||
float panel_round_distance(vec2 p, vec4 b, vec4 r) {
|
||||
vec2 q = p - b.xy;
|
||||
float d = panel_box_distance(p, b);
|
||||
vec2 a = q;
|
||||
if (r.x > 0.0 && a.x < r.x && a.y < r.x) d = max(d, length(a - r.x) - r.x);
|
||||
a = vec2(b.z - q.x, q.y);
|
||||
if (r.y > 0.0 && a.x < r.y && a.y < r.y) d = max(d, length(a - r.y) - r.y);
|
||||
a = b.zw - q;
|
||||
if (r.z > 0.0 && a.x < r.z && a.y < r.z) d = max(d, length(a - r.z) - r.z);
|
||||
a = vec2(q.x, b.w - q.y);
|
||||
if (r.w > 0.0 && a.x < r.w && a.y < r.w) d = max(d, length(a - r.w) - r.w);
|
||||
return d;
|
||||
}
|
||||
float panel_smin(float a, float b) {
|
||||
if (panel_fusion <= 0.0) return min(a, b);
|
||||
float h = max(panel_fusion - abs(a - b), 0.0) / panel_fusion;
|
||||
return min(a, b) - h * h * panel_fusion * 0.25;
|
||||
}
|
||||
float panel_distance(vec2 p) {
|
||||
vec4 unions = vec4(1.0e8);
|
||||
float cutout = 1.0e8;
|
||||
for (int i = 0; i < 32; i++) {
|
||||
if (float(i) >= panel_count) break;
|
||||
mat3 m = panel_shapes[i];
|
||||
vec4 b = vec4(m[0].xyz, m[1].x);
|
||||
vec4 r = vec4(m[1].yz, m[2].xy);
|
||||
float op = floor(m[2].z / 4.0);
|
||||
float zone = mod(m[2].z, 4.0);
|
||||
float d = panel_round_distance(p, b, r);
|
||||
if (op > 1.5) {
|
||||
vec2 c = b.xy;
|
||||
if (op < 2.5) c.y += b.w;
|
||||
else if (op < 3.5) c += b.zw;
|
||||
else if (op < 4.5) c.x += b.z;
|
||||
d = max(panel_box_distance(p, b), min(b.z, b.w) - length(p - c));
|
||||
}
|
||||
if (op > 0.5 && op < 1.5) cutout = min(cutout, d);
|
||||
else if (zone < 0.5) unions.x = min(unions.x, d);
|
||||
else if (zone < 1.5) unions.y = panel_smin(unions.y, d);
|
||||
else if (zone < 2.5) unions.z = panel_smin(unions.z, d);
|
||||
else unions.w = panel_smin(unions.w, d);
|
||||
}
|
||||
return max(min(min(unions.x, unions.y), min(unions.z, unions.w)), -cutout);
|
||||
}
|
||||
float material_distance(vec2 p, vec4 b, vec4 r) {
|
||||
if (panel_count > 0.5) return panel_distance(p);
|
||||
return rounded_rect_corners_distance(p, b, r);
|
||||
}
|
||||
Reference in new issue
Block a user