Commit graph

211 commits

Author SHA1 Message Date
Pierre-Clément Tosi
a6d39c5fa9 rand: Bump dependency to 0.9.2
Use rand::random() or rand::Rng::fill() in place of the now-removed
OsRng.fill_bytes(), note that the generic function now supports arrays
of any length.

Replace the deprecated rand::thread_rng() with its new name rand::rng()
or with new alternatives such as rand::random_range() where appropriate.

In fuzz/, update the impl of rand_core::RndCore which now does not
require implementing try_fill_bytes() (moved to TryRndCore) so remove it
as the function was only used by unit tests (which can also be removed).

As a result, CrosVM now follow the clean split of all client code only
depending on rand::Rnd (no imports of RndCore left) and the one provided
(FuzzRng) uses the rand_core crate, as recommended by the crate docs.

BUG=b:460349550
TEST=tools/presubmit

Change-Id: Icf0121297efcb0388e8aab17394c21457edbb119
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/7253053
Auto-Submit: Pierre-Clément Tosi <ptosi@google.com>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Pierre-Clément Tosi <ptosi@google.com>
2026-01-30 03:12:59 -08:00
Jeongik Cha
927fd7d563 Support AHardwareBuffer as RutabagaHandle
To support AHB as rutabaga resource, extend RutabagaHandle to an enum of
MesaHandle or AhbInfo. MesaHandle isn't enough to store every
information which AHB needs.

And RutabagaHandle(especially AhbInfo) is expected to be used for blob,
not fence, so make blob-related function use RutabagaHandle instead of
MesaHandle.

And restore ag/34872403 behavior about zero-copy with new
RutabagaHandle(AhbInfo)

Refer to https://github.com/magma-gpu/rutabaga_gfx/pull/37

Bug: b:453989233
Test: build && the buffer for screen is zero-copied

Change-Id: Iad490c6127f9998570e7b7dbab903b88f089373b
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/7262326
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Frederick Mayle <fmayle@google.com>
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
Commit-Queue: Jeongik Cha <jeongik@google.com>
2026-01-05 18:39:39 -08:00
Keiichi Watanabe
80699fd842 gpu_display: windows: Fix clippy::large-enum-variant
BUG=b:455879436
TEST=CQ

Change-Id: I303993025db24c0b7316912699e410c3594d5dc6
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/7169836
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Noah Gold <nkgold@google.com>
2025-11-21 13:20:00 -08:00
Keiichi Watanabe
4b0f24e4ef Automatic clippy fix for Rust 1.88
To prepare for Rust toolchain uprev, ran `tools/clippy --fix` with
Rust 1.88 for each platform.
To build with the current Rust version 1.81, some changes with unstable
features were manually reverted.

BUG=b:455879436
TEST=CQ

Change-Id: I4a91460d4fc2de5d7afbc2da04b7f7765219bb2e
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/7089630
Reviewed-by: David Stevens <stevensd@chromium.org>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
2025-11-17 10:25:21 -08:00
Frederick Mayle
74fa3115b7 crosvm: split and refactor gfxstream feature
Recently, all the "gfxstream" feature usage in the "devices" crate was
removed. This commit goes a step farther by remove the "gfxtream"
feature from the "devices" crate entirely. Instead, the top level
"gfxsteam" feature only enables gfxstream in the "rutabaga_gfx"
dependency. The Windows specific gfxstream integration in the
"gpu_display" crate is control with a separate, new "gfxstream_display"
feature.

Previously, "gfxstream" would implicitly enable "devices/gpu", but build
that enables the top level "gfxstream" without the top level "gpu"
feature was and is broken because "vm_control/gpu" and "gpu_display"
would be off. So, I've removed the implict "gfxstream => devices/gpu"
edge to avoid confusion.

Change-Id: I36d3185c85220a795a6bdc72f2e568cfcc0c67e3
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/7017494
Commit-Queue: Frederick Mayle <fmayle@google.com>
Reviewed-by: Kaiyi Li <kaiyili@google.com>
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
2025-10-08 16:23:29 -07:00
A. Cody Schuffelen
afaa8be303 Workspace deps grab bag
- anyhow
- argh
- cfg-if
- enumn
- gdbstub
- gdbstub_arch
- rand
- remain
- serde
- serde_json
- thiserror

