2022-09-13 17:47:21 +00:00
|
|
|
// Copyright 2022 The ChromiumOS Authors
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2022-07-27 18:11:32 +00:00
|
|
|
use gpu_display::GpuDisplay;
|
|
|
|
use gpu_display::SurfaceType;
|
2019-04-16 22:09:20 +00:00
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let mut disp = GpuDisplay::open_x(None::<&str>).unwrap();
|
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-02-02 06:14:16 +00:00
|
|
|
let surface_id = disp
|
|
|
|
.create_surface(None, 1280, 1024, SurfaceType::Scanout)
|
|
|
|
.unwrap();
|
2019-04-16 22:09:20 +00:00
|
|
|
|
|
|
|
let mem = disp.framebuffer(surface_id).unwrap();
|
|
|
|
for y in 0..1024 {
|
|
|
|
let mut row = [0u32; 1280];
|
2021-01-11 17:40:34 +00:00
|
|
|
for (x, item) in row.iter_mut().enumerate() {
|
2019-04-16 22:09:20 +00:00
|
|
|
let b = ((x as f32 / 1280.0) * 256.0) as u32;
|
|
|
|
let g = ((y as f32 / 1024.0) * 256.0) as u32;
|
2021-01-11 17:40:34 +00:00
|
|
|
*item = b | (g << 8);
|
2019-04-16 22:09:20 +00:00
|
|
|
}
|
|
|
|
mem.as_volatile_slice()
|
2020-05-15 11:06:58 +00:00
|
|
|
.offset(1280 * 4 * y)
|
2019-04-16 22:09:20 +00:00
|
|
|
.unwrap()
|
|
|
|
.copy_from(&row);
|
|
|
|
}
|
|
|
|
disp.flip(surface_id);
|
|
|
|
|
|
|
|
while !disp.close_requested(surface_id) {
|
2021-04-26 23:40:48 +00:00
|
|
|
disp.dispatch_events().unwrap();
|
2019-04-16 22:09:20 +00:00
|
|
|
}
|
|
|
|
}
|