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