blob: 6de671a0a532c668661ccec3af319039f77cc0d0 [file] [log] [blame]
Sean Paul6a55e9f2015-04-30 15:31:06 -04001/*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Roman Stratiienko13cc3662020-08-29 21:35:39 +030017#include "DrmMode.h"
18
19#include "DrmDevice.h"
Sean Paul6a55e9f2015-04-30 15:31:06 -040020
Sean Paul6a55e9f2015-04-30 15:31:06 -040021namespace android {
22
23DrmMode::DrmMode(drmModeModeInfoPtr m)
24 : id_(0),
25 clock_(m->clock),
26 h_display_(m->hdisplay),
27 h_sync_start_(m->hsync_start),
28 h_sync_end_(m->hsync_end),
29 h_total_(m->htotal),
30 h_skew_(m->hskew),
31 v_display_(m->vdisplay),
32 v_sync_start_(m->vsync_start),
33 v_sync_end_(m->vsync_end),
34 v_total_(m->vtotal),
35 v_scan_(m->vscan),
Sean Paulad563d42015-10-28 15:56:23 -040036 v_refresh_(m->vrefresh),
Sean Paul6a55e9f2015-04-30 15:31:06 -040037 flags_(m->flags),
38 type_(m->type),
39 name_(m->name) {
40}
41
Sean Paul6a55e9f2015-04-30 15:31:06 -040042bool DrmMode::operator==(const drmModeModeInfo &m) const {
43 return clock_ == m.clock && h_display_ == m.hdisplay &&
44 h_sync_start_ == m.hsync_start && h_sync_end_ == m.hsync_end &&
45 h_total_ == m.htotal && h_skew_ == m.hskew &&
46 v_display_ == m.vdisplay && v_sync_start_ == m.vsync_start &&
47 v_sync_end_ == m.vsync_end && v_total_ == m.vtotal &&
Zach Reiznerc6520e42015-08-13 14:32:09 -070048 v_scan_ == m.vscan && flags_ == m.flags && type_ == m.type;
Sean Paul6a55e9f2015-04-30 15:31:06 -040049}
50
Sean Paul877be972015-06-03 14:08:27 -040051void DrmMode::ToDrmModeModeInfo(drm_mode_modeinfo *m) const {
Sean Paul6a55e9f2015-04-30 15:31:06 -040052 m->clock = clock_;
53 m->hdisplay = h_display_;
54 m->hsync_start = h_sync_start_;
55 m->hsync_end = h_sync_end_;
56 m->htotal = h_total_;
57 m->hskew = h_skew_;
58 m->vdisplay = v_display_;
59 m->vsync_start = v_sync_start_;
60 m->vsync_end = v_sync_end_;
61 m->vtotal = v_total_;
62 m->vscan = v_scan_;
Sean Paulad563d42015-10-28 15:56:23 -040063 m->vrefresh = v_refresh_;
Sean Paul6a55e9f2015-04-30 15:31:06 -040064 m->flags = flags_;
65 m->type = type_;
66 strncpy(m->name, name_.c_str(), DRM_DISPLAY_MODE_LEN);
67}
68
69uint32_t DrmMode::id() const {
70 return id_;
71}
72
73void DrmMode::set_id(uint32_t id) {
74 id_ = id;
75}
76
77uint32_t DrmMode::clock() const {
78 return clock_;
79}
80
81uint32_t DrmMode::h_display() const {
82 return h_display_;
83}
84
85uint32_t DrmMode::h_sync_start() const {
86 return h_sync_start_;
87}
88
89uint32_t DrmMode::h_sync_end() const {
90 return h_sync_end_;
91}
92
93uint32_t DrmMode::h_total() const {
94 return h_total_;
95}
96
97uint32_t DrmMode::h_skew() const {
98 return h_skew_;
99}
100
101uint32_t DrmMode::v_display() const {
102 return v_display_;
103}
104
105uint32_t DrmMode::v_sync_start() const {
106 return v_sync_start_;
107}
108
109uint32_t DrmMode::v_sync_end() const {
110 return v_sync_end_;
111}
112
113uint32_t DrmMode::v_total() const {
114 return v_total_;
115}
116
117uint32_t DrmMode::v_scan() const {
118 return v_scan_;
119}
120
Stéphane Marchesinb74e08c2015-07-05 02:00:08 -0700121float DrmMode::v_refresh() const {
Neil Armstrong9cf798d2019-06-04 14:37:51 +0000122 // Always recalculate refresh to report correct float rate
123 return clock_ / (float)(v_total_ * h_total_) * 1000.0f;
Sean Paul6a55e9f2015-04-30 15:31:06 -0400124}
125
126uint32_t DrmMode::flags() const {
127 return flags_;
128}
129
130uint32_t DrmMode::type() const {
131 return type_;
132}
133
134std::string DrmMode::name() const {
135 return name_;
136}
Sean Paulf72cccd2018-08-27 13:59:08 -0400137} // namespace android