9c6c51
From e6b37b93dd6e7ec133378aec04dd9c96e0ab57cb Mon Sep 17 00:00:00 2001
9c6c51
Message-Id: <e6b37b93dd6e7ec133378aec04dd9c96e0ab57cb@dist-git>
9c6c51
From: Erik Skultety <eskultet@redhat.com>
9c6c51
Date: Thu, 19 Jul 2018 15:04:00 +0200
9c6c51
Subject: [PATCH] conf: Introduce virDomainGraphicsDefHasOpenGL helper
9c6c51
MIME-Version: 1.0
9c6c51
Content-Type: text/plain; charset=UTF-8
9c6c51
Content-Transfer-Encoding: 8bit
9c6c51
9c6c51
A simple helper which will loop through all the graphics elements and
9c6c51
checks whether at least one of them enables OpenGL support, either by
9c6c51
containing <gl enable='yes'/> or being of type 'egl-headless'.
9c6c51
9c6c51
Signed-off-by: Erik Skultety <eskultet@redhat.com>
9c6c51
Acked-by: Michal Privoznik <mprivozn@redhat.com>
9c6c51
Reviewed-by: Ján Tomko <jtomko@redhat.com>
9c6c51
(cherry picked from commit 425329181f1db19f34a8ffffc1da9afa7f323f13)
9c6c51
9c6c51
https://bugzilla.redhat.com/show_bug.cgi?id=1475770
9c6c51
Signed-off-by: Erik Skultety <eskultet@redhat.com>
9c6c51
Reviewed-by: Ján Tomko <jtomko@redhat.com>
9c6c51
---
9c6c51
 src/conf/domain_conf.c   | 43 ++++++++++++++++++++++++++++++++++++++++
9c6c51
 src/conf/domain_conf.h   |  3 +++
9c6c51
 src/libvirt_private.syms |  1 +
9c6c51
 3 files changed, 47 insertions(+)
9c6c51
9c6c51
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
9c6c51
index fa4dfafcff..08654ab41d 100644
9c6c51
--- a/src/conf/domain_conf.c
9c6c51
+++ b/src/conf/domain_conf.c
9c6c51
@@ -30284,3 +30284,46 @@ virDomainDefHasManagedPR(const virDomainDef *def)
9c6c51
 
9c6c51
     return false;
9c6c51
 }
9c6c51
+
9c6c51
+
9c6c51
+/**
9c6c51
+ * virDomainGraphicsDefHasOpenGL:
9c6c51
+ * @def: domain definition
9c6c51
+ *
9c6c51
+ * Returns true if a domain config contains at least one <graphics> element
9c6c51
+ * with OpenGL support enabled, false otherwise.
9c6c51
+ */
9c6c51
+bool
9c6c51
+virDomainGraphicsDefHasOpenGL(const virDomainDef *def)
9c6c51
+{
9c6c51
+    size_t i;
9c6c51
+
9c6c51
+    for (i = 0; i < def->ngraphics; i++) {
9c6c51
+        virDomainGraphicsDefPtr graphics = def->graphics[i];
9c6c51
+
9c6c51
+        /* we only care about OpenGL support for a given type here */
9c6c51
+        switch (graphics->type) {
9c6c51
+        case VIR_DOMAIN_GRAPHICS_TYPE_VNC:
9c6c51
+        case VIR_DOMAIN_GRAPHICS_TYPE_RDP:
9c6c51
+        case VIR_DOMAIN_GRAPHICS_TYPE_DESKTOP:
9c6c51
+            continue;
9c6c51
+        case VIR_DOMAIN_GRAPHICS_TYPE_SDL:
9c6c51
+            if (graphics->data.sdl.gl == VIR_TRISTATE_BOOL_YES)
9c6c51
+                return true;
9c6c51
+
9c6c51
+            continue;
9c6c51
+        case VIR_DOMAIN_GRAPHICS_TYPE_SPICE:
9c6c51
+            if (graphics->data.spice.gl == VIR_TRISTATE_BOOL_YES)
9c6c51
+                return true;
9c6c51
+
9c6c51
+            continue;
9c6c51
+        case VIR_DOMAIN_GRAPHICS_TYPE_EGL_HEADLESS:
9c6c51
+            return true;
9c6c51
+
9c6c51
+        case VIR_DOMAIN_GRAPHICS_TYPE_LAST:
9c6c51
+            break;
9c6c51
+        }
9c6c51
+    }
9c6c51
+
9c6c51
+    return false;
9c6c51
+}
9c6c51
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
9c6c51
index 26f75b15d0..3deda1d978 100644
9c6c51
--- a/src/conf/domain_conf.h
9c6c51
+++ b/src/conf/domain_conf.h
9c6c51
@@ -3642,4 +3642,7 @@ virDomainDiskGetDetectZeroesMode(virDomainDiskDiscard discard,
9c6c51
 bool
9c6c51
 virDomainDefHasManagedPR(const virDomainDef *def);
9c6c51
 
9c6c51
+bool
9c6c51
+virDomainGraphicsDefHasOpenGL(const virDomainDef *def);
9c6c51
+
9c6c51
 #endif /* __DOMAIN_CONF_H */
9c6c51
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
9c6c51
index 5bd08d3f67..86846f3b08 100644
9c6c51
--- a/src/libvirt_private.syms
9c6c51
+++ b/src/libvirt_private.syms
9c6c51
@@ -368,6 +368,7 @@ virDomainGetFilesystemForTarget;
9c6c51
 virDomainGraphicsAuthConnectedTypeFromString;
9c6c51
 virDomainGraphicsAuthConnectedTypeToString;
9c6c51
 virDomainGraphicsDefFree;
9c6c51
+virDomainGraphicsDefHasOpenGL;
9c6c51
 virDomainGraphicsGetListen;
9c6c51
 virDomainGraphicsListenAppendAddress;
9c6c51
 virDomainGraphicsListenAppendSocket;
9c6c51
-- 
9c6c51
2.18.0
9c6c51