Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

fix(android): the 60 fps frame-rate hint reaches the system on current Android

yhhc8a95d9081da
diff --git a/native/host/platform/android.cpp b/native/host/platform/android.cpp
index 7ab3df49a..3c26f01c8 100644
--- a/native/host/platform/android.cpp
+++ b/native/host/platform/android.cpp
@@ -521,7 +521,13 @@ void framesResumed(bool is);
void hintFrameRate(ANativeWindow* window, float fps) {
constexpr int8_t kCompatibilityDefault = 0; // ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT
using SetFrameRateFn = int32_t (*)(ANativeWindow*, float, int8_t);
- const auto set = reinterpret_cast<SetFrameRateFn>(dlsym(RTLD_DEFAULT, "ANativeWindow_setFrameRate"));
+ // From libnativewindow, which exports it: RTLD_DEFAULT searches only what this
+ // namespace loaded globally, and on a current device that is not the library
+ // this symbol lives in — the lookup came back empty on Android 16 and the hint
+ // was never given, which is the 120 Hz cadence problem above, every frame.
+ static void* const nativeWindow = dlopen("libnativewindow.so", RTLD_NOW | RTLD_LOCAL);
+ auto set = nativeWindow ? reinterpret_cast<SetFrameRateFn>(dlsym(nativeWindow, "ANativeWindow_setFrameRate")) : nullptr;
+ if (!set) set = reinterpret_cast<SetFrameRateFn>(dlsym(RTLD_DEFAULT, "ANativeWindow_setFrameRate"));
if (!window || !set) {
if (window) __android_log_print(ANDROID_LOG_WARN, LOG_TAG, "frame rate hint: unavailable (API < 30)");
return;
diff --git a/src/esengine/renderer/webgpu/WebGPUDevice.cpp b/src/esengine/renderer/webgpu/WebGPUDevice.cpp
index 88336f94d..4b16e9361 100644
--- a/src/esengine/renderer/webgpu/WebGPUDevice.cpp
+++ b/src/esengine/renderer/webgpu/WebGPUDevice.cpp
@@ -536,7 +536,7 @@ bool WebGPUDevice::configureSwapchain(u32 width, u32 height) {
if (present_uncapped_) {
ES_LOG_WARN("WebGPUDevice: uncapped present asked for, surface gave {}",
cfg.presentMode == WGPUPresentMode_Immediate ? "Immediate"
- : cfg.presentMode == WGPUPresentMode_Mailbox ? "Mailbox — still vsynced on Metal"
+ : cfg.presentMode == WGPUPresentMode_Mailbox ? "Mailbox — the compositor still shows one frame per vsync"
: "Fifo — the frame IS the refresh interval");
}
wgpuSurfaceConfigure(surface_, &cfg);