diff options
author | Zach Reizner <zachr@google.com> | 2019-04-16 15:09:20 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2019-07-25 22:15:48 +0000 |
commit | f5285c647acacb4f25ef8cf9334254b976e71686 (patch) | |
tree | fcc238ec97736727a9c18b3b9de29be3dce3983e /gpu_display/examples/simple_open.rs | |
parent | b2110bef59d72529d99c722df9b3e9a1d705e6f4 (diff) | |
download | crosvm-f5285c647acacb4f25ef8cf9334254b976e71686.tar crosvm-f5285c647acacb4f25ef8cf9334254b976e71686.tar.gz crosvm-f5285c647acacb4f25ef8cf9334254b976e71686.tar.bz2 crosvm-f5285c647acacb4f25ef8cf9334254b976e71686.tar.lz crosvm-f5285c647acacb4f25ef8cf9334254b976e71686.tar.xz crosvm-f5285c647acacb4f25ef8cf9334254b976e71686.tar.zst crosvm-f5285c647acacb4f25ef8cf9334254b976e71686.zip |
gpu_display: add X11 backend
This change adds an X11 backend to the gpu_display crate. With this addition, the virtio-gpu device can display to traditional linux desktops that only have X11 output. Change-Id: I86c80cac91ca5bdc97588194a44040273ae69385 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1591572 Reviewed-by: Stéphane Marchesin <marcheu@chromium.org> Commit-Queue: Zach Reizner <zachr@chromium.org> Tested-by: Zach Reizner <zachr@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Auto-Submit: Zach Reizner <zachr@chromium.org>
Diffstat (limited to 'gpu_display/examples/simple_open.rs')
-rw-r--r-- | gpu_display/examples/simple_open.rs | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/gpu_display/examples/simple_open.rs b/gpu_display/examples/simple_open.rs new file mode 100644 index 0000000..bb7b1a2 --- /dev/null +++ b/gpu_display/examples/simple_open.rs @@ -0,0 +1,25 @@ +use gpu_display::GpuDisplay; + +fn main() { + let mut disp = GpuDisplay::open_x(None::<&str>).unwrap(); + let surface_id = disp.create_surface(None, 1280, 1024).unwrap(); + + let mem = disp.framebuffer(surface_id).unwrap(); + for y in 0..1024 { + let mut row = [0u32; 1280]; + for x in 0..1280 { + let b = ((x as f32 / 1280.0) * 256.0) as u32; + let g = ((y as f32 / 1024.0) * 256.0) as u32; + row[x] = b | (g << 8); + } + mem.as_volatile_slice() + .offset((1280 * 4 * y) as u64) + .unwrap() + .copy_from(&row); + } + disp.flip(surface_id); + + while !disp.close_requested(surface_id) { + disp.dispatch_events(); + } +} |