summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Android.mk155
-rw-r--r--GraphicBuffer.cpp196
-rw-r--r--GraphicBuffer.h55
-rw-r--r--README.txt36
-rw-r--r--RgaApi.h25
-rw-r--r--RockchipRga.cpp133
-rw-r--r--RockchipRga.h95
-rw-r--r--drm/DrmmodeRga.cpp586
-rw-r--r--drm/DrmmodeRga.h38
-rw-r--r--drm/DrmmodeRgaContext.h51
-rwxr-xr-xdrm/gralloc_rga.h17
-rw-r--r--drmrga.h121
-rw-r--r--mix/NormalRga.cpp2509
-rw-r--r--mix/gralloc_rga.h39
-rw-r--r--normal/NormalRga.cpp2506
-rw-r--r--normal/NormalRga.h270
-rw-r--r--normal/NormalRgaApi.cpp809
-rw-r--r--normal/NormalRgaContext.h23
-rw-r--r--normal/gralloc_rga.h39
-rw-r--r--tests/Android.mk592
-rw-r--r--tests/RockchipFileOps.cpp221
-rw-r--r--tests/RockchipFileOps.h20
-rw-r--r--tests/RockchipRgaBlit.cpp188
-rw-r--r--tests/RockchipRgaBlitSlt.cpp220
-rw-r--r--tests/RockchipRgaBlitUserSpace.cpp151
-rw-r--r--tests/RockchipRgaColorFill.cpp197
-rw-r--r--tests/RockchipRgaCopy.cpp195
-rw-r--r--tests/RockchipRgaCopyRgba.cpp170
-rw-r--r--tests/RockchipRgaCovertRgb565ToYuv.cpp177
-rw-r--r--tests/RockchipRgaCovertRgbaToYuv.cpp177
-rw-r--r--tests/RockchipRgaCovertYuvTenBitToNormalYuv.cpp195
-rw-r--r--tests/RockchipRgaCovertYuvToRgba.cpp176
-rw-r--r--tests/RockchipRgaPattenBuff.cpp175
-rw-r--r--tests/RockchipRgaRgbaMirror.cpp169
-rw-r--r--tests/RockchipRgaStereo.cpp187
-rw-r--r--tests/RockchipRgaStereoUserSpace.cpp173
-rw-r--r--version.h6
-rw-r--r--version.h.template6
-rwxr-xr-xversion.sh11
39 files changed, 11109 insertions, 0 deletions
diff --git a/Android.mk b/Android.mk
new file mode 100644
index 0000000..f3b34e6
--- /dev/null
+++ b/Android.mk
@@ -0,0 +1,155 @@
+LOCAL_PATH:= $(call my-dir)
+#================================================================
+ifneq ($(strip $(BOARD_USE_DRM)), true)
+include $(CLEAR_VARS)
+
+$(info $(shell $(LOCAL_PATH)/version.sh))
+
+LOCAL_CFLAGS += -DGL_GLEXT_PROTOTYPES -DEGL_EGLEXT_PROTOTYPES
+
+LOCAL_CFLAGS += -DROCKCHIP_GPU_LIB_ENABLE
+
+#LOCAL_CFLAGS += -Wall -Werror -Wunreachable-code
+
+LOCAL_C_INCLUDES += external/tinyalsa/include
+LOCAL_C_INCLUDES += hardware/rockchip/libgralloc
+LOCAL_C_INCLUDES += hardware/rk29/libgralloc_ump
+LOCAL_C_INCLUDES += $(LOCAL_PATH)/normal
+
+LOCAL_CFLAGS := \
+ -DLOG_TAG=\"librga-normal\"
+
+LOCAL_SHARED_LIBRARIES := \
+ libcutils \
+ liblog \
+ libutils \
+ libbinder \
+ libui \
+ libEGL \
+ libGLESv1_CM \
+ libgui \
+ libhardware
+
+#has no "external/stlport" from Android 6.0 on
+ifeq (1,$(strip $(shell expr $(PLATFORM_VERSION) \< 6.0)))
+LOCAL_C_INCLUDES += \
+ external/stlport/stlport
+
+LOCAL_SHARED_LIBRARIES += \
+ libstlport
+
+LOCAL_C_INCLUDES += bionic
+endif
+
+LOCAL_SRC_FILES:= \
+ RockchipRga.cpp \
+ GraphicBuffer.cpp \
+ normal/NormalRga.cpp \
+ normal/NormalRgaApi.cpp
+
+ifneq (1,$(strip $(shell expr $(PLATFORM_VERSION) \< 6.0)))
+ifeq ($(strip $(TARGET_BOARD_PLATFORM_GPU)), mali-t720)
+LOCAL_CFLAGS += -DMALI_PRODUCT_ID_T72X=1
+LOCAL_CFLAGS += -DMALI_AFBC_GRALLOC=0
+endif
+
+ifeq ($(strip $(TARGET_BOARD_PLATFORM_GPU)), mali-t760)
+LOCAL_CFLAGS += -DMALI_PRODUCT_ID_T76X=1
+LOCAL_CFLAGS += -DMALI_AFBC_GRALLOC=1
+endif
+
+ifeq ($(strip $(TARGET_BOARD_PLATFORM_GPU)), mali-t860)
+LOCAL_CFLAGS += -DMALI_PRODUCT_ID_T86X=1
+LOCAL_CFLAGS += -DMALI_AFBC_GRALLOC=1
+endif
+endif #android 6.0 and later
+
+ifeq ($(strip $(TARGET_BOARD_PLATFORM)),rk3368)
+LOCAL_CFLAGS += -DRK3368
+endif
+
+LOCAL_MODULE:= librga
+include $(BUILD_SHARED_LIBRARY)
+endif
+#############################################################################################
+#############################################################################################
+ifeq ($(strip $(BOARD_USE_DRM)), true)
+include $(CLEAR_VARS)
+
+$(info $(shell $(LOCAL_PATH)/version.sh))
+
+LOCAL_SRC_FILES += \
+ RockchipRga.cpp \
+ GraphicBuffer.cpp \
+ mix/NormalRga.cpp \
+ normal/NormalRgaApi.cpp
+
+LOCAL_MODULE := librga
+
+LOCAL_C_INCLUDES += external/libdrm/rockchip
+LOCAL_C_INCLUDES += hardware/rockchip/libgralloc
+LOCAL_C_INCLUDES += hardware/rk29/libgralloc_ump
+LOCAL_C_INCLUDES += $(LOCAL_PATH)/drm
+
+LOCAL_SHARED_LIBRARIES := libdrm
+LOCAL_SHARED_LIBRARIES += \
+ libdrm_rockchip \
+ liblog \
+ libui \
+ libcutils \
+ libhardware
+
+LOCAL_CFLAGS := \
+ -DLOG_TAG=\"librga-mix\"
+
+ifeq ($(strip $(TARGET_BOARD_PLATFORM)),rk3368)
+LOCAL_CFLAGS += -DRK3368_DRM=1
+endif
+
+LOCAL_MODULE_TAGS := optional
+#LOCAL_MODULE_RELATIVE_PATH := hw
+LOCAL_MODULE_CLASS := SHARED_LIBRARIES
+LOCAL_MODULE_SUFFIX := $(TARGET_SHLIB_SUFFIX)
+
+include $(BUILD_SHARED_LIBRARY)
+endif
+#===================================================================
+ifeq ($(strip $(BOARD_USE_DRM)), future)
+#############################################################################################
+ifeq ($(strip $(BOARD_USE_DRM)), true)
+include $(CLEAR_VARS)
+
+$(info $(shell $(LOCAL_PATH)/version.sh))
+
+LOCAL_SRC_FILES += \
+ RockchipRga.cpp \
+ GraphicBuffer.cpp \
+ drm/DrmmodeRga.cpp
+
+LOCAL_MODULE := librga
+
+LOCAL_C_INCLUDES += external/libdrm/rockchip
+LOCAL_C_INCLUDES += hardware/rockchip/libgralloc
+LOCAL_C_INCLUDES += hardware/rk29/libgralloc_ump
+LOCAL_C_INCLUDES += $(LOCAL_PATH)/drm
+
+LOCAL_SHARED_LIBRARIES := libdrm
+LOCAL_SHARED_LIBRARIES += \
+ libdrm_rockchip \
+ liblog \
+ libui \
+ libcutils \
+ libhardware
+
+LOCAL_CFLAGS := \
+ -DLOG_TAG=\"librga-drm\"
+
+LOCAL_MODULE_TAGS := optional
+#LOCAL_MODULE_RELATIVE_PATH := hw
+LOCAL_MODULE_CLASS := SHARED_LIBRARIES
+LOCAL_MODULE_SUFFIX := $(TARGET_SHLIB_SUFFIX)
+
+include $(BUILD_SHARED_LIBRARY)
+endif
+#===================================================================
+endif #it will be used when upstrean in the future
diff --git a/GraphicBuffer.cpp b/GraphicBuffer.cpp
new file mode 100644
index 0000000..963d8db
--- /dev/null
+++ b/GraphicBuffer.cpp
@@ -0,0 +1,196 @@
+/*
+ * Copyright (C) 2016 Rockchip Electronics Co.Ltd
+ * Authors:
+ * Zhiqin Wei <wzq@rock-chips.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ */
+#include "GraphicBuffer.h"
+#include <gralloc_rga.h>
+gralloc_module_t const *mAllocMod = NULL;
+
+enum {
+ GET_HANDLE_FD = GRALLOC_MODULE_PERFORM_GET_HADNLE_PRIME_FD,
+ GET_HADNLE_ATTRIBUTES = GRALLOC_MODULE_PERFORM_GET_HADNLE_ATTRIBUTES,
+ //GET_INTERNAL_FORMAT = GRALLOC_MODULE_PERFORM_GET_INTERNAL_FORMAT,
+ //GET_HADNLE_USAGE = GRALLOC_MODULE_PERFORM_GET_USAGE,
+};
+// ---------------------------------------------------------------------------
+int RkInitAllocModle()
+{
+ const hw_module_t *allocMod = NULL;
+ int ret = 0;
+
+ if (mAllocMod)
+ return 0;
+
+ ret= hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &allocMod);
+ ALOGE_IF(ret, "FATAL:can't find the %s module",GRALLOC_HARDWARE_MODULE_ID);
+ if (ret == 0)
+ mAllocMod = reinterpret_cast<gralloc_module_t const *>(allocMod);
+
+ return ret;
+}
+
+int RkRgaGetHandleFd(buffer_handle_t handle, int *fd)
+{
+ int op = GET_HANDLE_FD;
+ int ret = 0;
+
+ if (!mAllocMod)
+ ret = RkInitAllocModle();
+
+ if (ret)
+ return ret;
+
+ if (mAllocMod->perform)
+ mAllocMod->perform(mAllocMod, op, handle, fd);
+ else
+ return -ENODEV;
+
+ if (ret)
+ ALOGE("GraphicBufferGetHandldFd fail %d for:%s",ret,strerror(ret));
+ else if (false) {
+ ALOGD("fd = %d",*fd);
+ fprintf(stderr,"fd = %d\n", *fd);
+ }
+
+ return ret;
+}
+
+int RkRgaGetHandleAttributes(buffer_handle_t handle,
+ std::vector<int> *attrs)
+{
+ int op = GET_HADNLE_ATTRIBUTES;
+ int ret = 0;
+
+ if (!mAllocMod)
+ ret = RkInitAllocModle();
+
+ if (ret)
+ return ret;
+
+ if(!mAllocMod->perform)
+ return -ENODEV;
+
+#if RK3368_DRM
+ int w,h,pixel_stride,format,size;
+
+ op = GRALLOC_MODULE_PERFORM_GET_HADNLE_WIDTH;
+ mAllocMod->perform(mAllocMod, op, handle, &w);
+ op = GRALLOC_MODULE_PERFORM_GET_HADNLE_HEIGHT;
+ mAllocMod->perform(mAllocMod, op, handle, &h);
+ op = GRALLOC_MODULE_PERFORM_GET_HADNLE_STRIDE;
+ mAllocMod->perform(mAllocMod, op, handle, &pixel_stride);
+ op = GRALLOC_MODULE_PERFORM_GET_HADNLE_FORMAT;
+ mAllocMod->perform(mAllocMod, op, handle, &format);
+ op = GRALLOC_MODULE_PERFORM_GET_HADNLE_SIZE;
+ mAllocMod->perform(mAllocMod, op, handle, &size);
+
+ //add to attrs.
+ attrs->emplace_back(w);
+ attrs->emplace_back(h);
+ attrs->emplace_back(pixel_stride);
+ attrs->emplace_back(format);
+ attrs->emplace_back(size);
+
+#else
+ mAllocMod->perform(mAllocMod, op, handle, attrs);
+
+ if (ret)
+ ALOGE("GraphicBufferGetHandldAttributes fail %d for:%s",ret,strerror(ret));
+ else if (false) {
+ ALOGD("%d,%d,%d,%d,%d,%d",attrs->at(0),attrs->at(1),attrs->at(2),
+ attrs->at(3),attrs->at(4),attrs->at(5));
+ fprintf(stderr,"%d,%d,%d,%d,%d,%d\n",
+ attrs->at(0),attrs->at(1),attrs->at(2),
+ attrs->at(3),attrs->at(4),attrs->at(5));
+ }
+#endif
+
+ return ret;
+}
+
+int RkRgaGetHandleMapAddress(buffer_handle_t handle,
+ void **buf)
+{
+ int usage = GRALLOC_USAGE_SW_READ_MASK | GRALLOC_USAGE_SW_WRITE_MASK;
+ int ret = 0;
+
+ if (!mAllocMod)
+ ret = RkInitAllocModle();
+
+ if (ret)
+ return ret;
+
+ if (mAllocMod->lock)
+ ret = mAllocMod->lock(mAllocMod, handle, usage, 0, 0, 0, 0, buf);
+ else
+ return -ENODEV;
+
+ if (ret)
+ ALOGE("GetHandleMapAddress fail %d for:%s",ret,strerror(ret));
+
+ return ret;
+}
+
+int RkRgaGetRgaFormat(int format)
+{
+ switch (format)
+ {
+ case HAL_PIXEL_FORMAT_RGB_565:
+ return RK_FORMAT_RGB_565;
+ case HAL_PIXEL_FORMAT_RGB_888:
+ return RK_FORMAT_RGB_888;
+ case HAL_PIXEL_FORMAT_RGBA_8888:
+ return RK_FORMAT_RGBA_8888;
+ case HAL_PIXEL_FORMAT_RGBX_8888:
+ return RK_FORMAT_RGBX_8888;
+ case HAL_PIXEL_FORMAT_BGRA_8888:
+ return RK_FORMAT_BGRA_8888;
+ case HAL_PIXEL_FORMAT_YCrCb_420_SP:
+ return RK_FORMAT_YCrCb_420_SP;
+ case HAL_PIXEL_FORMAT_YCrCb_NV12:
+ return RK_FORMAT_YCbCr_420_SP;
+ case HAL_PIXEL_FORMAT_YCrCb_NV12_VIDEO:
+ return RK_FORMAT_YCbCr_420_SP;
+ case HAL_PIXEL_FORMAT_YCrCb_NV12_10:
+ return RK_FORMAT_YCbCr_420_SP_10B; //0x20
+ default:
+ ALOGE("Is unsupport format now,please fix");
+ return -1;
+ }
+}
+
+
+int RkRgaGetRgaFormatFromAndroid(int format)
+{
+ switch (format)
+ {
+ case HAL_PIXEL_FORMAT_RGB_565:
+ return RK_FORMAT_RGB_565;
+ case HAL_PIXEL_FORMAT_RGB_888:
+ return RK_FORMAT_RGB_888;
+ case HAL_PIXEL_FORMAT_RGBA_8888:
+ return RK_FORMAT_RGBA_8888;
+ case HAL_PIXEL_FORMAT_RGBX_8888:
+ return RK_FORMAT_RGBX_8888;
+ case HAL_PIXEL_FORMAT_BGRA_8888:
+ return RK_FORMAT_BGRA_8888;
+ case HAL_PIXEL_FORMAT_YCrCb_420_SP:
+ return RK_FORMAT_YCrCb_420_SP;
+ case HAL_PIXEL_FORMAT_YCrCb_NV12:
+ return RK_FORMAT_YCbCr_420_SP;
+ case HAL_PIXEL_FORMAT_YCrCb_NV12_VIDEO:
+ return RK_FORMAT_YCbCr_420_SP;
+ case HAL_PIXEL_FORMAT_YCrCb_NV12_10:
+ return RK_FORMAT_YCbCr_420_SP_10B;//0x20
+ default:
+ ALOGE("Is unsupport format now,please fix");
+ return -1;
+ }
+}
diff --git a/GraphicBuffer.h b/GraphicBuffer.h
new file mode 100644
index 0000000..f556047
--- /dev/null
+++ b/GraphicBuffer.h
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2016 Rockchip Electronics Co.Ltd
+ * Authors:
+ * Zhiqin Wei <wzq@rock-chips.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ */
+
+#ifndef _rk_graphic_buffer_h_
+#define _rk_graphic_buffer_h_
+#include <stdint.h>
+#include <vector>
+#include <sys/types.h>
+
+#include <system/window.h>
+#include <system/graphics.h>
+
+#include <utils/Thread.h>
+
+#include <EGL/egl.h>
+#include <GLES/gl.h>
+
+//////////////////////////////////////////////////////////////////////////////////
+#include <hardware/hardware.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <time.h>
+#include <unistd.h>
+
+#include <sys/mman.h>
+#include <linux/stddef.h>
+
+#include <hardware/rga.h>
+#include "stdio.h"
+
+#include <utils/Atomic.h>
+#include <utils/Errors.h>
+#include <utils/Log.h>
+
+#include "drmrga.h"
+// -------------------------------------------------------------------------------
+int RkRgaGetHandleFd(buffer_handle_t handle, int *fd);
+int RkRgaGetHandleAttributes(buffer_handle_t handle,
+ std::vector<int> *attrs);
+int RkRgaGetHandleMapAddress(buffer_handle_t handle,
+ void **buf);
+
+int RkRgaGetRgaFormat(int format);
+#endif
diff --git a/README.txt b/README.txt
new file mode 100644
index 0000000..e19f65a
--- /dev/null
+++ b/README.txt
@@ -0,0 +1,36 @@
+1、解压文档到hardware/rockchip/librga或者hardware/rk29/librga
+
+2、编译librga目录,推相应的库
+
+3、test目录提供几个测试代码,拷贝,旋转,合成等
+
+4、data目录是二进制源数据,数据太大存放到服务器,自行下载
+
+5、drm目录是用于drm框架的源码
+
+6、normal目录是用于早期rga框架的,兼容rga各个代。
+
+7、因为产品需要,出现了mix方案,所以驱动是normal的代码,安卓是drm版本的,因此重新整理了一套mix用于过度阶段。
+
+8、按照一定规则命名二进制文件
+/**********************************************************************************************************
+ in%dw%d-h%d-%s.yuv解释如下:
+--->第一个%d是文件的索引,一般为0,防止所有格式一样,导致无法使用,比如合成的时候,可能两个文件完全一样的属性
+--->第二个%d是宽的意思,这里的宽一般指虚宽
+--->第三个%d是宽的意思,这里的高一般指虚高
+--->第四个%s是格式的名字,目前格式名字如下:
+*****************************************************************
+*HAL_PIXEL_FORMAT_RGB_565: "rgb565"; *
+*HAL_PIXEL_FORMAT_RGB_888: "rgb888"; *
+*HAL_PIXEL_FORMAT_RGBA_8888: "rgba8888"; *
+*HAL_PIXEL_FORMAT_RGBX_8888: "rgbx8888"; *
+*HAL_PIXEL_FORMAT_BGRA_8888: "bgra8888"; *
+*HAL_PIXEL_FORMAT_YCrCb_420_SP: "crcb420sp"; *
+*HAL_PIXEL_FORMAT_YCrCb_NV12: "nv12"; *
+*HAL_PIXEL_FORMAT_YCrCb_NV12_VIDEO: "nv12"; *
+*HAL_PIXEL_FORMAT_YCrCb_NV12_10: "nv12_10"; *
+*****************************************************************
+*/
+
+9、本模块有rga相关说明文件,如有需要可联系图形部门索要
+
diff --git a/RgaApi.h b/RgaApi.h
new file mode 100644
index 0000000..32674de
--- /dev/null
+++ b/RgaApi.h
@@ -0,0 +1,25 @@
+/*
+ * Copyright (C) 2016 Rockchip Electronics Co.Ltd
+ * Authors:
+ * Zhiqin Wei <wzq@rock-chips.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ */
+
+#ifndef _rockchip_rga_api_h_
+#define _rockchip_rga_api_h_
+#ifdef __cplusplus
+extern "C" {
+#endif
+int RgaInit(void **ctx);
+int RgaDeInit(void *ctx);
+int RgaBlit(rga_info_t *src, rga_info_t *dst, rga_info_t *src1);
+int RgaCollorFill(rga_info_t *dst);
+#ifdef __cplusplus
+}
+#endif
+#endif
diff --git a/RockchipRga.cpp b/RockchipRga.cpp
new file mode 100644
index 0000000..e51e096
--- /dev/null
+++ b/RockchipRga.cpp
@@ -0,0 +1,133 @@
+/*
+ * Copyright (C) 2016 Rockchip Electronics Co.Ltd
+ * Authors:
+ * Zhiqin Wei <wzq@rock-chips.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ */
+
+#define LOG_NDEBUG 0
+#ifdef LOG_TAG
+#undef LOG_TAG
+#define LOG_TAG "rockchiprga"
+#endif
+
+#include <stdint.h>
+#include <sys/types.h>
+#include <math.h>
+#include <fcntl.h>
+#include <utils/misc.h>
+#include <signal.h>
+#include <time.h>
+
+#include <cutils/properties.h>
+
+#include <binder/IPCThreadState.h>
+#include <utils/Atomic.h>
+#include <utils/Errors.h>
+#include <utils/Log.h>
+#include <utils/Mutex.h>
+#include <utils/Singleton.h>
+
+#include <ui/PixelFormat.h>
+#include <ui/Rect.h>
+#include <ui/Region.h>
+#include <ui/DisplayInfo.h>
+#include <ui/GraphicBufferMapper.h>
+
+#include <gui/ISurfaceComposer.h>
+#include <gui/Surface.h>
+#include <gui/SurfaceComposerClient.h>
+
+#include "RockchipRga.h"
+#include "RgaApi.h"
+#include "version.h"
+
+namespace android {
+
+// ---------------------------------------------------------------------------
+ANDROID_SINGLETON_STATIC_INSTANCE(RockchipRga)
+
+Mutex RockchipRga::mMutex;
+
+RockchipRga::RockchipRga():
+ mSupportRga(false),
+ mLogOnce(0),
+ mLogAlways(0),
+ mContext(NULL)
+{
+ RkRgaInit();
+ ALOGI("Rga built version:%s", RK_GRAPHICS_VER);
+}
+
+RockchipRga::~RockchipRga()
+{
+ RgaDeInit(mContext);
+}
+
+int RockchipRga::RkRgaInit()
+{
+ int ret = 0;
+
+ ret = RgaInit(&mContext);
+ if(ret == 0)
+ mSupportRga = true;
+ else
+ mSupportRga = false;
+
+ return 0;
+}
+
+int RockchipRga::RkRgaGetBufferFd(buffer_handle_t handle, int *fd)
+{
+ int ret = 0;
+ ret = RkRgaGetHandleFd(handle, fd);
+ return ret;
+}
+
+int RockchipRga::RkRgaBlit(rga_info *src, rga_info *dst, rga_info *src1)
+{
+ int ret = 0;
+ ret = RgaBlit(src, dst, src1);
+ if (ret) {
+ RkRgaLogOutUserPara(src);
+ RkRgaLogOutUserPara(dst);
+ RkRgaLogOutUserPara(src1);
+ ALOGE("This output the user patamaters when rga call blit fail");
+ }
+ return ret;
+}
+
+int RockchipRga::RkRgaCollorFill(rga_info *dst)
+{
+ int ret = 0;
+ ret = RgaCollorFill(dst);
+ return ret;
+}
+
+int RockchipRga::RkRgaLogOutUserPara(rga_info *rgaInfo)
+{
+ if (!rgaInfo)
+ return -EINVAL;
+
+ ALOGD("fd-vir-phy-hnd-format[%d, %p, %p, %p, %d]", rgaInfo->fd,
+ rgaInfo->virAddr, rgaInfo->phyAddr, (void*)rgaInfo->hnd, rgaInfo->format);
+ ALOGD("rect[%d, %d, %d, %d, %d, %d, %d, %d]",
+ rgaInfo->rect.xoffset, rgaInfo->rect.yoffset,
+ rgaInfo->rect.width, rgaInfo->rect.height, rgaInfo->rect.wstride,
+ rgaInfo->rect.hstride, rgaInfo->rect.format, rgaInfo->rect.size);
+ ALOGD("f-blend-size-rotation-col-log-mmu[%d, %x, %d, %d, %d, %d, %d]",
+ rgaInfo->format, rgaInfo->blend, rgaInfo->bufferSize,
+ rgaInfo->rotation, rgaInfo->color, rgaInfo->testLog, rgaInfo->mmuFlag);
+ return 0;
+}
+
+// ---------------------------------------------------------------------------
+
+}
+; // namespace android
+
diff --git a/RockchipRga.h b/RockchipRga.h
new file mode 100644
index 0000000..3f4cd83
--- /dev/null
+++ b/RockchipRga.h
@@ -0,0 +1,95 @@
+/*
+ * Copyright (C) 2016 Rockchip Electronics Co.Ltd
+ * Authors:
+ * Zhiqin Wei <wzq@rock-chips.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ */
+
+#ifndef _rockchip_rga_h_
+#define _rockchip_rga_h_
+
+#include <stdint.h>
+#include <vector>
+#include <sys/types.h>
+
+#include <system/window.h>
+
+#include <utils/Thread.h>
+
+#ifndef UN_NEED_GL
+#include <EGL/egl.h>
+#include <GLES/gl.h>
+#endif
+
+//////////////////////////////////////////////////////////////////////////////////
+#include <hardware/hardware.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <time.h>
+#include <unistd.h>
+#include <utils/Singleton.h>
+
+#include <sys/mman.h>
+#include <linux/stddef.h>
+
+#include <hardware/rga.h>
+#include "stdio.h"
+
+#include "drmrga.h"
+#ifndef UN_NEED_GL
+#include "GraphicBuffer.h"
+#endif
+//////////////////////////////////////////////////////////////////////////////////
+
+namespace android {
+// -------------------------------------------------------------------------------
+
+class RockchipRga :public Singleton<RockchipRga>
+{
+/************************************public**************************************/
+
+public:
+
+ static inline RockchipRga& get() {return getInstance();}
+
+ int RkRgaInit();
+ int RkRgaGetBufferFd(buffer_handle_t handle, int *fd);
+ int RkRgaBlit(rga_info *src, rga_info *dst, rga_info *src1);
+ int RkRgaCollorFill(rga_info *dst);
+
+
+ void RkRgaSetLogOnceFlag(int log) {mLogOnce = log;}
+ void RkRgaSetAlwaysLogFlag(bool log) {mLogAlways = log;}
+ void RkRgaLogOutRgaReq(struct rga_req rgaReg);
+ int RkRgaLogOutUserPara(rga_info *rgaInfo);
+ inline bool RkRgaIsReady() { return mSupportRga; }
+
+/************************************private***********************************/
+private:
+ bool mSupportRga;
+ int mLogOnce;
+ int mLogAlways;
+ void * mContext;
+ static Mutex mMutex;
+
+ friend class Singleton<RockchipRga>;
+ RockchipRga();
+ ~RockchipRga();
+
+
+
+};
+
+// ---------------------------------------------------------------------------
+
+}; // namespace android
+
+#endif // ANDROID_BOOTANIMATION_H
+
diff --git a/drm/DrmmodeRga.cpp b/drm/DrmmodeRga.cpp
new file mode 100644
index 0000000..d1ba593
--- /dev/null
+++ b/drm/DrmmodeRga.cpp
@@ -0,0 +1,586 @@
+/*
+ * Copyright (C) 2016 Rockchip Electronics Co.Ltd
+ * Authors:
+ * Zhiqin Wei <wzq@rock-chips.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ */
+
+#include "DrmmodeRga.h"
+#include "../RgaApi.h"
+
+volatile int32_t refCount = 0;
+struct rgaContext *rgaCtx = NULL;
+
+int RgaBlit(rga_info *src, rga_info *dst, rga_info *src1)
+{
+ struct rgaContext *ctx = rgaCtx;
+ struct rga_image srcImage, dstImage, src1Image;
+ rga_rect_t relSrcRect,tmpSrcRect,relDstRect,tmpDstRect;
+ rga_rect_t relSrc1Rect,tmpSrc1Rect;
+ int srcFd,dstFd,src1Fd;
+ int degree = 0;
+ int ret = 0;
+ int planeAlpha;
+ int rotation = 0;
+ unsigned int blend;
+ bool perpixelAlpha;
+ drm_rga_t *pRects = NULL;
+ drm_rga_t rects;
+
+ if (!ctx) {
+ ALOGE("Try to use uninit rgaCtx=%p",ctx);
+ return -ENODEV;
+ }
+
+ if (!src && !dst && !src1) {
+ ALOGE("src = %p, dst = %p, src1 = %p", src, dst, src1);
+ return -EINVAL;
+ }
+
+ if (!src && !dst) {
+ ALOGE("src = %p, dst = %p", src, dst);
+ return -EINVAL;
+ }
+
+ if (src) {
+ rotation = src->rotation;
+ blend = src->blend;
+ memcpy(&relSrcRect, &src->rect, sizeof(rga_rect_t));
+ }
+ if (dst)
+ memcpy(&relDstRect, &dst->rect, sizeof(rga_rect_t));
+ if (src1)
+ memcpy(&relSrc1Rect, &src1->rect, sizeof(rga_rect_t));
+
+ srcFd = dstFd = src1Fd = -1;
+ if (src && src->hnd) {
+ ret = RkRgaGetHandleFd(src->hnd, &srcFd);
+ if (ret) {
+ ALOGE("dst handle get fd fail ret = %d,hnd=%p", ret, src->hnd);
+ printf("-dst handle get fd fail ret = %d,hnd=%p", ret, src->hnd);
+ return ret;
+ } else if (srcFd < 0)
+ ALOGE("dst handle get srcFd = %d,hnd=%p", srcFd, src->hnd);
+ if (!isRectValid(relSrcRect)) {
+ ret = getRgaRect(src->hnd, &tmpSrcRect);
+ if (ret)
+ return ret;
+ memcpy(&relSrcRect, &tmpSrcRect, sizeof(rga_rect_t));
+ }
+ if (relSrcRect.hstride == 0)
+ relSrcRect.hstride = relSrcRect.height;
+ }
+
+ if (dst && dst->hnd) {
+ ret = RkRgaGetHandleFd(dst->hnd, &dstFd);
+ if (ret) {
+ ALOGE("dst handle get fd fail ret = %d,hnd=%p", ret, &dst->hnd);
+ printf("-dst handle get fd fail ret = %d,hnd=%p", ret, &dst->hnd);
+ return ret;
+ }
+ if (!isRectValid(relDstRect)) {
+ ret = getRgaRect(dst->hnd, &tmpDstRect);
+ if (ret)
+ return ret;
+ memcpy(&relDstRect, &tmpDstRect, sizeof(rga_rect_t));
+ }
+ if (relDstRect.hstride == 0)
+ relDstRect.hstride = relDstRect.height;
+ }
+
+ if (src1 && src1->hnd) {
+ ret = RkRgaGetHandleFd(src1->hnd, &src1Fd);
+ if (ret) {
+ ALOGE("dst handle get fd fail ret = %d,hnd=%p", ret, &src1->hnd);
+ printf("-dst handle get fd fail ret = %d,hnd=%p", ret, &src1->hnd);
+ return ret;
+ }
+ if (!isRectValid(relSrcRect)) {
+ ret = getRgaRect(src1->hnd, &tmpSrc1Rect);
+ if (ret)
+ return ret;
+ memcpy(&relSrc1Rect, &tmpSrc1Rect, sizeof(rga_rect_t));
+ }
+ if (relSrc1Rect.hstride == 0)
+ relSrc1Rect.hstride = relSrc1Rect.height;
+ }
+
+ if (src && srcFd < 0)
+ srcFd = src->fd;
+
+ if (dst && dstFd < 0)
+ dstFd = dst->fd;
+
+ if (src1 && src1Fd < 0)
+ src1Fd = src1->fd;
+
+ if (src && srcFd < 0) {
+ ALOGE("Has not support without src fd now");
+ return -EINVAL;
+ }
+
+ if (dst && dstFd < 0) {
+ ALOGE("Has not support without dst fd now");
+ return -EINVAL;
+ }
+
+ if (src1 && src1Fd < 0) {
+ ALOGE("Has not support without src fd now");
+ return -EINVAL;
+ }
+ //check rects
+ //check buffer_handle_t with rects
+
+ memset(&srcImage, 0, sizeof(struct rga_image));
+ memset(&dstImage, 0, sizeof(struct rga_image));
+ memset(&src1Image, 0, sizeof(struct rga_image));
+
+ planeAlpha = (blend & 0xFF0000) >> 16;
+ perpixelAlpha = relSrcRect.format == HAL_PIXEL_FORMAT_RGBA_8888 ||
+ relSrcRect.format == HAL_PIXEL_FORMAT_BGRA_8888;
+
+ dstImage.bo[0] = dstFd;
+ srcImage.bo[0] = srcFd;
+ src1Image.bo[0] = src1Fd;
+
+ srcImage.buf_type = RGA_IMGBUF_GEM;
+ srcImage.width = relSrcRect.width;
+ srcImage.height = relSrcRect.height;
+ srcImage.hstride = relSrcRect.hstride;
+ srcImage.stride = computeRgaStrideByAndroidFormat(relSrcRect.wstride,
+ relSrcRect.format);
+ srcImage.color_mode = getDrmFomatFromAndroidFormat(relSrcRect.format);
+
+ if (!srcImage.color_mode) {
+ ALOGE("bad format : %d",srcImage.color_mode);
+ return -EINVAL;
+ }
+
+ dstImage.buf_type = RGA_IMGBUF_GEM;
+ dstImage.width = relDstRect.width;
+ dstImage.height = relDstRect.height;
+ dstImage.hstride = relDstRect.hstride;
+ dstImage.stride = computeRgaStrideByAndroidFormat(relDstRect.wstride,
+ relDstRect.format);
+ dstImage.color_mode = getDrmFomatFromAndroidFormat(relDstRect.format);
+
+ if (!dstImage.color_mode) {
+ ALOGE("bad format : %d",dstImage.color_mode);
+ return -EINVAL;
+ }
+
+ if (src1) {
+ src1Image.buf_type = RGA_IMGBUF_GEM;
+ src1Image.width = relSrc1Rect.width;
+ src1Image.height = relSrc1Rect.height;
+ src1Image.hstride = relSrcRect.hstride;
+ src1Image.stride = computeRgaStrideByAndroidFormat(relSrc1Rect.wstride,
+ relSrc1Rect.format);
+ src1Image.color_mode = getDrmFomatFromAndroidFormat(relSrc1Rect.format);
+
+ if (!src1Image.color_mode) {
+ ALOGE("bad format : %d",src1Image.color_mode);
+ return -EINVAL;
+ }
+ }
+
+ if ((rotation & DRM_RGA_TRANSFORM_ROT_90)
+ degree = 90;
+
+#if 0
+ printf("[0x%x]src[%d,%d,%d,%d][%d,%d],dst[%d,%d,%d,%d][%d,%d]\n",rotation,
+ relSrcRect.xoffset,relSrcRect.yoffset,
+ relSrcRect.width, relSrcRect.height,
+ relSrcRect.wstride,relSrcRect.hstride,
+ relDstRect.xoffset,relDstRect.yoffset,
+ relDstRect.width, relDstRect.height,
+ relDstRect.wstride,relDstRect.hstride);
+ ALOGD("[0x%x]src[%d,%d,%d,%d][%d,%d],dst[%d,%d,%d,%d][%d,%d]\n",rotation,
+ relSrcRect.xoffset,relSrcRect.yoffset,
+ relSrcRect.width, relSrcRect.height,
+ relSrcRect.wstride,relSrcRect.hstride,
+ relDstRect.xoffset,relDstRect.yoffset,
+ relDstRect.width, relDstRect.height,
+ relDstRect.wstride,relDstRect.hstride);
+ fprintf(stderr, "ctx=%p,ctx->ctx=%p\n",ctx,ctx->ctx);
+ ctx->ctx->log = 1;
+#endif
+
+ rga_multiple_transform(ctx->ctx, &srcImage, &dstImage,
+ relSrcRect.xoffset, relSrcRect.yoffset,
+ relSrcRect.width, relSrcRect.height,
+ relDstRect.xoffset, relDstRect.yoffset,
+ relDstRect.width, relDstRect.height,
+ degree, rotation & DRM_RGA_TRANSFORM_FLIP_H,
+ rotation & DRM_RGA_TRANSFORM_FLIP_V);
+
+ ret = rga_exec(ctx->ctx);
+ if (ret < 0) {
+ ALOGE("Handle by rga error");
+ return ret;
+ }
+ return 0;
+}
+
+int RgaCollorFill(rga_info *dst)
+{
+ if (!dst)
+ return -EINVAL;
+
+ return 0;
+}
+
+int drmRgaOpen(void **context)
+{
+
+ struct rockchip_device *dev = NULL;
+ struct rgaContext *ctx = NULL;
+ int fd = -1;
+ int ret = 0;
+
+ if (!context) {
+ ret = -EINVAL;
+ goto mallocErr;
+ }
+
+ if (!rgaCtx) {
+ ctx = (struct rgaContext *)malloc(sizeof(struct rgaContext));
+ if(!ctx) {
+ ret = -ENOMEM;
+ ALOGE("malloc fail:%s.",strerror(errno));
+ goto mallocErr;
+ }
+ } else {
+ ctx = rgaCtx;
+ ALOGW("Had init the rga dev ctx = %p",ctx);
+ goto init;
+ }
+
+ //fd = drmOpen(DRM_MODULE_NAME, NULL);
+ fd = open("/dev/dri/renderD128", O_RDWR);
+ if (fd < 0) {
+ ret = -ENODEV;
+ ALOGE("failed to open DRM:%s.",strerror(errno));
+ goto drmOpenErr;
+ }
+
+ dev = rockchip_device_create(fd);
+ if (!dev) {
+ ret = -ENODEV;
+ ALOGE("failed to create DRM device:%s.",strerror(errno));
+ goto devCreateErr;
+ }
+
+ ctx->ctx = rga_init(dev->fd);
+ if (!ctx->ctx) {
+ ret = -ENODEV;
+ ALOGE("failed to init rga dev:%s.",strerror(errno));
+ goto rgaInitErr;
+ }
+
+ fprintf(stderr, "ctx=%p,ctx->ctx=%p\n",ctx,ctx->ctx);
+ rgaCtx = ctx;
+
+init:
+ android_atomic_inc(&refCount);
+ *context = (void *)ctx;
+ return ret;
+
+loadModErr:
+rgaInitErr:
+ rockchip_device_destroy(dev);
+devCreateErr:
+ drmClose(fd);
+drmOpenErr:
+ free(ctx);
+mallocErr:
+ return ret;
+}
+
+int drmRgaClose(void *context)
+{
+ struct rgaContext *ctx = rgaCtx;
+
+ if (!ctx) {
+ ALOGE("Try to exit uninit rgaCtx=%p", ctx);
+ return -ENODEV;
+ }
+
+ if (context) {
+ ALOGE("Try to uninit rgaCtx=%p", context);
+ return -ENODEV;
+ }
+
+ if (context != ctx) {
+ ALOGE("Try to exit wrong ctx=%p",ctx);
+ return -ENODEV;
+ }
+
+ if (refCount <= 0) {
+ ALOGW("This can not be happened");
+ return 0;
+ }
+
+ if (refCount > 0 && android_atomic_dec(&refCount) != 1)
+ return 0;
+
+ rgaCtx = NULL;
+
+ rga_fini(ctx->ctx);
+
+ drmClose(ctx->dev->fd);
+ rockchip_device_destroy(ctx->dev);
+
+ free(ctx);
+
+ return 0;
+}
+
+int RgaInit(void **ctx)
+{
+ int ret = 0;
+ ret = drmRgaOpen(ctx);
+ return ret;
+}
+
+int RgaDeInit(void *ctx)
+{
+ int ret = 0;
+ ret = drmRgaClose(ctx);
+ return ret;
+}
+
+static int dumpRgaRects(drm_rga_t tmpRects)
+{
+ ALOGD("Src:[%d,%d,%d,%d][%d,%d,%d]=>Dst:[%d,%d,%d,%d][%d,%d,%d]",
+ tmpRects.src.xoffset,tmpRects.src.yoffset,
+ tmpRects.src.width, tmpRects.src.height,
+ tmpRects.src.wstride,tmpRects.src.format, tmpRects.src.size,
+ tmpRects.dst.xoffset,tmpRects.dst.yoffset,
+ tmpRects.dst.width, tmpRects.dst.height,
+ tmpRects.dst.wstride,tmpRects.dst.format, tmpRects.dst.size);
+ return 0;
+}
+
+static int isRectValid(rga_rect_t rect)
+{
+ return rect.width > 0 && rect.height > 0;
+}
+
+static int getRgaRect(buffer_handle_t hnd, rga_rect_t *rect)
+{
+ int ret = 0;
+ std::vector<int> dstAttrs;
+
+ if (!rect) {
+ ALOGE("Get rect but rect[%p] is null point", rect);
+ return -EINVAL;
+ }
+
+ ret = RkRgaGetHandleAttributes(hnd, &dstAttrs);
+ if (ret) {
+ ALOGE("dst handle get Attributes fail ret = %d,hnd=%p", ret, &hnd);
+ printf("dst handle get Attributes fail ret = %d,hnd=%p", ret, &hnd);
+ return ret;
+ }
+
+ if (dstAttrs.size() <= 0) {
+ ALOGE("SIZE = %d", (int)dstAttrs.size());
+ return -EINVAL;
+ }
+
+ memset(rect, 0, sizeof(rga_rect_t));
+
+ rect->size = dstAttrs.at(ASIZE);
+ rect->width = dstAttrs.at(AWIDTH);
+ rect->height = dstAttrs.at(AHEIGHT);
+ rect->wstride = dstAttrs.at(ASTRIDE);
+ rect->format = dstAttrs.at(AFORMAT);
+
+ return ret;
+}
+
+static int getRgaRects(buffer_handle_t src,
+ buffer_handle_t dst, drm_rga_t* tmpRects)
+{
+ int ret = 0;
+ std::vector<int> srcAttrs,dstAttrs;
+ ret = RkRgaGetHandleAttributes(src, &srcAttrs);
+ if (ret) {
+ ALOGE("dst handle get Attributes fail ret = %d,hnd=%p",ret,&src);
+ printf("dst handle get Attributes fail ret = %d,hnd=%p",ret,&src);
+ return ret;
+ }
+ ret = RkRgaGetHandleAttributes(dst, &dstAttrs);
+ if (ret) {
+ ALOGE("dst handle get Attributes fail ret = %d,hnd=%p",ret,&dst);
+ printf("dst handle get Attributes fail ret = %d,hnd=%p",ret,&dst);
+ return ret;
+ }
+
+ memset(tmpRects,0,sizeof(drm_rga_t));
+
+ tmpRects->src.size = srcAttrs.at(ASIZE);
+ tmpRects->src.width = srcAttrs.at(AWIDTH);
+ tmpRects->src.height = srcAttrs.at(AHEIGHT);
+ tmpRects->src.wstride = srcAttrs.at(ASTRIDE);
+ tmpRects->src.format = srcAttrs.at(AFORMAT);
+
+ tmpRects->dst.size = dstAttrs.at(ASIZE);
+ tmpRects->dst.width = dstAttrs.at(AWIDTH);
+ tmpRects->dst.height = dstAttrs.at(AHEIGHT);
+ tmpRects->dst.wstride = dstAttrs.at(ASTRIDE);
+ tmpRects->dst.format = dstAttrs.at(AFORMAT);
+
+ return ret;
+}
+
+static int getDrmFomatFromAndroidFormat(int format)
+{
+ int ret = 0;
+
+ switch (format) {
+ case HAL_PIXEL_FORMAT_RGBA_8888:
+ ret = DRM_FORMAT_RGBA8888;
+ break;
+
+ case HAL_PIXEL_FORMAT_RGBX_8888:
+ ret = DRM_FORMAT_RGBX8888;
+ break;
+
+ case HAL_PIXEL_FORMAT_RGB_888:
+ ret = DRM_FORMAT_RGB888;
+ break;
+
+ case HAL_PIXEL_FORMAT_RGB_565:
+ ret = DRM_FORMAT_RGB565;
+ break;
+
+ case HAL_PIXEL_FORMAT_BGRA_8888:
+ ret = DRM_FORMAT_BGRA8888;
+ break;
+
+ case HAL_PIXEL_FORMAT_sRGB_A_8888:
+ //ret = what?;
+ break;
+
+ case HAL_PIXEL_FORMAT_sRGB_X_8888:
+ //ret = what?;
+ break;
+
+ case HAL_PIXEL_FORMAT_YCbCr_422_SP:
+ ret = DRM_FORMAT_NV16;
+ break;
+
+ case HAL_PIXEL_FORMAT_YCrCb_420_SP:
+ ret = DRM_FORMAT_NV21;
+ break;
+
+ case HAL_PIXEL_FORMAT_YCbCr_422_I:
+ //ret = DRM_FORMAT_RGBX8888;
+ break;
+
+ case HAL_PIXEL_FORMAT_YCrCb_NV12:
+ ret = DRM_FORMAT_NV12;
+ break;
+
+ case HAL_PIXEL_FORMAT_YCrCb_NV12_VIDEO:
+ ret = DRM_FORMAT_NV12;
+ break;
+
+ case HAL_PIXEL_FORMAT_YCrCb_NV12_10:
+ ret = DRM_FORMAT_NV12_10;
+ break;
+
+ case HAL_PIXEL_FORMAT_YCbCr_422_SP_10:
+ //ret = DRM_FORMAT_RGBX8888;
+ break;
+
+
+ case HAL_PIXEL_FORMAT_YCrCb_420_SP_10:
+ //ret = DRM_FORMAT_RGBX8888;
+ break;
+
+ default:
+ ALOGD("Unsuport format %d", format);
+ break;
+ }
+ return ret;
+}
+
+static int getPixelWidthByDrmFormat(int format)
+{
+ return format;
+}
+
+static int getPixelWidthByAndroidFormat(int format)
+{
+ int pixelWidth = -1;
+ switch (format) {
+ case HAL_PIXEL_FORMAT_RGBA_8888:
+ case HAL_PIXEL_FORMAT_RGBX_8888:
+ case HAL_PIXEL_FORMAT_BGRA_8888:
+ pixelWidth = 4;
+ break;
+
+ case HAL_PIXEL_FORMAT_RGB_888:
+ pixelWidth = 3;
+ break;
+
+ case HAL_PIXEL_FORMAT_RGB_565:
+ pixelWidth = 2;
+ break;
+
+ case HAL_PIXEL_FORMAT_sRGB_A_8888:
+ case HAL_PIXEL_FORMAT_sRGB_X_8888:
+ ALOGE("format 0x%x not support",format);
+ break;
+
+ case HAL_PIXEL_FORMAT_YCbCr_422_SP:
+ case HAL_PIXEL_FORMAT_YCrCb_420_SP:
+ case HAL_PIXEL_FORMAT_YCbCr_422_I:
+ case HAL_PIXEL_FORMAT_YCrCb_NV12:
+ case HAL_PIXEL_FORMAT_YCrCb_NV12_VIDEO:
+ pixelWidth = 1;
+ break;
+
+ case HAL_PIXEL_FORMAT_YCrCb_NV12_10:
+ case HAL_PIXEL_FORMAT_YCbCr_422_SP_10:
+ case HAL_PIXEL_FORMAT_YCrCb_420_SP_10:
+ pixelWidth = 1;
+ break;
+
+ default:
+ ALOGE("format 0x%x not support",format);
+ break;
+ }
+ return pixelWidth;
+}
+
+static int computeRgaStrideByDrmFormat(int stride, int format)
+{
+ return stride * format;
+}
+
+static int computeRgaStrideByAndroidFormat(int stride, int format)
+{
+ int pixelWidth = 0;
+ int widthStride = 0;
+
+ pixelWidth = getPixelWidthByAndroidFormat(format);
+
+ if (pixelWidth < 0)
+ return -EINVAL;
+
+ widthStride = stride * pixelWidth;
+
+ //if (format == HAL_PIXEL_FORMAT_YCrCb_NV12_10)
+ // widthStride = widthStride * 5 / 4;
+
+ return widthStride;
+}
diff --git a/drm/DrmmodeRga.h b/drm/DrmmodeRga.h
new file mode 100644
index 0000000..3d28c52
--- /dev/null
+++ b/drm/DrmmodeRga.h
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2016 Rockchip Electronics Co.Ltd
+ * Authors:
+ * Zhiqin Wei <wzq@rock-chips.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ */
+
+#ifndef _rk_drm_drm_rga_api_
+#define _rk_drm_drm_rga_api_
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+#include "drmrga.h"
+#include <android/native_window.h>
+
+#include <utils/Log.h>
+#include <cutils/atomic.h>
+
+#include "DrmmodeRgaContext.h"
+#include "../GraphicBuffer.h"
+
+static int dumpRgaRects(drm_rga_t tmpRects);
+static int isRectValid(rga_rect_t rect);
+static int getDrmFomatFromAndroidFormat(int format);
+static int getRgaRect(buffer_handle_t hnd, rga_rect_t *rect);
+static int getRgaRects(buffer_handle_t src, buffer_handle_t dst, drm_rga_t* tmpRects);
+static int getPixelWidthByDrmFormat(int format);
+static int getPixelWidthByAndroidFormat(int format);
+static int computeRgaStrideByDrmFormat(int stride, int format);
+static int computeRgaStrideByAndroidFormat(int stride, int format);
+#endif
diff --git a/drm/DrmmodeRgaContext.h b/drm/DrmmodeRgaContext.h
new file mode 100644
index 0000000..db7aed6
--- /dev/null
+++ b/drm/DrmmodeRgaContext.h
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2016 Rockchip Electronics Co.Ltd
+ * Authors:
+ * Zhiqin Wei <wzq@rock-chips.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ */
+
+#ifndef _rk_drm_rga_rga_context_
+#define _rk_drm_rga_rga_context_
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <time.h>
+#include <unistd.h>
+
+#include <sys/mman.h>
+#include <linux/stddef.h>
+
+#include <xf86drm.h>
+#include <xf86drmMode.h>
+//#include <libkms.h>
+#include <drm_fourcc.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+#include "rockchip_drm.h"
+#include "rockchip_drmif.h"
+#include "rockchip_rga.h"
+#ifdef __cplusplus
+}
+#endif
+
+#include <utils/Mutex.h>
+
+#define DRM_MODULE_NAME "rockchip"
+
+#define UNUSED(...) (void)(__VA_ARGS__)
+
+struct rgaContext{
+ rga_context *ctx;
+ struct rockchip_device *dev;
+};
+#endif
diff --git a/drm/gralloc_rga.h b/drm/gralloc_rga.h
new file mode 100755
index 0000000..2757fc9
--- /dev/null
+++ b/drm/gralloc_rga.h
@@ -0,0 +1,17 @@
+/*
+ * Copyright (C) 2016 Rockchip Electronics Co.Ltd
+ * Authors:
+ * Zhiqin Wei <wzq@rock-chips.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ */
+
+#ifndef _rockchip_rga_drm_gralloc_h_
+#define _rockchip_rga_drm_gralloc_h_
+#include <hardware/gralloc.h>
+
+#endif
diff --git a/drmrga.h b/drmrga.h
new file mode 100644
index 0000000..6d39b0d
--- /dev/null
+++ b/drmrga.h
@@ -0,0 +1,121 @@
+/*
+ * Copyright (C) 2016 Rockchip Electronics Co.Ltd
+ * Authors:
+ * Zhiqin Wei <wzq@rock-chips.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ */
+
+#ifndef _rk_drm_rga_
+#define _rk_drm_rga_
+
+#define DRMRGA_HARDWARE_MODULE_ID "librga"
+
+#include <stdint.h>
+#include <sys/cdefs.h>
+
+#include <hardware/gralloc.h>
+#include <hardware/hardware.h>
+#include <system/graphics.h>
+#include <cutils/native_handle.h>
+
+
+/*****************************************************************************/
+
+/* for compatibility */
+#define DRM_RGA_MODULE_API_VERSION HWC_MODULE_API_VERSION_0_1
+#define DRM_RGA_DEVICE_API_VERSION HWC_DEVICE_API_VERSION_0_1
+#define DRM_RGA_API_VERSION HWC_DEVICE_API_VERSION
+
+#define DRM_RGA_TRANSFORM_ROT_MASK 0x0000000F
+#define DRM_RGA_TRANSFORM_ROT_0 0x00000000
+#define DRM_RGA_TRANSFORM_ROT_90 HAL_TRANSFORM_ROT_90
+#define DRM_RGA_TRANSFORM_ROT_180 HAL_TRANSFORM_ROT_180
+#define DRM_RGA_TRANSFORM_ROT_270 HAL_TRANSFORM_ROT_270
+
+#define DRM_RGA_TRANSFORM_FLIP_MASK 0x00000003
+#define DRM_RGA_TRANSFORM_FLIP_H HAL_TRANSFORM_FLIP_H
+#define DRM_RGA_TRANSFORM_FLIP_V HAL_TRANSFORM_FLIP_V
+
+enum {
+ AWIDTH = 0,
+ AHEIGHT,
+ ASTRIDE,
+ AFORMAT,
+ ASIZE,
+ ATYPE,
+};
+/*****************************************************************************/
+
+/*
+ @value size: user not need care about.For avoid read/write out of memory
+ */
+typedef struct rga_rect {
+ int xoffset;
+ int yoffset;
+ int width;
+ int height;
+ int wstride;
+ int hstride;
+ int format;
+ int size;
+} rga_rect_t;
+
+/*
+ @value fd: use fd to share memory, it can be ion shard fd,and dma fd.
+ @value virAddr:userspace address
+ @value phyAddr:use phy address
+ @value hnd: use buffer_handle_t
+ */
+typedef struct rga_info {
+ int fd;
+ void *virAddr;
+ void *phyAddr;
+ buffer_handle_t hnd;
+ int format;
+ rga_rect_t rect;
+ unsigned int blend;
+ int bufferSize;
+ int rotation;
+ int color;
+ int testLog;
+ int mmuFlag;
+ int reserve[128];
+} rga_info_t;
+
+typedef struct drm_rga {
+ rga_rect_t src;
+ rga_rect_t dst;
+} drm_rga_t;
+
+/*
+ @fun rga_set_rect:For use to set the rects esayly
+
+ @param rect:The rect user want to set,like setting the src rect:
+ drm_rga_t rects;
+ rga_set_rect(rects.src,0,0,1920,1080,1920,NV12);
+ mean to set the src rect to the value.
+ */
+static inline int rga_set_rect(rga_rect_t *rect,
+ int x, int y, int w, int h, int sw, int sh, int f)
+{
+ if (!rect)
+ return -EINVAL;
+
+ rect->xoffset = x;
+ rect->yoffset = y;
+ rect->width = w;
+ rect->height = h;
+ rect->wstride = sw;
+ rect->hstride = sh;
+ rect->format = f;
+
+ return 0;
+}
+/*****************************************************************************/
+
+#endif
diff --git a/mix/NormalRga.cpp b/mix/NormalRga.cpp
new file mode 100644
index 0000000..3b1c6dd
--- /dev/null
+++ b/mix/NormalRga.cpp
@@ -0,0 +1,2509 @@
+/*
+ * Copyright (C) 2016 Rockchip Electronics Co.Ltd
+ * Authors:
+ * Zhiqin Wei <wzq@rock-chips.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ */
+#include "../normal/NormalRga.h"
+#include "../normal/NormalRgaContext.h"
+#include "../GraphicBuffer.h"
+#include "../RgaApi.h"
+
+#define RGA_BUF_GEM_TYPE_MASK 0xC0
+#define RGA_BUF_GEM_TYPE_DMA 0x80
+
+volatile int32_t refCount = 0;
+struct rgaContext *rgaCtx = NULL;
+
+void NormalRgaSetLogOnceFlag(int log)
+{
+ struct rgaContext *ctx = NULL;
+
+ ctx->mLogOnce = log;
+ return;
+}
+
+void NormalRgaSetAlwaysLogFlag(int log)
+{
+ struct rgaContext *ctx = NULL;
+
+ ctx->mLogAlways = log;
+ return;
+}
+
+int NormalRgaOpen(void **context)
+{
+ struct rgaContext *ctx = NULL;
+ char buf[30];
+ int fd = -1;
+ int ret = 0;
+
+ if (!context) {
+ ret = -EINVAL;
+ goto mallocErr;
+ }
+
+ if (!rgaCtx) {
+ ctx = (struct rgaContext *)malloc(sizeof(struct rgaContext));
+ if(!ctx) {
+ ret = -ENOMEM;
+ ALOGE("malloc fail:%s.",strerror(errno));
+ goto mallocErr;
+ }
+ } else {
+ ctx = rgaCtx;
+ ALOGW("Had init the rga dev ctx = %p",ctx);
+ goto init;
+ }
+
+ fd = open("/dev/rga", O_RDWR, 0);
+ if (fd < 0) {
+ ret = -ENODEV;
+ ALOGE("failed to open DRM:%s.",strerror(errno));
+ goto drmOpenErr;
+ }
+ ctx->rgaFd = fd;
+
+ ret = ioctl(fd, RGA_GET_VERSION, buf);
+ ctx->mVersion = atof(buf);
+ fprintf(stderr, "librga:RGA_GET_VERSION:%s,%f\n", buf, ctx->mVersion);
+
+ NormalRgaInitTables();
+
+ fprintf(stderr, "ctx=%p,ctx->rgaFd=%d\n",ctx, ctx->rgaFd );
+ rgaCtx = ctx;
+
+init:
+ android_atomic_inc(&refCount);
+ *context = (void *)ctx;
+ return ret;
+
+loadModErr:
+rgaInitErr:
+devCreateErr:
+ close(fd);
+drmOpenErr:
+ free(ctx);
+mallocErr:
+ return ret;
+}
+
+int NormalRgaClose(void *context)
+{
+ struct rgaContext *ctx = rgaCtx;
+
+ if (!ctx) {
+ ALOGE("Try to exit uninit rgaCtx=%p", ctx);
+ return -ENODEV;
+ }
+
+ if (!context) {
+ ALOGE("Try to uninit rgaCtx=%p", context);
+ return -ENODEV;
+ }
+
+ if (context != ctx) {
+ ALOGE("Try to exit wrong ctx=%p",ctx);
+ return -ENODEV;
+ }
+
+ if (refCount <= 0) {
+ ALOGW("This can not be happened");
+ return 0;
+ }
+
+ if (refCount > 0 && android_atomic_dec(&refCount) != 1)
+ return 0;
+
+ rgaCtx = NULL;
+
+ close(ctx->rgaFd);
+
+ free(ctx);
+
+ return 0;
+}
+
+int RgaInit(void **ctx)
+{
+ int ret = 0;
+ ret = NormalRgaOpen(ctx);
+ return ret;
+}
+
+int RgaDeInit(void *ctx)
+{
+ int ret = 0;
+ ret = NormalRgaClose(ctx);
+ return ret;
+}
+
+int NormalRgaPaletteTable(buffer_handle_t dst,
+ unsigned int v, drm_rga_t *rects)
+{
+ //check rects
+ //check buffer_handle_t with rects
+ struct rgaContext *ctx = rgaCtx;
+ int srcVirW,srcVirH,srcActW,srcActH,srcXPos,srcYPos;
+ int dstVirW,dstVirH,dstActW,dstActH,dstXPos,dstYPos;
+ int scaleMode,rotateMode,orientation,ditherEn;
+ int srcType,dstType,srcMmuFlag,dstMmuFlag;
+ int planeAlpha;
+ int dstFd = -1;
+ int srcFd = -1;
+ int ret = 0;
+ drm_rga_t tmpRects,relRects;
+ struct rga_req rgaReg;
+ bool perpixelAlpha;
+ void *srcBuf = NULL;
+ void *dstBuf = NULL;
+ RECT clip;
+
+ if (!ctx) {
+ ALOGE("Try to use uninit rgaCtx=%p",ctx);
+ return -ENODEV;
+ }
+
+ if (rects && (ctx->mLogAlways || ctx->mLogOnce)) {
+ ALOGD("Src:[%d,%d,%d,%d][%d,%d,%d]=>Dst:[%d,%d,%d,%d][%d,%d,%d]",
+ rects->src.xoffset,rects->src.yoffset,
+ rects->src.width, rects->src.height,
+ rects->src.wstride,rects->src.format, rects->src.size,
+ rects->dst.xoffset,rects->dst.yoffset,
+ rects->dst.width, rects->dst.height,
+ rects->dst.wstride,rects->dst.format, rects->dst.size);
+ }
+
+ memset(&rgaReg, 0, sizeof(struct rga_req));
+
+ srcType = dstType = srcMmuFlag = dstMmuFlag = 0;
+
+ ret = NormalRgaGetRects(NULL, dst, &srcType, &dstType, &tmpRects);
+ if (ret && !rects) {
+ ALOGE("%d:Has not rects for render", __LINE__);
+ return ret;
+ }
+
+ if (rects) {
+ if (rects->src.wstride > 0 && rects->dst.wstride > 0)
+ memcpy(&relRects, rects, sizeof(drm_rga_t));
+ else if (rects->src.wstride > 0) {
+ memcpy(&(relRects.src), &(rects->src), sizeof(rga_rect_t));
+ memcpy(&(relRects.dst), &(tmpRects.dst), sizeof(rga_rect_t));
+ } else if (rects->dst.wstride > 0) {
+ memcpy(&(relRects.src), &(tmpRects.src), sizeof(rga_rect_t));
+ memcpy(&(relRects.dst), &(rects->dst), sizeof(rga_rect_t));
+ }
+ } else
+ memcpy(&relRects, &tmpRects, sizeof(drm_rga_t));
+
+ if (ctx->mLogAlways || ctx->mLogOnce) {
+ ALOGD("Src:[%d,%d,%d,%d][%d,%d,%d]=>Dst:[%d,%d,%d,%d][%d,%d,%d]",
+ tmpRects.src.xoffset,tmpRects.src.yoffset,
+ tmpRects.src.width, tmpRects.src.height,
+ tmpRects.src.wstride,tmpRects.src.format, tmpRects.src.size,
+ tmpRects.dst.xoffset,tmpRects.dst.yoffset,
+ tmpRects.dst.width, tmpRects.dst.height,
+ tmpRects.dst.wstride,tmpRects.dst.format, tmpRects.dst.size);
+ ALOGD("Src:[%d,%d,%d,%d][%d,%d,%d]=>Dst:[%d,%d,%d,%d][%d,%d,%d]",
+ relRects.src.xoffset,relRects.src.yoffset,
+ relRects.src.width, relRects.src.height,
+ relRects.src.wstride,relRects.src.format, relRects.src.size,
+ relRects.dst.xoffset,relRects.dst.yoffset,
+ relRects.dst.width, relRects.dst.height,
+ relRects.dst.wstride,relRects.dst.format, relRects.dst.size);
+ }
+
+ RkRgaGetHandleMapAddress(dst, &dstBuf);
+ RkRgaGetHandleFd(dst, &dstFd);
+ if (dstFd == -1 && !dstBuf) {
+ ALOGE("%d:dst has not fd and address for render", __LINE__);
+ return ret;
+ }
+
+ if (dstFd == 0 && !dstBuf) {
+ ALOGE("dstFd is zero, now driver not support");
+ return -EINVAL;
+ } else
+ dstFd = -1;
+
+ orientation = 0;
+ rotateMode = 0;
+ srcVirW = relRects.src.wstride;
+ srcVirH = relRects.src.height;
+ srcXPos = relRects.src.xoffset;
+ srcYPos = relRects.src.yoffset;
+ srcActW = relRects.src.width;
+ srcActH = relRects.src.height;
+
+ dstVirW = relRects.dst.wstride;
+ dstVirH = relRects.dst.height;
+ dstXPos = relRects.dst.xoffset;
+ dstYPos = relRects.dst.yoffset;
+ dstActW = relRects.dst.width;
+ dstActH = relRects.dst.height;
+
+ NormalRgaSetSrcActiveInfo(&rgaReg, srcActW, srcActH, srcXPos, srcYPos);
+ NormalRgaSetDstActiveInfo(&rgaReg, dstActW, dstActH, dstXPos, dstYPos);
+ NormalRgaSetSrcVirtualInfo(&rgaReg, (unsigned long)srcBuf,
+ (unsigned long)srcBuf + srcVirW * srcVirH,
+ (unsigned long)srcBuf + srcVirW * srcVirH * 5/4,
+ srcVirW, srcVirH,
+ RkRgaGetRgaFormat(relRects.src.format),0);
+ /*dst*/
+ NormalRgaSetDstVirtualInfo(&rgaReg, (unsigned long)dstBuf,
+ (unsigned long)dstBuf + dstVirW * dstVirH,
+ (unsigned long)dstBuf + dstVirW * dstVirH * 5/4,
+ dstVirW, dstVirH, &clip,
+ RkRgaGetRgaFormat(relRects.dst.format),0);
+ NormalRgaSetPatInfo(&rgaReg, dstVirW, dstVirH,
+ dstXPos, dstYPos, relRects.dst.format);
+ NormalRgaSetFadingEnInfo(&rgaReg, v & 0xFF000000, v & 0xFF0000, v & 0xFF00);
+
+ /*mode*/
+ NormalRgaUpdatePaletteTableMode(&rgaReg, 0, v & 0xFF);
+
+ if (srcMmuFlag || dstMmuFlag) {
+ NormalRgaMmuInfo(&rgaReg, 1, 0, 0, 0, 0, 2);
+ NormalRgaMmuFlag(&rgaReg, srcMmuFlag, dstMmuFlag);
+ }
+
+ if (ctx->mLogAlways || ctx->mLogOnce)
+ NormalRgaLogOutRgaReq(rgaReg);
+
+ if(ioctl(ctx->rgaFd, RGA_BLIT_SYNC, &rgaReg)) {
+ printf(" %s(%d) RGA_BLIT fail: %s",__FUNCTION__, __LINE__,strerror(errno));
+ ALOGE(" %s(%d) RGA_BLIT fail: %s",__FUNCTION__, __LINE__,strerror(errno));
+ }
+
+ if (ctx->mLogOnce)
+ ctx->mLogOnce = 0;
+
+ return 0;
+}
+
+int RgaBlit(rga_info *src, rga_info *dst, rga_info *src1)
+{
+ //check rects
+ //check buffer_handle_t with rects
+ struct rgaContext *ctx = rgaCtx;
+ int srcVirW,srcVirH,srcActW,srcActH,srcXPos,srcYPos;
+ int dstVirW,dstVirH,dstActW,dstActH,dstXPos,dstYPos;
+ int src1VirW,src1VirH,src1ActW,src1ActH,src1XPos,src1YPos;
+ int scaleMode,rotateMode,orientation,ditherEn;
+ int srcType,dstType,src1Type,srcMmuFlag,dstMmuFlag,src1MmuFlag;
+ int planeAlpha;
+ int dstFd = -1;
+ int srcFd = -1;
+ int src1Fd = -1;
+ int rotation;
+ int ret = 0;
+ rga_rect_t relSrcRect,tmpSrcRect,relDstRect,tmpDstRect;
+ rga_rect_t relSrc1Rect,tmpSrc1Rect;
+ struct rga_req rgaReg;
+ unsigned int yuvToRgbMode;
+ unsigned int blend;
+ bool perpixelAlpha;
+ void *srcBuf = NULL;
+ void *dstBuf = NULL;
+ void *src1Buf = NULL;
+ RECT clip;
+
+ if (!ctx) {
+ ALOGE("Try to use uninit rgaCtx=%p",ctx);
+ return -ENODEV;
+ }
+
+ memset(&rgaReg, 0, sizeof(struct rga_req));
+
+ srcType = dstType = srcMmuFlag = dstMmuFlag = 0;
+ src1Type = src1MmuFlag = 0;
+ yuvToRgbMode = 0;
+ rotation = 0;
+ blend = 0;
+
+ if (!src && !dst && !src1) {
+ ALOGE("src = %p, dst = %p, src1 = %p", src, dst, src1);
+ return -EINVAL;
+ }
+
+ if (!src && !dst) {
+ ALOGE("src = %p, dst = %p", src, dst);
+ return -EINVAL;
+ }
+
+ if (src) {
+ rotation = src->rotation;
+ blend = src->blend;
+ memcpy(&relSrcRect, &src->rect, sizeof(rga_rect_t));
+ }
+
+ if (dst)
+ memcpy(&relDstRect, &dst->rect, sizeof(rga_rect_t));
+ if (src1)
+ memcpy(&relSrc1Rect, &src1->rect, sizeof(rga_rect_t));
+
+ srcFd = dstFd = src1Fd = -1;
+ if (src && src->hnd) {
+ ret = RkRgaGetHandleFd(src->hnd, &srcFd);
+ if (ret) {
+ ALOGE("dst handle get fd fail ret = %d,hnd=%p", ret, &src->hnd);
+ printf("-dst handle get fd fail ret = %d,hnd=%p", ret, &src->hnd);
+ return ret;
+ }
+ if (!isRectValid(relSrcRect)) {
+ ret = NormalRgaGetRect(src->hnd, &tmpSrcRect);
+ if (ret)
+ return ret;
+ memcpy(&relSrcRect, &tmpSrcRect, sizeof(rga_rect_t));
+ }
+ NormalRgaGetMmuType(src->hnd, &srcType);
+ }
+
+ if (dst && dst->hnd) {
+ ret = RkRgaGetHandleFd(dst->hnd, &dstFd);
+ if (ret) {
+ ALOGE("dst handle get fd fail ret = %d,hnd=%p", ret, &dst->hnd);
+ printf("-dst handle get fd fail ret = %d,hnd=%p", ret, &dst->hnd);
+ return ret;
+ }
+ if (!isRectValid(relDstRect)) {
+ ret = NormalRgaGetRect(dst->hnd, &tmpDstRect);
+ if (ret)
+ return ret;
+ memcpy(&relDstRect, &tmpDstRect, sizeof(rga_rect_t));
+ }
+ NormalRgaGetMmuType(dst->hnd, &dstType);
+ }
+
+ if (src1 && src1->hnd) {
+ ret = RkRgaGetHandleFd(src1->hnd, &src1Fd);
+ if (ret) {
+ ALOGE("dst handle get fd fail ret = %d,hnd=%p", ret, &src1->hnd);
+ printf("-dst handle get fd fail ret = %d,hnd=%p", ret, &src1->hnd);
+ return ret;
+ }
+ if (!isRectValid(relSrcRect)) {
+ ret = NormalRgaGetRect(src1->hnd, &tmpSrc1Rect);
+ if (ret)
+ return ret;
+ memcpy(&relSrc1Rect, &tmpSrc1Rect, sizeof(rga_rect_t));
+ }
+ NormalRgaGetMmuType(src1->hnd, &src1Type);
+ }
+
+ if (src && srcFd < 0)
+ srcFd = src->fd;
+
+ if (src && src->phyAddr)
+ srcBuf = src->phyAddr;
+ else if (src && src->virAddr)
+ srcBuf = src->virAddr;
+
+ if (srcFd == -1 && !srcBuf) {
+ ALOGE("%d:src has not fd and address for render", __LINE__);
+ return ret;
+ }
+
+ if (srcFd == 0 && !srcBuf) {
+ ALOGE("srcFd is zero, now driver not support");
+ return -EINVAL;
+ }
+
+ if (srcFd == 0)
+ srcFd = -1;
+
+ if (dst && dstFd < 0)
+ dstFd = dst->fd;
+
+ if (dst && dst->phyAddr)
+ dstBuf = dst->phyAddr;
+ else if (dst && dst->virAddr)
+ dstBuf = dst->virAddr;
+
+ if (dst && dstFd == -1 && !dstBuf) {
+ ALOGE("%d:dst has not fd and address for render", __LINE__);
+ return ret;
+ }
+
+ if (dst && dstFd == 0 && !dstBuf) {
+ ALOGE("dstFd is zero, now driver not support");
+ return -EINVAL;
+ }
+
+ if (dstFd == 0)
+ dstFd = -1;
+
+ if (src1 && src1Fd < 0)
+ src1Fd = src1->fd;
+
+ if (src1 && src1->phyAddr)
+ src1Buf = src1->phyAddr;
+ else if (src1 && src1->virAddr)
+ src1Buf = src1->virAddr;
+
+ if (src1 && src1Fd == -1 && !src1Buf) {
+ ALOGE("%d:dst has not fd and address for render", __LINE__);
+ return ret;
+ }
+
+ if (src1 && src1Fd == 0 && !src1Buf) {
+ ALOGE("dstFd is zero, now driver not support");
+ return -EINVAL;
+ }
+
+ if (src1Fd == 0)
+ src1Fd = -1;
+
+ planeAlpha = (blend & 0xFF0000) >> 16;
+ perpixelAlpha = relSrcRect.format == HAL_PIXEL_FORMAT_RGBA_8888 ||
+ relSrcRect.format == HAL_PIXEL_FORMAT_BGRA_8888;
+
+ switch ((blend & 0xFFFF)) {
+ case 0x0105:
+ if (perpixelAlpha && planeAlpha < 255)
+ NormalRgaSetAlphaEnInfo(&rgaReg, 1, 2, planeAlpha , 1, 9, 0);
+ else if (perpixelAlpha)
+ NormalRgaSetAlphaEnInfo(&rgaReg, 1, 1, 0, 1, 3, 0);
+ else
+ NormalRgaSetAlphaEnInfo(&rgaReg, 1, 0, planeAlpha , 0, 0, 0);
+ break;
+
+ case 0x0405:
+ if (perpixelAlpha && planeAlpha < 255)
+ NormalRgaSetAlphaEnInfo(&rgaReg, 1, 2, planeAlpha , 0, 0, 0);
+ else if (perpixelAlpha)
+ NormalRgaSetAlphaEnInfo(&rgaReg, 1, 1, 0, 0, 0, 0);
+ else
+ NormalRgaSetAlphaEnInfo(&rgaReg, 1, 0, planeAlpha , 0, 0, 0);
+ break;
+
+ case 0x0100:
+ default:
+ /* Tips: BLENDING_NONE is non-zero value, handle zero value as
+ * BLENDING_NONE. */
+ /* C = Cs
+ * A = As */
+ break;
+ }
+
+ if (relSrcRect.hstride == 0)
+ relSrcRect.hstride = relSrcRect.height;
+
+ if (relDstRect.hstride == 0)
+ relDstRect.hstride = relDstRect.height;
+
+ if (relSrc1Rect.hstride == 0)
+ relSrc1Rect.hstride = relSrc1Rect.height;
+
+ //if (relSrcRect.format == HAL_PIXEL_FORMAT_YCrCb_NV12_10)
+ // relSrcRect.wstride = relSrcRect.wstride * 5 / 4;
+
+ if (src) {
+ ret = checkRectForRga(relSrcRect);
+ if (ret) {
+ ALOGE("[%s,%d]Error src rect for rga blit", __func__, __LINE__);
+ return ret;
+ }
+ }
+
+ if (dst) {
+ ret = checkRectForRga(relDstRect);
+ if (ret) {
+ ALOGE("[%s,%d]Error dst rect for rga blit", __func__, __LINE__);
+ return ret;
+ }
+ }
+
+ if (src1) {
+ ret = checkRectForRga(relSrc1Rect);
+ if (ret) {
+ ALOGE("[%s,%d]Error src1 rect for rga blit", __func__, __LINE__);
+ return ret;
+ }
+ }
+
+ if (src && dst) {
+ float hScale = (float)relSrcRect.width / relDstRect.width;
+ float vScale = (float)relSrcRect.height / relDstRect.height;
+ if (rotation & HAL_TRANSFORM_ROT_90) {
+ hScale = (float)relSrcRect.width / relDstRect.height;
+ vScale = (float)relSrcRect.height / relDstRect.width;
+ }
+ if (hScale < 1/16 || hScale > 16 || vScale < 1/16 || vScale > 16) {
+ ALOGE("Error scale[%f,%f] line %d", hScale, vScale, __LINE__);
+ return -EINVAL;
+ }
+ if (ctx->mVersion <= 2.0 && (hScale < 1/8 ||
+ hScale > 8 || vScale < 1/8 || vScale > 8)) {
+ ALOGE("Error scale[%f,%f] line %d", hScale, vScale, __LINE__);
+ return -EINVAL;
+ }
+ if (ctx->mVersion <= 1.003 && (hScale < 1/2 || vScale < 1/2)) {
+ ALOGE("e scale[%f,%f] ver[%f]", hScale, vScale, ctx->mVersion);
+ return -EINVAL;
+ }
+ }
+
+ switch (rotation) {
+ case HAL_TRANSFORM_FLIP_H:
+ orientation = 0;
+ rotateMode = 2;
+ srcVirW = relSrcRect.wstride;
+ srcVirH = relSrcRect.hstride;
+ srcXPos = relSrcRect.xoffset;
+ srcYPos = relSrcRect.yoffset;
+ srcActW = relSrcRect.width;
+ srcActH = relSrcRect.height;
+
+ dstVirW = relDstRect.wstride;
+ dstVirH = relDstRect.height;
+ dstXPos = relDstRect.xoffset;
+ dstYPos = relDstRect.yoffset;
+ dstActW = relDstRect.width;
+ dstActH = relDstRect.height;
+ break;
+ case HAL_TRANSFORM_FLIP_V:
+ orientation = 0;
+ rotateMode = 3;
+ srcVirW = relSrcRect.wstride;
+ srcVirH = relSrcRect.hstride;
+ srcXPos = relSrcRect.xoffset;
+ srcYPos = relSrcRect.yoffset;
+ srcActW = relSrcRect.width;
+ srcActH = relSrcRect.height;
+
+ dstVirW = relDstRect.wstride;
+ dstVirH = relDstRect.height;
+ dstXPos = relDstRect.xoffset;
+ dstYPos = relDstRect.yoffset;
+ dstActW = relDstRect.width;
+ dstActH = relDstRect.height;
+ break;
+ case HAL_TRANSFORM_ROT_90:
+ orientation = 90;
+ rotateMode = 1;
+ srcVirW = relSrcRect.wstride;
+ srcVirH = relSrcRect.hstride;
+ srcXPos = relSrcRect.xoffset;
+ srcYPos = relSrcRect.yoffset;
+ srcActW = relSrcRect.width;
+ srcActH = relSrcRect.height;
+
+ dstVirW = relDstRect.wstride;
+ dstVirH = relDstRect.height;
+ dstXPos = relDstRect.width - 1;
+ //dstYPos = relDstRect.yoffset;
+ dstYPos = 0;
+ dstActW = relDstRect.height;
+ dstActH = relDstRect.width;
+ break;
+ case HAL_TRANSFORM_ROT_180:
+ orientation = 180;
+ rotateMode = 1;
+ srcVirW = relSrcRect.wstride;
+ srcVirH = relSrcRect.hstride;
+ srcXPos = relSrcRect.xoffset;
+ srcYPos = relSrcRect.yoffset;
+ srcActW = relSrcRect.width;
+ srcActH = relSrcRect.height;
+
+ dstVirW = relDstRect.wstride;
+ dstVirH = relDstRect.height;
+ dstXPos = relDstRect.width - 1;
+ dstYPos = relDstRect.height - 1;
+ dstActW = relDstRect.width;
+ dstActH = relDstRect.height;
+ break;
+ case HAL_TRANSFORM_ROT_270:
+ orientation = 270;
+ rotateMode = 1;
+ srcVirW = relSrcRect.wstride;
+ srcVirH = relSrcRect.hstride;
+ srcXPos = relSrcRect.xoffset;
+ srcYPos = relSrcRect.yoffset;
+ srcActW = relSrcRect.width;
+ srcActH = relSrcRect.height;
+
+ dstVirW = relDstRect.wstride;
+ dstVirH = relDstRect.height;
+ //dstXPos = relDstRect.xoffset;
+ dstXPos = 0;
+ dstYPos = relDstRect.height - 1;
+ dstActW = relDstRect.height;
+ dstActH = relDstRect.width;
+ break;
+ default:
+ orientation = 0;
+ rotateMode = 0;
+ srcVirW = relSrcRect.wstride;
+ srcVirH = relSrcRect.hstride;
+ srcXPos = relSrcRect.xoffset;
+ srcYPos = relSrcRect.yoffset;
+ srcActW = relSrcRect.width;
+ srcActH = relSrcRect.height;
+
+ dstVirW = relDstRect.wstride;
+ dstVirH = relDstRect.height;
+ dstXPos = relDstRect.xoffset;
+ dstYPos = relDstRect.yoffset;
+ dstActW = relDstRect.width;
+ dstActH = relDstRect.height;
+ break;
+ }
+
+ clip.xmin = 0;
+ clip.xmax = dstActW - 1;
+ clip.ymin = 0;
+ clip.ymax = dstActH - 1;
+
+ scaleMode = 0;
+ //scale up use bicubic
+ if (srcActW / dstActW < 1 || srcActH / dstActH < 1)
+ scaleMode = 2;
+
+ /*
+ if (scaleMode && (srcFormat == RK_FORMAT_RGBA_8888 ||
+ srcFormat == RK_FORMAT_BGRA_8888)) {
+ scale_mode = 0; // force change scale_mode to 0 ,for rga not support
+ }*/
+
+ ditherEn = (android::bytesPerPixel(relSrcRect.format)
+ != android::bytesPerPixel(relSrcRect.format) ? 1 : 0);
+
+
+ if (ctx->mVersion <= 1.003) {
+ srcMmuFlag = dstMmuFlag = 1;
+
+#if defined(__arm64__) || defined(__aarch64__)
+ NormalRgaSetSrcVirtualInfo(&rgaReg, (unsigned long)srcBuf,
+ (unsigned long)srcBuf + srcVirW * srcVirH,
+ (unsigned long)srcBuf + srcVirW * srcVirH * 5/4,
+ srcVirW, srcVirH,
+ RkRgaGetRgaFormat(relSrcRect.format),0);
+ /*dst*/
+ NormalRgaSetDstVirtualInfo(&rgaReg, (unsigned long)dstBuf,
+ (unsigned long)dstBuf + dstVirW * dstVirH,
+ (unsigned long)dstBuf + dstVirW * dstVirH * 5/4,
+ dstVirW, dstVirH, &clip,
+ RkRgaGetRgaFormat(relDstRect.format),0);
+#else
+ NormalRgaSetSrcVirtualInfo(&rgaReg, (unsigned int)srcBuf,
+ (unsigned int)srcBuf + srcVirW * srcVirH,
+ (unsigned int)srcBuf + srcVirW * srcVirH * 5/4,
+ srcVirW, srcVirH,
+ RkRgaGetRgaFormat(relSrcRect.format),0);
+ /*dst*/
+ NormalRgaSetDstVirtualInfo(&rgaReg, (unsigned int)dstBuf,
+ (unsigned int)dstBuf + dstVirW * dstVirH,
+ (unsigned int)dstBuf + dstVirW * dstVirH * 5/4,
+ dstVirW, dstVirH, &clip,
+ RkRgaGetRgaFormat(relDstRect.format),0);
+#endif
+ } else if (ctx->mVersion < 2.0) {
+ /*Src*/
+ if (srcFd != -1) {
+ srcMmuFlag = srcType ? 1 : 0;
+ if (src && srcFd == src->fd)
+ srcMmuFlag = src->mmuFlag ? 1 : 0;
+ NormalRgaSetSrcVirtualInfo(&rgaReg, 0, 0, 0, srcVirW, srcVirH,
+ RkRgaGetRgaFormat(relSrcRect.format),0);
+ NormalRgaSetFdsOffsets(&rgaReg, srcFd, 0, 0, 0);
+ } else {
+ if (src && src->hnd)
+ srcMmuFlag = srcType ? 1 : 0;
+ if (src && srcBuf == src->virAddr)
+ srcMmuFlag = 1;
+ if (src && srcBuf == src->phyAddr)
+ srcMmuFlag = 0;
+#if defined(__arm64__) || defined(__aarch64__)
+ NormalRgaSetSrcVirtualInfo(&rgaReg, (unsigned long)srcBuf,
+ (unsigned long)srcBuf + srcVirW * srcVirH,
+ (unsigned long)srcBuf + srcVirW * srcVirH * 5/4,
+ srcVirW, srcVirH,
+ RkRgaGetRgaFormat(relSrcRect.format),0);
+#else
+ NormalRgaSetSrcVirtualInfo(&rgaReg, (unsigned int)srcBuf,
+ (unsigned int)srcBuf + srcVirW * srcVirH,
+ (unsigned int)srcBuf + srcVirW * srcVirH * 5/4,
+ srcVirW, srcVirH,
+ RkRgaGetRgaFormat(relSrcRect.format),0);
+#endif
+ }
+ /*dst*/
+ if (dstFd != -1) {
+ dstMmuFlag = dstType ? 1 : 0;
+ if (dst && dstFd == dst->fd)
+ dstMmuFlag = dst->mmuFlag ? 1 : 0;
+ NormalRgaSetDstVirtualInfo(&rgaReg, 0, 0, 0, dstVirW, dstVirH, &clip,
+ RkRgaGetRgaFormat(relDstRect.format),0);
+ /*src dst fd*/
+ NormalRgaSetFdsOffsets(&rgaReg, 0, dstFd, 0, 0);
+ } else {
+ if (dst && dst->hnd)
+ dstMmuFlag = dstType ? 1 : 0;
+ if (dst && dstBuf == dst->virAddr)
+ dstMmuFlag = 1;
+ if (dst && dstBuf == dst->phyAddr)
+ dstMmuFlag = 0;
+#if defined(__arm64__) || defined(__aarch64__)
+ NormalRgaSetDstVirtualInfo(&rgaReg, (unsigned long)dstBuf,
+ (unsigned long)dstBuf + dstVirW * dstVirH,
+ (unsigned long)dstBuf + dstVirW * dstVirH * 5/4,
+ dstVirW, dstVirH, &clip,
+ RkRgaGetRgaFormat(relDstRect.format),0);
+#else
+ NormalRgaSetDstVirtualInfo(&rgaReg, (unsigned int)dstBuf,
+ (unsigned int)dstBuf + dstVirW * dstVirH,
+ (unsigned int)dstBuf + dstVirW * dstVirH * 5/4,
+ dstVirW, dstVirH, &clip,
+ RkRgaGetRgaFormat(relDstRect.format),0);
+#endif
+ }
+ } else {
+ if (src && src->hnd)
+ srcMmuFlag = srcType ? 1 : 0;
+ if (src && srcBuf == src->virAddr)
+ srcMmuFlag = 1;
+ if (src && srcBuf == src->phyAddr)
+ srcMmuFlag = 0;
+ if (srcFd != -1)
+ srcMmuFlag = srcType ? 1 : 0;
+ if (src && srcFd == src->fd)
+ srcMmuFlag = src->mmuFlag ? 1 : 0;
+
+ if (dst && dst->hnd)
+ dstMmuFlag = dstType ? 1 : 0;
+ if (dst && dstBuf == dst->virAddr)
+ dstMmuFlag = 1;
+ if (dst && dstBuf == dst->phyAddr)
+ dstMmuFlag = 0;
+ if (dstFd != -1)
+ dstMmuFlag = dstType ? 1 : 0;
+ if (dst && dstFd == dst->fd)
+ dstMmuFlag = dst->mmuFlag ? 1 : 0;
+#if defined(__arm64__) || defined(__aarch64__)
+ NormalRgaSetSrcVirtualInfo(&rgaReg, srcFd != -1 ? srcFd : 0,
+ (unsigned long)srcBuf,
+ (unsigned long)srcBuf + srcVirW * srcVirH,
+ srcVirW, srcVirH,
+ RkRgaGetRgaFormat(relSrcRect.format),0);
+ /*dst*/
+ NormalRgaSetDstVirtualInfo(&rgaReg, dstFd != -1 ? dstFd : 0,
+ (unsigned long)dstBuf,
+ (unsigned long)dstBuf + dstVirW * dstVirH,
+ dstVirW, dstVirH, &clip,
+ RkRgaGetRgaFormat(relDstRect.format),0);
+#else
+ NormalRgaSetSrcVirtualInfo(&rgaReg, srcFd != -1 ? srcFd : 0,
+ (unsigned int)srcBuf,
+ (unsigned int)srcBuf + srcVirW * srcVirH,
+ srcVirW, srcVirH,
+ RkRgaGetRgaFormat(relSrcRect.format),0);
+ /*dst*/
+ NormalRgaSetDstVirtualInfo(&rgaReg, dstFd != -1 ? dstFd : 0,
+ (unsigned int)dstBuf,
+ (unsigned int)dstBuf + dstVirW * dstVirH,
+ dstVirW, dstVirH, &clip,
+ RkRgaGetRgaFormat(relDstRect.format),0);
+#endif
+ }
+
+ NormalRgaSetSrcActiveInfo(&rgaReg, srcActW, srcActH, srcXPos, srcYPos);
+ NormalRgaSetDstActiveInfo(&rgaReg, dstActW, dstActH, dstXPos, dstYPos);
+
+ if (NormalRgaIsYuvFormat(RkRgaGetRgaFormat(relSrcRect.format)) &&
+ NormalRgaIsRgbFormat(RkRgaGetRgaFormat(relDstRect.format)))
+ yuvToRgbMode |= 0x1 << 0;
+
+ if (NormalRgaIsRgbFormat(RkRgaGetRgaFormat(relSrcRect.format)) &&
+ NormalRgaIsYuvFormat(RkRgaGetRgaFormat(relDstRect.format)))
+ yuvToRgbMode |= 0x2 << 4;
+
+ /*mode*/
+ NormalRgaSetBitbltMode(&rgaReg, scaleMode, rotateMode,
+ orientation, ditherEn, 0, yuvToRgbMode);
+
+ /*force to mmu flag to mask*/
+ srcMmuFlag = dstMmuFlag = 1;
+
+ if (srcMmuFlag || dstMmuFlag) {
+ NormalRgaMmuInfo(&rgaReg, 1, 0, 0, 0, 0, 2);
+ NormalRgaMmuFlag(&rgaReg, srcMmuFlag, dstMmuFlag);
+ }
+
+ rgaReg.render_mode |= RGA_BUF_GEM_TYPE_DMA;
+
+ //ALOGD("%d,%d,%d", srcMmuFlag, dstMmuFlag,rotateMode);
+ //NormalRgaLogOutRgaReq(rgaReg);
+
+ if(ioctl(ctx->rgaFd, RGA_BLIT_SYNC, &rgaReg)) {
+ printf(" %s(%d) RGA_BLIT fail: %s",__FUNCTION__, __LINE__,strerror(errno));
+ ALOGE(" %s(%d) RGA_BLIT fail: %s",__FUNCTION__, __LINE__,strerror(errno));
+ ALOGE("%d,%d,%d", srcMmuFlag, dstMmuFlag, rotateMode);
+ NormalRgaLogOutRgaReq(rgaReg);
+ }
+
+ return 0;
+}
+
+int RgaCollorFill(rga_info *dst)
+{
+ //check rects
+ //check buffer_handle_t with rects
+ struct rgaContext *ctx = rgaCtx;
+ int dstVirW,dstVirH,dstActW,dstActH,dstXPos,dstYPos;
+ int scaleMode,ditherEn;
+ int dstType,dstMmuFlag;
+ int dstFd = -1;
+ int ret = 0;
+ unsigned int color = 0x00000000;
+ rga_rect_t relDstRect,tmpDstRect;
+ struct rga_req rgaReg;
+ COLOR_FILL fillColor ;
+ void *dstBuf = NULL;
+ RECT clip;
+
+ if (!ctx) {
+ ALOGE("Try to use uninit rgaCtx=%p",ctx);
+ return -ENODEV;
+ }
+
+ memset(&rgaReg, 0, sizeof(struct rga_req));
+
+ dstType = dstMmuFlag = 0;
+
+ if (!dst) {
+ ALOGE("src = %p, dst = %p", dst, dst);
+ return -EINVAL;
+ }
+
+ if (dst) {
+ color = dst->color;
+ memcpy(&relDstRect, &dst->rect, sizeof(rga_rect_t));
+ }
+
+ dstFd = -1;
+
+ if (relDstRect.hstride == 0)
+ relDstRect.hstride = relDstRect.height;
+
+ if (dst && dst->hnd) {
+ ret = RkRgaGetHandleFd(dst->hnd, &dstFd);
+ if (ret) {
+ ALOGE("dst handle get fd fail ret = %d,hnd=%p", ret, &dst->hnd);
+ printf("-dst handle get fd fail ret = %d,hnd=%p", ret, &dst->hnd);
+ return ret;
+ }
+ if (!isRectValid(relDstRect)) {
+ ret = NormalRgaGetRect(dst->hnd, &tmpDstRect);
+ if (ret)
+ return ret;
+ memcpy(&relDstRect, &tmpDstRect, sizeof(rga_rect_t));
+ }
+ NormalRgaGetMmuType(dst->hnd, &dstType);
+ }
+
+
+ if (dst && dstFd < 0)
+ dstFd = dst->fd;
+
+ if (dst && dst->phyAddr)
+ dstBuf = dst->phyAddr;
+ else if (dst && dst->virAddr)
+ dstBuf = dst->virAddr;
+
+ if (dst && dstFd == -1 && !dstBuf) {
+ ALOGE("%d:dst has not fd and address for render", __LINE__);
+ return ret;
+ }
+
+ if (dst && dstFd == 0 && !dstBuf) {
+ ALOGE("dstFd is zero, now driver not support");
+ return -EINVAL;
+ }
+
+ if (dstFd == 0)
+ dstFd = -1;
+
+ if (relDstRect.hstride == 0)
+ relDstRect.hstride = relDstRect.height;
+
+ dstVirW = relDstRect.wstride;
+ dstVirH = relDstRect.hstride;
+ dstXPos = relDstRect.xoffset;
+ dstYPos = relDstRect.yoffset;
+ dstActW = relDstRect.width;
+ dstActH = relDstRect.height;
+
+ clip.xmin = 0;
+ clip.xmax = dstActW - 1;
+ clip.ymin = 0;
+ clip.ymax = dstActH - 1;
+
+ if (ctx->mVersion <= 1.003) {
+#if defined(__arm64__) || defined(__aarch64__)
+ /*dst*/
+ NormalRgaSetDstVirtualInfo(&rgaReg, (unsigned long)dstBuf,
+ (unsigned long)dstBuf + dstVirW * dstVirH,
+ (unsigned long)dstBuf + dstVirW * dstVirH * 5/4,
+ dstVirW, dstVirH, &clip,
+ RkRgaGetRgaFormat(relDstRect.format),0);
+#else
+ /*dst*/
+ NormalRgaSetDstVirtualInfo(&rgaReg, (unsigned int)dstBuf,
+ (unsigned int)dstBuf + dstVirW * dstVirH,
+ (unsigned int)dstBuf + dstVirW * dstVirH * 5/4,
+ dstVirW, dstVirH, &clip,
+ RkRgaGetRgaFormat(relDstRect.format),0);
+#endif
+ } else if (ctx->mVersion < 2.0) {
+ /*dst*/
+ if (dstFd != -1) {
+ dstMmuFlag = dstType ? 1 : 0;
+ if (dst && dstFd == dst->fd)
+ dstMmuFlag = dst->mmuFlag ? 1 : 0;
+ NormalRgaSetDstVirtualInfo(&rgaReg, 0, 0, 0, dstVirW, dstVirH, &clip,
+ RkRgaGetRgaFormat(relDstRect.format),0);
+ /*src dst fd*/
+ NormalRgaSetFdsOffsets(&rgaReg, 0, dstFd, 0, 0);
+ } else {
+ if (dst && dst->hnd)
+ dstMmuFlag = dstType ? 1 : 0;
+ if (dst && dstBuf == dst->virAddr)
+ dstMmuFlag = 1;
+ if (dst && dstBuf == dst->phyAddr)
+ dstMmuFlag = 0;
+#if defined(__arm64__) || defined(__aarch64__)
+ NormalRgaSetDstVirtualInfo(&rgaReg, (unsigned long)dstBuf,
+ (unsigned long)dstBuf + dstVirW * dstVirH,
+ (unsigned long)dstBuf + dstVirW * dstVirH * 5/4,
+ dstVirW, dstVirH, &clip,
+ RkRgaGetRgaFormat(relDstRect.format),0);
+#else
+ NormalRgaSetDstVirtualInfo(&rgaReg, (unsigned int)dstBuf,
+ (unsigned int)dstBuf + dstVirW * dstVirH,
+ (unsigned int)dstBuf + dstVirW * dstVirH * 5/4,
+ dstVirW, dstVirH, &clip,
+ RkRgaGetRgaFormat(relDstRect.format),0);
+#endif
+ }
+ } else {
+ if (dst && dst->hnd)
+ dstMmuFlag = dstType ? 1 : 0;
+ if (dst && dstBuf == dst->virAddr)
+ dstMmuFlag = 1;
+ if (dst && dstBuf == dst->phyAddr)
+ dstMmuFlag = 0;
+ if (dstFd != -1)
+ dstMmuFlag = dstType ? 1 : 0;
+ if (dst && dstFd == dst->fd)
+ dstMmuFlag = dst->mmuFlag ? 1 : 0;
+#if defined(__arm64__) || defined(__aarch64__)
+ /*dst*/
+ NormalRgaSetDstVirtualInfo(&rgaReg, dstFd != -1 ? dstFd : 0,
+ (unsigned long)dstBuf,
+ (unsigned long)dstBuf + dstVirW * dstVirH,
+ dstVirW, dstVirH, &clip,
+ RkRgaGetRgaFormat(relDstRect.format),0);
+#else
+ /*dst*/
+ NormalRgaSetDstVirtualInfo(&rgaReg, dstFd != -1 ? dstFd : 0,
+ (unsigned int)dstBuf,
+ (unsigned int)dstBuf + dstVirW * dstVirH,
+ dstVirW, dstVirH, &clip,
+ RkRgaGetRgaFormat(relDstRect.format),0);
+#endif
+ }
+
+ NormalRgaSetDstActiveInfo(&rgaReg, dstActW, dstActH, dstXPos, dstYPos);
+
+ memset(&fillColor , 0x0, sizeof(COLOR_FILL));
+
+ /*mode*/
+ NormalRgaSetColorFillMode(&rgaReg, &fillColor, 0, 0, color, 0, 0, 0, 0, 0);
+
+ if (dstMmuFlag) {
+ NormalRgaMmuInfo(&rgaReg, 1, 0, 0, 0, 0, 2);
+ NormalRgaMmuFlag(&rgaReg, dstMmuFlag, dstMmuFlag);
+ }
+
+ //ALOGD("%d,%d,%d", srcMmuFlag, dstMmuFlag, rotateMode);
+ //NormalRgaLogOutRgaReq(rgaReg);
+
+ if(ioctl(ctx->rgaFd, RGA_BLIT_SYNC, &rgaReg)) {
+ printf("%s(%d) RGA_BLIT fail: %s",__FUNCTION__, __LINE__,strerror(errno));
+ ALOGE("%s(%d) RGA_BLIT fail: %s",__FUNCTION__, __LINE__,strerror(errno));
+ NormalRgaLogOutRgaReq(rgaReg);
+ }
+
+ return 0;
+}
+
+int RgaBlit(buffer_handle_t src,
+ buffer_handle_t dst, drm_rga_t *rects, int rotation, int blend)
+{
+
+ //check rects
+ //check buffer_handle_t with rects
+ struct rgaContext *ctx = rgaCtx;
+ int srcVirW,srcVirH,srcActW,srcActH,srcXPos,srcYPos;
+ int dstVirW,dstVirH,dstActW,dstActH,dstXPos,dstYPos;
+ int scaleMode,rotateMode,orientation,ditherEn;
+ int srcType,dstType,srcMmuFlag,dstMmuFlag;
+ int planeAlpha;
+ int dstFd = -1;
+ int srcFd = -1;
+ int ret = 0;
+ drm_rga_t tmpRects,relRects;
+ struct rga_req rgaReg;
+ bool perpixelAlpha;
+ void *srcBuf = NULL;
+ void *dstBuf = NULL;
+ RECT clip;
+
+ if (!ctx) {
+ ALOGE("Try to use uninit rgaCtx=%p",ctx);
+ return -ENODEV;
+ }
+
+ if (rects && (ctx->mLogAlways || ctx->mLogOnce)) {
+ ALOGD("Src:[%d,%d,%d,%d][%d,%d,%d]=>Dst:[%d,%d,%d,%d][%d,%d,%d]",
+ rects->src.xoffset,rects->src.yoffset,
+ rects->src.width, rects->src.height,
+ rects->src.wstride,rects->src.format, rects->src.size,
+ rects->dst.xoffset,rects->dst.yoffset,
+ rects->dst.width, rects->dst.height,
+ rects->dst.wstride,rects->dst.format, rects->dst.size);
+ }
+
+ memset(&rgaReg, 0, sizeof(struct rga_req));
+
+ srcType = dstType = srcMmuFlag = dstMmuFlag = 0;
+
+ ret = NormalRgaGetRects(src, dst, &srcType, &dstType, &tmpRects);
+ if (ret && !rects) {
+ ALOGE("%d:Has not rects for render", __LINE__);
+ return ret;
+ }
+
+ if (rects) {
+ if (rects->src.wstride > 0 && rects->dst.wstride > 0)
+ memcpy(&relRects, rects, sizeof(drm_rga_t));
+ else if (rects->src.wstride > 0) {
+ memcpy(&(relRects.src), &(rects->src), sizeof(rga_rect_t));
+ memcpy(&(relRects.dst), &(tmpRects.dst), sizeof(rga_rect_t));
+ } else if (rects->dst.wstride > 0) {
+ memcpy(&(relRects.src), &(tmpRects.src), sizeof(rga_rect_t));
+ memcpy(&(relRects.dst), &(rects->dst), sizeof(rga_rect_t));
+ }
+ } else
+ memcpy(&relRects, &tmpRects, sizeof(drm_rga_t));
+
+ if (ctx->mLogAlways || ctx->mLogOnce) {
+ ALOGD("Src:[%d,%d,%d,%d][%d,%d,%d]=>Dst:[%d,%d,%d,%d][%d,%d,%d]",
+ tmpRects.src.xoffset,tmpRects.src.yoffset,
+ tmpRects.src.width, tmpRects.src.height,
+ tmpRects.src.wstride,tmpRects.src.format, tmpRects.src.size,
+ tmpRects.dst.xoffset,tmpRects.dst.yoffset,
+ tmpRects.dst.width, tmpRects.dst.height,
+ tmpRects.dst.wstride,tmpRects.dst.format, tmpRects.dst.size);
+ ALOGD("Src:[%d,%d,%d,%d][%d,%d,%d]=>Dst:[%d,%d,%d,%d][%d,%d,%d]",
+ relRects.src.xoffset,relRects.src.yoffset,
+ relRects.src.width, relRects.src.height,
+ relRects.src.wstride,relRects.src.format, relRects.src.size,
+ relRects.dst.xoffset,relRects.dst.yoffset,
+ relRects.dst.width, relRects.dst.height,
+ relRects.dst.wstride,relRects.dst.format, relRects.dst.size);
+ }
+
+ RkRgaGetHandleMapAddress(src, &srcBuf);
+ RkRgaGetHandleFd(src, &srcFd);
+ if (srcFd == -1 && !srcBuf) {
+ ALOGE("%d:src has not fd and address for render", __LINE__);
+ return ret;
+ }
+
+ if (srcFd == 0 && !srcBuf) {
+ ALOGE("srcFd is zero, now driver not support");
+ return -EINVAL;
+ } else
+ srcFd = -1;
+
+ RkRgaGetHandleMapAddress(dst, &dstBuf);
+ RkRgaGetHandleFd(dst, &dstFd);
+ if (dstFd == -1 && !dstBuf) {
+ ALOGE("%d:dst has not fd and address for render", __LINE__);
+ return ret;
+ }
+
+ if (dstFd == 0 && !dstBuf) {
+ ALOGE("dstFd is zero, now driver not support");
+ return -EINVAL;
+ } else
+ dstFd = -1;
+
+ planeAlpha = (blend & 0xFF0000) >> 16;
+ perpixelAlpha = relRects.src.format == HAL_PIXEL_FORMAT_RGBA_8888 ||
+ relRects.src.format == HAL_PIXEL_FORMAT_BGRA_8888;
+
+ switch ((blend & 0xFFFF)) {
+ case 0x0105:
+ if (perpixelAlpha && planeAlpha < 255)
+ NormalRgaSetAlphaEnInfo(&rgaReg, 1, 2, planeAlpha , 1, 9, 0);
+ else if (perpixelAlpha)
+ NormalRgaSetAlphaEnInfo(&rgaReg, 1, 1, 0, 1, 3, 0);
+ else
+ NormalRgaSetAlphaEnInfo(&rgaReg, 1, 0, planeAlpha , 0, 0, 0);
+ break;
+
+ case 0x0405:
+ if (perpixelAlpha && planeAlpha < 255)
+ NormalRgaSetAlphaEnInfo(&rgaReg, 1, 2, planeAlpha , 0, 0, 0);
+ else if (perpixelAlpha)
+ NormalRgaSetAlphaEnInfo(&rgaReg, 1, 1, 0, 0, 0, 0);
+ else
+ NormalRgaSetAlphaEnInfo(&rgaReg, 1, 0, planeAlpha , 0, 0, 0);
+ break;
+
+ case 0x0100:
+ default:
+ /* Tips: BLENDING_NONE is non-zero value, handle zero value as
+ * BLENDING_NONE. */
+ /* C = Cs
+ * A = As */
+ break;
+ }
+
+ switch (rotation) {
+ case HAL_TRANSFORM_FLIP_H:
+ orientation = 0;
+ rotateMode = 2;
+ srcVirW = relRects.src.wstride;
+ srcVirH = relRects.src.height;
+ srcXPos = relRects.src.xoffset;
+ srcYPos = relRects.src.yoffset;
+ srcActW = relRects.src.width;
+ srcActH = relRects.src.height;
+
+ dstVirW = relRects.dst.wstride;
+ dstVirH = relRects.dst.height;
+ dstXPos = relRects.dst.xoffset;
+ dstYPos = relRects.dst.yoffset;
+ dstActW = relRects.dst.width;
+ dstActH = relRects.dst.height;
+ break;
+ case HAL_TRANSFORM_FLIP_V:
+ orientation = 0;
+ rotateMode = 3;
+ srcVirW = relRects.src.wstride;
+ srcVirH = relRects.src.height;
+ srcXPos = relRects.src.xoffset;
+ srcYPos = relRects.src.yoffset;
+ srcActW = relRects.src.width;
+ srcActH = relRects.src.height;
+
+ dstVirW = relRects.dst.wstride;
+ dstVirH = relRects.dst.height;
+ dstXPos = relRects.dst.xoffset;
+ dstYPos = relRects.dst.yoffset;
+ dstActW = relRects.dst.width;
+ dstActH = relRects.dst.height;
+ break;
+ case HAL_TRANSFORM_ROT_90:
+ orientation = 90;
+ rotateMode = 1;
+ srcVirW = relRects.src.wstride;
+ srcVirH = relRects.src.height;
+ srcXPos = relRects.src.xoffset;
+ srcYPos = relRects.src.yoffset;
+ srcActW = relRects.src.width;
+ srcActH = relRects.src.height;
+
+ dstVirW = relRects.dst.wstride;
+ dstVirH = relRects.dst.height;
+ dstXPos = relRects.dst.width - 1;
+ //dstYPos = relRects.dst.yoffset;
+ dstYPos = 0;
+ dstActW = relRects.dst.height;
+ dstActH = relRects.dst.width;
+ break;
+ case HAL_TRANSFORM_ROT_180:
+ orientation = 180;
+ rotateMode = 1;
+ srcVirW = relRects.src.wstride;
+ srcVirH = relRects.src.height;
+ srcXPos = relRects.src.xoffset;
+ srcYPos = relRects.src.yoffset;
+ srcActW = relRects.src.width;
+ srcActH = relRects.src.height;
+
+ dstVirW = relRects.dst.wstride;
+ dstVirH = relRects.dst.height;
+ dstXPos = relRects.dst.width - 1;
+ dstYPos = relRects.dst.height - 1;
+ dstActW = relRects.dst.width;
+ dstActH = relRects.dst.height;
+ break;
+ case HAL_TRANSFORM_ROT_270:
+ orientation = 270;
+ rotateMode = 1;
+ srcVirW = relRects.src.wstride;
+ srcVirH = relRects.src.height;
+ srcXPos = relRects.src.xoffset;
+ srcYPos = relRects.src.yoffset;
+ srcActW = relRects.src.width;
+ srcActH = relRects.src.height;
+
+ dstVirW = relRects.dst.wstride;
+ dstVirH = relRects.dst.height;
+ //dstXPos = relRects.dst.xoffset;
+ dstXPos = 0;
+ dstYPos = relRects.dst.height - 1;
+ dstActW = relRects.dst.height;
+ dstActH = relRects.dst.width;
+ break;
+ default:
+ orientation = 0;
+ rotateMode = 0;
+ srcVirW = relRects.src.wstride;
+ srcVirH = relRects.src.height;
+ srcXPos = relRects.src.xoffset;
+ srcYPos = relRects.src.yoffset;
+ srcActW = relRects.src.width;
+ srcActH = relRects.src.height;
+
+ dstVirW = relRects.dst.wstride;
+ dstVirH = relRects.dst.height;
+ dstXPos = relRects.dst.xoffset;
+ dstYPos = relRects.dst.yoffset;
+ dstActW = relRects.dst.width;
+ dstActH = relRects.dst.height;
+ break;
+ }
+
+ clip.xmin = 0;
+ clip.xmax = dstActW - 1;
+ clip.ymin = 0;
+ clip.ymax = dstActH - 1;
+
+ scaleMode = 0;
+ //scale up use bicubic
+ if (srcActW / dstActW < 1 || srcActH / dstActH < 1)
+ scaleMode = 2;
+
+ /*
+ if (scaleMode && (srcFormat == RK_FORMAT_RGBA_8888 ||
+ srcFormat == RK_FORMAT_BGRA_8888)) {
+ scale_mode = 0; // force change scale_mode to 0 ,for rga not support
+ }*/
+
+ ditherEn = (android::bytesPerPixel(relRects.src.format)
+ != android::bytesPerPixel(relRects.src.format) ? 1 : 0);
+
+ if (ctx->mVersion <= 1.003) {
+ srcMmuFlag = dstMmuFlag = 1;
+
+#if defined(__arm64__) || defined(__aarch64__)
+ NormalRgaSetSrcVirtualInfo(&rgaReg, (unsigned long)srcBuf,
+ (unsigned long)srcBuf + srcVirW * srcVirH,
+ (unsigned long)srcBuf + srcVirW * srcVirH * 5/4,
+ srcVirW, srcVirH,
+ RkRgaGetRgaFormat(relRects.src.format),0);
+ /*dst*/
+ NormalRgaSetDstVirtualInfo(&rgaReg, (unsigned long)dstBuf,
+ (unsigned long)dstBuf + dstVirW * dstVirH,
+ (unsigned long)dstBuf + dstVirW * dstVirH * 5/4,
+ dstVirW, dstVirH, &clip,
+ RkRgaGetRgaFormat(relRects.dst.format),0);
+#else
+ NormalRgaSetSrcVirtualInfo(&rgaReg, (unsigned int)srcBuf,
+ (unsigned int)srcBuf + srcVirW * srcVirH,
+ (unsigned int)srcBuf + srcVirW * srcVirH * 5/4,
+ srcVirW, srcVirH,
+ RkRgaGetRgaFormat(relRects.src.format),0);
+ /*dst*/
+ NormalRgaSetDstVirtualInfo(&rgaReg, (unsigned int)dstBuf,
+ (unsigned int)dstBuf + dstVirW * dstVirH,
+ (unsigned int)dstBuf + dstVirW * dstVirH * 5/4,
+ dstVirW, dstVirH, &clip,
+ RkRgaGetRgaFormat(relRects.dst.format),0);
+#endif
+ } else if (ctx->mVersion < 2.0) {
+ /*Src*/
+ if (srcFd != -1) {
+ srcMmuFlag = srcType ? 1 : 0;
+ NormalRgaSetSrcVirtualInfo(&rgaReg, 0, 0, 0, srcVirW, srcVirH,
+ RkRgaGetRgaFormat(relRects.src.format),0);
+ NormalRgaSetFdsOffsets(&rgaReg, srcFd, 0, 0, 0);
+ } else {
+ srcMmuFlag = 1;
+
+#if defined(__arm64__) || defined(__aarch64__)
+ NormalRgaSetSrcVirtualInfo(&rgaReg, (unsigned long)srcBuf,
+ (unsigned long)srcBuf + srcVirW * srcVirH,
+ (unsigned long)srcBuf + srcVirW * srcVirH * 5/4,
+ srcVirW, srcVirH,
+ RkRgaGetRgaFormat(relRects.src.format),0);
+#else
+ NormalRgaSetSrcVirtualInfo(&rgaReg, (unsigned int)srcBuf,
+ (unsigned int)srcBuf + srcVirW * srcVirH,
+ (unsigned int)srcBuf + srcVirW * srcVirH * 5/4,
+ srcVirW, srcVirH,
+ RkRgaGetRgaFormat(relRects.src.format),0);
+#endif
+ }
+ /*dst*/
+ if (dstFd != -1) {
+ dstMmuFlag = srcType ? 1 : 0;
+ NormalRgaSetDstVirtualInfo(&rgaReg, 0, 0, 0, dstVirW, dstVirH, &clip,
+ RkRgaGetRgaFormat(relRects.dst.format),0);
+ /*src dst fd*/
+ NormalRgaSetFdsOffsets(&rgaReg, 0, dstFd, 0, 0);
+ } else {
+ dstMmuFlag = 1;
+#if defined(__arm64__) || defined(__aarch64__)
+ NormalRgaSetDstVirtualInfo(&rgaReg, (unsigned long)dstBuf,
+ (unsigned long)dstBuf + dstVirW * dstVirH,
+ (unsigned long)dstBuf + dstVirW * dstVirH * 5/4,
+ dstVirW, dstVirH, &clip,
+ RkRgaGetRgaFormat(relRects.dst.format),0);
+#else
+ NormalRgaSetDstVirtualInfo(&rgaReg, (unsigned int)dstBuf,
+ (unsigned int)dstBuf + dstVirW * dstVirH,
+ (unsigned int)dstBuf + dstVirW * dstVirH * 5/4,
+ dstVirW, dstVirH, &clip,
+ RkRgaGetRgaFormat(relRects.dst.format),0);
+#endif
+ }
+ } else {
+ srcMmuFlag = ((srcFd != -1 && srcType) || srcFd == -1) ? 1 : 0;
+ dstMmuFlag = ((dstFd != -1 && dstType) || dstFd == -1) ? 1 : 0;
+#if defined(__arm64__) || defined(__aarch64__)
+ NormalRgaSetSrcVirtualInfo(&rgaReg, srcFd != -1 ? srcFd : 0,
+ (unsigned long)srcBuf,
+ (unsigned long)srcBuf + srcVirW * srcVirH,
+ srcVirW, srcVirH,
+ RkRgaGetRgaFormat(relRects.src.format),0);
+ /*dst*/
+ NormalRgaSetDstVirtualInfo(&rgaReg, dstFd != -1 ? dstFd : 0,
+ (unsigned long)dstBuf,
+ (unsigned long)dstBuf + dstVirW * dstVirH,
+ dstVirW, dstVirH, &clip,
+ RkRgaGetRgaFormat(relRects.dst.format),0);
+#else
+ NormalRgaSetSrcVirtualInfo(&rgaReg, srcFd != -1 ? srcFd : 0,
+ (unsigned int)srcBuf,
+ (unsigned int)srcBuf + srcVirW * srcVirH,
+ srcVirW, srcVirH,
+ RkRgaGetRgaFormat(relRects.src.format),0);
+ /*dst*/
+ NormalRgaSetDstVirtualInfo(&rgaReg, dstFd != -1 ? dstFd : 0,
+ (unsigned int)dstBuf,
+ (unsigned int)dstBuf + dstVirW * dstVirH,
+ dstVirW, dstVirH, &clip,
+ RkRgaGetRgaFormat(relRects.dst.format),0);
+#endif
+ }
+
+ NormalRgaSetSrcActiveInfo(&rgaReg, srcActW, srcActH, srcXPos, srcYPos);
+ NormalRgaSetDstActiveInfo(&rgaReg, dstActW, dstActH, dstXPos, dstYPos);
+
+ /*mode*/
+ NormalRgaSetBitbltMode(&rgaReg, scaleMode, rotateMode, orientation, ditherEn, 0, 0);
+
+ if (srcMmuFlag || dstMmuFlag) {
+ NormalRgaMmuInfo(&rgaReg, 1, 0, 0, 0, 0, 2);
+ NormalRgaMmuFlag(&rgaReg, srcMmuFlag, dstMmuFlag);
+ }
+
+ if(ioctl(ctx->rgaFd, RGA_BLIT_SYNC, &rgaReg)) {
+ printf(" %s(%d) RGA_BLIT fail: %s",__FUNCTION__, __LINE__,strerror(errno));
+ ALOGE(" %s(%d) RGA_BLIT fail: %s",__FUNCTION__, __LINE__,strerror(errno));
+ }
+
+ if (ctx->mLogOnce)
+ ctx->mLogOnce = 0;
+
+ return 0;
+}
+
+int RgaBlit(void *src,
+ buffer_handle_t dst, drm_rga_t *rects, int rotation, int blend)
+{
+ //check rects
+ //check buffer_handle_t with rects
+ struct rgaContext *ctx = rgaCtx;
+ int srcVirW,srcVirH,srcActW,srcActH,srcXPos,srcYPos;
+ int dstVirW,dstVirH,dstActW,dstActH,dstXPos,dstYPos;
+ int scaleMode,rotateMode,orientation,ditherEn;
+ int srcType,dstType,srcMmuFlag,dstMmuFlag;
+ int planeAlpha;
+ int dstFd = -1;
+ int srcFd = -1;
+ int ret = 0;
+ drm_rga_t tmpRects,relRects;
+ struct rga_req rgaReg;
+ bool perpixelAlpha;
+ void *srcBuf = NULL;
+ void *dstBuf = NULL;
+ RECT clip;
+
+ if (!ctx) {
+ ALOGE("Try to use uninit rgaCtx=%p",ctx);
+ return -ENODEV;
+ }
+
+ memset(&rgaReg, 0, sizeof(struct rga_req));
+
+ srcType = dstType = srcMmuFlag = dstMmuFlag = 0;
+
+ if (!rects) {
+ ALOGE("%d:Has not user rects for render", __LINE__);
+ return ret;
+ }
+
+ if (rects->src.wstride <= 0) {
+ ALOGE("%d:Has invalid rects for render", __LINE__);
+ return -EINVAL;
+ }
+
+ ret = NormalRgaGetRects(NULL, dst, &srcType, &dstType, &tmpRects);
+ if (ret) {
+ ALOGE("%d:Has not rects for render", __LINE__);
+ return ret;
+ }
+
+ if (rects->dst.wstride > 0)
+ memcpy(&relRects, rects, sizeof(drm_rga_t));
+ else {
+ memcpy(&(relRects.src), &(rects->src), sizeof(rga_rect_t));
+ memcpy(&(relRects.dst), &(tmpRects.dst), sizeof(rga_rect_t));
+ }
+
+ srcBuf = src;
+ if (!srcBuf) {
+ ALOGE("%d:src has not fd and address for render", __LINE__);
+ return ret;
+ }
+
+ RkRgaGetHandleMapAddress(dst, &dstBuf);
+ RkRgaGetHandleFd(dst, &dstFd);
+ if (dstFd == -1 && !dstBuf) {
+ ALOGE("%d:dst has not fd and address for render", __LINE__);
+ return ret;
+ }
+
+ if (dstFd == 0 && !dstBuf) {
+ ALOGE("dstFd is zero, now driver not support");
+ return -EINVAL;
+ } else
+ dstFd = -1;
+
+ planeAlpha = (blend & 0xFF0000) >> 16;
+ perpixelAlpha = relRects.src.format == HAL_PIXEL_FORMAT_RGBA_8888 ||
+ relRects.src.format == HAL_PIXEL_FORMAT_BGRA_8888;
+
+ switch ((blend & 0xFFFF)) {
+ case 0x0105:
+ if (perpixelAlpha && planeAlpha < 255)
+ NormalRgaSetAlphaEnInfo(&rgaReg, 1, 2, planeAlpha , 1, 9, 0);
+ else if (perpixelAlpha)
+ NormalRgaSetAlphaEnInfo(&rgaReg, 1, 1, 0, 1, 3, 0);
+ else
+ NormalRgaSetAlphaEnInfo(&rgaReg, 1, 0, planeAlpha , 0, 0, 0);
+ break;
+
+ case 0x0405:
+ if (perpixelAlpha && planeAlpha < 255)
+ NormalRgaSetAlphaEnInfo(&rgaReg, 1, 2, planeAlpha , 0, 0, 0);
+ else if (perpixelAlpha)
+ NormalRgaSetAlphaEnInfo(&rgaReg, 1, 1, 0, 0, 0, 0);
+ else
+ NormalRgaSetAlphaEnInfo(&rgaReg, 1, 0, planeAlpha , 0, 0, 0);
+ break;
+
+ case 0x0100:
+ default:
+ /* Tips: BLENDING_NONE is non-zero value, handle zero value as
+ * BLENDING_NONE. */
+ /* C = Cs
+ * A = As */
+ break;
+ }
+
+
+ switch (rotation) {
+ case HAL_TRANSFORM_FLIP_H:
+ orientation = 0;
+ rotateMode = 2;
+ srcVirW = relRects.src.wstride;
+ srcVirH = relRects.src.height;
+ srcXPos = relRects.src.xoffset;
+ srcYPos = relRects.src.yoffset;
+ srcActW = relRects.src.width;
+ srcActH = relRects.src.height;
+
+ dstVirW = relRects.dst.wstride;
+ dstVirH = relRects.dst.height;
+ dstXPos = relRects.dst.xoffset;
+ dstYPos = relRects.dst.yoffset;
+ dstActW = relRects.dst.width;
+ dstActH = relRects.dst.height;
+ break;
+ case HAL_TRANSFORM_FLIP_V:
+ orientation = 0;
+ rotateMode = 3;
+ srcVirW = relRects.src.wstride;
+ srcVirH = relRects.src.height;
+ srcXPos = relRects.src.xoffset;
+ srcYPos = relRects.src.yoffset;
+ srcActW = relRects.src.width;
+ srcActH = relRects.src.height;
+
+ dstVirW = relRects.dst.wstride;
+ dstVirH = relRects.dst.height;
+ dstXPos = relRects.dst.xoffset;
+ dstYPos = relRects.dst.yoffset;
+ dstActW = relRects.dst.width;
+ dstActH = relRects.dst.height;
+ break;
+ case HAL_TRANSFORM_ROT_90:
+ orientation = 90;
+ rotateMode = 1;
+ srcVirW = relRects.src.wstride;
+ srcVirH = relRects.src.height;
+ srcXPos = relRects.src.xoffset;
+ srcYPos = relRects.src.yoffset;
+ srcActW = relRects.src.width;
+ srcActH = relRects.src.height;
+
+ dstVirW = relRects.dst.wstride;
+ dstVirH = relRects.dst.height;
+ dstXPos = relRects.dst.width - 1;
+ //dstYPos = relRects.dst.yoffset;
+ dstYPos = 0;
+ dstActW = relRects.dst.height;
+ dstActH = relRects.dst.width;
+ break;
+ case HAL_TRANSFORM_ROT_180:
+ orientation = 180;
+ rotateMode = 1;
+ srcVirW = relRects.src.wstride;
+ srcVirH = relRects.src.height;
+ srcXPos = relRects.src.xoffset;
+ srcYPos = relRects.src.yoffset;
+ srcActW = relRects.src.width;
+ srcActH = relRects.src.height;
+
+ dstVirW = relRects.dst.wstride;
+ dstVirH = relRects.dst.height;
+ dstXPos = relRects.dst.width - 1;
+ dstYPos = relRects.dst.height - 1;
+ dstActW = relRects.dst.width;
+ dstActH = relRects.dst.height;
+ break;
+ case HAL_TRANSFORM_ROT_270:
+ orientation = 270;
+ rotateMode = 1;
+ srcVirW = relRects.src.wstride;
+ srcVirH = relRects.src.height;
+ srcXPos = relRects.src.xoffset;
+ srcYPos = relRects.src.yoffset;
+ srcActW = relRects.src.width;
+ srcActH = relRects.src.height;
+
+ dstVirW = relRects.dst.wstride;
+ dstVirH = relRects.dst.height;
+ //dstXPos = relRects.dst.xoffset;
+ dstXPos = 0;
+ dstYPos = relRects.dst.height - 1;
+ dstActW = relRects.dst.height;
+ dstActH = relRects.dst.width;
+ break;
+ default:
+ orientation = 0;
+ rotateMode = 0;
+ srcVirW = relRects.src.wstride;
+ srcVirH = relRects.src.height;
+ srcXPos = relRects.src.xoffset;
+ srcYPos = relRects.src.yoffset;
+ srcActW = relRects.src.width;
+ srcActH = relRects.src.height;
+
+ dstVirW = relRects.dst.wstride;
+ dstVirH = relRects.dst.height;
+ dstXPos = relRects.dst.xoffset;
+ dstYPos = relRects.dst.yoffset;
+ dstActW = relRects.dst.width;
+ dstActH = relRects.dst.height;
+ break;
+ }
+
+ clip.xmin = 0;
+ clip.xmax = dstActW - 1;
+ clip.ymin = 0;
+ clip.ymax = dstActH - 1;
+
+ scaleMode = 0;
+ //scale up use bicubic
+ if (srcActW / dstActW < 1 || srcActH / dstActH < 1)
+ scaleMode = 2;
+
+ /*
+ if (scaleMode && (srcFormat == RK_FORMAT_RGBA_8888 ||
+ srcFormat == RK_FORMAT_BGRA_8888)) {
+ scale_mode = 0; // force change scale_mode to 0 ,for rga not support
+ }*/
+
+ ditherEn = (android::bytesPerPixel(relRects.src.format)
+ != android::bytesPerPixel(relRects.src.format) ? 1 : 0);
+
+ if (ctx->mVersion <= 1.003) {
+ srcMmuFlag = dstMmuFlag = 1;
+
+#if defined(__arm64__) || defined(__aarch64__)
+ NormalRgaSetSrcVirtualInfo(&rgaReg, (unsigned long)srcBuf,
+ (unsigned long)srcBuf + srcVirW * srcVirH,
+ (unsigned long)srcBuf + srcVirW * srcVirH * 5/4,
+ srcVirW, srcVirH,
+ RkRgaGetRgaFormat(relRects.src.format),0);
+ /*dst*/
+ NormalRgaSetDstVirtualInfo(&rgaReg, (unsigned long)dstBuf,
+ (unsigned long)dstBuf + dstVirW * dstVirH,
+ (unsigned long)dstBuf + dstVirW * dstVirH * 5/4,
+ dstVirW, dstVirH, &clip,
+ RkRgaGetRgaFormat(relRects.dst.format),0);
+#else
+ NormalRgaSetSrcVirtualInfo(&rgaReg, (unsigned int)srcBuf,
+ (unsigned int)srcBuf + srcVirW * srcVirH,
+ (unsigned int)srcBuf + srcVirW * srcVirH * 5/4,
+ srcVirW, srcVirH,
+ RkRgaGetRgaFormat(relRects.src.format),0);
+ /*dst*/
+ NormalRgaSetDstVirtualInfo(&rgaReg, (unsigned int)dstBuf,
+ (unsigned int)dstBuf + dstVirW * dstVirH,
+ (unsigned int)dstBuf + dstVirW * dstVirH * 5/4,
+ dstVirW, dstVirH, &clip,
+ RkRgaGetRgaFormat(relRects.dst.format),0);
+#endif
+ } else if (ctx->mVersion < 2.0) {
+ /*Src*/
+ if (srcFd != -1) {
+ srcMmuFlag = srcType ? 1 : 0;
+ NormalRgaSetSrcVirtualInfo(&rgaReg, 0, 0, 0, srcVirW, srcVirH,
+ RkRgaGetRgaFormat(relRects.src.format),0);
+ NormalRgaSetFdsOffsets(&rgaReg, srcFd, 0, 0, 0);
+ } else {
+ srcMmuFlag = 1;
+
+#if defined(__arm64__) || defined(__aarch64__)
+ NormalRgaSetSrcVirtualInfo(&rgaReg, (unsigned long)srcBuf,
+ (unsigned long)srcBuf + srcVirW * srcVirH,
+ (unsigned long)srcBuf + srcVirW * srcVirH * 5/4,
+ srcVirW, srcVirH,
+ RkRgaGetRgaFormat(relRects.src.format),0);
+#else
+ NormalRgaSetSrcVirtualInfo(&rgaReg, (unsigned int)srcBuf,
+ (unsigned int)srcBuf + srcVirW * srcVirH,
+ (unsigned int)srcBuf + srcVirW * srcVirH * 5/4,
+ srcVirW, srcVirH,
+ RkRgaGetRgaFormat(relRects.src.format),0);
+#endif
+ }
+ /*dst*/
+ if (dstFd != -1) {
+ dstMmuFlag = srcType ? 1 : 0;
+ NormalRgaSetDstVirtualInfo(&rgaReg, 0, 0, 0, dstVirW, dstVirH, &clip,
+ RkRgaGetRgaFormat(relRects.dst.format),0);
+ /*src dst fd*/
+ NormalRgaSetFdsOffsets(&rgaReg, 0, dstFd, 0, 0);
+ } else {
+ dstMmuFlag = 1;
+#if defined(__arm64__) || defined(__aarch64__)
+ NormalRgaSetDstVirtualInfo(&rgaReg, (unsigned long)dstBuf,
+ (unsigned long)dstBuf + dstVirW * dstVirH,
+ (unsigned long)dstBuf + dstVirW * dstVirH * 5/4,
+ dstVirW, dstVirH, &clip,
+ RkRgaGetRgaFormat(relRects.dst.format),0);
+#else
+ NormalRgaSetDstVirtualInfo(&rgaReg, (unsigned int)dstBuf,
+ (unsigned int)dstBuf + dstVirW * dstVirH,
+ (unsigned int)dstBuf + dstVirW * dstVirH * 5/4,
+ dstVirW, dstVirH, &clip,
+ RkRgaGetRgaFormat(relRects.dst.format),0);
+#endif
+ }
+ } else {
+ srcMmuFlag = ((srcFd != -1 && srcType) || srcFd == -1) ? 1 : 0;
+ dstMmuFlag = ((dstFd != -1 && dstType) || dstFd == -1) ? 1 : 0;
+#if defined(__arm64__) || defined(__aarch64__)
+ NormalRgaSetSrcVirtualInfo(&rgaReg, srcFd != -1 ? srcFd : 0,
+ (unsigned long)srcBuf,
+ (unsigned long)srcBuf + srcVirW * srcVirH,
+ srcVirW, srcVirH,
+ RkRgaGetRgaFormat(relRects.src.format),0);
+ /*dst*/
+ NormalRgaSetDstVirtualInfo(&rgaReg, dstFd != -1 ? dstFd : 0,
+ (unsigned long)dstBuf,
+ (unsigned long)dstBuf + dstVirW * dstVirH,
+ dstVirW, dstVirH, &clip,
+ RkRgaGetRgaFormat(relRects.dst.format),0);
+#else
+ NormalRgaSetSrcVirtualInfo(&rgaReg, srcFd != -1 ? srcFd : 0,
+ (unsigned int)srcBuf,
+ (unsigned int)srcBuf + srcVirW * srcVirH,
+ srcVirW, srcVirH,
+ RkRgaGetRgaFormat(relRects.src.format),0);
+ /*dst*/
+ NormalRgaSetDstVirtualInfo(&rgaReg, dstFd != -1 ? dstFd : 0,
+ (unsigned int)dstBuf,
+ (unsigned int)dstBuf + dstVirW * dstVirH,
+ dstVirW, dstVirH, &clip,
+ RkRgaGetRgaFormat(relRects.dst.format),0);
+#endif
+ }
+
+ NormalRgaSetSrcActiveInfo(&rgaReg, srcActW, srcActH, srcXPos, srcYPos);
+ NormalRgaSetDstActiveInfo(&rgaReg, dstActW, dstActH, dstXPos, dstYPos);
+
+ /*mode*/
+ NormalRgaSetBitbltMode(&rgaReg, scaleMode, rotateMode, orientation, ditherEn, 0, 0);
+
+ if (srcMmuFlag || dstMmuFlag) {
+ NormalRgaMmuInfo(&rgaReg, 1, 0, 0, 0, 0, 2);
+ NormalRgaMmuFlag(&rgaReg, srcMmuFlag, dstMmuFlag);
+ }
+
+ if(ioctl(ctx->rgaFd, RGA_BLIT_SYNC, &rgaReg)) {
+ printf(" %s(%d) RGA_BLIT fail: %s",__FUNCTION__, __LINE__,strerror(errno));
+ ALOGE(" %s(%d) RGA_BLIT fail: %s",__FUNCTION__, __LINE__,strerror(errno));
+ }
+
+ return 0;
+}
+
+int RgaBlit(buffer_handle_t src,
+ void *dst, drm_rga_t *rects, int rotation, int blend)
+{
+ //check rects
+ //check buffer_handle_t with rects
+ struct rgaContext *ctx = rgaCtx;
+ int srcVirW,srcVirH,srcActW,srcActH,srcXPos,srcYPos;
+ int dstVirW,dstVirH,dstActW,dstActH,dstXPos,dstYPos;
+ int scaleMode,rotateMode,orientation,ditherEn;
+ int srcType,dstType,srcMmuFlag,dstMmuFlag;
+ int planeAlpha;
+ int dstFd = -1;
+ int srcFd = -1;
+ int ret = 0;
+ drm_rga_t tmpRects,relRects;
+ struct rga_req rgaReg;
+ bool perpixelAlpha;
+ void *srcBuf = NULL;
+ void *dstBuf = NULL;
+ RECT clip;
+
+ if (!ctx) {
+ ALOGE("Try to use uninit rgaCtx=%p",ctx);
+ return -ENODEV;
+ }
+
+ memset(&rgaReg, 0, sizeof(struct rga_req));
+
+ srcType = dstType = srcMmuFlag = dstMmuFlag = 0;
+
+ if (!rects) {
+ ALOGE("%d:Has not user rects for render", __LINE__);
+ return ret;
+ }
+
+ if (rects->dst.wstride <= 0) {
+ ALOGE("%d:Has invalid rects for render", __LINE__);
+ return -EINVAL;
+ }
+
+ ret = NormalRgaGetRects(src, NULL, &srcType, &dstType, &tmpRects);
+ if (ret) {
+ ALOGE("%d:Has not rects for render", __LINE__);
+ return ret;
+ }
+
+ if (rects->src.wstride > 0)
+ memcpy(&relRects, rects, sizeof(drm_rga_t));
+ else {
+ memcpy(&(relRects.src), &(tmpRects.src), sizeof(rga_rect_t));
+ memcpy(&(relRects.dst), &(rects->dst), sizeof(rga_rect_t));
+ }
+
+ RkRgaGetHandleMapAddress(src, &srcBuf);
+ RkRgaGetHandleFd(src, &srcFd);
+ if (srcFd == -1 && !srcBuf) {
+ ALOGE("%d:src has not fd and address for render", __LINE__);
+ return ret;
+ }
+
+ if (srcFd == 0 && !srcBuf) {
+ ALOGE("srcFd is zero, now driver not support");
+ return -EINVAL;
+ } else
+ srcFd = -1;
+
+ dstBuf = dst;
+ if (!dstBuf) {
+ ALOGE("%d:dst has not fd and address for render", __LINE__);
+ return ret;
+ }
+
+ planeAlpha = (blend & 0xFF0000) >> 16;
+ perpixelAlpha = relRects.src.format == HAL_PIXEL_FORMAT_RGBA_8888 ||
+ relRects.src.format == HAL_PIXEL_FORMAT_BGRA_8888;
+
+ switch ((blend & 0xFFFF)) {
+ case 0x0105:
+ if (perpixelAlpha && planeAlpha < 255)
+ NormalRgaSetAlphaEnInfo(&rgaReg, 1, 2, planeAlpha , 1, 9, 0);
+ else if (perpixelAlpha)
+ NormalRgaSetAlphaEnInfo(&rgaReg, 1, 1, 0, 1, 3, 0);
+ else
+ NormalRgaSetAlphaEnInfo(&rgaReg, 1, 0, planeAlpha , 0, 0, 0);
+ break;
+
+ case 0x0405:
+ if (perpixelAlpha && planeAlpha < 255)
+ NormalRgaSetAlphaEnInfo(&rgaReg, 1, 2, planeAlpha , 0, 0, 0);
+ else if (perpixelAlpha)
+ NormalRgaSetAlphaEnInfo(&rgaReg, 1, 1, 0, 0, 0, 0);
+ else
+ NormalRgaSetAlphaEnInfo(&rgaReg, 1, 0, planeAlpha , 0, 0, 0);
+ break;
+
+ case 0x0100:
+ default:
+ /* Tips: BLENDING_NONE is non-zero value, handle zero value as
+ * BLENDING_NONE. */
+ /* C = Cs
+ * A = As */
+ break;
+ }
+
+
+ switch (rotation) {
+ case HAL_TRANSFORM_FLIP_H:
+ orientation = 0;
+ rotateMode = 2;
+ srcVirW = relRects.src.wstride;
+ srcVirH = relRects.src.height;
+ srcXPos = relRects.src.xoffset;
+ srcYPos = relRects.src.yoffset;
+ srcActW = relRects.src.width;
+ srcActH = relRects.src.height;
+
+ dstVirW = relRects.dst.wstride;
+ dstVirH = relRects.dst.height;
+ dstXPos = relRects.dst.xoffset;
+ dstYPos = relRects.dst.yoffset;
+ dstActW = relRects.dst.width;
+ dstActH = relRects.dst.height;
+ break;
+ case HAL_TRANSFORM_FLIP_V:
+ orientation = 0;
+ rotateMode = 3;
+ srcVirW = relRects.src.wstride;
+ srcVirH = relRects.src.height;
+ srcXPos = relRects.src.xoffset;
+ srcYPos = relRects.src.yoffset;
+ srcActW = relRects.src.width;
+ srcActH = relRects.src.height;
+
+ dstVirW = relRects.dst.wstride;
+ dstVirH = relRects.dst.height;
+ dstXPos = relRects.dst.xoffset;
+ dstYPos = relRects.dst.yoffset;
+ dstActW = relRects.dst.width;
+ dstActH = relRects.dst.height;
+ break;
+ case HAL_TRANSFORM_ROT_90:
+ orientation = 90;
+ rotateMode = 1;
+ srcVirW = relRects.src.wstride;
+ srcVirH = relRects.src.height;
+ srcXPos = relRects.src.xoffset;
+ srcYPos = relRects.src.yoffset;
+ srcActW = relRects.src.width;
+ srcActH = relRects.src.height;
+
+ dstVirW = relRects.dst.wstride;
+ dstVirH = relRects.dst.height;
+ dstXPos = relRects.dst.width - 1;
+ //dstYPos = relRects.dst.yoffset;
+ dstYPos = 0;
+ dstActW = relRects.dst.height;
+ dstActH = relRects.dst.width;
+ break;
+ case HAL_TRANSFORM_ROT_180:
+ orientation = 180;
+ rotateMode = 1;
+ srcVirW = relRects.src.wstride;
+ srcVirH = relRects.src.height;
+ srcXPos = relRects.src.xoffset;
+ srcYPos = relRects.src.yoffset;
+ srcActW = relRects.src.width;
+ srcActH = relRects.src.height;
+
+ dstVirW = relRects.dst.wstride;
+ dstVirH = relRects.dst.height;
+ dstXPos = relRects.dst.width - 1;
+ dstYPos = relRects.dst.height - 1;
+ dstActW = relRects.dst.width;
+ dstActH = relRects.dst.height;
+ break;
+ case HAL_TRANSFORM_ROT_270:
+ orientation = 270;
+ rotateMode = 1;
+ srcVirW = relRects.src.wstride;
+ srcVirH = relRects.src.height;
+ srcXPos = relRects.src.xoffset;
+ srcYPos = relRects.src.yoffset;
+ srcActW = relRects.src.width;
+ srcActH = relRects.src.height;
+
+ dstVirW = relRects.dst.wstride;
+ dstVirH = relRects.dst.height;
+ //dstXPos = relRects.dst.xoffset;
+ dstXPos = 0;
+ dstYPos = relRects.dst.height - 1;
+ dstActW = relRects.dst.height;
+ dstActH = relRects.dst.width;
+ break;
+ default:
+ orientation = 0;
+ rotateMode = 0;
+ srcVirW = relRects.src.wstride;
+ srcVirH = relRects.src.height;
+ srcXPos = relRects.src.xoffset;
+ srcYPos = relRects.src.yoffset;
+ srcActW = relRects.src.width;
+ srcActH = relRects.src.height;
+
+ dstVirW = relRects.dst.wstride;
+ dstVirH = relRects.dst.height;
+ dstXPos = relRects.dst.xoffset;
+ dstYPos = relRects.dst.yoffset;
+ dstActW = relRects.dst.width;
+ dstActH = relRects.dst.height;
+ break;
+ }
+
+ clip.xmin = 0;
+ clip.xmax = dstActW - 1;
+ clip.ymin = 0;
+ clip.ymax = dstActH - 1;
+
+ scaleMode = 0;
+ //scale up use bicubic
+ if (srcActW / dstActW < 1 || srcActH / dstActH < 1)
+ scaleMode = 2;
+
+ /*
+ if (scaleMode && (srcFormat == RK_FORMAT_RGBA_8888 ||
+ srcFormat == RK_FORMAT_BGRA_8888)) {
+ scale_mode = 0; // force change scale_mode to 0 ,for rga not support
+ }*/
+
+ ditherEn = (android::bytesPerPixel(relRects.src.format)
+ != android::bytesPerPixel(relRects.src.format) ? 1 : 0);
+
+ if (ctx->mVersion <= 1.003) {
+ srcMmuFlag = dstMmuFlag = 1;
+
+#if defined(__arm64__) || defined(__aarch64__)
+ NormalRgaSetSrcVirtualInfo(&rgaReg, (unsigned long)srcBuf,
+ (unsigned long)srcBuf + srcVirW * srcVirH,
+ (unsigned long)srcBuf + srcVirW * srcVirH * 5/4,
+ srcVirW, srcVirH,
+ RkRgaGetRgaFormat(relRects.src.format),0);
+ /*dst*/
+ NormalRgaSetDstVirtualInfo(&rgaReg, (unsigned long)dstBuf,
+ (unsigned long)dstBuf + dstVirW * dstVirH,
+ (unsigned long)dstBuf + dstVirW * dstVirH * 5/4,
+ dstVirW, dstVirH, &clip,
+ RkRgaGetRgaFormat(relRects.dst.format),0);
+#else
+ NormalRgaSetSrcVirtualInfo(&rgaReg, (unsigned int)srcBuf,
+ (unsigned int)srcBuf + srcVirW * srcVirH,
+ (unsigned int)srcBuf + srcVirW * srcVirH * 5/4,
+ srcVirW, srcVirH,
+ RkRgaGetRgaFormat(relRects.src.format),0);
+ /*dst*/
+ NormalRgaSetDstVirtualInfo(&rgaReg, (unsigned int)dstBuf,
+ (unsigned int)dstBuf + dstVirW * dstVirH,
+ (unsigned int)dstBuf + dstVirW * dstVirH * 5/4,
+ dstVirW, dstVirH, &clip,
+ RkRgaGetRgaFormat(relRects.dst.format),0);
+#endif
+ } else if (ctx->mVersion < 2.0) {
+ /*Src*/
+ if (srcFd != -1) {
+ srcMmuFlag = srcType ? 1 : 0;
+ NormalRgaSetSrcVirtualInfo(&rgaReg, 0, 0, 0, srcVirW, srcVirH,
+ RkRgaGetRgaFormat(relRects.src.format),0);
+ NormalRgaSetFdsOffsets(&rgaReg, srcFd, 0, 0, 0);
+ } else {
+ srcMmuFlag = 1;
+
+#if defined(__arm64__) || defined(__aarch64__)
+ NormalRgaSetSrcVirtualInfo(&rgaReg, (unsigned long)srcBuf,
+ (unsigned long)srcBuf + srcVirW * srcVirH,
+ (unsigned long)srcBuf + srcVirW * srcVirH * 5/4,
+ srcVirW, srcVirH,
+ RkRgaGetRgaFormat(relRects.src.format),0);
+#else
+ NormalRgaSetSrcVirtualInfo(&rgaReg, (unsigned int)srcBuf,
+ (unsigned int)srcBuf + srcVirW * srcVirH,
+ (unsigned int)srcBuf + srcVirW * srcVirH * 5/4,
+ srcVirW, srcVirH,
+ RkRgaGetRgaFormat(relRects.src.format),0);
+#endif
+ }
+ /*dst*/
+ if (dstFd != -1) {
+ dstMmuFlag = srcType ? 1 : 0;
+ NormalRgaSetDstVirtualInfo(&rgaReg, 0, 0, 0, dstVirW, dstVirH, &clip,
+ RkRgaGetRgaFormat(relRects.dst.format),0);
+ /*src dst fd*/
+ NormalRgaSetFdsOffsets(&rgaReg, 0, dstFd, 0, 0);
+ } else {
+ dstMmuFlag = 1;
+#if defined(__arm64__) || defined(__aarch64__)
+ NormalRgaSetDstVirtualInfo(&rgaReg, (unsigned long)dstBuf,
+ (unsigned long)dstBuf + dstVirW * dstVirH,
+ (unsigned long)dstBuf + dstVirW * dstVirH * 5/4,
+ dstVirW, dstVirH, &clip,
+ RkRgaGetRgaFormat(relRects.dst.format),0);
+#else
+ NormalRgaSetDstVirtualInfo(&rgaReg, (unsigned int)dstBuf,
+ (unsigned int)dstBuf + dstVirW * dstVirH,
+ (unsigned int)dstBuf + dstVirW * dstVirH * 5/4,
+ dstVirW, dstVirH, &clip,
+ RkRgaGetRgaFormat(relRects.dst.format),0);
+#endif
+ }
+ } else {
+ srcMmuFlag = ((srcFd != -1 && srcType) || srcFd == -1) ? 1 : 0;
+ dstMmuFlag = ((dstFd != -1 && dstType) || dstFd == -1) ? 1 : 0;
+#if defined(__arm64__) || defined(__aarch64__)
+ NormalRgaSetSrcVirtualInfo(&rgaReg, srcFd != -1 ? srcFd : 0,
+ (unsigned long)srcBuf,
+ (unsigned long)srcBuf + srcVirW * srcVirH,
+ srcVirW, srcVirH,
+ RkRgaGetRgaFormat(relRects.src.format),0);
+ /*dst*/
+ NormalRgaSetDstVirtualInfo(&rgaReg, dstFd != -1 ? dstFd : 0,
+ (unsigned long)dstBuf,
+ (unsigned long)dstBuf + dstVirW * dstVirH,
+ dstVirW, dstVirH, &clip,
+ RkRgaGetRgaFormat(relRects.dst.format),0);
+#else
+ NormalRgaSetSrcVirtualInfo(&rgaReg, srcFd != -1 ? srcFd : 0,
+ (unsigned int)srcBuf,
+ (unsigned int)srcBuf + srcVirW * srcVirH,
+ srcVirW, srcVirH,
+ RkRgaGetRgaFormat(relRects.src.format),0);
+ /*dst*/
+ NormalRgaSetDstVirtualInfo(&rgaReg, dstFd != -1 ? dstFd : 0,
+ (unsigned int)dstBuf,
+ (unsigned int)dstBuf + dstVirW * dstVirH,
+ dstVirW, dstVirH, &clip,
+ RkRgaGetRgaFormat(relRects.dst.format),0);
+#endif
+ }
+
+ NormalRgaSetSrcActiveInfo(&rgaReg, srcActW, srcActH, srcXPos, srcYPos);
+ NormalRgaSetDstActiveInfo(&rgaReg, dstActW, dstActH, dstXPos, dstYPos);
+
+ /*mode*/
+ NormalRgaSetBitbltMode(&rgaReg, scaleMode, rotateMode, orientation, ditherEn, 0, 0);
+
+ if (srcMmuFlag || dstMmuFlag) {
+ NormalRgaMmuInfo(&rgaReg, 1, 0, 0, 0, 0, 2);
+ NormalRgaMmuFlag(&rgaReg, srcMmuFlag, dstMmuFlag);
+ }
+
+ if(ioctl(ctx->rgaFd, RGA_BLIT_SYNC, &rgaReg)) {
+ printf(" %s(%d) RGA_BLIT fail: %s",__FUNCTION__, __LINE__,strerror(errno));
+ ALOGE(" %s(%d) RGA_BLIT fail: %s",__FUNCTION__, __LINE__,strerror(errno));
+ }
+
+ return 0;
+}
+
+int RgaBlit(void *src, void *dst,
+ drm_rga_t *rects, int rotation, int blend)
+{
+ //check rects
+ //check buffer_handle_t with rects
+ struct rgaContext *ctx = rgaCtx;
+ int srcVirW,srcVirH,srcActW,srcActH,srcXPos,srcYPos;
+ int dstVirW,dstVirH,dstActW,dstActH,dstXPos,dstYPos;
+ int scaleMode,rotateMode,orientation,ditherEn;
+ int srcType,dstType,srcMmuFlag,dstMmuFlag;
+ int planeAlpha;
+ int dstFd = -1;
+ int srcFd = -1;
+ int ret = 0;
+ drm_rga_t relRects;
+ struct rga_req rgaReg;
+ bool perpixelAlpha;
+ void *srcBuf = NULL;
+ void *dstBuf = NULL;
+ RECT clip;
+
+ if (!ctx) {
+ ALOGE("Try to use uninit rgaCtx=%p",ctx);
+ return -ENODEV;
+ }
+
+ if (rects && (ctx->mLogAlways || ctx->mLogOnce)) {
+ ALOGD("Src:[%d,%d,%d,%d][%d,%d,%d]=>Dst:[%d,%d,%d,%d][%d,%d,%d]",
+ rects->src.xoffset,rects->src.yoffset,
+ rects->src.width, rects->src.height,
+ rects->src.wstride,rects->src.format, rects->src.size,
+ rects->dst.xoffset,rects->dst.yoffset,
+ rects->dst.width, rects->dst.height,
+ rects->dst.wstride,rects->dst.format, rects->dst.size);
+ }
+
+ memset(&rgaReg, 0, sizeof(struct rga_req));
+
+ srcType = dstType = srcMmuFlag = dstMmuFlag = 0;
+
+ if (!rects) {
+ ALOGE("%d:Has not user rects for render", __LINE__);
+ return ret;
+ }
+
+ if (rects->src.wstride <= 0 || rects->dst.wstride <= 0) {
+ ALOGE("%d:Has invalid rects for render", __LINE__);
+ return -EINVAL;
+ }
+
+ memcpy(&relRects, rects, sizeof(drm_rga_t));
+
+ srcBuf = src;
+ if (!srcBuf) {
+ ALOGE("%d:src has not fd and address for render", __LINE__);
+ return ret;
+ }
+
+ dstBuf = dst;
+ if (!dstBuf) {
+ ALOGE("%d:dst has not fd and address for render", __LINE__);
+ return ret;
+ }
+
+ planeAlpha = (blend & 0xFF0000) >> 16;
+ perpixelAlpha = relRects.src.format == HAL_PIXEL_FORMAT_RGBA_8888 ||
+ relRects.src.format == HAL_PIXEL_FORMAT_BGRA_8888;
+
+ switch ((blend & 0xFFFF)) {
+ case 0x0105:
+ if (perpixelAlpha && planeAlpha < 255)
+ NormalRgaSetAlphaEnInfo(&rgaReg, 1, 2, planeAlpha , 1, 9, 0);
+ else if (perpixelAlpha)
+ NormalRgaSetAlphaEnInfo(&rgaReg, 1, 1, 0, 1, 3, 0);
+ else
+ NormalRgaSetAlphaEnInfo(&rgaReg, 1, 0, planeAlpha , 0, 0, 0);
+ break;
+
+ case 0x0405:
+ if (perpixelAlpha && planeAlpha < 255)
+ NormalRgaSetAlphaEnInfo(&rgaReg, 1, 2, planeAlpha , 0, 0, 0);
+ else if (perpixelAlpha)
+ NormalRgaSetAlphaEnInfo(&rgaReg, 1, 1, 0, 0, 0, 0);
+ else
+ NormalRgaSetAlphaEnInfo(&rgaReg, 1, 0, planeAlpha , 0, 0, 0);
+ break;
+
+ case 0x0100:
+ default:
+ /* Tips: BLENDING_NONE is non-zero value, handle zero value as
+ * BLENDING_NONE. */
+ /* C = Cs
+ * A = As */
+ break;
+ }
+
+
+ switch (rotation) {
+ case HAL_TRANSFORM_FLIP_H:
+ orientation = 0;
+ rotateMode = 2;
+ srcVirW = relRects.src.wstride;
+ srcVirH = relRects.src.height;
+ srcXPos = relRects.src.xoffset;
+ srcYPos = relRects.src.yoffset;
+ srcActW = relRects.src.width;
+ srcActH = relRects.src.height;
+
+ dstVirW = relRects.dst.wstride;
+ dstVirH = relRects.dst.height;
+ dstXPos = relRects.dst.xoffset;
+ dstYPos = relRects.dst.yoffset;
+ dstActW = relRects.dst.width;
+ dstActH = relRects.dst.height;
+ break;
+ case HAL_TRANSFORM_FLIP_V:
+ orientation = 0;
+ rotateMode = 3;
+ srcVirW = relRects.src.wstride;
+ srcVirH = relRects.src.height;
+ srcXPos = relRects.src.xoffset;
+ srcYPos = relRects.src.yoffset;
+ srcActW = relRects.src.width;
+ srcActH = relRects.src.height;
+
+ dstVirW = relRects.dst.wstride;
+ dstVirH = relRects.dst.height;
+ dstXPos = relRects.dst.xoffset;
+ dstYPos = relRects.dst.yoffset;
+ dstActW = relRects.dst.width;
+ dstActH = relRects.dst.height;
+ break;
+ case HAL_TRANSFORM_ROT_90:
+ orientation = 90;
+ rotateMode = 1;
+ srcVirW = relRects.src.wstride;
+ srcVirH = relRects.src.height;
+ srcXPos = relRects.src.xoffset;
+ srcYPos = relRects.src.yoffset;
+ srcActW = relRects.src.width;
+ srcActH = relRects.src.height;
+
+ dstVirW = relRects.dst.wstride;
+ dstVirH = relRects.dst.height;
+ dstXPos = relRects.dst.width - 1;
+ //dstYPos = relRects.dst.yoffset;
+ dstYPos = 0;
+ dstActW = relRects.dst.height;
+ dstActH = relRects.dst.width;
+ break;
+ case HAL_TRANSFORM_ROT_180:
+ orientation = 180;
+ rotateMode = 1;
+ srcVirW = relRects.src.wstride;
+ srcVirH = relRects.src.height;
+ srcXPos = relRects.src.xoffset;
+ srcYPos = relRects.src.yoffset;
+ srcActW = relRects.src.width;
+ srcActH = relRects.src.height;
+
+ dstVirW = relRects.dst.wstride;
+ dstVirH = relRects.dst.height;
+ dstXPos = relRects.dst.width - 1;
+ dstYPos = relRects.dst.height - 1;
+ dstActW = relRects.dst.width;
+ dstActH = relRects.dst.height;
+ break;
+ case HAL_TRANSFORM_ROT_270:
+ orientation = 270;
+ rotateMode = 1;
+ srcVirW = relRects.src.wstride;
+ srcVirH = relRects.src.height;
+ srcXPos = relRects.src.xoffset;
+ srcYPos = relRects.src.yoffset;
+ srcActW = relRects.src.width;
+ srcActH = relRects.src.height;
+
+ dstVirW = relRects.dst.wstride;
+ dstVirH = relRects.dst.height;
+ //dstXPos = relRects.dst.xoffset;
+ dstXPos = 0;
+ dstYPos = relRects.dst.height - 1;
+ dstActW = relRects.dst.height;
+ dstActH = relRects.dst.width;
+ break;
+ default:
+ orientation = 0;
+ rotateMode = 0;
+ srcVirW = relRects.src.wstride;
+ srcVirH = relRects.src.height;
+ srcXPos = relRects.src.xoffset;
+ srcYPos = relRects.src.yoffset;
+ srcActW = relRects.src.width;
+ srcActH = relRects.src.height;
+
+ dstVirW = relRects.dst.wstride;
+ dstVirH = relRects.dst.height;
+ dstXPos = relRects.dst.xoffset;
+ dstYPos = relRects.dst.yoffset;
+ dstActW = relRects.dst.width;
+ dstActH = relRects.dst.height;
+ break;
+ }
+
+ clip.xmin = 0;
+ clip.xmax = dstActW - 1;
+ clip.ymin = 0;
+ clip.ymax = dstActH - 1;
+
+ scaleMode = 0;
+ //scale up use bicubic
+ if (srcActW / dstActW < 1 || srcActH / dstActH < 1)
+ scaleMode = 2;
+
+ /*
+ if (scaleMode && (srcFormat == RK_FORMAT_RGBA_8888 ||
+ srcFormat == RK_FORMAT_BGRA_8888)) {
+ scale_mode = 0; // force change scale_mode to 0 ,for rga not support
+ }*/
+
+ ditherEn = (android::bytesPerPixel(relRects.src.format)
+ != android::bytesPerPixel(relRects.src.format) ? 1 : 0);
+
+ if (ctx->mVersion <= 1.003) {
+ srcMmuFlag = dstMmuFlag = 1;
+
+#if defined(__arm64__) || defined(__aarch64__)
+ NormalRgaSetSrcVirtualInfo(&rgaReg, (unsigned long)srcBuf,
+ (unsigned long)srcBuf + srcVirW * srcVirH,
+ (unsigned long)srcBuf + srcVirW * srcVirH * 5/4,
+ srcVirW, srcVirH,
+ RkRgaGetRgaFormat(relRects.src.format),0);
+ /*dst*/
+ NormalRgaSetDstVirtualInfo(&rgaReg, (unsigned long)dstBuf,
+ (unsigned long)dstBuf + dstVirW * dstVirH,
+ (unsigned long)dstBuf + dstVirW * dstVirH * 5/4,
+ dstVirW, dstVirH, &clip,
+ RkRgaGetRgaFormat(relRects.dst.format),0);
+#else
+ NormalRgaSetSrcVirtualInfo(&rgaReg, (unsigned int)srcBuf,
+ (unsigned int)srcBuf + srcVirW * srcVirH,
+ (unsigned int)srcBuf + srcVirW * srcVirH * 5/4,
+ srcVirW, srcVirH,
+ RkRgaGetRgaFormat(relRects.src.format),0);
+ /*dst*/
+ NormalRgaSetDstVirtualInfo(&rgaReg, (unsigned int)dstBuf,
+ (unsigned int)dstBuf + dstVirW * dstVirH,
+ (unsigned int)dstBuf + dstVirW * dstVirH * 5/4,
+ dstVirW, dstVirH, &clip,
+ RkRgaGetRgaFormat(relRects.dst.format),0);
+#endif
+ } else if (ctx->mVersion < 2.0) {
+ /*Src*/
+ if (srcFd != -1) {
+ srcMmuFlag = srcType ? 1 : 0;
+ NormalRgaSetSrcVirtualInfo(&rgaReg, 0, 0, 0, srcVirW, srcVirH,
+ RkRgaGetRgaFormat(relRects.src.format),0);
+ NormalRgaSetFdsOffsets(&rgaReg, srcFd, 0, 0, 0);
+ } else {
+ srcMmuFlag = 1;
+
+#if defined(__arm64__) || defined(__aarch64__)
+ NormalRgaSetSrcVirtualInfo(&rgaReg, (unsigned long)srcBuf,
+ (unsigned long)srcBuf + srcVirW * srcVirH,
+ (unsigned long)srcBuf + srcVirW * srcVirH * 5/4,
+ srcVirW, srcVirH,
+ RkRgaGetRgaFormat(relRects.src.format),0);
+#else
+ NormalRgaSetSrcVirtualInfo(&rgaReg, (unsigned int)srcBuf,
+ (unsigned int)srcBuf + srcVirW * srcVirH,
+ (unsigned int)srcBuf + srcVirW * srcVirH * 5/4,
+ srcVirW, srcVirH,
+ RkRgaGetRgaFormat(relRects.src.format),0);
+#endif
+ }
+ /*dst*/
+ if (dstFd != -1) {
+ dstMmuFlag = srcType ? 1 : 0;
+ NormalRgaSetDstVirtualInfo(&rgaReg, 0, 0, 0, dstVirW, dstVirH, &clip,
+ RkRgaGetRgaFormat(relRects.dst.format),0);
+ /*src dst fd*/
+ NormalRgaSetFdsOffsets(&rgaReg, 0, dstFd, 0, 0);
+ } else {
+ dstMmuFlag = 1;
+#if defined(__arm64__) || defined(__aarch64__)
+ NormalRgaSetDstVirtualInfo(&rgaReg, (unsigned long)dstBuf,
+ (unsigned long)dstBuf + dstVirW * dstVirH,
+ (unsigned long)dstBuf + dstVirW * dstVirH * 5/4,
+ dstVirW, dstVirH, &clip,
+ RkRgaGetRgaFormat(relRects.dst.format),0);
+#else
+ NormalRgaSetDstVirtualInfo(&rgaReg, (unsigned int)dstBuf,
+ (unsigned int)dstBuf + dstVirW * dstVirH,
+ (unsigned int)dstBuf + dstVirW * dstVirH * 5/4,
+ dstVirW, dstVirH, &clip,
+ RkRgaGetRgaFormat(relRects.dst.format),0);
+#endif
+ }
+ } else {
+ srcMmuFlag = ((srcFd != -1 && srcType) || srcFd == -1) ? 1 : 0;
+ dstMmuFlag = ((dstFd != -1 && dstType) || dstFd == -1) ? 1 : 0;
+#if defined(__arm64__) || defined(__aarch64__)
+ NormalRgaSetSrcVirtualInfo(&rgaReg, srcFd != -1 ? srcFd : 0,
+ (unsigned long)srcBuf,
+ (unsigned long)srcBuf + srcVirW * srcVirH,
+ srcVirW, srcVirH,
+ RkRgaGetRgaFormat(relRects.src.format),0);
+ /*dst*/
+ NormalRgaSetDstVirtualInfo(&rgaReg, dstFd != -1 ? dstFd : 0,
+ (unsigned long)dstBuf,
+ (unsigned long)dstBuf + dstVirW * dstVirH,
+ dstVirW, dstVirH, &clip,
+ RkRgaGetRgaFormat(relRects.dst.format),0);
+#else
+ NormalRgaSetSrcVirtualInfo(&rgaReg, srcFd != -1 ? srcFd : 0,
+ (unsigned int)srcBuf,
+ (unsigned int)srcBuf + srcVirW * srcVirH,
+ srcVirW, srcVirH,
+ RkRgaGetRgaFormat(relRects.src.format),0);
+ /*dst*/
+ NormalRgaSetDstVirtualInfo(&rgaReg, dstFd != -1 ? dstFd : 0,
+ (unsigned int)dstBuf,
+ (unsigned int)dstBuf + dstVirW * dstVirH,
+ dstVirW, dstVirH, &clip,
+ RkRgaGetRgaFormat(relRects.dst.format),0);
+#endif
+ }
+
+ NormalRgaSetSrcActiveInfo(&rgaReg, srcActW, srcActH, srcXPos, srcYPos);
+ NormalRgaSetDstActiveInfo(&rgaReg, dstActW, dstActH, dstXPos, dstYPos);
+
+ /*mode*/
+ NormalRgaSetBitbltMode(&rgaReg, scaleMode, rotateMode, orientation, ditherEn, 0, 0);
+
+ if (srcMmuFlag || dstMmuFlag) {
+ NormalRgaMmuInfo(&rgaReg, 1, 0, 0, 0, 0, 2);
+ NormalRgaMmuFlag(&rgaReg, srcMmuFlag, dstMmuFlag);
+ }
+
+ if(ioctl(ctx->rgaFd, RGA_BLIT_SYNC, &rgaReg)) {
+ printf(" %s(%d) RGA_BLIT fail: %s",__FUNCTION__, __LINE__,strerror(errno));
+ ALOGE(" %s(%d) RGA_BLIT fail: %s",__FUNCTION__, __LINE__,strerror(errno));
+ }
+
+ if (ctx->mLogOnce)
+ ctx->mLogOnce = 0;
+
+ return 0;
+}
+
+int NormalRgaScale()
+{
+ return 1;
+}
+
+int NormalRgaRoate()
+{
+ return 1;
+}
+
+int NormalRgaRoateScale()
+{
+ return 1;
+}
diff --git a/mix/gralloc_rga.h b/mix/gralloc_rga.h
new file mode 100644
index 0000000..2d5e581
--- /dev/null
+++ b/mix/gralloc_rga.h
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2016 Rockchip Electronics Co.Ltd
+ * Authors:
+ * Zhiqin Wei <wzq@rock-chips.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ */
+
+#ifndef _rockchip_rga_drm_gralloc_h_
+#define _rockchip_rga_drm_gralloc_h_
+
+#ifndef RK3368
+#include <gralloc_priv.h>
+
+#else
+#include <hardware/img_gralloc_public.h>
+#ifndef GRALLOC_MODULE_PERFORM_GET_HADNLE_PRIME_FD
+#define GRALLOC_MODULE_PERFORM_GET_HADNLE_PRIME_FD 0x81000002
+#endif
+
+#ifndef GRALLOC_MODULE_PERFORM_GET_HADNLE_ATTRIBUTES
+#define GRALLOC_MODULE_PERFORM_GET_HADNLE_ATTRIBUTES 0x81000004
+#endif
+
+#ifndef GRALLOC_MODULE_PERFORM_GET_INTERNAL_FORMAT
+#define GRALLOC_MODULE_PERFORM_GET_INTERNAL_FORMAT 0x81000006
+#endif
+
+#ifndef GRALLOC_MODULE_PERFORM_GET_USAGE
+#define GRALLOC_MODULE_PERFORM_GET_USAGE 0xffeeff03
+#endif
+#endif
+
+#endif
+
diff --git a/normal/NormalRga.cpp b/normal/NormalRga.cpp
new file mode 100644
index 0000000..14a3e86
--- /dev/null
+++ b/normal/NormalRga.cpp
@@ -0,0 +1,2506 @@
+/*
+ * Copyright (C) 2016 Rockchip Electronics Co.Ltd
+ * Authors:
+ * Zhiqin Wei <wzq@rock-chips.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ */
+#include "NormalRga.h"
+#include "NormalRgaContext.h"
+#include "../GraphicBuffer.h"
+#include "../RgaApi.h"
+
+volatile int32_t refCount = 0;
+struct rgaContext *rgaCtx = NULL;
+
+void NormalRgaSetLogOnceFlag(int log)
+{
+ struct rgaContext *ctx = NULL;
+
+ ctx->mLogOnce = log;
+ return;
+}
+
+void NormalRgaSetAlwaysLogFlag(int log)
+{
+ struct rgaContext *ctx = NULL;
+
+ ctx->mLogAlways = log;
+ return;
+}
+
+int NormalRgaOpen(void **context)
+{
+ struct rgaContext *ctx = NULL;
+ char buf[30];
+ int fd = -1;
+ int ret = 0;
+
+ if (!context) {
+ ret = -EINVAL;
+ goto mallocErr;
+ }
+
+ if (!rgaCtx) {
+ ctx = (struct rgaContext *)malloc(sizeof(struct rgaContext));
+ if(!ctx) {
+ ret = -ENOMEM;
+ ALOGE("malloc fail:%s.",strerror(errno));
+ goto mallocErr;
+ }
+ } else {
+ ctx = rgaCtx;
+ ALOGW("Had init the rga dev ctx = %p",ctx);
+ goto init;
+ }
+
+ fd = open("/dev/rga", O_RDWR, 0);
+ if (fd < 0) {
+ ret = -ENODEV;
+ ALOGE("failed to open DRM:%s.",strerror(errno));
+ goto drmOpenErr;
+ }
+ ctx->rgaFd = fd;
+
+ ret = ioctl(fd, RGA_GET_VERSION, buf);
+ ctx->mVersion = atof(buf);
+ fprintf(stderr, "librga:RGA_GET_VERSION:%s,%f\n", buf, ctx->mVersion);
+
+ NormalRgaInitTables();
+
+ fprintf(stderr, "ctx=%p,ctx->rgaFd=%d\n",ctx, ctx->rgaFd );
+ rgaCtx = ctx;
+
+init:
+ android_atomic_inc(&refCount);
+ *context = (void *)ctx;
+ return ret;
+
+loadModErr:
+rgaInitErr:
+devCreateErr:
+ close(fd);
+drmOpenErr:
+ free(ctx);
+mallocErr:
+ return ret;
+}
+
+int NormalRgaClose(void *context)
+{
+ struct rgaContext *ctx = rgaCtx;
+
+ if (!ctx) {
+ ALOGE("Try to exit uninit rgaCtx=%p", ctx);
+ return -ENODEV;
+ }
+
+ if (!context) {
+ ALOGE("Try to uninit rgaCtx=%p", context);
+ return -ENODEV;
+ }
+
+ if (context != ctx) {
+ ALOGE("Try to exit wrong ctx=%p",ctx);
+ return -ENODEV;
+ }
+
+ if (refCount <= 0) {
+ ALOGW("This can not be happened");
+ return 0;
+ }
+
+ if (refCount > 0 && android_atomic_dec(&refCount) != 1)
+ return 0;
+
+ rgaCtx = NULL;
+
+ close(ctx->rgaFd);
+
+ free(ctx);
+
+ return 0;
+}
+
+int RgaInit(void **ctx)
+{
+ int ret = 0;
+ ret = NormalRgaOpen(ctx);
+ return ret;
+}
+
+int RgaDeInit(void *ctx)
+{
+ int ret = 0;
+ ret = NormalRgaClose(ctx);
+ return ret;
+}
+
+int NormalRgaPaletteTable(buffer_handle_t dst,
+ unsigned int v, drm_rga_t *rects)
+{
+ //check rects
+ //check buffer_handle_t with rects
+ struct rgaContext *ctx = rgaCtx;
+ int srcVirW,srcVirH,srcActW,srcActH,srcXPos,srcYPos;
+ int dstVirW,dstVirH,dstActW,dstActH,dstXPos,dstYPos;
+ int scaleMode,rotateMode,orientation,ditherEn;
+ int srcType,dstType,srcMmuFlag,dstMmuFlag;
+ int planeAlpha;
+ int dstFd = -1;
+ int srcFd = -1;
+ int ret = 0;
+ drm_rga_t tmpRects,relRects;
+ struct rga_req rgaReg;
+ bool perpixelAlpha;
+ void *srcBuf = NULL;
+ void *dstBuf = NULL;
+ RECT clip;
+
+ if (!ctx) {
+ ALOGE("Try to use uninit rgaCtx=%p",ctx);
+ return -ENODEV;
+ }
+
+ if (rects && (ctx->mLogAlways || ctx->mLogOnce)) {
+ ALOGD("Src:[%d,%d,%d,%d][%d,%d,%d]=>Dst:[%d,%d,%d,%d][%d,%d,%d]",
+ rects->src.xoffset,rects->src.yoffset,
+ rects->src.width, rects->src.height,
+ rects->src.wstride,rects->src.format, rects->src.size,
+ rects->dst.xoffset,rects->dst.yoffset,
+ rects->dst.width, rects->dst.height,
+ rects->dst.wstride,rects->dst.format, rects->dst.size);
+ }
+
+ memset(&rgaReg, 0, sizeof(struct rga_req));
+
+ srcType = dstType = srcMmuFlag = dstMmuFlag = 0;
+
+ ret = NormalRgaGetRects(NULL, dst, &srcType, &dstType, &tmpRects);
+ if (ret && !rects) {
+ ALOGE("%d:Has not rects for render", __LINE__);
+ return ret;
+ }
+
+ if (rects) {
+ if (rects->src.wstride > 0 && rects->dst.wstride > 0)
+ memcpy(&relRects, rects, sizeof(drm_rga_t));
+ else if (rects->src.wstride > 0) {
+ memcpy(&(relRects.src), &(rects->src), sizeof(rga_rect_t));
+ memcpy(&(relRects.dst), &(tmpRects.dst), sizeof(rga_rect_t));
+ } else if (rects->dst.wstride > 0) {
+ memcpy(&(relRects.src), &(tmpRects.src), sizeof(rga_rect_t));
+ memcpy(&(relRects.dst), &(rects->dst), sizeof(rga_rect_t));
+ }
+ } else
+ memcpy(&relRects, &tmpRects, sizeof(drm_rga_t));
+
+ if (ctx->mLogAlways || ctx->mLogOnce) {
+ ALOGD("Src:[%d,%d,%d,%d][%d,%d,%d]=>Dst:[%d,%d,%d,%d][%d,%d,%d]",
+ tmpRects.src.xoffset,tmpRects.src.yoffset,
+ tmpRects.src.width, tmpRects.src.height,
+ tmpRects.src.wstride,tmpRects.src.format, tmpRects.src.size,
+ tmpRects.dst.xoffset,tmpRects.dst.yoffset,
+ tmpRects.dst.width, tmpRects.dst.height,
+ tmpRects.dst.wstride,tmpRects.dst.format, tmpRects.dst.size);
+ ALOGD("Src:[%d,%d,%d,%d][%d,%d,%d]=>Dst:[%d,%d,%d,%d][%d,%d,%d]",
+ relRects.src.xoffset,relRects.src.yoffset,
+ relRects.src.width, relRects.src.height,
+ relRects.src.wstride,relRects.src.format, relRects.src.size,
+ relRects.dst.xoffset,relRects.dst.yoffset,
+ relRects.dst.width, relRects.dst.height,
+ relRects.dst.wstride,relRects.dst.format, relRects.dst.size);
+ }
+
+ RkRgaGetHandleMapAddress(dst, &dstBuf);
+ RkRgaGetHandleFd(dst, &dstFd);
+ if (dstFd == -1 && !dstBuf) {
+ ALOGE("%d:dst has not fd and address for render", __LINE__);
+ return ret;
+ }
+
+ if (dstFd == 0 && !dstBuf) {
+ ALOGE("dstFd is zero, now driver not support");
+ return -EINVAL;
+ } else
+ dstFd = -1;
+
+ orientation = 0;
+ rotateMode = 0;
+ srcVirW = relRects.src.wstride;
+ srcVirH = relRects.src.height;
+ srcXPos = relRects.src.xoffset;
+ srcYPos = relRects.src.yoffset;
+ srcActW = relRects.src.width;
+ srcActH = relRects.src.height;
+
+ dstVirW = relRects.dst.wstride;
+ dstVirH = relRects.dst.height;
+ dstXPos = relRects.dst.xoffset;
+ dstYPos = relRects.dst.yoffset;
+ dstActW = relRects.dst.width;
+ dstActH = relRects.dst.height;
+
+ NormalRgaSetSrcActiveInfo(&rgaReg, srcActW, srcActH, srcXPos, srcYPos);
+ NormalRgaSetDstActiveInfo(&rgaReg, dstActW, dstActH, dstXPos, dstYPos);
+ NormalRgaSetSrcVirtualInfo(&rgaReg, (unsigned long)srcBuf,
+ (unsigned long)srcBuf + srcVirW * srcVirH,
+ (unsigned long)srcBuf + srcVirW * srcVirH * 5/4,
+ srcVirW, srcVirH,
+ RkRgaGetRgaFormat(relRects.src.format),0);
+ /*dst*/
+ NormalRgaSetDstVirtualInfo(&rgaReg, (unsigned long)dstBuf,
+ (unsigned long)dstBuf + dstVirW * dstVirH,
+ (unsigned long)dstBuf + dstVirW * dstVirH * 5/4,
+ dstVirW, dstVirH, &clip,
+ RkRgaGetRgaFormat(relRects.dst.format),0);
+ NormalRgaSetPatInfo(&rgaReg, dstVirW, dstVirH,
+ dstXPos, dstYPos, relRects.dst.format);
+ NormalRgaSetFadingEnInfo(&rgaReg, v & 0xFF000000, v & 0xFF0000, v & 0xFF00);
+
+ /*mode*/
+ NormalRgaUpdatePaletteTableMode(&rgaReg, 0, v & 0xFF);
+
+ if (srcMmuFlag || dstMmuFlag) {
+ NormalRgaMmuInfo(&rgaReg, 1, 0, 0, 0, 0, 2);
+ NormalRgaMmuFlag(&rgaReg, srcMmuFlag, dstMmuFlag);
+ }
+
+ if (ctx->mLogAlways || ctx->mLogOnce)
+ NormalRgaLogOutRgaReq(rgaReg);
+
+ if(ioctl(ctx->rgaFd, RGA_BLIT_SYNC, &rgaReg)) {
+ printf(" %s(%d) RGA_BLIT fail: %s",__FUNCTION__, __LINE__,strerror(errno));
+ ALOGE(" %s(%d) RGA_BLIT fail: %s",__FUNCTION__, __LINE__,strerror(errno));
+ }
+
+ if (ctx->mLogOnce)
+ ctx->mLogOnce = 0;
+
+ return 0;
+}
+
+int RgaBlit(rga_info *src, rga_info *dst, rga_info *src1)
+{
+ //check rects
+ //check buffer_handle_t with rects
+ struct rgaContext *ctx = rgaCtx;
+ int srcVirW,srcVirH,srcActW,srcActH,srcXPos,srcYPos;
+ int dstVirW,dstVirH,dstActW,dstActH,dstXPos,dstYPos;
+ int src1VirW,src1VirH,src1ActW,src1ActH,src1XPos,src1YPos;
+ int scaleMode,rotateMode,orientation,ditherEn;
+ int srcType,dstType,src1Type,srcMmuFlag,dstMmuFlag,src1MmuFlag;
+ int planeAlpha;
+ int dstFd = -1;
+ int srcFd = -1;
+ int src1Fd = -1;
+ int rotation;
+ int ret = 0;
+ rga_rect_t relSrcRect,tmpSrcRect,relDstRect,tmpDstRect;
+ rga_rect_t relSrc1Rect,tmpSrc1Rect;
+ struct rga_req rgaReg;
+ unsigned int blend;
+ unsigned int yuvToRgbMode;
+ bool perpixelAlpha;
+ void *srcBuf = NULL;
+ void *dstBuf = NULL;
+ void *src1Buf = NULL;
+ RECT clip;
+
+ if (!ctx) {
+ ALOGE("Try to use uninit rgaCtx=%p",ctx);
+ return -ENODEV;
+ }
+
+ memset(&rgaReg, 0, sizeof(struct rga_req));
+
+ srcType = dstType = srcMmuFlag = dstMmuFlag = 0;
+ src1Type = src1MmuFlag = 0;
+ rotation = 0;
+ blend = 0;
+ yuvToRgbMode = 0;
+
+ if (!src && !dst && !src1) {
+ ALOGE("src = %p, dst = %p, src1 = %p", src, dst, src1);
+ return -EINVAL;
+ }
+
+ if (!src && !dst) {
+ ALOGE("src = %p, dst = %p", src, dst);
+ return -EINVAL;
+ }
+
+ if (src) {
+ rotation = src->rotation;
+ blend = src->blend;
+ memcpy(&relSrcRect, &src->rect, sizeof(rga_rect_t));
+ }
+
+ if (dst)
+ memcpy(&relDstRect, &dst->rect, sizeof(rga_rect_t));
+ if (src1)
+ memcpy(&relSrc1Rect, &src1->rect, sizeof(rga_rect_t));
+
+ srcFd = dstFd = src1Fd = -1;
+ if (src && src->hnd) {
+ ret = RkRgaGetHandleFd(src->hnd, &srcFd);
+ if (ret) {
+ ALOGE("dst handle get fd fail ret = %d,hnd=%p", ret, &src->hnd);
+ printf("-dst handle get fd fail ret = %d,hnd=%p", ret, &src->hnd);
+ return ret;
+ }
+ if (!isRectValid(relSrcRect)) {
+ ret = NormalRgaGetRect(src->hnd, &tmpSrcRect);
+ if (ret)
+ return ret;
+ memcpy(&relSrcRect, &tmpSrcRect, sizeof(rga_rect_t));
+ }
+ NormalRgaGetMmuType(src->hnd, &srcType);
+ }
+
+ if (dst && dst->hnd) {
+ ret = RkRgaGetHandleFd(dst->hnd, &dstFd);
+ if (ret) {
+ ALOGE("dst handle get fd fail ret = %d,hnd=%p", ret, &dst->hnd);
+ printf("-dst handle get fd fail ret = %d,hnd=%p", ret, &dst->hnd);
+ return ret;
+ }
+ if (!isRectValid(relDstRect)) {
+ ret = NormalRgaGetRect(dst->hnd, &tmpDstRect);
+ if (ret)
+ return ret;
+ memcpy(&relDstRect, &tmpDstRect, sizeof(rga_rect_t));
+ }
+ NormalRgaGetMmuType(dst->hnd, &dstType);
+ }
+
+ if (src1 && src1->hnd) {
+ ret = RkRgaGetHandleFd(src1->hnd, &src1Fd);
+ if (ret) {
+ ALOGE("dst handle get fd fail ret = %d,hnd=%p", ret, &src1->hnd);
+ printf("-dst handle get fd fail ret = %d,hnd=%p", ret, &src1->hnd);
+ return ret;
+ }
+ if (!isRectValid(relSrcRect)) {
+ ret = NormalRgaGetRect(src1->hnd, &tmpSrc1Rect);
+ if (ret)
+ return ret;
+ memcpy(&relSrc1Rect, &tmpSrc1Rect, sizeof(rga_rect_t));
+ }
+ NormalRgaGetMmuType(src1->hnd, &src1Type);
+ }
+
+ if (src && srcFd < 0)
+ srcFd = src->fd;
+
+ if (src && src->phyAddr)
+ srcBuf = src->phyAddr;
+ else if (src && src->virAddr)
+ srcBuf = src->virAddr;
+ else if (src && src->hnd)
+ ret = RkRgaGetHandleMapAddress(src->hnd, &srcBuf);
+
+ if (srcFd == -1 && !srcBuf) {
+ ALOGE("%d:src has not fd and address for render", __LINE__);
+ return ret;
+ }
+
+ if (srcFd == 0 && !srcBuf) {
+ ALOGE("srcFd is zero, now driver not support");
+ return -EINVAL;
+ }
+
+ if (srcFd == 0)
+ srcFd = -1;
+
+ if (dst && dstFd < 0)
+ dstFd = dst->fd;
+
+ if (dst && dst->phyAddr)
+ dstBuf = dst->phyAddr;
+ else if (dst && dst->virAddr)
+ dstBuf = dst->virAddr;
+ else if (dst && dst->hnd)
+ ret = RkRgaGetHandleMapAddress(dst->hnd, &dstBuf);
+
+ if (dst && dstFd == -1 && !dstBuf) {
+ ALOGE("%d:dst has not fd and address for render", __LINE__);
+ return ret;
+ }
+
+ if (dst && dstFd == 0 && !dstBuf) {
+ ALOGE("dstFd is zero, now driver not support");
+ return -EINVAL;
+ }
+
+ if (dstFd == 0)
+ dstFd = -1;
+
+ if (src1 && src1Fd < 0)
+ src1Fd = src1->fd;
+
+ if (src1 && src1->phyAddr)
+ src1Buf = src1->phyAddr;
+ else if (src1 && src1->virAddr)
+ src1Buf = src1->virAddr;
+ else if (src1 && src1->hnd)
+ ret = RkRgaGetHandleMapAddress(src1->hnd, &src1Buf);
+
+ if (src1 && src1Fd == -1 && !src1Buf) {
+ ALOGE("%d:dst has not fd and address for render", __LINE__);
+ return ret;
+ }
+
+ if (src1 && src1Fd == 0 && !src1Buf) {
+ ALOGE("dstFd is zero, now driver not support");
+ return -EINVAL;
+ }
+
+ if (src1Fd == 0)
+ src1Fd = -1;
+
+ planeAlpha = (blend & 0xFF0000) >> 16;
+ perpixelAlpha = relSrcRect.format == HAL_PIXEL_FORMAT_RGBA_8888 ||
+ relSrcRect.format == HAL_PIXEL_FORMAT_BGRA_8888;
+
+ switch ((blend & 0xFFFF)) {
+ case 0x0105:
+ if (perpixelAlpha && planeAlpha < 255)
+ NormalRgaSetAlphaEnInfo(&rgaReg, 1, 2, planeAlpha , 1, 9, 0);
+ else if (perpixelAlpha)
+ NormalRgaSetAlphaEnInfo(&rgaReg, 1, 1, 0, 1, 3, 0);
+ else
+ NormalRgaSetAlphaEnInfo(&rgaReg, 1, 0, planeAlpha , 0, 0, 0);
+ break;
+
+ case 0x0405:
+ if (perpixelAlpha && planeAlpha < 255)
+ NormalRgaSetAlphaEnInfo(&rgaReg, 1, 2, planeAlpha , 0, 0, 0);
+ else if (perpixelAlpha)
+ NormalRgaSetAlphaEnInfo(&rgaReg, 1, 1, 0, 0, 0, 0);
+ else
+ NormalRgaSetAlphaEnInfo(&rgaReg, 1, 0, planeAlpha , 0, 0, 0);
+ break;
+
+ case 0x0100:
+ default:
+ /* Tips: BLENDING_NONE is non-zero value, handle zero value as
+ * BLENDING_NONE. */
+ /* C = Cs
+ * A = As */
+ break;
+ }
+
+ if (relSrcRect.hstride == 0)
+ relSrcRect.hstride = relSrcRect.height;
+
+ if (relDstRect.hstride == 0)
+ relDstRect.hstride = relDstRect.height;
+
+ if (relSrc1Rect.hstride == 0)
+ relSrc1Rect.hstride = relSrc1Rect.height;
+
+ //if (relSrcRect.format == HAL_PIXEL_FORMAT_YCrCb_NV12_10)
+ // relSrcRect.wstride = relSrcRect.wstride * 5 / 4;
+
+ if (src) {
+ ret = checkRectForRga(relSrcRect);
+ if (ret) {
+ ALOGE("[%s,%d]Error src rect for rga blit", __func__, __LINE__);
+ return ret;
+ }
+ }
+
+ if (dst) {
+ ret = checkRectForRga(relDstRect);
+ if (ret) {
+ ALOGE("[%s,%d]Error dst rect for rga blit", __func__, __LINE__);
+ return ret;
+ }
+ }
+
+ if (src1) {
+ ret = checkRectForRga(relSrc1Rect);
+ if (ret) {
+ ALOGE("[%s,%d]Error src1 rect for rga blit", __func__, __LINE__);
+ return ret;
+ }
+ }
+
+ if (src && dst) {
+ float hScale = (float)relSrcRect.width / relDstRect.width;
+ float vScale = (float)relSrcRect.height / relDstRect.height;
+ if (rotation & HAL_TRANSFORM_ROT_90) {
+ hScale = (float)relSrcRect.width / relDstRect.height;
+ vScale = (float)relSrcRect.height / relDstRect.width;
+ }
+ if (hScale < 1/16 || hScale > 16 || vScale < 1/16 || vScale > 16) {
+ ALOGE("Error scale[%f,%f] line %d", hScale, vScale, __LINE__);
+ return -EINVAL;
+ }
+ if (ctx->mVersion <= 2.0 && (hScale < 1/8 ||
+ hScale > 8 || vScale < 1/8 || vScale > 8)) {
+ ALOGE("Error scale[%f,%f] line %d", hScale, vScale, __LINE__);
+ return -EINVAL;
+ }
+ if (ctx->mVersion <= 1.003 && (hScale < 1/2 || vScale < 1/2)) {
+ ALOGE("e scale[%f,%f] ver[%f]", hScale, vScale, ctx->mVersion);
+ return -EINVAL;
+ }
+ }
+
+ switch (rotation) {
+ case HAL_TRANSFORM_FLIP_H:
+ orientation = 0;
+ rotateMode = 2;
+ srcVirW = relSrcRect.wstride;
+ srcVirH = relSrcRect.hstride;
+ srcXPos = relSrcRect.xoffset;
+ srcYPos = relSrcRect.yoffset;
+ srcActW = relSrcRect.width;
+ srcActH = relSrcRect.height;
+
+ dstVirW = relDstRect.wstride;
+ dstVirH = relDstRect.height;
+ dstXPos = relDstRect.xoffset;
+ dstYPos = relDstRect.yoffset;
+ dstActW = relDstRect.width;
+ dstActH = relDstRect.height;
+ break;
+ case HAL_TRANSFORM_FLIP_V:
+ orientation = 0;
+ rotateMode = 3;
+ srcVirW = relSrcRect.wstride;
+ srcVirH = relSrcRect.hstride;
+ srcXPos = relSrcRect.xoffset;
+ srcYPos = relSrcRect.yoffset;
+ srcActW = relSrcRect.width;
+ srcActH = relSrcRect.height;
+
+ dstVirW = relDstRect.wstride;
+ dstVirH = relDstRect.height;
+ dstXPos = relDstRect.xoffset;
+ dstYPos = relDstRect.yoffset;
+ dstActW = relDstRect.width;
+ dstActH = relDstRect.height;
+ break;
+ case HAL_TRANSFORM_ROT_90:
+ orientation = 90;
+ rotateMode = 1;
+ srcVirW = relSrcRect.wstride;
+ srcVirH = relSrcRect.hstride;
+ srcXPos = relSrcRect.xoffset;
+ srcYPos = relSrcRect.yoffset;
+ srcActW = relSrcRect.width;
+ srcActH = relSrcRect.height;
+
+ dstVirW = relDstRect.wstride;
+ dstVirH = relDstRect.height;
+ dstXPos = relDstRect.width - 1;
+ //dstYPos = relDstRect.yoffset;
+ dstYPos = 0;
+ dstActW = relDstRect.height;
+ dstActH = relDstRect.width;
+ break;
+ case HAL_TRANSFORM_ROT_180:
+ orientation = 180;
+ rotateMode = 1;
+ srcVirW = relSrcRect.wstride;
+ srcVirH = relSrcRect.hstride;
+ srcXPos = relSrcRect.xoffset;
+ srcYPos = relSrcRect.yoffset;
+ srcActW = relSrcRect.width;
+ srcActH = relSrcRect.height;
+
+ dstVirW = relDstRect.wstride;
+ dstVirH = relDstRect.height;
+ dstXPos = relDstRect.width - 1;
+ dstYPos = relDstRect.height - 1;
+ dstActW = relDstRect.width;
+ dstActH = relDstRect.height;
+ break;
+ case HAL_TRANSFORM_ROT_270:
+ orientation = 270;
+ rotateMode = 1;
+ srcVirW = relSrcRect.wstride;
+ srcVirH = relSrcRect.hstride;
+ srcXPos = relSrcRect.xoffset;
+ srcYPos = relSrcRect.yoffset;
+ srcActW = relSrcRect.width;
+ srcActH = relSrcRect.height;
+
+ dstVirW = relDstRect.wstride;
+ dstVirH = relDstRect.height;
+ //dstXPos = relDstRect.xoffset;
+ dstXPos = 0;
+ dstYPos = relDstRect.height - 1;
+ dstActW = relDstRect.height;
+ dstActH = relDstRect.width;
+ break;
+ default:
+ orientation = 0;
+ rotateMode = 0;
+ srcVirW = relSrcRect.wstride;
+ srcVirH = relSrcRect.hstride;
+ srcXPos = relSrcRect.xoffset;
+ srcYPos = relSrcRect.yoffset;
+ srcActW = relSrcRect.width;
+ srcActH = relSrcRect.height;
+
+ dstVirW = relDstRect.wstride;
+ dstVirH = relDstRect.height;
+ dstXPos = relDstRect.xoffset;
+ dstYPos = relDstRect.yoffset;
+ dstActW = relDstRect.width;
+ dstActH = relDstRect.height;
+ break;
+ }
+
+ clip.xmin = 0;
+ clip.xmax = dstActW - 1;
+ clip.ymin = 0;
+ clip.ymax = dstActH - 1;
+
+ scaleMode = 0;
+ //scale up use bicubic
+ if (srcActW / dstActW < 1 || srcActH / dstActH < 1)
+ scaleMode = 2;
+
+ /*
+ if (scaleMode && (srcFormat == RK_FORMAT_RGBA_8888 ||
+ srcFormat == RK_FORMAT_BGRA_8888)) {
+ scale_mode = 0; // force change scale_mode to 0 ,for rga not support
+ }*/
+
+ ditherEn = (android::bytesPerPixel(relSrcRect.format)
+ != android::bytesPerPixel(relSrcRect.format) ? 1 : 0);
+
+
+ if (ctx->mVersion <= 1.003) {
+ srcMmuFlag = dstMmuFlag = 1;
+
+#if defined(__arm64__) || defined(__aarch64__)
+ NormalRgaSetSrcVirtualInfo(&rgaReg, (unsigned long)srcBuf,
+ (unsigned long)srcBuf + srcVirW * srcVirH,
+ (unsigned long)srcBuf + srcVirW * srcVirH * 5/4,
+ srcVirW, srcVirH,
+ RkRgaGetRgaFormat(relSrcRect.format),0);
+ /*dst*/
+ NormalRgaSetDstVirtualInfo(&rgaReg, (unsigned long)dstBuf,
+ (unsigned long)dstBuf + dstVirW * dstVirH,
+ (unsigned long)dstBuf + dstVirW * dstVirH * 5/4,
+ dstVirW, dstVirH, &clip,
+ RkRgaGetRgaFormat(relDstRect.format),0);
+#else
+ NormalRgaSetSrcVirtualInfo(&rgaReg, (unsigned int)srcBuf,
+ (unsigned int)srcBuf + srcVirW * srcVirH,
+ (unsigned int)srcBuf + srcVirW * srcVirH * 5/4,
+ srcVirW, srcVirH,
+ RkRgaGetRgaFormat(relSrcRect.format),0);
+ /*dst*/
+ NormalRgaSetDstVirtualInfo(&rgaReg, (unsigned int)dstBuf,
+ (unsigned int)dstBuf + dstVirW * dstVirH,
+ (unsigned int)dstBuf + dstVirW * dstVirH * 5/4,
+ dstVirW, dstVirH, &clip,
+ RkRgaGetRgaFormat(relDstRect.format),0);
+#endif
+ } else if (ctx->mVersion < 2.0) {
+ /*Src*/
+ if (srcFd != -1) {
+ srcMmuFlag = srcType ? 1 : 0;
+ if (src && srcFd == src->fd)
+ srcMmuFlag = src->mmuFlag ? 1 : 0;
+ NormalRgaSetSrcVirtualInfo(&rgaReg, 0, 0, 0, srcVirW, srcVirH,
+ RkRgaGetRgaFormat(relSrcRect.format),0);
+ NormalRgaSetFdsOffsets(&rgaReg, srcFd, 0, 0, 0);
+ } else {
+ if (src && src->hnd)
+ srcMmuFlag = srcType ? 1 : 0;
+ if (src && srcBuf == src->virAddr)
+ srcMmuFlag = 1;
+ if (src && srcBuf == src->phyAddr)
+ srcMmuFlag = 0;
+#if defined(__arm64__) || defined(__aarch64__)
+ NormalRgaSetSrcVirtualInfo(&rgaReg, (unsigned long)srcBuf,
+ (unsigned long)srcBuf + srcVirW * srcVirH,
+ (unsigned long)srcBuf + srcVirW * srcVirH * 5/4,
+ srcVirW, srcVirH,
+ RkRgaGetRgaFormat(relSrcRect.format),0);
+#else
+ NormalRgaSetSrcVirtualInfo(&rgaReg, (unsigned int)srcBuf,
+ (unsigned int)srcBuf + srcVirW * srcVirH,
+ (unsigned int)srcBuf + srcVirW * srcVirH * 5/4,
+ srcVirW, srcVirH,
+ RkRgaGetRgaFormat(relSrcRect.format),0);
+#endif
+ }
+ /*dst*/
+ if (dstFd != -1) {
+ dstMmuFlag = dstType ? 1 : 0;
+ if (dst && dstFd == dst->fd)
+ dstMmuFlag = dst->mmuFlag ? 1 : 0;
+ NormalRgaSetDstVirtualInfo(&rgaReg, 0, 0, 0, dstVirW, dstVirH, &clip,
+ RkRgaGetRgaFormat(relDstRect.format),0);
+ /*src dst fd*/
+ NormalRgaSetFdsOffsets(&rgaReg, 0, dstFd, 0, 0);
+ } else {
+ if (dst && dst->hnd)
+ dstMmuFlag = dstType ? 1 : 0;
+ if (dst && dstBuf == dst->virAddr)
+ dstMmuFlag = 1;
+ if (dst && dstBuf == dst->phyAddr)
+ dstMmuFlag = 0;
+#if defined(__arm64__) || defined(__aarch64__)
+ NormalRgaSetDstVirtualInfo(&rgaReg, (unsigned long)dstBuf,
+ (unsigned long)dstBuf + dstVirW * dstVirH,
+ (unsigned long)dstBuf + dstVirW * dstVirH * 5/4,
+ dstVirW, dstVirH, &clip,
+ RkRgaGetRgaFormat(relDstRect.format),0);
+#else
+ NormalRgaSetDstVirtualInfo(&rgaReg, (unsigned int)dstBuf,
+ (unsigned int)dstBuf + dstVirW * dstVirH,
+ (unsigned int)dstBuf + dstVirW * dstVirH * 5/4,
+ dstVirW, dstVirH, &clip,
+ RkRgaGetRgaFormat(relDstRect.format),0);
+#endif
+ }
+ } else {
+ if (src && src->hnd)
+ srcMmuFlag = srcType ? 1 : 0;
+ if (src && srcBuf == src->virAddr)
+ srcMmuFlag = 1;
+ if (src && srcBuf == src->phyAddr)
+ srcMmuFlag = 0;
+ if (srcFd != -1)
+ srcMmuFlag = srcType ? 1 : 0;
+ if (src && srcFd == src->fd)
+ srcMmuFlag = src->mmuFlag ? 1 : 0;
+
+ if (dst && dst->hnd)
+ dstMmuFlag = dstType ? 1 : 0;
+ if (dst && dstBuf == dst->virAddr)
+ dstMmuFlag = 1;
+ if (dst && dstBuf == dst->phyAddr)
+ dstMmuFlag = 0;
+ if (dstFd != -1)
+ dstMmuFlag = dstType ? 1 : 0;
+ if (dst && dstFd == dst->fd)
+ dstMmuFlag = dst->mmuFlag ? 1 : 0;
+#if defined(__arm64__) || defined(__aarch64__)
+ NormalRgaSetSrcVirtualInfo(&rgaReg, srcFd != -1 ? srcFd : 0,
+ (unsigned long)srcBuf,
+ (unsigned long)srcBuf + srcVirW * srcVirH,
+ srcVirW, srcVirH,
+ RkRgaGetRgaFormat(relSrcRect.format),0);
+ /*dst*/
+ NormalRgaSetDstVirtualInfo(&rgaReg, dstFd != -1 ? dstFd : 0,
+ (unsigned long)dstBuf,
+ (unsigned long)dstBuf + dstVirW * dstVirH,
+ dstVirW, dstVirH, &clip,
+ RkRgaGetRgaFormat(relDstRect.format),0);
+#else
+ NormalRgaSetSrcVirtualInfo(&rgaReg, srcFd != -1 ? srcFd : 0,
+ (unsigned int)srcBuf,
+ (unsigned int)srcBuf + srcVirW * srcVirH,
+ srcVirW, srcVirH,
+ RkRgaGetRgaFormat(relSrcRect.format),0);
+ /*dst*/
+ NormalRgaSetDstVirtualInfo(&rgaReg, dstFd != -1 ? dstFd : 0,
+ (unsigned int)dstBuf,
+ (unsigned int)dstBuf + dstVirW * dstVirH,
+ dstVirW, dstVirH, &clip,
+ RkRgaGetRgaFormat(relDstRect.format),0);
+#endif
+ }
+
+ NormalRgaSetSrcActiveInfo(&rgaReg, srcActW, srcActH, srcXPos, srcYPos);
+ NormalRgaSetDstActiveInfo(&rgaReg, dstActW, dstActH, dstXPos, dstYPos);
+
+ if (NormalRgaIsYuvFormat(RkRgaGetRgaFormat(relSrcRect.format)) &&
+ NormalRgaIsRgbFormat(RkRgaGetRgaFormat(relDstRect.format)))
+ yuvToRgbMode |= 0x1 << 0;
+
+ if (NormalRgaIsRgbFormat(RkRgaGetRgaFormat(relSrcRect.format)) &&
+ NormalRgaIsYuvFormat(RkRgaGetRgaFormat(relDstRect.format)))
+ yuvToRgbMode |= 0x1 << 4;
+
+ /*mode*/
+ NormalRgaSetBitbltMode(&rgaReg, scaleMode, rotateMode, orientation,
+ ditherEn, 0, yuvToRgbMode);
+
+ if (srcMmuFlag || dstMmuFlag) {
+ NormalRgaMmuInfo(&rgaReg, 1, 0, 0, 0, 0, 2);
+ NormalRgaMmuFlag(&rgaReg, srcMmuFlag, dstMmuFlag);
+ }
+
+ ALOGD("%d,%d,%d", srcMmuFlag, dstMmuFlag,rotateMode);
+ NormalRgaLogOutRgaReq(rgaReg);
+
+ if(ioctl(ctx->rgaFd, RGA_BLIT_SYNC, &rgaReg)) {
+ printf(" %s(%d) RGA_BLIT fail: %s",__FUNCTION__, __LINE__,strerror(errno));
+ ALOGE(" %s(%d) RGA_BLIT fail: %s",__FUNCTION__, __LINE__,strerror(errno));
+ }
+
+ return 0;
+}
+
+int RgaCollorFill(rga_info *dst)
+{
+ //check rects
+ //check buffer_handle_t with rects
+ struct rgaContext *ctx = rgaCtx;
+ int dstVirW,dstVirH,dstActW,dstActH,dstXPos,dstYPos;
+ int scaleMode,ditherEn;
+ int dstType,dstMmuFlag;
+ int dstFd = -1;
+ int ret = 0;
+ unsigned int color = 0x00000000;
+ rga_rect_t relDstRect,tmpDstRect;
+ struct rga_req rgaReg;
+ COLOR_FILL fillColor ;
+ void *dstBuf = NULL;
+ RECT clip;
+
+ if (!ctx) {
+ ALOGE("Try to use uninit rgaCtx=%p",ctx);
+ return -ENODEV;
+ }
+
+ memset(&rgaReg, 0, sizeof(struct rga_req));
+
+ dstType = dstMmuFlag = 0;
+
+ if (!dst) {
+ ALOGE("src = %p, dst = %p", dst, dst);
+ return -EINVAL;
+ }
+
+ if (dst) {
+ color = dst->color;
+ memcpy(&relDstRect, &dst->rect, sizeof(rga_rect_t));
+ }
+
+ dstFd = -1;
+
+ if (relDstRect.hstride == 0)
+ relDstRect.hstride = relDstRect.height;
+
+ if (dst && dst->hnd) {
+ ret = RkRgaGetHandleFd(dst->hnd, &dstFd);
+ if (ret) {
+ ALOGE("dst handle get fd fail ret = %d,hnd=%p", ret, &dst->hnd);
+ printf("-dst handle get fd fail ret = %d,hnd=%p", ret, &dst->hnd);
+ return ret;
+ }
+ if (!isRectValid(relDstRect)) {
+ ret = NormalRgaGetRect(dst->hnd, &tmpDstRect);
+ if (ret)
+ return ret;
+ memcpy(&relDstRect, &tmpDstRect, sizeof(rga_rect_t));
+ }
+ NormalRgaGetMmuType(dst->hnd, &dstType);
+ }
+
+
+ if (dst && dstFd < 0)
+ dstFd = dst->fd;
+
+ if (dst && dst->phyAddr)
+ dstBuf = dst->phyAddr;
+ else if (dst && dst->virAddr)
+ dstBuf = dst->virAddr;
+ else if (dst && dst->hnd)
+ ret = RkRgaGetHandleMapAddress(dst->hnd, &dstBuf);
+
+ if (dst && dstFd == -1 && !dstBuf) {
+ ALOGE("%d:dst has not fd and address for render", __LINE__);
+ return ret;
+ }
+
+ if (dst && dstFd == 0 && !dstBuf) {
+ ALOGE("dstFd is zero, now driver not support");
+ return -EINVAL;
+ }
+
+ if (dstFd == 0)
+ dstFd = -1;
+
+ if (relDstRect.hstride == 0)
+ relDstRect.hstride = relDstRect.height;
+
+ dstVirW = relDstRect.wstride;
+ dstVirH = relDstRect.hstride;
+ dstXPos = relDstRect.xoffset;
+ dstYPos = relDstRect.yoffset;
+ dstActW = relDstRect.width;
+ dstActH = relDstRect.height;
+
+ clip.xmin = 0;
+ clip.xmax = dstActW - 1;
+ clip.ymin = 0;
+ clip.ymax = dstActH - 1;
+
+ if (ctx->mVersion <= 1.003) {
+#if defined(__arm64__) || defined(__aarch64__)
+ /*dst*/
+ NormalRgaSetDstVirtualInfo(&rgaReg, (unsigned long)dstBuf,
+ (unsigned long)dstBuf + dstVirW * dstVirH,
+ (unsigned long)dstBuf + dstVirW * dstVirH * 5/4,
+ dstVirW, dstVirH, &clip,
+ RkRgaGetRgaFormat(relDstRect.format),0);
+#else
+ /*dst*/
+ NormalRgaSetDstVirtualInfo(&rgaReg, (unsigned int)dstBuf,
+ (unsigned int)dstBuf + dstVirW * dstVirH,
+ (unsigned int)dstBuf + dstVirW * dstVirH * 5/4,
+ dstVirW, dstVirH, &clip,
+ RkRgaGetRgaFormat(relDstRect.format),0);
+#endif
+ } else if (ctx->mVersion < 2.0) {
+ /*dst*/
+ if (dstFd != -1) {
+ dstMmuFlag = dstType ? 1 : 0;
+ if (dst && dstFd == dst->fd)
+ dstMmuFlag = dst->mmuFlag ? 1 : 0;
+ NormalRgaSetDstVirtualInfo(&rgaReg, 0, 0, 0, dstVirW, dstVirH, &clip,
+ RkRgaGetRgaFormat(relDstRect.format),0);
+ /*src dst fd*/
+ NormalRgaSetFdsOffsets(&rgaReg, 0, dstFd, 0, 0);
+ } else {
+ if (dst && dst->hnd)
+ dstMmuFlag = dstType ? 1 : 0;
+ if (dst && dstBuf == dst->virAddr)
+ dstMmuFlag = 1;
+ if (dst && dstBuf == dst->phyAddr)
+ dstMmuFlag = 0;
+#if defined(__arm64__) || defined(__aarch64__)
+ NormalRgaSetDstVirtualInfo(&rgaReg, (unsigned long)dstBuf,
+ (unsigned long)dstBuf + dstVirW * dstVirH,
+ (unsigned long)dstBuf + dstVirW * dstVirH * 5/4,
+ dstVirW, dstVirH, &clip,
+ RkRgaGetRgaFormat(relDstRect.format),0);
+#else
+ NormalRgaSetDstVirtualInfo(&rgaReg, (unsigned int)dstBuf,
+ (unsigned int)dstBuf + dstVirW * dstVirH,
+ (unsigned int)dstBuf + dstVirW * dstVirH * 5/4,
+ dstVirW, dstVirH, &clip,
+ RkRgaGetRgaFormat(relDstRect.format),0);
+#endif
+ }
+ } else {
+ if (dst && dst->hnd)
+ dstMmuFlag = dstType ? 1 : 0;
+ if (dst && dstBuf == dst->virAddr)
+ dstMmuFlag = 1;
+ if (dst && dstBuf == dst->phyAddr)
+ dstMmuFlag = 0;
+ if (dstFd != -1)
+ dstMmuFlag = dstType ? 1 : 0;
+ if (dst && dstFd == dst->fd)
+ dstMmuFlag = dst->mmuFlag ? 1 : 0;
+#if defined(__arm64__) || defined(__aarch64__)
+ /*dst*/
+ NormalRgaSetDstVirtualInfo(&rgaReg, dstFd != -1 ? dstFd : 0,
+ (unsigned long)dstBuf,
+ (unsigned long)dstBuf + dstVirW * dstVirH,
+ dstVirW, dstVirH, &clip,
+ RkRgaGetRgaFormat(relDstRect.format),0);
+#else
+ /*dst*/
+ NormalRgaSetDstVirtualInfo(&rgaReg, dstFd != -1 ? dstFd : 0,
+ (unsigned int)dstBuf,
+ (unsigned int)dstBuf + dstVirW * dstVirH,
+ dstVirW, dstVirH, &clip,
+ RkRgaGetRgaFormat(relDstRect.format),0);
+#endif
+ }
+
+ NormalRgaSetDstActiveInfo(&rgaReg, dstActW, dstActH, dstXPos, dstYPos);
+
+ memset(&fillColor , 0x0, sizeof(COLOR_FILL));
+
+ /*mode*/
+ NormalRgaSetColorFillMode(&rgaReg, &fillColor, 0, 0, color, 0, 0, 0, 0, 0);
+
+ if (dstMmuFlag) {
+ NormalRgaMmuInfo(&rgaReg, 1, 0, 0, 0, 0, 2);
+ NormalRgaMmuFlag(&rgaReg, dstMmuFlag, dstMmuFlag);
+ }
+
+ //ALOGD("%d,%d,%d", srcMmuFlag, dstMmuFlag,rotateMode);
+ //NormalRgaLogOutRgaReq(rgaReg);
+
+ if(ioctl(ctx->rgaFd, RGA_BLIT_SYNC, &rgaReg)) {
+ printf(" %s(%d) RGA_BLIT fail: %s",__FUNCTION__, __LINE__,strerror(errno));
+ ALOGE(" %s(%d) RGA_BLIT fail: %s",__FUNCTION__, __LINE__,strerror(errno));
+ }
+
+ return 0;
+}
+
+int RgaBlit(buffer_handle_t src,
+ buffer_handle_t dst, drm_rga_t *rects, int rotation, int blend)
+{
+
+ //check rects
+ //check buffer_handle_t with rects
+ struct rgaContext *ctx = rgaCtx;
+ int srcVirW,srcVirH,srcActW,srcActH,srcXPos,srcYPos;
+ int dstVirW,dstVirH,dstActW,dstActH,dstXPos,dstYPos;
+ int scaleMode,rotateMode,orientation,ditherEn;
+ int srcType,dstType,srcMmuFlag,dstMmuFlag;
+ int planeAlpha;
+ int dstFd = -1;
+ int srcFd = -1;
+ int ret = 0;
+ drm_rga_t tmpRects,relRects;
+ struct rga_req rgaReg;
+ bool perpixelAlpha;
+ void *srcBuf = NULL;
+ void *dstBuf = NULL;
+ RECT clip;
+
+ if (!ctx) {
+ ALOGE("Try to use uninit rgaCtx=%p",ctx);
+ return -ENODEV;
+ }
+
+ if (rects && (ctx->mLogAlways || ctx->mLogOnce)) {
+ ALOGD("Src:[%d,%d,%d,%d][%d,%d,%d]=>Dst:[%d,%d,%d,%d][%d,%d,%d]",
+ rects->src.xoffset,rects->src.yoffset,
+ rects->src.width, rects->src.height,
+ rects->src.wstride,rects->src.format, rects->src.size,
+ rects->dst.xoffset,rects->dst.yoffset,
+ rects->dst.width, rects->dst.height,
+ rects->dst.wstride,rects->dst.format, rects->dst.size);
+ }
+
+ memset(&rgaReg, 0, sizeof(struct rga_req));
+
+ srcType = dstType = srcMmuFlag = dstMmuFlag = 0;
+
+ ret = NormalRgaGetRects(src, dst, &srcType, &dstType, &tmpRects);
+ if (ret && !rects) {
+ ALOGE("%d:Has not rects for render", __LINE__);
+ return ret;
+ }
+
+ if (rects) {
+ if (rects->src.wstride > 0 && rects->dst.wstride > 0)
+ memcpy(&relRects, rects, sizeof(drm_rga_t));
+ else if (rects->src.wstride > 0) {
+ memcpy(&(relRects.src), &(rects->src), sizeof(rga_rect_t));
+ memcpy(&(relRects.dst), &(tmpRects.dst), sizeof(rga_rect_t));
+ } else if (rects->dst.wstride > 0) {
+ memcpy(&(relRects.src), &(tmpRects.src), sizeof(rga_rect_t));
+ memcpy(&(relRects.dst), &(rects->dst), sizeof(rga_rect_t));
+ }
+ } else
+ memcpy(&relRects, &tmpRects, sizeof(drm_rga_t));
+
+ if (ctx->mLogAlways || ctx->mLogOnce) {
+ ALOGD("Src:[%d,%d,%d,%d][%d,%d,%d]=>Dst:[%d,%d,%d,%d][%d,%d,%d]",
+ tmpRects.src.xoffset,tmpRects.src.yoffset,
+ tmpRects.src.width, tmpRects.src.height,
+ tmpRects.src.wstride,tmpRects.src.format, tmpRects.src.size,
+ tmpRects.dst.xoffset,tmpRects.dst.yoffset,
+ tmpRects.dst.width, tmpRects.dst.height,
+ tmpRects.dst.wstride,tmpRects.dst.format, tmpRects.dst.size);
+ ALOGD("Src:[%d,%d,%d,%d][%d,%d,%d]=>Dst:[%d,%d,%d,%d][%d,%d,%d]",
+ relRects.src.xoffset,relRects.src.yoffset,
+ relRects.src.width, relRects.src.height,
+ relRects.src.wstride,relRects.src.format, relRects.src.size,
+ relRects.dst.xoffset,relRects.dst.yoffset,
+ relRects.dst.width, relRects.dst.height,
+ relRects.dst.wstride,relRects.dst.format, relRects.dst.size);
+ }
+
+ RkRgaGetHandleMapAddress(src, &srcBuf);
+ RkRgaGetHandleFd(src, &srcFd);
+ if (srcFd == -1 && !srcBuf) {
+ ALOGE("%d:src has not fd and address for render", __LINE__);
+ return ret;
+ }
+
+ if (srcFd == 0 && !srcBuf) {
+ ALOGE("srcFd is zero, now driver not support");
+ return -EINVAL;
+ } else
+ srcFd = -1;
+
+ RkRgaGetHandleMapAddress(dst, &dstBuf);
+ RkRgaGetHandleFd(dst, &dstFd);
+ if (dstFd == -1 && !dstBuf) {
+ ALOGE("%d:dst has not fd and address for render", __LINE__);
+ return ret;
+ }
+
+ if (dstFd == 0 && !dstBuf) {
+ ALOGE("dstFd is zero, now driver not support");
+ return -EINVAL;
+ } else
+ dstFd = -1;
+
+ planeAlpha = (blend & 0xFF0000) >> 16;
+ perpixelAlpha = relRects.src.format == HAL_PIXEL_FORMAT_RGBA_8888 ||
+ relRects.src.format == HAL_PIXEL_FORMAT_BGRA_8888;
+
+ switch ((blend & 0xFFFF)) {
+ case 0x0105:
+ if (perpixelAlpha && planeAlpha < 255)
+ NormalRgaSetAlphaEnInfo(&rgaReg, 1, 2, planeAlpha , 1, 9, 0);
+ else if (perpixelAlpha)
+ NormalRgaSetAlphaEnInfo(&rgaReg, 1, 1, 0, 1, 3, 0);
+ else
+ NormalRgaSetAlphaEnInfo(&rgaReg, 1, 0, planeAlpha , 0, 0, 0);
+ break;
+
+ case 0x0405:
+ if (perpixelAlpha && planeAlpha < 255)
+ NormalRgaSetAlphaEnInfo(&rgaReg, 1, 2, planeAlpha , 0, 0, 0);
+ else if (perpixelAlpha)
+ NormalRgaSetAlphaEnInfo(&rgaReg, 1, 1, 0, 0, 0, 0);
+ else
+ NormalRgaSetAlphaEnInfo(&rgaReg, 1, 0, planeAlpha , 0, 0, 0);
+ break;
+
+ case 0x0100:
+ default:
+ /* Tips: BLENDING_NONE is non-zero value, handle zero value as
+ * BLENDING_NONE. */
+ /* C = Cs
+ * A = As */
+ break;
+ }
+
+ switch (rotation) {
+ case HAL_TRANSFORM_FLIP_H:
+ orientation = 0;
+ rotateMode = 2;
+ srcVirW = relRects.src.wstride;
+ srcVirH = relRects.src.height;
+ srcXPos = relRects.src.xoffset;
+ srcYPos = relRects.src.yoffset;
+ srcActW = relRects.src.width;
+ srcActH = relRects.src.height;
+
+ dstVirW = relRects.dst.wstride;
+ dstVirH = relRects.dst.height;
+ dstXPos = relRects.dst.xoffset;
+ dstYPos = relRects.dst.yoffset;
+ dstActW = relRects.dst.width;
+ dstActH = relRects.dst.height;
+ break;
+ case HAL_TRANSFORM_FLIP_V:
+ orientation = 0;
+ rotateMode = 3;
+ srcVirW = relRects.src.wstride;
+ srcVirH = relRects.src.height;
+ srcXPos = relRects.src.xoffset;
+ srcYPos = relRects.src.yoffset;
+ srcActW = relRects.src.width;
+ srcActH = relRects.src.height;
+
+ dstVirW = relRects.dst.wstride;
+ dstVirH = relRects.dst.height;
+ dstXPos = relRects.dst.xoffset;
+ dstYPos = relRects.dst.yoffset;
+ dstActW = relRects.dst.width;
+ dstActH = relRects.dst.height;
+ break;
+ case HAL_TRANSFORM_ROT_90:
+ orientation = 90;
+ rotateMode = 1;
+ srcVirW = relRects.src.wstride;
+ srcVirH = relRects.src.height;
+ srcXPos = relRects.src.xoffset;
+ srcYPos = relRects.src.yoffset;
+ srcActW = relRects.src.width;
+ srcActH = relRects.src.height;
+
+ dstVirW = relRects.dst.wstride;
+ dstVirH = relRects.dst.height;
+ dstXPos = relRects.dst.width - 1;
+ //dstYPos = relRects.dst.yoffset;
+ dstYPos = 0;
+ dstActW = relRects.dst.height;
+ dstActH = relRects.dst.width;
+ break;
+ case HAL_TRANSFORM_ROT_180:
+ orientation = 180;
+ rotateMode = 1;
+ srcVirW = relRects.src.wstride;
+ srcVirH = relRects.src.height;
+ srcXPos = relRects.src.xoffset;
+ srcYPos = relRects.src.yoffset;
+ srcActW = relRects.src.width;
+ srcActH = relRects.src.height;
+
+ dstVirW = relRects.dst.wstride;
+ dstVirH = relRects.dst.height;
+ dstXPos = relRects.dst.width - 1;
+ dstYPos = relRects.dst.height - 1;
+ dstActW = relRects.dst.width;
+ dstActH = relRects.dst.height;
+ break;
+ case HAL_TRANSFORM_ROT_270:
+ orientation = 270;
+ rotateMode = 1;
+ srcVirW = relRects.src.wstride;
+ srcVirH = relRects.src.height;
+ srcXPos = relRects.src.xoffset;
+ srcYPos = relRects.src.yoffset;
+ srcActW = relRects.src.width;
+ srcActH = relRects.src.height;
+
+ dstVirW = relRects.dst.wstride;
+ dstVirH = relRects.dst.height;
+ //dstXPos = relRects.dst.xoffset;
+ dstXPos = 0;
+ dstYPos = relRects.dst.height - 1;
+ dstActW = relRects.dst.height;
+ dstActH = relRects.dst.width;
+ break;
+ default:
+ orientation = 0;
+ rotateMode = 0;
+ srcVirW = relRects.src.wstride;
+ srcVirH = relRects.src.height;
+ srcXPos = relRects.src.xoffset;
+ srcYPos = relRects.src.yoffset;
+ srcActW = relRects.src.width;
+ srcActH = relRects.src.height;
+
+ dstVirW = relRects.dst.wstride;
+ dstVirH = relRects.dst.height;
+ dstXPos = relRects.dst.xoffset;
+ dstYPos = relRects.dst.yoffset;
+ dstActW = relRects.dst.width;
+ dstActH = relRects.dst.height;
+ break;
+ }
+
+ clip.xmin = 0;
+ clip.xmax = dstActW - 1;
+ clip.ymin = 0;
+ clip.ymax = dstActH - 1;
+
+ scaleMode = 0;
+ //scale up use bicubic
+ if (srcActW / dstActW < 1 || srcActH / dstActH < 1)
+ scaleMode = 2;
+
+ /*
+ if (scaleMode && (srcFormat == RK_FORMAT_RGBA_8888 ||
+ srcFormat == RK_FORMAT_BGRA_8888)) {
+ scale_mode = 0; // force change scale_mode to 0 ,for rga not support
+ }*/
+
+ ditherEn = (android::bytesPerPixel(relRects.src.format)
+ != android::bytesPerPixel(relRects.src.format) ? 1 : 0);
+
+ if (ctx->mVersion <= 1.003) {
+ srcMmuFlag = dstMmuFlag = 1;
+
+#if defined(__arm64__) || defined(__aarch64__)
+ NormalRgaSetSrcVirtualInfo(&rgaReg, (unsigned long)srcBuf,
+ (unsigned long)srcBuf + srcVirW * srcVirH,
+ (unsigned long)srcBuf + srcVirW * srcVirH * 5/4,
+ srcVirW, srcVirH,
+ RkRgaGetRgaFormat(relRects.src.format),0);
+ /*dst*/
+ NormalRgaSetDstVirtualInfo(&rgaReg, (unsigned long)dstBuf,
+ (unsigned long)dstBuf + dstVirW * dstVirH,
+ (unsigned long)dstBuf + dstVirW * dstVirH * 5/4,
+ dstVirW, dstVirH, &clip,
+ RkRgaGetRgaFormat(relRects.dst.format),0);
+#else
+ NormalRgaSetSrcVirtualInfo(&rgaReg, (unsigned int)srcBuf,
+ (unsigned int)srcBuf + srcVirW * srcVirH,
+ (unsigned int)srcBuf + srcVirW * srcVirH * 5/4,
+ srcVirW, srcVirH,
+ RkRgaGetRgaFormat(relRects.src.format),0);
+ /*dst*/
+ NormalRgaSetDstVirtualInfo(&rgaReg, (unsigned int)dstBuf,
+ (unsigned int)dstBuf + dstVirW * dstVirH,
+ (unsigned int)dstBuf + dstVirW * dstVirH * 5/4,
+ dstVirW, dstVirH, &clip,
+ RkRgaGetRgaFormat(relRects.dst.format),0);
+#endif
+ } else if (ctx->mVersion < 2.0) {
+ /*Src*/
+ if (srcFd != -1) {
+ srcMmuFlag = srcType ? 1 : 0;
+ NormalRgaSetSrcVirtualInfo(&rgaReg, 0, 0, 0, srcVirW, srcVirH,
+ RkRgaGetRgaFormat(relRects.src.format),0);
+ NormalRgaSetFdsOffsets(&rgaReg, srcFd, 0, 0, 0);
+ } else {
+ srcMmuFlag = 1;
+
+#if defined(__arm64__) || defined(__aarch64__)
+ NormalRgaSetSrcVirtualInfo(&rgaReg, (unsigned long)srcBuf,
+ (unsigned long)srcBuf + srcVirW * srcVirH,
+ (unsigned long)srcBuf + srcVirW * srcVirH * 5/4,
+ srcVirW, srcVirH,
+ RkRgaGetRgaFormat(relRects.src.format),0);
+#else
+ NormalRgaSetSrcVirtualInfo(&rgaReg, (unsigned int)srcBuf,
+ (unsigned int)srcBuf + srcVirW * srcVirH,
+ (unsigned int)srcBuf + srcVirW * srcVirH * 5/4,
+ srcVirW, srcVirH,
+ RkRgaGetRgaFormat(relRects.src.format),0);
+#endif
+ }
+ /*dst*/
+ if (dstFd != -1) {
+ dstMmuFlag = srcType ? 1 : 0;
+ NormalRgaSetDstVirtualInfo(&rgaReg, 0, 0, 0, dstVirW, dstVirH, &clip,
+ RkRgaGetRgaFormat(relRects.dst.format),0);
+ /*src dst fd*/
+ NormalRgaSetFdsOffsets(&rgaReg, 0, dstFd, 0, 0);
+ } else {
+ dstMmuFlag = 1;
+#if defined(__arm64__) || defined(__aarch64__)
+ NormalRgaSetDstVirtualInfo(&rgaReg, (unsigned long)dstBuf,
+ (unsigned long)dstBuf + dstVirW * dstVirH,
+ (unsigned long)dstBuf + dstVirW * dstVirH * 5/4,
+ dstVirW, dstVirH, &clip,
+ RkRgaGetRgaFormat(relRects.dst.format),0);
+#else
+ NormalRgaSetDstVirtualInfo(&rgaReg, (unsigned int)dstBuf,
+ (unsigned int)dstBuf + dstVirW * dstVirH,
+ (unsigned int)dstBuf + dstVirW * dstVirH * 5/4,
+ dstVirW, dstVirH, &clip,
+ RkRgaGetRgaFormat(relRects.dst.format),0);
+#endif
+ }
+ } else {
+ srcMmuFlag = ((srcFd != -1 && srcType) || srcFd == -1) ? 1 : 0;
+ dstMmuFlag = ((dstFd != -1 && dstType) || dstFd == -1) ? 1 : 0;
+#if defined(__arm64__) || defined(__aarch64__)
+ NormalRgaSetSrcVirtualInfo(&rgaReg, srcFd != -1 ? srcFd : 0,
+ (unsigned long)srcBuf,
+ (unsigned long)srcBuf + srcVirW * srcVirH,
+ srcVirW, srcVirH,
+ RkRgaGetRgaFormat(relRects.src.format),0);
+ /*dst*/
+ NormalRgaSetDstVirtualInfo(&rgaReg, dstFd != -1 ? dstFd : 0,
+ (unsigned long)dstBuf,
+ (unsigned long)dstBuf + dstVirW * dstVirH,
+ dstVirW, dstVirH, &clip,
+ RkRgaGetRgaFormat(relRects.dst.format),0);
+#else
+ NormalRgaSetSrcVirtualInfo(&rgaReg, srcFd != -1 ? srcFd : 0,
+ (unsigned int)srcBuf,
+ (unsigned int)srcBuf + srcVirW * srcVirH,
+ srcVirW, srcVirH,
+ RkRgaGetRgaFormat(relRects.src.format),0);
+ /*dst*/
+ NormalRgaSetDstVirtualInfo(&rgaReg, dstFd != -1 ? dstFd : 0,
+ (unsigned int)dstBuf,
+ (unsigned int)dstBuf + dstVirW * dstVirH,
+ dstVirW, dstVirH, &clip,
+ RkRgaGetRgaFormat(relRects.dst.format),0);
+#endif
+ }
+
+ NormalRgaSetSrcActiveInfo(&rgaReg, srcActW, srcActH, srcXPos, srcYPos);
+ NormalRgaSetDstActiveInfo(&rgaReg, dstActW, dstActH, dstXPos, dstYPos);
+
+ /*mode*/
+ NormalRgaSetBitbltMode(&rgaReg, scaleMode, rotateMode, orientation, ditherEn, 0, 0);
+
+ if (srcMmuFlag || dstMmuFlag) {
+ NormalRgaMmuInfo(&rgaReg, 1, 0, 0, 0, 0, 2);
+ NormalRgaMmuFlag(&rgaReg, srcMmuFlag, dstMmuFlag);
+ }
+
+ if(ioctl(ctx->rgaFd, RGA_BLIT_SYNC, &rgaReg)) {
+ printf(" %s(%d) RGA_BLIT fail: %s",__FUNCTION__, __LINE__,strerror(errno));
+ ALOGE(" %s(%d) RGA_BLIT fail: %s",__FUNCTION__, __LINE__,strerror(errno));
+ }
+
+ if (ctx->mLogOnce)
+ ctx->mLogOnce = 0;
+
+ return 0;
+}
+
+int RgaBlit(void *src,
+ buffer_handle_t dst, drm_rga_t *rects, int rotation, int blend)
+{
+ //check rects
+ //check buffer_handle_t with rects
+ struct rgaContext *ctx = rgaCtx;
+ int srcVirW,srcVirH,srcActW,srcActH,srcXPos,srcYPos;
+ int dstVirW,dstVirH,dstActW,dstActH,dstXPos,dstYPos;
+ int scaleMode,rotateMode,orientation,ditherEn;
+ int srcType,dstType,srcMmuFlag,dstMmuFlag;
+ int planeAlpha;
+ int dstFd = -1;
+ int srcFd = -1;
+ int ret = 0;
+ drm_rga_t tmpRects,relRects;
+ struct rga_req rgaReg;
+ bool perpixelAlpha;
+ void *srcBuf = NULL;
+ void *dstBuf = NULL;
+ RECT clip;
+
+ if (!ctx) {
+ ALOGE("Try to use uninit rgaCtx=%p",ctx);
+ return -ENODEV;
+ }
+
+ memset(&rgaReg, 0, sizeof(struct rga_req));
+
+ srcType = dstType = srcMmuFlag = dstMmuFlag = 0;
+
+ if (!rects) {
+ ALOGE("%d:Has not user rects for render", __LINE__);
+ return ret;
+ }
+
+ if (rects->src.wstride <= 0) {
+ ALOGE("%d:Has invalid rects for render", __LINE__);
+ return -EINVAL;
+ }
+
+ ret = NormalRgaGetRects(NULL, dst, &srcType, &dstType, &tmpRects);
+ if (ret) {
+ ALOGE("%d:Has not rects for render", __LINE__);
+ return ret;
+ }
+
+ if (rects->dst.wstride > 0)
+ memcpy(&relRects, rects, sizeof(drm_rga_t));
+ else {
+ memcpy(&(relRects.src), &(rects->src), sizeof(rga_rect_t));
+ memcpy(&(relRects.dst), &(tmpRects.dst), sizeof(rga_rect_t));
+ }
+
+ srcBuf = src;
+ if (!srcBuf) {
+ ALOGE("%d:src has not fd and address for render", __LINE__);
+ return ret;
+ }
+
+ RkRgaGetHandleMapAddress(dst, &dstBuf);
+ RkRgaGetHandleFd(dst, &dstFd);
+ if (dstFd == -1 && !dstBuf) {
+ ALOGE("%d:dst has not fd and address for render", __LINE__);
+ return ret;
+ }
+
+ if (dstFd == 0 && !dstBuf) {
+ ALOGE("dstFd is zero, now driver not support");
+ return -EINVAL;
+ } else
+ dstFd = -1;
+
+ planeAlpha = (blend & 0xFF0000) >> 16;
+ perpixelAlpha = relRects.src.format == HAL_PIXEL_FORMAT_RGBA_8888 ||
+ relRects.src.format == HAL_PIXEL_FORMAT_BGRA_8888;
+
+ switch ((blend & 0xFFFF)) {
+ case 0x0105:
+ if (perpixelAlpha && planeAlpha < 255)
+ NormalRgaSetAlphaEnInfo(&rgaReg, 1, 2, planeAlpha , 1, 9, 0);
+ else if (perpixelAlpha)
+ NormalRgaSetAlphaEnInfo(&rgaReg, 1, 1, 0, 1, 3, 0);
+ else
+ NormalRgaSetAlphaEnInfo(&rgaReg, 1, 0, planeAlpha , 0, 0, 0);
+ break;
+
+ case 0x0405:
+ if (perpixelAlpha && planeAlpha < 255)
+ NormalRgaSetAlphaEnInfo(&rgaReg, 1, 2, planeAlpha , 0, 0, 0);
+ else if (perpixelAlpha)
+ NormalRgaSetAlphaEnInfo(&rgaReg, 1, 1, 0, 0, 0, 0);
+ else
+ NormalRgaSetAlphaEnInfo(&rgaReg, 1, 0, planeAlpha , 0, 0, 0);
+ break;
+
+ case 0x0100:
+ default:
+ /* Tips: BLENDING_NONE is non-zero value, handle zero value as
+ * BLENDING_NONE. */
+ /* C = Cs
+ * A = As */
+ break;
+ }
+
+
+ switch (rotation) {
+ case HAL_TRANSFORM_FLIP_H:
+ orientation = 0;
+ rotateMode = 2;
+ srcVirW = relRects.src.wstride;
+ srcVirH = relRects.src.height;
+ srcXPos = relRects.src.xoffset;
+ srcYPos = relRects.src.yoffset;
+ srcActW = relRects.src.width;
+ srcActH = relRects.src.height;
+
+ dstVirW = relRects.dst.wstride;
+ dstVirH = relRects.dst.height;
+ dstXPos = relRects.dst.xoffset;
+ dstYPos = relRects.dst.yoffset;
+ dstActW = relRects.dst.width;
+ dstActH = relRects.dst.height;
+ break;
+ case HAL_TRANSFORM_FLIP_V:
+ orientation = 0;
+ rotateMode = 3;
+ srcVirW = relRects.src.wstride;
+ srcVirH = relRects.src.height;
+ srcXPos = relRects.src.xoffset;
+ srcYPos = relRects.src.yoffset;
+ srcActW = relRects.src.width;
+ srcActH = relRects.src.height;
+
+ dstVirW = relRects.dst.wstride;
+ dstVirH = relRects.dst.height;
+ dstXPos = relRects.dst.xoffset;
+ dstYPos = relRects.dst.yoffset;
+ dstActW = relRects.dst.width;
+ dstActH = relRects.dst.height;
+ break;
+ case HAL_TRANSFORM_ROT_90:
+ orientation = 90;
+ rotateMode = 1;
+ srcVirW = relRects.src.wstride;
+ srcVirH = relRects.src.height;
+ srcXPos = relRects.src.xoffset;
+ srcYPos = relRects.src.yoffset;
+ srcActW = relRects.src.width;
+ srcActH = relRects.src.height;
+
+ dstVirW = relRects.dst.wstride;
+ dstVirH = relRects.dst.height;
+ dstXPos = relRects.dst.width - 1;
+ //dstYPos = relRects.dst.yoffset;
+ dstYPos = 0;
+ dstActW = relRects.dst.height;
+ dstActH = relRects.dst.width;
+ break;
+ case HAL_TRANSFORM_ROT_180:
+ orientation = 180;
+ rotateMode = 1;
+ srcVirW = relRects.src.wstride;
+ srcVirH = relRects.src.height;
+ srcXPos = relRects.src.xoffset;
+ srcYPos = relRects.src.yoffset;
+ srcActW = relRects.src.width;
+ srcActH = relRects.src.height;
+
+ dstVirW = relRects.dst.wstride;
+ dstVirH = relRects.dst.height;
+ dstXPos = relRects.dst.width - 1;
+ dstYPos = relRects.dst.height - 1;
+ dstActW = relRects.dst.width;
+ dstActH = relRects.dst.height;
+ break;
+ case HAL_TRANSFORM_ROT_270:
+ orientation = 270;
+ rotateMode = 1;
+ srcVirW = relRects.src.wstride;
+ srcVirH = relRects.src.height;
+ srcXPos = relRects.src.xoffset;
+ srcYPos = relRects.src.yoffset;
+ srcActW = relRects.src.width;
+ srcActH = relRects.src.height;
+
+ dstVirW = relRects.dst.wstride;
+ dstVirH = relRects.dst.height;
+ //dstXPos = relRects.dst.xoffset;
+ dstXPos = 0;
+ dstYPos = relRects.dst.height - 1;
+ dstActW = relRects.dst.height;
+ dstActH = relRects.dst.width;
+ break;
+ default:
+ orientation = 0;
+ rotateMode = 0;
+ srcVirW = relRects.src.wstride;
+ srcVirH = relRects.src.height;
+ srcXPos = relRects.src.xoffset;
+ srcYPos = relRects.src.yoffset;
+ srcActW = relRects.src.width;
+ srcActH = relRects.src.height;
+
+ dstVirW = relRects.dst.wstride;
+ dstVirH = relRects.dst.height;
+ dstXPos = relRects.dst.xoffset;
+ dstYPos = relRects.dst.yoffset;
+ dstActW = relRects.dst.width;
+ dstActH = relRects.dst.height;
+ break;
+ }
+
+ clip.xmin = 0;
+ clip.xmax = dstActW - 1;
+ clip.ymin = 0;
+ clip.ymax = dstActH - 1;
+
+ scaleMode = 0;
+ //scale up use bicubic
+ if (srcActW / dstActW < 1 || srcActH / dstActH < 1)
+ scaleMode = 2;
+
+ /*
+ if (scaleMode && (srcFormat == RK_FORMAT_RGBA_8888 ||
+ srcFormat == RK_FORMAT_BGRA_8888)) {
+ scale_mode = 0; // force change scale_mode to 0 ,for rga not support
+ }*/
+
+ ditherEn = (android::bytesPerPixel(relRects.src.format)
+ != android::bytesPerPixel(relRects.src.format) ? 1 : 0);
+
+ if (ctx->mVersion <= 1.003) {
+ srcMmuFlag = dstMmuFlag = 1;
+
+#if defined(__arm64__) || defined(__aarch64__)
+ NormalRgaSetSrcVirtualInfo(&rgaReg, (unsigned long)srcBuf,
+ (unsigned long)srcBuf + srcVirW * srcVirH,
+ (unsigned long)srcBuf + srcVirW * srcVirH * 5/4,
+ srcVirW, srcVirH,
+ RkRgaGetRgaFormat(relRects.src.format),0);
+ /*dst*/
+ NormalRgaSetDstVirtualInfo(&rgaReg, (unsigned long)dstBuf,
+ (unsigned long)dstBuf + dstVirW * dstVirH,
+ (unsigned long)dstBuf + dstVirW * dstVirH * 5/4,
+ dstVirW, dstVirH, &clip,
+ RkRgaGetRgaFormat(relRects.dst.format),0);
+#else
+ NormalRgaSetSrcVirtualInfo(&rgaReg, (unsigned int)srcBuf,
+ (unsigned int)srcBuf + srcVirW * srcVirH,
+ (unsigned int)srcBuf + srcVirW * srcVirH * 5/4,
+ srcVirW, srcVirH,
+ RkRgaGetRgaFormat(relRects.src.format),0);
+ /*dst*/
+ NormalRgaSetDstVirtualInfo(&rgaReg, (unsigned int)dstBuf,
+ (unsigned int)dstBuf + dstVirW * dstVirH,
+ (unsigned int)dstBuf + dstVirW * dstVirH * 5/4,
+ dstVirW, dstVirH, &clip,
+ RkRgaGetRgaFormat(relRects.dst.format),0);
+#endif
+ } else if (ctx->mVersion < 2.0) {
+ /*Src*/
+ if (srcFd != -1) {
+ srcMmuFlag = srcType ? 1 : 0;
+ NormalRgaSetSrcVirtualInfo(&rgaReg, 0, 0, 0, srcVirW, srcVirH,
+ RkRgaGetRgaFormat(relRects.src.format),0);
+ NormalRgaSetFdsOffsets(&rgaReg, srcFd, 0, 0, 0);
+ } else {
+ srcMmuFlag = 1;
+
+#if defined(__arm64__) || defined(__aarch64__)
+ NormalRgaSetSrcVirtualInfo(&rgaReg, (unsigned long)srcBuf,
+ (unsigned long)srcBuf + srcVirW * srcVirH,
+ (unsigned long)srcBuf + srcVirW * srcVirH * 5/4,
+ srcVirW, srcVirH,
+ RkRgaGetRgaFormat(relRects.src.format),0);
+#else
+ NormalRgaSetSrcVirtualInfo(&rgaReg, (unsigned int)srcBuf,
+ (unsigned int)srcBuf + srcVirW * srcVirH,
+ (unsigned int)srcBuf + srcVirW * srcVirH * 5/4,
+ srcVirW, srcVirH,
+ RkRgaGetRgaFormat(relRects.src.format),0);
+#endif
+ }
+ /*dst*/
+ if (dstFd != -1) {
+ dstMmuFlag = srcType ? 1 : 0;
+ NormalRgaSetDstVirtualInfo(&rgaReg, 0, 0, 0, dstVirW, dstVirH, &clip,
+ RkRgaGetRgaFormat(relRects.dst.format),0);
+ /*src dst fd*/
+ NormalRgaSetFdsOffsets(&rgaReg, 0, dstFd, 0, 0);
+ } else {
+ dstMmuFlag = 1;
+#if defined(__arm64__) || defined(__aarch64__)
+ NormalRgaSetDstVirtualInfo(&rgaReg, (unsigned long)dstBuf,
+ (unsigned long)dstBuf + dstVirW * dstVirH,
+ (unsigned long)dstBuf + dstVirW * dstVirH * 5/4,
+ dstVirW, dstVirH, &clip,
+ RkRgaGetRgaFormat(relRects.dst.format),0);
+#else
+ NormalRgaSetDstVirtualInfo(&rgaReg, (unsigned int)dstBuf,
+ (unsigned int)dstBuf + dstVirW * dstVirH,
+ (unsigned int)dstBuf + dstVirW * dstVirH * 5/4,
+ dstVirW, dstVirH, &clip,
+ RkRgaGetRgaFormat(relRects.dst.format),0);
+#endif
+ }
+ } else {
+ srcMmuFlag = ((srcFd != -1 && srcType) || srcFd == -1) ? 1 : 0;
+ dstMmuFlag = ((dstFd != -1 && dstType) || dstFd == -1) ? 1 : 0;
+#if defined(__arm64__) || defined(__aarch64__)
+ NormalRgaSetSrcVirtualInfo(&rgaReg, srcFd != -1 ? srcFd : 0,
+ (unsigned long)srcBuf,
+ (unsigned long)srcBuf + srcVirW * srcVirH,
+ srcVirW, srcVirH,
+ RkRgaGetRgaFormat(relRects.src.format),0);
+ /*dst*/
+ NormalRgaSetDstVirtualInfo(&rgaReg, dstFd != -1 ? dstFd : 0,
+ (unsigned long)dstBuf,
+ (unsigned long)dstBuf + dstVirW * dstVirH,
+ dstVirW, dstVirH, &clip,
+ RkRgaGetRgaFormat(relRects.dst.format),0);
+#else
+ NormalRgaSetSrcVirtualInfo(&rgaReg, srcFd != -1 ? srcFd : 0,
+ (unsigned int)srcBuf,
+ (unsigned int)srcBuf + srcVirW * srcVirH,
+ srcVirW, srcVirH,
+ RkRgaGetRgaFormat(relRects.src.format),0);
+ /*dst*/
+ NormalRgaSetDstVirtualInfo(&rgaReg, dstFd != -1 ? dstFd : 0,
+ (unsigned int)dstBuf,
+ (unsigned int)dstBuf + dstVirW * dstVirH,
+ dstVirW, dstVirH, &clip,
+ RkRgaGetRgaFormat(relRects.dst.format),0);
+#endif
+ }
+
+ NormalRgaSetSrcActiveInfo(&rgaReg, srcActW, srcActH, srcXPos, srcYPos);
+ NormalRgaSetDstActiveInfo(&rgaReg, dstActW, dstActH, dstXPos, dstYPos);
+
+ /*mode*/
+ NormalRgaSetBitbltMode(&rgaReg, scaleMode, rotateMode, orientation, ditherEn, 0, 0);
+
+ if (srcMmuFlag || dstMmuFlag) {
+ NormalRgaMmuInfo(&rgaReg, 1, 0, 0, 0, 0, 2);
+ NormalRgaMmuFlag(&rgaReg, srcMmuFlag, dstMmuFlag);
+ }
+
+ if(ioctl(ctx->rgaFd, RGA_BLIT_SYNC, &rgaReg)) {
+ printf(" %s(%d) RGA_BLIT fail: %s",__FUNCTION__, __LINE__,strerror(errno));
+ ALOGE(" %s(%d) RGA_BLIT fail: %s",__FUNCTION__, __LINE__,strerror(errno));
+ }
+
+ return 0;
+}
+
+int RgaBlit(buffer_handle_t src,
+ void *dst, drm_rga_t *rects, int rotation, int blend)
+{
+ //check rects
+ //check buffer_handle_t with rects
+ struct rgaContext *ctx = rgaCtx;
+ int srcVirW,srcVirH,srcActW,srcActH,srcXPos,srcYPos;
+ int dstVirW,dstVirH,dstActW,dstActH,dstXPos,dstYPos;
+ int scaleMode,rotateMode,orientation,ditherEn;
+ int srcType,dstType,srcMmuFlag,dstMmuFlag;
+ int planeAlpha;
+ int dstFd = -1;
+ int srcFd = -1;
+ int ret = 0;
+ drm_rga_t tmpRects,relRects;
+ struct rga_req rgaReg;
+ bool perpixelAlpha;
+ void *srcBuf = NULL;
+ void *dstBuf = NULL;
+ RECT clip;
+
+ if (!ctx) {
+ ALOGE("Try to use uninit rgaCtx=%p",ctx);
+ return -ENODEV;
+ }
+
+ memset(&rgaReg, 0, sizeof(struct rga_req));
+
+ srcType = dstType = srcMmuFlag = dstMmuFlag = 0;
+
+ if (!rects) {
+ ALOGE("%d:Has not user rects for render", __LINE__);
+ return ret;
+ }
+
+ if (rects->dst.wstride <= 0) {
+ ALOGE("%d:Has invalid rects for render", __LINE__);
+ return -EINVAL;
+ }
+
+ ret = NormalRgaGetRects(src, NULL, &srcType, &dstType, &tmpRects);
+ if (ret) {
+ ALOGE("%d:Has not rects for render", __LINE__);
+ return ret;
+ }
+
+ if (rects->src.wstride > 0)
+ memcpy(&relRects, rects, sizeof(drm_rga_t));
+ else {
+ memcpy(&(relRects.src), &(tmpRects.src), sizeof(rga_rect_t));
+ memcpy(&(relRects.dst), &(rects->dst), sizeof(rga_rect_t));
+ }
+
+ RkRgaGetHandleMapAddress(src, &srcBuf);
+ RkRgaGetHandleFd(src, &srcFd);
+ if (srcFd == -1 && !srcBuf) {
+ ALOGE("%d:src has not fd and address for render", __LINE__);
+ return ret;
+ }
+
+ if (srcFd == 0 && !srcBuf) {
+ ALOGE("srcFd is zero, now driver not support");
+ return -EINVAL;
+ } else
+ srcFd = -1;
+
+ dstBuf = dst;
+ if (!dstBuf) {
+ ALOGE("%d:dst has not fd and address for render", __LINE__);
+ return ret;
+ }
+
+ planeAlpha = (blend & 0xFF0000) >> 16;
+ perpixelAlpha = relRects.src.format == HAL_PIXEL_FORMAT_RGBA_8888 ||
+ relRects.src.format == HAL_PIXEL_FORMAT_BGRA_8888;
+
+ switch ((blend & 0xFFFF)) {
+ case 0x0105:
+ if (perpixelAlpha && planeAlpha < 255)
+ NormalRgaSetAlphaEnInfo(&rgaReg, 1, 2, planeAlpha , 1, 9, 0);
+ else if (perpixelAlpha)
+ NormalRgaSetAlphaEnInfo(&rgaReg, 1, 1, 0, 1, 3, 0);
+ else
+ NormalRgaSetAlphaEnInfo(&rgaReg, 1, 0, planeAlpha , 0, 0, 0);
+ break;
+
+ case 0x0405:
+ if (perpixelAlpha && planeAlpha < 255)
+ NormalRgaSetAlphaEnInfo(&rgaReg, 1, 2, planeAlpha , 0, 0, 0);
+ else if (perpixelAlpha)
+ NormalRgaSetAlphaEnInfo(&rgaReg, 1, 1, 0, 0, 0, 0);
+ else
+ NormalRgaSetAlphaEnInfo(&rgaReg, 1, 0, planeAlpha , 0, 0, 0);
+ break;
+
+ case 0x0100:
+ default:
+ /* Tips: BLENDING_NONE is non-zero value, handle zero value as
+ * BLENDING_NONE. */
+ /* C = Cs
+ * A = As */
+ break;
+ }
+
+
+ switch (rotation) {
+ case HAL_TRANSFORM_FLIP_H:
+ orientation = 0;
+ rotateMode = 2;
+ srcVirW = relRects.src.wstride;
+ srcVirH = relRects.src.height;
+ srcXPos = relRects.src.xoffset;
+ srcYPos = relRects.src.yoffset;
+ srcActW = relRects.src.width;
+ srcActH = relRects.src.height;
+
+ dstVirW = relRects.dst.wstride;
+ dstVirH = relRects.dst.height;
+ dstXPos = relRects.dst.xoffset;
+ dstYPos = relRects.dst.yoffset;
+ dstActW = relRects.dst.width;
+ dstActH = relRects.dst.height;
+ break;
+ case HAL_TRANSFORM_FLIP_V:
+ orientation = 0;
+ rotateMode = 3;
+ srcVirW = relRects.src.wstride;
+ srcVirH = relRects.src.height;
+ srcXPos = relRects.src.xoffset;
+ srcYPos = relRects.src.yoffset;
+ srcActW = relRects.src.width;
+ srcActH = relRects.src.height;
+
+ dstVirW = relRects.dst.wstride;
+ dstVirH = relRects.dst.height;
+ dstXPos = relRects.dst.xoffset;
+ dstYPos = relRects.dst.yoffset;
+ dstActW = relRects.dst.width;
+ dstActH = relRects.dst.height;
+ break;
+ case HAL_TRANSFORM_ROT_90:
+ orientation = 90;
+ rotateMode = 1;
+ srcVirW = relRects.src.wstride;
+ srcVirH = relRects.src.height;
+ srcXPos = relRects.src.xoffset;
+ srcYPos = relRects.src.yoffset;
+ srcActW = relRects.src.width;
+ srcActH = relRects.src.height;
+
+ dstVirW = relRects.dst.wstride;
+ dstVirH = relRects.dst.height;
+ dstXPos = relRects.dst.width - 1;
+ //dstYPos = relRects.dst.yoffset;
+ dstYPos = 0;
+ dstActW = relRects.dst.height;
+ dstActH = relRects.dst.width;
+ break;
+ case HAL_TRANSFORM_ROT_180:
+ orientation = 180;
+ rotateMode = 1;
+ srcVirW = relRects.src.wstride;
+ srcVirH = relRects.src.height;
+ srcXPos = relRects.src.xoffset;
+ srcYPos = relRects.src.yoffset;
+ srcActW = relRects.src.width;
+ srcActH = relRects.src.height;
+
+ dstVirW = relRects.dst.wstride;
+ dstVirH = relRects.dst.height;
+ dstXPos = relRects.dst.width - 1;
+ dstYPos = relRects.dst.height - 1;
+ dstActW = relRects.dst.width;
+ dstActH = relRects.dst.height;
+ break;
+ case HAL_TRANSFORM_ROT_270:
+ orientation = 270;
+ rotateMode = 1;
+ srcVirW = relRects.src.wstride;
+ srcVirH = relRects.src.height;
+ srcXPos = relRects.src.xoffset;
+ srcYPos = relRects.src.yoffset;
+ srcActW = relRects.src.width;
+ srcActH = relRects.src.height;
+
+ dstVirW = relRects.dst.wstride;
+ dstVirH = relRects.dst.height;
+ //dstXPos = relRects.dst.xoffset;
+ dstXPos = 0;
+ dstYPos = relRects.dst.height - 1;
+ dstActW = relRects.dst.height;
+ dstActH = relRects.dst.width;
+ break;
+ default:
+ orientation = 0;
+ rotateMode = 0;
+ srcVirW = relRects.src.wstride;
+ srcVirH = relRects.src.height;
+ srcXPos = relRects.src.xoffset;
+ srcYPos = relRects.src.yoffset;
+ srcActW = relRects.src.width;
+ srcActH = relRects.src.height;
+
+ dstVirW = relRects.dst.wstride;
+ dstVirH = relRects.dst.height;
+ dstXPos = relRects.dst.xoffset;
+ dstYPos = relRects.dst.yoffset;
+ dstActW = relRects.dst.width;
+ dstActH = relRects.dst.height;
+ break;
+ }
+
+ clip.xmin = 0;
+ clip.xmax = dstActW - 1;
+ clip.ymin = 0;
+ clip.ymax = dstActH - 1;
+
+ scaleMode = 0;
+ //scale up use bicubic
+ if (srcActW / dstActW < 1 || srcActH / dstActH < 1)
+ scaleMode = 2;
+
+ /*
+ if (scaleMode && (srcFormat == RK_FORMAT_RGBA_8888 ||
+ srcFormat == RK_FORMAT_BGRA_8888)) {
+ scale_mode = 0; // force change scale_mode to 0 ,for rga not support
+ }*/
+
+ ditherEn = (android::bytesPerPixel(relRects.src.format)
+ != android::bytesPerPixel(relRects.src.format) ? 1 : 0);
+
+ if (ctx->mVersion <= 1.003) {
+ srcMmuFlag = dstMmuFlag = 1;
+
+#if defined(__arm64__) || defined(__aarch64__)
+ NormalRgaSetSrcVirtualInfo(&rgaReg, (unsigned long)srcBuf,
+ (unsigned long)srcBuf + srcVirW * srcVirH,
+ (unsigned long)srcBuf + srcVirW * srcVirH * 5/4,
+ srcVirW, srcVirH,
+ RkRgaGetRgaFormat(relRects.src.format),0);
+ /*dst*/
+ NormalRgaSetDstVirtualInfo(&rgaReg, (unsigned long)dstBuf,
+ (unsigned long)dstBuf + dstVirW * dstVirH,
+ (unsigned long)dstBuf + dstVirW * dstVirH * 5/4,
+ dstVirW, dstVirH, &clip,
+ RkRgaGetRgaFormat(relRects.dst.format),0);
+#else
+ NormalRgaSetSrcVirtualInfo(&rgaReg, (unsigned int)srcBuf,
+ (unsigned int)srcBuf + srcVirW * srcVirH,
+ (unsigned int)srcBuf + srcVirW * srcVirH * 5/4,
+ srcVirW, srcVirH,
+ RkRgaGetRgaFormat(relRects.src.format),0);
+ /*dst*/
+ NormalRgaSetDstVirtualInfo(&rgaReg, (unsigned int)dstBuf,
+ (unsigned int)dstBuf + dstVirW * dstVirH,
+ (unsigned int)dstBuf + dstVirW * dstVirH * 5/4,
+ dstVirW, dstVirH, &clip,
+ RkRgaGetRgaFormat(relRects.dst.format),0);
+#endif
+ } else if (ctx->mVersion < 2.0) {
+ /*Src*/
+ if (srcFd != -1) {
+ srcMmuFlag = srcType ? 1 : 0;
+ NormalRgaSetSrcVirtualInfo(&rgaReg, 0, 0, 0, srcVirW, srcVirH,
+ RkRgaGetRgaFormat(relRects.src.format),0);
+ NormalRgaSetFdsOffsets(&rgaReg, srcFd, 0, 0, 0);
+ } else {
+ srcMmuFlag = 1;
+
+#if defined(__arm64__) || defined(__aarch64__)
+ NormalRgaSetSrcVirtualInfo(&rgaReg, (unsigned long)srcBuf,
+ (unsigned long)srcBuf + srcVirW * srcVirH,
+ (unsigned long)srcBuf + srcVirW * srcVirH * 5/4,
+ srcVirW, srcVirH,
+ RkRgaGetRgaFormat(relRects.src.format),0);
+#else
+ NormalRgaSetSrcVirtualInfo(&rgaReg, (unsigned int)srcBuf,
+ (unsigned int)srcBuf + srcVirW * srcVirH,
+ (unsigned int)srcBuf + srcVirW * srcVirH * 5/4,
+ srcVirW, srcVirH,
+ RkRgaGetRgaFormat(relRects.src.format),0);
+#endif
+ }
+ /*dst*/
+ if (dstFd != -1) {
+ dstMmuFlag = srcType ? 1 : 0;
+ NormalRgaSetDstVirtualInfo(&rgaReg, 0, 0, 0, dstVirW, dstVirH, &clip,
+ RkRgaGetRgaFormat(relRects.dst.format),0);
+ /*src dst fd*/
+ NormalRgaSetFdsOffsets(&rgaReg, 0, dstFd, 0, 0);
+ } else {
+ dstMmuFlag = 1;
+#if defined(__arm64__) || defined(__aarch64__)
+ NormalRgaSetDstVirtualInfo(&rgaReg, (unsigned long)dstBuf,
+ (unsigned long)dstBuf + dstVirW * dstVirH,
+ (unsigned long)dstBuf + dstVirW * dstVirH * 5/4,
+ dstVirW, dstVirH, &clip,
+ RkRgaGetRgaFormat(relRects.dst.format),0);
+#else
+ NormalRgaSetDstVirtualInfo(&rgaReg, (unsigned int)dstBuf,
+ (unsigned int)dstBuf + dstVirW * dstVirH,
+ (unsigned int)dstBuf + dstVirW * dstVirH * 5/4,
+ dstVirW, dstVirH, &clip,
+ RkRgaGetRgaFormat(relRects.dst.format),0);
+#endif
+ }
+ } else {
+ srcMmuFlag = ((srcFd != -1 && srcType) || srcFd == -1) ? 1 : 0;
+ dstMmuFlag = ((dstFd != -1 && dstType) || dstFd == -1) ? 1 : 0;
+#if defined(__arm64__) || defined(__aarch64__)
+ NormalRgaSetSrcVirtualInfo(&rgaReg, srcFd != -1 ? srcFd : 0,
+ (unsigned long)srcBuf,
+ (unsigned long)srcBuf + srcVirW * srcVirH,
+ srcVirW, srcVirH,
+ RkRgaGetRgaFormat(relRects.src.format),0);
+ /*dst*/
+ NormalRgaSetDstVirtualInfo(&rgaReg, dstFd != -1 ? dstFd : 0,
+ (unsigned long)dstBuf,
+ (unsigned long)dstBuf + dstVirW * dstVirH,
+ dstVirW, dstVirH, &clip,
+ RkRgaGetRgaFormat(relRects.dst.format),0);
+#else
+ NormalRgaSetSrcVirtualInfo(&rgaReg, srcFd != -1 ? srcFd : 0,
+ (unsigned int)srcBuf,
+ (unsigned int)srcBuf + srcVirW * srcVirH,
+ srcVirW, srcVirH,
+ RkRgaGetRgaFormat(relRects.src.format),0);
+ /*dst*/
+ NormalRgaSetDstVirtualInfo(&rgaReg, dstFd != -1 ? dstFd : 0,
+ (unsigned int)dstBuf,
+ (unsigned int)dstBuf + dstVirW * dstVirH,
+ dstVirW, dstVirH, &clip,
+ RkRgaGetRgaFormat(relRects.dst.format),0);
+#endif
+ }
+
+ NormalRgaSetSrcActiveInfo(&rgaReg, srcActW, srcActH, srcXPos, srcYPos);
+ NormalRgaSetDstActiveInfo(&rgaReg, dstActW, dstActH, dstXPos, dstYPos);
+
+ /*mode*/
+ NormalRgaSetBitbltMode(&rgaReg, scaleMode, rotateMode, orientation, ditherEn, 0, 0);
+
+ if (srcMmuFlag || dstMmuFlag) {
+ NormalRgaMmuInfo(&rgaReg, 1, 0, 0, 0, 0, 2);
+ NormalRgaMmuFlag(&rgaReg, srcMmuFlag, dstMmuFlag);
+ }
+
+ if(ioctl(ctx->rgaFd, RGA_BLIT_SYNC, &rgaReg)) {
+ printf(" %s(%d) RGA_BLIT fail: %s",__FUNCTION__, __LINE__,strerror(errno));
+ ALOGE(" %s(%d) RGA_BLIT fail: %s",__FUNCTION__, __LINE__,strerror(errno));
+ }
+
+ return 0;
+}
+
+int RgaBlit(void *src, void *dst,
+ drm_rga_t *rects, int rotation, int blend)
+{
+ //check rects
+ //check buffer_handle_t with rects
+ struct rgaContext *ctx = rgaCtx;
+ int srcVirW,srcVirH,srcActW,srcActH,srcXPos,srcYPos;
+ int dstVirW,dstVirH,dstActW,dstActH,dstXPos,dstYPos;
+ int scaleMode,rotateMode,orientation,ditherEn;
+ int srcType,dstType,srcMmuFlag,dstMmuFlag;
+ int planeAlpha;
+ int dstFd = -1;
+ int srcFd = -1;
+ int ret = 0;
+ drm_rga_t relRects;
+ struct rga_req rgaReg;
+ bool perpixelAlpha;
+ void *srcBuf = NULL;
+ void *dstBuf = NULL;
+ RECT clip;
+
+ if (!ctx) {
+ ALOGE("Try to use uninit rgaCtx=%p",ctx);
+ return -ENODEV;
+ }
+
+ if (rects && (ctx->mLogAlways || ctx->mLogOnce)) {
+ ALOGD("Src:[%d,%d,%d,%d][%d,%d,%d]=>Dst:[%d,%d,%d,%d][%d,%d,%d]",
+ rects->src.xoffset,rects->src.yoffset,
+ rects->src.width, rects->src.height,
+ rects->src.wstride,rects->src.format, rects->src.size,
+ rects->dst.xoffset,rects->dst.yoffset,
+ rects->dst.width, rects->dst.height,
+ rects->dst.wstride,rects->dst.format, rects->dst.size);
+ }
+
+ memset(&rgaReg, 0, sizeof(struct rga_req));
+
+ srcType = dstType = srcMmuFlag = dstMmuFlag = 0;
+
+ if (!rects) {
+ ALOGE("%d:Has not user rects for render", __LINE__);
+ return ret;
+ }
+
+ if (rects->src.wstride <= 0 || rects->dst.wstride <= 0) {
+ ALOGE("%d:Has invalid rects for render", __LINE__);
+ return -EINVAL;
+ }
+
+ memcpy(&relRects, rects, sizeof(drm_rga_t));
+
+ srcBuf = src;
+ if (!srcBuf) {
+ ALOGE("%d:src has not fd and address for render", __LINE__);
+ return ret;
+ }
+
+ dstBuf = dst;
+ if (!dstBuf) {
+ ALOGE("%d:dst has not fd and address for render", __LINE__);
+ return ret;
+ }
+
+ planeAlpha = (blend & 0xFF0000) >> 16;
+ perpixelAlpha = relRects.src.format == HAL_PIXEL_FORMAT_RGBA_8888 ||
+ relRects.src.format == HAL_PIXEL_FORMAT_BGRA_8888;
+
+ switch ((blend & 0xFFFF)) {
+ case 0x0105:
+ if (perpixelAlpha && planeAlpha < 255)
+ NormalRgaSetAlphaEnInfo(&rgaReg, 1, 2, planeAlpha , 1, 9, 0);
+ else if (perpixelAlpha)
+ NormalRgaSetAlphaEnInfo(&rgaReg, 1, 1, 0, 1, 3, 0);
+ else
+ NormalRgaSetAlphaEnInfo(&rgaReg, 1, 0, planeAlpha , 0, 0, 0);
+ break;
+
+ case 0x0405:
+ if (perpixelAlpha && planeAlpha < 255)
+ NormalRgaSetAlphaEnInfo(&rgaReg, 1, 2, planeAlpha , 0, 0, 0);
+ else if (perpixelAlpha)
+ NormalRgaSetAlphaEnInfo(&rgaReg, 1, 1, 0, 0, 0, 0);
+ else
+ NormalRgaSetAlphaEnInfo(&rgaReg, 1, 0, planeAlpha , 0, 0, 0);
+ break;
+
+ case 0x0100:
+ default:
+ /* Tips: BLENDING_NONE is non-zero value, handle zero value as
+ * BLENDING_NONE. */
+ /* C = Cs
+ * A = As */
+ break;
+ }
+
+
+ switch (rotation) {
+ case HAL_TRANSFORM_FLIP_H:
+ orientation = 0;
+ rotateMode = 2;
+ srcVirW = relRects.src.wstride;
+ srcVirH = relRects.src.height;
+ srcXPos = relRects.src.xoffset;
+ srcYPos = relRects.src.yoffset;
+ srcActW = relRects.src.width;
+ srcActH = relRects.src.height;
+
+ dstVirW = relRects.dst.wstride;
+ dstVirH = relRects.dst.height;
+ dstXPos = relRects.dst.xoffset;
+ dstYPos = relRects.dst.yoffset;
+ dstActW = relRects.dst.width;
+ dstActH = relRects.dst.height;
+ break;
+ case HAL_TRANSFORM_FLIP_V:
+ orientation = 0;
+ rotateMode = 3;
+ srcVirW = relRects.src.wstride;
+ srcVirH = relRects.src.height;
+ srcXPos = relRects.src.xoffset;
+ srcYPos = relRects.src.yoffset;
+ srcActW = relRects.src.width;
+ srcActH = relRects.src.height;
+
+ dstVirW = relRects.dst.wstride;
+ dstVirH = relRects.dst.height;
+ dstXPos = relRects.dst.xoffset;
+ dstYPos = relRects.dst.yoffset;
+ dstActW = relRects.dst.width;
+ dstActH = relRects.dst.height;
+ break;
+ case HAL_TRANSFORM_ROT_90:
+ orientation = 90;
+ rotateMode = 1;
+ srcVirW = relRects.src.wstride;
+ srcVirH = relRects.src.height;
+ srcXPos = relRects.src.xoffset;
+ srcYPos = relRects.src.yoffset;
+ srcActW = relRects.src.width;
+ srcActH = relRects.src.height;
+
+ dstVirW = relRects.dst.wstride;
+ dstVirH = relRects.dst.height;
+ dstXPos = relRects.dst.width - 1;
+ //dstYPos = relRects.dst.yoffset;
+ dstYPos = 0;
+ dstActW = relRects.dst.height;
+ dstActH = relRects.dst.width;
+ break;
+ case HAL_TRANSFORM_ROT_180:
+ orientation = 180;
+ rotateMode = 1;
+ srcVirW = relRects.src.wstride;
+ srcVirH = relRects.src.height;
+ srcXPos = relRects.src.xoffset;
+ srcYPos = relRects.src.yoffset;
+ srcActW = relRects.src.width;
+ srcActH = relRects.src.height;
+
+ dstVirW = relRects.dst.wstride;
+ dstVirH = relRects.dst.height;
+ dstXPos = relRects.dst.width - 1;
+ dstYPos = relRects.dst.height - 1;
+ dstActW = relRects.dst.width;
+ dstActH = relRects.dst.height;
+ break;
+ case HAL_TRANSFORM_ROT_270:
+ orientation = 270;
+ rotateMode = 1;
+ srcVirW = relRects.src.wstride;
+ srcVirH = relRects.src.height;
+ srcXPos = relRects.src.xoffset;
+ srcYPos = relRects.src.yoffset;
+ srcActW = relRects.src.width;
+ srcActH = relRects.src.height;
+
+ dstVirW = relRects.dst.wstride;
+ dstVirH = relRects.dst.height;
+ //dstXPos = relRects.dst.xoffset;
+ dstXPos = 0;
+ dstYPos = relRects.dst.height - 1;
+ dstActW = relRects.dst.height;
+ dstActH = relRects.dst.width;
+ break;
+ default:
+ orientation = 0;
+ rotateMode = 0;
+ srcVirW = relRects.src.wstride;
+ srcVirH = relRects.src.height;
+ srcXPos = relRects.src.xoffset;
+ srcYPos = relRects.src.yoffset;
+ srcActW = relRects.src.width;
+ srcActH = relRects.src.height;
+
+ dstVirW = relRects.dst.wstride;
+ dstVirH = relRects.dst.height;
+ dstXPos = relRects.dst.xoffset;
+ dstYPos = relRects.dst.yoffset;
+ dstActW = relRects.dst.width;
+ dstActH = relRects.dst.height;
+ break;
+ }
+
+ clip.xmin = 0;
+ clip.xmax = dstActW - 1;
+ clip.ymin = 0;
+ clip.ymax = dstActH - 1;
+
+ scaleMode = 0;
+ //scale up use bicubic
+ if (srcActW / dstActW < 1 || srcActH / dstActH < 1)
+ scaleMode = 2;
+
+ /*
+ if (scaleMode && (srcFormat == RK_FORMAT_RGBA_8888 ||
+ srcFormat == RK_FORMAT_BGRA_8888)) {
+ scale_mode = 0; // force change scale_mode to 0 ,for rga not support
+ }*/
+
+ ditherEn = (android::bytesPerPixel(relRects.src.format)
+ != android::bytesPerPixel(relRects.src.format) ? 1 : 0);
+
+ if (ctx->mVersion <= 1.003) {
+ srcMmuFlag = dstMmuFlag = 1;
+
+#if defined(__arm64__) || defined(__aarch64__)
+ NormalRgaSetSrcVirtualInfo(&rgaReg, (unsigned long)srcBuf,
+ (unsigned long)srcBuf + srcVirW * srcVirH,
+ (unsigned long)srcBuf + srcVirW * srcVirH * 5/4,
+ srcVirW, srcVirH,
+ RkRgaGetRgaFormat(relRects.src.format),0);
+ /*dst*/
+ NormalRgaSetDstVirtualInfo(&rgaReg, (unsigned long)dstBuf,
+ (unsigned long)dstBuf + dstVirW * dstVirH,
+ (unsigned long)dstBuf + dstVirW * dstVirH * 5/4,
+ dstVirW, dstVirH, &clip,
+ RkRgaGetRgaFormat(relRects.dst.format),0);
+#else
+ NormalRgaSetSrcVirtualInfo(&rgaReg, (unsigned int)srcBuf,
+ (unsigned int)srcBuf + srcVirW * srcVirH,
+ (unsigned int)srcBuf + srcVirW * srcVirH * 5/4,
+ srcVirW, srcVirH,
+ RkRgaGetRgaFormat(relRects.src.format),0);
+ /*dst*/
+ NormalRgaSetDstVirtualInfo(&rgaReg, (unsigned int)dstBuf,
+ (unsigned int)dstBuf + dstVirW * dstVirH,
+ (unsigned int)dstBuf + dstVirW * dstVirH * 5/4,
+ dstVirW, dstVirH, &clip,
+ RkRgaGetRgaFormat(relRects.dst.format),0);
+#endif
+ } else if (ctx->mVersion < 2.0) {
+ /*Src*/
+ if (srcFd != -1) {
+ srcMmuFlag = srcType ? 1 : 0;
+ NormalRgaSetSrcVirtualInfo(&rgaReg, 0, 0, 0, srcVirW, srcVirH,
+ RkRgaGetRgaFormat(relRects.src.format),0);
+ NormalRgaSetFdsOffsets(&rgaReg, srcFd, 0, 0, 0);
+ } else {
+ srcMmuFlag = 1;
+
+#if defined(__arm64__) || defined(__aarch64__)
+ NormalRgaSetSrcVirtualInfo(&rgaReg, (unsigned long)srcBuf,
+ (unsigned long)srcBuf + srcVirW * srcVirH,
+ (unsigned long)srcBuf + srcVirW * srcVirH * 5/4,
+ srcVirW, srcVirH,
+ RkRgaGetRgaFormat(relRects.src.format),0);
+#else
+ NormalRgaSetSrcVirtualInfo(&rgaReg, (unsigned int)srcBuf,
+ (unsigned int)srcBuf + srcVirW * srcVirH,
+ (unsigned int)srcBuf + srcVirW * srcVirH * 5/4,
+ srcVirW, srcVirH,
+ RkRgaGetRgaFormat(relRects.src.format),0);
+#endif
+ }
+ /*dst*/
+ if (dstFd != -1) {
+ dstMmuFlag = srcType ? 1 : 0;
+ NormalRgaSetDstVirtualInfo(&rgaReg, 0, 0, 0, dstVirW, dstVirH, &clip,
+ RkRgaGetRgaFormat(relRects.dst.format),0);
+ /*src dst fd*/
+ NormalRgaSetFdsOffsets(&rgaReg, 0, dstFd, 0, 0);
+ } else {
+ dstMmuFlag = 1;
+#if defined(__arm64__) || defined(__aarch64__)
+ NormalRgaSetDstVirtualInfo(&rgaReg, (unsigned long)dstBuf,
+ (unsigned long)dstBuf + dstVirW * dstVirH,
+ (unsigned long)dstBuf + dstVirW * dstVirH * 5/4,
+ dstVirW, dstVirH, &clip,
+ RkRgaGetRgaFormat(relRects.dst.format),0);
+#else
+ NormalRgaSetDstVirtualInfo(&rgaReg, (unsigned int)dstBuf,
+ (unsigned int)dstBuf + dstVirW * dstVirH,
+ (unsigned int)dstBuf + dstVirW * dstVirH * 5/4,
+ dstVirW, dstVirH, &clip,
+ RkRgaGetRgaFormat(relRects.dst.format),0);
+#endif
+ }
+ } else {
+ srcMmuFlag = ((srcFd != -1 && srcType) || srcFd == -1) ? 1 : 0;
+ dstMmuFlag = ((dstFd != -1 && dstType) || dstFd == -1) ? 1 : 0;
+#if defined(__arm64__) || defined(__aarch64__)
+ NormalRgaSetSrcVirtualInfo(&rgaReg, srcFd != -1 ? srcFd : 0,
+ (unsigned long)srcBuf,
+ (unsigned long)srcBuf + srcVirW * srcVirH,
+ srcVirW, srcVirH,
+ RkRgaGetRgaFormat(relRects.src.format),0);
+ /*dst*/
+ NormalRgaSetDstVirtualInfo(&rgaReg, dstFd != -1 ? dstFd : 0,
+ (unsigned long)dstBuf,
+ (unsigned long)dstBuf + dstVirW * dstVirH,
+ dstVirW, dstVirH, &clip,
+ RkRgaGetRgaFormat(relRects.dst.format),0);
+#else
+ NormalRgaSetSrcVirtualInfo(&rgaReg, srcFd != -1 ? srcFd : 0,
+ (unsigned int)srcBuf,
+ (unsigned int)srcBuf + srcVirW * srcVirH,
+ srcVirW, srcVirH,
+ RkRgaGetRgaFormat(relRects.src.format),0);
+ /*dst*/
+ NormalRgaSetDstVirtualInfo(&rgaReg, dstFd != -1 ? dstFd : 0,
+ (unsigned int)dstBuf,
+ (unsigned int)dstBuf + dstVirW * dstVirH,
+ dstVirW, dstVirH, &clip,
+ RkRgaGetRgaFormat(relRects.dst.format),0);
+#endif
+ }
+
+ NormalRgaSetSrcActiveInfo(&rgaReg, srcActW, srcActH, srcXPos, srcYPos);
+ NormalRgaSetDstActiveInfo(&rgaReg, dstActW, dstActH, dstXPos, dstYPos);
+
+ /*mode*/
+ NormalRgaSetBitbltMode(&rgaReg, scaleMode, rotateMode, orientation, ditherEn, 0, 0);
+
+ if (srcMmuFlag || dstMmuFlag) {
+ NormalRgaMmuInfo(&rgaReg, 1, 0, 0, 0, 0, 2);
+ NormalRgaMmuFlag(&rgaReg, srcMmuFlag, dstMmuFlag);
+ }
+
+ if(ioctl(ctx->rgaFd, RGA_BLIT_SYNC, &rgaReg)) {
+ printf(" %s(%d) RGA_BLIT fail: %s",__FUNCTION__, __LINE__,strerror(errno));
+ ALOGE(" %s(%d) RGA_BLIT fail: %s",__FUNCTION__, __LINE__,strerror(errno));
+ }
+
+ if (ctx->mLogOnce)
+ ctx->mLogOnce = 0;
+
+ return 0;
+}
+
+int NormalRgaScale()
+{
+ return 1;
+}
+
+int NormalRgaRoate()
+{
+ return 1;
+}
+
+int NormalRgaRoateScale()
+{
+ return 1;
+}
diff --git a/normal/NormalRga.h b/normal/NormalRga.h
new file mode 100644
index 0000000..7cedef2
--- /dev/null
+++ b/normal/NormalRga.h
@@ -0,0 +1,270 @@
+/*
+ * Copyright (C) 2016 Rockchip Electronics Co.Ltd
+ * Authors:
+ * Zhiqin Wei <wzq@rock-chips.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ */
+
+#ifndef _rockchip_normal_rga_h_
+#define _rockchip_normal_rga_h_
+#include <stdint.h>
+#include <vector>
+#include <sys/types.h>
+
+#include <system/window.h>
+
+#include <utils/Thread.h>
+
+#include <EGL/egl.h>
+#include <GLES/gl.h>
+
+//////////////////////////////////////////////////////////////////////////////////
+#include <hardware/hardware.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <time.h>
+#include <unistd.h>
+#include <fcntl.h>
+
+#include <utils/Atomic.h>
+#include <utils/Errors.h>
+#include <utils/Log.h>
+#include <ui/PixelFormat.h>
+
+#include <sys/mman.h>
+#include <linux/stddef.h>
+
+#include <hardware/rga.h>
+#include "stdio.h"
+
+#include "drmrga.h"
+#include "NormalRgaContext.h"
+
+
+int NormalRgaInitTables();
+
+int NormalRgaPaletteTable(buffer_handle_t dst,
+ unsigned int v, drm_rga_t *rects);
+
+int NormalRgaStereo(buffer_handle_t src,
+ buffer_handle_t dst,int div);
+int NormalRgaScale();
+int NormalRgaRoate();
+int NormalRgaRoateScale();
+int NormalRgaGetRects(buffer_handle_t src, buffer_handle_t dst,
+ int *sType, int *dType, drm_rga_t* tmpRects);
+/*
+@fun NormalRgaSetRects:For use to set the rects esayly
+
+@param rect:The rect user want to set,like setting the src rect:
+ drm_rga_t rects;
+ NormalRgaSetRects(rects.src,0,0,1920,1080,1920,NV12);
+ mean to set the src rect to the value.
+*/
+int checkRectForRga(rga_rect_t rect);
+int isRectValid(rga_rect_t rect);
+int NormalRgaGetRect(buffer_handle_t hnd, rga_rect_t *rect);
+int NormalRgaGetMmuType(buffer_handle_t hnd, int *mmuType);
+
+int NormalRgaSetRect(rga_rect_t *rect, int x, int y,
+ int w, int h, int s, int f);
+void NormalRgaSetLogOnceFlag(int log);
+void NormalRgaSetAlwaysLogFlag(bool log);
+void NormalRgaLogOutRgaReq(struct rga_req rgaReg);
+
+int NormalRgaSetFdsOffsets(struct rga_req *req,
+ uint16_t src_fd, uint16_t dst_fd,
+ uint32_t src_offset, uint32_t dst_offset);
+
+int NormalRgaSetSrcActiveInfo(struct rga_req *req,
+ unsigned int width, unsigned int height,
+ unsigned int x_off, unsigned int y_off);
+
+
+#if defined(__arm64__) || defined(__aarch64__)
+int NormalRgaSetSrcVirtualInfo(struct rga_req *req,
+ unsigned long yrgb_addr,unsigned long uv_addr,unsigned long v_addr,
+ unsigned int vir_w ,unsigned int vir_h, unsigned char format,
+ unsigned char a_swap_en);
+#else
+int NormalRgaSetSrcVirtualInfo(struct rga_req *req,
+ unsigned int yrgb_addr, unsigned int uv_addr,unsigned int v_addr,
+ unsigned int vir_w, unsigned int vir_h, unsigned char format,
+ unsigned char a_swap_en);
+#endif
+
+
+int NormalRgaSetDstActiveInfo(struct rga_req *req,
+ unsigned int width, unsigned int height,
+ unsigned int x_off, unsigned int y_off);
+
+
+#if defined(__arm64__) || defined(__aarch64__)
+int NormalRgaSetDstVirtualInfo(struct rga_req *msg,
+ unsigned long yrgb_addr,unsigned long uv_addr,unsigned long v_addr,
+ unsigned int vir_w, unsigned int vir_h,
+ RECT *clip, unsigned char format, unsigned char a_swap_en);
+#else
+int NormalRgaSetDstVirtualInfo(struct rga_req *msg,
+ unsigned int yrgb_addr,unsigned int uv_addr, unsigned int v_addr,
+ unsigned int vir_w, unsigned int vir_h,
+ RECT *clip, unsigned char format, unsigned char a_swap_en);
+#endif
+
+
+int NormalRgaSetPatInfo(struct rga_req *msg,
+ unsigned int width,unsigned int height,unsigned int x_off,
+ unsigned int y_off, unsigned int pat_format);
+
+
+#if defined(__arm64__) || defined(__aarch64__)
+int NormalRgaSetRopMaskInfo(struct rga_req *msg,
+ unsigned long rop_mask_addr,unsigned int rop_mask_endian_mode);
+#else
+int NormalRgaSetRopMaskInfo(struct rga_req *msg,
+ unsigned int rop_mask_addr,unsigned int rop_mask_endian_mode);
+#endif
+
+
+/* 0:alpha' = alpha + (alpha>>7) | alpha' = alpha */
+/* 0 global alpha / 1 per pixel alpha / 2 mix mode */
+
+/* porter duff alpha mode en */
+
+/* use dst alpha */
+
+int NormalRgaSetAlphaEnInfo(struct rga_req *msg,
+ unsigned int alpha_cal_mode, unsigned int alpha_mode,
+ unsigned int global_a_value, unsigned int PD_en,
+ unsigned int PD_mode, unsigned int dst_alpha_en );
+
+
+
+int NormalRgaSetRopEnInfo(struct rga_req *msg,
+ unsigned int ROP_mode, unsigned int ROP_code,
+ unsigned int color_mode,unsigned int solid_color);
+
+
+int NormalRgaSetFadingEnInfo(struct rga_req *msg,
+ unsigned char r,unsigned char g,unsigned char b);
+
+
+int NormalRgaSetSrcTransModeInfo(struct rga_req *msg,
+ unsigned char trans_mode,unsigned char a_en,unsigned char b_en,
+ unsigned char g_en,unsigned char r_en,unsigned char color_key_min,
+ unsigned char color_key_max,unsigned char zero_mode_en);
+
+bool NormalRgaIsBppFormat(int format);
+
+bool NormalRgaIsYuvFormat(int format);
+
+bool NormalRgaIsRgbFormat(int format);
+
+
+// 0/near 1/bilnear 2/bicubic
+// 0/copy 1/rotate_scale 2/x_mirror 3/y_mirror
+// rotate angle
+// dither en flag
+// AA flag
+int NormalRgaSetBitbltMode(struct rga_req *msg,
+ unsigned char scale_mode, unsigned char rotate_mode,
+ unsigned int angle, unsigned int dither_en,
+ unsigned int AA_en, unsigned int yuv2rgb_mode);
+
+
+/* 1bpp/2bpp/4bpp/8bpp */
+/* src endian mode sel */
+/* BPP1 = 0 */
+/* BPP1 = 1 */
+int NormalRgaSetColorPaletteMode(struct rga_req *msg,
+ unsigned char palette_mode,unsigned char endian_mode,
+ unsigned int bpp1_0_color, unsigned int bpp1_1_color);
+
+
+/* gradient color part */
+ /* saturation mode */
+ /* patten fill or solid fill */
+/* solid color */
+ /* pattern width */
+ /* pattern height */
+ /* pattern x offset */
+ /* pattern y offset */
+ /* alpha en */
+int NormalRgaSetColorFillMode(
+ struct rga_req *msg, COLOR_FILL *gr_color,
+ unsigned char gr_satur_mode, unsigned char cf_mode,
+ unsigned int color, unsigned short pat_width,
+ unsigned short pat_height, unsigned char pat_x_off,
+ unsigned char pat_y_off, unsigned char aa_en);
+
+
+/* start point */
+/* end point */
+/* line point drawing color */
+/* line width */
+/* AA en */
+/* last point en */
+int NormalRgaSetLineDrawingMode(struct rga_req *msg,
+ POINT sp, POINT ep,
+ unsigned int color, unsigned int line_width,
+ unsigned char AA_en, unsigned char last_point_en);
+
+
+
+/* blur/sharpness */
+/* filter intensity */
+/* dither_en flag */
+
+int NormalRgaSetBlurSharpFilterMode(
+ struct rga_req *msg, unsigned char filter_mode,
+ unsigned char filter_type, unsigned char dither_en);
+
+
+int NormalRgaSetPreScalingMode(
+ struct rga_req *msg, unsigned char dither_en);
+
+
+/* LUT table addr */
+/* 1bpp/2bpp/4bpp/8bpp */
+#if defined(__arm64__) || defined(__aarch64__)
+int NormalRgaUpdatePaletteTableMode(
+ struct rga_req *msg,unsigned long LUT_addr,unsigned int palette_mode);
+#else
+int NormalRgaUpdatePaletteTableMode(
+ struct rga_req *msg,unsigned int LUT_addr, unsigned int palette_mode);
+#endif
+
+
+/* patten addr */
+/* patten width */
+/* patten height */
+/* patten format */
+
+int NormalRgaUpdatePattenBuffMode(struct rga_req *msg,
+ unsigned int pat_addr, unsigned int w,
+ unsigned int h, unsigned int format);
+
+
+#if defined(__arm64__) || defined(__aarch64__)
+int NormalRgaMmuInfo(struct rga_req *msg,
+ unsigned char mmu_en, unsigned char src_flush,
+ unsigned char dst_flush,unsigned char cmd_flush,
+ unsigned long base_addr, unsigned char page_size);
+#else
+int NormalRgaMmuInfo(struct rga_req *msg,
+ unsigned char mmu_en, unsigned char src_flush,
+ unsigned char dst_flush,unsigned char cmd_flush,
+ unsigned int base_addr, unsigned char page_size);
+#endif
+
+int NormalRgaMmuFlag(struct rga_req *msg,
+ int src_mmu_en, int dst_mmu_en);
+
+#endif
diff --git a/normal/NormalRgaApi.cpp b/normal/NormalRgaApi.cpp
new file mode 100644
index 0000000..17579be
--- /dev/null
+++ b/normal/NormalRgaApi.cpp
@@ -0,0 +1,809 @@
+/*
+ * Copyright (C) 2016 Rockchip Electronics Co.Ltd
+ * Authors:
+ * Zhiqin Wei <wzq@rock-chips.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ */
+
+#include "NormalRga.h"
+#include "NormalRgaContext.h"
+#include "../GraphicBuffer.h"
+
+int sina_table[360];
+int cosa_table[360];
+/**********************************************************************
+ =======================================================================
+ **********************************************************************/
+int checkRectForRga(rga_rect_t rect)
+{
+ if (rect.xoffset < 0 || rect.yoffset < 0) {
+ ALOGE("err offset[%d,%d]", rect.xoffset, rect.yoffset);
+ return -EINVAL;
+ }
+
+ if (rect.width < 2 || rect.height < 2) {
+ ALOGE("err act[%d,%d]", rect.width, rect.height);
+ return -EINVAL;
+ }
+
+ if (rect.xoffset + rect.width > rect.wstride) {
+ ALOGE("err ws[%d,%d,%d]", rect.xoffset, rect.width, rect.wstride);
+ return -EINVAL;
+ }
+
+ if (rect.yoffset + rect.height > rect.hstride) {
+ ALOGE("err hs[%d,%d,%d]", rect.yoffset, rect.height, rect.hstride);
+ return -EINVAL;
+ }
+
+ if (NormalRgaIsYuvFormat(RkRgaGetRgaFormat(rect.format)) &&
+ ((rect.wstride % 8) || (rect.xoffset % 2) || (rect.width % 2) ||
+ (rect.yoffset % 2) || (rect.height % 2) || (rect.hstride % 2))) {
+ ALOGE("err wstride is not align to 8 or yuv not align to 2");
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+int isRectValid(rga_rect_t rect)
+{
+ return rect.width > 0 && rect.height > 0;
+}
+
+int NormalRgaGetRects(buffer_handle_t src,
+ buffer_handle_t dst,int* sType,int* dType,drm_rga_t* tmpRects)
+{
+ int ret = 0;
+ std::vector<int> srcAttrs,dstAttrs;
+ if (src)
+ ret = RkRgaGetHandleAttributes(src, &srcAttrs);
+ if (ret) {
+ ALOGE("dst handle get Attributes fail ret = %d,hnd=%p",ret,&src);
+ printf("dst handle get Attributes fail ret = %d,hnd=%p",ret,&src);
+ return ret;
+ }
+
+ if (dst)
+ ret = RkRgaGetHandleAttributes(dst, &dstAttrs);
+ if (ret) {
+ ALOGE("dst handle get Attributes fail ret = %d,hnd=%p",ret,&dst);
+ printf("dst handle get Attributes fail ret = %d,hnd=%p",ret,&dst);
+ return ret;
+ }
+
+ memset(tmpRects,0,sizeof(drm_rga_t));
+
+ if (src) {
+ tmpRects->src.size = srcAttrs.at(ASIZE);
+ tmpRects->src.width = srcAttrs.at(AWIDTH);
+ tmpRects->src.height = srcAttrs.at(AHEIGHT);
+ tmpRects->src.wstride = srcAttrs.at(ASTRIDE);
+ tmpRects->src.format = srcAttrs.at(AFORMAT);
+ if (sType)
+ *sType = srcAttrs.at(ATYPE);
+ }
+
+ if (dst) {
+ tmpRects->dst.size = dstAttrs.at(ASIZE);
+ tmpRects->dst.width = dstAttrs.at(AWIDTH);
+ tmpRects->dst.height = dstAttrs.at(AHEIGHT);
+ tmpRects->dst.wstride = dstAttrs.at(ASTRIDE);
+ tmpRects->dst.format = dstAttrs.at(AFORMAT);
+ if (dType)
+ *dType = dstAttrs.at(ATYPE);
+ }
+
+ return ret;
+}
+
+int NormalRgaGetRect(buffer_handle_t hnd, rga_rect_t *rect)
+{
+ int ret = 0;
+ std::vector<int> dstAttrs;
+
+ if (!rect) {
+ ALOGE("Get rect but rect[%p] is null point", rect);
+ return -EINVAL;
+ }
+
+ ret = RkRgaGetHandleAttributes(hnd, &dstAttrs);
+ if (ret) {
+ ALOGE("dst handle get Attributes fail ret = %d,hnd=%p", ret, &hnd);
+ printf("dst handle get Attributes fail ret = %d,hnd=%p", ret, &hnd);
+ return ret;
+ }
+
+ memset(rect, 0, sizeof(rga_rect_t));
+
+ rect->size = dstAttrs.at(ASIZE);
+ rect->width = dstAttrs.at(AWIDTH);
+ rect->height = dstAttrs.at(AHEIGHT);
+ rect->wstride = dstAttrs.at(ASTRIDE);
+ rect->format = dstAttrs.at(AFORMAT);
+
+ return ret;
+}
+
+int NormalRgaGetMmuType(buffer_handle_t hnd, int *mmuType)
+{
+ int ret = 0;
+ std::vector<int> dstAttrs;
+
+ if (!mmuType) {
+ ALOGE("Get rect but mmuType[%p] is null point", mmuType);
+ return -EINVAL;
+ }
+
+ ret = RkRgaGetHandleAttributes(hnd, &dstAttrs);
+ if (ret) {
+ ALOGE("dst handle get Attributes fail ret = %d,hnd=%p", ret, &hnd);
+ printf("dst handle get Attributes fail ret = %d,hnd=%p", ret, &hnd);
+ return ret;
+ }
+
+ if (mmuType && dstAttrs.size() >= 5)
+ *mmuType = dstAttrs.at(ATYPE);
+
+ return ret;
+}
+
+int NormalRgaSetRect(rga_rect_t *rect, int x, int y,
+ int w, int h, int s, int f)
+{
+ if (!rect)
+ return -EINVAL;
+
+ rect->xoffset = x;
+ rect->yoffset = y;
+ rect->width = w;
+ rect->height = h;
+ rect->wstride = s;
+ rect->format = f;
+
+ return 0;
+}
+
+int NormalRgaSetSrcActiveInfo(struct rga_req *req,
+ unsigned int width, unsigned int height,
+ unsigned int x_off, unsigned int y_off)
+{
+ req->src.act_w = width;
+ req->src.act_h = height;
+ req->src.x_offset = x_off;
+ req->src.y_offset = y_off;
+
+ return 1;
+}
+
+int NormalRgaSetFdsOffsets(struct rga_req *req,
+ uint16_t src_fd, uint16_t dst_fd,
+ uint32_t src_offset, uint32_t dst_offset)
+{
+ req->line_draw_info.color = src_fd | (dst_fd << 16);
+ req->line_draw_info.flag = src_offset;
+ req->line_draw_info.line_width = dst_offset;
+ return 0;
+}
+
+#if defined(__arm64__) || defined(__aarch64__)
+int NormalRgaSetSrcVirtualInfo(struct rga_req *req,
+ unsigned long yrgb_addr,unsigned long uv_addr,unsigned long v_addr,
+ unsigned int vir_w ,unsigned int vir_h, unsigned char format,
+ unsigned char a_swap_en)
+#else
+int NormalRgaSetSrcVirtualInfo(struct rga_req *req,
+ unsigned int yrgb_addr, unsigned int uv_addr,unsigned int v_addr,
+ unsigned int vir_w, unsigned int vir_h, unsigned char format,
+ unsigned char a_swap_en)
+#endif
+{
+ req->src.yrgb_addr = yrgb_addr;
+ req->src.uv_addr = uv_addr;
+ req->src.v_addr = v_addr;
+ req->src.vir_w = vir_w;
+ req->src.vir_h = vir_h;
+ req->src.format = format;
+ req->src.alpha_swap |= (a_swap_en & 1);
+
+ return 1;
+}
+
+int NormalRgaSetDstActiveInfo(struct rga_req *req,
+ unsigned int width, unsigned int height,
+ unsigned int x_off, unsigned int y_off)
+{
+ req->dst.act_w = width;
+ req->dst.act_h = height;
+ req->dst.x_offset = x_off;
+ req->dst.y_offset = y_off;
+
+ return 1;
+}
+
+#if defined(__arm64__) || defined(__aarch64__)
+int NormalRgaSetDstVirtualInfo(struct rga_req *msg,
+ unsigned long yrgb_addr,unsigned long uv_addr,unsigned long v_addr,
+ unsigned int vir_w, unsigned int vir_h,
+ RECT *clip, unsigned char format, unsigned char a_swap_en)
+#else
+int NormalRgaSetDstVirtualInfo(struct rga_req *msg,
+ unsigned int yrgb_addr,unsigned int uv_addr, unsigned int v_addr,
+ unsigned int vir_w, unsigned int vir_h,
+ RECT *clip, unsigned char format, unsigned char a_swap_en)
+#endif
+{
+ msg->dst.yrgb_addr = yrgb_addr;
+ msg->dst.uv_addr = uv_addr;
+ msg->dst.v_addr = v_addr;
+ msg->dst.vir_w = vir_w;
+ msg->dst.vir_h = vir_h;
+ msg->dst.format = format;
+
+ msg->clip.xmin = clip->xmin;
+ msg->clip.xmax = clip->xmax;
+ msg->clip.ymin = clip->ymin;
+ msg->clip.ymax = clip->ymax;
+
+ msg->dst.alpha_swap |= (a_swap_en & 1);
+
+ return 1;
+}
+
+int NormalRgaSetPatInfo(struct rga_req *msg,
+ unsigned int width,unsigned int height,unsigned int x_off,
+ unsigned int y_off, unsigned int pat_format)
+{
+ msg->pat.act_w = width;
+ msg->pat.act_h = height;
+ msg->pat.x_offset = x_off;
+ msg->pat.y_offset = y_off;
+
+ msg->pat.format = pat_format;
+
+ return 1;
+}
+
+#if defined(__arm64__) || defined(__aarch64__)
+int NormalRgaSetRopMaskInfo(struct rga_req *msg,
+ unsigned long rop_mask_addr,unsigned int rop_mask_endian_mode)
+#else
+int NormalRgaSetRopMaskInfo(struct rga_req *msg,
+ unsigned int rop_mask_addr,unsigned int rop_mask_endian_mode)
+#endif
+{
+ msg->rop_mask_addr = rop_mask_addr;
+ msg->endian_mode = rop_mask_endian_mode;
+ return 1;
+}
+
+/* 0:alpha' = alpha + (alpha>>7) | alpha' = alpha */
+/* 0 global alpha / 1 per pixel alpha / 2 mix mode */
+
+/* porter duff alpha mode en */
+
+/* use dst alpha */
+
+int NormalRgaSetAlphaEnInfo(struct rga_req *msg,
+ unsigned int alpha_cal_mode, unsigned int alpha_mode,
+ unsigned int global_a_value, unsigned int PD_en,
+ unsigned int PD_mode, unsigned int dst_alpha_en )
+{
+ msg->alpha_rop_flag |= 1;
+ msg->alpha_rop_flag |= ((PD_en & 1) << 3);
+ msg->alpha_rop_flag |= ((alpha_cal_mode & 1) << 4);
+
+ msg->alpha_global_value = global_a_value;
+ msg->alpha_rop_mode |= (alpha_mode & 3);
+ msg->alpha_rop_mode |= (dst_alpha_en << 5);
+
+ msg->PD_mode = PD_mode;
+
+
+ return 1;
+}
+
+
+int NormalRgaSetRopEnInfo(struct rga_req *msg,
+ unsigned int ROP_mode, unsigned int ROP_code,
+ unsigned int color_mode,unsigned int solid_color)
+{
+ msg->alpha_rop_flag |= (0x3);
+ msg->alpha_rop_mode |= ((ROP_mode & 3) << 2);
+
+ msg->rop_code = ROP_code;
+ msg->color_fill_mode = color_mode;
+ msg->fg_color = solid_color;
+ return 1;
+}
+
+int NormalRgaSetFadingEnInfo(struct rga_req *msg,
+ unsigned char r,unsigned char g,unsigned char b)
+{
+ msg->alpha_rop_flag |= (0x1 << 2);
+
+ msg->fading.b = b;
+ msg->fading.g = g;
+ msg->fading.r = r;
+ return 1;
+}
+
+int NormalRgaSetSrcTransModeInfo(struct rga_req *msg,
+ unsigned char trans_mode,unsigned char a_en,unsigned char b_en,
+ unsigned char g_en,unsigned char r_en,unsigned char color_key_min,
+ unsigned char color_key_max,unsigned char zero_mode_en
+ )
+{
+ msg->src_trans_mode = ((a_en & 1) << 4) | ((b_en & 1) << 3) |
+ ((g_en & 1) << 2) | ((r_en & 1) << 1) | (trans_mode & 1);
+
+ msg->color_key_min = color_key_min;
+ msg->color_key_max = color_key_max;
+ msg->alpha_rop_mode |= (zero_mode_en << 4);
+ return 1;
+}
+
+bool NormalRgaIsBppFormat(int format)
+{
+ bool ret = false;
+
+ switch (format) {
+ case RK_FORMAT_BPP1:
+ case RK_FORMAT_BPP2:
+ case RK_FORMAT_BPP4:
+ case RK_FORMAT_BPP8:
+ ret = true;
+ default:
+ break;
+ }
+
+ return ret;
+}
+
+bool NormalRgaIsYuvFormat(int format)
+{
+ bool ret = false;
+
+ switch (format) {
+ case RK_FORMAT_YCbCr_422_SP:
+ case RK_FORMAT_YCbCr_422_P:
+ case RK_FORMAT_YCbCr_420_SP:
+ case RK_FORMAT_YCbCr_420_P:
+ case RK_FORMAT_YCrCb_422_SP:
+ case RK_FORMAT_YCrCb_422_P:
+ case RK_FORMAT_YCrCb_420_SP:
+ case RK_FORMAT_YCrCb_420_P:
+ case RK_FORMAT_YCbCr_420_SP_10B:
+ case RK_FORMAT_YCrCb_420_SP_10B:
+ ret = true;
+ break;
+ }
+
+ return ret;
+}
+
+bool NormalRgaIsRgbFormat(int format)
+{
+ bool ret = false;
+
+ switch (format){
+ case RK_FORMAT_RGBA_8888:
+ case RK_FORMAT_RGBX_8888:
+ case RK_FORMAT_RGB_888:
+ case RK_FORMAT_BGRA_8888:
+ case RK_FORMAT_RGB_565:
+ case RK_FORMAT_RGBA_5551:
+ case RK_FORMAT_RGBA_4444:
+ case RK_FORMAT_BGR_888:
+ ret = true;
+ break;
+ default:
+ break;
+ }
+
+ return ret;
+}
+
+// 0/near 1/bilnear 2/bicubic
+// 0/copy 1/rotate_scale 2/x_mirror 3/y_mirror
+// rotate angle
+// dither en flag
+// AA flag
+int NormalRgaSetBitbltMode(struct rga_req *msg,
+ unsigned char scale_mode, unsigned char rotate_mode,
+ unsigned int angle, unsigned int dither_en,
+ unsigned int AA_en, unsigned int yuv2rgb_mode)
+{
+ unsigned int alpha_mode;
+ msg->render_mode = bitblt_mode;
+
+ msg->scale_mode = scale_mode;
+ msg->rotate_mode = rotate_mode;
+
+ msg->sina = sina_table[angle];
+ msg->cosa = cosa_table[angle];
+
+ msg->yuv2rgb_mode = yuv2rgb_mode;
+
+ msg->alpha_rop_flag |= ((AA_en << 7) & 0x80);
+
+ alpha_mode = msg->alpha_rop_mode & 3;
+ if(rotate_mode == BB_ROTATE)
+ {
+ if (AA_en == ENABLE)
+ {
+ if ((msg->alpha_rop_flag & 0x3) == 0x1)
+ {
+ if (alpha_mode == 0)
+ {
+ msg->alpha_rop_mode = 0x2;
+ }
+ else if (alpha_mode == 1)
+ {
+ msg->alpha_rop_mode = 0x1;
+ }
+ }
+ else
+ {
+ msg->alpha_rop_flag |= 1;
+ msg->alpha_rop_mode = 1;
+ }
+ }
+ }
+
+ if (msg->src_trans_mode)
+ msg->scale_mode = 0;
+
+ msg->alpha_rop_flag |= (dither_en << 5);
+
+ return 0;
+}
+
+/* 1bpp/2bpp/4bpp/8bpp */
+/* src endian mode sel */
+/* BPP1 = 0 */
+/* BPP1 = 1 */
+int NormalRgaSetColorPaletteMode(struct rga_req *msg,
+ unsigned char palette_mode,unsigned char endian_mode,
+ unsigned int bpp1_0_color, unsigned int bpp1_1_color)
+{
+ msg->render_mode = color_palette_mode;
+
+ msg->palette_mode = palette_mode;
+ msg->endian_mode = endian_mode;
+ msg->fg_color = bpp1_0_color;
+ msg->bg_color = bpp1_1_color;
+
+ return 1;
+}
+
+/* gradient color part */
+/* saturation mode */
+/* patten fill or solid fill */
+/* solid color */
+/* pattern width */
+/* pattern height */
+/* pattern x offset */
+/* pattern y offset */
+/* alpha en */
+int NormalRgaSetColorFillMode(
+ struct rga_req *msg, COLOR_FILL *gr_color,
+ unsigned char gr_satur_mode, unsigned char cf_mode,
+ unsigned int color, unsigned short pat_width,
+ unsigned short pat_height, unsigned char pat_x_off,
+ unsigned char pat_y_off, unsigned char aa_en)
+{
+ msg->render_mode = color_fill_mode;
+
+ msg->gr_color.gr_x_a = ((int)(gr_color->gr_x_a * 256.0))& 0xffff;
+ msg->gr_color.gr_x_b = ((int)(gr_color->gr_x_b * 256.0))& 0xffff;
+ msg->gr_color.gr_x_g = ((int)(gr_color->gr_x_g * 256.0))& 0xffff;
+ msg->gr_color.gr_x_r = ((int)(gr_color->gr_x_r * 256.0))& 0xffff;
+
+ msg->gr_color.gr_y_a = ((int)(gr_color->gr_y_a * 256.0))& 0xffff;
+ msg->gr_color.gr_y_b = ((int)(gr_color->gr_y_b * 256.0))& 0xffff;
+ msg->gr_color.gr_y_g = ((int)(gr_color->gr_y_g * 256.0))& 0xffff;
+ msg->gr_color.gr_y_r = ((int)(gr_color->gr_y_r * 256.0))& 0xffff;
+
+ msg->color_fill_mode = cf_mode;
+
+ msg->pat.act_w = pat_width;
+ msg->pat.act_h = pat_height;
+
+ msg->pat.x_offset = pat_x_off;
+ msg->pat.y_offset = pat_y_off;
+
+ msg->fg_color = color;
+
+ msg->alpha_rop_flag |= ((gr_satur_mode & 1) << 6);
+
+ if(aa_en)
+ {
+ msg->alpha_rop_flag |= 0x1;
+ msg->alpha_rop_mode = 1;
+ }
+ return 1;
+}
+
+/* start point */
+/* end point */
+/* line point drawing color */
+/* line width */
+/* AA en */
+/* last point en */
+int NormalRgaSetLineDrawingMode(struct rga_req *msg,
+ POINT sp, POINT ep,
+ unsigned int color, unsigned int line_width,
+ unsigned char AA_en, unsigned char last_point_en)
+
+{
+ msg->render_mode = line_point_drawing_mode;
+
+ msg->line_draw_info.start_point.x = sp.x;
+ msg->line_draw_info.start_point.y = sp.y;
+ msg->line_draw_info.end_point.x = ep.x;
+ msg->line_draw_info.end_point.y = ep.y;
+
+ msg->line_draw_info.color = color;
+ msg->line_draw_info.line_width = line_width;
+ msg->line_draw_info.flag |= (AA_en & 1);
+ msg->line_draw_info.flag |= ((last_point_en & 1) << 1);
+
+ if (AA_en == 1)
+ {
+ msg->alpha_rop_flag = 1;
+ msg->alpha_rop_mode = 0x1;
+ }
+
+ return 1;
+}
+
+/* blur/sharpness */
+/* filter intensity */
+/* dither_en flag */
+
+int NormalRgaSetBlurSharpFilterMode(
+ struct rga_req *msg, unsigned char filter_mode,
+ unsigned char filter_type, unsigned char dither_en)
+{
+ msg->render_mode = blur_sharp_filter_mode;
+
+ msg->bsfilter_flag |= (filter_type & 3);
+ msg->bsfilter_flag |= ((filter_mode & 1) << 2);
+ msg->alpha_rop_flag |= ((dither_en & 1) << 5);
+ return 1;
+}
+
+int NormalRgaSetPreScalingMode(
+ struct rga_req *msg, unsigned char dither_en)
+{
+ msg->render_mode = pre_scaling_mode;
+
+ msg->alpha_rop_flag |= ((dither_en & 1) << 5);
+ return 1;
+}
+
+/* LUT table addr */
+/* 1bpp/2bpp/4bpp/8bpp */
+#if defined(__arm64__) || defined(__aarch64__)
+int NormalRgaUpdatePaletteTableMode(
+ struct rga_req *msg,unsigned long LUT_addr,unsigned int palette_mode)
+#else
+int NormalRgaUpdatePaletteTableMode(
+ struct rga_req *msg,unsigned int LUT_addr, unsigned int palette_mode)
+#endif
+{
+ msg->render_mode = update_palette_table_mode;
+
+ msg->LUT_addr = LUT_addr;
+ msg->palette_mode = palette_mode;
+ return 1;
+}
+
+/* patten addr */
+/* patten width */
+/* patten height */
+/* patten format */
+
+int NormalRgaUpdatePattenBuffMode(struct rga_req *msg,
+ unsigned int pat_addr, unsigned int w,
+ unsigned int h, unsigned int format)
+{
+ msg->render_mode = update_patten_buff_mode;
+
+ msg->pat.yrgb_addr = pat_addr;
+ msg->pat.act_w = w*h; // hxx
+ msg->pat.act_h = 1; // hxx
+ msg->pat.format = format;
+ return 1;
+}
+
+#if defined(__arm64__) || defined(__aarch64__)
+int NormalRgaMmuInfo(struct rga_req *msg,
+ unsigned char mmu_en, unsigned char src_flush,
+ unsigned char dst_flush,unsigned char cmd_flush,
+ unsigned long base_addr, unsigned char page_size)
+#else
+int NormalRgaMmuInfo(struct rga_req *msg,
+ unsigned char mmu_en, unsigned char src_flush,
+ unsigned char dst_flush,unsigned char cmd_flush,
+ unsigned int base_addr, unsigned char page_size)
+#endif
+{
+ msg->mmu_info.mmu_en = mmu_en;
+ msg->mmu_info.base_addr = base_addr;
+ msg->mmu_info.mmu_flag = ((page_size & 0x3) << 4) |
+ ((cmd_flush & 0x1) << 3) |
+ ((dst_flush & 0x1) << 2) |
+ ((src_flush & 0x1) << 1) | mmu_en;
+ return 1;
+}
+
+int NormalRgaMmuFlag(struct rga_req *msg,
+ int src_mmu_en, int dst_mmu_en)
+{
+ if (src_mmu_en || dst_mmu_en)
+ msg->mmu_info.mmu_flag |= (0x1 << 31);
+
+ if (src_mmu_en)
+ msg->mmu_info.mmu_flag |= (0x1 << 8);
+
+ if (dst_mmu_en)
+ msg->mmu_info.mmu_flag |= (0x1 << 10);
+
+ return 1;
+}
+
+int NormalRgaInitTables()
+{
+ int sinaTable[360] = {
+ 0, 1144, 2287, 3430, 4572, 5712, 6850, 7987, 9121, 10252,
+ 11380, 12505, 13626, 14742, 15855, 16962, 18064, 19161, 20252, 21336,
+ 22415, 23486, 24550, 25607, 26656, 27697, 28729, 29753, 30767, 31772,
+ 32768, 33754, 34729, 35693, 36647, 37590, 38521, 39441, 40348, 41243,
+ 42126, 42995, 43852, 44695, 45525, 46341, 47143, 47930, 48703, 49461,
+ 50203, 50931, 51643, 52339, 53020, 53684, 54332, 54963, 55578, 56175,
+ 56756, 57319, 57865, 58393, 58903, 59396, 59870, 60326, 60764, 61183,
+ 61584, 61966, 62328, 62672, 62997, 63303, 63589, 63856, 64104, 64332,
+ 64540, 64729, 64898, 65048, 65177, 65287, 65376, 65446, 65496, 65526,
+ 65536, 65526, 65496, 65446, 65376, 65287, 65177, 65048, 64898, 64729,
+ 64540, 64332, 64104, 63856, 63589, 63303, 62997, 62672, 62328, 61966,
+ 61584, 61183, 60764, 60326, 59870, 59396, 58903, 58393, 57865, 57319,
+ 56756, 56175, 55578, 54963, 54332, 53684, 53020, 52339, 51643, 50931,
+ 50203, 49461, 48703, 47930, 47143, 46341, 45525, 44695, 43852, 42995,
+ 42126, 41243, 40348, 39441, 38521, 37590, 36647, 35693, 34729, 33754,
+ 32768, 31772, 30767, 29753, 28729, 27697, 26656, 25607, 24550, 23486,
+ 22415, 21336, 20252, 19161, 18064, 16962, 15855, 14742, 13626, 12505,
+ 11380, 10252, 9121, 7987, 6850, 5712, 4572, 3430, 2287, 1144,
+ 0, -1144, -2287, -3430, -4572, -5712, -6850, -7987, -9121, -10252,
+ -11380, -12505, -13626, -14742, -15855, -16962, -18064, -19161, -20252, -21336,
+ -22415, -23486, -24550, -25607, -26656, -27697, -28729, -29753, -30767, -31772,
+ -32768, -33754, -34729, -35693, -36647, -37590, -38521, -39441, -40348, -41243,
+ -42126, -42995, -43852, -44695, -45525, -46341, -47143, -47930, -48703, -49461,
+ -50203, -50931, -51643, -52339, -53020, -53684, -54332, -54963, -55578, -56175,
+ -56756, -57319, -57865, -58393, -58903, -59396, -59870, -60326, -60764, -61183,
+ -61584, -61966, -62328, -62672, -62997, -63303, -63589, -63856, -64104, -64332,
+ -64540, -64729, -64898, -65048, -65177, -65287, -65376, -65446, -65496, -65526,
+ -65536, -65526, -65496, -65446, -65376, -65287, -65177, -65048, -64898, -64729,
+ -64540, -64332, -64104, -63856, -63589, -63303, -62997, -62672, -62328, -61966,
+ -61584, -61183, -60764, -60326, -59870, -59396, -58903, -58393, -57865, -57319,
+ -56756, -56175, -55578, -54963, -54332, -53684, -53020, -52339, -51643, -50931,
+ -50203, -49461, -48703, -47930, -47143, -46341, -45525, -44695, -43852, -42995,
+ -42126, -41243, -40348, -39441, -38521, -37590, -36647, -35693, -34729, -33754,
+ -32768, -31772, -30767, -29753, -28729, -27697, -26656, -25607, -24550, -23486,
+ -22415, -21336, -20252, -19161, -18064, -16962, -15855, -14742, -13626, -12505,
+ -11380, -10252, -9121, -7987, -6850, -5712, -4572, -3430, -2287, -1144
+ };
+ int cosaTable[360] = {
+ 65536, 65526, 65496, 65446, 65376, 65287, 65177, 65048, 64898, 64729,
+ 64540, 64332, 64104, 63856, 63589, 63303, 62997, 62672, 62328, 61966,
+ 61584, 61183, 60764, 60326, 59870, 59396, 58903, 58393, 57865, 57319,
+ 56756, 56175, 55578, 54963, 54332, 53684, 53020, 52339, 51643, 50931,
+ 50203, 49461, 48703, 47930, 47143, 46341, 45525, 44695, 43852, 42995,
+ 42126, 41243, 40348, 39441, 38521, 37590, 36647, 35693, 34729, 33754,
+ 32768, 31772, 30767, 29753, 28729, 27697, 26656, 25607, 24550, 23486,
+ 22415, 21336, 20252, 19161, 18064, 16962, 15855, 14742, 13626, 12505,
+ 11380, 10252, 9121, 7987, 6850, 5712, 4572, 3430, 2287, 1144,
+ 0, -1144, -2287, -3430, -4572, -5712, -6850, -7987, -9121, -10252,
+ -11380, -12505, -13626, -14742, -15855, -16962, -18064, -19161, -20252, -21336,
+ -22415, -23486, -24550, -25607, -26656, -27697, -28729, -29753, -30767, -31772,
+ -32768, -33754, -34729, -35693, -36647, -37590, -38521, -39441, -40348, -41243,
+ -42126, -42995, -43852, -44695, -45525, -46341, -47143, -47930, -48703, -49461,
+ -50203, -50931, -51643, -52339, -53020, -53684, -54332, -54963, -55578, -56175,
+ -56756, -57319, -57865, -58393, -58903, -59396, -59870, -60326, -60764, -61183,
+ -61584, -61966, -62328, -62672, -62997, -63303, -63589, -63856, -64104, -64332,
+ -64540, -64729, -64898, -65048, -65177, -65287, -65376, -65446, -65496, -65526,
+ -65536, -65526, -65496, -65446, -65376, -65287, -65177, -65048, -64898, -64729,
+ -64540, -64332, -64104, -63856, -63589, -63303, -62997, -62672, -62328, -61966,
+ -61584, -61183, -60764, -60326, -59870, -59396, -58903, -58393, -57865, -57319,
+ -56756, -56175, -55578, -54963, -54332, -53684, -53020, -52339, -51643, -50931,
+ -50203, -49461, -48703, -47930, -47143, -46341, -45525, -44695, -43852, -42995,
+ -42126, -41243, -40348, -39441, -38521, -37590, -36647, -35693, -34729, -33754,
+ -32768, -31772, -30767, -29753, -28729, -27697, -26656, -25607, -24550, -23486,
+ -22415, -21336, -20252, -19161, -18064, -16962, -15855, -14742, -13626, -12505,
+ -11380, -10252, -9121, -7987, -6850, -5712, -4572, -3430, -2287, -1144,
+ 0, 1144, 2287, 3430, 4572, 5712, 6850, 7987, 9121, 10252,
+ 11380, 12505, 13626, 14742, 15855, 16962, 18064, 19161, 20252, 21336,
+ 22415, 23486, 24550, 25607, 26656, 27697, 28729, 29753, 30767, 31772,
+ 32768, 33754, 34729, 35693, 36647, 37590, 38521, 39441, 40348, 41243,
+ 42126, 42995, 43852, 44695, 45525, 46341, 47143, 47930, 48703, 49461,
+ 50203, 50931, 51643, 52339, 53020, 53684, 54332, 54963, 55578, 56175,
+ 56756, 57319, 57865, 58393, 58903, 59396, 59870, 60326, 60764, 61183,
+ 61584, 61966, 62328, 62672, 62997, 63303, 63589, 63856, 64104, 64332,
+ 64540, 64729, 64898, 65048, 65177, 65287, 65376, 65446, 65496, 65526
+ };
+ memcpy(sina_table, sinaTable, sizeof(sina_table));
+ memcpy(cosa_table, cosaTable, sizeof(cosa_table));
+ return 0;
+}
+
+void NormalRgaLogOutRgaReq(struct rga_req rgaReg)
+{
+#if defined(__arm64__) || defined(__aarch64__)
+ ALOGD("render_mode=%d rotate_mode=%d\n",
+ rgaReg.render_mode, rgaReg.rotate_mode);
+ ALOGD("src:[%lx,%lx,%lx],x-y[%d,%d],w-h[%d,%d],vw-vh[%d,%d],f=%d",
+ rgaReg.src.yrgb_addr, rgaReg.src.uv_addr, rgaReg.src.v_addr,
+ rgaReg.src.x_offset, rgaReg.src.y_offset,
+ rgaReg.src.act_w, rgaReg.src.act_h,
+ rgaReg.src.vir_w, rgaReg.src.vir_h, rgaReg.src.format);
+ ALOGD("dst:[%lx,%lx,%lx],x-y[%d,%d],w-h[%d,%d],vw-vh[%d,%d],f=%d",
+ rgaReg.dst.yrgb_addr, rgaReg.dst.uv_addr, rgaReg.dst.v_addr,
+ rgaReg.dst.x_offset, rgaReg.dst.y_offset,
+ rgaReg.dst.act_w, rgaReg.dst.act_h,
+ rgaReg.dst.vir_w, rgaReg.dst.vir_h, rgaReg.dst.format);
+ ALOGD("pat:[%lx,%lx,%lx],x-y[%d,%d],w-h[%d,%d],vw-vh[%d,%d],f=%d",
+ rgaReg.pat.yrgb_addr, rgaReg.pat.uv_addr, rgaReg.pat.v_addr,
+ rgaReg.pat.x_offset, rgaReg.pat.y_offset,
+ rgaReg.pat.act_w, rgaReg.pat.act_h,
+ rgaReg.pat.vir_w, rgaReg.pat.vir_h, rgaReg.pat.format);
+ ALOGD("ROP:[%lx,%x,%x],LUT[%lx]", rgaReg.rop_mask_addr, rgaReg.alpha_rop_flag,
+ rgaReg.rop_code, rgaReg.LUT_addr);
+
+ ALOGD("color:[%x,%x,%x,%x,%x]", rgaReg.color_key_max, rgaReg.color_key_min,
+ rgaReg.fg_color, rgaReg.bg_color, rgaReg.color_fill_mode);
+
+ ALOGD("MMU:[%d,%lx,%x]", rgaReg.mmu_info.mmu_en,
+ rgaReg.mmu_info.base_addr, rgaReg.mmu_info.mmu_flag);
+
+
+ ALOGD("mode[%d,%d,%d,%d]", rgaReg.palette_mode, rgaReg.yuv2rgb_mode,
+ rgaReg.endian_mode, rgaReg.src_trans_mode);
+#else
+ ALOGD("render_mode=%d rotate_mode=%d\n",
+ rgaReg.render_mode, rgaReg.rotate_mode);
+ ALOGD("src:[%x,%x,%x],x-y[%d,%d],w-h[%d,%d],vw-vh[%d,%d],f=%d",
+ rgaReg.src.yrgb_addr, rgaReg.src.uv_addr, rgaReg.src.v_addr,
+ rgaReg.src.x_offset, rgaReg.src.y_offset,
+ rgaReg.src.act_w, rgaReg.src.act_h,
+ rgaReg.src.vir_w, rgaReg.src.vir_h, rgaReg.src.format);
+ ALOGD("dst:[%x,%x,%x],x-y[%d,%d],w-h[%d,%d],vw-vh[%d,%d],f=%d",
+ rgaReg.dst.yrgb_addr, rgaReg.dst.uv_addr, rgaReg.dst.v_addr,
+ rgaReg.dst.x_offset, rgaReg.dst.y_offset,
+ rgaReg.dst.act_w, rgaReg.dst.act_h,
+ rgaReg.dst.vir_w, rgaReg.dst.vir_h, rgaReg.dst.format);
+ ALOGD("pat:[%x,%x,%x],x-y[%d,%d],w-h[%d,%d],vw-vh[%d,%d],f=%d",
+ rgaReg.pat.yrgb_addr, rgaReg.pat.uv_addr, rgaReg.pat.v_addr,
+ rgaReg.pat.x_offset, rgaReg.pat.y_offset,
+ rgaReg.pat.act_w, rgaReg.pat.act_h,
+ rgaReg.pat.vir_w, rgaReg.pat.vir_h, rgaReg.pat.format);
+ ALOGD("ROP:[%x,%x,%x],LUT[%x]", rgaReg.rop_mask_addr, rgaReg.alpha_rop_flag,
+ rgaReg.rop_code, rgaReg.LUT_addr);
+
+ ALOGD("color:[%x,%x,%x,%x,%x]", rgaReg.color_key_max, rgaReg.color_key_min,
+ rgaReg.fg_color, rgaReg.bg_color, rgaReg.color_fill_mode);
+
+ ALOGD("MMU:[%d,%x,%x]", rgaReg.mmu_info.mmu_en,
+ rgaReg.mmu_info.base_addr, rgaReg.mmu_info.mmu_flag);
+
+
+ ALOGD("mode[%d,%d,%d,%d]", rgaReg.palette_mode, rgaReg.yuv2rgb_mode,
+ rgaReg.endian_mode, rgaReg.src_trans_mode);
+#endif
+ return;
+}
diff --git a/normal/NormalRgaContext.h b/normal/NormalRgaContext.h
new file mode 100644
index 0000000..fbd90d8
--- /dev/null
+++ b/normal/NormalRgaContext.h
@@ -0,0 +1,23 @@
+/*
+ * Copyright (C) 2016 Rockchip Electronics Co.Ltd
+ * Authors:
+ * Zhiqin Wei <wzq@rock-chips.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ */
+
+#ifndef _rockchip_normal_rga_context_h_
+#define _rockchip_normal_rga_context_h_
+#define UNUSED(...) (void)(__VA_ARGS__)
+
+struct rgaContext{
+ int rgaFd;
+ int mLogAlways;
+ int mLogOnce;
+ float mVersion;
+};
+#endif \ No newline at end of file
diff --git a/normal/gralloc_rga.h b/normal/gralloc_rga.h
new file mode 100644
index 0000000..2d5e581
--- /dev/null
+++ b/normal/gralloc_rga.h
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2016 Rockchip Electronics Co.Ltd
+ * Authors:
+ * Zhiqin Wei <wzq@rock-chips.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ */
+
+#ifndef _rockchip_rga_drm_gralloc_h_
+#define _rockchip_rga_drm_gralloc_h_
+
+#ifndef RK3368
+#include <gralloc_priv.h>
+
+#else
+#include <hardware/img_gralloc_public.h>
+#ifndef GRALLOC_MODULE_PERFORM_GET_HADNLE_PRIME_FD
+#define GRALLOC_MODULE_PERFORM_GET_HADNLE_PRIME_FD 0x81000002
+#endif
+
+#ifndef GRALLOC_MODULE_PERFORM_GET_HADNLE_ATTRIBUTES
+#define GRALLOC_MODULE_PERFORM_GET_HADNLE_ATTRIBUTES 0x81000004
+#endif
+
+#ifndef GRALLOC_MODULE_PERFORM_GET_INTERNAL_FORMAT
+#define GRALLOC_MODULE_PERFORM_GET_INTERNAL_FORMAT 0x81000006
+#endif
+
+#ifndef GRALLOC_MODULE_PERFORM_GET_USAGE
+#define GRALLOC_MODULE_PERFORM_GET_USAGE 0xffeeff03
+#endif
+#endif
+
+#endif
+
diff --git a/tests/Android.mk b/tests/Android.mk
new file mode 100644
index 0000000..eecf718
--- /dev/null
+++ b/tests/Android.mk
@@ -0,0 +1,592 @@
+LOCAL_PATH:= $(call my-dir)
+#======================================================================
+#
+#rgargb565toyuv
+#
+#======================================================================
+include $(CLEAR_VARS)
+
+LOCAL_CFLAGS += -DGL_GLEXT_PROTOTYPES -DEGL_EGLEXT_PROTOTYPES
+
+LOCAL_CFLAGS += -DROCKCHIP_GPU_LIB_ENABLE
+
+LOCAL_CFLAGS += -Wall -Werror -Wunreachable-code
+
+LOCAL_C_INCLUDES += external/tinyalsa/include
+
+LOCAL_C_INCLUDES += hardware/rockchip/librga
+LOCAL_C_INCLUDES += hardware/rk29/librga
+
+LOCAL_SHARED_LIBRARIES := \
+ libcutils \
+ liblog \
+ libutils \
+ libbinder \
+ libui \
+ libEGL \
+ libGLESv1_CM \
+ libgui \
+ libhardware \
+ librga
+
+#has no "external/stlport" from Android 6.0 on
+ifeq (1,$(strip $(shell expr $(PLATFORM_VERSION) \< 6.0)))
+LOCAL_C_INCLUDES += \
+ external/stlport/stlport
+
+LOCAL_SHARED_LIBRARIES += \
+ libstlport
+
+LOCAL_C_INCLUDES += bionic
+endif
+
+LOCAL_SRC_FILES:= \
+ RockchipFileOps.cpp \
+ RockchipRgaCovertRgb565ToYuv.cpp
+
+LOCAL_MODULE:= rgargb565toyuv
+
+ifdef TARGET_32_BIT_SURFACEFLINGER
+LOCAL_32_BIT_ONLY := true
+endif
+
+include $(BUILD_EXECUTABLE)
+
+#======================================================================
+#
+#rgargbatoyuv
+#
+#======================================================================
+include $(CLEAR_VARS)
+
+LOCAL_CFLAGS += -DGL_GLEXT_PROTOTYPES -DEGL_EGLEXT_PROTOTYPES
+
+LOCAL_CFLAGS += -DROCKCHIP_GPU_LIB_ENABLE
+
+LOCAL_CFLAGS += -Wall -Werror -Wunreachable-code
+
+LOCAL_C_INCLUDES += external/tinyalsa/include
+
+LOCAL_C_INCLUDES += hardware/rockchip/librga
+LOCAL_C_INCLUDES += hardware/rk29/librga
+
+LOCAL_SHARED_LIBRARIES := \
+ libcutils \
+ liblog \
+ libutils \
+ libbinder \
+ libui \
+ libEGL \
+ libGLESv1_CM \
+ libgui \
+ libhardware \
+ librga
+
+#has no "external/stlport" from Android 6.0 on
+ifeq (1,$(strip $(shell expr $(PLATFORM_VERSION) \< 6.0)))
+LOCAL_C_INCLUDES += \
+ external/stlport/stlport
+
+LOCAL_SHARED_LIBRARIES += \
+ libstlport
+
+LOCAL_C_INCLUDES += bionic
+endif
+
+LOCAL_SRC_FILES:= \
+ RockchipFileOps.cpp \
+ RockchipRgaCovertRgbaToYuv.cpp
+
+LOCAL_MODULE:= rgargbatoyuv
+
+ifdef TARGET_32_BIT_SURFACEFLINGER
+LOCAL_32_BIT_ONLY := true
+endif
+
+include $(BUILD_EXECUTABLE)
+
+#======================================================================
+#
+#rgacopy
+#
+#======================================================================
+include $(CLEAR_VARS)
+
+LOCAL_CFLAGS += -DGL_GLEXT_PROTOTYPES -DEGL_EGLEXT_PROTOTYPES
+
+LOCAL_CFLAGS += -DROCKCHIP_GPU_LIB_ENABLE
+
+LOCAL_CFLAGS += -Wall -Werror -Wunreachable-code
+
+LOCAL_C_INCLUDES += external/tinyalsa/include
+
+LOCAL_C_INCLUDES += hardware/rockchip/librga
+LOCAL_C_INCLUDES += hardware/rk29/librga
+
+LOCAL_SHARED_LIBRARIES := \
+ libcutils \
+ liblog \
+ libutils \
+ libbinder \
+ libui \
+ libEGL \
+ libGLESv1_CM \
+ libgui \
+ libhardware \
+ librga
+
+#has no "external/stlport" from Android 6.0 on
+ifeq (1,$(strip $(shell expr $(PLATFORM_VERSION) \< 6.0)))
+LOCAL_C_INCLUDES += \
+ external/stlport/stlport
+
+LOCAL_SHARED_LIBRARIES += \
+ libstlport
+
+LOCAL_C_INCLUDES += bionic
+endif
+
+LOCAL_SRC_FILES:= \
+ RockchipFileOps.cpp \
+ RockchipRgaCopy.cpp
+
+LOCAL_MODULE:= rgacopy
+
+ifdef TARGET_32_BIT_SURFACEFLINGER
+LOCAL_32_BIT_ONLY := true
+endif
+
+include $(BUILD_EXECUTABLE)
+
+
+#======================================================================
+#
+#rgacopyrgba
+#
+#======================================================================
+include $(CLEAR_VARS)
+
+LOCAL_CFLAGS += -DGL_GLEXT_PROTOTYPES -DEGL_EGLEXT_PROTOTYPES
+
+LOCAL_CFLAGS += -DROCKCHIP_GPU_LIB_ENABLE
+
+LOCAL_CFLAGS += -Wall -Werror -Wunreachable-code
+
+LOCAL_C_INCLUDES += external/tinyalsa/include
+
+LOCAL_C_INCLUDES += hardware/rockchip/librga
+LOCAL_C_INCLUDES += hardware/rk29/librga
+
+LOCAL_SHARED_LIBRARIES := \
+ libcutils \
+ liblog \
+ libutils \
+ libbinder \
+ libui \
+ libEGL \
+ libGLESv1_CM \
+ libgui \
+ libhardware \
+ librga
+
+#has no "external/stlport" from Android 6.0 on
+ifeq (1,$(strip $(shell expr $(PLATFORM_VERSION) \< 6.0)))
+LOCAL_C_INCLUDES += \
+ external/stlport/stlport
+
+LOCAL_SHARED_LIBRARIES += \
+ libstlport
+
+LOCAL_C_INCLUDES += bionic
+endif
+
+LOCAL_SRC_FILES:= \
+ RockchipFileOps.cpp \
+ RockchipRgaCopyRgba.cpp
+
+LOCAL_MODULE:= rgacopyrgba
+
+ifdef TARGET_32_BIT_SURFACEFLINGER
+LOCAL_32_BIT_ONLY := true
+endif
+
+include $(BUILD_EXECUTABLE)
+
+
+#======================================================================
+#
+#rgacoveryuvtorgba
+#
+#======================================================================
+include $(CLEAR_VARS)
+
+LOCAL_CFLAGS += -DGL_GLEXT_PROTOTYPES -DEGL_EGLEXT_PROTOTYPES
+
+LOCAL_CFLAGS += -DROCKCHIP_GPU_LIB_ENABLE
+
+LOCAL_CFLAGS += -Wall -Werror -Wunreachable-code
+
+LOCAL_C_INCLUDES += external/tinyalsa/include
+
+LOCAL_C_INCLUDES += hardware/rockchip/librga
+LOCAL_C_INCLUDES += hardware/rk29/librga
+
+LOCAL_SHARED_LIBRARIES := \
+ libcutils \
+ liblog \
+ libutils \
+ libbinder \
+ libui \
+ libEGL \
+ libGLESv1_CM \
+ libgui \
+ libhardware \
+ librga
+
+#has no "external/stlport" from Android 6.0 on
+ifeq (1,$(strip $(shell expr $(PLATFORM_VERSION) \< 6.0)))
+LOCAL_C_INCLUDES += \
+ external/stlport/stlport
+
+LOCAL_SHARED_LIBRARIES += \
+ libstlport
+
+LOCAL_C_INCLUDES += bionic
+endif
+
+LOCAL_SRC_FILES:= \
+ RockchipFileOps.cpp \
+ RockchipRgaCovertYuvToRgba.cpp
+
+LOCAL_MODULE:= rgacoveryuvtorgba
+
+ifdef TARGET_32_BIT_SURFACEFLINGER
+LOCAL_32_BIT_ONLY := true
+endif
+
+include $(BUILD_EXECUTABLE)
+
+
+#======================================================================
+#
+#rgargbamirror
+#
+#======================================================================
+include $(CLEAR_VARS)
+
+LOCAL_CFLAGS += -DGL_GLEXT_PROTOTYPES -DEGL_EGLEXT_PROTOTYPES
+
+LOCAL_CFLAGS += -DROCKCHIP_GPU_LIB_ENABLE
+
+LOCAL_CFLAGS += -Wall -Werror -Wunreachable-code
+
+LOCAL_C_INCLUDES += external/tinyalsa/include
+
+LOCAL_C_INCLUDES += hardware/rockchip/librga
+LOCAL_C_INCLUDES += hardware/rk29/librga
+
+LOCAL_SHARED_LIBRARIES := \
+ libcutils \
+ liblog \
+ libutils \
+ libbinder \
+ libui \
+ libEGL \
+ libGLESv1_CM \
+ libgui \
+ libhardware \
+ librga
+
+#has no "external/stlport" from Android 6.0 on
+ifeq (1,$(strip $(shell expr $(PLATFORM_VERSION) \< 6.0)))
+LOCAL_C_INCLUDES += \
+ external/stlport/stlport
+
+LOCAL_SHARED_LIBRARIES += \
+ libstlport
+
+LOCAL_C_INCLUDES += bionic
+endif
+
+LOCAL_SRC_FILES:= \
+ RockchipFileOps.cpp \
+ RockchipRgaRgbaMirror.cpp
+
+LOCAL_MODULE:= rgargbamirror
+
+ifdef TARGET_32_BIT_SURFACEFLINGER
+LOCAL_32_BIT_ONLY := true
+endif
+
+include $(BUILD_EXECUTABLE)
+
+
+#======================================================================
+#
+#rgablit
+#
+#======================================================================
+include $(CLEAR_VARS)
+
+LOCAL_CFLAGS += -DGL_GLEXT_PROTOTYPES -DEGL_EGLEXT_PROTOTYPES
+
+LOCAL_CFLAGS += -DROCKCHIP_GPU_LIB_ENABLE
+
+LOCAL_CFLAGS += -Wall -Werror -Wunreachable-code
+
+LOCAL_C_INCLUDES += external/tinyalsa/include
+
+LOCAL_C_INCLUDES += hardware/rockchip/librga
+LOCAL_C_INCLUDES += hardware/rk29/librga
+
+LOCAL_SHARED_LIBRARIES := \
+ libcutils \
+ liblog \
+ libutils \
+ libbinder \
+ libui \
+ libEGL \
+ libGLESv1_CM \
+ libgui \
+ libhardware \
+ librga
+
+#has no "external/stlport" from Android 6.0 on
+ifeq (1,$(strip $(shell expr $(PLATFORM_VERSION) \< 6.0)))
+LOCAL_C_INCLUDES += \
+ external/stlport/stlport
+
+LOCAL_SHARED_LIBRARIES += \
+ libstlport
+
+LOCAL_C_INCLUDES += bionic
+endif
+
+LOCAL_SRC_FILES:= \
+ RockchipFileOps.cpp \
+ RockchipRgaBlit.cpp
+
+LOCAL_MODULE:= rgablit
+
+ifdef TARGET_32_BIT_SURFACEFLINGER
+LOCAL_32_BIT_ONLY := true
+endif
+
+include $(BUILD_EXECUTABLE)
+
+#======================================================================
+#
+#rgauserstereo
+#
+#======================================================================
+include $(CLEAR_VARS)
+
+LOCAL_CFLAGS += -DGL_GLEXT_PROTOTYPES -DEGL_EGLEXT_PROTOTYPES
+
+LOCAL_CFLAGS += -DROCKCHIP_GPU_LIB_ENABLE
+
+LOCAL_CFLAGS += -Wall -Werror -Wunreachable-code
+
+LOCAL_C_INCLUDES += external/tinyalsa/include
+
+LOCAL_C_INCLUDES += hardware/rockchip/librga
+LOCAL_C_INCLUDES += hardware/rk29/librga
+
+LOCAL_SHARED_LIBRARIES := \
+ libcutils \
+ liblog \
+ libutils \
+ libbinder \
+ libui \
+ libEGL \
+ libGLESv1_CM \
+ libgui \
+ libhardware \
+ librga
+
+#has no "external/stlport" from Android 6.0 on
+ifeq (1,$(strip $(shell expr $(PLATFORM_VERSION) \< 6.0)))
+LOCAL_C_INCLUDES += \
+ external/stlport/stlport
+
+LOCAL_SHARED_LIBRARIES += \
+ libstlport
+
+LOCAL_C_INCLUDES += bionic
+endif
+
+LOCAL_SRC_FILES:= \
+ RockchipFileOps.cpp \
+ RockchipRgaStereoUserSpace.cpp
+
+LOCAL_MODULE:= rgauserstereo
+
+ifdef TARGET_32_BIT_SURFACEFLINGER
+LOCAL_32_BIT_ONLY := true
+endif
+
+include $(BUILD_EXECUTABLE)
+
+
+#======================================================================
+#
+#rgauserblit
+#
+#======================================================================
+include $(CLEAR_VARS)
+
+LOCAL_CFLAGS += -DGL_GLEXT_PROTOTYPES -DEGL_EGLEXT_PROTOTYPES
+
+LOCAL_CFLAGS += -DROCKCHIP_GPU_LIB_ENABLE
+
+LOCAL_CFLAGS += -Wall -Werror -Wunreachable-code
+
+LOCAL_C_INCLUDES += external/tinyalsa/include
+
+LOCAL_C_INCLUDES += hardware/rockchip/librga
+LOCAL_C_INCLUDES += hardware/rk29/librga
+
+LOCAL_SHARED_LIBRARIES := \
+ libcutils \
+ liblog \
+ libutils \
+ libbinder \
+ libui \
+ libEGL \
+ libGLESv1_CM \
+ libgui \
+ libhardware \
+ librga
+
+#has no "external/stlport" from Android 6.0 on
+ifeq (1,$(strip $(shell expr $(PLATFORM_VERSION) \< 6.0)))
+LOCAL_C_INCLUDES += \
+ external/stlport/stlport
+
+LOCAL_SHARED_LIBRARIES += \
+ libstlport
+
+LOCAL_C_INCLUDES += bionic
+endif
+
+LOCAL_SRC_FILES:= \
+ RockchipFileOps.cpp \
+ RockchipRgaBlitUserSpace.cpp
+
+LOCAL_MODULE:= rgauserblit
+
+ifdef TARGET_32_BIT_SURFACEFLINGER
+LOCAL_32_BIT_ONLY := true
+endif
+
+include $(BUILD_EXECUTABLE)
+
+
+#======================================================================
+#
+#rgapalettetable
+#
+#======================================================================
+include $(CLEAR_VARS)
+
+LOCAL_CFLAGS += -DGL_GLEXT_PROTOTYPES -DEGL_EGLEXT_PROTOTYPES
+
+LOCAL_CFLAGS += -DROCKCHIP_GPU_LIB_ENABLE
+
+LOCAL_CFLAGS += -Wall -Werror -Wunreachable-code
+
+LOCAL_C_INCLUDES += external/tinyalsa/include
+
+LOCAL_C_INCLUDES += hardware/rockchip/librga
+LOCAL_C_INCLUDES += hardware/rk29/librga
+
+LOCAL_SHARED_LIBRARIES := \
+ libcutils \
+ liblog \
+ libutils \
+ libbinder \
+ libui \
+ libEGL \
+ libGLESv1_CM \
+ libgui \
+ libhardware \
+ librga
+
+#has no "external/stlport" from Android 6.0 on
+ifeq (1,$(strip $(shell expr $(PLATFORM_VERSION) \< 6.0)))
+LOCAL_C_INCLUDES += \
+ external/stlport/stlport
+
+LOCAL_SHARED_LIBRARIES += \
+ libstlport
+
+LOCAL_C_INCLUDES += bionic
+endif
+
+LOCAL_SRC_FILES:= \
+ RockchipFileOps.cpp \
+ RockchipRgaPattenBuff.cpp
+
+LOCAL_MODULE:= rgapattenbuff
+
+ifdef TARGET_32_BIT_SURFACEFLINGER
+LOCAL_32_BIT_ONLY := true
+endif
+
+include $(BUILD_EXECUTABLE)
+
+#======================================================================
+#
+#rgablitslt
+#
+#======================================================================
+include $(CLEAR_VARS)
+
+LOCAL_CFLAGS += -DGL_GLEXT_PROTOTYPES -DEGL_EGLEXT_PROTOTYPES
+
+LOCAL_CFLAGS += -DROCKCHIP_GPU_LIB_ENABLE
+
+LOCAL_CFLAGS += -Wall -Werror -Wunreachable-code
+
+LOCAL_C_INCLUDES += external/tinyalsa/include
+
+LOCAL_C_INCLUDES += hardware/rockchip/librga
+LOCAL_C_INCLUDES += hardware/rk29/librga
+
+LOCAL_SHARED_LIBRARIES := \
+ libcutils \
+ liblog \
+ libutils \
+ libbinder \
+ libui \
+ libEGL \
+ libGLESv1_CM \
+ libgui \
+ libhardware \
+ librga
+
+#has no "external/stlport" from Android 6.0 on
+ifeq (1,$(strip $(shell expr $(PLATFORM_VERSION) \< 6.0)))
+LOCAL_C_INCLUDES += \
+ external/stlport/stlport
+
+LOCAL_SHARED_LIBRARIES += \
+ libstlport
+
+LOCAL_C_INCLUDES += bionic
+endif
+
+LOCAL_SRC_FILES:= \
+ RockchipFileOps.cpp \
+ RockchipRgaBlitSlt.cpp
+
+LOCAL_MODULE:= rgablitslt
+
+ifdef TARGET_32_BIT_SURFACEFLINGER
+LOCAL_32_BIT_ONLY := true
+endif
+
+include $(BUILD_EXECUTABLE)
+
+#======================================================================
+#
diff --git a/tests/RockchipFileOps.cpp b/tests/RockchipFileOps.cpp
new file mode 100644
index 0000000..518cde4
--- /dev/null
+++ b/tests/RockchipFileOps.cpp
@@ -0,0 +1,221 @@
+#include <stdint.h>
+#include <sys/types.h>
+#include <math.h>
+#include <fcntl.h>
+#include <utils/misc.h>
+#include <signal.h>
+#include <time.h>
+
+#include <cutils/properties.h>
+
+#include <binder/IPCThreadState.h>
+#include <utils/Atomic.h>
+#include <utils/Errors.h>
+#include <utils/Log.h>
+
+#include <ui/PixelFormat.h>
+#include <ui/Rect.h>
+#include <ui/Region.h>
+#include <ui/DisplayInfo.h>
+#include <ui/GraphicBufferMapper.h>
+#include <RockchipRga.h>
+
+#include <gui/ISurfaceComposer.h>
+#include <gui/Surface.h>
+#include <gui/SurfaceComposerClient.h>
+
+#include <GLES/gl.h>
+#include <GLES/glext.h>
+#include <EGL/eglext.h>
+
+#include <stdint.h>
+#include <sys/types.h>
+
+#include <system/window.h>
+
+#include <utils/Thread.h>
+
+#include <EGL/egl.h>
+#include <GLES/gl.h>
+
+///////////////////////////////////////////////////////
+//#include "../drmrga.h"
+#include <hardware/hardware.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <time.h>
+#include <unistd.h>
+
+#include <sys/mman.h>
+#include <linux/stddef.h>
+
+float get_bpp_from_format(int format)
+{
+ float bpp = 0;
+
+ switch (format) {
+ case HAL_PIXEL_FORMAT_RGB_565:
+ bpp = 2;
+ break;
+ case HAL_PIXEL_FORMAT_RGB_888:
+ bpp = 3;
+ break;
+ case HAL_PIXEL_FORMAT_RGBA_8888:
+ bpp = 4;
+ break;
+ case HAL_PIXEL_FORMAT_RGBX_8888:
+ bpp = 4;
+ break;
+ case HAL_PIXEL_FORMAT_BGRA_8888:
+ bpp = 4;
+ break;
+ case HAL_PIXEL_FORMAT_YCrCb_420_SP:
+ bpp = 1.5;
+ break;
+ case HAL_PIXEL_FORMAT_YCrCb_NV12:
+ bpp = 1.5;
+ break;
+ case HAL_PIXEL_FORMAT_YCrCb_NV12_VIDEO:
+ bpp = 1.5;
+ break;
+ case HAL_PIXEL_FORMAT_YCrCb_NV12_10:
+ bpp = 1.875;
+ break;
+ default:
+ ALOGE("Is unsupport format now,please fix");
+ return 0;
+ }
+
+ return bpp;
+}
+
+int get_buf_size_by_w_h_f(int w, int h, int f)
+{
+ float bpp = get_bpp_from_format(f);
+ int size = 0;
+
+ size = (int)w * h * bpp;
+ return size;
+}
+
+int get_string_by_format(char *value, int format)
+{
+ if (!value)
+ return -EINVAL;
+
+ switch (format) {
+ case HAL_PIXEL_FORMAT_RGB_565:
+ memcpy(value, "rgb565", sizeof("rgb565"));
+ break;
+ case HAL_PIXEL_FORMAT_RGB_888:
+ memcpy(value, "rgb888", sizeof("rgb888"));
+ break;
+ case HAL_PIXEL_FORMAT_RGBA_8888:
+ memcpy(value, "rgba8888", sizeof("rgba8888"));
+ break;
+ case HAL_PIXEL_FORMAT_RGBX_8888:
+ memcpy(value, "rgbx8888", sizeof("rgbx8888"));
+ break;
+ case HAL_PIXEL_FORMAT_BGRA_8888:
+ memcpy(value, "bgra8888", sizeof("bgra8888"));
+ break;
+ case HAL_PIXEL_FORMAT_YCrCb_420_SP:
+ memcpy(value, "crcb420sp", sizeof("crcb420sp"));
+ break;
+ case HAL_PIXEL_FORMAT_YCrCb_NV12:
+ memcpy(value, "nv12", sizeof("nv12"));
+ break;
+ case HAL_PIXEL_FORMAT_YCrCb_NV12_VIDEO:
+ memcpy(value, "nv12", sizeof("nv12"));
+ break;
+ case HAL_PIXEL_FORMAT_YCrCb_NV12_10:
+ memcpy(value, "nv12_10", sizeof("nv12_10"));
+ break;
+ default:
+ ALOGE("Is unsupport format now,please fix");
+ return 0;
+ }
+
+ return 0;
+}
+
+int get_buf_from_file(void *buf, int f, int sw, int sh, int index)
+{
+ const char *inputFilePath = "/data/in%dw%d-h%d-%s.bin";
+ char filePath[100];
+ char fstring[30];
+ int ret = 0;
+
+ ret = get_string_by_format(fstring, f);
+ snprintf(filePath, 100, inputFilePath, index, sw, sh, fstring);
+#if 1
+ FILE *file = fopen(filePath, "rb");
+ if (!file) {
+ fprintf(stderr, "Could not open %s\n", filePath);
+ return -EINVAL;
+ }
+ fread(buf, get_buf_size_by_w_h_f(sw, sh, f), 1, file);
+ fclose(file);
+#else
+ {
+ char *pbuf = (char*)malloc(2 * mHeight * 4864);
+ for (int i = 0; i < 2160 * 1.6; i++)
+ memcpy(pbuf+i*4800,buf+i*6080,4800);
+ const char *outFilePath = "/data/fb3840x2160-2.yuv";
+ FILE *file = fopen(outFilePath, "wb+");
+ if (!file) {
+ fprintf(stderr, "Could not open %s\n", outFilePath);
+ return false;
+ }
+ fwrite(pbuf, 2 * 4864 * 2160, 1, file);
+ free(pbuf);
+ fclose(file);
+ }
+#endif
+
+ return 0;
+}
+
+int output_buf_data_to_file(void *buf, int f, int sw, int sh, int index)
+{
+ const char *outputFilePath = "/data/out%dw%d-h%d-%s.bin";
+ char filePath[100];
+ char fstring[30];
+ int ret = 0;
+
+ ret = get_string_by_format(fstring, f);
+ snprintf(filePath, 100, outputFilePath, index, sw, sh, fstring);
+#if 0
+ FILE *file = fopen(yuvFilePath, "rb");
+ if (!file) {
+ fprintf(stderr, "Could not open %s\n", yuvFilePath);
+ return false;
+ }
+ #if 0
+ {
+ char *pbuf = (char*)malloc(2 * mHeight * 4864);
+ fread(pbuf, 2 * 4864 * 2160, 1, file);
+ for (int i = 0; i < 2160; i++)
+ memcpy(buf+i*4800,pbuf+i*6080,4800);
+ memset(buf+2160*4800,0x80,4800 * 2160);
+ }
+ #else
+ fread(dstbuf, 2 * 1920 * 1088, 1, file);
+ fclose(file);
+ #endif
+#else
+ FILE *file = fopen(filePath, "wb+");
+ if (!file) {
+ fprintf(stderr, "Could not open %s\n", filePath);
+ return false;
+ } else
+ fprintf(stderr, "open %s and write ok\n", filePath);
+ fwrite(buf, get_buf_size_by_w_h_f(sw, sh, f), 1, file);
+ fclose(file);
+#endif
+
+ return 0;
+}
+
diff --git a/tests/RockchipFileOps.h b/tests/RockchipFileOps.h
new file mode 100644
index 0000000..6d123ec
--- /dev/null
+++ b/tests/RockchipFileOps.h
@@ -0,0 +1,20 @@
+/*
+ * Copyright (C) 2016 Rockchip Electronics Co.Ltd
+ * Authors:
+ * Zhiqin Wei <wzq@rock-chips.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ */
+
+#ifndef _rk_file_ops_h_
+#define _rk_file_ops_h_
+
+// -------------------------------------------------------------------------------
+int get_buf_from_file(void *buf, int f, int sw, int sh, int index);
+int output_buf_data_to_file(void *buf, int f, int sw, int sh, int index);
+#endif
+
diff --git a/tests/RockchipRgaBlit.cpp b/tests/RockchipRgaBlit.cpp
new file mode 100644
index 0000000..a2c18bb
--- /dev/null
+++ b/tests/RockchipRgaBlit.cpp
@@ -0,0 +1,188 @@
+/*
+ * Copyright (C) 2016 Rockchip Electronics Co.Ltd
+ * Authors:
+ * Zhiqin Wei <wzq@rock-chips.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ */
+
+#define LOG_NDEBUG 0
+#define LOG_TAG "RockchipRgaStereo"
+
+#include <stdint.h>
+#include <sys/types.h>
+#include <math.h>
+#include <fcntl.h>
+#include <utils/misc.h>
+#include <signal.h>
+#include <time.h>
+
+#include <cutils/properties.h>
+
+#include <binder/IPCThreadState.h>
+#include <utils/Atomic.h>
+#include <utils/Errors.h>
+#include <utils/Log.h>
+
+#include <ui/PixelFormat.h>
+#include <ui/Rect.h>
+#include <ui/Region.h>
+#include <ui/DisplayInfo.h>
+#include <ui/GraphicBufferMapper.h>
+
+#include <gui/ISurfaceComposer.h>
+#include <gui/Surface.h>
+#include <gui/SurfaceComposerClient.h>
+#include <RockchipRga.h>
+
+#include <GLES/gl.h>
+#include <GLES/glext.h>
+#include <EGL/eglext.h>
+
+#include <stdint.h>
+#include <sys/types.h>
+
+#include <system/window.h>
+
+#include <utils/Thread.h>
+
+#include <EGL/egl.h>
+#include <GLES/gl.h>
+
+///////////////////////////////////////////////////////
+//#include "../drmrga.h"
+#include <hardware/hardware.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <time.h>
+#include <unistd.h>
+
+#include <sys/mman.h>
+#include <linux/stddef.h>
+#include "RockchipFileOps.h"
+///////////////////////////////////////////////////////
+
+using namespace android;
+
+int main()
+{
+ int ret = 0;
+ int srcWidth,srcHeight,srcFormat;
+ int dstWidth,dstHeight,dstFormat;
+
+ srcWidth = 2048;
+ srcHeight = 1536;
+ srcFormat = HAL_PIXEL_FORMAT_RGBA_8888;
+
+ dstWidth = 2048;
+ dstHeight = 1536;
+ dstFormat = HAL_PIXEL_FORMAT_RGBA_8888;
+
+ RockchipRga& rkRga(RockchipRga::get());
+
+ GraphicBufferMapper &mgbMapper = GraphicBufferMapper::get();
+
+
+ char* buf = NULL;
+ sp<GraphicBuffer> gbs(new GraphicBuffer(srcWidth,srcHeight,srcFormat,
+ GRALLOC_USAGE_SW_WRITE_OFTEN));
+
+ if (gbs->initCheck()) {
+ printf("GraphicBuffer error : %s\n",strerror(errno));
+ return ret;
+ } else
+ printf("GraphicBuffer ok : %s\n","*************************************");
+
+
+ sp<GraphicBuffer> gbd(new GraphicBuffer(dstWidth,dstHeight,dstFormat,
+ GRALLOC_USAGE_SW_WRITE_OFTEN));
+
+ if (gbd->initCheck()) {
+ printf("GraphicBuffer error : %s\n",strerror(errno));
+ return ret;
+ } else
+ printf("GraphicBuffer ok : %s\n","*************************************");
+
+
+ mgbMapper.registerBuffer(gbs->handle);
+ mgbMapper.registerBuffer(gbd->handle);
+
+ ret = gbs->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)&buf);
+
+ if (ret) {
+ printf("lock buffer error : %s\n",strerror(errno));
+ return ret;
+ } else
+ printf("lock buffer ok : %s\n","**************************************");
+
+#if 1
+ get_buf_from_file(buf, srcFormat, srcWidth, srcHeight, 0);
+#else
+ memset(buf,0x55,4*1200*1920);
+#endif
+ ret = gbs->unlock();
+
+ ret = gbd->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)&buf);
+
+ if (ret) {
+ printf("lock buffer error : %s\n",strerror(errno));
+ return ret;
+ } else
+ printf("lock buffer ok : %s\n","**************************************");
+
+
+ {
+#if 1
+ get_buf_from_file(buf, srcFormat, srcWidth, srcHeight, 1);
+#else
+ memset(buf,0x55,4*1200*1920);
+#endif
+ }
+ ret = gbd->unlock();
+
+ ret = gbs->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)&buf);
+ if (ret) {
+ printf("unlock buffer error : %s\n",strerror(errno));
+ return ret;
+ } else
+ printf("unlock buffer ok : %s\n","*************************************");
+
+ while(1) {
+ rga_info_t src;
+ rga_info_t dst;
+ memset(&src, 0, sizeof(rga_info_t));
+ src.fd = -1;
+ src.blend = 0xFF0105;
+ memset(&dst, 0, sizeof(rga_info_t));
+ dst.fd = -1;
+ src.hnd = gbs->handle;
+ dst.hnd = gbd->handle;
+ ret = rkRga.RkRgaBlit(&src, &dst, NULL);
+
+ if (ret) {
+ printf("rgaFillColor error : %s,hnd=%p\n",
+ strerror(errno),(void*)(gbd->handle));
+ ALOGD("rgaFillColor error : %s,hnd=%p\n",
+ strerror(errno),(void*)(gbd->handle));
+ }
+
+ {
+ char* dstbuf = NULL;
+ ret = gbd->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)&dstbuf);
+ //for(int i =0; i < mHeight * 1.5; i++)
+ // memcpy(dstbuf + i * 2400,buf + i * 3000,2400);
+ output_buf_data_to_file(dstbuf, dstFormat, dstWidth, dstHeight, 0);
+ ret = gbd->unlock();
+ }
+ printf("threadloop\n");
+ usleep(500000);
+ break;
+ }
+ return 0;
+}
diff --git a/tests/RockchipRgaBlitSlt.cpp b/tests/RockchipRgaBlitSlt.cpp
new file mode 100644
index 0000000..aef7973
--- /dev/null
+++ b/tests/RockchipRgaBlitSlt.cpp
@@ -0,0 +1,220 @@
+/*
+ * Copyright (C) 2016 Rockchip Electronics Co.Ltd
+ * Authors:
+ * Zhiqin Wei <wzq@rock-chips.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ */
+
+#define LOG_NDEBUG 0
+#define LOG_TAG "RockchipRgaStereo"
+
+#include <stdint.h>
+#include <sys/types.h>
+#include <math.h>
+#include <fcntl.h>
+#include <utils/misc.h>
+#include <signal.h>
+#include <time.h>
+
+#include <cutils/properties.h>
+
+#include <binder/IPCThreadState.h>
+#include <utils/Atomic.h>
+#include <utils/Errors.h>
+#include <utils/Log.h>
+
+#include <ui/PixelFormat.h>
+#include <ui/Rect.h>
+#include <ui/Region.h>
+#include <ui/DisplayInfo.h>
+#include <ui/GraphicBufferMapper.h>
+
+#include <gui/ISurfaceComposer.h>
+#include <gui/Surface.h>
+#include <gui/SurfaceComposerClient.h>
+#include <RockchipRga.h>
+
+#include <GLES/gl.h>
+#include <GLES/glext.h>
+#include <EGL/eglext.h>
+
+#include <stdint.h>
+#include <sys/types.h>
+
+#include <system/window.h>
+
+#include <utils/Thread.h>
+
+#include <EGL/egl.h>
+#include <GLES/gl.h>
+
+///////////////////////////////////////////////////////
+//#include "../drmrga.h"
+#include <hardware/hardware.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <time.h>
+#include <unistd.h>
+
+#include <sys/mman.h>
+#include <linux/stddef.h>
+#include "RockchipFileOps.h"
+///////////////////////////////////////////////////////
+
+using namespace android;
+
+int main()
+{
+ int ret = 0;
+ int srcWidth,srcHeight,srcFormat;
+ int dstWidth,dstHeight,dstFormat;
+
+ srcWidth = 1536;
+ srcHeight = 2048;
+ srcFormat = HAL_PIXEL_FORMAT_RGBA_8888;
+
+ dstWidth = 1536;
+ dstHeight = 2048;
+ dstFormat = HAL_PIXEL_FORMAT_RGBX_8888;
+
+ RockchipRga& rkRga(RockchipRga::get());
+
+ GraphicBufferMapper &mgbMapper = GraphicBufferMapper::get();
+
+
+ char* buf = NULL;
+ sp<GraphicBuffer> gbs(new GraphicBuffer(srcWidth,srcHeight,srcFormat,
+ GRALLOC_USAGE_SW_WRITE_OFTEN));
+
+ if (gbs->initCheck()) {
+ printf("GraphicBuffer error : %s\n",strerror(errno));
+ return ret;
+ } else
+ printf("GraphicBuffer ok : %s\n","*************************************");
+
+
+ sp<GraphicBuffer> gbd(new GraphicBuffer(dstWidth,dstHeight,dstFormat,
+ GRALLOC_USAGE_SW_WRITE_OFTEN));
+
+ if (gbd->initCheck()) {
+ printf("GraphicBuffer error : %s\n",strerror(errno));
+ return ret;
+ } else
+ printf("GraphicBuffer ok : %s\n","*************************************");
+
+
+ mgbMapper.registerBuffer(gbs->handle);
+ mgbMapper.registerBuffer(gbd->handle);
+
+ ret = gbs->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)&buf);
+
+ if (ret) {
+ printf("lock buffer error : %s\n",strerror(errno));
+ return ret;
+ } else
+ printf("lock buffer ok : %s\n","**************************************");
+
+#if 1
+ get_buf_from_file(buf, srcFormat, srcWidth, srcHeight, 0);
+#else
+ memset(buf,0x55,4*1200*1920);
+#endif
+ ret = gbs->unlock();
+
+ ret = gbd->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)&buf);
+
+ if (ret) {
+ printf("lock buffer error : %s\n",strerror(errno));
+ return ret;
+ } else
+ printf("lock buffer ok : %s\n","**************************************");
+
+
+ {
+#if 1
+ get_buf_from_file(buf, srcFormat, srcWidth, srcHeight, 1);
+#else
+ memset(buf,0x55,4*1200*1920);
+#endif
+ }
+ ret = gbd->unlock();
+
+ ret = gbs->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)&buf);
+ if (ret) {
+ printf("unlock buffer error : %s\n",strerror(errno));
+ return ret;
+ } else
+ printf("unlock buffer ok : %s\n","*************************************");
+
+ while(1) {
+ rga_info_t src;
+ rga_info_t dst;
+ memset(&src, 0, sizeof(rga_info_t));
+ src.fd = -1;
+ src.blend = 0xFF0105;
+ memset(&dst, 0, sizeof(rga_info_t));
+ dst.fd = -1;
+ src.hnd = gbs->handle;
+ dst.hnd = gbd->handle;
+ ret = rkRga.RkRgaBlit(&src, &dst, NULL);
+
+ if (ret) {
+ printf("rgaFillColor error : %s,hnd=%p\n",
+ strerror(errno),(void*)(gbd->handle));
+ ALOGD("rgaFillColor error : %s,hnd=%p\n",
+ strerror(errno),(void*)(gbd->handle));
+ }
+
+ {
+ char* dstbuf = NULL;
+ ret = gbd->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)&dstbuf);
+ output_buf_data_to_file(dstbuf, dstFormat, dstWidth, dstHeight, 0);
+ ret = gbd->unlock();
+ ret = gbd->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)&dstbuf);
+
+ get_buf_from_file(buf, srcFormat, srcWidth, srcHeight, 2);
+ ret = gbs->unlock();
+ ret = gbs->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)&buf);
+
+ int size = dstWidth * dstHeight * 4;
+ //for(int i =0; i < mHeight * 1.5; i++)
+ // memcpy(dstbuf + i * 2400,buf + i * 3000,2400);
+ //output_buf_data_to_file(dstbuf, dstFormat, dstWidth, dstHeight, 0);
+ //ret = gbd->unlock();
+ //ret = gbd->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)&dstbuf);
+ unsigned int *pstd = (unsigned int *)buf;
+ unsigned int *pnow = (unsigned int *)dstbuf;
+ int errCount = 0;
+ int rightCount = 0;
+ for (int i = 0; i < size / 4; i++) {
+ if (*pstd != *pnow) {
+ printf("i = %8d,[0x%x,0x%x];", i, *pstd ,*pnow);
+ if (i % 16 == 0)
+ printf("\n");
+ errCount ++;
+
+ } else {
+ if (i % (640*1024) == 0)
+ printf("pass i=%8d[0x%x,0x%x]\n",i,*pstd,*pnow);
+ rightCount++;
+ }
+ pstd++;
+ pnow++;
+ if (errCount > 64)
+ break;
+ }
+ ret = gbs->unlock();
+ ret = gbd->unlock();
+ printf("errCount=%d,rightCount=%d\n", errCount, rightCount);
+ }
+ break;
+ }
+ return 0;
+}
diff --git a/tests/RockchipRgaBlitUserSpace.cpp b/tests/RockchipRgaBlitUserSpace.cpp
new file mode 100644
index 0000000..3b3c093
--- /dev/null
+++ b/tests/RockchipRgaBlitUserSpace.cpp
@@ -0,0 +1,151 @@
+/*
+ * Copyright (C) 2016 Rockchip Electronics Co.Ltd
+ * Authors:
+ * Zhiqin Wei <wzq@rock-chips.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ */
+
+#define LOG_NDEBUG 0
+#define LOG_TAG "RockchipRgaStereo"
+
+#include <stdint.h>
+#include <sys/types.h>
+#include <math.h>
+#include <fcntl.h>
+#include <utils/misc.h>
+#include <signal.h>
+#include <time.h>
+
+#include <cutils/properties.h>
+
+#include <binder/IPCThreadState.h>
+#include <utils/Atomic.h>
+#include <utils/Errors.h>
+#include <utils/Log.h>
+
+#include <ui/PixelFormat.h>
+#include <ui/Rect.h>
+#include <ui/Region.h>
+#include <ui/DisplayInfo.h>
+#include <ui/GraphicBufferMapper.h>
+
+#include <gui/ISurfaceComposer.h>
+#include <gui/Surface.h>
+#include <gui/SurfaceComposerClient.h>
+#include <RockchipRga.h>
+
+#include <GLES/gl.h>
+#include <GLES/glext.h>
+#include <EGL/eglext.h>
+
+#include <stdint.h>
+#include <sys/types.h>
+
+#include <system/window.h>
+
+#include <utils/Thread.h>
+
+#include <EGL/egl.h>
+#include <GLES/gl.h>
+
+///////////////////////////////////////////////////////
+//#include "../drmrga.h"
+#include <hardware/hardware.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <time.h>
+#include <unistd.h>
+
+#include <sys/mman.h>
+#include <linux/stddef.h>
+#include "RockchipFileOps.h"
+///////////////////////////////////////////////////////
+
+using namespace android;
+
+int main()
+{
+ int ret = 0;
+ int srcWidth,srcHeight,srcFormat;
+ int dstWidth,dstHeight,dstFormat;
+
+ void *src = NULL;
+ void *dst = NULL;
+
+ srcWidth = 2048;
+ srcHeight = 1536;
+ srcFormat = HAL_PIXEL_FORMAT_RGBA_8888;
+
+ dstWidth = 2048;
+ dstHeight = 1536;
+ dstFormat = HAL_PIXEL_FORMAT_RGBA_8888;
+
+ src = malloc(srcWidth * srcHeight * 4);
+ if (!src)
+ return -ENOMEM;
+
+ dst = malloc(dstWidth * dstHeight * 4);
+
+ if (!dst) {
+ free(src);
+ return -ENOMEM;
+ }
+
+ RockchipRga& rkRga(RockchipRga::get());
+
+ char* buf = (char *)src;
+
+#if 1
+ get_buf_from_file(buf, srcFormat, srcWidth, srcHeight, 0);
+#else
+ memset(buf,0x55,4*1200*1920);
+#endif
+
+ buf = (char *)dst;
+ {
+#if 1
+ get_buf_from_file(buf, srcFormat, srcWidth, srcHeight, 1);
+#else
+ memset(buf,0x55,4*1200*1920);
+#endif
+ }
+
+ while(1) {
+ //rkRga.RkRgaSetLogOnceFlag(1);
+ //drm_rga_t rects;
+ //memset(&rects, 0, sizeof(drm_rga_t));
+ //rga_set_rect(&rects.src, 0, 0, srcWidth, srcHeight, srcWidth, srcFormat);
+ //rga_set_rect(&rects.dst, 0, 0, dstWidth, dstHeight, dstWidth, dstFormat);
+ rga_info_t rgasrc;
+ rga_info_t rgadst;
+ memset(&rgasrc, 0, sizeof(rga_info_t));
+ rgasrc.fd = -1;
+ rgasrc.mmuFlag = 1;
+ memset(&rgadst, 0, sizeof(rga_info_t));
+ rgadst.fd = -1;
+ rgadst.mmuFlag = 1;
+ rgasrc.virAddr = src;
+ rgadst.virAddr = dst;
+ rgasrc.blend = 0x880105;
+ rga_set_rect(&rgasrc.rect, 0,0,srcWidth,srcHeight,srcWidth/*stride*/,srcHeight,srcFormat);
+ rga_set_rect(&rgadst.rect, 0,0,dstWidth,dstHeight,dstWidth/*stride*/,dstHeight,dstFormat);
+ ret = rkRga.RkRgaBlit(&rgasrc, &rgadst, NULL);
+ {
+ char* dstbuf = (char *)dst;
+ //for(int i =0; i < mHeight * 1.5; i++)
+ // memcpy(dstbuf + i * 2400,buf + i * 3000,2400);
+ output_buf_data_to_file(dstbuf, dstFormat, dstWidth, dstHeight, 0);
+ }
+ printf("threadloop\n");
+ usleep(500000);
+ break;
+ }
+ return 0;
+}
diff --git a/tests/RockchipRgaColorFill.cpp b/tests/RockchipRgaColorFill.cpp
new file mode 100644
index 0000000..70e177c
--- /dev/null
+++ b/tests/RockchipRgaColorFill.cpp
@@ -0,0 +1,197 @@
+/*
+ * Copyright (C) 2016 Rockchip Electronics Co.Ltd
+ * Authors:
+ * Zhiqin Wei <wzq@rock-chips.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ */
+
+#define LOG_NDEBUG 0
+#define LOG_TAG "RockchipRgaStereo"
+
+#include <stdint.h>
+#include <sys/types.h>
+#include <math.h>
+#include <fcntl.h>
+#include <utils/misc.h>
+#include <signal.h>
+#include <time.h>
+
+#include <cutils/properties.h>
+
+#include <binder/IPCThreadState.h>
+#include <utils/Atomic.h>
+#include <utils/Errors.h>
+#include <utils/Log.h>
+
+#include <ui/PixelFormat.h>
+#include <ui/Rect.h>
+#include <ui/Region.h>
+#include <ui/DisplayInfo.h>
+#include <ui/GraphicBufferMapper.h>
+#include <RockchipRga.h>
+
+#include <gui/ISurfaceComposer.h>
+#include <gui/Surface.h>
+#include <gui/SurfaceComposerClient.h>
+
+#include <GLES/gl.h>
+#include <GLES/glext.h>
+#include <EGL/eglext.h>
+
+#include <stdint.h>
+#include <sys/types.h>
+
+#include <system/window.h>
+
+#include <utils/Thread.h>
+
+#include <EGL/egl.h>
+#include <GLES/gl.h>
+
+///////////////////////////////////////////////////////
+//#include "../drmrga.h"
+#include <hardware/hardware.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <time.h>
+#include <unistd.h>
+
+#include <sys/mman.h>
+#include <linux/stddef.h>
+#include "RockchipFileOps.h"
+///////////////////////////////////////////////////////
+
+using namespace android;
+
+int main()
+{
+ int ret = 0;
+ int srcWidth,srcHeight,srcFormat;
+ int dstWidth,dstHeight,dstFormat;
+
+ srcWidth = 1920;
+ srcHeight = 1088;
+ srcFormat = HAL_PIXEL_FORMAT_YCrCb_NV12;
+
+ dstWidth = 1920;
+ dstHeight = 1088;
+ dstFormat = HAL_PIXEL_FORMAT_YCrCb_NV12;
+
+ RockchipRga& rkRga(RockchipRga::get());
+
+ GraphicBufferMapper &mgbMapper = GraphicBufferMapper::get();
+
+
+ char* buf = NULL;
+ sp<GraphicBuffer> gbs(new GraphicBuffer(srcWidth,srcHeight,srcFormat,
+ GRALLOC_USAGE_SW_WRITE_OFTEN));
+
+ if (gbs->initCheck()) {
+ printf("GraphicBuffer error : %s\n",strerror(errno));
+ return ret;
+ } else
+ printf("GraphicBuffer ok : %s\n","*************************************");
+
+
+ sp<GraphicBuffer> gbd(new GraphicBuffer(dstWidth,dstHeight,dstFormat,
+ GRALLOC_USAGE_SW_WRITE_OFTEN));
+
+ if (gbd->initCheck()) {
+ printf("GraphicBuffer error : %s\n",strerror(errno));
+ return ret;
+ } else
+ printf("GraphicBuffer ok : %s\n","*************************************");
+
+
+ mgbMapper.registerBuffer(gbs->handle);
+ mgbMapper.registerBuffer(gbd->handle);
+
+ ret = gbs->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)&buf);
+
+ if (ret) {
+ printf("lock buffer error : %s\n",strerror(errno));
+ return ret;
+ } else
+ printf("lock buffer ok : %s\n","**************************************");
+
+#if 1
+ get_buf_from_file(buf, srcFormat, srcWidth, srcHeight, 0);
+#else
+ memset(buf,0x55,4*1200*1920);
+#endif
+ ret = gbs->unlock();
+ ret = gbs->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)&buf);
+ if (ret) {
+ printf("unlock buffer error : %s\n",strerror(errno));
+ return ret;
+ } else
+ printf("unlock buffer ok : %s\n","*************************************");
+#define USE_HANDLE 1
+ while(1) {
+ rga_info_t src;
+ rga_info_t dst;
+ memset(&src, 0, sizeof(rga_info_t));
+ src.fd = -1;
+ src.mmuFlag = 1;
+ memset(&dst, 0, sizeof(rga_info_t));
+ dst.fd = -1;
+ dst.mmuFlag = 1;
+#if USE_HANDLE
+ src.hnd = gbs->handle;
+ dst.hnd = gbd->handle;
+ /*just to try scal the target buffer: ok to support scale*/
+ //rga_set_rect(&dst.rect, 0,0,1280,720,1280/*stride*/,dstFormat);
+ //ALOGD("%p,%p,%d,%d",src.hnd,gbs->handle,src.hnd->version,gbs->handle->version);
+#else //use fd
+ ret = rkRga.RkRgaGetBufferFd(gbs->handle, &src.fd);
+ if (ret) {
+ printf("rgaFillColor error : %s,hnd=%p\n",
+ strerror(errno),(void*)(gbd->handle));
+ ALOGD("rgaFillColor error : %s,hnd=%p\n",
+ strerror(errno),(void*)(gbd->handle));
+ }
+ ret = rkRga.RkRgaGetBufferFd(gbd->handle, &dst.fd);
+ if (ret) {
+ printf("rgaFillColor error : %s,hnd=%p\n",
+ strerror(errno),(void*)(gbd->handle));
+ ALOGD("rgaFillColor error : %s,hnd=%p\n",
+ strerror(errno),(void*)(gbd->handle));
+ }
+
+ //if use fd we need give the rect use handle rect is first else will get if
+ //from handle.handle has the info fo w h stride format and so on
+ rga_set_rect(&src.rect, 0,0,srcWidth,srcHeight,srcWidth/*stride*/,srcFormat);
+ rga_set_rect(&dst.rect, 0,0,dstWidth,dstHeight,dstWidth/*stride*/,dstFormat);
+#endif
+
+ dst.color = 0x80808080;
+ rkRga.RkRgaCollorFill(&dst);
+
+ if (ret) {
+ printf("rgaFillColor error : %s,hnd=%p\n",
+ strerror(errno),(void*)(gbd->handle));
+ ALOGD("rgaFillColor error : %s,hnd=%p\n",
+ strerror(errno),(void*)(gbd->handle));
+ }
+
+ {
+ char* dstbuf = NULL;
+ ret = gbd->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)&dstbuf);
+ //for(int i =0; i < mHeight * 1.5; i++)
+ // memcpy(dstbuf + i * 2400,buf + i * 3000,2400);
+ output_buf_data_to_file(dstbuf, dstFormat, dstWidth, dstHeight, 0);
+ ret = gbd->unlock();
+ }
+ printf("threadloop\n");
+ usleep(500000);
+ break;
+ }
+ return 0;
+}
diff --git a/tests/RockchipRgaCopy.cpp b/tests/RockchipRgaCopy.cpp
new file mode 100644
index 0000000..8237771
--- /dev/null
+++ b/tests/RockchipRgaCopy.cpp
@@ -0,0 +1,195 @@
+/*
+ * Copyright (C) 2016 Rockchip Electronics Co.Ltd
+ * Authors:
+ * Zhiqin Wei <wzq@rock-chips.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ */
+
+#define LOG_NDEBUG 0
+#define LOG_TAG "RockchipRgaStereo"
+
+#include <stdint.h>
+#include <sys/types.h>
+#include <math.h>
+#include <fcntl.h>
+#include <utils/misc.h>
+#include <signal.h>
+#include <time.h>
+
+#include <cutils/properties.h>
+
+#include <binder/IPCThreadState.h>
+#include <utils/Atomic.h>
+#include <utils/Errors.h>
+#include <utils/Log.h>
+
+#include <ui/PixelFormat.h>
+#include <ui/Rect.h>
+#include <ui/Region.h>
+#include <ui/DisplayInfo.h>
+#include <ui/GraphicBufferMapper.h>
+#include <RockchipRga.h>
+
+#include <gui/ISurfaceComposer.h>
+#include <gui/Surface.h>
+#include <gui/SurfaceComposerClient.h>
+
+#include <GLES/gl.h>
+#include <GLES/glext.h>
+#include <EGL/eglext.h>
+
+#include <stdint.h>
+#include <sys/types.h>
+
+#include <system/window.h>
+
+#include <utils/Thread.h>
+
+#include <EGL/egl.h>
+#include <GLES/gl.h>
+
+///////////////////////////////////////////////////////
+//#include "../drmrga.h"
+#include <hardware/hardware.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <time.h>
+#include <unistd.h>
+
+#include <sys/mman.h>
+#include <linux/stddef.h>
+#include "RockchipFileOps.h"
+///////////////////////////////////////////////////////
+
+using namespace android;
+
+int main()
+{
+ int ret = 0;
+ int srcWidth,srcHeight,srcFormat;
+ int dstWidth,dstHeight,dstFormat;
+
+ srcWidth = 1920;
+ srcHeight = 1088;
+ srcFormat = HAL_PIXEL_FORMAT_YCrCb_NV12;
+
+ dstWidth = 1920;
+ dstHeight = 1088;
+ dstFormat = HAL_PIXEL_FORMAT_YCrCb_NV12;
+
+ RockchipRga& rkRga(RockchipRga::get());
+
+ GraphicBufferMapper &mgbMapper = GraphicBufferMapper::get();
+
+
+ char* buf = NULL;
+ sp<GraphicBuffer> gbs(new GraphicBuffer(srcWidth,srcHeight,srcFormat,
+ GRALLOC_USAGE_SW_WRITE_OFTEN));
+
+ if (gbs->initCheck()) {
+ printf("GraphicBuffer error : %s\n",strerror(errno));
+ return ret;
+ } else
+ printf("GraphicBuffer ok : %s\n","*************************************");
+
+
+ sp<GraphicBuffer> gbd(new GraphicBuffer(dstWidth,dstHeight,dstFormat,
+ GRALLOC_USAGE_SW_WRITE_OFTEN));
+
+ if (gbd->initCheck()) {
+ printf("GraphicBuffer error : %s\n",strerror(errno));
+ return ret;
+ } else
+ printf("GraphicBuffer ok : %s\n","*************************************");
+
+
+ mgbMapper.registerBuffer(gbs->handle);
+ mgbMapper.registerBuffer(gbd->handle);
+
+ ret = gbs->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)&buf);
+
+ if (ret) {
+ printf("lock buffer error : %s\n",strerror(errno));
+ return ret;
+ } else
+ printf("lock buffer ok : %s\n","**************************************");
+
+#if 1
+ get_buf_from_file(buf, srcFormat, srcWidth, srcHeight, 0);
+#else
+ memset(buf,0x55,4*1200*1920);
+#endif
+ ret = gbs->unlock();
+ ret = gbs->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)&buf);
+ if (ret) {
+ printf("unlock buffer error : %s\n",strerror(errno));
+ return ret;
+ } else
+ printf("unlock buffer ok : %s\n","*************************************");
+#define USE_HANDLE 1
+ while(1) {
+ rga_info_t src;
+ rga_info_t dst;
+ memset(&src, 0, sizeof(rga_info_t));
+ src.fd = -1;
+ src.mmuFlag = 1;
+ memset(&dst, 0, sizeof(rga_info_t));
+ dst.fd = -1;
+ dst.mmuFlag = 1;
+#if USE_HANDLE
+ src.hnd = gbs->handle;
+ dst.hnd = gbd->handle;
+ /*just to try scal the target buffer: ok to support scale*/
+ //rga_set_rect(&dst.rect, 0,0,1280,720,1280/*stride*/,dstFormat);
+ //ALOGD("%p,%p,%d,%d",src.hnd,gbs->handle,src.hnd->version,gbs->handle->version);
+#else //use fd
+ ret = rkRga.RkRgaGetBufferFd(gbs->handle, &src.fd);
+ if (ret) {
+ printf("rgaFillColor error : %s,hnd=%p\n",
+ strerror(errno),(void*)(gbd->handle));
+ ALOGD("rgaFillColor error : %s,hnd=%p\n",
+ strerror(errno),(void*)(gbd->handle));
+ }
+ ret = rkRga.RkRgaGetBufferFd(gbd->handle, &dst.fd);
+ if (ret) {
+ printf("rgaFillColor error : %s,hnd=%p\n",
+ strerror(errno),(void*)(gbd->handle));
+ ALOGD("rgaFillColor error : %s,hnd=%p\n",
+ strerror(errno),(void*)(gbd->handle));
+ }
+
+ //if use fd we need give the rect use handle rect is first else will get if
+ //from handle.handle has the info fo w h stride format and so on
+ rga_set_rect(&src.rect, 0,0,srcWidth,srcHeight,srcWidth/*stride*/,srcFormat);
+ rga_set_rect(&dst.rect, 0,0,dstWidth,dstHeight,dstWidth/*stride*/,dstFormat);
+#endif
+ ret = rkRga.RkRgaBlit(&src, &dst, NULL);
+
+ if (ret) {
+ printf("rgaFillColor error : %s,hnd=%p\n",
+ strerror(errno),(void*)(gbd->handle));
+ ALOGD("rgaFillColor error : %s,hnd=%p\n",
+ strerror(errno),(void*)(gbd->handle));
+ }
+
+ {
+ char* dstbuf = NULL;
+ ret = gbd->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)&dstbuf);
+ //for(int i =0; i < mHeight * 1.5; i++)
+ // memcpy(dstbuf + i * 2400,buf + i * 3000,2400);
+ output_buf_data_to_file(dstbuf, dstFormat, dstWidth, dstHeight, 0);
+ ret = gbd->unlock();
+ }
+ printf("threadloop\n");
+ usleep(500000);
+ break;
+ }
+ return 0;
+}
diff --git a/tests/RockchipRgaCopyRgba.cpp b/tests/RockchipRgaCopyRgba.cpp
new file mode 100644
index 0000000..1d393fd
--- /dev/null
+++ b/tests/RockchipRgaCopyRgba.cpp
@@ -0,0 +1,170 @@
+/*
+ * Copyright (C) 2016 Rockchip Electronics Co.Ltd
+ * Authors:
+ * Zhiqin Wei <wzq@rock-chips.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ */
+
+#define LOG_NDEBUG 0
+#define LOG_TAG "RockchipRgaStereo"
+
+#include <stdint.h>
+#include <sys/types.h>
+#include <math.h>
+#include <fcntl.h>
+#include <utils/misc.h>
+#include <signal.h>
+#include <time.h>
+
+#include <cutils/properties.h>
+
+#include <binder/IPCThreadState.h>
+#include <utils/Atomic.h>
+#include <utils/Errors.h>
+#include <utils/Log.h>
+
+#include <ui/PixelFormat.h>
+#include <ui/Rect.h>
+#include <ui/Region.h>
+#include <ui/DisplayInfo.h>
+#include <ui/GraphicBufferMapper.h>
+
+#include <gui/ISurfaceComposer.h>
+#include <gui/Surface.h>
+#include <gui/SurfaceComposerClient.h>
+#include <RockchipRga.h>
+
+#include <GLES/gl.h>
+#include <GLES/glext.h>
+#include <EGL/eglext.h>
+
+#include <stdint.h>
+#include <sys/types.h>
+
+#include <system/window.h>
+
+#include <utils/Thread.h>
+
+#include <EGL/egl.h>
+#include <GLES/gl.h>
+
+///////////////////////////////////////////////////////
+//#include "../drmrga.h"
+#include <hardware/hardware.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <time.h>
+#include <unistd.h>
+
+#include <sys/mman.h>
+#include <linux/stddef.h>
+#include "RockchipFileOps.h"
+///////////////////////////////////////////////////////
+
+using namespace android;
+
+int main()
+{
+ int ret = 0;
+ int srcWidth,srcHeight,srcFormat;
+ int dstWidth,dstHeight,dstFormat;
+
+ srcWidth = 1920;
+ srcHeight = 1080;
+ srcFormat = HAL_PIXEL_FORMAT_RGBA_8888;
+
+ dstWidth = 1920;
+ dstHeight = 1080;
+ dstFormat = HAL_PIXEL_FORMAT_RGBA_8888;
+
+ RockchipRga& rkRga(RockchipRga::get());
+
+ GraphicBufferMapper &mgbMapper = GraphicBufferMapper::get();
+
+
+ char* buf = NULL;
+ sp<GraphicBuffer> gbs(new GraphicBuffer(srcWidth,srcHeight,srcFormat,
+ GRALLOC_USAGE_SW_WRITE_OFTEN));
+
+ if (gbs->initCheck()) {
+ printf("GraphicBuffer error : %s\n",strerror(errno));
+ return ret;
+ } else
+ printf("GraphicBuffer ok : %s\n","*************************************");
+
+
+ sp<GraphicBuffer> gbd(new GraphicBuffer(dstWidth,dstHeight,dstFormat,
+ GRALLOC_USAGE_SW_WRITE_OFTEN));
+
+ if (gbd->initCheck()) {
+ printf("GraphicBuffer error : %s\n",strerror(errno));
+ return ret;
+ } else
+ printf("GraphicBuffer ok : %s\n","*************************************");
+
+
+ mgbMapper.registerBuffer(gbs->handle);
+ mgbMapper.registerBuffer(gbd->handle);
+
+ ret = gbs->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)&buf);
+
+ if (ret) {
+ printf("lock buffer error : %s\n",strerror(errno));
+ return ret;
+ } else
+ printf("lock buffer ok : %s\n","**************************************");
+
+#if 1
+ get_buf_from_file(buf, srcFormat, srcWidth, srcHeight, 0);
+#else
+ memset(buf,0x55,4*1200*1920);
+#endif
+ ret = gbs->unlock();
+ ret = gbs->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)&buf);
+ if (ret) {
+ printf("unlock buffer error : %s\n",strerror(errno));
+ return ret;
+ } else
+ printf("unlock buffer ok : %s\n","*************************************");
+
+ while(1) {
+
+ //ret = rkRga.RkRgaBlit(gbs->handle, gbd->handle, NULL, 0, 0);
+ rga_info_t src;
+ rga_info_t dst;
+ memset(&src, 0, sizeof(rga_info_t));
+ src.fd = -1;
+ memset(&dst, 0, sizeof(rga_info_t));
+ dst.fd = -1;
+ src.hnd = gbs->handle;
+ dst.hnd = gbd->handle;
+ ret = rkRga.RkRgaBlit(&src, &dst, NULL);
+
+ if (ret) {
+ printf("rgaFillColor error : %s,hnd=%p\n",
+ strerror(errno),(void*)(gbd->handle));
+ ALOGD("rgaFillColor error : %s,hnd=%p\n",
+ strerror(errno),(void*)(gbd->handle));
+ }
+
+ {
+ char* dstbuf = NULL;
+ ret = gbd->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)&dstbuf);
+ //for(int i =0; i < mHeight * 1.5; i++)
+ // memcpy(dstbuf + i * 2400,buf + i * 3000,2400);
+ output_buf_data_to_file(dstbuf, dstFormat, dstWidth, dstHeight, 0);
+ ret = gbd->unlock();
+ }
+ printf("threadloop\n");
+ usleep(500000);
+ break;
+ }
+ return 0;
+}
diff --git a/tests/RockchipRgaCovertRgb565ToYuv.cpp b/tests/RockchipRgaCovertRgb565ToYuv.cpp
new file mode 100644
index 0000000..f18c561
--- /dev/null
+++ b/tests/RockchipRgaCovertRgb565ToYuv.cpp
@@ -0,0 +1,177 @@
+/*
+ * Copyright (C) 2016 Rockchip Electronics Co.Ltd
+ * Authors:
+ * Zhiqin Wei <wzq@rock-chips.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ */
+
+#define LOG_NDEBUG 0
+#define LOG_TAG "RockchipRgaStereo"
+
+#include <stdint.h>
+#include <sys/types.h>
+#include <math.h>
+#include <fcntl.h>
+#include <utils/misc.h>
+#include <signal.h>
+#include <time.h>
+
+#include <cutils/properties.h>
+
+#include <binder/IPCThreadState.h>
+#include <utils/Atomic.h>
+#include <utils/Errors.h>
+#include <utils/Log.h>
+
+#include <ui/PixelFormat.h>
+#include <ui/Rect.h>
+#include <ui/Region.h>
+#include <ui/DisplayInfo.h>
+#include <ui/GraphicBufferMapper.h>
+
+#include <gui/ISurfaceComposer.h>
+#include <gui/Surface.h>
+#include <gui/SurfaceComposerClient.h>
+#include <RockchipRga.h>
+
+#include <GLES/gl.h>
+#include <GLES/glext.h>
+#include <EGL/eglext.h>
+
+#include <stdint.h>
+#include <sys/types.h>
+
+#include <system/window.h>
+
+#include <utils/Thread.h>
+
+#include <EGL/egl.h>
+#include <GLES/gl.h>
+
+///////////////////////////////////////////////////////
+//#include "../drmrga.h"
+#include <hardware/hardware.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <time.h>
+#include <unistd.h>
+
+#include <sys/mman.h>
+#include <linux/stddef.h>
+#include "RockchipFileOps.h"
+///////////////////////////////////////////////////////
+
+using namespace android;
+
+int main()
+{
+ int ret = 0;
+ int srcWidth,srcHeight,srcFormat;
+ int dstWidth,dstHeight,dstFormat;
+
+ srcWidth = 1440;
+ srcHeight = 1440;
+ srcFormat = HAL_PIXEL_FORMAT_RGB_565;
+
+ dstWidth = 1440;
+ dstHeight = 1440;
+ //dstFormat = HAL_PIXEL_FORMAT_YCrCb_NV12;
+ dstFormat = HAL_PIXEL_FORMAT_RGB_565;
+
+ RockchipRga& rkRga(RockchipRga::get());
+
+ GraphicBufferMapper &mgbMapper = GraphicBufferMapper::get();
+
+
+ char* buf = NULL;
+ sp<GraphicBuffer> gbs(new GraphicBuffer(srcWidth,srcHeight,srcFormat,
+ GRALLOC_USAGE_SW_WRITE_OFTEN));
+
+ if (gbs->initCheck()) {
+ printf("GraphicBuffer error : %s\n",strerror(errno));
+ return ret;
+ } else
+ printf("GraphicBuffer ok : %s\n","*************************************");
+
+
+ sp<GraphicBuffer> gbd(new GraphicBuffer(dstWidth,dstHeight,dstFormat,
+ GRALLOC_USAGE_SW_WRITE_OFTEN));
+
+ if (gbd->initCheck()) {
+ printf("GraphicBuffer error : %s\n",strerror(errno));
+ return ret;
+ } else
+ printf("GraphicBuffer ok : %s\n","*************************************");
+
+
+ mgbMapper.registerBuffer(gbs->handle);
+ mgbMapper.registerBuffer(gbd->handle);
+
+ ret = gbs->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)&buf);
+
+ if (ret) {
+ printf("lock buffer error : %s\n",strerror(errno));
+ return ret;
+ } else
+ printf("lock buffer ok : %s\n","**************************************");
+
+#if 1
+ get_buf_from_file(buf, srcFormat, srcWidth, srcHeight, 0);
+#else
+ memset(buf,0x55,4*1200*1920);
+#endif
+ ret = gbs->unlock();
+ ret = gbs->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)&buf);
+ if (ret) {
+ printf("unlock buffer error : %s\n",strerror(errno));
+ return ret;
+ } else
+ printf("unlock buffer ok : %s\n","*************************************");
+
+ while(1) {
+ static int count = 0;
+ //drm_rga_t rects;
+ //memset(&rects, 0, sizeof(drm_rga_t));
+ //rga_set_rect(&rects.src, 0, 0, 1920, 1088, 1920, 21);
+ //rga_set_rect(&rects.dst, 200, 120, 1520, 800, 1920, 1);
+ //ret = rkRga.RkRgaBlit(gbs->handle, gbd->handle, 0, HAL_TRANSFORM_ROT_180, 0);
+ rga_info_t src;
+ rga_info_t dst;
+ memset(&src, 0, sizeof(rga_info_t));
+ src.fd = -1;
+ memset(&dst, 0, sizeof(rga_info_t));
+ dst.fd = -1;
+ src.hnd = gbs->handle;
+ dst.hnd = gbd->handle;
+ ret = rkRga.RkRgaBlit(&src, &dst, NULL);
+
+ if (ret) {
+ printf("rgaFillColor error : %s,hnd=%p\n",
+ strerror(errno),(void*)(gbd->handle));
+ ALOGD("rgaFillColor error : %s,hnd=%p\n",
+ strerror(errno),(void*)(gbd->handle));
+ }
+
+ {
+ char* dstbuf = NULL;
+ ret = gbd->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)&dstbuf);
+ //for(int i =0; i < mHeight * 1.5; i++)
+ // memcpy(dstbuf + i * 2400,buf + i * 3000,2400);
+ output_buf_data_to_file(dstbuf, dstFormat, dstWidth, dstHeight, 0);
+ ret = gbd->unlock();
+ }
+ count ++;
+ printf("threadloop\n");
+ usleep(500000);
+ if (count > 1)
+ break;
+ }
+ return 0;
+}
diff --git a/tests/RockchipRgaCovertRgbaToYuv.cpp b/tests/RockchipRgaCovertRgbaToYuv.cpp
new file mode 100644
index 0000000..97ba2d4
--- /dev/null
+++ b/tests/RockchipRgaCovertRgbaToYuv.cpp
@@ -0,0 +1,177 @@
+/*
+ * Copyright (C) 2016 Rockchip Electronics Co.Ltd
+ * Authors:
+ * Zhiqin Wei <wzq@rock-chips.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ */
+
+#define LOG_NDEBUG 0
+#define LOG_TAG "RockchipRgaStereo"
+
+#include <stdint.h>
+#include <sys/types.h>
+#include <math.h>
+#include <fcntl.h>
+#include <utils/misc.h>
+#include <signal.h>
+#include <time.h>
+
+#include <cutils/properties.h>
+
+#include <binder/IPCThreadState.h>
+#include <utils/Atomic.h>
+#include <utils/Errors.h>
+#include <utils/Log.h>
+
+#include <ui/PixelFormat.h>
+#include <ui/Rect.h>
+#include <ui/Region.h>
+#include <ui/DisplayInfo.h>
+#include <ui/GraphicBufferMapper.h>
+
+#include <gui/ISurfaceComposer.h>
+#include <gui/Surface.h>
+#include <gui/SurfaceComposerClient.h>
+#include <RockchipRga.h>
+
+#include <GLES/gl.h>
+#include <GLES/glext.h>
+#include <EGL/eglext.h>
+
+#include <stdint.h>
+#include <sys/types.h>
+
+#include <system/window.h>
+
+#include <utils/Thread.h>
+
+#include <EGL/egl.h>
+#include <GLES/gl.h>
+
+///////////////////////////////////////////////////////
+//#include "../drmrga.h"
+#include <hardware/hardware.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <time.h>
+#include <unistd.h>
+
+#include <sys/mman.h>
+#include <linux/stddef.h>
+#include "RockchipFileOps.h"
+///////////////////////////////////////////////////////
+
+using namespace android;
+
+int main()
+{
+ int ret = 0;
+ int srcWidth,srcHeight,srcFormat;
+ int dstWidth,dstHeight,dstFormat;
+
+ srcWidth = 2048;
+ srcHeight = 1536;
+ srcFormat = HAL_PIXEL_FORMAT_RGBA_8888;
+
+ dstWidth = 2048;
+ dstHeight = 1536;
+ dstFormat = HAL_PIXEL_FORMAT_YCrCb_NV12;
+ //dstFormat = HAL_PIXEL_FORMAT_RGBA_8888;
+
+ RockchipRga& rkRga(RockchipRga::get());
+
+ GraphicBufferMapper &mgbMapper = GraphicBufferMapper::get();
+
+
+ char* buf = NULL;
+ sp<GraphicBuffer> gbs(new GraphicBuffer(srcWidth,srcHeight,srcFormat,
+ GRALLOC_USAGE_SW_WRITE_OFTEN));
+
+ if (gbs->initCheck()) {
+ printf("GraphicBuffer error : %s\n",strerror(errno));
+ return ret;
+ } else
+ printf("GraphicBuffer ok : %s\n","*************************************");
+
+
+ sp<GraphicBuffer> gbd(new GraphicBuffer(dstWidth,dstHeight,dstFormat,
+ GRALLOC_USAGE_SW_WRITE_OFTEN));
+
+ if (gbd->initCheck()) {
+ printf("GraphicBuffer error : %s\n",strerror(errno));
+ return ret;
+ } else
+ printf("GraphicBuffer ok : %s\n","*************************************");
+
+
+ mgbMapper.registerBuffer(gbs->handle);
+ mgbMapper.registerBuffer(gbd->handle);
+
+ ret = gbs->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)&buf);
+
+ if (ret) {
+ printf("lock buffer error : %s\n",strerror(errno));
+ return ret;
+ } else
+ printf("lock buffer ok : %s\n","**************************************");
+
+#if 1
+ get_buf_from_file(buf, srcFormat, srcWidth, srcHeight, 0);
+#else
+ memset(buf,0x55,4*1200*1920);
+#endif
+ ret = gbs->unlock();
+ ret = gbs->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)&buf);
+ if (ret) {
+ printf("unlock buffer error : %s\n",strerror(errno));
+ return ret;
+ } else
+ printf("unlock buffer ok : %s\n","*************************************");
+
+ while(1) {
+ static int count = 0;
+ //drm_rga_t rects;
+ //memset(&rects, 0, sizeof(drm_rga_t));
+ //rga_set_rect(&rects.src, 0, 0, 1920, 1088, 1920, 21);
+ //rga_set_rect(&rects.dst, 200, 120, 1520, 800, 1920, 1);
+ //ret = rkRga.RkRgaBlit(gbs->handle, gbd->handle, 0, HAL_TRANSFORM_ROT_180, 0);
+ rga_info_t src;
+ rga_info_t dst;
+ memset(&src, 0, sizeof(rga_info_t));
+ src.fd = -1;
+ memset(&dst, 0, sizeof(rga_info_t));
+ dst.fd = -1;
+ src.hnd = gbs->handle;
+ dst.hnd = gbd->handle;
+ ret = rkRga.RkRgaBlit(&src, &dst, NULL);
+
+ if (ret) {
+ printf("rgaFillColor error : %s,hnd=%p\n",
+ strerror(errno),(void*)(gbd->handle));
+ ALOGD("rgaFillColor error : %s,hnd=%p\n",
+ strerror(errno),(void*)(gbd->handle));
+ }
+
+ {
+ char* dstbuf = NULL;
+ ret = gbd->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)&dstbuf);
+ //for(int i =0; i < mHeight * 1.5; i++)
+ // memcpy(dstbuf + i * 2400,buf + i * 3000,2400);
+ output_buf_data_to_file(dstbuf, dstFormat, dstWidth, dstHeight, 0);
+ ret = gbd->unlock();
+ }
+ count ++;
+ printf("threadloop\n");
+ usleep(500000);
+ if (count > 1)
+ break;
+ }
+ return 0;
+}
diff --git a/tests/RockchipRgaCovertYuvTenBitToNormalYuv.cpp b/tests/RockchipRgaCovertYuvTenBitToNormalYuv.cpp
new file mode 100644
index 0000000..6cce0ec
--- /dev/null
+++ b/tests/RockchipRgaCovertYuvTenBitToNormalYuv.cpp
@@ -0,0 +1,195 @@
+/*
+ * Copyright (C) 2016 Rockchip Electronics Co.Ltd
+ * Authors:
+ * Zhiqin Wei <wzq@rock-chips.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ */
+
+#define LOG_NDEBUG 0
+#define LOG_TAG "RockchipRgaStereo"
+
+#include <stdint.h>
+#include <sys/types.h>
+#include <math.h>
+#include <fcntl.h>
+#include <utils/misc.h>
+#include <signal.h>
+#include <time.h>
+
+#include <cutils/properties.h>
+
+#include <binder/IPCThreadState.h>
+#include <utils/Atomic.h>
+#include <utils/Errors.h>
+#include <utils/Log.h>
+
+#include <ui/PixelFormat.h>
+#include <ui/Rect.h>
+#include <ui/Region.h>
+#include <ui/DisplayInfo.h>
+#include <ui/GraphicBufferMapper.h>
+#include <RockchipRga.h>
+
+#include <gui/ISurfaceComposer.h>
+#include <gui/Surface.h>
+#include <gui/SurfaceComposerClient.h>
+
+#include <GLES/gl.h>
+#include <GLES/glext.h>
+#include <EGL/eglext.h>
+
+#include <stdint.h>
+#include <sys/types.h>
+
+#include <system/window.h>
+
+#include <utils/Thread.h>
+
+#include <EGL/egl.h>
+#include <GLES/gl.h>
+
+///////////////////////////////////////////////////////
+//#include "../drmrga.h"
+#include <hardware/hardware.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <time.h>
+#include <unistd.h>
+
+#include <sys/mman.h>
+#include <linux/stddef.h>
+#include "RockchipFileOps.h"
+///////////////////////////////////////////////////////
+
+using namespace android;
+
+int main()
+{
+ int ret = 0;
+ int srcWidth,srcHeight,srcFormat;
+ int dstWidth,dstHeight,dstFormat;
+
+ srcWidth = 1920;
+ srcHeight = 1088;
+ srcFormat = HAL_PIXEL_FORMAT_YCrCb_NV12_10;
+
+ dstWidth = 1920;
+ dstHeight = 1088;
+ dstFormat = HAL_PIXEL_FORMAT_YCrCb_NV12;
+
+ RockchipRga& rkRga(RockchipRga::get());
+
+ GraphicBufferMapper &mgbMapper = GraphicBufferMapper::get();
+
+
+ char* buf = NULL;
+ sp<GraphicBuffer> gbs(new GraphicBuffer(srcWidth,srcHeight,srcFormat,
+ GRALLOC_USAGE_SW_WRITE_OFTEN));
+
+ if (gbs->initCheck()) {
+ printf("GraphicBuffer error : %s\n",strerror(errno));
+ return ret;
+ } else
+ printf("GraphicBuffer ok : %s\n","*************************************");
+
+
+ sp<GraphicBuffer> gbd(new GraphicBuffer(dstWidth,dstHeight,dstFormat,
+ GRALLOC_USAGE_SW_WRITE_OFTEN));
+
+ if (gbd->initCheck()) {
+ printf("GraphicBuffer error : %s\n",strerror(errno));
+ return ret;
+ } else
+ printf("GraphicBuffer ok : %s\n","*************************************");
+
+
+ mgbMapper.registerBuffer(gbs->handle);
+ mgbMapper.registerBuffer(gbd->handle);
+
+ ret = gbs->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)&buf);
+
+ if (ret) {
+ printf("lock buffer error : %s\n",strerror(errno));
+ return ret;
+ } else
+ printf("lock buffer ok : %s\n","**************************************");
+
+#if 1
+ get_buf_from_file(buf, srcFormat, srcWidth, srcHeight, 0);
+#else
+ memset(buf,0x55,4*1200*1920);
+#endif
+ ret = gbs->unlock();
+ ret = gbs->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)&buf);
+ if (ret) {
+ printf("unlock buffer error : %s\n",strerror(errno));
+ return ret;
+ } else
+ printf("unlock buffer ok : %s\n","*************************************");
+#define USE_HANDLE 1
+ while(1) {
+ rga_info_t src;
+ rga_info_t dst;
+ memset(&src, 0, sizeof(rga_info_t));
+ src.fd = -1;
+ src.mmuFlag = 1;
+ memset(&dst, 0, sizeof(rga_info_t));
+ dst.fd = -1;
+ dst.mmuFlag = 1;
+#if USE_HANDLE
+ src.hnd = gbs->handle;
+ dst.hnd = gbd->handle;
+ /*just to try scal the target buffer: ok to support scale*/
+ //rga_set_rect(&dst.rect, 0,0,1280,720,1280/*stride*/,dstFormat);
+ //ALOGD("%p,%p,%d,%d",src.hnd,gbs->handle,src.hnd->version,gbs->handle->version);
+#else //use fd
+ ret = rkRga.RkRgaGetBufferFd(gbs->handle, &src.fd);
+ if (ret) {
+ printf("rgaFillColor error : %s,hnd=%p\n",
+ strerror(errno),(void*)(gbd->handle));
+ ALOGD("rgaFillColor error : %s,hnd=%p\n",
+ strerror(errno),(void*)(gbd->handle));
+ }
+ ret = rkRga.RkRgaGetBufferFd(gbd->handle, &dst.fd);
+ if (ret) {
+ printf("rgaFillColor error : %s,hnd=%p\n",
+ strerror(errno),(void*)(gbd->handle));
+ ALOGD("rgaFillColor error : %s,hnd=%p\n",
+ strerror(errno),(void*)(gbd->handle));
+ }
+
+ //if use fd we need give the rect use handle rect is first else will get if
+ //from handle.handle has the info fo w h stride format and so on
+ rga_set_rect(&src.rect, 0,0,srcWidth,srcHeight,srcWidth/*stride*/,srcFormat);
+ rga_set_rect(&dst.rect, 0,0,dstWidth,dstHeight,dstWidth/*stride*/,dstFormat);
+#endif
+ ret = rkRga.RkRgaBlit(&src, &dst, NULL);
+
+ if (ret) {
+ printf("rgaFillColor error : %s,hnd=%p\n",
+ strerror(errno),(void*)(gbd->handle));
+ ALOGD("rgaFillColor error : %s,hnd=%p\n",
+ strerror(errno),(void*)(gbd->handle));
+ }
+
+ {
+ char* dstbuf = NULL;
+ ret = gbd->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)&dstbuf);
+ //for(int i =0; i < mHeight * 1.5; i++)
+ // memcpy(dstbuf + i * 2400,buf + i * 3000,2400);
+ output_buf_data_to_file(dstbuf, dstFormat, dstWidth, dstHeight, 0);
+ ret = gbd->unlock();
+ }
+ printf("threadloop\n");
+ usleep(500000);
+ break;
+ }
+ return 0;
+}
diff --git a/tests/RockchipRgaCovertYuvToRgba.cpp b/tests/RockchipRgaCovertYuvToRgba.cpp
new file mode 100644
index 0000000..3865a34
--- /dev/null
+++ b/tests/RockchipRgaCovertYuvToRgba.cpp
@@ -0,0 +1,176 @@
+/*
+ * Copyright (C) 2016 Rockchip Electronics Co.Ltd
+ * Authors:
+ * Zhiqin Wei <wzq@rock-chips.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ */
+
+#define LOG_NDEBUG 0
+#define LOG_TAG "RockchipRgaStereo"
+
+#include <stdint.h>
+#include <sys/types.h>
+#include <math.h>
+#include <fcntl.h>
+#include <utils/misc.h>
+#include <signal.h>
+#include <time.h>
+
+#include <cutils/properties.h>
+
+#include <binder/IPCThreadState.h>
+#include <utils/Atomic.h>
+#include <utils/Errors.h>
+#include <utils/Log.h>
+
+#include <ui/PixelFormat.h>
+#include <ui/Rect.h>
+#include <ui/Region.h>
+#include <ui/DisplayInfo.h>
+#include <ui/GraphicBufferMapper.h>
+
+#include <gui/ISurfaceComposer.h>
+#include <gui/Surface.h>
+#include <gui/SurfaceComposerClient.h>
+#include <RockchipRga.h>
+
+#include <GLES/gl.h>
+#include <GLES/glext.h>
+#include <EGL/eglext.h>
+
+#include <stdint.h>
+#include <sys/types.h>
+
+#include <system/window.h>
+
+#include <utils/Thread.h>
+
+#include <EGL/egl.h>
+#include <GLES/gl.h>
+
+///////////////////////////////////////////////////////
+//#include "../drmrga.h"
+#include <hardware/hardware.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <time.h>
+#include <unistd.h>
+
+#include <sys/mman.h>
+#include <linux/stddef.h>
+#include "RockchipFileOps.h"
+///////////////////////////////////////////////////////
+
+using namespace android;
+
+int main()
+{
+ int ret = 0;
+ int srcWidth,srcHeight,srcFormat;
+ int dstWidth,dstHeight,dstFormat;
+
+ srcWidth = 1920;
+ srcHeight = 1088;
+ srcFormat = HAL_PIXEL_FORMAT_YCrCb_NV12;
+
+ dstWidth = 1920;
+ dstHeight = 1080;
+ dstFormat = HAL_PIXEL_FORMAT_RGBA_8888;
+
+ RockchipRga& rkRga(RockchipRga::get());
+
+ GraphicBufferMapper &mgbMapper = GraphicBufferMapper::get();
+
+
+ char* buf = NULL;
+ sp<GraphicBuffer> gbs(new GraphicBuffer(srcWidth,srcHeight,srcFormat,
+ GRALLOC_USAGE_SW_WRITE_OFTEN));
+
+ if (gbs->initCheck()) {
+ printf("GraphicBuffer error : %s\n",strerror(errno));
+ return ret;
+ } else
+ printf("GraphicBuffer ok : %s\n","*************************************");
+
+
+ sp<GraphicBuffer> gbd(new GraphicBuffer(dstWidth,dstHeight,dstFormat,
+ GRALLOC_USAGE_SW_WRITE_OFTEN));
+
+ if (gbd->initCheck()) {
+ printf("GraphicBuffer error : %s\n",strerror(errno));
+ return ret;
+ } else
+ printf("GraphicBuffer ok : %s\n","*************************************");
+
+
+ mgbMapper.registerBuffer(gbs->handle);
+ mgbMapper.registerBuffer(gbd->handle);
+
+ ret = gbs->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)&buf);
+
+ if (ret) {
+ printf("lock buffer error : %s\n",strerror(errno));
+ return ret;
+ } else
+ printf("lock buffer ok : %s\n","**************************************");
+
+#if 1
+ get_buf_from_file(buf, srcFormat, srcWidth, srcHeight, 0);
+#else
+ memset(buf,0x55,4*1200*1920);
+#endif
+ ret = gbs->unlock();
+ ret = gbs->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)&buf);
+ if (ret) {
+ printf("unlock buffer error : %s\n",strerror(errno));
+ return ret;
+ } else
+ printf("unlock buffer ok : %s\n","*************************************");
+
+ while(1) {
+ static int count = 0;
+ //drm_rga_t rects;
+ //memset(&rects, 0, sizeof(drm_rga_t));
+ //rga_set_rect(&rects.src, 0, 0, 1920, 1088, 1920, 21);
+ //rga_set_rect(&rects.dst, 200, 120, 1520, 800, 1920, 1);
+ //ret = rkRga.RkRgaBlit(gbs->handle, gbd->handle, 0, HAL_TRANSFORM_ROT_180, 0);
+ rga_info_t src;
+ rga_info_t dst;
+ memset(&src, 0, sizeof(rga_info_t));
+ src.fd = -1;
+ memset(&dst, 0, sizeof(rga_info_t));
+ dst.fd = -1;
+ src.hnd = gbs->handle;
+ dst.hnd = gbd->handle;
+ ret = rkRga.RkRgaBlit(&src, &dst, NULL);
+
+ if (ret) {
+ printf("rgaFillColor error : %s,hnd=%p\n",
+ strerror(errno),(void*)(gbd->handle));
+ ALOGD("rgaFillColor error : %s,hnd=%p\n",
+ strerror(errno),(void*)(gbd->handle));
+ }
+
+ {
+ char* dstbuf = NULL;
+ ret = gbd->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)&dstbuf);
+ //for(int i =0; i < mHeight * 1.5; i++)
+ // memcpy(dstbuf + i * 2400,buf + i * 3000,2400);
+ output_buf_data_to_file(dstbuf, dstFormat, dstWidth, dstHeight, 0);
+ ret = gbd->unlock();
+ }
+ count ++;
+ printf("threadloop\n");
+ usleep(500000);
+ if (count > 1)
+ break;
+ }
+ return 0;
+}
diff --git a/tests/RockchipRgaPattenBuff.cpp b/tests/RockchipRgaPattenBuff.cpp
new file mode 100644
index 0000000..18e993d
--- /dev/null
+++ b/tests/RockchipRgaPattenBuff.cpp
@@ -0,0 +1,175 @@
+/*
+ * Copyright (C) 2016 Rockchip Electronics Co.Ltd
+ * Authors:
+ * Zhiqin Wei <wzq@rock-chips.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ */
+
+#define LOG_NDEBUG 0
+#define LOG_TAG "RockchipRgaStereo"
+
+#include <stdint.h>
+#include <sys/types.h>
+#include <math.h>
+#include <fcntl.h>
+#include <utils/misc.h>
+#include <signal.h>
+#include <time.h>
+
+#include <cutils/properties.h>
+
+#include <binder/IPCThreadState.h>
+#include <utils/Atomic.h>
+#include <utils/Errors.h>
+#include <utils/Log.h>
+
+#include <ui/PixelFormat.h>
+#include <ui/Rect.h>
+#include <ui/Region.h>
+#include <ui/DisplayInfo.h>
+#include <ui/GraphicBufferMapper.h>
+
+#include <gui/ISurfaceComposer.h>
+#include <gui/Surface.h>
+#include <gui/SurfaceComposerClient.h>
+#include <RockchipRga.h>
+
+#include <GLES/gl.h>
+#include <GLES/glext.h>
+#include <EGL/eglext.h>
+
+#include <stdint.h>
+#include <sys/types.h>
+
+#include <system/window.h>
+
+#include <utils/Thread.h>
+
+#include <EGL/egl.h>
+#include <GLES/gl.h>
+
+///////////////////////////////////////////////////////
+//#include "../drmrga.h"
+#include <hardware/hardware.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <time.h>
+#include <unistd.h>
+
+#include <sys/mman.h>
+#include <linux/stddef.h>
+#include "RockchipFileOps.h"
+///////////////////////////////////////////////////////
+
+using namespace android;
+
+int main()
+{
+ int ret = 0;
+ int srcWidth,srcHeight,srcFormat;
+ int dstWidth,dstHeight,dstFormat;
+
+ srcWidth = 1920;
+ srcHeight = 1080;
+ srcFormat = HAL_PIXEL_FORMAT_RGBA_8888;
+
+ dstWidth = 1920;
+ dstHeight = 1080;
+ dstFormat = HAL_PIXEL_FORMAT_RGBA_8888;
+
+ RockchipRga& rkRga(RockchipRga::get());
+
+ GraphicBufferMapper &mgbMapper = GraphicBufferMapper::get();
+
+
+ char* buf = NULL;
+ sp<GraphicBuffer> gbs(new GraphicBuffer(srcWidth,srcHeight,srcFormat,
+ GRALLOC_USAGE_SW_WRITE_OFTEN));
+
+ if (gbs->initCheck()) {
+ printf("GraphicBuffer error : %s\n",strerror(errno));
+ return ret;
+ } else
+ printf("GraphicBuffer ok : %s\n","*************************************");
+
+
+ sp<GraphicBuffer> gbd(new GraphicBuffer(dstWidth,dstHeight,dstFormat,
+ GRALLOC_USAGE_SW_WRITE_OFTEN));
+
+ if (gbd->initCheck()) {
+ printf("GraphicBuffer error : %s\n",strerror(errno));
+ return ret;
+ } else
+ printf("GraphicBuffer ok : %s\n","*************************************");
+
+
+ mgbMapper.registerBuffer(gbs->handle);
+ mgbMapper.registerBuffer(gbd->handle);
+
+ ret = gbs->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)&buf);
+
+ if (ret) {
+ printf("lock buffer error : %s\n",strerror(errno));
+ return ret;
+ } else
+ printf("lock buffer ok : %s\n","**************************************");
+
+#if 1
+ get_buf_from_file(buf, srcFormat, srcWidth, srcHeight, 0);
+#else
+ memset(buf,0x55,4*1200*1920);
+#endif
+ ret = gbs->unlock();
+ ret = gbs->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)&buf);
+ if (ret) {
+ printf("unlock buffer error : %s\n",strerror(errno));
+ return ret;
+ } else
+ printf("unlock buffer ok : %s\n","*************************************");
+
+ while(1) {
+ //drm_rga_t rects;
+ //memset(&rects, 0, sizeof(drm_rga_t));
+ //rga_set_rect(&rects.src, 0, 0, 1920, 1088, 1920, 21);
+ //rga_set_rect(&rects.dst, 200, 120, 1520, 800, 1920, 1);
+ //rkRga.RkRgaSetLogOnceFlag(1);
+ //ret = rkRga.RkRgaPaletteTable(gbd->handle, 0x8855aa03, &rects);
+
+ rga_info_t src;
+ rga_info_t dst;
+ memset(&src, 0, sizeof(rga_info_t));
+ src.fd = -1;
+ memset(&dst, 0, sizeof(rga_info_t));
+ dst.fd = -1;
+ src.hnd = gbs->handle;
+ dst.hnd = gbd->handle;
+ ret = rkRga.RkRgaBlit(&src, &dst, NULL);
+
+ if (ret) {
+ printf("rgaFillColor error : %s,hnd=%p\n",
+ strerror(errno),(void*)(gbd->handle));
+ ALOGD("rgaFillColor error : %s,hnd=%p\n",
+ strerror(errno),(void*)(gbd->handle));
+ }
+
+ {
+ char* dstbuf = NULL;
+ ret = gbd->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)&dstbuf);
+ //for(int i =0; i < mHeight * 1.5; i++)
+ // memcpy(dstbuf + i * 2400,buf + i * 3000,2400);
+ output_buf_data_to_file(dstbuf, dstFormat, dstWidth, dstHeight, 0);
+ ret = gbd->unlock();
+ }
+ printf("threadloop\n");
+ usleep(500000);
+ break;
+ }
+ return 0;
+}
diff --git a/tests/RockchipRgaRgbaMirror.cpp b/tests/RockchipRgaRgbaMirror.cpp
new file mode 100644
index 0000000..453d236
--- /dev/null
+++ b/tests/RockchipRgaRgbaMirror.cpp
@@ -0,0 +1,169 @@
+/*
+ * Copyright (C) 2016 Rockchip Electronics Co.Ltd
+ * Authors:
+ * Zhiqin Wei <wzq@rock-chips.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ */
+
+#define LOG_NDEBUG 0
+#define LOG_TAG "RockchipRgaStereo"
+
+#include <stdint.h>
+#include <sys/types.h>
+#include <math.h>
+#include <fcntl.h>
+#include <utils/misc.h>
+#include <signal.h>
+#include <time.h>
+
+#include <cutils/properties.h>
+
+#include <binder/IPCThreadState.h>
+#include <utils/Atomic.h>
+#include <utils/Errors.h>
+#include <utils/Log.h>
+
+#include <ui/PixelFormat.h>
+#include <ui/Rect.h>
+#include <ui/Region.h>
+#include <ui/DisplayInfo.h>
+#include <ui/GraphicBufferMapper.h>
+
+#include <gui/ISurfaceComposer.h>
+#include <gui/Surface.h>
+#include <gui/SurfaceComposerClient.h>
+#include <RockchipRga.h>
+
+#include <GLES/gl.h>
+#include <GLES/glext.h>
+#include <EGL/eglext.h>
+
+#include <stdint.h>
+#include <sys/types.h>
+
+#include <system/window.h>
+
+#include <utils/Thread.h>
+
+#include <EGL/egl.h>
+#include <GLES/gl.h>
+
+///////////////////////////////////////////////////////
+//#include "../drmrga.h"
+#include <hardware/hardware.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <time.h>
+#include <unistd.h>
+
+#include <sys/mman.h>
+#include <linux/stddef.h>
+#include "RockchipFileOps.h"
+///////////////////////////////////////////////////////
+
+using namespace android;
+
+int main()
+{
+ int ret = 0;
+ int srcWidth,srcHeight,srcFormat;
+ int dstWidth,dstHeight,dstFormat;
+
+ srcWidth = 1920;
+ srcHeight = 1080;
+ srcFormat = HAL_PIXEL_FORMAT_RGBA_8888;
+
+ dstWidth = 1920;
+ dstHeight = 1080;
+ dstFormat = HAL_PIXEL_FORMAT_RGBA_8888;
+
+ RockchipRga& rkRga(RockchipRga::get());
+
+ GraphicBufferMapper &mgbMapper = GraphicBufferMapper::get();
+
+
+ char* buf = NULL;
+ sp<GraphicBuffer> gbs(new GraphicBuffer(srcWidth,srcHeight,srcFormat,
+ GRALLOC_USAGE_SW_WRITE_OFTEN));
+
+ if (gbs->initCheck()) {
+ printf("GraphicBuffer error : %s\n",strerror(errno));
+ return ret;
+ } else
+ printf("GraphicBuffer ok : %s\n","*************************************");
+
+
+ sp<GraphicBuffer> gbd(new GraphicBuffer(dstWidth,dstHeight,dstFormat,
+ GRALLOC_USAGE_SW_WRITE_OFTEN));
+
+ if (gbd->initCheck()) {
+ printf("GraphicBuffer error : %s\n",strerror(errno));
+ return ret;
+ } else
+ printf("GraphicBuffer ok : %s\n","*************************************");
+
+
+ mgbMapper.registerBuffer(gbs->handle);
+ mgbMapper.registerBuffer(gbd->handle);
+
+ ret = gbs->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)&buf);
+
+ if (ret) {
+ printf("lock buffer error : %s\n",strerror(errno));
+ return ret;
+ } else
+ printf("lock buffer ok : %s\n","**************************************");
+
+#if 1
+ get_buf_from_file(buf, srcFormat, srcWidth, srcHeight, 0);
+#else
+ memset(buf,0x55,4*1200*1920);
+#endif
+ ret = gbs->unlock();
+ ret = gbs->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)&buf);
+ if (ret) {
+ printf("unlock buffer error : %s\n",strerror(errno));
+ return ret;
+ } else
+ printf("unlock buffer ok : %s\n","*************************************");
+
+ while(1) {
+ //int rotation = HAL_TRANSFORM_FLIP_H;
+ //ret = rkRga.RkRgaBlit(gbs->handle, gbd->handle, NULL, rotation, 0);
+ rga_info_t src;
+ rga_info_t dst;
+ memset(&src, 0, sizeof(rga_info_t));
+ src.fd = -1;
+ memset(&dst, 0, sizeof(rga_info_t));
+ dst.fd = -1;
+ src.hnd = gbs->handle;
+ dst.hnd = gbd->handle;
+ ret = rkRga.RkRgaBlit(&src, &dst, NULL);
+ if (ret) {
+ printf("rgaFillColor error : %s,hnd=%p\n",
+ strerror(errno),(void*)(gbd->handle));
+ ALOGD("rgaFillColor error : %s,hnd=%p\n",
+ strerror(errno),(void*)(gbd->handle));
+ }
+
+ {
+ char* dstbuf = NULL;
+ ret = gbd->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)&dstbuf);
+ //for(int i =0; i < mHeight * 1.5; i++)
+ // memcpy(dstbuf + i * 2400,buf + i * 3000,2400);
+ output_buf_data_to_file(dstbuf, dstFormat, dstWidth, dstHeight, 0);
+ ret = gbd->unlock();
+ }
+ printf("threadloop\n");
+ usleep(500000);
+ break;
+ }
+ return 0;
+}
diff --git a/tests/RockchipRgaStereo.cpp b/tests/RockchipRgaStereo.cpp
new file mode 100644
index 0000000..82d0d89
--- /dev/null
+++ b/tests/RockchipRgaStereo.cpp
@@ -0,0 +1,187 @@
+/*
+ * Copyright (C) 2016 Rockchip Electronics Co.Ltd
+ * Authors:
+ * Zhiqin Wei <wzq@rock-chips.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ */
+
+#define LOG_NDEBUG 0
+#define LOG_TAG "RockchipRgaStereo"
+
+#include <stdint.h>
+#include <sys/types.h>
+#include <math.h>
+#include <fcntl.h>
+#include <utils/misc.h>
+#include <signal.h>
+#include <time.h>
+
+#include <cutils/properties.h>
+
+#include <binder/IPCThreadState.h>
+#include <utils/Atomic.h>
+#include <utils/Errors.h>
+#include <utils/Log.h>
+
+#include <ui/PixelFormat.h>
+#include <ui/Rect.h>
+#include <ui/Region.h>
+#include <ui/DisplayInfo.h>
+#include <ui/GraphicBufferMapper.h>
+
+#include <gui/ISurfaceComposer.h>
+#include <gui/Surface.h>
+#include <gui/SurfaceComposerClient.h>
+#include <RockchipRga.h>
+
+#include <GLES/gl.h>
+#include <GLES/glext.h>
+#include <EGL/eglext.h>
+
+#include <stdint.h>
+#include <sys/types.h>
+
+#include <system/window.h>
+
+#include <utils/Thread.h>
+
+#include <EGL/egl.h>
+#include <GLES/gl.h>
+
+///////////////////////////////////////////////////////
+//#include "../drmrga.h"
+#include <hardware/hardware.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <time.h>
+#include <unistd.h>
+
+#include <sys/mman.h>
+#include <linux/stddef.h>
+#include "RockchipFileOps.h"
+///////////////////////////////////////////////////////
+
+using namespace android;
+
+int main()
+{
+ int ret = 0;
+
+ int srcWidth,srcHeight,srcFormat;
+ int dstWidth,dstHeight,dstFormat;
+
+ srcWidth = 1920;
+ srcHeight = 1088;
+ srcFormat = HAL_PIXEL_FORMAT_YCrCb_NV12;
+
+ dstWidth = 3840;
+ dstHeight = 1080;
+ dstFormat = HAL_PIXEL_FORMAT_RGBA_8888;
+
+ RockchipRga& rkRga(RockchipRga::get());
+
+ GraphicBufferMapper &mgbMapper = GraphicBufferMapper::get();
+
+
+ char* buf = NULL;
+ sp<GraphicBuffer> gbs(new GraphicBuffer(srcWidth, srcHeight, srcFormat,
+ GRALLOC_USAGE_PROTECTED | GRALLOC_USAGE_SW_WRITE_OFTEN));
+
+ if (gbs->initCheck()) {
+ printf("GraphicBuffer error : %s\n",strerror(errno));
+ return ret;
+ } else
+ printf("GraphicBuffer ok : %s\n","**************************************");
+
+
+ sp<GraphicBuffer> gbd(new GraphicBuffer(dstWidth, dstHeight, dstFormat,
+ GRALLOC_USAGE_PROTECTED | GRALLOC_USAGE_SW_WRITE_OFTEN));
+
+ if (gbd->initCheck()) {
+ printf("GraphicBuffer error : %s\n",strerror(errno));
+ return ret;
+ } else
+ printf("GraphicBuffer ok : %s\n","*************************************");
+
+
+ mgbMapper.registerBuffer(gbs->handle);
+ mgbMapper.registerBuffer(gbd->handle);
+
+ ret = gbs->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)&buf);
+
+ if (ret) {
+ printf("lock buffer error : %s\n",strerror(errno));
+ return ret;
+ } else
+ printf("lock buffer ok : %s\n","**************************************");
+
+#if 1
+ get_buf_from_file(buf, srcFormat, srcWidth, srcHeight, 0);
+#else
+ memset(buf,0x55,4*1200*1920);
+#endif
+ ret = gbs->unlock();
+ ret = gbs->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)&buf);
+ if (ret) {
+ printf("unlock buffer error : %s\n",strerror(errno));
+ return ret;
+ } else
+ printf("unlock buffer ok : %s\n","*************************************");
+
+ while(1) {
+
+ //rkRga.RkRgaSetLogOnceFlag(1);
+ //drm_rga_t rects;
+ /*******************************left***********************************/
+ //memset(&rects, 0, sizeof(drm_rga_t));
+ //rga_set_rect(&rects.src, 0, 0, srcWidth, srcHeight, srcWidth, srcFormat);
+ //rga_set_rect(&rects.dst, 0, 0, dstWidth / 2, dstHeight,
+ // dstWidth, dstFormat);
+ //ret = rkRga.RkRgaBlit(gbs->handle, gbd->handle, &rects, 0, 0);
+
+ /*******************************right**********************************/
+ //rkRga.RkRgaSetLogOnceFlag(1);
+ //rga_set_rect(&rects.src, 0, 0, srcWidth, srcHeight, srcWidth, srcFormat);
+ //rga_set_rect(&rects.dst, dstWidth / 2, 0, dstWidth / 2,
+ // dstHeight, dstWidth, dstFormat);
+ //ret = rkRga.RkRgaBlit(gbs->handle, gbd->handle, &rects, 0, 0);
+
+ rga_info_t src;
+ rga_info_t dst;
+ memset(&src, 0, sizeof(rga_info_t));
+ src.fd = -1;
+ memset(&dst, 0, sizeof(rga_info_t));
+ dst.fd = -1;
+ src.hnd = gbs->handle;
+ dst.hnd = gbd->handle;
+ ret = rkRga.RkRgaBlit(&src, &dst, NULL);
+
+
+ if (ret) {
+ printf("rgaFillColor error : %s,hnd=%p\n",
+ strerror(errno),(void*)(gbd->handle));
+ ALOGD("rgaFillColor error : %s,hnd=%p\n",
+ strerror(errno),(void*)(gbd->handle));
+ }
+
+ {
+ char* dstbuf = NULL;
+ ret = gbd->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)&dstbuf);
+ //for(int i =0; i < mHeight * 1.5; i++)
+ // memcpy(dstbuf + i * 2400,buf + i * 3000,2400);
+ output_buf_data_to_file(dstbuf, dstFormat, dstWidth, dstHeight, 0);
+ ret = gbd->unlock();
+ }
+ printf("threadloop\n");
+ usleep(500000);
+ break;
+ }
+ return 0;
+}
diff --git a/tests/RockchipRgaStereoUserSpace.cpp b/tests/RockchipRgaStereoUserSpace.cpp
new file mode 100644
index 0000000..461b9bc
--- /dev/null
+++ b/tests/RockchipRgaStereoUserSpace.cpp
@@ -0,0 +1,173 @@
+/*
+ * Copyright (C) 2016 Rockchip Electronics Co.Ltd
+ * Authors:
+ * Zhiqin Wei <wzq@rock-chips.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ */
+
+#define LOG_NDEBUG 0
+#define LOG_TAG "RockchipRgaStereo"
+
+#include <stdint.h>
+#include <sys/types.h>
+#include <math.h>
+#include <fcntl.h>
+#include <utils/misc.h>
+#include <signal.h>
+#include <time.h>
+
+#include <cutils/properties.h>
+
+#include <binder/IPCThreadState.h>
+#include <utils/Atomic.h>
+#include <utils/Errors.h>
+#include <utils/Log.h>
+
+#include <ui/PixelFormat.h>
+#include <ui/Rect.h>
+#include <ui/Region.h>
+#include <ui/DisplayInfo.h>
+#include <ui/GraphicBufferMapper.h>
+
+#include <gui/ISurfaceComposer.h>
+#include <gui/Surface.h>
+#include <gui/SurfaceComposerClient.h>
+#include <RockchipRga.h>
+
+#include <GLES/gl.h>
+#include <GLES/glext.h>
+#include <EGL/eglext.h>
+
+#include <stdint.h>
+#include <sys/types.h>
+
+#include <system/window.h>
+
+#include <utils/Thread.h>
+
+#include <EGL/egl.h>
+#include <GLES/gl.h>
+
+///////////////////////////////////////////////////////
+//#include "../drmrga.h"
+#include <hardware/hardware.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <time.h>
+#include <unistd.h>
+
+#include <sys/mman.h>
+#include <linux/stddef.h>
+#include "RockchipFileOps.h"
+///////////////////////////////////////////////////////
+
+using namespace android;
+
+int main()
+{
+ int ret = 0;
+
+ int srcWidth,srcHeight,srcFormat;
+ int dstWidth,dstHeight,dstFormat;
+
+ void *src = NULL;
+ void *dst = NULL;
+
+ srcWidth = 1920;
+ srcHeight = 1088;
+ srcFormat = HAL_PIXEL_FORMAT_YCrCb_NV12;
+
+ dstWidth = 3840;
+ dstHeight = 1080;
+ dstFormat = HAL_PIXEL_FORMAT_RGBA_8888;
+
+ src = malloc(srcWidth * srcHeight * 2);
+ if (!src)
+ return -ENOMEM;
+
+ dst = malloc(dstWidth * dstHeight * 4);
+
+ if (!dst) {
+ free(src);
+ return -ENOMEM;
+ }
+
+ RockchipRga& rkRga(RockchipRga::get());
+
+
+#if 1
+ char *buf = (char *)src;
+ const char *yuvFilePath = "/data/inputBuffer.bin";
+ FILE *file = fopen(yuvFilePath, "rb");
+ if (!file) {
+ fprintf(stderr, "Could not open %s\n", yuvFilePath);
+ return false;
+ } else
+ fprintf(stderr, "open %s ok\n", yuvFilePath);
+
+ fread(buf, 1.5 * srcWidth * srcHeight, 1, file);
+ #if 0
+ {
+ char *pbuf = (char*)malloc(2 * mHeight * 4864);
+ for (int i = 0; i < 2160 * 1.6; i++)
+ memcpy(pbuf+i*4800,buf+i*6080,4800);
+ const char *outFilePath = "/data/fb3840x2160-2.yuv";
+ FILE *file = fopen(outFilePath, "wb+");
+ if (!file) {
+ fprintf(stderr, "Could not open %s\n", outFilePath);
+ return false;
+ }
+ fwrite(pbuf, 2 * 4864 * 2160, 1, file);
+ free(pbuf);
+ fclose(file);
+ }
+ #endif
+ fclose(file);
+#else
+ memset(buf,0x55,4*1200*1920);
+#endif
+ while(1) {
+
+ //rkRga.RkRgaSetLogOnceFlag(1);
+ //drm_rga_t rects;
+ /*******************************left***********************************/
+ //memset(&rects, 0, sizeof(drm_rga_t));
+ //rga_set_rect(&rects.src, 0, 0, srcWidth, srcHeight, srcWidth, srcFormat);
+ //rga_set_rect(&rects.dst, 0, 0, dstWidth / 2, dstHeight,
+ // dstWidth, dstFormat);
+ //ret = rkRga.RkRgaBlit(src, dst, &rects, 0, 0);
+
+ /*******************************right**********************************/
+ //rkRga.RkRgaSetLogOnceFlag(1);
+ //rga_set_rect(&rects.src, 0, 0, srcWidth, srcHeight, srcWidth, srcFormat);
+ //rga_set_rect(&rects.dst, dstWidth / 2, 0, dstWidth / 2,
+ // dstHeight, dstWidth, dstFormat);
+ ret = rkRga.RkRgaBlit(NULL, NULL, NULL);
+
+
+ if (ret) {
+ printf("rgaFillColor error : %s,hnd=%p\n",
+ strerror(errno),(void*)(dst));
+ ALOGD("rgaFillColor error : %s,hnd=%p\n",
+ strerror(errno),(void*)(dst));
+ }
+
+ {
+ char* dstbuf = (char *)dst;
+ //for(int i =0; i < mHeight * 1.5; i++)
+ // memcpy(dstbuf + i * 2400,buf + i * 3000,2400);
+ output_buf_data_to_file(dstbuf, dstFormat, dstWidth, dstHeight, 0);
+ }
+ printf("threadloop\n");
+ usleep(500000);
+ break;
+ }
+ return 0;
+}
diff --git a/version.h b/version.h
new file mode 100644
index 0000000..fcb8b00
--- /dev/null
+++ b/version.h
@@ -0,0 +1,6 @@
+#ifndef _rk_graphics_version_h_
+#define _rk_graphics_version_h_
+
+#define RK_GRAPHICS_VER "version:"
+
+#endif // VERSION_H
diff --git a/version.h.template b/version.h.template
new file mode 100644
index 0000000..5c828a3
--- /dev/null
+++ b/version.h.template
@@ -0,0 +1,6 @@
+#ifndef _rk_graphics_version_h_
+#define _rk_graphics_version_h_
+
+#define RK_GRAPHICS_VER "version:$FULL_VERSION"
+
+#endif // VERSION_H
diff --git a/version.sh b/version.sh
new file mode 100755
index 0000000..15f604d
--- /dev/null
+++ b/version.sh
@@ -0,0 +1,11 @@
+#!/bin/bash
+rm -f version.h
+
+COMMIT_ID=$(cd $(dirname $0) && git log -1 | awk 'NR==1{print}')
+SUB_COMMIT_ID=$(echo "$COMMIT_ID" | cut -c8-14)
+#CUR_TIME=$(date "+%G-%m-%d %H:%M:%S")
+#RK_GRAPHICS_VERSION=$SUB_COMMIT_ID+"$CUR_TIME"
+RK_GRAPHICS_VERSION=$SUB_COMMIT_ID
+
+cd $(dirname $0) && cat version.h.template | sed "s/\$FULL_VERSION/$RK_GRAPHICS_VERSION/g" > version.h
+echo "Generated version.h"