• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2022 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 NativeVsync
18  * @{
19  *
20  * @brief Provides the native vsync capability.
21  *
22  * @syscap SystemCapability.Graphic.Graphic2D.NativeVsync
23  * @since 9
24  * @version 1.0
25  */
26 
27 /**
28  * @file native_vsync.h
29  *
30  * @brief Defines the functions for obtaining and using a native vsync.
31  *
32  * @kit ArkGraphics2D
33  * @library libnative_vsync.so
34  * @syscap SystemCapability.Graphic.Graphic2D.NativeVsync
35  * @since 9
36  * @version 1.0
37  */
38 
39 #ifndef NDK_INCLUDE_NATIVE_VSYNC_H_
40 #define NDK_INCLUDE_NATIVE_VSYNC_H_
41 
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45 
46 struct OH_NativeVSync;
47 typedef struct OH_NativeVSync OH_NativeVSync;
48 typedef void (*OH_NativeVSync_FrameCallback)(long long timestamp, void *data);
49 
50 /**
51  * @brief Creates a <b>NativeVsync</b> instance.\n
52  * A new <b>NativeVsync</b> instance is created each time this function is called.
53  *
54  * @syscap SystemCapability.Graphic.Graphic2D.NativeVsync
55  * @param name Indicates the vsync connection name.
56  * @param length Indicates the name's length.
57  * @return Returns the pointer to the <b>NativeVsync</b> instance created.
58  * @since 9
59  * @version 1.0
60  */
61 OH_NativeVSync* OH_NativeVSync_Create(const char* name, unsigned int length);
62 
63 /**
64  * @brief Delete the NativeVsync instance.
65  *
66  * @syscap SystemCapability.Graphic.Graphic2D.NativeVsync
67  * @param nativeVsync Indicates the pointer to a <b>NativeVsync</b> instance.
68  * @since 9
69  * @version 1.0
70  */
71 void OH_NativeVSync_Destroy(OH_NativeVSync* nativeVsync);
72 
73 /**
74  * @brief Creates a <b>NativeVsync</b> instance.\n
75  * A new <b>NativeVsync</b> instance is created each time this function is called.
76  *
77  * @syscap SystemCapability.Graphic.Graphic2D.NativeVsync
78  * @param windowID Indicates the id of the associated window.
79  * @param name Indicates the vsync connection name.
80  * @param length Indicates the name's length.
81  * @return Returns the pointer to the <b>NativeVsync</b> instance created.
82  * @since 14
83  * @version 1.0
84  */
85 OH_NativeVSync* OH_NativeVSync_Create_ForAssociatedWindow(uint64_t windowID, const char* name, unsigned int length);
86 /**
87  * @brief Request next vsync with callback.
88  * If you call this interface multiple times in one frame, it will only call the last callback.
89  *
90  * @syscap SystemCapability.Graphic.Graphic2D.NativeVsync
91  * @param nativeVsync Indicates the pointer to a NativeVsync.
92  * @param callback Indicates the OH_NativeVSync_FrameCallback which will be called when next vsync coming.
93  * @param data Indicates data which will be used in callback.
94  * @return {@link NATIVE_ERROR_OK} 0 - Success.
95  *     {@link NATIVE_ERROR_INVALID_ARGUMENTS} 40001000 - the parameter nativeVsync is NULL or callback is NULL.
96  *     {@link NATIVE_ERROR_BINDER_ERROR} 50401000 - ipc send failed.
97  * @since 9
98  * @version 1.0
99  */
100 int OH_NativeVSync_RequestFrame(OH_NativeVSync* nativeVsync, OH_NativeVSync_FrameCallback callback, void* data);
101 
102 /**
103  * @brief Request next vsync with callback.
104  * If this function is called multiple times in one vsync period, all these callbacks and dataset will be called.
105  *
106  * @syscap SystemCapability.Graphic.Graphic2D.NativeVsync
107  * @param nativeVsync Indicates the pointer to a NativeVsync.
108  * @param callback Indicates the OH_NativeVSync_FrameCallback which will be called when next vsync coming.
109  * @param data Indicates data which will be used in callback.
110  * @return {@link NATIVE_ERROR_OK} 0 - Success.
111  *     {@link NATIVE_ERROR_INVALID_ARGUMENTS} 40001000 - the parameter nativeVsync is NULL or callback is NULL.
112  *     {@link NATIVE_ERROR_BINDER_ERROR} 50401000 - ipc send failed.
113  * @since 12
114  * @version 1.0
115  */
116 int OH_NativeVSync_RequestFrameWithMultiCallback(
117     OH_NativeVSync* nativeVsync, OH_NativeVSync_FrameCallback callback, void* data);
118 
119 /**
120  * @brief Get vsync period.
121  *
122  * @syscap SystemCapability.Graphic.Graphic2D.NativeVsync
123  * @param nativeVsync Indicates the pointer to a NativeVsync.
124  * @param period Indicates the vsync period.
125  * @return Returns int32_t, return value == 0, success, otherwise, failed.
126  * @since 10
127  * @version 1.0
128  */
129 int OH_NativeVSync_GetPeriod(OH_NativeVSync* nativeVsync, long long* period);
130 
131 /**
132  * @brief Enables DVSync to improve the smoothness of self-drawing animations.
133  * DVSync, short for Decoupled VSync, is a frame timing management policy that is decoupled from the hardware's VSync.
134  * DVSync drives the early rendering of upcoming animation frames by sending VSync signals with future timestamps.
135  * These frames are stored in a frame buffer queue. This helps DVSync reduce potential frame drop and therefore
136  * enhances the smoothness of animations.
137  * DVSync requires free self-drawing frame buffers to store these pre-rendered animation frames.
138  * Therefore, you must ensure that at least one free frame buffer is available. Otherwise, do not enable DVSync.
139  * After DVSync is enabled, you must correctly respond to the early VSync signals and request the subsequent VSync
140  * after the animation frame associated with the previous VSync is complete. In addition, the self-drawing frames must
141  * carry timestamps that align with VSync.
142  * After the animation ends, disable DVSync.
143  * Only phones and tablets support DVSync.
144  * On a platform that does not support DVSync or if another application has enabled DVSync, the attempt to enable it
145  * will not take effect, and the application still receives normal VSync signals.
146  *
147  * @syscap SystemCapability.Graphic.Graphic2D.NativeVsync
148  * @param nativeVsync Indicates the pointer to a NativeVsync.
149  * @param enable Whether to enable DVSync.The value true means to enable DVSync, and false means the opposite.
150  * @return {@link NATIVE_ERROR_OK} 0 - Success.
151  *     {@link NATIVE_ERROR_INVALID_ARGUMENTS} 40001000 - the parameter nativeVsync is NULL.
152  *     {@link NATIVE_ERROR_BINDER_ERROR} 50401000 - ipc send failed.
153  * @since 14
154  * @version 1.0
155  */
156 int OH_NativeVSync_DVSyncSwitch(OH_NativeVSync* nativeVsync, bool enable);
157 #ifdef __cplusplus
158 }
159 #endif
160 
161 /** @} */
162 #endif