diff --git a/display/buffer/v1_0/BUILD.gn b/display/buffer/v1_0/BUILD.gn index ff5d1fbe620ec5798076bd6c824fb8122dfce733..89fbda61ddbbe75e895932124c87c9e43f007344 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 a7db5c20e921175ef6862009fe8d28e5409d42c2..419e6cb14ccb2d004b80597558892895d207d787 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 @@ -77,10 +77,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); @@ -88,15 +90,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", @@ -111,20 +116,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 DISPLAY_TRACE; CHECK_NULLPOINTER_RETURN_VALUE(allocator_, HDF_FAILURE); sptr hdiBuffer; @@ -204,6 +227,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 b51a5f9bef785f8e6ccd10fdd02f43d8dc1bf436..f6c76db0d2d42d3aba3b12ea33a54d76b1c65070 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 ff4b53d7e87f3e30f7d49eb0b88c708254cb4b11..1d9e0a5dc1fdad10f114b38b1eb21f6a5215cbc2 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 0e6530855c1e46acbc568ba3b039b4fd0dfd160c..4f55dac588fe3761fe31e4d2209802c0c6319ff5 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 1113e9cb409d057978d419c53b4d03001717ea1a..3e696e72f0232ab875ba6aeb3ded98fa13a4b93c 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 0000000000000000000000000000000000000000..b03f11c5fc97ea099cf1e2a216f6fab70b64c82b --- /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 = [] +}