Check and use QemuDmaBuf->modifier in egl_dmabuf_import_texture()
for dmabuf imports.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
ui/egl-helpers.c | 34 +++++++++++++++++++++++++---------
1 file changed, 25 insertions(+), 9 deletions(-)
diff --git a/ui/egl-helpers.c b/ui/egl-helpers.c
index 0c9716067cfb..edc53f6d3464 100644
--- a/ui/egl-helpers.c
+++ b/ui/egl-helpers.c
@@ -229,20 +229,36 @@ int egl_get_fd_for_texture(uint32_t tex_id, EGLint *stride, EGLint *fourcc,
void egl_dmabuf_import_texture(QemuDmaBuf *dmabuf)
{
EGLImageKHR image = EGL_NO_IMAGE_KHR;
- EGLint attrs[] = {
- EGL_DMA_BUF_PLANE0_FD_EXT, dmabuf->fd,
- EGL_DMA_BUF_PLANE0_PITCH_EXT, dmabuf->stride,
- EGL_DMA_BUF_PLANE0_OFFSET_EXT, 0,
- EGL_WIDTH, dmabuf->width,
- EGL_HEIGHT, dmabuf->height,
- EGL_LINUX_DRM_FOURCC_EXT, dmabuf->fourcc,
- EGL_NONE, /* end of list */
- };
+ EGLint attrs[64];
+ int i = 0;
if (dmabuf->texture != 0) {
return;
}
+ attrs[i++] = EGL_WIDTH;
+ attrs[i++] = dmabuf->width;
+ attrs[i++] = EGL_HEIGHT;
+ attrs[i++] = dmabuf->height;
+ attrs[i++] = EGL_LINUX_DRM_FOURCC_EXT;
+ attrs[i++] = dmabuf->fourcc;
+
+ attrs[i++] = EGL_DMA_BUF_PLANE0_FD_EXT;
+ attrs[i++] = dmabuf->fd;
+ attrs[i++] = EGL_DMA_BUF_PLANE0_PITCH_EXT;
+ attrs[i++] = dmabuf->stride;
+ attrs[i++] = EGL_DMA_BUF_PLANE0_OFFSET_EXT;
+ attrs[i++] = 0;
+#ifdef EGL_DMA_BUF_PLANE0_MODIFIER_LO_EXT
+ if (dmabuf->modifier) {
+ attrs[i++] = EGL_DMA_BUF_PLANE0_MODIFIER_LO_EXT;
+ attrs[i++] = (dmabuf->modifier >> 0) & 0xffffffff;
+ attrs[i++] = EGL_DMA_BUF_PLANE0_MODIFIER_HI_EXT;
+ attrs[i++] = (dmabuf->modifier >> 32) & 0xffffffff;
+ }
+#endif
+ attrs[i++] = EGL_NONE;
+
image = eglCreateImageKHR(qemu_egl_display,
EGL_NO_CONTEXT,
EGL_LINUX_DMA_BUF_EXT,
--
2.18.1
Hi
On Wed, May 29, 2019 at 9:24 AM Gerd Hoffmann <kraxel@redhat.com> wrote:
>
> Check and use QemuDmaBuf->modifier in egl_dmabuf_import_texture()
> for dmabuf imports.
>
> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
> ---
> ui/egl-helpers.c | 34 +++++++++++++++++++++++++---------
> 1 file changed, 25 insertions(+), 9 deletions(-)
>
> diff --git a/ui/egl-helpers.c b/ui/egl-helpers.c
> index 0c9716067cfb..edc53f6d3464 100644
> --- a/ui/egl-helpers.c
> +++ b/ui/egl-helpers.c
> @@ -229,20 +229,36 @@ int egl_get_fd_for_texture(uint32_t tex_id, EGLint *stride, EGLint *fourcc,
> void egl_dmabuf_import_texture(QemuDmaBuf *dmabuf)
> {
> EGLImageKHR image = EGL_NO_IMAGE_KHR;
> - EGLint attrs[] = {
> - EGL_DMA_BUF_PLANE0_FD_EXT, dmabuf->fd,
> - EGL_DMA_BUF_PLANE0_PITCH_EXT, dmabuf->stride,
> - EGL_DMA_BUF_PLANE0_OFFSET_EXT, 0,
> - EGL_WIDTH, dmabuf->width,
> - EGL_HEIGHT, dmabuf->height,
> - EGL_LINUX_DRM_FOURCC_EXT, dmabuf->fourcc,
> - EGL_NONE, /* end of list */
> - };
> + EGLint attrs[64];
> + int i = 0;
>
> if (dmabuf->texture != 0) {
> return;
> }
>
> + attrs[i++] = EGL_WIDTH;
> + attrs[i++] = dmabuf->width;
> + attrs[i++] = EGL_HEIGHT;
> + attrs[i++] = dmabuf->height;
> + attrs[i++] = EGL_LINUX_DRM_FOURCC_EXT;
> + attrs[i++] = dmabuf->fourcc;
> +
> + attrs[i++] = EGL_DMA_BUF_PLANE0_FD_EXT;
> + attrs[i++] = dmabuf->fd;
> + attrs[i++] = EGL_DMA_BUF_PLANE0_PITCH_EXT;
> + attrs[i++] = dmabuf->stride;
> + attrs[i++] = EGL_DMA_BUF_PLANE0_OFFSET_EXT;
> + attrs[i++] = 0;
> +#ifdef EGL_DMA_BUF_PLANE0_MODIFIER_LO_EXT
> + if (dmabuf->modifier) {
> + attrs[i++] = EGL_DMA_BUF_PLANE0_MODIFIER_LO_EXT;
> + attrs[i++] = (dmabuf->modifier >> 0) & 0xffffffff;
> + attrs[i++] = EGL_DMA_BUF_PLANE0_MODIFIER_HI_EXT;
> + attrs[i++] = (dmabuf->modifier >> 32) & 0xffffffff;
> + }
> +#endif
Shouldn't there be at least a warning for #else?
> + attrs[i++] = EGL_NONE;
> +
> image = eglCreateImageKHR(qemu_egl_display,
> EGL_NO_CONTEXT,
> EGL_LINUX_DMA_BUF_EXT,
> --
> 2.18.1
>
>
--
Marc-André Lureau
Hi,
> > +#ifdef EGL_DMA_BUF_PLANE0_MODIFIER_LO_EXT
> > + if (dmabuf->modifier) {
> > + attrs[i++] = EGL_DMA_BUF_PLANE0_MODIFIER_LO_EXT;
> > + attrs[i++] = (dmabuf->modifier >> 0) & 0xffffffff;
> > + attrs[i++] = EGL_DMA_BUF_PLANE0_MODIFIER_HI_EXT;
> > + attrs[i++] = (dmabuf->modifier >> 32) & 0xffffffff;
> > + }
> > +#endif
>
> Shouldn't there be at least a warning for #else?
I don't think so. In most cases (single gpu device in the host) things
will work fine even without specifying the modifier.
cheers,
Gerd
© 2016 - 2026 Red Hat, Inc.