• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
38   bool SameSize(const DrmMode &mode) const;
39 
GetRawMode()40   auto &GetRawMode() const {
41     return mode_;
42   }
43 
GetVRefresh()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   }
52 
GetVSyncPeriodNs()53   auto GetVSyncPeriodNs() const {
54     static const int kNanosecondsPerSecond = 1E9;
55     return static_cast<int32_t>(kNanosecondsPerSecond *
56                                 double(1 / GetVRefresh()));
57   }
58 
GetName()59   auto GetName() const {
60     return std::string(mode_.name) + "@" + std::to_string(GetVRefresh());
61   }
62 
63   auto CreateModeBlob(const DrmDevice &drm) -> DrmModeUserPropertyBlobUnique;
64 
65  private:
66   drmModeModeInfo mode_;
67 };
68 }  // namespace android
69