drm_hwcomposer: Rework DrmMode class
Simplify code and raise-up clang-tidy level of DrmMode class
to 'normal'.
Signed-off-by: Roman Stratiienko <r.stratiienko@gmail.com>
diff --git a/drm/DrmConnector.h b/drm/DrmConnector.h
index 1e1a685..63150e7 100644
--- a/drm/DrmConnector.h
+++ b/drm/DrmConnector.h
@@ -123,7 +123,7 @@
const uint32_t index_in_res_array_;
- DrmMode active_mode_;
+ DrmMode active_mode_{};
std::vector<DrmMode> modes_;
DrmProperty dpms_property_;
diff --git a/drm/DrmMode.cpp b/drm/DrmMode.cpp
index 010ea1b..7cbea44 100644
--- a/drm/DrmMode.cpp
+++ b/drm/DrmMode.cpp
@@ -22,119 +22,22 @@
namespace android {
-DrmMode::DrmMode(drmModeModeInfoPtr m)
- : clock_(m->clock),
- h_display_(m->hdisplay),
- h_sync_start_(m->hsync_start),
- h_sync_end_(m->hsync_end),
- h_total_(m->htotal),
- h_skew_(m->hskew),
- v_display_(m->vdisplay),
- v_sync_start_(m->vsync_start),
- v_sync_end_(m->vsync_end),
- v_total_(m->vtotal),
- v_scan_(m->vscan),
- v_refresh_(m->vrefresh),
- flags_(m->flags),
- type_(m->type),
- name_(m->name) {
-}
+DrmMode::DrmMode(drmModeModeInfoPtr m) : mode_(*m){};
bool DrmMode::operator==(const drmModeModeInfo &m) const {
- return clock_ == m.clock && h_display_ == m.hdisplay &&
- h_sync_start_ == m.hsync_start && h_sync_end_ == m.hsync_end &&
- h_total_ == m.htotal && h_skew_ == m.hskew &&
- v_display_ == m.vdisplay && v_sync_start_ == m.vsync_start &&
- v_sync_end_ == m.vsync_end && v_total_ == m.vtotal &&
- v_scan_ == m.vscan && flags_ == m.flags && type_ == m.type;
-}
-
-uint32_t DrmMode::clock() const {
- return clock_;
-}
-
-uint16_t DrmMode::h_display() const {
- return h_display_;
-}
-
-uint16_t DrmMode::h_sync_start() const {
- return h_sync_start_;
-}
-
-uint16_t DrmMode::h_sync_end() const {
- return h_sync_end_;
-}
-
-uint16_t DrmMode::h_total() const {
- return h_total_;
-}
-
-uint16_t DrmMode::h_skew() const {
- return h_skew_;
-}
-
-uint16_t DrmMode::v_display() const {
- return v_display_;
-}
-
-uint16_t DrmMode::v_sync_start() const {
- return v_sync_start_;
-}
-
-uint16_t DrmMode::v_sync_end() const {
- return v_sync_end_;
-}
-
-uint16_t DrmMode::v_total() const {
- return v_total_;
-}
-
-uint16_t DrmMode::v_scan() const {
- return v_scan_;
-}
-
-float DrmMode::v_refresh() const {
- if (clock_ == 0) {
- return v_refresh_;
- }
- // Always recalculate refresh to report correct float rate
- return static_cast<float>(clock_) / (float)(v_total_ * h_total_) * 1000.0F;
-}
-
-uint32_t DrmMode::flags() const {
- return flags_;
-}
-
-uint32_t DrmMode::type() const {
- return type_;
-}
-
-std::string DrmMode::name() const {
- return name_ + "@" + std::to_string(v_refresh());
+ return memcmp(&m, &mode_, offsetof(drmModeModeInfo, name)) == 0;
}
auto DrmMode::CreateModeBlob(const DrmDevice &drm)
-> DrmModeUserPropertyBlobUnique {
- struct drm_mode_modeinfo drm_mode = {
- .clock = clock_,
- .hdisplay = h_display_,
- .hsync_start = h_sync_start_,
- .hsync_end = h_sync_end_,
- .htotal = h_total_,
- .hskew = h_skew_,
- .vdisplay = v_display_,
- .vsync_start = v_sync_start_,
- .vsync_end = v_sync_end_,
- .vtotal = v_total_,
- .vscan = v_scan_,
- .vrefresh = v_refresh_,
- .flags = flags_,
- .type = type_,
- };
- strncpy(drm_mode.name, name_.c_str(), DRM_DISPLAY_MODE_LEN);
+ struct drm_mode_modeinfo drm_mode = {};
+ /* drm_mode_modeinfo and drmModeModeInfo should be identical
+ * At least libdrm does the same memcpy in drmModeAttachMode();
+ */
+ memcpy(&drm_mode, &mode_, sizeof(struct drm_mode_modeinfo));
return drm.RegisterUserPropertyBlob(&drm_mode,
- sizeof(struct drm_mode_modeinfo));
+ sizeof(struct drm_mode_modeinfo));
}
} // namespace android
diff --git a/drm/DrmMode.h b/drm/DrmMode.h
index c6ddc63..c5790a5 100644
--- a/drm/DrmMode.h
+++ b/drm/DrmMode.h
@@ -35,47 +35,26 @@
bool operator==(const drmModeModeInfo &m) const;
- uint32_t clock() const;
+ auto &GetRawMode() const {
+ return mode_;
+ }
- uint16_t h_display() const;
- uint16_t h_sync_start() const;
- uint16_t h_sync_end() const;
- uint16_t h_total() const;
- uint16_t h_skew() const;
+ auto GetVRefresh() const {
+ if (mode_.clock == 0) {
+ return float(mode_.vrefresh);
+ }
+ // Always recalculate refresh to report correct float rate
+ return static_cast<float>(mode_.clock) /
+ (float)(mode_.vtotal * mode_.htotal) * 1000.0F;
+ }
- uint16_t v_display() const;
- uint16_t v_sync_start() const;
- uint16_t v_sync_end() const;
- uint16_t v_total() const;
- uint16_t v_scan() const;
- float v_refresh() const;
-
- uint32_t flags() const;
- uint32_t type() const;
-
- std::string name() const;
+ auto GetName() const {
+ return std::string(mode_.name) + "@" + std::to_string(GetVRefresh());
+ }
auto CreateModeBlob(const DrmDevice &drm) -> DrmModeUserPropertyBlobUnique;
private:
- uint32_t clock_ = 0;
-
- uint16_t h_display_ = 0;
- uint16_t h_sync_start_ = 0;
- uint16_t h_sync_end_ = 0;
- uint16_t h_total_ = 0;
- uint16_t h_skew_ = 0;
-
- uint16_t v_display_ = 0;
- uint16_t v_sync_start_ = 0;
- uint16_t v_sync_end_ = 0;
- uint16_t v_total_ = 0;
- uint16_t v_scan_ = 0;
- uint16_t v_refresh_ = 0;
-
- uint32_t flags_ = 0;
- uint32_t type_ = 0;
-
- std::string name_;
+ drmModeModeInfo mode_;
};
} // namespace android
diff --git a/drm/VSyncWorker.cpp b/drm/VSyncWorker.cpp
index 7b4fae4..a2cad28 100644
--- a/drm/VSyncWorker.cpp
+++ b/drm/VSyncWorker.cpp
@@ -80,8 +80,8 @@
float refresh = 60.0F; // Default to 60Hz refresh rate
if (pipe_ != nullptr &&
- pipe_->connector->Get()->GetActiveMode().v_refresh() != 0.0F) {
- refresh = pipe_->connector->Get()->GetActiveMode().v_refresh();
+ pipe_->connector->Get()->GetActiveMode().GetVRefresh() != 0.0F) {
+ refresh = pipe_->connector->Get()->GetActiveMode().GetVRefresh();
}
auto phased_timestamp = GetPhasedVSync(kOneSecondNs /