summaryrefslogtreecommitdiff
path: root/src/backends/native/gen-default-modes.py
blob: aa731ee101c9eb84fd50824728308ba207db3d68 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# Copyright (C) 2016 Red Hat Inc.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
# 02111-1307, USA.

import os
import sys

common_resolutions = [
    # 4:3
    (800, 600),
    (1024, 768),
    (1152, 864),
    (1280, 960),
    (1400, 1050),
    (1440, 1080),
    (1600, 1200),
    (1920, 1440),
    (2048, 1536),
    # 16:10
    (1280, 800),
    (1440, 900),
    (1680, 1050),
    (1920, 1200),
    (2560, 1600),
    # 16:9
    (1280, 720),
    (1366, 768),
    (1600, 900),
    (1920, 1080),
    (2048, 1152),
    (2560, 1440),
    (2880, 1620),
    (3200, 1800),
    (3840, 2160),
    (4096, 2304),
    (5120, 2880),
]

output_lines = [
    "/* Generated by gen-default-modes.py */\n",
    "const drmModeModeInfo meta_default_drm_mode_infos[] = {",
]

def sync_flags(hsync, vsync):
    flags = "DRM_MODE_FLAG_"
    flags += "NHSYNC" if hsync[0] is '-' else "PHSYNC"
    flags += " | DRM_MODE_FLAG_"
    flags += "NVSYNC" if vsync[0] is '-' else "PVSYNC"
    return flags

def drm_mode_info_from_modeline(line):
    sline = line.split()
    return "{ %d, %d, %d, %d, %d, 0, %d, %d, %d, %d, 0, 0, %s, DRM_MODE_TYPE_DEFAULT, %s }," % \
        (int(float(sline[2]) * 1000),
         int(sline[3]),
         int(sline[4]),
         int(sline[5]),
         int(sline[6]),
         int(sline[7]),
         int(sline[8]),
         int(sline[9]),
         int(sline[10]),
         sync_flags(sline[11], sline[12]),
         sline[1])

for resolution in common_resolutions:
    cvt = os.popen("%s %s %s" % ('cvt', resolution[0], resolution[1]))
    cvt.readline() # discard comment line
    line = cvt.readline()
    output_lines.append(drm_mode_info_from_modeline(line))
    cvt.close()
output_lines.append("};")

for line in output_lines:
    sys.stdout.write(line + "\n")
sys.stdout.flush()