1
0
Fork 0

edid: Make libdisplay-info hard dep

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3602>
This commit is contained in:
Sebastian Wick 2024-02-20 16:54:24 +01:00 committed by Marge Bot
parent 34c2767f81
commit c820a63b87
6 changed files with 3 additions and 358 deletions

View file

@ -365,7 +365,6 @@ check-code-style:
-Degl_device=true -Degl_device=true
-Dwayland_eglstream=true -Dwayland_eglstream=true
-Dcatch=true -Dcatch=true
-Dlibdisplay_info=enabled
.build-mutter: .build-mutter:
extends: extends:

View file

@ -124,9 +124,6 @@
/* Whether the Xwayland supports +/-byteswappedclients */ /* Whether the Xwayland supports +/-byteswappedclients */
#mesondefine HAVE_XWAYLAND_BYTE_SWAPPED_CLIENTS #mesondefine HAVE_XWAYLAND_BYTE_SWAPPED_CLIENTS
/* Defined if libdisplay-info is enabled */
#mesondefine HAVE_LIBDISPLAY_INFO
/* Whether the Xwayland has -enable-ei-portal option */ /* Whether the Xwayland has -enable-ei-portal option */
#mesondefine HAVE_XWAYLAND_ENABLE_EI_PORTAL #mesondefine HAVE_XWAYLAND_ENABLE_EI_PORTAL

View file

@ -39,6 +39,7 @@ libwacom_req = '>= 0.13'
atk_req = '>= 2.5.3' atk_req = '>= 2.5.3'
harfbuzz_req = '>= 2.6' harfbuzz_req = '>= 2.6'
libei_req = '>= 1.0.901' libei_req = '>= 1.0.901'
libdisplay_info_req = '>= 0.2'
# optional version requirements # optional version requirements
udev_req = '>= 228' udev_req = '>= 228'
@ -130,6 +131,7 @@ harfbuzz_dep = dependency('harfbuzz', version: harfbuzz_req)
libeis_dep = dependency('libeis-1.0', version: libei_req) libeis_dep = dependency('libeis-1.0', version: libei_req)
libei_dep = dependency('libei-1.0', version: libei_req) libei_dep = dependency('libei-1.0', version: libei_req)
gvdb_dep = dependency('gvdb') gvdb_dep = dependency('gvdb')
libdisplay_info_dep = dependency('libdisplay-info', version: libdisplay_info_req)
have_wayland = get_option('wayland') have_wayland = get_option('wayland')
have_x11 = get_option('x11') have_x11 = get_option('x11')
@ -170,10 +172,6 @@ if have_x11_client
endif endif
endif endif
use_libdisplay_info = get_option('libdisplay_info')
libdisplay_info_dep = dependency('libdisplay-info', required: use_libdisplay_info)
have_libdisplay_info = libdisplay_info_dep.found()
have_gnome_desktop = get_option('libgnome_desktop') have_gnome_desktop = get_option('libgnome_desktop')
if have_gnome_desktop if have_gnome_desktop
gnome_desktop_dep = dependency('gnome-desktop-4') gnome_desktop_dep = dependency('gnome-desktop-4')
@ -563,7 +561,6 @@ cdata.set('HAVE_SM', have_sm)
cdata.set('HAVE_STARTUP_NOTIFICATION', have_startup_notification) cdata.set('HAVE_STARTUP_NOTIFICATION', have_startup_notification)
cdata.set('HAVE_INTROSPECTION', have_introspection) cdata.set('HAVE_INTROSPECTION', have_introspection)
cdata.set('HAVE_PROFILER', have_profiler) cdata.set('HAVE_PROFILER', have_profiler)
cdata.set('HAVE_LIBDISPLAY_INFO', have_libdisplay_info)
cdata.set('HAVE_TIMERFD', have_timerfd) cdata.set('HAVE_TIMERFD', have_timerfd)
cdata.set('HAVE_MALLOC_TRIM', have_malloc_trim) cdata.set('HAVE_MALLOC_TRIM', have_malloc_trim)
cdata.set('HAVE_EVENTFD', have_eventfd) cdata.set('HAVE_EVENTFD', have_eventfd)
@ -735,7 +732,6 @@ summary('Native Backend', have_native_backend, section: 'Options')
summary('EGL Device', have_egl_device, section: 'Options') summary('EGL Device', have_egl_device, section: 'Options')
summary('Remote desktop', have_remote_desktop, section: 'Options') summary('Remote desktop', have_remote_desktop, section: 'Options')
summary('libgnome-desktop', have_gnome_desktop, section: 'Options') summary('libgnome-desktop', have_gnome_desktop, section: 'Options')
summary('libdisplay-info', have_libdisplay_info, section: 'Options')
summary('Sound player', have_sound_player, section: 'Options') summary('Sound player', have_sound_player, section: 'Options')
summary('gudev', have_libgudev, section: 'Options') summary('gudev', have_libgudev, section: 'Options')
summary('Wacom', have_libwacom, section: 'Options') summary('Wacom', have_libwacom, section: 'Options')

