Skip to content

Commit

Permalink
Fix subsurfaces not receiving position updates
Browse files Browse the repository at this point in the history
This fixes an issue where subsurfaces would always stay at their
original location regardless of `wl_subsurface::set_position` calls.

This was caused by the subsurface's texture being loaded from cache with
its original location. To ensure the subsurface position is correct, the
texture's location is now always updated after loading it from the
cache.

Closes #145.
  • Loading branch information
chrisduerr committed Feb 10, 2024
1 parent 794eb6f commit c3cd0e1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/drawing.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! Drawing utilities.
use std::cell::Cell;
use std::ops::Deref;
use std::rc::Rc;

Expand Down Expand Up @@ -54,7 +55,7 @@ const GESTURE_HANDLE_BLOCKED_RGBA: [u8; 3] = [117, 42, 42];
pub struct Texture {
opaque_regions: Vec<Rectangle<i32, Logical>>,
tracker: DamageSnapshot<i32, Logical>,
location: Point<i32, Logical>,
location: Cell<Point<i32, Logical>>,
src_rect: Rectangle<f64, Logical>,
dst_size: Size<i32, Logical>,
buffer_size: Size<i32, Logical>,
Expand Down Expand Up @@ -118,10 +119,10 @@ impl Texture {
Self {
opaque_regions,
window_scale,
location,
texture,
tracker: buffer.damage.tracker.snapshot(),
buffer_size: buffer.buffer_size,
location: Cell::new(location),
buffer: buffer.buffer.clone(),
transform: buffer.transform,
scale: buffer.scale as f64,
Expand All @@ -146,6 +147,11 @@ impl Texture {
Texture::new(texture, logical_size, scale, opaque)
}

/// Move texture to a different location.
pub fn set_location(&self, location: Point<i32, Logical>) {
self.location.replace(location);
}

/// Target size after rendering.
pub fn size(&self) -> Size<i32, Logical> {
self.dst_size
Expand Down Expand Up @@ -185,7 +191,8 @@ impl Element for RenderTexture {

fn geometry(&self, scale: Scale<f64>) -> Rectangle<i32, Physical> {
let scale = self.window_scale.map_or(scale.x, |window_scale| window_scale.scale(scale.x));
Rectangle::from_loc_and_size(self.location, self.dst_size).to_physical_precise_round(scale)
Rectangle::from_loc_and_size(self.location.get(), self.dst_size)
.to_physical_precise_round(scale)
}

fn damage_since(
Expand Down
4 changes: 4 additions & 0 deletions src/windows/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,11 @@ impl<S: Surface + 'static> Window<S> {

// Skip surface if buffer was already imported.
if let Some(texture) = &data.texture {
// Ensure texture's location is up to date.
texture.set_location(location);

self.texture_cache.push(texture.clone(), location);

return TraversalAction::DoChildren(location);
}

Expand Down

0 comments on commit c3cd0e1

Please sign in to comment.