blob: 2b558c98c41659583f69010eb2af810ff0d80342 [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"
18#include "drmresources.h"
19
20#include <stdint.h>
21#include <string>
Sean Paul6a55e9f2015-04-30 15:31:06 -040022#include <xf86drmMode.h>
23
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
45DrmMode::DrmMode()
46 : id_(0),
47 clock_(0),
48 h_display_(0),
49 h_sync_start_(0),
50 h_sync_end_(0),
51 h_total_(0),
52 h_skew_(0),
53 v_display_(0),
54 v_sync_start_(0),
55 v_sync_end_(0),
56 v_total_(0),
57 v_scan_(0),
Sean Paulad563d42015-10-28 15:56:23 -040058 v_refresh_(0),
Sean Paul6a55e9f2015-04-30 15:31:06 -040059 flags_(0),
60 type_(0),
61 name_("") {
62}
63
64DrmMode::~DrmMode() {
65}
66
67bool DrmMode::operator==(const drmModeModeInfo &m) const {
68 return clock_ == m.clock && h_display_ == m.hdisplay &&
69 h_sync_start_ == m.hsync_start && h_sync_end_ == m.hsync_end &&
70 h_total_ == m.htotal && h_skew_ == m.hskew &&
71 v_display_ == m.vdisplay && v_sync_start_ == m.vsync_start &&
72 v_sync_end_ == m.vsync_end && v_total_ == m.vtotal &&
Zach Reiznerc6520e42015-08-13 14:32:09 -070073 v_scan_ == m.vscan && flags_ == m.flags && type_ == m.type;
Sean Paul6a55e9f2015-04-30 15:31:06 -040074}
75
Sean Paul877be972015-06-03 14:08:27 -040076void DrmMode::ToDrmModeModeInfo(drm_mode_modeinfo *m) const {
Sean Paul6a55e9f2015-04-30 15:31:06 -040077 m->clock = clock_;
78 m->hdisplay = h_display_;
79 m->hsync_start = h_sync_start_;
80 m->hsync_end = h_sync_end_;
81 m->htotal = h_total_;
82 m->hskew = h_skew_;
83 m->vdisplay = v_display_;
84 m->vsync_start = v_sync_start_;
85 m->vsync_end = v_sync_end_;
86 m->vtotal = v_total_;
87 m->vscan = v_scan_;
Sean Paulad563d42015-10-28 15:56:23 -040088 m->vrefresh = v_refresh_;
Sean Paul6a55e9f2015-04-30 15:31:06 -040089 m->flags = flags_;
90 m->type = type_;
91 strncpy(m->name, name_.c_str(), DRM_DISPLAY_MODE_LEN);
92}
93
94uint32_t DrmMode::id() const {
95 return id_;
96}
97
98void DrmMode::set_id(uint32_t id) {
99 id_ = id;
100}
101
102uint32_t DrmMode::clock() const {
103 return clock_;
104}
105
106uint32_t DrmMode::h_display() const {
107 return h_display_;
108}
109
110uint32_t DrmMode::h_sync_start() const {
111 return h_sync_start_;
112}
113
114uint32_t DrmMode::h_sync_end() const {
115 return h_sync_end_;
116}
117
118uint32_t DrmMode::h_total() const {
119 return h_total_;
120}
121
122uint32_t DrmMode::h_skew() const {
123 return h_skew_;
124}
125
126uint32_t DrmMode::v_display() const {
127 return v_display_;
128}
129
130uint32_t DrmMode::v_sync_start() const {
131 return v_sync_start_;
132}
133
134uint32_t DrmMode::v_sync_end() const {
135 return v_sync_end_;
136}
137
138uint32_t DrmMode::v_total() const {
139 return v_total_;
140}
141
142uint32_t DrmMode::v_scan() const {
143 return v_scan_;
144}
145
Stéphane Marchesinb74e08c2015-07-05 02:00:08 -0700146float DrmMode::v_refresh() const {
Sean Paulad563d42015-10-28 15:56:23 -0400147 return v_refresh_ ? v_refresh_ * 1.0f :
148 clock_ / (float)(v_total_ * h_total_) * 1000.0f;
Sean Paul6a55e9f2015-04-30 15:31:06 -0400149}
150
151uint32_t DrmMode::flags() const {
152 return flags_;
153}
154
155uint32_t DrmMode::type() const {
156 return type_;
157}
158
159std::string DrmMode::name() const {
160 return name_;
161}
162}