1 /* 2 * Copyright (c) 2025 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_COLOR_TEMPERATURE_H 17 #define RENDER_SERVICE_BASE_DISPLAY_ENGINE_RS_COLOR_TEMPERATURE_H 18 19 #include <cinttypes> 20 #include <functional> 21 #include <vector> 22 23 #include "common/rs_macros.h" 24 #include "screen_manager/screen_types.h" 25 #ifndef ROSEN_CROSS_PLATFORM 26 #include <v1_0/cm_color_space.h> 27 #endif 28 29 30 namespace OHOS { 31 namespace Rosen { 32 #ifndef ROSEN_CROSS_PLATFORM 33 using namespace OHOS::HDI::Display::Graphic::Common::V1_0; 34 #endif 35 36 class RSColorTemperatureInterface { 37 public: 38 virtual ~RSColorTemperatureInterface() = default; 39 virtual bool Init() = 0; 40 virtual void RegisterRefresh(std::function<void()>&& refreshFunc) = 0; 41 virtual void UpdateScreenStatus(ScreenId screenId, ScreenPowerStatus powerStatus) = 0; 42 virtual bool IsDimmingOn(ScreenId screenId) = 0; 43 virtual void DimmingIncrease(ScreenId screenId) = 0; 44 virtual bool IsColorTemperatureOn() const = 0; 45 virtual std::vector<float> GetNewLinearCct(ScreenId screenId) = 0; 46 #ifndef ROSEN_CROSS_PLATFORM 47 virtual std::vector<float> GetLayerLinearCct(ScreenId screenId, 48 const std::vector<uint8_t>& dynamicMetadata, const CM_Matrix srcColorMatrix) = 0; 49 #endif 50 }; 51 52 class RSB_EXPORT RSColorTemperature { 53 public: 54 RSColorTemperature(const RSColorTemperature&) = delete; 55 RSColorTemperature& operator=(const RSColorTemperature&) = delete; 56 RSColorTemperature(RSColorTemperature&) = delete; 57 RSColorTemperature& operator=(RSColorTemperature&&) = delete; 58 59 RSB_EXPORT static RSColorTemperature& Get(); 60 RSB_EXPORT void Init(); 61 62 RSB_EXPORT void RegisterRefresh(std::function<void()>&& refreshFunc); 63 RSB_EXPORT void UpdateScreenStatus(ScreenId screenId, ScreenPowerStatus powerStatus); 64 RSB_EXPORT bool IsDimmingOn(ScreenId screenId); 65 RSB_EXPORT void DimmingIncrease(ScreenId screenId); 66 RSB_EXPORT bool IsColorTemperatureOn() const; 67 RSB_EXPORT std::vector<float> GetNewLinearCct(ScreenId screenId); 68 #ifndef ROSEN_CROSS_PLATFORM 69 RSB_EXPORT std::vector<float> GetLayerLinearCct(ScreenId screenId, 70 const std::vector<uint8_t>& dynamicMetadata, const CM_Matrix srcColorMatrix = CM_Matrix::MATRIX_P3); 71 #endif 72 73 private: 74 RSColorTemperature() = default; 75 ~RSColorTemperature(); 76 77 #ifdef ROSEN_OHOS 78 bool LoadLibrary(); 79 void CloseLibrary(); 80 81 bool initStatus_{false}; 82 void *extLibHandle_{nullptr}; 83 RSColorTemperatureInterface* rSColorTemperatureInterface_{nullptr}; 84 85 using CreateFunc = RSColorTemperatureInterface*(*)(); 86 using DestroyFunc = void(*)(); 87 88 CreateFunc create_{nullptr}; 89 DestroyFunc destroy_{nullptr}; 90 #endif 91 }; 92 93 } // Rosen 94 } // OHOS 95 96 #endif // RENDER_SERVICE_BASE_DISPLAY_ENGINE_RS_COLOR_TEMPERATURE_H