blob: 971c327589c998dd86bd182096a87bef6d144dbe [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::id() const {
53 return id_;
54}
55
56void DrmMode::set_id(uint32_t id) {
57 id_ = id;
58}
59
60uint32_t DrmMode::clock() const {
61 return clock_;
62}
63
Roman Stratiienko40b374b2021-10-22 18:13:09 +030064uint16_t DrmMode::h_display() const {
Sean Paul6a55e9f2015-04-30 15:31:06 -040065 return h_display_;
66}
67
Roman Stratiienko40b374b2021-10-22 18:13:09 +030068uint16_t DrmMode::h_sync_start() const {
Sean Paul6a55e9f2015-04-30 15:31:06 -040069 return h_sync_start_;
70}
71
Roman Stratiienko40b374b2021-10-22 18:13:09 +030072uint16_t DrmMode::h_sync_end() const {
Sean Paul6a55e9f2015-04-30 15:31:06 -040073 return h_sync_end_;
74}
75
Roman Stratiienko40b374b2021-10-22 18:13:09 +030076uint16_t DrmMode::h_total() const {
Sean Paul6a55e9f2015-04-30 15:31:06 -040077 return h_total_;
78}
79
Roman Stratiienko40b374b2021-10-22 18:13:09 +030080uint16_t DrmMode::h_skew() const {
Sean Paul6a55e9f2015-04-30 15:31:06 -040081 return h_skew_;
82}
83
Roman Stratiienko40b374b2021-10-22 18:13:09 +030084uint16_t DrmMode::v_display() const {
Sean Paul6a55e9f2015-04-30 15:31:06 -040085 return v_display_;
86}
87
Roman Stratiienko40b374b2021-10-22 18:13:09 +030088uint16_t DrmMode::v_sync_start() const {
Sean Paul6a55e9f2015-04-30 15:31:06 -040089 return v_sync_start_;
90}
91
Roman Stratiienko40b374b2021-10-22 18:13:09 +030092uint16_t DrmMode::v_sync_end() const {
Sean Paul6a55e9f2015-04-30 15:31:06 -040093 return v_sync_end_;
94}
95
Roman Stratiienko40b374b2021-10-22 18:13:09 +030096uint16_t DrmMode::v_total() const {
Sean Paul6a55e9f2015-04-30 15:31:06 -040097 return v_total_;
98}
99
Roman Stratiienko40b374b2021-10-22 18:13:09 +0300100uint16_t DrmMode::v_scan() const {
Sean Paul6a55e9f2015-04-30 15:31:06 -0400101 return v_scan_;
102}
103
Stéphane Marchesinb74e08c2015-07-05 02:00:08 -0700104float DrmMode::v_refresh() const {
Neil Armstrong9cf798d2019-06-04 14:37:51 +0000105 // Always recalculate refresh to report correct float rate
Roman Stratiienkod26619b2021-08-04 19:55:37 +0300106 return static_cast<float>(clock_) / (float)(v_total_ * h_total_) * 1000.0F;
Sean Paul6a55e9f2015-04-30 15:31:06 -0400107}
108
109uint32_t DrmMode::flags() const {
110 return flags_;
111}
112
113uint32_t DrmMode::type() const {
114 return type_;
115}
116
117std::string DrmMode::name() const {
118 return name_;
119}
Roman Stratiienko40b374b2021-10-22 18:13:09 +0300120
121auto DrmMode::CreateModeBlob(const DrmDevice &drm)
122 -> DrmModeUserPropertyBlobUnique {
123 struct drm_mode_modeinfo drm_mode = {
124 .clock = clock_,
125 .hdisplay = h_display_,
126 .hsync_start = h_sync_start_,
127 .hsync_end = h_sync_end_,
128 .htotal = h_total_,
129 .hskew = h_skew_,
130 .vdisplay = v_display_,
131 .vsync_start = v_sync_start_,
132 .vsync_end = v_sync_end_,
133 .vtotal = v_total_,
134 .vscan = v_scan_,
135 .vrefresh = v_refresh_,
136 .flags = flags_,
137 .type = type_,
138 };
139 strncpy(drm_mode.name, name_.c_str(), DRM_DISPLAY_MODE_LEN);
140
141 return drm.RegisterUserPropertyBlob(&drm_mode,
142 sizeof(struct drm_mode_modeinfo));
143}
144
Sean Paulf72cccd2018-08-27 13:59:08 -0400145} // namespace android