Skip to content

Multi-session GPU rendering — switch SharedFrame per active tab #19

@CREVIOS

Description

@CREVIOS

Problem

When multiple RDP sessions are open (tabs), the GpuRenderer only holds a reference to ONE SharedFrame. Switching tabs doesn't change which session's frames are rendered by the GPU.

Current architecture

```
SessionActor 1 → SharedFrame A (global, managed state)
SessionActor 2 → SharedFrame A (same one!) ← WRONG
GpuRenderer → SharedFrame A
```

Both sessions write to the same SharedFrame, causing frame corruption (interleaved pixels from different desktops).

Correct architecture

```
SessionActor 1 → SharedFrame A (per-session)
SessionActor 2 → SharedFrame B (per-session)
GpuRenderer → active_frame (switches on tab change)

Tab switch: user clicks "Session 2" tab
→ frontend sends IPC: set_active_session(session_2_id)
→ GpuRenderer.set_active_frame(SharedFrame B)
→ next render() uses SharedFrame B
```

Implementation

Step 1: Per-session SharedFrame

In `SessionManager::create_session()`, create a NEW SharedFrame for each session instead of using the global one:

```rust
let shared_frame = SharedFrame::new(width, height);
// Store in the session handle
```

Step 2: SharedFrame registry

Add a `HashMap<String, Arc>` to managed state, keyed by session ID:

```rust
pub struct FrameRegistry {
frames: Mutex<HashMap<String, Arc>>,
active: Mutex<Option<Arc>>,
}
```

Step 3: Active frame switching

Add a Tauri command `set_active_session(session_id)` that:

  1. Looks up the session's SharedFrame in the registry
  2. Swaps it into `GpuRenderer`'s `shared_frame` field
  3. Forces a full repaint

Step 4: Frontend integration

In `SessionView.tsx`, when switching tabs, call `set_active_session(newSessionId)`.

Files to modify

  • `src-tauri/src/renderer/shared_frame.rs` — no changes needed
  • `src-tauri/src/renderer/gpu.rs` — make `shared_frame` swappable (`Arc` or `Mutex<Arc>`)
  • `src-tauri/src/rdp/session.rs` — per-session SharedFrame creation
  • `src-tauri/src/lib.rs` — manage `FrameRegistry` instead of single SharedFrame
  • `src-tauri/src/commands/session.rs` — add `set_active_session` command
  • `src/components/session/SessionView.tsx` — call `set_active_session` on tab switch

Priority: P1 — multi-session is broken without this

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestgpuGPU rendering pipeline

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions