xserver/include/edid.h
Tautvis 2d72f9e192
Some checks failed
Build X servers / ubuntu-fetch-pkg (push) Has been cancelled
Build X servers / xserver-build-ubuntu-no-gbm (push) Has been cancelled
Build X servers / xserver-build-ubuntu (push) Has been cancelled
Build X servers / abi-changes-check (push) Has been cancelled
Build X servers / xserver-build-ubuntu-debug (push) Has been cancelled
Build X servers / xserver-build-ubuntu-valgrind (push) Has been cancelled
Build X servers / ubuntu-deps-image (push) Has been cancelled
Build X servers / build-sdk-image (push) Has been cancelled
Build X servers / drivers-build-ubuntu (input-elographics:25.0.0) (push) Has been cancelled
Build X servers / drivers-build-ubuntu (input-evdev:25.0.0) (push) Has been cancelled
Build X servers / drivers-build-ubuntu (input-joystick:25.0.0) (push) Has been cancelled
Build X servers / drivers-build-ubuntu (input-keyboard:25.0.0) (push) Has been cancelled
Build X servers / drivers-build-ubuntu (input-libinput:25.0.0) (push) Has been cancelled
Build X servers / drivers-build-ubuntu (input-mouse:25.0.0) (push) Has been cancelled
Build X servers / drivers-build-ubuntu (input-synaptics:25.0.0) (push) Has been cancelled
Build X servers / drivers-build-ubuntu (input-vmmouse:25.0.0) (push) Has been cancelled
Build X servers / drivers-build-ubuntu (input-void:25.0.0) (push) Has been cancelled
Build X servers / drivers-build-ubuntu (input-wacom:25.0.0) (push) Has been cancelled
Build X servers / drivers-build-ubuntu (video-amdgpu:25.0.0) (push) Has been cancelled
Build X servers / drivers-build-ubuntu (video-apm:25.0.0) (push) Has been cancelled
Build X servers / drivers-build-ubuntu (video-ark:25.0.0) (push) Has been cancelled
Build X servers / drivers-build-ubuntu (video-ast:25.0.0) (push) Has been cancelled
Build X servers / drivers-build-ubuntu (video-ati:25.0.0) (push) Has been cancelled
Build X servers / drivers-build-ubuntu (video-chips:25.0.0) (push) Has been cancelled
Build X servers / drivers-build-ubuntu (video-cirrus:25.0.0) (push) Has been cancelled
Build X servers / drivers-build-ubuntu (video-dummy:25.0.0) (push) Has been cancelled
Build X servers / drivers-build-ubuntu (video-fbdev:25.0.0) (push) Has been cancelled
Build X servers / drivers-build-ubuntu (video-freedreno:25.0.0) (push) Has been cancelled
Build X servers / drivers-build-ubuntu (video-geode:25.0.0) (push) Has been cancelled
Build X servers / drivers-build-ubuntu (video-i128:25.0.0) (push) Has been cancelled
Build X servers / drivers-build-ubuntu (video-i740:25.0.0) (push) Has been cancelled
Build X servers / drivers-build-ubuntu (video-intel:25.0.1) (push) Has been cancelled
Build X servers / drivers-build-ubuntu (video-mach64:25.0.0) (push) Has been cancelled
Build X servers / drivers-build-ubuntu (video-mga:25.0.0) (push) Has been cancelled
Build X servers / drivers-build-ubuntu (video-neomagic:25.0.0) (push) Has been cancelled
Build X servers / drivers-build-ubuntu (video-nested:25.0.0) (push) Has been cancelled
Build X servers / drivers-build-ubuntu (video-nouveau:25.0.0) (push) Has been cancelled
Build X servers / drivers-build-ubuntu (video-nv:25.0.0) (push) Has been cancelled
Build X servers / drivers-build-ubuntu (video-omap:25.0.0) (push) Has been cancelled
Build X servers / drivers-build-ubuntu (video-qxl:25.0.0) (push) Has been cancelled
Build X servers / drivers-build-ubuntu (video-r128:25.0.0) (push) Has been cancelled
Build X servers / drivers-build-ubuntu (video-rendition:25.0.0) (push) Has been cancelled
Build X servers / drivers-build-ubuntu (video-s3virge:25.0.0) (push) Has been cancelled
Build X servers / drivers-build-ubuntu (video-savage:25.0.0) (push) Has been cancelled
Build X servers / drivers-build-ubuntu (video-siliconmotion:25.0.0) (push) Has been cancelled
Build X servers / drivers-build-ubuntu (video-sis:25.0.0) (push) Has been cancelled
Build X servers / drivers-build-ubuntu (video-sisusb:25.0.0) (push) Has been cancelled
Build X servers / drivers-build-ubuntu (video-suncg14:25.0.0) (push) Has been cancelled
Build X servers / drivers-build-ubuntu (video-suncg3:25.0.0) (push) Has been cancelled
Build X servers / drivers-build-ubuntu (video-suncg6:25.0.0) (push) Has been cancelled
Build X servers / drivers-build-ubuntu (video-sunffb:25.0.0) (push) Has been cancelled
Build X servers / drivers-build-ubuntu (video-sunleo:25.0.0) (push) Has been cancelled
Build X servers / drivers-build-ubuntu (video-suntcx:25.0.0) (push) Has been cancelled
Build X servers / drivers-build-ubuntu (video-tdfx:25.0.0) (push) Has been cancelled
Build X servers / drivers-build-ubuntu (video-trident:25.0.0) (push) Has been cancelled
Build X servers / drivers-build-ubuntu (video-v4l:25.0.1) (push) Has been cancelled
Build X servers / drivers-build-ubuntu (video-vbox:25.0.0) (push) Has been cancelled
Build X servers / drivers-build-ubuntu (video-vesa:25.0.0) (push) Has been cancelled
Build X servers / drivers-build-ubuntu (video-vmware:25.0.0) (push) Has been cancelled
Build X servers / drivers-build-ubuntu (video-voodoo:25.0.0) (push) Has been cancelled
Build X servers / drivers-build-ubuntu (video-xgi:25.0.0) (push) Has been cancelled
Build X servers / xserver-build-mingw32-ubuntu (push) Has been cancelled
Build X servers / xserver-build-macos (push) Has been cancelled
Build X servers / xserver-build-freebsd (push) Has been cancelled
Build X servers / xserver-build-dragonflybsd (push) Has been cancelled
Build X servers / xserver-build-netbsd (push) Has been cancelled
Build X servers / xserver-build-solaris (push) Has been cancelled
Build X servers / xserver-build-openbsd (push) Has been cancelled
Build X servers / xserver-build-hurd (push) Has been cancelled
Build X servers / xserver-build-alpine (push) Has been cancelled
Build X servers / gentoo-deps-image (push) Has been cancelled
Build X servers / xserver-build-gentoo (push) Has been cancelled
Build X servers / xserver-build-rhel (10) (push) Has been cancelled
Build X servers / xserver-build-rhel (9) (push) Has been cancelled
Build X servers / xserver-build-cygwin (push) Has been cancelled
Build X servers / xserver-build-arch (push) Has been cancelled
Build X servers / xserver-build-qemu-user (http://deb.debian.org/debian, armhf, qemu-arm-static, bookworm) (push) Has been cancelled
Build X servers / xserver-build-qemu-user (http://deb.debian.org/debian, mipsel, qemu-mipsel-static, bookworm) (push) Has been cancelled
Build X servers / xserver-build-qemu-user (http://deb.debian.org/debian, ppc64el, qemu-ppc64le-static, bookworm) (push) Has been cancelled
Build X servers / xserver-build-qemu-user (http://deb.debian.org/debian-ports, alpha, qemu-alpha-static, unstable) (push) Has been cancelled
Build X servers / xserver-build-qemu-user (http://deb.debian.org/debian-ports, sparc64, qemu-sparc64-static, unstable) (push) Has been cancelled
Build X servers / Check Signed-Off-By (push) Has been cancelled
Build X servers / Release pushed tag (push) Has been cancelled
check PRs for merge conflicts / notify (push) Has been cancelled
xfree86: ddc: parse CTA-861-G HDR static metadata + colorimetry data blocks
Add xf86DoInterpretHDRMetadata(), which walks the EDID's CTA/CEA
extension data blocks and fills in a new struct monitor_hdr_data
(tail-appended field xf86Monitor::hdr) from the two blocks a display
uses to advertise HDR support:

 - the Colorimetry Data Block (tag 5): which extended gamuts/transfer
   spaces the display accepts (BT.2020 RGB/YCC/cYCC, opRGB, xvYCC,
   ICtCp, ...), exposed via is_CTA_CDB_*() bit-test macros.
 - the HDR Static Metadata Data Block (tag 6): supported EOTFs
   (traditional SDR/HDR gamma, SMPTE ST.2084/PQ, HLG) plus the
   desired content min/max/max-frame-average luminance, decoded with
   the CTA-861-G power-law formulas.

Covered by a new EDID unit test (test/ddc-tests.c) using real captured
EDIDs from four displays (Samsung Q800T, MSI MAG321CURV, HP 27 QD, and
a QEMU virtual display as the "no HDR block present" negative case),
asserting the parsed colorimetry/luminance values match known-good
figures for each.

This is a standalone prerequisite for HDR support, independent of any
particular rendering-pipeline design: cepelinas9000's HDR work
(https://github.com/cepelinas9000/xserver/tree/wip/x11hdrV2) needs to
know a display's HDR/colorimetry capabilities before doing anything
else, and this is useful on its own for any HDR/wide-gamut detection
regardless of how the rest of the pipeline ends up looking.

Extracted (with typo/whitespace cleanup, no logic changes) from
cepelinas9000's wip/x11hdrV2 branch, commit 159a6f484a, for standalone
review ahead of the larger HDR effort.

Note for review: struct monitor_hdr_data is added as a new field at
the tail of the public xf86Monitor struct (include/edid.h) - additive
only, no existing field shifts.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2026-08-24 13:50:42 +02:00

269 lines
6.7 KiB
C

/*
* edid.h: defines to parse an EDID block
*
* This file contains all information to interpret a standard EDIC block
* transmitted by a display device via DDC (Display Data Channel). So far
* there is no information to deal with optional EDID blocks.
* DDC is a Trademark of VESA (Video Electronics Standard Association).
*
* Copyright 1998 by Egbert Eich <Egbert.Eich@Physik.TU-Darmstadt.DE>
*/
#ifndef _EDID_H_
#define _EDID_H_
#include <stdbool.h>
#include <stdint.h>
#include <X11/Xmd.h>
#include <X11/Xfuncproto.h>
#define STD_TIMINGS 8
#define DET_TIMINGS 4
/* input type */
#define DIGITAL(x) (x)
/* Msc stuff EDID Ver > 1.1 */
#define PREFERRED_TIMING_MODE(x) ((x) & 0x2)
#define GTF_SUPPORTED(x) ((x) & 0x1)
struct vendor {
char name[4];
int prod_id;
unsigned int serial;
int week;
int year;
};
struct edid_version {
int version;
int revision;
};
struct disp_features {
unsigned int input_type:1;
unsigned int input_voltage:2;
unsigned int input_setup:1;
unsigned int input_sync:5;
unsigned int input_dfp:1;
unsigned int input_bpc:3;
unsigned int input_interface:4;
/* 15 bit hole */
int hsize;
int vsize;
float gamma;
unsigned int dpms:3;
unsigned int display_type:2;
unsigned int msc:3;
float redx;
float redy;
float greenx;
float greeny;
float bluex;
float bluey;
float whitex;
float whitey;
};
struct established_timings {
uint8_t t1;
uint8_t t2;
uint8_t t_manu;
};
struct std_timings {
int hsize;
int vsize;
int refresh;
CARD16 id;
};
struct detailed_timings {
int clock;
int h_active;
int h_blanking;
int v_active;
int v_blanking;
int h_sync_off;
int h_sync_width;
int v_sync_off;
int v_sync_width;
int h_size;
int v_size;
int h_border;
int v_border;
unsigned int interlaced:1;
unsigned int stereo:2;
unsigned int sync:2;
unsigned int misc:2;
unsigned int stereo_1:1;
};
#define DT 0
#define DS_SERIAL 0xFF
#define DS_ASCII_STR 0xFE
#define DS_NAME 0xFC
#define DS_RANGES 0xFD
#define DS_WHITE_P 0xFB
#define DS_STD_TIMINGS 0xFA
#define DS_CMD 0xF9
#define DS_CVT 0xF8
#define DS_EST_III 0xF7
#define DS_DUMMY 0x10
#define DS_UNKOWN 0x100 /* type is an int */
#define DS_VENDOR 0x101
#define DS_VENDOR_MAX 0x110
/*
* Display range limit Descriptor of EDID version1, reversion 4
*/
typedef enum {
DR_DEFAULT_GTF,
DR_LIMITS_ONLY,
DR_SECONDARY_GTF,
DR_CVT_SUPPORTED = 4,
} DR_timing_flags;
struct monitor_ranges {
int min_v;
int max_v;
int min_h;
int max_h;
int max_clock; /* in mhz */
int gtf_2nd_f;
int gtf_2nd_c;
int gtf_2nd_m;
int gtf_2nd_k;
int gtf_2nd_j;
int max_clock_khz;
int maxwidth; /* in pixels */
char supported_aspect;
char preferred_aspect;
char supported_blanking;
char supported_scaling;
int preferred_refresh; /* in hz */
DR_timing_flags display_range_timing_flags;
};
struct whitePoints {
int index;
float white_x;
float white_y;
float white_gamma;
};
struct cvt_timings {
int width;
int height;
int rate;
int rates;
};
/*
* Be careful when adding new sections; this structure can't grow, it's
* embedded in the middle of xf86Monitor which is ABI. Sizes below are
* in bytes, for ILP32 systems. If all else fails just copy the section
* literally like serial and friends.
*/
struct detailed_monitor_section {
int type;
union {
struct detailed_timings d_timings; /* 56 */
uint8_t serial[13];
uint8_t ascii_data[13];
uint8_t name[13];
struct monitor_ranges ranges; /* 60 */
struct std_timings std_t[5]; /* 80 */
struct whitePoints wp[2]; /* 32 */
/* color management data */
struct cvt_timings cvt[4]; /* 64 */
uint8_t est_iii[6]; /* 6 */
} section; /* max: 80 */
};
/* flags */
#define MONITOR_EDID_COMPLETE_RAWDATA 0x01
/* old, don't use */
#define EDID_COMPLETE_RAWDATA 0x01
/**
* @brief The monitor_hdr_data hdr metadata struct
* This struct mirrors Table 92 - HDR Static Metadata Data Block (HDR SMDB) structure
*/
struct monitor_hdr_data {
bool hdr_valid : 1; /* static metadata v1 found, doesn't mean all fields are set */
bool colorimetry_valid : 1; /* if colorimetry tag found */
bool tf_traditional_sdr : 1,
tf_traditional_hdr : 1,
tf_pq : 1,
tf_hlg : 1,
tf_4 : 1,
tf_5 : 1;
unsigned int resv : 2; /* reserved bits */
float desired_content_min_luminance; /* in cd/m2, can be 0 */
float desired_content_max_luminance; /* in cd/m2, can be 0 */
float desired_content_max_frame_avg_luminance; /* in cd/m2, if unset 0 */
bool sm_static_metadata_type1 : 1;
unsigned int sm_1_7 : 7; /* reserved bits */
int reserved_1[4]; /* for future */
unsigned int colorimetry_profiles : 16;
int reserved_2[4]; /* for future */
};
#define CTA_HDR_SMDB_TF_SDR 1
#define CTA_HDR_SMDB_TF_HDR 2
#define CTA_HDR_SMDB_TF_ST2084 4
#define CTA_HDR_SMDB_TF_HLG 8
#define CTA_HDR_SMDB_SM_TYPE1 1
/* these constants are from Colorimetry Data Block (CDB) byte 3 and 4, converted into natural representation (big endian) uint16 */
#define is_CTA_CDB_BT2020_RGB(x) (((x) & 0x8000) == 0x8000)
#define is_CTA_CDB_BT2020_YCC(x) (((x) & 0x4000) == 0x4000)
#define is_CTA_CDB_BT2020_cYCC(x) (((x) & 0x2000) == 0x2000)
#define is_CTA_CDB_opRGB(x) (((x) & 0x1000) == 0x1000)
#define is_CTA_CDB_opYCC601(x) (((x) & 0x0800) == 0x0800)
#define is_CTA_CDB_sYCC601(x) (((x) & 0x0400) == 0x0400)
#define is_CTA_CDB_xvYCC709(x) (((x) & 0x0200) == 0x0200)
#define is_CTA_CDB_xvYCC601(x) (((x) & 0x0100) == 0x0100)
#define is_CTA_CDB_ST2113RGB(x) (((x) & 0x0080) == 0x0080)
#define is_CTA_CDB_iCtCp(x) (((x) & 0x0040) == 0x0040)
/*
* For DisplayID devices, only the scrnIndex, flags, and rawData fields
* are meaningful. For EDID, they all are.
*/
typedef struct {
int scrnIndex;
struct vendor vendor;
struct edid_version ver;
struct disp_features features;
struct established_timings timings1;
struct std_timings timings2[8];
struct detailed_monitor_section det_mon[4];
unsigned long flags;
int no_sections;
uint8_t *rawData;
struct monitor_hdr_data hdr;
} xf86Monitor, *xf86MonPtr;
extern _X_EXPORT xf86MonPtr ConfiguredMonitor;
/*
* check whether monitor supports Generalized Timing Formula
*
* @param monitor the monitor information structure to check
* @return true if GTF is supported by the monitor
*/
_X_EXPORT bool xf86Monitor_gtf_supported(xf86MonPtr monitor);
#endif /* _EDID_H_ */