Video tiles and viewer render through their own Surface entity, so new frames repaint only the video instead of the whole app
Browse files at this commitfc0f6876c7778f89604d6c96e614e9d7453a39ecParent: 6b212ab- perf
- video tiles and viewer render through their own Surface entity, so new frames repaint only the video instead of the whole app
- harness session runs in a systemd scope
6 changed files +116 -60
- crates/client/src/gui.rs +1 -0
- crates/client/src/gui/camera_view.rs +37 -28
- crates/client/src/gui/share_view.rs +28 -31
- crates/client/src/gui/surface.rs +48 -0
- harness/down.sh +1 -0
- harness/up.sh +1 -1
crates/client/src/gui.rsmodified+1 -0
| @@ -58,6 +58,7 @@ mod share_view; | |||
| 58 | mod sidebar; | 58 | mod sidebar; |
| 59 | mod snippet; | 59 | mod snippet; |
| 60 | mod social; | 60 | mod social; |
| 61 | +mod surface; | ||
| 61 | mod voice_note; | 62 | mod voice_note; |
| 62 | mod voice_settings; | 63 | mod voice_settings; |
| 63 | mod voice_stats; | 64 | mod voice_stats; |
crates/client/src/gui/camera_view.rsmodified+37 -28
| @@ -1,11 +1,9 @@ | |||
| 1 | use common::model::Id; | 1 | use common::model::Id; |
| 2 | -use std::sync::Arc; | ||
| 3 | 2 | ||
| 4 | use common::share::{Fps, Kind, Quality, Resolution}; | 3 | use common::share::{Fps, Kind, Quality, Resolution}; |
| 5 | use gpui_kit::{ | 4 | use gpui_kit::{ |
| 6 | - AnyElement, Context, Entity, InteractiveElement, IntoElement, ObjectFit, ParentElement, | 5 | + AnyElement, AppContext as _, Context, Entity, InteractiveElement, IntoElement, ParentElement, |
| 7 | - RenderImage, StatefulInteractiveElement, Styled, StyledImage, Task, Window, assets::IconName, | 6 | + StatefulInteractiveElement, Styled, Task, Window, assets::IconName, component::Icon, div, px, |
| 8 | - component::Icon, div, img, px, | ||
| 9 | }; | 7 | }; |
| 10 | 8 | ||
| 11 | use super::{ | 9 | use super::{ |
| @@ -13,6 +11,7 @@ use super::{ | |||
| 13 | media_view::into_render_image, | 11 | media_view::into_render_image, |
| 14 | notify_error, | 12 | notify_error, |
| 15 | share_view::{self, FRAME_TICK}, | 13 | share_view::{self, FRAME_TICK}, |
| 14 | + surface::Surface, | ||
| 16 | text, | 15 | text, |
| 17 | widget::{icon_button, spawn_warn}, | 16 | widget::{icon_button, spawn_warn}, |
| 18 | }; | 17 | }; |
| @@ -38,8 +37,12 @@ pub(super) fn tile_quality(stage: Stage) -> WatchQuality { | |||
| 38 | } | 37 | } |
| 39 | 38 | ||
| 40 | pub(super) struct Tile { | 39 | pub(super) struct Tile { |
| 41 | - pub(super) generation: Option<u64>, | 40 | + pub(super) shown: bool, |
| 42 | - pub(super) frame: Option<Arc<RenderImage>>, | 41 | + pub(super) surface: Entity<Surface>, |
| 42 | +} | ||
| 43 | + | ||
| 44 | +fn tile_cover(stage: Stage) -> bool { | ||
| 45 | + stage != Stage::Grid | ||
| 43 | } | 46 | } |
| 44 | 47 | ||
| 45 | impl Yumush { | 48 | impl Yumush { |
| @@ -61,11 +64,13 @@ impl Yumush { | |||
| 61 | if self.chat.tiles.contains_key(&source) { | 64 | if self.chat.tiles.contains_key(&source) { |
| 62 | continue; | 65 | continue; |
| 63 | } | 66 | } |
| 67 | + let cover = tile_cover(self.chat.stage); | ||
| 68 | + let surface = cx.new(|_| Surface::new(cover)); | ||
| 64 | self.chat.tiles.insert( | 69 | self.chat.tiles.insert( |
| 65 | source, | 70 | source, |
| 66 | Tile { | 71 | Tile { |
| 67 | - generation: None, | 72 | + shown: false, |
| 68 | - frame: None, | 73 | + surface, |
| 69 | }, | 74 | }, |
| 70 | ); | 75 | ); |
| 71 | changed = true; | 76 | changed = true; |
| @@ -92,7 +97,11 @@ impl Yumush { | |||
| 92 | .copied() | 97 | .copied() |
| 93 | .collect(); | 98 | .collect(); |
| 94 | for source in gone { | 99 | for source in gone { |
| 95 | - if let Some(frame) = self.chat.tiles.remove(&source).and_then(|tile| tile.frame) { | 100 | + if let Some(tile) = self.chat.tiles.remove(&source) |
| 101 | + && let Some(frame) = tile | ||
| 102 | + .surface | ||
| 103 | + .update(cx, |surface, cx| surface.replace(None, cx)) | ||
| 104 | + { | ||
| 96 | cx.drop_image(frame, None); | 105 | cx.drop_image(frame, None); |
| 97 | } | 106 | } |
| 98 | if viewing != Some(source) { | 107 | if viewing != Some(source) { |
| @@ -113,12 +122,15 @@ impl Yumush { | |||
| 113 | let Some(frame) = self.network.share_frame(user_id, kind) else { | 122 | let Some(frame) = self.network.share_frame(user_id, kind) else { |
| 114 | continue; | 123 | continue; |
| 115 | }; | 124 | }; |
| 116 | - tile.generation = Some(frame.generation); | ||
| 117 | let next = into_render_image(frame); | 125 | let next = into_render_image(frame); |
| 118 | - if let Some(old) = std::mem::replace(&mut tile.frame, next) { | 126 | + changed |= !tile.shown && next.is_some(); |
| 127 | + tile.shown |= next.is_some(); | ||
| 128 | + if let Some(old) = tile | ||
| 129 | + .surface | ||
| 130 | + .update(cx, |surface, cx| surface.replace(next, cx)) | ||
| 131 | + { | ||
| 119 | cx.drop_image(old, None); | 132 | cx.drop_image(old, None); |
| 120 | } | 133 | } |
| 121 | - changed = true; | ||
| 122 | } | 134 | } |
| 123 | 135 | ||
| 124 | if changed { | 136 | if changed { |
| @@ -130,10 +142,12 @@ impl Yumush { | |||
| 130 | self.chat.stage = stage; | 142 | self.chat.stage = stage; |
| 131 | let viewing = self.viewing(); | 143 | let viewing = self.viewing(); |
| 132 | let quality = tile_quality(stage); | 144 | let quality = tile_quality(stage); |
| 133 | - for &(user_id, kind) in self.chat.tiles.keys() { | 145 | + for (&(user_id, kind), tile) in &self.chat.tiles { |
| 134 | if viewing != Some((user_id, kind)) { | 146 | if viewing != Some((user_id, kind)) { |
| 135 | self.network.set_watch_quality(user_id, kind, quality); | 147 | self.network.set_watch_quality(user_id, kind, quality); |
| 136 | } | 148 | } |
| 149 | + tile.surface | ||
| 150 | + .update(cx, |surface, cx| surface.set_cover(tile_cover(stage), cx)); | ||
| 137 | } | 151 | } |
| 138 | cx.notify(); | 152 | cx.notify(); |
| 139 | } | 153 | } |
| @@ -321,19 +335,16 @@ fn stage_tile( | |||
| 321 | let entity = entity.clone(); | 335 | let entity = entity.clone(); |
| 322 | let focused = yumush.is_watching(user_id, kind); | 336 | let focused = yumush.is_watching(user_id, kind); |
| 323 | let speaking = yumush.chat.waves.speaking.contains(&user_id); | 337 | let speaking = yumush.chat.waves.speaking.contains(&user_id); |
| 324 | - let frame = yumush | 338 | + let surface = yumush |
| 325 | .chat | 339 | .chat |
| 326 | .tiles | 340 | .tiles |
| 327 | .get(&(user_id, kind)) | 341 | .get(&(user_id, kind)) |
| 328 | - .and_then(|tile| tile.frame.clone()) | 342 | + .filter(|tile| tile.shown) |
| 329 | - .or_else(|| yumush.viewer_frame(user_id, kind)); | 343 | + .map(|tile| tile.surface.clone()); |
| 330 | let user = yumush.chat.author(user_id); | 344 | let user = yumush.chat.author(user_id); |
| 331 | let name = user.map_or("Someone", |user| user.username.as_str()); | 345 | let name = user.map_or("Someone", |user| user.username.as_str()); |
| 332 | - let content = match (frame, user) { | 346 | + let content = match (surface, user) { |
| 333 | - (Some(frame), _) => img(frame) | 347 | + (Some(surface), _) => surface.into_any_element(), |
| 334 | - .size_full() | ||
| 335 | - .object_fit(ObjectFit::Cover) | ||
| 336 | - .into_any_element(), | ||
| 337 | (None, Some(user)) => div() | 348 | (None, Some(user)) => div() |
| 338 | .size_full() | 349 | .size_full() |
| 339 | .flex() | 350 | .flex() |
| @@ -401,19 +412,17 @@ fn grid_cell( | |||
| 401 | (user_id, kind): (Id, Kind), | 412 | (user_id, kind): (Id, Kind), |
| 402 | shared: bool, | 413 | shared: bool, |
| 403 | ) -> AnyElement { | 414 | ) -> AnyElement { |
| 404 | - let frame = yumush | 415 | + let surface = yumush |
| 405 | .chat | 416 | .chat |
| 406 | .tiles | 417 | .tiles |
| 407 | .get(&(user_id, kind)) | 418 | .get(&(user_id, kind)) |
| 408 | - .and_then(|tile| tile.frame.clone()); | 419 | + .filter(|tile| tile.shown) |
| 420 | + .map(|tile| tile.surface.clone()); | ||
| 409 | let speaking = yumush.chat.waves.speaking.contains(&user_id); | 421 | let speaking = yumush.chat.waves.speaking.contains(&user_id); |
| 410 | let user = yumush.chat.author(user_id); | 422 | let user = yumush.chat.author(user_id); |
| 411 | let name = user.map_or("Someone", |user| user.username.as_str()); | 423 | let name = user.map_or("Someone", |user| user.username.as_str()); |
| 412 | - let content = match (frame, user) { | 424 | + let content = match (surface, user) { |
| 413 | - (Some(frame), _) => img(frame) | 425 | + (Some(surface), _) => surface.into_any_element(), |
| 414 | - .size_full() | ||
| 415 | - .object_fit(ObjectFit::Contain) | ||
| 416 | - .into_any_element(), | ||
| 417 | (None, Some(user)) => div() | 426 | (None, Some(user)) => div() |
| 418 | .size_full() | 427 | .size_full() |
| 419 | .flex() | 428 | .flex() |
crates/client/src/gui/share_view.rsmodified+28 -31
| @@ -11,8 +11,7 @@ const TOP_QUALITY: Quality = Quality { | |||
| 11 | }; | 11 | }; |
| 12 | use gpui_kit::{ | 12 | use gpui_kit::{ |
| 13 | Anchor, AnyElement, AppContext, Context, Div, Entity, InteractiveElement, IntoElement, | 13 | Anchor, AnyElement, AppContext, Context, Div, Entity, InteractiveElement, IntoElement, |
| 14 | - MouseButton, ObjectFit, ParentElement, RenderImage, StatefulInteractiveElement, Styled, | 14 | + MouseButton, ParentElement, StatefulInteractiveElement, Styled, Subscription, Task, Window, |
| 15 | - StyledImage, Subscription, Task, Window, | ||
| 16 | assets::IconName, | 15 | assets::IconName, |
| 17 | component::{ | 16 | component::{ |
| 18 | Icon, | 17 | Icon, |
| @@ -20,7 +19,7 @@ use gpui_kit::{ | |||
| 20 | slider::{Slider, SliderEvent, SliderState}, | 19 | slider::{Slider, SliderEvent, SliderState}, |
| 21 | switch::Switch, | 20 | switch::Switch, |
| 22 | }, | 21 | }, |
| 23 | - div, img, | 22 | + div, |
| 24 | prelude::FluentBuilder as _, | 23 | prelude::FluentBuilder as _, |
| 25 | px, | 24 | px, |
| 26 | }; | 25 | }; |
| @@ -32,6 +31,7 @@ use super::{ | |||
| 32 | media_view::into_render_image, | 31 | media_view::into_render_image, |
| 33 | notify_error, pop_in, | 32 | notify_error, pop_in, |
| 34 | settings_page::segmented, | 33 | settings_page::segmented, |
| 34 | + surface::Surface, | ||
| 35 | text, | 35 | text, |
| 36 | widget::{icon_button, spawn_warn}, | 36 | widget::{icon_button, spawn_warn}, |
| 37 | }; | 37 | }; |
| @@ -88,8 +88,8 @@ impl AudioMode { | |||
| 88 | pub(super) struct Viewer { | 88 | pub(super) struct Viewer { |
| 89 | user_id: Id, | 89 | user_id: Id, |
| 90 | kind: Kind, | 90 | kind: Kind, |
| 91 | - generation: Option<u64>, | 91 | + shown: bool, |
| 92 | - frame: Option<Arc<RenderImage>>, | 92 | + surface: Entity<Surface>, |
| 93 | pub(super) fullscreen: bool, | 93 | pub(super) fullscreen: bool, |
| 94 | volume: Entity<SliderState>, | 94 | volume: Entity<SliderState>, |
| 95 | restore: f32, | 95 | restore: f32, |
| @@ -244,14 +244,6 @@ impl Yumush { | |||
| 244 | .is_some_and(|viewer| viewer.user_id == user_id && viewer.kind == kind) | 244 | .is_some_and(|viewer| viewer.user_id == user_id && viewer.kind == kind) |
| 245 | } | 245 | } |
| 246 | 246 | ||
| 247 | - pub(super) fn viewer_frame(&self, user_id: Id, kind: Kind) -> Option<Arc<RenderImage>> { | ||
| 248 | - self.chat | ||
| 249 | - .viewer | ||
| 250 | - .as_ref() | ||
| 251 | - .filter(|viewer| viewer.user_id == user_id && viewer.kind == kind) | ||
| 252 | - .and_then(|viewer| viewer.frame.clone()) | ||
| 253 | - } | ||
| 254 | - | ||
| 255 | pub(super) fn viewing(&self) -> Option<(Id, Kind)> { | 247 | pub(super) fn viewing(&self) -> Option<(Id, Kind)> { |
| 256 | self.chat | 248 | self.chat |
| 257 | .viewer | 249 | .viewer |
| @@ -300,8 +292,8 @@ impl Yumush { | |||
| 300 | self.chat.viewer = Some(Viewer { | 292 | self.chat.viewer = Some(Viewer { |
| 301 | user_id, | 293 | user_id, |
| 302 | kind, | 294 | kind, |
| 303 | - generation: None, | 295 | + shown: false, |
| 304 | - frame: None, | 296 | + surface: cx.new(|_| Surface::new(false)), |
| 305 | fullscreen: false, | 297 | fullscreen: false, |
| 306 | volume, | 298 | volume, |
| 307 | restore: FULL_VOLUME, | 299 | restore: FULL_VOLUME, |
| @@ -339,9 +331,12 @@ impl Yumush { | |||
| 339 | let Some(viewer) = self.chat.viewer.take() else { | 331 | let Some(viewer) = self.chat.viewer.take() else { |
| 340 | return; | 332 | return; |
| 341 | }; | 333 | }; |
| 342 | - if let Some(frame) = viewer.frame { | 334 | + let surface = viewer.surface.clone(); |
| 343 | - cx.defer(move |cx| cx.drop_image(frame, None)); | 335 | + cx.defer(move |cx| { |
| 344 | - } | 336 | + if let Some(frame) = surface.update(cx, |surface, cx| surface.replace(None, cx)) { |
| 337 | + cx.drop_image(frame, None); | ||
| 338 | + } | ||
| 339 | + }); | ||
| 345 | let network = self.network.clone(); | 340 | let network = self.network.clone(); |
| 346 | if self.chat.tiles.contains_key(&(viewer.user_id, viewer.kind)) { | 341 | if self.chat.tiles.contains_key(&(viewer.user_id, viewer.kind)) { |
| 347 | network.set_watch_quality( | 342 | network.set_watch_quality( |
| @@ -367,23 +362,30 @@ impl Yumush { | |||
| 367 | let Some(frame) = self.network.share_frame(viewer.user_id, viewer.kind) else { | 362 | let Some(frame) = self.network.share_frame(viewer.user_id, viewer.kind) else { |
| 368 | return; | 363 | return; |
| 369 | }; | 364 | }; |
| 370 | - viewer.generation = Some(frame.generation); | ||
| 371 | let next = into_render_image(frame); | 365 | let next = into_render_image(frame); |
| 366 | + let appeared = !viewer.shown && next.is_some(); | ||
| 367 | + viewer.shown |= next.is_some(); | ||
| 368 | + let previous = viewer | ||
| 369 | + .surface | ||
| 370 | + .update(cx, |surface, cx| surface.replace(next.clone(), cx)); | ||
| 372 | if let Some(tile) = self.chat.tiles.get_mut(&(viewer.user_id, viewer.kind)) { | 371 | if let Some(tile) = self.chat.tiles.get_mut(&(viewer.user_id, viewer.kind)) { |
| 373 | - tile.generation = viewer.generation; | 372 | + tile.shown |= next.is_some(); |
| 374 | - if let Some(old) = std::mem::replace(&mut tile.frame, next.clone()) | 373 | + if let Some(old) = tile |
| 375 | - && !viewer | 374 | + .surface |
| 376 | - .frame | 375 | + .update(cx, |surface, cx| surface.replace(next, cx)) |
| 376 | + && !previous | ||
| 377 | .as_ref() | 377 | .as_ref() |
| 378 | .is_some_and(|current| Arc::ptr_eq(current, &old)) | 378 | .is_some_and(|current| Arc::ptr_eq(current, &old)) |
| 379 | { | 379 | { |
| 380 | cx.drop_image(old, None); | 380 | cx.drop_image(old, None); |
| 381 | } | 381 | } |
| 382 | } | 382 | } |
| 383 | - if let Some(old) = std::mem::replace(&mut viewer.frame, next) { | 383 | + if let Some(old) = previous { |
| 384 | cx.drop_image(old, None); | 384 | cx.drop_image(old, None); |
| 385 | } | 385 | } |
| 386 | - cx.notify(); | 386 | + if appeared { |
| 387 | + cx.notify(); | ||
| 388 | + } | ||
| 387 | } | 389 | } |
| 388 | 390 | ||
| 389 | pub(super) fn toggle_fullscreen(&mut self, cx: &mut Context<Self>) { | 391 | pub(super) fn toggle_fullscreen(&mut self, cx: &mut Context<Self>) { |
| @@ -516,12 +518,7 @@ impl Yumush { | |||
| 516 | let entity = entity.clone(); | 518 | let entity = entity.clone(); |
| 517 | move |_, _, cx| entity.update(cx, |yumush, cx| yumush.close_viewer(cx)) | 519 | move |_, _, cx| entity.update(cx, |yumush, cx| yumush.close_viewer(cx)) |
| 518 | }) | 520 | }) |
| 519 | - .children( | 521 | + .when(viewer.shown, |video| video.child(viewer.surface.clone())), |
| 520 | - viewer | ||
| 521 | - .frame | ||
| 522 | - .clone() | ||
| 523 | - .map(|frame| img(frame).size_full().object_fit(ObjectFit::Contain)), | ||
| 524 | - ), | ||
| 525 | ) | 522 | ) |
| 526 | .child( | 523 | .child( |
| 527 | div() | 524 | div() |
crates/client/src/gui/surface.rsadded+48 -0
| @@ -0,0 +1,48 @@ | |||
| 1 | +use std::sync::Arc; | ||
| 2 | + | ||
| 3 | +use gpui_kit::{ | ||
| 4 | + Context, IntoElement, ObjectFit, ParentElement, Render, RenderImage, Styled, StyledImage, | ||
| 5 | + Window, div, img, | ||
| 6 | +}; | ||
| 7 | + | ||
| 8 | +pub(super) struct Surface { | ||
| 9 | + frame: Option<Arc<RenderImage>>, | ||
| 10 | + cover: bool, | ||
| 11 | +} | ||
| 12 | + | ||
| 13 | +impl Surface { | ||
| 14 | + pub(super) fn new(cover: bool) -> Self { | ||
| 15 | + Self { frame: None, cover } | ||
| 16 | + } | ||
| 17 | + | ||
| 18 | + pub(super) fn replace( | ||
| 19 | + &mut self, | ||
| 20 | + frame: Option<Arc<RenderImage>>, | ||
| 21 | + cx: &mut Context<Self>, | ||
| 22 | + ) -> Option<Arc<RenderImage>> { | ||
| 23 | + cx.notify(); | ||
| 24 | + std::mem::replace(&mut self.frame, frame) | ||
| 25 | + } | ||
| 26 | + | ||
| 27 | + pub(super) fn set_cover(&mut self, cover: bool, cx: &mut Context<Self>) { | ||
| 28 | + if self.cover != cover { | ||
| 29 | + self.cover = cover; | ||
| 30 | + cx.notify(); | ||
| 31 | + } | ||
| 32 | + } | ||
| 33 | +} | ||
| 34 | + | ||
| 35 | +impl Render for Surface { | ||
| 36 | + fn render(&mut self, _: &mut Window, _: &mut Context<Self>) -> impl IntoElement { | ||
| 37 | + let fit = if self.cover { | ||
| 38 | + ObjectFit::Cover | ||
| 39 | + } else { | ||
| 40 | + ObjectFit::Contain | ||
| 41 | + }; | ||
| 42 | + div().size_full().children( | ||
| 43 | + self.frame | ||
| 44 | + .clone() | ||
| 45 | + .map(|frame| img(frame).size_full().object_fit(fit)), | ||
| 46 | + ) | ||
| 47 | + } | ||
| 48 | +} | ||
harness/down.shmodified+1 -0
| @@ -2,4 +2,5 @@ | |||
| 2 | STATE="${HARNESS_STATE:-/tmp/claude-1000/yumush-harness}" | 2 | STATE="${HARNESS_STATE:-/tmp/claude-1000/yumush-harness}" |
| 3 | [ -f "$STATE/pids" ] || exit 0 | 3 | [ -f "$STATE/pids" ] || exit 0 |
| 4 | tac "$STATE/pids" | while read -r name pid; do kill "$pid" 2>/dev/null && echo "stopped $name $pid"; done | 4 | tac "$STATE/pids" | while read -r name pid; do kill "$pid" 2>/dev/null && echo "stopped $name $pid"; done |
| 5 | +systemctl --user stop yumush-harness-session.scope 2>/dev/null | ||
| 5 | rm -f "$STATE/pids" "$STATE/env" "$STATE/env2" | 6 | rm -f "$STATE/pids" "$STATE/env" "$STATE/env2" |
harness/up.shmodified+1 -1
| @@ -10,7 +10,7 @@ printf '[server_config]\ndatabase_path = "yumush.db"\nserver_address = "127.0.0. | |||
| 10 | cp "$HERE/portals.conf" "$STATE/xdg/xdg-desktop-portal/niri-portals.conf" | 10 | cp "$HERE/portals.conf" "$STATE/xdg/xdg-desktop-portal/niri-portals.conf" |
| 11 | (cd "$STATE/server" && YUMUSH_CONFIG_DIR="$STATE/server" exec "$ROOT/target/${PROFILE:-harness}/server" >"$STATE/server.log" 2>&1) & | 11 | (cd "$STATE/server" && YUMUSH_CONFIG_DIR="$STATE/server" exec "$ROOT/target/${PROFILE:-harness}/server" >"$STATE/server.log" 2>&1) & |
| 12 | echo "server $!" >> "$STATE/pids" | 12 | echo "server $!" >> "$STATE/pids" |
| 13 | -dbus-run-session -- "$HERE/session.sh" "$STATE" >"$STATE/session.log" 2>&1 & | 13 | +systemd-run --user --scope --collect -q -u yumush-harness-session dbus-run-session -- "$HERE/session.sh" "$STATE" >"$STATE/session.log" 2>&1 & |
| 14 | echo "session $!" >> "$STATE/pids" | 14 | echo "session $!" >> "$STATE/pids" |
| 15 | for _ in $(seq 100); do [ -s "$STATE/env" ] && break; sleep 0.2; done | 15 | for _ in $(seq 100); do [ -s "$STATE/env" ] && break; sleep 0.2; done |
| 16 | cat "$STATE/env" | 16 | cat "$STATE/env" |