Marius Vlad | 67e9119 | 2021-02-01 13:23:20 +0200 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | |
| 3 | # Copyright 2021 Collabora, Ltd. |
| 4 | # |
| 5 | # Permission is hereby granted, free of charge, to any person obtaining |
| 6 | # a copy of this software and associated documentation files (the |
| 7 | # "Software"), to deal in the Software without restriction, including |
| 8 | # without limitation the rights to use, copy, modify, merge, publish, |
| 9 | # distribute, sublicense, and/or sell copies of the Software, and to |
| 10 | # permit persons to whom the Software is furnished to do so, subject to |
| 11 | # the following conditions: |
| 12 | # |
| 13 | # The above copyright notice and this permission notice (including the |
| 14 | # next paragraph) shall be included in all copies or substantial |
| 15 | # portions of the Software. |
| 16 | # |
| 17 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 18 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 19 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 20 | # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 21 | # BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 22 | # ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 23 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 24 | # SOFTWARE. |
| 25 | |
| 26 | # Helper script that reads drm_fourcc.h and writes a static table with the |
| 27 | # simpler format token modifiers |
| 28 | |
| 29 | import sys |
| 30 | import re |
| 31 | |
| 32 | filename = sys.argv[1] |
| 33 | towrite = sys.argv[2] |
| 34 | |
| 35 | fm_re = { |
| 36 | 'intel': r'^#define I915_FORMAT_MOD_(\w+)', |
| 37 | 'others': r'^#define DRM_FORMAT_MOD_((?:ARM|SAMSUNG|QCOM|VIVANTE|NVIDIA|BROADCOM|ALLWINNER)\w+)\s', |
| 38 | 'vendors': r'^#define DRM_FORMAT_MOD_VENDOR_(\w+)' |
| 39 | } |
| 40 | |
| 41 | def print_fm_intel(f, f_mod): |
| 42 | f.write(' {{ DRM_MODIFIER_INTEL({}, {}) }},\n'.format(f_mod, f_mod)) |
| 43 | |
| 44 | # generic write func |
| 45 | def print_fm(f, vendor, mod, f_name): |
| 46 | f.write(' {{ DRM_MODIFIER({}, {}, {}) }},\n'.format(vendor, mod, f_name)) |
| 47 | |
| 48 | with open(filename, "r") as f: |
| 49 | data = f.read() |
| 50 | for k, v in fm_re.items(): |
| 51 | fm_re[k] = re.findall(v, data, flags=re.M) |
| 52 | |
| 53 | with open(towrite, "w") as f: |
| 54 | f.write('''\ |
| 55 | /* AUTOMATICALLY GENERATED by gen_table_fourcc.py. You should modify |
| 56 | that script instead of adding here entries manually! */ |
| 57 | static const struct drmFormatModifierInfo drm_format_modifier_table[] = { |
| 58 | ''') |
| 59 | f.write(' { DRM_MODIFIER_INVALID(NONE, INVALID_MODIFIER) },\n') |
| 60 | f.write(' { DRM_MODIFIER_LINEAR(NONE, LINEAR) },\n') |
| 61 | |
| 62 | for entry in fm_re['intel']: |
| 63 | print_fm_intel(f, entry) |
| 64 | |
| 65 | for entry in fm_re['others']: |
| 66 | (vendor, mod) = entry.split('_', 1) |
Dennis Tsiang | bd26b61 | 2021-09-22 14:53:50 +0100 | [diff] [blame] | 67 | if vendor == 'ARM' and (mod == 'TYPE_AFBC' or mod == 'TYPE_MISC' or mod == 'TYPE_AFRC'): |
Marius Vlad | 67e9119 | 2021-02-01 13:23:20 +0200 | [diff] [blame] | 68 | continue |
| 69 | print_fm(f, vendor, mod, mod) |
| 70 | |
| 71 | f.write('''\ |
| 72 | }; |
| 73 | ''') |
| 74 | |
| 75 | f.write('''\ |
| 76 | static const struct drmFormatModifierVendorInfo drm_format_modifier_vendor_table[] = { |
| 77 | ''') |
| 78 | |
| 79 | for entry in fm_re['vendors']: |
| 80 | f.write(" {{ DRM_FORMAT_MOD_VENDOR_{}, \"{}\" }},\n".format(entry, entry)) |
| 81 | |
| 82 | f.write('''\ |
| 83 | }; |
| 84 | ''') |