• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2022 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 use anyhow::Context;
8 use anyhow::Result;
9 use gpu_display::GpuDisplay;
10 use gpu_display::SurfaceType;
11 
run() -> Result<()>12 fn run() -> Result<()> {
13     let mut disp = GpuDisplay::open_x(None::<&str>).context("open_x")?;
14     let surface_id = disp
15         .create_surface(None, 1280, 1024, SurfaceType::Scanout)
16         .context("create_surface")?;
17 
18     let mem = disp.framebuffer(surface_id).context("framebuffer")?;
19     for y in 0..1024 {
20         let mut row = [0u32; 1280];
21         for (x, item) in row.iter_mut().enumerate() {
22             let b = ((x as f32 / 1280.0) * 256.0) as u32;
23             let g = ((y as f32 / 1024.0) * 256.0) as u32;
24             *item = b | (g << 8);
25         }
26         mem.as_volatile_slice()
27             .offset(1280 * 4 * y)
28             .unwrap()
29             .copy_from(&row);
30     }
31     disp.flip(surface_id);
32 
33     while !disp.close_requested(surface_id) {
34         disp.dispatch_events().context("dispatch_events")?;
35     }
36 
37     Ok(())
38 }
39 
main()40 fn main() {
41     if let Err(e) = run() {
42         eprintln!("error: {:#}", e);
43         exit(1);
44     }
45 }
46