summary refs log tree commit diff
path: root/gpu_display
diff options
context:
space:
mode:
authorNoah Gold <nkgold@google.com>2020-02-01 13:01:58 -0800
committerCommit Bot <commit-bot@chromium.org>2020-03-06 01:00:39 +0000
commitdc7f52bdb76a8f3b3cf6260bc0d861758956991e (patch)
treeabde34b5dc09609981c695f5de5772fe2661358a /gpu_display
parentd2a862b41f07d387926f0b984c56dc838003102c (diff)
downloadcrosvm-dc7f52bdb76a8f3b3cf6260bc0d861758956991e.tar
crosvm-dc7f52bdb76a8f3b3cf6260bc0d861758956991e.tar.gz
crosvm-dc7f52bdb76a8f3b3cf6260bc0d861758956991e.tar.bz2
crosvm-dc7f52bdb76a8f3b3cf6260bc0d861758956991e.tar.lz
crosvm-dc7f52bdb76a8f3b3cf6260bc0d861758956991e.tar.xz
crosvm-dc7f52bdb76a8f3b3cf6260bc0d861758956991e.tar.zst
crosvm-dc7f52bdb76a8f3b3cf6260bc0d861758956991e.zip
Use simple virtio_input_events where possible.
Previously, all input events in CrosVM were required to be linux
input_events, which have a timestamp field that is actually unused by
when we send/receive from the guest which are of type
virtio_input_event. This CL allows CrosVM to understand both types of input
events in a first class manner. It is a follow up on
https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1930405.

This CL also addresses some bugs with window driven input:
1. attach_event_device was being called before the surface was
created, so the devices were never attached.
2. The default touchpad size was not being set to the display window
size.

Additionally, it removes the unused event "filter" feature on event
sources.

Breaking change: from this point forward, CrosVM will treat input events sent
via a socket (e.g. SocketEventSource) to be virtio_input_events.

BUG=None
TEST=builds + manual

Change-Id: I7fec07c582e5a071a6f116975ba70d6e621bb483
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2034046
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Noah Gold <nkgold@google.com>
Diffstat (limited to 'gpu_display')
-rw-r--r--gpu_display/src/event_device.rs16
-rw-r--r--gpu_display/src/gpu_display_x.rs22
2 files changed, 21 insertions, 17 deletions
diff --git a/gpu_display/src/event_device.rs b/gpu_display/src/event_device.rs
index 5f1bbc7..5aae55c 100644
--- a/gpu_display/src/event_device.rs
+++ b/gpu_display/src/event_device.rs
@@ -3,14 +3,14 @@
 // found in the LICENSE file.
 
 use data_model::DataInit;
-use linux_input_sys::input_event;
+use linux_input_sys::{virtio_input_event, InputEventDecoder};
 use std::collections::VecDeque;
 use std::io::{self, Error, ErrorKind, Read, Write};
 use std::iter::ExactSizeIterator;
 use std::os::unix::io::{AsRawFd, RawFd};
 use std::os::unix::net::UnixStream;
 
-const EVENT_SIZE: usize = input_event::EVENT_SIZE;
+const EVENT_SIZE: usize = virtio_input_event::SIZE;
 const EVENT_BUFFER_LEN_MAX: usize = 16 * EVENT_SIZE;
 
 // /// Half-way build `EventDevice` with only the `event_socket` defined. Finish building the
@@ -93,7 +93,7 @@ impl EventDevice {
         self.event_buffer.is_empty()
     }
 
-    pub fn send_report<E: IntoIterator<Item = input_event>>(
+    pub fn send_report<E: IntoIterator<Item = virtio_input_event>>(
         &mut self,
         events: E,
     ) -> io::Result<bool>
@@ -111,14 +111,14 @@ impl EventDevice {
         }
 
         self.event_buffer
-            .extend(input_event::syn().as_slice().iter());
+            .extend(virtio_input_event::syn().as_slice().iter());
 
         self.flush_buffered_events()
     }
 
     /// Sends the given `event`, returning `Ok(true)` if, after this function returns, there are no
     /// buffered events remaining.
