blob: abd3b32b3e85443676666c1bb4e3c2701c7c1279 [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 Paul6a55e9f2015-04-30 15:31:06 -040039 flags_(m->flags),
40 type_(m->type),
41 name_(m->name) {
42}
43
44DrmMode::DrmMode()
45 : id_(0),
46 clock_(0),
47 h_display_(0),
48 h_sync_start_(0),
49 h_sync_end_(0),
50 h_total_(0),
51 h_skew_(0),
52 v_display_(0),
53 v_sync_start_(0),
54 v_sync_end_(0),
55 v_total_(0),
56 v_scan_(0),
Sean Paul6a55e9f2015-04-30 15:31:06 -040057 flags_(0),
58 type_(0),
59 name_("") {
60}
61
62DrmMode::~DrmMode() {
63}
64
65bool DrmMode::operator==(const drmModeModeInfo &m) const {
66 return clock_ == m.clock && h_display_ == m.hdisplay &&
67 h_sync_start_ == m.hsync_start && h_sync_end_ == m.hsync_end &&
68 h_total_ == m.htotal && h_skew_ == m.hskew &&
69 v_display_ == m.vdisplay && v_sync_start_ == m.vsync_start &&
70 v_sync_end_ == m.vsync_end && v_total_ == m.vtotal &&
Stéphane Marchesinb74e08c2015-07-05 02:00:08 -070071 v_scan_ == m.vscan && flags_ == m.flags &&
Sean Paul6a55e9f2015-04-30 15:31:06 -040072 type_ == m.type;
73}
74
Sean Paul877be972015-06-03 14:08:27 -040075void DrmMode::ToDrmModeModeInfo(drm_mode_modeinfo *m) const {
Sean Paul6a55e9f2015-04-30 15:31:06 -040076 m->clock = clock_;
77 m->hdisplay = h_display_;
78 m->hsync_start = h_sync_start_;
79 m->hsync_end = h_sync_end_;
80 m->htotal = h_total_;
81 m->hskew = h_skew_;
82 m->vdisplay = v_display_;
83 m->vsync_start = v_sync_start_;
84 m->vsync_end = v_sync_end_;
85 m->vtotal = v_total_;
86 m->vscan = v_scan_;
Sean Paul6a55e9f2015-04-30 15:31:06 -040087 m->flags = flags_;
88 m->type = type_;
89 strncpy(m->name, name_.c_str(), DRM_DISPLAY_MODE_LEN);
90}
91
92uint32_t DrmMode::id() const {
93 return id_;
94}
95
96void DrmMode::set_id(uint32_t id) {
97 id_ = id;
98}
99
100uint32_t DrmMode::clock() const {
101 return clock_;
102}
103
104uint32_t DrmMode::h_display() const {
105 return h_display_;
106}
107
108uint32_t DrmMode::h_sync_start() const {
109 return h_sync_start_;
110}
111
112uint32_t DrmMode::h_sync_end() const {
113 return h_sync_end_;
114}
115
116uint32_t DrmMode::h_total() const {
117 return h_total_;
118}
119
120uint32_t DrmMode::h_skew() const {
121 return h_skew_;
122}
123
124uint32_t DrmMode::v_display() const {
125 return v_display_;
126}
127
128uint32_t DrmMode::v_sync_start() const {
129 return v_sync_start_;
130}
131
132uint32_t DrmMode::v_sync_end() const {
133 return v_sync_end_;
134}
135
136uint32_t DrmMode::v_total() const {
137 return v_total_;
138}
139
140uint32_t DrmMode::v_scan() const {
141 return v_scan_;
142}
143
Stéphane Marchesinb74e08c2015-07-05 02:00:08 -0700144float DrmMode::v_refresh() const {
145 return clock_ / (float)(v_total_ * h_total_) * 1000.0f;
Sean Paul6a55e9f2015-04-30 15:31:06 -0400146}
147
148uint32_t DrmMode::flags() const {
149 return flags_;
150}
151
152uint32_t DrmMode::type() const {
153 return type_;
154}
155
156std::string DrmMode::name() const {
157 return name_;
158}
159}