summaryrefslogtreecommitdiff
path: root/kms++/helpers.cpp
blob: 715e757969cc94d5741245e0b2748e6f75344fc5 (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

#include "connector.h"
#include "helpers.h"
#include <cstring>

#define CPY(field) dst.field = src.field

namespace kms
{
Videomode drm_mode_to_video_mode(const drmModeModeInfo& drmmode)
{
	Videomode mode = { };

	auto& src = drmmode;
	auto& dst = mode;

	CPY(clock);

	CPY(hdisplay);
	CPY(hsync_start);
	CPY(hsync_end);
	CPY(htotal);
	CPY(hskew);

	CPY(vdisplay);
	CPY(vsync_start);
	CPY(vsync_end);
	CPY(vtotal);
	CPY(vscan);

	CPY(vrefresh);

	CPY(flags);
	CPY(type);

	mode.name = drmmode.name;

	return mode;
}

drmModeModeInfo video_mode_to_drm_mode(const Videomode& mode)
{
	drmModeModeInfo drmmode = { };

	auto& src = mode;
	auto& dst = drmmode;

	CPY(clock);

	CPY(hdisplay);
	CPY(hsync_start);
	CPY(hsync_end);
	CPY(htotal);
	CPY(hskew);

	CPY(vdisplay);
	CPY(vsync_start);
	CPY(vsync_end);
	CPY(vtotal);
	CPY(vscan);

	CPY(vrefresh);

	CPY(flags);
	CPY(type);

	strncpy(drmmode.name, mode.name.c_str(), sizeof(drmmode.name));
	drmmode.name[sizeof(drmmode.name) - 1] = 0;

	return drmmode;
}
}