crosvm/gpu_display/examples/simple_open.rs
Robert Tarasov bb95fc4512 gpu_display/wayland: Added keyboard and pointing devices
Added preliminary version of keyboard and pointing device routine
for wayland implementation. The pointing input is wired as a multi
touch device. Due to the fact that wayland client is callback based,
all the necessary incoming events are serialized and stashed in the
temp circular buffer and then processed afterwards from the main event
loop.

Known issues:

1. Mouse input can't be properly wired inside the guest as a mouse
   device without pointer locking, but this is not what we want. The
   approach emulates it as a multitouch device, but, of course, it
   implies limitations in functionality.  Limitations include cursor
   in the VM that doesn't move in unison with the host cursor.

2. I kept the mouse cursor surface since it's not decided yet which
   approach for handling pointing input device will be used (see #1).

   Removing the mouse surface in the guest would remove the lagging
   guest cursor.  The alternatives to the multi-touch device are:

   "- Relative mice (e.g. a typical PC mouse). These are relative
      devices, meaning they send deltas from the current cursor
      position.  Some apps like games rely on these events.

    - Touchscreens (multitouch, single touch). These are absolute
      devices, and are much easier to implement seamless guest/host
      input for.

    - Touchpads (these are absolute devices). I'm not sure these are
      really compelling for any use case." -nkgold@

3. This code is for POC purpose only, so there are still lot of minor
   issues and negligence in it.

Looking forward for your comments and proposals.

BUG=b:177939148
TEST=crosvm $ARGS \
      --display-window-keyboard \
      --display-window-mouse \
      --gpu=3d,glx=false,egl=true \
      --wayland-sock=/run/user/1000/wayland-0 \
      $OTHER_ARGS

Change-Id: If4a9b73b8da4e0cc52fa619bbd6e5588ccdb7874
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2688439
Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2021-06-15 03:14:07 +00:00

28 lines
802 B
Rust

use gpu_display::{GpuDisplay, SurfaceType};
fn main() {
let mut disp = GpuDisplay::open_x(None::<&str>).unwrap();
let surface_id = disp
.create_surface(None, 1280, 1024, SurfaceType::Scanout)
.unwrap();
let mem = disp.framebuffer(surface_id).unwrap();
for y in 0..1024 {
let mut row = [0u32; 1280];
for (x, item) in row.iter_mut().enumerate() {
let b = ((x as f32 / 1280.0) * 256.0) as u32;
let g = ((y as f32 / 1024.0) * 256.0) as u32;
*item = b | (g << 8);
}
mem.as_volatile_slice()
.offset(1280 * 4 * y)
.unwrap()
.copy_from(&row);
}
disp.flip(surface_id);
while !disp.close_requested(surface_id) {
disp.dispatch_events().unwrap();
}
}