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(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 57 while ((hdi = CompHdi::Get()) == nullptr) { 58 // Waiting for display composer service ready 59 usleep(WAIT_TIME_INTERVAL); 60 } 61 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(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(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(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(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(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(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(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(hdi_); 168 return ToDispErrCode(hdi_->SetDisplayPowerStatus(devId, status)); 169 } 170 GetDisplayBacklight(uint32_t devId,uint32_t & level)171 virtual int32_t GetDisplayBacklight(uint32_t devId, uint32_t& level) override 172 { 173 COMPOSER_CHECK_NULLPTR(hdi_); 174 return ToDispErrCode(hdi_->GetDisplayBacklight(devId, level)); 175 } 176 SetDisplayBacklight(uint32_t devId,uint32_t level)177 virtual int32_t SetDisplayBacklight(uint32_t devId, uint32_t level) override 178 { 179 COMPOSER_CHECK_NULLPTR(hdi_); 180 return ToDispErrCode(hdi_->SetDisplayBacklight(devId, level)); 181 } 182 GetDisplayProperty(uint32_t devId,uint32_t id,uint64_t & value)183 virtual int32_t GetDisplayProperty(uint32_t devId, uint32_t id, uint64_t& value) override 184 { 185 COMPOSER_CHECK_NULLPTR(hdi_); 186 return ToDispErrCode(hdi_->GetDisplayProperty(devId, id, value)); 187 } 188 GetDisplayCompChange(uint32_t devId,std::vector<uint32_t> & layers,std::vector<int32_t> & types)189 virtual int32_t GetDisplayCompChange( 190 uint32_t devId, std::vector<uint32_t>& layers, std::vector<int32_t>& types) override 191 { 192 COMPOSER_CHECK_NULLPTR(req_); 193 return ToDispErrCode(req_->GetDisplayCompChange(devId, layers, types)); 194 } 195 SetDisplayClientCrop(uint32_t devId,const IRect & rect)196 virtual int32_t SetDisplayClientCrop(uint32_t devId, const IRect& rect) override 197 { 198 COMPOSER_CHECK_NULLPTR(hdi_); 199 return ToDispErrCode(hdi_->SetDisplayClientCrop(devId, rect)); 200 } 201 SetDisplayClientBuffer(uint32_t devId,const BufferHandle * buffer,uint32_t seqNo,int32_t fence)202 virtual int32_t SetDisplayClientBuffer(uint32_t devId, const BufferHandle* buffer, uint32_t seqNo, 203 int32_t fence) override 204 { 205 COMPOSER_CHECK_NULLPTR(req_); 206 return ToDispErrCode(req_->SetDisplayClientBuffer(devId, buffer, seqNo, fence)); 207 } 208 SetDisplayClientDamage(uint32_t devId,std::vector<IRect> & rects)209 virtual int32_t SetDisplayClientDamage(uint32_t devId, std::vector<IRect>& rects) override 210 { 211 COMPOSER_CHECK_NULLPTR(req_); 212 return ToDispErrCode(req_->SetDisplayClientDamage(devId, rects)); 213 } 214 SetDisplayVsyncEnabled(uint32_t devId,bool enabled)215 virtual int32_t SetDisplayVsyncEnabled(uint32_t devId, bool enabled) override 216 { 217 COMPOSER_CHECK_NULLPTR(hdi_); 218 219 /* Already enabled, return success */ 220 if (enabled && vsyncEnableCount_[devId] > 0) { 221 HDF_LOGD("%{public}s: Count[%{public}u] = %{public}u, Skip", __func__, devId, vsyncEnableCount_[devId]); 222 ++vsyncEnableCount_[devId]; 223 return DISPLAY_SUCCESS; 224 } 225 226 int32_t ret = ToDispErrCode(hdi_->SetDisplayVsyncEnabled(devId, enabled)); 227 if (ret != DISPLAY_SUCCESS) { 228 return ret; 229 } 230 231 vsyncEnableCount_[devId] = enabled ? 1 : 0; 232 return ret; 233 } 234 RegDisplayVBlankCallback(uint32_t devId,VBlankCallback cb,void * data)235 virtual int32_t RegDisplayVBlankCallback(uint32_t devId, VBlankCallback cb, void *data) override 236 { 237 vBlankCb_ = cb; 238 vBlankCbData_ = data; 239 COMPOSER_CHECK_NULLPTR(hdi_); 240 return ToDispErrCode(hdi_->RegDisplayVBlankCallback(devId, this)); 241 } 242 GetDisplayReleaseFence(uint32_t devId,std::vector<uint32_t> & layers,std::vector<int32_t> & fences)243 virtual int32_t GetDisplayReleaseFence( 244 uint32_t devId, std::vector<uint32_t>& layers, std::vector<int32_t>& fences) override 245 { 246 std::vector<sptr<HdifdParcelable>> hdiFences; 247 COMPOSER_CHECK_NULLPTR(hdi_); 248 int32_t ret = ToDispErrCode(hdi_->GetDisplayReleaseFence(devId, layers, hdiFences)); 249 if (ret == DISPLAY_SUCCESS) { 250 for (uint32_t i = 0; i < hdiFences.size(); i++) { 251 if (hdiFences[i] == nullptr) { 252 HDF_LOGE("%{public}s: GetReleaseFence contains nullptr", __func__); 253 continue; 254 } 255 fences.push_back(hdiFences[i]->Move()); 256 } 257 } 258 return ret; 259 } 260 CreateVirtualDisplay(uint32_t width,uint32_t height,int32_t & format,uint32_t & devId)261 virtual int32_t CreateVirtualDisplay(uint32_t width, uint32_t height, int32_t& format, uint32_t& devId) override 262 { 263 COMPOSER_CHECK_NULLPTR(hdi_); 264 return ToDispErrCode(hdi_->CreateVirtualDisplay(width, height, format, devId)); 265 } 266 DestroyVirtualDisplay(uint32_t devId)267 virtual int32_t DestroyVirtualDisplay(uint32_t devId) override 268 { 269 COMPOSER_CHECK_NULLPTR(hdi_); 270 return ToDispErrCode(hdi_->DestroyVirtualDisplay(devId)); 271 } 272 SetVirtualDisplayBuffer(uint32_t devId,const BufferHandle & buffer,const int32_t fence)273 virtual int32_t SetVirtualDisplayBuffer(uint32_t devId, const BufferHandle& buffer, const int32_t fence) override 274 { 275 int32_t ret = DISPLAY_SUCCESS; 276 277 sptr<NativeBuffer> hdiBuffer = new NativeBuffer(); 278 if (hdiBuffer == nullptr) { 279 ret = DISPLAY_FAILURE; 280 } else { 281 hdiBuffer->SetBufferHandle(const_cast<BufferHandle*>(&buffer)); 282 sptr<HdifdParcelable> hdiFence(new HdifdParcelable); 283 hdiFence->Init(fence); 284 ret = ToDispErrCode(hdi_->SetVirtualDisplayBuffer(devId, hdiBuffer, hdiFence)); 285 } 286 287 return ret; 288 } 289 SetDisplayProperty(uint32_t devId,uint32_t id,uint64_t value)290 virtual int32_t SetDisplayProperty(uint32_t devId, uint32_t id, uint64_t value) override 291 { 292 COMPOSER_CHECK_NULLPTR(hdi_); 293 return ToDispErrCode(hdi_->SetDisplayProperty(devId, id, value)); 294 } 295 Commit(uint32_t devId,int32_t & fence)296 virtual int32_t Commit(uint32_t devId, int32_t& fence) override 297 { 298 COMPOSER_CHECK_NULLPTR(req_); 299 return ToDispErrCode(req_->Commit(devId, fence)); 300 } 301 GetDisplaySupportedColorGamuts(uint32_t devId,std::vector<ColorGamut> & gamuts)302 virtual int32_t GetDisplaySupportedColorGamuts(uint32_t devId, std::vector<ColorGamut>& gamuts) override 303 { 304 return DISPLAY_NOT_SUPPORT; 305 } GetDisplayColorGamut(uint32_t devId,ColorGamut & gamut)306 virtual int32_t GetDisplayColorGamut(uint32_t devId, ColorGamut& gamut) override 307 { 308 return DISPLAY_NOT_SUPPORT; 309 } 310 SetDisplayColorGamut(uint32_t devId,const ColorGamut & gamut)311 virtual int32_t SetDisplayColorGamut(uint32_t devId, const ColorGamut& gamut) override 312 { 313 return DISPLAY_NOT_SUPPORT; 314 } 315 GetDisplayGamutMap(uint32_t devId,GamutMap & gamutMap)316 virtual int32_t GetDisplayGamutMap(uint32_t devId, GamutMap& gamutMap) override 317 { 318 return DISPLAY_NOT_SUPPORT; 319 } 320 SetDisplayGamutMap(uint32_t devId,const GamutMap & gamutMap)321 virtual int32_t SetDisplayGamutMap(uint32_t devId, const GamutMap& gamutMap) override 322 { 323 return DISPLAY_NOT_SUPPORT; 324 } 325 SetDisplayColorTransform(uint32_t devId,const std::vector<float> & matrix)326 virtual int32_t SetDisplayColorTransform(uint32_t devId, const std::vector<float>& matrix) override 327 { 328 return DISPLAY_NOT_SUPPORT; 329 } 330 GetHDRCapabilityInfos(uint32_t devId,HDRCapability & info)331 virtual int32_t GetHDRCapabilityInfos(uint32_t devId, HDRCapability& info) override 332 { 333 return DISPLAY_NOT_SUPPORT; 334 } 335 GetSupportedMetadataKey(uint32_t devId,std::vector<HDRMetadataKey> & keys)336 virtual int32_t GetSupportedMetadataKey(uint32_t devId, std::vector<HDRMetadataKey>& keys) override 337 { 338 return DISPLAY_NOT_SUPPORT; 339 } 340 341 // layer func CreateLayer(uint32_t devId,const LayerInfo & layerInfo,uint32_t cacheCount,uint32_t & layerId)342 virtual int32_t CreateLayer(uint32_t devId, const LayerInfo& layerInfo, uint32_t cacheCount, 343 uint32_t& layerId) override 344 { 345 COMPOSER_CHECK_NULLPTR(hdi_); 346 return ToDispErrCode(hdi_->CreateLayer(devId, layerInfo, cacheCount, layerId)); 347 } 348 DestroyLayer(uint32_t devId,uint32_t layerId)349 virtual int32_t DestroyLayer(uint32_t devId, uint32_t layerId) override 350 { 351 COMPOSER_CHECK_NULLPTR(hdi_); 352 return ToDispErrCode(hdi_->DestroyLayer(devId, layerId)); 353 } 354 PrepareDisplayLayers(uint32_t devId,bool & needFlushFb)355 virtual int32_t PrepareDisplayLayers(uint32_t devId, bool& needFlushFb) override 356 { 357 COMPOSER_CHECK_NULLPTR(req_); 358 return ToDispErrCode(req_->PrepareDisplayLayers(devId, needFlushFb)); 359 } 360 SetLayerAlpha(uint32_t devId,uint32_t layerId,const LayerAlpha & alpha)361 virtual int32_t SetLayerAlpha(uint32_t devId, uint32_t layerId, const LayerAlpha& alpha) override 362 { 363 COMPOSER_CHECK_NULLPTR(req_); 364 return ToDispErrCode(req_->SetLayerAlpha(devId, layerId, alpha)); 365 } 366 SetLayerRegion(uint32_t devId,uint32_t layerId,const IRect & rect)367 virtual int32_t SetLayerRegion(uint32_t devId, uint32_t layerId, const IRect& rect) override 368 { 369 COMPOSER_CHECK_NULLPTR(req_); 370 return ToDispErrCode(req_->SetLayerRegion(devId, layerId, rect)); 371 } 372 SetLayerCrop(uint32_t devId,uint32_t layerId,const IRect & rect)373 virtual int32_t SetLayerCrop(uint32_t devId, uint32_t layerId, const IRect& rect) override 374 { 375 COMPOSER_CHECK_NULLPTR(req_); 376 return ToDispErrCode(req_->SetLayerCrop(devId, layerId, rect)); 377 } 378 SetLayerZorder(uint32_t devId,uint32_t layerId,uint32_t zorder)379 virtual int32_t SetLayerZorder(uint32_t devId, uint32_t layerId, uint32_t zorder) override 380 { 381 COMPOSER_CHECK_NULLPTR(req_); 382 return ToDispErrCode(req_->SetLayerZorder(devId, layerId, zorder)); 383 } 384 SetLayerPreMulti(uint32_t devId,uint32_t layerId,bool preMul)385 virtual int32_t SetLayerPreMulti(uint32_t devId, uint32_t layerId, bool preMul) override 386 { 387 COMPOSER_CHECK_NULLPTR(req_); 388 return ToDispErrCode(req_->SetLayerPreMulti(devId, layerId, preMul)); 389 } 390 SetLayerTransformMode(uint32_t devId,uint32_t layerId,TransformType type)391 virtual int32_t SetLayerTransformMode(uint32_t devId, uint32_t layerId, TransformType type) override 392 { 393 COMPOSER_CHECK_NULLPTR(req_); 394 return ToDispErrCode(req_->SetLayerTransformMode(devId, layerId, type)); 395 } 396 SetLayerDirtyRegion(uint32_t devId,uint32_t layerId,std::vector<IRect> & rects)397 virtual int32_t SetLayerDirtyRegion(uint32_t devId, uint32_t layerId, std::vector<IRect>& rects) override 398 { 399 COMPOSER_CHECK_NULLPTR(req_); 400 return ToDispErrCode(req_->SetLayerDirtyRegion(devId, layerId, rects)); 401 } 402 SetLayerVisibleRegion(uint32_t devId,uint32_t layerId,std::vector<IRect> & rects)403 virtual int32_t SetLayerVisibleRegion(uint32_t devId, uint32_t layerId, std::vector<IRect>& rects) override 404 { 405 COMPOSER_CHECK_NULLPTR(req_); 406 return ToDispErrCode(req_->SetLayerVisibleRegion(devId, layerId, rects)); 407 } 408 SetLayerBuffer(uint32_t devId,uint32_t layerId,const BufferHandle * buffer,uint32_t seqNo,int32_t fence,const std::vector<uint32_t> & deletingList)409 virtual int32_t SetLayerBuffer(uint32_t devId, uint32_t layerId, const BufferHandle* buffer, uint32_t seqNo, 410 int32_t fence, const std::vector<uint32_t>& deletingList) override 411 { 412 COMPOSER_CHECK_NULLPTR(req_); 413 return ToDispErrCode(req_->SetLayerBuffer(devId, layerId, buffer, seqNo, fence, deletingList)); 414 } 415 SetLayerCompositionType(uint32_t devId,uint32_t layerId,CompositionType type)416 virtual int32_t SetLayerCompositionType(uint32_t devId, uint32_t layerId, CompositionType type) override 417 { 418 COMPOSER_CHECK_NULLPTR(req_); 419 return ToDispErrCode(req_->SetLayerCompositionType(devId, layerId, type)); 420 } 421 SetLayerBlendType(uint32_t devId,uint32_t layerId,BlendType type)422 virtual int32_t SetLayerBlendType(uint32_t devId, uint32_t layerId, BlendType type) override 423 { 424 COMPOSER_CHECK_NULLPTR(req_); 425 return ToDispErrCode(req_->SetLayerBlendType(devId, layerId, type)); 426 } 427 SetLayerMaskInfo(uint32_t devId,uint32_t layerId,const MaskInfo maskInfo)428 virtual int32_t SetLayerMaskInfo(uint32_t devId, uint32_t layerId, const MaskInfo maskInfo) override 429 { 430 COMPOSER_CHECK_NULLPTR(hdi_); 431 return ToDispErrCode(req_->SetLayerMaskInfo(devId, layerId, maskInfo)); 432 } 433 SetLayerColorTransform(uint32_t devId,uint32_t layerId,const std::vector<float> & matrix)434 virtual int32_t SetLayerColorTransform(uint32_t devId, uint32_t layerId, const std::vector<float>& matrix) override 435 { 436 return DISPLAY_NOT_SUPPORT; 437 } 438 SetLayerColorDataSpace(uint32_t devId,uint32_t layerId,const ColorDataSpace colorSpace)439 virtual int32_t SetLayerColorDataSpace(uint32_t devId, uint32_t layerId, const ColorDataSpace colorSpace) override 440 { 441 return DISPLAY_NOT_SUPPORT; 442 } 443 GetLayerColorDataSpace(uint32_t devId,uint32_t layerId,ColorDataSpace & colorSpace)444 virtual int32_t GetLayerColorDataSpace(uint32_t devId, uint32_t layerId, ColorDataSpace& colorSpace) override 445 { 446 return DISPLAY_NOT_SUPPORT; 447 } 448 SetLayerMetaData(uint32_t devId,uint32_t layerId,const std::vector<HDRMetaData> & metaData)449 virtual int32_t SetLayerMetaData(uint32_t devId, uint32_t layerId, 450 const std::vector<HDRMetaData>& metaData) override 451 { 452 return DISPLAY_NOT_SUPPORT; 453 } 454 SetLayerMetaDataSet(uint32_t devId,uint32_t layerId,HDRMetadataKey key,const std::vector<uint8_t> & metaData)455 virtual int32_t SetLayerMetaDataSet(uint32_t devId, uint32_t layerId, HDRMetadataKey key, 456 const std::vector<uint8_t>& metaData) override 457 { 458 return DISPLAY_NOT_SUPPORT; 459 } 460 GetSupportedPresentTimestamp(uint32_t devId,uint32_t layerId,PresentTimestampType & type)461 virtual int32_t GetSupportedPresentTimestamp(uint32_t devId, uint32_t layerId, PresentTimestampType& type) override 462 { 463 return DISPLAY_NOT_SUPPORT; 464 } 465 GetHwPresentTimestamp(uint32_t devId,uint32_t layerId,PresentTimestamp & pts)466 virtual int32_t GetHwPresentTimestamp(uint32_t devId, uint32_t layerId, PresentTimestamp& pts) override 467 { 468 return DISPLAY_NOT_SUPPORT; 469 } 470 SetLayerTunnelHandle(uint32_t devId,uint32_t layerId,const ExtDataHandle & handle)471 virtual int32_t SetLayerTunnelHandle(uint32_t devId, uint32_t layerId, const ExtDataHandle& handle) override 472 { 473 return DISPLAY_NOT_SUPPORT; 474 } 475 SetLayerColor(uint32_t devId,uint32_t layerId,const LayerColor & layerColor)476 virtual int32_t SetLayerColor(uint32_t devId, uint32_t layerId, const LayerColor& layerColor) override 477 { 478 COMPOSER_CHECK_NULLPTR(req_); 479 return ToDispErrCode(req_->SetLayerColor(devId, layerId, layerColor)); 480 } 481 482 // Callback implement OnHotPlug(uint32_t outputId,bool connected)483 virtual int32_t OnHotPlug(uint32_t outputId, bool connected) override 484 { 485 HDF_LOGI("OnHotPlug(%{public}u, %{public}u)", outputId, connected); 486 int32_t ret = HDF_SUCCESS; 487 if (hotPlugCb_ != nullptr) { 488 hotPlugCb_(outputId, connected, hotPlugCbData_); 489 } else { 490 HDF_LOGE("error: hot plug callback fn is nullptr"); 491 ret = HDF_FAILURE; 492 } 493 494 return ret; 495 } 496 OnVBlank(uint32_t sequence,uint64_t ns)497 virtual int32_t OnVBlank(uint32_t sequence, uint64_t ns) override 498 { 499 DISPLAY_TRACE; 500 501 int32_t ret = HDF_SUCCESS; 502 if (vBlankCb_ != nullptr) { 503 vBlankCb_(sequence, ns, vBlankCbData_); 504 } else { 505 HDF_LOGE("error: vblank callback fn is nullptr"); 506 ret = HDF_FAILURE; 507 } 508 509 return ret; 510 } 511 512 protected: ToDispErrCode(int32_t hdfStatus)513 int32_t ToDispErrCode(int32_t hdfStatus) 514 { 515 int32_t ec = DISPLAY_FAILURE; 516 switch (hdfStatus) { 517 case HDF_SUCCESS: 518 ec = DISPLAY_SUCCESS; 519 break; 520 case HDF_FAILURE: 521 ec = DISPLAY_FAILURE; 522 break; 523 case HDF_ERR_NOT_SUPPORT: 524 ec = DISPLAY_NOT_SUPPORT; 525 break; 526 case HDF_ERR_INVALID_PARAM: 527 ec = DISPLAY_PARAM_ERR; 528 break; 529 case HDF_ERR_DEVICE_BUSY: 530 ec = DISPLAY_SYS_BUSY; 531 break; 532 case HDF_ERR_BAD_FD: 533 ec = DISPLAY_FD_ERR; 534 break; 535 case HDF_ERR_NOPERM: 536 ec = DISPLAY_NOT_PERM; 537 break; 538 case HDF_DEV_ERR_NO_MEMORY: 539 ec = DISPLAY_NOMEM; 540 break; 541 case HDF_ERR_IO: 542 case HDF_ERR_INVALID_OBJECT: 543 case HDF_ERR_MALLOC_FAIL: 544 case HDF_ERR_TIMEOUT: 545 case HDF_ERR_THREAD_CREATE_FAIL: 546 case HDF_ERR_QUEUE_FULL: 547 case HDF_BSP_ERR_OP: 548 case HDF_ERR_BSP_PLT_API_ERR: 549 case HDF_PAL_ERR_DEV_CREATE: 550 case HDF_PAL_ERR_INNER: 551 case HDF_DEV_ERR_NO_DEVICE: 552 case HDF_DEV_ERR_NO_DEVICE_SERVICE: 553 case HDF_DEV_ERR_DEV_INIT_FAIL: 554 case HDF_DEV_ERR_PUBLISH_FAIL: 555 case HDF_DEV_ERR_ATTACHDEV_FAIL: 556 case HDF_DEV_ERR_NODATA: 557 case HDF_DEV_ERR_NORANGE: 558 case HDF_DEV_ERR_OP: 559 default: 560 break; 561 } 562 return ec; 563 } 564 565 protected: 566 static constexpr uint32_t WAIT_TIME_INTERVAL = 10000; 567 sptr<CompHdi> hdi_; 568 std::shared_ptr<CmdReq> req_; 569 HotPlugCallback hotPlugCb_; 570 VBlankCallback vBlankCb_; 571 void *hotPlugCbData_; 572 void *vBlankCbData_; 573 sptr<IRemoteObject::DeathRecipient> recipient_; 574 std::unordered_map<uint32_t, uint32_t> vsyncEnableCount_; 575 }; 576 using HdiDisplayComposer = DisplayComposerHdiImpl<IDisplayComposerInterface, IDisplayComposer, HdiDisplayCmdRequester>; 577 } // namespace V1_0 578 } // namespace Composer 579 } // namespace Display 580 } // namespace HDI 581 } // namespace OHOS 582 #endif // OHOS_HDI_DISPLAY_V1_0_DISPLAY_COMPOSER_HDI_IMPL_H 583