Commit graph

185 commits

Author SHA1 Message Date
Daniel Verkamp
2f47ba1930 gpu_display: allow dead code in dwl bindings
BUG=b:344974550
TEST=tools/clippy

Change-Id: Ic20d3d01f7d8a60fefbc8abdcc8b9cb34fd7bb8b
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5617615
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2024-06-10 23:00:00 +00:00
Jeongik Cha
fa3f917c34 Support cursor in android display
1. Handle cursor scanout as well
2. Add set_android_surface_position to handle cursor move event

Bug: 327559087
Test: check cursor in vm
Change-Id: I5429cb88a0f7983df015e05745070bf71f7c15ad
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5569432
Commit-Queue: Frederick Mayle <fmayle@google.com>
Reviewed-by: Jiyong Park <jiyong@google.com>
Reviewed-by: Frederick Mayle <fmayle@google.com>
2024-05-28 17:45:38 +00:00
Daniel Verkamp
52b8e42869 Cargo.toml: avoid "*" versions for external crates
Ensure that every Cargo.toml dependency on a third-party crates.io crate
specifies at least a major version, or a minor version for 0.x crates,
to ensure that if a new major version is published, it cannot cause API
breaks.

The versions are selected to match the ones already in Cargo.lock, so
this should have no functional change, but it will help prevent new "*"
versions from being introduced via copy-and-paste.

For rationale, see the Cargo FAQ:
<https://doc.rust-lang.org/cargo/faq.html#can-libraries-use--as-a-version-for-their-dependencies>

`minijail`, `audio_streams`, and `cras` are left as "*" for now, since
they have unusual situations (imported from a submodule and/or replaced
at build time with ebuild magic).

BUG=None
TEST=tools/dev_container tools/presubmit
TEST=verify Cargo.lock is unchanged

Change-Id: Ifa18199f812f01d2d10bfb4146b3353c1a76527c
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5555656
Reviewed-by: Frederick Mayle <fmayle@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2024-05-22 01:01:42 +00:00
Noah Gold
ad0f44e61c gpu_display: establish crate OWNERS
GFX work often requires review from domain expers, but until now we have
not formally enumerated this list.

BUG=b:328338772
TEST=n/a

Change-Id: If71c03270df675d43049c95491f91a5229ca05b5
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5437463
Reviewed-by: Jason Macnak <natsu@google.com>
Reviewed-by: Ryan Neph <ryanneph@google.com>
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Noah Gold <nkgold@google.com>
2024-04-19 17:55:42 +00:00
Pujun Lun
c06f757ae8 gpu_display: add max_num_displays to GpuParameters.
This parameter specifies the max number of concurrent crosvm
displays we support. By default, it will be VIRTIO_GPU_MAX_SCANOUTS
(i.e. 16). Different products may choose different upper bounds,
but it should never exceed VIRTIO_GPU_MAX_SCANOUTS. For Windows,
this defines the max number of concurrent windows.

BUG=b:332910955

Change-Id: I9127133e444063f791bc01715ef9a383fc8b9ee6
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5426762
Commit-Queue: Pujun Lun <lunpujun@google.com>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Kaiyi Li <kaiyili@google.com>
Reviewed-by: Jason Macnak <natsu@google.com>
2024-04-11 20:30:05 +00:00
Jiyong Park
b64bf7843d Refactor android display backend
This change refactors the C interface between crosvm and the android
display backend which is designed to be implemented outside of crosvm.

The below is a few important changes:

* The new interface allows crosvm to draw directly on Android surface.
  Previously, we allocated a framebuffer in crosvm, let crosvm draw on
it, and passed it to the Android-side backend where the framebuffer
is copied to Android surface using CPU.

* Respect stride set by Android. When a buffer is created on the Android
  side, the stride is usually set to a multiple of 16 for maximum
performance. This change reports that stride back to crosvm so that it
can respect the stride. Previously, we used a stride value that is equal
to the screen width which may not be multiple of 16.

* The error callback function pointer is passed to the Android side only
  when the context is created. The Android side is expected to keep the
