• 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 #include "drm_plane.h"
17 #include "drm_device.h"
18 
19 namespace OHOS {
20 namespace HDI {
21 namespace DISPLAY {
22 struct PlaneTypeName planeTypeNames[] = {
23     { DrmPlaneType::DRM_PLANE_TYPE_CLUSTER0_WIN0, "Cluster0-win0" },
24     { DrmPlaneType::DRM_PLANE_TYPE_CLUSTER0_WIN1, "Cluster0-win1" },
25     { DrmPlaneType::DRM_PLANE_TYPE_CLUSTER1_WIN0, "Cluster1-win0" },
26     { DrmPlaneType::DRM_PLANE_TYPE_CLUSTER1_WIN1, "Cluster1-win1" },
27 
28     { DrmPlaneType::DRM_PLANE_TYPE_ESMART0_WIN0, "Esmart0-win0" },
29     { DrmPlaneType::DRM_PLANE_TYPE_ESMART0_WIN1, "Esmart0-win1" },
30     { DrmPlaneType::DRM_PLANE_TYPE_ESMART0_WIN2, "Esmart0-win2" },
31     { DrmPlaneType::DRM_PLANE_TYPE_ESMART0_WIN3, "Esmart0-win3" },
32 
33     { DrmPlaneType::DRM_PLANE_TYPE_ESMART1_WIN0, "Esmart1-win0" },
34     { DrmPlaneType::DRM_PLANE_TYPE_ESMART1_WIN1, "Esmart1-win1" },
35     { DrmPlaneType::DRM_PLANE_TYPE_ESMART1_WIN2, "Esmart1-win2" },
36     { DrmPlaneType::DRM_PLANE_TYPE_ESMART1_WIN3, "Esmart1-win3" },
37 
38     { DrmPlaneType::DRM_PLANE_TYPE_SMART0_WIN0, "Smart0-win0" },
39     { DrmPlaneType::DRM_PLANE_TYPE_SMART0_WIN1, "Smart0-win1" },
40     { DrmPlaneType::DRM_PLANE_TYPE_SMART0_WIN2, "Smart0-win2" },
41     { DrmPlaneType::DRM_PLANE_TYPE_SMART0_WIN3, "Smart0-win3" },
42 
43     { DrmPlaneType::DRM_PLANE_TYPE_SMART1_WIN0, "Smart1-win0" },
44     { DrmPlaneType::DRM_PLANE_TYPE_SMART1_WIN1, "Smart1-win1" },
45     { DrmPlaneType::DRM_PLANE_TYPE_SMART1_WIN2, "Smart1-win2" },
46     { DrmPlaneType::DRM_PLANE_TYPE_SMART1_WIN3, "Smart1-win3" },
47 
48     { DrmPlaneType::DRM_PLANE_TYPE_Unknown, "unknown" },
49 };
50 
DrmPlane(drmModePlane & p)51 DrmPlane::DrmPlane(drmModePlane &p)
52     : mId(p.plane_id), mPossibleCrtcs(p.possible_crtcs), mCrtcId(p.crtc_id),
53     mFormats(p.formats, p.formats + p.count_formats)
54 {}
55 
~DrmPlane()56 DrmPlane::~DrmPlane()
57 {
58     DISPLAY_DEBUGLOG();
59 }
60 
GetCrtcProp(DrmDevice & drmDevice)61 int DrmPlane::GetCrtcProp(DrmDevice &drmDevice)
62 {
63     int32_t ret;
64     int32_t crtc_x, crtc_y, crtc_w, crtc_h;
65     DrmProperty prop;
66 
67     ret = drmDevice.GetPlaneProperty(*this, PROP_CRTC_X_ID, prop);
68     DISPLAY_CHK_RETURN((ret != DISPLAY_SUCCESS), DISPLAY_FAILURE, DISPLAY_LOGE("cat not get pane crtc_x prop id"));
69     mPropCrtc_xId = prop.propId;
70     crtc_x = prop.value;
71 
72     ret = drmDevice.GetPlaneProperty(*this, PROP_CRTC_Y_ID, prop);
73     DISPLAY_CHK_RETURN((ret != DISPLAY_SUCCESS), DISPLAY_FAILURE, DISPLAY_LOGE("cat not get pane crtc_y prop id"));
74     mPropCrtc_yId = prop.propId;
75     crtc_y = prop.value;
76 
77     ret = drmDevice.GetPlaneProperty(*this, PROP_CRTC_W_ID, prop);
78     DISPLAY_CHK_RETURN((ret != DISPLAY_SUCCESS), DISPLAY_FAILURE, DISPLAY_LOGE("cat not get pane crtc_w prop id"));
79     mPropCrtc_wId = prop.propId;
80     crtc_w = prop.value;
81 
82     ret = drmDevice.GetPlaneProperty(*this, PROP_CRTC_H_ID, prop);
83     DISPLAY_CHK_RETURN((ret != DISPLAY_SUCCESS), DISPLAY_FAILURE, DISPLAY_LOGE("cat not get pane crtc_h prop id"));
84     mPropCrtc_hId = prop.propId;
85     crtc_h = prop.value;
86 
87     DISPLAY_LOGE("plane %{public}d crtc_x %{public}d crtc_y %{public}d crtc_w %{public}d crtc_h %{public}d",
88         GetId(), crtc_x, crtc_y, crtc_w, crtc_h);
89 
90     return 0;
91 }
92 
GetSrcProp(DrmDevice & drmDevice)93 int  DrmPlane::GetSrcProp(DrmDevice &drmDevice)
94 {
95     int32_t ret;
96     int32_t src_x, src_y, src_w, src_h;
97     DrmProperty prop;
98 
99     ret = drmDevice.GetPlaneProperty(*this, PROP_SRC_X_ID, prop);
100     DISPLAY_CHK_RETURN((ret != DISPLAY_SUCCESS), DISPLAY_FAILURE, DISPLAY_LOGE("cat not get pane src_x prop id"));
101     mPropSrc_xId = prop.propId;
102     src_x = prop.value;
103 
104     ret = drmDevice.GetPlaneProperty(*this, PROP_SRC_Y_ID, prop);
105     DISPLAY_CHK_RETURN((ret != DISPLAY_SUCCESS), DISPLAY_FAILURE, DISPLAY_LOGE("cat not get pane src_y prop id"));
106     mPropSrc_yId = prop.propId;
107     src_y = prop.value;
108 
109     ret = drmDevice.GetPlaneProperty(*this, PROP_SRC_W_ID, prop);
110     DISPLAY_CHK_RETURN((ret != DISPLAY_SUCCESS), DISPLAY_FAILURE, DISPLAY_LOGE("cat not get pane src_w prop id"));
111     mPropSrc_wId = prop.propId;
112     src_w = prop.value;
113 
114     ret = drmDevice.GetPlaneProperty(*this, PROP_SRC_H_ID, prop);
115     DISPLAY_CHK_RETURN((ret != DISPLAY_SUCCESS), DISPLAY_FAILURE, DISPLAY_LOGE("cat not get pane src_h prop id"));
116     mPropSrc_hId = prop.propId;
117     src_h = prop.value;
118 
119     DISPLAY_LOGE("plane %{public}d src_x %{public}d src_y %{public}d src_w %{public}d src_h %{public}d",
120         GetId(), src_x, src_y, src_w, src_h);
121 
122     return 0;
123 }
124 
Init(DrmDevice & drmDevice)125 int32_t DrmPlane::Init(DrmDevice &drmDevice)
126 {
127     DISPLAY_DEBUGLOG();
128     int32_t ret;
129     uint32_t find_name = 0;
130     DrmProperty prop;
131     GetCrtcProp(drmDevice);
132     GetSrcProp(drmDevice);
133     ret = drmDevice.GetPlaneProperty(*this, PROP_FBID, prop);
134     mPropFbId = prop.propId;
135     DISPLAY_CHK_RETURN((ret != DISPLAY_SUCCESS), DISPLAY_FAILURE, DISPLAY_LOGE("can not get plane fb id"));
136     ret = drmDevice.GetPlaneProperty(*this, PROP_IN_FENCE_FD, prop);
137     DISPLAY_CHK_RETURN((ret != DISPLAY_SUCCESS), DISPLAY_FAILURE, DISPLAY_LOGE("cat not get plane in fence prop id"));
138     mPropFenceInId = prop.propId;
139     ret = drmDevice.GetPlaneProperty(*this, PROP_CRTC_ID, prop);
140     DISPLAY_CHK_RETURN((ret != DISPLAY_SUCCESS), DISPLAY_FAILURE, DISPLAY_LOGE("cat not get pane crtc prop id"));
141     mPropCrtcId = prop.propId;
142 
143     ret = drmDevice.GetPlaneProperty(*this, PROP_ZPOS_ID, prop);
144     DISPLAY_CHK_RETURN((ret != DISPLAY_SUCCESS), DISPLAY_FAILURE, DISPLAY_LOGE("cat not get pane crtc prop id"));
145     mPropZposId = prop.propId;
146 
147     ret = drmDevice.GetPlaneProperty(*this, "NAME", prop);
148     DISPLAY_CHK_RETURN((ret != DISPLAY_SUCCESS), DISPLAY_FAILURE, DISPLAY_LOGE("cat not get pane crtc prop id"));
149 
150     int i = 0;
151     int tmp = static_cast<int>ARRAY_SIZE(planeTypeNames);
152     for (i = 0; i < tmp; i++) {
153         find_name = 0;
154 
155         for (auto &drmEnum : prop.enums) {
156             if (!strncmp(drmEnum.name.c_str(), (const char*)planeTypeNames[i].name, strlen(planeTypeNames[i].name))) {
157                 find_name = (1LL << drmEnum.value);
158             }
159         }
160 
161         if (find_name) {
162             DISPLAY_LOGI("find plane id %{public}d, type %{public}x %{public}s",
163                 GetId(), planeTypeNames[i].type, planeTypeNames[i].name);
164             mWinType = planeTypeNames[i].type;
165             mName = planeTypeNames[i].name;
166             break;
167         }
168     }
169 
170     ret = drmDevice.GetPlaneProperty(*this, PROP_TYPE, prop);
171     DISPLAY_CHK_RETURN((ret != DISPLAY_SUCCESS), DISPLAY_FAILURE, DISPLAY_LOGE("cat not get pane crtc prop id"));
172     switch (prop.value) {
173         case DRM_PLANE_TYPE_OVERLAY:
174         case DRM_PLANE_TYPE_PRIMARY:
175         case DRM_PLANE_TYPE_CURSOR:
176             mType = static_cast<uint32_t>(prop.value);
177             break;
178         default:
179             DISPLAY_LOGE("unknown type value %{public}" PRIu64 "", prop.value);
180             return DISPLAY_FAILURE;
181     }
182     return DISPLAY_SUCCESS;
183 }
184 } // namespace OHOS
185 } // namespace HDI
186 } // namespace DISPLAY
187