• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 RS_COMMON_HOOK_H
17 #define RS_COMMON_HOOK_H
18 
19 #include <atomic>
20 #include <functional>
21 #include <string>
22 #include <unordered_map>
23 
24 #include "animation/rs_frame_rate_range.h"
25 
26 namespace OHOS::Rosen {
27 class RsCommonHook {
28 public:
29     static RsCommonHook& Instance();
30     void RegisterStartNewAnimationListener(std::function<void(const std::string&)> listener);
31     void OnStartNewAnimation(const std::string &componentName);
32     // source crop tuning
33     void SetVideoSurfaceFlag(bool videoSurfaceFlag);
34     bool GetVideoSurfaceFlag() const;
35 
36     // use in updating hwcnode hardware state with background alpha
37     void SetHardwareEnabledByHwcnodeBelowSelfInAppFlag(bool hardwareEnabledByHwcNodeSkippedFlag);
38     void SetHardwareEnabledByBackgroundAlphaFlag(bool hardwareEnabledByBackgroundAlphaSkippedFlag);
39     bool GetHardwareEnabledByHwcnodeBelowSelfInAppFlag() const;
40     bool GetHardwareEnabledByBackgroundAlphaFlag() const;
41     void SetComponentPowerFpsFunc(std::function<void(FrameRateRange& range)> func);
42     void GetComponentPowerFps(FrameRateRange& range);
43     bool GetIsWhiteListForSolidColorLayerFlag() const;
44     void SetIsWhiteListForSolidColorLayerFlag(bool isWhiteListForSolidColorLayerFlag);
45 
46 private:
47     std::function<void(const std::string&)> startNewAniamtionFunc_ = nullptr;
48     // source crop tuning
49     std::atomic<bool> videoSurfaceFlag_{false};
50 
51     // use in updating hwcnode hardware state with background alpha
52     std::atomic<bool> hardwareEnabledByHwcnodeSkippedFlag_{false};
53     std::atomic<bool> hardwareEnabledByBackgroundAlphaSkippedFlag_{false};
54     std::atomic<bool> isWhiteListForSolidColorLayerFlag_{false};
55     std::function<void(FrameRateRange& range)> componentPowerFpsFunc_ = nullptr;
56 };
57 } // namespace OHOS::Rosen
58 #endif