@@ -4,30 +4,59 @@ use crate::presenter::{PRESENTER_SCREEN_HEIGHT, PRESENTER_SCREEN_WIDTH};
44use crate :: settings:: SettingValue ;
55use screenlayouts:: SCREEN_LAYOUTS ;
66
7+ const SCALE_FACTORS : [ f32 ; 8 ] = [ 0.25 , 0.5 , 0.75 , 1.0 , 1.25 , 1.5 , 1.75 , 2.0 ] ;
8+
79pub struct ScreenLayout {
810 pub index : usize ,
911 pub swap : bool ,
12+ top_scale_index : usize ,
13+ bottom_scale_index : usize ,
1014 overlap : bool ,
1115 screen_top : [ f32 ; 16 ] ,
1216 screen_bottom : [ f32 ; 16 ] ,
17+ bottom_inverse_mtx : [ f32 ; 9 ] ,
1318}
1419
1520impl ScreenLayout {
1621 pub fn settings_value ( ) -> SettingValue {
1722 SettingValue :: List ( 0 , SCREEN_LAYOUTS . iter ( ) . map ( |( name, _) | name. to_string ( ) ) . collect ( ) )
1823 }
1924
20- pub fn new ( index : usize , swap : bool ) -> Self {
25+ pub fn scale_settings_value ( ) -> SettingValue {
26+ SettingValue :: List ( 3 , SCALE_FACTORS . iter ( ) . map ( |factor| format ! ( "{}%" , ( factor * 100.0 ) as u8 ) ) . collect ( ) )
27+ }
28+
29+ fn scale_matrix ( factor : f32 ) -> [ f32 ; 9 ] {
30+ [ factor, 0.0 , 0.0 , 0.0 , factor, 0.0 , 0.0 , 0.0 , 1.0 ]
31+ }
32+
33+ pub fn new ( index : usize , swap : bool , top_scale_index : usize , bottom_scale_index : usize ) -> Self {
2134 const GUEST_DISPLAY_DIM_MTX : [ [ f32 ; 3 ] ; 4 ] = [
2235 [ -( DISPLAY_WIDTH as f32 / 2.0 ) , -( DISPLAY_HEIGHT as f32 / 2.0 ) , 1.0 ] ,
2336 [ DISPLAY_WIDTH as f32 / 2.0 , -( DISPLAY_HEIGHT as f32 / 2.0 ) , 1.0 ] ,
2437 [ DISPLAY_WIDTH as f32 / 2.0 , DISPLAY_HEIGHT as f32 / 2.0 , 1.0 ] ,
2538 [ -( DISPLAY_WIDTH as f32 / 2.0 ) , DISPLAY_HEIGHT as f32 / 2.0 , 1.0 ] ,
2639 ] ;
27- let a_mtx = & SCREEN_LAYOUTS [ index] . 1 [ 0 ] ;
28- let b_mtx = & SCREEN_LAYOUTS [ index] . 1 [ 1 ] ;
40+ let mut a_mtx = SCREEN_LAYOUTS [ index] . 1 [ 0 ] ;
41+ let mut b_mtx = SCREEN_LAYOUTS [ index] . 1 [ 1 ] ;
42+
43+ let top_scale_mtx = Self :: scale_matrix ( SCALE_FACTORS [ top_scale_index] ) ;
44+ let bottom_scale_mtx = Self :: scale_matrix ( SCALE_FACTORS [ bottom_scale_index] ) ;
45+
46+ unsafe {
47+ math:: neon:: matmul3_neon ( a_mtx. as_ptr ( ) as _ , top_scale_mtx. as_ptr ( ) as _ , a_mtx. as_mut_ptr ( ) ) ;
48+ math:: neon:: matmul3_neon ( b_mtx. as_ptr ( ) as _ , bottom_scale_mtx. as_ptr ( ) as _ , b_mtx. as_mut_ptr ( ) ) ;
49+ }
50+
2951 let mut screen_top = [ [ 0.0 ; 3 ] ; 4 ] ;
3052 let mut screen_bottom = [ [ 0.0 ; 3 ] ; 4 ] ;
53+ let mut bottom_inverse_mtx = SCREEN_LAYOUTS [ index] . 1 [ if swap { 2 } else { 3 } ] ;
54+
55+ unsafe {
56+ let inverse_scale_mtx = Self :: scale_matrix ( 1.0 / SCALE_FACTORS [ if swap { top_scale_index } else { bottom_scale_index } ] ) ;
57+ math:: neon:: matmul3_neon ( inverse_scale_mtx. as_ptr ( ) as _ , bottom_inverse_mtx. as_ptr ( ) as _ , bottom_inverse_mtx. as_mut_ptr ( ) ) ;
58+ }
59+
3160 let overlap = unsafe {
3261 for i in 0 ..GUEST_DISPLAY_DIM_MTX . len ( ) {
3362 math:: neon:: matvec3_neon ( a_mtx. as_ptr ( ) as _ , GUEST_DISPLAY_DIM_MTX [ i] . as_ptr ( ) as _ , screen_top[ i] . as_mut_ptr ( ) ) ;
@@ -52,9 +81,12 @@ impl ScreenLayout {
5281
5382 overlap
5483 } ;
84+
5585 ScreenLayout {
5686 index,
5787 swap,
88+ top_scale_index,
89+ bottom_scale_index,
5890 overlap,
5991 screen_top : [
6092 screen_top[ 0 ] [ 0 ] ,
@@ -92,23 +124,22 @@ impl ScreenLayout {
92124 0.0 ,
93125 0.0 ,
94126 ] ,
127+ bottom_inverse_mtx,
95128 }
96129 }
97130
98- pub fn apply_settings_event ( & self , offset : i8 , swap : bool ) -> ScreenLayout {
131+ pub fn apply_settings_event ( & self , offset : i8 , swap : bool , top_screen_scale_offset : i8 , bottom_screen_scale_offset : i8 ) -> ScreenLayout {
99132 ScreenLayout :: new (
100133 ( ( SCREEN_LAYOUTS . len ( ) as isize + ( self . index as isize + offset as isize ) ) % SCREEN_LAYOUTS . len ( ) as isize ) as usize ,
101134 self . swap ^ swap,
135+ ( ( SCALE_FACTORS . len ( ) as isize + ( self . top_scale_index as isize + top_screen_scale_offset as isize ) ) % SCALE_FACTORS . len ( ) as isize ) as usize ,
136+ ( ( SCALE_FACTORS . len ( ) as isize + ( self . bottom_scale_index as isize + bottom_screen_scale_offset as isize ) ) % SCALE_FACTORS . len ( ) as isize ) as usize ,
102137 )
103138 }
104139
105- pub fn get_bottom_inverse_mtx ( & self ) -> & [ f32 ; 9 ] {
106- & SCREEN_LAYOUTS [ self . index ] . 1 [ if self . swap { 2 } else { 3 } ]
107- }
108-
109140 pub fn normalize_touch_points ( & self , x : i16 , y : i16 ) -> ( i16 , i16 ) {
110141 let mut touch_points = [ x as f32 , y as f32 , 1.0 ] ;
111- unsafe { math:: neon:: matvec3_neon ( self . get_bottom_inverse_mtx ( ) . as_ptr ( ) as _ , touch_points. as_ptr ( ) as _ , touch_points. as_mut_ptr ( ) as _ ) } ;
142+ unsafe { math:: neon:: matvec3_neon ( self . bottom_inverse_mtx . as_ptr ( ) as _ , touch_points. as_ptr ( ) as _ , touch_points. as_mut_ptr ( ) as _ ) } ;
112143 ( touch_points[ 0 ] as i16 + DISPLAY_WIDTH as i16 / 2 , touch_points[ 1 ] as i16 + DISPLAY_HEIGHT as i16 / 2 )
113144 }
114145
0 commit comments