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(std::shared_ptr<DrmConnector> &connector, std::shared_ptr<DrmCrtc> &crtc, 50 std::shared_ptr<DrmDevice> &drmDevice); ~HdiDrmComposition()51 ~HdiDrmComposition() override {} 52 int32_t Init() override; 53 int32_t SetLayers(std::vector<HdiLayer *> &layers, HdiLayer &clientLayer) override; 54 int32_t Apply(bool modeSet) override; 55 int32_t UpdateMode(std::unique_ptr<DrmModeBlock> &modeBlock, drmModeAtomicReq &pset); 56 57 private: 58 int32_t UpdateVideoRect(HdiDrmLayer &videoLayer, HdiDrmLayer &clientLayer); 59 bool IsAmVideoLayer(HdiLayer &hdiLayer); 60 int32_t ApplyPlane(HdiDrmLayer &layer, DrmPlane &drmPlane, drmModeAtomicReqPtr pset); 61 HdiDrmLayer *mVideoLayer; 62 std::shared_ptr<DrmDevice> mDrmDevice; 63 std::shared_ptr<DrmConnector> mConnector; 64 std::shared_ptr<DrmCrtc> mCrtc; 65 std::vector<std::shared_ptr<DrmPlane>> mPrimPlanes; 66 std::vector<std::shared_ptr<DrmPlane>> mOverlayPlanes; 67 std::vector<std::shared_ptr<DrmPlane>> mPlanes; 68 }; 69 } // OHOS 70 } // HDI 71 } // DISPLAY 72 73 #endif // HDI_DRM_COMPOSITION_H 74