├── Android.bp ├── Android.go ├── Android.mk ├── CMakeLists.txt ├── LICENSE ├── Makefile ├── README.md ├── buildroot.cmake ├── cmake-android.sh ├── cmake-linux.sh ├── core ├── GrallocOps.cpp ├── NormalRga.cpp ├── NormalRga.h ├── NormalRgaApi.cpp ├── NormalRgaContext.h ├── RgaApi.cpp ├── RgaUtils.cpp ├── RockchipRga.cpp └── platform_gralloc4.cpp ├── cross ├── cross_file_aarch64.txt └── cross_file_arm32.txt ├── debian ├── changelog ├── compat ├── control ├── copyright ├── librga-dev.dirs ├── librga-dev.install ├── librga2.dirs ├── librga2.install └── rules ├── docs └── README.md ├── im2d_api ├── im2d.cpp ├── im2d.h └── im2d.hpp ├── include ├── GrallocOps.h ├── RgaApi.h ├── RgaMutex.h ├── RgaSingleton.h ├── RgaUtils.h ├── RockchipRga.h ├── drmrga.h ├── platform_gralloc4.h └── rga.h ├── meson.build ├── meson.sh ├── meson_options.txt ├── samples ├── im2d_api_demo │ ├── Android.mk │ ├── args.cpp │ ├── args.h │ └── rgaImDemo.cpp ├── rgaBlit │ ├── Android.mk │ └── rgaBlit.cpp ├── rgaClip │ ├── Android.mk │ └── rgaClip.cpp ├── rgaColorFill │ ├── ._rgaColorFill.cpp │ ├── Android.mk │ └── rgaColorFill.cpp ├── rgaColorPalette │ ├── Android.mk │ └── rgaColorPalette.cpp ├── rgaCopy565ToRgba │ ├── Android.mk │ └── rgaCopy565ToRgba.cpp ├── rgaCopy565ToYuv │ ├── Android.mk │ └── rgaCopy565ToYuv.cpp ├── rgaCopyRgbaTo565 │ ├── Android.mk │ └── rgaCopyRgbaTo565.cpp ├── rgaCopyRgbaToYuv │ ├── Android.mk │ └── rgaCopyRgbaToYuv.cpp ├── rgaCopyScale │ ├── Android.mk │ └── rgaCopyScale.cpp ├── rgaCopyYuvTo565 │ ├── Android.mk │ └── rgaCopyYuvTo565.cpp ├── rgaCopyYuvToRgba │ ├── Android.mk │ └── rgaCopyYuvToRgba.cpp ├── rgaMirror │ ├── Android.mk │ └── rgaMirror.cpp ├── rgaROP │ ├── Android.mk │ └── rgaRop.cpp ├── rgaRotation │ ├── Android.mk │ └── rgaRotation.cpp ├── rgaSlt │ ├── Android.mk │ └── rgaSlt.cpp ├── rgaTestCache │ ├── Android.mk │ └── rgaTestCache.cpp ├── rgaUserSpace │ ├── Android.mk │ └── rgaUserSpace.cpp └── sample_file │ ├── README.txt │ ├── in0w1280-h720-rgba8888.bin │ └── in1w1280-h720-rgba8888.bin ├── version.h.in ├── version.h.template └── version.sh /Android.bp: -------------------------------------------------------------------------------- 1 | bootstrap_go_package { 2 | name: "soong-librga", 3 | pkgPath: "android/soong/librga", 4 | deps: [ 5 | "blueprint", 6 | "blueprint-pathtools", 7 | "soong", 8 | "soong-android", 9 | "soong-cc", 10 | "soong-genrule", 11 | ], 12 | srcs: [ 13 | "Android.go", 14 | ], 15 | pluginFor: ["soong_build"], 16 | } 17 | 18 | cc_librga { 19 | name: "cc_librga_defaults" 20 | } 21 | 22 | cc_library_shared { 23 | name: "librga", 24 | defaults: [ 25 | "cc_librga_defaults" 26 | ], 27 | 28 | vendor_available: true, 29 | 30 | header_libs: [ 31 | "gl_headers", 32 | "libgui_headers", 33 | "libbinder_headers", 34 | "liblog_headers", 35 | ], 36 | srcs: [ 37 | "core/RockchipRga.cpp", 38 | "core/GrallocOps.cpp", 39 | "core/NormalRga.cpp", 40 | "core/NormalRgaApi.cpp", 41 | "core/RgaApi.cpp", 42 | "core/RgaUtils.cpp", 43 | "im2d_api/im2d.cpp" 44 | ], 45 | export_include_dirs: [ 46 | "include", 47 | "core" 48 | ], 49 | include_dirs: [ 50 | "external/libdrm", 51 | "external/libdrm/include/drm", 52 | "hardware/libhardware/include/hardware", 53 | "hardware/libhardware/modules/gralloc", 54 | "frameworks/native/libs/nativewindow/include", 55 | "system/core/liblog/include", 56 | "system/core/libsync", 57 | "system/core/libsync/include", 58 | ], 59 | 60 | shared_libs: [ 61 | "liblog", 62 | "libui", 63 | "libutils", 64 | "libcutils", 65 | "libhardware", 66 | "libsync", 67 | ], 68 | 69 | cflags: ["-Wno-error"] +["-DLOG_TAG=\"librga\""] + ["-DRK_DRM_GRALLOC=1"] + ["-DANDROID_8"] + ["-DANDROID_7_DRM"] + ["-DUSE_AHARDWAREBUFFER=1"] + ["-DANDROID"], 70 | } 71 | -------------------------------------------------------------------------------- /Android.go: -------------------------------------------------------------------------------- 1 | package librga 2 | 3 | import ( 4 | "android/soong/android" 5 | "android/soong/cc" 6 | "fmt" 7 | "strings" 8 | ) 9 | 10 | func init() { 11 | fmt.Println("librga want to conditional Compile") 12 | android.RegisterModuleType("cc_librga", DefaultsFactory) 13 | } 14 | 15 | func DefaultsFactory() (android.Module) { 16 | module := cc.DefaultsFactory() 17 | android.AddLoadHook(module, Defaults) 18 | return module 19 | } 20 | 21 | func Defaults(ctx android.LoadHookContext) { 22 | sdkVersion := ctx.AConfig().PlatformSdkVersionInt() 23 | 24 | if (sdkVersion >= 29 ) { 25 | type props struct { 26 | Srcs []string 27 | Cflags []string 28 | Shared_libs []string 29 | Include_dirs []string 30 | Double_loadable *bool 31 | } 32 | 33 | p := &props{} 34 | p.Srcs = getSrcs(ctx) 35 | p.Cflags = getCflags(ctx) 36 | p.Shared_libs = getSharedLibs(ctx) 37 | p.Include_dirs = getIncludeDirs(ctx) 38 | 39 | double_loadable := true 40 | p.Double_loadable = &double_loadable 41 | 42 | ctx.AppendProperties(p) 43 | } else { 44 | type props struct { 45 | Srcs []string 46 | Cflags []string 47 | Shared_libs []string 48 | Include_dirs []string 49 | } 50 | 51 | p := &props{} 52 | p.Srcs = getSrcs(ctx) 53 | p.Cflags = getCflags(ctx) 54 | p.Shared_libs = getSharedLibs(ctx) 55 | p.Include_dirs = getIncludeDirs(ctx) 56 | 57 | ctx.AppendProperties(p) 58 | } 59 | } 60 | 61 | //条件编译主要修改函数 62 | func getCflags(ctx android.BaseContext) ([]string) { 63 | var cppflags []string 64 | 65 | sdkVersion := ctx.AConfig().PlatformSdkVersionInt() 66 | 67 | //该打印输出为: TARGET_PRODUCT:rk3328 fmt.Println("TARGET_PRODUCT:",ctx.AConfig().Getenv("TARGET_PRODUCT")) //通过 strings.EqualFold 比较字符串,可参考go语言字符串对比 68 | if (strings.EqualFold(ctx.AConfig().Getenv("TARGET_BOARD_PLATFORM"),"rk3368") ) { 69 | //添加 DEBUG 宏定义 70 | cppflags = append(cppflags,"-DRK3368=1") 71 | } 72 | 73 | if (strings.EqualFold(ctx.AConfig().Getenv("TARGET_RK_GRALLOC_VERSION"),"4") ) { 74 | if (sdkVersion >= 30 ) { 75 | cppflags = append(cppflags,"-DUSE_GRALLOC_4") 76 | } 77 | } 78 | 79 | //将需要区分的环境变量在此区域添加 //.... 80 | return cppflags 81 | } 82 | 83 | func getSharedLibs(ctx android.BaseContext) ([]string) { 84 | var libs []string 85 | 86 | sdkVersion := ctx.AConfig().PlatformSdkVersionInt() 87 | 88 | if (strings.EqualFold(ctx.AConfig().Getenv("TARGET_RK_GRALLOC_VERSION"),"4") ) { 89 | if (sdkVersion >= 30 ) { 90 | libs = append(libs, "libgralloctypes") 91 | libs = append(libs, "libhidlbase") 92 | libs = append(libs, "android.hardware.graphics.mapper@4.0") 93 | } 94 | } 95 | 96 | if (sdkVersion < 29 ) { 97 | libs = append(libs, "libdrm") 98 | } 99 | 100 | return libs 101 | } 102 | 103 | func getIncludeDirs(ctx android.BaseContext) ([]string) { 104 | var dirs []string 105 | 106 | sdkVersion := ctx.AConfig().PlatformSdkVersionInt() 107 | 108 | if (strings.EqualFold(ctx.AConfig().Getenv("TARGET_RK_GRALLOC_VERSION"),"4") ) { 109 | if (sdkVersion >= 30 ) { 110 | dirs = append(dirs, "hardware/rockchip/libgralloc/bifrost") 111 | dirs = append(dirs, "hardware/rockchip/libgralloc/bifrost/src") 112 | } 113 | } 114 | 115 | return dirs 116 | } 117 | 118 | func getSrcs(ctx android.BaseContext) ([]string) { 119 | var src []string 120 | 121 | sdkVersion := ctx.AConfig().PlatformSdkVersionInt() 122 | 123 | if (strings.EqualFold(ctx.AConfig().Getenv("TARGET_RK_GRALLOC_VERSION"),"4") ) { 124 | if (sdkVersion >= 30 ) { 125 | src = append(src, "core/platform_gralloc4.cpp") 126 | } 127 | } 128 | 129 | return src 130 | } 131 | -------------------------------------------------------------------------------- /Android.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2018 Fuzhou Rockchip Electronics Co., Ltd. All rights reserved. 3 | # Authors: 4 | # lihuang 5 | # libin 6 | # 7 | # This program is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation, either version 3 of the License, or 10 | # (at your option) any later version. 11 | # 12 | # This program is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU General Public License 18 | # along with this program. If not, see . 19 | # 20 | # BY DOWNLOADING, INSTALLING, COPYING, SAVING OR OTHERWISE USING THIS SOFTWARE, 21 | # YOU ACKNOWLEDGE THAT YOU AGREE THE SOFTWARE RECEIVED FORM ROCKCHIP IS PROVIDED 22 | # TO YOU ON AN "AS IS" BASIS and ROCKCHP DISCLAIMS ANY AND ALL WARRANTIES AND 23 | # REPRESENTATIONS WITH RESPECT TO SUCH FILE, WHETHER EXPRESS, IMPLIED, STATUTORY 24 | # OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF TITLE, 25 | # NON-INFRINGEMENT, MERCHANTABILITY, SATISFACTROY QUALITY, ACCURACY OR FITNESS FOR 26 | # A PARTICULAR PURPOSE. 27 | # 28 | 29 | LOCAL_PATH:= $(call my-dir) 30 | ifeq (1,$(strip $(shell expr $(PLATFORM_SDK_VERSION) \< 28))) 31 | 32 | ifneq ($(strip $(BOARD_USE_DRM)), true) 33 | include $(CLEAR_VARS) 34 | 35 | $(info $(shell $(LOCAL_PATH)/version.sh)) 36 | 37 | LOCAL_CFLAGS += -DGL_GLEXT_PROTOTYPES -DEGL_EGLEXT_PROTOTYPES 38 | 39 | LOCAL_CFLAGS += -DROCKCHIP_GPU_LIB_ENABLE 40 | 41 | ifeq (1,$(strip $(shell expr $(PLATFORM_SDK_VERSION) \> 25))) 42 | LOCAL_CFLAGS += -DUSE_AHARDWAREBUFFER=1 43 | endif 44 | 45 | #LOCAL_CFLAGS += -Wall -Werror -Wunreachable-code 46 | 47 | LOCAL_C_INCLUDES += external/tinyalsa/include 48 | LOCAL_C_INCLUDES += hardware/rockchip/libgralloc 49 | LOCAL_C_INCLUDES += hardware/rk29/libgralloc_ump 50 | LOCAL_C_INCLUDES += hardware/libhardware/include/hardware 51 | LOCAL_C_INCLUDES += $(LOCAL_PATH)/include 52 | 53 | LOCAL_CFLAGS := \ 54 | -DLOG_TAG=\"librga\" 55 | 56 | LOCAL_SHARED_LIBRARIES := \ 57 | libcutils \ 58 | liblog \ 59 | libutils \ 60 | libbinder \ 61 | libui \ 62 | libEGL \ 63 | libGLESv1_CM \ 64 | libgui \ 65 | libhardware 66 | 67 | #has no "external/stlport" from Android 6.0 on 68 | ifeq (1,$(strip $(shell expr $(PLATFORM_VERSION) \< 6.0))) 69 | LOCAL_C_INCLUDES += \ 70 | external/stlport/stlport 71 | 72 | LOCAL_SHARED_LIBRARIES += \ 73 | libstlport 74 | 75 | LOCAL_C_INCLUDES += bionic 76 | endif 77 | 78 | LOCAL_SRC_FILES:= \ 79 | core/RockchipRga.cpp \ 80 | core/GrallocOps.cpp \ 81 | core/NormalRga.cpp \ 82 | core/NormalRgaApi.cpp \ 83 | core/RgaApi.cpp \ 84 | core/RgaUtils.cpp \ 85 | im2d_api/im2d.cpp 86 | 87 | ifneq (1,$(strip $(shell expr $(PLATFORM_VERSION) \< 6.0))) 88 | ifeq ($(strip $(TARGET_BOARD_PLATFORM_GPU)), mali-t720) 89 | LOCAL_CFLAGS += -DMALI_PRODUCT_ID_T72X=1 90 | LOCAL_CFLAGS += -DMALI_AFBC_GRALLOC=0 91 | endif 92 | 93 | ifeq ($(strip $(TARGET_BOARD_PLATFORM_GPU)), mali-t760) 94 | LOCAL_CFLAGS += -DMALI_PRODUCT_ID_T76X=1 95 | LOCAL_CFLAGS += -DMALI_AFBC_GRALLOC=1 96 | endif 97 | 98 | ifeq ($(strip $(TARGET_BOARD_PLATFORM_GPU)), mali-t860) 99 | LOCAL_CFLAGS += -DMALI_PRODUCT_ID_T86X=1 100 | LOCAL_CFLAGS += -DMALI_AFBC_GRALLOC=1 101 | endif 102 | endif #android 6.0 and later 103 | 104 | ifeq ($(strip $(TARGET_BOARD_PLATFORM)),rk3368) 105 | LOCAL_CFLAGS += -DRK3368 106 | endif 107 | 108 | ifeq ($(strip $(TARGET_BOARD_PLATFORM)),rk3188) 109 | LOCAL_CFLAGS += -DRK3188 110 | endif 111 | 112 | ifeq ($(strip $(GRAPHIC_MEMORY_PROVIDER)),dma_buf) 113 | LOCAL_CFLAGS += -DUSE_DMA_BUF 114 | endif 115 | 116 | LOCAL_MODULE:= librga 117 | include $(BUILD_SHARED_LIBRARY) 118 | endif #end of BOARD_USE_DRM=false 119 | ############################################################################################# 120 | 121 | ############################################################################################# 122 | ifeq ($(strip $(BOARD_USE_DRM)), true) 123 | include $(CLEAR_VARS) 124 | 125 | $(info $(shell $(LOCAL_PATH)/version.sh)) 126 | 127 | LOCAL_SRC_FILES += \ 128 | core/RockchipRga.cpp \ 129 | core/GrallocOps.cpp \ 130 | core/NormalRga.cpp \ 131 | core/NormalRgaApi.cpp \ 132 | core/RgaApi.cpp \ 133 | core/RgaUtils.cpp \ 134 | im2d_api/im2d.cpp 135 | 136 | LOCAL_MODULE := librga 137 | LOCAL_PROPRIETARY_MODULE := true 138 | LOCAL_C_INCLUDES += external/libdrm/rockchip 139 | LOCAL_C_INCLUDES += hardware/rockchip/libgralloc 140 | LOCAL_C_INCLUDES += hardware/rk29/libgralloc_ump 141 | LOCAL_C_INCLUDES += hardware/libhardware/include/hardware 142 | LOCAL_C_INCLUDES += hardware/libhardware/modules/gralloc 143 | LOCAL_C_INCLUDES += frameworks/native/libs/nativewindow/include 144 | LOCAL_C_INCLUDES += $(LOCAL_PATH)/include 145 | 146 | LOCAL_SHARED_LIBRARIES := libdrm 147 | LOCAL_SHARED_LIBRARIES += \ 148 | libdrm_rockchip \ 149 | liblog \ 150 | libui \ 151 | libcutils \ 152 | libhardware 153 | 154 | LOCAL_CFLAGS := \ 155 | -DLOG_TAG=\"librga\" 156 | 157 | LOCAL_CFLAGS += -DANDROID 158 | 159 | ifeq (1,$(strip $(shell expr $(PLATFORM_SDK_VERSION) \> 25))) 160 | LOCAL_CFLAGS += -DUSE_AHARDWAREBUFFER=1 161 | endif 162 | 163 | ifneq ($(strip $(TARGET_BOARD_PLATFORM)),rk3368) 164 | LOCAL_SHARED_LIBRARIES += libgralloc_drm 165 | endif 166 | 167 | ifneq (1,$(strip $(shell expr $(PLATFORM_VERSION) \< 6.9))) 168 | LOCAL_CFLAGS += -DANDROID_7_DRM 169 | LOCAL_CFLAGS += -DRK_DRM_GRALLOC=1 170 | endif 171 | 172 | ifeq ($(strip $(TARGET_BOARD_PLATFORM)),rk3368) 173 | LOCAL_CFLAGS += -DRK3368 174 | endif 175 | 176 | ifeq ($(strip $(TARGET_BOARD_PLATFORM)),rk3126c) 177 | LOCAL_CFLAGS += -DRK3126C 178 | endif 179 | 180 | ifneq (1,$(strip $(shell expr $(PLATFORM_VERSION) \< 8.0))) 181 | LOCAL_CFLAGS += -DANDROID_8 182 | endif 183 | 184 | LOCAL_MODULE_TAGS := optional 185 | #LOCAL_MODULE_RELATIVE_PATH := hw 186 | LOCAL_MODULE_CLASS := SHARED_LIBRARIES 187 | LOCAL_MODULE_SUFFIX := $(TARGET_SHLIB_SUFFIX) 188 | 189 | include $(BUILD_SHARED_LIBRARY) 190 | endif #end of BOARD_USE_DRM = true 191 | ############################################################################################# 192 | 193 | ############################################################################################# 194 | ifeq ($(strip $(BOARD_USE_DRM)), future) 195 | ifeq ($(strip $(BOARD_USE_DRM)), true) 196 | include $(CLEAR_VARS) 197 | 198 | $(info $(shell $(LOCAL_PATH)/version.sh)) 199 | 200 | LOCAL_SRC_FILES += \ 201 | core/RockchipRga.cpp \ 202 | core/GrallocOps.cpp \ 203 | drm/DrmmodeRga.cpp \ 204 | core/RgaApi.cpp \ 205 | core/RgaUtils.cpp \ 206 | im2d_api/im2d.cpp 207 | 208 | LOCAL_MODULE := librga 209 | 210 | LOCAL_C_INCLUDES += external/libdrm/rockchip 211 | LOCAL_C_INCLUDES += hardware/rockchip/libgralloc 212 | LOCAL_C_INCLUDES += hardware/rk29/libgralloc_ump 213 | LOCAL_C_INCLUDES += $(LOCAL_PATH)/drm 214 | 215 | LOCAL_SHARED_LIBRARIES := libdrm 216 | LOCAL_SHARED_LIBRARIES += \ 217 | libdrm_rockchip \ 218 | liblog \ 219 | libui \ 220 | libcutils \ 221 | libhardware 222 | 223 | LOCAL_CFLAGS := \ 224 | -DLOG_TAG=\"librga-drm\" 225 | 226 | ifeq (1,$(strip $(shell expr $(PLATFORM_SDK_VERSION) \> 25))) 227 | LOCAL_CFLAGS += -DUSE_AHARDWAREBUFFER=1 228 | endif 229 | 230 | LOCAL_MODULE_TAGS := optional 231 | #LOCAL_MODULE_RELATIVE_PATH := hw 232 | LOCAL_MODULE_CLASS := SHARED_LIBRARIES 233 | LOCAL_MODULE_SUFFIX := $(TARGET_SHLIB_SUFFIX) 234 | 235 | include $(BUILD_SHARED_LIBRARY) 236 | endif #end of BOARD_USE_DRM=true 237 | ############################################################################################# 238 | endif #end of BOARD_USE_DRM=future it will be used when upstrean in the future 239 | 240 | endif #end of PLATFORM_SDK_VERSION < 28 241 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | if(NOT CMAKE_BUILD_TYPE) 2 | message("default to Release build for GCC builds") 3 | set(CMAKE_BUILD_TYPE Release CACHE STRING 4 | "Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel." 5 | FORCE) 6 | endif() 7 | 8 | if(CMAKE_BUILD_TARGET STREQUAL ndk) 9 | message("set ndk toolchain") 10 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error -DLOG_TAG=librga") 11 | add_compile_options(-DLINUX) 12 | add_compile_options(-DANDROID_VNDK) 13 | endif() 14 | 15 | if(CMAKE_BUILD_TARGET STREQUAL buildroot) 16 | message("set buildroot toolchain") 17 | set(CMAKE_TOOLCHAIN_FILE 18 | ${CMAKE_SOURCE_DIR}/buildroot.cmake) 19 | include(${CMAKE_SOURCE_DIR}/buildroot.cmake) 20 | add_compile_options(-DLINUX) 21 | set(CMAKE_CXX_FLAGS "-std=c++11 -O2 -pthread") 22 | endif() 23 | 24 | cmake_minimum_required(VERSION 2.8) 25 | 26 | #project name 27 | project(librga) 28 | 29 | include_directories( 30 | ./ 31 | ./include 32 | external/libdrm 33 | external/libdrm/include/drm 34 | hardware/libhardware/include/hardware 35 | hardware/libhardware/modules/gralloc 36 | system/core/liblog/includeNDROID_NDK_REVISION_REGEX 37 | system/core/libion/kernel-headers 38 | ) 39 | 40 | set(IM2D_SRCS 41 | core/RockchipRga.cpp 42 | core/GrallocOps.cpp 43 | core/NormalRga.cpp 44 | core/NormalRgaApi.cpp 45 | core/RgaUtils.cpp 46 | im2d_api/im2d.cpp) 47 | 48 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUN_NEED_GL") 49 | 50 | if(CMAKE_BUILD_TARGET STREQUAL ndk) 51 | string(REPLACE "-DANDROID" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") 52 | endif() 53 | 54 | add_library(rga SHARED ${IM2D_SRCS}) 55 | 56 | 57 | #build im2d test 58 | set(IM2D_DEMO_SRCS 59 | samples/im2d_api_demo/rgaImDemo.cpp 60 | samples/im2d_api_demo/args.cpp) 61 | 62 | add_executable(im2d ${IM2D_DEMO_SRCS}) 63 | 64 | target_link_libraries(im2d 65 | rga) 66 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Rockchip Electronics Co.,Ltd. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright notice, 8 | // this list of conditions and the following disclaimer. 9 | // 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, 11 | // this list of conditions and the following disclaimer in the documentation 12 | // and/or other materials provided with the distribution. 13 | // 14 | // 3. Neither the name of the copyright holder nor the names of its contributors 15 | // may be used to endorse or promote products derived from this software without 16 | // specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | // POSSIBILITY OF SUCH DAMAGE. 29 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | ################################################################## 2 | # 3 | # FILENAME : Makefile 4 | # DESCRIPT : A general makefile to generate an ELF or a 5 | # dynamic or a static library for C/C++ project. 6 | # AUTHOR : vfhky 2015.08.07 7 | # URI : https://typecodes.com/cseries/cppgeneralmakefile.html 8 | # 9 | ################################################################## 10 | 11 | .PHONY: all clean help 12 | all: 13 | 14 | # Some important on-off settings. You can not be too careful about them. 15 | DEBUG := y 16 | # Flag of generate a dynamic lib or a static lib: y means yes. If the target is a excutable file, it should be blank! 17 | GEN_LIBS := y 18 | # Flag of generate a dynamic lib: y means yes. It should be blank unless you want to generate a dynamic lib! 19 | GEN_DYN_LIB := y 20 | # The name of target bin file.Please let it be blank unless the target is a excutable file. 21 | EXCUTE_BIN := 22 | # Name of the static lib. It should be blank unless the target is a static lib, then the GEN_LIBS is y and GEN_DYN_LIB is blank. 23 | # STATIC_LIBS := libsrcpbl.a 24 | # Name of the dynamic lib. It should be blank unless the target is a dynamic lib, then the GEN_LIBS is y and GEN_DYN_LIB is y. 25 | DYNAMIC_LIBS := librga.so 26 | 27 | # Environment settings. The value of PROJECT_DIR shoule be set in the *nix system as the the absolute dir path of your project. 28 | PROJECT_DIR ?= /home/lee/rv1126/external/rga 29 | #CURDIR := $(PROJECT_DIR)/src/pbl 30 | CURDIR := $(shell pwd) 31 | PRG_BIN_DIR := $(PROJECT_DIR)/bin 32 | PRG_LIB_DIR := $(PROJECT_DIR)/lib 33 | PRG_INC_DIR := $(PROJECT_DIR)/include 34 | 35 | # Cross compile tools defined. You needn't modify these vars below generally. 36 | AS ?= as 37 | LD ?= ld 38 | CC ?= /home/lee/rv1126/buildroot/output/rockchip_puma/host/bin/arm-linux-gnueabihf-gcc 39 | CXX ?= /home/lee/rv1126/buildroot/output/rockchip_puma/host/bin/arm-linux-gnueabihf-g++ 40 | CPP ?= $(CC) -E 41 | AR ?= ar rcs 42 | NM ?= nm 43 | STRIP ?= strip 44 | RANLIB ?= ranlib 45 | STD_OPT ?= -D_GNU_SOURCE 46 | CC ?= -std=c99 $(STD_OPT) 47 | CXX ?= $(STD_OPT) 48 | 49 | # *nix system tools defined. You needn't modify these vars below generally. 50 | BLACK = "\e[33;0m" 51 | RED = "\e[31;1m" 52 | GREEN = "\e[32;1m" 53 | YELLOW = "\e[33;3m" 54 | BLUE = "\e[34;1m" 55 | PURPLE = "\e[35;1m" 56 | CYAN = "\e[36;1m" 57 | WHITE = "\e[37;1m" 58 | CP := cp 59 | SED := sed 60 | FIND := find 61 | MKDIR := mkdir -p 62 | XARGS := xargs 63 | MV := mv 64 | RM := rm -rf 65 | 66 | 67 | # Get .c, .cpp source files by searching from current directory. 68 | CUR_SRC_DIR = $(shell ls -AxR $(CURDIR)|grep ":"|tr -d ':'|grep -v "samples") 69 | CUR_SRC := $(foreach subdir,$(CUR_SRC_DIR),$(wildcard $(subdir)/*.c $(subdir)/*.cpp)) 70 | #CUR_SRC := $(shell find . -name "*.c" -o -name "*.cpp"|sed -e 's,./,,') 71 | CUR_C := $(filter %.c, $(CUR_SRC)) 72 | CUR_CPP := $(filter %.cpp, $(CUR_SRC)) 73 | 74 | # Get the include files, object files, dependent files by searching from PRG_INC_DIR. 75 | CUR_INC_DIR = $(shell ls -AxR $(PRG_INC_DIR)|grep ":"|tr -d ':') 76 | CUR_INC := $(foreach subdir,$(CUR_INC_DIR),$(subdir)/*.h) 77 | SRC_H := $(filter %.h, $(CUR_INC)) 78 | #CUR_OBJ := $(addprefix $(PRG_BIN_DIR)/,$(strip $(CUR_CPP:.cpp=.o) $(CUR_C:.c=.o))) 79 | #CUR_OBJ := $(addprefix $(PRG_BIN_DIR)/,$(notdir $(CUR_CPP:.cpp=.o) $(CUR_C:.c=.o))) 80 | CUR_OBJ := $(strip $(CUR_CPP:.cpp=.o) $(CUR_C:.c=.o)) 81 | #CUR_DEP := $(addprefix $(PRG_BIN_DIR)/,$(notdir $(CUR_CPP:.cpp=.d) $(CUR_C:.c=.d))) 82 | CUR_DEP := $(strip $(CUR_CPP:.cpp=.d) $(CUR_C:.c=.d)) 83 | 84 | # Create directory in the header files, bin and library directory. 85 | $(foreach dirname,$(sort $(PRG_INC_DIR) $(PRG_BIN_DIR) $(PRG_LIB_DIR)),\ 86 | $(shell $(MKDIR) $(dirname))) 87 | 88 | # Complie and link variables. LD_LIBS means the dynamic or static library needed for the object file. 89 | CFLAGS := $(if $(DEBUG),-g -Wall, -O2 -Wall) -DLINUX 90 | CFLAGS += $(if $(GEN_DYN_LIB), $(addprefix -fPIC -I ,$(sort $(dir $(SRC_H)))), $(addprefix -I ,$(sort $(dir $(SRC_H))))) 91 | CXXFLAGS = $(CFLAGS) 92 | LDFLAGS := 93 | LD_LIB_DIR := #-L $(PRG_LIB_DIR) 94 | LD_LIBS := -lpthread #-lsrcpbl -lmysqlclient 95 | XLD_FLG := -Xlinker "-(" $(LDFLAGS) -Xlinker "-)" 96 | 97 | ifeq ($(LIBDRM),y) 98 | LD_LIBS += -ldrm 99 | PRG_INC_DIR += /home/lee/rv1126/buildroot/output/rockchip_puma/host/include/ 100 | endif 101 | 102 | # Add vpath. 103 | vpath %.h $(sort $(dir $(SRC_H))) 104 | vpath %.c $(sort $(dir $(CUR_C))) 105 | vpath %.cpp $(sort $(dir $(CUR_CPP))) 106 | 107 | # Generate depend files. 108 | ifneq "$(MAKECMDGOALS)" "clean" 109 | sinclude $(CUR_DEP) 110 | endif 111 | 112 | # Gen_depend(depend-file,source-file,object-file,cc). This command-package is used to generate a depend file with a postfix of .d. 113 | define gen_depend 114 | @set -e; \ 115 | $(RM) $1; \ 116 | $4 $(CFLAGS) -MM $2 | \ 117 | $(SED) 's,\($(notdir $3)\): ,$3: ,' > $1.tmp; \ 118 | $(SED) -e 's/#.*//' \ 119 | -e 's/^[^:]*: *//' \ 120 | -e 's/ *\\$$//' \ 121 | -e '/^$$/ d' \ 122 | -e 's/$$/ :/' < $1.tmp >> $1.tmp; \ 123 | $(MV) $1.tmp $1; 124 | endef 125 | 126 | # Rules to generate objects file(.o) from .c or .cpp files. 127 | $(CURDIR)/%.o: $(CURDIR)/%.c 128 | @$(call gen_depend,$(patsubst %.o,%.d,$@),$<,$@,$(CC)) 129 | $(CC) $(CFLAGS) -o $@ -c $< 130 | 131 | $(CURDIR)/%.o: $(CURDIR)/%.cpp 132 | @$(call gen_depend,$(patsubst %.o,%.d,$@),$<,$@,$(CXX)) 133 | $(CXX) $(CXXFLAGS) -o $@ -c $< 134 | 135 | # Gen_excbin(target,CUR_OBJ,cc). This command-package is used to generate a excutable file. 136 | define gen_excbin 137 | ULT_BIN += $(PRG_BIN_DIR)/$1 138 | $(PRG_BIN_DIR)/$1: $2 139 | $3 $(LDFLAGS) $$^ $(LD_LIB_DIR) $(LD_LIBS) $(XLD_FLG) -o $$@ 140 | @echo -e $(YELLOW)"========================Success========================"$(BLACK) 141 | endef 142 | 143 | # Gen_libs(libs,CUR_OBJ,cc). This command-package is used to generate a dynamic lib or a static lib. 144 | define gen_libs 145 | ULT_LIBS += $(PRG_LIB_DIR)/$1 146 | $(PRG_LIB_DIR)/$1: $2 147 | $3 $(if $(GEN_DYN_LIB),-shared $$^ $(CXXFLAGS) $(LD_LIB_DIR) $(LD_LIBS) $(XLD_FLG) -o $$@,$$@ $$^) 148 | @echo -e $(YELLOW)"========================Success========================"$(BLACK) 149 | endef 150 | 151 | # Call gen_excbin to generate a excutale file. 152 | $(foreach bin,$(EXCUTE_BIN),$(eval $(call gen_excbin,$(bin),$(CURDIR)/$(bin).o,$(CXX)))) 153 | 154 | # Call gen_libs to generate a dynamic lib. 155 | $(foreach lib,$(DYNAMIC_LIBS),$(eval $(call gen_libs,$(lib),$(CUR_OBJ),$(CXX)))) 156 | 157 | # Call gen_libs to generate a static lib. 158 | $(foreach lib,$(STATIC_LIBS),$(eval $(call gen_libs,$(lib),$(CUR_OBJ),$(AR)))) 159 | 160 | 161 | all: $(ULT_BIN) $(ULT_LIBS) 162 | 163 | 164 | clean: 165 | -$(FIND) $(CURDIR) -name "*.o" -o -name "*.d" | $(XARGS) $(RM) 166 | -$(RM) $(ULT_BIN) $(ULT_LIBS) 167 | 168 | 169 | help: 170 | @echo CC=[$(CC)] 171 | @echo CXX=[$(CXX)] 172 | @echo CFLAGS=[$(CFLAGS)] 173 | @echo CXXFLAGS=[$(CXXFLAGS)] 174 | @echo PROJECT_DIR=[$(PROJECT_DIR)] 175 | @echo CURDIR=[$(CURDIR)] 176 | @echo PRG_BIN_DIR=[$(PRG_BIN_DIR)] 177 | @echo PRG_LIB_DIR=[$(PRG_LIB_DIR)] 178 | @echo PRG_INC_DIR=[$(PRG_INC_DIR)] 179 | @echo CUR_SRC_DIR=[$(CUR_SRC_DIR)] 180 | @echo CUR_SRC=[$(CUR_SRC)] 181 | @echo CUR_C=[$(CUR_C)] 182 | @echo CUR_CPP=[$(CUR_CPP)] 183 | @echo CUR_OBJ=[$(CUR_OBJ)] 184 | @echo CUR_DEP=[$(CUR_DEP)] 185 | @echo STATIC_LIBS=[$(STATIC_LIBS)] 186 | @echo DYNAMIC_LIBS=[$(DYNAMIC_LIBS)] 187 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## librga 2 | 3 | RGA (Raster Graphic Acceleration Unit)是一个独立的2D硬件加速器,可用于加速点/线绘制,执行图像缩放、旋转、bitBlt、alpha混合等常见的2D图形操作。本仓库代码实现了RGA用户空间驱动,并提供了一系列2D图形操作API。 4 | 5 | ### 版本说明 6 | 7 | **librga** 版本: v1.04
8 | **librga API** 版本: v1.11 9 | 10 | ### 适用芯片平台 11 | 12 | Rockchip RK3066 | RK3188 | RK2926 | RK2928 | RK3026 | RK3028 | RK3128 | Sofia3gr | RK3288 | RK3288w | RK3190 | RK1108 | RK3368 | RK3326 | RK3228 | RK3228H | RK3326 | RK1808 | RV1126 | RV1109 | RK3399 | RK3399pro 13 | 14 | ### 目录说明 15 | 16 | **core:** RGA用户空间驱动实现 17 | 18 | **include:** 相关头文件 19 | 20 | **im2d_api:** RGA API相关实现及头文件 21 | 22 | **samples:** librga使用例程 23 | 24 | ### 编译说明 25 | 26 | * **Android Source Project** 27 | 28 | 下载librga仓库拷贝至android源码工程 hardware/rockchip目录,执行**mm**进行编译。根据不同的Android版本将自动选择Android.mk或Android.bp作为编译脚本。 29 | 30 | * **Android NDK (build for android)** 31 | 32 | 修改librga源码根目录下的文件**cmake-android.sh**。执行以下操作完成编译: 33 | 34 | ```bash 35 | $ mkdir build 36 | $ cd build 37 | $ cp ../cmake-android.sh ./ 38 | $ chmod +x ./cmake-android.sh 39 | $ ./cmake-android.sh 40 | $ make 41 | ``` 42 | 43 | **[编译选项]** 44 | 45 | 1. 指定ANDROID_NDK_HOME为NDK开发包的路径 46 | 2. 指定CMAKE_ANDROID为android SDK包中cmake可执行文件的路径 47 | 3. 根据需要选择不同架构,设置-DANDROID_ABI等于armeabi-v7a或arm64-v8a 48 | 4. 根据需要选择不同的android平台版本,设置-DANDROID_PLATFORM 49 | 50 | * **Cmake (buildroot/debian)** 51 | 52 | 修改librga源码根目录下的**buildroot.cmake**文件。执行以下操作完成编译: 53 | 54 | ```bash 55 | $ mkdir build 56 | $ cd build 57 | $ cp ../cmake-linux.sh ./ 58 | $ chmod +x ./cmake-linux.sh 59 | $ ./cmake-linux.sh 60 | $ make 61 | ``` 62 | 63 | **[编译选项]** 64 | 65 | 1. 指定TOOLCHAIN_HOME为交叉编译工具的路径 66 | 2. 指定CMAKE_C_COMPILER为gcc编译命令的路径 67 | 3. 指定CMAKE_CXX_COMPILER为g++编译命令的路径 68 | 69 | * **Meson(buildroot/debian)** 70 | 71 | librga提供了meson.build,最新buildroot支持meson 编译。单独编译可以使用meson.sh 脚本进行config,需要自行修改meson.sh 内指定install 路径,以及PATH等环境变量,cross目录下是交叉编译工具配置文件,也需要自行修改为对应交叉编译工具路径。 72 | 73 | 执行以下操作完成编译: 74 | 75 | ```bash 76 | $ ./meson.sh 77 | $ ninja -C build-rga install 78 | ``` 79 | 80 | * **Makefile(buildroot/debian)** 81 | 82 | librga也提供了Makefile文件,可以在开发板上直接执行make命令,或修改Makefile自行定义交叉编译工具后执行make完成编译。 83 | 84 | ### 使用说明 85 | 86 | * **头文件引用** 87 | 88 | * 调用librga 89 | 90 | include/RockchipRga.h 91 | 92 | * 调用im2d api 93 | 94 | im2d_api/im2d.hpp 95 | 96 | * **库文件** 97 | 98 | librga.so 99 | 100 | * librga应用开发接口说明参考以下文件: 101 | 102 | [API document](docs/README.md) 103 | 104 | -------------------------------------------------------------------------------- /buildroot.cmake: -------------------------------------------------------------------------------- 1 | SET(TOOLCHAIN_HOME "/home/cc/mksdk/rk3288linux/prebuilts/gcc/linux-x86/aarch64/gcc-linaro-6.3.1-2017.05-x86_64_aarch64-linux-gnu") 2 | 3 | # this is required 4 | #SET(CMAKE_SYSTEM_NAME Linux) 5 | 6 | # specify the cross compiler 7 | SET(CMAKE_C_COMPILER ${TOOLCHAIN_HOME}/bin/aarch64-linux-gnu-gcc) 8 | SET(CMAKE_CXX_COMPILER ${TOOLCHAIN_HOME}/bin/aarch64-linux-gnu-g++) 9 | 10 | # where is the target environment 11 | SET(CMAKE_FIND_ROOT_PATH ${TOOLCHAIN_HOME}) 12 | 13 | # search for programs in the build host directories (not necessary) 14 | SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 15 | # for libraries and headers in the target directories 16 | SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 17 | SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 18 | -------------------------------------------------------------------------------- /cmake-android.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ANDROID_NDK_HOME=/Users/jacobchen/Library/Android/sdk/ndk/21.3.6528147 4 | CMAKE_ANDROID=/Users/jacobchen/Library/Android/sdk/cmake/3.6.4111459/bin/cmake 5 | 6 | ${CMAKE_ANDROID} -DCMAKE_BUILD_TARGET=ndk -DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK_HOME/build/cmake/android.toolchain.cmake \ 7 | -DANDROID_NDK=$ANDROID_NDK_HOME \ 8 | -DANDROID_ABI=armeabi-v7a \ 9 | -DANDROID_TOOLCHAIN=clang \ 10 | -DANDROID_PLATFORM=android-27 \ 11 | -DANDROID_STL=c++_shared \ 12 | .. 13 | make 14 | -------------------------------------------------------------------------------- /cmake-linux.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | cmake -DCMAKE_BUILD_TARGET=buildroot \ 4 | .. 5 | make 6 | -------------------------------------------------------------------------------- /core/NormalRgaContext.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Rockchip Electronics Co., Ltd. 3 | * Authors: 4 | * Zhiqin Wei 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #ifndef _rockchip_normal_rga_context_h_ 20 | #define _rockchip_normal_rga_context_h_ 21 | 22 | #ifdef LINUX 23 | #define __DEBUG 0 24 | 25 | #define ALOGE(...) printf(__VA_ARGS__); printf("\n") 26 | #endif 27 | 28 | struct rgaContext { 29 | int rgaFd; 30 | int mLogAlways; 31 | int mLogOnce; 32 | float mVersion; 33 | int Is_debug; 34 | 35 | }; 36 | #endif 37 | -------------------------------------------------------------------------------- /core/RgaApi.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Rockchip Electronics Co., Ltd. 3 | * Authors: 4 | * Zhiqin Wei 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #include "RgaApi.h" 20 | 21 | #include "RockchipRga.h" 22 | 23 | 24 | #ifndef ANDROID /* LINUX */ 25 | RockchipRga& c_rkRga(RockchipRga::get()); 26 | #else 27 | android::RockchipRga& c_rkRga(android::RockchipRga::get()); 28 | #endif 29 | 30 | int c_RkRgaInit() 31 | { 32 | int ret; 33 | ret = c_rkRga.RkRgaInit(); 34 | return ret; 35 | } 36 | 37 | void c_RkRgaDeInit() 38 | { 39 | c_rkRga.RkRgaDeInit(); 40 | } 41 | 42 | int c_RkRgaBlit(rga_info_t *src, rga_info_t *dst, rga_info_t *src1) 43 | { 44 | int ret; 45 | ret = c_rkRga.RkRgaBlit(src, dst, src1); 46 | return ret ; 47 | } 48 | 49 | int c_RkRgaColorFill(rga_info_t *dst) 50 | { 51 | return c_rkRga.RkRgaCollorFill(dst); 52 | } 53 | 54 | int c_RkRgaFlush() 55 | { 56 | return c_rkRga.RkRgaFlush(); 57 | } 58 | 59 | #ifndef ANDROID /* linux */ 60 | int c_RkRgaGetAllocBuffer(bo_t *bo_info, int width, int height, int bpp) 61 | { 62 | c_rkRga.RkRgaGetAllocBuffer(bo_info, width, height, bpp); 63 | return 0; 64 | } 65 | 66 | int c_RkRgaGetAllocBufferCache(bo_t *bo_info, int width, int height, int bpp) 67 | { 68 | c_rkRga.RkRgaGetAllocBufferCache(bo_info, width, height, bpp); 69 | return 0; 70 | } 71 | 72 | int c_RkRgaGetMmap(bo_t *bo_info) 73 | { 74 | c_rkRga.RkRgaGetMmap(bo_info); 75 | return 0; 76 | } 77 | 78 | int c_RkRgaUnmap(bo_t *bo_info) 79 | { 80 | c_rkRga.RkRgaUnmap(bo_info); 81 | return 0; 82 | } 83 | 84 | int c_RkRgaFree(bo_t *bo_info) 85 | { 86 | c_rkRga.RkRgaFree(bo_info); 87 | return 0; 88 | } 89 | 90 | int c_RkRgaGetBufferFd(bo_t *bo_info, int *fd) 91 | { 92 | c_rkRga.RkRgaGetBufferFd(bo_info, fd); 93 | return 0; 94 | } 95 | #endif /* #ifndef Andorid */ 96 | 97 | -------------------------------------------------------------------------------- /cross/cross_file_aarch64.txt: -------------------------------------------------------------------------------- 1 | [binaries] 2 | c = '/home/lee/new_rk3399_linux/rk3399/buildroot/output/rockchip_rk3399/host/bin/aarch64-buildroot-linux-gnu-gcc' 3 | cpp = '/home/lee/new_rk3399_linux/rk3399/buildroot/output/rockchip_rk3399/host/bin/aarch64-buildroot-linux-gnu-g++' 4 | ar = '/home/lee/new_rk3399_linux/rk3399/buildroot/output/rockchip_rk3399/host/bin/aarch64-buildroot-linux-gnu-ar' 5 | strip = '/home/lee/new_rk3399_linux/rk3399/buildroot/output/rockchip_rk3399/host/bin/aarch64-buildroot-linux-gnu-strip' 6 | pkgconfig = '/home/lee/new_rk3399_linux/rk3399/buildroot/output/rockchip_rk3399/host/bin/pkg-config' 7 | 8 | [host_machine] 9 | system = 'linux' 10 | cpu_family = 'aarch64' 11 | cpu = 'aarch64' 12 | endian = 'little' 13 | 14 | [properties] 15 | needs_exe_wrapper = true 16 | c_args = ['-I/home/lee/new_rk3399_linux/rk3399/buildroot/output/rockchip_rk3399/host/aarch64-buildroot-linux-gnu/sysroot/usr/include', '-L/home/lee/new_rk3399_linux/rk3399/buildroot/output/rockchip_rk3399/host/aarch64-buildroot-linux-gnu/sysroot/usr/lib', '-L/home/lee/new_rk3399_linux/rk3399/buildroot/output/rockchip_rk3399/host/lib', '-I/home/lee/new_rk3399_linux/rk3399/buildroot/output/rockchip_rk3399/host/include'] 17 | -------------------------------------------------------------------------------- /cross/cross_file_arm32.txt: -------------------------------------------------------------------------------- 1 | [binaries] 2 | c = '/home/lee/rv1126/buildroot/output/rockchip_puma/host/bin/arm-linux-gnueabihf-gcc' 3 | cpp = '/home/lee/rv1126/buildroot/output/rockchip_puma/host/bin/arm-linux-gnueabihf-g++' 4 | ar = '/home/lee/rv1126/buildroot/output/rockchip_puma/host/bin/arm-linux-gnueabihf-ar' 5 | strip = '/home/lee/rv1126/buildroot/output/rockchip_puma/host/bin/arm-linux-gnueabihf-gcc-strip' 6 | pkgconfig = '/home/lee/rv1126/buildroot/output/rockchip_puma/host/bin/pkg-config' 7 | 8 | [host_machine] 9 | system = 'linux' 10 | cpu_family = 'arm' 11 | cpu = 'arm' 12 | endian = 'little' 13 | 14 | [properties] 15 | needs_exe_wrapper = true 16 | c_args = ['-I/home/lee/rv1126/buildroot/output/rockchip_puma/host/arm-buildroot-linux-gnueabihf/sysroot/usr/include', '-L/home/lee/rv1126/buildroot/output/rockchip_puma/host/arm-buildroot-linux-gnueabihf/sysroot/usr/lib', '-L/home/lee/rv1126/buildroot/output/rockchip_puma/host/lib', '-I/home/lee/rv1126/buildroot/output/rockchip_puma/host/include'] 17 | -------------------------------------------------------------------------------- /debian/changelog: -------------------------------------------------------------------------------- 1 | librga (2.0.0-1) stable; urgency=medium 2 | 3 | * Initial release. 4 | 5 | -- Jeffy Chen Thu, 23 Jul 2020 17:49:04 +0800 6 | -------------------------------------------------------------------------------- /debian/compat: -------------------------------------------------------------------------------- 1 | 11 2 | -------------------------------------------------------------------------------- /debian/control: -------------------------------------------------------------------------------- 1 | Source: librga 2 | Priority: optional 3 | Maintainer: Putin Lee 4 | Uploaders: Jeffy Chen 5 | Build-Depends: debhelper (>= 11), 6 | libdrm-dev (>= 2.4.0), 7 | meson, 8 | pkg-config 9 | Standards-Version: 4.1.3 10 | Section: libs 11 | Homepage: https://github.com/rockchip-linux/linux-rga 12 | Vcs-Git: https://github.com/rockchip-linux/linux-rga 13 | Vcs-Browser: https://github.com/rockchip-linux/linux-rga 14 | 15 | Package: librga-dev 16 | Section: libdevel 17 | Architecture: any 18 | Description: Userspace interface to Rockchip RGA 2D accelerator 19 | 20 | Package: librga2 21 | Architecture: any 22 | Depends: ${shlibs:Depends}, ${misc:Depends} 23 | Description: Userspace interface to Rockchip RGA 2D accelerator 24 | -------------------------------------------------------------------------------- /debian/copyright: -------------------------------------------------------------------------------- 1 | Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ 2 | Upstream-Name: linux-rga 3 | Source: https://github.com/rockchip-linux/linux-rga 4 | 5 | Files: * 6 | Copyright: 2016 Zhiqin Wei 7 | 2017 Putin Lee 8 | License: GPL-2+ 9 | 10 | Files: debian/* 11 | Copyright: 2020 Jeffy Chen 12 | License: GPL-2+ 13 | This package is free software; you can redistribute it and/or modify 14 | it under the terms of the GNU General Public License as published by 15 | the Free Software Foundation; either version 2 of the License, or 16 | (at your option) any later version. 17 | . 18 | This package is distributed in the hope that it will be useful, 19 | but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | GNU General Public License for more details. 22 | . 23 | You should have received a copy of the GNU General Public License 24 | along with this program. If not, see 25 | . 26 | On Debian systems, the complete text of the GNU General 27 | Public License version 2 can be found in "/usr/share/common-licenses/GPL-2". 28 | 29 | # Please also look if there are files or directories which have a 30 | # different copyright/license attached and list them here. 31 | # Please avoid picking licenses with terms that are more restrictive than the 32 | # packaged work, as it may make Debian's contributions unacceptable upstream. 33 | -------------------------------------------------------------------------------- /debian/librga-dev.dirs: -------------------------------------------------------------------------------- 1 | usr/lib 2 | usr/include 3 | -------------------------------------------------------------------------------- /debian/librga-dev.install: -------------------------------------------------------------------------------- 1 | usr/include/* 2 | usr/lib/*/lib*.so 3 | usr/lib/*/pkgconfig/* 4 | -------------------------------------------------------------------------------- /debian/librga2.dirs: -------------------------------------------------------------------------------- 1 | usr/lib 2 | -------------------------------------------------------------------------------- /debian/librga2.install: -------------------------------------------------------------------------------- 1 | usr/lib/*/lib*.so.* 2 | -------------------------------------------------------------------------------- /debian/rules: -------------------------------------------------------------------------------- 1 | #!/usr/bin/make -f 2 | # See debhelper(7) (uncomment to enable) 3 | # output every command that modifies files on the build system. 4 | export DH_VERBOSE = 1 5 | 6 | override_dh_auto_configure: 7 | dh_auto_configure -- -Dlibdrm=true 8 | 9 | %: 10 | dh $@ --buildsystem=meson 11 | -------------------------------------------------------------------------------- /im2d_api/im2d.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 Rockchip Electronics Co., Ltd. 3 | * Authors: 4 | * PutinLee 5 | * Cerf Yu 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | #ifndef _im2d_hpp_ 20 | #define _im2d_hpp_ 21 | 22 | #include "im2d.h" 23 | #include "RgaUtils.h" 24 | 25 | #ifdef ANDROID 26 | 27 | #include 28 | 29 | using namespace android; 30 | 31 | IM_API rga_buffer_t wrapbuffer_handle(buffer_handle_t hnd); 32 | IM_API rga_buffer_t wrapbuffer_GraphicBuffer(sp buf); 33 | 34 | #if USE_AHARDWAREBUFFER 35 | #include 36 | IM_API rga_buffer_t wrapbuffer_AHardwareBuffer(AHardwareBuffer *buf); 37 | 38 | #endif /* USE_AHARDWAREBUFFER */ 39 | #endif /* ANDROID */ 40 | #endif /* _im2d_hpp_ */ 41 | 42 | -------------------------------------------------------------------------------- /include/GrallocOps.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Rockchip Electronics Co., Ltd. 3 | * Authors: 4 | * Zhiqin Wei 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #ifndef _rk_graphic_buffer_h_ 20 | #define _rk_graphic_buffer_h_ 21 | 22 | #ifdef ANDROID 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | #include 29 | 30 | #include 31 | 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | 39 | #include 40 | #include 41 | 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | 48 | #include "drmrga.h" 49 | #include "rga.h" 50 | 51 | // ------------------------------------------------------------------------------- 52 | int RkRgaGetHandleFd(buffer_handle_t handle, int *fd); 53 | int RkRgaGetHandleAttributes(buffer_handle_t handle, 54 | std::vector *attrs); 55 | int RkRgaGetHandleMapAddress(buffer_handle_t handle, 56 | void **buf); 57 | #endif //Android 58 | 59 | #endif //_rk_graphic_buffer_h_ 60 | -------------------------------------------------------------------------------- /include/RgaApi.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Rockchip Electronics Co., Ltd. 3 | * Authors: 4 | * Zhiqin Wei 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #include 28 | #include 29 | 30 | #include "drmrga.h" 31 | #include "rga.h" 32 | 33 | #ifdef __cplusplus 34 | extern "C"{ 35 | #endif 36 | 37 | /* 38 | * Compatible with the old version of C interface.The new 39 | * version of the C interface no longer requires users to 40 | * initialize rga, so RgaInit and RgaDeInit are just for 41 | * compatibility with the old C interface, so please do 42 | * not use ctx, because it is usually a NULL. 43 | */ 44 | #define RgaInit(ctx) { \ 45 | (void)ctx; /* unused */ \ 46 | c_RkRgaInit(); \ 47 | } 48 | #define RgaDeInit(ctx) { \ 49 | (void)ctx; /* unused */ \ 50 | c_RkRgaDeInit(); \ 51 | } 52 | #define RgaBlit(...) c_RkRgaBlit(__VA_ARGS__) 53 | #define RgaCollorFill(...) c_RkRgaColorFill(__VA_ARGS__) 54 | #define RgaFlush() c_RkRgaFlush() 55 | 56 | int c_RkRgaInit(); 57 | void c_RkRgaDeInit(); 58 | int c_RkRgaBlit(rga_info_t *src, rga_info_t *dst, rga_info_t *src1); 59 | int c_RkRgaColorFill(rga_info_t *dst); 60 | int c_RkRgaFlush(); 61 | 62 | #ifndef ANDROID /* linux */ 63 | int c_RkRgaGetAllocBuffer(bo_t *bo_info, int width, int height, int bpp); 64 | int c_RkRgaGetAllocBufferCache(bo_t *bo_info, int width, int height, int bpp); 65 | int c_RkRgaGetMmap(bo_t *bo_info); 66 | int c_RkRgaUnmap(bo_t *bo_info); 67 | int c_RkRgaFree(bo_t *bo_info); 68 | int c_RkRgaGetBufferFd(bo_t *bo_info, int *fd); 69 | #endif /* #ifndef ANDROID */ 70 | 71 | #ifdef __cplusplus 72 | } 73 | #endif 74 | -------------------------------------------------------------------------------- /include/RgaMutex.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 Rockchip Electronics Co., Ltd. 3 | * Authors: 4 | * PutinLee 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | 20 | #ifndef _LIBS_RGA_MUTEX_H 21 | #define _LIBS_RGA_MUTEX_H 22 | 23 | #ifndef ANDROID 24 | #include 25 | #include 26 | #include 27 | 28 | #include 29 | 30 | 31 | // Enable thread safety attributes only with clang. 32 | // The attributes can be safely erased when compiling with other compilers. 33 | #if defined(__clang__) && (!defined(SWIG)) 34 | #define THREAD_ANNOTATION_ATTRIBUTE__(x) __attribute__((x)) 35 | #else 36 | #define THREAD_ANNOTATION_ATTRIBUTE__(x) // no-op 37 | #endif 38 | 39 | #define CAPABILITY(x) THREAD_ANNOTATION_ATTRIBUTE__(capability(x)) 40 | 41 | #define SCOPED_CAPABILITY THREAD_ANNOTATION_ATTRIBUTE__(scoped_lockable) 42 | 43 | #define GUARDED_BY(x) THREAD_ANNOTATION_ATTRIBUTE__(guarded_by(x)) 44 | 45 | #define PT_GUARDED_BY(x) THREAD_ANNOTATION_ATTRIBUTE__(pt_guarded_by(x)) 46 | 47 | #define ACQUIRED_BEFORE(...) THREAD_ANNOTATION_ATTRIBUTE__(acquired_before(__VA_ARGS__)) 48 | 49 | #define ACQUIRED_AFTER(...) THREAD_ANNOTATION_ATTRIBUTE__(acquired_after(__VA_ARGS__)) 50 | 51 | #define REQUIRES(...) THREAD_ANNOTATION_ATTRIBUTE__(requires_capability(__VA_ARGS__)) 52 | 53 | #define REQUIRES_SHARED(...) THREAD_ANNOTATION_ATTRIBUTE__(requires_shared_capability(__VA_ARGS__)) 54 | 55 | #define ACQUIRE(...) THREAD_ANNOTATION_ATTRIBUTE__(acquire_capability(__VA_ARGS__)) 56 | 57 | #define ACQUIRE_SHARED(...) THREAD_ANNOTATION_ATTRIBUTE__(acquire_shared_capability(__VA_ARGS__)) 58 | 59 | #define RELEASE(...) THREAD_ANNOTATION_ATTRIBUTE__(release_capability(__VA_ARGS__)) 60 | 61 | #define RELEASE_SHARED(...) THREAD_ANNOTATION_ATTRIBUTE__(release_shared_capability(__VA_ARGS__)) 62 | 63 | #define TRY_ACQUIRE(...) THREAD_ANNOTATION_ATTRIBUTE__(try_acquire_capability(__VA_ARGS__)) 64 | 65 | #define TRY_ACQUIRE_SHARED(...) \ 66 | THREAD_ANNOTATION_ATTRIBUTE__(try_acquire_shared_capability(__VA_ARGS__)) 67 | 68 | #define EXCLUDES(...) THREAD_ANNOTATION_ATTRIBUTE__(locks_excluded(__VA_ARGS__)) 69 | 70 | #define ASSERT_CAPABILITY(x) THREAD_ANNOTATION_ATTRIBUTE__(assert_capability(x)) 71 | 72 | #define ASSERT_SHARED_CAPABILITY(x) THREAD_ANNOTATION_ATTRIBUTE__(assert_shared_capability(x)) 73 | 74 | #define RETURN_CAPABILITY(x) THREAD_ANNOTATION_ATTRIBUTE__(lock_returned(x)) 75 | 76 | #define NO_THREAD_SAFETY_ANALYSIS THREAD_ANNOTATION_ATTRIBUTE__(no_thread_safety_analysis) 77 | 78 | class Condition; 79 | 80 | /* 81 | * NOTE: This class is for code that builds on Win32. Its usage is 82 | * deprecated for code which doesn't build for Win32. New code which 83 | * doesn't build for Win32 should use std::mutex and std::lock_guard instead. 84 | * 85 | * Simple mutex class. The implementation is system-dependent. 86 | * 87 | * The mutex must be unlocked by the thread that locked it. They are not 88 | * recursive, i.e. the same thread can't lock it multiple times. 89 | */ 90 | class CAPABILITY("mutex") Mutex { 91 | public: 92 | enum { 93 | PRIVATE = 0, 94 | SHARED = 1 95 | }; 96 | 97 | Mutex(); 98 | explicit Mutex(const char* name); 99 | explicit Mutex(int type, const char* name = nullptr); 100 | ~Mutex(); 101 | 102 | // lock or unlock the mutex 103 | int32_t lock() ACQUIRE(); 104 | void unlock() RELEASE(); 105 | 106 | // lock if possible; returns 0 on success, error otherwise 107 | int32_t tryLock() TRY_ACQUIRE(0); 108 | 109 | int32_t timedLock(int64_t timeoutNs) TRY_ACQUIRE(0); 110 | 111 | // Manages the mutex automatically. It'll be locked when Autolock is 112 | // constructed and released when Autolock goes out of scope. 113 | class SCOPED_CAPABILITY Autolock { 114 | public: 115 | inline explicit Autolock(Mutex& mutex) ACQUIRE(mutex) : mLock(mutex) { 116 | mLock.lock(); 117 | } 118 | inline explicit Autolock(Mutex* mutex) ACQUIRE(mutex) : mLock(*mutex) { 119 | mLock.lock(); 120 | } 121 | inline ~Autolock() RELEASE() { 122 | mLock.unlock(); 123 | } 124 | 125 | private: 126 | Mutex& mLock; 127 | // Cannot be copied or moved - declarations only 128 | Autolock(const Autolock&); 129 | Autolock& operator=(const Autolock&); 130 | }; 131 | 132 | private: 133 | friend class Condition; 134 | 135 | // A mutex cannot be copied 136 | Mutex(const Mutex&); 137 | Mutex& operator=(const Mutex&); 138 | 139 | pthread_mutex_t mMutex; 140 | }; 141 | 142 | // --------------------------------------------------------------------------- 143 | inline Mutex::Mutex() { 144 | pthread_mutex_init(&mMutex, nullptr); 145 | } 146 | inline Mutex::Mutex(__attribute__((unused)) const char* name) { 147 | pthread_mutex_init(&mMutex, nullptr); 148 | } 149 | inline Mutex::Mutex(int type, __attribute__((unused)) const char* name) { 150 | if (type == SHARED) { 151 | pthread_mutexattr_t attr; 152 | pthread_mutexattr_init(&attr); 153 | pthread_mutexattr_setpshared(&attr, PTHREAD_PROCESS_SHARED); 154 | pthread_mutex_init(&mMutex, &attr); 155 | pthread_mutexattr_destroy(&attr); 156 | } else { 157 | pthread_mutex_init(&mMutex, nullptr); 158 | } 159 | } 160 | inline Mutex::~Mutex() { 161 | pthread_mutex_destroy(&mMutex); 162 | } 163 | inline int32_t Mutex::lock() { 164 | return -pthread_mutex_lock(&mMutex); 165 | } 166 | inline void Mutex::unlock() { 167 | pthread_mutex_unlock(&mMutex); 168 | } 169 | inline int32_t Mutex::tryLock() { 170 | return -pthread_mutex_trylock(&mMutex); 171 | } 172 | inline int32_t Mutex::timedLock(int64_t timeoutNs) { 173 | timespec now; 174 | clock_gettime(CLOCK_REALTIME, &now); 175 | timeoutNs += now.tv_sec*1000000000 + now.tv_nsec; 176 | const struct timespec ts = { 177 | /* .tv_sec = */ static_cast(timeoutNs / 1000000000), 178 | /* .tv_nsec = */ static_cast(timeoutNs % 1000000000), 179 | }; 180 | return -pthread_mutex_timedlock(&mMutex, &ts); 181 | } 182 | 183 | // --------------------------------------------------------------------------- 184 | 185 | /* 186 | * Automatic mutex. Declare one of these at the top of a function. 187 | * When the function returns, it will go out of scope, and release the 188 | * mutex. 189 | */ 190 | 191 | typedef Mutex::Autolock AutoMutex; 192 | #endif // __ANDROID_VNDK__ 193 | #endif // _LIBS_RGA_MUTEX_H 194 | -------------------------------------------------------------------------------- /include/RgaSingleton.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Rockchip Electronics Co., Ltd. 3 | * Authors: 4 | * Zhiqin Wei 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #ifndef _LIBS_RGA_SINGLETON_H 20 | #define _LIBS_RGA_SINGLETON_H 21 | 22 | #ifndef ANDROID 23 | #include "RgaMutex.h" 24 | 25 | #if defined(__clang__) 26 | #pragma clang diagnostic push 27 | #pragma clang diagnostic ignored "-Wundefined-var-template" 28 | #endif 29 | 30 | template 31 | class Singleton { 32 | public: 33 | static TYPE& getInstance() { 34 | Mutex::Autolock _l(sLock); 35 | TYPE* instance = sInstance; 36 | if (instance == nullptr) { 37 | instance = new TYPE(); 38 | sInstance = instance; 39 | } 40 | return *instance; 41 | } 42 | 43 | static bool hasInstance() { 44 | Mutex::Autolock _l(sLock); 45 | return sInstance != nullptr; 46 | } 47 | 48 | protected: 49 | ~Singleton() { } 50 | Singleton() { } 51 | 52 | private: 53 | Singleton(const Singleton&); 54 | Singleton& operator = (const Singleton&); 55 | static Mutex sLock; 56 | static TYPE* sInstance; 57 | }; 58 | 59 | #if defined(__clang__) 60 | #pragma clang diagnostic pop 61 | #endif 62 | 63 | #define RGA_SINGLETON_STATIC_INSTANCE(TYPE) \ 64 | template<> ::Mutex \ 65 | (::Singleton< TYPE >::sLock)(::Mutex::PRIVATE); \ 66 | template<> TYPE* ::Singleton< TYPE >::sInstance(nullptr); /* NOLINT */ \ 67 | template class ::Singleton< TYPE >; 68 | 69 | #endif //ANDROID 70 | #endif //_LIBS_RGA_SINGLETON_H 71 | -------------------------------------------------------------------------------- /include/RgaUtils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Rockchip Electronics Co., Ltd. 3 | * Authors: 4 | * Zhiqin Wei 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #ifndef _rga_utils_h_ 20 | #define _rga_utils_h_ 21 | 22 | // ------------------------------------------------------------------------------- 23 | float get_bpp_from_format(int format); 24 | int get_buf_from_file(void *buf, int f, int sw, int sh, int index); 25 | int output_buf_data_to_file(void *buf, int f, int sw, int sh, int index); 26 | #endif 27 | 28 | -------------------------------------------------------------------------------- /include/RockchipRga.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Rockchip Electronics Co., Ltd. 3 | * Authors: 4 | * Zhiqin Wei 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #ifndef _rockchip_rga_h_ 20 | #define _rockchip_rga_h_ 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | #include "drmrga.h" 34 | #include "GrallocOps.h" 35 | #include "RgaUtils.h" 36 | #include "rga.h" 37 | 38 | ////////////////////////////////////////////////////////////////////////////////// 39 | #ifndef ANDROID 40 | #include "RgaSingleton.h" 41 | #endif 42 | 43 | #ifdef ANDROID 44 | #include 45 | #include 46 | #include 47 | 48 | namespace android { 49 | #endif 50 | 51 | class RockchipRga :public Singleton { 52 | public: 53 | 54 | static inline RockchipRga& get() { 55 | return getInstance(); 56 | } 57 | 58 | int RkRgaInit(); 59 | void RkRgaDeInit(); 60 | #ifndef ANDROID /* LINUX */ 61 | int RkRgaAllocBuffer(int drm_fd /* input */, bo_t *bo_info, 62 | int width, int height, int bpp, int flags); 63 | int RkRgaFreeBuffer(int drm_fd /* input */, bo_t *bo_info); 64 | int RkRgaGetAllocBuffer(bo_t *bo_info, int width, int height, int bpp); 65 | int RkRgaGetAllocBufferExt(bo_t *bo_info, int width, int height, int bpp, int flags); 66 | int RkRgaGetAllocBufferCache(bo_t *bo_info, int width, int height, int bpp); 67 | int RkRgaGetMmap(bo_t *bo_info); 68 | int RkRgaUnmap(bo_t *bo_info); 69 | int RkRgaFree(bo_t *bo_info); 70 | int RkRgaGetBufferFd(bo_t *bo_info, int *fd); 71 | #else 72 | int RkRgaGetBufferFd(buffer_handle_t handle, int *fd); 73 | int RkRgaGetHandleMapCpuAddress(buffer_handle_t handle, void **buf); 74 | #endif 75 | int RkRgaBlit(rga_info *src, rga_info *dst, rga_info *src1); 76 | int RkRgaSrcOver(rga_info *src, rga_info *dst, rga_info *src1); 77 | int RkRgaCollorFill(rga_info *dst); 78 | int RkRgaCollorPalette(rga_info *src, rga_info *dst, rga_info *lut); 79 | int RkRgaFlush(); 80 | 81 | 82 | void RkRgaSetLogOnceFlag(int log) { 83 | mLogOnce = log; 84 | } 85 | void RkRgaSetAlwaysLogFlag(bool log) { 86 | mLogAlways = log; 87 | } 88 | void RkRgaLogOutRgaReq(struct rga_req rgaReg); 89 | int RkRgaLogOutUserPara(rga_info *rgaInfo); 90 | inline bool RkRgaIsReady() { 91 | return mSupportRga; 92 | } 93 | 94 | RockchipRga(); 95 | ~RockchipRga(); 96 | private: 97 | bool mSupportRga; 98 | int mLogOnce; 99 | int mLogAlways; 100 | void * mContext; 101 | 102 | friend class Singleton; 103 | }; 104 | 105 | #ifdef ANDROID 106 | }; // namespace android 107 | #endif 108 | 109 | #endif 110 | 111 | -------------------------------------------------------------------------------- /include/drmrga.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Rockchip Electronics Co., Ltd. 3 | * Authors: 4 | * Zhiqin Wei 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #ifndef _rk_drm_rga_ 20 | #define _rk_drm_rga_ 21 | 22 | #include 23 | #include 24 | 25 | #ifdef ANDROID 26 | #define DRMRGA_HARDWARE_MODULE_ID "librga" 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #endif 33 | 34 | #ifndef ANDROID /* LINUX */ 35 | /* flip source image horizontally (around the vertical axis) */ 36 | #define HAL_TRANSFORM_FLIP_H 0x01 37 | /* flip source image vertically (around the horizontal axis)*/ 38 | #define HAL_TRANSFORM_FLIP_V 0x02 39 | /* rotate source image 90 degrees clockwise */ 40 | #define HAL_TRANSFORM_ROT_90 0x04 41 | /* rotate source image 180 degrees */ 42 | #define HAL_TRANSFORM_ROT_180 0x03 43 | /* rotate source image 270 degrees clockwise */ 44 | #define HAL_TRANSFORM_ROT_270 0x07 45 | #endif 46 | 47 | #define HAL_TRANSFORM_FLIP_H_V 0x08 48 | 49 | /*****************************************************************************/ 50 | 51 | /* for compatibility */ 52 | #define DRM_RGA_MODULE_API_VERSION HWC_MODULE_API_VERSION_0_1 53 | #define DRM_RGA_DEVICE_API_VERSION HWC_DEVICE_API_VERSION_0_1 54 | #define DRM_RGA_API_VERSION HWC_DEVICE_API_VERSION 55 | 56 | #define DRM_RGA_TRANSFORM_ROT_MASK 0x0000000F 57 | #define DRM_RGA_TRANSFORM_ROT_0 0x00000000 58 | #define DRM_RGA_TRANSFORM_ROT_90 HAL_TRANSFORM_ROT_90 59 | #define DRM_RGA_TRANSFORM_ROT_180 HAL_TRANSFORM_ROT_180 60 | #define DRM_RGA_TRANSFORM_ROT_270 HAL_TRANSFORM_ROT_270 61 | 62 | #define DRM_RGA_TRANSFORM_FLIP_MASK 0x00000003 63 | #define DRM_RGA_TRANSFORM_FLIP_H HAL_TRANSFORM_FLIP_H 64 | #define DRM_RGA_TRANSFORM_FLIP_V HAL_TRANSFORM_FLIP_V 65 | 66 | enum { 67 | AWIDTH = 0, 68 | AHEIGHT, 69 | ASTRIDE, 70 | AFORMAT, 71 | ASIZE, 72 | ATYPE, 73 | }; 74 | /*****************************************************************************/ 75 | 76 | #ifndef ANDROID 77 | /* memory type definitions. */ 78 | enum drm_rockchip_gem_mem_type { 79 | /* Physically Continuous memory and used as default. */ 80 | ROCKCHIP_BO_CONTIG = 1 << 0, 81 | /* cachable mapping. */ 82 | ROCKCHIP_BO_CACHABLE = 1 << 1, 83 | /* write-combine mapping. */ 84 | ROCKCHIP_BO_WC = 1 << 2, 85 | ROCKCHIP_BO_SECURE = 1 << 3, 86 | ROCKCHIP_BO_MASK = ROCKCHIP_BO_CONTIG | ROCKCHIP_BO_CACHABLE | 87 | ROCKCHIP_BO_WC | ROCKCHIP_BO_SECURE 88 | }; 89 | 90 | typedef struct bo { 91 | int fd; 92 | void *ptr; 93 | size_t size; 94 | size_t offset; 95 | size_t pitch; 96 | unsigned handle; 97 | } bo_t; 98 | #endif 99 | 100 | /* 101 | @value size: user not need care about.For avoid read/write out of memory 102 | */ 103 | typedef struct rga_rect { 104 | int xoffset; 105 | int yoffset; 106 | int width; 107 | int height; 108 | int wstride; 109 | int hstride; 110 | int format; 111 | int size; 112 | } rga_rect_t; 113 | 114 | typedef struct rga_nn { 115 | int nn_flag; 116 | int scale_r; 117 | int scale_g; 118 | int scale_b; 119 | int offset_r; 120 | int offset_g; 121 | int offset_b; 122 | } rga_nn_t; 123 | 124 | typedef struct rga_dither { 125 | int enable; 126 | int mode; 127 | int lut0_l; 128 | int lut0_h; 129 | int lut1_l; 130 | int lut1_h; 131 | } rga_dither_t; 132 | 133 | /* 134 | @value fd: use fd to share memory, it can be ion shard fd,and dma fd. 135 | @value virAddr:userspace address 136 | @value phyAddr:use phy address 137 | @value hnd: use buffer_handle_t 138 | */ 139 | typedef struct rga_info { 140 | int fd; 141 | void *virAddr; 142 | void *phyAddr; 143 | #ifndef ANDROID /* LINUX */ 144 | unsigned hnd; 145 | #else /* Android */ 146 | buffer_handle_t hnd; 147 | #endif 148 | int format; 149 | rga_rect_t rect; 150 | unsigned int blend; 151 | int bufferSize; 152 | int rotation; 153 | int color; 154 | int testLog; 155 | int mmuFlag; 156 | int colorkey_en; 157 | int colorkey_max; 158 | int colorkey_min; 159 | int scale_mode; 160 | int color_space_mode; 161 | int sync_mode; 162 | rga_nn_t nn; 163 | rga_dither_t dither; 164 | int rop_code; 165 | int reserve[128]; 166 | } rga_info_t; 167 | 168 | 169 | typedef struct drm_rga { 170 | rga_rect_t src; 171 | rga_rect_t dst; 172 | } drm_rga_t; 173 | 174 | /* 175 | @fun rga_set_rect:For use to set the rects esayly 176 | 177 | @param rect:The rect user want to set,like setting the src rect: 178 | drm_rga_t rects; 179 | rga_set_rect(rects.src,0,0,1920,1080,1920,NV12); 180 | mean to set the src rect to the value. 181 | */ 182 | static inline int rga_set_rect(rga_rect_t *rect, 183 | int x, int y, int w, int h, int sw, int sh, int f) { 184 | if (!rect) 185 | return -EINVAL; 186 | 187 | rect->xoffset = x; 188 | rect->yoffset = y; 189 | rect->width = w; 190 | rect->height = h; 191 | rect->wstride = sw; 192 | rect->hstride = sh; 193 | rect->format = f; 194 | 195 | return 0; 196 | } 197 | 198 | #ifndef ANDROID /* LINUX */ 199 | static inline void rga_set_rotation(rga_info_t *info, int angle) { 200 | if (angle == 90) 201 | info->rotation = HAL_TRANSFORM_ROT_90; 202 | else if (angle == 180) 203 | info->rotation = HAL_TRANSFORM_ROT_180; 204 | else if (angle == 270) 205 | info->rotation = HAL_TRANSFORM_ROT_270; 206 | } 207 | #endif 208 | /*****************************************************************************/ 209 | 210 | #endif 211 | -------------------------------------------------------------------------------- /include/platform_gralloc4.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017-2018 RockChip Limited. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /* -------------------------------------------------------------------------------------------------------- 18 | * File: platform_gralloc4.h 19 | * 20 | * Desc: 声明对 buffer_handle_t 实例的 get metadata, import_buffer/free_buffer, lock_buffer/unlock_buffer 等接口. 21 | * 这些接口都将基于 IMapper 4.0 (gralloc 4.0) 实现. 22 | * 23 | * ----------------------------------------------------------------------------------- 24 | * < 习语 和 缩略语 > : 25 | * 26 | * ----------------------------------------------------------------------------------- 27 | * Usage: 28 | * 29 | * Note: 30 | * 31 | * Author: ChenZhen 32 | * 33 | * Log: 34 | * init. 35 | ----Fri Aug 28 10:10:14 2020 36 | * 37 | * -------------------------------------------------------------------------------------------------------- 38 | */ 39 | 40 | 41 | #ifndef __PLATFORM_GRALLOC4_H__ 42 | #define __PLATFORM_GRALLOC4_H__ 43 | 44 | 45 | /* --------------------------------------------------------------------------------------------------------- 46 | * Include Files 47 | * --------------------------------------------------------------------------------------------------------- 48 | */ 49 | // #include 50 | 51 | #include 52 | 53 | #include 54 | #include 55 | 56 | #include 57 | 58 | /* --------------------------------------------------------------------------------------------------------- 59 | * Macros Definition 60 | * --------------------------------------------------------------------------------------------------------- 61 | */ 62 | 63 | 64 | namespace gralloc4 { 65 | /* --------------------------------------------------------------------------------------------------------- 66 | * Types and Structures Definition 67 | * --------------------------------------------------------------------------------------------------------- 68 | */ 69 | 70 | 71 | /* --------------------------------------------------------------------------------------------------------- 72 | * Global Functions' Prototype 73 | * --------------------------------------------------------------------------------------------------------- 74 | */ 75 | 76 | /* 77 | * 获取 'handle' 引用的 graphic_buffer 的 internal_format. 78 | */ 79 | uint64_t get_internal_format(buffer_handle_t handle); 80 | 81 | int get_width(buffer_handle_t handle, uint64_t* width); 82 | 83 | int get_height(buffer_handle_t handle, uint64_t* height); 84 | 85 | int get_pixel_stride(buffer_handle_t handle, int* pixel_stride); 86 | 87 | int get_byte_stride(buffer_handle_t handle, int* byte_stride); 88 | 89 | int get_format_requested(buffer_handle_t handle, int* format_requested); 90 | 91 | int get_usage(buffer_handle_t handle, uint64_t* usage); 92 | 93 | int get_allocation_size(buffer_handle_t handle, uint64_t* usage); 94 | 95 | int get_share_fd(buffer_handle_t handle, int* share_fd); 96 | 97 | using android::status_t; 98 | 99 | status_t importBuffer(buffer_handle_t rawHandle, buffer_handle_t* outHandle); 100 | 101 | void freeBuffer(buffer_handle_t handle); 102 | 103 | status_t lock(buffer_handle_t bufferHandle, 104 | uint64_t usage, 105 | int x, 106 | int y, 107 | int w, 108 | int h, 109 | void** outData); 110 | 111 | void unlock(buffer_handle_t bufferHandle); 112 | 113 | /* --------------------------------------------------------------------------------------------------------- 114 | * Inline Functions Implementation 115 | * --------------------------------------------------------------------------------------------------------- 116 | */ 117 | 118 | } 119 | 120 | #endif /* __PLATFORM_GRALLOC4_H__ */ 121 | 122 | -------------------------------------------------------------------------------- /meson.build: -------------------------------------------------------------------------------- 1 | project( 2 | 'librga', 3 | 'cpp', 4 | version : '2.0.0', 5 | meson_version : '>=0.47.0', 6 | default_options : ['warning_level=3', 'cpp_std=c++14'] 7 | ) 8 | 9 | pkgconfig = import('pkgconfig') 10 | 11 | libdrm_dep = dependency('', required : false) 12 | libdrm_option = get_option('libdrm') 13 | if libdrm_option != 'false' 14 | libdrm_dep = dependency('libdrm', version : '>= 2.4.0') 15 | if libdrm_option == 'true' and not libdrm_dep.found() 16 | error('libdrm requested, but not found.') 17 | endif 18 | endif 19 | 20 | if libdrm_dep.found() 21 | message('Building with libdrm.') 22 | add_project_arguments('-DLIBDRM=1', language : 'cpp') 23 | else 24 | message('Building without libdrm.') 25 | endif 26 | 27 | libthreads_dep = dependency('threads') 28 | 29 | git_version_h = vcs_tag( 30 | command : ['git', 'rev-parse', '--short', 'HEAD'], 31 | input : 'version.h.in', output : 'version.h', 32 | ) 33 | add_project_arguments('-include', 'version.h', language : 'cpp') 34 | add_project_arguments('-DLINUX=1', language : 'cpp') 35 | 36 | librga_srcs = [ 37 | git_version_h, 38 | 'core/GrallocOps.cpp', 39 | 'core/NormalRgaApi.cpp', 40 | 'core/NormalRga.cpp', 41 | 'core/RgaUtils.cpp', 42 | 'core/RockchipRga.cpp', 43 | 'core/RgaApi.cpp', 44 | 'im2d_api/im2d.cpp', 45 | ] 46 | 47 | incdir = include_directories('include') 48 | 49 | librga = shared_library( 50 | 'rga', 51 | librga_srcs, 52 | dependencies : [libdrm_dep, libthreads_dep], 53 | include_directories : incdir, 54 | version : meson.project_version(), 55 | install : true, 56 | ) 57 | 58 | install_headers( 59 | 'include/rga.h', 60 | 'include/drmrga.h', 61 | 'include/GrallocOps.h', 62 | 'include/RockchipRga.h', 63 | 'include/RgaMutex.h', 64 | 'include/RgaSingleton.h', 65 | 'include/RgaUtils.h', 66 | 'include/RgaApi.h', 67 | 'im2d_api/im2d.h', 68 | 'im2d_api/im2d.hpp', 69 | subdir : 'rga', 70 | ) 71 | 72 | pkgconfig.generate( 73 | libraries : librga, 74 | filebase : 'librga', 75 | name : 'librga', 76 | version : meson.project_version(), 77 | description : 'Userspace interface to Rockchip RGA 2D accelerator', 78 | ) 79 | 80 | librga_demo_option = get_option('librga_demo') 81 | if librga_demo_option != 'false' 82 | demo_src = [ 83 | git_version_h, 84 | 'samples/im2d_api_demo/rgaImDemo.cpp', 85 | 'samples/im2d_api_demo/args.cpp' 86 | ] 87 | demo_incdir = include_directories('include', 'im2d_api') 88 | librga_dep = dependency('librga') 89 | executable( 90 | 'rgaImDemo', 91 | demo_src, 92 | include_directories : demo_incdir, 93 | dependencies : librga_dep, 94 | cpp_args : ['-Wno-pedantic'], 95 | install : true, 96 | ) 97 | endif 98 | -------------------------------------------------------------------------------- /meson.sh: -------------------------------------------------------------------------------- 1 | echo "# to rm ./build-rga/" 2 | rm -rf build-rga 3 | 4 | ORIGINAL_PATH=$PATH 5 | export PATH=/home/lee/new_rk3399_linux/rk3399/buildroot/output/rockchip_rk3399/host/bin:$PATH 6 | #export PATH=/home/lee/rk3399_linux/output/rockchip_rk3399/host/bin:$PATH 7 | 8 | export PKG_CONFIG_PATH=/home/lee/new_rk3399_linux/rk3399/buildroot/output/rockchip_rk3399/host/lib/pkgconfig:/home/lee/new_rk3399_linux/rk3399/buildroot/output/rockchip_rk3399/host/usr/aarch64-buildroot-linux-gnu/sysroot/usr/lib/pkgconfig 9 | #export PKG_CONFIG_PATH=/home/lee/rk3399_linux/output/rockchip_rk3399/host/lib/pkgconfig 10 | 11 | meson --prefix=/home/lee/new_rk3399_linux/rk3399/external/rga/output build-rga --cross-file cross/cross_file_aarch64.txt 12 | 13 | export PATH=$ORIGINAL_PATH 14 | 15 | unset PKG_CONFIG_PATH 16 | -------------------------------------------------------------------------------- /meson_options.txt: -------------------------------------------------------------------------------- 1 | option('libdrm', type: 'combo', choices: ['true', 'false', 'auto'], value: 'auto', 2 | description: 'With libdrm (default: auto)') 3 | option('librga_demo', type: 'combo', choices: ['true', 'false', 'auto'], value: 'false', 4 | description: 'With librga_demo (default: false)') 5 | -------------------------------------------------------------------------------- /samples/im2d_api_demo/Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH:= $(call my-dir) 2 | #====================================================================== 3 | # 4 | #rgaImDemo 5 | # 6 | #====================================================================== 7 | include $(CLEAR_VARS) 8 | LOCAL_VENDOR_MODULE := true 9 | 10 | LOCAL_CFLAGS += -DGL_GLEXT_PROTOTYPES -DEGL_EGLEXT_PROTOTYPES 11 | 12 | LOCAL_CFLAGS += -DROCKCHIP_GPU_LIB_ENABLE 13 | 14 | ifeq (1,$(strip $(shell expr $(PLATFORM_SDK_VERSION) \> 25))) 15 | LOCAL_CFLAGS += -DUSE_AHARDWAREBUFFER=1 16 | endif 17 | 18 | LOCAL_CFLAGS += -Wall -Werror -Wunreachable-code 19 | 20 | LOCAL_C_INCLUDES += \ 21 | $(LOCAL_PATH)/../.. \ 22 | $(LOCAL_PATH)/../../include 23 | 24 | LOCAL_SHARED_LIBRARIES := \ 25 | libcutils \ 26 | liblog \ 27 | libutils \ 28 | libui \ 29 | libEGL \ 30 | libGLESv1_CM \ 31 | libhardware \ 32 | librga \ 33 | libnativewindow 34 | 35 | LOCAL_HEADER_LIBRARIES += \ 36 | libutils_headers \ 37 | libcutils_headers \ 38 | libhardware_headers \ 39 | liblog_headers \ 40 | libgui_headers \ 41 | libbinder_headers 42 | 43 | #has no "external/stlport" from Android 6.0 on 44 | ifeq (1,$(strip $(shell expr $(PLATFORM_VERSION) \< 6.0))) 45 | LOCAL_C_INCLUDES += \ 46 | external/stlport/stlport 47 | 48 | LOCAL_C_INCLUDES += bionic 49 | endif 50 | 51 | #ifeq ($(strip $(BOARD_USE_DRM)), true) 52 | #ifneq (1,$(strip $(shell expr $(PLATFORM_VERSION) \< 6.9))) 53 | LOCAL_CFLAGS += -DANDROID_7_DRM -DANDROID 54 | #endif 55 | #endif 56 | 57 | ifeq ($(strip $(TARGET_BOARD_PLATFORM)),rk3368) 58 | LOCAL_CFLAGS += -DRK3368 59 | endif 60 | 61 | ifneq (1,$(strip $(shell expr $(PLATFORM_VERSION) \< 8.0))) 62 | LOCAL_CFLAGS += -DANDROID_8 63 | endif 64 | 65 | ifeq ($(strip $(TARGET_BOARD_PLATFORM)),rk3188) 66 | LOCAL_CFLAGS += -DRK3188 67 | endif 68 | 69 | LOCAL_SRC_FILES:= \ 70 | rgaImDemo.cpp \ 71 | args.cpp 72 | 73 | LOCAL_MODULE:= rgaImDemo 74 | 75 | ifdef TARGET_32_BIT_SURFACEFLINGER 76 | LOCAL_32_BIT_ONLY := true 77 | endif 78 | 79 | include $(BUILD_EXECUTABLE) 80 | 81 | -------------------------------------------------------------------------------- /samples/im2d_api_demo/args.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 Rockchip Electronics Co., Ltd. 3 | * Authors: 4 | * PutinLee 5 | * Cerf Yu 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | 20 | #ifndef ARGS_H 21 | #define ARGS_H 22 | 23 | #include "im2d_api/im2d.hpp" 24 | 25 | typedef enum _mode_code { 26 | MODE_QUERYSTRING = 0, 27 | MODE_COPY, 28 | MODE_RESIZE, 29 | MODE_CROP, 30 | MODE_ROTATE, 31 | MODE_FLIP, 32 | MODE_TRANSLATE, 33 | MODE_BLEND, 34 | MODE_CVTCOLOR, 35 | MODE_FILL, 36 | MODE_WHILE, 37 | MODE_NONE, 38 | MODE_MAX 39 | } MODE_CODE; 40 | 41 | #define MODE_QUERYSTRING_CHAR (char) (MODE_QUERYSTRING+'0') 42 | #define MODE_COPY_CHAR (char) (MODE_COPY +'0') 43 | #define MODE_RESIZE_CHAR (char) (MODE_RESIZE +'0') 44 | #define MODE_CROP_CHAR (char) (MODE_CROP +'0') 45 | #define MODE_ROTATE_CHAR (char) (MODE_ROTATE +'0') 46 | #define MODE_FLIP_CHAR (char) (MODE_FLIP +'0') 47 | #define MODE_TRANSLATE_CHAR (char) (MODE_TRANSLATE +'0') 48 | #define MODE_BLEND_CHAR (char) (MODE_BLEND +'0') 49 | #define MODE_CVTCOLOR_CHAR (char) (MODE_CVTCOLOR +'0') 50 | #define MODE_FILL_CHAR (char) (MODE_FILL +'0') 51 | #define MODE_NONE_CHAR (char) (MODE_NONE +'0') 52 | 53 | #define BLUE_COLOR 0xffff0000 54 | #define GREEN_COLOR 0xff00ff00 55 | #define RED_COLOR 0xff0000ff 56 | #define WHILE_FLAG (1 << 7) 57 | 58 | int readArguments(int argc, char *argv[], int* parm); 59 | IM_INFORMATION readInfo(char* targ); 60 | int readParm(char* targ); 61 | 62 | #endif 63 | 64 | -------------------------------------------------------------------------------- /samples/rgaBlit/Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH:= $(call my-dir) 2 | #====================================================================== 3 | # 4 | #rgaBlit 5 | # 6 | #====================================================================== 7 | include $(CLEAR_VARS) 8 | LOCAL_VENDOR_MODULE := true 9 | 10 | LOCAL_CFLAGS += -DGL_GLEXT_PROTOTYPES -DEGL_EGLEXT_PROTOTYPES 11 | 12 | LOCAL_CFLAGS += -DROCKCHIP_GPU_LIB_ENABLE 13 | 14 | LOCAL_CFLAGS += -Wall -Werror -Wunreachable-code 15 | 16 | LOCAL_C_INCLUDES += external/tinyalsa/include 17 | 18 | LOCAL_C_INCLUDES += hardware/rockchip/librga 19 | LOCAL_C_INCLUDES += hardware/rk29/librga \ 20 | system/core \ 21 | system/core/include/utils \ 22 | system/core/liblog/include \ 23 | $(LOCAL_PATH)/../.. \ 24 | $(LOCAL_PATH)/../../include 25 | 26 | LOCAL_SHARED_LIBRARIES := \ 27 | libcutils \ 28 | liblog \ 29 | libutils \ 30 | libui \ 31 | libEGL \ 32 | libGLESv1_CM \ 33 | libhardware \ 34 | librga 35 | 36 | LOCAL_HEADER_LIBRARIES += \ 37 | libutils_headers \ 38 | libcutils_headers \ 39 | libhardware_headers \ 40 | liblog_headers \ 41 | libgui_headers \ 42 | libbinder_headers 43 | 44 | #has no "external/stlport" from Android 6.0 on 45 | ifeq (1,$(strip $(shell expr $(PLATFORM_VERSION) \< 6.0))) 46 | LOCAL_C_INCLUDES += \ 47 | external/stlport/stlport 48 | 49 | LOCAL_C_INCLUDES += bionic 50 | endif 51 | 52 | #ifeq ($(strip $(BOARD_USE_DRM)), true) 53 | #ifneq (1,$(strip $(shell expr $(PLATFORM_VERSION) \< 6.9))) 54 | LOCAL_CFLAGS += -DANDROID_7_DRM -DANDROID 55 | #endif 56 | #endif 57 | 58 | ifeq ($(strip $(TARGET_BOARD_PLATFORM)),rk3368) 59 | LOCAL_CFLAGS += -DRK3368 60 | endif 61 | 62 | ifneq (1,$(strip $(shell expr $(PLATFORM_VERSION) \< 8.0))) 63 | LOCAL_CFLAGS += -DANDROID_8 64 | endif 65 | 66 | ifeq ($(strip $(TARGET_BOARD_PLATFORM)),rk3188) 67 | LOCAL_CFLAGS += -DRK3188 68 | endif 69 | 70 | LOCAL_SRC_FILES:= \ 71 | rgaBlit.cpp 72 | 73 | LOCAL_MODULE:= rgaBlit 74 | 75 | ifdef TARGET_32_BIT_SURFACEFLINGER 76 | LOCAL_32_BIT_ONLY := true 77 | endif 78 | 79 | include $(BUILD_EXECUTABLE) 80 | 81 | -------------------------------------------------------------------------------- /samples/rgaClip/Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH:= $(call my-dir) 2 | #====================================================================== 3 | # 4 | #rgaClip 5 | # 6 | #====================================================================== 7 | include $(CLEAR_VARS) 8 | LOCAL_VENDOR_MODULE := true 9 | 10 | LOCAL_CFLAGS += -DGL_GLEXT_PROTOTYPES -DEGL_EGLEXT_PROTOTYPES 11 | 12 | LOCAL_CFLAGS += -DROCKCHIP_GPU_LIB_ENABLE 13 | 14 | LOCAL_CFLAGS += -Wall -Werror -Wunreachable-code 15 | 16 | LOCAL_C_INCLUDES += external/tinyalsa/include 17 | 18 | LOCAL_C_INCLUDES += hardware/rockchip/librga 19 | LOCAL_C_INCLUDES += hardware/rk29/librga \ 20 | system/core \ 21 | system/core/include/utils \ 22 | system/core/liblog/include \ 23 | $(LOCAL_PATH)/../.. \ 24 | $(LOCAL_PATH)/../../include 25 | 26 | LOCAL_SHARED_LIBRARIES := \ 27 | libcutils \ 28 | liblog \ 29 | libutils \ 30 | libui \ 31 | libEGL \ 32 | libGLESv1_CM \ 33 | libhardware \ 34 | librga 35 | 36 | LOCAL_HEADER_LIBRARIES += \ 37 | libutils_headers \ 38 | libcutils_headers \ 39 | libhardware_headers \ 40 | liblog_headers \ 41 | libgui_headers \ 42 | libbinder_headers 43 | 44 | #has no "external/stlport" from Android 6.0 on 45 | ifeq (1,$(strip $(shell expr $(PLATFORM_VERSION) \< 6.0))) 46 | LOCAL_C_INCLUDES += \ 47 | external/stlport/stlport 48 | 49 | LOCAL_C_INCLUDES += bionic 50 | endif 51 | 52 | #ifeq ($(strip $(BOARD_USE_DRM)), true) 53 | #ifneq (1,$(strip $(shell expr $(PLATFORM_VERSION) \< 6.9))) 54 | LOCAL_CFLAGS += -DANDROID_7_DRM -DANDROID 55 | #endif 56 | #endif 57 | 58 | ifeq ($(strip $(TARGET_BOARD_PLATFORM)),rk3368) 59 | LOCAL_CFLAGS += -DRK3368 60 | endif 61 | 62 | ifneq (1,$(strip $(shell expr $(PLATFORM_VERSION) \< 8.0))) 63 | LOCAL_CFLAGS += -DANDROID_8 64 | endif 65 | 66 | ifeq ($(strip $(TARGET_BOARD_PLATFORM)),rk3188) 67 | LOCAL_CFLAGS += -DRK3188 68 | endif 69 | 70 | LOCAL_SRC_FILES:= \ 71 | rgaClip.cpp 72 | 73 | LOCAL_MODULE:= rgaClip 74 | 75 | ifdef TARGET_32_BIT_SURFACEFLINGER 76 | LOCAL_32_BIT_ONLY := true 77 | endif 78 | 79 | include $(BUILD_EXECUTABLE) 80 | 81 | -------------------------------------------------------------------------------- /samples/rgaClip/rgaClip.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Rockchip Electronics Co., Ltd. 3 | * Authors: 4 | * Zhiqin Wei 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #define LOG_NDEBUG 0 20 | #define LOG_TAG "rgaClip" 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | #include 50 | #include 51 | #include 52 | #include 53 | 54 | #include 55 | #include 56 | #include 57 | #include 58 | 59 | #ifndef ANDROID_8 60 | #include 61 | #endif 62 | 63 | #include "RockchipRga.h" 64 | #include "RgaUtils.h" 65 | 66 | /////////////////////////////////////////////////////// 67 | 68 | using namespace android; 69 | 70 | int main() { 71 | int ret = 0; 72 | int srcWidth,srcHeight,srcFormat; 73 | int dstWidth,dstHeight,dstFormat; 74 | char* buf = NULL; 75 | 76 | srcWidth = 1280; 77 | srcHeight = 720; 78 | srcFormat = HAL_PIXEL_FORMAT_RGBA_8888; 79 | 80 | dstWidth = 360; 81 | dstHeight = 360; 82 | dstFormat = HAL_PIXEL_FORMAT_RGBA_8888; 83 | 84 | RockchipRga& rkRga(RockchipRga::get()); 85 | 86 | // GraphicBufferMapper &mgbMapper = GraphicBufferMapper::get(); 87 | 88 | /********** apply for src_buffer **********/ 89 | #ifdef ANDROID_7_DRM 90 | sp gbs(new GraphicBuffer(srcWidth,srcHeight,srcFormat, 91 | GRALLOC_USAGE_SW_WRITE_OFTEN | GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_HW_FB)); 92 | #else 93 | sp gbs(new GraphicBuffer(srcWidth,srcHeight,srcFormat, 94 | GRALLOC_USAGE_SW_WRITE_OFTEN | GRALLOC_USAGE_SW_READ_OFTEN)); 95 | #endif 96 | 97 | if (gbs->initCheck()) { 98 | printf("GraphicBuffer_src error : %s\n",strerror(errno)); 99 | return ret; 100 | } else 101 | printf("GraphicBuffer_src %s \n","ok"); 102 | 103 | /********** apply for dst_buffer **********/ 104 | #ifdef ANDROID_7_DRM 105 | sp gbd(new GraphicBuffer(dstWidth,dstHeight,dstFormat, 106 | GRALLOC_USAGE_SW_WRITE_OFTEN | GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_HW_FB)); 107 | #else 108 | sp gbd(new GraphicBuffer(dstWidth,dstHeight,dstFormat, 109 | GRALLOC_USAGE_SW_WRITE_OFTEN | GRALLOC_USAGE_SW_READ_OFTEN)); 110 | #endif 111 | 112 | if (gbd->initCheck()) { 113 | printf("GraphicBuffer_dst error : %s\n",strerror(errno)); 114 | return ret; 115 | } else 116 | printf("GraphicBuffer_dst %s \n","ok"); 117 | 118 | /********** map buffer_address to userspace **********/ 119 | /* 120 | #ifdef ANDROID_8 121 | buffer_handle_t importedHandle_src; 122 | buffer_handle_t importedHandle_dst; 123 | mgbMapper.importBuffer(gbs->handle, &importedHandle_src); 124 | mgbMapper.importBuffer(gbd->handle, &importedHandle_dst); 125 | gbs->handle = importedHandle_src; 126 | gbd->handle = importedHandle_dst; 127 | #else 128 | mgbMapper.registerBuffer(gbs->handle); 129 | mgbMapper.registerBuffer(gbd->handle); 130 | #endif 131 | */ 132 | /********** write data to src_buffer**********/ 133 | ret = gbs->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)&buf); 134 | 135 | if (ret) { 136 | printf("lock buffer_src error : %s\n",strerror(errno)); 137 | return ret; 138 | } else 139 | printf("lock buffer_src %s \n","ok"); 140 | 141 | 142 | get_buf_from_file(buf, srcFormat, srcWidth, srcHeight, 0); 143 | 144 | ret = gbs->unlock(); 145 | if (ret) { 146 | printf("unlock buffer_src error : %s\n",strerror(errno)); 147 | return ret; 148 | } else 149 | printf("unlock buffer_src %s \n","ok"); 150 | 151 | /********** write data to dst_buffer or init buffer **********/ 152 | ret = gbd->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)&buf); 153 | 154 | if (ret) { 155 | printf("lock buffer_dst error : %s\n",strerror(errno)); 156 | return ret; 157 | } else 158 | printf("lock buffer_dst %s \n","ok"); 159 | 160 | memset(buf,0x00,4*360*360); 161 | 162 | ret = gbd->unlock(); 163 | if (ret) { 164 | printf("unlock buffer_dst error : %s\n",strerror(errno)); 165 | return ret; 166 | } else 167 | printf("unlock buffer_dst %s \n","ok"); 168 | 169 | while(1) { 170 | /********** rga_info_t Init **********/ 171 | rga_info_t src; 172 | rga_info_t dst; 173 | 174 | memset(&src, 0, sizeof(rga_info_t)); 175 | src.fd = -1; 176 | src.mmuFlag = 1; 177 | src.hnd = gbs->handle; 178 | 179 | memset(&dst, 0, sizeof(rga_info_t)); 180 | dst.fd = -1; 181 | dst.mmuFlag = 1; 182 | dst.hnd = gbd->handle; 183 | 184 | /********** get src_Fd **********/ 185 | ret = rkRga.RkRgaGetBufferFd(gbs->handle, &src.fd); 186 | printf("src.fd =%d\n",src.fd); 187 | if (ret) { 188 | printf("rgaGetsrcFd fail : %s,hnd=%p \n", 189 | strerror(errno),(void*)(gbd->handle)); 190 | } 191 | /********** get dst_Fd **********/ 192 | ret = rkRga.RkRgaGetBufferFd(gbd->handle, &dst.fd); 193 | printf("dst.fd =%d \n",dst.fd); 194 | if (ret) { 195 | printf("rgaGetdstFd error : %s,hnd=%p\n", 196 | strerror(errno),(void*)(gbd->handle)); 197 | } 198 | /********** if not fd, try to check phyAddr and virAddr **************/ 199 | #ifndef RK3188 200 | if(src.fd <= 0|| dst.fd <= 0) 201 | #endif 202 | { 203 | /********** check phyAddr and virAddr ,if none to get virAddr **********/ 204 | if (( src.phyAddr != 0 || src.virAddr != 0 ) || src.hnd != NULL ) { 205 | ret = RkRgaGetHandleMapAddress( gbs->handle, &src.virAddr ); 206 | printf("src.virAddr =%p\n",src.virAddr); 207 | if(!src.virAddr) { 208 | printf("err! src has not fd and address for render ,Stop!\n"); 209 | break; 210 | } 211 | } 212 | 213 | /********** check phyAddr and virAddr ,if none to get virAddr **********/ 214 | if (( dst.phyAddr != 0 || dst.virAddr != 0 ) || dst.hnd != NULL ) { 215 | ret = RkRgaGetHandleMapAddress( gbd->handle, &dst.virAddr ); 216 | printf("dst.virAddr =%p\n",dst.virAddr); 217 | if(!dst.virAddr) { 218 | printf("err! dst has not fd and address for render ,Stop!\n"); 219 | break; 220 | } 221 | } 222 | } 223 | 224 | /********** set the rect_info **********/ 225 | rga_set_rect(&src.rect, 400,200,dstWidth,dstHeight,srcWidth/*stride*/,srcHeight,srcFormat); 226 | rga_set_rect(&dst.rect, 0,0,dstWidth,dstHeight,dstWidth/*stride*/,dstHeight,dstFormat); 227 | 228 | /************ set the rga_mod ,rotation\composition\scale\copy .... **********/ 229 | 230 | 231 | /********** call rga_Interface **********/ 232 | struct timeval tpend1, tpend2; 233 | long usec1 = 0; 234 | gettimeofday(&tpend1, NULL); 235 | 236 | ret = rkRga.RkRgaBlit(&src, &dst, NULL); 237 | if (ret) { 238 | printf("rgaFillColor error : %s,hnd=%p\n", 239 | strerror(errno),(void*)(gbd->handle)); 240 | } 241 | 242 | gettimeofday(&tpend2, NULL); 243 | usec1 = 1000 * (tpend2.tv_sec - tpend1.tv_sec) + (tpend2.tv_usec - tpend1.tv_usec) / 1000; 244 | printf("cost_time=%ld ms\n", usec1); 245 | 246 | 247 | { 248 | /********** output buf data to file **********/ 249 | char* dstbuf = NULL; 250 | ret = gbd->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)&dstbuf); 251 | //for(int i =0; i < mHeight * 1.5; i++) 252 | // memcpy(dstbuf + i * 2400,buf + i * 3000,2400); 253 | output_buf_data_to_file(dstbuf, dstFormat, dstWidth, dstHeight, 0); 254 | ret = gbd->unlock(); 255 | } 256 | printf("threadloop\n"); 257 | usleep(500000); 258 | break; 259 | } 260 | return 0; 261 | } 262 | -------------------------------------------------------------------------------- /samples/rgaColorFill/._rgaColorFill.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lihuang1111/linux-rga/cec3dbb1d490c034d55abf47e3d0a076888f7666/samples/rgaColorFill/._rgaColorFill.cpp -------------------------------------------------------------------------------- /samples/rgaColorFill/Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH:= $(call my-dir) 2 | #====================================================================== 3 | # 4 | #rgaColorFill 5 | # 6 | #====================================================================== 7 | include $(CLEAR_VARS) 8 | LOCAL_VENDOR_MODULE := true 9 | 10 | LOCAL_CFLAGS += -DGL_GLEXT_PROTOTYPES -DEGL_EGLEXT_PROTOTYPES 11 | 12 | LOCAL_CFLAGS += -DROCKCHIP_GPU_LIB_ENABLE 13 | 14 | LOCAL_CFLAGS += -Wall -Werror -Wunreachable-code 15 | 16 | LOCAL_C_INCLUDES += external/tinyalsa/include 17 | 18 | LOCAL_C_INCLUDES += hardware/rockchip/librga 19 | LOCAL_C_INCLUDES += hardware/rk29/librga \ 20 | system/core \ 21 | system/core/include/utils \ 22 | system/core/liblog/include \ 23 | $(LOCAL_PATH)/../.. \ 24 | $(LOCAL_PATH)/../../include 25 | 26 | LOCAL_SHARED_LIBRARIES := \ 27 | libcutils \ 28 | liblog \ 29 | libutils \ 30 | libui \ 31 | libEGL \ 32 | libGLESv1_CM \ 33 | libhardware \ 34 | librga 35 | 36 | LOCAL_HEADER_LIBRARIES += \ 37 | libutils_headers \ 38 | libcutils_headers \ 39 | libhardware_headers \ 40 | liblog_headers \ 41 | libgui_headers \ 42 | libbinder_headers 43 | 44 | #has no "external/stlport" from Android 6.0 on 45 | ifeq (1,$(strip $(shell expr $(PLATFORM_VERSION) \< 6.0))) 46 | LOCAL_C_INCLUDES += \ 47 | external/stlport/stlport 48 | 49 | LOCAL_C_INCLUDES += bionic 50 | endif 51 | 52 | #ifeq ($(strip $(BOARD_USE_DRM)), true) 53 | #ifneq (1,$(strip $(shell expr $(PLATFORM_VERSION) \< 6.9))) 54 | LOCAL_CFLAGS += -DANDROID_7_DRM -DANDROID 55 | #endif 56 | #endif 57 | 58 | ifeq ($(strip $(TARGET_BOARD_PLATFORM)),rk3368) 59 | LOCAL_CFLAGS += -DRK3368 60 | endif 61 | 62 | ifneq (1,$(strip $(shell expr $(PLATFORM_VERSION) \< 8.0))) 63 | LOCAL_CFLAGS += -DANDROID_8 64 | endif 65 | 66 | ifeq ($(strip $(TARGET_BOARD_PLATFORM)),rk3188) 67 | LOCAL_CFLAGS += -DRK3188 68 | endif 69 | 70 | LOCAL_SRC_FILES:= \ 71 | rgaColorFill.cpp 72 | 73 | LOCAL_MODULE:= rgaColorFill 74 | 75 | ifdef TARGET_32_BIT_SURFACEFLINGER 76 | LOCAL_32_BIT_ONLY := true 77 | endif 78 | 79 | include $(BUILD_EXECUTABLE) 80 | 81 | -------------------------------------------------------------------------------- /samples/rgaColorFill/rgaColorFill.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Rockchip Electronics Co., Ltd. 3 | * Authors: 4 | * Zhiqin Wei 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #define LOG_NDEBUG 0 20 | #define LOG_TAG "rgaBlit" 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | #include 50 | #include 51 | #include 52 | #include 53 | 54 | #include 55 | #include 56 | #include 57 | #include 58 | 59 | #ifndef ANDROID_8 60 | #include 61 | #endif 62 | 63 | #include "RockchipRga.h" 64 | #include "RgaUtils.h" 65 | 66 | /////////////////////////////////////////////////////// 67 | 68 | using namespace android; 69 | 70 | int main() { 71 | int ret = 0; 72 | int dstWidth,dstHeight,dstFormat; 73 | char* buf = NULL; 74 | 75 | 76 | dstWidth = 1280; 77 | dstHeight = 720; 78 | dstFormat = HAL_PIXEL_FORMAT_RGBA_8888; 79 | 80 | /********** instantiation RockchipRga **********/ 81 | RockchipRga& rkRga(RockchipRga::get()); 82 | 83 | /********** instantiation GraphicBufferMapper **********/ 84 | // GraphicBufferMapper &mgbMapper = GraphicBufferMapper::get(); 85 | 86 | /********** apply for dst_buffer **********/ 87 | #ifdef ANDROID_7_DRM 88 | sp gbd(new GraphicBuffer(dstWidth,dstHeight,dstFormat, 89 | GRALLOC_USAGE_SW_WRITE_OFTEN | GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_HW_FB)); 90 | #else 91 | sp gbd(new GraphicBuffer(dstWidth,dstHeight,dstFormat, 92 | GRALLOC_USAGE_SW_WRITE_OFTEN | GRALLOC_USAGE_SW_READ_OFTEN)); 93 | #endif 94 | 95 | if (gbd->initCheck()) { 96 | printf("GraphicBuffer_dst error : %s\n",strerror(errno)); 97 | return ret; 98 | } else 99 | printf("GraphicBuffer_dst %s \n","ok"); 100 | 101 | /********** map buffer_address to userspace **********/ 102 | /* 103 | #ifdef ANDROID_8 104 | buffer_handle_t importedHandle_dst; 105 | mgbMapper.importBuffer(gbd->handle, &importedHandle_dst); 106 | gbd->handle = importedHandle_dst; 107 | #else 108 | mgbMapper.registerBuffer(gbd->handle); 109 | #endif 110 | */ 111 | /********** write data to src_buffer or init buffer**********/ 112 | ret = gbd->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)&buf); 113 | if (ret) { 114 | printf("lock buffer_dst error : %s\n",strerror(errno)); 115 | return ret; 116 | } else 117 | printf("lock buffer_dst %s \n","ok"); 118 | 119 | 120 | memset(buf,0x00,4*1280*720); 121 | 122 | 123 | ret = gbd->unlock(); 124 | if (ret) { 125 | printf("unlock buffer_dst error : %s\n",strerror(errno)); 126 | return ret; 127 | } else 128 | printf("unlock buffer_dst %s \n","ok"); 129 | 130 | while(1) { 131 | /********** rga_info_t Init **********/ 132 | rga_info_t dst; 133 | 134 | 135 | memset(&dst, 0, sizeof(rga_info_t)); 136 | dst.fd = -1; 137 | dst.mmuFlag = 1; 138 | dst.hnd = gbd->handle; 139 | 140 | /********** get dst_Fd **********/ 141 | ret = rkRga.RkRgaGetBufferFd(gbd->handle, &dst.fd); 142 | printf("dst.fd =%d \n",dst.fd); 143 | if (ret) { 144 | printf("rgaGetdstFd error : %s,hnd=%p\n", 145 | strerror(errno),(void*)(gbd->handle)); 146 | } 147 | /********** fd is valid ? **************/ 148 | #ifndef RK3188 149 | if(dst.fd <= 0) 150 | #endif 151 | { 152 | /********** check phyAddr and virAddr ,if none to get virAddr **********/ 153 | if (( dst.phyAddr != 0 || dst.virAddr != 0 ) || dst.hnd != NULL ) { 154 | ret = RkRgaGetHandleMapAddress( gbd->handle, &dst.virAddr ); 155 | printf("dst.virAddr =%p\n",dst.virAddr); 156 | if(!dst.virAddr) { 157 | printf("err! dst has not fd and address for render ,Stop!\n"); 158 | break; 159 | } 160 | } 161 | } 162 | /********** set the rect_info **********/ 163 | rga_set_rect(&dst.rect, 0,0,dstWidth,dstHeight,dstWidth/*stride*/,dstHeight,dstFormat); 164 | 165 | /************ set the rga_mod **********/ 166 | dst.color = 0xffff0000; 167 | //dst.color = 0xff00ff00; 168 | //dst.color = 0xff0000ff; 169 | 170 | /********** call rga_Interface **********/ 171 | struct timeval tpend1, tpend2; 172 | long usec1 = 0; 173 | gettimeofday(&tpend1, NULL); 174 | 175 | ret = rkRga.RkRgaCollorFill(&dst); 176 | if (ret) { 177 | printf("rgaFillColor error : %s,hnd=%p\n", 178 | strerror(errno),(void*)(gbd->handle)); 179 | } 180 | 181 | gettimeofday(&tpend2, NULL); 182 | usec1 = 1000 * (tpend2.tv_sec - tpend1.tv_sec) + (tpend2.tv_usec - tpend1.tv_usec) / 1000; 183 | printf("cost_time=%ld ms\n", usec1); 184 | 185 | 186 | { 187 | /********** output buf data to file **********/ 188 | char* dstbuf = NULL; 189 | ret = gbd->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)&dstbuf); 190 | //for(int i =0; i < mHeight * 1.5; i++) 191 | // memcpy(dstbuf + i * 2400,buf + i * 3000,2400); 192 | output_buf_data_to_file(dstbuf, dstFormat, dstWidth, dstHeight, 0); 193 | ret = gbd->unlock(); 194 | } 195 | printf("threadloop\n"); 196 | usleep(500000); 197 | break; 198 | } 199 | return 0; 200 | } 201 | -------------------------------------------------------------------------------- /samples/rgaColorPalette/Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH:= $(call my-dir) 2 | #====================================================================== 3 | # 4 | #rgaBlit 5 | # 6 | #====================================================================== 7 | include $(CLEAR_VARS) 8 | LOCAL_VENDOR_MODULE := true 9 | 10 | LOCAL_CFLAGS += -DGL_GLEXT_PROTOTYPES -DEGL_EGLEXT_PROTOTYPES 11 | 12 | LOCAL_CFLAGS += -DROCKCHIP_GPU_LIB_ENABLE 13 | 14 | LOCAL_CFLAGS += -Wall -Werror -Wunreachable-code 15 | 16 | LOCAL_C_INCLUDES += external/tinyalsa/include 17 | 18 | LOCAL_C_INCLUDES += hardware/rockchip/librga 19 | LOCAL_C_INCLUDES += hardware/rk29/librga \ 20 | system/core \ 21 | system/core/include/utils \ 22 | system/core/liblog/include \ 23 | $(LOCAL_PATH)/../.. \ 24 | $(LOCAL_PATH)/../../include 25 | 26 | LOCAL_SHARED_LIBRARIES := \ 27 | libcutils \ 28 | liblog \ 29 | libutils \ 30 | libui \ 31 | libEGL \ 32 | libGLESv1_CM \ 33 | libhardware \ 34 | librga 35 | 36 | LOCAL_HEADER_LIBRARIES += \ 37 | libutils_headers \ 38 | libcutils_headers \ 39 | libhardware_headers \ 40 | liblog_headers \ 41 | libgui_headers \ 42 | libbinder_headers 43 | 44 | #has no "external/stlport" from Android 6.0 on 45 | ifeq (1,$(strip $(shell expr $(PLATFORM_VERSION) \< 6.0))) 46 | LOCAL_C_INCLUDES += \ 47 | external/stlport/stlport 48 | 49 | LOCAL_C_INCLUDES += bionic 50 | endif 51 | 52 | #ifeq ($(strip $(BOARD_USE_DRM)), true) 53 | #ifneq (1,$(strip $(shell expr $(PLATFORM_VERSION) \< 6.9))) 54 | LOCAL_CFLAGS += -DANDROID_7_DRM -DANDROID 55 | #endif 56 | #endif 57 | 58 | ifeq ($(strip $(TARGET_BOARD_PLATFORM)),rk3368) 59 | LOCAL_CFLAGS += -DRK3368 60 | endif 61 | 62 | ifneq (1,$(strip $(shell expr $(PLATFORM_VERSION) \< 8.0))) 63 | LOCAL_CFLAGS += -DANDROID_8 64 | endif 65 | 66 | ifeq ($(strip $(TARGET_BOARD_PLATFORM)),rk3188) 67 | LOCAL_CFLAGS += -DRK3188 68 | endif 69 | 70 | LOCAL_SRC_FILES:= \ 71 | rgaColorPalette.cpp 72 | 73 | LOCAL_MODULE:= rgaColorPalette 74 | 75 | ifdef TARGET_32_BIT_SURFACEFLINGER 76 | LOCAL_32_BIT_ONLY := true 77 | endif 78 | 79 | include $(BUILD_EXECUTABLE) 80 | 81 | -------------------------------------------------------------------------------- /samples/rgaCopy565ToRgba/Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH:= $(call my-dir) 2 | #====================================================================== 3 | # 4 | #rgaCopy565ToRgba 5 | # 6 | #====================================================================== 7 | include $(CLEAR_VARS) 8 | LOCAL_VENDOR_MODULE := true 9 | 10 | LOCAL_CFLAGS += -DGL_GLEXT_PROTOTYPES -DEGL_EGLEXT_PROTOTYPES 11 | 12 | LOCAL_CFLAGS += -DROCKCHIP_GPU_LIB_ENABLE 13 | 14 | LOCAL_CFLAGS += -Wall -Werror -Wunreachable-code 15 | 16 | LOCAL_C_INCLUDES += external/tinyalsa/include 17 | 18 | LOCAL_C_INCLUDES += hardware/rockchip/librga 19 | LOCAL_C_INCLUDES += hardware/rk29/librga \ 20 | system/core \ 21 | system/core/include/utils \ 22 | system/core/liblog/include \ 23 | $(LOCAL_PATH)/../.. \ 24 | $(LOCAL_PATH)/../../include 25 | 26 | LOCAL_SHARED_LIBRARIES := \ 27 | libcutils \ 28 | liblog \ 29 | libutils \ 30 | libui \ 31 | libEGL \ 32 | libGLESv1_CM \ 33 | libhardware \ 34 | librga 35 | 36 | LOCAL_HEADER_LIBRARIES += \ 37 | libutils_headers \ 38 | libcutils_headers \ 39 | libhardware_headers \ 40 | liblog_headers \ 41 | libgui_headers \ 42 | libbinder_headers 43 | 44 | #has no "external/stlport" from Android 6.0 on 45 | ifeq (1,$(strip $(shell expr $(PLATFORM_VERSION) \< 6.0))) 46 | LOCAL_C_INCLUDES += \ 47 | external/stlport/stlport 48 | 49 | LOCAL_C_INCLUDES += bionic 50 | endif 51 | 52 | #ifeq ($(strip $(BOARD_USE_DRM)), true) 53 | #ifneq (1,$(strip $(shell expr $(PLATFORM_VERSION) \< 6.9))) 54 | LOCAL_CFLAGS += -DANDROID_7_DRM -DANDROID 55 | #endif 56 | #endif 57 | 58 | ifeq ($(strip $(TARGET_BOARD_PLATFORM)),rk3368) 59 | LOCAL_CFLAGS += -DRK3368 60 | endif 61 | 62 | ifneq (1,$(strip $(shell expr $(PLATFORM_VERSION) \< 8.0))) 63 | LOCAL_CFLAGS += -DANDROID_8 64 | endif 65 | 66 | ifeq ($(strip $(TARGET_BOARD_PLATFORM)),rk3188) 67 | LOCAL_CFLAGS += -DRK3188 68 | endif 69 | 70 | LOCAL_SRC_FILES:= \ 71 | rgaCopy565ToRgba.cpp 72 | 73 | LOCAL_MODULE:= rgaCopy565ToRgba 74 | 75 | ifdef TARGET_32_BIT_SURFACEFLINGER 76 | LOCAL_32_BIT_ONLY := true 77 | endif 78 | 79 | include $(BUILD_EXECUTABLE) 80 | 81 | -------------------------------------------------------------------------------- /samples/rgaCopy565ToRgba/rgaCopy565ToRgba.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Rockchip Electronics Co., Ltd. 3 | * Authors: 4 | * Zhiqin Wei 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #define LOG_NDEBUG 0 20 | #define LOG_TAG "rgaCopy565ToRgba" 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | #include 50 | #include 51 | #include 52 | #include 53 | 54 | #include 55 | #include 56 | #include 57 | #include 58 | 59 | #ifndef ANDROID_8 60 | #include 61 | #endif 62 | 63 | #include "RockchipRga.h" 64 | #include "RgaUtils.h" 65 | 66 | /////////////////////////////////////////////////////// 67 | 68 | using namespace android; 69 | 70 | int main() { 71 | int ret = 0; 72 | int srcWidth,srcHeight,srcFormat; 73 | int dstWidth,dstHeight,dstFormat; 74 | char* buf = NULL; 75 | 76 | /********** SrcInfo set **********/ 77 | srcWidth = 1088; 78 | srcHeight = 800; 79 | srcFormat = HAL_PIXEL_FORMAT_RGB_565; 80 | 81 | /********** DstInfo set **********/ 82 | dstWidth = 1088; 83 | dstHeight = 800; 84 | dstFormat = HAL_PIXEL_FORMAT_RGBA_8888; 85 | 86 | RockchipRga& rkRga(RockchipRga::get()); 87 | 88 | // GraphicBufferMapper &mgbMapper = GraphicBufferMapper::get(); 89 | 90 | /********** apply for src_buffer **********/ 91 | #ifdef ANDROID_7_DRM 92 | sp gbs(new GraphicBuffer(srcWidth,srcHeight,srcFormat, 93 | GRALLOC_USAGE_SW_WRITE_OFTEN | GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_HW_FB)); 94 | #else 95 | sp gbs(new GraphicBuffer(srcWidth,srcHeight,srcFormat, 96 | GRALLOC_USAGE_SW_WRITE_OFTEN | GRALLOC_USAGE_SW_READ_OFTEN)); 97 | #endif 98 | 99 | if (gbs->initCheck()) { 100 | printf("GraphicBuffer_src error : %s\n",strerror(errno)); 101 | return ret; 102 | } else 103 | printf("GraphicBuffer_src %s \n","ok"); 104 | 105 | /********** apply for dst_buffer **********/ 106 | #ifdef ANDROID_7_DRM 107 | sp gbd(new GraphicBuffer(dstWidth,dstHeight,dstFormat, 108 | GRALLOC_USAGE_SW_WRITE_OFTEN | GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_HW_FB)); 109 | #else 110 | sp gbd(new GraphicBuffer(dstWidth,dstHeight,dstFormat, 111 | GRALLOC_USAGE_SW_WRITE_OFTEN | GRALLOC_USAGE_SW_READ_OFTEN)); 112 | #endif 113 | 114 | if (gbd->initCheck()) { 115 | printf("GraphicBuffer_dst error : %s\n",strerror(errno)); 116 | return ret; 117 | } else 118 | printf("GraphicBuffer_dst %s \n","ok"); 119 | 120 | /********** map buffer_address to userspace **********/ 121 | /* 122 | #ifdef ANDROID_8 123 | buffer_handle_t importedHandle_src; 124 | buffer_handle_t importedHandle_dst; 125 | mgbMapper.importBuffer(gbs->handle, &importedHandle_src); 126 | mgbMapper.importBuffer(gbd->handle, &importedHandle_dst); 127 | gbs->handle = importedHandle_src; 128 | gbd->handle = importedHandle_dst; 129 | #else 130 | mgbMapper.registerBuffer(gbs->handle); 131 | mgbMapper.registerBuffer(gbd->handle); 132 | #endif 133 | */ 134 | /********** write data to src_buffer or init buffer**********/ 135 | ret = gbs->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)&buf); 136 | 137 | if (ret) { 138 | printf("lock buffer_src error : %s\n",strerror(errno)); 139 | return ret; 140 | } else 141 | printf("lock buffer_src %s \n","ok"); 142 | 143 | 144 | get_buf_from_file(buf, srcFormat, srcWidth, srcHeight, 0); 145 | 146 | 147 | ret = gbs->unlock(); 148 | if (ret) { 149 | printf("unlock buffer_src error : %s\n",strerror(errno)); 150 | return ret; 151 | } else 152 | printf("unlock buffer_src %s \n","ok"); 153 | 154 | /********** write data to dst_buffer or init buffer **********/ 155 | ret = gbd->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)&buf); 156 | if (ret) { 157 | printf("lock buffer_dst error : %s\n",strerror(errno)); 158 | return ret; 159 | } else 160 | printf("lock buffer_dst %s \n","ok"); 161 | 162 | memset(buf,0x00,2*1088*800); 163 | 164 | ret = gbd->unlock(); 165 | if (ret) { 166 | printf("unlock buffer_dst error : %s\n",strerror(errno)); 167 | return ret; 168 | } else 169 | printf("unlock buffer_dst %s \n","ok"); 170 | 171 | while(1) { 172 | /********** rga_info_t Init **********/ 173 | rga_info_t src; 174 | rga_info_t dst; 175 | 176 | memset(&src, 0, sizeof(rga_info_t)); 177 | src.fd = -1; 178 | src.mmuFlag = 1; 179 | src.hnd = gbs->handle; 180 | 181 | memset(&dst, 0, sizeof(rga_info_t)); 182 | dst.fd = -1; 183 | dst.mmuFlag = 1; 184 | dst.hnd = gbd->handle; 185 | 186 | /********** get src_Fd **********/ 187 | ret = rkRga.RkRgaGetBufferFd(gbs->handle, &src.fd); 188 | printf("src.fd =%d\n",src.fd); 189 | if (ret) { 190 | printf("rgaGetsrcFd fail : %s,hnd=%p \n", 191 | strerror(errno),(void*)(gbd->handle)); 192 | } 193 | /********** get dst_Fd **********/ 194 | ret = rkRga.RkRgaGetBufferFd(gbd->handle, &dst.fd); 195 | printf("dst.fd =%d \n",dst.fd); 196 | if (ret) { 197 | printf("rgaGetdstFd error : %s,hnd=%p\n", 198 | strerror(errno),(void*)(gbd->handle)); 199 | } 200 | /********** if not fd, try to check phyAddr and virAddr **************/ 201 | #ifndef RK3188 202 | if(src.fd <= 0|| dst.fd <= 0) 203 | #endif 204 | { 205 | /********** check phyAddr and virAddr ,if none to get virAddr **********/ 206 | if (( src.phyAddr != 0 || src.virAddr != 0 ) || src.hnd != NULL ) { 207 | ret = RkRgaGetHandleMapAddress( gbs->handle, &src.virAddr ); 208 | printf("src.virAddr =%p\n",src.virAddr); 209 | if(!src.virAddr) { 210 | printf("err! src has not fd and address for render ,Stop!\n"); 211 | break; 212 | } 213 | } 214 | 215 | /********** check phyAddr and virAddr ,if none to get virAddr **********/ 216 | if (( dst.phyAddr != 0 || dst.virAddr != 0 ) || dst.hnd != NULL ) { 217 | ret = RkRgaGetHandleMapAddress( gbd->handle, &dst.virAddr ); 218 | printf("dst.virAddr =%p\n",dst.virAddr); 219 | if(!dst.virAddr) { 220 | printf("err! dst has not fd and address for render ,Stop!\n"); 221 | break; 222 | } 223 | } 224 | } 225 | /********** set the rect_info **********/ 226 | rga_set_rect(&src.rect, 0,0,srcWidth,srcHeight,srcWidth/*stride*/,srcHeight,srcFormat); 227 | rga_set_rect(&dst.rect, 0,0,dstWidth,dstHeight,dstWidth/*stride*/,dstHeight,dstFormat); 228 | 229 | /************ set the rga_mod ,rotation\composition\scale\copy .... **********/ 230 | 231 | 232 | /********** call rga_Interface **********/ 233 | struct timeval tpend1, tpend2; 234 | long usec1 = 0; 235 | gettimeofday(&tpend1, NULL); 236 | 237 | ret = rkRga.RkRgaBlit(&src, &dst, NULL); 238 | 239 | gettimeofday(&tpend2, NULL); 240 | usec1 = 1000 * (tpend2.tv_sec - tpend1.tv_sec) + (tpend2.tv_usec - tpend1.tv_usec) / 1000; 241 | printf("cost_time=%ld ms\n", usec1); 242 | if (ret) { 243 | printf("rgaFillColor error : %s,hnd=%p\n", 244 | strerror(errno),(void*)(gbd->handle)); 245 | } 246 | 247 | { 248 | /********** output buf data to file **********/ 249 | char* dstbuf = NULL; 250 | ret = gbd->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)&dstbuf); 251 | output_buf_data_to_file(dstbuf, dstFormat, dstWidth, dstHeight, 0); 252 | ret = gbd->unlock(); 253 | } 254 | printf("threadloop\n"); 255 | usleep(500000); 256 | break; 257 | } 258 | return 0; 259 | } 260 | -------------------------------------------------------------------------------- /samples/rgaCopy565ToYuv/Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH:= $(call my-dir) 2 | #====================================================================== 3 | # 4 | #rgaCopy565ToYuv 5 | # 6 | #====================================================================== 7 | include $(CLEAR_VARS) 8 | LOCAL_VENDOR_MODULE := true 9 | 10 | LOCAL_CFLAGS += -DGL_GLEXT_PROTOTYPES -DEGL_EGLEXT_PROTOTYPES 11 | 12 | LOCAL_CFLAGS += -DROCKCHIP_GPU_LIB_ENABLE 13 | 14 | LOCAL_CFLAGS += -Wall -Werror -Wunreachable-code 15 | 16 | LOCAL_C_INCLUDES += external/tinyalsa/include 17 | 18 | LOCAL_C_INCLUDES += hardware/rockchip/librga 19 | LOCAL_C_INCLUDES += hardware/rk29/librga \ 20 | system/core \ 21 | system/core/include/utils \ 22 | system/core/liblog/include \ 23 | $(LOCAL_PATH)/../.. \ 24 | $(LOCAL_PATH)/../../include 25 | 26 | LOCAL_SHARED_LIBRARIES := \ 27 | libcutils \ 28 | liblog \ 29 | libutils \ 30 | libui \ 31 | libEGL \ 32 | libGLESv1_CM \ 33 | libhardware \ 34 | librga 35 | 36 | LOCAL_HEADER_LIBRARIES += \ 37 | libutils_headers \ 38 | libcutils_headers \ 39 | libhardware_headers \ 40 | liblog_headers \ 41 | libgui_headers \ 42 | libbinder_headers 43 | 44 | #has no "external/stlport" from Android 6.0 on 45 | ifeq (1,$(strip $(shell expr $(PLATFORM_VERSION) \< 6.0))) 46 | LOCAL_C_INCLUDES += \ 47 | external/stlport/stlport 48 | 49 | LOCAL_C_INCLUDES += bionic 50 | endif 51 | 52 | #ifeq ($(strip $(BOARD_USE_DRM)), true) 53 | #ifneq (1,$(strip $(shell expr $(PLATFORM_VERSION) \< 6.9))) 54 | LOCAL_CFLAGS += -DANDROID_7_DRM -DANDROID 55 | #endif 56 | #endif 57 | 58 | ifeq ($(strip $(TARGET_BOARD_PLATFORM)),rk3368) 59 | LOCAL_CFLAGS += -DRK3368 60 | endif 61 | 62 | ifneq (1,$(strip $(shell expr $(PLATFORM_VERSION) \< 8.0))) 63 | LOCAL_CFLAGS += -DANDROID_8 64 | endif 65 | 66 | ifeq ($(strip $(TARGET_BOARD_PLATFORM)),rk3188) 67 | LOCAL_CFLAGS += -DRK3188 68 | endif 69 | 70 | LOCAL_SRC_FILES:= \ 71 | rgaCopy565ToYuv.cpp 72 | 73 | LOCAL_MODULE:= rgaCopy565ToYuv 74 | 75 | ifdef TARGET_32_BIT_SURFACEFLINGER 76 | LOCAL_32_BIT_ONLY := true 77 | endif 78 | 79 | include $(BUILD_EXECUTABLE) 80 | 81 | -------------------------------------------------------------------------------- /samples/rgaCopy565ToYuv/rgaCopy565ToYuv.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Rockchip Electronics Co., Ltd. 3 | * Authors: 4 | * Zhiqin Wei 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #define LOG_NDEBUG 0 20 | #define LOG_TAG "rgaCopy565ToYuv" 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | #include 50 | #include 51 | #include 52 | #include 53 | 54 | #include 55 | #include 56 | #include 57 | #include 58 | 59 | #ifndef ANDROID_8 60 | #include 61 | #endif 62 | 63 | #include "RockchipRga.h" 64 | #include "RgaUtils.h" 65 | 66 | /////////////////////////////////////////////////////// 67 | 68 | using namespace android; 69 | 70 | int main() { 71 | int ret = 0; 72 | int srcWidth,srcHeight,srcFormat; 73 | int dstWidth,dstHeight,dstFormat; 74 | char* buf = NULL; 75 | 76 | /********** SrcInfo set **********/ 77 | srcWidth = 1088; 78 | srcHeight = 800; 79 | srcFormat = HAL_PIXEL_FORMAT_RGB_565; 80 | 81 | /********** DstInfo set **********/ 82 | dstWidth = 1088; 83 | dstHeight = 800; 84 | dstFormat = HAL_PIXEL_FORMAT_YCrCb_NV12; 85 | 86 | RockchipRga& rkRga(RockchipRga::get()); 87 | 88 | // GraphicBufferMapper &mgbMapper = GraphicBufferMapper::get(); 89 | 90 | /********** apply for src_buffer **********/ 91 | #ifdef ANDROID_7_DRM 92 | sp gbs(new GraphicBuffer(srcWidth,srcHeight,srcFormat, 93 | GRALLOC_USAGE_SW_WRITE_OFTEN | GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_HW_FB)); 94 | #else 95 | sp gbs(new GraphicBuffer(srcWidth,srcHeight,srcFormat, 96 | GRALLOC_USAGE_SW_WRITE_OFTEN | GRALLOC_USAGE_SW_READ_OFTEN)); 97 | #endif 98 | 99 | if (gbs->initCheck()) { 100 | printf("GraphicBuffer_src error : %s\n",strerror(errno)); 101 | return ret; 102 | } else 103 | printf("GraphicBuffer_src %s \n","ok"); 104 | 105 | /********** apply for dst_buffer **********/ 106 | #ifdef ANDROID_7_DRM 107 | sp gbd(new GraphicBuffer(dstWidth,dstHeight,dstFormat, 108 | GRALLOC_USAGE_SW_WRITE_OFTEN | GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_HW_FB)); 109 | #else 110 | sp gbd(new GraphicBuffer(dstWidth,dstHeight,dstFormat, 111 | GRALLOC_USAGE_SW_WRITE_OFTEN | GRALLOC_USAGE_SW_READ_OFTEN)); 112 | #endif 113 | 114 | if (gbd->initCheck()) { 115 | printf("GraphicBuffer_dst error : %s\n",strerror(errno)); 116 | return ret; 117 | } else 118 | printf("GraphicBuffer_dst %s \n","ok"); 119 | 120 | /********** map buffer_address to userspace **********/ 121 | /* 122 | #ifdef ANDROID_8 123 | buffer_handle_t importedHandle_src; 124 | buffer_handle_t importedHandle_dst; 125 | mgbMapper.importBuffer(gbs->handle, &importedHandle_src); 126 | mgbMapper.importBuffer(gbd->handle, &importedHandle_dst); 127 | gbs->handle = importedHandle_src; 128 | gbd->handle = importedHandle_dst; 129 | #else 130 | mgbMapper.registerBuffer(gbs->handle); 131 | mgbMapper.registerBuffer(gbd->handle); 132 | #endif 133 | */ 134 | /********** write data to src_buffer or init buffer**********/ 135 | ret = gbs->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)&buf); 136 | 137 | if (ret) { 138 | printf("lock buffer_src error : %s\n",strerror(errno)); 139 | return ret; 140 | } else 141 | printf("lock buffer_src %s \n","ok"); 142 | 143 | 144 | get_buf_from_file(buf, srcFormat, srcWidth, srcHeight, 0); 145 | 146 | 147 | ret = gbs->unlock(); 148 | if (ret) { 149 | printf("unlock buffer_src error : %s\n",strerror(errno)); 150 | return ret; 151 | } else 152 | printf("unlock buffer_src %s \n","ok"); 153 | 154 | /********** write data to dst_buffer or init buffer **********/ 155 | ret = gbd->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)&buf); 156 | if (ret) { 157 | printf("lock buffer_dst error : %s\n",strerror(errno)); 158 | return ret; 159 | } else 160 | printf("lock buffer_dst %s \n","ok"); 161 | 162 | memset(buf,0x00,2*1088*800); 163 | 164 | ret = gbd->unlock(); 165 | if (ret) { 166 | printf("unlock buffer_dst error : %s\n",strerror(errno)); 167 | return ret; 168 | } else 169 | printf("unlock buffer_dst %s \n","ok"); 170 | 171 | while(1) { 172 | /********** rga_info_t Init **********/ 173 | rga_info_t src; 174 | rga_info_t dst; 175 | 176 | memset(&src, 0, sizeof(rga_info_t)); 177 | src.fd = -1; 178 | src.mmuFlag = 1; 179 | src.hnd = gbs->handle; 180 | 181 | memset(&dst, 0, sizeof(rga_info_t)); 182 | dst.fd = -1; 183 | dst.mmuFlag = 1; 184 | dst.hnd = gbd->handle; 185 | 186 | /********** get src_Fd **********/ 187 | ret = rkRga.RkRgaGetBufferFd(gbs->handle, &src.fd); 188 | printf("src.fd =%d\n",src.fd); 189 | if (ret) { 190 | printf("rgaGetsrcFd fail : %s,hnd=%p \n", 191 | strerror(errno),(void*)(gbd->handle)); 192 | } 193 | 194 | /********** get dst_Fd **********/ 195 | ret = rkRga.RkRgaGetBufferFd(gbd->handle, &dst.fd); 196 | printf("dst.fd =%d \n",dst.fd); 197 | if (ret) { 198 | printf("rgaGetdstFd error : %s,hnd=%p\n", 199 | strerror(errno),(void*)(gbd->handle)); 200 | } 201 | /********** if not fd, try to check phyAddr and virAddr **************/ 202 | #ifndef RK3188 203 | if(src.fd <= 0|| dst.fd <= 0) 204 | #endif 205 | { 206 | /********** check phyAddr and virAddr ,if none to get virAddr **********/ 207 | if (( src.phyAddr != 0 || src.virAddr != 0 ) || src.hnd != NULL ) { 208 | ret = RkRgaGetHandleMapAddress( gbs->handle, &src.virAddr ); 209 | printf("src.virAddr =%p\n",src.virAddr); 210 | if(!src.virAddr) { 211 | printf("err! src has not fd and address for render ,Stop!\n"); 212 | break; 213 | } 214 | } 215 | 216 | /********** check phyAddr and virAddr ,if none to get virAddr **********/ 217 | if (( dst.phyAddr != 0 || dst.virAddr != 0 ) || dst.hnd != NULL ) { 218 | ret = RkRgaGetHandleMapAddress( gbd->handle, &dst.virAddr ); 219 | printf("dst.virAddr =%p\n",dst.virAddr); 220 | if(!dst.virAddr) { 221 | printf("err! dst has not fd and address for render ,Stop!\n"); 222 | break; 223 | } 224 | } 225 | } 226 | /********** set the rect_info **********/ 227 | rga_set_rect(&src.rect, 0,0,srcWidth,srcHeight,srcWidth/*stride*/,srcHeight,srcFormat); 228 | rga_set_rect(&dst.rect, 0,0,dstWidth,dstHeight,dstWidth/*stride*/,dstHeight,dstFormat); 229 | 230 | /************ set the rga_mod ,rotation\composition\scale\copy .... **********/ 231 | 232 | 233 | /********** call rga_Interface **********/ 234 | struct timeval tpend1, tpend2; 235 | long usec1 = 0; 236 | gettimeofday(&tpend1, NULL); 237 | 238 | ret = rkRga.RkRgaBlit(&src, &dst, NULL); 239 | 240 | gettimeofday(&tpend2, NULL); 241 | usec1 = 1000 * (tpend2.tv_sec - tpend1.tv_sec) + (tpend2.tv_usec - tpend1.tv_usec) / 1000; 242 | printf("cost_time=%ld ms\n", usec1); 243 | if (ret) { 244 | printf("rgaFillColor error : %s,hnd=%p\n", 245 | strerror(errno),(void*)(gbd->handle)); 246 | } 247 | 248 | { 249 | /********** output buf data to file **********/ 250 | char* dstbuf = NULL; 251 | ret = gbd->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)&dstbuf); 252 | output_buf_data_to_file(dstbuf, dstFormat, dstWidth, dstHeight, 0); 253 | ret = gbd->unlock(); 254 | } 255 | printf("threadloop\n"); 256 | usleep(500000); 257 | break; 258 | } 259 | return 0; 260 | } 261 | -------------------------------------------------------------------------------- /samples/rgaCopyRgbaTo565/Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH:= $(call my-dir) 2 | #====================================================================== 3 | # 4 | #rgaCopyRgbaTo565 5 | # 6 | #====================================================================== 7 | include $(CLEAR_VARS) 8 | LOCAL_VENDOR_MODULE := true 9 | 10 | LOCAL_CFLAGS += -DGL_GLEXT_PROTOTYPES -DEGL_EGLEXT_PROTOTYPES 11 | 12 | LOCAL_CFLAGS += -DROCKCHIP_GPU_LIB_ENABLE 13 | 14 | LOCAL_CFLAGS += -Wall -Werror -Wunreachable-code 15 | 16 | LOCAL_C_INCLUDES += external/tinyalsa/include 17 | 18 | LOCAL_C_INCLUDES += hardware/rockchip/librga 19 | LOCAL_C_INCLUDES += hardware/rk29/librga \ 20 | system/core \ 21 | system/core/include/utils \ 22 | system/core/liblog/include \ 23 | $(LOCAL_PATH)/../.. \ 24 | $(LOCAL_PATH)/../../include 25 | 26 | LOCAL_SHARED_LIBRARIES := \ 27 | libcutils \ 28 | liblog \ 29 | libutils \ 30 | libui \ 31 | libEGL \ 32 | libGLESv1_CM \ 33 | libhardware \ 34 | librga 35 | 36 | LOCAL_HEADER_LIBRARIES += \ 37 | libutils_headers \ 38 | libcutils_headers \ 39 | libhardware_headers \ 40 | liblog_headers \ 41 | libgui_headers \ 42 | libbinder_headers 43 | 44 | #has no "external/stlport" from Android 6.0 on 45 | ifeq (1,$(strip $(shell expr $(PLATFORM_VERSION) \< 6.0))) 46 | LOCAL_C_INCLUDES += \ 47 | external/stlport/stlport 48 | 49 | LOCAL_C_INCLUDES += bionic 50 | endif 51 | 52 | #ifeq ($(strip $(BOARD_USE_DRM)), true) 53 | #ifneq (1,$(strip $(shell expr $(PLATFORM_VERSION) \< 6.9))) 54 | LOCAL_CFLAGS += -DANDROID_7_DRM -DANDROID 55 | #endif 56 | #endif 57 | 58 | ifeq ($(strip $(TARGET_BOARD_PLATFORM)),rk3368) 59 | LOCAL_CFLAGS += -DRK3368 60 | endif 61 | 62 | ifneq (1,$(strip $(shell expr $(PLATFORM_VERSION) \< 8.0))) 63 | LOCAL_CFLAGS += -DANDROID_8 64 | endif 65 | 66 | ifeq ($(strip $(TARGET_BOARD_PLATFORM)),rk3188) 67 | LOCAL_CFLAGS += -DRK3188 68 | endif 69 | 70 | LOCAL_SRC_FILES:= \ 71 | rgaCopyRgbaTo565.cpp 72 | 73 | LOCAL_MODULE:= rgaCopyRgbaTo565 74 | 75 | ifdef TARGET_32_BIT_SURFACEFLINGER 76 | LOCAL_32_BIT_ONLY := true 77 | endif 78 | 79 | include $(BUILD_EXECUTABLE) 80 | 81 | -------------------------------------------------------------------------------- /samples/rgaCopyRgbaTo565/rgaCopyRgbaTo565.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Rockchip Electronics Co., Ltd. 3 | * Authors: 4 | * Zhiqin Wei 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #define LOG_NDEBUG 0 20 | #define LOG_TAG "rgaCopyRgbaToYuv" 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | #include 50 | #include 51 | #include 52 | #include 53 | 54 | #include 55 | #include 56 | #include 57 | #include 58 | 59 | #ifndef ANDROID_8 60 | #include 61 | #endif 62 | 63 | #include "RockchipRga.h" 64 | #include "RgaUtils.h" 65 | 66 | /////////////////////////////////////////////////////// 67 | 68 | using namespace android; 69 | 70 | int main() { 71 | int ret = 0; 72 | int srcWidth,srcHeight,srcFormat; 73 | int dstWidth,dstHeight,dstFormat; 74 | char* buf = NULL; 75 | 76 | /********** SrcInfo set **********/ 77 | srcWidth = 1280; 78 | srcHeight = 720; 79 | srcFormat = HAL_PIXEL_FORMAT_RGBA_8888; 80 | 81 | /********** DstInfo set **********/ 82 | dstWidth = 1280; 83 | dstHeight = 720; 84 | dstFormat = HAL_PIXEL_FORMAT_RGB_565; 85 | 86 | RockchipRga& rkRga(RockchipRga::get()); 87 | 88 | // GraphicBufferMapper &mgbMapper = GraphicBufferMapper::get(); 89 | 90 | /********** apply for src_buffer **********/ 91 | #ifdef ANDROID_7_DRM 92 | sp gbs(new GraphicBuffer(srcWidth,srcHeight,srcFormat, 93 | GRALLOC_USAGE_SW_WRITE_OFTEN | GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_HW_FB)); 94 | #else 95 | sp gbs(new GraphicBuffer(srcWidth,srcHeight,srcFormat, 96 | GRALLOC_USAGE_SW_WRITE_OFTEN | GRALLOC_USAGE_SW_READ_OFTEN)); 97 | #endif 98 | 99 | if (gbs->initCheck()) { 100 | printf("GraphicBuffer_src error : %s\n",strerror(errno)); 101 | return ret; 102 | } else 103 | printf("GraphicBuffer_src %s \n","ok"); 104 | 105 | /********** apply for dst_buffer **********/ 106 | #ifdef ANDROID_7_DRM 107 | sp gbd(new GraphicBuffer(dstWidth,dstHeight,dstFormat, 108 | GRALLOC_USAGE_SW_WRITE_OFTEN | GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_HW_FB)); 109 | #else 110 | sp gbd(new GraphicBuffer(dstWidth,dstHeight,dstFormat, 111 | GRALLOC_USAGE_SW_WRITE_OFTEN | GRALLOC_USAGE_SW_READ_OFTEN)); 112 | #endif 113 | 114 | if (gbd->initCheck()) { 115 | printf("GraphicBuffer_dst error : %s\n",strerror(errno)); 116 | return ret; 117 | } else 118 | printf("GraphicBuffer_dst %s \n","ok"); 119 | 120 | /********** map buffer_address to userspace **********/ 121 | /* 122 | #ifdef ANDROID_8 123 | buffer_handle_t importedHandle_src; 124 | buffer_handle_t importedHandle_dst; 125 | mgbMapper.importBuffer(gbs->handle, &importedHandle_src); 126 | mgbMapper.importBuffer(gbd->handle, &importedHandle_dst); 127 | gbs->handle = importedHandle_src; 128 | gbd->handle = importedHandle_dst; 129 | #else 130 | mgbMapper.registerBuffer(gbs->handle); 131 | mgbMapper.registerBuffer(gbd->handle); 132 | #endif 133 | */ 134 | /********** write data to src_buffer or init buffer**********/ 135 | ret = gbs->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)&buf); 136 | if (ret) { 137 | printf("lock buffer_src error : %s\n",strerror(errno)); 138 | return ret; 139 | } else 140 | printf("lock buffer_src %s \n","ok"); 141 | 142 | 143 | get_buf_from_file(buf, srcFormat, srcWidth, srcHeight, 0); 144 | 145 | 146 | ret = gbs->unlock(); 147 | if (ret) { 148 | printf("unlock buffer_src error : %s\n",strerror(errno)); 149 | return ret; 150 | } else 151 | printf("unlock buffer_src %s \n","ok"); 152 | 153 | /********** write data to dst_buffer or init buffer **********/ 154 | ret = gbd->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)&buf); 155 | if (ret) { 156 | printf("lock buffer_dst error : %s\n",strerror(errno)); 157 | return ret; 158 | } else 159 | printf("lock buffer_dst %s \n","ok"); 160 | 161 | memset(buf,0x00,2*1280*720); 162 | 163 | ret = gbd->unlock(); 164 | if (ret) { 165 | printf("unlock buffer_dst error : %s\n",strerror(errno)); 166 | return ret; 167 | } else 168 | printf("unlock buffer_dst %s \n","ok"); 169 | 170 | while(1) { 171 | /********** rga_info_t Init **********/ 172 | rga_info_t src; 173 | rga_info_t dst; 174 | 175 | memset(&src, 0, sizeof(rga_info_t)); 176 | src.fd = -1; 177 | src.mmuFlag = 1; 178 | src.hnd = gbs->handle; 179 | 180 | memset(&dst, 0, sizeof(rga_info_t)); 181 | dst.fd = -1; 182 | dst.mmuFlag = 1; 183 | dst.hnd = gbd->handle; 184 | 185 | /********** get src_Fd **********/ 186 | ret = rkRga.RkRgaGetBufferFd(gbs->handle, &src.fd); 187 | printf("src.fd =%d\n",src.fd); 188 | if (ret) { 189 | printf("rgaGetsrcFd fail : %s,hnd=%p \n", 190 | strerror(errno),(void*)(gbd->handle)); 191 | } 192 | /********** get dst_Fd **********/ 193 | ret = rkRga.RkRgaGetBufferFd(gbd->handle, &dst.fd); 194 | printf("dst.fd =%d \n",dst.fd); 195 | if (ret) { 196 | printf("rgaGetdstFd error : %s,hnd=%p\n", 197 | strerror(errno),(void*)(gbd->handle)); 198 | } 199 | /********** if not fd, try to check phyAddr and virAddr **************/ 200 | #ifndef RK3188 201 | if(src.fd <= 0|| dst.fd <= 0) 202 | #endif 203 | { 204 | /********** check phyAddr and virAddr ,if none to get virAddr **********/ 205 | if (( src.phyAddr != 0 || src.virAddr != 0 ) || src.hnd != NULL ) { 206 | ret = RkRgaGetHandleMapAddress( gbs->handle, &src.virAddr ); 207 | printf("src.virAddr =%p\n",src.virAddr); 208 | if(!src.virAddr) { 209 | printf("err! src has not fd and address for render ,Stop!\n"); 210 | break; 211 | } 212 | } 213 | 214 | /********** check phyAddr and virAddr ,if none to get virAddr **********/ 215 | if (( dst.phyAddr != 0 || dst.virAddr != 0 ) || dst.hnd != NULL ) { 216 | ret = RkRgaGetHandleMapAddress( gbd->handle, &dst.virAddr ); 217 | printf("dst.virAddr =%p\n",dst.virAddr); 218 | if(!dst.virAddr) { 219 | printf("err! dst has not fd and address for render ,Stop!\n"); 220 | break; 221 | } 222 | } 223 | } 224 | /********** set the rect_info **********/ 225 | rga_set_rect(&src.rect, 0,0,srcWidth,srcHeight,srcWidth/*stride*/,srcHeight,srcFormat); 226 | rga_set_rect(&dst.rect, 0,0,dstWidth,dstHeight,dstWidth/*stride*/,dstHeight,dstFormat); 227 | 228 | /************ set the rga_mod ,rotation\composition\scale\copy .... **********/ 229 | 230 | 231 | /********** call rga_Interface **********/ 232 | struct timeval tpend1, tpend2; 233 | long usec1 = 0; 234 | gettimeofday(&tpend1, NULL); 235 | 236 | ret = rkRga.RkRgaBlit(&src, &dst, NULL); 237 | 238 | gettimeofday(&tpend2, NULL); 239 | usec1 = 1000 * (tpend2.tv_sec - tpend1.tv_sec) + (tpend2.tv_usec - tpend1.tv_usec) / 1000; 240 | printf("cost_time=%ld ms\n", usec1); 241 | if (ret) { 242 | printf("rgaFillColor error : %s,hnd=%p\n", 243 | strerror(errno),(void*)(gbd->handle)); 244 | } 245 | 246 | { 247 | /********** output buf data to file **********/ 248 | char* dstbuf = NULL; 249 | ret = gbd->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)&dstbuf); 250 | output_buf_data_to_file(dstbuf, dstFormat, dstWidth, dstHeight, 0); 251 | ret = gbd->unlock(); 252 | } 253 | printf("threadloop\n"); 254 | usleep(500000); 255 | break; 256 | } 257 | return 0; 258 | } 259 | -------------------------------------------------------------------------------- /samples/rgaCopyRgbaToYuv/Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH:= $(call my-dir) 2 | #====================================================================== 3 | # 4 | #rgaCopyRgbaToYuv 5 | # 6 | #====================================================================== 7 | include $(CLEAR_VARS) 8 | LOCAL_VENDOR_MODULE := true 9 | 10 | LOCAL_CFLAGS += -DGL_GLEXT_PROTOTYPES -DEGL_EGLEXT_PROTOTYPES 11 | 12 | LOCAL_CFLAGS += -DROCKCHIP_GPU_LIB_ENABLE 13 | 14 | LOCAL_CFLAGS += -Wall -Werror -Wunreachable-code 15 | 16 | LOCAL_C_INCLUDES += external/tinyalsa/include 17 | 18 | LOCAL_C_INCLUDES += hardware/rockchip/librga 19 | LOCAL_C_INCLUDES += hardware/rk29/librga \ 20 | system/core \ 21 | system/core/include/utils \ 22 | system/core/liblog/include \ 23 | $(LOCAL_PATH)/../.. \ 24 | $(LOCAL_PATH)/../../include 25 | 26 | LOCAL_SHARED_LIBRARIES := \ 27 | libcutils \ 28 | liblog \ 29 | libutils \ 30 | libui \ 31 | libEGL \ 32 | libGLESv1_CM \ 33 | libhardware \ 34 | librga 35 | 36 | LOCAL_HEADER_LIBRARIES += \ 37 | libutils_headers \ 38 | libcutils_headers \ 39 | libhardware_headers \ 40 | liblog_headers \ 41 | libgui_headers \ 42 | libbinder_headers 43 | 44 | #has no "external/stlport" from Android 6.0 on 45 | ifeq (1,$(strip $(shell expr $(PLATFORM_VERSION) \< 6.0))) 46 | LOCAL_C_INCLUDES += \ 47 | external/stlport/stlport 48 | 49 | LOCAL_C_INCLUDES += bionic 50 | endif 51 | 52 | #ifeq ($(strip $(BOARD_USE_DRM)), true) 53 | #ifneq (1,$(strip $(shell expr $(PLATFORM_VERSION) \< 6.9))) 54 | LOCAL_CFLAGS += -DANDROID_7_DRM -DANDROID 55 | #endif 56 | #endif 57 | 58 | ifeq ($(strip $(TARGET_BOARD_PLATFORM)),rk3368) 59 | LOCAL_CFLAGS += -DRK3368 60 | endif 61 | 62 | ifneq (1,$(strip $(shell expr $(PLATFORM_VERSION) \< 8.0))) 63 | LOCAL_CFLAGS += -DANDROID_8 64 | endif 65 | 66 | ifeq ($(strip $(TARGET_BOARD_PLATFORM)),rk3188) 67 | LOCAL_CFLAGS += -DRK3188 68 | endif 69 | 70 | LOCAL_SRC_FILES:= \ 71 | rgaCopyRgbaToYuv.cpp 72 | 73 | LOCAL_MODULE:= rgaCopyRgbaToYuv 74 | 75 | ifdef TARGET_32_BIT_SURFACEFLINGER 76 | LOCAL_32_BIT_ONLY := true 77 | endif 78 | 79 | include $(BUILD_EXECUTABLE) 80 | 81 | -------------------------------------------------------------------------------- /samples/rgaCopyRgbaToYuv/rgaCopyRgbaToYuv.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Rockchip Electronics Co., Ltd. 3 | * Authors: 4 | * Zhiqin Wei 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #define LOG_NDEBUG 0 20 | #define LOG_TAG "rgaCopyRgbaToYuv" 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | #include 50 | #include 51 | #include 52 | #include 53 | 54 | #include 55 | #include 56 | #include 57 | #include 58 | 59 | #ifndef ANDROID_8 60 | #include 61 | #endif 62 | 63 | #include "RockchipRga.h" 64 | #include "RgaUtils.h" 65 | 66 | /////////////////////////////////////////////////////// 67 | 68 | using namespace android; 69 | 70 | int main() { 71 | int ret = 0; 72 | int srcWidth,srcHeight,srcFormat; 73 | int dstWidth,dstHeight,dstFormat; 74 | char* buf = NULL; 75 | 76 | /********** SrcInfo set **********/ 77 | srcWidth = 1280; 78 | srcHeight = 720; 79 | srcFormat = HAL_PIXEL_FORMAT_RGBA_8888; 80 | 81 | /********** DstInfo set **********/ 82 | dstWidth = 1280; 83 | dstHeight = 720; 84 | dstFormat = HAL_PIXEL_FORMAT_YCrCb_NV12; 85 | 86 | RockchipRga& rkRga(RockchipRga::get()); 87 | 88 | // GraphicBufferMapper &mgbMapper = GraphicBufferMapper::get(); 89 | 90 | /********** apply for src_buffer **********/ 91 | #ifdef ANDROID_7_DRM 92 | sp gbs(new GraphicBuffer(srcWidth,srcHeight,srcFormat, 93 | GRALLOC_USAGE_SW_WRITE_OFTEN | GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_HW_FB)); 94 | #else 95 | sp gbs(new GraphicBuffer(srcWidth,srcHeight,srcFormat, 96 | GRALLOC_USAGE_SW_WRITE_OFTEN | GRALLOC_USAGE_SW_READ_OFTEN)); 97 | #endif 98 | 99 | if (gbs->initCheck()) { 100 | printf("GraphicBuffer_src error : %s\n",strerror(errno)); 101 | return ret; 102 | } else 103 | printf("GraphicBuffer_src %s \n","ok"); 104 | 105 | /********** apply for dst_buffer **********/ 106 | #ifdef ANDROID_7_DRM 107 | sp gbd(new GraphicBuffer(dstWidth,dstHeight,dstFormat, 108 | GRALLOC_USAGE_SW_WRITE_OFTEN | GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_HW_FB)); 109 | #else 110 | sp gbd(new GraphicBuffer(dstWidth,dstHeight,dstFormat, 111 | GRALLOC_USAGE_SW_WRITE_OFTEN | GRALLOC_USAGE_SW_READ_OFTEN)); 112 | #endif 113 | 114 | if (gbd->initCheck()) { 115 | printf("GraphicBuffer_dst error : %s\n",strerror(errno)); 116 | return ret; 117 | } else 118 | printf("GraphicBuffer_dst %s \n","ok"); 119 | 120 | /********** map buffer_address to userspace **********/ 121 | /* 122 | #ifdef ANDROID_8 123 | buffer_handle_t importedHandle_src; 124 | buffer_handle_t importedHandle_dst; 125 | mgbMapper.importBuffer(gbs->handle, &importedHandle_src); 126 | mgbMapper.importBuffer(gbd->handle, &importedHandle_dst); 127 | gbs->handle = importedHandle_src; 128 | gbd->handle = importedHandle_dst; 129 | #else 130 | mgbMapper.registerBuffer(gbs->handle); 131 | mgbMapper.registerBuffer(gbd->handle); 132 | #endif 133 | */ 134 | /********** write data to src_buffer or init buffer**********/ 135 | ret = gbs->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)&buf); 136 | if (ret) { 137 | printf("lock buffer_src error : %s\n",strerror(errno)); 138 | return ret; 139 | } else 140 | printf("lock buffer_src ok %s \n","ok"); 141 | 142 | get_buf_from_file(buf, srcFormat, srcWidth, srcHeight, 0); 143 | 144 | ret = gbs->unlock(); 145 | if (ret) { 146 | printf("unlock buffer_src error : %s\n",strerror(errno)); 147 | return ret; 148 | } else 149 | printf("unlock buffer_src %s \n","ok"); 150 | 151 | /********** write data to dst_buffer or init buffer **********/ 152 | ret = gbd->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)&buf); 153 | if (ret) { 154 | printf("lock buffer_dst error : %s\n",strerror(errno)); 155 | return ret; 156 | } else 157 | printf("lock buffer_dst ok %s \n","ok"); 158 | 159 | memset(buf,0x00,1.5*1280*720); 160 | 161 | ret = gbd->unlock(); 162 | if (ret) { 163 | printf("unlock buffer_dst error : %s\n",strerror(errno)); 164 | return ret; 165 | } else 166 | printf("unlock buffer_dst %s \n","ok"); 167 | 168 | while(1) { 169 | /********** rga_info_t Init **********/ 170 | rga_info_t src; 171 | rga_info_t dst; 172 | 173 | memset(&src, 0, sizeof(rga_info_t)); 174 | src.fd = -1; 175 | src.mmuFlag = 1; 176 | //src.hnd = gbs->handle; 177 | 178 | memset(&dst, 0, sizeof(rga_info_t)); 179 | dst.fd = -1; 180 | dst.mmuFlag = 1; 181 | //dst.hnd = gbd->handle; 182 | 183 | /********** get src_Fd **********/ 184 | ret = rkRga.RkRgaGetBufferFd(gbs->handle, &src.fd); 185 | printf("src.fd =%d\n",src.fd); 186 | if (ret) { 187 | printf("rgaGetsrcFd fail : %s,hnd=%p \n", 188 | strerror(errno),(void*)(gbd->handle)); 189 | } 190 | /********** get dst_Fd **********/ 191 | ret = rkRga.RkRgaGetBufferFd(gbd->handle, &dst.fd); 192 | printf("dst.fd =%d \n",dst.fd); 193 | if (ret) { 194 | printf("rgaGetdstFd error : %s,hnd=%p\n", 195 | strerror(errno),(void*)(gbd->handle)); 196 | } 197 | /********** if not fd, try to check phyAddr and virAddr **************/ 198 | #ifndef RK3188 199 | if(src.fd <= 0|| dst.fd <= 0) 200 | #endif 201 | { 202 | /********** check phyAddr and virAddr ,if none to get virAddr **********/ 203 | if (( src.phyAddr != 0 || src.virAddr != 0 ) || src.hnd != NULL ) { 204 | ret = RkRgaGetHandleMapAddress( gbs->handle, &src.virAddr ); 205 | printf("src.virAddr =%p\n",src.virAddr); 206 | if(!src.virAddr) { 207 | printf("err! src has not fd and address for render ,Stop!\n"); 208 | break; 209 | } 210 | } 211 | 212 | /********** check phyAddr and virAddr ,if none to get virAddr **********/ 213 | if (( dst.phyAddr != 0 || dst.virAddr != 0 ) || dst.hnd != NULL ) { 214 | ret = RkRgaGetHandleMapAddress( gbd->handle, &dst.virAddr ); 215 | printf("dst.virAddr =%p\n",dst.virAddr); 216 | if(!dst.virAddr) { 217 | printf("err! dst has not fd and address for render ,Stop!\n"); 218 | break; 219 | } 220 | } 221 | } 222 | 223 | /********** set the rect_info **********/ 224 | rga_set_rect(&src.rect, 0,0,srcWidth,srcHeight,srcWidth/*stride*/,srcHeight,srcFormat); 225 | rga_set_rect(&dst.rect, 0,0,dstWidth,dstHeight,dstWidth/*stride*/,dstHeight,dstFormat); 226 | 227 | /************ set the rga_mod ,rotation\composition\scale\copy .... **********/ 228 | 229 | 230 | /********** call rga_Interface **********/ 231 | struct timeval tpend1, tpend2; 232 | long usec1 = 0; 233 | gettimeofday(&tpend1, NULL); 234 | 235 | ret = rkRga.RkRgaBlit(&src, &dst, NULL); 236 | 237 | gettimeofday(&tpend2, NULL); 238 | usec1 = 1000 * (tpend2.tv_sec - tpend1.tv_sec) + (tpend2.tv_usec - tpend1.tv_usec) / 1000; 239 | printf("cost_time=%ld ms\n", usec1); 240 | if (ret) { 241 | printf("rgaFillColor error : %s,hnd=%p\n", 242 | strerror(errno),(void*)(gbd->handle)); 243 | } 244 | 245 | { 246 | /********** output buf data to file **********/ 247 | char* dstbuf = NULL; 248 | ret = gbd->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)&dstbuf); 249 | output_buf_data_to_file(dstbuf, dstFormat, dstWidth, dstHeight, 0); 250 | ret = gbd->unlock(); 251 | } 252 | printf("threadloop\n"); 253 | usleep(500000); 254 | break; 255 | } 256 | return 0; 257 | } 258 | -------------------------------------------------------------------------------- /samples/rgaCopyScale/Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH:= $(call my-dir) 2 | #====================================================================== 3 | # 4 | #rgaCopyScale 5 | # 6 | #====================================================================== 7 | include $(CLEAR_VARS) 8 | LOCAL_VENDOR_MODULE := true 9 | 10 | LOCAL_CFLAGS += -DGL_GLEXT_PROTOTYPES -DEGL_EGLEXT_PROTOTYPES 11 | 12 | LOCAL_CFLAGS += -DROCKCHIP_GPU_LIB_ENABLE 13 | 14 | LOCAL_CFLAGS += -Wall -Werror -Wunreachable-code 15 | 16 | LOCAL_C_INCLUDES += external/tinyalsa/include 17 | 18 | LOCAL_C_INCLUDES += hardware/rockchip/librga 19 | LOCAL_C_INCLUDES += hardware/rk29/librga \ 20 | system/core \ 21 | system/core/include/utils \ 22 | system/core/liblog/include \ 23 | $(LOCAL_PATH)/../.. \ 24 | $(LOCAL_PATH)/../../include 25 | 26 | LOCAL_SHARED_LIBRARIES := \ 27 | libcutils \ 28 | liblog \ 29 | libutils \ 30 | libui \ 31 | libEGL \ 32 | libGLESv1_CM \ 33 | libhardware \ 34 | librga 35 | 36 | LOCAL_HEADER_LIBRARIES += \ 37 | libutils_headers \ 38 | libcutils_headers \ 39 | libhardware_headers \ 40 | liblog_headers \ 41 | libgui_headers \ 42 | libbinder_headers 43 | 44 | #has no "external/stlport" from Android 6.0 on 45 | ifeq (1,$(strip $(shell expr $(PLATFORM_VERSION) \< 6.0))) 46 | LOCAL_C_INCLUDES += \ 47 | external/stlport/stlport 48 | 49 | LOCAL_C_INCLUDES += bionic 50 | endif 51 | 52 | #ifeq ($(strip $(BOARD_USE_DRM)), true) 53 | #ifneq (1,$(strip $(shell expr $(PLATFORM_VERSION) \< 6.9))) 54 | LOCAL_CFLAGS += -DANDROID_7_DRM -DANDROID 55 | #endif 56 | #endif 57 | 58 | ifeq ($(strip $(TARGET_BOARD_PLATFORM)),rk3368) 59 | LOCAL_CFLAGS += -DRK3368 60 | endif 61 | 62 | ifneq (1,$(strip $(shell expr $(PLATFORM_VERSION) \< 8.0))) 63 | LOCAL_CFLAGS += -DANDROID_8 64 | endif 65 | 66 | ifeq ($(strip $(TARGET_BOARD_PLATFORM)),rk3188) 67 | LOCAL_CFLAGS += -DRK3188 68 | endif 69 | 70 | LOCAL_SRC_FILES:= \ 71 | rgaCopyScale.cpp 72 | 73 | LOCAL_MODULE:= rgaCopyScale 74 | 75 | ifdef TARGET_32_BIT_SURFACEFLINGER 76 | LOCAL_32_BIT_ONLY := true 77 | endif 78 | 79 | include $(BUILD_EXECUTABLE) 80 | 81 | -------------------------------------------------------------------------------- /samples/rgaCopyScale/rgaCopyScale.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Rockchip Electronics Co., Ltd. 3 | * Authors: 4 | * Zhiqin Wei 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #define LOG_NDEBUG 0 20 | #define LOG_TAG "rgaCopyScale" 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | #include 50 | #include 51 | #include 52 | #include 53 | 54 | #include 55 | #include 56 | #include 57 | #include 58 | 59 | #ifndef ANDROID_8 60 | #include 61 | #endif 62 | 63 | #include "RockchipRga.h" 64 | #include "RgaUtils.h" 65 | 66 | /////////////////////////////////////////////////////// 67 | 68 | using namespace android; 69 | 70 | int main() { 71 | int ret = 0; 72 | int srcWidth,srcHeight,srcFormat; 73 | int dstWidth,dstHeight,dstFormat; 74 | char* buf = NULL; 75 | 76 | /********** SrcInfo set **********/ 77 | srcWidth = 1280; 78 | srcHeight = 720; 79 | srcFormat = HAL_PIXEL_FORMAT_RGBA_8888; 80 | 81 | /********** DstInfo set **********/ 82 | dstWidth = 1920; 83 | dstHeight = 1088; 84 | dstFormat = HAL_PIXEL_FORMAT_RGBA_8888; 85 | 86 | RockchipRga& rkRga(RockchipRga::get()); 87 | 88 | // GraphicBufferMapper &mgbMapper = GraphicBufferMapper::get(); 89 | 90 | /********** apply for src_buffer **********/ 91 | #ifdef ANDROID_7_DRM 92 | sp gbs(new GraphicBuffer(srcWidth,srcHeight,srcFormat, 93 | GRALLOC_USAGE_SW_WRITE_OFTEN | GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_HW_FB)); 94 | #else 95 | sp gbs(new GraphicBuffer(srcWidth,srcHeight,srcFormat, 96 | GRALLOC_USAGE_SW_WRITE_OFTEN | GRALLOC_USAGE_SW_READ_OFTEN)); 97 | #endif 98 | 99 | if (gbs->initCheck()) { 100 | printf("GraphicBuffer_src error : %s\n",strerror(errno)); 101 | return ret; 102 | } else 103 | printf("GraphicBuffer_src %s \n","ok"); 104 | 105 | /********** apply for dst_buffer **********/ 106 | #ifdef ANDROID_7_DRM 107 | sp gbd(new GraphicBuffer(dstWidth,dstHeight,dstFormat, 108 | GRALLOC_USAGE_SW_WRITE_OFTEN | GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_HW_FB)); 109 | #else 110 | sp gbd(new GraphicBuffer(dstWidth,dstHeight,dstFormat, 111 | GRALLOC_USAGE_SW_WRITE_OFTEN | GRALLOC_USAGE_SW_READ_OFTEN)); 112 | #endif 113 | 114 | if (gbd->initCheck()) { 115 | printf("GraphicBuffer_dst error : %s\n",strerror(errno)); 116 | return ret; 117 | } else 118 | printf("GraphicBuffer_dst %s \n","ok"); 119 | 120 | /********** map buffer_address to userspace **********/ 121 | /* 122 | #ifdef ANDROID_8 123 | buffer_handle_t importedHandle_src; 124 | buffer_handle_t importedHandle_dst; 125 | mgbMapper.importBuffer(gbs->handle, &importedHandle_src); 126 | mgbMapper.importBuffer(gbd->handle, &importedHandle_dst); 127 | gbs->handle = importedHandle_src; 128 | gbd->handle = importedHandle_dst; 129 | #else 130 | mgbMapper.registerBuffer(gbs->handle); 131 | mgbMapper.registerBuffer(gbd->handle); 132 | #endif 133 | */ 134 | /********** write data to src_buffer or init buffer**********/ 135 | ret = gbs->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)&buf); 136 | if (ret) { 137 | printf("lock buffer_src error : %s\n",strerror(errno)); 138 | return ret; 139 | } else 140 | printf("lock buffer_src %s \n","ok"); 141 | 142 | get_buf_from_file(buf, srcFormat, srcWidth, srcHeight, 0); 143 | 144 | ret = gbs->unlock(); 145 | if (ret) { 146 | printf("unlock buffer_src error : %s\n",strerror(errno)); 147 | return ret; 148 | } else 149 | printf("unlock buffer_src %s \n","ok"); 150 | 151 | /********** write data to dst_buffer or init buffer **********/ 152 | ret = gbd->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)&buf); 153 | if (ret) { 154 | printf("lock buffer_dst error : %s\n",strerror(errno)); 155 | return ret; 156 | } else 157 | printf("lock buffer_dst %s \n","ok"); 158 | 159 | memset(buf,0x00,4*1920*1088); 160 | 161 | ret = gbd->unlock(); 162 | if (ret) { 163 | printf("unlock buffer_dst error : %s\n",strerror(errno)); 164 | return ret; 165 | } else 166 | printf("unlock buffer_dst %s \n","ok"); 167 | 168 | while(1) { 169 | /********** rga_info_t Init **********/ 170 | rga_info_t src; 171 | rga_info_t dst; 172 | 173 | memset(&src, 0, sizeof(rga_info_t)); 174 | src.fd = -1; 175 | src.mmuFlag = 1; 176 | src.hnd = gbs->handle; 177 | 178 | memset(&dst, 0, sizeof(rga_info_t)); 179 | dst.fd = -1; 180 | dst.mmuFlag = 1; 181 | dst.hnd = gbd->handle; 182 | 183 | /********** get src_Fd **********/ 184 | ret = rkRga.RkRgaGetBufferFd(gbs->handle, &src.fd); 185 | printf("src.fd =%d\n",src.fd); 186 | if (ret) { 187 | printf("rgaGetsrcFd fail : %s,hnd=%p \n", 188 | strerror(errno),(void*)(gbd->handle)); 189 | } 190 | /********** get dst_Fd **********/ 191 | ret = rkRga.RkRgaGetBufferFd(gbd->handle, &dst.fd); 192 | printf("dst.fd =%d \n",dst.fd); 193 | ALOGD("dst.fd =%d\n",dst.fd); 194 | if (ret) { 195 | printf("rgaGetdstFd error : %s,hnd=%p\n", 196 | strerror(errno),(void*)(gbd->handle)); 197 | } 198 | /********** if not fd, try to check phyAddr and virAddr **************/ 199 | #ifndef RK3188 200 | if(src.fd <= 0|| dst.fd <= 0) 201 | #endif 202 | { 203 | /********** check phyAddr and virAddr ,if none to get virAddr **********/ 204 | if (( src.phyAddr != 0 || src.virAddr != 0 ) || src.hnd != NULL ) { 205 | ret = RkRgaGetHandleMapAddress( gbs->handle, &src.virAddr ); 206 | printf("src.virAddr =%p\n",src.virAddr); 207 | if(!src.virAddr) { 208 | printf("err! src has not fd and address for render ,Stop!\n"); 209 | break; 210 | } 211 | } 212 | 213 | /********** check phyAddr and virAddr ,if none to get virAddr **********/ 214 | if (( dst.phyAddr != 0 || dst.virAddr != 0 ) || dst.hnd != NULL ) { 215 | ret = RkRgaGetHandleMapAddress( gbd->handle, &dst.virAddr ); 216 | printf("dst.virAddr =%p\n",dst.virAddr); 217 | if(!dst.virAddr) { 218 | printf("err! dst has not fd and address for render ,Stop!\n"); 219 | break; 220 | } 221 | } 222 | } 223 | /********** set the rect_info **********/ 224 | rga_set_rect(&src.rect, 0,0,srcWidth,srcHeight,srcWidth/*stride*/,srcHeight,srcFormat); 225 | rga_set_rect(&dst.rect, 0,0,dstWidth,dstHeight,dstWidth/*stride*/,dstHeight,dstFormat); 226 | 227 | /************ set the rga_mod ,rotation\composition\scale\copy .... **********/ 228 | 229 | 230 | /********** call rga_Interface **********/ 231 | struct timeval tpend1, tpend2; 232 | long usec1 = 0; 233 | gettimeofday(&tpend1, NULL); 234 | 235 | ret = rkRga.RkRgaBlit(&src, &dst, NULL); 236 | 237 | gettimeofday(&tpend2, NULL); 238 | usec1 = 1000 * (tpend2.tv_sec - tpend1.tv_sec) + (tpend2.tv_usec - tpend1.tv_usec) / 1000; 239 | printf("cost_time=%ld ms\n", usec1); 240 | if (ret) { 241 | printf("rgaFillColor error : %s,hnd=%p\n", 242 | strerror(errno),(void*)(gbd->handle)); 243 | } 244 | 245 | { 246 | /********** output buf data to file **********/ 247 | char* dstbuf = NULL; 248 | ret = gbd->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)&dstbuf); 249 | output_buf_data_to_file(dstbuf, dstFormat, dstWidth, dstHeight, 0); 250 | ret = gbd->unlock(); 251 | } 252 | printf("threadloop\n"); 253 | usleep(500000); 254 | break; 255 | } 256 | return 0; 257 | } 258 | -------------------------------------------------------------------------------- /samples/rgaCopyYuvTo565/Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH:= $(call my-dir) 2 | #====================================================================== 3 | # 4 | #rgaCopyYuvTo565 5 | # 6 | #====================================================================== 7 | include $(CLEAR_VARS) 8 | LOCAL_VENDOR_MODULE := true 9 | 10 | LOCAL_CFLAGS += -DGL_GLEXT_PROTOTYPES -DEGL_EGLEXT_PROTOTYPES 11 | 12 | LOCAL_CFLAGS += -DROCKCHIP_GPU_LIB_ENABLE 13 | 14 | LOCAL_CFLAGS += -Wall -Werror -Wunreachable-code 15 | 16 | LOCAL_C_INCLUDES += external/tinyalsa/include 17 | 18 | LOCAL_C_INCLUDES += hardware/rockchip/librga 19 | LOCAL_C_INCLUDES += hardware/rk29/librga \ 20 | system/core \ 21 | system/core/include/utils \ 22 | system/core/liblog/include \ 23 | $(LOCAL_PATH)/../.. \ 24 | $(LOCAL_PATH)/../../include 25 | 26 | LOCAL_SHARED_LIBRARIES := \ 27 | libcutils \ 28 | liblog \ 29 | libutils \ 30 | libui \ 31 | libEGL \ 32 | libGLESv1_CM \ 33 | libhardware \ 34 | librga 35 | 36 | LOCAL_HEADER_LIBRARIES += \ 37 | libutils_headers \ 38 | libcutils_headers \ 39 | libhardware_headers \ 40 | liblog_headers \ 41 | libgui_headers \ 42 | libbinder_headers 43 | 44 | #has no "external/stlport" from Android 6.0 on 45 | ifeq (1,$(strip $(shell expr $(PLATFORM_VERSION) \< 6.0))) 46 | LOCAL_C_INCLUDES += \ 47 | external/stlport/stlport 48 | 49 | LOCAL_C_INCLUDES += bionic 50 | endif 51 | 52 | #ifeq ($(strip $(BOARD_USE_DRM)), true) 53 | #ifneq (1,$(strip $(shell expr $(PLATFORM_VERSION) \< 6.9))) 54 | LOCAL_CFLAGS += -DANDROID_7_DRM -DANDROID 55 | #endif 56 | #endif 57 | 58 | ifeq ($(strip $(TARGET_BOARD_PLATFORM)),rk3368) 59 | LOCAL_CFLAGS += -DRK3368 60 | endif 61 | 62 | ifneq (1,$(strip $(shell expr $(PLATFORM_VERSION) \< 8.0))) 63 | LOCAL_CFLAGS += -DANDROID_8 64 | endif 65 | 66 | ifeq ($(strip $(TARGET_BOARD_PLATFORM)),rk3188) 67 | LOCAL_CFLAGS += -DRK3188 68 | endif 69 | 70 | LOCAL_SRC_FILES:= \ 71 | rgaCopyYuvTo565.cpp 72 | 73 | LOCAL_MODULE:= rgaCopyYuvTo565 74 | 75 | ifdef TARGET_32_BIT_SURFACEFLINGER 76 | LOCAL_32_BIT_ONLY := true 77 | endif 78 | 79 | include $(BUILD_EXECUTABLE) 80 | 81 | -------------------------------------------------------------------------------- /samples/rgaCopyYuvTo565/rgaCopyYuvTo565.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Rockchip Electronics Co., Ltd. 3 | * Authors: 4 | * Zhiqin Wei 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #define LOG_NDEBUG 0 20 | #define LOG_TAG "rgaCopyYuvTo565" 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | #include 50 | #include 51 | #include 52 | #include 53 | 54 | #include 55 | #include 56 | #include 57 | #include 58 | 59 | #ifndef ANDROID_8 60 | #include 61 | #endif 62 | 63 | #include "RockchipRga.h" 64 | #include "RgaUtils.h" 65 | 66 | /////////////////////////////////////////////////////// 67 | 68 | using namespace android; 69 | 70 | int main() { 71 | int ret = 0; 72 | int srcWidth,srcHeight,srcFormat; 73 | int dstWidth,dstHeight,dstFormat; 74 | char* buf = NULL; 75 | 76 | /********** SrcInfo set **********/ 77 | srcWidth = 1280; 78 | srcHeight = 720; 79 | srcFormat = HAL_PIXEL_FORMAT_YCrCb_NV12; 80 | 81 | /********** DstInfo set **********/ 82 | dstWidth = 1280; 83 | dstHeight = 720; 84 | dstFormat = HAL_PIXEL_FORMAT_RGB_565; 85 | 86 | RockchipRga& rkRga(RockchipRga::get()); 87 | 88 | // GraphicBufferMapper &mgbMapper = GraphicBufferMapper::get(); 89 | 90 | /********** apply for src_buffer **********/ 91 | #ifdef ANDROID_7_DRM 92 | sp gbs(new GraphicBuffer(srcWidth,srcHeight,srcFormat, 93 | GRALLOC_USAGE_SW_WRITE_OFTEN | GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_HW_FB)); 94 | #else 95 | sp gbs(new GraphicBuffer(srcWidth,srcHeight,srcFormat, 96 | GRALLOC_USAGE_SW_WRITE_OFTEN | GRALLOC_USAGE_SW_READ_OFTEN)); 97 | #endif 98 | 99 | if (gbs->initCheck()) { 100 | printf("GraphicBuffer_src error : %s\n",strerror(errno)); 101 | return ret; 102 | } else 103 | printf("GraphicBuffer_src %s \n","ok"); 104 | 105 | /********** apply for dst_buffer **********/ 106 | #ifdef ANDROID_7_DRM 107 | sp gbd(new GraphicBuffer(dstWidth,dstHeight,dstFormat, 108 | GRALLOC_USAGE_SW_WRITE_OFTEN | GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_HW_FB)); 109 | #else 110 | sp gbd(new GraphicBuffer(dstWidth,dstHeight,dstFormat, 111 | GRALLOC_USAGE_SW_WRITE_OFTEN | GRALLOC_USAGE_SW_READ_OFTEN)); 112 | #endif 113 | 114 | if (gbd->initCheck()) { 115 | printf("GraphicBuffer_dst error : %s\n",strerror(errno)); 116 | return ret; 117 | } else 118 | printf("GraphicBuffer_dst %s \n","ok"); 119 | 120 | /********** map buffer_address to userspace **********/ 121 | /* 122 | #ifdef ANDROID_8 123 | buffer_handle_t importedHandle_src; 124 | buffer_handle_t importedHandle_dst; 125 | mgbMapper.importBuffer(gbs->handle, &importedHandle_src); 126 | mgbMapper.importBuffer(gbd->handle, &importedHandle_dst); 127 | gbs->handle = importedHandle_src; 128 | gbd->handle = importedHandle_dst; 129 | #else 130 | mgbMapper.registerBuffer(gbs->handle); 131 | mgbMapper.registerBuffer(gbd->handle); 132 | #endif 133 | */ 134 | /********** write data to src_buffer or init buffer**********/ 135 | ret = gbs->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)&buf); 136 | 137 | if (ret) { 138 | printf("lock buffer_src error : %s\n",strerror(errno)); 139 | return ret; 140 | } else 141 | printf("lock buffer_src %s \n","ok"); 142 | 143 | get_buf_from_file(buf, srcFormat, srcWidth, srcHeight, 0); 144 | 145 | ret = gbs->unlock(); 146 | if (ret) { 147 | printf("unlock buffer_src error : %s\n",strerror(errno)); 148 | return ret; 149 | } else 150 | printf("unlock buffer_src %s \n","ok"); 151 | 152 | /********** write data to dst_buffer or init buffer **********/ 153 | ret = gbd->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)&buf); 154 | 155 | if (ret) { 156 | printf("lock buffer_dst error : %s\n",strerror(errno)); 157 | return ret; 158 | } else 159 | printf("lock buffer_dst %s \n","ok"); 160 | 161 | memset(buf,0x00,2*1280*720); 162 | 163 | ret = gbd->unlock(); 164 | if (ret) { 165 | printf("unlock buffer_dst error : %s\n",strerror(errno)); 166 | return ret; 167 | } else 168 | printf("unlock buffer_dst %s \n","ok"); 169 | 170 | while(1) { 171 | /********** rga_info_t Init **********/ 172 | rga_info_t src; 173 | rga_info_t dst; 174 | 175 | memset(&src, 0, sizeof(rga_info_t)); 176 | src.fd = -1; 177 | src.mmuFlag = 1; 178 | src.hnd = gbs->handle; 179 | 180 | memset(&dst, 0, sizeof(rga_info_t)); 181 | dst.fd = -1; 182 | dst.mmuFlag = 1; 183 | dst.hnd = gbd->handle; 184 | 185 | /********** get src_Fd **********/ 186 | ret = rkRga.RkRgaGetBufferFd(gbs->handle, &src.fd); 187 | printf("src.fd =%d\n",src.fd); 188 | if (ret) { 189 | printf("rgaGetsrcFd fail : %s,hnd=%p \n", 190 | strerror(errno),(void*)(gbd->handle)); 191 | } 192 | /********** get dst_Fd **********/ 193 | ret = rkRga.RkRgaGetBufferFd(gbd->handle, &dst.fd); 194 | printf("dst.fd =%d \n",dst.fd); 195 | if (ret) { 196 | printf("rgaGetdstFd error : %s,hnd=%p\n", 197 | strerror(errno),(void*)(gbd->handle)); 198 | } 199 | /********** if not fd, try to check phyAddr and virAddr **************/ 200 | #ifndef RK3188 201 | if(src.fd <= 0|| dst.fd <= 0) 202 | #endif 203 | { 204 | /********** check phyAddr and virAddr ,if none to get virAddr **********/ 205 | if (( src.phyAddr != 0 || src.virAddr != 0 ) || src.hnd != NULL ) { 206 | ret = RkRgaGetHandleMapAddress( gbs->handle, &src.virAddr ); 207 | printf("src.virAddr =%p\n",src.virAddr); 208 | if(!src.virAddr) { 209 | printf("err! src has not fd and address for render ,Stop!\n"); 210 | break; 211 | } 212 | } 213 | 214 | /********** check phyAddr and virAddr ,if none to get virAddr **********/ 215 | if (( dst.phyAddr != 0 || dst.virAddr != 0 ) || dst.hnd != NULL ) { 216 | ret = RkRgaGetHandleMapAddress( gbd->handle, &dst.virAddr ); 217 | printf("dst.virAddr =%p\n",dst.virAddr); 218 | if(!dst.virAddr) { 219 | printf("err! dst has not fd and address for render ,Stop!\n"); 220 | break; 221 | } 222 | } 223 | } 224 | /********** set the rect_info **********/ 225 | rga_set_rect(&src.rect, 0,0,srcWidth,srcHeight,srcWidth/*stride*/,srcHeight,srcFormat); 226 | rga_set_rect(&dst.rect, 0,0,dstWidth,dstHeight,dstWidth/*stride*/,dstHeight,dstFormat); 227 | 228 | /************ set the rga_mod ,rotation\composition\scale\copy .... **********/ 229 | 230 | 231 | /********** call rga_Interface **********/ 232 | struct timeval tpend1, tpend2; 233 | long usec1 = 0; 234 | gettimeofday(&tpend1, NULL); 235 | ret = rkRga.RkRgaBlit(&src, &dst, NULL); 236 | gettimeofday(&tpend2, NULL); 237 | usec1 = 1000 * (tpend2.tv_sec - tpend1.tv_sec) + (tpend2.tv_usec - tpend1.tv_usec) / 1000; 238 | printf("cost_time=%ld ms\n", usec1); 239 | if (ret) { 240 | printf("rgaFillColor error : %s,hnd=%p\n", 241 | strerror(errno),(void*)(gbd->handle)); 242 | } 243 | 244 | { 245 | /********** output buf data to file **********/ 246 | char* dstbuf = NULL; 247 | ret = gbd->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)&dstbuf); 248 | output_buf_data_to_file(dstbuf, dstFormat, dstWidth, dstHeight, 0); 249 | ret = gbd->unlock(); 250 | } 251 | printf("threadloop\n"); 252 | usleep(500000); 253 | break; 254 | } 255 | return 0; 256 | } 257 | -------------------------------------------------------------------------------- /samples/rgaCopyYuvToRgba/Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH:= $(call my-dir) 2 | #====================================================================== 3 | # 4 | #rgaCopyYuvToRgba 5 | # 6 | #====================================================================== 7 | include $(CLEAR_VARS) 8 | LOCAL_VENDOR_MODULE := true 9 | 10 | LOCAL_CFLAGS += -DGL_GLEXT_PROTOTYPES -DEGL_EGLEXT_PROTOTYPES 11 | 12 | LOCAL_CFLAGS += -DROCKCHIP_GPU_LIB_ENABLE 13 | 14 | LOCAL_CFLAGS += -Wall -Werror -Wunreachable-code 15 | 16 | LOCAL_C_INCLUDES += external/tinyalsa/include 17 | 18 | LOCAL_C_INCLUDES += hardware/rockchip/librga 19 | LOCAL_C_INCLUDES += hardware/rk29/librga \ 20 | system/core \ 21 | system/core/include/utils \ 22 | system/core/liblog/include \ 23 | $(LOCAL_PATH)/../.. \ 24 | $(LOCAL_PATH)/../../include 25 | 26 | LOCAL_SHARED_LIBRARIES := \ 27 | libcutils \ 28 | liblog \ 29 | libutils \ 30 | libui \ 31 | libEGL \ 32 | libGLESv1_CM \ 33 | libhardware \ 34 | librga 35 | 36 | LOCAL_HEADER_LIBRARIES += \ 37 | libutils_headers \ 38 | libcutils_headers \ 39 | libhardware_headers \ 40 | liblog_headers \ 41 | libgui_headers \ 42 | libbinder_headers 43 | 44 | #has no "external/stlport" from Android 6.0 on 45 | ifeq (1,$(strip $(shell expr $(PLATFORM_VERSION) \< 6.0))) 46 | LOCAL_C_INCLUDES += \ 47 | external/stlport/stlport 48 | 49 | LOCAL_C_INCLUDES += bionic 50 | endif 51 | 52 | #ifeq ($(strip $(BOARD_USE_DRM)), true) 53 | #ifneq (1,$(strip $(shell expr $(PLATFORM_VERSION) \< 6.9))) 54 | LOCAL_CFLAGS += -DANDROID_7_DRM -DANDROID 55 | #endif 56 | #endif 57 | 58 | ifeq ($(strip $(TARGET_BOARD_PLATFORM)),rk3368) 59 | LOCAL_CFLAGS += -DRK3368 60 | endif 61 | 62 | ifneq (1,$(strip $(shell expr $(PLATFORM_VERSION) \< 8.0))) 63 | LOCAL_CFLAGS += -DANDROID_8 64 | endif 65 | 66 | ifeq ($(strip $(TARGET_BOARD_PLATFORM)),rk3188) 67 | LOCAL_CFLAGS += -DRK3188 68 | endif 69 | 70 | LOCAL_SRC_FILES:= \ 71 | rgaCopyYuvToRgba.cpp 72 | 73 | LOCAL_MODULE:= rgaCopyYuvToRgba 74 | 75 | ifdef TARGET_32_BIT_SURFACEFLINGER 76 | LOCAL_32_BIT_ONLY := true 77 | endif 78 | 79 | include $(BUILD_EXECUTABLE) 80 | 81 | -------------------------------------------------------------------------------- /samples/rgaCopyYuvToRgba/rgaCopyYuvToRgba.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Rockchip Electronics Co., Ltd. 3 | * Authors: 4 | * Zhiqin Wei 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #define LOG_NDEBUG 0 20 | #define LOG_TAG "rgaCopyYuvToRgba" 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | #include 50 | #include 51 | #include 52 | #include 53 | 54 | #include 55 | #include 56 | #include 57 | #include 58 | 59 | #ifndef ANDROID_8 60 | #include 61 | #endif 62 | 63 | #include "RockchipRga.h" 64 | #include "RgaUtils.h" 65 | 66 | /////////////////////////////////////////////////////// 67 | 68 | using namespace android; 69 | 70 | int main() { 71 | int ret = 0; 72 | int srcWidth,srcHeight,srcFormat; 73 | int dstWidth,dstHeight,dstFormat; 74 | char* buf = NULL; 75 | 76 | /********** SrcInfo set **********/ 77 | srcWidth = 1280; 78 | srcHeight = 720; 79 | srcFormat = HAL_PIXEL_FORMAT_YCrCb_NV12; 80 | 81 | /********** DstInfo set **********/ 82 | dstWidth = 1280; 83 | dstHeight = 720; 84 | dstFormat = HAL_PIXEL_FORMAT_RGBA_8888; 85 | 86 | RockchipRga& rkRga(RockchipRga::get()); 87 | 88 | // GraphicBufferMapper &mgbMapper = GraphicBufferMapper::get(); 89 | 90 | /********** apply for src_buffer **********/ 91 | #ifdef ANDROID_7_DRM 92 | sp gbs(new GraphicBuffer(srcWidth,srcHeight,srcFormat, 93 | GRALLOC_USAGE_SW_WRITE_OFTEN | GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_HW_FB)); 94 | #else 95 | sp gbs(new GraphicBuffer(srcWidth,srcHeight,srcFormat, 96 | GRALLOC_USAGE_SW_WRITE_OFTEN | GRALLOC_USAGE_SW_READ_OFTEN)); 97 | #endif 98 | 99 | if (gbs->initCheck()) { 100 | printf("GraphicBuffer_src error : %s\n",strerror(errno)); 101 | return ret; 102 | } else 103 | printf("GraphicBuffer_src %s \n","ok"); 104 | 105 | /********** apply for dst_buffer **********/ 106 | #ifdef ANDROID_7_DRM 107 | sp gbd(new GraphicBuffer(dstWidth,dstHeight,dstFormat, 108 | GRALLOC_USAGE_SW_WRITE_OFTEN | GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_HW_FB)); 109 | #else 110 | sp gbd(new GraphicBuffer(dstWidth,dstHeight,dstFormat, 111 | GRALLOC_USAGE_SW_WRITE_OFTEN | GRALLOC_USAGE_SW_READ_OFTEN)); 112 | #endif 113 | 114 | if (gbd->initCheck()) { 115 | printf("GraphicBuffer_dst error : %s\n",strerror(errno)); 116 | return ret; 117 | } else 118 | printf("GraphicBuffer_dst %s \n","ok"); 119 | 120 | /********** map buffer_address to userspace **********/ 121 | /* 122 | #ifdef ANDROID_8 123 | buffer_handle_t importedHandle_src; 124 | buffer_handle_t importedHandle_dst; 125 | mgbMapper.importBuffer(gbs->handle, &importedHandle_src); 126 | mgbMapper.importBuffer(gbd->handle, &importedHandle_dst); 127 | gbs->handle = importedHandle_src; 128 | gbd->handle = importedHandle_dst; 129 | #else 130 | mgbMapper.registerBuffer(gbs->handle); 131 | mgbMapper.registerBuffer(gbd->handle); 132 | #endif 133 | */ 134 | /********** write data to src_buffer or init buffer**********/ 135 | ret = gbs->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)&buf); 136 | if (ret) { 137 | printf("lock buffer_src error : %s\n",strerror(errno)); 138 | return ret; 139 | } else 140 | printf("lock buffer_src %s \n","ok"); 141 | 142 | get_buf_from_file(buf, srcFormat, srcWidth, srcHeight, 0); 143 | 144 | ret = gbs->unlock(); 145 | if (ret) { 146 | printf("unlock buffer_src error : %s\n",strerror(errno)); 147 | return ret; 148 | } else 149 | printf("unlock buffer_src %s \n","ok"); 150 | 151 | /********** write data to dst_buffer or init buffer **********/ 152 | ret = gbd->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)&buf); 153 | if (ret) { 154 | printf("lock buffer_dst error : %s\n",strerror(errno)); 155 | return ret; 156 | } else 157 | printf("lock buffer_dst %s \n","ok"); 158 | 159 | memset(buf,0x00,4*1280*720); 160 | 161 | ret = gbd->unlock(); 162 | if (ret) { 163 | printf("unlock buffer_dst error : %s\n",strerror(errno)); 164 | return ret; 165 | } else 166 | printf("unlock buffer_dst %s \n","ok"); 167 | 168 | while(1) { 169 | /********** rga_info_t Init **********/ 170 | rga_info_t src; 171 | rga_info_t dst; 172 | 173 | memset(&src, 0, sizeof(rga_info_t)); 174 | src.fd = -1; 175 | src.mmuFlag = 1; 176 | src.hnd = gbs->handle; 177 | 178 | memset(&dst, 0, sizeof(rga_info_t)); 179 | dst.fd = -1; 180 | dst.mmuFlag = 1; 181 | dst.hnd = gbd->handle; 182 | 183 | /********** get src_Fd **********/ 184 | ret = rkRga.RkRgaGetBufferFd(gbs->handle, &src.fd); 185 | printf("src.fd =%d\n",src.fd); 186 | if (ret) { 187 | printf("rgaGetsrcFd fail : %s,hnd=%p \n", 188 | strerror(errno),(void*)(gbd->handle)); 189 | } 190 | 191 | /********** get dst_Fd **********/ 192 | ret = rkRga.RkRgaGetBufferFd(gbd->handle, &dst.fd); 193 | printf("dst.fd =%d \n",dst.fd); 194 | if (ret) { 195 | printf("rgaGetdstFd error : %s,hnd=%p\n", 196 | strerror(errno),(void*)(gbd->handle)); 197 | } 198 | 199 | /********** if not fd, try to check phyAddr and virAddr **************/ 200 | #ifndef RK3188 201 | if(src.fd <= 0|| dst.fd <= 0) 202 | #endif 203 | { 204 | /********** check phyAddr and virAddr ,if none to get virAddr **********/ 205 | if (( src.phyAddr != 0 || src.virAddr != 0 ) || src.hnd != NULL ) { 206 | ret = RkRgaGetHandleMapAddress( gbs->handle, &src.virAddr ); 207 | printf("src.virAddr =%p\n",src.virAddr); 208 | if(!src.virAddr) { 209 | printf("err! src has not fd and address for render ,Stop!\n"); 210 | break; 211 | } 212 | } 213 | 214 | /********** check phyAddr and virAddr ,if none to get virAddr **********/ 215 | if (( dst.phyAddr != 0 || dst.virAddr != 0 ) || dst.hnd != NULL ) { 216 | ret = RkRgaGetHandleMapAddress( gbd->handle, &dst.virAddr ); 217 | printf("dst.virAddr =%p\n",dst.virAddr); 218 | if(!dst.virAddr) { 219 | printf("err! dst has not fd and address for render ,Stop!\n"); 220 | break; 221 | } 222 | } 223 | } 224 | /********** set the rect_info **********/ 225 | rga_set_rect(&src.rect, 0,0,srcWidth,srcHeight,srcWidth/*stride*/,srcHeight,srcFormat); 226 | rga_set_rect(&dst.rect, 0,0,dstWidth,dstHeight,dstWidth/*stride*/,dstHeight,dstFormat); 227 | 228 | /************ set the rga_mod ,rotation\composition\scale\copy .... **********/ 229 | 230 | 231 | /********** call rga_Interface **********/ 232 | struct timeval tpend1, tpend2; 233 | long usec1 = 0; 234 | gettimeofday(&tpend1, NULL); 235 | ret = rkRga.RkRgaBlit(&src, &dst, NULL); 236 | gettimeofday(&tpend2, NULL); 237 | usec1 = 1000 * (tpend2.tv_sec - tpend1.tv_sec) + (tpend2.tv_usec - tpend1.tv_usec) / 1000; 238 | printf("cost_time=%ld ms\n", usec1); 239 | if (ret) { 240 | printf("rgaFillColor error : %s,hnd=%p\n", 241 | strerror(errno),(void*)(gbd->handle)); 242 | } 243 | 244 | { 245 | /********** output buf data to file **********/ 246 | char* dstbuf = NULL; 247 | ret = gbd->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)&dstbuf); 248 | output_buf_data_to_file(dstbuf, dstFormat, dstWidth, dstHeight, 0); 249 | ret = gbd->unlock(); 250 | } 251 | printf("threadloop\n"); 252 | usleep(500000); 253 | break; 254 | } 255 | return 0; 256 | } 257 | -------------------------------------------------------------------------------- /samples/rgaMirror/Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH:= $(call my-dir) 2 | #====================================================================== 3 | # 4 | #rgaMirror 5 | # 6 | #====================================================================== 7 | include $(CLEAR_VARS) 8 | LOCAL_VENDOR_MODULE := true 9 | 10 | LOCAL_CFLAGS += -DGL_GLEXT_PROTOTYPES -DEGL_EGLEXT_PROTOTYPES 11 | 12 | LOCAL_CFLAGS += -DROCKCHIP_GPU_LIB_ENABLE 13 | 14 | LOCAL_CFLAGS += -Wall -Werror -Wunreachable-code 15 | 16 | LOCAL_C_INCLUDES += external/tinyalsa/include 17 | 18 | LOCAL_C_INCLUDES += hardware/rockchip/librga 19 | LOCAL_C_INCLUDES += hardware/rk29/librga \ 20 | system/core \ 21 | system/core/include/utils \ 22 | system/core/liblog/include \ 23 | $(LOCAL_PATH)/../.. \ 24 | $(LOCAL_PATH)/../../include 25 | 26 | LOCAL_SHARED_LIBRARIES := \ 27 | libcutils \ 28 | liblog \ 29 | libutils \ 30 | libui \ 31 | libEGL \ 32 | libGLESv1_CM \ 33 | libhardware \ 34 | librga 35 | 36 | LOCAL_HEADER_LIBRARIES += \ 37 | libutils_headers \ 38 | libcutils_headers \ 39 | libhardware_headers \ 40 | liblog_headers \ 41 | libgui_headers \ 42 | libbinder_headers 43 | 44 | #has no "external/stlport" from Android 6.0 on 45 | ifeq (1,$(strip $(shell expr $(PLATFORM_VERSION) \< 6.0))) 46 | LOCAL_C_INCLUDES += \ 47 | external/stlport/stlport 48 | 49 | LOCAL_C_INCLUDES += bionic 50 | endif 51 | 52 | #ifeq ($(strip $(BOARD_USE_DRM)), true) 53 | #ifneq (1,$(strip $(shell expr $(PLATFORM_VERSION) \< 6.9))) 54 | LOCAL_CFLAGS += -DANDROID_7_DRM -DANDROID 55 | #endif 56 | #endif 57 | 58 | ifeq ($(strip $(TARGET_BOARD_PLATFORM)),rk3368) 59 | LOCAL_CFLAGS += -DRK3368 60 | endif 61 | 62 | ifneq (1,$(strip $(shell expr $(PLATFORM_VERSION) \< 8.0))) 63 | LOCAL_CFLAGS += -DANDROID_8 64 | endif 65 | 66 | ifeq ($(strip $(TARGET_BOARD_PLATFORM)),rk3188) 67 | LOCAL_CFLAGS += -DRK3188 68 | endif 69 | 70 | LOCAL_SRC_FILES:= \ 71 | rgaMirror.cpp 72 | 73 | LOCAL_MODULE:= rgaMirror 74 | 75 | ifdef TARGET_32_BIT_SURFACEFLINGER 76 | LOCAL_32_BIT_ONLY := true 77 | endif 78 | 79 | include $(BUILD_EXECUTABLE) 80 | 81 | -------------------------------------------------------------------------------- /samples/rgaMirror/rgaMirror.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Rockchip Electronics Co., Ltd. 3 | * Authors: 4 | * Zhiqin Wei 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #define LOG_NDEBUG 0 20 | #define LOG_TAG "rgaMirror" 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | #include 50 | #include 51 | #include 52 | #include 53 | 54 | #include 55 | #include 56 | #include 57 | #include 58 | 59 | #ifndef ANDROID_8 60 | #include 61 | #endif 62 | 63 | #include "RockchipRga.h" 64 | #include "RgaUtils.h" 65 | 66 | /////////////////////////////////////////////////////// 67 | 68 | using namespace android; 69 | 70 | int main() { 71 | int ret = 0; 72 | int srcWidth,srcHeight,srcFormat; 73 | int dstWidth,dstHeight,dstFormat; 74 | char* buf = NULL; 75 | 76 | /********** SrcInfo set **********/ 77 | srcWidth = 1280; 78 | srcHeight = 720; 79 | srcFormat = HAL_PIXEL_FORMAT_RGBA_8888; 80 | 81 | /********** DstInfo set **********/ 82 | dstWidth = 1280; 83 | dstHeight = 720; 84 | dstFormat = HAL_PIXEL_FORMAT_RGBA_8888; 85 | 86 | RockchipRga& rkRga(RockchipRga::get()); 87 | 88 | // GraphicBufferMapper &mgbMapper = GraphicBufferMapper::get(); 89 | 90 | /********** apply for src_buffer **********/ 91 | #ifdef ANDROID_7_DRM 92 | sp gbs(new GraphicBuffer(srcWidth,srcHeight,srcFormat, 93 | GRALLOC_USAGE_SW_WRITE_OFTEN | GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_HW_FB)); 94 | #else 95 | sp gbs(new GraphicBuffer(srcWidth,srcHeight,srcFormat, 96 | GRALLOC_USAGE_SW_WRITE_OFTEN | GRALLOC_USAGE_SW_READ_OFTEN)); 97 | #endif 98 | if (gbs->initCheck()) { 99 | printf("GraphicBuffer_src error : %s\n",strerror(errno)); 100 | return ret; 101 | } else 102 | printf("GraphicBuffer_src %s \n","ok"); 103 | 104 | /********** apply for dst_buffer **********/ 105 | #ifdef ANDROID_7_DRM 106 | sp gbd(new GraphicBuffer(dstWidth,dstHeight,dstFormat, 107 | GRALLOC_USAGE_SW_WRITE_OFTEN | GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_HW_FB)); 108 | #else 109 | sp gbd(new GraphicBuffer(dstWidth,dstHeight,dstFormat, 110 | GRALLOC_USAGE_SW_WRITE_OFTEN | GRALLOC_USAGE_SW_READ_OFTEN)); 111 | #endif 112 | 113 | if (gbd->initCheck()) { 114 | printf("GraphicBuffer_dst error : %s\n",strerror(errno)); 115 | return ret; 116 | } else 117 | printf("GraphicBuffer_dst %s \n","ok"); 118 | 119 | /********** map buffer_address to userspace **********/ 120 | /* 121 | #ifdef ANDROID_8 122 | buffer_handle_t importedHandle_src; 123 | buffer_handle_t importedHandle_dst; 124 | mgbMapper.importBuffer(gbs->handle, &importedHandle_src); 125 | mgbMapper.importBuffer(gbd->handle, &importedHandle_dst); 126 | gbs->handle = importedHandle_src; 127 | gbd->handle = importedHandle_dst; 128 | #else 129 | mgbMapper.registerBuffer(gbs->handle); 130 | mgbMapper.registerBuffer(gbd->handle); 131 | #endif 132 | */ 133 | /********** write data to src_buffer or init buffer**********/ 134 | ret = gbs->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)&buf); 135 | if (ret) { 136 | printf("lock buffer_src error : %s\n",strerror(errno)); 137 | return ret; 138 | } else 139 | printf("lock buffer_src %s \n","ok"); 140 | 141 | get_buf_from_file(buf, srcFormat, srcWidth, srcHeight, 0); 142 | 143 | ret = gbs->unlock(); 144 | if (ret) { 145 | printf("unlock buffer_src error : %s\n",strerror(errno)); 146 | return ret; 147 | } else 148 | printf("unlock buffer_src %s \n","ok"); 149 | 150 | /********** write data to dst_buffer or init buffer **********/ 151 | ret = gbd->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)&buf); 152 | if (ret) { 153 | printf("lock buffer_dst error : %s\n",strerror(errno)); 154 | return ret; 155 | } else 156 | printf("lock buffer_dst %s \n","ok"); 157 | 158 | memset(buf,0x00,4*1280*720); 159 | 160 | ret = gbd->unlock(); 161 | if (ret) { 162 | printf("unlock buffer_dst error : %s\n",strerror(errno)); 163 | return ret; 164 | } else 165 | printf("unlock buffer_dst %s \n","ok"); 166 | 167 | while(1) { 168 | /********** rga_info_t Init **********/ 169 | rga_info_t src; 170 | rga_info_t dst; 171 | 172 | memset(&src, 0, sizeof(rga_info_t)); 173 | src.fd = -1; 174 | src.mmuFlag = 1; 175 | src.hnd = gbs->handle; 176 | 177 | memset(&dst, 0, sizeof(rga_info_t)); 178 | dst.fd = -1; 179 | dst.mmuFlag = 1; 180 | dst.hnd = gbd->handle; 181 | 182 | /********** get src_Fd **********/ 183 | ret = rkRga.RkRgaGetBufferFd(gbs->handle, &src.fd); 184 | printf("src.fd =%d\n",src.fd); 185 | if (ret) { 186 | printf("rgaGetsrcFd fail : %s,hnd=%p \n", 187 | strerror(errno),(void*)(gbd->handle)); 188 | } 189 | /********** get dst_Fd **********/ 190 | ret = rkRga.RkRgaGetBufferFd(gbd->handle, &dst.fd); 191 | printf("dst.fd =%d \n",dst.fd); 192 | if (ret) { 193 | printf("rgaGetdstFd error : %s,hnd=%p\n", 194 | strerror(errno),(void*)(gbd->handle)); 195 | } 196 | /********** if not fd, try to check phyAddr and virAddr **************/ 197 | #ifndef RK3188 198 | if(src.fd <= 0|| dst.fd <= 0) 199 | #endif 200 | { 201 | /********** check phyAddr and virAddr ,if none to get virAddr **********/ 202 | if (( src.phyAddr != 0 || src.virAddr != 0 ) || src.hnd != NULL ) { 203 | ret = RkRgaGetHandleMapAddress( gbs->handle, &src.virAddr ); 204 | printf("src.virAddr =%p\n",src.virAddr); 205 | if(!src.virAddr) { 206 | printf("err! src has not fd and address for render ,Stop!\n"); 207 | break; 208 | } 209 | } 210 | 211 | /********** check phyAddr and virAddr ,if none to get virAddr **********/ 212 | if (( dst.phyAddr != 0 || dst.virAddr != 0 ) || dst.hnd != NULL ) { 213 | ret = RkRgaGetHandleMapAddress( gbd->handle, &dst.virAddr ); 214 | printf("dst.virAddr =%p\n",dst.virAddr); 215 | if(!dst.virAddr) { 216 | printf("err! dst has not fd and address for render ,Stop!\n"); 217 | break; 218 | } 219 | } 220 | } 221 | /********** set the rect_info **********/ 222 | rga_set_rect(&src.rect, 0,0,srcWidth,srcHeight,srcWidth/*stride*/,srcHeight,srcFormat); 223 | rga_set_rect(&dst.rect, 0,0,dstWidth,dstHeight,dstWidth/*stride*/,dstHeight,dstFormat); 224 | 225 | /************ set the rga_mod ,rotation\composition\scale\copy .... **********/ 226 | src.rotation = HAL_TRANSFORM_FLIP_V; 227 | //src.rotation = HAL_TRANSFORM_FLIP_H; 228 | //src.rotation = HAL_TRANSFORM_FLIP_H | HAL_TRANSFORM_FLIP_V << 4; 229 | 230 | /********** call rga_Interface **********/ 231 | struct timeval tpend1, tpend2; 232 | long usec1 = 0; 233 | gettimeofday(&tpend1, NULL); 234 | ret = rkRga.RkRgaBlit(&src, &dst, NULL); 235 | gettimeofday(&tpend2, NULL); 236 | usec1 = 1000 * (tpend2.tv_sec - tpend1.tv_sec) + (tpend2.tv_usec - tpend1.tv_usec) / 1000; 237 | printf("cost_time=%ld ms\n", usec1); 238 | if (ret) { 239 | printf("rgaFillColor error : %s,hnd=%p\n", 240 | strerror(errno),(void*)(gbd->handle)); 241 | } 242 | 243 | { 244 | /********** output buf data to file **********/ 245 | char* dstbuf = NULL; 246 | ret = gbd->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)&dstbuf); 247 | output_buf_data_to_file(dstbuf, dstFormat, dstWidth, dstHeight, 0); 248 | ret = gbd->unlock(); 249 | } 250 | printf("threadloop\n"); 251 | usleep(500000); 252 | break; 253 | } 254 | return 0; 255 | } 256 | -------------------------------------------------------------------------------- /samples/rgaROP/Android.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2018 Fuzhou Rockchip Electronics Co., Ltd. All rights reserved. 3 | # Authors: 4 | # lihuang 5 | # libin 6 | # 7 | # This program is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation, either version 3 of the License, or 10 | # (at your option) any later version. 11 | # 12 | # This program is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU General Public License 18 | # along with this program. If not, see . 19 | # 20 | # BY DOWNLOADING, INSTALLING, COPYING, SAVING OR OTHERWISE USING THIS SOFTWARE, 21 | # YOU ACKNOWLEDGE THAT YOU AGREE THE SOFTWARE RECEIVED FORM ROCKCHIP IS PROVIDED 22 | # TO YOU ON AN "AS IS" BASIS and ROCKCHP DISCLAIMS ANY AND ALL WARRANTIES AND 23 | # REPRESENTATIONS WITH RESPECT TO SUCH FILE, WHETHER EXPRESS, IMPLIED, STATUTORY 24 | # OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF TITLE, 25 | # NON-INFRINGEMENT, MERCHANTABILITY, SATISFACTROY QUALITY, ACCURACY OR FITNESS FOR 26 | # A PARTICULAR PURPOSE. 27 | # 28 | 29 | LOCAL_PATH:= $(call my-dir) 30 | #====================================================================== 31 | # 32 | #rgaBlit 33 | # 34 | #====================================================================== 35 | include $(CLEAR_VARS) 36 | 37 | LOCAL_CFLAGS += -DGL_GLEXT_PROTOTYPES -DEGL_EGLEXT_PROTOTYPES 38 | 39 | LOCAL_CFLAGS += -DROCKCHIP_GPU_LIB_ENABLE 40 | 41 | LOCAL_CFLAGS += -Wall -Werror -Wunreachable-code 42 | 43 | LOCAL_C_INCLUDES += \ 44 | external/tinyalsa/include \ 45 | hardware/rockchip/librga \ 46 | hardware/rk29/librga \ 47 | $(LOCAL_PATH)/../.. \ 48 | $(LOCAL_PATH)/../../include 49 | 50 | LOCAL_SHARED_LIBRARIES := \ 51 | libcutils \ 52 | liblog \ 53 | libutils \ 54 | libbinder \ 55 | libui \ 56 | libEGL \ 57 | libGLESv1_CM \ 58 | libgui \ 59 | libhardware \ 60 | librga 61 | 62 | #has no "external/stlport" from Android 6.0 on 63 | ifeq (1,$(strip $(shell expr $(PLATFORM_VERSION) \< 6.0))) 64 | LOCAL_C_INCLUDES += \ 65 | external/stlport/stlport 66 | 67 | LOCAL_C_INCLUDES += bionic 68 | endif 69 | 70 | #ifeq ($(strip $(BOARD_USE_DRM)), true) 71 | #ifneq (1,$(strip $(shell expr $(PLATFORM_VERSION) \< 6.9))) 72 | LOCAL_CFLAGS += -DANDROID_7_DRM -DANDROID 73 | #endif 74 | #endif 75 | 76 | ifeq ($(strip $(TARGET_BOARD_PLATFORM)),rk3368) 77 | LOCAL_CFLAGS += -DRK3368 78 | endif 79 | 80 | ifneq (1,$(strip $(shell expr $(PLATFORM_VERSION) \< 8.0))) 81 | LOCAL_CFLAGS += -DANDROID_8 82 | endif 83 | 84 | ifeq ($(strip $(TARGET_BOARD_PLATFORM)),rk3188) 85 | LOCAL_CFLAGS += -DRK3188 86 | endif 87 | 88 | LOCAL_SRC_FILES:= \ 89 | rgaRop.cpp 90 | 91 | LOCAL_MODULE:= rgaRop 92 | 93 | ifdef TARGET_32_BIT_SURFACEFLINGER 94 | LOCAL_32_BIT_ONLY := true 95 | endif 96 | 97 | include $(BUILD_EXECUTABLE) 98 | 99 | -------------------------------------------------------------------------------- /samples/rgaRotation/Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH:= $(call my-dir) 2 | #====================================================================== 3 | # 4 | #rgaRotation 5 | # 6 | #====================================================================== 7 | include $(CLEAR_VARS) 8 | LOCAL_VENDOR_MODULE := true 9 | 10 | LOCAL_CFLAGS += -DGL_GLEXT_PROTOTYPES -DEGL_EGLEXT_PROTOTYPES 11 | 12 | LOCAL_CFLAGS += -DROCKCHIP_GPU_LIB_ENABLE 13 | 14 | LOCAL_CFLAGS += -Wall -Werror -Wunreachable-code 15 | 16 | LOCAL_C_INCLUDES += external/tinyalsa/include 17 | 18 | LOCAL_C_INCLUDES += hardware/rockchip/librga 19 | LOCAL_C_INCLUDES += hardware/rk29/librga \ 20 | system/core \ 21 | system/core/include/utils \ 22 | system/core/liblog/include \ 23 | $(LOCAL_PATH)/../.. \ 24 | $(LOCAL_PATH)/../../include 25 | 26 | LOCAL_SHARED_LIBRARIES := \ 27 | libcutils \ 28 | liblog \ 29 | libutils \ 30 | libui \ 31 | libEGL \ 32 | libGLESv1_CM \ 33 | libhardware \ 34 | librga 35 | 36 | LOCAL_HEADER_LIBRARIES += \ 37 | libutils_headers \ 38 | libcutils_headers \ 39 | libhardware_headers \ 40 | liblog_headers \ 41 | libgui_headers \ 42 | libbinder_headers 43 | 44 | #has no "external/stlport" from Android 6.0 on 45 | ifeq (1,$(strip $(shell expr $(PLATFORM_VERSION) \< 6.0))) 46 | LOCAL_C_INCLUDES += \ 47 | external/stlport/stlport 48 | 49 | LOCAL_C_INCLUDES += bionic 50 | endif 51 | 52 | #ifeq ($(strip $(BOARD_USE_DRM)), true) 53 | #ifneq (1,$(strip $(shell expr $(PLATFORM_VERSION) \< 6.9))) 54 | LOCAL_CFLAGS += -DANDROID_7_DRM -DANDROID 55 | #endif 56 | #endif 57 | 58 | ifeq ($(strip $(TARGET_BOARD_PLATFORM)),rk3368) 59 | LOCAL_CFLAGS += -DRK3368 60 | endif 61 | 62 | ifneq (1,$(strip $(shell expr $(PLATFORM_VERSION) \< 8.0))) 63 | LOCAL_CFLAGS += -DANDROID_8 64 | endif 65 | 66 | ifeq ($(strip $(TARGET_BOARD_PLATFORM)),rk3188) 67 | LOCAL_CFLAGS += -DRK3188 68 | endif 69 | 70 | LOCAL_SRC_FILES:= \ 71 | rgaRotation.cpp 72 | 73 | LOCAL_MODULE:= rgaRotation 74 | 75 | ifdef TARGET_32_BIT_SURFACEFLINGER 76 | LOCAL_32_BIT_ONLY := true 77 | endif 78 | 79 | include $(BUILD_EXECUTABLE) 80 | 81 | -------------------------------------------------------------------------------- /samples/rgaSlt/Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH:= $(call my-dir) 2 | #====================================================================== 3 | # 4 | #rgaSlt 5 | # 6 | #====================================================================== 7 | include $(CLEAR_VARS) 8 | LOCAL_VENDOR_MODULE := true 9 | 10 | LOCAL_CFLAGS += -DGL_GLEXT_PROTOTYPES -DEGL_EGLEXT_PROTOTYPES 11 | 12 | LOCAL_CFLAGS += -DROCKCHIP_GPU_LIB_ENABLE 13 | 14 | LOCAL_CFLAGS += -Wall -Werror -Wunreachable-code 15 | 16 | LOCAL_C_INCLUDES += external/tinyalsa/include 17 | 18 | LOCAL_C_INCLUDES += hardware/rockchip/librga 19 | LOCAL_C_INCLUDES += hardware/rk29/librga \ 20 | system/core \ 21 | system/core/include/utils \ 22 | system/core/liblog/include \ 23 | $(LOCAL_PATH)/../.. \ 24 | $(LOCAL_PATH)/../../include 25 | 26 | LOCAL_SHARED_LIBRARIES := \ 27 | libcutils \ 28 | liblog \ 29 | libutils \ 30 | libui \ 31 | libEGL \ 32 | libGLESv1_CM \ 33 | libhardware \ 34 | librga 35 | 36 | LOCAL_HEADER_LIBRARIES += \ 37 | libutils_headers \ 38 | libcutils_headers \ 39 | libhardware_headers \ 40 | liblog_headers \ 41 | libgui_headers \ 42 | libbinder_headers 43 | 44 | 45 | #has no "external/stlport" from Android 6.0 on 46 | ifeq (1,$(strip $(shell expr $(PLATFORM_VERSION) \< 6.0))) 47 | LOCAL_C_INCLUDES += \ 48 | external/stlport/stlport 49 | 50 | LOCAL_C_INCLUDES += bionic 51 | endif 52 | 53 | #ifeq ($(strip $(BOARD_USE_DRM)), true) 54 | #ifneq (1,$(strip $(shell expr $(PLATFORM_VERSION) \< 6.9))) 55 | LOCAL_CFLAGS += -DANDROID_7_DRM -DANDROID 56 | #endif 57 | #endif 58 | 59 | ifeq ($(strip $(TARGET_BOARD_PLATFORM)),rk3368) 60 | LOCAL_CFLAGS += -DRK3368 61 | endif 62 | 63 | ifneq (1,$(strip $(shell expr $(PLATFORM_VERSION) \< 8.0))) 64 | LOCAL_CFLAGS += -DANDROID_8 65 | endif 66 | 67 | ifeq ($(strip $(TARGET_BOARD_PLATFORM)),rk3188) 68 | LOCAL_CFLAGS += -DRK3188 69 | endif 70 | 71 | LOCAL_SRC_FILES:= \ 72 | rgaSlt.cpp 73 | 74 | LOCAL_MODULE:= rgaSlt 75 | 76 | ifdef TARGET_32_BIT_SURFACEFLINGER 77 | LOCAL_32_BIT_ONLY := true 78 | endif 79 | 80 | include $(BUILD_EXECUTABLE) 81 | 82 | -------------------------------------------------------------------------------- /samples/rgaTestCache/Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH:= $(call my-dir) 2 | #====================================================================== 3 | # 4 | #rgaTestCache 5 | # 6 | #====================================================================== 7 | include $(CLEAR_VARS) 8 | LOCAL_VENDOR_MODULE := true 9 | 10 | LOCAL_CFLAGS += -DGL_GLEXT_PROTOTYPES -DEGL_EGLEXT_PROTOTYPES 11 | 12 | LOCAL_CFLAGS += -DROCKCHIP_GPU_LIB_ENABLE 13 | 14 | LOCAL_CFLAGS += -Wall -Werror -Wunreachable-code 15 | 16 | LOCAL_C_INCLUDES += external/tinyalsa/include 17 | 18 | LOCAL_C_INCLUDES += hardware/rockchip/librga 19 | LOCAL_C_INCLUDES += hardware/rk29/librga \ 20 | system/core \ 21 | system/core/include/utils \ 22 | system/core/liblog/include \ 23 | $(LOCAL_PATH)/../.. \ 24 | $(LOCAL_PATH)/../../include 25 | 26 | LOCAL_SHARED_LIBRARIES := \ 27 | libcutils \ 28 | liblog \ 29 | libutils \ 30 | libui \ 31 | libEGL \ 32 | libGLESv1_CM \ 33 | libhardware \ 34 | librga 35 | 36 | LOCAL_HEADER_LIBRARIES += \ 37 | libutils_headers \ 38 | libcutils_headers \ 39 | libhardware_headers \ 40 | liblog_headers \ 41 | libgui_headers \ 42 | libbinder_headers 43 | 44 | #has no "external/stlport" from Android 6.0 on 45 | ifeq (1,$(strip $(shell expr $(PLATFORM_VERSION) \< 6.0))) 46 | LOCAL_C_INCLUDES += \ 47 | external/stlport/stlport 48 | 49 | LOCAL_C_INCLUDES += bionic 50 | endif 51 | 52 | #ifeq ($(strip $(BOARD_USE_DRM)), true) 53 | #ifneq (1,$(strip $(shell expr $(PLATFORM_VERSION) \< 6.9))) 54 | LOCAL_CFLAGS += -DANDROID_7_DRM -DANDROID 55 | #endif 56 | #endif 57 | 58 | ifeq ($(strip $(TARGET_BOARD_PLATFORM)),rk3368) 59 | LOCAL_CFLAGS += -DRK3368 60 | endif 61 | 62 | ifneq (1,$(strip $(shell expr $(PLATFORM_VERSION) \< 8.0))) 63 | LOCAL_CFLAGS += -DANDROID_8 64 | endif 65 | 66 | ifeq ($(strip $(TARGET_BOARD_PLATFORM)),rk3188) 67 | LOCAL_CFLAGS += -DRK3188 68 | endif 69 | 70 | LOCAL_SRC_FILES:= \ 71 | rgaTestCache.cpp 72 | 73 | LOCAL_MODULE:= rgaTestCache 74 | 75 | ifdef TARGET_32_BIT_SURFACEFLINGER 76 | LOCAL_32_BIT_ONLY := true 77 | endif 78 | 79 | include $(BUILD_EXECUTABLE) 80 | 81 | -------------------------------------------------------------------------------- /samples/rgaTestCache/rgaTestCache.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Rockchip Electronics Co., Ltd. 3 | * Authors: 4 | * Zhiqin Wei 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #define LOG_NDEBUG 0 20 | #define LOG_TAG "rgaTestCache" 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | #include 50 | #include 51 | #include 52 | #include 53 | 54 | #include 55 | #include 56 | #include 57 | #include 58 | 59 | #ifndef ANDROID_8 60 | #include 61 | #endif 62 | 63 | #include "RockchipRga.h" 64 | #include "RgaUtils.h" 65 | 66 | /////////////////////////////////////////////////////// 67 | 68 | using namespace android; 69 | 70 | int main() { 71 | int ret = 0; 72 | int srcWidth,srcHeight,srcFormat; 73 | int dstWidth,dstHeight,dstFormat; 74 | 75 | void *src = NULL; 76 | void *dst = NULL; 77 | void *src2 = NULL; 78 | void *dst2 = NULL; 79 | 80 | /********** SrcInfo set **********/ 81 | srcWidth = 1280; 82 | srcHeight = 720; 83 | srcFormat = HAL_PIXEL_FORMAT_RGBA_8888; 84 | 85 | /********** DstInfo set **********/ 86 | dstWidth = 1280; 87 | dstHeight = 720; 88 | dstFormat = HAL_PIXEL_FORMAT_RGBA_8888; 89 | 90 | /********** apply for src_buffer **********/ 91 | #ifdef ANDROID_7_DRM 92 | sp gbs(new GraphicBuffer(srcWidth,srcHeight,srcFormat, 93 | GRALLOC_USAGE_SW_WRITE_OFTEN | GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_HW_FB)); 94 | #else 95 | sp gbs(new GraphicBuffer(srcWidth,srcHeight,srcFormat, 96 | GRALLOC_USAGE_SW_WRITE_OFTEN | GRALLOC_USAGE_SW_READ_OFTEN)); 97 | #endif 98 | 99 | if (gbs->initCheck()) { 100 | printf("GraphicBuffer_src1 error : %s\n",strerror(errno)); 101 | return ret; 102 | } else 103 | printf("GraphicBuffer_src1 ok \n"); 104 | 105 | #ifdef ANDROID_7_DRM 106 | sp gbs2(new GraphicBuffer(srcWidth,srcHeight,srcFormat, 107 | GRALLOC_USAGE_SW_WRITE_OFTEN | GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_HW_FB)); 108 | #else 109 | sp gbs2(new GraphicBuffer(srcWidth,srcHeight,srcFormat, 110 | GRALLOC_USAGE_SW_WRITE_OFTEN | GRALLOC_USAGE_SW_READ_OFTEN)); 111 | #endif 112 | if (gbs2->initCheck()) { 113 | printf("GraphicBuffer_src2 error : %s\n",strerror(errno)); 114 | return ret; 115 | } else 116 | printf("GraphicBuffer_src2 ok\n"); 117 | 118 | /********** write data to src_buffer or init buffer**********/ 119 | ret = gbs->lock(GRALLOC_USAGE_SW_WRITE_OFTEN | GRALLOC_USAGE_SW_READ_OFTEN, (void**)&src); 120 | if (ret) { 121 | printf("lock buffer_src1 error : %s\n",strerror(errno)); 122 | return ret; 123 | } else 124 | printf("lock buffer_src1 ok\n"); 125 | 126 | char* buf = (char *)src; 127 | 128 | struct timeval tpend1, tpend2; 129 | long usec1 = 0; 130 | //gettimeofday(&tpend1, NULL); 131 | 132 | memset(buf,0x00,4*1280*720); 133 | 134 | //gettimeofday(&tpend2, NULL); 135 | //usec1 = 1000000 * (tpend2.tv_sec - tpend1.tv_sec) + (tpend2.tv_usec - tpend1.tv_usec); 136 | //printf("gralloc_cost_time=%ld us\n", usec1); 137 | ret = gbs->unlock(); 138 | if (ret) { 139 | printf("unlock buffer_src1 error : %s\n",strerror(errno)); 140 | return ret; 141 | } else 142 | printf("unlock buffer_src1 %s \n","ok"); 143 | 144 | /********** write data to src_buffer or init buffer**********/ 145 | ret = gbs2->lock(GRALLOC_USAGE_SW_WRITE_OFTEN | GRALLOC_USAGE_SW_READ_OFTEN, (void**)&src2); 146 | if (ret) { 147 | printf("lock buffer_src2 error : %s\n",strerror(errno)); 148 | return ret; 149 | } else 150 | printf("lock buffer_src2 ok : \n"); 151 | 152 | char* buf2 = (char *)src2; 153 | 154 | //usec1 = 0; 155 | //gettimeofday(&tpend1, NULL); 156 | 157 | memset(buf2,0x55,4*1280*720); 158 | 159 | //gettimeofday(&tpend2, NULL); 160 | //usec1 = 1000000 * (tpend2.tv_sec - tpend1.tv_sec) + (tpend2.tv_usec - tpend1.tv_usec); 161 | //printf("gralloc_cost_time=%ld us\n", usec1); 162 | ret = gbs->unlock(); 163 | if (ret) { 164 | printf("unlock buffer_src2 error : %s\n",strerror(errno)); 165 | return ret; 166 | } else 167 | printf("unlock buffer_src2 %s \n","ok"); 168 | 169 | printf("gralloc_buf1_address=%p \n", buf); 170 | printf("gralloc_buf2_address=%p \n", buf2); 171 | usleep(50); 172 | 173 | ret = gbs->lock(GRALLOC_USAGE_SW_WRITE_OFTEN | GRALLOC_USAGE_SW_READ_OFTEN, (void**)&src); 174 | if (ret) { 175 | printf("lock buffer_src error : %s\n",strerror(errno)); 176 | return ret; 177 | } else 178 | printf("lock buffer_src ok \n"); 179 | 180 | buf = (char *)src; 181 | 182 | ret = gbs2->lock(GRALLOC_USAGE_SW_WRITE_OFTEN | GRALLOC_USAGE_SW_READ_OFTEN, (void**)&src2); 183 | if (ret) { 184 | printf("lock buffer_src2 error : %s\n",strerror(errno)); 185 | return ret; 186 | } else 187 | printf("lock buffer_src2 ok\n"); 188 | 189 | buf2 = (char *)src2; 190 | 191 | usec1 = 0; 192 | gettimeofday(&tpend1, NULL); 193 | 194 | memcpy(buf,buf2,4*1280*720); 195 | 196 | gettimeofday(&tpend2, NULL); 197 | usec1 = 1000000 * (tpend2.tv_sec - tpend1.tv_sec) + (tpend2.tv_usec - tpend1.tv_usec); 198 | printf("<<<<<------ memcpy gralloc cost_time=%ld us ------>>>>>\n", usec1); 199 | 200 | ret = gbs->unlock(); 201 | if (ret) { 202 | printf("unlock buffer_src error : %s\n",strerror(errno)); 203 | return ret; 204 | } else 205 | printf("unlock buffer_src ok\n"); 206 | ret = gbs2->unlock(); 207 | if (ret) { 208 | printf("unlock buffer_src2 error : %s\n",strerror(errno)); 209 | return ret; 210 | } else 211 | printf("unlock buffer_src2 ok\n"); 212 | 213 | 214 | /********** apply for dst_buffer **********/ 215 | dst = malloc(dstWidth * dstHeight * 4); 216 | if (!dst) { 217 | free(src); 218 | return -ENOMEM; 219 | } 220 | dst2 = malloc(dstWidth * dstHeight * 4); 221 | if (!dst2) { 222 | free(src); 223 | return -ENOMEM; 224 | } 225 | 226 | /********** write data to dst_buffer or init buffer **********/ 227 | buf = (char *)dst; 228 | printf("malloc_address1=%p \n", buf); 229 | buf2 = (char *)dst2; 230 | printf("malloc_address2=%p \n", buf2); 231 | 232 | usec1 = 0; 233 | struct timeval tpend3, tpend4; 234 | //gettimeofday(&tpend3, NULL); 235 | 236 | memset(buf,0x00,4*1280*720); 237 | 238 | //gettimeofday(&tpend4, NULL); 239 | //usec1 = 1000000 * (tpend4.tv_sec - tpend3.tv_sec) + (tpend4.tv_usec - tpend3.tv_usec) ; 240 | //ALOGD("malloc_cost_time=%ld us\n", usec1); 241 | //printf("malloc_cost_time=%ld us\n", usec1); 242 | 243 | //usec1 = 0; 244 | //gettimeofday(&tpend3, NULL); 245 | 246 | memset(buf2,0x55,4*1280*720); 247 | 248 | //gettimeofday(&tpend4, NULL); 249 | //usec1 = 1000000 * (tpend4.tv_sec - tpend3.tv_sec) + (tpend4.tv_usec - tpend3.tv_usec) ; 250 | //printf("malloc_cost_time=%ld us\n", usec1); 251 | 252 | usec1 = 0; 253 | gettimeofday(&tpend3, NULL); 254 | 255 | memcpy(buf2,buf,4*1280*720); 256 | 257 | gettimeofday(&tpend4, NULL); 258 | usec1 = 1000000 * (tpend4.tv_sec - tpend3.tv_sec) + (tpend4.tv_usec - tpend3.tv_usec) ; 259 | printf("<<<<<------ memcpy malloc cost_time=%ld us ------>>>>>\n\n", usec1); 260 | 261 | free(dst); 262 | dst = NULL; 263 | buf = NULL; 264 | free(dst2); 265 | dst2 = NULL; 266 | buf2 = NULL; 267 | 268 | printf("threadloop\n"); 269 | usleep(500000); 270 | 271 | return 0; 272 | } 273 | -------------------------------------------------------------------------------- /samples/rgaUserSpace/Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH:= $(call my-dir) 2 | #====================================================================== 3 | # 4 | #rgaUserSpace 5 | # 6 | #====================================================================== 7 | include $(CLEAR_VARS) 8 | LOCAL_VENDOR_MODULE := true 9 | 10 | LOCAL_CFLAGS += -DGL_GLEXT_PROTOTYPES -DEGL_EGLEXT_PROTOTYPES 11 | 12 | LOCAL_CFLAGS += -DROCKCHIP_GPU_LIB_ENABLE 13 | 14 | LOCAL_CFLAGS += -Wall -Werror -Wunreachable-code 15 | 16 | LOCAL_C_INCLUDES += external/tinyalsa/include 17 | 18 | LOCAL_C_INCLUDES += hardware/rockchip/librga 19 | LOCAL_C_INCLUDES += hardware/rk29/librga \ 20 | system/core \ 21 | system/core/include/utils \ 22 | system/core/liblog/include \ 23 | $(LOCAL_PATH)/../.. \ 24 | $(LOCAL_PATH)/../../include 25 | 26 | LOCAL_SHARED_LIBRARIES := \ 27 | libcutils \ 28 | liblog \ 29 | libutils \ 30 | libui \ 31 | libEGL \ 32 | libGLESv1_CM \ 33 | libhardware \ 34 | librga 35 | 36 | LOCAL_HEADER_LIBRARIES += \ 37 | libutils_headers \ 38 | libcutils_headers \ 39 | libhardware_headers \ 40 | liblog_headers \ 41 | libgui_headers \ 42 | libbinder_headers 43 | 44 | #has no "external/stlport" from Android 6.0 on 45 | ifeq (1,$(strip $(shell expr $(PLATFORM_VERSION) \< 6.0))) 46 | LOCAL_C_INCLUDES += \ 47 | external/stlport/stlport 48 | 49 | LOCAL_C_INCLUDES += bionic 50 | endif 51 | 52 | #ifeq ($(strip $(BOARD_USE_DRM)), true) 53 | #ifneq (1,$(strip $(shell expr $(PLATFORM_VERSION) \< 6.9))) 54 | LOCAL_CFLAGS += -DANDROID_7_DRM -DANDROID 55 | #endif 56 | #endif 57 | 58 | ifeq ($(strip $(TARGET_BOARD_PLATFORM)),rk3368) 59 | LOCAL_CFLAGS += -DRK3368 60 | endif 61 | 62 | ifneq (1,$(strip $(shell expr $(PLATFORM_VERSION) \< 8.0))) 63 | LOCAL_CFLAGS += -DANDROID_8 64 | endif 65 | 66 | ifeq ($(strip $(TARGET_BOARD_PLATFORM)),rk3188) 67 | LOCAL_CFLAGS += -DRK3188 68 | endif 69 | 70 | LOCAL_SRC_FILES:= \ 71 | rgaUserSpace.cpp 72 | 73 | LOCAL_MODULE:= rgaUserSpace 74 | 75 | ifdef TARGET_32_BIT_SURFACEFLINGER 76 | LOCAL_32_BIT_ONLY := true 77 | endif 78 | 79 | include $(BUILD_EXECUTABLE) 80 | 81 | -------------------------------------------------------------------------------- /samples/rgaUserSpace/rgaUserSpace.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Rockchip Electronics Co., Ltd. 3 | * Authors: 4 | * Zhiqin Wei 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #define LOG_NDEBUG 0 20 | #define LOG_TAG "rgaUserSpace" 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | #include 50 | #include 51 | #include 52 | #include 53 | 54 | #include 55 | #include 56 | #include 57 | #include 58 | 59 | #ifndef ANDROID_8 60 | #include 61 | #endif 62 | 63 | #include "RockchipRga.h" 64 | #include "RgaUtils.h" 65 | 66 | /////////////////////////////////////////////////////// 67 | 68 | using namespace android; 69 | 70 | int main() { 71 | int ret = 0; 72 | int srcWidth,srcHeight,srcFormat; 73 | int dstWidth,dstHeight,dstFormat; 74 | 75 | void *src = NULL; 76 | void *dst = NULL; 77 | 78 | srcWidth = 1280; 79 | srcHeight = 720; 80 | srcFormat = HAL_PIXEL_FORMAT_RGBA_8888; 81 | 82 | dstWidth = 1280; 83 | dstHeight = 720; 84 | dstFormat = HAL_PIXEL_FORMAT_RGBA_8888; 85 | 86 | /********** apply for buffer **********/ 87 | src = malloc(srcWidth * srcHeight * 4); 88 | if (!src) 89 | return -ENOMEM; 90 | 91 | /********** apply for buffer **********/ 92 | dst = malloc(dstWidth * dstHeight * 4); 93 | if (!dst) { 94 | free(src); 95 | return -ENOMEM; 96 | } 97 | 98 | RockchipRga& rkRga(RockchipRga::get()); 99 | 100 | /********** get data to src_buffer or init buffer**********/ 101 | char* buf = (char *)src; 102 | #if 1 103 | get_buf_from_file(buf, srcFormat, srcWidth, srcHeight, 1); 104 | #else 105 | memset(buf,0x55,4*1280*720); 106 | #endif 107 | 108 | /********** get data to dst_buffer or init buffer **********/ 109 | buf = (char *)dst; 110 | #if 1 111 | get_buf_from_file(buf, srcFormat, srcWidth, srcHeight, 0); 112 | #else 113 | memset(buf,0x00,4*1280*720); 114 | #endif 115 | 116 | while(1) { 117 | /********** rga_info_t Init **********/ 118 | rga_info_t rgasrc; 119 | rga_info_t rgadst; 120 | 121 | memset(&rgasrc, 0, sizeof(rga_info_t)); 122 | rgasrc.fd = -1; 123 | rgasrc.mmuFlag = 1; 124 | rgasrc.virAddr = src; 125 | 126 | memset(&rgadst, 0, sizeof(rga_info_t)); 127 | rgadst.fd = -1; 128 | rgadst.mmuFlag = 1; 129 | rgadst.virAddr = dst; 130 | 131 | /********** set the rect_info **********/ 132 | rga_set_rect(&rgasrc.rect, 0,0,srcWidth,srcHeight,srcWidth/*stride*/,srcHeight,srcFormat); 133 | rga_set_rect(&rgadst.rect, 0,0,dstWidth,dstHeight,dstWidth/*stride*/,dstHeight,dstFormat); 134 | 135 | /************ set the rga_mod ,rotation\composition\scale\copy .... **********/ 136 | rgasrc.blend = 0xff0105; 137 | 138 | /********** call rga_Interface **********/ 139 | struct timeval tpend1, tpend2; 140 | long usec1 = 0; 141 | gettimeofday(&tpend1, NULL); 142 | ret = rkRga.RkRgaBlit(&rgasrc, &rgadst, NULL); 143 | gettimeofday(&tpend2, NULL); 144 | usec1 = 1000 * (tpend2.tv_sec - tpend1.tv_sec) + (tpend2.tv_usec - tpend1.tv_usec) / 1000; 145 | printf("cost_time=%ld ms\n", usec1); 146 | 147 | if (ret) { 148 | printf("rgaFillColor error : %s\n", 149 | strerror(errno)); 150 | } 151 | 152 | { 153 | /********** output buf data to file **********/ 154 | char* dstbuf = (char *)dst; 155 | output_buf_data_to_file(dstbuf, dstFormat, dstWidth, dstHeight, 0); 156 | } 157 | printf("threadloop\n"); 158 | usleep(500000); 159 | break; 160 | } 161 | return 0; 162 | } 163 | -------------------------------------------------------------------------------- /samples/sample_file/README.txt: -------------------------------------------------------------------------------- 1 | 使用示例图片时,Android系统须将源图片存储在设备/data/目录下,Linux系统须将源图储存在设备/usr/data目录下。 2 | 命名规则如下,输入文件为 in , 输出文件为 out: 3 | --->第一个%d 是文件的索引, 一般为 0, 用于区别格式及宽高完全相同的文件 4 | --->第二个%d 是宽的意思, 这里的宽一般指虚宽 5 | --->第三个%d 是高的意思, 这里的高一般指虚高 6 | --->第四个%s 是格式的名字。 7 | 8 | 示例图片:in0w1280-h720-rgba8888.bin 9 | 分辨率:1280×720 10 | 格式 :RGBA8888 11 | 描述 :除logo外为全透明。 12 | 13 | 示例图片:in1w1280-h720-rgba8888.bin 14 | 分辨率:1280×720 15 | 格式 :RGBA8888 16 | 描述 :全不透明。 17 | 18 | 19 | 更加详尽的使用测试用例方法以及API说明请至librga/docs/README.md查看。 -------------------------------------------------------------------------------- /samples/sample_file/in0w1280-h720-rgba8888.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lihuang1111/linux-rga/cec3dbb1d490c034d55abf47e3d0a076888f7666/samples/sample_file/in0w1280-h720-rgba8888.bin -------------------------------------------------------------------------------- /samples/sample_file/in1w1280-h720-rgba8888.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lihuang1111/linux-rga/cec3dbb1d490c034d55abf47e3d0a076888f7666/samples/sample_file/in1w1280-h720-rgba8888.bin -------------------------------------------------------------------------------- /version.h.in: -------------------------------------------------------------------------------- 1 | #ifndef _rk_graphics_version_h_ 2 | #define _rk_graphics_version_h_ 3 | 4 | #define RK_GRAPHICS_VER "@VCS_TAG@" 5 | 6 | #endif //_rk_graphics_version_h_ 7 | -------------------------------------------------------------------------------- /version.h.template: -------------------------------------------------------------------------------- 1 | #ifndef _rk_graphics_version_h_ 2 | #define _rk_graphics_version_h_ 3 | 4 | #define RK_GRAPHICS_VER "version:$FULL_VERSION" 5 | 6 | #endif // VERSION_H 7 | -------------------------------------------------------------------------------- /version.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | rm -f version.h 3 | 4 | COMMIT_ID=$(cd $(dirname $0) && git log -1 | awk 'NR==1{print}') 5 | SUB_COMMIT_ID=$(echo "$COMMIT_ID" | cut -c8-14) 6 | CUR_TIME=$(date "+%G-%m-%d %H:%M:%S") 7 | RK_GRAPHICS_VERSION=$SUB_COMMIT_ID+"$CUR_TIME" 8 | 9 | cd $(dirname $0) && cat version.h.template | sed "s/\$FULL_VERSION/$RK_GRAPHICS_VERSION/g" > version.h 10 | echo "Generated version.h" 11 | --------------------------------------------------------------------------------