blob: 6a879e8199c8a12cb2687869f5a4c7c1601db120 [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)
26 : id_(0),
27 clock_(m->clock),
28 h_display_(m->hdisplay),
29 h_sync_start_(m->hsync_start),
30 h_sync_end_(m->hsync_end),
31 h_total_(m->htotal),
32 h_skew_(m->hskew),
33 v_display_(m->vdisplay),
34 v_sync_start_(m->vsync_start),
35 v_sync_end_(m->vsync_end),
36 v_total_(m->vtotal),
37 v_scan_(m->vscan),
Sean Paulad563d42015-10-28 15:56:23 -040038 v_refresh_(m->vrefresh),
Sean Paul6a55e9f2015-04-30 15:31:06 -040039 flags_(m->flags),
40 type_(m->type),
41 name_(m->name) {
42}
43
Sean Paul6a55e9f2015-04-30 15:31:06 -040044bool DrmMode::operator==(const drmModeModeInfo &m) const {
45 return clock_ == m.clock && h_display_ == m.hdisplay &&
46 h_sync_start_ == m.hsync_start && h_sync_end_ == m.hsync_end &&
47 h_total_ == m.htotal && h_skew_ == m.hskew &&
48 v_display_ == m.vdisplay && v_sync_start_ == m.vsync_start &&
49 v_sync_end_ == m.vsync_end && v_total_ == m.vtotal &&
Zach Reiznerc6520e42015-08-13 14:32:09 -070050 v_scan_ == m.vscan && flags_ == m.flags && type_ == m.type;
Sean Paul6a55e9f2015-04-30 15:31:06 -040051}
52
Sean Paul877be972015-06-03 14:08:27 -040053void DrmMode::ToDrmModeModeInfo(drm_mode_modeinfo *m) const {
Sean Paul6a55e9f2015-04-30 15:31:06 -040054 m->clock = clock_;
55 m->hdisplay = h_display_;
56 m->hsync_start = h_sync_start_;
57 m->hsync_end = h_sync_end_;
58 m->htotal = h_total_;
59 m->hskew = h_skew_;
60 m->vdisplay = v_display_;
61 m->vsync_start = v_sync_start_;
62 m->vsync_end = v_sync_end_;
63 m->vtotal = v_total_;
64 m->vscan = v_scan_;
Sean Paulad563d42015-10-28 15:56:23 -040065 m->vrefresh = v_refresh_;
Sean Paul6a55e9f2015-04-30 15:31:06 -040066 m->flags = flags_;
67 m->type = type_;
68 strncpy(m->name, name_.c_str(), DRM_DISPLAY_MODE_LEN);
69}
70
71uint32_t DrmMode::id() const {
72 return id_;
73}
74
75void DrmMode::set_id(uint32_t id) {
76 id_ = id;
77}
78
79uint32_t DrmMode::clock() const {
80 return clock_;
81}
82
83uint32_t DrmMode::h_display() const {
84 return h_display_;
85}
86
87uint32_t DrmMode::h_sync_start() const {
88 return h_sync_start_;
89}
90
91uint32_t DrmMode::h_sync_end() const {
92 return h_sync_end_;
93}
94
95uint32_t DrmMode::h_total() const {
96 return h_total_;
97}
98
99uint32_t DrmMode::h_skew() const {
100 return h_skew_;
101}
102
103uint32_t DrmMode::v_display() const {
104 return v_display_;
105}
106
107uint32_t DrmMode::v_sync_start() const {
108 return v_sync_start_;
109}
110
111uint32_t DrmMode::v_sync_end() const {
112 return v_sync_end_;
113}
114
115uint32_t DrmMode::v_total() const {
116 return v_total_;
117}
118
119uint32_t DrmMode::v_scan() const {
120 return v_scan_;
121}
122
Stéphane Marchesinb74e08c2015-07-05 02:00:08 -0700123float DrmMode::v_refresh() const {
Neil Armstrong9cf798d2019-06-04 14:37:51 +0000124 // Always recalculate refresh to report correct float rate
125 return clock_ / (float)(v_total_ * h_total_) * 1000.0f;
Sean Paul6a55e9f2015-04-30 15:31:06 -0400126}
127
128uint32_t DrmMode::flags() const {
129 return flags_;
130}
131
132uint32_t DrmMode::type() const {
133 return type_;
134}
135
136std::string DrmMode::name() const {
137 return name_;
138}
Sean Paulf72cccd2018-08-27 13:59:08 -0400139} // namespace android