• 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 #include <stdint.h>
43 
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
47 
48 struct OH_NativeVSync;
49 typedef struct OH_NativeVSync OH_NativeVSync;
50 typedef void (*OH_NativeVSync_FrameCallback)(long long timestamp, void *data);
51 
52 /**
53  * @brief Creates a <b>NativeVsync</b> instance.\n
54  * A new <b>NativeVsync</b> instance is created each time this function is called.
55  *
56  * @syscap SystemCapability.Graphic.Graphic2D.NativeVsync
57  * @param name Indicates the vsync connection name.
58  * @param length Indicates the name's length.
59  * @return Returns the pointer to the <b>NativeVsync</b> instance created.
60  * @since 9
61  * @version 1.0
62  */
63 OH_NativeVSync* OH_NativeVSync_Create(const char* name, unsigned int length);
64 
65 /**
66  * @brief Destroys an <b>OH_NativeVSync</b> instance.
67  * Once the <b>OH_NativeVSync</b> pointer is destroyed, it must not be used to prevent dangling pointer problems.
68  * Pay special attention to the management of the <b>OH_NativeVSync</b> pointer in concurrent multithreaded scenarios.
69  *
70  * @syscap SystemCapability.Graphic.Graphic2D.NativeVsync
71  * @param nativeVsync Pointer to an <b>OH_NativeVSync</b> instance.
72  * @since 9
73  * @version 1.0
74  */
75 void OH_NativeVSync_Destroy(OH_NativeVSync* nativeVsync);
76 
77 /**
78  * @brief Creates a <b>NativeVsync</b> instance.\n
79  * A new <b>NativeVsync</b> instance is created each time this function is called.
80  *
81  * @syscap SystemCapability.Graphic.Graphic2D.NativeVsync
82  * @param windowID Indicates the id of the associated window.
83  * @param name Indicates the vsync connection name.
84  * @param length Indicates the name's length.
85  * @return Returns the pointer to the <b>NativeVsync</b> instance created.
86  * @since 14
87  * @version 1.0
88  */
89 OH_NativeVSync* OH_NativeVSync_Create_ForAssociatedWindow(uint64_t windowID, const char* name, unsigned int length);
90 /**
91  * @brief Request next vsync with callback.
92  * If you call this interface multiple times in one frame, it will only call the last callback.
93  *
94  * @syscap SystemCapability.Graphic.Graphic2D.NativeVsync
95  * @param nativeVsync Indicates the pointer to a NativeVsync.
96  * @param callback Indicates the OH_NativeVSync_FrameCallback which will be called when next vsync coming.
97  * @param data Indicates data which will be used in callback.
98  * @return {@link NATIVE_ERROR_OK} 0 - Success.
99  *     {@link NATIVE_ERROR_INVALID_ARGUMENTS} 40001000 - the parameter nativeVsync is NULL or callback is NULL.
100  *     {@link NATIVE_ERROR_BINDER_ERROR} 50401000 - ipc send failed.
101  * @since 9
102  * @version 1.0
103  */
104 int OH_NativeVSync_RequestFrame(OH_NativeVSync* nativeVsync, OH_NativeVSync_FrameCallback callback, void* data);
105 
106 /**
107  * @brief Request next vsync with callback.
108  * If this function is called multiple times in one vsync period, all these callbacks and dataset will be called.
109  *
110  * @syscap SystemCapability.Graphic.Graphic2D.NativeVsync
111  * @param nativeVsync Indicates the pointer to a NativeVsync.
112  * @param callback Indicates the OH_NativeVSync_FrameCallback which will be called when next vsync coming.
113  * @param data Indicates data which will be used in callback.
114  * @return {@link NATIVE_ERROR_OK} 0 - Success.
115  *     {@link NATIVE_ERROR_INVALID_ARGUMENTS} 40001000 - the parameter nativeVsync is NULL or callback is NULL.
116  *     {@link NATIVE_ERROR_BINDER_ERROR} 50401000 - ipc send failed.
117  * @since 12
118  * @version 1.0
119  */
120 int OH_NativeVSync_RequestFrameWithMultiCallback(
121     OH_NativeVSync* nativeVsync, OH_NativeVSync_FrameCallback callback, void* data);
122 
123 /**
124  * @brief Obtains the VSync period.
125  * The VSync period is refreshed only when the <b>OH_NativeVSync_FrameCallback</b> callback is received
126  * following a request for a VSync signal via <b>OH_NativeVSync_RequestFrame</b>.
127  * To obtain the VSync period for the first time using this function,
128  * you need to call <b>OH_NativeVSync_RequestFrame</b> to request a VSync signal.
129  * Once the <b>OH_NativeVSync_FrameCallback</b> callback is received, the vsync period can be obtained.
130  *
131  * @syscap SystemCapability.Graphic.Graphic2D.NativeVsync
132  * @param nativeVsync Indicates the pointer to a NativeVsync.
133  * @param period Indicates the vsync period.
134  * @return Returns int32_t, return value == 0, success, otherwise, failed.
135  * @since 10
136  * @version 1.0
137  */
138 int OH_NativeVSync_GetPeriod(OH_NativeVSync* nativeVsync, long long* period);
139 
140 /**
141  * @brief Enables DVSync to improve the smoothness of self-drawing animations.
142  * DVSync, short for Decoupled VSync, is a frame timing management policy that is decoupled from the hardware's VSync.
143  * DVSync drives the early rendering of upcoming animation frames by sending VSync signals with future timestamps.
144  * These frames are stored in a frame buffer queue. This helps DVSync reduce potential frame drop and therefore
145  * enhances the smoothness of animations.
146  * DVSync requires free self-drawing frame buffers to store these pre-rendered animation frames.
147  * Therefore, you must ensure that at least one free frame buffer is available. Otherwise, do not enable DVSync.
148  * After DVSync is enabled, you must correctly respond to the early VSync signals and request the subsequent VSync
149  * after the animation frame associated with the previous VSync is complete. In addition, the self-drawing frames must
150  * carry timestamps that align with VSync.
151  * After the animation ends, disable DVSync.
152  * Only phones and tablets support DVSync.
153  * On a platform that does not support DVSync or if another application has enabled DVSync, the attempt to enable it
154  * will not take effect, and the application still receives normal VSync signals.
155  *
156  * @syscap SystemCapability.Graphic.Graphic2D.NativeVsync
157  * @param nativeVsync Indicates the pointer to a NativeVsync.
158  * @param enable Whether to enable DVSync.The value true means to enable DVSync, and false means the opposite.
159  * @return {@link NATIVE_ERROR_OK} 0 - Success.
160  *     {@link NATIVE_ERROR_INVALID_ARGUMENTS} 40001000 - the parameter nativeVsync is NULL.
161  *     {@link NATIVE_ERROR_BINDER_ERROR} 50401000 - ipc send failed.
162  * @since 14
163  * @version 1.0
164  */
165 int OH_NativeVSync_DVSyncSwitch(OH_NativeVSync* nativeVsync, bool enable);
166 #ifdef __cplusplus
167 }
168 #endif
169 
170 /** @} */
171 #endif