1 // Copyright 2019 The ChromiumOS Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 use std::process::exit; 6 7 #[cfg(any(target_os = "android", target_os = "linux"))] 8 mod platform { 9 use anyhow::Context; 10 use anyhow::Result; 11 use gpu_display::*; 12 use vm_control::gpu::DisplayMode; 13 use vm_control::gpu::DisplayParameters; 14 run() -> Result<()>15 pub fn run() -> Result<()> { 16 let mut disp = GpuDisplay::open_wayland(None::<&str>).context("open_wayland")?; 17 let surface_id = disp 18 .create_surface( 19 None, 20 /* scanout_id= */ Some(0), 21 &DisplayParameters::default_with_mode(DisplayMode::Windowed(1280, 1024)), 22 SurfaceType::Scanout, 23 ) 24 .context("create_surface")?; 25 disp.flip(surface_id); 26 disp.commit(surface_id).context("commit")?; 27 while !disp.close_requested(surface_id) { 28 disp.dispatch_events().context("dispatch_events")?; 29 } 30 Ok(()) 31 } 32 } 33 34 #[cfg(not(unix))] 35 mod platform { 36 use anyhow::anyhow; 37 use anyhow::Result; 38 run() -> Result<()>39 pub fn run() -> Result<()> { 40 Err(anyhow!("Only supported on unix targets")) 41 } 42 } 43 main()44fn main() { 45 if let Err(e) = platform::run() { 46 eprintln!("error: {:#}", e); 47 exit(1); 48 } 49 } 50