edid: Remove all unnecessary EDID parameters parsing

This commit retains only necessary EDID parameters while
eliminating redundant EDID parsing in mutter

Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/2597
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2825>
This commit is contained in:
adarshgm 2023-02-03 05:50:15 +00:00
parent 01353fdc08
commit 8e914f6772
2 changed files with 22 additions and 524 deletions

View File

@ -61,19 +61,6 @@ get_bits (int in, int begin, int end)
return (in >> begin) & mask;
}
static void
decode_check_sum (const uint8_t *edid,
MetaEdidInfo *info)
{
int i;
uint8_t check = 0;
for (i = 0; i < 128; ++i)
check += edid[i];
info->checksum = check;
}
static gboolean
decode_header (const uint8_t *edid)
{
@ -86,14 +73,12 @@ static gboolean
decode_vendor_and_product_identification (const uint8_t *edid,
MetaEdidInfo *info)
{
int is_model_year;
/* Manufacturer Code */
info->manufacturer_code[0] = get_bits (edid[0x08], 2, 6);
info->manufacturer_code[1] = get_bits (edid[0x08], 0, 1) << 3;
info->manufacturer_code[0] = get_bits (edid[0x08], 2, 6);
info->manufacturer_code[1] = get_bits (edid[0x08], 0, 1) << 3;
info->manufacturer_code[1] |= get_bits (edid[0x09], 5, 7);
info->manufacturer_code[2] = get_bits (edid[0x09], 0, 4);
info->manufacturer_code[3] = '\0';
info->manufacturer_code[2] = get_bits (edid[0x09], 0, 4);
info->manufacturer_code[3] = '\0';
info->manufacturer_code[0] += 'A' - 1;
info->manufacturer_code[1] += 'A' - 1;
@ -105,46 +90,6 @@ decode_vendor_and_product_identification (const uint8_t *edid,
/* Serial Number */
info->serial_number =
edid[0x0c] | edid[0x0d] << 8 | edid[0x0e] << 16 | edid[0x0f] << 24;
/* Week and Year */
is_model_year = FALSE;
switch (edid[0x10])
{
case 0x00:
info->production_week = -1;
break;
case 0xff:
info->production_week = -1;
is_model_year = TRUE;
break;
default:
info->production_week = edid[0x10];
break;
}
if (is_model_year)
{
info->production_year = -1;
info->model_year = 1990 + edid[0x11];
}
else
{
info->production_year = 1990 + edid[0x11];
info->model_year = -1;
}
return TRUE;
}
static gboolean
decode_edid_version (const uint8_t *edid,
MetaEdidInfo *info)
{
info->major_version = edid[0x12];
info->minor_version = edid[0x13];
return TRUE;
}
@ -152,129 +97,12 @@ static gboolean
decode_display_parameters (const uint8_t *edid,
MetaEdidInfo *info)
{
/* Digital vs Analog */
info->is_digital = get_bit (edid[0x14], 7);
if (info->is_digital)
{
int bits;
static const int bit_depth[8] =
{
-1, 6, 8, 10, 12, 14, 16, -1
};
static const MetaEdidInterface interfaces[6] =
{
META_EDID_INTERFACE_UNDEFINED,
META_EDID_INTERFACE_DVI,
META_EDID_INTERFACE_HDMI_A,
META_EDID_INTERFACE_HDMI_B,
META_EDID_INTERFACE_MDDI,
META_EDID_INTERFACE_DISPLAY_PORT
};
bits = get_bits (edid[0x14], 4, 6);
info->connector.digital.bits_per_primary = bit_depth[bits];
bits = get_bits (edid[0x14], 0, 3);
if (bits <= 5)
info->connector.digital.interface = interfaces[bits];
else
info->connector.digital.interface = META_EDID_INTERFACE_UNDEFINED;
}
else
{
int bits = get_bits (edid[0x14], 5, 6);
static const double levels[][3] =
{
{ 0.7, 0.3, 1.0 },
{ 0.714, 0.286, 1.0 },
{ 1.0, 0.4, 1.4 },
{ 0.7, 0.0, 0.7 },
};
info->connector.analog.video_signal_level = levels[bits][0];
info->connector.analog.sync_signal_level = levels[bits][1];
info->connector.analog.total_signal_level = levels[bits][2];
info->connector.analog.blank_to_black = get_bit (edid[0x14], 4);
info->connector.analog.separate_hv_sync = get_bit (edid[0x14], 3);
info->connector.analog.composite_sync_on_h = get_bit (edid[0x14], 2);
info->connector.analog.composite_sync_on_green = get_bit (edid[0x14], 1);
info->connector.analog.serration_on_vsync = get_bit (edid[0x14], 0);
}
/* Screen Size / Aspect Ratio */
if (edid[0x15] == 0 && edid[0x16] == 0)
{
info->width_mm = -1;
info->height_mm = -1;
info->aspect_ratio = -1.0;
}
else if (edid[0x16] == 0)
{
info->width_mm = -1;
info->height_mm = -1;
info->aspect_ratio = 100.0 / (edid[0x15] + 99);
}
else if (edid[0x15] == 0)
{
info->width_mm = -1;
info->height_mm = -1;
info->aspect_ratio = 100.0 / (edid[0x16] + 99);
info->aspect_ratio = 1/info->aspect_ratio; /* portrait */
}
else
{
info->width_mm = 10 * edid[0x15];
info->height_mm = 10 * edid[0x16];
}
/* Gamma */
if (edid[0x17] == 0xFF)
info->gamma = -1.0;
else
info->gamma = (edid[0x17] + 100.0) / 100.0;
/* Features */
info->standby = get_bit (edid[0x18], 7);
info->suspend = get_bit (edid[0x18], 6);
info->active_off = get_bit (edid[0x18], 5);
if (info->is_digital)
{
info->connector.digital.rgb444 = TRUE;
if (get_bit (edid[0x18], 3))
info->connector.digital.ycrcb444 = 1;
if (get_bit (edid[0x18], 4))
info->connector.digital.ycrcb422 = 1;
}
else
{
int bits = get_bits (edid[0x18], 3, 4);
MetaEdidColorType color_type[4] =
{
META_EDID_COLOR_TYPE_MONOCHROME,
META_EDID_COLOR_TYPE_RGB,
META_EDID_COLOR_TYPE_OTHER_COLOR,
META_EDID_COLOR_TYPE_UNDEFINED
};
info->connector.analog.color_type = color_type[bits];
}
info->srgb_is_standard = get_bit (edid[0x18], 2);
/* In 1.3 this is called "has preferred timing" */
info->preferred_timing_includes_native = get_bit (edid[0x18], 1);
/* FIXME: In 1.3 this indicates whether the monitor accepts GTF */
info->continuous_frequency = get_bit (edid[0x18], 0);
return TRUE;
}
@ -308,93 +136,6 @@ decode_color_characteristics (const uint8_t *edid,
return TRUE;
}
static int
decode_established_timings (const uint8_t *edid,
MetaEdidInfo *info)
{
static const MetaEdidTiming established[][8] =
{
{
{ 800, 600, 60 },
{ 800, 600, 56 },
{ 640, 480, 75 },
{ 640, 480, 72 },
{ 640, 480, 67 },
{ 640, 480, 60 },
{ 720, 400, 88 },
{ 720, 400, 70 }
},
{
{ 1280, 1024, 75 },
{ 1024, 768, 75 },
{ 1024, 768, 70 },
{ 1024, 768, 60 },
{ 1024, 768, 87 },
{ 832, 624, 75 },
{ 800, 600, 75 },
{ 800, 600, 72 }
},
{
{ 0, 0, 0 },
{ 0, 0, 0 },
{ 0, 0, 0 },
{ 0, 0, 0 },
{ 0, 0, 0 },
{ 0, 0, 0 },
{ 0, 0, 0 },
{ 1152, 870, 75 }
},
};
int i, j, idx;
idx = 0;
for (i = 0; i < 3; ++i)
{
for (j = 0; j < 8; ++j)
{
int byte = edid[0x23 + i];
if (get_bit (byte, j) && established[i][j].frequency != 0)
info->established[idx++] = established[i][j];
}
}
return TRUE;
}
static gboolean
decode_standard_timings (const uint8_t *edid,
MetaEdidInfo *info)
{
int i;
for (i = 0; i < 8; i++)
{
int first = edid[0x26 + 2 * i];
int second = edid[0x27 + 2 * i];
if (first != 0x01 && second != 0x01)
{
int w = 8 * (first + 31);
int h = 0;
switch (get_bits (second, 6, 7))
{
case 0x00: h = (w / 16) * 10; break;
case 0x01: h = (w / 4) * 3; break;
case 0x02: h = (w / 5) * 4; break;
case 0x03: h = (w / 16) * 9; break;
}
info->standard[i].width = w;
info->standard[i].height = h;
info->standard[i].frequency = get_bits (second, 0, 5) + 60;
}
}
return TRUE;
}
static void
decode_lf_string (const uint8_t *s,
int n_chars,
@ -422,7 +163,7 @@ decode_lf_string (const uint8_t *s,
static void
decode_display_descriptor (const uint8_t *desc,
MetaEdidInfo *info)
MetaEdidInfo *info)
{
switch (desc[0x03])
{
@ -432,127 +173,26 @@ decode_display_descriptor (const uint8_t *desc,
case 0xFF:
decode_lf_string (desc + 5, 13, info->dsc_serial_number);
break;
case 0xFE:
decode_lf_string (desc + 5, 13, info->dsc_string);
break;
case 0xFD:
/* Range Limits */
break;
case 0xFB:
/* Color Point */
break;
case 0xFA:
/* Timing Identifications */
break;
case 0xF9:
/* Color Management */
break;
case 0xF8:
/* Timing Codes */
break;
case 0xF7:
/* Established Timings */
break;
case 0x10:
break;
}
}
static void
decode_detailed_timing (const uint8_t *timing,
MetaEdidDetailedTiming *detailed)
{
int bits;
MetaEdidStereoType stereo[] =
{
META_EDID_STEREO_TYPE_NO_STEREO,
META_EDID_STEREO_TYPE_NO_STEREO,
META_EDID_STEREO_TYPE_FIELD_RIGHT,
META_EDID_STEREO_TYPE_FIELD_LEFT,
META_EDID_STEREO_TYPE_TWO_WAY_RIGHT_ON_EVEN,
META_EDID_STEREO_TYPE_TWO_WAY_LEFT_ON_EVEN,
META_EDID_STEREO_TYPE_FOUR_WAY_INTERLEAVED,
META_EDID_STEREO_TYPE_SIDE_BY_SIDE
};
detailed->pixel_clock = (timing[0x00] | timing[0x01] << 8) * 10000;
detailed->h_addr = timing[0x02] | ((timing[0x04] & 0xf0) << 4);
detailed->h_blank = timing[0x03] | ((timing[0x04] & 0x0f) << 8);
detailed->v_addr = timing[0x05] | ((timing[0x07] & 0xf0) << 4);
detailed->v_blank = timing[0x06] | ((timing[0x07] & 0x0f) << 8);
detailed->h_front_porch = timing[0x08] | get_bits (timing[0x0b], 6, 7) << 8;
detailed->h_sync = timing[0x09] | get_bits (timing[0x0b], 4, 5) << 8;
detailed->v_front_porch =
get_bits (timing[0x0a], 4, 7) | get_bits (timing[0x0b], 2, 3) << 4;
detailed->v_sync =
get_bits (timing[0x0a], 0, 3) | get_bits (timing[0x0b], 0, 1) << 4;
detailed->width_mm = timing[0x0c] | get_bits (timing[0x0e], 4, 7) << 8;
detailed->height_mm = timing[0x0d] | get_bits (timing[0x0e], 0, 3) << 8;
detailed->right_border = timing[0x0f];
detailed->top_border = timing[0x10];
detailed->interlaced = get_bit (timing[0x11], 7);
/* Stereo */
bits = get_bits (timing[0x11], 5, 6) << 1 | get_bit (timing[0x11], 0);
detailed->stereo = stereo[bits];
/* Sync */
bits = timing[0x11];
detailed->digital_sync = get_bit (bits, 4);
if (detailed->digital_sync)
{
detailed->connector.digital.composite = !get_bit (bits, 3);
if (detailed->connector.digital.composite)
{
detailed->connector.digital.serrations = get_bit (bits, 2);
detailed->connector.digital.negative_vsync = FALSE;
}
else
{
detailed->connector.digital.serrations = FALSE;
detailed->connector.digital.negative_vsync = !get_bit (bits, 2);
}
detailed->connector.digital.negative_hsync = !get_bit (bits, 0);
}
else
{
detailed->connector.analog.bipolar = get_bit (bits, 3);
detailed->connector.analog.serrations = get_bit (bits, 2);
detailed->connector.analog.sync_on_green = !get_bit (bits, 1);
}
}
static gboolean
decode_descriptors (const uint8_t *edid,
MetaEdidInfo *info)
{
int i;
int timing_idx;
timing_idx = 0;
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);
}
else
{
decode_detailed_timing (edid + index, &(info->detailed_timings[timing_idx++]));
}
}
}
info->n_detailed_timings = timing_idx;
return TRUE;
}
@ -680,15 +320,10 @@ meta_edid_info_new_parse (const uint8_t *edid)
info = g_new0 (MetaEdidInfo, 1);
decode_check_sum (edid, info);
if (decode_header (edid)
&& decode_vendor_and_product_identification (edid, info)
&& decode_edid_version (edid, info)
&& decode_display_parameters (edid, info)
&& decode_color_characteristics (edid, info)
&& decode_established_timings (edid, info)
&& decode_standard_timings (edid, info)
&& decode_descriptors (edid, info)
&& decode_extensions (edid, info))
{

View File

@ -30,39 +30,8 @@
#include "core/util-private.h"
typedef struct _MetaEdidInfo MetaEdidInfo;
typedef struct _MetaEdidTiming MetaEdidTiming;
typedef struct _MetaEdidDetailedTiming MetaEdidDetailedTiming;
typedef struct _MetaEdidHdrStaticMetadata MetaEdidHdrStaticMetadata;
typedef enum
{
META_EDID_INTERFACE_UNDEFINED,
META_EDID_INTERFACE_DVI,
META_EDID_INTERFACE_HDMI_A,
META_EDID_INTERFACE_HDMI_B,
META_EDID_INTERFACE_MDDI,
META_EDID_INTERFACE_DISPLAY_PORT
} MetaEdidInterface;
typedef enum
{
META_EDID_COLOR_TYPE_UNDEFINED,
META_EDID_COLOR_TYPE_MONOCHROME,
META_EDID_COLOR_TYPE_RGB,
META_EDID_COLOR_TYPE_OTHER_COLOR
} MetaEdidColorType;
typedef enum
{
META_EDID_STEREO_TYPE_NO_STEREO,
META_EDID_STEREO_TYPE_FIELD_RIGHT,
META_EDID_STEREO_TYPE_FIELD_LEFT,
META_EDID_STEREO_TYPE_TWO_WAY_RIGHT_ON_EVEN,
META_EDID_STEREO_TYPE_TWO_WAY_LEFT_ON_EVEN,
META_EDID_STEREO_TYPE_FOUR_WAY_INTERLEAVED,
META_EDID_STEREO_TYPE_SIDE_BY_SIDE
} MetaEdidStereoType;
typedef enum
{
META_EDID_COLORIMETRY_XVYCC601 = (1 << 0),
@ -90,51 +59,6 @@ typedef enum
META_EDID_STATIC_METADATA_TYPE1 = 0,
} MetaEdidStaticMetadataType;
struct _MetaEdidTiming
{
int width;
int height;
int frequency;
};
struct _MetaEdidDetailedTiming
{
int pixel_clock;
int h_addr;
int h_blank;
int h_sync;
int h_front_porch;
int v_addr;
int v_blank;
int v_sync;
int v_front_porch;
int width_mm;
int height_mm;
int right_border;
int top_border;
int interlaced;
MetaEdidStereoType stereo;
int digital_sync;
union
{
struct
{
int bipolar;
int serrations;
int sync_on_green;
} analog;
struct
{
int composite;
int serrations;
int negative_vsync;
int negative_hsync;
} digital;
} connector;
};
struct _MetaEdidHdrStaticMetadata
{
int available;
@ -147,86 +71,25 @@ struct _MetaEdidHdrStaticMetadata
struct _MetaEdidInfo
{
int checksum;
char manufacturer_code[4];
int product_code;
unsigned int serial_number;
char manufacturer_code[4];
int product_code;
unsigned int serial_number;
int production_week; /* -1 if not specified */
int production_year; /* -1 if not specified */
int model_year; /* -1 if not specified */
double gamma; /* -1.0 if not specified */
int major_version;
int minor_version;
int is_digital;
union
{
struct
{
int bits_per_primary;
MetaEdidInterface interface;
int rgb444;
int ycrcb444;
int ycrcb422;
} digital;
struct
{
double video_signal_level;
double sync_signal_level;
double total_signal_level;
int blank_to_black;
int separate_hv_sync;
int composite_sync_on_h;
int composite_sync_on_green;
int serration_on_vsync;
MetaEdidColorType color_type;
} analog;
} connector;
int width_mm; /* -1 if not specified */
int height_mm; /* -1 if not specified */
double aspect_ratio; /* -1.0 if not specififed */
double gamma; /* -1.0 if not specified */
int standby;
int suspend;
int active_off;
int srgb_is_standard;
int preferred_timing_includes_native;
int continuous_frequency;
double red_x;
double red_y;
double green_x;
double green_y;
double blue_x;
double blue_y;
double white_x;
double white_y;
MetaEdidTiming established[24]; /* Terminated by 0x0x0 */
MetaEdidTiming standard[8];
int n_detailed_timings;
MetaEdidDetailedTiming detailed_timings[4]; /* If monitor has a preferred
* mode, it is the first one
* (whether it has, is
* determined by the
* preferred_timing_includes
* bit.
*/
double red_x;
double red_y;
double green_x;
double green_y;
double blue_x;
double blue_y;
double white_x;
double white_y;
/* Optional product description */
char dsc_serial_number[14];
char dsc_product_name[14];
char dsc_string[14]; /* Unspecified ASCII data */
char dsc_serial_number[14];
char dsc_product_name[14];
char dsc_string[14]; /* Unspecified ASCII data */
MetaEdidColorimetry colorimetry;
MetaEdidHdrStaticMetadata hdr_static_metadata;