1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef DRM_PLANE_H
17 #define DRM_PLANE_H
18 #include <cinttypes>
19 #include <string>
20 #include <vector>
21 #include <xf86drm.h>
22 #include <xf86drmMode.h>
23 
24 namespace OHOS {
25     namespace HDI {
26         namespace DISPLAY {
27             enum class DrmPropertyType {
28                 DRM_PROPERTY_TYPE_INT,
29                 DRM_PROPERTY_TYPE_ENUM,
30                 DRM_PROPERTY_TYPE_OBJECT,
31                 DRM_PROPERTY_TYPE_BLOB,
32                 DRM_PROPERTY_TYPE_BITMASK,
33                 DRM_PROPERTY_TYPE_INVALID,
34             };
35 
36             enum class DrmPlaneType {
37                 DRM_PLANE_TYPE_CLUSTER0_WIN0 = 1 << 0,
38                 DRM_PLANE_TYPE_CLUSTER0_WIN1 = 1 << 1,
39 
40                 DRM_PLANE_TYPE_CLUSTER1_WIN0 = 1 << 2,
41                 DRM_PLANE_TYPE_CLUSTER1_WIN1 = 1 << 3,
42 
43                 DRM_PLANE_TYPE_ESMART0_WIN0 = 1 << 4,
44                 DRM_PLANE_TYPE_ESMART0_WIN1 = 1 << 5,
45                 DRM_PLANE_TYPE_ESMART0_WIN2 = 1 << 6,
46                 DRM_PLANE_TYPE_ESMART0_WIN3 = 1 << 7,
47 
48                 DRM_PLANE_TYPE_ESMART1_WIN0 = 1 << 8,
49                 DRM_PLANE_TYPE_ESMART1_WIN1 = 1 << 9,
50                 DRM_PLANE_TYPE_ESMART1_WIN2 = 1 << 10,
51                 DRM_PLANE_TYPE_ESMART1_WIN3 = 1 << 11,
52 
53                 DRM_PLANE_TYPE_SMART0_WIN0 = 1 << 12,
54                 DRM_PLANE_TYPE_SMART0_WIN1 = 1 << 13,
55                 DRM_PLANE_TYPE_SMART0_WIN2 = 1 << 14,
56                 DRM_PLANE_TYPE_SMART0_WIN3 = 1 << 15,
57 
58                 DRM_PLANE_TYPE_SMART1_WIN0 = 1 << 16,
59                 DRM_PLANE_TYPE_SMART1_WIN1 = 1 << 17,
60                 DRM_PLANE_TYPE_SMART1_WIN2 = 1 << 18,
61                 DRM_PLANE_TYPE_SMART1_WIN3 = 1 << 19,
62 
63                 DRM_PLANE_TYPE_CLUSTER0_MASK = 0x3,
64                 DRM_PLANE_TYPE_CLUSTER1_MASK = 0xc,
65                 DRM_PLANE_TYPE_CLUSTER_MASK = 0xf,
66                 DRM_PLANE_TYPE_ESMART0_MASK = 0xf0,
67                 DRM_PLANE_TYPE_ESMART1_MASK = 0xf00,
68                 DRM_PLANE_TYPE_SMART0_MASK = 0xf000,
69                 DRM_PLANE_TYPE_SMART1_MASK = 0xf0000,
70                 DRM_PLANE_TYPE_Unknown = 0xffffffff,
71             };
72 
73             struct PlaneMaskName {
74                 DrmPlaneType mask;
75                 const char *name;
76             };
77 
78             struct PlaneTypeName {
79                 DrmPlaneType type;
80                 const char *name;
81             };
82 
83             const std::string PROP_FBID = "FB_ID";
84             const std::string PROP_IN_FENCE_FD = "IN_FENCE_FD";
85             const std::string PROP_CRTC_ID = "CRTC_ID";
86             const std::string PROP_TYPE = "type";
87 
88             const std::string PROP_CRTC_X_ID = "CRTC_X";
89             const std::string PROP_CRTC_Y_ID = "CRTC_Y";
90             const std::string PROP_CRTC_W_ID = "CRTC_W";
91             const std::string PROP_CRTC_H_ID = "CRTC_H";
92 
93             const std::string PROP_SRC_X_ID = "SRC_X";
94             const std::string PROP_SRC_Y_ID = "SRC_Y";
95             const std::string PROP_SRC_W_ID = "SRC_W";
96             const std::string PROP_SRC_H_ID = "SRC_H";
97 
98             const std::string PROP_ZPOS_ID = "zpos";
99 
100             class DrmDevice;
101 
102             class DrmPlane {
103             public:
104                 explicit DrmPlane(drmModePlane &p);
105                 virtual ~DrmPlane();
106                 int32_t Init(DrmDevice &drmDevice);
107                 int GetCrtcProp(DrmDevice &drmDevice);
108                 int GetSrcProp(DrmDevice &drmDevice);
GetId() const109                 uint32_t GetId() const
110                 {
111                     return mId;
112                 }
GetPropFbId() const113                 uint32_t GetPropFbId() const
114                 {
115                     return mPropFbId;
116                 }
GetPropCrtc_xId() const117                 uint32_t GetPropCrtc_xId() const
118                 {
119                     return mPropCrtc_xId;
120                 }
GetPropCrtc_yId() const121                 uint32_t GetPropCrtc_yId() const
122                 {
123                     return mPropCrtc_yId;
124                 }
GetPropCrtc_wId() const125                 uint32_t GetPropCrtc_wId() const
126                 {
127                     return mPropCrtc_wId;
128                 }
GetPropCrtc_hId() const129                 uint32_t GetPropCrtc_hId() const
130                 {
131                     return mPropCrtc_hId;
132                 }
GetPropSrc_xId() const133                 uint32_t GetPropSrc_xId() const
134                 {
135                     return mPropSrc_xId;
136                 }
GetPropSrc_yId() const137                 uint32_t GetPropSrc_yId() const
138                 {
139                     return mPropSrc_yId;
140                 }
GetPropSrc_wId() const141                 uint32_t GetPropSrc_wId() const
142                 {
143                     return mPropSrc_wId;
144                 }
GetPropSrc_hId() const145                 uint32_t GetPropSrc_hId() const
146                 {
147                     return mPropSrc_hId;
148                 }
GetPropZposId() const149                 uint32_t GetPropZposId() const
150                 {
151                     return mPropZposId;
152                 }
GetPropFenceInId() const153                 uint32_t GetPropFenceInId() const
154                 {
155                     return mPropFenceInId;
156                 }
GetPropCrtcId() const157                 uint32_t GetPropCrtcId() const
158                 {
159                     return mPropCrtcId;
160                 }
GetPossibleCrtcs() const161                 uint32_t GetPossibleCrtcs() const
162                 {
163                     return mPossibleCrtcs;
164                 }
GetType() const165                 uint32_t GetType() const
166                 {
167                     return mType;
168                 }
BindToPipe(uint32_t pipe)169                 void BindToPipe(uint32_t pipe)
170                 {
171                     mPipe = pipe;
172                 }
UnBindPipe()173                 void UnBindPipe()
174                 {
175                     mPipe = 0;
176                 }
IsIdle() const177                 bool IsIdle() const
178                 {
179                     return (mPipe == 0);
180                 }
GetCrtcId()181                 uint32_t GetCrtcId()
182                 {
183                     return mCrtcId;
184                 }
GetPipe()185                 uint32_t GetPipe()
186                 {
187                     return mPipe;
188                 }
GetWinType()189                 DrmPlaneType GetWinType()
190                 {
191                     return mWinType;
192                 }
GetName()193                 std::string GetName()
194                 {
195                     return mName;
196                 }
197 
198             private:
199                 uint32_t mId = 0;
200                 uint32_t mPossibleCrtcs = 0;
201                 uint32_t mCrtcId = 0;
202                 uint32_t mPropFbId = 0;
203                 uint32_t mPropFenceInId = 0;
204                 uint32_t mPropCrtcId = 0;
205                 DrmPlaneType mWinType = DrmPlaneType::DRM_PLANE_TYPE_Unknown;
206                 std::string mName;
207 
208                 uint32_t mPropCrtc_xId = 0;
209                 uint32_t mPropCrtc_yId = 0;
210                 uint32_t mPropCrtc_wId = 0;
211                 uint32_t mPropCrtc_hId = 0;
212 
213                 uint32_t mPropSrc_xId = 0;
214                 uint32_t mPropSrc_yId = 0;
215                 uint32_t mPropSrc_wId = 0;
216                 uint32_t mPropSrc_hId = 0;
217 
218                 uint32_t mPropZposId = 0;
219 
220                 uint32_t mPipe = 0;
221                 uint32_t mType = 0;
222                 std::vector<uint32_t> mFormats;
223             };
224         } // namespace OHOS
225     }     // namespace HDI
226 } // namespace DISPLAY
227 
228 #endif // DRM_PLANE_H
229