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 #include "swappy/swappy.h"
18
19 #include "Swappy.h"
20
21 #include "Settings.h"
22
23 #include <chrono>
24
25 using namespace swappy;
26
27 extern "C" {
28
Swappy_init(JNIEnv * env,jobject jactivity)29 void Swappy_init(JNIEnv *env, jobject jactivity) {
30 Swappy::init(env, jactivity);
31 }
32
Swappy_destroy()33 void Swappy_destroy() {
34 Swappy::destroyInstance();
35 }
36
Swappy_onChoreographer(int64_t frameTimeNanos)37 void Swappy_onChoreographer(int64_t frameTimeNanos) {
38 Swappy::onChoreographer(frameTimeNanos);
39 }
40
Swappy_swap(EGLDisplay display,EGLSurface surface)41 bool Swappy_swap(EGLDisplay display, EGLSurface surface) {
42 return Swappy::swap(display, surface);
43 }
44
Swappy_setRefreshPeriod(uint64_t period_ns)45 void Swappy_setRefreshPeriod(uint64_t period_ns) {
46 Settings::getInstance()->setRefreshPeriod(std::chrono::nanoseconds(period_ns));
47 }
48
Swappy_setUseAffinity(bool tf)49 void Swappy_setUseAffinity(bool tf) {
50 Settings::getInstance()->setUseAffinity(tf);
51 }
52
Swappy_setSwapIntervalNS(uint64_t swap_ns)53 void Swappy_setSwapIntervalNS(uint64_t swap_ns) {
54 Settings::getInstance()->setSwapIntervalNS(swap_ns);
55 }
56
Swappy_getRefreshPeriodNanos()57 uint64_t Swappy_getRefreshPeriodNanos() {
58 return Settings::getInstance()->getRefreshPeriod().count();
59 }
60
Swappy_getUseAffinity()61 bool Swappy_getUseAffinity() {
62 return Settings::getInstance()->getUseAffinity();
63 }
64
Swappy_getSwapIntervalNS()65 uint64_t Swappy_getSwapIntervalNS() {
66 return Swappy::getSwapIntervalNS();
67 }
68
Swappy_injectTracer(const SwappyTracer * t)69 void Swappy_injectTracer(const SwappyTracer *t) {
70 Swappy::addTracer(t);
71 }
72
Swappy_setAutoSwapInterval(bool enabled)73 void Swappy_setAutoSwapInterval(bool enabled) {
74 Swappy::setAutoSwapInterval(enabled);
75 }
76
Swappy_setAutoPipelineMode(bool enabled)77 void Swappy_setAutoPipelineMode(bool enabled) {
78 Swappy::setAutoPipelineMode(enabled);
79 }
80
Swappy_enableStats(bool enabled)81 void Swappy_enableStats(bool enabled) {
82 Swappy::enableStats(enabled);
83 }
84
Swappy_recordFrameStart(EGLDisplay display,EGLSurface surface)85 void Swappy_recordFrameStart(EGLDisplay display, EGLSurface surface) {
86 Swappy::recordFrameStart(display, surface);
87 }
88
Swappy_getStats(Swappy_Stats * stats)89 void Swappy_getStats(Swappy_Stats *stats) {
90 Swappy::getStats(stats);
91 }
92
Swappy_isEnabled()93 bool Swappy_isEnabled() {
94 return Swappy::isEnabled();
95 }
96
97 } // extern "C" {
98