summary refs log tree commit diff
path: root/gpu_buffer
diff options
context:
space:
mode:
authorZach Reizner <zachr@google.com>2019-04-16 15:09:20 -0700
committerCommit Bot <commit-bot@chromium.org>2019-07-25 22:15:48 +0000
commitf5285c647acacb4f25ef8cf9334254b976e71686 (patch)
treefcc238ec97736727a9c18b3b9de29be3dce3983e /gpu_buffer
parentb2110bef59d72529d99c722df9b3e9a1d705e6f4 (diff)
downloadcrosvm-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_buffer')
-rw-r--r--gpu_buffer/src/lib.rs14
1 files changed, 9 insertions, 5 deletions
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));