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