• 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 #ifndef ANDROID_DRM_MODE_H_
18 #define ANDROID_DRM_MODE_H_
19 
20 #include <stdint.h>
21 #include <xf86drmMode.h>
22 
23 #include <ratio>
24 #include <string>
25 
26 // Alternative definitions(alias) of DRM modes and flags for VRR.
27 // The kernel contains corresponding defines that MUST align with those specified here..
28 #define DRM_MODE_TYPE_VRR DRM_MODE_TYPE_USERDEF
29 #define DRM_MODE_FLAG_NS DRM_MODE_FLAG_CLKDIV2
30 #define DRM_MODE_FLAG_TE_FREQ_X1 DRM_MODE_FLAG_PHSYNC
31 #define DRM_MODE_FLAG_TE_FREQ_X2 DRM_MODE_FLAG_NHSYNC
32 #define DRM_MODE_FLAG_TE_FREQ_X4 DRM_MODE_FLAG_PVSYNC
33 
34 // BTS needs to take operation rate into account
35 #define DRM_MODE_FLAG_BTS_OP_RATE DRM_MODE_FLAG_NVSYNC
36 
37 #define PANEL_REFRESH_CTRL_FI (1 << 0)
38 #define PANEL_REFRESH_CTRL_IDLE (1 << 1)
39 
40 namespace android {
41 
42 class DrmMode {
43  public:
44   DrmMode() = default;
45   DrmMode(drmModeModeInfoPtr m);
46 
47   bool operator==(const drmModeModeInfo &m) const;
48   void ToDrmModeModeInfo(drm_mode_modeinfo *m) const;
49 
is_vrr_mode()50   inline bool is_vrr_mode() const { return (type_ & DRM_MODE_TYPE_VRR); };
is_ns_mode()51   inline bool is_ns_mode() const { return (flags_ & DRM_MODE_FLAG_NS); };
52 
53   uint32_t id() const;
54   void set_id(uint32_t id);
55 
56   uint32_t clock() const;
57 
58   uint32_t h_display() const;
59   uint32_t h_sync_start() const;
60   uint32_t h_sync_end() const;
61   uint32_t h_total() const;
62   uint32_t h_skew() const;
63 
64   uint32_t v_display() const;
65   uint32_t v_sync_start() const;
66   uint32_t v_sync_end() const;
67   uint32_t v_total() const;
68   uint32_t v_scan() const;
69   float v_refresh() const;
70   float te_frequency() const;
71   // Convert frequency to period, with the default unit being nanoseconds.
72   float v_period(int64_t unit = std::nano::den) const;
73   float te_period(int64_t unit = std::nano::den) const;
74 
75   bool is_operation_rate_to_bts() const;
76   uint32_t flags() const;
77   uint32_t type() const;
78 
79   std::string name() const;
80 
81  private:
82   uint32_t id_ = 0;
83 
84   uint32_t clock_ = 0;
85 
86   uint32_t h_display_ = 0;
87   uint32_t h_sync_start_ = 0;
88   uint32_t h_sync_end_ = 0;
89   uint32_t h_total_ = 0;
90   uint32_t h_skew_ = 0;
91 
92   uint32_t v_display_ = 0;
93   uint32_t v_sync_start_ = 0;
94   uint32_t v_sync_end_ = 0;
95   uint32_t v_total_ = 0;
96   uint32_t v_scan_ = 0;
97   uint32_t v_refresh_ = 0;
98 
99   uint32_t flags_ = 0;
100   uint32_t type_ = 0;
101 
102   std::string name_;
103 };
104 }  // namespace android
105 
106 #endif  // ANDROID_DRM_MODE_H_
107