/* * Copyright (c) 2021 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef DRM_DEVICE_H #define DRM_DEVICE_H #include #include #include #include #include "drm_connector.h" #include "drm_crtc.h" #include "drm_encoder.h" #include "drm_plane.h" #include "hdi_device_common.h" #include "hdi_device_interface.h" #include "hdi_display.h" #include "hdi_shared_fd.h" namespace OHOS { namespace HDI { namespace DISPLAY { #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) class DrmPropertyEnum { public: explicit DrmPropertyEnum(drm_mode_property_enum *e) : value(e->value), name(e->name) { } ~DrmPropertyEnum() {}; uint64_t value; std::string name; }; struct DrmProperty { uint32_t propId; uint64_t value; uint32_t type; uint32_t flags; std::string name; std::vector values; std::vector enums; std::vector blob_ids; }; class DrmDevice : public HdiDeviceInterface, std::enable_shared_from_this { public: static std::shared_ptr Create(); static uint32_t ConvertToDrmFormat(PixelFormat fmtIn); static int GetDrmFd(); DrmDevice(); ~DrmDevice() override {} std::vector> GetDrmPlane(uint32_t pipe, uint32_t type); int32_t GetCrtcProperty(const DrmCrtc &crtc, const std::string &name, DrmProperty &prop); int32_t GetConnectorProperty(const DrmConnector &connector, const std::string &name, DrmProperty &prop); int32_t GetPlaneProperty(const DrmPlane &plane, const std::string &name, DrmProperty &prop); int32_t GetProperty(uint32_t objId, uint32_t objType, const std::string &name, DrmProperty &prop); std::shared_ptr GetDrmEncoderFromId(uint32_t id); std::shared_ptr GetDrmConnectorFromId(uint32_t id); std::shared_ptr GetDrmCrtcFromId(uint32_t id); void CreateCrtc(drmModeCrtcPtr c); std::unordered_map> DiscoveryDisplay() override; int32_t Init() override; void DeInit() override; bool HandleHotplug(uint32_t dispId, bool plugIn) override; private: static FdPtr mDrmFd; static std::shared_ptr mInstance; void FindAllCrtc(const drmModeResPtr &drmRes); void FindAllEncoder(const drmModeResPtr &drmRes); void FindAllConnector(const drmModeResPtr &drmRes); void FindAllPlane(); int InitNetLink(); IdMapPtr mDisplays; IdMapPtr mCrtcs; IdMapPtr mEncoders; IdMapPtr mConnectors; std::vector> mPlanes; std::unordered_map dispConnectorIdMaps_; }; } // namespace OHOS } // namespace HDI } // namespace DISPLAY #endif // DRM_DEVICE_H