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 HDI_DRM_COMPOSITION_H 17 #define HDI_DRM_COMPOSITION_H 18 #include <vector> 19 #include <memory> 20 #include <xf86drm.h> 21 #include <xf86drmMode.h> 22 #include "drm_device.h" 23 #include "hdi_composer.h" 24 #include "hdi_device_common.h" 25 #include "hdi_drm_layer.h" 26 27 namespace OHOS { 28 namespace HDI { 29 namespace DISPLAY { 30 class AtomicReqPtr { 31 public: AtomicReqPtr(drmModeAtomicReqPtr ptr)32 explicit AtomicReqPtr(drmModeAtomicReqPtr ptr) : mPtr(ptr) {} ~AtomicReqPtr()33 virtual ~AtomicReqPtr() 34 { 35 if (mPtr != nullptr) 36 drmModeAtomicFree(mPtr); 37 } Get()38 drmModeAtomicReqPtr Get() const 39 { 40 return mPtr; 41 } 42 43 private: 44 drmModeAtomicReqPtr mPtr; 45 }; 46 47 class HdiDrmComposition : public HdiComposition { 48 public: 49 HdiDrmComposition(const std::shared_ptr<DrmConnector> &connector, 50 const std::shared_ptr<DrmCrtc> &crtc, 51 const std::shared_ptr<DrmDevice> &drmDevice); ~HdiDrmComposition()52 ~HdiDrmComposition() override {} 53 int32_t Init() override; 54 int32_t SetLayers(std::vector<HdiLayer *> &layers, HdiLayer &clientLayer) override; 55 int32_t Apply(bool modeSet) override; 56 int32_t UpdateMode(std::unique_ptr<DrmModeBlock> &modeBlock); 57 58 private: 59 int32_t ApplyPlane(HdiDrmLayer &layer, HdiLayer &hlayer, DrmPlane &drmPlane, drmModeAtomicReqPtr pset); 60 int32_t SetSrcProperty(DrmPlane &drmPlane, drmModeAtomicReqPtr pset, int32_t bufferW, int32_t bufferH); 61 int32_t SetCrtcProperty(DrmPlane &drmPlane, drmModeAtomicReqPtr pset, int32_t bufferW, int32_t bufferH); 62 int32_t RemoveUnusePlane(drmModeAtomicReqPtr pset); 63 int32_t FindPlaneAndApply(drmModeAtomicReqPtr pset); 64 std::shared_ptr<DrmDevice> mDrmDevice; 65 std::shared_ptr<DrmConnector> mConnector; 66 std::shared_ptr<DrmCrtc> mCrtc; 67 std::vector<std::shared_ptr<DrmPlane>> mPrimPlanes; 68 std::vector<std::shared_ptr<DrmPlane>> mOverlayPlanes; 69 std::vector<std::shared_ptr<DrmPlane>> mPlanes; 70 }; 71 } // OHOS 72 } // HDI 73 } // DISPLAY 74 75 #endif // HDI_DRM_COMPOSITION_H 76