• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <cstring>
20 
21 #include "DrmDevice.h"
22 
23 namespace android {
24 
DrmMode(drmModeModeInfoPtr m)25 DrmMode::DrmMode(drmModeModeInfoPtr m)
26     : clock_(m->clock),
27       h_display_(m->hdisplay),
28       h_sync_start_(m->hsync_start),
29       h_sync_end_(m->hsync_end),
30       h_total_(m->htotal),
31       h_skew_(m->hskew),
32       v_display_(m->vdisplay),
33       v_sync_start_(m->vsync_start),
34       v_sync_end_(m->vsync_end),
35       v_total_(m->vtotal),
36       v_scan_(m->vscan),
37       v_refresh_(m->vrefresh),
38       flags_(m->flags),
39       type_(m->type),
40       name_(m->name) {
41 }
42 
operator ==(const drmModeModeInfo & m) const43 bool DrmMode::operator==(const drmModeModeInfo &m) const {
44   return clock_ == m.clock && h_display_ == m.hdisplay &&
45          h_sync_start_ == m.hsync_start && h_sync_end_ == m.hsync_end &&
46          h_total_ == m.htotal && h_skew_ == m.hskew &&
47          v_display_ == m.vdisplay && v_sync_start_ == m.vsync_start &&
48          v_sync_end_ == m.vsync_end && v_total_ == m.vtotal &&
49          v_scan_ == m.vscan && flags_ == m.flags && type_ == m.type;
50 }
51 
clock() const52 uint32_t DrmMode::clock() const {
53   return clock_;
54 }
55 
h_display() const56 uint16_t DrmMode::h_display() const {
57   return h_display_;
58 }
59 
h_sync_start() const60 uint16_t DrmMode::h_sync_start() const {
61   return h_sync_start_;
62 }
63 
h_sync_end() const64 uint16_t DrmMode::h_sync_end() const {
65   return h_sync_end_;
66 }
67 
h_total() const68 uint16_t DrmMode::h_total() const {
69   return h_total_;
70 }
71 
h_skew() const72 uint16_t DrmMode::h_skew() const {
73   return h_skew_;
74 }
75 
v_display() const76 uint16_t DrmMode::v_display() const {
77   return v_display_;
78 }
79 
v_sync_start() const80 uint16_t DrmMode::v_sync_start() const {
81   return v_sync_start_;
82 }
83 
v_sync_end() const84 uint16_t DrmMode::v_sync_end() const {
85   return v_sync_end_;
86 }
87 
v_total() const88 uint16_t DrmMode::v_total() const {
89   return v_total_;
90 }
91 
v_scan() const92 uint16_t DrmMode::v_scan() const {
93   return v_scan_;
94 }
95 
v_refresh() const96 float DrmMode::v_refresh() const {
97   if (clock_ == 0) {
98     return v_refresh_;
99   }
100   // Always recalculate refresh to report correct float rate
101   return static_cast<float>(clock_) / (float)(v_total_ * h_total_) * 1000.0F;
102 }
103 
flags() const104 uint32_t DrmMode::flags() const {
105   return flags_;
106 }
107 
type() const108 uint32_t DrmMode::type() const {
109   return type_;
110 }
111 
name() const112 std::string DrmMode::name() const {
113   return name_ + "@" + std::to_string(v_refresh());
114 }
115 
CreateModeBlob(const DrmDevice & drm)116 auto DrmMode::CreateModeBlob(const DrmDevice &drm)
117     -> DrmModeUserPropertyBlobUnique {
118   struct drm_mode_modeinfo drm_mode = {
119       .clock = clock_,
120       .hdisplay = h_display_,
121       .hsync_start = h_sync_start_,
122       .hsync_end = h_sync_end_,
123       .htotal = h_total_,
124       .hskew = h_skew_,
125       .vdisplay = v_display_,
126       .vsync_start = v_sync_start_,
127       .vsync_end = v_sync_end_,
128       .vtotal = v_total_,
129       .vscan = v_scan_,
130       .vrefresh = v_refresh_,
131       .flags = flags_,
132       .type = type_,
133   };
134   strncpy(drm_mode.name, name_.c_str(), DRM_DISPLAY_MODE_LEN);
135 
136   return drm.RegisterUserPropertyBlob(&drm_mode,
137                                        sizeof(struct drm_mode_modeinfo));
138 }
139 
140 }  // namespace android
141