[PATCH 11/20] ui: add an optional get_flags callback to GraphicHwOps

marcandre.lureau@redhat.com posted 20 patches 3 years, 9 months ago
There is a newer version of this series
[PATCH 11/20] ui: add an optional get_flags callback to GraphicHwOps
Posted by marcandre.lureau@redhat.com 3 years, 9 months ago
From: Marc-André Lureau <marcandre.lureau@redhat.com>

Those flags can be used to express different requirements for the
display or other needs.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 include/ui/console.h         |  9 +++++++++
 hw/display/virtio-gpu-base.c | 16 ++++++++++++++++
 hw/display/virtio-vga.c      |  9 +++++++++
 hw/vfio/display.c            |  6 ++++++
 4 files changed, 40 insertions(+)

diff --git a/include/ui/console.h b/include/ui/console.h
index ac989fdf70..0595aa9953 100644
--- a/include/ui/console.h
+++ b/include/ui/console.h
@@ -368,7 +368,16 @@ static inline void console_write_ch(console_ch_t *dest, uint32_t ch)
     *dest = ch;
 }
 
+enum {
+    GRAPHIC_FLAGS_NONE     = 0,
+    /* require a console/display with GL callbacks */
+    GRAPHIC_FLAGS_GL       = 1 << 0,
+    /* require a console/display with DMABUF import */
+    GRAPHIC_FLAGS_DMABUF   = 1 << 1,
+};
+
 typedef struct GraphicHwOps {
+    int (*get_flags)(void *opaque); /* optional, default 0 */
     void (*invalidate)(void *opaque);
     void (*gfx_update)(void *opaque);
     bool gfx_update_async; /* if true, calls graphic_hw_update_done() */
diff --git a/hw/display/virtio-gpu-base.c b/hw/display/virtio-gpu-base.c
index 40ccd00f94..82c37aac62 100644
--- a/hw/display/virtio-gpu-base.c
+++ b/hw/display/virtio-gpu-base.c
@@ -114,7 +114,23 @@ virtio_gpu_gl_block(void *opaque, bool block)
     }
 }
 
+static int
+virtio_gpu_get_flags(void *opaque)
+{
+    VirtIOGPUBase *g = opaque;
+    int flags = GRAPHIC_FLAGS_NONE;
+
+    if (virtio_gpu_virgl_enabled(g->conf))
+        flags |= GRAPHIC_FLAGS_GL;
+
+    if (virtio_gpu_dmabuf_enabled(g->conf))
+        flags |= GRAPHIC_FLAGS_DMABUF;
+
+    return flags;
+}
+
 static const GraphicHwOps virtio_gpu_ops = {
+    .get_flags = virtio_gpu_get_flags,
     .invalidate = virtio_gpu_invalidate_display,
     .gfx_update = virtio_gpu_update_display,
     .text_update = virtio_gpu_text_update,
diff --git a/hw/display/virtio-vga.c b/hw/display/virtio-vga.c
index 81f776ee36..b071909b68 100644
--- a/hw/display/virtio-vga.c
+++ b/hw/display/virtio-vga.c
@@ -68,7 +68,16 @@ static void virtio_vga_base_gl_block(void *opaque, bool block)
     }
 }
 
+static int virtio_vga_base_get_flags(void *opaque)
+{
+    VirtIOVGABase *vvga = opaque;
+    VirtIOGPUBase *g = vvga->vgpu;
+
+    return g->hw_ops->get_flags(g);
+}
+
 static const GraphicHwOps virtio_vga_base_ops = {
+    .get_flags = virtio_vga_base_get_flags,
     .invalidate = virtio_vga_base_invalidate_display,
     .gfx_update = virtio_vga_base_update_display,
     .text_update = virtio_vga_base_text_update,
diff --git a/hw/vfio/display.c b/hw/vfio/display.c
index 42d67e870b..f04473e3ce 100644
--- a/hw/vfio/display.c
+++ b/hw/vfio/display.c
@@ -335,7 +335,13 @@ static void vfio_display_dmabuf_update(void *opaque)
     }
 }
 
+static int vfio_display_get_flags(void *opaque)
+{
+    return GRAPHIC_FLAGS_GL | GRAPHIC_FLAGS_DMABUF;
+}
+
 static const GraphicHwOps vfio_display_dmabuf_ops = {
+    .get_flags  = vfio_display_get_flags,
     .gfx_update = vfio_display_dmabuf_update,
     .ui_info    = vfio_display_edid_ui_info,
 };
