1 /*
2  * Copyright (c) 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_BASE_PIPELINE_RS_RENDER_DISPLAY_SYNC_H
16 #define RENDER_SERVICE_BASE_PIPELINE_RS_RENDER_DISPLAY_SYNC_H
17 
18 #include <refbase.h>
19 
20 #include "animation/rs_frame_rate_range.h"
21 #include "animation/rs_render_animation.h"
22 #include "common/rs_common_def.h"
23 #include "common/rs_macros.h"
24 
25 namespace OHOS {
26 namespace Rosen {
27 class RSB_EXPORT RSRenderDisplaySync : public std::enable_shared_from_this<RSRenderDisplaySync> {
28 public:
29     explicit RSRenderDisplaySync(NodeId id);
30     explicit RSRenderDisplaySync(std::weak_ptr<RSRenderAnimation> renderAnimation);
31     ~RSRenderDisplaySync() = default;
32 
33     uint64_t GetId() const;
34     bool OnFrameSkip(uint64_t timestamp, int64_t period, bool isDisplaySyncEnabled);
35     void SetExpectedFrameRateRange(const FrameRateRange& range);
36     const FrameRateRange& GetExpectedFrameRange() const;
37     void SetAnimateResult(std::tuple<bool, bool, bool>& result);
38     std::tuple<bool, bool, bool> GetAnimateResult() const;
39 private:
40     int32_t CalcSkipRateCount(int32_t frameRate);
41     int32_t GetNearestFrameRate(int32_t num, const std::vector<int32_t>& rates);
42 
43     NodeId id_ = 0;
44     uint64_t timestamp_ = 0;
45     int64_t currentPeriod_ = 0;
46     int64_t currentFrameRate_ = 0;
47     int64_t referenceCount_ = 0;
48     int64_t skipRateCount_ = 1;
49 
50     bool isSkipCountUpdate_ = false;
51     std::tuple<bool, bool, bool> animateResult_;
52     FrameRateRange expectedFrameRateRange_;
53     std::weak_ptr<RSRenderAnimation> renderAnimation_;
54 };
55 } // namespace Rosen
56 } // namespace OHOS
57 
58 #endif // RENDER_SERVICE_BASE_PIPELINE_RS_RENDER_DISPLAY_SYNC_H
59