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
19 #include "DrmDevice.h"
20
21 namespace android {
22
DrmMode(drmModeModeInfoPtr m)23 DrmMode::DrmMode(drmModeModeInfoPtr m)
24 : id_(0),
25 clock_(m->clock),
26 h_display_(m->hdisplay),
27 h_sync_start_(m->hsync_start),
28 h_sync_end_(m->hsync_end),
29 h_total_(m->htotal),
30 h_skew_(m->hskew),
31 v_display_(m->vdisplay),
32 v_sync_start_(m->vsync_start),
33 v_sync_end_(m->vsync_end),
34 v_total_(m->vtotal),
35 v_scan_(m->vscan),
36 v_refresh_(m->vrefresh),
37 flags_(m->flags),
38 type_(m->type),
39 name_(m->name) {
40 }
41
operator ==(const drmModeModeInfo & m) const42 bool DrmMode::operator==(const drmModeModeInfo &m) const {
43 return clock_ == m.clock && h_display_ == m.hdisplay &&
44 h_sync_start_ == m.hsync_start && h_sync_end_ == m.hsync_end &&
45 h_total_ == m.htotal && h_skew_ == m.hskew &&
46 v_display_ == m.vdisplay && v_sync_start_ == m.vsync_start &&
47 v_sync_end_ == m.vsync_end && v_total_ == m.vtotal &&
48 v_scan_ == m.vscan && flags_ == m.flags && type_ == m.type;
49 }
50
ToDrmModeModeInfo(drm_mode_modeinfo * m) const51 void DrmMode::ToDrmModeModeInfo(drm_mode_modeinfo *m) const {
52 m->clock = clock_;
53 m->hdisplay = h_display_;
54 m->hsync_start = h_sync_start_;
55 m->hsync_end = h_sync_end_;
56 m->htotal = h_total_;
57 m->hskew = h_skew_;
58 m->vdisplay = v_display_;
59 m->vsync_start = v_sync_start_;
60 m->vsync_end = v_sync_end_;
61 m->vtotal = v_total_;
62 m->vscan = v_scan_;
63 m->vrefresh = v_refresh_;
64 m->flags = flags_;
65 m->type = type_;
66 strncpy(m->name, name_.c_str(), DRM_DISPLAY_MODE_LEN);
67 }
68
id() const69 uint32_t DrmMode::id() const {
70 return id_;
71 }
72
set_id(uint32_t id)73 void DrmMode::set_id(uint32_t id) {
74 id_ = id;
75 }
76
clock() const77 uint32_t DrmMode::clock() const {
78 return clock_;
79 }
80
h_display() const81 uint32_t DrmMode::h_display() const {
82 return h_display_;
83 }
84
h_sync_start() const85 uint32_t DrmMode::h_sync_start() const {
86 return h_sync_start_;
87 }
88
h_sync_end() const89 uint32_t DrmMode::h_sync_end() const {
90 return h_sync_end_;
91 }
92
h_total() const93 uint32_t DrmMode::h_total() const {
94 return h_total_;
95 }
96
h_skew() const97 uint32_t DrmMode::h_skew() const {
98 return h_skew_;
99 }
100
v_display() const101 uint32_t DrmMode::v_display() const {
102 return v_display_;
103 }
104
v_sync_start() const105 uint32_t DrmMode::v_sync_start() const {
106 return v_sync_start_;
107 }
108
v_sync_end() const109 uint32_t DrmMode::v_sync_end() const {
110 return v_sync_end_;
111 }
112
v_total() const113 uint32_t DrmMode::v_total() const {
114 return v_total_;
115 }
116
v_scan() const117 uint32_t DrmMode::v_scan() const {
118 return v_scan_;
119 }
120
v_refresh() const121 float DrmMode::v_refresh() const {
122 // Always recalculate refresh to report correct float rate
123 return clock_ / (float)(v_total_ * h_total_) * 1000.0f;
124 }
125
flags() const126 uint32_t DrmMode::flags() const {
127 return flags_;
128 }
129
type() const130 uint32_t DrmMode::type() const {
131 return type_;
132 }
133
name() const134 std::string DrmMode::name() const {
135 return name_;
136 }
137 } // namespace android
138