Home | History | Annotate | Download | only in swappy
      1 /*
      2  * Copyright 2018 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #pragma once
     18 
     19 #include <stdint.h>
     20 #include <EGL/egl.h>
     21 #include <EGL/eglext.h>
     22 #include <jni.h>
     23 
     24 #ifdef __cplusplus
     25 extern "C" {
     26 #endif
     27 
     28 // swap interval constant helpers
     29 #define SWAPPY_SWAP_60FPS (16666667L)
     30 #define SWAPPY_SWAP_30FPS (33333333L)
     31 #define SWAPPY_SWAP_20FPS (50000000L)
     32 
     33 // Initialize Swappy, getting the required Android parameters from the display subsystem via JNI
     34 void Swappy_init(JNIEnv *env, jobject jactivity);
     35 
     36 // Returns true if Swappy was successfully initialized.
     37 // Returns false if either the 'swappy.disable' system property is not 'false'
     38 //  or the required OpenGL extensions are not available for Swappy to work.
     39 bool Swappy_isEnabled();
     40 
     41 // Destroy resources and stop all threads that swappy has created
     42 void Swappy_destroy();
     43 
     44 // Replace calls to eglSwapBuffers with this. Swappy will wait for the previous frame's
     45 // buffer to be processed by the GPU before actually calling eglSwapBuffers.
     46 bool Swappy_swap(EGLDisplay display, EGLSurface surface);
     47 
     48 // Parameter setters
     49 void Swappy_setRefreshPeriod(uint64_t period_ns);
     50 void Swappy_setUseAffinity(bool tf);
     51 void Swappy_setSwapIntervalNS(uint64_t swap_ns);
     52 
     53 // Parameter getters
     54 uint64_t Swappy_getRefreshPeriodNanos();
     55 uint64_t Swappy_getSwapIntervalNS();
     56 bool Swappy_getUseAffinity();
     57 
     58 #ifdef __cplusplus
     59 };
     60 #endif
     61