From e33bc4a25091b0e26c30ad6108f135c3326f76c5 Mon Sep 17 00:00:00 2001 From: cww Date: Tue, 1 Aug 2023 14:51:35 +0800 Subject: [PATCH 1/5] CMakeLists.txt add RGA_ENABLE_INSTALL_SAMPLES Signed-off-by: cww Change-Id: I7660eeb837448963df735aa2ddd7c9109ed0d130 --- CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 35e65d3..019b7c4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -154,3 +154,7 @@ install(TARGETS ${STATIC_LIB_NAME} # build im2d api demo add_subdirectory(samples/im2d_api_demo) #add_subdirectory(samples) + +if (DEFINED RGA_ENABLE_INSTALL_SAMPLES) +install(DIRECTORY samples DESTINATION ${CMAKE_INSTALL_PREFIX}) +endif() From 566f903ea0b7596a50cc1dd0d5dbdb852c31156a Mon Sep 17 00:00:00 2001 From: Yu Qiaowei Date: Wed, 16 Aug 2023 16:47:13 +0800 Subject: [PATCH 2/5] samples: padding_demo: using dma32 Signed-off-by: Yu Qiaowei Change-Id: I5cacba2032a441919b2d1a3004e163f016d04363 --- samples/padding_demo/src/rga_padding_demo.cpp | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/samples/padding_demo/src/rga_padding_demo.cpp b/samples/padding_demo/src/rga_padding_demo.cpp index a4d06ae..0e53d7c 100644 --- a/samples/padding_demo/src/rga_padding_demo.cpp +++ b/samples/padding_demo/src/rga_padding_demo.cpp @@ -39,6 +39,7 @@ #include "im2d.hpp" #include "utils.h" +#include "dma_alloc.h" #define LOCAL_FILE_PATH "/data" @@ -47,6 +48,7 @@ int main() { int src_width, src_height, src_format; int dst_width, dst_height, dst_format; char *src_buf, *dst_buf; + int src_dma_fd, dst_dma_fd; int src_buf_size, dst_buf_size; int top, bottom, left, right; @@ -72,8 +74,18 @@ int main() { src_buf_size = src_width * src_height * get_bpp_from_format(src_format); dst_buf_size = dst_width * dst_height * get_bpp_from_format(dst_format); - src_buf = (char *)malloc(src_buf_size); - dst_buf = (char *)malloc(dst_buf_size); + ret = dma_buf_alloc(DMA_HEAP_DMA32_UNCACHE_PATCH, src_buf_size, &src_dma_fd, (void **)&src_buf); + if (ret < 0) { + printf("alloc src dma_heap buffer failed!\n"); + return -1; + } + + ret = dma_buf_alloc(DMA_HEAP_DMA32_UNCACHE_PATCH, dst_buf_size, &dst_dma_fd, (void **)&dst_buf); + if (ret < 0) { + printf("alloc dst dma_heap buffer failed!\n"); + dma_buf_free(src_buf_size, &src_dma_fd, src_buf); + return -1; + } /* fill image data */ if (0 != read_image_from_file(src_buf, LOCAL_FILE_PATH, src_width, src_height, src_format, 0)) { @@ -82,8 +94,8 @@ int main() { } memset(dst_buf, 0x80, dst_buf_size); - src_handle = importbuffer_virtualaddr(src_buf, src_buf_size); - dst_handle = importbuffer_virtualaddr(dst_buf, dst_buf_size); + src_handle = importbuffer_fd(src_dma_fd, src_buf_size); + dst_handle = importbuffer_fd(dst_dma_fd, dst_buf_size); if (src_handle == 0 || dst_handle == 0) { printf("importbuffer failed!\n"); goto release_buffer; @@ -130,10 +142,9 @@ int main() { if (dst_handle) releasebuffer_handle(dst_handle); - if (src_buf) - free(src_buf); - if (dst_buf) - free(dst_buf); +free_buf: + dma_buf_free(src_buf_size, &src_dma_fd, src_buf); + dma_buf_free(dst_buf_size, &dst_dma_fd, dst_buf); return ret; } From d2afc0a716218c4d60dd273059fa659a7ffad8bc Mon Sep 17 00:00:00 2001 From: Yu Qiaowei Date: Wed, 16 Aug 2023 17:04:45 +0800 Subject: [PATCH 3/5] normal: fill: add debug log Signed-off-by: Yu Qiaowei Change-Id: I5c8c38b313fafb6403fc1eccc29e541f711d0263 --- core/NormalRga.cpp | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/core/NormalRga.cpp b/core/NormalRga.cpp index 766223c..e3c5fa8 100644 --- a/core/NormalRga.cpp +++ b/core/NormalRga.cpp @@ -1512,6 +1512,14 @@ int RgaCollorFill(rga_info *dst) { return -ENODEV; } + /* print debug log by setting property vendor.rga.log as 1 */ + is_debug_log(); + if(is_out_log()) { + ALOGD("<<<<-------- print rgaLog -------->>>>"); + ALOGD("dst->hnd = 0x%lx\n", (unsigned long)dst->hnd); + ALOGD("dst: handle = %d, Fd = %.2d ,phyAddr = %p ,virAddr = %p\n", dst->handle, dst->fd, dst->phyAddr, dst->virAddr); + } + memset(&rgaReg, 0, sizeof(struct rga_req)); dstType = dstMmuFlag = 0; @@ -1571,6 +1579,11 @@ int RgaCollorFill(rga_info *dst) { return -EINVAL; } + if(is_out_log()) { + ALOGD("handle_flag: 0x%x\n", rgaReg.handle_flag); + ALOGD("dst: Fd/handle = %.2d , buf = %p, mmuFlag = %d, mmuType = %d\n", dstFd, dstBuf, dst->mmuFlag, dstType); + } + relDstRect.format = RkRgaCompatibleFormat(relDstRect.format); if (dstFd == 0) @@ -1685,11 +1698,11 @@ int RgaCollorFill(rga_info *dst) { NormalRgaMmuFlag(&rgaReg, dstMmuFlag, dstMmuFlag); } -#ifdef LINUX -#if __DEBUG - NormalRgaLogOutRgaReq(rgaReg); -#endif -#endif + if(is_out_log()) { + ALOGD("dstMmuFlag = %d\n", dstMmuFlag); + ALOGD("<<<<-------- rgaReg -------->>>>\n"); + NormalRgaLogOutRgaReq(rgaReg); + } if(dst->sync_mode == RGA_BLIT_ASYNC) { sync_mode = dst->sync_mode; From a2fae161ee1c3145a9fb20e98a8d83b6822c9c1c Mon Sep 17 00:00:00 2001 From: Yu Qiaowei Date: Wed, 16 Aug 2023 17:15:43 +0800 Subject: [PATCH 4/5] im2d_api: task: fixed the issue of abnormal req parameters Due to premature job release, the memory of req was reclaimed, resulting in potentially incorrect parameters being read by the driver. update to 1.9.3_[1] Signed-off-by: Yu Qiaowei Change-Id: I20e5cb0705808a266d73f7c4b1542f8f64ccbf44 --- im2d_api/im2d_version.h | 2 +- im2d_api/src/im2d_impl.cpp | 47 +++++++++++++++++++------------------- 2 files changed, 25 insertions(+), 24 deletions(-) diff --git a/im2d_api/im2d_version.h b/im2d_api/im2d_version.h index 761daec..354dd59 100644 --- a/im2d_api/im2d_version.h +++ b/im2d_api/im2d_version.h @@ -26,7 +26,7 @@ #define RGA_API_MAJOR_VERSION 1 #define RGA_API_MINOR_VERSION 9 #define RGA_API_REVISION_VERSION 3 -#define RGA_API_BUILD_VERSION 0 +#define RGA_API_BUILD_VERSION 1 #define RGA_API_SUFFIX diff --git a/im2d_api/src/im2d_impl.cpp b/im2d_api/src/im2d_impl.cpp index 12b54f5..6303619 100644 --- a/im2d_api/src/im2d_impl.cpp +++ b/im2d_api/src/im2d_impl.cpp @@ -2052,11 +2052,23 @@ IM_STATUS rga_job_cancel(im_job_handle_t job_handle) { IM_STATUS rga_job_submit(im_job_handle_t job_handle, int sync_mode, int acquire_fence_fd, int *release_fence_fd) { int ret; im_rga_job_t *job = NULL; - struct rga_user_request submit_request; + struct rga_user_request submit_request = {0}; if (rga_get_context() != IM_STATUS_SUCCESS) return IM_STATUS_FAILED; + switch (sync_mode) { + case IM_SYNC: + submit_request.sync_mode = RGA_BLIT_SYNC; + break; + case IM_ASYNC: + submit_request.sync_mode = RGA_BLIT_ASYNC; + break; + default: + IM_LOGE("illegal sync mode!\n"); + return IM_STATUS_ILLEGAL_PARAM; + } + g_im2d_job_manager.mutex.lock(); if (g_im2d_job_manager.job_map.count(job_handle) == 0) { @@ -2074,43 +2086,32 @@ IM_STATUS rga_job_submit(im_job_handle_t job_handle, int sync_mode, int acquire_ return IM_STATUS_FAILED; } - memset(&submit_request, 0x0, sizeof(submit_request)); - - submit_request.task_ptr = ptr_to_u64(&job->req); - submit_request.task_num = job->task_count; - submit_request.id = job->id; - g_im2d_job_manager.job_map.erase(job_handle); g_im2d_job_manager.job_count--; g_im2d_job_manager.mutex.unlock(); - free(job); - - switch (sync_mode) { - case IM_SYNC: - submit_request.sync_mode = RGA_BLIT_SYNC; - break; - case IM_ASYNC: - submit_request.sync_mode = RGA_BLIT_ASYNC; - break; - default: - IM_LOGE("illegal sync mode!\n"); - return IM_STATUS_ILLEGAL_PARAM; - } - + submit_request.task_ptr = ptr_to_u64(job->req); + submit_request.task_num = job->task_count; + submit_request.id = job->id; submit_request.acquire_fence_fd = acquire_fence_fd; ret = ioctl(rgaCtx->rgaFd, RGA_IOC_REQUEST_SUBMIT, &submit_request); if (ret < 0) { IM_LOGE(" %s(%d) start config fail: %s",__FUNCTION__, __LINE__,strerror(errno)); - return IM_STATUS_FAILED; + ret = IM_STATUS_FAILED; + goto free_job; + } else { + ret = IM_STATUS_SUCCESS; } if ((sync_mode == IM_ASYNC) && release_fence_fd) *release_fence_fd = submit_request.release_fence_fd; - return IM_STATUS_SUCCESS; +free_job: + free(job); + + return (IM_STATUS)ret; } IM_STATUS rga_job_config(im_job_handle_t job_handle, int sync_mode, int acquire_fence_fd, int *release_fence_fd) { From c6105b06ade0e5dc7f16924c7f0f5e9dcdb198bc Mon Sep 17 00:00:00 2001 From: Yu Qiaowei Date: Mon, 4 Sep 2023 16:04:55 +0800 Subject: [PATCH 5/5] replace dependency on ANDROID_12 by USE_HARDWARE_ROCKCHIP update to 1.9.3_[2] Signed-off-by: Yu Qiaowei Change-Id: I3090600c1262c1ee896e0d6cee6646dd026c6e03 --- Android.go | 5 +++++ core/platform_gralloc4.cpp | 2 +- core/utils/android_utils/src/android_utils.cpp | 2 +- im2d_api/im2d_version.h | 2 +- include/drmrga.h | 2 +- samples/im2d_api_demo/Android.mk | 4 ++++ samples/im2d_api_demo/rgaImDemo.cpp | 3 +++ 7 files changed, 16 insertions(+), 4 deletions(-) diff --git a/Android.go b/Android.go index 834fbff..cd60fe3 100644 --- a/Android.go +++ b/Android.go @@ -97,6 +97,11 @@ func getCflags(ctx android.BaseContext, sdkVersion int) ([]string) { } } + //Android 12开始使用libhardware_rockchip存放RK私有定义 + if (sdkVersion >= 31 ) { + cppflags = append(cppflags,"-DUSE_HARDWARE_ROCKCHIP") + } + //将需要区分的环境变量在此区域添加 //.... return cppflags } diff --git a/core/platform_gralloc4.cpp b/core/platform_gralloc4.cpp index d2ab7cb..0e81bb4 100644 --- a/core/platform_gralloc4.cpp +++ b/core/platform_gralloc4.cpp @@ -61,7 +61,7 @@ #include -#ifdef ANDROID_12 +#ifdef USE_HARDWARE_ROCKCHIP #include #endif diff --git a/core/utils/android_utils/src/android_utils.cpp b/core/utils/android_utils/src/android_utils.cpp index 801fd42..1db2dcc 100644 --- a/core/utils/android_utils/src/android_utils.cpp +++ b/core/utils/android_utils/src/android_utils.cpp @@ -25,7 +25,7 @@ #include #include -#ifdef ANDROID_12 +#ifdef USE_HARDWARE_ROCKCHIP #include #endif diff --git a/im2d_api/im2d_version.h b/im2d_api/im2d_version.h index 354dd59..354c672 100644 --- a/im2d_api/im2d_version.h +++ b/im2d_api/im2d_version.h @@ -26,7 +26,7 @@ #define RGA_API_MAJOR_VERSION 1 #define RGA_API_MINOR_VERSION 9 #define RGA_API_REVISION_VERSION 3 -#define RGA_API_BUILD_VERSION 1 +#define RGA_API_BUILD_VERSION 2 #define RGA_API_SUFFIX diff --git a/include/drmrga.h b/include/drmrga.h index f0ebf81..8d0f61a 100644 --- a/include/drmrga.h +++ b/include/drmrga.h @@ -33,7 +33,7 @@ #include #include -#ifdef ANDROID_12 +#if defined(ANDROID_12) || defined(USE_HARDWARE_ROCKCHIP) #include #endif diff --git a/samples/im2d_api_demo/Android.mk b/samples/im2d_api_demo/Android.mk index 91f3b5c..66d18e2 100644 --- a/samples/im2d_api_demo/Android.mk +++ b/samples/im2d_api_demo/Android.mk @@ -15,6 +15,10 @@ ifeq (1,$(strip $(shell expr $(PLATFORM_SDK_VERSION) \> 25))) LOCAL_CFLAGS += -DUSE_AHARDWAREBUFFER=1 endif +ifeq (1,$(strip $(shell expr $(PLATFORM_SDK_VERSION) \> 31))) +LOCAL_CFLAGS += -DUSE_HARDWARE_ROCKCHIP=1 +endif + LOCAL_CFLAGS += -Wall -Werror -Wunreachable-code LOCAL_C_INCLUDES += \ diff --git a/samples/im2d_api_demo/rgaImDemo.cpp b/samples/im2d_api_demo/rgaImDemo.cpp index c270fbf..37cc40b 100644 --- a/samples/im2d_api_demo/rgaImDemo.cpp +++ b/samples/im2d_api_demo/rgaImDemo.cpp @@ -29,6 +29,9 @@ #ifdef ANDROID #include +#if defined(ANDROID_12) || defined(USE_HARDWARE_ROCKCHIP) +#include +#endif #endif #include "im2d.hpp"