1 /* 2 * Copyright (c) 2023 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_1_DISPLAY_COMPOSER_HDI_IMPL_H 17 #define OHOS_HDI_DISPLAY_V1_1_DISPLAY_COMPOSER_HDI_IMPL_H 18 19 #include "v1_0/hdi_impl/display_composer_hdi_impl.h" 20 #include "v1_1/display_command/display_cmd_requester.h" 21 #include "v1_1/display_composer_type.h" 22 #include "v1_1/idisplay_composer.h" 23 #include "v1_1/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_1 { 36 37 template <typename Interface, typename CompHdi, typename CmdReq> 38 class DisplayComposerHdiImpl : public V1_0::DisplayComposerHdiImpl<Interface, CompHdi, CmdReq>, 39 public ISeamlessChangeCallback, public IModeCallback, public IRefreshCallback { 40 public: Create(bool needSMQ)41 static IDisplayComposerInterface* Create(bool needSMQ) 42 { 43 sptr<CompHdi> hdi; 44 std::shared_ptr<CmdReq> req = nullptr; 45 46 while ((hdi = CompHdi::Get()) == nullptr) { 47 // Waiting for display composer service ready 48 usleep(WAIT_TIME_INTERVAL); 49 } 50 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_0(hdi, req), 63 hdi_v1_1_(hdi), 64 seamlessChangeCb_(nullptr), 65 refreshCb_(nullptr), 66 seamlessChangeCbData_(nullptr), 67 refreshCbData_(nullptr), 68 modeCb_(nullptr) {} 69 ~DisplayComposerHdiImpl()70 virtual ~DisplayComposerHdiImpl() {} 71 OnSeamlessChange(uint32_t outputId)72 virtual int32_t OnSeamlessChange(uint32_t outputId) override 73 { 74 HDF_LOGD("OnSeamlessChange(%{public}u)", outputId); 75 int32_t ret = HDF_SUCCESS; 76 if (seamlessChangeCb_) { 77 seamlessChangeCb_(outputId, seamlessChangeCbData_); 78 } else { 79 HDF_LOGE("seamless change callback is nullptr"); 80 ret = HDF_FAILURE; 81 } 82 return ret; 83 } 84 RegSeamlessChangeCallback(SeamlessChangeCallback cb,void * data)85 virtual int32_t RegSeamlessChangeCallback(SeamlessChangeCallback cb, void *data) override 86 { 87 seamlessChangeCb_ = cb; 88 seamlessChangeCbData_ = data; 89 COMPOSER_CHECK_NULLPTR(hdi_v1_1_); 90 return ToDispErrCode(hdi_v1_1_->RegSeamlessChangeCallback(this)); 91 } 92 GetDisplaySupportedModesExt(unsigned int devId,std::vector<DisplayModeInfoExt> & modes)93 virtual int32_t GetDisplaySupportedModesExt(unsigned int devId, std::vector<DisplayModeInfoExt> &modes) override 94 { 95 COMPOSER_CHECK_NULLPTR(hdi_v1_1_); 96 return ToDispErrCode(hdi_v1_1_->GetDisplaySupportedModesExt(devId, modes)); 97 } 98 OnMode(uint32_t modeId,uint64_t vBlankPeriod)99 virtual int32_t OnMode(uint32_t modeId, uint64_t vBlankPeriod) override 100 { 101 HDF_LOGD("OnMode(%{public}u, %{public}" PRIu64 ")", modeId, vBlankPeriod); 102 int32_t ret = HDF_SUCCESS; 103 if (modeCb_) { 104 modeCb_(modeId, vBlankPeriod, nullptr); 105 } else { 106 HDF_LOGE("mode callback is nullptr"); 107 ret = HDF_FAILURE; 108 } 109 return ret; 110 } 111 SetDisplayModeAsync(uint32_t devId,uint32_t modeId,ModeCallback cb)112 virtual int32_t SetDisplayModeAsync(uint32_t devId, uint32_t modeId, ModeCallback cb) override 113 { 114 modeCb_ = cb; 115 COMPOSER_CHECK_NULLPTR(hdi_v1_1_); 116 return ToDispErrCode(hdi_v1_1_->SetDisplayModeAsync(devId, modeId, this)); 117 } 118 GetDisplayVBlankPeriod(uint32_t devId,uint64_t & period)119 virtual int32_t GetDisplayVBlankPeriod(uint32_t devId, uint64_t &period) override 120 { 121 COMPOSER_CHECK_NULLPTR(hdi_v1_1_); 122 return ToDispErrCode(hdi_v1_1_->GetDisplayVBlankPeriod(devId, period)); 123 } 124 SetLayerPerFrameParameter(uint32_t devId,uint32_t layerId,const std::string & key,const std::vector<int8_t> & value)125 virtual int32_t SetLayerPerFrameParameter(uint32_t devId, uint32_t layerId, const std::string& key, 126 const std::vector<int8_t>& value) override 127 { 128 return ToDispErrCode(hdi_v1_1_->SetLayerPerFrameParameter(devId, layerId, key, value)); 129 } 130 GetSupportedLayerPerFrameParameterKey(std::vector<std::string> & keys)131 virtual int32_t GetSupportedLayerPerFrameParameterKey(std::vector<std::string>& keys) override 132 { 133 return ToDispErrCode(hdi_v1_1_->GetSupportedLayerPerFrameParameterKey(keys)); 134 } 135 SetDisplayOverlayResolution(uint32_t devId,uint32_t width,uint32_t height)136 virtual int32_t SetDisplayOverlayResolution(uint32_t devId, uint32_t width, uint32_t height) override 137 { 138 return ToDispErrCode(hdi_v1_1_->SetDisplayOverlayResolution(devId, width, height)); 139 } 140 OnRefresh(uint32_t devId)141 virtual int32_t OnRefresh(uint32_t devId) override 142 { 143 HDF_LOGD("OnRefresh(%{public}u)", devId); 144 int32_t ret = HDF_SUCCESS; 145 if (refreshCb_ != nullptr) { 146 refreshCb_(devId, refreshCbData_); 147 } else { 148 HDF_LOGE("error: refresh callback fn is nullptr"); 149 ret = HDF_FAILURE; 150 } 151 return ret; 152 } 153 RegRefreshCallback(RefreshCallback cb,void * data)154 virtual int32_t RegRefreshCallback(RefreshCallback cb, void *data) override 155 { 156 refreshCb_ = cb; 157 refreshCbData_ = data; 158 COMPOSER_CHECK_NULLPTR(hdi_v1_1_); 159 return ToDispErrCode(hdi_v1_1_->RegRefreshCallback(this)); 160 } 161 GetDisplaySupportedColorGamuts(uint32_t devId,std::vector<ColorGamut> & gamuts)162 virtual int32_t GetDisplaySupportedColorGamuts(uint32_t devId, std::vector<ColorGamut>& gamuts) override 163 { 164 COMPOSER_CHECK_NULLPTR(hdi_v1_1_); 165 return ToDispErrCode(hdi_v1_1_->GetDisplaySupportedColorGamuts(devId, gamuts)); 166 } 167 GetHDRCapabilityInfos(uint32_t devId,HDRCapability & info)168 virtual int32_t GetHDRCapabilityInfos(uint32_t devId, HDRCapability& info) override 169 { 170 COMPOSER_CHECK_NULLPTR(hdi_v1_1_); 171 return ToDispErrCode(hdi_v1_1_->GetHDRCapabilityInfos(devId, info)); 172 } 173 174 private: 175 using BaseType1_0 = V1_0::DisplayComposerHdiImpl<Interface, CompHdi, CmdReq>; 176 using BaseType1_0::WAIT_TIME_INTERVAL; 177 using BaseType1_0::ToDispErrCode; 178 sptr<CompHdi> hdi_v1_1_; 179 SeamlessChangeCallback seamlessChangeCb_; 180 RefreshCallback refreshCb_; 181 void *seamlessChangeCbData_; 182 void *refreshCbData_; 183 ModeCallback modeCb_; 184 }; 185 using HdiDisplayComposer = DisplayComposerHdiImpl<IDisplayComposerInterface, IDisplayComposer, HdiDisplayCmdRequester>; 186 } // namespace V1_1 187 } // namespace Composer 188 } // namespace Display 189 } // namespace HDI 190 } // namespace OHOS 191 #endif // OHOS_HDI_DISPLAY_V1_1_DISPLAY_COMPOSER_HDI_IMPL_H 192