1 /* 2 * Copyright (c) 2025 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 "rs_uifirst_frame_rate_control.h" 17 18 namespace OHOS { 19 namespace Rosen { SetAnimationStartInfo(const DataBaseRs & eventInfo)20void RSUifirstFrameRateControl::SetAnimationStartInfo(const DataBaseRs& eventInfo) 21 { 22 if (!RSSystemProperties::GetSubThreadControlFrameRate()) { 23 return; 24 } 25 auto sceneId = GetSceneId(eventInfo.sceneId); 26 27 switch (sceneId) { 28 case SceneId::LAUNCHER_APP_LAUNCH_FROM_ICON: 29 forceRefreshOnce_ = true; 30 SetStartAnimation(true); 31 break; 32 case SceneId::LAUNCHER_APP_SWIPE_TO_HOME: 33 forceRefreshOnce_ = true; 34 SetStopAnimation(true); 35 break; 36 case SceneId::GESTURE_TO_RECENTS: 37 forceRefreshOnce_ = true; 38 SetMultTaskAnimation(true); 39 break; 40 case SceneId::LAUNCHER_APP_LAUNCH_FROM_RECENT: 41 forceRefreshOnce_ = false; 42 break; 43 case SceneId::AOD_TO_LAUNCHER: 44 case SceneId::LOCKSCREEN_TO_LAUNCHER: 45 SetStartAnimation(false); 46 SetStopAnimation(false); 47 SetMultTaskAnimation(false); 48 break; 49 default: 50 break; 51 } 52 } 53 SetAnimationEndInfo(const DataBaseRs & eventInfo)54void RSUifirstFrameRateControl::SetAnimationEndInfo(const DataBaseRs& eventInfo) 55 { 56 if (!RSSystemProperties::GetSubThreadControlFrameRate()) { 57 return; 58 } 59 auto sceneId = GetSceneId(eventInfo.sceneId); 60 61 switch (sceneId) { 62 case SceneId::LAUNCHER_APP_LAUNCH_FROM_ICON: 63 SetStartAnimation(false); 64 break; 65 case SceneId::LAUNCHER_APP_SWIPE_TO_HOME: 66 SetStopAnimation(false); 67 break; 68 case SceneId::LAUNCHER_APP_LAUNCH_FROM_RECENT: 69 forceRefreshOnce_ = true; 70 SetMultTaskAnimation(false); 71 break; 72 case SceneId::EXIT_RECENT_2_HOME_ANI: 73 case SceneId::CLEAR_1_RECENT_ANI: 74 case SceneId::CLEAR_ALL_RECENT_ANI: 75 SetMultTaskAnimation(false); 76 break; 77 default: 78 break; 79 } 80 } 81 JudgeMultiSubSurface(const RSSurfaceRenderNode & node)82bool RSUifirstFrameRateControl::JudgeMultiSubSurface(const RSSurfaceRenderNode& node) 83 { 84 return node.GetChildren()->size() > 1; 85 } 86 GetUifirstFrameDropInternal(int frameInterval)87bool RSUifirstFrameRateControl::GetUifirstFrameDropInternal(int frameInterval) 88 { 89 std::lock_guard<std::mutex> lock(incrementCallCount_); 90 callCount_++; 91 if (callCount_ % (frameInterval + 1) == 0) { 92 callCount_ = 0; 93 return false; 94 } 95 return true; 96 } 97 SubThreadFrameDropDecision(const RSSurfaceRenderNode & node)98bool RSUifirstFrameRateControl::SubThreadFrameDropDecision(const RSSurfaceRenderNode& node) 99 { 100 bool inAnimation = JudgeStartAnimation() || JudgeStopAnimation() || JudgeMultTaskAnimation(); 101 bool hasMultipleSubSurfaces = JudgeMultiSubSurface(node); 102 bool canDropFrame = GetUifirstFrameDropInternal(RSSystemProperties::GetSubThreadDropFrameInterval()); 103 104 return inAnimation && (forceRefreshOnce_ || (!hasMultipleSubSurfaces && canDropFrame)); 105 } 106 NeedRSUifirstControlFrameDrop(const RSSurfaceRenderNode & node)107bool RSUifirstFrameRateControl::NeedRSUifirstControlFrameDrop(const RSSurfaceRenderNode& node) 108 { 109 return SubThreadFrameDropDecision(node); 110 } 111 } 112 }