Skip to content

Commit

Permalink
Merge branch 'linux-rga-multi' of github.com:JeffyCN/mirrors
Browse files Browse the repository at this point in the history
  • Loading branch information
tsukumijima committed Oct 12, 2023
2 parents fe82b76 + c6105b0 commit f8c78f8
Show file tree
Hide file tree
Showing 11 changed files with 81 additions and 40 deletions.
5 changes: 5 additions & 0 deletions Android.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
23 changes: 18 additions & 5 deletions core/NormalRga.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion core/platform_gralloc4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@

#include <drm_fourcc.h>

#ifdef ANDROID_12
#ifdef USE_HARDWARE_ROCKCHIP
#include <hardware/hardware_rockchip.h>
#endif

Expand Down
2 changes: 1 addition & 1 deletion core/utils/android_utils/src/android_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include <ui/PixelFormat.h>
#include <hardware/hardware.h>

#ifdef ANDROID_12
#ifdef USE_HARDWARE_ROCKCHIP
#include <hardware/hardware_rockchip.h>
#endif

Expand Down
2 changes: 1 addition & 1 deletion im2d_api/im2d_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 2

#define RGA_API_SUFFIX

Expand Down
47 changes: 24 additions & 23 deletions im2d_api/src/im2d_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion include/drmrga.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#include <system/graphics.h>
#include <cutils/native_handle.h>

#ifdef ANDROID_12
#if defined(ANDROID_12) || defined(USE_HARDWARE_ROCKCHIP)
#include <hardware/hardware_rockchip.h>
#endif

Expand Down
4 changes: 4 additions & 0 deletions samples/im2d_api_demo/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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 += \
Expand Down
3 changes: 3 additions & 0 deletions samples/im2d_api_demo/rgaImDemo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@

#ifdef ANDROID
#include <ui/GraphicBuffer.h>
#if defined(ANDROID_12) || defined(USE_HARDWARE_ROCKCHIP)
#include <hardware/hardware_rockchip.h>
#endif
#endif

#include "im2d.hpp"
Expand Down
27 changes: 19 additions & 8 deletions samples/padding_demo/src/rga_padding_demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "im2d.hpp"

#include "utils.h"
#include "dma_alloc.h"

#define LOCAL_FILE_PATH "/data"

Expand All @@ -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;

Expand All @@ -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)) {
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}

0 comments on commit f8c78f8

Please sign in to comment.