From a417e542d5f9cd240b380bc974fa00ad9a38e559 Mon Sep 17 00:00:00 2001 From: YOUR_NAME Date: Thu, 20 May 2021 13:49:33 +0000 Subject: [PATCH] =?UTF-8?q?IssueNo=EF=BC=9A#I3S732=20Description:sync=20L2?= =?UTF-8?q?=20input=20and=20display=20to=20L1=20Feature=20or=20Bugfix:Bugf?= =?UTF-8?q?ix=20Binary=20Source:=20No?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- display/hal/BUILD.gn | 59 +- display/hal/default/BUILD.gn | 0 display/hal/default/display_gfx.c | 2 +- display/hal/default/display_gralloc.c | 10 +- display/hal/default/display_layer.c | 16 +- display/hal/disp_common.h | 2 +- display/hal/disp_hal.c | 156 ++-- display/hal/disp_hal.h | 26 +- display/interfaces/include/display_device.h | 146 ++++ display/interfaces/include/display_gfx.h | 5 +- display/interfaces/include/display_gralloc.h | 32 +- display/interfaces/include/display_layer.h | 96 ++- display/interfaces/include/display_type.h | 449 ++++++---- display/interfaces/include/display_vgu.h | 769 ++++++++++++++++++ display/interfaces_lite/include/display_gfx.h | 196 +++++ .../interfaces_lite/include/display_gralloc.h | 163 ++++ .../interfaces_lite/include/display_layer.h | 575 +++++++++++++ .../interfaces_lite/include/display_type.h | 397 +++++++++ display/test/BUILD.gn | 18 +- display/test/unittest/BUILD.gn | 2 +- display/test/unittest/common/display_test.c | 9 +- .../test/unittest/common/hdi_display_test.cpp | 2 +- display/test/unittest/common/loadbmp_test.c | 150 ++-- display/test/unittest/common/loadbmp_test.h | 2 +- input/hal/BUILD.gn | 133 ++- input/hal/include/input_common.h | 10 +- input/hal/src/input_controller.c | 179 ++-- input/hal/src/input_manager.c | 129 ++- input/hal/src/input_reporter.c | 106 ++- input/interfaces/include/input_controller.h | 8 +- input/interfaces/include/input_manager.h | 44 +- input/interfaces/include/input_reporter.h | 32 +- input/interfaces/include/input_type.h | 44 +- input/test/BUILD.gn | 22 +- input/test/unittest/common/hdi_input_test.cpp | 51 +- input/test/unittest/common/hdi_input_test.h | 1 + 36 files changed, 3427 insertions(+), 614 deletions(-) mode change 100755 => 100644 display/hal/BUILD.gn mode change 100755 => 100644 display/hal/default/BUILD.gn mode change 100755 => 100644 display/hal/default/display_gfx.c mode change 100755 => 100644 display/hal/default/display_gralloc.c mode change 100755 => 100644 display/hal/default/display_layer.c mode change 100755 => 100644 display/hal/disp_common.h mode change 100755 => 100644 display/hal/disp_hal.c mode change 100755 => 100644 display/hal/disp_hal.h create mode 100644 display/interfaces/include/display_device.h create mode 100644 display/interfaces/include/display_vgu.h create mode 100644 display/interfaces_lite/include/display_gfx.h create mode 100644 display/interfaces_lite/include/display_gralloc.h create mode 100644 display/interfaces_lite/include/display_layer.h create mode 100644 display/interfaces_lite/include/display_type.h mode change 100755 => 100644 input/hal/BUILD.gn mode change 100755 => 100644 input/hal/include/input_common.h mode change 100755 => 100644 input/hal/src/input_controller.c mode change 100755 => 100644 input/hal/src/input_reporter.c mode change 100755 => 100644 input/test/unittest/common/hdi_input_test.cpp diff --git a/display/hal/BUILD.gn b/display/hal/BUILD.gn old mode 100755 new mode 100644 index b7eea2170f..a81643411a --- a/display/hal/BUILD.gn +++ b/display/hal/BUILD.gn @@ -11,21 +11,54 @@ # See the License for the specific language governing permissions and # limitations under the License. -import("//build/lite/config/component/lite_component.gni") -if (board_name == "hi3516dv300" || board_name == "hispark_taurus" || - board_name == "hi3518ev300" || board_name == "hispark_aries" || - board_name == "aegis_hi3516dv300") { - group("hdi_display") { - public_deps = [ "//device/hisilicon/hardware/display/libs:hdi_display" ] +if (defined(ohos_lite)) { + import("//build/lite/config/component/lite_component.gni") + + if (board_name == "hi3516dv300" || board_name == "hispark_taurus" || + board_name == "hi3518ev300" || board_name == "hispark_aries" || + board_name == "aegis_hi3516dv300") { + group("hdi_display") { + public_deps = [ "//device/hisilicon/hardware/display/libs:hdi_display" ] + } } -} -if (board_name == "sun8i") { - group("hdi_display") { - public_deps = [ "//vendor/allwinner/sun8i/hdi/display:hdi_display" ] +} else { + import("//build/ohos.gni") + + config("display_hdi_public_config") { + visibility = [ ":*" ] + include_dirs = [ + "//drivers/peripheral/display/interfaces/include", + "//third_party/bounds_checking_function/include", + "//foundation/graphic/standard/utils/include", + ] } -} -if (board_name == "default") { + group("hdi_display") { - public_deps = [ "//drivers/peripheral/display/hal/default:hdi_display" ] + deps = [ + ":hdi_display_device", + ":hdi_display_gfx", + ":hdi_display_gralloc", + ":hdi_display_layer", + ] + } + + group("hdi_display_device") { + deps = [ "//device/hisilicon/hardware/display/libs:display_device" ] + public_configs = [ ":display_hdi_public_config" ] + } + + group("hdi_display_gfx") { + deps = [ "//device/hisilicon/hardware/display/libs:display_gfx" ] + public_configs = [ ":display_hdi_public_config" ] + } + + group("hdi_display_gralloc") { + deps = [ "//device/hisilicon/hardware/display/libs:display_gralloc" ] + public_configs = [ ":display_hdi_public_config" ] + } + + group("hdi_display_layer") { + deps = [ "//device/hisilicon/hardware/display/libs:display_layer" ] + public_configs = [ ":display_hdi_public_config" ] } } diff --git a/display/hal/default/BUILD.gn b/display/hal/default/BUILD.gn old mode 100755 new mode 100644 diff --git a/display/hal/default/display_gfx.c b/display/hal/default/display_gfx.c old mode 100755 new mode 100644 index ddd8eadf4b..ffc929a38c --- a/display/hal/default/display_gfx.c +++ b/display/hal/default/display_gfx.c @@ -13,10 +13,10 @@ * limitations under the License. */ +#include "display_gfx.h" #include #include "hdf_log.h" #include "display_type.h" -#include "display_gfx.h" int32_t GfxInitialize(GfxFuncs **funcs) { diff --git a/display/hal/default/display_gralloc.c b/display/hal/default/display_gralloc.c old mode 100755 new mode 100644 index ec3e51a092..86397bdc15 --- a/display/hal/default/display_gralloc.c +++ b/display/hal/default/display_gralloc.c @@ -13,14 +13,14 @@ * limitations under the License. */ -#include +#include "display_gralloc.h" #include +#include #include #include #include #include "hdf_log.h" #include "display_type.h" -#include "display_gralloc.h" #define DEFAULT_READ_WRITE_PERMISSIONS 0666 #define MAX_MALLOC_SIZE 0x10000000UL @@ -36,9 +36,9 @@ static int32_t AllocMem(GrallocBuffer *buffer) HDF_LOGE("%s: buffer is null", __func__); return DISPLAY_NULL_PTR; } - HDF_LOGD("%s: buffer->type = %d, buffer->size = %d", __func__, buffer->type, buffer->size); - if (buffer->size > MAX_MALLOC_SIZE || buffer->size == 0) { - HDF_LOGE("%s: size is invalid, size = %d", __func__, buffer->size); + HDF_LOGD("%s: buffer->type = %d, buffer->size = %u", __func__, buffer->type, buffer->size); + if ((buffer->size > MAX_MALLOC_SIZE) || (buffer->size == 0)) { + HDF_LOGE("%s: size is invalid, size = %u", __func__, buffer->size); return DISPLAY_FAILURE; } while ((shmid = shmget(key, buffer->size, IPC_CREAT | IPC_EXCL | DEFAULT_READ_WRITE_PERMISSIONS)) < 0) { diff --git a/display/hal/default/display_layer.c b/display/hal/default/display_layer.c old mode 100755 new mode 100644 index ddf34df999..8292326866 --- a/display/hal/default/display_layer.c +++ b/display/hal/default/display_layer.c @@ -13,13 +13,14 @@ * limitations under the License. */ +#include "display_layer.h" +#include #include #include #include #include #include "hdf_log.h" #include "display_type.h" -#include "display_layer.h" #define DEV_ID 0 #define LAYER_ID 0 @@ -102,7 +103,7 @@ static int32_t OpenLayer(uint32_t devId, const LayerInfo *layerInfo, uint32_t *l priv->fbSize = ((priv->pitch * priv->height) + 0xfff) & (~0xfff); priv->fbAddr = (void *)mmap(NULL, priv->fbSize, PROT_READ | PROT_WRITE, MAP_SHARED, priv->fd, 0); if (priv->fbAddr == NULL) { - HDF_LOGE("%s: mmap fb address failure", __func__); + HDF_LOGE("%s: mmap fb address failure, errno: %d", __func__, errno); close(priv->fd); priv->fd = -1; priv->pitch = 0; @@ -133,6 +134,9 @@ static int32_t CloseLayer(uint32_t devId, uint32_t layerId) free(priv->layerAddr); priv->layerAddr = NULL; } + if (priv->fbAddr != NULL) { + munmap(priv->fbAddr, priv->fbSize); + } priv->fd = -1; return DISPLAY_SUCCESS; } @@ -151,7 +155,7 @@ static int32_t GetDisplayInfo(uint32_t devId, DisplayInfo *dispInfo) dispInfo->width = priv->width; dispInfo->height = priv->height; dispInfo->rotAngle = ROTATE_NONE; - HDF_LOGD("%s: width = %d, height = %d, rotAngle = %d", __func__, dispInfo->width, + HDF_LOGD("%s: width = %u, height = %u, rotAngle = %u", __func__, dispInfo->width, dispInfo->height, dispInfo->rotAngle); return DISPLAY_SUCCESS; } @@ -167,6 +171,10 @@ static int32_t Flush(uint32_t devId, uint32_t layerId, LayerBuffer *buffer) HDF_LOGE("%s: layerId invalid", __func__); return DISPLAY_FAILURE; } + if (buffer == NULL) { + HDF_LOGE("%s: buffer is null", __func__); + return DISPLAY_FAILURE; + } HDF_LOGD("%s: width = %d, height = %d, pixFormat = %d, pitch = %d", __func__, buffer->width, buffer->height, buffer->pixFormat, buffer->pitch); @@ -235,7 +243,7 @@ int32_t LayerInitialize(LayerFuncs **funcs) lFuncs->Flush = Flush; lFuncs->GetLayerBuffer = GetLayerBuffer; *funcs = lFuncs; - HDF_LOGI("%s: layer initialize success", __func__); + HDF_LOGI("%s: success", __func__); return DISPLAY_SUCCESS; } diff --git a/display/hal/disp_common.h b/display/hal/disp_common.h old mode 100755 new mode 100644 index 2e5ca126de..9687d847be --- a/display/hal/disp_common.h +++ b/display/hal/disp_common.h @@ -52,7 +52,7 @@ enum PowerMode { DISP_OFF, }; -/* output timming */ +/* output timing */ enum IntfSync { OUTPUT_USER = 0, /* User timing */ OUTPUT_PAL, /* PAL standard */ diff --git a/display/hal/disp_hal.c b/display/hal/disp_hal.c old mode 100755 new mode 100644 index f74d63c421..7fed9a096a --- a/display/hal/disp_hal.c +++ b/display/hal/disp_hal.c @@ -13,12 +13,11 @@ * limitations under the License. */ +#include "disp_hal.h" #include -#include "display_type.h" #include "hdf_io_service_if.h" #include "hdf_log.h" #include "hdf_sbuf.h" -#include "disp_hal.h" #define OFFSET_TWO_BYTE 16 #define MASK_TWO_BYTE 0xffff @@ -28,16 +27,16 @@ static int32_t DispCmdSend(const uint32_t cmd, struct HdfSBuf *reqData, struct H struct HdfIoService *dispService = NULL; dispService = HdfIoServiceBind(DISP_SERVICE_NAME); - if (dispService == NULL || dispService->dispatcher == NULL || dispService->dispatcher->Dispatch == NULL) { + if ((dispService == NULL) || (dispService->dispatcher == NULL) || (dispService->dispatcher->Dispatch == NULL)) { HDF_LOGE("%s:bad remote service found", __func__); goto EXIT; } int32_t ret = dispService->dispatcher->Dispatch(&dispService->object, cmd, reqData, respData); - if (ret) { - HDF_LOGE("%s: cmd=%d, ret=%d", __func__, cmd, ret); + if (ret != DISPLAY_SUCCESS) { + HDF_LOGE("%s: cmd=%u, ret=%d", __func__, cmd, ret); goto EXIT; } - HDF_LOGI("%s: cmd=%d, ret=%d", __func__, cmd, ret); + HDF_LOGI("%s: cmd=%u, ret=%d", __func__, cmd, ret); HdfIoServiceRecycle(dispService); return DISPLAY_SUCCESS; @@ -46,7 +45,7 @@ EXIT: return DISPLAY_FAILURE; } -int32_t DispGetInfo(uint32_t devId, struct DispInfo *info) +static int32_t GetInfo(uint32_t devId, struct DispInfo *info) { int32_t ret; struct DispInfo *tmpInfo = NULL; @@ -73,7 +72,7 @@ int32_t DispGetInfo(uint32_t devId, struct DispInfo *info) goto EXIT; } ret = DispCmdSend(DISP_CMD_GET_PANELINFO, data, reply); - if (ret) { + if (ret != DISPLAY_SUCCESS) { HDF_LOGE("cmd:DISP_CMD_GET_PANEL_INFO failure"); goto EXIT; } @@ -83,9 +82,9 @@ int32_t DispGetInfo(uint32_t devId, struct DispInfo *info) goto EXIT; } (void)memcpy_s(info, sizeof(struct DispInfo), tmpInfo, dataSize); - HDF_LOGI("tmpInfo->width = %d, tmpInfo->height = %d", tmpInfo->width, tmpInfo->height); - HDF_LOGI("tmpInfo->hbp = %d, tmpInfo->hfp = %d", tmpInfo->hbp, tmpInfo->hfp); - HDF_LOGI("tmpInfo->frameRate = %d", tmpInfo->frameRate); + HDF_LOGI("tmpInfo->width = %u, tmpInfo->height = %u", tmpInfo->width, tmpInfo->height); + HDF_LOGI("tmpInfo->hbp = %u, tmpInfo->hfp = %u", tmpInfo->hbp, tmpInfo->hfp); + HDF_LOGI("tmpInfo->frameRate = %u", tmpInfo->frameRate); HDF_LOGI("tmpInfo->intfSync = %d", tmpInfo->intfSync); HdfSBufRecycle(data); HdfSBufRecycle(reply); @@ -97,35 +96,51 @@ EXIT: return DISPLAY_FAILURE; } -int32_t DispOn(uint32_t devId) +static int32_t DispGetParaProcess(uint32_t devId, const uint32_t cmd, uint32_t *value) { int32_t ret; - uint32_t mode = DISP_ON; + struct HdfSBuf *data = NULL; + struct HdfSBuf *reply = NULL; - struct HdfSBuf *data = HdfSBufObtainDefaultSize(); + if (value == NULL) { + HDF_LOGE("%s: invalid param", __func__); + return DISPLAY_FAILURE; + } + + data = HdfSBufObtainDefaultSize(); if (data == NULL) { HDF_LOGE("%s: obtain data sbuf fail", __func__); return DISPLAY_FAILURE; } - uint32_t para = (devId << OFFSET_TWO_BYTE) | (mode & 0xffff); - if (!HdfSbufWriteUint32(data, para)) { - HDF_LOGE("HdfSbufWriteUint32 failure\n"); + reply = HdfSBufObtainDefaultSize(); + if (reply == NULL) { + HDF_LOGE("%s: obtain reply sbuf fail", __func__); goto EXIT; } - ret = DispCmdSend(DISP_CMD_SET_POWERMODE, data, NULL); - if (ret) { - HDF_LOGE("cmd:DISP_CMD_SET_POWERMODE failure\n"); + if (!HdfSbufWriteUint32(data, devId)) { + HDF_LOGE("HdfSbufWriteUint32 failure"); + goto EXIT; + } + ret = DispCmdSend(cmd, data, reply); + if (ret != DISPLAY_SUCCESS) { + HDF_LOGE("cmd:DISP_CMD_GET_PANEL_INFO failure"); + goto EXIT; + } + if (!HdfSbufReadUint32(reply, value)) { + HDF_LOGE("HdfSbufReadUint32 failure"); goto EXIT; } HdfSBufRecycle(data); + HdfSBufRecycle(reply); return DISPLAY_SUCCESS; EXIT: HdfSBufRecycle(data); + HdfSBufRecycle(reply); return DISPLAY_FAILURE; } -int32_t SetBacklight(uint32_t devId, uint32_t level) +static int32_t DispEventProcess(uint32_t devId, const uint32_t cmd, uint32_t val) { int32_t ret; @@ -134,14 +149,14 @@ int32_t SetBacklight(uint32_t devId, uint32_t level) HDF_LOGE("%s: obtain data sbuf fail", __func__); return DISPLAY_FAILURE; } - uint32_t para = (devId << OFFSET_TWO_BYTE) | (level & 0xffff); + uint32_t para = (devId << OFFSET_TWO_BYTE) | (val & 0xffff); if (!HdfSbufWriteUint32(data, para)) { HDF_LOGE("HdfSbufWriteUint32 failure\n"); goto EXIT; } - ret = DispCmdSend(DISP_CMD_SET_BACKLIGHT, data, NULL); + ret = DispCmdSend(cmd, data, NULL); if (ret) { - HDF_LOGE("cmd:DISP_CMD_SET_BACKLIGHT failure\n"); + HDF_LOGE("cmd:DISP_CMD_SET_%s failure\n", (cmd == DISP_CMD_SET_POWERSTATUS) ? "POWERMODE" : "BACKLIGHT"); goto EXIT; } HdfSBufRecycle(data); @@ -152,56 +167,63 @@ EXIT: return DISPLAY_FAILURE; } -int32_t DispOff(uint32_t devId) +static int32_t SetPowerStatus(uint32_t devId, PowerStatus pStatus) { - int32_t ret; - uint32_t mode = DISP_OFF; + return DispEventProcess(devId, DISP_CMD_SET_POWERSTATUS, pStatus); +} - struct HdfSBuf *data = HdfSBufObtainDefaultSize(); - if (data == NULL) { - HDF_LOGE("%s: obtain data sbuf fail", __func__); - return DISPLAY_FAILURE; - } - uint32_t para = (devId << OFFSET_TWO_BYTE) | (mode & 0xffff); - if (!HdfSbufWriteUint32(data, para)) { - HDF_LOGE("HdfSbufWriteUint32 failure\n"); - goto EXIT; - } - ret = DispCmdSend(DISP_CMD_SET_POWERMODE, data, NULL); - if (ret) { - HDF_LOGE("cmd:DISP_CMD_SET_POWERMODE failure\n"); - goto EXIT; - } - HdfSBufRecycle(data); - return DISPLAY_SUCCESS; +static int32_t GetPowerStatus(uint32_t devId, PowerStatus *pStatus) +{ + return DispGetParaProcess(devId, DISP_CMD_GET_POWERSTATUS, pStatus); +} -EXIT: - HdfSBufRecycle(data); - return DISPLAY_FAILURE; +static int32_t SetBacklight(uint32_t devId, uint32_t level) +{ + return DispEventProcess(devId, DISP_CMD_SET_BACKLIGHT, level); } -int32_t DispInit(uint32_t devId) +static int32_t GetBacklight(uint32_t devId, uint32_t *level) { - int32_t ret; + return DispGetParaProcess(devId, DISP_CMD_GET_BACKLIGHT, level); +} - struct HdfSBuf *data = HdfSBufObtainDefaultSize(); - if (data == NULL) { - HDF_LOGE("%s: obtain data sbuf fail", __func__); - return DISPLAY_FAILURE; - } - if (!HdfSbufWriteUint32(data, devId)) { - HDF_LOGE("HdfSbufWriteUint32 failure\n"); - goto EXIT; - } - ret = DispCmdSend(DISP_CMD_INIT, data, NULL); - if (ret) { - HDF_LOGE("cmd:DISP_CMD_INIT failure\n"); - goto EXIT; - } - HdfSBufRecycle(data); +HalFuncs *GetHalFuncs(void) +{ + static HalFuncs *hFuncs = NULL; + + if (hFuncs == NULL) { + hFuncs = (HalFuncs *)malloc(sizeof(HalFuncs)); + if (hFuncs == NULL) { + HDF_LOGE("%s: malloc fail", __func__); + return NULL; + } + (void)memset_s(hFuncs, sizeof(HalFuncs), 0, sizeof(HalFuncs)); + hFuncs->SetPowerStatus = SetPowerStatus; + hFuncs->GetPowerStatus = GetPowerStatus; + hFuncs->SetBacklight = SetBacklight; + hFuncs->GetBacklight = GetBacklight; + hFuncs->GetInfo = GetInfo; + } + return hFuncs; +} + +int32_t DispInit(uint32_t devId) +{ + HDF_LOGI("%s: driver has inited", __func__); return DISPLAY_SUCCESS; +} -EXIT: - HdfSBufRecycle(data); - return DISPLAY_FAILURE; +int32_t DispOn(uint32_t devId) +{ + return SetPowerStatus(devId, POWER_STATUS_ON); +} + +int32_t DispOff(uint32_t devId) +{ + return SetPowerStatus(devId, POWER_STATUS_OFF); +} + +int32_t DispGetInfo(uint32_t devId, struct DispInfo *info) +{ + return GetInfo(devId, info); } diff --git a/display/hal/disp_hal.h b/display/hal/disp_hal.h old mode 100755 new mode 100644 index b2388bad87..3d90d4f818 --- a/display/hal/disp_hal.h +++ b/display/hal/disp_hal.h @@ -20,21 +20,41 @@ #define DISP_SERVICE_NAME "hdf_disp" enum DispCmd { - DISP_CMD_INIT = 0, - DISP_CMD_GET_PANELINFO, - DISP_CMD_SET_POWERMODE, + DISP_CMD_GET_PANELINFO = 1, + DISP_CMD_SET_POWERSTATUS, DISP_CMD_SET_BACKLIGHT, + DISP_CMD_GET_POWERSTATUS, + DISP_CMD_GET_BACKLIGHT, }; +typedef enum { + POWER_STATUS_ON, + POWER_STATUS_STANDBY, + POWER_STATUS_SUSPEND, + POWER_STATUS_OFF, + POWER_STATUS_BUTT +} PowerStatus; + struct DispPara { uint32_t devId; void *par; uint32_t size; }; +typedef struct { + int32_t (*SetPowerStatus)(uint32_t devId, PowerStatus pStatus); + int32_t (*GetPowerStatus)(uint32_t devId, PowerStatus *pStatus); + int32_t (*SetBacklight)(uint32_t devId, uint32_t level); + int32_t (*GetBacklight)(uint32_t devId, uint32_t *level); + int32_t (*GetInfo)(uint32_t devId, struct DispInfo *info); +} HalFuncs; + +HalFuncs *GetHalFuncs(void); + int32_t DispInit(uint32_t devId); int32_t DispOn(uint32_t devId); int32_t DispOff(uint32_t devId); int32_t SetBacklight(uint32_t devId, uint32_t level); int32_t DispGetInfo(uint32_t devId, struct DispInfo *info); + #endif /* DISP_HAL_H */ diff --git a/display/interfaces/include/display_device.h b/display/interfaces/include/display_device.h new file mode 100644 index 0000000000..2a67ba8611 --- /dev/null +++ b/display/interfaces/include/display_device.h @@ -0,0 +1,146 @@ +/* + * 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_device.h + * + * @brief Declares control functions of the display device. + * + * @since 1.0 + * @version 2.0 + */ + +#ifndef DISPLAY_DEVICE_H +#define DISPLAY_DEVICE_H +#include "display_type.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Defines pointers to the functions of the display device. + */ +typedef struct { + /** + * @brief Sets the power status. + * + * When the OS enters the sleep mode or wakes up from the sleep mode, the display service or + * the power management module can set the power status of the display device, so that the driver IC + * of the device can normally enter the specified state. + * + * @param devId Indicates the ID of a display device. The value ranges from 0 to 4, where 0 indicates + * the first display device and 4 indicates the last display device. + * @param status Indicates the power status to set. The display service determines whether to set the + * display device to the on or off state based on this setting. For details, see @link PowerStatus}. + * + * @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 (*SetDisplayPowerStatus)(uint32_t devId, PowerStatus status); + + /** + * @brief Obtains the power status. + * + * You can use this function to obtain the power status of the display device specified by devId. + * + * @param devId Indicates the ID of a display device. The value ranges from 0 to 4, where 0 indicates + * the first display device and 4 indicates the last display device. + * @param status Indicates the power status of the display device specified by devId. For details, + * see {@link PowerStatus}. + * + * @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 (*GetDisplayPowerStatus)(uint32_t devId, PowerStatus *status); + + /** + * @brief Sets the backlight level. + * + * You can use this function to set the backlight level of the display device specified by devId. + * + * @param devId Indicates the ID of a display device. The value ranges from 0 to 4, where 0 indicates + * the first display device and 4 indicates the last display device. + * @param level Indicates the backlight level to set. + * + * @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 (*SetDisplayBacklight)(uint32_t devId, uint32_t level); + + /** + * @brief Obtains the backlight level. + * + * You can use this function to obtain the backlight level of the display device specified by devId. + * + * @param devId Indicates the ID of a display device. The value ranges from 0 to 4, where 0 indicates + * the first display device and 4 indicates the last display device. + * @param level Indicates the backlight level. + * + * @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 (*GetDisplayBacklight)(uint32_t devId, uint32_t *level); +} DeviceFuncs; + +/** + * @brief Initializes the control functions of the display device. You can apply for the resources for + * using control functions and then operate the display device by using the control functions. + * + * @param funcs Indicates the double pointer to the control functions of the display device. The caller obtains + * the double pointer to operate the display device. The memory is allocated during initialization, and therefore + * the caller does not need to allocate the memory. + * + * @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 DeviceInitialize(DeviceFuncs **funcs); + +/** + * @brief Uninitializes control functions of the display device. The resources used by + * the control functions will be released. + * + * @param funcs Indicates the double pointer to control functions of the display device. It is used to release + * the memory allocated during initialization of the control 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 DeviceUninitialize(DeviceFuncs *funcs); + +#ifdef __cplusplus +} +#endif +#endif +/* @} */ \ No newline at end of file diff --git a/display/interfaces/include/display_gfx.h b/display/interfaces/include/display_gfx.h index d6576b19da..1b9e770fc3 100644 --- a/display/interfaces/include/display_gfx.h +++ b/display/interfaces/include/display_gfx.h @@ -19,10 +19,11 @@ * * @brief Defines driver functions of the display module. * - * The driver functions provided for the GUI include the layer, hardware acceleration, memory, and callback functions. + * 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 1.0 + * @version 2.0 */ /** diff --git a/display/interfaces/include/display_gralloc.h b/display/interfaces/include/display_gralloc.h index 5f1fd53201..5e23feaa74 100644 --- a/display/interfaces/include/display_gralloc.h +++ b/display/interfaces/include/display_gralloc.h @@ -19,10 +19,10 @@ * * @brief Defines driver functions of the display module. * - * The driver functions provided for the GUI include the layer, hardware acceleration, memory, and callback functions. - * + * 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 1.0 + * @version 2.0 */ @@ -32,7 +32,7 @@ * @brief Declares the driver functions for memory. * * @since 1.0 - * @version 1.0 + * @version 2.0 */ #ifndef DISPLAY_GRALLOC_H @@ -59,7 +59,7 @@ typedef struct { * @since 1.0 * @version 1.0 */ - int32_t (*AllocMem)(GrallocBuffer *buffer); + int32_t (*AllocMem)(const AllocInfo* info, BufferHandle** handle); /** * @brief Releases memory. @@ -69,7 +69,7 @@ typedef struct { * @since 1.0 * @version 1.0 */ - void (*FreeMem)(GrallocBuffer *buffer); + void (*FreeMem)(BufferHandle *handle); /** * @brief Maps memory to memory without cache in the process's address space. @@ -80,7 +80,7 @@ typedef struct { * @since 1.0 * @version 1.0 */ - void *(*Mmap)(GrallocBuffer *buffer); + void *(*Mmap)(BufferHandle *handle); /** * @brief Maps memory to memory with cache in the process's address space. @@ -103,7 +103,7 @@ typedef struct { * @since 1.0 * @version 1.0 */ - int32_t (*Unmap)(GrallocBuffer *buffer); + int32_t (*Unmap)(BufferHandle *handle); /** * @brief Flushes data from the cache to memory and invalidates the data in the cache. @@ -115,7 +115,7 @@ typedef struct { * @since 1.0 * @version 1.0 */ - int32_t (*FlushCache)(GrallocBuffer *buffer); + int32_t (*FlushCache)(BufferHandle *handle); /** * @brief Flushes data from the cache mapped via {@link Mmap} to memory and invalidates the data in the cache. @@ -127,7 +127,19 @@ typedef struct { * @since 1.0 * @version 1.0 */ - int32_t (*FlushMCache)(GrallocBuffer *buffer); + int32_t (*FlushMCache)(BufferHandle *buffer); + + /** + * @brief Invalidate the Cache, it will update the cache from memory. + * + * @param buffer 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); } GrallocFuncs; /** diff --git a/display/interfaces/include/display_layer.h b/display/interfaces/include/display_layer.h index f7caef6d54..65e7597046 100644 --- a/display/interfaces/include/display_layer.h +++ b/display/interfaces/include/display_layer.h @@ -19,7 +19,8 @@ * * @brief Defines driver functions of the display module. * - * The driver functions provided for the GUI include the layer, hardware acceleration, memory, and callback functions. + * 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 1.0 @@ -31,7 +32,7 @@ * @brief Declares the driver functions for implementing layer operations. * * @since 1.0 - * @version 1.0 + * @version 2.0 */ #ifndef DISPLAY_LAYTER_H @@ -107,8 +108,8 @@ typedef struct { * @since 1.0 * @version 1.0 */ - int32_t (*OpenLayer)(uint32_t devId, const LayerInfo *layerInfo, uint32_t *layerId); + int32_t (*CreateLayer)(uint32_t devId, const LayerInfo *layerInfo, uint32_t *layerId); /** * @brief Closes a layer that is no longer required on a specified display device. * @@ -536,6 +537,95 @@ typedef struct { * @version 1.0 */ int32_t (*SnapShot)(uint32_t devId, LayerBuffer *buffer); + + /** + * @brief Set the visible region for a layer + * + * + * @param devId Indicates the ID of a display device. The value ranges from 0 to 4, where 0 indicates the first + * display device and 4 indicates the last display device. + * @param layerId Indicates the layer ID, which identifies a unique layer. You can perform operations on the layer + * with the specified layer ID. + * @param num Indiactes the count of rect. the region contains multiple IRect, the num means how much rects in the + * region. + * @param rect Indiactes the pointer of the rectes. + * + * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} + * otherwise. + * @since 2.0 + * @version 2.0 + */ + int32_t (*SetLayerVisibleRegion)(uint32_t devId, uint32_t layerId, uint32_t num, IRect *rect); + + /** + * @brief Set the buffer for a layer. + * + * + * @param devId Indicates the ID of a display device. The value ranges from 0 to 4, where 0 indicates the first + * display device and 4 indicates the last display device. + * @param layerId Indicates the layer ID, which identifies a unique layer. You can perform operations on the layer + * with the specified layer ID. + * @param buffer Indiactes pointer of the buffer handle, the buffer handle should contain all the information of the + * buffer which will been used for composition + * @param fence Indiactes the fd of a sync file + * + * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} + * otherwise. + * @since 2.0 + * @version 2.0 + */ + int32_t (*SetLayerBuffer)(uint32_t devId, uint32_t layerId, const BufferHandle *buffer, int32_t fence); + + /** + * @brief Extension interface + * + * + * @param devId Indicates the ID of a display device. The value ranges from 0 to 4, where 0 indicates the first + * display device and 4 indicates the last display device. + * @param layerId Indicates the layer ID, which identifies a unique layer. You can perform operations on the layer + * with the specified layer ID. + * @param cmd Indiactes externsion cmd, the implement will use it to identify different intention + * + * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} + * otherwise. + * @since 2.0 + * @version 2.0 + */ + int32_t (*InvokeLayerCmd)(uint32_t devId, uint32_t layerId, uint32_t cmd, ...); + + /** + * @brief set the composition type which the client expect + * + * + * @param devId Indicates the ID of a display device. The value ranges from 0 to 4, where 0 indicates the first + * display device and 4 indicates the last display device. + * @param layerId Indicates the layer ID, which identifies a unique layer. You can perform operations on the layer + * with the specified layer ID. + * @param type Indicates composition type which the client expect, it may be chagne by the implement + * + * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} + * otherwise. + * @since 2.0 + * @version 2.0 + */ + int32_t (*SetLayerCompositionType)(uint32_t devId, uint32_t layerId, CompositionType type); + + /** + * @brief set the blend type + * + * + * @param devId Indicates the ID of a display device. The value ranges from 0 to 4, where 0 indicates the first + * display device and 4 indicates the last display device. + * @param layerId Indicates the layer ID, which identifies a unique layer. You can perform operations on the layer + * with the specified layer ID. + * @param type Indicates blend type + * + * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} + * otherwise. + * @since 2.0 + * @version 2.0 + */ + int32_t (*SetLayerBlendType)(uint32_t devId, uint32_t layerId, BlendType type); } LayerFuncs; /** diff --git a/display/interfaces/include/display_type.h b/display/interfaces/include/display_type.h index 3dc2db85de..cdc3526a8b 100644 --- a/display/interfaces/include/display_type.h +++ b/display/interfaces/include/display_type.h @@ -19,10 +19,11 @@ * * @brief Defines driver functions of the display module. * - * The driver functions provided for the GUI include the layer, hardware acceleration, memory, and callback functions. + * 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 1.0 + * @version 2.0 */ /** @@ -31,7 +32,7 @@ * @brief Declares the data types used by the display driver functions. * * @since 1.0 - * @version 1.0 + * @version 2.0 */ #ifndef DISPLAY_TYPE_H @@ -45,6 +46,7 @@ #include #include #include +#include #ifdef __cplusplus extern "C" { @@ -55,15 +57,15 @@ extern "C" { * */ typedef enum { - DISPLAY_SUCCESS = 0, /* < Success */ - DISPLAY_FAILURE = -1, /* < Failure */ - DISPLAY_FD_ERR = -2, /* < File handle (FD) error */ - DISPLAY_PARAM_ERR = -3, /* < Parameter error */ - DISPLAY_NULL_PTR = -4, /* < Null pointer */ - DISPLAY_NOT_SUPPORT = -5, /* < Unsupported feature */ - DISPLAY_NOMEM = -6, /* < Insufficient memory */ - DISPLAY_SYS_BUSY = -7, /* < System busy */ - DISPLAY_NOT_PERM = -8 /* < Forbidden operation */ + DISPLAY_SUCCESS = 0, /**< Success */ + DISPLAY_FAILURE = -1, /**< Failure */ + DISPLAY_FD_ERR = -2, /**< File handle (FD) error */ + DISPLAY_PARAM_ERR = -3, /**< Parameter error */ + DISPLAY_NULL_PTR = -4, /**< Null pointer */ + DISPLAY_NOT_SUPPORT = -5, /**< Unsupported feature */ + DISPLAY_NOMEM = -6, /**< Insufficient memory */ + DISPLAY_SYS_BUSY = -7, /**< System busy */ + DISPLAY_NOT_PERM = -8 /**< Forbidden operation */ } DispErrCode; /** @@ -71,52 +73,64 @@ typedef enum { * */ typedef enum { - LAYER_TYPE_GRAPHIC, /* < Graphic layer */ - LAYER_TYPE_OVERLAY, /* < Overlay layer */ - LAYER_TYPE_SDIEBAND, /* < Sideband layer */ - LAYER_TYPE_BUTT /* < Empty layer */ + LAYER_TYPE_GRAPHIC, /**< Graphic layer */ + LAYER_TYPE_OVERLAY, /**< Overlay layer */ + LAYER_TYPE_SDIEBAND, /**< Sideband layer */ + LAYER_TYPE_CURSOR, /**< Cursor Layer */ + LAYER_TYPE_BUTT /**< Empty layer */ } LayerType; +/* * + * @brief Defines the buffer usage + * + */ +enum { + HBM_USE_CPU_READ = (1 << 0), /**< CPU will read the memory */ + HBM_USE_CPU_WRITE = (1 << 1), /**< CPU will write the memory */ + HBM_USE_MEM_MMZ = (1 << 2), /**< will use mmz to allocate memory */ + HBM_USE_MEM_DMA = (1 << 3), /**< the allocator should support dma buffer */ +}; + /** * @brief Enumerates pixel formats. * */ typedef enum { - PIXEL_FMT_CLUT8 = 0, /* < CLUT8 format */ - PIXEL_FMT_CLUT1, /* < CLUT1 format */ - PIXEL_FMT_CLUT4, /* < CLUT4 format */ - PIXEL_FMT_RGB_565, /* < RGB565 format */ - PIXEL_FMT_RGBA_5658, /* < RGBA5658 format */ - PIXEL_FMT_RGBX_4444, /* < RGBX4444 format */ - PIXEL_FMT_RGBA_4444, /* < RGBA4444 format */ - PIXEL_FMT_RGB_444, /* < RGB444 format */ - PIXEL_FMT_RGBX_5551, /* < RGBX5551 format */ - PIXEL_FMT_RGBA_5551, /* < RGBA5551 format */ - PIXEL_FMT_RGB_555, /* < RGB555 format */ - PIXEL_FMT_RGBX_8888, /* < RGBX8888 format */ - PIXEL_FMT_RGBA_8888, /* < RGBA8888 format */ - PIXEL_FMT_RGB_888, /* < RGB888 format */ - PIXEL_FMT_BGR_565, /* < BGR565 format */ - PIXEL_FMT_BGRX_4444, /* < BGRX4444 format */ - PIXEL_FMT_BGRA_4444, /* < BGRA4444 format */ - PIXEL_FMT_BGRX_5551, /* < BGRX5551 format */ - PIXEL_FMT_BGRA_5551, /* < BGRA5551 format */ - PIXEL_FMT_BGRX_8888, /* < BGRX8888 format */ - PIXEL_FMT_BGRA_8888, /* < BGRA8888 format */ - PIXEL_FMT_YUV_422_I, /* < YUV422 interleaved format */ - PIXEL_FMT_YCBCR_422_SP, /* < YCBCR422 semi-planar format */ - PIXEL_FMT_YCRCB_422_SP, /* < YCRCB422 semi-planar format */ - PIXEL_FMT_YCBCR_420_SP, /* < YCBCR420 semi-planar format */ - PIXEL_FMT_YCRCB_420_SP, /* < YCRCB420 semi-planar format */ - PIXEL_FMT_YCBCR_422_P, /* < YCBCR422 planar format */ - PIXEL_FMT_YCRCB_422_P, /* < YCRCB422 planar format */ - PIXEL_FMT_YCBCR_420_P, /* < YCBCR420 planar format */ - PIXEL_FMT_YCRCB_420_P, /* < YCRCB420 planar format */ - PIXEL_FMT_YUYV_422_PKG, /* < YUYV422 packed format */ - PIXEL_FMT_UYVY_422_PKG, /* < UYVY422 packed format */ - PIXEL_FMT_YVYU_422_PKG, /* < YVYU422 packed format */ - PIXEL_FMT_VYUY_422_PKG, /* < VYUY422 packed format */ - PIXEL_FMT_BUTT /* < Invalid pixel format */ + PIXEL_FMT_CLUT8 = 0, /**< CLUT8 format */ + PIXEL_FMT_CLUT1, /**< CLUT1 format */ + PIXEL_FMT_CLUT4, /**< CLUT4 format */ + PIXEL_FMT_RGB_565, /**< RGB565 format */ + PIXEL_FMT_RGBA_5658, /**< RGBA5658 format */ + PIXEL_FMT_RGBX_4444, /**< RGBX4444 format */ + PIXEL_FMT_RGBA_4444, /**< RGBA4444 format */ + PIXEL_FMT_RGB_444, /**< RGB444 format */ + PIXEL_FMT_RGBX_5551, /**< RGBX5551 format */ + PIXEL_FMT_RGBA_5551, /**< RGBA5551 format */ + PIXEL_FMT_RGB_555, /**< RGB555 format */ + PIXEL_FMT_RGBX_8888, /**< RGBX8888 format */ + PIXEL_FMT_RGBA_8888, /**< RGBA8888 format */ + PIXEL_FMT_RGB_888, /**< RGB888 format */ + PIXEL_FMT_BGR_565, /**< BGR565 format */ + PIXEL_FMT_BGRX_4444, /**< BGRX4444 format */ + PIXEL_FMT_BGRA_4444, /**< BGRA4444 format */ + PIXEL_FMT_BGRX_5551, /**< BGRX5551 format */ + PIXEL_FMT_BGRA_5551, /**< BGRA5551 format */ + PIXEL_FMT_BGRX_8888, /**< BGRX8888 format */ + PIXEL_FMT_BGRA_8888, /**< BGRA8888 format */ + PIXEL_FMT_YUV_422_I, /**< YUV422 interleaved format */ + PIXEL_FMT_YCBCR_422_SP, /**< YCBCR422 semi-planar format */ + PIXEL_FMT_YCRCB_422_SP, /**< YCRCB422 semi-planar format */ + PIXEL_FMT_YCBCR_420_SP, /**< YCBCR420 semi-planar format */ + PIXEL_FMT_YCRCB_420_SP, /**< YCRCB420 semi-planar format */ + PIXEL_FMT_YCBCR_422_P, /**< YCBCR422 planar format */ + PIXEL_FMT_YCRCB_422_P, /**< YCRCB422 planar format */ + PIXEL_FMT_YCBCR_420_P, /**< YCBCR420 planar format */ + PIXEL_FMT_YCRCB_420_P, /**< YCRCB420 planar format */ + PIXEL_FMT_YUYV_422_PKG, /**< YUYV422 packed format */ + PIXEL_FMT_UYVY_422_PKG, /**< UYVY422 packed format */ + PIXEL_FMT_YVYU_422_PKG, /**< YVYU422 packed format */ + PIXEL_FMT_VYUY_422_PKG, /**< VYUY422 packed format */ + PIXEL_FMT_BUTT /**< Invalid pixel format */ } PixelFormat; /** @@ -124,11 +138,11 @@ typedef enum { * */ typedef enum { - ROTATE_NONE = 0, /* < No rotation */ - ROTATE_90, /* < Rotation by 90 degrees */ - ROTATE_180, /* < Rotation by 180 degrees */ - ROTATE_270, /* < Rotation by 270 degrees */ - ROTATE_BUTT /* < Invalid operation */ + ROTATE_NONE = 0, /**< No rotation */ + ROTATE_90, /**< Rotation by 90 degrees */ + ROTATE_180, /**< Rotation by 180 degrees */ + ROTATE_270, /**< Rotation by 270 degrees */ + ROTATE_BUTT /**< Invalid operation */ } TransformType; /** @@ -138,9 +152,10 @@ typedef enum { * */ typedef enum { - NORMAL_MEM = 0, /* < Memory without cache */ - CACHE_MEM, /* < Memory with cache */ - SHM_MEM /* < Shared memory */ + NORMAL_MEM = 0, /**< Memory without cache */ + CACHE_MEM, /**< Memory with cache */ + SHM_MEM, /**< Shared memory */ + DMA_MEM /**< DMA Memory */ } MemType; /** @@ -150,23 +165,23 @@ typedef enum { * */ typedef enum { - BLEND_NONE = 0, /* < No blending */ - BLEND_CLEAR, /* < CLEAR blending */ - BLEND_SRC, /* < SRC blending */ - BLEND_SRCOVER, /* < SRC_OVER blending */ - BLEND_DSTOVER, /* < DST_OVER blending */ - BLEND_SRCIN, /* < SRC_IN blending */ - BLEND_DSTIN, /* < DST_IN blending */ - BLEND_SRCOUT, /* < SRC_OUT blending */ - BLEND_DSTOUT, /* < DST_OUT blending */ - BLEND_SRCATOP, /* < SRC_ATOP blending */ - BLEND_DSTATOP, /* < DST_ATOP blending */ - BLEND_ADD, /* < ADD blending */ - BLEND_XOR, /* < XOR blending */ - BLEND_DST, /* < DST blending */ - BLEND_AKS, /* < AKS blending */ - BLEND_AKD, /* < AKD blending */ - BLEND_BUTT /* < Null operation */ + BLEND_NONE = 0, /**< No blending */ + BLEND_CLEAR, /**< CLEAR blending */ + BLEND_SRC, /**< SRC blending */ + BLEND_SRCOVER, /**< SRC_OVER blending */ + BLEND_DSTOVER, /**< DST_OVER blending */ + BLEND_SRCIN, /**< SRC_IN blending */ + BLEND_DSTIN, /**< DST_IN blending */ + BLEND_SRCOUT, /**< SRC_OUT blending */ + BLEND_DSTOUT, /**< DST_OUT blending */ + BLEND_SRCATOP, /**< SRC_ATOP blending */ + BLEND_DSTATOP, /**< DST_ATOP blending */ + BLEND_ADD, /**< ADD blending */ + BLEND_XOR, /**< XOR blending */ + BLEND_DST, /**< DST blending */ + BLEND_AKS, /**< AKS blending */ + BLEND_AKD, /**< AKD blending */ + BLEND_BUTT /**< Null operation */ } BlendType; /** @@ -177,23 +192,23 @@ typedef enum { * */ typedef enum { - ROP_BLACK = 0, /* < Blackness */ - ROP_NOTMERGEPEN, /* < ~(S2+S1) */ - ROP_MASKNOTPEN, /* < ~S2&S1 */ - ROP_NOTCOPYPEN, /* < ~S2 */ - ROP_MASKPENNOT, /* < S2&~S1 */ - ROP_NOT, /* < ~S1 */ - ROP_XORPEN, /* < S2^S1 */ - ROP_NOTMASKPEN, /* < ~(S2&S1) */ - ROP_MASKPEN, /* < S2&S1 */ - ROP_NOTXORPEN, /* < ~(S2^S1) */ - ROP_NOP, /* < S1 */ - ROP_MERGENOTPEN, /* < ~S2+S1 */ - ROP_COPYPE, /* < S2 */ - ROP_MERGEPENNOT, /* < S2+~S1 */ - ROP_MERGEPEN, /* < S2+S1 */ - ROP_WHITE, /* < Whiteness */ - ROP_BUTT /* < Invalid ROP type */ + ROP_BLACK = 0, /**< Blackness */ + ROP_NOTMERGEPEN, /**< ~(S2+S1) */ + ROP_MASKNOTPEN, /**< ~S2&S1 */ + ROP_NOTCOPYPEN, /**< ~S2 */ + ROP_MASKPENNOT, /**< S2&~S1 */ + ROP_NOT, /**< ~S1 */ + ROP_XORPEN, /**< S2^S1 */ + ROP_NOTMASKPEN, /**< ~(S2&S1) */ + ROP_MASKPEN, /**< S2&S1 */ + ROP_NOTXORPEN, /**< ~(S2^S1) */ + ROP_NOP, /**< S1 */ + ROP_MERGENOTPEN, /**< ~S2+S1 */ + ROP_COPYPE, /**< S2 */ + ROP_MERGEPENNOT, /**< S2+~S1 */ + ROP_MERGEPEN, /**< S2+S1 */ + ROP_WHITE, /**< Whiteness */ + ROP_BUTT /**< Invalid ROP type */ } RopType; /** @@ -201,10 +216,10 @@ typedef enum { * */ typedef enum { - CKEY_NONE = 0, /* < No color key */ - CKEY_SRC, /* < Source color key */ - CKEY_DST, /* < Destination color key */ - CKEY_BUTT /* < Null operation */ + CKEY_NONE = 0, /**< No color key */ + CKEY_SRC, /**< Source color key */ + CKEY_DST, /**< Destination color key */ + CKEY_BUTT /**< Null operation */ } ColorKey; /** @@ -212,10 +227,10 @@ typedef enum { * */ typedef enum { - MIRROR_NONE = 0, /* < No mirror */ - MIRROR_LR, /* < Left and right mirrors */ - MIRROR_TB, /* < Top and bottom mirrors */ - MIRROR_BUTT /* < Null operation */ + MIRROR_NONE = 0, /**< No mirror */ + MIRROR_LR, /**< Left and right mirrors */ + MIRROR_TB, /**< Top and bottom mirrors */ + MIRROR_BUTT /**< Null operation */ } MirrorType; /** @@ -223,9 +238,9 @@ typedef enum { * */ typedef enum { - INVALID = 0, /* < Invalid connection */ - CONNECTED, /* < Connected */ - DISCONNECTED /* < Disconnected */ + INVALID = 0, /**< Invalid connection */ + CONNECTED, /**< Connected */ + DISCONNECTED /**< Disconnected */ } Connection; /** @@ -233,9 +248,9 @@ typedef enum { * */ typedef struct { - uint32_t width; /* < Display width */ - uint32_t height; /* < Display height */ - int32_t rotAngle; /* < Rotation angle of the display */ + uint32_t width; /**< Display width */ + uint32_t height; /**< Display height */ + int32_t rotAngle; /**< Rotation angle of the display */ } DisplayInfo; /** @@ -246,11 +261,11 @@ typedef struct { * */ typedef struct { - int32_t width; /* < Layer width */ - int32_t height; /* < Layer height */ - LayerType type; /* < Layer type, which can be a graphic layer, overlay layer, or sideband layer */ - int32_t bpp; /* < Number of bits occupied by each pixel */ - PixelFormat pixFormat; /* < Pixel format of the layer */ + int32_t width; /**< Layer width */ + int32_t height; /**< Layer height */ + LayerType type; /**< Layer type, which can be a graphic layer, overlay layer, or sideband layer */ + int32_t bpp; /**< Number of bits occupied by each pixel */ + PixelFormat pixFormat; /**< Pixel format of the layer */ } LayerInfo; /** @@ -258,32 +273,22 @@ typedef struct { * */ typedef struct { - bool enGlobalAlpha; /* < Global alpha enable bit */ - bool enPixelAlpha; /* < Pixel alpha enable bit */ - uint8_t alpha0; /* < Alpha0 value, ranging from 0 to 255 */ - uint8_t alpha1; /* < Alpha1 value, ranging from 0 to 255 */ - uint8_t gAlpha; /* < Global alpha value, ranging from 0 to 255 */ + bool enGlobalAlpha; /**< Global alpha enable bit */ + bool enPixelAlpha; /**< Pixel alpha enable bit */ + uint8_t alpha0; /**< Alpha0 value, ranging from 0 to 255 */ + uint8_t alpha1; /**< Alpha1 value, ranging from 0 to 255 */ + uint8_t gAlpha; /**< Global alpha value, ranging from 0 to 255 */ } LayerAlpha; -/** - * @brief Defines the buffer handle, including the shared memory key, shared memory ID, and physical memory address. - * - */ -typedef struct { - int32_t key; /* < Shared memory key */ - int32_t shmid; /* < Unique ID of the shared memory */ - uint64_t phyAddr; /* < Physical memory address */ -} BufferHandle; - /** * @brief Defines the memory buffer, such as virtual and physical memory addresses. * */ typedef struct { - BufferHandle hdl; /* < Buffer handle */ - MemType type; /* < Type of the requested memory */ - uint32_t size; /* < Size of the requested memory */ - void *virAddr; /* < Virtual address of the requested memory */ + BufferHandle hdl; /**< Buffer handle */ + MemType type; /**< Type of the requested memory */ + uint32_t size; /**< Size of the requested memory */ + void *virAddr; /**< Virtual address of the requested memory */ } GrallocBuffer; /** @@ -291,8 +296,8 @@ typedef struct { * */ typedef struct { - uint64_t phyAddr; /* < Physical memory address */ - void *virAddr; /* < Virtual memory address */ + uint64_t phyAddr; /**< Physical memory address */ + void *virAddr; /**< Virtual memory address */ } BufferData; /** @@ -300,12 +305,13 @@ typedef struct { * */ typedef struct { - int32_t fenceId; /* < Fence ID of the buffer */ - int32_t width; /* < Buffer width */ - int32_t height; /* < Buffer height */ - int32_t pitch; /* < Number of bytes from one row of pixels in memory to the next */ - PixelFormat pixFormat; /* < Pixel format of the buffer */ - BufferData data; /* < Layer buffer data */ + int32_t fenceId; /**< Fence ID of the buffer */ + int32_t width; /**< Buffer width */ + int32_t height; /**< Buffer height */ + int32_t pitch; /**< Number of bytes from one row of pixels in memory to the next */ + PixelFormat pixFormat; /**< Pixel format of the buffer */ + BufferData data; /**< Layer buffer data */ + BufferHandle* hdl; /**< Layer buffer handle */ } LayerBuffer; /** @@ -313,10 +319,10 @@ typedef struct { * */ typedef struct { - int32_t x; /* < Start X coordinate of the rectangle */ - int32_t y; /* < Start Y coordinate of the rectangle */ - int32_t w; /* < Width of the rectangle */ - int32_t h; /* < Height of the rectangle */ + int32_t x; /**< Start X coordinate of the rectangle */ + int32_t y; /**< Start Y coordinate of the rectangle */ + int32_t w; /**< Width of the rectangle */ + int32_t h; /**< Height of the rectangle */ } IRect; /** @@ -324,19 +330,19 @@ typedef struct { * */ typedef struct { - uint64_t phyAddr; /* < Start physical address of an image */ - int32_t height; /* < Image height */ - int32_t width; /* < Image width */ - int32_t stride; /* < Image stride */ - PixelFormat enColorFmt; /* < Image format */ - bool bYCbCrClut; /* < Whether the color lookup table (CLUT) is in the YCbCr space */ - bool bAlphaMax255; /* < Maximum alpha value of an image (255 or 128) */ - bool bAlphaExt1555; /* < ARGB1555 alpha extension enable bit */ - uint8_t alpha0; /* < Value of alpha0, ranging from 0 to 255 */ - uint8_t alpha1; /* < Value of alpha1, ranging from 0 to 255 */ - uint64_t cbcrPhyAddr; /* < CbCr physical address */ - int32_t cbcrStride; /* < CbCr stride */ - uint64_t clutPhyAddr; /* < Start physical address of the CLUT, used for color extension or correction */ + uint64_t phyAddr; /**< Start physical address of an image */ + int32_t height; /**< Image height */ + int32_t width; /**< Image width */ + int32_t stride; /**< Image stride */ + PixelFormat enColorFmt; /**< Image format */ + bool bYCbCrClut; /**< Whether the color lookup table (CLUT) is in the YCbCr space */ + bool bAlphaMax255; /**< Maximum alpha value of an image (255 or 128) */ + bool bAlphaExt1555; /**< ARGB1555 alpha extension enable bit */ + uint8_t alpha0; /**< Value of alpha0, ranging from 0 to 255 */ + uint8_t alpha1; /**< Value of alpha1, ranging from 0 to 255 */ + uint64_t cbcrPhyAddr; /**< CbCr physical address */ + int32_t cbcrStride; /**< CbCr stride */ + uint64_t clutPhyAddr; /**< Start physical address of the CLUT, used for color extension or correction */ } ISurface; /** @@ -344,11 +350,11 @@ typedef struct { * */ typedef struct { - int32_t x0; /* < X coordinate of the start point of a line */ - int32_t y0; /* < Y coordinate of the start point of a line */ - int32_t x1; /* < X coordinate of the end point of a line */ - int32_t y1; /* < Y coordinate of the end point of a line */ - uint32_t color; /* < Line color */ + int32_t x0; /**< X coordinate of the start point of a line */ + int32_t y0; /**< Y coordinate of the start point of a line */ + int32_t x1; /**< X coordinate of the end point of a line */ + int32_t y1; /**< Y coordinate of the end point of a line */ + uint32_t color; /**< Line color */ } ILine; /** @@ -356,10 +362,10 @@ typedef struct { * */ typedef struct { - int32_t x; /* < X coordinate of a circle center */ - int32_t y; /* < Y coordinate of a circle center */ - int32_t r; /* < Radius of a circle */ - uint32_t color; /* < Circle color */ + int32_t x; /**< X coordinate of a circle center */ + int32_t y; /**< Y coordinate of a circle center */ + int32_t r; /**< Radius of a circle */ + uint32_t color; /**< Circle color */ } ICircle; /** @@ -367,8 +373,8 @@ typedef struct { * */ typedef struct { - IRect rect; /* < Bounds of a rectangle */ - uint32_t color; /* < Rectangle color */ + IRect rect; /**< Bounds of a rectangle */ + uint32_t color; /**< Rectangle color */ } Rectangle; /** @@ -376,19 +382,106 @@ typedef struct { * */ typedef struct { - bool enGlobalAlpha; /* < Golbal alpha enable bit */ - uint32_t globalAlpha; /* < Global alpha value */ - bool enPixelAlpha; /* < Pixel alpha enable bit */ - BlendType blendType; /* < Blending type */ - ColorKey colorKeyFrom; /* < Color key mode */ - bool enableRop; /* < Raster operations pipeline (ROP) enable bit */ - RopType colorRopType; /* < Color ROP type */ - RopType alphaRopType; /* < Alpha ROP type */ - bool enableScale; /* < Scaling enable bit */ - TransformType rotateType; /* < Rotation type */ - MirrorType mirrorType; /* < Mirror type */ + bool enGlobalAlpha; /**< Golbal alpha enable bit */ + uint32_t globalAlpha; /**< Global alpha value */ + bool enPixelAlpha; /**< Pixel alpha enable bit */ + BlendType blendType; /**< Blending type */ + ColorKey colorKeyFrom; /**< Color key mode */ + bool enableRop; /**< Raster operations pipeline (ROP) enable bit */ + RopType colorRopType; /**< Color ROP type */ + RopType alphaRopType; /**< Alpha ROP type */ + bool enableScale; /**< Scaling enable bit */ + TransformType rotateType; /**< Rotation type */ + MirrorType mirrorType; /**< Mirror type */ } GfxOpt; +#define PROPERTY_NAME_LEN 50 + +/** + * @brief Defines property object which contains name, property id and value. + * + */ +typedef struct { + char name[PROPERTY_NAME_LEN]; /**< Name of the property */ + uint32_t propId; /**< Property id which was decided in the DRM internal */ + uint64_t value; /**< the value of property */ +} PropertyObject; + +/** + * @brief Enumerates interface types. + * + */ +typedef enum { + DISP_INTF_HDMI = 0, /**< HDMI interface */ + DISP_INTF_LCD, /**< LCD interface */ + DISP_INTF_BT1120, /**< BT1120 interface */ + DISP_INTF_BT656, /**< BT656 interface */ + DISP_INTF_YPBPR, /**< YPBPR interface */ + DISP_INTF_RGB, /**< RGB interface */ + DISP_INTF_CVBS, /**< CVBS interface */ + DISP_INTF_SVIDEO, /**< SVIDEO interface */ + DISP_INTF_VGA, /**< VGA interface */ + DISP_INTF_MIPI, /**< MIPI interface */ + DISP_INTF_PANEL, /**< PANEL interface */ + DISP_INTF_BUTT, +} InterfaceType; + +/** + * @brief Defines the capability of the output. + */ +typedef struct { + char name[PROPERTY_NAME_LEN]; /**< name of output */ + InterfaceType type; /**< interface type of output */ + uint32_t phyWidth; /**< Physical width */ + uint32_t phyHeight; /**< Physical width */ + uint32_t supportLayers; /**< BitMask of LayerType */ + uint32_t propertyCount; /**< Count of properties */ + PropertyObject* props; /**< Array of property objects */ +} DisplayCapability; + +/** + * @brief Defines output mode info + */ +typedef struct { + int32_t width; /**< width in pixel */ + int32_t height; /**< height in pixel */ + uint32_t freshRate; /**< fresh rate in one second */ +} DisplayModeInfo; + +/** + * @brief Defines information for allocate memory + * + */ +typedef struct { + uint32_t width; /**< The width of the request allocation */ + uint32_t height; /**< The height of the request allocation */ + uint64_t usage; /**< The usage of the request allocation */ + PixelFormat format; /**< The format of the request allocation */ + MemType type; /**< The memory of the request allocation */ +} AllocInfo; +/** + * @brief Enumerates power status. + */ + +typedef enum { + POWER_STATUS_ON, /**< The power status is on */ + POWER_STATUS_STANDBY, /**< The power status is standby */ + POWER_STATUS_SUSPEND, /**< The power status is suspend */ + POWER_STATUS_OFF, /**< The power status is off */ + POWER_STATUS_BUTT +} PowerStatus; + +/** + * @brief Enumerates composition type for special layer + */ +typedef enum { + COMPOSITION_CLIENT, /**< client composistion type, the composer should been cpu or gpu */ + COMPOSITION_DEVICE, /**< device composistion type, the composer should been a hardware */ + COMPOSITION_CURSOR, /**< cursor composistion type. it should been used for cursor */ + COMPOSITION_VIDEO, /**< cursor composistion type. it should been used for video */ + COMPOSITION_BUTT +} CompositionType; + #ifdef __cplusplus } #endif diff --git a/display/interfaces/include/display_vgu.h b/display/interfaces/include/display_vgu.h new file mode 100644 index 0000000000..6214bfaa1a --- /dev/null +++ b/display/interfaces/include/display_vgu.h @@ -0,0 +1,769 @@ +/* + * 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. + */ + +/* * + * @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 3.0 + */ + +/* * + * @file display_vgu.h + * + * @brief Declares the driver functions for implementing 2D vector hardware acceleration. + * + * @since 3.0 + */ + +#ifndef DISPLAY_VGU_H +#define DISPLAY_VGU_H +#include "display_type.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#undef HDI_VGU_SCALAR_IS_FLOAT +#define HDI_VGU_SCALAR_IS_FLOAT 1 + +#ifdef HDI_VGU_SCALAR_IS_FLOAT +typedef float VGUScalar; +#else +typedef int32_t VGUScalar; +#endif + +typedef PixelFormat VGUPixelFormat; /* < Pixel formats */ +typedef BlendType VGUBlendType; /* < Blend types supported by hardware acceleration */ + +/* * + * @brief Enumerates data types of paths. + * + */ +typedef enum { + VGU_DATA_TYPE_S16 = 0, /* < Integer (2 bytes) */ + VGU_DATA_TYPE_S32, /* < Integer (4 bytes) */ + VGU_DATA_TYPE_F32 /* < Floating point number (4 bytes) */ +} VGUPathDataType; + +/* * + * @brief Enumerates supported hardware acceleration capabilities. + * + */ +typedef enum { + VGU_CAP_BLIT = (1 << 0), /* < Bit blit */ + VGU_CAP_BLIT_NUM = (1 << 1), /* < Maximum number of images that can be combined during bit blit */ + VGU_CAP_PATH = (1 << 2), /* < Path filling and stroking */ + VGU_CAP_FILTER_BLUR = (1 << 3), /* < Blur filter */ +} VGUCapability; + +/* * + * @brief Enumerates result codes that may return. + * + */ +typedef enum { + VGU_SUCCESS = 0, /* < The operation is successful. */ + VGU_NO_SUPPORT = -1, /* < This feature is not supported. */ + VGU_OPERATION_FAILED = -2, /* < The operation failed. */ + VGU_OUT_OF_MEMORY = -3, /* < The operation ran out of memory. */ + VGU_TIMEOUT = -4, /* < The operation times out. */ + VGU_INVALID_PARAMETER = -5, /* < One or more parameters are invalid. */ + VGU_BUSY = -6, /* < The device is busy. */ + VGU_NO_CONTEXT = -7, /* < There is no context specified. */ +} VGUResult; + +/* * + * @brief Enumerates styles for the endpoints of a stroked line. + * + */ +typedef enum { + VGU_LINECAP_BUTT = 0, /* < A line with a squared-off end (default value) */ + VGU_LINECAP_ROUND, /* < A line with a rounded end */ + VGU_LINECAP_SQUARE /* < A line with a squared-off end */ +} VGULineCap; + +/* * + * @brief Enumerates join types for stroked lines. + * + */ +typedef enum { + VGU_LINE_JOIN_MITER = 0, /* < A join with a sharp corner (default value) */ + VGU_LINE_JOIN_ROUND, /* < A join with a rounded end */ + VGU_LINE_JOIN_BEVEL, /* < A join with a squared-off end */ + VGU_LINE_JOIN_BUTT /* < Invalid definition */ +} VGUJointType; + +/* * + * @brief Defines the coordinates of a point. + * + */ +typedef struct { + VGUScalar x; /* < Horizontal coordinate of the point */ + VGUScalar y; /* < Vertical coordinate of the point */ +} VGUPoint; + +/* * + * @brief Defines a rectangle. + * + */ +typedef struct { + VGUScalar x; /* < Horizontal coordinate of the start point of the rectangle */ + VGUScalar y; /* < Vertical coordinate of the start point of the rectangle */ + VGUScalar w; /* < Width of the rectangle */ + VGUScalar h; /* < Height of the rectangle */ +} VGURect; + +/* * + * @brief Enumerates filter types for rendering an image. + * + */ +typedef enum { + VGU_FILTER_BILINEAR = 0, /* < Bilinear interpolation filter (default value) */ + VGU_FILTER_NEAREST, /* < No interpolation filter */ + VGU_FILTER_LINEAR, /* < Linear interpolation filter */ + VGU_FILTER_BUTT /* < Invalid definition */ +} VGUFilter; + +/* * + * @brief Enumerates fill rules for graphics. + * + */ +typedef enum { + VGU_RULE_WINDING = 0, /* < Non-zero winding rule (default value) */ + VGU_RULE_EVEN_ODD, /* < Even-odd rule */ + VGU_RULE_BUTT /* < Invalid definition */ +} VGUFillRule; + +/* * + * @brief Enumerates fill types of the outside of the gradient area. + * + */ +typedef enum { + VGU_SPREAD_PAD = 0, /* < The area is filled with the closest gradient stop color. (Default value) */ + VGU_SPREAD_REFLECT, /* < The gradient is reflected outside the area. */ + VGU_SPREAD_REPEAT, /* < The gradient is repeated outside the area. */ + VGU_SPREAD_BUTT /* < Invalid definition */ +} VGUFillSpread; + +/* * + * @brief Enumerates wrap types of a pattern. + * + */ +typedef enum { + VGU_WRAP_REFLECT = 0, /* < The pattern is reflected. */ + VGU_WRAP_REPEAT, /* < The pattern is repeated. */ + VGU_WRAP_BUTT /* < Invalid definition */ +} VGUWrapType; + +/* * + * @brief Enumerates commands for drawing a path. + * + */ +typedef enum { + VGU_PATH_CMD_CLOSE = 0, /* < Close the current subpath (coordinates: none). */ + VGU_PATH_CMD_MOVE, /* < Move to the specified point (coordinates: x0, y0). */ + VGU_PATH_CMD_LINE, /* < Draw a line (coordinates: x0, y0). */ + VGU_PATH_CMD_HLINE, /* < Draw a horizontal line (coordinates: x0). */ + VGU_PATH_CMD_VLINE, /* < Draw a vertical line (coordinates: y0). */ + VGU_PATH_CMD_QUAD, /* < Draw a quadratic Bezier curve (coordinates: x0, y0, x1, y1). */ + VGU_PATH_CMD_CUBIC, /* < Draw a cubic Bezier curve (coordinates: x0, y0, x1, y1, x2, y2). */ + VGU_PATH_CMD_SQUAD, /* < Draw a smooth quadratic Bezier curve (coordinates: x1, y1). */ + VGU_PATH_CMD_SCUBIC, /* < Draw a smooth cubic Bezier curve (coordinates: x1, y1, x2, y2). */ + VGU_PATH_CMD_BUTT, /* < Invalid definition */ +} VGUPathCmd; + +/* * + * @brief Defines a path object, which stores path-related commands and coordinates. + * + */ +typedef struct { + uint8_t *segment; /* < Pointer to the path command data */ + int32_t numSegments; /* < Total number of path commands */ + uint8_t *data; /* < Pointer to the coordinates used in the path commands */ + VGUPathDataType type; /* < Data type of the path */ + bool enAlias; /* < Whether to enable anti-aliasing */ + VGURect boundBox; /* < Bounding box of the path */ +} VGUPath; + +/* * + * @brief Enumerates transform types. + * + */ +typedef enum { + VGU_TRANSFORM_TRANSLATE = (1 << 0), /* < Translate */ + VGU_TRANSFORM_SCALE = (1 << 1), /* < Scale */ + VGU_TRANSFORM_ROTATE_90 = (1 << 2), /* < Rotate by 90 degrees */ + VGU_TRANSFORM_ROTATE_180 = (1 << 3), /* < Rotate by 180 degrees */ + VGU_TRANSFORM_ROTATE_270 = (1 << 4), /* < Rotate by 270 degrees */ + VGU_TRANSFORM_OTHER = (1 << 16) /* < Other transform type */ +} VGUTransformType; + +/* * + * @brief Defines a transformation matrix. + * + */ +typedef struct { + float m[3][3]; /* < 3x3 transformation matrix */ + uint32_t type; /* < Transform type, which can be scale, translate, or rotate by 90 x N degrees */ +} VGUMatrix3; + +/* * + * @brief Stores bitmap information for hardware acceleration. + * + */ +typedef struct { + VGUPixelFormat pixelFormat; /* < Pixel format */ + uint32_t width; /* < Bitmap width */ + uint32_t height; /* < Bitmap height */ + uint32_t stride; /* < Bitmap stride */ + void *virAddr; /* < Virtual address of the requested memory */ + uint64_t phyAddr; /* < Physical memory address */ +} VGUBuffer; + +/* * + * @brief Enumerates clip types of a surface. + * + */ +typedef enum { + VGU_CLIP_RECT = 0, /* < Rectangle clip (default value) */ + VGU_CLIP_PATH, /* < Path clip */ + VGU_CLIP_BUTT /* < Invalid definition */ +} VGUClipType; + +/* * + * @brief Defines a mask layer. + * + */ +typedef struct { + VGUBuffer *buffer; /* < Pointer to the buffer for the mask */ + VGURect *rect; /* < Pointer to the rectangle for the mask */ +} VGUMaskLayer; + +/* * + * @brief Stores surface information for 2D hardware acceleration. + * + */ +typedef struct { + VGUBuffer *buffer; /* < Bitmap buffer */ + union { + VGURect *clipRect; /* < Pointer to the clip rectangle. If it is null, the entire surface will be rendered. */ + VGUPath *clipPath; /* < Pointer to the clip path. If it is null, the entire surface will be rendered. */ + }; + VGUClipType clipType; /* < Clip type of the surface */ + VGUMaskLayer *mask; /* < Mask layer, which can be null */ + VGUBlendType blend; /* < Blend type, specifying how a new image is drawn onto an existing surface */ + VGUFilter filter; /* < Filter type */ +} VGUSurface; + +/* * + * @brief Defines how the colors are distributed along the gradient. + * + */ +typedef struct { + float stop; /* < Stop position. The value ranges from 0.0 to 1.0. */ + uint32_t color; /* < Color of the stop */ +} VGUColorStop; + +/* * + * @brief Defines a linear gradient. + * + */ +typedef struct { + VGUScalar x1; /* < Horizontal coordinate of the start point of the linear gradient */ + VGUScalar y1; /* < Vertical coordinate of the start point of the linear gradient */ + VGUScalar x2; /* < Horizontal coordinate of the end point of the linear gradient */ + VGUScalar y2; /* < Vertical coordinate of the end point of the linear gradient */ +} VGULinear; + +/* * + * @brief Defines a radial gradient. + * + */ +typedef struct { + VGUScalar x0; /* < Horizontal coordinate of the center of the inner circle */ + VGUScalar y0; /* < Vertical coordinate of the center of the inner circle */ + VGUScalar r0; /* < Radius of the inner circle */ + VGUScalar x1; /* < Horizontal coordinate of the center of the outer circle */ + VGUScalar y1; /* < Vertical coordinate of the center of the outer circle */ + VGUScalar r1; /* < Radius of the outer circle */ +} VGURadial; + +/* * + * @brief Defines a conic gradient. + * + */ +typedef struct { + VGUScalar cx; /* < Horizontal coordinate of the center of the circle */ + VGUScalar cy; /* < Vertical coordinate of the center of the circle */ +} VGUConic; + +/* * + * @brief Defines an image. + * + */ +typedef struct { + VGUBuffer *buffer; /* < Image buffer */ + VGUMatrix3 *matrix; /* < Pointer to the transformation matrix. If it is null, the identity matrix is used. */ + VGURect *rect; /* < Pointer to the rectangle of the image. If it is null, the entire buffer data is used. */ + uint8_t opacity; /* < Opacity. The value ranges from 0 to 255. */ +} VGUImage; + +/* * + * @brief Defines an image pattern. + * + */ +typedef struct { + VGUImage *image; /* < Pointer to the image object */ + VGUWrapType wrapx; /* < Wrap the image horizontally. */ + VGUWrapType wrapy; /* < Wrap the image vertically. */ +} VGUPattern; + +/* * + * @brief Enumerates gradient types. + * + */ +typedef enum { + VGU_GRADIENT_LINEAR = 0, /* < Linear gradient */ + VGU_GRADIENT_RADIAL, /* < Radial gradient */ + VGU_GRADIENT_CONIC, /* < Conic gradient */ + VGU_GRADIENT_BUTT /* < Invalid definition */ +} VGUGradientType; + +/* * + * @brief Defines a gradient object. + * + */ +typedef struct { + VGUMatrix3 *matrix; /* < Pointer to the transformation matrix of the gradient object */ + VGUColorStop *colorStops; /* < Pointer to the gradient stop color array */ + uint16_t stopCount; /* < Number of stop colors */ + union { + VGULinear linear; /* < Linear gradient object */ + VGURadial radial; /* < Radial gradient object */ + VGUConic conic; /* < Conic gradient object */ + }; + VGUGradientType type; /* < Gradient type */ + VGUFillSpread spread; /* < Gradient spread mode */ + uint8_t opacity; /* < Opacity. The value ranges from 0 to 255. */ +} VGUGradient; + +/* * + * @brief Defines a solid color. + * + */ +typedef struct { + uint32_t color; /* < Solid color */ + uint8_t opacity; /* < Opacity. The value ranges from 0 to 255. */ +} VGUSolid; + +/* * + * @brief Enumerates paint types. + * + */ +typedef enum { + VGU_PAINT_SOLID = 0, /* < Paint a solid color. */ + VGU_PAINT_GRADIENT, /* < Paint a gradient object. */ + VGU_PAINT_PATTERN, /* < Paint a pattern. */ + VGU_PAINT_BUTT /* < Invalid operation */ +} VGUPaintType; + +/* * + * @brief Defines the paint style when filling or stroking a path. + * + */ +typedef struct { + union { + VGUGradient *gradient; /* < Pointer to the gradient object */ + VGUPattern *pattern; /* < Pointer to the pattern object */ + VGUSolid *solid; /* < Pointer to the solid color object */ + }; + VGUPaintType type; /* < Paint type */ +} VGUPaintStyle; + +/* * + * @brief Defines path filling attributes. + * + */ +typedef struct { + VGUFillRule rule; /* < Fill rule */ +} VGUFillAttr; + +/* * + * @brief Defines path stroking attributes. + * + */ +typedef struct { + VGULineCap cap; /* < Line cap style */ + VGUJointType join; /* < Join type */ + float miterLimit; /* < Miter limit */ + float width; /* < Line width */ +} VGUStrokeAttr; + +/* * + * @brief Defines driver functions for 2D hardware acceleration. + */ +typedef struct { + /* * + * @brief Initializes hardware acceleration. + * + * @return Returns VGU_SUCCESS if the operation is successful; returns an error code defined in + * {@link VGUResult} otherwise. + * @see DeinitVgu + * @since 3.0 + */ + VGUResult (*InitVgu)(void); + + /* * + * @brief Deinitializes hardware acceleration. + * + * @return Returns VGU_SUCCESS if the operation is successful; returns an error code defined in + * {@link VGUResult} otherwise. + * @see InitVgu + * @since 3.0 + */ + VGUResult (*DeinitVgu)(void); + + /* * + * @brief Queries hardware acceleration capabilities. + * + * @param cap Indicates the capabilities to query, which are defined by VGUCapability. + * + * @return Returns a value greater than or equal to 0 if the operation is successful; returns an error code defined + * in {@link VGUResult} otherwise. + * @since 3.0 + */ + int32_t (*QueryCapability)(uint32_t cap); + + /* * + * @brief Fills the given path with a specified paint style. + * + * @param target Indicates the pointer to the target surface. + * @param path Indicates the pointer to the path object. + * @param matrix Indicates the pointer to the transformation matrix object. If this parameter is null, + * the identity matrix is used by default. + * @param attr Indicates the pointer to the path filling attributes. + * @param style Indicates the pointer to the paint style to use. + * + * @return Returns VGU_SUCCESS if the operation is successful; returns an error code defined in + * {@link VGUResult} otherwise. + * @since 3.0 + */ + VGUResult (*RenderFill)(VGUSurface *target, const VGUPath *path, const VGUMatrix3 *matrix, const VGUFillAttr *attr, + const VGUPaintStyle *style); + + /* * + * @brief Strokes the given path with a specified paint style. + * + * @param target Indicates the pointer to the target surface. + * @param path Indicates the pointer to the path object. + * @param matrix Indicates the pointer to the transformation matrix object. If this parameter is null, + * the identity matrix is used by default. + * @param attr Indicates the pointer to the path stroking attributes. + * @param style Indicates the pointer to the paint style to use. + * + * @return Returns VGU_SUCCESS if the operation is successful; returns an error code defined in + * {@link VGUResult} otherwise. + * @since 3.0 + */ + VGUResult (*RenderStroke)(VGUSurface *target, const VGUPath *path, const VGUMatrix3 *matrix, + const VGUStrokeAttr *attr, const VGUPaintStyle *style); + + /* * + * @brief Blurs a specified surface. + * + * @param target Indicates the pointer to the target surface. + * @param blur Indicates the blur radius. + * + * @return Returns VGU_SUCCESS if the operation is successful; returns an error code defined in + * {@link VGUResult} otherwise. + * @since 3.0 + */ + VGUResult (*RenderBlur)(VGUSurface *target, uint16_t blur); + + /* * + * @brief Blits an image to the target surface. + * + * During bit blit, color space conversion (CSC) and transformation can be implemented. + * + * @param target Indicates the pointer to the target surface. + * @param src Indicates the pointer to the source image. + * @param color Indicates the color for blending. If this parameter is 0, color blending is not performed. + * + * @return Returns VGU_SUCCESS if the operation is successful; returns an error code defined in + * {@link VGUResult} otherwise. + * @since 3.0 + */ + VGUResult (*RenderBlit)(VGUSurface *target, const VGUImage *src, uint32_t color); + + /* * + * @brief Blits multiple images to the target surface. + * + * During bit blit, color space conversion (CSC) and transformation can be implemented. You can use this + * function to combine multiple source images to the target surface. + * To query the maximum number of source images allowed, call the QueryCapability function. + * + * @param target Indicates the pointer to the target surface. + * @param src Indicates the pointer to the array of source images. + * @param count Indicates the number of source images. + * @param color Indicates the color for blending. If this parameter is 0, color blending is not performed. + * + * @return Returns VGU_SUCCESS if the operation is successful; returns an error code defined in + * {@link VGUResult} otherwise. + * @since 3.0 + */ + VGUResult (*RenderBlitN)(VGUSurface *target, const VGUImage *src, uint16_t count, uint32_t color); + + /* * + * @brief Clears a rectangle with a given color on the target surface. + * + * @param target Indicates the pointer to the target surface. + * @param rect Indicates the pointer to the rectangle to clear. If this parameter is null, the entire surface + * will be cleared. + * @param color Indicates the color to fill. + * @param opacity Indicates the opacity to set. + * + * @return Returns VGU_SUCCESS if the operation is successful; returns an error code defined in + * {@link VGUResult} otherwise. + * @since 3.0 + */ + VGUResult (*RenderClearRect)(VGUSurface *target, const VGURect *rect, uint32_t color, uint8_t opacity); + + /* * + * @brief Disables hardware acceleration for rendering. + * + * @return Returns VGU_SUCCESS if the operation is successful; returns an error code defined in + * {@link VGUResult} otherwise. + * @since 3.0 + */ + VGUResult (*RenderCancel)(); + + /* * + * @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 keeps waiting until hardware acceleration is complete. + * + * @return Returns VGU_SUCCESS if the operation is successful; returns an error code defined in + * {@link VGUResult} otherwise. + * @since 3.0 + */ + VGUResult (*RenderSync)(int32_t timeOut); +} VGUFuncs; + +/* * + * @brief Initializes a path object. + * + * @param path Indicates the pointer to the path object. + * @param type Indicates the data type of the path. + * @param segments Indicates the pointer to the path commands. + * @param numSegments Indicates the total number of path commands. + * @param data Indicates the pointer to the coordinate data used in the path commands. + * @param enAlias Specifies whether to enable anti-aliasing. + * @param boundBox Indicates the bounding box of the path. + * + * @return Returns VGU_SUCCESS if the operation is successful; returns an error code defined in + * {@link VGUResult} otherwise. + * @since 3.0 + */ +VGUResult VGUPathInit(VGUPath *path, VGUPathDataType type, const uint8_t* segments, int numSegments, + const uint8_t *data, bool enAlias, VGURect boundBox); + +/* * + * @brief Adds a subpath to a specified path. + * + * @param path Indicates the pointer to the path object. + * @param subpath Indicates the pointer to the subpath object. + * + * @return Returns VGU_SUCCESS if the operation is successful; returns an error code defined in + * {@link VGUResult} otherwise. + * @since 3.0 + */ +VGUResult VGUPathAppend(VGUPath *path, const VGUPath *subpath); + +/* * + * @brief Clears the memory of a specified path object. + * + * @param path Indicates the pointer to the path object. + * + * @return Returns VGU_SUCCESS if the operation is successful; returns an error code defined in + * {@link VGUResult} otherwise. + * @since 3.0 + */ +VGUResult VGUPathClear(VGUPath *path); + +/* * + * @brief Loads an identity matrix into a specified matrix object. + * + * @param matrix Indicates the pointer to the transformation matrix object. + * + * @return Returns VGU_SUCCESS if the operation is successful; returns an error code defined in + * {@link VGUResult} otherwise. + * @since 3.0 + */ +VGUResult VGUMatrixIdentity(VGUMatrix3 *matrix); + +/* * + * @brief Scales a specified transformation matrix. + * + * @param matrix Indicates the pointer to the transformation matrix object. + * @param xScale Indicates how much you want to scale the horizontal coordinate by. + * @param yScale Indicates how much you want to scale the vertical coordinate by. + * + * @return Returns VGU_SUCCESS if the operation is successful; returns an error code defined in + * {@link VGUResult} otherwise. + * @since 3.0 + */ +VGUResult VGUMatrixScale(VGUMatrix3 *matrix, float xScale, float yScale); + +/* * + * @brief Rotates a specified transformation matrix. + * + * @param matrix Indicates the pointer to the transformation matrix object. + * @param degree Indicates the number of degrees to rotate. + * + * @return Returns VGU_SUCCESS if the operation is successful; returns an error code defined in + * {@link VGUResult} otherwise. + * @since 3.0 + */ +VGUResult VGUMatrixRotate(VGUMatrix3 *matrix, float degree); + +/* * + * @brief Translates a specified transformation matrix. + * + * @param matrix Indicates the pointer to the transformation matrix object. + * @param x Indicates how much you want to translate the horizontal coordinate by. + * @param y Indicates how much you want to translate the vertical coordinate by. + * + * @return Returns VGU_SUCCESS if the operation is successful; returns an error code defined in + * {@link VGUResult} otherwise. + * @since 3.0 + */ +VGUResult VGUMatrixTranslate(VGUMatrix3 *matrix, float x, float y); + +/* * + * @brief Adds color stops to a specified gradient. + * + * @param gradient Indicates the pointer to the gradient object. + * @param colorStop Indicates the pointer to the color stop array. + * @param count Indicates the total number of color stops. + * + * @return Returns VGU_SUCCESS if the operation is successful; returns an error code defined in + * {@link VGUResult} otherwise. + * @since 3.0 + */ +VGUResult VGUGradientColorStop(VGUGradient *gradient, const VGUColorStop *colorStop, uint32_t count); + +/* * + * @brief Clears color stops of a specified gradient. + * + * @param gradient Indicates the pointer to the gradient object. + * + * @return Returns VGU_SUCCESS if the operation is successful; returns an error code defined in + * {@link VGUResult} otherwise. + * @since 3.0 + */ +VGUResult VGUGradientClearStop(VGUGradient *gradient); + +/* * + * @brief Sets a transformation matrix for a specified gradient. + * + * @param gradient Indicates the pointer to the gradient object. + * @param matrix Indicates the pointer to the transformation matrix object to set. + * + * @return Returns VGU_SUCCESS if the operation is successful; returns an error code defined in + * {@link VGUResult} otherwise. + * @since 3.0 + */ +VGUResult VGUGradientMatrix(VGUGradient *gradient, const VGUMatrix3 *matrix); + +/* * + * @brief Creates a linear gradient object. + * + * @param gradient Indicates the pointer to the gradient object. + * @param p1 Indicates the pointer to the coordinates of the start point. + * @param p2 Indicates the pointer to the coordinates of the end point. + * + * @return Returns VGU_SUCCESS if the operation is successful; returns an error code defined in + * {@link VGUResult} otherwise. + * @since 3.0 + */ +VGUResult VGUGradientLinear(VGUGradient *gradient, const VGUPoint *p1, const VGUPoint *p2); + +/* * + * @brief Creates a radial gradient object. + * + * @param gradient Indicates the pointer to the gradient object. + * @param p1 Indicates the pointer to the center point coordinates of the inner circle. + * @param r1 Indicates the radius of the inner circle. + * @param p2 Indicates the pointer to the center point coordinates of the outer circle. + * @param r2 Indicates the radius of the outer circle. + * + * @return Returns VGU_SUCCESS if the operation is successful; returns an error code defined in + * {@link VGUResult} otherwise. + * @since 3.0 + */ +VGUResult VGUGradientRadial(VGUGradient *gradient, const VGUPoint *p1, VGUScalar r1, const VGUPoint *p2, VGUScalar r2); + +/* * + * @brief Creates a conic gradient object. + * + * @param gradient Indicates the pointer to the gradient object. + * @param cx Indicates the horizontal coordinate of the center point of the gradient. + * @param cy Indicates the vertical coordinate of the center point of the gradient. + * + * @return Returns VGU_SUCCESS if the operation is successful; returns an error code defined in + * {@link VGUResult} otherwise. + * @since 3.0 + */ +VGUResult VGUGradientConic(VGUGradient *gradient, VGUScalar cx, VGUScalar cy); + +/* * + * @brief Initializes the hardware acceleration module to obtain the pointer to functions for + * hardware acceleration operations. + * + * @param funcs Indicates the double pointer to the 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 VGU_SUCCESS if the operation is successful; returns an error code defined in + * {@link VGUResult} otherwise. + * + * @since 3.0 + */ +VGUResult VGUInitialize(VGUFuncs **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 VGU_SUCCESS if the operation is successful; returns an error code defined in + * {@link VGUResult} otherwise. + * @since 3.0 + */ +VGUResult VGUUninitialize(VGUFuncs *funcs); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/display/interfaces_lite/include/display_gfx.h b/display/interfaces_lite/include/display_gfx.h new file mode 100644 index 0000000000..1b9e770fc3 --- /dev/null +++ b/display/interfaces_lite/include/display_gfx.h @@ -0,0 +1,196 @@ +/* + * 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 "display_type.h" + +#ifdef __cplusplus +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); + +#ifdef __cplusplus +} +#endif +#endif +/** @} */ diff --git a/display/interfaces_lite/include/display_gralloc.h b/display/interfaces_lite/include/display_gralloc.h new file mode 100644 index 0000000000..7ab76c9d53 --- /dev/null +++ b/display/interfaces_lite/include/display_gralloc.h @@ -0,0 +1,163 @@ +/* + * 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 "display_type.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Defines pointers to the memory driver functions. + */ +typedef struct { + /** + * @brief Allocates memory based on the parameters passed by the GUI. + * + * The allocated memory can be classified into shared memory, memory with cache, and memory without cache. + * + * @param buffer 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 + */ + int32_t (*AllocMem)(GrallocBuffer *buffer); + + /** + * @brief Releases memory. + * + * @param buffer Indicates the pointer to the buffer of the memory to release. + * + * @since 1.0 + * @version 1.0 + */ + void (*FreeMem)(GrallocBuffer *buffer); + + /** + * @brief Maps memory to memory without cache in the process's address space. + * + * @param buffer 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)(GrallocBuffer *buffer); + + /** + * @brief Maps memory to memory with cache in the process's address space. + * + * @param buffer 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)(GrallocBuffer *buffer); + + /** + * @brief Unmaps memory, that is, removes any mappings in the process's address space. + * + * @param buffer 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)(GrallocBuffer *buffer); + + /** + * @brief Flushes data from the cache to memory and invalidates the data in the cache. + * + * @param buffer 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)(GrallocBuffer *buffer); + + /** + * @brief Flushes data from the cache mapped via {@link Mmap} to memory and invalidates the data in the cache. + * + * @param buffer 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)(GrallocBuffer *buffer); +} 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); + +#ifdef __cplusplus +} +#endif +#endif +/** @} */ diff --git a/display/interfaces_lite/include/display_layer.h b/display/interfaces_lite/include/display_layer.h new file mode 100644 index 0000000000..1e0b848295 --- /dev/null +++ b/display/interfaces_lite/include/display_layer.h @@ -0,0 +1,575 @@ +/* + * 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 1.0 + */ + +/** + * @file display_layer.h + * + * @brief Declares the driver functions for implementing layer operations. + * + * @since 1.0 + * @version 2.0 + */ + +#ifndef DISPLAY_LAYTER_H +#define DISPLAY_LAYTER_H +#include "display_type.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Defines pointers to the layer driver functions. + */ +typedef struct { + /** + * @brief Initializes a display device. + * + * @param devId Indicates the ID of a display device. The value ranges from 0 to 4, where 0 indicates the first + * display device and 4 indicates the last display device. + * + * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} + * otherwise. + * @see DeinitDisplay + * @since 1.0 + * @version 1.0 + */ + int32_t (*InitDisplay)(uint32_t devId); + + /** + * @brief Deinitializes a display device. + * + * @param devId Indicates the ID of a display device. The value ranges from 0 to 4, where 0 indicates the first + * display device and 4 indicates the last display device. + * + * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} + * otherwise. + * @see InitDisplay + * @since 1.0 + * @version 1.0 + */ + int32_t (*DeinitDisplay)(uint32_t devId); + + /** + * @brief Obtains information about a display device. + * + * @param devId Indicates the ID of a display device. The value ranges from 0 to 4, where 0 indicates the first + * display device and 4 indicates the last display device. + * @param dispInfo Indicates the pointer to the display device information obtained. + * + * @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 (*GetDisplayInfo)(uint32_t devId, DisplayInfo *dispInfo); + + /** + * @brief Opens a layer on a specified display device. + * + * Before using a layer on the GUI, you must open the layer based on the layer information. After the layer is + * opened, you can obtain the layer ID and then use other functions based on the layer ID. + * + * @param devId Indicates the ID of a display device. The value ranges from 0 to 4, where 0 indicates the first + * display device and 4 indicates the last display device. + * @param layerInfo Indicates the pointer to the layer information passed to open a layer, including the layer + * type, layer size, and pixel format. + * @param layerId Indicates the pointer to the layer ID, which identifies a unique layer. The layer ID is returned + * to the GUI after the layer is successfully opened. + * + * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} + * otherwise. + * @see CloseLayer + * @since 1.0 + * @version 1.0 + */ + int32_t (*OpenLayer)(uint32_t devId, const LayerInfo *layerInfo, uint32_t *layerId); + + /** + * @brief Closes a layer that is no longer required on a specified display device. + * + * @param devId Indicates the ID of a display device. The value ranges from 0 to 4, where 0 indicates the first + * display device and 4 indicates the last display device. + * @param layerId Indicates the layer ID, which identifies a unique layer. You can perform operations on the layer + * with the specified layer ID. + * + * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} + * otherwise. + * @see OpenLayer + * @since 1.0 + * @version 1.0 + */ + int32_t (*CloseLayer)(uint32_t devId, uint32_t layerId); + + /** + * @brief Sets whether a layer is visible. + * + * A visible layer is displayed on the screen, whereas an invisible layer is not displayed on the screen. + * + * @param devId Indicates the ID of a display device. The value ranges from 0 to 4, where 0 indicates the first + * display device and 4 indicates the last display device. + * @param layerId Indicates the layer ID, which identifies a unique layer. You can perform operations on the layer + * with the specified layer ID. + * @param visible Indicates the visibility to set for the layer. The value true means to set the layer to be + * visible, and false means the opposite. + * + * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} + * otherwise. + * @see GetLayerVisibleState + * @since 1.0 + * @version 1.0 + */ + int32_t (*SetLayerVisible)(uint32_t devId, uint32_t layerId, bool visible); + + /** + * @brief Checks whether a layer is visible. + * + * @param devId Indicates the ID of a display device. The value ranges from 0 to 4, where 0 indicates the first + * display device and 4 indicates the last display device. + * @param layerId Indicates the layer ID, which identifies a unique layer. You can perform operations on the layer + * with the specified layer ID. + * @param visible Indicates the pointer to the obtained layer visibility. The value true indicates that the + * layer is visible, and false indicates that the layer is invisible. + * + * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} + * otherwise. + * @see SetLayerVisible + * @since 1.0 + * @version 1.0 + */ + int32_t (*GetLayerVisibleState)(uint32_t devId, uint32_t layerId, bool *visible); + + /** + * @brief Sets the size of a layer. + * + * @param devId Indicates the ID of a display device. The value ranges from 0 to 4, where 0 indicates the first + * display device and 4 indicates the last display device. + * @param layerId Indicates the layer ID, which identifies a unique layer. You can perform operations on the layer + * with the specified layer ID. + * @param rect Indicates the pointer to the layer size to set, in pixels. + * + * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} + * otherwise. + * @see GetLayerSize + * @since 1.0 + * @version 1.0 + */ + int32_t (*SetLayerSize)(uint32_t devId, uint32_t layerId, IRect *rect); + + /** + * @brief Obtains the size of a layer. + * + * @param devId Indicates the ID of a display device. The value ranges from 0 to 4, where 0 indicates the first + * display device and 4 indicates the last display device. + * @param layerId Indicates the layer ID, which identifies a unique layer. You can perform operations on the layer + * with the specified layer ID. + * @param rect Indicates the pointer to the obtained layer size. + * + * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} + * otherwise. + * @see SetLayerSize + * @since 1.0 + * @version 1.0 + */ + int32_t (*GetLayerSize)(uint32_t devId, uint32_t layerId, IRect *rect); + + /** + * @brief Sets the rectangular area to crop for a layer. + * + * @param devId Indicates the ID of a display device. The value ranges from 0 to 4, where 0 indicates the first + * display device and 4 indicates the last display device. + * @param layerId Indicates the layer ID, which identifies a unique layer. You can perform operations on the layer + * with the specified layer ID. + * @param rect Indicates the pointer to the rectangular area to crop. + * + * @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 (*SetLayerCrop)(uint32_t devId, uint32_t layerId, IRect *rect); + + /** + * @brief Sets the z-order for a layer. + * + * A larger z-order value indicates a higher layer. + * + * @param devId Indicates the ID of a display device. The value ranges from 0 to 4, where 0 indicates the first + * display device and 4 indicates the last display device. + * @param layerId Indicates the layer ID, which identifies a unique layer. You can perform operations on the layer + * with the specified layer ID. + * @param zorder Indicates the z-order to set. The value is an integer ranging from 0 to 255. + * + * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} + * otherwise. + * @see GetLayerZorder + * @since 1.0 + * @version 1.0 + */ + int32_t (*SetLayerZorder)(uint32_t devId, uint32_t layerId, uint32_t zorder); + + /** + * @brief Obtains the z-order of a layer. + * + * @param devId Indicates the ID of a display device. The value ranges from 0 to 4, where 0 indicates the first + * display device and 4 indicates the last display device. + * @param layerId Indicates the layer ID, which identifies a unique layer. You can perform operations on the layer + * with the specified layer ID. + * @param zorder Indicates the pointer to the obtained z-order. The value is an integer ranging from 0 to 255. + * A larger z-order value indicates a higher layer. + * + * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} + * otherwise. + * @see SetLayerZorder + * @since 1.0 + * @version 1.0 + */ + int32_t (*GetLayerZorder)(uint32_t devId, uint32_t layerId, uint32_t *zorder); + + /** + * @brief Sets layer premultiplication. + * + * @param devId Indicates the ID of a display device. The value ranges from 0 to 4, where 0 indicates the first + * display device and 4 indicates the last display device. + * @param layerId Indicates the layer ID, which identifies a unique layer. You can perform operations on the layer + * with the specified layer ID. + * @param preMul Specifies whether to enable layer premultiplication. The value 1 means to enable layer + * premultiplication, and 0 means the opposite. + * + * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} + * otherwise. + * @see GetLayerPreMulti + * @since 1.0 + * @version 1.0 + */ + int32_t (*SetLayerPreMulti)(uint32_t devId, uint32_t layerId, bool preMul); + + /** + * @brief Obtains the premultiplication flag of a layer. + * + * @param devId Indicates the ID of a display device. The value ranges from 0 to 4, where 0 indicates the first + * display device and 4 indicates the last display device. + * @param layerId Indicates the layer ID, which identifies a unique layer. You can perform operations on the layer + * with the specified layer ID. + * @param preMul Indicates the pointer to the obtained layer premultiplication flag. + * + * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} + * otherwise. + * @see SetLayerPreMulti + * @since 1.0 + * @version 1.0 + */ + int32_t (*GetLayerPreMulti)(uint32_t devId, uint32_t layerId, bool *preMul); + + /** + * @brief Sets the alpha value for a layer. + * + * @param devId Indicates the ID of a display device. The value ranges from 0 to 4, where 0 indicates the first + * display device and 4 indicates the last display device. + * @param layerId Indicates the layer ID, which identifies a unique layer. You can perform operations on the layer + * with the specified layer ID. + * @param alpha Indicates the pointer to the alpha value to set. + * + * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} + * otherwise. + * @see GetLayerAlpha + * @since 1.0 + * @version 1.0 + */ + int32_t (*SetLayerAlpha)(uint32_t devId, uint32_t layerId, LayerAlpha *alpha); + + /** + * @brief Obtains the alpha value of a layer. + * + * @param devId Indicates the ID of a display device. The value ranges from 0 to 4, where 0 indicates the first + * display device and 4 indicates the last display device. + * @param layerId Indicates the layer ID, which identifies a unique layer. You can perform operations on the layer + * with the specified layer ID. + * @param alpha Indicates the pointer to the obtained alpha value. + * + * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} + * otherwise. + * @see SetLayerAlpha + * @since 1.0 + * @version 1.0 + */ + int32_t (*GetLayerAlpha)(uint32_t devId, uint32_t layerId, LayerAlpha *alpha); + + /** + * @brief Sets the color key for a layer. The color key is used during layer overlay. + * + * @param devId Indicates the ID of a display device. The value ranges from 0 to 4, where 0 indicates the first + * display device and 4 indicates the last display device. + * @param layerId Indicates the layer ID, which identifies a unique layer. You can perform operations on the layer + * with the specified layer ID. + * @param enable Specify whether to enable the color key. + * @param key Indicates the color key. + * + * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} + * otherwise. + * @see GetLayerColorKey + * @since 1.0 + * @version 1.0 + */ + int32_t (*SetLayerColorKey)(uint32_t devId, uint32_t layerId, bool enable, uint32_t key); + + /** + * @brief Obtains the color key of a layer. + * + * @param devId Indicates the ID of a display device. The value ranges from 0 to 4, where 0 indicates the first + * display device and 4 indicates the last display device. + * @param layerId Indicates the layer ID, which identifies a unique layer. You can perform operations on the layer + * with the specified layer ID. + * @param enable Indicates the pointer to the color key enable bit. + * @param key Indicates the pointer to the color key. + * + * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} + * otherwise. + * @see SetLayerColorKey + * @since 1.0 + * @version 1.0 + */ + int32_t (*GetLayerColorKey)(uint32_t devId, uint32_t layerId, bool *enable, uint32_t *key); + + /** + * @brief Sets the palette for a layer. + * + * @param devId Indicates the ID of a display device. The value ranges from 0 to 4, where 0 indicates the first + * display device and 4 indicates the last display device. + * @param layerId Indicates the layer ID, which identifies a unique layer. You can perform operations on the layer + * with the specified layer ID. + * @param palette Indicates the pointer to the palette to set. + * @param len Indicates the length of the palette. + * + * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} + * otherwise. + * @see GetLayerPalette + * @since 1.0 + * @version 1.0 + */ + int32_t (*SetLayerPalette)(uint32_t devId, uint32_t layerId, uint32_t *palette, uint32_t len); + + /** + * @brief Obtains the palette of a layer. + * + * @param devId Indicates the ID of a display device. The value ranges from 0 to 4, where 0 indicates the first + * display device and 4 indicates the last display device. + * @param layerId Indicates the layer ID, which identifies a unique layer. You can perform operations on the layer + * with the specified layer ID. + * @param palette Indicates the pointer to the obtained palette. + * @param len Indicates the length of the palette. + * + * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} + * otherwise. + * @see SetLayerPalette + * @since 1.0 + * @version 1.0 + */ + int32_t (*GetLayerPalette)(uint32_t devId, uint32_t layerId, uint32_t *palette, uint32_t len); + + /** + * @brief Sets the transform mode for rotating, scaling, or moving a layer. + * + * @param devId Indicates the ID of a display device. The value ranges from 0 to 4, where 0 indicates the first + * display device and 4 indicates the last display device. + * @param layerId Indicates the layer ID, which identifies a unique layer. You can perform operations on the layer + * with the specified layer ID. + * @param type Indicates the transformation mode to set. + * + * @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 (*SetTransformMode)(uint32_t devId, uint32_t layerId, TransformType type); + + /** + * @brief Sets the compression feature for a layer. + * + * In specific scenarios, images need to be compressed. You can set whether to enable layer compression. + * + * @param devId Indicates the ID of a display device. The value ranges from 0 to 4, where 0 indicates the first + * display device and 4 indicates the last display device. + * @param layerId Indicates the layer ID, which identifies a unique layer. You can perform operations on the layer + * with the specified layer ID. + * @param compType Specifies whether to enable the compression feature. The value true>/b> means to enable + * compression, and false> means the opposite. + * + * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} + * otherwise. + * @see GetLayerCompression + * @since 1.0 + * @version 1.0 + */ + int32_t (*SetLayerCompression)(uint32_t devId, uint32_t layerId, int32_t compType); + + /** + * @brief Checks whether the compression feature is enabled for a layer. + * + * @param devId Indicates the ID of a display device. The value ranges from 0 to 4, where 0 indicates the first + * display device and 4 indicates the last display device. + * @param layerId Indicates the layer ID, which identifies a unique layer. You can perform operations on the layer + * with the specified layer ID. + * @param compType Indicates the pointer to the variable specifying whether the compression feature is enabled. + * + * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} + * otherwise. + * @see SetLayerCompression + * @since 1.0 + * @version 1.0 + */ + int32_t (*GetLayerCompression)(uint32_t devId, uint32_t layerId, int32_t *compType); + + /** + * @brief Sets the flushing area for a layer. + * + * After the GUI draws an image, you must set the layer flushing area before calling the {@link Flush} function to + * flush the screen. + * + * @param devId Indicates the ID of a display device. The value ranges from 0 to 4, where 0 indicates the first + * display device and 4 indicates the last display device. + * @param layerId Indicates the layer ID, which identifies a unique layer. You can perform operations on the layer + * with the specified layer ID. + * @param region Indicates the pointer to the flushing area to set. + * + * @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 (*SetLayerDirtyRegion)(uint32_t devId, uint32_t layerId, IRect *region); + + /** + * @brief Obtains the buffer of a layer. + * + * After drawing a picture in the buffer, the application calls the {@link Flush} function to display the picture + * on the screen. + * + * @param devId Indicates the ID of a display device. The value ranges from 0 to 4, where 0 indicates the first + * display device and 4 indicates the last display device. + * @param layerId Indicates the layer ID, which identifies a unique layer. You can perform operations on the layer + * with the specified layer ID. + * @param buffer Indicates the pointer to the obtained buffer. + * + * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} + * otherwise. + * @see Flush + * @since 1.0 + * @version 1.0 + */ + int32_t (*GetLayerBuffer)(uint32_t devId, uint32_t layerId, LayerBuffer *buffer); + + /** + * @brief Flushes a layer. + * + * Display data in the buffer is flushed to a specified layer so that the image data is displayed on the screen. + * + * @param devId Indicates the ID of a display device. The value ranges from 0 to 4, where 0 indicates the first + * display device and 4 indicates the last display device. + * @param layerId Indicates the layer ID, which identifies a unique layer. You can perform operations on the layer + * with the specified layer ID. + * @param buffer Indicates the pointer to the buffer in which the display data is 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 (*Flush)(uint32_t devId, uint32_t layerId, LayerBuffer *buffer); + + /** + * @brief Waits for the arrival of vertical blanking. + * + * This function blocks the process until vertical blanking arrives, implementing the synchronization between + * software and hardware. + * + * @param devId Indicates the ID of a display device. The value ranges from 0 to 4, where 0 indicates the first + * display device and 4 indicates the last display device. + * @param layerId Indicates the layer ID, which identifies a unique layer. You can perform operations on the layer + * with the specified layer ID. + * @param timeOut Indicates the maximum duration that the process waits for the arrival of vertical blanking. + * + * @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 (*WaitForVBlank)(uint32_t devId, uint32_t layerId, int32_t timeOut); + + /** + * @brief Implements the snapshot feature. + * + * This function saves the screenshot of image data on the display device to the buffer for debugging or as + * requested by applications. + * + * @param devId Indicates the ID of a display device. The value ranges from 0 to 4, where 0 indicates the first + * display device and 4 indicates the last display device. + * @param buffer Indicates the pointer to the buffer for saving screenshots. + * + * @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 (*SnapShot)(uint32_t devId, LayerBuffer *buffer); +} LayerFuncs; + +/** + * @brief Initializes the layer to apply for resources used by the layer and obtain the pointer to functions for + * layer operations. + * + * @param funcs Indicates the double pointer to functions for layer operations. Memory is allocated automatically when + * you initiate the layer 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. + * @see LayerUninitialize + * @since 1.0 + * @version 1.0 + */ +int32_t LayerInitialize(LayerFuncs **funcs); + +/** + * @brief Deinitializes the layer module to release the memory allocated to the pointer to functions for + * layer operations. + * + * @param funcs Indicates the pointer to functions for layer operations. + * + * @return Returns 0 if the operation is successful; returns an error code defined in {@link DispErrCode} + * otherwise. + * @see LayerInitialize + * @since 1.0 + * @version 1.0 + */ +int32_t LayerUninitialize(LayerFuncs *funcs); + +#ifdef __cplusplus +} +#endif +#endif +/** @} */ diff --git a/display/interfaces_lite/include/display_type.h b/display/interfaces_lite/include/display_type.h new file mode 100644 index 0000000000..17960ff11e --- /dev/null +++ b/display/interfaces_lite/include/display_type.h @@ -0,0 +1,397 @@ +/* + * 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_type.h + * + * @brief Declares the data types used by the display driver functions. + * + * @since 1.0 + * @version 2.0 + */ + +#ifndef DISPLAY_TYPE_H +#define DISPLAY_TYPE_H +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Enumerates return values of the functions. + * + */ +typedef enum { + DISPLAY_SUCCESS = 0, /**< Success */ + DISPLAY_FAILURE = -1, /**< Failure */ + DISPLAY_FD_ERR = -2, /**< File handle (FD) error */ + DISPLAY_PARAM_ERR = -3, /**< Parameter error */ + DISPLAY_NULL_PTR = -4, /**< Null pointer */ + DISPLAY_NOT_SUPPORT = -5, /**< Unsupported feature */ + DISPLAY_NOMEM = -6, /**< Insufficient memory */ + DISPLAY_SYS_BUSY = -7, /**< System busy */ + DISPLAY_NOT_PERM = -8 /**< Forbidden operation */ +} DispErrCode; + +/** + * @brief Enumerates layer types. + * + */ +typedef enum { + LAYER_TYPE_GRAPHIC, /* < Graphic layer */ + LAYER_TYPE_OVERLAY, /* < Overlay layer */ + LAYER_TYPE_SDIEBAND, /* < Sideband layer */ + LAYER_TYPE_BUTT /* < Empty layer */ +} LayerType; + +/** + * @brief Enumerates pixel formats. + * + */ +typedef enum { + PIXEL_FMT_CLUT8 = 0, /**< CLUT8 format */ + PIXEL_FMT_CLUT1, /**< CLUT1 format */ + PIXEL_FMT_CLUT4, /**< CLUT4 format */ + PIXEL_FMT_RGB_565, /**< RGB565 format */ + PIXEL_FMT_RGBA_5658, /**< RGBA5658 format */ + PIXEL_FMT_RGBX_4444, /**< RGBX4444 format */ + PIXEL_FMT_RGBA_4444, /**< RGBA4444 format */ + PIXEL_FMT_RGB_444, /**< RGB444 format */ + PIXEL_FMT_RGBX_5551, /**< RGBX5551 format */ + PIXEL_FMT_RGBA_5551, /**< RGBA5551 format */ + PIXEL_FMT_RGB_555, /**< RGB555 format */ + PIXEL_FMT_RGBX_8888, /**< RGBX8888 format */ + PIXEL_FMT_RGBA_8888, /**< RGBA8888 format */ + PIXEL_FMT_RGB_888, /**< RGB888 format */ + PIXEL_FMT_BGR_565, /**< BGR565 format */ + PIXEL_FMT_BGRX_4444, /**< BGRX4444 format */ + PIXEL_FMT_BGRA_4444, /**< BGRA4444 format */ + PIXEL_FMT_BGRX_5551, /**< BGRX5551 format */ + PIXEL_FMT_BGRA_5551, /**< BGRA5551 format */ + PIXEL_FMT_BGRX_8888, /**< BGRX8888 format */ + PIXEL_FMT_BGRA_8888, /**< BGRA8888 format */ + PIXEL_FMT_YUV_422_I, /**< YUV422 interleaved format */ + PIXEL_FMT_YCBCR_422_SP, /**< YCBCR422 semi-planar format */ + PIXEL_FMT_YCRCB_422_SP, /**< YCRCB422 semi-planar format */ + PIXEL_FMT_YCBCR_420_SP, /**< YCBCR420 semi-planar format */ + PIXEL_FMT_YCRCB_420_SP, /**< YCRCB420 semi-planar format */ + PIXEL_FMT_YCBCR_422_P, /**< YCBCR422 planar format */ + PIXEL_FMT_YCRCB_422_P, /**< YCRCB422 planar format */ + PIXEL_FMT_YCBCR_420_P, /**< YCBCR420 planar format */ + PIXEL_FMT_YCRCB_420_P, /**< YCRCB420 planar format */ + PIXEL_FMT_YUYV_422_PKG, /**< YUYV422 packed format */ + PIXEL_FMT_UYVY_422_PKG, /**< UYVY422 packed format */ + PIXEL_FMT_YVYU_422_PKG, /**< YVYU422 packed format */ + PIXEL_FMT_VYUY_422_PKG, /**< VYUY422 packed format */ + PIXEL_FMT_BUTT /**< Invalid pixel format */ +} PixelFormat; + +/** + * @brief Enumerates transform types of images. + * + */ +typedef enum { + ROTATE_NONE = 0, /**< No rotation */ + ROTATE_90, /**< Rotation by 90 degrees */ + ROTATE_180, /**< Rotation by 180 degrees */ + ROTATE_270, /**< Rotation by 270 degrees */ + ROTATE_BUTT /**< Invalid operation */ +} TransformType; + +/** + * @brief Enumerates memory types. + * + * Memory is allocated based on the type specified by the GUI. + * + */ +typedef enum { + NORMAL_MEM = 0, /* < Memory without cache */ + CACHE_MEM, /* < Memory with cache */ + SHM_MEM /* < Shared memory */ +} MemType; + +/** + * @brief Enumerates image blending types. + * + * The system combines images based on a specified blending type during hardware acceleration. + * + */ +typedef enum { + BLEND_NONE = 0, /**< No blending */ + BLEND_CLEAR, /**< CLEAR blending */ + BLEND_SRC, /**< SRC blending */ + BLEND_SRCOVER, /**< SRC_OVER blending */ + BLEND_DSTOVER, /**< DST_OVER blending */ + BLEND_SRCIN, /**< SRC_IN blending */ + BLEND_DSTIN, /**< DST_IN blending */ + BLEND_SRCOUT, /**< SRC_OUT blending */ + BLEND_DSTOUT, /**< DST_OUT blending */ + BLEND_SRCATOP, /**< SRC_ATOP blending */ + BLEND_DSTATOP, /**< DST_ATOP blending */ + BLEND_ADD, /**< ADD blending */ + BLEND_XOR, /**< XOR blending */ + BLEND_DST, /**< DST blending */ + BLEND_AKS, /**< AKS blending */ + BLEND_AKD, /**< AKD blending */ + BLEND_BUTT /**< Null operation */ +} BlendType; + +/** + * @brief Enumerates ROP types supported by hardware acceleration. + * + * ROP performs bitwise Boolean operations (including bitwise AND and bitwise OR) on the RGB color and + * alpha values of the foreground bitmap with those of the background bitmap, and then outputs the result. + * + */ +typedef enum { + ROP_BLACK = 0, /**< Blackness */ + ROP_NOTMERGEPEN, /**< ~(S2+S1) */ + ROP_MASKNOTPEN, /**< ~S2&S1 */ + ROP_NOTCOPYPEN, /**< ~S2 */ + ROP_MASKPENNOT, /**< S2&~S1 */ + ROP_NOT, /**< ~S1 */ + ROP_XORPEN, /**< S2^S1 */ + ROP_NOTMASKPEN, /**< ~(S2&S1) */ + ROP_MASKPEN, /**< S2&S1 */ + ROP_NOTXORPEN, /**< ~(S2^S1) */ + ROP_NOP, /**< S1 */ + ROP_MERGENOTPEN, /**< ~S2+S1 */ + ROP_COPYPE, /**< S2 */ + ROP_MERGEPENNOT, /**< S2+~S1 */ + ROP_MERGEPEN, /**< S2+S1 */ + ROP_WHITE, /**< Whiteness */ + ROP_BUTT /**< Invalid ROP type */ +} RopType; + +/** + * @brief Enumerates color key types supported by hardware acceleration. + * + */ +typedef enum { + CKEY_NONE = 0, /**< No color key */ + CKEY_SRC, /**< Source color key */ + CKEY_DST, /**< Destination color key */ + CKEY_BUTT /**< Null operation */ +} ColorKey; + +/** + * @brief Enumerates mirror types supported by hardware acceleration. + * + */ +typedef enum { + MIRROR_NONE = 0, /**< No mirror */ + MIRROR_LR, /**< Left and right mirrors */ + MIRROR_TB, /**< Top and bottom mirrors */ + MIRROR_BUTT /**< Null operation */ +} MirrorType; + +/** + * @brief Enumerates connection types of hot plugging. + * + */ +typedef enum { + INVALID = 0, /**< Invalid connection */ + CONNECTED, /**< Connected */ + DISCONNECTED /**< Disconnected */ +} Connection; + +/** + * @brief Defines display information. + * + */ +typedef struct { + uint32_t width; /**< Display width */ + uint32_t height; /**< Display height */ + int32_t rotAngle; /**< Rotation angle of the display */ +} DisplayInfo; + +/** + * @brief Defines layer information. + * + * LayerInfo must be passed to the {@link OpenLayer} function, which creates a layer based on the layer + * information. + * + */ +typedef struct { + int32_t width; /**< Layer width */ + int32_t height; /**< Layer height */ + LayerType type; /**< Layer type, which can be a graphic layer, overlay layer, or sideband layer */ + int32_t bpp; /**< Number of bits occupied by each pixel */ + PixelFormat pixFormat; /**< Pixel format of the layer */ +} LayerInfo; + +/** + * @brief Defines alpha information about a layer. + * + */ +typedef struct { + bool enGlobalAlpha; /**< Global alpha enable bit */ + bool enPixelAlpha; /**< Pixel alpha enable bit */ + uint8_t alpha0; /**< Alpha0 value, ranging from 0 to 255 */ + uint8_t alpha1; /**< Alpha1 value, ranging from 0 to 255 */ + uint8_t gAlpha; /**< Global alpha value, ranging from 0 to 255 */ +} LayerAlpha; + +/** + * @brief Defines the buffer handle, including the shared memory key, shared memory ID, and physical memory address. + * + */ +typedef struct { + int32_t key; /* < Shared memory key */ + int32_t shmid; /* < Unique ID of the shared memory */ + uint64_t phyAddr; /* < Physical memory address */ +} BufferHandle; + +/** + * @brief Defines the memory buffer, such as virtual and physical memory addresses. + * + */ +typedef struct { + BufferHandle hdl; /**< Buffer handle */ + MemType type; /**< Type of the requested memory */ + uint32_t size; /**< Size of the requested memory */ + void *virAddr; /**< Virtual address of the requested memory */ +} GrallocBuffer; + +/** + * @brief Defines buffer data of a layer, including the virtual and physical memory addresses. + * + */ +typedef struct { + uint64_t phyAddr; /**< Physical memory address */ + void *virAddr; /**< Virtual memory address */ +} BufferData; + +/** + * @brief Defines the buffer, which is used to store layer data. + * + */ +typedef struct { + int32_t fenceId; /* < Fence ID of the buffer */ + int32_t width; /* < Buffer width */ + int32_t height; /* < Buffer height */ + int32_t pitch; /* < Number of bytes from one row of pixels in memory to the next */ + PixelFormat pixFormat; /* < Pixel format of the buffer */ + BufferData data; /* < Layer buffer data */ +} LayerBuffer; + +/** + * @brief Defines the information about a rectangle. + * + */ +typedef struct { + int32_t x; /**< Start X coordinate of the rectangle */ + int32_t y; /**< Start Y coordinate of the rectangle */ + int32_t w; /**< Width of the rectangle */ + int32_t h; /**< Height of the rectangle */ +} IRect; + +/** + * @brief Stores surface information for hardware acceleration, such as draw image and bit blit. + * + */ +typedef struct { + uint64_t phyAddr; /**< Start physical address of an image */ + int32_t height; /**< Image height */ + int32_t width; /**< Image width */ + int32_t stride; /**< Image stride */ + PixelFormat enColorFmt; /**< Image format */ + bool bYCbCrClut; /**< Whether the color lookup table (CLUT) is in the YCbCr space */ + bool bAlphaMax255; /**< Maximum alpha value of an image (255 or 128) */ + bool bAlphaExt1555; /**< ARGB1555 alpha extension enable bit */ + uint8_t alpha0; /**< Value of alpha0, ranging from 0 to 255 */ + uint8_t alpha1; /**< Value of alpha1, ranging from 0 to 255 */ + uint64_t cbcrPhyAddr; /**< CbCr physical address */ + int32_t cbcrStride; /**< CbCr stride */ + uint64_t clutPhyAddr; /**< Start physical address of the CLUT, used for color extension or correction */ +} ISurface; + +/** + * @brief Describes a line to help draw lines in hardware acceleration. + * + */ +typedef struct { + int32_t x0; /**< X coordinate of the start point of a line */ + int32_t y0; /**< Y coordinate of the start point of a line */ + int32_t x1; /**< X coordinate of the end point of a line */ + int32_t y1; /**< Y coordinate of the end point of a line */ + uint32_t color; /**< Line color */ +} ILine; + +/** + * @brief Describes a circle to help draw circles in hardware acceleration. + * + */ +typedef struct { + int32_t x; /**< X coordinate of a circle center */ + int32_t y; /**< Y coordinate of a circle center */ + int32_t r; /**< Radius of a circle */ + uint32_t color; /**< Circle color */ +} ICircle; + +/** + * @brief Describes a rectangle to help draw rectangles in hardware acceleration. + * + */ +typedef struct { + IRect rect; /**< Bounds of a rectangle */ + uint32_t color; /**< Rectangle color */ +} Rectangle; + +/** + * @brief Defines hardware acceleration options. + * + */ +typedef struct { + bool enGlobalAlpha; /**< Golbal alpha enable bit */ + uint32_t globalAlpha; /**< Global alpha value */ + bool enPixelAlpha; /**< Pixel alpha enable bit */ + BlendType blendType; /**< Blending type */ + ColorKey colorKeyFrom; /**< Color key mode */ + bool enableRop; /**< Raster operations pipeline (ROP) enable bit */ + RopType colorRopType; /**< Color ROP type */ + RopType alphaRopType; /**< Alpha ROP type */ + bool enableScale; /**< Scaling enable bit */ + TransformType rotateType; /**< Rotation type */ + MirrorType mirrorType; /**< Mirror type */ +} GfxOpt; + +#ifdef __cplusplus +} +#endif +#endif +/* @} */ diff --git a/display/test/BUILD.gn b/display/test/BUILD.gn index 09c6008400..fff7462f7f 100644 --- a/display/test/BUILD.gn +++ b/display/test/BUILD.gn @@ -11,15 +11,17 @@ # See the License for the specific language governing permissions and # limitations under the License. -import("//build/lite/config/component/lite_component.gni") -import("//build/lite/config/test.gni") +if (defined(ohos_lite)) { + import("//build/lite/config/component/lite_component.gni") + import("//build/lite/config/test.gni") -lite_component("hdf_test_display") { - # add hdf subsystem unittest - if (ohos_build_type == "debug") { - if (board_name == "hi3516dv300" || board_name == "hispark_taurus") { - deps = [ "unittest:hdf_peripheral_display_test" ] + lite_component("hdf_test_display") { + # add hdf subsystem unittest + if (ohos_build_type == "debug") { + if (board_name == "hi3516dv300" || board_name == "hispark_taurus") { + deps = [ "unittest:hdf_peripheral_display_test" ] + } } + features = [] } - features = [] } diff --git a/display/test/unittest/BUILD.gn b/display/test/unittest/BUILD.gn index 98985a02e9..22ba04620b 100644 --- a/display/test/unittest/BUILD.gn +++ b/display/test/unittest/BUILD.gn @@ -29,7 +29,7 @@ unittest("hdf_peripheral_display_test") { "//drivers/framework/include", "//drivers/framework/test/unittest/include", "//base/hiviewdfx/hilog_lite/interfaces/native/innerkits", - "//drivers/peripheral/display/interfaces/include", + "//drivers/peripheral/display/interfaces_lite/include", ] sources = [ diff --git a/display/test/unittest/common/display_test.c b/display/test/unittest/common/display_test.c index 0b03891239..8a08949f00 100644 --- a/display/test/unittest/common/display_test.c +++ b/display/test/unittest/common/display_test.c @@ -13,11 +13,11 @@ * limitations under the License. */ +#include "display_test.h" #include #include "securec.h" #include "hdf_log.h" #include "loadbmp_test.h" -#include "display_test.h" DisplayTest g_displayTest; static GrallocBuffer g_buffer; @@ -125,7 +125,7 @@ int32_t DisplayInit(void) } ret = GfxInitialize(&g_displayTest.gfxFuncs); if (ret != DISPLAY_SUCCESS || g_displayTest.gfxFuncs == NULL) { - HDF_LOGE("%s: gralloc initialize failure", __func__); + HDF_LOGE("%s: gfx initialize failure", __func__); return DISPLAY_FAILURE; } return DISPLAY_SUCCESS; @@ -148,7 +148,7 @@ int32_t InitDisplayTest(void) if (g_displayTest.layerFuncs->InitDisplay != NULL) { ret = g_displayTest.layerFuncs->InitDisplay(g_displayTest.devId); if (ret != DISPLAY_SUCCESS) { - HDF_LOGE("%s: MPI VO can't be opened repeatly, so here bypass ret check", __func__); + HDF_LOGE("%s: MPI VO can't be opened repeatedly, so here bypass ret check", __func__); return DISPLAY_SUCCESS; } } @@ -225,11 +225,10 @@ int32_t CloseLayerTest(void) int32_t SetLayerVisibleTest(void) { int32_t ret; - bool visibled = true; // set layer visible if (g_displayTest.layerFuncs->SetLayerVisible != NULL) { - ret = g_displayTest.layerFuncs->SetLayerVisible(g_displayTest.devId, g_displayTest.layerId, visibled); + ret = g_displayTest.layerFuncs->SetLayerVisible(g_displayTest.devId, g_displayTest.layerId, true); if (ret != DISPLAY_SUCCESS) { HDF_LOGE("%s: SetLayerVisible fail", __func__); return DISPLAY_FAILURE; diff --git a/display/test/unittest/common/hdi_display_test.cpp b/display/test/unittest/common/hdi_display_test.cpp index d2700a714c..090e13646f 100644 --- a/display/test/unittest/common/hdi_display_test.cpp +++ b/display/test/unittest/common/hdi_display_test.cpp @@ -39,7 +39,7 @@ void HdiDisplayTest::SetUpTestCase() HDF_LOGE("%s: DisplayInit fail", __func__); ASSERT_TRUE(0); } - // sleep 1 to wait hdmi open + // sleep 1s to wait hdmi open sleep(1); } diff --git a/display/test/unittest/common/loadbmp_test.c b/display/test/unittest/common/loadbmp_test.c index 4d72f3c8d3..46e9b71e89 100644 --- a/display/test/unittest/common/loadbmp_test.c +++ b/display/test/unittest/common/loadbmp_test.c @@ -13,17 +13,17 @@ * limitations under the License. */ +#include "loadbmp_test.h" #include #include #include #include #include -#include #include +#include #include "securec.h" #include "hdf_log.h" #include "display_type.h" -#include "loadbmp_test.h" #define EOK 0 @@ -114,67 +114,68 @@ static int32_t CheckBmpInfo(const OsdBitMapInfo *bmpInfo) static int32_t LoadPicToBuffer(const int8_t *fileName, OsdLogo *videoLogo, OsdColorFmt enFmt, uint8_t **outBuf, uint32_t *stride) { - FILE *file = NULL; - OsdBitMapFileHeader bmpFileHeader; - OsdBitMapInfo bmpInfo; - uint32_t h; - uint64_t byteNum; - char realPath[PATH_MAX] = {0}; - - if (GetBmpInfo(fileName, &bmpFileHeader, &bmpInfo) < 0) { - return DISPLAY_FAILURE; - } - if (CheckBmpInfo(&bmpInfo) != DISPLAY_SUCCESS) { - /* only support 1555.8888 888 bitmap */ - HDF_LOGE("%s: bitmap format not supported", __func__); - return DISPLAY_FAILURE; - } - videoLogo->bpp = bmpInfo.header.bitCnt / EIGHT_BITS_PER_PIXEL; - if (realpath((char*)fileName, realPath) == NULL) { - printf("%s: file %s does not exist\n", __func__, fileName); - return DISPLAY_FAILURE; - } - if ((file = fopen((const char*)realPath, "rb")) == NULL) { - HDF_LOGE("%s: Open file failure: %s", __func__, fileName); - return DISPLAY_FAILURE; - } - videoLogo->width = bmpInfo.header.width; - videoLogo->height = bmpInfo.header.height; - *stride = videoLogo->width * videoLogo->bpp; - h = videoLogo->height; - if ((*stride % FOUR_BITS_PER_PIXEL) != 0) { - *stride = (*stride & 0xfffc) + FOUR_BITS_PER_PIXEL; - } - /* RGB8888 or RGB1555 */ - *outBuf = (uint8_t*)malloc(videoLogo->height * (*stride)); - if (*outBuf == NULL) { - HDF_LOGE("%s: not enough memory to malloc", __func__); - fclose(file); - return DISPLAY_FAILURE; - } - fseek(file, bmpFileHeader.offBits, 0); - byteNum = h * (*stride); - if (byteNum > UINT32_MAX) { - HDF_LOGE("%s: buffer size is beyond param's limit", __func__); - fclose(file); - free(*outBuf); - *outBuf = NULL; - return DISPLAY_FAILURE; - } - if (fread((*outBuf), 1, byteNum, file) != byteNum) { - HDF_LOGE("%s: fread %u*%u error", __func__, h, *stride); - fclose(file); - free(*outBuf); - *outBuf = NULL; - return DISPLAY_FAILURE; - } - if (enFmt >= OSD_COLOR_FMT_RGB888) { - videoLogo->stride = videoLogo->width * FOUR_BITS_PER_PIXEL; - } else { - videoLogo->stride = videoLogo->width * TWO_BITS_PER_PIXEL; - } + FILE *file = NULL; + OsdBitMapFileHeader bmpFileHeader; + OsdBitMapInfo bmpInfo; + uint32_t h; + uint64_t byteNum; + char realPath[PATH_MAX] = {0}; + + if (GetBmpInfo(fileName, &bmpFileHeader, &bmpInfo) < 0) { + return DISPLAY_FAILURE; + } + if (CheckBmpInfo(&bmpInfo) != DISPLAY_SUCCESS) { + /* only support 1555.8888 888 bitmap */ + HDF_LOGE("%s: bitmap format not supported", __func__); + return DISPLAY_FAILURE; + } + videoLogo->bpp = bmpInfo.header.bitCnt / EIGHT_BITS_PER_PIXEL; + if (realpath((char*)fileName, realPath) == NULL) { + printf("%s: file %s does not exist\n", __func__, fileName); + return DISPLAY_FAILURE; + } + if ((file = fopen((const char*)realPath, "rb")) == NULL) { + HDF_LOGE("%s: Open file failure: %s", __func__, fileName); + return DISPLAY_FAILURE; + } + videoLogo->width = bmpInfo.header.width; + videoLogo->height = ((bmpInfo.header.height > 0) ? bmpInfo.header.height : + (-bmpInfo.header.height)); + *stride = videoLogo->width * videoLogo->bpp; + h = videoLogo->height; + if ((*stride % FOUR_BITS_PER_PIXEL) != 0) { + *stride = (*stride & 0xfffc) + FOUR_BITS_PER_PIXEL; + } + /* RGB8888 or RGB1555 */ + *outBuf = (uint8_t*)malloc(videoLogo->height * (*stride)); + if (*outBuf == NULL) { + HDF_LOGE("%s: not enough memory to malloc", __func__); + fclose(file); + return DISPLAY_FAILURE; + } + fseek(file, bmpFileHeader.offBits, 0); + byteNum = h * (*stride); + if (byteNum > UINT32_MAX) { + HDF_LOGE("%s: buffer size is beyond param's limit", __func__); + fclose(file); + free(*outBuf); + *outBuf = NULL; + return DISPLAY_FAILURE; + } + if (fread((*outBuf), 1, byteNum, file) != byteNum) { + HDF_LOGE("%s: fread %u*%u error", __func__, h, *stride); fclose(file); - return DISPLAY_SUCCESS; + free(*outBuf); + *outBuf = NULL; + return DISPLAY_FAILURE; + } + if (enFmt >= OSD_COLOR_FMT_RGB888) { + videoLogo->stride = videoLogo->width * FOUR_BITS_PER_PIXEL; + } else { + videoLogo->stride = videoLogo->width * TWO_BITS_PER_PIXEL; + } + fclose(file); + return DISPLAY_SUCCESS; } static void LoadRgbData(OsdLogo *videoLogo, OsdColorFmt enFmt, uint32_t stride, uint8_t *origBuf) @@ -281,13 +282,13 @@ static int32_t LoadBMPEx(const int8_t *fileName, OsdLogo *videoLogo, OsdColorFmt } if (videoLogo->bpp == THREE_BITS_PER_PIXEL) { ret = Copy3BitsByFmt(videoLogo, enFmt, stride, origBmpBuf); - if (ret < 0) { + if (ret != DISPLAY_SUCCESS) { HDF_LOGE("%s: Copy3BitsByFmt failure", __func__); } } else if ((videoLogo->bpp == TWO_BITS_PER_PIXEL) || (videoLogo->bpp == FOUR_BITS_PER_PIXEL)) { ret = Copy2BitsAnd4Bits(videoLogo, stride, origBmpBuf); if (ret != DISPLAY_SUCCESS) { - HDF_LOGE("%s: Copy3BitsByFmt failure", __func__); + HDF_LOGE("%s: Copy2BitsAnd4Bits failure", __func__); free(origBmpBuf); return ret; } @@ -296,33 +297,16 @@ static int32_t LoadBMPEx(const int8_t *fileName, OsdLogo *videoLogo, OsdColorFmt return DISPLAY_SUCCESS; } -static int8_t *GetExtName(int8_t *fileName) -{ - int8_t *pret = NULL; - uint32_t len; - - len = strlen((const char *)fileName); - while (len) { - pret = fileName + len; - if (*pret == '.') { - return (pret + 1); - } - - len--; - } - - return pret; -} - static int32_t LoadImageEx(const int8_t *fileName, OsdLogo *videoLogo, OsdColorFmt enFmt) { - const char *ext = (const char *)GetExtName((int8_t*)fileName); + char *ext = strrchr((const char *)fileName, '.'); if (ext == NULL) { HDF_LOGE("%s: LoadImageEx error", __func__); return DISPLAY_FAILURE; } + ext = ext + 1; if (strcmp(ext, "bmp") == 0) { if (LoadBMPEx(fileName, videoLogo, enFmt) != 0) { HDF_LOGE("%s: LoadBMPEx error", __func__); diff --git a/display/test/unittest/common/loadbmp_test.h b/display/test/unittest/common/loadbmp_test.h index 9e7e326481..759dd36771 100644 --- a/display/test/unittest/common/loadbmp_test.h +++ b/display/test/unittest/common/loadbmp_test.h @@ -56,9 +56,9 @@ typedef struct { uint32_t width; /* out */ uint32_t height; /* out */ uint32_t stride; /* in */ - uint8_t *picBuffer; /* in/out */ uint32_t len; /* picBuffer length */ uint16_t bpp; /* bpp */ + uint8_t *picBuffer; /* in/out */ } OsdLogo; typedef struct { diff --git a/input/hal/BUILD.gn b/input/hal/BUILD.gn old mode 100755 new mode 100644 index 7761c9cb2a..b495bd55f3 --- a/input/hal/BUILD.gn +++ b/input/hal/BUILD.gn @@ -11,50 +11,95 @@ # See the License for the specific language governing permissions and # limitations under the License. -import("//build/lite/config/component/lite_component.gni") - -HDF_FWKS = "//drivers/framework" - -shared_library("hdi_input") { - sources = [ - "src/input_controller.c", - "src/input_manager.c", - "src/input_reporter.c", - ] - - include_dirs = [ - "include", - "//drivers/peripheral/input/interfaces/include", - "//drivers/adapter/uhdf/posix/include", - "$HDF_FWKS/include/utils", - "$HDF_FWKS/include/osal", - "$HDF_FWKS/core/adapter/syscall/include", - "$HDF_FWKS/include/core", - "$HDF_FWKS/ability/sbuf/include", - "$HDF_FWKS/core/shared/include", - "$HDF_FWKS/utils/include", - "//third_party/bounds_checking_function/include", - ] - - deps = [ - "//base/hiviewdfx/hilog_lite/frameworks/featured:hilog_shared", - "//drivers/adapter/uhdf/manager:hdf_core", - "//drivers/adapter/uhdf/posix:hdf_posix_osal", - "//third_party/bounds_checking_function:libsec_shared", - ] - - defines = [ "__USER__" ] - - cflags = [ - "-Wall", - "-Wextra", - "-Werror", - "-fsigned-char", - "-fno-common", - "-fno-strict-aliasing", - ] +if (defined(ohos_lite)) { + import("//build/lite/config/component/lite_component.gni") +} else { + import("//build/ohos.gni") } -lite_component("hdi") { - features = [ ":hdi_input" ] +if (defined(ohos_lite)) { + HDF_FWKS = "//drivers/framework" + + shared_library("hdi_input") { + sources = [ + "src/input_controller.c", + "src/input_manager.c", + "src/input_reporter.c", + ] + + include_dirs = [ + "include", + "//drivers/peripheral/input/interfaces/include", + "//drivers/adapter/uhdf/posix/include", + "$HDF_FWKS/include/utils", + "$HDF_FWKS/include/osal", + "$HDF_FWKS/core/adapter/syscall/include", + "$HDF_FWKS/include/core", + "$HDF_FWKS/ability/sbuf/include", + "$HDF_FWKS/core/shared/include", + "$HDF_FWKS/utils/include", + "//third_party/bounds_checking_function/include", + ] + + deps = [ + "//base/hiviewdfx/hilog_lite/frameworks/featured:hilog_shared", + "//drivers/adapter/uhdf/manager:hdf_core", + "//drivers/adapter/uhdf/posix:hdf_posix_osal", + "//third_party/bounds_checking_function:libsec_shared", + ] + + defines = [ "__USER__" ] + + cflags = [ + "-Wall", + "-Wextra", + "-Werror", + "-fsigned-char", + "-fno-common", + "-fno-strict-aliasing", + ] + } + + lite_component("hdi") { + features = [ ":hdi_input" ] + } +} else { + INPUT_ROOT_DIR = "//drivers/peripheral/input" + config("input_hdi_public_config") { + visibility = [ ":*" ] + include_dirs = [ "$INPUT_ROOT_DIR/interfaces/include" ] + } + + ohos_shared_library("hdi_input") { + sources = [ + "src/input_controller.c", + "src/input_manager.c", + "src/input_reporter.c", + ] + + public_configs = [ ":input_hdi_public_config" ] + include_dirs = [ "$INPUT_ROOT_DIR/hal/include" ] + deps = [ + "//drivers/adapter/uhdf2/osal:libhdf_utils", + "//utils/native/base:utils", + ] + + defines = [ "__OHOS__USER__" ] + + cflags = [ + "-Wall", + "-Wextra", + "-Werror", + "-fsigned-char", + "-fno-common", + "-fno-strict-aliasing", + ] + + subsystem_name = "hdf" + if (is_standard_system) { + external_deps = [ "hiviewdfx_hilog_native:libhilog" ] + } else { + external_deps = [ "hilog:libhilog" ] + } + } } diff --git a/input/hal/include/input_common.h b/input/hal/include/input_common.h old mode 100755 new mode 100644 index 674c01869c..b53ca173fc --- a/input/hal/include/input_common.h +++ b/input/hal/include/input_common.h @@ -26,8 +26,9 @@ extern "C" { #endif -#define SERVICE_NAME_LEN 16 +#define SERVICE_NAME_LEN 24 #define MAX_POLLFD_NUM 10 +#define SCAN_DEV 0 #define GET_MANAGER_CHECK_RETURN(manager) do { \ manager = GetDevManager(); \ @@ -45,6 +46,12 @@ typedef struct { struct DListHead node; /* Head node of a linked list */ } DeviceInfoNode; +typedef struct { + void *service; /**< Service of the device */ + void *listener; /**< Event listener of the device */ + InputReportEventCb *callback; /**< Callback {@link InputReportEventCb} for reporting data */ +} HostDevInfo; + /** * @brief Describes the input device manager. */ @@ -55,6 +62,7 @@ typedef struct { pthread_t thread; /* Monitoring thread for polling */ struct pollfd pollFds[MAX_POLLFD_NUM]; /* The records of poll fds */ pthread_mutex_t mutex; /* Mutex object to synchronize */ + HostDevInfo hostDev; } InputDevManager; /** diff --git a/input/hal/src/input_controller.c b/input/hal/src/input_controller.c old mode 100755 new mode 100644 index e38f10a3e2..6b59a23270 --- a/input/hal/src/input_controller.c +++ b/input/hal/src/input_controller.c @@ -12,15 +12,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - +#include "input_controller.h" #include #include #include #include - #include "hdf_io_service_if.h" #include "input_common.h" -#include "input_controller.h" InputDevManager *GetDevManager(void); @@ -43,12 +41,12 @@ static bool FillSbufData(struct HdfSBuf *data, int32_t cmd, const void *in) break; } if (!ret) { - HDF_LOGE("%s: sbuf write failed", __func__); + HDF_LOGE("%s: cmd = %d sbuf write failed", __func__, cmd); } return ret; } -static bool ObtainSbufData(struct HdfSBuf *reply, int32_t cmd, void *out, int32_t length) +static bool ObtainSbufData(struct HdfSBuf *reply, int32_t cmd, void *out, uint32_t length) { bool ret = false; uint32_t tempInt; @@ -106,7 +104,7 @@ EXIT: return INPUT_FAILURE; } -static int32_t IoServiceOps(struct HdfIoService *service, int32_t cmd, const void *in, void *out, int32_t outLen) +static int32_t IoServiceOps(struct HdfIoService *service, int32_t cmd, const void *in, void *out, uint32_t outLen) { int32_t ret; struct HdfSBuf *data = NULL; @@ -146,8 +144,9 @@ static int32_t SetPowerStatus(uint32_t devIndex, uint32_t status) DeviceInfoNode *pos = NULL; DeviceInfoNode *next = NULL; InputDevManager *manager = NULL; + struct HdfIoService *service = NULL; - if (devIndex >= MAX_INPUT_DEV_NUM || status >= INPUT_POWER_STATUS_UNKNOWN) { + if ((devIndex >= MAX_INPUT_DEV_NUM) || (status >= INPUT_POWER_STATUS_UNKNOWN)) { HDF_LOGE("%s: invalid param", __func__); return INPUT_INVALID_PARAM; } @@ -158,10 +157,10 @@ static int32_t SetPowerStatus(uint32_t devIndex, uint32_t status) if (pos->payload.devIndex != devIndex) { continue; } - struct HdfIoService *service = (struct HdfIoService *)pos->payload.service; + service = (struct HdfIoService *)pos->payload.service; if (IoServiceOps(service, SET_PWR_STATUS, &status, NULL, 0)) { - HDF_LOGE("%s: set power status failed", __func__); pthread_mutex_unlock(&manager->mutex); + HDF_LOGE("%s: set power status failed", __func__); return INPUT_FAILURE; } pos->payload.powerStatus = status; @@ -169,8 +168,8 @@ static int32_t SetPowerStatus(uint32_t devIndex, uint32_t status) return INPUT_SUCCESS; } - HDF_LOGE("%s: device%u doesn't exist, can't set power status", __func__, devIndex); pthread_mutex_unlock(&manager->mutex); + HDF_LOGE("%s: device%u doesn't exist, can't set power status", __func__, devIndex); return INPUT_FAILURE; } @@ -179,8 +178,9 @@ static int32_t GetPowerStatus(uint32_t devIndex, uint32_t *status) DeviceInfoNode *pos = NULL; DeviceInfoNode *next = NULL; InputDevManager *manager = NULL; + struct HdfIoService *service = NULL; - if (devIndex >= MAX_INPUT_DEV_NUM || status == NULL) { + if ((devIndex >= MAX_INPUT_DEV_NUM) || (status == NULL)) { HDF_LOGE("%s: invalid param", __func__); return INPUT_INVALID_PARAM; } @@ -191,15 +191,15 @@ static int32_t GetPowerStatus(uint32_t devIndex, uint32_t *status) if (pos->payload.devIndex != devIndex) { continue; } - struct HdfIoService *service = (struct HdfIoService *)pos->payload.service; + service = (struct HdfIoService *)pos->payload.service; if (IoServiceOps(service, GET_PWR_STATUS, NULL, status, sizeof(uint32_t))) { - HDF_LOGE("%s: get power status failed", __func__); pthread_mutex_unlock(&manager->mutex); + HDF_LOGE("%s: get power status failed", __func__); return INPUT_FAILURE; } if (*status >= INPUT_POWER_STATUS_UNKNOWN) { - HDF_LOGE("%s: power status is unknown", __func__); pthread_mutex_unlock(&manager->mutex); + HDF_LOGE("%s: power status is unknown", __func__); return INPUT_FAILURE; } pos->payload.powerStatus = *status; @@ -207,8 +207,8 @@ static int32_t GetPowerStatus(uint32_t devIndex, uint32_t *status) return INPUT_SUCCESS; } - HDF_LOGE("%s: device%u doesn't exist, can't get power status", __func__, devIndex); pthread_mutex_unlock(&manager->mutex); + HDF_LOGE("%s: device%u doesn't exist, can't get power status", __func__, devIndex); return INPUT_FAILURE; } @@ -217,8 +217,9 @@ static int32_t GetDeviceType(uint32_t devIndex, uint32_t *deviceType) DeviceInfoNode *pos = NULL; DeviceInfoNode *next = NULL; InputDevManager *manager = NULL; + struct HdfIoService *service = NULL; - if (devIndex >= MAX_INPUT_DEV_NUM || deviceType == NULL) { + if ((devIndex >= MAX_INPUT_DEV_NUM) || (deviceType == NULL)) { HDF_LOGE("%s: invalid param", __func__); return INPUT_INVALID_PARAM; } @@ -229,15 +230,15 @@ static int32_t GetDeviceType(uint32_t devIndex, uint32_t *deviceType) if (pos->payload.devIndex != devIndex) { continue; } - struct HdfIoService *service = (struct HdfIoService *)pos->payload.service; + service = (struct HdfIoService *)pos->payload.service; if (IoServiceOps(service, GET_DEV_TYPE, NULL, deviceType, sizeof(uint32_t))) { - HDF_LOGE("%s: get device type failed", __func__); pthread_mutex_unlock(&manager->mutex); + HDF_LOGE("%s: get device type failed", __func__); return INPUT_FAILURE; } if (*deviceType >= INDEV_TYPE_UNKNOWN) { - HDF_LOGE("%s: device type is unknown", __func__); pthread_mutex_unlock(&manager->mutex); + HDF_LOGE("%s: device type is unknown", __func__); return INPUT_FAILURE; } pos->payload.devType = *deviceType; @@ -245,18 +246,20 @@ static int32_t GetDeviceType(uint32_t devIndex, uint32_t *deviceType) return INPUT_SUCCESS; } - HDF_LOGE("%s: device%u doesn't exist, can't get device type", __func__, devIndex); pthread_mutex_unlock(&manager->mutex); + HDF_LOGE("%s: device%u doesn't exist, can't get device type", __func__, devIndex); return INPUT_FAILURE; } -static int32_t GetChipName(uint32_t devIndex, char *chipName, uint32_t length) +static int32_t GetGeneralInfo(uint32_t devIndex, char *generalInfo, uint32_t length, uint32_t lengthLimit, int32_t cmd) { DeviceInfoNode *pos = NULL; DeviceInfoNode *next = NULL; InputDevManager *manager = NULL; + void *info = NULL; + struct HdfIoService *service = NULL; - if (devIndex >= MAX_INPUT_DEV_NUM || chipName == NULL || length < CHIP_NAME_LEN) { + if ((devIndex >= MAX_INPUT_DEV_NUM) || (generalInfo == NULL) || (length < lengthLimit)) { HDF_LOGE("%s: invalid param", __func__); return INPUT_INVALID_PARAM; } @@ -267,104 +270,58 @@ static int32_t GetChipName(uint32_t devIndex, char *chipName, uint32_t length) if (pos->payload.devIndex != devIndex) { continue; } - struct HdfIoService *service = (struct HdfIoService *)pos->payload.service; - if (IoServiceOps(service, GET_CHIP_NAME, NULL, pos->payload.chipName, CHIP_NAME_LEN)) { - HDF_LOGE("%s: get chip name failed", __func__); + switch (cmd) { + case GET_CHIP_NAME: + info = pos->payload.chipName; + break; + case GET_CHIP_INFO: + info = pos->payload.chipInfo; + break; + case GET_VENDOR_NAME: + info = pos->payload.vendorName; + break; + default: + pthread_mutex_unlock(&manager->mutex); + HDF_LOGE("%s: cmd = %d invalid param", __func__, cmd); + return INPUT_FAILURE; + } + + service = (struct HdfIoService *)pos->payload.service; + if (IoServiceOps(service, cmd, NULL, info, lengthLimit)) { pthread_mutex_unlock(&manager->mutex); + HDF_LOGE("%s: get information fail", __func__); return INPUT_FAILURE; } - if (strncpy_s(chipName, length, pos->payload.chipName, CHIP_NAME_LEN - 1) != EOK) { - HDF_LOGE("%s: strncpy_s fail", __func__); + if (strncpy_s(generalInfo, length, info, lengthLimit - 1) != EOK) { pthread_mutex_unlock(&manager->mutex); + HDF_LOGE("%s: strncpy_s fail", __func__); return INPUT_FAILURE; } - HDF_LOGI("%s: device%u's chip name is %s", __func__, devIndex, chipName); pthread_mutex_unlock(&manager->mutex); + HDF_LOGI("%s: device%u get information success", __func__, devIndex); return INPUT_SUCCESS; } - HDF_LOGE("%s: device%u doesn't exist, can't get chip name", __func__, devIndex); pthread_mutex_unlock(&manager->mutex); + HDF_LOGE("%s: device%u doesn't exist, can't get information", __func__, devIndex); return INPUT_FAILURE; } -static int32_t GetChipInfo(uint32_t devIndex, char *chipInfo, uint32_t length) +static int32_t GetChipName(uint32_t devIndex, char *chipName, uint32_t length) { - DeviceInfoNode *pos = NULL; - DeviceInfoNode *next = NULL; - InputDevManager *manager = NULL; - - if (devIndex >= MAX_INPUT_DEV_NUM || chipInfo == NULL || length < CHIP_INFO_LEN) { - HDF_LOGE("%s: invalid param", __func__); - return INPUT_INVALID_PARAM; - } - - GET_MANAGER_CHECK_RETURN(manager); - pthread_mutex_lock(&manager->mutex); - DLIST_FOR_EACH_ENTRY_SAFE(pos, next, &manager->devList, DeviceInfoNode, node) { - if (pos->payload.devIndex != devIndex) { - continue; - } - struct HdfIoService *service = (struct HdfIoService *)pos->payload.service; - if (IoServiceOps(service, GET_CHIP_INFO, NULL, pos->payload.chipInfo, CHIP_INFO_LEN)) { - HDF_LOGE("%s: get chip info failed", __func__); - pthread_mutex_unlock(&manager->mutex); - return INPUT_FAILURE; - } - if (strncpy_s(chipInfo, length, pos->payload.chipInfo, CHIP_INFO_LEN - 1) != EOK) { - HDF_LOGE("%s: strncpy_s fail", __func__); - pthread_mutex_unlock(&manager->mutex); - return INPUT_FAILURE; - } - pthread_mutex_unlock(&manager->mutex); - return INPUT_SUCCESS; - } + return GetGeneralInfo(devIndex, chipName, length, CHIP_NAME_LEN, GET_CHIP_NAME); +} - HDF_LOGE("%s: device%u doesn't exist, can't get chip info", __func__, devIndex); - pthread_mutex_unlock(&manager->mutex); - return INPUT_FAILURE; +static int32_t GetChipInfo(uint32_t devIndex, char *chipInfo, uint32_t length) +{ + return GetGeneralInfo(devIndex, chipInfo, length, CHIP_INFO_LEN, GET_CHIP_INFO); } static int32_t GetVendorName(uint32_t devIndex, char *vendorName, uint32_t length) { - DeviceInfoNode *pos = NULL; - DeviceInfoNode *next = NULL; - InputDevManager *manager = NULL; - - if (devIndex >= MAX_INPUT_DEV_NUM || vendorName == NULL || length < CHIP_NAME_LEN) { - HDF_LOGE("%s: invalid param", __func__); - return INPUT_INVALID_PARAM; - } - - GET_MANAGER_CHECK_RETURN(manager); - pthread_mutex_lock(&manager->mutex); - DLIST_FOR_EACH_ENTRY_SAFE(pos, next, &manager->devList, DeviceInfoNode, node) { - if (pos->payload.devIndex != devIndex) { - continue; - } - struct HdfIoService *service = (struct HdfIoService *)pos->payload.service; - if (IoServiceOps(service, GET_VENDOR_NAME, NULL, pos->payload.vendorName, VENDOR_NAME_LEN)) { - HDF_LOGE("%s: get vendor name failed", __func__); - pthread_mutex_unlock(&manager->mutex); - return INPUT_FAILURE; - } - - if (strncpy_s(vendorName, length, pos->payload.vendorName, VENDOR_NAME_LEN - 1) != EOK) { - HDF_LOGE("%s: strncpy_s fail", __func__); - pthread_mutex_unlock(&manager->mutex); - return INPUT_FAILURE; - } - - HDF_LOGI("%s: device%u's vendor name is %s", __func__, devIndex, vendorName); - pthread_mutex_unlock(&manager->mutex); - return INPUT_SUCCESS; - } - - HDF_LOGE("%s: device%u doesn't exist, can't get vendor name", __func__, devIndex); - pthread_mutex_unlock(&manager->mutex); - return INPUT_FAILURE; + return GetGeneralInfo(devIndex, vendorName, length, VENDOR_NAME_LEN, GET_VENDOR_NAME); } static int32_t SetGestureMode(uint32_t devIndex, uint32_t gestureMode) @@ -372,6 +329,7 @@ static int32_t SetGestureMode(uint32_t devIndex, uint32_t gestureMode) DeviceInfoNode *pos = NULL; DeviceInfoNode *next = NULL; InputDevManager *manager = NULL; + struct HdfIoService *service = NULL; if (devIndex >= MAX_INPUT_DEV_NUM) { HDF_LOGE("%s: invalid param", __func__); @@ -384,18 +342,18 @@ static int32_t SetGestureMode(uint32_t devIndex, uint32_t gestureMode) if (pos->payload.devIndex != devIndex) { continue; } - struct HdfIoService *service = (struct HdfIoService *)pos->payload.service; + service = (struct HdfIoService *)pos->payload.service; if (IoServiceOps(service, SET_GESTURE_MODE, &gestureMode, NULL, 0)) { - HDF_LOGE("%s: set gesture mode failed", __func__); pthread_mutex_unlock(&manager->mutex); + HDF_LOGE("%s: set gesture mode failed", __func__); return INPUT_FAILURE; } pthread_mutex_unlock(&manager->mutex); return INPUT_SUCCESS; } - HDF_LOGE("%s: device%u doesn't exist, can't set gesture mode", __func__, devIndex); pthread_mutex_unlock(&manager->mutex); + HDF_LOGE("%s: device%u doesn't exist, can't set gesture mode", __func__, devIndex); return INPUT_FAILURE; } @@ -406,8 +364,8 @@ static int32_t RunCapacitanceTest(uint32_t devIndex, uint32_t testType, char *re InputDevManager *manager = NULL; CapacitanceTestInfo testInfo; - if (devIndex >= MAX_INPUT_DEV_NUM || testType >= TEST_TYPE_UNKNOWN || - result == NULL || length < SELF_TEST_RESULT_LEN) { + if (devIndex >= (MAX_INPUT_DEV_NUM) || (testType >= TEST_TYPE_UNKNOWN) || + (result == NULL) || (length < SELF_TEST_RESULT_LEN)) { HDF_LOGE("%s: invalid param", __func__); return INPUT_INVALID_PARAM; } @@ -422,23 +380,23 @@ static int32_t RunCapacitanceTest(uint32_t devIndex, uint32_t testType, char *re } struct HdfIoService *service = (struct HdfIoService *)pos->payload.service; if (IoServiceOps(service, RUN_CAPAC_TEST, &testInfo.testType, testInfo.testResult, SELF_TEST_RESULT_LEN)) { - HDF_LOGE("%s: run capacitance test failed", __func__); pthread_mutex_unlock(&manager->mutex); + HDF_LOGE("%s: run capacitance test failed", __func__); return INPUT_FAILURE; } if (strncpy_s(result, length, testInfo.testResult, SELF_TEST_RESULT_LEN - 1) != EOK) { - HDF_LOGE("%s: strncpy_s fail", __func__); pthread_mutex_unlock(&manager->mutex); + HDF_LOGE("%s: strncpy_s fail", __func__); return INPUT_FAILURE; } - HDF_LOGI("%s: capacitance test result is %s", __func__, result); pthread_mutex_unlock(&manager->mutex); + HDF_LOGI("%s: capacitance test result is %s", __func__, result); return INPUT_SUCCESS; } - HDF_LOGE("%s: device%u doesn't exist, can't run capacitance test", __func__, devIndex); pthread_mutex_unlock(&manager->mutex); + HDF_LOGE("%s: device%u doesn't exist, can't run capacitance test", __func__, devIndex); return INPUT_FAILURE; } @@ -448,7 +406,8 @@ static int32_t RunExtraCommand(uint32_t devIndex, InputExtraCmd *cmdInfo) DeviceInfoNode *next = NULL; InputDevManager *manager = NULL; - if (devIndex >= MAX_INPUT_DEV_NUM || cmdInfo == NULL || cmdInfo->cmdCode == NULL || cmdInfo->cmdValue == NULL) { + if ((devIndex >= MAX_INPUT_DEV_NUM) || (cmdInfo == NULL) || (cmdInfo->cmdCode == NULL) || + (cmdInfo->cmdValue == NULL)) { HDF_LOGE("%s: invalid param", __func__); return INPUT_INVALID_PARAM; } @@ -461,16 +420,16 @@ static int32_t RunExtraCommand(uint32_t devIndex, InputExtraCmd *cmdInfo) } struct HdfIoService *service = (struct HdfIoService *)pos->payload.service; if (IoServiceOps(service, RUN_EXTRA_CMD, cmdInfo, NULL, 0)) { - HDF_LOGE("%s: run extra cmd failed", __func__); pthread_mutex_unlock(&manager->mutex); + HDF_LOGE("%s: run extra cmd failed", __func__); return INPUT_FAILURE; } pthread_mutex_unlock(&manager->mutex); return INPUT_SUCCESS; } - HDF_LOGE("%s: device%d doesn't exist, can't run extra cmd", __func__, devIndex); pthread_mutex_unlock(&manager->mutex); + HDF_LOGE("%s: device%d doesn't exist, can't run extra cmd", __func__, devIndex); return INPUT_FAILURE; } diff --git a/input/hal/src/input_manager.c b/input/hal/src/input_manager.c index d10c67b960..5a84ec7a28 100644 --- a/input/hal/src/input_manager.c +++ b/input/hal/src/input_manager.c @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - +#include "input_manager.h" #include #include #include @@ -21,15 +21,12 @@ #include #include #include - #include "hdf_io_service_if.h" - #include "input_common.h" -#include "input_manager.h" -#define DEVICE_NODE_PATH "/dev/input/event" -#define DEVICE_NODE_USB_PATH "/dev/usb/uhid" #define TOUCH_INDEX 1 +#define PLACEHOLDER_LENGTH 2 +#define PLACEHOLDER_LIMIT 10 static InputDevManager *g_devManager; int32_t InstanceReporterHdi(InputReporter **hdi); @@ -58,13 +55,13 @@ static int32_t GetInputDevice(uint32_t devIndex, DeviceInfo **devInfo) continue; } *devInfo = &pos->payload; - HDF_LOGI("%s: device%u get info succ", __func__, devIndex); pthread_mutex_unlock(&manager->mutex); + HDF_LOGI("%s: device%u get info succ", __func__, devIndex); return INPUT_SUCCESS; } - HDF_LOGE("%s: device%u doesn't exist, can't get device info", __func__, devIndex); pthread_mutex_unlock(&manager->mutex); + HDF_LOGE("%s: device%u doesn't exist, can't get device info", __func__, devIndex); return INPUT_FAILURE; } @@ -87,9 +84,9 @@ static int32_t GetInputDeviceList(uint32_t *devNum, DeviceInfo **deviceList, uin DLIST_FOR_EACH_ENTRY_SAFE(pos, next, &manager->devList, DeviceInfoNode, node) { if (tempSize >= size) { *devNum = manager->currentDevNum; + pthread_mutex_unlock(&manager->mutex); HDF_LOGE("%s: size is not enough, size = %u, devNum = %u", __func__, size, *devNum); - pthread_mutex_unlock(&manager->mutex); return INPUT_FAILURE; } *tempList = &pos->payload; @@ -122,16 +119,18 @@ static int32_t CloseInputDevice(uint32_t devIndex) return INPUT_SUCCESS; } - HDF_LOGE("%s: device%u doesn't exist", __func__, devIndex); pthread_mutex_unlock(&manager->mutex); + HDF_LOGE("%s: device%u doesn't exist", __func__, devIndex); return INPUT_FAILURE; } -static int32_t AddService(const uint32_t index, const struct HdfIoService *service) +static int32_t AddService(uint32_t index, const struct HdfIoService *service) { InputDevManager *manager = NULL; - DeviceInfoNode *device = (DeviceInfoNode *)malloc(sizeof(DeviceInfoNode)); + DeviceInfoNode *device = NULL; + GET_MANAGER_CHECK_RETURN(manager); + device = (DeviceInfoNode *)malloc(sizeof(DeviceInfoNode)); if (device == NULL) { HDF_LOGE("%s: malloc fail", __func__); return INPUT_NOMEM; @@ -140,7 +139,6 @@ static int32_t AddService(const uint32_t index, const struct HdfIoService *servi device->payload.devIndex = index; device->payload.service = (void *)service; - GET_MANAGER_CHECK_RETURN(manager); pthread_mutex_lock(&manager->mutex); DListInsertTail(&device->node, &manager->devList); manager->currentDevNum++; @@ -163,8 +161,8 @@ static int32_t CheckIndex(uint32_t devIndex) pthread_mutex_lock(&manager->mutex); DLIST_FOR_EACH_ENTRY_SAFE(pos, next, &manager->devList, DeviceInfoNode, node) { if (pos->payload.devIndex == devIndex) { - HDF_LOGE("%s: the device%u has existed", __func__, devIndex); pthread_mutex_unlock(&manager->mutex); + HDF_LOGE("%s: the device%u has existed", __func__, devIndex); return INPUT_FAILURE; } } @@ -182,7 +180,9 @@ static int32_t OpenInputDevice(uint32_t devIndex) return INPUT_FAILURE; } - ret = snprintf_s(serviceName, SERVICE_NAME_LEN, strlen("event") + 1, "%s%u", "event", devIndex); + int32_t len = (devIndex < PLACEHOLDER_LIMIT) ? 1 : PLACEHOLDER_LENGTH; + ret = snprintf_s(serviceName, SERVICE_NAME_LEN, strlen("hdf_input_event") + len, "%s%u", + "hdf_input_event", devIndex); if (ret == -1) { HDF_LOGE("%s: snprintf_s fail", __func__); return INPUT_FAILURE; @@ -200,7 +200,60 @@ static int32_t OpenInputDevice(uint32_t devIndex) return INPUT_FAILURE; } - HDF_LOGI("%s: open dev%d succ, service name = %s", __func__, devIndex, serviceName); + HDF_LOGI("%s: open dev%u succ, service name = %s", __func__, devIndex, serviceName); + return INPUT_SUCCESS; +} + +static int32_t ScanInputDevice(DevDesc *staArr, uint32_t arrLen) +{ + InputDevManager *manager = NULL; + struct HdfIoService *service = NULL; + struct HdfSBuf *reply = NULL; + char *data = {0}; + uint32_t count = 0; + uint32_t replayDataSize = 0; + int32_t ret; + + GET_MANAGER_CHECK_RETURN(manager); + pthread_mutex_lock(&manager->mutex); + if (manager->hostDev.service == NULL) { + manager->hostDev.service = HdfIoServiceBind(DEV_MANAGER_SERVICE_NAME); + } + service = manager->hostDev.service; + pthread_mutex_unlock(&manager->mutex); + + if (service == NULL) { + HDF_LOGE("%s: HdfIoServiceBind failed", __func__); + return INPUT_FAILURE; + } + reply = HdfSBufObtainDefaultSize(); + if (reply == NULL) { + HDF_LOGE("%s: fail to obtain sbuf data", __func__); + return INPUT_FAILURE; + } + + ret = service->dispatcher->Dispatch(&service->object, 0, NULL, reply); + if (ret != INPUT_SUCCESS) { + HDF_LOGE("%s: dispatch fail", __func__); + HdfSBufRecycle(reply); + return INPUT_FAILURE; + } + + while (count < arrLen) { + if (!HdfSbufReadBuffer(reply, (const void **)(&data), &replayDataSize) || + replayDataSize != sizeof(DevDesc)) { + HDF_LOGE("%s: sbuf read failed", __func__); + break; + } + if (memcpy_s(&staArr[count], sizeof(DevDesc), data, replayDataSize) != EOK) { + HDF_LOGE("%s: memcpy failed, line: %d", __func__, __LINE__); + HdfSBufRecycle(reply); + return INPUT_FAILURE; + } + HDF_LOGI("%s: type = %d, id =%d", __func__, staArr[count].devType, staArr[count].devIndex); + count++; + } + HdfSBufRecycle(reply); return INPUT_SUCCESS; } @@ -214,6 +267,7 @@ static int32_t InstanceManagerHdi(InputManager **manager) (void)memset_s(managerHdi, sizeof(InputManager), 0, sizeof(InputManager)); + managerHdi->ScanInputDevice = ScanInputDevice; managerHdi->OpenInputDevice = OpenInputDevice; managerHdi->CloseInputDevice = CloseInputDevice; managerHdi->GetInputDevice = GetInputDevice; @@ -305,7 +359,7 @@ int32_t GetInputInterface(IInputInterface **inputInterface) ret = InitDevManager(); if (ret != INPUT_SUCCESS) { - HDF_LOGE("%s: failed to initialze manager", __func__); + HDF_LOGE("%s: failed to initialize manager", __func__); FreeInputHdi(inputHdi); return INPUT_FAILURE; } @@ -314,3 +368,44 @@ int32_t GetInputInterface(IInputInterface **inputInterface) HDF_LOGI("%s: exit succ", __func__); return INPUT_SUCCESS; } + +int32_t ReleaseInputInterface(IInputInterface *inputInterface) +{ + DeviceInfoNode *pos = NULL; + DeviceInfoNode *next = NULL; + InputDevManager *manager = NULL; + int32_t ret; + + if (inputInterface == NULL) { + return INPUT_NULL_PTR; + } + + GET_MANAGER_CHECK_RETURN(manager); + + pthread_mutex_lock(&manager->mutex); + DLIST_FOR_EACH_ENTRY_SAFE(pos, next, &manager->devList, DeviceInfoNode, node) { + ret = HdfDeviceUnregisterEventListener(pos->payload.service, pos->payload.listener); + if (ret != HDF_SUCCESS) { + pthread_mutex_unlock(&manager->mutex); + HDF_LOGE("%s: failed to release listener", __func__); + return INPUT_FAILURE; + } + free(pos->payload.service); + pos->payload.service = NULL; + DListRemove(&pos->node); + free(pos); + pos = NULL; + } + + pthread_mutex_unlock(&manager->mutex); + pthread_mutex_destroy(&manager->mutex); + free(manager); + manager = NULL; + g_devManager = NULL; + + if (inputInterface != NULL) { + FreeInputHdi(inputInterface); + inputInterface = NULL; + } + return INPUT_SUCCESS; +} \ No newline at end of file diff --git a/input/hal/src/input_reporter.c b/input/hal/src/input_reporter.c old mode 100755 new mode 100644 index 599ba9f67a..b11b3a5da6 --- a/input/hal/src/input_reporter.c +++ b/input/hal/src/input_reporter.c @@ -12,18 +12,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - +#include "input_reporter.h" #include #include #include #include #include - #include "hdf_io_service_if.h" #include "hdf_syscall_adapter.h" #include "osal_time.h" #include "input_common.h" -#include "input_reporter.h" #define POLL_WAIT_MS 100 #define MOUSE_DATA_LEN 4 @@ -62,7 +60,7 @@ static int32_t EventListenerCallback(struct HdfDevEventlistener *listener, struc } if (!HdfSbufReadBuffer(data, (const void **)&pkgs[count], &len)) { - HDF_LOGE("%s: sbuf read failed", __func__); + HDF_LOGE("%s: sbuf read finished", __func__); break; } @@ -74,7 +72,7 @@ static int32_t EventListenerCallback(struct HdfDevEventlistener *listener, struc DLIST_FOR_EACH_ENTRY_SAFE(pos, next, &manager->devList, DeviceInfoNode, node) { if (pos->payload.service == service) { - pos->payload.callback->ReportEventPkgCallback((const EventPackage **)pkgs, count); + pos->payload.callback->ReportEventPkgCallback((const EventPackage **)pkgs, count, pos->payload.devIndex); } } return INPUT_SUCCESS; @@ -116,9 +114,9 @@ static int32_t RegisterReportCallback(uint32_t devIndex, InputReportEventCb *cal return INPUT_FAILURE; } if (HdfDeviceRegisterEventListener(pos->payload.service, listener) != INPUT_SUCCESS) { - HDF_LOGE("%s: fail to register listener", __func__); free(listener); pthread_mutex_unlock(&manager->mutex); + HDF_LOGE("%s: fail to register listener", __func__); return INPUT_FAILURE; } manager->callbackNum++; @@ -129,8 +127,8 @@ static int32_t RegisterReportCallback(uint32_t devIndex, InputReportEventCb *cal return INPUT_SUCCESS; } - HDF_LOGE("%s: device%u doesn't exist, can't register callback", __func__, devIndex); pthread_mutex_unlock(&manager->mutex); + HDF_LOGE("%s: device%u doesn't exist, can't register callback", __func__, devIndex); return INPUT_FAILURE; } @@ -153,8 +151,8 @@ static int32_t UnregisterReportCallback(uint32_t devIndex) } if (pos->payload.callback != NULL) { if (HdfDeviceUnregisterEventListener(pos->payload.service, pos->payload.listener) != INPUT_SUCCESS) { - HDF_LOGE("%s: fail to unregister listener", __func__); pthread_mutex_unlock(&manager->mutex); + HDF_LOGE("%s: fail to unregister listener", __func__); return INPUT_FAILURE; } free(pos->payload.listener); @@ -165,15 +163,103 @@ static int32_t UnregisterReportCallback(uint32_t devIndex) HDF_LOGI("%s: device%u unregister callback succ", __func__, devIndex); return INPUT_SUCCESS; } else { + pthread_mutex_unlock(&manager->mutex); HDF_LOGE("%s: device%u does not register callback", __func__, devIndex); + return INPUT_FAILURE; } } - HDF_LOGE("%s: device%u doesn't exist, can't unregister callback", __func__, devIndex); pthread_mutex_unlock(&manager->mutex); + HDF_LOGE("%s: device%u doesn't exist, can't unregister callback", __func__, devIndex); return INPUT_FAILURE; } +static int32_t HotPlugEventListenerCallback(struct HdfDevEventlistener *listener, + struct HdfIoService *service, uint32_t id, struct HdfSBuf *data) +{ + (void)listener; + (void)id; + uint32_t len = 0; + HotPlugEvent *event = NULL; + InputDevManager *manager = NULL; + + if (service == NULL || data == NULL) { + HDF_LOGE("%s: invalid param", __func__); + return INPUT_INVALID_PARAM; + } + + GET_MANAGER_CHECK_RETURN(manager); + pthread_mutex_lock(&manager->mutex); + + if (!HdfSbufReadBuffer(data, (const void **)&event, &len)) { + HDF_LOGE("%s: sbuf read finished", __func__); + } + manager->hostDev.callback->ReportHotPlugEventCallback((const HotPlugEvent *)event); + pthread_mutex_unlock(&manager->mutex); + return INPUT_SUCCESS; +} + +static struct HdfDevEventlistener *HotPlugEventListenerInstance(void) +{ + struct HdfDevEventlistener *listener = (struct HdfDevEventlistener *)malloc(sizeof(struct HdfDevEventlistener)); + if (listener == NULL) { + HDF_LOGE("%s: instance listener failed", __func__); + return NULL; + } + + (void)memset_s(listener, sizeof(struct HdfDevEventlistener), 0, sizeof(struct HdfDevEventlistener)); + listener->onReceive = HotPlugEventListenerCallback; + return listener; +} + +static int32_t RegisterHotPlugCallback(InputReportEventCb *callback) +{ + InputDevManager *manager = NULL; + struct HdfIoService *service = NULL; + + if ((callback == NULL) || (callback->ReportHotPlugEventCallback == NULL)) { + HDF_LOGE("%s: invalid param", __func__); + return INPUT_INVALID_PARAM; + } + GET_MANAGER_CHECK_RETURN(manager); + + pthread_mutex_lock(&manager->mutex); + service = manager->hostDev.service; + if (service == NULL) { + manager->hostDev.service = HdfIoServiceBind(DEV_MANAGER_SERVICE_NAME); + service = manager->hostDev.service; + } + + struct HdfDevEventlistener *listener = HotPlugEventListenerInstance(); + if (listener == NULL) { + pthread_mutex_unlock(&manager->mutex); + HDF_LOGE("%s: fail to instance listener", __func__); + return INPUT_FAILURE; + } + if (HdfDeviceRegisterEventListener(service, listener) != INPUT_SUCCESS) { + pthread_mutex_unlock(&manager->mutex); + HDF_LOGE("%s: fail to register listener", __func__); + free(listener); + return INPUT_FAILURE; + } + manager->hostDev.callback = callback; + manager->hostDev.listener = (void *)listener; + pthread_mutex_unlock(&manager->mutex); + return INPUT_SUCCESS; +} + +static int32_t UnregisterHotPlugCallback(void) +{ + InputDevManager *manager = NULL; + GET_MANAGER_CHECK_RETURN(manager); + + pthread_mutex_lock(&manager->mutex); + manager->hostDev.callback = NULL; + manager->hostDev.listener = NULL; + pthread_mutex_unlock(&manager->mutex); + return INPUT_SUCCESS; +} + int32_t InstanceReporterHdi(InputReporter **reporter) { InputReporter *reporterHdi = (InputReporter *)malloc(sizeof(InputReporter)); @@ -186,6 +272,8 @@ int32_t InstanceReporterHdi(InputReporter **reporter) reporterHdi->RegisterReportCallback = RegisterReportCallback; reporterHdi->UnregisterReportCallback = UnregisterReportCallback; + reporterHdi->RegisterHotPlugCallback = RegisterHotPlugCallback; + reporterHdi->UnregisterHotPlugCallback = UnregisterHotPlugCallback; *reporter = reporterHdi; return INPUT_SUCCESS; diff --git a/input/interfaces/include/input_controller.h b/input/interfaces/include/input_controller.h index c90432cc8b..7bc4321c76 100644 --- a/input/interfaces/include/input_controller.h +++ b/input/interfaces/include/input_controller.h @@ -110,7 +110,7 @@ typedef struct { * @param devIndex Indicates the index of an input device. A maximum of 32 input devices are supported. * The value ranges from 0 to 31, and value 0 represents the first input device. * @param chipInfo Indicates the pointer to the chip information. - * @param length Indicates the length of the chip information. + * @param length Indicates the length of the chip information. The minimum value of length is 10. * @return Returns 0 if the operation is successful; returns an error code defined * in {@link RetStatus} otherwise. * @since 1.0 @@ -124,7 +124,7 @@ typedef struct { * @param devIndex Indicates the index of an input device. A maximum of 32 input devices are supported. * The value ranges from 0 to 31, and value 0 represents the first input device. * @param vendorName Indicates the pointer to the module vendor name. - * @param length Indicates the length of the module vendor name. + * @param length Indicates the length of the module vendor name. The minimum value of length is 10. * @return Returns 0 if the operation is successful; returns an error code defined * in {@link RetStatus} otherwise. * @since 1.0 @@ -138,7 +138,7 @@ typedef struct { * @param devIndex Indicates the index of an input device. A maximum of 32 input devices are supported. * The value ranges from 0 to 31, and value 0 represents the first input device. * @param chipName Indicates the pointer to the driver chip name. - * @param length Indicates the length of the driver chip name. + * @param length Indicates the length of the driver chip name. The minimum value of length is 10. * @return Returns 0 if the operation is successful; returns an error code defined * in {@link RetStatus} otherwise. * @since 1.0 @@ -173,7 +173,7 @@ typedef struct { * @param testType Indicates the capacitance test type. For details, see {@link CapacitanceTest}. * @param result Indicates the pointer to the capacitance test result. The value is SUCC for a successful * operation and is an error code for a failed operation. - * @param length Indicates the length of the test result. + * @param length Indicates the length of the test result. The minimum value of length is 20. * @return Returns 0 if the operation is successful; returns an error code defined * in {@link RetStatus} otherwise. * @since 1.0 diff --git a/input/interfaces/include/input_manager.h b/input/interfaces/include/input_manager.h index 15b2315bee..da41bda981 100644 --- a/input/interfaces/include/input_manager.h +++ b/input/interfaces/include/input_manager.h @@ -49,11 +49,24 @@ extern "C" { /** * @brief Provides interfaces for managing input devices. * - * The interfaces can be used to perform basic operations on the input devices, such as opening and closing the device - * files, querying information about a specified input device, and obtaining information about all input devices in - * the device list. + * The interfaces can be used to perform basic operations on the input devices, such as scanning online devices, + * opening and closing the device files, querying information about a specified input device, and obtaining information + * about all input devices in the device list. */ typedef struct { + /** + * @brief Scans all online input devices. + * + * @param staArr Indicates the pointer to the array storing information about the scanned input devices, + * including the device index and device type. + * @param arrLen Indicates the length of the array. + * @return Returns 0 if the operation is successful; returns an error code defined in + * {@link RetStatus} otherwise. + * @since 1.0 + * @version 1.0 + */ + int32_t (*ScanInputDevice)(DevDesc *staArr, uint32_t arrLen); + /** * @brief Opens a specified input device file. * @@ -99,8 +112,8 @@ typedef struct { * @param devList Indicates the double pointer to information about all devices in the device list. * For details, see {@link DeviceInfo}. * @param size Indicates the number of elements in the devList array. - * @return Returns 0 if the operation is successful; returns an error code defined - * in {@link RetStatus} otherwise. + * @return Returns 0 if the operation is successful; returns an error code defined in + * {@link RetStatus} otherwise. * @since 1.0 * @version 1.0 */ @@ -111,17 +124,15 @@ typedef struct { * @brief Defines interfaces for providing driver capabilities of input devices. */ typedef struct { - InputManager *iInputManager; /**< Device management interface for input devices */ - InputController *iInputController; /**< Service control interface for input devices */ - InputReporter *iInputReporter; /**< Data reporting interface for input devices */ + InputManager *iInputManager; /**< Device management interface for input devices */ + InputController *iInputController; /**< Service control interface for input devices */ + InputReporter *iInputReporter; /**< Data reporting interface for input devices */ } IInputInterface; /** * @brief Gets all interfaces for performing operations on input devices. * - * You can call this function after the input service is started. - * - * @param interface Indicates the double pointer to the interface for performing operations on input devices. + * @param interface Indicates the double pointer to the interfaces for performing operations on input devices. * @return Returns 0 if the operation is successful; returns an error code defined in * {@link RetStatus} otherwise. * @since 1.0 @@ -129,6 +140,17 @@ typedef struct { */ int32_t GetInputInterface(IInputInterface **interface); +/** + * @brief Releases all interfaces for performing operations on input devices. + * + * @param inputInterface Indicates the pointer to the interfaces for performing operations on input devices. + * @return Returns 0 if the operation is successful; returns an error code defined in + * {@link RetStatus} otherwise. + * @since 1.0 + * @version 1.0 + */ +int32_t ReleaseInputInterface(IInputInterface *inputInterface); + #ifdef __cplusplus } #endif diff --git a/input/interfaces/include/input_reporter.h b/input/interfaces/include/input_reporter.h index 2fde5ac4f7..855b782c0d 100644 --- a/input/interfaces/include/input_reporter.h +++ b/input/interfaces/include/input_reporter.h @@ -47,16 +47,15 @@ extern "C" { /** * @brief Provides interfaces for reporting event data of input devices. * - * The interfaces include the registration and unregistration of callbacks for reporting subscribed data of - * specified input devices. - * + * The interfaces include the registration and unregistration of callbacks for reporting subscribed data of specified + * input devices. */ typedef struct { /** * @brief Registers a callback for reporting subscribed data of specified input devices. * - * After this callback is successfully registered, the driver can report the input event data to the input - * service through this callback. + * After this callback is successfully registered, the driver can report the input event data to the input service + * through this callback. * * @param devIndex Indicates the index of an input device. A maximum of 32 input devices are supported. * The value ranges from 0 to 31, and value 0 represents the first input device. @@ -79,6 +78,29 @@ typedef struct { * @version 1.0 */ int32_t (*UnregisterReportCallback)(uint32_t devIndex); + + /** + * @brief Registers a hot plug callback to the HDIs for input devices. + * + * All input devices can use this callback to report hot plug events. + * + * @param callback Indicates the pointer to the callback to register. + * @return Returns 0 if the operation is successful; returns an error code defined in + * {@link RetStatus} otherwise. + * @since 1.0 + * @version 1.0 + */ + int32_t (*RegisterHotPlugCallback)(InputReportEventCb *callback); + + /** + * @brief Unregisters the hot plug callback of input devices. + * + * @return Returns 0 if the operation is successful; returns an error code defined in + * {@link RetStatus} otherwise. + * @since 1.0 + * @version 1.0 + */ + int32_t (*UnregisterHotPlugCallback)(void); } InputReporter; #ifdef __cplusplus diff --git a/input/interfaces/include/input_type.h b/input/interfaces/include/input_type.h index cb2877962f..96414b9387 100644 --- a/input/interfaces/include/input_type.h +++ b/input/interfaces/include/input_type.h @@ -52,6 +52,7 @@ extern "C" { #define CHIP_NAME_LEN 10 #define VENDOR_NAME_LEN 10 #define SELF_TEST_RESULT_LEN 20 +#define DEV_MANAGER_SERVICE_NAME "hdf_input_host" /** * @brief Enumerates return values. @@ -70,14 +71,15 @@ enum RetStatus { * @brief Enumerates input device types. */ enum InputDevType { - INDEV_TYPE_TOUCH, /**< Touchscreen */ - INDEV_TYPE_KEY, /**< Physical key */ - INDEV_TYPE_KEYBOARD, /**< Keyboard */ - INDEV_TYPE_MOUSE, /**< Mouse */ - INDEV_TYPE_BUTTON, /**< Virtual button */ - INDEV_TYPE_CROWN, /**< Watch crown */ - INDEV_TYPE_ENCODER, /**< Customized type of a specific function or event */ - INDEV_TYPE_UNKNOWN, /**< Unknown input device type */ + INDEV_TYPE_TOUCH, /**< Touchscreen */ + INDEV_TYPE_KEY, /**< Physical key */ + INDEV_TYPE_BUTTON, /**< Virtual button */ + INDEV_TYPE_CROWN, /**< Watch crown */ + INDEV_TYPE_ENCODER, /**< Customized type of a specific function or event */ + INDEV_TYPE_HID_BEGIN_POS = 33, /* HID type start position */ + INDEV_TYPE_MOUSE, /**< Mouse */ + INDEV_TYPE_KEYBOARD, /**< Keyboard */ + INDEV_TYPE_UNKNOWN, /**< Unknown input device type */ }; /** @@ -111,6 +113,17 @@ typedef struct { uint64_t timestamp; /**< Timestamp of the input event */ } EventPackage; +typedef struct { + uint32_t devIndex; + uint32_t devType; + uint32_t status; +} HotPlugEvent; + +typedef struct { + uint32_t devIndex; + uint32_t devType; +} DevDesc; + /** * @brief Describes the input event callback registered by the input service. */ @@ -118,15 +131,22 @@ typedef struct { /** * @brief Reports input event data by the registered callback. * - * @param eventData Indicates the pointer to the input event data reported by the input driver. + * @param pkgs describes the input event data package. * @param count Indicates the number of input event data packets. - * @param devIndex Indicates the index of an input device. A maximum of 32 input devices are supported. - * The value ranges from 0 to 31, and value 0 represents the first input device. + * @param devIndex Indicates the index of an input device. + * @since 1.0 + * @version 1.0 + */ + void (*ReportEventPkgCallback)(const EventPackage **pkgs, uint32_t count, uint32_t devIndex); + + /** + * @brief Reports hot plug event data by the registered callback. * + * @param event Indicates the pointer to the hot plug event data reported by the input driver. * @since 1.0 * @version 1.0 */ - void (*ReportEventPkgCallback)(const EventPackage **pkgs, uint32_t count); + void (*ReportHotPlugEventCallback)(const HotPlugEvent *event); } InputReportEventCb; /** diff --git a/input/test/BUILD.gn b/input/test/BUILD.gn index 2172fe6538..5a121442c5 100644 --- a/input/test/BUILD.gn +++ b/input/test/BUILD.gn @@ -11,15 +11,23 @@ # See the License for the specific language governing permissions and # limitations under the License. -import("//build/lite/config/component/lite_component.gni") -import("//build/lite/config/test.gni") +if (defined(ohos_lite)) { + import("//build/lite/config/component/lite_component.gni") + import("//build/lite/config/test.gni") -lite_component("hdf_test_input") { - # add hdf subsystem unittest - if (ohos_build_type == "debug") { + lite_component("hdf_test_input") { + # add hdf subsystem unittest + if (ohos_build_type == "debug") { + if (board_name == "hi3516dv300" || board_name == "hispark_taurus") { + deps = [ "unittest:hdf_peripheral_input_test" ] + } + } + features = [] + } +} else { + group("hdf_unittest_input") { if (board_name == "hi3516dv300" || board_name == "hispark_taurus") { - deps = [ "unittest:hdf_peripheral_input_test" ] + deps = [ "unittest:hdf_hi3516dv300_${ohos_kernel_type}_test_input" ] } } - features = [] } diff --git a/input/test/unittest/common/hdi_input_test.cpp b/input/test/unittest/common/hdi_input_test.cpp old mode 100755 new mode 100644 index 445c158059..8556ef4d7f --- a/input/test/unittest/common/hdi_input_test.cpp +++ b/input/test/unittest/common/hdi_input_test.cpp @@ -13,6 +13,7 @@ * limitations under the License. */ +#include "hdi_input_test.h" #include #include #include @@ -24,7 +25,6 @@ #include "osal_time.h" #include "hdf_log.h" #include "input_manager.h" -#include "hdi_input_test.h" using namespace testing::ext; @@ -49,8 +49,10 @@ void HdiInputTest::SetUpTestCase() void HdiInputTest::TearDownTestCase() { - free(g_inputInterface); - g_inputInterface = NULL; + if (g_inputInterface != NULL) { + free(g_inputInterface); + g_inputInterface = NULL; + } } void HdiInputTest::SetUp() @@ -68,7 +70,7 @@ void HdiInputTest::TearDown() } \ } while (0) -void ReportEventPkgCallback(const EventPackage **pkgs, uint32_t count) +static void ReportEventPkgCallback(const EventPackage **pkgs, uint32_t count, uint32_t devIndex) { if (pkgs == NULL) { return; @@ -78,6 +80,32 @@ void ReportEventPkgCallback(const EventPackage **pkgs, uint32_t count) } } +void ReportHotPlugEventPkgCallback(const HotPlugEvent *msg) +{ + if (msg == NULL) { + return; + } + HDF_LOGI("%s: status =%d devId=%d type =%d", __func__, msg->status, msg->devIndex, msg->devType); +} + +HWTEST_F(HdiInputTest, ScanInputDevice, TestSize.Level1) +{ + DevDesc sta[MAX_DEVICES] = {0}; + + HDF_LOGI("%s: [Input] RegisterCallbackAndReportData001 enter", __func__); + int32_t ret; + + INPUT_CHECK_NULL_POINTER(g_inputInterface, INPUT_NULL_PTR); + INPUT_CHECK_NULL_POINTER(g_inputInterface->iInputManager, INPUT_NULL_PTR); + + ret = g_inputInterface->iInputManager->ScanInputDevice(sta, sizeof(sta)/sizeof(DevDesc)); + if (!ret) { + HDF_LOGI("%s:%d, %d, %d, %d", __func__, sta[0].devType, sta[0].devIndex, sta[1].devType, sta[1].devIndex); + } + + EXPECT_EQ(ret, INPUT_SUCCESS); +} + /** * @tc.name: OpenInputDev001 * @tc.desc: open input device test @@ -315,7 +343,7 @@ HWTEST_F(HdiInputTest, RegisterCallback001, TestSize.Level1) /** * @tc.name: SetPowerStatus001 - * @tc.desc: set devcie power status test + * @tc.desc: set device power status test * @tc.type: FUNC * @tc.require: AR000F867T */ @@ -336,7 +364,7 @@ HWTEST_F(HdiInputTest, SetPowerStatus001, TestSize.Level1) /** * @tc.name: SetPowerStatus002 - * @tc.desc: set devcie power status test + * @tc.desc: set device power status test * @tc.type: FUNC * @tc.require: AR000F867T */ @@ -358,7 +386,7 @@ HWTEST_F(HdiInputTest, SetPowerStatus002, TestSize.Level1) /** * @tc.name: GetPowerStatus001 - * @tc.desc: get devcie power status test + * @tc.desc: get device power status test * @tc.type: FUNC * @tc.require: AR000F867S */ @@ -380,7 +408,7 @@ HWTEST_F(HdiInputTest, GetPowerStatus001, TestSize.Level1) /** * @tc.name: GetPowerStatus002 - * @tc.desc: get devcie power status test + * @tc.desc: get device power status test * @tc.type: FUNC * @tc.require: AR000F867S */ @@ -587,6 +615,7 @@ HWTEST_F(HdiInputTest, RegisterCallbackAndReportData001, TestSize.Level1) HDF_LOGI("%s: [Input] RegisterCallbackAndReportData001 enter", __func__); int32_t ret; g_callback.ReportEventPkgCallback = ReportEventPkgCallback; + g_callback.ReportHotPlugEventCallback = ReportHotPlugEventPkgCallback; INPUT_CHECK_NULL_POINTER(g_inputInterface, INPUT_NULL_PTR); INPUT_CHECK_NULL_POINTER(g_inputInterface->iInputReporter, INPUT_NULL_PTR); @@ -596,6 +625,12 @@ HWTEST_F(HdiInputTest, RegisterCallbackAndReportData001, TestSize.Level1) if (ret) { HDF_LOGE("%s: register callback failed for device 1, ret %d", __func__, ret); } + + ret = g_inputInterface->iInputReporter->RegisterHotPlugCallback(&g_callback); + if (ret) { + HDF_LOGE("%s: register callback failed for device manager, ret %d", __func__, ret); + } + EXPECT_EQ(ret, INPUT_SUCCESS); HDF_LOGI("%s: wait 10s for testing, pls touch the panel now", __func__); HDF_LOGI("%s: The event data is as following:", __func__); diff --git a/input/test/unittest/common/hdi_input_test.h b/input/test/unittest/common/hdi_input_test.h index 8dda23a5ce..bdc761264b 100644 --- a/input/test/unittest/common/hdi_input_test.h +++ b/input/test/unittest/common/hdi_input_test.h @@ -25,5 +25,6 @@ const int TOUCH_INDEX = 1; const int INVALID_INDEX = 5; const int NAME_MAX_LEN = 10; const int TEST_RESULT_LEN = 32; +const int MAX_DEVICES = 32; #endif -- Gitee