Watch sessions from the Google for Games Developer Summit.

Swappy for OpenGL

OpenGL part of Swappy.

Summary

Functions

SwappyGL_destroy()
void
Destroy resources and stop all threads that Swappy has created.
SwappyGL_getFenceTimeoutNS()
uint64_t
Get the fence timeout value, in nanoseconds.
SwappyGL_getRefreshPeriodNanos()
uint64_t
Get the refresh period value, in nanoseconds.
SwappyGL_getSwapIntervalNS()
uint64_t
Get the swap interval value, in nanoseconds.
SwappyGL_getUseAffinity()
bool
SwappyGL_init(JNIEnv *env, jobject jactivity)
bool
Initialize Swappy, getting the required Android parameters from the display subsystem via JNI.
SwappyGL_init_internal(JNIEnv *env, jobject jactivity)
bool
SwappyGL_isEnabled()
bool
Check if Swappy was successfully initialized.
SwappyGL_setFenceTimeoutNS(uint64_t fence_timeout_ns)
void
Set the fence timeout parameter, for devices with faulty drivers.
SwappyGL_setSwapIntervalNS(uint64_t swap_ns)
void
Override the swap interval.
SwappyGL_setUseAffinity(bool tf)
void
SwappyGL_swap(EGLDisplay display, EGLSurface surface)
bool
Replace calls to eglSwapBuffers with this.

Functions

SwappyGL_destroy

void SwappyGL_destroy()

Destroy resources and stop all threads that Swappy has created.

See also: SwappyGL_init

SwappyGL_getFenceTimeoutNS

uint64_t SwappyGL_getFenceTimeoutNS()

Get the fence timeout value, in nanoseconds.

SwappyGL_getRefreshPeriodNanos

uint64_t SwappyGL_getRefreshPeriodNanos()

Get the refresh period value, in nanoseconds.

SwappyGL_getSwapIntervalNS

uint64_t SwappyGL_getSwapIntervalNS()

Get the swap interval value, in nanoseconds.

SwappyGL_getUseAffinity

bool SwappyGL_getUseAffinity()

SwappyGL_init

bool SwappyGL_init(
  JNIEnv *env,
  jobject jactivity
)

Initialize Swappy, getting the required Android parameters from the display subsystem via JNI.

See also: SwappyGL_destroy

Details
Parameters
env
The JNI environment where Swappy is used
jactivity
The activity where Swappy is used
Returns
false if Swappy failed to initialize.

SwappyGL_init_internal

bool SwappyGL_init_internal(
  JNIEnv *env,
  jobject jactivity
)

SwappyGL_isEnabled

bool SwappyGL_isEnabled()

Check if Swappy was successfully initialized.

Details
Returns
false if either the swappy.disable system property is not false or the required OpenGL extensions are not available for Swappy to work.

SwappyGL_setFenceTimeoutNS

void SwappyGL_setFenceTimeoutNS(
  uint64_t fence_timeout_ns
)

Set the fence timeout parameter, for devices with faulty drivers.

Its default value is 50,000,000ns (50ms).

SwappyGL_setSwapIntervalNS

void SwappyGL_setSwapIntervalNS(
  uint64_t swap_ns
)

Override the swap interval.

By default, Swappy will adjust the swap interval based on actual frame rendering time.

If an app wants to override the swap interval calculated by Swappy, it can call this function:

  • This will temporarily override Swappy's frame timings but, unless SwappyGL_setAutoSwapInterval(false) is called, the timings will continue to be be updated dynamically, so the swap interval may change.
  • This set the minimal interval to run. For example, SwappyGL_setSwapIntervalNS(SWAPPY_SWAP_30FPS) will not allow Swappy to swap faster, even if auto mode decides that it can. But it can go slower if auto mode is on.

Details
Parameters
swap_ns
The new swap interval value, in nanoseconds.

SwappyGL_setUseAffinity

void SwappyGL_setUseAffinity(
  bool tf
)

SwappyGL_swap

bool SwappyGL_swap(
  EGLDisplay display,
  EGLSurface surface
)

Replace calls to eglSwapBuffers with this.

Swappy will wait for the previous frame's buffer to be processed by the GPU before actually calling eglSwapBuffers.