1 /*
2  * Copyright (c) 2023-2023 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 BRIGHTNESS_BASE_H
17 #define BRIGHTNESS_BASE_H
18 
19 #include <ctime>
20 #include <cmath>
21 #include <string>
22 
23 namespace OHOS {
24 namespace DisplayPowerMgr {
25 
26 constexpr uint32_t DEFAULT_DISPLAY_ID = 0;
27 constexpr uint32_t OUTTER_SCREEN_DISPLAY_ID = 5;
28 const float EPSILON = 0.0000001f;
29 const int MSECPERSEC = 1000;
30 const int NSECPERMSEC = 1000000;
31 
32 enum class BrightnessFilterMode {
33     MEAN_FILTER = 0,
34     WEIGHT_FILTER,
35     FITLER_END
36 };
37 
38 enum class BrightnessSceneMode {
39     MODE_DEFAULT = 0,
40     MODE_GAME,
41     MODE_VIDEO,
42     SCENCE_END
43 };
44 
45 enum class BrightnessModeState {
46     CAMERA_MODE,
47     GAME_MODE,
48     DEFAULT_MODE
49 };
50 
GetCurrentTimeMillis()51 inline int64_t GetCurrentTimeMillis()
52 {
53     struct timespec val {};
54     if (clock_gettime(CLOCK_BOOTTIME, &val) == 0) {
55         return static_cast<int64_t>(val.tv_sec) * MSECPERSEC + val.tv_nsec / NSECPERMSEC;
56     }
57     return 0;
58 }
59 
IsEqualF(float a,float b)60 inline bool IsEqualF(float a, float b)
61 {
62     return fabs(a - b) < EPSILON;
63 }
64 } // namespace BrightnessPowerMgr
65 } // namespace OHOS
66 #endif // BRIGHTNESS_BASE_H