[mutter/wip/rstrode/rhel-8.0.0: 15/30] renderer/native: honour dumb buffer stride



commit dc539017e7aa11205e4286ecbea7992afe6a8711
Author: Pekka Paalanen <pekka paalanen collabora co uk>
Date:   Wed Sep 5 12:07:59 2018 +0300

    renderer/native: honour dumb buffer stride
    
    meta_renderer_native_gles3_read_pixels() was assuming that the target
    buffer stride == width * 4. This is not generally true. When a DRM
    driver allocates a dumb buffer, it is free to choose a stride so that
    the buffer can actually work on the hardware.
    
    Record the driver chosen stride in MetaDumbBuffer, and use it in the CPU
    copy path. This should fix any possible stride issues in
    meta_renderer_native_gles3_read_pixels().

 src/backends/native/meta-renderer-native-gles3.c | 8 ++++++--
 src/backends/native/meta-renderer-native-gles3.h | 4 +++-
 src/backends/native/meta-renderer-native.c       | 7 ++++++-
 3 files changed, 15 insertions(+), 4 deletions(-)
---
diff --git a/src/backends/native/meta-renderer-native-gles3.c 
b/src/backends/native/meta-renderer-native-gles3.c
index dbc59b6f6..49832ff7e 100644
--- a/src/backends/native/meta-renderer-native-gles3.c
+++ b/src/backends/native/meta-renderer-native-gles3.c
@@ -2,6 +2,7 @@
 
 /*
  * Copyright (C) 2017 Red Hat
+ * Copyright (c) 2018 DisplayLink (UK) Ltd.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
@@ -243,16 +244,19 @@ meta_renderer_native_gles3_read_pixels (MetaEgl   *egl,
                                         MetaGles3 *gles3,
                                         int        width,
                                         int        height,
-                                        uint8_t   *target_data)
+                                        uint8_t   *target_data,
+                                        int        target_stride_bytes)
 {
   int y;
 
+  g_assert (target_stride_bytes >= 0);
+
   GLBAS (gles3, glFinish, ());
 
   for (y = 0; y < height; y++)
     {
       GLBAS (gles3, glReadPixels, (0, height - y, width, 1,
                                    GL_RGBA, GL_UNSIGNED_BYTE,
-                                   target_data + width * y * 4));
+                                   target_data + y * target_stride_bytes));
     }
 }
diff --git a/src/backends/native/meta-renderer-native-gles3.h 
b/src/backends/native/meta-renderer-native-gles3.h
index b4ca19285..ecd0d29de 100644
--- a/src/backends/native/meta-renderer-native-gles3.h
+++ b/src/backends/native/meta-renderer-native-gles3.h
@@ -2,6 +2,7 @@
 
 /*
  * Copyright (C) 2017 Red Hat
+ * Copyright (c) 2018 DisplayLink (UK) Ltd.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
@@ -40,6 +41,7 @@ void meta_renderer_native_gles3_read_pixels (MetaEgl   *egl,
                                              MetaGles3 *gles3,
                                              int        width,
                                              int        height,
-                                             uint8_t   *target_data);
+                                             uint8_t   *target_data,
+                                             int        target_stride_bytes);
 
 #endif /* META_RENDERER_NATIVE_GLES3_H */
diff --git a/src/backends/native/meta-renderer-native.c b/src/backends/native/meta-renderer-native.c
index 5d6664678..34a4522d4 100644
--- a/src/backends/native/meta-renderer-native.c
+++ b/src/backends/native/meta-renderer-native.c
@@ -125,6 +125,7 @@ typedef struct _MetaDumbBuffer
   uint64_t map_size;
   int width;
   int height;
+  int stride_bytes;
 } MetaDumbBuffer;
 
 typedef struct _MetaOnscreenNativeSecondaryGpuState
@@ -1793,6 +1794,7 @@ copy_shared_framebuffer_cpu (CoglOnscreen                        *onscreen,
   MetaEgl *egl = meta_renderer_native_get_egl (renderer_native);
   int width, height;
   uint8_t *target_data;
+  int target_stride_bytes;
   uint32_t target_fb_id;
   MetaDumbBuffer *next_dumb_fb;
   MetaDumbBuffer *current_dumb_fb;
@@ -1811,12 +1813,14 @@ copy_shared_framebuffer_cpu (CoglOnscreen                        *onscreen,
   g_assert (height == secondary_gpu_state->cpu.dumb_fb->height);
 
   target_data = secondary_gpu_state->cpu.dumb_fb->map;
+  target_stride_bytes = secondary_gpu_state->cpu.dumb_fb->stride_bytes;
   target_fb_id = secondary_gpu_state->cpu.dumb_fb->fb_id;
 
   meta_renderer_native_gles3_read_pixels (egl,
                                           renderer_native->gles3,
                                           width, height,
-                                          target_data);
+                                          target_data,
+                                          target_stride_bytes);
 
   secondary_gpu_state->gbm.next_fb_id = target_fb_id;
 }
@@ -2310,6 +2314,7 @@ init_dumb_fb (MetaDumbBuffer  *dumb_fb,
   dumb_fb->map_size = create_arg.size;
   dumb_fb->width = width;
   dumb_fb->height = height;
+  dumb_fb->stride_bytes = create_arg.pitch;
 
   return TRUE;
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]