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_CALCULATION_MANAGER_H
17#define BRIGHTNESS_CALCULATION_MANAGER_H
18
19#include <memory>
20#include <mutex>
21#include <vector>
22
23#include "calculation_curve.h"
24
25namespace OHOS {
26namespace DisplayPowerMgr {
27
28class BrightnessCalculationManager {
29public:
30    BrightnessCalculationManager() = default;
31    virtual ~BrightnessCalculationManager() = default;;
32    BrightnessCalculationManager(const BrightnessCalculationManager&) = delete;
33    BrightnessCalculationManager& operator=(const BrightnessCalculationManager&) = delete;
34    BrightnessCalculationManager(BrightnessCalculationManager&&) = delete;
35    BrightnessCalculationManager& operator=(BrightnessCalculationManager&&) = delete;
36    void InitParameters();
37    float GetInterpolatedValue(float lux);
38    void UpdateCurrentUserId(int userId);
39    void UpdateBrightnessOffset(float posBrightness, float lux);
40    void SetGameModeEnable(bool isGameCurveEnable);
41    void SetCameraModeEnable(bool isCameraCurveEnable);
42    void ResetOffsetFromHumanFactor(bool isOffsetResetEnable, int minOffsetBrightness, int maxOffsetBrightness);
43    int GetDisplayIdWithDisplayMode(int displayMode);
44    int GetSensorIdWithDisplayMode(int displayMode);
45    int GetDisplayIdWithFoldstatus(int foldStatus);
46    int GetSensorIdWithFoldstatus(int foldStatus);
47
48private:
49    void UpdateParaFromReboot();
50    void UpdateCurveAmbientLux(float lux);
51    float GetInterpolatedBrightenssLevel(float positionBrightness, float lux);
52    void UpdateDefaultBrightness(float lux);
53    float GetCurrentBrightness(float lux);
54
55    bool IsDefaultBrightnessMode(float positionBrightness);
56    float GetAmbientOffsetLux();
57    float GetBrightenOffsetNoValidBrightenLux(float lux);
58
59    float GetOffsetLevel(float brightnessStartOrig, float brightnessEndOrig,
60        float brightnessStartNew, float delta);
61    float GetDefaultBrightenOffsetBrightenRaio(float brightnessStartOrig, float brightnessEndOrig,
62        float brightnessStartNew, float deltaStart);
63    float GetDefaultDarkenOffsetBrightenRatio(float brightnessStartOrig, float brightnessEndOrig,
64        float brightnessStartNew, float deltaStart);
65    float GetDefaultDarkenOffsetDarkenRatio(float brightnessStartOrig, float brightnessEndOrig,
66        float brightnessStartNew, float deltaStart);
67    float GetDefaultBrightenOffsetDarkenRatio(float brightnessStartOrig, float brightnessEndOrig,
68        float brightnessStartNew);
69    void ResetDefaultBrightnessOffset();
70
71    BrightnessCalculationCurve mBrightnessCalculationCurve{};
72    int mCurrentUserId{0};
73    bool mIsCameraCurveEnable{false};
74    bool mIsGameCurveEnable{false};
75    float mDelta{0.0f};
76    float mOffsetLux{0.0f};
77    float mPosBrightness{0.0f};
78    bool mIsReboot{false};
79    float mOffsetBrightnessLast{0.0f};
80    float mLastLuxDefaultBrightness{0.0f};
81    float mStartLuxDefaultBrightness{0.0f};
82    float mCurveLux{0.0f};
83    float mDefaultBrightnessFromLux{0.0f};
84    float offsetBrightenAlphaRight{0.0f};
85    float offsetDarkenAlphaLeft{0.0f};
86    float offsetBrightenAlphaLeft{0.0f};
87    float offsetBrightenRatioLeft{0.0f};
88};
89
90} // namespace DisplayPowerMgr
91} // namespace OHOS
92
93#endif // BRIGHTNESS_CALCULATION_MANAGER_H
94