diff --git a/display/BUILD.gn b/display/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..f7b4135af0e64d7857a6a9d05328a2f4189eff19 --- /dev/null +++ b/display/BUILD.gn @@ -0,0 +1,24 @@ +# Copyright (c) 2021 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/ohos.gni") +import("//vendor/${product_company}/${product_name}/product.gni") + +group("display_device_interface_entry") { + deps = [ + "v1_0:libdisplay_device_proxy_1.0", + "buffersequence:libbufferhandle_parcelable", + "hdifdsequence:libhdifd_parcelable", + ] +} + diff --git a/display/buffersequence/.buffer_handle_parcelable.cpp.swp b/display/buffersequence/.buffer_handle_parcelable.cpp.swp new file mode 100644 index 0000000000000000000000000000000000000000..225c22f217aa00c3627f3ea5b1177471f8cbc182 Binary files /dev/null and b/display/buffersequence/.buffer_handle_parcelable.cpp.swp differ diff --git a/display/buffersequence/BUILD.gn b/display/buffersequence/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..fe9d0a060e982a27b54a8700bfd77e959c1aab09 --- /dev/null +++ b/display/buffersequence/BUILD.gn @@ -0,0 +1,52 @@ +# Copyright (C) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/ohos.gni") +import("//drivers/hdf_core/adapter/uhdf2/uhdf.gni") + +config("bufferhandle_parcelable_config") { + include_dirs = [ + "//drivers/interface/display/buffersequence", + "//drivers/hdf_core/framework/include/utils", + "//drivers/hdf_core/adapter/uhdf2/osal/include", + "//drivers/peripheral/base", + ] +} + +ohos_shared_library("libbufferhandle_parcelable") { + + sources = [ "buffer_handle_parcelable.cpp" ] + + public_configs = [ ":bufferhandle_parcelable_config" ] + + cflags = [ + "-Wall", + "-Wextra", + "-Werror", + "-fsigned-char", + "-fno-common", + "-fno-strict-aliasing", + ] + + deps = [] + + external_deps = [ + "utils_base:utils", + "ipc:ipc_core", + "hiviewdfx_hilog_native:libhilog", + ] + + install_images = [ chipset_base_dir ] + subsystem_name = "hdf" + part_name = "drivers_interface_display" +} diff --git a/display/buffersequence/buffer_handle_parcelable.cpp b/display/buffersequence/buffer_handle_parcelable.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5c836fca6b7290a5468a1495b2d3957eeb2645d6 --- /dev/null +++ b/display/buffersequence/buffer_handle_parcelable.cpp @@ -0,0 +1,278 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "buffer_handle_parcelable.h" +#include +#include +#include + +#include "securec.h" +#include "hdf_log.h" +#include "ipc_file_descriptor.h" + +namespace OHOS { +namespace HDI { +namespace Display { + +BufferHandleParcelable::BufferHandleParcelable() + : init_(false), handle_(nullptr) +{ +} + +BufferHandleParcelable::BufferHandleParcelable(BufferHandle& handle) + : init_(true), handle_(&handle) +{ +} + +BufferHandleParcelable::~BufferHandleParcelable() +{ + if (init_ == false || handle_ == nullptr) { + return; + } + FreeBufferHandle(handle_); +} + +bool BufferHandleParcelable::Init(const BufferHandle& handle) +{ + if (init_ == true) { + HDF_LOGE("bufferhandle parcel have been initialized."); + return false; + } + + size_t handleSize = sizeof(BufferHandle) + (sizeof(int32_t) * + (handle.reserveFds + handle.reserveInts)); + handle_ = static_cast(malloc(handleSize)); + if (handle_ == nullptr) { + HDF_LOGE("InitBufferHandle malloc %zu failed", handleSize); + return false; + } + + if (memcpy_s(handle_, handleSize, &handle, handleSize) != EOK) { + HDF_LOGE("clone bufferhandle failed"); + return false; + } + + if (handle.fd == -1) { + handle_->fd = handle.fd; + } else { + handle_->fd = dup(handle.fd); + if (handle_->fd == -1) { + HDF_LOGE("bufferhandle dup fd failed"); + free(handle_); + return false; + } + } + + for (uint32_t i = 0; i < handle_->reserveFds; i++) { + handle_->reserve[i] = dup(handle.reserve[i]); + if (handle_->reserve[i] == -1) { + FreeBufferHandle(handle_); + HDF_LOGE("%{public}s ReadFileDescriptor reserve failed", __func__); + return false; + } + } + init_ = true; + + return true; +} + +bool BufferHandleParcelable::Marshalling(Parcel& parcel) const +{ + if (!parcel.WriteUint32(handle_->reserveFds) || !parcel.WriteUint32(handle_->reserveInts) || + !parcel.WriteInt32(handle_->width) || !parcel.WriteInt32(handle_->stride) || + !parcel.WriteInt32(handle_->height) || !parcel.WriteInt32(handle_->size) || + !parcel.WriteInt32(handle_->format) || !parcel.WriteInt64(handle_->usage) || + !parcel.WriteUint64(handle_->phyAddr) || !parcel.WriteInt32(handle_->key)) { + HDF_LOGE("%{public}s a lot failed", __func__); + return false; + } + bool validFd = (handle_->fd >= 0); + if (!parcel.WriteBool(validFd)) { + HDF_LOGE("%{public}s parcel.WriteBool failed", __func__); + return false; + } + if (validFd && !WriteFileDescriptor(handle_->fd, parcel)) { + HDF_LOGE("%{public}s parcel.WriteFileDescriptor fd failed", __func__); + return false; + } + + for (uint32_t i = 0; i < handle_->reserveFds; i++) { + if (!WriteFileDescriptor(handle_->reserve[i], parcel)) { + HDF_LOGE("%{public}s parcel.WriteFileDescriptor reserveFds failed", __func__); + return false; + } + } + for (uint32_t j = 0; j < handle_->reserveInts; j++) { + if (!parcel.WriteInt32(handle_->reserve[handle_->reserveFds + j])) { + HDF_LOGE("%{public}s parcel.WriteInt32 reserve failed", __func__); + return false; + } + } + return true; +} + +bool BufferHandleParcelable::ExtractFromParcel(Parcel& parcel) +{ + if (init_ == true) { + HDF_LOGE("bufferhandle parcel have been initialized."); + return false; + } + uint32_t reserveFds = 0; + uint32_t reserveInts = 0; + if (!parcel.ReadUint32(reserveFds) || !parcel.ReadUint32(reserveInts)) { + HDF_LOGE("%{public}s parcel.ReadUint32 reserveFds failed", __func__); + return false; + } + size_t handleSize = sizeof(BufferHandle) + (sizeof(int32_t) * (reserveFds + reserveInts)); + handle_ = static_cast(malloc(handleSize)); + if (handle_ == nullptr) { + HDF_LOGE("BufferHandle malloc %zu failed", handleSize); + return false; + } + handle_->reserveFds = reserveFds; + handle_->reserveInts = reserveInts; + bool validFd = false; + if (!parcel.ReadInt32(handle_->width) || !parcel.ReadInt32(handle_->stride) || !parcel.ReadInt32(handle_->height) || + !parcel.ReadInt32(handle_->size) || !parcel.ReadInt32(handle_->format) || !parcel.ReadUint64(handle_->usage) || + !parcel.ReadUint64(handle_->phyAddr) || !parcel.ReadInt32(handle_->key) || !parcel.ReadBool(validFd)) { + HDF_LOGE("%{public}s parcel read failed", __func__); + return false; + } + handle_->virAddr = 0; + if (validFd) { + handle_->fd = ReadFileDescriptor(parcel); + if (handle_->fd == -1) { + HDF_LOGE("%{public}s ReadFileDescriptor fd failed", __func__); + return false; + } + } + for (uint32_t i = 0; i < handle_->reserveFds; i++) { + handle_->reserve[i] = ReadFileDescriptor(parcel); + if (handle_->reserve[i] == -1) { + FreeBufferHandle(handle_); + HDF_LOGE("%{public}s ReadFileDescriptor reserve failed", __func__); + return false; + } + } + for (uint32_t j = 0; j < handle_->reserveInts; j++) { + if (!parcel.ReadInt32(handle_->reserve[reserveFds + j])) { + FreeBufferHandle(handle_); + HDF_LOGE("%{public}s ReadInt32 reserve failed", __func__); + return false; + } + } + return true; +} + +sptr BufferHandleParcelable::Unmarshalling(Parcel& parcel) +{ + sptr newParcelable = new BufferHandleParcelable(); + bool ret = newParcelable->ExtractFromParcel(parcel); + if (!ret) { + return nullptr; + } else { + newParcelable->init_ = true; + } + return newParcelable; +} + +BufferHandle* BufferHandleParcelable::GetBufferHandle() { + return handle_; +} + +BufferHandle* BufferHandleParcelable::Move() { + BufferHandle* handlePtr = handle_; + handle_ = nullptr; + init_ = false; + return handlePtr; +} + +bool BufferHandleParcelable::WriteFileDescriptor(const int fd, Parcel& parcel) +{ + if (fd < 0) { + return false; + } + int dupFd = dup(fd); + if (dupFd < 0) { + return false; + } + sptr descriptor = new (std::nothrow) IPCFileDescriptor(dupFd); + if (descriptor == nullptr) { + HDF_LOGE("create IPCFileDescriptor object failed"); + return false; + } + return parcel.WriteObject(descriptor); +} + +int BufferHandleParcelable::ReadFileDescriptor(Parcel& parcel) +{ + sptr descriptor = parcel.ReadObject(); + if (descriptor == nullptr) { + return -1; + } + int fd = descriptor->GetFd(); + if (fd < 0) { + return -1; + } + return dup(fd); +} + +void BufferHandleParcelable::FreeBufferHandle(BufferHandle* handle) +{ + if (handle->fd != -1) { + close(handle->fd); + } + for (uint32_t i = 0; i < handle->reserveFds; i++) { + if (handle->reserve[i] != -1) { + close(handle->reserve[i]); + } + } + free(handle); +} + +std::string BufferHandleParcelable::Dump() const +{ + std::stringstream os; + + os << "{"; + os << "fd:" << handle_->fd << ", "; + os << "width:" << handle_->width << ", "; + os << "stride:" << handle_->stride << ", "; + os << "height:" << handle_->height << ", "; + os << "size:" << handle_->size << ", "; + os << "format:" << handle_->format << ", "; + os << "usage:" << handle_->usage << ", "; + os << "phyAddr:" << handle_->phyAddr << ", "; + os << "key:" << handle_->key << ", "; + os << "}\nreserveFds[" << handle_->reserveFds << "]:{"; + + uint32_t i = 0; + for (; i < handle_->reserveFds; i++) { + os << handle_->reserve[i] << ", "; + } + os << "},\nreserveInts[" << handle_->reserveInts << "]:{"; + + uint32_t n = 0; + for (; n < handle_->reserveInts; n++) { + os << handle_->reserve[i + n] << ", "; + } + + os << "}\n"; + + return os.str(); +} +} // Display +} // HDI +} // OHOS diff --git a/display/buffersequence/buffer_handle_parcelable.h b/display/buffersequence/buffer_handle_parcelable.h new file mode 100644 index 0000000000000000000000000000000000000000..37d749e554c7fe2e7bf2d09c027f54f7ff7f5a27 --- /dev/null +++ b/display/buffersequence/buffer_handle_parcelable.h @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_HDI_BUFFER_HANDLE_PARCELABLE +#define OHOS_HDI_BUFFER_HANDLE_PARCELABLE + +#include +#include +#include +#include "buffer_handle.h" + +namespace OHOS { +namespace HDI { +namespace Display { + +using namespace OHOS; + +class BufferHandleParcelable: public Parcelable { +public: + BufferHandleParcelable(); + BufferHandleParcelable(BufferHandle& handle); + virtual ~BufferHandleParcelable(); + + bool Init(const BufferHandle& handle); + bool ExtractFromParcel(Parcel& parcel); + bool Marshalling(Parcel& parcel) const override; + static sptr Unmarshalling(Parcel& parcel); + BufferHandle* GetBufferHandle(); + BufferHandle* Move(); + std::string Dump() const; + +private: + static bool WriteFileDescriptor(const int fd, Parcel& parcel); + static int ReadFileDescriptor(Parcel& parcel); + static void FreeBufferHandle(BufferHandle* handle); + +private: + bool init_; + BufferHandle* handle_; +}; +} // Display +} // HDI +} // OHOS +#endif // OHOS_HDI_BUFFER_HANDLE_PARCELABLE diff --git a/display/bundle.json b/display/bundle.json old mode 100755 new mode 100644 index af5f7e9e383ef0f6915a21f152dc9fee6a525bf8..74f63a7a2ecdafd6a2df5da03695093ae200ab5c --- 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,24 +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/v1_0:display_device_client" + "//drivers/interface/display:display_device_interface_entry" + ], + "test": [ ], "inner_kits": [ { - "name": "//drivers/peripheral/display/hdi_service/gralloc/client:hdi_gralloc_client", + "name": "//drivers/interface/display/v1_0:libdisplay_device_proxy_1.0", "header": { - "header_files": [ - "idisplay_gralloc.h", - "parcel_utils.h" - ], - "header_base": "//drivers/peripheral/display/hdi_service/gralloc/include" + "header_files": [ + ], + "header_base": "//drivers/interface/display" } }, { diff --git a/display/command_pack/command_data_packer.h b/display/command_pack/command_data_packer.h new file mode 100644 index 0000000000000000000000000000000000000000..d08fe63429efafa1eab3c467e1772473c5e605af --- /dev/null +++ b/display/command_pack/command_data_packer.h @@ -0,0 +1,230 @@ +/* + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _DISPLAY_DATA_PACKER_H_ +#define _DISPLAY_DATA_PACKER_H_ + +#include +#include +#include "hdf_log.h" + +namespace OHOS { +namespace HDI { +namespace Display { + +class CommandDataPacker { +public: + CommandDataPacker() + : packSize_(0), + writePos_(0), + curSecOffset_(0), + settingSecLen_(0), + curSecLenPos_(0), + data_(nullptr) + { + } + + ~CommandDataPacker() + { + if (data_ != nullptr) { + delete data_; + } + } + + bool Init(size_t size = INIT_DATA_SIZE) + { + bool ret = true; + packSize_ = size; + uint32_t alignedSize = (packSize_ + ALLOC_PAGE_SIZE -1) & (~(ALLOC_PAGE_SIZE - 1)); + data_ = new char[alignedSize](); + if (data_ == nullptr) { + HDF_LOGE("memory alloc failed."); + ret = false; + } else { + packSize_ = alignedSize; + } + return ret; + } + + bool WriteUint64(uint64_t value) + { + return Write(value); + } + + bool WriteUint32(uint32_t value) + { + return Write(value); + } + + bool WriteUint8(uint8_t value) + { + return Write(value); + } + + bool WriteInt32(int32_t value) + { + return Write(value); + } + + bool WriteBool(bool value) + { + return Write(value); + } + + size_t ValidSize() + { + return writePos_; + } + + size_t PackSize() + { + return packSize_; + } + + char* GetDataPtr() + { + return data_; + } + + bool PackBegin(int32_t beginCmd) + { + writePos_ = 0; + settingSecLen_ = 4; + curSecLenPos_ = 0; + curSecOffset_ = writePos_; + return WriteInt32(beginCmd); + } + + bool BeginSection(int32_t cmdId, int32_t len = 0) + { + bool ret = false; + // len must be 4 byte alignment. + if ((len & 3) != 0) { + HDF_LOGE("error: length is not aligned by 4 bytes."); + } else { + ret = true; + } + // Update current data before next section. + if (ret == true) { + curSecOffset_ = writePos_; + if(WriteUint32(SECTION_END_MAGIC) == false) { + ret = false; + } else if (WriteInt32(cmdId) == true) { + curSecLenPos_ = writePos_; + settingSecLen_ = len; + // Now we don't write Section len here, + // but write it on EndSection. + writePos_ += sizeof(uint32_t); + } else { + ret = false; + } + } + return ret; + } + + bool EndSection() + { + // Write cmd len before data related is updated. + if (writePos_ >= curSecOffset_) { + uint32_t actualLen = writePos_ - curSecOffset_; + uint32_t updatedLen = actualLen > settingSecLen_ ? actualLen : settingSecLen_; + *reinterpret_cast(data_ + curSecLenPos_) = updatedLen; + writePos_ = curSecOffset_ + updatedLen; + } else { + HDF_LOGE("error: writePos_(%{public}d) before curSecOffset_(%{public}d).", + writePos_, curSecOffset_); + return false; + } + return (writePos_ >= packSize_ ? false : true); + } + + bool PackEnd(int32_t endCmd) + { + bool ret = WriteInt32(endCmd); + if (writePos_ >= packSize_) { + HDF_LOGE("error: writePos_(%{public}d) > packSize_(%{public}d), write overflow.", + writePos_, curSecOffset_); + ret = false; + } + + return ret; + } + + void Dump() + { + HDF_LOGI("---------------------------------------------\n"); + HDF_LOGI("ALLOC_PAGE_SIZE =%{public}d\n", ALLOC_PAGE_SIZE); + HDF_LOGI("INIT_DATA_SIZE =%{public}d\n", INIT_DATA_SIZE); + HDF_LOGI("SECTION_END_MAGIC =0x%{public}x\n", SECTION_END_MAGIC); + HDF_LOGI("packSize_ =%{public}d\n", packSize_); + HDF_LOGI("writePos_ =%{public}d\n", writePos_); + HDF_LOGI("curSecOffset_ =%{public}d\n", curSecOffset_); + HDF_LOGI("settingSecLen_ =%{public}d\n", settingSecLen_); + HDF_LOGI("curSecLenPos_ =%{public}d\n", curSecLenPos_); + HDF_LOGI("data_ =%{public}p\n", data_); + uint32_t i = 0; + for (; 4*i < writePos_;) { + HDF_LOGI("%{public}08x ", *reinterpret_cast(data_ + 4*i)); + i++; + if (i%8 == 0) { + HDF_LOGI("\n"); + } else if (i%4 == 0) { + HDF_LOGI(" "); + } else {} + } + HDF_LOGI("\n"); + } +private: + template + bool Write(T value) + { + size_t writeSize = sizeof(T); + + size_t newSize = writePos_ + writeSize; + if (newSize > packSize_) { + newSize = (newSize + ALLOC_PAGE_SIZE - 1) & (~(ALLOC_PAGE_SIZE - 1)); + + char* newData = new char[newSize]; + if (memcpy_s(newData, newSize, data_, packSize_) != EOK) { + HDF_LOGE("memcpy_s failed."); + return false; + } + data_ = newData; + packSize_ = newSize; + delete data_; + } + *reinterpret_cast(data_ + writePos_) = value; + writePos_ += writeSize; + + return true; + } + +private: + static constexpr uint32_t ALLOC_PAGE_SIZE = 1024; + static constexpr uint32_t INIT_DATA_SIZE = 32 * ALLOC_PAGE_SIZE; + static constexpr uint32_t SECTION_END_MAGIC = 0xB5B5B5B5; + +private: + size_t packSize_; + size_t writePos_; + size_t curSecOffset_; + uint32_t settingSecLen_; + size_t curSecLenPos_; + char* data_; +}; +} // Display +} // HDI +} // OHOS +#endif diff --git a/display/command_pack/command_data_unpacker.h b/display/command_pack/command_data_unpacker.h new file mode 100644 index 0000000000000000000000000000000000000000..c9938248fdc5d3f22b42ef123bd3aa24d444be4f --- /dev/null +++ b/display/command_pack/command_data_unpacker.h @@ -0,0 +1,187 @@ +/* + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _COMMAND_DATA_UNPACKER_H_ +#define _COMMAND_DATA_UNPACKER_H_ + +#include +#include "hdf_log.h" + +namespace OHOS { +namespace HDI { +namespace Display { + +class CommandDataUnpacker { +public: + CommandDataUnpacker() + : packSize_(0), + readPos_(0), + curSecOffset_(0), + curSecLen_(0), + data_(nullptr) + { + } + + void Init(char* unpackData, size_t size) + { + packSize_ = size; + data_ = unpackData; + return; + } + + bool ReadUint64(uint64_t& value) + { + return Read(value); + } + + bool ReadUint32(uint32_t& value) + { + return Read(value); + } + + bool ReadUint8(uint8_t& value) + { + int32_t intVal = 0; + bool ret = Read(intVal); + if (ret == true) { + value = static_cast(intVal & 0xFF); + } + + return ret; + } + + bool ReadInt32(int32_t& value) + { + return Read(value); + } + + bool ReadBool(bool& value) + { + int32_t intVal = 0; + bool ret = Read(intVal); + if (ret == true) { + value = (intVal == 0 ? false : true); + } + + return ret; + } + + char* GetDataPtr() + { + return data_; + } + + bool PackBegin(int32_t& beginCmd) + { + readPos_ = 0; + curSecLen_ = 4; + curSecOffset_ = readPos_; + + return ReadInt32(beginCmd); + } + + bool BeginSection(int32_t& cmdId) + { + uint32_t magic; + curSecOffset_ = readPos_; + + bool ret = ReadUint32(magic); + if (ret == true) { + ret = (magic == SECTION_END_MAGIC ? true : false); + } + if (ret == true && !(ReadInt32(cmdId) && ReadUint32(curSecLen_))) { + HDF_LOGE("error: cmdId=%{public}d or curSecLen_=%{public}d error.", + cmdId, curSecLen_); + ret = false; + } + return ret; + } + + bool NextSection() + { + readPos_ = curSecOffset_ + curSecLen_; + bool ret = ((readPos_ >= (packSize_ - COMMAND_ID_SIZE)) ? false : true); + return ret; + } + + bool PackEnd(int32_t& endCmd) + { + bool ret = ReadInt32(endCmd); + if ((ret == true) && (readPos_ == packSize_)) { + ret = true; + } else { + HDF_LOGE("error: readPos_(%{public}d) > packSize_(%{public}d), read overflow.", + readPos_, curSecOffset_); + ret = false; + } + return ret; + } + + void Dump() + { + HDF_LOGI("---------------------------------------------\n"); + HDF_LOGI("SECTION_END_MAGIC =0x%{public}x\n", SECTION_END_MAGIC); + HDF_LOGI("COMMAND_ID_SIZE =%{public}d\n", COMMAND_ID_SIZE); + HDF_LOGI("packSize_ =%{public}d\n", packSize_); + HDF_LOGI("readPos_ =%{public}d\n", readPos_); + HDF_LOGI("curSecOffset_ =%{public}d\n", curSecOffset_); + HDF_LOGI("curSecLen_ =%{public}d\n", curSecLen_); + HDF_LOGI("data_ =%{public}p\n", data_); + uint32_t i = 0; + for (; 4*i < packSize_;) { + HDF_LOGI("%{public}08x ", *reinterpret_cast(data_ + 4*i)); + i++; + if (i%8 == 0) { + HDF_LOGI("\n"); + } else if (i%4 == 0) { + HDF_LOGI(" "); + } else {} + } + HDF_LOGI("\n"); + } + +private: + template + bool Read(T& value) + { + size_t dataSize = sizeof(T); + + if (readPos_ + dataSize > packSize_) { + HDF_LOGE("Read overflow, readPos=%{public}d + %{public}d}, packSize=%{public}d.", + readPos_, dataSize, packSize_); + return false; + } + + value = *reinterpret_cast(data_ + readPos_); + readPos_ += dataSize; + + return true; + } + +private: + static constexpr uint32_t SECTION_END_MAGIC = 0xB5B5B5B5; + static constexpr uint32_t COMMAND_ID_SIZE = sizeof(int32_t); + +private: + size_t packSize_; + size_t readPos_; + size_t curSecOffset_; + uint32_t curSecLen_; + char* data_; +}; +} // Display +} // HDI +} // OHOS +#endif diff --git a/display/hdifdsequence/BUILD.gn b/display/hdifdsequence/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..ae5ded62197bba682b315c2399a2ae7ce7a35547 --- /dev/null +++ b/display/hdifdsequence/BUILD.gn @@ -0,0 +1,53 @@ +# Copyright (C) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/ohos.gni") +import("//drivers/hdf_core/adapter/uhdf2/uhdf.gni") + +config("hdifd_parcelable_config") { + include_dirs = [ + "//drivers/interface/display/hdifdsequence", + "//drivers/hdf_core/framework/include/utils", + "//drivers/hdf_core/adapter/uhdf2/osal/include", + "//drivers/peripheral/base", + ] +} + +ohos_shared_library("libhdifd_parcelable") { + + sources = [ "hdifd_parcelable.cpp" ] + + public_configs = [ ":hdifd_parcelable_config" ] + + cflags = [ + "-Wall", + "-Wextra", + "-Werror", + "-fsigned-char", + "-fno-common", + "-fno-strict-aliasing", + ] + + deps = [ + ] + + external_deps = [ + "utils_base:utils", + "ipc:ipc_core", + "hiviewdfx_hilog_native:libhilog", + ] + + install_images = [ chipset_base_dir ] + subsystem_name = "hdf" + part_name = "drivers_interface_display" +} diff --git a/display/hdifdsequence/hdifd_parcelable.cpp b/display/hdifdsequence/hdifd_parcelable.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f29a9f265c2e0b3331f0d2cf4e10f182867f18bb --- /dev/null +++ b/display/hdifdsequence/hdifd_parcelable.cpp @@ -0,0 +1,155 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "hdifd_parcelable.h" +#include +#include +#include + +#include "securec.h" +#include "hdf_log.h" +#include "ipc_file_descriptor.h" + +namespace OHOS { +namespace HDI { +namespace Display { + +HdifdParcelable::HdifdParcelable() + : init_(false), hdiFd_(-1) +{ +} + +HdifdParcelable::HdifdParcelable(int32_t fd) + : init_(true), hdiFd_(fd) +{ +} + +HdifdParcelable::~HdifdParcelable() +{ + if ((init_ != false) && (hdiFd_ != -1)) { + close(hdiFd_); + } +} + +bool HdifdParcelable::Init(int32_t fd) +{ + bool ret = true; + + if (init_ == true) { + HDF_LOGE("fd parcelable have been initialized."); + ret = false; + } else { + if (fd < 0) { + hdiFd_ = -1; + } else { + hdiFd_ = dup(fd); + ret = (hdiFd_ < 0) ? false : true; + } + if (ret == false) + { + return ret; + } + init_ = true; + } + + return ret; +} + +bool HdifdParcelable::WriteFileDescriptor(const int fd, Parcel& parcel) +{ + if (fd < 0) { + return false; + } + int dupFd = dup(fd); + if (dupFd < 0) { + return false; + } + + sptr descriptor = new (std::nothrow) IPCFileDescriptor(dupFd); + if (descriptor == nullptr) { + HDF_LOGE("create IPCFileDescriptor object failed"); + return false; + } + return parcel.WriteObject(descriptor); +} + +int HdifdParcelable::ReadFileDescriptor(Parcel& parcel) +{ + sptr descriptor = parcel.ReadObject(); + if (descriptor == nullptr) { + return -1; + } + int fd = descriptor->GetFd(); + if (fd < 0) { + return -1; + } + return dup(fd); +} + +bool HdifdParcelable::Marshalling(Parcel& parcel) const +{ + bool validFlag = (hdiFd_ >= 0); + if (!parcel.WriteBool(validFlag)) { + HDF_LOGE("%{public}s parcel.WriteBool failed", __func__); + return false; + } + if (validFlag && !WriteFileDescriptor(hdiFd_, parcel)) { + HDF_LOGE("%{public}s parcel.WriteFileDescriptor fd failed", __func__); + return false; + } + return true; +} + +sptr HdifdParcelable::Unmarshalling(Parcel& parcel) +{ + bool validFlag = false; + if (!parcel.ReadBool(validFlag)) { + HDF_LOGE("%{public}s ReadBool validFlag failed", __func__); + return nullptr; + } + int32_t fd = -1; + if (validFlag) { + fd = ReadFileDescriptor(parcel); + if (fd < 0) { + HDF_LOGE("%{public}s ReadFileDescriptor fd failed", __func__); + return nullptr; + } + } + sptr newParcelable = new HdifdParcelable(fd); + //newParcelable->Init(fd); + newParcelable->init_ = true; + return newParcelable; +} + +int32_t HdifdParcelable::GetFd() { + return hdiFd_; +} + +int32_t HdifdParcelable::Move() { + init_ = false; + return hdiFd_; +} + +std::string HdifdParcelable::Dump() const +{ + std::stringstream os; + + os << "fd: {" << hdiFd_ << "}\n"; + + return os.str(); +} +} // Display +} // HDI +} // OHOS diff --git a/display/hdifdsequence/hdifd_parcelable.h b/display/hdifdsequence/hdifd_parcelable.h new file mode 100644 index 0000000000000000000000000000000000000000..54ec2ba75ec925fc6e1969e07ce8d21e53b25de8 --- /dev/null +++ b/display/hdifdsequence/hdifd_parcelable.h @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_HDI_HDIFD_PARCELABLE +#define OHOS_HDI_HDIFD_PARCELABLE + +#include +#include +#include +#include "buffer_handle.h" + +namespace OHOS { +namespace HDI { +namespace Display { + +using namespace OHOS; + +class HdifdParcelable : public Parcelable { +public: + HdifdParcelable(); + HdifdParcelable(int32_t fd); + virtual ~HdifdParcelable(); + + bool Init(int32_t fd); + bool Marshalling(Parcel& parcel) const override; + static sptr Unmarshalling(Parcel& parcel); + int32_t Move(); + int32_t GetFd(); + std::string Dump() const; + +private: + static bool WriteFileDescriptor(const int fd, Parcel& parcel); + static int ReadFileDescriptor(Parcel& parcel); + +private: + bool init_; + int32_t hdiFd_; +}; +} // Display +} // HDI +} // OHOS +#endif // OHOS_HDI_HDIFD_PARCELABLE diff --git a/display/include/display_common.h b/display/include/display_common.h new file mode 100644 index 0000000000000000000000000000000000000000..a4af760f83e1680722773cc9fba3e7a6a411b6be --- /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 0000000000000000000000000000000000000000..446151ba2ec578a012d847b1149d25b84effc266 --- /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 0000000000000000000000000000000000000000..a3f402fa82b7a3e5e9f8a989b29657eb47e39173 --- /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 0000000000000000000000000000000000000000..b4a09b7781cdb9a740f8255b5583eb22128a0952 --- /dev/null +++ b/display/include/display_log.h @@ -0,0 +1,127 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef DISPLAY_LOG_H +#define DISPLAY_LOG_H +#include +#include +#include "hilog/log.h" +#include "stdio.h" +#ifdef HDF_LOG_TAG +#undef HDF_LOG_TAG +#endif + +#if defined(__cplusplus) +extern "C" { +#endif + +#undef LOG_TAG +#undef LOG_DOMAIN +#define LOG_TAG "DISP" +#define LOG_DOMAIN 0xD001400 + +#ifndef DISPLAY_UNUSED +#define DISPLAY_UNUSED(x) (void)x +#endif + +#define __FILENAME__ (strrchr(__FILE__, '/') ? (strrchr(__FILE__, '/') + 1) : __FILE__) + +#ifndef DISPLAY_DEBUG_ENABLE +#define DISPLAY_DEBUG_ENABLE 1 +#endif + +#ifndef DISPLAY_LOGD +#define DISPLAY_LOGD(format, ...) \ + do { \ + if (DISPLAY_DEBUG_ENABLE) { \ + HILOG_DEBUG(LOG_CORE, "[%{public}s@%{public}s:%{public}d] " format "\n", \ + __FUNCTION__, __FILENAME__, __LINE__, \ + ##__VA_ARGS__); \ + } \ + } while (0) +#endif + +#ifndef DISPLAY_LOGI +#define DISPLAY_LOGI(format, ...) \ + do { \ + HILOG_INFO(LOG_CORE, "[%{public}s@%{public}s:%{public}d] " format "\n", __FUNCTION__, __FILENAME__, __LINE__, \ + ##__VA_ARGS__); \ + } while (0) +#endif + +#ifndef DISPLAY_LOGW +#define DISPLAY_LOGW(format, ...) \ + do { \ + HILOG_WARN(LOG_CORE, "[%{public}s@%{public}s:%{public}d] " format "\n", __FUNCTION__, __FILENAME__, __LINE__, \ + ##__VA_ARGS__); \ + } while (0) +#endif + +#ifndef DISPLAY_LOGE +#define DISPLAY_LOGE(format, ...) \ + do { \ + HILOG_ERROR(LOG_CORE, \ + "\033[0;32;31m" \ + "[%{public}s@%{public}s:%{public}d] " format "\033[m" \ + "\n", \ + __FUNCTION__, __FILENAME__, __LINE__, ##__VA_ARGS__); \ + } while (0) +#endif + +#ifndef CHECK_NULLPOINTER_RETURN_VALUE +#define CHECK_NULLPOINTER_RETURN_VALUE(pointer, ret) \ + do { \ + if ((pointer) == NULL) { \ + DISPLAY_LOGE("pointer is null and return ret\n"); \ + return (ret); \ + } \ + } while (0) +#endif + +#ifndef CHECK_NULLPOINTER_RETURN +#define CHECK_NULLPOINTER_RETURN(pointer) \ + do { \ + if ((pointer) == NULL) { \ + DISPLAY_LOGE("pointer is null and return\n"); \ + return; \ + } \ + } while (0) +#endif + +#ifndef DISPLAY_CHK_RETURN +#define DISPLAY_CHK_RETURN(val, ret, ...) \ + do { \ + if (val) { \ + __VA_ARGS__; \ + return (ret); \ + } \ + } while (0) +#endif + +#ifndef DISPLAY_CHK_RETURN_NOT_VALUE +#define DISPLAY_CHK_RETURN_NOT_VALUE(val, ...) \ + do { \ + if (val) { \ + __VA_ARGS__; \ + return; \ + } \ + } while (0) +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* DISPLAY_LOG_H*/ diff --git a/display/v1_0/.HdiDisplayDeviceType.idl.swp b/display/v1_0/.HdiDisplayDeviceType.idl.swp new file mode 100644 index 0000000000000000000000000000000000000000..652ca7e2ac0dd4a20398fb6a6dac129d07c92d33 Binary files /dev/null and b/display/v1_0/.HdiDisplayDeviceType.idl.swp differ diff --git a/display/v1_0/BUILD.gn b/display/v1_0/BUILD.gn old mode 100755 new mode 100644 index 7ecda509160558345567499443f4cbce5207ab52..855aa2e168733587862645f700b1a748be723651 --- a/display/v1_0/BUILD.gn +++ b/display/v1_0/BUILD.gn @@ -11,61 +11,32 @@ # 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("display_device_client") { + group("libdisplay_proxy_1.0") { + deps = [] + public_configs = [] } } else { - import("//build/ohos.gni") - import("//build/ohos/native_stub/native_stub.gni") + hdi("display_device") { + module_name = "display_device" - # - # exported include directories - # - config("libdisplay_exported_config") { - visibility = [ ":*" ] - include_dirs = [ - "//drivers/peripheral/base", - "//drivers/peripheral/display/interfaces/include", + sources = [ + "IDisplayDevice.idl", + "HdiDisplayDeviceType.idl", + "IHotPlugCallback.idl", + "IVBlankCallback.idl", + "IRefreshCallback.idl", ] - } - - # - # stub library for libdisplay_gralloc - # - ohos_native_stub_library("libdisplay_gralloc") { - public_configs = [ ":libdisplay_exported_config" ] - stub_description_file = "./stub/libdisplay_gralloc.stub.json" - } - - # - # stub library for libdisplay_device - # - ohos_native_stub_library("libdisplay_device") { - public_configs = [ ":libdisplay_exported_config" ] - stub_description_file = "./stub/libdisplay_device.stub.json" - } - # - # stub library for libdisplay_gfx - # - ohos_native_stub_library("libdisplay_gfx") { - public_configs = [ ":libdisplay_exported_config" ] - stub_description_file = "./stub/libdisplay_gfx.stub.json" - } - - # - # stub library for libdisplay_layer - # - ohos_native_stub_library("libdisplay_layer") { - public_configs = [ ":libdisplay_exported_config" ] - stub_description_file = "./stub/libdisplay_layer.stub.json" - } - - group("display_device_client") { - deps = [ - ":libdisplay_device", - ":libdisplay_layer", + sequenceable = [ + "//drivers/interface/display/hdifdsequence:libhdifd_parcelable", + "//drivers/interface/display/buffersequence:libbufferhandle_parcelable", ] - public_configs = [ ":libdisplay_exported_config" ] + + language = "cpp" + subsystem_name = "hdf" + part_name = "drivers_interface_display" } } diff --git a/display/v1_0/HdiDisplayDeviceType.idl b/display/v1_0/HdiDisplayDeviceType.idl new file mode 100644 index 0000000000000000000000000000000000000000..7e1893ca0a604578a2747656cf9bfd2dc6235e8d --- /dev/null +++ b/display/v1_0/HdiDisplayDeviceType.idl @@ -0,0 +1,445 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ohos.hdi.display.v1_0; + +sequenceable OHOS.HDI.Display.BufferHandleParcelable; +sequenceable OHOS.HDI.Display.HdifdParcelable; + +enum DispCmd { + // request cmd + REQUEST_CMD_PREPAREDISPLAYLAYERS = 256, + REQUEST_CMD_SETDISPLAYCLIENTBUFFER = 257, + REQUEST_CMD_SETDISPLAYCLIENTDAMAGE = 258, + REQUEST_CMD_COMMIT = 259, + REQUEST_CMD_SETLAYERALPHA = 260, + REQUEST_CMD_SETLAYERSIZE = 261, + REQUEST_CMD_SETLAYERCROP = 262, + REQUEST_CMD_SETLAYERZORDER = 263, + REQUEST_CMD_SETLAYERPREMULTI = 264, + REQUEST_CMD_SETTRANSFORMMODE = 265, + REQUEST_CMD_SETLAYERDIRTYREGION = 266, + REQUEST_CMD_SETLAYERVISIBLEREGION = 267, + REQUEST_CMD_SETLAYERBUFFER = 268, + REQUEST_CMD_SETLAYERCOMPOSITIONTYPE = 269, + REQUEST_CMD_SETLAYERBLENDTYPE = 270, + REQUEST_CMD_SETLAYERVISIBLE = 271, + // reply cmd + REPLY_CMD_SETERROR = 1024, + REPLY_CMD_PREPAREDISPLAYLAYERS = 1025, + REPLY_CMD_COMMIT = 1026, + // Pack control cmd + CONTROL_CMD_REQUEST_BEGIN = 8192, + CONTROL_CMD_REPLY_BEGIN = 8193, + CONTROL_CMD_REQUEST_END = 8194, + CONTROL_CMD_REPLY_END = 8195, +}; + +enum InterfaceType { + DISP_INTF_HDMI = 0, // -1, + DISP_INTF_LCD = 1, + DISP_INTF_BT1120 = 2, + DISP_INTF_BT656 = 3, + DISP_INTF_YPBPR = 4, + DISP_INTF_RGB = 5, + DISP_INTF_CVBS = 6, + DISP_INTF_SVIDEO = 7, + DISP_INTF_VGA = 8, + DISP_INTF_MIPI = 9, + DISP_INTF_PANEL = 10, + DISP_INTF_BUTT = 11, +}; +enum DispErrCode { + DISPLAY_SUCCESS = 0, + DISPLAY_FAILURE = -1, + DISPLAY_FD_ERR = -2, + DISPLAY_PARAM_ERR = -3, + DISPLAY_NULL_PTR = -4, + DISPLAY_NOT_SUPPORT = -5, + DISPLAY_NOMEM = -6, + DISPLAY_SYS_BUSY = -7, + DISPLAY_NOT_PERM = -8, +}; +enum LayerType { + LAYER_TYPE_GRAPHIC = 0, + LAYER_TYPE_OVERLAY = 1, + LAYER_TYPE_SDIEBAND = 2, + LAYER_TYPE_CURSOR = 3, + LAYER_TYPE_BUTT = 4, +}; +enum LostName_0 { + HBM_USE_CPU_READ = ( 1 << 0 ), + HBM_USE_CPU_WRITE = ( 1 << 1 ), + HBM_USE_MEM_MMZ = ( 1 << 2 ), + HBM_USE_MEM_DMA = ( 1 << 3 ), + HBM_USE_MEM_SHARE = ( 1 << 4 ), + HBM_USE_MEM_MMZ_CACHE = ( 1 << 5 ), + HBM_USE_MEM_FB = ( 1 << 6 ), + HBM_USE_ASSIGN_SIZE = ( 1 << 7 ), +}; +enum PixelFormat { + PIXEL_FMT_CLUT8 = 0, + PIXEL_FMT_CLUT1 = 1, + PIXEL_FMT_CLUT4 = 2, + PIXEL_FMT_RGB_565 = 3, + PIXEL_FMT_RGBA_5658 = 4, + PIXEL_FMT_RGBX_4444 = 5, + PIXEL_FMT_RGBA_4444 = 6, + PIXEL_FMT_RGB_444 = 7, + PIXEL_FMT_RGBX_5551 = 8, + PIXEL_FMT_RGBA_5551 = 9, + PIXEL_FMT_RGB_555 = 10, + PIXEL_FMT_RGBX_8888 = 11, + PIXEL_FMT_RGBA_8888 = 12, + PIXEL_FMT_RGB_888 = 13, + PIXEL_FMT_BGR_565 = 14, + PIXEL_FMT_BGRX_4444 = 15, + PIXEL_FMT_BGRA_4444 = 16, + PIXEL_FMT_BGRX_5551 = 17, + PIXEL_FMT_BGRA_5551 = 18, + PIXEL_FMT_BGRX_8888 = 19, + PIXEL_FMT_BGRA_8888 = 20, + PIXEL_FMT_YUV_422_I = 21, + PIXEL_FMT_YCBCR_422_SP = 22, + PIXEL_FMT_YCRCB_422_SP = 23, + PIXEL_FMT_YCBCR_420_SP = 24, + PIXEL_FMT_YCRCB_420_SP = 25, + PIXEL_FMT_YCBCR_422_P = 26, + PIXEL_FMT_YCRCB_422_P = 27, + PIXEL_FMT_YCBCR_420_P = 28, + PIXEL_FMT_YCRCB_420_P = 29, + PIXEL_FMT_YUYV_422_PKG = 30, + PIXEL_FMT_UYVY_422_PKG = 31, + PIXEL_FMT_YVYU_422_PKG = 32, + PIXEL_FMT_VYUY_422_PKG = 33, + PIXEL_FMT_BUTT = 34, +}; +enum TransformType { + ROTATE_NONE = 0, + ROTATE_90 = 1, + ROTATE_180 = 2, + ROTATE_270 = 3, + ROTATE_BUTT = 4, +}; +enum BlendType { + BLEND_NONE = 0, + BLEND_CLEAR = 1, + BLEND_SRC = 2, + BLEND_SRCOVER = 3, + BLEND_DSTOVER = 4, + BLEND_SRCIN = 5, + BLEND_DSTIN = 6, + BLEND_SRCOUT = 7, + BLEND_DSTOUT = 8, + BLEND_SRCATOP = 9, + BLEND_DSTATOP = 10, + BLEND_ADD = 11, + BLEND_XOR = 12, + BLEND_DST = 13, + BLEND_AKS = 14, + BLEND_AKD = 15, + BLEND_BUTT = 16, +}; +enum RopType { + ROP_BLACK = 0, + ROP_NOTMERGEPEN = 1, + ROP_MASKNOTPEN = 2, + ROP_NOTCOPYPEN = 3, + ROP_MASKPENNOT = 4, + ROP_NOT = 5, + ROP_XORPEN = 6, + ROP_NOTMASKPEN = 7, + ROP_MASKPEN = 8, + ROP_NOTXORPEN = 9, + ROP_NOP = 10, + ROP_MERGENOTPEN = 11, + ROP_COPYPE = 12, + ROP_MERGEPENNOT = 13, + ROP_MERGEPEN = 14, + ROP_WHITE = 15, + ROP_BUTT = 16, +}; +enum ColorKey { + CKEY_NONE = 0, + CKEY_SRC = 1, + CKEY_DST = 2, + CKEY_BUTT = 3, +}; +enum MirrorType { + MIRROR_NONE = 0, + MIRROR_LR = 1, + MIRROR_TB = 2, + MIRROR_BUTT = 3, +}; +enum Connection { + CON_INVALID = 0, + CONNECTED = 1, + DISCONNECTED = 2, +}; +enum DispPowerStatus { + POWER_STATUS_ON = 0, + POWER_STATUS_STANDBY = 1, + POWER_STATUS_SUSPEND = 2, + POWER_STATUS_OFF = 3, + POWER_STATUS_BUTT = 4, +}; +enum CompositionType { + COMPOSITION_CLIENT = 0, + COMPOSITION_DEVICE = 1, + COMPOSITION_CURSOR = 2, + COMPOSITION_VIDEO = 3, + COMPOSITION_BUTT = 4, +}; +enum ColorGamut { + COLOR_GAMUT_INVALID = -1, + COLOR_GAMUT_NATIVE = 0, + COLOR_GAMUT_SATNDARD_BT601 = 1, + COLOR_GAMUT_STANDARD_BT709 = 2, + COLOR_GAMUT_DCI_P3 = 3, + COLOR_GAMUT_SRGB = 4, + COLOR_GAMUT_ADOBE_RGB = 5, + COLOR_GAMUT_DISPLAY_P3 = 6, + COLOR_GAMUT_BT2020 = 7, + COLOR_GAMUT_BT2100_PQ = 8, + COLOR_GAMUT_BT2100_HLG = 9, + COLOR_GAMUT_DISPLAY_BT2020 = 10, +}; +enum GamutMap { + GAMUT_MAP_CONSTANT = 0, + GAMUT_MAP_EXPANSION = 1, + GAMUT_MAP_HDR_CONSTANT = 2, + GAMUT_MAP_HDR_EXPANSION = 3, +}; +/* +enum ColorDataSpace { + COLOR_DATA_SPACE_UNKNOWN = 0, + GAMUT_BT601 = 1, + GAMUT_BT709 = 2, + GAMUT_DCI_P3 = 3, + GAMUT_SRGB = 4, + GAMUT_ADOBE_RGB = 5, + GAMUT_DISPLAY_P3 = 6, + GAMUT_BT2020 = 7, + GAMUT_BT2100_PQ = 8, + GAMUT_BT2100_HLG = 9, + GAMUT_DISPLAY_BT2020 = 10, + TRANSFORM_FUNC_UNSPECIFIED = 256, + TRANSFORM_FUNC_LINEAR = 512, + TRANSFORM_FUNC_SRGB = 768, + TRANSFORM_FUNC_SMPTE_170M = 1024, + TRANSFORM_FUNC_GM2_2 = 1280, + TRANSFORM_FUNC_GM2_6 = 1536, + TRANSFORM_FUNC_GM2_8 = 1792, + TRANSFORM_FUNC_ST2084 = 2048, + TRANSFORM_FUNC_HLG = 2304, + PRECISION_UNSPECIFIED = 65536, + PRECISION_FULL = 131072, + PRESION_LIMITED = 196608, + PRESION_EXTENDED = 262144, + BT601_SMPTE170M_FULL = GAMUT_BT601 | TRANSFORM_FUNC_SMPTE_170M | PRECISION_FULL, + BT601_SMPTE170M_LIMITED = GAMUT_BT601 | TRANSFORM_FUNC_SMPTE_170M | PRESION_LIMITED, + BT709_LINEAR_FULL = GAMUT_BT709 | TRANSFORM_FUNC_LINEAR | PRECISION_FULL, + BT709_LINEAR_EXTENDED = GAMUT_BT709 | TRANSFORM_FUNC_LINEAR | PRESION_EXTENDED, + BT709_SRGB_FULL = GAMUT_BT709 | TRANSFORM_FUNC_SRGB | PRECISION_FULL, + BT709_SRGB_EXTENDED = GAMUT_BT709 | TRANSFORM_FUNC_SRGB | PRESION_EXTENDED, + BT709_SMPTE170M_LIMITED = GAMUT_BT709 | TRANSFORM_FUNC_SMPTE_170M | PRESION_LIMITED, + DCI_P3_LINEAR_FULL = GAMUT_DCI_P3 | TRANSFORM_FUNC_LINEAR | PRECISION_FULL, + DCI_P3_GAMMA26_FULL = GAMUT_DCI_P3 | TRANSFORM_FUNC_GM2_6 | PRECISION_FULL, + DISPLAY_P3_LINEAR_FULL = GAMUT_DISPLAY_P3 | TRANSFORM_FUNC_LINEAR | PRECISION_FULL, + DCI_P3_SRGB_FULL = GAMUT_DCI_P3 | TRANSFORM_FUNC_SRGB | PRECISION_FULL, + ADOBE_RGB_GAMMA22_FULL = GAMUT_ADOBE_RGB | TRANSFORM_FUNC_GM2_2 | PRECISION_FULL, + BT2020_LINEAR_FULL = GAMUT_BT2020 | TRANSFORM_FUNC_LINEAR | PRECISION_FULL, + BT2020_SRGB_FULL = GAMUT_BT2020 | TRANSFORM_FUNC_SRGB | PRECISION_FULL, + BT2020_SMPTE170M_FULL = GAMUT_BT2020 | TRANSFORM_FUNC_SMPTE_170M | PRECISION_FULL, + BT2020_ST2084_FULL = GAMUT_BT2020 | TRANSFORM_FUNC_ST2084 | PRECISION_FULL, + BT2020_HLG_FULL = GAMUT_BT2020 | TRANSFORM_FUNC_HLG | PRECISION_FULL, + BT2020_ST2084_LIMITED = GAMUT_BT2020 | TRANSFORM_FUNC_ST2084 | PRESION_LIMITED, +}; +*/ +enum HDRFormat { + NOT_SUPPORT_HDR = 0, + DOLBY_VISION = 1, + HDR10 = 2, + HLG = 3, + HDR10_PLUS = 4, + HDR_VIVID = 5, +}; +enum HDRMetadataKey { + MATAKEY_RED_PRIMARY_X = 0, + MATAKEY_RED_PRIMARY_Y = 1, + MATAKEY_GREEN_PRIMARY_X = 2, + MATAKEY_GREEN_PRIMARY_Y = 3, + MATAKEY_BLUE_PRIMARY_X = 4, + MATAKEY_BLUE_PRIMARY_Y = 5, + MATAKEY_WHITE_PRIMARY_X = 6, + MATAKEY_WHITE_PRIMARY_Y = 7, + MATAKEY_MAX_LUMINANCE = 8, + MATAKEY_MIN_LUMINANCE = 9, + MATAKEY_MAX_CONTENT_LIGHT_LEVEL = 10, + MATAKEY_MAX_FRAME_AVERAGE_LIGHT_LEVEL = 11, + MATAKEY_HDR10_PLUS = 12, + MATAKEY_HDR_VIVID = 13, +}; + +struct HdiBufferHandleInfo { + unsigned int seqId; + BufferHandleParcelable hdl; +}; + +struct HdifdInfo { + int id; + HdifdParcelable hdiFd; +}; + +struct PropertyObject { + String name; + unsigned int propId; + unsigned long value; +}; +struct DisplayCapability { + String name; + enum InterfaceType type; + unsigned int phyWidth; + unsigned int phyHeight; + unsigned int supportLayers; + unsigned int virtualDispCount; + boolean supportWriteBack; + unsigned int propertyCount; + struct PropertyObject[] props; +}; +struct DisplayInfo { + unsigned int width; + unsigned int height; + int rotAngle; +}; +struct LayerInfo { + int width; + int height; + enum LayerType type; + int bpp; + enum PixelFormat pixFormat; +}; +struct LayerAlpha { + boolean enGlobalAlpha; + boolean enPixelAlpha; + unsigned char alpha0; + unsigned char alpha1; + unsigned char gAlpha; +}; +struct BufferData { + unsigned long phyAddr; + //void[] virAddr; +}; +struct LayerBuffer { + FileDescriptor fenceId; + int width; + int height; + int pitch; + enum PixelFormat pixFormat; + struct BufferData data; + BufferHandleParcelable hdl; +}; +struct IRect { + int x; + int y; + int w; + int h; +}; +struct ISurface { + unsigned long phyAddr; + int height; + int width; + int stride; + enum PixelFormat enColorFmt; + boolean bYCbCrClut; + boolean bAlphaMax255; + boolean bAlphaExt1555; + unsigned char alpha0; + unsigned char alpha1; + unsigned long cbcrPhyAddr; + int cbcrStride; + unsigned long clutPhyAddr; +}; +struct ILine { + int x0; + int y0; + int x1; + int y1; + unsigned int color; +}; +struct ICircle { + int x; + int y; + int r; + unsigned int color; +}; +struct Rectangle { + struct IRect rect; + unsigned int color; +}; +struct GfxOpt { + boolean enGlobalAlpha; + unsigned int globalAlpha; + boolean enPixelAlpha; + enum BlendType blendType; + enum ColorKey colorKeyFrom; + boolean enableRop; + enum RopType colorRopType; + enum RopType alphaRopType; + boolean enableScale; + enum TransformType rotateType; + enum MirrorType mirrorType; +}; +struct DisplayModeInfo { + int width; + int height; + unsigned int freshRate; + int id; +}; +struct HDRCapability { + unsigned int formatCount; + enum HDRFormat[] formats; + float maxLum; + float maxAverageLum; + float minLum; +}; +struct HDRMetaData { + enum HDRMetadataKey key; + float value; +}; +enum PresentTimestampType { + HARDWARE_DISPLAY_PTS_UNSUPPORTED = 0, + HARDWARE_DISPLAY_PTS_DELAY = 1 << 0, + HARDWARE_DISPLAY_PTS_TIMESTAMP = 1 << 1, +}; +struct PresentTimestamp { + enum PresentTimestampType type; + long time; +}; +struct ExtDataHandle { + int fd; + unsigned int reserveInts; + int[] reserve; +}; +struct YUVDescInfo { + unsigned long baseAddr; + unsigned int yOffset; + unsigned int uOffset; + unsigned int vOffset; + unsigned int yStride; + unsigned int uvStride; + unsigned int uvStep; +}; // __attribute__((__packed__)) YUVDescInfo; + diff --git a/display/v1_0/IDisplayDevice.idl b/display/v1_0/IDisplayDevice.idl new file mode 100644 index 0000000000000000000000000000000000000000..c8cc31c822f11d07b3e73181dbe31014096306ce --- /dev/null +++ b/display/v1_0/IDisplayDevice.idl @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ohos.hdi.display.v1_0; + +import ohos.hdi.display.v1_0.HdiDisplayDeviceType; +import ohos.hdi.display.v1_0.IHotPlugCallback; +import ohos.hdi.display.v1_0.IVBlankCallback; +import ohos.hdi.display.v1_0.IRefreshCallback; + +sequenceable OHOS.HDI.Display.HdifdParcelable; +sequenceable OHOS.HDI.Display.BufferHandleParcelable; + +interface IDisplayDevice { + RegHotPlugCallback([in] IHotPlugCallback cb); + GetDisplayCapability([in] unsigned int devId, [out] struct DisplayCapability info); + GetDisplaySupportedModes([in] unsigned int devId, [out] struct DisplayModeInfo[] modes); + GetDisplayMode([in] unsigned int devId, [out] unsigned int modeId); + SetDisplayMode([in] unsigned int devId, [in] unsigned int modeId); + GetDisplayPowerStatus([in] unsigned int devId, [out] enum DispPowerStatus status); + SetDisplayPowerStatus([in] unsigned int devId, [in] enum DispPowerStatus status); + GetDisplayBacklight([in] unsigned int devId, [out] unsigned int level); + SetDisplayBacklight([in] unsigned int devId, [in] unsigned int level); + GetDisplayProperty([in] unsigned int devId, [in] unsigned int id, [out] unsigned long value); + GetDisplayCompChange([in] unsigned int devId, [out] unsigned int[] layers, [out] int[] type); + SetDisplayClientCrop([in] unsigned int devId, [in] struct IRect rect); + SetDisplayClientDestRect([in] unsigned int devId, [in] struct IRect rect); + SetDisplayVsyncEnabled([in] unsigned int devId, [in] boolean enabled); + RegDisplayVBlankCallback([in] unsigned int devId, [in] IVBlankCallback cb); + GetDisplayReleaseFence([in] unsigned int devId, [out] unsigned int[] layers, + [out] HdifdParcelable[] fences); + CreateVirtualDisplay([in] unsigned int width, [in] unsigned int height, + [out] int format, [out] unsigned int devId); + DestroyVirtualDisplay([in] unsigned int devId); + SetVirtualDisplayBuffer([in] unsigned int devId, [in] BufferHandleParcelable buffer, + [in] HdifdParcelable fence); + SetDisplayProperty([in] unsigned int devId, [in] unsigned int id, [in] unsigned long value); + CreateLayer([in] unsigned int devId, [in] struct LayerInfo layerInfo, + [out] unsigned int layerId); + CloseLayer([in] unsigned int devId, [in] unsigned int layerId); + // func for smq transfer + InitCmdRequest([in] SharedMemQueue request); + CmdRequest([in] unsigned int inEleCnt, [in] struct HdifdInfo[] inFds, + [out] unsigned int outEleCnt, [out] struct HdifdInfo[] outFds); + GetCmdReply([out] SharedMemQueue reply); +} diff --git a/display/v1_0/IHotPlugCallback.idl b/display/v1_0/IHotPlugCallback.idl new file mode 100644 index 0000000000000000000000000000000000000000..ed306c52d795215b0f5461df3b0ba7d5a5c8b8e0 --- /dev/null +++ b/display/v1_0/IHotPlugCallback.idl @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ohos.hdi.display.v1_0; + +import ohos.hdi.display.v1_0.HdiDisplayDeviceType; + +[callback] interface IHotPlugCallback { + OnHotPlug([in] unsigned int outputId, [in] boolean connected); +} diff --git a/display/v1_0/IRefreshCallback.idl b/display/v1_0/IRefreshCallback.idl new file mode 100644 index 0000000000000000000000000000000000000000..410cc96603e5093fc30f45a96251355ac2f8125f --- /dev/null +++ b/display/v1_0/IRefreshCallback.idl @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ohos.hdi.display.v1_0; + +import ohos.hdi.display.v1_0.HdiDisplayDeviceType; + +[callback] interface IRefreshCallback { + OnRefresh([in] unsigned int devId); +} diff --git a/display/v1_0/IVBlankCallback.idl b/display/v1_0/IVBlankCallback.idl new file mode 100644 index 0000000000000000000000000000000000000000..bc7eafda4acc98638610e5ec164560fac818069f --- /dev/null +++ b/display/v1_0/IVBlankCallback.idl @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ohos.hdi.display.v1_0; + +import ohos.hdi.display.v1_0.HdiDisplayDeviceType; + +[callback] interface IVBlankCallback { + OnVBlank([in] unsigned int sequence, [in] unsigned long ns); +} diff --git a/display/v1_0/display_command/display_cmd_requester.h b/display/v1_0/display_command/display_cmd_requester.h new file mode 100644 index 0000000000000000000000000000000000000000..699c58e12f6570ae8e0e6d4d46adec1d5120a0fc --- /dev/null +++ b/display/v1_0/display_command/display_cmd_requester.h @@ -0,0 +1,610 @@ +/* + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_HDI_DISPLAY_V1_0_DISPLAYCMDREQUESTER_H +#define OHOS_HDI_DISPLAY_V1_0_DISPLAYCMDREQUESTER_H + +#include +#include "hdf_log.h" +#include "hdi_smq.h" +#include "buffer_handle_parcelable.h" +#include "hdifd_parcelable.h" +#include "command_data_packer.h" +#include "command_data_unpacker.h" +#include "display_cmd_utils.h" +#include "v1_0/idisplay_device.h" +#include "v1_0/hdi_display_device_type.h" + +namespace OHOS { +namespace HDI { +namespace Display { +namespace V1_0 { + +using namespace OHOS::HDI::Base; +using namespace OHOS::HDI::Display::V1_0; + +template +class DisplayCmdRequester { +public: + DisplayCmdRequester(sptr hdi) + : initFlag_(false), + hdi_(hdi), + request_(nullptr), + reply_(nullptr), + requestPacker_(nullptr) + { + } + + static std::unique_ptr Create(sptr hdi) + { + auto requester = std::make_unique(hdi); + auto ret = requester->Init(CmdUtils::INIT_ELEMENT_COUNT); + if (ret != HDF_SUCCESS) { + HDF_LOGE("DisplayCmdRequester init failed"); + return nullptr; + } + return requester; + } + + int32_t Init(uint32_t eleCnt) + { + int32_t ec = HDF_FAILURE; + request_ = std::make_shared(eleCnt, SmqType::SYNCED_SMQ); + if (request_ == nullptr) { + HDF_LOGE("nullptr failure."); + return HDF_FAILURE; + } else { + ec = hdi_->InitCmdRequest(request_); + if (ec != HDF_SUCCESS) { + HDF_LOGE("InitCmdRequest failure, ec=%{public}d", ec); + return HDF_FAILURE; + } + requestPacker_ = std::make_shared(); + if (requestPacker_ == nullptr || + requestPacker_->Init(request_->GetSize() * CmdUtils::ELEMENT_SIZE) == false) { + HDF_LOGE("requestPacker init failure."); + return HDF_FAILURE; + } + } + + ec = hdi_->GetCmdReply(reply_); + if (ec != HDF_SUCCESS) { + HDF_LOGE("GetCmdReply failure, ec=%{public}d", ec); + return ec; + } + initFlag_ = true; + return CmdUtils::StartPack(CONTROL_CMD_REQUEST_BEGIN, requestPacker_); + } + + int32_t PrepareDisplayLayers(uint32_t devId, bool& needFlushFb) + { + int32_t ec = CmdUtils::StartSection(REQUEST_CMD_PREPAREDISPLAYLAYERS, requestPacker_); + if (ec == HDF_SUCCESS) { + ec = requestPacker_->WriteUint32(devId) ? HDF_SUCCESS : HDF_FAILURE; + } + if (ec == HDF_SUCCESS) { + ec = CmdUtils::EndSection(requestPacker_); + } + if (ec == HDF_SUCCESS) { + ec = CmdUtils::EndPack(requestPacker_); + } + size_t replyEleCnt; + std::vector outFds; + std::shared_ptr replyData; + if (ec == HDF_SUCCESS) { + ec = DoRequest(replyEleCnt, outFds, replyData); + } + + if (ec == HDF_SUCCESS) { + ec = DoReplyResults(replyEleCnt, outFds, replyData, [&](void* data)->int32_t { + needFlushFb = *(reinterpret_cast(data)); + return HDF_SUCCESS; + }); + } + + if (ec != HDF_SUCCESS) { + HDF_LOGE("PrepareDisplayLayers failure, ec=%{public}d", ec); + } + return PeriodDataReset(); + } + + int32_t SetDisplayClientBuffer(uint32_t devId, const BufferHandle& buffer, int32_t fence) + { + int32_t ec = CmdUtils::StartSection(REQUEST_CMD_SETDISPLAYCLIENTBUFFER, requestPacker_); + if (ec == HDF_SUCCESS) { + ec = requestPacker_->WriteUint32(devId) ? HDF_SUCCESS : HDF_FAILURE; + } + if (ec == HDF_SUCCESS) { + ec = CmdUtils::BufferHandlePack(buffer, requestPacker_, requestHdiFds_); + } + if (ec == HDF_SUCCESS) { + ec = CmdUtils::FileDescriptorPack(fence, requestPacker_, requestHdiFds_); + } + if (ec == HDF_SUCCESS) { + ec = CmdUtils::EndSection(requestPacker_); + } else { + HDF_LOGE("error: %{public}d@%{public}s failed, ec=%{public}d", + __LINE__, __func__, ec); + } + return ec; + } + + int32_t SetDisplayClientDamage(uint32_t devId, std::vector& rects) + { + int32_t ec = CmdUtils::StartSection(REQUEST_CMD_SETDISPLAYCLIENTDAMAGE, requestPacker_); + if (ec == HDF_SUCCESS) { + ec = requestPacker_->WriteUint32(devId) ? HDF_SUCCESS : HDF_FAILURE; + } + size_t vectSize = rects.size(); + if (ec == HDF_SUCCESS) { + ec = requestPacker_->WriteUint32(vectSize) ? HDF_SUCCESS : HDF_FAILURE; + } + for (int32_t i = 0; i < vectSize; i++) { + if (ec == HDF_FAILURE) { + break; + } + ec = CmdUtils::RectPack(rects[i], requestPacker_); + } + if (ec == HDF_SUCCESS) { + ec = CmdUtils::EndSection(requestPacker_); + } else { + HDF_LOGE("error: %{public}d@%{public}s failed, ec=%{public}d", + __LINE__, __func__, ec); + } + return ec; + } + + int32_t Commit(uint32_t devId, int32_t& fence) + { + int32_t ec = CmdUtils::StartSection(REQUEST_CMD_COMMIT, requestPacker_); + if (ec == HDF_SUCCESS) { + ec = requestPacker_->WriteUint32(devId) ? HDF_SUCCESS : HDF_FAILURE; + } + if (ec == HDF_SUCCESS) { + ec = CmdUtils::EndSection(requestPacker_); + } + if (ec == HDF_SUCCESS) { + ec = CmdUtils::EndPack(requestPacker_); + } + size_t replyEleCnt = 0; + std::vector outFds; + std::shared_ptr replyData; + if (ec == HDF_SUCCESS) { + ec = DoRequest(replyEleCnt, outFds, replyData); + } + + if (ec == HDF_SUCCESS) { + ec = DoReplyResults(replyEleCnt, outFds, replyData, [&](void* data)->int32_t { + fence = *(reinterpret_cast(data)); + return HDF_SUCCESS; + }); + } + + if (ec != HDF_SUCCESS) { + HDF_LOGE("Commit failure, ec=%{public}d", ec); + } + + return PeriodDataReset(); + } + + int32_t SetLayerAlpha(uint32_t devId, uint32_t layerId, const LayerAlpha& alpha) + { + int32_t ec = CmdUtils::StartSection(REQUEST_CMD_SETLAYERALPHA, requestPacker_); + if (ec == HDF_SUCCESS) { + ec = CmdUtils::SetupDevice(devId, layerId, requestPacker_); + } + bool retVal = (ec == HDF_SUCCESS) ? true : false; + if (retVal) { + retVal = requestPacker_->WriteBool(alpha.enGlobalAlpha); + } + if (retVal) { + retVal = requestPacker_->WriteBool(alpha.enPixelAlpha); + } + if (retVal) { + retVal = requestPacker_->WriteUint8(alpha.alpha0); + } + if (retVal) { + retVal = requestPacker_->WriteUint8(alpha.alpha1); + } + if (retVal) { + retVal = requestPacker_->WriteUint8(alpha.gAlpha); + } + if (retVal) { + retVal = CmdUtils::EndSection(requestPacker_) == HDF_SUCCESS ? true : false; + } else { + HDF_LOGE("error: %{public}d@%{public}s failed, retVal=%{public}d", + __LINE__, __func__, retVal); + } + return retVal ? HDF_SUCCESS : HDF_FAILURE; + } + + int32_t SetLayerSize(uint32_t devId, uint32_t layerId, const IRect& rect) + { + int32_t ec = CmdUtils::StartSection(REQUEST_CMD_SETLAYERSIZE, requestPacker_); + if (ec == HDF_SUCCESS) { + ec = CmdUtils::SetupDevice(devId, layerId, requestPacker_); + } + if (ec == HDF_SUCCESS) { + ec = CmdUtils::RectPack(rect, requestPacker_); + } + if (ec == HDF_SUCCESS) { + ec = CmdUtils::EndSection(requestPacker_); + } else { + HDF_LOGE("error: %{public}d@%{public}s failed, retVal=%{public}d", + __LINE__, __func__, ec); + } + return ec; + } + + int32_t SetLayerCrop(uint32_t devId, uint32_t layerId, const IRect& rect) + { + int32_t ec = CmdUtils::StartSection(REQUEST_CMD_SETLAYERCROP, requestPacker_); + if (ec == HDF_SUCCESS) { + ec = CmdUtils::SetupDevice(devId, layerId, requestPacker_); + } + if (ec == HDF_SUCCESS) { + ec = CmdUtils::RectPack(rect, requestPacker_); + } + if (ec == HDF_SUCCESS) { + ec = CmdUtils::EndSection(requestPacker_); + } else { + HDF_LOGE("error: %{public}d@%{public}s failed, retVal=%{public}d", + __LINE__, __func__, ec); + } + return ec; + } + + int32_t SetLayerZorder(uint32_t devId, uint32_t layerId, uint32_t zorder) + { + int32_t ec = CmdUtils::StartSection(REQUEST_CMD_SETLAYERZORDER, requestPacker_); + if (ec == HDF_SUCCESS) { + ec = CmdUtils::SetupDevice(devId, layerId, requestPacker_); + } + if (ec == HDF_SUCCESS) { + ec = requestPacker_->WriteUint32(zorder) ? HDF_SUCCESS : HDF_FAILURE; + } + if (ec == HDF_SUCCESS) { + ec = CmdUtils::EndSection(requestPacker_); + } else { + HDF_LOGE("error: %{public}d@%{public}s failed, retVal=%{public}d", + __LINE__, __func__, ec); + } + return ec; + } + + int32_t SetLayerPreMulti(uint32_t devId, uint32_t layerId, bool preMul) + { + int32_t ec = CmdUtils::StartSection(REQUEST_CMD_SETLAYERPREMULTI, requestPacker_); + if (ec == HDF_SUCCESS) { + ec = CmdUtils::SetupDevice(devId, layerId, requestPacker_); + } + if (ec == HDF_SUCCESS) { + ec = requestPacker_->WriteBool(preMul) ? HDF_SUCCESS : HDF_FAILURE; + } + if (ec == HDF_SUCCESS) { + ec = CmdUtils::EndSection(requestPacker_); + } else { + HDF_LOGE("error: %{public}d@%{public}s failed, retVal=%{public}d", + __LINE__, __func__, ec); + } + return ec; + } + + int32_t SetTransformMode(uint32_t devId, uint32_t layerId, TransformType type) + { + int32_t ec = CmdUtils::StartSection(REQUEST_CMD_SETTRANSFORMMODE, requestPacker_); + if (ec == HDF_SUCCESS) { + ec = CmdUtils::SetupDevice(devId, layerId, requestPacker_); + } + if (ec == HDF_SUCCESS) { + ec = requestPacker_->WriteInt32(type) ? HDF_SUCCESS : HDF_FAILURE; + } + if (ec == HDF_SUCCESS) { + ec = CmdUtils::EndSection(requestPacker_); + } else { + HDF_LOGE("error: %{public}d@%{public}s failed, retVal=%{public}d", + __LINE__, __func__, ec); + } + return ec; + } + + int32_t SetLayerDirtyRegion(uint32_t devId, uint32_t layerId, const IRect& region) + { + int32_t ec = CmdUtils::StartSection(REQUEST_CMD_SETLAYERDIRTYREGION, requestPacker_); + if (ec == HDF_SUCCESS) { + ec = CmdUtils::SetupDevice(devId, layerId, requestPacker_); + } + if (ec == HDF_SUCCESS) { + ec = CmdUtils::RectPack(region, requestPacker_); + } + if (ec == HDF_SUCCESS) { + ec = CmdUtils::EndSection(requestPacker_); + } else { + HDF_LOGE("error: %{public}d@%{public}s failed, retVal=%{public}d", + __LINE__, __func__, ec); + } + return ec; + } + + int32_t SetLayerVisibleRegion(uint32_t devId, uint32_t layerId, std::vector& rects) + { + int32_t ec = CmdUtils::StartSection(REQUEST_CMD_SETLAYERVISIBLEREGION, requestPacker_); + if (ec == HDF_SUCCESS) { + ec = CmdUtils::SetupDevice(devId, layerId, requestPacker_); + } + size_t vSize = rects.size(); + if (ec == HDF_SUCCESS) { + ec = requestPacker_->WriteUint32(vSize) ? HDF_SUCCESS : HDF_FAILURE; + } + for (uint32_t i = 0; i < vSize; i++) { + if (ec == HDF_FAILURE) { + break; + } + ec = CmdUtils::RectPack(rects[i], requestPacker_); + } + if (ec == HDF_SUCCESS) { + ec = CmdUtils::EndSection(requestPacker_); + } else { + HDF_LOGE("error: %{public}d@%{public}s failed, retVal=%{public}d", + __LINE__, __func__, ec); + } + return ec; + } + + int32_t SetLayerBuffer(uint32_t devId, uint32_t layerId, BufferHandle buffer, int32_t fence) + { + int32_t ec = CmdUtils::StartSection(REQUEST_CMD_SETLAYERBUFFER, requestPacker_); + if (ec == HDF_SUCCESS) { + ec = CmdUtils::SetupDevice(devId, layerId, requestPacker_); + } + if (ec == HDF_SUCCESS) { + ec = CmdUtils::BufferHandlePack(buffer, requestPacker_, requestHdiFds_); + } + if (ec == HDF_SUCCESS) { + ec = CmdUtils::FileDescriptorPack(fence, requestPacker_, requestHdiFds_); + } + if (ec == HDF_SUCCESS) { + ec = CmdUtils::EndSection(requestPacker_); + } else { + HDF_LOGE("error: %{public}d@%{public}s failed, ec=%{public}d", + __LINE__, __func__, ec); + } + return ec; + } + + int32_t SetLayerCompositionType(uint32_t devId, uint32_t layerId, CompositionType type) + { + int32_t ec = CmdUtils::StartSection(REQUEST_CMD_SETLAYERCOMPOSITIONTYPE, requestPacker_); + if (ec == HDF_SUCCESS) { + ec = CmdUtils::SetupDevice(devId, layerId, requestPacker_); + } + if (ec == HDF_SUCCESS) { + ec = requestPacker_->WriteInt32(type) ? HDF_SUCCESS : HDF_FAILURE; + } + if (ec == HDF_SUCCESS) { + ec = CmdUtils::EndSection(requestPacker_); + } else { + HDF_LOGE("error: %{public}d@%{public}s failed, retVal=%{public}d", + __LINE__, __func__, ec); + } + return ec; + } + + int32_t SetLayerBlendType(uint32_t devId, uint32_t layerId, BlendType type) + { + int32_t ec = CmdUtils::StartSection(REQUEST_CMD_SETLAYERBLENDTYPE, requestPacker_); + if (ec == HDF_SUCCESS) { + ec = CmdUtils::SetupDevice(devId, layerId, requestPacker_); + } + if (ec == HDF_SUCCESS) { + ec = requestPacker_->WriteInt32(type) ? HDF_SUCCESS : HDF_FAILURE; + } + if (ec == HDF_SUCCESS) { + ec = CmdUtils::EndSection(requestPacker_); + } else { + HDF_LOGE("error: %{public}d@%{public}s failed, retVal=%{public}d", + __LINE__, __func__, ec); + } + return ec; + } + + int32_t SetLayerVisible(uint32_t devId, uint32_t layerId, bool visible) + { + int32_t ec = CmdUtils::StartSection(REQUEST_CMD_SETLAYERVISIBLE, requestPacker_); + if (ec == HDF_SUCCESS) { + ec = CmdUtils::SetupDevice(devId, layerId, requestPacker_); + } + if (ec == HDF_SUCCESS) { + ec = requestPacker_->WriteBool(visible) ? HDF_SUCCESS : HDF_FAILURE; + } + if (ec == HDF_SUCCESS) { + ec = CmdUtils::EndSection(requestPacker_); + } else { + HDF_LOGE("error: %{public}d@%{public}s failed, retVal=%{public}d", + __LINE__, __func__, ec); + } + return ec; + } + +private: + int32_t OnReplySetError(std::shared_ptr replyUnpacker, + std::unordered_map& errMaps) + { + int32_t ec = HDF_FAILURE; + uint32_t errCnt = 0; + auto retVal = replyUnpacker->ReadUint32(errCnt); + if (retVal) { + int32_t errCmd = -1; + int32_t errCode = -1; + for (; errCnt > 0; errCnt--) { + retVal = replyUnpacker->ReadInt32(errCmd); + if (retVal) { + retVal = replyUnpacker->ReadInt32(errCode); + } + HDF_LOGI("cmd:%{public}s, err:%{public}d", + CmdUtils::CommandToString(errCmd), errCode); + errMaps.emplace(errCmd, errCode); + } + ec = retVal ? HDF_SUCCESS : HDF_FAILURE; + } + + return ec; + } + + int32_t OnReplyPrepareDisplayLayers(std::shared_ptr replyUnpacker, + bool& needFlushFb) + { + return replyUnpacker->ReadBool(needFlushFb) ? HDF_SUCCESS : HDF_FAILURE; + } + + int32_t OnReplyCommit(std::shared_ptr replyUnpacker, + std::vector replyFds, int32_t& fenceFd) + { + return CmdUtils::FileDescriptorUnpack(replyUnpacker, replyFds, fenceFd); + } + + int32_t DoReplyResults(size_t replyEleCnt, std::vector replyFds, + std::shared_ptr replyData, std::function fn) + { + std::shared_ptr replyUnpacker = + std::make_shared(); + replyUnpacker->Init(replyData.get(), replyEleCnt * CmdUtils::ELEMENT_SIZE); + replyUnpacker->Dump(); // liuxk + int32_t unpackCmd = -1; + int32_t ec = HDF_SUCCESS; + if (!replyUnpacker->PackBegin(unpackCmd)) { + HDF_LOGE("error: PackBegin failed, unpackCmd=%{public}d.", unpackCmd); + ec = HDF_FAILURE; + } else { + if (unpackCmd != CONTROL_CMD_REPLY_BEGIN) { + HDF_LOGI("error: PackBegin cmd not match, unpackCmd=%{public}d.", unpackCmd); + ec = HDF_FAILURE; + } + } + while (ec == HDF_SUCCESS && replyUnpacker->NextSection()) { + if(!replyUnpacker->BeginSection(unpackCmd)) { + HDF_LOGE("error: PackSection failed, unpackCmd=%{public}d.", unpackCmd); + ec = HDF_FAILURE; + } + switch (unpackCmd) { + case REPLY_CMD_PREPAREDISPLAYLAYERS: + { + bool needFlushFb; + ec = OnReplyPrepareDisplayLayers(replyUnpacker, needFlushFb); + if (ec == HDF_SUCCESS) { + ec = fn(&needFlushFb); + } + if (ec != HDF_SUCCESS) { + HDF_LOGI("error: ReadBool failed, unpackCmd=%{public}s.", + CmdUtils::CommandToString(unpackCmd)); + } + } + break; + case REPLY_CMD_SETERROR: + if (ec == HDF_SUCCESS) { + std::unordered_map errMaps; + ec = OnReplySetError(replyUnpacker, errMaps); + if (ec == HDF_SUCCESS && errMaps.size() > 0) { + HDF_LOGI("error: server return errs, size=%{public}d", errMaps.size()); + ec = HDF_FAILURE; + } + } + break; + case REPLY_CMD_COMMIT: + { + int32_t fenceFd = -1; + ec = OnReplyCommit(replyUnpacker, replyFds, fenceFd); + if (ec == HDF_SUCCESS) { + ec = fn(&fenceFd); + } + if (ec != HDF_SUCCESS) { + HDF_LOGI("error: return fence fd error, unpackCmd=%{public}s.", + CmdUtils::CommandToString(unpackCmd)); + } + } + break; + default: + HDF_LOGE("Unpack command failure."); + ec = HDF_FAILURE; + break; + } + } + if (ec == HDF_SUCCESS ) { + ec = replyUnpacker->PackEnd(unpackCmd) ? HDF_SUCCESS : HDF_FAILURE; + } + if (unpackCmd != CONTROL_CMD_REPLY_END) { + HDF_LOGE("error: PackEnd failed, endCmd = %{public}s", + CmdUtils::CommandToString(unpackCmd)); + } + + return ec; + } + + int32_t DoRequest(size_t& replyEleCnt, std::vector& outFds, + std::shared_ptr& replyData) + { + requestPacker_->Dump(); // liuxk + int32_t eleCnt = requestPacker_->ValidSize() / CmdUtils::ELEMENT_SIZE; + int32_t ec = request_->Write(reinterpret_cast(requestPacker_->GetDataPtr()), + eleCnt, CmdUtils::TRANSFER_WAIT_TIME); + if (ec != HDF_SUCCESS) { + HDF_LOGE("CmdRequest write failure, ec=%{public}d", ec); + } else { + ec = hdi_->CmdRequest(eleCnt, requestHdiFds_, replyEleCnt, outFds); + if (ec != HDF_SUCCESS) { + HDF_LOGE("CmdRequest failure, ec=%{public}d", ec); + } else { + if (replyEleCnt != 0) { + replyData.reset(new char[replyEleCnt * CmdUtils::ELEMENT_SIZE], + std::default_delete()); + ec = reply_->Read(reinterpret_cast(replyData.get()), + replyEleCnt, CmdUtils::TRANSFER_WAIT_TIME); + if (ec != HDF_SUCCESS) { + HDF_LOGE("reply read data failure, ec=%{public}d", ec); + } + } + } + } + return ec; + } + + int32_t PeriodDataReset() + { + for (uint32_t i = 0; i < requestHdiFds_.size(); ++i) { + int32_t fd = requestHdiFds_[i].hdiFd->Move(); + if (fd != -1) { + close(fd); + } + } + requestHdiFds_.clear(); + return CmdUtils::StartPack(CONTROL_CMD_REQUEST_BEGIN, requestPacker_); + } + +private: + bool initFlag_; + sptr hdi_; + std::shared_ptr request_; + std::shared_ptr reply_; + // Period data + std::shared_ptr requestPacker_; + std::vector requestHdiFds_; +}; +using HdiDisplayCmdRequester = + DisplayCmdRequester, IDisplayDevice>; +} // V1_0 +} // Display +} // HDI +} // OHOS +#endif diff --git a/display/v1_0/display_command/display_cmd_responser.h b/display/v1_0/display_command/display_cmd_responser.h new file mode 100644 index 0000000000000000000000000000000000000000..a60956787b3682ebeccd62d79dea423d1f3c485b --- /dev/null +++ b/display/v1_0/display_command/display_cmd_responser.h @@ -0,0 +1,675 @@ +/* + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_HDI_DISPLAY_V1_0_DISPLAYCMDREQUESTER_H +#define OHOS_HDI_DISPLAY_V1_0_DISPLAYCMDREQUESTER_H + +#include +#include "hdf_base.h" +#include "hdf_log.h" +#include "hdi_smq.h" +#include "buffer_handle_utils.h" +#include "buffer_handle_parcelable.h" +#include "hdifd_parcelable.h" +#include "command_data_packer.h" +#include "command_data_unpacker.h" +#include "display_cmd_utils.h" +#include "v1_0/include/idisplay_device_interface.h" +#include "v1_0/hdi_display_device_type.h" + +namespace OHOS { +namespace HDI { +namespace Display { +namespace V1_0 { + +using namespace OHOS::HDI::Base; +using namespace OHOS::HDI::Display::V1_0; +using HdifdSet = std::vector>; + +template +class DisplayCmdResponser { +public: + static std::unique_ptr Create(std::shared_ptr impl) + { + return std::make_unique(impl); + } + + DisplayCmdResponser(std::shared_ptr halImpl) + : impl_(halImpl), + request_(nullptr), + isReplyUpdated_(false), + reply_(nullptr), + replyCommandCnt_(0), + replyPacker_(nullptr) + { + } + + ~DisplayCmdResponser() + { + } + + int32_t InitCmdRequest(const std::shared_ptr& request) + { + if (request_ != nullptr) { + request_.reset(); + } + request_ = request; + + return HDF_SUCCESS; + } + + int32_t GetCmdReply(std::shared_ptr& reply) + { + int32_t ec = HDF_SUCCESS; + if (isReplyUpdated_ == false) { + ec = InitReply(CmdUtils::INIT_ELEMENT_COUNT); + } + if (ec == HDF_SUCCESS) { + if (reply_ != nullptr) { + reply = reply_; + } else { + ec = HDF_FAILURE; + } + } + isReplyUpdated_ = false; + if (ec != HDF_SUCCESS) { + HDF_LOGE("error: GetCmdReply failure"); + } + return ec; + } + + int32_t CmdRequest(uint32_t inEleCnt, const std::vector& inFds, + uint32_t& outEleCnt, std::vector& outFds) + { + std::shared_ptr requestData(new char[inEleCnt * CmdUtils::ELEMENT_SIZE], + std::default_delete()); + int32_t ec = request_->Read(reinterpret_cast(requestData.get()), + inEleCnt, CmdUtils::TRANSFER_WAIT_TIME); + + std::shared_ptr unpacker = std::make_shared(); + if (ec == HDF_SUCCESS) { + unpacker->Init(requestData.get(), inEleCnt * CmdUtils::ELEMENT_SIZE); + unpacker->Dump(); // liuxk + } else { + ec = HDF_FAILURE; + } + int32_t unpackCmd = -1; + if (ec != HDF_SUCCESS || unpacker->PackBegin(unpackCmd) == false) { + HDF_LOGE("error: Check RequestBegin failed."); + ec = HDF_FAILURE; + } + if (unpackCmd != CONTROL_CMD_REQUEST_BEGIN) { + HDF_LOGI("error: unpacker PackBegin cmd not match, cmd(%{public}d)=%{public}s.", + unpackCmd, CmdUtils::CommandToString(unpackCmd)); + ec = HDF_FAILURE; + } + + while (ec == HDF_SUCCESS && unpacker->NextSection()) { + if(!unpacker->BeginSection(unpackCmd)) { + HDF_LOGE("error: PackSection failed, unpackCmd=%{public}s.", + CmdUtils::CommandToString(unpackCmd)); + ec = HDF_FAILURE; + } + HDF_LOGE("liuxk: PackSection, unpackCmd-[%{public}d]=%{public}s.", + unpackCmd, CmdUtils::CommandToString(unpackCmd)); + switch (unpackCmd) { + case REQUEST_CMD_PREPAREDISPLAYLAYERS: + OnPrepareDisplayLayers(unpacker); + break; + case REQUEST_CMD_SETDISPLAYCLIENTBUFFER: + OnSetDisplayClientBuffer(unpacker, inFds); + break; + case REQUEST_CMD_SETDISPLAYCLIENTDAMAGE: + OnSetDisplayClientDamage(unpacker); + break; + case REQUEST_CMD_COMMIT: + OnCommit(unpacker, outFds); + break; + case REQUEST_CMD_SETLAYERALPHA: + OnSetLayerAlpha(unpacker); + break; + case REQUEST_CMD_SETLAYERSIZE: + OnSetLayerSize(unpacker); + break; + case REQUEST_CMD_SETLAYERCROP: + OnSetLayerCrop(unpacker); + break; + case REQUEST_CMD_SETLAYERZORDER: + OnSetLayerZorder(unpacker); + break; + case REQUEST_CMD_SETLAYERPREMULTI: + OnSetLayerPreMulti(unpacker); + break; + case REQUEST_CMD_SETTRANSFORMMODE: + OnSetTransformMode(unpacker); + break; + case REQUEST_CMD_SETLAYERDIRTYREGION: + OnSetLayerDirtyRegion(unpacker); + break; + case REQUEST_CMD_SETLAYERVISIBLEREGION: + OnSetLayerVisibleRegion(unpacker); + break; + case REQUEST_CMD_SETLAYERBUFFER: { + OnSetLayerBuffer(unpacker, inFds); + break;} + case REQUEST_CMD_SETLAYERCOMPOSITIONTYPE: + OnSetLayerCompositionType(unpacker); + break; + case REQUEST_CMD_SETLAYERBLENDTYPE: + OnSetLayerBlendType(unpacker); + break; + case REQUEST_CMD_SETLAYERVISIBLE: + OnSetLayerVisible(unpacker); + break; + case CONTROL_CMD_REQUEST_END: + OnRequestEnd(unpacker); + break; + default: + HDF_LOGE("error: not support display command, unpacked Cmd=%{public}d.", + unpackCmd); + ec = HDF_FAILURE; + break; + } + } + // pack request end commands + replyPacker_->PackEnd(CONTROL_CMD_REPLY_END); + HDF_LOGE("CmdReply command cnt=%{public}d", replyCommandCnt_); + // Write reply pack + replyPacker_->Dump(); // liuxk + outEleCnt = replyPacker_->ValidSize() / CmdUtils::ELEMENT_SIZE; + ec = reply_->Write(reinterpret_cast(replyPacker_->GetDataPtr()), + outEleCnt, CmdUtils::TRANSFER_WAIT_TIME); + if (ec != HDF_SUCCESS) { + HDF_LOGE("Reply write failure, ec=%{public}d", ec); + outEleCnt = 0; + } + int32_t ec2 = PeriodDataReset(); + + return (ec == HDF_SUCCESS ? ec2 : ec); + } + +private: + int32_t InitReply(uint32_t size) + { + reply_ = std::make_shared(size, SmqType::SYNCED_SMQ); + if (reply_ == nullptr) { + HDF_LOGE("nullptr error."); + return HDF_FAILURE; + } + replyPacker_ = std::make_shared(); + if (replyPacker_ == nullptr || + replyPacker_->Init(reply_->GetSize() * CmdUtils::ELEMENT_SIZE) == false) { + HDF_LOGE("replyPacker init failure."); + return HDF_FAILURE; + } + return CmdUtils::StartPack(CONTROL_CMD_REPLY_BEGIN, replyPacker_); + } + + void OnRequestEnd(std::shared_ptr unpacker) + { + // pack reply error commands + size_t errCnt = errMaps_.size(); + if (errCnt >= 0) { + int32_t ec = CmdUtils::StartSection(REPLY_CMD_SETERROR, replyPacker_); + bool retVal = (ec == HDF_SUCCESS) ? true : false; + if (retVal) { + retVal = replyPacker_->WriteUint32(errCnt); + } + for (auto it = errMaps_.begin(); it != errMaps_.end(); ++it) { + if (retVal) { + break; + } + if (retVal) { + retVal = replyPacker_->WriteInt32(it->first); + } + if (retVal) { + retVal = replyPacker_->WriteInt32(it->second); + } + HDF_LOGE("Call display cmd failed, Id:%{public}s, ec=%{public}d", + CmdUtils::CommandToString(it->first), it->second); + } + if (retVal) { + CmdUtils::EndSection(replyPacker_); + } else { + HDF_LOGE("OnRequestEnd failed"); + } + replyCommandCnt_++; + } + + return; + } + + void OnPrepareDisplayLayers(std::shared_ptr unpacker) + { + uint32_t devId = -1; + int32_t ec = unpacker->ReadUint32(devId) ? HDF_SUCCESS : HDF_FAILURE; + + bool needFlush = false; + if (ec == HDF_SUCCESS) { + ec = impl_->PrepareDisplayLayers(devId, needFlush); + } + // reply pack + if (ec == HDF_SUCCESS) { + ec = CmdUtils::StartSection(REPLY_CMD_PREPAREDISPLAYLAYERS, replyPacker_); + } + if (ec == HDF_SUCCESS) { + ec = replyPacker_->WriteBool(needFlush) ? HDF_SUCCESS : HDF_FAILURE; + } + if (ec == HDF_SUCCESS) { + ec = CmdUtils::EndSection(replyPacker_); + replyCommandCnt_++; + } + if (ec != HDF_SUCCESS) { + errMaps_.emplace(REQUEST_CMD_PREPAREDISPLAYLAYERS, ec); + } + + return; + } + + void OnSetDisplayClientBuffer(std::shared_ptr unpacker, + const std::vector& inFds) + { + uint32_t devId; + int32_t ec = unpacker->ReadUint32(devId) ? HDF_SUCCESS : HDF_FAILURE; + + BufferHandle* buffer = nullptr; + if (ec == HDF_SUCCESS) { + ec = CmdUtils::BufferHandleUnpack(unpacker, inFds, buffer); + } + + int32_t fence = -1; + if (ec == HDF_SUCCESS) { + ec = CmdUtils::FileDescriptorUnpack(unpacker, inFds, fence); + } + HdifdParcelable fdParcel(fence); + + if (ec == HDF_SUCCESS) { + ec = impl_->SetDisplayClientBuffer(devId, *buffer, fdParcel.GetFd()); + } + FreeBufferHandle(buffer); + if (ec != HDF_SUCCESS) { + errMaps_.emplace(REQUEST_CMD_SETDISPLAYCLIENTBUFFER, ec); + } + return; + } + + void OnSetDisplayClientDamage(std::shared_ptr unpacker) + { + uint32_t devId = -1; + int32_t ec = unpacker->ReadUint32(devId) ? HDF_SUCCESS : HDF_FAILURE; + + size_t vectSize = 0; + if (ec == HDF_SUCCESS) { + ec = unpacker->ReadUint32(vectSize) ? HDF_SUCCESS : HDF_FAILURE; + } + + std::vector rects; + rects.reserve(vectSize); + for (int32_t i = 0; i < vectSize; i++) { + if (ec == HDF_FAILURE) { + break; + } + ec = CmdUtils::RectUnpack(unpacker, rects[i]); + } + if (ec == HDF_SUCCESS) { + ec = impl_->SetDisplayClientDamage(devId, rects); + } + if (ec != HDF_SUCCESS) { + errMaps_.emplace(REQUEST_CMD_SETDISPLAYCLIENTDAMAGE, ec); + } + return; + } + + void OnCommit(std::shared_ptr unpacker, std::vector& outFds) + { + uint32_t devId = -1; + int32_t ec = unpacker->ReadUint32(devId) ? HDF_SUCCESS : HDF_FAILURE; + + // do request + int32_t fence = -1; + if (ec == HDF_SUCCESS) { + ec = impl_->Commit(devId, fence); + } + HdifdParcelable fdParcel(fence); + // reply pack + if (ec == HDF_SUCCESS) { + ec = CmdUtils::StartSection(REPLY_CMD_COMMIT, replyPacker_); + } + if (ec == HDF_SUCCESS) { + ec = CmdUtils::FileDescriptorPack(fdParcel.GetFd(), replyPacker_, outFds); + } + if (ec == HDF_SUCCESS) { + ec = CmdUtils::EndSection(replyPacker_); + replyCommandCnt_++; + } + // push err maps if exist + if (ec != HDF_SUCCESS) { + errMaps_.emplace(REQUEST_CMD_COMMIT, ec); + } + + return; + } + + void OnSetLayerAlpha(std::shared_ptr unpacker) + { + // unpack + uint32_t devId = -1; + uint32_t layerId = -1; + int32_t ec = CmdUtils::SetupDeviceUnpack(unpacker, devId, layerId); + LayerAlpha alpha; + bool retVal = (ec == HDF_SUCCESS) ? true : false; + if (retVal) { + retVal = unpacker->ReadBool(alpha.enGlobalAlpha); + } + if (retVal) { + retVal = unpacker->ReadBool(alpha.enPixelAlpha); + } + if (retVal) { + retVal = unpacker->ReadUint8(alpha.alpha0); + } + if (retVal) { + retVal = unpacker->ReadUint8(alpha.alpha1); + } + if (retVal) { + retVal = unpacker->ReadUint8(alpha.gAlpha); + } + // do request + if (retVal) { + ec = impl_->SetLayerAlpha(devId, layerId, alpha); + } else { + ec = retVal ? HDF_SUCCESS : HDF_FAILURE; + } + // push err maps if exist + if (ec != HDF_SUCCESS) { + errMaps_.emplace(REQUEST_CMD_SETLAYERALPHA, ec); + } + return; + } + + void OnSetLayerSize(std::shared_ptr unpacker) + { + // unpack + uint32_t devId = -1; + uint32_t layerId = -1; + int32_t ec = CmdUtils::SetupDeviceUnpack(unpacker, devId, layerId); + IRect rect; + if (ec == HDF_SUCCESS) { + ec = CmdUtils::RectUnpack(unpacker, rect); + } + // do request + if (ec == HDF_SUCCESS) { + ec = impl_->SetLayerSize(devId, layerId, rect); + } + // push err maps if exist + if (ec != HDF_SUCCESS) { + errMaps_.emplace(REQUEST_CMD_SETLAYERSIZE, ec); + } + + return; + } + + void OnSetLayerCrop(std::shared_ptr unpacker) + { + // unpack + uint32_t devId = -1; + uint32_t layerId = -1; + int32_t ec = CmdUtils::SetupDeviceUnpack(unpacker, devId, layerId); + IRect rect; + if (ec == HDF_SUCCESS) { + ec = CmdUtils::RectUnpack(unpacker, rect); + } + // do request + if (ec == HDF_SUCCESS) { + ec = impl_->SetLayerCrop(devId, layerId, rect); + } + // push err maps if exist + if (ec != HDF_SUCCESS) { + errMaps_.emplace(REQUEST_CMD_SETLAYERCROP, ec); + } + return; + } + + void OnSetLayerZorder(std::shared_ptr unpacker) + { + // unpack + uint32_t devId = -1; + uint32_t layerId = -1; + int32_t ec = CmdUtils::SetupDeviceUnpack(unpacker, devId, layerId); + uint32_t zorder; + if (ec == HDF_SUCCESS) { + ec = unpacker->ReadUint32(zorder) ? HDF_SUCCESS : HDF_FAILURE; + } + // do request + if (ec == HDF_SUCCESS) { + ec = impl_->SetLayerZorder(devId, layerId, zorder); + } + // push err maps if exist + if (ec != HDF_SUCCESS) { + errMaps_.emplace(REQUEST_CMD_SETLAYERZORDER, ec); + } + return; + } + + void OnSetLayerPreMulti(std::shared_ptr unpacker) + { + // unpack + uint32_t devId = -1; + uint32_t layerId = -1; + int32_t ec = CmdUtils::SetupDeviceUnpack(unpacker, devId, layerId); + bool preMulti; + if (ec == HDF_SUCCESS) { + ec = unpacker->ReadBool(preMulti) ? HDF_SUCCESS : HDF_FAILURE; + } + // do request + if (ec == HDF_SUCCESS) { + ec = impl_->SetLayerPreMulti(devId, layerId, preMulti); + } + // push err maps if exist + if (ec != HDF_SUCCESS) { + errMaps_.emplace(REQUEST_CMD_SETLAYERPREMULTI, ec); + } + return; + } + + void OnSetTransformMode(std::shared_ptr unpacker) + { + // unpack + uint32_t devId = -1; + uint32_t layerId = -1; + int32_t ec = CmdUtils::SetupDeviceUnpack(unpacker, devId, layerId); + int32_t type; + if (ec == HDF_SUCCESS) { + ec = unpacker->ReadInt32(type) ? HDF_SUCCESS : HDF_FAILURE; + } + // do request + if (ec == HDF_SUCCESS) { + ec = impl_->SetTransformMode(devId, layerId, static_cast(type)); + } + // push err maps if exist + if (ec != HDF_SUCCESS) { + errMaps_.emplace(REQUEST_CMD_SETTRANSFORMMODE, ec); + } + return; + } + + void OnSetLayerDirtyRegion(std::shared_ptr unpacker) + { + // unpack + uint32_t devId = -1; + uint32_t layerId = -1; + int32_t ec = CmdUtils::SetupDeviceUnpack(unpacker, devId, layerId); + IRect rect; + if (ec == HDF_SUCCESS) { + ec = CmdUtils::RectUnpack(unpacker, rect); + } + // do request + if (ec == HDF_SUCCESS) { + ec = impl_->SetLayerDirtyRegion(devId, layerId, rect); + } + // push err maps if exist + if (ec != HDF_SUCCESS) { + errMaps_.emplace(REQUEST_CMD_SETLAYERDIRTYREGION, ec); + } + return; + } + + void OnSetLayerVisibleRegion(std::shared_ptr unpacker) + { + // unpack + uint32_t devId = -1; + uint32_t layerId = -1; + int32_t ec = CmdUtils::SetupDeviceUnpack(unpacker, devId, layerId); + + size_t vectSize = 0; + if (ec == HDF_SUCCESS) { + ec = unpacker->ReadUint32(vectSize) ? HDF_SUCCESS : HDF_FAILURE; + } + std::vector rects; + for (int32_t i = 0; i < vectSize; i++) { + if (ec == HDF_FAILURE) { + break; + } + IRect rect; + ec = CmdUtils::RectUnpack(unpacker, rect); + rects.push_back(rect); + } + if (ec == HDF_SUCCESS) { + ec = impl_->SetLayerVisibleRegion(devId, layerId, rects); + } + if (ec != HDF_SUCCESS) { + errMaps_.emplace(REQUEST_CMD_SETLAYERVISIBLEREGION, ec); + } + return; + } + + void OnSetLayerBuffer(std::shared_ptr unpacker, + const std::vector& inFds) + { + // unpack + uint32_t devId = -1; + uint32_t layerId = -1; + int32_t ec = CmdUtils::SetupDeviceUnpack(unpacker, devId, layerId); + + BufferHandle* buffer = nullptr; + if (ec == HDF_SUCCESS) { + ec = CmdUtils::BufferHandleUnpack(unpacker, inFds, buffer); + } + int32_t fence = -1; + if (ec == HDF_SUCCESS) { + ec = CmdUtils::FileDescriptorUnpack(unpacker, inFds, fence); + } + HdifdParcelable fdParcel(fence); + if (ec == HDF_SUCCESS) { + ec = impl_->SetLayerBuffer(devId, layerId, *buffer, fdParcel.GetFd()); + } + FreeBufferHandle(buffer); + if (ec != HDF_SUCCESS) { + errMaps_.emplace(REQUEST_CMD_SETLAYERBUFFER, ec); + } + return; + } + + void OnSetLayerCompositionType(std::shared_ptr unpacker) + { + // unpack + uint32_t devId = -1; + uint32_t layerId = -1; + int32_t ec = CmdUtils::SetupDeviceUnpack(unpacker, devId, layerId); + int32_t type; + if (ec == HDF_SUCCESS) { + ec = unpacker->ReadInt32(type) ? HDF_SUCCESS : HDF_FAILURE; + } + // do request + if (ec == HDF_SUCCESS) { + ec = impl_->SetLayerCompositionType(devId, layerId, static_cast(type)); + } + // push err maps if exist + if (ec != HDF_SUCCESS) { + errMaps_.emplace(REQUEST_CMD_SETLAYERCOMPOSITIONTYPE, ec); + } + return; + } + + void OnSetLayerBlendType(std::shared_ptr unpacker) + { + // unpack + uint32_t devId = -1; + uint32_t layerId = -1; + int32_t ec = CmdUtils::SetupDeviceUnpack(unpacker, devId, layerId); + int32_t type; + if (ec == HDF_SUCCESS) { + ec = unpacker->ReadInt32(type) ? HDF_SUCCESS : HDF_FAILURE; + } + // do request + if (ec == HDF_SUCCESS) { + ec = impl_->SetLayerBlendType(devId, layerId, static_cast(type)); + } + // push err maps if exist + if (ec != HDF_SUCCESS) { + errMaps_.emplace(REQUEST_CMD_SETLAYERBLENDTYPE, ec); + } + return; + } + + void OnSetLayerVisible(std::shared_ptr unpacker) + { + // unpack + uint32_t devId = -1; + uint32_t layerId = -1; + int32_t ec = CmdUtils::SetupDeviceUnpack(unpacker, devId, layerId); + bool visible = false; + if (ec == HDF_SUCCESS) { + ec = unpacker->ReadBool(visible) ? HDF_SUCCESS : HDF_FAILURE; + } + // do request + if (ec == HDF_SUCCESS) { + ec = impl_->SetLayerVisible(devId, layerId, visible); + } + // push err maps if exist + if (ec != HDF_SUCCESS) { + errMaps_.emplace(REQUEST_CMD_SETLAYERPREMULTI, ec); + } + return; + } + + int32_t PeriodDataReset() + { + replyCommandCnt_ = 0; + errMaps_.clear(); + + int32_t ec = CmdUtils::StartPack(CONTROL_CMD_REPLY_BEGIN, replyPacker_); + if (ec != HDF_SUCCESS) { + HDF_LOGE("PackBegin failure, ec=%{public}d", ec); + } + return ec; + } + +private: + std::shared_ptr impl_; + std::shared_ptr request_; + bool isReplyUpdated_; + std::shared_ptr reply_; + // period data + uint32_t replyCommandCnt_; + std::shared_ptr replyPacker_; + std::unordered_map errMaps_; +}; +using HdiDisplayCmdResponser = + DisplayCmdResponser, IDisplayDeviceInterface>; +} // V1_0 +} // Display +} // HDI +} // OHOS +#endif diff --git a/display/v1_0/display_command/display_cmd_utils.h b/display/v1_0/display_command/display_cmd_utils.h new file mode 100644 index 0000000000000000000000000000000000000000..0cc0ab1381baf3f76d35c368f6f708aaf6391d89 --- /dev/null +++ b/display/v1_0/display_command/display_cmd_utils.h @@ -0,0 +1,333 @@ +/* + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_HDI_DISPLAY_V1_0_DISPLAYCMDUTILS_H +#define OHOS_HDI_DISPLAY_V1_0_DISPLAYCMDUTILS_H + +#include "buffer_handle_utils.h" +#include "command_data_packer.h" +#include "command_data_unpacker.h" +#include "v1_0/hdi_display_device_type.h" + +namespace OHOS { +namespace HDI { +namespace Display { +namespace V1_0 { + +using namespace OHOS::HDI::Display::V1_0; + +class DisplayCmdUtils { +public: + static constexpr int32_t MAX_INT = 0x7fffffff; + static constexpr int32_t MIN_INT = 0x80000000; + static constexpr uint32_t ELEMENT_SIZE = sizeof(int32_t); + static constexpr uint32_t TRANSFER_WAIT_TIME = 100000000; // ms + static constexpr uint32_t INIT_ELEMENT_COUNT = 32 * 1024; + + #define SWITCHCASE(x) case (x): {return #x;} + static const char* CommandToString(int32_t cmdId) + { + switch (cmdId) { + // request cmd + SWITCHCASE(REQUEST_CMD_PREPAREDISPLAYLAYERS); + SWITCHCASE(REQUEST_CMD_SETDISPLAYCLIENTBUFFER); + SWITCHCASE(REQUEST_CMD_SETDISPLAYCLIENTDAMAGE); + SWITCHCASE(REQUEST_CMD_COMMIT); + SWITCHCASE(REQUEST_CMD_SETLAYERALPHA); + SWITCHCASE(REQUEST_CMD_SETLAYERSIZE); + SWITCHCASE(REQUEST_CMD_SETLAYERCROP); + SWITCHCASE(REQUEST_CMD_SETLAYERZORDER); + SWITCHCASE(REQUEST_CMD_SETLAYERPREMULTI); + SWITCHCASE(REQUEST_CMD_SETTRANSFORMMODE); + SWITCHCASE(REQUEST_CMD_SETLAYERDIRTYREGION); + SWITCHCASE(REQUEST_CMD_SETLAYERVISIBLEREGION); + SWITCHCASE(REQUEST_CMD_SETLAYERBUFFER); + SWITCHCASE(REQUEST_CMD_SETLAYERCOMPOSITIONTYPE); + SWITCHCASE(REQUEST_CMD_SETLAYERBLENDTYPE); + SWITCHCASE(REQUEST_CMD_SETLAYERVISIBLE); + // reply cmd + SWITCHCASE(REPLY_CMD_SETERROR); + SWITCHCASE(REPLY_CMD_PREPAREDISPLAYLAYERS); + SWITCHCASE(REPLY_CMD_COMMIT); + // pack control cmd + SWITCHCASE(CONTROL_CMD_REQUEST_BEGIN); + SWITCHCASE(CONTROL_CMD_REPLY_BEGIN); + SWITCHCASE(CONTROL_CMD_REQUEST_END); + SWITCHCASE(CONTROL_CMD_REPLY_END); + default: + return "unknow command id."; + } + } + + static int32_t StartPack(int32_t cmdId, std::shared_ptr packer) + { + return packer->PackBegin(cmdId) ? HDF_SUCCESS : HDF_FAILURE; + } + + static int32_t EndPack(std::shared_ptr packer) + { + return packer->PackEnd(CONTROL_CMD_REQUEST_END) ? HDF_SUCCESS : HDF_FAILURE; + } + + static int32_t StartSection(int32_t cmdId, std::shared_ptr packer) + { + return packer->BeginSection(cmdId) ? HDF_SUCCESS : HDF_FAILURE; + } + + static int32_t SetupDevice(uint32_t devId, uint32_t layerId, + std::shared_ptr packer) + { + bool retVal = packer->WriteUint32(devId); + if (retVal) { + retVal = packer->WriteUint32(layerId); + } + return retVal ? HDF_SUCCESS : HDF_FAILURE; + } + + static int32_t EndSection(std::shared_ptr packer) + { + return packer->EndSection() ? HDF_SUCCESS : HDF_FAILURE; + } + + static int32_t GenerateHdifdSeqid() + { + static int32_t HdifdSeqidCursor = 0; + return HdifdSeqidCursor <= MAX_INT ? ++HdifdSeqidCursor : 0; + } + + static bool MatchHdiFd(int32_t id, std::vector hdiFds, int32_t& fd) + { + for (uint32_t i = 0; i < hdiFds.size(); ++i) { + if (hdiFds[i].id == id) { + fd = hdiFds[i].hdiFd->Move(); + return true; + } + } + return false; + } + + static int32_t RectPack(const IRect& rect, std::shared_ptr packer) + { + bool retVal = packer->WriteInt32(rect.x); + if (retVal) { + retVal = packer->WriteInt32(rect.y); + } + if (retVal) { + retVal = packer->WriteInt32(rect.w); + } + if (retVal) { + retVal = packer->WriteInt32(rect.h); + } + return retVal ? HDF_SUCCESS : HDF_FAILURE; + } + + static int32_t FileDescriptorPack(const int32_t fd, std::shared_ptr packer, + std::vector& hdiFds) + { + int32_t ec = HDF_SUCCESS; + + HdifdInfo hdifdInfo; + hdifdInfo.id = GenerateHdifdSeqid(); + hdifdInfo.hdiFd = new HdifdParcelable(); + if (hdifdInfo.hdiFd == nullptr) { + HDF_LOGE("error: new HdifdParcelable failed"); + ec = HDF_FAILURE; + } else { + if (fd >= 0) { + // A normal fd is transfered by binder, + // Here just write id for unpacking to match fd. + if (ec == HDF_SUCCESS && hdifdInfo.hdiFd->Init(fd)) { + hdiFds.push_back(hdifdInfo); + ec = packer->WriteInt32(hdifdInfo.id) ? HDF_SUCCESS : HDF_FAILURE; + } else { + HDF_LOGE("error: PackHdifd failed"); + ec = HDF_FAILURE; + } + } else { + // A illegal fd is transfered by smq directly + ec = packer->WriteInt32(fd) ? HDF_SUCCESS : HDF_FAILURE; + } + } + + return ec; + } + + static int32_t BufferHandlePack(const BufferHandle& buffer, + std::shared_ptr packer, std::vector& hdiFds) + { + bool retVal = packer->WriteUint32(buffer.reserveFds); + if (retVal) { + retVal = packer->WriteUint32(buffer.reserveInts); + } + int32_t ec = HDF_SUCCESS; + if (retVal) { + ec = FileDescriptorPack(buffer.fd, packer, hdiFds); + retVal = (ec == HDF_SUCCESS ? true : false); + } + if (retVal) { + retVal = packer->WriteInt32(buffer.width); + } + if (retVal) { + retVal = packer->WriteInt32(buffer.stride); + } + if (retVal) { + retVal = packer->WriteInt32(buffer.height); + } + if (retVal) { + retVal = packer->WriteInt32(buffer.size); + } + if (retVal) { + retVal = packer->WriteInt32(buffer.format); + } + if (retVal) { + retVal = packer->WriteUint64(buffer.usage); + } + if (retVal) { + retVal = packer->WriteUint64(buffer.phyAddr); + } + if (retVal) { + retVal = packer->WriteInt32(buffer.key); + } + if (retVal) { + int32_t i = 0; + for (i = 0; i < buffer.reserveFds; i++) { + ec = FileDescriptorPack(buffer.reserve[i], packer, hdiFds); + if (ec != HDF_SUCCESS) { + retVal = false; + break; + } + } + for (int32_t j = 0; j < buffer.reserveInts; j++) { + retVal = packer->WriteInt32(buffer.reserve[i++]); + if (!retVal) { + break; + } + } + } + return retVal ? HDF_SUCCESS : HDF_FAILURE; + } + + static int32_t SetupDeviceUnpack(std::shared_ptr unpacker, + uint32_t& devId, uint32_t& layerId) + { + bool retVal = unpacker->ReadUint32(devId); + if (retVal) { + retVal = unpacker->ReadUint32(layerId); + } + return retVal ? HDF_SUCCESS : HDF_FAILURE; + } + + static int32_t RectUnpack(std::shared_ptr unpacker, IRect& rect) + { + bool retVal = unpacker->ReadInt32(rect.x); + if (retVal) { + retVal = unpacker->ReadInt32(rect.y); + } + if (retVal) { + retVal = unpacker->ReadInt32(rect.w); + } + if (retVal) { + retVal = unpacker->ReadInt32(rect.h); + } + return retVal ? HDF_SUCCESS : HDF_FAILURE; + } + + static int32_t FileDescriptorUnpack(std::shared_ptr unpacker, + const std::vector& hdiFds, int32_t& fd) + { + int32_t fdId = -1; + int32_t ec = unpacker->ReadInt32(fdId) ? HDF_SUCCESS : HDF_FAILURE; + if (ec == HDF_SUCCESS && fdId >=0) { + ec = MatchHdiFd(fdId, hdiFds, fd) ? HDF_SUCCESS : HDF_FAILURE; + } + if (ec == HDF_FAILURE) { + // if matching failure, the illegal fd is transfered by smq directly, + // not by binder IPC + fd = fdId; + } + return ec; + } + + static int32_t BufferHandleUnpack(std::shared_ptr unpacker, + const std::vector& hdiFds, BufferHandle*& buffer) + { + uint32_t fdsNum = 0; + uint32_t intsNum = 0; + bool retVal = unpacker->ReadUint32(fdsNum); + if (retVal) { + retVal = unpacker->ReadUint32(intsNum); + } + BufferHandle* handle = AllocateBufferHandle(fdsNum, intsNum); + retVal = (handle == nullptr ? false : true); + if (retVal) { + handle->reserveFds = fdsNum; + handle->reserveInts = intsNum; + } + int32_t ec = HDF_SUCCESS; + if (retVal) { + ec = FileDescriptorUnpack(unpacker, hdiFds, handle->fd); + retVal = (ec == HDF_SUCCESS ? true : false); + } + if (retVal) { + retVal = unpacker->ReadInt32(handle->width); + } + if (retVal) { + retVal = unpacker->ReadInt32(handle->stride); + } + if (retVal) { + retVal = unpacker->ReadInt32(handle->height); + } + if (retVal) { + retVal = unpacker->ReadInt32(handle->size); + } + if (retVal) { + retVal = unpacker->ReadInt32(handle->format); + } + if (retVal) { + retVal = unpacker->ReadUint64(handle->usage); + } + if (retVal) { + retVal = unpacker->ReadUint64(handle->phyAddr); + } + if (retVal) { + retVal = unpacker->ReadInt32(handle->key); + } + if (retVal) { + int32_t i = 0; + for (i = 0; i < handle->reserveFds; i++) { + ec = FileDescriptorUnpack(unpacker, hdiFds, handle->reserve[i]); + if (ec != HDF_SUCCESS) { + retVal = false; + break; + } + } + for (int32_t j = 0; j < handle->reserveInts; j++) { + retVal = unpacker->ReadInt32(handle->reserve[i++]); + if (!retVal) { + break; + } + } + } + buffer = handle; + + return retVal ? HDF_SUCCESS : HDF_FAILURE; + } +}; +using CmdUtils = DisplayCmdUtils; +} // V1_0 +} // Display +} // HDI +} // OHOS +#endif diff --git a/display/v1_0/hdi_impl/.display_device_hdi_impl.h.swp b/display/v1_0/hdi_impl/.display_device_hdi_impl.h.swp new file mode 100644 index 0000000000000000000000000000000000000000..f212e0ece1fdd68ff8be9acced62c0f4e072b2f7 Binary files /dev/null and b/display/v1_0/hdi_impl/.display_device_hdi_impl.h.swp differ 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 100644 index 0000000000000000000000000000000000000000..e6523eb94c99c1c5ddacc8ade24ee8ce25eaf53d --- /dev/null +++ b/display/v1_0/hdi_impl/display_device_hdi_impl.h @@ -0,0 +1,332 @@ +/* + * 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, + std::vector& modes) override + { + return hdi_->GetDisplaySupportedModes(devId, modes); + } + + virtual int32_t GetDisplayMode(uint32_t devId, uint32_t& modeId) override + { + return hdi_->GetDisplayMode(devId, modeId); + } + + virtual int32_t SetDisplayMode(uint32_t devId, uint32_t modeId) override + { + return hdi_->SetDisplayMode(devId, modeId); + } + + virtual int32_t GetDisplayPowerStatus(uint32_t devId, DispPowerStatus& status) override + { + return hdi_->GetDisplayPowerStatus(devId, status); + } + + virtual int32_t SetDisplayPowerStatus(uint32_t devId, DispPowerStatus status) override + { + return hdi_->SetDisplayPowerStatus(devId, status); + } + + virtual int32_t GetDisplayBacklight(uint32_t devId, uint32_t& level) override + { + return hdi_->GetDisplayBacklight(devId, level); + } + + virtual int32_t SetDisplayBacklight(uint32_t devId, uint32_t level) override + { + return hdi_->SetDisplayBacklight(devId, level); + } + + virtual int32_t GetDisplayProperty(uint32_t devId, uint32_t id, uint64_t& value) override + { + return hdi_->GetDisplayProperty(devId, id, value); + } + + virtual int32_t GetDisplayCompChange(uint32_t devId, std::vector& layers, + std::vector& types) override + { + return hdi_->GetDisplayCompChange(devId, layers, types); + } + + virtual int32_t SetDisplayClientCrop(uint32_t devId, const IRect& rect) override + { + return hdi_->SetDisplayClientCrop(devId, rect); + } + + virtual int32_t SetDisplayClientDestRect(uint32_t devId, const IRect& rect) override + { + return hdi_->SetDisplayClientDestRect(devId, rect); + } + + virtual int32_t SetDisplayClientBuffer(uint32_t devId, + const BufferHandle& buffer, int32_t fence) override + { + return req_->SetDisplayClientBuffer(devId, buffer, fence); + } + + virtual int32_t SetDisplayClientDamage(uint32_t devId, std::vector& rects) override + { + return req_->SetDisplayClientDamage(devId, rects); + } + + virtual int32_t SetDisplayVsyncEnabled(uint32_t devId, bool enabled) override + { + return hdi_->SetDisplayVsyncEnabled(devId, enabled); + } + + virtual int32_t RegDisplayVBlankCallback(uint32_t devId, VBlankCallback cb, void* data) override + { + vBlankCb_ = cb; + vBlankCbData_ = data; + return hdi_->RegDisplayVBlankCallback(devId, this); + } + + virtual int32_t GetDisplayReleaseFence(uint32_t devId, std::vector& layers, + std::vector& fences) override + { + std::vector> hdiFences; + int32_t ret = hdi_->GetDisplayReleaseFence(devId, layers, hdiFences); + if (ret == HDF_SUCCESS) { + for (int i = 0; i < hdiFences.size(); i++) { + fences.push_back(hdiFences[i]->Move()); + } + } + return ret; + } + + virtual int32_t CreateVirtualDisplay(uint32_t width, uint32_t height, int32_t& format, + uint32_t& devId) override + { + return hdi_->CreateVirtualDisplay(width, height, format, devId); + } + + virtual int32_t DestroyVirtualDisplay(uint32_t devId) override + { + return hdi_->DestroyVirtualDisplay(devId); + } + + virtual int32_t SetVirtualDisplayBuffer(uint32_t devId, + const BufferHandle& buffer, const int32_t fence) override + { + int32_t ret = HDF_SUCCESS; + + sptr hdiBuffer(new BufferHandleParcelable()); + bool bRet = hdiBuffer->Init(buffer); + + if (bRet == false) { + ret = HDF_FAILURE; + } else { + sptr hdiFence(new HdifdParcelable); + hdiFence->Init(fence); + ret = hdi_->SetVirtualDisplayBuffer(devId, hdiBuffer, hdiFence); + } + + return ret; + } + + virtual int32_t SetDisplayProperty(uint32_t devId, uint32_t id, uint64_t value) override + { + return hdi_->SetDisplayProperty(devId, id, value); + } + + virtual int32_t Commit(uint32_t devId, int32_t& fence) override + { + return req_->Commit(devId, fence); + } + + // *** layer func + virtual int32_t CreateLayer(uint32_t devId, const LayerInfo& layerInfo, + uint32_t& layerId) override + { + return hdi_->CreateLayer(devId, layerInfo, layerId); + } + + virtual int32_t CloseLayer(uint32_t devId, uint32_t layerId) override + { + return hdi_->CloseLayer(devId, layerId); + } + + virtual int32_t PrepareDisplayLayers(uint32_t devId, bool& needFlushFb) override + { + return req_->PrepareDisplayLayers(devId, needFlushFb); + } + + virtual int32_t SetLayerAlpha(uint32_t devId, uint32_t layerId, const LayerAlpha& alpha) override + { + return req_->SetLayerAlpha(devId, layerId, alpha); + } + + virtual int32_t SetLayerSize(uint32_t devId, uint32_t layerId, const IRect& rect) override + { + return req_->SetLayerSize(devId, layerId, rect); + } + + virtual int32_t SetLayerCrop(uint32_t devId, uint32_t layerId, const IRect& rect) override + { + return req_->SetLayerCrop(devId, layerId, rect); + } + + virtual int32_t SetLayerZorder(uint32_t devId, uint32_t layerId, uint32_t zorder) override + { + return req_->SetLayerZorder(devId, layerId, zorder); + } + + virtual int32_t SetLayerPreMulti(uint32_t devId, uint32_t layerId, bool preMul) override + { + return req_->SetLayerPreMulti(devId, layerId, preMul); + } + + virtual int32_t SetTransformMode(uint32_t devId, uint32_t layerId, TransformType type) override + { + return req_->SetTransformMode(devId, layerId, type); + } + + virtual int32_t SetLayerDirtyRegion(uint32_t devId, uint32_t layerId, + const IRect& region) override + { + return req_->SetLayerDirtyRegion(devId, layerId, region); + } + + virtual int32_t SetLayerVisibleRegion(uint32_t devId, uint32_t layerId, + std::vector& rects) override + { + return req_->SetLayerVisibleRegion(devId, layerId, rects); + } + + virtual int32_t SetLayerBuffer(uint32_t devId, uint32_t layerId, + BufferHandle& buffer, int32_t fence) override + { + return req_->SetLayerBuffer(devId, layerId, buffer, fence); + } + + virtual int32_t SetLayerCompositionType(uint32_t devId, uint32_t layerId, + CompositionType type) override + { + return req_->SetLayerCompositionType(devId, layerId, type); + } + + virtual int32_t SetLayerBlendType(uint32_t devId, uint32_t layerId, BlendType type) override + { + return req_->SetLayerBlendType(devId, layerId, type); + } + + virtual int32_t SetLayerVisible(uint32_t devId, uint32_t layerId, bool visible) override + { + return req_->SetLayerVisible(devId, layerId, visible); + } + + // Callback implement + virtual int32_t OnHotPlug(uint32_t outputId, bool connected) override + { + int32_t ret = HDF_SUCCESS; + if (hotPlugCb_ != nullptr) { + hotPlugCb_(outputId, connected, hotPlugCbData_); + } else { + HDF_LOGE("erroe: hot plug callback fn is nullptr"); + ret = HDF_FAILURE; + } + + return ret; + } + + virtual int32_t OnVBlank(uint32_t sequence, uint64_t ns) override + { + int32_t ret = HDF_SUCCESS; + if (vBlankCb_ != nullptr) { + vBlankCb_(sequence, ns, vBlankCbData_); + } else { + HDF_LOGE("erroe: vblank callback fn is nullptr"); + ret = HDF_FAILURE; + } + + return ret; + } + +private: + sptr hdi_; + std::shared_ptr req_; + HotPlugCallback hotPlugCb_; + VBlankCallback vBlankCb_; + void* hotPlugCbData_; + void* vBlankCbData_; +}; +using HdiDisplayDeviceImpl = + DisplayDeviceHdiImpl; +} // V1_0 +} // Display +} // HDI +} // OHOS +#endif diff --git a/display/v1_0/include/idisplay_device_interface.h b/display/v1_0/include/idisplay_device_interface.h new file mode 100644 index 0000000000000000000000000000000000000000..770594c2667589451ccd655eb6d9160431b1b10d --- /dev/null +++ b/display/v1_0/include/idisplay_device_interface.h @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_HDI_DISPLAY_V1_0_IDISPLAYDEVICEINTERFACE_H +#define OHOS_HDI_DISPLAY_V1_0_IDISPLAYDEVICEINTERFACE_H + +#include +#include "display_common.h" +#include "display/v1_0/hdi_display_device_type.h" + +namespace OHOS { +namespace HDI { +namespace Display { +namespace V1_0 { + +using namespace OHOS::HDI::Display::V1_0; + +class IDisplayDeviceInterface { +public: + virtual ~IDisplayDeviceInterface() = default; + // *** device func + virtual int32_t RegHotPlugCallback(HotPlugCallback cb, void *data) = 0; + virtual int32_t GetDisplayCapability(uint32_t devId, DisplayCapability& info) = 0; + virtual int32_t GetDisplaySupportedModes(uint32_t devId, + std::vector& modes) = 0; + virtual int32_t GetDisplayMode(uint32_t devId, uint32_t& modeId) = 0; + virtual int32_t SetDisplayMode(uint32_t devId, uint32_t modeId) = 0; + virtual int32_t GetDisplayPowerStatus(uint32_t devId, DispPowerStatus& status) = 0; + virtual int32_t SetDisplayPowerStatus(uint32_t devId, DispPowerStatus status) = 0; + virtual int32_t GetDisplayBacklight(uint32_t devId, uint32_t& level) = 0; + virtual int32_t SetDisplayBacklight(uint32_t devId, uint32_t level) = 0; + virtual int32_t GetDisplayProperty(uint32_t devId, uint32_t id, uint64_t& value) = 0; + virtual int32_t GetDisplayCompChange(uint32_t devId, std::vector& layers, + std::vector& types) = 0; + virtual int32_t SetDisplayClientCrop(uint32_t devId, const IRect& rect) = 0; + virtual int32_t SetDisplayClientDestRect(uint32_t devId, const IRect& rect) = 0; + virtual int32_t SetDisplayClientBuffer(uint32_t devId, + const BufferHandle& buffer, int32_t fence) = 0; + virtual int32_t SetDisplayClientDamage(uint32_t devId, std::vector& rects) = 0; + virtual int32_t SetDisplayVsyncEnabled(uint32_t devId, bool enabled) = 0; + virtual int32_t RegDisplayVBlankCallback(uint32_t devId, VBlankCallback cb, + void* data) = 0; + virtual int32_t GetDisplayReleaseFence(uint32_t devId, std::vector& layers, + std::vector& fences) = 0; + virtual int32_t CreateVirtualDisplay(uint32_t width, uint32_t height, int32_t& format, + uint32_t& devId) = 0; + virtual int32_t DestroyVirtualDisplay(uint32_t devId) = 0; + virtual int32_t SetVirtualDisplayBuffer(uint32_t devId, + const BufferHandle& buffer, const int32_t fence) = 0; + virtual int32_t SetDisplayProperty(uint32_t devId, uint32_t id, uint64_t value) = 0; + virtual int32_t Commit(uint32_t devId, int32_t& fence) = 0; + // *** layer func + virtual int32_t CreateLayer(uint32_t devId, const LayerInfo& layerInfo, + uint32_t& layerId) = 0; + virtual int32_t CloseLayer(uint32_t devId, uint32_t layerId) = 0; + virtual int32_t PrepareDisplayLayers(uint32_t devId, bool& needFlushFb) = 0; + virtual int32_t SetLayerAlpha(uint32_t devId, uint32_t layerId, const LayerAlpha& alpha) = 0; + virtual int32_t SetLayerSize(uint32_t devId, uint32_t layerId, const IRect& rect) = 0; + virtual int32_t SetLayerCrop(uint32_t devId, uint32_t layerId, const IRect& rect) = 0; + virtual int32_t SetLayerZorder(uint32_t devId, uint32_t layerId, uint32_t zorder) = 0; + virtual int32_t SetLayerPreMulti(uint32_t devId, uint32_t layerId, bool preMul) = 0; + virtual int32_t SetTransformMode(uint32_t devId, uint32_t layerId, TransformType type) = 0; + virtual int32_t SetLayerDirtyRegion(uint32_t devId, uint32_t layerId, + const IRect& region) = 0; + virtual int32_t SetLayerVisibleRegion(uint32_t devId, uint32_t layerId, + std::vector& rects) = 0; + virtual int32_t SetLayerBuffer(uint32_t devId, uint32_t layerId, + BufferHandle& buffer, int32_t fence) = 0; + virtual int32_t SetLayerCompositionType(uint32_t devId, uint32_t layerId, + CompositionType type) = 0; + virtual int32_t SetLayerBlendType(uint32_t devId, uint32_t layerId, BlendType type) = 0; + virtual int32_t SetLayerVisible(uint32_t devId, uint32_t layerId, bool visible) = 0; +}; +} // V1_0 +} // Display +} // HDI +} // OHOS + +#endif // OHOS_HDI_DISPLAY_V1_0_IDISPLAYDEVICEINTERFACE_H diff --git a/gralloc/BUILD.gn b/gralloc/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..a5e1b32971ef27b1925d9620ab596adf67dd5046 --- /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 0000000000000000000000000000000000000000..db859ac462133704d1fa7a0030c82f466311fc4b --- /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 Binary files /dev/null and b/gralloc/v1_0/.BUILD.gn.swp differ diff --git a/gralloc/v1_0/BUILD.gn b/gralloc/v1_0/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..f1d07979d9f77876d5a9ba7fa57368d84d93e66c --- /dev/null +++ b/gralloc/v1_0/BUILD.gn @@ -0,0 +1,76 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//drivers/hdf_core/adapter/uhdf2/hdi.gni") +if (defined(ohos_lite)) { + group("libgralloc_proxy_1.0") { + deps = [] + public_configs = [] + } +} else { + hdi("gralloc") { + module_name = "gralloc" + + sources = [ + "IAllocatorInterface.idl", + "IMapperInterface.idl", + "GrallocTypes.idl", + ] + + sequenceable = [ + "//drivers/interface/display/buffersequence:libbufferhandle_parcelable", + ] + + language = "cpp" + subsystem_name = "hdf" + part_name = "drivers_interface_gralloc" + } +} + +ohos_shared_library("libgralloc_hdi_impl") { + + sources = [ + "hdi_impl/gralloc_hdi_impl.cpp", + ] + + include_dirs = [ + "../", + "hdi_impl", + "include", + ] + + cflags = [ + "-Wall", + "-Wextra", + "-Werror", + "-fsigned-char", + "-fno-common", + "-fno-strict-aliasing", + ] + + deps = [ + "//drivers/interface/display/buffersequence:libbufferhandle_parcelable", + "//foundation/graphic/graphic_2d/utils/buffer_handle:buffer_handle", + "//drivers/interface/gralloc/v1_0:libgralloc_proxy_1.0", + ] + + external_deps = [ + "utils_base:utils", + "ipc:ipc_core", + "hiviewdfx_hilog_native:libhilog", + ] + + install_images = [ chipset_base_dir ] + subsystem_name = "hdf" + part_name = "drivers_interface_gralloc" +} diff --git a/gralloc/v1_0/GrallocTypes.idl b/gralloc/v1_0/GrallocTypes.idl new file mode 100644 index 0000000000000000000000000000000000000000..77b51401e78fe684628eaf6f6be6451b9c361671 --- /dev/null +++ b/gralloc/v1_0/GrallocTypes.idl @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ohos.hdi.gralloc.v1_0; + +struct AllocInfo { + unsigned int width; + unsigned int height; + unsigned long usage; + unsigned int format; + unsigned int expectedSize; +}; + +struct VerifyAllocInfo { + unsigned int width; + unsigned int height; + unsigned long usage; + unsigned int format; +}; + diff --git a/gralloc/v1_0/IAllocatorInterface.idl b/gralloc/v1_0/IAllocatorInterface.idl new file mode 100755 index 0000000000000000000000000000000000000000..dfee4525bb80b733844a64b20b657dfd34c9b613 --- /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 0000000000000000000000000000000000000000..5df22f02024c40d8fe123b51770f02f938184e4f --- /dev/null +++ b/gralloc/v1_0/IMapperInterface.idl @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ohos.hdi.gralloc.v1_0; + +import ohos.hdi.gralloc.v1_0.GrallocTypes; + +sequenceable OHOS.HDI.Display.BufferHandleParcelable; + +interface IMapperInterface { + FreeMem([in] BufferHandleParcelable handle); + Mmap([in] BufferHandleParcelable handle); + MmapCache([in] BufferHandleParcelable buffer); + Unmap([in] BufferHandleParcelable handle); + FlushCache([in] BufferHandleParcelable handle); + FlushMCache([in] BufferHandleParcelable buffer); + InvalidateCache([in] BufferHandleParcelable handle); +} diff --git a/gralloc/v1_0/hdi_impl/.gralloc_hdi_impl.cpp.swp b/gralloc/v1_0/hdi_impl/.gralloc_hdi_impl.cpp.swp new file mode 100644 index 0000000000000000000000000000000000000000..41b96da60d3c3320716bfbc0293aca82054e40da Binary files /dev/null and b/gralloc/v1_0/hdi_impl/.gralloc_hdi_impl.cpp.swp differ 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 0000000000000000000000000000000000000000..28b06308fbe5a88f1572736cb46f0bd957154837 --- /dev/null +++ b/gralloc/v1_0/hdi_impl/gralloc_hdi_impl.cpp @@ -0,0 +1,116 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gralloc_hdi_impl.h" +#include "hdf_log.h" + +namespace OHOS { +namespace HDI { +namespace Gralloc { +namespace V1_0 { + +GrallocHdiImpl::GrallocHdiImpl() +{ + allocator_ = IAllocatorInterface::Get(); + mapper_ = IMapperInterface::Get(true); +} + +int32_t GrallocHdiImpl::AllocMem(const AllocInfo& info, BufferHandle*& handle) const +{ + sptr hdiBuffer; + int32_t ret = allocator_->AllocMem(info, hdiBuffer); + if (ret == HDF_SUCCESS) { + handle = hdiBuffer->Move(); + } else { + handle = nullptr; + } + return ret; +} + +void GrallocHdiImpl::FreeMem(const BufferHandle& handle) const +{ + sptr hdiBuffer = + new BufferHandleParcelable(const_cast(handle)); + mapper_->FreeMem(hdiBuffer); +} + +void* GrallocHdiImpl::Mmap(const BufferHandle& handle) const +{ + sptr hdiBuffer = + new BufferHandleParcelable(const_cast(handle)); + int32_t ret = mapper_->Mmap(hdiBuffer); + (void)hdiBuffer->Move(); + void *virAddr = (ret == HDF_SUCCESS ? handle.virAddr : nullptr); + return virAddr; +} + +void* GrallocHdiImpl::MmapCache(const BufferHandle& handle) const +{ + sptr hdiBuffer = + new BufferHandleParcelable(const_cast(handle)); + int32_t ret = mapper_->MmapCache(hdiBuffer); + (void)hdiBuffer->Move(); + void *virAddr = (ret == HDF_SUCCESS ? handle.virAddr : nullptr); + return virAddr; +} + +int32_t GrallocHdiImpl::Unmap(const BufferHandle& handle) const +{ + sptr hdiBuffer = + new BufferHandleParcelable(const_cast(handle)); + int32_t ret = mapper_->Unmap(hdiBuffer); + (void)hdiBuffer->Move(); + return ret; +} + +int32_t GrallocHdiImpl::FlushCache(const BufferHandle& handle) const +{ + sptr hdiBuffer = + new BufferHandleParcelable(const_cast(handle)); + int32_t ret = mapper_->FlushCache(hdiBuffer); + (void)hdiBuffer->Move(); + return ret; +} + +int32_t GrallocHdiImpl::FlushMCache(const BufferHandle& handle) const +{ + sptr hdiBuffer = + new BufferHandleParcelable(const_cast(handle)); + int32_t ret = mapper_->FlushMCache(hdiBuffer); + (void)hdiBuffer->Move(); + return ret; +} + +int32_t GrallocHdiImpl::InvalidateCache(const BufferHandle& handle) const +{ + sptr hdiBuffer = + new BufferHandleParcelable(const_cast(handle)); + int32_t ret = mapper_->InvalidateCache(hdiBuffer); + (void)hdiBuffer->Move(); + return ret; +} + +int32_t GrallocHdiImpl::IsSupportedAlloc(const std::vector &infos, + std::vector &supporteds) const +{ + (void)infos; + (void)supporteds; + return HDF_ERR_NOT_SUPPORT; +} + +} // namespace V1_0 +} // namespace Gralloc +} // namespace HDI +} // namespace OHOS diff --git a/gralloc/v1_0/hdi_impl/gralloc_hdi_impl.h b/gralloc/v1_0/hdi_impl/gralloc_hdi_impl.h new file mode 100644 index 0000000000000000000000000000000000000000..1a66641b9c552a3a19ce42469e38e066bf525643 --- /dev/null +++ b/gralloc/v1_0/hdi_impl/gralloc_hdi_impl.h @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef GRALLOC_HDI_IMPL_V1_0_H +#define GRALLOC_HDI_IMPL_V1_0_H + +#include "buffer_handle.h" +#include "v1_0/include/igralloc_interface.h" +#include "v1_0/iallocator_interface.h" +#include "v1_0/imapper_interface.h" +#include "v1_0/gralloc_types.h" + +namespace OHOS { +namespace HDI { +namespace Gralloc { +namespace V1_0 { +class GrallocHdiImpl : public IGrallocInterface { +public: + GrallocHdiImpl(); + virtual ~GrallocHdiImpl() = default; + + virtual int32_t AllocMem(const AllocInfo& info, BufferHandle*& handle) const override; + virtual void FreeMem(const BufferHandle& handle) const override; + virtual void *Mmap(const BufferHandle& handle) const override; + virtual void *MmapCache(const BufferHandle& handle) const override; + virtual int32_t Unmap(const BufferHandle& handle) const override; + virtual int32_t FlushCache(const BufferHandle& handle) const override; + virtual int32_t FlushMCache(const BufferHandle& handle) const override; + virtual int32_t InvalidateCache(const BufferHandle& handle) const override; + virtual int32_t IsSupportedAlloc(const std::vector &infos, + std::vector &supporteds) const override; +private: + sptr allocator_; + sptr mapper_; +}; +} // namespace V1_0 +} // namespace Gralloc +} // namespace HDI +} // namespace OHOS + +#endif // GRALLOC_HDI_IMPL_V1_0_H diff --git a/gralloc/v1_0/include/.igralloc_interface.h.swp b/gralloc/v1_0/include/.igralloc_interface.h.swp new file mode 100644 index 0000000000000000000000000000000000000000..51dc8473e302b2bad10a6906745498f870d7e10b Binary files /dev/null and b/gralloc/v1_0/include/.igralloc_interface.h.swp differ diff --git a/gralloc/v1_0/include/igralloc_interface.h b/gralloc/v1_0/include/igralloc_interface.h new file mode 100644 index 0000000000000000000000000000000000000000..9b28b457b5bbec38bb22e2c310cd06b6a99e46f1 --- /dev/null +++ b/gralloc/v1_0/include/igralloc_interface.h @@ -0,0 +1,162 @@ +/* + * 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_IGRALLOC_INTERFACE_V1_0_H +#define HDI_IGRALLOC_INTERFACE_V1_0_H + +#include +#include "buffer_handle.h" +#include "v1_0/gralloc_types.h" + +namespace OHOS { +namespace HDI { +namespace Gralloc { +namespace V1_0 { + +class IGrallocInterface { +public: + virtual ~IGrallocInterface() = default; + + /** + * @brief Obtains all interfaces of IGrallocInterface. + * + * @return Returns IGrallocInterface* if the operation is successful; returns an null point otherwise. + * @since 1.0 + * @version 1.0 + */ + template + static IGrallocInterface* Get() + { + IGrallocInterface* instance = new Impl(); + if (instance == nullptr) { + return nullptr; + } + return instance; + } + + /** + * @brief Allocates memory based on the parameters passed by the GUI. + * + * @param info Indicates the description of the memory to allocate. + * + * @param handle Indicates the pointer to the buffer of the memory to allocate. + * + * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} + * otherwise. + * @since 1.0 + * @version 1.0 + */ + virtual int32_t AllocMem(const AllocInfo &info, BufferHandle *&handle) const = 0; + + /** + * @brief Releases memory. + * + * @param handle Indicates the reference to the buffer of the memory to release. + * + * @since 1.0 + * @version 1.0 + */ + virtual void FreeMem(const BufferHandle &handle) const = 0; + + /** + * @brief Maps memory to memory without cache in the process's address space. + * + * @param handle Indicates the reference to the buffer of the memory to map. + * + * @return Returns the pointer to a valid address if the operation is successful; returns NULL otherwise. + * @since 1.0 + * @version 1.0 + */ + virtual void *Mmap(const BufferHandle &handle) const = 0; + + /** + * @brief Maps memory to memory with cache in the process's address space. + * + * @param handle Indicates the reference to the buffer of the memory to map. + * + * @return Returns the pointer to a valid address if the operation is successful; returns NULL otherwise. + * @since 1.0 + * @version 1.0 + */ + virtual void *MmapCache(const BufferHandle &buffer) const = 0; + + /** + * @brief Unmaps memory, that is, removes mappings from the process's address space. + * + * @param handle Indicates the reference to the buffer of the memory to unmap. + * + * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} + * otherwise. + * @since 1.0 + * @version 1.0 + */ + virtual int32_t Unmap(const BufferHandle &handle) const = 0; + + /** + * @brief Flushes data from the cache to memory and invalidates the data in the cache. + * + * @param handle Indicates the reference to the buffer of the cache to flush. + * + * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} + * otherwise. + * @since 1.0 + * @version 1.0 + */ + virtual int32_t FlushCache(const BufferHandle &handle) const = 0; + + /** + * @brief Flushes data from the cache mapped via {@link Mmap} to memory and invalidates the data in the cache. + * + * @param handle Indicates the reference to the buffer of the cache to flush. + * + * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} + * otherwise. + * @since 1.0 + * @version 1.0 + */ + virtual int32_t FlushMCache(const BufferHandle &buffer) const = 0; + + /** + * @brief Invalidates the cache to update it from memory. + * + * @param handle Indicates the reference to the buffer of the cache, which will be invalidated. + * + * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} + * otherwise. + * @since 1.0 + * @version 1.0 + */ + virtual int32_t InvalidateCache(const BufferHandle &handle) const = 0; + + /** + * @brief Checks whether the given VerifyAllocInfo array is allocatable. + * + * @param infos Indicates the VerifyAllocInfo array. + * @param supporteds Indicates whether the array is allocatable. + * + * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} + * otherwise. + * @since 1.0 + * @version 1.0 + */ + virtual int32_t IsSupportedAlloc(const std::vector &infos, + std::vector &supporteds) const = 0; +}; +} // namespace V1_0 +} // namespace Gralloc +} // namespace HDI +} // namespace OHOS + +#endif // HDI_IGRALLOC_INTERFACE_V1_0_H