dl
dl_android.h
浏览该文件的文档.
1
12#pragma once
13
14#include "system/dl_platform.h"
15#if DL_PLATFORM == DL_PLATFORM_ANDROID
16#include <android/native_window_jni.h>
17#include <game-activity/native_app_glue/android_native_app_glue.h>
18#include <android/asset_manager_jni.h>
19#include <android/asset_manager.h>
20
21#include "io/dl_log.h"
22#include "base/dl_type_def.h"
23#include "system/dl_time.h"
24
25namespace dl
26{
27
28// 安卓输入事件处理
29int32_t Android_HandleInput(android_app* app);
30
31// 安卓事件处理
32bool Android_ProcessEvent(android_app* app);
33
34// 安卓app_cmd处理
35void Android_OnAppCmd(android_app *app, int32_t cmd);
36
39{
40 android_app* _app;
41 int _surfaceState;// 0.无效 1.安卓已创建,但未重置交换链 2.正常
42 Point _sizeWindow; // 0表示窗口未就绪
43 bool _bRequestDestroy;// 用户层的中止
44 bool _bPause;// Activity触发onPause等切换,会丢失surface
45 AndroidData(android_app* app):
46 _app{app},
49 _bRequestDestroy{false},
50 _bPause{false}
51 {}
52 void Init()
53 {
54 // 过滤器
55 android_app_set_key_event_filter(_app, NULL);
56 android_app_set_motion_event_filter(_app, NULL);
57
58 _app->onAppCmd = Android_OnAppCmd;
59 //app->activity->callbacks->onContentRectChanged = on_content_rect_changed;
60 _app->userData = this;
61
62 do
63 {
65 {
66 log_info0("Android app has been destroyed by the OS!");
67 return ;//ExitCode::Close;
68 }
69 } while (_surfaceState == 0);
70 }
71};
72extern AndroidData* g_android;
73
74// glfw接口安卓平台封装
75struct GLFWwindow{};
76struct GLFWmonitor{};
77
78inline bool glfwInit() { return true; }
79
80inline bool glfwWindowShouldClose(void *window)
81{
82 return g_android->_app->destroyRequested || g_android->_bRequestDestroy;
83}
84
85inline void glfwGetFramebufferSize(void *window, int *w, int *h)
86{
87 *w = g_android->_sizeWindow[0];
88 *h = g_android->_sizeWindow[1];
89}
90
91inline const char **glfwGetRequiredInstanceExtensions(uint32_t *count)
92{
93 static const char *ret[] = {
94 "VK_KHR_surface",
95 "VK_KHR_android_surface"
96 };
97 *count = 2;
98 return ret;
99}
100
101inline void glfwWaitEvents()
102{
104}
105
106inline void glfwDestroyWindow(void *window)
107{
108 // nothing to do
109}
110
111inline void glfwTerminate()
112{
113 // nothing to do
114}
115
116inline void glfwSetCursorPos(void *window, int x, int y)
117{
118 // nothing to do
119}
120
121inline void glfwSetWindowShouldClose(void *window, int)
122{
123 g_android->_bRequestDestroy = true;
124}
125
126inline void glfwSetClipboardString(void *, const char *)
127{
128 // todo
129}
130
131inline const char* glfwGetClipboardString(void *)
132{
133 return "glfwGetClipboardString not support!";
134}
135
136
137inline void glfwGetWindowSize(void *window, int *w, int *h)
138{
139 *w = g_android->_sizeWindow[0];
140 *h = g_android->_sizeWindow[1];
141}
142
143inline void glfwGetMonitorWorkarea(void *monitor, int *x, int *y, int *w, int *h)
144{
145 *x = 0;
146 *y = 0;
147 *w = g_android->_sizeWindow[0];
148 *h = g_android->_sizeWindow[1];
149}
150
151inline void glfwSetWindowPos(void *window, int x, int y)
152{
153 // nothing to do
154}
155
156inline void glfwPollEvents()
157{
159}
160
161}
162#endif
日志系统
平台宏
时间相关
通用类型定义
const char ** glfwGetRequiredInstanceExtensions(uint32_t *count)
void glfwWaitEvents()
bool Android_ProcessEvent(android_app *app)
void glfwSetCursorPos(void *window, int x, int y)
void glfwGetMonitorWorkarea(void *monitor, int *x, int *y, int *w, int *h)
void glfwSetWindowPos(void *window, int x, int y)
void Android_OnAppCmd(android_app *app, int32_t cmd)
void glfwPollEvents()
void glfwGetWindowSize(void *window, int *w, int *h)
void glfwGetFramebufferSize(void *window, int *w, int *h)
int32_t Android_HandleInput(android_app *app)
void log_info0(std::string_view str, const std::source_location location=std::source_location::current())
bool glfwInit()
void glfwSetWindowShouldClose(void *window, int)
const char * glfwGetClipboardString(void *)
AndroidData * g_android
void glfwSetClipboardString(void *, const char *)
void glfwTerminate()
bool glfwWindowShouldClose(void *window)
void glfwDestroyWindow(void *window)
Point2 Point
AndroidData(android_app *app)
android_app * _app