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 OHOS_ACE_COMPONENT_TEST_PIPELINE_STATUS_H
17#define OHOS_ACE_COMPONENT_TEST_PIPELINE_STATUS_H
18
19namespace OHOS::Ace::ComponentTest {
20
21class PipelineStatusHolder {
22public:
23    void Update()
24    {
25        ++vsyncCountRealTime_;
26    }
27
28private:
29    friend class IdleMonitorThread;
30    friend class IdleWatcher;
31
32    uint32_t vsyncCountRealTime_ = 0;
33    uint32_t vsyncCountLastCheck_ = 0;
34    uint8_t idleCounter_ = 0;
35    uint8_t longOptCounter_ = 0;
36    uint8_t idleCheckRetry_;
37
38    bool Check()
39    {
40        uint8_t vsyncCount = vsyncCountLastCheck_;
41        vsyncCountLastCheck_ = vsyncCountRealTime_;
42        if (longOptCounter_ == 0) {
43            ++idleCheckRetry_;
44            return vsyncCountRealTime_ == vsyncCount;
45        } else {
46            idleCheckRetry_ = 0;
47            return false;
48        }
49    }
50
51    void IncreaseLongOpt()
52    {
53        ++longOptCounter_;
54    }
55
56    void DecreaseLongOpt()
57    {
58        if (longOptCounter_ > 0) {
59            --longOptCounter_;
60        }
61    }
62
63    void IdleCounterAdd()
64    {
65        ++idleCounter_;
66    }
67
68    void IdleCounterClear()
69    {
70        idleCounter_ = 0;
71    }
72
73    bool IdleCounterReached(uint8_t num) const
74    {
75        return idleCounter_ >= num;
76    }
77
78    void RetryCounterClear()
79    {
80        idleCheckRetry_ = 0;
81    }
82
83    bool RetryCounterReached(uint8_t num) const
84    {
85        return idleCheckRetry_ >= num;
86    }
87};
88
89// extern g_pipelineStatusHolder;
90
91extern void UpdatePipelineStatus();
92
93} // namespace OHOS::Ace::ComponentTest
94
95#endif // OHOS_ACE_COMPONENT_TEST_PIPELINE_STATUS_H
96