mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2026-04-13 08:22:16 -04:00
render/pixel_format: generate tables via kdfs
Leverage go-kdfs [1] to automatically generate tables (basic info for single-plane formats, YUV list, opaque list). This allows us to drop our manually written tables and check format info in a kdfs viewer (the kdfs CLI or pixfmtdb) to ensure it's correct. Add a new gen-pixel-format ninja target to regenerate tables. Tables are checked in Git instead of being generated at build-time, so that the kdfs CLI isn't a build-time dependency. block_width/block_height are now never zero. [1]: https://gitlab.freedesktop.org/emersion/go-kdf
This commit is contained in:
parent
34ffeaa4ef
commit
e69e1b5f7a
5 changed files with 634 additions and 282 deletions
68
render/gen_pixel_format.sh
Executable file
68
render/gen_pixel_format.sh
Executable file
|
|
@ -0,0 +1,68 @@
|
|||
#!/bin/sh -eu
|
||||
#
|
||||
# usage: gen_pixel_format.sh pixel_format_table.c
|
||||
|
||||
KDFS=${KDFS:-kdfs}
|
||||
|
||||
output_file="$1"
|
||||
|
||||
gen_info() {
|
||||
"$KDFS" show --json 'DRM_FORMAT_*' | jq -r '
|
||||
to_entries[]
|
||||
| select((.value.bytes_plane | length) == 1)
|
||||
|
|
||||
" {\n" +
|
||||
" .drm_format = \(.key),\n" +
|
||||
" .bytes_per_block = \(.value.bytes_plane[0]),\n" +
|
||||
" .block_width = \(.value.texel_block_dimension[0]),\n" +
|
||||
" .block_height = \(.value.texel_block_dimension[1]),\n" +
|
||||
" },"
|
||||
'
|
||||
}
|
||||
|
||||
gen_opaque() {
|
||||
"$KDFS" show --json 'DRM_FORMAT_*' | jq -r '
|
||||
to_entries[]
|
||||
| select(any(.value.sample_info[]; .channel == "a") | not)
|
||||
| " case \(.key):"
|
||||
'
|
||||
}
|
||||
|
||||
gen_ycbcr() {
|
||||
"$KDFS" show --json 'DRM_FORMAT_*' | jq -r '
|
||||
to_entries[]
|
||||
| select(.value.color_model == "yuvsda")
|
||||
| " case \(.key):"
|
||||
'
|
||||
}
|
||||
|
||||
cat >"$output_file" << EOF
|
||||
// Generated by gen_pixel_formats.sh - DO NOT EDIT
|
||||
|
||||
#include <drm_fourcc.h>
|
||||
#include "render/pixel_format.h"
|
||||
|
||||
const struct wlr_pixel_format_info pixel_format_info[] = {
|
||||
$(gen_info)
|
||||
};
|
||||
|
||||
const size_t pixel_format_info_len = sizeof(pixel_format_info) / sizeof(pixel_format_info[0]);
|
||||
|
||||
bool pixel_format_is_opaque(uint32_t format) {
|
||||
switch (format) {
|
||||
$(gen_opaque)
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool pixel_format_is_ycbcr(uint32_t format) {
|
||||
switch (format) {
|
||||
$(gen_ycbcr)
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
EOF
|
||||
Loading…
Add table
Add a link
Reference in a new issue