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