View file

@ -218,10 +218,3 @@ option('catch',
value: false, value: false,
description: 'Use catch to catch backtraces' description: 'Use catch to catch backtraces'
) )
option('libdisplay_info',
type: 'feature',
value: 'enabled',
deprecated: {'true': 'enabled', 'false': 'disabled'},
description: 'Build with or without libdisplay-info'
)

View file

@ -29,15 +29,12 @@
#include <math.h> #include <math.h>
#include <glib.h> #include <glib.h>
#ifdef HAVE_LIBDISPLAY_INFO
#include <libdisplay-info/cta.h> #include <libdisplay-info/cta.h>
#include <libdisplay-info/edid.h> #include <libdisplay-info/edid.h>
#include <libdisplay-info/info.h> #include <libdisplay-info/info.h>
#endif
#include "backends/edid.h" #include "backends/edid.h"
#ifdef HAVE_LIBDISPLAY_INFO
static void static void
decode_edid_descriptors (const struct di_edid *di_edid, decode_edid_descriptors (const struct di_edid *di_edid,
const struct di_edid_display_descriptor *desc, const struct di_edid_display_descriptor *desc,
@ -249,338 +246,6 @@ decode_edid_info (const uint8_t *edid,
return TRUE; return TRUE;
} }
#else /* HAVE_LIBDISPLAY_INFO */
/* VESA E-EDID */
#define EDID_BLOCK_LENGTH 128
#define EDID_EXT_FLAG_ADDR 0x7E
#define EDID_EXT_TAG_ADDR 0x00
/* VESA reserved IDs for extension blocks */
#define EDID_EXT_ID_CTA 0x02
/* CTA-861 extension block */
#define EDID_EXT_CTA_REVISION_ADDR 0x01
#define EDID_EXT_CTA_DESCRIPTOR_OFFSET_ADDR 0x02
#define EDID_EXT_CTA_DATA_BLOCK_OFFSET 0x04
#define EDID_EXT_CTA_TAG_EXTENDED 0x07
#define EDID_EXT_CTA_TAG_EXTENDED_COLORIMETRY 0x0705
#define EDID_EXT_CTA_TAG_EXTENDED_HDR_STATIC_METADATA 0x0706
static int
get_bit (int in, int bit)
{
return (in & (1 << bit)) >> bit;
}
static int
get_bits (int in, int begin, int end)
{
int mask = (1 << (end - begin + 1)) - 1;
return (in >> begin) & mask;
}
static gboolean
decode_header (const uint8_t *edid)
{
if (memcmp (edid, "\x00\xff\xff\xff\xff\xff\xff\x00", 8) == 0)
return TRUE;
return FALSE;
}
static gboolean
decode_vendor_and_product_identification (const uint8_t *edid,
MetaEdidInfo *info)
{
char manufacturer_code[4];
/* Manufacturer Code */
manufacturer_code[0] = get_bits (edid[0x08], 2, 6);
manufacturer_code[1] = get_bits (edid[0x08], 0, 1) << 3;
manufacturer_code[1] |= get_bits (edid[0x09], 5, 7);
manufacturer_code[2] = get_bits (edid[0x09], 0, 4);
manufacturer_code[3] = '\0';
manufacturer_code[0] += 'A' - 1;
manufacturer_code[1] += 'A' - 1;
manufacturer_code[2] += 'A' - 1;
info->manufacturer_code = g_strdup (manufacturer_code);
/* Product Code */
info->product_code = edid[0x0b] << 8 | edid[0x0a];
/* Serial Number */
info->serial_number =
edid[0x0c] | edid[0x0d] << 8 | edid[0x0e] << 16 | edid[0x0f] << 24;
return TRUE;
}
static gboolean
decode_display_parameters (const uint8_t *edid,
MetaEdidInfo *info)
{
/* Gamma */
if (edid[0x17] == 0xFF)
info->gamma = -1.0;
else
info->gamma = (edid[0x17] + 100.0) / 100.0;
return TRUE;
}
static double
decode_fraction (int high, int low)
{
double result = 0.0;
int i;
high = (high << 2) | low;
for (i = 0; i < 10; ++i)
result += get_bit (high, i) * pow (2, i - 10);
return result;
}
static gboolean
decode_color_characteristics (const uint8_t *edid,
MetaEdidInfo *info)
{
info->red_x = decode_fraction (edid[0x1b], get_bits (edid[0x19], 6, 7));
info->red_y = decode_fraction (edid[0x1c], get_bits (edid[0x19], 5, 4));
info->green_x = decode_fraction (edid[0x1d], get_bits (edid[0x19], 2, 3));
info->green_y = decode_fraction (edid[0x1e], get_bits (edid[0x19], 0, 1));
info->blue_x = decode_fraction (edid[0x1f], get_bits (edid[0x1a], 6, 7));
info->blue_y = decode_fraction (edid[0x20], get_bits (edid[0x1a], 4, 5));
info->white_x = decode_fraction (edid[0x21], get_bits (edid[0x1a], 2, 3));
info->white_y = decode_fraction (edid[0x22], get_bits (edid[0x1a], 0, 1));
return TRUE;
}
static void
decode_lf_string (const uint8_t *s,
char **result)
{
int i;
char decoded[14] = { 0 };
for (i = 0; i < 13; ++i)
{
if (s[i] == 0x0a)
{
decoded[i] = '\0';
break;
}
else if (s[i] == 0x00)
{
/* Convert embedded 0's to spaces */
decoded[i] = ' ';
}
else
{
decoded[i] = s[i];
}
}
*result = g_strdup (decoded);
}
static void
decode_display_descriptor (const uint8_t *desc,
MetaEdidInfo *info)
{
switch (desc[0x03])
{
case 0xFC:
decode_lf_string (desc + 5, &info->dsc_product_name);
break;
case 0xFF:
decode_lf_string (desc + 5, &info->dsc_serial_number);
break;
}
}
static gboolean
decode_descriptors (const uint8_t *edid,
MetaEdidInfo *info)
{
int i;
for (i = 0; i < 4; ++i)
{
int index = 0x36 + i * 18;
if (edid[index + 0] == 0x00 && edid[index + 1] == 0x00)
{
decode_display_descriptor (edid + index, info);
}
}
return TRUE;
}
static gboolean
decode_ext_cta_colorimetry (const uint8_t *data_block,
MetaEdidInfo *info)
{
/* CTA-861-H: Table 78 - Colorimetry Data Block (CDB) */
info->colorimetry = (data_block[3] << 8) + data_block[2];
return TRUE;
}
static float
decode_max_luminance (uint8_t raw)
{
if (raw == 0)
return 0.f;
return 50 * powf (2, (float) raw / 32);
}
static float
decode_min_luminance (uint8_t raw,
float max)
{
if (raw == 0)
return 0.f;
return max * powf ((float) raw / 255, 2) / 100;
}
static gboolean
decode_ext_cta_hdr_static_metadata (const uint8_t *data_block,
MetaEdidInfo *info)
{
/* CTA-861-H: Table 92 - HDR Static Metadata Data Block (HDR SMDB) */
int size;
info->hdr_static_metadata.tf = data_block[2];
info->hdr_static_metadata.sm = data_block[3];
size = get_bits (data_block[0], 0, 5);
if (size > 3)
{
info->hdr_static_metadata.max_luminance =
decode_max_luminance (data_block[4]);
}
if (size > 4)
{
info->hdr_static_metadata.max_fal = decode_max_luminance (data_block[5]);
}
if (size > 5)
{
info->hdr_static_metadata.min_luminance =
decode_min_luminance (data_block[6],
info->hdr_static_metadata.max_luminance);
}
return TRUE;
}
static gboolean
decode_ext_cta (const uint8_t *cta_block,
MetaEdidInfo *info)
{
const uint8_t *data_block;
uint8_t data_block_end;
uint8_t data_block_offset;
int size;
int tag;
/* The CTA extension block is a number of data blocks followed by a number
* of (timing) descriptors. We only parse the data blocks. */
/* CTA-861-H Table 58: CTA Extension Version 3 */
data_block_end = cta_block[EDID_EXT_CTA_DESCRIPTOR_OFFSET_ADDR];
data_block_offset = EDID_EXT_CTA_DATA_BLOCK_OFFSET;
/* Table 58:
* If d=0, then no detailed timing descriptors are provided, and no data is
* provided in the data block collection */
if (data_block_end == 0)
return TRUE;
/* Table 58:
* If no data is provided in the data block collection, then d=4 */
if (data_block_end == 4)
return TRUE;
if (data_block_end < 4)
return FALSE;
while (data_block_offset < data_block_end)
{
/* CTA-861-H 7.4: CTA Data Block Collection */
data_block = cta_block + data_block_offset;
size = get_bits (data_block[0], 0, 4) + 1;
tag = get_bits (data_block[0], 5, 7);
data_block_offset += size;
/* CTA Data Block extended tag type is the second byte */
if (tag == EDID_EXT_CTA_TAG_EXTENDED)
tag = (tag << 8) + data_block[1];
switch (tag)
{
case EDID_EXT_CTA_TAG_EXTENDED_COLORIMETRY:
if (!decode_ext_cta_colorimetry (data_block, info))
return FALSE;
break;
case EDID_EXT_CTA_TAG_EXTENDED_HDR_STATIC_METADATA:
if (!decode_ext_cta_hdr_static_metadata (data_block, info))
return FALSE;
break;
}
}
return TRUE;
}
static gboolean
decode_extensions (const uint8_t *edid,
MetaEdidInfo *info)
{
int blocks;
int i;
const uint8_t *block = NULL;
blocks = edid[EDID_EXT_FLAG_ADDR];
for (i = 0; i < blocks; i++)
{
block = edid + EDID_BLOCK_LENGTH * (i + 1);
switch (block[EDID_EXT_TAG_ADDR])
{
case EDID_EXT_ID_CTA:
if (!decode_ext_cta (block, info))
return FALSE;
break;
}
}
return TRUE;
}
static gboolean
decode_edid_info (const uint8_t *edid,
MetaEdidInfo *info,
size_t size)
{
return decode_header (edid) &&
decode_vendor_and_product_identification (edid, info) &&
decode_display_parameters (edid, info) &&
decode_color_characteristics (edid, info) &&
decode_descriptors (edid, info) &&
decode_extensions (edid, info);
}
#endif /* HAVE_LIBDISPLAY_INFO */
MetaEdidInfo * MetaEdidInfo *
meta_edid_info_new_parse (const uint8_t *edid, meta_edid_info_new_parse (const uint8_t *edid,
size_t size) size_t size)

View file

@ -27,6 +27,7 @@ mutter_pkg_private_deps = [
xkbcommon_dep, xkbcommon_dep,
gdk_pixbuf_dep, gdk_pixbuf_dep,
libeis_dep, libeis_dep,
libdisplay_info_dep,
] ]
if have_gnome_desktop if have_gnome_desktop
@ -35,12 +36,6 @@ if have_gnome_desktop
] ]
endif endif
if have_libdisplay_info
mutter_pkg_private_deps += [
libdisplay_info_dep,
]
endif
if have_sound_player if have_sound_player
mutter_pkg_private_deps += [ mutter_pkg_private_deps += [
libcanberra_dep, libcanberra_dep,