Files
Shivansps 1d0dd687cd Android Build (#6992)
* android build support

* Update es_compatibility.h

* Support reporting flags in android

* include pref_path in json v2

* add vulkan headers

* shaderc includes

* remove headers

* force use prebuilt vulkan

* fix vulkan inverted screen

* fix find sdl3 precompiled android

* Update CMakeLists.txt

* replace sdl2 android function names for sdl3 versions

* change sdl includes in osapi

* fix sdl3 includes, again

* rename function to sdl3 name

* remove unused definition

* copy libshaderc_shared.so to output in android

* do not look for vulkan-loader in android

* revert changes to SDL2.cmake

* add comment to vulkan pretransform setup

* cleanup maxsize function

* rename new android functions in osapi

* android trap back button

* Remove calculate_max_resize_max_size

* touch ui opacity control

* change opacity control to int

* fix opacity slider

* Corrected android working folder fallback and set borderless mode as default

* Implement shared helper for JNI calls

* Add version tag and sha256 to android prebuilt libs

* vulkan android check eSuboptimal

* An already requested rebuild also avoids redundant Android surface queries

* add cache bool to cmakelist

* set string ids
2026-11-05 20:56:36 +01:00

143 lines
3.3 KiB
C++

#ifndef EXTERNALCODE_H_INCLUDED_
#define EXTERNALCODE_H_INCLUDED_
#include "globalincs/pstypes.h"
/* This class loads external libraries for FSO use.
* Uses SDL to do the actual loading so this should be supported on most platforms
*/
class SCP_ExternalCode
{
public:
SCP_ExternalCode( )
: m_library(NULL)
{
}
virtual ~SCP_ExternalCode()
{
if (m_library)
SDL_UnloadObject(m_library);
}
protected:
bool LoadExternal( const char* externlib, const char* basePath = nullptr )
{
if ( !externlib )
return FALSE;
m_library = SDL_LoadObject(externlib);
#ifdef __ANDROID__
if (m_library == NULL) {
auto android_path = SDL_GetAndroidInternalStoragePath();
if (android_path != nullptr) {
SCP_string android_full_path = android_path;
if (android_full_path.back() != DIR_SEPARATOR_CHAR) {
android_full_path += DIR_SEPARATOR_CHAR;
}
android_full_path += SCP_string("natives") + DIR_SEPARATOR_CHAR + externlib;
#ifndef NDEBUG
mprintf(("Calling SDL_LoadObject with the following path: '%s'\n", android_full_path.c_str()));
#endif
m_library = SDL_LoadObject(android_full_path.c_str());
}
}
#endif
// check full path as a fallback for our own libraries
// NOTE: basePath is assumed to have a trailing slash!
if ( !m_library && basePath )
{
SCP_string fullpath = basePath;
fullpath += externlib;
m_library = SDL_LoadObject(fullpath.c_str());
}
#ifndef NDEBUG
if (m_library == NULL)
{
mprintf(("Failed to load library '%s': '%s'\n", externlib, SDL_GetError()));
}
#endif
return m_library != NULL;
}
void* LoadFunction(const char* functionname)
{
if (m_library != NULL && functionname != NULL)
{
void* func = reinterpret_cast<void *>(SDL_LoadFunction(m_library, functionname));
#ifndef NDEBUG
if (func == NULL)
{
mprintf(("Failed to load function '%s': '%s'\n", functionname, SDL_GetError()));
}
#endif
return func;
}
return NULL;
}
template<class FuncType>
FuncType LoadFunction(const char* functionname)
{
return reinterpret_cast<FuncType>(LoadFunction(functionname));
}
private:
SDL_SharedObject* m_library;
};
/* These are available if you're compiling an external DLL
* So far we have trackir, and speech is on the way
*/
#ifdef _WIN32
# define SCP_EXT_CALLCONV __cdecl
# ifdef SCPDLL_EXTERNAL_LIB
# define SCPDLL_EXTERNAL __declspec( dllexport )
# else
# define SCPDLL_EXTERNAL __declspec( dllimport )
# endif
/* Must be in a CPP file in your DLL code
* If you want to write your own, you shouldn't.
*/
# define SCPDLL_DLLMAIN( ) \
SCP_EXTERN_C BOOL APIENTRY DllMain( HANDLE, DWORD, LPVOID ) { return TRUE; }
#else
# define SCP_EXT_CALLCONV
# define SCPDLL_EXTERNAL
# define SCPDLL_DLLMAIN( )
#endif
#ifdef __cplusplus
# define SCP_EXTERN_C extern "C"
#else
# define SCP_EXTERN_C
#endif
/* Version information */
typedef struct _SCPDLL_Version
{
int major;
int minor;
int patch;
} SCPDLL_Version;
typedef int (SCP_EXT_CALLCONV *SCPDLL_PFVERSION)(SCPDLL_Version*);
/* Must be in a CPP file in your DLL code */
#define SCPDLL_VERSION_FUNCTION( Major, Minor, Patch ) \
SCP_EXTERN_C int SCPDLL_EXTERNAL SCPDLL_GetVersion( SCPDLL_Version* v ) { \
if ( !v ) return -1;\
v->major = Major; v->minor = Minor; v->patch = Patch;\
return 0; }
#endif /* EXTERNALCODE_H_INCLUDED_ */