This level of indirection makes it possible to centrally update the
versions of these dependencies.

Bug: b/418050464
Change-Id: I4223e83d33ea527ed3bab8028ad16160e3fa0364
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/6551986
Auto-Submit: Cody Schuffelen <schuffelen@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Cody Schuffelen <schuffelen@google.com>
2025-05-16 11:26:38 -07:00
A. Cody Schuffelen
f34a4abcbb Use workspace dependencies: crosvm workspace crates
Exclusions:
- perfetto
- sandbox
- rutabaga_gfx/ffi
- rutabaga_gfx/kumquat/gpu_client

This adds a level of indirection for internal crate dependencies, making
it less of a hassle to move a crate or add a new feature that is
universally enabled.

Continuation of crrev.com/c/6551983

Partially mechanically generated via
```
$ for TARGET in aarch64 aarch64_sys_reg acpi_tables android_audio anti_tamper arch argh_helpers audio_streams audio_streams_conformance_test audio_util balloon_control base base_tokio bit_field broker_ipc catapult_converter crash_report cros_async cros_fdt cros_tracing crosvm_cli crosvm_control crosvm_plugin crypto data_model devices disk e2e_tests ext2 ffmpeg fuse fuzz gpu_display hypervisor hypervisor_test_macro io_uring kernel_cmdline kernel_loader kvm kvm_sys libcras_stub linux_input_sys metrics metrics_events net_sys net_util power_monitor prebuilts proto_build_tools protos resources rutabaga_gfx serde_keyvalue snapshot swap sync system_api usb_sys usb_util vfio_sys vhost virtio_sys vm_control vm_memory vmm_vhost x86_64; do
  sed -i "s/^$TARGET =.*path[^,]\\+$/$TARGET = { workspace = true }/" $(find . -name Cargo.toml) && git restore Cargo.toml
  sed -i "s/^$TARGET =.*path[^,]\\+,/$TARGET = { workspace = true,/" $(find . -name Cargo.toml) && git restore Cargo.toml;
done
$ git restore perfetto
$ git restore sandbox
$ git restore rutabaga_gfx/ffi
$ git restore rutabaga_gfx/kumquat/gpu_client
```

Bug: b/418050464
Change-Id: I529b1a23128f19459b89e248a7c96ae2e487a441
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/6554153
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Cody Schuffelen <schuffelen@google.com>
2025-05-15 19:26:10 -07:00
A. Cody Schuffelen
83cec09245 Use workspace dependencies: libc
This allows all members of the workspace to depend on `libc` using
```
base = { workspace = true }
```
as opposed to the current collection of multiple numbered versions,
which had this distribution:
```
$ rg 'libc =' --no-filename --no-line-number | sort | uniq -c | sort -nr
      33 libc = "0.2"
      3 libc = "0.2.93"
      2 libc = "0.2.65"
      2 libc = "0.2.44"
      1 libc = { version = "0.2", features = ["extra_traits"] }
      1 libc = ">=0.2.39"
      1 libc = "0.2.153"
      1 libc = "0.2.116"
      1 libc = "*"
```

See:
- https://chromium-review.googlesource.com/c/crosvm/crosvm/+/6544746/comments/c2fb58d3_1430749b
- https://doc.rust-lang.org/cargo/reference/workspaces.html#the-dependencies-table
- https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#inheriting-a-dependency-from-a-workspace

Bug: b/418050464
Change-Id: I61438cbfe47b18621ce00791a892af9a56d91fd7
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/6551984
Reviewed-by: Frederick Mayle <fmayle@google.com>
Commit-Queue: Cody Schuffelen <schuffelen@google.com>
2025-05-15 17:53:02 -07:00
A. Cody Schuffelen
2eb1a03271 Use workspace dependencies: base
This allows all members of the workspace to depend on `base` using
```
base = { workspace = true }
```
as opposed to the current distribution:
```
$ rg 'base =' -g Cargo.toml --no-filename --no-line-number | sort | uniq -c | sort -nr
     43 base = { path = "../base" }
      4 base = { path = "../../../base" }
      2 base = { path = "../../base" }
      1 base = { path = "base" }
      1 base = { path = "../base/" }
```

