xserver: Branch 'master' - 6 commits

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Fri Aug 6 11:39:48 UTC 2021


 .gitlab-ci.yml                   |    2 
 .gitlab-ci/debian-install.sh     |    8 +
 configure.ac                     |   13 +
 hw/xfree86/meson.build           |   15 -
 hw/xfree86/modes/Makefile.am     |    1 
 hw/xfree86/modes/meson.build     |    5 
 hw/xfree86/modes/xf86Modes.c     |   31 ++++
 hw/xfree86/modes/xf86cvt.c       |  295 ---------------------------------------
 hw/xfree86/utils/Makefile.am     |    1 
 hw/xfree86/utils/cvt/.gitignore  |    1 
 hw/xfree86/utils/cvt/Makefile.am |   35 ----
 hw/xfree86/utils/cvt/cvt.c       |  294 --------------------------------------
 hw/xfree86/utils/man/Makefile.am |    2 
 hw/xfree86/utils/man/cvt.man     |   41 -----
 hw/xwayland/Makefile.am          |    6 
 hw/xwayland/xwayland-cvt.c       |  288 ++------------------------------------
 meson.build                      |    2 
 test/meson.build                 |    2 
 18 files changed, 79 insertions(+), 963 deletions(-)

New commits:
commit 7eba412072afdc9d27896410872e40364a8010bf
Author: Olivier Fourdan <ofourdan at redhat.com>
Date:   Fri Mar 26 15:48:23 2021 +0100

    xfree86: Move xf86CVTMode() function
    
    The xf86CVTMode() was implemented in a standalone source file because it
    was being used for both the xfree86 API and the standalone cvt utility.
    
    Now that the cvt utility is removed (as part of libxcvt) we can move the
    small xf86CVTMode() function with the rest of the xf86Modes sources.
    
    Closes: https://gitlab.freedesktop.org/xorg/xserver/-/issues/1142
    Signed-off-by: Olivier Fourdan <ofourdan at redhat.com>
    Reviewed-by: Matt Turner <mattst88 at gmail.com>

diff --git a/hw/xfree86/modes/Makefile.am b/hw/xfree86/modes/Makefile.am
index 6eb162a89..35a174b5b 100644
--- a/hw/xfree86/modes/Makefile.am
+++ b/hw/xfree86/modes/Makefile.am
@@ -8,7 +8,6 @@ libxf86modes_la_SOURCES = \
 	xf86Crtc.c \
 	xf86Crtc.h \
 	xf86Cursors.c \
-	xf86cvt.c \
 	xf86gtf.c \
 	xf86EdidModes.c \
 	xf86Modes.c \
diff --git a/hw/xfree86/modes/meson.build b/hw/xfree86/modes/meson.build
index 52c7ef9b3..8a40018ca 100644
--- a/hw/xfree86/modes/meson.build
+++ b/hw/xfree86/modes/meson.build
@@ -1,7 +1,6 @@
 srcs_xorg_modes = [
     'xf86Crtc.c',
     'xf86Cursors.c',
-    'xf86cvt.c',
     'xf86gtf.c',
     'xf86EdidModes.c',
     'xf86Modes.c',
diff --git a/hw/xfree86/modes/xf86Modes.c b/hw/xfree86/modes/xf86Modes.c
index 5651f1ef8..384996724 100644
--- a/hw/xfree86/modes/xf86Modes.c
+++ b/hw/xfree86/modes/xf86Modes.c
@@ -29,6 +29,7 @@
 #include <xorg-config.h>
 #endif
 
+#include <libxcvt/libxcvt.h>
 #include "xf86Modes.h"
 #include "xf86Priv.h"
 
@@ -792,3 +793,33 @@ xf86PruneDuplicateModes(DisplayModePtr modes)
 
     return modes;
 }
+
+/*
+ * Generate a CVT standard mode from HDisplay, VDisplay and VRefresh.
+ */
+DisplayModePtr
+xf86CVTMode(int HDisplay, int VDisplay, float VRefresh, Bool Reduced,
+            Bool Interlaced)
+{
+    struct libxcvt_mode_info *libxcvt_mode_info;
+    DisplayModeRec *Mode = xnfcalloc(1, sizeof(DisplayModeRec));
+
+    libxcvt_mode_info =
+        libxcvt_gen_mode_info(HDisplay, VDisplay, VRefresh, Reduced, Interlaced);
+
+    Mode->VDisplay   = libxcvt_mode_info->vdisplay;
+    Mode->HDisplay   = libxcvt_mode_info->hdisplay;
+    Mode->Clock      = libxcvt_mode_info->dot_clock;
+    Mode->HSyncStart = libxcvt_mode_info->hsync_start;
+    Mode->HSyncEnd   = libxcvt_mode_info->hsync_end;
+    Mode->HTotal     = libxcvt_mode_info->htotal;
+    Mode->VSyncStart = libxcvt_mode_info->vsync_start;
+    Mode->VSyncEnd   = libxcvt_mode_info->vsync_end;
+    Mode->VTotal     = libxcvt_mode_info->vtotal;
+    Mode->VRefresh   = libxcvt_mode_info->vrefresh;
+    Mode->Flags      = libxcvt_mode_info->mode_flags;
+
+    free(libxcvt_mode_info);
+
+    return Mode;
+}
diff --git a/hw/xfree86/modes/xf86cvt.c b/hw/xfree86/modes/xf86cvt.c
deleted file mode 100644
index be5021c89..000000000
--- a/hw/xfree86/modes/xf86cvt.c
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * Copyright 2005-2006 Luc Verhaegen.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- */
-
-#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-
-#include "xf86.h"
-#include "xf86Modes.h"
-
-#include <string.h>
-#include <libxcvt/libxcvt.h>
-
-/*
- * Generate a CVT standard mode from HDisplay, VDisplay and VRefresh.
- *
- * These calculations are stolen from the CVT calculation spreadsheet written
- * by Graham Loveridge. He seems to be claiming no copyright and there seems to
- * be no license attached to this. He apparently just wants to see his name
- * mentioned.
- *
- * This file can be found at http://www.vesa.org/Public/CVT/CVTd6r1.xls
- *
- * Comments and structure corresponds to the comments and structure of the xls.
- * This should ease importing of future changes to the standard (not very
- * likely though).
- *
- * About margins; i'm sure that they are to be the bit between HDisplay and
- * HBlankStart, HBlankEnd and HTotal, VDisplay and VBlankStart, VBlankEnd and
- * VTotal, where the overscan colour is shown. FB seems to call _all_ blanking
- * outside sync "margin" for some reason. Since we prefer seeing proper
- * blanking instead of the overscan colour, and since the Crtc* values will
- * probably get altered after us, we will disable margins altogether. With
- * these calculations, Margins will plainly expand H/VDisplay, and we don't
- * want that. -- libv
- *
- */
-DisplayModePtr
-xf86CVTMode(int HDisplay, int VDisplay, float VRefresh, Bool Reduced,
-            Bool Interlaced)
-{
-    struct libxcvt_mode_info *libxcvt_mode_info;
-    DisplayModeRec *Mode = xnfcalloc(1, sizeof(DisplayModeRec));
-
-    libxcvt_mode_info =
-        libxcvt_gen_mode_info(HDisplay, VDisplay, VRefresh, Reduced, Interlaced);
-
-    Mode->VDisplay   = libxcvt_mode_info->vdisplay;
-    Mode->HDisplay   = libxcvt_mode_info->hdisplay;
-    Mode->Clock      = libxcvt_mode_info->dot_clock;
-    Mode->HSyncStart = libxcvt_mode_info->hsync_start;
-    Mode->HSyncEnd   = libxcvt_mode_info->hsync_end;
-    Mode->HTotal     = libxcvt_mode_info->htotal;
-    Mode->VSyncStart = libxcvt_mode_info->vsync_start;
-    Mode->VSyncEnd   = libxcvt_mode_info->vsync_end;
-    Mode->VTotal     = libxcvt_mode_info->vtotal;
-    Mode->VRefresh   = libxcvt_mode_info->vrefresh;
-    Mode->Flags      = libxcvt_mode_info->mode_flags;
-
-    free(libxcvt_mode_info);
-
-    return Mode;
-}
commit f2781e95369583259991cd3add6f90f33be32171
Author: Olivier Fourdan <ofourdan at redhat.com>
Date:   Thu Mar 25 10:27:31 2021 +0100

    xfree86/cvt: Drop cvt utility
    
    The cvt utility is now replaced by the standalone version found in
    libxcvt, no need to build the one in xfree86 anymore.
    
    Closes: https://gitlab.freedesktop.org/xorg/xserver/-/issues/1142
    Signed-off-by: Olivier Fourdan <ofourdan at redhat.com>
    Reviewed-by: Matt Turner <mattst88 at gmail.com>

