• 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_common.h"
18 #include "drm_device.h"
19 
20 namespace OHOS {
21 namespace HDI {
22 namespace DISPLAY {
DrmCrtc(drmModeCrtcPtr c,uint32_t pipe)23 DrmCrtc::DrmCrtc(drmModeCrtcPtr c, uint32_t pipe) : mId(c->crtc_id), mPipe(pipe) {}
24 
Init(DrmDevice & drmDevice)25 int32_t DrmCrtc::Init(DrmDevice &drmDevice)
26 {
27     DISPLAY_LOGD();
28     int32_t ret;
29     DrmProperty prop;
30     ret = drmDevice.GetCrtcProperty(*this, PROP_MODEID, prop);
31     mModePropId = prop.propId;
32     DISPLAY_CHK_RETURN((ret != DISPLAY_SUCCESS), DISPLAY_FAILURE, DISPLAY_LOGE("can not get mode prop id"));
33 
34     ret = drmDevice.GetCrtcProperty(*this, PROP_OUTFENCE, prop);
35     DISPLAY_CHK_RETURN((ret != DISPLAY_SUCCESS), DISPLAY_FAILURE, DISPLAY_LOGE("cat not get out fence prop id"));
36     mOutFencePropId = prop.propId;
37 
38     ret = drmDevice.GetCrtcProperty(*this, PROP_ACTIVE, prop);
39     DISPLAY_CHK_RETURN((ret != DISPLAY_SUCCESS), DISPLAY_FAILURE, DISPLAY_LOGE("cat not get out fence prop id"));
40     mActivePropId = prop.propId;
41 
42     return DISPLAY_SUCCESS;
43 }
44 
BindToDisplay(uint32_t id)45 int32_t DrmCrtc::BindToDisplay(uint32_t id)
46 {
47     DISPLAY_CHK_RETURN((mDisplayId != INVALIDE_DISPLAY_ID), DISPLAY_FAILURE,
48         DISPLAY_LOGE("the crtc has bind to %{public}d", mDisplayId));
49     mDisplayId = id;
50     return DISPLAY_SUCCESS;
51 }
52 
UnBindDisplay(uint32_t id)53 void DrmCrtc::UnBindDisplay(uint32_t id)
54 {
55     DISPLAY_LOGD();
56     if (mDisplayId == id) {
57         mDisplayId = INVALIDE_DISPLAY_ID;
58     } else {
59         DISPLAY_LOGE("can not unbind");
60     }
61 }
62 
CanBind()63 bool DrmCrtc::CanBind()
64 {
65     return (mDisplayId == INVALIDE_DISPLAY_ID);
66 }
67 
SetActivieMode(int32_t id)68 int32_t DrmCrtc::SetActivieMode(int32_t id)
69 {
70     DISPLAY_LOGD("set activie modeid to %{public}d", id);
71     DISPLAY_CHK_RETURN((id > 0), DISPLAY_PARAM_ERR, DISPLAY_LOGE("id %{public}d is invalid ", id));
72     if (mActiveModeId != id) {
73         mNeedModeSet = true;
74     }
75     mActiveModeId = id;
76     return DISPLAY_SUCCESS;
77 }
78 } // namespace OHOS
79 } // namespace HDI
80 } // namespace DISPLAY
81