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..876837b5c2cbe600f132e2e4158fb10b7b2f13e4 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 @@ -65,6 +65,8 @@ } while (0) #endif +static pthread_rwlock_t g_rwLock = PTHREAD_RWLOCK_INITIALIZER; + namespace OHOS { namespace HDI { namespace Display { @@ -72,6 +74,7 @@ namespace Buffer { namespace V1_0 { template +#ifndef DISPLAY_COMMUNITY class DisplayBufferHdiImpl : public Interface { public: explicit DisplayBufferHdiImpl(bool isAllocLocal = false) : allocator_(nullptr), @@ -205,6 +208,159 @@ protected: sptr mapper_; sptr recipient_; }; +#else +class DisplayBufferHdiImpl : public Interface { +public: + explicit DisplayBufferHdiImpl(bool isAllocLocal = false) : allocator_(nullptr), + mapper_(nullptr), recipient_(nullptr) + { + while ((mapper_ = IMapper::Get(true)) == nullptr) { + // Waiting for mapper IF ready + usleep(WAIT_TIME_INTERVAL); + } + } + virtual ~DisplayBufferHdiImpl() + { + pthread_rwlock_wrlock(&g_rwLock); + if (allocator_ != nullptr) { + if (recipient_ != nullptr) { + sptr remoteObj = OHOS::HDI::hdi_objcast(allocator_); + remoteObj->RemoveDeathRecipient(recipient_); + recipient_ = nullptr; + } + } + pthread_rwlock_unlock(&g_rwLock); + } + + bool AddDeathRecipient(const sptr& recipient) override + { + pthread_rwlock_wrlock(&g_rwLock); + recipient_ = recipient; + pthread_rwlock_unlock(&g_rwLock); + return true; + } + + bool RemoveDeathRecipient() override + { + pthread_rwlock_wrlock(&g_rwLock); + if (allocator_ != nullptr) { + if (recipient_ != nullptr) { + sptr remoteObj = OHOS::HDI::hdi_objcast(allocator_); + remoteObj->RemoveDeathRecipient(recipient_); + recipient_ = nullptr; + } + } + pthread_rwlock_unlock(&g_rwLock); + return true; + } + + int32_t AllocMem(const AllocInfo& info, BufferHandle*& handle) override + { + HdfTrace traceAlloc(__func__, "HDI:DISP:ENTER:"); + if (allocator_ == nullptr) { + pthread_rwlock_wrlock(&g_rwLock); + if (allocator_ == nullptr) { + while ((allocator_ = IAllocator::Get(false)) == nullptr) { + // Waiting for allocator service ready + HDF_LOGI("Waiting for allocator service ready!"); + usleep(WAIT_TIME_INTERVAL); + } + } + pthread_rwlock_unlock(&g_rwLock); + } + + pthread_rwlock_rdlock(&g_rwLock); + if (allocator_ == nullptr) { + pthread_rwlock_unlock(&g_rwLock); + return HDF_FAILURE; + } + + sptr remoteObj = OHOS::HDI::hdi_objcast(allocator_); + remoteObj->AddDeathRecipient(recipient_); + + DISPLAY_TRACE; + CHECK_NULLPOINTER_RETURN_VALUE(allocator_, HDF_FAILURE); + sptr hdiBuffer; + int32_t ret = allocator_->AllocMem(info, hdiBuffer); + if ((ret == HDF_SUCCESS) && (hdiBuffer != nullptr)) { + handle = hdiBuffer->Move(); + } else { + handle = nullptr; + if (ret == HDF_SUCCESS) { + ret = HDF_FAILURE; + } + HDF_LOGE("%{public}s: AllocMem error", __func__); + } + pthread_rwlock_unlock(&g_rwLock); + return ret; + } + + void FreeMem(const BufferHandle& handle) const override + { + CHECK_NULLPOINTER_RETURN(mapper_); + sptr hdiBuffer = new NativeBuffer(); + CHECK_NULLPOINTER_RETURN(hdiBuffer); + hdiBuffer->SetBufferHandle(const_cast(&handle), true); + mapper_->FreeMem(hdiBuffer); + } + + void *Mmap(const BufferHandle& handle) const override + { + CHECK_NULLPOINTER_RETURN_VALUE(mapper_, nullptr); + sptr hdiBuffer = new NativeBuffer(); + CHECK_NULLPOINTER_RETURN_VALUE(hdiBuffer, nullptr); + hdiBuffer->SetBufferHandle(const_cast(&handle)); + int32_t ret = mapper_->Mmap(hdiBuffer); + void *virAddr = (ret == HDF_SUCCESS ? handle.virAddr : nullptr); + return virAddr; + } + + int32_t Unmap(const BufferHandle& handle) const override + { + CHECK_NULLPOINTER_RETURN_VALUE(mapper_, HDF_FAILURE); + sptr hdiBuffer = new NativeBuffer(); + CHECK_NULLPOINTER_RETURN_VALUE(hdiBuffer, HDF_FAILURE); + hdiBuffer->SetBufferHandle(const_cast(&handle)); + int32_t ret = mapper_->Unmap(hdiBuffer); + return ret; + } + + int32_t FlushCache(const BufferHandle& handle) const override + { + CHECK_NULLPOINTER_RETURN_VALUE(mapper_, HDF_FAILURE); + sptr hdiBuffer = new NativeBuffer(); + CHECK_NULLPOINTER_RETURN_VALUE(hdiBuffer, HDF_FAILURE); + hdiBuffer->SetBufferHandle(const_cast(&handle)); + int32_t ret = mapper_->FlushCache(hdiBuffer); + return ret; + } + + int32_t InvalidateCache(const BufferHandle& handle) const override + { + CHECK_NULLPOINTER_RETURN_VALUE(mapper_, HDF_FAILURE); + sptr hdiBuffer = new NativeBuffer(); + CHECK_NULLPOINTER_RETURN_VALUE(hdiBuffer, HDF_FAILURE); + hdiBuffer->SetBufferHandle(const_cast(&handle)); + int32_t ret = mapper_->InvalidateCache(hdiBuffer); + return ret; + } + + int32_t IsSupportedAlloc(const std::vector& infos, + std::vector& supporteds) const override + { + (void)infos; + (void)supporteds; + return HDF_ERR_NOT_SUPPORT; + } + +protected: + static constexpr uint32_t WAIT_TIME_INTERVAL = 10000; + sptr allocator_; + sptr mapper_; + sptr recipient_; + std::mutex mutex_; +}; +#endif using HdiDisplayBufferImpl = DisplayBufferHdiImpl; } // namespace V1_0 } // namespace Buffer diff --git a/display/buffer/v1_0/include/idisplay_buffer.h b/display/buffer/v1_0/include/idisplay_buffer.h index b51a5f9bef785f8e6ccd10fdd02f43d8dc1bf436..9b682631fd88a95251110df17784f565347596ad 100644 --- a/display/buffer/v1_0/include/idisplay_buffer.h +++ b/display/buffer/v1_0/include/idisplay_buffer.h @@ -53,7 +53,11 @@ public: * @since 4.0 * @version 1.0 */ +#ifndef DISPLAY_COMMUNITY virtual int32_t AllocMem(const AllocInfo& info, BufferHandle*& handle) const = 0; +#else + virtual int32_t AllocMem(const AllocInfo& info, BufferHandle*& handle) = 0; +#endif /** * @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 76a2a3b4904b94c1af2d7b4ba17a6afe01e7da01..a630e1f7f1f4a2b066a2bd4157c83dc739810555 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 = [] +}