diff options
| author | Lizzy Fleckenstein <lizzy@vlhl.dev> | 2026-03-31 01:30:36 +0200 |
|---|---|---|
| committer | Lizzy Fleckenstein <lizzy@vlhl.dev> | 2026-03-31 01:30:36 +0200 |
| commit | 8e2ff15dbd3fe70fe2b52397b1eaba3fe2d7a5e8 (patch) | |
| tree | 925fa596210d1a1f01e00e0743a643f4552e7a7a /tools/Vulkan-Tools/cube/android | |
| parent | 1f17b4df127bd280e50d93a46ae93df704adc2b0 (diff) | |
| parent | 90bf5bc4fd8bea0d300f6564af256a51a34124b8 (diff) | |
| download | usermoji-8e2ff15dbd3fe70fe2b52397b1eaba3fe2d7a5e8.tar.xz | |
add tools/Vulkan-Tools
Diffstat (limited to 'tools/Vulkan-Tools/cube/android')
| -rw-r--r-- | tools/Vulkan-Tools/cube/android/AndroidManifest.xml | 26 | ||||
| -rw-r--r-- | tools/Vulkan-Tools/cube/android/CMakeLists.txt | 57 | ||||
| -rw-r--r-- | tools/Vulkan-Tools/cube/android/android_util.cpp | 84 | ||||
| -rw-r--r-- | tools/Vulkan-Tools/cube/android/android_util.h | 32 |
4 files changed, 199 insertions, 0 deletions
diff --git a/tools/Vulkan-Tools/cube/android/AndroidManifest.xml b/tools/Vulkan-Tools/cube/android/AndroidManifest.xml new file mode 100644 index 00000000..fbec106d --- /dev/null +++ b/tools/Vulkan-Tools/cube/android/AndroidManifest.xml @@ -0,0 +1,26 @@ +<?xml version="1.0"?> +<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.VkCube" android:versionCode="1" android:versionName="1.0"> + + <!-- Allow this app to read and write files (for use by tracing libraries). --> + <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> + <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> + <uses-permission android:name="android.permission.INTERNET"/> + + <uses-sdk android:minSdkVersion="23" android:targetSdkVersion="23"/> + + <!-- This .apk has no Java code itself, so set hasCode to false. --> + <application android:label="VkCube" android:hasCode="false" android:debuggable='true'> + + <!-- Our activity is the built-in NativeActivity framework class. + This will take care of integrating with our NDK code. --> + <activity android:name="android.app.NativeActivity" android:label="VkCube" android:exported="true"> + <!-- Tell NativeActivity the name of or .so --> + <meta-data android:name="android.app.lib_name" android:value="VkCube"/> + <intent-filter> + <action android:name="android.intent.action.MAIN"/> + <category android:name="android.intent.category.LAUNCHER"/> + </intent-filter> + </activity> + </application> + +</manifest> diff --git a/tools/Vulkan-Tools/cube/android/CMakeLists.txt b/tools/Vulkan-Tools/cube/android/CMakeLists.txt new file mode 100644 index 00000000..af607a55 --- /dev/null +++ b/tools/Vulkan-Tools/cube/android/CMakeLists.txt @@ -0,0 +1,57 @@ +# ~~~ +# Copyright (c) 2023 Valve Corporation +# Copyright (c) 2023 LunarG, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ~~~ + +target_sources(vkcube PRIVATE + android_util.cpp + android_util.h +) + +target_include_directories(vkcube PRIVATE + . +) + +set_directory_properties(PROPERTIES "COMPILE_OPTIONS" "") # Disable compiler warnings for android glue + +set(native_app_glue_dir "${CMAKE_ANDROID_NDK}/sources/android/native_app_glue") + +if (NOT EXISTS ${native_app_glue_dir}) + message(FATAL_ERROR "Couldn't find Android Native Glue directory!") +endif() + +# https://stackoverflow.com/questions/57189936/compiling-native-app-glue-c-results-in-an-invalid-library-file/76963564#76963564 +add_library(android_glue OBJECT) + +target_include_directories(android_glue PUBLIC ${native_app_glue_dir}) +target_sources(android_glue PRIVATE + ${native_app_glue_dir}/android_native_app_glue.c + ${native_app_glue_dir}/android_native_app_glue.h +) + +set_target_properties(vkcube PROPERTIES OUTPUT_NAME "VkCube") + +target_link_libraries(vkcube + android_glue + log + android +) + +# https://stackoverflow.com/questions/76631917/cmake-how-to-install-shared-stl-libraries-for-android/76656492#76656492 +if ("${CMAKE_ANDROID_STL_TYPE}" MATCHES "shared") + file(READ "${CMAKE_ANDROID_NDK}/meta/abis.json" JSON_FILE) + string(JSON TRIPLE GET "${JSON_FILE}" "${CMAKE_ANDROID_ARCH_ABI}" "triple") + install(FILES "${CMAKE_SYSROOT}/usr/lib/${TRIPLE}/libc++_shared.so" DESTINATION "${CMAKE_INSTALL_LIBDIR}") +endif() diff --git a/tools/Vulkan-Tools/cube/android/android_util.cpp b/tools/Vulkan-Tools/cube/android/android_util.cpp new file mode 100644 index 00000000..173e8ab8 --- /dev/null +++ b/tools/Vulkan-Tools/cube/android/android_util.cpp @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2016 Google, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Relicensed from the WTFPL (http://www.wtfpl.net/faq/). + */ + +#include "android_util.h" +#include <android_native_app_glue.h> +#include <cassert> +#include <cstring> +#include <vector> +#include <string> +#include <sstream> +#include <stdlib.h> + +extern "C" { + +// Convert Intents to arg list, returning argc and argv +// Note that this C routine mallocs memory that the caller must free +char **get_args(struct android_app *app, const char *intent_extra_data_key, const char *appTag, int *count) { + std::vector<std::string> args; + JavaVM &vm = *app->activity->vm; + JNIEnv *p_env; + if (vm.AttachCurrentThread(&p_env, nullptr) != JNI_OK) return nullptr; + + JNIEnv &env = *p_env; + jobject activity = app->activity->clazz; + jmethodID get_intent_method = env.GetMethodID(env.GetObjectClass(activity), "getIntent", "()Landroid/content/Intent;"); + jobject intent = env.CallObjectMethod(activity, get_intent_method); + jmethodID get_string_extra_method = + env.GetMethodID(env.GetObjectClass(intent), "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;"); + jvalue get_string_extra_args; + get_string_extra_args.l = env.NewStringUTF(intent_extra_data_key); + jstring extra_str = static_cast<jstring>(env.CallObjectMethodA(intent, get_string_extra_method, &get_string_extra_args)); + + std::string args_str; + if (extra_str) { + const char *extra_utf = env.GetStringUTFChars(extra_str, nullptr); + args_str = extra_utf; + env.ReleaseStringUTFChars(extra_str, extra_utf); + env.DeleteLocalRef(extra_str); + } + + env.DeleteLocalRef(get_string_extra_args.l); + env.DeleteLocalRef(intent); + vm.DetachCurrentThread(); + + // split args_str + std::stringstream ss(args_str); + std::string arg; + while (std::getline(ss, arg, ' ')) { + if (!arg.empty()) args.push_back(arg); + } + + // Convert our STL results to C friendly constructs + assert(count != nullptr); + *count = args.size() + 1; + char **vector = (char **)malloc(*count * sizeof(char *)); + const char *appName = appTag ? appTag : (const char *)"appTag"; + + vector[0] = (char *)malloc(strlen(appName) * sizeof(char)); + strcpy(vector[0], appName); + + for (uint32_t i = 0; i < args.size(); i++) { + vector[i + 1] = (char *)malloc(strlen(args[i].c_str()) * sizeof(char)); + strcpy(vector[i + 1], args[i].c_str()); + } + + return vector; +} + +} // extern "C" diff --git a/tools/Vulkan-Tools/cube/android/android_util.h b/tools/Vulkan-Tools/cube/android/android_util.h new file mode 100644 index 00000000..e8966458 --- /dev/null +++ b/tools/Vulkan-Tools/cube/android/android_util.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2016 Google, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Relicensed from the WTFPL (http://www.wtfpl.net/faq/). + */ + +#ifndef ANDROID_UTIL_H +#define ANDROID_UTIL_H + +#ifdef __cplusplus +extern "C" { +#endif + +char **get_args(struct android_app *app, const char *intent_extra_data_key, const char *appTag, int *count); + +#ifdef __cplusplus +} +#endif + +#endif |
