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 ROSEN_RENDER_SERVICE_BASE_RS_LUMINANCE_CONTROL_H
17 #define ROSEN_RENDER_SERVICE_BASE_RS_LUMINANCE_CONTROL_H
18 
19 #include <cinttypes>
20 
21 #include "common/rs_macros.h"
22 #include "screen_manager/screen_types.h"
23 
24 namespace OHOS {
25 namespace Rosen {
26 
27 enum HDR_TYPE : int32_t {
28     PHOTO,
29     VIDEO,
30     MAX = 255,
31 };
32 
33 enum CLOSEHDR_SCENEID : uint32_t {
34     MULTI_DISPLAY = 0,
35     CLOSEHDR_SCENEID_MAX
36 };
37 
38 class RSB_EXPORT RSLuminanceControl {
39 public:
40     RSLuminanceControl(const RSLuminanceControl&) = delete;
41     RSLuminanceControl& operator=(const RSLuminanceControl&) = delete;
42     RSLuminanceControl(RSLuminanceControl&&) = delete;
43     RSLuminanceControl& operator=(RSLuminanceControl&&) = delete;
44 
45     RSB_EXPORT static RSLuminanceControl& Get();
46     RSB_EXPORT void Init();
47 
48     RSB_EXPORT bool SetHdrStatus(ScreenId screenId, bool isHdrOn, int32_t type = HDR_TYPE::PHOTO);
49     RSB_EXPORT bool IsHdrOn(ScreenId screenId);
50     RSB_EXPORT bool IsDimmingOn(ScreenId screenId);
51     RSB_EXPORT void DimmingIncrease(ScreenId screenId);
52 
53     RSB_EXPORT void SetSdrLuminance(ScreenId screenId, uint32_t level);
54     RSB_EXPORT uint32_t GetNewHdrLuminance(ScreenId screenId);
55     RSB_EXPORT void SetNowHdrLuminance(ScreenId screenId, uint32_t level);
56     RSB_EXPORT bool IsNeedUpdateLuminance(ScreenId screenId);
57 
58     RSB_EXPORT float GetHdrTmoNits(ScreenId screenId, int32_t mode);
59     RSB_EXPORT float GetSdrDisplayNits(ScreenId screenId);
60     RSB_EXPORT float GetHdrDisplayNits(ScreenId screenId);
61     RSB_EXPORT float GetDisplayNits(ScreenId screenId);
62     RSB_EXPORT double GetHdrBrightnessRatio(ScreenId screenId, int32_t mode);
63     RSB_EXPORT float CalScaler(const float& maxContentLightLevel, const float& ratio = 1.0f);
64     RSB_EXPORT bool IsHdrPictureOn();
65 
66     RSB_EXPORT bool IsForceCloseHdr();
67     RSB_EXPORT void ForceCloseHdr(uint32_t closeHdrSceneId, bool forceCloseHdr);
68 
69 private:
70     RSLuminanceControl() = default;
71     ~RSLuminanceControl();
72 #ifdef ROSEN_OHOS
73     bool LoadLibrary();
74     bool LoadStatusControl();
75     bool LoadLumControl();
76     bool LoadTmoControl();
77     void CloseLibrary();
78 
79     bool initStatus_{false};
80     void *extLibHandle_{nullptr};
81 
82     using SetHdrStatusFunc = bool(*)(ScreenId, bool, int32_t);
83     using IsHdrOnFunc = bool(*)(ScreenId);
84     using IsDimmingOnFunc = bool(*)(ScreenId);
85     using DimmingIncreaseFunc = void(*)(ScreenId);
86     using SetSdrLuminanceFunc = void(*)(ScreenId, uint32_t);
87     using GetNewHdrLuminanceFunc = uint32_t(*)(ScreenId);
88     using SetNowHdrLuminanceFunc = void(*)(ScreenId, uint32_t);
89     using IsNeedUpdateLuminanceFunc = bool(*)(ScreenId);
90     using GetHdrTmoNitsFunc = float(*)(ScreenId, int32_t);
91     using GetSdrDisplayNitsFunc = float(*)(ScreenId);
92     using GetHdrDisplayNitsFunc = float(*)(ScreenId);
93     using GetDisplayNitsFunc = float(*)(ScreenId);
94     using GetNonlinearRatioFunc = double(*)(ScreenId, int32_t);
95     using CalScalerFunc = float(*)(const float&, const float&);
96     using IsHdrPictureOnFunc = bool(*)();
97     using IsForceCloseHdrFunc = bool(*)();
98     using ForceCloseHdrFunc = void(*)(uint32_t, bool);
99 
100     SetHdrStatusFunc setHdrStatus_{nullptr};
101     IsHdrOnFunc isHdrOn_{nullptr};
102     IsDimmingOnFunc isDimmingOn_{nullptr};
103     DimmingIncreaseFunc dimmingIncrease_{nullptr};
104     SetSdrLuminanceFunc setSdrLuminance_{nullptr};
105     GetNewHdrLuminanceFunc getNewHdrLuminance_{nullptr};
106     SetNowHdrLuminanceFunc setNowHdrLuminance_{nullptr};
107     IsNeedUpdateLuminanceFunc isNeedUpdateLuminance_{nullptr};
108     GetHdrTmoNitsFunc getHdrTmoNits_{nullptr};
109     GetSdrDisplayNitsFunc getSdrDisplayNits_{nullptr};
110     GetHdrDisplayNitsFunc getHdrDisplayNits_{nullptr};
111     GetDisplayNitsFunc getDisplayNits_{nullptr};
112     GetNonlinearRatioFunc getNonlinearRatio_{nullptr};
113     CalScalerFunc calScaler_{nullptr};
114     IsHdrPictureOnFunc isHdrPictureOn_{nullptr};
115     IsForceCloseHdrFunc isForceCloseHdr_{nullptr};
116     ForceCloseHdrFunc forceCloseHdr_{nullptr};
117 #endif
118 };
119 
120 } // namespace Rosen
121 } // namespace OHOS
122 
123 #endif // ROSEN_RENDER_SERVICE_BASE_RS_LUMINANCE_CONTROL_H
124