• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     // Cluster 0
38     DRM_PLANE_TYPE_CLUSTER0_WIN0 = 1 << 0,
39     DRM_PLANE_TYPE_CLUSTER0_WIN1 = 1 << 1,
40     // Cluster 1
41     DRM_PLANE_TYPE_CLUSTER1_WIN0 = 1 << 2,
42     DRM_PLANE_TYPE_CLUSTER1_WIN1 = 1 << 3,
43     // Cluster 2
44     DRM_PLANE_TYPE_CLUSTER2_WIN0 = 1 << 4,
45     DRM_PLANE_TYPE_CLUSTER2_WIN1 = 1 << 5,
46     // Cluster 3
47     DRM_PLANE_TYPE_CLUSTER3_WIN0 = 1 << 6,
48     DRM_PLANE_TYPE_CLUSTER3_WIN1 = 1 << 7,
49     // Esmart 0
50     DRM_PLANE_TYPE_ESMART0_WIN0 = 1 << 8,
51     DRM_PLANE_TYPE_ESMART0_WIN1 = 1 << 10,
52     DRM_PLANE_TYPE_ESMART0_WIN2 = 1 << 16,
53     DRM_PLANE_TYPE_ESMART0_WIN3 = 1 << 20,
54     // Esmart 1
55     DRM_PLANE_TYPE_ESMART1_WIN0 = 1 << 12,
56     DRM_PLANE_TYPE_ESMART1_WIN1 = 1 << 13,
57     DRM_PLANE_TYPE_ESMART1_WIN2 = 1 << 14,
58     DRM_PLANE_TYPE_ESMART1_WIN3 = 1 << 15,
59     // Esmart 2
60     DRM_PLANE_TYPE_ESMART2_WIN0 = 1 << 9,
61     DRM_PLANE_TYPE_ESMART2_WIN1 = 1 << 17,
62     DRM_PLANE_TYPE_ESMART2_WIN2 = 1 << 18,
63     DRM_PLANE_TYPE_ESMART2_WIN3 = 1 << 19,
64     // Esmart 3
65     DRM_PLANE_TYPE_ESMART3_WIN0 = 1 << 11,
66     DRM_PLANE_TYPE_ESMART3_WIN1 = 1 << 21,
67     DRM_PLANE_TYPE_ESMART3_WIN2 = 1 << 22,
68     DRM_PLANE_TYPE_ESMART3_WIN3 = 1 << 23,
69     // Cluster mask
70     DRM_PLANE_TYPE_CLUSTER0_MASK= 0x1,
71     DRM_PLANE_TYPE_CLUSTER1_MASK= 0x2,
72     DRM_PLANE_TYPE_CLUSTER2_MASK= 0x40,
73     DRM_PLANE_TYPE_CLUSTER3_MASK= 0x80,
74 
75     DRM_PLANE_TYPE_CLUSTER_MASK = 0xff,
76     // Esmart mask
77     DRM_PLANE_TYPE_ESMART0_MASK = 0x04,
78     DRM_PLANE_TYPE_ESMART1_MASK = 0x08,
79     DRM_PLANE_TYPE_ESMART2_MASK = 0x100,
80     DRM_PLANE_TYPE_ESMART3_MASK = 0x200,
81     DRM_PLANE_TYPE_ESMART_MASK = 0xffff00,
82     DRM_PLANE_TYPE_Unknown      = 0xffffffff,
83 };
84 
85 struct PlaneMaskName {
86     DrmPlaneType mask;
87     const char *name;
88 };
89 
90 struct PlaneTypeName {
91     DrmPlaneType type;
92     const char *name;
93 };
94 
95 const std::string PROP_FBID = "FB_ID";
96 const std::string PROP_IN_FENCE_FD = "IN_FENCE_FD";
97 const std::string PROP_CRTC_ID = "CRTC_ID";
98 const std::string PROP_TYPE = "type";
99 
100 const std::string PROP_CRTC_X_ID = "CRTC_X";
101 const std::string PROP_CRTC_Y_ID = "CRTC_Y";
102 const std::string PROP_CRTC_W_ID = "CRTC_W";
103 const std::string PROP_CRTC_H_ID = "CRTC_H";
104 
105 const std::string PROP_SRC_X_ID = "SRC_X";
106 const std::string PROP_SRC_Y_ID = "SRC_Y";
107 const std::string PROP_SRC_W_ID = "SRC_W";
108 const std::string PROP_SRC_H_ID = "SRC_H";
109 
110 const std::string PROP_ZPOS_ID = "zpos";
111 
112 class DrmDevice;
113 
114 class DrmPlane {
115 public:
116     explicit DrmPlane(drmModePlane &p);
117     virtual ~DrmPlane();
118     int32_t Init(DrmDevice &drmDevice);
119     int GetCrtcProp(DrmDevice &drmDevice);
120     int GetSrcProp(DrmDevice &drmDevice);
GetId()121     uint32_t GetId() const
122     {
123         return mId;
124     }
GetPropFbId()125     uint32_t GetPropFbId() const
126     {
127         return mPropFbId;
128     }
GetPropCrtc_xId()129     uint32_t GetPropCrtc_xId() const
130     {
131         return mPropCrtc_xId;
132     }
GetPropCrtc_yId()133     uint32_t GetPropCrtc_yId() const
134     {
135         return mPropCrtc_yId;
136     }
GetPropCrtc_wId()137     uint32_t GetPropCrtc_wId() const
138     {
139         return mPropCrtc_wId;
140     }
GetPropCrtc_hId()141     uint32_t GetPropCrtc_hId() const
142     {
143         return mPropCrtc_hId;
144     }
GetPropSrc_xId()145     uint32_t GetPropSrc_xId() const
146     {
147         return mPropSrc_xId;
148     }
GetPropSrc_yId()149     uint32_t GetPropSrc_yId() const
150     {
151         return mPropSrc_yId;
152     }
GetPropSrc_wId()153     uint32_t GetPropSrc_wId() const
154     {
155         return mPropSrc_wId;
156     }
GetPropSrc_hId()157     uint32_t GetPropSrc_hId() const
158     {
159         return mPropSrc_hId;
160     }
GetPropZposId()161     uint32_t GetPropZposId() const
162     {
163         return mPropZposId;
164     }
GetPropFenceInId()165     uint32_t GetPropFenceInId() const
166     {
167         return mPropFenceInId;
168     }
GetPropCrtcId()169     uint32_t GetPropCrtcId() const
170     {
171         return mPropCrtcId;
172     }
GetPossibleCrtcs()173     uint32_t GetPossibleCrtcs() const
174     {
175         return mPossibleCrtcs;
176     }
GetType()177     uint32_t GetType() const
178     {
179         return mType;
180     }
BindToPipe(uint32_t pipe)181     void BindToPipe(uint32_t pipe)
182     {
183         mPipe = pipe;
184     }
UnBindPipe()185     void UnBindPipe()
186     {
187         mPipe = 0;
188     }
IsIdle()189     bool IsIdle() const
190     {
191         return (mPipe == 0);
192     }
GetCrtcId()193     uint32_t GetCrtcId()
194     {
195         return mCrtcId;
196     }
GetPipe()197     uint32_t GetPipe()
198     {
199         return mPipe;
200     }
GetWinType()201     DrmPlaneType GetWinType()
202     {
203         return mWinType;
204     }
GetName()205     std::string GetName()
206     {
207         return mName;
208     }
209 private:
210     uint32_t mId = 0;
211     uint32_t mPossibleCrtcs = 0;
212     uint32_t mCrtcId = 0;
213     uint32_t mPropFbId = 0;
214     uint32_t mPropFenceInId = 0;
215     uint32_t mPropCrtcId = 0;
216     DrmPlaneType mWinType = DrmPlaneType::DRM_PLANE_TYPE_Unknown;
217     std::string mName;
218 
219     uint32_t mPropCrtc_xId = 0;
220     uint32_t mPropCrtc_yId = 0;
221     uint32_t mPropCrtc_wId = 0;
222     uint32_t mPropCrtc_hId = 0;
223 
224     uint32_t mPropSrc_xId = 0;
225     uint32_t mPropSrc_yId = 0;
226     uint32_t mPropSrc_wId = 0;
227     uint32_t mPropSrc_hId = 0;
228 
229     uint32_t mPropZposId = 0;
230 
231     uint32_t mPipe = 0;
232     uint32_t mType = 0;
233     std::vector<uint32_t> mFormats;
234 };
235 } // namespace OHOS
236 } // namespace HDI
237 } // namespace DISPLAY
238 
239 #endif // DRM_PLANE_H
240