From 8bd972b78bb055208540db738493bc65a02fa618 Mon Sep 17 00:00:00 2001 From: liuxk Date: Fri, 22 Jul 2022 10:55:50 +0800 Subject: [PATCH] Grall and display interface standardlized Signed-off-by: liuxk --- display/BUILD.gn | 24 + .../.buffer_handle_parcelable.cpp.swp | Bin 0 -> 24576 bytes display/buffersequence/BUILD.gn | 52 ++ .../buffer_handle_parcelable.cpp | 278 ++++++++ .../buffersequence/buffer_handle_parcelable.h | 56 ++ display/bundle.json | 22 +- display/command_pack/command_data_packer.h | 230 ++++++ display/command_pack/command_data_unpacker.h | 187 +++++ display/hdifdsequence/BUILD.gn | 53 ++ display/hdifdsequence/hdifd_parcelable.cpp | 155 ++++ display/hdifdsequence/hdifd_parcelable.h | 54 ++ display/include/display_common.h | 35 + display/include/display_gfx.h | 201 ++++++ display/include/display_gralloc.h | 207 ++++++ display/include/display_log.h | 127 ++++ display/v1_0/.HdiDisplayDeviceType.idl.swp | Bin 0 -> 16384 bytes display/v1_0/BUILD.gn | 42 ++ display/v1_0/HdiDisplayDeviceType.idl | 445 ++++++++++++ display/v1_0/IDisplayDevice.idl | 58 ++ display/v1_0/IHotPlugCallback.idl | 22 + display/v1_0/IRefreshCallback.idl | 22 + display/v1_0/IVBlankCallback.idl | 22 + .../display_command/display_cmd_requester.h | 610 ++++++++++++++++ .../display_command/display_cmd_responser.h | 675 ++++++++++++++++++ .../v1_0/display_command/display_cmd_utils.h | 333 +++++++++ .../hdi_impl/.display_device_hdi_impl.h.swp | Bin 0 -> 16384 bytes .../v1_0/hdi_impl/display_device_hdi_impl.h | 332 +++++++++ .../v1_0/include/idisplay_device_interface.h | 91 +++ gralloc/BUILD.gn | 24 + gralloc/bundle.json | 42 ++ gralloc/v1_0/.BUILD.gn.swp | Bin 0 -> 12288 bytes gralloc/v1_0/BUILD.gn | 76 ++ gralloc/v1_0/GrallocTypes.idl | 32 + gralloc/v1_0/IAllocatorInterface.idl | 24 + gralloc/v1_0/IMapperInterface.idl | 30 + .../v1_0/hdi_impl/.gralloc_hdi_impl.cpp.swp | Bin 0 -> 16384 bytes gralloc/v1_0/hdi_impl/gralloc_hdi_impl.cpp | 116 +++ gralloc/v1_0/hdi_impl/gralloc_hdi_impl.h | 53 ++ .../v1_0/include/.igralloc_interface.h.swp | Bin 0 -> 16384 bytes gralloc/v1_0/include/igralloc_interface.h | 162 +++++ 40 files changed, 4883 insertions(+), 9 deletions(-) create mode 100644 display/BUILD.gn create mode 100644 display/buffersequence/.buffer_handle_parcelable.cpp.swp create mode 100644 display/buffersequence/BUILD.gn create mode 100644 display/buffersequence/buffer_handle_parcelable.cpp create mode 100644 display/buffersequence/buffer_handle_parcelable.h create mode 100644 display/command_pack/command_data_packer.h create mode 100644 display/command_pack/command_data_unpacker.h create mode 100644 display/hdifdsequence/BUILD.gn create mode 100644 display/hdifdsequence/hdifd_parcelable.cpp create mode 100644 display/hdifdsequence/hdifd_parcelable.h create mode 100644 display/include/display_common.h create mode 100644 display/include/display_gfx.h create mode 100644 display/include/display_gralloc.h create mode 100644 display/include/display_log.h create mode 100644 display/v1_0/.HdiDisplayDeviceType.idl.swp create mode 100644 display/v1_0/BUILD.gn create mode 100644 display/v1_0/HdiDisplayDeviceType.idl create mode 100644 display/v1_0/IDisplayDevice.idl create mode 100644 display/v1_0/IHotPlugCallback.idl create mode 100644 display/v1_0/IRefreshCallback.idl create mode 100644 display/v1_0/IVBlankCallback.idl create mode 100644 display/v1_0/display_command/display_cmd_requester.h create mode 100644 display/v1_0/display_command/display_cmd_responser.h create mode 100644 display/v1_0/display_command/display_cmd_utils.h create mode 100644 display/v1_0/hdi_impl/.display_device_hdi_impl.h.swp create mode 100644 display/v1_0/hdi_impl/display_device_hdi_impl.h create mode 100644 display/v1_0/include/idisplay_device_interface.h create mode 100755 gralloc/BUILD.gn create mode 100644 gralloc/bundle.json create mode 100644 gralloc/v1_0/.BUILD.gn.swp create mode 100755 gralloc/v1_0/BUILD.gn create mode 100644 gralloc/v1_0/GrallocTypes.idl create mode 100755 gralloc/v1_0/IAllocatorInterface.idl create mode 100755 gralloc/v1_0/IMapperInterface.idl create mode 100644 gralloc/v1_0/hdi_impl/.gralloc_hdi_impl.cpp.swp create mode 100644 gralloc/v1_0/hdi_impl/gralloc_hdi_impl.cpp create mode 100644 gralloc/v1_0/hdi_impl/gralloc_hdi_impl.h create mode 100644 gralloc/v1_0/include/.igralloc_interface.h.swp create mode 100644 gralloc/v1_0/include/igralloc_interface.h diff --git a/display/BUILD.gn b/display/BUILD.gn new file mode 100644 index 00000000..f7b4135a --- /dev/null +++ b/display/BUILD.gn @@ -0,0 +1,24 @@ +# Copyright (c) 2021 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. + +import("//build/ohos.gni") +import("//vendor/${product_company}/${product_name}/product.gni") + +group("display_device_interface_entry") { + deps = [ + "v1_0:libdisplay_device_proxy_1.0", + "buffersequence:libbufferhandle_parcelable", + "hdifdsequence:libhdifd_parcelable", + ] +} + diff --git a/display/buffersequence/.buffer_handle_parcelable.cpp.swp b/display/buffersequence/.buffer_handle_parcelable.cpp.swp new file mode 100644 index 0000000000000000000000000000000000000000..225c22f217aa00c3627f3ea5b1177471f8cbc182 GIT binary patch literal 24576 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 literal 0 HcmV?d00001 diff --git a/display/buffersequence/BUILD.gn b/display/buffersequence/BUILD.gn new file mode 100644 index 00000000..fe9d0a06 --- /dev/null +++ b/display/buffersequence/BUILD.gn @@ -0,0 +1,52 @@ +# Copyright (C) 2022 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. + +import("//build/ohos.gni") +import("//drivers/hdf_core/adapter/uhdf2/uhdf.gni") + +config("bufferhandle_parcelable_config") { + include_dirs = [ + "//drivers/interface/display/buffersequence", + "//drivers/hdf_core/framework/include/utils", + "//drivers/hdf_core/adapter/uhdf2/osal/include", + "//drivers/peripheral/base", + ] +} + +ohos_shared_library("libbufferhandle_parcelable") { + + sources = [ "buffer_handle_parcelable.cpp" ] + + public_configs = [ ":bufferhandle_parcelable_config" ] + + cflags = [ + "-Wall", + "-Wextra", + "-Werror", + "-fsigned-char", + "-fno-common", + "-fno-strict-aliasing", + ] + + deps = [] + + external_deps = [ + "utils_base:utils", + "ipc:ipc_core", + "hiviewdfx_hilog_native:libhilog", + ] + + install_images = [ chipset_base_dir ] + subsystem_name = "hdf" + part_name = "drivers_interface_display" +} diff --git a/display/buffersequence/buffer_handle_parcelable.cpp b/display/buffersequence/buffer_handle_parcelable.cpp new file mode 100644 index 00000000..5c836fca --- /dev/null +++ b/display/buffersequence/buffer_handle_parcelable.cpp @@ -0,0 +1,278 @@ +/* + * Copyright (c) 2021 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. + */ + +#include "buffer_handle_parcelable.h" +#include +#include +#include + +#include "securec.h" +#include "hdf_log.h" +#include "ipc_file_descriptor.h" + +namespace OHOS { +namespace HDI { +namespace Display { + +BufferHandleParcelable::BufferHandleParcelable() + : init_(false), handle_(nullptr) +{ +} + +BufferHandleParcelable::BufferHandleParcelable(BufferHandle& handle) + : init_(true), handle_(&handle) +{ +} + +BufferHandleParcelable::~BufferHandleParcelable() +{ + if (init_ == false || handle_ == nullptr) { + return; + } + FreeBufferHandle(handle_); +} + +bool BufferHandleParcelable::Init(const BufferHandle& handle) +{ + if (init_ == true) { + HDF_LOGE("bufferhandle parcel have been initialized."); + return false; + } + + size_t handleSize = sizeof(BufferHandle) + (sizeof(int32_t) * + (handle.reserveFds + handle.reserveInts)); + handle_ = static_cast(malloc(handleSize)); + if (handle_ == nullptr) { + HDF_LOGE("InitBufferHandle malloc %zu failed", handleSize); + return false; + } + + if (memcpy_s(handle_, handleSize, &handle, handleSize) != EOK) { + HDF_LOGE("clone bufferhandle failed"); + return false; + } + + if (handle.fd == -1) { + handle_->fd = handle.fd; + } else { + handle_->fd = dup(handle.fd); + if (handle_->fd == -1) { + HDF_LOGE("bufferhandle dup fd failed"); + free(handle_); + return false; + } + } + + for (uint32_t i = 0; i < handle_->reserveFds; i++) { + handle_->reserve[i] = dup(handle.reserve[i]); + if (handle_->reserve[i] == -1) { + FreeBufferHandle(handle_); + HDF_LOGE("%{public}s ReadFileDescriptor reserve failed", __func__); + return false; + } + } + init_ = true; + + return true; +} + +bool BufferHandleParcelable::Marshalling(Parcel& parcel) const +{ + if (!parcel.WriteUint32(handle_->reserveFds) || !parcel.WriteUint32(handle_->reserveInts) || + !parcel.WriteInt32(handle_->width) || !parcel.WriteInt32(handle_->stride) || + !parcel.WriteInt32(handle_->height) || !parcel.WriteInt32(handle_->size) || + !parcel.WriteInt32(handle_->format) || !parcel.WriteInt64(handle_->usage) || + !parcel.WriteUint64(handle_->phyAddr) || !parcel.WriteInt32(handle_->key)) { + HDF_LOGE("%{public}s a lot failed", __func__); + return false; + } + bool validFd = (handle_->fd >= 0); + if (!parcel.WriteBool(validFd)) { + HDF_LOGE("%{public}s parcel.WriteBool failed", __func__); + return false; + } + if (validFd && !WriteFileDescriptor(handle_->fd, parcel)) { + HDF_LOGE("%{public}s parcel.WriteFileDescriptor fd failed", __func__); + return false; + } + + for (uint32_t i = 0; i < handle_->reserveFds; i++) { + if (!WriteFileDescriptor(handle_->reserve[i], parcel)) { + HDF_LOGE("%{public}s parcel.WriteFileDescriptor reserveFds failed", __func__); + return false; + } + } + for (uint32_t j = 0; j < handle_->reserveInts; j++) { + if (!parcel.WriteInt32(handle_->reserve[handle_->reserveFds + j])) { + HDF_LOGE("%{public}s parcel.WriteInt32 reserve failed", __func__); + return false; + } + } + return true; +} + +bool BufferHandleParcelable::ExtractFromParcel(Parcel& parcel) +{ + if (init_ == true) { + HDF_LOGE("bufferhandle parcel have been initialized."); + return false; + } + uint32_t reserveFds = 0; + uint32_t reserveInts = 0; + if (!parcel.ReadUint32(reserveFds) || !parcel.ReadUint32(reserveInts)) { + HDF_LOGE("%{public}s parcel.ReadUint32 reserveFds failed", __func__); + return false; + } + size_t handleSize = sizeof(BufferHandle) + (sizeof(int32_t) * (reserveFds + reserveInts)); + handle_ = static_cast(malloc(handleSize)); + if (handle_ == nullptr) { + HDF_LOGE("BufferHandle malloc %zu failed", handleSize); + return false; + } + handle_->reserveFds = reserveFds; + handle_->reserveInts = reserveInts; + bool validFd = false; + if (!parcel.ReadInt32(handle_->width) || !parcel.ReadInt32(handle_->stride) || !parcel.ReadInt32(handle_->height) || + !parcel.ReadInt32(handle_->size) || !parcel.ReadInt32(handle_->format) || !parcel.ReadUint64(handle_->usage) || + !parcel.ReadUint64(handle_->phyAddr) || !parcel.ReadInt32(handle_->key) || !parcel.ReadBool(validFd)) { + HDF_LOGE("%{public}s parcel read failed", __func__); + return false; + } + handle_->virAddr = 0; + if (validFd) { + handle_->fd = ReadFileDescriptor(parcel); + if (handle_->fd == -1) { + HDF_LOGE("%{public}s ReadFileDescriptor fd failed", __func__); + return false; + } + } + for (uint32_t i = 0; i < handle_->reserveFds; i++) { + handle_->reserve[i] = ReadFileDescriptor(parcel); + if (handle_->reserve[i] == -1) { + FreeBufferHandle(handle_); + HDF_LOGE("%{public}s ReadFileDescriptor reserve failed", __func__); + return false; + } + } + for (uint32_t j = 0; j < handle_->reserveInts; j++) { + if (!parcel.ReadInt32(handle_->reserve[reserveFds + j])) { + FreeBufferHandle(handle_); + HDF_LOGE("%{public}s ReadInt32 reserve failed", __func__); + return false; + } + } + return true; +} + +sptr BufferHandleParcelable::Unmarshalling(Parcel& parcel) +{ + sptr newParcelable = new BufferHandleParcelable(); + bool ret = newParcelable->ExtractFromParcel(parcel); + if (!ret) { + return nullptr; + } else { + newParcelable->init_ = true; + } + return newParcelable; +} + +BufferHandle* BufferHandleParcelable::GetBufferHandle() { + return handle_; +} + +BufferHandle* BufferHandleParcelable::Move() { + BufferHandle* handlePtr = handle_; + handle_ = nullptr; + init_ = false; + return handlePtr; +} + +bool BufferHandleParcelable::WriteFileDescriptor(const int fd, Parcel& parcel) +{ + if (fd < 0) { + return false; + } + int dupFd = dup(fd); + if (dupFd < 0) { + return false; + } + sptr descriptor = new (std::nothrow) IPCFileDescriptor(dupFd); + if (descriptor == nullptr) { + HDF_LOGE("create IPCFileDescriptor object failed"); + return false; + } + return parcel.WriteObject(descriptor); +} + +int BufferHandleParcelable::ReadFileDescriptor(Parcel& parcel) +{ + sptr descriptor = parcel.ReadObject(); + if (descriptor == nullptr) { + return -1; + } + int fd = descriptor->GetFd(); + if (fd < 0) { + return -1; + } + return dup(fd); +} + +void BufferHandleParcelable::FreeBufferHandle(BufferHandle* handle) +{ + if (handle->fd != -1) { + close(handle->fd); + } + for (uint32_t i = 0; i < handle->reserveFds; i++) { + if (handle->reserve[i] != -1) { + close(handle->reserve[i]); + } + } + free(handle); +} + +std::string BufferHandleParcelable::Dump() const +{ + std::stringstream os; + + os << "{"; + os << "fd:" << handle_->fd << ", "; + os << "width:" << handle_->width << ", "; + os << "stride:" << handle_->stride << ", "; + os << "height:" << handle_->height << ", "; + os << "size:" << handle_->size << ", "; + os << "format:" << handle_->format << ", "; + os << "usage:" << handle_->usage << ", "; + os << "phyAddr:" << handle_->phyAddr << ", "; + os << "key:" << handle_->key << ", "; + os << "}\nreserveFds[" << handle_->reserveFds << "]:{"; + + uint32_t i = 0; + for (; i < handle_->reserveFds; i++) { + os << handle_->reserve[i] << ", "; + } + os << "},\nreserveInts[" << handle_->reserveInts << "]:{"; + + uint32_t n = 0; + for (; n < handle_->reserveInts; n++) { + os << handle_->reserve[i + n] << ", "; + } + + os << "}\n"; + + return os.str(); +} +} // Display +} // HDI +} // OHOS diff --git a/display/buffersequence/buffer_handle_parcelable.h b/display/buffersequence/buffer_handle_parcelable.h new file mode 100644 index 00000000..37d749e5 --- /dev/null +++ b/display/buffersequence/buffer_handle_parcelable.h @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2021 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. + */ + +#ifndef OHOS_HDI_BUFFER_HANDLE_PARCELABLE +#define OHOS_HDI_BUFFER_HANDLE_PARCELABLE + +#include +#include +#include +#include "buffer_handle.h" + +namespace OHOS { +namespace HDI { +namespace Display { + +using namespace OHOS; + +class BufferHandleParcelable: public Parcelable { +public: + BufferHandleParcelable(); + BufferHandleParcelable(BufferHandle& handle); + virtual ~BufferHandleParcelable(); + + bool Init(const BufferHandle& handle); + bool ExtractFromParcel(Parcel& parcel); + bool Marshalling(Parcel& parcel) const override; + static sptr Unmarshalling(Parcel& parcel); + BufferHandle* GetBufferHandle(); + BufferHandle* Move(); + std::string Dump() const; + +private: + static bool WriteFileDescriptor(const int fd, Parcel& parcel); + static int ReadFileDescriptor(Parcel& parcel); + static void FreeBufferHandle(BufferHandle* handle); + +private: + bool init_; + BufferHandle* handle_; +}; +} // Display +} // HDI +} // OHOS +#endif // OHOS_HDI_BUFFER_HANDLE_PARCELABLE diff --git a/display/bundle.json b/display/bundle.json index b69e6a25..27b1d0dd 100644 --- a/display/bundle.json +++ b/display/bundle.json @@ -1,6 +1,6 @@ { "name": "drivers_interface_display", - "version": "3.1.0", + "version": "1.0", "description": "display device driver interface", "homePage": "https://gitee.com/openharmony", "license": "Apache License 2.0", @@ -22,23 +22,27 @@ "ram": "1MB", "deps": { "components": [ + "ipc", + "device_driver_framework", + "hiviewdfx_hilog_native", + "utils_base" ], - "third_party": [ + "third_part": [ ] }, "build": { "sub_component": [ - "//drivers/peripheral/display/hdi_service/gralloc/client:hdi_gralloc_client" + "//drivers/interface/display:display_device_interface_entry" + ], + "test": [ ], "inner_kits": [ { - "name": "//drivers/peripheral/display/hdi_service/gralloc/client:hdi_gralloc_client", + "name": "//drivers/interface/display/v1_0:libdisplay_device_proxy_1.0", "header": { - "header_files": [ - "idisplay_gralloc.h", - "parcel_utils.h" - ], - "header_base": "//drivers/peripheral/display/hdi_service/gralloc/include" + "header_files": [ + ], + "header_base": "//drivers/interface/display" } } ] diff --git a/display/command_pack/command_data_packer.h b/display/command_pack/command_data_packer.h new file mode 100644 index 00000000..d08fe634 --- /dev/null +++ b/display/command_pack/command_data_packer.h @@ -0,0 +1,230 @@ +/* + * Copyright (c) 2020-2021 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. + */ + +#ifndef _DISPLAY_DATA_PACKER_H_ +#define _DISPLAY_DATA_PACKER_H_ + +#include +#include +#include "hdf_log.h" + +namespace OHOS { +namespace HDI { +namespace Display { + +class CommandDataPacker { +public: + CommandDataPacker() + : packSize_(0), + writePos_(0), + curSecOffset_(0), + settingSecLen_(0), + curSecLenPos_(0), + data_(nullptr) + { + } + + ~CommandDataPacker() + { + if (data_ != nullptr) { + delete data_; + } + } + + bool Init(size_t size = INIT_DATA_SIZE) + { + bool ret = true; + packSize_ = size; + uint32_t alignedSize = (packSize_ + ALLOC_PAGE_SIZE -1) & (~(ALLOC_PAGE_SIZE - 1)); + data_ = new char[alignedSize](); + if (data_ == nullptr) { + HDF_LOGE("memory alloc failed."); + ret = false; + } else { + packSize_ = alignedSize; + } + return ret; + } + + bool WriteUint64(uint64_t value) + { + return Write(value); + } + + bool WriteUint32(uint32_t value) + { + return Write(value); + } + + bool WriteUint8(uint8_t value) + { + return Write(value); + } + + bool WriteInt32(int32_t value) + { + return Write(value); + } + + bool WriteBool(bool value) + { + return Write(value); + } + + size_t ValidSize() + { + return writePos_; + } + + size_t PackSize() + { + return packSize_; + } + + char* GetDataPtr() + { + return data_; + } + + bool PackBegin(int32_t beginCmd) + { + writePos_ = 0; + settingSecLen_ = 4; + curSecLenPos_ = 0; + curSecOffset_ = writePos_; + return WriteInt32(beginCmd); + } + + bool BeginSection(int32_t cmdId, int32_t len = 0) + { + bool ret = false; + // len must be 4 byte alignment. + if ((len & 3) != 0) { + HDF_LOGE("error: length is not aligned by 4 bytes."); + } else { + ret = true; + } + // Update current data before next section. + if (ret == true) { + curSecOffset_ = writePos_; + if(WriteUint32(SECTION_END_MAGIC) == false) { + ret = false; + } else if (WriteInt32(cmdId) == true) { + curSecLenPos_ = writePos_; + settingSecLen_ = len; + // Now we don't write Section len here, + // but write it on EndSection. + writePos_ += sizeof(uint32_t); + } else { + ret = false; + } + } + return ret; + } + + bool EndSection() + { + // Write cmd len before data related is updated. + if (writePos_ >= curSecOffset_) { + uint32_t actualLen = writePos_ - curSecOffset_; + uint32_t updatedLen = actualLen > settingSecLen_ ? actualLen : settingSecLen_; + *reinterpret_cast(data_ + curSecLenPos_) = updatedLen; + writePos_ = curSecOffset_ + updatedLen; + } else { + HDF_LOGE("error: writePos_(%{public}d) before curSecOffset_(%{public}d).", + writePos_, curSecOffset_); + return false; + } + return (writePos_ >= packSize_ ? false : true); + } + + bool PackEnd(int32_t endCmd) + { + bool ret = WriteInt32(endCmd); + if (writePos_ >= packSize_) { + HDF_LOGE("error: writePos_(%{public}d) > packSize_(%{public}d), write overflow.", + writePos_, curSecOffset_); + ret = false; + } + + return ret; + } + + void Dump() + { + HDF_LOGI("---------------------------------------------\n"); + HDF_LOGI("ALLOC_PAGE_SIZE =%{public}d\n", ALLOC_PAGE_SIZE); + HDF_LOGI("INIT_DATA_SIZE =%{public}d\n", INIT_DATA_SIZE); + HDF_LOGI("SECTION_END_MAGIC =0x%{public}x\n", SECTION_END_MAGIC); + HDF_LOGI("packSize_ =%{public}d\n", packSize_); + HDF_LOGI("writePos_ =%{public}d\n", writePos_); + HDF_LOGI("curSecOffset_ =%{public}d\n", curSecOffset_); + HDF_LOGI("settingSecLen_ =%{public}d\n", settingSecLen_); + HDF_LOGI("curSecLenPos_ =%{public}d\n", curSecLenPos_); + HDF_LOGI("data_ =%{public}p\n", data_); + uint32_t i = 0; + for (; 4*i < writePos_;) { + HDF_LOGI("%{public}08x ", *reinterpret_cast(data_ + 4*i)); + i++; + if (i%8 == 0) { + HDF_LOGI("\n"); + } else if (i%4 == 0) { + HDF_LOGI(" "); + } else {} + } + HDF_LOGI("\n"); + } +private: + template + bool Write(T value) + { + size_t writeSize = sizeof(T); + + size_t newSize = writePos_ + writeSize; + if (newSize > packSize_) { + newSize = (newSize + ALLOC_PAGE_SIZE - 1) & (~(ALLOC_PAGE_SIZE - 1)); + + char* newData = new char[newSize]; + if (memcpy_s(newData, newSize, data_, packSize_) != EOK) { + HDF_LOGE("memcpy_s failed."); + return false; + } + data_ = newData; + packSize_ = newSize; + delete data_; + } + *reinterpret_cast(data_ + writePos_) = value; + writePos_ += writeSize; + + return true; + } + +private: + static constexpr uint32_t ALLOC_PAGE_SIZE = 1024; + static constexpr uint32_t INIT_DATA_SIZE = 32 * ALLOC_PAGE_SIZE; + static constexpr uint32_t SECTION_END_MAGIC = 0xB5B5B5B5; + +private: + size_t packSize_; + size_t writePos_; + size_t curSecOffset_; + uint32_t settingSecLen_; + size_t curSecLenPos_; + char* data_; +}; +} // Display +} // HDI +} // OHOS +#endif diff --git a/display/command_pack/command_data_unpacker.h b/display/command_pack/command_data_unpacker.h new file mode 100644 index 00000000..c9938248 --- /dev/null +++ b/display/command_pack/command_data_unpacker.h @@ -0,0 +1,187 @@ +/* + * Copyright (c) 2020-2021 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. + */ + +#ifndef _COMMAND_DATA_UNPACKER_H_ +#define _COMMAND_DATA_UNPACKER_H_ + +#include +#include "hdf_log.h" + +namespace OHOS { +namespace HDI { +namespace Display { + +class CommandDataUnpacker { +public: + CommandDataUnpacker() + : packSize_(0), + readPos_(0), + curSecOffset_(0), + curSecLen_(0), + data_(nullptr) + { + } + + void Init(char* unpackData, size_t size) + { + packSize_ = size; + data_ = unpackData; + return; + } + + bool ReadUint64(uint64_t& value) + { + return Read(value); + } + + bool ReadUint32(uint32_t& value) + { + return Read(value); + } + + bool ReadUint8(uint8_t& value) + { + int32_t intVal = 0; + bool ret = Read(intVal); + if (ret == true) { + value = static_cast(intVal & 0xFF); + } + + return ret; + } + + bool ReadInt32(int32_t& value) + { + return Read(value); + } + + bool ReadBool(bool& value) + { + int32_t intVal = 0; + bool ret = Read(intVal); + if (ret == true) { + value = (intVal == 0 ? false : true); + } + + return ret; + } + + char* GetDataPtr() + { + return data_; + } + + bool PackBegin(int32_t& beginCmd) + { + readPos_ = 0; + curSecLen_ = 4; + curSecOffset_ = readPos_; + + return ReadInt32(beginCmd); + } + + bool BeginSection(int32_t& cmdId) + { + uint32_t magic; + curSecOffset_ = readPos_; + + bool ret = ReadUint32(magic); + if (ret == true) { + ret = (magic == SECTION_END_MAGIC ? true : false); + } + if (ret == true && !(ReadInt32(cmdId) && ReadUint32(curSecLen_))) { + HDF_LOGE("error: cmdId=%{public}d or curSecLen_=%{public}d error.", + cmdId, curSecLen_); + ret = false; + } + return ret; + } + + bool NextSection() + { + readPos_ = curSecOffset_ + curSecLen_; + bool ret = ((readPos_ >= (packSize_ - COMMAND_ID_SIZE)) ? false : true); + return ret; + } + + bool PackEnd(int32_t& endCmd) + { + bool ret = ReadInt32(endCmd); + if ((ret == true) && (readPos_ == packSize_)) { + ret = true; + } else { + HDF_LOGE("error: readPos_(%{public}d) > packSize_(%{public}d), read overflow.", + readPos_, curSecOffset_); + ret = false; + } + return ret; + } + + void Dump() + { + HDF_LOGI("---------------------------------------------\n"); + HDF_LOGI("SECTION_END_MAGIC =0x%{public}x\n", SECTION_END_MAGIC); + HDF_LOGI("COMMAND_ID_SIZE =%{public}d\n", COMMAND_ID_SIZE); + HDF_LOGI("packSize_ =%{public}d\n", packSize_); + HDF_LOGI("readPos_ =%{public}d\n", readPos_); + HDF_LOGI("curSecOffset_ =%{public}d\n", curSecOffset_); + HDF_LOGI("curSecLen_ =%{public}d\n", curSecLen_); + HDF_LOGI("data_ =%{public}p\n", data_); + uint32_t i = 0; + for (; 4*i < packSize_;) { + HDF_LOGI("%{public}08x ", *reinterpret_cast(data_ + 4*i)); + i++; + if (i%8 == 0) { + HDF_LOGI("\n"); + } else if (i%4 == 0) { + HDF_LOGI(" "); + } else {} + } + HDF_LOGI("\n"); + } + +private: + template + bool Read(T& value) + { + size_t dataSize = sizeof(T); + + if (readPos_ + dataSize > packSize_) { + HDF_LOGE("Read overflow, readPos=%{public}d + %{public}d}, packSize=%{public}d.", + readPos_, dataSize, packSize_); + return false; + } + + value = *reinterpret_cast(data_ + readPos_); + readPos_ += dataSize; + + return true; + } + +private: + static constexpr uint32_t SECTION_END_MAGIC = 0xB5B5B5B5; + static constexpr uint32_t COMMAND_ID_SIZE = sizeof(int32_t); + +private: + size_t packSize_; + size_t readPos_; + size_t curSecOffset_; + uint32_t curSecLen_; + char* data_; +}; +} // Display +} // HDI +} // OHOS +#endif diff --git a/display/hdifdsequence/BUILD.gn b/display/hdifdsequence/BUILD.gn new file mode 100644 index 00000000..ae5ded62 --- /dev/null +++ b/display/hdifdsequence/BUILD.gn @@ -0,0 +1,53 @@ +# Copyright (C) 2022 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. + +import("//build/ohos.gni") +import("//drivers/hdf_core/adapter/uhdf2/uhdf.gni") + +config("hdifd_parcelable_config") { + include_dirs = [ + "//drivers/interface/display/hdifdsequence", + "//drivers/hdf_core/framework/include/utils", + "//drivers/hdf_core/adapter/uhdf2/osal/include", + "//drivers/peripheral/base", + ] +} + +ohos_shared_library("libhdifd_parcelable") { + + sources = [ "hdifd_parcelable.cpp" ] + + public_configs = [ ":hdifd_parcelable_config" ] + + cflags = [ + "-Wall", + "-Wextra", + "-Werror", + "-fsigned-char", + "-fno-common", + "-fno-strict-aliasing", + ] + + deps = [ + ] + + external_deps = [ + "utils_base:utils", + "ipc:ipc_core", + "hiviewdfx_hilog_native:libhilog", + ] + + install_images = [ chipset_base_dir ] + subsystem_name = "hdf" + part_name = "drivers_interface_display" +} diff --git a/display/hdifdsequence/hdifd_parcelable.cpp b/display/hdifdsequence/hdifd_parcelable.cpp new file mode 100644 index 00000000..f29a9f26 --- /dev/null +++ b/display/hdifdsequence/hdifd_parcelable.cpp @@ -0,0 +1,155 @@ +/* + * Copyright (c) 2021 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. + */ + +#include "hdifd_parcelable.h" +#include +#include +#include + +#include "securec.h" +#include "hdf_log.h" +#include "ipc_file_descriptor.h" + +namespace OHOS { +namespace HDI { +namespace Display { + +HdifdParcelable::HdifdParcelable() + : init_(false), hdiFd_(-1) +{ +} + +HdifdParcelable::HdifdParcelable(int32_t fd) + : init_(true), hdiFd_(fd) +{ +} + +HdifdParcelable::~HdifdParcelable() +{ + if ((init_ != false) && (hdiFd_ != -1)) { + close(hdiFd_); + } +} + +bool HdifdParcelable::Init(int32_t fd) +{ + bool ret = true; + + if (init_ == true) { + HDF_LOGE("fd parcelable have been initialized."); + ret = false; + } else { + if (fd < 0) { + hdiFd_ = -1; + } else { + hdiFd_ = dup(fd); + ret = (hdiFd_ < 0) ? false : true; + } + if (ret == false) + { + return ret; + } + init_ = true; + } + + return ret; +} + +bool HdifdParcelable::WriteFileDescriptor(const int fd, Parcel& parcel) +{ + if (fd < 0) { + return false; + } + int dupFd = dup(fd); + if (dupFd < 0) { + return false; + } + + sptr descriptor = new (std::nothrow) IPCFileDescriptor(dupFd); + if (descriptor == nullptr) { + HDF_LOGE("create IPCFileDescriptor object failed"); + return false; + } + return parcel.WriteObject(descriptor); +} + +int HdifdParcelable::ReadFileDescriptor(Parcel& parcel) +{ + sptr descriptor = parcel.ReadObject(); + if (descriptor == nullptr) { + return -1; + } + int fd = descriptor->GetFd(); + if (fd < 0) { + return -1; + } + return dup(fd); +} + +bool HdifdParcelable::Marshalling(Parcel& parcel) const +{ + bool validFlag = (hdiFd_ >= 0); + if (!parcel.WriteBool(validFlag)) { + HDF_LOGE("%{public}s parcel.WriteBool failed", __func__); + return false; + } + if (validFlag && !WriteFileDescriptor(hdiFd_, parcel)) { + HDF_LOGE("%{public}s parcel.WriteFileDescriptor fd failed", __func__); + return false; + } + return true; +} + +sptr HdifdParcelable::Unmarshalling(Parcel& parcel) +{ + bool validFlag = false; + if (!parcel.ReadBool(validFlag)) { + HDF_LOGE("%{public}s ReadBool validFlag failed", __func__); + return nullptr; + } + int32_t fd = -1; + if (validFlag) { + fd = ReadFileDescriptor(parcel); + if (fd < 0) { + HDF_LOGE("%{public}s ReadFileDescriptor fd failed", __func__); + return nullptr; + } + } + sptr newParcelable = new HdifdParcelable(fd); + //newParcelable->Init(fd); + newParcelable->init_ = true; + return newParcelable; +} + +int32_t HdifdParcelable::GetFd() { + return hdiFd_; +} + +int32_t HdifdParcelable::Move() { + init_ = false; + return hdiFd_; +} + +std::string HdifdParcelable::Dump() const +{ + std::stringstream os; + + os << "fd: {" << hdiFd_ << "}\n"; + + return os.str(); +} +} // Display +} // HDI +} // OHOS diff --git a/display/hdifdsequence/hdifd_parcelable.h b/display/hdifdsequence/hdifd_parcelable.h new file mode 100644 index 00000000..54ec2ba7 --- /dev/null +++ b/display/hdifdsequence/hdifd_parcelable.h @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2021 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. + */ + +#ifndef OHOS_HDI_HDIFD_PARCELABLE +#define OHOS_HDI_HDIFD_PARCELABLE + +#include +#include +#include +#include "buffer_handle.h" + +namespace OHOS { +namespace HDI { +namespace Display { + +using namespace OHOS; + +class HdifdParcelable : public Parcelable { +public: + HdifdParcelable(); + HdifdParcelable(int32_t fd); + virtual ~HdifdParcelable(); + + bool Init(int32_t fd); + bool Marshalling(Parcel& parcel) const override; + static sptr Unmarshalling(Parcel& parcel); + int32_t Move(); + int32_t GetFd(); + std::string Dump() const; + +private: + static bool WriteFileDescriptor(const int fd, Parcel& parcel); + static int ReadFileDescriptor(Parcel& parcel); + +private: + bool init_; + int32_t hdiFd_; +}; +} // Display +} // HDI +} // OHOS +#endif // OHOS_HDI_HDIFD_PARCELABLE diff --git a/display/include/display_common.h b/display/include/display_common.h new file mode 100644 index 00000000..a4af760f --- /dev/null +++ b/display/include/display_common.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2021 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. + */ + +#ifndef DISPLAY_COMMON_H +#define DISPLAY_COMMON_H + +#include + +namespace OHOS { +namespace HDI { +namespace Display { + +typedef void (*HotPlugCallback)(uint32_t devId, bool connected, void *data); +typedef void (*VBlankCallback)(unsigned int sequence, uint64_t ns, void *data); +typedef void (*RefreshCallback)(uint32_t devId, void *data); +//typedef std::function HotPlugCallback; +//typedef std::function VBlankCallback; +//typedef std::function RefreshCallback; + +} // Display +} // HDI +} // OHOS +#endif /* DISPLAY_COMMON_H */ diff --git a/display/include/display_gfx.h b/display/include/display_gfx.h new file mode 100644 index 00000000..446151ba --- /dev/null +++ b/display/include/display_gfx.h @@ -0,0 +1,201 @@ +/* + * Copyright (c) 2020-2021 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. + */ + +/** + * @addtogroup Display + * @{ + * + * @brief Defines driver functions of the display module. + * + * This module provides driver functions for the graphics subsystem, including graphics layer management, + * device control, graphics hardware acceleration, display memory management, and callbacks. + * + * @since 1.0 + * @version 2.0 + */ + +/** + * @file display_gfx.h + * + * @brief Declares the driver functions for implementing hardware acceleration. + * + * @since 1.0 + * @version 1.0 + */ + +#ifndef DISPLAY_GFX_H +#define DISPLAY_GFX_H +#include "v1_0/hdi_display_device_type.h" + +#ifdef __cplusplus +namespace OHOS { +namespace HDI { +namespace Display { +using namespace OHOS::HDI::Display::V1_0; + +extern "C" { +#endif +/** + * @brief Defines pointers to the hardware acceleration driver functions. + */ +typedef struct { + /** + * @brief Initializes hardware acceleration. + * + * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} + * otherwise. + * @see DeinitGfx + * @since 1.0 + * @version 1.0 + */ + int32_t (*InitGfx)(void); + + /** + * @brief Deinitializes hardware acceleration. + * + * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} + * otherwise. + * @see InitGfx + * @since 1.0 + * @version 1.0 + */ + int32_t (*DeinitGfx)(void); + + /** + * @brief Fills a rectangle with a given color on the canvas. + * + * @param surface Indicates the pointer to the canvas. + * @param rect Indicates the pointer to the rectangle to fill. + * @param color Indicates the color to fill. + * @param opt Indicates the pointer to the hardware acceleration option. + * + * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} + * otherwise. + * @since 1.0 + * @version 1.0 + */ + int32_t (*FillRect)(ISurface *surface, IRect *rect, uint32_t color, GfxOpt *opt); + + /** + * @brief Draws a rectangle with a given color on the canvas. + * + * @param surface Indicates the pointer to the canvas. + * @param rect Indicates the pointer to the rectangle to draw. + * @param color Indicates the color to draw. + * @param opt Indicates the pointer to the hardware acceleration option. + * + * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} + * otherwise. + * @since 1.0 + * @version 1.0 + */ + int32_t (*DrawRectangle)(ISurface *surface, Rectangle *rect, uint32_t color, GfxOpt *opt); + + /** + * @brief Draws a straight line with a given color on the canvas. + * + * @param surface Indicates the pointer to the canvas. + * @param line Indicates the pointer to the line to draw. + * @param opt Indicates the pointer to the hardware acceleration option. + * + * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} + * otherwise. + * @since 1.0 + * @version 1.0 + */ + int32_t (*DrawLine)(ISurface *surface, ILine *line, GfxOpt *opt); + + /** + * @brief Draws a circle with a specified center and radius on the canvas using a given color. + * + * @param surface Indicates the pointer to the canvas. + * @param circle Indicates the pointer to the circle to draw. + * @param opt Indicates the pointer to the hardware acceleration option. + * + * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} + * otherwise. + * @since 1.0 + * @version 1.0 + */ + int32_t (*DrawCircle)(ISurface *surface, ICircle *circle, GfxOpt *opt); + + /** + * @brief Blits bitmaps. + * + * During bit blit, color space conversion (CSC), scaling, and rotation can be implemented. + * + * @param srcSurface Indicates the pointer to the source bitmap. + * @param srcRect Indicates the pointer to the rectangle of the source bitmap. + * @param dstSurface Indicates the pointer to the destination bitmap. + * @param dstRect Indicates the pointer to the rectangle of the destination bitmap. + * @param opt Indicates the pointer to the hardware acceleration option. + * + * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} + * otherwise. + * @since 1.0 + * @version 1.0 + */ + int32_t (*Blit)(ISurface *srcSurface, IRect *srcRect, ISurface *dstSurface, IRect *dstRect, GfxOpt *opt); + + /** + * @brief Synchronizes hardware acceleration when it is used to draw and blit bitmaps. + * + * This function blocks the process until hardware acceleration is complete. + * + * @param timeOut Indicates the timeout duration for hardware acceleration synchronization. The value 0 + * indicates no timeout, so the process waits until hardware acceleration is complete. + * + * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} + * otherwise. + * @since 1.0 + * @version 1.0 + */ + int32_t (*Sync)(int32_t timeOut); +} GfxFuncs; + +/** + * @brief Initializes the hardware acceleration module to obtain the pointer to functions for hardware acceleration + * operations. + * + * @param funcs Indicates the double pointer to functions for hardware acceleration operations. Memory is allocated + * automatically when you initiate the hardware acceleration module, so you can simply use the pointer to gain access + * to the functions. + * + * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} + * otherwise. + * @since 1.0 + * @version 1.0 + */ +int32_t GfxInitialize(GfxFuncs **funcs); + +/** + * @brief Deinitializes the hardware acceleration module to release the pointer to functions for hardware + * acceleration operations. + * + * @param funcs Indicates the pointer to the functions for hardware acceleration operations. + * + * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} + * otherwise. + * @since 1.0 + * @version 1.0 + */ +int32_t GfxUninitialize(GfxFuncs *funcs); + +} +} // Display +} // HDI +} // OHOS +#endif +/** @} */ diff --git a/display/include/display_gralloc.h b/display/include/display_gralloc.h new file mode 100644 index 00000000..a3f402fa --- /dev/null +++ b/display/include/display_gralloc.h @@ -0,0 +1,207 @@ +/* + * Copyright (c) 2020-2021 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. + */ + +/** + * @addtogroup Display + * @{ + * + * @brief Defines driver functions of the display module. + * + * This module provides driver functions for the graphics subsystem, including graphics layer management, + * device control, graphics hardware acceleration, display memory management, and callbacks. + * @since 1.0 + * @version 2.0 + */ + + +/** + * @file display_gralloc.h + * + * @brief Declares the driver functions for memory. + * + * @since 1.0 + * @version 2.0 + */ + +#ifndef DISPLAY_GRALLOC_H +#define DISPLAY_GRALLOC_H +#include "v1_0/hdi_display_device_type.h" + +#ifdef __cplusplus +namespace OHOS { +namespace HDI { +namespace Display { +using namespace OHOS::HDI::Display::V1_0; + +extern "C" { +#endif + +/** + * @brief Defines pointers to the memory driver functions. + */ +typedef struct { + /** + * @brief Allocates memory based on the parameters passed by the GUI. + * + * @param info Indicates the pointer to the description info of the memory to allocate. + * + * @param handle Indicates the double pointer to the buffer of the memory to allocate. + * + * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} + * otherwise. + * @since 1.0 + * @version 1.0 + */ + int32_t (*AllocMem)(const AllocInfo* info, BufferHandle** handle); + + /** + * @brief Releases memory. + * + * @param handle Indicates the pointer to the buffer of the memory to release. + * + * @since 1.0 + * @version 1.0 + */ + void (*FreeMem)(BufferHandle *handle); + + /** + * @brief Maps memory to memory without cache in the process's address space. + * + * @param handle Indicates the pointer to the buffer of the memory to map. + * + * @return Returns the pointer to a valid address if the operation is successful; returns NULL otherwise. + * @since 1.0 + * @version 1.0 + */ + void *(*Mmap)(BufferHandle *handle); + + /** + * @brief Maps memory for YUV. + * + * @param handle Indicates the pointer to the buffer of the memory to map. + * @param info Indicates the pointer to the YUVDescInfo of the memory to map. + * + * @return Returns the pointer to a valid address if the operation is successful; returns NULL otherwise. + * @since 3.2 + * @version 1.0 + */ + void *(*MmapYUV)(BufferHandle *handle, YUVDescInfo *info); + + /** + * @brief Maps memory to memory with cache in the process's address space. + * + * @param handle Indicates the pointer to the buffer of the memory to map. + * + * @return Returns the pointer to a valid address if the operation is successful; returns NULL otherwise. + * @since 1.0 + * @version 1.0 + */ + void *(*MmapCache)(BufferHandle *handle); + + /** + * @brief Unmaps memory, that is, removes any mappings from the process's address space. + * + * @param handle Indicates the pointer to the buffer of the memory to unmap. + * + * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} + * otherwise. + * @since 1.0 + * @version 1.0 + */ + int32_t (*Unmap)(BufferHandle *handle); + + /** + * @brief Flushes data from the cache to memory and invalidates the data in the cache. + * + * @param handle Indicates the pointer to the buffer of the cache to flush. + * + * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} + * otherwise. + * @since 1.0 + * @version 1.0 + */ + int32_t (*FlushCache)(BufferHandle *handle); + + /** + * @brief Flushes data from the cache mapped via {@link Mmap} to memory and invalidates the data in the cache. + * + * @param handle Indicates the pointer to the buffer of the cache to flush. + * + * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} + * otherwise. + * @since 1.0 + * @version 1.0 + */ + int32_t (*FlushMCache)(BufferHandle *handle); + + /** + * @brief Invalidates the cache to update it from memory. + * + * @param handle Indicates the pointer to the buffer of the cache, which will been invalidated. + * + * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} + * otherwise. + * @since 1.0 + * @version 1.0 + */ + int32_t (*InvalidateCache)(BufferHandle* handle); + + /** + * @brief Checks whether the given VerifyAllocInfo array is allocatable. + * + * @param num Indicates the size of infos array. + * @param infos Indicates the pointer to the VerifyAllocInfo array. + * @param supporteds Indicates the pointer to the array that can be allocated. + * + * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} + * otherwise. + * @since 1.0 + * @version 1.0 + */ + int32_t (*IsSupportedAlloc)(uint32_t num, const VerifyAllocInfo *infos, bool *supporteds); +} GrallocFuncs; + +/** + * @brief Initializes the memory module to obtain the pointer to functions for memory operations. + * + * @param funcs Indicates the double pointer to functions for memory operations. Memory is allocated automatically when + * you initiate the memory module initialization, so you can simply use the pointer to gain access to the functions. + * + * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} + * otherwise. + * @since 1.0 + * @version 1.0 + */ +int32_t GrallocInitialize(GrallocFuncs **funcs); + +/** + * @brief Deinitializes the memory module to release the memory allocated to the pointer to functions for memory + * operations. + * + * @param funcs Indicates the pointer to functions for memory operations. + * + * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} + * otherwise. + * @since 1.0 + * @version 1.0 + */ +int32_t GrallocUninitialize(GrallocFuncs *funcs); + +} +} // Display +} // HDI +} // OHOS +#endif +/** @} */ diff --git a/display/include/display_log.h b/display/include/display_log.h new file mode 100644 index 00000000..b4a09b77 --- /dev/null +++ b/display/include/display_log.h @@ -0,0 +1,127 @@ +/* + * Copyright (c) 2021 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. + */ + +#ifndef DISPLAY_LOG_H +#define DISPLAY_LOG_H +#include +#include +#include "hilog/log.h" +#include "stdio.h" +#ifdef HDF_LOG_TAG +#undef HDF_LOG_TAG +#endif + +#if defined(__cplusplus) +extern "C" { +#endif + +#undef LOG_TAG +#undef LOG_DOMAIN +#define LOG_TAG "DISP" +#define LOG_DOMAIN 0xD001400 + +#ifndef DISPLAY_UNUSED +#define DISPLAY_UNUSED(x) (void)x +#endif + +#define __FILENAME__ (strrchr(__FILE__, '/') ? (strrchr(__FILE__, '/') + 1) : __FILE__) + +#ifndef DISPLAY_DEBUG_ENABLE +#define DISPLAY_DEBUG_ENABLE 1 +#endif + +#ifndef DISPLAY_LOGD +#define DISPLAY_LOGD(format, ...) \ + do { \ + if (DISPLAY_DEBUG_ENABLE) { \ + HILOG_DEBUG(LOG_CORE, "[%{public}s@%{public}s:%{public}d] " format "\n", \ + __FUNCTION__, __FILENAME__, __LINE__, \ + ##__VA_ARGS__); \ + } \ + } while (0) +#endif + +#ifndef DISPLAY_LOGI +#define DISPLAY_LOGI(format, ...) \ + do { \ + HILOG_INFO(LOG_CORE, "[%{public}s@%{public}s:%{public}d] " format "\n", __FUNCTION__, __FILENAME__, __LINE__, \ + ##__VA_ARGS__); \ + } while (0) +#endif + +#ifndef DISPLAY_LOGW +#define DISPLAY_LOGW(format, ...) \ + do { \ + HILOG_WARN(LOG_CORE, "[%{public}s@%{public}s:%{public}d] " format "\n", __FUNCTION__, __FILENAME__, __LINE__, \ + ##__VA_ARGS__); \ + } while (0) +#endif + +#ifndef DISPLAY_LOGE +#define DISPLAY_LOGE(format, ...) \ + do { \ + HILOG_ERROR(LOG_CORE, \ + "\033[0;32;31m" \ + "[%{public}s@%{public}s:%{public}d] " format "\033[m" \ + "\n", \ + __FUNCTION__, __FILENAME__, __LINE__, ##__VA_ARGS__); \ + } while (0) +#endif + +#ifndef CHECK_NULLPOINTER_RETURN_VALUE +#define CHECK_NULLPOINTER_RETURN_VALUE(pointer, ret) \ + do { \ + if ((pointer) == NULL) { \ + DISPLAY_LOGE("pointer is null and return ret\n"); \ + return (ret); \ + } \ + } while (0) +#endif + +#ifndef CHECK_NULLPOINTER_RETURN +#define CHECK_NULLPOINTER_RETURN(pointer) \ + do { \ + if ((pointer) == NULL) { \ + DISPLAY_LOGE("pointer is null and return\n"); \ + return; \ + } \ + } while (0) +#endif + +#ifndef DISPLAY_CHK_RETURN +#define DISPLAY_CHK_RETURN(val, ret, ...) \ + do { \ + if (val) { \ + __VA_ARGS__; \ + return (ret); \ + } \ + } while (0) +#endif + +#ifndef DISPLAY_CHK_RETURN_NOT_VALUE +#define DISPLAY_CHK_RETURN_NOT_VALUE(val, ...) \ + do { \ + if (val) { \ + __VA_ARGS__; \ + return; \ + } \ + } while (0) +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* DISPLAY_LOG_H*/ diff --git a/display/v1_0/.HdiDisplayDeviceType.idl.swp b/display/v1_0/.HdiDisplayDeviceType.idl.swp new file mode 100644 index 0000000000000000000000000000000000000000..652ca7e2ac0dd4a20398fb6a6dac129d07c92d33 GIT binary patch literal 16384 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 literal 0 HcmV?d00001 diff --git a/display/v1_0/BUILD.gn b/display/v1_0/BUILD.gn new file mode 100644 index 00000000..bd838efd --- /dev/null +++ b/display/v1_0/BUILD.gn @@ -0,0 +1,42 @@ +# Copyright (c) 2022 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. + +import("//drivers/hdf_core/adapter/uhdf2/hdi.gni") + +if (defined(ohos_lite)) { + group("libdisplay_proxy_1.0") { + deps = [] + public_configs = [] + } +} else { + hdi("display_device") { + module_name = "display_device" + + sources = [ + "IDisplayDevice.idl", + "HdiDisplayDeviceType.idl", + "IHotPlugCallback.idl", + "IVBlankCallback.idl", + "IRefreshCallback.idl", + ] + + sequenceable = [ + "//drivers/interface/display/hdifdsequence:libhdifd_parcelable", + "//drivers/interface/display/buffersequence:libbufferhandle_parcelable", + ] + + language = "cpp" + subsystem_name = "hdf" + part_name = "drivers_interface_display" + } +} diff --git a/display/v1_0/HdiDisplayDeviceType.idl b/display/v1_0/HdiDisplayDeviceType.idl new file mode 100644 index 00000000..7e1893ca --- /dev/null +++ b/display/v1_0/HdiDisplayDeviceType.idl @@ -0,0 +1,445 @@ +/* + * Copyright (c) 2022 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. + */ + +package ohos.hdi.display.v1_0; + +sequenceable OHOS.HDI.Display.BufferHandleParcelable; +sequenceable OHOS.HDI.Display.HdifdParcelable; + +enum DispCmd { + // request cmd + REQUEST_CMD_PREPAREDISPLAYLAYERS = 256, + REQUEST_CMD_SETDISPLAYCLIENTBUFFER = 257, + REQUEST_CMD_SETDISPLAYCLIENTDAMAGE = 258, + REQUEST_CMD_COMMIT = 259, + REQUEST_CMD_SETLAYERALPHA = 260, + REQUEST_CMD_SETLAYERSIZE = 261, + REQUEST_CMD_SETLAYERCROP = 262, + REQUEST_CMD_SETLAYERZORDER = 263, + REQUEST_CMD_SETLAYERPREMULTI = 264, + REQUEST_CMD_SETTRANSFORMMODE = 265, + REQUEST_CMD_SETLAYERDIRTYREGION = 266, + REQUEST_CMD_SETLAYERVISIBLEREGION = 267, + REQUEST_CMD_SETLAYERBUFFER = 268, + REQUEST_CMD_SETLAYERCOMPOSITIONTYPE = 269, + REQUEST_CMD_SETLAYERBLENDTYPE = 270, + REQUEST_CMD_SETLAYERVISIBLE = 271, + // reply cmd + REPLY_CMD_SETERROR = 1024, + REPLY_CMD_PREPAREDISPLAYLAYERS = 1025, + REPLY_CMD_COMMIT = 1026, + // Pack control cmd + CONTROL_CMD_REQUEST_BEGIN = 8192, + CONTROL_CMD_REPLY_BEGIN = 8193, + CONTROL_CMD_REQUEST_END = 8194, + CONTROL_CMD_REPLY_END = 8195, +}; + +enum InterfaceType { + DISP_INTF_HDMI = 0, // -1, + DISP_INTF_LCD = 1, + DISP_INTF_BT1120 = 2, + DISP_INTF_BT656 = 3, + DISP_INTF_YPBPR = 4, + DISP_INTF_RGB = 5, + DISP_INTF_CVBS = 6, + DISP_INTF_SVIDEO = 7, + DISP_INTF_VGA = 8, + DISP_INTF_MIPI = 9, + DISP_INTF_PANEL = 10, + DISP_INTF_BUTT = 11, +}; +enum DispErrCode { + DISPLAY_SUCCESS = 0, + DISPLAY_FAILURE = -1, + DISPLAY_FD_ERR = -2, + DISPLAY_PARAM_ERR = -3, + DISPLAY_NULL_PTR = -4, + DISPLAY_NOT_SUPPORT = -5, + DISPLAY_NOMEM = -6, + DISPLAY_SYS_BUSY = -7, + DISPLAY_NOT_PERM = -8, +}; +enum LayerType { + LAYER_TYPE_GRAPHIC = 0, + LAYER_TYPE_OVERLAY = 1, + LAYER_TYPE_SDIEBAND = 2, + LAYER_TYPE_CURSOR = 3, + LAYER_TYPE_BUTT = 4, +}; +enum LostName_0 { + HBM_USE_CPU_READ = ( 1 << 0 ), + HBM_USE_CPU_WRITE = ( 1 << 1 ), + HBM_USE_MEM_MMZ = ( 1 << 2 ), + HBM_USE_MEM_DMA = ( 1 << 3 ), + HBM_USE_MEM_SHARE = ( 1 << 4 ), + HBM_USE_MEM_MMZ_CACHE = ( 1 << 5 ), + HBM_USE_MEM_FB = ( 1 << 6 ), + HBM_USE_ASSIGN_SIZE = ( 1 << 7 ), +}; +enum PixelFormat { + PIXEL_FMT_CLUT8 = 0, + PIXEL_FMT_CLUT1 = 1, + PIXEL_FMT_CLUT4 = 2, + PIXEL_FMT_RGB_565 = 3, + PIXEL_FMT_RGBA_5658 = 4, + PIXEL_FMT_RGBX_4444 = 5, + PIXEL_FMT_RGBA_4444 = 6, + PIXEL_FMT_RGB_444 = 7, + PIXEL_FMT_RGBX_5551 = 8, + PIXEL_FMT_RGBA_5551 = 9, + PIXEL_FMT_RGB_555 = 10, + PIXEL_FMT_RGBX_8888 = 11, + PIXEL_FMT_RGBA_8888 = 12, + PIXEL_FMT_RGB_888 = 13, + PIXEL_FMT_BGR_565 = 14, + PIXEL_FMT_BGRX_4444 = 15, + PIXEL_FMT_BGRA_4444 = 16, + PIXEL_FMT_BGRX_5551 = 17, + PIXEL_FMT_BGRA_5551 = 18, + PIXEL_FMT_BGRX_8888 = 19, + PIXEL_FMT_BGRA_8888 = 20, + PIXEL_FMT_YUV_422_I = 21, + PIXEL_FMT_YCBCR_422_SP = 22, + PIXEL_FMT_YCRCB_422_SP = 23, + PIXEL_FMT_YCBCR_420_SP = 24, + PIXEL_FMT_YCRCB_420_SP = 25, + PIXEL_FMT_YCBCR_422_P = 26, + PIXEL_FMT_YCRCB_422_P = 27, + PIXEL_FMT_YCBCR_420_P = 28, + PIXEL_FMT_YCRCB_420_P = 29, + PIXEL_FMT_YUYV_422_PKG = 30, + PIXEL_FMT_UYVY_422_PKG = 31, + PIXEL_FMT_YVYU_422_PKG = 32, + PIXEL_FMT_VYUY_422_PKG = 33, + PIXEL_FMT_BUTT = 34, +}; +enum TransformType { + ROTATE_NONE = 0, + ROTATE_90 = 1, + ROTATE_180 = 2, + ROTATE_270 = 3, + ROTATE_BUTT = 4, +}; +enum BlendType { + BLEND_NONE = 0, + BLEND_CLEAR = 1, + BLEND_SRC = 2, + BLEND_SRCOVER = 3, + BLEND_DSTOVER = 4, + BLEND_SRCIN = 5, + BLEND_DSTIN = 6, + BLEND_SRCOUT = 7, + BLEND_DSTOUT = 8, + BLEND_SRCATOP = 9, + BLEND_DSTATOP = 10, + BLEND_ADD = 11, + BLEND_XOR = 12, + BLEND_DST = 13, + BLEND_AKS = 14, + BLEND_AKD = 15, + BLEND_BUTT = 16, +}; +enum RopType { + ROP_BLACK = 0, + ROP_NOTMERGEPEN = 1, + ROP_MASKNOTPEN = 2, + ROP_NOTCOPYPEN = 3, + ROP_MASKPENNOT = 4, + ROP_NOT = 5, + ROP_XORPEN = 6, + ROP_NOTMASKPEN = 7, + ROP_MASKPEN = 8, + ROP_NOTXORPEN = 9, + ROP_NOP = 10, + ROP_MERGENOTPEN = 11, + ROP_COPYPE = 12, + ROP_MERGEPENNOT = 13, + ROP_MERGEPEN = 14, + ROP_WHITE = 15, + ROP_BUTT = 16, +}; +enum ColorKey { + CKEY_NONE = 0, + CKEY_SRC = 1, + CKEY_DST = 2, + CKEY_BUTT = 3, +}; +enum MirrorType { + MIRROR_NONE = 0, + MIRROR_LR = 1, + MIRROR_TB = 2, + MIRROR_BUTT = 3, +}; +enum Connection { + CON_INVALID = 0, + CONNECTED = 1, + DISCONNECTED = 2, +}; +enum DispPowerStatus { + POWER_STATUS_ON = 0, + POWER_STATUS_STANDBY = 1, + POWER_STATUS_SUSPEND = 2, + POWER_STATUS_OFF = 3, + POWER_STATUS_BUTT = 4, +}; +enum CompositionType { + COMPOSITION_CLIENT = 0, + COMPOSITION_DEVICE = 1, + COMPOSITION_CURSOR = 2, + COMPOSITION_VIDEO = 3, + COMPOSITION_BUTT = 4, +}; +enum ColorGamut { + COLOR_GAMUT_INVALID = -1, + COLOR_GAMUT_NATIVE = 0, + COLOR_GAMUT_SATNDARD_BT601 = 1, + COLOR_GAMUT_STANDARD_BT709 = 2, + COLOR_GAMUT_DCI_P3 = 3, + COLOR_GAMUT_SRGB = 4, + COLOR_GAMUT_ADOBE_RGB = 5, + COLOR_GAMUT_DISPLAY_P3 = 6, + COLOR_GAMUT_BT2020 = 7, + COLOR_GAMUT_BT2100_PQ = 8, + COLOR_GAMUT_BT2100_HLG = 9, + COLOR_GAMUT_DISPLAY_BT2020 = 10, +}; +enum GamutMap { + GAMUT_MAP_CONSTANT = 0, + GAMUT_MAP_EXPANSION = 1, + GAMUT_MAP_HDR_CONSTANT = 2, + GAMUT_MAP_HDR_EXPANSION = 3, +}; +/* +enum ColorDataSpace { + COLOR_DATA_SPACE_UNKNOWN = 0, + GAMUT_BT601 = 1, + GAMUT_BT709 = 2, + GAMUT_DCI_P3 = 3, + GAMUT_SRGB = 4, + GAMUT_ADOBE_RGB = 5, + GAMUT_DISPLAY_P3 = 6, + GAMUT_BT2020 = 7, + GAMUT_BT2100_PQ = 8, + GAMUT_BT2100_HLG = 9, + GAMUT_DISPLAY_BT2020 = 10, + TRANSFORM_FUNC_UNSPECIFIED = 256, + TRANSFORM_FUNC_LINEAR = 512, + TRANSFORM_FUNC_SRGB = 768, + TRANSFORM_FUNC_SMPTE_170M = 1024, + TRANSFORM_FUNC_GM2_2 = 1280, + TRANSFORM_FUNC_GM2_6 = 1536, + TRANSFORM_FUNC_GM2_8 = 1792, + TRANSFORM_FUNC_ST2084 = 2048, + TRANSFORM_FUNC_HLG = 2304, + PRECISION_UNSPECIFIED = 65536, + PRECISION_FULL = 131072, + PRESION_LIMITED = 196608, + PRESION_EXTENDED = 262144, + BT601_SMPTE170M_FULL = GAMUT_BT601 | TRANSFORM_FUNC_SMPTE_170M | PRECISION_FULL, + BT601_SMPTE170M_LIMITED = GAMUT_BT601 | TRANSFORM_FUNC_SMPTE_170M | PRESION_LIMITED, + BT709_LINEAR_FULL = GAMUT_BT709 | TRANSFORM_FUNC_LINEAR | PRECISION_FULL, + BT709_LINEAR_EXTENDED = GAMUT_BT709 | TRANSFORM_FUNC_LINEAR | PRESION_EXTENDED, + BT709_SRGB_FULL = GAMUT_BT709 | TRANSFORM_FUNC_SRGB | PRECISION_FULL, + BT709_SRGB_EXTENDED = GAMUT_BT709 | TRANSFORM_FUNC_SRGB | PRESION_EXTENDED, + BT709_SMPTE170M_LIMITED = GAMUT_BT709 | TRANSFORM_FUNC_SMPTE_170M | PRESION_LIMITED, + DCI_P3_LINEAR_FULL = GAMUT_DCI_P3 | TRANSFORM_FUNC_LINEAR | PRECISION_FULL, + DCI_P3_GAMMA26_FULL = GAMUT_DCI_P3 | TRANSFORM_FUNC_GM2_6 | PRECISION_FULL, + DISPLAY_P3_LINEAR_FULL = GAMUT_DISPLAY_P3 | TRANSFORM_FUNC_LINEAR | PRECISION_FULL, + DCI_P3_SRGB_FULL = GAMUT_DCI_P3 | TRANSFORM_FUNC_SRGB | PRECISION_FULL, + ADOBE_RGB_GAMMA22_FULL = GAMUT_ADOBE_RGB | TRANSFORM_FUNC_GM2_2 | PRECISION_FULL, + BT2020_LINEAR_FULL = GAMUT_BT2020 | TRANSFORM_FUNC_LINEAR | PRECISION_FULL, + BT2020_SRGB_FULL = GAMUT_BT2020 | TRANSFORM_FUNC_SRGB | PRECISION_FULL, + BT2020_SMPTE170M_FULL = GAMUT_BT2020 | TRANSFORM_FUNC_SMPTE_170M | PRECISION_FULL, + BT2020_ST2084_FULL = GAMUT_BT2020 | TRANSFORM_FUNC_ST2084 | PRECISION_FULL, + BT2020_HLG_FULL = GAMUT_BT2020 | TRANSFORM_FUNC_HLG | PRECISION_FULL, + BT2020_ST2084_LIMITED = GAMUT_BT2020 | TRANSFORM_FUNC_ST2084 | PRESION_LIMITED, +}; +*/ +enum HDRFormat { + NOT_SUPPORT_HDR = 0, + DOLBY_VISION = 1, + HDR10 = 2, + HLG = 3, + HDR10_PLUS = 4, + HDR_VIVID = 5, +}; +enum HDRMetadataKey { + MATAKEY_RED_PRIMARY_X = 0, + MATAKEY_RED_PRIMARY_Y = 1, + MATAKEY_GREEN_PRIMARY_X = 2, + MATAKEY_GREEN_PRIMARY_Y = 3, + MATAKEY_BLUE_PRIMARY_X = 4, + MATAKEY_BLUE_PRIMARY_Y = 5, + MATAKEY_WHITE_PRIMARY_X = 6, + MATAKEY_WHITE_PRIMARY_Y = 7, + MATAKEY_MAX_LUMINANCE = 8, + MATAKEY_MIN_LUMINANCE = 9, + MATAKEY_MAX_CONTENT_LIGHT_LEVEL = 10, + MATAKEY_MAX_FRAME_AVERAGE_LIGHT_LEVEL = 11, + MATAKEY_HDR10_PLUS = 12, + MATAKEY_HDR_VIVID = 13, +}; + +struct HdiBufferHandleInfo { + unsigned int seqId; + BufferHandleParcelable hdl; +}; + +struct HdifdInfo { + int id; + HdifdParcelable hdiFd; +}; + +struct PropertyObject { + String name; + unsigned int propId; + unsigned long value; +}; +struct DisplayCapability { + String name; + enum InterfaceType type; + unsigned int phyWidth; + unsigned int phyHeight; + unsigned int supportLayers; + unsigned int virtualDispCount; + boolean supportWriteBack; + unsigned int propertyCount; + struct PropertyObject[] props; +}; +struct DisplayInfo { + unsigned int width; + unsigned int height; + int rotAngle; +}; +struct LayerInfo { + int width; + int height; + enum LayerType type; + int bpp; + enum PixelFormat pixFormat; +}; +struct LayerAlpha { + boolean enGlobalAlpha; + boolean enPixelAlpha; + unsigned char alpha0; + unsigned char alpha1; + unsigned char gAlpha; +}; +struct BufferData { + unsigned long phyAddr; + //void[] virAddr; +}; +struct LayerBuffer { + FileDescriptor fenceId; + int width; + int height; + int pitch; + enum PixelFormat pixFormat; + struct BufferData data; + BufferHandleParcelable hdl; +}; +struct IRect { + int x; + int y; + int w; + int h; +}; +struct ISurface { + unsigned long phyAddr; + int height; + int width; + int stride; + enum PixelFormat enColorFmt; + boolean bYCbCrClut; + boolean bAlphaMax255; + boolean bAlphaExt1555; + unsigned char alpha0; + unsigned char alpha1; + unsigned long cbcrPhyAddr; + int cbcrStride; + unsigned long clutPhyAddr; +}; +struct ILine { + int x0; + int y0; + int x1; + int y1; + unsigned int color; +}; +struct ICircle { + int x; + int y; + int r; + unsigned int color; +}; +struct Rectangle { + struct IRect rect; + unsigned int color; +}; +struct GfxOpt { + boolean enGlobalAlpha; + unsigned int globalAlpha; + boolean enPixelAlpha; + enum BlendType blendType; + enum ColorKey colorKeyFrom; + boolean enableRop; + enum RopType colorRopType; + enum RopType alphaRopType; + boolean enableScale; + enum TransformType rotateType; + enum MirrorType mirrorType; +}; +struct DisplayModeInfo { + int width; + int height; + unsigned int freshRate; + int id; +}; +struct HDRCapability { + unsigned int formatCount; + enum HDRFormat[] formats; + float maxLum; + float maxAverageLum; + float minLum; +}; +struct HDRMetaData { + enum HDRMetadataKey key; + float value; +}; +enum PresentTimestampType { + HARDWARE_DISPLAY_PTS_UNSUPPORTED = 0, + HARDWARE_DISPLAY_PTS_DELAY = 1 << 0, + HARDWARE_DISPLAY_PTS_TIMESTAMP = 1 << 1, +}; +struct PresentTimestamp { + enum PresentTimestampType type; + long time; +}; +struct ExtDataHandle { + int fd; + unsigned int reserveInts; + int[] reserve; +}; +struct YUVDescInfo { + unsigned long baseAddr; + unsigned int yOffset; + unsigned int uOffset; + unsigned int vOffset; + unsigned int yStride; + unsigned int uvStride; + unsigned int uvStep; +}; // __attribute__((__packed__)) YUVDescInfo; + diff --git a/display/v1_0/IDisplayDevice.idl b/display/v1_0/IDisplayDevice.idl new file mode 100644 index 00000000..c8cc31c8 --- /dev/null +++ b/display/v1_0/IDisplayDevice.idl @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2022 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. + */ + +package ohos.hdi.display.v1_0; + +import ohos.hdi.display.v1_0.HdiDisplayDeviceType; +import ohos.hdi.display.v1_0.IHotPlugCallback; +import ohos.hdi.display.v1_0.IVBlankCallback; +import ohos.hdi.display.v1_0.IRefreshCallback; + +sequenceable OHOS.HDI.Display.HdifdParcelable; +sequenceable OHOS.HDI.Display.BufferHandleParcelable; + +interface IDisplayDevice { + RegHotPlugCallback([in] IHotPlugCallback cb); + GetDisplayCapability([in] unsigned int devId, [out] struct DisplayCapability info); + GetDisplaySupportedModes([in] unsigned int devId, [out] struct DisplayModeInfo[] modes); + GetDisplayMode([in] unsigned int devId, [out] unsigned int modeId); + SetDisplayMode([in] unsigned int devId, [in] unsigned int modeId); + GetDisplayPowerStatus([in] unsigned int devId, [out] enum DispPowerStatus status); + SetDisplayPowerStatus([in] unsigned int devId, [in] enum DispPowerStatus status); + GetDisplayBacklight([in] unsigned int devId, [out] unsigned int level); + SetDisplayBacklight([in] unsigned int devId, [in] unsigned int level); + GetDisplayProperty([in] unsigned int devId, [in] unsigned int id, [out] unsigned long value); + GetDisplayCompChange([in] unsigned int devId, [out] unsigned int[] layers, [out] int[] type); + SetDisplayClientCrop([in] unsigned int devId, [in] struct IRect rect); + SetDisplayClientDestRect([in] unsigned int devId, [in] struct IRect rect); + SetDisplayVsyncEnabled([in] unsigned int devId, [in] boolean enabled); + RegDisplayVBlankCallback([in] unsigned int devId, [in] IVBlankCallback cb); + GetDisplayReleaseFence([in] unsigned int devId, [out] unsigned int[] layers, + [out] HdifdParcelable[] fences); + CreateVirtualDisplay([in] unsigned int width, [in] unsigned int height, + [out] int format, [out] unsigned int devId); + DestroyVirtualDisplay([in] unsigned int devId); + SetVirtualDisplayBuffer([in] unsigned int devId, [in] BufferHandleParcelable buffer, + [in] HdifdParcelable fence); + SetDisplayProperty([in] unsigned int devId, [in] unsigned int id, [in] unsigned long value); + CreateLayer([in] unsigned int devId, [in] struct LayerInfo layerInfo, + [out] unsigned int layerId); + CloseLayer([in] unsigned int devId, [in] unsigned int layerId); + // func for smq transfer + InitCmdRequest([in] SharedMemQueue request); + CmdRequest([in] unsigned int inEleCnt, [in] struct HdifdInfo[] inFds, + [out] unsigned int outEleCnt, [out] struct HdifdInfo[] outFds); + GetCmdReply([out] SharedMemQueue reply); +} diff --git a/display/v1_0/IHotPlugCallback.idl b/display/v1_0/IHotPlugCallback.idl new file mode 100644 index 00000000..ed306c52 --- /dev/null +++ b/display/v1_0/IHotPlugCallback.idl @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2022 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. + */ + +package ohos.hdi.display.v1_0; + +import ohos.hdi.display.v1_0.HdiDisplayDeviceType; + +[callback] interface IHotPlugCallback { + OnHotPlug([in] unsigned int outputId, [in] boolean connected); +} diff --git a/display/v1_0/IRefreshCallback.idl b/display/v1_0/IRefreshCallback.idl new file mode 100644 index 00000000..410cc966 --- /dev/null +++ b/display/v1_0/IRefreshCallback.idl @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2022 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. + */ + +package ohos.hdi.display.v1_0; + +import ohos.hdi.display.v1_0.HdiDisplayDeviceType; + +[callback] interface IRefreshCallback { + OnRefresh([in] unsigned int devId); +} diff --git a/display/v1_0/IVBlankCallback.idl b/display/v1_0/IVBlankCallback.idl new file mode 100644 index 00000000..bc7eafda --- /dev/null +++ b/display/v1_0/IVBlankCallback.idl @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2022 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. + */ + +package ohos.hdi.display.v1_0; + +import ohos.hdi.display.v1_0.HdiDisplayDeviceType; + +[callback] interface IVBlankCallback { + OnVBlank([in] unsigned int sequence, [in] unsigned long ns); +} diff --git a/display/v1_0/display_command/display_cmd_requester.h b/display/v1_0/display_command/display_cmd_requester.h new file mode 100644 index 00000000..699c58e1 --- /dev/null +++ b/display/v1_0/display_command/display_cmd_requester.h @@ -0,0 +1,610 @@ +/* + * Copyright (c) 2020-2021 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. + */ + +#ifndef OHOS_HDI_DISPLAY_V1_0_DISPLAYCMDREQUESTER_H +#define OHOS_HDI_DISPLAY_V1_0_DISPLAYCMDREQUESTER_H + +#include +#include "hdf_log.h" +#include "hdi_smq.h" +#include "buffer_handle_parcelable.h" +#include "hdifd_parcelable.h" +#include "command_data_packer.h" +#include "command_data_unpacker.h" +#include "display_cmd_utils.h" +#include "v1_0/idisplay_device.h" +#include "v1_0/hdi_display_device_type.h" + +namespace OHOS { +namespace HDI { +namespace Display { +namespace V1_0 { + +using namespace OHOS::HDI::Base; +using namespace OHOS::HDI::Display::V1_0; + +template +class DisplayCmdRequester { +public: + DisplayCmdRequester(sptr hdi) + : initFlag_(false), + hdi_(hdi), + request_(nullptr), + reply_(nullptr), + requestPacker_(nullptr) + { + } + + static std::unique_ptr Create(sptr hdi) + { + auto requester = std::make_unique(hdi); + auto ret = requester->Init(CmdUtils::INIT_ELEMENT_COUNT); + if (ret != HDF_SUCCESS) { + HDF_LOGE("DisplayCmdRequester init failed"); + return nullptr; + } + return requester; + } + + int32_t Init(uint32_t eleCnt) + { + int32_t ec = HDF_FAILURE; + request_ = std::make_shared(eleCnt, SmqType::SYNCED_SMQ); + if (request_ == nullptr) { + HDF_LOGE("nullptr failure."); + return HDF_FAILURE; + } else { + ec = hdi_->InitCmdRequest(request_); + if (ec != HDF_SUCCESS) { + HDF_LOGE("InitCmdRequest failure, ec=%{public}d", ec); + return HDF_FAILURE; + } + requestPacker_ = std::make_shared(); + if (requestPacker_ == nullptr || + requestPacker_->Init(request_->GetSize() * CmdUtils::ELEMENT_SIZE) == false) { + HDF_LOGE("requestPacker init failure."); + return HDF_FAILURE; + } + } + + ec = hdi_->GetCmdReply(reply_); + if (ec != HDF_SUCCESS) { + HDF_LOGE("GetCmdReply failure, ec=%{public}d", ec); + return ec; + } + initFlag_ = true; + return CmdUtils::StartPack(CONTROL_CMD_REQUEST_BEGIN, requestPacker_); + } + + int32_t PrepareDisplayLayers(uint32_t devId, bool& needFlushFb) + { + int32_t ec = CmdUtils::StartSection(REQUEST_CMD_PREPAREDISPLAYLAYERS, requestPacker_); + if (ec == HDF_SUCCESS) { + ec = requestPacker_->WriteUint32(devId) ? HDF_SUCCESS : HDF_FAILURE; + } + if (ec == HDF_SUCCESS) { + ec = CmdUtils::EndSection(requestPacker_); + } + if (ec == HDF_SUCCESS) { + ec = CmdUtils::EndPack(requestPacker_); + } + size_t replyEleCnt; + std::vector outFds; + std::shared_ptr replyData; + if (ec == HDF_SUCCESS) { + ec = DoRequest(replyEleCnt, outFds, replyData); + } + + if (ec == HDF_SUCCESS) { + ec = DoReplyResults(replyEleCnt, outFds, replyData, [&](void* data)->int32_t { + needFlushFb = *(reinterpret_cast(data)); + return HDF_SUCCESS; + }); + } + + if (ec != HDF_SUCCESS) { + HDF_LOGE("PrepareDisplayLayers failure, ec=%{public}d", ec); + } + return PeriodDataReset(); + } + + int32_t SetDisplayClientBuffer(uint32_t devId, const BufferHandle& buffer, int32_t fence) + { + int32_t ec = CmdUtils::StartSection(REQUEST_CMD_SETDISPLAYCLIENTBUFFER, requestPacker_); + if (ec == HDF_SUCCESS) { + ec = requestPacker_->WriteUint32(devId) ? HDF_SUCCESS : HDF_FAILURE; + } + if (ec == HDF_SUCCESS) { + ec = CmdUtils::BufferHandlePack(buffer, requestPacker_, requestHdiFds_); + } + if (ec == HDF_SUCCESS) { + ec = CmdUtils::FileDescriptorPack(fence, requestPacker_, requestHdiFds_); + } + if (ec == HDF_SUCCESS) { + ec = CmdUtils::EndSection(requestPacker_); + } else { + HDF_LOGE("error: %{public}d@%{public}s failed, ec=%{public}d", + __LINE__, __func__, ec); + } + return ec; + } + + int32_t SetDisplayClientDamage(uint32_t devId, std::vector& rects) + { + int32_t ec = CmdUtils::StartSection(REQUEST_CMD_SETDISPLAYCLIENTDAMAGE, requestPacker_); + if (ec == HDF_SUCCESS) { + ec = requestPacker_->WriteUint32(devId) ? HDF_SUCCESS : HDF_FAILURE; + } + size_t vectSize = rects.size(); + if (ec == HDF_SUCCESS) { + ec = requestPacker_->WriteUint32(vectSize) ? HDF_SUCCESS : HDF_FAILURE; + } + for (int32_t i = 0; i < vectSize; i++) { + if (ec == HDF_FAILURE) { + break; + } + ec = CmdUtils::RectPack(rects[i], requestPacker_); + } + if (ec == HDF_SUCCESS) { + ec = CmdUtils::EndSection(requestPacker_); + } else { + HDF_LOGE("error: %{public}d@%{public}s failed, ec=%{public}d", + __LINE__, __func__, ec); + } + return ec; + } + + int32_t Commit(uint32_t devId, int32_t& fence) + { + int32_t ec = CmdUtils::StartSection(REQUEST_CMD_COMMIT, requestPacker_); + if (ec == HDF_SUCCESS) { + ec = requestPacker_->WriteUint32(devId) ? HDF_SUCCESS : HDF_FAILURE; + } + if (ec == HDF_SUCCESS) { + ec = CmdUtils::EndSection(requestPacker_); + } + if (ec == HDF_SUCCESS) { + ec = CmdUtils::EndPack(requestPacker_); + } + size_t replyEleCnt = 0; + std::vector outFds; + std::shared_ptr replyData; + if (ec == HDF_SUCCESS) { + ec = DoRequest(replyEleCnt, outFds, replyData); + } + + if (ec == HDF_SUCCESS) { + ec = DoReplyResults(replyEleCnt, outFds, replyData, [&](void* data)->int32_t { + fence = *(reinterpret_cast(data)); + return HDF_SUCCESS; + }); + } + + if (ec != HDF_SUCCESS) { + HDF_LOGE("Commit failure, ec=%{public}d", ec); + } + + return PeriodDataReset(); + } + + int32_t SetLayerAlpha(uint32_t devId, uint32_t layerId, const LayerAlpha& alpha) + { + int32_t ec = CmdUtils::StartSection(REQUEST_CMD_SETLAYERALPHA, requestPacker_); + if (ec == HDF_SUCCESS) { + ec = CmdUtils::SetupDevice(devId, layerId, requestPacker_); + } + bool retVal = (ec == HDF_SUCCESS) ? true : false; + if (retVal) { + retVal = requestPacker_->WriteBool(alpha.enGlobalAlpha); + } + if (retVal) { + retVal = requestPacker_->WriteBool(alpha.enPixelAlpha); + } + if (retVal) { + retVal = requestPacker_->WriteUint8(alpha.alpha0); + } + if (retVal) { + retVal = requestPacker_->WriteUint8(alpha.alpha1); + } + if (retVal) { + retVal = requestPacker_->WriteUint8(alpha.gAlpha); + } + if (retVal) { + retVal = CmdUtils::EndSection(requestPacker_) == HDF_SUCCESS ? true : false; + } else { + HDF_LOGE("error: %{public}d@%{public}s failed, retVal=%{public}d", + __LINE__, __func__, retVal); + } + return retVal ? HDF_SUCCESS : HDF_FAILURE; + } + + int32_t SetLayerSize(uint32_t devId, uint32_t layerId, const IRect& rect) + { + int32_t ec = CmdUtils::StartSection(REQUEST_CMD_SETLAYERSIZE, requestPacker_); + if (ec == HDF_SUCCESS) { + ec = CmdUtils::SetupDevice(devId, layerId, requestPacker_); + } + if (ec == HDF_SUCCESS) { + ec = CmdUtils::RectPack(rect, requestPacker_); + } + if (ec == HDF_SUCCESS) { + ec = CmdUtils::EndSection(requestPacker_); + } else { + HDF_LOGE("error: %{public}d@%{public}s failed, retVal=%{public}d", + __LINE__, __func__, ec); + } + return ec; + } + + int32_t SetLayerCrop(uint32_t devId, uint32_t layerId, const IRect& rect) + { + int32_t ec = CmdUtils::StartSection(REQUEST_CMD_SETLAYERCROP, requestPacker_); + if (ec == HDF_SUCCESS) { + ec = CmdUtils::SetupDevice(devId, layerId, requestPacker_); + } + if (ec == HDF_SUCCESS) { + ec = CmdUtils::RectPack(rect, requestPacker_); + } + if (ec == HDF_SUCCESS) { + ec = CmdUtils::EndSection(requestPacker_); + } else { + HDF_LOGE("error: %{public}d@%{public}s failed, retVal=%{public}d", + __LINE__, __func__, ec); + } + return ec; + } + + int32_t SetLayerZorder(uint32_t devId, uint32_t layerId, uint32_t zorder) + { + int32_t ec = CmdUtils::StartSection(REQUEST_CMD_SETLAYERZORDER, requestPacker_); + if (ec == HDF_SUCCESS) { + ec = CmdUtils::SetupDevice(devId, layerId, requestPacker_); + } + if (ec == HDF_SUCCESS) { + ec = requestPacker_->WriteUint32(zorder) ? HDF_SUCCESS : HDF_FAILURE; + } + if (ec == HDF_SUCCESS) { + ec = CmdUtils::EndSection(requestPacker_); + } else { + HDF_LOGE("error: %{public}d@%{public}s failed, retVal=%{public}d", + __LINE__, __func__, ec); + } + return ec; + } + + int32_t SetLayerPreMulti(uint32_t devId, uint32_t layerId, bool preMul) + { + int32_t ec = CmdUtils::StartSection(REQUEST_CMD_SETLAYERPREMULTI, requestPacker_); + if (ec == HDF_SUCCESS) { + ec = CmdUtils::SetupDevice(devId, layerId, requestPacker_); + } + if (ec == HDF_SUCCESS) { + ec = requestPacker_->WriteBool(preMul) ? HDF_SUCCESS : HDF_FAILURE; + } + if (ec == HDF_SUCCESS) { + ec = CmdUtils::EndSection(requestPacker_); + } else { + HDF_LOGE("error: %{public}d@%{public}s failed, retVal=%{public}d", + __LINE__, __func__, ec); + } + return ec; + } + + int32_t SetTransformMode(uint32_t devId, uint32_t layerId, TransformType type) + { + int32_t ec = CmdUtils::StartSection(REQUEST_CMD_SETTRANSFORMMODE, requestPacker_); + if (ec == HDF_SUCCESS) { + ec = CmdUtils::SetupDevice(devId, layerId, requestPacker_); + } + if (ec == HDF_SUCCESS) { + ec = requestPacker_->WriteInt32(type) ? HDF_SUCCESS : HDF_FAILURE; + } + if (ec == HDF_SUCCESS) { + ec = CmdUtils::EndSection(requestPacker_); + } else { + HDF_LOGE("error: %{public}d@%{public}s failed, retVal=%{public}d", + __LINE__, __func__, ec); + } + return ec; + } + + int32_t SetLayerDirtyRegion(uint32_t devId, uint32_t layerId, const IRect& region) + { + int32_t ec = CmdUtils::StartSection(REQUEST_CMD_SETLAYERDIRTYREGION, requestPacker_); + if (ec == HDF_SUCCESS) { + ec = CmdUtils::SetupDevice(devId, layerId, requestPacker_); + } + if (ec == HDF_SUCCESS) { + ec = CmdUtils::RectPack(region, requestPacker_); + } + if (ec == HDF_SUCCESS) { + ec = CmdUtils::EndSection(requestPacker_); + } else { + HDF_LOGE("error: %{public}d@%{public}s failed, retVal=%{public}d", + __LINE__, __func__, ec); + } + return ec; + } + + int32_t SetLayerVisibleRegion(uint32_t devId, uint32_t layerId, std::vector& rects) + { + int32_t ec = CmdUtils::StartSection(REQUEST_CMD_SETLAYERVISIBLEREGION, requestPacker_); + if (ec == HDF_SUCCESS) { + ec = CmdUtils::SetupDevice(devId, layerId, requestPacker_); + } + size_t vSize = rects.size(); + if (ec == HDF_SUCCESS) { + ec = requestPacker_->WriteUint32(vSize) ? HDF_SUCCESS : HDF_FAILURE; + } + for (uint32_t i = 0; i < vSize; i++) { + if (ec == HDF_FAILURE) { + break; + } + ec = CmdUtils::RectPack(rects[i], requestPacker_); + } + if (ec == HDF_SUCCESS) { + ec = CmdUtils::EndSection(requestPacker_); + } else { + HDF_LOGE("error: %{public}d@%{public}s failed, retVal=%{public}d", + __LINE__, __func__, ec); + } + return ec; + } + + int32_t SetLayerBuffer(uint32_t devId, uint32_t layerId, BufferHandle buffer, int32_t fence) + { + int32_t ec = CmdUtils::StartSection(REQUEST_CMD_SETLAYERBUFFER, requestPacker_); + if (ec == HDF_SUCCESS) { + ec = CmdUtils::SetupDevice(devId, layerId, requestPacker_); + } + if (ec == HDF_SUCCESS) { + ec = CmdUtils::BufferHandlePack(buffer, requestPacker_, requestHdiFds_); + } + if (ec == HDF_SUCCESS) { + ec = CmdUtils::FileDescriptorPack(fence, requestPacker_, requestHdiFds_); + } + if (ec == HDF_SUCCESS) { + ec = CmdUtils::EndSection(requestPacker_); + } else { + HDF_LOGE("error: %{public}d@%{public}s failed, ec=%{public}d", + __LINE__, __func__, ec); + } + return ec; + } + + int32_t SetLayerCompositionType(uint32_t devId, uint32_t layerId, CompositionType type) + { + int32_t ec = CmdUtils::StartSection(REQUEST_CMD_SETLAYERCOMPOSITIONTYPE, requestPacker_); + if (ec == HDF_SUCCESS) { + ec = CmdUtils::SetupDevice(devId, layerId, requestPacker_); + } + if (ec == HDF_SUCCESS) { + ec = requestPacker_->WriteInt32(type) ? HDF_SUCCESS : HDF_FAILURE; + } + if (ec == HDF_SUCCESS) { + ec = CmdUtils::EndSection(requestPacker_); + } else { + HDF_LOGE("error: %{public}d@%{public}s failed, retVal=%{public}d", + __LINE__, __func__, ec); + } + return ec; + } + + int32_t SetLayerBlendType(uint32_t devId, uint32_t layerId, BlendType type) + { + int32_t ec = CmdUtils::StartSection(REQUEST_CMD_SETLAYERBLENDTYPE, requestPacker_); + if (ec == HDF_SUCCESS) { + ec = CmdUtils::SetupDevice(devId, layerId, requestPacker_); + } + if (ec == HDF_SUCCESS) { + ec = requestPacker_->WriteInt32(type) ? HDF_SUCCESS : HDF_FAILURE; + } + if (ec == HDF_SUCCESS) { + ec = CmdUtils::EndSection(requestPacker_); + } else { + HDF_LOGE("error: %{public}d@%{public}s failed, retVal=%{public}d", + __LINE__, __func__, ec); + } + return ec; + } + + int32_t SetLayerVisible(uint32_t devId, uint32_t layerId, bool visible) + { + int32_t ec = CmdUtils::StartSection(REQUEST_CMD_SETLAYERVISIBLE, requestPacker_); + if (ec == HDF_SUCCESS) { + ec = CmdUtils::SetupDevice(devId, layerId, requestPacker_); + } + if (ec == HDF_SUCCESS) { + ec = requestPacker_->WriteBool(visible) ? HDF_SUCCESS : HDF_FAILURE; + } + if (ec == HDF_SUCCESS) { + ec = CmdUtils::EndSection(requestPacker_); + } else { + HDF_LOGE("error: %{public}d@%{public}s failed, retVal=%{public}d", + __LINE__, __func__, ec); + } + return ec; + } + +private: + int32_t OnReplySetError(std::shared_ptr replyUnpacker, + std::unordered_map& errMaps) + { + int32_t ec = HDF_FAILURE; + uint32_t errCnt = 0; + auto retVal = replyUnpacker->ReadUint32(errCnt); + if (retVal) { + int32_t errCmd = -1; + int32_t errCode = -1; + for (; errCnt > 0; errCnt--) { + retVal = replyUnpacker->ReadInt32(errCmd); + if (retVal) { + retVal = replyUnpacker->ReadInt32(errCode); + } + HDF_LOGI("cmd:%{public}s, err:%{public}d", + CmdUtils::CommandToString(errCmd), errCode); + errMaps.emplace(errCmd, errCode); + } + ec = retVal ? HDF_SUCCESS : HDF_FAILURE; + } + + return ec; + } + + int32_t OnReplyPrepareDisplayLayers(std::shared_ptr replyUnpacker, + bool& needFlushFb) + { + return replyUnpacker->ReadBool(needFlushFb) ? HDF_SUCCESS : HDF_FAILURE; + } + + int32_t OnReplyCommit(std::shared_ptr replyUnpacker, + std::vector replyFds, int32_t& fenceFd) + { + return CmdUtils::FileDescriptorUnpack(replyUnpacker, replyFds, fenceFd); + } + + int32_t DoReplyResults(size_t replyEleCnt, std::vector replyFds, + std::shared_ptr replyData, std::function fn) + { + std::shared_ptr replyUnpacker = + std::make_shared(); + replyUnpacker->Init(replyData.get(), replyEleCnt * CmdUtils::ELEMENT_SIZE); + replyUnpacker->Dump(); // liuxk + int32_t unpackCmd = -1; + int32_t ec = HDF_SUCCESS; + if (!replyUnpacker->PackBegin(unpackCmd)) { + HDF_LOGE("error: PackBegin failed, unpackCmd=%{public}d.", unpackCmd); + ec = HDF_FAILURE; + } else { + if (unpackCmd != CONTROL_CMD_REPLY_BEGIN) { + HDF_LOGI("error: PackBegin cmd not match, unpackCmd=%{public}d.", unpackCmd); + ec = HDF_FAILURE; + } + } + while (ec == HDF_SUCCESS && replyUnpacker->NextSection()) { + if(!replyUnpacker->BeginSection(unpackCmd)) { + HDF_LOGE("error: PackSection failed, unpackCmd=%{public}d.", unpackCmd); + ec = HDF_FAILURE; + } + switch (unpackCmd) { + case REPLY_CMD_PREPAREDISPLAYLAYERS: + { + bool needFlushFb; + ec = OnReplyPrepareDisplayLayers(replyUnpacker, needFlushFb); + if (ec == HDF_SUCCESS) { + ec = fn(&needFlushFb); + } + if (ec != HDF_SUCCESS) { + HDF_LOGI("error: ReadBool failed, unpackCmd=%{public}s.", + CmdUtils::CommandToString(unpackCmd)); + } + } + break; + case REPLY_CMD_SETERROR: + if (ec == HDF_SUCCESS) { + std::unordered_map errMaps; + ec = OnReplySetError(replyUnpacker, errMaps); + if (ec == HDF_SUCCESS && errMaps.size() > 0) { + HDF_LOGI("error: server return errs, size=%{public}d", errMaps.size()); + ec = HDF_FAILURE; + } + } + break; + case REPLY_CMD_COMMIT: + { + int32_t fenceFd = -1; + ec = OnReplyCommit(replyUnpacker, replyFds, fenceFd); + if (ec == HDF_SUCCESS) { + ec = fn(&fenceFd); + } + if (ec != HDF_SUCCESS) { + HDF_LOGI("error: return fence fd error, unpackCmd=%{public}s.", + CmdUtils::CommandToString(unpackCmd)); + } + } + break; + default: + HDF_LOGE("Unpack command failure."); + ec = HDF_FAILURE; + break; + } + } + if (ec == HDF_SUCCESS ) { + ec = replyUnpacker->PackEnd(unpackCmd) ? HDF_SUCCESS : HDF_FAILURE; + } + if (unpackCmd != CONTROL_CMD_REPLY_END) { + HDF_LOGE("error: PackEnd failed, endCmd = %{public}s", + CmdUtils::CommandToString(unpackCmd)); + } + + return ec; + } + + int32_t DoRequest(size_t& replyEleCnt, std::vector& outFds, + std::shared_ptr& replyData) + { + requestPacker_->Dump(); // liuxk + int32_t eleCnt = requestPacker_->ValidSize() / CmdUtils::ELEMENT_SIZE; + int32_t ec = request_->Write(reinterpret_cast(requestPacker_->GetDataPtr()), + eleCnt, CmdUtils::TRANSFER_WAIT_TIME); + if (ec != HDF_SUCCESS) { + HDF_LOGE("CmdRequest write failure, ec=%{public}d", ec); + } else { + ec = hdi_->CmdRequest(eleCnt, requestHdiFds_, replyEleCnt, outFds); + if (ec != HDF_SUCCESS) { + HDF_LOGE("CmdRequest failure, ec=%{public}d", ec); + } else { + if (replyEleCnt != 0) { + replyData.reset(new char[replyEleCnt * CmdUtils::ELEMENT_SIZE], + std::default_delete()); + ec = reply_->Read(reinterpret_cast(replyData.get()), + replyEleCnt, CmdUtils::TRANSFER_WAIT_TIME); + if (ec != HDF_SUCCESS) { + HDF_LOGE("reply read data failure, ec=%{public}d", ec); + } + } + } + } + return ec; + } + + int32_t PeriodDataReset() + { + for (uint32_t i = 0; i < requestHdiFds_.size(); ++i) { + int32_t fd = requestHdiFds_[i].hdiFd->Move(); + if (fd != -1) { + close(fd); + } + } + requestHdiFds_.clear(); + return CmdUtils::StartPack(CONTROL_CMD_REQUEST_BEGIN, requestPacker_); + } + +private: + bool initFlag_; + sptr hdi_; + std::shared_ptr request_; + std::shared_ptr reply_; + // Period data + std::shared_ptr requestPacker_; + std::vector requestHdiFds_; +}; +using HdiDisplayCmdRequester = + DisplayCmdRequester, IDisplayDevice>; +} // V1_0 +} // Display +} // HDI +} // OHOS +#endif diff --git a/display/v1_0/display_command/display_cmd_responser.h b/display/v1_0/display_command/display_cmd_responser.h new file mode 100644 index 00000000..a6095678 --- /dev/null +++ b/display/v1_0/display_command/display_cmd_responser.h @@ -0,0 +1,675 @@ +/* + * Copyright (c) 2020-2021 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. + */ + +#ifndef OHOS_HDI_DISPLAY_V1_0_DISPLAYCMDREQUESTER_H +#define OHOS_HDI_DISPLAY_V1_0_DISPLAYCMDREQUESTER_H + +#include +#include "hdf_base.h" +#include "hdf_log.h" +#include "hdi_smq.h" +#include "buffer_handle_utils.h" +#include "buffer_handle_parcelable.h" +#include "hdifd_parcelable.h" +#include "command_data_packer.h" +#include "command_data_unpacker.h" +#include "display_cmd_utils.h" +#include "v1_0/include/idisplay_device_interface.h" +#include "v1_0/hdi_display_device_type.h" + +namespace OHOS { +namespace HDI { +namespace Display { +namespace V1_0 { + +using namespace OHOS::HDI::Base; +using namespace OHOS::HDI::Display::V1_0; +using HdifdSet = std::vector>; + +template +class DisplayCmdResponser { +public: + static std::unique_ptr Create(std::shared_ptr impl) + { + return std::make_unique(impl); + } + + DisplayCmdResponser(std::shared_ptr halImpl) + : impl_(halImpl), + request_(nullptr), + isReplyUpdated_(false), + reply_(nullptr), + replyCommandCnt_(0), + replyPacker_(nullptr) + { + } + + ~DisplayCmdResponser() + { + } + + int32_t InitCmdRequest(const std::shared_ptr& request) + { + if (request_ != nullptr) { + request_.reset(); + } + request_ = request; + + return HDF_SUCCESS; + } + + int32_t GetCmdReply(std::shared_ptr& reply) + { + int32_t ec = HDF_SUCCESS; + if (isReplyUpdated_ == false) { + ec = InitReply(CmdUtils::INIT_ELEMENT_COUNT); + } + if (ec == HDF_SUCCESS) { + if (reply_ != nullptr) { + reply = reply_; + } else { + ec = HDF_FAILURE; + } + } + isReplyUpdated_ = false; + if (ec != HDF_SUCCESS) { + HDF_LOGE("error: GetCmdReply failure"); + } + return ec; + } + + int32_t CmdRequest(uint32_t inEleCnt, const std::vector& inFds, + uint32_t& outEleCnt, std::vector& outFds) + { + std::shared_ptr requestData(new char[inEleCnt * CmdUtils::ELEMENT_SIZE], + std::default_delete()); + int32_t ec = request_->Read(reinterpret_cast(requestData.get()), + inEleCnt, CmdUtils::TRANSFER_WAIT_TIME); + + std::shared_ptr unpacker = std::make_shared(); + if (ec == HDF_SUCCESS) { + unpacker->Init(requestData.get(), inEleCnt * CmdUtils::ELEMENT_SIZE); + unpacker->Dump(); // liuxk + } else { + ec = HDF_FAILURE; + } + int32_t unpackCmd = -1; + if (ec != HDF_SUCCESS || unpacker->PackBegin(unpackCmd) == false) { + HDF_LOGE("error: Check RequestBegin failed."); + ec = HDF_FAILURE; + } + if (unpackCmd != CONTROL_CMD_REQUEST_BEGIN) { + HDF_LOGI("error: unpacker PackBegin cmd not match, cmd(%{public}d)=%{public}s.", + unpackCmd, CmdUtils::CommandToString(unpackCmd)); + ec = HDF_FAILURE; + } + + while (ec == HDF_SUCCESS && unpacker->NextSection()) { + if(!unpacker->BeginSection(unpackCmd)) { + HDF_LOGE("error: PackSection failed, unpackCmd=%{public}s.", + CmdUtils::CommandToString(unpackCmd)); + ec = HDF_FAILURE; + } + HDF_LOGE("liuxk: PackSection, unpackCmd-[%{public}d]=%{public}s.", + unpackCmd, CmdUtils::CommandToString(unpackCmd)); + switch (unpackCmd) { + case REQUEST_CMD_PREPAREDISPLAYLAYERS: + OnPrepareDisplayLayers(unpacker); + break; + case REQUEST_CMD_SETDISPLAYCLIENTBUFFER: + OnSetDisplayClientBuffer(unpacker, inFds); + break; + case REQUEST_CMD_SETDISPLAYCLIENTDAMAGE: + OnSetDisplayClientDamage(unpacker); + break; + case REQUEST_CMD_COMMIT: + OnCommit(unpacker, outFds); + break; + case REQUEST_CMD_SETLAYERALPHA: + OnSetLayerAlpha(unpacker); + break; + case REQUEST_CMD_SETLAYERSIZE: + OnSetLayerSize(unpacker); + break; + case REQUEST_CMD_SETLAYERCROP: + OnSetLayerCrop(unpacker); + break; + case REQUEST_CMD_SETLAYERZORDER: + OnSetLayerZorder(unpacker); + break; + case REQUEST_CMD_SETLAYERPREMULTI: + OnSetLayerPreMulti(unpacker); + break; + case REQUEST_CMD_SETTRANSFORMMODE: + OnSetTransformMode(unpacker); + break; + case REQUEST_CMD_SETLAYERDIRTYREGION: + OnSetLayerDirtyRegion(unpacker); + break; + case REQUEST_CMD_SETLAYERVISIBLEREGION: + OnSetLayerVisibleRegion(unpacker); + break; + case REQUEST_CMD_SETLAYERBUFFER: { + OnSetLayerBuffer(unpacker, inFds); + break;} + case REQUEST_CMD_SETLAYERCOMPOSITIONTYPE: + OnSetLayerCompositionType(unpacker); + break; + case REQUEST_CMD_SETLAYERBLENDTYPE: + OnSetLayerBlendType(unpacker); + break; + case REQUEST_CMD_SETLAYERVISIBLE: + OnSetLayerVisible(unpacker); + break; + case CONTROL_CMD_REQUEST_END: + OnRequestEnd(unpacker); + break; + default: + HDF_LOGE("error: not support display command, unpacked Cmd=%{public}d.", + unpackCmd); + ec = HDF_FAILURE; + break; + } + } + // pack request end commands + replyPacker_->PackEnd(CONTROL_CMD_REPLY_END); + HDF_LOGE("CmdReply command cnt=%{public}d", replyCommandCnt_); + // Write reply pack + replyPacker_->Dump(); // liuxk + outEleCnt = replyPacker_->ValidSize() / CmdUtils::ELEMENT_SIZE; + ec = reply_->Write(reinterpret_cast(replyPacker_->GetDataPtr()), + outEleCnt, CmdUtils::TRANSFER_WAIT_TIME); + if (ec != HDF_SUCCESS) { + HDF_LOGE("Reply write failure, ec=%{public}d", ec); + outEleCnt = 0; + } + int32_t ec2 = PeriodDataReset(); + + return (ec == HDF_SUCCESS ? ec2 : ec); + } + +private: + int32_t InitReply(uint32_t size) + { + reply_ = std::make_shared(size, SmqType::SYNCED_SMQ); + if (reply_ == nullptr) { + HDF_LOGE("nullptr error."); + return HDF_FAILURE; + } + replyPacker_ = std::make_shared(); + if (replyPacker_ == nullptr || + replyPacker_->Init(reply_->GetSize() * CmdUtils::ELEMENT_SIZE) == false) { + HDF_LOGE("replyPacker init failure."); + return HDF_FAILURE; + } + return CmdUtils::StartPack(CONTROL_CMD_REPLY_BEGIN, replyPacker_); + } + + void OnRequestEnd(std::shared_ptr unpacker) + { + // pack reply error commands + size_t errCnt = errMaps_.size(); + if (errCnt >= 0) { + int32_t ec = CmdUtils::StartSection(REPLY_CMD_SETERROR, replyPacker_); + bool retVal = (ec == HDF_SUCCESS) ? true : false; + if (retVal) { + retVal = replyPacker_->WriteUint32(errCnt); + } + for (auto it = errMaps_.begin(); it != errMaps_.end(); ++it) { + if (retVal) { + break; + } + if (retVal) { + retVal = replyPacker_->WriteInt32(it->first); + } + if (retVal) { + retVal = replyPacker_->WriteInt32(it->second); + } + HDF_LOGE("Call display cmd failed, Id:%{public}s, ec=%{public}d", + CmdUtils::CommandToString(it->first), it->second); + } + if (retVal) { + CmdUtils::EndSection(replyPacker_); + } else { + HDF_LOGE("OnRequestEnd failed"); + } + replyCommandCnt_++; + } + + return; + } + + void OnPrepareDisplayLayers(std::shared_ptr unpacker) + { + uint32_t devId = -1; + int32_t ec = unpacker->ReadUint32(devId) ? HDF_SUCCESS : HDF_FAILURE; + + bool needFlush = false; + if (ec == HDF_SUCCESS) { + ec = impl_->PrepareDisplayLayers(devId, needFlush); + } + // reply pack + if (ec == HDF_SUCCESS) { + ec = CmdUtils::StartSection(REPLY_CMD_PREPAREDISPLAYLAYERS, replyPacker_); + } + if (ec == HDF_SUCCESS) { + ec = replyPacker_->WriteBool(needFlush) ? HDF_SUCCESS : HDF_FAILURE; + } + if (ec == HDF_SUCCESS) { + ec = CmdUtils::EndSection(replyPacker_); + replyCommandCnt_++; + } + if (ec != HDF_SUCCESS) { + errMaps_.emplace(REQUEST_CMD_PREPAREDISPLAYLAYERS, ec); + } + + return; + } + + void OnSetDisplayClientBuffer(std::shared_ptr unpacker, + const std::vector& inFds) + { + uint32_t devId; + int32_t ec = unpacker->ReadUint32(devId) ? HDF_SUCCESS : HDF_FAILURE; + + BufferHandle* buffer = nullptr; + if (ec == HDF_SUCCESS) { + ec = CmdUtils::BufferHandleUnpack(unpacker, inFds, buffer); + } + + int32_t fence = -1; + if (ec == HDF_SUCCESS) { + ec = CmdUtils::FileDescriptorUnpack(unpacker, inFds, fence); + } + HdifdParcelable fdParcel(fence); + + if (ec == HDF_SUCCESS) { + ec = impl_->SetDisplayClientBuffer(devId, *buffer, fdParcel.GetFd()); + } + FreeBufferHandle(buffer); + if (ec != HDF_SUCCESS) { + errMaps_.emplace(REQUEST_CMD_SETDISPLAYCLIENTBUFFER, ec); + } + return; + } + + void OnSetDisplayClientDamage(std::shared_ptr unpacker) + { + uint32_t devId = -1; + int32_t ec = unpacker->ReadUint32(devId) ? HDF_SUCCESS : HDF_FAILURE; + + size_t vectSize = 0; + if (ec == HDF_SUCCESS) { + ec = unpacker->ReadUint32(vectSize) ? HDF_SUCCESS : HDF_FAILURE; + } + + std::vector rects; + rects.reserve(vectSize); + for (int32_t i = 0; i < vectSize; i++) { + if (ec == HDF_FAILURE) { + break; + } + ec = CmdUtils::RectUnpack(unpacker, rects[i]); + } + if (ec == HDF_SUCCESS) { + ec = impl_->SetDisplayClientDamage(devId, rects); + } + if (ec != HDF_SUCCESS) { + errMaps_.emplace(REQUEST_CMD_SETDISPLAYCLIENTDAMAGE, ec); + } + return; + } + + void OnCommit(std::shared_ptr unpacker, std::vector& outFds) + { + uint32_t devId = -1; + int32_t ec = unpacker->ReadUint32(devId) ? HDF_SUCCESS : HDF_FAILURE; + + // do request + int32_t fence = -1; + if (ec == HDF_SUCCESS) { + ec = impl_->Commit(devId, fence); + } + HdifdParcelable fdParcel(fence); + // reply pack + if (ec == HDF_SUCCESS) { + ec = CmdUtils::StartSection(REPLY_CMD_COMMIT, replyPacker_); + } + if (ec == HDF_SUCCESS) { + ec = CmdUtils::FileDescriptorPack(fdParcel.GetFd(), replyPacker_, outFds); + } + if (ec == HDF_SUCCESS) { + ec = CmdUtils::EndSection(replyPacker_); + replyCommandCnt_++; + } + // push err maps if exist + if (ec != HDF_SUCCESS) { + errMaps_.emplace(REQUEST_CMD_COMMIT, ec); + } + + return; + } + + void OnSetLayerAlpha(std::shared_ptr unpacker) + { + // unpack + uint32_t devId = -1; + uint32_t layerId = -1; + int32_t ec = CmdUtils::SetupDeviceUnpack(unpacker, devId, layerId); + LayerAlpha alpha; + bool retVal = (ec == HDF_SUCCESS) ? true : false; + if (retVal) { + retVal = unpacker->ReadBool(alpha.enGlobalAlpha); + } + if (retVal) { + retVal = unpacker->ReadBool(alpha.enPixelAlpha); + } + if (retVal) { + retVal = unpacker->ReadUint8(alpha.alpha0); + } + if (retVal) { + retVal = unpacker->ReadUint8(alpha.alpha1); + } + if (retVal) { + retVal = unpacker->ReadUint8(alpha.gAlpha); + } + // do request + if (retVal) { + ec = impl_->SetLayerAlpha(devId, layerId, alpha); + } else { + ec = retVal ? HDF_SUCCESS : HDF_FAILURE; + } + // push err maps if exist + if (ec != HDF_SUCCESS) { + errMaps_.emplace(REQUEST_CMD_SETLAYERALPHA, ec); + } + return; + } + + void OnSetLayerSize(std::shared_ptr unpacker) + { + // unpack + uint32_t devId = -1; + uint32_t layerId = -1; + int32_t ec = CmdUtils::SetupDeviceUnpack(unpacker, devId, layerId); + IRect rect; + if (ec == HDF_SUCCESS) { + ec = CmdUtils::RectUnpack(unpacker, rect); + } + // do request + if (ec == HDF_SUCCESS) { + ec = impl_->SetLayerSize(devId, layerId, rect); + } + // push err maps if exist + if (ec != HDF_SUCCESS) { + errMaps_.emplace(REQUEST_CMD_SETLAYERSIZE, ec); + } + + return; + } + + void OnSetLayerCrop(std::shared_ptr unpacker) + { + // unpack + uint32_t devId = -1; + uint32_t layerId = -1; + int32_t ec = CmdUtils::SetupDeviceUnpack(unpacker, devId, layerId); + IRect rect; + if (ec == HDF_SUCCESS) { + ec = CmdUtils::RectUnpack(unpacker, rect); + } + // do request + if (ec == HDF_SUCCESS) { + ec = impl_->SetLayerCrop(devId, layerId, rect); + } + // push err maps if exist + if (ec != HDF_SUCCESS) { + errMaps_.emplace(REQUEST_CMD_SETLAYERCROP, ec); + } + return; + } + + void OnSetLayerZorder(std::shared_ptr unpacker) + { + // unpack + uint32_t devId = -1; + uint32_t layerId = -1; + int32_t ec = CmdUtils::SetupDeviceUnpack(unpacker, devId, layerId); + uint32_t zorder; + if (ec == HDF_SUCCESS) { + ec = unpacker->ReadUint32(zorder) ? HDF_SUCCESS : HDF_FAILURE; + } + // do request + if (ec == HDF_SUCCESS) { + ec = impl_->SetLayerZorder(devId, layerId, zorder); + } + // push err maps if exist + if (ec != HDF_SUCCESS) { + errMaps_.emplace(REQUEST_CMD_SETLAYERZORDER, ec); + } + return; + } + + void OnSetLayerPreMulti(std::shared_ptr unpacker) + { + // unpack + uint32_t devId = -1; + uint32_t layerId = -1; + int32_t ec = CmdUtils::SetupDeviceUnpack(unpacker, devId, layerId); + bool preMulti; + if (ec == HDF_SUCCESS) { + ec = unpacker->ReadBool(preMulti) ? HDF_SUCCESS : HDF_FAILURE; + } + // do request + if (ec == HDF_SUCCESS) { + ec = impl_->SetLayerPreMulti(devId, layerId, preMulti); + } + // push err maps if exist + if (ec != HDF_SUCCESS) { + errMaps_.emplace(REQUEST_CMD_SETLAYERPREMULTI, ec); + } + return; + } + + void OnSetTransformMode(std::shared_ptr unpacker) + { + // unpack + uint32_t devId = -1; + uint32_t layerId = -1; + int32_t ec = CmdUtils::SetupDeviceUnpack(unpacker, devId, layerId); + int32_t type; + if (ec == HDF_SUCCESS) { + ec = unpacker->ReadInt32(type) ? HDF_SUCCESS : HDF_FAILURE; + } + // do request + if (ec == HDF_SUCCESS) { + ec = impl_->SetTransformMode(devId, layerId, static_cast(type)); + } + // push err maps if exist + if (ec != HDF_SUCCESS) { + errMaps_.emplace(REQUEST_CMD_SETTRANSFORMMODE, ec); + } + return; + } + + void OnSetLayerDirtyRegion(std::shared_ptr unpacker) + { + // unpack + uint32_t devId = -1; + uint32_t layerId = -1; + int32_t ec = CmdUtils::SetupDeviceUnpack(unpacker, devId, layerId); + IRect rect; + if (ec == HDF_SUCCESS) { + ec = CmdUtils::RectUnpack(unpacker, rect); + } + // do request + if (ec == HDF_SUCCESS) { + ec = impl_->SetLayerDirtyRegion(devId, layerId, rect); + } + // push err maps if exist + if (ec != HDF_SUCCESS) { + errMaps_.emplace(REQUEST_CMD_SETLAYERDIRTYREGION, ec); + } + return; + } + + void OnSetLayerVisibleRegion(std::shared_ptr unpacker) + { + // unpack + uint32_t devId = -1; + uint32_t layerId = -1; + int32_t ec = CmdUtils::SetupDeviceUnpack(unpacker, devId, layerId); + + size_t vectSize = 0; + if (ec == HDF_SUCCESS) { + ec = unpacker->ReadUint32(vectSize) ? HDF_SUCCESS : HDF_FAILURE; + } + std::vector rects; + for (int32_t i = 0; i < vectSize; i++) { + if (ec == HDF_FAILURE) { + break; + } + IRect rect; + ec = CmdUtils::RectUnpack(unpacker, rect); + rects.push_back(rect); + } + if (ec == HDF_SUCCESS) { + ec = impl_->SetLayerVisibleRegion(devId, layerId, rects); + } + if (ec != HDF_SUCCESS) { + errMaps_.emplace(REQUEST_CMD_SETLAYERVISIBLEREGION, ec); + } + return; + } + + void OnSetLayerBuffer(std::shared_ptr unpacker, + const std::vector& inFds) + { + // unpack + uint32_t devId = -1; + uint32_t layerId = -1; + int32_t ec = CmdUtils::SetupDeviceUnpack(unpacker, devId, layerId); + + BufferHandle* buffer = nullptr; + if (ec == HDF_SUCCESS) { + ec = CmdUtils::BufferHandleUnpack(unpacker, inFds, buffer); + } + int32_t fence = -1; + if (ec == HDF_SUCCESS) { + ec = CmdUtils::FileDescriptorUnpack(unpacker, inFds, fence); + } + HdifdParcelable fdParcel(fence); + if (ec == HDF_SUCCESS) { + ec = impl_->SetLayerBuffer(devId, layerId, *buffer, fdParcel.GetFd()); + } + FreeBufferHandle(buffer); + if (ec != HDF_SUCCESS) { + errMaps_.emplace(REQUEST_CMD_SETLAYERBUFFER, ec); + } + return; + } + + void OnSetLayerCompositionType(std::shared_ptr unpacker) + { + // unpack + uint32_t devId = -1; + uint32_t layerId = -1; + int32_t ec = CmdUtils::SetupDeviceUnpack(unpacker, devId, layerId); + int32_t type; + if (ec == HDF_SUCCESS) { + ec = unpacker->ReadInt32(type) ? HDF_SUCCESS : HDF_FAILURE; + } + // do request + if (ec == HDF_SUCCESS) { + ec = impl_->SetLayerCompositionType(devId, layerId, static_cast(type)); + } + // push err maps if exist + if (ec != HDF_SUCCESS) { + errMaps_.emplace(REQUEST_CMD_SETLAYERCOMPOSITIONTYPE, ec); + } + return; + } + + void OnSetLayerBlendType(std::shared_ptr unpacker) + { + // unpack + uint32_t devId = -1; + uint32_t layerId = -1; + int32_t ec = CmdUtils::SetupDeviceUnpack(unpacker, devId, layerId); + int32_t type; + if (ec == HDF_SUCCESS) { + ec = unpacker->ReadInt32(type) ? HDF_SUCCESS : HDF_FAILURE; + } + // do request + if (ec == HDF_SUCCESS) { + ec = impl_->SetLayerBlendType(devId, layerId, static_cast(type)); + } + // push err maps if exist + if (ec != HDF_SUCCESS) { + errMaps_.emplace(REQUEST_CMD_SETLAYERBLENDTYPE, ec); + } + return; + } + + void OnSetLayerVisible(std::shared_ptr unpacker) + { + // unpack + uint32_t devId = -1; + uint32_t layerId = -1; + int32_t ec = CmdUtils::SetupDeviceUnpack(unpacker, devId, layerId); + bool visible = false; + if (ec == HDF_SUCCESS) { + ec = unpacker->ReadBool(visible) ? HDF_SUCCESS : HDF_FAILURE; + } + // do request + if (ec == HDF_SUCCESS) { + ec = impl_->SetLayerVisible(devId, layerId, visible); + } + // push err maps if exist + if (ec != HDF_SUCCESS) { + errMaps_.emplace(REQUEST_CMD_SETLAYERPREMULTI, ec); + } + return; + } + + int32_t PeriodDataReset() + { + replyCommandCnt_ = 0; + errMaps_.clear(); + + int32_t ec = CmdUtils::StartPack(CONTROL_CMD_REPLY_BEGIN, replyPacker_); + if (ec != HDF_SUCCESS) { + HDF_LOGE("PackBegin failure, ec=%{public}d", ec); + } + return ec; + } + +private: + std::shared_ptr impl_; + std::shared_ptr request_; + bool isReplyUpdated_; + std::shared_ptr reply_; + // period data + uint32_t replyCommandCnt_; + std::shared_ptr replyPacker_; + std::unordered_map errMaps_; +}; +using HdiDisplayCmdResponser = + DisplayCmdResponser, IDisplayDeviceInterface>; +} // V1_0 +} // Display +} // HDI +} // OHOS +#endif diff --git a/display/v1_0/display_command/display_cmd_utils.h b/display/v1_0/display_command/display_cmd_utils.h new file mode 100644 index 00000000..0cc0ab13 --- /dev/null +++ b/display/v1_0/display_command/display_cmd_utils.h @@ -0,0 +1,333 @@ +/* + * Copyright (c) 2020-2021 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. + */ + +#ifndef OHOS_HDI_DISPLAY_V1_0_DISPLAYCMDUTILS_H +#define OHOS_HDI_DISPLAY_V1_0_DISPLAYCMDUTILS_H + +#include "buffer_handle_utils.h" +#include "command_data_packer.h" +#include "command_data_unpacker.h" +#include "v1_0/hdi_display_device_type.h" + +namespace OHOS { +namespace HDI { +namespace Display { +namespace V1_0 { + +using namespace OHOS::HDI::Display::V1_0; + +class DisplayCmdUtils { +public: + static constexpr int32_t MAX_INT = 0x7fffffff; + static constexpr int32_t MIN_INT = 0x80000000; + static constexpr uint32_t ELEMENT_SIZE = sizeof(int32_t); + static constexpr uint32_t TRANSFER_WAIT_TIME = 100000000; // ms + static constexpr uint32_t INIT_ELEMENT_COUNT = 32 * 1024; + + #define SWITCHCASE(x) case (x): {return #x;} + static const char* CommandToString(int32_t cmdId) + { + switch (cmdId) { + // request cmd + SWITCHCASE(REQUEST_CMD_PREPAREDISPLAYLAYERS); + SWITCHCASE(REQUEST_CMD_SETDISPLAYCLIENTBUFFER); + SWITCHCASE(REQUEST_CMD_SETDISPLAYCLIENTDAMAGE); + SWITCHCASE(REQUEST_CMD_COMMIT); + SWITCHCASE(REQUEST_CMD_SETLAYERALPHA); + SWITCHCASE(REQUEST_CMD_SETLAYERSIZE); + SWITCHCASE(REQUEST_CMD_SETLAYERCROP); + SWITCHCASE(REQUEST_CMD_SETLAYERZORDER); + SWITCHCASE(REQUEST_CMD_SETLAYERPREMULTI); + SWITCHCASE(REQUEST_CMD_SETTRANSFORMMODE); + SWITCHCASE(REQUEST_CMD_SETLAYERDIRTYREGION); + SWITCHCASE(REQUEST_CMD_SETLAYERVISIBLEREGION); + SWITCHCASE(REQUEST_CMD_SETLAYERBUFFER); + SWITCHCASE(REQUEST_CMD_SETLAYERCOMPOSITIONTYPE); + SWITCHCASE(REQUEST_CMD_SETLAYERBLENDTYPE); + SWITCHCASE(REQUEST_CMD_SETLAYERVISIBLE); + // reply cmd + SWITCHCASE(REPLY_CMD_SETERROR); + SWITCHCASE(REPLY_CMD_PREPAREDISPLAYLAYERS); + SWITCHCASE(REPLY_CMD_COMMIT); + // pack control cmd + SWITCHCASE(CONTROL_CMD_REQUEST_BEGIN); + SWITCHCASE(CONTROL_CMD_REPLY_BEGIN); + SWITCHCASE(CONTROL_CMD_REQUEST_END); + SWITCHCASE(CONTROL_CMD_REPLY_END); + default: + return "unknow command id."; + } + } + + static int32_t StartPack(int32_t cmdId, std::shared_ptr packer) + { + return packer->PackBegin(cmdId) ? HDF_SUCCESS : HDF_FAILURE; + } + + static int32_t EndPack(std::shared_ptr packer) + { + return packer->PackEnd(CONTROL_CMD_REQUEST_END) ? HDF_SUCCESS : HDF_FAILURE; + } + + static int32_t StartSection(int32_t cmdId, std::shared_ptr packer) + { + return packer->BeginSection(cmdId) ? HDF_SUCCESS : HDF_FAILURE; + } + + static int32_t SetupDevice(uint32_t devId, uint32_t layerId, + std::shared_ptr packer) + { + bool retVal = packer->WriteUint32(devId); + if (retVal) { + retVal = packer->WriteUint32(layerId); + } + return retVal ? HDF_SUCCESS : HDF_FAILURE; + } + + static int32_t EndSection(std::shared_ptr packer) + { + return packer->EndSection() ? HDF_SUCCESS : HDF_FAILURE; + } + + static int32_t GenerateHdifdSeqid() + { + static int32_t HdifdSeqidCursor = 0; + return HdifdSeqidCursor <= MAX_INT ? ++HdifdSeqidCursor : 0; + } + + static bool MatchHdiFd(int32_t id, std::vector hdiFds, int32_t& fd) + { + for (uint32_t i = 0; i < hdiFds.size(); ++i) { + if (hdiFds[i].id == id) { + fd = hdiFds[i].hdiFd->Move(); + return true; + } + } + return false; + } + + static int32_t RectPack(const IRect& rect, std::shared_ptr packer) + { + bool retVal = packer->WriteInt32(rect.x); + if (retVal) { + retVal = packer->WriteInt32(rect.y); + } + if (retVal) { + retVal = packer->WriteInt32(rect.w); + } + if (retVal) { + retVal = packer->WriteInt32(rect.h); + } + return retVal ? HDF_SUCCESS : HDF_FAILURE; + } + + static int32_t FileDescriptorPack(const int32_t fd, std::shared_ptr packer, + std::vector& hdiFds) + { + int32_t ec = HDF_SUCCESS; + + HdifdInfo hdifdInfo; + hdifdInfo.id = GenerateHdifdSeqid(); + hdifdInfo.hdiFd = new HdifdParcelable(); + if (hdifdInfo.hdiFd == nullptr) { + HDF_LOGE("error: new HdifdParcelable failed"); + ec = HDF_FAILURE; + } else { + if (fd >= 0) { + // A normal fd is transfered by binder, + // Here just write id for unpacking to match fd. + if (ec == HDF_SUCCESS && hdifdInfo.hdiFd->Init(fd)) { + hdiFds.push_back(hdifdInfo); + ec = packer->WriteInt32(hdifdInfo.id) ? HDF_SUCCESS : HDF_FAILURE; + } else { + HDF_LOGE("error: PackHdifd failed"); + ec = HDF_FAILURE; + } + } else { + // A illegal fd is transfered by smq directly + ec = packer->WriteInt32(fd) ? HDF_SUCCESS : HDF_FAILURE; + } + } + + return ec; + } + + static int32_t BufferHandlePack(const BufferHandle& buffer, + std::shared_ptr packer, std::vector& hdiFds) + { + bool retVal = packer->WriteUint32(buffer.reserveFds); + if (retVal) { + retVal = packer->WriteUint32(buffer.reserveInts); + } + int32_t ec = HDF_SUCCESS; + if (retVal) { + ec = FileDescriptorPack(buffer.fd, packer, hdiFds); + retVal = (ec == HDF_SUCCESS ? true : false); + } + if (retVal) { + retVal = packer->WriteInt32(buffer.width); + } + if (retVal) { + retVal = packer->WriteInt32(buffer.stride); + } + if (retVal) { + retVal = packer->WriteInt32(buffer.height); + } + if (retVal) { + retVal = packer->WriteInt32(buffer.size); + } + if (retVal) { + retVal = packer->WriteInt32(buffer.format); + } + if (retVal) { + retVal = packer->WriteUint64(buffer.usage); + } + if (retVal) { + retVal = packer->WriteUint64(buffer.phyAddr); + } + if (retVal) { + retVal = packer->WriteInt32(buffer.key); + } + if (retVal) { + int32_t i = 0; + for (i = 0; i < buffer.reserveFds; i++) { + ec = FileDescriptorPack(buffer.reserve[i], packer, hdiFds); + if (ec != HDF_SUCCESS) { + retVal = false; + break; + } + } + for (int32_t j = 0; j < buffer.reserveInts; j++) { + retVal = packer->WriteInt32(buffer.reserve[i++]); + if (!retVal) { + break; + } + } + } + return retVal ? HDF_SUCCESS : HDF_FAILURE; + } + + static int32_t SetupDeviceUnpack(std::shared_ptr unpacker, + uint32_t& devId, uint32_t& layerId) + { + bool retVal = unpacker->ReadUint32(devId); + if (retVal) { + retVal = unpacker->ReadUint32(layerId); + } + return retVal ? HDF_SUCCESS : HDF_FAILURE; + } + + static int32_t RectUnpack(std::shared_ptr unpacker, IRect& rect) + { + bool retVal = unpacker->ReadInt32(rect.x); + if (retVal) { + retVal = unpacker->ReadInt32(rect.y); + } + if (retVal) { + retVal = unpacker->ReadInt32(rect.w); + } + if (retVal) { + retVal = unpacker->ReadInt32(rect.h); + } + return retVal ? HDF_SUCCESS : HDF_FAILURE; + } + + static int32_t FileDescriptorUnpack(std::shared_ptr unpacker, + const std::vector& hdiFds, int32_t& fd) + { + int32_t fdId = -1; + int32_t ec = unpacker->ReadInt32(fdId) ? HDF_SUCCESS : HDF_FAILURE; + if (ec == HDF_SUCCESS && fdId >=0) { + ec = MatchHdiFd(fdId, hdiFds, fd) ? HDF_SUCCESS : HDF_FAILURE; + } + if (ec == HDF_FAILURE) { + // if matching failure, the illegal fd is transfered by smq directly, + // not by binder IPC + fd = fdId; + } + return ec; + } + + static int32_t BufferHandleUnpack(std::shared_ptr unpacker, + const std::vector& hdiFds, BufferHandle*& buffer) + { + uint32_t fdsNum = 0; + uint32_t intsNum = 0; + bool retVal = unpacker->ReadUint32(fdsNum); + if (retVal) { + retVal = unpacker->ReadUint32(intsNum); + } + BufferHandle* handle = AllocateBufferHandle(fdsNum, intsNum); + retVal = (handle == nullptr ? false : true); + if (retVal) { + handle->reserveFds = fdsNum; + handle->reserveInts = intsNum; + } + int32_t ec = HDF_SUCCESS; + if (retVal) { + ec = FileDescriptorUnpack(unpacker, hdiFds, handle->fd); + retVal = (ec == HDF_SUCCESS ? true : false); + } + if (retVal) { + retVal = unpacker->ReadInt32(handle->width); + } + if (retVal) { + retVal = unpacker->ReadInt32(handle->stride); + } + if (retVal) { + retVal = unpacker->ReadInt32(handle->height); + } + if (retVal) { + retVal = unpacker->ReadInt32(handle->size); + } + if (retVal) { + retVal = unpacker->ReadInt32(handle->format); + } + if (retVal) { + retVal = unpacker->ReadUint64(handle->usage); + } + if (retVal) { + retVal = unpacker->ReadUint64(handle->phyAddr); + } + if (retVal) { + retVal = unpacker->ReadInt32(handle->key); + } + if (retVal) { + int32_t i = 0; + for (i = 0; i < handle->reserveFds; i++) { + ec = FileDescriptorUnpack(unpacker, hdiFds, handle->reserve[i]); + if (ec != HDF_SUCCESS) { + retVal = false; + break; + } + } + for (int32_t j = 0; j < handle->reserveInts; j++) { + retVal = unpacker->ReadInt32(handle->reserve[i++]); + if (!retVal) { + break; + } + } + } + buffer = handle; + + return retVal ? HDF_SUCCESS : HDF_FAILURE; + } +}; +using CmdUtils = DisplayCmdUtils; +} // V1_0 +} // Display +} // HDI +} // OHOS +#endif diff --git a/display/v1_0/hdi_impl/.display_device_hdi_impl.h.swp b/display/v1_0/hdi_impl/.display_device_hdi_impl.h.swp new file mode 100644 index 0000000000000000000000000000000000000000..f212e0ece1fdd68ff8be9acced62c0f4e072b2f7 GIT binary patch literal 16384 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 +class DisplayDeviceHdiImpl : + public Interface, + public IHotPlugCallback, + public IVBlankCallback +{ +public: + static std::unique_ptr create() + { + sptr hdi = Hdi::Get(); + std::shared_ptr req = CmdReq::Create(hdi); + return std::make_unique(hdi, req); + } + + DisplayDeviceHdiImpl(sptr hdi, std::shared_ptr req) + : hdi_(hdi), + req_(req), + hotPlugCb_(nullptr), + vBlankCb_(nullptr), + hotPlugCbData_(nullptr), + vBlankCbData_(nullptr) + { + } + + virtual ~DisplayDeviceHdiImpl() + { + } + + // *** device func + virtual int32_t RegHotPlugCallback(HotPlugCallback cb, void *data) override + { + hotPlugCb_ = cb; + hotPlugCbData_ = data; + return hdi_->RegHotPlugCallback(this); + } + + virtual int32_t GetDisplayCapability(uint32_t devId, DisplayCapability& info) override + { + return hdi_->GetDisplayCapability(devId, info); + } + + virtual int32_t GetDisplaySupportedModes(uint32_t devId, + std::vector& modes) override + { + return hdi_->GetDisplaySupportedModes(devId, modes); + } + + virtual int32_t GetDisplayMode(uint32_t devId, uint32_t& modeId) override + { + return hdi_->GetDisplayMode(devId, modeId); + } + + virtual int32_t SetDisplayMode(uint32_t devId, uint32_t modeId) override + { + return hdi_->SetDisplayMode(devId, modeId); + } + + virtual int32_t GetDisplayPowerStatus(uint32_t devId, DispPowerStatus& status) override + { + return hdi_->GetDisplayPowerStatus(devId, status); + } + + virtual int32_t SetDisplayPowerStatus(uint32_t devId, DispPowerStatus status) override + { + return hdi_->SetDisplayPowerStatus(devId, status); + } + + virtual int32_t GetDisplayBacklight(uint32_t devId, uint32_t& level) override + { + return hdi_->GetDisplayBacklight(devId, level); + } + + virtual int32_t SetDisplayBacklight(uint32_t devId, uint32_t level) override + { + return hdi_->SetDisplayBacklight(devId, level); + } + + virtual int32_t GetDisplayProperty(uint32_t devId, uint32_t id, uint64_t& value) override + { + return hdi_->GetDisplayProperty(devId, id, value); + } + + virtual int32_t GetDisplayCompChange(uint32_t devId, std::vector& layers, + std::vector& types) override + { + return hdi_->GetDisplayCompChange(devId, layers, types); + } + + virtual int32_t SetDisplayClientCrop(uint32_t devId, const IRect& rect) override + { + return hdi_->SetDisplayClientCrop(devId, rect); + } + + virtual int32_t SetDisplayClientDestRect(uint32_t devId, const IRect& rect) override + { + return hdi_->SetDisplayClientDestRect(devId, rect); + } + + virtual int32_t SetDisplayClientBuffer(uint32_t devId, + const BufferHandle& buffer, int32_t fence) override + { + return req_->SetDisplayClientBuffer(devId, buffer, fence); + } + + virtual int32_t SetDisplayClientDamage(uint32_t devId, std::vector& rects) override + { + return req_->SetDisplayClientDamage(devId, rects); + } + + virtual int32_t SetDisplayVsyncEnabled(uint32_t devId, bool enabled) override + { + return hdi_->SetDisplayVsyncEnabled(devId, enabled); + } + + virtual int32_t RegDisplayVBlankCallback(uint32_t devId, VBlankCallback cb, void* data) override + { + vBlankCb_ = cb; + vBlankCbData_ = data; + return hdi_->RegDisplayVBlankCallback(devId, this); + } + + virtual int32_t GetDisplayReleaseFence(uint32_t devId, std::vector& layers, + std::vector& fences) override + { + std::vector> hdiFences; + int32_t ret = hdi_->GetDisplayReleaseFence(devId, layers, hdiFences); + if (ret == HDF_SUCCESS) { + for (int i = 0; i < hdiFences.size(); i++) { + fences.push_back(hdiFences[i]->Move()); + } + } + return ret; + } + + virtual int32_t CreateVirtualDisplay(uint32_t width, uint32_t height, int32_t& format, + uint32_t& devId) override + { + return hdi_->CreateVirtualDisplay(width, height, format, devId); + } + + virtual int32_t DestroyVirtualDisplay(uint32_t devId) override + { + return hdi_->DestroyVirtualDisplay(devId); + } + + virtual int32_t SetVirtualDisplayBuffer(uint32_t devId, + const BufferHandle& buffer, const int32_t fence) override + { + int32_t ret = HDF_SUCCESS; + + sptr hdiBuffer(new BufferHandleParcelable()); + bool bRet = hdiBuffer->Init(buffer); + + if (bRet == false) { + ret = HDF_FAILURE; + } else { + sptr hdiFence(new HdifdParcelable); + hdiFence->Init(fence); + ret = hdi_->SetVirtualDisplayBuffer(devId, hdiBuffer, hdiFence); + } + + return ret; + } + + virtual int32_t SetDisplayProperty(uint32_t devId, uint32_t id, uint64_t value) override + { + return hdi_->SetDisplayProperty(devId, id, value); + } + + virtual int32_t Commit(uint32_t devId, int32_t& fence) override + { + return req_->Commit(devId, fence); + } + + // *** layer func + virtual int32_t CreateLayer(uint32_t devId, const LayerInfo& layerInfo, + uint32_t& layerId) override + { + return hdi_->CreateLayer(devId, layerInfo, layerId); + } + + virtual int32_t CloseLayer(uint32_t devId, uint32_t layerId) override + { + return hdi_->CloseLayer(devId, layerId); + } + + virtual int32_t PrepareDisplayLayers(uint32_t devId, bool& needFlushFb) override + { + return req_->PrepareDisplayLayers(devId, needFlushFb); + } + + virtual int32_t SetLayerAlpha(uint32_t devId, uint32_t layerId, const LayerAlpha& alpha) override + { + return req_->SetLayerAlpha(devId, layerId, alpha); + } + + virtual int32_t SetLayerSize(uint32_t devId, uint32_t layerId, const IRect& rect) override + { + return req_->SetLayerSize(devId, layerId, rect); + } + + virtual int32_t SetLayerCrop(uint32_t devId, uint32_t layerId, const IRect& rect) override + { + return req_->SetLayerCrop(devId, layerId, rect); + } + + virtual int32_t SetLayerZorder(uint32_t devId, uint32_t layerId, uint32_t zorder) override + { + return req_->SetLayerZorder(devId, layerId, zorder); + } + + virtual int32_t SetLayerPreMulti(uint32_t devId, uint32_t layerId, bool preMul) override + { + return req_->SetLayerPreMulti(devId, layerId, preMul); + } + + virtual int32_t SetTransformMode(uint32_t devId, uint32_t layerId, TransformType type) override + { + return req_->SetTransformMode(devId, layerId, type); + } + + virtual int32_t SetLayerDirtyRegion(uint32_t devId, uint32_t layerId, + const IRect& region) override + { + return req_->SetLayerDirtyRegion(devId, layerId, region); + } + + virtual int32_t SetLayerVisibleRegion(uint32_t devId, uint32_t layerId, + std::vector& rects) override + { + return req_->SetLayerVisibleRegion(devId, layerId, rects); + } + + virtual int32_t SetLayerBuffer(uint32_t devId, uint32_t layerId, + BufferHandle& buffer, int32_t fence) override + { + return req_->SetLayerBuffer(devId, layerId, buffer, fence); + } + + virtual int32_t SetLayerCompositionType(uint32_t devId, uint32_t layerId, + CompositionType type) override + { + return req_->SetLayerCompositionType(devId, layerId, type); + } + + virtual int32_t SetLayerBlendType(uint32_t devId, uint32_t layerId, BlendType type) override + { + return req_->SetLayerBlendType(devId, layerId, type); + } + + virtual int32_t SetLayerVisible(uint32_t devId, uint32_t layerId, bool visible) override + { + return req_->SetLayerVisible(devId, layerId, visible); + } + + // Callback implement + virtual int32_t OnHotPlug(uint32_t outputId, bool connected) override + { + int32_t ret = HDF_SUCCESS; + if (hotPlugCb_ != nullptr) { + hotPlugCb_(outputId, connected, hotPlugCbData_); + } else { + HDF_LOGE("erroe: hot plug callback fn is nullptr"); + ret = HDF_FAILURE; + } + + return ret; + } + + virtual int32_t OnVBlank(uint32_t sequence, uint64_t ns) override + { + int32_t ret = HDF_SUCCESS; + if (vBlankCb_ != nullptr) { + vBlankCb_(sequence, ns, vBlankCbData_); + } else { + HDF_LOGE("erroe: vblank callback fn is nullptr"); + ret = HDF_FAILURE; + } + + return ret; + } + +private: + sptr hdi_; + std::shared_ptr req_; + HotPlugCallback hotPlugCb_; + VBlankCallback vBlankCb_; + void* hotPlugCbData_; + void* vBlankCbData_; +}; +using HdiDisplayDeviceImpl = + DisplayDeviceHdiImpl; +} // V1_0 +} // Display +} // HDI +} // OHOS +#endif diff --git a/display/v1_0/include/idisplay_device_interface.h b/display/v1_0/include/idisplay_device_interface.h new file mode 100644 index 00000000..770594c2 --- /dev/null +++ b/display/v1_0/include/idisplay_device_interface.h @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2022 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. + */ + +#ifndef OHOS_HDI_DISPLAY_V1_0_IDISPLAYDEVICEINTERFACE_H +#define OHOS_HDI_DISPLAY_V1_0_IDISPLAYDEVICEINTERFACE_H + +#include +#include "display_common.h" +#include "display/v1_0/hdi_display_device_type.h" + +namespace OHOS { +namespace HDI { +namespace Display { +namespace V1_0 { + +using namespace OHOS::HDI::Display::V1_0; + +class IDisplayDeviceInterface { +public: + virtual ~IDisplayDeviceInterface() = default; + // *** device func + virtual int32_t RegHotPlugCallback(HotPlugCallback cb, void *data) = 0; + virtual int32_t GetDisplayCapability(uint32_t devId, DisplayCapability& info) = 0; + virtual int32_t GetDisplaySupportedModes(uint32_t devId, + std::vector& modes) = 0; + virtual int32_t GetDisplayMode(uint32_t devId, uint32_t& modeId) = 0; + virtual int32_t SetDisplayMode(uint32_t devId, uint32_t modeId) = 0; + virtual int32_t GetDisplayPowerStatus(uint32_t devId, DispPowerStatus& status) = 0; + virtual int32_t SetDisplayPowerStatus(uint32_t devId, DispPowerStatus status) = 0; + virtual int32_t GetDisplayBacklight(uint32_t devId, uint32_t& level) = 0; + virtual int32_t SetDisplayBacklight(uint32_t devId, uint32_t level) = 0; + virtual int32_t GetDisplayProperty(uint32_t devId, uint32_t id, uint64_t& value) = 0; + virtual int32_t GetDisplayCompChange(uint32_t devId, std::vector& layers, + std::vector& types) = 0; + virtual int32_t SetDisplayClientCrop(uint32_t devId, const IRect& rect) = 0; + virtual int32_t SetDisplayClientDestRect(uint32_t devId, const IRect& rect) = 0; + virtual int32_t SetDisplayClientBuffer(uint32_t devId, + const BufferHandle& buffer, int32_t fence) = 0; + virtual int32_t SetDisplayClientDamage(uint32_t devId, std::vector& rects) = 0; + virtual int32_t SetDisplayVsyncEnabled(uint32_t devId, bool enabled) = 0; + virtual int32_t RegDisplayVBlankCallback(uint32_t devId, VBlankCallback cb, + void* data) = 0; + virtual int32_t GetDisplayReleaseFence(uint32_t devId, std::vector& layers, + std::vector& fences) = 0; + virtual int32_t CreateVirtualDisplay(uint32_t width, uint32_t height, int32_t& format, + uint32_t& devId) = 0; + virtual int32_t DestroyVirtualDisplay(uint32_t devId) = 0; + virtual int32_t SetVirtualDisplayBuffer(uint32_t devId, + const BufferHandle& buffer, const int32_t fence) = 0; + virtual int32_t SetDisplayProperty(uint32_t devId, uint32_t id, uint64_t value) = 0; + virtual int32_t Commit(uint32_t devId, int32_t& fence) = 0; + // *** layer func + virtual int32_t CreateLayer(uint32_t devId, const LayerInfo& layerInfo, + uint32_t& layerId) = 0; + virtual int32_t CloseLayer(uint32_t devId, uint32_t layerId) = 0; + virtual int32_t PrepareDisplayLayers(uint32_t devId, bool& needFlushFb) = 0; + virtual int32_t SetLayerAlpha(uint32_t devId, uint32_t layerId, const LayerAlpha& alpha) = 0; + virtual int32_t SetLayerSize(uint32_t devId, uint32_t layerId, const IRect& rect) = 0; + virtual int32_t SetLayerCrop(uint32_t devId, uint32_t layerId, const IRect& rect) = 0; + virtual int32_t SetLayerZorder(uint32_t devId, uint32_t layerId, uint32_t zorder) = 0; + virtual int32_t SetLayerPreMulti(uint32_t devId, uint32_t layerId, bool preMul) = 0; + virtual int32_t SetTransformMode(uint32_t devId, uint32_t layerId, TransformType type) = 0; + virtual int32_t SetLayerDirtyRegion(uint32_t devId, uint32_t layerId, + const IRect& region) = 0; + virtual int32_t SetLayerVisibleRegion(uint32_t devId, uint32_t layerId, + std::vector& rects) = 0; + virtual int32_t SetLayerBuffer(uint32_t devId, uint32_t layerId, + BufferHandle& buffer, int32_t fence) = 0; + virtual int32_t SetLayerCompositionType(uint32_t devId, uint32_t layerId, + CompositionType type) = 0; + virtual int32_t SetLayerBlendType(uint32_t devId, uint32_t layerId, BlendType type) = 0; + virtual int32_t SetLayerVisible(uint32_t devId, uint32_t layerId, bool visible) = 0; +}; +} // V1_0 +} // Display +} // HDI +} // OHOS + +#endif // OHOS_HDI_DISPLAY_V1_0_IDISPLAYDEVICEINTERFACE_H diff --git a/gralloc/BUILD.gn b/gralloc/BUILD.gn new file mode 100755 index 00000000..a5e1b329 --- /dev/null +++ b/gralloc/BUILD.gn @@ -0,0 +1,24 @@ +# Copyright (c) 2021 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. + +import("//build/ohos.gni") +import("//vendor/${product_company}/${product_name}/product.gni") + +group("gralloc_interface_entry") { + deps = [ + "v1_0:libgralloc_proxy_1.0", + "v1_0:libgralloc_hdi_impl", + "//drivers/interface/display/buffersequence:libbufferhandle_parcelable", + ] +} + diff --git a/gralloc/bundle.json b/gralloc/bundle.json new file mode 100644 index 00000000..db859ac4 --- /dev/null +++ b/gralloc/bundle.json @@ -0,0 +1,42 @@ +{ + "name": "drivers_interface_gralloc", + "description": "gralloc device driver interface", + "version": "3.2", + "license": "Apache License 2.0", + "component": { + "name": "drivers_interface_gralloc", + "subsystem": "hdf", + "syscap": [""], + "adapter_system_type": ["standard"], + "rom": "675KB", + "ram": "1024KB", + "deps": { + "components": [ + "ipc", + "hdf_core", + "hiviewdfx_hilog_native", + "utils_base" + ], + "third_part": [ + "bounds_checking_function" + ] + }, + "build": { + "sub_component": [ + "//drivers/interface/gralloc:gralloc_interface_entry" + ], + "test": [ + ], + "inner_kits": [ + { + "name": "//drivers/interface/gralloc/v1_0:libgralloc_proxy_1.0", + "header": { + "header_files": [ + ], + "header_base": "//drivers/interface/gralloc" + } + } + ] + } + } +} diff --git a/gralloc/v1_0/.BUILD.gn.swp b/gralloc/v1_0/.BUILD.gn.swp new file mode 100644 index 0000000000000000000000000000000000000000..9ee2fa9e591af8968bc9c21f5640f37af9009cae GIT binary patch literal 12288 zcmeI2L2nyH6vrnVI6wo4p5XM@pvsY4uj8s!)vA@;B+wP9BgILp3ZZ4ZJ8KVF?@VWA z;}}%ngt&6$6HswLf(svjZvYo0z5rY*4u~uN-K;}WDwQi_M*4d_GjHC!`MueL|eTkhO%(NWIPe!*zi18NqDdpcf(tI(bh(1T>QJO zy_F|$#tGODq+Mp0dTaHoz7o7a=U?4B<4pYVJpoU^6YvB)0Z+ga@B}=8vqiw^CH4u9 z{9JSF3(a%siD%RG4^O}o@B};oPrwuK1Uvyxz!UHUJONL@6Zj7j;3;E&yujF_7ZE)E z|6lz6|M6wUzJLbMn@|A#{t{!4p+}H_UWa~KX6!rYTj+DBfVQBU&;=-fUW1;8emlq5 zuh7rX_t2Nnr_hJc97>_{&@yxm`V%qz0(}F04OKCI1^MO)cmke)C*TQq0-k^;;0gTi z2|Q#(m54MqE-v^~&ALx ziRc#aPLP_UvK1`)tMn0jNFuiaUyiYtqg*C&qKZt8YoAA`QlXD~W1~vl3P7WA6>Fmo z=kZ#n8&pnZMy*t2vJh!YO_Ysu>BMS1Gu6tt)(Pf37R5l&K>Vt3@I+nb2|W#|lN(g)GJd$Wv);?G#Cb zmwVCf?d`o?y4T;?=?`|J%^_{?(E9dZBifC&2k5;;{lR^DCmL+DNk{}?NE~V-tR?Iy zr#hD+tpdWeaYl|xC(?gLOwyh*PzCXVg8q=AVL-R~!)VxskG&$V92?v@Y2arxCtMBW zq`p%*pH+MEu@RVaiey1EBOQ*`CaW?x<3_L*_^H~&Ieje*XR}#{Yo1I*N11U5UllxgW=}I9_r$&CHGZHQ$8m(avXj+B}${0or26AEa#17p&XUCKW>7lha^ZMutB4~ZhgN3AONL9-}Wy$%oSh|b9I#8E3* arCzt!quV8)2}v8`0B3|jr%hW9srd_|X{ka0 literal 0 HcmV?d00001 diff --git a/gralloc/v1_0/BUILD.gn b/gralloc/v1_0/BUILD.gn new file mode 100755 index 00000000..f1d07979 --- /dev/null +++ b/gralloc/v1_0/BUILD.gn @@ -0,0 +1,76 @@ +# Copyright (c) 2022 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. + +import("//drivers/hdf_core/adapter/uhdf2/hdi.gni") +if (defined(ohos_lite)) { + group("libgralloc_proxy_1.0") { + deps = [] + public_configs = [] + } +} else { + hdi("gralloc") { + module_name = "gralloc" + + sources = [ + "IAllocatorInterface.idl", + "IMapperInterface.idl", + "GrallocTypes.idl", + ] + + sequenceable = [ + "//drivers/interface/display/buffersequence:libbufferhandle_parcelable", + ] + + language = "cpp" + subsystem_name = "hdf" + part_name = "drivers_interface_gralloc" + } +} + +ohos_shared_library("libgralloc_hdi_impl") { + + sources = [ + "hdi_impl/gralloc_hdi_impl.cpp", + ] + + include_dirs = [ + "../", + "hdi_impl", + "include", + ] + + cflags = [ + "-Wall", + "-Wextra", + "-Werror", + "-fsigned-char", + "-fno-common", + "-fno-strict-aliasing", + ] + + deps = [ + "//drivers/interface/display/buffersequence:libbufferhandle_parcelable", + "//foundation/graphic/graphic_2d/utils/buffer_handle:buffer_handle", + "//drivers/interface/gralloc/v1_0:libgralloc_proxy_1.0", + ] + + external_deps = [ + "utils_base:utils", + "ipc:ipc_core", + "hiviewdfx_hilog_native:libhilog", + ] + + install_images = [ chipset_base_dir ] + subsystem_name = "hdf" + part_name = "drivers_interface_gralloc" +} diff --git a/gralloc/v1_0/GrallocTypes.idl b/gralloc/v1_0/GrallocTypes.idl new file mode 100644 index 00000000..77b51401 --- /dev/null +++ b/gralloc/v1_0/GrallocTypes.idl @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2022 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. + */ + +package ohos.hdi.gralloc.v1_0; + +struct AllocInfo { + unsigned int width; + unsigned int height; + unsigned long usage; + unsigned int format; + unsigned int expectedSize; +}; + +struct VerifyAllocInfo { + unsigned int width; + unsigned int height; + unsigned long usage; + unsigned int format; +}; + diff --git a/gralloc/v1_0/IAllocatorInterface.idl b/gralloc/v1_0/IAllocatorInterface.idl new file mode 100755 index 00000000..dfee4525 --- /dev/null +++ b/gralloc/v1_0/IAllocatorInterface.idl @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2022 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. + */ + +package ohos.hdi.gralloc.v1_0; + +import ohos.hdi.gralloc.v1_0.GrallocTypes; + +sequenceable OHOS.HDI.Display.BufferHandleParcelable; + +interface IAllocatorInterface { + AllocMem([in] struct AllocInfo info, [out] BufferHandleParcelable handle); +} diff --git a/gralloc/v1_0/IMapperInterface.idl b/gralloc/v1_0/IMapperInterface.idl new file mode 100755 index 00000000..5df22f02 --- /dev/null +++ b/gralloc/v1_0/IMapperInterface.idl @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2022 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. + */ + +package ohos.hdi.gralloc.v1_0; + +import ohos.hdi.gralloc.v1_0.GrallocTypes; + +sequenceable OHOS.HDI.Display.BufferHandleParcelable; + +interface IMapperInterface { + FreeMem([in] BufferHandleParcelable handle); + Mmap([in] BufferHandleParcelable handle); + MmapCache([in] BufferHandleParcelable buffer); + Unmap([in] BufferHandleParcelable handle); + FlushCache([in] BufferHandleParcelable handle); + FlushMCache([in] BufferHandleParcelable buffer); + InvalidateCache([in] BufferHandleParcelable handle); +} diff --git a/gralloc/v1_0/hdi_impl/.gralloc_hdi_impl.cpp.swp b/gralloc/v1_0/hdi_impl/.gralloc_hdi_impl.cpp.swp new file mode 100644 index 0000000000000000000000000000000000000000..41b96da60d3c3320716bfbc0293aca82054e40da GIT binary patch literal 16384 zcmeI2ON2ERVZ z*w5etZ~|-u-)v;;0{94g2+jcuEP#{XFxU-tfbHNV*aj}Ig-!4!u)z#C0uF z1pEODpa9l_tB*7G2e<;h0H1?%AOqHd-ydV_6Yws02b>2-K>=(9KdfQwGjJZf4$gvQ zFa~ymwczVV5f6M|03EynHiJ#zH*CIK0H?qlm;eVr7W{>Fy9&Mq=fGhw1h#^9!xjg^YL$CK<1vFF= zG@iE`x+P3K;5pr>^K?6Rl1-Ll^Crb6r*zx2_)*<6xTRMto;DoY56Xt_2m88H^o^(M zQPTdzjPC~CiWD6i;aKNXe8b@;FP9$@F>}6}`f*K1vFuC=RU|$?{*w zbkGX@`pjyVsN2hXFVB6UPVD486=&W?Z(GG3EB5bBC20sRYnom>xX6Kr29h8QFX?EM z*-ujw2g{}TTyC;dqL-51IowK?Av?4z3=GK_aW}))45VEx&z%%ufO?0mj)(WJ!mHrn zy}7vYJLq;^1nrmJL67qpzPL)Nb=@P=a_>$bnD#^m z5Nj3P=22E3#U*x6N(OE+KS&-6h?Jj+rbYSIvDQrH5D(IU7xKj6PTgecs5DvAo(xEQ zhV_mEEAP|&Ow;gN2C@N?If}q+O1BNZHwkVcxW=6+HuAWE0!>p z{S4)F`-LEyyXiC`eAm*K5+8Dw;C29o;=)pcR4!LT+bEaed2Cjo!CUdPzy0{g7Ecl+ zndPH}>0xi}T6R!EAPmYU@ok|7+NF0to0=xg-yrdIL2=9UW5J*=a^J-fWIBeU$8fI` zkd(P1Y-%FE;=VXlEFpkx6SiT6CZ|;0td=dOHe6421=ixZXy+g^Vi^r+fGn{nWGyih zrqDLIM?sy_v@p2s^I@5y#CdlZRh>AE?{Y&_A&;fowNS5ds$s(J*}|?7X6K8-_am#A zNlP=w^K(Cn7wNz)!b6$%fA zDocd^gU3%U4N$43ELE>zur(=g(BjneM1a~2lJ8W5rtWc=k(T6D4+1x%Y0YMHSVx1_ z`LN^FG+2{5`r33pH(4l64vpeGe4Oco6Ji~+L{25pVOz(n-^E>Zh1Pl??Jp%sZ6}}* zBVSNQ6{`YX^3w))WnVyUsgLY^)P#23RwBug7VXw68~NF4>p?n(L-A-af{&DzPeCfl zl#=7e0OjDICu;S8(nddxj*RZ4sZeinK@+@ziXy@AAWa8oBW-}m_5b@=!^<_jT>oPU z9$lYet^Wo%2V8IxWWX5M1Ga$;;O`{wWtm@HN&%&SQa~x76i^B%1(X6x0i}RaKq;UU z_&*g`ChRA5_H5*S4C@KQo=tC1vbED2EVqDqzWT|%vB}xla-lefFA+zN7H8+;J<#}T zgCDxC<6#%X?+%rFhX{!GNBzLeWE$MSKHt8I<5=U=*U8nNd}?fMfhLZ1K3e*vRteE= XVX|4>Z4;XYqPo=HxrF(s_(Ap$D$HDt literal 0 HcmV?d00001 diff --git a/gralloc/v1_0/hdi_impl/gralloc_hdi_impl.cpp b/gralloc/v1_0/hdi_impl/gralloc_hdi_impl.cpp new file mode 100644 index 00000000..28b06308 --- /dev/null +++ b/gralloc/v1_0/hdi_impl/gralloc_hdi_impl.cpp @@ -0,0 +1,116 @@ +/* + * Copyright (c) 2021 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. + */ + +#include "gralloc_hdi_impl.h" +#include "hdf_log.h" + +namespace OHOS { +namespace HDI { +namespace Gralloc { +namespace V1_0 { + +GrallocHdiImpl::GrallocHdiImpl() +{ + allocator_ = IAllocatorInterface::Get(); + mapper_ = IMapperInterface::Get(true); +} + +int32_t GrallocHdiImpl::AllocMem(const AllocInfo& info, BufferHandle*& handle) const +{ + sptr hdiBuffer; + int32_t ret = allocator_->AllocMem(info, hdiBuffer); + if (ret == HDF_SUCCESS) { + handle = hdiBuffer->Move(); + } else { + handle = nullptr; + } + return ret; +} + +void GrallocHdiImpl::FreeMem(const BufferHandle& handle) const +{ + sptr hdiBuffer = + new BufferHandleParcelable(const_cast(handle)); + mapper_->FreeMem(hdiBuffer); +} + +void* GrallocHdiImpl::Mmap(const BufferHandle& handle) const +{ + sptr hdiBuffer = + new BufferHandleParcelable(const_cast(handle)); + int32_t ret = mapper_->Mmap(hdiBuffer); + (void)hdiBuffer->Move(); + void *virAddr = (ret == HDF_SUCCESS ? handle.virAddr : nullptr); + return virAddr; +} + +void* GrallocHdiImpl::MmapCache(const BufferHandle& handle) const +{ + sptr hdiBuffer = + new BufferHandleParcelable(const_cast(handle)); + int32_t ret = mapper_->MmapCache(hdiBuffer); + (void)hdiBuffer->Move(); + void *virAddr = (ret == HDF_SUCCESS ? handle.virAddr : nullptr); + return virAddr; +} + +int32_t GrallocHdiImpl::Unmap(const BufferHandle& handle) const +{ + sptr hdiBuffer = + new BufferHandleParcelable(const_cast(handle)); + int32_t ret = mapper_->Unmap(hdiBuffer); + (void)hdiBuffer->Move(); + return ret; +} + +int32_t GrallocHdiImpl::FlushCache(const BufferHandle& handle) const +{ + sptr hdiBuffer = + new BufferHandleParcelable(const_cast(handle)); + int32_t ret = mapper_->FlushCache(hdiBuffer); + (void)hdiBuffer->Move(); + return ret; +} + +int32_t GrallocHdiImpl::FlushMCache(const BufferHandle& handle) const +{ + sptr hdiBuffer = + new BufferHandleParcelable(const_cast(handle)); + int32_t ret = mapper_->FlushMCache(hdiBuffer); + (void)hdiBuffer->Move(); + return ret; +} + +int32_t GrallocHdiImpl::InvalidateCache(const BufferHandle& handle) const +{ + sptr hdiBuffer = + new BufferHandleParcelable(const_cast(handle)); + int32_t ret = mapper_->InvalidateCache(hdiBuffer); + (void)hdiBuffer->Move(); + return ret; +} + +int32_t GrallocHdiImpl::IsSupportedAlloc(const std::vector &infos, + std::vector &supporteds) const +{ + (void)infos; + (void)supporteds; + return HDF_ERR_NOT_SUPPORT; +} + +} // namespace V1_0 +} // namespace Gralloc +} // namespace HDI +} // namespace OHOS diff --git a/gralloc/v1_0/hdi_impl/gralloc_hdi_impl.h b/gralloc/v1_0/hdi_impl/gralloc_hdi_impl.h new file mode 100644 index 00000000..1a66641b --- /dev/null +++ b/gralloc/v1_0/hdi_impl/gralloc_hdi_impl.h @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2021 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. + */ + +#ifndef GRALLOC_HDI_IMPL_V1_0_H +#define GRALLOC_HDI_IMPL_V1_0_H + +#include "buffer_handle.h" +#include "v1_0/include/igralloc_interface.h" +#include "v1_0/iallocator_interface.h" +#include "v1_0/imapper_interface.h" +#include "v1_0/gralloc_types.h" + +namespace OHOS { +namespace HDI { +namespace Gralloc { +namespace V1_0 { +class GrallocHdiImpl : public IGrallocInterface { +public: + GrallocHdiImpl(); + virtual ~GrallocHdiImpl() = default; + + virtual int32_t AllocMem(const AllocInfo& info, BufferHandle*& handle) const override; + virtual void FreeMem(const BufferHandle& handle) const override; + virtual void *Mmap(const BufferHandle& handle) const override; + virtual void *MmapCache(const BufferHandle& handle) const override; + virtual int32_t Unmap(const BufferHandle& handle) const override; + virtual int32_t FlushCache(const BufferHandle& handle) const override; + virtual int32_t FlushMCache(const BufferHandle& handle) const override; + virtual int32_t InvalidateCache(const BufferHandle& handle) const override; + virtual int32_t IsSupportedAlloc(const std::vector &infos, + std::vector &supporteds) const override; +private: + sptr allocator_; + sptr mapper_; +}; +} // namespace V1_0 +} // namespace Gralloc +} // namespace HDI +} // namespace OHOS + +#endif // GRALLOC_HDI_IMPL_V1_0_H diff --git a/gralloc/v1_0/include/.igralloc_interface.h.swp b/gralloc/v1_0/include/.igralloc_interface.h.swp new file mode 100644 index 0000000000000000000000000000000000000000..51dc8473e302b2bad10a6906745498f870d7e10b GIT binary patch literal 16384 zcmeI3UyR&F9mj`~PzofVRszuo>BmKc+tv1VbD^Xpm(y+Uuf^S-bbFUJ0%`Hu;faU`-~l9x015R8QPc|F_@hb{QYhaU+q;|H z+omN4g2t9U=h&W^o%#O8Gryl_(yW{{*64w$3d8X(#GSHu^#)%}|s zfpwDv>Elo70?S=rZkMO;oA+&A5ACuaaIbC3j_>U@-tuC=Xj%n+m;*Kye!hYjb6H`_G_z7o+?-1Hc}uwFTz9Y#Po6fsvn(r zKizZp)@{`Oys5bYxdOQYxdOQYxdOQYxdOQYxdKse2m3T+xFeOKlb+u+bbfPseSdoP zhn}aG`6*W*S0Gm)S0Gm)S0Gm)S0Gm)S0Gm)S0Gm)SKxn80n=to#r$W~2LP=9XYv2_ zcQW=YcoeLF_knxCpAIwj0(cUf1BbxR4l#BGTn3lGE~tYIFb6&W4uS*V@9$vjkKkEw z4g3f^1)cyM-~t;Izy$dI+woiAOW?DBgDN-;?gB5qjj^ADAA_slTi`Ny9Mr%vc;zm} zUItgdH^C%$H#h+P@>aA7d<}dRd=Z=n7B~#<1TWpm*dM@i;2Yp^@EDi{C&7zvVeI$d zJa`x^fEn=5gN$7VFM+4QB~Sy);MWIGXYdTT0!;7;@Gy7D0(cKN2>uE? z{TX}*Tm_fF0#Nq52fP>D;z8;tvgAZ_O)0oTORm1&csr&mkPfL;8l6LU{q$4166Io%>3{498O5fHe9?*NMnqd)#|$Pd z-wPvpFm@a+S5U0W=~!Ez3zR%NLzUCI04kQ#GtH^JCBpaUIJUl!I*K$GVp9npyyK%< zvMWNK)I_C`Jc^}98~PN|Omns}Q*O?ZaCE(~n?;(DDp-UR#+Jpy(23pCl;jK1aN<(> z5_PlDWbO!$D=FxaIahewv>?J@QA)Kt=3-j0^h9%kDa{TgjU&Ueh1Jteax|Z->O*5C zW>X77ep0Pebv%oeXjyZ5B_~GKf`+MyN+`yR(2Nr5-tl)}B;*W)*9!Y)4WzGH_(8PG zwk7^WVSueVV+^Y$`?Z=6_O5NM zu4F(ut5LokcNShLMTME}ho#pq~U6Su!tn-5`?vR2bzav%GZX z45bMQ^axYg)L|?qyG)I2+i9`)YlIBEOGYPfCksiTNj_9264qW>mw7Z7BB=i8~jwKs(L*;FZ zRAb1NnG^T?XReJToh(3NxI|{`MyFX2H(gty@ zxVN%k+;F|VvR+rk98EV9(}dnyob4!9h6<QgWlM{EhpHPJ)!L@9Sf}+3nqRLi7@Nj=4OdH4t(~Kf8nuNIarhjl3%?L(-w!`2(8~q4 zVe}%|B8;SH#u47_kxDE7crXD*1-Ql&)jApV33{+vH|ix-$d>0Sw^H&?#zH281iVmm z46_MO-!;30Uo~5p9Bt(c!S(4%5utS@3VkQ)nv$a!RgyZ|Q52jim%H8WlnF<*&8K|X zDx)-|V_04_<`--A#rvjJP@prN^JBQZyX5N*54X|s16(Cub*8l$sq%Nzq@Ev994c#| ziH<-m`2~vyaHT!uR{E%+i?qKsU@HyRb9`_t|dB~1}>;0O{)A8X{HG^CKYKO z6_ldYj%d;<&~#<`IIYBHmkV0pJ7_2pOqFOgf{n^WrsDrDV%QeqTowOk>-*nBtbY|u z0|JM^KM?Ex4Lk$B3!VZMPyoL}Z2v3pF<^j`;3zl(ev3H%H{ciG%is$@#r8+Q(}>}} z4peOK0S6ob_kz2@PZ7Ug1D^+T;3MECh}(YvE`vwG=fH=+3uwdh;FsWs;0kyQdW)U zv#Xz~Zx<+E#oHmgTy?x5K27%p8~BXSZF3zZC|}i-63#UIVg!ypzFsRQJ_!)vxu)N@ zwJHPoRlXtZl5(<)sesv1#eADv+aV49YzzOD)Z4p|Ju5SI$-(F?S&aXJy +#include "buffer_handle.h" +#include "v1_0/gralloc_types.h" + +namespace OHOS { +namespace HDI { +namespace Gralloc { +namespace V1_0 { + +class IGrallocInterface { +public: + virtual ~IGrallocInterface() = default; + + /** + * @brief Obtains all interfaces of IGrallocInterface. + * + * @return Returns IGrallocInterface* if the operation is successful; returns an null point otherwise. + * @since 1.0 + * @version 1.0 + */ + template + static IGrallocInterface* Get() + { + IGrallocInterface* instance = new Impl(); + if (instance == nullptr) { + return nullptr; + } + return instance; + } + + /** + * @brief Allocates memory based on the parameters passed by the GUI. + * + * @param info Indicates the description of the memory to allocate. + * + * @param handle Indicates the pointer to the buffer of the memory to allocate. + * + * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} + * otherwise. + * @since 1.0 + * @version 1.0 + */ + virtual int32_t AllocMem(const AllocInfo &info, BufferHandle *&handle) const = 0; + + /** + * @brief Releases memory. + * + * @param handle Indicates the reference to the buffer of the memory to release. + * + * @since 1.0 + * @version 1.0 + */ + virtual void FreeMem(const BufferHandle &handle) const = 0; + + /** + * @brief Maps memory to memory without cache in the process's address space. + * + * @param handle Indicates the reference to the buffer of the memory to map. + * + * @return Returns the pointer to a valid address if the operation is successful; returns NULL otherwise. + * @since 1.0 + * @version 1.0 + */ + virtual void *Mmap(const BufferHandle &handle) const = 0; + + /** + * @brief Maps memory to memory with cache in the process's address space. + * + * @param handle Indicates the reference to the buffer of the memory to map. + * + * @return Returns the pointer to a valid address if the operation is successful; returns NULL otherwise. + * @since 1.0 + * @version 1.0 + */ + virtual void *MmapCache(const BufferHandle &buffer) const = 0; + + /** + * @brief Unmaps memory, that is, removes mappings from the process's address space. + * + * @param handle Indicates the reference to the buffer of the memory to unmap. + * + * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} + * otherwise. + * @since 1.0 + * @version 1.0 + */ + virtual int32_t Unmap(const BufferHandle &handle) const = 0; + + /** + * @brief Flushes data from the cache to memory and invalidates the data in the cache. + * + * @param handle Indicates the reference to the buffer of the cache to flush. + * + * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} + * otherwise. + * @since 1.0 + * @version 1.0 + */ + virtual int32_t FlushCache(const BufferHandle &handle) const = 0; + + /** + * @brief Flushes data from the cache mapped via {@link Mmap} to memory and invalidates the data in the cache. + * + * @param handle Indicates the reference to the buffer of the cache to flush. + * + * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} + * otherwise. + * @since 1.0 + * @version 1.0 + */ + virtual int32_t FlushMCache(const BufferHandle &buffer) const = 0; + + /** + * @brief Invalidates the cache to update it from memory. + * + * @param handle Indicates the reference to the buffer of the cache, which will be invalidated. + * + * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} + * otherwise. + * @since 1.0 + * @version 1.0 + */ + virtual int32_t InvalidateCache(const BufferHandle &handle) const = 0; + + /** + * @brief Checks whether the given VerifyAllocInfo array is allocatable. + * + * @param infos Indicates the VerifyAllocInfo array. + * @param supporteds Indicates whether the array is allocatable. + * + * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} + * otherwise. + * @since 1.0 + * @version 1.0 + */ + virtual int32_t IsSupportedAlloc(const std::vector &infos, + std::vector &supporteds) const = 0; +}; +} // namespace V1_0 +} // namespace Gralloc +} // namespace HDI +} // namespace OHOS + +#endif // HDI_IGRALLOC_INTERFACE_V1_0_H -- Gitee