• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021–2022 Beijing OSWare Technology Co., Ltd
3  * This file contains confidential and proprietary information of
4  * OSWare Technology Co., Ltd
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 
19 #ifndef DRM_CONNECTOR_H
20 #define DRM_CONNECTOR_H
21 #include <string>
22 #include <unordered_map>
23 #include <vector>
24 #include <xf86drm.h>
25 #include <xf86drmMode.h>
26 #include "display_type.h"
27 #include "drm_encoder.h"
28 #include "hdi_device_common.h"
29 #include "hdi_fd.h"
30 
31 namespace OHOS {
32 namespace HDI {
33 namespace DISPLAY {
34 const std::string PROP_DPMS = "DPMS";
35 const std::string PROP_CRTCID = "CRTC_ID";
36 const std::string PROP_BRIGHTNESS = "brightness";
37 class DrmDevice;
38 class DrmModeBlock;
39 
40 class DrmMode {
41 public:
DrmMode()42     DrmMode() {}
DrmMode(drmModeModeInfo & modeInfo,uint32_t id)43     DrmMode(drmModeModeInfo &modeInfo, uint32_t id) : mModeInfo(modeInfo), mId(id) {}
~DrmMode()44     virtual ~DrmMode() {}
GetModeInfoPtr()45     drmModeModeInfoPtr GetModeInfoPtr()
46     {
47         return &mModeInfo;
48     }
49     void ConvertToHdiMode(DisplayModeInfo &hdiMode);
50 
51 private:
52     drmModeModeInfo mModeInfo = { 0 };
53     int32_t mId = -1;
54 };
55 
56 class DrmModeBlock {
57 public:
58     explicit DrmModeBlock(DrmMode &mode);
59     virtual ~DrmModeBlock();
60     int32_t Init(DrmMode &mode);
GetBlockId()61     uint32_t GetBlockId() const
62     {
63         return mBlockId;
64     }
65 
66 private:
67     uint32_t mBlockId = DRM_INVALID_ID;
68 };
69 
70 class DrmConnector {
71 public:
72     DrmConnector(drmModeConnector c, FdPtr &fd);
~DrmConnector()73     virtual ~DrmConnector() {}
GetId()74     uint32_t GetId() const
75     {
76         return mId;
77     }
GetEncoderId()78     uint32_t GetEncoderId() const
79     {
80         return mEncoderId;
81     }
82     void GetDisplayCap(DisplayCapability &cap);
83     int32_t Init(DrmDevice &drmDevice);
84     int32_t PickIdleCrtcId(IdMapPtr<DrmEncoder> &encoders, IdMapPtr<DrmCrtc> &crtcs, uint32_t &crtcId);
85     int32_t GetDisplaySupportedModes(uint32_t *num, DisplayModeInfo *modes);
GetPreferenceId()86     int32_t GetPreferenceId() const
87     {
88         return mPreferenceId;
89     }
GetPropCrtcId()90     uint32_t GetPropCrtcId() const
91     {
92         return mPropCrtcId;
93     }
94     int32_t TryPickEncoder(IdMapPtr<DrmEncoder> &encoders, uint32_t encoderId, IdMapPtr<DrmCrtc> &crtcs,
95         uint32_t &crtcId);
96     // update modes will reset the preference mode id and active mode id
97     int32_t UpdateModes();
98     std::unique_ptr<DrmModeBlock> GetModeBlockFromId(int32_t id);
99     int32_t GetModeFromId(int32_t id, DrmMode &mode);
GetDpmsState()100     uint64_t GetDpmsState() const
101     {
102         return mDpmsState;
103     }
104     int32_t SetDpmsState(uint64_t dmps);
105     bool IsConnected();
106 
107     int32_t GetBrightness(uint32_t& level);
108     int32_t SetBrightness(uint32_t level);
109 
110 private:
111     static void ConvertTypeToName(uint32_t type, std::string &name);
112     static void ConvertToHdiType(uint32_t type, InterfaceType &hdiType);
113 
114     void InitModes(drmModeConnector c);
115     uint32_t mId;
116     InterfaceType mType;
117     uint32_t mPhyWidth;
118     uint32_t mPhyHeight;
119     uint32_t mSupportLayers = 0;
120     uint32_t mVirtualDispCount = 0;
121     bool mSupportWriteBack = false;
122     uint32_t mPropertyCount = 0;
123     uint32_t mEncoderId;
124     std::vector<uint32_t> mPossibleEncoders;
125     std::string mName;
126     drmModeConnection mConnectState;
127     uint32_t mPropDpmsId = DRM_INVALID_ID;
128     uint64_t mDpmsState = 0;
129     uint32_t mPropCrtcId = DRM_INVALID_ID;
130     uint32_t mBrightnessLevel = 0;
131     std::unordered_map<int32_t, DrmMode> mModes;
132     int32_t mPreferenceId = INVALID_MODE_ID;
133 
134     FdPtr mDrmFdPtr;
135 };
136 } // namespace OHOS
137 } // namespace HDI
138 } // namespace DISPLAY
139 #endif // DRM_CONNECTOR_H
140