mirror of
https://github.com/niri-wm/niri.git
synced 2026-06-23 02:05:33 +07:00
visual-tests: Add gradient angle and area tests
This commit is contained in:
@@ -0,0 +1,76 @@
|
|||||||
|
use std::f32::consts::{FRAC_PI_2, PI};
|
||||||
|
use std::sync::atomic::Ordering;
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
|
use niri::animation::ANIMATION_SLOWDOWN;
|
||||||
|
use niri::render_helpers::gradient::GradientRenderElement;
|
||||||
|
use smithay::backend::renderer::element::RenderElement;
|
||||||
|
use smithay::backend::renderer::gles::GlesRenderer;
|
||||||
|
use smithay::utils::{Logical, Physical, Rectangle, Scale, Size};
|
||||||
|
|
||||||
|
use super::TestCase;
|
||||||
|
|
||||||
|
pub struct GradientAngle {
|
||||||
|
angle: f32,
|
||||||
|
prev_time: Duration,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl GradientAngle {
|
||||||
|
pub fn new(_size: Size<i32, Logical>) -> Self {
|
||||||
|
Self {
|
||||||
|
angle: 0.,
|
||||||
|
prev_time: Duration::ZERO,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TestCase for GradientAngle {
|
||||||
|
fn are_animations_ongoing(&self) -> bool {
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
|
fn advance_animations(&mut self, current_time: Duration) {
|
||||||
|
let mut delta = if self.prev_time.is_zero() {
|
||||||
|
Duration::ZERO
|
||||||
|
} else {
|
||||||
|
current_time.saturating_sub(self.prev_time)
|
||||||
|
};
|
||||||
|
self.prev_time = current_time;
|
||||||
|
|
||||||
|
let slowdown = ANIMATION_SLOWDOWN.load(Ordering::SeqCst);
|
||||||
|
if slowdown == 0. {
|
||||||
|
delta = Duration::ZERO
|
||||||
|
} else {
|
||||||
|
delta = delta.div_f64(slowdown);
|
||||||
|
}
|
||||||
|
|
||||||
|
self.angle += delta.as_secs_f32() * PI;
|
||||||
|
|
||||||
|
if self.angle >= PI * 2. {
|
||||||
|
self.angle -= PI * 2.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn render(
|
||||||
|
&mut self,
|
||||||
|
renderer: &mut GlesRenderer,
|
||||||
|
size: Size<i32, Physical>,
|
||||||
|
) -> Vec<Box<dyn RenderElement<GlesRenderer>>> {
|
||||||
|
let (a, b) = (size.w / 4, size.h / 4);
|
||||||
|
let size = (size.w - a * 2, size.h - b * 2);
|
||||||
|
let area = Rectangle::from_loc_and_size((a, b), size);
|
||||||
|
|
||||||
|
GradientRenderElement::new(
|
||||||
|
renderer,
|
||||||
|
Scale::from(1.),
|
||||||
|
area,
|
||||||
|
area,
|
||||||
|
[1., 0., 0., 1.],
|
||||||
|
[0., 1., 0., 1.],
|
||||||
|
self.angle - FRAC_PI_2,
|
||||||
|
)
|
||||||
|
.into_iter()
|
||||||
|
.map(|elem| Box::new(elem) as _)
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,116 @@
|
|||||||
|
use std::f32::consts::{FRAC_PI_4, PI};
|
||||||
|
use std::sync::atomic::Ordering;
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
|
use niri::animation::ANIMATION_SLOWDOWN;
|
||||||
|
use niri::layout::focus_ring::FocusRing;
|
||||||
|
use niri::render_helpers::gradient::GradientRenderElement;
|
||||||
|
use niri_config::Color;
|
||||||
|
use smithay::backend::renderer::element::RenderElement;
|
||||||
|
use smithay::backend::renderer::gles::GlesRenderer;
|
||||||
|
use smithay::utils::{Logical, Physical, Point, Rectangle, Scale, Size};
|
||||||
|
|
||||||
|
use super::TestCase;
|
||||||
|
|
||||||
|
pub struct GradientArea {
|
||||||
|
progress: f32,
|
||||||
|
border: FocusRing,
|
||||||
|
prev_time: Duration,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl GradientArea {
|
||||||
|
pub fn new(_size: Size<i32, Logical>) -> Self {
|
||||||
|
let mut border = FocusRing::new(niri_config::FocusRing {
|
||||||
|
off: false,
|
||||||
|
width: 1,
|
||||||
|
active_color: Color::new(255, 255, 255, 128),
|
||||||
|
inactive_color: Color::default(),
|
||||||
|
active_gradient: None,
|
||||||
|
inactive_gradient: None,
|
||||||
|
});
|
||||||
|
border.set_active(true);
|
||||||
|
|
||||||
|
Self {
|
||||||
|
progress: 0.,
|
||||||
|
border,
|
||||||
|
prev_time: Duration::ZERO,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TestCase for GradientArea {
|
||||||
|
fn are_animations_ongoing(&self) -> bool {
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
|
fn advance_animations(&mut self, current_time: Duration) {
|
||||||
|
let mut delta = if self.prev_time.is_zero() {
|
||||||
|
Duration::ZERO
|
||||||
|
} else {
|
||||||
|
current_time.saturating_sub(self.prev_time)
|
||||||
|
};
|
||||||
|
self.prev_time = current_time;
|
||||||
|
|
||||||
|
let slowdown = ANIMATION_SLOWDOWN.load(Ordering::SeqCst);
|
||||||
|
if slowdown == 0. {
|
||||||
|
delta = Duration::ZERO
|
||||||
|
} else {
|
||||||
|
delta = delta.div_f64(slowdown);
|
||||||
|
}
|
||||||
|
|
||||||
|
self.progress += delta.as_secs_f32() * PI;
|
||||||
|
|
||||||
|
if self.progress >= PI * 2. {
|
||||||
|
self.progress -= PI * 2.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn render(
|
||||||
|
&mut self,
|
||||||
|
renderer: &mut GlesRenderer,
|
||||||
|
size: Size<i32, Physical>,
|
||||||
|
) -> Vec<Box<dyn RenderElement<GlesRenderer>>> {
|
||||||
|
let mut rv = Vec::new();
|
||||||
|
|
||||||
|
let f = (self.progress.sin() + 1.) / 2.;
|
||||||
|
|
||||||
|
let (a, b) = (size.w / 4, size.h / 4);
|
||||||
|
let rect_size = (size.w - a * 2, size.h - b * 2);
|
||||||
|
let area = Rectangle::from_loc_and_size((a, b), rect_size);
|
||||||
|
|
||||||
|
let g_size = Size::from((
|
||||||
|
(size.w as f32 / 8. + size.w as f32 / 8. * 7. * f).round() as i32,
|
||||||
|
(size.h as f32 / 8. + size.h as f32 / 8. * 7. * f).round() as i32,
|
||||||
|
));
|
||||||
|
let g_loc = ((size.w - g_size.w) / 2, (size.h - g_size.h) / 2);
|
||||||
|
let g_area = Rectangle::from_loc_and_size(g_loc, g_size);
|
||||||
|
|
||||||
|
self.border.update(g_size, true);
|
||||||
|
rv.extend(
|
||||||
|
self.border
|
||||||
|
.render(
|
||||||
|
renderer,
|
||||||
|
Point::from(g_loc),
|
||||||
|
Scale::from(1.),
|
||||||
|
size.to_logical(1),
|
||||||
|
)
|
||||||
|
.map(|elem| Box::new(elem) as _),
|
||||||
|
);
|
||||||
|
|
||||||
|
rv.extend(
|
||||||
|
GradientRenderElement::new(
|
||||||
|
renderer,
|
||||||
|
Scale::from(1.),
|
||||||
|
area,
|
||||||
|
g_area,
|
||||||
|
[1., 0., 0., 1.],
|
||||||
|
[0., 1., 0., 1.],
|
||||||
|
FRAC_PI_4,
|
||||||
|
)
|
||||||
|
.into_iter()
|
||||||
|
.map(|elem| Box::new(elem) as _),
|
||||||
|
);
|
||||||
|
|
||||||
|
rv
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,12 +4,14 @@ use smithay::backend::renderer::element::RenderElement;
|
|||||||
use smithay::backend::renderer::gles::GlesRenderer;
|
use smithay::backend::renderer::gles::GlesRenderer;
|
||||||
use smithay::utils::{Physical, Size};
|
use smithay::utils::{Physical, Size};
|
||||||
|
|
||||||
|
pub mod gradient_angle;
|
||||||
|
pub mod gradient_area;
|
||||||
pub mod layout;
|
pub mod layout;
|
||||||
pub mod tile;
|
pub mod tile;
|
||||||
pub mod window;
|
pub mod window;
|
||||||
|
|
||||||
pub trait TestCase {
|
pub trait TestCase {
|
||||||
fn resize(&mut self, width: i32, height: i32);
|
fn resize(&mut self, _width: i32, _height: i32) {}
|
||||||
fn are_animations_ongoing(&self) -> bool {
|
fn are_animations_ongoing(&self) -> bool {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,8 @@ use smithay::utils::{Logical, Size};
|
|||||||
use smithay_view::SmithayView;
|
use smithay_view::SmithayView;
|
||||||
use tracing_subscriber::EnvFilter;
|
use tracing_subscriber::EnvFilter;
|
||||||
|
|
||||||
|
use crate::cases::gradient_angle::GradientAngle;
|
||||||
|
use crate::cases::gradient_area::GradientArea;
|
||||||
use crate::cases::layout::Layout;
|
use crate::cases::layout::Layout;
|
||||||
use crate::cases::TestCase;
|
use crate::cases::TestCase;
|
||||||
|
|
||||||
@@ -108,6 +110,9 @@ fn build_ui(app: &adw::Application) {
|
|||||||
"Layout - Open To The Left - Big",
|
"Layout - Open To The Left - Big",
|
||||||
);
|
);
|
||||||
|
|
||||||
|
s.add(GradientAngle::new, "Gradient - Angle");
|
||||||
|
s.add(GradientArea::new, "Gradient - Area");
|
||||||
|
|
||||||
let content_headerbar = adw::HeaderBar::new();
|
let content_headerbar = adw::HeaderBar::new();
|
||||||
|
|
||||||
let anim_adjustment = gtk::Adjustment::new(1., 0., 10., 0.1, 0.5, 0.);
|
let anim_adjustment = gtk::Adjustment::new(1., 0., 10., 0.1, 0.5, 0.);
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ mod imp {
|
|||||||
use anyhow::{ensure, Context};
|
use anyhow::{ensure, Context};
|
||||||
use gtk::gdk;
|
use gtk::gdk;
|
||||||
use gtk::prelude::*;
|
use gtk::prelude::*;
|
||||||
|
use niri::render_helpers::shaders;
|
||||||
use niri::utils::get_monotonic_time;
|
use niri::utils::get_monotonic_time;
|
||||||
use smithay::backend::egl::ffi::egl;
|
use smithay::backend::egl::ffi::egl;
|
||||||
use smithay::backend::egl::EGLContext;
|
use smithay::backend::egl::EGLContext;
|
||||||
@@ -190,8 +191,12 @@ mod imp {
|
|||||||
.into_iter()
|
.into_iter()
|
||||||
.filter(|c| *c != Capability::ColorTransformations);
|
.filter(|c| *c != Capability::ColorTransformations);
|
||||||
|
|
||||||
GlesRenderer::with_capabilities(egl_context, capabilities)
|
let mut renderer = GlesRenderer::with_capabilities(egl_context, capabilities)
|
||||||
.context("error creating GlesRenderer")
|
.context("error creating GlesRenderer")?;
|
||||||
|
|
||||||
|
shaders::init(&mut renderer);
|
||||||
|
|
||||||
|
Ok(renderer)
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe fn with_framebuffer_save_restore<T>(
|
unsafe fn with_framebuffer_save_restore<T>(
|
||||||
|
|||||||
Reference in New Issue
Block a user