@@ -1044,73 +1044,11 @@ impl SurfaceThreadState {
10441044 // we can't use the elements after `compositor.render_frame`,
10451045 // so let's collect everything we need for screencopy now
10461046 let mut has_cursor_mode_none = false ;
1047- let frames: Vec < (
1048- ScreencopySessionRef ,
1049- ScreencopyFrame ,
1050- Result < ( Option < Vec < Rectangle < i32 , Physical > > > , RenderElementStates ) , OutputNoMode > ,
1051- ) > = self
1047+ let frames = self
10521048 . mirroring
10531049 . is_none ( )
1054- . then ( || {
1055- self . output
1056- . take_pending_frames ( )
1057- . into_iter ( )
1058- . map ( |( session, frame) | {
1059- let additional_damage = frame. damage ( ) ;
1060- let session_data = session. user_data ( ) . get :: < SessionData > ( ) . unwrap ( ) ;
1061- let mut damage_tracking = session_data. lock ( ) . unwrap ( ) ;
1062-
1063- let old_len = if !additional_damage. is_empty ( ) {
1064- let area = self
1065- . output
1066- . current_mode ( )
1067- . unwrap ( )
1068- /* TODO: Mode is Buffer..., why is this Physical in the first place */
1069- . size
1070- . to_logical ( 1 )
1071- . to_buffer ( 1 , Transform :: Normal )
1072- . to_f64 ( ) ;
1073-
1074- let old_len = elements. len ( ) ;
1075- elements. extend (
1076- additional_damage
1077- . into_iter ( )
1078- . map ( |rect| {
1079- rect. to_f64 ( )
1080- . to_logical (
1081- self . output . current_scale ( ) . fractional_scale ( ) ,
1082- self . output . current_transform ( ) ,
1083- & area,
1084- )
1085- . to_i32_round ( )
1086- } )
1087- . map ( DamageElement :: new)
1088- . map ( Into :: into) ,
1089- ) ;
1090-
1091- Some ( old_len)
1092- } else {
1093- None
1094- } ;
1095-
1096- let buffer = frame. buffer ( ) ;
1097- let age = damage_tracking. age_for_buffer ( & buffer) ;
1098- let res = damage_tracking. dt . damage_output ( age, & elements) ;
1099-
1100- if let Some ( old_len) = old_len {
1101- elements. truncate ( old_len) ;
1102- }
1103-
1104- if !session. draw_cursor ( ) {
1105- has_cursor_mode_none = true ;
1106- }
1107-
1108- let res = res. map ( |( a, b) | ( a. cloned ( ) , b) ) ;
1109- std:: mem:: drop ( damage_tracking) ;
1110- ( session, frame, res)
1111- } )
1112- . collect ( )
1113- } ) . unwrap_or_default ( ) ;
1050+ . then ( || take_screencopy_frames ( & self . output , & mut elements, & mut has_cursor_mode_none) )
1051+ . unwrap_or_default ( ) ;
11141052
11151053 // actual rendering
11161054 let source_output = self
@@ -1628,6 +1566,75 @@ fn get_surface_dmabuf_feedback(
16281566 }
16291567}
16301568
1569+ // TODO: Don't mutate `elements`
1570+ fn take_screencopy_frames (
1571+ output : & Output ,
1572+ elements : & mut Vec < CosmicElement < GlMultiRenderer > > ,
1573+ has_cursor_mode_none : & mut bool ,
1574+ ) -> Vec < (
1575+ ScreencopySessionRef ,
1576+ ScreencopyFrame ,
1577+ Result < ( Option < Vec < Rectangle < i32 , Physical > > > , RenderElementStates ) , OutputNoMode > ,
1578+ ) > {
1579+ output
1580+ . take_pending_frames ( )
1581+ . into_iter ( )
1582+ . map ( |( session, frame) | {
1583+ let additional_damage = frame. damage ( ) ;
1584+ let session_data = session. user_data ( ) . get :: < SessionData > ( ) . unwrap ( ) ;
1585+ let mut damage_tracking = session_data. lock ( ) . unwrap ( ) ;
1586+
1587+ let old_len = if !additional_damage. is_empty ( ) {
1588+ let area = output
1589+ . current_mode ( )
1590+ . unwrap ( )
1591+ /* TODO: Mode is Buffer..., why is this Physical in the first place */
1592+ . size
1593+ . to_logical ( 1 )
1594+ . to_buffer ( 1 , Transform :: Normal )
1595+ . to_f64 ( ) ;
1596+
1597+ let old_len = elements. len ( ) ;
1598+ elements. extend (
1599+ additional_damage
1600+ . into_iter ( )
1601+ . map ( |rect| {
1602+ rect. to_f64 ( )
1603+ . to_logical (
1604+ output. current_scale ( ) . fractional_scale ( ) ,
1605+ output. current_transform ( ) ,
1606+ & area,
1607+ )
1608+ . to_i32_round ( )
1609+ } )
1610+ . map ( DamageElement :: new)
1611+ . map ( Into :: into) ,
1612+ ) ;
1613+
1614+ Some ( old_len)
1615+ } else {
1616+ None
1617+ } ;
1618+
1619+ let buffer = frame. buffer ( ) ;
1620+ let age = damage_tracking. age_for_buffer ( & buffer) ;
1621+ let res = damage_tracking. dt . damage_output ( age, & elements) ;
1622+
1623+ if let Some ( old_len) = old_len {
1624+ elements. truncate ( old_len) ;
1625+ }
1626+
1627+ if !session. draw_cursor ( ) {
1628+ * has_cursor_mode_none = true ;
1629+ }
1630+
1631+ let res = res. map ( |( a, b) | ( a. cloned ( ) , b) ) ;
1632+ std:: mem:: drop ( damage_tracking) ;
1633+ ( session, frame, res)
1634+ } )
1635+ . collect ( )
1636+ }
1637+
16311638fn send_screencopy_result < ' a > (
16321639 renderer : & mut GlMultiRenderer < ' a > ,
16331640 output : & Output ,
0 commit comments