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