From 0b4effefb98cae049cd9d281a79f97be6be44d42 Mon Sep 17 00:00:00 2001 From: yangkan Date: Tue, 22 Oct 2024 13:57:01 +0800 Subject: [PATCH] =?UTF-8?q?surface=E6=9D=83=E9=99=90=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yangkan --- .../v1_0/hdi_impl/display_buffer_hdi_impl.h | 54 ++++++++++--------- display/buffer/v1_0/include/idisplay_buffer.h | 2 +- 2 files changed, 30 insertions(+), 26 deletions(-) diff --git a/display/buffer/v1_0/hdi_impl/display_buffer_hdi_impl.h b/display/buffer/v1_0/hdi_impl/display_buffer_hdi_impl.h index 925dd06f..e2280088 100644 --- a/display/buffer/v1_0/hdi_impl/display_buffer_hdi_impl.h +++ b/display/buffer/v1_0/hdi_impl/display_buffer_hdi_impl.h @@ -75,10 +75,6 @@ public: explicit DisplayBufferHdiImpl(bool isAllocLocal = false) : allocator_(nullptr), mapper_(nullptr), recipient_(nullptr) { - while ((allocator_ = IAllocator::Get(isAllocLocal)) == nullptr) { - // Waiting for allocator service ready - usleep(WAIT_TIME_INTERVAL); - } while ((mapper_ = IMapper::Get(true)) == nullptr) { // Waiting for mapper IF ready usleep(WAIT_TIME_INTERVAL); @@ -87,43 +83,50 @@ public: virtual ~DisplayBufferHdiImpl() { if (recipient_ != nullptr) { - sptr remoteObj = OHOS::HDI::hdi_objcast(allocator_); - remoteObj->RemoveDeathRecipient(recipient_); - recipient_ = nullptr; + if (allocator_ != nullptr) { + sptr remoteObj = OHOS::HDI::hdi_objcast(allocator_); + remoteObj->RemoveDeathRecipient(recipient_); + recipient_ = nullptr; + } } } bool AddDeathRecipient(const sptr& recipient) override { - sptr remoteObj = OHOS::HDI::hdi_objcast(allocator_); - if (recipient_ != nullptr) { - HDF_LOGE("%{public}s: the existing recipient is removed, and add the new. %{public}d", - __func__, __LINE__); - remoteObj->RemoveDeathRecipient(recipient_); - } - bool ret = remoteObj->AddDeathRecipient(recipient); - if (ret) { - recipient_ = recipient; - } else { - recipient_ = nullptr; - HDF_LOGE("%{public}s: AddDeathRecipient failed %{public}d", __func__, __LINE__); - } - return ret; + + recipient_ = recipient; + return true; } bool RemoveDeathRecipient() override { if (recipient_ != nullptr) { - sptr remoteObj = OHOS::HDI::hdi_objcast(allocator_); - remoteObj->RemoveDeathRecipient(recipient_); - recipient_ = nullptr; + if (allocator_ != nullptr) { + sptr remoteObj = OHOS::HDI::hdi_objcast(allocator_); + remoteObj->RemoveDeathRecipient(recipient_); + recipient_ = nullptr; + } } return true; } - int32_t AllocMem(const AllocInfo& info, BufferHandle*& handle) const override + int32_t AllocMem(const AllocInfo& info, BufferHandle*& handle) override { + if (allocator_ == nullptr) { + HDF_LOGE("%{public}s: yktest allocator_ is nullptr", __func__); + std::lock_guard lock(mutex_); + while (allocator_ == nullptr) { + HDF_LOGE("%{public}s: yktest allocator_ is nullptr1", __func__); + allocator_ = IAllocator::Get(false); + } + } + CHECK_NULLPOINTER_RETURN_VALUE(allocator_, HDF_FAILURE); + sptr remoteObj = OHOS::HDI::hdi_objcast(allocator_); + HDF_LOGE("%{public}s: yktest allocator_ get complete", __func__); + remoteObj->AddDeathRecipient(recipient_); + HDF_LOGE("%{public}s: yktest AddDeathRecipient complete", __func__); + sptr hdiBuffer; int32_t ret = allocator_->AllocMem(info, hdiBuffer); if ((ret == HDF_SUCCESS) && (hdiBuffer != nullptr)) { @@ -201,6 +204,7 @@ protected: sptr allocator_; sptr mapper_; sptr recipient_; + std::mutex mutex_; }; using HdiDisplayBufferImpl = DisplayBufferHdiImpl; } // namespace V1_0 diff --git a/display/buffer/v1_0/include/idisplay_buffer.h b/display/buffer/v1_0/include/idisplay_buffer.h index b51a5f9b..f6c76db0 100644 --- a/display/buffer/v1_0/include/idisplay_buffer.h +++ b/display/buffer/v1_0/include/idisplay_buffer.h @@ -53,7 +53,7 @@ public: * @since 4.0 * @version 1.0 */ - virtual int32_t AllocMem(const AllocInfo& info, BufferHandle*& handle) const = 0; + virtual int32_t AllocMem(const AllocInfo& info, BufferHandle*& handle) = 0; /** * @brief Releases memory. -- Gitee