-- 
2.29.0


Re: [PATCH 11/20] ui: add an optional get_flags callback to GraphicHwOps
Posted by Gerd Hoffmann 3 years, 9 months ago
> +static int
> +virtio_gpu_get_flags(void *opaque)
> +{
> +    VirtIOGPUBase *g = opaque;
> +    int flags = GRAPHIC_FLAGS_NONE;
> +
> +    if (virtio_gpu_virgl_enabled(g->conf))
> +        flags |= GRAPHIC_FLAGS_GL;
> +
> +    if (virtio_gpu_dmabuf_enabled(g->conf))
> +        flags |= GRAPHIC_FLAGS_DMABUF;

fbe6ba76ac01 ui: add an optional get_flags callback to GraphicHwOps
ERROR: braces {} are necessary for all arms of this statement
#50: FILE: hw/display/virtio-gpu-base.c:123:
+    if (virtio_gpu_virgl_enabled(g->conf))
[...]

ERROR: braces {} are necessary for all arms of this statement
#53: FILE: hw/display/virtio-gpu-base.c:126:
+    if (virtio_gpu_dmabuf_enabled(g->conf))
[...]

total: 2 errors, 0 warnings, 68 lines checked


Re: [PATCH 11/20] ui: add an optional get_flags callback to GraphicHwOps
Posted by Marc-André Lureau 3 years, 8 months ago
On Wed, Feb 3, 2021 at 7:48 PM Gerd Hoffmann <kraxel@redhat.com> wrote:

> > +static int
> > +virtio_gpu_get_flags(void *opaque)
> > +{
> > +    VirtIOGPUBase *g = opaque;
> > +    int flags = GRAPHIC_FLAGS_NONE;
> > +
> > +    if (virtio_gpu_virgl_enabled(g->conf))
> > +        flags |= GRAPHIC_FLAGS_GL;
> > +
> > +    if (virtio_gpu_dmabuf_enabled(g->conf))
> > +        flags |= GRAPHIC_FLAGS_DMABUF;
>
> fbe6ba76ac01 ui: add an optional get_flags callback to GraphicHwOps
> ERROR: braces {} are necessary for all arms of this statement
> #50: FILE: hw/display/virtio-gpu-base.c:123:
> +    if (virtio_gpu_virgl_enabled(g->conf))
> [...]
>
> ERROR: braces {} are necessary for all arms of this statement
> #53: FILE: hw/display/virtio-gpu-base.c:126:
> +    if (virtio_gpu_dmabuf_enabled(g->conf))
> [...]
>
> total: 2 errors, 0 warnings, 68 lines checked
>

If you queued the series, do you mind squashing a style fix? Otherwise I
can resend.

Thanks
Re: [PATCH 11/20] ui: add an optional get_flags callback to GraphicHwOps
Posted by Gerd Hoffmann 3 years, 8 months ago
On Thu, Feb 04, 2021 at 02:21:02AM +0400, Marc-André Lureau wrote:
> On Wed, Feb 3, 2021 at 7:48 PM Gerd Hoffmann <kraxel@redhat.com> wrote:
> 
> > > +static int
> > > +virtio_gpu_get_flags(void *opaque)
> > > +{
> > > +    VirtIOGPUBase *g = opaque;
> > > +    int flags = GRAPHIC_FLAGS_NONE;
> > > +
> > > +    if (virtio_gpu_virgl_enabled(g->conf))
> > > +        flags |= GRAPHIC_FLAGS_GL;
> > > +
> > > +    if (virtio_gpu_dmabuf_enabled(g->conf))
> > > +        flags |= GRAPHIC_FLAGS_DMABUF;
> >
> > fbe6ba76ac01 ui: add an optional get_flags callback to GraphicHwOps
> > ERROR: braces {} are necessary for all arms of this statement
> > #50: FILE: hw/display/virtio-gpu-base.c:123:
> > +    if (virtio_gpu_virgl_enabled(g->conf))
> > [...]
> >
> > ERROR: braces {} are necessary for all arms of this statement
> > #53: FILE: hw/display/virtio-gpu-base.c:126:
> > +    if (virtio_gpu_dmabuf_enabled(g->conf))
> > [...]
> >
> > total: 2 errors, 0 warnings, 68 lines checked
> >
> 
> If you queued the series, do you mind squashing a style fix? Otherwise I
> can resend.

Whatever is easier for you (note there are more codestyle warnings in
following patches, see patchew report).

take care,
  Gerd