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