android: keep EGL extension slots for Skia (the UI did not start on Waydroid)
On Waydroid the app ended right after start: "Could not create Skia Direct Context from GL interface", after libEGL logged "no more slots for eglGetProcAddress". Android's libEGL gives every GL function without a built-in entry point one of 256 extension slots on its first lookup. Slint's Skia OpenGL surface loads glow's whole function table (desktop GL included) before Skia assembles its interface; Mesa returns an entry point for every name, so the slots run out, Skia gets NULL for glTextureBarrierNV (advertised through GL_NV_texture_barrier) and refuses the interface. Look up the 83 extension functions Skia's GLES interface can use (Skia m153's GrGLAssembleGLESInterfaceAutogen.cpp) once per process before Slint creates its surface, so they get slots first; glow's desktop-only lookups are the ones that fail. Vendor drivers return NULL for desktop-only names and were not affected. docs/android.md explains it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NJvYyRmTjKcb9i8eyYXK5G
This commit is contained in:
1 parent
e050148a32
commit
f7ada91fcd
4 files changed
+163
-1
No files matched your search
@@ -14,7 +14,7 @@ use voelin_core::Command;
|
||||
|
||||
use crate::foreground::Foreground;
|
||||
use crate::host::EngineHost;
|
||||
use crate::{bridge, capture, secrets};
|
||||
use crate::{bridge, capture, egl, secrets};
|
||||
|
||||
/// Store setting (`bool`): the user's opt-in to local crash reports.
|
||||
pub const CRASH_REPORTS_SETTING: &str = "crash_reports";
|
||||
@@ -73,6 +73,8 @@ fn run(app: AndroidApp) -> anyhow::Result<()> {
|
||||
let host = host()?;
|
||||
static PROCESS: Once = Once::new();
|
||||
PROCESS.call_once(|| {
|
||||
// Before Slint creates the first window surface.
|
||||
egl::reserve_skia_extension_slots();
|
||||
capture::register();
|
||||
watch_voice(host);
|
||||
});
|
||||
|
||||
@@ -0,0 +1,135 @@
|
||||
//! Keep EGL extension slots for Skia (Mesa-based Android, e.g. Waydroid).
|
||||
//!
|
||||
//! Android's libEGL gives each GL function it has no built-in entry point for
|
||||
//! one of a fixed number of "extension slots" (256) the first time
|
||||
//! `eglGetProcAddress` looks it up. Slint's Skia OpenGL surface first loads
|
||||
//! glow's whole function table, desktop GL included, and only then lets Skia
|
||||
//! assemble its GLES interface. Vendor drivers return nothing for desktop-only
|
||||
//! names, but Mesa returns an entry point for every name, so under Mesa glow
|
||||
//! uses up all slots. Skia then gets nothing for the extension functions it
|
||||
//! needs, e.g. `glTextureBarrierNV` when the driver advertises
|
||||
//! `GL_NV_texture_barrier`, and the app cannot draw ("Could not create Skia
|
||||
//! Direct Context from GL interface", with "no more slots for
|
||||
//! eglGetProcAddress" before it in logcat).
|
||||
//!
|
||||
//! Looking Skia's extension functions up once, before Slint creates its
|
||||
//! surface, gives them slots first; libEGL remembers them, and the lookups
|
||||
//! that later fail are glow's desktop-only ones, which nothing here uses.
|
||||
|
||||
use std::ffi::{CStr, c_char, c_void};
|
||||
|
||||
use tracing::info;
|
||||
|
||||
#[link(name = "EGL")]
|
||||
#[allow(unsafe_code)] // FFI declaration
|
||||
unsafe extern "C" {
|
||||
fn eglGetProcAddress(procname: *const c_char) -> *const c_void;
|
||||
}
|
||||
|
||||
/// Every extension function (name with a vendor suffix) that Skia's GLES
|
||||
/// interface can look up: `GET_PROC_SUFFIX` in Skia m153's
|
||||
/// `src/gpu/ganesh/gl/GrGLAssembleGLESInterfaceAutogen.cpp` (the version
|
||||
/// skia-safe 0.153 builds). Core GLES functions have built-in entry points and
|
||||
/// need no slot. Update the list when skia-safe moves to a new Skia milestone.
|
||||
const SKIA_GLES_EXTENSION_FUNCTIONS: &[&CStr] = &[
|
||||
c"glBeginQueryEXT",
|
||||
c"glBindFragDataLocationEXT",
|
||||
c"glBindFragDataLocationIndexedEXT",
|
||||
c"glBindUniformLocationCHROMIUM",
|
||||
c"glBindVertexArrayOES",
|
||||
c"glBlendBarrierKHR",
|
||||
c"glBlendBarrierNV",
|
||||
c"glBlitFramebufferANGLE",
|
||||
c"glBlitFramebufferCHROMIUM",
|
||||
c"glBlitFramebufferNV",
|
||||
c"glClearTexImageEXT",
|
||||
c"glClearTexSubImageEXT",
|
||||
c"glClientWaitSyncAPPLE",
|
||||
c"glCopyBufferSubDataNV",
|
||||
c"glDebugMessageCallbackKHR",
|
||||
c"glDebugMessageControlKHR",
|
||||
c"glDebugMessageInsertKHR",
|
||||
c"glDeleteFencesNV",
|
||||
c"glDeleteQueriesEXT",
|
||||
c"glDeleteSyncAPPLE",
|
||||
c"glDeleteVertexArraysOES",
|
||||
c"glDiscardFramebufferEXT",
|
||||
c"glDrawArraysInstancedANGLE",
|
||||
c"glDrawArraysInstancedBaseInstanceANGLE",
|
||||
c"glDrawArraysInstancedBaseInstanceEXT",
|
||||
c"glDrawArraysInstancedEXT",
|
||||
c"glDrawElementsInstancedANGLE",
|
||||
c"glDrawElementsInstancedBaseVertexBaseInstanceANGLE",
|
||||
c"glDrawElementsInstancedBaseVertexBaseInstanceEXT",
|
||||
c"glDrawElementsInstancedEXT",
|
||||
c"glEndQueryEXT",
|
||||
c"glEndTilingQCOM",
|
||||
c"glFenceSyncAPPLE",
|
||||
c"glFinishFenceNV",
|
||||
c"glFlushMappedBufferRangeEXT",
|
||||
c"glFramebufferTexture2DMultisampleEXT",
|
||||
c"glFramebufferTexture2DMultisampleIMG",
|
||||
c"glGenFencesNV",
|
||||
c"glGenQueriesEXT",
|
||||
c"glGenVertexArraysOES",
|
||||
c"glGetDebugMessageLogKHR",
|
||||
c"glGetProgramBinaryOES",
|
||||
c"glGetQueryObjecti64vEXT",
|
||||
c"glGetQueryObjectui64vEXT",
|
||||
c"glGetQueryObjectuivEXT",
|
||||
c"glGetQueryivEXT",
|
||||
c"glInsertEventMarkerEXT",
|
||||
c"glIsSyncAPPLE",
|
||||
c"glMapBufferOES",
|
||||
c"glMapBufferRangeEXT",
|
||||
c"glMapBufferSubDataCHROMIUM",
|
||||
c"glMapTexSubImage2DCHROMIUM",
|
||||
c"glMultiDrawArraysIndirectEXT",
|
||||
c"glMultiDrawArraysInstancedBaseInstanceANGLE",
|
||||
c"glMultiDrawElementsIndirectEXT",
|
||||
c"glMultiDrawElementsInstancedBaseVertexBaseInstanceANGLE",
|
||||
c"glObjectLabelKHR",
|
||||
c"glPatchParameteriOES",
|
||||
c"glPopDebugGroupKHR",
|
||||
c"glPopGroupMarkerEXT",
|
||||
c"glProgramBinaryOES",
|
||||
c"glPushDebugGroupKHR",
|
||||
c"glPushGroupMarkerEXT",
|
||||
c"glQueryCounterEXT",
|
||||
c"glRenderbufferStorageMultisampleANGLE",
|
||||
c"glRenderbufferStorageMultisampleCHROMIUM",
|
||||
c"glResolveMultisampleFramebufferAPPLE",
|
||||
c"glSetFenceNV",
|
||||
c"glStartTilingQCOM",
|
||||
c"glTestFenceNV",
|
||||
c"glTexBufferEXT",
|
||||
c"glTexBufferOES",
|
||||
c"glTexBufferRangeEXT",
|
||||
c"glTexBufferRangeOES",
|
||||
c"glTexStorage2DEXT",
|
||||
c"glTextureBarrierNV",
|
||||
c"glUnmapBufferOES",
|
||||
c"glUnmapBufferSubDataCHROMIUM",
|
||||
c"glUnmapTexSubImage2DCHROMIUM",
|
||||
c"glVertexAttribDivisorANGLE",
|
||||
c"glVertexAttribDivisorEXT",
|
||||
c"glWaitSyncAPPLE",
|
||||
c"glWindowRectanglesEXT",
|
||||
];
|
||||
|
||||
/// Look up [`SKIA_GLES_EXTENSION_FUNCTIONS`] so libEGL keeps their slots.
|
||||
/// Call once per process, before the first window is shown.
|
||||
pub fn reserve_skia_extension_slots() {
|
||||
let found = SKIA_GLES_EXTENSION_FUNCTIONS.iter().filter(|name| resolves(name)).count();
|
||||
info!(
|
||||
"EGL: {found} of {} Skia extension functions resolved ahead of Slint's surface",
|
||||
SKIA_GLES_EXTENSION_FUNCTIONS.len()
|
||||
);
|
||||
}
|
||||
|
||||
#[allow(unsafe_code)] // the FFI call
|
||||
fn resolves(name: &CStr) -> bool {
|
||||
// SAFETY: `name` is NUL-terminated; eglGetProcAddress may be the first EGL
|
||||
// call of the process and only returns an address, which is not used.
|
||||
!unsafe { eglGetProcAddress(name.as_ptr()) }.is_null()
|
||||
}
|
||||
@@ -14,6 +14,8 @@
|
||||
//! - `capture` (Android): screen and system-audio capture through
|
||||
//! MediaProjection, registered as `voelin_media` capture providers
|
||||
//! - `secrets` (Android): passwords encrypted with an Android Keystore key
|
||||
//! - `egl` (Android): keeps EGL extension slots for Skia, without which the
|
||||
//! UI cannot draw on Mesa-based Android (Waydroid)
|
||||
//!
|
||||
//! Only [`host`] and [`foreground`] build on other platforms, for tests.
|
||||
|
||||
@@ -27,4 +29,6 @@ mod bridge;
|
||||
#[cfg(target_os = "android")]
|
||||
mod capture;
|
||||
#[cfg(target_os = "android")]
|
||||
mod egl;
|
||||
#[cfg(target_os = "android")]
|
||||
mod secrets;
|
||||
Reference in new issue
Block a user