Merge branch '2410281915_vsync' of https://gitee.com/hfwang0318/window_window_manager into 2410281915_vsync

This commit is contained in:
hfwang0318 2024-10-29 22:35:16 +08:00
commit 2e31adbf25
11 changed files with 78 additions and 84 deletions

View File

@ -49,11 +49,9 @@ public:
void SetFrameRateLinkerEnable(bool enabled);
void SetDisplaySoloistFrameRateLinkerEnable(bool enabled);
void SetUiDvsyncSwitch(bool dvsyncSwitch);
void OnFlushUIParams();
uint32_t GetRequestTimes()
{
return requestTimes_.load();
}
void DecreaseRequestVsyncTimes() { requestVsyncTimes_--; }
int32_t GetRequestVsyncTimes() { return requestVsyncTimes_.load(); }
private:
std::shared_ptr<VSyncReceiver> GetOrCreateVsyncReceiver();
@ -71,12 +69,13 @@ private:
bool isFirstVsyncBack_ = true;
bool destroyed_ = false;
bool hasRequestedVsync_ = false;
std::atomic<uint32_t> requestTimes_;
std::shared_ptr<VSyncReceiver> receiver_ = nullptr;
std::shared_ptr<RSFrameRateLinker> frameRateLinker_ = nullptr;
using Callbacks = std::unordered_set<std::shared_ptr<VsyncCallback>>;
Callbacks vsyncCallbacks_;
// Above guarded by mutex_
std::atomic<int32_t> requestVsyncTimes_;
};
} // namespace Rosen
} // namespace OHOS

View File

@ -141,7 +141,7 @@ __attribute__((no_sanitize("cfi"))) void VsyncStation::RequestVsync(
vsyncHandler_->PostTask(task, vsyncTimeoutTaskName_, VSYNC_TIME_OUT_MILLISECONDS);
}
requestTimes_++;
requestVsyncTimes_++;
WindowFrameTraceImpl::GetInstance()->VsyncStartFrameTrace();
auto task = [weakThis = weak_from_this()]
(int64_t timestamp, int64_t frameCount, void* client) {
@ -263,10 +263,5 @@ void VsyncStation::SetUiDvsyncSwitch(bool dvsyncSwitch)
receiver->SetUiDvsyncSwitch(dvsyncSwitch);
}
}
void VsyncStation::OnFlushUIParams()
{
requestTimes_--;
}
} // namespace Rosen
} // namespace OHOS

View File

