From 09e66adadcdec001dc043c4e2b7161ff86912243 Mon Sep 17 00:00:00 2001 From: Alexander Smorkalov Date: Fri, 23 Aug 2013 17:37:43 +0400 Subject: [PATCH] New Tegra detector with Android 4.3 support added. Manager version++. (cherry picked from commit aa00b5a0ab3d7289af8ab2006f8521fd3ed17e92) Conflicts: platforms/android/service/engine/jni/BinderComponent/TegraDetector.cpp --- .../service/engine/AndroidManifest.xml | 4 +- .../android/service/engine/CMakeLists.txt | 33 ++++++++-- .../jni/BinderComponent/HardwareDetector.cpp | 9 ++- .../jni/BinderComponent/TegraDetector.cpp | 61 ------------------- .../jni/BinderComponent/TegraDetector.h | 9 ++- .../org/opencv/engine/HardwareDetector.java | 11 ++-- .../engine/manager/ManagerActivity.java | 4 ++ 7 files changed, 52 insertions(+), 79 deletions(-) delete mode 100644 platforms/android/service/engine/jni/BinderComponent/TegraDetector.cpp diff --git a/platforms/android/service/engine/AndroidManifest.xml b/platforms/android/service/engine/AndroidManifest.xml index 8eb06689c7..dc992b3a62 100644 --- a/platforms/android/service/engine/AndroidManifest.xml +++ b/platforms/android/service/engine/AndroidManifest.xml @@ -1,8 +1,8 @@ + android:versionCode="210@ANDROID_PLATFORM_VERSION_CODE@" + android:versionName="2.10" > diff --git a/platforms/android/service/engine/CMakeLists.txt b/platforms/android/service/engine/CMakeLists.txt index 852a028cab..b1cac9383c 100644 --- a/platforms/android/service/engine/CMakeLists.txt +++ b/platforms/android/service/engine/CMakeLists.txt @@ -26,19 +26,32 @@ endif() configure_file("${CMAKE_CURRENT_SOURCE_DIR}/${ANDROID_MANIFEST_FILE}" "${OpenCV_BINARY_DIR}/platforms/android/service/engine/.build/${ANDROID_MANIFEST_FILE}" @ONLY) -link_directories("${ANDROID_SOURCE_TREE}/out/target/product/generic/system/lib" "${ANDROID_SOURCE_TREE}/out/target/product/${ANDROID_PRODUCT}/system/lib" "${ANDROID_SOURCE_TREE}/bin/${ANDROID_ARCH_NAME}") +link_directories( + "${ANDROID_SOURCE_TREE}/out/target/product/generic/system/lib" + "${ANDROID_SOURCE_TREE}/out/target/product/${ANDROID_PRODUCT}/system/lib" + "${ANDROID_SOURCE_TREE}/bin/${ANDROID_ARCH_NAME}") + +file(GLOB engine_files "jni/BinderComponent/*.cpp" "jni/BinderComponent/*.h" "jni/include/*.h") +set(engine_libs "z" "binder" "log" "utils") + +if (TEGRA_DETECTOR) + if (ANDROID_NATIVE_API_LEVEL GREATER 8) + add_definitions(-DUSE_TEGRA_HW_DETECTOR) + list(APPEND engine_libs ${TEGRA_DETECTOR} GLESv2 EGL) + else() + message(FATAL_ERROR "Tegra detector required native api level 9 or above") + endif() +endif() # -D__SUPPORT_ARMEABI_FEATURES key is also available add_definitions(-DPLATFORM_ANDROID -D__SUPPORT_ARMEABI_V7A_FEATURES -D__SUPPORT_TEGRA3 -D__SUPPORT_MIPS) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti -fno-exceptions") - set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-allow-shlib-undefined") -file(GLOB engine_files "jni/BinderComponent/*.cpp" "jni/BinderComponent/*.h" "jni/include/*.h") -include_directories(jni/BinderComponent jni/include) +include_directories("jni/BinderComponent" "jni/include") include_directories(SYSTEM "${ANDROID_SOURCE_TREE}/frameworks/base/include" "${ANDROID_SOURCE_TREE}/system/core/include") add_library(${engine} SHARED ${engine_files}) -target_link_libraries(${engine} z binder log utils) +target_link_libraries(${engine} ${engine_libs}) set_target_properties(${engine} PROPERTIES OUTPUT_NAME ${engine} @@ -51,7 +64,15 @@ add_custom_command(TARGET ${engine} POST_BUILD COMMAND ${CMAKE_STRIP} --strip-un file(GLOB engine_jni_files "jni/JNIWrapper/*.cpp" "jni/JNIWrapper/*.h" "jni/include/*.h") list(APPEND engine_jni_files jni/NativeService/CommonPackageManager.cpp jni/NativeService/PackageInfo.cpp) -include_directories(jni/include jni/JNIWrapper jni/NativeService jni/BinderComponent "${ANDROID_SOURCE_TREE}/frameworks/base/include" "${ANDROID_SOURCE_TREE}/system/core/include" "${ANDROID_SOURCE_TREE}/frameworks/base/core/jni") +include_directories( + jni/include jni/JNIWrapper + jni/NativeService + jni/BinderComponent + "${ANDROID_SOURCE_TREE}/frameworks/base/include" + "${ANDROID_SOURCE_TREE}/system/core/include" + "${ANDROID_SOURCE_TREE}/frameworks/base/core/jni" + ) + add_library(${engine}_jni SHARED ${engine_jni_files}) target_link_libraries(${engine}_jni z binder log utils android_runtime ${engine}) diff --git a/platforms/android/service/engine/jni/BinderComponent/HardwareDetector.cpp b/platforms/android/service/engine/jni/BinderComponent/HardwareDetector.cpp index eab49ac5f3..d0d8514b74 100644 --- a/platforms/android/service/engine/jni/BinderComponent/HardwareDetector.cpp +++ b/platforms/android/service/engine/jni/BinderComponent/HardwareDetector.cpp @@ -13,7 +13,7 @@ int GetCpuID() map cpu_info = GetCpuInfo(); map::const_iterator it; - #if defined(__i386__) +#if defined(__i386__) LOGD("Using X86 HW detector"); result |= ARCH_X86; it = cpu_info.find("flags"); @@ -161,8 +161,11 @@ int GetProcessorCount() int DetectKnownPlatforms() { +#if defined(__arm__) && defined(USE_TEGRA_HW_DETECTOR) int tegra_status = DetectTegra(); - +#else + int tegra_status = NOT_TEGRA; +#endif // All Tegra platforms since Tegra3 if (2 < tegra_status) { @@ -172,4 +175,4 @@ int DetectKnownPlatforms() { return PLATFORM_UNKNOWN; } -} \ No newline at end of file +} diff --git a/platforms/android/service/engine/jni/BinderComponent/TegraDetector.cpp b/platforms/android/service/engine/jni/BinderComponent/TegraDetector.cpp deleted file mode 100644 index 3933efe499..0000000000 --- a/platforms/android/service/engine/jni/BinderComponent/TegraDetector.cpp +++ /dev/null @@ -1,61 +0,0 @@ -#include "TegraDetector.h" -#include -#include - -#define KERNEL_CONFIG "/proc/config.gz" -#define KERNEL_CONFIG_MAX_LINE_WIDTH 512 -#define KERNEL_CONFIG_TEGRA_MAGIC "CONFIG_ARCH_TEGRA=y" -#define KERNEL_CONFIG_TEGRA2_MAGIC "CONFIG_ARCH_TEGRA_2x_SOC=y" -#define KERNEL_CONFIG_TEGRA3_MAGIC "CONFIG_ARCH_TEGRA_3x_SOC=y" -#define KERNEL_CONFIG_TEGRA4_MAGIC "CONFIG_ARCH_TEGRA_11x_SOC=y" -#define MAX_DATA_LEN 4096 - -int DetectTegra() -{ - int result = TEGRA_NOT_TEGRA; - gzFile kernelConfig = gzopen(KERNEL_CONFIG, "r"); - if (kernelConfig != 0) - { - char tmpbuf[KERNEL_CONFIG_MAX_LINE_WIDTH]; - const char *tegra_config = KERNEL_CONFIG_TEGRA_MAGIC; - const char *tegra2_config = KERNEL_CONFIG_TEGRA2_MAGIC; - const char *tegra3_config = KERNEL_CONFIG_TEGRA3_MAGIC; - const char *tegra4_config = KERNEL_CONFIG_TEGRA4_MAGIC; - int len = strlen(tegra_config); - int len2 = strlen(tegra2_config); - int len3 = strlen(tegra3_config); - int len4 = strlen(tegra4_config); - while (0 != gzgets(kernelConfig, tmpbuf, KERNEL_CONFIG_MAX_LINE_WIDTH)) - { - if (0 == strncmp(tmpbuf, tegra_config, len)) - { - result = 1; - } - - if (0 == strncmp(tmpbuf, tegra2_config, len2)) - { - result = 2; - break; - } - - if (0 == strncmp(tmpbuf, tegra3_config, len3)) - { - result = 3; - break; - } - - if (0 == strncmp(tmpbuf, tegra4_config, len4)) - { - result = 4; - break; - } - } - gzclose(kernelConfig); - } - else - { - result = TEGRA_DETECTOR_ERROR; - } - - return result; -} \ No newline at end of file diff --git a/platforms/android/service/engine/jni/BinderComponent/TegraDetector.h b/platforms/android/service/engine/jni/BinderComponent/TegraDetector.h index 8fbdb607a1..4ca930b754 100644 --- a/platforms/android/service/engine/jni/BinderComponent/TegraDetector.h +++ b/platforms/android/service/engine/jni/BinderComponent/TegraDetector.h @@ -2,8 +2,13 @@ #define __TEGRA_DETECTOR_H__ #define TEGRA_DETECTOR_ERROR -2 -#define TEGRA_NOT_TEGRA -1 +#define NOT_TEGRA -1 +#define TEGRA2 2 +#define TEGRA3 3 +#define TEGRA4i 4 +#define TEGRA4 5 +#define TEGRA5 6 int DetectTegra(); -#endif \ No newline at end of file +#endif diff --git a/platforms/android/service/engine/src/org/opencv/engine/HardwareDetector.java b/platforms/android/service/engine/src/org/opencv/engine/HardwareDetector.java index 7fc7e1ae8a..dc82ec30cc 100644 --- a/platforms/android/service/engine/src/org/opencv/engine/HardwareDetector.java +++ b/platforms/android/service/engine/src/org/opencv/engine/HardwareDetector.java @@ -30,11 +30,12 @@ public class HardwareDetector // GPU Acceleration options public static final int FEATURES_HAS_GPU = 0x010000; - public static final int PLATFORM_TEGRA = 1; - public static final int PLATFORM_TEGRA2 = 2; - public static final int PLATFORM_TEGRA3 = 3; - public static final int PLATFORM_TEGRA4 = 4; - + public static final int PLATFORM_TEGRA = 1; + public static final int PLATFORM_TEGRA2 = 2; + public static final int PLATFORM_TEGRA3 = 3; + public static final int PLATFORM_TEGRA4i = 4; + public static final int PLATFORM_TEGRA4 = 5; + public static final int PLATFORM_TEGRA5 = 6; public static final int PLATFORM_UNKNOWN = 0; diff --git a/platforms/android/service/engine/src/org/opencv/engine/manager/ManagerActivity.java b/platforms/android/service/engine/src/org/opencv/engine/manager/ManagerActivity.java index 3c1aac994a..e22f7b5298 100644 --- a/platforms/android/service/engine/src/org/opencv/engine/manager/ManagerActivity.java +++ b/platforms/android/service/engine/src/org/opencv/engine/manager/ManagerActivity.java @@ -107,6 +107,10 @@ public class ManagerActivity extends Activity { HardwarePlatformView.setText("Tegra 3"); } + else if (HardwareDetector.PLATFORM_TEGRA4i == Platfrom) + { + HardwarePlatformView.setText("Tegra 4i"); + } else { HardwarePlatformView.setText("Tegra 4"); -- GitLab