• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <mutex>
19 #include <refbase.h>
20 
21 #include "animation/rs_frame_rate_range.h"
22 #include "common/rs_common_def.h"
23 #include "common/rs_macros.h"
24 
25 namespace OHOS {
26 namespace Rosen {
27 class RSIFrameRateLinkerExpectedFpsUpdateCallback;
28 class RSB_EXPORT RSRenderFrameRateLinker : public std::enable_shared_from_this<RSRenderFrameRateLinker> {
29 public:
30     using ObserverType = std::function<void (const RSRenderFrameRateLinker&)>;
31     using TimePoint = std::atomic<std::chrono::steady_clock::time_point>;
32     explicit RSRenderFrameRateLinker(FrameRateLinkerId id, ObserverType observer);
33     explicit RSRenderFrameRateLinker(ObserverType observer);
34     explicit RSRenderFrameRateLinker(FrameRateLinkerId id);
35     explicit RSRenderFrameRateLinker();
36 
37     RSRenderFrameRateLinker(const RSRenderFrameRateLinker& other);
38     RSRenderFrameRateLinker(const RSRenderFrameRateLinker&& other);
39     RSRenderFrameRateLinker& operator=(const RSRenderFrameRateLinker& other);
40     RSRenderFrameRateLinker& operator=(const RSRenderFrameRateLinker&& other);
41     ~RSRenderFrameRateLinker();
42 
GetId()43     inline FrameRateLinkerId GetId() const
44     {
45         return id_;
46     }
47 
GetAceAnimatorExpectedFrameRate()48     inline int32_t GetAceAnimatorExpectedFrameRate() {
49         return animatorExpectedFrameRate_;
50     }
51 
GetVsyncName()52     inline std::string GetVsyncName()
53     {
54         return vsyncName_;
55     }
56 
GetWindowNodeId()57     inline uint64_t GetWindowNodeId()
58     {
59         return windowNodeId_;
60     }
61 
62     void SetAnimatorExpectedFrameRate(int32_t animatorExpectedFrameRate);
63     void SetVsyncName(const std::string &vsyncName);
64     void SetWindowNodeId(uint64_t windowNodeId);
65     void SetExpectedRange(const FrameRateRange& range);
66     const FrameRateRange& GetExpectedRange() const;
67     void SetFrameRate(uint32_t rate);
68     uint32_t GetFrameRate() const;
69 
70     void RegisterExpectedFpsUpdateCallback(pid_t pid, sptr<RSIFrameRateLinkerExpectedFpsUpdateCallback> callback);
71     void UpdateNativeVSyncTimePoint();
72     bool NativeVSyncIsTimeOut() const;
73 private:
74     static FrameRateLinkerId GenerateId();
75     void Copy(const RSRenderFrameRateLinker&& other);
76     void Notify();
77 
78     FrameRateLinkerId id_ = 0;
79     ObserverType observer_ = nullptr; // will not be copied to other obj
80     FrameRateRange expectedRange_;
81     const std::string xcomponentId_ = "";
82     uint32_t frameRate_ = 0;
83     int32_t animatorExpectedFrameRate_ = -1;
84     std::string vsyncName_;
85     uint64_t windowNodeId_ = 0;
86     mutable std::mutex mutex_;
87     TimePoint nativeVSyncTimePoint_ = std::chrono::steady_clock::time_point::min();
88 
89     std::unordered_map<pid_t, sptr<RSIFrameRateLinkerExpectedFpsUpdateCallback>> expectedFpsChangeCallbacks_;
90 };
91 } // namespace Rosen
92 } // namespace OHOS
93 
94 #endif // RENDER_SERVICE_CLIENT_CORE_PIPELINE_RS_RENDER_FRAME_RATE_LINKER_H
95