2023-12-31 11:11:36 -05:00
|
|
|
#include "backend.h"
|
2024-03-14 12:39:41 -04:00
|
|
|
#include "core/exception.h"
|
2023-12-31 11:11:36 -05:00
|
|
|
|
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;
|
|
|
|
|
|
2024-01-21 17:30:00 -05:00
|
|
|
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)
|
2024-03-14 12:12:34 +01:00
|
|
|
throw satdump_exception("Could not get JNI environement");
|
2024-01-21 17:30:00 -05:00
|
|
|
|
|
|
|
|
jni_return = java_vm->AttachCurrentThread(&java_env, NULL);
|
|
|
|
|
if (jni_return != JNI_OK)
|
2024-03-14 12:12:34 +01:00
|
|
|
throw satdump_exception("Could not attach to thread");
|
2024-01-21 17:30:00 -05:00
|
|
|
|
|
|
|
|
jclass native_activity_clazz = java_env->GetObjectClass(g_App->activity->clazz);
|
|
|
|
|
if (native_activity_clazz == NULL)
|
2024-03-14 12:12:34 +01:00
|
|
|
throw satdump_exception("Could not get MainActivity class");
|
2024-01-21 17:30:00 -05:00
|
|
|
|
|
|
|
|
jmethodID method_id = java_env->GetMethodID(native_activity_clazz, "get_dpi", "()F");
|
|
|
|
|
if (method_id == NULL)
|
2024-03-14 12:12:34 +01:00
|
|
|
throw satdump_exception("Could not get methode ID");
|
2024-01-21 17:30:00 -05:00
|
|
|
|
|
|
|
|
jfloat jflt = java_env->CallFloatMethod(g_App->activity->clazz, method_id);
|
|
|
|
|
|
|
|
|
|
jni_return = java_vm->DetachCurrentThread();
|
|
|
|
|
if (jni_return != JNI_OK)
|
2024-03-14 12:12:34 +01:00
|
|
|
throw satdump_exception("Could not detach from thread");
|
2024-01-21 17:30:00 -05:00
|
|
|
|
|
|
|
|
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()
|
|
|
|
|
{
|
2024-01-21 17:30:00 -05:00
|
|
|
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
|
|
|
}
|