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().
This commit is contained in:
Pekka Paalanen 2018-09-05 12:07:59 +03:00
parent 72e236106f
commit a3d826c54b
3 changed files with 15 additions and 4 deletions

View File

@ -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));
}
}

View File

@ -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 */

View File

@ -126,6 +126,7 @@ typedef struct _MetaDumbBuffer
uint64_t map_size;
int width;
int height;
int stride_bytes;
} MetaDumbBuffer;
typedef struct _MetaOnscreenNativeSecondaryGpuState
@ -1786,6 +1787,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;
@ -1804,12 +1806,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;
}
@ -2306,6 +2310,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;