Commit graph

157 commits

Author SHA1 Message Date
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
Pujun Lun
a1c2173bbf Override host monitor DPI for remote desktop sessions.
We found that when we are using a remote desktop, the monitor DPI
reported by GetDpiForMonitor() may not make sense. For example, on
Chrome Remote Desktop we always get 25 DPI, while the standard DPI is
96. Because of that, the calculated guest DPI is also too low, and all
the UI elements in the guest appear very small.

This might be a flaw in Windows Remote Desktop Protocol. As a
workaround, we would just assume the monitor DPI is the standard value
if we find that KiwiVM is running in a remote session.

Bug: 273810154
Test: Ran B* in CRD and checked the Overlay UI size
Change-Id: Ie335fe8df394b19733bbee8f70931c29b836f3d3
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4804796
Reviewed-by: Vikram Auradkar <auradkar@google.com>
Commit-Queue: Kaiyi Li <kaiyili@google.com>
2023-09-08 21:29:23 +00:00
Kaiyi Li
2ae3bc2d19 gpu_display: enable keycode_converter module on Windows
The downstream also relies on the keycode_converter module to translate
the input events.

Change-Id: I840226246dbf5112837b76ea7ad5677f75a4a5ca
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4804692
Commit-Queue: Kaiyi Li <kaiyili@google.com>
Reviewed-by: Vikram Auradkar <auradkar@google.com>
2023-09-08 21:29:23 +00:00
lunpujun
907dc87a2a Bring window to foreground on ShowWindowRequest if already shown.
This is used if the start game button is pressed when a game is already
running. The user may hit that button if they have trouble in finding
the game window since it may be behind other windows or minimized. The
BSS will send an empty ShowWindowRequest and we will bring the window to
the foreground. If the window has been minimized, we will need to
restore it first.

Bug: 260061297
Test: Ran GPG and tested this feature
Change-Id: Id7c7253b2d82cddc9670804486d3bfed92379a12
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4804691
Reviewed-by: Vikram Auradkar <auradkar@google.com>
2023-09-08 21:29:23 +00:00
Noah Gold
bb311f2fb0 gpu_display: send mouse position w/ Kiwi scroll events.
Bug: 262705211
Test: ran emulator & verified scroll position is sent to the guest &
that the bug no longer repros.

Change-Id: Iaa8e748aeaa8faea361e7d6deb94fe152824c850
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4804795
Reviewed-by: Vikram Auradkar <auradkar@google.com>
2023-09-08 21:29:23 +00:00
Kaiyi Li
688d41b1f2 gpu_display: remove unused Windows code
Change-Id: I0f5a090a6934a1b03d0866252478091963591d1f
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4804794
Commit-Queue: Kaiyi Li <kaiyili@google.com>
Reviewed-by: Vikram Auradkar <auradkar@google.com>
2023-08-30 18:14:49 +00:00
Kaiyi Li
503f54b283 gpu_display: correct how Metrics is imported
Change-Id: I3c6e8c7b36940bf04cba1f4a0ef1e2fd469d8ee8
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4804686
Reviewed-by: Vikram Auradkar <auradkar@google.com>
2023-08-30 18:14:49 +00:00
Pujun Lun
be5eb18d11 gpu_display: log elapsed time for updating host viewport size.
`update_virtual_display_projection()` calls into gfxstream, which may
take a long time to finish if we have a hard time acquiring a certain
lock in gfxstream (b/244201551). We will log the elapsed time and create
a B2T2 rule to catch hanging events.

Bug: 244201551
Test: Ran GPG and checked the log
Change-Id: I4055abc77bcbeeea465e6a79353d0e57fbb63acc
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4802517
Reviewed-by: Vikram Auradkar <auradkar@google.com>
2023-08-30 18:14:49 +00:00
Noah Gold
a1e0d46704 gpu_display: guest -> host input event dispatch.
virtio-input devices can receive events from the guest. Primarily this
is used controlling the numlock, capslock, and scroll lock lights. For
KiwiMouse, we'll be using LED 0 (the numlock LED) to allow the guest to
signal whether the mouse should be captured.

