• 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 
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 
GetName()51   auto GetName() const {
52     return std::string(mode_.name) + "@" + std::to_string(GetVRefresh());
53   }
54 
55   auto CreateModeBlob(const DrmDevice &drm) -> DrmModeUserPropertyBlobUnique;
56 
57  private:
58   drmModeModeInfo mode_;
59 };
60 }  // namespace android
61