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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
|
#include <xf86drm.h>
#include <xf86drmMode.h>
#include <cmath>
#include <sstream>
#include <fmt/format.h>
#include <kms++/kms++.h>
#include "helpers.h"
using namespace std;
namespace kms
{
bool Videomode::valid() const
{
return !!clock;
}
unique_ptr<Blob> Videomode::to_blob(Card& card) const
{
drmModeModeInfo drm_mode = video_mode_to_drm_mode(*this);
return unique_ptr<Blob>(new Blob(card, &drm_mode, sizeof(drm_mode)));
}
float Videomode::calculated_vrefresh() const
{
// XXX interlace should only halve visible vertical lines, not blanking
float refresh = (clock * 1000.0) / (htotal * vtotal) * (interlace() ? 2 : 1);
return roundf(refresh * 100.0) / 100.0;
}
bool Videomode::interlace() const
{
return flags & DRM_MODE_FLAG_INTERLACE;
}
SyncPolarity Videomode::hsync() const
{
if (flags & DRM_MODE_FLAG_PHSYNC)
return SyncPolarity::Positive;
if (flags & DRM_MODE_FLAG_NHSYNC)
return SyncPolarity::Negative;
return SyncPolarity::Undefined;
}
SyncPolarity Videomode::vsync() const
{
if (flags & DRM_MODE_FLAG_PVSYNC)
return SyncPolarity::Positive;
if (flags & DRM_MODE_FLAG_NVSYNC)
return SyncPolarity::Negative;
return SyncPolarity::Undefined;
}
void Videomode::set_interlace(bool ilace)
{
if (ilace)
flags |= DRM_MODE_FLAG_INTERLACE;
else
flags &= ~DRM_MODE_FLAG_INTERLACE;
}
void Videomode::set_hsync(SyncPolarity pol)
{
flags &= ~(DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NHSYNC);
switch (pol) {
case SyncPolarity::Positive:
flags |= DRM_MODE_FLAG_PHSYNC;
break;
case SyncPolarity::Negative:
flags |= DRM_MODE_FLAG_NHSYNC;
break;
default:
break;
}
}
void Videomode::set_vsync(SyncPolarity pol)
{
flags &= ~(DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_NVSYNC);
switch (pol) {
case SyncPolarity::Positive:
flags |= DRM_MODE_FLAG_PVSYNC;
break;
case SyncPolarity::Negative:
flags |= DRM_MODE_FLAG_NVSYNC;
break;
default:
break;
}
}
string Videomode::to_string_short() const
{
return fmt::format("{}x{}{}@{:.2f}", hdisplay, vdisplay, interlace() ? "i" : "", calculated_vrefresh());
}
static char sync_to_char(SyncPolarity pol)
{
switch (pol) {
case SyncPolarity::Positive:
return '+';
case SyncPolarity::Negative:
return '-';
default:
return '?';
}
}
string Videomode::to_string_long() const
{
string h = fmt::format("{}/{}/{}/{}/{}", hdisplay, hfp(), hsw(), hbp(), sync_to_char(hsync()));
string v = fmt::format("{}/{}/{}/{}/{}", vdisplay, vfp(), vsw(), vbp(), sync_to_char(vsync()));
string str = fmt::format("{} {:.3f} {} {} {} ({:.2f}) {:#x} {:#x}",
to_string_short(),
clock / 1000.0,
h, v,
vrefresh, calculated_vrefresh(),
flags,
type);
return str;
}
string Videomode::to_string_long_padded() const
{
string h = fmt::format("{}/{}/{}/{}/{}", hdisplay, hfp(), hsw(), hbp(), sync_to_char(hsync()));
string v = fmt::format("{}/{}/{}/{}/{}", vdisplay, vfp(), vsw(), vbp(), sync_to_char(vsync()));
string str = fmt::format("{:<16} {:7.3f} {:<18} {:<18} {:2} ({:.2f}) {:#10x} {:#6x}",
to_string_short(),
clock / 1000.0,
h, v,
vrefresh, calculated_vrefresh(),
flags,
type);
return str;
}
Videomode videomode_from_timings(uint32_t clock_khz,
uint16_t hact, uint16_t hfp, uint16_t hsw, uint16_t hbp,
uint16_t vact, uint16_t vfp, uint16_t vsw, uint16_t vbp)
{
Videomode m { };
m.clock = clock_khz;
m.hdisplay = hact;
m.hsync_start = hact + hfp;
m.hsync_end = hact + hfp + hsw;
m.htotal = hact + hfp + hsw + hbp;
m.vdisplay = vact;
m.vsync_start = vact + vfp;
m.vsync_end = vact + vfp + vsw;
m.vtotal = vact + vfp + vsw + vbp;
return m;
}
}
|