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_DEVICE_H 20 #define DRM_DEVICE_H 21 #include <unordered_map> 22 #include <memory> 23 #include <xf86drm.h> 24 #include <xf86drmMode.h> 25 #include "drm_connector.h" 26 #include "drm_crtc.h" 27 #include "drm_encoder.h" 28 #include "drm_plane.h" 29 #include "hdi_device_common.h" 30 #include "hdi_device_interface.h" 31 #include "hdi_display.h" 32 #include "hdi_fd.h" 33 34 namespace OHOS { 35 namespace HDI { 36 namespace DISPLAY { 37 struct DrmProperty { 38 uint32_t propId; 39 uint64_t value; 40 }; 41 42 class DrmDevice : public HdiDeviceInterface, std::enable_shared_from_this<DrmDevice> { 43 public: 44 static std::shared_ptr<HdiDeviceInterface> Create(); 45 static uint32_t ConvertToDrmFormat(PixelFormat fmtIn); 46 static int GetDrmFd(); 47 DrmDevice(); ~DrmDevice()48 virtual ~DrmDevice() {} 49 50 std::vector<std::shared_ptr<DrmPlane>> GetDrmPlane(uint32_t pipe, uint32_t type); 51 52 int32_t GetCrtcProperty(const DrmCrtc &crtc, const std::string &name, DrmProperty &prop); 53 int32_t GetConnectorProperty(const DrmConnector &connector, const std::string &name, DrmProperty &prop); 54 int32_t GetPlaneProperty(const DrmPlane &plane, const std::string &name, DrmProperty &prop); 55 56 int32_t GetProperty(uint32_t objId, uint32_t objType, const std::string &name, DrmProperty &prop); 57 std::shared_ptr<DrmEncoder> GetDrmEncoderFromId(uint32_t id); 58 std::shared_ptr<DrmConnector> GetDrmConnectorFromId(uint32_t id); 59 std::shared_ptr<DrmCrtc> GetDrmCrtcFromId(uint32_t id); 60 void CreateCrtc(drmModeCrtcPtr c); 61 virtual std::unordered_map<uint32_t, std::shared_ptr<HdiDisplay>> DiscoveryDisplay(); 62 virtual int32_t Init(); 63 virtual void DeInit(); 64 65 private: 66 static FdPtr mDrmFd; 67 static std::shared_ptr<DrmDevice> mInstance; 68 void FindAllCrtc(const drmModeResPtr &drmRes); 69 void FindAllEncoder(const drmModeResPtr &drmRes); 70 void FindAllConnector(const drmModeResPtr &drmRes); 71 void FindAllPlane(); 72 int InitNetLink(); 73 IdMapPtr<HdiDisplay> mDisplays; 74 IdMapPtr<DrmCrtc> mCrtcs; 75 IdMapPtr<DrmEncoder> mEncoders; 76 IdMapPtr<DrmConnector> mConnectors; 77 std::vector<std::shared_ptr<DrmPlane>> mPlanes; 78 }; 79 } // namespace OHOS 80 } // namespace HDI 81 } // namespace DISPLAY 82 83 #endif // DRM_DEVICE_H