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 | |
Roman Stratiienko | df3120f | 2022-12-07 23:10:55 +0200 | [diff] [blame] | 38 | auto &GetRawMode() const { |
| 39 | return mode_; |
| 40 | } |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 41 | |
Roman Stratiienko | df3120f | 2022-12-07 23:10:55 +0200 | [diff] [blame] | 42 | 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 Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 50 | |
Drew Davenport | 8053f2e | 2024-10-02 13:44:41 -0600 | [diff] [blame^] | 51 | auto GetVSyncPeriodNs() const { |
| 52 | static const int kNanosecondsPerSecond = 1E9; |
| 53 | return static_cast<int32_t>(kNanosecondsPerSecond * |
| 54 | double(1 / GetVRefresh())); |
| 55 | } |
| 56 | |
Roman Stratiienko | df3120f | 2022-12-07 23:10:55 +0200 | [diff] [blame] | 57 | auto GetName() const { |
| 58 | return std::string(mode_.name) + "@" + std::to_string(GetVRefresh()); |
| 59 | } |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 60 | |
Roman Stratiienko | 40b374b | 2021-10-22 18:13:09 +0300 | [diff] [blame] | 61 | auto CreateModeBlob(const DrmDevice &drm) -> DrmModeUserPropertyBlobUnique; |
| 62 | |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 63 | private: |
Roman Stratiienko | df3120f | 2022-12-07 23:10:55 +0200 | [diff] [blame] | 64 | drmModeModeInfo mode_; |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 65 | }; |
Sean Paul | f72cccd | 2018-08-27 13:59:08 -0400 | [diff] [blame] | 66 | } // namespace android |