]> xenbits.xensource.com Git - libvirt.git/commitdiff
Generic parsing support for video acceleration
authorPritesh Kothari <Pritesh.Kothari@Sun.COM>
Thu, 3 Sep 2009 08:26:41 +0000 (10:26 +0200)
committerDaniel Veillard <veillard@redhat.com>
Thu, 3 Sep 2009 08:29:35 +0000 (10:29 +0200)
* 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
src/domain_conf.c
src/domain_conf.h

index df31f4a873ff8bc05ca202a0a842d65e9f65bd2b..4bd301a68dabb9ffb430ef87b0447ed5af524d00 100644 (file)
               <ref name="unsignedInt"/>
             </attribute>
           </optional>
+          <optional>
+            <element name="acceleration">
+              <optional>
+                <attribute name="accel3d">
+                  <choice>
+                    <value>yes</value>
+                    <value>no</value>
+                  </choice>
+                </attribute>
+              </optional>
+              <optional>
+                <attribute name="accel2d">
+                  <choice>
+                    <value>yes</value>
+                    <value>no</value>
+                  </choice>
+                </attribute>
+              </optional>
+            </element>
+          </optional>
        </element>
       </optional>
     </element>
index ade3eb40b69a09f817079a2ad12d80da118ddac4..79225a89bb802da086411f67d4297fb136f62b07 100644 (file)
@@ -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, "        <acceleration accel3d='%s'",
+                      def->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, "      </model>\n");
+    } else {
+        virBufferAddLit(buf, "/>\n");
+    }
+
     virBufferAddLit(buf, "    </video>\n");
 
     return 0;
index 0854a0d3bab5025bcf72eeb972604bca5714d183..53d30d24d5655f706662021ee246d9d9d2c490a1 100644 (file)
@@ -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 */