OSDN Git Service

7f8c04d6e87db70245a8c952007976f1f4f3006b
[android-x86/external-drm_hwcomposer.git] / drmmode.cpp
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
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       flags_(m->flags),
40       type_(m->type),
41       name_(m->name) {
42 }
43
44 DrmMode::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),
57       flags_(0),
58       type_(0),
59       name_("") {
60 }
61
62 DrmMode::~DrmMode() {
63 }
64
65 bool 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 &&
71          v_scan_ == m.vscan && flags_ == m.flags && type_ == m.type;
72 }
73
74 void DrmMode::ToDrmModeModeInfo(drm_mode_modeinfo *m) const {
75   m->clock = clock_;
76   m->hdisplay = h_display_;
77   m->hsync_start = h_sync_start_;
78   m->hsync_end = h_sync_end_;
79   m->htotal = h_total_;
80   m->hskew = h_skew_;
81   m->vdisplay = v_display_;
82   m->vsync_start = v_sync_start_;
83   m->vsync_end = v_sync_end_;
84   m->vtotal = v_total_;
85   m->vscan = v_scan_;
86   m->flags = flags_;
87   m->type = type_;
88   strncpy(m->name, name_.c_str(), DRM_DISPLAY_MODE_LEN);
89 }
90
91 uint32_t DrmMode::id() const {
92   return id_;
93 }
94
95 void DrmMode::set_id(uint32_t id) {
96   id_ = id;
97 }
98
99 uint32_t DrmMode::clock() const {
100   return clock_;
101 }
102
103 uint32_t DrmMode::h_display() const {
104   return h_display_;
105 }
106
107 uint32_t DrmMode::h_sync_start() const {
108   return h_sync_start_;
109 }
110
111 uint32_t DrmMode::h_sync_end() const {
112   return h_sync_end_;
113 }
114
115 uint32_t DrmMode::h_total() const {
116   return h_total_;
117 }
118
119 uint32_t DrmMode::h_skew() const {
120   return h_skew_;
121 }
122
123 uint32_t DrmMode::v_display() const {
124   return v_display_;
125 }
126
127 uint32_t DrmMode::v_sync_start() const {
128   return v_sync_start_;
129 }
130
131 uint32_t DrmMode::v_sync_end() const {
132   return v_sync_end_;
133 }
134
135 uint32_t DrmMode::v_total() const {
136   return v_total_;
137 }
138
139 uint32_t DrmMode::v_scan() const {
140   return v_scan_;
141 }
142
143 float DrmMode::v_refresh() const {
144   return clock_ / (float)(v_total_ * h_total_) * 1000.0f;
145 }
146
147 uint32_t DrmMode::flags() const {
148   return flags_;
149 }
150
151 uint32_t DrmMode::type() const {
152   return type_;
153 }
154
155 std::string DrmMode::name() const {
156   return name_;
157 }
158 }