ffi #jni_main R.5: retire legacy NativeActivity surface

Deletes the entire NativeActivity / native_app_glue / ALooper stack
that the previous Android entry path was built around:

  - `examples/99-android-egl-clear.sx` — the demo of the legacy path.
  - `library/modules/platform/android.sx` — `AndroidPlatform.init`,
    `run_frame_loop`, `sx_android_bootstrap`, `g_android_app`, plus
    the ALooper / AInputEvent / ANativeActivity / AConfiguration
    foreign decls that fed them. The JNI helpers (`sx_load_javavm_fn`,
    `sx_android_get_env`, `sx_query_safe_insets_jni`, the
    `ANATIVEACTIVITY_*` offsets) were tied to the ANativeActivity*
    delivered to `android_main` — they're stale now that the OS hands
    sx code a Java Activity directly via `onCreate(JNIEnv*, jobject)`.
  - `library/vendors/sx_android_jni/sx_android_jni.c` — the input-
    handler installer (`sx_android_install_input_handler`), which
    poked NDK app-pointer field offsets that no longer exist.

`library/modules/platform/android_jni.sx` (the `Activity`/`Window`/
`View`/`WindowInsets` `#jni_class` registry used for safe-insets
dispatch) survives — it's standalone declarative bindings useful from
any `#jni_main` onCreate body. Docstring updated to drop the
"imported from android.sx" framing.

131 host / 4 cross / zig build test all green. End-to-end smoke APK
still produces the expected JNI-mangled symbol +
SxApp-extends-Activity dex.

External consumers (chess) will need to migrate their entry from the
`AndroidPlatform.run_frame_loop` model to the `#jni_main` model
(Java-side Activity drives lifecycle; onSurfaceChanged / Choreographer
drive frames via JNI callbacks). That migration is downstream work.
This commit is contained in:
agra
2026-05-20 15:17:24 +03:00
parent 3300bfb0df
commit 619d524bac
5 changed files with 10 additions and 737 deletions

View File

@@ -1,79 +0,0 @@
// Android-only: pure-sx NativeActivity that brings up EGL on the
// ANativeWindow delivered by native_app_glue and clears the screen
// every frame via GLES3. Equivalent of `examples/63-metal-clear.sx`
// for the Android target.
//
// Entry-point contract (the "via Platform" shape):
// - User writes BOTH `main` and `android_main` at top level.
// - `android_main(app)` calls `sx_android_bootstrap(app)` and then
// `main()`. The library never names `main`; the OS-shape entry
// symbol lives in user code, where the other entry symbols are.
// - `main` instantiates `AndroidPlatform`, calls `init`, then
// `run_frame_loop` which drives the looper until destroyRequested.
//
// This exercises end-to-end the Android pipeline shipped in Session 70:
// - `sx build --target android` toolchain (NDK clang + glue link).
// - `--apk` APK assembly (manifest + aapt2 + zipalign + apksigner).
// - `android_main` (user-written here) gets external LLVM linkage
// via the `isExportedEntryName` allowlist in lower.zig.
// - `AndroidPlatform.run_frame_loop` drains ALooper events,
// creates EGL on `APP_CMD_INIT_WINDOW`, ticks the closure every
// 16 ms.
//
// Build + install on a connected device:
//
// /Users/agra/projects/sx/zig-out/bin/sx build --target android \
// --apk /tmp/sxhello.apk --bundle-id co.swipelab.sxhello \
// -o /tmp/libsxhello.so examples/99-android-egl-clear.sx
// adb install -r /tmp/sxhello.apk
// adb shell am start -n co.swipelab.sxhello/android.app.NativeActivity
// adb logcat -d --pid=$(adb shell pidof co.swipelab.sxhello)
//
// Expected: solid purple frame on the device. Periodic
// `rendered 60 frames` lines in logcat.
#import "modules/std.sx";
#import "modules/compiler.sx";
#import "modules/platform/api.sx";
#import "modules/platform/android.sx";
// GLES3 (linked via -lGLESv3)
glClearColor :: (r: f32, g: f32, b: f32, a: f32) #foreign;
glClear :: (mask: u32) #foreign;
GL_COLOR_BUFFER_BIT :u32: 0x4000;
frame_count : s32 = 0;
g_plat : *AndroidPlatform = null;
frame_tick :: () {
fc := g_plat.begin_frame();
glClearColor(0.5, 0.2, 0.8, 1.0); // purple
glClear(GL_COLOR_BUFFER_BIT);
g_plat.end_frame();
frame_count += 1;
if (frame_count % 60) == 0 {
__android_log_print(4, "sxhello".ptr, "rendered 60 frames\n".ptr);
}
}
main :: () -> s32 {
inline if OS == .android {
plat : AndroidPlatform = .{};
plat.init("sxhello", 0, 0);
g_plat = @plat;
plat.run_frame_loop(() => frame_tick());
}
0;
}
// OS-shape entry symbol. native_app_glue's
// `ANativeActivity_onCreate` ultimately calls this on the worker
// thread. We hand the app pointer to the platform module and then
// let user `main` drive the normal cross-platform setup path.
android_main :: (app: *void) {
inline if OS == .android {
sx_android_bootstrap(app);
main();
}
}