diff --git a/utils/include/wm_common_inner.h b/utils/include/wm_common_inner.h index e18328dcc92112e3749d3b360a2892ade62d00b7..b2fb221086bf8a9771bdc6972e3ea5a05ffce4e6 100644 --- a/utils/include/wm_common_inner.h +++ b/utils/include/wm_common_inner.h @@ -90,36 +90,11 @@ struct ModeChangeHotZonesConfig { uint32_t secondaryRange_; }; -struct WindowShadowParameters { - float elevation_; - std::string color_; - float offsetX_; - float offsetY_; - float alpha_; -}; - -struct AppWindowEffectConfig { - float fullScreenCornerRadius_; - float splitCornerRadius_; - float floatCornerRadius_; - - WindowShadowParameters focusedShadow_; - WindowShadowParameters unfocusedShadow_; - - // defaultCornerRadiusL = 16.0vp - AppWindowEffectConfig() : fullScreenCornerRadius_(0.0), splitCornerRadius_(0.0), floatCornerRadius_(0.0) - { - focusedShadow_ = {0, "#000000", 0, 0, 0}; - unfocusedShadow_ = {0, "#000000", 0, 0, 0}; - } -}; - struct SystemConfig : public Parcelable { bool isSystemDecorEnable_ = true; uint32_t decorModeSupportInfo_ = WindowModeSupport::WINDOW_MODE_SUPPORT_ALL; bool isStretchable_ = false; WindowMode defaultWindowMode_ = WindowMode::WINDOW_MODE_FULLSCREEN; - AppWindowEffectConfig effectConfig_; virtual bool Marshalling(Parcel& parcel) const override { @@ -132,27 +107,6 @@ struct SystemConfig : public Parcelable { return false; } - if (!parcel.WriteFloat(effectConfig_.fullScreenCornerRadius_) || - !parcel.WriteFloat(effectConfig_.splitCornerRadius_) || - !parcel.WriteFloat(effectConfig_.floatCornerRadius_)) { - return false; - } - - if (!parcel.WriteFloat(effectConfig_.focusedShadow_.elevation_) || - !parcel.WriteString(effectConfig_.focusedShadow_.color_) || - !parcel.WriteFloat(effectConfig_.focusedShadow_.offsetX_) || - !parcel.WriteFloat(effectConfig_.focusedShadow_.offsetY_) || - !parcel.WriteFloat(effectConfig_.focusedShadow_.alpha_)) { - return false; - } - - if (!parcel.WriteFloat(effectConfig_.unfocusedShadow_.elevation_) || - !parcel.WriteString(effectConfig_.unfocusedShadow_.color_) || - !parcel.WriteFloat(effectConfig_.unfocusedShadow_.offsetX_) || - !parcel.WriteFloat(effectConfig_.unfocusedShadow_.offsetY_) || - !parcel.WriteFloat(effectConfig_.unfocusedShadow_.alpha_)) { - return false; - } return true; } @@ -163,19 +117,6 @@ struct SystemConfig : public Parcelable { config->isStretchable_ = parcel.ReadBool(); config->decorModeSupportInfo_ = parcel.ReadUint32(); config->defaultWindowMode_ = static_cast(parcel.ReadUint32()); - config->effectConfig_.fullScreenCornerRadius_ = parcel.ReadFloat(); - config->effectConfig_.splitCornerRadius_ = parcel.ReadFloat(); - config->effectConfig_.floatCornerRadius_ = parcel.ReadFloat(); - config->effectConfig_.focusedShadow_.elevation_ = parcel.ReadFloat(); - config->effectConfig_.focusedShadow_.color_ = parcel.ReadString(); - config->effectConfig_.focusedShadow_.offsetX_ = parcel.ReadFloat(); - config->effectConfig_.focusedShadow_.offsetY_ = parcel.ReadFloat(); - config->effectConfig_.focusedShadow_.alpha_ = parcel.ReadFloat(); - config->effectConfig_.unfocusedShadow_.elevation_ = parcel.ReadFloat(); - config->effectConfig_.unfocusedShadow_.color_ = parcel.ReadString(); - config->effectConfig_.unfocusedShadow_.offsetX_ = parcel.ReadFloat(); - config->effectConfig_.unfocusedShadow_.offsetY_ = parcel.ReadFloat(); - config->effectConfig_.unfocusedShadow_.alpha_ = parcel.ReadFloat(); return config; } }; diff --git a/wm/include/window_impl.h b/wm/include/window_impl.h index 01de5d9001b7dca65e275fa5c32be94201caa634..78a66e952b75015e9263783039ddc6844100d181 100644 --- a/wm/include/window_impl.h +++ b/wm/include/window_impl.h @@ -526,9 +526,7 @@ private: void SetSystemConfig(); void TransformSurfaceNode(const Transform& trans); bool IsAppMainOrSunOrFloatingWindow(); - WMError SetWindowCornerRadiusAccordingToSystemConfig(); bool IsAppMainOrSubOrFloatingWindow(); - WMError UpdateWindowShadowAccordingToSystemConfig(); WMError WindowCreateCheck(uint32_t parentId); uint32_t CalculatePointerDirection(int32_t pointerX, int32_t pointerY); void HandlePointerStyle(const std::shared_ptr& pointerEvent); diff --git a/wm/src/window_impl.cpp b/wm/src/window_impl.cpp index 7331fc363a47329372d70b5d0aa3c0d1abd255b6..70e1e61faa594222380eea2c3918085a472e8b2c 100755 --- a/wm/src/window_impl.cpp +++ b/wm/src/window_impl.cpp @@ -119,6 +119,9 @@ RSSurfaceNode::SharedPtr WindowImpl::CreateSurfaceNode(std::string name, WindowT case WindowType::WINDOW_TYPE_POINTER: rsSurfaceNodeType = RSSurfaceNodeType::SELF_DRAWING_WINDOW_NODE; break; + case WindowType::WINDOW_TYPE_APP_MAIN_WINDOW: + rsSurfaceNodeType = RSSurfaceNodeType::APP_WINDOW_NODE; + break; default: rsSurfaceNodeType = RSSurfaceNodeType::DEFAULT; break; @@ -913,83 +916,6 @@ bool WindowImpl::IsAppMainOrSubOrFloatingWindow() return false; } -WMError WindowImpl::SetWindowCornerRadiusAccordingToSystemConfig() -{ - auto display = SingletonContainer::IsDestroyed() ? nullptr : - SingletonContainer::Get().GetDisplayById(property_->GetDisplayId()); - if (display == nullptr) { - WLOGFE("get display failed displayId:%{public}" PRIu64", window id:%{public}u", property_->GetDisplayId(), - property_->GetWindowId()); - return WMError::WM_ERROR_INVALID_WINDOW; - } - auto vpr = display->GetVirtualPixelRatio(); - auto fullscreenRadius = windowSystemConfig_.effectConfig_.fullScreenCornerRadius_ * vpr; - auto splitRadius = windowSystemConfig_.effectConfig_.splitCornerRadius_ * vpr; - auto floatRadius = windowSystemConfig_.effectConfig_.floatCornerRadius_ * vpr; - - WLOGFD("[WEffect] [name:%{public}s] mode: %{public}u, vpr: %{public}f, [%{public}f, %{public}f, %{public}f]", - name_.c_str(), GetMode(), vpr, fullscreenRadius, splitRadius, floatRadius); - if (MathHelper::NearZero(fullscreenRadius) && MathHelper::NearZero(splitRadius) && - MathHelper::NearZero(floatRadius)) { - return WMError::WM_DO_NOTHING; - } - if (WindowHelper::IsFullScreenWindow(GetMode())) { - return SetCornerRadius(fullscreenRadius); - } else if (WindowHelper::IsSplitWindowMode(GetMode())) { - return SetCornerRadius(splitRadius); - } else if (WindowHelper::IsFloatingWindow(GetMode())) { - return SetCornerRadius(floatRadius); - } - return WMError::WM_DO_NOTHING; -} - -WMError WindowImpl::UpdateWindowShadowAccordingToSystemConfig() -{ - if (!WindowHelper::IsAppWindow(GetType()) && !isAppFloatingWindow_) { - return WMError::WM_ERROR_INVALID_WINDOW; - } - - auto& shadow = isFocused_ ? windowSystemConfig_.effectConfig_.focusedShadow_ : - windowSystemConfig_.effectConfig_.unfocusedShadow_; - - if (MathHelper::NearZero(shadow.elevation_)) { - return WMError::WM_ERROR_INVALID_PARAM; - } - - if (!WindowHelper::IsFloatingWindow(GetMode())) { - surfaceNode_->SetShadowElevation(0.f); - WLOGI("[WEffect][%{public}s]close shadow", name_.c_str()); - return WMError::WM_OK; - } - - auto display = SingletonContainer::IsDestroyed() ? nullptr : - SingletonContainer::Get().GetDisplayById(property_->GetDisplayId()); - if (display == nullptr) { - WLOGFE("get display failed displayId:%{public}" PRIu64", window id:%{public}u", property_->GetDisplayId(), - property_->GetWindowId()); - return WMError::WM_ERROR_INVALID_WINDOW; - } - auto vpr = display->GetVirtualPixelRatio(); - - uint32_t colorValue; - if (!ColorParser::Parse(shadow.color_, colorValue)) { - WLOGFE("[WEffect]invalid color string: %{public}s", shadow.color_.c_str()); - return WMError::WM_ERROR_INVALID_PARAM; - } - - WLOGI("[WEffect][%{public}s]focused: %{public}u, [%{public}f, %{public}s, %{public}f, %{public}f, %{public}f]", - name_.c_str(), isFocused_, shadow.elevation_, shadow.color_.c_str(), - shadow.offsetX_, shadow.offsetY_, shadow.alpha_); - - surfaceNode_->SetShadowElevation(shadow.elevation_ * vpr); - surfaceNode_->SetShadowColor(colorValue); - surfaceNode_->SetShadowOffsetX(shadow.offsetX_); - surfaceNode_->SetShadowOffsetY(shadow.offsetY_); - surfaceNode_->SetShadowAlpha(shadow.alpha_); - RSTransaction::FlushImplicitTransaction(); - return WMError::WM_OK; -} - void WindowImpl::SetSystemConfig() { if (!IsAppMainOrSubOrFloatingWindow()) { @@ -1010,9 +936,7 @@ void WindowImpl::SetSystemConfig() property_->SetLastWindowMode(windowSystemConfig_.defaultWindowMode_); } } - SetWindowCornerRadiusAccordingToSystemConfig(); } - UpdateWindowShadowAccordingToSystemConfig(); } WMError WindowImpl::WindowCreateCheck(uint32_t parentId) @@ -2195,11 +2119,6 @@ void WindowImpl::UpdateMode(WindowMode mode) property_->SetWindowMode(mode); UpdateDecorEnable(true); UpdateTitleButtonVisibility(); - - // different modes have different corner radius settings - SetWindowCornerRadiusAccordingToSystemConfig(); - // fullscreen and split have no shadow, float has shadow - UpdateWindowShadowAccordingToSystemConfig(); } void WindowImpl::UpdateModeSupportInfo(uint32_t modeSupportInfo) @@ -2683,7 +2602,6 @@ void WindowImpl::UpdateFocusStatus(bool focused) NotifyAfterUnfocused(); } isFocused_ = focused; - UpdateWindowShadowAccordingToSystemConfig(); } bool WindowImpl::IsFocused() const diff --git a/wm/test/unittest/window_impl_test.cpp b/wm/test/unittest/window_impl_test.cpp index 839967ef30c00bddd04a545c23ccc45208c75f9f..8507be4c3f1347f39fc63f555c1374e416d400d9 100644 --- a/wm/test/unittest/window_impl_test.cpp +++ b/wm/test/unittest/window_impl_test.cpp @@ -2289,66 +2289,6 @@ HWTEST_F(WindowImplTest, UpdateTitleButtonVisibility, Function | SmallTest | Lev ASSERT_EQ(WMError::WM_OK, window->Destroy()); } -/* - * @tc.name: SetWindowCornerRadiusAccordingToSystemConfig - * @tc.desc: SetWindowCornerRadiusAccordingToSystemConfig test - * @tc.type: FUNC - */ -HWTEST_F(WindowImplTest, SetWindowCornerRadiusAccordingToSystemConfig, Function | SmallTest | Level3) -{ - sptr option = new WindowOption(); - sptr window = new WindowImpl(option); - - EXPECT_CALL(m->Mock(), GetSystemConfig(_)).WillOnce(Return(WMError::WM_OK)); - EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK)); - ASSERT_EQ(WMError::WM_OK, window->Create(INVALID_WINDOW_ID)); - - ASSERT_EQ(WMError::WM_DO_NOTHING, window->SetWindowCornerRadiusAccordingToSystemConfig()); - window->windowSystemConfig_.effectConfig_.fullScreenCornerRadius_ = 1.0f; - window->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN); - ASSERT_EQ(WMError::WM_OK, window->SetWindowCornerRadiusAccordingToSystemConfig()); - window->windowSystemConfig_.effectConfig_.fullScreenCornerRadius_ = 0.0f; - window->windowSystemConfig_.effectConfig_.splitCornerRadius_ = 1.0f; - window->SetWindowMode(WindowMode::WINDOW_MODE_SPLIT_PRIMARY); - ASSERT_EQ(WMError::WM_OK, window->SetWindowCornerRadiusAccordingToSystemConfig()); - window->windowSystemConfig_.effectConfig_.splitCornerRadius_ = 0.0f; - window->windowSystemConfig_.effectConfig_.floatCornerRadius_ = 1.0f; - window->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING); - ASSERT_EQ(WMError::WM_OK, window->SetWindowCornerRadiusAccordingToSystemConfig()); - - EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK)); - ASSERT_EQ(WMError::WM_OK, window->Destroy()); -} - -/* - * @tc.name: UpdateWindowShadowAccordingToSystemConfig - * @tc.desc: UpdateWindowShadowAccordingToSystemConfig test - * @tc.type: FUNC - */ -HWTEST_F(WindowImplTest, UpdateWindowShadowAccordingToSystemConfig, Function | SmallTest | Level3) -{ - sptr option = new WindowOption(); - sptr window = new WindowImpl(option); - - EXPECT_CALL(m->Mock(), GetSystemConfig(_)).WillOnce(Return(WMError::WM_OK)); - EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK)); - ASSERT_EQ(WMError::WM_OK, window->Create(INVALID_WINDOW_ID)); - - window->windowSystemConfig_.effectConfig_.unfocusedShadow_.elevation_ = 1.0f; - window->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN); - ASSERT_EQ(WMError::WM_OK, window->UpdateWindowShadowAccordingToSystemConfig()); - - window->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING); - window->windowSystemConfig_.effectConfig_.unfocusedShadow_.color_ = "????"; - ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->UpdateWindowShadowAccordingToSystemConfig()); - - window->windowSystemConfig_.effectConfig_.unfocusedShadow_.color_ = "#000000"; - ASSERT_EQ(WMError::WM_OK, window->UpdateWindowShadowAccordingToSystemConfig()); - - EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK)); - ASSERT_EQ(WMError::WM_OK, window->Destroy()); -} - /* * @tc.name: WindowCreateCheck * @tc.desc: WindowCreateCheck test diff --git a/wmserver/BUILD.gn b/wmserver/BUILD.gn index 4ae1f297e2816a039080e22d591dbfa06f13228c..bfdc9e7a10904b621bc1116c7f5b775dc4cb2f87 100644 --- a/wmserver/BUILD.gn +++ b/wmserver/BUILD.gn @@ -68,6 +68,7 @@ ohos_shared_library("libwms") { "src/window_snapshot/snapshot_controller.cpp", "src/window_snapshot/snapshot_proxy.cpp", "src/window_snapshot/snapshot_stub.cpp", + "src/window_system_effect.cpp", "src/window_zorder_policy.cpp", "src/zidl/ressched_report.cpp", "src/zidl/window_manager_stub.cpp", diff --git a/wmserver/include/starting_window.h b/wmserver/include/starting_window.h index e239f64de9ab2fc37cdc270a0d45f1c9ec0b47e7..280abf7ec038dd346dc7b114434fca8520e3984b 100644 --- a/wmserver/include/starting_window.h +++ b/wmserver/include/starting_window.h @@ -41,22 +41,13 @@ public: static void AddNodeOnRSTree(sptr& node, bool isMultiDisplay); static void ReleaseStartWinSurfaceNode(sptr& node); static void SetDefaultWindowMode(WindowMode defaultMode); - static void SetWindowSystemEffectConfig(AppWindowEffectConfig config); - static void SetWindowRoot(const sptr& windowRoot); - static WMError SetStartingWindowEffect(const sptr& node, bool isFocus = true); static void SetAnimationConfig(AnimationConfig config); static bool transAnimateEnable_; private: static WMError CreateLeashAndStartingSurfaceNode(sptr& node); - // window effect - static WMError SetCornerRadius(const sptr& node); - static WMError SetWindowShadow(const sptr& node, bool isFocus); static WMError SetStartingWindowAnimation(wptr weak); - static std::recursive_mutex mutex_; static WindowMode defaultMode_; - static wptr windowRoot_; - static AppWindowEffectConfig windowSystemEffectConfig_; static AnimationConfig animationConfig_; }; } // Rosen diff --git a/wmserver/include/window_controller.h b/wmserver/include/window_controller.h index 909561e0ecf1ee64aeb384f60236db4e671e802b..e43af417830878f7b0e34bd032b57b7be4463fdc 100644 --- a/wmserver/include/window_controller.h +++ b/wmserver/include/window_controller.h @@ -82,10 +82,10 @@ public: void RecoverDefaultMouseStyle(uint32_t windowId); WmErrorCode RaiseToAppTop(uint32_t windowId); WMError SetAspectRatio(uint32_t windowId, float ratio); + void FlushWindowInfo(uint32_t windowId); private: uint32_t GenWindowId(); - void FlushWindowInfo(uint32_t windowId); void FlushWindowInfoWithDisplayId(DisplayId displayId); void UpdateWindowAnimation(const sptr& node); void ProcessDisplayChange(DisplayId defaultDisplayId, sptr displayInfo, diff --git a/wmserver/include/window_manager_service.h b/wmserver/include/window_manager_service.h index 05ee2e4a2b8172324da809ae7b482ffcaade0847..7d16230464b267131628483e928399d18fcc7d12 100644 --- a/wmserver/include/window_manager_service.h +++ b/wmserver/include/window_manager_service.h @@ -39,6 +39,7 @@ #include "window_dumper.h" #include "window_manager_config.h" #include "window_root.h" +#include "window_system_effect.h" #include "snapshot_controller.h" #include "perform_reporter.h" #include "struct_multimodal.h" diff --git a/wmserver/include/window_node.h b/wmserver/include/window_node.h index 08a315c8dbcb55e170d8df715d75ac13a44c0058..bd80847da1b9ed3787c6eb2c06ff72af2c0f1942 100644 --- a/wmserver/include/window_node.h +++ b/wmserver/include/window_node.h @@ -152,7 +152,7 @@ public: std::vector showingDisplays_; AbilityInfo abilityInfo_; WindowNodeStateMachine stateMachine_; - + bool isFocused_ { false }; private: sptr property_ = nullptr; sptr windowToken_ = nullptr; diff --git a/wmserver/include/window_root.h b/wmserver/include/window_root.h index 26d0d6f8b460c1458a24f75eda599d8d7153dd3d..e3d99bee860193300e5887bd84075c6dbfd187b5 100644 --- a/wmserver/include/window_root.h +++ b/wmserver/include/window_root.h @@ -101,7 +101,7 @@ public: void MinimizeTargetWindows(std::vector& windowIds); WMError UpdateRsTree(uint32_t windowId, bool isAdd); void RemoveSingleUserWindowNodes(int accountId); - sptr FindDialogCallerNode(WindowType type, sptr token); + sptr FindMainWindowWithToken(sptr token); bool CheckMultiDialogWindows(WindowType type, sptr token); bool HasPrivateWindow(DisplayId displayId); Rect GetDisplayRectWithoutSystemBarAreas(DisplayId displayId); diff --git a/wmserver/include/window_system_effect.h b/wmserver/include/window_system_effect.h new file mode 100644 index 0000000000000000000000000000000000000000..eb47534814ec3675340c405332c18f2e3a9a8989 --- /dev/null +++ b/wmserver/include/window_system_effect.h @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_ROSEN_WINDOW_SYSTEM_EFFECT_H +#define OHOS_ROSEN_WINDOW_SYSTEM_EFFECT_H + +#include +#include "wm_common.h" +#include "window_node.h" +#include "window_root.h" + +namespace OHOS { +namespace Rosen { +struct WindowShadowParameters { + float elevation_; + std::string color_; + float offsetX_; + float offsetY_; + float alpha_; +}; +struct AppWindowEffectConfig { + float fullScreenCornerRadius_; + float splitCornerRadius_; + float floatCornerRadius_; + + WindowShadowParameters focusedShadow_; + WindowShadowParameters unfocusedShadow_; + + // defaultCornerRadiusL = 16.0vp + AppWindowEffectConfig() : fullScreenCornerRadius_(0.0), splitCornerRadius_(0.0), floatCornerRadius_(0.0) + { + focusedShadow_ = {0, "#000000", 0, 0, 0}; + unfocusedShadow_ = {0, "#000000", 0, 0, 0}; + } +}; +class WindowSystemEffect : public RefBase { +public: + WindowSystemEffect() = delete; + ~WindowSystemEffect() = default; + + static void SetWindowSystemEffectConfig(AppWindowEffectConfig config); + static void SetWindowRoot(const sptr& windowRoot); + + static WMError SetWindowEffect(const sptr& node); + static WMError SetWindowShadow(const sptr& node); + static WMError SetCornerRadius(const sptr& node); +private: + static bool IsAppMainOrSubOrFloatingWindow(const sptr& node); + static AppWindowEffectConfig windowSystemEffectConfig_; + static wptr windowRoot_; +}; +} // Rosen +} // OHOS +#endif // OHOS_ROSEN_WINDOW_SYSTEM_EFFECT_H diff --git a/wmserver/src/input_window_monitor.cpp b/wmserver/src/input_window_monitor.cpp index 4672ead00fcb8f5ccaee00bc9c74ad8b1743c26f..432cfeb3c31e948255dce658ab7e05258ae13b6b 100644 --- a/wmserver/src/input_window_monitor.cpp +++ b/wmserver/src/input_window_monitor.cpp @@ -166,8 +166,11 @@ void InputWindowMonitor::TraverseWindowNodes(const std::vector> { std::map> dialogWindowMap; for (const auto& windowNode: windowNodes) { + if (windowNode->GetWindowType() != WindowType::WINDOW_TYPE_DIALOG) { + continue; + } sptr callerNode = - windowRoot_->FindDialogCallerNode(windowNode->GetWindowType(), windowNode->dialogTargetToken_); + windowRoot_->FindMainWindowWithToken(windowNode->dialogTargetToken_); if (callerNode != nullptr) { dialogWindowMap.insert(std::make_pair(callerNode->GetWindowId(), windowNode)); } diff --git a/wmserver/src/remote_animation.cpp b/wmserver/src/remote_animation.cpp index ba169299158c6cd3bc9831dd13a676b07fc79e4d..22ba8eb9c9a67d10c4a2d3d481598d3e310455f7 100644 --- a/wmserver/src/remote_animation.cpp +++ b/wmserver/src/remote_animation.cpp @@ -28,6 +28,7 @@ #include "window_helper.h" #include "window_inner_manager.h" #include "window_manager_hilog.h" +#include "window_system_effect.h" #include "zidl/ressched_report.h" namespace OHOS { @@ -182,7 +183,6 @@ static void GetAndDrawSnapShot(const sptr& srcNode) srcNode->startingWinSurfaceNode_->SetBounds(0, 0, rect.width_, rect.height_); SurfaceDraw::DrawImageRect(srcNode->startingWinSurfaceNode_, srcNode->GetWindowRect(), pixelMap, 0x00ffffff, true); - StartingWindow::SetStartingWindowEffect(srcNode, false); srcNode->leashWinSurfaceNode_->RemoveChild(srcNode->surfaceNode_); srcNode->leashWinSurfaceNode_->AddChild(srcNode->startingWinSurfaceNode_, -1); RSTransaction::FlushImplicitTransaction(); @@ -660,9 +660,6 @@ sptr RemoteAnimation::CreateWindowAnimationTarget(sptr< auto boundsRect = RectF(rect.posX_, rect.posY_, rect.width_, rect.height_); auto& stagingProperties = windowAnimationTarget->surfaceNode_->GetStagingProperties(); auto radius = stagingProperties.GetCornerRadius(); - if (windowNode->startingWinSurfaceNode_ != nullptr) { - radius = windowNode->startingWinSurfaceNode_->GetStagingProperties().GetCornerRadius(); - } windowAnimationTarget->windowBounds_ = RRect(boundsRect, radius); return windowAnimationTarget; } @@ -700,6 +697,11 @@ void RemoteAnimation::ExecuteFinalStateTask(sptr& node) } else if (node->stateMachine_.IsWindowNodeShownOrShowing()) { WLOGFI("execute task layout after show animation id:%{public}u!", node->GetWindowId()); winRoot->LayoutWhenAddWindowNode(node, true); + WindowSystemEffect::SetWindowEffect(node); + auto winController = windowController_.promote(); + if (winController) { + winController->FlushWindowInfo(node->GetWindowId()); + } } else { WLOGFD("current State:%{public}u invalid", static_cast(node->stateMachine_.GetCurrentState())); } diff --git a/wmserver/src/starting_window.cpp b/wmserver/src/starting_window.cpp index 6ea0f9b36bb58c55171d4ad6955064a0f0bc328d..a1a998a2383cc094dd72b9b40eedc494256faa11 100644 --- a/wmserver/src/starting_window.cpp +++ b/wmserver/src/starting_window.cpp @@ -19,12 +19,12 @@ #include #include #include -#include "color_parser.h" #include "remote_animation.h" #include "window_helper.h" #include "window_inner_manager.h" #include "window_manager_hilog.h" #include "window_manager_service.h" +#include "window_system_effect.h" namespace OHOS { namespace Rosen { @@ -34,8 +34,6 @@ namespace { std::recursive_mutex StartingWindow::mutex_; WindowMode StartingWindow::defaultMode_ = WindowMode::WINDOW_MODE_FULLSCREEN; -wptr StartingWindow::windowRoot_; -AppWindowEffectConfig StartingWindow::windowSystemEffectConfig_; bool StartingWindow::transAnimateEnable_ = true; AnimationConfig StartingWindow::animationConfig_; @@ -123,7 +121,7 @@ WMError StartingWindow::DrawStartingWindow(sptr& node, return WMError::WM_ERROR_NULLPTR; } // set window effect - SetStartingWindowEffect(node); + WindowSystemEffect::SetWindowEffect(node); if (pixelMap == nullptr) { SurfaceDraw::DrawColor(node->startingWinSurfaceNode_, rect.width_, rect.height_, bkgColor); return WMError::WM_OK; @@ -299,98 +297,9 @@ void StartingWindow::SetDefaultWindowMode(WindowMode defaultMode) defaultMode_ = defaultMode; } -void StartingWindow::SetWindowSystemEffectConfig(AppWindowEffectConfig config) -{ - windowSystemEffectConfig_ = config; -} - void StartingWindow::SetAnimationConfig(AnimationConfig config) { animationConfig_ = config; } - -void StartingWindow::SetWindowRoot(const sptr& windowRoot) -{ - windowRoot_ = windowRoot; -} - -WMError StartingWindow::SetCornerRadius(const sptr& node) -{ - auto winRoot = windowRoot_.promote(); - if (winRoot == nullptr) { - WLOGFE("window root is null"); - return WMError::WM_ERROR_NULLPTR; - } - - auto vpr = winRoot->GetVirtualPixelRatio(node->GetDisplayId()); - auto fullscreenRadius = windowSystemEffectConfig_.fullScreenCornerRadius_ * vpr; - auto splitRadius = windowSystemEffectConfig_.splitCornerRadius_ * vpr; - auto floatRadius = windowSystemEffectConfig_.floatCornerRadius_ * vpr; - - WLOGFD("[WEffect] [id:%{public}d] mode: %{public}u, vpr: %{public}f, [%{public}f, %{public}f, %{public}f]", - node->GetWindowId(), node->GetWindowMode(), vpr, fullscreenRadius, splitRadius, floatRadius); - if (MathHelper::NearZero(fullscreenRadius) && MathHelper::NearZero(splitRadius) && - MathHelper::NearZero(floatRadius)) { - return WMError::WM_DO_NOTHING; - } - if (WindowHelper::IsFullScreenWindow(node->GetWindowMode())) { - node->startingWinSurfaceNode_->SetCornerRadius(fullscreenRadius); - } else if (WindowHelper::IsSplitWindowMode(node->GetWindowMode())) { - node->startingWinSurfaceNode_->SetCornerRadius(splitRadius); - } else if (WindowHelper::IsFloatingWindow(node->GetWindowMode())) { - node->startingWinSurfaceNode_->SetCornerRadius(floatRadius); - } - return WMError::WM_OK; -} - -WMError StartingWindow::SetWindowShadow(const sptr& node, bool isFocus) -{ - auto winRoot = windowRoot_.promote(); - if (winRoot == nullptr) { - return WMError::WM_ERROR_NULLPTR; - } - - if (!WindowHelper::IsFloatingWindow(node->GetWindowMode())) { - WLOGFW("only float mode can set shadow, id: %{public}u!", node->GetWindowId()); - return WMError::WM_ERROR_INVALID_PARAM; - } - - auto& shadow = isFocus ? windowSystemEffectConfig_.focusedShadow_ : - windowSystemEffectConfig_.unfocusedShadow_; - - if (MathHelper::NearZero(shadow.elevation_)) { - WLOGFD("set shadow elevation 0.0"); - return WMError::WM_ERROR_INVALID_PARAM; - } - - uint32_t colorValue; - if (!ColorParser::Parse(shadow.color_, colorValue)) { - WLOGFE("[WEffect]invalid color string: %{public}s", shadow.color_.c_str()); - return WMError::WM_ERROR_INVALID_PARAM; - } - - WLOGFI("[WEffect][id:%{public}d] focused: %{public}u, [%{public}f, %{public}s, %{public}f, %{public}f, %{public}f]", - node->GetWindowId(), isFocus, shadow.elevation_, shadow.color_.c_str(), - shadow.offsetX_, shadow.offsetY_, shadow.alpha_); - auto vpr = winRoot->GetVirtualPixelRatio(node->GetDisplayId()); - node->startingWinSurfaceNode_->SetShadowElevation(shadow.elevation_ * vpr); - node->startingWinSurfaceNode_->SetShadowColor(colorValue); - node->startingWinSurfaceNode_->SetShadowOffsetX(shadow.offsetX_); - node->startingWinSurfaceNode_->SetShadowOffsetY(shadow.offsetY_); - node->startingWinSurfaceNode_->SetShadowAlpha(shadow.alpha_); - return WMError::WM_OK; -} - -WMError StartingWindow::SetStartingWindowEffect(const sptr& node, bool isFocus) -{ - auto winRoot = windowRoot_.promote(); - if ((!node) || (!node->startingWinSurfaceNode_)) { - WLOGFE("window root or node or startingWinSurfaceNode_ is null"); - return WMError::WM_ERROR_NULLPTR; - } - SetCornerRadius(node); - SetWindowShadow(node, isFocus); - return WMError::WM_OK; -} } // Rosen } // OHOS diff --git a/wmserver/src/window_controller.cpp b/wmserver/src/window_controller.cpp index 353ea5a2b46959113cc815fcecc360602f7203c8..2d73d40d85521e5b5c5855cc95b6668e3935d4f5 100644 --- a/wmserver/src/window_controller.cpp +++ b/wmserver/src/window_controller.cpp @@ -33,6 +33,7 @@ #include "window_inner_manager.h" #include "window_manager_hilog.h" #include "window_helper.h" +#include "window_system_effect.h" #include "wm_common.h" #include "wm_math.h" @@ -246,6 +247,8 @@ WMError WindowController::CreateWindow(sptr& window, sptrabilityToken_ = token; node->dialogTargetToken_ = token; UpdateWindowAnimation(node); + // for system and subwindow + WindowSystemEffect::SetWindowEffect(node); WLOGFD("createWindow id:%{public}u", windowId); // test node->stateMachine_.SetWindowId(windowId); diff --git a/wmserver/src/window_layout_policy_cascade.cpp b/wmserver/src/window_layout_policy_cascade.cpp index 5c5ca8d66d32f6c9a26f30738fbde4865001ef00..36c935062b368fb38e85b70bd9ec1dcbdc4dfb3f 100644 --- a/wmserver/src/window_layout_policy_cascade.cpp +++ b/wmserver/src/window_layout_policy_cascade.cpp @@ -21,6 +21,7 @@ #include "window_helper.h" #include "window_inner_manager.h" #include "window_manager_hilog.h" +#include "window_system_effect.h" #include "wm_math.h" namespace OHOS { @@ -81,6 +82,8 @@ void WindowLayoutPolicyCascade::Reorder() node->SetDecoStatus(true); if (node->GetWindowMode() != WindowMode::WINDOW_MODE_FLOATING) { node->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING); + // when change mode, need to reset shadow and radius + WindowSystemEffect::SetWindowEffect(node); if (node->GetWindowToken()) { node->GetWindowToken()->UpdateWindowMode(WindowMode::WINDOW_MODE_FLOATING); } diff --git a/wmserver/src/window_layout_policy_tile.cpp b/wmserver/src/window_layout_policy_tile.cpp index 8a31702da8aec7c3910c87dd2cb0602f408097f3..9281937e27f9fe9e5229271459a6caabbb1ec22e 100644 --- a/wmserver/src/window_layout_policy_tile.cpp +++ b/wmserver/src/window_layout_policy_tile.cpp @@ -21,6 +21,7 @@ #include "window_helper.h" #include "window_inner_manager.h" #include "window_manager_hilog.h" +#include "window_system_effect.h" namespace OHOS { namespace Rosen { @@ -314,6 +315,8 @@ void WindowLayoutPolicyTile::ApplyPresetRectForTileWindows(DisplayId displayId) auto& rect = (*rectIt); if (WindowHelper::IsRectSatisfiedWithSizeLimits(rect, node->GetWindowUpdatedSizeLimits())) { node->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING); + // when change mode, need to reset shadow and radius + WindowSystemEffect::SetWindowEffect(node); if (node->GetWindowToken()) { node->GetWindowToken()->UpdateWindowMode(WindowMode::WINDOW_MODE_FLOATING); } diff --git a/wmserver/src/window_manager_service.cpp b/wmserver/src/window_manager_service.cpp index 0edb420886210f8a456a0aab0c607c02bb359439..54ebe2a4ebc93b8d8f84d473f4aa35f61ca3512b 100644 --- a/wmserver/src/window_manager_service.cpp +++ b/wmserver/src/window_manager_service.cpp @@ -274,7 +274,7 @@ bool WindowManagerService::Init() ConfigureWindowManagerService(); StartingWindow::SetAnimationConfig(WindowNodeContainer::GetAnimationConfigRef()); } - StartingWindow::SetWindowRoot(windowRoot_); + WindowSystemEffect::SetWindowRoot(windowRoot_); WLOGI("Init success"); return true; } @@ -592,14 +592,14 @@ bool WindowManagerService::ConfigAppWindowShadow(const WindowManagerConfig::Conf void WindowManagerService::ConfigWindowEffect(const WindowManagerConfig::ConfigItem& effectConfig) { AppWindowEffectConfig config; - + AppWindowEffectConfig systemEffectConfig; // config corner radius WindowManagerConfig::ConfigItem item = effectConfig["appWindows"]["cornerRadius"]; if (item.IsMap()) { if (ConfigAppWindowCornerRadius(item["fullScreen"], config.fullScreenCornerRadius_) && ConfigAppWindowCornerRadius(item["split"], config.splitCornerRadius_) && ConfigAppWindowCornerRadius(item["float"], config.floatCornerRadius_)) { - systemConfig_.effectConfig_ = config; + systemEffectConfig = config; } } @@ -607,17 +607,17 @@ void WindowManagerService::ConfigWindowEffect(const WindowManagerConfig::ConfigI item = effectConfig["appWindows"]["shadow"]["focused"]; if (item.IsMap()) { if (ConfigAppWindowShadow(item, config.focusedShadow_)) { - systemConfig_.effectConfig_.focusedShadow_ = config.focusedShadow_; + systemEffectConfig.focusedShadow_ = config.focusedShadow_; } } item = effectConfig["appWindows"]["shadow"]["unfocused"]; if (item.IsMap()) { if (ConfigAppWindowShadow(item, config.unfocusedShadow_)) { - systemConfig_.effectConfig_.unfocusedShadow_ = config.unfocusedShadow_; + systemEffectConfig.unfocusedShadow_ = config.unfocusedShadow_; } } - StartingWindow::SetWindowSystemEffectConfig(systemConfig_.effectConfig_); + WindowSystemEffect::SetWindowSystemEffectConfig(systemEffectConfig); } RSAnimationTimingCurve WindowManagerService::CreateCurve(const WindowManagerConfig::ConfigItem& curveConfig) diff --git a/wmserver/src/window_node_container.cpp b/wmserver/src/window_node_container.cpp index 191bf5f967bb01a9e33285300d556507428dd7d6..371e650553740617e187bd71857f4d10e858ea69 100644 --- a/wmserver/src/window_node_container.cpp +++ b/wmserver/src/window_node_container.cpp @@ -38,6 +38,7 @@ #include "window_manager_agent_controller.h" #include "window_manager_hilog.h" #include "window_manager_service.h" +#include "window_system_effect.h" #include "wm_common.h" #include "wm_common_inner.h" @@ -746,7 +747,9 @@ void WindowNodeContainer::UpdateFocusStatus(uint32_t id, bool focused) if (focused) { focusedPid_ = node->GetCallingPid(); } - + node->isFocused_ = focused; + // change focus window shadow + WindowSystemEffect::SetWindowShadow(node); if (node->GetCallingPid() == 0) { WLOGFW("focused window is starting window, no need notify"); return; @@ -1904,6 +1907,8 @@ void WindowNodeContainer::ReZOrderShowWhenLockedWindows(bool up) parentNode->children_.insert(position, needReZOrderNode); if (up && WindowHelper::IsSplitWindowMode(needReZOrderNode->GetWindowMode())) { needReZOrderNode->GetWindowProperty()->ResumeLastWindowMode(); + // when change mode, need to reset shadow and radius + WindowSystemEffect::SetWindowEffect(needReZOrderNode); if (needReZOrderNode->GetWindowToken() != nullptr) { needReZOrderNode->GetWindowToken()->UpdateWindowMode(needReZOrderNode->GetWindowMode()); } @@ -1948,6 +1953,8 @@ void WindowNodeContainer::RaiseShowWhenLockedWindowIfNeeded(const sptrparent_ = aboveAppWindowNode_; if (WindowHelper::IsSplitWindowMode(node->GetWindowMode())) { node->GetWindowProperty()->ResumeLastWindowMode(); + // when change mode, need to reset shadow and radius + WindowSystemEffect::SetWindowEffect(node); if (node->GetWindowToken() != nullptr) { node->GetWindowToken()->UpdateWindowMode(node->GetWindowMode()); } @@ -2108,6 +2115,8 @@ WMError WindowNodeContainer::SetWindowMode(sptr& node, WindowMode ds return res; } } + // when change mode, need to reset shadow and radius + WindowSystemEffect::SetWindowEffect(node); if (node->GetWindowToken() != nullptr) { node->GetWindowToken()->UpdateWindowMode(node->GetWindowMode()); } diff --git a/wmserver/src/window_pair.cpp b/wmserver/src/window_pair.cpp index a1bd246cd779cc3dc4687816747bc89a0475cb1b..12332d3bc3636167c912554eaf2ab62e4993c8b8 100644 --- a/wmserver/src/window_pair.cpp +++ b/wmserver/src/window_pair.cpp @@ -21,6 +21,7 @@ #include "window_inner_manager.h" #include "window_manager_hilog.h" #include "window_helper.h" +#include "window_system_effect.h" #include "surface_draw.h" namespace OHOS { @@ -208,6 +209,8 @@ void WindowPair::Clear() primary_->SetWindowSizeChangeReason(WindowSizeChangeReason::SPLIT_TO_FULL); } primary_->GetWindowProperty()->ResumeLastWindowMode(); + // when change mode, need to reset shadow and radius + WindowSystemEffect::SetWindowEffect(primary_); primary_->GetWindowToken()->UpdateWindowMode(primary_->GetWindowMode()); } } @@ -223,6 +226,8 @@ void WindowPair::Clear() secondary_->SetWindowSizeChangeReason(WindowSizeChangeReason::SPLIT_TO_FULL); } secondary_->GetWindowProperty()->ResumeLastWindowMode(); + // when change mode, need to reset shadow and radius + WindowSystemEffect::SetWindowEffect(secondary_); secondary_->GetWindowToken()->UpdateWindowMode(secondary_->GetWindowMode()); } } @@ -386,6 +391,8 @@ void WindowPair::SwitchPosition() if (primary_->GetWindowMode() == secondary_->GetWindowMode() && primary_->GetWindowMode() == WindowMode::WINDOW_MODE_SPLIT_PRIMARY) { primary_->SetWindowMode(WindowMode::WINDOW_MODE_SPLIT_SECONDARY); + // when change mode, need to reset shadow and radius + WindowSystemEffect::SetWindowEffect(primary_); if (primary_->GetWindowToken() != nullptr) { primary_->GetWindowToken()->UpdateWindowMode(WindowMode::WINDOW_MODE_SPLIT_SECONDARY); } @@ -393,6 +400,8 @@ void WindowPair::SwitchPosition() } else if (primary_->GetWindowMode() == secondary_->GetWindowMode() && primary_->GetWindowMode() == WindowMode::WINDOW_MODE_SPLIT_SECONDARY) { secondary_->SetWindowMode(WindowMode::WINDOW_MODE_SPLIT_PRIMARY); + // when change mode, need to reset shadow and radius + WindowSystemEffect::SetWindowEffect(secondary_); if (secondary_->GetWindowToken() != nullptr) { secondary_->GetWindowToken()->UpdateWindowMode(WindowMode::WINDOW_MODE_SPLIT_PRIMARY); } @@ -480,6 +489,8 @@ void WindowPair::HandleRemoveWindow(sptr& node) WLOGI("Resume unpaired split related window id: %{public}u", node->GetWindowId()); if (node->GetWindowProperty() != nullptr && node->GetWindowToken() != nullptr) { node->GetWindowProperty()->ResumeLastWindowMode(); + // when change mode, need to reset shadow and radius + WindowSystemEffect::SetWindowEffect(node); node->GetWindowToken()->UpdateWindowMode(node->GetWindowMode()); } // target node is not in window pair, need resume mode when remove diff --git a/wmserver/src/window_root.cpp b/wmserver/src/window_root.cpp index 1d6e02b4c17b8f0a1c9beec1938b61f7be2b8e67..178c9f4ff6cf491506d85971459ad7f0704ad458 100644 --- a/wmserver/src/window_root.cpp +++ b/wmserver/src/window_root.cpp @@ -29,7 +29,7 @@ #include "window_manager_hilog.h" #include "window_manager_service.h" #include "window_manager_agent_controller.h" - +#include "window_system_effect.h" namespace OHOS { namespace Rosen { namespace { @@ -446,6 +446,8 @@ WMError WindowRoot::ToggleShownStateForAllAppWindows() if (mode == WindowMode::WINDOW_MODE_SPLIT_PRIMARY || mode == WindowMode::WINDOW_MODE_SPLIT_SECONDARY) { property->SetWindowMode(mode); + // when change mode, need to reset shadow and radius + WindowSystemEffect::SetWindowEffect(windowNode); windowNode->GetWindowToken()->RestoreSplitWindowMode(static_cast(mode)); } windowNode->GetWindowToken()->UpdateWindowState(WindowState::STATE_SHOWN); @@ -607,7 +609,7 @@ WMError WindowRoot::BindDialogToParent(sptr& node, sptr& if (node->GetWindowType() != WindowType::WINDOW_TYPE_DIALOG) { return WMError::WM_OK; } - sptr callerNode = FindDialogCallerNode(node->GetWindowType(), node->dialogTargetToken_); + sptr callerNode = FindMainWindowWithToken(node->dialogTargetToken_); parentNode = (callerNode != nullptr) ? callerNode : nullptr; if (parentNode == nullptr) { node->GetWindowToken()->NotifyDestroy(); @@ -1179,7 +1181,7 @@ WMError WindowRoot::RaiseZOrderForAppWindow(sptr& node) WLOGFW("window container could not be found"); return WMError::WM_ERROR_NULLPTR; } - sptr parentNode = FindDialogCallerNode(node->GetWindowType(), node->dialogTargetToken_); + sptr parentNode = FindMainWindowWithToken(node->dialogTargetToken_); if (parentNode != nullptr) { container->RaiseZOrderForAppWindow(node, parentNode); } @@ -1628,12 +1630,8 @@ WMError WindowRoot::UpdateRsTree(uint32_t windowId, bool isAdd) return WMError::WM_OK; } -sptr WindowRoot::FindDialogCallerNode(WindowType type, sptr token) +sptr WindowRoot::FindMainWindowWithToken(sptr token) { - if (type != WindowType::WINDOW_TYPE_DIALOG) { - return nullptr; - } - auto iter = std::find_if(windowNodeMap_.begin(), windowNodeMap_.end(), [token](const std::map>::value_type& pair) { if (WindowHelper::IsMainWindow(pair.second->GetWindowType())) { @@ -1656,14 +1654,14 @@ bool WindowRoot::CheckMultiDialogWindows(WindowType type, sptr to sptr newCaller, oriCaller; - newCaller = FindDialogCallerNode(type, token); + newCaller = FindMainWindowWithToken(token); if (newCaller == nullptr) { return false; } for (auto& iter : windowNodeMap_) { if (iter.second->GetWindowType() == WindowType::WINDOW_TYPE_DIALOG) { - oriCaller = FindDialogCallerNode(iter.second->GetWindowType(), iter.second->dialogTargetToken_); + oriCaller = FindMainWindowWithToken(iter.second->dialogTargetToken_); if (oriCaller == newCaller) { return true; } diff --git a/wmserver/src/window_system_effect.cpp b/wmserver/src/window_system_effect.cpp new file mode 100644 index 0000000000000000000000000000000000000000..abc5abd88f59d48d03171938674a7ae8c9e45a9e --- /dev/null +++ b/wmserver/src/window_system_effect.cpp @@ -0,0 +1,167 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "window_system_effect.h" + +#include +#include "color_parser.h" +#include "remote_animation.h" +#include "window_helper.h" +#include "window_inner_manager.h" +#include "window_manager_hilog.h" + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowSystemEffect"}; +} + +AppWindowEffectConfig WindowSystemEffect::windowSystemEffectConfig_; +wptr WindowSystemEffect::windowRoot_; + +void WindowSystemEffect::SetWindowSystemEffectConfig(AppWindowEffectConfig config) +{ + windowSystemEffectConfig_ = config; +} + +void WindowSystemEffect::SetWindowRoot(const sptr& windowRoot) +{ + windowRoot_ = windowRoot; +} + +WMError WindowSystemEffect::SetCornerRadius(const sptr& node) +{ + auto winRoot = windowRoot_.promote(); + if (winRoot == nullptr || node == nullptr) { + WLOGFE("window root is null"); + return WMError::WM_ERROR_NULLPTR; + } + // if change mode during animation, not set radius until animationFinish + if (RemoteAnimation::IsRemoteAnimationEnabledAndFirst(node->GetDisplayId()) && + node->stateMachine_.IsShowAnimationPlaying()) { + WLOGFW("not set radius during animation"); + return WMError::WM_DO_NOTHING; + } + + if (!IsAppMainOrSubOrFloatingWindow(node)) { + return WMError::WM_DO_NOTHING; + } + auto vpr = winRoot->GetVirtualPixelRatio(node->GetDisplayId()); + auto fullscreenRadius = windowSystemEffectConfig_.fullScreenCornerRadius_ * vpr; + auto splitRadius = windowSystemEffectConfig_.splitCornerRadius_ * vpr; + auto floatRadius = windowSystemEffectConfig_.floatCornerRadius_ * vpr; + + WLOGFD("[WEffect] [id:%{public}d] mode: %{public}u, vpr: %{public}f, [%{public}f, %{public}f, %{public}f]", + node->GetWindowId(), node->GetWindowMode(), vpr, fullscreenRadius, splitRadius, floatRadius); + if (MathHelper::NearZero(fullscreenRadius) && MathHelper::NearZero(splitRadius) && + MathHelper::NearZero(floatRadius)) { + return WMError::WM_DO_NOTHING; + } + auto surfaceNode = node->leashWinSurfaceNode_ != nullptr ? node->leashWinSurfaceNode_ : node->surfaceNode_; + if (surfaceNode == nullptr) { + WLOGFE("window surfaceNode is null"); + return WMError::WM_ERROR_NULLPTR; + } + if (WindowHelper::IsFullScreenWindow(node->GetWindowMode())) { + surfaceNode->SetCornerRadius(fullscreenRadius); + } else if (WindowHelper::IsSplitWindowMode(node->GetWindowMode())) { + surfaceNode->SetCornerRadius(splitRadius); + } else if (WindowHelper::IsFloatingWindow(node->GetWindowMode())) { + surfaceNode->SetCornerRadius(floatRadius); + } + return WMError::WM_OK; +} + +bool WindowSystemEffect::IsAppMainOrSubOrFloatingWindow(const sptr& node) +{ + if (WindowHelper::IsAppWindow(node->GetWindowType())) { + return true; + } + auto winRoot = windowRoot_.promote(); + if (winRoot == nullptr) { + return false; + } + // Type float has main window + if (WindowHelper::IsAppFloatingWindow(node->GetWindowType()) && + winRoot->FindMainWindowWithToken(node->abilityToken_)) { + return true; + } + WLOGFD("not appWindow or app floating window, id: %{public}u!", node->GetWindowId()); + return false; +} + +WMError WindowSystemEffect::SetWindowShadow(const sptr& node) +{ + auto winRoot = windowRoot_.promote(); + if (winRoot == nullptr || node == nullptr) { + return WMError::WM_ERROR_NULLPTR; + } + + if (!IsAppMainOrSubOrFloatingWindow(node)) { + return WMError::WM_DO_NOTHING; + } + + if (MathHelper::NearZero(windowSystemEffectConfig_.focusedShadow_.elevation_) && + MathHelper::NearZero(windowSystemEffectConfig_.unfocusedShadow_.elevation_)) { + WLOGFD("shadow elevation both 0.0, id: %{public}u", node->GetWindowId()); + return WMError::WM_DO_NOTHING; + } + + auto surfaceNode = node->leashWinSurfaceNode_ != nullptr ? node->leashWinSurfaceNode_ : node->surfaceNode_; + if (surfaceNode == nullptr) { + WLOGFE("window surfaceNode is null"); + return WMError::WM_ERROR_NULLPTR; + } + // when float mode change to fullscreen/split mode + if (!WindowHelper::IsFloatingWindow(node->GetWindowMode())) { + surfaceNode->SetShadowElevation(0.f); + surfaceNode->SetShadowAlpha(0.f); + WLOGFD("[WEffect]close shadow id: %{public}u", node->GetWindowId()); + return WMError::WM_OK; + } + + auto& shadow = node->isFocused_ ? windowSystemEffectConfig_.focusedShadow_ : + windowSystemEffectConfig_.unfocusedShadow_; + uint32_t colorValue; + if (!ColorParser::Parse(shadow.color_, colorValue)) { + WLOGFE("[WEffect]invalid color string: %{public}s", shadow.color_.c_str()); + return WMError::WM_ERROR_INVALID_PARAM; + } + + WLOGFI("[WEffect][id:%{public}d] focused: %{public}u, [%{public}f, %{public}s, %{public}f, %{public}f, %{public}f]", + node->GetWindowId(), node->isFocused_, shadow.elevation_, shadow.color_.c_str(), + shadow.offsetX_, shadow.offsetY_, shadow.alpha_); + auto vpr = winRoot->GetVirtualPixelRatio(node->GetDisplayId()); + surfaceNode->SetShadowElevation(shadow.elevation_ * vpr); + surfaceNode->SetShadowColor(colorValue); + surfaceNode->SetShadowOffsetX(shadow.offsetX_); + surfaceNode->SetShadowOffsetY(shadow.offsetY_); + surfaceNode->SetShadowAlpha(shadow.alpha_); + return WMError::WM_OK; +} + +WMError WindowSystemEffect::SetWindowEffect(const sptr& node) +{ + auto winRoot = windowRoot_.promote(); + if (node == nullptr) { + WLOGFE("window node is null"); + return WMError::WM_ERROR_NULLPTR; + } + SetCornerRadius(node); + SetWindowShadow(node); + return WMError::WM_OK; +} +} // Rosen +} // OHOS diff --git a/wmserver/test/unittest/BUILD.gn b/wmserver/test/unittest/BUILD.gn index c9452d22692abda5170294f6be1c3c32a3882ae2..ebfdfbe6d59771dc79cb06c5ba5749206b5529cb 100644 --- a/wmserver/test/unittest/BUILD.gn +++ b/wmserver/test/unittest/BUILD.gn @@ -44,6 +44,7 @@ group("unittest") { ":wmserver_window_pair_test", ":wmserver_window_root_test", ":wmserver_window_snapshot_test", + ":wmserver_window_system_effect_test", ":wmserver_window_zorder_policy_test", ] } @@ -381,3 +382,13 @@ ohos_unittest("wmserver_window_root_test") { public_deps = test_public_deps external_deps = test_external_deps } + +ohos_unittest("wmserver_window_system_effect_test") { + module_out_path = module_out_path + configs = test_public_config + sources = [ "window_system_effect_test.cpp" ] + + deps = test_inner_deps + public_deps = test_public_deps + external_deps = test_external_deps +} diff --git a/wmserver/test/unittest/starting_window_test.cpp b/wmserver/test/unittest/starting_window_test.cpp index 9ebee793689ce54e38bf61fcdd42d458456f5527..f3bdba9695b3279bbe515e63fa3be61e0aef02f3 100644 --- a/wmserver/test/unittest/starting_window_test.cpp +++ b/wmserver/test/unittest/starting_window_test.cpp @@ -38,15 +38,12 @@ private: static sptr transitionInfo_; RSSurfaceNode::SharedPtr CreateRSSurfaceNode(); static sptr animationController_; - static sptr node_; - AppWindowEffectConfig effectConfig_; + sptr node_; AnimationConfig animationConfig_; - sptr windowRoot_; }; sptr StartingWindowTest::transitionInfo_ = nullptr; sptr StartingWindowTest::animationController_ = nullptr; -sptr StartingWindowTest::node_ = nullptr; void StartingWindowTest::SetUpTestCase() { @@ -68,16 +65,7 @@ void StartingWindowTest::SetUp() }; node_ = StartingWindow::CreateWindowNode(transitionInfo_, 101); // 101 is windowId node_->SetWindowRect({0, 0, 100, 100}); // 100 test data - effectConfig_.fullScreenCornerRadius_ = 16.0f; // 16.f test data - effectConfig_.splitCornerRadius_ = 16.0f; // 16.f test data - effectConfig_.floatCornerRadius_ = 16.0f; // 16.f test data - effectConfig_.focusedShadow_ = {80, "#000000", 0, 5, 0.45}; - effectConfig_.unfocusedShadow_ = {55, "#000000", 0, 10, 0.25}; - StartingWindow::SetWindowSystemEffectConfig(effectConfig_); StartingWindow::SetAnimationConfig(animationConfig_); - windowRoot_ = new WindowRoot([](Event event, const sptr& remoteObject) {}); - ASSERT_NE(nullptr, windowRoot_); - StartingWindow::SetWindowRoot(windowRoot_); StartingWindow::transAnimateEnable_ = true; } @@ -85,8 +73,6 @@ void StartingWindowTest::TearDown() { transitionInfo_ = nullptr; node_ = nullptr; - AppWindowEffectConfig config; - effectConfig_ = config; } RSSurfaceNode::SharedPtr StartingWindowTest::CreateRSSurfaceNode() @@ -216,6 +202,7 @@ HWTEST_F(StartingWindowTest, DrawStartingWindow01, Function | SmallTest | Level2 std::shared_ptr pixelMap = std::make_shared(); sptr node = nullptr; ASSERT_EQ(WMError::WM_ERROR_NULLPTR, StartingWindow::DrawStartingWindow(node, pixelMap, 0x00FFFFFF, true)); + usleep(10000); } /** @@ -228,6 +215,7 @@ HWTEST_F(StartingWindowTest, DrawStartingWindow02, Function | SmallTest | Level2 node_->leashWinSurfaceNode_ = nullptr; std::shared_ptr pixelMap = std::make_shared(); ASSERT_EQ(WMError::WM_OK, StartingWindow::DrawStartingWindow(node_, pixelMap, 0x00FFFFFF, true)); + usleep(10000); } /** @@ -239,6 +227,7 @@ HWTEST_F(StartingWindowTest, DrawStartingWindow03, Function | SmallTest | Level2 { std::shared_ptr pixelMap = std::make_shared(); ASSERT_EQ(WMError::WM_OK, StartingWindow::DrawStartingWindow(node_, pixelMap, 0x00FFFFFF, false)); + usleep(10000); } /** @@ -251,6 +240,7 @@ HWTEST_F(StartingWindowTest, DrawStartingWindow04, Function | SmallTest | Level2 node_->startingWinSurfaceNode_ = nullptr; std::shared_ptr pixelMap = std::make_shared(); ASSERT_EQ(WMError::WM_ERROR_NULLPTR, StartingWindow::DrawStartingWindow(node_, pixelMap, 0x00FFFFFF, true)); + usleep(10000); } /** @@ -261,6 +251,7 @@ HWTEST_F(StartingWindowTest, DrawStartingWindow04, Function | SmallTest | Level2 HWTEST_F(StartingWindowTest, DrawStartingWindow05, Function | SmallTest | Level2) { ASSERT_EQ(WMError::WM_OK, StartingWindow::DrawStartingWindow(node_, nullptr, 0x00FFFFFF, true)); + usleep(10000); } /** @@ -272,6 +263,7 @@ HWTEST_F(StartingWindowTest, DrawStartingWindow06, Function | SmallTest | Level2 { std::shared_ptr pixelMap = std::make_shared(); ASSERT_EQ(WMError::WM_OK, StartingWindow::DrawStartingWindow(node_, pixelMap, 0x00FFFFFF, true)); + usleep(10000); } /** @@ -434,60 +426,6 @@ HWTEST_F(StartingWindowTest, AddNodeOnRSTree06, Function | SmallTest | Level2) usleep(200000); } -/** - * @tc.name: SetStartingWindowEffect01 - * @tc.desc: set starting window corner radius with different parameter - * @tc.type: FUNC - */ -HWTEST_F(StartingWindowTest, SetStartingWindowEffect01, Function | SmallTest | Level2) -{ - sptr windowNode = nullptr; - ASSERT_EQ(WMError::WM_ERROR_NULLPTR, StartingWindow::SetStartingWindowEffect(windowNode)); - - // fullscreen - ASSERT_EQ(WMError::WM_OK, StartingWindow::SetStartingWindowEffect(node_)); - StartingWindow::windowSystemEffectConfig_.fullScreenCornerRadius_ = -0.001f; - ASSERT_EQ(WMError::WM_OK, StartingWindow::SetStartingWindowEffect(node_)); - node_->SetWindowMode(WindowMode::WINDOW_MODE_SPLIT_PRIMARY); - //splitmode - ASSERT_EQ(WMError::WM_OK, StartingWindow::SetStartingWindowEffect(node_)); - StartingWindow::windowSystemEffectConfig_.splitCornerRadius_ = -0.001f; - ASSERT_EQ(WMError::WM_OK, StartingWindow::SetStartingWindowEffect(node_)); - // - node_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING); - ASSERT_EQ(WMError::WM_OK, StartingWindow::SetStartingWindowEffect(node_)); - StartingWindow::windowSystemEffectConfig_.floatCornerRadius_ = -0.001f; - ASSERT_EQ(WMError::WM_OK, StartingWindow::SetStartingWindowEffect(node_)); - - node_->startingWinSurfaceNode_ = nullptr; - ASSERT_EQ(WMError::WM_ERROR_NULLPTR, StartingWindow::SetStartingWindowEffect(node_)); - StartingWindow::SetWindowRoot(nullptr); - ASSERT_EQ(WMError::WM_ERROR_NULLPTR, StartingWindow::SetStartingWindowEffect(node_)); -} - -/** - * @tc.name: SetWindowShadow - * @tc.desc: set starting window shadow with different parameter - * @tc.type: FUNC - */ -HWTEST_F(StartingWindowTest, SetWindowShadow01, Function | SmallTest | Level2) -{ - // fullscreen - ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, StartingWindow::SetWindowShadow(node_, true)); - node_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING); - ASSERT_EQ(WMError::WM_OK, StartingWindow::SetWindowShadow(node_, true)); - ASSERT_EQ(WMError::WM_OK, StartingWindow::SetWindowShadow(node_, false)); - - StartingWindow::windowSystemEffectConfig_.focusedShadow_.color_ = ""; - ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, StartingWindow::SetWindowShadow(node_, true)); - - StartingWindow::windowSystemEffectConfig_.focusedShadow_.elevation_ = 0.0001f; - ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, StartingWindow::SetWindowShadow(node_, true)); - - StartingWindow::SetWindowRoot(nullptr); - ASSERT_EQ(WMError::WM_ERROR_NULLPTR, StartingWindow::SetWindowShadow(node_, true)); -} - /** * @tc.name: SetStartingWindowAnimation * @tc.desc: set starting window animation with different parameter diff --git a/wmserver/test/unittest/window_system_effect_test.cpp b/wmserver/test/unittest/window_system_effect_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0ceecc3ac412b634278d0c37d28bd6a0f8b6a0ce --- /dev/null +++ b/wmserver/test/unittest/window_system_effect_test.cpp @@ -0,0 +1,171 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "iremote_object_mocker.h" +#include "window_helper.h" +#include "window_system_effect.h" +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace Rosen { +class WindowSystemEffectTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp() override; + void TearDown() override; + + sptr CreateWindowProperty(); +private: + RSSurfaceNode::SharedPtr CreateRSSurfaceNode(std::string name); + sptr node_ = nullptr; + AppWindowEffectConfig effectConfig_; + sptr windowRoot_; +}; + +void WindowSystemEffectTest::SetUpTestCase() +{ +} + +void WindowSystemEffectTest::TearDownTestCase() +{ +} + +void WindowSystemEffectTest::SetUp() +{ + node_ = new WindowNode(CreateWindowProperty()); // 101 is windowId + node_->SetWindowRect({0, 0, 100, 100}); // 100 test data + node_->leashWinSurfaceNode_ = CreateRSSurfaceNode("leashSurfaceNodeTest"); + node_->surfaceNode_ = CreateRSSurfaceNode("SurfaceNodeTest"); + effectConfig_.fullScreenCornerRadius_ = 16.0f; // 16.f test data + effectConfig_.splitCornerRadius_ = 16.0f; // 16.f test data + effectConfig_.floatCornerRadius_ = 16.0f; // 16.f test data + effectConfig_.focusedShadow_ = {80, "#000000", 0, 5, 0.45}; + effectConfig_.unfocusedShadow_ = {55, "#000000", 0, 10, 0.25}; + WindowSystemEffect::SetWindowSystemEffectConfig(effectConfig_); + windowRoot_ = new WindowRoot([](Event event, const sptr& remoteObject) {}); + ASSERT_NE(nullptr, windowRoot_); + WindowSystemEffect::SetWindowRoot(windowRoot_); +} + +void WindowSystemEffectTest::TearDown() +{ + node_ = nullptr; + AppWindowEffectConfig config; + effectConfig_ = config; +} + +RSSurfaceNode::SharedPtr WindowSystemEffectTest::CreateRSSurfaceNode(std::string name) +{ + struct RSSurfaceNodeConfig rsSurfaceNodeConfig; + rsSurfaceNodeConfig.SurfaceNodeName = name; + auto surfaceNode = RSSurfaceNode::Create(rsSurfaceNodeConfig); + return surfaceNode; +} + +sptr WindowSystemEffectTest::CreateWindowProperty() +{ + sptr property = new WindowProperty(); + return property; +} +namespace { +/** + * @tc.name: SetWindowEffectAndCornerRadius01 + * @tc.desc: set window corner radius with different parameter + * @tc.type: FUNC + */ +HWTEST_F(WindowSystemEffectTest, SetWindowEffectAndCornerRadius01, Function | SmallTest | Level2) +{ + sptr windowNode = nullptr; + ASSERT_EQ(WMError::WM_ERROR_NULLPTR, WindowSystemEffect::SetWindowEffect(windowNode)); + ASSERT_EQ(WMError::WM_OK, WindowSystemEffect::SetWindowEffect(node_)); + // fullscreen + node_->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN); + ASSERT_EQ(WMError::WM_OK, WindowSystemEffect::SetCornerRadius(node_)); + WindowSystemEffect::windowSystemEffectConfig_.fullScreenCornerRadius_ = 0.0f; + ASSERT_EQ(WMError::WM_OK, WindowSystemEffect::SetCornerRadius(node_)); + + // splitmode + node_->SetWindowMode(WindowMode::WINDOW_MODE_SPLIT_PRIMARY); + ASSERT_EQ(WMError::WM_OK, WindowSystemEffect::SetCornerRadius(node_)); + WindowSystemEffect::windowSystemEffectConfig_.splitCornerRadius_ = 0.0f; + ASSERT_EQ(WMError::WM_OK, WindowSystemEffect::SetCornerRadius(node_)); + + // float mode + node_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING); + ASSERT_EQ(WMError::WM_OK, WindowSystemEffect::SetCornerRadius(node_)); + WindowSystemEffect::windowSystemEffectConfig_.floatCornerRadius_ = 0.0f; + ASSERT_EQ(WMError::WM_DO_NOTHING, WindowSystemEffect::SetCornerRadius(node_)); + + node_->leashWinSurfaceNode_ = nullptr; + WindowSystemEffect::windowSystemEffectConfig_.floatCornerRadius_ = 16.0f; + ASSERT_EQ(WMError::WM_OK, WindowSystemEffect::SetCornerRadius(node_)); + + node_->leashWinSurfaceNode_ = CreateRSSurfaceNode("leashSurfaceNodeTest"); + node_->surfaceNode_ = nullptr; + ASSERT_EQ(WMError::WM_OK, WindowSystemEffect::SetCornerRadius(node_)); + + node_->leashWinSurfaceNode_ = nullptr; + ASSERT_EQ(WMError::WM_ERROR_NULLPTR, WindowSystemEffect::SetCornerRadius(node_)); + + WindowSystemEffect::SetWindowRoot(nullptr); + ASSERT_EQ(WMError::WM_ERROR_NULLPTR, WindowSystemEffect::SetCornerRadius(node_)); +} + +/** + * @tc.name: SetWindowShadow + * @tc.desc: set window shadow with different parameter + * @tc.type: FUNC + */ +HWTEST_F(WindowSystemEffectTest, SetWindowShadow01, Function | SmallTest | Level2) +{ + sptr windowNode = nullptr; + ASSERT_EQ(WMError::WM_ERROR_NULLPTR, WindowSystemEffect::SetWindowShadow(windowNode)); + + // fullscreen + node_->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN); + ASSERT_EQ(WMError::WM_DO_NOTHING, WindowSystemEffect::SetWindowShadow(node_)); + // float + node_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING); + ASSERT_EQ(WMError::WM_OK, WindowSystemEffect::SetWindowShadow(node_)); + node_->isFocused_ = true; + ASSERT_EQ(WMError::WM_OK, WindowSystemEffect::SetWindowShadow(node_)); + + WindowSystemEffect::windowSystemEffectConfig_.focusedShadow_.color_ = ""; + ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, WindowSystemEffect::SetWindowShadow(node_)); + + WindowSystemEffect::windowSystemEffectConfig_.focusedShadow_.elevation_ = 0.0001f; + ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, WindowSystemEffect::SetWindowShadow(node_)); + + WindowSystemEffect::windowSystemEffectConfig_ = effectConfig_; + node_->GetWindowProperty()->SetWindowType(WindowType::WINDOW_TYPE_FLOAT); + ASSERT_EQ(WMError::WM_DO_NOTHING, WindowSystemEffect::SetWindowShadow(node_)); + + sptr testNode = new WindowNode(CreateWindowProperty()); + sptr token = new IRemoteObjectMocker(); + testNode->abilityToken_ = token; + windowRoot_->windowNodeMap_.insert({testNode->GetWindowId(), testNode}); + node_->abilityToken_ = token; + ASSERT_EQ(WMError::WM_OK, WindowSystemEffect::SetWindowShadow(node_)); + + WindowSystemEffect::SetWindowRoot(nullptr); + ASSERT_EQ(WMError::WM_ERROR_NULLPTR, WindowSystemEffect::SetWindowShadow(node_)); +} +} +} +}