1 /*
2  * Copyright (c) 2024 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 #ifndef C_INCLUDE_NATIVE_DISPLAY_SOLOIST_H_
17 #define C_INCLUDE_NATIVE_DISPLAY_SOLOIST_H_
18 
19 /**
20  * @addtogroup NativeDisplaySoloist
21  * @{
22  *
23  * @brief Provides the native displaySoloist capability.
24  *
25  * @since 12
26  * @version 1.0
27  */
28 
29 /**
30  * @file native_display_soloist.h
31  *
32  * @brief Defines the functions for obtaining and using a native displaySoloist.
33  * @syscap SystemCapability.Graphic.Graphic2D.HyperGraphicManager
34  * @library libnative_display_soloist.so
35  * @since 12
36  * @version 1.0
37  */
38 
39 #include <stdint.h>
40 #include <stdbool.h>
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44 
45 /**
46  * @brief Defines the native displaySoloist struct.
47  *
48  * @since 12
49  * @version 1.0
50  */
51 typedef struct OH_DisplaySoloist OH_DisplaySoloist;
52 
53 /**
54  * @brief Defines the native displaySoloist callback.
55  *
56  * @param timestamp Indicates the current timestamp.
57  * @param targetTimestamp Indicates the target timestamp.
58  * @param data Indicates the pointer to user data.
59  * @since 12
60  * @version 1.0
61  */
62 typedef void (*OH_DisplaySoloist_FrameCallback)(long long timestamp, long long targetTimestamp, void* data);
63 
64 /**
65  * @brief Defines the expected frame rate range struct.
66  *
67  * @since 12
68  * @version 1.0
69  */
70 typedef struct {
71     /** The minimum frame rate of dynamical callback rate range. */
72     int32_t min;
73     /** The maximum frame rate of dynamical callback rate range. */
74     int32_t max;
75     /** The expected frame rate of dynamical callback rate range. */
76     int32_t expected;
77 } DisplaySoloist_ExpectedRateRange;
78 
79 /**
80  * @brief Creates a <b>OH_DisplaySoloist</b> instance.\n
81  *
82  * @param useExclusiveThread Indicates whether the vsync run in a exclusive thread.
83  * @return Returns the pointer to the <b>OH_DisplaySoloist</b> instance created if the execution is successful.
84  * if nullptr is returned, the creation fails.
85  * the possible cause of the failure is that the available memory is empty.
86  * @since 12
87  * @version 1.0
88  */
89 OH_DisplaySoloist* OH_DisplaySoloist_Create(bool useExclusiveThread);
90 
91 /**
92  * @brief Destroys a <b>OH_DisplaySoloist</b> instance and reclaims the memory occupied by the object.
93  *
94  * @param displaySoloist Indicates the pointer to a native displaySoloist.
95  * @return Returns int32_t, returns 0 if the execution is successful, returns -1 if displaySoloist is incorrect.
96  * @since 12
97  * @version 1.0
98  */
99 int32_t OH_DisplaySoloist_Destroy(OH_DisplaySoloist* displaySoloist);
100 
101 /**
102  * @brief Start to request next vsync with callback.
103  *
104  * @param displaySoloist Indicates the pointer to a native displaySoloist.
105  * @param callback Indicates the OH_DisplaySoloist_FrameCallback which will be called when next vsync coming.
106  * @param data Indicates data whick will be used in callback.
107  * @return Returns int32_t, returns 0 if the execution is successful.
108  * returns -1 if displaySoloist or callback is incorrect.
109  * @since 12
110  * @version 1.0
111  */
112 int32_t OH_DisplaySoloist_Start(
113     OH_DisplaySoloist* displaySoloist, OH_DisplaySoloist_FrameCallback callback, void* data);
114 
115 /**
116  * @brief Stop to request next vsync with callback.
117  *
118  * @param displaySoloist Indicates the pointer to a native displaySoloist.
119  * @return Returns int32_t, returns 0 if the execution is successful, returns -1 if displaySoloist is incorrect.
120  * @since 12
121  * @version 1.0
122  */
123 int32_t OH_DisplaySoloist_Stop(OH_DisplaySoloist* displaySoloist);
124 
125 /**
126  * @brief Set vsync expected frame rate range.
127  *
128  * @param displaySoloist Indicates the pointer to a native displaySoloist.
129  * @param range Indicates the pointer to an expected rate range.
130  * @return Returns int32_t, returns 0 if the execution is successful
131  * returns -1 if displaySoloist or range is incorrect.
132  * @since 12
133  * @version 1.0
134  */
135 int32_t OH_DisplaySoloist_SetExpectedFrameRateRange(
136     OH_DisplaySoloist* displaySoloist, DisplaySoloist_ExpectedRateRange* range);
137 
138 #ifdef __cplusplus
139 }
140 #endif
141 
142 #endif
143 /** @} */
144