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 } 56 ~DrmPlane()57 DrmPlane::~DrmPlane() 58 { 59 DISPLAY_DEBUGLOG(); 60 } 61 GetCrtcProp(DrmDevice & drmDevice)62 int DrmPlane::GetCrtcProp(DrmDevice &drmDevice) 63 { 64 int32_t ret; 65 int32_t crtc_x, crtc_y, crtc_w, crtc_h; 66 DrmProperty prop; 67 68 ret = drmDevice.GetPlaneProperty(*this, PROP_CRTC_X_ID, prop); 69 DISPLAY_CHK_RETURN((ret != DISPLAY_SUCCESS), DISPLAY_FAILURE, 70 DISPLAY_LOGE("cat not get pane crtc_x prop id")); 71 mPropCrtc_xId = prop.propId; 72 crtc_x = prop.value; 73 74 ret = drmDevice.GetPlaneProperty(*this, PROP_CRTC_Y_ID, prop); 75 DISPLAY_CHK_RETURN((ret != DISPLAY_SUCCESS), DISPLAY_FAILURE, 76 DISPLAY_LOGE("cat not get pane crtc_y prop id")); 77 mPropCrtc_yId = prop.propId; 78 crtc_y = prop.value; 79 80 ret = drmDevice.GetPlaneProperty(*this, PROP_CRTC_W_ID, prop); 81 DISPLAY_CHK_RETURN((ret != DISPLAY_SUCCESS), DISPLAY_FAILURE, 82 DISPLAY_LOGE("cat not get pane crtc_w prop id")); 83 mPropCrtc_wId = prop.propId; 84 crtc_w = prop.value; 85 86 ret = drmDevice.GetPlaneProperty(*this, PROP_CRTC_H_ID, prop); 87 DISPLAY_CHK_RETURN((ret != DISPLAY_SUCCESS), DISPLAY_FAILURE, 88 DISPLAY_LOGE("cat not get pane crtc_h prop id")); 89 mPropCrtc_hId = prop.propId; 90 crtc_h = prop.value; 91 92 DISPLAY_LOGE("plane %{public}d crtc_x %{public}d crtc_y %{public}d crtc_w %{public}d crtc_h %{public}d", 93 GetId(), crtc_x, crtc_y, crtc_w, crtc_h); 94 95 return 0; 96 } 97 GetSrcProp(DrmDevice & drmDevice)98 int DrmPlane::GetSrcProp(DrmDevice &drmDevice) 99 { 100 int32_t ret; 101 int32_t src_x, src_y, src_w, src_h; 102 DrmProperty prop; 103 104 ret = drmDevice.GetPlaneProperty(*this, PROP_SRC_X_ID, prop); 105 DISPLAY_CHK_RETURN((ret != DISPLAY_SUCCESS), DISPLAY_FAILURE, 106 DISPLAY_LOGE("cat not get pane src_x prop id")); 107 mPropSrc_xId = prop.propId; 108 src_x = prop.value; 109 110 ret = drmDevice.GetPlaneProperty(*this, PROP_SRC_Y_ID, prop); 111 DISPLAY_CHK_RETURN((ret != DISPLAY_SUCCESS), DISPLAY_FAILURE, 112 DISPLAY_LOGE("cat not get pane src_y prop id")); 113 mPropSrc_yId = prop.propId; 114 src_y = prop.value; 115 116 ret = drmDevice.GetPlaneProperty(*this, PROP_SRC_W_ID, prop); 117 DISPLAY_CHK_RETURN((ret != DISPLAY_SUCCESS), DISPLAY_FAILURE, 118 DISPLAY_LOGE("cat not get pane src_w prop id")); 119 mPropSrc_wId = prop.propId; 120 src_w = prop.value; 121 122 ret = drmDevice.GetPlaneProperty(*this, PROP_SRC_H_ID, prop); 123 DISPLAY_CHK_RETURN((ret != DISPLAY_SUCCESS), DISPLAY_FAILURE, 124 DISPLAY_LOGE("cat not get pane src_h prop id")); 125 mPropSrc_hId = prop.propId; 126 src_h = prop.value; 127 128 DISPLAY_LOGE("plane %{public}d src_x %{public}d src_y %{public}d src_w %{public}d src_h %{public}d", 129 GetId(), src_x, src_y, src_w, src_h); 130 131 return 0; 132 } 133 Init(DrmDevice & drmDevice)134 int32_t DrmPlane::Init(DrmDevice &drmDevice) 135 { 136 DISPLAY_DEBUGLOG(); 137 int32_t ret; 138 uint32_t find_name = 0; 139 DrmProperty prop; 140 GetCrtcProp(drmDevice); 141 GetSrcProp(drmDevice); 142 ret = drmDevice.GetPlaneProperty(*this, PROP_FBID, prop); 143 mPropFbId = prop.propId; 144 DISPLAY_CHK_RETURN((ret != DISPLAY_SUCCESS), DISPLAY_FAILURE, DISPLAY_LOGE("can not get plane fb id")); 145 ret = drmDevice.GetPlaneProperty(*this, PROP_IN_FENCE_FD, prop); 146 DISPLAY_CHK_RETURN((ret != DISPLAY_SUCCESS), DISPLAY_FAILURE, 147 DISPLAY_LOGE("cat not get plane in fence prop id")); 148 mPropFenceInId = prop.propId; 149 ret = drmDevice.GetPlaneProperty(*this, PROP_CRTC_ID, prop); 150 DISPLAY_CHK_RETURN((ret != DISPLAY_SUCCESS), DISPLAY_FAILURE, 151 DISPLAY_LOGE("cat not get pane crtc prop id")); 152 mPropCrtcId = prop.propId; 153 154 ret = drmDevice.GetPlaneProperty(*this, PROP_ZPOS_ID, prop); 155 DISPLAY_CHK_RETURN((ret != DISPLAY_SUCCESS), DISPLAY_FAILURE, 156 DISPLAY_LOGE("cat not get pane crtc prop id")); 157 mPropZposId = prop.propId; 158 159 ret = drmDevice.GetPlaneProperty(*this, "NAME", prop); 160 DISPLAY_CHK_RETURN((ret != DISPLAY_SUCCESS), DISPLAY_FAILURE, 161 DISPLAY_LOGE("cat not get pane crtc prop id")); 162 int count = static_cast<int> ARRAY_SIZE(planeTypeNames); 163 for (int i = 0; i < count; i++) { 164 find_name = 0; 165 166 for (auto &drmEnum : prop.enums) { 167 if (!strncmp(drmEnum.name.c_str(), (const char *)planeTypeNames[i].name, 168 strlen(planeTypeNames[i].name))) { 169 find_name = (1LL << drmEnum.value); 170 } 171 } 172 173 if (find_name) { 174 DISPLAY_LOGI("find plane id %{public}d, type %{public}x %{public}s", GetId(), 175 planeTypeNames[i].type, planeTypeNames[i].name); 176 mWinType = planeTypeNames[i].type; 177 mName = planeTypeNames[i].name; 178 break; 179 } 180 } 181 182 ret = drmDevice.GetPlaneProperty(*this, PROP_TYPE, prop); 183 DISPLAY_CHK_RETURN((ret != DISPLAY_SUCCESS), DISPLAY_FAILURE, 184 DISPLAY_LOGE("cat not get pane crtc prop id")); 185 switch (prop.value) { 186 case DRM_PLANE_TYPE_OVERLAY: 187 case DRM_PLANE_TYPE_PRIMARY: 188 case DRM_PLANE_TYPE_CURSOR: 189 mType = static_cast<uint32_t>(prop.value); 190 break; 191 default: 192 DISPLAY_LOGE("unknown type value %{public}" PRIu64 "", prop.value); 193 return DISPLAY_FAILURE; 194 } 195 return DISPLAY_SUCCESS; 196 } 197 } // namespace OHOS 198 } // namespace HDI 199 } // namespace DISPLAY 200