For AI agents: the complete documentation index is available at /next/llms.txt, the full documentation bundle is available at /next/llms-full.txt, and this page is available as Markdown at /next/api/lynx-native-api/lynx-extension-module/register-after-animation-frame-listener.md.
Lynx
  • English
  • RegisterAfterAnimationFrameListener

    The RegisterAfterAnimationFrameListener method, part of the VSyncObserver class, registers a persistent listener that is called after every VSync signal occurs. Unlike RequestAnimationFrame, which is a one-shot request, no API is exposed to unregister this listener, making it suitable for continuous monitoring or tasks that need to run on every frame.

    This method must be called on the BTS (Background Thread Script) thread. It also supports both C++ std::function and C-style function pointer callbacks.

    Method Signature

    With std::function callback

    void RegisterAfterAnimationFrameListener(lynx::pub::VSyncObserverCallback callback);

    With C-function callback

    void RegisterAfterAnimationFrameListener(vsync_observer_callback callback, void* user_data);

    Parameters

    NameTypeDescriptionRequired
    callbacklynx::pub::VSyncObserverCallback / vsync_observer_callbackThe function to be called after each VSync signal. See the callback signatures below.Yes
    user_datavoid*(C-function overload only) A pass-through context pointer provided to the callback. Pass nullptr when unused.Yes

    Callback Functions

    The C++ lynx::pub::VSyncObserverCallback signature is:

    void(int64_t frame_start_time, int64_t frame_end_time);

    The C vsync_observer_callback signature is:

    void(void* user_data, int64_t frame_start_time, int64_t frame_end_time);

    Important Notes

    • Execution Thread: This method and its callbacks are intended to be used on the BTS thread.
    • Persistent Listener: The registered callback will be invoked for every subsequent VSync signal, not just once.
    • Lifecycle: Keep the VSyncObserver instance alive while the runtime may invoke the callback. The API does not provide an explicit unregister operation.

    Example

    This example shows how to register a listener to log information for every frame.

    // Assuming this code is running on the BTS thread and 'vsync_observer' is available.
    
    vsync_observer->RegisterAfterAnimationFrameListener([](int64_t start_time, int64_t end_time) {
        // This will be logged on every single frame.
        // Useful for performance monitoring or continuous updates.
        printf("Frame processed. Start: %lld, End: %lld\\n", start_time, end_time);
    });

    Compatibility

    LCD tables only load in the browser

    Except as otherwise noted, this work is licensed under a Creative Commons Attribution 4.0 International License, and code samples are licensed under the Apache License 2.0.