blob: 010ea1b4651455b9a15fecc2e95eaeff936505d5 [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
Roman Stratiienko13cc3662020-08-29 21:35:39 +030017#include "DrmMode.h"
18
Roman Stratiienkod518a052021-02-25 19:15:14 +020019#include <cstring>
20
Roman Stratiienko13cc3662020-08-29 21:35:39 +030021#include "DrmDevice.h"
Sean Paul6a55e9f2015-04-30 15:31:06 -040022
Sean Paul6a55e9f2015-04-30 15:31:06 -040023namespace android {
24
25DrmMode::DrmMode(drmModeModeInfoPtr m)
Roman Stratiienkoe2f2c922021-02-13 10:57:47 +020026 : clock_(m->clock),
Sean Paul6a55e9f2015-04-30 15:31:06 -040027 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),
Sean Paulad563d42015-10-28 15:56:23 -040037 v_refresh_(m->vrefresh),
Sean Paul6a55e9f2015-04-30 15:31:06 -040038 flags_(m->flags),
39 type_(m->type),
40 name_(m->name) {
41}
42
Sean Paul6a55e9f2015-04-30 15:31:06 -040043bool 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 &&
Zach Reiznerc6520e42015-08-13 14:32:09 -070049 v_scan_ == m.vscan && flags_ == m.flags && type_ == m.type;
Sean Paul6a55e9f2015-04-30 15:31:06 -040050}
51
Sean Paul6a55e9f2015-04-30 15:31:06 -040052uint32_t DrmMode::clock() const {
53 return clock_;
54}
55
Roman Stratiienko40b374b2021-10-22 18:13:09 +030056uint16_t DrmMode::h_display() const {
Sean Paul6a55e9f2015-04-30 15:31:06 -040057 return h_display_;
58}
59
Roman Stratiienko40b374b2021-10-22 18:13:09 +030060uint16_t DrmMode::h_sync_start() const {
Sean Paul6a55e9f2015-04-30 15:31:06 -040061 return h_sync_start_;
62}
63
Roman Stratiienko40b374b2021-10-22 18:13:09 +030064uint16_t DrmMode::h_sync_end() const {
Sean Paul6a55e9f2015-04-30 15:31:06 -040065 return h_sync_end_;
66}
67
Roman Stratiienko40b374b2021-10-22 18:13:09 +030068uint16_t DrmMode::h_total() const {
Sean Paul6a55e9f2015-04-30 15:31:06 -040069 return h_total_;
70}
71
Roman Stratiienko40b374b2021-10-22 18:13:09 +030072uint16_t DrmMode::h_skew() const {
Sean Paul6a55e9f2015-04-30 15:31:06 -040073 return h_skew_;
74}
75
Roman Stratiienko40b374b2021-10-22 18:13:09 +030076uint16_t DrmMode::v_display() const {
Sean Paul6a55e9f2015-04-30 15:31:06 -040077 return v_display_;
78}
79
Roman Stratiienko40b374b2021-10-22 18:13:09 +030080uint16_t DrmMode::v_sync_start() const {
Sean Paul6a55e9f2015-04-30 15:31:06 -040081 return v_sync_start_;
82}
83
Roman Stratiienko40b374b2021-10-22 18:13:09 +030084uint16_t DrmMode::v_sync_end() const {
Sean Paul6a55e9f2015-04-30 15:31:06 -040085 return v_sync_end_;
86}
87
Roman Stratiienko40b374b2021-10-22 18:13:09 +030088uint16_t DrmMode::v_total() const {
Sean Paul6a55e9f2015-04-30 15:31:06 -040089 return v_total_;
90}
91
Roman Stratiienko40b374b2021-10-22 18:13:09 +030092uint16_t DrmMode::v_scan() const {
Sean Paul6a55e9f2015-04-30 15:31:06 -040093 return v_scan_;
94}
95
Stéphane Marchesinb74e08c2015-07-05 02:00:08 -070096float DrmMode::v_refresh() const {
Roman Stratiienkof0c507f2022-01-17 18:29:24 +020097 if (clock_ == 0) {
98 return v_refresh_;
99 }
Neil Armstrong9cf798d2019-06-04 14:37:51 +0000100 // Always recalculate refresh to report correct float rate
Roman Stratiienkod26619b2021-08-04 19:55:37 +0300101 return static_cast<float>(clock_) / (float)(v_total_ * h_total_) * 1000.0F;
Sean Paul6a55e9f2015-04-30 15:31:06 -0400102}
103
104uint32_t DrmMode::flags() const {
105 return flags_;
106}
107
108uint32_t DrmMode::type() const {
109 return type_;
110}
111
112std::string DrmMode::name() const {
Roman Stratiienkoa148f212021-11-16 18:23:18 +0200113 return name_ + "@" + std::to_string(v_refresh());
Sean Paul6a55e9f2015-04-30 15:31:06 -0400114}
Roman Stratiienko40b374b2021-10-22 18:13:09 +0300115
116auto 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
Sean Paulf72cccd2018-08-27 13:59:08 -0400140} // namespace android