We need the capture information to be communicated from the virtio-input
device to SurfaceInput, but some of the plumbing is missing. Currently
we only support host -> guest data, and not the other way around (at
least in gpu_display_win). This CL adds a route for data to flow from
virtio-input to the gpu_display_win Surface via the
the GPU device worker & GpuDisplay::handle_event_device.

Bug: 239991275
Test: ran emulator & verified events were arriving in
on_handle_event_device as expected.

Change-Id: I7ab8e5ec51f7aa655b2cb44fe38483103388b53d
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4719210
Reviewed-by: Vikram Auradkar <auradkar@google.com>
2023-08-30 18:14:49 +00:00
Pujun Lun
6003534ca3 gpu_display: refactor gpu_main_display_tube.
After go/playcl/83699, the WndProc thread is the only thread that
accesses this tube, so we could change its type from Arc<Mutex<Tube>> to
Rc<Tube>, so that we no longer need to worry about deadlocking.

This tube was a field of struct DisplayParameters. That struct is used
for CLI arg parsing, however, we don't get this tube from CLI so the
code looks awkward. Besides, DisplayParameters specifies params for each
individual window, but we will likely only have one tube and share it
among multiple windows when we support multi-windowing. So, we can
remove it from DisplayParameters, and WindowProcedureThread will
distribute the clones of the tube to surfaces.

Bug: 257486521
Test: Ran GPG

Change-Id: Ic7adeb4a41c89d79e40820ad4d50e8d85c4e385c
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4804685
Reviewed-by: Noah Gold <nkgold@google.com>
Commit-Queue: Kaiyi Li <kaiyili@google.com>
2023-08-29 21:59:39 +00:00
lunpujun
d56dbed44d gpu_display: deprecate MessageRelayThread.
We used to spawn a separate thread to poll gpu_main_display_tube for
messages from the external supervisor, and then wrap those messages in
thread messages (WM_USER_HANDLE_SERVICE_MESSAGE_INTERNAL) that are
posted to the WndProc thread. Now that we have replaced GetMessageW() with
MsgWaitForMultipleObjects(), we can poll that tube and the message queue
at the same time in the WndProc thread, and then route service messages
to WindowMessageDispatcher::process_service_message().

The newly added MsgWaitContext looks similar to EventContext but it is
much simpler, since we don't need to worry about removing handles,
setting timeout, etc. It may get more complex when we start to add more
handles to it (for event devices, etc.), and we might look for ways to
unify the logic with EventContext, but this simple struct should suffice
for now.

Bug: 244489783
Bug: 244491590
Test: flat run emulator
Test: flat run battlestar

Change-Id: I5722523ad1424a1860f2883d33728a1baf9550cc
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4719209
Reviewed-by: Pujun Lun <lunpujun@google.com>
Reviewed-by: Noah Gold <nkgold@google.com>
Commit-Queue: Kaiyi Li <kaiyili@google.com>
2023-08-29 00:18:26 +00:00
Pujun Lun
3106fa2733 gpu_display: replace GetMessageW() with MsgWaitForMultipleObjects().
Currently we have two display event loops, one in the GPU worker thread
(mainly used by other platforms; we just poll event devices and the
display closed event there) and one in the WndProc thread (for handling
Windows specific window messages). We are exploring the possibilities of
merging those loops.

MsgWaitForMultipleObjects() allows us to wait for window messages and
other events at the same time. As the first step of our experiments,
we will use it to replace GetMessageW() while keeping everything else
unchanged. Simple performance tests show that there is no regression in
the average latency between we posting a message to the message queue
and we finishing retrieving it from the queue.

Bug: 244489783
Test: Ran GPG

Change-Id: I2ccea348459fa7af0a2ee0ac55e7c817f222a2f6
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4719208
Reviewed-by: Pujun Lun <lunpujun@google.com>
Commit-Queue: Kaiyi Li <kaiyili@google.com>
Reviewed-by: Noah Gold <nkgold@google.com>
2023-08-28 23:33:23 +00:00
lunpujun
ca35151bc1 gpu_display: fix a potential memory leak in thread_message_util.
If PeekMessageW() does retrieve a message, we are responsibe for
dropping it.

