1
0
Fork 0

drm-buffer-gbm: Cache EGLImages created during screen-casting

This consolidates duplicate code in meta_drm_buffer_gbm_blit_to_framebuffer
to use the newly added meta_drm_buffer_gbm_create_native_blit_image, which
also has the side-effect of caching creation of the EGLImage per GBM BO.

(cherry picked from commit c866ca2206ab279f639fa452f43812abd9be243a)
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/4027>
Signed-off-by: Mingi Sung <sungmg@saltyming.net>
This commit is contained in:
Gert-dev 2024-10-02 21:14:53 +02:00 committed by Mingi Sung
parent 09c8a4c8a3
commit 61fd95e495
Signed by: sungmg
GPG key ID: 41BAFD6FFD8036C5

View file

@ -384,67 +384,28 @@ meta_drm_buffer_gbm_blit_to_framebuffer (CoglScanout *scanout,
CoglEglImageFlags flags;
CoglOffscreen *cogl_fbo = NULL;
CoglTexture *cogl_tex;
uint32_t n_planes;
uint64_t *modifiers;
uint32_t *strides;
uint32_t *offsets;
uint32_t width;
uint32_t height;
uint32_t drm_format;
int *fds;
uint32_t format;
gboolean result;
int dmabuf_fd = -1;
uint32_t i;
const MetaFormatInfo *format_info;
dmabuf_fd = gbm_bo_get_fd (buffer_gbm->bo);
if (dmabuf_fd == -1)
{
g_set_error (error, G_IO_ERROR, G_IO_ERROR_EXISTS,
"Failed to export buffer's DMA fd: %s",
g_strerror (errno));
return FALSE;
}
egl_image = meta_drm_buffer_gbm_create_native_blit_image (egl, egl_display, buffer_gbm->bo, error);
drm_format = gbm_bo_get_format (buffer_gbm->bo);
format_info = meta_format_info_from_drm_format (drm_format);
g_assert (format_info);
cogl_format = format_info->cogl_format;
width = gbm_bo_get_width (buffer_gbm->bo);
height = gbm_bo_get_height (buffer_gbm->bo);
n_planes = gbm_bo_get_plane_count (buffer_gbm->bo);
fds = g_alloca (sizeof (int) * n_planes);
strides = g_alloca (sizeof (uint32_t) * n_planes);
offsets = g_alloca (sizeof (uint32_t) * n_planes);
modifiers = g_alloca (sizeof (uint64_t) * n_planes);
for (i = 0; i < n_planes; i++)
{
fds[i] = dmabuf_fd;
strides[i] = gbm_bo_get_stride_for_plane (buffer_gbm->bo, i);
offsets[i] = gbm_bo_get_offset (buffer_gbm->bo, i);
modifiers[i] = gbm_bo_get_modifier (buffer_gbm->bo);
}
egl_image = meta_egl_create_dmabuf_image (egl,
egl_display,
width,
height,
drm_format,
n_planes,
fds,
strides,
offsets,
modifiers,
error);
if (egl_image == EGL_NO_IMAGE_KHR)
{
result = FALSE;
goto out;
}
width = gbm_bo_get_width (buffer_gbm->bo);
height = gbm_bo_get_height (buffer_gbm->bo);
format = gbm_bo_get_format (buffer_gbm->bo);
format_info = meta_format_info_from_drm_format (format);
g_assert (format_info);
cogl_format = format_info->cogl_format;
flags = COGL_EGL_IMAGE_FLAG_NO_GET_DATA;
cogl_tex = cogl_texture_2d_new_from_egl_image (cogl_context,
width,
@ -480,7 +441,6 @@ meta_drm_buffer_gbm_blit_to_framebuffer (CoglScanout *scanout,
out:
g_clear_object (&cogl_fbo);
close (dmabuf_fd);
return result;
}