How frankbarretta/lsfg-android-application works
Purpose and Entry Points
LSFG is a sideloaded Android frame-generation overlay for games. It captures display frames, runs a patched external lsfg-vk-android framegen library, and presents generated frames above the target app. Main UI/navigation begins at app/src/main/java/com/lsfg/android/ui/MainActivity.kt; runtime orchestration is the foreground service in app/src/main/java/com/lsfg/android/session/LsfgForegroundService.kt.
UI, Configuration, and Session Launch
Compose screens collect DLL, target-app, projection, pacing, and framegen settings, persisted through preferences. A projection request yields the per-session MediaProjection token; the service must post its foreground notification before capture work. Relevant paths: app/src/main/java/com/lsfg/android/ui/ProjectionRequestActivity.kt, app/src/main/java/com/lsfg/android/prefs/LsfgPreferences.kt, app/src/main/java/com/lsfg/android/session/LsfgForegroundService.kt.
Overlay Host and Input Boundary
OverlayManager owns the system overlay and its surface lifecycle. It can use application-overlay windows or an accessibility-overlay host; the latter is mediated by the accessibility service. The service waits for a valid output surface before starting capture, and surface recreation drives resize/retarget handling. Touch passthrough is implemented through touchable-inset management rather than non-touchable window flags. Paths: app/src/main/java/com/lsfg/android/session/OverlayManager.kt, app/src/main/java/com/lsfg/android/session/LsfgAccessibilityService.kt, app/src/main/java/com/lsfg/android/session/FrameGraphView.kt.
Capture and Privileged Timing
The visible video path is MediaProjection → VirtualDisplay → ImageReader → AHardwareBuffer; CaptureEngine supplies these frames to JNI/native rendering. Root and Shizuku code provide alternative/privileged integration, but Shizuku is timing-only and does not supply visible overlay buffers. Its AIDL boundary separates the app from the Shizuku user service. Paths: app/src/main/java/com/lsfg/android/session/CaptureEngine.kt, app/src/main/java/com/lsfg/android/session/ShizukuCaptureEngine.kt, app/src/main/aidl/com/lsfg/android/shizuku/IShizukuCaptureService.aidl.
Native Render and Framegen Pipeline
Kotlin calls one JNI boundary; native code owns a worker-thread render loop, persistent Vulkan session, AHardwareBuffer import, framegen context lifecycle, pacing, and presentation to the overlay ANativeWindow. Imported buffers are shared with framegen through Android Vulkan external-memory/AHB mechanisms; device synchronization is a critical boundary because framegen has its own Vulkan device. Paths: app/src/main/java/com/lsfg/android/session/NativeBridge.kt, app/src/main/cpp/lsfg_jni.cpp, app/src/main/cpp/lsfg_render_loop.cpp, app/src/main/cpp/android_vk_session.cpp, app/src/main/cpp/ahb_image_bridge.cpp.
Shader Asset Pipeline and Capability Gate
A user-selected proprietary Lossless.dll is processed on-device: native extraction translates DXBC resources to SPIR-V, writes shader assets under app storage, then probes each module on a headless Vulkan device before full initialization. The DLL is deleted afterward. Devices lacking required Vulkan capabilities—especially robustness2—fall back to capture-only mirror output. Paths: app/src/main/java/com/lsfg/android/session/ShaderExtractor.kt, app/src/main/cpp/android_shader_loader.cpp, app/src/main/cpp/android_vk_probe.cpp.
Runtime Coordination and Infrastructure
Parameter changes requiring allocation/context changes are serialized by the foreground service; hot-applicable controls use dedicated JNI calls. Native crash handlers and Kotlin crash reporting preserve failures for next-launch reporting. The app targets Android 10+ and uses Kotlin/Compose plus C++20/NDK/CMake, Vulkan 1.2+, MediaProjection, WindowManager overlays, optional AccessibilityService, and optional Shizuku. Planned CPU/GPU/NNAPI postprocessing scaffolding exists but is not end-to-end wired. Paths: app/src/main/java/com/lsfg/android/session/CrashReporter.kt, app/src/main/cpp/crash_reporter.cpp, app/src/main/cpp/nnapi_postprocess.cpp.
Main entry points: LsfgForegroundService.kt Foreground session service · lsfg_render_loop.cpp Vulkan render loop · MainActivity.kt Compose UI · android_vk_probe.cpp Vulkan capability probe
Components 21
Android control
- Compose UI · Collects session, pacing, and framegen settings.
app/src/main/java/com/lsfg/android/ui/MainActivity.kt - Projection request · Obtains the per-session MediaProjection token.
app/src/main/java/com/lsfg/android/ui/ProjectionRequestActivity.kt - Preferences
app/src/main/java/com/lsfg/android/prefs/LsfgPreferences.kt - Foreground session service · Serializes session changes and starts capture only after notification and output surface readiness.
app/src/main/java/com/lsfg/android/session/LsfgForegroundService.kt - Crash reporting · Preserves native and Kotlin failures for the next launch.
app/src/main/java/com/lsfg/android/session/CrashReporter.kt
Capture and overlay
- Target app display
- Overlay manager · Owns overlay windows, touchable insets, and output surface lifecycle.
app/src/main/java/com/lsfg/android/session/OverlayManager.kt - Accessibility overlay host · Optional host for accessibility-overlay windows.
app/src/main/java/com/lsfg/android/session/LsfgAccessibilityService.kt - Overlay view · Provides the presentation surface to the overlay host.
app/src/main/java/com/lsfg/android/session/FrameGraphView.kt - MediaProjection capture · Creates VirtualDisplay and ImageReader frames backed by AHardwareBuffer.
app/src/main/java/com/lsfg/android/session/CaptureEngine.kt - Shizuku timing integration · Provides timing integration only, not visible overlay buffers.
app/src/main/java/com/lsfg/android/session/ShizukuCaptureEngine.kt - Shizuku AIDL boundary · Separates the app from the Shizuku user service.
app/src/main/aidl/com/lsfg/android/shizuku/IShizukuCaptureService.aidl
Native frame pipeline
- JNI bridge · Single boundary for lifecycle, frames, and hot controls.
app/src/main/java/com/lsfg/android/session/NativeBridge.kt - JNI entrypoint
app/src/main/cpp/lsfg_jni.cpp - Vulkan render loop · Owns frame pacing, framegen lifecycle, and overlay presentation.
app/src/main/cpp/lsfg_render_loop.cpp - Vulkan session · Maintains the renderer device and presentation state.
app/src/main/cpp/android_vk_session.cpp - AHardwareBuffer bridge · Imports capture buffers across the framegen device boundary.
app/src/main/cpp/ahb_image_bridge.cpp - Native crash handler
app/src/main/cpp/crash_reporter.cpp
Shader capability gate
- DLL shader extraction · Processes selected Lossless.dll and deletes it after asset generation.
app/src/main/java/com/lsfg/android/session/ShaderExtractor.kt - DXBC to SPIR-V loader · Translates DLL resources and writes app-storage shader assets.
app/src/main/cpp/android_shader_loader.cpp - Vulkan capability probe · Headlessly validates shader modules and required capabilities such as robustness2.
app/src/main/cpp/android_vk_probe.cpp
Connections 25
- Compose UI → Preferences: reads and saves settings
- Compose UI → Projection request: requests consent
- Compose UI → Foreground session service: launches session
- Preferences → Foreground session service: session configuration
- Projection request → Foreground session service: MediaProjection token
- Foreground session service → Overlay manager: creates overlay
- Accessibility overlay host → Overlay manager: optional overlay host
- Overlay manager → Overlay view: owns surface
- Overlay view → Foreground session service: surface lifecycle
- Foreground session service → MediaProjection capture: starts after surface ready
- Target app display → MediaProjection capture: MediaProjection capture
- MediaProjection capture → JNI bridge: AHardwareBuffer frames
- Foreground session service → Shizuku timing integration: optional timing mode
- Shizuku timing integration → Shizuku AIDL boundary: IPC
- Foreground session service → JNI bridge: lifecycle and controls
- JNI bridge → JNI entrypoint: JNI calls
- JNI entrypoint → Vulkan render loop: commands and frames
- Vulkan render loop → Vulkan session: uses renderer device
- Vulkan render loop → AHardwareBuffer bridge: imports input
- Vulkan render loop → Overlay view: presents to ANativeWindow
- DLL shader extraction → DXBC to SPIR-V loader: selected DLL
- DXBC to SPIR-V loader → Vulkan capability probe: SPIR-V assets
- Vulkan capability probe → Foreground session service: framegen or mirror-only gate
- Vulkan capability probe → Vulkan render loop: validated assets
- Native crash handler → Crash reporting: native failures