MCPcopy Create free account
hub / github.com/android/ndk-samples / android_main

Function android_main

hello-vulkan/app/src/main/cpp/vk_main.cpp:124–155  ·  view source on GitHub ↗

* Entry point required by the Android Glue library. * This can also be achieved more verbosely by manually declaring JNI functions * and calling them from the Android application layer. */

Source from the content-addressed store, hash-verified

122 * and calling them from the Android application layer.
123 */
124void android_main(struct android_app* state) {
125 VulkanEngine engine{};
126 vkt::HelloVK vulkanBackend{};
127
128 engine.app = state;
129 engine.app_backend = &vulkanBackend;
130 state->userData = &engine;
131 state->onAppCmd = HandleCmd;
132
133 android_app_set_key_event_filter(state, VulkanKeyEventFilter);
134 android_app_set_motion_event_filter(state, VulkanMotionEventFilter);
135
136 while (!state->destroyRequested) {
137 android_poll_source* source;
138 auto result = ALooper_pollOnce(engine.canRender ? 0 : -1, nullptr, nullptr,
139 (void**)&source);
140 if (result == ALOOPER_POLL_ERROR) {
141 LOGE("ALooper_pollOnce returned an error");
142 std::abort();
143 }
144
145 if (source != nullptr) {
146 source->process(state, source);
147 }
148
149 HandleInputEvents(state);
150
151 if (engine.canRender) {
152 engine.app_backend->render();
153 }
154 }
155}

Callers

nothing calls this directly

Calls 2

HandleInputEventsFunction · 0.85
renderMethod · 0.45

Tested by

no test coverage detected