pointer along with the context and use it when something goes wrong.

Bug: 331900473
TEST=./tools/presubmit

Change-Id: I3e5b05407c41413ea55bba37cb7f34f504799734
(cherry picked from commit 4e5494276d9736fa697bcd3e62207f8708b1c0a4)
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5446565
Commit-Queue: Frederick Mayle <fmayle@google.com>
Reviewed-by: Frederick Mayle <fmayle@google.com>
2024-04-11 16:27:22 +00:00
Pujun Lun
509fd7babf gpu_display: add DisplayParameters to create_surface() interface.
"width" and "height" are removed from the interface since they can
be derived from DisplayParameters.

Windows implementation was assuming only one display, so
DisplayParameters was passed in with GpuDisplay::open_winapi() and
assumed not to change. To support multi-display, it needs to be
passed in every time we create a new surface. This should make no
functional change to other platforms.

BUG=b:332910955

Change-Id: I32767a37c8a1f50716190e13aa94c9c159db3d04
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5041413
Reviewed-by: Jason Macnak <natsu@google.com>
Commit-Queue: Pujun Lun <lunpujun@google.com>
Reviewed-by: Kaiyi Li <kaiyili@google.com>
Reviewed-by: Frederick Mayle <fmayle@google.com>
2024-04-04 22:20:57 +00:00
Daniel Verkamp
d608436b2e gpu_display: X: set window name to "crosvm"
Previously, the X display window did not have a title. Set it to
"crosvm" to match the Wayland display and make it easier to find when
switching windows.

BUG=None
TEST=tools/examples/example_desktop

Change-Id: I4fc2b2bfdb6e4dd008b3a1f274a6c0b4eb6d020d
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5402949
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: David Stevens <stevensd@chromium.org>
2024-03-29 01:01:16 +00:00
Jiyong Park
33b33a43ff gpu_display: additional cleanup to the Android display backend
This change addresses comments left on
https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5390926

TEST=./tools/presubmit
Bug: 325929966

Change-Id: Ia05c7dbfd6adde43f33fe776d4993f012491a7e2
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5395371
Reviewed-by: Frederick Mayle <fmayle@google.com>
Commit-Queue: Jiyong Park <jiyong@google.com>
2024-03-27 00:30:00 +00:00
Jason Macnak
8eab91e544 gpu_display: add Android display backend
This change introduces two features:
* android_display and
* android_display_stub

The android_display feature adds a new GPU display backend for Android
which emits the display output to an Android surface. The surface is not
created by the backend itself, but by an external entity (ex: Android
app) by creating a SurfaceView. This allows us to display a VM anywhere
the app is shown.

The owner of the surface (the app) is expected to share the surface with
the new backend by calling an AIDL method that the backend will
implement. The AIDL service implementing the method will be registered
to the service manager using the name set via the cmdline option
--android-display-service NAME.

This CL however doesn't include the implementation of the AIDL service
because upstream crosvm doesn't support building an AIDL service and
Android-specific libraries like libnativewindow. Instead, the
android_display_stub feature provides a no-op stub for the AIDL service,
so that we can at least build the rest of the new display backend.

TEST=cargo build
TEST=cargo build -F android_display,android_display_stub
TEST=./tools/run_tests
TEST=./tools/run_tests -F android_display,android_display_stub
TEST=./tools/presubmit
Bug: 325929966

Change-Id: I24f672beaa4a28253f150306a64df34f4962361e
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5390926
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Jiyong Park <jiyong@google.com>
2024-03-26 00:08:54 +00:00
Daniel Verkamp
742791deef tree-wide: replace data_model::zerocopy_from_*()
Use zerocopy functions directly instead. This is a step toward replacing
our data_model crate with standard crates.io functionality where
possible.

BUG=b:312312646
TEST=tools/dev_container tools/presubmit

Change-Id: I9717edce6fe2b4ca53ad9043db61de2e9bc55b78
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5046345
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Noah Gold <nkgold@google.com>
2024-03-13 18:03:24 +00:00
Kaiyi Li
e264c7ccbf gpu_display: integrate vulkan display with windowing
Add a new vulkan interface to GpuDisplay and GpuDisplaySurface, and
implement the new interface for GpuDisplayWin using VulkanDisplay.

