diff --git a/renderdoc/CMakeLists.txt b/renderdoc/CMakeLists.txt index 61bdf3c3f..2b9fd7097 100644 --- a/renderdoc/CMakeLists.txt +++ b/renderdoc/CMakeLists.txt @@ -23,6 +23,7 @@ elseif(APPLE) list(APPEND RDOC_LIBRARIES PRIVATE m PRIVATE dl + PRIVATE log PRIVATE ${CMAKE_THREAD_LIBS_INIT}) elseif(UNIX) find_package(PkgConfig REQUIRED) diff --git a/renderdoc/driver/vulkan/vk_android.cpp b/renderdoc/driver/vulkan/vk_android.cpp index 234aac306..d0cbb218a 100644 --- a/renderdoc/driver/vulkan/vk_android.cpp +++ b/renderdoc/driver/vulkan/vk_android.cpp @@ -45,4 +45,7 @@ void VulkanReplay::OutputWindow::CreateSurface(VkInstance inst) void VulkanReplay::GetOutputWindowDimensions(uint64_t id, int32_t &w, int32_t &h) { + w = 500; + h = 500; // FIXME + RDCLOG("VulkanReplay::GetOutputWindowDimensions: %i, %i", w, h); } diff --git a/renderdoc/os/posix/posix_libentry.cpp b/renderdoc/os/posix/posix_libentry.cpp index 59c2c119d..8978d2377 100644 --- a/renderdoc/os/posix/posix_libentry.cpp +++ b/renderdoc/os/posix/posix_libentry.cpp @@ -43,7 +43,8 @@ void library_loaded() FileIO::GetExecutableFilename(curfile); if(curfile.find("/renderdoccmd") != string::npos || - curfile.find("/renderdocui") != string::npos || curfile.find("/qrenderdoc") != string::npos) + curfile.find("/renderdocui") != string::npos || curfile.find("/qrenderdoc") != string::npos || + curfile.find("/system/bin/app_process") != string::npos) { RDCDEBUG("Not creating hooks - in replay app"); diff --git a/renderdoccmd/CMakeLists.txt b/renderdoccmd/CMakeLists.txt index f0cb17603..c016ff6ed 100644 --- a/renderdoccmd/CMakeLists.txt +++ b/renderdoccmd/CMakeLists.txt @@ -4,6 +4,10 @@ set(libraries PRIVATE renderdoc) if(APPLE) list(APPEND sources renderdoccmd_apple.cpp) +elseif(ANDROID) + list(APPEND sources renderdoccmd_android.cpp) + include_directories(${ANDROID_NDK}/sources/android/native_app_glue) + list(APPEND libraries PRIVATE -llog -landroid) elseif(UNIX) list(APPEND sources renderdoccmd_linux.cpp) @@ -14,6 +18,10 @@ elseif(UNIX) list(APPEND libraries PRIVATE -lxcb) endif() -add_executable(renderdoccmd ${sources}) +if(ANDROID) + add_library(renderdoccmd SHARED ${sources}) +else() + add_executable(renderdoccmd ${sources}) +endif() target_include_directories(renderdoccmd ${includes}) target_link_libraries(renderdoccmd ${libraries}) diff --git a/renderdoccmd/android/AndroidManifest.xml b/renderdoccmd/android/AndroidManifest.xml new file mode 100644 index 000000000..5c32a8b5e --- /dev/null +++ b/renderdoccmd/android/AndroidManifest.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/renderdoccmd/android/src/org/renderdoc/renderdoccmd/Loader.java b/renderdoccmd/android/src/org/renderdoc/renderdoccmd/Loader.java new file mode 100644 index 000000000..f574f9889 --- /dev/null +++ b/renderdoccmd/android/src/org/renderdoc/renderdoccmd/Loader.java @@ -0,0 +1,10 @@ +package org.renderdoc.renderdoccmd; +import android.app.Activity; + +public class Loader extends android.app.NativeActivity +{ + /* load our native library */ + static { + System.loadLibrary("renderdoc"); + } +} diff --git a/renderdoccmd/renderdoccmd_android.cpp b/renderdoccmd/renderdoccmd_android.cpp new file mode 100644 index 000000000..f8e3bd57d --- /dev/null +++ b/renderdoccmd/renderdoccmd_android.cpp @@ -0,0 +1,121 @@ +/****************************************************************************** + * The MIT License (MIT) + * + * Copyright (c) 2016 Baldur Karlsson + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + ******************************************************************************/ + +#include + +#include +#include + +#include + +#include + +#include +#define ANativeActivity_onCreate __attribute__((visibility("default"))) ANativeActivity_onCreate +extern "C" { +#include +} + +#include +#define LOGCAT_TAG "renderdoc" + +using std::string; + +struct android_app *android_state; + +string GetUsername() +{ + return string("Username"); +} + +void DisplayRendererPreview(ReplayRenderer *renderer, TextureDisplay displayCfg) +{ + ANativeWindow *connectionScreenWindow = android_state->window; + + ReplayOutput *out = + ReplayRenderer_CreateOutput(renderer, connectionScreenWindow, eOutputType_TexDisplay); + + OutputConfig c = {eOutputType_TexDisplay}; + + ReplayOutput_SetOutputConfig(out, c); + ReplayOutput_SetTextureDisplay(out, displayCfg); + + for(int i = 0; i < 100; i++) + { + ReplayRenderer_SetFrameEvent(renderer, 10000000 + rand() % 1000, true); + + __android_log_print(ANDROID_LOG_INFO, LOGCAT_TAG, "Frame %i", i); + ReplayOutput_Display(out); + + usleep(100000); + } +} + +int renderdoccmd(int argc, char **argv); +void handle_cmd(android_app *app, int32_t cmd) +{ + switch(cmd) + { + case APP_CMD_INIT_WINDOW: + { + // The window is being shown, get it ready. + + __android_log_print(ANDROID_LOG_INFO, LOGCAT_TAG, + "APP_CMD_INIT_WINDOW: android_state->window: %p", android_state->window); + + char *argv[] = { + "renderdoccmd", "/sdcard/capture.rdc", + }; + int argc = sizeof(argv) / sizeof(argv[0]); + renderdoccmd(argc, argv); + break; + } + case APP_CMD_TERM_WINDOW: + // The window is being hidden or closed, clean it up. + // DeleteVulkan(); + break; + default: __android_log_print(ANDROID_LOG_INFO, LOGCAT_TAG, "event not handled: %d", cmd); + } +} + +void android_main(struct android_app *state) +{ + android_state = state; + android_state->onAppCmd = handle_cmd; + + __android_log_print(ANDROID_LOG_INFO, LOGCAT_TAG, "android_main android_state->window: %p", + android_state->window); + + // Used to poll the events in the main loop + int events; + android_poll_source *source; + do + { + if(ALooper_pollAll(1, nullptr, &events, (void **)&source) >= 0) + { + if(source != NULL) + source->process(android_state, source); + } + } while(android_state->destroyRequested == 0); +}