9d5688decac186fbab901da172d6823fc52c45d7
[mesa.git] / src / mapi / glapi / gen / marshal_XML.py
1 #!/usr/bin/env python
2
3 # Copyright (C) 2012 Intel Corporation
4 #
5 # Permission is hereby granted, free of charge, to any person obtaining a
6 # copy of this software and associated documentation files (the "Software"),
7 # to deal in the Software without restriction, including without limitation
8 # the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 # and/or sell copies of the Software, and to permit persons to whom the
10 # Software is furnished to do so, subject to the following conditions:
11 #
12 # The above copyright notice and this permission notice (including the next
13 # paragraph) shall be included in all copies or substantial portions of the
14 # Software.
15 #
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22 # IN THE SOFTWARE.
23
24 # marshal_XML.py: factory for interpreting XML for the purpose of
25 # building thread marshalling code.
26
27 import gl_XML
28
29
30 class marshal_item_factory(gl_XML.gl_item_factory):
31 """Factory to create objects derived from gl_item containing
32 information necessary to generate thread marshalling code."""
33
34 def create_function(self, element, context):
35 return marshal_function(element, context)
36
37
38 class marshal_function(gl_XML.gl_function):
39 def process_element(self, element):
40 # Do normal processing.
41 super(marshal_function, self).process_element(element)
42
43 # Only do further processing when we see the canonical
44 # function name.
45 if element.get('name') != self.name:
46 return
47
48 # Classify fixed and variable parameters.
49 self.fixed_params = []
50 self.variable_params = []
51 for p in self.parameters:
52 if p.is_padding:
53 continue
54 if p.is_variable_length():
55 self.variable_params.append(p)
56 else:
57 self.fixed_params.append(p)
58
59 # Store the "marshal" attribute, if present.
60 self.marshal = element.get('marshal')
61
62 def marshal_flavor(self):
63 """Find out how this function should be marshalled between
64 client and server threads."""
65 # If a "marshal" attribute was present, that overrides any
66 # determination that would otherwise be made by this function.
67 if self.marshal != None:
68 if self.marshal == 'draw':
69 # TODO: as a temporary measure, do draw functions
70 # synchronously, since they may access client memory
71 # via vertex attribute pointers.
72 return 'sync'
73 return self.marshal
74
75 if self.exec_flavor == 'skip':
76 # Functions marked exec="skip" are not yet implemented in
77 # Mesa, so don't bother trying to marshal them.
78 return 'skip'
79
80 if self.return_type != 'void':
81 return 'sync'
82 for p in self.parameters:
83 if p.is_output:
84 return 'sync'
85 if p.is_pointer() and not (p.count or p.counter):
86 return 'sync'
87 if p.count_parameter_list:
88 # Parameter size is determined by enums; haven't
89 # written logic to handle this yet. TODO: fix.
90 return 'sync'
91 return 'async'