1 /* 2 * Copyright (c) 2024 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 OHOS_HDI_DISPLAY_V1_2_DISPLAY_COMPOSER_HDI_IMPL_H 17 #define OHOS_HDI_DISPLAY_V1_2_DISPLAY_COMPOSER_HDI_IMPL_H 18 19 #include "v1_1/hdi_impl/display_composer_hdi_impl.h" 20 #include "v1_2/display_command/display_cmd_requester.h" 21 #include "v1_2/display_composer_type.h" 22 #include "v1_2/idisplay_composer.h" 23 #include "v1_2/include/idisplay_composer_interface.h" 24 #include <cinttypes> 25 26 #undef LOG_TAG 27 #define LOG_TAG "DISP_HDI_COMP" 28 #undef LOG_DOMAIN 29 #define LOG_DOMAIN 0xD002515 30 31 namespace OHOS { 32 namespace HDI { 33 namespace Display { 34 namespace Composer { 35 namespace V1_2 { 36 37 template <typename Interface, typename CompHdi, typename CmdReq> 38 class DisplayComposerHdiImpl : public V1_1::DisplayComposerHdiImpl<Interface, CompHdi, CmdReq>, 39 public IVBlankIdleCallback { 40 public: Create(bool needSMQ)41 static IDisplayComposerInterface* Create(bool needSMQ) 42 { 43 sptr<CompHdi> hdi; 44 std::shared_ptr<CmdReq> req = nullptr; 45 HDF_LOGI("%{public}s: hdi v1_2 start", __func__); 46 while ((hdi = CompHdi::Get()) == nullptr) { 47 // Waiting for display composer service ready 48 usleep(WAIT_TIME_INTERVAL); 49 } 50 HDF_LOGI("%{public}s: hdi v1_2 end", __func__); 51 if (needSMQ) { 52 req = CmdReq::Create(hdi); 53 if (req == nullptr) { 54 HDF_LOGE("%{public}s: Create DisplayCmdRequester failed %{public}d", __func__, __LINE__); 55 return nullptr; 56 } 57 } 58 return new DisplayComposerHdiImpl(hdi, req); 59 } 60 DisplayComposerHdiImpl(sptr<CompHdi> hdi,std::shared_ptr<CmdReq> req)61 DisplayComposerHdiImpl(sptr<CompHdi> hdi, std::shared_ptr<CmdReq> req) 62 : BaseType1_1(hdi, req), 63 req_v1_2_(req), 64 hdi_v1_2_(hdi), 65 isSupportSkipValidate_(0), 66 VBlankIdleCb_(nullptr), 67 VBlankIdleCbData_(nullptr) {} 68 ~DisplayComposerHdiImpl()69 virtual ~DisplayComposerHdiImpl() {} 70 CommitAndGetReleaseFence(uint32_t devId,int32_t & fence,int32_t & skipState,bool & needFlush,std::vector<uint32_t> & layers,std::vector<int32_t> & fences,bool isValidated)71 virtual int32_t CommitAndGetReleaseFence(uint32_t devId, int32_t& fence, int32_t& skipState, bool& needFlush, 72 std::vector<uint32_t>& layers, std::vector<int32_t>& fences, bool isValidated) override 73 { 74 COMPOSER_CHECK_NULLPTR_RETURN(req_v1_2_); 75 bool isSupportSkipValidate = (isSupportSkipValidate_ == 1) ? 1 : 0; 76 return ToDispErrCode(req_v1_2_->CommitAndGetReleaseFence(devId, fence, 77 isSupportSkipValidate, skipState, needFlush, layers, fences, isValidated)); 78 } 79 GetDisplayProperty(uint32_t devId,uint32_t id,uint64_t & value)80 virtual int32_t GetDisplayProperty(uint32_t devId, uint32_t id, uint64_t& value) override 81 { 82 COMPOSER_CHECK_NULLPTR_RETURN(hdi_v1_2_); 83 value = 0; 84 int32_t ret = ToDispErrCode(hdi_v1_2_->GetDisplayProperty(devId, id, value)); 85 if (ret == DISPLAY_SUCCESS) { 86 isSupportSkipValidate_ = value; 87 } 88 89 return ret; 90 } 91 RegDisplayVBlankIdleCallback(VBlankIdleCallback cb,void * data)92 virtual int32_t RegDisplayVBlankIdleCallback(VBlankIdleCallback cb, void *data) override 93 { 94 VBlankIdleCb_ = cb; 95 VBlankIdleCbData_ = data; 96 COMPOSER_CHECK_NULLPTR_RETURN(hdi_v1_2_); 97 return ToDispErrCode(hdi_v1_2_->RegDisplayVBlankIdleCallback(this)); 98 } 99 SetDisplayConstraint(uint32_t devId,uint64_t frameID,uint64_t ns,uint32_t type)100 virtual int32_t SetDisplayConstraint(uint32_t devId, uint64_t frameID, uint64_t ns, uint32_t type) override 101 { 102 COMPOSER_CHECK_NULLPTR_RETURN(req_v1_2_); 103 return ToDispErrCode(req_v1_2_->SetDisplayConstraint(devId, frameID, ns, type)); 104 } 105 OnVBlankIdleCallback(uint32_t devId,uint64_t ns)106 virtual int32_t OnVBlankIdleCallback(uint32_t devId, uint64_t ns) override 107 { 108 int32_t ret = HDF_SUCCESS; 109 if (VBlankIdleCb_ != nullptr) { 110 VBlankIdleCb_(devId, ns, VBlankIdleCbData_); 111 } else { 112 HDF_LOGE("error: VBlankIdle is nullptr"); 113 ret = HDF_FAILURE; 114 } 115 return ret; 116 } ClearClientBuffer(uint32_t devId)117 virtual int32_t ClearClientBuffer(uint32_t devId) override 118 { 119 COMPOSER_CHECK_NULLPTR_RETURN(req_v1_2_); 120 return ToDispErrCode(hdi_v1_2_->ClearClientBuffer(devId)); 121 } 122 ClearLayerBuffer(uint32_t devId,uint32_t layerId)123 virtual int32_t ClearLayerBuffer(uint32_t devId, uint32_t layerId) override 124 { 125 COMPOSER_CHECK_NULLPTR_RETURN(req_v1_2_); 126 return ToDispErrCode(hdi_v1_2_->ClearLayerBuffer(devId, layerId)); 127 } 128 SetHardwareCursorPosition(uint32_t devId,int32_t x,int32_t y)129 virtual int32_t SetHardwareCursorPosition(uint32_t devId, int32_t x, int32_t y) override 130 { 131 COMPOSER_CHECK_NULLPTR_RETURN(hdi_v1_2_); 132 int32_t ret = ToDispErrCode(hdi_v1_2_->SetHardwareCursorPosition(devId, x, y)); 133 return ret; 134 } 135 EnableHardwareCursorStats(uint32_t devId,bool enable)136 virtual int32_t EnableHardwareCursorStats(uint32_t devId, bool enable) override 137 { 138 COMPOSER_CHECK_NULLPTR_RETURN(hdi_v1_2_); 139 int32_t ret = ToDispErrCode(hdi_v1_2_->EnableHardwareCursorStats(devId, enable)); 140 return ret; 141 } 142 GetHardwareCursorStats(uint32_t devId,uint32_t & frameCount,uint32_t & vsyncCount)143 virtual int32_t GetHardwareCursorStats(uint32_t devId, uint32_t& frameCount, uint32_t& vsyncCount) override 144 { 145 COMPOSER_CHECK_NULLPTR_RETURN(hdi_v1_2_); 146 int32_t ret = ToDispErrCode(hdi_v1_2_->GetHardwareCursorStats(devId, frameCount, vsyncCount)); 147 return ret; 148 } 149 150 protected: 151 using BaseType1_1 = V1_1::DisplayComposerHdiImpl<Interface, CompHdi, CmdReq>; 152 using BaseType1_1::WAIT_TIME_INTERVAL; 153 using BaseType1_1::ToDispErrCode; 154 std::shared_ptr<CmdReq> req_v1_2_; 155 sptr<CompHdi> hdi_v1_2_; 156 uint64_t isSupportSkipValidate_; 157 private: 158 VBlankIdleCallback VBlankIdleCb_; 159 void *VBlankIdleCbData_; 160 }; 161 using HdiDisplayComposer = DisplayComposerHdiImpl<IDisplayComposerInterface, IDisplayComposer, HdiDisplayCmdRequester>; 162 } // namespace V1_2 163 } // namespace Composer 164 } // namespace Display 165 } // namespace HDI 166 } // namespace OHOS 167 #endif // OHOS_HDI_DISPLAY_V1_2_DISPLAY_COMPOSER_HDI_IMPL_H 168