diff options
author | Tomi Valkeinen <tomi.valkeinen@ti.com> | 2015-11-13 19:24:52 +0200 |
---|---|---|
committer | Tomi Valkeinen <tomi.valkeinen@ti.com> | 2015-11-13 22:12:41 +0200 |
commit | de716254d983a05402a593793480ee1e5ee9e97e (patch) | |
tree | 8acb73d64cb8183c24e1bcbdb89abf262cd02737 | |
parent | c146ed65aee4c55fc57d8798ac0e1643ed26be8a (diff) |
Videomode cleanup
-rw-r--r-- | libkms++/connector.h | 14 | ||||
-rw-r--r-- | libkms++/helpers.cpp | 61 | ||||
-rw-r--r-- | libkms++/videomode.h | 20 |
3 files changed, 76 insertions, 19 deletions
diff --git a/libkms++/connector.h b/libkms++/connector.h index 9776be3..a897d31 100644 --- a/libkms++/connector.h +++ b/libkms++/connector.h @@ -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; 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 <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 index 0000000..28a5b00 --- /dev/null +++ b/libkms++/videomode.h @@ -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; +}; + +} |