From 6b0d14e8aff3cc6dece9af176cab42e1815ced13 Mon Sep 17 00:00:00 2001 From: liuxk Date: Mon, 11 Jul 2022 15:49:36 +0800 Subject: [PATCH 01/24] develop branch merge back --- display/BUILD.gn | 24 + display/buffersequence/BUILD.gn | 54 ++ .../buffer_handle_parcelable.cpp | 278 +++++++ .../buffersequence/buffer_handle_parcelable.h | 55 ++ display/bundle.json | 22 +- display/command_pack/command_data_packer.h | 271 +++++++ display/command_pack/command_data_unpacker.h | 190 +++++ display/hdifdsequence/BUILD.gn | 53 ++ display/hdifdsequence/hdifd_parcelable.cpp | 157 ++++ display/hdifdsequence/hdifd_parcelable.h | 53 ++ 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/BUILD.gn | 42 ++ display/v1_0/HdiDisplayDeviceType.idl | 458 ++++++++++++ display/v1_0/IDisplayDevice.idl | 90 +++ display/v1_0/IHotPlugCallback.idl | 22 + display/v1_0/IRefreshCallback.idl | 22 + display/v1_0/IVBlankCallback.idl | 22 + .../display_command/display_cmd_requester.h | 617 ++++++++++++++++ .../display_command/display_cmd_responser.h | 691 ++++++++++++++++++ .../v1_0/display_command/display_cmd_utils.h | 366 ++++++++++ .../v1_0/hdi_impl/display_device_hdi_impl.h | 331 +++++++++ .../v1_0/include/idisplay_device_interface.h | 150 ++++ 25 files changed, 4529 insertions(+), 9 deletions(-) create mode 100755 display/BUILD.gn create mode 100755 display/buffersequence/BUILD.gn create mode 100755 display/buffersequence/buffer_handle_parcelable.cpp create mode 100755 display/buffersequence/buffer_handle_parcelable.h create mode 100755 display/command_pack/command_data_packer.h create mode 100755 display/command_pack/command_data_unpacker.h create mode 100755 display/hdifdsequence/BUILD.gn create mode 100755 display/hdifdsequence/hdifd_parcelable.cpp create mode 100755 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 100755 display/v1_0/BUILD.gn create mode 100755 display/v1_0/HdiDisplayDeviceType.idl create mode 100755 display/v1_0/IDisplayDevice.idl create mode 100755 display/v1_0/IHotPlugCallback.idl create mode 100755 display/v1_0/IRefreshCallback.idl create mode 100755 display/v1_0/IVBlankCallback.idl create mode 100755 display/v1_0/display_command/display_cmd_requester.h create mode 100755 display/v1_0/display_command/display_cmd_responser.h create mode 100755 display/v1_0/display_command/display_cmd_utils.h create mode 100755 display/v1_0/hdi_impl/display_device_hdi_impl.h create mode 100755 display/v1_0/include/idisplay_device_interface.h diff --git a/display/BUILD.gn b/display/BUILD.gn new file mode 100755 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/BUILD.gn b/display/buffersequence/BUILD.gn new file mode 100755 index 00000000..c600ac0e --- /dev/null +++ b/display/buffersequence/BUILD.gn @@ -0,0 +1,54 @@ +# 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 = [ + "//foundation/graphic/graphic_2d/utils/buffer_handle:buffer_handle", + ] + + external_deps = [ + "utils_base:utils", + "ipc:ipc_core", + "hiviewdfx_hilog_native:libhilog", + ] + + install_images = [ chipset_base_dir ] + subsystem_name = "hdf" + part_name = "display_device_driver" +} diff --git a/display/buffersequence/buffer_handle_parcelable.cpp b/display/buffersequence/buffer_handle_parcelable.cpp new file mode 100755 index 00000000..b68c1443 --- /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() +{ + if (init_ == false) { + 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 +{ + HDF_LOGE("liuxk, %{public}d@%{public}s parcel size=%{public}d, dataptr=%{public}d", + __LINE__, __func__, parcel.GetDataSize(), parcel.GetWritePosition()); + 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; + } + } + HDF_LOGE("liuxk, %{public}d@%{public}s parcel size=%{public}d, dataptr=%{public}d", + __LINE__, __func__, parcel.GetDataSize(), parcel.GetWritePosition()); + 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; + } + 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; + } + } + HDF_LOGE("liuxk, %{public}d@%{public}s reserveFds=%{public}d, reserveInts=%{public}d", __LINE__, __func__, handle_->reserveFds, handle_->reserveInts); + return true; +} + +sptr BufferHandleParcelable::Unmarshalling(Parcel& parcel) +{ + sptr newParcelable = new BufferHandleParcelable(); + HDF_LOGE("liuxk, %{public}d@%{public}s parcel size=%{public}d, readptr=%{public}d", + __LINE__, __func__, parcel.GetDataSize(), parcel.GetReadPosition()); + newParcelable->ExtractFromParcel(parcel); + HDF_LOGE("liuxk, %{public}d@%{public}s parcel size=%{public}d, readptr=%{public}d", + __LINE__, __func__, parcel.GetDataSize(), parcel.GetReadPosition()); + HDF_LOGE("liuxk, %{public}d@%{public}s dump BufferHandleParcelable:\n%{public}s", + __LINE__, __func__, newParcelable->Dump().c_str()); + 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 100755 index 00000000..73dfbb14 --- /dev/null +++ b/display/buffersequence/buffer_handle_parcelable.h @@ -0,0 +1,55 @@ +/* + * 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(); + 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 100755 index 00000000..0e996023 --- /dev/null +++ b/display/command_pack/command_data_packer.h @@ -0,0 +1,271 @@ +/* + * 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 { + +#include +#include +#include +#include + +#define FILE_PATH "/data/hdi_file_log.txt" + +static char logBuffer[1024] = {0}; + +void WriteFile(const char* buff, const int32_t size) +{ + //char path[256] = "/data/hidl_file_log.txt"; + int logFd = -1; + int wSize; + int ret; + + logFd = open(FILE_PATH, O_RDWR | O_CREAT, 00766); // 00766:file operate permission + if (logFd == -1) { + return; + } + lseek(logFd, 0, SEEK_END); + + if (size == -1) { + wSize = strlen(buff); + } else { + wSize = size; + } + + ret = write(logFd , buff, wSize); + if (ret == -1) { + printf("demo test:write image file error.\n"); + } + + close(logFd); +} + +#define F_LOGE(fmt, ...) sprintf(logBuffer, "%d@%s, " fmt "\n", __LINE__, __func__, ##__VA_ARGS__); \ + WriteFile(logBuffer, strlen(logBuffer)) + + + +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; + } + + #define PACK_LOG F_LOGE + void Print() + { + PACK_LOG("---------------------------------------------\n"); + PACK_LOG("ALLOC_PAGE_SIZE =%d\n", ALLOC_PAGE_SIZE); + PACK_LOG("INIT_DATA_SIZE =%d\n", INIT_DATA_SIZE); + PACK_LOG("SECTION_END_MAGIC =0x%x\n", SECTION_END_MAGIC); + PACK_LOG("packSize_ =%d\n", packSize_); + PACK_LOG("writePos_ =%d\n", writePos_); + PACK_LOG("curSecOffset_ =%d\n", curSecOffset_); + PACK_LOG("settingSecLen_ =%d\n", settingSecLen_); + PACK_LOG("curSecLenPos_ =%d\n", curSecLenPos_); + PACK_LOG("data_ =%p\n", data_); + uint32_t i = 0; + for (; 4*i < writePos_;) { + PACK_LOG("%08x ", *reinterpret_cast(data_ + 4*i)); + i++; + if (i%8 == 0) { + PACK_LOG("\n"); + } else if (i%4 == 0) { + PACK_LOG(" "); + } else {} + } + PACK_LOG("\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 100755 index 00000000..1d6bdfa6 --- /dev/null +++ b/display/command_pack/command_data_unpacker.h @@ -0,0 +1,190 @@ +/* + * 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; + } + + #define PACK_LOG F_LOGE + void Print() + { + PACK_LOG("---------------------------------------------\n"); + PACK_LOG("SECTION_END_MAGIC =0x%x\n", SECTION_END_MAGIC); + PACK_LOG("COMMAND_ID_SIZE =%d\n", COMMAND_ID_SIZE); + PACK_LOG("packSize_ =%d\n", packSize_); + PACK_LOG("readPos_ =%d\n", readPos_); + PACK_LOG("curSecOffset_ =%d\n", curSecOffset_); + PACK_LOG("curSecLen_ =%d\n", curSecLen_); + PACK_LOG("data_ =%p\n", data_); + uint32_t i = 0; + for (; 4*i < packSize_;) { + PACK_LOG("%08x ", *reinterpret_cast(data_ + 4*i)); + i++; + if (i%8 == 0) { + PACK_LOG("\n"); + } else if (i%4 == 0) { + PACK_LOG(" "); + } else {} + } + PACK_LOG("\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_); + //HDF_LOGE("liuxk read: readPos=%{public}d, packsize=%{public}d, value=%{public}d.", + // readPos_, packSize_, value); + 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 100755 index 00000000..29e70ca5 --- /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 = "display_device_driver" +} diff --git a/display/hdifdsequence/hdifd_parcelable.cpp b/display/hdifdsequence/hdifd_parcelable.cpp new file mode 100755 index 00000000..1f371c6f --- /dev/null +++ b/display/hdifdsequence/hdifd_parcelable.cpp @@ -0,0 +1,157 @@ +/* + * 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() +{ + 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 +{ + HDF_LOGE("liuxk, %{public}d@%{public}s parcel size=%{public}d, dataptr=%{public}d", + __LINE__, __func__, parcel.GetDataSize(), parcel.GetData()); + 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; + } + HDF_LOGE("liuxk, %{public}d@%{public}s parcel size=%{public}d, dataptr=%{public}d", + __LINE__, __func__, parcel.GetDataSize(), parcel.GetData()); + + return true; +} + +sptr HdifdParcelable::Unmarshalling(Parcel& parcel) +{ + bool validFlag = false; + HDF_LOGE("liuxk, %{public}d@%{public}s parcel size=%{public}d, dataptr=%{public}d", + __LINE__, __func__, parcel.GetDataSize(), parcel.GetData()); + 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(); + newParcelable->Init(fd); + HDF_LOGE("liuxk, %{public}d@%{public}s parcel size=%{public}d, dataptr=%{public}d", + __LINE__, __func__, parcel.GetDataSize(), parcel.GetData()); + HDF_LOGE("liuxk, %{public}d@%{public}s dump HdifdParcelable:\n%{public}s", + __LINE__, __func__, newParcelable->Dump().c_str()); + 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 100755 index 00000000..cfbee816 --- /dev/null +++ b/display/hdifdsequence/hdifd_parcelable.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 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(); + 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..e4fbd1fc --- /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..63cef320 --- /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..9e10ec27 --- /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/BUILD.gn b/display/v1_0/BUILD.gn new file mode 100755 index 00000000..49e4ef04 --- /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 = "display_device_driver" + } +} diff --git a/display/v1_0/HdiDisplayDeviceType.idl b/display/v1_0/HdiDisplayDeviceType.idl new file mode 100755 index 00000000..c512a5fb --- /dev/null +++ b/display/v1_0/HdiDisplayDeviceType.idl @@ -0,0 +1,458 @@ +/* + * 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 AllocInfo { + unsigned int width; + unsigned int height; + unsigned long usage; + enum PixelFormat format; + unsigned int expectedSize; +}; +struct HDRCapability { + unsigned int formatCount; + enum HDRFormat[] formats; + float maxLum; + float maxAverageLum; + float minLum; +}; +struct HDRMetaData { + enum HDRMetadataKey key; + float value; +}; +struct VerifyAllocInfo { + unsigned int width; + unsigned int height; + unsigned long usage; + enum PixelFormat format; +}; +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 100755 index 00000000..4caa73dd --- /dev/null +++ b/display/v1_0/IDisplayDevice.idl @@ -0,0 +1,90 @@ +/* + * 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] unsigned int num, + [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 num, + [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 num, + [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); + //TestFn([in] unsigned int inEleCnt, [in] unsigned int[] inFdCnt, + // [in] HdifdParcelable[] inFds, [out] unsigned int outEleCnt, + // [out] unsigned int[] outFdCnt, [out] HdifdParcelable[] outFds); + + // interfaces implement by smq + //PrepareDisplayLayers([in] unsigned int devId, [out] boolean needFlushFb); + //SetDisplayClientBuffer([in] unsigned int devId, [in] BufferHandleParcelable buffer, + // [in] int fence); + //SetDisplayClientDamage([in] unsigned int devId, [out] unsigned int num, + // [out] struct IRect[] rect); + //Commit([in] unsigned int devId, [out] int fence); + //SetLayerAlpha([in] unsigned int devId, [in] unsigned int layerId, + // [in] struct LayerAlpha alpha); + //SetLayerSize([in] unsigned int devId, [in] unsigned int layerId, [in] struct IRect rect); + //SetLayerCrop([in] unsigned int devId, [in] unsigned int layerId, [in] struct IRect rect); + //SetLayerZorder([in] unsigned int devId, [in] unsigned int layerId, [in] unsigned int zorder); + //SetLayerPreMulti([in] unsigned int devId, [in] unsigned int layerId, [in] boolean preMul); + //SetTransformMode([in] unsigned int devId, [in] unsigned int layerId, + // [in] enum TransformType type); + //SetLayerDirtyRegion([in] unsigned int devId, [in] unsigned int layerId, + // [in] struct IRect region); + //SetLayerVisibleRegion([in] unsigned int devId, [in] unsigned int layerId, + // [out] unsigned int num, [out] struct IRect[] rect); + //SetLayerBuffer = , + // [in] BufferHandleParcelable buffer, [in] int fence); + //SetLayerCompositionType = , + // [in] enum CompositionType type); + //SetLayerBlendType = , + // [in] enum BlendType type); + //SetLayerVisible = , +} diff --git a/display/v1_0/IHotPlugCallback.idl b/display/v1_0/IHotPlugCallback.idl new file mode 100755 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 100755 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 100755 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 100755 index 00000000..161b6cc4 --- /dev/null +++ b/display/v1_0/display_command/display_cmd_requester.h @@ -0,0 +1,617 @@ +/* + * 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); + F_LOG("liuxk, ec=%d", ec); + } + + if (ec == HDF_SUCCESS) { + ec = DoReplyResults(replyEleCnt, outFds, replyData, [&](void* data)->int32_t { + fence = *(reinterpret_cast(data)); + return HDF_SUCCESS; + }); + F_LOG("liuxk, ec=%d, fence=%d", ec, fence); + } + + if (ec != HDF_SUCCESS) { + HDF_LOGE("Commit failure, ec=%{public}d", ec); + } + + F_LOG("liuxk, ec=%d, fence=%d", ec, fence); + 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->Print(); // 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); + F_LOG("liuxk, ec=%d, fenceFd=%d", ec, fenceFd); + if (ec == HDF_SUCCESS) { + ec = fn(&fenceFd); + F_LOG("liuxk, ec=%d, fenceFd=%d", ec, fenceFd); + } + F_LOG("liuxk, ec=%d, fenceFd=%d", ec, 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; + F_LOG("liuxk, ec=%d", ec); + } + F_LOG("liuxk, ec=%d", ec); + 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_->Print(); // 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 100755 index 00000000..b1a0de04 --- /dev/null +++ b/display/v1_0/display_command/display_cmd_responser.h @@ -0,0 +1,691 @@ +/* + * 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_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) + { + HDF_LOGE("DisplayCmdRequester constructor"); + } + + 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; + } + } + 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->Print(); // 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_->Print(); // 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; + if (ec == HDF_SUCCESS) { + ec = CmdUtils::BufferHandleUnpack(unpacker, inFds, buffer); + } + BufferHandleParcelable bufParcel; + if (ec == HDF_SUCCESS) { + ec = bufParcel.Init(buffer) ? HDF_SUCCESS : HDF_FAILURE; + } + + int32_t fence = -1; + if (ec == HDF_SUCCESS) { + ec = CmdUtils::FileDescriptorUnpack(unpacker, inFds, fence); + } + HdifdParcelable fdParcel; + if (ec == HDF_SUCCESS) { + ec = fdParcel.Init(fence) ? HDF_SUCCESS : HDF_FAILURE; + } + + if (ec == HDF_SUCCESS) { + ec = impl_->SetDisplayClientBuffer(devId, *bufParcel.GetBufferHandle(), + fdParcel.GetFd()); + } + 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; + if (ec == HDF_SUCCESS) { + ec = fdParcel.Init(fence) ? HDF_SUCCESS : HDF_FAILURE; + } + // 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); + + F_LOG("liuxk, devId=%d, layerId=%d", devId, layerId); + BufferHandle buffer; + if (ec == HDF_SUCCESS) { + ec = CmdUtils::BufferHandleUnpack(unpacker, inFds, buffer); + } + BufferHandleParcelable bufParcel; + if (ec == HDF_SUCCESS) { + ec = bufParcel.Init(buffer) ? HDF_SUCCESS : HDF_FAILURE; + } + + F_LOG("liuxk, ec=%d", ec); + int32_t fence = -1; + if (ec == HDF_SUCCESS) { + ec = CmdUtils::FileDescriptorUnpack(unpacker, inFds, fence); + } + HdifdParcelable fdParcel; + if (ec == HDF_SUCCESS) { + ec = fdParcel.Init(fence) ? HDF_SUCCESS : HDF_FAILURE; + } + + if (ec == HDF_SUCCESS) { + ec = impl_->SetLayerBuffer(devId, layerId, *bufParcel.GetBufferHandle(), + fdParcel.GetFd()); + } + 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 100755 index 00000000..08a1dd39 --- /dev/null +++ b/display/v1_0/display_command/display_cmd_utils.h @@ -0,0 +1,366 @@ +/* + * 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 "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; + +#include +#include +#include +#include + +#define FILE_PATH "/data/hdi_file_log.txt" + +static char logBuffer[1024] = {0}; + +void WriteFile(const char* buff, const int32_t size) +{ + //char path[256] = "/data/hidl_file_log.txt"; + int logFd = -1; + int wSize; + int ret; + + logFd = open(FILE_PATH, O_RDWR | O_CREAT, 00766); // 00766:file operate permission + if (logFd == -1) { + return; + } + lseek(logFd, 0, SEEK_END); + + if (size == -1) { + wSize = strlen(buff); + } else { + wSize = size; + } + + ret = write(logFd , buff, wSize); + if (ret == -1) { + printf("demo test:write image file error.\n"); + } + + close(logFd); +} + +#define F_LOG(fmt, ...) sprintf(logBuffer, "%d@%s, " fmt "\n", __LINE__, __func__, ##__VA_ARGS__); \ + WriteFile(logBuffer, strlen(logBuffer)) + + +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) + { + F_LOG("liuxk, id=%d, hdiFds size=%d", id, hdiFds.size()); + for (uint32_t i = 0; i < hdiFds.size(); ++i) { + F_LOG("liuxk, hdifd id[%d]=%d", i, hdiFds[i].id); + if (hdiFds[i].id == id) { + fd = hdiFds[i].hdiFd->Move(); + F_LOG("liuxk, hdifd id=%d, fd=%d", hdiFds[i].id, fd); + 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 { + int32_t transFd = -1; + if (fd >= 0) { + // A normal fd is transfered by binder, + // Here just write id for unpacking to match fd. + transFd = dup(fd); + ec = (transFd >= 0 ? HDF_SUCCESS : HDF_FAILURE); + if (ec == HDF_SUCCESS && hdifdInfo.hdiFd->Init(transFd)) { + 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) + { + int32_t ec = FileDescriptorPack(buffer.fd, packer, hdiFds); + bool 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.phyAddr); + } + if (retVal) { + retVal = packer->WriteInt32(buffer.key); + } + if (retVal) { + retVal = packer->WriteUint32(buffer.reserveFds); + } + if (retVal) { + retVal = packer->WriteUint32(buffer.reserveInts); + } + 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_SUCCESS) { + // A illegal fd is transfered by smq directly + fd = fdId; + } + return ec; + } + + static int32_t BufferHandleUnpack(std::shared_ptr unpacker, + const std::vector& hdiFds, BufferHandle& buffer) + { + int32_t ec = FileDescriptorUnpack(unpacker, hdiFds, buffer.fd); + F_LOG("liuxk, ec =%d, fd=%d", ec, buffer.fd); + bool retVal = (ec == HDF_SUCCESS ? true : false); + F_LOG("liuxk, retVal =%d", retVal); + if (retVal) { + retVal = unpacker->ReadInt32(buffer.width); + } + if (retVal) { + retVal = unpacker->ReadInt32(buffer.stride); + } + if (retVal) { + retVal = unpacker->ReadInt32(buffer.height); + } + if (retVal) { + retVal = unpacker->ReadInt32(buffer.size); + } + if (retVal) { + retVal = unpacker->ReadInt32(buffer.format); + } + if (retVal) { + retVal = unpacker->ReadUint64(buffer.phyAddr); + } + if (retVal) { + retVal = unpacker->ReadInt32(buffer.key); + } + if (retVal) { + retVal = unpacker->ReadUint32(buffer.reserveFds); + } + if (retVal) { + retVal = unpacker->ReadUint32(buffer.reserveInts); + } + if (buffer.reserveFds > 0 || buffer.reserveInts > 0) { + retVal = false; + HDF_LOGE("Error: not support variable length structure(BufferHandle)"); + } + if (retVal) { + int32_t i = 0; + for (i = 0; i < buffer.reserveFds; i++) { + ec = FileDescriptorUnpack(unpacker, hdiFds, buffer.reserve[i]); + if (ec != HDF_SUCCESS) { + retVal = false; + break; + } + } + for (int32_t j = 0; j < buffer.reserveInts; j++) { + retVal = unpacker->ReadInt32(buffer.reserve[i++]); + if (!retVal) { + break; + } + } + } + + 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 b/display/v1_0/hdi_impl/display_device_hdi_impl.h new file mode 100755 index 00000000..a0757d40 --- /dev/null +++ b/display/v1_0/hdi_impl/display_device_hdi_impl.h @@ -0,0 +1,331 @@ +/* + * 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_DISPLAYDEVICEHDIIMPL_H +#define OHOS_HDI_DISPLAY_V1_0_DISPLAYDEVICEHDIIMPL_H + +#include "hdf_log.h" +//#include "display_type.h" +#include "v1_0/display_command/display_cmd_requester.h" +#include "v1_0/include/idisplay_device_interface.h" +#include "v1_0/idisplay_device.h" +#include "v1_0/hdi_display_device_type.h" + +namespace OHOS { +namespace HDI { +namespace DISPLAY { +namespace V1_0 { + +#define CHECK_AND_RETURN(x, code) \ + if (x) { return code; } else { return HDF_FAILURE; } + +using namespace OHOS::HDI::Display::V1_0; + +template +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, uint32_t& num, + std::vector& modes) override + { + return hdi_->GetDisplaySupportedModes(devId, num, 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, uint32_t& num, + std::vector& layers, std::vector& types) override + { + return hdi_->GetDisplayCompChange(devId, num, 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_->RegHotPlugCallback(this); + } + + virtual int32_t GetDisplayReleaseFence(uint32_t devId, uint32_t& num, + std::vector& layers, std::vector& fences) override + { + std::vector> hdiFences; + int32_t ret = hdi_->GetDisplayReleaseFence(devId, num, 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 100755 index 00000000..bea8b3c1 --- /dev/null +++ b/display/v1_0/include/idisplay_device_interface.h @@ -0,0 +1,150 @@ +/* + * 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, uint32_t& num, + 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, uint32_t& num, + 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, uint32_t& num, + 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; + // not implement for openharmony + //virtual int32_t RegDisplayRefreshCallback(uint32_t devId, RefreshCallback callback, + // void *data) = 0; + //virtual int32_t GetDisplaySupportedColorGamuts(uint32_t devId, uint32_t& num, + // ColorGamut& gamuts) = 0; + //virtual int32_t GetDisplayColorGamut(uint32_t devId, ColorGamut& gamut) = 0; + //virtual int32_t SetDisplayColorGamut(uint32_t devId, ColorGamut gamut) = 0; + //virtual int32_t GetDisplayGamutMap(uint32_t devId, GamutMap& gamutMap) = 0; + //virtual int32_t SetDisplayGamutMap(uint32_t devId, GamutMap gamutMap) = 0; + //virtual int32_t SetDisplayColorTransform(uint32_t devId, const float& matrix) = 0; + //virtual int32_t GetHDRCapabilityInfos(uint32_t devId, HDRCapability& info) = 0; + //virtual int32_t GetSupportedMetadataKey(uint32_t devId, + // std::vector& keys) = 0; + //virtual int32_t InvokeDisplayCmd(uint32_t devId, ...) = 0; + //virtual int32_t GetWriteBackFrame(uint32_t devId, BufferHandle& buffer, int32_t& fence) = 0; + //virtual int32_t CreateWriteBack(uint32_t& devId, uint32_t width, uint32_t height, + // int32_t& format) = 0; + //virtual int32_t DestroyWriteBack(uint32_t devId) = 0; + + //virtual int32_t InitDisplay(uint32_t devId) = 0; + //virtual int32_t DeinitDisplay(uint32_t devId) = 0; + //virtual int32_t GetDisplayInfo(uint32_t devId, DisplayInfo& dispInfo) = 0; + //virtual int32_t GetLayerVisibleState(uint32_t devId, uint32_t layerId, bool& visible) = 0; + //virtual int32_t GetLayerSize(uint32_t devId, uint32_t layerId, IRect& rect) = 0; + //virtual int32_t GetLayerZorder(uint32_t devId, uint32_t layerId, uint32_t& zorder) = 0; + //virtual int32_t GetLayerPreMulti(uint32_t devId, uint32_t layerId, bool& preMul) = 0; + //virtual int32_t GetLayerAlpha(uint32_t devId, uint32_t layerId, LayerAlpha& alpha) = 0; + //virtual int32_t SetLayerColorKey(uint32_t devId, uint32_t layerId, bool enable, + // uint32_t key) = 0; + //virtual int32_t GetLayerColorKey(uint32_t devId, uint32_t layerId, bool& enable, + // uint32_t& key) = 0; + //virtual int32_t SetLayerPalette(uint32_t devId, uint32_t layerId, uint32_t& palette, + // uint32_t len) = 0; + //virtual int32_t GetLayerPalette(uint32_t devId, uint32_t layerId, uint32_t& palette, + // uint32_t len) = 0; + //virtual int32_t SetLayerCompression(uint32_t devId, uint32_t layerId, int32_t compType) = 0; + //virtual int32_t GetLayerCompression(uint32_t devId, uint32_t layerId, int32_t& compType) = 0; + //virtual int32_t GetLayerBuffer(uint32_t devId, uint32_t layerId, LayerBuffer& buffer) = 0; + //virtual int32_t Flush(uint32_t devId, uint32_t layerId, LayerBuffer& buffer) = 0; + //virtual int32_t WaitForVBlank(uint32_t devId, uint32_t layerId, int32_t timeOut) = 0; + //virtual int32_t SnapShot(uint32_t devId, LayerBuffer& buffer) = 0; + //virtual int32_t InvokeLayerCmd(uint32_t devId, uint32_t layerId, uint32_t cmd, ...) = 0; + //virtual int32_t SetLayerColorTransform(uint32_t devId, uint32_t layerId, + // const float& matrix) = 0; + //virtual int32_t SetLayerColorDataSpace(uint32_t devId, uint32_t layerId, + // ColorDataSpace colorSpace) = 0; + //virtual int32_t GetLayerColorDataSpace(uint32_t devId, uint32_t layerId, + // ColorDataSpace& colorSpace) = 0; + //virtual int32_t SetLayerMetaData(uint32_t devId, uint32_t layerId, + // const std::vector metaData) = 0; + //virtual int32_t SetLayerMetaDataSet(uint32_t devId, uint32_t layerId, HDRMetadataKey key, + // const std::vector metaData) = 0; + //virtual int32_t GetSupportedPresentTimestamp(uint32_t devId, uint32_t layerId, + // PresentTimestampType& type) = 0; + //virtual int32_t GetHwPresentTimestamp(uint32_t devId, uint32_t layerId, + // PresentTimestamp& pts) = 0; + //virtual int32_t SetLayerTunnelHandle(uint32_t devId, uint32_t layerId, + // ExtDataHandle& handle) = 0; + //virtual int32_t GetLayerReleaseFence(uint32_t devId, uint32_t layerId, int32_t& fence) = 0; +}; +} // V1_0 +} // Display +} // HDI +} // OHOS + +#endif // OHOS_HDI_DISPLAY_V1_0_IDISPLAYDEVICEINTERFACE_H -- Gitee From a9257cb0b2cf844f41303254ff82012323c5b312 Mon Sep 17 00:00:00 2001 From: liuxk Date: Tue, 12 Jul 2022 09:42:31 +0800 Subject: [PATCH 02/24] Add interface for hdifd and hdibuffer --- display/buffersequence/buffer_handle_parcelable.cpp | 6 ++++++ display/buffersequence/buffer_handle_parcelable.h | 1 + display/hdifdsequence/hdifd_parcelable.cpp | 11 ++++++++--- display/hdifdsequence/hdifd_parcelable.h | 1 + display/v1_0/display_command/display_cmd_responser.h | 4 ++-- 5 files changed, 18 insertions(+), 5 deletions(-) diff --git a/display/buffersequence/buffer_handle_parcelable.cpp b/display/buffersequence/buffer_handle_parcelable.cpp index b68c1443..91ac632b 100755 --- a/display/buffersequence/buffer_handle_parcelable.cpp +++ b/display/buffersequence/buffer_handle_parcelable.cpp @@ -31,6 +31,11 @@ BufferHandleParcelable::BufferHandleParcelable() { } +BufferHandleParcelable::BufferHandleParcelable(BufferHandle& handle) + : init_(true), handle_(&handle) +{ +} + BufferHandleParcelable::~BufferHandleParcelable() { if (init_ == false) { @@ -185,6 +190,7 @@ sptr BufferHandleParcelable::Unmarshalling(Parcel& parce __LINE__, __func__, parcel.GetDataSize(), parcel.GetReadPosition()); HDF_LOGE("liuxk, %{public}d@%{public}s dump BufferHandleParcelable:\n%{public}s", __LINE__, __func__, newParcelable->Dump().c_str()); + newParcelable->init_ = true; return newParcelable; } diff --git a/display/buffersequence/buffer_handle_parcelable.h b/display/buffersequence/buffer_handle_parcelable.h index 73dfbb14..3287a2ed 100755 --- a/display/buffersequence/buffer_handle_parcelable.h +++ b/display/buffersequence/buffer_handle_parcelable.h @@ -30,6 +30,7 @@ using namespace OHOS; class BufferHandleParcelable: public Parcelable { public: BufferHandleParcelable(); + BufferHandleParcelable(BufferHandle& handle); virtual ~BufferHandleParcelable(); bool Init(const BufferHandle& handle); diff --git a/display/hdifdsequence/hdifd_parcelable.cpp b/display/hdifdsequence/hdifd_parcelable.cpp index 1f371c6f..a39d4438 100755 --- a/display/hdifdsequence/hdifd_parcelable.cpp +++ b/display/hdifdsequence/hdifd_parcelable.cpp @@ -31,6 +31,11 @@ HdifdParcelable::HdifdParcelable() { } +HdifdParcelable::HdifdParcelable(int32_t fd) + : init_(true), hdiFd_(fd) +{ +} + HdifdParcelable::~HdifdParcelable() { if ((init_ != false) && (hdiFd_ != -1)) { @@ -105,7 +110,6 @@ bool HdifdParcelable::Marshalling(Parcel& parcel) const } HDF_LOGE("liuxk, %{public}d@%{public}s parcel size=%{public}d, dataptr=%{public}d", __LINE__, __func__, parcel.GetDataSize(), parcel.GetData()); - return true; } @@ -126,12 +130,13 @@ sptr HdifdParcelable::Unmarshalling(Parcel& parcel) return nullptr; } } - sptr newParcelable = new HdifdParcelable(); - newParcelable->Init(fd); + sptr newParcelable = new HdifdParcelable(fd); + //newParcelable->Init(fd); HDF_LOGE("liuxk, %{public}d@%{public}s parcel size=%{public}d, dataptr=%{public}d", __LINE__, __func__, parcel.GetDataSize(), parcel.GetData()); HDF_LOGE("liuxk, %{public}d@%{public}s dump HdifdParcelable:\n%{public}s", __LINE__, __func__, newParcelable->Dump().c_str()); + newParcelable->init_ = true; return newParcelable; } diff --git a/display/hdifdsequence/hdifd_parcelable.h b/display/hdifdsequence/hdifd_parcelable.h index cfbee816..dba13ac3 100755 --- a/display/hdifdsequence/hdifd_parcelable.h +++ b/display/hdifdsequence/hdifd_parcelable.h @@ -30,6 +30,7 @@ using namespace OHOS; class HdifdParcelable : public Parcelable { public: HdifdParcelable(); + HdifdParcelable(int32_t fd); virtual ~HdifdParcelable(); bool Init(int32_t fd); diff --git a/display/v1_0/display_command/display_cmd_responser.h b/display/v1_0/display_command/display_cmd_responser.h index b1a0de04..0667bae9 100755 --- a/display/v1_0/display_command/display_cmd_responser.h +++ b/display/v1_0/display_command/display_cmd_responser.h @@ -567,7 +567,7 @@ private: uint32_t layerId = -1; int32_t ec = CmdUtils::SetupDeviceUnpack(unpacker, devId, layerId); - F_LOG("liuxk, devId=%d, layerId=%d", devId, layerId); + //F_LOG("liuxk, devId=%d, layerId=%d", devId, layerId); BufferHandle buffer; if (ec == HDF_SUCCESS) { ec = CmdUtils::BufferHandleUnpack(unpacker, inFds, buffer); @@ -577,7 +577,7 @@ private: ec = bufParcel.Init(buffer) ? HDF_SUCCESS : HDF_FAILURE; } - F_LOG("liuxk, ec=%d", ec); + //F_LOG("liuxk, ec=%d", ec); int32_t fence = -1; if (ec == HDF_SUCCESS) { ec = CmdUtils::FileDescriptorUnpack(unpacker, inFds, fence); -- Gitee From 015c8cc80d258f4a3b0279134061c4757871e660 Mon Sep 17 00:00:00 2001 From: liuxk Date: Tue, 12 Jul 2022 17:04:32 +0800 Subject: [PATCH 03/24] Fix bufferhandle map issues --- .../buffer_handle_parcelable.cpp | 2 +- .../display_command/display_cmd_requester.h | 19 +++++-- .../display_command/display_cmd_responser.h | 57 ++++++++++++++----- .../v1_0/display_command/display_cmd_utils.h | 13 ++--- .../v1_0/hdi_impl/display_device_hdi_impl.h | 5 +- 5 files changed, 68 insertions(+), 28 deletions(-) diff --git a/display/buffersequence/buffer_handle_parcelable.cpp b/display/buffersequence/buffer_handle_parcelable.cpp index 91ac632b..48b8f325 100755 --- a/display/buffersequence/buffer_handle_parcelable.cpp +++ b/display/buffersequence/buffer_handle_parcelable.cpp @@ -38,7 +38,7 @@ BufferHandleParcelable::BufferHandleParcelable(BufferHandle& handle) BufferHandleParcelable::~BufferHandleParcelable() { - if (init_ == false) { + if (init_ == false || handle_ == nullptr) { return; } FreeBufferHandle(handle_); diff --git a/display/v1_0/display_command/display_cmd_requester.h b/display/v1_0/display_command/display_cmd_requester.h index 161b6cc4..82c95e0f 100755 --- a/display/v1_0/display_command/display_cmd_requester.h +++ b/display/v1_0/display_command/display_cmd_requester.h @@ -44,7 +44,8 @@ public: request_(nullptr), reply_(nullptr), requestPacker_(nullptr) - {} + { + } static std::unique_ptr Create(sptr hdi) { @@ -102,6 +103,8 @@ public: size_t replyEleCnt; std::vector outFds; std::shared_ptr replyData; + HDF_LOGE("liuxk, %{public}d@%{public}s, PrepareDisplayLayers ec=%{public}d", + __LINE__, __func__, ec); if (ec == HDF_SUCCESS) { ec = DoRequest(replyEleCnt, outFds, replyData); } @@ -110,12 +113,18 @@ public: ec = DoReplyResults(replyEleCnt, outFds, replyData, [&](void* data)->int32_t { needFlushFb = *(reinterpret_cast(data)); return HDF_SUCCESS; + HDF_LOGE("liuxk, %{public}d@%{public}s, PrepareDisplayLayers ec=%{public}d", + __LINE__, __func__, ec); }); } + HDF_LOGE("liuxk, %{public}d@%{public}s, PrepareDisplayLayers ec=%{public}d", + __LINE__, __func__, ec); if (ec != HDF_SUCCESS) { HDF_LOGE("PrepareDisplayLayers failure, ec=%{public}d", ec); } + HDF_LOGE("liuxk, %{public}d@%{public}s, PrepareDisplayLayers ec=%{public}d", + __LINE__, __func__, ec); return PeriodDataReset(); } @@ -508,6 +517,8 @@ private: if (ec == HDF_SUCCESS) { ec = fn(&needFlushFb); } + HDF_LOGE("liuxk, %{public}d@%{public}s, PrepareDisplayLayers ec=%{public}d, needFlushFb=%{public}d", + __LINE__, __func__, ec, needFlushFb); if (ec != HDF_SUCCESS) { HDF_LOGI("error: ReadBool failed, unpackCmd=%{public}s.", CmdUtils::CommandToString(unpackCmd)); @@ -528,12 +539,12 @@ private: { int32_t fenceFd = -1; ec = OnReplyCommit(replyUnpacker, replyFds, fenceFd); - F_LOG("liuxk, ec=%d, fenceFd=%d", ec, fenceFd); + HDF_LOGE("liuxk, commit ec=%{bublic}d, fenceFd=%{public}d", ec, fenceFd); if (ec == HDF_SUCCESS) { ec = fn(&fenceFd); - F_LOG("liuxk, ec=%d, fenceFd=%d", ec, fenceFd); + HDF_LOGE("liuxk, commit 1 ec=%{public}d, fenceFd=%{public}d", ec, fenceFd); } - F_LOG("liuxk, ec=%d, fenceFd=%d", ec, fenceFd); + HDF_LOGE("liuxk, commit2 ec=%{public}d, fenceFd=%{public}d", ec, fenceFd); if (ec != HDF_SUCCESS) { HDF_LOGI("error: return fence fd error, unpackCmd=%{public}s.", CmdUtils::CommandToString(unpackCmd)); diff --git a/display/v1_0/display_command/display_cmd_responser.h b/display/v1_0/display_command/display_cmd_responser.h index 0667bae9..a84320f7 100755 --- a/display/v1_0/display_command/display_cmd_responser.h +++ b/display/v1_0/display_command/display_cmd_responser.h @@ -25,6 +25,7 @@ #include "command_data_packer.h" #include "command_data_unpacker.h" #include "display_cmd_utils.h" +#include "display_gralloc.h" #include "v1_0/include/idisplay_device_interface.h" #include "v1_0/hdi_display_device_type.h" @@ -51,9 +52,18 @@ public: isReplyUpdated_(false), reply_(nullptr), replyCommandCnt_(0), - replyPacker_(nullptr) + replyPacker_(nullptr), + gralloc_(nullptr) { - HDF_LOGE("DisplayCmdRequester constructor"); + if (GrallocInitialize(&gralloc_) != DISPLAY_SUCCESS) { + HDF_LOGE("error: DisplayCmdResponser construct failure"); + } + } + ~DisplayCmdResponser() + { + if (GrallocUninitialize(gralloc_) != DISPLAY_SUCCESS) { + HDF_LOGE("error: DisplayCmdResponser destruct failure"); + } } int32_t InitCmdRequest(const std::shared_ptr& request) @@ -79,6 +89,7 @@ public: ec = HDF_FAILURE; } } + isReplyUpdated_ = false; if (ec != HDF_SUCCESS) { HDF_LOGE("error: GetCmdReply failure"); } @@ -283,19 +294,25 @@ private: if (ec == HDF_SUCCESS) { ec = CmdUtils::BufferHandleUnpack(unpacker, inFds, buffer); } - BufferHandleParcelable bufParcel; if (ec == HDF_SUCCESS) { - ec = bufParcel.Init(buffer) ? HDF_SUCCESS : HDF_FAILURE; + void *vAddr = gralloc_->Mmap(&buffer); + ec = (vAddr == nullptr ? HDF_FAILURE : HDF_SUCCESS); } + BufferHandleParcelable bufParcel(buffer); + //BufferHandleParcelable bufParcel; + //if (ec == HDF_SUCCESS) { + // ec = bufParcel.Init(buffer) ? HDF_SUCCESS : HDF_FAILURE; + //} int32_t fence = -1; if (ec == HDF_SUCCESS) { ec = CmdUtils::FileDescriptorUnpack(unpacker, inFds, fence); } - HdifdParcelable fdParcel; - if (ec == HDF_SUCCESS) { - ec = fdParcel.Init(fence) ? HDF_SUCCESS : HDF_FAILURE; - } + HdifdParcelable fdParcel(fence); + //HdifdParcelable fdParcel; + //if (ec == HDF_SUCCESS) { + // ec = fdParcel.Init(fence) ? HDF_SUCCESS : HDF_FAILURE; + //} if (ec == HDF_SUCCESS) { ec = impl_->SetDisplayClientBuffer(devId, *bufParcel.GetBufferHandle(), @@ -568,24 +585,35 @@ private: int32_t ec = CmdUtils::SetupDeviceUnpack(unpacker, devId, layerId); //F_LOG("liuxk, devId=%d, layerId=%d", devId, layerId); + //for (int i = 0; i < inFds.size(); i++) { //liuxk + // HDF_LOGE("liuxk, %{public}d@%{public}s inFds[%{public}d] fdid=%{public}d, fd:%{public}d", + // __LINE__, __func__, i, inFds[i].id, inFds[i].hdiFd->GetFd()); + //} + BufferHandle buffer; if (ec == HDF_SUCCESS) { ec = CmdUtils::BufferHandleUnpack(unpacker, inFds, buffer); } - BufferHandleParcelable bufParcel; if (ec == HDF_SUCCESS) { - ec = bufParcel.Init(buffer) ? HDF_SUCCESS : HDF_FAILURE; + void *vAddr = gralloc_->Mmap(&buffer); + ec = (vAddr == nullptr ? HDF_FAILURE : HDF_SUCCESS); } + BufferHandleParcelable bufParcel(buffer); + //BufferHandleParcelable bufParcel; + //if (ec == HDF_SUCCESS) { + // ec = bufParcel.Init(buffer) ? HDF_SUCCESS : HDF_FAILURE; + //} //F_LOG("liuxk, ec=%d", ec); int32_t fence = -1; if (ec == HDF_SUCCESS) { ec = CmdUtils::FileDescriptorUnpack(unpacker, inFds, fence); } - HdifdParcelable fdParcel; - if (ec == HDF_SUCCESS) { - ec = fdParcel.Init(fence) ? HDF_SUCCESS : HDF_FAILURE; - } + HdifdParcelable fdParcel(fence); + //HdifdParcelable fdParcel; + //if (ec == HDF_SUCCESS) { + // ec = fdParcel.Init(fence) ? HDF_SUCCESS : HDF_FAILURE; + //} if (ec == HDF_SUCCESS) { ec = impl_->SetLayerBuffer(devId, layerId, *bufParcel.GetBufferHandle(), @@ -681,6 +709,7 @@ private: uint32_t replyCommandCnt_; std::shared_ptr replyPacker_; std::unordered_map errMaps_; + GrallocFuncs *gralloc_; }; using HdiDisplayCmdResponser = DisplayCmdResponser, IDisplayDeviceInterface>; diff --git a/display/v1_0/display_command/display_cmd_utils.h b/display/v1_0/display_command/display_cmd_utils.h index 08a1dd39..31175634 100755 --- a/display/v1_0/display_command/display_cmd_utils.h +++ b/display/v1_0/display_command/display_cmd_utils.h @@ -18,6 +18,7 @@ #include "command_data_packer.h" #include "command_data_unpacker.h" +#include "display_gralloc.h" #include "v1_0/hdi_display_device_type.h" namespace OHOS { @@ -148,12 +149,9 @@ public: static bool MatchHdiFd(int32_t id, std::vector hdiFds, int32_t& fd) { - F_LOG("liuxk, id=%d, hdiFds size=%d", id, hdiFds.size()); for (uint32_t i = 0; i < hdiFds.size(); ++i) { - F_LOG("liuxk, hdifd id[%d]=%d", i, hdiFds[i].id); if (hdiFds[i].id == id) { fd = hdiFds[i].hdiFd->Move(); - F_LOG("liuxk, hdifd id=%d, fd=%d", hdiFds[i].id, fd); return true; } } @@ -293,8 +291,9 @@ public: if (ec == HDF_SUCCESS && fdId >=0) { ec = MatchHdiFd(fdId, hdiFds, fd) ? HDF_SUCCESS : HDF_FAILURE; } - if (ec == HDF_SUCCESS) { - // A illegal fd is transfered by smq directly + if (ec == HDF_FAILURE) { + // if matching failure, the illegal fd is transfered by smq directly, + // not by binder IPC fd = fdId; } return ec; @@ -304,9 +303,9 @@ public: const std::vector& hdiFds, BufferHandle& buffer) { int32_t ec = FileDescriptorUnpack(unpacker, hdiFds, buffer.fd); - F_LOG("liuxk, ec =%d, fd=%d", ec, buffer.fd); + //F_LOG("liuxk, ec =%d, fd=%d", ec, buffer.fd); bool retVal = (ec == HDF_SUCCESS ? true : false); - F_LOG("liuxk, retVal =%d", retVal); + //F_LOG("liuxk, retVal =%d", retVal); if (retVal) { retVal = unpacker->ReadInt32(buffer.width); } diff --git a/display/v1_0/hdi_impl/display_device_hdi_impl.h b/display/v1_0/hdi_impl/display_device_hdi_impl.h index a0757d40..4d19b65a 100755 --- a/display/v1_0/hdi_impl/display_device_hdi_impl.h +++ b/display/v1_0/hdi_impl/display_device_hdi_impl.h @@ -58,7 +58,8 @@ public: } virtual ~DisplayDeviceHdiImpl() - {} + { + } // *** device func virtual int32_t RegHotPlugCallback(HotPlugCallback cb, void *data) override @@ -150,7 +151,7 @@ public: { vBlankCb_ = cb; vBlankCbData_ = data; - return hdi_->RegHotPlugCallback(this); + return hdi_->RegDisplayVBlankCallback(devId, this); } virtual int32_t GetDisplayReleaseFence(uint32_t devId, uint32_t& num, -- Gitee From e4620390f53bd66c7e8434566fa787813044c8a2 Mon Sep 17 00:00:00 2001 From: liuxk Date: Tue, 12 Jul 2022 17:35:34 +0800 Subject: [PATCH 04/24] Change file mod to 644 --- display/BUILD.gn | 0 display/buffersequence/BUILD.gn | 0 display/buffersequence/buffer_handle_parcelable.cpp | 0 display/buffersequence/buffer_handle_parcelable.h | 0 display/command_pack/command_data_packer.h | 0 display/command_pack/command_data_unpacker.h | 0 display/hdifdsequence/BUILD.gn | 0 display/hdifdsequence/hdifd_parcelable.cpp | 0 display/hdifdsequence/hdifd_parcelable.h | 0 display/v1_0/BUILD.gn | 0 display/v1_0/HdiDisplayDeviceType.idl | 0 display/v1_0/IDisplayDevice.idl | 0 display/v1_0/IHotPlugCallback.idl | 0 display/v1_0/IRefreshCallback.idl | 0 display/v1_0/IVBlankCallback.idl | 0 display/v1_0/display_command/display_cmd_requester.h | 0 display/v1_0/display_command/display_cmd_responser.h | 0 display/v1_0/display_command/display_cmd_utils.h | 0 display/v1_0/hdi_impl/display_device_hdi_impl.h | 0 display/v1_0/include/idisplay_device_interface.h | 0 20 files changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 display/BUILD.gn mode change 100755 => 100644 display/buffersequence/BUILD.gn mode change 100755 => 100644 display/buffersequence/buffer_handle_parcelable.cpp mode change 100755 => 100644 display/buffersequence/buffer_handle_parcelable.h mode change 100755 => 100644 display/command_pack/command_data_packer.h mode change 100755 => 100644 display/command_pack/command_data_unpacker.h mode change 100755 => 100644 display/hdifdsequence/BUILD.gn mode change 100755 => 100644 display/hdifdsequence/hdifd_parcelable.cpp mode change 100755 => 100644 display/hdifdsequence/hdifd_parcelable.h mode change 100755 => 100644 display/v1_0/BUILD.gn mode change 100755 => 100644 display/v1_0/HdiDisplayDeviceType.idl mode change 100755 => 100644 display/v1_0/IDisplayDevice.idl mode change 100755 => 100644 display/v1_0/IHotPlugCallback.idl mode change 100755 => 100644 display/v1_0/IRefreshCallback.idl mode change 100755 => 100644 display/v1_0/IVBlankCallback.idl mode change 100755 => 100644 display/v1_0/display_command/display_cmd_requester.h mode change 100755 => 100644 display/v1_0/display_command/display_cmd_responser.h mode change 100755 => 100644 display/v1_0/display_command/display_cmd_utils.h mode change 100755 => 100644 display/v1_0/hdi_impl/display_device_hdi_impl.h mode change 100755 => 100644 display/v1_0/include/idisplay_device_interface.h diff --git a/display/BUILD.gn b/display/BUILD.gn old mode 100755 new mode 100644 diff --git a/display/buffersequence/BUILD.gn b/display/buffersequence/BUILD.gn old mode 100755 new mode 100644 diff --git a/display/buffersequence/buffer_handle_parcelable.cpp b/display/buffersequence/buffer_handle_parcelable.cpp old mode 100755 new mode 100644 diff --git a/display/buffersequence/buffer_handle_parcelable.h b/display/buffersequence/buffer_handle_parcelable.h old mode 100755 new mode 100644 diff --git a/display/command_pack/command_data_packer.h b/display/command_pack/command_data_packer.h old mode 100755 new mode 100644 diff --git a/display/command_pack/command_data_unpacker.h b/display/command_pack/command_data_unpacker.h old mode 100755 new mode 100644 diff --git a/display/hdifdsequence/BUILD.gn b/display/hdifdsequence/BUILD.gn old mode 100755 new mode 100644 diff --git a/display/hdifdsequence/hdifd_parcelable.cpp b/display/hdifdsequence/hdifd_parcelable.cpp old mode 100755 new mode 100644 diff --git a/display/hdifdsequence/hdifd_parcelable.h b/display/hdifdsequence/hdifd_parcelable.h old mode 100755 new mode 100644 diff --git a/display/v1_0/BUILD.gn b/display/v1_0/BUILD.gn old mode 100755 new mode 100644 diff --git a/display/v1_0/HdiDisplayDeviceType.idl b/display/v1_0/HdiDisplayDeviceType.idl old mode 100755 new mode 100644 diff --git a/display/v1_0/IDisplayDevice.idl b/display/v1_0/IDisplayDevice.idl old mode 100755 new mode 100644 diff --git a/display/v1_0/IHotPlugCallback.idl b/display/v1_0/IHotPlugCallback.idl old mode 100755 new mode 100644 diff --git a/display/v1_0/IRefreshCallback.idl b/display/v1_0/IRefreshCallback.idl old mode 100755 new mode 100644 diff --git a/display/v1_0/IVBlankCallback.idl b/display/v1_0/IVBlankCallback.idl old mode 100755 new mode 100644 diff --git a/display/v1_0/display_command/display_cmd_requester.h b/display/v1_0/display_command/display_cmd_requester.h old mode 100755 new mode 100644 diff --git a/display/v1_0/display_command/display_cmd_responser.h b/display/v1_0/display_command/display_cmd_responser.h old mode 100755 new mode 100644 diff --git a/display/v1_0/display_command/display_cmd_utils.h b/display/v1_0/display_command/display_cmd_utils.h old mode 100755 new mode 100644 diff --git a/display/v1_0/hdi_impl/display_device_hdi_impl.h b/display/v1_0/hdi_impl/display_device_hdi_impl.h old mode 100755 new mode 100644 diff --git a/display/v1_0/include/idisplay_device_interface.h b/display/v1_0/include/idisplay_device_interface.h old mode 100755 new mode 100644 -- Gitee From 5dac1df89ffbdbbc8a79925d7a32bbc2eaff6f55 Mon Sep 17 00:00:00 2001 From: liuxk Date: Tue, 12 Jul 2022 18:11:19 +0800 Subject: [PATCH 05/24] Support bufferhandle Variable size --- .../display_command/display_cmd_responser.h | 28 ++------- .../v1_0/display_command/display_cmd_utils.h | 61 ++++++++++--------- 2 files changed, 38 insertions(+), 51 deletions(-) diff --git a/display/v1_0/display_command/display_cmd_responser.h b/display/v1_0/display_command/display_cmd_responser.h index a84320f7..840d2b62 100644 --- a/display/v1_0/display_command/display_cmd_responser.h +++ b/display/v1_0/display_command/display_cmd_responser.h @@ -290,15 +290,15 @@ private: uint32_t devId; int32_t ec = unpacker->ReadUint32(devId) ? HDF_SUCCESS : HDF_FAILURE; - BufferHandle buffer; + BufferHandle* buffer; if (ec == HDF_SUCCESS) { ec = CmdUtils::BufferHandleUnpack(unpacker, inFds, buffer); } if (ec == HDF_SUCCESS) { - void *vAddr = gralloc_->Mmap(&buffer); + void *vAddr = gralloc_->Mmap(buffer); ec = (vAddr == nullptr ? HDF_FAILURE : HDF_SUCCESS); } - BufferHandleParcelable bufParcel(buffer); + BufferHandleParcelable bufParcel(*buffer); //BufferHandleParcelable bufParcel; //if (ec == HDF_SUCCESS) { // ec = bufParcel.Init(buffer) ? HDF_SUCCESS : HDF_FAILURE; @@ -584,37 +584,21 @@ private: uint32_t layerId = -1; int32_t ec = CmdUtils::SetupDeviceUnpack(unpacker, devId, layerId); - //F_LOG("liuxk, devId=%d, layerId=%d", devId, layerId); - //for (int i = 0; i < inFds.size(); i++) { //liuxk - // HDF_LOGE("liuxk, %{public}d@%{public}s inFds[%{public}d] fdid=%{public}d, fd:%{public}d", - // __LINE__, __func__, i, inFds[i].id, inFds[i].hdiFd->GetFd()); - //} - - BufferHandle buffer; + BufferHandle* buffer; if (ec == HDF_SUCCESS) { ec = CmdUtils::BufferHandleUnpack(unpacker, inFds, buffer); } if (ec == HDF_SUCCESS) { - void *vAddr = gralloc_->Mmap(&buffer); + void *vAddr = gralloc_->Mmap(buffer); ec = (vAddr == nullptr ? HDF_FAILURE : HDF_SUCCESS); } - BufferHandleParcelable bufParcel(buffer); - //BufferHandleParcelable bufParcel; - //if (ec == HDF_SUCCESS) { - // ec = bufParcel.Init(buffer) ? HDF_SUCCESS : HDF_FAILURE; - //} - //F_LOG("liuxk, ec=%d", ec); + BufferHandleParcelable bufParcel(*buffer); int32_t fence = -1; if (ec == HDF_SUCCESS) { ec = CmdUtils::FileDescriptorUnpack(unpacker, inFds, fence); } HdifdParcelable fdParcel(fence); - //HdifdParcelable fdParcel; - //if (ec == HDF_SUCCESS) { - // ec = fdParcel.Init(fence) ? HDF_SUCCESS : HDF_FAILURE; - //} - if (ec == HDF_SUCCESS) { ec = impl_->SetLayerBuffer(devId, layerId, *bufParcel.GetBufferHandle(), fdParcel.GetFd()); diff --git a/display/v1_0/display_command/display_cmd_utils.h b/display/v1_0/display_command/display_cmd_utils.h index 31175634..c611ba13 100644 --- a/display/v1_0/display_command/display_cmd_utils.h +++ b/display/v1_0/display_command/display_cmd_utils.h @@ -210,8 +210,14 @@ public: static int32_t BufferHandlePack(const BufferHandle& buffer, std::shared_ptr packer, std::vector& hdiFds) { - int32_t ec = FileDescriptorPack(buffer.fd, packer, hdiFds); - bool retVal = (ec == HDF_SUCCESS ? true : false); + bool retVal = packer->WriteUint32(buffer.reserveFds); + if (retVal) { + retVal = packer->WriteUint32(buffer.reserveInts); + } + if (retVal) { + int32_t ec = FileDescriptorPack(buffer.fd, packer, hdiFds); + retVal = (ec == HDF_SUCCESS ? true : false); + } if (retVal) { retVal = packer->WriteInt32(buffer.width); } @@ -233,12 +239,6 @@ public: if (retVal) { retVal = packer->WriteInt32(buffer.key); } - if (retVal) { - retVal = packer->WriteUint32(buffer.reserveFds); - } - if (retVal) { - retVal = packer->WriteUint32(buffer.reserveInts); - } if (retVal) { int32_t i = 0; for (i = 0; i < buffer.reserveFds; i++) { @@ -300,59 +300,62 @@ public: } static int32_t BufferHandleUnpack(std::shared_ptr unpacker, - const std::vector& hdiFds, BufferHandle& buffer) + const std::vector& hdiFds, BufferHandle*& buffer) { - int32_t ec = FileDescriptorUnpack(unpacker, hdiFds, buffer.fd); - //F_LOG("liuxk, ec =%d, fd=%d", ec, buffer.fd); - bool retVal = (ec == HDF_SUCCESS ? true : false); - //F_LOG("liuxk, retVal =%d", retVal); + uint32_t fdsNum = 0; + uint32_t intsNum = 0; + bool retVal = unpacker->ReadUint32(fdsNum); if (retVal) { - retVal = unpacker->ReadInt32(buffer.width); + retVal = unpacker->ReadUint32(intsNum); } + BufferHandle* handle = AllocateBufferHandle(fdsNum, intsNum); + retVal = (handle == nullptr ? true : false); if (retVal) { - retVal = unpacker->ReadInt32(buffer.stride); + handle->reserveFds = fdsNum; + handle->reserveInts = intsNum; } if (retVal) { - retVal = unpacker->ReadInt32(buffer.height); + int32_t ec = FileDescriptorUnpack(unpacker, hdiFds, handle->fd); + retVal = (ec == HDF_SUCCESS ? true : false); } if (retVal) { - retVal = unpacker->ReadInt32(buffer.size); + retVal = unpacker->ReadInt32(handle->width); } if (retVal) { - retVal = unpacker->ReadInt32(buffer.format); + retVal = unpacker->ReadInt32(handle->stride); } if (retVal) { - retVal = unpacker->ReadUint64(buffer.phyAddr); + retVal = unpacker->ReadInt32(handle->height); } if (retVal) { - retVal = unpacker->ReadInt32(buffer.key); + retVal = unpacker->ReadInt32(handle->size); } if (retVal) { - retVal = unpacker->ReadUint32(buffer.reserveFds); + retVal = unpacker->ReadInt32(handle->format); } if (retVal) { - retVal = unpacker->ReadUint32(buffer.reserveInts); + retVal = unpacker->ReadUint64(handle->phyAddr); } - if (buffer.reserveFds > 0 || buffer.reserveInts > 0) { - retVal = false; - HDF_LOGE("Error: not support variable length structure(BufferHandle)"); + if (retVal) { + retVal = unpacker->ReadInt32(handle->key); } if (retVal) { int32_t i = 0; - for (i = 0; i < buffer.reserveFds; i++) { - ec = FileDescriptorUnpack(unpacker, hdiFds, buffer.reserve[i]); + 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 < buffer.reserveInts; j++) { - retVal = unpacker->ReadInt32(buffer.reserve[i++]); + 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; } -- Gitee From e671197e157404685353c6bc84912321ad99b545 Mon Sep 17 00:00:00 2001 From: liuxk Date: Tue, 12 Jul 2022 19:09:42 +0800 Subject: [PATCH 06/24] Fix build errors --- .../v1_0/display_command/display_cmd_responser.h | 8 ++++++-- display/v1_0/display_command/display_cmd_utils.h | 13 ++++++++++--- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/display/v1_0/display_command/display_cmd_responser.h b/display/v1_0/display_command/display_cmd_responser.h index 840d2b62..9ca55fad 100644 --- a/display/v1_0/display_command/display_cmd_responser.h +++ b/display/v1_0/display_command/display_cmd_responser.h @@ -290,7 +290,7 @@ private: uint32_t devId; int32_t ec = unpacker->ReadUint32(devId) ? HDF_SUCCESS : HDF_FAILURE; - BufferHandle* buffer; + BufferHandle* buffer = nullptr; if (ec == HDF_SUCCESS) { ec = CmdUtils::BufferHandleUnpack(unpacker, inFds, buffer); } @@ -584,15 +584,19 @@ private: uint32_t layerId = -1; int32_t ec = CmdUtils::SetupDeviceUnpack(unpacker, devId, layerId); - BufferHandle* buffer; + BufferHandle* buffer = nullptr; if (ec == HDF_SUCCESS) { ec = CmdUtils::BufferHandleUnpack(unpacker, inFds, buffer); } + HDF_LOGE("liuxk1, fd=%{public}d, reserveFds=%{public}d, reserveInts=%{public}d, width=%{public}d, stride=%{public}d, height=%{public}d", + buffer->fd, buffer->reserveFds, buffer->reserveInts, buffer->width, buffer->stride, buffer->height); if (ec == HDF_SUCCESS) { void *vAddr = gralloc_->Mmap(buffer); ec = (vAddr == nullptr ? HDF_FAILURE : HDF_SUCCESS); } + HDF_LOGE("liuxk2, fd=%{public}d, reserveFds=%{public}d, reserveInts=%{public}d, width=%{public}d, stride=%{public}d, height=%{public}d", + buffer->fd, buffer->reserveFds, buffer->reserveInts, buffer->width, buffer->stride, buffer->height); BufferHandleParcelable bufParcel(*buffer); int32_t fence = -1; if (ec == HDF_SUCCESS) { diff --git a/display/v1_0/display_command/display_cmd_utils.h b/display/v1_0/display_command/display_cmd_utils.h index c611ba13..d8e01bfb 100644 --- a/display/v1_0/display_command/display_cmd_utils.h +++ b/display/v1_0/display_command/display_cmd_utils.h @@ -16,6 +16,7 @@ #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 "display_gralloc.h" @@ -214,8 +215,9 @@ public: if (retVal) { retVal = packer->WriteUint32(buffer.reserveInts); } + int32_t ec = HDF_SUCCESS; if (retVal) { - int32_t ec = FileDescriptorPack(buffer.fd, packer, hdiFds); + ec = FileDescriptorPack(buffer.fd, packer, hdiFds); retVal = (ec == HDF_SUCCESS ? true : false); } if (retVal) { @@ -239,6 +241,8 @@ public: if (retVal) { retVal = packer->WriteInt32(buffer.key); } + HDF_LOGE("liuxk, fd=%{public}d, reserveFds=%{public}d, reserveInts=%{public}d, width=%{public}d, stride=%{public}d, height=%{public}d", + buffer.fd, buffer.reserveFds, buffer.reserveInts, buffer.width, buffer.stride, buffer.height); if (retVal) { int32_t i = 0; for (i = 0; i < buffer.reserveFds; i++) { @@ -309,13 +313,14 @@ public: retVal = unpacker->ReadUint32(intsNum); } BufferHandle* handle = AllocateBufferHandle(fdsNum, intsNum); - retVal = (handle == nullptr ? true : false); + retVal = (handle == nullptr ? false : true); if (retVal) { handle->reserveFds = fdsNum; handle->reserveInts = intsNum; } + int32_t ec = HDF_SUCCESS; if (retVal) { - int32_t ec = FileDescriptorUnpack(unpacker, hdiFds, handle->fd); + ec = FileDescriptorUnpack(unpacker, hdiFds, handle->fd); retVal = (ec == HDF_SUCCESS ? true : false); } if (retVal) { @@ -339,6 +344,8 @@ public: if (retVal) { retVal = unpacker->ReadInt32(handle->key); } + HDF_LOGE("liuxk, fd=%{public}d, reserveFds=%{public}d, reserveInts=%{public}d, width=%{public}d, stride=%{public}d, height=%{public}d", + handle->fd, handle->reserveFds, handle->reserveInts, handle->width, handle->stride, handle->height); if (retVal) { int32_t i = 0; for (i = 0; i < handle->reserveFds; i++) { -- Gitee From 5943b3bf90051e3bbc75f9f3b0059331125a01f4 Mon Sep 17 00:00:00 2001 From: liuxk Date: Tue, 12 Jul 2022 20:08:56 +0800 Subject: [PATCH 07/24] Fix buffer mmap issue --- display/v1_0/display_command/display_cmd_responser.h | 5 ----- display/v1_0/display_command/display_cmd_utils.h | 6 ++++++ 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/display/v1_0/display_command/display_cmd_responser.h b/display/v1_0/display_command/display_cmd_responser.h index 9ca55fad..79599c94 100644 --- a/display/v1_0/display_command/display_cmd_responser.h +++ b/display/v1_0/display_command/display_cmd_responser.h @@ -588,15 +588,10 @@ private: if (ec == HDF_SUCCESS) { ec = CmdUtils::BufferHandleUnpack(unpacker, inFds, buffer); } - HDF_LOGE("liuxk1, fd=%{public}d, reserveFds=%{public}d, reserveInts=%{public}d, width=%{public}d, stride=%{public}d, height=%{public}d", - buffer->fd, buffer->reserveFds, buffer->reserveInts, buffer->width, buffer->stride, buffer->height); if (ec == HDF_SUCCESS) { void *vAddr = gralloc_->Mmap(buffer); ec = (vAddr == nullptr ? HDF_FAILURE : HDF_SUCCESS); } - - HDF_LOGE("liuxk2, fd=%{public}d, reserveFds=%{public}d, reserveInts=%{public}d, width=%{public}d, stride=%{public}d, height=%{public}d", - buffer->fd, buffer->reserveFds, buffer->reserveInts, buffer->width, buffer->stride, buffer->height); BufferHandleParcelable bufParcel(*buffer); int32_t fence = -1; if (ec == HDF_SUCCESS) { diff --git a/display/v1_0/display_command/display_cmd_utils.h b/display/v1_0/display_command/display_cmd_utils.h index d8e01bfb..8674b49d 100644 --- a/display/v1_0/display_command/display_cmd_utils.h +++ b/display/v1_0/display_command/display_cmd_utils.h @@ -235,6 +235,9 @@ public: if (retVal) { retVal = packer->WriteInt32(buffer.format); } + if (retVal) { + retVal = packer->WriteUint64(buffer.usage); + } if (retVal) { retVal = packer->WriteUint64(buffer.phyAddr); } @@ -338,6 +341,9 @@ public: if (retVal) { retVal = unpacker->ReadInt32(handle->format); } + if (retVal) { + retVal = unpacker->ReadUint64(handle->usage); + } if (retVal) { retVal = unpacker->ReadUint64(handle->phyAddr); } -- Gitee From 5663326fbbd2892b7a4ac5b7b8744f63983e303b Mon Sep 17 00:00:00 2001 From: liuxk Date: Tue, 12 Jul 2022 20:09:45 +0800 Subject: [PATCH 08/24] delete log --- display/v1_0/display_command/display_cmd_utils.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/display/v1_0/display_command/display_cmd_utils.h b/display/v1_0/display_command/display_cmd_utils.h index 8674b49d..08c790a4 100644 --- a/display/v1_0/display_command/display_cmd_utils.h +++ b/display/v1_0/display_command/display_cmd_utils.h @@ -244,8 +244,6 @@ public: if (retVal) { retVal = packer->WriteInt32(buffer.key); } - HDF_LOGE("liuxk, fd=%{public}d, reserveFds=%{public}d, reserveInts=%{public}d, width=%{public}d, stride=%{public}d, height=%{public}d", - buffer.fd, buffer.reserveFds, buffer.reserveInts, buffer.width, buffer.stride, buffer.height); if (retVal) { int32_t i = 0; for (i = 0; i < buffer.reserveFds; i++) { @@ -350,8 +348,6 @@ public: if (retVal) { retVal = unpacker->ReadInt32(handle->key); } - HDF_LOGE("liuxk, fd=%{public}d, reserveFds=%{public}d, reserveInts=%{public}d, width=%{public}d, stride=%{public}d, height=%{public}d", - handle->fd, handle->reserveFds, handle->reserveInts, handle->width, handle->stride, handle->height); if (retVal) { int32_t i = 0; for (i = 0; i < handle->reserveFds; i++) { -- Gitee From b7adb3b27042874bd895326de8a2494c2c0f1dd4 Mon Sep 17 00:00:00 2001 From: liuxk Date: Tue, 12 Jul 2022 20:53:15 +0800 Subject: [PATCH 09/24] Fix memory leak of bufferhandle --- .../display_command/display_cmd_responser.h | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/display/v1_0/display_command/display_cmd_responser.h b/display/v1_0/display_command/display_cmd_responser.h index 79599c94..8985ba5f 100644 --- a/display/v1_0/display_command/display_cmd_responser.h +++ b/display/v1_0/display_command/display_cmd_responser.h @@ -20,6 +20,7 @@ #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" @@ -298,26 +299,17 @@ private: void *vAddr = gralloc_->Mmap(buffer); ec = (vAddr == nullptr ? HDF_FAILURE : HDF_SUCCESS); } - BufferHandleParcelable bufParcel(*buffer); - //BufferHandleParcelable bufParcel; - //if (ec == HDF_SUCCESS) { - // ec = bufParcel.Init(buffer) ? HDF_SUCCESS : HDF_FAILURE; - //} int32_t fence = -1; if (ec == HDF_SUCCESS) { ec = CmdUtils::FileDescriptorUnpack(unpacker, inFds, fence); } HdifdParcelable fdParcel(fence); - //HdifdParcelable fdParcel; - //if (ec == HDF_SUCCESS) { - // ec = fdParcel.Init(fence) ? HDF_SUCCESS : HDF_FAILURE; - //} if (ec == HDF_SUCCESS) { - ec = impl_->SetDisplayClientBuffer(devId, *bufParcel.GetBufferHandle(), - fdParcel.GetFd()); + ec = impl_->SetDisplayClientBuffer(devId, *buffer, fdParcel.GetFd()); } + FreeBufferHandle(buffer); if (ec != HDF_SUCCESS) { errMaps_.emplace(REQUEST_CMD_SETDISPLAYCLIENTBUFFER, ec); } @@ -592,16 +584,15 @@ private: void *vAddr = gralloc_->Mmap(buffer); ec = (vAddr == nullptr ? HDF_FAILURE : HDF_SUCCESS); } - BufferHandleParcelable bufParcel(*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, *bufParcel.GetBufferHandle(), - fdParcel.GetFd()); + ec = impl_->SetLayerBuffer(devId, layerId, *buffer, fdParcel.GetFd()); } + FreeBufferHandle(buffer); if (ec != HDF_SUCCESS) { errMaps_.emplace(REQUEST_CMD_SETLAYERBUFFER, ec); } -- Gitee From 953312da12d8c588caf32cf3bafd859c733439d9 Mon Sep 17 00:00:00 2001 From: liuxk Date: Wed, 13 Jul 2022 09:27:57 +0800 Subject: [PATCH 10/24] Replace gralloc interface --- display/include/idisplay_gralloc.h | 154 ++++++++++++++++++ .../display_command/display_cmd_responser.h | 15 +- .../v1_0/display_command/display_cmd_utils.h | 2 +- 3 files changed, 162 insertions(+), 9 deletions(-) create mode 100644 display/include/idisplay_gralloc.h diff --git a/display/include/idisplay_gralloc.h b/display/include/idisplay_gralloc.h new file mode 100644 index 00000000..11fbacfd --- /dev/null +++ b/display/include/idisplay_gralloc.h @@ -0,0 +1,154 @@ +/* + * 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 HDI_IDISPLAY_GRALLOC_V1_0_H +#define HDI_IDISPLAY_GRALLOC_V1_0_H + +#include +#include "v1_0/hdi_display_device_type.h" +#include "buffer_handle.h" + +namespace OHOS { +namespace HDI { +namespace Display { +namespace V1_0 { +class IDisplayGralloc { +public: + virtual ~IDisplayGralloc() = default; + + /** + * @brief Obtains all interfaces of IDisplayGralloc. + * + * @return Returns IDisplayGralloc* if the operation is successful; returns an null point otherwise. + * @since 1.0 + * @version 1.0 + */ + // static sptr Get(); + static IDisplayGralloc* Get(); + + /** + * @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 Display +} // namespace HDI +} // namespace OHOS + +#endif // HDI_IDISPLAY_GRALLOC_V1_0_H diff --git a/display/v1_0/display_command/display_cmd_responser.h b/display/v1_0/display_command/display_cmd_responser.h index 8985ba5f..5dc72986 100644 --- a/display/v1_0/display_command/display_cmd_responser.h +++ b/display/v1_0/display_command/display_cmd_responser.h @@ -26,7 +26,7 @@ #include "command_data_packer.h" #include "command_data_unpacker.h" #include "display_cmd_utils.h" -#include "display_gralloc.h" +#include "idisplay_gralloc.h" #include "v1_0/include/idisplay_device_interface.h" #include "v1_0/hdi_display_device_type.h" @@ -56,15 +56,14 @@ public: replyPacker_(nullptr), gralloc_(nullptr) { - if (GrallocInitialize(&gralloc_) != DISPLAY_SUCCESS) { + gralloc_.reset(IDisplayGralloc::Get()); + if (gralloc_.get() == nullptr) { HDF_LOGE("error: DisplayCmdResponser construct failure"); } } + ~DisplayCmdResponser() { - if (GrallocUninitialize(gralloc_) != DISPLAY_SUCCESS) { - HDF_LOGE("error: DisplayCmdResponser destruct failure"); - } } int32_t InitCmdRequest(const std::shared_ptr& request) @@ -296,7 +295,7 @@ private: ec = CmdUtils::BufferHandleUnpack(unpacker, inFds, buffer); } if (ec == HDF_SUCCESS) { - void *vAddr = gralloc_->Mmap(buffer); + void *vAddr = gralloc_->Mmap(static_cast(*buffer)); ec = (vAddr == nullptr ? HDF_FAILURE : HDF_SUCCESS); } @@ -581,7 +580,7 @@ private: ec = CmdUtils::BufferHandleUnpack(unpacker, inFds, buffer); } if (ec == HDF_SUCCESS) { - void *vAddr = gralloc_->Mmap(buffer); + void *vAddr = gralloc_->Mmap(static_cast(*buffer)); ec = (vAddr == nullptr ? HDF_FAILURE : HDF_SUCCESS); } int32_t fence = -1; @@ -683,7 +682,7 @@ private: uint32_t replyCommandCnt_; std::shared_ptr replyPacker_; std::unordered_map errMaps_; - GrallocFuncs *gralloc_; + std::unique_ptr gralloc_; }; using HdiDisplayCmdResponser = DisplayCmdResponser, IDisplayDeviceInterface>; diff --git a/display/v1_0/display_command/display_cmd_utils.h b/display/v1_0/display_command/display_cmd_utils.h index 08c790a4..b2272b5d 100644 --- a/display/v1_0/display_command/display_cmd_utils.h +++ b/display/v1_0/display_command/display_cmd_utils.h @@ -19,7 +19,7 @@ #include "buffer_handle_utils.h" #include "command_data_packer.h" #include "command_data_unpacker.h" -#include "display_gralloc.h" +//#include "display_gralloc.h" #include "v1_0/hdi_display_device_type.h" namespace OHOS { -- Gitee From 6a1791a047e8601d7d5730a9bb377c2bdeea737a Mon Sep 17 00:00:00 2001 From: liuxk Date: Wed, 13 Jul 2022 15:13:28 +0800 Subject: [PATCH 11/24] Fix fd leak issues --- display/v1_0/display_command/display_cmd_responser.h | 5 +---- display/v1_0/display_command/display_cmd_utils.h | 5 +---- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/display/v1_0/display_command/display_cmd_responser.h b/display/v1_0/display_command/display_cmd_responser.h index 5dc72986..d5a77c5d 100644 --- a/display/v1_0/display_command/display_cmd_responser.h +++ b/display/v1_0/display_command/display_cmd_responser.h @@ -352,10 +352,7 @@ private: if (ec == HDF_SUCCESS) { ec = impl_->Commit(devId, fence); } - HdifdParcelable fdParcel; - if (ec == HDF_SUCCESS) { - ec = fdParcel.Init(fence) ? HDF_SUCCESS : HDF_FAILURE; - } + HdifdParcelable fdParcel(fence); // reply pack if (ec == HDF_SUCCESS) { ec = CmdUtils::StartSection(REPLY_CMD_COMMIT, replyPacker_); diff --git a/display/v1_0/display_command/display_cmd_utils.h b/display/v1_0/display_command/display_cmd_utils.h index b2272b5d..1d78112d 100644 --- a/display/v1_0/display_command/display_cmd_utils.h +++ b/display/v1_0/display_command/display_cmd_utils.h @@ -186,13 +186,10 @@ public: HDF_LOGE("error: new HdifdParcelable failed"); ec = HDF_FAILURE; } else { - int32_t transFd = -1; if (fd >= 0) { // A normal fd is transfered by binder, // Here just write id for unpacking to match fd. - transFd = dup(fd); - ec = (transFd >= 0 ? HDF_SUCCESS : HDF_FAILURE); - if (ec == HDF_SUCCESS && hdifdInfo.hdiFd->Init(transFd)) { + if (ec == HDF_SUCCESS && hdifdInfo.hdiFd->Init(fd)) { hdiFds.push_back(hdifdInfo); ec = packer->WriteInt32(hdifdInfo.id) ? HDF_SUCCESS : HDF_FAILURE; } else { -- Gitee From 3bae859e093d600d8a1ab767d73c8cef87188d0f Mon Sep 17 00:00:00 2001 From: liuxk Date: Wed, 13 Jul 2022 18:36:35 +0800 Subject: [PATCH 12/24] Fix memory leak issue --- display/v1_0/display_command/display_cmd_responser.h | 8 -------- 1 file changed, 8 deletions(-) diff --git a/display/v1_0/display_command/display_cmd_responser.h b/display/v1_0/display_command/display_cmd_responser.h index d5a77c5d..8212442a 100644 --- a/display/v1_0/display_command/display_cmd_responser.h +++ b/display/v1_0/display_command/display_cmd_responser.h @@ -294,10 +294,6 @@ private: if (ec == HDF_SUCCESS) { ec = CmdUtils::BufferHandleUnpack(unpacker, inFds, buffer); } - if (ec == HDF_SUCCESS) { - void *vAddr = gralloc_->Mmap(static_cast(*buffer)); - ec = (vAddr == nullptr ? HDF_FAILURE : HDF_SUCCESS); - } int32_t fence = -1; if (ec == HDF_SUCCESS) { @@ -576,10 +572,6 @@ private: if (ec == HDF_SUCCESS) { ec = CmdUtils::BufferHandleUnpack(unpacker, inFds, buffer); } - if (ec == HDF_SUCCESS) { - void *vAddr = gralloc_->Mmap(static_cast(*buffer)); - ec = (vAddr == nullptr ? HDF_FAILURE : HDF_SUCCESS); - } int32_t fence = -1; if (ec == HDF_SUCCESS) { ec = CmdUtils::FileDescriptorUnpack(unpacker, inFds, fence); -- Gitee From 4a4b72a901cd68d274882aa997af388eb2c31cee Mon Sep 17 00:00:00 2001 From: liuxk Date: Thu, 14 Jul 2022 09:02:10 +0800 Subject: [PATCH 13/24] Code check first drop. --- .../buffer_handle_parcelable.cpp | 19 ++--- display/command_pack/command_data_packer.h | 75 +++++-------------- display/command_pack/command_data_unpacker.h | 29 ++++--- display/hdifdsequence/hdifd_parcelable.cpp | 15 +--- .../display_command/display_cmd_requester.h | 22 +----- .../display_command/display_cmd_responser.h | 4 +- .../v1_0/display_command/display_cmd_utils.h | 41 ---------- .../v1_0/include/idisplay_device_interface.h | 59 --------------- 8 files changed, 44 insertions(+), 220 deletions(-) diff --git a/display/buffersequence/buffer_handle_parcelable.cpp b/display/buffersequence/buffer_handle_parcelable.cpp index 48b8f325..96b867d1 100644 --- a/display/buffersequence/buffer_handle_parcelable.cpp +++ b/display/buffersequence/buffer_handle_parcelable.cpp @@ -90,8 +90,6 @@ bool BufferHandleParcelable::Init(const BufferHandle& handle) bool BufferHandleParcelable::Marshalling(Parcel& parcel) const { - HDF_LOGE("liuxk, %{public}d@%{public}s parcel size=%{public}d, dataptr=%{public}d", - __LINE__, __func__, parcel.GetDataSize(), parcel.GetWritePosition()); 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) || @@ -122,8 +120,6 @@ bool BufferHandleParcelable::Marshalling(Parcel& parcel) const return false; } } - HDF_LOGE("liuxk, %{public}d@%{public}s parcel size=%{public}d, dataptr=%{public}d", - __LINE__, __func__, parcel.GetDataSize(), parcel.GetWritePosition()); return true; } @@ -176,21 +172,18 @@ bool BufferHandleParcelable::ExtractFromParcel(Parcel& parcel) return false; } } - HDF_LOGE("liuxk, %{public}d@%{public}s reserveFds=%{public}d, reserveInts=%{public}d", __LINE__, __func__, handle_->reserveFds, handle_->reserveInts); return true; } sptr BufferHandleParcelable::Unmarshalling(Parcel& parcel) { sptr newParcelable = new BufferHandleParcelable(); - HDF_LOGE("liuxk, %{public}d@%{public}s parcel size=%{public}d, readptr=%{public}d", - __LINE__, __func__, parcel.GetDataSize(), parcel.GetReadPosition()); - newParcelable->ExtractFromParcel(parcel); - HDF_LOGE("liuxk, %{public}d@%{public}s parcel size=%{public}d, readptr=%{public}d", - __LINE__, __func__, parcel.GetDataSize(), parcel.GetReadPosition()); - HDF_LOGE("liuxk, %{public}d@%{public}s dump BufferHandleParcelable:\n%{public}s", - __LINE__, __func__, newParcelable->Dump().c_str()); - newParcelable->init_ = true; + bool ret = newParcelable->ExtractFromParcel(parcel); + if (!ret) { + return nullptr; + } else { + newParcelable->init_ = true; + } return newParcelable; } diff --git a/display/command_pack/command_data_packer.h b/display/command_pack/command_data_packer.h index 0e996023..727dc59b 100644 --- a/display/command_pack/command_data_packer.h +++ b/display/command_pack/command_data_packer.h @@ -24,47 +24,6 @@ namespace OHOS { namespace HDI { namespace DISPLAY { -#include -#include -#include -#include - -#define FILE_PATH "/data/hdi_file_log.txt" - -static char logBuffer[1024] = {0}; - -void WriteFile(const char* buff, const int32_t size) -{ - //char path[256] = "/data/hidl_file_log.txt"; - int logFd = -1; - int wSize; - int ret; - - logFd = open(FILE_PATH, O_RDWR | O_CREAT, 00766); // 00766:file operate permission - if (logFd == -1) { - return; - } - lseek(logFd, 0, SEEK_END); - - if (size == -1) { - wSize = strlen(buff); - } else { - wSize = size; - } - - ret = write(logFd , buff, wSize); - if (ret == -1) { - printf("demo test:write image file error.\n"); - } - - close(logFd); -} - -#define F_LOGE(fmt, ...) sprintf(logBuffer, "%d@%s, " fmt "\n", __LINE__, __func__, ##__VA_ARGS__); \ - WriteFile(logBuffer, strlen(logBuffer)) - - - class CommandDataPacker { public: CommandDataPacker() @@ -74,7 +33,8 @@ public: settingSecLen_(0), curSecLenPos_(0), data_(nullptr) - {} + { + } ~CommandDataPacker() { @@ -202,30 +162,29 @@ public: return ret; } - #define PACK_LOG F_LOGE - void Print() + void Dump() { - PACK_LOG("---------------------------------------------\n"); - PACK_LOG("ALLOC_PAGE_SIZE =%d\n", ALLOC_PAGE_SIZE); - PACK_LOG("INIT_DATA_SIZE =%d\n", INIT_DATA_SIZE); - PACK_LOG("SECTION_END_MAGIC =0x%x\n", SECTION_END_MAGIC); - PACK_LOG("packSize_ =%d\n", packSize_); - PACK_LOG("writePos_ =%d\n", writePos_); - PACK_LOG("curSecOffset_ =%d\n", curSecOffset_); - PACK_LOG("settingSecLen_ =%d\n", settingSecLen_); - PACK_LOG("curSecLenPos_ =%d\n", curSecLenPos_); - PACK_LOG("data_ =%p\n", data_); + 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_;) { - PACK_LOG("%08x ", *reinterpret_cast(data_ + 4*i)); + HDF_LOGI("%{public}08x ", *reinterpret_cast(data_ + 4*i)); i++; if (i%8 == 0) { - PACK_LOG("\n"); + HDF_LOGI("\n"); } else if (i%4 == 0) { - PACK_LOG(" "); + HDF_LOGI(" "); } else {} } - PACK_LOG("\n"); + HDF_LOGI("\n"); } private: template diff --git a/display/command_pack/command_data_unpacker.h b/display/command_pack/command_data_unpacker.h index 1d6bdfa6..79a933e2 100644 --- a/display/command_pack/command_data_unpacker.h +++ b/display/command_pack/command_data_unpacker.h @@ -129,28 +129,27 @@ public: return ret; } - #define PACK_LOG F_LOGE - void Print() + void Dump() { - PACK_LOG("---------------------------------------------\n"); - PACK_LOG("SECTION_END_MAGIC =0x%x\n", SECTION_END_MAGIC); - PACK_LOG("COMMAND_ID_SIZE =%d\n", COMMAND_ID_SIZE); - PACK_LOG("packSize_ =%d\n", packSize_); - PACK_LOG("readPos_ =%d\n", readPos_); - PACK_LOG("curSecOffset_ =%d\n", curSecOffset_); - PACK_LOG("curSecLen_ =%d\n", curSecLen_); - PACK_LOG("data_ =%p\n", data_); + 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_;) { - PACK_LOG("%08x ", *reinterpret_cast(data_ + 4*i)); + HDF_LOGI("%{public}08x ", *reinterpret_cast(data_ + 4*i)); i++; if (i%8 == 0) { - PACK_LOG("\n"); + HDF_LOGI("\n"); } else if (i%4 == 0) { - PACK_LOG(" "); + HDF_LOGI(" "); } else {} } - PACK_LOG("\n"); + HDF_LOGI("\n"); } private: @@ -166,8 +165,6 @@ private: } value = *reinterpret_cast(data_ + readPos_); - //HDF_LOGE("liuxk read: readPos=%{public}d, packsize=%{public}d, value=%{public}d.", - // readPos_, packSize_, value); readPos_ += dataSize; return true; diff --git a/display/hdifdsequence/hdifd_parcelable.cpp b/display/hdifdsequence/hdifd_parcelable.cpp index a39d4438..8c5d46f4 100644 --- a/display/hdifdsequence/hdifd_parcelable.cpp +++ b/display/hdifdsequence/hdifd_parcelable.cpp @@ -57,7 +57,10 @@ bool HdifdParcelable::Init(int32_t fd) hdiFd_ = dup(fd); ret = (hdiFd_ < 0) ? false : true; } - if (ret == false) return ret; + if (ret == false) + { + return ret; + } init_ = true; } @@ -97,8 +100,6 @@ int HdifdParcelable::ReadFileDescriptor(Parcel& parcel) bool HdifdParcelable::Marshalling(Parcel& parcel) const { - HDF_LOGE("liuxk, %{public}d@%{public}s parcel size=%{public}d, dataptr=%{public}d", - __LINE__, __func__, parcel.GetDataSize(), parcel.GetData()); bool validFlag = (hdiFd_ >= 0); if (!parcel.WriteBool(validFlag)) { HDF_LOGE("%{public}s parcel.WriteBool failed", __func__); @@ -108,16 +109,12 @@ bool HdifdParcelable::Marshalling(Parcel& parcel) const HDF_LOGE("%{public}s parcel.WriteFileDescriptor fd failed", __func__); return false; } - HDF_LOGE("liuxk, %{public}d@%{public}s parcel size=%{public}d, dataptr=%{public}d", - __LINE__, __func__, parcel.GetDataSize(), parcel.GetData()); return true; } sptr HdifdParcelable::Unmarshalling(Parcel& parcel) { bool validFlag = false; - HDF_LOGE("liuxk, %{public}d@%{public}s parcel size=%{public}d, dataptr=%{public}d", - __LINE__, __func__, parcel.GetDataSize(), parcel.GetData()); if (!parcel.ReadBool(validFlag)) { HDF_LOGE("%{public}s ReadBool validFlag failed", __func__); return nullptr; @@ -132,10 +129,6 @@ sptr HdifdParcelable::Unmarshalling(Parcel& parcel) } sptr newParcelable = new HdifdParcelable(fd); //newParcelable->Init(fd); - HDF_LOGE("liuxk, %{public}d@%{public}s parcel size=%{public}d, dataptr=%{public}d", - __LINE__, __func__, parcel.GetDataSize(), parcel.GetData()); - HDF_LOGE("liuxk, %{public}d@%{public}s dump HdifdParcelable:\n%{public}s", - __LINE__, __func__, newParcelable->Dump().c_str()); newParcelable->init_ = true; return newParcelable; } diff --git a/display/v1_0/display_command/display_cmd_requester.h b/display/v1_0/display_command/display_cmd_requester.h index 82c95e0f..7452049e 100644 --- a/display/v1_0/display_command/display_cmd_requester.h +++ b/display/v1_0/display_command/display_cmd_requester.h @@ -103,8 +103,6 @@ public: size_t replyEleCnt; std::vector outFds; std::shared_ptr replyData; - HDF_LOGE("liuxk, %{public}d@%{public}s, PrepareDisplayLayers ec=%{public}d", - __LINE__, __func__, ec); if (ec == HDF_SUCCESS) { ec = DoRequest(replyEleCnt, outFds, replyData); } @@ -113,18 +111,12 @@ public: ec = DoReplyResults(replyEleCnt, outFds, replyData, [&](void* data)->int32_t { needFlushFb = *(reinterpret_cast(data)); return HDF_SUCCESS; - HDF_LOGE("liuxk, %{public}d@%{public}s, PrepareDisplayLayers ec=%{public}d", - __LINE__, __func__, ec); }); } - HDF_LOGE("liuxk, %{public}d@%{public}s, PrepareDisplayLayers ec=%{public}d", - __LINE__, __func__, ec); if (ec != HDF_SUCCESS) { HDF_LOGE("PrepareDisplayLayers failure, ec=%{public}d", ec); } - HDF_LOGE("liuxk, %{public}d@%{public}s, PrepareDisplayLayers ec=%{public}d", - __LINE__, __func__, ec); return PeriodDataReset(); } @@ -191,7 +183,6 @@ public: std::shared_ptr replyData; if (ec == HDF_SUCCESS) { ec = DoRequest(replyEleCnt, outFds, replyData); - F_LOG("liuxk, ec=%d", ec); } if (ec == HDF_SUCCESS) { @@ -199,14 +190,12 @@ public: fence = *(reinterpret_cast(data)); return HDF_SUCCESS; }); - F_LOG("liuxk, ec=%d, fence=%d", ec, fence); } if (ec != HDF_SUCCESS) { HDF_LOGE("Commit failure, ec=%{public}d", ec); } - F_LOG("liuxk, ec=%d, fence=%d", ec, fence); return PeriodDataReset(); } @@ -492,7 +481,7 @@ private: std::shared_ptr replyUnpacker = std::make_shared(); replyUnpacker->Init(replyData.get(), replyEleCnt * CmdUtils::ELEMENT_SIZE); - replyUnpacker->Print(); // liuxk + replyUnpacker->Dump(); // liuxk int32_t unpackCmd = -1; int32_t ec = HDF_SUCCESS; if (!replyUnpacker->PackBegin(unpackCmd)) { @@ -517,8 +506,6 @@ private: if (ec == HDF_SUCCESS) { ec = fn(&needFlushFb); } - HDF_LOGE("liuxk, %{public}d@%{public}s, PrepareDisplayLayers ec=%{public}d, needFlushFb=%{public}d", - __LINE__, __func__, ec, needFlushFb); if (ec != HDF_SUCCESS) { HDF_LOGI("error: ReadBool failed, unpackCmd=%{public}s.", CmdUtils::CommandToString(unpackCmd)); @@ -539,12 +526,9 @@ private: { int32_t fenceFd = -1; ec = OnReplyCommit(replyUnpacker, replyFds, fenceFd); - HDF_LOGE("liuxk, commit ec=%{bublic}d, fenceFd=%{public}d", ec, fenceFd); if (ec == HDF_SUCCESS) { ec = fn(&fenceFd); - HDF_LOGE("liuxk, commit 1 ec=%{public}d, fenceFd=%{public}d", ec, fenceFd); } - HDF_LOGE("liuxk, commit2 ec=%{public}d, fenceFd=%{public}d", ec, fenceFd); if (ec != HDF_SUCCESS) { HDF_LOGI("error: return fence fd error, unpackCmd=%{public}s.", CmdUtils::CommandToString(unpackCmd)); @@ -559,9 +543,7 @@ private: } if (ec == HDF_SUCCESS ) { ec = replyUnpacker->PackEnd(unpackCmd) ? HDF_SUCCESS : HDF_FAILURE; - F_LOG("liuxk, ec=%d", ec); } - F_LOG("liuxk, ec=%d", ec); if (unpackCmd != CONTROL_CMD_REPLY_END) { HDF_LOGE("error: PackEnd failed, endCmd = %{public}s", CmdUtils::CommandToString(unpackCmd)); @@ -573,7 +555,7 @@ private: int32_t DoRequest(size_t& replyEleCnt, std::vector& outFds, std::shared_ptr& replyData) { - requestPacker_->Print(); // liuxk + 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); diff --git a/display/v1_0/display_command/display_cmd_responser.h b/display/v1_0/display_command/display_cmd_responser.h index 8212442a..d38014d2 100644 --- a/display/v1_0/display_command/display_cmd_responser.h +++ b/display/v1_0/display_command/display_cmd_responser.h @@ -107,7 +107,7 @@ public: std::shared_ptr unpacker = std::make_shared(); if (ec == HDF_SUCCESS) { unpacker->Init(requestData.get(), inEleCnt * CmdUtils::ELEMENT_SIZE); - unpacker->Print(); // liuxk + unpacker->Dump(); // liuxk } else { ec = HDF_FAILURE; } @@ -193,7 +193,7 @@ public: replyPacker_->PackEnd(CONTROL_CMD_REPLY_END); HDF_LOGE("CmdReply command cnt=%{public}d", replyCommandCnt_); // Write reply pack - replyPacker_->Print(); // liuxk + replyPacker_->Dump(); // liuxk outEleCnt = replyPacker_->ValidSize() / CmdUtils::ELEMENT_SIZE; ec = reply_->Write(reinterpret_cast(replyPacker_->GetDataPtr()), outEleCnt, CmdUtils::TRANSFER_WAIT_TIME); diff --git a/display/v1_0/display_command/display_cmd_utils.h b/display/v1_0/display_command/display_cmd_utils.h index 1d78112d..c48af31c 100644 --- a/display/v1_0/display_command/display_cmd_utils.h +++ b/display/v1_0/display_command/display_cmd_utils.h @@ -19,7 +19,6 @@ #include "buffer_handle_utils.h" #include "command_data_packer.h" #include "command_data_unpacker.h" -//#include "display_gralloc.h" #include "v1_0/hdi_display_device_type.h" namespace OHOS { @@ -29,46 +28,6 @@ namespace V1_0 { using namespace OHOS::HDI::Display::V1_0; -#include -#include -#include -#include - -#define FILE_PATH "/data/hdi_file_log.txt" - -static char logBuffer[1024] = {0}; - -void WriteFile(const char* buff, const int32_t size) -{ - //char path[256] = "/data/hidl_file_log.txt"; - int logFd = -1; - int wSize; - int ret; - - logFd = open(FILE_PATH, O_RDWR | O_CREAT, 00766); // 00766:file operate permission - if (logFd == -1) { - return; - } - lseek(logFd, 0, SEEK_END); - - if (size == -1) { - wSize = strlen(buff); - } else { - wSize = size; - } - - ret = write(logFd , buff, wSize); - if (ret == -1) { - printf("demo test:write image file error.\n"); - } - - close(logFd); -} - -#define F_LOG(fmt, ...) sprintf(logBuffer, "%d@%s, " fmt "\n", __LINE__, __func__, ##__VA_ARGS__); \ - WriteFile(logBuffer, strlen(logBuffer)) - - class DisplayCmdUtils { public: static constexpr int32_t MAX_INT = 0x7fffffff; diff --git a/display/v1_0/include/idisplay_device_interface.h b/display/v1_0/include/idisplay_device_interface.h index bea8b3c1..5d6df6ec 100644 --- a/display/v1_0/include/idisplay_device_interface.h +++ b/display/v1_0/include/idisplay_device_interface.h @@ -82,65 +82,6 @@ public: 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; - // not implement for openharmony - //virtual int32_t RegDisplayRefreshCallback(uint32_t devId, RefreshCallback callback, - // void *data) = 0; - //virtual int32_t GetDisplaySupportedColorGamuts(uint32_t devId, uint32_t& num, - // ColorGamut& gamuts) = 0; - //virtual int32_t GetDisplayColorGamut(uint32_t devId, ColorGamut& gamut) = 0; - //virtual int32_t SetDisplayColorGamut(uint32_t devId, ColorGamut gamut) = 0; - //virtual int32_t GetDisplayGamutMap(uint32_t devId, GamutMap& gamutMap) = 0; - //virtual int32_t SetDisplayGamutMap(uint32_t devId, GamutMap gamutMap) = 0; - //virtual int32_t SetDisplayColorTransform(uint32_t devId, const float& matrix) = 0; - //virtual int32_t GetHDRCapabilityInfos(uint32_t devId, HDRCapability& info) = 0; - //virtual int32_t GetSupportedMetadataKey(uint32_t devId, - // std::vector& keys) = 0; - //virtual int32_t InvokeDisplayCmd(uint32_t devId, ...) = 0; - //virtual int32_t GetWriteBackFrame(uint32_t devId, BufferHandle& buffer, int32_t& fence) = 0; - //virtual int32_t CreateWriteBack(uint32_t& devId, uint32_t width, uint32_t height, - // int32_t& format) = 0; - //virtual int32_t DestroyWriteBack(uint32_t devId) = 0; - - //virtual int32_t InitDisplay(uint32_t devId) = 0; - //virtual int32_t DeinitDisplay(uint32_t devId) = 0; - //virtual int32_t GetDisplayInfo(uint32_t devId, DisplayInfo& dispInfo) = 0; - //virtual int32_t GetLayerVisibleState(uint32_t devId, uint32_t layerId, bool& visible) = 0; - //virtual int32_t GetLayerSize(uint32_t devId, uint32_t layerId, IRect& rect) = 0; - //virtual int32_t GetLayerZorder(uint32_t devId, uint32_t layerId, uint32_t& zorder) = 0; - //virtual int32_t GetLayerPreMulti(uint32_t devId, uint32_t layerId, bool& preMul) = 0; - //virtual int32_t GetLayerAlpha(uint32_t devId, uint32_t layerId, LayerAlpha& alpha) = 0; - //virtual int32_t SetLayerColorKey(uint32_t devId, uint32_t layerId, bool enable, - // uint32_t key) = 0; - //virtual int32_t GetLayerColorKey(uint32_t devId, uint32_t layerId, bool& enable, - // uint32_t& key) = 0; - //virtual int32_t SetLayerPalette(uint32_t devId, uint32_t layerId, uint32_t& palette, - // uint32_t len) = 0; - //virtual int32_t GetLayerPalette(uint32_t devId, uint32_t layerId, uint32_t& palette, - // uint32_t len) = 0; - //virtual int32_t SetLayerCompression(uint32_t devId, uint32_t layerId, int32_t compType) = 0; - //virtual int32_t GetLayerCompression(uint32_t devId, uint32_t layerId, int32_t& compType) = 0; - //virtual int32_t GetLayerBuffer(uint32_t devId, uint32_t layerId, LayerBuffer& buffer) = 0; - //virtual int32_t Flush(uint32_t devId, uint32_t layerId, LayerBuffer& buffer) = 0; - //virtual int32_t WaitForVBlank(uint32_t devId, uint32_t layerId, int32_t timeOut) = 0; - //virtual int32_t SnapShot(uint32_t devId, LayerBuffer& buffer) = 0; - //virtual int32_t InvokeLayerCmd(uint32_t devId, uint32_t layerId, uint32_t cmd, ...) = 0; - //virtual int32_t SetLayerColorTransform(uint32_t devId, uint32_t layerId, - // const float& matrix) = 0; - //virtual int32_t SetLayerColorDataSpace(uint32_t devId, uint32_t layerId, - // ColorDataSpace colorSpace) = 0; - //virtual int32_t GetLayerColorDataSpace(uint32_t devId, uint32_t layerId, - // ColorDataSpace& colorSpace) = 0; - //virtual int32_t SetLayerMetaData(uint32_t devId, uint32_t layerId, - // const std::vector metaData) = 0; - //virtual int32_t SetLayerMetaDataSet(uint32_t devId, uint32_t layerId, HDRMetadataKey key, - // const std::vector metaData) = 0; - //virtual int32_t GetSupportedPresentTimestamp(uint32_t devId, uint32_t layerId, - // PresentTimestampType& type) = 0; - //virtual int32_t GetHwPresentTimestamp(uint32_t devId, uint32_t layerId, - // PresentTimestamp& pts) = 0; - //virtual int32_t SetLayerTunnelHandle(uint32_t devId, uint32_t layerId, - // ExtDataHandle& handle) = 0; - //virtual int32_t GetLayerReleaseFence(uint32_t devId, uint32_t layerId, int32_t& fence) = 0; }; } // V1_0 } // Display -- Gitee From 95e37326bef83b7ce61a30cb767f7cfe6ca51ce6 Mon Sep 17 00:00:00 2001 From: liuxk Date: Thu, 14 Jul 2022 09:49:02 +0800 Subject: [PATCH 14/24] Remove num out arguments from interfaces. --- display/v1_0/IDisplayDevice.idl | 40 ++----------------- .../v1_0/hdi_impl/display_device_hdi_impl.h | 16 ++++---- .../v1_0/include/idisplay_device_interface.h | 10 ++--- 3 files changed, 17 insertions(+), 49 deletions(-) diff --git a/display/v1_0/IDisplayDevice.idl b/display/v1_0/IDisplayDevice.idl index 4caa73dd..95a0e51c 100644 --- a/display/v1_0/IDisplayDevice.idl +++ b/display/v1_0/IDisplayDevice.idl @@ -26,8 +26,7 @@ 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] unsigned int num, - [out] struct DisplayModeInfo[] modes); + 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); @@ -35,14 +34,13 @@ interface IDisplayDevice { 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 num, - [out] unsigned int[] layers, [out] int[] type); + 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 num, - [out] unsigned int[] layers, [out] HdifdParcelable[] fences); + 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); @@ -57,34 +55,4 @@ interface IDisplayDevice { CmdRequest([in] unsigned int inEleCnt, [in] struct HdifdInfo[] inFds, [out] unsigned int outEleCnt, [out] struct HdifdInfo[] outFds); GetCmdReply([out] SharedMemQueue reply); - //TestFn([in] unsigned int inEleCnt, [in] unsigned int[] inFdCnt, - // [in] HdifdParcelable[] inFds, [out] unsigned int outEleCnt, - // [out] unsigned int[] outFdCnt, [out] HdifdParcelable[] outFds); - - // interfaces implement by smq - //PrepareDisplayLayers([in] unsigned int devId, [out] boolean needFlushFb); - //SetDisplayClientBuffer([in] unsigned int devId, [in] BufferHandleParcelable buffer, - // [in] int fence); - //SetDisplayClientDamage([in] unsigned int devId, [out] unsigned int num, - // [out] struct IRect[] rect); - //Commit([in] unsigned int devId, [out] int fence); - //SetLayerAlpha([in] unsigned int devId, [in] unsigned int layerId, - // [in] struct LayerAlpha alpha); - //SetLayerSize([in] unsigned int devId, [in] unsigned int layerId, [in] struct IRect rect); - //SetLayerCrop([in] unsigned int devId, [in] unsigned int layerId, [in] struct IRect rect); - //SetLayerZorder([in] unsigned int devId, [in] unsigned int layerId, [in] unsigned int zorder); - //SetLayerPreMulti([in] unsigned int devId, [in] unsigned int layerId, [in] boolean preMul); - //SetTransformMode([in] unsigned int devId, [in] unsigned int layerId, - // [in] enum TransformType type); - //SetLayerDirtyRegion([in] unsigned int devId, [in] unsigned int layerId, - // [in] struct IRect region); - //SetLayerVisibleRegion([in] unsigned int devId, [in] unsigned int layerId, - // [out] unsigned int num, [out] struct IRect[] rect); - //SetLayerBuffer = , - // [in] BufferHandleParcelable buffer, [in] int fence); - //SetLayerCompositionType = , - // [in] enum CompositionType type); - //SetLayerBlendType = , - // [in] enum BlendType type); - //SetLayerVisible = , } diff --git a/display/v1_0/hdi_impl/display_device_hdi_impl.h b/display/v1_0/hdi_impl/display_device_hdi_impl.h index 4d19b65a..db425fac 100644 --- a/display/v1_0/hdi_impl/display_device_hdi_impl.h +++ b/display/v1_0/hdi_impl/display_device_hdi_impl.h @@ -74,10 +74,10 @@ public: return hdi_->GetDisplayCapability(devId, info); } - virtual int32_t GetDisplaySupportedModes(uint32_t devId, uint32_t& num, + virtual int32_t GetDisplaySupportedModes(uint32_t devId, std::vector& modes) override { - return hdi_->GetDisplaySupportedModes(devId, num, modes); + return hdi_->GetDisplaySupportedModes(devId, modes); } virtual int32_t GetDisplayMode(uint32_t devId, uint32_t& modeId) override @@ -115,10 +115,10 @@ public: return hdi_->GetDisplayProperty(devId, id, value); } - virtual int32_t GetDisplayCompChange(uint32_t devId, uint32_t& num, - std::vector& layers, std::vector& types) override + virtual int32_t GetDisplayCompChange(uint32_t devId, std::vector& layers, + std::vector& types) override { - return hdi_->GetDisplayCompChange(devId, num, layers, types); + return hdi_->GetDisplayCompChange(devId, layers, types); } virtual int32_t SetDisplayClientCrop(uint32_t devId, const IRect& rect) override @@ -154,11 +154,11 @@ public: return hdi_->RegDisplayVBlankCallback(devId, this); } - virtual int32_t GetDisplayReleaseFence(uint32_t devId, uint32_t& num, - std::vector& layers, std::vector& fences) override + virtual int32_t GetDisplayReleaseFence(uint32_t devId, std::vector& layers, + std::vector& fences) override { std::vector> hdiFences; - int32_t ret = hdi_->GetDisplayReleaseFence(devId, num, layers, 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()); diff --git a/display/v1_0/include/idisplay_device_interface.h b/display/v1_0/include/idisplay_device_interface.h index 5d6df6ec..a4a6aeb0 100644 --- a/display/v1_0/include/idisplay_device_interface.h +++ b/display/v1_0/include/idisplay_device_interface.h @@ -33,7 +33,7 @@ public: // *** 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, uint32_t& num, + 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; @@ -42,8 +42,8 @@ public: 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, uint32_t& num, - std::vector& layers, std::vector& types) = 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, @@ -52,8 +52,8 @@ public: 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, uint32_t& num, - std::vector& layers, std::vector& fences) = 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; -- Gitee From 99c5f9e1774852947c0ddbe541b2fe14d7814be5 Mon Sep 17 00:00:00 2001 From: liuxk Date: Thu, 14 Jul 2022 11:26:35 +0800 Subject: [PATCH 15/24] Change namespace name --- display/buffersequence/buffer_handle_parcelable.cpp | 4 ++-- display/buffersequence/buffer_handle_parcelable.h | 4 ++-- display/command_pack/command_data_packer.h | 4 ++-- display/command_pack/command_data_unpacker.h | 4 ++-- display/hdifdsequence/hdifd_parcelable.cpp | 4 ++-- display/hdifdsequence/hdifd_parcelable.h | 4 ++-- display/include/display_common.h | 4 ++-- display/include/display_gfx.h | 4 ++-- display/include/display_gralloc.h | 4 ++-- display/v1_0/HdiDisplayDeviceType.idl | 4 ++-- display/v1_0/IDisplayDevice.idl | 4 ++-- display/v1_0/display_command/display_cmd_requester.h | 4 ++-- display/v1_0/display_command/display_cmd_responser.h | 4 ++-- display/v1_0/display_command/display_cmd_utils.h | 4 ++-- display/v1_0/hdi_impl/display_device_hdi_impl.h | 4 ++-- display/v1_0/include/idisplay_device_interface.h | 2 +- 16 files changed, 31 insertions(+), 31 deletions(-) diff --git a/display/buffersequence/buffer_handle_parcelable.cpp b/display/buffersequence/buffer_handle_parcelable.cpp index 96b867d1..d58d6a7a 100644 --- a/display/buffersequence/buffer_handle_parcelable.cpp +++ b/display/buffersequence/buffer_handle_parcelable.cpp @@ -24,7 +24,7 @@ namespace OHOS { namespace HDI { -namespace DISPLAY { +namespace Display { BufferHandleParcelable::BufferHandleParcelable() : init_(false), handle_(nullptr) @@ -272,6 +272,6 @@ std::string BufferHandleParcelable::Dump() const return os.str(); } -} // DISPLAY +} // Display } // HDI } // OHOS diff --git a/display/buffersequence/buffer_handle_parcelable.h b/display/buffersequence/buffer_handle_parcelable.h index 3287a2ed..37d749e5 100644 --- a/display/buffersequence/buffer_handle_parcelable.h +++ b/display/buffersequence/buffer_handle_parcelable.h @@ -23,7 +23,7 @@ namespace OHOS { namespace HDI { -namespace DISPLAY { +namespace Display { using namespace OHOS; @@ -50,7 +50,7 @@ private: bool init_; BufferHandle* handle_; }; -} // DISPLAY +} // Display } // HDI } // OHOS #endif // OHOS_HDI_BUFFER_HANDLE_PARCELABLE diff --git a/display/command_pack/command_data_packer.h b/display/command_pack/command_data_packer.h index 727dc59b..d08fe634 100644 --- a/display/command_pack/command_data_packer.h +++ b/display/command_pack/command_data_packer.h @@ -22,7 +22,7 @@ namespace OHOS { namespace HDI { -namespace DISPLAY { +namespace Display { class CommandDataPacker { public: @@ -224,7 +224,7 @@ private: size_t curSecLenPos_; char* data_; }; -} // DISPLAY +} // Display } // HDI } // OHOS #endif diff --git a/display/command_pack/command_data_unpacker.h b/display/command_pack/command_data_unpacker.h index 79a933e2..c9938248 100644 --- a/display/command_pack/command_data_unpacker.h +++ b/display/command_pack/command_data_unpacker.h @@ -21,7 +21,7 @@ namespace OHOS { namespace HDI { -namespace DISPLAY { +namespace Display { class CommandDataUnpacker { public: @@ -181,7 +181,7 @@ private: uint32_t curSecLen_; char* data_; }; -} // DISPLAY +} // Display } // HDI } // OHOS #endif diff --git a/display/hdifdsequence/hdifd_parcelable.cpp b/display/hdifdsequence/hdifd_parcelable.cpp index 8c5d46f4..f29a9f26 100644 --- a/display/hdifdsequence/hdifd_parcelable.cpp +++ b/display/hdifdsequence/hdifd_parcelable.cpp @@ -24,7 +24,7 @@ namespace OHOS { namespace HDI { -namespace DISPLAY { +namespace Display { HdifdParcelable::HdifdParcelable() : init_(false), hdiFd_(-1) @@ -150,6 +150,6 @@ std::string HdifdParcelable::Dump() const return os.str(); } -} // DISPLAY +} // Display } // HDI } // OHOS diff --git a/display/hdifdsequence/hdifd_parcelable.h b/display/hdifdsequence/hdifd_parcelable.h index dba13ac3..54ec2ba7 100644 --- a/display/hdifdsequence/hdifd_parcelable.h +++ b/display/hdifdsequence/hdifd_parcelable.h @@ -23,7 +23,7 @@ namespace OHOS { namespace HDI { -namespace DISPLAY { +namespace Display { using namespace OHOS; @@ -48,7 +48,7 @@ private: bool init_; int32_t hdiFd_; }; -} // DISPLAY +} // Display } // HDI } // OHOS #endif // OHOS_HDI_HDIFD_PARCELABLE diff --git a/display/include/display_common.h b/display/include/display_common.h index e4fbd1fc..a4af760f 100644 --- a/display/include/display_common.h +++ b/display/include/display_common.h @@ -20,7 +20,7 @@ namespace OHOS { namespace HDI { -namespace DISPLAY { +namespace Display { typedef void (*HotPlugCallback)(uint32_t devId, bool connected, void *data); typedef void (*VBlankCallback)(unsigned int sequence, uint64_t ns, void *data); @@ -29,7 +29,7 @@ typedef void (*RefreshCallback)(uint32_t devId, void *data); //typedef std::function VBlankCallback; //typedef std::function RefreshCallback; -} // DISPLAY +} // Display } // HDI } // OHOS #endif /* DISPLAY_COMMON_H */ diff --git a/display/include/display_gfx.h b/display/include/display_gfx.h index 63cef320..446151ba 100644 --- a/display/include/display_gfx.h +++ b/display/include/display_gfx.h @@ -42,7 +42,7 @@ #ifdef __cplusplus namespace OHOS { namespace HDI { -namespace DISPLAY { +namespace Display { using namespace OHOS::HDI::Display::V1_0; extern "C" { @@ -194,7 +194,7 @@ int32_t GfxInitialize(GfxFuncs **funcs); int32_t GfxUninitialize(GfxFuncs *funcs); } -} // DISPLAY +} // Display } // HDI } // OHOS #endif diff --git a/display/include/display_gralloc.h b/display/include/display_gralloc.h index 9e10ec27..a3f402fa 100644 --- a/display/include/display_gralloc.h +++ b/display/include/display_gralloc.h @@ -42,7 +42,7 @@ #ifdef __cplusplus namespace OHOS { namespace HDI { -namespace DISPLAY { +namespace Display { using namespace OHOS::HDI::Display::V1_0; extern "C" { @@ -200,7 +200,7 @@ int32_t GrallocInitialize(GrallocFuncs **funcs); int32_t GrallocUninitialize(GrallocFuncs *funcs); } -} // DISPLAY +} // Display } // HDI } // OHOS #endif diff --git a/display/v1_0/HdiDisplayDeviceType.idl b/display/v1_0/HdiDisplayDeviceType.idl index c512a5fb..d9775f7e 100644 --- a/display/v1_0/HdiDisplayDeviceType.idl +++ b/display/v1_0/HdiDisplayDeviceType.idl @@ -15,8 +15,8 @@ package ohos.hdi.display.v1_0; -sequenceable OHOS.HDI.DISPLAY.BufferHandleParcelable; -sequenceable OHOS.HDI.DISPLAY.HdifdParcelable; +sequenceable OHOS.HDI.Display.BufferHandleParcelable; +sequenceable OHOS.HDI.Display.HdifdParcelable; enum DispCmd { // request cmd diff --git a/display/v1_0/IDisplayDevice.idl b/display/v1_0/IDisplayDevice.idl index 95a0e51c..c8cc31c8 100644 --- a/display/v1_0/IDisplayDevice.idl +++ b/display/v1_0/IDisplayDevice.idl @@ -20,8 +20,8 @@ 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; +sequenceable OHOS.HDI.Display.HdifdParcelable; +sequenceable OHOS.HDI.Display.BufferHandleParcelable; interface IDisplayDevice { RegHotPlugCallback([in] IHotPlugCallback cb); diff --git a/display/v1_0/display_command/display_cmd_requester.h b/display/v1_0/display_command/display_cmd_requester.h index 7452049e..699c58e1 100644 --- a/display/v1_0/display_command/display_cmd_requester.h +++ b/display/v1_0/display_command/display_cmd_requester.h @@ -29,7 +29,7 @@ namespace OHOS { namespace HDI { -namespace DISPLAY { +namespace Display { namespace V1_0 { using namespace OHOS::HDI::Base; @@ -604,7 +604,7 @@ private: using HdiDisplayCmdRequester = DisplayCmdRequester, IDisplayDevice>; } // V1_0 -} // DISPLAY +} // 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 index d38014d2..c57bef9e 100644 --- a/display/v1_0/display_command/display_cmd_responser.h +++ b/display/v1_0/display_command/display_cmd_responser.h @@ -32,7 +32,7 @@ namespace OHOS { namespace HDI { -namespace DISPLAY { +namespace Display { namespace V1_0 { using namespace OHOS::HDI::Base; @@ -676,7 +676,7 @@ private: using HdiDisplayCmdResponser = DisplayCmdResponser, IDisplayDeviceInterface>; } // V1_0 -} // DISPLAY +} // 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 index c48af31c..0cc0ab13 100644 --- a/display/v1_0/display_command/display_cmd_utils.h +++ b/display/v1_0/display_command/display_cmd_utils.h @@ -23,7 +23,7 @@ namespace OHOS { namespace HDI { -namespace DISPLAY { +namespace Display { namespace V1_0 { using namespace OHOS::HDI::Display::V1_0; @@ -327,7 +327,7 @@ public: }; using CmdUtils = DisplayCmdUtils; } // V1_0 -} // DISPLAY +} // Display } // HDI } // OHOS #endif diff --git a/display/v1_0/hdi_impl/display_device_hdi_impl.h b/display/v1_0/hdi_impl/display_device_hdi_impl.h index db425fac..e6523eb9 100644 --- a/display/v1_0/hdi_impl/display_device_hdi_impl.h +++ b/display/v1_0/hdi_impl/display_device_hdi_impl.h @@ -25,7 +25,7 @@ namespace OHOS { namespace HDI { -namespace DISPLAY { +namespace Display { namespace V1_0 { #define CHECK_AND_RETURN(x, code) \ @@ -326,7 +326,7 @@ private: using HdiDisplayDeviceImpl = DisplayDeviceHdiImpl; } // V1_0 -} // DISPLAY +} // Display } // HDI } // OHOS #endif diff --git a/display/v1_0/include/idisplay_device_interface.h b/display/v1_0/include/idisplay_device_interface.h index a4a6aeb0..770594c2 100644 --- a/display/v1_0/include/idisplay_device_interface.h +++ b/display/v1_0/include/idisplay_device_interface.h @@ -22,7 +22,7 @@ namespace OHOS { namespace HDI { -namespace DISPLAY { +namespace Display { namespace V1_0 { using namespace OHOS::HDI::Display::V1_0; -- Gitee From fae325dfb16299cddd0b988a20ec9131ffc0f1d4 Mon Sep 17 00:00:00 2001 From: liuxk Date: Thu, 14 Jul 2022 16:09:54 +0800 Subject: [PATCH 16/24] Add gralloc interface --- gralloc/BUILD.gn | 24 ++++++ gralloc/bundle.json | 42 ++++++++++ gralloc/v1_0/.BUILD.gn.swp | Bin 0 -> 12288 bytes gralloc/v1_0/BUILD.gn | 74 ++++++++++++++++++ gralloc/v1_0/GrallocTypes.idl | 62 +++++++++++++++ gralloc/v1_0/IAllocatorInterface.idl | 24 ++++++ gralloc/v1_0/IMapperInterface.idl | 30 ++++++++ gralloc/v1_0/hdi_impl/gralloc_hdi_impl.cpp | 85 +++++++++++++++++++++ gralloc/v1_0/hdi_impl/gralloc_hdi_impl.h | 51 +++++++++++++ gralloc/v1_0/include/igralloc_interface.h | 45 +++++++++++ 10 files changed, 437 insertions(+) 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 create mode 100644 gralloc/v1_0/hdi_impl/gralloc_hdi_impl.h create mode 100644 gralloc/v1_0/include/igralloc_interface.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..96efac5e --- /dev/null +++ b/gralloc/v1_0/BUILD.gn @@ -0,0 +1,74 @@ +# 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_peripheral_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 = [ + "//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 = "display_device_driver" +} diff --git a/gralloc/v1_0/GrallocTypes.idl b/gralloc/v1_0/GrallocTypes.idl new file mode 100644 index 00000000..a5a6df86 --- /dev/null +++ b/gralloc/v1_0/GrallocTypes.idl @@ -0,0 +1,62 @@ +/* + * 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; + +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, +}; + +struct AllocInfo { + unsigned int width; + unsigned int height; + unsigned long usage; + enum PixelFormat format; + unsigned int expectedSize; +}; \ No newline at end of file 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 b/gralloc/v1_0/hdi_impl/gralloc_hdi_impl.cpp new file mode 100644 index 00000000..fa00d552 --- /dev/null +++ b/gralloc/v1_0/hdi_impl/gralloc_hdi_impl.cpp @@ -0,0 +1,85 @@ +/* + * 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" + +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) +{ + 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) +{ + sptr hdiBuffer; + hdiBuffer->Init(handle); + mapper_->FreeMem(hdiBuffer); +} + +void* GrallocHdiImpl::Mmap(const BufferHandle& handle) +{ + sptr hdiBuffer(handle); + hdiBuffer->Init(handle); + return mapper_->Mmap(handle); +} + +void* GrallocHdiImpl::MmapCache(const BufferHandle& buffer) +{ + return mapper_->MmapCache(handle); +} + +int32_t GrallocHdiImpl::Unmap(const BufferHandle& handle) +{ + return mapper_->Unmap(handle); +} + +int32_t GrallocHdiImpl::FlushCache(const BufferHandle& handle) +{ + return mapper_->FlushCache(handle); +} + +int32_t GrallocHdiImpl::FlushMCache(const BufferHandle& buffer) +{ + return mapper_->FlushMCache(handle); +} + +int32_t GrallocHdiImpl::InvalidateCache(const BufferHandle& handle) +{ + return mapper_->InvalidateCache(handle); +} + +} // namespace V1_0 +} // namespace Gralloc +} // namespace HDI +} // namespace OHOS + +#endif // GRALLOC_HDI_IMPL_V1_0_H 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..2975b1f7 --- /dev/null +++ b/gralloc/v1_0/hdi_impl/gralloc_hdi_impl.h @@ -0,0 +1,51 @@ +/* + * 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 "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) override; + virtual void FreeMem(const BufferHandle& handle) override; + virtual void *Mmap(const BufferHandle& handle) override; + virtual void *MmapCache(const BufferHandle& buffer) override; + virtual int32_t Unmap(const BufferHandle& handle) override; + virtual int32_t FlushCache(const BufferHandle& handle) override; + virtual int32_t FlushMCache(const BufferHandle& buffer) override; + virtual int32_t InvalidateCache(const BufferHandle& handle) 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 b/gralloc/v1_0/include/igralloc_interface.h new file mode 100644 index 00000000..a2be24fd --- /dev/null +++ b/gralloc/v1_0/include/igralloc_interface.h @@ -0,0 +1,45 @@ +/* + * 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 HDI_GRALLOC_INTERFACE_V1_0_H +#define HDI_GRALLOC_INTERFACE_V1_0_H + +#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; + virtual int32_t AllocMem(const AllocInfo& info, BufferHandle*& handle) = 0; + virtual void FreeMem(const BufferHandle& handle) = 0; + virtual void *Mmap(const BufferHandle& handle) = 0; + virtual void *MmapCache(const BufferHandle& buffer) = 0; + virtual int32_t Unmap(const BufferHandle& handle) = 0; + virtual int32_t FlushCache(const BufferHandle& handle) = 0; + virtual int32_t FlushMCache(const BufferHandle& buffer) = 0; + virtual int32_t InvalidateCache(const BufferHandle& handle) = 0; +}; + +} // namespace V1_0 +} // namespace Gralloc +} // namespace HDI +} // namespace OHOS + +#endif // HDI_GRALLOC_INTERFACE_V1_0_H -- Gitee From 3bdd65805d898602db4f52a9fb1cbc99c4e03f45 Mon Sep 17 00:00:00 2001 From: liuxk Date: Thu, 14 Jul 2022 18:23:32 +0800 Subject: [PATCH 17/24] gralloc interface implement --- display/buffersequence/BUILD.gn | 4 +- gralloc/v1_0/BUILD.gn | 1 + gralloc/v1_0/hdi_impl/gralloc_hdi_impl.cpp | 50 ++++++++++++++++------ gralloc/v1_0/hdi_impl/gralloc_hdi_impl.h | 5 ++- 4 files changed, 41 insertions(+), 19 deletions(-) diff --git a/display/buffersequence/BUILD.gn b/display/buffersequence/BUILD.gn index c600ac0e..c76e3db2 100644 --- a/display/buffersequence/BUILD.gn +++ b/display/buffersequence/BUILD.gn @@ -38,9 +38,7 @@ ohos_shared_library("libbufferhandle_parcelable") { "-fno-strict-aliasing", ] - deps = [ - "//foundation/graphic/graphic_2d/utils/buffer_handle:buffer_handle", - ] + deps = [] external_deps = [ "utils_base:utils", diff --git a/gralloc/v1_0/BUILD.gn b/gralloc/v1_0/BUILD.gn index 96efac5e..2f0aaf9b 100755 --- a/gralloc/v1_0/BUILD.gn +++ b/gralloc/v1_0/BUILD.gn @@ -58,6 +58,7 @@ ohos_shared_library("libgralloc_hdi_impl") { ] 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", ] diff --git a/gralloc/v1_0/hdi_impl/gralloc_hdi_impl.cpp b/gralloc/v1_0/hdi_impl/gralloc_hdi_impl.cpp index fa00d552..1b804438 100644 --- a/gralloc/v1_0/hdi_impl/gralloc_hdi_impl.cpp +++ b/gralloc/v1_0/hdi_impl/gralloc_hdi_impl.cpp @@ -40,46 +40,68 @@ int32_t GrallocHdiImpl::AllocMem(const AllocInfo& info, BufferHandle*& handle) void GrallocHdiImpl::FreeMem(const BufferHandle& handle) { - sptr hdiBuffer; - hdiBuffer->Init(handle); + sptr hdiBuffer = + new BufferHandleParcelable(const_cast(handle)); mapper_->FreeMem(hdiBuffer); } void* GrallocHdiImpl::Mmap(const BufferHandle& handle) { - sptr hdiBuffer(handle); - hdiBuffer->Init(handle); - return mapper_->Mmap(handle); + sptr hdiBuffer = + new BufferHandleParcelable(const_cast(handle)); + int32_t ret = mapper_->Mmap(hdiBuffer); + hdiBuffer->Move(); + void *virAddr = (ret == HDF_SUCCESS ? handle.virAddr : nullptr); + return virAddr; } -void* GrallocHdiImpl::MmapCache(const BufferHandle& buffer) +void* GrallocHdiImpl::MmapCache(const BufferHandle& handle) { - return mapper_->MmapCache(handle); + sptr hdiBuffer = + new BufferHandleParcelable(const_cast(handle)); + int32_t ret = mapper_->MmapCache(hdiBuffer); + hdiBuffer->Move(); + void *virAddr = (ret == HDF_SUCCESS ? handle.virAddr : nullptr); + return virAddr; } int32_t GrallocHdiImpl::Unmap(const BufferHandle& handle) { - return mapper_->Unmap(handle); + sptr hdiBuffer = + new BufferHandleParcelable(const_cast(handle)); + int32_t ret = mapper_->Unmap(hdiBuffer); + hdiBuffer->Move(); + return ret; } int32_t GrallocHdiImpl::FlushCache(const BufferHandle& handle) { - return mapper_->FlushCache(handle); + sptr hdiBuffer = + new BufferHandleParcelable(const_cast(handle)); + int32_t ret = mapper_->FlushCache(hdiBuffer); + hdiBuffer->Move(); + return ret; } -int32_t GrallocHdiImpl::FlushMCache(const BufferHandle& buffer) +int32_t GrallocHdiImpl::FlushMCache(const BufferHandle& handle) { - return mapper_->FlushMCache(handle); + sptr hdiBuffer = + new BufferHandleParcelable(const_cast(handle)); + int32_t ret = mapper_->FlushMCache(hdiBuffer); + hdiBuffer->Move(); + return ret; } int32_t GrallocHdiImpl::InvalidateCache(const BufferHandle& handle) { - return mapper_->InvalidateCache(handle); + sptr hdiBuffer = + new BufferHandleParcelable(const_cast(handle)); + int32_t ret = mapper_->InvalidateCache(hdiBuffer); + hdiBuffer->Move(); + return ret; } } // namespace V1_0 } // namespace Gralloc } // namespace HDI } // namespace OHOS - -#endif // GRALLOC_HDI_IMPL_V1_0_H diff --git a/gralloc/v1_0/hdi_impl/gralloc_hdi_impl.h b/gralloc/v1_0/hdi_impl/gralloc_hdi_impl.h index 2975b1f7..1508493e 100644 --- a/gralloc/v1_0/hdi_impl/gralloc_hdi_impl.h +++ b/gralloc/v1_0/hdi_impl/gralloc_hdi_impl.h @@ -17,6 +17,7 @@ #define GRALLOC_HDI_IMPL_V1_0_H #include "buffer_handle.h" +#include "buffer_handle_parcelable.h" #include "igralloc_interface.h" #include "v1_0/iallocator_interface.h" #include "v1_0/imapper_interface.h" @@ -34,10 +35,10 @@ public: virtual int32_t AllocMem(const AllocInfo& info, BufferHandle*& handle) override; virtual void FreeMem(const BufferHandle& handle) override; virtual void *Mmap(const BufferHandle& handle) override; - virtual void *MmapCache(const BufferHandle& buffer) override; + virtual void *MmapCache(const BufferHandle& handle) override; virtual int32_t Unmap(const BufferHandle& handle) override; virtual int32_t FlushCache(const BufferHandle& handle) override; - virtual int32_t FlushMCache(const BufferHandle& buffer) override; + virtual int32_t FlushMCache(const BufferHandle& handle) override; virtual int32_t InvalidateCache(const BufferHandle& handle) override; private: sptr allocator_; -- Gitee From 12224540def4f972305617171328517cbd162cb1 Mon Sep 17 00:00:00 2001 From: liuxk Date: Fri, 15 Jul 2022 15:56:59 +0800 Subject: [PATCH 18/24] Add gralloc interface impl --- gralloc/v1_0/GrallocTypes.idl | 21 +++- gralloc/v1_0/hdi_impl/gralloc_hdi_impl.cpp | 48 +++++--- gralloc/v1_0/hdi_impl/gralloc_hdi_impl.h | 18 +-- gralloc/v1_0/include/igralloc_interface.h | 133 +++++++++++++++++++-- 4 files changed, 185 insertions(+), 35 deletions(-) diff --git a/gralloc/v1_0/GrallocTypes.idl b/gralloc/v1_0/GrallocTypes.idl index a5a6df86..93dee646 100644 --- a/gralloc/v1_0/GrallocTypes.idl +++ b/gralloc/v1_0/GrallocTypes.idl @@ -53,10 +53,29 @@ enum PixelFormat { PIXEL_FMT_BUTT = 34, }; +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 ), +}; + struct AllocInfo { unsigned int width; unsigned int height; unsigned long usage; enum PixelFormat format; unsigned int expectedSize; -}; \ No newline at end of file +}; + +struct VerifyAllocInfo { + unsigned int width; + unsigned int height; + unsigned long usage; + enum PixelFormat format; +}; + diff --git a/gralloc/v1_0/hdi_impl/gralloc_hdi_impl.cpp b/gralloc/v1_0/hdi_impl/gralloc_hdi_impl.cpp index 1b804438..5e36f00d 100644 --- a/gralloc/v1_0/hdi_impl/gralloc_hdi_impl.cpp +++ b/gralloc/v1_0/hdi_impl/gralloc_hdi_impl.cpp @@ -14,19 +14,31 @@ */ #include "gralloc_hdi_impl.h" +#include "hdf_log.h" namespace OHOS { namespace HDI { namespace Gralloc { namespace V1_0 { +IGrallocInterface* IGrallocInterface::Get() +{ + static IGrallocInterface* instance = nullptr; + instance = new GrallocHdiImpl(); + if (instance == nullptr) { + HDF_LOGE("%{public}s: Can't new a DisplayGrallocClient instance", __func__); + return nullptr; + } + return instance; +} + GrallocHdiImpl::GrallocHdiImpl() { allocator_ = IAllocatorInterface::Get(); mapper_ = IMapperInterface::Get(true); } -int32_t GrallocHdiImpl::AllocMem(const AllocInfo& info, BufferHandle*& handle) +int32_t GrallocHdiImpl::AllocMem(const AllocInfo& info, BufferHandle*& handle) const { sptr hdiBuffer; int32_t ret = allocator_->AllocMem(info, hdiBuffer); @@ -38,69 +50,77 @@ int32_t GrallocHdiImpl::AllocMem(const AllocInfo& info, BufferHandle*& handle) return ret; } -void GrallocHdiImpl::FreeMem(const BufferHandle& handle) +void GrallocHdiImpl::FreeMem(const BufferHandle& handle) const { sptr hdiBuffer = new BufferHandleParcelable(const_cast(handle)); mapper_->FreeMem(hdiBuffer); } -void* GrallocHdiImpl::Mmap(const BufferHandle& handle) +void* GrallocHdiImpl::Mmap(const BufferHandle& handle) const { sptr hdiBuffer = new BufferHandleParcelable(const_cast(handle)); int32_t ret = mapper_->Mmap(hdiBuffer); - hdiBuffer->Move(); + (void)hdiBuffer->Move(); void *virAddr = (ret == HDF_SUCCESS ? handle.virAddr : nullptr); return virAddr; } -void* GrallocHdiImpl::MmapCache(const BufferHandle& handle) +void* GrallocHdiImpl::MmapCache(const BufferHandle& handle) const { sptr hdiBuffer = new BufferHandleParcelable(const_cast(handle)); int32_t ret = mapper_->MmapCache(hdiBuffer); - hdiBuffer->Move(); + (void)hdiBuffer->Move(); void *virAddr = (ret == HDF_SUCCESS ? handle.virAddr : nullptr); return virAddr; } -int32_t GrallocHdiImpl::Unmap(const BufferHandle& handle) +int32_t GrallocHdiImpl::Unmap(const BufferHandle& handle) const { sptr hdiBuffer = new BufferHandleParcelable(const_cast(handle)); int32_t ret = mapper_->Unmap(hdiBuffer); - hdiBuffer->Move(); + (void)hdiBuffer->Move(); return ret; } -int32_t GrallocHdiImpl::FlushCache(const BufferHandle& handle) +int32_t GrallocHdiImpl::FlushCache(const BufferHandle& handle) const { sptr hdiBuffer = new BufferHandleParcelable(const_cast(handle)); int32_t ret = mapper_->FlushCache(hdiBuffer); - hdiBuffer->Move(); + (void)hdiBuffer->Move(); return ret; } -int32_t GrallocHdiImpl::FlushMCache(const BufferHandle& handle) +int32_t GrallocHdiImpl::FlushMCache(const BufferHandle& handle) const { sptr hdiBuffer = new BufferHandleParcelable(const_cast(handle)); int32_t ret = mapper_->FlushMCache(hdiBuffer); - hdiBuffer->Move(); + (void)hdiBuffer->Move(); return ret; } -int32_t GrallocHdiImpl::InvalidateCache(const BufferHandle& handle) +int32_t GrallocHdiImpl::InvalidateCache(const BufferHandle& handle) const { sptr hdiBuffer = new BufferHandleParcelable(const_cast(handle)); int32_t ret = mapper_->InvalidateCache(hdiBuffer); - hdiBuffer->Move(); + (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 diff --git a/gralloc/v1_0/hdi_impl/gralloc_hdi_impl.h b/gralloc/v1_0/hdi_impl/gralloc_hdi_impl.h index 1508493e..2c0ba41c 100644 --- a/gralloc/v1_0/hdi_impl/gralloc_hdi_impl.h +++ b/gralloc/v1_0/hdi_impl/gralloc_hdi_impl.h @@ -32,14 +32,16 @@ public: GrallocHdiImpl(); virtual ~GrallocHdiImpl() = default; - virtual int32_t AllocMem(const AllocInfo& info, BufferHandle*& handle) override; - virtual void FreeMem(const BufferHandle& handle) override; - virtual void *Mmap(const BufferHandle& handle) override; - virtual void *MmapCache(const BufferHandle& handle) override; - virtual int32_t Unmap(const BufferHandle& handle) override; - virtual int32_t FlushCache(const BufferHandle& handle) override; - virtual int32_t FlushMCache(const BufferHandle& handle) override; - virtual int32_t InvalidateCache(const BufferHandle& handle) override; + 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_; diff --git a/gralloc/v1_0/include/igralloc_interface.h b/gralloc/v1_0/include/igralloc_interface.h index a2be24fd..972469ea 100644 --- a/gralloc/v1_0/include/igralloc_interface.h +++ b/gralloc/v1_0/include/igralloc_interface.h @@ -13,9 +13,10 @@ * limitations under the License. */ -#ifndef HDI_GRALLOC_INTERFACE_V1_0_H -#define HDI_GRALLOC_INTERFACE_V1_0_H +#ifndef HDI_IGRALLOC_INTERFACE_V1_0_H +#define HDI_IGRALLOC_INTERFACE_V1_0_H +#include #include "buffer_handle.h" #include "v1_0/gralloc_types.h" @@ -27,19 +28,127 @@ namespace V1_0 { class IGrallocInterface { public: virtual ~IGrallocInterface() = default; - virtual int32_t AllocMem(const AllocInfo& info, BufferHandle*& handle) = 0; - virtual void FreeMem(const BufferHandle& handle) = 0; - virtual void *Mmap(const BufferHandle& handle) = 0; - virtual void *MmapCache(const BufferHandle& buffer) = 0; - virtual int32_t Unmap(const BufferHandle& handle) = 0; - virtual int32_t FlushCache(const BufferHandle& handle) = 0; - virtual int32_t FlushMCache(const BufferHandle& buffer) = 0; - virtual int32_t InvalidateCache(const BufferHandle& handle) = 0; -}; + /** + * @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 + */ + static IGrallocInterface* Get(); + + /** + * @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_GRALLOC_INTERFACE_V1_0_H +#endif // HDI_IGRALLOC_INTERFACE_V1_0_H -- Gitee From 7cba4a0b214310543b32d2d62aa4ac14e08d68d8 Mon Sep 17 00:00:00 2001 From: liuxk Date: Fri, 15 Jul 2022 20:29:55 +0800 Subject: [PATCH 19/24] Replace gralloc interface --- display/include/idisplay_gralloc.h | 154 ------------------ display/v1_0/HdiDisplayDeviceType.idl | 13 -- .../display_command/display_cmd_responser.h | 9 +- gralloc/v1_0/GrallocTypes.idl | 53 +----- 4 files changed, 3 insertions(+), 226 deletions(-) delete mode 100644 display/include/idisplay_gralloc.h diff --git a/display/include/idisplay_gralloc.h b/display/include/idisplay_gralloc.h deleted file mode 100644 index 11fbacfd..00000000 --- a/display/include/idisplay_gralloc.h +++ /dev/null @@ -1,154 +0,0 @@ -/* - * 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 HDI_IDISPLAY_GRALLOC_V1_0_H -#define HDI_IDISPLAY_GRALLOC_V1_0_H - -#include -#include "v1_0/hdi_display_device_type.h" -#include "buffer_handle.h" - -namespace OHOS { -namespace HDI { -namespace Display { -namespace V1_0 { -class IDisplayGralloc { -public: - virtual ~IDisplayGralloc() = default; - - /** - * @brief Obtains all interfaces of IDisplayGralloc. - * - * @return Returns IDisplayGralloc* if the operation is successful; returns an null point otherwise. - * @since 1.0 - * @version 1.0 - */ - // static sptr Get(); - static IDisplayGralloc* Get(); - - /** - * @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 Display -} // namespace HDI -} // namespace OHOS - -#endif // HDI_IDISPLAY_GRALLOC_V1_0_H diff --git a/display/v1_0/HdiDisplayDeviceType.idl b/display/v1_0/HdiDisplayDeviceType.idl index d9775f7e..7e1893ca 100644 --- a/display/v1_0/HdiDisplayDeviceType.idl +++ b/display/v1_0/HdiDisplayDeviceType.idl @@ -408,13 +408,6 @@ struct DisplayModeInfo { unsigned int freshRate; int id; }; -struct AllocInfo { - unsigned int width; - unsigned int height; - unsigned long usage; - enum PixelFormat format; - unsigned int expectedSize; -}; struct HDRCapability { unsigned int formatCount; enum HDRFormat[] formats; @@ -426,12 +419,6 @@ struct HDRMetaData { enum HDRMetadataKey key; float value; }; -struct VerifyAllocInfo { - unsigned int width; - unsigned int height; - unsigned long usage; - enum PixelFormat format; -}; enum PresentTimestampType { HARDWARE_DISPLAY_PTS_UNSUPPORTED = 0, HARDWARE_DISPLAY_PTS_DELAY = 1 << 0, diff --git a/display/v1_0/display_command/display_cmd_responser.h b/display/v1_0/display_command/display_cmd_responser.h index c57bef9e..a6095678 100644 --- a/display/v1_0/display_command/display_cmd_responser.h +++ b/display/v1_0/display_command/display_cmd_responser.h @@ -26,7 +26,6 @@ #include "command_data_packer.h" #include "command_data_unpacker.h" #include "display_cmd_utils.h" -#include "idisplay_gralloc.h" #include "v1_0/include/idisplay_device_interface.h" #include "v1_0/hdi_display_device_type.h" @@ -53,13 +52,8 @@ public: isReplyUpdated_(false), reply_(nullptr), replyCommandCnt_(0), - replyPacker_(nullptr), - gralloc_(nullptr) + replyPacker_(nullptr) { - gralloc_.reset(IDisplayGralloc::Get()); - if (gralloc_.get() == nullptr) { - HDF_LOGE("error: DisplayCmdResponser construct failure"); - } } ~DisplayCmdResponser() @@ -671,7 +665,6 @@ private: uint32_t replyCommandCnt_; std::shared_ptr replyPacker_; std::unordered_map errMaps_; - std::unique_ptr gralloc_; }; using HdiDisplayCmdResponser = DisplayCmdResponser, IDisplayDeviceInterface>; diff --git a/gralloc/v1_0/GrallocTypes.idl b/gralloc/v1_0/GrallocTypes.idl index 93dee646..77b51401 100644 --- a/gralloc/v1_0/GrallocTypes.idl +++ b/gralloc/v1_0/GrallocTypes.idl @@ -15,60 +15,11 @@ package ohos.hdi.gralloc.v1_0; -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 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 ), -}; - struct AllocInfo { unsigned int width; unsigned int height; unsigned long usage; - enum PixelFormat format; + unsigned int format; unsigned int expectedSize; }; @@ -76,6 +27,6 @@ struct VerifyAllocInfo { unsigned int width; unsigned int height; unsigned long usage; - enum PixelFormat format; + unsigned int format; }; -- Gitee From c5693962da2d3e0d99d48ef3ddfec7b782a7f93d Mon Sep 17 00:00:00 2001 From: liuxk Date: Mon, 18 Jul 2022 13:53:11 +0800 Subject: [PATCH 20/24] Adjust build part name. --- display/buffersequence/BUILD.gn | 2 +- display/hdifdsequence/BUILD.gn | 2 +- display/v1_0/BUILD.gn | 2 +- gralloc/v1_0/BUILD.gn | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/display/buffersequence/BUILD.gn b/display/buffersequence/BUILD.gn index c76e3db2..fe9d0a06 100644 --- a/display/buffersequence/BUILD.gn +++ b/display/buffersequence/BUILD.gn @@ -48,5 +48,5 @@ ohos_shared_library("libbufferhandle_parcelable") { install_images = [ chipset_base_dir ] subsystem_name = "hdf" - part_name = "display_device_driver" + part_name = "drivers_interface_display" } diff --git a/display/hdifdsequence/BUILD.gn b/display/hdifdsequence/BUILD.gn index 29e70ca5..ae5ded62 100644 --- a/display/hdifdsequence/BUILD.gn +++ b/display/hdifdsequence/BUILD.gn @@ -49,5 +49,5 @@ ohos_shared_library("libhdifd_parcelable") { install_images = [ chipset_base_dir ] subsystem_name = "hdf" - part_name = "display_device_driver" + part_name = "drivers_interface_display" } diff --git a/display/v1_0/BUILD.gn b/display/v1_0/BUILD.gn index 49e4ef04..bd838efd 100644 --- a/display/v1_0/BUILD.gn +++ b/display/v1_0/BUILD.gn @@ -37,6 +37,6 @@ if (defined(ohos_lite)) { language = "cpp" subsystem_name = "hdf" - part_name = "display_device_driver" + part_name = "drivers_interface_display" } } diff --git a/gralloc/v1_0/BUILD.gn b/gralloc/v1_0/BUILD.gn index 2f0aaf9b..6c1f1d7a 100755 --- a/gralloc/v1_0/BUILD.gn +++ b/gralloc/v1_0/BUILD.gn @@ -33,7 +33,7 @@ if (defined(ohos_lite)) { language = "cpp" subsystem_name = "hdf" - part_name = "drivers_peripheral_gralloc" + part_name = "drivers_interface_gralloc" } } @@ -71,5 +71,5 @@ ohos_shared_library("libgralloc_hdi_impl") { install_images = [ chipset_base_dir ] subsystem_name = "hdf" - part_name = "display_device_driver" + part_name = "drivers_interface_gralloc" } -- Gitee From 8fddf3c080f140a49be1787e26f9c9190569e987 Mon Sep 17 00:00:00 2001 From: liuxk Date: Mon, 18 Jul 2022 16:16:14 +0800 Subject: [PATCH 21/24] Fix gralloc mt issues --- display/buffersequence/buffer_handle_parcelable.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/display/buffersequence/buffer_handle_parcelable.cpp b/display/buffersequence/buffer_handle_parcelable.cpp index d58d6a7a..5c836fca 100644 --- a/display/buffersequence/buffer_handle_parcelable.cpp +++ b/display/buffersequence/buffer_handle_parcelable.cpp @@ -150,6 +150,7 @@ bool BufferHandleParcelable::ExtractFromParcel(Parcel& parcel) HDF_LOGE("%{public}s parcel read failed", __func__); return false; } + handle_->virAddr = 0; if (validFd) { handle_->fd = ReadFileDescriptor(parcel); if (handle_->fd == -1) { -- Gitee From 0b2a33c73fb1a3f03c17b769e4902c9d0f86c6a1 Mon Sep 17 00:00:00 2001 From: liuxk Date: Thu, 21 Jul 2022 18:20:40 +0800 Subject: [PATCH 22/24] Change gralloc get interface --- gralloc/v1_0/BUILD.gn | 1 + gralloc/v1_0/hdi_impl/gralloc_hdi_impl.cpp | 22 +++++++++++----------- gralloc/v1_0/hdi_impl/gralloc_hdi_impl.h | 2 +- gralloc/v1_0/include/igralloc_interface.h | 11 ++++++++++- 4 files changed, 23 insertions(+), 13 deletions(-) diff --git a/gralloc/v1_0/BUILD.gn b/gralloc/v1_0/BUILD.gn index 6c1f1d7a..f1d07979 100755 --- a/gralloc/v1_0/BUILD.gn +++ b/gralloc/v1_0/BUILD.gn @@ -44,6 +44,7 @@ ohos_shared_library("libgralloc_hdi_impl") { ] include_dirs = [ + "../", "hdi_impl", "include", ] diff --git a/gralloc/v1_0/hdi_impl/gralloc_hdi_impl.cpp b/gralloc/v1_0/hdi_impl/gralloc_hdi_impl.cpp index 5e36f00d..cf41b6a3 100644 --- a/gralloc/v1_0/hdi_impl/gralloc_hdi_impl.cpp +++ b/gralloc/v1_0/hdi_impl/gralloc_hdi_impl.cpp @@ -21,17 +21,17 @@ namespace HDI { namespace Gralloc { namespace V1_0 { -IGrallocInterface* IGrallocInterface::Get() -{ - static IGrallocInterface* instance = nullptr; - instance = new GrallocHdiImpl(); - if (instance == nullptr) { - HDF_LOGE("%{public}s: Can't new a DisplayGrallocClient instance", __func__); - return nullptr; - } - return instance; -} - +//IGrallocInterface* IGrallocInterface::Get() +//{ +// static IGrallocInterface* instance = nullptr; +// instance = new GrallocHdiImpl(); +// if (instance == nullptr) { +// HDF_LOGE("%{public}s: Can't new a DisplayGrallocClient instance", __func__); +// return nullptr; +// } +// return instance; +//} +// GrallocHdiImpl::GrallocHdiImpl() { allocator_ = IAllocatorInterface::Get(); diff --git a/gralloc/v1_0/hdi_impl/gralloc_hdi_impl.h b/gralloc/v1_0/hdi_impl/gralloc_hdi_impl.h index 2c0ba41c..755c5101 100644 --- a/gralloc/v1_0/hdi_impl/gralloc_hdi_impl.h +++ b/gralloc/v1_0/hdi_impl/gralloc_hdi_impl.h @@ -18,7 +18,7 @@ #include "buffer_handle.h" #include "buffer_handle_parcelable.h" -#include "igralloc_interface.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" diff --git a/gralloc/v1_0/include/igralloc_interface.h b/gralloc/v1_0/include/igralloc_interface.h index 972469ea..fee13be1 100644 --- a/gralloc/v1_0/include/igralloc_interface.h +++ b/gralloc/v1_0/include/igralloc_interface.h @@ -36,7 +36,16 @@ public: * @since 1.0 * @version 1.0 */ - static IGrallocInterface* Get(); + template + static IGrallocInterface* Get() + { + static IGrallocInterface* instance = nullptr; + instance = new Impl(); + if (instance == nullptr) { + return nullptr; + } + return instance; + } /** * @brief Allocates memory based on the parameters passed by the GUI. -- Gitee From da89033f5f11b1c9a76c478883700dcb771e9572 Mon Sep 17 00:00:00 2001 From: liuxk Date: Thu, 21 Jul 2022 18:22:15 +0800 Subject: [PATCH 23/24] remove comments --- gralloc/v1_0/hdi_impl/gralloc_hdi_impl.cpp | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/gralloc/v1_0/hdi_impl/gralloc_hdi_impl.cpp b/gralloc/v1_0/hdi_impl/gralloc_hdi_impl.cpp index cf41b6a3..28b06308 100644 --- a/gralloc/v1_0/hdi_impl/gralloc_hdi_impl.cpp +++ b/gralloc/v1_0/hdi_impl/gralloc_hdi_impl.cpp @@ -21,17 +21,6 @@ namespace HDI { namespace Gralloc { namespace V1_0 { -//IGrallocInterface* IGrallocInterface::Get() -//{ -// static IGrallocInterface* instance = nullptr; -// instance = new GrallocHdiImpl(); -// if (instance == nullptr) { -// HDF_LOGE("%{public}s: Can't new a DisplayGrallocClient instance", __func__); -// return nullptr; -// } -// return instance; -//} -// GrallocHdiImpl::GrallocHdiImpl() { allocator_ = IAllocatorInterface::Get(); -- Gitee From 80cf0520df84888066aa5616cbb64f96e9738bf0 Mon Sep 17 00:00:00 2001 From: liuxk Date: Fri, 22 Jul 2022 10:41:05 +0800 Subject: [PATCH 24/24] clean up code --- gralloc/v1_0/hdi_impl/gralloc_hdi_impl.h | 1 - gralloc/v1_0/include/igralloc_interface.h | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/gralloc/v1_0/hdi_impl/gralloc_hdi_impl.h b/gralloc/v1_0/hdi_impl/gralloc_hdi_impl.h index 755c5101..1a66641b 100644 --- a/gralloc/v1_0/hdi_impl/gralloc_hdi_impl.h +++ b/gralloc/v1_0/hdi_impl/gralloc_hdi_impl.h @@ -17,7 +17,6 @@ #define GRALLOC_HDI_IMPL_V1_0_H #include "buffer_handle.h" -#include "buffer_handle_parcelable.h" #include "v1_0/include/igralloc_interface.h" #include "v1_0/iallocator_interface.h" #include "v1_0/imapper_interface.h" diff --git a/gralloc/v1_0/include/igralloc_interface.h b/gralloc/v1_0/include/igralloc_interface.h index fee13be1..9b28b457 100644 --- a/gralloc/v1_0/include/igralloc_interface.h +++ b/gralloc/v1_0/include/igralloc_interface.h @@ -39,8 +39,7 @@ public: template static IGrallocInterface* Get() { - static IGrallocInterface* instance = nullptr; - instance = new Impl(); + IGrallocInterface* instance = new Impl(); if (instance == nullptr) { return nullptr; } -- Gitee