renderer/native: Add meta_dumb_buffer_ensure_dmabuf_fd

Follow-up work will use this in an attempt to use the primary GPU to
copy into secondary GPU dumb buffers.

https://gitlab.gnome.org/GNOME/mutter/merge_requests/615
This commit is contained in:
Pekka Paalanen 2018-11-29 13:37:16 +02:00 committed by Jonas Ådahl
parent a3c425ad89
commit 2c893beff1

View File

@ -138,6 +138,7 @@ typedef struct _MetaDumbBuffer
int height; int height;
int stride_bytes; int stride_bytes;
uint32_t drm_format; uint32_t drm_format;
int dmabuf_fd;
} MetaDumbBuffer; } MetaDumbBuffer;
typedef struct _MetaOnscreenNativeSecondaryGpuState typedef struct _MetaOnscreenNativeSecondaryGpuState
@ -240,6 +241,10 @@ init_dumb_fb (MetaDumbBuffer *dumb_fb,
uint32_t format, uint32_t format,
GError **error); GError **error);
static int
meta_dumb_buffer_ensure_dmabuf_fd (MetaDumbBuffer *dumb_fb,
MetaGpuKms *gpu_kms);
static MetaEgl * static MetaEgl *
meta_renderer_native_get_egl (MetaRendererNative *renderer_native); meta_renderer_native_get_egl (MetaRendererNative *renderer_native);
@ -2461,6 +2466,7 @@ init_dumb_fb (MetaDumbBuffer *dumb_fb,
dumb_fb->height = height; dumb_fb->height = height;
dumb_fb->stride_bytes = create_arg.pitch; dumb_fb->stride_bytes = create_arg.pitch;
dumb_fb->drm_format = format; dumb_fb->drm_format = format;
dumb_fb->dmabuf_fd = -1;
return TRUE; return TRUE;
@ -2478,6 +2484,33 @@ err_ioctl:
return FALSE; return FALSE;
} }
static int
meta_dumb_buffer_ensure_dmabuf_fd (MetaDumbBuffer *dumb_fb,
MetaGpuKms *gpu_kms)
{
int ret;
int kms_fd;
int dmabuf_fd;
if (dumb_fb->dmabuf_fd != -1)
return dumb_fb->dmabuf_fd;
kms_fd = meta_gpu_kms_get_fd (gpu_kms);
ret = drmPrimeHandleToFD (kms_fd, dumb_fb->handle, DRM_CLOEXEC,
&dmabuf_fd);
if (ret)
{
g_debug ("Failed to export dumb drm buffer: %s",
g_strerror (errno));
return -1;
}
dumb_fb->dmabuf_fd = dmabuf_fd;
return dumb_fb->dmabuf_fd;
}
static void static void
release_dumb_fb (MetaDumbBuffer *dumb_fb, release_dumb_fb (MetaDumbBuffer *dumb_fb,
MetaGpuKms *gpu_kms) MetaGpuKms *gpu_kms)
@ -2488,6 +2521,9 @@ release_dumb_fb (MetaDumbBuffer *dumb_fb,
if (!dumb_fb->map) if (!dumb_fb->map)
return; return;
if (dumb_fb->dmabuf_fd != -1)
close (dumb_fb->dmabuf_fd);
munmap (dumb_fb->map, dumb_fb->map_size); munmap (dumb_fb->map, dumb_fb->map_size);
dumb_fb->map = NULL; dumb_fb->map = NULL;