Diligent Engine API Reference: D:/GitHub/DiligentEngine/DiligentCore/External/Android/native_app_glue/android_native_app_glue.h Source File

Diligent Engine API Reference

android_native_app_glue.h
1 /*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 */
17
18 #ifndef _ANDROID_NATIVE_APP_GLUE_H
19 #define _ANDROID_NATIVE_APP_GLUE_H
20
21 #include <poll.h>
22 #include <pthread.h>
23 #include <sched.h>
24
25 #include <android/configuration.h>
26 #include <android/looper.h>
27 #include <android/native_activity.h>
28
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32
84 struct android_app;
85
90 struct android_poll_source {
91 // The identifier of this source. May be LOOPER_ID_MAIN or
92 // LOOPER_ID_INPUT.
93 int32_t id;
94
95 // The android_app this ident is associated with.
96 struct android_app* app;
97
98 // Function to call to perform the standard processing of data from
99 // this source.
100 void (*process)(struct android_app* app, struct android_poll_source* source);
101 };
102
111 struct android_app {
112 // The application can place a pointer to its own state object
113 // here if it likes.
114 void* userData;
115
116 // Fill this in with the function to process main app commands (APP_CMD_*)
117 void (*onAppCmd)(struct android_app* app, int32_t cmd);
118
119 // Fill this in with the function to process input events. At this point
120 // the event has already been pre-dispatched, and it will be finished upon
121 // return. Return 1 if you have handled the event, 0 for any default
122 // dispatching.
123 int32_t (*onInputEvent)(struct android_app* app, AInputEvent* event);
124
125 // The ANativeActivity object instance that this app is running in.
126 ANativeActivity* activity;
127
128 // The current configuration the app is running in.
129 AConfiguration* config;
130
131 // This is the last instance's saved state, as provided at creation time.
132 // It is NULL if there was no state. You can use this as you need; the
133 // memory will remain around until you call android_app_exec_cmd() for
134 // APP_CMD_RESUME, at which point it will be freed and savedState set to NULL.
135 // These variables should only be changed when processing a APP_CMD_SAVE_STATE,
136 // at which point they will be initialized to NULL and you can malloc your
137 // state and place the information here. In that case the memory will be
138 // freed for you later.
139 void* savedState;
140 size_t savedStateSize;
141
142 // The ALooper associated with the app's thread.
143 ALooper* looper;
144
145 // When non-NULL, this is the input queue from which the app will
146 // receive user input events.
147 AInputQueue* inputQueue;
148
149 // When non-NULL, this is the window surface that the app can draw in.
150 ANativeWindow* window;
151
152 // Current content rectangle of the window; this is the area where the
153 // window's content should be placed to be seen by the user.
154 ARect contentRect;
155
156 // Current state of the app's activity. May be either APP_CMD_START,
157 // APP_CMD_RESUME, APP_CMD_PAUSE, or APP_CMD_STOP; see below.
158 int activityState;
159
160 // This is non-zero when the application's NativeActivity is being
161 // destroyed and waiting for the app thread to complete.
162 int destroyRequested;
163
164 // -------------------------------------------------
165 // Below are "private" implementation of the glue code.
166
167 pthread_mutex_t mutex;
168 pthread_cond_t cond;
169
170 int msgread;
171 int msgwrite;
172
173 pthread_t thread;
174
175 struct android_poll_source cmdPollSource;
176 struct android_poll_source inputPollSource;
177
178 int running;
179 int stateSaved;
180 int destroyed;
181 int redrawNeeded;
182 AInputQueue* pendingInputQueue;
183 ANativeWindow* pendingWindow;
184 ARect pendingContentRect;
185 };
186
187 enum {
195 LOOPER_ID_MAIN = 1,
196
204 LOOPER_ID_INPUT = 2,
205
209 LOOPER_ID_USER = 3,
210 };
211
212 enum {
218 APP_CMD_INPUT_CHANGED,
219
225 APP_CMD_INIT_WINDOW,
226
233 APP_CMD_TERM_WINDOW,
234
239 APP_CMD_WINDOW_RESIZED,
240
246 APP_CMD_WINDOW_REDRAW_NEEDED,
247
253 APP_CMD_CONTENT_RECT_CHANGED,
254
259 APP_CMD_GAINED_FOCUS,
260
265 APP_CMD_LOST_FOCUS,
266
270 APP_CMD_CONFIG_CHANGED,
271
276 APP_CMD_LOW_MEMORY,
277
281 APP_CMD_START,
282
286 APP_CMD_RESUME,
287
295 APP_CMD_SAVE_STATE,
296
300 APP_CMD_PAUSE,
301
305 APP_CMD_STOP,
306
311 APP_CMD_DESTROY,
312 };
313
318 int8_t android_app_read_cmd(struct android_app* android_app);
319
325 void android_app_pre_exec_cmd(struct android_app* android_app, int8_t cmd);
326
332 void android_app_post_exec_cmd(struct android_app* android_app, int8_t cmd);
333
339 __attribute__((
340 deprecated("Calls to app_dummy are no longer necessary. See "
341 "https://github.com/android-ndk/ndk/issues/381."))) void
342 app_dummy();
343
348 extern void android_main(struct android_app* app);
349
350 #ifdef __cplusplus
351 }
352 #endif
353
354 #endif /* _ANDROID_NATIVE_APP_GLUE_H */
android_app
Definition: android_native_app_glue.h:111
android_poll_source
Definition: android_native_app_glue.h:90