From f5285c647acacb4f25ef8cf9334254b976e71686 Mon Sep 17 00:00:00 2001 From: Zach Reizner Date: Tue, 16 Apr 2019 15:09:20 -0700 Subject: gpu_display: add X11 backend MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Commit-Queue: Zach Reizner Tested-by: Zach Reizner Tested-by: kokoro Auto-Submit: Zach Reizner --- gpu_buffer/src/lib.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'gpu_buffer/src') diff --git a/gpu_buffer/src/lib.rs b/gpu_buffer/src/lib.rs index 53fca92..08174dc 100644 --- a/gpu_buffer/src/lib.rs +++ b/gpu_buffer/src/lib.rs @@ -566,19 +566,21 @@ impl Buffer { height: u32, plane: usize, dst: VolatileSlice, + dst_stride: u32, ) -> Result<(), Error> { if width == 0 || height == 0 { return Ok(()); } let mapping = self.map(x, y, width, height, plane, GBM_BO_TRANSFER_READ)?; + let src_stride = mapping.stride() as u64; + let dst_stride = dst_stride as u64; - if x == 0 && width == self.width() { + if x == 0 && width == self.width() && src_stride == dst_stride { mapping.as_volatile_slice().copy_to_volatile_slice(dst); } else { // This path is more complicated because there are gaps in the data between lines. let width = width as u64; - let stride = mapping.stride() as u64; let bytes_per_pixel = match self.format().bytes_per_pixel(plane) { Some(bpp) => bpp as u64, None => return Err(Error::UnknownFormat(self.format())), @@ -586,12 +588,13 @@ impl Buffer { let line_copy_size = checked_arithmetic!(width * bytes_per_pixel)?; let src = mapping.as_volatile_slice(); for yy in 0..(height as u64) { - let line_offset = checked_arithmetic!(yy * stride)?; + let src_line_offset = checked_arithmetic!(yy * src_stride)?; + let dst_line_offset = checked_arithmetic!(yy * dst_stride)?; let src_line = src - .get_slice(line_offset, line_copy_size) + .get_slice(src_line_offset, line_copy_size) .map_err(Error::Memcopy)?; let dst_line = dst - .get_slice(line_offset, line_copy_size) + .get_slice(dst_line_offset, line_copy_size) .map_err(Error::Memcopy)?; src_line.copy_to_volatile_slice(dst_line); } @@ -855,6 +858,7 @@ mod tests { 1024, 0, dst.as_mut_slice().get_slice(0, dst_len).unwrap(), + bo.stride(), ) .expect("failed to read bo"); assert!(dst.iter().all(|&x| x == 0x4A)); -- cgit 1.4.1