blob: 5f2e7c2bfa9e7a6a287ff83b6414ebaafa35472f [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
17#include "drmmode.h"
Sean Paulf72cccd2018-08-27 13:59:08 -040018#include "drmdevice.h"
Sean Paul6a55e9f2015-04-30 15:31:06 -040019
20#include <stdint.h>
Sean Paul6a55e9f2015-04-30 15:31:06 -040021#include <xf86drmMode.h>
Sean Paulf72cccd2018-08-27 13:59:08 -040022#include <string>
Sean Paul6a55e9f2015-04-30 15:31:06 -040023
24namespace android {
25
26DrmMode::DrmMode(drmModeModeInfoPtr m)
27 : id_(0),
28 clock_(m->clock),
29 h_display_(m->hdisplay),
30 h_sync_start_(m->hsync_start),
31 h_sync_end_(m->hsync_end),
32 h_total_(m->htotal),
33 h_skew_(m->hskew),
34 v_display_(m->vdisplay),
35 v_sync_start_(m->vsync_start),
36 v_sync_end_(m->vsync_end),
37 v_total_(m->vtotal),
38 v_scan_(m->vscan),
Sean Paulad563d42015-10-28 15:56:23 -040039 v_refresh_(m->vrefresh),
Sean Paul6a55e9f2015-04-30 15:31:06 -040040 flags_(m->flags),
41 type_(m->type),
42 name_(m->name) {
43}
44
Sean Paul6a55e9f2015-04-30 15:31:06 -040045bool DrmMode::operator==(const drmModeModeInfo &m) const {
46 return clock_ == m.clock && h_display_ == m.hdisplay &&
47 h_sync_start_ == m.hsync_start && h_sync_end_ == m.hsync_end &&
48 h_total_ == m.htotal && h_skew_ == m.hskew &&
49 v_display_ == m.vdisplay && v_sync_start_ == m.vsync_start &&
50 v_sync_end_ == m.vsync_end && v_total_ == m.vtotal &&
Zach Reiznerc6520e42015-08-13 14:32:09 -070051 v_scan_ == m.vscan && flags_ == m.flags && type_ == m.type;
Sean Paul6a55e9f2015-04-30 15:31:06 -040052}
53
Sean Paul877be972015-06-03 14:08:27 -040054void DrmMode::ToDrmModeModeInfo(drm_mode_modeinfo *m) const {
Sean Paul6a55e9f2015-04-30 15:31:06 -040055 m->clock = clock_;
56 m->hdisplay = h_display_;
57 m->hsync_start = h_sync_start_;
58 m->hsync_end = h_sync_end_;
59 m->htotal = h_total_;
60 m->hskew = h_skew_;
61 m->vdisplay = v_display_;
62 m->vsync_start = v_sync_start_;
63 m->vsync_end = v_sync_end_;
64 m->vtotal = v_total_;
65 m->vscan = v_scan_;
Sean Paulad563d42015-10-28 15:56:23 -040066 m->vrefresh = v_refresh_;
Sean Paul6a55e9f2015-04-30 15:31:06 -040067 m->flags = flags_;
68 m->type = type_;
69 strncpy(m->name, name_.c_str(), DRM_DISPLAY_MODE_LEN);
70}
71
72uint32_t DrmMode::id() const {
73 return id_;
74}
75
76void DrmMode::set_id(uint32_t id) {
77 id_ = id;
78}
79
80uint32_t DrmMode::clock() const {
81 return clock_;
82}
83
84uint32_t DrmMode::h_display() const {
85 return h_display_;
86}
87
88uint32_t DrmMode::h_sync_start() const {
89 return h_sync_start_;
90}
91
92uint32_t DrmMode::h_sync_end() const {
93 return h_sync_end_;
94}
95
96uint32_t DrmMode::h_total() const {
97 return h_total_;
98}
99
100uint32_t DrmMode::h_skew() const {
101 return h_skew_;
102}
103
104uint32_t DrmMode::v_display() const {
105 return v_display_;
106}
107
108uint32_t DrmMode::v_sync_start() const {
109 return v_sync_start_;
110}
111
112uint32_t DrmMode::v_sync_end() const {
113 return v_sync_end_;
114}
115
116uint32_t DrmMode::v_total() const {
117 return v_total_;
118}
119
120uint32_t DrmMode::v_scan() const {
121 return v_scan_;
122}
123
Stéphane Marchesinb74e08c2015-07-05 02:00:08 -0700124float DrmMode::v_refresh() const {
Sean Paulf72cccd2018-08-27 13:59:08 -0400125 return v_refresh_ ? v_refresh_ * 1.0f
126 : clock_ / (float)(v_total_ * h_total_) * 1000.0f;
Sean Paul6a55e9f2015-04-30 15:31:06 -0400127}
128
129uint32_t DrmMode::flags() const {
130 return flags_;
131}
132
133uint32_t DrmMode::type() const {
134 return type_;
135}
136
137std::string DrmMode::name() const {
138 return name_;
139}
Sean Paulf72cccd2018-08-27 13:59:08 -0400140} // namespace android