• 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 #ifndef DRM_CONNECTOR_H
17 #define DRM_CONNECTOR_H
18 #include <string>
19 #include <unordered_map>
20 #include <vector>
21 #include <xf86drm.h>
22 #include <xf86drmMode.h>
23 #include "drm_encoder.h"
24 #include "hdi_device_common.h"
25 #include "hdi_fd.h"
26 
27 namespace OHOS {
28 namespace HDI {
29 namespace DISPLAY {
30 const std::string PROP_DPMS = "DPMS";
31 const std::string PROP_CRTCID = "CRTC_ID";
32 const std::string PROP_BRIGHTNESS = "brightness";
33 class DrmDevice;
34 class DrmModeBlock;
35 
36 class DrmMode {
37 public:
DrmMode()38     DrmMode() {};
DrmMode(drmModeModeInfo & modeInfo,uint32_t id)39     DrmMode(drmModeModeInfo &modeInfo, uint32_t id) : mModeInfo(modeInfo), mId(id) {}
~DrmMode()40     virtual ~DrmMode() {};
GetModeInfoPtr()41     drmModeModeInfoPtr GetModeInfoPtr()
42     {
43         return &mModeInfo;
44     }
45     void ConvertToHdiMode(DisplayModeInfo &hdiMode);
46 
47 private:
48     drmModeModeInfo mModeInfo = { 0 };
49     int32_t mId = -1;
50 };
51 
52 class DrmModeBlock {
53 public:
54     explicit DrmModeBlock(DrmMode &mode);
55     virtual ~DrmModeBlock();
56     int32_t Init(DrmMode &mode);
GetBlockId()57     uint32_t GetBlockId() const
58     {
59         return mBlockId;
60     }
61 
62 private:
63     uint32_t mBlockId = 0xFFFFFFFF;
64 };
65 
66 class DrmConnector {
67 public:
68     DrmConnector(drmModeConnector c, FdPtr &fd);
~DrmConnector()69     virtual ~DrmConnector() {};
GetId()70     uint32_t GetId() const
71     {
72         return mId;
73     }
GetEncoderId()74     uint32_t GetEncoderId() const
75     {
76         return mEncoderId;
77     }
78     void GetDisplayCap(DisplayCapability &cap);
79     int32_t Init(DrmDevice &drmDevice);
80     int32_t PickIdleCrtcId(IdMapPtr<DrmEncoder> &encoders, IdMapPtr<DrmCrtc> &crtcs, uint32_t &crtcId);
81     int32_t GetDisplaySupportedModes(uint32_t *num, DisplayModeInfo *modes);
GetPreferenceId()82     int32_t GetPreferenceId() const
83     {
84         return mPreferenceId;
85     }
GetPropCrtcId()86     uint32_t GetPropCrtcId() const
87     {
88         return mPropCrtcId;
89     }
90     int32_t TryPickEncoder(IdMapPtr<DrmEncoder> &encoders, uint32_t encoderId, IdMapPtr<DrmCrtc> &crtcs,
91         uint32_t &crtcId);
92     // update modes will reset the preference mode id and active mode id
93     int32_t UpdateModes();
94     std::unique_ptr<DrmModeBlock> GetModeBlockFromId(int32_t id);
95     int32_t GetModeFromId(int32_t id, DrmMode &mode);
GetDpmsState()96     uint64_t GetDpmsState() const
97     {
98         return mDpmsState;
99     }
100     int32_t SetDpmsState(uint64_t dmps);
101     bool IsConnected();
102 
103     int32_t GetBrightness(uint32_t& level);
104     int32_t SetBrightness(uint32_t level);
105 
106 private:
107     static void ConvertTypeToName(uint32_t type, std::string &name);
108     static void ConvertToHdiType(uint32_t type, InterfaceType &hdiType);
109 
110     void InitModes(drmModeConnector c);
111     uint32_t mId;
112     InterfaceType mType;
113     uint32_t mPhyWidth;
114     uint32_t mPhyHeight;
115     uint32_t mSupportLayers = 0;
116     uint32_t mVirtualDispCount = 0;
117     bool mSupportWriteBack = false;
118     uint32_t mPropertyCount = 0;
119     uint32_t mEncoderId;
120     std::vector<uint32_t> mPossibleEncoders;
121     std::string mName;
122     drmModeConnection mConnectState;
123     uint32_t mPropDpmsId = 0xFFFFFFFF;
124     uint64_t mDpmsState = 0;
125     uint32_t mPropCrtcId = 0xFFFFFFFF;
126     uint32_t mPropBrightnessId = 0xFFFFFFFF;
127     uint32_t mBrightnessLevel = 0;
128     std::unordered_map<int32_t, DrmMode> mModes;
129     int32_t mPreferenceId = -1;
130 
131     FdPtr mDrmFdPtr;
132 };
133 } // namespace OHOS
134 } // namespace HDI
135 } // namespace DISPLAY
136 #endif // DRM_CONNECTOR_H
137