• 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 #include "feature/hyper_graphic_manager/rs_vblank_idle_corrector.h"
17 
18 #include "hgm_core.h"
19 #include "hgm_frame_rate_manager.h"
20 #include "platform/common/rs_log.h"
21 #include "rs_trace.h"
22 #include "screen_manager/rs_screen_manager.h"
23 
24 namespace OHOS {
25 namespace Rosen {
26 namespace {
27 constexpr uint32_t IDLE_FRAME_COUNT_THRESHOLD = 2;
28 };
29 
SetScreenVBlankIdle(ScreenId id)30 void RSVBlankIdleCorrector::SetScreenVBlankIdle(ScreenId id)
31 {
32     bool isCorrectorEnabled = HgmCore::Instance().IsVBlankIdleCorrectEnabled();
33     if (isCorrectorEnabled) {
34         currIdleScreenId_ = id;
35         idleFrameCount_ = IDLE_FRAME_COUNT_THRESHOLD;
36         isVBlankIdle_ = true;
37     }
38 }
39 
ProcessScreenConstraint(uint64_t timestamp,uint64_t constraintRelativeTime)40 void RSVBlankIdleCorrector::ProcessScreenConstraint(uint64_t timestamp, uint64_t constraintRelativeTime)
41 {
42     auto screenManager = CreateOrGetScreenManager();
43     if (screenManager == nullptr) {
44         RS_LOGE("RSHardwareThread CreateOrGetScreenManager fail.");
45         return;
46     }
47 
48     auto frameRateMgr = HgmCore::Instance().GetFrameRateMgr();
49     if (frameRateMgr == nullptr) {
50         RS_LOGE("RSHardwareThread CreateOrGetScreenManager fail, frameRateMgr is null!");
51         return;
52     }
53 
54     ScreenId curScreenId = frameRateMgr->GetCurScreenId();
55 
56     bool isScreenNeedAdaptive = frameRateMgr->AdaptiveStatus() == SupportASStatus::SUPPORT_AS &&
57         frameRateMgr->IsGameNodeOnTree();
58     if (isScreenNeedAdaptive) {
59         RS_TRACE_NAME("RSVBlankIdleCorrector::ProcessScreenConstraint set 3 in Adaptive Mode!");
60         screenManager->SetScreenConstraint(curScreenId, 0, ScreenConstraintType::CONSTRAINT_ADAPTIVE);
61         return;
62     }
63 
64     bool isCorrectorEnabled = HgmCore::Instance().IsVBlankIdleCorrectEnabled();
65     if (!isCorrectorEnabled) {
66         idleFrameCount_ = 0;
67         isVBlankIdle_ = false;
68         screenManager->SetScreenConstraint(curScreenId, 0, ScreenConstraintType::CONSTRAINT_NONE);
69         return;
70     }
71 
72     if (isVBlankIdle_) {
73         uint64_t pipelineOffset = static_cast<uint64_t>(HgmCore::Instance().GetPipelineOffset());
74         if (idleFrameCount_ > 0) {
75             uint64_t absoluteTime = timestamp + pipelineOffset;
76             screenManager->SetScreenConstraint(currIdleScreenId_,
77                 absoluteTime, ScreenConstraintType::CONSTRAINT_ABSOLUTE);
78         } else {
79             screenManager->SetScreenConstraint(currIdleScreenId_, 0, ScreenConstraintType::CONSTRAINT_NONE);
80         }
81         idleFrameCount_--;
82         if (idleFrameCount_ < 0) {
83             currIdleScreenId_ = curScreenId;
84             idleFrameCount_ = 0;
85             isVBlankIdle_ = false;
86         }
87     } else if (constraintRelativeTime > 0) {
88         screenManager->SetScreenConstraint(curScreenId,
89             constraintRelativeTime, ScreenConstraintType::CONSTRAINT_RELATIVE);
90     } else {
91         screenManager->SetScreenConstraint(curScreenId, 0, ScreenConstraintType::CONSTRAINT_NONE);
92     }
93 }
94 }
95 }
96