1e9297d28Sopenharmony_ci/* 2e9297d28Sopenharmony_ci * Copyright (c) 2021 Huawei Device Co., Ltd. 3e9297d28Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4e9297d28Sopenharmony_ci * you may not use this file except in compliance with the License. 5e9297d28Sopenharmony_ci * You may obtain a copy of the License at 6e9297d28Sopenharmony_ci * 7e9297d28Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8e9297d28Sopenharmony_ci * 9e9297d28Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10e9297d28Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11e9297d28Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12e9297d28Sopenharmony_ci * See the License for the specific language governing permissions and 13e9297d28Sopenharmony_ci * limitations under the License. 14e9297d28Sopenharmony_ci */ 15e9297d28Sopenharmony_ci 16e9297d28Sopenharmony_ci#include "native_vsync.h" 17e9297d28Sopenharmony_ci 18e9297d28Sopenharmony_ci#include <iostream> 19e9297d28Sopenharmony_ci#include <thread> 20e9297d28Sopenharmony_ci#include <unistd.h> 21e9297d28Sopenharmony_ci 22e9297d28Sopenharmony_cistatic bool flag = false; 23e9297d28Sopenharmony_cistatic void OnVSync(long long timestamp, void* data) 24e9297d28Sopenharmony_ci{ 25e9297d28Sopenharmony_ci flag = true; 26e9297d28Sopenharmony_ci std::cout << "OnVSync: " << timestamp << std::endl; 27e9297d28Sopenharmony_ci} 28e9297d28Sopenharmony_ci 29e9297d28Sopenharmony_cistatic void ThreadMain(OH_NativeVSync* nativeVSync) 30e9297d28Sopenharmony_ci{ 31e9297d28Sopenharmony_ci OH_NativeVSync_FrameCallback callback = OnVSync; 32e9297d28Sopenharmony_ci OH_NativeVSync_RequestFrame(nativeVSync, callback, nullptr); 33e9297d28Sopenharmony_ci while (!flag) { 34e9297d28Sopenharmony_ci std::cout << "wait for vsync!\n"; 35e9297d28Sopenharmony_ci sleep(1); 36e9297d28Sopenharmony_ci } 37e9297d28Sopenharmony_ci std::cout << "vsync come, end this thread\n"; 38e9297d28Sopenharmony_ci} 39e9297d28Sopenharmony_ciint32_t main(int32_t argc, const char *argv[]) 40e9297d28Sopenharmony_ci{ 41e9297d28Sopenharmony_ci char name[] = "hello_vsync"; 42e9297d28Sopenharmony_ci OH_NativeVSync* nativeVSync = OH_NativeVSync_Create(name, strlen(name)); 43e9297d28Sopenharmony_ci std::thread th(ThreadMain, nativeVSync); 44e9297d28Sopenharmony_ci th.join(); 45e9297d28Sopenharmony_ci OH_NativeVSync_Destroy(nativeVSync); 46e9297d28Sopenharmony_ci return 0; 47e9297d28Sopenharmony_ci}