blob: 75208245c58042446f68a51be0d70c41175ceda7 [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
Drew Davenporte60540f2025-02-07 12:18:43 -070038 bool SameSize(const DrmMode &mode) const;
39
Roman Stratiienkodf3120f2022-12-07 23:10:55 +020040 auto &GetRawMode() const {
41 return mode_;
42 }
Sean Paul6a55e9f2015-04-30 15:31:06 -040043
Roman Stratiienkodf3120f2022-12-07 23:10:55 +020044 auto GetVRefresh() const {
45 if (mode_.clock == 0) {
46 return float(mode_.vrefresh);
47 }
48 // Always recalculate refresh to report correct float rate
49 return static_cast<float>(mode_.clock) /
50 (float)(mode_.vtotal * mode_.htotal) * 1000.0F;
51 }
Sean Paul6a55e9f2015-04-30 15:31:06 -040052
Drew Davenport8053f2e2024-10-02 13:44:41 -060053 auto GetVSyncPeriodNs() const {
54 static const int kNanosecondsPerSecond = 1E9;
55 return static_cast<int32_t>(kNanosecondsPerSecond *
56 double(1 / GetVRefresh()));
57 }
58
Roman Stratiienkodf3120f2022-12-07 23:10:55 +020059 auto GetName() const {
60 return std::string(mode_.name) + "@" + std::to_string(GetVRefresh());
61 }
Sean Paul6a55e9f2015-04-30 15:31:06 -040062
Roman Stratiienko40b374b2021-10-22 18:13:09 +030063 auto CreateModeBlob(const DrmDevice &drm) -> DrmModeUserPropertyBlobUnique;
64
Sean Paul6a55e9f2015-04-30 15:31:06 -040065 private:
Roman Stratiienkodf3120f2022-12-07 23:10:55 +020066 drmModeModeInfo mode_;
Sean Paul6a55e9f2015-04-30 15:31:06 -040067};
Sean Paulf72cccd2018-08-27 13:59:08 -040068} // namespace android