From de716254d983a05402a593793480ee1e5ee9e97e Mon Sep 17 00:00:00 2001 From: Tomi Valkeinen Date: Fri, 13 Nov 2015 19:24:52 +0200 Subject: Videomode cleanup --- libkms++/helpers.cpp | 61 ++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 55 insertions(+), 6 deletions(-) (limited to 'libkms++/helpers.cpp') diff --git a/libkms++/helpers.cpp b/libkms++/helpers.cpp index 7746bde..715e757 100644 --- a/libkms++/helpers.cpp +++ b/libkms++/helpers.cpp @@ -3,21 +3,70 @@ #include "helpers.h" #include +#define CPY(field) dst.field = src.field + namespace kms { Videomode drm_mode_to_video_mode(const drmModeModeInfo& drmmode) { - // XXX these are the same at the moment - Videomode mode; - memcpy(&mode, &drmmode, sizeof(mode)); + 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) { - // XXX these are the same at the moment - drmModeModeInfo drmmode; - memcpy(&drmmode, &mode, sizeof(drmmode)); + 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; } } -- cgit v1.2.3