Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 28 additions & 50 deletions src/backend/kms/surface/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1072,7 +1072,7 @@ impl SurfaceThreadState {
let frames = self
.mirroring
.is_none()
.then(|| take_screencopy_frames(&self.output, &mut elements, &mut has_cursor_mode_none))
.then(|| take_screencopy_frames(&self.output, &elements, &mut has_cursor_mode_none))
.unwrap_or_default();

// actual rendering
Expand Down Expand Up @@ -1345,13 +1345,6 @@ impl SurfaceThreadState {
(&session, frame, res),
now.into(),
) {
session
.user_data()
.get::<SessionData>()
.unwrap()
.lock()
.unwrap()
.reset();
tracing::warn!(?err, "Failed to screencopy");
}
}
Expand Down Expand Up @@ -1380,14 +1373,7 @@ impl SurfaceThreadState {
}
}
Err(err) => {
for (session, frame, _) in frames {
session
.user_data()
.get::<SessionData>()
.unwrap()
.lock()
.unwrap()
.reset();
for (_session, frame, _) in frames {
frame.fail(FailureReason::Unknown);
}
return Err(err).with_context(|| "Failed to submit result for display");
Expand Down Expand Up @@ -1591,10 +1577,9 @@ fn get_surface_dmabuf_feedback(
}
}

// TODO: Don't mutate `elements`
fn take_screencopy_frames(
output: &Output,
elements: &mut Vec<CosmicElement<GlMultiRenderer>>,
elements: &[CosmicElement<GlMultiRenderer>],
has_cursor_mode_none: &mut bool,
) -> Vec<(
ScreencopySessionRef,
Expand All @@ -1609,7 +1594,15 @@ fn take_screencopy_frames(
let session_data = session.user_data().get::<SessionData>().unwrap();
let mut damage_tracking = session_data.lock().unwrap();

let old_len = if !additional_damage.is_empty() {
let buffer = frame.buffer();
let age = if matches!(buffer_type(&buffer), Some(BufferType::Shm)) {
// TODO re-use offscreen buffer to damage track screencopy to shm
0
} else {
1
};

if !additional_damage.is_empty() {
let area = output
.current_mode()
.unwrap()
Expand All @@ -1619,41 +1612,26 @@ fn take_screencopy_frames(
.to_buffer(1, Transform::Normal)
.to_f64();

let old_len = elements.len();
elements.extend(
additional_damage
.into_iter()
.map(|rect| {
rect.to_f64()
.to_logical(
output.current_scale().fractional_scale(),
output.current_transform(),
&area,
)
.to_i32_round()
})
.map(DamageElement::new)
.map(Into::into),
);

Some(old_len)
} else {
None
let additional_damage_elements: Vec<_> = additional_damage
.into_iter()
.map(|rect| {
rect.to_f64()
.to_logical(
output.current_scale().fractional_scale(),
output.current_transform(),
&area,
)
.to_i32_round()
})
.map(DamageElement::new)
.collect();
let _ = damage_tracking
.dt
.damage_output(age, &additional_damage_elements);
};

let buffer = frame.buffer();
let age = if matches!(buffer_type(&frame.buffer()), Some(BufferType::Shm)) {
// TODO re-use offscreen buffer to damage track screencopy to shm
0
} else {
damage_tracking.age_for_buffer(&buffer)
};
let res = damage_tracking.dt.damage_output(age, &elements);

if let Some(old_len) = old_len {
elements.truncate(old_len);
}

if !session.draw_cursor() {
*has_cursor_mode_none = true;
}
Expand Down
26 changes: 0 additions & 26 deletions src/backend/render/element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ where
Cursor(RescaleRenderElement<RelocateRenderElement<CursorRenderElement<R>>>),
Dnd(WaylandSurfaceRenderElement<R>),
MoveGrab(RescaleRenderElement<CosmicMappedRenderElement<R>>),
AdditionalDamage(DamageElement),
Postprocess(
CropRenderElement<RelocateRenderElement<RescaleRenderElement<TextureShaderElement>>>,
),
Expand All @@ -53,7 +52,6 @@ where
CosmicElement::Cursor(elem) => elem.id(),
CosmicElement::Dnd(elem) => elem.id(),
CosmicElement::MoveGrab(elem) => elem.id(),
CosmicElement::AdditionalDamage(elem) => elem.id(),
CosmicElement::Postprocess(elem) => elem.id(),
CosmicElement::Zoom(elem) => elem.id(),
#[cfg(feature = "debug")]
Expand All @@ -67,7 +65,6 @@ where
CosmicElement::Cursor(elem) => elem.current_commit(),
CosmicElement::Dnd(elem) => elem.current_commit(),
CosmicElement::MoveGrab(elem) => elem.current_commit(),
CosmicElement::AdditionalDamage(elem) => elem.current_commit(),
CosmicElement::Postprocess(elem) => elem.current_commit(),
CosmicElement::Zoom(elem) => elem.current_commit(),
#[cfg(feature = "debug")]
Expand All @@ -81,7 +78,6 @@ where
CosmicElement::Cursor(elem) => elem.src(),
CosmicElement::Dnd(elem) => elem.src(),
CosmicElement::MoveGrab(elem) => elem.src(),
CosmicElement::AdditionalDamage(elem) => elem.src(),
CosmicElement::Postprocess(elem) => elem.src(),
CosmicElement::Zoom(elem) => elem.src(),
#[cfg(feature = "debug")]
Expand All @@ -95,7 +91,6 @@ where
CosmicElement::Cursor(elem) => elem.geometry(scale),
CosmicElement::Dnd(elem) => elem.geometry(scale),
CosmicElement::MoveGrab(elem) => elem.geometry(scale),
CosmicElement::AdditionalDamage(elem) => elem.geometry(scale),
CosmicElement::Postprocess(elem) => elem.geometry(scale),
CosmicElement::Zoom(elem) => elem.geometry(scale),
#[cfg(feature = "debug")]
Expand All @@ -109,7 +104,6 @@ where
CosmicElement::Cursor(elem) => elem.location(scale),
CosmicElement::Dnd(elem) => elem.location(scale),
CosmicElement::MoveGrab(elem) => elem.location(scale),
CosmicElement::AdditionalDamage(elem) => elem.location(scale),
CosmicElement::Postprocess(elem) => elem.location(scale),
CosmicElement::Zoom(elem) => elem.location(scale),
#[cfg(feature = "debug")]
Expand All @@ -123,7 +117,6 @@ where
CosmicElement::Cursor(elem) => elem.transform(),
CosmicElement::Dnd(elem) => elem.transform(),
CosmicElement::MoveGrab(elem) => elem.transform(),
CosmicElement::AdditionalDamage(elem) => elem.transform(),
CosmicElement::Postprocess(elem) => elem.transform(),
CosmicElement::Zoom(elem) => elem.transform(),
#[cfg(feature = "debug")]
Expand All @@ -141,7 +134,6 @@ where
CosmicElement::Cursor(elem) => elem.damage_since(scale, commit),
CosmicElement::Dnd(elem) => elem.damage_since(scale, commit),
CosmicElement::MoveGrab(elem) => elem.damage_since(scale, commit),
CosmicElement::AdditionalDamage(elem) => elem.damage_since(scale, commit),
CosmicElement::Postprocess(elem) => elem.damage_since(scale, commit),
CosmicElement::Zoom(elem) => elem.damage_since(scale, commit),
#[cfg(feature = "debug")]
Expand All @@ -155,7 +147,6 @@ where
CosmicElement::Cursor(elem) => elem.opaque_regions(scale),
CosmicElement::Dnd(elem) => elem.opaque_regions(scale),
CosmicElement::MoveGrab(elem) => elem.opaque_regions(scale),
CosmicElement::AdditionalDamage(elem) => elem.opaque_regions(scale),
CosmicElement::Postprocess(elem) => elem.opaque_regions(scale),
CosmicElement::Zoom(elem) => elem.opaque_regions(scale),
#[cfg(feature = "debug")]
Expand All @@ -169,7 +160,6 @@ where
CosmicElement::Cursor(elem) => elem.alpha(),
CosmicElement::Dnd(elem) => elem.alpha(),
CosmicElement::MoveGrab(elem) => elem.alpha(),
CosmicElement::AdditionalDamage(elem) => elem.alpha(),
CosmicElement::Postprocess(elem) => elem.alpha(),
CosmicElement::Zoom(elem) => elem.alpha(),
#[cfg(feature = "debug")]
Expand All @@ -183,7 +173,6 @@ where
CosmicElement::Cursor(elem) => elem.kind(),
CosmicElement::Dnd(elem) => elem.kind(),
CosmicElement::MoveGrab(elem) => elem.kind(),
CosmicElement::AdditionalDamage(elem) => elem.kind(),
CosmicElement::Postprocess(elem) => elem.kind(),
CosmicElement::Zoom(elem) => elem.kind(),
#[cfg(feature = "debug")]
Expand Down Expand Up @@ -212,9 +201,6 @@ where
CosmicElement::Cursor(elem) => elem.draw(frame, src, dst, damage, opaque_regions),
CosmicElement::Dnd(elem) => elem.draw(frame, src, dst, damage, opaque_regions),
CosmicElement::MoveGrab(elem) => elem.draw(frame, src, dst, damage, opaque_regions),
CosmicElement::AdditionalDamage(elem) => {
RenderElement::<R>::draw(elem, frame, src, dst, damage, opaque_regions)
}
CosmicElement::Postprocess(elem) => {
let glow_frame = R::glow_frame_mut(frame);
RenderElement::<GlowRenderer>::draw(
Expand Down Expand Up @@ -250,7 +236,6 @@ where
CosmicElement::Cursor(elem) => elem.underlying_storage(renderer),
CosmicElement::Dnd(elem) => elem.underlying_storage(renderer),
CosmicElement::MoveGrab(elem) => elem.underlying_storage(renderer),
CosmicElement::AdditionalDamage(elem) => elem.underlying_storage(renderer),
CosmicElement::Postprocess(elem) => {
let glow_renderer = renderer.glow_renderer_mut();
elem.underlying_storage(glow_renderer)
Expand Down Expand Up @@ -281,17 +266,6 @@ where
}
}

impl<R> From<DamageElement> for CosmicElement<R>
where
R: Renderer + ImportAll + ImportMem + AsGlowRenderer,
R::TextureId: 'static,
CosmicMappedRenderElement<R>: RenderElement<R>,
{
fn from(elem: DamageElement) -> Self {
Self::AdditionalDamage(elem)
}
}

impl<R> From<MemoryRenderBufferRenderElement<R>> for CosmicElement<R>
where
R: Renderer + ImportAll + ImportMem + AsGlowRenderer,
Expand Down
44 changes: 21 additions & 23 deletions src/backend/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1353,21 +1353,20 @@ where
)?;

let old_len = elements.len();
elements.extend(
additional_damage
.into_iter()
.map(|rect| {
rect.to_f64()
.to_logical(
output.current_scale().fractional_scale(),
output.current_transform(),
&area,
)
.to_i32_round()
})
.map(DamageElement::new)
.map(Into::into),
);
let additional_damage_elements: Vec<_> = additional_damage
.into_iter()
.map(|rect| {
rect.to_f64()
.to_logical(
output.current_scale().fractional_scale(),
output.current_transform(),
&area,
)
.to_i32_round()
})
.map(DamageElement::new)
.collect();
dt.damage_output(age, &additional_damage_elements)?;

Some(old_len)
} else {
Expand Down Expand Up @@ -1473,7 +1472,7 @@ where
CosmicMappedRenderElement<R>: RenderElement<R>,
WorkspaceRenderElement<R>: RenderElement<R>,
{
let mut elements: Vec<CosmicElement<R>> = workspace_elements(
let elements: Vec<CosmicElement<R>> = workspace_elements(
gpu,
renderer,
shell,
Expand All @@ -1488,13 +1487,12 @@ where

if let Some(additional_damage) = additional_damage {
let output_geo = output.geometry().to_local(&output).as_logical();
elements.extend(
additional_damage
.into_iter()
.filter_map(|rect| rect.intersection(output_geo))
.map(DamageElement::new)
.map(Into::<CosmicElement<R>>::into),
);
let additional_damage_elements: Vec<_> = additional_damage
.into_iter()
.filter_map(|rect| rect.intersection(output_geo))
.map(DamageElement::new)
.collect();
damage_tracker.damage_output(age, &additional_damage_elements)?;
}

let res = damage_tracker.render_output(
Expand Down
Loading
Loading