Bug: 244489783
Test: Ran GPG
Change-Id: I69250387cc93698513a47d38de52d161a0026692
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4719207
Reviewed-by: Pujun Lun <lunpujun@google.com>
Reviewed-by: Vikram Auradkar <auradkar@google.com>
Commit-Queue: Kaiyi Li <kaiyili@google.com>
2023-08-28 21:01:43 +00:00
Frederick Mayle
d13a8cf231 gpu_display: delete unused field and method GpuDisplay::is_x
Change-Id: I5a1e4aa28100bf9d935902bf5040b4e4f6744927
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4777341
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2023-08-18 18:23:25 +00:00
Frederick Mayle
6a4aea4445 gpu_display: simplify GpuDisplay::open_x signature
Change-Id: I334004ac47466de2f8cd800e680a14cb7f75ef3c
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4775759
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2023-08-18 18:23:25 +00:00
Vikram Auradkar
0e1c85f293 clippy: Disallow new_without_default
BUG=b:283512997
TEST=none

Change-Id: If10b73f0cd686ff1a1a17e4aa3260f01e1ee8db5
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4546662
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Vikram Auradkar <auradkar@google.com>
2023-05-22 21:14:06 +00:00
Ryan Neph
99ca07bd39 gpu_display: pass error logging callback and remove syslog()
syslog() is used on the error path for wayland display management. On
32-bit arm, the glibc implementation of syslog() uses send(), which
causes a seccomp violation. This was regressed a long time ago and never
found until now.

Fixing syslog() on 32-bit arm requires changes to gpu_device.policy on
32-bit arm (to add send() and socket()), but we'd prefer to call
crosvm's configured logger and drop syslog() anyways, so let's just do
that.

TEST=Run crosvm + glxgears/vkcube
BUG=b:281165392

Change-Id: I69bcf8cf3617d117360c4a255b1cc1234493eccc
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4517955
Commit-Queue: Ryan Neph <ryanneph@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2023-05-10 19:56:16 +00:00
Daniel Verkamp
b080f54729 gpu_display: allow xlib::Window to u64 casts
The code should not depend on xlib::Window being u64 internally (it
could differ on 32-bit platforms), so allow the clippy warning rather
than removing the casts.

BUG=b:276487055
TEST=tools/clippy # with rust 1.68

Change-Id: Iba59c2d4fb940837783679fce81c2b35ed64142b
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4390738
Reviewed-by: Zihan Chen <zihanchen@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2023-04-10 19:55:20 +00:00
Daniel Verkamp
083dcf75f4 tree-wide: apply nightly rustfmt
BUG=None
TEST=tools/fmt --nightly

Change-Id: Ifb08dd55ccf2a74ef739d7517a64970d24a82405
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4375640
Auto-Submit: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2023-03-27 21:30:45 +00:00
Zihan Chen
bbc4f68ebb crosvm: Convert DataInit to zerocopy 10/n
We are down to only 30 `unsafe impl DataInit` across our repo now!

TEST=CQ

BUG=b:204409584

Change-Id: I1b6cf95b2a15eac194f3b464330009fd898a0bfa
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4356907
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Auto-Submit: Zihan Chen <zihanchen@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2023-03-24 18:12:38 +00:00
Zihan Chen
c30a6ac4ea gpu_display: Read only 8 bytes from socket for virtio_input_event
Previously this function will consume 24 bytes from event socket
and try to convert the bytes into virtio_input_event (8 bytes)
using DataInit::from_slice(). from_slice() guards size mismatched
conversion and will always return None and fall into Err branch.

Seems related to crrev/c/2034046

TEST=CQ, input still work running a debian desktop vm

Change-Id: Ib82095fed6ec4591ba170a6a52fe47a61d33e013
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4357923
Reviewed-by: Noah Gold <nkgold@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Zihan Chen <zihanchen@google.com>
2023-03-22 01:30:34 +00:00
Daniel Verkamp
732b422bdc gpu_display: find wayland-scanner with which in build.rs
This allows us to print a more useful error message if the
wayland-scanner tool is not present.

