satdump/android/backend.cpp

90 lines
2.5 KiB
C++
Raw Normal View History

2023-12-31 11:11:36 -05:00
#include "backend.h"
2024-01-21 21:52:54 -05:00
extern struct android_app *g_App;
2023-12-31 11:11:36 -05:00
extern EGLDisplay g_EglDisplay;
extern EGLSurface g_EglSurface;
float funcDeviceScale()
{
JavaVM* java_vm = g_App->activity->vm;
JNIEnv* java_env = NULL;
jint jni_return = java_vm->GetEnv((void**)&java_env, JNI_VERSION_1_6);
if (jni_return == JNI_ERR)
throw std::runtime_error("Could not get JNI environement");
jni_return = java_vm->AttachCurrentThread(&java_env, NULL);
if (jni_return != JNI_OK)
throw std::runtime_error("Could not attach to thread");
jclass native_activity_clazz = java_env->GetObjectClass(g_App->activity->clazz);
if (native_activity_clazz == NULL)
throw std::runtime_error("Could not get MainActivity class");
jmethodID method_id = java_env->GetMethodID(native_activity_clazz, "get_dpi", "()F");
if (method_id == NULL)
throw std::runtime_error("Could not get methode ID");
jfloat jflt = java_env->CallFloatMethod(g_App->activity->clazz, method_id);
jni_return = java_vm->DetachCurrentThread();
if (jni_return != JNI_OK)
throw std::runtime_error("Could not detach from thread");
return jflt;
}
void funcRebuildFonts()
{
ImGui_ImplOpenGL3_DestroyFontsTexture();
ImGui_ImplOpenGL3_CreateFontsTexture();
}
2023-12-31 11:11:36 -05:00
void funcSetMousePos(int, int)
{
// Not implemented on Android
}
std::pair<int, int> funcBeginFrame()
{
2023-12-31 15:38:36 -05:00
// Get display dimensions
EGLint width, height;
eglQuerySurface(g_EglDisplay, g_EglSurface, EGL_WIDTH, &width);
eglQuerySurface(g_EglDisplay, g_EglSurface, EGL_HEIGHT, &height);
2023-12-31 11:11:36 -05:00
// Start the Dear ImGui frame
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplAndroid_NewFrame();
ImGui::NewFrame();
2023-12-31 15:38:36 -05:00
return { (int)width, (int)height };
2023-12-31 11:11:36 -05:00
}
void funcEndFrame()
{
ImGui::Render();
ImGuiIO& io = ImGui::GetIO();
glViewport(0, 0, (int)io.DisplaySize.x, (int)io.DisplaySize.y);
2024-01-21 14:57:41 -05:00
glClearColor(style::theme.frame_bg.Value.x, style::theme.frame_bg.Value.y, style::theme.frame_bg.Value.z, 1.0f);
2023-12-31 11:11:36 -05:00
glClear(GL_COLOR_BUFFER_BIT);
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
eglSwapBuffers(g_EglDisplay, g_EglSurface);
}
2023-12-31 11:46:40 -05:00
void funcSetIcon(uint8_t*, int, int)
2023-12-31 11:11:36 -05:00
{
// Not implemented on Android
}
void bindBackendFunctions()
{
backend::device_scale = funcDeviceScale();
backend::rebuildFonts = funcRebuildFonts;
2023-12-31 11:11:36 -05:00
backend::setMousePos = funcSetMousePos;
backend::beginFrame = funcBeginFrame;
backend::endFrame = funcEndFrame;
backend::setIcon = funcSetIcon;
2023-12-31 11:46:40 -05:00
}