1 /*
2  * Copyright (c) 2020-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 /**
17  * @addtogroup UI_Utils
18  * @{
19  *
20  * @brief Defines basic UI utils.
21  *
22  * @since 1.0
23  * @version 1.0
24  */
25 
26 /**
27  * @file sys_info.h
28  *
29  * @brief Declares the system information about the graphics module, including the function to obtain the information
30  *        about FPS, which needs to be enabled by the <b>ENABLE_FPS_SUPPORT</b> macro.
31  *
32  * @since 1.0
33  * @version 1.0
34  */
35 
36 #ifndef GRAPHIC_LITE_SYS_INFO_H
37 #define GRAPHIC_LITE_SYS_INFO_H
38 
39 #include "graphic_config.h"
40 #include "gfx_utils/heap_base.h"
41 
42 namespace OHOS {
43 /**
44  * @brief Obtains the system information. Currently, the FPS information can be obtained. To enable the FPS feature,
45  *        enable the <b>ENABLE_FPS_SUPPORT</b> macro.
46  *
47  * @since 1.0
48  * @version 1.0
49  */
50 class SysInfo {
51 public:
52     /**
53      * @brief Enumerates the FPS capture types.
54      *
55      * @since 1.0
56      * @version 1.0
57      */
58     enum FPSCalculateType {
59         /** Fixed time sampling: The system collects the number of page refresh times within one second. */
60         FPS_CT_FIXED_TIME,
61         /**
62          * Average sampling: The system collects statistics on the average frame rate of 100 frames. No extra space is
63          * required to store the data of each frame. The precision is not as high as that of precise sampling.
64          */
65         FPS_CT_AVERAGE_SAMPLING,
66         /**
67          * Precise sampling: The system collects statistics on the average frame rate of the current 100 frames. Extra
68          * space is required to save the data of each frame. The result is more precise than that of average sampling.
69          */
70         FPS_CT_PRECISE_SAMPLING
71     };
72 
73     /**
74      * @brief Called when the FPS changes.
75      *
76      * @since 1.0
77      * @version 1.0
78      */
79     class OnFPSChangedListener : public HeapBase {
80     public:
81         /**
82          * @brief A constructor used to create an <b>OnFPSChangedListener</b> instance with the default sampling type
83          *        <b>FPS_CT_FIXED_TIME</b>.
84          *
85          * @since 1.0
86          * @version 1.0
87          */
OnFPSChangedListener()88         OnFPSChangedListener() : type_(FPS_CT_FIXED_TIME) {}
89 
90         /**
91          * @brief A destructor used to delete the <b>OnFPSChangedListener</b> instance.
92          *
93          * @since 1.0
94          * @version 1.0
95          */
~OnFPSChangedListener()96         virtual ~OnFPSChangedListener() {}
97 
98         /**
99          * @brief Called when the FPS data changes.
100          *
101          * @param newFPS Indicates the FPS data.
102          * @since 1.0
103          * @version 1.0
104          */
105         virtual void OnFPSChanged(float newFPS) = 0;
106 
107         /**
108          * @brief Obtains the FPS sampling type.
109          *
110          * @return Returns the FPS sampling type. For details, see {@link FPSCalculateType}.
111          * @since 1.0
112          * @version 1.0
113          */
GetFPSCalculateType()114         FPSCalculateType GetFPSCalculateType() const
115         {
116             return type_;
117         }
118 
119         /**
120          * @brief Sets the FPS sampling type.
121          *
122          * @param type Indicates the FPS sampling type. For details, see {@link FPSCalculateType}.
123          * @since 1.0
124          * @version 1.0
125          */
SetFPSCalculateType(FPSCalculateType type)126         void SetFPSCalculateType(FPSCalculateType type)
127         {
128             type_ = type;
129         }
130 
131     private:
132         FPSCalculateType type_;
133     };
134 
135     /**
136      * @brief Obtains the FPS data.
137      *
138      * @return Returns the FPS data.
139      * @since 1.0
140      * @version 1.0
141      */
142     static float GetFPS();
143 
144     /**
145      * @brief Registers the listener for notifying the FPS changes.
146      *
147      * @param onFPSChangedListener Indicates the pointer to the FPS change notification function. For details, see
148      *                             {@link OnFPSChangedListener}.
149      * @since 1.0
150      * @version 1.0
151      */
152     static void RegisterFPSChangedListener(OnFPSChangedListener* onFPSChangedListener);
153 
154 private:
155     SysInfo() = default;
156     ~SysInfo() = default;
157 };
158 } // namespace OHOS
159 #endif
160