14babd585Smrg#!/usr/bin/env python3 24babd585Smrg 34babd585Smrg# Copyright 2021 Collabora, Ltd. 44babd585Smrg# 54babd585Smrg# Permission is hereby granted, free of charge, to any person obtaining 64babd585Smrg# a copy of this software and associated documentation files (the 74babd585Smrg# "Software"), to deal in the Software without restriction, including 84babd585Smrg# without limitation the rights to use, copy, modify, merge, publish, 94babd585Smrg# distribute, sublicense, and/or sell copies of the Software, and to 104babd585Smrg# permit persons to whom the Software is furnished to do so, subject to 114babd585Smrg# the following conditions: 124babd585Smrg# 134babd585Smrg# The above copyright notice and this permission notice (including the 144babd585Smrg# next paragraph) shall be included in all copies or substantial 154babd585Smrg# portions of the Software. 164babd585Smrg# 174babd585Smrg# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 184babd585Smrg# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 194babd585Smrg# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 204babd585Smrg# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 214babd585Smrg# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 224babd585Smrg# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 234babd585Smrg# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 244babd585Smrg# SOFTWARE. 254babd585Smrg 264babd585Smrg# Helper script that reads drm_fourcc.h and writes a static table with the 274babd585Smrg# simpler format token modifiers 284babd585Smrg 294babd585Smrgimport sys 304babd585Smrgimport re 314babd585Smrg 324babd585Smrgfilename = sys.argv[1] 334babd585Smrgtowrite = sys.argv[2] 344babd585Smrg 354babd585Smrgfm_re = { 364babd585Smrg 'intel': r'^#define I915_FORMAT_MOD_(\w+)', 374babd585Smrg 'others': r'^#define DRM_FORMAT_MOD_((?:ARM|SAMSUNG|QCOM|VIVANTE|NVIDIA|BROADCOM|ALLWINNER)\w+)\s', 384babd585Smrg 'vendors': r'^#define DRM_FORMAT_MOD_VENDOR_(\w+)' 394babd585Smrg} 404babd585Smrg 414babd585Smrgdef print_fm_intel(f, f_mod): 424babd585Smrg f.write(' {{ DRM_MODIFIER_INTEL({}, {}) }},\n'.format(f_mod, f_mod)) 434babd585Smrg 444babd585Smrg# generic write func 454babd585Smrgdef print_fm(f, vendor, mod, f_name): 464babd585Smrg f.write(' {{ DRM_MODIFIER({}, {}, {}) }},\n'.format(vendor, mod, f_name)) 474babd585Smrg 484babd585Smrgwith open(filename, "r") as f: 494babd585Smrg data = f.read() 504babd585Smrg for k, v in fm_re.items(): 514babd585Smrg fm_re[k] = re.findall(v, data, flags=re.M) 524babd585Smrg 534babd585Smrgwith open(towrite, "w") as f: 544babd585Smrg f.write('''\ 554babd585Smrg/* AUTOMATICALLY GENERATED by gen_table_fourcc.py. You should modify 564babd585Smrg that script instead of adding here entries manually! */ 574babd585Smrgstatic const struct drmFormatModifierInfo drm_format_modifier_table[] = { 584babd585Smrg''') 590ed5401bSmrg f.write(' { DRM_MODIFIER_INVALID(NONE, INVALID) },\n') 604babd585Smrg f.write(' { DRM_MODIFIER_LINEAR(NONE, LINEAR) },\n') 614babd585Smrg 624babd585Smrg for entry in fm_re['intel']: 634babd585Smrg print_fm_intel(f, entry) 644babd585Smrg 654babd585Smrg for entry in fm_re['others']: 664babd585Smrg (vendor, mod) = entry.split('_', 1) 6749ef06a4Smrg if vendor == 'ARM' and (mod == 'TYPE_AFBC' or mod == 'TYPE_MISC' or mod == 'TYPE_AFRC'): 684babd585Smrg continue 694babd585Smrg print_fm(f, vendor, mod, mod) 704babd585Smrg 714babd585Smrg f.write('''\ 724babd585Smrg}; 734babd585Smrg''') 744babd585Smrg 754babd585Smrg f.write('''\ 764babd585Smrgstatic const struct drmFormatModifierVendorInfo drm_format_modifier_vendor_table[] = { 774babd585Smrg''') 784babd585Smrg 794babd585Smrg for entry in fm_re['vendors']: 804babd585Smrg f.write(" {{ DRM_FORMAT_MOD_VENDOR_{}, \"{}\" }},\n".format(entry, entry)) 814babd585Smrg 824babd585Smrg f.write('''\ 834babd585Smrg}; 844babd585Smrg''') 85