summary refs log tree commit diff
path: root/src/linux.rs
diff options
context:
space:
mode:
authorKaiyi Li <kaiyili@google.com>2020-02-06 17:53:11 -0800
committerCommit Bot <commit-bot@chromium.org>2020-02-12 19:01:12 +0000
commitbccb4ebb852f74de44034ca4ebac9242bfb71d22 (patch)
tree529d2d22689e869877ef2d6742a1975c40d3df5c /src/linux.rs
parentc13648b444a77ea850adc7da25859696a4b20578 (diff)
downloadcrosvm-bccb4ebb852f74de44034ca4ebac9242bfb71d22.tar
crosvm-bccb4ebb852f74de44034ca4ebac9242bfb71d22.tar.gz
crosvm-bccb4ebb852f74de44034ca4ebac9242bfb71d22.tar.bz2
crosvm-bccb4ebb852f74de44034ca4ebac9242bfb71d22.tar.lz
crosvm-bccb4ebb852f74de44034ca4ebac9242bfb71d22.tar.xz
crosvm-bccb4ebb852f74de44034ca4ebac9242bfb71d22.tar.zst
crosvm-bccb4ebb852f74de44034ca4ebac9242bfb71d22.zip
Use display size as the default size for single touch
When the user specifies the display size through the gpu argument but
not specifies the size of the single touch device, the display size
will be used as the size of these touch devices.

Use default() to initialize the GpuParameters. Allow initialize the
GpuParameters dynamically in the future.

Change-Id: I9fa04f8ff479732370514fbaeb062d737adba319
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2043072
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Kaiyi Li <kaiyili@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Diffstat (limited to 'src/linux.rs')
-rw-r--r--src/linux.rs41
1 files changed, 28 insertions, 13 deletions
diff --git a/src/linux.rs b/src/linux.rs
index 84edf5c..ab6c64c 100644
--- a/src/linux.rs
+++ b/src/linux.rs
@@ -62,7 +62,10 @@ use vm_control::{
     VmRunMode,
 };
 
-use crate::{Config, DiskOption, Executable, SharedDir, SharedDirKind, TouchDeviceOption};
+use crate::{
+    Config, DiskOption, Executable, SharedDir, SharedDirKind, TouchDeviceOption,
+    DEFAULT_TOUCH_DEVICE_HEIGHT, DEFAULT_TOUCH_DEVICE_WIDTH,
+};
 
 use arch::{self, LinuxArch, RunnableLinuxVm, VirtioDeviceStub, VmComponents, VmImage};
 
@@ -473,13 +476,16 @@ fn create_tpm_device(cfg: &Config) -> DeviceResult {
 }
 
 fn create_single_touch_device(cfg: &Config, single_touch_spec: &TouchDeviceOption) -> DeviceResult {
-    let socket = single_touch_spec.path.into_unix_stream().map_err(|e| {
-        error!("failed configuring virtio single touch: {:?}", e);
-        e
-    })?;
-
-    let dev = virtio::new_single_touch(socket, single_touch_spec.width, single_touch_spec.height)
-        .map_err(Error::InputDeviceNew)?;
+    let socket = single_touch_spec
+        .get_path()
+        .into_unix_stream()
+        .map_err(|e| {
+            error!("failed configuring virtio single touch: {:?}", e);
+            e
+        })?;
+
+    let (width, height) = single_touch_spec.get_size();
+    let dev = virtio::new_single_touch(socket, width, height).map_err(Error::InputDeviceNew)?;
     Ok(VirtioDeviceStub {
         dev: Box::new(dev),
         jail: simple_jail(&cfg, "input_device")?,
@@ -487,13 +493,13 @@ fn create_single_touch_device(cfg: &Config, single_touch_spec: &TouchDeviceOptio
 }
 
 fn create_trackpad_device(cfg: &Config, trackpad_spec: &TouchDeviceOption) -> DeviceResult {
-    let socket = trackpad_spec.path.into_unix_stream().map_err(|e| {
+    let socket = trackpad_spec.get_path().into_unix_stream().map_err(|e| {
         error!("failed configuring virtio trackpad: {}", e);
         e
     })?;
 
-    let dev = virtio::new_trackpad(socket, trackpad_spec.width, trackpad_spec.height)
-        .map_err(Error::InputDeviceNew)?;
+    let (width, height) = trackpad_spec.get_size();
+    let dev = virtio::new_trackpad(socket, width, height).map_err(Error::InputDeviceNew)?;
 
     Ok(VirtioDeviceStub {
         dev: Box::new(dev),
@@ -1030,8 +1036,17 @@ fn create_virtio_devices(
                 // TODO(nkgold): the width/height here should match the display's height/width. When
                 // those settings are available as CLI options, we should use the CLI options here
                 // as well.
-                let dev = virtio::new_single_touch(virtio_dev_socket, 1280, 1024)
-                    .map_err(Error::InputDeviceNew)?;
+                let (single_touch_width, single_touch_height) = cfg
+                    .virtio_single_touch
+                    .as_ref()
+                    .map(|single_touch_spec| single_touch_spec.get_size())
+                    .unwrap_or((DEFAULT_TOUCH_DEVICE_WIDTH, DEFAULT_TOUCH_DEVICE_HEIGHT));
+                let dev = virtio::new_single_touch(
+                    virtio_dev_socket,
+                    single_touch_width,
+                    single_touch_height,
+                )
+                .map_err(Error::InputDeviceNew)?;
                 devs.push(VirtioDeviceStub {
                     dev: Box::new(dev),
                     jail: simple_jail(&cfg, "input_device")?,