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/request-before-animation-frame.md.
Lynx
  • English
  • RequestBeforeAnimationFrame

    The RequestBeforeAnimationFrame method, part of the VSyncObserver class, schedules a function to be executed just before the next screen repaint, synchronized with the VSync signal. Unlike RequestAnimationFrame, callbacks registered with this method are guaranteed to be executed before any standard animation frame callbacks. This is useful for tasks that need to update state or perform calculations before other visual updates occur in the same frame.

    This method also provides two overloads for C++ std::function and C-style function pointers.

    Method Signature

    With std::function callback

    void RequestBeforeAnimationFrame(uintptr_t id, lynx::pub::VSyncObserverCallback callback);

    With C-function callback

    void RequestBeforeAnimationFrame(uintptr_t id,
                                     vsync_observer_callback callback,
                                     void* user_data);

    Parameters

    NameTypeDescriptionRequired
    iduintptr_tA unique identifier for the request instance.Yes
    callbacklynx::pub::VSyncObserverCallback / vsync_observer_callbackThe function to be called before normal animation callbacks when the next VSync signal arrives. See the callback signatures below.Yes
    user_datavoid*(C-function overload only) A pass-through context pointer provided to the callback. Pass nullptr when no context is needed.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);

    Example

    This example demonstrates how to schedule a high-priority task before other animations.

    // Assuming 'vsync_observer' is a valid std::unique_ptr<VSyncObserver>.
    
    uintptr_t high_priority_id = 2;
    
    vsync_observer->RequestBeforeAnimationFrame(high_priority_id, [](int64_t start_time, int64_t end_time) {
        // This logic runs before other RequestAnimationFrame callbacks.
        // Ideal for pre-calculation or state updates.
        printf("High-priority task executed for frame: %lld\\n", start_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.