1 /*
2  * Copyright (c) 2021-2023 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 #ifndef RENDER_SERVICE_CLIENT_CORE_PIPELINE_RS_RENDER_FRAME_RATE_LINKER_H
16 #define RENDER_SERVICE_CLIENT_CORE_PIPELINE_RS_RENDER_FRAME_RATE_LINKER_H
17 
18 #include <refbase.h>
19 
20 #include "animation/rs_frame_rate_range.h"
21 #include "common/rs_common_def.h"
22 #include "common/rs_macros.h"
23 
24 namespace OHOS {
25 namespace Rosen {
26 class RSIFrameRateLinkerExpectedFpsUpdateCallback;
27 class RSB_EXPORT RSRenderFrameRateLinker : public std::enable_shared_from_this<RSRenderFrameRateLinker> {
28 public:
29     explicit RSRenderFrameRateLinker(FrameRateLinkerId id);
30     explicit RSRenderFrameRateLinker();
31 
32     RSRenderFrameRateLinker(const RSRenderFrameRateLinker&) = delete;
33     RSRenderFrameRateLinker(const RSRenderFrameRateLinker&&) = delete;
34     RSRenderFrameRateLinker& operator=(const RSRenderFrameRateLinker&) = delete;
35     RSRenderFrameRateLinker& operator=(const RSRenderFrameRateLinker&&) = delete;
36     ~RSRenderFrameRateLinker();
37 
GetId()38     inline FrameRateLinkerId GetId() const
39     {
40         return id_;
41     }
42 
GetAceAnimatorExpectedFrameRate()43     inline int32_t GetAceAnimatorExpectedFrameRate() {
44         return animatorExpectedFrameRate_;
45     }
46 
47     void SetAnimatorExpectedFrameRate(int32_t animatorExpectedFrameRate);
48 
49     void SetExpectedRange(const FrameRateRange& range);
50     const FrameRateRange& GetExpectedRange() const;
51     void SetFrameRate(uint32_t rate);
52     uint32_t GetFrameRate() const;
53 
54     void RegisterExpectedFpsUpdateCallback(pid_t pid, sptr<RSIFrameRateLinkerExpectedFpsUpdateCallback> callback);
55 private:
56     static FrameRateLinkerId GenerateId();
57     FrameRateLinkerId id_ = 0;
58     FrameRateRange expectedRange_;
59     uint32_t frameRate_ = 0;
60     int32_t animatorExpectedFrameRate_ = -1;
61 
62     std::unordered_map<pid_t, sptr<RSIFrameRateLinkerExpectedFpsUpdateCallback>> expectedFpsChangeCallbacks_;
63 };
64 } // namespace Rosen
65 } // namespace OHOS
66 
67 #endif // RENDER_SERVICE_CLIENT_CORE_PIPELINE_RS_RENDER_FRAME_RATE_LINKER_H
68