See:
- https://chromium-review.googlesource.com/c/crosvm/crosvm/+/6544746/comments/c2fb58d3_1430749b
- https://doc.rust-lang.org/cargo/reference/workspaces.html#the-dependencies-table
- https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#inheriting-a-dependency-from-a-workspace

Bug: b/418050464
Change-Id: I1439fd1a5b99233a36a30a9c542abcf54ce5ac1c
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/6551983
Reviewed-by: Frederick Mayle <fmayle@google.com>
Commit-Queue: Cody Schuffelen <schuffelen@google.com>
2025-05-15 17:52:56 -07:00
Shalini Sengupta
b2455d90ba gpu_display: Rename Only: Host display to be graphics api agnostic
BUG=b:408008303
TEST=presubmit

Change-Id: I8d5d8473bd933744fecf3ad464d373e3cdf57525
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/6431586
Commit-Queue: Shalini Sengupta <shalinisen@google.com>
Reviewed-by: Idan Raiter <idanr@google.com>
2025-04-04 11:34:18 -07:00
Jason Macnak
dee7838993 gpu_display: Add copy of xdg shell protocol xml
... so that all the needed protocols for Cuttlefish's wayland
server are included in the single Crosvm project.

Bug: b/402245771
Test: n/a
Change-Id: I778e0035688b53b1066f1a72bd7e06653ac1af23
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/6379563
Commit-Queue: Jason Macnak <natsu@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2025-03-21 09:51:46 -07:00
Daniel Verkamp
84a8152003 [clippy] doc comment fix
Change-Id: Idfe04a8a6055ccf36364953794c267f405450363
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/6266471
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2025-02-24 18:53:05 -08:00
Daniel Verkamp
e39f3f44c6 [clippy] map_or() -> is_some_and() cleanups
Change-Id: If7dc2fb4cfc9ac83cfcc90f6567b2f0741b89cd5
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/6195242
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2025-02-24 18:24:21 -08:00
Dennis Kempin
d3cfaa929b Uprev pkg-config to 0.3.31
This was requested to fix some issues in mesa CI.
This is also the version that ChromeOS vendors.

BUG=b:397464790
TEST=None

Change-Id: I50313c3b24d7cb098523c7f96b0ad0fbc28f0905
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/6299710
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Auto-Submit: Dennis Kempin <denniskempin@google.com>
2025-02-24 14:09:09 -08:00
Daniel Verkamp
f20af151e2 crosvm: upgrade zerocopy to 0.8
BUG=b:372549215
TEST=tools/dev_container tools/presubmit

Change-Id: I3fcc524d1c6c41ae92c51cecb6e4d856c3d60670
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/6255229
Reviewed-by: Frederick Mayle <fmayle@google.com>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2025-02-24 11:35:51 -08:00
Daniel Verkamp
85a5d2a264 [clippy] clean up redundant lifetime annotations
Change-Id: I7885de5fcbae19ff26d74cb078a57825059b306b
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/6195239
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2025-02-11 16:14:19 -08:00
Daniel Verkamp
29b23c4e90 [clippy] use c"" for CStr literals
Change-Id: I7999bdf12ba15d6cd378ec97bf80b6b0c431be07
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/6195238
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2025-02-11 15:11:30 -08:00
Daniel Verkamp
8faa8b442c [clippy] doc comment cleanups
Fix doc comments that were detached from the items they were intended to
describe or malformed in other ways.

Change-Id: I1d53f58554a4061e69b05b712a98c2c6137354fe
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/6195236
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2025-01-27 13:07:09 -08:00
Daniel Verkamp
fbb8137c0a Windows clippy fixes for Rust 1.81
Add the minimal allow(dead_code) and feature declarations to allow the
clippy checks to pass for Windows with Rust 1.81.

BUG=b:365852007
TEST=tools/presubmit clippy_mingw64