@ -562,32 +562,29 @@ void JsSceneSessionManager::ProcessAbilityManagerCollaboratorRegistered()
SceneSessionManager::GetInstance().SetAbilityManagerCollaboratorRegisteredFunc(func);
}
void JsSceneSessionManager::ProcessSSMCallbackOnRootScene()
void JsSceneSessionManager::RegisterRootSceneCallbacksOnSSManager()
{
RegisterDumpRootSceneElementInfoListener();
RegisterVirtualPixelRatioChangeListener();
RootSceneProcessBackEventFunc processBackEventFunc = [this]() {
TLOGD(WmsLogTag::WMS_EVENT, "rootScene BackEvent");
SceneSessionManager::GetInstance().SetRootSceneProcessBackEventFunc([this] {
TLOGND(WmsLogTag::WMS_EVENT, "rootScene BackEvent");
this->OnRootSceneBackEvent();
};
SceneSessionManager::GetInstance().SetRootSceneProcessBackEventFunc(processBackEventFunc);
auto onFlushUIParamsFunc = []() {
});
SceneSessionManager::GetInstance().SetOnFlushUIParamsFunc([] {
RootScene::staticRootScene_->OnFlushUIParams();
};
SceneSessionManager::GetInstance().SetOnFlushUIParamsFunc(onFlushUIParamsFunc);
auto getIsLayoutFinishedFunc = []() {
return RootScene::staticRootScene_->IsLayoutFinished();
};
SceneSessionManager::GetInstance().SetGetIsLayoutFinishedFunc(getIsLayoutFinishedFunc);
});
SceneSessionManager::GetInstance().SetGetIsLastFrameLayoutFinishedFunc([] {
return RootScene::staticRootScene_->IsLastFrameLayoutFinished();
});
}
void JsSceneSessionManager::ProcessRootSceneCallbackOnSSM()
void JsSceneSessionManager::RegisterSSManagerCallbacksOnRootScene()
{
rootScene_->SetGetSessionRectCallback([](AvoidAreaType type) {
return SceneSessionManager::GetInstance().GetRootSessionAvoidSessionRect(type);
});
if (!Session::IsScbCoreEnabled()) {
rootScene_->SetFrameLayoutFinishCallback([]() {
rootScene_->SetFrameLayoutFinishCallback([] {
SceneSessionManager::GetInstance().NotifyUpdateRectAfterLayout();
SceneSessionManager::GetInstance().FlushWindowInfoToMMI();
});
@ -1504,8 +1501,8 @@ napi_value JsSceneSessionManager::OnGetRootSceneSession(napi_env env, napi_callb
ScenePersistentStorage::InitDir(context->GetPreferencesDir());
SceneSessionManager::GetInstance().InitPersistentStorage();
});
ProcessSSMCallbackOnRootScene();
ProcessRootSceneCallbackOnSSM();
RegisterRootSceneCallbacksOnSSManager();
RegisterSSManagerCallbacksOnRootScene();
napi_value jsRootSceneSessionObj = JsRootSceneSession::Create(env, rootSceneSession);
if (jsRootSceneSessionObj == nullptr) {
WLOGFE("[NAPI]jsRootSceneSessionObj is nullptr");

View File

@ -221,8 +221,8 @@ private:
std::shared_ptr<NativeReference> GetJSCallback(const std::string& functionName);
void ProcessAbilityManagerCollaboratorRegistered();
void OnAbilityManagerCollaboratorRegistered();
void ProcessSSMCallbackOnRootScene();
void ProcessRootSceneCallbackOnSSM();
void RegisterRootSceneCallbacksOnSSManager();
void RegisterSSManagerCallbacksOnRootScene();
napi_env env_;
std::shared_mutex jsCbMapMutex_;

View File

@ -90,7 +90,7 @@ using NotifyMainWindowTopmostChangeFunc = std::function<void(bool isTopmost)>;
using NotifyPrivacyModeChangeFunc = std::function<void(uint32_t isPrivacyMode)>;
using UpdateGestureBackEnabledCallback = std::function<void(int32_t persistentId)>;
using NotifyVisibleChangeFunc = std::function<void(int32_t persistentId)>;
using GetIsLayoutFinishedFunc = std::function<WSError(bool& isLayoutFinished)>;
using IsLayoutFinishedFunc = std::function<WSError(bool& isLayoutFinished)>;
class SceneSession : public Session {
public:
@ -284,13 +284,13 @@ public:
WSError GetAllAvoidAreas(std::map<AvoidAreaType, AvoidArea>& avoidAreas) override;
WSError SetSystemBarProperty(WindowType type, SystemBarProperty systemBarProperty);
void SetIsStatusBarVisible(bool isVisible);
WSError SetIsStatusBarVisibleTask(bool isVisible);
WSError SetIsStatusBarVisibleInner(bool isVisible);
WSError UpdateAvoidArea(const sptr<AvoidArea>& avoidArea, AvoidAreaType type) override;
void UpdateRotationAvoidArea();
bool CheckGetAvoidAreaAvailable(AvoidAreaType type) override;
bool GetIsDisplayStatusBarTemporarily() const;
void SetIsDisplayStatusBarTemporarily(bool isTemporary);
void SetGetIsLayoutFinishedFunc(GetIsLayoutFinishedFunc&& getIsLayoutFinishedFunc);
void SetGetIsLastFrameLayoutFinishedFunc(IsLayoutFinishedFunc&& isLayoutFinishedFunc);
void SetAbilitySessionInfo(std::shared_ptr<AppExecFwk::AbilityInfo> abilityInfo);
void SetWindowDragHotAreaListener(const NotifyWindowDragHotAreaFunc& func);
@ -554,11 +554,11 @@ private:
/**
* Window Immersive
*/
void CalculateAvoidAreaRect(WSRect &rect, WSRect &avoidRect, AvoidArea &avoidArea) const;
void GetSystemAvoidArea(WSRect &rect, AvoidArea &avoidArea);
void GetCutoutAvoidArea(WSRect &rect, AvoidArea &avoidArea);
void GetKeyboardAvoidArea(WSRect &rect, AvoidArea &avoidArea);
void GetAINavigationBarArea(WSRect rect, AvoidArea &avoidArea) const;
void CalculateAvoidAreaRect(WSRect& rect, WSRect& avoidRect, AvoidArea& avoidArea) const;
void GetSystemAvoidArea(WSRect& rect, AvoidArea& avoidArea);
void GetCutoutAvoidArea(WSRect& rect, AvoidArea& avoidArea);
void GetKeyboardAvoidArea(WSRect& rect, AvoidArea& avoidArea);
void GetAINavigationBarArea(WSRect rect, AvoidArea& avoidArea) const;
/*
* Window Lifecycle
@ -759,7 +759,7 @@ private:
*/
std::atomic_bool isDisplayStatusBarTemporarily_ { false };
bool isStatusBarVisible_ = true;
GetIsLayoutFinishedFunc getIsLayoutFinishedFunc_;
IsLayoutFinishedFunc isLayoutFinishedFunc_;
};
} // namespace OHOS::Rosen
#endif // OHOS_ROSEN_WINDOW_SCENE_SCENE_SESSION_H

View File

@ -1307,17 +1307,17 @@ WSError SceneSession::SetSystemBarProperty(WindowType type, SystemBarProperty sy
void SceneSession::SetIsStatusBarVisible(bool isVisible)
{
auto task = [weakThis = wptr(this), isVisible]() {
sptr<SceneSession> self = weakThis.promote();
if (self == nullptr) {
sptr<SceneSession> sceneSession = weakThis.promote();
if (sceneSession == nullptr) {
TLOGNE(WmsLogTag::WMS_IMMS, "session is null");
return;
}
self->SetIsStatusBarVisibleTask(isVisible);
sceneSession->SetIsStatusBarVisibleInner(isVisible);
};
PostTask(task, __func__);
}
WSError SceneSession::SetIsStatusBarVisibleTask(bool isVisible)
WSError SceneSession::SetIsStatusBarVisibleInner(bool isVisible)
{
bool isNeedNotify = isStatusBarVisible_ != isVisible;
TLOGI(WmsLogTag::WMS_IMMS, "Window [%{public}d, %{public}s] status bar visible %{public}u, "
@ -1326,14 +1326,14 @@ WSError SceneSession::SetIsStatusBarVisibleTask(bool isVisible)
if (!isNeedNotify) {
return WSError::WS_OK;
}
if (getIsLayoutFinishedFunc_ == nullptr) {
TLOGE(WmsLogTag::WMS_IMMS, "getIsLayoutFinishedFunc_ is null, id: %{public}d", GetPersistentId());
if (isLayoutFinishedFunc_ == nullptr) {
TLOGE(WmsLogTag::WMS_IMMS, "isLayoutFinishedFunc is null, id: %{public}d", GetPersistentId());
return WSError::WS_ERROR_NULLPTR;
}
bool isLayoutFinished = false;
WSError ret = getIsLayoutFinishedFunc_(isLayoutFinished);
WSError ret = isLayoutFinishedFunc_(isLayoutFinished);
if (ret != WSError::WS_OK) {
TLOGE(WmsLogTag::WMS_IMMS, "getIsLayoutFinishedFunc_ failed: %{public}d", ret);
TLOGE(WmsLogTag::WMS_IMMS, "isLayoutFinishedFunc failed: %{public}d", ret);
return ret;
}
if (isLayoutFinished) {
@ -4694,9 +4694,9 @@ bool SceneSession::GetIsDisplayStatusBarTemporarily() const
return isDisplayStatusBarTemporarily_.load();
}
void SceneSession::SetGetIsLayoutFinishedFunc(GetIsLayoutFinishedFunc&& getIsLayoutFinishedFunc)
void SceneSession::SetGetIsLastFrameLayoutFinishedFunc(IsLayoutFinishedFunc&& isLayoutFinishedFunc)
{
getIsLayoutFinishedFunc_ = std::move(getIsLayoutFinishedFunc);
isLayoutFinishedFunc_ = std::move(isLayoutFinishedFunc);
}
void SceneSession::SetStartingWindowExitAnimationFlag(bool enable)

View File

@ -118,7 +118,7 @@ using RootSceneProcessBackEventFunc = std::function<void()>;
using ProcessCloseTargetFloatWindowFunc = std::function<void(const std::string& bundleName)>;
using AbilityManagerCollaboratorRegisteredFunc = std::function<void()>;
using OnFlushUIParamsFunc = std::function<void()>;
using GetIsLayoutFinishedOnRootSceneFunc = std::function<bool()>;
using IsLayoutFinishedOnRootSceneFunc = std::function<bool()>;
class AppAnrListener : public IRemoteStub<AppExecFwk::IAppDebugListener> {
public:
@ -364,15 +364,15 @@ public:
/*
* Window Immersive
*/
WSError GetIsLayoutFullScreen(bool &isLayoutFullScreen);
WSError UpdateSessionAvoidAreaListener(int32_t &persistentId, bool haveListener) override;
WSError GetIsLayoutFullScreen(bool& isLayoutFullScreen);
WSError UpdateSessionAvoidAreaListener(int32_t& persistentId, bool haveListener) override;
bool GetImmersiveState(ScreenId screenId);
WSError NotifyStatusBarShowStatus(int32_t persistentId, bool isVisible);
WSError NotifyAINavigationBarShowStatus(bool isVisible, WSRect barArea, uint64_t displayId);
WSRect GetAINavigationBarArea(uint64_t displayId);
void ClearDisplayStatusBarTemporarilyFlags();
void SetOnFlushUIParamsFunc(OnFlushUIParamsFunc&& func);
void SetGetIsLayoutFinishedFunc(GetIsLayoutFinishedOnRootSceneFunc&& func);
void SetGetIsLastFrameLayoutFinishedFunc(IsLayoutFinishedOnRootSceneFunc&& func);
WSError NotifyWindowExtensionVisibilityChange(int32_t pid, int32_t uid, bool visible) override;
void DealwithVisibilityChange(const std::vector<std::pair<uint64_t, WindowVisibilityState>>& visibilityChangeInfos,
@ -618,9 +618,9 @@ private:
void UpdateNormalSessionAvoidArea(const int32_t& persistentId, sptr<SceneSession>& sceneSession, bool& needUpdate);
void UpdateAvoidArea(int32_t persistentId);
void UpdateAvoidAreaByType(int32_t persistentId, AvoidAreaType type);
WSError IsLayoutFinished(bool& isLayoutFinished);
void HandleSpecificSystemBarProperty(WindowType type, const sptr<WindowSessionProperty> &property,
const sptr<SceneSession> &sceneSession);
WSError IsLastFrameLayoutFinished(bool& isLayoutFinished);
void HandleSpecificSystemBarProperty(WindowType type, const sptr<WindowSessionProperty>& property,
const sptr<SceneSession>& sceneSession);
sptr<AppExecFwk::IBundleMgr> GetBundleManager();
std::shared_ptr<Global::Resource::ResourceManager> GetResourceManager(const AppExecFwk::AbilityInfo& abilityInfo);
@ -981,7 +981,7 @@ private:
* Window Immersive
*/
OnFlushUIParamsFunc onFlushUIParamsFunc_;
GetIsLayoutFinishedOnRootSceneFunc getIsLayoutFinishedOnRootSceneFunc_;
IsLayoutFinishedOnRootSceneFunc isLayoutFinishedOnRootSceneFunc_;
bool isAINavigationBarVisible_ = false;
std::shared_mutex currAINavigationBarAreaMapMutex_;
std::map<uint64_t, WSRect> currAINavigationBarAreaMap_;

View File

@ -1526,8 +1526,8 @@ sptr<SceneSession> SceneSessionManager::CreateSceneSession(const SessionInfo& se
if (sceneSession->moveDragController_) {
sceneSession->moveDragController_->SetIsPcWindow(systemConfig_.IsPcWindow());
}
sceneSession->SetGetIsLayoutFinishedFunc([this](bool& isLayoutFinished) {
return this->IsLayoutFinished(isLayoutFinished);
sceneSession->SetGetIsLastFrameLayoutFinishedFunc([this](bool& isLayoutFinished) {
return this->IsLastFrameLayoutFinished(isLayoutFinished);
});
}
return sceneSession;
@ -4550,9 +4550,9 @@ void SceneSessionManager::SetOnFlushUIParamsFunc(OnFlushUIParamsFunc&& func)
onFlushUIParamsFunc_ = std::move(func);
}
void SceneSessionManager::SetGetIsLayoutFinishedFunc(GetIsLayoutFinishedOnRootSceneFunc&& func)
void SceneSessionManager::SetGetIsLastFrameLayoutFinishedFunc(IsLayoutFinishedOnRootSceneFunc&& func)
{
getIsLayoutFinishedOnRootSceneFunc_ = std::move(func);
isLayoutFinishedOnRootSceneFunc_ = std::move(func);
}
void FocusIDChange(int32_t persistentId, sptr<SceneSession>& sceneSession)
@ -11314,13 +11314,13 @@ WMError SceneSessionManager::GetDisplayIdByWindowId(const std::vector<uint64_t>&
return taskScheduler_->PostSyncTask(task, "GetDisplayIdByWindowId");
}
WSError SceneSessionManager::IsLayoutFinished(bool& isLayoutFinished)
WSError SceneSessionManager::IsLastFrameLayoutFinished(bool& isLayoutFinished)
{
if (getIsLayoutFinishedOnRootSceneFunc_ == nullptr) {
TLOGE(WmsLogTag::WMS_IMMS, "getIsLayoutFinishedOnRootSceneFunc_ is null");
if (isLayoutFinishedOnRootSceneFunc_ == nullptr) {
TLOGE(WmsLogTag::WMS_IMMS, "isLayoutFinishedOnRootSceneFunc is null");
return WSError::WS_ERROR_NULLPTR;
}
isLayoutFinished = getIsLayoutFinishedOnRootSceneFunc_();
isLayoutFinished = isLayoutFinishedOnRootSceneFunc_();
return WSError::WS_OK;
}
} // namespace OHOS::Rosen

View File

@ -2179,42 +2179,41 @@ HWTEST_F(SceneSessionTest, SetSessionGlobalRect, Function | SmallTest | Level2)
* @tc.desc: SetSessionGlobalRect
* @tc.type: FUNC
*/
HWTEST_F(SceneSessionTest, SetIsStatusBarVisibleTask01, Function | SmallTest | Level2)
HWTEST_F(SceneSessionTest, SetIsStatusBarVisibleInner01, Function | SmallTest | Level2)
{
SessionInfo info;
info.abilityName_ = "SetIsStatusBarVisibleTask01";
info.bundleName_ = "SetIsStatusBarVisibleTask01";
info.abilityName_ = "SetIsStatusBarVisibleInner01";
info.bundleName_ = "SetIsStatusBarVisibleInner01";
info.windowType_ = 1;
sptr<Rosen::ISession> session_;
sptr<SceneSession::SpecificSessionCallback> specificCallback_ =
sptr<SceneSession::SpecificSessionCallback> specificCallback =
sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
EXPECT_NE(specificCallback_, nullptr);
sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, specificCallback_);
EXPECT_NE(specificCallback, nullptr);
sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, specificCallback);
EXPECT_NE(sceneSession, nullptr);
sceneSession->isStatusBarVisible_ = true;
EXPECT_EQ(sceneSession->SetIsStatusBarVisibleTask(true), WSError::WS_OK);
EXPECT_EQ(sceneSession->SetIsStatusBarVisibleTask(false), WSError::WS_ERROR_NULLPTR);
EXPECT_EQ(sceneSession->SetIsStatusBarVisibleInner(true), WSError::WS_OK);
EXPECT_EQ(sceneSession->SetIsStatusBarVisibleInner(false), WSError::WS_ERROR_NULLPTR);
sceneSession->getIsLayoutFinishedFunc_ = [](bool& isLayoutFinished) {
return WSError::WS_ERROR_NULLPTR;
};
EXPECT_EQ(sceneSession->SetIsStatusBarVisibleTask(true), WSError::WS_ERROR_NULLPTR);
EXPECT_EQ(sceneSession->SetIsStatusBarVisibleInner(true), WSError::WS_ERROR_NULLPTR);
sceneSession->getIsLayoutFinishedFunc_ = [](bool& isLayoutFinished) {
isLayoutFinished = false;
return WSError::WS_OK;
};
EXPECT_EQ(sceneSession->SetIsStatusBarVisibleTask(false), WSError::WS_OK);
EXPECT_EQ(sceneSession->SetIsStatusBarVisibleInner(false), WSError::WS_OK);
sceneSession->getIsLayoutFinishedFunc_ = [](bool& isLayoutFinished) {
isLayoutFinished = true;
return WSError::WS_OK;
};
sceneSession->specificCallback_->onUpdateAvoidAreaByType_ = [](int32_t persistentId, AvoidAreaType type) { };
EXPECT_EQ(sceneSession->SetIsStatusBarVisibleTask(true), WSError::WS_OK);
sceneSession->specificCallback_->onUpdateAvoidAreaByType_ = [](int32_t persistentId, AvoidAreaType type) {};
EXPECT_EQ(sceneSession->SetIsStatusBarVisibleInner(true), WSError::WS_OK);
sceneSession->specificCallback_ = nullptr;
EXPECT_EQ(sceneSession->SetIsStatusBarVisibleTask(false), WSError::WS_OK);
EXPECT_EQ(sceneSession->SetIsStatusBarVisibleInner(false), WSError::WS_OK);
}
} // namespace
} // Rosen

View File

@ -51,7 +51,11 @@ public:
void RequestVsync(const std::shared_ptr<VsyncCallback>& vsyncCallback) override;
int64_t GetVSyncPeriod() override;
void FlushFrameRate(uint32_t rate, int32_t animatorExpectedFrameRate, uint32_t rateType = 0) override;
bool IsLayoutFinished();
/**
* Window Immersive
*/
bool IsLastFrameLayoutFinished();
void OnFlushUIParams();
void OnBundleUpdated(const std::string& bundleName);

View File

@ -184,16 +184,16 @@ void RootScene::FlushFrameRate(uint32_t rate, int32_t animatorExpectedFrameRate,
vsyncStation_->FlushFrameRate(rate, animatorExpectedFrameRate, rateType);
}
bool RootScene::IsLayoutFinished()
bool RootScene::IsLastFrameLayoutFinished()
{
uint32_t requestTimes = vsyncStation_->GetRequestTimes();
WLOGI("RootScene vsync request times: %{public}d", requestTimes);
int32_t requestTimes = vsyncStation_->GetRequestVsyncTimes();
TLOGI(WmsLogTag::WMS_LAYOUT, "RootScene vsync request times: %{public}d", requestTimes);
return requestTimes == 0;
}
void RootScene::OnFlushUIParams()
{
vsyncStation_->OnFlushUIParams();
vsyncStation_->DecreaseRequestVsyncTimes();
}
void RootScene::OnBundleUpdated(const std::string& bundleName)