xref: /aosp_15_r20/external/drm_hwcomposer/drm/DrmMode.h (revision 0a9764fe0a15e71ebbeb85e87e10990c23aab47f)
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 
17 #pragma once
18 
19 #include <xf86drmMode.h>
20 
21 #include <cstdint>
22 #include <cstdio>
23 #include <string>
24 
25 #include "DrmUnique.h"
26 
27 namespace android {
28 
29 class DrmDevice;
30 
31 class DrmMode {
32  public:
33   DrmMode() = default;
34   explicit DrmMode(drmModeModeInfoPtr m);
35 
36   bool operator==(const drmModeModeInfo &m) const;
37 
GetRawMode()38   auto &GetRawMode() const {
39     return mode_;
40   }
41 
GetVRefresh()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   }
50 
GetVSyncPeriodNs()51   auto GetVSyncPeriodNs() const {
52     static const int kNanosecondsPerSecond = 1E9;
53     return static_cast<int32_t>(kNanosecondsPerSecond *
54                                 double(1 / GetVRefresh()));
55   }
56 
GetName()57   auto GetName() const {
58     return std::string(mode_.name) + "@" + std::to_string(GetVRefresh());
59   }
60 
61   auto CreateModeBlob(const DrmDevice &drm) -> DrmModeUserPropertyBlobUnique;
62 
63  private:
64   drmModeModeInfo mode_;
65 };
66 }  // namespace android
67