blob: c5790a5b0d8f0110d566305f462b50ef6a780b80 [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 Stratiienkobde95662022-12-10 20:27:58 +020017#pragma once
Sean Paul6a55e9f2015-04-30 15:31:06 -040018
Sean Paul6a55e9f2015-04-30 15:31:06 -040019#include <xf86drmMode.h>
Roman Stratiienkoaa3cd542020-08-29 11:26:16 +030020
Roman Stratiienkoa148f212021-11-16 18:23:18 +020021#include <cstdint>
Roman Stratiienkoe78235c2021-12-23 17:36:12 +020022#include <cstdio>
Sean Paulf72cccd2018-08-27 13:59:08 -040023#include <string>
Sean Paul6a55e9f2015-04-30 15:31:06 -040024
Roman Stratiienko40b374b2021-10-22 18:13:09 +030025#include "DrmUnique.h"
26
Sean Paul6a55e9f2015-04-30 15:31:06 -040027namespace android {
28
Roman Stratiienko40b374b2021-10-22 18:13:09 +030029class DrmDevice;
30
Sean Paul6a55e9f2015-04-30 15:31:06 -040031class DrmMode {
32 public:
Zach Reiznerff30b522015-10-28 19:08:45 -070033 DrmMode() = default;
Roman Stratiienkoe78235c2021-12-23 17:36:12 +020034 explicit DrmMode(drmModeModeInfoPtr m);
Sean Paul6a55e9f2015-04-30 15:31:06 -040035
36 bool operator==(const drmModeModeInfo &m) const;
Sean Paul6a55e9f2015-04-30 15:31:06 -040037
Roman Stratiienkodf3120f2022-12-07 23:10:55 +020038 auto &GetRawMode() const {
39 return mode_;
40 }
Sean Paul6a55e9f2015-04-30 15:31:06 -040041
Roman Stratiienkodf3120f2022-12-07 23:10:55 +020042 auto GetVRefresh() const {
43 if (mode_.clock == 0) {
44 return float(mode_.vrefresh);
45 }
46 // Always recalculate refresh to report correct float rate
47 return static_cast<float>(mode_.clock) /
48 (float)(mode_.vtotal * mode_.htotal) * 1000.0F;
49 }
Sean Paul6a55e9f2015-04-30 15:31:06 -040050
Roman Stratiienkodf3120f2022-12-07 23:10:55 +020051 auto GetName() const {
52 return std::string(mode_.name) + "@" + std::to_string(GetVRefresh());
53 }
Sean Paul6a55e9f2015-04-30 15:31:06 -040054
Roman Stratiienko40b374b2021-10-22 18:13:09 +030055 auto CreateModeBlob(const DrmDevice &drm) -> DrmModeUserPropertyBlobUnique;
56
Sean Paul6a55e9f2015-04-30 15:31:06 -040057 private:
Roman Stratiienkodf3120f2022-12-07 23:10:55 +020058 drmModeModeInfo mode_;
Sean Paul6a55e9f2015-04-30 15:31:06 -040059};
Sean Paulf72cccd2018-08-27 13:59:08 -040060} // namespace android