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 RENDER_SERVICE_BASE_DISPLAY_ENGINE_RS_LUMINANCE_CONTROL_H 17 #define RENDER_SERVICE_BASE_DISPLAY_ENGINE_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 CLOSEHDR_SCENEID : uint32_t { 28 MULTI_DISPLAY = 0, 29 CLOSEHDR_SCENEID_MAX 30 }; 31 32 enum HdrStatus : uint32_t { 33 NO_HDR = 0x0000, 34 HDR_PHOTO = 0x0001, 35 HDR_VIDEO = 0x0010, 36 AI_HDR_VIDEO = 0x0100, 37 }; 38 39 class RSB_EXPORT RSLuminanceControl { 40 public: 41 RSLuminanceControl(const RSLuminanceControl&) = delete; 42 RSLuminanceControl& operator=(const RSLuminanceControl&) = delete; 43 RSLuminanceControl(RSLuminanceControl&&) = delete; 44 RSLuminanceControl& operator=(RSLuminanceControl&&) = delete; 45 46 RSB_EXPORT static RSLuminanceControl& Get(); 47 RSB_EXPORT void Init(); 48 49 RSB_EXPORT bool SetHdrStatus(ScreenId screenId, HdrStatus displayHdrstatus); 50 RSB_EXPORT bool IsHdrOn(ScreenId screenId); 51 RSB_EXPORT bool IsDimmingOn(ScreenId screenId); 52 RSB_EXPORT void DimmingIncrease(ScreenId screenId); 53 54 RSB_EXPORT void SetSdrLuminance(ScreenId screenId, uint32_t level); 55 RSB_EXPORT uint32_t GetNewHdrLuminance(ScreenId screenId); 56 RSB_EXPORT void SetNowHdrLuminance(ScreenId screenId, uint32_t level); 57 RSB_EXPORT bool IsNeedUpdateLuminance(ScreenId screenId); 58 59 RSB_EXPORT float GetSdrDisplayNits(ScreenId screenId); 60 RSB_EXPORT float GetDisplayNits(ScreenId screenId); 61 RSB_EXPORT double GetHdrBrightnessRatio(ScreenId screenId, int32_t mode); 62 RSB_EXPORT float CalScaler(const float& maxContentLightLevel, 63 int32_t dynamicMetadataSize, 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 RSB_EXPORT bool IsCloseHardwareHdr(); 69 70 private: 71 RSLuminanceControl() = default; 72 ~RSLuminanceControl(); 73 #ifdef ROSEN_OHOS 74 bool LoadLibrary(); 75 bool LoadStatusControl(); 76 bool LoadLumControl(); 77 bool LoadTmoControl(); 78 void CloseLibrary(); 79 80 bool initStatus_{false}; 81 void *extLibHandle_{nullptr}; 82 83 using SetHdrStatusFunc = bool(*)(ScreenId, HdrStatus); 84 using IsHdrOnFunc = bool(*)(ScreenId); 85 using IsDimmingOnFunc = bool(*)(ScreenId); 86 using DimmingIncreaseFunc = void(*)(ScreenId); 87 using SetSdrLuminanceFunc = void(*)(ScreenId, uint32_t); 88 using GetNewHdrLuminanceFunc = uint32_t(*)(ScreenId); 89 using SetNowHdrLuminanceFunc = void(*)(ScreenId, uint32_t); 90 using IsNeedUpdateLuminanceFunc = bool(*)(ScreenId); 91 using GetSdrDisplayNitsFunc = float(*)(ScreenId); 92 using GetDisplayNitsFunc = float(*)(ScreenId); 93 using GetNonlinearRatioFunc = double(*)(ScreenId, int32_t); 94 using CalScalerFunc = float(*)(const float&, int32_t, const float&); 95 using IsHdrPictureOnFunc = bool(*)(); 96 using IsForceCloseHdrFunc = bool(*)(); 97 using ForceCloseHdrFunc = void(*)(uint32_t, bool); 98 using IsCloseHardwareHdrFunc = 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 GetSdrDisplayNitsFunc getSdrDisplayNits_{nullptr}; 109 GetDisplayNitsFunc getDisplayNits_{nullptr}; 110 GetNonlinearRatioFunc getNonlinearRatio_{nullptr}; 111 CalScalerFunc calScaler_{nullptr}; 112 IsHdrPictureOnFunc isHdrPictureOn_{nullptr}; 113 IsForceCloseHdrFunc isForceCloseHdr_{nullptr}; 114 ForceCloseHdrFunc forceCloseHdr_{nullptr}; 115 IsCloseHardwareHdrFunc isCloseHardwareHdr_{nullptr}; 116 #endif 117 }; 118 119 } // namespace Rosen 120 } // namespace OHOS 121 122 #endif // RENDER_SERVICE_BASE_DISPLAY_ENGINE_RS_LUMINANCE_CONTROL_H 123