diff --git a/configure.ac b/configure.ac
index e57ba723a..264bbb9d6 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2488,7 +2488,6 @@ hw/xfree86/x86emu/Makefile
 hw/xfree86/xkb/Makefile
 hw/xfree86/utils/Makefile
 hw/xfree86/utils/man/Makefile
-hw/xfree86/utils/cvt/Makefile
 hw/xfree86/utils/gtf/Makefile
 hw/dmx/config/Makefile
 hw/dmx/config/man/Makefile
diff --git a/hw/xfree86/meson.build b/hw/xfree86/meson.build
index a13d4aab4..7d3693fba 100644
--- a/hw/xfree86/meson.build
+++ b/hw/xfree86/meson.build
@@ -171,15 +171,6 @@ if get_option('suid_wrapper')
     )
 endif
 
-executable('cvt',
-    ['utils/cvt/cvt.c', 'modes/xf86cvt.c'],
-    include_directories: [inc, xorg_inc],
-    dependencies: [ xorg_deps, libxcvt_dep ],
-    link_with: libxserver_os,
-    c_args: xorg_c_args,
-    install: true,
-)
-
 executable('gtf',
     'utils/gtf/gtf.c',
     include_directories: [inc, xorg_inc],
@@ -234,12 +225,6 @@ install_man(configure_file(
     configuration: manpage_config,
 ))
 
-install_man(configure_file(
-    input: 'utils/man/cvt.man',
-    output: 'cvt.1',
-    configuration: manpage_config,
-))
-
 install_man(configure_file(
     input: 'utils/man/gtf.man',
     output: 'gtf.1',
diff --git a/hw/xfree86/utils/Makefile.am b/hw/xfree86/utils/Makefile.am
index 71f979048..ce83bc3b1 100644
--- a/hw/xfree86/utils/Makefile.am
+++ b/hw/xfree86/utils/Makefile.am
@@ -1,4 +1,3 @@
 SUBDIRS = \
 	gtf \
-	cvt \
 	man
diff --git a/hw/xfree86/utils/cvt/.gitignore b/hw/xfree86/utils/cvt/.gitignore
deleted file mode 100644
index a217c5563..000000000
--- a/hw/xfree86/utils/cvt/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-cvt
diff --git a/hw/xfree86/utils/cvt/Makefile.am b/hw/xfree86/utils/cvt/Makefile.am
deleted file mode 100644
index be56ddbea..000000000
--- a/hw/xfree86/utils/cvt/Makefile.am
+++ /dev/null
@@ -1,36 +0,0 @@
-# Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
-#
-# Permission is hereby granted, free of charge, to any person obtaining a
-# copy of this software and associated documentation files (the "Software"),
-# to deal in the Software without restriction, including without limitation
-# the rights to use, copy, modify, merge, publish, distribute, sublicense,
-# and/or sell copies of the Software, and to permit persons to whom the
-# Software is furnished to do so, subject to the following conditions:
-#
-# The above copyright notice and this permission notice (including the next
-# paragraph) shall be included in all copies or substantial portions of the
-# Software.
-#
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
-# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
-# DEALINGS IN THE SOFTWARE.
-# 
-
-bin_PROGRAMS = cvt
-
-AM_CPPFLAGS = $(XORG_INCS) \
-	   -I$(top_srcdir)/hw/xfree86/ddc \
-	   -I$(top_srcdir)/hw/xfree86/modes \
-	   -I$(top_srcdir)/hw/xfree86/parser
-
-# gah
-cvt_SOURCES = cvt.c \
-	$(top_srcdir)/hw/xfree86/modes/xf86cvt.c \
-	$(top_srcdir)/os/xprintf.c
-
-cvt_CFLAGS = $(DIX_CFLAGS) $(XORG_CFLAGS)
-cvt_LDADD = $(LIBXCVT_LIBS)
diff --git a/hw/xfree86/utils/cvt/cvt.c b/hw/xfree86/utils/cvt/cvt.c
deleted file mode 100644
index 8e5bc1aeb..000000000
--- a/hw/xfree86/utils/cvt/cvt.c
+++ /dev/null
@@ -1,294 +0,0 @@
-/*
- * Copyright 2005-2006 Luc Verhaegen.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- *
- */
-
-/* Standalone VESA CVT standard timing modelines generator. */
-
-#include "xf86.h"
-#include "xf86Modes.h"
-
-/* FatalError implementation used by the server code we built in */
-void
-FatalError(const char *f, ...)
-{
-    va_list args;
-
-    va_start(args, f);
-    vfprintf(stderr, f, args);
-    va_end(args);
-    exit(1);
-}
-
-/* xnfalloc implementation used by the server code we built in */
-void *
-XNFalloc(unsigned long n)
-{
-    void *r;
-
-    r = malloc(n);
-    if (!r) {
-        perror("malloc failed");
-        exit(1);
-    }
-    return r;
-}
-
-/* xnfcalloc implementation used by the server code we built in */
-void *
-XNFcallocarray(size_t nmemb, size_t size)
-{
-    void *r;
-
-    r = calloc(nmemb, size);
-    if (!r) {
-        perror("calloc failed");
-        exit(1);
-    }
-    return r;
-}
-
-/*
- * Quickly check whether this is a CVT standard mode.
- */
-static Bool
-CVTCheckStandard(int HDisplay, int VDisplay, float VRefresh, Bool Reduced,
-                 Bool Verbose)
-{
-    Bool IsCVT = TRUE;
-
-    if ((!(VDisplay % 3) && ((VDisplay * 4 / 3) == HDisplay)) ||
-        (!(VDisplay % 9) && ((VDisplay * 16 / 9) == HDisplay)) ||
-        (!(VDisplay % 10) && ((VDisplay * 16 / 10) == HDisplay)) ||
-        (!(VDisplay % 4) && ((VDisplay * 5 / 4) == HDisplay)) ||
-        (!(VDisplay % 9) && ((VDisplay * 15 / 9) == HDisplay)));
-    else {
-        if (Verbose)
-            fprintf(stderr, "Warning: Aspect Ratio is not CVT standard.\n");
-        IsCVT = FALSE;
-    }
-
-    if ((VRefresh != 50.0) && (VRefresh != 60.0) &&
-        (VRefresh != 75.0) && (VRefresh != 85.0)) {
-        if (Verbose)
-            fprintf(stderr, "Warning: Refresh Rate is not CVT standard "
-                    "(50, 60, 75 or 85Hz).\n");
-        IsCVT = FALSE;
-    }
-
-    return IsCVT;
-}
-
-/*
- * I'm not documenting --interlaced for obvious reasons, even though I did
- * implement it. I also can't deny having looked at gtf here.
- */
-static void
-PrintUsage(char *Name)
-{
-    fprintf(stderr, "\n");
-    fprintf(stderr, "usage: %s [-v|--verbose] [-r|--reduced] X Y [refresh]\n",
-            Name);
-    fprintf(stderr, "\n");
-    fprintf(stderr, " -v|--verbose : Warn about CVT standard adherence.\n");
-    fprintf(stderr, " -r|--reduced : Create a mode with reduced blanking "
-            "(default: normal blanking).\n");
-    fprintf(stderr, "            X : Desired horizontal resolution "
-            "(multiple of 8, required).\n");
-    fprintf(stderr,
-            "            Y : Desired vertical resolution (required).\n");
-    fprintf(stderr,
-            "      refresh : Desired refresh rate (default: 60.0Hz).\n");
-    fprintf(stderr, "\n");
-
-    fprintf(stderr, "Calculates VESA CVT (Coordinated Video Timing) modelines"
-            " for use with X.\n");
-}
-
-/*
- *
- */
-static void
-PrintComment(DisplayModeRec * Mode, Bool CVT, Bool Reduced)
-{
-    printf("# %dx%d %.2f Hz ", Mode->HDisplay, Mode->VDisplay, Mode->VRefresh);
-
-    if (CVT) {
-        printf("(CVT %.2fM",
-               ((float) Mode->HDisplay * Mode->VDisplay) / 1000000.0);
-
-        if (!(Mode->VDisplay % 3) &&
-            ((Mode->VDisplay * 4 / 3) == Mode->HDisplay))
-            printf("3");
-        else if (!(Mode->VDisplay % 9) &&
-                 ((Mode->VDisplay * 16 / 9) == Mode->HDisplay))
-            printf("9");
-        else if (!(Mode->VDisplay % 10) &&
-                 ((Mode->VDisplay * 16 / 10) == Mode->HDisplay))
-            printf("A");
-        else if (!(Mode->VDisplay % 4) &&
-                 ((Mode->VDisplay * 5 / 4) == Mode->HDisplay))
-            printf("4");
-        else if (!(Mode->VDisplay % 9) &&
-                 ((Mode->VDisplay * 15 / 9) == Mode->HDisplay))
-            printf("9");
-
-        if (Reduced)
-            printf("-R");
-
-        printf(") ");
-    }
-    else
-        printf("(CVT) ");
-
-    printf("hsync: %.2f kHz; ", Mode->HSync);
-    printf("pclk: %.2f MHz", ((float) Mode->Clock) / 1000.0);
-
-    printf("\n");
-}
-
-/*
- * Originally grabbed from xf86Mode.c.
- *
- * Ignoring the actual Mode->name, as the user will want something solid
- * to grab hold of.
- */
-static void
-PrintModeline(DisplayModePtr Mode, int HDisplay, int VDisplay, float VRefresh,
-              Bool Reduced)
-{
-    if (Reduced)
-        printf("Modeline \"%dx%dR\"  ", HDisplay, VDisplay);
-    else
-        printf("Modeline \"%dx%d_%.2f\"  ", HDisplay, VDisplay, VRefresh);
-
-    printf("%6.2f  %i %i %i %i  %i %i %i %i", Mode->Clock / 1000.,
-           Mode->HDisplay, Mode->HSyncStart, Mode->HSyncEnd, Mode->HTotal,
-           Mode->VDisplay, Mode->VSyncStart, Mode->VSyncEnd, Mode->VTotal);
-
-    if (Mode->Flags & V_INTERLACE)
-        printf(" interlace");
-    if (Mode->Flags & V_PHSYNC)
-        printf(" +hsync");
-    if (Mode->Flags & V_NHSYNC)
-        printf(" -hsync");
-    if (Mode->Flags & V_PVSYNC)
-        printf(" +vsync");
-    if (Mode->Flags & V_NVSYNC)
-        printf(" -vsync");
-
-    printf("\n");
-}
-
-/*
- *
- */
-int
-main(int argc, char *argv[])
-{
-    DisplayModeRec *Mode;
-    int HDisplay = 0, VDisplay = 0;
-    float VRefresh = 0.0;
-    Bool Reduced = FALSE, Verbose = FALSE, IsCVT;
-    Bool Interlaced = FALSE;
-    int n;
-
-    if ((argc < 3) || (argc > 7)) {
-        PrintUsage(argv[0]);
-        return 1;
-    }
-
-    /* This doesn't filter out bad flags properly. Bad flags get passed down
-     * to atoi/atof, which then return 0, so that these variables can get
-     * filled next time round. So this is just a cosmetic problem.
-     */
-    for (n = 1; n < argc; n++) {
-        if (!strcmp(argv[n], "-r") || !strcmp(argv[n], "--reduced"))
-            Reduced = TRUE;
-        else if (!strcmp(argv[n], "-i") || !strcmp(argv[n], "--interlaced"))
-            Interlaced = TRUE;
-        else if (!strcmp(argv[n], "-v") || !strcmp(argv[n], "--verbose"))
-            Verbose = TRUE;
-        else if (!strcmp(argv[n], "-h") || !strcmp(argv[n], "--help")) {
-            PrintUsage(argv[0]);
-            return 0;
-        }
-        else if (!HDisplay) {
-            HDisplay = atoi(argv[n]);
-            if (!HDisplay) {
-                PrintUsage(argv[0]);
-                return 1;
-            }
-        }
-        else if (!VDisplay) {
-            VDisplay = atoi(argv[n]);
-            if (!VDisplay) {
-                PrintUsage(argv[0]);
-                return 1;
-            }
-        }
-        else if (!VRefresh) {
-            VRefresh = atof(argv[n]);
-            if (!VRefresh) {
-                PrintUsage(argv[0]);
-                return 1;
-            }
-        }
-        else {
-            PrintUsage(argv[0]);
-            return 1;
-        }
-    }
-
-    if (!HDisplay || !VDisplay) {
-        PrintUsage(argv[0]);
-        return 0;
-    }
-
-    /* Default to 60.0Hz */
-    if (!VRefresh)
-        VRefresh = 60.0;
-
-    /* Horizontal timing is always a multiple of 8: round up. */
-    if (HDisplay & 0x07) {
-        HDisplay &= ~0x07;
-        HDisplay += 8;
-    }
-
-    if (Reduced) {
-        if ((VRefresh / 60.0) != floor(VRefresh / 60.0)) {
-            fprintf(stderr,
-                    "\nERROR: Multiple of 60Hz refresh rate required for "
-                    " reduced blanking.\n");
-            PrintUsage(argv[0]);
-            return 0;
-        }
-    }
-
-    IsCVT = CVTCheckStandard(HDisplay, VDisplay, VRefresh, Reduced, Verbose);
-
-    Mode = xf86CVTMode(HDisplay, VDisplay, VRefresh, Reduced, Interlaced);
-
-    PrintComment(Mode, IsCVT, Reduced);
-    PrintModeline(Mode, HDisplay, VDisplay, VRefresh, Reduced);
-
-    return 0;
-}
diff --git a/hw/xfree86/utils/man/Makefile.am b/hw/xfree86/utils/man/Makefile.am
index 7afc5bcca..25b3b6a4f 100644
--- a/hw/xfree86/utils/man/Makefile.am
+++ b/hw/xfree86/utils/man/Makefile.am
@@ -1,2 +1,2 @@
 include $(top_srcdir)/manpages.am
-appman_PRE = cvt.man gtf.man
+appman_PRE = gtf.man
diff --git a/hw/xfree86/utils/man/cvt.man b/hw/xfree86/utils/man/cvt.man
deleted file mode 100644
index 009ab6540..000000000
--- a/hw/xfree86/utils/man/cvt.man
+++ /dev/null
@@ -1,41 +0,0 @@
-.TH CVT 1 @vendorversion@
-.SH NAME
-cvt - calculate VESA CVT mode lines
-.SH SYNOPSIS
-.B cvt
-.RB [ \-v | \-\-verbose ]
-.RB [ \-r | \-\-reduced ]
-.I h-resolution
-.I v-resolution
-.RB [ refresh ]
-.SH DESCRIPTION
-.I Cvt
-is a utility for calculating VESA Coordinated Video Timing modes.  Given the
-desired horizontal and vertical resolutions, a modeline adhering to the CVT
-standard is printed. This modeline can be included in Xorg
-.B xorg.conf(@filemansuffix@)
-.
-
-.SH OPTIONS
-.TP 8
-.BR refresh
-Provide a vertical refresh rate in Hz.  The CVT standard prefers either 50.0,
-60.0, 75.0 or 85.0Hz.  The default is 60.0Hz.
-.TP 8
-.BR \-v | \-\-verbose
-Warn verbosely when a given mode does not completely correspond with CVT
-standards.
-.TP 8
-.BR \-r | \-\-reduced
-Create a mode with reduced blanking.  This allows for higher frequency signals,
-with a lower or equal dotclock. Not for Cathode Ray Tube based displays though.
-
-.SH "SEE ALSO"
-xorg.conf(@filemansuffix@), gtf(@appmansuffix@)
-.SH AUTHOR
-Luc Verhaegen.
-.PP
-This program is based on the Coordinated Video Timing sample
-implementation written by Graham Loveridge. This file is publicly
-available at <http://www.vesa.org/Public/CVT/CVTd6r1.xls>. CVT is a
-VESA trademark.
commit f788289bdcc4f04bd2fb62552df1c8c1ae0aea45
Author: Olivier Fourdan <ofourdan at redhat.com>
Date:   Thu Mar 25 10:19:55 2021 +0100

    xfree86: Use libxcvt
    
    Replace the local implementation of the VESA CVT standard timing
    modelines generator with the one from libxct to avoid code duplication.
    
    Closes: https://gitlab.freedesktop.org/xorg/xserver/-/issues/1142
    Signed-off-by: Olivier Fourdan <ofourdan at redhat.com>
    Reviewed-by: Matt Turner <mattst88 at gmail.com>

diff --git a/hw/xfree86/meson.build b/hw/xfree86/meson.build
index b1b5920a5..a13d4aab4 100644
--- a/hw/xfree86/meson.build
+++ b/hw/xfree86/meson.build
@@ -174,7 +174,7 @@ endif
 executable('cvt',
     ['utils/cvt/cvt.c', 'modes/xf86cvt.c'],
     include_directories: [inc, xorg_inc],
-    dependencies: xorg_deps,
+    dependencies: [ xorg_deps, libxcvt_dep ],
     link_with: libxserver_os,
     c_args: xorg_c_args,
     install: true,
diff --git a/hw/xfree86/modes/meson.build b/hw/xfree86/modes/meson.build
index ddacca158..52c7ef9b3 100644
--- a/hw/xfree86/modes/meson.build
+++ b/hw/xfree86/modes/meson.build
@@ -15,8 +15,8 @@ endif
 
 xorg_modes = static_library('xorg_modes',
     srcs_xorg_modes,
-    include_directories: [inc, xorg_inc],
-    dependencies: common_dep,
+    include_directories: [ inc, xorg_inc ],
+    dependencies: [ common_dep, libxcvt_dep ],
     c_args: xorg_c_args,
 )
 
diff --git a/hw/xfree86/modes/xf86cvt.c b/hw/xfree86/modes/xf86cvt.c
index c0a342040..be5021c89 100644
--- a/hw/xfree86/modes/xf86cvt.c
+++ b/hw/xfree86/modes/xf86cvt.c
@@ -20,12 +20,6 @@
  * OTHER DEALINGS IN THE SOFTWARE.
  */
 
-/*
- * The reason for having this function in a file of its own is
- * so that ../utils/cvt/cvt can link to it, and that xf86CVTMode
- * code is shared directly.
- */
-
 #ifdef HAVE_XORG_CONFIG_H
 #include <xorg-config.h>
 #endif
@@ -34,6 +28,7 @@
 #include "xf86Modes.h"
 
 #include <string.h>
+#include <libxcvt/libxcvt.h>
 
 /*
  * Generate a CVT standard mode from HDisplay, VDisplay and VRefresh.
@@ -63,233 +58,25 @@ DisplayModePtr
 xf86CVTMode(int HDisplay, int VDisplay, float VRefresh, Bool Reduced,
             Bool Interlaced)
 {
+    struct libxcvt_mode_info *libxcvt_mode_info;
     DisplayModeRec *Mode = xnfcalloc(1, sizeof(DisplayModeRec));
 
-    /* 1) top/bottom margin size (% of height) - default: 1.8 */
-#define CVT_MARGIN_PERCENTAGE 1.8
-
-    /* 2) character cell horizontal granularity (pixels) - default 8 */
-#define CVT_H_GRANULARITY 8
-
-    /* 4) Minimum vertical porch (lines) - default 3 */
-#define CVT_MIN_V_PORCH 3
-
-    /* 4) Minimum number of vertical back porch lines - default 6 */
-#define CVT_MIN_V_BPORCH 6
-
-    /* Pixel Clock step (kHz) */
-#define CVT_CLOCK_STEP 250
-
-    Bool Margins = FALSE;
-    float VFieldRate, HPeriod;
-    int HDisplayRnd, HMargin;
-    int VDisplayRnd, VMargin, VSync;
-    float Interlace;            /* Please rename this */
-    char *tmp;
-
-    /* CVT default is 60.0Hz */
-    if (!VRefresh)
-        VRefresh = 60.0;
-
-    /* 1. Required field rate */
-    if (Interlaced)
-        VFieldRate = VRefresh * 2;
-    else
-        VFieldRate = VRefresh;
-
-    /* 2. Horizontal pixels */
-    HDisplayRnd = HDisplay - (HDisplay % CVT_H_GRANULARITY);
-
-    /* 3. Determine left and right borders */
-    if (Margins) {
-        /* right margin is actually exactly the same as left */
-        HMargin = (((float) HDisplayRnd) * CVT_MARGIN_PERCENTAGE / 100.0);
-        HMargin -= HMargin % CVT_H_GRANULARITY;
-    }
-    else
-        HMargin = 0;
-
-    /* 4. Find total active pixels */
-    Mode->HDisplay = HDisplayRnd + 2 * HMargin;
-
-    /* 5. Find number of lines per field */
-    if (Interlaced)
-        VDisplayRnd = VDisplay / 2;
-    else
-        VDisplayRnd = VDisplay;
-
-    /* 6. Find top and bottom margins */
-    /* nope. */
-    if (Margins)
-        /* top and bottom margins are equal again. */
-        VMargin = (((float) VDisplayRnd) * CVT_MARGIN_PERCENTAGE / 100.0);
-    else
-        VMargin = 0;
-
-    Mode->VDisplay = VDisplay + 2 * VMargin;
-
-    /* 7. Interlace */
-    if (Interlaced)
-        Interlace = 0.5;
-    else
-        Interlace = 0.0;
-
-    /* Determine VSync Width from aspect ratio */
-    if (!(VDisplay % 3) && ((VDisplay * 4 / 3) == HDisplay))
-        VSync = 4;
-    else if (!(VDisplay % 9) && ((VDisplay * 16 / 9) == HDisplay))
-        VSync = 5;
-    else if (!(VDisplay % 10) && ((VDisplay * 16 / 10) == HDisplay))
-        VSync = 6;
-    else if (!(VDisplay % 4) && ((VDisplay * 5 / 4) == HDisplay))
-        VSync = 7;
-    else if (!(VDisplay % 9) && ((VDisplay * 15 / 9) == HDisplay))
-        VSync = 7;
-    else                        /* Custom */
-        VSync = 10;
-
-    if (!Reduced) {             /* simplified GTF calculation */
-
-        /* 4) Minimum time of vertical sync + back porch interval (µs)
-         * default 550.0 */
-#define CVT_MIN_VSYNC_BP 550.0
-
-        /* 3) Nominal HSync width (% of line period) - default 8 */
-#define CVT_HSYNC_PERCENTAGE 8
-
-        float HBlankPercentage;
-        int VSyncAndBackPorch, VBackPorch;
-        int HBlank;
-
-        /* 8. Estimated Horizontal period */
-        HPeriod = ((float) (1000000.0 / VFieldRate - CVT_MIN_VSYNC_BP)) /
-            (VDisplayRnd + 2 * VMargin + CVT_MIN_V_PORCH + Interlace);
-
-        /* 9. Find number of lines in sync + backporch */
-        if (((int) (CVT_MIN_VSYNC_BP / HPeriod) + 1) <
-            (VSync + CVT_MIN_V_PORCH))
-            VSyncAndBackPorch = VSync + CVT_MIN_V_PORCH;
-        else
-            VSyncAndBackPorch = (int) (CVT_MIN_VSYNC_BP / HPeriod) + 1;
-
-        /* 10. Find number of lines in back porch */
-        VBackPorch = VSyncAndBackPorch - VSync;
-        (void) VBackPorch;
-
-        /* 11. Find total number of lines in vertical field */
-        Mode->VTotal = VDisplayRnd + 2 * VMargin + VSyncAndBackPorch + Interlace
-            + CVT_MIN_V_PORCH;
-
-        /* 5) Definition of Horizontal blanking time limitation */
-        /* Gradient (%/kHz) - default 600 */
-#define CVT_M_FACTOR 600
-
-        /* Offset (%) - default 40 */
-#define CVT_C_FACTOR 40
-
-        /* Blanking time scaling factor - default 128 */
-#define CVT_K_FACTOR 128
-
-        /* Scaling factor weighting - default 20 */
-#define CVT_J_FACTOR 20
-
-#define CVT_M_PRIME CVT_M_FACTOR * CVT_K_FACTOR / 256
-#define CVT_C_PRIME (CVT_C_FACTOR - CVT_J_FACTOR) * CVT_K_FACTOR / 256 + \
-        CVT_J_FACTOR
-
-        /* 12. Find ideal blanking duty cycle from formula */
-        HBlankPercentage = CVT_C_PRIME - CVT_M_PRIME * HPeriod / 1000.0;
-
-        /* 13. Blanking time */
-        if (HBlankPercentage < 20)
-            HBlankPercentage = 20;
-
-        HBlank = Mode->HDisplay * HBlankPercentage / (100.0 - HBlankPercentage);
-        HBlank -= HBlank % (2 * CVT_H_GRANULARITY);
-
-        /* 14. Find total number of pixels in a line. */
-        Mode->HTotal = Mode->HDisplay + HBlank;
-
-        /* Fill in HSync values */
-        Mode->HSyncEnd = Mode->HDisplay + HBlank / 2;
-
-        Mode->HSyncStart = Mode->HSyncEnd -
-            (Mode->HTotal * CVT_HSYNC_PERCENTAGE) / 100;
-        Mode->HSyncStart += CVT_H_GRANULARITY -
-            Mode->HSyncStart % CVT_H_GRANULARITY;
-
-        /* Fill in VSync values */
-        Mode->VSyncStart = Mode->VDisplay + CVT_MIN_V_PORCH;
-        Mode->VSyncEnd = Mode->VSyncStart + VSync;
-
-    }
-    else {                      /* Reduced blanking */
-        /* Minimum vertical blanking interval time (µs) - default 460 */
-#define CVT_RB_MIN_VBLANK 460.0
-
-        /* Fixed number of clocks for horizontal sync */
-#define CVT_RB_H_SYNC 32.0
-
-        /* Fixed number of clocks for horizontal blanking */
-#define CVT_RB_H_BLANK 160.0
-
-        /* Fixed number of lines for vertical front porch - default 3 */
-#define CVT_RB_VFPORCH 3
-
-        int VBILines;
-
-        /* 8. Estimate Horizontal period. */
-        HPeriod = ((float) (1000000.0 / VFieldRate - CVT_RB_MIN_VBLANK)) /
-            (VDisplayRnd + 2 * VMargin);
-
-        /* 9. Find number of lines in vertical blanking */
-        VBILines = ((float) CVT_RB_MIN_VBLANK) / HPeriod + 1;
-
-        /* 10. Check if vertical blanking is sufficient */
-        if (VBILines < (CVT_RB_VFPORCH + VSync + CVT_MIN_V_BPORCH))
-            VBILines = CVT_RB_VFPORCH + VSync + CVT_MIN_V_BPORCH;
-
-        /* 11. Find total number of lines in vertical field */
-        Mode->VTotal = VDisplayRnd + 2 * VMargin + Interlace + VBILines;
-
-        /* 12. Find total number of pixels in a line */
-        Mode->HTotal = Mode->HDisplay + CVT_RB_H_BLANK;
-
-        /* Fill in HSync values */
-        Mode->HSyncEnd = Mode->HDisplay + CVT_RB_H_BLANK / 2;
-        Mode->HSyncStart = Mode->HSyncEnd - CVT_RB_H_SYNC;
-
-        /* Fill in VSync values */
-        Mode->VSyncStart = Mode->VDisplay + CVT_RB_VFPORCH;
-        Mode->VSyncEnd = Mode->VSyncStart + VSync;
-    }
-
-    /* 15/13. Find pixel clock frequency (kHz for xf86) */
-    Mode->Clock = Mode->HTotal * 1000.0 / HPeriod;
-    Mode->Clock -= Mode->Clock % CVT_CLOCK_STEP;
-
-    /* 16/14. Find actual Horizontal Frequency (kHz) */
-    Mode->HSync = ((float) Mode->Clock) / ((float) Mode->HTotal);
-
-    /* 17/15. Find actual Field rate */
-    Mode->VRefresh = (1000.0 * ((float) Mode->Clock)) /
-        ((float) (Mode->HTotal * Mode->VTotal));
-
-    /* 18/16. Find actual vertical frame frequency */
-    /* ignore - just set the mode flag for interlaced */
-    if (Interlaced)
-        Mode->VTotal *= 2;
-
-    XNFasprintf(&tmp, "%dx%d", HDisplay, VDisplay);
-    Mode->name = tmp;
-
-    if (Reduced)
-        Mode->Flags |= V_PHSYNC | V_NVSYNC;
-    else
-        Mode->Flags |= V_NHSYNC | V_PVSYNC;
-
-    if (Interlaced)
-        Mode->Flags |= V_INTERLACE;
+    libxcvt_mode_info =
+        libxcvt_gen_mode_info(HDisplay, VDisplay, VRefresh, Reduced, Interlaced);
+
+    Mode->VDisplay   = libxcvt_mode_info->vdisplay;
+    Mode->HDisplay   = libxcvt_mode_info->hdisplay;
+    Mode->Clock      = libxcvt_mode_info->dot_clock;
+    Mode->HSyncStart = libxcvt_mode_info->hsync_start;
+    Mode->HSyncEnd   = libxcvt_mode_info->hsync_end;
+    Mode->HTotal     = libxcvt_mode_info->htotal;
+    Mode->VSyncStart = libxcvt_mode_info->vsync_start;
+    Mode->VSyncEnd   = libxcvt_mode_info->vsync_end;
+    Mode->VTotal     = libxcvt_mode_info->vtotal;
+    Mode->VRefresh   = libxcvt_mode_info->vrefresh;
+    Mode->Flags      = libxcvt_mode_info->mode_flags;
+
+    free(libxcvt_mode_info);
 
     return Mode;
 }
diff --git a/hw/xfree86/utils/cvt/Makefile.am b/hw/xfree86/utils/cvt/Makefile.am
index 26abeb40b..be56ddbea 100644
--- a/hw/xfree86/utils/cvt/Makefile.am
+++ b/hw/xfree86/utils/cvt/Makefile.am
@@ -33,3 +33,4 @@ cvt_SOURCES = cvt.c \
 	$(top_srcdir)/os/xprintf.c
 
 cvt_CFLAGS = $(DIX_CFLAGS) $(XORG_CFLAGS)
+cvt_LDADD = $(LIBXCVT_LIBS)
diff --git a/test/meson.build b/test/meson.build
index 91ea15723..4a79394e4 100644
--- a/test/meson.build
+++ b/test/meson.build
@@ -182,7 +182,7 @@ if build_xorg
     unit = executable('tests',
          unit_sources,
          c_args: unit_c_args,
-         dependencies: [pixman_dep, randrproto_dep, inputproto_dep],
+         dependencies: [pixman_dep, randrproto_dep, inputproto_dep, libxcvt_dep],
          include_directories: unit_includes,
          link_args: ldwraps,
          link_with: xorg_link,
commit 6ea2c001f9d23c91113b937fb99053e262d21df6
Author: Olivier Fourdan <ofourdan at redhat.com>
Date:   Thu Mar 25 10:17:49 2021 +0100

    xwayland: Use libxcvt
    
    Xwayland is using a copy of the CVT generator found in Xorg.
    
    Rather than duplicating the code within the xserver tree, use the
    libxcvt implementation instead.
    
    Closes: https://gitlab.freedesktop.org/xorg/xserver/-/issues/1142
    Signed-off-by: Olivier Fourdan <ofourdan at redhat.com>
    Reviewed-by: Matt Turner <mattst88 at gmail.com>

diff --git a/hw/xwayland/Makefile.am b/hw/xwayland/Makefile.am
index 088ec5e66..0060df70a 100644
--- a/hw/xwayland/Makefile.am
+++ b/hw/xwayland/Makefile.am
@@ -12,7 +12,8 @@ Xwayland_CFLAGS =				\
 	$(XWAYLANDMODULES_CFLAGS)		\
 	$(DIX_CFLAGS)				\
 	$(GLAMOR_CFLAGS)			\
-	$(GBM_CFLAGS)
+	$(GBM_CFLAGS)				\
+	$(LIBXCVT_CFLAGS)
 
 Xwayland_SOURCES =				\
 	xwayland.c				\
@@ -60,7 +61,8 @@ Xwayland_LDADD =				\
 	$(GLXVND_LIB)				\
 	$(XWAYLAND_SYS_LIBS)			\
 	$(top_builddir)/Xext/libXvidmode.la	\
-	$(XSERVER_SYS_LIBS)
+	$(XSERVER_SYS_LIBS)			\
+	$(LIBXCVT_LIBS)
 Xwayland_LDFLAGS = $(LD_EXPORT_SYMBOLS_FLAG)
 
 Xwayland_built_sources =
diff --git a/hw/xwayland/xwayland-cvt.c b/hw/xwayland/xwayland-cvt.c
index 1bc3cec92..ba8cbc9d1 100644
--- a/hw/xwayland/xwayland-cvt.c
+++ b/hw/xwayland/xwayland-cvt.c
@@ -1,8 +1,6 @@
-/* Copied from hw/xfree86/modes/xf86cvt.c into xwayland DDX and
- * changed to generate an RRMode */
-
 /*
  * Copyright 2005-2006 Luc Verhaegen.
+ * Copyright © 2021 Red Hat, Inc.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
@@ -23,284 +21,38 @@
  * OTHER DEALINGS IN THE SOFTWARE.
  */
 
-/*
- * The reason for having this function in a file of its own is
- * so that ../utils/cvt/cvt can link to it, and that xf86CVTMode
- * code is shared directly.
- */
-
 #include <xwayland-config.h>
 
 #include <string.h>
 #include <randrstr.h>
+#include <libxcvt/libxcvt.h>
 
 #include "xwayland-cvt.h"
 
-/*
- * Generate a CVT standard mode from HDisplay, VDisplay and VRefresh.
- *
- * These calculations are stolen from the CVT calculation spreadsheet written
- * by Graham Loveridge. He seems to be claiming no copyright and there seems to
- * be no license attached to this. He apparently just wants to see his name
- * mentioned.
- *
- * This file can be found at http://www.vesa.org/Public/CVT/CVTd6r1.xls
- *
- * Comments and structure corresponds to the comments and structure of the xls.
- * This should ease importing of future changes to the standard (not very
- * likely though).
- *
- * About margins; i'm sure that they are to be the bit between HDisplay and
- * HBlankStart, HBlankEnd and HTotal, VDisplay and VBlankStart, VBlankEnd and
- * VTotal, where the overscan colour is shown. FB seems to call _all_ blanking
- * outside sync "margin" for some reason. Since we prefer seeing proper
- * blanking instead of the overscan colour, and since the Crtc* values will
- * probably get altered after us, we will disable margins altogether. With
- * these calculations, Margins will plainly expand H/VDisplay, and we don't
- * want that. -- libv
- *
- */
 RRModePtr
-xwayland_cvt(int HDisplay, int VDisplay, float VRefresh, Bool Reduced,
-             Bool Interlaced)
+xwayland_cvt(int hdisplay, int vdisplay, float vrefresh, Bool reduced,
+             Bool interlaced)
 {
-    /* 1) top/bottom margin size (% of height) - default: 1.8 */
-#define CVT_MARGIN_PERCENTAGE 1.8
-
-    /* 2) character cell horizontal granularity (pixels) - default 8 */
-#define CVT_H_GRANULARITY 8
-
-    /* 4) Minimum vertical porch (lines) - default 3 */
-#define CVT_MIN_V_PORCH 3
-
-    /* 4) Minimum number of vertical back porch lines - default 6 */
-#define CVT_MIN_V_BPORCH 6
-
-    /* Pixel Clock step (kHz) */
-#define CVT_CLOCK_STEP 250
-
-    Bool Margins = FALSE;
-    float VFieldRate, HPeriod;
-    int HDisplayRnd, HMargin;
-    int VDisplayRnd, VMargin, VSync;
-    float Interlace;            /* Please rename this */
+    struct libxcvt_mode_info *libxcvt_mode_info;
     char name[128];
     xRRModeInfo modeinfo;
 
-    memset(&modeinfo, 0, sizeof modeinfo);
-
-    /* CVT default is 60.0Hz */
-    if (!VRefresh)
-        VRefresh = 60.0;
-
-    /* 1. Required field rate */
-    if (Interlaced)
-        VFieldRate = VRefresh * 2;
-    else
-        VFieldRate = VRefresh;
-
-    /* 2. Horizontal pixels */
-    HDisplayRnd = HDisplay - (HDisplay % CVT_H_GRANULARITY);
-
-    /* 3. Determine left and right borders */
-    if (Margins) {
-        /* right margin is actually exactly the same as left */
-        HMargin = (((float) HDisplayRnd) * CVT_MARGIN_PERCENTAGE / 100.0);
-        HMargin -= HMargin % CVT_H_GRANULARITY;
-    }
-    else
-        HMargin = 0;
-
-    /* 4. Find total active pixels */
-    modeinfo.width = HDisplayRnd + 2 * HMargin;
-
-    /* 5. Find number of lines per field */
-    if (Interlaced)
-        VDisplayRnd = VDisplay / 2;
-    else
-        VDisplayRnd = VDisplay;
-
-    /* 6. Find top and bottom margins */
-    /* nope. */
-    if (Margins)
-        /* top and bottom margins are equal again. */
-        VMargin = (((float) VDisplayRnd) * CVT_MARGIN_PERCENTAGE / 100.0);
-    else
-        VMargin = 0;
-
-    modeinfo.height = VDisplay + 2 * VMargin;
-
-    /* 7. Interlace */
-    if (Interlaced)
-        Interlace = 0.5;
-    else
-        Interlace = 0.0;
-
-    /* Determine VSync Width from aspect ratio */
-    if (!(VDisplay % 3) && ((VDisplay * 4 / 3) == HDisplay))
-        VSync = 4;
-    else if (!(VDisplay % 9) && ((VDisplay * 16 / 9) == HDisplay))
-        VSync = 5;
-    else if (!(VDisplay % 10) && ((VDisplay * 16 / 10) == HDisplay))
-        VSync = 6;
-    else if (!(VDisplay % 4) && ((VDisplay * 5 / 4) == HDisplay))
-        VSync = 7;
-    else if (!(VDisplay % 9) && ((VDisplay * 15 / 9) == HDisplay))
-        VSync = 7;
-    else                        /* Custom */
-        VSync = 10;
-
-    if (!Reduced) {             /* simplified GTF calculation */
-
-        /* 4) Minimum time of vertical sync + back porch interval (µs)
-         * default 550.0 */
-#define CVT_MIN_VSYNC_BP 550.0
-
-        /* 3) Nominal HSync width (% of line period) - default 8 */
-#define CVT_HSYNC_PERCENTAGE 8
-
-        float HBlankPercentage;
-        int VSyncAndBackPorch, VBackPorch;
-        int HBlank;
-
-        /* 8. Estimated Horizontal period */
-        HPeriod = ((float) (1000000.0 / VFieldRate - CVT_MIN_VSYNC_BP)) /
-            (VDisplayRnd + 2 * VMargin + CVT_MIN_V_PORCH + Interlace);
-
-        /* 9. Find number of lines in sync + backporch */
-        if (((int) (CVT_MIN_VSYNC_BP / HPeriod) + 1) <
-            (VSync + CVT_MIN_V_PORCH))
-            VSyncAndBackPorch = VSync + CVT_MIN_V_PORCH;
-        else
-            VSyncAndBackPorch = (int) (CVT_MIN_VSYNC_BP / HPeriod) + 1;
+    libxcvt_mode_info =
+        libxcvt_gen_mode_info(hdisplay, vdisplay, vrefresh, reduced, interlaced);
 
-        /* 10. Find number of lines in back porch */
-        VBackPorch = VSyncAndBackPorch - VSync;
-        (void) VBackPorch;
-
-        /* 11. Find total number of lines in vertical field */
-        modeinfo.vTotal =
-            VDisplayRnd + 2 * VMargin + VSyncAndBackPorch + Interlace +
-            CVT_MIN_V_PORCH;
-
-        /* 5) Definition of Horizontal blanking time limitation */
-        /* Gradient (%/kHz) - default 600 */
-#define CVT_M_FACTOR 600
-
-        /* Offset (%) - default 40 */
-#define CVT_C_FACTOR 40
-
-        /* Blanking time scaling factor - default 128 */
-#define CVT_K_FACTOR 128
-
-        /* Scaling factor weighting - default 20 */
-#define CVT_J_FACTOR 20
-
-#define CVT_M_PRIME CVT_M_FACTOR * CVT_K_FACTOR / 256
-#define CVT_C_PRIME (CVT_C_FACTOR - CVT_J_FACTOR) * CVT_K_FACTOR / 256 + \
-        CVT_J_FACTOR
-
-        /* 12. Find ideal blanking duty cycle from formula */
-        HBlankPercentage = CVT_C_PRIME - CVT_M_PRIME * HPeriod / 1000.0;
-
-        /* 13. Blanking time */
-        if (HBlankPercentage < 20)
-            HBlankPercentage = 20;
-
-        HBlank = modeinfo.width * HBlankPercentage / (100.0 - HBlankPercentage);
-        HBlank -= HBlank % (2 * CVT_H_GRANULARITY);
-
-        /* 14. Find total number of pixels in a line. */
-        modeinfo.hTotal = modeinfo.width + HBlank;
-
-        /* Fill in HSync values */
-        modeinfo.hSyncEnd = modeinfo.width + HBlank / 2;
-
-        modeinfo.hSyncStart = modeinfo.hSyncEnd -
-            (modeinfo.hTotal * CVT_HSYNC_PERCENTAGE) / 100;
-        modeinfo.hSyncStart += CVT_H_GRANULARITY -
-            modeinfo.hSyncStart % CVT_H_GRANULARITY;
-
-        /* Fill in VSync values */
-        modeinfo.vSyncStart = modeinfo.height + CVT_MIN_V_PORCH;
-        modeinfo.vSyncEnd = modeinfo.vSyncStart + VSync;
-
-    }
-    else {                      /* Reduced blanking */
-        /* Minimum vertical blanking interval time (µs) - default 460 */
-#define CVT_RB_MIN_VBLANK 460.0
-
-        /* Fixed number of clocks for horizontal sync */
-#define CVT_RB_H_SYNC 32.0
-
-        /* Fixed number of clocks for horizontal blanking */
-#define CVT_RB_H_BLANK 160.0
-
-        /* Fixed number of lines for vertical front porch - default 3 */
-#define CVT_RB_VFPORCH 3
-
-        int VBILines;
-
-        /* 8. Estimate Horizontal period. */
-        HPeriod = ((float) (1000000.0 / VFieldRate - CVT_RB_MIN_VBLANK)) /
-            (VDisplayRnd + 2 * VMargin);
-
-        /* 9. Find number of lines in vertical blanking */
-        VBILines = ((float) CVT_RB_MIN_VBLANK) / HPeriod + 1;
-
-        /* 10. Check if vertical blanking is sufficient */
-        if (VBILines < (CVT_RB_VFPORCH + VSync + CVT_MIN_V_BPORCH))
-            VBILines = CVT_RB_VFPORCH + VSync + CVT_MIN_V_BPORCH;
-
-        /* 11. Find total number of lines in vertical field */
-        modeinfo.vTotal = VDisplayRnd + 2 * VMargin + Interlace + VBILines;
-
-        /* 12. Find total number of pixels in a line */
-        modeinfo.hTotal = modeinfo.width + CVT_RB_H_BLANK;
-
-        /* Fill in HSync values */
-        modeinfo.hSyncEnd = modeinfo.width + CVT_RB_H_BLANK / 2;
-        modeinfo.hSyncStart = modeinfo.hSyncEnd - CVT_RB_H_SYNC;
-
-        /* Fill in VSync values */
-        modeinfo.vSyncStart = modeinfo.height + CVT_RB_VFPORCH;
-        modeinfo.vSyncEnd = modeinfo.vSyncStart + VSync;
-    }
-
-    /* 15/13. Find pixel clock frequency (kHz for xf86) */
-    modeinfo.dotClock = modeinfo.hTotal * 1000.0 / HPeriod;
-    modeinfo.dotClock -= modeinfo.dotClock % CVT_CLOCK_STEP;
-    modeinfo.dotClock *= 1000.0;
-#if 0
-    /* 16/14. Find actual Horizontal Frequency (kHz) */
-    modeinfo.hSync = ((float) modeinfo.dotClock) / ((float) modeinfo.hTotal);
-#endif
-
-#if 0
-    /* 17/15. Find actual Field rate */
-    modeinfo.vRefresh = (1000.0 * ((float) modeinfo.dotClock)) /
-        ((float) (modeinfo.hTotal * modeinfo.vTotal));
-#endif
-
-    /* 18/16. Find actual vertical frame frequency */
-    /* ignore - just set the mode flag for interlaced */
-    if (Interlaced)
-        modeinfo.vTotal *= 2;
-
-    if (Reduced)
-        modeinfo.modeFlags |= RR_HSyncPositive | RR_VSyncNegative;
-    else
-        modeinfo.modeFlags |= RR_HSyncNegative | RR_VSyncPositive;
-
-    if (Interlaced)
-        modeinfo.modeFlags |= RR_Interlace;
-
-    /* FWXGA hack adapted from hw/xfree86/modes/xf86EdidModes.c, because you can't say 1366 */
-    if (HDisplay == 1366 && VDisplay == 768) {
-         modeinfo.width = 1366;
-         modeinfo.hSyncStart--;
-         modeinfo.hSyncEnd--;
-    }
+    memset(&modeinfo, 0, sizeof modeinfo);
+    modeinfo.width      = libxcvt_mode_info->hdisplay;
+    modeinfo.height     = libxcvt_mode_info->vdisplay;
+    modeinfo.dotClock   = libxcvt_mode_info->dot_clock * 1000.0;
+    modeinfo.hSyncStart = libxcvt_mode_info->hsync_start;
+    modeinfo.hSyncEnd   = libxcvt_mode_info->hsync_end;
+    modeinfo.hTotal     = libxcvt_mode_info->htotal;
+    modeinfo.vSyncStart = libxcvt_mode_info->vsync_start;
+    modeinfo.vSyncEnd   = libxcvt_mode_info->vsync_end;
+    modeinfo.vTotal     = libxcvt_mode_info->vtotal;
+    modeinfo.modeFlags  = libxcvt_mode_info->mode_flags;
+
+    free(libxcvt_mode_info);
 
     snprintf(name, sizeof name, "%dx%d",
              modeinfo.width, modeinfo.height);
commit a4ab57cb748674823744a8ef5a0b416ee553efe8
Author: Olivier Fourdan <ofourdan at redhat.com>
Date:   Thu Mar 25 10:16:31 2021 +0100

    build: Add dependency on libxcvt
    
    libxcvt is a library providing a standalone version of the X server
    implementation of the VESA CVT standard timing modelines generator.
    
    Closes: https://gitlab.freedesktop.org/xorg/xserver/-/issues/1142
    Signed-off-by: Olivier Fourdan <ofourdan at redhat.com>
    Reviewed-by: Matt Turner <mattst88 at gmail.com>

diff --git a/configure.ac b/configure.ac
index 10b64e535..e57ba723a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -758,6 +758,7 @@ LIBUDEV="libudev >= 143"
 LIBSELINUX="libselinux >= 2.0.86"
 LIBDBUS="dbus-1 >= 1.0"
 LIBPIXMAN="pixman-1 >= 0.27.2"
+LIBXCVT="libxcvt"
 
 dnl Pixman is always required, but we separate it out so we can link
 dnl specific modules against it
@@ -765,7 +766,7 @@ PKG_CHECK_MODULES(PIXMAN, $LIBPIXMAN)
 REQUIRED_LIBS="$REQUIRED_LIBS $LIBPIXMAN $LIBXFONT xau"
 
 dnl Core modules for most extensions, et al.
-SDK_REQUIRED_MODULES="$XPROTO $RANDRPROTO $RENDERPROTO $XEXTPROTO $INPUTPROTO $KBPROTO $FONTSPROTO $LIBPIXMAN"
+SDK_REQUIRED_MODULES="$XPROTO $RANDRPROTO $RENDERPROTO $XEXTPROTO $INPUTPROTO $KBPROTO $FONTSPROTO $LIBPIXMAN $LIBXCVT"
 # Make SDK_REQUIRED_MODULES available for inclusion in xorg-server.pc
 AC_SUBST(SDK_REQUIRED_MODULES)
 
@@ -1758,11 +1759,14 @@ fi
 AC_MSG_RESULT([$XORG])
 
 if test "x$XORG" = xyes; then
+	PKG_CHECK_MODULES([LIBXCVT], $LIBXCVT)
+
 	XORG_DDXINCS='-I$(top_srcdir)/hw/xfree86 -I$(top_srcdir)/hw/xfree86/include -I$(top_srcdir)/hw/xfree86/common'
 	XORG_OSINCS='-I$(top_srcdir)/hw/xfree86/os-support -I$(top_srcdir)/hw/xfree86/os-support/bus -I$(top_srcdir)/os'
 	XORG_INCS="$XORG_DDXINCS $XORG_OSINCS"
-	XORG_CFLAGS="$XORGSERVER_CFLAGS -DHAVE_XORG_CONFIG_H"
+	XORG_CFLAGS="$XORGSERVER_CFLAGS $LIBXCVT_CFLAGS -DHAVE_XORG_CONFIG_H"
 	XORG_LIBS="$COMPOSITE_LIB $FIXES_LIB $XEXT_LIB $DBE_LIB $RECORD_LIB $RANDR_LIB $RENDER_LIB $DAMAGE_LIB $DRI3_LIB $PRESENT_LIB $MIEXT_SYNC_LIB $MIEXT_DAMAGE_LIB $XI_LIB $XKB_LIB"
+	XORG_SYS_LIBS="$XORG_SYS_LIBS $LIBXCVT_LIBS"
 
 	dnl ==================================================================
 	dnl symbol visibility
@@ -2347,8 +2351,10 @@ if test "x$XWAYLAND" = xyes; then
 		AC_SUBST(have_eglstream, "false")
 	fi
 
+	PKG_CHECK_MODULES([LIBXCVT], $LIBXCVT)
+
 	XWAYLAND_LIBS="$FB_LIB $FIXES_LIB $MI_LIB $XEXT_LIB $DBE_LIB $RECORD_LIB $GLX_LIBS $RANDR_LIB $RENDER_LIB $DAMAGE_LIB $DRI3_LIB $PRESENT_LIB $MIEXT_SYNC_LIB $MIEXT_DAMAGE_LIB $MIEXT_SHADOW_LIB $XI_LIB $XKB_LIB $XKB_STUB_LIB $COMPOSITE_LIB $MAIN_LIB $DIX_LIB $OS_LIB"
-	XWAYLAND_SYS_LIBS="$XWAYLANDMODULES_LIBS $GLX_SYS_LIBS"
+	XWAYLAND_SYS_LIBS="$XWAYLANDMODULES_LIBS $GLX_SYS_LIBS $LIBXCVT_LIBS"
 	AC_SUBST([XWAYLAND_LIBS])
 	AC_SUBST([XWAYLAND_SYS_LIBS])
 
diff --git a/meson.build b/meson.build
index 24a3840e0..bdab9a9f3 100644
--- a/meson.build
+++ b/meson.build
@@ -192,6 +192,7 @@ if (host_machine.system() != 'darwin' and
     endif
 endif
 xorgsdkdir = join_paths(get_option('prefix'), get_option('includedir'), 'xorg')
+libxcvt_dep = dependency('libxcvt', required: build_xorg)
 
 build_xwayland = false
 if (host_machine.system() != 'darwin' and
@@ -208,6 +209,7 @@ if (host_machine.system() != 'darwin' and
         xwayland_dep = [
             dependency('wayland-client', version: wayland_req, required: xwayland_required),
             dependency('wayland-protocols', version: wayland_protocols_req, required: xwayland_required),
+            dependency('libxcvt', required: xwayland_required),
         ]
 
         if build_glamor
commit 84897891e5e7eb44068cda22284dca70c6cfd1a2
Author: Olivier Fourdan <ofourdan at redhat.com>
Date:   Fri Jul 9 15:11:51 2021 +0200

    ci: Install libxcvt from git
    
    Signed-off-by: Olivier Fourdan <ofourdan at redhat.com>

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 157a53006..d5404c00a 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -11,7 +11,7 @@ variables:
     FDO_UPSTREAM_REPO: xorg/xserver
     FDO_DISTRIBUTION_VERSION: buster-slim
     FDO_DISTRIBUTION_EXEC: 'env FDO_CI_CONCURRENT=${FDO_CI_CONCURRENT} bash .gitlab-ci/debian-install.sh'
-    FDO_DISTRIBUTION_TAG: "2021-05-17"
+    FDO_DISTRIBUTION_TAG: "2021-07-09"
 
 include:
   - project: 'freedesktop/ci-templates'
diff --git a/.gitlab-ci/debian-install.sh b/.gitlab-ci/debian-install.sh
index 963533cda..16003e8a4 100644
--- a/.gitlab-ci/debian-install.sh
+++ b/.gitlab-ci/debian-install.sh
@@ -107,6 +107,14 @@ apt-get install -y \
 
 cd /root
 
+# xserver requires libxcvt
+git clone https://gitlab.freedesktop.org/xorg/lib//libxcvt.git --depth 1 --branch=libxcvt-0.1.0
+cd libxcvt
+meson _build
+ninja -C _build -j${FDO_CI_CONCURRENT:-4} install
+cd ..
+rm -rf libxcvt
+
 # xserver requires xorgproto >= 2021.4.99.2 for XI 2.3.99.1
 git clone https://gitlab.freedesktop.org/xorg/proto/xorgproto.git --depth 1 --branch=xorgproto-2021.4.99.2
 pushd xorgproto


More information about the xorg-commit mailing list