-    pub fn send_event_encoded(&mut self, event: input_event) -> io::Result<bool> {
+    pub fn send_event_encoded(&mut self, event: virtio_input_event) -> io::Result<bool> {
         if !self.flush_buffered_events()? {
             return Ok(false);
         }
@@ -137,14 +137,14 @@ impl EventDevice {
         Ok(false)
     }
 
-    pub fn recv_event_encoded(&self) -> io::Result<input_event> {
+    pub fn recv_event_encoded(&self) -> io::Result<virtio_input_event> {
         let mut event_bytes = [0u8; 24];
         (&self.event_socket).read_exact(&mut event_bytes)?;
-        match input_event::from_slice(&event_bytes) {
+        match virtio_input_event::from_slice(&event_bytes) {
             Some(event) => Ok(*event),
             None => Err(Error::new(
                 ErrorKind::InvalidInput,
-                "failed to read input_event",
+                "failed to read virtio_input_event",
             )),
         }
     }
diff --git a/gpu_display/src/gpu_display_x.rs b/gpu_display/src/gpu_display_x.rs
index c0074ca..2940f40 100644
--- a/gpu_display/src/gpu_display_x.rs
+++ b/gpu_display/src/gpu_display_x.rs
@@ -11,7 +11,7 @@
 )]
 mod xlib;
 
-use linux_input_sys::input_event;
+use linux_input_sys::virtio_input_event;
 use std::cmp::max;
 use std::collections::BTreeMap;
 use std::ffi::{c_void, CStr, CString};
@@ -333,7 +333,11 @@ impl Surface {
         }
     }
 
-    fn dispatch_to_event_devices(&mut self, events: &[input_event], device_type: EventDeviceKind) {
+    fn dispatch_to_event_devices(
+        &mut self,
+        events: &[virtio_input_event],
+        device_type: EventDeviceKind,
+    ) {
         for event_device in self.event_devices.values_mut() {
             if event_device.kind() != device_type {
                 continue;
@@ -348,7 +352,7 @@ impl Surface {
         match ev.as_enum(self.buffer_completion_type) {
             XEventEnum::KeyEvent(key) => {
                 if let Some(linux_keycode) = self.keycode_translator.translate(key.keycode) {
-                    let events = &[input_event::key(
+                    let events = &[virtio_input_event::key(
                         linux_keycode,
                         key.type_ == xlib::KeyPress as i32,
                     )];
@@ -363,9 +367,9 @@ impl Surface {
                 if button_event.button & xlib::Button1 != 0 {
                     // The touch event *must* be first per the Linux input subsystem's guidance.
                     let events = &[
-                        input_event::touch(pressed),
-                        input_event::absolute_x(max(0, button_event.x) as u32),
-                        input_event::absolute_y(max(0, button_event.y) as u32),
+                        virtio_input_event::touch(pressed),
+                        virtio_input_event::absolute_x(max(0, button_event.x) as u32),
+                        virtio_input_event::absolute_y(max(0, button_event.y) as u32),
                     ];
                     self.dispatch_to_event_devices(events, EventDeviceKind::Touchscreen);
                 }
@@ -373,9 +377,9 @@ impl Surface {
             XEventEnum::Motion(motion) => {
                 if motion.state & xlib::Button1Mask != 0 {
                     let events = &[
-                        input_event::touch(true),
-                        input_event::absolute_x(max(0, motion.x) as u32),
-                        input_event::absolute_y(max(0, motion.y) as u32),
+                        virtio_input_event::touch(true),
+                        virtio_input_event::absolute_x(max(0, motion.x) as u32),
+                        virtio_input_event::absolute_y(max(0, motion.y) as u32),
                     ];
                     self.dispatch_to_event_devices(events, EventDeviceKind::Touchscreen);
                 }