1 /* 2 * Copyright (c) 2025 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 /** 17 * @addtogroup NativeFence 18 * @{ 19 * 20 * @brief Provides the native fence capability 21 * 22 * @since 20 23 * @version 1.0 24 */ 25 26 /** 27 * @file native_fence.h 28 * 29 * @brief Defines the functions for using native fence. 30 * 31 * @kit ArkGraphics2D 32 * @library libnative_fence.so 33 * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow 34 * @since 20 35 * @version 1.0 36 */ 37 38 #ifndef NDK_INCLUDE_NATIVE_FENCE_H_ 39 #define NDK_INCLUDE_NATIVE_FENCE_H_ 40 41 #include <stdint.h> 42 43 #ifdef __cplusplus 44 extern "C" { 45 #endif 46 47 /** 48 * @brief Checks if the fenceFd is valid. 49 * 50 * @param fenceFd Indicates a file descriptor handle, which is used for timing synchronization. 51 * @return Returns true if the fenceFd is valid. 52 * Returns false if the fenceFd is a negative integer. 53 * @since 20 54 * @version 1.0 55 */ 56 bool OH_NativeFence_IsValid(int fenceFd); 57 58 /** 59 * @brief Waits for a fence signal. The maximum waiting time is determined by the timeout parameter. 60 * The incoming fenceFd needs to be closed by the user themselves. 61 * 62 * @param fenceFd Indicates a file descriptor handle, which is used for timing synchronization. 63 * @param timeout Indicates the timeout duration. 64 * The unit is milliseconds, 0 represents immediate return. 65 * @return Returns true if the fence signaled. 66 * Returns false in the following cases: 67 * 1.if the fenceFd is a negative integer. 68 * 2.no event occurred within the specified timeout period. 69 * 3.the underlying poll interface call failed. 70 * 4.the timeout value is 0. 71 * 5.failed to duplicate the file descriptor. 72 * @since 20 73 * @version 1.0 74 */ 75 bool OH_NativeFence_Wait(int fenceFd, uint32_t timeout); 76 77 /** 78 * @brief Waits forever for a fence signal. 79 * The incoming fenceFd needs to be closed by the user themselves. 80 * 81 * @param fenceFd Indicates a file descriptor handle, which is used for timing synchronization. 82 * @return Returns true if the fence signaled. 83 * Returns false in the following cases: 84 * 1.if the fenceFd is a negative integer. 85 * 2.no incidents have occurred, permanent waiting. 86 * 3.failed to duplicate the file descriptor. 87 * @since 20 88 * @version 1.0 89 */ 90 bool OH_NativeFence_WaitForever(int fenceFd); 91 92 /** 93 * @brief Close the fenceFd. 94 * 95 * @param fenceFd Indicates a file descriptor handle, which is used for timing synchronization. 96 * This value is a non negative integer. 97 * @since 20 98 * @version 1.0 99 */ 100 void OH_NativeFence_Close(int fenceFd); 101 #ifdef __cplusplus 102 } 103 #endif 104 /** @} */ 105 #endif