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_0_DISPLAY_COMPOSER_HDI_IMPL_H 17 #define OHOS_HDI_DISPLAY_V1_0_DISPLAY_COMPOSER_HDI_IMPL_H 18 19 #include <unistd.h> 20 #include "hdf_trace.h" 21 #include "hilog/log.h" 22 #include "iproxy_broker.h" 23 #include "iremote_object.h" 24 #include "v1_0/display_command/display_cmd_requester.h" 25 #include "v1_0/display_composer_type.h" 26 #include "v1_0/idisplay_composer.h" 27 #include "v1_0/include/idisplay_composer_interface.h" 28 29 #undef LOG_TAG 30 #define LOG_TAG "DISP_HDI_COMP" 31 #undef LOG_DOMAIN 32 #define LOG_DOMAIN 0xD002515 33 34 namespace OHOS { 35 namespace HDI { 36 namespace Display { 37 namespace Composer { 38 namespace V1_0 { 39 using namespace OHOS::HDI::Display::Composer::V1_0; 40 41 #define DISPLAY_TRACE HdfTrace trace(__func__, "HDI:DISP:") 42 43 #define COMPOSER_CHECK_NULLPTR_RETURN(ptr) \ 44 if ((ptr) == nullptr) { \ 45 HDF_LOGE("%{public}d@%{public}s nullptr error", __LINE__, __func__); \ 46 return DISPLAY_NULL_PTR; \ 47 } 48 49 template <typename Interface, typename CompHdi, typename CmdReq> 50 class DisplayComposerHdiImpl : public Interface, public IHotPlugCallback, public IVBlankCallback { 51 public: Create(bool needSMQ)52 static IDisplayComposerInterface* Create(bool needSMQ) 53 { 54 sptr<CompHdi> hdi; 55 std::shared_ptr<CmdReq> req = nullptr; 56 HDF_LOGI("%{public}s: hdi V1_0 start", __func__); 57 while ((hdi = CompHdi::Get()) == nullptr) { 58 // Waiting for display composer service ready 59 usleep(WAIT_TIME_INTERVAL); 60 } 61 HDF_LOGI("%{public}s: hdi V1_0 end", __func__); 62 if (needSMQ) { 63 req = CmdReq::Create(hdi); 64 if (req == nullptr) { 65 HDF_LOGE("%{public}s: Create DisplayCmdRequester failed %{public}d", __func__, __LINE__); 66 return nullptr; 67 } 68 } 69 return new DisplayComposerHdiImpl(hdi, req); 70 } 71 DisplayComposerHdiImpl(sptr<CompHdi> hdi,std::shared_ptr<CmdReq> req)72 DisplayComposerHdiImpl(sptr<CompHdi> hdi, std::shared_ptr<CmdReq> req) 73 : hdi_(hdi), 74 req_(req), 75 hotPlugCb_(nullptr), 76 vBlankCb_(nullptr), 77 hotPlugCbData_(nullptr), 78 vBlankCbData_(nullptr), 79 recipient_(nullptr) { 80 vsyncEnableCount_.clear(); 81 } 82 ~DisplayComposerHdiImpl()83 virtual ~DisplayComposerHdiImpl() 84 { 85 if (recipient_ != nullptr) { 86 sptr<IRemoteObject> remoteObj = OHOS::HDI::hdi_objcast<CompHdi>(hdi_); 87 remoteObj->RemoveDeathRecipient(recipient_); 88 recipient_ = nullptr; 89 } 90 } 91 AddDeathRecipient(const sptr<IRemoteObject::DeathRecipient> & recipient)92 virtual bool AddDeathRecipient(const sptr<IRemoteObject::DeathRecipient>& recipient) override 93 { 94 sptr<IRemoteObject> remoteObj = OHOS::HDI::hdi_objcast<CompHdi>(hdi_); 95 if (recipient_ != nullptr) { 96 HDF_LOGI("%{public}s: the existing recipient is removed, and add the new. %{public}d", 97 __func__, __LINE__); 98 remoteObj->RemoveDeathRecipient(recipient_); 99 } 100 bool ret = remoteObj->AddDeathRecipient(recipient); 101 if (ret) { 102 recipient_ = recipient; 103 } else { 104 recipient_ = nullptr; 105 HDF_LOGE("%{public}s: AddDeathRecipient failed %{public}d", __func__, __LINE__); 106 } 107 return ret; 108 } 109 RemoveDeathRecipient()110 virtual bool RemoveDeathRecipient() override 111 { 112 if (recipient_ != nullptr) { 113 sptr<IRemoteObject> remoteObj = OHOS::HDI::hdi_objcast<CompHdi>(hdi_); 114 remoteObj->RemoveDeathRecipient(recipient_); 115 recipient_ = nullptr; 116 } 117 return true; 118 } 119 120 // device func RegHotPlugCallback(HotPlugCallback cb,void * data)121 virtual int32_t RegHotPlugCallback(HotPlugCallback cb, void *data) override 122 { 123 hotPlugCb_ = cb; 124 hotPlugCbData_ = data; 125 COMPOSER_CHECK_NULLPTR_RETURN(hdi_); 126 return ToDispErrCode(hdi_->RegHotPlugCallback(this)); 127 } 128 SetClientBufferCacheCount(uint32_t devId,uint32_t cacheCount)129 virtual int32_t SetClientBufferCacheCount(uint32_t devId, uint32_t cacheCount) override 130 { 131 COMPOSER_CHECK_NULLPTR_RETURN(hdi_); 132 return ToDispErrCode(hdi_->SetClientBufferCacheCount(devId, cacheCount)); 133 } 134 GetDisplayCapability(uint32_t devId,DisplayCapability & info)135 virtual int32_t GetDisplayCapability(uint32_t devId, DisplayCapability& info) override 136 { 137 COMPOSER_CHECK_NULLPTR_RETURN(hdi_); 138 return ToDispErrCode(hdi_->GetDisplayCapability(devId, info)); 139 } 140 GetDisplaySupportedModes(uint32_t devId,std::vector<DisplayModeInfo> & modes)141 virtual int32_t GetDisplaySupportedModes(uint32_t devId, std::vector<DisplayModeInfo>& modes) override 142 { 143 COMPOSER_CHECK_NULLPTR_RETURN(hdi_); 144 return ToDispErrCode(hdi_->GetDisplaySupportedModes(devId, modes)); 145 } 146 GetDisplayMode(uint32_t devId,uint32_t & modeId)147 virtual int32_t GetDisplayMode(uint32_t devId, uint32_t& modeId) override 148 { 149 COMPOSER_CHECK_NULLPTR_RETURN(hdi_); 150 return ToDispErrCode(hdi_->GetDisplayMode(devId, modeId)); 151 } 152 SetDisplayMode(uint32_t devId,uint32_t modeId)153 virtual int32_t SetDisplayMode(uint32_t devId, uint32_t modeId) override 154 { 155 COMPOSER_CHECK_NULLPTR_RETURN(hdi_); 156 return ToDispErrCode(hdi_->SetDisplayMode(devId, modeId)); 157 } 158 GetDisplayPowerStatus(uint32_t devId,DispPowerStatus & status)159 virtual int32_t GetDisplayPowerStatus(uint32_t devId, DispPowerStatus& status) override 160 { 161 COMPOSER_CHECK_NULLPTR_RETURN(hdi_); 162 return ToDispErrCode(hdi_->GetDisplayPowerStatus(devId, status)); 163 } 164 SetDisplayPowerStatus(uint32_t devId,DispPowerStatus status)165 virtual int32_t SetDisplayPowerStatus(uint32_t devId, DispPowerStatus status) override 166 { 167 COMPOSER_CHECK_NULLPTR_RETURN(hdi_); 168 int32_t ret = hdi_->SetDisplayPowerStatus(devId, status); 169 HDF_LOGI("devId: %{public}u, status: %{public}u", devId, status); 170 return ToDispErrCode(ret); 171 } 172 GetDisplayBacklight(uint32_t devId,uint32_t & level)173 virtual int32_t GetDisplayBacklight(uint32_t devId, uint32_t& level) override 174 { 175 COMPOSER_CHECK_NULLPTR_RETURN(hdi_); 176 return ToDispErrCode(hdi_->GetDisplayBacklight(devId, level)); 177 } 178 SetDisplayBacklight(uint32_t devId,uint32_t level)179 virtual int32_t SetDisplayBacklight(uint32_t devId, uint32_t level) override 180 { 181 COMPOSER_CHECK_NULLPTR_RETURN(hdi_); 182 return ToDispErrCode(hdi_->SetDisplayBacklight(devId, level)); 183 } 184 GetDisplayProperty(uint32_t devId,uint32_t id,uint64_t & value)185 virtual int32_t GetDisplayProperty(uint32_t devId, uint32_t id, uint64_t& value) override 186 { 187 COMPOSER_CHECK_NULLPTR_RETURN(hdi_); 188 return ToDispErrCode(hdi_->GetDisplayProperty(devId, id, value)); 189 } 190 GetDisplayCompChange(uint32_t devId,std::vector<uint32_t> & layers,std::vector<int32_t> & types)191 virtual int32_t GetDisplayCompChange( 192 uint32_t devId, std::vector<uint32_t>& layers, std::vector<int32_t>& types) override 193 { 194 COMPOSER_CHECK_NULLPTR_RETURN(req_); 195 return ToDispErrCode(req_->GetDisplayCompChange(devId, layers, types)); 196 } 197 SetDisplayClientCrop(uint32_t devId,const IRect & rect)198 virtual int32_t SetDisplayClientCrop(uint32_t devId, const IRect& rect) override 199 { 200 COMPOSER_CHECK_NULLPTR_RETURN(hdi_); 201 return ToDispErrCode(hdi_->SetDisplayClientCrop(devId, rect)); 202 } 203 SetDisplayClientBuffer(uint32_t devId,const BufferHandle * buffer,uint32_t seqNo,int32_t fence)204 virtual int32_t SetDisplayClientBuffer(uint32_t devId, const BufferHandle* buffer, uint32_t seqNo, 205 int32_t fence) override 206 { 207 COMPOSER_CHECK_NULLPTR_RETURN(req_); 208 return ToDispErrCode(req_->SetDisplayClientBuffer(devId, buffer, seqNo, fence)); 209 } 210 SetDisplayClientDamage(uint32_t devId,std::vector<IRect> & rects)211 virtual int32_t SetDisplayClientDamage(uint32_t devId, std::vector<IRect>& rects) override 212 { 213 COMPOSER_CHECK_NULLPTR_RETURN(req_); 214 return ToDispErrCode(req_->SetDisplayClientDamage(devId, rects)); 215 } 216 SetDisplayVsyncEnabled(uint32_t devId,bool enabled)217 virtual int32_t SetDisplayVsyncEnabled(uint32_t devId, bool enabled) override 218 { 219 COMPOSER_CHECK_NULLPTR_RETURN(hdi_); 220 221 /* Already enabled, return success */ 222 if (enabled && vsyncEnableCount_[devId] > 0) { 223 HDF_LOGD("%{public}s: Count[%{public}u] = %{public}u, Skip", __func__, devId, vsyncEnableCount_[devId]); 224 ++vsyncEnableCount_[devId]; 225 return DISPLAY_SUCCESS; 226 } 227 228 int32_t ret = ToDispErrCode(hdi_->SetDisplayVsyncEnabled(devId, enabled)); 229 if (ret != DISPLAY_SUCCESS) { 230 return ret; 231 } 232 233 vsyncEnableCount_[devId] = enabled ? 1 : 0; 234 return ret; 235 } 236 RegDisplayVBlankCallback(uint32_t devId,VBlankCallback cb,void * data)237 virtual int32_t RegDisplayVBlankCallback(uint32_t devId, VBlankCallback cb, void *data) override 238 { 239 vBlankCb_ = cb; 240 vBlankCbData_ = data; 241 COMPOSER_CHECK_NULLPTR_RETURN(hdi_); 242 return ToDispErrCode(hdi_->RegDisplayVBlankCallback(devId, this)); 243 } 244 GetDisplayReleaseFence(uint32_t devId,std::vector<uint32_t> & layers,std::vector<int32_t> & fences)245 virtual int32_t GetDisplayReleaseFence( 246 uint32_t devId, std::vector<uint32_t>& layers, std::vector<int32_t>& fences) override 247 { 248 std::vector<sptr<HdifdParcelable>> hdiFences; 249 COMPOSER_CHECK_NULLPTR_RETURN(hdi_); 250 int32_t ret = ToDispErrCode(hdi_->GetDisplayReleaseFence(devId, layers, hdiFences)); 251 if (ret == DISPLAY_SUCCESS) { 252 for (uint32_t i = 0; i < hdiFences.size(); i++) { 253 if (hdiFences[i] == nullptr) { 254 HDF_LOGE("%{public}s: GetReleaseFence contains nullptr", __func__); 255 continue; 256 } 257 fences.push_back(hdiFences[i]->Move()); 258 } 259 } 260 return ret; 261 } 262 CreateVirtualDisplay(uint32_t width,uint32_t height,int32_t & format,uint32_t & devId)263 virtual int32_t CreateVirtualDisplay(uint32_t width, uint32_t height, int32_t& format, uint32_t& devId) override 264 { 265 COMPOSER_CHECK_NULLPTR_RETURN(hdi_); 266 return ToDispErrCode(hdi_->CreateVirtualDisplay(width, height, format, devId)); 267 } 268 DestroyVirtualDisplay(uint32_t devId)269 virtual int32_t DestroyVirtualDisplay(uint32_t devId) override 270 { 271 COMPOSER_CHECK_NULLPTR_RETURN(hdi_); 272 return ToDispErrCode(hdi_->DestroyVirtualDisplay(devId)); 273 } 274 SetVirtualDisplayBuffer(uint32_t devId,const BufferHandle & buffer,const int32_t fence)275 virtual int32_t SetVirtualDisplayBuffer(uint32_t devId, const BufferHandle& buffer, const int32_t fence) override 276 { 277 int32_t ret = DISPLAY_SUCCESS; 278 279 sptr<NativeBuffer> hdiBuffer = new NativeBuffer(); 280 if (hdiBuffer == nullptr) { 281 ret = DISPLAY_FAILURE; 282 } else { 283 hdiBuffer->SetBufferHandle(const_cast<BufferHandle*>(&buffer)); 284 sptr<HdifdParcelable> hdiFence(new HdifdParcelable); 285 hdiFence->Init(fence); 286 ret = ToDispErrCode(hdi_->SetVirtualDisplayBuffer(devId, hdiBuffer, hdiFence)); 287 } 288 289 return ret; 290 } 291 SetDisplayProperty(uint32_t devId,uint32_t id,uint64_t value)292 virtual int32_t SetDisplayProperty(uint32_t devId, uint32_t id, uint64_t value) override 293 { 294 COMPOSER_CHECK_NULLPTR_RETURN(hdi_); 295 return ToDispErrCode(hdi_->SetDisplayProperty(devId, id, value)); 296 } 297 Commit(uint32_t devId,int32_t & fence)298 virtual int32_t Commit(uint32_t devId, int32_t& fence) override 299 { 300 COMPOSER_CHECK_NULLPTR_RETURN(req_); 301 return ToDispErrCode(req_->Commit(devId, fence)); 302 } 303 GetDisplaySupportedColorGamuts(uint32_t devId,std::vector<ColorGamut> & gamuts)304 virtual int32_t GetDisplaySupportedColorGamuts(uint32_t devId, std::vector<ColorGamut>& gamuts) override 305 { 306 return DISPLAY_NOT_SUPPORT; 307 } GetDisplayColorGamut(uint32_t devId,ColorGamut & gamut)308 virtual int32_t GetDisplayColorGamut(uint32_t devId, ColorGamut& gamut) override 309 { 310 return DISPLAY_NOT_SUPPORT; 311 } 312 SetDisplayColorGamut(uint32_t devId,const ColorGamut & gamut)313 virtual int32_t SetDisplayColorGamut(uint32_t devId, const ColorGamut& gamut) override 314 { 315 return DISPLAY_NOT_SUPPORT; 316 } 317 GetDisplayGamutMap(uint32_t devId,GamutMap & gamutMap)318 virtual int32_t GetDisplayGamutMap(uint32_t devId, GamutMap& gamutMap) override 319 { 320 return DISPLAY_NOT_SUPPORT; 321 } 322 SetDisplayGamutMap(uint32_t devId,const GamutMap & gamutMap)323 virtual int32_t SetDisplayGamutMap(uint32_t devId, const GamutMap& gamutMap) override 324 { 325 return DISPLAY_NOT_SUPPORT; 326 } 327 SetDisplayColorTransform(uint32_t devId,const std::vector<float> & matrix)328 virtual int32_t SetDisplayColorTransform(uint32_t devId, const std::vector<float>& matrix) override 329 { 330 return DISPLAY_NOT_SUPPORT; 331 } 332 GetHDRCapabilityInfos(uint32_t devId,HDRCapability & info)333 virtual int32_t GetHDRCapabilityInfos(uint32_t devId, HDRCapability& info) override 334 { 335 return DISPLAY_NOT_SUPPORT; 336 } 337 GetSupportedMetadataKey(uint32_t devId,std::vector<HDRMetadataKey> & keys)338 virtual int32_t GetSupportedMetadataKey(uint32_t devId, std::vector<HDRMetadataKey>& keys) override 339 { 340 return DISPLAY_NOT_SUPPORT; 341 } 342 343 // layer func CreateLayer(uint32_t devId,const LayerInfo & layerInfo,uint32_t cacheCount,uint32_t & layerId)344 virtual int32_t CreateLayer(uint32_t devId, const LayerInfo& layerInfo, uint32_t cacheCount, 345 uint32_t& layerId) override 346 { 347 COMPOSER_CHECK_NULLPTR_RETURN(hdi_); 348 return ToDispErrCode(hdi_->CreateLayer(devId, layerInfo, cacheCount, layerId)); 349 } 350 DestroyLayer(uint32_t devId,uint32_t layerId)351 virtual int32_t DestroyLayer(uint32_t devId, uint32_t layerId) override 352 { 353 COMPOSER_CHECK_NULLPTR_RETURN(hdi_); 354 return ToDispErrCode(hdi_->DestroyLayer(devId, layerId)); 355 } 356 PrepareDisplayLayers(uint32_t devId,bool & needFlushFb)357 virtual int32_t PrepareDisplayLayers(uint32_t devId, bool& needFlushFb) override 358 { 359 COMPOSER_CHECK_NULLPTR_RETURN(req_); 360 return ToDispErrCode(req_->PrepareDisplayLayers(devId, needFlushFb)); 361 } 362 SetLayerAlpha(uint32_t devId,uint32_t layerId,const LayerAlpha & alpha)363 virtual int32_t SetLayerAlpha(uint32_t devId, uint32_t layerId, const LayerAlpha& alpha) override 364 { 365 COMPOSER_CHECK_NULLPTR_RETURN(req_); 366 return ToDispErrCode(req_->SetLayerAlpha(devId, layerId, alpha)); 367 } 368 SetLayerRegion(uint32_t devId,uint32_t layerId,const IRect & rect)369 virtual int32_t SetLayerRegion(uint32_t devId, uint32_t layerId, const IRect& rect) override 370 { 371 COMPOSER_CHECK_NULLPTR_RETURN(req_); 372 return ToDispErrCode(req_->SetLayerRegion(devId, layerId, rect)); 373 } 374 SetLayerCrop(uint32_t devId,uint32_t layerId,const IRect & rect)375 virtual int32_t SetLayerCrop(uint32_t devId, uint32_t layerId, const IRect& rect) override 376 { 377 COMPOSER_CHECK_NULLPTR_RETURN(req_); 378 return ToDispErrCode(req_->SetLayerCrop(devId, layerId, rect)); 379 } 380 SetLayerZorder(uint32_t devId,uint32_t layerId,uint32_t zorder)381 virtual int32_t SetLayerZorder(uint32_t devId, uint32_t layerId, uint32_t zorder) override 382 { 383 COMPOSER_CHECK_NULLPTR_RETURN(req_); 384 return ToDispErrCode(req_->SetLayerZorder(devId, layerId, zorder)); 385 } 386 SetLayerPreMulti(uint32_t devId,uint32_t layerId,bool preMul)387 virtual int32_t SetLayerPreMulti(uint32_t devId, uint32_t layerId, bool preMul) override 388 { 389 COMPOSER_CHECK_NULLPTR_RETURN(req_); 390 return ToDispErrCode(req_->SetLayerPreMulti(devId, layerId, preMul)); 391 } 392 SetLayerTransformMode(uint32_t devId,uint32_t layerId,TransformType type)393 virtual int32_t SetLayerTransformMode(uint32_t devId, uint32_t layerId, TransformType type) override 394 { 395 COMPOSER_CHECK_NULLPTR_RETURN(req_); 396 return ToDispErrCode(req_->SetLayerTransformMode(devId, layerId, type)); 397 } 398 SetLayerDirtyRegion(uint32_t devId,uint32_t layerId,std::vector<IRect> & rects)399 virtual int32_t SetLayerDirtyRegion(uint32_t devId, uint32_t layerId, std::vector<IRect>& rects) override 400 { 401 COMPOSER_CHECK_NULLPTR_RETURN(req_); 402 return ToDispErrCode(req_->SetLayerDirtyRegion(devId, layerId, rects)); 403 } 404 SetLayerVisibleRegion(uint32_t devId,uint32_t layerId,std::vector<IRect> & rects)405 virtual int32_t SetLayerVisibleRegion(uint32_t devId, uint32_t layerId, std::vector<IRect>& rects) override 406 { 407 COMPOSER_CHECK_NULLPTR_RETURN(req_); 408 return ToDispErrCode(req_->SetLayerVisibleRegion(devId, layerId, rects)); 409 } 410 SetLayerBuffer(uint32_t devId,uint32_t layerId,const BufferHandle * buffer,uint32_t seqNo,int32_t fence,const std::vector<uint32_t> & deletingList)411 virtual int32_t SetLayerBuffer(uint32_t devId, uint32_t layerId, const BufferHandle* buffer, uint32_t seqNo, 412 int32_t fence, const std::vector<uint32_t>& deletingList) override 413 { 414 COMPOSER_CHECK_NULLPTR_RETURN(req_); 415 return ToDispErrCode(req_->SetLayerBuffer(devId, layerId, buffer, seqNo, fence, deletingList)); 416 } 417 SetLayerCompositionType(uint32_t devId,uint32_t layerId,CompositionType type)418 virtual int32_t SetLayerCompositionType(uint32_t devId, uint32_t layerId, CompositionType type) override 419 { 420 COMPOSER_CHECK_NULLPTR_RETURN(req_); 421 return ToDispErrCode(req_->SetLayerCompositionType(devId, layerId, type)); 422 } 423 SetLayerBlendType(uint32_t devId,uint32_t layerId,BlendType type)424 virtual int32_t SetLayerBlendType(uint32_t devId, uint32_t layerId, BlendType type) override 425 { 426 COMPOSER_CHECK_NULLPTR_RETURN(req_); 427 return ToDispErrCode(req_->SetLayerBlendType(devId, layerId, type)); 428 } 429 SetLayerMaskInfo(uint32_t devId,uint32_t layerId,const MaskInfo maskInfo)430 virtual int32_t SetLayerMaskInfo(uint32_t devId, uint32_t layerId, const MaskInfo maskInfo) override 431 { 432 COMPOSER_CHECK_NULLPTR_RETURN(hdi_); 433 return ToDispErrCode(req_->SetLayerMaskInfo(devId, layerId, maskInfo)); 434 } 435 SetLayerColorTransform(uint32_t devId,uint32_t layerId,const std::vector<float> & matrix)436 virtual int32_t SetLayerColorTransform(uint32_t devId, uint32_t layerId, const std::vector<float>& matrix) override 437 { 438 return DISPLAY_NOT_SUPPORT; 439 } 440 SetLayerColorDataSpace(uint32_t devId,uint32_t layerId,const ColorDataSpace colorSpace)441 virtual int32_t SetLayerColorDataSpace(uint32_t devId, uint32_t layerId, const ColorDataSpace colorSpace) override 442 { 443 return DISPLAY_NOT_SUPPORT; 444 } 445 GetLayerColorDataSpace(uint32_t devId,uint32_t layerId,ColorDataSpace & colorSpace)446 virtual int32_t GetLayerColorDataSpace(uint32_t devId, uint32_t layerId, ColorDataSpace& colorSpace) override 447 { 448 return DISPLAY_NOT_SUPPORT; 449 } 450 SetLayerMetaData(uint32_t devId,uint32_t layerId,const std::vector<HDRMetaData> & metaData)451 virtual int32_t SetLayerMetaData(uint32_t devId, uint32_t layerId, 452 const std::vector<HDRMetaData>& metaData) override 453 { 454 return DISPLAY_NOT_SUPPORT; 455 } 456 SetLayerMetaDataSet(uint32_t devId,uint32_t layerId,HDRMetadataKey key,const std::vector<uint8_t> & metaData)457 virtual int32_t SetLayerMetaDataSet(uint32_t devId, uint32_t layerId, HDRMetadataKey key, 458 const std::vector<uint8_t>& metaData) override 459 { 460 return DISPLAY_NOT_SUPPORT; 461 } 462 GetSupportedPresentTimestamp(uint32_t devId,uint32_t layerId,PresentTimestampType & type)463 virtual int32_t GetSupportedPresentTimestamp(uint32_t devId, uint32_t layerId, PresentTimestampType& type) override 464 { 465 return DISPLAY_NOT_SUPPORT; 466 } 467 GetHwPresentTimestamp(uint32_t devId,uint32_t layerId,PresentTimestamp & pts)468 virtual int32_t GetHwPresentTimestamp(uint32_t devId, uint32_t layerId, PresentTimestamp& pts) override 469 { 470 return DISPLAY_NOT_SUPPORT; 471 } 472 SetLayerTunnelHandle(uint32_t devId,uint32_t layerId,const ExtDataHandle & handle)473 virtual int32_t SetLayerTunnelHandle(uint32_t devId, uint32_t layerId, const ExtDataHandle& handle) override 474 { 475 return DISPLAY_NOT_SUPPORT; 476 } 477 SetLayerColor(uint32_t devId,uint32_t layerId,const LayerColor & layerColor)478 virtual int32_t SetLayerColor(uint32_t devId, uint32_t layerId, const LayerColor& layerColor) override 479 { 480 COMPOSER_CHECK_NULLPTR_RETURN(req_); 481 return ToDispErrCode(req_->SetLayerColor(devId, layerId, layerColor)); 482 } 483 484 // Callback implement OnHotPlug(uint32_t outputId,bool connected)485 virtual int32_t OnHotPlug(uint32_t outputId, bool connected) override 486 { 487 DISPLAY_TRACE; 488 489 HDF_LOGI("OnHotPlug(%{public}u, %{public}u)", outputId, connected); 490 int32_t ret = HDF_SUCCESS; 491 if (hotPlugCb_ != nullptr) { 492 hotPlugCb_(outputId, connected, hotPlugCbData_); 493 } else { 494 HDF_LOGE("error: hot plug callback fn is nullptr"); 495 ret = HDF_FAILURE; 496 } 497 498 return ret; 499 } 500 OnVBlank(uint32_t sequence,uint64_t ns)501 virtual int32_t OnVBlank(uint32_t sequence, uint64_t ns) override 502 { 503 DISPLAY_TRACE; 504 505 int32_t ret = HDF_SUCCESS; 506 if (vBlankCb_ != nullptr) { 507 vBlankCb_(sequence, ns, vBlankCbData_); 508 } else { 509 HDF_LOGE("error: vblank callback fn is nullptr"); 510 ret = HDF_FAILURE; 511 } 512 513 return ret; 514 } 515 516 protected: ToDispErrCode(int32_t hdfStatus)517 int32_t ToDispErrCode(int32_t hdfStatus) 518 { 519 int32_t ec = DISPLAY_FAILURE; 520 switch (hdfStatus) { 521 case HDF_SUCCESS: 522 ec = DISPLAY_SUCCESS; 523 break; 524 case HDF_FAILURE: 525 ec = DISPLAY_FAILURE; 526 break; 527 case HDF_ERR_NOT_SUPPORT: 528 ec = DISPLAY_NOT_SUPPORT; 529 break; 530 case HDF_ERR_INVALID_PARAM: 531 ec = DISPLAY_PARAM_ERR; 532 break; 533 case HDF_ERR_DEVICE_BUSY: 534 ec = DISPLAY_SYS_BUSY; 535 break; 536 case HDF_ERR_BAD_FD: 537 ec = DISPLAY_FD_ERR; 538 break; 539 case HDF_ERR_NOPERM: 540 ec = DISPLAY_NOT_PERM; 541 break; 542 case HDF_DEV_ERR_NO_MEMORY: 543 ec = DISPLAY_NOMEM; 544 break; 545 case HDF_ERR_IO: 546 case HDF_ERR_INVALID_OBJECT: 547 case HDF_ERR_MALLOC_FAIL: 548 case HDF_ERR_TIMEOUT: 549 case HDF_ERR_THREAD_CREATE_FAIL: 550 case HDF_ERR_QUEUE_FULL: 551 case HDF_BSP_ERR_OP: 552 case HDF_ERR_BSP_PLT_API_ERR: 553 case HDF_PAL_ERR_DEV_CREATE: 554 case HDF_PAL_ERR_INNER: 555 case HDF_DEV_ERR_NO_DEVICE: 556 case HDF_DEV_ERR_NO_DEVICE_SERVICE: 557 case HDF_DEV_ERR_DEV_INIT_FAIL: 558 case HDF_DEV_ERR_PUBLISH_FAIL: 559 case HDF_DEV_ERR_ATTACHDEV_FAIL: 560 case HDF_DEV_ERR_NODATA: 561 case HDF_DEV_ERR_NORANGE: 562 case HDF_DEV_ERR_OP: 563 default: 564 break; 565 } 566 return ec; 567 } 568 569 protected: 570 static constexpr uint32_t WAIT_TIME_INTERVAL = 10000; 571 sptr<CompHdi> hdi_; 572 std::shared_ptr<CmdReq> req_; 573 HotPlugCallback hotPlugCb_; 574 VBlankCallback vBlankCb_; 575 void *hotPlugCbData_; 576 void *vBlankCbData_; 577 sptr<IRemoteObject::DeathRecipient> recipient_; 578 std::unordered_map<uint32_t, uint32_t> vsyncEnableCount_; 579 }; 580 using HdiDisplayComposer = DisplayComposerHdiImpl<IDisplayComposerInterface, IDisplayComposer, HdiDisplayCmdRequester>; 581 } // namespace V1_0 582 } // namespace Composer 583 } // namespace Display 584 } // namespace HDI 585 } // namespace OHOS 586 #endif // OHOS_HDI_DISPLAY_V1_0_DISPLAY_COMPOSER_HDI_IMPL_H 587