Change-Id: I9ab776b07d8e9e14fe380d9b5ef1fa332788ff63
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/6013080
Reviewed-by: Kaiyi Li <kaiyili@google.com>
Reviewed-by: Noah Gold <nkgold@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2024-11-13 00:07:11 +00:00
Richard Zhang
adb8234a12 Revert "gpu: Add parameter for a custom cursor file"
This reverts commit 2744e5fef6.

Reason for revert: This cmd line param is no longer being used

BUG=b:364906315

Original change's description:
> gpu: Add parameter for a custom cursor file
>
> This will be used to display a custom mouse cursor for Surfaces. This CL
> won't change any functionality
>
> BUG=b:362814745
> TEST=builds and presubmits
>
> Change-Id: If4e5a41bdaa92fecf680aa09fe8e2ca154946d07
> Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5825087
> Reviewed-by: Noah Gold <nkgold@google.com>
> Commit-Queue: Richard Zhang <rizhang@google.com>
> Reviewed-by: Pujun Lun <lunpujun@google.com>

Bug: b:362814745
Change-Id: Ib975f92e96e3adb07e1fa27d1a5e6c870e76881a
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5876365
Commit-Queue: Richard Zhang <rizhang@google.com>
Reviewed-by: Noah Gold <nkgold@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2024-09-19 19:20:09 +00:00
Lepton Wu
4a3a13a15c gpu_display/wayland: Add touch event for mouse
Android guest doesn't work if there is no touch event.

BUG=b:364360076
TEST=manual - run crosvm with Android guest and mouse click works.

Change-Id: Ia678854d469e56bfa24f60721677222455ab1500
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5832986
Commit-Queue: Lepton Wu <lepton@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2024-09-13 22:38:29 +00:00
Daniel Verkamp
c2ebaa19e4 Fix bad indentation in Markdown around lists
Some doc comments were being incorrectly interpreted due to missing
indentation (for intentional line contintuations) or line breaks (for
new lines that were intended to be separate paragraphs).

Clippy warns about these as of Rust 1.80:
<https://rust-lang.github.io/rust-clippy/master/index.html#/doc_lazy_continuation>

Fix them along with some other nearby minor formatting cleanups.

TEST=tools/cargo-doc
TEST=tools/clippy # with rust-toolchain 1.80

Change-Id: Ice0b7cc3bd75d9ab08c10107a13f95ca9f87a0a3
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5758934
Auto-Submit: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Frederick Mayle <fmayle@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2024-09-10 02:05:59 +00:00
Richard Zhang
2744e5fef6 gpu: Add parameter for a custom cursor file
This will be used to display a custom mouse cursor for Surfaces. This CL
won't change any functionality

BUG=b:362814745
TEST=builds and presubmits

Change-Id: If4e5a41bdaa92fecf680aa09fe8e2ca154946d07
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5825087
Reviewed-by: Noah Gold <nkgold@google.com>
Commit-Queue: Richard Zhang <rizhang@google.com>
Reviewed-by: Pujun Lun <lunpujun@google.com>
2024-08-30 18:17:58 +00:00
Jason Macnak
35d59da127 gpu_display: android: rename ANativeWindow struct
... to reflect changes from aosp/3127803 where an internal struct
is now used to allow for updates to the underlying ANativeWindow
when the viewer app is stopped/resumed.

Bug: b/334903567
Test: presubmit
Change-Id: I96e258e864e2265a66e253af400afba9e5c50073
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5637775
Reviewed-by: Jiyong Park <jiyong@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Jason Macnak <natsu@google.com>
2024-06-18 01:51:04 +00:00
Daniel Verkamp
51cf0f429d gpu_display: don't dereference NULL if alloc fails
dwl_context_new() did not check if the allocation failed before using
the returned pointer.

BUG=None
TEST=tools/dev_container tools/presubmit

Change-Id: Ibeb0fb0b0a6e434657f09f8c24a7bd6ff7f8c21a
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5634619
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
2024-06-14 23:51:48 +00:00
Daniel Verkamp
e38524847d Windows clippy fixes for Rust 1.77
BUG=b:344974550
TEST=tools/presubmit clippy_mingw64

Change-Id: I1a4c8a59cb0618ed40ebe04129be359dfee5c5e4
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5627831
Reviewed-by: Noah Gold <nkgold@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2024-06-13 01:07:13 +00:00
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