From 6aa576cda7592015f85676a43409b6d4c03ad892 Mon Sep 17 00:00:00 2001 From: Pritesh Kothari Date: Thu, 3 Sep 2009 10:26:41 +0200 Subject: [PATCH] Generic parsing support for video acceleration * docs/schemas/domain.rng: augment the video model with an optional acceleration element with optional accel2d and accel3d flags * src/domain_conf.c src/domain_conf.h: exten the virDomainVideoDef structure with an optional accel field, virDomainVideoAccelDefParseXML and virDomainVideoAccelDefFormat functions to parse and serialize the structure. --- docs/schemas/domain.rng | 20 ++++++++++++ src/domain_conf.c | 70 ++++++++++++++++++++++++++++++++++++++++- src/domain_conf.h | 9 ++++++ 3 files changed, 98 insertions(+), 1 deletion(-) diff --git a/docs/schemas/domain.rng b/docs/schemas/domain.rng index df31f4a873..4bd301a68d 100644 --- a/docs/schemas/domain.rng +++ b/docs/schemas/domain.rng @@ -819,6 +819,26 @@ + + + + + + yes + no + + + + + + + yes + no + + + + + diff --git a/src/domain_conf.c b/src/domain_conf.c index ade3eb40b6..79225a89bb 100644 --- a/src/domain_conf.c +++ b/src/domain_conf.c @@ -391,6 +391,7 @@ void virDomainVideoDefFree(virDomainVideoDefPtr def) if (!def) return; + VIR_FREE(def->accel); VIR_FREE(def); } @@ -1777,6 +1778,52 @@ virDomainVideoDefaultType(virDomainDefPtr def) } } +static virDomainVideoAccelDefPtr +virDomainVideoAccelDefParseXML(virConnectPtr conn, const xmlNodePtr node) { + xmlNodePtr cur; + virDomainVideoAccelDefPtr def; + char *support3d = NULL; + char *support2d = NULL; + + cur = node->children; + while (cur != NULL) { + if (cur->type == XML_ELEMENT_NODE) { + if ((support3d == NULL) && (support2d == NULL) && + xmlStrEqual(cur->name, BAD_CAST "acceleration")) { + support3d = virXMLPropString(cur, "accel3d"); + support2d = virXMLPropString(cur, "accel2d"); + } + } + cur = cur->next; + } + + if ((support3d == NULL) && (support2d == NULL)) + return(NULL); + + if (VIR_ALLOC(def) < 0) { + virReportOOMError(conn); + return NULL; + } + + if (support3d) { + if (STREQ(support3d, "yes")) + def->support3d = 1; + else + def->support3d = 0; + VIR_FREE(support3d); + } + + if (support2d) { + if (STREQ(support2d, "yes")) + def->support2d = 1; + else + def->support2d = 0; + VIR_FREE(support2d); + } + + return def; +} + static virDomainVideoDefPtr virDomainVideoDefParseXML(virConnectPtr conn, const xmlNodePtr node, @@ -1801,6 +1848,7 @@ virDomainVideoDefParseXML(virConnectPtr conn, type = virXMLPropString(cur, "type"); vram = virXMLPropString(cur, "vram"); heads = virXMLPropString(cur, "heads"); + def->accel = virDomainVideoAccelDefParseXML(conn, cur); } } cur = cur->next; @@ -3852,6 +3900,19 @@ virDomainSoundDefFormat(virConnectPtr conn, return 0; } + +static void +virDomainVideoAccelDefFormat(virBufferPtr buf, + virDomainVideoAccelDefPtr def) +{ + virBufferVSprintf(buf, " support3d ? "yes" : "no"); + virBufferVSprintf(buf, " accel2d='%s'", + def->support2d ? "yes" : "no"); + virBufferAddLit(buf, "/>\n"); +} + + static int virDomainVideoDefFormat(virConnectPtr conn, virBufferPtr buf, @@ -3872,7 +3933,14 @@ virDomainVideoDefFormat(virConnectPtr conn, virBufferVSprintf(buf, " vram='%u'", def->vram); if (def->heads) virBufferVSprintf(buf, " heads='%u'", def->heads); - virBufferAddLit(buf, "/>\n"); + if (def->accel) { + virBufferAddLit(buf, ">\n"); + virDomainVideoAccelDefFormat(buf, def->accel); + virBufferAddLit(buf, " \n"); + } else { + virBufferAddLit(buf, "/>\n"); + } + virBufferAddLit(buf, " \n"); return 0; diff --git a/src/domain_conf.h b/src/domain_conf.h index 0854a0d3ba..53d30d24d5 100644 --- a/src/domain_conf.h +++ b/src/domain_conf.h @@ -309,12 +309,21 @@ enum virDomainVideoType { }; +typedef struct _virDomainVideoAccelDef virDomainVideoAccelDef; +typedef virDomainVideoAccelDef *virDomainVideoAccelDefPtr; +struct _virDomainVideoAccelDef { + int support3d : 1; + int support2d : 1; +}; + + typedef struct _virDomainVideoDef virDomainVideoDef; typedef virDomainVideoDef *virDomainVideoDefPtr; struct _virDomainVideoDef { int type; unsigned int vram; unsigned int heads; + virDomainVideoAccelDefPtr accel; }; /* 3 possible graphics console modes */ -- GitLab