Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 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 | |
Roman Stratiienko | bde9566 | 2022-12-10 20:27:58 +0200 | [diff] [blame] | 17 | #pragma once |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 18 | |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 19 | #include <xf86drmMode.h> |
Roman Stratiienko | aa3cd54 | 2020-08-29 11:26:16 +0300 | [diff] [blame] | 20 | |
Roman Stratiienko | a148f21 | 2021-11-16 18:23:18 +0200 | [diff] [blame] | 21 | #include <cstdint> |
Roman Stratiienko | e78235c | 2021-12-23 17:36:12 +0200 | [diff] [blame] | 22 | #include <cstdio> |
Sean Paul | f72cccd | 2018-08-27 13:59:08 -0400 | [diff] [blame] | 23 | #include <string> |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 24 | |
Roman Stratiienko | 40b374b | 2021-10-22 18:13:09 +0300 | [diff] [blame] | 25 | #include "DrmUnique.h" |
| 26 | |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 27 | namespace android { |
| 28 | |
Roman Stratiienko | 40b374b | 2021-10-22 18:13:09 +0300 | [diff] [blame] | 29 | class DrmDevice; |
| 30 | |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 31 | class DrmMode { |
| 32 | public: |
Zach Reizner | ff30b52 | 2015-10-28 19:08:45 -0700 | [diff] [blame] | 33 | DrmMode() = default; |
Roman Stratiienko | e78235c | 2021-12-23 17:36:12 +0200 | [diff] [blame] | 34 | explicit DrmMode(drmModeModeInfoPtr m); |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 35 | |
| 36 | bool operator==(const drmModeModeInfo &m) const; |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 37 | |
Drew Davenport | e60540f | 2025-02-07 12:18:43 -0700 | [diff] [blame] | 38 | bool SameSize(const DrmMode &mode) const; |
| 39 | |
Roman Stratiienko | df3120f | 2022-12-07 23:10:55 +0200 | [diff] [blame] | 40 | auto &GetRawMode() const { |
| 41 | return mode_; |
| 42 | } |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 43 | |
Roman Stratiienko | df3120f | 2022-12-07 23:10:55 +0200 | [diff] [blame] | 44 | 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 Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 52 | |
Drew Davenport | 8053f2e | 2024-10-02 13:44:41 -0600 | [diff] [blame] | 53 | auto GetVSyncPeriodNs() const { |
| 54 | static const int kNanosecondsPerSecond = 1E9; |
| 55 | return static_cast<int32_t>(kNanosecondsPerSecond * |
| 56 | double(1 / GetVRefresh())); |
| 57 | } |
| 58 | |
Roman Stratiienko | df3120f | 2022-12-07 23:10:55 +0200 | [diff] [blame] | 59 | auto GetName() const { |
| 60 | return std::string(mode_.name) + "@" + std::to_string(GetVRefresh()); |
| 61 | } |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 62 | |
Roman Stratiienko | 40b374b | 2021-10-22 18:13:09 +0300 | [diff] [blame] | 63 | auto CreateModeBlob(const DrmDevice &drm) -> DrmModeUserPropertyBlobUnique; |
| 64 | |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 65 | private: |
Roman Stratiienko | df3120f | 2022-12-07 23:10:55 +0200 | [diff] [blame] | 66 | drmModeModeInfo mode_; |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 67 | }; |
Sean Paul | f72cccd | 2018-08-27 13:59:08 -0400 | [diff] [blame] | 68 | } // namespace android |