• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2023 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_crtc.h"
17 #include "display_log.h"
18 #include "drm_device.h"
19 
20 namespace OHOS {
21 namespace HDI {
22 namespace DISPLAY {
23 struct PlaneMaskName planeMaskNames[] = {
24     { DrmPlaneType::DRM_PLANE_TYPE_CLUSTER0_MASK, "Cluster0" },
25     { DrmPlaneType::DRM_PLANE_TYPE_CLUSTER1_MASK, "Cluster1" },
26     { DrmPlaneType::DRM_PLANE_TYPE_ESMART0_MASK, "Esmart0" },
27     { DrmPlaneType::DRM_PLANE_TYPE_ESMART1_MASK, "Esmart1" },
28     { DrmPlaneType::DRM_PLANE_TYPE_SMART0_MASK, "Smart0" },
29     { DrmPlaneType::DRM_PLANE_TYPE_SMART1_MASK, "Smart1" },
30     { DrmPlaneType::DRM_PLANE_TYPE_Unknown, "unknown" },
31 };
32 
DrmCrtc(drmModeCrtcPtr c,uint32_t pipe)33 DrmCrtc::DrmCrtc(drmModeCrtcPtr c, uint32_t pipe) : mId(c->crtc_id), mPipe(pipe), mPlaneMask(0)
34 {
35 }
36 
Init(DrmDevice & drmDevice)37 int32_t DrmCrtc::Init(DrmDevice &drmDevice)
38 {
39     DISPLAY_LOGD();
40     int32_t ret;
41     DrmProperty prop;
42     ret = drmDevice.GetCrtcProperty(*this, PROP_MODEID, prop);
43     mModePropId = prop.propId;
44     DISPLAY_CHK_RETURN((ret != DISPLAY_SUCCESS), DISPLAY_FAILURE, DISPLAY_LOGE("can not get mode prop id"));
45 
46     ret = drmDevice.GetCrtcProperty(*this, PROP_OUTFENCE, prop);
47     DISPLAY_CHK_RETURN((ret != DISPLAY_SUCCESS), DISPLAY_FAILURE, DISPLAY_LOGE("cat not get out fence prop id"));
48     mOutFencePropId = prop.propId;
49 
50     ret = drmDevice.GetCrtcProperty(*this, PROP_ACTIVE, prop);
51     DISPLAY_CHK_RETURN((ret != DISPLAY_SUCCESS), DISPLAY_FAILURE, DISPLAY_LOGE("cat not get out fence prop id"));
52     mActivePropId = prop.propId;
53 
54     // Plane mask
55     mPlaneMask = 0;
56     ret = drmDevice.GetCrtcProperty(*this, "PLANE_MASK", prop);
57     if (ret != DISPLAY_SUCCESS) {
58         DISPLAY_LOGE("Failed to get plane_mask property");
59     } else {
60         for (int i = 0; i < static_cast<int>(ARRAY_SIZE(planeMaskNames)); i++) {
61             for (auto &drmEnum : prop.enums) {
62                 if (!strncmp(drmEnum.name.c_str(), (const char*)planeMaskNames[i].name,
63                              strlen(drmEnum.name.c_str())) && (prop.value & (1LL << drmEnum.value)) > 0) {
64                     mPlaneMask |=  static_cast<int>(planeMaskNames[i].mask);
65                     DISPLAY_LOGI("crtc id %{public}d, plane name %{public}s value %{public}llx",
66                                  GetId(), (const char*)planeMaskNames[i].name,
67                                  (long long)planeMaskNames[i].mask);
68                 }
69             }
70         }
71     }
72     return DISPLAY_SUCCESS;
73 }
74 
BindToDisplay(uint32_t id)75 int32_t DrmCrtc::BindToDisplay(uint32_t id)
76 {
77     DISPLAY_CHK_RETURN((mDisplayId != INVALIDE_DISPLAY_ID), DISPLAY_FAILURE,
78         DISPLAY_LOGE("the crtc has bind to %{public}d", mDisplayId));
79     mDisplayId = id;
80     return DISPLAY_SUCCESS;
81 }
82 
UnBindDisplay(uint32_t id)83 void DrmCrtc::UnBindDisplay(uint32_t id)
84 {
85     DISPLAY_LOGD();
86     if (mDisplayId == id) {
87         mDisplayId = INVALIDE_DISPLAY_ID;
88     } else {
89         DISPLAY_LOGE("can not unbind");
90     }
91 }
92 
CanBind()93 bool DrmCrtc::CanBind()
94 {
95     return (mDisplayId == INVALIDE_DISPLAY_ID);
96 }
97 
SetActivieMode(int32_t id)98 int32_t DrmCrtc::SetActivieMode(int32_t id)
99 {
100     DISPLAY_LOGD("set activie modeid to %{public}d", id);
101     DISPLAY_CHK_RETURN((id > 0), DISPLAY_PARAM_ERR, DISPLAY_LOGE("id %{public}d is invalid ", id));
102     if (mActiveModeId != id) {
103         mNeedModeSet = true;
104     }
105     mActiveModeId = id;
106     return DISPLAY_SUCCESS;
107 }
108 } // namespace OHOS
109 } // namespace HDI
110 } // namespace DISPLAY
111