glapi: Read GLES information from XML.
authorPaul Berry <stereotype441@gmail.com>
Wed, 10 Oct 2012 23:48:08 +0000 (16:48 -0700)
committerPaul Berry <stereotype441@gmail.com>
Tue, 16 Oct 2012 19:03:55 +0000 (12:03 -0700)
Tested-by: Matt Turner <mattst88@gmail.com>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
src/mapi/glapi/gen/gl_XML.py

index f956730f2e07c68781046b6349ac78d470b10a17..ef7ed519b5a29a92fa7c0b68c71bcac25da7bd57 100644 (file)
@@ -25,6 +25,7 @@
 # Authors:
 #    Ian Romanick <idr@us.ibm.com>
 
+from decimal import Decimal
 import libxml2
 import re, sys, string
 import typeexpr
@@ -606,6 +607,16 @@ class gl_function( gl_item ):
         self.initialized = 0
         self.images = []
 
+        # self.entry_point_api_map[name][api] is a decimal value
+        # indicating the earliest version of the given API in which
+        # each entry point exists.  Every entry point is included in
+        # the first level of the map; the second level of the map only
+        # lists APIs which contain the entry point in at least one
+        # version.  For example,
+        # self.entry_point_gles_map['ClipPlanex'] == { 'es1':
+        # Decimal('1.1') }.
+        self.entry_point_api_map = {}
+
         self.assign_offset = 0
 
         self.static_entry_points = []
@@ -634,6 +645,14 @@ class gl_function( gl_item ):
             self.static_entry_points.append(name)
 
         self.entry_points.append( name )
+
+        self.entry_point_api_map[name] = {}
+        for api in ('es1', 'es2'):
+            version_str = element.nsProp(api, None)
+            assert version_str is not None
+            if version_str != 'none':
+                self.entry_point_api_map[name][api] = Decimal(version_str)
+
         if alias:
             true_name = alias
         else:
@@ -779,6 +798,22 @@ class gl_function( gl_item ):
         else:
             return "_dispatch_stub_%u" % (self.offset)
 
+    def entry_points_for_api_version(self, api, version = None):
+        """Return a list of the entry point names for this function
+        which are supported in the given API (and optionally, version).
+
+        Use the decimal.Decimal type to precisely express non-integer
+        versions.
+        """
+        result = []
+        for entry_point, api_to_ver in self.entry_point_api_map.iteritems():
+            if api not in api_to_ver:
+                continue
+            if version is not None and version < api_to_ver[api]:
+                continue
+            result.append(entry_point)
+        return result
+
 
 class gl_item_factory(object):
     """Factory to create objects derived from gl_item."""
@@ -825,6 +860,19 @@ class gl_api(object):
 
         self.functions_by_name = functions_by_name
 
+    def filter_functions_by_api(self, api, version = None):
+        """Filter out entry points not in the given API (or
+        optionally, not in the given version of the given API).
+        """
+        functions_by_name = {}
+        for func in self.functions_by_name.itervalues():
+            entry_points = func.entry_points_for_api_version(api, version)
+            if entry_points:
+                func.filter_entry_points(entry_points)
+                functions_by_name[func.name] = func
+
+        self.functions_by_name = functions_by_name
+
     def process_element(self, doc):
         element = doc.children
         while element.type != "element" or element.name != "OpenGLAPI":