1 /*
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>
22 #include <xf86drmMode.h>
23
24 namespace android {
25
DrmMode(drmModeModeInfoPtr m)26 DrmMode::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),
39 v_refresh_(m->vrefresh),
40 flags_(m->flags),
41 type_(m->type),
42 name_(m->name) {
43 }
44
DrmMode()45 DrmMode::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),
58 v_refresh_(0),
59 flags_(0),
60 type_(0),
61 name_("") {
62 }
63
~DrmMode()64 DrmMode::~DrmMode() {
65 }
66
operator ==(const drmModeModeInfo & m) const67 bool 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 &&
73 v_scan_ == m.vscan && v_refresh_ == m.vrefresh && flags_ == m.flags &&
74 type_ == m.type;
75 }
76
ToDrmModeModeInfo(drm_mode_modeinfo * m) const77 void DrmMode::ToDrmModeModeInfo(drm_mode_modeinfo *m) const {
78 m->clock = clock_;
79 m->hdisplay = h_display_;
80 m->hsync_start = h_sync_start_;
81 m->hsync_end = h_sync_end_;
82 m->htotal = h_total_;
83 m->hskew = h_skew_;
84 m->vdisplay = v_display_;
85 m->vsync_start = v_sync_start_;
86 m->vsync_end = v_sync_end_;
87 m->vtotal = v_total_;
88 m->vscan = v_scan_;
89 m->vrefresh = v_refresh_;
90 m->flags = flags_;
91 m->type = type_;
92 strncpy(m->name, name_.c_str(), DRM_DISPLAY_MODE_LEN);
93 }
94
id() const95 uint32_t DrmMode::id() const {
96 return id_;
97 }
98
set_id(uint32_t id)99 void DrmMode::set_id(uint32_t id) {
100 id_ = id;
101 }
102
clock() const103 uint32_t DrmMode::clock() const {
104 return clock_;
105 }
106
h_display() const107 uint32_t DrmMode::h_display() const {
108 return h_display_;
109 }
110
h_sync_start() const111 uint32_t DrmMode::h_sync_start() const {
112 return h_sync_start_;
113 }
114
h_sync_end() const115 uint32_t DrmMode::h_sync_end() const {
116 return h_sync_end_;
117 }
118
h_total() const119 uint32_t DrmMode::h_total() const {
120 return h_total_;
121 }
122
h_skew() const123 uint32_t DrmMode::h_skew() const {
124 return h_skew_;
125 }
126
v_display() const127 uint32_t DrmMode::v_display() const {
128 return v_display_;
129 }
130
v_sync_start() const131 uint32_t DrmMode::v_sync_start() const {
132 return v_sync_start_;
133 }
134
v_sync_end() const135 uint32_t DrmMode::v_sync_end() const {
136 return v_sync_end_;
137 }
138
v_total() const139 uint32_t DrmMode::v_total() const {
140 return v_total_;
141 }
142
v_scan() const143 uint32_t DrmMode::v_scan() const {
144 return v_scan_;
145 }
146
v_refresh() const147 uint32_t DrmMode::v_refresh() const {
148 return v_refresh_;
149 }
150
flags() const151 uint32_t DrmMode::flags() const {
152 return flags_;
153 }
154
type() const155 uint32_t DrmMode::type() const {
156 return type_;
157 }
158
name() const159 std::string DrmMode::name() const {
160 return name_;
161 }
162 }
163