Videomode cleanup
authorTomi Valkeinen <tomi.valkeinen@ti.com>
Fri, 13 Nov 2015 17:24:52 +0000 (19:24 +0200)
committerTomi Valkeinen <tomi.valkeinen@ti.com>
Fri, 13 Nov 2015 20:12:41 +0000 (22:12 +0200)
libkms++/connector.h
libkms++/helpers.cpp
libkms++/videomode.h [new file with mode: 0644]

index 9776be35258c940609c22d6b3d65ce187ce8631e..a897d31d7d79bfad828b57bfd23298a480d94ac0 100644 (file)
@@ -3,25 +3,13 @@
 #include <vector>
 
 #include "drmobject.h"
+#include "videomode.h"
 
 namespace kms
 {
 
 struct ConnectorPriv;
 
-struct Videomode
-{
-       uint32_t clock;
-       uint16_t hdisplay, hsync_start, hsync_end, htotal, hskew;
-       uint16_t vdisplay, vsync_start, vsync_end, vtotal, vscan;
-
-       uint32_t vrefresh;
-
-       uint32_t flags;
-       uint32_t type;
-       char name[32]; // XXX
-};
-
 class Connector : public DrmObject
 {
        friend class Card;
index 7746bdefdb88989bec597ad7e84862fd5d4e1e25..715e757969cc94d5741245e0b2748e6f75344fc5 100644 (file)
@@ -3,21 +3,70 @@
 #include "helpers.h"
 #include <cstring>
 
+#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;
 }
 }
diff --git a/libkms++/videomode.h b/libkms++/videomode.h
new file mode 100644 (file)
index 0000000..28a5b00
--- /dev/null
@@ -0,0 +1,20 @@
+#pragma once
+
+namespace kms
+{
+
+struct Videomode
+{
+       uint32_t clock;
+       uint16_t hdisplay, hsync_start, hsync_end, htotal, hskew;
+       uint16_t vdisplay, vsync_start, vsync_end, vtotal, vscan;
+
+       uint32_t vrefresh;
+
+       uint32_t flags;         // DRM_MODE_FLAG_*
+       uint32_t type;          // DRM_MODE_TYPE_*
+
+       std::string name;
+};
+
+}