From 12d3b9fd9541e897a11ab799e8d15c771c4aaf5d Mon Sep 17 00:00:00 2001 From: yangkan Date: Mon, 28 Oct 2024 14:34:39 +0800 Subject: [PATCH] =?UTF-8?q?surface=E8=B0=83=E7=94=A8alloc=E6=9D=83?= =?UTF-8?q?=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 --- display/buffer/v1_0/BUILD.gn | 3 ++ .../v1_0/hdi_impl/display_buffer_hdi_impl.h | 42 +++++++++++++++---- display/buffer/v1_0/include/idisplay_buffer.h | 2 +- display/buffer/v1_1/BUILD.gn | 3 ++ display/buffer/v1_2/BUILD.gn | 3 ++ display/bundle.json | 3 ++ display/display_config.gni | 22 ++++++++++ 7 files changed, 68 insertions(+), 10 deletions(-) create mode 100644 display/display_config.gni diff --git a/display/buffer/v1_0/BUILD.gn b/display/buffer/v1_0/BUILD.gn index 249dec9c..9a08183f 100644 --- a/display/buffer/v1_0/BUILD.gn +++ b/display/buffer/v1_0/BUILD.gn @@ -12,6 +12,7 @@ # limitations under the License. import("//build/config/components/hdi/hdi.gni") +import("./../../display_config.gni") hdi("display_buffer") { module_name = "display_buffer" @@ -39,6 +40,8 @@ config("libdisplay_buffer_hdi_impl_config") { } ohos_shared_library("libdisplay_buffer_hdi_impl") { + defines = [] + defines += display_defines sources = [ "hdi_impl/display_buffer_hdi_impl.cpp" ] public_configs = [ ":libdisplay_buffer_hdi_impl_config" ] 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..3c14d75c 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,12 @@ public: explicit DisplayBufferHdiImpl(bool isAllocLocal = false) : allocator_(nullptr), mapper_(nullptr), recipient_(nullptr) { +#ifndef DISPLAY_COMMUNITY while ((allocator_ = IAllocator::Get(isAllocLocal)) == nullptr) { // Waiting for allocator service ready usleep(WAIT_TIME_INTERVAL); } +#endif while ((mapper_ = IMapper::Get(true)) == nullptr) { // Waiting for mapper IF ready usleep(WAIT_TIME_INTERVAL); @@ -86,15 +88,18 @@ public: } virtual ~DisplayBufferHdiImpl() { - if (recipient_ != nullptr) { - sptr remoteObj = OHOS::HDI::hdi_objcast(allocator_); - remoteObj->RemoveDeathRecipient(recipient_); - recipient_ = nullptr; + if (allocator_ != nullptr) { + if (recipient_ != nullptr) { + sptr remoteObj = OHOS::HDI::hdi_objcast(allocator_); + remoteObj->RemoveDeathRecipient(recipient_); + recipient_ = nullptr; + } } } bool AddDeathRecipient(const sptr& recipient) override { +#ifndef DISPLAY_COMMUNITY 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", @@ -109,20 +114,38 @@ public: HDF_LOGE("%{public}s: AddDeathRecipient failed %{public}d", __func__, __LINE__); } return ret; +#else + recipient_ = recipient; + return true; +#endif } bool RemoveDeathRecipient() override { - if (recipient_ != nullptr) { - sptr remoteObj = OHOS::HDI::hdi_objcast(allocator_); - remoteObj->RemoveDeathRecipient(recipient_); - recipient_ = nullptr; + if (allocator_ != nullptr) { + if (recipient_ != 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 { +#ifdef DISPLAY_COMMUNITY + if (allocator_ == nullptr) { + std::lock_guard lock(mutex_); + while (allocator_ == nullptr) { + allocator_ = IAllocator::Get(false); + } + } + + CHECK_NULLPOINTER_RETURN_VALUE(allocator_, HDF_FAILURE); + sptr remoteObj = OHOS::HDI::hdi_objcast(allocator_); + remoteObj->AddDeathRecipient(recipient_); +#endif CHECK_NULLPOINTER_RETURN_VALUE(allocator_, HDF_FAILURE); sptr hdiBuffer; int32_t ret = allocator_->AllocMem(info, hdiBuffer); @@ -201,6 +224,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. diff --git a/display/buffer/v1_1/BUILD.gn b/display/buffer/v1_1/BUILD.gn index 8dbaae28..95e035ac 100644 --- a/display/buffer/v1_1/BUILD.gn +++ b/display/buffer/v1_1/BUILD.gn @@ -12,6 +12,7 @@ # limitations under the License. import("//build/config/components/hdi/hdi.gni") +import("./../../display_config.gni") hdi("display_buffer") { module_name = "display_buffer" @@ -34,6 +35,8 @@ config("libdisplay_buffer_hdi_impl_config") { } ohos_shared_library("libdisplay_buffer_hdi_impl_v1_1") { + defines = [] + defines += display_defines sources = [ "../v1_0/hdi_impl/display_buffer_hdi_impl.cpp", "./hdi_impl/display_buffer_hdi_impl.cpp", diff --git a/display/buffer/v1_2/BUILD.gn b/display/buffer/v1_2/BUILD.gn index f3975441..fbe95d3c 100644 --- a/display/buffer/v1_2/BUILD.gn +++ b/display/buffer/v1_2/BUILD.gn @@ -12,6 +12,7 @@ # limitations under the License. import("//build/config/components/hdi/hdi.gni") +import("./../../display_config.gni") hdi("display_buffer") { module_name = "display_buffer" @@ -38,6 +39,8 @@ config("libdisplay_buffer_hdi_impl_config") { } ohos_shared_library("libdisplay_buffer_hdi_impl_v1_2") { + defines = [] + defines += display_defines sources = [ "../v1_0/hdi_impl/display_buffer_hdi_impl.cpp", "../v1_1/hdi_impl/display_buffer_hdi_impl.cpp", diff --git a/display/bundle.json b/display/bundle.json index 1113e9cb..3e696e72 100644 --- a/display/bundle.json +++ b/display/bundle.json @@ -25,6 +25,9 @@ ], "rom": "700KB", "ram": "1MB", + "features": [ + "drivers_interface_display_community" + ], "deps": { "components": [ "hdf_core", diff --git a/display/display_config.gni b/display/display_config.gni new file mode 100644 index 00000000..b03f11c5 --- /dev/null +++ b/display/display_config.gni @@ -0,0 +1,22 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +declare_args() { + drivers_interface_display_community = false +} + +if (drivers_interface_display_community) { + display_defines = [ "DISPLAY_COMMUNITY" ] +} else { + display_defines = [] +} -- Gitee