[gnome-flashback] edid: prepare types for wider exposure



commit 29b20b67df37219d2a3e0dc6d47823faf8da3aab
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Sat Aug 13 15:32:27 2022 +0300

    edid: prepare types for wider exposure
    
    Based on mutter commit:
    https://gitlab.gnome.org/GNOME/mutter/-/commit/de2443bc3e8e257891a7

 backends/gf-edid-parse.c   | 93 +++++++++++++++++++++++++++-------------------
 backends/gf-edid-private.h | 82 ++++++++++++++++++++--------------------
 backends/gf-output-info.c  |  4 +-
 3 files changed, 98 insertions(+), 81 deletions(-)
---
diff --git a/backends/gf-edid-parse.c b/backends/gf-edid-parse.c
index 28809dc..f3d3e6e 100644
--- a/backends/gf-edid-parse.c
+++ b/backends/gf-edid-parse.c
@@ -47,7 +47,7 @@ get_bits (int in,
 }
 
 static int
-decode_header (const uchar *edid)
+decode_header (const uint8_t *edid)
 {
   if (memcmp (edid, "\x00\xff\xff\xff\xff\xff\xff\x00", 8) == 0)
     return TRUE;
@@ -55,8 +55,8 @@ decode_header (const uchar *edid)
 }
 
 static int
