blob: dd2575811e00a30eb3992d1ba8de4f137f18ecaf [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
Roman Stratiienkod518a052021-02-25 19:15:14 +020019#include <cstring>
20
Roman Stratiienko13cc3662020-08-29 21:35:39 +030021#include "DrmDevice.h"
Sean Paul6a55e9f2015-04-30 15:31:06 -040022
Sean Paul6a55e9f2015-04-30 15:31:06 -040023namespace android {
24
25DrmMode::DrmMode(drmModeModeInfoPtr m)
Roman Stratiienkoe2f2c922021-02-13 10:57:47 +020026 : clock_(m->clock),
Sean Paul6a55e9f2015-04-30 15:31:06 -040027 h_display_(m->hdisplay),
28 h_sync_start_(m->hsync_start),
29 h_sync_end_(m->hsync_end),
30 h_total_(m->htotal),
31 h_skew_(m->hskew),
32 v_display_(m->vdisplay),
33 v_sync_start_(m->vsync_start),
34 v_sync_end_(m->vsync_end),
35 v_total_(m->vtotal),
36 v_scan_(m->vscan),
Sean Paulad563d42015-10-28 15:56:23 -040037 v_refresh_(m->vrefresh),
Sean Paul6a55e9f2015-04-30 15:31:06 -040038 flags_(m->flags),
39 type_(m->type),
40 name_(m->name) {
41}
42
Sean Paul6a55e9f2015-04-30 15:31:06 -040043bool DrmMode::operator==(const drmModeModeInfo &m) const {
44 return clock_ == m.clock && h_display_ == m.hdisplay &&
45 h_sync_start_ == m.hsync_start && h_sync_end_ == m.hsync_end &&
46 h_total_ == m.htotal && h_skew_ == m.hskew &&
47 v_display_ == m.vdisplay && v_sync_start_ == m.vsync_start &&
48 v_sync_end_ == m.vsync_end && v_total_ == m.vtotal &&
Zach Reiznerc6520e42015-08-13 14:32:09 -070049 v_scan_ == m.vscan && flags_ == m.flags && type_ == m.type;
Sean Paul6a55e9f2015-04-30 15:31:06 -040050}
51
Sean Paul877be972015-06-03 14:08:27 -040052void DrmMode::ToDrmModeModeInfo(drm_mode_modeinfo *m) const {
Sean Paul6a55e9f2015-04-30 15:31:06 -040053 m->clock = clock_;
54 m->hdisplay = h_display_;
55 m->hsync_start = h_sync_start_;
56 m->hsync_end = h_sync_end_;
57 m->htotal = h_total_;
58 m->hskew = h_skew_;
59 m->vdisplay = v_display_;
60 m->vsync_start = v_sync_start_;
61 m->vsync_end = v_sync_end_;
62 m->vtotal = v_total_;
63 m->vscan = v_scan_;
Sean Paulad563d42015-10-28 15:56:23 -040064 m->vrefresh = v_refresh_;
Sean Paul6a55e9f2015-04-30 15:31:06 -040065 m->flags = flags_;
66 m->type = type_;
67 strncpy(m->name, name_.c_str(), DRM_DISPLAY_MODE_LEN);
68}
69
70uint32_t DrmMode::id() const {
71 return id_;
72}
73
74void DrmMode::set_id(uint32_t id) {
75 id_ = id;
76}
77
78uint32_t DrmMode::clock() const {
79 return clock_;
80}
81
82uint32_t DrmMode::h_display() const {
83 return h_display_;
84}
85
86uint32_t DrmMode::h_sync_start() const {
87 return h_sync_start_;
88}
89
90uint32_t DrmMode::h_sync_end() const {
91 return h_sync_end_;
92}
93
94uint32_t DrmMode::h_total() const {
95 return h_total_;
96}
97
98uint32_t DrmMode::h_skew() const {
99 return h_skew_;
100}
101
102uint32_t DrmMode::v_display() const {
103 return v_display_;
104}
105
106uint32_t DrmMode::v_sync_start() const {
107 return v_sync_start_;
108}
109
110uint32_t DrmMode::v_sync_end() const {
111 return v_sync_end_;
112}
113
114uint32_t DrmMode::v_total() const {
115 return v_total_;
116}
117
118uint32_t DrmMode::v_scan() const {
119 return v_scan_;
120}
121
Stéphane Marchesinb74e08c2015-07-05 02:00:08 -0700122float DrmMode::v_refresh() const {
Neil Armstrong9cf798d2019-06-04 14:37:51 +0000123 // Always recalculate refresh to report correct float rate
Roman Stratiienkoe2f2c922021-02-13 10:57:47 +0200124 return clock_ / (float)(v_total_ * h_total_) * 1000.0F;
Sean Paul6a55e9f2015-04-30 15:31:06 -0400125}
126
127uint32_t DrmMode::flags() const {
128 return flags_;
129}
130
131uint32_t DrmMode::type() const {
132 return type_;
133}
134
135std::string DrmMode::name() const {
136 return name_;
137}
Sean Paulf72cccd2018-08-27 13:59:08 -0400138} // namespace android