[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["没有我需要的信息","missingTheInformationINeed","thumb-down"],["太复杂/步骤太多","tooComplicatedTooManySteps","thumb-down"],["内容需要更新","outOfDate","thumb-down"],["翻译问题","translationIssue","thumb-down"],["示例/代码问题","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-08-01。"],[],[],null,["# Add frame pacing functions\n\nUse the following functions to use Android Frame Pacing with a rendering engine\nbased on the OpenGL ES API.\n\nInitialize and destroy\n----------------------\n\nUse the following functions to initialize and destroy an instance of Android\nFrame Pacing, respectively:\n\n- [`void SwappyGL_init(JNIEnv *env, jobject jactivity);`](/games/sdk/reference/frame-pacing/group/swappy-g-l#group__swappy_g_l_1gad9a8392c399ae9b87a7bfe3f14678019)\n- [`void SwappyGL_destroy();`](/games/sdk/reference/frame-pacing/group/swappy-g-l#group__swappy_g_l_1gaa8c4eac2519c1c0bede3e54d848ecd4c)\n\nIn general, you should call `SwappyGL_init()` as early as possible during the\nengine startup sequence, and you should call `SwappyGL_destroy()` when the game\nis exiting. You shouldn't need to call these methods at any other time.\n\nConfigure swap interval and refresh period\n------------------------------------------\n\nUse the following functions to configure an instance of Android Frame Pacing:\n\n- [`void SwappyGL_setSwapIntervalNS(uint64_t swap_ns);`](/games/sdk/reference/frame-pacing/group/swappy-g-l#swappygl_setswapintervalns)\n- [`void SwappyGL_setFenceTimeoutNS(uint64_t fence_timeout_ns);`](/games/sdk/reference/frame-pacing/group/swappy-g-l#swappygl_setfencetimeoutns)\n- [`void SwappyGL_setUseAffinity(bool tf);`](/games/sdk/reference/frame-pacing/group/swappy-g-l#swappygl_setuseaffinity)\n\n| **Note:** Basic integrations usually don't require you to call `SwappyGL_setFenceTimeoutNS()` and `SwappyGL_setUseAffinity()`.\n\nWhen calling `SwappyGL_setSwapIntervalNS()`, pass in the duration that a frame\nshould be presented. In most cases, you can use one of the following constants:\n`SWAPPY_SWAP_60FPS`, `SWAPPY_SWAP_30FPS`, or `SWAPPY_SWAP_20FPS`.\n\nIn general, you should call these methods directly after a call to\n`SwappyGL_init()`. However, you might also need to call these methods at other\ntimes during your game's execution.\n\n### Setting the ANativeWindow\n\nSwappy needs the handle of `ANativeWindow` in order to perform\n`ANativeWindow`-specific operation, such as calling\n[`ANativeWindow_setFrameRate()`](/ndk/reference/group/a-native-window#anativewindow_setframerate).\nCall\n[`SwappyGL_setWindow()`](/games/sdk/reference/frame-pacing/group/swappy-g-l#swappygl_setwindow)\nwhen your Android display surface has changed and you have a new `ANativeWindow`\nhandle (see the [Bouncyball sample](https://android.googlesource.com/platform/frameworks/opt/gamesdk/+/refs/heads/master/samples/bouncyball) for an example).\n\n### Auto Modes\n\nAndroid Frame Pacing adjusts the swap duration and pipeline mode based on the\naverage duration of previous frames. You can control this behavior with the\nfollowing functions:\n\n- [`void SwappyGL_setAutoSwapInterval(bool enabled);`](/games/sdk/reference/frame-pacing/group/swappy-g-l-extra#swappygl_setautoswapinterval)\n- [`void SwappyGL_setMaxAutoSwapIntervalNS(uint64_t max_swap_ns);`](/games/sdk/reference/frame-pacing/group/swappy-g-l-extra#swappygl_setmaxautoswapintervalns)\n- [`void SwappyGL_setAutoPipelineMode(bool enabled);`](/games/sdk/reference/frame-pacing/group/swappy-g-l-extra#swappygl_setautopipelinemode)\n\nPerform per-frame swap\n----------------------\n\nDuring each rendering frame, call\n[`bool SwappyGL_swap(EGLDisplay display, EGLSurface surface)`](/games/sdk/reference/frame-pacing/group/swappy-g-l#swappygl_swap).\nThis method wraps the `eglSwapBuffers()` method from Open GL ES, so you should\nreplace all instances of `eglSwapBuffers()` in your game with `SwappyGL_swap()`.\n\nUtility functions\n-----------------\n\nThe following method checks whether Android Frame Pacing is enabled:\n\n- [`bool SwappyGL_isEnabled();`](/games/sdk/reference/frame-pacing/group/swappy-g-l#swappygl_isenabled)\n\nIt's possible that an instance of Android Frame Pacing isn't able to initialize\nitself for any of the following reasons:\n\n- The necessary EGL functions are missing on the device.\n- The system has set the `swappy.disable` property.\n\nIn either of these situations, `SwappyGL_isEnabled()` returns `false`, and it's\nbest for you to implement an alternative frame-pacing strategy.\n| **Note:** Even if `SwappyGL_isEnabled()` returns `false`, the `SwappyGL_swap()` function still invokes `eglSwapBuffers()`."]]