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 #ifndef DRM_CRTC_H
17 #define DRM_CRTC_H
18 #include <string>
19 #include <memory>
20 #include <xf86drm.h>
21 #include <xf86drmMode.h>
22 #include "hdi_device_common.h"
23 #include "hdi_display.h"
24 
25 namespace OHOS {
26     namespace HDI {
27         namespace DISPLAY {
28             const std::string PROP_ACTIVE = "ACTIVE";
29             const std::string PROP_MODEID = "MODE_ID";
30             const std::string PROP_OUTFENCE = "OUT_FENCE_PTR";
31 
32             class DrmDevice;
33 
34             class DrmCrtc {
35             public:
36                 DrmCrtc(drmModeCrtcPtr c, uint32_t pipe);
~DrmCrtc()37                 virtual ~DrmCrtc() {};
38                 int32_t BindToDisplay(uint32_t id);
39                 void UnBindDisplay(uint32_t id);
40                 bool CanBind();
GetId() const41                 uint32_t GetId() const
42                 {
43                     return mId;
44                 }
GetModePropId() const45                 uint32_t GetModePropId() const
46                 {
47                     return mModePropId;
48                 }
GetOutFencePropId() const49                 uint32_t GetOutFencePropId() const
50                 {
51                     return mOutFencePropId;
52                 }
GetActivePropId() const53                 uint32_t GetActivePropId() const
54                 {
55                     return mActivePropId;
56                 }
GetPipe() const57                 uint32_t GetPipe() const
58                 {
59                     return mPipe;
60                 }
61                 int32_t Init(DrmDevice &drmDevice);
62                 int32_t SetActivieMode(int32_t id);
GetActiveModeId() const63                 int32_t GetActiveModeId() const
64                 {
65                     return mActiveModeId;
66                 }
NeedModeSet()67                 bool NeedModeSet()
68                 {
69                     return mNeedModeSet;
70                 }
ClearModeSet()71                 void ClearModeSet()
72                 {
73                     mNeedModeSet = false;
74                 }
GetPlaneMask()75                 uint32_t GetPlaneMask()
76                 {
77                     return mPlaneMask;
78                 }
79 
80             private:
81                 uint32_t mId = 0;
82                 uint32_t mModePropId = 0;
83                 uint32_t mOutFencePropId = 0;
84                 uint32_t mActivePropId = 0;
85                 uint32_t mDisplayId = INVALIDE_DISPLAY_ID;
86                 uint32_t mPipe = 0;
87                 int32_t mActiveModeId = INVALID_MODE_ID;
88                 bool mNeedModeSet = false;
89                 uint32_t mPlaneMask = 0;
90             };
91         } // namespace OHOS
92     }     // namespace HDI
93 } // namespace DISPLAY
94 
95 #endif // DRM_CRTC_H