Test: ran emulatorNexusHwcTest
Change-Id: I241af4edaae7c5d5d99f6b27fb2a7448b9a1b321
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5214575
Reviewed-by: Noah Gold <nkgold@google.com>
Commit-Queue: Colin Downs-Razouk <colindr@google.com>
2024-03-08 17:11:01 +00:00
Noah Gold
229ecae3cf gpu_display: improve event device error logging.
The event device type was missing, which makes it a hassle to determine
the type (it can be done from the index). Our path for reading events
also threw away the underlying error, which makes debugging pretty
tricky. This CL fixes both issues.

BUG=b:324486429
TEST=builds

Change-Id: Ie42c065fc6b35c9195db136b94e8831d82c8a23e
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5351358
Reviewed-by: Pujun Lun <lunpujun@google.com>
Commit-Queue: Noah Gold <nkgold@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2024-03-08 01:06:31 +00:00
Daniel Verkamp
a6f3ec0094 gpu_display: replace lazy_static with static Mutex init
The lazy_static crate should not be used in crosvm (it has been replaced
with once_cell in https://crrev.com/c/3707624), and sync::Mutex can be
statically initialized now (https://crrev.com/c/5318701), so the lazy
initialization is not even necessary.

Additionally, the once_cell dependency was unnecessarily reintroduced;
it is unused, so it can be removed from Cargo.toml (again).

Change-Id: I263d856e72dbf531ab25595c60f9e88aba9e321f
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5342656
Reviewed-by: Kaiyi Li <kaiyili@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2024-03-05 18:45:13 +00:00
Kaiyi Li
33f1afda24 gpu_display: wndproc for vulkan
Windows procedure implementation for the vulkan display.

Test: ran vulkaninfo
Change-Id: Iab7b501092155cdb7eacf6e71c2da4ec6c2253f9
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5214574
Reviewed-by: Noah Gold <nkgold@google.com>
Commit-Queue: Colin Downs-Razouk <colindr@google.com>
Reviewed-by: Pujun Lun <lunpujun@google.com>
2024-03-04 23:14:40 +00:00
Kaiyi Li
35e605fc78 gpu_display: vulkan post resource
Implementation of PostResource and the vulkan calls that blit the image
to the swapchain image.

Test: build
Change-Id: Ib76043ee30e1ef4ff5f1da77bbb2d2548e7af681
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5214573
Reviewed-by: Noah Gold <nkgold@google.com>
Reviewed-by: Mateusz Przybylski <mprzybyl@google.com>
2024-03-04 23:14:40 +00:00
Kaiyi Li
121a1c0108 gpu_display: vulkan post worker
The post worker is responsible for actually posting images to the
display when `post` is called. The image supplied to `post` is copied to
the swapchain image (via a blit operation) and then the swapchain image
is queued for presentation to the display.

Test: build
Change-Id: Ief7bb4aed9b33d3fab48696193d6a3bb438dbf24
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5214572
Reviewed-by: Mateusz Przybylski <mprzybyl@google.com>
Reviewed-by: Noah Gold <nkgold@google.com>
2024-03-04 23:14:40 +00:00
Kaiyi Li
750925baed gpu_display: vulkan external image
ExternalImage type manages importing, acquiring, and releasing an image
generated externally in vulkan.

Test: build
Change-Id: Ia95a5ee983d9e9dfb4fa51c5c2917b81fdd89400
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5214571
Reviewed-by: Noah Gold <nkgold@google.com>
Reviewed-by: Mateusz Przybylski <mprzybyl@google.com>
2024-03-04 23:14:40 +00:00
Kaiyi Li
90a6797a65 gpu_display: vulkan display top level impl
Implement the top level types of vulkan display, including
VulkanDisplay and VulkanState and VulkanStateBuilder.

Test: build
Change-Id: I8bf7113d14219500f7a1388bc8ebb73f89bc8d09
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5214570
Reviewed-by: Mateusz Przybylski <mprzybyl@google.com>
Reviewed-by: Noah Gold <nkgold@google.com>
2024-03-04 23:14:40 +00:00
Kaiyi Li
7fbd71e5bf gpu_display: new vulkan display
This is a new display path for creating vulkan-based surfaces.

Test: build
Change-Id: I28e3b455ed265b615c4f8fe7c6ac28e2da81ec2e
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5214569
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Ryan Neph <ryanneph@google.com>
2024-03-04 23:14:40 +00:00
Pujun Lun
f1bcfe1475 everywhere: enable setting mouse mode thru CLI.
Example command:
crosvm gpu set-mouse-mode <control_socket_path> \
    --display-id=0 \
    --mouse-mode=relative

This enables the Windows implementation to toggle mouse capture
mode (touchscreen <-> relative). It will have no effect if the
specified "display-id" doesn't point to an existing guest display
associated with an in-use host display.

BUG=b:324087519
TEST=presubmit

Change-Id: I9e513eb692d4b9cba66eb1e629ab8f7018645059
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5319794
Reviewed-by: Noah Gold <nkgold@google.com>
Commit-Queue: Pujun Lun <lunpujun@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2024-03-04 22:17:23 +00:00
Pujun Lun
a2e4721e3a gpu_display_win: upstream mouse input handling code.
MouseInputManager supports touchscreen mode and relative mode (i.e.
captured mouse cursor). The relative mode uses Windows raw input
events. Since only one window in an application can receive those
events, we register the raw input device with the MessageOnlyWindow
and reroute the raw input events to the current foreground GUI
window.

BUG=b:254702853
TEST=presubmit

Change-Id: I18e4d62777bdf0e7d39267426d1301fa6211af31
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5318692
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Noah Gold <nkgold@google.com>
Commit-Queue: Pujun Lun <lunpujun@google.com>
2024-02-29 19:29:19 +00:00
Pujun Lun
399190f441 gpu_display_win: support per-scanout input devices.
We will create per-scanout touchscreen devices to support multi-window.
DisplayEventDispatcher is updated to manage multiple device ids for one
kind of event devices, and GuiWindow needs to be passed around in
KeyboardInputManager and MouseInputManager to provide the scanout id
when we need to dispatch events to the guest.

BUG=b:254702853
TEST=presubmit

Change-Id: Ie40d2e67bab3a564b17c41555f4ba235993b0e19
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5318691
Reviewed-by: Richard Zhang <rizhang@google.com>
Commit-Queue: Pujun Lun <lunpujun@google.com>
2024-02-27 19:54:31 +00:00
Daniel Verkamp
24dfa67e5e Remove once_cell from a few more static Mutex inits
Missed these since they used the fully qualified sync::Mutex instead of
just Mutex.

Change-Id: I20748fa4a1271ce3b89e576e9c0925ab894104bc
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5321445
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Frederick Mayle <fmayle@google.com>
2024-02-27 00:57:35 +00:00
Pujun Lun
77709742c9 gpu_display_win: upstream multi-display impl for Windows.
1. Introduced two structs for window management:
   a. WindowResources: a host window that isn't currently used (no
      Surface associated).
   b. WindowMessageProcessor: a host window associated with a guest
      display/Surface.
2. Enabled WindowMessageDispatcher to manage multiple
   WindowResources and WindowMessageProcessors.
3. Enabled adding/removing multiple Surfaces. See the CreateSurface
   and ReleaseSurface commands in DisplaySendToWndProc.

BUG=b:254702853
TEST=presubmit

Change-Id: I5940a597e00f58dfb99b43149d72a7e36f196f7e
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5286460
Commit-Queue: Pujun Lun <lunpujun@google.com>
Reviewed-by: Noah Gold <nkgold@google.com>
2024-02-22 00:18:56 +00:00
A. Cody Schuffelen
ecc0206af8 Upgrade rust to 1.73.0
There don't appear to be any new clippy warnings, and this is the
version of Rust that Android is now using: b/303252546. Work for the
next version is tracked in b/310977762.

This doesn't have any particular features I'm looking for (async traits
only come in 1.75.0). I'm not particularly attached to this change. If
it's easy to upgrade the container though, we could ensure no new clippy
warnings appear.

Android rust versions appear here:
https://cs.android.com/android/platform/superproject/main/+/main:prebuilts/rust/linux-x86/

Also not sure what the ChromeOS release schedule is.

Release docs: https://releases.rs/docs/1.73.0/

Test: tools/dev_container --clean bash -c "rustc --version && tools/presubmit clippy"
Change-Id: I2d3010c3032053709f0c0beb7dcbe2b80d782415
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5201659
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
2024-02-20 19:11:51 +00:00
Kaiyi Li
c28067d1d9 Reformat comments
Test: presubmit
Change-Id: I39c261d9985989873b698213c5d8b653fc13757b
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5299850
Auto-Submit: Kaiyi Li <kaiyili@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2024-02-15 23:30:13 +00:00
Pujun Lun
224cc67e89 gpu_display: add scanout id to create_surface() interface.
GpuDisplay::create_surface() and GpuDisplay::set_scanout_id() were
called back-to-back. To support multi-display on Windows (where
host windows are associated with scanouts), it makes more sense to
pass in the scanout id when creating the surface so that we can
immediately use it for routing input events. This shouldn't affect
other platforms.

BUG=b:254702853
TEST=presubmit

Change-Id: I0c4081107706420492465e755f9440f3c4363b78
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5273974
Reviewed-by: Kaiyi Li <kaiyili@google.com>
Reviewed-by: Jason Macnak <natsu@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Pujun Lun <lunpujun@google.com>
2024-02-12 19:49:48 +00:00
Vikram Auradkar
2768f223ee clippy: enforce safety block comments
BUG=b:316174930
TEST=none

Change-Id: I5c7811b2c548155aa003e4b71a54bbc16e2f2588
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5120567
Commit-Queue: Vikram Auradkar <auradkar@google.com>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2023-12-14 18:21:54 +00:00
Pujun Lun
165acb2e03 gpu_display: add Surface implementation for Windows.
This is where we process host display events, such as window size
change and mouse input events. MouseInputManager etc are currently
no-op. Their implementation will be added later.

BUG=b:306024335

Change-Id: Ib67fd64894bd8c9f47cf2ee3cdf2a20901defe3b
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5053935
Reviewed-by: Richard Zhang <rizhang@google.com>
Commit-Queue: Pujun Lun <lunpujun@google.com>
Reviewed-by: Noah Gold <nkgold@google.com>
2023-11-28 20:04:06 +00:00
Daniel Verkamp
fcc28f5573 data_model: move IoBuf and VolatileMemory to base
IoBuf is defined in a platform-specific way (it is either iovec on unix
or WSABUF for windows), so it fits into the mission statement of the
base crate, which is meant to be *the* platform abstraction layer in
crosvm.

IoBufMut and VolatileMemory/VolatileSlice are defined in terms of IoBuf,
so they are also moved into base for consistency. Every crate that uses
these types already depended on base, so no extra dependencies are
added, and a few can be removed.

BUG=b:312312646
TEST=tools/dev_container tools/presubmit

Change-Id: I4dddc55d46906dfc55b88e8e6a967d7e1c1922dd
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5046605
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2023-11-27 21:42:49 +00:00
Pujun Lun
1a8f413d7d gpu_display: add KeyboardInputManager to handle key events on Windows.
BUG=b:306407787

Change-Id: I28286cb6f999da56020fba2e79d4ad9a1875c8eb
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5026248
Reviewed-by: Noah Gold <nkgold@google.com>
Commit-Queue: Pujun Lun <lunpujun@google.com>
2023-11-17 01:34:38 +00:00
Pujun Lun
f4c1624319 gpu_display: nuke HandleWindowMessage trait.
BUG=b:306024335

Change-Id: Ic6f5f5ea7a65bed2e08967bd0a33a4e54a59fe55
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5008063
Reviewed-by: Vikram Auradkar <auradkar@google.com>
Reviewed-by: Kaiyi Li <kaiyili@google.com>
Commit-Queue: Pujun Lun <lunpujun@google.com>
2023-11-16 20:13:23 +00:00
Pujun Lun
57ae9b5996 linux_input_sys: add a "repeat" option to key events.
It will be used in the upcoming Windows implementation. The
behavior should remain unchanged for other platforms.

BUG=b:306407787

Change-Id: I7f925055e2d3d9e03f64096cbf590c7ac897a00c
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5028148
Reviewed-by: Noah Gold <nkgold@google.com>
Commit-Queue: Pujun Lun <lunpujun@google.com>
2023-11-16 16:39:02 +00:00
Pujun Lun
8bb5b07a9d gpu_display: turn window messages into enums.
The WindowMessage enum covers general window messages that multiple
modules may want to process, such as window manager, input manager,
etc.

After this change, it isn't necessary to have the HandleWindowMessage
trait anymore. It will be nuked in the follow-up CL.

BUG=b:244492422

Change-Id: Ib4d8dfd29ff7d7f55aa2d1f759b091aee32c2cdf
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5002765
Commit-Queue: Pujun Lun <lunpujun@google.com>
Reviewed-by: Kaiyi Li <kaiyili@google.com>
Reviewed-by: Vikram Auradkar <auradkar@google.com>
2023-11-08 20:53:35 +00:00
Daniel Verkamp
870a4e036a gpu_display: only build Wayland code on Linux
Refactor the build.rs platform detection to explicitly select the
Wayland support code when building for Linux (instead of skipping it
only for Windows).

BUG=None
TEST=tools/dev_container tools/presubmit
TEST=cargo build -p gpu_display --target=aarch64-apple-darwin

Change-Id: I9437acdc2e2439d0da094887a5a8f520f3279399
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5005295
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Cody Schuffelen <schuffelen@google.com>
2023-11-03 20:20:08 +00:00
Kaiyi Li
58b25b1fdb Allow gpu_display examples to be compiled without the kiwi feature
Test: cargo build -p gpu_display --example simple
Change-Id: Idec97f362ffbd1173344ca4968d15aeeda73fcff
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4863127
Commit-Queue: Colin Downs-Razouk <colindr@google.com>
Reviewed-by: Noah Gold <nkgold@google.com>
2023-10-24 23:19:03 +00:00
Kaiyi Li
b116d80b1d crosvm: windows: initialize input event config in one place
Move the initialization of input event config to a separate function
to prepare removing the input event config from the GPU config.

Test: flat run emulator and see input functioning
Bug: 291656763
Change-Id: Ic733949a122b0e51fad2794e154511a5f3fb1085
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4804702
Reviewed-by: Noah Gold <nkgold@google.com>
Commit-Queue: Colin Downs-Razouk <colindr@google.com>
2023-10-24 23:18:38 +00:00
Noah Gold
eec8ecef18 gpu_display: fix Cargo feature selection.
The features we request in gpu_display weren't complete with respect to
the code we were using from dependent crates. This has been fine because
we usually build crosvm as a monolith, but when testing we need the
individual crates to be complete.

Bug: 295082178
Test: nextest -p gpu_display --features=kiwi -E \
'test(can_create_2_window_proc_threads)'

Change-Id: Ib1f6a23149f08124eab3cad56cf9350a570d1c9a
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4805406
Commit-Queue: Colin Downs-Razouk <colindr@google.com>
Reviewed-by: Vikram Auradkar <auradkar@google.com>
2023-10-24 23:18:38 +00:00
Kaiyi Li
4c2892b38e gpu_display: gpu_display_win: use builder to create the wndproc thread
Bug: b/291656763
Test: flat run emulator
Change-Id: I5b5597e0ae74556f7d9e3856a265b2ebc49fc77b
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4805405
Reviewed-by: Noah Gold <nkgold@google.com>
Commit-Queue: Colin Downs-Razouk <colindr@google.com>
2023-10-24 23:18:38 +00:00
Kaiyi Li
c530a0185c gpu_display: allow creating multiple window structs
We weren't able to create multiple GuiWindow's and MessageOnlyWindow's
because they will try to register the window class with the same name
every time a window is created.

Move the logic to register window class to window_procedure_thread, and
also register different window classes for different message handlers
because they don't share the same WNDPROC.

Test: cargo nextest run --workspace --features all-msvc64_product_debug gpu_display
Test: flat run emulator
Change-Id: Icaf3596731c7bcdedccfa6d9929bee0d0f63cfb5
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4804700
Commit-Queue: Colin Downs-Razouk <colindr@google.com>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2023-10-23 16:37:02 +00:00
A. Cody Schuffelen
4748c54b95 Rename "unix" to "linux" in code and docs
$ for DIR in $(find . -name "unix"); do mv $DIR $(echo $DIR | sed "s/unix/linux/"); done
$ for FILE in $(find . -name "unix.rs"); do mv $FILE $(echo $FILE | sed "s/unix/linux/"); done
$ find . -type f -not -path '*/\.git/*' | xargs -I {} sed -E -i "s/mod unix/mod linux/g" {}
$ find . -type f -not -path '*/\.git/*' -not -path '*/third_party/perfetto/*' | xargs -I {} sed -E -i "s/([^o][^s])::unix/\1::linux/g" {}
$ find . -type f -not -path '*/\.git/*' | xargs -I {} sed -E -i "s/use unix::/use linux::/g" {}
$ find . -type f -not -path '*/\.git/*' -not -path '*/third_party/perfetto/*' | xargs -I {} sed -E -i "s/sys::unix/sys::linux/g" {}
$ find . -type f -not -path '*/\.git/*' | xargs -I {} sed -E -i "s/use unix as platform/use linux as platform/g" {}

Test: ./tools/dev_container ./tools/presubmit
Bug: b/298269162
Change-Id: I2c8acb14d77a5588dab4eae124f4a9afbb9025f5
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4909060
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Vikram Auradkar <auradkar@google.com>
Commit-Queue: Cody Schuffelen <schuffelen@google.com>
Reviewed-by: Frederick Mayle <fmayle@google.com>
2023-10-11 01:15:07 +00:00
A. Cody Schuffelen
97dff044f8 Replace #[cfg(unix)] with #[cfg(any(target_os = "android", target_os = "linux"))]
Updates are made to source and documentation.

This more accurately represents the currently supported platforms of
Android/Linux and Windows, without unexpectedly including other
unix-like operating systems.

Command to reproduce:
$ find . -type f -not -path '*/\.git/*' | xargs -I {} sed -i 's/cfg(unix)/cfg(any(target_os = "android", target_os = "linux"))/g' {}
$ cargo fmt

md files manually updated to fix line lengths.

Renaming `unix` modules to `linux` will be done in a later CL.

Test: ./tools/dev_container ./tools/presubmit
Bug: b/298269162
Change-Id: I42c1bf0abf80b9a0df25551613910293217c7295
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4909059
Commit-Queue: Cody Schuffelen <schuffelen@google.com>
Reviewed-by: Frederick Mayle <fmayle@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Noah Gold <nkgold@google.com>
2023-10-11 00:43:29 +00:00
Zihan Chen
cbba480ebe crosvm: Uprev zerocopy to 0.7.x
zerocopy 0.7.x has finally released as a stable version, uprev it
to allow some remaining structs to be derivable.

TEST=CQ

BUG=b:300969352
FIXED=b:300969352

Change-Id: I90f0dfb09494f875fef1cd11bfcbd48030846092
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4878761
Auto-Submit: Zihan Chen <zihanchen@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Zihan Chen <zihanchen@google.com>
2023-10-10 17:34:32 +00:00
Pujun Lun
081bca1c13 Rename struct Window to GuiWindow.
This is to differentiate it from another struct, MessageOnlyWindow.
The only change besides renaming is that the function
get_current_module_handle() is moved out of the impl block of GuiWindow
since it is used by both types of windows.

Bug: 279810202
Test: Ran GPG
Change-Id: Ica607d8e2e8f2e0f0525dd86765c345252042963
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4804698
Reviewed-by: Noah Gold <nkgold@google.com>
Commit-Queue: Kaiyi Li <kaiyili@google.com>
2023-09-25 12:33:21 +00:00
Pujun Lun
27fde06214 Replace thread messages with a message router window.
Thread messages will be dropped when the modal loop is running, meaning
if the user is resizing/moving the window or invoking the window menu,
we will lose input device events or the command to destroy the window.

This CL uses a message-only window as a message router, whose HWND will
be exposed to other threads. Instead of being posted to the WndProc
thread itself, all those thread messages are now posted to this message
router window, so that they will still be dispatched to our wnd_proc
function while the modal loop is running. Other alternatives have been
discussed in b/279810202.

The lifetime of this new window is slightly shorter than that of the
WndProc thread. When we are about to terminate KiwiVM, we will destroy
the GUI window first, and then the message router window. The WndProc
thread will exit after those are done.

Now we have two types of windows in window.rs: MessageOnlyWindow and
Window. The latter one will be renamed to GuiWindow in the follow-up CL.
They implement the common trait, BasicWindow, to provide the basic
functionalities such as exposing the HWND, destorying the window, etc.

Bug: 279810202
Test: Ran GPG and tested basic windowing functionality
Change-Id: I7bff35a9f435d2a4250dcf3aa93b39e0ca64faff
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4804802
Reviewed-by: Noah Gold <nkgold@google.com>
2023-09-25 12:33:21 +00:00
Daniel Verkamp
03dd1feab7 Cargo.toml: depend on zerocopy 0.6 explicitly
Previously all of the zerocopy imports just used "*", but there are
API changes in zerocopy 0.7, so ensure we get a compatible version by
depending on 0.6 everywhere.

This is a no-op since Cargo.lock already specifies a 0.6.x version, but
it will prevent accidentally upgrading to 0.7.x without updating to the
new API.

BUG=b:301283548
TEST=cargo build

Change-Id: Ifd702d982a09b5083dddd666dc6f3052cba22214
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4878502
Reviewed-by: Zihan Chen <zihanchen@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2023-09-20 21:28:58 +00:00
Pujun Lun
7eac9a86c7 Add AOT for GPU display.
This will record the thread/window messages flowing through our message
pump. It could help debug window not responding issues like b/264846691.

TODO(b/252870196):
Add freeze detection and trigger simulated crash reports.

Bug: 264846691
Test: Triggered crash reports and checked the generated traces
Change-Id: If7a9fc4da40ed5b56cb7eff40e2680eccf0c6150
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4804800
Reviewed-by: Vikram Auradkar <auradkar@google.com>
Commit-Queue: Vikram Auradkar <auradkar@google.com>
Reviewed-by: Noah Gold <nkgold@google.com>
Auto-Submit: Kaiyi Li <kaiyili@google.com>
2023-09-20 17:17:11 +00:00
Frederick Mayle
34846b558b devices: virtio: gpu: snapshot support for 2d mode
General strategy:

  * We only snapshot the state relevant to the virtio-gpu 2d mode
    protocol (i.e. scanouts, resources, fences).
  * The GpuDisplay is recreated from scratch, we don't want to snapshot
    the state of a Wayland socket (for example).
  * No state about pending virtio requests needs to be snapshotted
    because the 2d backend completes them synchronously.

BUG=b:266514608

Change-Id: I9cfec93b1e4c9bcbb55dca09a19f6fc146db2b54
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4777342
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
2023-09-14 00:06:37 +00:00
Frederick Mayle
1a4a15fadc devices: virtio: gpu: reclaim EventDevices on suspend
We need to pass back the `EventDevice`s, otherwise virtio-input devices
will break on suspend.

I've moved the `import_event_device` calls up the stack to reduce the
amount of plumbing required.

BUG=b:266514608

Change-Id: I3decbb472bf66709cb2d3fe766d4bc3701a6a080
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4802512
Reviewed-by: Noah Gold <nkgold@google.com>
Reviewed-by: Elie Kheirallah <khei@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2023-09-14 00:06:37 +00:00