BUG=None
TEST=cargo build # with and without wayland-scanner present

Change-Id: I8909e064621cb4d71bc8ec96d76df8a2b4c4fc88
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4294676
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2023-02-27 21:18:21 +00:00
Zihan Chen
30f58a81aa crosvm: Partially convert DataInit to zerocopy (6/n)
This CL removed many uses of DataInit in devices. Some paddings
are manually added/fixed to allow AsBytes to derive without ABI
changes.

TESTED=CQ

BUG=b:204409584

Change-Id: I1f8c2d5304fc8e685cc3e5166c73481f6a3f78f7
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4235224
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Auto-Submit: Zihan Chen <zihanchen@google.com>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2023-02-10 01:52:24 +00:00
Zihan Chen
28ce4e5423 crosvm: Uprev rust toolchain and dev container
- Rust toolchain is updated to 1.65.0
- Catapult dashboard upload tool is added to dev_container
- Bindgen is updated to latest version to support custom derive
- Derive Eq when PartialEq is derived as required by new Clippy

TEST=CQ, bindgen-all-the-things

FIXED=b:260784028
BUG=b:257303497

Change-Id: I2034cd09e0aed84d4e9b30f2e85d84d94a442ea4
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4228427
Auto-Submit: Zihan Chen <zihanchen@google.com>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Zihan Chen <zihanchen@google.com>
2023-02-08 20:26:30 +00:00
Dennis Kempin
acc162000f Add conditional compilation for unix-only crates
Instead of configuring which crates to --exclude in
test_config.py, we can use conditional compilation to
exclude code that is not supported on windows.

This allows more fine-grained control and also allows
us to use plain cargo for building without complicated
configuration and exclusions.

BUG=b:265829867
TEST=cargo test --lib --bins --workspace
	--target=x86_64-pc-windows-gnu
	--features=all-mingw64

Change-Id: I8422c3f08053bc27d9896b220876a56bd25543d6
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4165868
Reviewed-by: Vikram Auradkar <auradkar@google.com>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2023-01-19 21:21:59 +00:00
Daniel Verkamp
ac0fc378a3 Fix remaining Chrome/Chromium OS instances
These should be written as ChromeOS and ChromiumOS (without the space)
to match the updated branding. The copyright headers were already
migrated to the new style (https://crrev.com/c/3894243), but there were
some more instances left over.

BUG=None
TEST=tools/cargo-doc

Change-Id: I8c76aea2eb33b2e370ab71ee9b5cc0a4cfd00585
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4129934
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2023-01-03 22:14:30 +00:00
Daniel Verkamp
7519b10342 gpu_display: require x feature for simple_open example
The simple_open example doesn't work without --features=x, so mark it as
a required feature.

BUG=None
TEST=cargo build -p gpu_display --example simple_open # fails
TEST=cargo build -p gpu_display --features x --example simple_open

Change-Id: Id780d6e56bb8aebd4abfc42f58ab0b49fb524f02
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4068551
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2022-12-01 06:11:48 +00:00
Daniel Verkamp
54cc0eb450 gpu_display: make simple and simple_open example targets
Fixes cargo warning:
  [...]/gpu_display/Cargo.toml: file found to be present in multiple build targets:
  [...]/gpu_display/examples/simple.rs

https://doc.rust-lang.org/cargo/reference/cargo-targets.html#examples

BUG=None
TEST=cargo build -p gpu_display --example simple --example simple_open

Change-Id: I76d0c5729caf2926c9d7fe54170b10c15267fe6f
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4068547
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
2022-12-01 06:11:03 +00:00
Daniel Verkamp
10990c89af Rust 1.65: Fix clippy derive_partial_eq_without_eq lints
BUG=b:260784028
TEST=tools/clippy

Change-Id: Ib2b595385ed04b9480b22549334ce798d980d347
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4064717
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
2022-12-01 01:32:30 +00:00