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 #include "common/rs_macros.h" 21 #include "screen_manager/screen_types.h" 22 #include <vector> 23 24 namespace OHOS { 25 namespace Rosen { 26 27 namespace RSLuminanceConst { 28 constexpr float DEFAULT_CAPTURE_HDR_NITS = 1000.0f; 29 constexpr float DEFAULT_CAST_HDR_NITS = 1000.0f; 30 constexpr float DEFAULT_CAST_SDR_NITS = 203.0f; 31 } 32 33 enum CLOSEHDR_SCENEID : uint32_t { 34 MULTI_DISPLAY = 0, 35 CLOSEHDR_SCENEID_MAX 36 }; 37 38 enum HDRComponentType : uint32_t { 39 IMAGE = 0, 40 UICOMPONENT, 41 EFFECT, 42 }; 43 44 enum HdrStatus : uint32_t { 45 NO_HDR = 0x0000, 46 HDR_PHOTO = 0x0001, 47 HDR_VIDEO = 0x0010, 48 AI_HDR_VIDEO = 0x0100, 49 HDR_EFFECT = 0x1000, 50 }; 51 52 class RSLuminanceControlInterface { 53 public: 54 virtual ~RSLuminanceControlInterface() = default; 55 virtual bool Init() = 0; 56 virtual bool SetHdrStatus(ScreenId screenId, HdrStatus hdrStatus) = 0; 57 virtual bool IsHdrOn(ScreenId screenId) const = 0; 58 virtual bool IsDimmingOn(ScreenId screenId) = 0; 59 virtual void DimmingIncrease(ScreenId screenId) = 0; 60 virtual void SetSdrLuminance(ScreenId screenId, uint32_t level) = 0; 61 virtual uint32_t GetNewHdrLuminance(ScreenId screenId) = 0; 62 virtual void SetNowHdrLuminance(ScreenId screenId, uint32_t level) = 0; 63 virtual bool IsNeedUpdateLuminance(ScreenId screenId) = 0; 64 virtual float GetSdrDisplayNits(ScreenId screenId) = 0; 65 virtual float GetDisplayNits(ScreenId screenId) = 0; 66 virtual double GetNonlinearRatio(ScreenId screenId, uint32_t mode) = 0; 67 virtual float CalScaler(const float& maxContentLightLevel, 68 const std::vector<uint8_t>& dynamicMetadata, const float& ratio) = 0; 69 virtual bool IsHdrPictureOn() = 0; 70 virtual bool IsForceCloseHdr() const = 0; 71 virtual void ForceCloseHdr(uint32_t closeHdrSceneId, bool forceCloseHdr) = 0; 72 virtual bool IsCloseHardwareHdr() const = 0; 73 virtual bool IsScreenNoHeadroom(ScreenId) = 0; 74 virtual bool IsEnableImageDetailEnhance() = 0; 75 }; 76 77 class RSB_EXPORT RSLuminanceControl { 78 public: 79 RSLuminanceControl(const RSLuminanceControl&) = delete; 80 RSLuminanceControl& operator=(const RSLuminanceControl&) = delete; 81 RSLuminanceControl(RSLuminanceControl&&) = delete; 82 RSLuminanceControl& operator=(RSLuminanceControl&&) = delete; 83 84 RSB_EXPORT static RSLuminanceControl& Get(); 85 RSB_EXPORT void Init(); 86 87 RSB_EXPORT bool SetHdrStatus(ScreenId screenId, HdrStatus displayHdrstatus); 88 RSB_EXPORT bool IsHdrOn(ScreenId screenId); 89 RSB_EXPORT bool IsDimmingOn(ScreenId screenId); 90 RSB_EXPORT void DimmingIncrease(ScreenId screenId); 91 92 RSB_EXPORT void SetSdrLuminance(ScreenId screenId, uint32_t level); 93 RSB_EXPORT uint32_t GetNewHdrLuminance(ScreenId screenId); 94 RSB_EXPORT void SetNowHdrLuminance(ScreenId screenId, uint32_t level); 95 RSB_EXPORT bool IsNeedUpdateLuminance(ScreenId screenId); 96 97 RSB_EXPORT float GetSdrDisplayNits(ScreenId screenId); 98 RSB_EXPORT float GetDisplayNits(ScreenId screenId); 99 RSB_EXPORT double GetHdrBrightnessRatio(ScreenId screenId, uint32_t mode); 100 RSB_EXPORT float CalScaler(const float& maxContentLightLevel, 101 const std::vector<uint8_t>& dynamicMetadata, const float& ratio = 1.0f); 102 RSB_EXPORT bool IsHdrPictureOn(); 103 RSB_EXPORT bool IsForceCloseHdr(); 104 RSB_EXPORT void ForceCloseHdr(uint32_t closeHdrSceneId, bool forceCloseHdr); 105 RSB_EXPORT bool IsCloseHardwareHdr(); 106 RSB_EXPORT bool IsScreenNoHeadroom(ScreenId screenId); 107 RSB_EXPORT bool IsEnableImageDetailEnhance(); 108 109 private: 110 RSLuminanceControl() = default; 111 ~RSLuminanceControl(); 112 #ifdef ROSEN_OHOS 113 bool LoadLibrary(); 114 void CloseLibrary(); 115 116 bool initStatus_{false}; 117 void *extLibHandle_{nullptr}; 118 RSLuminanceControlInterface* rSLuminanceControlInterface_{nullptr}; 119 120 using CreateFunc = RSLuminanceControlInterface*(*)(); 121 using DestroyFunc = void(*)(); 122 123 CreateFunc create_{nullptr}; 124 DestroyFunc destroy_{nullptr}; 125 #endif 126 }; 127 128 } // namespace Rosen 129 } // namespace OHOS 130 131 #endif // RENDER_SERVICE_BASE_DISPLAY_ENGINE_RS_LUMINANCE_CONTROL_H 132