!45624 对窗口传入config进行去重

Merge pull request !45624 from CamlostShi/deduplicateConfig
This commit is contained in:
openharmony_ci 2024-10-12 13:51:55 +00:00 committed by Gitee
commit 3f9196dd4f
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
4 changed files with 61 additions and 51 deletions

View File

@ -315,56 +315,29 @@ void AddAlarmLogFunc()
OHOS::Rosen::RSTransactionData::AddAlarmLog(logFunc);
}
void DeduplicateAvoidAreas(const RefPtr<NG::PipelineContext>& context,
std::map<OHOS::Rosen::AvoidAreaType, NG::SafeAreaInsets>& updatingInsets,
bool ParseAvoidAreasUpdate(const RefPtr<NG::PipelineContext>& context,
const std::map<OHOS::Rosen::AvoidAreaType, OHOS::Rosen::AvoidArea>& avoidAreas,
const ViewportConfig& config)
{
CHECK_NULL_VOID(context);
CHECK_NULL_RETURN(context, false);
auto safeAreaManager = context->GetSafeAreaManager();
CHECK_NULL_VOID(safeAreaManager);
CHECK_NULL_RETURN(safeAreaManager, false);
bool safeAreaUpdated = false;
for (auto& avoidArea : avoidAreas) {
if (avoidArea.first == OHOS::Rosen::AvoidAreaType::TYPE_SYSTEM) {
NG::SafeAreaInsets insets = ConvertAvoidArea(avoidArea.second);
if (safeAreaManager->CheckSystemSafeArea(insets)) {
updatingInsets[avoidArea.first] = insets;
}
safeAreaUpdated |= safeAreaManager->UpdateSystemSafeArea(ConvertAvoidArea(avoidArea.second));
} else if (avoidArea.first == OHOS::Rosen::AvoidAreaType::TYPE_NAVIGATION_INDICATOR) {
NG::SafeAreaInsets insets = ConvertAvoidArea(avoidArea.second);
if (safeAreaManager->CheckNavArea(insets)) {
updatingInsets[avoidArea.first] = insets;
}
safeAreaUpdated |= safeAreaManager->UpdateNavArea(ConvertAvoidArea(avoidArea.second));
} else if (avoidArea.first == OHOS::Rosen::AvoidAreaType::TYPE_CUTOUT && context->GetUseCutout()) {
NG::SafeAreaInsets insets = ConvertAvoidArea(avoidArea.second);
if (safeAreaManager->CheckCutoutSafeArea(insets,
NG::OptionalSize<uint32_t>(config.Width(), config.Height()))) {
updatingInsets[avoidArea.first] = insets;
}
}
}
}
void ParseAvoidAreasUpdate(const RefPtr<NG::PipelineContext>& context,
const std::map<OHOS::Rosen::AvoidAreaType, NG::SafeAreaInsets>& updatingInsets,
const ViewportConfig& config)
{
if (updatingInsets.empty()) {
return;
}
CHECK_NULL_VOID(context);
auto safeAreaManager = context->GetSafeAreaManager();
CHECK_NULL_VOID(safeAreaManager);
for (auto& insets : updatingInsets) {
if (insets.first == OHOS::Rosen::AvoidAreaType::TYPE_SYSTEM) {
safeAreaManager->UpdateSystemSafeArea(insets.second);
} else if (insets.first == OHOS::Rosen::AvoidAreaType::TYPE_NAVIGATION_INDICATOR) {
safeAreaManager->UpdateNavArea(insets.second);
} else if (insets.first == OHOS::Rosen::AvoidAreaType::TYPE_CUTOUT && context->GetUseCutout()) {
safeAreaManager->UpdateCutoutSafeArea(insets.second,
safeAreaUpdated |= safeAreaManager->UpdateCutoutSafeArea(ConvertAvoidArea(avoidArea.second),
NG::OptionalSize<uint32_t>(config.Width(), config.Height()));
}
}
context->SyncSafeArea(SafeAreaSyncType::SYNC_TYPE_AVOID_AREA);
if (safeAreaUpdated) {
context->SyncSafeArea(SafeAreaSyncType::SYNC_TYPE_AVOID_AREA);
return true;
}
return false;
}
void AvoidAreasUpdateOnUIExtension(const RefPtr<NG::PipelineContext>& context,
@ -381,7 +354,6 @@ void AvoidAreasUpdateOnUIExtension(const RefPtr<NG::PipelineContext>& context,
}
void UpdateSafeArea(const RefPtr<PipelineBase>& pipelineContext,
const std::map<OHOS::Rosen::AvoidAreaType, NG::SafeAreaInsets>& updatingInsets,
const std::map<OHOS::Rosen::AvoidAreaType, OHOS::Rosen::AvoidArea>& avoidAreas,
const ViewportConfig& config,
const RefPtr<Platform::AceContainer>& container)
@ -394,11 +366,11 @@ void UpdateSafeArea(const RefPtr<PipelineBase>& pipelineContext,
CHECK_NULL_VOID(safeAreaManager);
uint32_t keyboardHeight = safeAreaManager->GetKeyboardInset().Length();
safeAreaManager->UpdateKeyboardSafeArea(keyboardHeight, config.Height());
if (updatingInsets.find(OHOS::Rosen::AvoidAreaType::TYPE_CUTOUT) == updatingInsets.end()) {
if (avoidAreas.find(OHOS::Rosen::AvoidAreaType::TYPE_CUTOUT) == avoidAreas.end()) {
safeAreaManager->UpdateCutoutSafeArea(container->GetViewSafeAreaByType(Rosen::AvoidAreaType::TYPE_CUTOUT),
NG::OptionalSize<uint32_t>(config.Width(), config.Height()));
}
ParseAvoidAreasUpdate(context, updatingInsets, config);
ParseAvoidAreasUpdate(context, avoidAreas, config);
AvoidAreasUpdateOnUIExtension(context, avoidAreas);
}
@ -2513,12 +2485,24 @@ void UIContentImpl::UpdateViewportConfigWithAnimation(const ViewportConfig& conf
safeAreaManager = context->GetSafeAreaManager();
context->FireSizeChangeByRotateCallback(isOrientationChanged, rsTransaction);
}
if (safeAreaManager) {
DeduplicateAvoidAreas(context, updatingInsets, avoidAreas, config);
if (viewportConfigMgr_->IsConfigsEqual(config) && (rsTransaction == nullptr)) {
taskExecutor->PostTask(
[context, config, avoidAreas] {
if (avoidAreas.empty()) {
return;
}
if (ParseAvoidAreasUpdate(context, avoidAreas, config)) {
context->AnimateOnSafeAreaUpdate();
}
AvoidAreasUpdateOnUIExtension(context, avoidAreas);
},
TaskExecutor::TaskType::UI, "ArkUIUpdateOriginAvoidArea");
return;
}
auto task = [config = modifyConfig, container, reason, rsTransaction, rsWindow = window_,
isDynamicRender = isDynamicRender_, animationOpt, updatingInsets, avoidAreas]() {
isDynamicRender = isDynamicRender_, animationOpt, avoidAreas]() {
container->SetWindowPos(config.Left(), config.Top());
auto pipelineContext = container->GetPipelineContext();
if (pipelineContext) {
@ -2530,7 +2514,7 @@ void UIContentImpl::UpdateViewportConfigWithAnimation(const ViewportConfig& conf
pipelineContext->EnWaitFlushFinish();
pipelineContext->SetUIExtensionFlushFinishCallback(uiExtensionFlushFinishCallback);
}
UpdateSafeArea(pipelineContext, updatingInsets, avoidAreas, config, container);
UpdateSafeArea(pipelineContext, avoidAreas, config, container);
pipelineContext->SetDisplayWindowRectInfo(
Rect(Offset(config.Left(), config.Top()), Size(config.Width(), config.Height())));
TAG_LOGI(AceLogTag::ACE_WINDOW, "Update displayAvailableRect in UpdateViewportConfig to : %{public}s",
@ -2578,11 +2562,9 @@ void UIContentImpl::UpdateViewportConfigWithAnimation(const ViewportConfig& conf
AceViewportConfig aceViewportConfig(modifyConfig, reason, rsTransaction);
bool isReasonRotationOrDPI = (reason == OHOS::Rosen::WindowSizeChangeReason::ROTATION ||
reason == OHOS::Rosen::WindowSizeChangeReason::UPDATE_DPI_SYNC);
bool isAvoidAreaDoChanged = !updatingInsets.empty() ||
avoidAreas.find(OHOS::Rosen::AvoidAreaType::TYPE_KEYBOARD) != avoidAreas.end();
if (container->IsUseStageModel() && isReasonRotationOrDPI) {
viewportConfigMgr_->UpdateConfigSync(aceViewportConfig, std::move(task));
} else if (rsTransaction != nullptr || isAvoidAreaDoChanged) {
} else if (rsTransaction != nullptr || !avoidAreas.empty()) {
// When rsTransaction is not nullptr, the task contains animation. It shouldn't be cancled.
// When avoidAreas need updating, the task shouldn't be cancelled.
viewportConfigMgr_->UpdatePromiseConfig(aceViewportConfig, std::move(task), container,
@ -2590,6 +2572,7 @@ void UIContentImpl::UpdateViewportConfigWithAnimation(const ViewportConfig& conf
} else {
viewportConfigMgr_->UpdateConfig(aceViewportConfig, std::move(task), container, "ArkUIUpdateViewportConfig");
}
viewportConfigMgr_->StoreConfig(aceViewportConfig);
UIExtensionUpdateViewportConfig(config);
}

View File

@ -76,6 +76,15 @@ public:
}
}
void StoreConfig(T& config)
{
aceConfig_ = config;
}
bool IsConfigsEqual(const ViewportConfig& other)
{
return aceConfig_.config_ == other;
}
private:
void PostUpdateConfigTaskLocked(const T& config, CancelableCallback<void()> &&task,
const RefPtr<Container>& container, const std::string& taskName, TaskExecutor::TaskType type)
@ -97,6 +106,8 @@ private:
std::mutex updateTaskMutex_;
UpdateTask currentTask_;
T aceConfig_;
};
} // OHOS::Ace
#endif // FOUNDATION_ARKUI_ACE_ENGINE_FRAMEWORKS_CORE_COMMON_UPDATE_CONFIG_MANAGER_H

View File

@ -949,6 +949,8 @@ public:
void UpdateHalfFoldHoverProperty(int32_t windowWidth, int32_t windowHeight);
void AnimateOnSafeAreaUpdate();
protected:
void StartWindowSizeChangeAnimate(int32_t width, int32_t height, WindowSizeChangeReason type,
const std::shared_ptr<Rosen::RSTransaction>& rsTransaction = nullptr);
@ -1023,8 +1025,6 @@ private:
FrameInfo* GetCurrentFrameInfo(uint64_t recvTime, uint64_t timeStamp);
void AnimateOnSafeAreaUpdate();
// only used for static form.
void UpdateFormLinkInfos();

View File

@ -90,6 +90,22 @@ public:
return transform_;
}
bool operator==(const ViewportConfig& other) const
{
return width_ == other.Width() &&
height_ == other.Height() &&
posX_ == other.Left() &&
posY_ == other.Top() &&
density_ == other.Density() &&
orientation_ == other.Orientation() &&
transform_ == other.TransformHint();
}
bool operator!=(const ViewportConfig& other) const
{
return !operator==(other);
}
std::string ToString() const
{
std::string config = "Viewport config:";