Files
dl_old/dl/system/dl_android.h
T

162 lines
3.4 KiB
C++

/**
* @file dl_android.h
* @brief 安卓相关
*
*
* @version 1.0
* @author lveyou
* @date 24-01-28
*
* @note
*/
#pragma once
#include "system/dl_platform.h"
#if DL_PLATFORM == DL_PLATFORM_ANDROID
#include <android/native_window_jni.h>
#include <game-activity/native_app_glue/android_native_app_glue.h>
#include <android/asset_manager_jni.h>
#include <android/asset_manager.h>
#include "io/dl_log.h"
#include "base/dl_type_def.h"
#include "system/dl_time.h"
namespace dl
{
// 安卓输入事件处理
int32_t Android_HandleInput(android_app* app);
// 安卓事件处理
bool Android_ProcessEvent(android_app* app);
// 安卓app_cmd处理
void Android_OnAppCmd(android_app *app, int32_t cmd);
//! 安卓平台特有句柄
struct AndroidData
{
android_app* _app;
int _surfaceState;// 0.无效 1.安卓已创建,但未重置交换链 2.正常
Point _sizeWindow; // 0表示窗口未就绪
bool _bRequestDestroy;// 用户层的中止
bool _bPause;// Activity触发onPause等切换,会丢失surface
AndroidData(android_app* app):
_app{app},
_surfaceState{0},
_sizeWindow{},
_bRequestDestroy{false},
_bPause{false}
{}
void Init()
{
// 过滤器
android_app_set_key_event_filter(_app, NULL);
android_app_set_motion_event_filter(_app, NULL);
_app->onAppCmd = Android_OnAppCmd;
//app->activity->callbacks->onContentRectChanged = on_content_rect_changed;
_app->userData = this;
do
{
if (!Android_ProcessEvent(_app))
{
log_info0("Android app has been destroyed by the OS!");
return ;//ExitCode::Close;
}
} while (_surfaceState == 0);
}
};
extern AndroidData* g_android;
// glfw接口安卓平台封装
struct GLFWwindow{};
struct GLFWmonitor{};
inline bool glfwInit() { return true; }
inline bool glfwWindowShouldClose(void *window)
{
return g_android->_app->destroyRequested || g_android->_bRequestDestroy;
}
inline void glfwGetFramebufferSize(void *window, int *w, int *h)
{
*w = g_android->_sizeWindow[0];
*h = g_android->_sizeWindow[1];
}
inline const char **glfwGetRequiredInstanceExtensions(uint32_t *count)
{
static const char *ret[] = {
"VK_KHR_surface",
"VK_KHR_android_surface"
};
*count = 2;
return ret;
}
inline void glfwWaitEvents()
{
Android_ProcessEvent(g_android->_app);
}
inline void glfwDestroyWindow(void *window)
{
// nothing to do
}
inline void glfwTerminate()
{
// nothing to do
}
inline void glfwSetCursorPos(void *window, int x, int y)
{
// nothing to do
}
inline void glfwSetWindowShouldClose(void *window, int)
{
g_android->_bRequestDestroy = true;
}
inline void glfwSetClipboardString(void *, const char *)
{
// todo
}
inline const char* glfwGetClipboardString(void *)
{
return "glfwGetClipboardString not support!";
}
inline void glfwGetWindowSize(void *window, int *w, int *h)
{
*w = g_android->_sizeWindow[0];
*h = g_android->_sizeWindow[1];
}
inline void glfwGetMonitorWorkarea(void *monitor, int *x, int *y, int *w, int *h)
{
*x = 0;
*y = 0;
*w = g_android->_sizeWindow[0];
*h = g_android->_sizeWindow[1];
}
inline void glfwSetWindowPos(void *window, int x, int y)
{
// nothing to do
}
inline void glfwPollEvents()
{
Android_ProcessEvent(g_android->_app);
}
}
#endif