Commit 5a760f013a02
tarball9 files changed+2-318
@@ -99,22 +99,6 @@ mod tests {
9999
use proptest::prelude::*;100100
101101
#[test]102
- fn endpoints_are_exact() {103
- for c in [CubicBezier::LINEAR, CubicBezier::EASE] {104
- assert_eq!(c.sample(0.0), 0.0);105
- assert_eq!(c.sample(1.0), 1.0);106
- }107
- }108
-109
- #[test]110
- fn linear_is_identity() {111
- for i in 0..=100 {112
- let t = f64::from(i) / 100.0;113
- assert!((CubicBezier::LINEAR.sample(t) - t).abs() < 1e-6);114
- }115
- }116
-117
- #[test]118102
fn matched_slope_is_honoured() {119103
let c = CubicBezier::EASE.with_initial_slope(2.0);120104
assert!((c.initial_slope() - 2.0).abs() < 1e-9);@@ -35,31 +35,3 @@ impl Timeline {
3535
Position::Phase { phase, t }3636
}3737
}38
-39
-#[cfg(test)]40
-mod tests {41
- use super::*;42
-43
- #[test]44
- fn locates_phases() {45
- let tl = Timeline {46
- start_ns: 1_000,47
- phase_ns: 100,48
- phases: 3,49
- };50
- assert_eq!(tl.locate(999), Position::NotStarted);51
- assert_eq!(tl.locate(1_000), Position::Phase { phase: 0, t: 0.0 });52
- assert_eq!(tl.locate(1_150), Position::Phase { phase: 1, t: 0.5 });53
- assert_eq!(tl.locate(1_300), Position::Finished);54
- }55
-56
- #[test]57
- fn total_time_is_phases_times_duration() {58
- let tl = Timeline {59
- start_ns: 0,60
- phase_ns: 160_000_000,61
- phases: 4,62
- };63
- assert_eq!(tl.end_ns(), 640_000_000);64
- }65
-}@@ -36,24 +36,9 @@ mod tests {
3636
use super::*;3737
3838
#[test]39
- fn continues_same_direction() {40
- let slope = group_initial_slope([([100.0, 100.0, 0.0, 0.0], [50.0, 50.0, 0.0, 0.0])], 0.5);41
- assert_eq!(slope, Some(1.0));42
- }43
-44
- #[test]4539
fn reversal_starts_from_rest() {4640
let slope =4741
group_initial_slope([([100.0, 100.0, 0.0, 0.0], [-50.0, -50.0, 0.0, 0.0])], 0.5);4842
assert_eq!(slope, None);4943
}50
-51
- #[test]52
- fn ignores_windows_that_do_not_move_this_phase() {53
- let movers = [54
- ([500.0, 500.0, 0.0, 0.0], [0.0; 4]),55
- ([10.0, 10.0, 0.0, 0.0], [20.0, 20.0, 0.0, 0.0]),56
- ];57
- assert_eq!(group_initial_slope(movers, 1.0), Some(0.5));58
- }5944
}@@ -150,26 +150,10 @@ mod tests {
150150
use super::*;151151
152152
#[test]153
- fn satisfiable() {154
- let mut s = TwoSat::new(2);155
- s.either(Lit::new(0, true), Lit::new(1, true));156
- s.either(Lit::new(0, false), Lit::new(1, true));157
- let sol = s.solve().unwrap();158
- assert!(sol[1]);159
- }160
-161
- #[test]162153
fn unsatisfiable() {163154
let mut s = TwoSat::new(1);164155
s.require(Lit::new(0, true));165156
s.require(Lit::new(0, false));166157
assert!(s.solve().is_none());167158
}168
-169
- #[test]170
- fn preferences_are_kept_when_possible() {171
- let mut s = TwoSat::new(2);172
- s.either(Lit::new(0, false), Lit::new(1, false));173
- assert_eq!(s.solve_preferring(&[true, true]), Some(vec![true, false]));174
- }175159
}@@ -63,16 +63,6 @@ fn strategy(p: &Plan) -> Strategy {
6363
}6464
6565
#[test]66
-fn swap_uses_two_lanes() {67
- let c = cfg(Style::Orthogonal);68
- let ab = cols(region(), 2);69
- let ba = vec![ab[1], ab[0]];70
- let p = plan(&ab, &ba, &c);71
- assert_clean(&p, &c);72
- assert_eq!(strategy(&p), Strategy::Lanes { lanes: 2 });73
-}74
-75
-#[test]7666
fn full_reversal_needs_one_lane_per_window() {7767
let c = cfg(Style::Orthogonal);7868
let a = cols(region(), 4);@@ -83,14 +73,6 @@ fn full_reversal_needs_one_lane_per_window() {
8373
}8474
8575
#[test]86
-fn orientation_flip_is_two_phases() {87
- let c = cfg(Style::Orthogonal);88
- let p = plan(&cols(region(), 3), &rows(region(), 3), &c);89
- assert_clean(&p, &c);90
- assert_eq!(strategy(&p), Strategy::AxisOrder);91
-}92
-93
-#[test]9476
fn growing_both_axes_depends_on_style() {9577
let grid = |wide: bool| {9678
let r = if wide { [7.0, 3.0] } else { [1.0, 1.0] };@@ -143,24 +125,6 @@ fn insert_and_split_rewinds() {
143125
}144126
145127
#[test]146
-fn inserting_a_seed_is_one_phase() {147
- let c = cfg(Style::Orthogonal);148
- let three = cols(region(), 3);149
- let four = cols(region(), 4);150
- let seed = Rect::new(151
- (three[1].right() + three[2].x) / 2.0,152
- three[1].y,153
- 0.0,154
- three[1].h,155
- );156
- let from = vec![three[0], three[1], three[2], seed];157
- let to = vec![four[0], four[1], four[3], four[2]];158
- let p = plan(&from, &to, &c);159
- assert_clean(&p, &c);160
- assert_eq!(strategy(&p), Strategy::Direct);161
-}162
-163
-#[test]164128
fn tag_rows_swap_rigidly_with_two_lanes() {165129
let c = cfg(Style::Orthogonal);166130
let layout = |first_top: bool| {@@ -193,22 +157,6 @@ fn simultaneous_reversals_on_both_axes_use_the_grid() {
193157
assert!(matches!(strategy(&p), Strategy::Grid { .. }));194158
}195159
196
-#[test]197
-fn distant_groups_plan_independently() {198
- let c = cfg(Style::Orthogonal);199
- let thirds = cols(region(), 3);200
- let l = rows(thirds[0], 2);201
- let from = vec![l[0], l[1], thirds[1], thirds[2]];202
- let to = vec![l[1], l[0], thirds[1], thirds[2]];203
- let p = plan(&from, &to, &c);204
- assert_clean(&p, &c);205
- assert!(206
- p.groups207
- .iter()208
- .any(|g| g.members == [3] && g.strategy == Strategy::Unchanged)209
- );210
-}211
-212160
struct Rng(u64);213161
214162
impl Rng {@@ -303,29 +251,3 @@ proptest! {
303251
prop_assert_eq!(&second.keyframes[0], &mid);304252
}305253
}306
-307
-#[test]308
-#[ignore = "statistics, run with --ignored --nocapture"]309
-fn strategy_distribution() {310
- use std::collections::BTreeMap;311
- for style in [Style::Orthogonal, Style::Direct] {312
- let c = cfg(style);313
- let mut rng = Rng(0x9e37_79b9_7f4a_7c15);314
- let mut counts: BTreeMap<String, usize> = BTreeMap::new();315
- let mut holes = 0;316
- for _ in 0..20_000 {317
- let n = 2 + rng.below(7);318
- let (a, b) = (random_layout(&mut rng, n), random_layout(&mut rng, n));319
- let p = plan(&a, &b, &c);320
- assert_clean(&p, &c);321
- holes += p.groups.iter().filter(|g| g.opens_hole).count();322
- let key = match strategy(&p) {323
- Strategy::Lanes { .. } => "Lanes".to_string(),324
- Strategy::Grid { .. } => "Grid".to_string(),325
- s => format!("{s:?}"),326
- };327
- *counts.entry(key).or_default() += 1;328
- }329
- println!("{style:?}: {counts:?}, plans opening a hole: {holes}");330
- }331
-}@@ -67,22 +67,6 @@ mod tests {
6767
use super::*;6868
6969
#[test]70
- fn crossing_windows_overlap() {71
- let a0 = Rect::new(0.0, 0.0, 100.0, 100.0);72
- let b0 = Rect::new(110.0, 0.0, 100.0, 100.0);73
- assert!(overlaps_during(&a0, &b0, &b0, &a0, 0.5));74
- }75
-76
- #[test]77
- fn neighbours_moving_together_do_not() {78
- let a0 = Rect::new(0.0, 0.0, 100.0, 100.0);79
- let a1 = Rect::new(0.0, 0.0, 150.0, 100.0);80
- let b0 = Rect::new(110.0, 0.0, 100.0, 100.0);81
- let b1 = Rect::new(160.0, 0.0, 50.0, 100.0);82
- assert!(!overlaps_during(&a0, &a1, &b0, &b1, 0.5));83
- }84
-85
- #[test]8670
fn zero_size_seed_inside_a_window_is_not_an_overlap() {8771
let a = Rect::new(0.0, 0.0, 100.0, 100.0);8872
let seed = Rect::new(50.0, 0.0, 0.0, 100.0);@@ -86,24 +86,6 @@ mod tests {
8686
use super::*;8787
8888
#[test]89
- fn identity_covers_the_whole_texture() {90
- let uv = texture_uvs(91
- Rectangle::from_size((4.0, 2.0).into()),92
- (8, 4).into(),93
- (4, 2).into(),94
- Transform::Normal,95
- );96
- assert_eq!(uv, [[0.0, 0.0], [1.0, 0.0], [0.0, 1.0], [1.0, 1.0]]);97
- }98
-99
- #[test]100
- fn crop_selects_part_of_the_texture() {101
- let src = Rectangle::new((2.0, 0.0).into(), (2.0, 2.0).into());102
- let uv = texture_uvs(src, (2, 2).into(), (4, 2).into(), Transform::Normal);103
- assert_eq!(uv, [[0.5, 0.0], [1.0, 0.0], [0.5, 1.0], [1.0, 1.0]]);104
- }105
-106
- #[test]10789
fn rotation_permutes_corners_without_moving_identity_outputs() {10890
let dst = Rectangle::new((0, 0).into(), (10, 10).into());10991
let uvs = [[0.0, 0.0], [1.0, 0.0], [0.0, 1.0], [1.0, 1.0]];@@ -55,22 +55,6 @@ fn all_rgba(bytes: &[u8], want: [u8; 4]) -> bool {
5555
}5656
5757
#[test]58
-fn renders_into_an_allocated_dmabuf_and_reads_it_back() {59
- let Some(mut r) = renderer() else { return };60
- let mut buf = dmabuf(&r);61
- fill(&mut r, &mut buf, [1.0, 0.0, 0.0, 1.0]).wait().unwrap();62
- let target = r.bind(&mut buf).unwrap();63
- let mapping = r64
- .copy_framebuffer(65
- &target,66
- Rectangle::from_size((SIZE, SIZE).into()),67
- Fourcc::Abgr8888,68
- )69
- .unwrap();70
- assert!(all_rgba(r.map_texture(&mapping).unwrap(), [255, 0, 0, 255]));71
-}72
-73
-#[test]7458
fn samples_an_imported_dmabuf() {7559
let Some(mut r) = renderer() else { return };7660
let mut buf = dmabuf(&r);@@ -109,15 +93,6 @@ fn samples_an_imported_dmabuf() {
10993
}11094
11195
#[test]112
-fn imports_are_cached_per_buffer() {113
- let Some(mut r) = renderer() else { return };114
- let buf = dmabuf(&r);115
- let a = r.import_dmabuf(&buf, None).unwrap();116
- let b = r.import_dmabuf(&buf, None).unwrap();117
- assert_eq!(format!("{a:?}"), format!("{b:?}"));118
-}119
-120
-#[test]12196
fn frame_fences_export_as_sync_files() {12297
let Some(mut r) = renderer() else { return };12398
let mut buf = dmabuf(&r);@@ -4,9 +4,9 @@
44
use monolith_render_vk::{VulkanImage, VulkanRenderer, VulkanTexture};55
use smithay::backend::allocator::Fourcc;66
use smithay::backend::renderer::{7
- Bind, Color32F, ExportMem, Frame, ImportMem, Offscreen, Renderer, TextureFilter,7
+ Bind, Color32F, ExportMem, Frame, ImportMem, Offscreen, Renderer,88
};9
-use smithay::utils::{Physical, Rectangle, Size, Transform};9
+use smithay::utils::{Physical, Rectangle, Transform};1010
1111
const W: i32 = 64;1212
const H: i32 = 64;@@ -15,7 +15,6 @@ type Pixel = [u8; 4];
1515
1616
const RED: Pixel = [255, 0, 0, 255];1717
const GREEN: Pixel = [0, 255, 0, 255];18
-const BLUE: Pixel = [0, 0, 255, 255];1918
const WHITE: Pixel = [255, 255, 255, 255];2019
const BLACK: Pixel = [0, 0, 0, 255];2120
@@ -87,45 +86,6 @@ fn rgba(p: Pixel) -> Color32F {
8786
}8887
8988
#[test]90
-fn clears_to_a_colour() {91
- let mut s = Scene::new();92
- s.draw(Transform::Normal, |f| {93
- f.clear(rgba(RED), &[full()]).unwrap()94
- });95
- let px = s.pixels();96
- assert!(px.iter().all(|&p| p == RED));97
-}98
-99
-#[test]100
-fn solid_fill_respects_its_rectangle() {101
- let mut s = Scene::new();102
- s.draw(Transform::Normal, |f| {103
- f.clear(rgba(BLACK), &[full()]).unwrap();104
- let dst = Rectangle::new((16, 16).into(), (32, 32).into());105
- f.draw_solid(dst, &[Rectangle::from_size(dst.size)], rgba(GREEN))106
- .unwrap();107
- });108
- let px = s.pixels();109
- assert_eq!(at(&px, 16, 16), GREEN);110
- assert_eq!(at(&px, 47, 47), GREEN);111
- assert_eq!(at(&px, 15, 16), BLACK);112
- assert_eq!(at(&px, 48, 47), BLACK);113
-}114
-115
-#[test]116
-fn damage_limits_drawing() {117
- let mut s = Scene::new();118
- s.draw(Transform::Normal, |f| {119
- f.clear(rgba(BLACK), &[full()]).unwrap();120
- let damage = Rectangle::new((0, 0).into(), (8, 8).into());121
- f.draw_solid(full(), &[damage], rgba(BLUE)).unwrap();122
- });123
- let px = s.pixels();124
- assert_eq!(at(&px, 7, 7), BLUE);125
- assert_eq!(at(&px, 8, 8), BLACK);126
-}127
-128
-#[test]12989
fn partial_clear_keeps_previous_contents() {13090
let mut s = Scene::new();13191
s.draw(Transform::Normal, |f| {@@ -144,30 +104,6 @@ fn partial_clear_keeps_previous_contents() {
144104
}145105
146106
#[test]147
-fn textures_sample_with_nearest_filtering() {148
- let mut s = Scene::new();149
- s.renderer.upscale_filter(TextureFilter::Nearest).unwrap();150
- let tex = s.texture((2, 2), &[RED, GREEN, BLUE, WHITE]);151
- s.draw(Transform::Normal, |f| {152
- f.render_texture_from_to(153
- &tex,154
- Rectangle::from_size((2.0, 2.0).into()),155
- full(),156
- &[full()],157
- &[],158
- Transform::Normal,159
- 1.0,160
- )161
- .unwrap();162
- });163
- let px = s.pixels();164
- assert_eq!(at(&px, 8, 8), RED);165
- assert_eq!(at(&px, 56, 8), GREEN);166
- assert_eq!(at(&px, 8, 56), BLUE);167
- assert_eq!(at(&px, 56, 56), WHITE);168
-}169
-170
-#[test]171107
fn alpha_blends_premultiplied() {172108
let mut s = Scene::new();173109
let tex = s.texture((1, 1), &[WHITE]);@@ -206,46 +142,6 @@ fn output_transform_moves_content() {
206142
}207143
208144
#[test]209
-fn offscreen_images_can_be_sampled() {210
- let mut s = Scene::new();211
- let mut inner = s212
- .renderer213
- .create_buffer(Fourcc::Argb8888, Size::from((4, 4)))214
- .unwrap();215
- {216
- let mut t = s.renderer.bind(&mut inner).unwrap();217
- let mut f = s218
- .renderer219
- .render(&mut t, (4, 4).into(), Transform::Normal)220
- .unwrap();221
- f.clear(rgba(BLUE), &[Rectangle::from_size((4, 4).into())])222
- .unwrap();223
- f.finish().unwrap().wait().unwrap();224
- }225
- let tex = inner.texture();226
- s.draw(Transform::Normal, |f| {227
- f.render_texture_from_to(228
- &tex,229
- Rectangle::from_size((4.0, 4.0).into()),230
- full(),231
- &[full()],232
- &[],233
- Transform::Normal,234
- 1.0,235
- )236
- .unwrap();237
- });238
- assert_eq!(at(&s.pixels(), 32, 32), BLUE);239
-}240
-241
-#[test]242
-fn reports_the_device() {243
- let r = VulkanRenderer::new().unwrap();244
- eprintln!("rendering on {}", r.device_name());245
- assert!(!r.device_name().is_empty());246
-}247
-248
-#[test]249145
fn solid_fill_in_the_corner_keeps_its_colour() {250146
let mut s = Scene::new();251147
s.draw(Transform::Normal, |f| {