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
24namespace OHOS {
25namespace HDI {
26namespace DISPLAY {
27enum 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
36enum 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
73struct PlaneMaskName {
74    DrmPlaneType mask;
75    const char *name;
76};
77
78struct PlaneTypeName {
79    DrmPlaneType type;
80    const char *name;
81};
82
83const std::string PROP_FBID = "FB_ID";
84const std::string PROP_IN_FENCE_FD = "IN_FENCE_FD";
85const std::string PROP_CRTC_ID = "CRTC_ID";
86const std::string PROP_TYPE = "type";
87
88const std::string PROP_CRTC_X_ID = "CRTC_X";
89const std::string PROP_CRTC_Y_ID = "CRTC_Y";
90const std::string PROP_CRTC_W_ID = "CRTC_W";
91const std::string PROP_CRTC_H_ID = "CRTC_H";
92
93const std::string PROP_SRC_X_ID = "SRC_X";
94const std::string PROP_SRC_Y_ID = "SRC_Y";
95const std::string PROP_SRC_W_ID = "SRC_W";
96const std::string PROP_SRC_H_ID = "SRC_H";
97
98const std::string PROP_ZPOS_ID = "zpos";
99
100class DrmDevice;
101
102class DrmPlane {
103public:
104    explicit DrmPlane(drmModePlane &p);
105    virtual ~DrmPlane();
106    int32_t Init(DrmDevice &drmDevice);
107    int GetCrtcProp(DrmDevice &drmDevice);
108    int GetSrcProp(DrmDevice &drmDevice);
109    int GetNameProp(DrmDevice &drmDevice);
110    uint32_t GetId() const
111    {
112        return mId;
113    }
114    uint32_t GetPropFbId() const
115    {
116        return mPropFbId;
117    }
118    uint32_t GetPropCrtc_xId() const
119    {
120        return mPropCrtc_xId;
121    }
122    uint32_t GetPropCrtc_yId() const
123    {
124        return mPropCrtc_yId;
125    }
126    uint32_t GetPropCrtc_wId() const
127    {
128        return mPropCrtc_wId;
129    }
130    uint32_t GetPropCrtc_hId() const
131    {
132        return mPropCrtc_hId;
133    }
134    uint32_t GetPropSrc_xId() const
135    {
136        return mPropSrc_xId;
137    }
138    uint32_t GetPropSrc_yId() const
139    {
140        return mPropSrc_yId;
141    }
142    uint32_t GetPropSrc_wId() const
143    {
144        return mPropSrc_wId;
145    }
146    uint32_t GetPropSrc_hId() const
147    {
148        return mPropSrc_hId;
149    }
150    uint32_t GetPropZposId() const
151    {
152        return mPropZposId;
153    }
154    uint32_t GetPropFenceInId() const
155    {
156        return mPropFenceInId;
157    }
158    uint32_t GetPropCrtcId() const
159    {
160        return mPropCrtcId;
161    }
162    uint32_t GetPossibleCrtcs() const
163    {
164        return mPossibleCrtcs;
165    }
166    uint32_t GetType() const
167    {
168        return mType;
169    }
170    void BindToPipe(uint32_t pipe)
171    {
172        mPipe = pipe;
173    }
174    void UnBindPipe()
175    {
176        mPipe = 0;
177    }
178    bool IsIdle() const
179    {
180        return (mPipe == 0);
181    }
182    uint32_t GetCrtcId()
183    {
184        return mCrtcId;
185    }
186    uint32_t GetPipe()
187    {
188        return mPipe;
189    }
190    DrmPlaneType GetWinType()
191    {
192        return mWinType;
193    }
194    std::string GetName()
195    {
196        return mName;
197    }
198private:
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