-decode_vendor_and_product_identification (const uchar *edid,
-                                          MonitorInfo *info)
+decode_vendor_and_product_identification (const uint8_t *edid,
+                                          GfEdidInfo    *info)
 {
   int is_model_year;
 
@@ -110,8 +110,8 @@ decode_vendor_and_product_identification (const uchar *edid,
 }
 
 static int
-decode_edid_version (const uchar *edid,
-                     MonitorInfo *info)
+decode_edid_version (const uint8_t *edid,
+                     GfEdidInfo    *info)
 {
   info->major_version = edid[0x12];
   info->minor_version = edid[0x13];
@@ -120,8 +120,8 @@ decode_edid_version (const uchar *edid,
 }
 
 static int
-decode_display_parameters (const uchar *edid,
-                           MonitorInfo *info)
+decode_display_parameters (const uint8_t *edid,
+                           GfEdidInfo    *info)
 {
   /* Digital vs Analog */
   info->is_digital = get_bit (edid[0x14], 7);
@@ -135,9 +135,14 @@ decode_display_parameters (const uchar *edid,
           -1, 6, 8, 10, 12, 14, 16, -1
         };
 
-      static const Interface interfaces[6] =
+      static const GfEdidInterface interfaces[6] =
         {
-          UNDEFINED, DVI, HDMI_A, HDMI_B, MDDI, DISPLAY_PORT
+          GF_EDID_INTERFACE_UNDEFINED,
+          GF_EDID_INTERFACE_DVI,
+          GF_EDID_INTERFACE_HDMI_A,
+          GF_EDID_INTERFACE_HDMI_B,
+          GF_EDID_INTERFACE_MDDI,
+          GF_EDID_INTERFACE_DISPLAY_PORT
         };
 
       bits = get_bits (edid[0x14], 4, 6);
@@ -148,7 +153,7 @@ decode_display_parameters (const uchar *edid,
       if (bits <= 5)
         info->connector.digital.interface = interfaces[bits];
       else
-        info->connector.digital.interface = UNDEFINED;
+        info->connector.digital.interface = GF_EDID_INTERFACE_UNDEFINED;
     }
   else
     {
@@ -223,9 +228,12 @@ decode_display_parameters (const uchar *edid,
   else
     {
       int bits = get_bits (edid[0x18], 3, 4);
-      ColorType color_type[4] =
+      GfEdidColorType color_type[4] =
         {
-          MONOCHROME, RGB, OTHER_COLOR, UNDEFINED_COLOR
+          GF_EDID_COLOR_TYPE_MONOCHROME,
+          GF_EDID_COLOR_TYPE_RGB,
+          GF_EDID_COLOR_TYPE_OTHER_COLOR,
+          GF_EDID_COLOR_TYPE_UNDEFINED
         };
 
       info->connector.analog.color_type = color_type[bits];
@@ -257,8 +265,8 @@ decode_fraction (int high,
 }
 
 static int
-decode_color_characteristics (const uchar *edid,
-                              MonitorInfo *info)
+decode_color_characteristics (const uint8_t *edid,
+                              GfEdidInfo    *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));
@@ -273,10 +281,10 @@ decode_color_characteristics (const uchar *edid,
 }
 
 static int
-decode_established_timings (const uchar *edid,
-                            MonitorInfo *info)
+decode_established_timings (const uint8_t *edid,
+                            GfEdidInfo    *info)
 {
-  static const Timing established[][8] =
+  static const GfEdidTiming established[][8] =
     {
       {
         { 800, 600, 60 },
@@ -328,8 +336,8 @@ decode_established_timings (const uchar *edid,
 }
 
 static int
-decode_standard_timings (const uchar *edid,
-                         MonitorInfo *info)
+decode_standard_timings (const uint8_t *edid,
+                         GfEdidInfo    *info)
 {
   int i;
 
@@ -362,9 +370,9 @@ decode_standard_timings (const uchar *edid,
 }
 
 static void
-decode_lf_string (const uchar *s,
-                  int          n_chars,
-                  char        *result)
+decode_lf_string (const uint8_t *s,
+                  int            n_chars,
+                  char          *result)
 {
   int i;
   for (i = 0; i < n_chars; ++i)
@@ -387,8 +395,8 @@ decode_lf_string (const uchar *s,
 }
 
 static void
-decode_display_descriptor (const uchar *desc,
-                           MonitorInfo *info)
+decode_display_descriptor (const uint8_t *desc,
+                           GfEdidInfo    *info)
 {
   switch (desc[0x03])
     {
@@ -427,15 +435,22 @@ decode_display_descriptor (const uchar *desc,
 }
 
 static void
-decode_detailed_timing (const uchar    *timing,
-                        DetailedTiming *detailed)
+decode_detailed_timing (const uint8_t        *timing,
+                        GfEdidDetailedTiming *detailed)
 {
   int bits;
-  StereoType stereo[] =
+  GfEdidStereoType stereo[] =
     {
-      NO_STEREO, NO_STEREO, FIELD_RIGHT, FIELD_LEFT,
-      TWO_WAY_RIGHT_ON_EVEN, TWO_WAY_LEFT_ON_EVEN,
-      FOUR_WAY_INTERLEAVED, SIDE_BY_SIDE
+      GF_EDID_STEREO_TYPE_NO_STEREO,
+      GF_EDID_STEREO_TYPE_NO_STEREO,
+      GF_EDID_STEREO_TYPE_FIELD_RIGHT,
+      GF_EDID_STEREO_TYPE_FIELD_LEFT,
+
+      GF_EDID_STEREO_TYPE_TWO_WAY_RIGHT_ON_EVEN,
+      GF_EDID_STEREO_TYPE_TWO_WAY_LEFT_ON_EVEN,
+
+      GF_EDID_STEREO_TYPE_FOUR_WAY_INTERLEAVED,
+      GF_EDID_STEREO_TYPE_SIDE_BY_SIDE
     };
 
   detailed->pixel_clock = (timing[0x00] | timing[0x01] << 8) * 10000;
@@ -488,8 +503,8 @@ decode_detailed_timing (const uchar    *timing,
 }
 
 static int
-decode_descriptors (const uchar *edid,
-                    MonitorInfo *info)
+decode_descriptors (const uint8_t *edid,
+                    GfEdidInfo    *info)
 {
   int i;
   int timing_idx;
@@ -516,11 +531,11 @@ decode_descriptors (const uchar *edid,
 }
 
 static void
-decode_check_sum (const uchar *edid,
-                  MonitorInfo *info)
+decode_check_sum (const uint8_t *edid,
+                  GfEdidInfo    *info)
 {
   int i;
-  uchar check = 0;
+  uint8_t check = 0;
 
   for (i = 0; i < 128; ++i)
     check += edid[i];
@@ -528,10 +543,12 @@ decode_check_sum (const uchar *edid,
   info->checksum = check;
 }
 
-MonitorInfo *
-decode_edid (const uchar *edid)
+GfEdidInfo *
+gf_edid_info_new_parse (const uint8_t *edid)
 {
-  MonitorInfo *info = g_new0 (MonitorInfo, 1);
+  GfEdidInfo *info;
+
+  info = g_new0 (GfEdidInfo, 1);
 
   decode_check_sum (edid, info);
 
diff --git a/backends/gf-edid-private.h b/backends/gf-edid-private.h
index e20bb1e..14e95a5 100644
--- a/backends/gf-edid-private.h
+++ b/backends/gf-edid-private.h
@@ -21,51 +21,51 @@
 #define GF_EDID_PRIVATE_H
 
 #include <glib.h>
+#include <stdint.h>
 
 G_BEGIN_DECLS
 
-typedef unsigned char uchar;
-typedef struct MonitorInfo MonitorInfo;
-typedef struct Timing Timing;
-typedef struct DetailedTiming DetailedTiming;
+typedef struct _GfEdidInfo GfEdidInfo;
+typedef struct _GfEdidTiming GfEdidTiming;
+typedef struct _GfEdidDetailedTiming GfEdidDetailedTiming;
 
 typedef enum
 {
-  UNDEFINED,
-  DVI,
-  HDMI_A,
-  HDMI_B,
-  MDDI,
-  DISPLAY_PORT
-} Interface;
+  GF_EDID_INTERFACE_UNDEFINED,
+  GF_EDID_INTERFACE_DVI,
+  GF_EDID_INTERFACE_HDMI_A,
+  GF_EDID_INTERFACE_HDMI_B,
+  GF_EDID_INTERFACE_MDDI,
+  GF_EDID_INTERFACE_DISPLAY_PORT
+} GfEdidInterface;
 
 typedef enum
 {
-  UNDEFINED_COLOR,
-  MONOCHROME,
-  RGB,
-  OTHER_COLOR
-} ColorType;
+  GF_EDID_COLOR_TYPE_UNDEFINED,
+  GF_EDID_COLOR_TYPE_MONOCHROME,
+  GF_EDID_COLOR_TYPE_RGB,
+  GF_EDID_COLOR_TYPE_OTHER_COLOR
+} GfEdidColorType;
 
 typedef enum
 {
-  NO_STEREO,
-  FIELD_RIGHT,
-  FIELD_LEFT,
-  TWO_WAY_RIGHT_ON_EVEN,
-  TWO_WAY_LEFT_ON_EVEN,
-  FOUR_WAY_INTERLEAVED,
-  SIDE_BY_SIDE
-} StereoType;
-
-struct Timing
+  GF_EDID_STEREO_TYPE_NO_STEREO,
+  GF_EDID_STEREO_TYPE_FIELD_RIGHT,
+  GF_EDID_STEREO_TYPE_FIELD_LEFT,
+  GF_EDID_STEREO_TYPE_TWO_WAY_RIGHT_ON_EVEN,
+  GF_EDID_STEREO_TYPE_TWO_WAY_LEFT_ON_EVEN,
+  GF_EDID_STEREO_TYPE_FOUR_WAY_INTERLEAVED,
+  GF_EDID_STEREO_TYPE_SIDE_BY_SIDE
+} GfEdidStereoType;
+
+struct _GfEdidTiming
 {
   int width;
   int height;
   int frequency;
 };
 
-struct DetailedTiming
+struct _GfEdidDetailedTiming
 {
   int        pixel_clock;
   int        h_addr;
@@ -81,7 +81,7 @@ struct DetailedTiming
   int        right_border;
   int        top_border;
   int        interlaced;
-  StereoType stereo;
+  GfEdidStereoType stereo;
 
   int        digital_sync;
   union
@@ -103,7 +103,7 @@ struct DetailedTiming
   } connector;
 };
 
-struct MonitorInfo
+struct _GfEdidInfo
 {
   int            checksum;
   char           manufacturer_code[4];
@@ -124,7 +124,7 @@ struct MonitorInfo
     struct
     {
       int        bits_per_primary;
-      Interface  interface;
+      GfEdidInterface interface;
       int        rgb444;
       int        ycrcb444;
       int        ycrcb422;
@@ -142,7 +142,7 @@ struct MonitorInfo
       int        composite_sync_on_h;
       int        composite_sync_on_green;
       int        serration_on_vsync;
-      ColorType  color_type;
+      GfEdidColorType color_type;
     } analog;
   } connector;
 
@@ -169,17 +169,17 @@ struct MonitorInfo
   double         white_x;
   double         white_y;
 
-  Timing         established[24];       /* Terminated by 0x0x0 */
-  Timing         standard[8];
+  GfEdidTiming   established[24];       /* Terminated by 0x0x0 */
+  GfEdidTiming   standard[8];
 
   int            n_detailed_timings;
-  DetailedTiming 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.
-                                         */
+  GfEdidDetailedTiming 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.
+                                             */
 
   /* Optional product description */
   char           dsc_serial_number[14];
@@ -187,7 +187,7 @@ struct MonitorInfo
   char           dsc_string[14];        /* Unspecified ASCII data */
 };
 
-MonitorInfo *decode_edid (const uchar *data);
+GfEdidInfo *gf_edid_info_new_parse (const uint8_t *data);
 
 G_END_DECLS
 
diff --git a/backends/gf-output-info.c b/backends/gf-output-info.c
index 83b5e0a..e920071 100644
--- a/backends/gf-output-info.c
+++ b/backends/gf-output-info.c
@@ -72,7 +72,7 @@ void
 gf_output_info_parse_edid (GfOutputInfo *output_info,
                            GBytes       *edid)
 {
-  MonitorInfo *parsed_edid;
+  GfEdidInfo *parsed_edid;
   gsize len;
 
   if (!edid)
@@ -83,7 +83,7 @@ gf_output_info_parse_edid (GfOutputInfo *output_info,
       return;
     }
 
-  parsed_edid = decode_edid (g_bytes_get_data (edid, &len));
+  parsed_edid = gf_edid_info_new_parse (g_bytes_get_data (edid, &len));
   if (parsed_edid)
     {
       output_info->vendor = g_strndup (parsed_edid->manufacturer_code, 4);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]