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 {
DrmPlane(drmModePlane & p)22 DrmPlane::DrmPlane(drmModePlane &p)
23 : mId(p.plane_id), mPossibleCrtcs(p.possible_crtcs), mFormats(p.formats, p.formats + p.count_formats)
24 {}
25
~DrmPlane()26 DrmPlane::~DrmPlane()
27 {
28 DISPLAY_LOGD();
29 }
30
Init(DrmDevice & drmDevice)31 int32_t DrmPlane::Init(DrmDevice &drmDevice)
32 {
33 DISPLAY_LOGD();
34 int32_t ret;
35 DrmProperty prop;
36 ret = drmDevice.GetPlaneProperty(*this, PROP_FBID, prop);
37 mPropFbId = prop.propId;
38 DISPLAY_CHK_RETURN((ret != DISPLAY_SUCCESS), DISPLAY_FAILURE, DISPLAY_LOGE("can not get plane fb id"));
39 ret = drmDevice.GetPlaneProperty(*this, PROP_IN_FENCE_FD, prop);
40 DISPLAY_CHK_RETURN((ret != DISPLAY_SUCCESS), DISPLAY_FAILURE, DISPLAY_LOGE("cat not get plane in fence prop id"));
41 mPropFenceInId = prop.propId;
42 ret = drmDevice.GetPlaneProperty(*this, PROP_CRTC_ID, prop);
43 DISPLAY_CHK_RETURN((ret != DISPLAY_SUCCESS), DISPLAY_FAILURE, DISPLAY_LOGE("cat not get pane crtc prop id"));
44 mPropCrtcId = prop.propId;
45 ret = drmDevice.GetPlaneProperty(*this, PROP_TYPE, prop);
46 DISPLAY_CHK_RETURN((ret != DISPLAY_SUCCESS), DISPLAY_FAILURE, DISPLAY_LOGE("cat not get pane crtc prop id"));
47 switch (prop.value) {
48 case DRM_PLANE_TYPE_OVERLAY:
49 case DRM_PLANE_TYPE_PRIMARY:
50 case DRM_PLANE_TYPE_CURSOR:
51 mType = static_cast<uint32_t>(prop.value);
52 break;
53 default:
54 DISPLAY_LOGE("unknown type value %{public}" PRIu64 "", prop.value);
55 return DISPLAY_FAILURE;
56 }
57 return DISPLAY_SUCCESS;
58 }
59 } // namespace OHOS
60 } // namespace HDI
61 } // namespace DISPLAY
62