From 6b9096514489fddcfc6e47c7acdb5393b33b480f Mon Sep 17 00:00:00 2001 From: laiguizhong Date: Tue, 10 May 2022 19:11:33 +0800 Subject: [PATCH 01/81] =?UTF-8?q?=E4=BF=AE=E6=94=B9BUILD.gn?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: laiguizhong --- dmserver/BUILD.gn | 4 ++-- wmserver/BUILD.gn | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/dmserver/BUILD.gn b/dmserver/BUILD.gn index 23ffa01f..25c47bb6 100644 --- a/dmserver/BUILD.gn +++ b/dmserver/BUILD.gn @@ -79,9 +79,9 @@ ohos_shared_library("libdms") { ] if (is_standard_system) { - external_deps += [ "startup_l2:syspara" ] + external_deps += [ "init:libbegetutil" ] } else { - external_deps += [ "startup:syspara" ] + external_deps += [ "init_lite:libbegetutil" ] } part_name = "window_manager" diff --git a/wmserver/BUILD.gn b/wmserver/BUILD.gn index edd26123..c8d353b3 100644 --- a/wmserver/BUILD.gn +++ b/wmserver/BUILD.gn @@ -133,9 +133,9 @@ ohos_shared_library("libwms") { ] if (is_standard_system) { - external_deps += [ "startup_l2:syspara" ] + external_deps += [ "init:libbegetutil" ] } else { - external_deps += [ "startup:syspara" ] + external_deps += [ "init_lite:libbegetutil" ] } part_name = "window_manager" From 2f65f31387989db0b03d8834017c19dc3faca461 Mon Sep 17 00:00:00 2001 From: zhangxiao72 Date: Tue, 14 Jun 2022 11:25:37 +0800 Subject: [PATCH 02/81] =?UTF-8?q?=E9=83=A8=E4=BB=B6=E5=8C=96=E6=95=B4?= =?UTF-8?q?=E6=94=B9ace=5Fengine=5Fstandard=20=E4=BF=AE=E6=94=B9=E4=B8=BAa?= =?UTF-8?q?ce=5Fengine?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I1de5a46dde0908a18513e44c93f0576a8217b161 Signed-off-by: zhangxiao72 --- wm/BUILD.gn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wm/BUILD.gn b/wm/BUILD.gn index eb74ce04..9856e226 100644 --- a/wm/BUILD.gn +++ b/wm/BUILD.gn @@ -73,7 +73,7 @@ ohos_shared_library("libwm") { "ability_base:want", "ability_runtime:ability_context_native", "ability_runtime:ability_manager", - "ace_engine_standard:ace_uicontent", + "ace_engine:ace_uicontent", "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "graphic_standard:surface", From a290274be75dde4a2e10778d8c2ee20953e771fb Mon Sep 17 00:00:00 2001 From: shiqichang Date: Fri, 17 Jun 2022 17:11:53 +0800 Subject: [PATCH 03/81] =?UTF-8?q?aafwk=E7=9B=AE=E5=BD=95=E8=BD=AC=E7=A7=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: shiqichang Change-Id: I6fe6fd11ea21fe464c00154e8f1f755b96af365b --- extension/window_extension/BUILD.gn | 3 ++- interfaces/kits/napi/display_runtime/BUILD.gn | 6 +++--- interfaces/kits/napi/screen_recorder/BUILD.gn | 6 +++--- interfaces/kits/napi/screen_runtime/BUILD.gn | 6 +++--- interfaces/kits/napi/window_runtime/BUILD.gn | 6 +++--- wm/BUILD.gn | 2 +- wm/test/systemtest/BUILD.gn | 4 ++-- wm/test/unittest/BUILD.gn | 4 ++-- wm/test/unittest/mock_static_call.h | 2 +- 9 files changed, 20 insertions(+), 19 deletions(-) diff --git a/extension/window_extension/BUILD.gn b/extension/window_extension/BUILD.gn index 852c7c74..96f55f22 100644 --- a/extension/window_extension/BUILD.gn +++ b/extension/window_extension/BUILD.gn @@ -43,6 +43,7 @@ ohos_shared_library("libwindow_extension") { deps = [ "//foundation/ability/ability_runtime/frameworks/js/napi/aafwk/inner/napi_common:napi_common", + "//foundation/ability/ability_runtime/frameworks/native/appkit:app_context", "//foundation/graphic/graphic_2d/rosen/modules/render_service_client:librender_service_client", "//foundation/windowmanager/interfaces/kits/napi/window_runtime:window_native_kit", "//foundation/windowmanager/utils:libwmutil", @@ -70,7 +71,7 @@ config("window_extension_module_private_config") { include_dirs = [ "include", - "${aafwk_kits_path}/ability/ability_runtime/include", + "${aafwk_path}/interfaces/kits/native/ability/ability_runtime", ] } diff --git a/interfaces/kits/napi/display_runtime/BUILD.gn b/interfaces/kits/napi/display_runtime/BUILD.gn index d046ab9e..4d735321 100644 --- a/interfaces/kits/napi/display_runtime/BUILD.gn +++ b/interfaces/kits/napi/display_runtime/BUILD.gn @@ -35,9 +35,9 @@ ohos_shared_library("display_napi") { configs = [ ":display_config" ] deps = [ - "${aafwk_kits_path}/ability/native:abilitykit_native", - "${aafwk_kits_path}/appkit:app_context", - "${aafwk_kits_path}/appkit:appkit_native", + "${aafwk_path}/frameworks/native/ability/native:abilitykit_native", + "${aafwk_path}/frameworks/native/appkit:app_context", + "${aafwk_path}/frameworks/native/appkit:appkit_native", "../common:wm_napi_common", "//foundation/graphic/graphic_2d/rosen/modules/render_service_client:librender_service_client", "//foundation/windowmanager/dm:libdm", diff --git a/interfaces/kits/napi/screen_recorder/BUILD.gn b/interfaces/kits/napi/screen_recorder/BUILD.gn index 5d30cfb8..e9388119 100644 --- a/interfaces/kits/napi/screen_recorder/BUILD.gn +++ b/interfaces/kits/napi/screen_recorder/BUILD.gn @@ -38,9 +38,9 @@ ohos_shared_library("screenrecorder_napi") { configs = [ ":screen_runtime_config" ] deps = [ - "${aafwk_kits_path}/ability/native:abilitykit_native", - "${aafwk_kits_path}/appkit:app_context", - "${aafwk_kits_path}/appkit:appkit_native", + "${aafwk_path}/frameworks/native/ability/native:abilitykit_native", + "${aafwk_path}/frameworks/native/appkit:app_context", + "${aafwk_path}/frameworks/native/appkit:appkit_native", "//foundation/graphic/graphic_2d/rosen/modules/render_service_client:librender_service_client", "//foundation/windowmanager/dm:libdm", "//foundation/windowmanager/dmserver:libdms", diff --git a/interfaces/kits/napi/screen_runtime/BUILD.gn b/interfaces/kits/napi/screen_runtime/BUILD.gn index 03285272..e69ef8ec 100644 --- a/interfaces/kits/napi/screen_runtime/BUILD.gn +++ b/interfaces/kits/napi/screen_runtime/BUILD.gn @@ -37,9 +37,9 @@ ohos_shared_library("screen_napi") { configs = [ ":screen_runtime_config" ] deps = [ - "${aafwk_kits_path}/ability/native:abilitykit_native", - "${aafwk_kits_path}/appkit:app_context", - "${aafwk_kits_path}/appkit:appkit_native", + "${aafwk_path}/frameworks/native/ability/native:abilitykit_native", + "${aafwk_path}/frameworks/native/appkit:app_context", + "${aafwk_path}/frameworks/native/appkit:appkit_native", "//foundation/graphic/graphic_2d/rosen/modules/render_service_client:librender_service_client", "//foundation/windowmanager/dm:libdm", "//foundation/windowmanager/dmserver:libdms", diff --git a/interfaces/kits/napi/window_runtime/BUILD.gn b/interfaces/kits/napi/window_runtime/BUILD.gn index 40bed706..134a4170 100644 --- a/interfaces/kits/napi/window_runtime/BUILD.gn +++ b/interfaces/kits/napi/window_runtime/BUILD.gn @@ -77,9 +77,9 @@ ohos_shared_library("window_napi") { configs = [ ":window_manager_napi_config" ] deps = [ ":window_native_kit", - "${aafwk_kits_path}/ability/native:abilitykit_native", - "${aafwk_kits_path}/appkit:app_context", - "${aafwk_kits_path}/appkit:appkit_native", + "${aafwk_path}/frameworks/native/ability/native:abilitykit_native", + "${aafwk_path}/frameworks/native/appkit:app_context", + "${aafwk_path}/frameworks/native/appkit:appkit_native", "//foundation/windowmanager/utils:libwmutil", "//foundation/windowmanager/wm:libwm", "//foundation/windowmanager/wmserver:libwms", diff --git a/wm/BUILD.gn b/wm/BUILD.gn index eb74ce04..72e3452d 100644 --- a/wm/BUILD.gn +++ b/wm/BUILD.gn @@ -20,7 +20,7 @@ config("libwm_private_config") { include_dirs = [ "include", "../wmserver/include", - "${aafwk_kits_path}/ability/ability_runtime/include", + "${aafwk_path}/interfaces/kits/native/ability/ability_runtime", "${aafwk_inner_api_path}/ability_manager/include", "${aafwk_inner_api_path}/app_manager/include/appmgr", "//third_party/jsoncpp/include", diff --git a/wm/test/systemtest/BUILD.gn b/wm/test/systemtest/BUILD.gn index a016803d..9335e4fd 100644 --- a/wm/test/systemtest/BUILD.gn +++ b/wm/test/systemtest/BUILD.gn @@ -244,8 +244,8 @@ config("wm_systemtest_common_public_config") { "//third_party/googletest/googlemock/include", # for abilityContext - "${aafwk_kits_path}/ability/ability_runtime/include", - "${aafwk_kits_path}/appkit/native/ability_runtime/context", + "${aafwk_path}/interfaces/kits/native/ability/ability_runtime", + "${aafwk_path}/interfaces/kits/native/appkit/ability_runtime/context", "//base/global/resource_management/interfaces/inner_api/include", "//third_party/node/deps/icu-small/source/common", "${aafwk_inner_api_path}/ability_manager/include", diff --git a/wm/test/unittest/BUILD.gn b/wm/test/unittest/BUILD.gn index 3299ca27..a0b90166 100644 --- a/wm/test/unittest/BUILD.gn +++ b/wm/test/unittest/BUILD.gn @@ -144,8 +144,8 @@ config("wm_unittest_common_public_config") { "//third_party/googletest/googlemock/include", # for abilityContext - "${aafwk_kits_path}/ability/ability_runtime/include", - "${aafwk_kits_path}/appkit/native/ability_runtime/context", + "${aafwk_path}/interfaces/kits/native/ability/ability_runtime", + "${aafwk_path}/interfaces/kits/native/appkit/ability_runtime/context", "//base/global/resource_management/interfaces/inner_api/include", "//third_party/node/deps/icu-small/source/common", "${aafwk_inner_api_path}/ability_manager/include", diff --git a/wm/test/unittest/mock_static_call.h b/wm/test/unittest/mock_static_call.h index 76c14103..1769402d 100644 --- a/wm/test/unittest/mock_static_call.h +++ b/wm/test/unittest/mock_static_call.h @@ -18,7 +18,7 @@ #include #include "ability_context_impl.h" -#include "foundation/ability/ability_runtime/frameworks/kits/appkit/native/ability_runtime/context/context.h" +#include "foundation/ability/ability_runtime/interfaces/kits/native/appkit/ability_runtime/context/context.h" #include "static_call.h" namespace OHOS { From 4a8da435ed033fe3a04a607aed2ba2c27d0a101b Mon Sep 17 00:00:00 2001 From: qianlf Date: Tue, 21 Jun 2022 11:16:49 +0800 Subject: [PATCH 04/81] Add camera floating window type and test Signed-off-by: qianlf Change-Id: I272890078a0aad4abdb585202753df586c94097a --- interfaces/innerkits/wm/wm_common.h | 1 + .../window_manager_napi/js_window_manager.cpp | 4 +- .../window_napi/js_window_utils.cpp | 2 + .../window_napi/js_window_utils.h | 5 +- utils/include/window_helper.h | 5 + wm/include/window_impl.h | 1 + wm/src/window_impl.cpp | 29 +- wm/test/systemtest/BUILD.gn | 13 + .../window_app_floating_window_test.cpp | 312 ++++++++++++++++++ wmserver/include/window_zorder_policy.h | 1 + wmserver/src/window_layout_policy.cpp | 3 +- 11 files changed, 369 insertions(+), 7 deletions(-) create mode 100644 wm/test/systemtest/window_app_floating_window_test.cpp diff --git a/interfaces/innerkits/wm/wm_common.h b/interfaces/innerkits/wm/wm_common.h index 3c36a3ea..82912f9b 100644 --- a/interfaces/innerkits/wm/wm_common.h +++ b/interfaces/innerkits/wm/wm_common.h @@ -59,6 +59,7 @@ enum class WindowType : uint32_t { WINDOW_TYPE_BOOT_ANIMATION, WINDOW_TYPE_FREEZE_DISPLAY, WINDOW_TYPE_VOICE_INTERACTION, + WINDOW_TYPE_FLOAT_CAMERA, ABOVE_APP_SYSTEM_WINDOW_END, SYSTEM_WINDOW_END = ABOVE_APP_SYSTEM_WINDOW_END, }; diff --git a/interfaces/kits/napi/window_runtime/window_manager_napi/js_window_manager.cpp b/interfaces/kits/napi/window_runtime/window_manager_napi/js_window_manager.cpp index a65777c4..e0e4e4c6 100644 --- a/interfaces/kits/napi/window_runtime/window_manager_napi/js_window_manager.cpp +++ b/interfaces/kits/napi/window_runtime/window_manager_napi/js_window_manager.cpp @@ -166,7 +166,7 @@ static void CreateSystemWindowTask(void* contextPtr, std::string windowName, Win WLOGFE("[NAPI]Context is nullptr"); return; } - if (winType == WindowType::WINDOW_TYPE_FLOAT) { + if (winType == WindowType::WINDOW_TYPE_FLOAT || winType == WindowType::WINDOW_TYPE_FLOAT_CAMERA) { auto abilityContext = Context::ConvertTo(context->lock()); if (abilityContext != nullptr) { if (!CheckCallingPermission("ohos.permission.SYSTEM_FLOAT_WINDOW")) { @@ -538,7 +538,7 @@ NativeValue* JsWindowManager::OnSetWindowLayoutMode(NativeEngine& engine, Native if (winLayoutMode != WindowLayoutMode::CASCADE && winLayoutMode != WindowLayoutMode::TILE) { errCode = WMError::WM_ERROR_INVALID_PARAM; } - + WLOGFI("[NAPI]LayoutMode = %{public}u, err = %{public}d", winLayoutMode, errCode); AsyncTask::CompleteCallback complete = [=](NativeEngine& engine, AsyncTask& task, int32_t status) { diff --git a/interfaces/kits/napi/window_runtime/window_napi/js_window_utils.cpp b/interfaces/kits/napi/window_runtime/window_napi/js_window_utils.cpp index dd608251..0971dd62 100644 --- a/interfaces/kits/napi/window_runtime/window_napi/js_window_utils.cpp +++ b/interfaces/kits/napi/window_runtime/window_napi/js_window_utils.cpp @@ -62,6 +62,8 @@ NativeValue* WindowTypeInit(NativeEngine* engine) static_cast(ApiWindowType::TYPE_NAVIGATION_BAR))); object->SetProperty("TYPE_FLOAT", CreateJsValue(*engine, static_cast(ApiWindowType::TYPE_FLOAT))); + object->SetProperty("TYPE_FLOAT_CAMERA", CreateJsValue(*engine, + static_cast(ApiWindowType::TYPE_FLOAT_CAMERA))); object->SetProperty("TYPE_WALLPAPER", CreateJsValue(*engine, static_cast(ApiWindowType::TYPE_WALLPAPER))); object->SetProperty("TYPE_DESKTOP", CreateJsValue(*engine, diff --git a/interfaces/kits/napi/window_runtime/window_napi/js_window_utils.h b/interfaces/kits/napi/window_runtime/window_napi/js_window_utils.h index 3e631957..aef4219c 100644 --- a/interfaces/kits/napi/window_runtime/window_napi/js_window_utils.h +++ b/interfaces/kits/napi/window_runtime/window_napi/js_window_utils.h @@ -44,7 +44,8 @@ enum class ApiWindowType : uint32_t { TYPE_LAUNCHER_DOCK, TYPE_VOICE_INTERACTION, TYPE_POINTER, - TYPE_END = TYPE_POINTER, + TYPE_FLOAT_CAMERA, + TYPE_END = TYPE_FLOAT_CAMERA, }; enum class LifeCycleEventType : uint32_t { @@ -64,6 +65,7 @@ const std::map NATIVE_JS_TO_WINDOW_TYPE_MAP { { WindowType::WINDOW_TYPE_VOLUME_OVERLAY, ApiWindowType::TYPE_VOLUME_OVERLAY }, { WindowType::WINDOW_TYPE_NAVIGATION_BAR, ApiWindowType::TYPE_NAVIGATION_BAR }, { WindowType::WINDOW_TYPE_FLOAT, ApiWindowType::TYPE_FLOAT }, + { WindowType::WINDOW_TYPE_FLOAT_CAMERA, ApiWindowType::TYPE_FLOAT_CAMERA }, { WindowType::WINDOW_TYPE_WALLPAPER, ApiWindowType::TYPE_WALLPAPER }, { WindowType::WINDOW_TYPE_DESKTOP, ApiWindowType::TYPE_DESKTOP }, { WindowType::WINDOW_TYPE_LAUNCHER_RECENT, ApiWindowType::TYPE_LAUNCHER_RECENT }, @@ -82,6 +84,7 @@ const std::map JS_TO_NATIVE_WINDOW_TYPE_MAP { { ApiWindowType::TYPE_VOLUME_OVERLAY, WindowType::WINDOW_TYPE_VOLUME_OVERLAY }, { ApiWindowType::TYPE_NAVIGATION_BAR, WindowType::WINDOW_TYPE_NAVIGATION_BAR }, { ApiWindowType::TYPE_FLOAT, WindowType::WINDOW_TYPE_FLOAT }, + { ApiWindowType::TYPE_FLOAT_CAMERA, WindowType::WINDOW_TYPE_FLOAT_CAMERA }, { ApiWindowType::TYPE_WALLPAPER, WindowType::WINDOW_TYPE_WALLPAPER }, { ApiWindowType::TYPE_DESKTOP, WindowType::WINDOW_TYPE_DESKTOP }, { ApiWindowType::TYPE_LAUNCHER_RECENT, WindowType::WINDOW_TYPE_LAUNCHER_RECENT }, diff --git a/utils/include/window_helper.h b/utils/include/window_helper.h index 531a44ea..1d67ab03 100644 --- a/utils/include/window_helper.h +++ b/utils/include/window_helper.h @@ -39,6 +39,11 @@ public: return (IsMainWindow(type) || IsSubWindow(type)); } + static inline bool IsAppFloatingWindow(WindowType type) + { + return (type == WindowType::WINDOW_TYPE_FLOAT) || (type == WindowType::WINDOW_TYPE_FLOAT_CAMERA); + } + static inline bool IsBelowSystemWindow(WindowType type) { return (type >= WindowType::BELOW_APP_SYSTEM_WINDOW_BASE && type < WindowType::BELOW_APP_SYSTEM_WINDOW_END); diff --git a/wm/include/window_impl.h b/wm/include/window_impl.h index 5c6d70af..217738b0 100644 --- a/wm/include/window_impl.h +++ b/wm/include/window_impl.h @@ -313,6 +313,7 @@ private: void UpdatePointerEventForStretchableWindow(std::shared_ptr& pointerEvent); void UpdateDragType(); void InitListenerHandler(); + bool CheckCameraFloatingWindowMultiCreated(WindowType type); // colorspace, gamut using ColorSpaceConvertMap = struct { diff --git a/wm/src/window_impl.cpp b/wm/src/window_impl.cpp index bf745af0..dcaa1a01 100644 --- a/wm/src/window_impl.cpp +++ b/wm/src/window_impl.cpp @@ -625,7 +625,7 @@ WMError WindowImpl::SetFullScreen(bool status) void WindowImpl::MapFloatingWindowToAppIfNeeded() { - if (GetType() != WindowType::WINDOW_TYPE_FLOAT || context_.get() == nullptr) { + if (!WindowHelper::IsAppFloatingWindow(GetType()) || context_.get() == nullptr) { return; } @@ -634,7 +634,8 @@ void WindowImpl::MapFloatingWindowToAppIfNeeded() if (win->GetType() == WindowType::WINDOW_TYPE_APP_MAIN_WINDOW && context_.get() == win->GetContext().get()) { appFloatingWindowMap_[win->GetWindowId()].push_back(this); - WLOGFI("Map FloatingWindow %{public}u to AppMainWindow %{public}u", GetWindowId(), win->GetWindowId()); + WLOGFI("Map FloatingWindow %{public}u to AppMainWindow %{public}u, type is %{public}u", + GetWindowId(), win->GetWindowId(), GetType()); return; } } @@ -663,6 +664,12 @@ WMError WindowImpl::Create(const std::string& parentName, const std::shared_ptr< property_->SetParentId(parentId); } } + + if (CheckCameraFloatingWindowMultiCreated(property_->GetWindowType())) { + WLOGFE("Camera Floating Window already exists."); + return WMError::WM_ERROR_INVALID_WINDOW; + } + context_ = context; sptr window(this); sptr windowAgent(new WindowAgent(window)); @@ -723,7 +730,8 @@ void WindowImpl::DestroyFloatingWindow() // Destroy app floating window if exist if (appFloatingWindowMap_.count(GetWindowId()) > 0) { - for (auto& floatingWindow : appFloatingWindowMap_.at(GetWindowId())) { + auto floatingWindows = appFloatingWindowMap_.at(GetWindowId()); + for (auto& floatingWindow : floatingWindows) { if (floatingWindow == nullptr) { continue; } @@ -2243,6 +2251,7 @@ void WindowImpl::SetDefaultOption() } case WindowType::WINDOW_TYPE_TOAST: case WindowType::WINDOW_TYPE_FLOAT: + case WindowType::WINDOW_TYPE_FLOAT_CAMERA: case WindowType::WINDOW_TYPE_VOICE_INTERACTION: case WindowType::WINDOW_TYPE_LAUNCHER_DOCK: case WindowType::WINDOW_TYPE_SEARCHING_BAR: { @@ -2320,5 +2329,19 @@ void WindowImpl::GetRequestedTouchHotAreas(std::vector& rects) const { property_->GetTouchHotAreas(rects); } + +bool WindowImpl::CheckCameraFloatingWindowMultiCreated(WindowType type) +{ + if (type != WindowType::WINDOW_TYPE_FLOAT_CAMERA) { + return false; + } + + for (auto& winPair : windowMap_) { + if (winPair.second.second->GetType() == WindowType::WINDOW_TYPE_FLOAT_CAMERA) { + return true; + } + } + return false; +} } // namespace Rosen } // namespace OHOS diff --git a/wm/test/systemtest/BUILD.gn b/wm/test/systemtest/BUILD.gn index 3dc930a2..8c89f3a4 100644 --- a/wm/test/systemtest/BUILD.gn +++ b/wm/test/systemtest/BUILD.gn @@ -20,6 +20,7 @@ group("systemtest") { testonly = true deps = [ + ":wm_window_app_floating_window_test", ":wm_window_drag_test", ":wm_window_effect_test", ":wm_window_focus_test", @@ -243,6 +244,17 @@ ohos_systemtest("wm_window_mode_support_info_test") { ## SystemTest wm_window_mode_support_info_test }}} +## SystemTest wm_window_app_floating_window_test {{{ +ohos_systemtest("wm_window_app_floating_window_test") { + module_out_path = module_out_path + + sources = [ "window_app_floating_window_test.cpp" ] + + deps = [ ":wm_systemtest_common" ] +} + +## SystemTest wm_window_app_floating_window_test }}} + ## Build wm_systemtest_common.a {{{ config("wm_systemtest_common_public_config") { include_dirs = [ @@ -307,6 +319,7 @@ ohos_static_library("wm_systemtest_common") { "ability_base:base", "ability_base:want", "ability_base:zuri", + "ability_runtime:ability_context_native", "bundle_framework:appexecfwk_base", ] } diff --git a/wm/test/systemtest/window_app_floating_window_test.cpp b/wm/test/systemtest/window_app_floating_window_test.cpp new file mode 100644 index 00000000..df14fa72 --- /dev/null +++ b/wm/test/systemtest/window_app_floating_window_test.cpp @@ -0,0 +1,312 @@ +/* + * Copyright (c) 2022 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. + */ + +// gtest +#include +#include "ability_context_impl.h" +#include "window.h" +#include "window_option.h" +#include "window_scene.h" +#include "window_test_utils.h" +#include "wm_common.h" + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace Rosen { +class WindowAppFloatingWindowTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + virtual void SetUp() override; + virtual void TearDown() override; + + static inline float virtualPixelRatio_ = 1.0; + static inline std::shared_ptr abilityContext_ = nullptr; +}; + +void WindowAppFloatingWindowTest::SetUpTestCase() +{ + auto display = DisplayManager::GetInstance().GetDisplayById(0); + ASSERT_TRUE((display != nullptr)); + Rect displayRect = {0, 0, display->GetWidth(), display->GetHeight()}; + WindowTestUtils::InitByDisplayRect(displayRect); + virtualPixelRatio_ = WindowTestUtils::GetVirtualPixelRatio(0); +} + +void WindowAppFloatingWindowTest::TearDownTestCase() +{ +} + +void WindowAppFloatingWindowTest::SetUp() +{ +} + +void WindowAppFloatingWindowTest::TearDown() +{ +} + +static sptr CreateWindowScene() +{ + sptr listener = nullptr; + WindowAppFloatingWindowTest::abilityContext_ = std::make_shared(); + + sptr scene = new WindowScene(); + scene->Init(0, WindowAppFloatingWindowTest::abilityContext_, listener); + return scene; +} + +static sptr CreateAppFloatingWindow(WindowType type, Rect rect, std::string name = "") +{ + sptr option = new WindowOption(); + option->SetWindowType(type); + option->SetWindowRect(rect); + + static int cnt = 0; + std::string winName = (name == "") ? "FloatingWindowTest" + std::to_string(cnt++) : name; + + return Window::Create(winName, option, WindowAppFloatingWindowTest::abilityContext_); +} + +static inline Rect GetRectWithVpr(int32_t x, int32_t y, uint32_t w, uint32_t h) +{ + auto vpr = WindowAppFloatingWindowTest::virtualPixelRatio_; + return {x, y, static_cast(w * vpr), static_cast(h * vpr)}; +} + +/** + * @tc.name: AppFloatingWindow01 + * @tc.desc: AppFloatingWindow life cycle + * @tc.type: FUNC + */ +HWTEST_F(WindowAppFloatingWindowTest, AppFloatingWindow01, Function | MediumTest | Level2) +{ + sptr scene = CreateWindowScene(); + ASSERT_NE(nullptr, scene); + + Rect fltWindRect = GetRectWithVpr(0, 0, 400, 600); + sptr fltWin = CreateAppFloatingWindow(WindowType::WINDOW_TYPE_FLOAT, fltWindRect); + ASSERT_NE(nullptr, fltWin); + + ASSERT_EQ(WMError::WM_OK, scene->GoForeground()); + ASSERT_EQ(WMError::WM_OK, fltWin->Show()); + + ASSERT_EQ(WMError::WM_OK, fltWin->Hide()); + ASSERT_EQ(WMError::WM_OK, scene->GoBackground()); + + ASSERT_EQ(WMError::WM_OK, fltWin->Destroy()); + ASSERT_EQ(WMError::WM_OK, scene->GoDestroy()); +} + +/** + * @tc.name: AppFloatingWindow02 + * @tc.desc: AppFloatingWindow life cycle, main window hide first + * @tc.type: FUNC + */ +HWTEST_F(WindowAppFloatingWindowTest, AppFloatingWindow02, Function | MediumTest | Level3) +{ + sptr scene = CreateWindowScene(); + ASSERT_NE(nullptr, scene); + + Rect fltWindRect = GetRectWithVpr(0, 0, 400, 600); + sptr fltWin = CreateAppFloatingWindow(WindowType::WINDOW_TYPE_FLOAT, fltWindRect); + ASSERT_NE(nullptr, fltWin); + + ASSERT_EQ(WMError::WM_OK, scene->GoForeground()); + ASSERT_EQ(WMError::WM_OK, fltWin->Show()); + + ASSERT_EQ(WMError::WM_OK, scene->GoBackground()); + ASSERT_EQ(false, scene->GetMainWindow()->GetShowState()); + ASSERT_EQ(true, fltWin->GetShowState()); + ASSERT_EQ(WMError::WM_OK, fltWin->Hide()); + + ASSERT_EQ(WMError::WM_OK, fltWin->Destroy()); + ASSERT_EQ(WMError::WM_OK, scene->GoDestroy()); +} + +/** + * @tc.name: AppFloatingWindow03 + * @tc.desc: AppFloatingWindow life cycle, app floating window hide first + * @tc.type: FUNC + */ +HWTEST_F(WindowAppFloatingWindowTest, AppFloatingWindow03, Function | MediumTest | Level3) +{ + sptr scene = CreateWindowScene(); + ASSERT_NE(nullptr, scene); + + Rect fltWindRect = GetRectWithVpr(0, 0, 400, 600); + sptr fltWin = CreateAppFloatingWindow(WindowType::WINDOW_TYPE_FLOAT, fltWindRect); + ASSERT_NE(nullptr, fltWin); + + ASSERT_EQ(WMError::WM_OK, scene->GoForeground()); + ASSERT_EQ(WMError::WM_OK, fltWin->Show()); + + ASSERT_EQ(WMError::WM_OK, fltWin->Hide()); + ASSERT_EQ(false, fltWin->GetShowState()); + ASSERT_EQ(true, scene->GetMainWindow()->GetShowState()); + ASSERT_EQ(WMError::WM_OK, scene->GoBackground()); + + ASSERT_EQ(WMError::WM_OK, fltWin->Destroy()); + ASSERT_EQ(WMError::WM_OK, scene->GoDestroy()); +} + +/** + * @tc.name: AppFloatingWindow04 + * @tc.desc: AppFloatingWindow life cycle, main window destroy first + * @tc.type: FUNC + */ +HWTEST_F(WindowAppFloatingWindowTest, AppFloatingWindow04, Function | MediumTest | Level3) +{ + sptr scene = CreateWindowScene(); + ASSERT_NE(nullptr, scene); + + Rect fltWindRect = GetRectWithVpr(0, 0, 400, 600); + sptr fltWin = CreateAppFloatingWindow(WindowType::WINDOW_TYPE_FLOAT, fltWindRect); + ASSERT_NE(nullptr, fltWin); + + ASSERT_EQ(WMError::WM_OK, scene->GoForeground()); + ASSERT_EQ(WMError::WM_OK, fltWin->Show()); + + ASSERT_EQ(WMError::WM_OK, scene->GoDestroy()); + ASSERT_EQ(nullptr, scene->GetMainWindow()); + ASSERT_EQ(false, fltWin->GetShowState()); + ASSERT_EQ(WMError::WM_OK, fltWin->Destroy()); +} + +/** + * @tc.name: AppFloatingWindow05 + * @tc.desc: Camera AppFloatingWindow life cycle + * @tc.type: FUNC + */ +HWTEST_F(WindowAppFloatingWindowTest, AppFloatingWindow05, Function | MediumTest | Level2) +{ + sptr scene = CreateWindowScene(); + ASSERT_NE(nullptr, scene); + + Rect fltWindRect = GetRectWithVpr(0, 0, 400, 600); + sptr fltWin = CreateAppFloatingWindow(WindowType::WINDOW_TYPE_FLOAT_CAMERA, fltWindRect); + ASSERT_NE(nullptr, fltWin); + + ASSERT_EQ(WMError::WM_OK, scene->GoForeground()); + ASSERT_EQ(WMError::WM_OK, fltWin->Show()); + + ASSERT_EQ(WMError::WM_OK, fltWin->Hide()); + ASSERT_EQ(WMError::WM_OK, scene->GoBackground()); + + ASSERT_EQ(WMError::WM_OK, fltWin->Destroy()); + ASSERT_EQ(WMError::WM_OK, scene->GoDestroy()); +} + +/** + * @tc.name: AppFloatingWindow06 + * @tc.desc: Camera AppFloatingWindow life cycle, main window hide first + * @tc.type: FUNC + */ +HWTEST_F(WindowAppFloatingWindowTest, AppFloatingWindow06, Function | MediumTest | Level3) +{ + sptr scene = CreateWindowScene(); + ASSERT_NE(nullptr, scene); + + Rect fltWindRect = GetRectWithVpr(0, 0, 400, 600); + sptr fltWin = CreateAppFloatingWindow(WindowType::WINDOW_TYPE_FLOAT_CAMERA, fltWindRect); + ASSERT_NE(nullptr, fltWin); + + ASSERT_EQ(WMError::WM_OK, scene->GoForeground()); + ASSERT_EQ(WMError::WM_OK, fltWin->Show()); + + ASSERT_EQ(WMError::WM_OK, scene->GoBackground()); + ASSERT_EQ(false, scene->GetMainWindow()->GetShowState()); + ASSERT_EQ(true, fltWin->GetShowState()); + ASSERT_EQ(WMError::WM_OK, fltWin->Hide()); + + ASSERT_EQ(WMError::WM_OK, fltWin->Destroy()); + ASSERT_EQ(WMError::WM_OK, scene->GoDestroy()); +} + +/** + * @tc.name: AppFloatingWindow07 + * @tc.desc: Camera AppFloatingWindow life cycle, app floating window hide first + * @tc.type: FUNC + */ +HWTEST_F(WindowAppFloatingWindowTest, AppFloatingWindow07, Function | MediumTest | Level3) +{ + sptr scene = CreateWindowScene(); + ASSERT_NE(nullptr, scene); + + Rect fltWindRect = GetRectWithVpr(0, 0, 400, 600); + sptr fltWin = CreateAppFloatingWindow(WindowType::WINDOW_TYPE_FLOAT_CAMERA, fltWindRect); + ASSERT_NE(nullptr, fltWin); + + ASSERT_EQ(WMError::WM_OK, scene->GoForeground()); + ASSERT_EQ(WMError::WM_OK, fltWin->Show()); + + ASSERT_EQ(WMError::WM_OK, fltWin->Hide()); + ASSERT_EQ(false, fltWin->GetShowState()); + ASSERT_EQ(true, scene->GetMainWindow()->GetShowState()); + ASSERT_EQ(WMError::WM_OK, scene->GoBackground()); + + ASSERT_EQ(WMError::WM_OK, fltWin->Destroy()); + ASSERT_EQ(WMError::WM_OK, scene->GoDestroy()); +} + +/** + * @tc.name: AppFloatingWindow08 + * @tc.desc: Camera AppFloatingWindow life cycle, main window destroy first + * @tc.type: FUNC + */ +HWTEST_F(WindowAppFloatingWindowTest, AppFloatingWindow08, Function | MediumTest | Level3) +{ + sptr scene = CreateWindowScene(); + ASSERT_NE(nullptr, scene); + + Rect fltWindRect = GetRectWithVpr(0, 0, 400, 600); + sptr fltWin = CreateAppFloatingWindow(WindowType::WINDOW_TYPE_FLOAT_CAMERA, fltWindRect); + ASSERT_NE(nullptr, fltWin); + + ASSERT_EQ(WMError::WM_OK, scene->GoForeground()); + ASSERT_EQ(WMError::WM_OK, fltWin->Show()); + + ASSERT_EQ(WMError::WM_OK, scene->GoDestroy()); + ASSERT_EQ(nullptr, scene->GetMainWindow()); + ASSERT_EQ(false, fltWin->GetShowState()); + ASSERT_EQ(WMError::WM_OK, fltWin->Destroy()); +} + +/** + * @tc.name: AppFloatingWindow09 + * @tc.desc: Camera AppFloatingWindow rect check + * @tc.type: FUNC + */ +HWTEST_F(WindowAppFloatingWindowTest, AppFloatingWindow09, Function | MediumTest | Level3) +{ + sptr scene = CreateWindowScene(); + ASSERT_NE(nullptr, scene); + + Rect fltWindRect = GetRectWithVpr(10, 20, 10, 10); + sptr fltWin = CreateAppFloatingWindow(WindowType::WINDOW_TYPE_FLOAT_CAMERA, fltWindRect); + ASSERT_NE(nullptr, fltWin); + + ASSERT_EQ(WMError::WM_OK, scene->GoForeground()); + ASSERT_EQ(WMError::WM_OK, fltWin->Show()); + + Rect exceptRect = WindowTestUtils::GetFloatingLimitedRect(fltWindRect, virtualPixelRatio_); + ASSERT_TRUE(WindowTestUtils::RectEqualTo(fltWin, exceptRect)); + + ASSERT_EQ(WMError::WM_OK, fltWin->Destroy()); + ASSERT_EQ(WMError::WM_OK, scene->GoDestroy()); +} +} // namespace Rosen +} // namespace OHOS diff --git a/wmserver/include/window_zorder_policy.h b/wmserver/include/window_zorder_policy.h index af41d1e8..8df41594 100644 --- a/wmserver/include/window_zorder_policy.h +++ b/wmserver/include/window_zorder_policy.h @@ -52,6 +52,7 @@ private: { WindowType::WINDOW_TYPE_SYSTEM_ALARM_WINDOW, 106 }, { WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT, 107 }, { WindowType::WINDOW_TYPE_FLOAT, 108 }, + { WindowType::WINDOW_TYPE_FLOAT_CAMERA, 108 }, { WindowType::WINDOW_TYPE_TOAST, 109 }, { WindowType::WINDOW_TYPE_STATUS_BAR, 110 }, { WindowType::WINDOW_TYPE_PANEL, 111 }, diff --git a/wmserver/src/window_layout_policy.cpp b/wmserver/src/window_layout_policy.cpp index 0a8b5afc..68929bd1 100644 --- a/wmserver/src/window_layout_policy.cpp +++ b/wmserver/src/window_layout_policy.cpp @@ -678,7 +678,8 @@ void WindowLayoutPolicy::UpdateFloatingWindowSizeBySystemLimits(const sptrGetDisplayId())); // limit minimum size of floating (not system type) window - if (!WindowHelper::IsSystemWindow(node->GetWindowType())) { + if (!WindowHelper::IsSystemWindow(node->GetWindowType()) || + node->GetWindowType() == WindowType::WINDOW_TYPE_FLOAT_CAMERA) { winRect.width_ = std::max(systemLimits.minWidth_, winRect.width_); winRect.height_ = std::max(systemLimits.minHeight_, winRect.height_); } From ea3b7d2a5d5dbafb7dbaa64fb5253d3ebe074c7e Mon Sep 17 00:00:00 2001 From: xpeng Date: Tue, 21 Jun 2022 19:42:54 +0800 Subject: [PATCH 05/81] Add interfaces to control screen auto rotation lock Signed-off-by: xpeng Change-Id: Ia7dbf130ae113464ce439032ab9d9189c01973f4 --- dm/include/display_manager_adapter.h | 2 + dm/src/display_manager_adapter.cpp | 14 ++++ dm/src/screen_manager.cpp | 10 +++ dm/test/systemtest/screen_manager_test.cpp | 14 ++++ dmserver/include/display_manager_interface.h | 4 + dmserver/include/display_manager_proxy.h | 2 + dmserver/include/display_manager_service.h | 2 + dmserver/src/display_manager_proxy.cpp | 51 ++++++++++++ dmserver/src/display_manager_service.cpp | 11 +++ dmserver/src/display_manager_stub.cpp | 11 +++ interfaces/innerkits/dm/screen_manager.h | 3 +- .../napi/screen_runtime/api/@ohos.screen.d.ts | 15 ++++ .../screen_runtime/napi/js_screen_manager.cpp | 79 +++++++++++++++++++ 13 files changed, 217 insertions(+), 1 deletion(-) diff --git a/dm/include/display_manager_adapter.h b/dm/include/display_manager_adapter.h index f206bcb9..e4403668 100644 --- a/dm/include/display_manager_adapter.h +++ b/dm/include/display_manager_adapter.h @@ -89,6 +89,8 @@ public: virtual bool SetScreenActiveMode(ScreenId screenId, uint32_t modeId); virtual sptr GetScreenInfo(ScreenId screenId); virtual bool SetVirtualPixelRatio(ScreenId screenId, float virtualPixelRatio); + virtual DMError SetScreenRotationLocked(bool isLocked); + virtual bool IsScreenRotationLocked(); // colorspace, gamut virtual DMError GetScreenSupportedColorGamuts(ScreenId screenId, std::vector& colorGamuts); diff --git a/dm/src/display_manager_adapter.cpp b/dm/src/display_manager_adapter.cpp index 2402ec2b..82cdda11 100644 --- a/dm/src/display_manager_adapter.cpp +++ b/dm/src/display_manager_adapter.cpp @@ -125,6 +125,20 @@ DMError ScreenManagerAdapter::SetVirtualScreenSurface(ScreenId screenId, sptrSetVirtualScreenSurface(screenId, surface); } +DMError ScreenManagerAdapter::SetScreenRotationLocked(bool isLocked) +{ + INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED); + WLOGFI("DisplayManagerAdapter::SetScreenRotationLocked"); + return displayManagerServiceProxy_->SetScreenRotationLocked(isLocked); +} + +bool ScreenManagerAdapter::IsScreenRotationLocked() +{ + INIT_PROXY_CHECK_RETURN(false); + WLOGFI("DisplayManagerAdapter::IsScreenRotationLocked"); + return displayManagerServiceProxy_->IsScreenRotationLocked(); +} + bool ScreenManagerAdapter::SetScreenPowerForAll(ScreenPowerState state, PowerStateChangeReason reason) { INIT_PROXY_CHECK_RETURN(false); diff --git a/dm/src/screen_manager.cpp b/dm/src/screen_manager.cpp index 5580390a..9f3d784f 100644 --- a/dm/src/screen_manager.cpp +++ b/dm/src/screen_manager.cpp @@ -435,6 +435,16 @@ ScreenPowerState ScreenManager::GetScreenPower(ScreenId dmsScreenId) return SingletonContainer::Get().GetScreenPower(dmsScreenId); } +DMError ScreenManager::SetScreenRotationLocked(bool isLocked) +{ + return SingletonContainer::Get().SetScreenRotationLocked(isLocked); +} + +bool ScreenManager::IsScreenRotationLocked() +{ + return SingletonContainer::Get().IsScreenRotationLocked(); +} + void ScreenManager::Impl::NotifyScreenConnect(sptr info) { std::lock_guard lock(mutex_); diff --git a/dm/test/systemtest/screen_manager_test.cpp b/dm/test/systemtest/screen_manager_test.cpp index d338001c..489a3ee8 100644 --- a/dm/test/systemtest/screen_manager_test.cpp +++ b/dm/test/systemtest/screen_manager_test.cpp @@ -743,6 +743,20 @@ HWTEST_F(ScreenManagerTest, ScreenManager17, Function | MediumTest | Level2) ASSERT_NE(SCREEN_ID_INVALID, virtualScreenId); } } + +/** + * @tc.name: ScreenManager18 + * @tc.desc: Set screen rotation lock, and check whether screen rotation lock is Locked. + * @tc.type: FUNC + */ +HWTEST_F(ScreenManagerTest, ScreenManager18, Function | SmallTest | Level1) +{ + bool originalLockStatus = ScreenManager::GetInstance().IsScreenRotationLocked(); + ScreenManager::GetInstance().SetScreenRotationLocked(!originalLockStatus); + bool modifiedLockedStatus = ScreenManager::GetInstance().IsScreenRotationLocked(); + ScreenManager::GetInstance().SetScreenRotationLocked(originalLockStatus); + ASSERT_EQ(!originalLockStatus, modifiedLockedStatus); +} } } // namespace Rosen } // namespace OHOS diff --git a/dmserver/include/display_manager_interface.h b/dmserver/include/display_manager_interface.h index 862720f7..b6561687 100644 --- a/dmserver/include/display_manager_interface.h +++ b/dmserver/include/display_manager_interface.h @@ -71,6 +71,8 @@ public: TRANS_ID_SCREEN_GET_GAMUT_MAP, TRANS_ID_SCREEN_SET_GAMUT_MAP, TRANS_ID_SCREEN_SET_COLOR_TRANSFORM, + TRANS_ID_IS_SCREEN_ROTATION_LOCKED, + TRANS_ID_SET_SCREEN_ROTATION_LOCKED, }; virtual sptr GetDefaultDisplayInfo() = 0; @@ -83,6 +85,8 @@ public: virtual DMError SetVirtualScreenSurface(ScreenId screenId, sptr surface) = 0; virtual bool SetOrientation(ScreenId screenId, Orientation orientation) = 0; virtual std::shared_ptr GetDisplaySnapshot(DisplayId displayId) = 0; + virtual DMError SetScreenRotationLocked(bool isLocked) = 0; + virtual bool IsScreenRotationLocked() = 0; // colorspace, gamut virtual DMError GetScreenSupportedColorGamuts(ScreenId screenId, std::vector& colorGamuts) = 0; diff --git a/dmserver/include/display_manager_proxy.h b/dmserver/include/display_manager_proxy.h index c0bc28e6..14134a56 100644 --- a/dmserver/include/display_manager_proxy.h +++ b/dmserver/include/display_manager_proxy.h @@ -41,6 +41,8 @@ public: DMError SetVirtualScreenSurface(ScreenId screenId, sptr surface) override; bool SetOrientation(ScreenId screenId, Orientation orientation) override; std::shared_ptr GetDisplaySnapshot(DisplayId displayId) override; + bool IsScreenRotationLocked() override; + DMError SetScreenRotationLocked(bool isLocked) override; // colorspace, gamut DMError GetScreenSupportedColorGamuts(ScreenId screenId, std::vector& colorGamuts) override; diff --git a/dmserver/include/display_manager_service.h b/dmserver/include/display_manager_service.h index ae9ead92..6b0c5e6f 100644 --- a/dmserver/include/display_manager_service.h +++ b/dmserver/include/display_manager_service.h @@ -50,6 +50,8 @@ public: const sptr& displayManagerAgent) override; DMError DestroyVirtualScreen(ScreenId screenId) override; DMError SetVirtualScreenSurface(ScreenId screenId, sptr surface) override; + bool IsScreenRotationLocked() override; + DMError SetScreenRotationLocked(bool isLocked) override; sptr GetDefaultDisplayInfo() override; sptr GetDisplayInfoById(DisplayId displayId) override; diff --git a/dmserver/src/display_manager_proxy.cpp b/dmserver/src/display_manager_proxy.cpp index 63cdfd95..f5608a13 100644 --- a/dmserver/src/display_manager_proxy.cpp +++ b/dmserver/src/display_manager_proxy.cpp @@ -1005,4 +1005,55 @@ bool DisplayManagerProxy::SetVirtualPixelRatio(ScreenId screenId, float virtualP } return reply.ReadBool(); } + +bool DisplayManagerProxy::IsScreenRotationLocked() +{ + bool isLocked; + sptr remote = Remote(); + if (remote == nullptr) { + WLOGFW("IsScreenRotationLocked: remote is nullptr"); + return false; + } + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("IsScreenRotationLocked: WriteInterfaceToken failed"); + return false; + } + if (remote->SendRequest(static_cast(DisplayManagerMessage::TRANS_ID_IS_SCREEN_ROTATION_LOCKED), + data, reply, option) != ERR_NONE) { + WLOGFW("IsScreenRotationLocked: SendRequest failed"); + return false; + } + isLocked = reply.ReadBool(); + return isLocked; +} + +DMError DisplayManagerProxy::SetScreenRotationLocked(bool isLocked) +{ + sptr remote = Remote(); + if (remote == nullptr) { + WLOGFW("SetScreenRotationLocked: remote is null"); + return DMError::DM_ERROR_REMOTE_CREATE_FAILED; + } + + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("SetScreenRotationLocked: WriteInterfaceToken failed"); + return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED; + } + if (!data.WriteBool(isLocked)) { + WLOGFE("SetScreenRotationLocked: write isLocked failed"); + return DMError::DM_ERROR_IPC_FAILED; + } + if (remote->SendRequest(static_cast(DisplayManagerMessage::TRANS_ID_SET_SCREEN_ROTATION_LOCKED), + data, reply, option) != ERR_NONE) { + WLOGFE("SetScreenRotationLocked: SendRequest failed"); + return DMError::DM_ERROR_IPC_FAILED; + } + return static_cast(reply.ReadInt32()); +} } // namespace OHOS::Rosen \ No newline at end of file diff --git a/dmserver/src/display_manager_service.cpp b/dmserver/src/display_manager_service.cpp index 4d5f67ed..269340f2 100644 --- a/dmserver/src/display_manager_service.cpp +++ b/dmserver/src/display_manager_service.cpp @@ -559,4 +559,15 @@ float DisplayManagerService::GetCustomVirtualPixelRatio() { return DisplayManagerService::customVirtualPixelRatio_; } + +bool DisplayManagerService::IsScreenRotationLocked() +{ + return ScreenRotationController::IsScreenRotationLocked(); +} + +DMError DisplayManagerService::SetScreenRotationLocked(bool isLocked) +{ + ScreenRotationController::SetScreenRotationLocked(isLocked); + return DMError::DM_OK; +} } // namespace OHOS::Rosen \ No newline at end of file diff --git a/dmserver/src/display_manager_stub.cpp b/dmserver/src/display_manager_stub.cpp index 845589a2..ffbce65a 100644 --- a/dmserver/src/display_manager_stub.cpp +++ b/dmserver/src/display_manager_stub.cpp @@ -313,6 +313,17 @@ int32_t DisplayManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, reply.WriteInt32(static_cast(ret)); break; } + case DisplayManagerMessage::TRANS_ID_IS_SCREEN_ROTATION_LOCKED: { + bool isLocked = IsScreenRotationLocked(); + reply.WriteBool(isLocked); + break; + } + case DisplayManagerMessage::TRANS_ID_SET_SCREEN_ROTATION_LOCKED: { + bool isLocked = static_cast(data.ReadBool()); + DMError ret = SetScreenRotationLocked(isLocked); + reply.WriteInt32(static_cast(ret)); + break; + } default: WLOGFW("unknown transaction code"); return IPCObjectStub::OnRemoteRequest(code, data, reply, option); diff --git a/interfaces/innerkits/dm/screen_manager.h b/interfaces/innerkits/dm/screen_manager.h index a2b59dc7..a539049c 100644 --- a/interfaces/innerkits/dm/screen_manager.h +++ b/interfaces/innerkits/dm/screen_manager.h @@ -55,7 +55,8 @@ public: DMError SetVirtualScreenSurface(ScreenId screenId, sptr surface); bool SetScreenPowerForAll(ScreenPowerState state, PowerStateChangeReason reason); ScreenPowerState GetScreenPower(ScreenId screenId); - + DMError SetScreenRotationLocked(bool isLocked); + bool IsScreenRotationLocked(); private: ScreenManager(); ~ScreenManager(); diff --git a/interfaces/kits/napi/screen_runtime/api/@ohos.screen.d.ts b/interfaces/kits/napi/screen_runtime/api/@ohos.screen.d.ts index 8c35b9d5..bf3812dc 100644 --- a/interfaces/kits/napi/screen_runtime/api/@ohos.screen.d.ts +++ b/interfaces/kits/napi/screen_runtime/api/@ohos.screen.d.ts @@ -82,6 +82,21 @@ declare namespace screen { function setVirtualScreenSurface(screenId:number, surfaceId: string, callback: AsyncCallback): void; function setVirtualScreenSurface(screenId:number, surfaceId: string): Promise; + /** + * Get screen rotation lock status. + * @since 9 + */ + function isScreenRotationLocked(callback: AsyncCallback): void; + function isScreenRotationLocked(): Promise; + + /** + * Set screen rotation lock status. + * @param isLocked Indicates whether the screen rotation switch is locked. + * @since 9 + */ + function setScreenRotationLocked(isLocked:boolean, callback: AsyncCallback): void; + function setScreenRotationLocked(isLocked:boolean): Promise; + /** * the parameter of making expand screen * @syscap SystemCapability.WindowManager.WindowManager.Core diff --git a/interfaces/kits/napi/screen_runtime/napi/js_screen_manager.cpp b/interfaces/kits/napi/screen_runtime/napi/js_screen_manager.cpp index af3921b5..31798101 100644 --- a/interfaces/kits/napi/screen_runtime/napi/js_screen_manager.cpp +++ b/interfaces/kits/napi/screen_runtime/napi/js_screen_manager.cpp @@ -98,6 +98,18 @@ static NativeValue* SetVirtualScreenSurface(NativeEngine* engine, NativeCallback JsScreenManager* me = CheckParamsAndGetThis(engine, info); return (me != nullptr) ? me->OnSetVirtualScreenSurface(*engine, *info) : nullptr; } + +static NativeValue* IsScreenRotationLocked(NativeEngine* engine, NativeCallbackInfo* info) +{ + JsScreenManager* me = CheckParamsAndGetThis(engine, info); + return (me != nullptr) ? me->OnIsScreenRotationLocked(*engine, *info) : nullptr; +} + +static NativeValue* SetScreenRotationLocked(NativeEngine* engine, NativeCallbackInfo* info) +{ + JsScreenManager* me = CheckParamsAndGetThis(engine, info); + return (me != nullptr) ? me->OnSetScreenRotationLocked(*engine, *info) : nullptr; +} private: std::map, sptr>> jsCbMap_; std::mutex mtx_; @@ -607,6 +619,71 @@ NativeValue* OnSetVirtualScreenSurface(NativeEngine& engine, NativeCallbackInfo& engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result)); return result; } + +NativeValue* OnIsScreenRotationLocked(NativeEngine& engine, NativeCallbackInfo& info) +{ + WLOGFI("OnIsScreenRotationLocked is called"); + DMError errCode = DMError::DM_OK; + if (info.argc > 1) { + WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc); + errCode = DMError::DM_ERROR_INVALID_PARAM; + } + AsyncTask::CompleteCallback complete = + [this](NativeEngine& engine, AsyncTask& task, int32_t status) { + bool isLocked = SingletonContainer::Get().IsScreenRotationLocked(); + task.Resolve(engine, CreateJsValue(engine, isLocked)); + }; + NativeValue* lastParam = nullptr; + if (info.argc == ARGC_ONE && info.argv[ARGC_ONE - 1]->TypeOf() == NATIVE_FUNCTION) { + lastParam = info.argv[ARGC_ONE - 1]; + } + NativeValue* result = nullptr; + AsyncTask::Schedule( + engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result)); + return result; +} + +NativeValue* OnSetScreenRotationLocked(NativeEngine& engine, NativeCallbackInfo& info) +{ + WLOGFI("JsScreenManager::OnSetScreenRotationLocked is called"); + DMError errCode = DMError::DM_OK; + if (info.argc < 1 || info.argc > 2) { // 2: maximum params num + WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc); + errCode = DMError::DM_ERROR_INVALID_PARAM; + } + bool isLocked = false; + if (errCode == DMError::DM_OK) { + NativeBoolean* nativeVal = ConvertNativeValueTo(info.argv[0]); + if (nativeVal == nullptr) { + WLOGFE("[NAPI]Failed to convert parameter to isLocked"); + errCode = DMError::DM_ERROR_INVALID_PARAM; + } else { + isLocked = static_cast(*nativeVal); + } + } + + AsyncTask::CompleteCallback complete = + [isLocked, errCode](NativeEngine& engine, AsyncTask& task, int32_t status) { + if (errCode != DMError::DM_OK) { + task.Reject(engine, CreateJsError(engine, static_cast(errCode), "Invalidate params.")); + return; + } + DMError ret = SingletonContainer::Get().SetScreenRotationLocked(isLocked); + if (ret == DMError::DM_OK) { + task.Resolve(engine, engine.CreateUndefined()); + } else { + task.Reject(engine, CreateJsError(engine, static_cast(ret), + "JsScreenManager:SetScreenRotationLocked failed.")); + } + WLOGFI("JsScreenManager::OnSetScreenRotationLocked success, ret = %{public}d", ret); + }; + NativeValue* lastParam = (info.argc <= 1) ? nullptr : + (info.argv[1]->TypeOf() == NATIVE_FUNCTION ? info.argv[1] : nullptr); + NativeValue* result = nullptr; + AsyncTask::Schedule( + engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result)); + return result; +} }; NativeValue* JsScreenManagerInit(NativeEngine* engine, NativeValue* exportObj) @@ -635,6 +712,8 @@ NativeValue* JsScreenManagerInit(NativeEngine* engine, NativeValue* exportObj) BindNativeFunction(*engine, *object, "createVirtualScreen", JsScreenManager::CreateVirtualScreen); BindNativeFunction(*engine, *object, "destroyVirtualScreen", JsScreenManager::DestroyVirtualScreen); BindNativeFunction(*engine, *object, "setVirtualScreenSurface", JsScreenManager::SetVirtualScreenSurface); + BindNativeFunction(*engine, *object, "setScreenRotationLocked", JsScreenManager::SetScreenRotationLocked); + BindNativeFunction(*engine, *object, "isScreenRotationLocked", JsScreenManager::IsScreenRotationLocked); return engine->CreateUndefined(); } } // namespace Rosen From 6c64fe59442dfabf42eababee9bc51f8be57ed65 Mon Sep 17 00:00:00 2001 From: xpeng Date: Tue, 21 Jun 2022 21:01:47 +0800 Subject: [PATCH 06/81] traverse window to get current full-screen window's requestedOrientation Signed-off-by: xpeng Change-Id: I93f122058a6d6e8a9ecbc0dc2fe34b45c9fd39b0 --- dmserver/include/display_manager_service.h | 1 + dmserver/include/display_manager_service_inner.h | 1 + dmserver/include/screen_rotation_controller.h | 2 +- dmserver/src/display_manager_service.cpp | 7 +++++++ dmserver/src/display_manager_service_inner.cpp | 5 +++++ dmserver/src/screen_rotation_controller.cpp | 8 +++++--- utils/include/display_change_listener.h | 3 ++- wmserver/include/window_controller.h | 1 + wmserver/include/window_manager_service.h | 2 ++ wmserver/include/window_node_container.h | 1 + wmserver/src/window_controller.cpp | 9 +++++++++ wmserver/src/window_manager_service.cpp | 12 ++++++++++++ wmserver/src/window_node_container.cpp | 13 ++++++++++++- 13 files changed, 59 insertions(+), 6 deletions(-) diff --git a/dmserver/include/display_manager_service.h b/dmserver/include/display_manager_service.h index ae9ead92..94b17a4a 100644 --- a/dmserver/include/display_manager_service.h +++ b/dmserver/include/display_manager_service.h @@ -98,6 +98,7 @@ public: bool SetVirtualPixelRatio(ScreenId screenId, float virtualPixelRatio) override; static float GetCustomVirtualPixelRatio(); void RegisterDisplayChangeListener(sptr listener); + void GetFullScreenWindowRequestedOrientation(DisplayId displayId, Orientation &orientation); private: DisplayManagerService(); ~DisplayManagerService() = default; diff --git a/dmserver/include/display_manager_service_inner.h b/dmserver/include/display_manager_service_inner.h index 956434df..76f39ef8 100644 --- a/dmserver/include/display_manager_service_inner.h +++ b/dmserver/include/display_manager_service_inner.h @@ -45,6 +45,7 @@ public: void RegisterDisplayChangeListener(sptr listener); bool SetOrientationFromWindow(DisplayId displayId, Orientation orientation); bool SetRotationFromWindow(DisplayId displayId, Rotation targetRotation); + void GetFullScreenWindowRequestedOrientation(DisplayId displayId, Orientation &orientation); }; } // namespace OHOS::Rosen diff --git a/dmserver/include/screen_rotation_controller.h b/dmserver/include/screen_rotation_controller.h index f99f853a..c880491d 100644 --- a/dmserver/include/screen_rotation_controller.h +++ b/dmserver/include/screen_rotation_controller.h @@ -37,7 +37,7 @@ public: private: static void HandleGravitySensorEventCallback(SensorEvent *event); static Rotation GetCurrentDisplayRotation(); - static Orientation GetDisplayOrientation(); + static Orientation GetRequestedOrientation(); static int CalcRotationDegree(GravityData* gravityData); static Rotation CalcTargetDisplayRotation(Orientation requestedOrientation, Rotation sensorRotation); static Rotation ProcessAutoRotationPortraitOrientation(Rotation sensorRotation); diff --git a/dmserver/src/display_manager_service.cpp b/dmserver/src/display_manager_service.cpp index 4d5f67ed..fdbe12a0 100644 --- a/dmserver/src/display_manager_service.cpp +++ b/dmserver/src/display_manager_service.cpp @@ -130,6 +130,13 @@ void DisplayManagerService::NotifyDisplayStateChange(DisplayId defaultDisplayId, } } +void DisplayManagerService::GetFullScreenWindowRequestedOrientation(DisplayId displayId, Orientation &orientation) +{ + if (displayChangeListener_ != nullptr) { + displayChangeListener_->OnGetFullScreenWindowRequestedOrientation(displayId, orientation); + } +} + sptr DisplayManagerService::GetDefaultDisplayInfo() { ScreenId dmsScreenId = abstractScreenController_->GetDefaultAbstractScreenId(); diff --git a/dmserver/src/display_manager_service_inner.cpp b/dmserver/src/display_manager_service_inner.cpp index b890dc58..8660deec 100644 --- a/dmserver/src/display_manager_service_inner.cpp +++ b/dmserver/src/display_manager_service_inner.cpp @@ -147,4 +147,9 @@ bool DisplayManagerServiceInner::SetRotationFromWindow(DisplayId displayId, Rota return DisplayManagerService::GetInstance(). SetRotationFromWindow(displayInfo->GetScreenId(), targetRotation); } + +void DisplayManagerServiceInner::GetFullScreenWindowRequestedOrientation(DisplayId displayId, Orientation &orientation) +{ + DisplayManagerService::GetInstance().GetFullScreenWindowRequestedOrientation(displayId, orientation); +} } // namespace OHOS::Rosen \ No newline at end of file diff --git a/dmserver/src/screen_rotation_controller.cpp b/dmserver/src/screen_rotation_controller.cpp index ca8eb8e5..23ae8047 100644 --- a/dmserver/src/screen_rotation_controller.cpp +++ b/dmserver/src/screen_rotation_controller.cpp @@ -100,7 +100,7 @@ void ScreenRotationController::HandleGravitySensorEventCallback(SensorEvent *eve WLOGE("dms: Orientation Sensor Callback is not SENSOR_TYPE_ID_GRAVITY"); return; } - Orientation orientation = GetDisplayOrientation(); + Orientation orientation = GetRequestedOrientation(); if (!IsSensorRelatedOrientation(orientation)) { return; } @@ -153,9 +153,11 @@ Rotation ScreenRotationController::GetCurrentDisplayRotation() return DisplayManagerServiceInner::GetInstance().GetDisplayById(defaultDisplayId_)->GetRotation(); } -Orientation ScreenRotationController::GetDisplayOrientation() +Orientation ScreenRotationController::GetRequestedOrientation() { - return DisplayManagerServiceInner::GetInstance().GetDefaultDisplay()->GetOrientation(); + Orientation orientation = Orientation::UNSPECIFIED; + DisplayManagerServiceInner::GetInstance().GetFullScreenWindowRequestedOrientation(defaultDisplayId_, orientation); + return orientation; } Rotation ScreenRotationController::CalcTargetDisplayRotation( diff --git a/utils/include/display_change_listener.h b/utils/include/display_change_listener.h index 8e622fe7..62a5a8d2 100644 --- a/utils/include/display_change_listener.h +++ b/utils/include/display_change_listener.h @@ -34,7 +34,8 @@ enum class DisplayStateChangeType : uint32_t { class IDisplayChangeListener : public RefBase { public: virtual void OnDisplayStateChange(DisplayId defaultDisplayId, sptr info, - const std::map>& displayInfoMap, DisplayStateChangeType type)= 0; + const std::map>& displayInfoMap, DisplayStateChangeType type) = 0; + virtual void OnGetFullScreenWindowRequestedOrientation(DisplayId displayId, Orientation &orientation) = 0; }; } } diff --git a/wmserver/include/window_controller.h b/wmserver/include/window_controller.h index 42b146af..bfef9470 100644 --- a/wmserver/include/window_controller.h +++ b/wmserver/include/window_controller.h @@ -63,6 +63,7 @@ public: void CancelStartingWindow(sptr abilityToken); void MinimizeWindowsByLauncher(std::vector& windowIds, bool isAnimated, sptr& finishCallback); + Orientation GetFullScreenWindowRequestedOrientation(DisplayId displayId); private: uint32_t GenWindowId(); void FlushWindowInfo(uint32_t windowId); diff --git a/wmserver/include/window_manager_service.h b/wmserver/include/window_manager_service.h index 91ff46c1..f01c8dfc 100644 --- a/wmserver/include/window_manager_service.h +++ b/wmserver/include/window_manager_service.h @@ -41,6 +41,7 @@ class DisplayChangeListener : public IDisplayChangeListener { public: virtual void OnDisplayStateChange(DisplayId defaultDisplayId, sptr displayInfo, const std::map>& displayInfoMap, DisplayStateChangeType type) override; + virtual void OnGetFullScreenWindowRequestedOrientation(DisplayId displayId, Orientation &orientation) override; }; class WindowManagerServiceHandler : public AAFwk::WindowManagerServiceHandlerStub { @@ -101,6 +102,7 @@ public: void CancelStartingWindow(sptr abilityToken); void MinimizeWindowsByLauncher(std::vector windowIds, bool isAnimated, sptr& finishCallback) override; + void GetFullScreenWindowRequestedOrientation(DisplayId displayId, Orientation &orientation); protected: WindowManagerService(); virtual ~WindowManagerService() = default; diff --git a/wmserver/include/window_node_container.h b/wmserver/include/window_node_container.h index b41a614a..051fffc0 100644 --- a/wmserver/include/window_node_container.h +++ b/wmserver/include/window_node_container.h @@ -67,6 +67,7 @@ public: bool IsForbidDockSliceMove(DisplayId displayId) const; bool IsDockSliceInExitSplitModeArea(DisplayId displayId) const; void ExitSplitMode(DisplayId displayId); + Orientation GetFullScreenWindowRequestedOrientation(); void OnAvoidAreaChange(const std::vector& avoidAreas, DisplayId displayId); bool isVerticalDisplay(DisplayId displayId) const; diff --git a/wmserver/src/window_controller.cpp b/wmserver/src/window_controller.cpp index ddfd5f66..d5270383 100644 --- a/wmserver/src/window_controller.cpp +++ b/wmserver/src/window_controller.cpp @@ -956,5 +956,14 @@ void WindowController::MinimizeWindowsByLauncher(std::vector& windowId } } } + +Orientation WindowController::GetFullScreenWindowRequestedOrientation(DisplayId displayId) +{ + sptr windowNodeContainer = windowRoot_->GetOrCreateWindowNodeContainer(displayId); + if (windowNodeContainer != nullptr) { + return windowNodeContainer->GetFullScreenWindowRequestedOrientation(); + } + return Orientation::UNSPECIFIED; +} } // namespace OHOS } // namespace Rosen diff --git a/wmserver/src/window_manager_service.cpp b/wmserver/src/window_manager_service.cpp index a9915a95..7ba7171f 100644 --- a/wmserver/src/window_manager_service.cpp +++ b/wmserver/src/window_manager_service.cpp @@ -509,6 +509,11 @@ void DisplayChangeListener::OnDisplayStateChange(DisplayId defaultDisplayId, spt WindowManagerService::GetInstance().NotifyDisplayStateChange(defaultDisplayId, displayInfo, displayInfoMap, type); } +void DisplayChangeListener::OnGetFullScreenWindowRequestedOrientation(DisplayId displayId, Orientation &orientation) +{ + WindowManagerService::GetInstance().GetFullScreenWindowRequestedOrientation(displayId, orientation); +} + void WindowManagerService::ProcessPointDown(uint32_t windowId, bool isStartDrag) { return wmsTaskLooper_->PostTask([this, windowId, isStartDrag]() { @@ -617,5 +622,12 @@ void WindowManagerService::MinimizeWindowsByLauncher(std::vector windo return windowController_->MinimizeWindowsByLauncher(windowIds, isAnimated, finishCallback); }).get(); } + +void WindowManagerService::GetFullScreenWindowRequestedOrientation(DisplayId displayId, Orientation &orientation) +{ + wmsTaskLooper_->ScheduleTask([this, displayId, &orientation]() mutable { + orientation = windowController_->GetFullScreenWindowRequestedOrientation(displayId); + }).wait(); +} } // namespace Rosen } // namespace OHOS \ No newline at end of file diff --git a/wmserver/src/window_node_container.cpp b/wmserver/src/window_node_container.cpp index 8e796af3..b5db8092 100644 --- a/wmserver/src/window_node_container.cpp +++ b/wmserver/src/window_node_container.cpp @@ -1843,7 +1843,6 @@ WMError WindowNodeContainer::SetWindowMode(sptr& node, WindowMode ds return WMError::WM_OK; } - void WindowNodeContainer::GetModeChangeHotZones(DisplayId displayId, ModeChangeHotZones& hotZones, const ModeChangeHotZonesConfig& config) { @@ -1869,5 +1868,17 @@ sptr WindowNodeContainer::GetDisplayInfo(DisplayId displayId) { return displayGroupInfo_->GetDisplayInfo(displayId); } + +Orientation WindowNodeContainer::GetFullScreenWindowRequestedOrientation() +{ + std::vector> windowNodes; + TraverseContainer(windowNodes); + for (auto node : windowNodes) { + if (node->GetWindowMode() == WindowMode::WINDOW_MODE_FULLSCREEN) { + return node->GetRequestedOrientation(); + } + } + return Orientation::UNSPECIFIED; +} } // namespace Rosen } // namespace OHOS From 56c0d7475e599160f8ac25649173b79863099b3a Mon Sep 17 00:00:00 2001 From: jixingchun Date: Wed, 22 Jun 2022 11:23:06 +0800 Subject: [PATCH 07/81] refactor: graphic_2d remove_weston, so add direct deps Change the indirect dependencies public by the graphic_2d to direct dependencies Change-Id: I8366b22a6e2f2dfa3e32daa0b64a10d3a0d4d48b Signed-off-by: jixingchun --- interfaces/kits/napi/window_runtime/BUILD.gn | 1 + 1 file changed, 1 insertion(+) diff --git a/interfaces/kits/napi/window_runtime/BUILD.gn b/interfaces/kits/napi/window_runtime/BUILD.gn index 40bed706..19ada59a 100644 --- a/interfaces/kits/napi/window_runtime/BUILD.gn +++ b/interfaces/kits/napi/window_runtime/BUILD.gn @@ -83,6 +83,7 @@ ohos_shared_library("window_napi") { "//foundation/windowmanager/utils:libwmutil", "//foundation/windowmanager/wm:libwm", "//foundation/windowmanager/wmserver:libwms", + "//utils/native/base:utils", ] external_deps = [ From 837b8a62a83d870cec5395d547a1371edf4c3705 Mon Sep 17 00:00:00 2001 From: Zhang Peng Date: Wed, 22 Jun 2022 10:31:31 +0800 Subject: [PATCH 08/81] typo fix Signed-off-by: Zhang Peng Change-Id: Ia718cf408d5cadb26dc8174bca6e58f3298f358b --- dm/test/unittest/screen_manager_test.cpp | 8 +++--- dmserver/src/abstract_display_controller.cpp | 2 +- dmserver/src/abstract_screen.cpp | 2 +- dmserver/src/abstract_screen_controller.cpp | 4 +-- dmserver/src/display_manager_service.cpp | 2 +- dmserver/src/screen_rotation_controller.cpp | 4 +-- hisysevent.yaml | 2 +- utils/include/surface_reader_handler.h | 2 +- utils/include/surface_reader_handler_impl.h | 4 +-- utils/include/window_helper.h | 2 +- utils/include/wm_common_inner.h | 2 +- utils/src/surface_reader.cpp | 2 +- utils/src/surface_reader_handler_impl.cpp | 6 ++--- wm/include/window_adapter.h | 2 +- wm/include/window_impl.h | 6 ++--- wm/src/window_adapter.cpp | 4 +-- wm/src/window_impl.cpp | 18 ++++++------- .../windowipc_fuzzer/windowipc_fuzzer.cpp | 6 ++--- wm/test/unittest/mock_window_adapter.h | 2 +- wm/test/unittest/window_impl_test.cpp | 4 +-- wmserver/include/display_group_controller.h | 4 +-- wmserver/include/minimize_app.h | 4 +-- wmserver/include/window_controller.h | 2 +- wmserver/include/window_layout_policy.h | 4 +-- wmserver/include/window_manager_service.h | 2 +- wmserver/include/window_node_container.h | 6 ++--- wmserver/include/window_pair.h | 8 +++--- wmserver/include/window_root.h | 2 +- .../include/zidl/window_manager_interface.h | 8 +++--- wmserver/include/zidl/window_manager_proxy.h | 2 +- wmserver/src/avoid_area_controller.cpp | 6 ++--- wmserver/src/display_group_controller.cpp | 16 ++++++------ wmserver/src/input_window_monitor.cpp | 10 +++---- wmserver/src/remote_animation.cpp | 6 ++--- wmserver/src/window_controller.cpp | 10 +++---- wmserver/src/window_inner_manager.cpp | 4 +-- wmserver/src/window_layout_policy.cpp | 26 +++++++++---------- wmserver/src/window_layout_policy_cascade.cpp | 2 +- wmserver/src/window_layout_policy_tile.cpp | 6 ++--- wmserver/src/window_manager_service.cpp | 6 ++--- wmserver/src/window_node_container.cpp | 20 +++++++------- wmserver/src/window_pair.cpp | 6 ++--- wmserver/src/window_root.cpp | 22 ++++++++-------- wmserver/src/zidl/window_manager_proxy.cpp | 8 +++--- wmserver/src/zidl/window_manager_stub.cpp | 8 +++--- 45 files changed, 141 insertions(+), 141 deletions(-) diff --git a/dm/test/unittest/screen_manager_test.cpp b/dm/test/unittest/screen_manager_test.cpp index 72113de3..5357035d 100644 --- a/dm/test/unittest/screen_manager_test.cpp +++ b/dm/test/unittest/screen_manager_test.cpp @@ -51,11 +51,11 @@ void ScreenManagerTest::TearDown() namespace { /** - * @tc.name: CreateAndDestory01 + * @tc.name: CreateAndDestroy01 * @tc.desc: CreateVirtualScreen with invalid option and return invalid screen id * @tc.type: FUNC */ -HWTEST_F(ScreenManagerTest, CreateAndDestory01, Function | SmallTest | Level1) +HWTEST_F(ScreenManagerTest, CreateAndDestroy01, Function | SmallTest | Level1) { VirtualScreenOption wrongOption = {defaultName_, defaultWidth_, defaultHeight_, defaultDensity_, nullptr, defaultFlags_}; @@ -69,11 +69,11 @@ HWTEST_F(ScreenManagerTest, CreateAndDestory01, Function | SmallTest | Level1) } /** - * @tc.name: CreateAndDestory02 + * @tc.name: CreateAndDestroy02 * @tc.desc: CreateVirtualScreen with valid option and return valid screen id * @tc.type: FUNC */ -HWTEST_F(ScreenManagerTest, CreateAndDestory02, Function | SmallTest | Level1) +HWTEST_F(ScreenManagerTest, CreateAndDestroy02, Function | SmallTest | Level1) { ScreenManagerUtils utils; ASSERT_TRUE(utils.CreateSurface()); diff --git a/dmserver/src/abstract_display_controller.cpp b/dmserver/src/abstract_display_controller.cpp index 22c7198b..5a5fe602 100644 --- a/dmserver/src/abstract_display_controller.cpp +++ b/dmserver/src/abstract_display_controller.cpp @@ -108,7 +108,7 @@ std::shared_ptr AbstractDisplayController::GetScreenSnapshot(Di { sptr abstractDisplay = GetAbstractDisplay(displayId); if (abstractDisplay == nullptr) { - WLOGFE("GetScreenSnapshot: GetAbstarctDisplay failed"); + WLOGFE("GetScreenSnapshot: GetAbstractDisplay failed"); return nullptr; } ScreenId dmsScreenId = abstractDisplay->GetAbstractScreenId(); diff --git a/dmserver/src/abstract_screen.cpp b/dmserver/src/abstract_screen.cpp index e625408b..fd008e0d 100644 --- a/dmserver/src/abstract_screen.cpp +++ b/dmserver/src/abstract_screen.cpp @@ -243,7 +243,7 @@ Rotation AbstractScreen::CalcRotation(Orientation orientation) const if (info == nullptr) { return Rotation::ROTATION_0; } - // virtical: phone(Plugin screen); horizontal: pad & external screen + // vertical: phone(Plugin screen); horizontal: pad & external screen bool isVerticalScreen = info->width_ < info->height_; switch (orientation) { case Orientation::UNSPECIFIED: { diff --git a/dmserver/src/abstract_screen_controller.cpp b/dmserver/src/abstract_screen_controller.cpp index 01272560..48b15b8e 100644 --- a/dmserver/src/abstract_screen_controller.cpp +++ b/dmserver/src/abstract_screen_controller.cpp @@ -60,7 +60,7 @@ void AbstractScreenController::RegisterRsScreenConnectionChangeListener() auto task = [this] { RegisterRsScreenConnectionChangeListener(); }; - // posk task after 50 ms. + // post task after 50 ms. controllerHandler_->PostTask(task, 50, AppExecFwk::EventQueue::Priority::HIGH); } bool callbackRegister = DisplayManagerAgentController::GetInstance().SetRemoveAgentCallback( @@ -642,7 +642,7 @@ bool AbstractScreenController::SetRotation(ScreenId screenId, Rotation rotationA { auto screen = GetAbstractScreen(screenId); if (rotationAfter != screen->rotation_) { - WLOGI("set orientation. roatiton %{public}u", rotationAfter); + WLOGI("set orientation. rotation %{public}u", rotationAfter); ScreenId rsScreenId; if (!screenIdManager_.ConvertToRsScreenId(screenId, rsScreenId)) { WLOGE("Convert to RsScreenId fail. screenId: %{public}" PRIu64"", screenId); diff --git a/dmserver/src/display_manager_service.cpp b/dmserver/src/display_manager_service.cpp index 4d5f67ed..5cae9694 100644 --- a/dmserver/src/display_manager_service.cpp +++ b/dmserver/src/display_manager_service.cpp @@ -366,7 +366,7 @@ ScreenId DisplayManagerService::GetScreenIdByDisplayId(DisplayId displayId) cons { sptr abstractDisplay = abstractDisplayController_->GetAbstractDisplay(displayId); if (abstractDisplay == nullptr) { - WLOGFE("GetScreenIdByDisplayId: GetAbstarctDisplay failed"); + WLOGFE("GetScreenIdByDisplayId: GetAbstractDisplay failed"); return SCREEN_ID_INVALID; } return abstractDisplay->GetAbstractScreenId(); diff --git a/dmserver/src/screen_rotation_controller.cpp b/dmserver/src/screen_rotation_controller.cpp index ca8eb8e5..fa9c7bf4 100644 --- a/dmserver/src/screen_rotation_controller.cpp +++ b/dmserver/src/screen_rotation_controller.cpp @@ -24,7 +24,7 @@ namespace OHOS { namespace Rosen { namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "DisplaySensorController"}; - constexpr int64_t ORIENTATION_SENSOR_SAMPING_RATE = 200000000; // 200ms + constexpr int64_t ORIENTATION_SENSOR_SAMPLING_RATE = 200000000; // 200ms constexpr int64_t ORIENTATION_SENSOR_REPORTING_RATE = 200000000; // 200ms constexpr long ORIENTATION_SENSOR_CALLBACK_TIME_INTERVAL = 200; // 200ms constexpr int VALID_INCLINATION_ANGLE_THRESHOLD_COEFFICIENT = 3; @@ -54,7 +54,7 @@ void ScreenRotationController::SubscribeGravitySensor() user_.userData = nullptr; user_.callback = &HandleGravitySensorEventCallback; SubscribeSensor(SENSOR_TYPE_ID_GRAVITY, &user_); - SetBatch(SENSOR_TYPE_ID_GRAVITY, &user_, ORIENTATION_SENSOR_SAMPING_RATE, ORIENTATION_SENSOR_REPORTING_RATE); + SetBatch(SENSOR_TYPE_ID_GRAVITY, &user_, ORIENTATION_SENSOR_SAMPLING_RATE, ORIENTATION_SENSOR_REPORTING_RATE); SetMode(SENSOR_TYPE_ID_GRAVITY, &user_, SENSOR_ON_CHANGE); ActivateSensor(SENSOR_TYPE_ID_GRAVITY, &user_); isGravitySensorSubscribed_ = true; diff --git a/hisysevent.yaml b/hisysevent.yaml index 6a8fe294..b55daa79 100644 --- a/hisysevent.yaml +++ b/hisysevent.yaml @@ -25,7 +25,7 @@ # // __BASE is used for defining the basic info of the event. # // "type" optional values are: FAULT, STATISTICS, SECURITY, BEHAVIOR. # // "level" optional values are: CRITICAL, MINOR. -# // "tag" set tags with may used by subscriber of this event, multiple tags devided by space. +# // "tag" set tags with may used by subscriber of this event, multiple tags divided by space. # // "desc" full description of this event. # @PARAMETER: {type: parameter type, arrsize: array length(optional), desc: parameter description}. # // follow the __BASE block, each line defines a parameter of this event. diff --git a/utils/include/surface_reader_handler.h b/utils/include/surface_reader_handler.h index 0a594972..dfb4619c 100644 --- a/utils/include/surface_reader_handler.h +++ b/utils/include/surface_reader_handler.h @@ -26,7 +26,7 @@ public: virtual ~SurfaceReaderHandler() noexcept { } - virtual bool OnImageAvalible(sptr pixleMap) = 0; + virtual bool OnImageAvailable(sptr pixelMap) = 0; }; } } diff --git a/utils/include/surface_reader_handler_impl.h b/utils/include/surface_reader_handler_impl.h index f18115a2..5471a46c 100644 --- a/utils/include/surface_reader_handler_impl.h +++ b/utils/include/surface_reader_handler_impl.h @@ -23,14 +23,14 @@ namespace OHOS { namespace Rosen { class SurfaceReaderHandlerImpl : public SurfaceReaderHandler { public: - bool OnImageAvalible(sptr pixleMap) override; + bool OnImageAvailable(sptr pixelMap) override; bool IsImageOk(); void ResetFlag(); sptr GetPixelMap(); private: bool flag_ = false; - sptr pixleMap_ = nullptr; + sptr pixelMap_ = nullptr; std::recursive_mutex mutex_; }; } diff --git a/utils/include/window_helper.h b/utils/include/window_helper.h index 1d67ab03..9f719142 100644 --- a/utils/include/window_helper.h +++ b/utils/include/window_helper.h @@ -74,7 +74,7 @@ public: return ((IsMainWindow(type)) && (mode != WindowMode::WINDOW_MODE_FLOATING)); } - static inline bool IsFloatintWindow(WindowMode mode) + static inline bool IsFloatingWindow(WindowMode mode) { return mode == WindowMode::WINDOW_MODE_FLOATING; } diff --git a/utils/include/wm_common_inner.h b/utils/include/wm_common_inner.h index 731feeff..340f3932 100644 --- a/utils/include/wm_common_inner.h +++ b/utils/include/wm_common_inner.h @@ -146,7 +146,7 @@ namespace { constexpr uint32_t MIN_HORIZONTAL_SPLIT_WIDTH = 320; constexpr uint32_t MAX_FLOATING_SIZE = 2560; const std::string WINDOW_MANAGER_CONFIG_XML = "/system/etc/window/resources/window_manager_config.xml"; - const Rect IVALID_EMPTY_RECT = {0, 0, 0, 0}; + const Rect INVALID_EMPTY_RECT = {0, 0, 0, 0}; } } } diff --git a/utils/src/surface_reader.cpp b/utils/src/surface_reader.cpp index cbbb409f..9cf1cd10 100644 --- a/utils/src/surface_reader.cpp +++ b/utils/src/surface_reader.cpp @@ -152,7 +152,7 @@ bool SurfaceReader::ProcessBuffer(const sptr &buf) pixelMap->SetPixelsAddr(data, nullptr, width * height, AllocatorType::HEAP_ALLOC, nullptr); - handler_->OnImageAvalible(pixelMap); + handler_->OnImageAvailable(pixelMap); return true; } } diff --git a/utils/src/surface_reader_handler_impl.cpp b/utils/src/surface_reader_handler_impl.cpp index 4d0aae20..fc11c13c 100644 --- a/utils/src/surface_reader_handler_impl.cpp +++ b/utils/src/surface_reader_handler_impl.cpp @@ -21,12 +21,12 @@ namespace Rosen { namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "SurfaceReaderHandlerImpl"}; } // namespace -bool SurfaceReaderHandlerImpl::OnImageAvalible(sptr pixleMap) +bool SurfaceReaderHandlerImpl::OnImageAvailable(sptr pixelMap) { std::lock_guard lock(mutex_); if (!flag_) { flag_ = true; - pixleMap_ = pixleMap; + pixelMap_ = pixelMap; WLOGFI("Get an Image!"); } return true; @@ -49,7 +49,7 @@ void SurfaceReaderHandlerImpl::ResetFlag() sptr SurfaceReaderHandlerImpl::GetPixelMap() { std::lock_guard lock(mutex_); - return pixleMap_; + return pixelMap_; } } } \ No newline at end of file diff --git a/wm/include/window_adapter.h b/wm/include/window_adapter.h index e85fb3d2..8c1095e8 100644 --- a/wm/include/window_adapter.h +++ b/wm/include/window_adapter.h @@ -49,7 +49,7 @@ public: virtual void ProcessPointUp(uint32_t windowId); virtual void MinimizeAllAppWindows(DisplayId displayId); virtual WMError ToggleShownStateForAllAppWindows(); - virtual WMError MaxmizeWindow(uint32_t windowId); + virtual WMError MaximizeWindow(uint32_t windowId); virtual WMError SetWindowLayoutMode(WindowLayoutMode mode); virtual WMError UpdateProperty(sptr& windowProperty, PropertyChangeAction action); virtual WMError GetSystemConfig(SystemConfig& systemConfig); diff --git a/wm/include/window_impl.h b/wm/include/window_impl.h index 217738b0..9b433e12 100644 --- a/wm/include/window_impl.h +++ b/wm/include/window_impl.h @@ -189,7 +189,7 @@ public: void NotifySizeChange(Rect rect, WindowSizeChangeReason reason); void NotifyKeyEvent(std::shared_ptr &keyEvent); void NotifyPointEvent(std::shared_ptr& pointerEvent); - void NotifyAviodAreaChange(const std::vector& avoidArea); + void NotifyAvoidAreaChange(const std::vector& avoidArea); void NotifyDisplayMoveChange(DisplayId from, DisplayId to); void NotifyOccupiedAreaChange(const sptr& info); void NotifyModeChange(WindowMode mode); @@ -318,7 +318,7 @@ private: // colorspace, gamut using ColorSpaceConvertMap = struct { ColorSpace colorSpace; - ColorGamut sufaceColorGamut; + ColorGamut surfaceColorGamut; }; static const ColorSpaceConvertMap colorSpaceConvertMap[]; static ColorSpace GetColorSpaceFromSurfaceGamut(ColorGamut ColorGamut); @@ -361,7 +361,7 @@ private: Rect startRectExceptFrame_ = { 0, 0, 0, 0 }; Rect startRectExceptCorner_ = { 0, 0, 0, 0 }; DragType dragType_ = DragType::DRAG_UNDEFINED; - bool isAppDecorEnbale_ = true; + bool isAppDecorEnable_ = true; SystemConfig windowSystemConfig_ ; bool isOriginRectSet_ = false; bool isWaitingFrame_ = false; diff --git a/wm/src/window_adapter.cpp b/wm/src/window_adapter.cpp index 8d6e4dca..ac9c77db 100644 --- a/wm/src/window_adapter.cpp +++ b/wm/src/window_adapter.cpp @@ -149,11 +149,11 @@ WMError WindowAdapter::ToggleShownStateForAllAppWindows() return windowManagerServiceProxy_->ToggleShownStateForAllAppWindows(); } -WMError WindowAdapter::MaxmizeWindow(uint32_t windowId) +WMError WindowAdapter::MaximizeWindow(uint32_t windowId) { INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR); - return windowManagerServiceProxy_->MaxmizeWindow(windowId); + return windowManagerServiceProxy_->MaximizeWindow(windowId); } WMError WindowAdapter::GetSystemConfig(SystemConfig& systemConfig) diff --git a/wm/src/window_impl.cpp b/wm/src/window_impl.cpp index dcaa1a01..66cfeb33 100644 --- a/wm/src/window_impl.cpp +++ b/wm/src/window_impl.cpp @@ -314,7 +314,7 @@ WMError WindowImpl::SetWindowType(WindowType type) return WMError::WM_ERROR_INVALID_PARAM; } property_->SetWindowType(type); - if (isAppDecorEnbale_ && windowSystemConfig_.isSystemDecorEnable_) { + if (isAppDecorEnable_ && windowSystemConfig_.isSystemDecorEnable_) { property_->SetDecorEnable(WindowHelper::IsMainWindow(property_->GetWindowType())); } AdjustWindowAnimationFlag(); @@ -442,7 +442,7 @@ WMError WindowImpl::SetUIContent(const std::string& contentInfo, WLOGFE("fail to SetUIContent id: %{public}u", property_->GetWindowId()); return WMError::WM_ERROR_NULLPTR; } - if (!isAppDecorEnbale_ || !windowSystemConfig_.isSystemDecorEnable_) { + if (!isAppDecorEnable_ || !windowSystemConfig_.isSystemDecorEnable_) { WLOGFI("app set decor enable false"); property_->SetDecorEnable(false); } @@ -490,7 +490,7 @@ std::string WindowImpl::GetContentInfo() ColorSpace WindowImpl::GetColorSpaceFromSurfaceGamut(ColorGamut ColorGamut) { for (auto item: colorSpaceConvertMap) { - if (item.sufaceColorGamut == ColorGamut) { + if (item.surfaceColorGamut == ColorGamut) { return item.colorSpace; } } @@ -501,7 +501,7 @@ ColorGamut WindowImpl::GetSurfaceGamutFromColorSpace(ColorSpace colorSpace) { for (auto item: colorSpaceConvertMap) { if (item.colorSpace == colorSpace) { - return item.sufaceColorGamut; + return item.surfaceColorGamut; } } return ColorGamut::COLOR_GAMUT_SRGB; @@ -1147,7 +1147,7 @@ void WindowImpl::DisableAppWindowDecor() return; } WLOGFI("disable app window decoration."); - isAppDecorEnbale_ = false; + isAppDecorEnable_ = false; } bool WindowImpl::IsDecorEnable() const @@ -1494,7 +1494,7 @@ void WindowImpl::SetModeSupportInfo(uint32_t modeSupportInfo) property_->SetModeSupportInfo(modeSupportInfo); UpdateProperty(PropertyChangeAction::ACTION_UPDATE_MODE_SUPPORT_INFO); if (!WindowHelper::IsWindowModeSupported(modeSupportInfo, GetMode())) { - WLOGFI("currunt window mode is not supported, force to transform to appropriate mode. window id:%{public}u", + WLOGFI("current window mode is not supported, force to transform to appropriate mode. window id:%{public}u", GetWindowId()); WindowMode mode = WindowHelper::GetWindowModeFromModeSupportInfo(modeSupportInfo); if (mode != WindowMode::WINDOW_MODE_UNDEFINED) { @@ -1948,7 +1948,7 @@ void WindowImpl::UpdateConfiguration(const std::shared_ptr& avoidArea) { WLOGFI("Window Update AvoidArea, id: %{public}u", property_->GetWindowId()); - NotifyAviodAreaChange(avoidArea); + NotifyAvoidAreaChange(avoidArea); } void WindowImpl::UpdateWindowState(WindowState state) @@ -2127,7 +2127,7 @@ void WindowImpl::NotifyPointEvent(std::shared_ptr& pointerEve }); } -void WindowImpl::NotifyAviodAreaChange(const std::vector& avoidArea) +void WindowImpl::NotifyAvoidAreaChange(const std::vector& avoidArea) { std::vector> avoidAreaChangeListeners; { @@ -2215,7 +2215,7 @@ Rect WindowImpl::GetSystemAlarmWindowDefaultSize(Rect defaultRect) SYSTEM_ALARM_WINDOW_HEIGHT_RATIO)); rect = { static_cast((width - alarmWidth) / 2), static_cast((height - alarmHeight) / 2), - alarmWidth, alarmHeight }; // devided by 2 to middle the window + alarmWidth, alarmHeight }; // divided by 2 to middle the window return rect; } diff --git a/wm/test/fuzztest/windowipc_fuzzer/windowipc_fuzzer.cpp b/wm/test/fuzztest/windowipc_fuzzer/windowipc_fuzzer.cpp index 36d0a451..3b90ebc2 100644 --- a/wm/test/fuzztest/windowipc_fuzzer/windowipc_fuzzer.cpp +++ b/wm/test/fuzztest/windowipc_fuzzer/windowipc_fuzzer.cpp @@ -126,17 +126,17 @@ void IPCSpecificInterfaceFuzzTest2(sptr proxy, MessageParcel& sen sendData, reply, option); proxy->SendRequest(static_cast(IWindowManager::WindowManagerMessage::TRANS_ID_SET_BACKGROUND_BLUR), sendData, reply, option); - proxy->SendRequest(static_cast(IWindowManager::WindowManagerMessage::TRANS_ID_SET_APLPHA), + proxy->SendRequest(static_cast(IWindowManager::WindowManagerMessage::TRANS_ID_SET_ALPHA), sendData, reply, option); proxy->SendRequest(static_cast(IWindowManager::WindowManagerMessage::TRANS_ID_UPDATE_LAYOUT_MODE), sendData, reply, option); - proxy->SendRequest(static_cast(IWindowManager::WindowManagerMessage::TRANS_ID_MAXMIZE_WINDOW), + proxy->SendRequest(static_cast(IWindowManager::WindowManagerMessage::TRANS_ID_MAXIMIZE_WINDOW), sendData, reply, option); proxy->SendRequest(static_cast(IWindowManager::WindowManagerMessage::TRANS_ID_UPDATE_PROPERTY), sendData, reply, option); proxy->SendRequest( - static_cast(IWindowManager::WindowManagerMessage::TRANS_ID_GET_ACCCESSIBILITY_WIDDOW_INFO_ID), + static_cast(IWindowManager::WindowManagerMessage::TRANS_ID_GET_ACCESSIBILITY_WINDOW_INFO_ID), sendData, reply, option); proxy->SendRequest( static_cast(IWindowManager::WindowManagerMessage::TRANS_ID_ANIMATION_SET_CONTROLLER), diff --git a/wm/test/unittest/mock_window_adapter.h b/wm/test/unittest/mock_window_adapter.h index eda3cefc..8eeca6ba 100644 --- a/wm/test/unittest/mock_window_adapter.h +++ b/wm/test/unittest/mock_window_adapter.h @@ -32,7 +32,7 @@ public: MOCK_METHOD2(SetWindowBackgroundBlur, WMError(uint32_t windowId, WindowBlurLevel level)); MOCK_METHOD2(SetAlpha, WMError(uint32_t windowId, float alpha)); MOCK_METHOD2(UpdateProperty, WMError(sptr& windowProperty, PropertyChangeAction action)); - MOCK_METHOD1(MaxmizeWindow, WMError(uint32_t windowId)); + MOCK_METHOD1(MaximizeWindow, WMError(uint32_t windowId)); }; } } // namespace OHOS diff --git a/wm/test/unittest/window_impl_test.cpp b/wm/test/unittest/window_impl_test.cpp index ec92852d..a62f8260 100644 --- a/wm/test/unittest/window_impl_test.cpp +++ b/wm/test/unittest/window_impl_test.cpp @@ -1309,7 +1309,7 @@ HWTEST_F(WindowImplTest, SetTouchable02, Function | SmallTest | Level3) /** * @tc.name: DisableAppWindowDecor01 - * @tc.desc: disbale app window decor + * @tc.desc: disable app window decor * @tc.type: FUNC */ HWTEST_F(WindowImplTest, DisableAppWindowDecor01, Function | SmallTest | Level3) @@ -1323,7 +1323,7 @@ HWTEST_F(WindowImplTest, DisableAppWindowDecor01, Function | SmallTest | Level3) window->DisableAppWindowDecor(); EXPECT_CALL(m->Mock(), AddWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK)); ASSERT_EQ(WMError::WM_OK, window->Show()); - ASSERT_FALSE(window->isAppDecorEnbale_); + ASSERT_FALSE(window->isAppDecorEnable_); EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK)); ASSERT_EQ(WMError::WM_OK, window->Destroy()); } diff --git a/wmserver/include/display_group_controller.h b/wmserver/include/display_group_controller.h index 2d726d69..a16fe222 100644 --- a/wmserver/include/display_group_controller.h +++ b/wmserver/include/display_group_controller.h @@ -62,7 +62,7 @@ public: private: std::vector>* GetWindowNodesByDisplayIdAndRootType(DisplayId displayId, WindowRootNodeType type); void AddWindowNodeOnWindowTree(sptr& node, WindowRootNodeType rootType); - void ProcessNotCrossNodesOnDestroiedDisplay(DisplayId displayId, std::vector& windowIds); + void ProcessNotCrossNodesOnDestroyedDisplay(DisplayId displayId, std::vector& windowIds); void ProcessDisplaySizeChangeOrRotation(DisplayId defaultDisplayId, DisplayId displayId, const std::map& displayRectMap, DisplayStateChangeType type); void ProcessCrossNodes(DisplayId defaultDisplayId, DisplayStateChangeType type); @@ -72,7 +72,7 @@ private: void UpdateWindowDisplayIdIfNeeded(const sptr& node, const std::vector& curShowingDisplays); void UpdateWindowDisplayId(const sptr& node, DisplayId newDisplayId); - void ClearMapOfDestroiedDisplay(DisplayId displayId); + void ClearMapOfDestroyedDisplay(DisplayId displayId); void ChangeToRectInDisplayGroup(const sptr& node); sptr windowNodeContainer_; diff --git a/wmserver/include/minimize_app.h b/wmserver/include/minimize_app.h index 10f999f4..0d0c0f8e 100644 --- a/wmserver/include/minimize_app.h +++ b/wmserver/include/minimize_app.h @@ -26,7 +26,7 @@ namespace OHOS { namespace Rosen { enum class MinimizeReason : uint32_t { - MINIMIZE_BUTTOM, + MINIMIZE_BUTTON, MINIMIZE_ALL, LAYOUT_TILE, MAX_APP_COUNT, @@ -51,7 +51,7 @@ public: private: static inline bool IsFromUser(MinimizeReason reason) { - return (reason == MinimizeReason::MINIMIZE_ALL || reason == MinimizeReason::MINIMIZE_BUTTOM || + return (reason == MinimizeReason::MINIMIZE_ALL || reason == MinimizeReason::MINIMIZE_BUTTON || reason == MinimizeReason::MAX_APP_COUNT || reason == MinimizeReason::LAYOUT_TILE || reason == MinimizeReason::SPLIT_REPLACE || reason == MinimizeReason::SPLIT_QUIT); } diff --git a/wmserver/include/window_controller.h b/wmserver/include/window_controller.h index 42b146af..f7d668cc 100644 --- a/wmserver/include/window_controller.h +++ b/wmserver/include/window_controller.h @@ -51,7 +51,7 @@ public: WMError ProcessPointUp(uint32_t windowId); void MinimizeAllAppWindows(DisplayId displayId); WMError ToggleShownStateForAllAppWindows(); - WMError MaxmizeWindow(uint32_t windowId); + WMError MaximizeWindow(uint32_t windowId); WMError SetWindowLayoutMode(WindowLayoutMode mode); WMError UpdateProperty(sptr& property, PropertyChangeAction action); void NotifySystemBarTints(); diff --git a/wmserver/include/window_layout_policy.h b/wmserver/include/window_layout_policy.h index 37c317b8..c9f178a3 100644 --- a/wmserver/include/window_layout_policy.h +++ b/wmserver/include/window_layout_policy.h @@ -89,7 +89,7 @@ protected: void LimitFloatingWindowSize(const sptr& node, const Rect& displayRect, Rect& winRect) const; void LimitMainFloatingWindowPosition(const sptr& node, Rect& winRect) const; - void UpdateFloatongWindowSizeForStretchableWindow(const sptr& node, + void UpdateFloatingWindowSizeForStretchableWindow(const sptr& node, const Rect& displayRect, Rect& winRect) const; void UpdateFloatingWindowSizeByCustomizedLimits(const sptr& node, const Rect& displayRect, Rect& winRect) const; @@ -113,7 +113,7 @@ protected: Rect secondaryLimitRect_; Rect dividerRect_; Rect firstCascadeRect_; - std::vector exitSplitPoints_; // 2 element, first elment < second element + std::vector exitSplitPoints_; // 2 element, first element < second element std::vector splitRatioPoints_; }; sptr displayGroupInfo_; diff --git a/wmserver/include/window_manager_service.h b/wmserver/include/window_manager_service.h index 91ff46c1..55403f9d 100644 --- a/wmserver/include/window_manager_service.h +++ b/wmserver/include/window_manager_service.h @@ -82,7 +82,7 @@ public: WMError GetTopWindowId(uint32_t mainWinId, uint32_t& topWinId) override; void MinimizeAllAppWindows(DisplayId displayId) override; WMError ToggleShownStateForAllAppWindows() override; - WMError MaxmizeWindow(uint32_t windowId) override; + WMError MaximizeWindow(uint32_t windowId) override; WMError SetWindowLayoutMode(WindowLayoutMode mode) override; WMError UpdateProperty(sptr& windowProperty, PropertyChangeAction action) override; WMError GetAccessibilityWindowInfo(sptr& windowInfo) override; diff --git a/wmserver/include/window_node_container.h b/wmserver/include/window_node_container.h index b41a614a..84c60989 100644 --- a/wmserver/include/window_node_container.h +++ b/wmserver/include/window_node_container.h @@ -102,7 +102,7 @@ public: sptr GetLayoutPolicy() const; sptr GetAvoidController() const; - sptr GetMutiDisplayController() const; + sptr GetMultiDisplayController() const; sptr GetRootNode(WindowRootNodeType type) const; void NotifyDockWindowStateChanged(sptr& node, bool isEnable); @@ -129,7 +129,7 @@ private: bool IsSplitImmersiveNode(sptr node) const; bool TraverseFromTopToBottom(sptr node, const WindowNodeOperationFunc& func) const; bool TraverseFromBottomToTop(sptr node, const WindowNodeOperationFunc& func) const; - void RcoveryScreenDefaultOrientationIfNeed(DisplayId displayId); + void RecoverScreenDefaultOrientationIfNeed(DisplayId displayId); // cannot determine in case of a window covered by union of several windows or with transparent value void UpdateWindowVisibilityInfos(std::vector>& infos); void RaiseOrderedWindowToTop(std::vector>& orderedNodes, @@ -159,7 +159,7 @@ private: std::map backupWindowMode_; std::map backupDividerWindowRect_; sptr zorderPolicy_ = new WindowZorderPolicy(); - std::unordered_map> layoutPolicys_; + std::unordered_map> layoutPolicies_; WindowLayoutMode layoutMode_ = WindowLayoutMode::CASCADE; std::vector currentCoveredArea_; std::vector removedIds_; diff --git a/wmserver/include/window_pair.h b/wmserver/include/window_pair.h index 22311203..86d8391c 100644 --- a/wmserver/include/window_pair.h +++ b/wmserver/include/window_pair.h @@ -51,7 +51,7 @@ public: /** * Constructor used to create an empty WindowPair instance. * - * @param displayId the disply of window pair + * @param displayId the display of window pair * @param appNode the window root of app window */ WindowPair(const DisplayId& displayId, DisplayGroupWindowTree& displayGroupWindowTree); @@ -221,7 +221,7 @@ private: void DumpPairInfo(); /** - * Find pairable window frome window trees. + * Find pairable window from window trees. * * @param node the node waiting to be paired * @return window node @@ -237,7 +237,7 @@ private: sptr GetPairableWindow(sptr& node); /** - * Send brodcast message of split event. + * Send broadcast message of split event. * * @param node trigger node */ @@ -253,7 +253,7 @@ private: WindowPairStatus status_ = {WindowPairStatus::STATUS_EMPTY}; DisplayGroupWindowTree& displayGroupWindowTree_; bool isAllAppWindowsRestoring_ { false }; - Rect initalDivderRect_ {0, 0, 0, 0}; + Rect initalDividerRect_ {0, 0, 0, 0}; }; } // namespace Rosen } // namespace OHOS diff --git a/wmserver/include/window_root.h b/wmserver/include/window_root.h index 7181676b..243d9d39 100644 --- a/wmserver/include/window_root.h +++ b/wmserver/include/window_root.h @@ -61,7 +61,7 @@ public: WMError GetTopWindowId(uint32_t mainWinId, uint32_t& topWinId); void MinimizeAllAppWindows(DisplayId displayId); WMError ToggleShownStateForAllAppWindows(); - WMError MaxmizeWindow(uint32_t windowId); + WMError MaximizeWindow(uint32_t windowId); WMError SetWindowLayoutMode(DisplayId displayId, WindowLayoutMode mode); void ProcessWindowStateChange(WindowState state, WindowStateChangeReason reason); diff --git a/wmserver/include/zidl/window_manager_interface.h b/wmserver/include/zidl/window_manager_interface.h index fd4c0c30..2f4a3c99 100644 --- a/wmserver/include/zidl/window_manager_interface.h +++ b/wmserver/include/zidl/window_manager_interface.h @@ -50,11 +50,11 @@ public: TRANS_ID_MINIMIZE_ALL_APP_WINDOWS, TRANS_ID_TOGGLE_SHOWN_STATE_FOR_ALL_APP_WINDOWS, TRANS_ID_SET_BACKGROUND_BLUR, - TRANS_ID_SET_APLPHA, + TRANS_ID_SET_ALPHA, TRANS_ID_UPDATE_LAYOUT_MODE, - TRANS_ID_MAXMIZE_WINDOW, + TRANS_ID_MAXIMIZE_WINDOW, TRANS_ID_UPDATE_PROPERTY, - TRANS_ID_GET_ACCCESSIBILITY_WIDDOW_INFO_ID, + TRANS_ID_GET_ACCESSIBILITY_WINDOW_INFO_ID, TRANS_ID_ANIMATION_SET_CONTROLLER, TRANS_ID_GET_SYSTEM_CONFIG, TRANS_ID_NOTIFY_WINDOW_TRANSITION, @@ -76,7 +76,7 @@ public: virtual void ProcessPointUp(uint32_t windowId) = 0; virtual void MinimizeAllAppWindows(DisplayId displayId) = 0; virtual WMError ToggleShownStateForAllAppWindows() = 0; - virtual WMError MaxmizeWindow(uint32_t windowId) = 0; + virtual WMError MaximizeWindow(uint32_t windowId) = 0; virtual WMError SetWindowLayoutMode(WindowLayoutMode mode) = 0; virtual WMError UpdateProperty(sptr& windowProperty, PropertyChangeAction action) = 0; virtual void RegisterWindowManagerAgent(WindowManagerAgentType type, diff --git a/wmserver/include/zidl/window_manager_proxy.h b/wmserver/include/zidl/window_manager_proxy.h index 3f9eb72a..19ef06e1 100644 --- a/wmserver/include/zidl/window_manager_proxy.h +++ b/wmserver/include/zidl/window_manager_proxy.h @@ -44,7 +44,7 @@ public: void ProcessPointUp(uint32_t windowId) override; void MinimizeAllAppWindows(DisplayId displayId) override; WMError ToggleShownStateForAllAppWindows() override; - WMError MaxmizeWindow(uint32_t windowId) override; + WMError MaximizeWindow(uint32_t windowId) override; WMError SetWindowLayoutMode(WindowLayoutMode mode) override; WMError UpdateProperty(sptr& windowProperty, PropertyChangeAction action) override; diff --git a/wmserver/src/avoid_area_controller.cpp b/wmserver/src/avoid_area_controller.cpp index e0e87a09..444aeae4 100644 --- a/wmserver/src/avoid_area_controller.cpp +++ b/wmserver/src/avoid_area_controller.cpp @@ -46,7 +46,7 @@ void AvoidAreaController::UpdateAvoidNodesMap(DisplayId displayId, bool isAdd) bool AvoidAreaController::IsAvoidAreaNode(const sptr& node) const { if (node == nullptr) { - WLOGFE("IsAvoidAreaNode Failed, node is nullprt"); + WLOGFE("IsAvoidAreaNode Failed, node is nullptr"); return false; } @@ -96,7 +96,7 @@ WMError AvoidAreaController::AvoidControl(const sptr& node, AvoidCon WLOGFE("WinId:%{public}d is added. AvoidControl Add Failed. Type: %{public}u", windowId, type); return WMError::WM_ERROR_INVALID_PARAM; } - // do not update or removew a unexist node + // do not update or remove a non-exist node if (type != AvoidControlType::AVOID_NODE_ADD && iter == avoidNodes->end()) { WLOGFE("WinId:%{public}d not exist. AvoidControl Update or Remove Failed. Type: %{public}u", windowId, type); return WMError::WM_ERROR_INVALID_PARAM; @@ -120,7 +120,7 @@ WMError AvoidAreaController::AvoidControl(const sptr& node, AvoidCon return WMError::WM_ERROR_INVALID_PARAM; } - // get all Area info and notify windowcontainer + // get all Area info and notify window container std::vector avoidAreas = GetAvoidArea(node->GetDisplayId()); DumpAvoidArea(avoidAreas); UseCallbackNotifyAvoidAreaChanged(avoidAreas, node->GetDisplayId()); diff --git a/wmserver/src/display_group_controller.cpp b/wmserver/src/display_group_controller.cpp index e54aa33d..e42cb5cd 100644 --- a/wmserver/src/display_group_controller.cpp +++ b/wmserver/src/display_group_controller.cpp @@ -174,7 +174,7 @@ void DisplayGroupController::UpdateWindowShowingDisplays(const sptr& void DisplayGroupController::UpdateWindowDisplayIdIfNeeded(const sptr& node, const std::vector& curShowingDisplays) { - // current mutiDisplay is only support left-right combination, maxNum is two + // current multi-display is only support left-right combination, maxNum is two DisplayId newDisplayId = node->GetDisplayId(); if (curShowingDisplays.size() == 1) { newDisplayId = *(curShowingDisplays.begin()); @@ -232,7 +232,7 @@ void DisplayGroupController::PreProcessWindowNode(const sptr& node, PreProcessWindowNode(childNode, type); } } - WLOGFI("Current mode is not muti-display"); + WLOGFI("Current mode is not multi-display"); return; } @@ -314,7 +314,7 @@ void DisplayGroupController::MoveNotCrossNodeToDefaultDisplay(const sptr& windowIds) { if (displayId == defaultDisplayId_) { @@ -333,11 +333,11 @@ void DisplayGroupController::ProcessNotCrossNodesOnDestroiedDisplay(DisplayId di if (node->GetDisplayId() != displayId || node->isShowingOnMultiDisplays_) { continue; } - // destroy status and navigati + // destroy status and navigation bar if (node->GetWindowType() == WindowType::WINDOW_TYPE_STATUS_BAR || node->GetWindowType() == WindowType::WINDOW_TYPE_NAVIGATION_BAR) { windowNodeContainer_->DestroyWindowNode(node, windowIds); - WLOGFI("destroy status or navigationbar on destroied display, windowId: %{public}d", + WLOGFI("destroy status or navigation bar on destroyed display, windowId: %{public}d", node->GetWindowId()); continue; } @@ -380,11 +380,11 @@ void DisplayGroupController::ProcessDisplayDestroy(DisplayId defaultDisplayId, s windowNodeContainer_->GetAvoidController()->UpdateAvoidNodesMap(displayId, false); // delete nodes and map element of deleted display - ProcessNotCrossNodesOnDestroiedDisplay(displayId, windowIds); + ProcessNotCrossNodesOnDestroyedDisplay(displayId, windowIds); // modify RSTree and window tree of displayGroup for cross-display nodes ProcessCrossNodes(defaultDisplayId, DisplayStateChangeType::DESTROY); UpdateDisplayGroupWindowTree(); - ClearMapOfDestroiedDisplay(displayId); + ClearMapOfDestroyedDisplay(displayId); windowNodeContainer_->GetLayoutPolicy()->ProcessDisplayDestroy(displayId, displayRectMap); } @@ -423,7 +423,7 @@ void DisplayGroupController::ProcessDisplaySizeChangeOrRotation(DisplayId defaul windowNodeContainer_->GetLayoutPolicy()->ProcessDisplaySizeChangeOrRotation(displayId, displayRectMap); } -void DisplayGroupController::ClearMapOfDestroiedDisplay(DisplayId displayId) +void DisplayGroupController::ClearMapOfDestroyedDisplay(DisplayId displayId) { sysBarTintMaps_.erase(displayId); sysBarNodeMaps_.erase(displayId); diff --git a/wmserver/src/input_window_monitor.cpp b/wmserver/src/input_window_monitor.cpp index 3159b76d..cb53ec26 100644 --- a/wmserver/src/input_window_monitor.cpp +++ b/wmserver/src/input_window_monitor.cpp @@ -96,7 +96,7 @@ void InputWindowMonitor::UpdateDisplayInfo(const sptr& displayInfo, if (displayInfo->GetRotation() == Rotation::ROTATION_90 || displayInfo->GetRotation() == Rotation::ROTATION_270) { std::swap(displayWidth, displayHeight); } - MMI::DisplayInfo diplay = { + MMI::DisplayInfo display = { .id = static_cast(displayInfo->GetDisplayId()), .x = displayInfo->GetOffsetX(), .y = displayInfo->GetOffsetY(), @@ -107,13 +107,13 @@ void InputWindowMonitor::UpdateDisplayInfo(const sptr& displayInfo, .direction = GetDisplayDirectionForMmi(displayInfo->GetRotation()), }; auto displayIter = std::find_if(displayInfoVector.begin(), displayInfoVector.end(), - [&diplay](MMI::DisplayInfo& displayInfoTmp) { - return displayInfoTmp.id == diplay.id; + [&display](MMI::DisplayInfo& displayInfoTmp) { + return displayInfoTmp.id == display.id; }); if (displayIter != displayInfoVector.end()) { - *displayIter = diplay; + *displayIter = display; } else { - displayInfoVector.emplace_back(diplay); + displayInfoVector.emplace_back(display); } } diff --git a/wmserver/src/remote_animation.cpp b/wmserver/src/remote_animation.cpp index 0a81be72..de2d791b 100644 --- a/wmserver/src/remote_animation.cpp +++ b/wmserver/src/remote_animation.cpp @@ -115,7 +115,7 @@ WMError RemoteAnimation::NotifyAnimationTransition(sptr sr WLOGFE("RSWindowAnimation: no startingWindow for dst window id:%{public}u!", dstNode->GetWindowId()); return WMError::WM_ERROR_NO_REMOTE_ANIMATION; } - WLOGFI("RSWindowAnimation: nofity animation transition with dst currId:%{public}u!", dstNode->GetWindowId()); + WLOGFI("RSWindowAnimation: notify animation transition with dst currId:%{public}u!", dstNode->GetWindowId()); sptr finishedCallback = new(std::nothrow) RSWindowAnimationFinishedCallback( []() { WLOGFI("RSWindowAnimation: on finish transition with minimizeAll!"); @@ -173,7 +173,7 @@ WMError RemoteAnimation::NotifyAnimationMinimize(sptr srcI if (srcTarget == nullptr) { return WMError::WM_ERROR_NO_MEM; } - WLOGFI("RSWindowAnimation: nofity animation minimize Id:%{public}u!", srcNode->GetWindowId()); + WLOGFI("RSWindowAnimation: notify animation minimize Id:%{public}u!", srcNode->GetWindowId()); srcNode->isPlayAnimationHide_ = true; wptr weak = srcNode; auto minimizeFunc = [weak]() { @@ -203,7 +203,7 @@ WMError RemoteAnimation::NotifyAnimationClose(sptr srcInfo if (srcTarget == nullptr) { return WMError::WM_ERROR_NO_MEM; } - WLOGFI("RSWindowAnimation: nofity animation close id:%{public}u!", srcNode->GetWindowId()); + WLOGFI("RSWindowAnimation: notify animation close id:%{public}u!", srcNode->GetWindowId()); srcNode->isPlayAnimationHide_ = true; wptr weak = srcNode; auto closeFunc = [weak, event]() { diff --git a/wmserver/src/window_controller.cpp b/wmserver/src/window_controller.cpp index 33b382f5..acec6c78 100644 --- a/wmserver/src/window_controller.cpp +++ b/wmserver/src/window_controller.cpp @@ -35,7 +35,7 @@ namespace OHOS { namespace Rosen { namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowController"}; - constexpr uint32_t TOIUCH_HOT_AREA_MAX_NUM = 10; + constexpr uint32_t TOUCH_HOT_AREA_MAX_NUM = 10; } uint32_t WindowController::GenWindowId() @@ -622,7 +622,7 @@ WMError WindowController::ProcessPointDown(uint32_t windowId, bool isStartDrag) return WMError::WM_ERROR_NULLPTR; } if (!node->currentVisibility_) { - WLOGFE("this window is not visibile and not in window tree, windowId: %{public}u", windowId); + WLOGFE("this window is not visible and not in window tree, windowId: %{public}u", windowId); return WMError::WM_ERROR_INVALID_OPERATION; } @@ -690,13 +690,13 @@ WMError WindowController::ToggleShownStateForAllAppWindows() return windowRoot_->ToggleShownStateForAllAppWindows(); } -WMError WindowController::MaxmizeWindow(uint32_t windowId) +WMError WindowController::MaximizeWindow(uint32_t windowId) { WMError ret = SetWindowMode(windowId, WindowMode::WINDOW_MODE_FULLSCREEN); if (ret != WMError::WM_OK) { return ret; } - ret = windowRoot_->MaxmizeWindow(windowId); + ret = windowRoot_->MaximizeWindow(windowId); FlushWindowInfo(windowId); return ret; } @@ -873,7 +873,7 @@ WMError WindowController::UpdateTouchHotAreas(const sptr& node, cons node->GetWindowId(), static_cast(rects.size()), oss.str().c_str()); Rect windowRect = node->GetWindowRect(); std::vector hotAreas; - if (rects.size() > TOIUCH_HOT_AREA_MAX_NUM || !WindowHelper::CalculateTouchHotAreas(windowRect, rects, hotAreas)) { + if (rects.size() > TOUCH_HOT_AREA_MAX_NUM || !WindowHelper::CalculateTouchHotAreas(windowRect, rects, hotAreas)) { return WMError::WM_ERROR_INVALID_PARAM; } node->GetWindowProperty()->SetTouchHotAreas(rects); diff --git a/wmserver/src/window_inner_manager.cpp b/wmserver/src/window_inner_manager.cpp index b8fe03b4..5cddc9f0 100644 --- a/wmserver/src/window_inner_manager.cpp +++ b/wmserver/src/window_inner_manager.cpp @@ -80,13 +80,13 @@ void WindowInnerManager::Stop() void WindowInnerManager::HandleCreateWindow(std::string name, WindowType type, Rect rect) { auto dialogCallback = [this](int32_t id, const std::string& event, const std::string& params) { - if (params == "EVENT_CANCLE_CODE") { + if (params == "EVENT_CANCEL_CODE") { Ace::UIServiceMgrClient::GetInstance()->CancelDialog(id); } }; Ace::UIServiceMgrClient::GetInstance()->ShowDialog(name, dividerParams_, type, rect.posX_, rect.posY_, rect.width_, rect.height_, dialogCallback, &dialogId_); - WLOGFI("create inner window id: %{public}d succes", dialogId_); + WLOGFI("create inner window id: %{public}d success", dialogId_); return; } diff --git a/wmserver/src/window_layout_policy.cpp b/wmserver/src/window_layout_policy.cpp index 68929bd1..04bc5414 100644 --- a/wmserver/src/window_layout_policy.cpp +++ b/wmserver/src/window_layout_policy.cpp @@ -85,7 +85,7 @@ void WindowLayoutPolicy::LimitWindowToBottomRightCorner(const sptr& void WindowLayoutPolicy::UpdateDisplayGroupRect() { Rect newDisplayGroupRect = { 0, 0, 0, 0 }; - // current mutiDisplay is only support left-right combination, maxNum is two + // current multi-display is only support left-right combination, maxNum is two for (auto& elem : displayGroupInfo_->GetAllDisplayRects()) { newDisplayGroupRect.posX_ = std::min(displayGroupRect_.posX_, elem.second.posX_); newDisplayGroupRect.posY_ = std::min(displayGroupRect_.posY_, elem.second.posY_); @@ -151,10 +151,10 @@ void WindowLayoutPolicy::UpdateMultiDisplayFlag() { if (displayGroupInfo_->GetAllDisplayRects().size() > 1) { isMultiDisplay_ = true; - WLOGFI("current mode is muti-display"); + WLOGFI("current mode is multi-display"); } else { isMultiDisplay_ = false; - WLOGFI("current mode is not muti-display"); + WLOGFI("current mode is not multi-display"); } } @@ -534,8 +534,8 @@ FloatingWindowLimitsConfig WindowLayoutPolicy::GetCustomizedLimitsConfig(const R uint32_t configuredMaxHeight = static_cast(floatingWindowLimitsConfig_.maxHeight_ * virtualPixelRatio); uint32_t configuredMinWidth = static_cast(floatingWindowLimitsConfig_.minWidth_ * virtualPixelRatio); uint32_t configuredMinHeight = static_cast(floatingWindowLimitsConfig_.minHeight_ * virtualPixelRatio); - float configuerdMaxRatio = floatingWindowLimitsConfig_.maxRatio_; - float configuerdMinRatio = floatingWindowLimitsConfig_.minRatio_; + float configuredMaxRatio = floatingWindowLimitsConfig_.maxRatio_; + float configuredMinRatio = floatingWindowLimitsConfig_.minRatio_; // calculate new limit size if (systemLimits.minWidth_ <= configuredMaxWidth && configuredMaxWidth <= systemLimits.maxWidth_) { @@ -556,11 +556,11 @@ FloatingWindowLimitsConfig WindowLayoutPolicy::GetCustomizedLimitsConfig(const R static_cast(newLimitConfig.minHeight_); newLimitConfig.minRatio_ = static_cast(newLimitConfig.minWidth_) / static_cast(newLimitConfig.maxHeight_); - if (newLimitConfig.minRatio_ <= configuerdMaxRatio && configuerdMaxRatio <= newLimitConfig.maxRatio_) { - newLimitConfig.maxRatio_ = configuerdMaxRatio; + if (newLimitConfig.minRatio_ <= configuredMaxRatio && configuredMaxRatio <= newLimitConfig.maxRatio_) { + newLimitConfig.maxRatio_ = configuredMaxRatio; } - if (newLimitConfig.minRatio_ <= configuerdMinRatio && configuerdMinRatio <= newLimitConfig.maxRatio_) { - newLimitConfig.minRatio_ = configuerdMinRatio; + if (newLimitConfig.minRatio_ <= configuredMinRatio && configuredMinRatio <= newLimitConfig.maxRatio_) { + newLimitConfig.minRatio_ = configuredMinRatio; } // recalculate limit size by new ratio @@ -583,7 +583,7 @@ FloatingWindowLimitsConfig WindowLayoutPolicy::GetCustomizedLimitsConfig(const R return newLimitConfig; } -void WindowLayoutPolicy::UpdateFloatongWindowSizeForStretchableWindow(const sptr& node, +void WindowLayoutPolicy::UpdateFloatingWindowSizeForStretchableWindow(const sptr& node, const Rect& displayRect, Rect& winRect) const { if (node->GetWindowSizeChangeReason() == WindowSizeChangeReason::DRAG) { @@ -707,7 +707,7 @@ void WindowLayoutPolicy::LimitFloatingWindowSize(const sptr& node, if (node->GetStretchable() && WindowHelper::IsMainFloatingWindow(node->GetWindowType(), node->GetWindowMode())) { - UpdateFloatongWindowSizeForStretchableWindow(node, displayRect, winRect); + UpdateFloatingWindowSizeForStretchableWindow(node, displayRect, winRect); } // fix size in case of moving window when dragging @@ -811,7 +811,7 @@ void WindowLayoutPolicy::LimitWindowPositionWhenInitRectOrMove(const sptr(WINDOW_TITLE_BAR_HEIGHT * virtualPixelRatio); Rect limitRect; - // if is corss-display window, the limit rect should be full limitRect + // if is cross-display window, the limit rect should be full limitRect if (node->isShowingOnMultiDisplays_) { limitRect = displayGroupLimitRect_; } else { @@ -994,7 +994,7 @@ void WindowLayoutPolicy::SetFloatingWindowLimitsConfig(const FloatingWindowLimit Rect WindowLayoutPolicy::GetInitalDividerRect(DisplayId displayId) const { - return IVALID_EMPTY_RECT; + return INVALID_EMPTY_RECT; } } } diff --git a/wmserver/src/window_layout_policy_cascade.cpp b/wmserver/src/window_layout_policy_cascade.cpp index a38fd464..5b5bc0a1 100644 --- a/wmserver/src/window_layout_policy_cascade.cpp +++ b/wmserver/src/window_layout_policy_cascade.cpp @@ -301,7 +301,7 @@ void WindowLayoutPolicyCascade::UpdateLayoutRect(const sptr& node) if (!floatingWindow) { // fullscreen window winRect = limitRect; } else { // floating window - if (subWindow && parentLimit) { // subwidow and limited by parent + if (subWindow && parentLimit) { // subwindow and limited by parent limitRect = node->parent_->GetWindowRect(); UpdateFloatingLayoutRect(limitRect, winRect); } diff --git a/wmserver/src/window_layout_policy_tile.cpp b/wmserver/src/window_layout_policy_tile.cpp index b0cbcbda..87423252 100644 --- a/wmserver/src/window_layout_policy_tile.cpp +++ b/wmserver/src/window_layout_policy_tile.cpp @@ -271,7 +271,7 @@ void WindowLayoutPolicyTile::UpdateLayoutRect(const sptr& node) WLOGFE("window property is nullptr."); return; } - auto decorEnbale = property->GetDecorEnable(); + auto decorEnable = property->GetDecorEnable(); bool needAvoid = (flags & static_cast(WindowFlag::WINDOW_FLAG_NEED_AVOID)); bool parentLimit = (flags & static_cast(WindowFlag::WINDOW_FLAG_PARENT_LIMIT)); bool subWindow = WindowHelper::IsSubWindow(type); @@ -283,7 +283,7 @@ void WindowLayoutPolicyTile::UpdateLayoutRect(const sptr& node) WLOGFI("Id:%{public}u, avoid:%{public}d parLimit:%{public}d floating:%{public}d, sub:%{public}d, " \ "deco:%{public}d, type:%{public}u, requestRect:[%{public}d, %{public}d, %{public}u, %{public}u]", - node->GetWindowId(), needAvoid, parentLimit, floatingWindow, subWindow, decorEnbale, + node->GetWindowId(), needAvoid, parentLimit, floatingWindow, subWindow, decorEnable, static_cast(type), winRect.posX_, winRect.posY_, winRect.width_, winRect.height_); if (needAvoid) { limitRect = limitRectMap_[node->GetDisplayId()]; @@ -292,7 +292,7 @@ void WindowLayoutPolicyTile::UpdateLayoutRect(const sptr& node) if (!floatingWindow) { // fullscreen window winRect = limitRect; } else { // floating window - if (subWindow && parentLimit) { // subwidow and limited by parent + if (subWindow && parentLimit) { // subwindow and limited by parent limitRect = node->parent_->GetWindowRect(); UpdateFloatingLayoutRect(limitRect, winRect); } diff --git a/wmserver/src/window_manager_service.cpp b/wmserver/src/window_manager_service.cpp index a9915a95..9f5efcdd 100644 --- a/wmserver/src/window_manager_service.cpp +++ b/wmserver/src/window_manager_service.cpp @@ -541,11 +541,11 @@ WMError WindowManagerService::ToggleShownStateForAllAppWindows() return WMError::WM_OK; } -WMError WindowManagerService::MaxmizeWindow(uint32_t windowId) +WMError WindowManagerService::MaximizeWindow(uint32_t windowId) { return wmsTaskLooper_->ScheduleTask([this, windowId]() { - WM_SCOPED_TRACE("wms:MaxmizeWindow"); - return windowController_->MaxmizeWindow(windowId); + WM_SCOPED_TRACE("wms:MaximizeWindow"); + return windowController_->MaximizeWindow(windowId); }).get(); } diff --git a/wmserver/src/window_node_container.cpp b/wmserver/src/window_node_container.cpp index 8e796af3..3a3e752c 100644 --- a/wmserver/src/window_node_container.cpp +++ b/wmserver/src/window_node_container.cpp @@ -55,14 +55,14 @@ WindowNodeContainer::WindowNodeContainer(const sptr& displayInfo, S displayGroupController_->InitNewDisplay(displayId); // init layout policy - layoutPolicys_[WindowLayoutMode::CASCADE] = new WindowLayoutPolicyCascade(displayGroupInfo_, + layoutPolicies_[WindowLayoutMode::CASCADE] = new WindowLayoutPolicyCascade(displayGroupInfo_, displayGroupController_->displayGroupWindowTree_); - layoutPolicys_[WindowLayoutMode::TILE] = new WindowLayoutPolicyTile(displayGroupInfo_, + layoutPolicies_[WindowLayoutMode::TILE] = new WindowLayoutPolicyTile(displayGroupInfo_, displayGroupController_->displayGroupWindowTree_); - layoutPolicy_ = layoutPolicys_[WindowLayoutMode::CASCADE]; + layoutPolicy_ = layoutPolicies_[WindowLayoutMode::CASCADE]; layoutPolicy_->Launch(); - Rect initalDividerRect = layoutPolicys_[WindowLayoutMode::CASCADE]->GetInitalDividerRect(displayId); + Rect initalDividerRect = layoutPolicies_[WindowLayoutMode::CASCADE]->GetInitalDividerRect(displayId); displayGroupController_->SetInitalDividerRect(displayId, initalDividerRect); // init avoidAreaController UpdateAvoidAreaFunc func = std::bind(&WindowNodeContainer::OnAvoidAreaChange, this, @@ -300,7 +300,7 @@ WMError WindowNodeContainer::RemoveWindowNode(sptr& node) UpdateWindowVisibilityInfos(infos); DumpScreenWindowTree(); NotifyAccessibilityWindowInfo(node, WindowUpdateType::WINDOW_UPDATE_REMOVED); - RcoveryScreenDefaultOrientationIfNeed(node->GetDisplayId()); + RecoverScreenDefaultOrientationIfNeed(node->GetDisplayId()); if (node->GetWindowType() == WindowType::WINDOW_TYPE_KEYGUARD) { isScreenLocked_ = false; } @@ -447,7 +447,7 @@ bool WindowNodeContainer::UpdateRSTree(sptr& node, DisplayId display return true; } -void WindowNodeContainer::RcoveryScreenDefaultOrientationIfNeed(DisplayId displayId) +void WindowNodeContainer::RecoverScreenDefaultOrientationIfNeed(DisplayId displayId) { if (displayGroupController_->displayGroupWindowTree_[displayId][WindowRootNodeType::APP_WINDOW_NODE]->empty()) { WLOGFI("appWindowNode_ child is empty in display %{public}" PRIu64"", displayId); @@ -667,7 +667,7 @@ sptr WindowNodeContainer::GetAvoidController() const return avoidController_; } -sptr WindowNodeContainer::GetMutiDisplayController() const +sptr WindowNodeContainer::GetMultiDisplayController() const { return displayGroupController_; } @@ -923,7 +923,7 @@ void WindowNodeContainer::NotifyDockWindowStateChanged(sptr& node, b if (windowNode->GetWindowId() == node->GetWindowId()) { continue; } - if (!WindowHelper::IsFloatintWindow(windowNode->GetWindowMode())) { + if (!WindowHelper::IsFloatingWindow(windowNode->GetWindowMode())) { return; } } @@ -1526,7 +1526,7 @@ WMError WindowNodeContainer::SwitchLayoutPolicy(WindowLayoutMode dstMode, Displa } layoutMode_ = dstMode; layoutPolicy_->Clean(); - layoutPolicy_ = layoutPolicys_[dstMode]; + layoutPolicy_ = layoutPolicies_[dstMode]; layoutPolicy_->Launch(); DumpScreenWindowTree(); } else { @@ -1817,7 +1817,7 @@ WMError WindowNodeContainer::SetWindowMode(sptr& node, WindowMode ds } windowPair->UpdateIfSplitRelated(node); if (WindowHelper::IsMainWindow(node->GetWindowType())) { - if (WindowHelper::IsFloatintWindow(node->GetWindowMode())) { + if (WindowHelper::IsFloatingWindow(node->GetWindowMode())) { NotifyDockWindowStateChanged(node, true); } else { NotifyDockWindowStateChanged(node, false); diff --git a/wmserver/src/window_pair.cpp b/wmserver/src/window_pair.cpp index c6a45cb8..095b4add 100644 --- a/wmserver/src/window_pair.cpp +++ b/wmserver/src/window_pair.cpp @@ -226,7 +226,7 @@ bool WindowPair::IsSplitRelated(sptr& node) const std::vector> WindowPair::GetOrderedPair(sptr& node) { - WLOGI("Get piared node in Z order"); + WLOGI("Get paired node in Z order"); std::vector> orderedPair; if (node == nullptr || Find(node) == nullptr) { return orderedPair; @@ -368,7 +368,7 @@ void WindowPair::UpdateWindowPairStatus() status_ == WindowPairStatus::STATUS_PAIRING) { // create divider WindowInnerManager::GetInstance().CreateWindow("dialog_divider_ui", WindowType::WINDOW_TYPE_DOCK_SLICE, - initalDivderRect_); + initalDividerRect_); } else if ((prevStatus == WindowPairStatus::STATUS_PAIRED_DONE || prevStatus == WindowPairStatus::STATUS_PAIRING) && (status_ != WindowPairStatus::STATUS_PAIRED_DONE && status_ != WindowPairStatus::STATUS_PAIRING)) { // clear pair @@ -494,7 +494,7 @@ void WindowPair::SetAllAppWindowsRestoring(bool isAllAppWindowsRestoring) void WindowPair::SetInitalDividerRect(const Rect& rect) { - initalDivderRect_ = rect; + initalDividerRect_ = rect; } } // namespace Rosen } // namespace OHOS \ No newline at end of file diff --git a/wmserver/src/window_root.cpp b/wmserver/src/window_root.cpp index 8694e504..4f7b1263 100644 --- a/wmserver/src/window_root.cpp +++ b/wmserver/src/window_root.cpp @@ -89,7 +89,7 @@ sptr WindowRoot::GetOrCreateWindowNodeContainer(DisplayId d sptr WindowRoot::CreateWindowNodeContainer(sptr displayInfo) { if (displayInfo == nullptr || !CheckDisplayInfo(displayInfo)) { - WLOGFE("get display failed or get invailed display info"); + WLOGFE("get display failed or get invalid display info"); return nullptr; } @@ -331,7 +331,7 @@ WMError WindowRoot::ToggleShownStateForAllAppWindows() return res; } -WMError WindowRoot::MaxmizeWindow(uint32_t windowId) +WMError WindowRoot::MaximizeWindow(uint32_t windowId) { auto node = GetWindowNode(windowId); if (node == nullptr) { @@ -988,7 +988,7 @@ void WindowRoot::ProcessExpandDisplayCreate(DisplayId defaultDisplayId, sptr& displayRectMap) { if (displayInfo == nullptr || !CheckDisplayInfo(displayInfo)) { - WLOGFE("get display failed or get invailed display info"); + WLOGFE("get display failed or get invalid display info"); return; } DisplayId displayId = displayInfo->GetDisplayId(); @@ -999,7 +999,7 @@ void WindowRoot::ProcessExpandDisplayCreate(DisplayId defaultDisplayId, sptrGetMutiDisplayController()->ProcessDisplayCreate(defaultDisplayId, displayInfo, displayRectMap); + container->GetMultiDisplayController()->ProcessDisplayCreate(defaultDisplayId, displayInfo, displayRectMap); WLOGFI("[Display Create] Container exist, add new display, displayId: %{public}" PRIu64"", displayId); } @@ -1111,20 +1111,20 @@ void WindowRoot::ProcessDisplayDestroy(DisplayId defaultDisplayId, sptr needDestoryWindows; + std::vector needDestroyWindows; auto displayRectMap = GetAllDisplayRectsByDisplayInfo(displayInfoMap); // erase displayId in displayRectMap auto displayRectIter = displayRectMap.find(displayId); displayRectMap.erase(displayRectIter); - container->GetMutiDisplayController()->ProcessDisplayDestroy( - defaultDisplayId, displayInfo, displayRectMap, needDestoryWindows); - for (auto id : needDestoryWindows) { + container->GetMultiDisplayController()->ProcessDisplayDestroy( + defaultDisplayId, displayInfo, displayRectMap, needDestroyWindows); + for (auto id : needDestroyWindows) { auto node = GetWindowNode(id); if (node != nullptr) { DestroyWindowInner(node); } } - // move window which is not showing on destroied display to default display + // move window which is not showing on destroyed display to default display MoveNotShowingWindowToDefaultDisplay(defaultDisplayId, displayId); WLOGFI("[Display Destroy] displayId: %{public}" PRIu64" ", displayId); } @@ -1153,7 +1153,7 @@ void WindowRoot::ProcessDisplayChange(DisplayId defaultDisplayId, sptrGetMutiDisplayController()->ProcessDisplayChange(defaultDisplayId, displayInfo, displayRectMap, type); + container->GetMultiDisplayController()->ProcessDisplayChange(defaultDisplayId, displayInfo, displayRectMap, type); } float WindowRoot::GetVirtualPixelRatio(DisplayId displayId) const @@ -1209,7 +1209,7 @@ void WindowRoot::SetSplitRatios(const std::vector& splitRatioNumbers) } std::sort(splitRatios.begin(), splitRatios.end()); auto iter = std::unique(splitRatios.begin(), splitRatios.end()); - splitRatios.erase(iter, splitRatios.end()); // remove duplitcate ratios + splitRatios.erase(iter, splitRatios.end()); // remove duplicate ratios } void WindowRoot::SetExitSplitRatios(const std::vector& exitSplitRatios) diff --git a/wmserver/src/zidl/window_manager_proxy.cpp b/wmserver/src/zidl/window_manager_proxy.cpp index dd353a15..0a7b7dcf 100644 --- a/wmserver/src/zidl/window_manager_proxy.cpp +++ b/wmserver/src/zidl/window_manager_proxy.cpp @@ -204,7 +204,7 @@ WMError WindowManagerProxy::SetAlpha(uint32_t windowId, float alpha) WLOGFE("Write alpha failed"); return WMError::WM_ERROR_IPC_FAILED; } - if (Remote()->SendRequest(static_cast(WindowManagerMessage::TRANS_ID_SET_APLPHA), + if (Remote()->SendRequest(static_cast(WindowManagerMessage::TRANS_ID_SET_ALPHA), data, reply, option) != ERR_NONE) { return WMError::WM_ERROR_IPC_FAILED; } @@ -432,7 +432,7 @@ WMError WindowManagerProxy::ToggleShownStateForAllAppWindows() return static_cast(ret); } -WMError WindowManagerProxy::MaxmizeWindow(uint32_t windowId) +WMError WindowManagerProxy::MaximizeWindow(uint32_t windowId) { MessageParcel data; MessageParcel reply; @@ -445,7 +445,7 @@ WMError WindowManagerProxy::MaxmizeWindow(uint32_t windowId) WLOGFE("Write windowId failed"); return WMError::WM_ERROR_IPC_FAILED; } - if (Remote()->SendRequest(static_cast(WindowManagerMessage::TRANS_ID_MAXMIZE_WINDOW), + if (Remote()->SendRequest(static_cast(WindowManagerMessage::TRANS_ID_MAXIMIZE_WINDOW), data, reply, option) != ERR_NONE) { return WMError::WM_ERROR_IPC_FAILED; } @@ -542,7 +542,7 @@ WMError WindowManagerProxy::GetAccessibilityWindowInfo(sptrSendRequest(static_cast(WindowManagerMessage::TRANS_ID_GET_ACCCESSIBILITY_WIDDOW_INFO_ID), + if (Remote()->SendRequest(static_cast(WindowManagerMessage::TRANS_ID_GET_ACCESSIBILITY_WINDOW_INFO_ID), data, reply, option) != ERR_NONE) { return WMError::WM_ERROR_IPC_FAILED; } diff --git a/wmserver/src/zidl/window_manager_stub.cpp b/wmserver/src/zidl/window_manager_stub.cpp index 3b494a52..86f7e5c8 100644 --- a/wmserver/src/zidl/window_manager_stub.cpp +++ b/wmserver/src/zidl/window_manager_stub.cpp @@ -81,7 +81,7 @@ int32_t WindowManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, M reply.WriteInt32(static_cast(errCode)); break; } - case WindowManagerMessage::TRANS_ID_SET_APLPHA: { + case WindowManagerMessage::TRANS_ID_SET_ALPHA: { uint32_t windowId = data.ReadUint32(); float alpha = data.ReadFloat(); WMError errCode = SetAlpha(windowId, alpha); @@ -148,8 +148,8 @@ int32_t WindowManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, M reply.WriteInt32(static_cast(errCode)); break; } - case WindowManagerMessage::TRANS_ID_MAXMIZE_WINDOW: { - MaxmizeWindow(data.ReadUint32()); + case WindowManagerMessage::TRANS_ID_MAXIMIZE_WINDOW: { + MaximizeWindow(data.ReadUint32()); break; } case WindowManagerMessage::TRANS_ID_UPDATE_LAYOUT_MODE: { @@ -166,7 +166,7 @@ int32_t WindowManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, M reply.WriteInt32(static_cast(errCode)); break; } - case WindowManagerMessage::TRANS_ID_GET_ACCCESSIBILITY_WIDDOW_INFO_ID: { + case WindowManagerMessage::TRANS_ID_GET_ACCESSIBILITY_WINDOW_INFO_ID: { sptr windowInfo = data.ReadParcelable(); WMError errCode = GetAccessibilityWindowInfo(windowInfo); reply.WriteParcelable(windowInfo); From bf3476fe439362c8449f92ec3f532224d6ac0026 Mon Sep 17 00:00:00 2001 From: zhoushicheng Date: Mon, 20 Jun 2022 16:51:15 +0800 Subject: [PATCH 09/81] aafwk->ability_runtime Signed-off-by: zhoushicheng Change-Id: I8dc462c728868468e629af4a33ee81122ac844a2 --- windowmanager_aafwk.gni | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/windowmanager_aafwk.gni b/windowmanager_aafwk.gni index 3b87d4be..9d20e02d 100644 --- a/windowmanager_aafwk.gni +++ b/windowmanager_aafwk.gni @@ -14,5 +14,5 @@ aafwk_inner_api_path = "//foundation/ability/ability_runtime/interfaces/inner_api" aafwk_kits_path = "//foundation/ability/ability_runtime/frameworks/kits" -aafwk_path = "//foundation/ability/ability_runtime" +ability_runtime_path = "//foundation/ability/ability_runtime" aafwk_services_path = "//foundation/ability/ability_runtime/services" From e14ff63f53371b7796fa55b0d517353e5b263504 Mon Sep 17 00:00:00 2001 From: xpeng Date: Tue, 21 Jun 2022 20:55:28 +0800 Subject: [PATCH 10/81] Add interface to set window's requested orientation Signed-off-by: xpeng Change-Id: Ic98ae81d9cb5284145337e8d02e9fab8f6fa6d67 --- dmserver/src/screen_rotation_controller.cpp | 8 +- .../screen_runtime/napi/js_screen_manager.cpp | 6 +- .../napi/window_runtime/api/@ohos.window.d.ts | 34 ++++++++ .../window_runtime/window_napi/js_window.cpp | 77 +++++++++++++++++-- .../window_runtime/window_napi/js_window.h | 4 +- .../window_napi/js_window_utils.h | 30 ++++++++ 6 files changed, 147 insertions(+), 12 deletions(-) diff --git a/dmserver/src/screen_rotation_controller.cpp b/dmserver/src/screen_rotation_controller.cpp index ca8eb8e5..e55c6f9c 100644 --- a/dmserver/src/screen_rotation_controller.cpp +++ b/dmserver/src/screen_rotation_controller.cpp @@ -23,9 +23,9 @@ namespace OHOS { namespace Rosen { namespace { - constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "DisplaySensorController"}; + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "ScreenRotationController"}; constexpr int64_t ORIENTATION_SENSOR_SAMPING_RATE = 200000000; // 200ms - constexpr int64_t ORIENTATION_SENSOR_REPORTING_RATE = 200000000; // 200ms + constexpr int64_t ORIENTATION_SENSOR_REPORTING_RATE = 0; constexpr long ORIENTATION_SENSOR_CALLBACK_TIME_INTERVAL = 200; // 200ms constexpr int VALID_INCLINATION_ANGLE_THRESHOLD_COEFFICIENT = 3; } @@ -200,7 +200,7 @@ Rotation ScreenRotationController::ProcessAutoRotationPortraitOrientation(Rotati if (sensorRotation == Rotation::ROTATION_0 || sensorRotation == Rotation::ROTATION_180) { return sensorRotation; } - return currentDisplayRotation_; + return Rotation::ROTATION_0; } Rotation ScreenRotationController::ProcessAutoRotationLandscapeOrientation(Rotation sensorRotation) @@ -208,7 +208,7 @@ Rotation ScreenRotationController::ProcessAutoRotationLandscapeOrientation(Rotat if (sensorRotation == Rotation::ROTATION_90 || sensorRotation == Rotation::ROTATION_270) { return sensorRotation; } - return currentDisplayRotation_; + return Rotation::ROTATION_90; } void ScreenRotationController::SetScreenRotation(Rotation targetRotation) diff --git a/interfaces/kits/napi/screen_runtime/napi/js_screen_manager.cpp b/interfaces/kits/napi/screen_runtime/napi/js_screen_manager.cpp index 31798101..8d90cc1b 100644 --- a/interfaces/kits/napi/screen_runtime/napi/js_screen_manager.cpp +++ b/interfaces/kits/napi/screen_runtime/napi/js_screen_manager.cpp @@ -629,7 +629,11 @@ NativeValue* OnIsScreenRotationLocked(NativeEngine& engine, NativeCallbackInfo& errCode = DMError::DM_ERROR_INVALID_PARAM; } AsyncTask::CompleteCallback complete = - [this](NativeEngine& engine, AsyncTask& task, int32_t status) { + [errCode](NativeEngine& engine, AsyncTask& task, int32_t status) { + if (errCode != DMError::DM_OK) { + task.Reject(engine, CreateJsError(engine, static_cast(errCode), "Invalidate params.")); + return; + } bool isLocked = SingletonContainer::Get().IsScreenRotationLocked(); task.Resolve(engine, CreateJsValue(engine, isLocked)); }; diff --git a/interfaces/kits/napi/window_runtime/api/@ohos.window.d.ts b/interfaces/kits/napi/window_runtime/api/@ohos.window.d.ts index ef6cea81..a17bdacd 100644 --- a/interfaces/kits/napi/window_runtime/api/@ohos.window.d.ts +++ b/interfaces/kits/napi/window_runtime/api/@ohos.window.d.ts @@ -918,6 +918,20 @@ declare namespace window { */ setTransparent(isTransparent: boolean, callback: AsyncCallback): void; + /** + * Set the requested orientation config of a window + * @param orientation the orientation config of a window + * @since 9 + */ + setRequestedOrientation(orientation: Orientation): Promise; + + /** + * Set the requested orientation config of a window + * @param orientation the orientation config of a window + * @since 9 + */ + setRequestedOrientation(orientation: Orientation, callback: AsyncCallback): void; + /** * disable window decoration. It must be called before loadContent. * @systemapi @@ -1043,6 +1057,26 @@ declare namespace window { */ off(eventType: 'windowStageEvent', callback?: Callback): void; } + + /** + * screen orientation + * @syscap SystemCapability.WindowManager.WindowManager.Core + * @since 9 + */ + enum Orientation { + UNSPECIFIED = 0, + PORTRAIT = 1, + LANDSCAPE = 2, + PORTRAIT_INVERTED = 3, + LANDSCAPE_INVERTED = 4, + AUTO_ROTATION = 5, + AUTO_ROTATION_PORTRAIT = 6, + AUTO_ROTATION_LANDSCAPE = 7, + AUTO_ROTATION_RESTRICTED = 8, + AUTO_ROTATION_PORTRAIT_RESTRICTED = 9, + AUTO_ROTATION_LANDSCAPE_RESTRICTED = 10, + LOCKED = 11, + } } export default window; diff --git a/interfaces/kits/napi/window_runtime/window_napi/js_window.cpp b/interfaces/kits/napi/window_runtime/window_napi/js_window.cpp index da1b18c5..41c1e6e6 100644 --- a/interfaces/kits/napi/window_runtime/window_napi/js_window.cpp +++ b/interfaces/kits/napi/window_runtime/window_napi/js_window.cpp @@ -271,6 +271,13 @@ NativeValue* JsWindow::SetCallingWindow(NativeEngine* engine, NativeCallbackInfo return (me != nullptr) ? me->OnSetCallingWindow(*engine, *info) : nullptr; } +NativeValue* JsWindow::SetRequestedOrientation(NativeEngine* engine, NativeCallbackInfo* info) +{ + WLOGFI("[NAPI]SetRequestedOrientation"); + JsWindow* me = CheckParamsAndGetThis(engine, info); + return (me != nullptr) ? me->OnSetRequestedOrientation(*engine, *info) : nullptr; +} + NativeValue* JsWindow::DisableWindowDecor(NativeEngine* engine, NativeCallbackInfo* info) { WLOGFI("[NAPI]DisableWindowDecor"); @@ -1023,6 +1030,58 @@ NativeValue* JsWindow::OnIsShowing(NativeEngine& engine, NativeCallbackInfo& inf return result; } +NativeValue* JsWindow::OnSetRequestedOrientation(NativeEngine& engine, NativeCallbackInfo& info) +{ + WMError errCode = WMError::WM_OK; + Orientation requestedOrientation = Orientation::UNSPECIFIED; + if (info.argc < 1 || info.argc > 2) { // 2: maximum params num + WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc); + errCode = WMError::WM_ERROR_INVALID_PARAM; + } else { + NativeNumber* nativeType = ConvertNativeValueTo(info.argv[0]); + if (nativeType == nullptr) { + errCode = WMError::WM_ERROR_INVALID_PARAM; + WLOGFE("[NAPI]Failed to convert parameter to Orientation"); + } else { + requestedOrientation = JS_TO_NATIVE_ORIENTATION_MAP.at( + static_cast(static_cast(*nativeType))); + if (requestedOrientation < Orientation::BEGIN || requestedOrientation > Orientation::END) { + WLOGFE("[NAPI]Orientation %{public}u invalid!", static_cast(requestedOrientation)); + errCode = WMError::WM_ERROR_INVALID_PARAM; + } + } + } + + wptr weakToken(windowToken_); + AsyncTask::CompleteCallback complete = + [weakToken, requestedOrientation, errCode](NativeEngine& engine, AsyncTask& task, int32_t status) { + auto weakWindow = weakToken.promote(); + if (weakWindow == nullptr || errCode != WMError::WM_OK) { + task.Reject(engine, CreateJsError(engine, static_cast(errCode), + "OnSetRequestedOrientation failed")); + WLOGFE("[NAPI]Window is nullptr or get invalid param"); + return; + } + weakWindow->SetRequestedOrientation(requestedOrientation); + task.Resolve(engine, engine.CreateUndefined()); + WLOGFI("[NAPI]Window [%{public}u, %{public}s] OnSetRequestedOrientation end, orientation = %{public}u", + weakWindow->GetWindowId(), + weakWindow->GetWindowName().c_str(), + static_cast(requestedOrientation)); + }; + + NativeValue* lastParam = nullptr; + if (info.argc > 0 && info.argv[0]->TypeOf() == NATIVE_FUNCTION) { + lastParam = info.argv[0]; + } else if (info.argc > 1 && info.argv[1]->TypeOf() == NATIVE_FUNCTION) { + lastParam = info.argv[1]; + } + NativeValue* result = nullptr; + AsyncTask::Schedule( + engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result)); + return result; +} + NativeValue* JsWindow::OnIsSupportWideGamut(NativeEngine& engine, NativeCallbackInfo& info) { WMError errCode = WMError::WM_OK; @@ -1614,6 +1673,17 @@ NativeValue* CreateJsWindowObject(NativeEngine& engine, sptr& window) std::unique_ptr jsWindow = std::make_unique(window); object->SetNativePointer(jsWindow.release(), JsWindow::Finalizer, nullptr); + BindFunctions(engine, object); + + std::shared_ptr jsWindowRef; + jsWindowRef.reset(engine.CreateReference(objValue, 1)); + std::lock_guard lock(g_mutex); + g_jsWindowMap[windowName] = jsWindowRef; + return objValue; +} + +void BindFunctions(NativeEngine& engine, NativeObject* object) +{ BindNativeFunction(engine, *object, "show", JsWindow::Show); BindNativeFunction(engine, *object, "destroy", JsWindow::Destroy); BindNativeFunction(engine, *object, "hide", JsWindow::Hide); @@ -1647,12 +1717,7 @@ NativeValue* CreateJsWindowObject(NativeEngine& engine, sptr& window) BindNativeFunction(engine, *object, "disableWindowDecor", JsWindow::DisableWindowDecor); BindNativeFunction(engine, *object, "dump", JsWindow::Dump); BindNativeFunction(engine, *object, "setForbidSplitMove", JsWindow::SetForbidSplitMove); - - std::shared_ptr jsWindowRef; - jsWindowRef.reset(engine.CreateReference(objValue, 1)); - std::lock_guard lock(g_mutex); - g_jsWindowMap[windowName] = jsWindowRef; - return objValue; + BindNativeFunction(engine, *object, "setRequestedOrientation", JsWindow::SetRequestedOrientation); } } // namespace Rosen } // namespace OHOS diff --git a/interfaces/kits/napi/window_runtime/window_napi/js_window.h b/interfaces/kits/napi/window_runtime/window_napi/js_window.h index 9d26d9f5..3bc45ee9 100644 --- a/interfaces/kits/napi/window_runtime/window_napi/js_window.h +++ b/interfaces/kits/napi/window_runtime/window_napi/js_window.h @@ -27,6 +27,7 @@ namespace OHOS { namespace Rosen { NativeValue* CreateJsWindowObject(NativeEngine& engine, sptr& window); std::shared_ptr FindJsWindowObject(std::string windowName); +void BindFunctions(NativeEngine& engine, NativeObject* object); class JsWindow final { public: explicit JsWindow(const sptr& window); @@ -59,7 +60,7 @@ public: static NativeValue* SetTouchable(NativeEngine* engine, NativeCallbackInfo* info); static NativeValue* SetTransparent(NativeEngine* engine, NativeCallbackInfo* info); static NativeValue* SetCallingWindow(NativeEngine* engine, NativeCallbackInfo* info); - + static NativeValue* SetRequestedOrientation(NativeEngine* engine, NativeCallbackInfo* info); static NativeValue* DisableWindowDecor(NativeEngine* engine, NativeCallbackInfo* info); // colorspace, gamut static NativeValue* IsSupportWideGamut(NativeEngine* engine, NativeCallbackInfo* info); @@ -87,6 +88,7 @@ private: NativeValue* OnLoadContent(NativeEngine& engine, NativeCallbackInfo& info); NativeValue* OnGetAvoidArea(NativeEngine& engine, NativeCallbackInfo& info); NativeValue* OnIsShowing(NativeEngine& engine, NativeCallbackInfo& info); + NativeValue* OnSetRequestedOrientation(NativeEngine& engine, NativeCallbackInfo& info); // colorspace, gamut NativeValue* OnIsSupportWideGamut(NativeEngine& engine, NativeCallbackInfo& info); diff --git a/interfaces/kits/napi/window_runtime/window_napi/js_window_utils.h b/interfaces/kits/napi/window_runtime/window_napi/js_window_utils.h index 3e631957..751895ea 100644 --- a/interfaces/kits/napi/window_runtime/window_napi/js_window_utils.h +++ b/interfaces/kits/napi/window_runtime/window_napi/js_window_utils.h @@ -115,6 +115,36 @@ const std::map JS_TO_NATIVE_WINDOW_MODE_MAP { {ApiWindowMode::FLOATING, WindowMode::WINDOW_MODE_FLOATING }, }; +enum class ApiOrientation : uint32_t { + UNSPECIFIED = 0, + PORTRAIT = 1, + LANDSCAPE = 2, + PORTRAIT_INVERTED = 3, + LANDSCAPE_INVERTED = 4, + AUTO_ROTATION = 5, + AUTO_ROTATION_PORTRAIT = 6, + AUTO_ROTATION_LANDSCAPE = 7, + AUTO_ROTATION_RESTRICTED = 8, + AUTO_ROTATION_PORTRAIT_RESTRICTED = 9, + AUTO_ROTATION_LANDSCAPE_RESTRICTED = 10, + LOCKED = 11, +}; + +const std::map JS_TO_NATIVE_ORIENTATION_MAP { + {ApiOrientation::UNSPECIFIED, Orientation::UNSPECIFIED }, + {ApiOrientation::PORTRAIT, Orientation::VERTICAL }, + {ApiOrientation::LANDSCAPE, Orientation::HORIZONTAL }, + {ApiOrientation::PORTRAIT_INVERTED, Orientation::REVERSE_VERTICAL }, + {ApiOrientation::LANDSCAPE_INVERTED, Orientation::REVERSE_HORIZONTAL }, + {ApiOrientation::AUTO_ROTATION, Orientation::SENSOR }, + {ApiOrientation::AUTO_ROTATION_PORTRAIT, Orientation::SENSOR_VERTICAL }, + {ApiOrientation::AUTO_ROTATION_LANDSCAPE, Orientation::SENSOR_HORIZONTAL }, + {ApiOrientation::AUTO_ROTATION_RESTRICTED, Orientation::AUTO_ROTATION_RESTRICTED }, + {ApiOrientation::AUTO_ROTATION_PORTRAIT_RESTRICTED, Orientation::AUTO_ROTATION_PORTRAIT_RESTRICTED }, + {ApiOrientation::AUTO_ROTATION_LANDSCAPE_RESTRICTED, Orientation::AUTO_ROTATION_LANDSCAPE_RESTRICTED }, + {ApiOrientation::LOCKED, Orientation::LOCKED }, +}; + NativeValue* GetRectAndConvertToJsValue(NativeEngine& engine, const Rect rect); NativeValue* CreateJsWindowPropertiesObject(NativeEngine& engine, sptr& window); bool SetSystemBarPropertiesFromJs(NativeEngine& engine, NativeObject* jsObject, From 3ad103f94f5e316379b008fd692b6483eee9d25e Mon Sep 17 00:00:00 2001 From: xpeng Date: Wed, 22 Jun 2022 16:21:37 +0800 Subject: [PATCH 11/81] Update Schedule arguments Signed-off-by: xpeng Change-Id: I3a19ec615bfaee1ad7bbbe794f00cc5589ad4472 --- .../napi/screen_runtime/napi/js_screen_manager.cpp | 4 ++-- .../napi/window_runtime/window_napi/js_window.cpp | 11 +++-------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/interfaces/kits/napi/screen_runtime/napi/js_screen_manager.cpp b/interfaces/kits/napi/screen_runtime/napi/js_screen_manager.cpp index 8d90cc1b..edca53e6 100644 --- a/interfaces/kits/napi/screen_runtime/napi/js_screen_manager.cpp +++ b/interfaces/kits/napi/screen_runtime/napi/js_screen_manager.cpp @@ -642,7 +642,7 @@ NativeValue* OnIsScreenRotationLocked(NativeEngine& engine, NativeCallbackInfo& lastParam = info.argv[ARGC_ONE - 1]; } NativeValue* result = nullptr; - AsyncTask::Schedule( + AsyncTask::Schedule("JsScreenManager::OnIsScreenRotationLocked", engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result)); return result; } @@ -684,7 +684,7 @@ NativeValue* OnSetScreenRotationLocked(NativeEngine& engine, NativeCallbackInfo& NativeValue* lastParam = (info.argc <= 1) ? nullptr : (info.argv[1]->TypeOf() == NATIVE_FUNCTION ? info.argv[1] : nullptr); NativeValue* result = nullptr; - AsyncTask::Schedule( + AsyncTask::Schedule("JsScreenManager::OnSetScreenRotationLocked", engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result)); return result; } diff --git a/interfaces/kits/napi/window_runtime/window_napi/js_window.cpp b/interfaces/kits/napi/window_runtime/window_napi/js_window.cpp index 41c1e6e6..022b91b7 100644 --- a/interfaces/kits/napi/window_runtime/window_napi/js_window.cpp +++ b/interfaces/kits/napi/window_runtime/window_napi/js_window.cpp @@ -1051,7 +1051,6 @@ NativeValue* JsWindow::OnSetRequestedOrientation(NativeEngine& engine, NativeCal } } } - wptr weakToken(windowToken_); AsyncTask::CompleteCallback complete = [weakToken, requestedOrientation, errCode](NativeEngine& engine, AsyncTask& task, int32_t status) { @@ -1070,14 +1069,10 @@ NativeValue* JsWindow::OnSetRequestedOrientation(NativeEngine& engine, NativeCal static_cast(requestedOrientation)); }; - NativeValue* lastParam = nullptr; - if (info.argc > 0 && info.argv[0]->TypeOf() == NATIVE_FUNCTION) { - lastParam = info.argv[0]; - } else if (info.argc > 1 && info.argv[1]->TypeOf() == NATIVE_FUNCTION) { - lastParam = info.argv[1]; - } + NativeValue* lastParam = (info.argc <= 1) ? nullptr : + (info.argv[1]->TypeOf() == NATIVE_FUNCTION ? info.argv[1] : nullptr); NativeValue* result = nullptr; - AsyncTask::Schedule( + AsyncTask::Schedule("JsWindow::OnSetRequestedOrientation", engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result)); return result; } From d05e7fc86f17a11e73e2ee1ac58f200521664008 Mon Sep 17 00:00:00 2001 From: chyyy0213 Date: Wed, 22 Jun 2022 17:16:08 +0800 Subject: [PATCH 12/81] bugfix for subwindow with hot start Signed-off-by: chyyy0213 Change-Id: I5d0ff2b56b810ce378521e98c33a0d6cc118dc40 Signed-off-by: chyyy0213 --- wmserver/src/starting_window.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/wmserver/src/starting_window.cpp b/wmserver/src/starting_window.cpp index c66586df..d1733e9f 100644 --- a/wmserver/src/starting_window.cpp +++ b/wmserver/src/starting_window.cpp @@ -176,6 +176,11 @@ void StartingWindow::UpdateRSTree(sptr& node) } else { // to launcher dms.UpdateRSTree(shownDisplayId, node->surfaceNode_, true); } + for (auto& child : node->children_) { + if (child->currentVisibility_) { + dms.UpdateRSTree(shownDisplayId, child->surfaceNode_, true); + } + } } } }; From 3d20820bc32aaa16dba1b69ad4960206d6b95653 Mon Sep 17 00:00:00 2001 From: qianlf Date: Wed, 22 Jun 2022 17:29:34 +0800 Subject: [PATCH 13/81] Camera float window listerner Signed-off-by: qianlf Change-Id: Ie8e60de9f294fc171a9ba4fea0b9a5832874641b --- interfaces/innerkits/wm/window_manager.h | 8 ++ utils/include/window_property.h | 3 + utils/src/window_property.cpp | 14 +++- wm/include/window_manager_agent.h | 1 + .../zidl/window_manager_agent_interface.h | 3 + wm/include/zidl/window_manager_agent_proxy.h | 1 + wm/src/window_impl.cpp | 6 +- wm/src/window_manager.cpp | 66 +++++++++++++++ wm/src/window_manager_agent.cpp | 5 ++ wm/src/zidl/window_manager_agent_proxy.cpp | 26 ++++++ wm/src/zidl/window_manager_agent_stub.cpp | 6 ++ .../window_app_floating_window_test.cpp | 84 +++++++++++++++++++ .../include/window_manager_agent_controller.h | 1 + wmserver/include/window_node.h | 1 + wmserver/include/window_node_container.h | 1 + .../src/window_manager_agent_controller.cpp | 8 ++ wmserver/src/window_node.cpp | 5 ++ wmserver/src/window_node_container.cpp | 11 ++- 18 files changed, 247 insertions(+), 3 deletions(-) diff --git a/interfaces/innerkits/wm/window_manager.h b/interfaces/innerkits/wm/window_manager.h index 845f1a2f..fcc8b41c 100644 --- a/interfaces/innerkits/wm/window_manager.h +++ b/interfaces/innerkits/wm/window_manager.h @@ -125,6 +125,11 @@ public: virtual void OnWindowUpdate(const sptr& windowInfo, WindowUpdateType type) = 0; }; +class ICameraFloatWindowChangedListener : virtual public RefBase { +public: + virtual void OnCameraFloatWindowChange(uint32_t accessTokenId, bool isShowing) = 0; +}; + class WindowManager { WM_DECLARE_SINGLE_INSTANCE_BASE(WindowManager); friend class WindowManagerAgent; @@ -137,6 +142,8 @@ public: void UnregisterWindowUpdateListener(const sptr& listener); void RegisterVisibilityChangedListener(const sptr& listener); void UnregisterVisibilityChangedListener(const sptr& listener); + void RegisterCameraFloatWindowChangedListener(const sptr& listener); + void UnregisterCameraFloatWindowChangedListener(const sptr& listener); void MinimizeAllAppWindows(DisplayId displayId); WMError ToggleShownStateForAllAppWindows(); WMError SetWindowLayoutMode(WindowLayoutMode mode); @@ -155,6 +162,7 @@ private: void NotifyAccessibilityWindowInfo(const sptr& windowInfo, WindowUpdateType type) const; void UpdateWindowVisibilityInfo( const std::vector>& windowVisibilityInfos) const; + void UpdateCameraFloatWindowStatus(uint32_t accessTokenId, bool isShowing) const; }; } // namespace Rosen } // namespace OHOS diff --git a/utils/include/window_property.h b/utils/include/window_property.h index e21cf975..7aec8721 100644 --- a/utils/include/window_property.h +++ b/utils/include/window_property.h @@ -72,6 +72,7 @@ public: void SetStretchable(bool stretchable); void SetOriginRect(const Rect& rect); void SetTouchHotAreas(const std::vector& rects); + void SetAccessTokenId(uint32_t accessTokenId); WindowSizeChangeReason GetWindowSizeChangeReason() const; const std::string& GetWindowName() const; @@ -107,6 +108,7 @@ public: bool GetStretchable() const; const Rect& GetOriginRect() const; void GetTouchHotAreas(std::vector& rects) const; + uint32_t GetAccessTokenId() const; virtual bool Marshalling(Parcel& parcel) const override; static WindowProperty* Unmarshalling(Parcel& parcel); @@ -155,6 +157,7 @@ private: bool isStretchable_ {false}; DragType dragType_ = DragType::DRAG_UNDEFINED; std::vector touchHotAreas_; // coordinates relative to window. + uint32_t accessTokenId_ { 0 }; DEFINE_VAR_DEFAULT_FUNC_GET_SET(Orientation, RequestedOrientation, requestedOrientation, Orientation::UNSPECIFIED); }; } diff --git a/utils/src/window_property.cpp b/utils/src/window_property.cpp index b672c1c8..fa4f73d9 100644 --- a/utils/src/window_property.cpp +++ b/utils/src/window_property.cpp @@ -180,6 +180,11 @@ void WindowProperty::SetOriginRect(const Rect& rect) originRect_ = rect; } +void WindowProperty::SetAccessTokenId(uint32_t accessTokenId) +{ + accessTokenId_ = accessTokenId; +} + WindowSizeChangeReason WindowProperty::GetWindowSizeChangeReason() const { return windowSizeChangeReason_; @@ -375,6 +380,11 @@ void WindowProperty::GetTouchHotAreas(std::vector& rects) const rects = touchHotAreas_; } +uint32_t WindowProperty::GetAccessTokenId() const +{ + return accessTokenId_; +} + bool WindowProperty::MapMarshalling(Parcel& parcel) const { auto size = sysBarPropMap_.size(); @@ -450,7 +460,7 @@ bool WindowProperty::Marshalling(Parcel& parcel) const parcel.WriteBool(turnScreenOn_) && parcel.WriteBool(keepScreenOn_) && parcel.WriteUint32(modeSupportInfo_) && parcel.WriteUint32(static_cast(dragType_)) && parcel.WriteUint32(originRect_.width_) && parcel.WriteUint32(originRect_.height_) && - parcel.WriteBool(isStretchable_) && MarshallingTouchHotAreas(parcel); + parcel.WriteBool(isStretchable_) && MarshallingTouchHotAreas(parcel) && parcel.WriteUint32(accessTokenId_); } WindowProperty* WindowProperty::Unmarshalling(Parcel& parcel) @@ -498,6 +508,7 @@ WindowProperty* WindowProperty::Unmarshalling(Parcel& parcel) property->SetOriginRect(Rect { 0, 0, w, h }); property->SetStretchable(parcel.ReadBool()); UnmarshallingTouchHotAreas(parcel, property); + property->SetAccessTokenId(parcel.ReadUint32()); return property; } @@ -643,6 +654,7 @@ void WindowProperty::CopyFrom(const sptr& property) originRect_ = property->originRect_; isStretchable_ = property->isStretchable_; touchHotAreas_ = property->touchHotAreas_; + accessTokenId_ = property->accessTokenId_; } } } diff --git a/wm/include/window_manager_agent.h b/wm/include/window_manager_agent.h index 5adf8ee6..0e14a94c 100644 --- a/wm/include/window_manager_agent.h +++ b/wm/include/window_manager_agent.h @@ -30,6 +30,7 @@ public: void UpdateSystemBarRegionTints(DisplayId displayId, const SystemBarRegionTints& props) override; void NotifyAccessibilityWindowInfo(const sptr& windowInfo, WindowUpdateType type) override; void UpdateWindowVisibilityInfo(const std::vector>& visibilityInfos) override; + void UpdateCameraFloatWindowStatus(uint32_t accessTokenId, bool isShowing) override; }; } // namespace Rosen } // namespace OHOS diff --git a/wm/include/zidl/window_manager_agent_interface.h b/wm/include/zidl/window_manager_agent_interface.h index 705f5e8c..76c03263 100644 --- a/wm/include/zidl/window_manager_agent_interface.h +++ b/wm/include/zidl/window_manager_agent_interface.h @@ -27,6 +27,7 @@ enum class WindowManagerAgentType : uint32_t { WINDOW_MANAGER_AGENT_TYPE_SYSTEM_BAR, WINDOW_MANAGER_AGENT_TYPE_WINDOW_UPDATE, WINDOW_MANAGER_AGENT_TYPE_WINDOW_VISIBILITY, + WINDOW_MANAGER_AGENT_TYPE_CAMERA_FLOAT, }; class IWindowManagerAgent : public IRemoteBroker { @@ -38,6 +39,7 @@ public: TRANS_ID_UPDATE_SYSTEM_BAR_PROPS, TRANS_ID_UPDATE_WINDOW_STATUS, TRANS_ID_UPDATE_WINDOW_VISIBILITY, + TRANS_ID_UPDATE_CAMERA_FLOAT, }; virtual void UpdateFocusChangeInfo(const sptr& focusChangeInfo, bool focused) = 0; @@ -45,6 +47,7 @@ public: virtual void NotifyAccessibilityWindowInfo(const sptr& windowInfo, WindowUpdateType type) = 0; virtual void UpdateWindowVisibilityInfo(const std::vector>& visibilityInfos) = 0; + virtual void UpdateCameraFloatWindowStatus(uint32_t accessTokenId, bool isShowing) = 0; }; } // namespace Rosen } // namespace OHOS diff --git a/wm/include/zidl/window_manager_agent_proxy.h b/wm/include/zidl/window_manager_agent_proxy.h index f54ad701..657801d9 100644 --- a/wm/include/zidl/window_manager_agent_proxy.h +++ b/wm/include/zidl/window_manager_agent_proxy.h @@ -31,6 +31,7 @@ public: void UpdateSystemBarRegionTints(DisplayId displayId, const SystemBarRegionTints& tints) override; void NotifyAccessibilityWindowInfo(const sptr& windowInfo, WindowUpdateType type) override; void UpdateWindowVisibilityInfo(const std::vector>& visibilityInfos) override; + void UpdateCameraFloatWindowStatus(uint32_t accessTokenId, bool isShowing) override; private: static inline BrokerDelegator delegator_; diff --git a/wm/src/window_impl.cpp b/wm/src/window_impl.cpp index 66cfeb33..cddff153 100644 --- a/wm/src/window_impl.cpp +++ b/wm/src/window_impl.cpp @@ -16,10 +16,11 @@ #include "window_impl.h" #include +#include #include #include -#include +#include "ipc_skeleton.h" #include "color_parser.h" #include "display_manager.h" @@ -2341,6 +2342,9 @@ bool WindowImpl::CheckCameraFloatingWindowMultiCreated(WindowType type) return true; } } + uint32_t accessTokenId = static_cast(IPCSkeleton::GetCallingTokenID()); + property_->SetAccessTokenId(accessTokenId); + WLOGFI("Create camera float window, accessTokenId = %{public}u", accessTokenId); return false; } } // namespace Rosen diff --git a/wm/src/window_manager.cpp b/wm/src/window_manager.cpp index 34aa8956..e16ff519 100644 --- a/wm/src/window_manager.cpp +++ b/wm/src/window_manager.cpp @@ -146,6 +146,7 @@ public: void NotifySystemBarChanged(DisplayId displayId, const SystemBarRegionTints& tints); void NotifyAccessibilityWindowInfo(const sptr& windowInfo, WindowUpdateType type); void NotifyWindowVisibilityInfoChanged(const std::vector>& windowVisibilityInfos); + void UpdateCameraFloatWindowStatus(uint32_t accessTokenId, bool isShowing); static inline SingletonDelegator delegator_; bool isHandlerRunning_ = false; @@ -159,6 +160,8 @@ public: sptr windowUpdateListenerAgent_; std::vector> windowVisibilityListeners_; sptr windowVisibilityListenerAgent_; + std::vector> cameraFloatWindowChangedListeners_; + sptr cameraFloatWindowChangedListenerAgent_; }; void WindowManager::Impl::PostTask(ListenerTaskCallback &&callback, EventPriority priority = EventPriority::LOW, @@ -270,6 +273,16 @@ void WindowManager::Impl::NotifyWindowVisibilityInfoChanged( }, EventPriority::LOW, "AccessibilityWindowInfo"); } +void WindowManager::Impl::UpdateCameraFloatWindowStatus(uint32_t accessTokenId, bool isShowing) +{ + WLOGFI("Camera float window, accessTokenId = %{public}u, isShowing = %{public}u", accessTokenId, isShowing); + PostTask([this, accessTokenId, isShowing]() mutable { + for (auto& listener : cameraFloatWindowChangedListeners_) { + listener->OnCameraFloatWindowChange(accessTokenId, isShowing); + } + }, EventPriority::LOW, "CameraFloatWindowStatus"); +} + WindowManager::WindowManager() : pImpl_(std::make_unique()) { } @@ -467,6 +480,53 @@ void WindowManager::UnregisterVisibilityChangedListener(const sptr& listener) +{ + if (listener == nullptr) { + WLOGFE("listener could not be null"); + return; + } + + std::lock_guard lock(pImpl_->mutex_); + auto iter = std::find(pImpl_->cameraFloatWindowChangedListeners_.begin(), + pImpl_->cameraFloatWindowChangedListeners_.end(), listener); + if (iter != pImpl_->cameraFloatWindowChangedListeners_.end()) { + WLOGFI("Listener is already registered."); + return; + } + pImpl_->cameraFloatWindowChangedListeners_.push_back(listener); + if (pImpl_->cameraFloatWindowChangedListenerAgent_ == nullptr) { + pImpl_->cameraFloatWindowChangedListenerAgent_ = new WindowManagerAgent(); + SingletonContainer::Get().RegisterWindowManagerAgent( + WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_CAMERA_FLOAT, + pImpl_->cameraFloatWindowChangedListenerAgent_); + } +} + +void WindowManager::UnregisterCameraFloatWindowChangedListener(const sptr& listener) +{ + if (listener == nullptr) { + WLOGFE("listener could not be null"); + return; + } + + std::lock_guard lock(pImpl_->mutex_); + auto iter = std::find(pImpl_->cameraFloatWindowChangedListeners_.begin(), + pImpl_->cameraFloatWindowChangedListeners_.end(), listener); + if (iter == pImpl_->cameraFloatWindowChangedListeners_.end()) { + WLOGFE("could not find this listener"); + return; + } + pImpl_->cameraFloatWindowChangedListeners_.erase(iter); + if (pImpl_->cameraFloatWindowChangedListeners_.empty() && + pImpl_->cameraFloatWindowChangedListenerAgent_ != nullptr) { + SingletonContainer::Get().UnregisterWindowManagerAgent( + WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_CAMERA_FLOAT, + pImpl_->cameraFloatWindowChangedListenerAgent_); + pImpl_->cameraFloatWindowChangedListenerAgent_ = nullptr; + } +} + void WindowManager::UpdateFocusChangeInfo(const sptr& focusChangeInfo, bool focused) const { if (focusChangeInfo == nullptr) { @@ -511,5 +571,11 @@ WMError WindowManager::GetAccessibilityWindowInfo(sptr& } return ret; } + +void WindowManager::UpdateCameraFloatWindowStatus(uint32_t accessTokenId, bool isShowing) const +{ + std::lock_guard lock(pImpl_->mutex_); + pImpl_->UpdateCameraFloatWindowStatus(accessTokenId, isShowing); +} } // namespace Rosen } // namespace OHOS diff --git a/wm/src/window_manager_agent.cpp b/wm/src/window_manager_agent.cpp index b8328fc4..aa00b692 100644 --- a/wm/src/window_manager_agent.cpp +++ b/wm/src/window_manager_agent.cpp @@ -40,5 +40,10 @@ void WindowManagerAgent::UpdateWindowVisibilityInfo(const std::vector().UpdateWindowVisibilityInfo(visibilityInfos); } + +void WindowManagerAgent::UpdateCameraFloatWindowStatus(uint32_t accessTokenId, bool isShowing) +{ + SingletonContainer::Get().UpdateCameraFloatWindowStatus(accessTokenId, isShowing); +} } // namespace Rosen } // namespace OHOS diff --git a/wm/src/zidl/window_manager_agent_proxy.cpp b/wm/src/zidl/window_manager_agent_proxy.cpp index a9112ae1..d2c492f7 100644 --- a/wm/src/zidl/window_manager_agent_proxy.cpp +++ b/wm/src/zidl/window_manager_agent_proxy.cpp @@ -144,6 +144,32 @@ void WindowManagerAgentProxy::UpdateWindowVisibilityInfo( WLOGFE("SendRequest failed"); } } + +void WindowManagerAgentProxy::UpdateCameraFloatWindowStatus(uint32_t accessTokenId, bool isShowing) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_ASYNC); + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("WriteInterfaceToken failed"); + return; + } + + if (!data.WriteUint32(accessTokenId)) { + WLOGFE("Write accessTokenId failed"); + return; + } + + if (!data.WriteBool(isShowing)) { + WLOGFE("Write is showing status failed"); + return; + } + + if (Remote()->SendRequest(static_cast(WindowManagerAgentMsg::TRANS_ID_UPDATE_CAMERA_FLOAT), + data, reply, option) != ERR_NONE) { + WLOGFE("SendRequest failed"); + } +} } // namespace Rosen } // namespace OHOS diff --git a/wm/src/zidl/window_manager_agent_stub.cpp b/wm/src/zidl/window_manager_agent_stub.cpp index 558d2ebf..d15facfb 100644 --- a/wm/src/zidl/window_manager_agent_stub.cpp +++ b/wm/src/zidl/window_manager_agent_stub.cpp @@ -84,6 +84,12 @@ int WindowManagerAgentStub::OnRemoteRequest(uint32_t code, MessageParcel& data, UpdateWindowVisibilityInfo(infos); break; } + case WindowManagerAgentMsg::TRANS_ID_UPDATE_CAMERA_FLOAT: { + uint32_t accessTokenId = data.ReadUint32(); + bool isShowing = data.ReadBool(); + UpdateCameraFloatWindowStatus(accessTokenId, isShowing); + break; + } default: break; } diff --git a/wm/test/systemtest/window_app_floating_window_test.cpp b/wm/test/systemtest/window_app_floating_window_test.cpp index df14fa72..6f42ece0 100644 --- a/wm/test/systemtest/window_app_floating_window_test.cpp +++ b/wm/test/systemtest/window_app_floating_window_test.cpp @@ -16,7 +16,9 @@ // gtest #include #include "ability_context_impl.h" +#include "ipc_skeleton.h" #include "window.h" +#include "window_manager.h" #include "window_option.h" #include "window_scene.h" #include "window_test_utils.h" @@ -27,6 +29,17 @@ using namespace testing::ext; namespace OHOS { namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowAppFloatingWindowTest"}; +} + +class TestCameraFloatWindowChangedListener : public ICameraFloatWindowChangedListener { +public: + uint32_t accessTokenId_ = 0; + bool isShowing_ = false; + void OnCameraFloatWindowChange(uint32_t accessTokenId, bool isShowing) override; +}; + class WindowAppFloatingWindowTest : public testing::Test { public: static void SetUpTestCase(); @@ -36,8 +49,19 @@ public: static inline float virtualPixelRatio_ = 1.0; static inline std::shared_ptr abilityContext_ = nullptr; + static sptr testCameraFloatWindowChangedListener_; }; +sptr WindowAppFloatingWindowTest::testCameraFloatWindowChangedListener_ = + new TestCameraFloatWindowChangedListener(); + +void TestCameraFloatWindowChangedListener::OnCameraFloatWindowChange(uint32_t accessTokenId, bool isShowing) +{ + WLOGFI("TestCameraFloatWindowChangedListener [%{public}u, %{public}u]", accessTokenId, isShowing); + accessTokenId_ = accessTokenId; + isShowing_ = isShowing; +} + void WindowAppFloatingWindowTest::SetUpTestCase() { auto display = DisplayManager::GetInstance().GetDisplayById(0); @@ -308,5 +332,65 @@ HWTEST_F(WindowAppFloatingWindowTest, AppFloatingWindow09, Function | MediumTest ASSERT_EQ(WMError::WM_OK, fltWin->Destroy()); ASSERT_EQ(WMError::WM_OK, scene->GoDestroy()); } + +/** + * @tc.name: AppFloatingWindow10 + * @tc.desc: Camera AppFloatingWindow multi create + * @tc.type: FUNC + */ +HWTEST_F(WindowAppFloatingWindowTest, AppFloatingWindow10, Function | MediumTest | Level3) +{ + sptr scene = CreateWindowScene(); + ASSERT_NE(nullptr, scene); + + Rect fltWindRect = GetRectWithVpr(0, 0, 400, 600); + sptr fltWin = CreateAppFloatingWindow(WindowType::WINDOW_TYPE_FLOAT_CAMERA, fltWindRect); + ASSERT_NE(nullptr, fltWin); + + sptr fltWin2 = CreateAppFloatingWindow(WindowType::WINDOW_TYPE_FLOAT_CAMERA, fltWindRect); + ASSERT_EQ(nullptr, fltWin2); + + ASSERT_EQ(WMError::WM_OK, fltWin->Destroy()); + sptr fltWin3 = CreateAppFloatingWindow(WindowType::WINDOW_TYPE_FLOAT_CAMERA, fltWindRect); + ASSERT_NE(nullptr, fltWin3); + + ASSERT_EQ(WMError::WM_OK, fltWin3->Destroy()); + ASSERT_EQ(WMError::WM_OK, scene->GoDestroy()); +} + +/** + * @tc.name: AppFloatingWindow11 + * @tc.desc: Camera AppFloatingWindow listener + * @tc.type: FUNC + */ +HWTEST_F(WindowAppFloatingWindowTest, AppFloatingWindow11, Function | MediumTest | Level2) +{ + uint32_t tokenId = static_cast(IPCSkeleton::GetCallingTokenID()); + WindowManager::GetInstance().RegisterCameraFloatWindowChangedListener(testCameraFloatWindowChangedListener_); + sptr scene = CreateWindowScene(); + ASSERT_NE(nullptr, scene); + + Rect fltWindRect = GetRectWithVpr(0, 0, 400, 600); + sptr fltWin = CreateAppFloatingWindow(WindowType::WINDOW_TYPE_FLOAT_CAMERA, fltWindRect); + ASSERT_NE(nullptr, fltWin); + + ASSERT_EQ(WMError::WM_OK, scene->GoForeground()); + ASSERT_EQ(WMError::WM_OK, fltWin->Show()); + + usleep(500000); // 500000us = 0.5s + ASSERT_EQ(tokenId, testCameraFloatWindowChangedListener_->accessTokenId_); + ASSERT_EQ(true, testCameraFloatWindowChangedListener_->isShowing_); + + ASSERT_EQ(WMError::WM_OK, fltWin->Hide()); + + usleep(500000); // 500000us = 0.5s + ASSERT_EQ(tokenId, testCameraFloatWindowChangedListener_->accessTokenId_); + ASSERT_EQ(false, testCameraFloatWindowChangedListener_->isShowing_); + + ASSERT_EQ(WMError::WM_OK, fltWin->Destroy()); + ASSERT_EQ(WMError::WM_OK, scene->GoDestroy()); + + WindowManager::GetInstance().UnregisterCameraFloatWindowChangedListener(testCameraFloatWindowChangedListener_); +} } // namespace Rosen } // namespace OHOS diff --git a/wmserver/include/window_manager_agent_controller.h b/wmserver/include/window_manager_agent_controller.h index 02e35d42..30c05d99 100644 --- a/wmserver/include/window_manager_agent_controller.h +++ b/wmserver/include/window_manager_agent_controller.h @@ -35,6 +35,7 @@ public: void UpdateSystemBarRegionTints(DisplayId displayId, const SystemBarRegionTints& tints); void NotifyAccessibilityWindowInfo(const sptr& windowInfo, WindowUpdateType type); void UpdateWindowVisibilityInfo(const std::vector>& windowVisibilityInfos); + void UpdateCameraFloatWindowStatus(uint32_t accessTokenId, bool isShowing); private: WindowManagerAgentController() {} diff --git a/wmserver/include/window_node.h b/wmserver/include/window_node.h index 194cbd3c..1406214e 100644 --- a/wmserver/include/window_node.h +++ b/wmserver/include/window_node.h @@ -104,6 +104,7 @@ public: const Rect& GetOriginRect() const; void ResetWindowSizeChangeReason(); void GetTouchHotAreas(std::vector& rects) const; + uint32_t GetAccessTokenId() const; sptr parent_; std::vector> children_; diff --git a/wmserver/include/window_node_container.h b/wmserver/include/window_node_container.h index 1afda27d..e37923df 100644 --- a/wmserver/include/window_node_container.h +++ b/wmserver/include/window_node_container.h @@ -106,6 +106,7 @@ public: sptr GetMultiDisplayController() const; sptr GetRootNode(WindowRootNodeType type) const; void NotifyDockWindowStateChanged(sptr& node, bool isEnable); + void UpdateCameraFloatWindowStatus(const sptr& node, bool isShowing); private: void TraverseWindowNode(sptr& root, std::vector>& windowNodes) const; diff --git a/wmserver/src/window_manager_agent_controller.cpp b/wmserver/src/window_manager_agent_controller.cpp index 812be8bb..2686a809 100644 --- a/wmserver/src/window_manager_agent_controller.cpp +++ b/wmserver/src/window_manager_agent_controller.cpp @@ -74,5 +74,13 @@ void WindowManagerAgentController::UpdateWindowVisibilityInfo( agent->UpdateWindowVisibilityInfo(windowVisibilityInfos); } } + +void WindowManagerAgentController::UpdateCameraFloatWindowStatus(uint32_t accessTokenId, bool isShowing) +{ + for (auto& agent : wmAgentContainer_.GetAgentsByType( + WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_CAMERA_FLOAT)) { + agent->UpdateCameraFloatWindowStatus(accessTokenId, isShowing); + } +} } // namespace Rosen } // namespace OHOS \ No newline at end of file diff --git a/wmserver/src/window_node.cpp b/wmserver/src/window_node.cpp index a187e915..fbbb02e2 100644 --- a/wmserver/src/window_node.cpp +++ b/wmserver/src/window_node.cpp @@ -348,5 +348,10 @@ void WindowNode::GetTouchHotAreas(std::vector& rects) const { rects = touchHotAreas_; } + +uint32_t WindowNode::GetAccessTokenId() const +{ + return property_->GetAccessTokenId(); +} } // namespace Rosen } // namespace OHOS diff --git a/wmserver/src/window_node_container.cpp b/wmserver/src/window_node_container.cpp index fdc02692..ae993458 100644 --- a/wmserver/src/window_node_container.cpp +++ b/wmserver/src/window_node_container.cpp @@ -183,7 +183,7 @@ WMError WindowNodeContainer::AddWindowNode(sptr& node, sptrGetWindowId()); + UpdateCameraFloatWindowStatus(node, true); if (WindowHelper::IsAppWindow(node->GetWindowType())) { backupWindowIds_.clear(); } @@ -191,6 +191,7 @@ WMError WindowNodeContainer::AddWindowNode(sptr& node, sptrGetWindowType() == WindowType::WINDOW_TYPE_KEYGUARD) { isScreenLocked_ = true; } + WLOGFI("AddWindowNode windowId: %{public}u end", node->GetWindowId()); return WMError::WM_OK; } @@ -301,6 +302,7 @@ WMError WindowNodeContainer::RemoveWindowNode(sptr& node) DumpScreenWindowTree(); NotifyAccessibilityWindowInfo(node, WindowUpdateType::WINDOW_UPDATE_REMOVED); RecoverScreenDefaultOrientationIfNeed(node->GetDisplayId()); + UpdateCameraFloatWindowStatus(node, false); if (node->GetWindowType() == WindowType::WINDOW_TYPE_KEYGUARD) { isScreenLocked_ = false; } @@ -1880,5 +1882,12 @@ Orientation WindowNodeContainer::GetFullScreenWindowRequestedOrientation() } return Orientation::UNSPECIFIED; } + +void WindowNodeContainer::UpdateCameraFloatWindowStatus(const sptr& node, bool isShowing) +{ + if (node->GetWindowType() == WindowType::WINDOW_TYPE_FLOAT_CAMERA) { + WindowManagerAgentController::GetInstance().UpdateCameraFloatWindowStatus(node->GetAccessTokenId(), isShowing); + } +} } // namespace Rosen } // namespace OHOS From 94c35d7bd979413ef9f4aebd35d6f56e1d40af78 Mon Sep 17 00:00:00 2001 From: maojiangping Date: Thu, 23 Jun 2022 10:34:45 +0800 Subject: [PATCH 14/81] add more parameter checking for multiple hot areas setting Signed-off-by: maojiangping Change-Id: I52f4ef81c7943f28468711253ba710141db8c3d2 Signed-off-by: maojiangping --- utils/include/window_helper.h | 4 +++- wm/test/systemtest/window_input_test.cpp | 8 ++++++++ wmserver/src/window_controller.cpp | 15 +++++++++++---- wmserver/src/window_layout_policy.cpp | 4 +++- 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/utils/include/window_helper.h b/utils/include/window_helper.h index 9f719142..e32c9611 100644 --- a/utils/include/window_helper.h +++ b/utils/include/window_helper.h @@ -303,6 +303,7 @@ public: static bool CalculateTouchHotAreas(const Rect& windowRect, const std::vector& requestRects, std::vector& outRects) { + bool isOk = true; for (const auto& rect : requestRects) { if (rect.posX_ < 0 || rect.posY_ < 0 || rect.width_ == 0 || rect.height_ == 0) { return false; @@ -310,6 +311,7 @@ public: Rect hotArea; if (rect.posX_ >= static_cast(windowRect.width_) || rect.posY_ >= static_cast(windowRect.height_)) { + isOk = false; continue; } hotArea.posX_ = windowRect.posX_ + rect.posX_; @@ -320,7 +322,7 @@ public: std::min(hotArea.posY_ + rect.height_, windowRect.posY_ + windowRect.height_) - hotArea.posY_; outRects.emplace_back(hotArea); } - return true; + return isOk; } private: diff --git a/wm/test/systemtest/window_input_test.cpp b/wm/test/systemtest/window_input_test.cpp index d4f4b014..b1577c60 100644 --- a/wm/test/systemtest/window_input_test.cpp +++ b/wm/test/systemtest/window_input_test.cpp @@ -153,6 +153,14 @@ HWTEST_F(WindowInputTest, SetTouchHotAreas02, Function | MediumTest | Level3) rects.emplace_back(Rect{ 0, 0, windowRect.width_ / 2, 0 }); ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetTouchHotAreas(rects)); + rects.clear(); + rects.emplace_back(Rect{ windowRect.width_, 0, windowRect.width_ / 2, windowRect.height_ / 2 }); + ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetTouchHotAreas(rects)); + + rects.clear(); + rects.emplace_back(Rect{ 0, windowRect.height_, windowRect.width_ / 2, windowRect.height_ / 2 }); + ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetTouchHotAreas(rects)); + std::vector requestedTouchHotAreas; window->GetRequestedTouchHotAreas(requestedTouchHotAreas); ASSERT_TRUE(requestedTouchHotAreas.empty()); diff --git a/wmserver/src/window_controller.cpp b/wmserver/src/window_controller.cpp index 627dd869..c243b623 100644 --- a/wmserver/src/window_controller.cpp +++ b/wmserver/src/window_controller.cpp @@ -871,15 +871,22 @@ WMError WindowController::UpdateTouchHotAreas(const sptr& node, cons } WLOGFI("windowId: %{public}u, size: %{public}d, rects: %{public}s", node->GetWindowId(), static_cast(rects.size()), oss.str().c_str()); - Rect windowRect = node->GetWindowRect(); - std::vector hotAreas; - if (rects.size() > TOUCH_HOT_AREA_MAX_NUM || !WindowHelper::CalculateTouchHotAreas(windowRect, rects, hotAreas)) { + if (rects.size() > TOUCH_HOT_AREA_MAX_NUM) { + WLOGFE("the number of touch hot areas exceeds the maximum"); return WMError::WM_ERROR_INVALID_PARAM; } - node->GetWindowProperty()->SetTouchHotAreas(rects); + + std::vector hotAreas; if (rects.empty()) { hotAreas.emplace_back(node->GetFullWindowHotArea()); + } else { + Rect windowRect = node->GetWindowRect(); + if (!WindowHelper::CalculateTouchHotAreas(windowRect, rects, hotAreas)) { + WLOGFE("the requested touch hot areas are incorrect"); + return WMError::WM_ERROR_INVALID_PARAM; + } } + node->GetWindowProperty()->SetTouchHotAreas(rects); node->SetTouchHotAreas(hotAreas); FlushWindowInfo(node->GetWindowId()); return WMError::WM_OK; diff --git a/wmserver/src/window_layout_policy.cpp b/wmserver/src/window_layout_policy.cpp index 04bc5414..60e76d18 100644 --- a/wmserver/src/window_layout_policy.cpp +++ b/wmserver/src/window_layout_policy.cpp @@ -448,7 +448,9 @@ void WindowLayoutPolicy::CalcAndSetNodeHotZone(const Rect& winRect, const sptrSetTouchHotAreas(hotAreas); } From ab544ca6f3cf4058a840d3c6d5b02b73817b1d7b Mon Sep 17 00:00:00 2001 From: xpeng Date: Thu, 23 Jun 2022 14:08:34 +0800 Subject: [PATCH 15/81] fix problems Signed-off-by: xpeng Change-Id: Ib167bfeb30063d6bcea15fd674c33edca4cd26ae --- dm/include/display_manager_adapter.h | 2 +- dm/src/display_manager_adapter.cpp | 6 ++--- dm/src/screen_manager.cpp | 4 ++-- dmserver/include/display_manager_interface.h | 2 +- dmserver/include/display_manager_proxy.h | 2 +- dmserver/include/display_manager_service.h | 2 +- dmserver/src/display_manager_proxy.cpp | 14 +++++------ dmserver/src/display_manager_service.cpp | 3 +-- dmserver/src/display_manager_stub.cpp | 3 +-- dmserver/src/screen_rotation_controller.cpp | 4 ++-- interfaces/innerkits/dm/screen_manager.h | 2 +- .../screen_runtime/napi/js_screen_manager.cpp | 10 ++------ .../napi/window_runtime/api/@ohos.window.d.ts | 24 +++++++++---------- 13 files changed, 34 insertions(+), 44 deletions(-) diff --git a/dm/include/display_manager_adapter.h b/dm/include/display_manager_adapter.h index e4403668..2dda6823 100644 --- a/dm/include/display_manager_adapter.h +++ b/dm/include/display_manager_adapter.h @@ -89,7 +89,7 @@ public: virtual bool SetScreenActiveMode(ScreenId screenId, uint32_t modeId); virtual sptr GetScreenInfo(ScreenId screenId); virtual bool SetVirtualPixelRatio(ScreenId screenId, float virtualPixelRatio); - virtual DMError SetScreenRotationLocked(bool isLocked); + virtual void SetScreenRotationLocked(bool isLocked); virtual bool IsScreenRotationLocked(); // colorspace, gamut diff --git a/dm/src/display_manager_adapter.cpp b/dm/src/display_manager_adapter.cpp index 82cdda11..51d35ce7 100644 --- a/dm/src/display_manager_adapter.cpp +++ b/dm/src/display_manager_adapter.cpp @@ -125,11 +125,11 @@ DMError ScreenManagerAdapter::SetVirtualScreenSurface(ScreenId screenId, sptrSetVirtualScreenSurface(screenId, surface); } -DMError ScreenManagerAdapter::SetScreenRotationLocked(bool isLocked) +void ScreenManagerAdapter::SetScreenRotationLocked(bool isLocked) { - INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED); + INIT_PROXY_CHECK_RETURN(); WLOGFI("DisplayManagerAdapter::SetScreenRotationLocked"); - return displayManagerServiceProxy_->SetScreenRotationLocked(isLocked); + displayManagerServiceProxy_->SetScreenRotationLocked(isLocked); } bool ScreenManagerAdapter::IsScreenRotationLocked() diff --git a/dm/src/screen_manager.cpp b/dm/src/screen_manager.cpp index 9f3d784f..cd49bcc9 100644 --- a/dm/src/screen_manager.cpp +++ b/dm/src/screen_manager.cpp @@ -435,9 +435,9 @@ ScreenPowerState ScreenManager::GetScreenPower(ScreenId dmsScreenId) return SingletonContainer::Get().GetScreenPower(dmsScreenId); } -DMError ScreenManager::SetScreenRotationLocked(bool isLocked) +void ScreenManager::SetScreenRotationLocked(bool isLocked) { - return SingletonContainer::Get().SetScreenRotationLocked(isLocked); + SingletonContainer::Get().SetScreenRotationLocked(isLocked); } bool ScreenManager::IsScreenRotationLocked() diff --git a/dmserver/include/display_manager_interface.h b/dmserver/include/display_manager_interface.h index b6561687..17d22fc2 100644 --- a/dmserver/include/display_manager_interface.h +++ b/dmserver/include/display_manager_interface.h @@ -85,7 +85,7 @@ public: virtual DMError SetVirtualScreenSurface(ScreenId screenId, sptr surface) = 0; virtual bool SetOrientation(ScreenId screenId, Orientation orientation) = 0; virtual std::shared_ptr GetDisplaySnapshot(DisplayId displayId) = 0; - virtual DMError SetScreenRotationLocked(bool isLocked) = 0; + virtual void SetScreenRotationLocked(bool isLocked) = 0; virtual bool IsScreenRotationLocked() = 0; // colorspace, gamut diff --git a/dmserver/include/display_manager_proxy.h b/dmserver/include/display_manager_proxy.h index 14134a56..3b42f18d 100644 --- a/dmserver/include/display_manager_proxy.h +++ b/dmserver/include/display_manager_proxy.h @@ -42,7 +42,7 @@ public: bool SetOrientation(ScreenId screenId, Orientation orientation) override; std::shared_ptr GetDisplaySnapshot(DisplayId displayId) override; bool IsScreenRotationLocked() override; - DMError SetScreenRotationLocked(bool isLocked) override; + void SetScreenRotationLocked(bool isLocked) override; // colorspace, gamut DMError GetScreenSupportedColorGamuts(ScreenId screenId, std::vector& colorGamuts) override; diff --git a/dmserver/include/display_manager_service.h b/dmserver/include/display_manager_service.h index f652894a..c5a74a1d 100644 --- a/dmserver/include/display_manager_service.h +++ b/dmserver/include/display_manager_service.h @@ -51,7 +51,7 @@ public: DMError DestroyVirtualScreen(ScreenId screenId) override; DMError SetVirtualScreenSurface(ScreenId screenId, sptr surface) override; bool IsScreenRotationLocked() override; - DMError SetScreenRotationLocked(bool isLocked) override; + void SetScreenRotationLocked(bool isLocked) override; sptr GetDefaultDisplayInfo() override; sptr GetDisplayInfoById(DisplayId displayId) override; diff --git a/dmserver/src/display_manager_proxy.cpp b/dmserver/src/display_manager_proxy.cpp index f5608a13..2c1cd08b 100644 --- a/dmserver/src/display_manager_proxy.cpp +++ b/dmserver/src/display_manager_proxy.cpp @@ -1008,7 +1008,6 @@ bool DisplayManagerProxy::SetVirtualPixelRatio(ScreenId screenId, float virtualP bool DisplayManagerProxy::IsScreenRotationLocked() { - bool isLocked; sptr remote = Remote(); if (remote == nullptr) { WLOGFW("IsScreenRotationLocked: remote is nullptr"); @@ -1026,16 +1025,16 @@ bool DisplayManagerProxy::IsScreenRotationLocked() WLOGFW("IsScreenRotationLocked: SendRequest failed"); return false; } - isLocked = reply.ReadBool(); + bool isLocked = reply.ReadBool(); return isLocked; } -DMError DisplayManagerProxy::SetScreenRotationLocked(bool isLocked) +void DisplayManagerProxy::SetScreenRotationLocked(bool isLocked) { sptr remote = Remote(); if (remote == nullptr) { WLOGFW("SetScreenRotationLocked: remote is null"); - return DMError::DM_ERROR_REMOTE_CREATE_FAILED; + return; } MessageParcel data; @@ -1043,17 +1042,16 @@ DMError DisplayManagerProxy::SetScreenRotationLocked(bool isLocked) MessageOption option; if (!data.WriteInterfaceToken(GetDescriptor())) { WLOGFE("SetScreenRotationLocked: WriteInterfaceToken failed"); - return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED; + return; } if (!data.WriteBool(isLocked)) { WLOGFE("SetScreenRotationLocked: write isLocked failed"); - return DMError::DM_ERROR_IPC_FAILED; + return; } if (remote->SendRequest(static_cast(DisplayManagerMessage::TRANS_ID_SET_SCREEN_ROTATION_LOCKED), data, reply, option) != ERR_NONE) { WLOGFE("SetScreenRotationLocked: SendRequest failed"); - return DMError::DM_ERROR_IPC_FAILED; + return; } - return static_cast(reply.ReadInt32()); } } // namespace OHOS::Rosen \ No newline at end of file diff --git a/dmserver/src/display_manager_service.cpp b/dmserver/src/display_manager_service.cpp index 9918ccbe..03f74564 100644 --- a/dmserver/src/display_manager_service.cpp +++ b/dmserver/src/display_manager_service.cpp @@ -572,9 +572,8 @@ bool DisplayManagerService::IsScreenRotationLocked() return ScreenRotationController::IsScreenRotationLocked(); } -DMError DisplayManagerService::SetScreenRotationLocked(bool isLocked) +void DisplayManagerService::SetScreenRotationLocked(bool isLocked) { ScreenRotationController::SetScreenRotationLocked(isLocked); - return DMError::DM_OK; } } // namespace OHOS::Rosen \ No newline at end of file diff --git a/dmserver/src/display_manager_stub.cpp b/dmserver/src/display_manager_stub.cpp index ffbce65a..ea976d12 100644 --- a/dmserver/src/display_manager_stub.cpp +++ b/dmserver/src/display_manager_stub.cpp @@ -320,8 +320,7 @@ int32_t DisplayManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, } case DisplayManagerMessage::TRANS_ID_SET_SCREEN_ROTATION_LOCKED: { bool isLocked = static_cast(data.ReadBool()); - DMError ret = SetScreenRotationLocked(isLocked); - reply.WriteInt32(static_cast(ret)); + SetScreenRotationLocked(isLocked); break; } default: diff --git a/dmserver/src/screen_rotation_controller.cpp b/dmserver/src/screen_rotation_controller.cpp index 5267c7e6..2b0c5aad 100644 --- a/dmserver/src/screen_rotation_controller.cpp +++ b/dmserver/src/screen_rotation_controller.cpp @@ -202,7 +202,7 @@ Rotation ScreenRotationController::ProcessAutoRotationPortraitOrientation(Rotati if (sensorRotation == Rotation::ROTATION_0 || sensorRotation == Rotation::ROTATION_180) { return sensorRotation; } - return Rotation::ROTATION_0; + return currentDisplayRotation_; } Rotation ScreenRotationController::ProcessAutoRotationLandscapeOrientation(Rotation sensorRotation) @@ -210,7 +210,7 @@ Rotation ScreenRotationController::ProcessAutoRotationLandscapeOrientation(Rotat if (sensorRotation == Rotation::ROTATION_90 || sensorRotation == Rotation::ROTATION_270) { return sensorRotation; } - return Rotation::ROTATION_90; + return currentDisplayRotation_; } void ScreenRotationController::SetScreenRotation(Rotation targetRotation) diff --git a/interfaces/innerkits/dm/screen_manager.h b/interfaces/innerkits/dm/screen_manager.h index a539049c..704ba0c7 100644 --- a/interfaces/innerkits/dm/screen_manager.h +++ b/interfaces/innerkits/dm/screen_manager.h @@ -55,7 +55,7 @@ public: DMError SetVirtualScreenSurface(ScreenId screenId, sptr surface); bool SetScreenPowerForAll(ScreenPowerState state, PowerStateChangeReason reason); ScreenPowerState GetScreenPower(ScreenId screenId); - DMError SetScreenRotationLocked(bool isLocked); + void SetScreenRotationLocked(bool isLocked); bool IsScreenRotationLocked(); private: ScreenManager(); diff --git a/interfaces/kits/napi/screen_runtime/napi/js_screen_manager.cpp b/interfaces/kits/napi/screen_runtime/napi/js_screen_manager.cpp index 3727124d..cab5634e 100644 --- a/interfaces/kits/napi/screen_runtime/napi/js_screen_manager.cpp +++ b/interfaces/kits/napi/screen_runtime/napi/js_screen_manager.cpp @@ -672,14 +672,8 @@ NativeValue* OnSetScreenRotationLocked(NativeEngine& engine, NativeCallbackInfo& task.Reject(engine, CreateJsError(engine, static_cast(errCode), "Invalidate params.")); return; } - DMError ret = SingletonContainer::Get().SetScreenRotationLocked(isLocked); - if (ret == DMError::DM_OK) { - task.Resolve(engine, engine.CreateUndefined()); - } else { - task.Reject(engine, CreateJsError(engine, static_cast(ret), - "JsScreenManager:SetScreenRotationLocked failed.")); - } - WLOGFI("JsScreenManager::OnSetScreenRotationLocked success, ret = %{public}d", ret); + SingletonContainer::Get().SetScreenRotationLocked(isLocked); + task.Resolve(engine, engine.CreateUndefined()); }; NativeValue* lastParam = (info.argc <= 1) ? nullptr : (info.argv[1]->TypeOf() == NATIVE_FUNCTION ? info.argv[1] : nullptr); diff --git a/interfaces/kits/napi/window_runtime/api/@ohos.window.d.ts b/interfaces/kits/napi/window_runtime/api/@ohos.window.d.ts index a17bdacd..f0770296 100644 --- a/interfaces/kits/napi/window_runtime/api/@ohos.window.d.ts +++ b/interfaces/kits/napi/window_runtime/api/@ohos.window.d.ts @@ -1064,18 +1064,18 @@ declare namespace window { * @since 9 */ enum Orientation { - UNSPECIFIED = 0, - PORTRAIT = 1, - LANDSCAPE = 2, - PORTRAIT_INVERTED = 3, - LANDSCAPE_INVERTED = 4, - AUTO_ROTATION = 5, - AUTO_ROTATION_PORTRAIT = 6, - AUTO_ROTATION_LANDSCAPE = 7, - AUTO_ROTATION_RESTRICTED = 8, - AUTO_ROTATION_PORTRAIT_RESTRICTED = 9, - AUTO_ROTATION_LANDSCAPE_RESTRICTED = 10, - LOCKED = 11, + UNSPECIFIED = 0, + PORTRAIT = 1, + LANDSCAPE = 2, + PORTRAIT_INVERTED = 3, + LANDSCAPE_INVERTED = 4, + AUTO_ROTATION = 5, + AUTO_ROTATION_PORTRAIT = 6, + AUTO_ROTATION_LANDSCAPE = 7, + AUTO_ROTATION_RESTRICTED = 8, + AUTO_ROTATION_PORTRAIT_RESTRICTED = 9, + AUTO_ROTATION_LANDSCAPE_RESTRICTED = 10, + LOCKED = 11, } } From a8077402909b6326f787e6040d9167413e19ecbd Mon Sep 17 00:00:00 2001 From: zhoushicheng Date: Thu, 23 Jun 2022 15:19:11 +0800 Subject: [PATCH 16/81] aafwk->ability_runtime Signed-off-by: zhoushicheng Change-Id: Iab3086665f1370d9ae4d3ae5953e5da130609775 --- extension/window_extension/BUILD.gn | 6 +++--- interfaces/kits/napi/display_runtime/BUILD.gn | 6 +++--- interfaces/kits/napi/screen_recorder/BUILD.gn | 6 +++--- interfaces/kits/napi/screen_runtime/BUILD.gn | 6 +++--- interfaces/kits/napi/window_runtime/BUILD.gn | 6 +++--- windowmanager_aafwk.gni | 9 +++++---- wm/BUILD.gn | 6 +++--- wm/test/systemtest/BUILD.gn | 8 ++++---- wm/test/unittest/BUILD.gn | 8 ++++---- 9 files changed, 31 insertions(+), 30 deletions(-) diff --git a/extension/window_extension/BUILD.gn b/extension/window_extension/BUILD.gn index e4c39095..9aa80105 100644 --- a/extension/window_extension/BUILD.gn +++ b/extension/window_extension/BUILD.gn @@ -42,8 +42,8 @@ ohos_shared_library("libwindow_extension") { configs = [ ":libwindow_extension_private_config" ] deps = [ - "//foundation/ability/ability_runtime/frameworks/js/napi/aafwk/inner/napi_common:napi_common", - "//foundation/ability/ability_runtime/frameworks/kits/appkit:app_context", + "${ability_runtime_napi_path}/inner/napi_common:napi_common", + "${ability_runtime_kits_path}/appkit:app_context", "//foundation/graphic/graphic_2d/rosen/modules/render_service_client:librender_service_client", "//foundation/windowmanager/interfaces/kits/napi/window_runtime:window_native_kit", "//foundation/windowmanager/utils:libwmutil", @@ -71,7 +71,7 @@ config("window_extension_module_private_config") { include_dirs = [ "include", - "${aafwk_kits_path}/ability/ability_runtime/include", + "${ability_runtime_kits_path}/ability/ability_runtime/include", ] } diff --git a/interfaces/kits/napi/display_runtime/BUILD.gn b/interfaces/kits/napi/display_runtime/BUILD.gn index d046ab9e..ce41da04 100644 --- a/interfaces/kits/napi/display_runtime/BUILD.gn +++ b/interfaces/kits/napi/display_runtime/BUILD.gn @@ -35,9 +35,9 @@ ohos_shared_library("display_napi") { configs = [ ":display_config" ] deps = [ - "${aafwk_kits_path}/ability/native:abilitykit_native", - "${aafwk_kits_path}/appkit:app_context", - "${aafwk_kits_path}/appkit:appkit_native", + "${ability_runtime_kits_path}/ability/native:abilitykit_native", + "${ability_runtime_kits_path}/appkit:app_context", + "${ability_runtime_kits_path}/appkit:appkit_native", "../common:wm_napi_common", "//foundation/graphic/graphic_2d/rosen/modules/render_service_client:librender_service_client", "//foundation/windowmanager/dm:libdm", diff --git a/interfaces/kits/napi/screen_recorder/BUILD.gn b/interfaces/kits/napi/screen_recorder/BUILD.gn index 5d30cfb8..c9bfac25 100644 --- a/interfaces/kits/napi/screen_recorder/BUILD.gn +++ b/interfaces/kits/napi/screen_recorder/BUILD.gn @@ -38,9 +38,9 @@ ohos_shared_library("screenrecorder_napi") { configs = [ ":screen_runtime_config" ] deps = [ - "${aafwk_kits_path}/ability/native:abilitykit_native", - "${aafwk_kits_path}/appkit:app_context", - "${aafwk_kits_path}/appkit:appkit_native", + "${ability_runtime_kits_path}/ability/native:abilitykit_native", + "${ability_runtime_kits_path}/appkit:app_context", + "${ability_runtime_kits_path}/appkit:appkit_native", "//foundation/graphic/graphic_2d/rosen/modules/render_service_client:librender_service_client", "//foundation/windowmanager/dm:libdm", "//foundation/windowmanager/dmserver:libdms", diff --git a/interfaces/kits/napi/screen_runtime/BUILD.gn b/interfaces/kits/napi/screen_runtime/BUILD.gn index 03285272..700f04be 100644 --- a/interfaces/kits/napi/screen_runtime/BUILD.gn +++ b/interfaces/kits/napi/screen_runtime/BUILD.gn @@ -37,9 +37,9 @@ ohos_shared_library("screen_napi") { configs = [ ":screen_runtime_config" ] deps = [ - "${aafwk_kits_path}/ability/native:abilitykit_native", - "${aafwk_kits_path}/appkit:app_context", - "${aafwk_kits_path}/appkit:appkit_native", + "${ability_runtime_kits_path}/ability/native:abilitykit_native", + "${ability_runtime_kits_path}/appkit:app_context", + "${ability_runtime_kits_path}/appkit:appkit_native", "//foundation/graphic/graphic_2d/rosen/modules/render_service_client:librender_service_client", "//foundation/windowmanager/dm:libdm", "//foundation/windowmanager/dmserver:libdms", diff --git a/interfaces/kits/napi/window_runtime/BUILD.gn b/interfaces/kits/napi/window_runtime/BUILD.gn index 40bed706..fe1d661a 100644 --- a/interfaces/kits/napi/window_runtime/BUILD.gn +++ b/interfaces/kits/napi/window_runtime/BUILD.gn @@ -77,9 +77,9 @@ ohos_shared_library("window_napi") { configs = [ ":window_manager_napi_config" ] deps = [ ":window_native_kit", - "${aafwk_kits_path}/ability/native:abilitykit_native", - "${aafwk_kits_path}/appkit:app_context", - "${aafwk_kits_path}/appkit:appkit_native", + "${ability_runtime_kits_path}/ability/native:abilitykit_native", + "${ability_runtime_kits_path}/appkit:app_context", + "${ability_runtime_kits_path}/appkit:appkit_native", "//foundation/windowmanager/utils:libwmutil", "//foundation/windowmanager/wm:libwm", "//foundation/windowmanager/wmserver:libwms", diff --git a/windowmanager_aafwk.gni b/windowmanager_aafwk.gni index 9d20e02d..06fa2641 100644 --- a/windowmanager_aafwk.gni +++ b/windowmanager_aafwk.gni @@ -11,8 +11,9 @@ # See the License for the specific language governing permissions and # limitations under the License. -aafwk_inner_api_path = - "//foundation/ability/ability_runtime/interfaces/inner_api" -aafwk_kits_path = "//foundation/ability/ability_runtime/frameworks/kits" ability_runtime_path = "//foundation/ability/ability_runtime" -aafwk_services_path = "//foundation/ability/ability_runtime/services" +ability_runtime_inner_api_path = + "${ability_runtime_path}/interfaces/inner_api" +ability_runtime_kits_path = "${ability_runtime_path}/frameworks/kits" +ability_runtime_services_path = "${ability_runtime_path}/services" +ability_runtime_napi_path = "${ability_runtime_path}/frameworks/js/napi/aafwk" \ No newline at end of file diff --git a/wm/BUILD.gn b/wm/BUILD.gn index e57dcb7f..1410bd11 100644 --- a/wm/BUILD.gn +++ b/wm/BUILD.gn @@ -20,9 +20,9 @@ config("libwm_private_config") { include_dirs = [ "include", "../wmserver/include", - "${aafwk_kits_path}/ability/ability_runtime/include", - "${aafwk_inner_api_path}/ability_manager/include", - "${aafwk_inner_api_path}/app_manager/include/appmgr", + "${ability_runtime_kits_path}/ability/ability_runtime/include", + "${ability_runtime_inner_api_path}/ability_manager/include", + "${ability_runtime_inner_api_path}/app_manager/include/appmgr", "//third_party/jsoncpp/include", "//third_party/json/include", ] diff --git a/wm/test/systemtest/BUILD.gn b/wm/test/systemtest/BUILD.gn index 8c89f3a4..fdab657d 100644 --- a/wm/test/systemtest/BUILD.gn +++ b/wm/test/systemtest/BUILD.gn @@ -268,11 +268,11 @@ config("wm_systemtest_common_public_config") { "//third_party/googletest/googlemock/include", # for abilityContext - "${aafwk_kits_path}/ability/ability_runtime/include", - "${aafwk_kits_path}/appkit/native/ability_runtime/context", + "${ability_runtime_kits_path}/ability/ability_runtime/include", + "${ability_runtime_kits_path}/appkit/native/ability_runtime/context", "//base/global/resource_management/interfaces/inner_api/include", "//third_party/node/deps/icu-small/source/common", - "${aafwk_inner_api_path}/ability_manager/include", + "${ability_runtime_inner_api_path}/ability_manager/include", "//third_party/jsoncpp/include", "//third_party/json/include", @@ -301,7 +301,7 @@ ohos_static_library("wm_systemtest_common") { "//foundation/arkui/ace_engine/interfaces/inner_api/ace:ace_uicontent", # need delete it for abilitycontext - "${aafwk_inner_api_path}/ability_manager:ability_manager", + "${ability_runtime_inner_api_path}/ability_manager:ability_manager", "//foundation/arkui/napi:ace_napi", "//foundation/graphic/graphic_2d/rosen/modules/animation/window_animation:window_animation", "//foundation/graphic/graphic_2d/rosen/modules/render_service_client:librender_service_client", diff --git a/wm/test/unittest/BUILD.gn b/wm/test/unittest/BUILD.gn index 3299ca27..6e4f2885 100644 --- a/wm/test/unittest/BUILD.gn +++ b/wm/test/unittest/BUILD.gn @@ -144,11 +144,11 @@ config("wm_unittest_common_public_config") { "//third_party/googletest/googlemock/include", # for abilityContext - "${aafwk_kits_path}/ability/ability_runtime/include", - "${aafwk_kits_path}/appkit/native/ability_runtime/context", + "${ability_runtime_kits_path}/ability/ability_runtime/include", + "${ability_runtime_kits_path}/appkit/native/ability_runtime/context", "//base/global/resource_management/interfaces/inner_api/include", "//third_party/node/deps/icu-small/source/common", - "${aafwk_inner_api_path}/ability_manager/include", + "${ability_runtime_inner_api_path}/ability_manager/include", "//third_party/jsoncpp/include", "//third_party/json/include", @@ -174,7 +174,7 @@ ohos_static_library("wm_unittest_common") { "//base/powermgr/power_manager/interfaces/innerkits:powermgr_client", # need delete it for abilitycontext - "${aafwk_inner_api_path}/ability_manager:ability_manager", + "${ability_runtime_inner_api_path}/ability_manager:ability_manager", "//foundation/arkui/ace_engine/interfaces/inner_api/ace:ace_uicontent", "//foundation/arkui/napi:ace_napi", "//foundation/distributedschedule/safwk/interfaces/innerkits/safwk:system_ability_fwk", From ddf0849f57adcb32e7c07b9efb95b93dbe8c5125 Mon Sep 17 00:00:00 2001 From: xpeng Date: Thu, 23 Jun 2022 16:55:47 +0800 Subject: [PATCH 17/81] subscribe sensor when boot animation is finished, add switch to enabled/disabled autoraotation by command line Signed-off-by: xpeng Change-Id: I91875d122a382add6bf8c43cc2a74895f21d1564 --- dmserver/include/display_manager_service.h | 2 ++ dmserver/include/display_manager_service_inner.h | 1 + dmserver/src/display_manager_service.cpp | 14 +++++++++++++- dmserver/src/display_manager_service_inner.cpp | 5 +++++ wmserver/src/window_node_container.cpp | 3 +++ 5 files changed, 24 insertions(+), 1 deletion(-) diff --git a/dmserver/include/display_manager_service.h b/dmserver/include/display_manager_service.h index c5a74a1d..ac5fb515 100644 --- a/dmserver/include/display_manager_service.h +++ b/dmserver/include/display_manager_service.h @@ -59,6 +59,7 @@ public: bool SetOrientation(ScreenId screenId, Orientation orientation) override; bool SetOrientationFromWindow(ScreenId screenId, Orientation orientation); bool SetRotationFromWindow(ScreenId screenId, Rotation targetRotation); + void SetGravitySensorSubscriptionEnabled(); std::shared_ptr GetDisplaySnapshot(DisplayId displayId) override; ScreenId GetRSScreenId(DisplayId displayId) const; @@ -120,6 +121,7 @@ private: sptr displayDumper_; static float customVirtualPixelRatio_; std::map accessTokenIdMaps_; + bool isAutoRotationOpen_; }; } // namespace OHOS::Rosen diff --git a/dmserver/include/display_manager_service_inner.h b/dmserver/include/display_manager_service_inner.h index 76f39ef8..90e4d1d2 100644 --- a/dmserver/include/display_manager_service_inner.h +++ b/dmserver/include/display_manager_service_inner.h @@ -45,6 +45,7 @@ public: void RegisterDisplayChangeListener(sptr listener); bool SetOrientationFromWindow(DisplayId displayId, Orientation orientation); bool SetRotationFromWindow(DisplayId displayId, Rotation targetRotation); + void SetGravitySensorSubscriptionEnabled(); void GetFullScreenWindowRequestedOrientation(DisplayId displayId, Orientation &orientation); }; } // namespace OHOS::Rosen diff --git a/dmserver/src/display_manager_service.cpp b/dmserver/src/display_manager_service.cpp index 03f74564..739a4582 100644 --- a/dmserver/src/display_manager_service.cpp +++ b/dmserver/src/display_manager_service.cpp @@ -24,6 +24,7 @@ #include "display_manager_config.h" #include "dm_common.h" #include "permission.h" +#include "parameters.h" #include "screen_rotation_controller.h" #include "transaction/rs_interfaces.h" #include "window_manager_hilog.h" @@ -52,7 +53,9 @@ DisplayManagerService::DisplayManagerService() : SystemAbility(DISPLAY_MANAGER_S abstractScreenController_(new AbstractScreenController(mutex_)), displayPowerController_(new DisplayPowerController(mutex_, std::bind(&DisplayManagerService::NotifyDisplayStateChange, this, - std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4))) + std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4))), + isAutoRotationOpen_(OHOS::system::GetParameter( + "persist.display.ar.enabled", "1") == "1") // autoRotation default enabled { } @@ -576,4 +579,13 @@ void DisplayManagerService::SetScreenRotationLocked(bool isLocked) { ScreenRotationController::SetScreenRotationLocked(isLocked); } + +void DisplayManagerService::SetGravitySensorSubscriptionEnabled() +{ + if (!isAutoRotationOpen_) { + WLOGFE("autoRotation is not open"); + return; + } + ScreenRotationController::SubscribeGravitySensor(); +} } // namespace OHOS::Rosen \ No newline at end of file diff --git a/dmserver/src/display_manager_service_inner.cpp b/dmserver/src/display_manager_service_inner.cpp index 8660deec..43020920 100644 --- a/dmserver/src/display_manager_service_inner.cpp +++ b/dmserver/src/display_manager_service_inner.cpp @@ -152,4 +152,9 @@ void DisplayManagerServiceInner::GetFullScreenWindowRequestedOrientation(Display { DisplayManagerService::GetInstance().GetFullScreenWindowRequestedOrientation(displayId, orientation); } + +void DisplayManagerServiceInner::SetGravitySensorSubscriptionEnabled() +{ + DisplayManagerService::GetInstance().SetGravitySensorSubscriptionEnabled(); +} } // namespace OHOS::Rosen \ No newline at end of file diff --git a/wmserver/src/window_node_container.cpp b/wmserver/src/window_node_container.cpp index fdc02692..9d19a91a 100644 --- a/wmserver/src/window_node_container.cpp +++ b/wmserver/src/window_node_container.cpp @@ -304,6 +304,9 @@ WMError WindowNodeContainer::RemoveWindowNode(sptr& node) if (node->GetWindowType() == WindowType::WINDOW_TYPE_KEYGUARD) { isScreenLocked_ = false; } + if (node->GetWindowType() == WindowType::WINDOW_TYPE_BOOT_ANIMATION) { + DisplayManagerServiceInner::GetInstance().SetGravitySensorSubscriptionEnabled(); + } WLOGFI("RemoveWindowNode windowId: %{public}u end", node->GetWindowId()); return WMError::WM_OK; } From cb0f7c0bd1fb308fbadbf79e34b7e726b0f7591b Mon Sep 17 00:00:00 2001 From: leafly2021 Date: Fri, 24 Jun 2022 08:35:52 +0800 Subject: [PATCH 18/81] remove MaxmizeWindow Signed-off-by: leafly2021 Change-Id: I267d482c4c0ac06aee0048e4eac314353a9f98c6 --- interfaces/innerkits/wm/window.h | 14 ++++++++ wm/include/window_adapter.h | 1 - wm/src/window_adapter.cpp | 7 ---- .../windowipc_fuzzer/windowipc_fuzzer.cpp | 3 -- wm/test/unittest/mock_window_adapter.h | 1 - wmserver/include/window_controller.h | 1 - wmserver/include/window_manager_service.h | 1 - wmserver/include/window_node_container.h | 1 - wmserver/include/window_root.h | 1 - .../include/zidl/window_manager_interface.h | 2 -- wmserver/include/zidl/window_manager_proxy.h | 1 - wmserver/src/window_controller.cpp | 11 ------ wmserver/src/window_manager_service.cpp | 8 ----- wmserver/src/window_node_container.cpp | 34 +++---------------- wmserver/src/window_root.cpp | 19 ----------- wmserver/src/zidl/window_manager_proxy.cpp | 22 ------------ wmserver/src/zidl/window_manager_stub.cpp | 4 --- 17 files changed, 19 insertions(+), 112 deletions(-) diff --git a/interfaces/innerkits/wm/window.h b/interfaces/innerkits/wm/window.h index c7f91340..2cdea581 100644 --- a/interfaces/innerkits/wm/window.h +++ b/interfaces/innerkits/wm/window.h @@ -127,8 +127,22 @@ public: class Window : public RefBase { public: + /** + * @brief create window, include main_window/sub_window/system_window + * + * @param windowName window name, identify window instance + * @param option window propertion + * @param context ability context + * @return sptr If create window success,return window instance;Otherwise, return nullptr + */ static sptr Create(const std::string& windowName, sptr& option, const std::shared_ptr& context = nullptr); + /** + * @brief find window by windowName + * + * @param windowName + * @return sptr Return the window instance founded + */ static sptr Find(const std::string& windowName); static sptr GetTopWindowWithContext(const std::shared_ptr& context = nullptr); static sptr GetTopWindowWithId(uint32_t mainWinId); diff --git a/wm/include/window_adapter.h b/wm/include/window_adapter.h index 8c1095e8..a659fd86 100644 --- a/wm/include/window_adapter.h +++ b/wm/include/window_adapter.h @@ -49,7 +49,6 @@ public: virtual void ProcessPointUp(uint32_t windowId); virtual void MinimizeAllAppWindows(DisplayId displayId); virtual WMError ToggleShownStateForAllAppWindows(); - virtual WMError MaximizeWindow(uint32_t windowId); virtual WMError SetWindowLayoutMode(WindowLayoutMode mode); virtual WMError UpdateProperty(sptr& windowProperty, PropertyChangeAction action); virtual WMError GetSystemConfig(SystemConfig& systemConfig); diff --git a/wm/src/window_adapter.cpp b/wm/src/window_adapter.cpp index ac9c77db..6ae6be3f 100644 --- a/wm/src/window_adapter.cpp +++ b/wm/src/window_adapter.cpp @@ -149,13 +149,6 @@ WMError WindowAdapter::ToggleShownStateForAllAppWindows() return windowManagerServiceProxy_->ToggleShownStateForAllAppWindows(); } -WMError WindowAdapter::MaximizeWindow(uint32_t windowId) -{ - INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR); - - return windowManagerServiceProxy_->MaximizeWindow(windowId); -} - WMError WindowAdapter::GetSystemConfig(SystemConfig& systemConfig) { INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR); diff --git a/wm/test/fuzztest/windowipc_fuzzer/windowipc_fuzzer.cpp b/wm/test/fuzztest/windowipc_fuzzer/windowipc_fuzzer.cpp index 3b90ebc2..90d1f2fe 100644 --- a/wm/test/fuzztest/windowipc_fuzzer/windowipc_fuzzer.cpp +++ b/wm/test/fuzztest/windowipc_fuzzer/windowipc_fuzzer.cpp @@ -130,9 +130,6 @@ void IPCSpecificInterfaceFuzzTest2(sptr proxy, MessageParcel& sen sendData, reply, option); proxy->SendRequest(static_cast(IWindowManager::WindowManagerMessage::TRANS_ID_UPDATE_LAYOUT_MODE), sendData, reply, option); - - proxy->SendRequest(static_cast(IWindowManager::WindowManagerMessage::TRANS_ID_MAXIMIZE_WINDOW), - sendData, reply, option); proxy->SendRequest(static_cast(IWindowManager::WindowManagerMessage::TRANS_ID_UPDATE_PROPERTY), sendData, reply, option); proxy->SendRequest( diff --git a/wm/test/unittest/mock_window_adapter.h b/wm/test/unittest/mock_window_adapter.h index 8eeca6ba..4b7d529a 100644 --- a/wm/test/unittest/mock_window_adapter.h +++ b/wm/test/unittest/mock_window_adapter.h @@ -32,7 +32,6 @@ public: MOCK_METHOD2(SetWindowBackgroundBlur, WMError(uint32_t windowId, WindowBlurLevel level)); MOCK_METHOD2(SetAlpha, WMError(uint32_t windowId, float alpha)); MOCK_METHOD2(UpdateProperty, WMError(sptr& windowProperty, PropertyChangeAction action)); - MOCK_METHOD1(MaximizeWindow, WMError(uint32_t windowId)); }; } } // namespace OHOS diff --git a/wmserver/include/window_controller.h b/wmserver/include/window_controller.h index 86f44fed..37a7e16c 100644 --- a/wmserver/include/window_controller.h +++ b/wmserver/include/window_controller.h @@ -51,7 +51,6 @@ public: WMError ProcessPointUp(uint32_t windowId); void MinimizeAllAppWindows(DisplayId displayId); WMError ToggleShownStateForAllAppWindows(); - WMError MaximizeWindow(uint32_t windowId); WMError SetWindowLayoutMode(WindowLayoutMode mode); WMError UpdateProperty(sptr& property, PropertyChangeAction action); void NotifySystemBarTints(); diff --git a/wmserver/include/window_manager_service.h b/wmserver/include/window_manager_service.h index b92d1c75..c9a5fe13 100644 --- a/wmserver/include/window_manager_service.h +++ b/wmserver/include/window_manager_service.h @@ -83,7 +83,6 @@ public: WMError GetTopWindowId(uint32_t mainWinId, uint32_t& topWinId) override; void MinimizeAllAppWindows(DisplayId displayId) override; WMError ToggleShownStateForAllAppWindows() override; - WMError MaximizeWindow(uint32_t windowId) override; WMError SetWindowLayoutMode(WindowLayoutMode mode) override; WMError UpdateProperty(sptr& windowProperty, PropertyChangeAction action) override; WMError GetAccessibilityWindowInfo(sptr& windowInfo) override; diff --git a/wmserver/include/window_node_container.h b/wmserver/include/window_node_container.h index 1afda27d..ac147ec4 100644 --- a/wmserver/include/window_node_container.h +++ b/wmserver/include/window_node_container.h @@ -81,7 +81,6 @@ public: bool IsAppWindowsEmpty() const; void ProcessWindowStateChange(WindowState state, WindowStateChangeReason reason); void NotifySystemBarTints(std::vector displayIdVec); - void NotifySystemBarDismiss(sptr& node); WMError MinimizeAppNodeExceptOptions(MinimizeReason reason, const std::vector &exceptionalIds = {}, const std::vector &exceptionalModes = {}); WMError SetWindowMode(sptr& node, WindowMode dstMode); diff --git a/wmserver/include/window_root.h b/wmserver/include/window_root.h index 243d9d39..f09cdf09 100644 --- a/wmserver/include/window_root.h +++ b/wmserver/include/window_root.h @@ -61,7 +61,6 @@ public: WMError GetTopWindowId(uint32_t mainWinId, uint32_t& topWinId); void MinimizeAllAppWindows(DisplayId displayId); WMError ToggleShownStateForAllAppWindows(); - WMError MaximizeWindow(uint32_t windowId); WMError SetWindowLayoutMode(DisplayId displayId, WindowLayoutMode mode); void ProcessWindowStateChange(WindowState state, WindowStateChangeReason reason); diff --git a/wmserver/include/zidl/window_manager_interface.h b/wmserver/include/zidl/window_manager_interface.h index 2f4a3c99..a77c7d3f 100644 --- a/wmserver/include/zidl/window_manager_interface.h +++ b/wmserver/include/zidl/window_manager_interface.h @@ -52,7 +52,6 @@ public: TRANS_ID_SET_BACKGROUND_BLUR, TRANS_ID_SET_ALPHA, TRANS_ID_UPDATE_LAYOUT_MODE, - TRANS_ID_MAXIMIZE_WINDOW, TRANS_ID_UPDATE_PROPERTY, TRANS_ID_GET_ACCESSIBILITY_WINDOW_INFO_ID, TRANS_ID_ANIMATION_SET_CONTROLLER, @@ -76,7 +75,6 @@ public: virtual void ProcessPointUp(uint32_t windowId) = 0; virtual void MinimizeAllAppWindows(DisplayId displayId) = 0; virtual WMError ToggleShownStateForAllAppWindows() = 0; - virtual WMError MaximizeWindow(uint32_t windowId) = 0; virtual WMError SetWindowLayoutMode(WindowLayoutMode mode) = 0; virtual WMError UpdateProperty(sptr& windowProperty, PropertyChangeAction action) = 0; virtual void RegisterWindowManagerAgent(WindowManagerAgentType type, diff --git a/wmserver/include/zidl/window_manager_proxy.h b/wmserver/include/zidl/window_manager_proxy.h index 19ef06e1..f7e5d869 100644 --- a/wmserver/include/zidl/window_manager_proxy.h +++ b/wmserver/include/zidl/window_manager_proxy.h @@ -44,7 +44,6 @@ public: void ProcessPointUp(uint32_t windowId) override; void MinimizeAllAppWindows(DisplayId displayId) override; WMError ToggleShownStateForAllAppWindows() override; - WMError MaximizeWindow(uint32_t windowId) override; WMError SetWindowLayoutMode(WindowLayoutMode mode) override; WMError UpdateProperty(sptr& windowProperty, PropertyChangeAction action) override; diff --git a/wmserver/src/window_controller.cpp b/wmserver/src/window_controller.cpp index c243b623..bf0d6144 100644 --- a/wmserver/src/window_controller.cpp +++ b/wmserver/src/window_controller.cpp @@ -690,17 +690,6 @@ WMError WindowController::ToggleShownStateForAllAppWindows() return windowRoot_->ToggleShownStateForAllAppWindows(); } -WMError WindowController::MaximizeWindow(uint32_t windowId) -{ - WMError ret = SetWindowMode(windowId, WindowMode::WINDOW_MODE_FULLSCREEN); - if (ret != WMError::WM_OK) { - return ret; - } - ret = windowRoot_->MaximizeWindow(windowId); - FlushWindowInfo(windowId); - return ret; -} - WMError WindowController::GetTopWindowId(uint32_t mainWinId, uint32_t& topWinId) { return windowRoot_->GetTopWindowId(mainWinId, topWinId); diff --git a/wmserver/src/window_manager_service.cpp b/wmserver/src/window_manager_service.cpp index f36feb3b..1b4987c6 100644 --- a/wmserver/src/window_manager_service.cpp +++ b/wmserver/src/window_manager_service.cpp @@ -546,14 +546,6 @@ WMError WindowManagerService::ToggleShownStateForAllAppWindows() return WMError::WM_OK; } -WMError WindowManagerService::MaximizeWindow(uint32_t windowId) -{ - return wmsTaskLooper_->ScheduleTask([this, windowId]() { - WM_SCOPED_TRACE("wms:MaximizeWindow"); - return windowController_->MaximizeWindow(windowId); - }).get(); -} - WMError WindowManagerService::GetTopWindowId(uint32_t mainWinId, uint32_t& topWinId) { return wmsTaskLooper_->ScheduleTask([this, &topWinId, mainWinId]() { diff --git a/wmserver/src/window_node_container.cpp b/wmserver/src/window_node_container.cpp index 9d19a91a..72e4e93b 100644 --- a/wmserver/src/window_node_container.cpp +++ b/wmserver/src/window_node_container.cpp @@ -868,44 +868,20 @@ void WindowNodeContainer::NotifyIfKeyboardRegionChanged(const sptr& WLOGFE("does not have correct callingWindowMode for input method window"); } -void WindowNodeContainer::NotifySystemBarDismiss(sptr& node) -{ - WM_FUNCTION_TRACE(); - if (node == nullptr) { - WLOGE("could not find window"); - return; - } - SystemBarRegionTints tints; - auto& sysBarPropMapNode = node->GetSystemBarProperty(); - SysBarTintMap& sysBarTintMap = displayGroupController_->sysBarTintMaps_[node->GetDisplayId()]; - for (auto it : sysBarPropMapNode) { - it.second.enable_ = false; - node->SetSystemBarProperty(it.first, it.second); - WLOGFI("set system bar enable to false, id: %{public}u, type: %{public}d", - node->GetWindowId(), static_cast(it.first)); - if (sysBarTintMap[it.first].prop_.enable_) { - sysBarTintMap[it.first].prop_.enable_ = false; - tints.emplace_back(sysBarTintMap[it.first]); - WLOGFI("notify system bar dismiss, type: %{public}d", static_cast(it.first)); - } - } - WindowManagerAgentController::GetInstance().UpdateSystemBarRegionTints(node->GetDisplayId(), tints); -} - void WindowNodeContainer::NotifySystemBarTints(std::vector displayIdVec) { WM_FUNCTION_TRACE(); if (displayIdVec.size() != displayGroupController_->sysBarTintMaps_.size()) { - WLOGE("the number of display is error"); + WLOGE("[Immersive] the number of display is error"); } for (auto displayId : displayIdVec) { SystemBarRegionTints tints; SysBarTintMap& sysBarTintMap = displayGroupController_->sysBarTintMaps_[displayId]; for (auto it : sysBarTintMap) { - WLOGFI("system bar cur notify, type: %{public}d, " \ - "visible: %{public}d, color: %{public}x | %{public}x, " \ - "region: [%{public}d, %{public}d, %{public}d, %{public}d]", + WLOGFI("[Immersive] system bar cur notify, T: %{public}d, " \ + "V: %{public}d, C: %{public}x | %{public}x, " \ + "R: [%{public}d, %{public}d, %{public}d, %{public}d]", static_cast(it.first), sysBarTintMap[it.first].prop_.enable_, sysBarTintMap[it.first].prop_.backgroundColor_, sysBarTintMap[it.first].prop_.contentColor_, @@ -920,7 +896,7 @@ void WindowNodeContainer::NotifySystemBarTints(std::vector displayIdV void WindowNodeContainer::NotifyDockWindowStateChanged(sptr& node, bool isEnable) { WM_FUNCTION_TRACE(); - WLOGFI("begin isEnable: %{public}d", isEnable); + WLOGFI("[Immersive] begin isEnable: %{public}d", isEnable); if (isEnable) { for (auto& windowNode : appWindowNode_->children_) { if (windowNode->GetWindowId() == node->GetWindowId()) { diff --git a/wmserver/src/window_root.cpp b/wmserver/src/window_root.cpp index 4f7b1263..d6ae2bac 100644 --- a/wmserver/src/window_root.cpp +++ b/wmserver/src/window_root.cpp @@ -331,25 +331,6 @@ WMError WindowRoot::ToggleShownStateForAllAppWindows() return res; } -WMError WindowRoot::MaximizeWindow(uint32_t windowId) -{ - auto node = GetWindowNode(windowId); - if (node == nullptr) { - WLOGFE("could not find window"); - return WMError::WM_ERROR_NULLPTR; - } - auto container = GetOrCreateWindowNodeContainer(node->GetDisplayId()); - if (container == nullptr) { - WLOGFE("add window failed, window container could not be found"); - return WMError::WM_ERROR_NULLPTR; - } - auto property = node->GetWindowProperty(); - uint32_t flags = property->GetWindowFlags() & (~(static_cast(WindowFlag::WINDOW_FLAG_NEED_AVOID))); - property->SetWindowFlags(flags); - container->NotifySystemBarDismiss(node); - return WMError::WM_OK; -} - void WindowRoot::DestroyLeakStartingWindow() { WLOGFI("DestroyLeakStartingWindow is called"); diff --git a/wmserver/src/zidl/window_manager_proxy.cpp b/wmserver/src/zidl/window_manager_proxy.cpp index 0a7b7dcf..fe9b5390 100644 --- a/wmserver/src/zidl/window_manager_proxy.cpp +++ b/wmserver/src/zidl/window_manager_proxy.cpp @@ -432,28 +432,6 @@ WMError WindowManagerProxy::ToggleShownStateForAllAppWindows() return static_cast(ret); } -WMError WindowManagerProxy::MaximizeWindow(uint32_t windowId) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - if (!data.WriteInterfaceToken(GetDescriptor())) { - WLOGFE("WriteInterfaceToken failed"); - return WMError::WM_ERROR_IPC_FAILED; - } - if (!data.WriteUint32(windowId)) { - WLOGFE("Write windowId failed"); - return WMError::WM_ERROR_IPC_FAILED; - } - if (Remote()->SendRequest(static_cast(WindowManagerMessage::TRANS_ID_MAXIMIZE_WINDOW), - data, reply, option) != ERR_NONE) { - return WMError::WM_ERROR_IPC_FAILED; - } - - int32_t ret = reply.ReadInt32(); - return static_cast(ret); -} - WMError WindowManagerProxy::SetWindowLayoutMode(WindowLayoutMode mode) { MessageParcel data; diff --git a/wmserver/src/zidl/window_manager_stub.cpp b/wmserver/src/zidl/window_manager_stub.cpp index 86f7e5c8..b886abae 100644 --- a/wmserver/src/zidl/window_manager_stub.cpp +++ b/wmserver/src/zidl/window_manager_stub.cpp @@ -148,10 +148,6 @@ int32_t WindowManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, M reply.WriteInt32(static_cast(errCode)); break; } - case WindowManagerMessage::TRANS_ID_MAXIMIZE_WINDOW: { - MaximizeWindow(data.ReadUint32()); - break; - } case WindowManagerMessage::TRANS_ID_UPDATE_LAYOUT_MODE: { WindowLayoutMode mode = static_cast(data.ReadUint32()); WMError errCode = SetWindowLayoutMode(mode); From add5847c0ab1bfbae94d940553933e58ee8acfc3 Mon Sep 17 00:00:00 2001 From: xpeng Date: Fri, 24 Jun 2022 09:29:48 +0800 Subject: [PATCH 19/81] Get Orientation value from abilityinfo when creating window Signed-off-by: xpeng Change-Id: I2aa3f4b9b917003e67e6fc84769b83b91b22a2c3 --- dmserver/src/display_manager_service.cpp | 2 +- wm/include/window_impl.h | 20 ++++++++++++++++++++ wm/src/window_impl.cpp | 18 ++++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/dmserver/src/display_manager_service.cpp b/dmserver/src/display_manager_service.cpp index 739a4582..85e35de8 100644 --- a/dmserver/src/display_manager_service.cpp +++ b/dmserver/src/display_manager_service.cpp @@ -23,8 +23,8 @@ #include "display_manager_agent_controller.h" #include "display_manager_config.h" #include "dm_common.h" -#include "permission.h" #include "parameters.h" +#include "permission.h" #include "screen_rotation_controller.h" #include "transaction/rs_interfaces.h" #include "window_manager_hilog.h" diff --git a/wm/include/window_impl.h b/wm/include/window_impl.h index 9b433e12..1fb04ba5 100644 --- a/wm/include/window_impl.h +++ b/wm/include/window_impl.h @@ -34,6 +34,8 @@ #include "wm_common_inner.h" #include "wm_common.h" +using OHOS::AppExecFwk::DisplayOrientation; + namespace OHOS { namespace Rosen { union ColorParam { @@ -54,6 +56,23 @@ union ColorParam { #endif uint32_t value; }; + +const std::map ABILITY_TO_WMS_ORIENTATION_MAP { + {DisplayOrientation::UNSPECIFIED, Orientation::UNSPECIFIED }, + {DisplayOrientation::LANDSCAPE, Orientation::HORIZONTAL }, + {DisplayOrientation::PORTRAIT, Orientation::VERTICAL }, + {DisplayOrientation::FOLLOWRECENT, Orientation::UNSPECIFIED }, + {DisplayOrientation::LANDSCAPE_INVERTED, Orientation::REVERSE_HORIZONTAL }, + {DisplayOrientation::PORTRAIT_INVERTED, Orientation::REVERSE_VERTICAL }, + {DisplayOrientation::AUTO_ROTATION, Orientation::SENSOR }, + {DisplayOrientation::AUTO_ROTATION_LANDSCAPE, Orientation::SENSOR_HORIZONTAL }, + {DisplayOrientation::AUTO_ROTATION_PORTRAIT, Orientation::SENSOR_VERTICAL }, + {DisplayOrientation::AUTO_ROTATION_RESTRICTED, Orientation::AUTO_ROTATION_RESTRICTED }, + {DisplayOrientation::AUTO_ROTATION_LANDSCAPE_RESTRICTED, Orientation::AUTO_ROTATION_LANDSCAPE_RESTRICTED }, + {DisplayOrientation::AUTO_ROTATION_PORTRAIT_RESTRICTED, Orientation::AUTO_ROTATION_PORTRAIT_RESTRICTED }, + {DisplayOrientation::LOCKED, Orientation::LOCKED }, +}; + class WindowImpl : public Window { using ListenerTaskCallback = std::function; using EventHandler = OHOS::AppExecFwk::EventHandler; @@ -314,6 +333,7 @@ private: void UpdateDragType(); void InitListenerHandler(); bool CheckCameraFloatingWindowMultiCreated(WindowType type); + void SetOrientationFromAbility(); // colorspace, gamut using ColorSpaceConvertMap = struct { diff --git a/wm/src/window_impl.cpp b/wm/src/window_impl.cpp index 66cfeb33..a5f1c69d 100644 --- a/wm/src/window_impl.cpp +++ b/wm/src/window_impl.cpp @@ -690,6 +690,7 @@ WMError WindowImpl::Create(const std::string& parentName, const std::shared_ptr< } WLOGFI("get stretchable enable:%{public}d", windowSystemConfig_.isStretchable_); property_->SetStretchable(windowSystemConfig_.isStretchable_); + SetOrientationFromAbility(); } } WMError ret = SingletonContainer::Get().CreateWindow(windowAgent, property_, surfaceNode_, @@ -1207,6 +1208,23 @@ WMError WindowImpl::NotifyWindowTransition(TransitionReason reason) return SingletonContainer::Get().NotifyWindowTransition(fromInfo, toInfo); } +void WindowImpl::SetOrientationFromAbility() +{ + auto abilityContext = AbilityRuntime::Context::ConvertTo(context_); + if (abilityContext == nullptr) { + WLOGFE("id:%{public}d is not ability Window", property_->GetWindowId()); + return; + } + auto abilityInfo = abilityContext->GetAbilityInfo(); + Orientation orientation = ABILITY_TO_WMS_ORIENTATION_MAP.at(static_cast( + static_cast(abilityInfo->orientation))); + if (orientation < Orientation::BEGIN || orientation > Orientation::END) { + WLOGFE("Set orientation from ability failed"); + return; + } + property_->SetRequestedOrientation(orientation); +} + WMError WindowImpl::Minimize() { WLOGFI("[Client] Window %{public}u Minimize", property_->GetWindowId()); From 2bbf918c6e462a354338f4cfd08e966c6a679c99 Mon Sep 17 00:00:00 2001 From: zcdqs Date: Fri, 24 Jun 2022 12:38:23 +0800 Subject: [PATCH 20/81] add set nullptr before uicontent destroy Signed-off-by: zcdqs Change-Id: I968162916966e6e43b3dba400eaf2130b7c25dbf --- wm/include/window_impl.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/wm/include/window_impl.h b/wm/include/window_impl.h index 9b433e12..0f8f55b7 100644 --- a/wm/include/window_impl.h +++ b/wm/include/window_impl.h @@ -253,7 +253,11 @@ private: } inline void NotifyBeforeDestroy(std::string windowName) { - CALL_UI_CONTENT(Destroy); + if (uiContent_ != nullptr) { + auto uiContent = std::move(uiContent_); + uiContent_ = nullptr; + uiContent->Destroy(); + } if (notifyNativefunc_) { notifyNativefunc_(windowName); } From a56007d56e07c69bdde3da5ba9a14f3657551444 Mon Sep 17 00:00:00 2001 From: chyyy0213 Date: Thu, 23 Jun 2022 17:19:17 +0800 Subject: [PATCH 21/81] motify startingWindow show before animation Signed-off-by: chyyy0213 Change-Id: I81b6955be46df30cd2c00bd03e362df4063fcaf2 Signed-off-by: chyyy0213 --- wmserver/src/remote_animation.cpp | 4 ++-- wmserver/src/starting_window.cpp | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/wmserver/src/remote_animation.cpp b/wmserver/src/remote_animation.cpp index de2d791b..47021891 100644 --- a/wmserver/src/remote_animation.cpp +++ b/wmserver/src/remote_animation.cpp @@ -309,9 +309,9 @@ sptr RemoteAnimation::CreateWindowAnimationTarget(sptr< } auto& stagingProperties = windowAnimationTarget->surfaceNode_->GetStagingProperties(); - auto bounds = stagingProperties.GetBounds(); + auto rect = windowNode->GetWindowRect(); // 0, 1, 2, 3: convert bounds to RectF - auto boundsRect = RectF(bounds[0], bounds[1], bounds[2], bounds[3]); + auto boundsRect = RectF(rect.posX_, rect.posY_, rect.width_, rect.height_); windowAnimationTarget->windowBounds_ = RRect(boundsRect, stagingProperties.GetCornerRadius()); return windowAnimationTarget; } diff --git a/wmserver/src/starting_window.cpp b/wmserver/src/starting_window.cpp index d1733e9f..c183d372 100644 --- a/wmserver/src/starting_window.cpp +++ b/wmserver/src/starting_window.cpp @@ -42,6 +42,7 @@ sptr StartingWindow::CreateWindowNode(sptr inf property->SetWindowMode(info->GetWindowMode()); property->SetDisplayId(info->GetDisplayId()); property->SetWindowType(info->GetWindowType()); + property->AddWindowFlag(WindowFlag::WINDOW_FLAG_NEED_AVOID); if (info->GetShowFlagWhenLocked()) { property->AddWindowFlag(WindowFlag::WINDOW_FLAG_SHOW_WHEN_LOCKED); } @@ -97,6 +98,9 @@ void StartingWindow::DrawStartingWindow(sptr& node, return; } Rect rect = node->GetWindowRect(); + if (RemoteAnimation::CheckAnimationController() && node->leashWinSurfaceNode_) { + node->leashWinSurfaceNode_->SetBounds(rect.posX_, rect.posY_, -1, -1); + } if (pixelMap == nullptr) { surfaceDraw_.DrawBackgroundColor(node->startingWinSurfaceNode_, rect, bkgColor); return; From 8d14ce45ad85f39aab268ae60e20d02e90c72c99 Mon Sep 17 00:00:00 2001 From: zengqingyu Date: Fri, 24 Jun 2022 15:04:13 +0800 Subject: [PATCH 22/81] fix screen js enum usages Signed-off-by: zengqingyu Change-Id: I6f62aeb489e3fd53e19cc38e791596e098aacb35 --- .../kits/napi/display_runtime/js_display.h | 9 +++++ .../display_runtime/js_display_manager.cpp | 32 ++++++++++++++++++ .../screen_runtime/napi/js_screen_manager.cpp | 33 +++++++++++++++++++ 3 files changed, 74 insertions(+) diff --git a/interfaces/kits/napi/display_runtime/js_display.h b/interfaces/kits/napi/display_runtime/js_display.h index e2f7eb93..d9506d7f 100644 --- a/interfaces/kits/napi/display_runtime/js_display.h +++ b/interfaces/kits/napi/display_runtime/js_display.h @@ -33,6 +33,15 @@ public: private: sptr display_ = nullptr; }; +enum class DisplayStateMode : uint32_t { + STATE_UNKNOWN = 0, + STATE_OFF, + STATE_ON, + STATE_DOZE, + STATE_DOZE_SUSPEND, + STATE_VR, + STATE_ON_SUSPEND +}; } // namespace Rosen } // namespace OHOS #endif \ No newline at end of file diff --git a/interfaces/kits/napi/display_runtime/js_display_manager.cpp b/interfaces/kits/napi/display_runtime/js_display_manager.cpp index 00d9b586..b4c113ec 100644 --- a/interfaces/kits/napi/display_runtime/js_display_manager.cpp +++ b/interfaces/kits/napi/display_runtime/js_display_manager.cpp @@ -328,6 +328,36 @@ NativeValue* CreateJsDisplayArrayObject(NativeEngine& engine, std::vectorCreateObject(); + NativeObject *object = ConvertNativeValueTo(objValue); + if (object == nullptr) { + WLOGFE("Failed to get object"); + return nullptr; + } + + object->SetProperty("STATE_UNKNOWN", CreateJsValue(*engine, static_cast(DisplayStateMode::STATE_UNKNOWN))); + object->SetProperty("STATE_OFF", CreateJsValue(*engine, static_cast(DisplayStateMode::STATE_OFF))); + object->SetProperty("STATE_ON", CreateJsValue(*engine, static_cast(DisplayStateMode::STATE_ON))); + object->SetProperty("STATE_DOZE", + CreateJsValue(*engine, static_cast(DisplayStateMode::STATE_DOZE))); + object->SetProperty("STATE_DOZE_SUSPEND", + CreateJsValue(*engine, static_cast(DisplayStateMode::STATE_DOZE_SUSPEND))); + object->SetProperty("STATE_VR", + CreateJsValue(*engine, static_cast(DisplayStateMode::STATE_VR))); + object->SetProperty("STATE_ON_SUSPEND", + CreateJsValue(*engine, static_cast(DisplayStateMode::STATE_ON_SUSPEND))); + return objValue; +} + NativeValue* JsDisplayManagerInit(NativeEngine* engine, NativeValue* exportObj) { WLOGFI("JsDisplayManagerInit is called"); @@ -346,6 +376,8 @@ NativeValue* JsDisplayManagerInit(NativeEngine* engine, NativeValue* exportObj) std::unique_ptr jsDisplayManager = std::make_unique(engine); object->SetNativePointer(jsDisplayManager.release(), JsDisplayManager::Finalizer, nullptr); + object->SetProperty("DisplayState", InitDisplayState(engine)); + BindNativeFunction(*engine, *object, "getDefaultDisplay", JsDisplayManager::GetDefaultDisplay); BindNativeFunction(*engine, *object, "getDefaultDisplaySync", JsDisplayManager::GetDefaultDisplaySync); BindNativeFunction(*engine, *object, "getAllDisplay", JsDisplayManager::GetAllDisplay); diff --git a/interfaces/kits/napi/screen_runtime/napi/js_screen_manager.cpp b/interfaces/kits/napi/screen_runtime/napi/js_screen_manager.cpp index cab5634e..a79fb29d 100644 --- a/interfaces/kits/napi/screen_runtime/napi/js_screen_manager.cpp +++ b/interfaces/kits/napi/screen_runtime/napi/js_screen_manager.cpp @@ -684,6 +684,37 @@ NativeValue* OnSetScreenRotationLocked(NativeEngine& engine, NativeCallbackInfo& } }; +NativeValue* InitScreenOrientation(NativeEngine* engine) +{ + WLOGFI("JsScreenManager::InitScreenOrientation called"); + + if (engine == nullptr) { + WLOGFE("engine is nullptr"); + return nullptr; + } + + NativeValue *objValue = engine->CreateObject(); + NativeObject *object = ConvertNativeValueTo(objValue); + if (object == nullptr) { + WLOGFE("Failed to get object"); + return nullptr; + } + + object->SetProperty("UNSPECIFIED", CreateJsValue(*engine, static_cast(Orientation::UNSPECIFIED))); + object->SetProperty("VERTICAL", CreateJsValue(*engine, static_cast(Orientation::VERTICAL))); + object->SetProperty("HORIZONTAL", CreateJsValue(*engine, static_cast(Orientation::HORIZONTAL))); + object->SetProperty("REVERSE_VERTICAL", + CreateJsValue(*engine, static_cast(Orientation::REVERSE_VERTICAL))); + object->SetProperty("REVERSE_HORIZONTAL", + CreateJsValue(*engine, static_cast(Orientation::REVERSE_HORIZONTAL))); + object->SetProperty("SENSOR", CreateJsValue(*engine, static_cast(Orientation::SENSOR))); + object->SetProperty("SENSOR_VERTICAL", + CreateJsValue(*engine, static_cast(Orientation::SENSOR_VERTICAL))); + object->SetProperty("SENSOR_HORIZONTAL", + CreateJsValue(*engine, static_cast(Orientation::SENSOR_HORIZONTAL))); + return objValue; +} + NativeValue* JsScreenManagerInit(NativeEngine* engine, NativeValue* exportObj) { WLOGFI("JsScreenManagerInit is called"); @@ -702,6 +733,8 @@ NativeValue* JsScreenManagerInit(NativeEngine* engine, NativeValue* exportObj) std::unique_ptr jsScreenManager = std::make_unique(engine); object->SetNativePointer(jsScreenManager.release(), JsScreenManager::Finalizer, nullptr); + object->SetProperty("Orientation", InitScreenOrientation(engine)); + BindNativeFunction(*engine, *object, "getAllScreens", JsScreenManager::GetAllScreens); BindNativeFunction(*engine, *object, "on", JsScreenManager::RegisterScreenManagerCallback); BindNativeFunction(*engine, *object, "off", JsScreenManager::UnregisterScreenMangerCallback); From 943d1480b27e4f73681b32c09403f5b197d0c8f9 Mon Sep 17 00:00:00 2001 From: xiahaiqin Date: Fri, 24 Jun 2022 17:10:19 +0800 Subject: [PATCH 23/81] delete redundant trace Signed-off-by: xiahaiqin Change-Id: I3d75a44878919353702bb20e17dce5665c23c6af --- wm/src/window_impl.cpp | 2 ++ wmserver/src/window_manager_service.cpp | 1 - wmserver/src/window_node_container.cpp | 1 - 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/wm/src/window_impl.cpp b/wm/src/window_impl.cpp index cddff153..d3a899f8 100644 --- a/wm/src/window_impl.cpp +++ b/wm/src/window_impl.cpp @@ -1016,6 +1016,8 @@ WMError WindowImpl::SetBackgroundColor(const std::string& color) } uint32_t colorValue; if (ColorParser::Parse(color, colorValue)) { + WLOGFI("SetBackgroundColor: window: %{public}s, value: [%{public}s, %{public}u]", + name_.c_str(), color.c_str(), colorValue); return SetBackgroundColor(colorValue); } WLOGFE("invalid color string: %{public}s", color.c_str()); diff --git a/wmserver/src/window_manager_service.cpp b/wmserver/src/window_manager_service.cpp index 1b4987c6..a92349ba 100644 --- a/wmserver/src/window_manager_service.cpp +++ b/wmserver/src/window_manager_service.cpp @@ -586,7 +586,6 @@ WMError WindowManagerService::GetAccessibilityWindowInfo(sptrScheduleTask([this, &windowInfo]() { - WM_SCOPED_TRACE("wms:GetAccessibilityWindowInfo"); return windowRoot_->GetAccessibilityWindowInfo(windowInfo); }).get(); } diff --git a/wmserver/src/window_node_container.cpp b/wmserver/src/window_node_container.cpp index af501490..e05d7672 100644 --- a/wmserver/src/window_node_container.cpp +++ b/wmserver/src/window_node_container.cpp @@ -872,7 +872,6 @@ void WindowNodeContainer::NotifyIfKeyboardRegionChanged(const sptr& void WindowNodeContainer::NotifySystemBarTints(std::vector displayIdVec) { - WM_FUNCTION_TRACE(); if (displayIdVec.size() != displayGroupController_->sysBarTintMaps_.size()) { WLOGE("[Immersive] the number of display is error"); } From d181785edf5756f094078ad7722e4b2ad1e5f62e Mon Sep 17 00:00:00 2001 From: xingyanan Date: Sat, 25 Jun 2022 10:42:10 +0800 Subject: [PATCH 24/81] fix split window start from recent bug Signed-off-by: xingyanan Change-Id: Iccf06b7ce9c20d4d8db0a564c1ff2267df474ab3 --- wmserver/src/window_controller.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/wmserver/src/window_controller.cpp b/wmserver/src/window_controller.cpp index bf0d6144..a3d18c52 100644 --- a/wmserver/src/window_controller.cpp +++ b/wmserver/src/window_controller.cpp @@ -72,6 +72,11 @@ void WindowController::StartingWindow(sptr info, sptrGetWindowMode() != info->GetWindowMode()) { + WLOGFW("set starting window mode. starting mode is: %{public}u, window mode is:%{public}u.", + node->GetWindowMode(), info->GetWindowMode()); + node->SetWindowMode(info->GetWindowMode()); + } } if (windowRoot_->AddWindowNode(0, node, true) != WMError::WM_OK) { return; From c6867985dbc5cb9f1006ebae82e9ed5af1fe99e7 Mon Sep 17 00:00:00 2001 From: wlj Date: Tue, 21 Jun 2022 16:28:34 +0800 Subject: [PATCH 25/81] window visibility update Signed-off-by: wlj Change-Id: I37cbcd052ee23a845ee8d70c116a733fedf8d040 --- .../window_visibility_info_test.cpp | 45 +++++++++- wmserver/include/window_manager_service.h | 4 + wmserver/include/window_node.h | 2 +- wmserver/include/window_node_container.h | 2 - wmserver/include/window_root.h | 7 ++ wmserver/src/window_controller.cpp | 1 + wmserver/src/window_dumper.cpp | 2 + wmserver/src/window_manager_service.cpp | 47 +++++++++- wmserver/src/window_node_container.cpp | 58 ------------ wmserver/src/window_root.cpp | 89 +++++++++++++++++++ 10 files changed, 194 insertions(+), 63 deletions(-) diff --git a/wm/test/systemtest/window_visibility_info_test.cpp b/wm/test/systemtest/window_visibility_info_test.cpp index 0cc7787d..085583c8 100644 --- a/wm/test/systemtest/window_visibility_info_test.cpp +++ b/wm/test/systemtest/window_visibility_info_test.cpp @@ -36,7 +36,7 @@ namespace { } using utils = WindowTestUtils; -constexpr int WAIT_ASYNC_MS_TIME_OUT = 1500; // 1500ms +constexpr int WAIT_ASYNC_MS_TIME_OUT = 2000; // 2000ms #define CHECK_DISPLAY_POWER_STATE_RETURN() \ do { \ @@ -327,6 +327,49 @@ end: window2->Destroy(); subWindow2->Destroy(); } + +/** +* @tc.name: WindowVisibilityInfoTest04 +* @tc.desc: add two main window and sub windows and test callback +* @tc.type: FUNC +*/ +HWTEST_F(WindowVisibilityInfoTest, WindowVisibilityInfoTest04, Function | MediumTest | Level1) +{ + floatAppInfo_.name = "window1"; + floatAppInfo_.rect = {0, 0, 300, 600}; + sptr window1 = utils::CreateTestWindow(floatAppInfo_); + + floatAppInfo_.name = "window2"; + floatAppInfo_.rect = {0, 0, 300, 300}; + sptr window2 = utils::CreateTestWindow(floatAppInfo_); + + floatAppInfo_.name = "window3"; + floatAppInfo_.rect = {0, 300, 300, 300}; + sptr window3 = utils::CreateTestWindow(floatAppInfo_); + + ASSERT_EQ(WMError::WM_OK, window1->Show()); + WaitForCallback(); + CHECK_DISPLAY_POWER_STATE_RETURN(); + ASSERT_EQ(1, visibilityChangedListener_->windowVisibilityInfos_.size()); + ResetCallbackCalledFLag(); + + ASSERT_EQ(WMError::WM_OK, window2->Show()); + WaitForCallback(); + CHECK_DISPLAY_POWER_STATE_RETURN(); + ASSERT_EQ(1, visibilityChangedListener_->windowVisibilityInfos_.size()); + ResetCallbackCalledFLag(); + + ASSERT_EQ(WMError::WM_OK, window3->Show()); + WaitForCallback(); + CHECK_DISPLAY_POWER_STATE_RETURN(); + ASSERT_EQ(2, visibilityChangedListener_->windowVisibilityInfos_.size()); + ResetCallbackCalledFLag(); + +end: + window1->Destroy(); + window2->Destroy(); + window3->Destroy(); +} } } // namespace Rosen } // namespace OHOS diff --git a/wmserver/include/window_manager_service.h b/wmserver/include/window_manager_service.h index b92d1c75..e4b2c19f 100644 --- a/wmserver/include/window_manager_service.h +++ b/wmserver/include/window_manager_service.h @@ -23,6 +23,7 @@ #include #include #include +#include #include "display_change_listener.h" #include "drag_controller.h" #include "freeze_controller.h" @@ -111,6 +112,8 @@ private: bool Init(); void RegisterSnapshotHandler(); void RegisterWindowManagerServiceHandler(); + void RegisterWindowVisibilityChangeCallback(); + void WindowVisibilityChangeCallback(std::shared_ptr occlusionData); void OnWindowEvent(Event event, const sptr& remoteObject); void NotifyDisplayStateChange(DisplayId defaultDisplayId, sptr displayInfo, const std::map>& displayInfoMap, DisplayStateChangeType type); @@ -131,6 +134,7 @@ private: SystemConfig systemConfig_; ModeChangeHotZonesConfig hotZonesConfig_ { false, 0, 0, 0 }; std::unique_ptr wmsTaskLooper_; + RSInterfaces& rsInterface_; bool startingOpen_ = true; }; } diff --git a/wmserver/include/window_node.h b/wmserver/include/window_node.h index 194cbd3c..cd87be66 100644 --- a/wmserver/include/window_node.h +++ b/wmserver/include/window_node.h @@ -115,7 +115,7 @@ public: int32_t priority_ { 0 }; bool requestedVisibility_ { false }; bool currentVisibility_ { false }; - bool isCovered_ { true }; // initial value true to ensure notification when this window is shown + bool isVisible_ { false }; bool isAppCrash_ { false }; bool isPlayAnimationShow_ { false }; bool isPlayAnimationHide_ { false }; diff --git a/wmserver/include/window_node_container.h b/wmserver/include/window_node_container.h index 1afda27d..1f623c9f 100644 --- a/wmserver/include/window_node_container.h +++ b/wmserver/include/window_node_container.h @@ -131,8 +131,6 @@ private: bool TraverseFromTopToBottom(sptr node, const WindowNodeOperationFunc& func) const; bool TraverseFromBottomToTop(sptr node, const WindowNodeOperationFunc& func) const; void RecoverScreenDefaultOrientationIfNeed(DisplayId displayId); - // cannot determine in case of a window covered by union of several windows or with transparent value - void UpdateWindowVisibilityInfos(std::vector>& infos); void RaiseOrderedWindowToTop(std::vector>& orderedNodes, std::vector>& windowNodes); static bool ReadIsWindowAnimationEnabledProperty(); diff --git a/wmserver/include/window_root.h b/wmserver/include/window_root.h index 243d9d39..9b08d698 100644 --- a/wmserver/include/window_root.h +++ b/wmserver/include/window_root.h @@ -17,6 +17,7 @@ #include #include +#include #include "agent_death_recipient.h" #include "display_manager_service_inner.h" @@ -51,6 +52,8 @@ public: bool IsForbidDockSliceMove(DisplayId displayId) const; bool IsDockSliceInExitSplitModeArea(DisplayId displayId) const; void ExitSplitMode(DisplayId displayId); + void NotifyWindowVisibilityChange(std::shared_ptr occlusionData); + void AddSurfaceNodeIdWindowNodePair(uint64_t surfaceNodeId, sptr node); WMError RequestFocus(uint32_t windowId); WMError RequestActiveWindow(uint32_t windowId); @@ -114,8 +117,12 @@ private: void MoveNotShowingWindowToDefaultDisplay(DisplayId defaultDisplayId, DisplayId displayId); WMError PostProcessAddWindowNode(sptr& node, sptr& parentNode, sptr& container); + std::vector> GetWindowVisibilityChangeInfo( + std::shared_ptr occlusionData); std::map> windowNodeMap_; std::map, uint32_t> windowIdMap_; + std::map> surfaceIdWindowNodeMap_; + std::shared_ptr lastOcclusionData_ = std::make_shared(); std::map> windowNodeContainerMap_; std::map> displayIdMap_; diff --git a/wmserver/src/window_controller.cpp b/wmserver/src/window_controller.cpp index 627dd869..df2816a2 100644 --- a/wmserver/src/window_controller.cpp +++ b/wmserver/src/window_controller.cpp @@ -170,6 +170,7 @@ WMError WindowController::CreateWindow(sptr& window, sptrGetWindowType()) && node->startingWindowShown_) { StartingWindow::HandleClientWindowCreate(node, window, windowId, surfaceNode, property, pid, uid); windowRoot_->AddDeathRecipient(node); + windowRoot_->AddSurfaceNodeIdWindowNodePair(surfaceNode->GetId(), node); return WMError::WM_OK; } windowId = GenWindowId(); diff --git a/wmserver/src/window_dumper.cpp b/wmserver/src/window_dumper.cpp index eb11421d..134ee8f6 100644 --- a/wmserver/src/window_dumper.cpp +++ b/wmserver/src/window_dumper.cpp @@ -166,6 +166,7 @@ WMError WindowDumper::DumpSpecifiedWindowInfo(uint32_t windowId, const std::vect } Rect rect = node->GetWindowRect(); std::string isShown_ = node->startingWindowShown_ ? "true" : "false"; + std::string isVisible = node->isVisible_ ? "true" : "false"; std::ostringstream oss; oss << "WindowName: " << node->GetWindowName() << std::endl; oss << "DisplayId: " << node->GetDisplayId() << std::endl; @@ -176,6 +177,7 @@ WMError WindowDumper::DumpSpecifiedWindowInfo(uint32_t windowId, const std::vect oss << "Flag: " << node->GetWindowFlags() << std::endl; oss << "Orientation: " << static_cast(node->GetRequestedOrientation()) << std::endl; oss << "IsStartingWindow: " << isShown_ << std::endl; + oss << "IsVisible: " << isVisible << std::endl; oss << "WindowRect: " << "[ " << rect.posX_ << ", " << rect.posY_ << ", " << rect.width_ << ", " << rect.height_ << " ]" << std::endl; diff --git a/wmserver/src/window_manager_service.cpp b/wmserver/src/window_manager_service.cpp index f36feb3b..9afbb2e7 100644 --- a/wmserver/src/window_manager_service.cpp +++ b/wmserver/src/window_manager_service.cpp @@ -46,7 +46,8 @@ WM_IMPLEMENT_SINGLE_INSTANCE(WindowManagerService) const bool REGISTER_RESULT = SystemAbility::MakeAndRegisterAbility(&SingletonContainer::Get()); -WindowManagerService::WindowManagerService() : SystemAbility(WINDOW_MANAGER_SERVICE_ID, true) +WindowManagerService::WindowManagerService() : SystemAbility(WINDOW_MANAGER_SERVICE_ID, true), + rsInterface_(RSInterfaces::GetInstance()) { windowRoot_ = new WindowRoot( std::bind(&WindowManagerService::OnWindowEvent, this, std::placeholders::_1, std::placeholders::_2)); @@ -71,9 +72,53 @@ void WindowManagerService::OnStart() DisplayManagerServiceInner::GetInstance().RegisterDisplayChangeListener(listener); RegisterSnapshotHandler(); RegisterWindowManagerServiceHandler(); + RegisterWindowVisibilityChangeCallback(); wmsTaskLooper_->Start(); } + +void WindowManagerService::WindowVisibilityChangeCallback(std::shared_ptr occlusionData) +{ + WLOGFD("NotifyWindowVisibilityChange: enter"); + std::weak_ptr weak(occlusionData); + return wmsTaskLooper_->ScheduleTask([this, weak]() { + auto weakOcclusionData = weak.lock(); + if (weakOcclusionData == nullptr) { + WLOGFE("weak occlusionData is nullptr"); + return; + } + windowRoot_->NotifyWindowVisibilityChange(weakOcclusionData); + }).wait(); +} + +void WindowManagerService::RegisterWindowVisibilityChangeCallback() +{ + auto windowVisibilityChangeCb = std::bind(&WindowManagerService::WindowVisibilityChangeCallback, this, + std::placeholders::_1); + if (rsInterface_.RegisterOcclusionChangeCallback(windowVisibilityChangeCb) != WM_OK) { + WLOGFW("WindowManagerService::RegisterWindowVisibilityChangeCallback failed, create async thread!"); + auto fun = [this, windowVisibilityChangeCb]() { + WLOGFI("WindowManagerService::RegisterWindowVisibilityChangeCallback async thread enter!"); + int counter = 0; + while (rsInterface_.RegisterOcclusionChangeCallback(windowVisibilityChangeCb) != WM_OK) { + usleep(10000); // 10000us equals to 10ms + counter++; + if (counter >= 2000) { // wait for 2000 * 10ms = 20s + WLOGFE("WindowManagerService::RegisterWindowVisibilityChangeCallback timeout!"); + return; + } + } + WLOGFI("WindowManagerService::RegisterWindowVisibilityChangeCallback async thread register handler" + " successfully!"); + }; + std::thread thread(fun); + thread.detach(); + WLOGFI("WindowManagerService::RegisterWindowVisibilityChangeCallback async thread has been detached!"); + } else { + WLOGFI("WindowManagerService::RegisterWindowVisibilityChangeCallback OnStart succeed!"); + } +} + void WindowManagerService::RegisterSnapshotHandler() { if (snapshotController_ == nullptr) { diff --git a/wmserver/src/window_node_container.cpp b/wmserver/src/window_node_container.cpp index fdc02692..352a9fdc 100644 --- a/wmserver/src/window_node_container.cpp +++ b/wmserver/src/window_node_container.cpp @@ -179,8 +179,6 @@ WMError WindowNodeContainer::AddWindowNode(sptr& node, sptrAddWindowNode(node); NotifyIfAvoidAreaChanged(node, AvoidControlType::AVOID_NODE_ADD); - std::vector> infos; - UpdateWindowVisibilityInfos(infos); DumpScreenWindowTree(); NotifyAccessibilityWindowInfo(node, WindowUpdateType::WINDOW_UPDATE_ADDED); WLOGFI("AddWindowNode windowId: %{public}u end", node->GetWindowId()); @@ -268,17 +266,6 @@ WMError WindowNodeContainer::RemoveWindowNode(sptr& node) node->requestedVisibility_ = false; node->currentVisibility_ = false; - node->isCovered_ = true; - std::vector> infos = {new WindowVisibilityInfo(node->GetWindowId(), - node->GetCallingPid(), node->GetCallingUid(), false, node->GetWindowType())}; - for (auto& child : node->children_) { - if (child->currentVisibility_) { - child->currentVisibility_ = false; - child->isCovered_ = true; - infos.emplace_back(new WindowVisibilityInfo(child->GetWindowId(), child->GetCallingPid(), - child->GetCallingUid(), false, child->GetWindowType())); - } - } // Remove node from RSTree for (auto& displayId : node->GetShowingDisplays()) { UpdateRSTree(node, displayId, false, node->isPlayAnimationHide_); @@ -297,7 +284,6 @@ WMError WindowNodeContainer::RemoveWindowNode(sptr& node) NotifyDockWindowStateChanged(node, true); } NotifyIfAvoidAreaChanged(node, AvoidControlType::AVOID_NODE_REMOVE); - UpdateWindowVisibilityInfos(infos); DumpScreenWindowTree(); NotifyAccessibilityWindowInfo(node, WindowUpdateType::WINDOW_UPDATE_REMOVED); RecoverScreenDefaultOrientationIfNeed(node->GetDisplayId()); @@ -1720,50 +1706,6 @@ bool WindowNodeContainer::TraverseFromBottomToTop(sptr node, const W return false; } -void WindowNodeContainer::UpdateWindowVisibilityInfos(std::vector>& infos) -{ - // clear vector cache completely, swap with empty vector - auto emptyVector = std::vector(); - currentCoveredArea_.swap(emptyVector); - WindowNodeOperationFunc func = [this, &infos](sptr node) { - if (node == nullptr) { - return false; - } - Rect layoutRect = node->GetWindowRect(); - const Rect& displayRect = displayGroupInfo_->GetDisplayRect(node->GetDisplayId()); - int32_t nodeX = std::max(0, layoutRect.posX_); - int32_t nodeY = std::max(0, layoutRect.posY_); - int32_t nodeXEnd = std::min(displayRect.posX_ + static_cast(displayRect.width_), - layoutRect.posX_ + static_cast(layoutRect.width_)); - int32_t nodeYEnd = std::min(displayRect.posY_ + static_cast(displayRect.height_), - layoutRect.posY_ + static_cast(layoutRect.height_)); - - Rect rectInDisplay = {nodeX, nodeY, - static_cast(nodeXEnd - nodeX), static_cast(nodeYEnd - nodeY)}; - bool isCovered = false; - for (auto& rect : currentCoveredArea_) { - if (rectInDisplay.IsInsideOf(rect)) { - isCovered = true; - WLOGD("UpdateWindowVisibilityInfos: find covered window:%{public}u", node->GetWindowId()); - break; - } - } - if (!isCovered) { - currentCoveredArea_.emplace_back(rectInDisplay); - } - if (isCovered != node->isCovered_) { - node->isCovered_ = isCovered; - infos.emplace_back(new WindowVisibilityInfo(node->GetWindowId(), node->GetCallingPid(), - node->GetCallingUid(), !isCovered, node->GetWindowType())); - WLOGD("UpdateWindowVisibilityInfos: covered status changed window:%{public}u, covered:%{public}d", - node->GetWindowId(), isCovered); - } - return false; - }; - TraverseWindowTree(func, true); - WindowManagerAgentController::GetInstance().UpdateWindowVisibilityInfo(infos); -} - float WindowNodeContainer::GetVirtualPixelRatio(DisplayId displayId) const { return layoutPolicy_->GetVirtualPixelRatio(displayId); diff --git a/wmserver/src/window_root.cpp b/wmserver/src/window_root.cpp index 4f7b1263..18fb24cc 100644 --- a/wmserver/src/window_root.cpp +++ b/wmserver/src/window_root.cpp @@ -24,6 +24,7 @@ #include "window_manager_hilog.h" #include "window_manager_service.h" #include "wm_trace.h" +#include "window_manager_agent_controller.h" namespace OHOS { namespace Rosen { @@ -181,6 +182,9 @@ WMError WindowRoot::SaveWindow(const sptr& node) WLOGFI("save windowId %{public}u", node->GetWindowId()); windowNodeMap_.insert(std::make_pair(node->GetWindowId(), node)); + if (node->surfaceNode_ != nullptr) { + surfaceIdWindowNodeMap_.insert(std::make_pair(node->surfaceNode_->GetId(), node)); + } if (node->GetWindowToken()) { AddDeathRecipient(node); } @@ -256,6 +260,69 @@ void WindowRoot::ExitSplitMode(DisplayId displayId) container->ExitSplitMode(displayId); } + +void WindowRoot::AddSurfaceNodeIdWindowNodePair(uint64_t surfaceNodeId, sptr node) +{ + surfaceIdWindowNodeMap_.insert(std::make_pair(surfaceNodeId, node)); +} + +std::vector> WindowRoot::GetWindowVisibilityChangeInfo( + std::shared_ptr occlusionData) +{ + std::vector> visibityChangeInfo; + VisibleData& currentVisibleWindow = occlusionData->GetVisibleData(); + std::sort(currentVisibleWindow.begin(), currentVisibleWindow.end()); + VisibleData& lastVisibleWindow = lastOcclusionData_->GetVisibleData(); + uint32_t i, j; + i = j = 0; + for (; i < lastVisibleWindow.size() && j < currentVisibleWindow.size();) { + if (lastVisibleWindow[i] < currentVisibleWindow[j]) { + visibityChangeInfo.push_back(std::make_pair(lastVisibleWindow[i], false)); + i++; + } else if (lastVisibleWindow[i] > currentVisibleWindow[j]) { + visibityChangeInfo.push_back(std::make_pair(currentVisibleWindow[j], true)); + j++; + } else { + i++; + j++; + } + } + for (; i < lastVisibleWindow.size(); ++i) { + visibityChangeInfo.push_back(std::make_pair(lastVisibleWindow[i], false)); + } + for (; j < currentVisibleWindow.size(); ++j) { + visibityChangeInfo.push_back(std::make_pair(currentVisibleWindow[j], true)); + } + lastOcclusionData_ = occlusionData; + return visibityChangeInfo; +} + +void WindowRoot::NotifyWindowVisibilityChange(std::shared_ptr occlusionData) +{ + std::vector> visibityChangeInfo = GetWindowVisibilityChangeInfo(occlusionData); + std::vector> windowVisibilityInfos; + for (const auto& elem : visibityChangeInfo) { + uint64_t surfaceId = elem.first; + bool isVisible = elem.second; + auto iter = surfaceIdWindowNodeMap_.find(surfaceId); + if (iter == surfaceIdWindowNodeMap_.end()) { + continue; + } + sptr node = iter->second; + if (node == nullptr) { + continue; + } + node->isVisible_ = isVisible; + windowVisibilityInfos.emplace_back(new WindowVisibilityInfo(node->GetWindowId(), node->GetCallingPid(), + node->GetCallingUid(), isVisible, node->GetWindowType())); + WLOGFD("NotifyWindowVisibilityChange: covered status changed window:%{public}u, isVisible:%{public}d", + node->GetWindowId(), isVisible); + } + if (windowVisibilityInfos.size() != 0) { + WindowManagerAgentController::GetInstance().UpdateWindowVisibilityInfo(windowVisibilityInfos); + } +} + std::vector WindowRoot::GetAvoidAreaByType(uint32_t windowId, AvoidAreaType avoidAreaType) { std::vector avoidArea; @@ -631,6 +698,28 @@ WMError WindowRoot::DestroyWindowInner(sptr& node) return WMError::WM_ERROR_DESTROYED_OBJECT; } + std::vector> windowVisibilityInfos; + node->isVisible_ = false; + windowVisibilityInfos.emplace_back(new WindowVisibilityInfo(node->GetWindowId(), node->GetCallingPid(), + node->GetCallingUid(), false, node->GetWindowType())); + WLOGFD("NotifyWindowVisibilityChange: covered status changed window:%{public}u, isVisible:%{public}d", + node->GetWindowId(), node->isVisible_); + WindowManagerAgentController::GetInstance().UpdateWindowVisibilityInfo(windowVisibilityInfos); + + auto cmpFunc = [node](const std::map>::value_type& pair) { + if (pair.second == nullptr) { + return false; + } + if (pair.second->GetWindowId() == node->GetWindowId()) { + return true; + } + return false; + }; + auto iter = std::find_if(surfaceIdWindowNodeMap_.begin(), surfaceIdWindowNodeMap_.end(), cmpFunc); + if (iter != surfaceIdWindowNodeMap_.end()) { + surfaceIdWindowNodeMap_.erase(iter); + } + sptr window = node->GetWindowToken(); if ((window != nullptr) && (window->AsObject() != nullptr)) { if (windowIdMap_.count(window->AsObject()) == 0) { From a8a10bd87b6d52a8573189a3ad6189f2480165e5 Mon Sep 17 00:00:00 2001 From: xiahaiqin Date: Sat, 25 Jun 2022 16:07:53 +0800 Subject: [PATCH 26/81] modify window dump for pid Signed-off-by: xiahaiqin Change-Id: I756967a53b908f320288f1f5c294859b983febf0 --- wmserver/src/window_dumper.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wmserver/src/window_dumper.cpp b/wmserver/src/window_dumper.cpp index eb11421d..a593e553 100644 --- a/wmserver/src/window_dumper.cpp +++ b/wmserver/src/window_dumper.cpp @@ -84,7 +84,7 @@ WMError WindowDumper::DumpScreenGroupWindowInfo(ScreenId screenGroupId, oss << "-------------------------------------ScreenGroup " << screenGroupId << "-------------------------------------" << std::endl; - oss << "WindowName DisplayId Pid WinId Type Mode Flag ZOrd Orientation [ x y w h ]" + oss << "WindowName DisplayId Pid WinId Type Mode Flag ZOrd Orientation [ x y w h ]" << std::endl; std::vector> windowNodes; windowNodeContainer->TraverseContainer(windowNodes); @@ -100,7 +100,7 @@ WMError WindowDumper::DumpScreenGroupWindowInfo(ScreenId screenGroupId, // std::setw is used to set the output width and different width values are set to keep the format aligned. oss << std::left << std::setw(21) << windowName << std::left << std::setw(10) << windowNode->GetDisplayId() - << std::left << std::setw(5) << windowNode->GetCallingPid() + << std::left << std::setw(8) << windowNode->GetCallingPid() << std::left << std::setw(6) << windowNode->GetWindowId() << std::left << std::setw(5) << static_cast(windowNode->GetWindowType()) << std::left << std::setw(5) << static_cast(windowNode->GetWindowMode()) From 85c663e30f108a7a52ce390c27fd086c3eff84f4 Mon Sep 17 00:00:00 2001 From: xiaojianfeng Date: Thu, 23 Jun 2022 22:03:16 +0800 Subject: [PATCH 27/81] Refactor avoidArea Signed-off-by: xiaojianfeng Change-Id: Ic8fedcd7b7231515e46f0e03124943d3ca4e292a --- dmserver/src/display_manager_config.cpp | 3 +- interfaces/innerkits/wm/window.h | 2 +- interfaces/innerkits/wm/wm_common.h | 68 ++- .../napi/window_runtime/api/@ohos.window.d.ts | 32 +- .../window_runtime/window_napi/js_window.cpp | 7 +- .../window_napi/js_window_listener.cpp | 29 +- .../window_napi/js_window_listener.h | 6 +- .../js_window_register_manager.cpp | 24 +- .../window_napi/js_window_register_manager.h | 3 +- .../window_napi/js_window_utils.cpp | 21 +- .../window_napi/js_window_utils.h | 4 +- .../config/other/display_manager_config.xml | 2 + .../config/rk3568/display_manager_config.xml | 2 + utils/include/class_var_definition.h | 4 + utils/include/window_helper.h | 15 +- wm/include/window_adapter.h | 3 +- wm/include/window_agent.h | 2 +- wm/include/window_impl.h | 4 +- wm/include/zidl/window_interface.h | 2 +- wm/include/zidl/window_proxy.h | 2 +- wm/src/window_adapter.cpp | 12 +- wm/src/window_agent.cpp | 4 +- wm/src/window_impl.cpp | 61 ++- wm/src/zidl/window_proxy.cpp | 19 +- wm/src/zidl/window_stub.cpp | 25 +- wm/test/systemtest/BUILD.gn | 1 - wm/test/systemtest/window_immersive_test.cpp | 41 +- .../window_occupied_area_change_test.cpp | 4 +- .../window_split_immersive_test.cpp | 2 +- wm/test/systemtest/window_test_utils.cpp | 8 +- wm/test/unittest/BUILD.gn | 1 - wmserver/include/avoid_area_controller.h | 40 +- wmserver/include/window_controller.h | 2 +- wmserver/include/window_manager_service.h | 3 +- wmserver/include/window_node_container.h | 7 +- wmserver/include/window_root.h | 3 +- .../include/zidl/window_manager_interface.h | 4 +- wmserver/include/zidl/window_manager_proxy.h | 4 +- wmserver/src/avoid_area_controller.cpp | 441 +++++++++++++----- wmserver/src/display_group_controller.cpp | 3 +- wmserver/src/window_controller.cpp | 12 +- wmserver/src/window_dumper.cpp | 2 +- wmserver/src/window_manager_service.cpp | 21 +- wmserver/src/window_node_container.cpp | 73 ++- wmserver/src/window_root.cpp | 34 +- wmserver/src/zidl/window_manager_proxy.cpp | 52 ++- wmserver/src/zidl/window_manager_stub.cpp | 19 +- 47 files changed, 766 insertions(+), 367 deletions(-) diff --git a/dmserver/src/display_manager_config.cpp b/dmserver/src/display_manager_config.cpp index 22efc9e3..aab37b96 100644 --- a/dmserver/src/display_manager_config.cpp +++ b/dmserver/src/display_manager_config.cpp @@ -76,7 +76,8 @@ bool DisplayManagerConfig::LoadConfigXml(const std::string& configFilePath) auto nodeName = curNodePtr->name; if (!xmlStrcmp(nodeName, reinterpret_cast("dpi")) || - !xmlStrcmp(nodeName, reinterpret_cast("defaultDeviceRotationOffset"))) { + !xmlStrcmp(nodeName, reinterpret_cast("defaultDeviceRotationOffset")) || + !xmlStrcmp(nodeName, reinterpret_cast("cutoutArea"))) { ReadIntNumbersConfigInfo(curNodePtr); continue; } diff --git a/interfaces/innerkits/wm/window.h b/interfaces/innerkits/wm/window.h index 2cdea581..0a3684b4 100644 --- a/interfaces/innerkits/wm/window.h +++ b/interfaces/innerkits/wm/window.h @@ -71,7 +71,7 @@ public: class IAvoidAreaChangedListener : virtual public RefBase { public: - virtual void OnAvoidAreaChanged(std::vector avoidAreas) = 0; + virtual void OnAvoidAreaChanged(const AvoidArea avoidAreas, AvoidAreaType type) = 0; }; class IWindowDragListener : virtual public RefBase { diff --git a/interfaces/innerkits/wm/wm_common.h b/interfaces/innerkits/wm/wm_common.h index 82912f9b..5bcd2ab0 100644 --- a/interfaces/innerkits/wm/wm_common.h +++ b/interfaces/innerkits/wm/wm_common.h @@ -16,6 +16,8 @@ #ifndef OHOS_ROSEN_WM_COMMON_H #define OHOS_ROSEN_WM_COMMON_H +#include + namespace OHOS { namespace Rosen { using DisplayId = uint64_t; @@ -199,6 +201,11 @@ struct Rect { return !this->operator==(a); } + bool isUninitializedRect() const + { + return (posX_ == 0 && posY_ == 0 && width_ == 0 && height_ == 0); + } + bool IsInsideOf(const Rect& a) const { return (posX_ >= a.posX_ && posY_ >= a.posY_ && @@ -210,6 +217,7 @@ enum class AvoidAreaType : uint32_t { TYPE_SYSTEM, // area of SystemUI TYPE_CUTOUT, // cutout of screen TYPE_SYSTEM_GESTURE, // area for system gesture + TYPE_KEYBOARD, }; enum class OccupiedAreaType : uint32_t { @@ -226,11 +234,61 @@ enum class WindowAnimation : uint32_t { DEFAULT, }; -struct AvoidArea { - Rect leftRect; - Rect topRect; - Rect rightRect; - Rect bottomRect; +class AvoidArea : public Parcelable { +public: + Rect topRect_ { 0, 0, 0, 0 }; + Rect leftRect_ { 0, 0, 0, 0 }; + Rect rightRect_ { 0, 0, 0, 0 }; + Rect bottomRect_ { 0, 0, 0, 0 }; + + bool operator==(const AvoidArea& a) const + { + return (leftRect_ == a.leftRect_ && topRect_ == a.topRect_ && + rightRect_ == a.rightRect_ && bottomRect_ == a.bottomRect_); + } + + bool operator!=(const AvoidArea& a) const + { + return !this->operator==(a); + } + + bool isEmptyAvoidArea() const + { + return topRect_.isUninitializedRect() && leftRect_.isUninitializedRect() && + rightRect_.isUninitializedRect() && bottomRect_.isUninitializedRect(); + } + + static inline bool WriteParcel(Parcel& parcel, const Rect& rect) + { + return parcel.WriteInt32(rect.posX_) && parcel.WriteInt32(rect.posY_) && + parcel.WriteUint32(rect.width_) && parcel.WriteUint32(rect.height_); + } + + static inline bool ReadParcel(Parcel& parcel, Rect& rect) + { + return parcel.ReadInt32(rect.posX_) && parcel.ReadInt32(rect.posY_) && + parcel.ReadUint32(rect.width_) && parcel.ReadUint32(rect.height_); + } + + virtual bool Marshalling(Parcel& parcel) const override + { + return (WriteParcel(parcel, leftRect_) && WriteParcel(parcel, topRect_) && + WriteParcel(parcel, rightRect_) && WriteParcel(parcel, bottomRect_)); + } + + static AvoidArea* Unmarshalling(Parcel& parcel) + { + AvoidArea *avoidArea = new(std::nothrow) AvoidArea(); + if (avoidArea == nullptr) { + return nullptr; + } + if (ReadParcel(parcel, avoidArea->leftRect_) && ReadParcel(parcel, avoidArea->topRect_) && + ReadParcel(parcel, avoidArea->rightRect_) && ReadParcel(parcel, avoidArea->bottomRect_)) { + return avoidArea; + } + delete avoidArea; + return nullptr; + } }; enum class WindowUpdateType : int32_t { diff --git a/interfaces/kits/napi/window_runtime/api/@ohos.window.d.ts b/interfaces/kits/napi/window_runtime/api/@ohos.window.d.ts index f0770296..ff8203a6 100644 --- a/interfaces/kits/napi/window_runtime/api/@ohos.window.d.ts +++ b/interfaces/kits/napi/window_runtime/api/@ohos.window.d.ts @@ -83,7 +83,13 @@ declare namespace window { /** * area for system gesture */ - TYPE_SYSTEM_GESTURE + TYPE_SYSTEM_GESTURE, + + /** + * area for keyboard + * @since 9 + */ + TYPE_KEYBOARD } /** * Describes the window mode of an application @@ -375,6 +381,12 @@ declare namespace window { * @since 7 */ interface AvoidArea { + /** + * Whether avoidArea is visible on screen + * @since 9 + */ + visible: boolean; + /** * Rectangle on the left of the screen */ @@ -743,6 +755,7 @@ declare namespace window { * @param type: 'systemAvoidAreaChange' * @syscap SystemCapability.WindowManager.WindowManager.Core * @since 7 + * @deprecated since 9, please use on_avoidAreaChange instead. */ on(type: 'systemAvoidAreaChange', callback: Callback): void; @@ -751,9 +764,26 @@ declare namespace window { * @param type: 'systemAvoidAreaChange' * @syscap SystemCapability.WindowManager.WindowManager.Core * @since 7 + * @deprecated since 9, please use off_avoidAreaChange instead. */ off(type: 'systemAvoidAreaChange', callback?: Callback): void; + /** + * register the callback of avoidAreaChange + * @param type: 'avoidAreaChange' + * @syscap SystemCapability.WindowManager.WindowManager.Core + * @since 9 + */ + on(type: 'avoidAreaChange', callback: Callback<{ type: AvoidAreaType, area: AvoidArea }>): void; + + /** + * unregister the callback of avoidAreaChange + * @param type: 'avoidAreaChange' + * @syscap SystemCapability.WindowManager.WindowManager.Core + * @since 9 + */ + off(type: 'avoidAreaChange', callback?: Callback<{ type: AvoidAreaType, area: AvoidArea }>): void; + /** * Whether the window supports thr wide gamut setting. * @since 8 diff --git a/interfaces/kits/napi/window_runtime/window_napi/js_window.cpp b/interfaces/kits/napi/window_runtime/window_napi/js_window.cpp index 0c216c14..9419f120 100644 --- a/interfaces/kits/napi/window_runtime/window_napi/js_window.cpp +++ b/interfaces/kits/napi/window_runtime/window_napi/js_window.cpp @@ -979,10 +979,13 @@ NativeValue* JsWindow::OnGetAvoidArea(NativeEngine& engine, NativeCallbackInfo& AvoidArea avoidArea; WMError ret = weakWindow->GetAvoidAreaByType(avoidAreaType, avoidArea); if (ret != WMError::WM_OK) { - avoidArea = { g_emptyRect, g_emptyRect, g_emptyRect, g_emptyRect }; // left, top, right, bottom + avoidArea.topRect_ = g_emptyRect; + avoidArea.leftRect_ = g_emptyRect; + avoidArea.rightRect_ = g_emptyRect; + avoidArea.bottomRect_ = g_emptyRect; } // native avoidArea -> js avoidArea - NativeValue* avoidAreaObj = ChangeAvoidAreaToJsValue(engine, avoidArea); + NativeValue* avoidAreaObj = ConvertAvoidAreaToJsValue(engine, avoidArea, avoidAreaType); if (avoidAreaObj != nullptr) { task.Resolve(engine, avoidAreaObj); } else { diff --git a/interfaces/kits/napi/window_runtime/window_napi/js_window_listener.cpp b/interfaces/kits/napi/window_runtime/window_napi/js_window_listener.cpp index 715c7382..cdbc05b4 100644 --- a/interfaces/kits/napi/window_runtime/window_napi/js_window_listener.cpp +++ b/interfaces/kits/napi/window_runtime/window_napi/js_window_listener.cpp @@ -22,7 +22,6 @@ namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "JsWindowListener"}; } -constexpr uint32_t AVOID_AREA_NUM = 4; JsWindowListener::~JsWindowListener() { WLOGFI("[NAPI]~JsWindowListener"); @@ -110,37 +109,29 @@ void JsWindowListener::OnSystemBarPropertyChange(DisplayId displayId, const Syst *engine_, std::make_unique(callback, std::move(execute), std::move(complete))); } -void JsWindowListener::OnAvoidAreaChanged(const std::vector avoidAreas) +void JsWindowListener::OnAvoidAreaChanged(const AvoidArea avoidArea, AvoidAreaType type) { WLOGFI("[NAPI]OnAvoidAreaChanged"); // js callback should run in js thread std::unique_ptr complete = std::make_unique ( - [self = wptr(this), avoidAreas, eng = engine_] (NativeEngine &engine, + [self = wptr(this), avoidArea, type, eng = engine_] (NativeEngine &engine, AsyncTask &task, int32_t status) { auto thisListener = self.promote(); if (thisListener == nullptr || eng == nullptr) { WLOGFE("[NAPI]this listener or engine is nullptr"); return; } - NativeValue* avoidAreaValue = eng->CreateObject(); - NativeObject* object = ConvertNativeValueTo(avoidAreaValue); - if (object == nullptr) { - WLOGFE("[NAPI]Failed to convert rect to jsObject"); + NativeValue* avoidAreaValue = ConvertAvoidAreaToJsValue(engine, avoidArea, type); + if (avoidAreaValue == nullptr) { return; } - - if (static_cast(avoidAreas.size()) != AVOID_AREA_NUM) { - WLOGFE("[NAPI]AvoidAreas size is not 4 (left, top, right, bottom), size is %{public}u", - static_cast(avoidAreas.size())); - return; + if (thisListener->isDeprecatedInterface_) { + NativeValue* argv[] = { avoidAreaValue }; + thisListener->CallJsMethod(SYSTEM_AVOID_AREA_CHANGE_CB.c_str(), argv, ArraySize(argv)); + } else { + NativeValue* argv[] = { CreateJsValue(engine, static_cast(type)), avoidAreaValue }; + thisListener->CallJsMethod(AVOID_AREA_CHANGE_CB.c_str(), argv, ArraySize(argv)); } - - object->SetProperty("leftRect", GetRectAndConvertToJsValue(*eng, avoidAreas[0])); // idx 0 : left - object->SetProperty("topRect", GetRectAndConvertToJsValue(*eng, avoidAreas[1])); // idx 1 : top - object->SetProperty("rightRect", GetRectAndConvertToJsValue(*eng, avoidAreas[2])); // idx 2 : right - object->SetProperty("bottomRect", GetRectAndConvertToJsValue(*eng, avoidAreas[3])); // idx 3 : bottom - NativeValue* argv[] = {avoidAreaValue}; - thisListener->CallJsMethod(SYSTEM_AVOID_AREA_CHANGE_CB.c_str(), argv, ArraySize(argv)); } ); diff --git a/interfaces/kits/napi/window_runtime/window_napi/js_window_listener.h b/interfaces/kits/napi/window_runtime/window_napi/js_window_listener.h index 3dbe7e27..56a05f45 100644 --- a/interfaces/kits/napi/window_runtime/window_napi/js_window_listener.h +++ b/interfaces/kits/napi/window_runtime/window_napi/js_window_listener.h @@ -18,6 +18,8 @@ #include #include + +#include "class_var_definition.h" #include "js_window_utils.h" #include "native_engine/native_engine.h" #include "native_engine/native_value.h" @@ -31,6 +33,7 @@ namespace Rosen { const std::string WINDOW_SIZE_CHANGE_CB = "windowSizeChange"; const std::string SYSTEM_BAR_TINT_CHANGE_CB = "systemBarTintChange"; const std::string SYSTEM_AVOID_AREA_CHANGE_CB = "systemAvoidAreaChange"; +const std::string AVOID_AREA_CHANGE_CB = "avoidAreaChange"; const std::string LIFECYCLE_EVENT_CB = "lifeCycleEvent"; const std::string WINDOW_STAGE_EVENT_CB = "windowStageEvent"; const std::string KEYBOARD_HEIGHT_CHANGE_CB = "keyboardHeightChange"; @@ -49,7 +52,7 @@ public: void OnSystemBarPropertyChange(DisplayId displayId, const SystemBarRegionTints& tints) override; void OnSizeChange(Rect rect, WindowSizeChangeReason reason) override; void OnModeChange(WindowMode mode) override; - void OnAvoidAreaChanged(std::vector avoidAreas) override; + void OnAvoidAreaChanged(const AvoidArea avoidAreas, AvoidAreaType type) override; void AfterForeground() override; void AfterBackground() override; void AfterFocused() override; @@ -61,6 +64,7 @@ private: void LifeCycleCallBack(LifeCycleEventType eventType); NativeEngine* engine_ = nullptr; std::shared_ptr jsCallBack_ = nullptr; + DEFINE_VAR_DEFAULT_FUNC_SET(bool, IsDeprecatedInterface, isDeprecatedInterface, false) }; } // namespace Rosen } // namespace OHOS diff --git a/interfaces/kits/napi/window_runtime/window_napi/js_window_register_manager.cpp b/interfaces/kits/napi/window_runtime/window_napi/js_window_register_manager.cpp index 47a84494..633df51c 100644 --- a/interfaces/kits/napi/window_runtime/window_napi/js_window_register_manager.cpp +++ b/interfaces/kits/napi/window_runtime/window_napi/js_window_register_manager.cpp @@ -31,9 +31,10 @@ JsWindowRegisterManager::JsWindowRegisterManager() // white register list for window listenerProcess_[CaseType::CASE_WINDOW] = { {WINDOW_SIZE_CHANGE_CB, &JsWindowRegisterManager::ProcessWindowChangeRegister }, - {SYSTEM_AVOID_AREA_CHANGE_CB, &JsWindowRegisterManager::ProcessAvoidAreaChangeRegister }, + {SYSTEM_AVOID_AREA_CHANGE_CB, &JsWindowRegisterManager::ProcessSystemAvoidAreaChangeRegister }, + {AVOID_AREA_CHANGE_CB, &JsWindowRegisterManager::ProcessAvoidAreaChangeRegister }, {LIFECYCLE_EVENT_CB, &JsWindowRegisterManager::ProcessLifeCycleEventRegister }, - {KEYBOARD_HEIGHT_CHANGE_CB, &JsWindowRegisterManager::ProcesOccupiedAreaChangeRegister }, + {KEYBOARD_HEIGHT_CHANGE_CB, &JsWindowRegisterManager::ProcessOccupiedAreaChangeRegister }, {TOUCH_OUTSIDE_CB, &JsWindowRegisterManager::ProcessTouchOutsideRegister } }; // white register list for window stage @@ -62,6 +63,23 @@ bool JsWindowRegisterManager::ProcessWindowChangeRegister(sptr return true; } +bool JsWindowRegisterManager::ProcessSystemAvoidAreaChangeRegister(sptr listener, + sptr window, bool isRegister) +{ + if (window == nullptr) { + WLOGFE("[NAPI]Window is nullptr"); + return false; + } + listener->SetIsDeprecatedInterface(true); + sptr thisListener(listener); + if (isRegister) { + window->RegisterAvoidAreaChangeListener(thisListener); + } else { + window->UnregisterAvoidAreaChangeListener(thisListener); + } + return true; +} + bool JsWindowRegisterManager::ProcessAvoidAreaChangeRegister(sptr listener, sptr window, bool isRegister) { @@ -94,7 +112,7 @@ bool JsWindowRegisterManager::ProcessLifeCycleEventRegister(sptr listener, +bool JsWindowRegisterManager::ProcessOccupiedAreaChangeRegister(sptr listener, sptr window, bool isRegister) { if (window == nullptr) { diff --git a/interfaces/kits/napi/window_runtime/window_napi/js_window_register_manager.h b/interfaces/kits/napi/window_runtime/window_napi/js_window_register_manager.h index 1ff9ed34..fe5d4851 100644 --- a/interfaces/kits/napi/window_runtime/window_napi/js_window_register_manager.h +++ b/interfaces/kits/napi/window_runtime/window_napi/js_window_register_manager.h @@ -40,9 +40,10 @@ public: private: bool IsCallbackRegistered(std::string type, NativeValue* jsListenerObject); bool ProcessWindowChangeRegister(sptr listener, sptr window, bool isRegister); + bool ProcessSystemAvoidAreaChangeRegister(sptr listener, sptr window, bool isRegister); bool ProcessAvoidAreaChangeRegister(sptr listener, sptr window, bool isRegister); bool ProcessLifeCycleEventRegister(sptr listener, sptr window, bool isRegister); - bool ProcesOccupiedAreaChangeRegister(sptr listener, sptr window, bool isRegister); + bool ProcessOccupiedAreaChangeRegister(sptr listener, sptr window, bool isRegister); bool ProcessSystemBarChangeRegister(sptr listener, sptr window, bool isRegister); bool ProcessTouchOutsideRegister(sptr listener, sptr window, bool isRegister); using Func_t = bool(JsWindowRegisterManager::*)(sptr, sptr window, bool); diff --git a/interfaces/kits/napi/window_runtime/window_napi/js_window_utils.cpp b/interfaces/kits/napi/window_runtime/window_napi/js_window_utils.cpp index 0971dd62..9e4d09d6 100644 --- a/interfaces/kits/napi/window_runtime/window_napi/js_window_utils.cpp +++ b/interfaces/kits/napi/window_runtime/window_napi/js_window_utils.cpp @@ -100,6 +100,10 @@ NativeValue* AvoidAreaTypeInit(NativeEngine* engine) static_cast(AvoidAreaType::TYPE_SYSTEM))); object->SetProperty("TYPE_CUTOUT", CreateJsValue(*engine, static_cast(AvoidAreaType::TYPE_CUTOUT))); + object->SetProperty("TYPE_SYSTEM_GESTURE", CreateJsValue(*engine, + static_cast(AvoidAreaType::TYPE_SYSTEM_GESTURE))); + object->SetProperty("TYPE_KEYBOARD", CreateJsValue(*engine, + static_cast(AvoidAreaType::TYPE_KEYBOARD))); return objValue; } @@ -204,7 +208,7 @@ NativeValue* WindowLayoutModeInit(NativeEngine* engine) return objValue; } -NativeValue* GetRectAndConvertToJsValue(NativeEngine& engine, const Rect rect) +NativeValue* GetRectAndConvertToJsValue(NativeEngine& engine, const Rect& rect) { NativeValue* objValue = engine.CreateObject(); NativeObject* object = ConvertNativeValueTo(objValue); @@ -427,18 +431,19 @@ bool SetSystemBarPropertiesFromJs(NativeEngine& engine, NativeObject* jsObject, return true; } -NativeValue* ChangeAvoidAreaToJsValue(NativeEngine& engine, const AvoidArea& avoidArea) +NativeValue* ConvertAvoidAreaToJsValue(NativeEngine& engine, const AvoidArea& avoidArea, AvoidAreaType type) { NativeValue* objValue = engine.CreateObject(); NativeObject* object = ConvertNativeValueTo(objValue); if (object == nullptr) { - WLOGFE("[NAPI]Failed to convert rect to jsObject"); - return engine.CreateUndefined(); + WLOGFE("[NAPI]Failed to convert avoidArea to jsObject"); + return nullptr; } - object->SetProperty("leftRect", GetRectAndConvertToJsValue(engine, avoidArea.leftRect)); - object->SetProperty("topRect", GetRectAndConvertToJsValue(engine, avoidArea.topRect)); - object->SetProperty("rightRect", GetRectAndConvertToJsValue(engine, avoidArea.rightRect)); - object->SetProperty("bottomRect", GetRectAndConvertToJsValue(engine, avoidArea.bottomRect)); + object->SetProperty("visible", CreateJsValue(engine, type == AvoidAreaType::TYPE_CUTOUT ? false : true)); + object->SetProperty("leftRect", GetRectAndConvertToJsValue(engine, avoidArea.leftRect_)); + object->SetProperty("topRect", GetRectAndConvertToJsValue(engine, avoidArea.topRect_)); + object->SetProperty("rightRect", GetRectAndConvertToJsValue(engine, avoidArea.rightRect_)); + object->SetProperty("bottomRect", GetRectAndConvertToJsValue(engine, avoidArea.bottomRect_)); return objValue; } diff --git a/interfaces/kits/napi/window_runtime/window_napi/js_window_utils.h b/interfaces/kits/napi/window_runtime/window_napi/js_window_utils.h index 2a562153..4765a8ad 100644 --- a/interfaces/kits/napi/window_runtime/window_napi/js_window_utils.h +++ b/interfaces/kits/napi/window_runtime/window_napi/js_window_utils.h @@ -148,7 +148,7 @@ const std::map JS_TO_NATIVE_ORIENTATION_MAP { {ApiOrientation::LOCKED, Orientation::LOCKED }, }; - NativeValue* GetRectAndConvertToJsValue(NativeEngine& engine, const Rect rect); + NativeValue* GetRectAndConvertToJsValue(NativeEngine& engine, const Rect& rect); NativeValue* CreateJsWindowPropertiesObject(NativeEngine& engine, sptr& window); bool SetSystemBarPropertiesFromJs(NativeEngine& engine, NativeObject* jsObject, std::map& properties, sptr& window); @@ -156,7 +156,7 @@ const std::map JS_TO_NATIVE_ORIENTATION_MAP { NativeEngine& engine, NativeCallbackInfo& info, sptr& window); NativeValue* CreateJsSystemBarRegionTintArrayObject(NativeEngine& engine, const SystemBarRegionTints& tints); - NativeValue* ChangeAvoidAreaToJsValue(NativeEngine& engine, const AvoidArea& avoidArea); + NativeValue* ConvertAvoidAreaToJsValue(NativeEngine& engine, const AvoidArea& avoidArea, AvoidAreaType type); bool CheckCallingPermission(std::string permission); NativeValue* WindowTypeInit(NativeEngine* engine); NativeValue* AvoidAreaTypeInit(NativeEngine* engine); diff --git a/resources/config/other/display_manager_config.xml b/resources/config/other/display_manager_config.xml index ea91687e..a5da1418 100644 --- a/resources/config/other/display_manager_config.xml +++ b/resources/config/other/display_manager_config.xml @@ -16,4 +16,6 @@ 0 + + 10 10 100 20 \ No newline at end of file diff --git a/resources/config/rk3568/display_manager_config.xml b/resources/config/rk3568/display_manager_config.xml index 46fef2bd..7933d38e 100644 --- a/resources/config/rk3568/display_manager_config.xml +++ b/resources/config/rk3568/display_manager_config.xml @@ -19,4 +19,6 @@ 0 + + 10 10 100 20 diff --git a/utils/include/class_var_definition.h b/utils/include/class_var_definition.h index a9877a8d..e3439390 100644 --- a/utils/include/class_var_definition.h +++ b/utils/include/class_var_definition.h @@ -68,6 +68,10 @@ public: DEFINE_VAR_DEFAULT(type, memberName, defaultValue) \ DEFINE_FUNC_GET(type, funcName, memberName) +#define DEFINE_VAR_DEFAULT_FUNC_SET(type, funcName, memberName, defaultValue) \ + DEFINE_VAR_DEFAULT(type, memberName, defaultValue) \ + DEFINE_FUNC_SET(type, funcName, memberName) + #define DEFINE_VAR_FUNC_GET_SET(type, funcName, memberName) \ DEFINE_VAR(type, memberName) \ DEFINE_FUNC_GET(type, funcName, memberName) \ diff --git a/utils/include/window_helper.h b/utils/include/window_helper.h index e32c9611..f1653100 100644 --- a/utils/include/window_helper.h +++ b/utils/include/window_helper.h @@ -79,11 +79,18 @@ public: return mode == WindowMode::WINDOW_MODE_FLOATING; } - static inline bool IsAvoidAreaWindow(WindowType type) + static inline bool IsSystemBarWindow(WindowType type) { return (type == WindowType::WINDOW_TYPE_STATUS_BAR || type == WindowType::WINDOW_TYPE_NAVIGATION_BAR); } + static inline bool IsOverlayWindow(WindowType type) + { + return (type == WindowType::WINDOW_TYPE_STATUS_BAR + || type == WindowType::WINDOW_TYPE_NAVIGATION_BAR + || type == WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT); + } + static inline bool IsFullScreenWindow(WindowMode mode) { return mode == WindowMode::WINDOW_MODE_FULLSCREEN; @@ -122,11 +129,11 @@ public: static inline Rect GetOverlap(const Rect& rect1, const Rect& rect2, const int offsetX, const int offsetY) { - const static Rect noOverlapRect = { 0, 0, 0, 0}; + const static Rect noOverlapRect = { 0, 0, 0, 0 }; int32_t x_begin = std::max(rect1.posX_, rect2.posX_); - int32_t x_end = std::min(rect1.posX_ + rect1.width_, rect2.posX_ + rect2.width_); + int32_t x_end = std::min(rect1.posX_ + rect1.width_ - 1, rect2.posX_ + rect2.width_ - 1); int32_t y_begin = std::max(rect1.posY_, rect2.posY_); - int32_t y_end = std::min(rect1.posY_ + rect1.height_, rect2.posY_ + rect2.height_); + int32_t y_end = std::min(rect1.posY_ + rect1.height_ - 1, rect2.posY_ + rect2.height_ - 1); if (y_begin > y_end || x_begin > x_end) { return noOverlapRect; } diff --git a/wm/include/window_adapter.h b/wm/include/window_adapter.h index a659fd86..2be221d5 100644 --- a/wm/include/window_adapter.h +++ b/wm/include/window_adapter.h @@ -41,7 +41,7 @@ public: virtual WMError RemoveWindow(uint32_t windowId); virtual WMError DestroyWindow(uint32_t windowId); virtual WMError RequestFocus(uint32_t windowId); - virtual WMError GetAvoidAreaByType(uint32_t windowId, AvoidAreaType type, std::vector& avoidRect); + virtual WMError GetAvoidAreaByType(uint32_t windowId, AvoidAreaType type, AvoidArea& avoidRect); virtual WMError SetWindowBackgroundBlur(uint32_t windowId, WindowBlurLevel level); virtual WMError SetAlpha(uint32_t windowId, float alpha); virtual WMError GetTopWindowId(uint32_t mainWinId, uint32_t& topWinId); @@ -61,6 +61,7 @@ public: virtual WMError SetWindowAnimationController(const sptr& controller); virtual WMError NotifyWindowTransition(sptr from, sptr to); + virtual WMError UpdateAvoidAreaListener(uint32_t windowId, bool haveListener); virtual void ClearWindowAdapter(); virtual WMError GetAccessibilityWindowInfo(sptr& windowInfo); diff --git a/wm/include/window_agent.h b/wm/include/window_agent.h index 4163eca6..818accd6 100644 --- a/wm/include/window_agent.h +++ b/wm/include/window_agent.h @@ -30,7 +30,7 @@ public: void UpdateWindowRect(const struct Rect& rect, bool decoStatus, WindowSizeChangeReason reason) override; void UpdateWindowMode(WindowMode mode) override; void UpdateFocusStatus(bool focused) override; - void UpdateAvoidArea(const std::vector& avoidAreas) override; + void UpdateAvoidArea(const sptr& avoidArea, AvoidAreaType type) override; void UpdateWindowState(WindowState state) override; void UpdateWindowDragInfo(const PointInfo& point, DragEvent event) override; void UpdateDisplayId(DisplayId from, DisplayId to) override; diff --git a/wm/include/window_impl.h b/wm/include/window_impl.h index 0f8f55b7..2338fe10 100644 --- a/wm/include/window_impl.h +++ b/wm/include/window_impl.h @@ -178,7 +178,7 @@ public: virtual void RequestFrame() override; void UpdateFocusStatus(bool focused); virtual void UpdateConfiguration(const std::shared_ptr& configuration) override; - void UpdateAvoidArea(const std::vector& avoidAreas); + void UpdateAvoidArea(const sptr& avoidArea, AvoidAreaType type); void UpdateWindowState(WindowState state); sptr GetWindowProperty(); void UpdateDragEvent(const PointInfo& point, DragEvent event); @@ -189,7 +189,7 @@ public: void NotifySizeChange(Rect rect, WindowSizeChangeReason reason); void NotifyKeyEvent(std::shared_ptr &keyEvent); void NotifyPointEvent(std::shared_ptr& pointerEvent); - void NotifyAvoidAreaChange(const std::vector& avoidArea); + void NotifyAvoidAreaChange(const sptr& avoidArea, AvoidAreaType type); void NotifyDisplayMoveChange(DisplayId from, DisplayId to); void NotifyOccupiedAreaChange(const sptr& info); void NotifyModeChange(WindowMode mode); diff --git a/wm/include/zidl/window_interface.h b/wm/include/zidl/window_interface.h index 3e46b4be..bb516d18 100644 --- a/wm/include/zidl/window_interface.h +++ b/wm/include/zidl/window_interface.h @@ -46,7 +46,7 @@ public: virtual void UpdateWindowRect(const struct Rect& rect, bool decoStatus, WindowSizeChangeReason reason) = 0; virtual void UpdateWindowMode(WindowMode mode) = 0; virtual void UpdateFocusStatus(bool focused) = 0; - virtual void UpdateAvoidArea(const std::vector& avoidAreas) = 0; + virtual void UpdateAvoidArea(const sptr& avoidArea, AvoidAreaType type) = 0; virtual void UpdateWindowState(WindowState state) = 0; virtual void UpdateWindowDragInfo(const PointInfo& point, DragEvent event) = 0; virtual void UpdateDisplayId(DisplayId from, DisplayId to) = 0; diff --git a/wm/include/zidl/window_proxy.h b/wm/include/zidl/window_proxy.h index 41b71afd..ac492560 100644 --- a/wm/include/zidl/window_proxy.h +++ b/wm/include/zidl/window_proxy.h @@ -31,7 +31,7 @@ public: void UpdateWindowRect(const struct Rect& rect, bool decoStatus, WindowSizeChangeReason reason) override; void UpdateWindowMode(WindowMode mode) override; void UpdateFocusStatus(bool focused) override; - void UpdateAvoidArea(const std::vector& avoidAreas) override; + void UpdateAvoidArea(const sptr& avoidArea, AvoidAreaType type) override; void UpdateWindowState(WindowState state) override; void UpdateWindowDragInfo(const PointInfo& point, DragEvent event) override; void UpdateDisplayId(DisplayId from, DisplayId to) override; diff --git a/wm/src/window_adapter.cpp b/wm/src/window_adapter.cpp index 6ae6be3f..c492949c 100644 --- a/wm/src/window_adapter.cpp +++ b/wm/src/window_adapter.cpp @@ -99,11 +99,10 @@ WMError WindowAdapter::SetWindowAnimationController(const sptrSetWindowAnimationController(controller); } -WMError WindowAdapter::GetAvoidAreaByType(uint32_t windowId, AvoidAreaType type, std::vector& avoidRect) +WMError WindowAdapter::GetAvoidAreaByType(uint32_t windowId, AvoidAreaType type, AvoidArea& avoidArea) { INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR); - - avoidRect = windowManagerServiceProxy_->GetAvoidAreaByType(windowId, type); + avoidArea = windowManagerServiceProxy_->GetAvoidAreaByType(windowId, type); return WMError::WM_OK; } @@ -258,5 +257,12 @@ void WindowAdapter::MinimizeWindowsByLauncher(std::vector windowIds, b windowManagerServiceProxy_->MinimizeWindowsByLauncher(windowIds, isAnimated, finishCallback); return; } + +WMError WindowAdapter::UpdateAvoidAreaListener(uint32_t windowId, bool haveListener) +{ + INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR); + + return windowManagerServiceProxy_->UpdateAvoidAreaListener(windowId, haveListener); +} } // namespace Rosen } // namespace OHOS \ No newline at end of file diff --git a/wm/src/window_agent.cpp b/wm/src/window_agent.cpp index 548b1649..36bf52c8 100644 --- a/wm/src/window_agent.cpp +++ b/wm/src/window_agent.cpp @@ -55,13 +55,13 @@ void WindowAgent::UpdateFocusStatus(bool focused) window_->UpdateFocusStatus(focused); } -void WindowAgent::UpdateAvoidArea(const std::vector& avoidArea) +void WindowAgent::UpdateAvoidArea(const sptr& avoidArea, AvoidAreaType type) { if (window_ == nullptr) { WLOGFE("window_ is nullptr"); return; } - window_->UpdateAvoidArea(avoidArea); + window_->UpdateAvoidArea(avoidArea, type); } void WindowAgent::UpdateWindowState(WindowState state) diff --git a/wm/src/window_impl.cpp b/wm/src/window_impl.cpp index d3a899f8..f95c09a2 100644 --- a/wm/src/window_impl.cpp +++ b/wm/src/window_impl.cpp @@ -290,16 +290,13 @@ SystemBarProperty WindowImpl::GetSystemBarPropertyByType(WindowType type) const WMError WindowImpl::GetAvoidAreaByType(AvoidAreaType type, AvoidArea& avoidArea) { WLOGFI("GetAvoidAreaByType Search Type: %{public}u", static_cast(type)); - std::vector avoidAreaVec; uint32_t windowId = property_->GetWindowId(); - WMError ret = SingletonContainer::Get().GetAvoidAreaByType(windowId, type, avoidAreaVec); - if (ret != WMError::WM_OK || avoidAreaVec.size() != 4) { // 4: the avoid area num (left, top, right, bottom) - WLOGFE("GetAvoidAreaByType errCode:%{public}d winId:%{public}u Type is :%{public}u." \ - "Or avoidArea Size != 4. Current size of avoid area: %{public}u", static_cast(ret), - property_->GetWindowId(), static_cast(type), static_cast(avoidAreaVec.size())); + WMError ret = SingletonContainer::Get().GetAvoidAreaByType(windowId, type, avoidArea); + if (ret != WMError::WM_OK) { + WLOGFE("GetAvoidAreaByType errCode:%{public}d winId:%{public}u Type is :%{public}u.", + static_cast(ret), property_->GetWindowId(), static_cast(type)); return ret; } - avoidArea = {avoidAreaVec[0], avoidAreaVec[1], avoidAreaVec[2], avoidAreaVec[3]}; // 0:left 1:top 2:right 3:bottom return ret; } @@ -1336,25 +1333,36 @@ void WindowImpl::UnregisterWindowChangeListener(sptr& lis void WindowImpl::RegisterAvoidAreaChangeListener(sptr& listener) { if (listener == nullptr) { - WLOGFE("RegisterAvoidAreaChangeListener failed. AvoidAreaChangeListener is nullptr"); + WLOGFE("register avoid area listener fail. listener is null"); return; } - std::lock_guard lock(mutex_); - if (std::find(avoidAreaChangeListeners_.begin(), avoidAreaChangeListeners_.end(), listener) != - avoidAreaChangeListeners_.end()) { - WLOGFE("Listener already registered"); - return; + { + std::lock_guard lock(mutex_); + if (std::find(avoidAreaChangeListeners_.begin(), avoidAreaChangeListeners_.end(), listener) != + avoidAreaChangeListeners_.end()) { + WLOGFE("avoid area listener already registered"); + return; + } + avoidAreaChangeListeners_.push_back(listener); + } + if (avoidAreaChangeListeners_.size() == 1) { + SingletonContainer::Get().UpdateAvoidAreaListener(property_->GetWindowId(), true); } - avoidAreaChangeListeners_.emplace_back(listener); } void WindowImpl::UnregisterAvoidAreaChangeListener(sptr& listener) { - std::lock_guard lock(mutex_); - avoidAreaChangeListeners_.erase(std::remove_if(avoidAreaChangeListeners_.begin(), avoidAreaChangeListeners_.end(), - [listener](sptr registeredListener) { - return registeredListener == listener; - }), avoidAreaChangeListeners_.end()); + { + std::lock_guard lock(mutex_); + avoidAreaChangeListeners_.erase(std::remove_if(avoidAreaChangeListeners_.begin(), + avoidAreaChangeListeners_.end(), + [listener](sptr registeredListener) { + return registeredListener == listener; + }), avoidAreaChangeListeners_.end()); + } + if (avoidAreaChangeListeners_.empty()) { + SingletonContainer::Get().UpdateAvoidAreaListener(property_->GetWindowId(), false); + } } void WindowImpl::RegisterDragListener(const sptr& listener) @@ -1948,10 +1956,10 @@ void WindowImpl::UpdateConfiguration(const std::shared_ptr& avoidArea) +void WindowImpl::UpdateAvoidArea(const sptr& avoidArea, AvoidAreaType type) { WLOGFI("Window Update AvoidArea, id: %{public}u", property_->GetWindowId()); - NotifyAvoidAreaChange(avoidArea); + NotifyAvoidAreaChange(avoidArea, type); } void WindowImpl::UpdateWindowState(WindowState state) @@ -2130,17 +2138,22 @@ void WindowImpl::NotifyPointEvent(std::shared_ptr& pointerEve }); } -void WindowImpl::NotifyAvoidAreaChange(const std::vector& avoidArea) +void WindowImpl::NotifyAvoidAreaChange(const sptr& avoidArea, AvoidAreaType type) { std::vector> avoidAreaChangeListeners; { std::lock_guard lock(mutex_); avoidAreaChangeListeners = avoidAreaChangeListeners_; } - PostListenerTask([avoidAreaChangeListeners, avoidArea]() { + PostListenerTask([avoidAreaChangeListeners, avoidArea, type]() { + AvoidArea outAvoidArea; + outAvoidArea.topRect_ = avoidArea->topRect_; + outAvoidArea.leftRect_ = avoidArea->leftRect_; + outAvoidArea.rightRect_ = avoidArea->rightRect_; + outAvoidArea.bottomRect_ = avoidArea->bottomRect_; for (auto& listener : avoidAreaChangeListeners) { if (listener != nullptr) { - listener->OnAvoidAreaChanged(avoidArea); + listener->OnAvoidAreaChanged(outAvoidArea, type); } } }); diff --git a/wm/src/zidl/window_proxy.cpp b/wm/src/zidl/window_proxy.cpp index 92d25119..5b3a448c 100644 --- a/wm/src/zidl/window_proxy.cpp +++ b/wm/src/zidl/window_proxy.cpp @@ -97,7 +97,7 @@ void WindowProxy::UpdateFocusStatus(bool focused) return; } -void WindowProxy::UpdateAvoidArea(const std::vector& avoidArea) +void WindowProxy::UpdateAvoidArea(const sptr& avoidArea, AvoidAreaType type) { MessageParcel data; MessageParcel reply; @@ -106,21 +106,14 @@ void WindowProxy::UpdateAvoidArea(const std::vector& avoidArea) WLOGFE("WriteInterfaceToken failed"); return; } - - uint32_t len = static_cast(avoidArea.size()); - if (!data.WriteUint32(len)) { - WLOGFE("Write UpdateAvoidArea Vector Size failed"); + if (!data.WriteStrongParcelable(avoidArea)) { + WLOGFE("Write WindowRect failed"); return; } - - for (auto avoid : avoidArea) { - if (!(data.WriteInt32(avoid.posX_) && data.WriteInt32(avoid.posY_) && - data.WriteUint32(avoid.width_) && data.WriteUint32(avoid.height_))) { - WLOGFE("Write WindowRect failed"); - return; - } + if (!data.WriteUint32(static_cast(type))) { + WLOGFE("Write AvoidAreaType failed"); + return; } - if (Remote()->SendRequest(static_cast(WindowMessage::TRANS_ID_UPDATE_AVOID_AREA), data, reply, option) != ERR_NONE) { WLOGFE("SendRequest failed"); diff --git a/wm/src/zidl/window_stub.cpp b/wm/src/zidl/window_stub.cpp index 1ec7ea13..c8d00110 100644 --- a/wm/src/zidl/window_stub.cpp +++ b/wm/src/zidl/window_stub.cpp @@ -23,7 +23,6 @@ namespace OHOS { namespace Rosen { namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowStub"}; - const uint32_t MAX_AVOID_NUM = 4; } int WindowStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) @@ -52,28 +51,12 @@ int WindowStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParce break; } case WindowMessage::TRANS_ID_UPDATE_AVOID_AREA: { - std::vector avoidArea; - uint32_t len = data.ReadUint32(); - if (len != MAX_AVOID_NUM) { - WLOGFE("Read len fail. AvoidArea size != 4"); + sptr avoidArea = data.ReadStrongParcelable(); + uint32_t type; + if (!data.ReadUint32(type)) { return -1; } - avoidArea.resize(len); - if (avoidArea.size() < len) { - WLOGE("Fail to resize avoidArea."); - return -1; - } - - bool readVectorRes = true; - for (uint32_t i = 0; i < len; ++i) { - readVectorRes = data.ReadInt32(avoidArea[i].posX_) && data.ReadInt32(avoidArea[i].posY_) && - data.ReadUint32(avoidArea[i].width_) && data.ReadUint32(avoidArea[i].height_); - if (!readVectorRes) { - WLOGE("Fail to ReadInt32. index:%{public}u, nums:%{public}u", i, len); - return -1; - } - } - UpdateAvoidArea(avoidArea); + UpdateAvoidArea(avoidArea, static_cast(type)); break; } case WindowMessage::TRANS_ID_UPDATE_WINDOW_STATE: { diff --git a/wm/test/systemtest/BUILD.gn b/wm/test/systemtest/BUILD.gn index 392b70df..11d52155 100644 --- a/wm/test/systemtest/BUILD.gn +++ b/wm/test/systemtest/BUILD.gn @@ -25,7 +25,6 @@ group("systemtest") { ":wm_window_effect_test", ":wm_window_focus_test", ":wm_window_gamut_test", - ":wm_window_immersive_test", ":wm_window_input_method_test", ":wm_window_input_test", ":wm_window_layout_test", diff --git a/wm/test/systemtest/window_immersive_test.cpp b/wm/test/systemtest/window_immersive_test.cpp index c183248f..6f7191c3 100644 --- a/wm/test/systemtest/window_immersive_test.cpp +++ b/wm/test/systemtest/window_immersive_test.cpp @@ -59,8 +59,8 @@ public: class TestAvoidAreaChangedListener : public IAvoidAreaChangedListener { public: - std::vector avoidAreas_; - void OnAvoidAreaChanged(std::vector avoidAreas) override; + AvoidArea avoidAreas_; + void OnAvoidAreaChanged(const AvoidArea avoidAreas) override; }; class WindowImmersiveTest : public testing::Test { @@ -97,7 +97,7 @@ sptr WindowImmersiveTest::testAvoidAreaChangedList void WindowImmersiveTest::SetWindowSystemProps(const sptr& window, const SystemBarRegionTints& tints) { for (auto tint : tints) { - window->SetSystemBarProperty(tint.type_, tint.prop_); + window->SetSystemBarProperty(tint.type_, tint.propWindowImmersiveTest _); } } @@ -106,15 +106,16 @@ void WindowImmersiveTest::DumpFailedInfo(const SystemBarRegionTints& expect) auto act = testSystemBarChangedListener_->tints_; WLOGFI("WindowImmersiveTest Expected:"); for (auto tint : expect) { - WLOGFI("WindowType: %{public}4d, Enable: %{public}4d, Color: %{public}x | %{public}x", - static_cast(tint.type_), tint.prop_.enable_, - tint.prop_.backgroundColor_, tint.prop_.contentColor_); + WLOGFI("WindowType: %{public}4d, Enable: %{public}4d, Color: %{public}x | %{public}x", + static_cast(tint.type_), tint.prop_.enable_, + tint.prop_.backgroundColor_, tint.prop_.contentColor_); } WLOGFI("WindowImmersiveTest Act: "); + for (auto tint : act) { - WLOGFI("WindowType: %{public}4d, Enable: %{public}4d, Color: %{public}x | %{public}x", - static_cast(tint.type_), tint.prop_.enable_, - tint.prop_.backgroundColor_, tint.prop_.contentColor_); + WLOGFI("WindowType: %{public}4d, Enable: %{public}4d, Color: %{public}x | %{public}x", + static_cast(tint.type_), tint.prop_.enable_, + tint.prop_.backgroundColor_, tint.prop_.contentColor_); } } @@ -188,7 +189,7 @@ void TestSystemBarChangedListener::OnSystemBarPropertyChange(DisplayId displayId } } -void TestAvoidAreaChangedListener::OnAvoidAreaChanged(std::vector avoidAreas) +void TestAvoidAreaChangedListener::OnAvoidAreaChanged(AvoidArea avoidAreas) { avoidAreas_ = avoidAreas; } @@ -386,10 +387,10 @@ HWTEST_F(WindowImmersiveTest, GetAvoidAreaByTypeTest01, Function | MediumTest | AvoidArea avoidarea; WMError ret = win->GetAvoidAreaByType(AvoidAreaType::TYPE_CUTOUT, avoidarea); ASSERT_EQ(WMError::WM_OK, ret); - ASSERT_TRUE(utils::RectEqualToRect(EMPTY_RECT, avoidarea.leftRect)); - ASSERT_TRUE(utils::RectEqualToRect(EMPTY_RECT, avoidarea.rightRect)); - ASSERT_TRUE(utils::RectEqualToRect(EMPTY_RECT, avoidarea.topRect)); - ASSERT_TRUE(utils::RectEqualToRect(EMPTY_RECT, avoidarea.bottomRect)); + ASSERT_TRUE(utils::RectEqualToRect(EMPTY_RECT, avoidarea.leftRect_)); + ASSERT_TRUE(utils::RectEqualToRect(EMPTY_RECT, avoidarea.rightRect_)); + ASSERT_TRUE(utils::RectEqualToRect(EMPTY_RECT, avoidarea.topRect_)); + ASSERT_TRUE(utils::RectEqualToRect(EMPTY_RECT, avoidarea.bottomRect_)); ASSERT_EQ(WMError::WM_OK, win->Hide()); } @@ -403,19 +404,29 @@ HWTEST_F(WindowImmersiveTest, GetAvoidAreaByTypeTest02, Function | MediumTest | // Add full screenwindow for call GetAvoidArea, and push_back in activeWindows_ const sptr& win = utils::CreateTestWindow(fullScreenAppinfo_); activeWindows_.push_back(win); + ASSERT_EQ(WMError::WM_OK, win->Show()); + WLOGFI("win.posY_=%{public}d", win->GetRect().posY_); // Add a unexist leftAvoid avoidBarInfo_.rect = {0, 0, leftAvoidW_, leftAvoidH_}; const sptr& left = utils::CreateTestWindow(avoidBarInfo_); activeWindows_.push_back(left); + WLOGFI("win.posY_=%{public}d", win->GetRect().posY_); ASSERT_EQ(WMError::WM_OK, left->Show()); ASSERT_EQ(WMError::WM_OK, left->Resize(leftAvoidW_, leftAvoidH_)); + // Test GetAvoidArea AvoidArea avoidarea; WMError ret = win->GetAvoidAreaByType(AvoidAreaType::TYPE_SYSTEM, avoidarea); + WLOGFI("ret = [%{public}u, avoidArea: top[%{public}d, %{public}d, %{public}u, %{public}u], left[%{public}d, %{public}d, %{public}u, %{public}u], " \ + "right[%{public}d, %{public}d, %{public}u, %{public}u], bottom[%{public}d, %{public}d, %{public}u, %{public}u]", ret, + avoidarea.topRect_.posX_, avoidarea.topRect_.posY_, avoidarea.topRect_.width_, avoidarea.topRect_.height_, + avoidarea.leftRect_.posX_, avoidarea.leftRect_.posY_, avoidarea.leftRect_.width_, avoidarea.leftRect_.height_, + avoidarea.rightRect_.posX_, avoidarea.rightRect_.posY_, avoidarea.rightRect_.width_, avoidarea.rightRect_.height_, + avoidarea.bottomRect_.posX_, avoidarea.bottomRect_.posY_, avoidarea.bottomRect_.width_, avoidarea.bottomRect_.height_); ASSERT_EQ(WMError::WM_OK, ret); - ASSERT_TRUE(utils::RectEqualTo(left, avoidarea.leftRect)); + ASSERT_TRUE(utils::RectEqualTo(left, avoidarea.leftRect_)); ASSERT_EQ(WMError::WM_OK, left->Hide()); ASSERT_EQ(WMError::WM_OK, win->Hide()); } diff --git a/wm/test/systemtest/window_occupied_area_change_test.cpp b/wm/test/systemtest/window_occupied_area_change_test.cpp index 34b4a305..4fea3ec0 100644 --- a/wm/test/systemtest/window_occupied_area_change_test.cpp +++ b/wm/test/systemtest/window_occupied_area_change_test.cpp @@ -121,8 +121,8 @@ HWTEST_F(WindowOccupiedAreaChangeTest, KeyboardHeightChangeTest01, Function | Me ASSERT_EQ(testOccupiedAreaChangeListener_->rect_.posX_, window2->GetRect().posX_); ASSERT_EQ(testOccupiedAreaChangeListener_->rect_.posY_, window2->GetRect().posY_); - ASSERT_EQ(testOccupiedAreaChangeListener_->rect_.width_, window2->GetRect().width_ + 1); - ASSERT_EQ(testOccupiedAreaChangeListener_->rect_.height_, window2->GetRect().height_ + 1); + ASSERT_EQ(testOccupiedAreaChangeListener_->rect_.width_, window2->GetRect().width_); + ASSERT_EQ(testOccupiedAreaChangeListener_->rect_.height_, window2->GetRect().height_); } /** diff --git a/wm/test/systemtest/window_split_immersive_test.cpp b/wm/test/systemtest/window_split_immersive_test.cpp index fbb871dc..afeb680e 100644 --- a/wm/test/systemtest/window_split_immersive_test.cpp +++ b/wm/test/systemtest/window_split_immersive_test.cpp @@ -121,7 +121,7 @@ HWTEST_F(WindowSplitImmersiveTest, SplitImmersive01, Function | MediumTest | Lev Rect curFullScreenRect = fullWindow->GetRect(); AvoidArea avoidArea; fullWindow->GetAvoidAreaByType(AvoidAreaType::TYPE_SYSTEM, avoidArea); - ASSERT_EQ(avoidArea.topRect.height_, curFullScreenRect.posY_); + ASSERT_EQ(avoidArea.topRect_.height_, curFullScreenRect.posY_); ASSERT_EQ(WMError::WM_OK, fullWindow->Hide()); sleep(SPLIT_TEST_SLEEP_S); diff --git a/wm/test/systemtest/window_test_utils.cpp b/wm/test/systemtest/window_test_utils.cpp index ec4b12af..ff7e6299 100644 --- a/wm/test/systemtest/window_test_utils.cpp +++ b/wm/test/systemtest/window_test_utils.cpp @@ -359,10 +359,10 @@ void WindowTestUtils::UpdateSplitRects(const sptr& window) if (res != WMError::WM_OK) { WLOGFE("Get avoid type failed"); } - testUtils->UpdateLimitDisplayRect(testUtils->avoidArea_.leftRect); - testUtils->UpdateLimitDisplayRect(testUtils->avoidArea_.topRect); - testUtils->UpdateLimitDisplayRect(testUtils->avoidArea_.rightRect); - testUtils->UpdateLimitDisplayRect(testUtils->avoidArea_.bottomRect); + testUtils->UpdateLimitDisplayRect(testUtils->avoidArea_.leftRect_); + testUtils->UpdateLimitDisplayRect(testUtils->avoidArea_.topRect_); + testUtils->UpdateLimitDisplayRect(testUtils->avoidArea_.rightRect_); + testUtils->UpdateLimitDisplayRect(testUtils->avoidArea_.bottomRect_); if (isVerticalDisplay_) { splitRects_.dividerRect.posY_ = limitDisplayRect_.posY_ + diff --git a/wm/test/unittest/BUILD.gn b/wm/test/unittest/BUILD.gn index a0b90166..48d9f1fc 100644 --- a/wm/test/unittest/BUILD.gn +++ b/wm/test/unittest/BUILD.gn @@ -19,7 +19,6 @@ group("unittest") { testonly = true deps = [ - ":avoid_area_controller_test", ":wm_input_transfer_station_test", ":wm_window_effect_test", ":wm_window_impl_test", diff --git a/wmserver/include/avoid_area_controller.h b/wmserver/include/avoid_area_controller.h index 00039676..9b6cd6ff 100644 --- a/wmserver/include/avoid_area_controller.h +++ b/wmserver/include/avoid_area_controller.h @@ -18,9 +18,12 @@ #include #include +#include #include + #include +#include "class_var_definition.h" #include "window_node.h" #include "wm_common.h" #include "wm_common_inner.h" @@ -34,28 +37,35 @@ enum class AvoidControlType : uint32_t { AVOID_NODE_UNKNOWN, }; -using UpdateAvoidAreaFunc = std::function& avoidArea, DisplayId displayId)>; - class AvoidAreaController : public RefBase { public: - AvoidAreaController(DisplayId displayId, UpdateAvoidAreaFunc callback); + AvoidAreaController(uint32_t& focusedWindow) : focusedWindow_(focusedWindow) {}; ~AvoidAreaController() = default; - WMError AvoidControl(const sptr& node, AvoidControlType type); - - bool IsAvoidAreaNode(const sptr& node) const; - std::vector GetAvoidArea(DisplayId displayId) const; - std::vector GetAvoidAreaByType(AvoidAreaType avoidAreaType, DisplayId displayId) const; - void UpdateAvoidNodesMap(DisplayId displayId, bool isAdd); + void UpdateAvoidAreaListener(sptr& windowNode, bool isRegisterListener); + void ProcessWindowChange(const sptr& windowNode, AvoidControlType avoidType, + const std::function)>& checkFunc); + AvoidArea GetAvoidAreaByType(const sptr& node, AvoidAreaType avoidAreaType) const; private: - std::map>* GetAvoidNodesByDisplayId(DisplayId displayId); - void UseCallbackNotifyAvoidAreaChanged(std::vector& avoidArea, DisplayId displayId) const; - void DumpAvoidArea(const std::vector& avoidArea) const; - AvoidPosType GetAvoidPosType(const Rect& rect, DisplayId displayId) const; + void AddOrRemoveOverlayWindowIfNeed(const sptr& overlayNode, bool isAdding); + void AddOrRemoveKeyboard(const sptr& keyboardNode, bool isAdding); + void UpdateOverlayWindowIfNeed(const sptr& node, + const std::function)>& checkFunc); + AvoidPosType CalculateOverlayRect(const sptr& node, + const sptr& overlayNode, Rect& overlayRect) const; + AvoidPosType GetAvoidPosType(const Rect& windowRect, const Rect& overlayRect) const; + void SetAvoidAreaRect(AvoidArea& avoidArea, Rect& rect, AvoidPosType type) const; + bool UpdateAvoidAreaIfNeed(const AvoidArea& avoidArea, const sptr& node, AvoidAreaType avoidAreaType); + AvoidArea GetAvoidAreaSystemType(const sptr& node) const; + AvoidArea GetAvoidAreaKeyboardType(const sptr& node) const; - std::map>>> avoidNodesMaps_; - UpdateAvoidAreaFunc updateAvoidAreaCallBack_; + uint32_t& focusedWindow_; + std::unordered_map> overlayWindowMap_; + std::set> avoidAreaListenerNodes_; + std::map> lastUpdatedAvoidArea_; + DEFINE_VAR_DEFAULT_FUNC_SET(bool, FlagForProcessWindowChange, isForbidProcessingWindowChange, false) + uint32_t lastSoftInputKeyboardAreaUpdatedWindowId_ { 0 }; }; } } diff --git a/wmserver/include/window_controller.h b/wmserver/include/window_controller.h index 37a7e16c..ca602bfb 100644 --- a/wmserver/include/window_controller.h +++ b/wmserver/include/window_controller.h @@ -43,7 +43,7 @@ public: WMError RequestFocus(uint32_t windowId); WMError SetWindowBackgroundBlur(uint32_t windowId, WindowBlurLevel level); WMError SetAlpha(uint32_t windowId, float alpha); - std::vector GetAvoidAreaByType(uint32_t windowId, AvoidAreaType avoidAreaType); + AvoidArea GetAvoidAreaByType(uint32_t windowId, AvoidAreaType avoidAreaType); WMError GetTopWindowId(uint32_t mainWinId, uint32_t& topWinId); void NotifyDisplayStateChange(DisplayId defaultDisplayId, sptr displayInfo, const std::map>& displayInfoMap, DisplayStateChangeType type); diff --git a/wmserver/include/window_manager_service.h b/wmserver/include/window_manager_service.h index a91646f5..0366f24c 100644 --- a/wmserver/include/window_manager_service.h +++ b/wmserver/include/window_manager_service.h @@ -78,7 +78,7 @@ public: WMError RequestFocus(uint32_t windowId) override; WMError SetWindowBackgroundBlur(uint32_t windowId, WindowBlurLevel level) override; WMError SetAlpha(uint32_t windowId, float alpha) override; - std::vector GetAvoidAreaByType(uint32_t windowId, AvoidAreaType avoidAreaType) override; + AvoidArea GetAvoidAreaByType(uint32_t windowId, AvoidAreaType avoidAreaType) override; void ProcessPointDown(uint32_t windowId, bool isStartDrag) override; void ProcessPointUp(uint32_t windowId) override; WMError GetTopWindowId(uint32_t mainWinId, uint32_t& topWinId) override; @@ -97,6 +97,7 @@ public: WMError SetWindowAnimationController(const sptr& controller) override; WMError GetSystemConfig(SystemConfig& systemConfig) override; WMError GetModeChangeHotZones(DisplayId displayId, ModeChangeHotZones& hotZones) override; + WMError UpdateAvoidAreaListener(uint32_t windowId, bool haveAvoidAreaListener) override; void StartingWindow(sptr info, sptr pixelMap, bool isColdStart, uint32_t bkgColor = 0xffffffff); void CancelStartingWindow(sptr abilityToken); diff --git a/wmserver/include/window_node_container.h b/wmserver/include/window_node_container.h index f2273fbb..faea28a7 100644 --- a/wmserver/include/window_node_container.h +++ b/wmserver/include/window_node_container.h @@ -56,7 +56,7 @@ public: uint32_t ToOverrideBrightness(float brightness); void UpdateBrightness(uint32_t id, bool byRemoved); void HandleKeepScreenOn(const sptr& node, bool requireLock); - std::vector GetAvoidAreaByType(AvoidAreaType avoidAreaType, DisplayId displayId); + AvoidArea GetAvoidAreaByType(const sptr& node, AvoidAreaType avoidAreaType); WMError MinimizeStructuredAppWindowsExceptSelf(const sptr& node); void TraverseContainer(std::vector>& windowNodes) const; uint64_t GetScreenId(DisplayId displayId) const; @@ -69,7 +69,6 @@ public: void ExitSplitMode(DisplayId displayId); Orientation GetFullScreenWindowRequestedOrientation(); - void OnAvoidAreaChange(const std::vector& avoidAreas, DisplayId displayId); bool isVerticalDisplay(DisplayId displayId) const; WMError RaiseZOrderForAppWindow(sptr& node, sptr& parentNode); sptr GetNextFocusableWindow(uint32_t windowId) const; @@ -106,6 +105,9 @@ public: sptr GetRootNode(WindowRootNodeType type) const; void NotifyDockWindowStateChanged(sptr& node, bool isEnable); void UpdateCameraFloatWindowStatus(const sptr& node, bool isShowing); + void UpdateAvoidAreaListener(sptr& windowNode, bool haveAvoidAreaListener); + void BeforeProcessWindowAvoidAreaChangeWhenDisplayChange() const; + void ProcessWindowAvoidAreaChangeWhenDisplayChange() const; private: void TraverseWindowNode(sptr& root, std::vector>& windowNodes) const; @@ -146,6 +148,7 @@ private: const std::vector& lastShowingDisplays, const std::vector& curShowingDisplays); void FillWindowInfo(sptr& windowInfo, const sptr& node) const; + bool CheckWindowNodeWhetherInWindowTree(const sptr& node) const; float displayBrightness_ = UNDEFINED_BRIGHTNESS; uint32_t brightnessWindow_ = INVALID_WINDOW_ID; diff --git a/wmserver/include/window_root.h b/wmserver/include/window_root.h index fcc06234..660802fd 100644 --- a/wmserver/include/window_root.h +++ b/wmserver/include/window_root.h @@ -38,6 +38,7 @@ public: ~WindowRoot() = default; sptr GetOrCreateWindowNodeContainer(DisplayId displayId); + sptr GetWindowNodeContainer(DisplayId displayId); sptr CreateWindowNodeContainer(sptr displayInfo); sptr GetWindowNode(uint32_t windowId) const; @@ -58,7 +59,7 @@ public: WMError RequestFocus(uint32_t windowId); WMError RequestActiveWindow(uint32_t windowId); WMError MinimizeStructuredAppWindowsExceptSelf(sptr& node); - std::vector GetAvoidAreaByType(uint32_t windowId, AvoidAreaType avoidAreaType); + AvoidArea GetAvoidAreaByType(uint32_t windowId, AvoidAreaType avoidAreaType); WMError SetWindowMode(sptr& node, WindowMode dstMode); std::shared_ptr GetSurfaceNodeByAbilityToken(const sptr& abilityToken) const; WMError GetTopWindowId(uint32_t mainWinId, uint32_t& topWinId); diff --git a/wmserver/include/zidl/window_manager_interface.h b/wmserver/include/zidl/window_manager_interface.h index a77c7d3f..6a2576b6 100644 --- a/wmserver/include/zidl/window_manager_interface.h +++ b/wmserver/include/zidl/window_manager_interface.h @@ -59,6 +59,7 @@ public: TRANS_ID_NOTIFY_WINDOW_TRANSITION, TRANS_ID_GET_FULLSCREEN_AND_SPLIT_HOT_ZONE, TRANS_ID_GET_ANIMATION_CALLBACK, + TRANS_ID_UPDATE_AVOIDAREA_LISTENER, }; virtual WMError CreateWindow(sptr& window, sptr& property, const std::shared_ptr& surfaceNode, @@ -69,7 +70,7 @@ public: virtual WMError RequestFocus(uint32_t windowId) = 0; virtual WMError SetWindowBackgroundBlur(uint32_t windowId, WindowBlurLevel level) = 0; virtual WMError SetAlpha(uint32_t windowId, float alpha) = 0; - virtual std::vector GetAvoidAreaByType(uint32_t windowId, AvoidAreaType type) = 0; + virtual AvoidArea GetAvoidAreaByType(uint32_t windowId, AvoidAreaType type) = 0; virtual WMError GetTopWindowId(uint32_t mainWinId, uint32_t& topWinId) = 0; virtual void ProcessPointDown(uint32_t windowId, bool isStartDrag) = 0; virtual void ProcessPointUp(uint32_t windowId) = 0; @@ -89,6 +90,7 @@ public: virtual WMError GetModeChangeHotZones(DisplayId displayId, ModeChangeHotZones& hotZones) = 0; virtual void MinimizeWindowsByLauncher(std::vector windowIds, bool isAnimated, sptr& finishCallback) = 0; + virtual WMError UpdateAvoidAreaListener(uint32_t windowId, bool haveListener) = 0; }; } } diff --git a/wmserver/include/zidl/window_manager_proxy.h b/wmserver/include/zidl/window_manager_proxy.h index f7e5d869..fc358929 100644 --- a/wmserver/include/zidl/window_manager_proxy.h +++ b/wmserver/include/zidl/window_manager_proxy.h @@ -38,7 +38,7 @@ public: WMError RequestFocus(uint32_t windowId) override; WMError SetWindowBackgroundBlur(uint32_t windowId, WindowBlurLevel level) override; WMError SetAlpha(uint32_t windowId, float alpha) override; - std::vector GetAvoidAreaByType(uint32_t windowId, AvoidAreaType type) override; + AvoidArea GetAvoidAreaByType(uint32_t windowId, AvoidAreaType type) override; WMError GetTopWindowId(uint32_t mainWinId, uint32_t& topWinId) override; void ProcessPointDown(uint32_t windowId, bool isStartDrag) override; void ProcessPointUp(uint32_t windowId) override; @@ -58,6 +58,8 @@ public: WMError GetModeChangeHotZones(DisplayId displayId, ModeChangeHotZones& hotZones) override; void MinimizeWindowsByLauncher(std::vector windowIds, bool isAnimated, sptr& finishCallback) override; + WMError UpdateAvoidAreaListener(uint32_t windowId, bool haveListener) override; + private: static inline BrokerDelegator delegator_; }; diff --git a/wmserver/src/avoid_area_controller.cpp b/wmserver/src/avoid_area_controller.cpp index 444aeae4..6f5a1322 100644 --- a/wmserver/src/avoid_area_controller.cpp +++ b/wmserver/src/avoid_area_controller.cpp @@ -14,7 +14,7 @@ */ #include "avoid_area_controller.h" -#include "display_manager_service_inner.h" +#include "display_manager_config.h" #include "window_helper.h" #include "window_manager_hilog.h" #include "wm_trace.h" @@ -25,154 +25,337 @@ namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "AvoidAreaController"}; } -const int32_t AVOID_NUM = 4; - -AvoidAreaController::AvoidAreaController(DisplayId displayId, UpdateAvoidAreaFunc callback) +void AvoidAreaController::UpdateAvoidAreaListener(sptr& windowNode, bool isRegisterListener) { - UpdateAvoidNodesMap(displayId, true); - updateAvoidAreaCallBack_ = callback; -} - -void AvoidAreaController::UpdateAvoidNodesMap(DisplayId displayId, bool isAdd) -{ - if (isAdd) { - auto avoidNodesMapPtr = std::make_unique>>(); - avoidNodesMaps_.insert(std::make_pair(displayId, std::move(avoidNodesMapPtr))); + WLOGFE("haveAvoidAreaListener %{public}d", isRegisterListener); + if (windowNode == nullptr) { + WLOGFE("windowNode is nullptr."); + return; + } + if (isRegisterListener) { + avoidAreaListenerNodes_.insert(windowNode); } else { - avoidNodesMaps_.erase(displayId); + lastUpdatedAvoidArea_.erase(windowNode->GetWindowId()); + avoidAreaListenerNodes_.erase(windowNode); } } -bool AvoidAreaController::IsAvoidAreaNode(const sptr& node) const +void AvoidAreaController::ProcessWindowChange(const sptr& windowNode, AvoidControlType avoidType, + const std::function)>& checkFunc) { - if (node == nullptr) { - WLOGFE("IsAvoidAreaNode Failed, node is nullptr"); - return false; + if (isForbidProcessingWindowChange_) { + WLOGFI("do not process window change."); + return; } - - if (!WindowHelper::IsAvoidAreaWindow(node->GetWindowType())) { - WLOGFE("IsAvoidAreaNode Failed, node type is not avoid type"); - return false; + if (windowNode == nullptr || windowNode->GetWindowToken() == nullptr) { + WLOGFE("invalid WindowNode."); + return; } - - return true; -} - -std::map>* AvoidAreaController::GetAvoidNodesByDisplayId( - DisplayId displayId) -{ - if ((const_cast(this)->avoidNodesMaps_).find(displayId) != - (const_cast(this)->avoidNodesMaps_).end()) { - return (const_cast(this)->avoidNodesMaps_)[displayId].get(); - } - return nullptr; -} - -AvoidPosType AvoidAreaController::GetAvoidPosType(const Rect& rect, DisplayId displayId) const -{ - auto display = DisplayManagerServiceInner::GetInstance().GetDisplayById(displayId); - if (display == nullptr) { - WLOGFE("GetAvoidPosType fail. Get display fail. displayId:%{public}" PRIu64"", displayId); - return AvoidPosType::AVOID_POS_UNKNOWN; - } - uint32_t displayWidth = static_cast(display->GetWidth()); - uint32_t displayHeight = static_cast(display->GetHeight()); - - return WindowHelper::GetAvoidPosType(rect, displayWidth, displayHeight); -} - -WMError AvoidAreaController::AvoidControl(const sptr& node, AvoidControlType type) -{ - if (!IsAvoidAreaNode(node)) { - WLOGFE("AvoidControl check param Failed. Type: %{public}u", type); - return WMError::WM_ERROR_INVALID_PARAM; - } - - auto avoidNodes = GetAvoidNodesByDisplayId(node->GetDisplayId()); - uint32_t windowId = node->GetWindowId(); - auto iter = avoidNodes->find(windowId); - // do not add a exist node(the same id) - if (type == AvoidControlType::AVOID_NODE_ADD && iter != avoidNodes->end()) { - WLOGFE("WinId:%{public}d is added. AvoidControl Add Failed. Type: %{public}u", windowId, type); - return WMError::WM_ERROR_INVALID_PARAM; - } - // do not update or remove a non-exist node - if (type != AvoidControlType::AVOID_NODE_ADD && iter == avoidNodes->end()) { - WLOGFE("WinId:%{public}d not exist. AvoidControl Update or Remove Failed. Type: %{public}u", windowId, type); - return WMError::WM_ERROR_INVALID_PARAM; - } - - switch (type) { + switch (avoidType) { case AvoidControlType::AVOID_NODE_ADD: - (*avoidNodes)[windowId] = node; - WLOGFI("WinId:%{public}d add. And the windowType is %{public}d", windowId, node->GetWindowType()); + case AvoidControlType::AVOID_NODE_REMOVE: + AddOrRemoveOverlayWindowIfNeed(windowNode, avoidType == AvoidControlType::AVOID_NODE_ADD); break; case AvoidControlType::AVOID_NODE_UPDATE: - (*avoidNodes)[windowId] = node; - WLOGFI("WinId:%{public}d update. And the windowType is %{public}d", windowId, node->GetWindowType()); - break; - case AvoidControlType::AVOID_NODE_REMOVE: - avoidNodes->erase(iter); - WLOGFI("WinId:%{public}d remove. And the windowType is %{public}d", windowId, node->GetWindowType()); + UpdateOverlayWindowIfNeed(windowNode, checkFunc); break; default: - WLOGFE("invalid AvoidControlType: %{public}u", type); - return WMError::WM_ERROR_INVALID_PARAM; + break; } - - // get all Area info and notify window container - std::vector avoidAreas = GetAvoidArea(node->GetDisplayId()); - DumpAvoidArea(avoidAreas); - UseCallbackNotifyAvoidAreaChanged(avoidAreas, node->GetDisplayId()); - return WMError::WM_OK; } -std::vector AvoidAreaController::GetAvoidArea(DisplayId displayId) const +void AvoidAreaController::AddOrRemoveOverlayWindowIfNeed(const sptr& overlayNode, bool isAdding) { - auto avoidNodesPtr = const_cast(this)->GetAvoidNodesByDisplayId(displayId); - std::vector avoidArea(AVOID_NUM, {0, 0, 0, 0}); // avoid area left, top, right, bottom - for (auto iter = avoidNodesPtr->begin(); iter != avoidNodesPtr->end(); ++iter) { - Rect curRect = iter->second->GetWindowRect(); - auto curPos = GetAvoidPosType(curRect, iter->second->GetDisplayId()); - if (curPos == AvoidPosType::AVOID_POS_UNKNOWN) { - WLOGFE("GetAvoidArea AVOID_POS_UNKNOWN Rect: x : %{public}d, y: %{public}d, w: %{public}u h: %{public}u", - static_cast(curRect.posX_), static_cast(curRect.posY_), - static_cast(curRect.width_), static_cast(curRect.height_)); - continue; + if (!WindowHelper::IsOverlayWindow(overlayNode->GetWindowType())) { + WLOGFE("IsOverlayWindow Failed."); + return; + } + WM_FUNCTION_TRACE(); + + uint32_t overlayId = overlayNode->GetWindowId(); + bool isRecorded = (overlayWindowMap_.find(overlayId) != overlayWindowMap_.end()); + if (isAdding == isRecorded) { + WLOGE("error occured in overlay. overlayId %{public}u isAdding %{public}d record flag %{public}d", + overlayId, isAdding, isRecorded); + return; + } + WLOGFE("overlayId %{public}u isAdding %{public}d record flag %{public}d", overlayId, isAdding, isRecorded); + if (isAdding) { + overlayWindowMap_.insert(std::make_pair(overlayId, overlayNode)); + } else { + overlayWindowMap_.erase(overlayId); + } + + if (overlayNode->GetWindowType() == WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT) { + AddOrRemoveKeyboard(overlayNode, isAdding); + return; + } + + for (auto& node : avoidAreaListenerNodes_) { + AvoidArea systemAvoidArea = GetAvoidAreaByType(node, AvoidAreaType::TYPE_SYSTEM); + UpdateAvoidAreaIfNeed(systemAvoidArea, node, AvoidAreaType::TYPE_SYSTEM); + } +} + +void AvoidAreaController::AddOrRemoveKeyboard(const sptr& keyboardNode, bool isAdding) +{ + const uint32_t callingWindowId = keyboardNode->GetCallingWindow(); + sptr callingWindow = nullptr; + sptr focusWindow = nullptr; + sptr lastSoftInputKeyboardAreaUpdatedWindow = nullptr; + for (auto window : avoidAreaListenerNodes_) { + if (window != nullptr && window->GetWindowToken() != nullptr && window->GetWindowId() == callingWindowId) { + callingWindow = window; + } + if (window != nullptr && window->GetWindowToken() != nullptr && window->GetWindowId() == focusedWindow_) { + focusWindow = window; + } + if (window != nullptr && window->GetWindowToken() != nullptr && + window->GetWindowId() == lastSoftInputKeyboardAreaUpdatedWindowId_) { + lastSoftInputKeyboardAreaUpdatedWindow = window; + } + } + if (callingWindow == nullptr) { + callingWindow = focusWindow; + } + if (lastSoftInputKeyboardAreaUpdatedWindow != nullptr && lastSoftInputKeyboardAreaUpdatedWindow != callingWindow) { + const WindowMode windowMode = lastSoftInputKeyboardAreaUpdatedWindow->GetWindowMode(); + if (windowMode == WindowMode::WINDOW_MODE_FULLSCREEN || + windowMode == WindowMode::WINDOW_MODE_SPLIT_PRIMARY || + windowMode == WindowMode::WINDOW_MODE_SPLIT_SECONDARY || + windowMode == WindowMode::WINDOW_MODE_FLOATING) { + auto avoidArea = GetAvoidAreaByType(lastSoftInputKeyboardAreaUpdatedWindow, AvoidAreaType::TYPE_KEYBOARD); + UpdateAvoidAreaIfNeed(avoidArea, lastSoftInputKeyboardAreaUpdatedWindow, AvoidAreaType::TYPE_KEYBOARD); + } + } + if (callingWindow == nullptr && focusWindow == nullptr) { + WLOGFI("callingWindow: %{public}u is nullptr, focusWindow: %{public}u is nullptr.", + callingWindowId, focusedWindow_); + return; + } + const WindowMode callingWindowMode = callingWindow->GetWindowMode(); + if (callingWindowMode == WindowMode::WINDOW_MODE_FULLSCREEN || + callingWindowMode == WindowMode::WINDOW_MODE_SPLIT_PRIMARY || + callingWindowMode == WindowMode::WINDOW_MODE_SPLIT_SECONDARY || + callingWindowMode == WindowMode::WINDOW_MODE_FLOATING) { + auto avoidArea = GetAvoidAreaByType(callingWindow, AvoidAreaType::TYPE_KEYBOARD); + bool res = UpdateAvoidAreaIfNeed(avoidArea, callingWindow, AvoidAreaType::TYPE_KEYBOARD); + if (res) { + lastSoftInputKeyboardAreaUpdatedWindowId_ = callingWindow->GetWindowId(); + } + return; + } + WLOGFE("does not have correct callingWindowMode for input method window"); +} + +void AvoidAreaController::UpdateOverlayWindowIfNeed(const sptr& node, + const std::function)>& checkFunc) +{ + WM_FUNCTION_TRACE(); + if (WindowHelper::IsOverlayWindow(node->GetWindowType())) { + AvoidAreaType type = WindowHelper::IsSystemBarWindow(node->GetWindowType()) ? + AvoidAreaType::TYPE_SYSTEM : AvoidAreaType::TYPE_KEYBOARD; + for (auto& appNode : avoidAreaListenerNodes_) { + if (checkFunc != nullptr && checkFunc(appNode)) { + bool res = UpdateAvoidAreaIfNeed(GetAvoidAreaByType(appNode, type), appNode, type); + if (type == AvoidAreaType::TYPE_KEYBOARD && res) { + lastSoftInputKeyboardAreaUpdatedWindowId_ = appNode->GetWindowId(); + } + } + } + } else { + if (avoidAreaListenerNodes_.find(node) == avoidAreaListenerNodes_.end()) { + WLOGE("window: %{public}u is not in avoidAreaListenerNodes, don't update avoid area.", node->GetWindowId()); + return; + } + AvoidArea systemAvoidArea = GetAvoidAreaByType(node, AvoidAreaType::TYPE_SYSTEM); + AvoidArea cutoutAvoidArea = GetAvoidAreaByType(node, AvoidAreaType::TYPE_CUTOUT); + AvoidArea gestureAvoidArea = GetAvoidAreaByType(node, AvoidAreaType::TYPE_SYSTEM_GESTURE); + AvoidArea keyboardAvoidArea = GetAvoidAreaByType(node, AvoidAreaType::TYPE_KEYBOARD); + UpdateAvoidAreaIfNeed(systemAvoidArea, node, AvoidAreaType::TYPE_SYSTEM); + UpdateAvoidAreaIfNeed(cutoutAvoidArea, node, AvoidAreaType::TYPE_CUTOUT); + UpdateAvoidAreaIfNeed(gestureAvoidArea, node, AvoidAreaType::TYPE_SYSTEM_GESTURE); + if (UpdateAvoidAreaIfNeed(keyboardAvoidArea, node, AvoidAreaType::TYPE_KEYBOARD)) { + lastSoftInputKeyboardAreaUpdatedWindowId_ = node->GetWindowId(); + } + } +} + +bool AvoidAreaController::UpdateAvoidAreaIfNeed(const AvoidArea& avoidArea, const sptr& node, + AvoidAreaType avoidAreaType) +{ + auto iter = lastUpdatedAvoidArea_.find(node->GetWindowId()); + bool needUpdate = true; + if (iter != lastUpdatedAvoidArea_.end()) { + auto avoidAreaIter = iter->second.find(avoidAreaType); + if (avoidAreaIter != iter->second.end()) { + needUpdate = avoidAreaIter->second != avoidArea; + } else { + if (avoidArea.isEmptyAvoidArea()) { + needUpdate = false; + } + } + } else { + if (avoidArea.isEmptyAvoidArea()) { + needUpdate = false; + } + } + if (needUpdate) { + lastUpdatedAvoidArea_[node->GetWindowId()][avoidAreaType] = avoidArea; + node->GetWindowToken()->UpdateAvoidArea(new AvoidArea(avoidArea), avoidAreaType); + } + return needUpdate; +} + +AvoidPosType AvoidAreaController::CalculateOverlayRect(const sptr& node, + const sptr& overlayNode, Rect& overlayRect) const +{ + if (node->GetWindowId() == overlayNode->GetWindowId()) { + WLOGE("overlay not support self. windowId %{public}u", node->GetWindowId()); + return AvoidPosType::AVOID_POS_UNKNOWN; + } + const Rect rect = node->GetWindowRect(); + overlayRect = WindowHelper::GetOverlap(overlayNode->GetWindowRect(), rect, rect.posX_, rect.posY_); + return GetAvoidPosType(rect, overlayRect); +} + +AvoidPosType AvoidAreaController::GetAvoidPosType(const Rect& windowRect, const Rect& overlayRect) const +{ + if (windowRect.width_ == 0 || windowRect.height_ == 0) { + return AvoidPosType::AVOID_POS_UNKNOWN; + } + uint32_t centerX = overlayRect.posX_ + (overlayRect.width_ >> 1); + uint32_t centerY = overlayRect.posY_ + (overlayRect.height_ >> 1); + float res1 = float(centerY) - float(windowRect.height_) / float(windowRect.width_) * float(centerX); + float res2 = float(centerY) + float(windowRect.height_) / float(windowRect.width_) * float(centerX) + - float(windowRect.height_); + if (res1 < 0) { + if (res2 < 0) { + return AvoidPosType::AVOID_POS_TOP; + } + return AvoidPosType::AVOID_POS_RIGHT; + } + if (res2 < 0) { + return AvoidPosType::AVOID_POS_LEFT; + } + return AvoidPosType::AVOID_POS_BOTTOM; +} + +void AvoidAreaController::SetAvoidAreaRect(AvoidArea& avoidArea, Rect& rect, AvoidPosType type) const +{ + switch (type) { + case AvoidPosType::AVOID_POS_TOP : { + avoidArea.topRect_ = rect; + break; + } + case AvoidPosType::AVOID_POS_LEFT : { + avoidArea.leftRect_ = rect; + break; + } + case AvoidPosType::AVOID_POS_RIGHT : { + avoidArea.rightRect_ = rect; + break; + } + case AvoidPosType::AVOID_POS_BOTTOM : { + avoidArea.bottomRect_ = rect; + break; + } + default : { + WLOGFI("default type: %{public}u", type); + } + } +} + +AvoidArea AvoidAreaController::GetAvoidAreaByType(const sptr& node, AvoidAreaType avoidAreaType) const +{ + WLOGFI("avoidAreaType: %{public}u", avoidAreaType); + if (node == nullptr) { + WLOGFE("invalid WindowNode."); + return {}; + } + WindowMode windowMode = node->GetWindowMode(); + if (avoidAreaType != AvoidAreaType::TYPE_KEYBOARD && + windowMode != WindowMode::WINDOW_MODE_FULLSCREEN && + windowMode != WindowMode::WINDOW_MODE_SPLIT_PRIMARY && + windowMode != WindowMode::WINDOW_MODE_SPLIT_SECONDARY) { + WLOGFI("avoidAreaType: %{public}u, windowMode: %{public}u, return default avoid area.", + avoidAreaType, windowMode); + return {}; + } + switch (avoidAreaType) { + case AvoidAreaType::TYPE_SYSTEM : { + return GetAvoidAreaSystemType(node); + } + case AvoidAreaType::TYPE_KEYBOARD : { + return GetAvoidAreaKeyboardType(node); + } + case AvoidAreaType::TYPE_CUTOUT : { + auto numbersConfig = DisplayManagerConfig::GetIntNumbersConfig(); + if (numbersConfig.count("cutoutArea") == 0) { + return {}; + } + std::vector cutoutArea = numbersConfig["cutoutArea"]; + // 0, 1, 2, 3 means the index in the vector. + Rect cutoutAreaRect { cutoutArea[0], cutoutArea[1], (uint32_t)cutoutArea[2], (uint32_t)cutoutArea[3] }; + auto rect = node->GetWindowRect(); + Rect overlayRect = WindowHelper::GetOverlap(cutoutAreaRect, rect, rect.posX_, rect.posY_); + auto type = GetAvoidPosType(rect, overlayRect); + AvoidArea avoidArea; + SetAvoidAreaRect(avoidArea, overlayRect, type); + return avoidArea; + } + default : { + WLOGFI("cannot find avoidAreaType: %{public}u", avoidAreaType); + return {}; + } + } +} + +AvoidArea AvoidAreaController::GetAvoidAreaSystemType(const sptr& node) const +{ + AvoidArea systemAvoidArea; + Rect statusBarAvoidArea; + AvoidPosType statusBarAvoidPosType = AvoidPosType::AVOID_POS_UNKNOWN; + Rect navigationBarAvoidArea; + AvoidPosType navigationBarAvoidPosType = AvoidPosType::AVOID_POS_UNKNOWN; + for (auto& iter : overlayWindowMap_) { + if (iter.second != nullptr) { + if (iter.second->GetWindowType() == WindowType::WINDOW_TYPE_STATUS_BAR) { + statusBarAvoidPosType = CalculateOverlayRect(node, iter.second, statusBarAvoidArea); + } + if (iter.second->GetWindowType() == WindowType::WINDOW_TYPE_NAVIGATION_BAR) { + navigationBarAvoidPosType = CalculateOverlayRect(node, iter.second, navigationBarAvoidArea); + } + } + } + SetAvoidAreaRect(systemAvoidArea, statusBarAvoidArea, statusBarAvoidPosType); + SetAvoidAreaRect(systemAvoidArea, navigationBarAvoidArea, navigationBarAvoidPosType); + return systemAvoidArea; +} + +AvoidArea AvoidAreaController::GetAvoidAreaKeyboardType(const sptr& node) const +{ + AvoidArea avoidArea; + if (focusedWindow_ != node->GetWindowId()) { + WLOGFI("focusedWindow: %{public}u is not windowId: %{public}u", focusedWindow_, node->GetWindowId()); + return avoidArea; + } + for (auto& iter : overlayWindowMap_) { + if (iter.second != nullptr && + iter.second->GetWindowType() == WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT) { + const uint32_t callingWindowId = iter.second->GetCallingWindow(); + if (callingWindowId != node->GetWindowId() && focusedWindow_ != node->GetWindowId()) { + WLOGFI("windowId: %{public}u is not focusedWindow: %{public}u or callingWindow: %{public}u", + node->GetWindowId(), focusedWindow_, callingWindowId); + continue; + } + Rect avoidAreaRect; + AvoidPosType avoidPosType = CalculateOverlayRect(node, iter.second, avoidAreaRect); + SetAvoidAreaRect(avoidArea, avoidAreaRect, avoidPosType); + return avoidArea; } - avoidArea[static_cast(curPos)] = curRect; } return avoidArea; } - -std::vector AvoidAreaController::GetAvoidAreaByType(AvoidAreaType avoidAreaType, DisplayId displayId) const -{ - if (avoidAreaType != AvoidAreaType::TYPE_SYSTEM) { - WLOGFE("GetAvoidAreaByType. Support Type is AvoidAreaType::TYPE_SYSTEM. But current type is %{public}u", - static_cast(avoidAreaType)); - std::vector avoidArea(AVOID_NUM, {0, 0, 0, 0}); - return avoidArea; - } - WLOGFI("AvoidAreaController::GetAvoidAreaByType Success"); - return GetAvoidArea(displayId); -} - -void AvoidAreaController::UseCallbackNotifyAvoidAreaChanged(std::vector& avoidArea, DisplayId displayId) const -{ - if (updateAvoidAreaCallBack_) { - updateAvoidAreaCallBack_(avoidArea, displayId); - } -} - -void AvoidAreaController::DumpAvoidArea(const std::vector& avoidArea) const -{ - WLOGFI("----------------- AvoidArea Begin-----------------"); - WLOGFI(" No [ x y w h]"); - for (uint32_t i = 0; i < avoidArea.size(); i++) { - WLOGFI("%{public}4u [%{public}4d %{public}4d %{public}4u %{public}4u]", i, - avoidArea[i].posX_, avoidArea[i].posY_, avoidArea[i].width_, avoidArea[i].height_); - } - WLOGFI("----------------- AvoidArea End-----------------"); -} } } diff --git a/wmserver/src/display_group_controller.cpp b/wmserver/src/display_group_controller.cpp index e42cb5cd..1db53d21 100644 --- a/wmserver/src/display_group_controller.cpp +++ b/wmserver/src/display_group_controller.cpp @@ -358,7 +358,7 @@ void DisplayGroupController::ProcessDisplayCreate(DisplayId defaultDisplayId, sp WLOGFI("defaultDisplay, displayId: %{public}" PRIu64"", defaultDisplayId); DisplayId displayId = displayInfo->GetDisplayId(); - windowNodeContainer_->GetAvoidController()->UpdateAvoidNodesMap(displayId, true); + InitNewDisplay(displayId); // add displayInfo in displayGroupInfo @@ -377,7 +377,6 @@ void DisplayGroupController::ProcessDisplayDestroy(DisplayId defaultDisplayId, s std::vector& windowIds) { DisplayId displayId = displayInfo->GetDisplayId(); - windowNodeContainer_->GetAvoidController()->UpdateAvoidNodesMap(displayId, false); // delete nodes and map element of deleted display ProcessNotCrossNodesOnDestroyedDisplay(displayId, windowIds); diff --git a/wmserver/src/window_controller.cpp b/wmserver/src/window_controller.cpp index 5ba4dad4..d6ab58c7 100644 --- a/wmserver/src/window_controller.cpp +++ b/wmserver/src/window_controller.cpp @@ -495,6 +495,10 @@ void WindowController::ProcessDisplayChange(DisplayId defaultDisplayId, sptrGetOrCreateWindowNodeContainer(displayInfo->GetDisplayId()); + if (windowNodeContainer != nullptr) { + windowNodeContainer->BeforeProcessWindowAvoidAreaChangeWhenDisplayChange(); + } DisplayId displayId = displayInfo->GetDisplayId(); switch (type) { case DisplayStateChangeType::SIZE_CHANGE: @@ -511,6 +515,9 @@ void WindowController::ProcessDisplayChange(DisplayId defaultDisplayId, sptrProcessWindowAvoidAreaChangeWhenDisplayChange(); + } WLOGFI("Finish ProcessDisplayChange"); } @@ -609,10 +616,9 @@ WMError WindowController::SetWindowAnimationController(const sptr WindowController::GetAvoidAreaByType(uint32_t windowId, AvoidAreaType avoidAreaType) +AvoidArea WindowController::GetAvoidAreaByType(uint32_t windowId, AvoidAreaType avoidAreaType) { - std::vector avoidArea = windowRoot_->GetAvoidAreaByType(windowId, avoidAreaType); - return avoidArea; + return windowRoot_->GetAvoidAreaByType(windowId, avoidAreaType); } WMError WindowController::ProcessPointDown(uint32_t windowId, bool isStartDrag) diff --git a/wmserver/src/window_dumper.cpp b/wmserver/src/window_dumper.cpp index 2b773b1a..f1fe6015 100644 --- a/wmserver/src/window_dumper.cpp +++ b/wmserver/src/window_dumper.cpp @@ -247,7 +247,7 @@ void WindowDumper::ShowIllegalArgsInfo(std::string& dumpInfo, WMError errCode) c dumpInfo.append("The arguments are illegal and you can enter '-h' for help."); break; case WMError::WM_ERROR_NULLPTR: - dumpInfo.append("The window is invalid, you can enter '-a' to get valid window id."); + dumpInfo.append("The window is invalid, you can enter '-a' to get valid window id."); break; default: break; diff --git a/wmserver/src/window_manager_service.cpp b/wmserver/src/window_manager_service.cpp index 6aa870c1..d14f68ba 100644 --- a/wmserver/src/window_manager_service.cpp +++ b/wmserver/src/window_manager_service.cpp @@ -462,7 +462,7 @@ WMError WindowManagerService::SetAlpha(uint32_t windowId, float alpha) }).get(); } -std::vector WindowManagerService::GetAvoidAreaByType(uint32_t windowId, AvoidAreaType avoidAreaType) +AvoidArea WindowManagerService::GetAvoidAreaByType(uint32_t windowId, AvoidAreaType avoidAreaType) { return wmsTaskLooper_->ScheduleTask([this, windowId, avoidAreaType]() { WLOGFI("[WMS] GetAvoidAreaByType: %{public}u, Type: %{public}u", windowId, @@ -665,5 +665,24 @@ void WindowManagerService::GetFullScreenWindowRequestedOrientation(DisplayId dis orientation = windowController_->GetFullScreenWindowRequestedOrientation(displayId); }).wait(); } + +WMError WindowManagerService::UpdateAvoidAreaListener(uint32_t windowId, bool haveAvoidAreaListener) +{ + return wmsTaskLooper_->ScheduleTask([this, windowId, haveAvoidAreaListener]() { + WM_SCOPED_TRACE("wms:UpdateAvoidAreaListener"); + sptr node = windowRoot_->GetWindowNode(windowId); + if (node == nullptr) { + WLOGFE("get window node failed. win %{public}u", windowId); + return WMError::WM_DO_NOTHING; + } + sptr container = windowRoot_->GetWindowNodeContainer(node->GetDisplayId()); + if (container == nullptr) { + WLOGFE("get container failed. win %{public}u display %{public}" PRIu64"", windowId, node->GetDisplayId()); + return WMError::WM_DO_NOTHING; + } + container->UpdateAvoidAreaListener(node, haveAvoidAreaListener); + return WMError::WM_OK; + }).get(); +} } // namespace Rosen } // namespace OHOS \ No newline at end of file diff --git a/wmserver/src/window_node_container.cpp b/wmserver/src/window_node_container.cpp index d82228bb..942fa200 100644 --- a/wmserver/src/window_node_container.cpp +++ b/wmserver/src/window_node_container.cpp @@ -65,9 +65,7 @@ WindowNodeContainer::WindowNodeContainer(const sptr& displayInfo, S Rect initalDividerRect = layoutPolicies_[WindowLayoutMode::CASCADE]->GetInitalDividerRect(displayId); displayGroupController_->SetInitalDividerRect(displayId, initalDividerRect); // init avoidAreaController - UpdateAvoidAreaFunc func = std::bind(&WindowNodeContainer::OnAvoidAreaChange, this, - std::placeholders::_1, std::placeholders::_2); - avoidController_ = new AvoidAreaController(displayId, func); + avoidController_ = new AvoidAreaController(focusedWindow_); } WindowNodeContainer::~WindowNodeContainer() @@ -110,7 +108,7 @@ WMError WindowNodeContainer::AddWindowNodeOnWindowTree(sptr& node, c for (auto& child : node->children_) { child->currentVisibility_ = child->requestedVisibility_; } - if (WindowHelper::IsAvoidAreaWindow(node->GetWindowType())) { + if (WindowHelper::IsSystemBarWindow(node->GetWindowType())) { displayGroupController_->sysBarNodeMaps_[node->GetDisplayId()][node->GetWindowType()] = node; } } @@ -226,13 +224,9 @@ WMError WindowNodeContainer::UpdateWindowNode(sptr& node, WindowUpda if (WindowHelper::IsMainWindow(node->GetWindowType()) && WindowHelper::IsSwitchCascadeReason(reason)) { SwitchLayoutPolicy(WindowLayoutMode::CASCADE, node->GetDisplayId()); } + WLOGFI("UpdateWindowNode windowId: %{public}u begin", node->GetWindowId()); layoutPolicy_->UpdateWindowNode(node); - if (WindowHelper::IsAvoidAreaWindow(node->GetWindowType())) { - avoidController_->AvoidControl(node, AvoidControlType::AVOID_NODE_UPDATE); - NotifyIfSystemBarRegionChanged(node->GetDisplayId()); - } else { - NotifyIfSystemBarTintChanged(node->GetDisplayId()); - } + NotifyIfAvoidAreaChanged(node, AvoidControlType::AVOID_NODE_UPDATE); DumpScreenWindowTree(); WLOGFI("UpdateWindowNode windowId: %{public}u end", node->GetWindowId()); return WMError::WM_OK; @@ -760,8 +754,11 @@ std::unordered_map WindowNodeContainer::GetExpect void WindowNodeContainer::NotifyIfAvoidAreaChanged(const sptr& node, const AvoidControlType avoidType) const { - if (WindowHelper::IsAvoidAreaWindow(node->GetWindowType())) { - avoidController_->AvoidControl(node, avoidType); + auto checkFunc = [this](sptr node) { + return CheckWindowNodeWhetherInWindowTree(node); + }; + avoidController_->ProcessWindowChange(node, avoidType, checkFunc); + if (WindowHelper::IsSystemBarWindow(node->GetWindowType())) { NotifyIfSystemBarRegionChanged(node->GetDisplayId()); } else { NotifyIfSystemBarTintChanged(node->GetDisplayId()); @@ -770,6 +767,24 @@ void WindowNodeContainer::NotifyIfAvoidAreaChanged(const sptr& node, NotifyIfKeyboardRegionChanged(node, avoidType); } +void WindowNodeContainer::BeforeProcessWindowAvoidAreaChangeWhenDisplayChange() const +{ + avoidController_->SetFlagForProcessWindowChange(true); +} + +void WindowNodeContainer::ProcessWindowAvoidAreaChangeWhenDisplayChange() const +{ + avoidController_->SetFlagForProcessWindowChange(false); + auto checkFunc = [this](sptr node) { + return CheckWindowNodeWhetherInWindowTree(node); + }; + WindowNodeOperationFunc func = [avoidController = avoidController_, &checkFunc](sptr node) { + avoidController->ProcessWindowChange(node, AvoidControlType::AVOID_NODE_UPDATE, checkFunc); + return false; + }; + TraverseWindowTree(func, true); +} + void WindowNodeContainer::NotifyIfSystemBarTintChanged(DisplayId displayId) const { WM_FUNCTION_TRACE(); @@ -846,9 +861,9 @@ void WindowNodeContainer::NotifyIfKeyboardRegionChanged(const sptr& } WLOGFI("keyboard size change callingWindow: [%{public}s, %{public}u], " \ - "overlap rect: [%{public}d, %{public}d, %{public}u, %{public}u]", - callingWindow->GetWindowName().c_str(), callingWindow->GetWindowId(), - overlapRect.posX_, overlapRect.posY_, overlapRect.width_, overlapRect.height_); + "overlap rect: [%{public}d, %{public}d, %{public}u, %{public}u]", + callingWindow->GetWindowName().c_str(), callingWindow->GetWindowId(), + overlapRect.posX_, overlapRect.posY_, overlapRect.width_, overlapRect.height_); sptr info = new OccupiedAreaChangeInfo(OccupiedAreaType::TYPE_INPUT, overlapRect); callingWindow->GetWindowToken()->UpdateOccupiedAreaChangeInfo(info); return; @@ -904,6 +919,11 @@ void WindowNodeContainer::NotifyDockWindowStateChanged(sptr& node, b WindowManagerAgentController::GetInstance().UpdateSystemBarRegionTints(node->GetDisplayId(), tints); } +void WindowNodeContainer::UpdateAvoidAreaListener(sptr& windowNode, bool haveAvoidAreaListener) +{ + avoidController_->UpdateAvoidAreaListener(windowNode, haveAvoidAreaListener); +} + bool WindowNodeContainer::IsTopWindow(uint32_t windowId, sptr& rootNode) const { if (rootNode->children_.empty()) { @@ -1062,19 +1082,26 @@ void WindowNodeContainer::TraverseWindowNode(sptr& node, std::vector } } -std::vector WindowNodeContainer::GetAvoidAreaByType(AvoidAreaType avoidAreaType, DisplayId displayId) +AvoidArea WindowNodeContainer::GetAvoidAreaByType(const sptr& node, AvoidAreaType avoidAreaType) { - return avoidController_->GetAvoidAreaByType(avoidAreaType, displayId); + if (CheckWindowNodeWhetherInWindowTree(node)) { + return avoidController_->GetAvoidAreaByType(node, avoidAreaType); + } + return {}; } -void WindowNodeContainer::OnAvoidAreaChange(const std::vector& avoidArea, DisplayId displayId) +bool WindowNodeContainer::CheckWindowNodeWhetherInWindowTree(const sptr& node) const { - for (auto& node : appWindowNode_->children_) { - if (node->GetWindowMode() == WindowMode::WINDOW_MODE_FULLSCREEN && node->GetWindowToken() != nullptr) { - // notify client - node->GetWindowToken()->UpdateAvoidArea(avoidArea); + bool isInWindowTree = false; + WindowNodeOperationFunc func = [&node, &isInWindowTree](sptr windowNode) { + if (node->GetWindowId() == windowNode->GetWindowId()) { + isInWindowTree = true; + return true; } - } + return false; + }; + TraverseWindowTree(func, true); + return isInWindowTree; } void WindowNodeContainer::DumpScreenWindowTree() diff --git a/wmserver/src/window_root.cpp b/wmserver/src/window_root.cpp index 22946e31..e6bc12f6 100644 --- a/wmserver/src/window_root.cpp +++ b/wmserver/src/window_root.cpp @@ -66,9 +66,22 @@ ScreenId WindowRoot::GetScreenGroupId(DisplayId displayId, bool& isRecordedDispl sptr WindowRoot::GetOrCreateWindowNodeContainer(DisplayId displayId) { - bool isRecordedDisplay; - ScreenId displayGroupId = GetScreenGroupId(displayId, isRecordedDisplay); + auto container = GetWindowNodeContainer(displayId); + if (container != nullptr) { + return container; + } + + // In case of have no container for default display, create container + WLOGFE("Create container for current display, displayId: %{public}" PRIu64 "", displayId); sptr displayInfo = DisplayManagerServiceInner::GetInstance().GetDisplayById(displayId); + return CreateWindowNodeContainer(displayInfo); +} + +sptr WindowRoot::GetWindowNodeContainer(DisplayId displayId) +{ + bool isRecordedDisplay; + sptr displayInfo = DisplayManagerServiceInner::GetInstance().GetDisplayById(displayId); + ScreenId displayGroupId = GetScreenGroupId(displayId, isRecordedDisplay); auto iter = windowNodeContainerMap_.find(displayGroupId); if (iter != windowNodeContainerMap_.end()) { // if container exist for screenGroup and display is not be recorded, process expand display @@ -81,10 +94,7 @@ sptr WindowRoot::GetOrCreateWindowNodeContainer(DisplayId d } return iter->second; } - - // In case of have no container for default display, create container - WLOGFE("Create container for current display, displayId: %{public}" PRIu64 "", displayId); - return CreateWindowNodeContainer(displayInfo); + return nullptr; } sptr WindowRoot::CreateWindowNodeContainer(sptr displayInfo) @@ -260,7 +270,6 @@ void WindowRoot::ExitSplitMode(DisplayId displayId) container->ExitSplitMode(displayId); } - void WindowRoot::AddSurfaceNodeIdWindowNodePair(uint64_t surfaceNodeId, sptr node) { surfaceIdWindowNodeMap_.insert(std::make_pair(surfaceNodeId, node)); @@ -323,21 +332,20 @@ void WindowRoot::NotifyWindowVisibilityChange(std::shared_ptr o } } -std::vector WindowRoot::GetAvoidAreaByType(uint32_t windowId, AvoidAreaType avoidAreaType) +AvoidArea WindowRoot::GetAvoidAreaByType(uint32_t windowId, AvoidAreaType avoidAreaType) { - std::vector avoidArea; - auto node = GetWindowNode(windowId); + AvoidArea avoidArea; + sptr node = GetWindowNode(windowId); if (node == nullptr) { WLOGFE("could not find window"); return avoidArea; } - auto container = GetOrCreateWindowNodeContainer(node->GetDisplayId()); + sptr container = GetOrCreateWindowNodeContainer(node->GetDisplayId()); if (container == nullptr) { WLOGFE("add window failed, window container could not be found"); return avoidArea; } - avoidArea = container->GetAvoidAreaByType(avoidAreaType, node->GetDisplayId()); - return avoidArea; + return container->GetAvoidAreaByType(node, avoidAreaType); } void WindowRoot::MinimizeAllAppWindows(DisplayId displayId) diff --git a/wmserver/src/zidl/window_manager_proxy.cpp b/wmserver/src/zidl/window_manager_proxy.cpp index fe9b5390..db85b1e8 100644 --- a/wmserver/src/zidl/window_manager_proxy.cpp +++ b/wmserver/src/zidl/window_manager_proxy.cpp @@ -213,14 +213,13 @@ WMError WindowManagerProxy::SetAlpha(uint32_t windowId, float alpha) return static_cast(ret); } -std::vector WindowManagerProxy::GetAvoidAreaByType(uint32_t windowId, AvoidAreaType type) +AvoidArea WindowManagerProxy::GetAvoidAreaByType(uint32_t windowId, AvoidAreaType type) { MessageParcel data; MessageParcel reply; MessageOption option; - const uint32_t maxAvoidNum = 4; - std::vector avoidArea; + AvoidArea avoidArea; if (!data.WriteInterfaceToken(GetDescriptor())) { WLOGFE("WriteInterfaceToken failed"); return avoidArea; @@ -240,27 +239,11 @@ std::vector WindowManagerProxy::GetAvoidAreaByType(uint32_t windowId, Avoi data, reply, option) != ERR_NONE) { return avoidArea; } - - uint32_t avoidNum = reply.ReadUint32(); - if (avoidNum != maxAvoidNum) { - WLOGFE("Read len fail. AvoidArea size != 4"); + sptr area = reply.ReadParcelable(); + if (area == nullptr) { return avoidArea; } - avoidArea.resize(avoidNum); - if (avoidArea.size() < avoidNum) { - WLOGFE("Fail to resize avoidArea."); - return avoidArea; - } - bool readVectorRes = true; - for (uint32_t i = 0; i < avoidNum; ++i) { - readVectorRes = reply.ReadInt32(avoidArea[i].posX_) && reply.ReadInt32(avoidArea[i].posY_) && - reply.ReadUint32(avoidArea[i].width_) && reply.ReadUint32(avoidArea[i].height_); - if (!readVectorRes) { - WLOGFE("Fail to ReadInt32. index:%{public}u, nums:%{public}u", i, avoidNum); - return avoidArea; - } - } - return avoidArea; + return *area; } void WindowManagerProxy::RegisterWindowManagerAgent(WindowManagerAgentType type, @@ -667,5 +650,30 @@ void WindowManagerProxy::MinimizeWindowsByLauncher(std::vector windowI } return; } + +WMError WindowManagerProxy::UpdateAvoidAreaListener(uint32_t windowId, bool haveListener) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("WriteInterfaceToken failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + if (!data.WriteUint32(windowId)) { + WLOGFE("Write windowId failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + if (!data.WriteBool(haveListener)) { + WLOGFE("Write avoid area listener failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + if (Remote()->SendRequest(static_cast(WindowManagerMessage::TRANS_ID_UPDATE_AVOIDAREA_LISTENER), + data, reply, option) != ERR_NONE) { + return WMError::WM_ERROR_IPC_FAILED; + } + return static_cast(reply.ReadInt32()); +} } // namespace Rosen } // namespace OHOS \ No newline at end of file diff --git a/wmserver/src/zidl/window_manager_stub.cpp b/wmserver/src/zidl/window_manager_stub.cpp index b886abae..2ae7c7cf 100644 --- a/wmserver/src/zidl/window_manager_stub.cpp +++ b/wmserver/src/zidl/window_manager_stub.cpp @@ -91,17 +91,9 @@ int32_t WindowManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, M case WindowManagerMessage::TRANS_ID_GET_AVOID_AREA: { uint32_t windowId = data.ReadUint32(); AvoidAreaType avoidAreaType = static_cast(data.ReadUint32()); - std::vector avoidArea = GetAvoidAreaByType(windowId, avoidAreaType); + AvoidArea avoidArea = GetAvoidAreaByType(windowId, avoidAreaType); + reply.WriteParcelable(&avoidArea); - // prepare reply data - uint32_t avoidAreaNum = static_cast(avoidArea.size()); - reply.WriteUint32(avoidAreaNum); - for (auto avoid : avoidArea) { - reply.WriteInt32(avoid.posX_); - reply.WriteInt32(avoid.posY_); - reply.WriteUint32(avoid.width_); - reply.WriteUint32(avoid.height_); - } break; } case WindowManagerMessage::TRANS_ID_REGISTER_WINDOW_MANAGER_AGENT: { @@ -236,6 +228,13 @@ int32_t WindowManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, M } break; } + case WindowManagerMessage::TRANS_ID_UPDATE_AVOIDAREA_LISTENER: { + uint32_t windowId = data.ReadUint32(); + bool haveAvoidAreaListener = data.ReadBool(); + WMError errCode = UpdateAvoidAreaListener(windowId, haveAvoidAreaListener); + reply.WriteInt32(static_cast(errCode)); + break; + } default: WLOGFW("unknown transaction code %{public}d", code); return IPCObjectStub::OnRemoteRequest(code, data, reply, option); From 94b983586a438fd3b8a2509106760ffc5df4d49c Mon Sep 17 00:00:00 2001 From: xiaojianfeng Date: Sat, 25 Jun 2022 17:17:40 +0800 Subject: [PATCH 28/81] fix code style Signed-off-by: xiaojianfeng Change-Id: I70a83035135945f5af011d1b66a2bb581b4a6114 --- interfaces/innerkits/wm/window.h | 2 +- interfaces/innerkits/wm/wm_common.h | 2 +- .../napi/window_runtime/api/@ohos.window.d.ts | 2 +- .../window_napi/js_window_listener.h | 2 +- .../js_window_register_manager.cpp | 16 +- .../window_napi/js_window_utils.cpp | 3 +- wm/src/window_adapter.cpp | 1 - wm/src/window_agent.cpp | 4 +- wm/src/window_impl.cpp | 8 +- wm/test/systemtest/BUILD.gn | 2 +- wm/test/systemtest/window_immersive_test.cpp | 171 ++---------------- .../window_split_immersive_test.cpp | 4 - wmserver/include/avoid_area_controller.h | 4 +- wmserver/include/window_controller.h | 2 +- wmserver/include/window_node_container.h | 2 +- wmserver/include/zidl/window_manager_proxy.h | 1 - wmserver/src/avoid_area_controller.cpp | 54 +++--- wmserver/src/window_controller.cpp | 2 +- wmserver/src/window_manager_service.cpp | 1 - wmserver/src/window_node_container.cpp | 7 +- wmserver/src/window_root.cpp | 2 +- 21 files changed, 66 insertions(+), 226 deletions(-) diff --git a/interfaces/innerkits/wm/window.h b/interfaces/innerkits/wm/window.h index 0a3684b4..c1451688 100644 --- a/interfaces/innerkits/wm/window.h +++ b/interfaces/innerkits/wm/window.h @@ -71,7 +71,7 @@ public: class IAvoidAreaChangedListener : virtual public RefBase { public: - virtual void OnAvoidAreaChanged(const AvoidArea avoidAreas, AvoidAreaType type) = 0; + virtual void OnAvoidAreaChanged(const AvoidArea avoidArea, AvoidAreaType type) = 0; }; class IWindowDragListener : virtual public RefBase { diff --git a/interfaces/innerkits/wm/wm_common.h b/interfaces/innerkits/wm/wm_common.h index 5bcd2ab0..24da28ce 100644 --- a/interfaces/innerkits/wm/wm_common.h +++ b/interfaces/innerkits/wm/wm_common.h @@ -217,7 +217,7 @@ enum class AvoidAreaType : uint32_t { TYPE_SYSTEM, // area of SystemUI TYPE_CUTOUT, // cutout of screen TYPE_SYSTEM_GESTURE, // area for system gesture - TYPE_KEYBOARD, + TYPE_KEYBOARD, // area for soft input keyboard }; enum class OccupiedAreaType : uint32_t { diff --git a/interfaces/kits/napi/window_runtime/api/@ohos.window.d.ts b/interfaces/kits/napi/window_runtime/api/@ohos.window.d.ts index ff8203a6..2ba61c6b 100644 --- a/interfaces/kits/napi/window_runtime/api/@ohos.window.d.ts +++ b/interfaces/kits/napi/window_runtime/api/@ohos.window.d.ts @@ -86,7 +86,7 @@ declare namespace window { TYPE_SYSTEM_GESTURE, /** - * area for keyboard + * area for soft input keyboard * @since 9 */ TYPE_KEYBOARD diff --git a/interfaces/kits/napi/window_runtime/window_napi/js_window_listener.h b/interfaces/kits/napi/window_runtime/window_napi/js_window_listener.h index 56a05f45..8a39f121 100644 --- a/interfaces/kits/napi/window_runtime/window_napi/js_window_listener.h +++ b/interfaces/kits/napi/window_runtime/window_napi/js_window_listener.h @@ -52,7 +52,7 @@ public: void OnSystemBarPropertyChange(DisplayId displayId, const SystemBarRegionTints& tints) override; void OnSizeChange(Rect rect, WindowSizeChangeReason reason) override; void OnModeChange(WindowMode mode) override; - void OnAvoidAreaChanged(const AvoidArea avoidAreas, AvoidAreaType type) override; + void OnAvoidAreaChanged(const AvoidArea avoidArea, AvoidAreaType type) override; void AfterForeground() override; void AfterBackground() override; void AfterFocused() override; diff --git a/interfaces/kits/napi/window_runtime/window_napi/js_window_register_manager.cpp b/interfaces/kits/napi/window_runtime/window_napi/js_window_register_manager.cpp index 633df51c..79a81276 100644 --- a/interfaces/kits/napi/window_runtime/window_napi/js_window_register_manager.cpp +++ b/interfaces/kits/napi/window_runtime/window_napi/js_window_register_manager.cpp @@ -30,12 +30,12 @@ JsWindowRegisterManager::JsWindowRegisterManager() }; // white register list for window listenerProcess_[CaseType::CASE_WINDOW] = { - {WINDOW_SIZE_CHANGE_CB, &JsWindowRegisterManager::ProcessWindowChangeRegister }, - {SYSTEM_AVOID_AREA_CHANGE_CB, &JsWindowRegisterManager::ProcessSystemAvoidAreaChangeRegister }, - {AVOID_AREA_CHANGE_CB, &JsWindowRegisterManager::ProcessAvoidAreaChangeRegister }, - {LIFECYCLE_EVENT_CB, &JsWindowRegisterManager::ProcessLifeCycleEventRegister }, - {KEYBOARD_HEIGHT_CHANGE_CB, &JsWindowRegisterManager::ProcessOccupiedAreaChangeRegister }, - {TOUCH_OUTSIDE_CB, &JsWindowRegisterManager::ProcessTouchOutsideRegister } + { WINDOW_SIZE_CHANGE_CB, &JsWindowRegisterManager::ProcessWindowChangeRegister }, + { SYSTEM_AVOID_AREA_CHANGE_CB, &JsWindowRegisterManager::ProcessSystemAvoidAreaChangeRegister }, + { AVOID_AREA_CHANGE_CB, &JsWindowRegisterManager::ProcessAvoidAreaChangeRegister }, + { LIFECYCLE_EVENT_CB, &JsWindowRegisterManager::ProcessLifeCycleEventRegister }, + { KEYBOARD_HEIGHT_CHANGE_CB, &JsWindowRegisterManager::ProcessOccupiedAreaChangeRegister }, + { TOUCH_OUTSIDE_CB, &JsWindowRegisterManager::ProcessTouchOutsideRegister } }; // white register list for window stage listenerProcess_[CaseType::CASE_STAGE] = { @@ -70,6 +70,10 @@ bool JsWindowRegisterManager::ProcessSystemAvoidAreaChangeRegister(sptrSetIsDeprecatedInterface(true); sptr thisListener(listener); if (isRegister) { diff --git a/interfaces/kits/napi/window_runtime/window_napi/js_window_utils.cpp b/interfaces/kits/napi/window_runtime/window_napi/js_window_utils.cpp index 9e4d09d6..9253f519 100644 --- a/interfaces/kits/napi/window_runtime/window_napi/js_window_utils.cpp +++ b/interfaces/kits/napi/window_runtime/window_napi/js_window_utils.cpp @@ -102,8 +102,7 @@ NativeValue* AvoidAreaTypeInit(NativeEngine* engine) static_cast(AvoidAreaType::TYPE_CUTOUT))); object->SetProperty("TYPE_SYSTEM_GESTURE", CreateJsValue(*engine, static_cast(AvoidAreaType::TYPE_SYSTEM_GESTURE))); - object->SetProperty("TYPE_KEYBOARD", CreateJsValue(*engine, - static_cast(AvoidAreaType::TYPE_KEYBOARD))); + object->SetProperty("TYPE_KEYBOARD", CreateJsValue(*engine, static_cast(AvoidAreaType::TYPE_KEYBOARD))); return objValue; } diff --git a/wm/src/window_adapter.cpp b/wm/src/window_adapter.cpp index c492949c..2d2285a5 100644 --- a/wm/src/window_adapter.cpp +++ b/wm/src/window_adapter.cpp @@ -261,7 +261,6 @@ void WindowAdapter::MinimizeWindowsByLauncher(std::vector windowIds, b WMError WindowAdapter::UpdateAvoidAreaListener(uint32_t windowId, bool haveListener) { INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR); - return windowManagerServiceProxy_->UpdateAvoidAreaListener(windowId, haveListener); } } // namespace Rosen diff --git a/wm/src/window_agent.cpp b/wm/src/window_agent.cpp index 36bf52c8..e99a5966 100644 --- a/wm/src/window_agent.cpp +++ b/wm/src/window_agent.cpp @@ -57,8 +57,8 @@ void WindowAgent::UpdateFocusStatus(bool focused) void WindowAgent::UpdateAvoidArea(const sptr& avoidArea, AvoidAreaType type) { - if (window_ == nullptr) { - WLOGFE("window_ is nullptr"); + if (window_ == nullptr || avoidArea == nullptr) { + WLOGFE("window_ or avoidArea is nullptr."); return; } window_->UpdateAvoidArea(avoidArea, type); diff --git a/wm/src/window_impl.cpp b/wm/src/window_impl.cpp index f95c09a2..7dd3be9a 100644 --- a/wm/src/window_impl.cpp +++ b/wm/src/window_impl.cpp @@ -295,7 +295,6 @@ WMError WindowImpl::GetAvoidAreaByType(AvoidAreaType type, AvoidArea& avoidArea) if (ret != WMError::WM_OK) { WLOGFE("GetAvoidAreaByType errCode:%{public}d winId:%{public}u Type is :%{public}u.", static_cast(ret), property_->GetWindowId(), static_cast(type)); - return ret; } return ret; } @@ -2145,12 +2144,7 @@ void WindowImpl::NotifyAvoidAreaChange(const sptr& avoidArea, AvoidAr std::lock_guard lock(mutex_); avoidAreaChangeListeners = avoidAreaChangeListeners_; } - PostListenerTask([avoidAreaChangeListeners, avoidArea, type]() { - AvoidArea outAvoidArea; - outAvoidArea.topRect_ = avoidArea->topRect_; - outAvoidArea.leftRect_ = avoidArea->leftRect_; - outAvoidArea.rightRect_ = avoidArea->rightRect_; - outAvoidArea.bottomRect_ = avoidArea->bottomRect_; + PostListenerTask([avoidAreaChangeListeners, outAvoidArea = *avoidArea, type]() { for (auto& listener : avoidAreaChangeListeners) { if (listener != nullptr) { listener->OnAvoidAreaChanged(outAvoidArea, type); diff --git a/wm/test/systemtest/BUILD.gn b/wm/test/systemtest/BUILD.gn index 11d52155..f05745d1 100644 --- a/wm/test/systemtest/BUILD.gn +++ b/wm/test/systemtest/BUILD.gn @@ -25,9 +25,9 @@ group("systemtest") { ":wm_window_effect_test", ":wm_window_focus_test", ":wm_window_gamut_test", + ":wm_window_immersive_test", ":wm_window_input_method_test", ":wm_window_input_test", - ":wm_window_layout_test", ":wm_window_mode_support_info_test", ":wm_window_move_drag_test", ":wm_window_multi_ability_test", diff --git a/wm/test/systemtest/window_immersive_test.cpp b/wm/test/systemtest/window_immersive_test.cpp index 6f7191c3..919c00bf 100644 --- a/wm/test/systemtest/window_immersive_test.cpp +++ b/wm/test/systemtest/window_immersive_test.cpp @@ -59,8 +59,8 @@ public: class TestAvoidAreaChangedListener : public IAvoidAreaChangedListener { public: - AvoidArea avoidAreas_; - void OnAvoidAreaChanged(const AvoidArea avoidAreas) override; + AvoidArea avoidArea_; + void OnAvoidAreaChanged(const AvoidArea avoidArea, AvoidAreaType type) override; }; class WindowImmersiveTest : public testing::Test { @@ -97,7 +97,7 @@ sptr WindowImmersiveTest::testAvoidAreaChangedList void WindowImmersiveTest::SetWindowSystemProps(const sptr& window, const SystemBarRegionTints& tints) { for (auto tint : tints) { - window->SetSystemBarProperty(tint.type_, tint.propWindowImmersiveTest _); + window->SetSystemBarProperty(tint.type_, tint.prop_); } } @@ -106,16 +106,15 @@ void WindowImmersiveTest::DumpFailedInfo(const SystemBarRegionTints& expect) auto act = testSystemBarChangedListener_->tints_; WLOGFI("WindowImmersiveTest Expected:"); for (auto tint : expect) { - WLOGFI("WindowType: %{public}4d, Enable: %{public}4d, Color: %{public}x | %{public}x", - static_cast(tint.type_), tint.prop_.enable_, - tint.prop_.backgroundColor_, tint.prop_.contentColor_); + WLOGFI("WindowType: %{public}4d, Enable: %{public}4d, Color: %{public}x | %{public}x", + static_cast(tint.type_), tint.prop_.enable_, + tint.prop_.backgroundColor_, tint.prop_.contentColor_); } WLOGFI("WindowImmersiveTest Act: "); - for (auto tint : act) { - WLOGFI("WindowType: %{public}4d, Enable: %{public}4d, Color: %{public}x | %{public}x", - static_cast(tint.type_), tint.prop_.enable_, - tint.prop_.backgroundColor_, tint.prop_.contentColor_); + WLOGFI("WindowType: %{public}4d, Enable: %{public}4d, Color: %{public}x | %{public}x", + static_cast(tint.type_), tint.prop_.enable_, + tint.prop_.backgroundColor_, tint.prop_.contentColor_); } } @@ -189,9 +188,9 @@ void TestSystemBarChangedListener::OnSystemBarPropertyChange(DisplayId displayId } } -void TestAvoidAreaChangedListener::OnAvoidAreaChanged(AvoidArea avoidAreas) +void TestAvoidAreaChangedListener::OnAvoidAreaChanged(const AvoidArea avoidArea, AvoidAreaType type) { - avoidAreas_ = avoidAreas; + avoidArea_ = avoidArea; } void WindowImmersiveTest::SetUpTestCase() @@ -394,154 +393,6 @@ HWTEST_F(WindowImmersiveTest, GetAvoidAreaByTypeTest01, Function | MediumTest | ASSERT_EQ(WMError::WM_OK, win->Hide()); } -/** - * @tc.name: GetAvoidAreaByTypeTest02 - * @tc.desc: Add SystemBar left avoid. And Test GetAvoidArea. - * @tc.type: FUNC - */ -HWTEST_F(WindowImmersiveTest, GetAvoidAreaByTypeTest02, Function | MediumTest | Level3) -{ - // Add full screenwindow for call GetAvoidArea, and push_back in activeWindows_ - const sptr& win = utils::CreateTestWindow(fullScreenAppinfo_); - activeWindows_.push_back(win); - ASSERT_EQ(WMError::WM_OK, win->Show()); - WLOGFI("win.posY_=%{public}d", win->GetRect().posY_); - - // Add a unexist leftAvoid - avoidBarInfo_.rect = {0, 0, leftAvoidW_, leftAvoidH_}; - const sptr& left = utils::CreateTestWindow(avoidBarInfo_); - activeWindows_.push_back(left); - WLOGFI("win.posY_=%{public}d", win->GetRect().posY_); - ASSERT_EQ(WMError::WM_OK, left->Show()); - ASSERT_EQ(WMError::WM_OK, left->Resize(leftAvoidW_, leftAvoidH_)); - - - // Test GetAvoidArea - AvoidArea avoidarea; - WMError ret = win->GetAvoidAreaByType(AvoidAreaType::TYPE_SYSTEM, avoidarea); - WLOGFI("ret = [%{public}u, avoidArea: top[%{public}d, %{public}d, %{public}u, %{public}u], left[%{public}d, %{public}d, %{public}u, %{public}u], " \ - "right[%{public}d, %{public}d, %{public}u, %{public}u], bottom[%{public}d, %{public}d, %{public}u, %{public}u]", ret, - avoidarea.topRect_.posX_, avoidarea.topRect_.posY_, avoidarea.topRect_.width_, avoidarea.topRect_.height_, - avoidarea.leftRect_.posX_, avoidarea.leftRect_.posY_, avoidarea.leftRect_.width_, avoidarea.leftRect_.height_, - avoidarea.rightRect_.posX_, avoidarea.rightRect_.posY_, avoidarea.rightRect_.width_, avoidarea.rightRect_.height_, - avoidarea.bottomRect_.posX_, avoidarea.bottomRect_.posY_, avoidarea.bottomRect_.width_, avoidarea.bottomRect_.height_); - ASSERT_EQ(WMError::WM_OK, ret); - ASSERT_TRUE(utils::RectEqualTo(left, avoidarea.leftRect_)); - ASSERT_EQ(WMError::WM_OK, left->Hide()); - ASSERT_EQ(WMError::WM_OK, win->Hide()); -} - -/** - * @tc.name: GetAvoidAreaByTypeTest03 - * @tc.desc: Add SystemBar top avoid. And Test GetAvoidArea. - * @tc.type: FUNC - */ -HWTEST_F(WindowImmersiveTest, GetAvoidAreaByTypeTest03, Function | MediumTest | Level3) -{ - // Add full screenwindow for call GetAvoidArea, and push_back in activeWindows_ - const sptr& win = utils::CreateTestWindow(fullScreenAppinfo_); - activeWindows_.push_back(win); - - // Add a unexist topAvoid - avoidBarInfo_.name = "TopAvoidTest"; - avoidBarInfo_.rect = {0, 0, topAvoidW_, topAvoidH_}; - const sptr& top = utils::CreateTestWindow(avoidBarInfo_); - activeWindows_.push_back(top); - ASSERT_EQ(WMError::WM_OK, top->Show()); - ASSERT_EQ(WMError::WM_OK, top->Resize(topAvoidW_, topAvoidH_)); - - // Tesr GetAvoidArea - AvoidArea avoidarea; - WMError ret = win->GetAvoidAreaByType(AvoidAreaType::TYPE_SYSTEM, avoidarea); - ASSERT_EQ(WMError::WM_OK, ret); - ASSERT_TRUE(utils::RectEqualTo(top, avoidarea.topRect)); - ASSERT_EQ(WMError::WM_OK, top->Hide()); - ASSERT_EQ(WMError::WM_OK, win->Hide()); -} - -/** - * @tc.name: OnAvoidAreaChangedTest01 - * @tc.desc: Add unexistavoid and Update this avoid. Test OnAvoidAreaChanged listener - * @tc.type: FUNC - */ -HWTEST_F(WindowImmersiveTest, OnAvoidAreaChangedTest01, Function | MediumTest | Level3) -{ - // Add full screenwindow for RegisterAvoidAreaChangeListener - const sptr& window = utils::CreateTestWindow(fullScreenAppinfo_); - sptr thisListener(testAvoidAreaChangedListener_); - window->RegisterAvoidAreaChangeListener(thisListener); - activeWindows_.push_back(window); - ASSERT_EQ(WMError::WM_OK, window->Show()); - - // Add a unexist topAvoid - avoidBarInfo_.name = "TopAvoidTest"; - avoidBarInfo_.rect = {0, 0, topAvoidW_, topAvoidH_}; - const sptr& top = utils::CreateTestWindow(avoidBarInfo_); - activeWindows_.push_back(top); - ASSERT_EQ(WMError::WM_OK, top->Show()); - ASSERT_EQ(WMError::WM_OK, top->Resize(topAvoidW_, topAvoidH_)); - - // Await 100ms and get callback result in listener. Compare current avoidArea - usleep(WAIT_ASYNC_US); - std::vector avoidArea = testAvoidAreaChangedListener_->avoidAreas_; - ASSERT_EQ(4u, static_cast(avoidArea.size())); // 4: avoidAreaNum(left, top, right, bottom) - ASSERT_TRUE(utils::RectEqualToRect(avoidBarInfo_.rect, avoidArea[1])); // 1: left Rect - - // Update topavoid. Enlarge topAvoidH_ - uint32_t bigHeight = std::min(static_cast(utils::displayRect_.height_), - static_cast(utils::displayRect_.width_ * 0.5)); // 0.5 : just use bigger height for update - Rect bigTopRect = {0, 0, topAvoidW_, bigHeight}; - ASSERT_EQ(WMError::WM_OK, top->Resize(topAvoidW_, bigHeight)); - - // Await 100ms and get callback result in listener. Compare current avoidArea - usleep(WAIT_ASYNC_US); - std::vector avoidArea2 = testAvoidAreaChangedListener_->avoidAreas_; - ASSERT_TRUE(utils::RectEqualToRect(bigTopRect, avoidArea2[1])); - - window->UnregisterAvoidAreaChangeListener(thisListener); - ASSERT_EQ(WMError::WM_OK, top->Hide()); - ASSERT_EQ(WMError::WM_OK, window->Hide()); -} - -/** - * @tc.name: OnAvoidAreaChangedTest02 - * @tc.desc: Add unexistavoid and remove this avoid. Test OnAvoidAreaChanged listener - * @tc.type: FUNC - */ -HWTEST_F(WindowImmersiveTest, OnAvoidAreaChangedTest02, Function | MediumTest | Level3) -{ - // Add full screenwindow for call UpdateAvoidChange - const sptr& window = utils::CreateTestWindow(fullScreenAppinfo_); - sptr thisListener(testAvoidAreaChangedListener_); - window->RegisterAvoidAreaChangeListener(thisListener); - activeWindows_.push_back(window); - ASSERT_EQ(WMError::WM_OK, window->Show()); - - // Add a unexist leftAvoid - avoidBarInfo_.rect = {0, 0, leftAvoidW_, leftAvoidH_}; - const sptr& left = utils::CreateTestWindow(avoidBarInfo_); - activeWindows_.push_back(left); - ASSERT_EQ(WMError::WM_OK, left->Show()); - ASSERT_EQ(WMError::WM_OK, left->Resize(leftAvoidW_, leftAvoidH_)); - - // Await 100ms and get callback result in listener. Compare current avoidArea - usleep(WAIT_ASYNC_US); - std::vector avoidArea = testAvoidAreaChangedListener_->avoidAreas_; - ASSERT_EQ(4u, static_cast(avoidArea.size())); // 4: avoidAreaNum(left, top, right, bottom) - ASSERT_TRUE(utils::RectEqualToRect(avoidBarInfo_.rect, avoidArea[0])); // 0: left Rect - - // Remove left avoid. - ASSERT_EQ(WMError::WM_OK, left->Hide()); - - // Await 100ms and get callback result in listener. Compare current avoidArea - usleep(WAIT_ASYNC_US); - std::vector avoidArea2 = testAvoidAreaChangedListener_->avoidAreas_; - ASSERT_TRUE(utils::RectEqualToRect(EMPTY_RECT, avoidArea2[0])); // 0: left Rect - - window->UnregisterAvoidAreaChangeListener(thisListener); - ASSERT_EQ(WMError::WM_OK, window->Hide()); -} - /** * @tc.name: DockWindowTest01 * @tc.desc: Add unexistavoid and remove this avoid. Test OnAvoidAreaChanged listener diff --git a/wm/test/systemtest/window_split_immersive_test.cpp b/wm/test/systemtest/window_split_immersive_test.cpp index afeb680e..61b305f8 100644 --- a/wm/test/systemtest/window_split_immersive_test.cpp +++ b/wm/test/systemtest/window_split_immersive_test.cpp @@ -118,10 +118,6 @@ HWTEST_F(WindowSplitImmersiveTest, SplitImmersive01, Function | MediumTest | Lev // check is out split Immersive ASSERT_EQ(WindowMode::WINDOW_MODE_FULLSCREEN, fullWindow->GetMode()); - Rect curFullScreenRect = fullWindow->GetRect(); - AvoidArea avoidArea; - fullWindow->GetAvoidAreaByType(AvoidAreaType::TYPE_SYSTEM, avoidArea); - ASSERT_EQ(avoidArea.topRect_.height_, curFullScreenRect.posY_); ASSERT_EQ(WMError::WM_OK, fullWindow->Hide()); sleep(SPLIT_TEST_SLEEP_S); diff --git a/wmserver/include/avoid_area_controller.h b/wmserver/include/avoid_area_controller.h index 9b6cd6ff..82af2268 100644 --- a/wmserver/include/avoid_area_controller.h +++ b/wmserver/include/avoid_area_controller.h @@ -55,7 +55,7 @@ private: AvoidPosType CalculateOverlayRect(const sptr& node, const sptr& overlayNode, Rect& overlayRect) const; AvoidPosType GetAvoidPosType(const Rect& windowRect, const Rect& overlayRect) const; - void SetAvoidAreaRect(AvoidArea& avoidArea, Rect& rect, AvoidPosType type) const; + void SetAvoidAreaRect(AvoidArea& avoidArea, const Rect& rect, AvoidPosType type) const; bool UpdateAvoidAreaIfNeed(const AvoidArea& avoidArea, const sptr& node, AvoidAreaType avoidAreaType); AvoidArea GetAvoidAreaSystemType(const sptr& node) const; AvoidArea GetAvoidAreaKeyboardType(const sptr& node) const; @@ -64,8 +64,8 @@ private: std::unordered_map> overlayWindowMap_; std::set> avoidAreaListenerNodes_; std::map> lastUpdatedAvoidArea_; - DEFINE_VAR_DEFAULT_FUNC_SET(bool, FlagForProcessWindowChange, isForbidProcessingWindowChange, false) uint32_t lastSoftInputKeyboardAreaUpdatedWindowId_ { 0 }; + DEFINE_VAR_DEFAULT_FUNC_SET(bool, FlagForProcessWindowChange, isForbidProcessingWindowChange, false) }; } } diff --git a/wmserver/include/window_controller.h b/wmserver/include/window_controller.h index ca602bfb..66971809 100644 --- a/wmserver/include/window_controller.h +++ b/wmserver/include/window_controller.h @@ -43,7 +43,7 @@ public: WMError RequestFocus(uint32_t windowId); WMError SetWindowBackgroundBlur(uint32_t windowId, WindowBlurLevel level); WMError SetAlpha(uint32_t windowId, float alpha); - AvoidArea GetAvoidAreaByType(uint32_t windowId, AvoidAreaType avoidAreaType); + AvoidArea GetAvoidAreaByType(uint32_t windowId, AvoidAreaType avoidAreaType) const; WMError GetTopWindowId(uint32_t mainWinId, uint32_t& topWinId); void NotifyDisplayStateChange(DisplayId defaultDisplayId, sptr displayInfo, const std::map>& displayInfoMap, DisplayStateChangeType type); diff --git a/wmserver/include/window_node_container.h b/wmserver/include/window_node_container.h index faea28a7..6803edeb 100644 --- a/wmserver/include/window_node_container.h +++ b/wmserver/include/window_node_container.h @@ -56,7 +56,7 @@ public: uint32_t ToOverrideBrightness(float brightness); void UpdateBrightness(uint32_t id, bool byRemoved); void HandleKeepScreenOn(const sptr& node, bool requireLock); - AvoidArea GetAvoidAreaByType(const sptr& node, AvoidAreaType avoidAreaType); + AvoidArea GetAvoidAreaByType(const sptr& node, AvoidAreaType avoidAreaType) const; WMError MinimizeStructuredAppWindowsExceptSelf(const sptr& node); void TraverseContainer(std::vector>& windowNodes) const; uint64_t GetScreenId(DisplayId displayId) const; diff --git a/wmserver/include/zidl/window_manager_proxy.h b/wmserver/include/zidl/window_manager_proxy.h index fc358929..4d58628b 100644 --- a/wmserver/include/zidl/window_manager_proxy.h +++ b/wmserver/include/zidl/window_manager_proxy.h @@ -59,7 +59,6 @@ public: void MinimizeWindowsByLauncher(std::vector windowIds, bool isAnimated, sptr& finishCallback) override; WMError UpdateAvoidAreaListener(uint32_t windowId, bool haveListener) override; - private: static inline BrokerDelegator delegator_; }; diff --git a/wmserver/src/avoid_area_controller.cpp b/wmserver/src/avoid_area_controller.cpp index 6f5a1322..a173696c 100644 --- a/wmserver/src/avoid_area_controller.cpp +++ b/wmserver/src/avoid_area_controller.cpp @@ -75,11 +75,10 @@ void AvoidAreaController::AddOrRemoveOverlayWindowIfNeed(const sptr& uint32_t overlayId = overlayNode->GetWindowId(); bool isRecorded = (overlayWindowMap_.find(overlayId) != overlayWindowMap_.end()); if (isAdding == isRecorded) { - WLOGE("error occured in overlay. overlayId %{public}u isAdding %{public}d record flag %{public}d", + WLOGFE("error occured in overlay. overlayId %{public}u isAdding %{public}d record flag %{public}d", overlayId, isAdding, isRecorded); return; } - WLOGFE("overlayId %{public}u isAdding %{public}d record flag %{public}d", overlayId, isAdding, isRecorded); if (isAdding) { overlayWindowMap_.insert(std::make_pair(overlayId, overlayNode)); } else { @@ -102,34 +101,36 @@ void AvoidAreaController::AddOrRemoveKeyboard(const sptr& keyboardNo const uint32_t callingWindowId = keyboardNode->GetCallingWindow(); sptr callingWindow = nullptr; sptr focusWindow = nullptr; - sptr lastSoftInputKeyboardAreaUpdatedWindow = nullptr; + sptr lastKeyboardAreaUpdatedWindow = nullptr; for (auto window : avoidAreaListenerNodes_) { - if (window != nullptr && window->GetWindowToken() != nullptr && window->GetWindowId() == callingWindowId) { + if (window == nullptr || window->GetWindowToken() == nullptr) { + continue; + } + if (window->GetWindowId() == callingWindowId) { callingWindow = window; } - if (window != nullptr && window->GetWindowToken() != nullptr && window->GetWindowId() == focusedWindow_) { + if (window->GetWindowId() == focusedWindow_) { focusWindow = window; } - if (window != nullptr && window->GetWindowToken() != nullptr && - window->GetWindowId() == lastSoftInputKeyboardAreaUpdatedWindowId_) { - lastSoftInputKeyboardAreaUpdatedWindow = window; + if (window->GetWindowId() == lastSoftInputKeyboardAreaUpdatedWindowId_) { + lastKeyboardAreaUpdatedWindow = window; } } if (callingWindow == nullptr) { callingWindow = focusWindow; } - if (lastSoftInputKeyboardAreaUpdatedWindow != nullptr && lastSoftInputKeyboardAreaUpdatedWindow != callingWindow) { - const WindowMode windowMode = lastSoftInputKeyboardAreaUpdatedWindow->GetWindowMode(); + if (lastKeyboardAreaUpdatedWindow != nullptr && lastKeyboardAreaUpdatedWindow != callingWindow) { + const WindowMode windowMode = lastKeyboardAreaUpdatedWindow->GetWindowMode(); if (windowMode == WindowMode::WINDOW_MODE_FULLSCREEN || windowMode == WindowMode::WINDOW_MODE_SPLIT_PRIMARY || windowMode == WindowMode::WINDOW_MODE_SPLIT_SECONDARY || windowMode == WindowMode::WINDOW_MODE_FLOATING) { - auto avoidArea = GetAvoidAreaByType(lastSoftInputKeyboardAreaUpdatedWindow, AvoidAreaType::TYPE_KEYBOARD); - UpdateAvoidAreaIfNeed(avoidArea, lastSoftInputKeyboardAreaUpdatedWindow, AvoidAreaType::TYPE_KEYBOARD); + auto avoidArea = GetAvoidAreaByType(lastKeyboardAreaUpdatedWindow, AvoidAreaType::TYPE_KEYBOARD); + UpdateAvoidAreaIfNeed(avoidArea, lastKeyboardAreaUpdatedWindow, AvoidAreaType::TYPE_KEYBOARD); } } - if (callingWindow == nullptr && focusWindow == nullptr) { - WLOGFI("callingWindow: %{public}u is nullptr, focusWindow: %{public}u is nullptr.", + if (callingWindow == nullptr) { + WLOGFE("callingWindow: %{public}u is nullptr, focusWindow: %{public}u is nullptr.", callingWindowId, focusedWindow_); return; } @@ -168,15 +169,14 @@ void AvoidAreaController::UpdateOverlayWindowIfNeed(const sptr& node WLOGE("window: %{public}u is not in avoidAreaListenerNodes, don't update avoid area.", node->GetWindowId()); return; } - AvoidArea systemAvoidArea = GetAvoidAreaByType(node, AvoidAreaType::TYPE_SYSTEM); - AvoidArea cutoutAvoidArea = GetAvoidAreaByType(node, AvoidAreaType::TYPE_CUTOUT); - AvoidArea gestureAvoidArea = GetAvoidAreaByType(node, AvoidAreaType::TYPE_SYSTEM_GESTURE); - AvoidArea keyboardAvoidArea = GetAvoidAreaByType(node, AvoidAreaType::TYPE_KEYBOARD); - UpdateAvoidAreaIfNeed(systemAvoidArea, node, AvoidAreaType::TYPE_SYSTEM); - UpdateAvoidAreaIfNeed(cutoutAvoidArea, node, AvoidAreaType::TYPE_CUTOUT); - UpdateAvoidAreaIfNeed(gestureAvoidArea, node, AvoidAreaType::TYPE_SYSTEM_GESTURE); - if (UpdateAvoidAreaIfNeed(keyboardAvoidArea, node, AvoidAreaType::TYPE_KEYBOARD)) { - lastSoftInputKeyboardAreaUpdatedWindowId_ = node->GetWindowId(); + uint32_t start = static_cast(AvoidAreaType::TYPE_SYSTEM); + uint32_t end = static_cast(AvoidAreaType::TYPE_KEYBOARD); + for (int type = start; type <= end; type++) { + AvoidArea systemAvoidArea = GetAvoidAreaByType(node, static_cast(type)); + bool res = UpdateAvoidAreaIfNeed(systemAvoidArea, node, static_cast(type)); + if (res && type == static_cast(AvoidAreaType::TYPE_KEYBOARD)) { + lastSoftInputKeyboardAreaUpdatedWindowId_ = node->GetWindowId(); + } } } } @@ -241,7 +241,7 @@ AvoidPosType AvoidAreaController::GetAvoidPosType(const Rect& windowRect, const return AvoidPosType::AVOID_POS_BOTTOM; } -void AvoidAreaController::SetAvoidAreaRect(AvoidArea& avoidArea, Rect& rect, AvoidPosType type) const +void AvoidAreaController::SetAvoidAreaRect(AvoidArea& avoidArea, const Rect& rect, AvoidPosType type) const { switch (type) { case AvoidPosType::AVOID_POS_TOP : { @@ -335,10 +335,9 @@ AvoidArea AvoidAreaController::GetAvoidAreaSystemType(const sptr& no AvoidArea AvoidAreaController::GetAvoidAreaKeyboardType(const sptr& node) const { - AvoidArea avoidArea; if (focusedWindow_ != node->GetWindowId()) { WLOGFI("focusedWindow: %{public}u is not windowId: %{public}u", focusedWindow_, node->GetWindowId()); - return avoidArea; + return {}; } for (auto& iter : overlayWindowMap_) { if (iter.second != nullptr && @@ -351,11 +350,12 @@ AvoidArea AvoidAreaController::GetAvoidAreaKeyboardType(const sptr& } Rect avoidAreaRect; AvoidPosType avoidPosType = CalculateOverlayRect(node, iter.second, avoidAreaRect); + AvoidArea avoidArea; SetAvoidAreaRect(avoidArea, avoidAreaRect, avoidPosType); return avoidArea; } } - return avoidArea; + return {}; } } } diff --git a/wmserver/src/window_controller.cpp b/wmserver/src/window_controller.cpp index d6ab58c7..580d8326 100644 --- a/wmserver/src/window_controller.cpp +++ b/wmserver/src/window_controller.cpp @@ -616,7 +616,7 @@ WMError WindowController::SetWindowAnimationController(const sptrGetAvoidAreaByType(windowId, avoidAreaType); } diff --git a/wmserver/src/window_manager_service.cpp b/wmserver/src/window_manager_service.cpp index d14f68ba..89d51ef9 100644 --- a/wmserver/src/window_manager_service.cpp +++ b/wmserver/src/window_manager_service.cpp @@ -669,7 +669,6 @@ void WindowManagerService::GetFullScreenWindowRequestedOrientation(DisplayId dis WMError WindowManagerService::UpdateAvoidAreaListener(uint32_t windowId, bool haveAvoidAreaListener) { return wmsTaskLooper_->ScheduleTask([this, windowId, haveAvoidAreaListener]() { - WM_SCOPED_TRACE("wms:UpdateAvoidAreaListener"); sptr node = windowRoot_->GetWindowNode(windowId); if (node == nullptr) { WLOGFE("get window node failed. win %{public}u", windowId); diff --git a/wmserver/src/window_node_container.cpp b/wmserver/src/window_node_container.cpp index 942fa200..a2e77c39 100644 --- a/wmserver/src/window_node_container.cpp +++ b/wmserver/src/window_node_container.cpp @@ -224,7 +224,6 @@ WMError WindowNodeContainer::UpdateWindowNode(sptr& node, WindowUpda if (WindowHelper::IsMainWindow(node->GetWindowType()) && WindowHelper::IsSwitchCascadeReason(reason)) { SwitchLayoutPolicy(WindowLayoutMode::CASCADE, node->GetDisplayId()); } - WLOGFI("UpdateWindowNode windowId: %{public}u begin", node->GetWindowId()); layoutPolicy_->UpdateWindowNode(node); NotifyIfAvoidAreaChanged(node, AvoidControlType::AVOID_NODE_UPDATE); DumpScreenWindowTree(); @@ -862,8 +861,8 @@ void WindowNodeContainer::NotifyIfKeyboardRegionChanged(const sptr& WLOGFI("keyboard size change callingWindow: [%{public}s, %{public}u], " \ "overlap rect: [%{public}d, %{public}d, %{public}u, %{public}u]", - callingWindow->GetWindowName().c_str(), callingWindow->GetWindowId(), - overlapRect.posX_, overlapRect.posY_, overlapRect.width_, overlapRect.height_); + callingWindow->GetWindowName().c_str(), callingWindow->GetWindowId(), + overlapRect.posX_, overlapRect.posY_, overlapRect.width_, overlapRect.height_); sptr info = new OccupiedAreaChangeInfo(OccupiedAreaType::TYPE_INPUT, overlapRect); callingWindow->GetWindowToken()->UpdateOccupiedAreaChangeInfo(info); return; @@ -1082,7 +1081,7 @@ void WindowNodeContainer::TraverseWindowNode(sptr& node, std::vector } } -AvoidArea WindowNodeContainer::GetAvoidAreaByType(const sptr& node, AvoidAreaType avoidAreaType) +AvoidArea WindowNodeContainer::GetAvoidAreaByType(const sptr& node, AvoidAreaType avoidAreaType) const { if (CheckWindowNodeWhetherInWindowTree(node)) { return avoidController_->GetAvoidAreaByType(node, avoidAreaType); diff --git a/wmserver/src/window_root.cpp b/wmserver/src/window_root.cpp index e6bc12f6..59b64bac 100644 --- a/wmserver/src/window_root.cpp +++ b/wmserver/src/window_root.cpp @@ -72,7 +72,7 @@ sptr WindowRoot::GetOrCreateWindowNodeContainer(DisplayId d } // In case of have no container for default display, create container - WLOGFE("Create container for current display, displayId: %{public}" PRIu64 "", displayId); + WLOGFI("Create container for current display, displayId: %{public}" PRIu64 "", displayId); sptr displayInfo = DisplayManagerServiceInner::GetInstance().GetDisplayById(displayId); return CreateWindowNodeContainer(displayInfo); } From 436a25c9486bca3700244e87cf27a0a0c343dbfd Mon Sep 17 00:00:00 2001 From: xpeng Date: Mon, 27 Jun 2022 10:28:37 +0800 Subject: [PATCH 29/81] fix some problems Signed-off-by: xpeng Change-Id: I0a144b518d2cea11b04a8222c2c63a34622d4c03 --- wm/src/window_impl.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/wm/src/window_impl.cpp b/wm/src/window_impl.cpp index a5f1c69d..c2b1ac61 100644 --- a/wm/src/window_impl.cpp +++ b/wm/src/window_impl.cpp @@ -690,8 +690,8 @@ WMError WindowImpl::Create(const std::string& parentName, const std::shared_ptr< } WLOGFI("get stretchable enable:%{public}d", windowSystemConfig_.isStretchable_); property_->SetStretchable(windowSystemConfig_.isStretchable_); - SetOrientationFromAbility(); } + SetOrientationFromAbility(); } WMError ret = SingletonContainer::Get().CreateWindow(windowAgent, property_, surfaceNode_, windowId, token); @@ -1216,8 +1216,17 @@ void WindowImpl::SetOrientationFromAbility() return; } auto abilityInfo = abilityContext->GetAbilityInfo(); - Orientation orientation = ABILITY_TO_WMS_ORIENTATION_MAP.at(static_cast( - static_cast(abilityInfo->orientation))); + if (abilityInfo == nullptr) { + WLOGFE("id:%{public}d Ability window get ability info failed", property_->GetWindowId()); + return; + } + DisplayOrientation displayOrientation = static_cast( + static_cast(abilityInfo->orientation)); + if (ABILITY_TO_WMS_ORIENTATION_MAP.count(displayOrientation) == 0) { + WLOGFE("id:%{public}d Do not support this Orientation type", property_->GetWindowId()); + return; + } + Orientation orientation = ABILITY_TO_WMS_ORIENTATION_MAP.at(displayOrientation); if (orientation < Orientation::BEGIN || orientation > Orientation::END) { WLOGFE("Set orientation from ability failed"); return; From 2b31a4a92924a8e34c5692bdf520bc3bb47618e9 Mon Sep 17 00:00:00 2001 From: qianlf Date: Fri, 24 Jun 2022 19:09:30 +0800 Subject: [PATCH 30/81] git customization config path Signed-off-by: qianlf Change-Id: Ic33b5e3810c919dfc007f3253e7256c2a34e6792 --- dmserver/BUILD.gn | 1 + dmserver/include/display_manager_config.h | 3 ++- dmserver/include/display_manager_service.h | 3 --- dmserver/src/display_manager_config.cpp | 16 +++++++++++++++- dmserver/src/display_manager_service.cpp | 2 +- utils/include/wm_common_inner.h | 1 - wmserver/BUILD.gn | 1 + wmserver/include/window_manager_config.h | 3 ++- wmserver/src/window_manager_config.cpp | 17 ++++++++++++++++- wmserver/src/window_manager_service.cpp | 2 +- 10 files changed, 39 insertions(+), 10 deletions(-) diff --git a/dmserver/BUILD.gn b/dmserver/BUILD.gn index 7fed1e77..f9090b1f 100644 --- a/dmserver/BUILD.gn +++ b/dmserver/BUILD.gn @@ -57,6 +57,7 @@ ohos_shared_library("libdms") { external_deps = [ "access_token:libaccesstoken_sdk", + "config_policy:configpolicy_util", "graphic_standard:surface", "hilog_native:libhilog", "hitrace_native:hitrace_meter", diff --git a/dmserver/include/display_manager_config.h b/dmserver/include/display_manager_config.h index 55217c0e..f4615321 100644 --- a/dmserver/include/display_manager_config.h +++ b/dmserver/include/display_manager_config.h @@ -30,7 +30,7 @@ public: DisplayManagerConfig() = delete; ~DisplayManagerConfig() = default; - static bool LoadConfigXml(const std::string& configFilePath); + static bool LoadConfigXml(); static const std::map>& GetIntNumbersConfig(); static void DumpConfig(); @@ -39,6 +39,7 @@ private: static bool IsValidNode(const xmlNode& currNode); static void ReadIntNumbersConfigInfo(const xmlNodePtr& currNode); + static std::string GetConfigPath(const std::string& configFileName); static std::vector Split(std::string str, std::string pattern); static inline bool IsNumber(std::string str); diff --git a/dmserver/include/display_manager_service.h b/dmserver/include/display_manager_service.h index ac5fb515..430a002c 100644 --- a/dmserver/include/display_manager_service.h +++ b/dmserver/include/display_manager_service.h @@ -35,9 +35,6 @@ #include "singleton_delegator.h" namespace OHOS::Rosen { -namespace { - const std::string DISPLAY_MANAGER_CONFIG_XML = "/system/etc/window/resources/display_manager_config.xml"; -} class DisplayManagerService : public SystemAbility, public DisplayManagerStub { DECLARE_SYSTEM_ABILITY(DisplayManagerService); WM_DECLARE_SINGLE_INSTANCE_BASE(DisplayManagerService); diff --git a/dmserver/src/display_manager_config.cpp b/dmserver/src/display_manager_config.cpp index aab37b96..e54ad249 100644 --- a/dmserver/src/display_manager_config.cpp +++ b/dmserver/src/display_manager_config.cpp @@ -14,6 +14,7 @@ */ #include "display_manager_config.h" +#include "config_policy_utils.h" #include "window_manager_hilog.h" namespace OHOS { @@ -51,8 +52,21 @@ bool inline DisplayManagerConfig::IsNumber(std::string str) return true; } -bool DisplayManagerConfig::LoadConfigXml(const std::string& configFilePath) +std::string DisplayManagerConfig::GetConfigPath(const std::string& configFileName) { + char buf[PATH_MAX + 1]; + char* configPath = GetOneCfgFile(configFileName.c_str(), buf, PATH_MAX + 1); + char tmpPath[PATH_MAX + 1] = { 0 }; + if (!configPath || strlen(configPath) == 0 || strlen(configPath) > PATH_MAX || !realpath(configPath, tmpPath)) { + WLOGFI("[DmConfig] can not get customization config file"); + return "/system/" + configFileName; + } + return std::string(tmpPath); +} + +bool DisplayManagerConfig::LoadConfigXml() +{ + auto configFilePath = GetConfigPath("etc/window/resources/display_manager_config.xml"); xmlDocPtr docPtr = xmlReadFile(configFilePath.c_str(), nullptr, XML_PARSE_NOBLANKS); WLOGFI("[DmConfig] filePath: %{public}s", configFilePath.c_str()); if (docPtr == nullptr) { diff --git a/dmserver/src/display_manager_service.cpp b/dmserver/src/display_manager_service.cpp index 85e35de8..d96c7b09 100644 --- a/dmserver/src/display_manager_service.cpp +++ b/dmserver/src/display_manager_service.cpp @@ -84,7 +84,7 @@ bool DisplayManagerService::Init() WLOGFW("DisplayManagerService::Init failed"); return false; } - if (DisplayManagerConfig::LoadConfigXml(DISPLAY_MANAGER_CONFIG_XML)) { + if (DisplayManagerConfig::LoadConfigXml()) { DisplayManagerConfig::DumpConfig(); ConfigureDisplayManagerService(); } diff --git a/utils/include/wm_common_inner.h b/utils/include/wm_common_inner.h index 340f3932..2e95688c 100644 --- a/utils/include/wm_common_inner.h +++ b/utils/include/wm_common_inner.h @@ -145,7 +145,6 @@ namespace { constexpr uint32_t MIN_VERTICAL_SPLIT_HEIGHT = 240; constexpr uint32_t MIN_HORIZONTAL_SPLIT_WIDTH = 320; constexpr uint32_t MAX_FLOATING_SIZE = 2560; - const std::string WINDOW_MANAGER_CONFIG_XML = "/system/etc/window/resources/window_manager_config.xml"; const Rect INVALID_EMPTY_RECT = {0, 0, 0, 0}; } } diff --git a/wmserver/BUILD.gn b/wmserver/BUILD.gn index 2d35a997..8d29a140 100644 --- a/wmserver/BUILD.gn +++ b/wmserver/BUILD.gn @@ -91,6 +91,7 @@ ohos_shared_library("libwms") { "ability_base:want", "ability_runtime:ability_manager", "common_event_service:cesfwk_innerkits", + "config_policy:configpolicy_util", "display_manager_native:displaymgr", "graphic_standard:surface", "graphic_standard:window_animation", diff --git a/wmserver/include/window_manager_config.h b/wmserver/include/window_manager_config.h index 52604ff5..02cec8d1 100644 --- a/wmserver/include/window_manager_config.h +++ b/wmserver/include/window_manager_config.h @@ -31,7 +31,7 @@ public: WindowManagerConfig() = delete; ~WindowManagerConfig() = default; - static bool LoadConfigXml(const std::string& configFilePath); + static bool LoadConfigXml(); static const std::map& GetEnableConfig(); static const std::map>& GetIntNumbersConfig(); static const std::map>& GetFloatNumbersConfig(); @@ -46,6 +46,7 @@ private: static void ReadEnableConfigInfo(const xmlNodePtr& currNode); static void ReadIntNumbersConfigInfo(const xmlNodePtr& currNode); static void ReadFloatNumbersConfigInfo(const xmlNodePtr& currNode); + static std::string GetConfigPath(const std::string& configFileName); }; } // namespace Rosen } // namespace OHOS diff --git a/wmserver/src/window_manager_config.cpp b/wmserver/src/window_manager_config.cpp index 7f40faec..f958df33 100644 --- a/wmserver/src/window_manager_config.cpp +++ b/wmserver/src/window_manager_config.cpp @@ -14,6 +14,7 @@ */ #include "window_manager_config.h" +#include "config_policy_utils.h" #include "window_helper.h" #include "window_manager_hilog.h" @@ -27,8 +28,22 @@ std::map WindowManagerConfig::enableConfig_; std::map> WindowManagerConfig::intNumbersConfig_; std::map> WindowManagerConfig::floatNumbersConfig_; -bool WindowManagerConfig::LoadConfigXml(const std::string& configFilePath) + +std::string WindowManagerConfig::GetConfigPath(const std::string& configFileName) { + char buf[PATH_MAX + 1]; + char* configPath = GetOneCfgFile(configFileName.c_str(), buf, PATH_MAX + 1); + char tmpPath[PATH_MAX + 1] = { 0 }; + if (!configPath || strlen(configPath) == 0 || strlen(configPath) > PATH_MAX || !realpath(configPath, tmpPath)) { + WLOGFI("[WmConfig] can not get customization config file"); + return "/system/" + configFileName; + } + return std::string(tmpPath); +} + +bool WindowManagerConfig::LoadConfigXml() +{ + auto configFilePath = GetConfigPath("etc/window/resources/window_manager_config.xml"); xmlDocPtr docPtr = xmlReadFile(configFilePath.c_str(), nullptr, XML_PARSE_NOBLANKS); WLOGFI("[WmConfig] filePath: %{public}s", configFilePath.c_str()); if (docPtr == nullptr) { diff --git a/wmserver/src/window_manager_service.cpp b/wmserver/src/window_manager_service.cpp index 89d51ef9..73838370 100644 --- a/wmserver/src/window_manager_service.cpp +++ b/wmserver/src/window_manager_service.cpp @@ -219,7 +219,7 @@ bool WindowManagerService::Init() WLOGFW("WindowManagerService::Init failed"); return false; } - if (WindowManagerConfig::LoadConfigXml(WINDOW_MANAGER_CONFIG_XML)) { + if (WindowManagerConfig::LoadConfigXml()) { WindowManagerConfig::DumpConfig(); ConfigureWindowManagerService(); } From 299e98540fb2c79873a852ef87fc7a1c54142f0a Mon Sep 17 00:00:00 2001 From: xpeng Date: Mon, 27 Jun 2022 14:20:15 +0800 Subject: [PATCH 31/81] Update screen rotation strategy Signed-off-by: xpeng Change-Id: I2c76b4c4c78526e306b4aad595163b0d357a08c6 --- dmserver/include/screen_rotation_controller.h | 2 + dmserver/src/abstract_screen_controller.cpp | 10 +-- dmserver/src/screen_rotation_controller.cpp | 66 ++++++++++++++++--- 3 files changed, 64 insertions(+), 14 deletions(-) diff --git a/dmserver/include/screen_rotation_controller.h b/dmserver/include/screen_rotation_controller.h index c880491d..c77c78ab 100644 --- a/dmserver/include/screen_rotation_controller.h +++ b/dmserver/include/screen_rotation_controller.h @@ -47,6 +47,7 @@ private: static int CalcSensorDisplayRotation(int orientationDegree); static Rotation ConvertToDeviceRotation(Rotation sensorRotation); static bool IsSensorRelatedOrientation(Orientation orientation); + static void PreprocessOrientation(Orientation orientation); static DisplayId defaultDisplayId_; static bool isGravitySensorSubscribed_; @@ -55,6 +56,7 @@ private: static Rotation currentDisplayRotation_; static long lastCallbackTime_; static uint32_t defaultDeviceRotationOffset_; + static Orientation lastOrientationType_; }; } // Rosen } // OHOS diff --git a/dmserver/src/abstract_screen_controller.cpp b/dmserver/src/abstract_screen_controller.cpp index 48b15b8e..551a0d60 100644 --- a/dmserver/src/abstract_screen_controller.cpp +++ b/dmserver/src/abstract_screen_controller.cpp @@ -620,14 +620,16 @@ bool AbstractScreenController::SetOrientation(ScreenId screenId, Orientation new WLOGI("skip setting orientation. screen %{public}" PRIu64" orientation %{public}u", screenId, newOrientation); return true; } - - Rotation rotationAfter = screen->CalcRotation(newOrientation); - SetRotation(screenId, rotationAfter, false); + if (newOrientation >= Orientation::BEGIN && newOrientation <= Orientation::REVERSE_HORIZONTAL) { + Rotation rotationAfter = screen->CalcRotation(newOrientation); + SetRotation(screenId, rotationAfter, false); + screen->rotation_ = rotationAfter; + } + if (!screen->SetOrientation(newOrientation)) { WLOGE("fail to set rotation, screen %{public}" PRIu64"", screenId); return false; } - screen->rotation_ = rotationAfter; // Notify rotation event to ScreenManager NotifyScreenChanged(screen->ConvertToScreenInfo(), ScreenChangeEvent::UPDATE_ORIENTATION); diff --git a/dmserver/src/screen_rotation_controller.cpp b/dmserver/src/screen_rotation_controller.cpp index 2b0c5aad..ab088499 100644 --- a/dmserver/src/screen_rotation_controller.cpp +++ b/dmserver/src/screen_rotation_controller.cpp @@ -39,6 +39,7 @@ Rotation ScreenRotationController::currentDisplayRotation_; bool ScreenRotationController::isScreenRotationLocked_ = false; long ScreenRotationController::lastCallbackTime_ = 0; uint32_t ScreenRotationController::defaultDeviceRotationOffset_ = 0; +Orientation ScreenRotationController::lastOrientationType_ = Orientation::UNSPECIFIED; void ScreenRotationController::SubscribeGravitySensor() { @@ -101,13 +102,14 @@ void ScreenRotationController::HandleGravitySensorEventCallback(SensorEvent *eve return; } Orientation orientation = GetRequestedOrientation(); + currentDisplayRotation_ = GetCurrentDisplayRotation(); + PreprocessOrientation(orientation); if (!IsSensorRelatedOrientation(orientation)) { return; } GravityData* gravityData = reinterpret_cast(event->data); int sensorDegree = CalcRotationDegree(gravityData); - currentDisplayRotation_ = GetCurrentDisplayRotation(); Rotation currentSensorRotation; // Use ROTATION_0 when degree range is [0, 30]∪[330, 359] if (sensorDegree >= 0 && (sensorDegree <= 30 || sensorDegree >= 330)) { @@ -126,11 +128,11 @@ void ScreenRotationController::HandleGravitySensorEventCallback(SensorEvent *eve } Rotation targetDisplayRotation = CalcTargetDisplayRotation(orientation, currentSensorRotation); - if (ConvertToDeviceRotation(targetDisplayRotation) == currentDisplayRotation_) { + if (targetDisplayRotation == currentDisplayRotation_) { return; } - SetScreenRotation(ConvertToDeviceRotation(targetDisplayRotation)); + SetScreenRotation(targetDisplayRotation); } int ScreenRotationController::CalcRotationDegree(GravityData* gravityData) @@ -165,7 +167,7 @@ Rotation ScreenRotationController::CalcTargetDisplayRotation( { switch (requestedOrientation) { case Orientation::SENSOR: { - return sensorRotation; + return ConvertToDeviceRotation(sensorRotation); } case Orientation::SENSOR_VERTICAL: { return ProcessAutoRotationPortraitOrientation(sensorRotation); @@ -177,7 +179,7 @@ Rotation ScreenRotationController::CalcTargetDisplayRotation( if (isScreenRotationLocked_) { return currentDisplayRotation_; } - return sensorRotation; + return ConvertToDeviceRotation(sensorRotation); } case Orientation::AUTO_ROTATION_PORTRAIT_RESTRICTED: { if (isScreenRotationLocked_) { @@ -200,23 +202,31 @@ Rotation ScreenRotationController::CalcTargetDisplayRotation( Rotation ScreenRotationController::ProcessAutoRotationPortraitOrientation(Rotation sensorRotation) { if (sensorRotation == Rotation::ROTATION_0 || sensorRotation == Rotation::ROTATION_180) { - return sensorRotation; + return ConvertToDeviceRotation(sensorRotation); } - return currentDisplayRotation_; + if (currentDisplayRotation_ == ConvertToDeviceRotation(Rotation::ROTATION_0) || + currentDisplayRotation_ == ConvertToDeviceRotation(Rotation::ROTATION_180)) { + return currentDisplayRotation_; + } + return ConvertToDeviceRotation(Rotation::ROTATION_0); } Rotation ScreenRotationController::ProcessAutoRotationLandscapeOrientation(Rotation sensorRotation) { if (sensorRotation == Rotation::ROTATION_90 || sensorRotation == Rotation::ROTATION_270) { - return sensorRotation; + return ConvertToDeviceRotation(sensorRotation); } - return currentDisplayRotation_; + if (currentDisplayRotation_ == ConvertToDeviceRotation(Rotation::ROTATION_90) || + currentDisplayRotation_ == ConvertToDeviceRotation(Rotation::ROTATION_270)) { + return currentDisplayRotation_; + } + return ConvertToDeviceRotation(Rotation::ROTATION_90); } void ScreenRotationController::SetScreenRotation(Rotation targetRotation) { - DisplayManagerServiceInner::GetInstance().SetRotationFromWindow(defaultDisplayId_, targetRotation); DisplayManagerServiceInner::GetInstance().GetDefaultDisplay()->SetRotation(targetRotation); + DisplayManagerServiceInner::GetInstance().SetRotationFromWindow(defaultDisplayId_, targetRotation); } bool ScreenRotationController::CheckCallbackTimeInterval() @@ -250,5 +260,41 @@ bool ScreenRotationController::IsSensorRelatedOrientation(Orientation orientatio } return true; } + +void ScreenRotationController::PreprocessOrientation(Orientation orientation) +{ + if (lastOrientationType_ == orientation) { + return; + } + lastOrientationType_ = orientation; + switch (orientation) { + case Orientation::UNSPECIFIED: { + SetScreenRotation(Rotation::ROTATION_0); + break; + } + case Orientation::SENSOR_VERTICAL: + case Orientation::AUTO_ROTATION_PORTRAIT_RESTRICTED: { + if (currentDisplayRotation_ == ConvertToDeviceRotation(Rotation::ROTATION_90) || + currentDisplayRotation_ == ConvertToDeviceRotation(Rotation::ROTATION_270)) { + SetScreenRotation(ConvertToDeviceRotation(Rotation::ROTATION_0)); + } + break; + } + case Orientation::SENSOR_HORIZONTAL: + case Orientation::AUTO_ROTATION_LANDSCAPE_RESTRICTED: { + if (currentDisplayRotation_ == ConvertToDeviceRotation(Rotation::ROTATION_0) || + currentDisplayRotation_ == ConvertToDeviceRotation(Rotation::ROTATION_180)) { + Rotation baseHorizontalRotation = static_cast( + // divided by 90 to get bias, %4 to normalize the values into the range 0~3 + (static_cast(Rotation::ROTATION_90) + (defaultDeviceRotationOffset_ / 90)) % 4); + SetScreenRotation(baseHorizontalRotation); + } + break; + } + default: { + return; + } + } +} } // Rosen } // OHOS \ No newline at end of file From 2d3f3c1c7c4c26f86ed92efe35da6c29da4d90b5 Mon Sep 17 00:00:00 2001 From: xpeng Date: Mon, 27 Jun 2022 15:54:26 +0800 Subject: [PATCH 32/81] renamed interfaces's name Signed-off-by: xpeng Change-Id: I6e53681d912952913ed871dc75e6187945aeec65 --- .../napi/window_runtime/api/@ohos.window.d.ts | 8 ++++---- .../window_runtime/window_napi/js_window.cpp | 16 ++++++++-------- .../napi/window_runtime/window_napi/js_window.h | 4 ++-- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/interfaces/kits/napi/window_runtime/api/@ohos.window.d.ts b/interfaces/kits/napi/window_runtime/api/@ohos.window.d.ts index 2ba61c6b..dfd3821b 100644 --- a/interfaces/kits/napi/window_runtime/api/@ohos.window.d.ts +++ b/interfaces/kits/napi/window_runtime/api/@ohos.window.d.ts @@ -949,18 +949,18 @@ declare namespace window { setTransparent(isTransparent: boolean, callback: AsyncCallback): void; /** - * Set the requested orientation config of a window + * Set the preferred orientation config of a window * @param orientation the orientation config of a window * @since 9 */ - setRequestedOrientation(orientation: Orientation): Promise; + setPreferredOrientation(orientation: Orientation): Promise; /** - * Set the requested orientation config of a window + * Set the preferred orientation config of a window * @param orientation the orientation config of a window * @since 9 */ - setRequestedOrientation(orientation: Orientation, callback: AsyncCallback): void; + setPreferredOrientation(orientation: Orientation, callback: AsyncCallback): void; /** * disable window decoration. It must be called before loadContent. diff --git a/interfaces/kits/napi/window_runtime/window_napi/js_window.cpp b/interfaces/kits/napi/window_runtime/window_napi/js_window.cpp index 9419f120..a2df4b41 100644 --- a/interfaces/kits/napi/window_runtime/window_napi/js_window.cpp +++ b/interfaces/kits/napi/window_runtime/window_napi/js_window.cpp @@ -271,11 +271,11 @@ NativeValue* JsWindow::SetCallingWindow(NativeEngine* engine, NativeCallbackInfo return (me != nullptr) ? me->OnSetCallingWindow(*engine, *info) : nullptr; } -NativeValue* JsWindow::SetRequestedOrientation(NativeEngine* engine, NativeCallbackInfo* info) +NativeValue* JsWindow::SetPreferredOrientation(NativeEngine* engine, NativeCallbackInfo* info) { - WLOGFI("[NAPI]SetRequestedOrientation"); + WLOGFI("[NAPI]SetPreferredOrientation"); JsWindow* me = CheckParamsAndGetThis(engine, info); - return (me != nullptr) ? me->OnSetRequestedOrientation(*engine, *info) : nullptr; + return (me != nullptr) ? me->OnSetPreferredOrientation(*engine, *info) : nullptr; } NativeValue* JsWindow::DisableWindowDecor(NativeEngine* engine, NativeCallbackInfo* info) @@ -1033,7 +1033,7 @@ NativeValue* JsWindow::OnIsShowing(NativeEngine& engine, NativeCallbackInfo& inf return result; } -NativeValue* JsWindow::OnSetRequestedOrientation(NativeEngine& engine, NativeCallbackInfo& info) +NativeValue* JsWindow::OnSetPreferredOrientation(NativeEngine& engine, NativeCallbackInfo& info) { WMError errCode = WMError::WM_OK; Orientation requestedOrientation = Orientation::UNSPECIFIED; @@ -1060,13 +1060,13 @@ NativeValue* JsWindow::OnSetRequestedOrientation(NativeEngine& engine, NativeCal auto weakWindow = weakToken.promote(); if (weakWindow == nullptr || errCode != WMError::WM_OK) { task.Reject(engine, CreateJsError(engine, static_cast(errCode), - "OnSetRequestedOrientation failed")); + "OnSetPreferredOrientation failed")); WLOGFE("[NAPI]Window is nullptr or get invalid param"); return; } weakWindow->SetRequestedOrientation(requestedOrientation); task.Resolve(engine, engine.CreateUndefined()); - WLOGFI("[NAPI]Window [%{public}u, %{public}s] OnSetRequestedOrientation end, orientation = %{public}u", + WLOGFI("[NAPI]Window [%{public}u, %{public}s] OnSetPreferredOrientation end, orientation = %{public}u", weakWindow->GetWindowId(), weakWindow->GetWindowName().c_str(), static_cast(requestedOrientation)); @@ -1075,7 +1075,7 @@ NativeValue* JsWindow::OnSetRequestedOrientation(NativeEngine& engine, NativeCal NativeValue* lastParam = (info.argc <= 1) ? nullptr : (info.argv[1]->TypeOf() == NATIVE_FUNCTION ? info.argv[1] : nullptr); NativeValue* result = nullptr; - AsyncTask::Schedule("JsWindow::OnSetRequestedOrientation", + AsyncTask::Schedule("JsWindow::OnSetPreferredOrientation", engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result)); return result; } @@ -1715,7 +1715,7 @@ void BindFunctions(NativeEngine& engine, NativeObject* object) BindNativeFunction(engine, *object, "disableWindowDecor", JsWindow::DisableWindowDecor); BindNativeFunction(engine, *object, "dump", JsWindow::Dump); BindNativeFunction(engine, *object, "setForbidSplitMove", JsWindow::SetForbidSplitMove); - BindNativeFunction(engine, *object, "setRequestedOrientation", JsWindow::SetRequestedOrientation); + BindNativeFunction(engine, *object, "setPreferredOrientation", JsWindow::SetPreferredOrientation); } } // namespace Rosen } // namespace OHOS diff --git a/interfaces/kits/napi/window_runtime/window_napi/js_window.h b/interfaces/kits/napi/window_runtime/window_napi/js_window.h index 3bc45ee9..6a83610f 100644 --- a/interfaces/kits/napi/window_runtime/window_napi/js_window.h +++ b/interfaces/kits/napi/window_runtime/window_napi/js_window.h @@ -60,7 +60,7 @@ public: static NativeValue* SetTouchable(NativeEngine* engine, NativeCallbackInfo* info); static NativeValue* SetTransparent(NativeEngine* engine, NativeCallbackInfo* info); static NativeValue* SetCallingWindow(NativeEngine* engine, NativeCallbackInfo* info); - static NativeValue* SetRequestedOrientation(NativeEngine* engine, NativeCallbackInfo* info); + static NativeValue* SetPreferredOrientation(NativeEngine* engine, NativeCallbackInfo* info); static NativeValue* DisableWindowDecor(NativeEngine* engine, NativeCallbackInfo* info); // colorspace, gamut static NativeValue* IsSupportWideGamut(NativeEngine* engine, NativeCallbackInfo* info); @@ -88,7 +88,7 @@ private: NativeValue* OnLoadContent(NativeEngine& engine, NativeCallbackInfo& info); NativeValue* OnGetAvoidArea(NativeEngine& engine, NativeCallbackInfo& info); NativeValue* OnIsShowing(NativeEngine& engine, NativeCallbackInfo& info); - NativeValue* OnSetRequestedOrientation(NativeEngine& engine, NativeCallbackInfo& info); + NativeValue* OnSetPreferredOrientation(NativeEngine& engine, NativeCallbackInfo& info); // colorspace, gamut NativeValue* OnIsSupportWideGamut(NativeEngine& engine, NativeCallbackInfo& info); From 23011eb0ae88560875d67f28668a80ad31b20b9e Mon Sep 17 00:00:00 2001 From: xpeng Date: Mon, 27 Jun 2022 17:28:12 +0800 Subject: [PATCH 33/81] optimization logic Signed-off-by: xpeng Change-Id: Idbbb06e2e2ff11fefa552153e34e662c47546e67 --- dmserver/include/screen_rotation_controller.h | 4 ++- dmserver/src/screen_rotation_controller.cpp | 36 ++++++++++++------- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/dmserver/include/screen_rotation_controller.h b/dmserver/include/screen_rotation_controller.h index c77c78ab..0494feb7 100644 --- a/dmserver/include/screen_rotation_controller.h +++ b/dmserver/include/screen_rotation_controller.h @@ -47,7 +47,8 @@ private: static int CalcSensorDisplayRotation(int orientationDegree); static Rotation ConvertToDeviceRotation(Rotation sensorRotation); static bool IsSensorRelatedOrientation(Orientation orientation); - static void PreprocessOrientation(Orientation orientation); + static void ProcessRotationWhenSensorDataNotValid(Orientation orientation); + static void HandleUnspecifiedOrientation(Orientation orientation); static DisplayId defaultDisplayId_; static bool isGravitySensorSubscribed_; @@ -57,6 +58,7 @@ private: static long lastCallbackTime_; static uint32_t defaultDeviceRotationOffset_; static Orientation lastOrientationType_; + static Rotation defaultLandscapeDisplayRotation_; }; } // Rosen } // OHOS diff --git a/dmserver/src/screen_rotation_controller.cpp b/dmserver/src/screen_rotation_controller.cpp index ab088499..140999ba 100644 --- a/dmserver/src/screen_rotation_controller.cpp +++ b/dmserver/src/screen_rotation_controller.cpp @@ -23,7 +23,7 @@ namespace OHOS { namespace Rosen { namespace { - constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "DisplaySensorController"}; + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "ScreenRotationController"}; constexpr int64_t ORIENTATION_SENSOR_SAMPLING_RATE = 200000000; // 200ms constexpr int64_t ORIENTATION_SENSOR_REPORTING_RATE = 0; constexpr long ORIENTATION_SENSOR_CALLBACK_TIME_INTERVAL = 200; // 200ms @@ -40,6 +40,7 @@ bool ScreenRotationController::isScreenRotationLocked_ = false; long ScreenRotationController::lastCallbackTime_ = 0; uint32_t ScreenRotationController::defaultDeviceRotationOffset_ = 0; Orientation ScreenRotationController::lastOrientationType_ = Orientation::UNSPECIFIED; +Rotation ScreenRotationController::defaultLandscapeDisplayRotation_ = Rotation::ROTATION_90; void ScreenRotationController::SubscribeGravitySensor() { @@ -90,6 +91,9 @@ void ScreenRotationController::SetDefaultDeviceRotationOffset(uint32_t defaultDe return; } defaultDeviceRotationOffset_ = defaultDeviceRotationOffset; + defaultLandscapeDisplayRotation_ = static_cast( + // divided by 90 to get bias, %4 to normalize the values into the range 0~3 + (static_cast(Rotation::ROTATION_90) + (defaultDeviceRotationOffset_ / 90)) % 4); } void ScreenRotationController::HandleGravitySensorEventCallback(SensorEvent *event) @@ -103,7 +107,7 @@ void ScreenRotationController::HandleGravitySensorEventCallback(SensorEvent *eve } Orientation orientation = GetRequestedOrientation(); currentDisplayRotation_ = GetCurrentDisplayRotation(); - PreprocessOrientation(orientation); + HandleUnspecifiedOrientation(orientation); if (!IsSensorRelatedOrientation(orientation)) { return; } @@ -121,9 +125,11 @@ void ScreenRotationController::HandleGravitySensorEventCallback(SensorEvent *eve } else if (sensorDegree >= 240 && sensorDegree <= 300) { // Use ROTATION_270 when degree range is [240, 300] currentSensorRotation = Rotation::ROTATION_270; } else { + ProcessRotationWhenSensorDataNotValid(orientation); return; } - if (ConvertToDeviceRotation(currentSensorRotation) == currentDisplayRotation_) { + if ((ConvertToDeviceRotation(currentSensorRotation) == currentDisplayRotation_) && + (orientation == Orientation::SENSOR || orientation == Orientation::AUTO_ROTATION_RESTRICTED)) { return; } @@ -220,7 +226,7 @@ Rotation ScreenRotationController::ProcessAutoRotationLandscapeOrientation(Rotat currentDisplayRotation_ == ConvertToDeviceRotation(Rotation::ROTATION_270)) { return currentDisplayRotation_; } - return ConvertToDeviceRotation(Rotation::ROTATION_90); + return defaultLandscapeDisplayRotation_; } void ScreenRotationController::SetScreenRotation(Rotation targetRotation) @@ -261,17 +267,24 @@ bool ScreenRotationController::IsSensorRelatedOrientation(Orientation orientatio return true; } -void ScreenRotationController::PreprocessOrientation(Orientation orientation) +void ScreenRotationController::HandleUnspecifiedOrientation(Orientation orientation) +{ + if (lastOrientationType_ == orientation) { + return; + } + if (orientation == Orientation::UNSPECIFIED) { + SetScreenRotation(Rotation::ROTATION_0); + lastOrientationType_ = orientation; + } +} + +void ScreenRotationController::ProcessRotationWhenSensorDataNotValid(Orientation orientation) { if (lastOrientationType_ == orientation) { return; } lastOrientationType_ = orientation; switch (orientation) { - case Orientation::UNSPECIFIED: { - SetScreenRotation(Rotation::ROTATION_0); - break; - } case Orientation::SENSOR_VERTICAL: case Orientation::AUTO_ROTATION_PORTRAIT_RESTRICTED: { if (currentDisplayRotation_ == ConvertToDeviceRotation(Rotation::ROTATION_90) || @@ -284,10 +297,7 @@ void ScreenRotationController::PreprocessOrientation(Orientation orientation) case Orientation::AUTO_ROTATION_LANDSCAPE_RESTRICTED: { if (currentDisplayRotation_ == ConvertToDeviceRotation(Rotation::ROTATION_0) || currentDisplayRotation_ == ConvertToDeviceRotation(Rotation::ROTATION_180)) { - Rotation baseHorizontalRotation = static_cast( - // divided by 90 to get bias, %4 to normalize the values into the range 0~3 - (static_cast(Rotation::ROTATION_90) + (defaultDeviceRotationOffset_ / 90)) % 4); - SetScreenRotation(baseHorizontalRotation); + SetScreenRotation(defaultLandscapeDisplayRotation_); } break; } From 0d6fb9b20cd3df8dccb78ba9615aacaa65d6d814 Mon Sep 17 00:00:00 2001 From: xpeng Date: Tue, 28 Jun 2022 10:39:41 +0800 Subject: [PATCH 34/81] Optimize logic of auto rotation Signed-off-by: xpeng Change-Id: I18c304be2a4187743ba59eb53fb74748c49c30c2 --- dmserver/src/screen_rotation_controller.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/dmserver/src/screen_rotation_controller.cpp b/dmserver/src/screen_rotation_controller.cpp index 140999ba..635976db 100644 --- a/dmserver/src/screen_rotation_controller.cpp +++ b/dmserver/src/screen_rotation_controller.cpp @@ -109,6 +109,7 @@ void ScreenRotationController::HandleGravitySensorEventCallback(SensorEvent *eve currentDisplayRotation_ = GetCurrentDisplayRotation(); HandleUnspecifiedOrientation(orientation); if (!IsSensorRelatedOrientation(orientation)) { + lastOrientationType_ = orientation; return; } @@ -128,6 +129,7 @@ void ScreenRotationController::HandleGravitySensorEventCallback(SensorEvent *eve ProcessRotationWhenSensorDataNotValid(orientation); return; } + lastOrientationType_ = orientation; if ((ConvertToDeviceRotation(currentSensorRotation) == currentDisplayRotation_) && (orientation == Orientation::SENSOR || orientation == Orientation::AUTO_ROTATION_RESTRICTED)) { return; From 178ab21b46db755e77adf8056990a99d0b53a530 Mon Sep 17 00:00:00 2001 From: yichengzhao Date: Thu, 23 Jun 2022 20:51:37 +0800 Subject: [PATCH 35/81] notify windowproperty change Signed-off-by: yichengzhao Change-Id: Ic5fdc3d2efaa5f6d547747a554a5ff0e988df0e8 --- interfaces/innerkits/wm/wm_common.h | 1 + wmserver/include/window_controller.h | 1 + wmserver/src/window_controller.cpp | 25 +++++++++++++++++++++---- wmserver/src/window_node_container.cpp | 5 ++++- 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/interfaces/innerkits/wm/wm_common.h b/interfaces/innerkits/wm/wm_common.h index 24da28ce..bf277c7a 100644 --- a/interfaces/innerkits/wm/wm_common.h +++ b/interfaces/innerkits/wm/wm_common.h @@ -297,6 +297,7 @@ enum class WindowUpdateType : int32_t { WINDOW_UPDATE_FOCUSED, WINDOW_UPDATE_BOUNDS, WINDOW_UPDATE_ACTIVE, + WINDOW_UPDATE_PROPERTY, }; struct SystemConfig { diff --git a/wmserver/include/window_controller.h b/wmserver/include/window_controller.h index 66971809..f069fe17 100644 --- a/wmserver/include/window_controller.h +++ b/wmserver/include/window_controller.h @@ -83,6 +83,7 @@ private: WMError UpdateTouchHotAreas(const sptr& node, const std::vector& rects); void NotifyTouchOutside(const sptr& node); uint32_t GetEmbedNodeId(const std::vector>& windowNodes, const sptr& node); + void NotifyWindowPropertyChanged(const sptr& node); sptr windowRoot_; sptr inputWindowMonitor_; std::atomic windowId_ { INVALID_WINDOW_ID }; diff --git a/wmserver/src/window_controller.cpp b/wmserver/src/window_controller.cpp index 93b36835..e6feb3c0 100644 --- a/wmserver/src/window_controller.cpp +++ b/wmserver/src/window_controller.cpp @@ -779,18 +779,22 @@ WMError WindowController::UpdateProperty(sptr& property, Propert } WLOGFI("window: [%{public}s, %{public}u] update property for action: %{public}u", node->GetWindowName().c_str(), node->GetWindowId(), static_cast(action)); + WMError ret = WMError::WM_OK; switch (action) { case PropertyChangeAction::ACTION_UPDATE_RECT: { node->SetDecoStatus(property->GetDecoStatus()); node->SetOriginRect(property->GetOriginRect()); node->SetDragType(property->GetDragType()); - return ResizeRect(windowId, property->GetRequestRect(), property->GetWindowSizeChangeReason()); + ret = ResizeRect(windowId, property->GetRequestRect(), property->GetWindowSizeChangeReason()); + break; } case PropertyChangeAction::ACTION_UPDATE_MODE: { - return SetWindowMode(windowId, property->GetWindowMode()); + ret = SetWindowMode(windowId, property->GetWindowMode()); + break; } case PropertyChangeAction::ACTION_UPDATE_FLAGS: { - return SetWindowFlags(windowId, property->GetWindowFlags()); + ret = SetWindowFlags(windowId, property->GetWindowFlags()); + break; } case PropertyChangeAction::ACTION_UPDATE_OTHER_PROPS: { auto& props = property->GetSystemBarProperty(); @@ -850,7 +854,20 @@ WMError WindowController::UpdateProperty(sptr& property, Propert default: break; } - return WMError::WM_OK; + if (ret == WMError::WM_OK) { + NotifyWindowPropertyChanged(node); + } + return ret; +} + +void WindowController::NotifyWindowPropertyChanged(const sptr& node) +{ + auto windowNodeContainer = windowRoot_->GetOrCreateWindowNodeContainer(node->GetDisplayId()); + if (windowNodeContainer == nullptr) { + WLOGFE("windowNodeContainer is null"); + return; + } + windowNodeContainer->NotifyAccessibilityWindowInfo(node, WindowUpdateType::WINDOW_UPDATE_PROPERTY); } WMError WindowController::GetModeChangeHotZones(DisplayId displayId, diff --git a/wmserver/src/window_node_container.cpp b/wmserver/src/window_node_container.cpp index a2e77c39..88f638b7 100644 --- a/wmserver/src/window_node_container.cpp +++ b/wmserver/src/window_node_container.cpp @@ -992,7 +992,7 @@ void WindowNodeContainer::FillWindowInfo(sptr& windowInfo, const spt windowInfo->mode_ = node->GetWindowMode(); windowInfo->type_ = node->GetWindowType(); auto property = node->GetWindowProperty(); - if (!property) { + if (property != nullptr) { windowInfo->isDecorEnable_ = property->GetDecorEnable(); } } @@ -1018,6 +1018,9 @@ void WindowNodeContainer::NotifyAccessibilityWindowInfo(const sptr& case WindowUpdateType::WINDOW_UPDATE_REMOVED: isNeedNotify = true; break; + case WindowUpdateType::WINDOW_UPDATE_PROPERTY: + isNeedNotify = true; + break; default: break; } From 132837e8adafedf5691ffb9323e38b3e861241d6 Mon Sep 17 00:00:00 2001 From: zhoushicheng Date: Tue, 28 Jun 2022 14:46:44 +0800 Subject: [PATCH 36/81] aafwk->ability_runtime Signed-off-by: zhoushicheng Change-Id: I1538d71e0d004185560e092cf4b28a056057c585 --- windowmanager_aafwk.gni | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/windowmanager_aafwk.gni b/windowmanager_aafwk.gni index 06fa2641..19568b31 100644 --- a/windowmanager_aafwk.gni +++ b/windowmanager_aafwk.gni @@ -12,8 +12,7 @@ # limitations under the License. ability_runtime_path = "//foundation/ability/ability_runtime" -ability_runtime_inner_api_path = - "${ability_runtime_path}/interfaces/inner_api" +ability_runtime_inner_api_path = "${ability_runtime_path}/interfaces/inner_api" ability_runtime_kits_path = "${ability_runtime_path}/frameworks/kits" ability_runtime_services_path = "${ability_runtime_path}/services" ability_runtime_napi_path = "${ability_runtime_path}/frameworks/js/napi/aafwk" \ No newline at end of file From 6961ba0814ad49d1a40f667b5f34ad450a0ac488 Mon Sep 17 00:00:00 2001 From: xiaojianfeng Date: Tue, 28 Jun 2022 15:12:13 +0800 Subject: [PATCH 37/81] fix toggle split window states bug Signed-off-by: xiaojianfeng Change-Id: Iab9fcb834ac0ee71fe3a38efedec4b661de07515 --- wm/src/window_impl.cpp | 3 +- wmserver/include/window_node_container.h | 2 + wmserver/include/window_pair.h | 10 +--- wmserver/src/window_node_container.cpp | 76 +++++++++++++++--------- wmserver/src/window_pair.cpp | 7 +-- wmserver/src/window_root.cpp | 7 +-- 6 files changed, 56 insertions(+), 49 deletions(-) diff --git a/wm/src/window_impl.cpp b/wm/src/window_impl.cpp index 0dcecf56..51ab9274 100644 --- a/wm/src/window_impl.cpp +++ b/wm/src/window_impl.cpp @@ -2023,8 +2023,7 @@ void WindowImpl::UpdateWindowState(WindowState state) WLOGFD("MinimizeAbility, id: %{public}u", GetWindowId()); AAFwk::AbilityManagerClient::GetInstance()->MinimizeAbility(abilityContext->GetToken(), true); } else { - state_ = WindowState::STATE_HIDDEN; - NotifyAfterBackground(); + Hide(static_cast(WindowStateChangeReason::TOGGLING)); } break; } diff --git a/wmserver/include/window_node_container.h b/wmserver/include/window_node_container.h index 6803edeb..6115d75a 100644 --- a/wmserver/include/window_node_container.h +++ b/wmserver/include/window_node_container.h @@ -76,6 +76,7 @@ public: void MinimizeAllAppWindows(DisplayId displayId); void MinimizeOldestAppWindow(); WMError ToggleShownStateForAllAppWindows(std::function restoreFunc, bool restore); + void BackUpAllAppWindows(); void RestoreAllAppWindows(std::function restoreFunc); bool IsAppWindowsEmpty() const; void ProcessWindowStateChange(WindowState state, WindowStateChangeReason reason); @@ -160,6 +161,7 @@ private: std::vector backupWindowIds_; std::map backupWindowMode_; std::map backupDividerWindowRect_; + std::map> backupDisplaySplitWindowMode_; sptr zorderPolicy_ = new WindowZorderPolicy(); std::unordered_map> layoutPolicies_; WindowLayoutMode layoutMode_ = WindowLayoutMode::CASCADE; diff --git a/wmserver/include/window_pair.h b/wmserver/include/window_pair.h index 86d8391c..e1a25daf 100644 --- a/wmserver/include/window_pair.h +++ b/wmserver/include/window_pair.h @@ -17,6 +17,7 @@ #define OHOS_ROSEN_WINDOW_PAIR_H #include +#include "class_var_definition.h" #include "window_inner_manager.h" #include "window_node.h" #include "window_layout_policy.h" @@ -171,13 +172,6 @@ public: */ bool IsDockSliceInExitSplitModeArea(const std::vector& exitSplitPoints); - /** - * Set all app windows are restoring. - * - * @param ratio Indicates whether all app windows are restoring. - */ - void SetAllAppWindowsRestoring(bool isAllAppWindowsRestoring); - void SetInitalDividerRect(const Rect& rect); private: @@ -252,8 +246,8 @@ private: sptr divider_; WindowPairStatus status_ = {WindowPairStatus::STATUS_EMPTY}; DisplayGroupWindowTree& displayGroupWindowTree_; - bool isAllAppWindowsRestoring_ { false }; Rect initalDividerRect_ {0, 0, 0, 0}; + DEFINE_VAR_DEFAULT_FUNC_SET(bool, AllSplitAppWindowsRestoring, isAllSplitAppWindowsRestoring, false) }; } // namespace Rosen } // namespace OHOS diff --git a/wmserver/src/window_node_container.cpp b/wmserver/src/window_node_container.cpp index a2e77c39..0d64518f 100644 --- a/wmserver/src/window_node_container.cpp +++ b/wmserver/src/window_node_container.cpp @@ -1387,44 +1387,29 @@ WMError WindowNodeContainer::ToggleShownStateForAllAppWindows( std::function restoreFunc, bool restore) { WLOGFI("ToggleShownStateForAllAppWindows"); + sptr recentWindowNode = nullptr; for (auto node : aboveAppWindowNode_->children_) { if (node->GetWindowType() == WindowType::WINDOW_TYPE_LAUNCHER_RECENT) { - return WMError::WM_DO_NOTHING; + recentWindowNode = node; + if (node->GetWindowMode() == WindowMode::WINDOW_MODE_FULLSCREEN) { + return WMError::WM_OK; + } } } // to do, backup reentry: 1.ToggleShownStateForAllAppWindows fast; 2.this display should reset backupWindowIds_. if (!restore && appWindowNode_->children_.empty() && !backupWindowIds_.empty()) { backupWindowIds_.clear(); backupWindowMode_.clear(); + backupDisplaySplitWindowMode_.clear(); backupDividerWindowRect_.clear(); } if (!restore && !appWindowNode_->children_.empty() && backupWindowIds_.empty()) { WLOGFI("backup"); - std::set displayIdSet; - backupWindowMode_.clear(); - for (auto& appNode : appWindowNode_->children_) { - // exclude exceptional window - if (!WindowHelper::IsMainWindow(appNode->GetWindowType())) { - WLOGFE("is not main window, windowId:%{public}u", appNode->GetWindowId()); - continue; - } - // minimize window - WLOGFD("minimize window, windowId:%{public}u", appNode->GetWindowId()); - backupWindowIds_.emplace_back(appNode->GetWindowId()); - backupWindowMode_[appNode->GetWindowId()] = appNode->GetWindowMode(); - displayIdSet.insert(appNode->GetDisplayId()); - if (appNode->GetWindowToken()) { - appNode->GetWindowToken()->UpdateWindowState(WindowState::STATE_HIDDEN); - } - } - backupDividerWindowRect_.clear(); - for (auto displayId : displayIdSet) { - auto windowPair = displayGroupController_->GetWindowPairByDisplayId(displayId); - if (windowPair == nullptr || windowPair->GetDividerWindow() == nullptr) { - continue; - } - backupDividerWindowRect_[displayId] = windowPair->GetDividerWindow()->GetWindowRect(); + if (recentWindowNode != nullptr && recentWindowNode->GetWindowToken() != nullptr) { + WLOGFI("hide recent"); + recentWindowNode->GetWindowToken()->UpdateWindowState(WindowState::STATE_HIDDEN); } + BackUpAllAppWindows(); } else if (restore && !backupWindowIds_.empty()) { WLOGFI("restore"); RestoreAllAppWindows(restoreFunc); @@ -1434,6 +1419,40 @@ WMError WindowNodeContainer::ToggleShownStateForAllAppWindows( return WMError::WM_OK; } +void WindowNodeContainer::BackUpAllAppWindows() +{ + std::set displayIdSet; + backupWindowMode_.clear(); + backupDisplaySplitWindowMode_.clear(); + for (auto& appNode : appWindowNode_->children_) { + // exclude exceptional window + if (!WindowHelper::IsMainWindow(appNode->GetWindowType())) { + WLOGFE("is not main window, windowId:%{public}u", appNode->GetWindowId()); + continue; + } + // minimize window + WLOGFD("minimize window, windowId:%{public}u", appNode->GetWindowId()); + backupWindowIds_.emplace_back(appNode->GetWindowId()); + auto windowMode = appNode->GetWindowMode(); + backupWindowMode_[appNode->GetWindowId()] = windowMode; + if (WindowHelper::IsSplitWindowMode(windowMode)) { + backupDisplaySplitWindowMode_[appNode->GetWindowId()].insert(windowMode); + } + displayIdSet.insert(appNode->GetDisplayId()); + if (appNode->GetWindowToken()) { + appNode->GetWindowToken()->UpdateWindowState(WindowState::STATE_HIDDEN); + } + } + backupDividerWindowRect_.clear(); + for (auto displayId : displayIdSet) { + auto windowPair = displayGroupController_->GetWindowPairByDisplayId(displayId); + if (windowPair == nullptr || windowPair->GetDividerWindow() == nullptr) { + continue; + } + backupDividerWindowRect_[displayId] = windowPair->GetDividerWindow()->GetWindowRect(); + } +} + void WindowNodeContainer::RestoreAllAppWindows(std::function restoreFunc) { std::vector backupWindowIds(backupWindowIds_); @@ -1442,7 +1461,10 @@ void WindowNodeContainer::RestoreAllAppWindows(std::functionGetWindowPairByDisplayId(displayId); if (windowPair != nullptr) { - windowPair->SetAllAppWindowsRestoring(true); + if (backupDisplaySplitWindowMode_[displayId].count(WindowMode::WINDOW_MODE_SPLIT_PRIMARY) > 0 && + backupDisplaySplitWindowMode_[displayId].count(WindowMode::WINDOW_MODE_SPLIT_SECONDARY) > 0) { + windowPair->SetAllSplitAppWindowsRestoring(true); + } windowPairs.emplace_back(windowPair); } } @@ -1454,7 +1476,7 @@ void WindowNodeContainer::RestoreAllAppWindows(std::functionSetAllAppWindowsRestoring(false); + windowPair->SetAllSplitAppWindowsRestoring(false); } layoutPolicy_->SetSplitDividerWindowRects(backupDividerWindowRect_); backupWindowIds_.clear(); diff --git a/wmserver/src/window_pair.cpp b/wmserver/src/window_pair.cpp index 095b4add..359b17ac 100644 --- a/wmserver/src/window_pair.cpp +++ b/wmserver/src/window_pair.cpp @@ -331,7 +331,7 @@ void WindowPair::UpdateIfSplitRelated(sptr& node) status_, node->GetWindowId(), node->GetWindowMode()); if (status_ == WindowPairStatus::STATUS_EMPTY) { Insert(node); - if (!isAllAppWindowsRestoring_) { + if (!isAllSplitAppWindowsRestoring_) { // find pairable window from trees or send broadcast sptr pairableNode = GetPairableWindow(node); // insert pairable node @@ -487,11 +487,6 @@ void WindowPair::HandleRemoveWindow(sptr& node) } } -void WindowPair::SetAllAppWindowsRestoring(bool isAllAppWindowsRestoring) -{ - isAllAppWindowsRestoring_ = isAllAppWindowsRestoring; -} - void WindowPair::SetInitalDividerRect(const Rect& rect) { initalDividerRect_ = rect; diff --git a/wmserver/src/window_root.cpp b/wmserver/src/window_root.cpp index 59b64bac..f71a2973 100644 --- a/wmserver/src/window_root.cpp +++ b/wmserver/src/window_root.cpp @@ -395,12 +395,7 @@ WMError WindowRoot::ToggleShownStateForAllAppWindows() WindowManagerService::GetInstance().HandleAddWindow(property); return true; }; - WMError tmpRes = WMError::WM_OK; - if (isAllAppWindowsEmpty) { - tmpRes = container->ToggleShownStateForAllAppWindows(restoreFunc, true); - } else { - tmpRes = container->ToggleShownStateForAllAppWindows(restoreFunc, false); - } + WMError tmpRes = tmpRes = container->ToggleShownStateForAllAppWindows(restoreFunc, isAllAppWindowsEmpty); res = (res == WMError::WM_OK) ? tmpRes : res; }); return res; From a4778542949b62941d4d7184ef136b02bb2433ef Mon Sep 17 00:00:00 2001 From: zhoushicheng Date: Tue, 28 Jun 2022 15:27:41 +0800 Subject: [PATCH 38/81] aafwk->ability_runtime Signed-off-by: zhoushicheng Change-Id: I946b3abfe973aba38db6cb672ce95c8fcfd6566a --- windowmanager_aafwk.gni | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/windowmanager_aafwk.gni b/windowmanager_aafwk.gni index 19568b31..3bb6624d 100644 --- a/windowmanager_aafwk.gni +++ b/windowmanager_aafwk.gni @@ -15,4 +15,4 @@ ability_runtime_path = "//foundation/ability/ability_runtime" ability_runtime_inner_api_path = "${ability_runtime_path}/interfaces/inner_api" ability_runtime_kits_path = "${ability_runtime_path}/frameworks/kits" ability_runtime_services_path = "${ability_runtime_path}/services" -ability_runtime_napi_path = "${ability_runtime_path}/frameworks/js/napi/aafwk" \ No newline at end of file +ability_runtime_napi_path = "${ability_runtime_path}/frameworks/js/napi/aafwk" From 0532e97dae4ee9f4fcda61deac0e391ec8f2c103 Mon Sep 17 00:00:00 2001 From: wlj Date: Tue, 28 Jun 2022 14:25:57 +0800 Subject: [PATCH 39/81] fix split test Signed-off-by: wlj Change-Id: Ibb7407a419fdcf7b84a2fa17e2cd779ea2464250 --- resources/config/rk3568/window_manager_config.xml | 2 +- wm/test/systemtest/window_split_test.cpp | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/resources/config/rk3568/window_manager_config.xml b/resources/config/rk3568/window_manager_config.xml index 70ca77e2..db2b08f9 100644 --- a/resources/config/rk3568/window_manager_config.xml +++ b/resources/config/rk3568/window_manager_config.xml @@ -25,7 +25,7 @@ - 0.1 0.9 + 0.1 0.9 0.5 0.33 0.67 \ No newline at end of file diff --git a/wm/test/systemtest/window_split_test.cpp b/wm/test/systemtest/window_split_test.cpp index 56f569a3..4bb0413f 100644 --- a/wm/test/systemtest/window_split_test.cpp +++ b/wm/test/systemtest/window_split_test.cpp @@ -281,9 +281,6 @@ HWTEST_F(WindowSplitTest, SplitScreen06, Function | MediumTest | Level3) ASSERT_EQ(WMError::WM_OK, priWindow->Show()); sleep(SPLIT_TEST_SLEEP_S); - ASSERT_EQ(WindowMode::WINDOW_MODE_SPLIT_PRIMARY, priWindow->GetMode()); - ASSERT_EQ(WindowMode::WINDOW_MODE_SPLIT_SECONDARY, fullWindow->GetMode()); - utils::TestWindowInfo dividerInfo; dividerInfo.name = "divider0"; dividerInfo.type = WindowType::WINDOW_TYPE_DOCK_SLICE; @@ -304,7 +301,11 @@ HWTEST_F(WindowSplitTest, SplitScreen06, Function | MediumTest | Level3) divider->ConsumePointerEvent(pointerEvent); sleep(SPLIT_TEST_SLEEP_S); - posY += 10; + if (rect.width_ < rect.height_) { + posX += 10; + } else { + posY += 10; + } pointerEvent = utils::CreatePointerEvent(posX, posY, pointerId, MMI::PointerEvent::POINTER_ACTION_MOVE); divider->ConsumePointerEvent(pointerEvent); sleep(SPLIT_TEST_SLEEP_S); From 5d821d6f651b762753a8a6237b15d667fab1f9c1 Mon Sep 17 00:00:00 2001 From: xpeng Date: Tue, 28 Jun 2022 15:57:58 +0800 Subject: [PATCH 40/81] Update logic for UNSPECIFIED Signed-off-by: xpeng Change-Id: I5eab5f7a5ad4f501c187c68a8db38a5d3c1b2228 --- dmserver/include/display_manager_service.h | 2 +- .../include/display_manager_service_inner.h | 2 +- dmserver/src/display_manager_service.cpp | 4 ++-- .../src/display_manager_service_inner.cpp | 4 ++-- dmserver/src/screen_rotation_controller.cpp | 19 +++++++++++++------ utils/include/display_change_listener.h | 2 +- wmserver/include/window_controller.h | 2 +- wmserver/include/window_manager_service.h | 4 ++-- wmserver/include/window_node_container.h | 2 +- wmserver/src/window_controller.cpp | 4 ++-- wmserver/src/window_manager_service.cpp | 8 ++++---- wmserver/src/window_node_container.cpp | 5 ++++- 12 files changed, 34 insertions(+), 24 deletions(-) diff --git a/dmserver/include/display_manager_service.h b/dmserver/include/display_manager_service.h index 430a002c..1611bbc5 100644 --- a/dmserver/include/display_manager_service.h +++ b/dmserver/include/display_manager_service.h @@ -98,7 +98,7 @@ public: bool SetVirtualPixelRatio(ScreenId screenId, float virtualPixelRatio) override; static float GetCustomVirtualPixelRatio(); void RegisterDisplayChangeListener(sptr listener); - void GetFullScreenWindowRequestedOrientation(DisplayId displayId, Orientation &orientation); + void GetWindowPreferredOrientation(DisplayId displayId, Orientation &orientation); private: DisplayManagerService(); ~DisplayManagerService() = default; diff --git a/dmserver/include/display_manager_service_inner.h b/dmserver/include/display_manager_service_inner.h index 90e4d1d2..ed8e6c4f 100644 --- a/dmserver/include/display_manager_service_inner.h +++ b/dmserver/include/display_manager_service_inner.h @@ -46,7 +46,7 @@ public: bool SetOrientationFromWindow(DisplayId displayId, Orientation orientation); bool SetRotationFromWindow(DisplayId displayId, Rotation targetRotation); void SetGravitySensorSubscriptionEnabled(); - void GetFullScreenWindowRequestedOrientation(DisplayId displayId, Orientation &orientation); + void GetWindowPreferredOrientation(DisplayId displayId, Orientation &orientation); }; } // namespace OHOS::Rosen diff --git a/dmserver/src/display_manager_service.cpp b/dmserver/src/display_manager_service.cpp index d96c7b09..21153b61 100644 --- a/dmserver/src/display_manager_service.cpp +++ b/dmserver/src/display_manager_service.cpp @@ -133,10 +133,10 @@ void DisplayManagerService::NotifyDisplayStateChange(DisplayId defaultDisplayId, } } -void DisplayManagerService::GetFullScreenWindowRequestedOrientation(DisplayId displayId, Orientation &orientation) +void DisplayManagerService::GetWindowPreferredOrientation(DisplayId displayId, Orientation &orientation) { if (displayChangeListener_ != nullptr) { - displayChangeListener_->OnGetFullScreenWindowRequestedOrientation(displayId, orientation); + displayChangeListener_->OnGetWindowPreferredOrientation(displayId, orientation); } } diff --git a/dmserver/src/display_manager_service_inner.cpp b/dmserver/src/display_manager_service_inner.cpp index 43020920..1d95e999 100644 --- a/dmserver/src/display_manager_service_inner.cpp +++ b/dmserver/src/display_manager_service_inner.cpp @@ -148,9 +148,9 @@ bool DisplayManagerServiceInner::SetRotationFromWindow(DisplayId displayId, Rota SetRotationFromWindow(displayInfo->GetScreenId(), targetRotation); } -void DisplayManagerServiceInner::GetFullScreenWindowRequestedOrientation(DisplayId displayId, Orientation &orientation) +void DisplayManagerServiceInner::GetWindowPreferredOrientation(DisplayId displayId, Orientation &orientation) { - DisplayManagerService::GetInstance().GetFullScreenWindowRequestedOrientation(displayId, orientation); + DisplayManagerService::GetInstance().GetWindowPreferredOrientation(displayId, orientation); } void DisplayManagerServiceInner::SetGravitySensorSubscriptionEnabled() diff --git a/dmserver/src/screen_rotation_controller.cpp b/dmserver/src/screen_rotation_controller.cpp index 635976db..d4c414fb 100644 --- a/dmserver/src/screen_rotation_controller.cpp +++ b/dmserver/src/screen_rotation_controller.cpp @@ -36,7 +36,7 @@ DisplayId ScreenRotationController::defaultDisplayId_ = 0; bool ScreenRotationController::isGravitySensorSubscribed_ = false; SensorUser ScreenRotationController::user_; Rotation ScreenRotationController::currentDisplayRotation_; -bool ScreenRotationController::isScreenRotationLocked_ = false; +bool ScreenRotationController::isScreenRotationLocked_ = true; long ScreenRotationController::lastCallbackTime_ = 0; uint32_t ScreenRotationController::defaultDeviceRotationOffset_ = 0; Orientation ScreenRotationController::lastOrientationType_ = Orientation::UNSPECIFIED; @@ -55,10 +55,16 @@ void ScreenRotationController::SubscribeGravitySensor() } user_.userData = nullptr; user_.callback = &HandleGravitySensorEventCallback; - SubscribeSensor(SENSOR_TYPE_ID_GRAVITY, &user_); + if (SubscribeSensor(SENSOR_TYPE_ID_GRAVITY, &user_) != 0) { + WLOGFE("Subscribe gravity sensor failed"); + return; + } SetBatch(SENSOR_TYPE_ID_GRAVITY, &user_, ORIENTATION_SENSOR_SAMPLING_RATE, ORIENTATION_SENSOR_REPORTING_RATE); SetMode(SENSOR_TYPE_ID_GRAVITY, &user_, SENSOR_ON_CHANGE); - ActivateSensor(SENSOR_TYPE_ID_GRAVITY, &user_); + if (ActivateSensor(SENSOR_TYPE_ID_GRAVITY, &user_) != 0) { + WLOGFE("Activate gravity sensor failed"); + return; + } isGravitySensorSubscribed_ = true; } @@ -166,7 +172,7 @@ Rotation ScreenRotationController::GetCurrentDisplayRotation() Orientation ScreenRotationController::GetRequestedOrientation() { Orientation orientation = Orientation::UNSPECIFIED; - DisplayManagerServiceInner::GetInstance().GetFullScreenWindowRequestedOrientation(defaultDisplayId_, orientation); + DisplayManagerServiceInner::GetInstance().GetWindowPreferredOrientation(defaultDisplayId_, orientation); return orientation; } @@ -183,6 +189,7 @@ Rotation ScreenRotationController::CalcTargetDisplayRotation( case Orientation::SENSOR_HORIZONTAL: { return ProcessAutoRotationLandscapeOrientation(sensorRotation); } + case Orientation::UNSPECIFIED: case Orientation::AUTO_ROTATION_RESTRICTED: { if (isScreenRotationLocked_) { return currentDisplayRotation_; @@ -262,7 +269,7 @@ Rotation ScreenRotationController::ConvertToDeviceRotation(Rotation sensorRotati bool ScreenRotationController::IsSensorRelatedOrientation(Orientation orientation) { - if ((orientation >= Orientation::BEGIN && orientation <= Orientation::REVERSE_HORIZONTAL) || + if ((orientation >= Orientation::VERTICAL && orientation <= Orientation::REVERSE_HORIZONTAL) || orientation == Orientation::LOCKED) { return false; } @@ -274,7 +281,7 @@ void ScreenRotationController::HandleUnspecifiedOrientation(Orientation orientat if (lastOrientationType_ == orientation) { return; } - if (orientation == Orientation::UNSPECIFIED) { + if (orientation == Orientation::UNSPECIFIED && isScreenRotationLocked_) { SetScreenRotation(Rotation::ROTATION_0); lastOrientationType_ = orientation; } diff --git a/utils/include/display_change_listener.h b/utils/include/display_change_listener.h index 62a5a8d2..abd0c7af 100644 --- a/utils/include/display_change_listener.h +++ b/utils/include/display_change_listener.h @@ -35,7 +35,7 @@ class IDisplayChangeListener : public RefBase { public: virtual void OnDisplayStateChange(DisplayId defaultDisplayId, sptr info, const std::map>& displayInfoMap, DisplayStateChangeType type) = 0; - virtual void OnGetFullScreenWindowRequestedOrientation(DisplayId displayId, Orientation &orientation) = 0; + virtual void OnGetWindowPreferredOrientation(DisplayId displayId, Orientation &orientation) = 0; }; } } diff --git a/wmserver/include/window_controller.h b/wmserver/include/window_controller.h index 66971809..15b8aeed 100644 --- a/wmserver/include/window_controller.h +++ b/wmserver/include/window_controller.h @@ -62,7 +62,7 @@ public: void CancelStartingWindow(sptr abilityToken); void MinimizeWindowsByLauncher(std::vector& windowIds, bool isAnimated, sptr& finishCallback); - Orientation GetFullScreenWindowRequestedOrientation(DisplayId displayId); + Orientation GetWindowPreferredOrientation(DisplayId displayId); private: uint32_t GenWindowId(); void FlushWindowInfo(uint32_t windowId); diff --git a/wmserver/include/window_manager_service.h b/wmserver/include/window_manager_service.h index 0366f24c..08347cd5 100644 --- a/wmserver/include/window_manager_service.h +++ b/wmserver/include/window_manager_service.h @@ -42,7 +42,7 @@ class DisplayChangeListener : public IDisplayChangeListener { public: virtual void OnDisplayStateChange(DisplayId defaultDisplayId, sptr displayInfo, const std::map>& displayInfoMap, DisplayStateChangeType type) override; - virtual void OnGetFullScreenWindowRequestedOrientation(DisplayId displayId, Orientation &orientation) override; + virtual void OnGetWindowPreferredOrientation(DisplayId displayId, Orientation &orientation) override; }; class WindowManagerServiceHandler : public AAFwk::WindowManagerServiceHandlerStub { @@ -103,7 +103,7 @@ public: void CancelStartingWindow(sptr abilityToken); void MinimizeWindowsByLauncher(std::vector windowIds, bool isAnimated, sptr& finishCallback) override; - void GetFullScreenWindowRequestedOrientation(DisplayId displayId, Orientation &orientation); + void GetWindowPreferredOrientation(DisplayId displayId, Orientation &orientation); protected: WindowManagerService(); virtual ~WindowManagerService() = default; diff --git a/wmserver/include/window_node_container.h b/wmserver/include/window_node_container.h index 6803edeb..b7695d7b 100644 --- a/wmserver/include/window_node_container.h +++ b/wmserver/include/window_node_container.h @@ -67,7 +67,7 @@ public: bool IsForbidDockSliceMove(DisplayId displayId) const; bool IsDockSliceInExitSplitModeArea(DisplayId displayId) const; void ExitSplitMode(DisplayId displayId); - Orientation GetFullScreenWindowRequestedOrientation(); + Orientation GetWindowPreferredOrientation(); bool isVerticalDisplay(DisplayId displayId) const; WMError RaiseZOrderForAppWindow(sptr& node, sptr& parentNode); diff --git a/wmserver/src/window_controller.cpp b/wmserver/src/window_controller.cpp index 93b36835..b951efd3 100644 --- a/wmserver/src/window_controller.cpp +++ b/wmserver/src/window_controller.cpp @@ -964,11 +964,11 @@ void WindowController::MinimizeWindowsByLauncher(std::vector& windowId } } -Orientation WindowController::GetFullScreenWindowRequestedOrientation(DisplayId displayId) +Orientation WindowController::GetWindowPreferredOrientation(DisplayId displayId) { sptr windowNodeContainer = windowRoot_->GetOrCreateWindowNodeContainer(displayId); if (windowNodeContainer != nullptr) { - return windowNodeContainer->GetFullScreenWindowRequestedOrientation(); + return windowNodeContainer->GetWindowPreferredOrientation(); } return Orientation::UNSPECIFIED; } diff --git a/wmserver/src/window_manager_service.cpp b/wmserver/src/window_manager_service.cpp index 73838370..571e16ff 100644 --- a/wmserver/src/window_manager_service.cpp +++ b/wmserver/src/window_manager_service.cpp @@ -554,9 +554,9 @@ void DisplayChangeListener::OnDisplayStateChange(DisplayId defaultDisplayId, spt WindowManagerService::GetInstance().NotifyDisplayStateChange(defaultDisplayId, displayInfo, displayInfoMap, type); } -void DisplayChangeListener::OnGetFullScreenWindowRequestedOrientation(DisplayId displayId, Orientation &orientation) +void DisplayChangeListener::OnGetWindowPreferredOrientation(DisplayId displayId, Orientation &orientation) { - WindowManagerService::GetInstance().GetFullScreenWindowRequestedOrientation(displayId, orientation); + WindowManagerService::GetInstance().GetWindowPreferredOrientation(displayId, orientation); } void WindowManagerService::ProcessPointDown(uint32_t windowId, bool isStartDrag) @@ -659,10 +659,10 @@ void WindowManagerService::MinimizeWindowsByLauncher(std::vector windo }).get(); } -void WindowManagerService::GetFullScreenWindowRequestedOrientation(DisplayId displayId, Orientation &orientation) +void WindowManagerService::GetWindowPreferredOrientation(DisplayId displayId, Orientation &orientation) { wmsTaskLooper_->ScheduleTask([this, displayId, &orientation]() mutable { - orientation = windowController_->GetFullScreenWindowRequestedOrientation(displayId); + orientation = windowController_->GetWindowPreferredOrientation(displayId); }).wait(); } diff --git a/wmserver/src/window_node_container.cpp b/wmserver/src/window_node_container.cpp index a2e77c39..91df1d5e 100644 --- a/wmserver/src/window_node_container.cpp +++ b/wmserver/src/window_node_container.cpp @@ -1817,7 +1817,7 @@ sptr WindowNodeContainer::GetDisplayInfo(DisplayId displayId) return displayGroupInfo_->GetDisplayInfo(displayId); } -Orientation WindowNodeContainer::GetFullScreenWindowRequestedOrientation() +Orientation WindowNodeContainer::GetWindowPreferredOrientation() { std::vector> windowNodes; TraverseContainer(windowNodes); @@ -1825,6 +1825,9 @@ Orientation WindowNodeContainer::GetFullScreenWindowRequestedOrientation() if (node->GetWindowMode() == WindowMode::WINDOW_MODE_FULLSCREEN) { return node->GetRequestedOrientation(); } + if (node->GetWindowType() == WindowType::WINDOW_TYPE_DOCK_SLICE) { + return Orientation::UNSPECIFIED; + } } return Orientation::UNSPECIFIED; } From 8d67d15b66190dad8b90541a9f94fd30fa753bfe Mon Sep 17 00:00:00 2001 From: l00574490 Date: Tue, 28 Jun 2022 17:32:21 +0800 Subject: [PATCH 41/81] add st Signed-off-by: l00574490 Change-Id: I838164e6153c3b52e541c299534c85a9e1fe885b --- .../window_mode_support_info_test.cpp | 96 +++++++++++-------- 1 file changed, 56 insertions(+), 40 deletions(-) diff --git a/wm/test/systemtest/window_mode_support_info_test.cpp b/wm/test/systemtest/window_mode_support_info_test.cpp index bd93d8e9..94165378 100644 --- a/wm/test/systemtest/window_mode_support_info_test.cpp +++ b/wm/test/systemtest/window_mode_support_info_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2022 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 @@ -29,8 +29,8 @@ public: static void TearDownTestCase(); virtual void SetUp() override; virtual void TearDown() override; - utils::TestWindowInfo fullScreenAppInfo_; - utils::TestWindowInfo floatingScreenAppInfo_; + utils::TestWindowInfo fullAppInfo_1_; + utils::TestWindowInfo fullAppInfo_2_; private: static constexpr uint32_t WAIT_SYANC_US = 100000; }; @@ -49,7 +49,7 @@ void WindowModeSupportInfoTest::TearDownTestCase() void WindowModeSupportInfoTest::SetUp() { - fullScreenAppInfo_ = { + fullAppInfo_1_ = { .name = "FullWindow", .rect = utils::customAppRect_, .type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, @@ -58,8 +58,8 @@ void WindowModeSupportInfoTest::SetUp() .parentLimit = false, .parentName = "", }; - floatingScreenAppInfo_ = { - .name = "FloatingWindow", + fullAppInfo_2_ = { + .name = "FullWindow2", .rect = utils::customAppRect_, .type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, .mode = WindowMode::WINDOW_MODE_FULLSCREEN, @@ -81,8 +81,8 @@ namespace { */ HWTEST_F(WindowModeSupportInfoTest, WindowModeSupportInfo01, Function | MediumTest | Level3) { - const sptr& window = utils::CreateTestWindow(fullScreenAppInfo_); - + const sptr& window = utils::CreateTestWindow(fullAppInfo_1_); + window->SetModeSupportInfo(WindowModeSupport::WINDOW_MODE_SUPPORT_FULLSCREEN); ASSERT_EQ(WindowModeSupport::WINDOW_MODE_SUPPORT_FULLSCREEN, window->GetModeSupportInfo()); window->Destroy(); @@ -90,12 +90,44 @@ HWTEST_F(WindowModeSupportInfoTest, WindowModeSupportInfo01, Function | MediumTe /** * @tc.name: WindowModeSupportInfo02 - * @tc.desc: modeSupportInfo test for single window + * @tc.desc: modeSupportInfo test for single window, only support fullScreen mode * @tc.type: FUNC */ HWTEST_F(WindowModeSupportInfoTest, WindowModeSupportInfo02, Function | MediumTest | Level3) { - const sptr& window = utils::CreateTestWindow(fullScreenAppInfo_); + const sptr& window = utils::CreateTestWindow(fullAppInfo_1_); + + window->SetModeSupportInfo(WindowModeSupport::WINDOW_MODE_SUPPORT_FULLSCREEN); + ASSERT_EQ(WMError::WM_OK, window->Show()); + ASSERT_EQ(WindowMode::WINDOW_MODE_FULLSCREEN, window->GetMode()); + ASSERT_EQ(WMError::WM_OK, window->Hide()); + + window->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING); + ASSERT_EQ(WMError::WM_OK, window->Show()); + ASSERT_EQ(WindowMode::WINDOW_MODE_FULLSCREEN, window->GetMode()); + ASSERT_EQ(WMError::WM_OK, window->Hide()); + + window->SetWindowMode(WindowMode::WINDOW_MODE_SPLIT_PRIMARY); + ASSERT_EQ(WMError::WM_OK, window->Show()); + ASSERT_EQ(WindowMode::WINDOW_MODE_FULLSCREEN, window->GetMode()); + ASSERT_EQ(WMError::WM_OK, window->Hide()); + + window->SetWindowMode(WindowMode::WINDOW_MODE_SPLIT_SECONDARY); + ASSERT_EQ(WMError::WM_OK, window->Show()); + ASSERT_EQ(WindowMode::WINDOW_MODE_FULLSCREEN, window->GetMode()); + ASSERT_EQ(WMError::WM_OK, window->Hide()); + + window->Destroy(); +} + +/** + * @tc.name: WindowModeSupportInfo03 + * @tc.desc: modeSupportInfo test for single window, support both fullScreen and floating mode + * @tc.type: FUNC + */ +HWTEST_F(WindowModeSupportInfoTest, WindowModeSupportInfo03, Function | MediumTest | Level3) +{ + const sptr& window = utils::CreateTestWindow(fullAppInfo_1_); window->SetModeSupportInfo(WindowModeSupport::WINDOW_MODE_SUPPORT_FULLSCREEN | WindowModeSupport::WINDOW_MODE_SUPPORT_FLOATING); @@ -127,13 +159,13 @@ HWTEST_F(WindowModeSupportInfoTest, WindowModeSupportInfo02, Function | MediumTe } /** - * @tc.name: WindowModeSupportInfo03 + * @tc.name: WindowModeSupportInfo04 * @tc.desc: modeSupportInfo test for single window in case current window mode is not supported. * @tc.type: FUNC */ -HWTEST_F(WindowModeSupportInfoTest, WindowModeSupportInfo03, Function | MediumTest | Level3) +HWTEST_F(WindowModeSupportInfoTest, WindowModeSupportInfo04, Function | MediumTest | Level3) { - const sptr& window = utils::CreateTestWindow(fullScreenAppInfo_); + const sptr& window = utils::CreateTestWindow(fullAppInfo_1_); window->SetModeSupportInfo(WindowModeSupport::WINDOW_MODE_SUPPORT_FLOATING | WindowModeSupport::WINDOW_MODE_SUPPORT_SPLIT_PRIMARY | WindowModeSupport::WINDOW_MODE_SUPPORT_SPLIT_SECONDARY); @@ -151,23 +183,15 @@ HWTEST_F(WindowModeSupportInfoTest, WindowModeSupportInfo03, Function | MediumTe } /** - * @tc.name: WindowModeSupportInfo04 + * @tc.name: WindowModeSupportInfo05 * @tc.desc: modeSupportInfo test for layout cascade * @tc.type: FUNC */ -HWTEST_F(WindowModeSupportInfoTest, WindowModeSupportInfo04, Function | MediumTest | Level3) +HWTEST_F(WindowModeSupportInfoTest, WindowModeSupportInfo05, Function | MediumTest | Level3) { - const sptr& window1 = utils::CreateTestWindow(fullScreenAppInfo_); + const sptr& window1 = utils::CreateTestWindow(fullAppInfo_1_); window1->SetModeSupportInfo(WindowModeSupport::WINDOW_MODE_SUPPORT_FULLSCREEN); - const sptr& window2 = utils::CreateTestWindow(utils::TestWindowInfo { - .name = "FullWindow2", - .rect = utils::customAppRect_, - .type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, - .mode = WindowMode::WINDOW_MODE_FULLSCREEN, - .needAvoid = false, - .parentLimit = false, - .parentName = "", - }); + const sptr& window2 = utils::CreateTestWindow(fullAppInfo_2_); window2->SetModeSupportInfo(WindowModeSupport::WINDOW_MODE_SUPPORT_ALL); ASSERT_EQ(WMError::WM_OK, window1->Show()); ASSERT_EQ(WMError::WM_OK, window2->Show()); @@ -182,13 +206,13 @@ HWTEST_F(WindowModeSupportInfoTest, WindowModeSupportInfo04, Function | MediumTe } /** - * @tc.name: WindowModeSupportInfo05 + * @tc.name: WindowModeSupportInfo06 * @tc.desc: modeSupportInfo test for layout tile * @tc.type: FUNC */ -HWTEST_F(WindowModeSupportInfoTest, WindowModeSupportInfo05, Function | MediumTest | Level3) +HWTEST_F(WindowModeSupportInfoTest, WindowModeSupportInfo06, Function | MediumTest | Level3) { - const sptr& window = utils::CreateTestWindow(fullScreenAppInfo_); + const sptr& window = utils::CreateTestWindow(fullAppInfo_1_); window->SetModeSupportInfo(WindowModeSupport::WINDOW_MODE_SUPPORT_FULLSCREEN); ASSERT_EQ(WMError::WM_OK, window->Show()); WindowManager::GetInstance().SetWindowLayoutMode(WindowLayoutMode::TILE); @@ -202,23 +226,15 @@ HWTEST_F(WindowModeSupportInfoTest, WindowModeSupportInfo05, Function | MediumTe } /** - * @tc.name: WindowModeSupportInfo06 + * @tc.name: WindowModeSupportInfo07 * @tc.desc: modeSupportInfo test for split * @tc.type: FUNC */ -HWTEST_F(WindowModeSupportInfoTest, WindowModeSupportInfo06, Function | MediumTest | Level3) +HWTEST_F(WindowModeSupportInfoTest, WindowModeSupportInfo07, Function | MediumTest | Level3) { - const sptr& window1 = utils::CreateTestWindow(fullScreenAppInfo_); + const sptr& window1 = utils::CreateTestWindow(fullAppInfo_1_); window1->SetModeSupportInfo(WindowModeSupport::WINDOW_MODE_SUPPORT_ALL); - const sptr& window2 = utils::CreateTestWindow(utils::TestWindowInfo { - .name = "FullWindow2", - .rect = utils::customAppRect_, - .type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, - .mode = WindowMode::WINDOW_MODE_FULLSCREEN, - .needAvoid = false, - .parentLimit = false, - .parentName = "", - }); + const sptr& window2 = utils::CreateTestWindow(fullAppInfo_2_); window2->SetModeSupportInfo(WindowModeSupport::WINDOW_MODE_SUPPORT_FULLSCREEN); ASSERT_EQ(WMError::WM_OK, window1->Show()); ASSERT_EQ(WMError::WM_OK, window2->Show()); From 03094d9c1743b812bdaf25462211f0d116c6f3fd Mon Sep 17 00:00:00 2001 From: maojiangping Date: Wed, 29 Jun 2022 11:47:26 +0800 Subject: [PATCH 42/81] Fix codex issues. Signed-off-by: maojiangping Change-Id: Ie17b432e8e5fa2d91f8b8018efc3817b869ed7b2 --- dm/test/systemtest/screenshot_cmd_test.cpp | 2 +- dm/test/systemtest/screenshot_test.cpp | 12 +- dm/test/unittest/screenshot_test.cpp | 2 +- wm/test/systemtest/window_drag_test.cpp | 30 +-- wm/test/systemtest/window_effect_test.cpp | 10 +- wm/test/systemtest/window_focus_test.cpp | 70 +++--- wm/test/systemtest/window_gamut_test.cpp | 14 +- wm/test/systemtest/window_immersive_test.cpp | 48 ++-- .../systemtest/window_input_method_test.cpp | 24 +- wm/test/systemtest/window_input_test.cpp | 12 +- wm/test/systemtest/window_layout_test.cpp | 210 +++++++++--------- .../window_mode_support_info_test.cpp | 30 +-- wm/test/systemtest/window_move_drag_test.cpp | 12 +- .../systemtest/window_multi_ability_test.cpp | 36 +-- .../window_occupied_area_change_test.cpp | 24 +- wm/test/systemtest/window_rotation_test.cpp | 16 +- .../window_split_immersive_test.cpp | 14 +- wm/test/systemtest/window_split_test.cpp | 64 +++--- .../systemtest/window_touch_outside_test.cpp | 24 +- .../window_visibility_info_test.cpp | 38 ++-- 20 files changed, 346 insertions(+), 346 deletions(-) diff --git a/dm/test/systemtest/screenshot_cmd_test.cpp b/dm/test/systemtest/screenshot_cmd_test.cpp index 1c0ccb60..72f16b37 100644 --- a/dm/test/systemtest/screenshot_cmd_test.cpp +++ b/dm/test/systemtest/screenshot_cmd_test.cpp @@ -32,7 +32,7 @@ namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "ScreenshotCmdTest"}; } -using utils = DisplayTestUtils; +using Utils = DisplayTestUtils; class ScreenshotCmdTest : public testing::Test { public: static void SetUpTestCase(); diff --git a/dm/test/systemtest/screenshot_test.cpp b/dm/test/systemtest/screenshot_test.cpp index ee31ee98..fe7823bf 100644 --- a/dm/test/systemtest/screenshot_test.cpp +++ b/dm/test/systemtest/screenshot_test.cpp @@ -28,7 +28,7 @@ namespace Rosen { namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "ScreenshotTest"}; } -using utils = DisplayTestUtils; +using Utils = DisplayTestUtils; class ScreenshotTest : public testing::Test { public: static void SetUpTestCase(); @@ -109,7 +109,7 @@ HWTEST_F(ScreenshotTest, ScreenShotValid03, Function | MediumTest | Level2) ASSERT_NE(nullptr, screenshot); Media::Size screenSize = {screenshot->GetWidth(), screenshot->GetHeight()}; - ASSERT_TRUE(utils::SizeEqualToDisplay(dm.GetDefaultDisplay(), screenSize)); + ASSERT_TRUE(Utils::SizeEqualToDisplay(dm.GetDefaultDisplay(), screenSize)); } /** @@ -137,20 +137,20 @@ HWTEST_F(ScreenshotTest, ScreenShotValid05, Function | MediumTest | Level2) defaultImage_, defaultRot_); ASSERT_NE(nullptr, screenshot); Media::Size screenSize = {screenshot->GetWidth(), screenshot->GetHeight()}; - ASSERT_TRUE(utils::SizeEqual(defaultImage_, screenSize)); + ASSERT_TRUE(Utils::SizeEqual(defaultImage_, screenSize)); Media::Size halfDefault_ = {defaultImage_.width / 2, defaultImage_.height / 2}; Media::Rect halfRect = {defaultScreen_.left, defaultScreen_.top, halfDefault_.width, halfDefault_.height}; screenshot = dm.GetScreenshot(defaultId_, halfRect, defaultImage_, defaultRot_); ASSERT_NE(nullptr, screenshot); screenSize = {screenshot->GetWidth(), screenshot->GetHeight()}; - ASSERT_TRUE(utils::SizeEqual(defaultImage_, screenSize)); + ASSERT_TRUE(Utils::SizeEqual(defaultImage_, screenSize)); Media::Size halfSize = {halfDefault_.width, halfDefault_.height}; screenshot = dm.GetScreenshot(defaultId_, defaultScreen_, halfSize, defaultRot_); ASSERT_NE(nullptr, screenshot); screenSize = {screenshot->GetWidth(), screenshot->GetHeight()}; - ASSERT_TRUE(utils::SizeEqual(halfSize, screenSize)); + ASSERT_TRUE(Utils::SizeEqual(halfSize, screenSize)); } /** @@ -165,7 +165,7 @@ HWTEST_F(ScreenshotTest, ScreenShotValid06, Function | MediumTest | Level2) defaultImage_, defaultRot_); ASSERT_NE(nullptr, screenshot); Media::Size screenSize = {screenshot->GetWidth(), screenshot->GetHeight()}; - ASSERT_TRUE(utils::SizeEqualToDisplay(dm.GetDefaultDisplay(), screenSize)); + ASSERT_TRUE(Utils::SizeEqualToDisplay(dm.GetDefaultDisplay(), screenSize)); } /** diff --git a/dm/test/unittest/screenshot_test.cpp b/dm/test/unittest/screenshot_test.cpp index 57f50f2c..17da915b 100644 --- a/dm/test/unittest/screenshot_test.cpp +++ b/dm/test/unittest/screenshot_test.cpp @@ -26,7 +26,7 @@ using namespace testing::ext; namespace OHOS { namespace Rosen { -using utils = TestUtils; +using Utils = TestUtils; constexpr int32_t TEST_IMAGE_HEIGHT = 1080; constexpr int32_t TEST_IMAGE_WIDTH = 1920; using Mocker = SingletonMocker; diff --git a/wm/test/systemtest/window_drag_test.cpp b/wm/test/systemtest/window_drag_test.cpp index 34ec76d9..af107f63 100644 --- a/wm/test/systemtest/window_drag_test.cpp +++ b/wm/test/systemtest/window_drag_test.cpp @@ -23,7 +23,7 @@ using namespace testing::ext; namespace OHOS { namespace Rosen { -using utils = WindowTestUtils; +using Utils = WindowTestUtils; const int WAIT_CALLBACK_US = 100000; // 100000 us class TestDragListener : public IWindowDragListener { @@ -49,9 +49,9 @@ public: static sptr firstWindowDragListener_; static sptr secondWindowDragListener_; - utils::TestWindowInfo dragWindowInfo_; - utils::TestWindowInfo firstWindowInfo_; - utils::TestWindowInfo secondWindowInfo_; + Utils::TestWindowInfo dragWindowInfo_; + Utils::TestWindowInfo firstWindowInfo_; + Utils::TestWindowInfo secondWindowInfo_; }; sptr WindowDragTest::firstWindowDragListener_ = @@ -77,7 +77,7 @@ void WindowDragTest::SetUp() firstWindowInfo_ = { .name = "firstWindow", - .rect = utils::customAppRect_, + .rect = Utils::customAppRect_, .type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, .mode = WindowMode::WINDOW_MODE_FULLSCREEN, .needAvoid = false, @@ -87,7 +87,7 @@ void WindowDragTest::SetUp() secondWindowInfo_ = { .name = "secondWindow", - .rect = utils::customAppRect_, + .rect = Utils::customAppRect_, .type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, .mode = WindowMode::WINDOW_MODE_FLOATING, .needAvoid = false, @@ -105,12 +105,12 @@ namespace { * @tc.type: FUNC */ HWTEST_F(WindowDragTest, DragIn, Function | MediumTest | Level3) { - const sptr &firstWindow = utils::CreateTestWindow(firstWindowInfo_); + const sptr &firstWindow = Utils::CreateTestWindow(firstWindowInfo_); firstWindow->RegisterDragListener(firstWindowDragListener_); firstWindow->SetTurnScreenOn(true); firstWindow->Show(); - const sptr &dragWindow = utils::CreateTestWindow(dragWindowInfo_); + const sptr &dragWindow = Utils::CreateTestWindow(dragWindowInfo_); dragWindow->Show(); dragWindow->MoveTo(300, 300); usleep(WAIT_CALLBACK_US); @@ -129,12 +129,12 @@ HWTEST_F(WindowDragTest, DragIn, Function | MediumTest | Level3) { * @tc.type: FUNC */ HWTEST_F(WindowDragTest, DragMove, Function | MediumTest | Level3) { - const sptr &firstWindow = utils::CreateTestWindow(firstWindowInfo_); + const sptr &firstWindow = Utils::CreateTestWindow(firstWindowInfo_); firstWindow->RegisterDragListener(firstWindowDragListener_); firstWindow->SetTurnScreenOn(true); firstWindow->Show(); - const sptr &dragWindow = utils::CreateTestWindow(dragWindowInfo_); + const sptr &dragWindow = Utils::CreateTestWindow(dragWindowInfo_); dragWindow->Show(); dragWindow->MoveTo(300, 300); usleep(WAIT_CALLBACK_US); @@ -159,17 +159,17 @@ HWTEST_F(WindowDragTest, DragMove, Function | MediumTest | Level3) { * @tc.type: FUNC */ HWTEST_F(WindowDragTest, DragOut, Function | MediumTest | Level3) { - const sptr &firstWindow = utils::CreateTestWindow(firstWindowInfo_); + const sptr &firstWindow = Utils::CreateTestWindow(firstWindowInfo_); firstWindow->RegisterDragListener(firstWindowDragListener_); firstWindow->SetTurnScreenOn(true); firstWindow->Show(); secondWindowInfo_.rect = {500, 500, 500, 500}; - const sptr &secondWindow = utils::CreateTestWindow(secondWindowInfo_); + const sptr &secondWindow = Utils::CreateTestWindow(secondWindowInfo_); secondWindow->RegisterDragListener(secondWindowDragListener_); secondWindow->Show(); - const sptr &dragWindow = utils::CreateTestWindow(dragWindowInfo_); + const sptr &dragWindow = Utils::CreateTestWindow(dragWindowInfo_); dragWindow->Show(); dragWindow->MoveTo(300, 300); usleep(WAIT_CALLBACK_US); @@ -203,12 +203,12 @@ HWTEST_F(WindowDragTest, DragOut, Function | MediumTest | Level3) { * @tc.type: FUNC */ HWTEST_F(WindowDragTest, DragEnd, Function | MediumTest | Level3) { - const sptr &firstWindow = utils::CreateTestWindow(firstWindowInfo_); + const sptr &firstWindow = Utils::CreateTestWindow(firstWindowInfo_); firstWindow->RegisterDragListener(firstWindowDragListener_); firstWindow->SetTurnScreenOn(true); firstWindow->Show(); - const sptr &dragWindow = utils::CreateTestWindow(dragWindowInfo_); + const sptr &dragWindow = Utils::CreateTestWindow(dragWindowInfo_); dragWindow->Show(); dragWindow->MoveTo(199, 199); usleep(WAIT_CALLBACK_US); diff --git a/wm/test/systemtest/window_effect_test.cpp b/wm/test/systemtest/window_effect_test.cpp index 8d13f28b..3981b16d 100644 --- a/wm/test/systemtest/window_effect_test.cpp +++ b/wm/test/systemtest/window_effect_test.cpp @@ -21,14 +21,14 @@ using namespace testing::ext; namespace OHOS { namespace Rosen { -using utils = WindowTestUtils; +using Utils = WindowTestUtils; class WindowEffectTest : public testing::Test { public: static void SetUpTestCase(); static void TearDownTestCase(); virtual void SetUp() override; virtual void TearDown() override; - utils::TestWindowInfo fullScreenAppInfo_; + Utils::TestWindowInfo fullScreenAppInfo_; }; void WindowEffectTest::SetUpTestCase() @@ -43,7 +43,7 @@ void WindowEffectTest::SetUp() { fullScreenAppInfo_ = { .name = "FullWindow", - .rect = utils::customAppRect_, + .rect = Utils::customAppRect_, .type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, .mode = WindowMode::WINDOW_MODE_FULLSCREEN, .needAvoid = false, @@ -64,7 +64,7 @@ namespace { */ HWTEST_F(WindowEffectTest, WindowEffect01, Function | MediumTest | Level3) { - const sptr& window = utils::CreateTestWindow(fullScreenAppInfo_); + const sptr& window = Utils::CreateTestWindow(fullScreenAppInfo_); ASSERT_EQ(WMError::WM_OK, window->SetWindowBackgroundBlur(WindowBlurLevel::WINDOW_BLUR_LOW)); ASSERT_EQ(WindowBlurLevel::WINDOW_BLUR_LOW, window->GetWindowBackgroundBlur()); @@ -78,7 +78,7 @@ HWTEST_F(WindowEffectTest, WindowEffect01, Function | MediumTest | Level3) */ HWTEST_F(WindowEffectTest, WindowEffect02, Function | MediumTest | Level3) { - const sptr& window = utils::CreateTestWindow(fullScreenAppInfo_); + const sptr& window = Utils::CreateTestWindow(fullScreenAppInfo_); ASSERT_EQ(WMError::WM_OK, window->SetAlpha(1.0f)); ASSERT_EQ(1.0f, window->GetAlpha()); diff --git a/wm/test/systemtest/window_focus_test.cpp b/wm/test/systemtest/window_focus_test.cpp index 29b86105..1a4b05db 100644 --- a/wm/test/systemtest/window_focus_test.cpp +++ b/wm/test/systemtest/window_focus_test.cpp @@ -27,7 +27,7 @@ namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowFocusTest"}; } -using utils = WindowTestUtils; +using Utils = WindowTestUtils; const int WAIT_ASYNC_US = 100000; // 100000us class TestFocusChangedListener : public IFocusChangedListener { @@ -45,9 +45,9 @@ public: virtual void SetUp() override; virtual void TearDown() override; static sptr testFocusChangedListener_; - utils::TestWindowInfo fullScreenAppInfo_; - utils::TestWindowInfo floatAppInfo_; - utils::TestWindowInfo subAppInfo_; + Utils::TestWindowInfo fullScreenAppInfo_; + Utils::TestWindowInfo floatAppInfo_; + Utils::TestWindowInfo subAppInfo_; }; sptr WindowFocusTest::testFocusChangedListener_ = @@ -72,7 +72,7 @@ void WindowFocusTest::SetUpTestCase() WLOGFI("GetDefaultDisplay: id %{public}" PRIu64", w %{public}d, h %{public}d, fps %{public}u", display->GetId(), display->GetWidth(), display->GetHeight(), display->GetRefreshRate()); Rect displayRect = {0, 0, display->GetWidth(), display->GetHeight()}; - utils::InitByDisplayRect(displayRect); + Utils::InitByDisplayRect(displayRect); } void WindowFocusTest::TearDownTestCase() @@ -83,7 +83,7 @@ void WindowFocusTest::SetUp() { fullScreenAppInfo_ = { .name = "FullWindow", - .rect = utils::customAppRect_, + .rect = Utils::customAppRect_, .type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, .mode = WindowMode::WINDOW_MODE_FULLSCREEN, .needAvoid = false, @@ -92,7 +92,7 @@ void WindowFocusTest::SetUp() }; floatAppInfo_ = { .name = "ParentWindow", - .rect = utils::customAppRect_, + .rect = Utils::customAppRect_, .type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, .mode = WindowMode::WINDOW_MODE_FLOATING, .needAvoid = false, @@ -101,7 +101,7 @@ void WindowFocusTest::SetUp() }; subAppInfo_ = { .name = "SubWindow", - .rect = utils::customAppRect_, + .rect = Utils::customAppRect_, .type = WindowType::WINDOW_TYPE_APP_SUB_WINDOW, .mode = WindowMode::WINDOW_MODE_FLOATING, .needAvoid = false, @@ -126,23 +126,23 @@ HWTEST_F(WindowFocusTest, FocusChangedTest01, Function | MediumTest | Level3) { fullScreenAppInfo_.name = "FocusChangedTest01_1"; fullScreenAppInfo_.focusable_ = false; - const sptr& window1 = utils::CreateTestWindow(fullScreenAppInfo_); + const sptr& window1 = Utils::CreateTestWindow(fullScreenAppInfo_); ASSERT_NE(nullptr, window1); floatAppInfo_.name = "FocusChangedTest01_2"; floatAppInfo_.rect = { 10, 200, 300, 400 }; - const sptr& window2 = utils::CreateTestWindow(floatAppInfo_); + const sptr& window2 = Utils::CreateTestWindow(floatAppInfo_); ASSERT_NE(nullptr, window2); floatAppInfo_.name = "FocusChangedTest01_3"; floatAppInfo_.rect = { 250, 150, 300, 500 }; - const sptr& window3 = utils::CreateTestWindow(floatAppInfo_); + const sptr& window3 = Utils::CreateTestWindow(floatAppInfo_); ASSERT_NE(nullptr, window3); subAppInfo_.name = "FocusChangedTest01_4"; subAppInfo_.rect = { 400, 200, 100, 100 }; subAppInfo_.parentName = window3->GetWindowName(); - const sptr& subWindow = utils::CreateTestWindow(subAppInfo_); + const sptr& subWindow = Utils::CreateTestWindow(subAppInfo_); ASSERT_EQ(WMError::WM_OK, window3->Show()); // Await 100ms and get callback result in listener. @@ -181,14 +181,14 @@ HWTEST_F(WindowFocusTest, FocusChangedTest02, Function | MediumTest | Level3) { floatAppInfo_.name = "FocusChangedTest02_1"; floatAppInfo_.rect = { 10, 200, 300, 400 }; - const sptr& mainWindow = utils::CreateTestWindow(floatAppInfo_); + const sptr& mainWindow = Utils::CreateTestWindow(floatAppInfo_); ASSERT_NE(nullptr, mainWindow); ASSERT_EQ(WMError::WM_OK, mainWindow->Show()); subAppInfo_.name = "FocusChangedTest02_2"; subAppInfo_.rect = { 400, 200, 100, 100 }; subAppInfo_.parentName = mainWindow->GetWindowName(); - const sptr& subWindow = utils::CreateTestWindow(subAppInfo_); + const sptr& subWindow = Utils::CreateTestWindow(subAppInfo_); ASSERT_NE(nullptr, subWindow); ASSERT_EQ(WMError::WM_OK, subWindow->Show()); usleep(WAIT_ASYNC_US); @@ -212,20 +212,20 @@ HWTEST_F(WindowFocusTest, FocusChangedTest03, Function | MediumTest | Level3) { floatAppInfo_.name = "FocusChangedTest03_1"; floatAppInfo_.rect = { 10, 200, 300, 400 }; - const sptr& mainWindow1 = utils::CreateTestWindow(floatAppInfo_); + const sptr& mainWindow1 = Utils::CreateTestWindow(floatAppInfo_); ASSERT_NE(nullptr, mainWindow1); ASSERT_EQ(WMError::WM_OK, mainWindow1->Show()); subAppInfo_.name = "FocusChangedTest03_2"; subAppInfo_.rect = { 400, 200, 100, 100 }; subAppInfo_.parentName = mainWindow1->GetWindowName(); - const sptr& aboveSubWindow = utils::CreateTestWindow(subAppInfo_); + const sptr& aboveSubWindow = Utils::CreateTestWindow(subAppInfo_); ASSERT_NE(nullptr, aboveSubWindow); ASSERT_EQ(WMError::WM_OK, aboveSubWindow->Show()); floatAppInfo_.name = "FocusChangedTest03_3"; floatAppInfo_.rect = { 200, 200, 100, 100 }; - const sptr& mainWindow2 = utils::CreateTestWindow(floatAppInfo_); + const sptr& mainWindow2 = Utils::CreateTestWindow(floatAppInfo_); ASSERT_NE(nullptr, mainWindow2); ASSERT_EQ(WMError::WM_OK, mainWindow2->Show()); usleep(WAIT_ASYNC_US); @@ -251,7 +251,7 @@ HWTEST_F(WindowFocusTest, FocusChangedTest04, Function | MediumTest | Level3) { floatAppInfo_.name = "FocusChangedTest04_1"; floatAppInfo_.rect = { 10, 200, 300, 400 }; - const sptr& mainWindow1 = utils::CreateTestWindow(floatAppInfo_); + const sptr& mainWindow1 = Utils::CreateTestWindow(floatAppInfo_); ASSERT_NE(nullptr, mainWindow1); ASSERT_EQ(WMError::WM_OK, mainWindow1->Show()); @@ -259,13 +259,13 @@ HWTEST_F(WindowFocusTest, FocusChangedTest04, Function | MediumTest | Level3) subAppInfo_.rect = { 400, 200, 100, 100 }; subAppInfo_.parentName = mainWindow1->GetWindowName(); subAppInfo_.type = WindowType::WINDOW_TYPE_MEDIA; - const sptr& belowSubWindow = utils::CreateTestWindow(subAppInfo_); + const sptr& belowSubWindow = Utils::CreateTestWindow(subAppInfo_); ASSERT_NE(nullptr, belowSubWindow); ASSERT_EQ(WMError::WM_OK, belowSubWindow->Show()); floatAppInfo_.name = "FocusChangedTest04_3"; floatAppInfo_.rect = { 200, 200, 100, 100 }; - const sptr& mainWindow2 = utils::CreateTestWindow(floatAppInfo_); + const sptr& mainWindow2 = Utils::CreateTestWindow(floatAppInfo_); ASSERT_NE(nullptr, mainWindow2); ASSERT_EQ(WMError::WM_OK, mainWindow2->Show()); usleep(WAIT_ASYNC_US); @@ -291,13 +291,13 @@ HWTEST_F(WindowFocusTest, FocusChangedTest05, Function | MediumTest | Level3) { floatAppInfo_.name = "FocusChangedTest05_1"; floatAppInfo_.rect = { 10, 200, 300, 400 }; - const sptr& mainWindow1 = utils::CreateTestWindow(floatAppInfo_); + const sptr& mainWindow1 = Utils::CreateTestWindow(floatAppInfo_); ASSERT_NE(nullptr, mainWindow1); ASSERT_EQ(WMError::WM_OK, mainWindow1->Show()); floatAppInfo_.name = "FocusChangedTest05_2"; floatAppInfo_.rect = { 200, 200, 100, 100 }; - const sptr& mainWindow2 = utils::CreateTestWindow(floatAppInfo_); + const sptr& mainWindow2 = Utils::CreateTestWindow(floatAppInfo_); ASSERT_NE(nullptr, mainWindow2); ASSERT_EQ(WMError::WM_OK, mainWindow2->Show()); @@ -305,7 +305,7 @@ HWTEST_F(WindowFocusTest, FocusChangedTest05, Function | MediumTest | Level3) subAppInfo_.rect = { 400, 200, 100, 100 }; subAppInfo_.parentName = mainWindow2->GetWindowName(); subAppInfo_.type = WindowType::WINDOW_TYPE_MEDIA; - const sptr& belowSubWindow = utils::CreateTestWindow(subAppInfo_); + const sptr& belowSubWindow = Utils::CreateTestWindow(subAppInfo_); ASSERT_NE(nullptr, belowSubWindow); ASSERT_EQ(WMError::WM_OK, belowSubWindow->Show()); usleep(WAIT_ASYNC_US); @@ -340,7 +340,7 @@ HWTEST_F(WindowFocusTest, FocusChangedTest06, Function | MediumTest | Level3) { floatAppInfo_.name = "FocusChangedTest06_1"; floatAppInfo_.rect = { 10, 200, 300, 400 }; - const sptr& mainWindow = utils::CreateTestWindow(floatAppInfo_); + const sptr& mainWindow = Utils::CreateTestWindow(floatAppInfo_); ASSERT_NE(nullptr, mainWindow); ASSERT_EQ(WMError::WM_OK, mainWindow->Show()); @@ -348,7 +348,7 @@ HWTEST_F(WindowFocusTest, FocusChangedTest06, Function | MediumTest | Level3) subAppInfo_.rect = { 100, 200, 100, 100 }; subAppInfo_.parentName = mainWindow->GetWindowName(); subAppInfo_.type = WindowType::WINDOW_TYPE_MEDIA; - const sptr& belowSubWindow = utils::CreateTestWindow(subAppInfo_); + const sptr& belowSubWindow = Utils::CreateTestWindow(subAppInfo_); ASSERT_NE(nullptr, belowSubWindow); ASSERT_EQ(WMError::WM_OK, belowSubWindow->Show()); @@ -356,7 +356,7 @@ HWTEST_F(WindowFocusTest, FocusChangedTest06, Function | MediumTest | Level3) subAppInfo_.rect = { 400, 200, 100, 100 }; subAppInfo_.parentName = mainWindow->GetWindowName(); subAppInfo_.type = WindowType::WINDOW_TYPE_APP_SUB_WINDOW; - const sptr& aboveSubWindow = utils::CreateTestWindow(subAppInfo_); + const sptr& aboveSubWindow = Utils::CreateTestWindow(subAppInfo_); ASSERT_NE(nullptr, aboveSubWindow); ASSERT_EQ(WMError::WM_OK, aboveSubWindow->Show()); usleep(WAIT_ASYNC_US); @@ -377,19 +377,19 @@ HWTEST_F(WindowFocusTest, FocusChangedTest07, Function | MediumTest | Level3) { floatAppInfo_.name = "FocusChangedTest07_1"; floatAppInfo_.rect = { 10, 200, 300, 400 }; - const sptr& mainWindow1 = utils::CreateTestWindow(floatAppInfo_); + const sptr& mainWindow1 = Utils::CreateTestWindow(floatAppInfo_); ASSERT_NE(nullptr, mainWindow1); ASSERT_EQ(WMError::WM_OK, mainWindow1->Show()); floatAppInfo_.name = "FocusChangedTest07_2"; floatAppInfo_.rect = { 250, 150, 300, 500 }; - const sptr& mainWindow2 = utils::CreateTestWindow(floatAppInfo_); + const sptr& mainWindow2 = Utils::CreateTestWindow(floatAppInfo_); ASSERT_NE(nullptr, mainWindow2); ASSERT_EQ(WMError::WM_OK, mainWindow2->Show()); floatAppInfo_.name = "FocusChangedTest07_3"; floatAppInfo_.rect = { 300, 400, 10, 400 }; - const sptr& mainWindow3 = utils::CreateTestWindow(floatAppInfo_); + const sptr& mainWindow3 = Utils::CreateTestWindow(floatAppInfo_); ASSERT_NE(nullptr, mainWindow3); ASSERT_EQ(WMError::WM_OK, mainWindow3->Show()); @@ -397,21 +397,21 @@ HWTEST_F(WindowFocusTest, FocusChangedTest07, Function | MediumTest | Level3) subAppInfo_.rect = { 20, 100, 100, 100 }; subAppInfo_.parentName = mainWindow1->GetWindowName(); subAppInfo_.type = WindowType::WINDOW_TYPE_MEDIA; - const sptr& belowSubWindow1 = utils::CreateTestWindow(subAppInfo_); + const sptr& belowSubWindow1 = Utils::CreateTestWindow(subAppInfo_); ASSERT_NE(nullptr, belowSubWindow1); subAppInfo_.name = "FocusChangedTest07_5"; subAppInfo_.rect = { 400, 200, 100, 100 }; subAppInfo_.parentName = mainWindow2->GetWindowName(); subAppInfo_.type = WindowType::WINDOW_TYPE_APP_SUB_WINDOW; - const sptr& aboveSubWindow = utils::CreateTestWindow(subAppInfo_); + const sptr& aboveSubWindow = Utils::CreateTestWindow(subAppInfo_); ASSERT_NE(nullptr, aboveSubWindow); subAppInfo_.name = "FocusChangedTest07_6"; subAppInfo_.rect = { 310, 410, 100, 100 }; subAppInfo_.parentName = mainWindow3->GetWindowName(); subAppInfo_.type = WindowType::WINDOW_TYPE_MEDIA; - const sptr& belowSubWindow2 = utils::CreateTestWindow(subAppInfo_); + const sptr& belowSubWindow2 = Utils::CreateTestWindow(subAppInfo_); ASSERT_NE(nullptr, belowSubWindow2); ASSERT_EQ(WMError::WM_OK, aboveSubWindow->Show()); @@ -448,13 +448,13 @@ HWTEST_F(WindowFocusTest, FocusChangedTest08, Function | MediumTest | Level3) { floatAppInfo_.name = "FocusChangedTest08_1"; floatAppInfo_.rect = { 10, 200, 300, 400 }; - const sptr& mainWindow1 = utils::CreateTestWindow(floatAppInfo_); + const sptr& mainWindow1 = Utils::CreateTestWindow(floatAppInfo_); ASSERT_NE(nullptr, mainWindow1); ASSERT_EQ(WMError::WM_OK, mainWindow1->Show()); floatAppInfo_.name = "FocusChangedTest08_2"; floatAppInfo_.rect = { 250, 150, 300, 500 }; - const sptr& mainWindow2 = utils::CreateTestWindow(floatAppInfo_); + const sptr& mainWindow2 = Utils::CreateTestWindow(floatAppInfo_); ASSERT_NE(nullptr, mainWindow2); ASSERT_EQ(WMError::WM_OK, mainWindow2->Show()); @@ -462,7 +462,7 @@ HWTEST_F(WindowFocusTest, FocusChangedTest08, Function | MediumTest | Level3) subAppInfo_.rect = { 20, 100, 100, 100 }; subAppInfo_.parentName = mainWindow1->GetWindowName(); subAppInfo_.type = WindowType::WINDOW_TYPE_MEDIA; - const sptr& belowSubWindow = utils::CreateTestWindow(subAppInfo_); + const sptr& belowSubWindow = Utils::CreateTestWindow(subAppInfo_); ASSERT_NE(nullptr, belowSubWindow); ASSERT_EQ(WMError::WM_OK, belowSubWindow->Show()); usleep(WAIT_ASYNC_US); diff --git a/wm/test/systemtest/window_gamut_test.cpp b/wm/test/systemtest/window_gamut_test.cpp index 195bffcb..f0bad10d 100644 --- a/wm/test/systemtest/window_gamut_test.cpp +++ b/wm/test/systemtest/window_gamut_test.cpp @@ -21,7 +21,7 @@ using namespace testing::ext; namespace OHOS { namespace Rosen { -using utils = WindowTestUtils; +using Utils = WindowTestUtils; constexpr uint32_t MAX_WAIT_COUNT = 100; constexpr uint32_t WAIT_DUR = 10 * 1000; @@ -31,7 +31,7 @@ public: static void TearDownTestCase(); virtual void SetUp() override; virtual void TearDown() override; - utils::TestWindowInfo fullScreenAppInfo_; + Utils::TestWindowInfo fullScreenAppInfo_; }; void WindowGamutTest::SetUpTestCase() @@ -46,7 +46,7 @@ void WindowGamutTest::SetUp() { fullScreenAppInfo_ = { .name = "FullWindow", - .rect = utils::customAppRect_, + .rect = Utils::customAppRect_, .type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, .mode = WindowMode::WINDOW_MODE_FULLSCREEN, .needAvoid = false, @@ -67,7 +67,7 @@ namespace { */ HWTEST_F(WindowGamutTest, IsSupportWideGamut01, Function | MediumTest | Level3) { - const sptr& window = utils::CreateTestWindow(fullScreenAppInfo_); + const sptr& window = Utils::CreateTestWindow(fullScreenAppInfo_); ASSERT_EQ(true, window->IsSupportWideGamut()); @@ -81,7 +81,7 @@ HWTEST_F(WindowGamutTest, IsSupportWideGamut01, Function | MediumTest | Level3) */ HWTEST_F(WindowGamutTest, GetColorSpace01, Function | MediumTest | Level3) { - const sptr& window = utils::CreateTestWindow(fullScreenAppInfo_); + const sptr& window = Utils::CreateTestWindow(fullScreenAppInfo_); ASSERT_EQ(ColorSpace::COLOR_SPACE_DEFAULT, window->GetColorSpace()); @@ -101,7 +101,7 @@ HWTEST_F(WindowGamutTest, SetColorSpace01, Function | MediumTest | Level3) ColorSpace::COLOR_SPACE_WIDE_GAMUT }; ColorSpace colorSpace; - const sptr& window = utils::CreateTestWindow(fullScreenAppInfo_); + const sptr& window = Utils::CreateTestWindow(fullScreenAppInfo_); ColorSpace colorSpaceBackup = window->GetColorSpace(); // backup origin @@ -130,7 +130,7 @@ HWTEST_F(WindowGamutTest, SetColorSpace01, Function | MediumTest | Level3) */ HWTEST_F(WindowGamutTest, SetColorSpace02, Function | MediumTest | Level3) { - const sptr& window = utils::CreateTestWindow(fullScreenAppInfo_); + const sptr& window = Utils::CreateTestWindow(fullScreenAppInfo_); ColorSpace colorSpaceBackup = window->GetColorSpace(); diff --git a/wm/test/systemtest/window_immersive_test.cpp b/wm/test/systemtest/window_immersive_test.cpp index 919c00bf..5185e218 100644 --- a/wm/test/systemtest/window_immersive_test.cpp +++ b/wm/test/systemtest/window_immersive_test.cpp @@ -48,7 +48,7 @@ namespace { const float RATIO = 0.3; } -using utils = WindowTestUtils; +using Utils = WindowTestUtils; const int WAIT_ASYNC_US = 100000; // 100000us class TestSystemBarChangedListener : public ISystemBarChangedListener { @@ -79,8 +79,8 @@ public: static vector fullScreenExpecteds_; static sptr testSystemBarChangedListener_; static sptr testAvoidAreaChangedListener_; - utils::TestWindowInfo fullScreenAppinfo_; - utils::TestWindowInfo avoidBarInfo_; + Utils::TestWindowInfo fullScreenAppinfo_; + Utils::TestWindowInfo avoidBarInfo_; uint32_t leftAvoidW_; uint32_t leftAvoidH_; uint32_t topAvoidW_; @@ -200,7 +200,7 @@ void WindowImmersiveTest::SetUpTestCase() WLOGFI("GetDefaultDisplay: id %{public}" PRIu64", w %{public}d, h %{public}d, fps %{public}u", display->GetId(), display->GetWidth(), display->GetHeight(), display->GetRefreshRate()); Rect displayRect = {0, 0, display->GetWidth(), display->GetHeight()}; - utils::InitByDisplayRect(displayRect); + Utils::InitByDisplayRect(displayRect); } void WindowImmersiveTest::TearDownTestCase() @@ -211,7 +211,7 @@ void WindowImmersiveTest::SetUp() { fullScreenAppinfo_ = { .name = "main", - .rect = utils::customAppRect_, + .rect = Utils::customAppRect_, .type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, .mode = WindowMode::WINDOW_MODE_FULLSCREEN, // immersive setting .needAvoid = false, // immersive setting @@ -225,11 +225,11 @@ void WindowImmersiveTest::SetUp() .mode = WindowMode::WINDOW_MODE_FLOATING, }; // makesure left avoid win w < h - leftAvoidW_ = std::min(utils::displayRect_.width_, static_cast(utils::displayRect_.height_ * RATIO)); - leftAvoidH_ = utils::displayRect_.height_; + leftAvoidW_ = std::min(Utils::displayRect_.width_, static_cast(Utils::displayRect_.height_ * RATIO)); + leftAvoidH_ = Utils::displayRect_.height_; // makesure top avoid win h < w - topAvoidW_ = utils::displayRect_.width_; - topAvoidH_ = std::min(utils::displayRect_.height_, static_cast(utils::displayRect_.width_ * RATIO)); + topAvoidW_ = Utils::displayRect_.width_; + topAvoidH_ = std::min(Utils::displayRect_.height_, static_cast(Utils::displayRect_.width_ * RATIO)); WindowManager::GetInstance().RegisterSystemBarChangedListener(testSystemBarChangedListener_); activeWindows_.clear(); @@ -253,7 +253,7 @@ namespace { HWTEST_F(WindowImmersiveTest, ImmersiveTest01, Function | MediumTest | Level3) { fullScreenAppinfo_.name = "immer01"; - const sptr& window = utils::CreateTestWindow(fullScreenAppinfo_); + const sptr& window = Utils::CreateTestWindow(fullScreenAppinfo_); activeWindows_.push_back(window); SetWindowSystemProps(window, TEST_PROPS_1); ASSERT_EQ(WMError::WM_OK, window->Show()); @@ -268,11 +268,11 @@ HWTEST_F(WindowImmersiveTest, ImmersiveTest01, Function | MediumTest | Level3) */ HWTEST_F(WindowImmersiveTest, ImmersiveTest02, Function | MediumTest | Level3) { - const sptr& window1 = utils::CreateTestWindow(fullScreenAppinfo_); + const sptr& window1 = Utils::CreateTestWindow(fullScreenAppinfo_); activeWindows_.push_back(window1); SetWindowSystemProps(window1, TEST_PROPS_1); fullScreenAppinfo_.name = "Immer02"; - const sptr& window2 = utils::CreateTestWindow(fullScreenAppinfo_); + const sptr& window2 = Utils::CreateTestWindow(fullScreenAppinfo_); activeWindows_.push_back(window2); SetWindowSystemProps(window2, TEST_PROPS_2); ASSERT_EQ(WMError::WM_OK, window1->Show()); @@ -292,12 +292,12 @@ HWTEST_F(WindowImmersiveTest, ImmersiveTest02, Function | MediumTest | Level3) */ HWTEST_F(WindowImmersiveTest, ImmersiveTest03, Function | MediumTest | Level3) { - const sptr& window1 = utils::CreateTestWindow(fullScreenAppinfo_); + const sptr& window1 = Utils::CreateTestWindow(fullScreenAppinfo_); activeWindows_.push_back(window1); SetWindowSystemProps(window1, TEST_PROPS_1); fullScreenAppinfo_.name = "Immer03"; fullScreenAppinfo_.needAvoid = true; // no immersive setting - const sptr& window2 = utils::CreateTestWindow(fullScreenAppinfo_); + const sptr& window2 = Utils::CreateTestWindow(fullScreenAppinfo_); activeWindows_.push_back(window2); SetWindowSystemProps(window2, TEST_PROPS_2); ASSERT_EQ(WMError::WM_OK, window1->Show()); @@ -316,7 +316,7 @@ HWTEST_F(WindowImmersiveTest, ImmersiveTest03, Function | MediumTest | Level3) HWTEST_F(WindowImmersiveTest, ImmersiveTest04, Function | MediumTest | Level3) { fullScreenAppinfo_.needAvoid = true; // no immersive setting - const sptr& window1 = utils::CreateTestWindow(fullScreenAppinfo_); + const sptr& window1 = Utils::CreateTestWindow(fullScreenAppinfo_); activeWindows_.push_back(window1); SetWindowSystemProps(window1, TEST_PROPS_1); ASSERT_EQ(WMError::WM_OK, window1->Show()); @@ -338,7 +338,7 @@ HWTEST_F(WindowImmersiveTest, ImmersiveTest04, Function | MediumTest | Level3) HWTEST_F(WindowImmersiveTest, ImmersiveTest05, Function | MediumTest | Level3) { fullScreenAppinfo_.needAvoid = true; // no immersive setting - const sptr& window1 = utils::CreateTestWindow(fullScreenAppinfo_); + const sptr& window1 = Utils::CreateTestWindow(fullScreenAppinfo_); activeWindows_.push_back(window1); SetWindowSystemProps(window1, TEST_PROPS_1); ASSERT_EQ(WMError::WM_OK, window1->Show()); @@ -362,7 +362,7 @@ HWTEST_F(WindowImmersiveTest, ImmersiveNegativeTest01, Function | MediumTest | L { WindowType::WINDOW_TYPE_KEYGUARD, SYS_BAR_PROP_1, SYS_BAR_REGION_NULL }, { WindowType::WINDOW_TYPE_POINTER, SYS_BAR_PROP_2, SYS_BAR_REGION_NULL }, }; - const sptr& window = utils::CreateTestWindow(fullScreenAppinfo_); + const sptr& window = Utils::CreateTestWindow(fullScreenAppinfo_); activeWindows_.push_back(window); SetWindowSystemProps(window, TEST_PROPS_NEGATIVE); ASSERT_EQ(WMError::WM_OK, window->Show()); @@ -379,17 +379,17 @@ HWTEST_F(WindowImmersiveTest, ImmersiveNegativeTest01, Function | MediumTest | L HWTEST_F(WindowImmersiveTest, GetAvoidAreaByTypeTest01, Function | MediumTest | Level3) { // Add full screenwindow for call GetAvoidArea, and push_back in activeWindows_ - const sptr& win = utils::CreateTestWindow(fullScreenAppinfo_); + const sptr& win = Utils::CreateTestWindow(fullScreenAppinfo_); activeWindows_.push_back(win); // Test GetAvoidArea AvoidArea avoidarea; WMError ret = win->GetAvoidAreaByType(AvoidAreaType::TYPE_CUTOUT, avoidarea); ASSERT_EQ(WMError::WM_OK, ret); - ASSERT_TRUE(utils::RectEqualToRect(EMPTY_RECT, avoidarea.leftRect_)); - ASSERT_TRUE(utils::RectEqualToRect(EMPTY_RECT, avoidarea.rightRect_)); - ASSERT_TRUE(utils::RectEqualToRect(EMPTY_RECT, avoidarea.topRect_)); - ASSERT_TRUE(utils::RectEqualToRect(EMPTY_RECT, avoidarea.bottomRect_)); + ASSERT_TRUE(Utils::RectEqualToRect(EMPTY_RECT, avoidarea.leftRect_)); + ASSERT_TRUE(Utils::RectEqualToRect(EMPTY_RECT, avoidarea.rightRect_)); + ASSERT_TRUE(Utils::RectEqualToRect(EMPTY_RECT, avoidarea.topRect_)); + ASSERT_TRUE(Utils::RectEqualToRect(EMPTY_RECT, avoidarea.bottomRect_)); ASSERT_EQ(WMError::WM_OK, win->Hide()); } @@ -400,10 +400,10 @@ HWTEST_F(WindowImmersiveTest, GetAvoidAreaByTypeTest01, Function | MediumTest | */ HWTEST_F(WindowImmersiveTest, DockWindowTest01, Function | MediumTest | Level3) { - const sptr& dockWindow = utils::CreateDockWindow(); + const sptr& dockWindow = Utils::CreateDockWindow(); ASSERT_EQ(WMError::WM_OK, dockWindow->Show()); - const sptr& window = utils::CreateTestWindow(fullScreenAppinfo_); + const sptr& window = Utils::CreateTestWindow(fullScreenAppinfo_); usleep(WAIT_ASYNC_US); auto act = testSystemBarChangedListener_->tints_; diff --git a/wm/test/systemtest/window_input_method_test.cpp b/wm/test/systemtest/window_input_method_test.cpp index 222496d4..0f57c7f9 100644 --- a/wm/test/systemtest/window_input_method_test.cpp +++ b/wm/test/systemtest/window_input_method_test.cpp @@ -21,15 +21,15 @@ using namespace testing::ext; namespace OHOS { namespace Rosen { -using utils = WindowTestUtils; +using Utils = WindowTestUtils; class WindowInputMethodTest : public testing::Test { public: static void SetUpTestCase(); static void TearDownTestCase(); virtual void SetUp() override; virtual void TearDown() override; - utils::TestWindowInfo inputMethodWindowInfo_; - utils::TestWindowInfo keyGuardWindowInfo_; + Utils::TestWindowInfo inputMethodWindowInfo_; + Utils::TestWindowInfo keyGuardWindowInfo_; }; void WindowInputMethodTest::SetUpTestCase() @@ -37,7 +37,7 @@ void WindowInputMethodTest::SetUpTestCase() auto display = DisplayManager::GetInstance().GetDisplayById(0); ASSERT_TRUE((display != nullptr)); Rect displayRect = {0, 0, display->GetWidth(), display->GetHeight()}; - utils::InitByDisplayRect(displayRect); + Utils::InitByDisplayRect(displayRect); } void WindowInputMethodTest::TearDownTestCase() @@ -48,7 +48,7 @@ void WindowInputMethodTest::SetUp() { inputMethodWindowInfo_ = { .name = "", - .rect = utils::customAppRect_, + .rect = Utils::customAppRect_, .type = WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT, .mode = WindowMode::WINDOW_MODE_FLOATING, .needAvoid = false, @@ -57,7 +57,7 @@ void WindowInputMethodTest::SetUp() }; keyGuardWindowInfo_ = { .name = "", - .rect = utils::customAppRect_, + .rect = Utils::customAppRect_, .type = WindowType::WINDOW_TYPE_KEYGUARD, .mode = WindowMode::WINDOW_MODE_FULLSCREEN, .needAvoid = false, @@ -79,7 +79,7 @@ namespace { HWTEST_F(WindowInputMethodTest, InputMethodWindow01, Function | MediumTest | Level3) { inputMethodWindowInfo_.name = "input_method.1"; - const sptr& window = utils::CreateTestWindow(inputMethodWindowInfo_); + const sptr& window = Utils::CreateTestWindow(inputMethodWindowInfo_); ASSERT_EQ(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT, window->GetType()); ASSERT_EQ(WMError::WM_OK, window->Show()); ASSERT_EQ(WMError::WM_OK, window->Hide()); @@ -93,7 +93,7 @@ HWTEST_F(WindowInputMethodTest, InputMethodWindow01, Function | MediumTest | Lev HWTEST_F(WindowInputMethodTest, InputMethodWindow02, Function | MediumTest | Level3) { keyGuardWindowInfo_.name = "keyGuard.1"; - const sptr& window = utils::CreateTestWindow(keyGuardWindowInfo_); + const sptr& window = Utils::CreateTestWindow(keyGuardWindowInfo_); ASSERT_EQ(WindowType::WINDOW_TYPE_KEYGUARD, window->GetType()); ASSERT_EQ(WMError::WM_OK, window->Show()); ASSERT_EQ(WMError::WM_OK, window->Hide()); @@ -108,12 +108,12 @@ HWTEST_F(WindowInputMethodTest, InputMethodWindow03, Function | MediumTest | Lev { inputMethodWindowInfo_.name = "input_method.2"; keyGuardWindowInfo_.name = "keyGuard.2"; - const sptr& inputMethodWindow = utils::CreateTestWindow(inputMethodWindowInfo_); - const sptr& keyGuardWindow = utils::CreateTestWindow(keyGuardWindowInfo_); + const sptr& inputMethodWindow = Utils::CreateTestWindow(inputMethodWindowInfo_); + const sptr& keyGuardWindow = Utils::CreateTestWindow(keyGuardWindowInfo_); keyGuardWindow->Show(); inputMethodWindow->Show(); - ASSERT_TRUE(utils::RectEqualTo(keyGuardWindow, utils::displayRect_)); - ASSERT_TRUE(utils::RectEqualTo(inputMethodWindow, utils::customAppRect_)); + ASSERT_TRUE(Utils::RectEqualTo(keyGuardWindow, Utils::displayRect_)); + ASSERT_TRUE(Utils::RectEqualTo(inputMethodWindow, Utils::customAppRect_)); } } // namespace } // namespace Rosen diff --git a/wm/test/systemtest/window_input_test.cpp b/wm/test/systemtest/window_input_test.cpp index b1577c60..5f57f2a0 100644 --- a/wm/test/systemtest/window_input_test.cpp +++ b/wm/test/systemtest/window_input_test.cpp @@ -24,14 +24,14 @@ namespace Rosen { namespace { constexpr uint32_t WAIT_ASYNC_US = 100000; // 100ms } -using utils = WindowTestUtils; +using Utils = WindowTestUtils; class WindowInputTest : public testing::Test { public: static void SetUpTestCase(); static void TearDownTestCase(); virtual void SetUp() override; virtual void TearDown() override; - utils::TestWindowInfo fullScreenWindow_; + Utils::TestWindowInfo fullScreenWindow_; }; void WindowInputTest::SetUpTestCase() @@ -39,7 +39,7 @@ void WindowInputTest::SetUpTestCase() auto display = DisplayManager::GetInstance().GetDisplayById(0); ASSERT_TRUE((display != nullptr)); Rect displayRect = {0, 0, display->GetWidth(), display->GetHeight()}; - utils::InitByDisplayRect(displayRect); + Utils::InitByDisplayRect(displayRect); } void WindowInputTest::TearDownTestCase() @@ -50,7 +50,7 @@ void WindowInputTest::SetUp() { fullScreenWindow_ = { .name = "FullWindow", - .rect = utils::customAppRect_, + .rect = Utils::customAppRect_, .type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, .mode = WindowMode::WINDOW_MODE_FULLSCREEN, .needAvoid = false, @@ -72,7 +72,7 @@ namespace { HWTEST_F(WindowInputTest, SetTouchHotAreas01, Function | MediumTest | Level3) { fullScreenWindow_.name = "window_hot_areas.1"; - const sptr& window = utils::CreateTestWindow(fullScreenWindow_); + const sptr& window = Utils::CreateTestWindow(fullScreenWindow_); ASSERT_EQ(WMError::WM_OK, window->Show()); std::vector requestedTouchHotAreas; @@ -121,7 +121,7 @@ HWTEST_F(WindowInputTest, SetTouchHotAreas01, Function | MediumTest | Level3) HWTEST_F(WindowInputTest, SetTouchHotAreas02, Function | MediumTest | Level3) { fullScreenWindow_.name = "window_hot_areas.2"; - const sptr& window = utils::CreateTestWindow(fullScreenWindow_); + const sptr& window = Utils::CreateTestWindow(fullScreenWindow_); ASSERT_EQ(WMError::WM_OK, window->Show()); usleep(WAIT_ASYNC_US); diff --git a/wm/test/systemtest/window_layout_test.cpp b/wm/test/systemtest/window_layout_test.cpp index 65f0313b..d84a018b 100644 --- a/wm/test/systemtest/window_layout_test.cpp +++ b/wm/test/systemtest/window_layout_test.cpp @@ -22,7 +22,7 @@ using namespace testing::ext; namespace OHOS { namespace Rosen { -using utils = WindowTestUtils; +using Utils = WindowTestUtils; class WindowLayoutTest : public testing::Test { public: static void SetUpTestCase(); @@ -44,30 +44,30 @@ void WindowLayoutTest::SetUpTestCase() auto display = DisplayManager::GetInstance().GetDisplayById(0); ASSERT_TRUE((display != nullptr)); Rect displayRect = {0, 0, display->GetWidth(), display->GetHeight()}; - utils::InitByDisplayRect(displayRect); + Utils::InitByDisplayRect(displayRect); virtualPixelRatio_ = WindowTestUtils::GetVirtualPixelRatio(0); // calc expected rects Rect expected = { // 0. only statusBar 0, - utils::statusBarRect_.height_, - utils::displayRect_.width_, - utils::displayRect_.height_ - utils::statusBarRect_.height_, + Utils::statusBarRect_.height_, + Utils::displayRect_.width_, + Utils::displayRect_.height_ - Utils::statusBarRect_.height_, }; fullScreenExpecteds_.push_back(expected); expected = { // 1. both statusBar and naviBar 0, - utils::statusBarRect_.height_, - utils::displayRect_.width_, - utils::displayRect_.height_ - utils::statusBarRect_.height_ - utils::naviBarRect_.height_, + Utils::statusBarRect_.height_, + Utils::displayRect_.width_, + Utils::displayRect_.height_ - Utils::statusBarRect_.height_ - Utils::naviBarRect_.height_, }; fullScreenExpecteds_.push_back(expected); expected = { // 2. only naviBar 0, 0, - utils::displayRect_.width_, - utils::displayRect_.height_ - utils::naviBarRect_.height_, + Utils::displayRect_.width_, + Utils::displayRect_.height_ - Utils::naviBarRect_.height_, }; fullScreenExpecteds_.push_back(expected); } @@ -102,7 +102,7 @@ HWTEST_F(WindowLayoutTest, LayoutWindow01, Function | MediumTest | Level3) WindowManager::GetInstance().SetWindowLayoutMode(WindowLayoutMode::TILE); WindowManager::GetInstance().SetWindowLayoutMode(WindowLayoutMode::CASCADE); - utils::TestWindowInfo info = { + Utils::TestWindowInfo info = { .name = "main", .rect = {0, 0, 0, 0}, .type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, @@ -111,11 +111,11 @@ HWTEST_F(WindowLayoutTest, LayoutWindow01, Function | MediumTest | Level3) .parentLimit = false, .parentName = "", }; - const sptr& window = utils::CreateTestWindow(info); + const sptr& window = Utils::CreateTestWindow(info); activeWindows_.push_back(window); - Rect expect = utils::GetDefaultFloatingRect(window); + Rect expect = Utils::GetDefaultFloatingRect(window); ASSERT_EQ(WMError::WM_OK, window->Show()); - ASSERT_TRUE(utils::RectEqualTo(window, expect)); + ASSERT_TRUE(Utils::RectEqualTo(window, expect)); ASSERT_EQ(WMError::WM_OK, window->Hide()); } @@ -126,24 +126,24 @@ HWTEST_F(WindowLayoutTest, LayoutWindow01, Function | MediumTest | Level3) */ HWTEST_F(WindowLayoutTest, LayoutWindow02, Function | MediumTest | Level3) { - utils::TestWindowInfo info = { + Utils::TestWindowInfo info = { .name = "main", - .rect = utils::customAppRect_, + .rect = Utils::customAppRect_, .type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, .mode = WindowMode::WINDOW_MODE_FLOATING, .needAvoid = true, .parentLimit = false, .parentName = "", }; - const sptr& window = utils::CreateTestWindow(info); + const sptr& window = Utils::CreateTestWindow(info); activeWindows_.push_back(window); ASSERT_EQ(WMError::WM_OK, window->Show()); - Rect res = utils::GetFloatingLimitedRect(utils::customAppRect_, virtualPixelRatio_); + Rect res = Utils::GetFloatingLimitedRect(Utils::customAppRect_, virtualPixelRatio_); if (window->IsDecorEnable()) { - ASSERT_TRUE(utils::RectEqualTo(window, utils::GetDecorateRect(res, virtualPixelRatio_))); + ASSERT_TRUE(Utils::RectEqualTo(window, Utils::GetDecorateRect(res, virtualPixelRatio_))); } else { - ASSERT_TRUE(utils::RectEqualTo(window, res)); + ASSERT_TRUE(Utils::RectEqualTo(window, res)); } ASSERT_EQ(WMError::WM_OK, window->Hide()); } @@ -156,40 +156,40 @@ HWTEST_F(WindowLayoutTest, LayoutWindow02, Function | MediumTest | Level3) HWTEST_F(WindowLayoutTest, LayoutWindow04, Function | MediumTest | Level3) { // app window - utils::TestWindowInfo info = { + Utils::TestWindowInfo info = { .name = "main", - .rect = utils::customAppRect_, + .rect = Utils::customAppRect_, .type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, .mode = WindowMode::WINDOW_MODE_FLOATING, .needAvoid = true, .parentLimit = false, .parentName = "", }; - sptr appWin = utils::CreateTestWindow(info); + sptr appWin = Utils::CreateTestWindow(info); activeWindows_.push_back(appWin); // statusBar window - sptr statBar = utils::CreateStatusBarWindow(); + sptr statBar = Utils::CreateStatusBarWindow(); activeWindows_.push_back(statBar); ASSERT_EQ(WMError::WM_OK, appWin->Show()); - Rect res = utils::GetFloatingLimitedRect(utils::customAppRect_, virtualPixelRatio_); + Rect res = Utils::GetFloatingLimitedRect(Utils::customAppRect_, virtualPixelRatio_); if (appWin->IsDecorEnable()) { - ASSERT_TRUE(utils::RectEqualTo(appWin, utils::GetDecorateRect(res, virtualPixelRatio_))); + ASSERT_TRUE(Utils::RectEqualTo(appWin, Utils::GetDecorateRect(res, virtualPixelRatio_))); } else { - ASSERT_TRUE(utils::RectEqualTo(appWin, res)); + ASSERT_TRUE(Utils::RectEqualTo(appWin, res)); } ASSERT_EQ(WMError::WM_OK, statBar->Show()); if (appWin->IsDecorEnable()) { - ASSERT_TRUE(utils::RectEqualTo(appWin, utils::GetDecorateRect(res, virtualPixelRatio_))); + ASSERT_TRUE(Utils::RectEqualTo(appWin, Utils::GetDecorateRect(res, virtualPixelRatio_))); } else { - ASSERT_TRUE(utils::RectEqualTo(appWin, res)); + ASSERT_TRUE(Utils::RectEqualTo(appWin, res)); } ASSERT_EQ(WMError::WM_OK, statBar->Hide()); if (appWin->IsDecorEnable()) { - ASSERT_TRUE(utils::RectEqualTo(appWin, utils::GetDecorateRect(res, virtualPixelRatio_))); + ASSERT_TRUE(Utils::RectEqualTo(appWin, Utils::GetDecorateRect(res, virtualPixelRatio_))); } else { - ASSERT_TRUE(utils::RectEqualTo(appWin, res)); + ASSERT_TRUE(Utils::RectEqualTo(appWin, res)); } } @@ -201,33 +201,33 @@ HWTEST_F(WindowLayoutTest, LayoutWindow04, Function | MediumTest | Level3) HWTEST_F(WindowLayoutTest, LayoutWindow06, Function | MediumTest | Level3) { // statusBar window - sptr statBar = utils::CreateStatusBarWindow(); + sptr statBar = Utils::CreateStatusBarWindow(); activeWindows_.push_back(statBar); // naviBar window - sptr naviBar = utils::CreateNavigationBarWindow(); + sptr naviBar = Utils::CreateNavigationBarWindow(); activeWindows_.push_back(naviBar); // sys window - utils::TestWindowInfo info = { + Utils::TestWindowInfo info = { .name = "main", - .rect = utils::customAppRect_, + .rect = Utils::customAppRect_, .type = WindowType::WINDOW_TYPE_PANEL, .mode = WindowMode::WINDOW_MODE_FULLSCREEN, .needAvoid = false, .parentLimit = true, .parentName = "", }; - sptr sysWin = utils::CreateTestWindow(info); + sptr sysWin = Utils::CreateTestWindow(info); activeWindows_.push_back(sysWin); ASSERT_EQ(WMError::WM_OK, statBar->Show()); ASSERT_EQ(WMError::WM_OK, sysWin->Show()); - ASSERT_TRUE(utils::RectEqualTo(sysWin, utils::displayRect_)); + ASSERT_TRUE(Utils::RectEqualTo(sysWin, Utils::displayRect_)); ASSERT_EQ(WMError::WM_OK, naviBar->Show()); - ASSERT_TRUE(utils::RectEqualTo(sysWin, utils::displayRect_)); + ASSERT_TRUE(Utils::RectEqualTo(sysWin, Utils::displayRect_)); ASSERT_EQ(WMError::WM_OK, statBar->Hide()); - ASSERT_TRUE(utils::RectEqualTo(sysWin, utils::displayRect_)); + ASSERT_TRUE(Utils::RectEqualTo(sysWin, Utils::displayRect_)); } /** @@ -238,33 +238,33 @@ HWTEST_F(WindowLayoutTest, LayoutWindow06, Function | MediumTest | Level3) HWTEST_F(WindowLayoutTest, LayoutWindow07, Function | MediumTest | Level3) { // statusBar window - sptr statBar = utils::CreateStatusBarWindow(); + sptr statBar = Utils::CreateStatusBarWindow(); activeWindows_.push_back(statBar); // naviBar window - sptr naviBar = utils::CreateNavigationBarWindow(); + sptr naviBar = Utils::CreateNavigationBarWindow(); activeWindows_.push_back(naviBar); // sys window - utils::TestWindowInfo info = { + Utils::TestWindowInfo info = { .name = "main", - .rect = utils::customAppRect_, + .rect = Utils::customAppRect_, .type = WindowType::WINDOW_TYPE_PANEL, .mode = WindowMode::WINDOW_MODE_FLOATING, .needAvoid = false, .parentLimit = true, .parentName = "", }; - sptr sysWin = utils::CreateTestWindow(info); + sptr sysWin = Utils::CreateTestWindow(info); activeWindows_.push_back(sysWin); ASSERT_EQ(WMError::WM_OK, statBar->Show()); ASSERT_EQ(WMError::WM_OK, sysWin->Show()); - ASSERT_TRUE(utils::RectEqualTo(sysWin, utils::customAppRect_)); + ASSERT_TRUE(Utils::RectEqualTo(sysWin, Utils::customAppRect_)); ASSERT_EQ(WMError::WM_OK, naviBar->Show()); - ASSERT_TRUE(utils::RectEqualTo(sysWin, utils::customAppRect_)); + ASSERT_TRUE(Utils::RectEqualTo(sysWin, Utils::customAppRect_)); ASSERT_EQ(WMError::WM_OK, statBar->Hide()); - ASSERT_TRUE(utils::RectEqualTo(sysWin, utils::customAppRect_)); + ASSERT_TRUE(Utils::RectEqualTo(sysWin, Utils::customAppRect_)); } /** @@ -274,7 +274,7 @@ HWTEST_F(WindowLayoutTest, LayoutWindow07, Function | MediumTest | Level3) */ HWTEST_F(WindowLayoutTest, LayoutWindow08, Function | MediumTest | Level3) { - utils::TestWindowInfo info = { + Utils::TestWindowInfo info = { .name = "main", .rect = {0, 0, 0, 0}, .type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, @@ -283,11 +283,11 @@ HWTEST_F(WindowLayoutTest, LayoutWindow08, Function | MediumTest | Level3) .parentLimit = false, .parentName = "", }; - const sptr& window = utils::CreateTestWindow(info); + const sptr& window = Utils::CreateTestWindow(info); activeWindows_.push_back(window); - Rect expect = utils::GetDefaultFloatingRect(window); + Rect expect = Utils::GetDefaultFloatingRect(window); ASSERT_EQ(WMError::WM_OK, window->Show()); - ASSERT_TRUE(utils::RectEqualTo(window, expect)); + ASSERT_TRUE(Utils::RectEqualTo(window, expect)); ASSERT_EQ(WMError::WM_OK, window->Hide()); } @@ -298,7 +298,7 @@ HWTEST_F(WindowLayoutTest, LayoutWindow08, Function | MediumTest | Level3) */ HWTEST_F(WindowLayoutTest, LayoutWindow09, Function | MediumTest | Level3) { - utils::TestWindowInfo info = { + Utils::TestWindowInfo info = { .name = "main", .rect = {0, 0, 0, 0}, .type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, @@ -307,17 +307,17 @@ HWTEST_F(WindowLayoutTest, LayoutWindow09, Function | MediumTest | Level3) .parentLimit = false, .parentName = "", }; - const sptr& window = utils::CreateTestWindow(info); + const sptr& window = Utils::CreateTestWindow(info); activeWindows_.push_back(window); - Rect expect = utils::GetDefaultFloatingRect(window); + Rect expect = Utils::GetDefaultFloatingRect(window); ASSERT_EQ(WMError::WM_OK, window->Show()); - ASSERT_TRUE(utils::RectEqualTo(window, expect)); + ASSERT_TRUE(Utils::RectEqualTo(window, expect)); ASSERT_EQ(WMError::WM_OK, window->Resize(2u, 2u)); // 2: custom min size Rect finalExcept = { expect.posX_, expect.posY_, 2u, 2u}; // 2: custom min size - finalExcept = utils::GetFloatingLimitedRect(finalExcept, virtualPixelRatio_); - ASSERT_TRUE(utils::RectEqualTo(window, finalExcept)); + finalExcept = Utils::GetFloatingLimitedRect(finalExcept, virtualPixelRatio_); + ASSERT_TRUE(Utils::RectEqualTo(window, finalExcept)); ASSERT_EQ(WMError::WM_OK, window->Hide()); } @@ -328,7 +328,7 @@ HWTEST_F(WindowLayoutTest, LayoutWindow09, Function | MediumTest | Level3) */ HWTEST_F(WindowLayoutTest, LayoutWindow10, Function | MediumTest | Level3) { - utils::TestWindowInfo info = { + Utils::TestWindowInfo info = { .name = "main", .rect = {0, 0, 0, 0}, .type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, @@ -337,15 +337,15 @@ HWTEST_F(WindowLayoutTest, LayoutWindow10, Function | MediumTest | Level3) .parentLimit = false, .parentName = "", }; - const sptr& window = utils::CreateTestWindow(info); + const sptr& window = Utils::CreateTestWindow(info); activeWindows_.push_back(window); - Rect expect = utils::GetDefaultFloatingRect(window); + Rect expect = Utils::GetDefaultFloatingRect(window); ASSERT_EQ(WMError::WM_OK, window->Show()); - ASSERT_TRUE(utils::RectEqualTo(window, expect)); + ASSERT_TRUE(Utils::RectEqualTo(window, expect)); ASSERT_EQ(WMError::WM_OK, window->Maximize()); - ASSERT_TRUE(utils::RectEqualTo(window, utils::displayRect_)); + ASSERT_TRUE(Utils::RectEqualTo(window, Utils::displayRect_)); ASSERT_EQ(WMError::WM_OK, window->Recover()); - ASSERT_TRUE(utils::RectEqualTo(window, expect)); + ASSERT_TRUE(Utils::RectEqualTo(window, expect)); ASSERT_EQ(WMError::WM_OK, window->Minimize()); ASSERT_EQ(WMError::WM_OK, window->Close()); } @@ -357,7 +357,7 @@ HWTEST_F(WindowLayoutTest, LayoutWindow10, Function | MediumTest | Level3) */ HWTEST_F(WindowLayoutTest, LayoutTile01, Function | MediumTest | Level3) { - utils::TestWindowInfo info = { + Utils::TestWindowInfo info = { .name = "main", .rect = {0, 0, 0, 0}, .type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, @@ -367,47 +367,47 @@ HWTEST_F(WindowLayoutTest, LayoutTile01, Function | MediumTest | Level3) .parentName = "", }; - const sptr& window = utils::CreateTestWindow(info); + const sptr& window = Utils::CreateTestWindow(info); activeWindows_.push_back(window); - Rect expect = utils::GetDefaultFloatingRect(window); + Rect expect = Utils::GetDefaultFloatingRect(window); ASSERT_EQ(WMError::WM_OK, window->Show()); // init tile window rects and get max tile window num - utils::InitTileWindowRects(window); - uint32_t maxTileNum = utils::GetMaxTileWinNum(); + Utils::InitTileWindowRects(window); + uint32_t maxTileNum = Utils::GetMaxTileWinNum(); usleep(WAIT_SYANC_US); - ASSERT_TRUE(utils::RectEqualTo(window, expect)); + ASSERT_TRUE(Utils::RectEqualTo(window, expect)); WindowManager::GetInstance().SetWindowLayoutMode(WindowLayoutMode::TILE); usleep(WAIT_SYANC_US); - ASSERT_TRUE(utils::RectEqualTo(window, utils::singleTileRect_)); + ASSERT_TRUE(Utils::RectEqualTo(window, Utils::singleTileRect_)); info.name = "test1"; - const sptr& test1 = utils::CreateTestWindow(info); + const sptr& test1 = Utils::CreateTestWindow(info); activeWindows_.push_back(test1); ASSERT_EQ(WMError::WM_OK, test1->Show()); usleep(WAIT_SYANC_US); if (maxTileNum == 1) { - ASSERT_TRUE(utils::RectEqualTo(test1, utils::singleTileRect_)); + ASSERT_TRUE(Utils::RectEqualTo(test1, Utils::singleTileRect_)); WindowManager::GetInstance().SetWindowLayoutMode(WindowLayoutMode::CASCADE); return; } - ASSERT_TRUE(utils::RectEqualTo(window, utils::doubleTileRects_[0])); - ASSERT_TRUE(utils::RectEqualTo(test1, utils::doubleTileRects_[1])); + ASSERT_TRUE(Utils::RectEqualTo(window, Utils::doubleTileRects_[0])); + ASSERT_TRUE(Utils::RectEqualTo(test1, Utils::doubleTileRects_[1])); info.name = "test2"; - const sptr& test2 = utils::CreateTestWindow(info); + const sptr& test2 = Utils::CreateTestWindow(info); activeWindows_.push_back(test2); ASSERT_EQ(WMError::WM_OK, test2->Show()); usleep(WAIT_SYANC_US); if (maxTileNum == 2) { - ASSERT_TRUE(utils::RectEqualTo(test1, utils::doubleTileRects_[0])); - ASSERT_TRUE(utils::RectEqualTo(test2, utils::doubleTileRects_[1])); + ASSERT_TRUE(Utils::RectEqualTo(test1, Utils::doubleTileRects_[0])); + ASSERT_TRUE(Utils::RectEqualTo(test2, Utils::doubleTileRects_[1])); WindowManager::GetInstance().SetWindowLayoutMode(WindowLayoutMode::CASCADE); return; } - ASSERT_TRUE(utils::RectEqualTo(window, utils::tripleTileRects_[0])); - ASSERT_TRUE(utils::RectEqualTo(test1, utils::tripleTileRects_[1])); - ASSERT_TRUE(utils::RectEqualTo(test2, utils::tripleTileRects_[2])); // 2 is second rect idx + ASSERT_TRUE(Utils::RectEqualTo(window, Utils::tripleTileRects_[0])); + ASSERT_TRUE(Utils::RectEqualTo(test1, Utils::tripleTileRects_[1])); + ASSERT_TRUE(Utils::RectEqualTo(test2, Utils::tripleTileRects_[2])); // 2 is second rect idx WindowManager::GetInstance().SetWindowLayoutMode(WindowLayoutMode::CASCADE); } @@ -418,7 +418,7 @@ HWTEST_F(WindowLayoutTest, LayoutTile01, Function | MediumTest | Level3) */ HWTEST_F(WindowLayoutTest, LayoutTileNegative01, Function | MediumTest | Level3) { - utils::TestWindowInfo info = { + Utils::TestWindowInfo info = { .name = "main", .rect = {-1, -100, -1, -100}, // -1, -100, -1, -100 is typical negative case nums .type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, @@ -427,45 +427,45 @@ HWTEST_F(WindowLayoutTest, LayoutTileNegative01, Function | MediumTest | Level3) .parentLimit = false, .parentName = "", }; - const sptr& window = utils::CreateTestWindow(info); + const sptr& window = Utils::CreateTestWindow(info); activeWindows_.push_back(window); ASSERT_EQ(WMError::WM_OK, window->Show()); // init tile window rects and get max tile window num - utils::InitTileWindowRects(window); - uint32_t maxTileNum = utils::GetMaxTileWinNum(); + Utils::InitTileWindowRects(window); + uint32_t maxTileNum = Utils::GetMaxTileWinNum(); usleep(WAIT_SYANC_US); WindowManager::GetInstance().SetWindowLayoutMode(WindowLayoutMode::TILE); usleep(WAIT_SYANC_US); - ASSERT_TRUE(utils::RectEqualTo(window, utils::singleTileRect_)); + ASSERT_TRUE(Utils::RectEqualTo(window, Utils::singleTileRect_)); info.name = "test1"; - const sptr& test1 = utils::CreateTestWindow(info); + const sptr& test1 = Utils::CreateTestWindow(info); activeWindows_.push_back(test1); ASSERT_EQ(WMError::WM_OK, test1->Show()); usleep(WAIT_SYANC_US); if (maxTileNum == 1) { - ASSERT_TRUE(utils::RectEqualTo(test1, utils::singleTileRect_)); + ASSERT_TRUE(Utils::RectEqualTo(test1, Utils::singleTileRect_)); WindowManager::GetInstance().SetWindowLayoutMode(WindowLayoutMode::CASCADE); return; } - ASSERT_TRUE(utils::RectEqualTo(window, utils::doubleTileRects_[0])); - ASSERT_TRUE(utils::RectEqualTo(test1, utils::doubleTileRects_[1])); + ASSERT_TRUE(Utils::RectEqualTo(window, Utils::doubleTileRects_[0])); + ASSERT_TRUE(Utils::RectEqualTo(test1, Utils::doubleTileRects_[1])); info.name = "test2"; - const sptr& test2 = utils::CreateTestWindow(info); + const sptr& test2 = Utils::CreateTestWindow(info); activeWindows_.push_back(test2); ASSERT_EQ(WMError::WM_OK, test2->Show()); usleep(WAIT_SYANC_US); if (maxTileNum == 2) { - ASSERT_TRUE(utils::RectEqualTo(test1, utils::doubleTileRects_[0])); - ASSERT_TRUE(utils::RectEqualTo(test2, utils::doubleTileRects_[1])); + ASSERT_TRUE(Utils::RectEqualTo(test1, Utils::doubleTileRects_[0])); + ASSERT_TRUE(Utils::RectEqualTo(test2, Utils::doubleTileRects_[1])); WindowManager::GetInstance().SetWindowLayoutMode(WindowLayoutMode::CASCADE); return; } - ASSERT_TRUE(utils::RectEqualTo(window, utils::tripleTileRects_[0])); - ASSERT_TRUE(utils::RectEqualTo(test1, utils::tripleTileRects_[1])); - ASSERT_TRUE(utils::RectEqualTo(test2, utils::tripleTileRects_[2])); // 2 is second rect idx + ASSERT_TRUE(Utils::RectEqualTo(window, Utils::tripleTileRects_[0])); + ASSERT_TRUE(Utils::RectEqualTo(test1, Utils::tripleTileRects_[1])); + ASSERT_TRUE(Utils::RectEqualTo(test2, Utils::tripleTileRects_[2])); // 2 is second rect idx WindowManager::GetInstance().SetWindowLayoutMode(WindowLayoutMode::CASCADE); } @@ -476,7 +476,7 @@ HWTEST_F(WindowLayoutTest, LayoutTileNegative01, Function | MediumTest | Level3) */ HWTEST_F(WindowLayoutTest, LayoutNegative01, Function | MediumTest | Level3) { - utils::TestWindowInfo info = { + Utils::TestWindowInfo info = { .name = "main", .rect = {0, 0, 0, 0}, .type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, @@ -485,12 +485,12 @@ HWTEST_F(WindowLayoutTest, LayoutNegative01, Function | MediumTest | Level3) .parentLimit = false, .parentName = "", }; - const sptr& window = utils::CreateTestWindow(info); + const sptr& window = Utils::CreateTestWindow(info); activeWindows_.push_back(window); - Rect expect = utils::GetDefaultFloatingRect(window); + Rect expect = Utils::GetDefaultFloatingRect(window); ASSERT_EQ(WMError::WM_OK, window->Show()); usleep(WAIT_SYANC_US); - ASSERT_TRUE(utils::RectEqualTo(window, expect)); + ASSERT_TRUE(Utils::RectEqualTo(window, expect)); } /** @@ -502,7 +502,7 @@ HWTEST_F(WindowLayoutTest, LayoutNegative02, Function | MediumTest | Level3) { const uint32_t negativeW = 0; const uint32_t negativeH = 0; - utils::TestWindowInfo info = { + Utils::TestWindowInfo info = { .name = "main", .rect = {0, 0, 0, 0}, .type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, @@ -511,17 +511,17 @@ HWTEST_F(WindowLayoutTest, LayoutNegative02, Function | MediumTest | Level3) .parentLimit = false, .parentName = "", }; - const sptr& window = utils::CreateTestWindow(info); + const sptr& window = Utils::CreateTestWindow(info); activeWindows_.push_back(window); - Rect expect = utils::GetDefaultFloatingRect(window); + Rect expect = Utils::GetDefaultFloatingRect(window); ASSERT_EQ(WMError::WM_OK, window->Show()); usleep(WAIT_SYANC_US); - ASSERT_TRUE(utils::RectEqualTo(window, expect)); + ASSERT_TRUE(Utils::RectEqualTo(window, expect)); window->Resize(negativeW, negativeH); usleep(WAIT_SYANC_US); Rect expect2 = {expect.posX_, expect.posY_, negativeW, negativeH}; - expect2 = utils::CalcLimitedRect(expect2, virtualPixelRatio_); - ASSERT_TRUE(utils::RectEqualTo(window, expect2)); + expect2 = Utils::CalcLimitedRect(expect2, virtualPixelRatio_); + ASSERT_TRUE(Utils::RectEqualTo(window, expect2)); } } } // namespace Rosen diff --git a/wm/test/systemtest/window_mode_support_info_test.cpp b/wm/test/systemtest/window_mode_support_info_test.cpp index 94165378..10222bae 100644 --- a/wm/test/systemtest/window_mode_support_info_test.cpp +++ b/wm/test/systemtest/window_mode_support_info_test.cpp @@ -22,15 +22,15 @@ using namespace testing::ext; namespace OHOS { namespace Rosen { -using utils = WindowTestUtils; +using Utils = WindowTestUtils; class WindowModeSupportInfoTest : public testing::Test { public: static void SetUpTestCase(); static void TearDownTestCase(); virtual void SetUp() override; virtual void TearDown() override; - utils::TestWindowInfo fullAppInfo_1_; - utils::TestWindowInfo fullAppInfo_2_; + Utils::TestWindowInfo fullAppInfo_1_; + Utils::TestWindowInfo fullAppInfo_2_; private: static constexpr uint32_t WAIT_SYANC_US = 100000; }; @@ -40,7 +40,7 @@ void WindowModeSupportInfoTest::SetUpTestCase() auto display = DisplayManager::GetInstance().GetDisplayById(0); ASSERT_TRUE((display != nullptr)); Rect displayRect = {0, 0, display->GetWidth(), display->GetHeight()}; - utils::InitByDisplayRect(displayRect); + Utils::InitByDisplayRect(displayRect); } void WindowModeSupportInfoTest::TearDownTestCase() @@ -51,7 +51,7 @@ void WindowModeSupportInfoTest::SetUp() { fullAppInfo_1_ = { .name = "FullWindow", - .rect = utils::customAppRect_, + .rect = Utils::customAppRect_, .type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, .mode = WindowMode::WINDOW_MODE_FULLSCREEN, .needAvoid = false, @@ -60,7 +60,7 @@ void WindowModeSupportInfoTest::SetUp() }; fullAppInfo_2_ = { .name = "FullWindow2", - .rect = utils::customAppRect_, + .rect = Utils::customAppRect_, .type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, .mode = WindowMode::WINDOW_MODE_FULLSCREEN, .needAvoid = false, @@ -81,7 +81,7 @@ namespace { */ HWTEST_F(WindowModeSupportInfoTest, WindowModeSupportInfo01, Function | MediumTest | Level3) { - const sptr& window = utils::CreateTestWindow(fullAppInfo_1_); + const sptr& window = Utils::CreateTestWindow(fullAppInfo_1_); window->SetModeSupportInfo(WindowModeSupport::WINDOW_MODE_SUPPORT_FULLSCREEN); ASSERT_EQ(WindowModeSupport::WINDOW_MODE_SUPPORT_FULLSCREEN, window->GetModeSupportInfo()); @@ -95,7 +95,7 @@ HWTEST_F(WindowModeSupportInfoTest, WindowModeSupportInfo01, Function | MediumTe */ HWTEST_F(WindowModeSupportInfoTest, WindowModeSupportInfo02, Function | MediumTest | Level3) { - const sptr& window = utils::CreateTestWindow(fullAppInfo_1_); + const sptr& window = Utils::CreateTestWindow(fullAppInfo_1_); window->SetModeSupportInfo(WindowModeSupport::WINDOW_MODE_SUPPORT_FULLSCREEN); ASSERT_EQ(WMError::WM_OK, window->Show()); @@ -127,7 +127,7 @@ HWTEST_F(WindowModeSupportInfoTest, WindowModeSupportInfo02, Function | MediumTe */ HWTEST_F(WindowModeSupportInfoTest, WindowModeSupportInfo03, Function | MediumTest | Level3) { - const sptr& window = utils::CreateTestWindow(fullAppInfo_1_); + const sptr& window = Utils::CreateTestWindow(fullAppInfo_1_); window->SetModeSupportInfo(WindowModeSupport::WINDOW_MODE_SUPPORT_FULLSCREEN | WindowModeSupport::WINDOW_MODE_SUPPORT_FLOATING); @@ -165,7 +165,7 @@ HWTEST_F(WindowModeSupportInfoTest, WindowModeSupportInfo03, Function | MediumTe */ HWTEST_F(WindowModeSupportInfoTest, WindowModeSupportInfo04, Function | MediumTest | Level3) { - const sptr& window = utils::CreateTestWindow(fullAppInfo_1_); + const sptr& window = Utils::CreateTestWindow(fullAppInfo_1_); window->SetModeSupportInfo(WindowModeSupport::WINDOW_MODE_SUPPORT_FLOATING | WindowModeSupport::WINDOW_MODE_SUPPORT_SPLIT_PRIMARY | WindowModeSupport::WINDOW_MODE_SUPPORT_SPLIT_SECONDARY); @@ -189,9 +189,9 @@ HWTEST_F(WindowModeSupportInfoTest, WindowModeSupportInfo04, Function | MediumTe */ HWTEST_F(WindowModeSupportInfoTest, WindowModeSupportInfo05, Function | MediumTest | Level3) { - const sptr& window1 = utils::CreateTestWindow(fullAppInfo_1_); + const sptr& window1 = Utils::CreateTestWindow(fullAppInfo_1_); window1->SetModeSupportInfo(WindowModeSupport::WINDOW_MODE_SUPPORT_FULLSCREEN); - const sptr& window2 = utils::CreateTestWindow(fullAppInfo_2_); + const sptr& window2 = Utils::CreateTestWindow(fullAppInfo_2_); window2->SetModeSupportInfo(WindowModeSupport::WINDOW_MODE_SUPPORT_ALL); ASSERT_EQ(WMError::WM_OK, window1->Show()); ASSERT_EQ(WMError::WM_OK, window2->Show()); @@ -212,7 +212,7 @@ HWTEST_F(WindowModeSupportInfoTest, WindowModeSupportInfo05, Function | MediumTe */ HWTEST_F(WindowModeSupportInfoTest, WindowModeSupportInfo06, Function | MediumTest | Level3) { - const sptr& window = utils::CreateTestWindow(fullAppInfo_1_); + const sptr& window = Utils::CreateTestWindow(fullAppInfo_1_); window->SetModeSupportInfo(WindowModeSupport::WINDOW_MODE_SUPPORT_FULLSCREEN); ASSERT_EQ(WMError::WM_OK, window->Show()); WindowManager::GetInstance().SetWindowLayoutMode(WindowLayoutMode::TILE); @@ -232,9 +232,9 @@ HWTEST_F(WindowModeSupportInfoTest, WindowModeSupportInfo06, Function | MediumTe */ HWTEST_F(WindowModeSupportInfoTest, WindowModeSupportInfo07, Function | MediumTest | Level3) { - const sptr& window1 = utils::CreateTestWindow(fullAppInfo_1_); + const sptr& window1 = Utils::CreateTestWindow(fullAppInfo_1_); window1->SetModeSupportInfo(WindowModeSupport::WINDOW_MODE_SUPPORT_ALL); - const sptr& window2 = utils::CreateTestWindow(fullAppInfo_2_); + const sptr& window2 = Utils::CreateTestWindow(fullAppInfo_2_); window2->SetModeSupportInfo(WindowModeSupport::WINDOW_MODE_SUPPORT_FULLSCREEN); ASSERT_EQ(WMError::WM_OK, window1->Show()); ASSERT_EQ(WMError::WM_OK, window2->Show()); diff --git a/wm/test/systemtest/window_move_drag_test.cpp b/wm/test/systemtest/window_move_drag_test.cpp index 214865ea..6b0de20f 100644 --- a/wm/test/systemtest/window_move_drag_test.cpp +++ b/wm/test/systemtest/window_move_drag_test.cpp @@ -30,7 +30,7 @@ namespace { constexpr float DRAG_HOTZONE_RATIO = 0.6; constexpr int WAIT_SYANC_MS = 100000; } -using utils = WindowTestUtils; +using Utils = WindowTestUtils; class WindowMoveDragTest : public testing::Test { public: static void SetUpTestCase(); @@ -81,7 +81,7 @@ void WindowMoveDragTest::SetUp() WLOGFI("GetDefaultDisplay: id %{public}llu, w %{public}d, h %{public}d, fps %{public}u\n", (unsigned long long)display->GetId(), display->GetWidth(), display->GetHeight(), display->GetRefreshRate()); Rect displayRect = {0, 0, display->GetWidth(), display->GetHeight()}; - utils::InitByDisplayRect(displayRect); + Utils::InitByDisplayRect(displayRect); virtualPixelRatio_ = WindowTestUtils::GetVirtualPixelRatio(0); hotZone_ = static_cast(HOTZONE * virtualPixelRatio_); @@ -127,19 +127,19 @@ void WindowMoveDragTest::DoMoveOrDrag(bool isMove, bool isDrag) std::shared_ptr pointerEvent = CreatePointerEvent(startPointX_, startPointY_, pointerId_, MMI::PointerEvent::POINTER_ACTION_DOWN); window_->ConsumePointerEvent(pointerEvent); - ASSERT_TRUE(utils::RectEqualToRect(window_->GetRect(), startPointRect_)); + ASSERT_TRUE(Utils::RectEqualToRect(window_->GetRect(), startPointRect_)); pointerEvent = CreatePointerEvent(pointX_, pointY_, pointerId_, MMI::PointerEvent::POINTER_ACTION_MOVE); window_->ConsumePointerEvent(pointerEvent); CalExpectRects(); usleep(WAIT_SYANC_MS); - ASSERT_TRUE(utils::RectEqualToRect(window_->GetRect(), expectRect_)); + ASSERT_TRUE(Utils::RectEqualToRect(window_->GetRect(), expectRect_)); ASSERT_EQ(isMove, window_->startMoveFlag_); ASSERT_EQ(isDrag, window_->startDragFlag_); pointerEvent = CreatePointerEvent(pointX_, pointY_, pointerId_, MMI::PointerEvent::POINTER_ACTION_UP); window_->ConsumePointerEvent(pointerEvent); - ASSERT_TRUE(utils::RectEqualToRect(window_->GetRect(), expectRect_)); + ASSERT_TRUE(Utils::RectEqualToRect(window_->GetRect(), expectRect_)); } void WindowMoveDragTest::CalExpectRects() @@ -180,7 +180,7 @@ void WindowMoveDragTest::CalExpectRects() hasStartMove_ = false; } } - bool isVertical = (utils::displayRect_.width_ < utils::displayRect_.height_) ? true : false; + bool isVertical = (Utils::displayRect_.width_ < Utils::displayRect_.height_) ? true : false; expectRect_ = WindowHelper::GetFixedWindowRectByLimitSize(oriRect, startPointRect_, isVertical, virtualPixelRatio_); } diff --git a/wm/test/systemtest/window_multi_ability_test.cpp b/wm/test/systemtest/window_multi_ability_test.cpp index 48db7bc5..0d8c9811 100644 --- a/wm/test/systemtest/window_multi_ability_test.cpp +++ b/wm/test/systemtest/window_multi_ability_test.cpp @@ -23,7 +23,7 @@ using namespace testing::ext; namespace OHOS { namespace Rosen { -using utils = WindowTestUtils; +using Utils = WindowTestUtils; class WindowMultiAbilityTest : public testing::Test { public: static void SetUpTestCase(); @@ -54,7 +54,7 @@ static void ShowHideWindowSceneCallable(int i) { unsigned int sleepTimeMs = i * SLEEP_MS; usleep(sleepTimeMs); - sptr scene = utils::CreateWindowScene(); + sptr scene = Utils::CreateWindowScene(); const int loop = 10; int j = 0; for (; j < loop; j++) { @@ -74,7 +74,7 @@ static void CreateDestroyWindowSceneCallable(int i) int j = 0; for (; j < loop; j++) { usleep(sleepTimeMs); - sptr scene = utils::CreateWindowScene(); + sptr scene = Utils::CreateWindowScene(); usleep(sleepTimeMs); ASSERT_EQ(WMError::WM_OK, scene->GoForeground()); usleep(sleepTimeMs); @@ -94,11 +94,11 @@ static void CreateDestroyWindowSceneCallable(int i) */ HWTEST_F(WindowMultiAbilityTest, MultiAbilityWindow01, Function | MediumTest | Level2) { - sptr scene1 = utils::CreateWindowScene(); - sptr scene2 = utils::CreateWindowScene(); - sptr scene3 = utils::CreateWindowScene(); - sptr scene4 = utils::CreateWindowScene(); - sptr scene5 = utils::CreateWindowScene(); + sptr scene1 = Utils::CreateWindowScene(); + sptr scene2 = Utils::CreateWindowScene(); + sptr scene3 = Utils::CreateWindowScene(); + sptr scene4 = Utils::CreateWindowScene(); + sptr scene5 = Utils::CreateWindowScene(); ASSERT_EQ(WMError::WM_OK, scene1->GoForeground()); ASSERT_EQ(WMError::WM_OK, scene2->GoForeground()); @@ -162,27 +162,27 @@ HWTEST_F(WindowMultiAbilityTest, MultiAbilityWindow03, Function | MediumTest | L */ HWTEST_F(WindowMultiAbilityTest, MultiAbilityWindow04, Function | MediumTest | Level3) { - sptr scene1 = utils::CreateWindowScene(); + sptr scene1 = Utils::CreateWindowScene(); ASSERT_EQ(WMError::WM_OK, scene1->GoForeground()); ASSERT_EQ(WMError::WM_OK, scene1->GoBackground()); ASSERT_EQ(WMError::WM_OK, scene1->GoDestroy()); - sptr scene2 = utils::CreateWindowScene(); + sptr scene2 = Utils::CreateWindowScene(); ASSERT_EQ(WMError::WM_OK, scene2->GoForeground()); ASSERT_EQ(WMError::WM_OK, scene2->GoBackground()); ASSERT_EQ(WMError::WM_OK, scene2->GoDestroy()); - sptr scene3 = utils::CreateWindowScene(); + sptr scene3 = Utils::CreateWindowScene(); ASSERT_EQ(WMError::WM_OK, scene3->GoForeground()); ASSERT_EQ(WMError::WM_OK, scene3->GoBackground()); ASSERT_EQ(WMError::WM_OK, scene3->GoDestroy()); - sptr scene4 = utils::CreateWindowScene(); + sptr scene4 = Utils::CreateWindowScene(); ASSERT_EQ(WMError::WM_OK, scene4->GoForeground()); ASSERT_EQ(WMError::WM_OK, scene4->GoBackground()); ASSERT_EQ(WMError::WM_OK, scene4->GoDestroy()); - sptr scene5 = utils::CreateWindowScene(); + sptr scene5 = Utils::CreateWindowScene(); ASSERT_EQ(WMError::WM_OK, scene5->GoForeground()); ASSERT_EQ(WMError::WM_OK, scene5->GoBackground()); ASSERT_EQ(WMError::WM_OK, scene5->GoDestroy()); @@ -195,19 +195,19 @@ HWTEST_F(WindowMultiAbilityTest, MultiAbilityWindow04, Function | MediumTest | L */ HWTEST_F(WindowMultiAbilityTest, MultiAbilityWindow05, Function | MediumTest | Level3) { - sptr scene1 = utils::CreateWindowScene(); + sptr scene1 = Utils::CreateWindowScene(); ASSERT_EQ(WMError::WM_OK, scene1->GoForeground()); - sptr scene2 = utils::CreateWindowScene(); - sptr scene3 = utils::CreateWindowScene(); + sptr scene2 = Utils::CreateWindowScene(); + sptr scene3 = Utils::CreateWindowScene(); ASSERT_EQ(WMError::WM_OK, scene3->GoForeground()); ASSERT_EQ(WMError::WM_OK, scene1->GoBackground()); ASSERT_EQ(WMError::WM_OK, scene1->GoDestroy()); - sptr scene4 = utils::CreateWindowScene(); + sptr scene4 = Utils::CreateWindowScene(); ASSERT_EQ(WMError::WM_OK, scene3->GoBackground()); ASSERT_EQ(WMError::WM_OK, scene2->GoForeground()); ASSERT_EQ(WMError::WM_OK, scene4->GoForeground()); ASSERT_EQ(WMError::WM_OK, scene2->GoBackground()); - sptr scene5 = utils::CreateWindowScene(); + sptr scene5 = Utils::CreateWindowScene(); ASSERT_EQ(WMError::WM_OK, scene3->GoDestroy()); ASSERT_EQ(WMError::WM_OK, scene5->GoForeground()); ASSERT_EQ(WMError::WM_OK, scene5->GoBackground()); diff --git a/wm/test/systemtest/window_occupied_area_change_test.cpp b/wm/test/systemtest/window_occupied_area_change_test.cpp index 4fea3ec0..8162cb9b 100644 --- a/wm/test/systemtest/window_occupied_area_change_test.cpp +++ b/wm/test/systemtest/window_occupied_area_change_test.cpp @@ -26,7 +26,7 @@ namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowOccupiedAreaChangeTest"}; } -using utils = WindowTestUtils; +using Utils = WindowTestUtils; const int WAIT_ASYNC_US = 100000; // 100000us class TestOccupiedAreaChangeListener : public IOccupiedAreaChangeListener { @@ -43,8 +43,8 @@ public: virtual void SetUp() override; virtual void TearDown() override; static sptr testOccupiedAreaChangeListener_; - utils::TestWindowInfo fullScreenAppInfo_; - utils::TestWindowInfo imeAppInfo_; + Utils::TestWindowInfo fullScreenAppInfo_; + Utils::TestWindowInfo imeAppInfo_; }; sptr WindowOccupiedAreaChangeTest::testOccupiedAreaChangeListener_ = @@ -65,7 +65,7 @@ void WindowOccupiedAreaChangeTest::SetUpTestCase() WLOGFI("GetDefaultDisplay: id %{public}" PRIu64", w %{public}d, h %{public}d, fps %{public}u", display->GetId(), display->GetWidth(), display->GetHeight(), display->GetRefreshRate()); Rect displayRect = {0, 0, display->GetWidth(), display->GetHeight()}; - utils::InitByDisplayRect(displayRect); + Utils::InitByDisplayRect(displayRect); } void WindowOccupiedAreaChangeTest::TearDownTestCase() @@ -76,7 +76,7 @@ void WindowOccupiedAreaChangeTest::SetUp() { fullScreenAppInfo_ = { .name = "FullWindow", - .rect = utils::customAppRect_, + .rect = Utils::customAppRect_, .type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, .mode = WindowMode::WINDOW_MODE_FULLSCREEN, .needAvoid = false, @@ -85,7 +85,7 @@ void WindowOccupiedAreaChangeTest::SetUp() }; imeAppInfo_ = { .name = "ImeWindow", - .rect = utils::customAppRect_, + .rect = Utils::customAppRect_, .type = WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT, .mode = WindowMode::WINDOW_MODE_FLOATING, }; @@ -104,13 +104,13 @@ namespace { HWTEST_F(WindowOccupiedAreaChangeTest, KeyboardHeightChangeTest01, Function | MediumTest | Level3) { fullScreenAppInfo_.name = "KeyboardHeightChangeTest01"; - const sptr& window1 = utils::CreateTestWindow(fullScreenAppInfo_); + const sptr& window1 = Utils::CreateTestWindow(fullScreenAppInfo_); ASSERT_NE(nullptr, window1); window1->RegisterOccupiedAreaChangeListener(testOccupiedAreaChangeListener_); imeAppInfo_.name = "imeWindow1"; imeAppInfo_.rect = { 10, 200, 300, 400 }; - const sptr& window2 = utils::CreateTestWindow(imeAppInfo_); + const sptr& window2 = Utils::CreateTestWindow(imeAppInfo_); ASSERT_NE(nullptr, window2); ASSERT_EQ(WMError::WM_OK, window1->Show()); @@ -133,13 +133,13 @@ HWTEST_F(WindowOccupiedAreaChangeTest, KeyboardHeightChangeTest01, Function | Me HWTEST_F(WindowOccupiedAreaChangeTest, KeyboardHeightChangeTest02, Function | MediumTest | Level3) { fullScreenAppInfo_.name = "KeyboardHeightChangeTest02"; - const sptr& window1 = utils::CreateTestWindow(fullScreenAppInfo_); + const sptr& window1 = Utils::CreateTestWindow(fullScreenAppInfo_); ASSERT_NE(nullptr, window1); window1->RegisterOccupiedAreaChangeListener(testOccupiedAreaChangeListener_); imeAppInfo_.name = "imeWindow2"; imeAppInfo_.rect = { 10, 200, 300, 400 }; - const sptr& window2 = utils::CreateTestWindow(imeAppInfo_); + const sptr& window2 = Utils::CreateTestWindow(imeAppInfo_); ASSERT_NE(nullptr, window2); ASSERT_EQ(WMError::WM_OK, window1->Show()); @@ -162,13 +162,13 @@ HWTEST_F(WindowOccupiedAreaChangeTest, KeyboardHeightChangeTest02, Function | Me HWTEST_F(WindowOccupiedAreaChangeTest, KeyboardHeightChangeTest03, Function | MediumTest | Level3) { fullScreenAppInfo_.name = "KeyboardHeightChangeTest03"; - const sptr& window1 = utils::CreateTestWindow(fullScreenAppInfo_); + const sptr& window1 = Utils::CreateTestWindow(fullScreenAppInfo_); ASSERT_NE(nullptr, window1); window1->RegisterOccupiedAreaChangeListener(testOccupiedAreaChangeListener_); imeAppInfo_.name = "imeWindow3"; imeAppInfo_.rect = { 10, 200, 300, 400 }; - const sptr& window2 = utils::CreateTestWindow(imeAppInfo_); + const sptr& window2 = Utils::CreateTestWindow(imeAppInfo_); ASSERT_NE(nullptr, window2); ASSERT_EQ(WMError::WM_OK, window1->Show()); diff --git a/wm/test/systemtest/window_rotation_test.cpp b/wm/test/systemtest/window_rotation_test.cpp index 5b6d390a..b2bab19c 100644 --- a/wm/test/systemtest/window_rotation_test.cpp +++ b/wm/test/systemtest/window_rotation_test.cpp @@ -27,7 +27,7 @@ using namespace testing::ext; namespace OHOS { namespace Rosen { -using utils = WindowTestUtils; +using Utils = WindowTestUtils; class DisplayListener : public DisplayManager::IDisplayListener { public: virtual void OnCreate(DisplayId) override; @@ -51,7 +51,7 @@ public: virtual void SetUp() override; virtual void TearDown() override; std::vector> activeWindows_; - utils::TestWindowInfo fullInfo_; + Utils::TestWindowInfo fullInfo_; sptr displayListener_; sptr screenListener_; private: @@ -97,7 +97,7 @@ void WindowRotationTest::SetUp() { fullInfo_ = { .name = "", - .rect = utils::customAppRect_, + .rect = Utils::customAppRect_, .type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, .mode = WindowMode::WINDOW_MODE_FULLSCREEN, .needAvoid = true, @@ -132,7 +132,7 @@ HWTEST_F(WindowRotationTest, WindowRotationTest1, Function | MediumTest | Level3 { fullInfo_.name = "fullscreen.1"; fullInfo_.orientation_ = Orientation::UNSPECIFIED; - const sptr& fullWindow = utils::CreateTestWindow(fullInfo_); + const sptr& fullWindow = Utils::CreateTestWindow(fullInfo_); activeWindows_.push_back(fullWindow); ASSERT_EQ(WMError::WM_OK, fullWindow->Show()); ASSERT_EQ(WindowMode::WINDOW_MODE_FULLSCREEN, fullWindow->GetMode()); @@ -163,7 +163,7 @@ HWTEST_F(WindowRotationTest, WindowRotationTest2, Function | MediumTest | Level3 { fullInfo_.name = "fullscreen.2"; fullInfo_.orientation_ = Orientation::REVERSE_HORIZONTAL; - const sptr& fullWindow = utils::CreateTestWindow(fullInfo_); + const sptr& fullWindow = Utils::CreateTestWindow(fullInfo_); activeWindows_.push_back(fullWindow); ASSERT_EQ(WMError::WM_OK, fullWindow->Show()); ASSERT_EQ(WindowMode::WINDOW_MODE_FULLSCREEN, fullWindow->GetMode()); @@ -201,7 +201,7 @@ HWTEST_F(WindowRotationTest, WindowRotationTest3, Function | MediumTest | Level3 fullInfo_.name = "fullscreen.4"; fullInfo_.orientation_ = Orientation::REVERSE_HORIZONTAL; fullInfo_.mode = WindowMode::WINDOW_MODE_FLOATING; - const sptr& fullWindow = utils::CreateTestWindow(fullInfo_); + const sptr& fullWindow = Utils::CreateTestWindow(fullInfo_); fullInfo_.mode = WindowMode::WINDOW_MODE_FULLSCREEN; activeWindows_.push_back(fullWindow); ASSERT_EQ(WMError::WM_OK, fullWindow->Show()); @@ -233,7 +233,7 @@ HWTEST_F(WindowRotationTest, WindowRotationTest4, Function | MediumTest | Level3 defaultScreen->SetOrientation(Orientation::REVERSE_HORIZONTAL); fullInfo_.name = "fullscreen.5"; fullInfo_.orientation_ = Orientation::HORIZONTAL; - const sptr& fullWindow = utils::CreateTestWindow(fullInfo_); + const sptr& fullWindow = Utils::CreateTestWindow(fullInfo_); activeWindows_.push_back(fullWindow); ASSERT_EQ(WMError::WM_OK, fullWindow->Show()); ASSERT_EQ(WindowMode::WINDOW_MODE_FULLSCREEN, fullWindow->GetMode()); @@ -276,7 +276,7 @@ HWTEST_F(WindowRotationTest, WindowRotationTest5, Function | MediumTest | Level3 defaultScreen->SetOrientation(Orientation::REVERSE_HORIZONTAL); fullInfo_.name = "fullscreen.5"; fullInfo_.orientation_ = Orientation::HORIZONTAL; - const sptr& fullWindow = utils::CreateTestWindow(fullInfo_); + const sptr& fullWindow = Utils::CreateTestWindow(fullInfo_); activeWindows_.push_back(fullWindow); ASSERT_EQ(WMError::WM_OK, fullWindow->Show()); ASSERT_EQ(WindowMode::WINDOW_MODE_FULLSCREEN, fullWindow->GetMode()); diff --git a/wm/test/systemtest/window_split_immersive_test.cpp b/wm/test/systemtest/window_split_immersive_test.cpp index 61b305f8..7a899cb5 100644 --- a/wm/test/systemtest/window_split_immersive_test.cpp +++ b/wm/test/systemtest/window_split_immersive_test.cpp @@ -23,7 +23,7 @@ using namespace testing::ext; namespace OHOS { namespace Rosen { -using utils = WindowTestUtils; +using Utils = WindowTestUtils; class WindowSplitImmersiveTest : public testing::Test { public: @@ -35,8 +35,8 @@ public: void HideAndUnregister(const sptr& fullWindow, const sptr& priWindow, const sptr& top); std::vector> activeWindows_; - utils::TestWindowInfo fullInfo_; - utils::TestWindowInfo splitInfo_; + Utils::TestWindowInfo fullInfo_; + Utils::TestWindowInfo splitInfo_; private: static constexpr uint32_t SPLIT_TEST_SLEEP_S = 1; // split test sleep time @@ -54,7 +54,7 @@ void WindowSplitImmersiveTest::SetUp() { fullInfo_ = { .name = "fullscreen.1", - .rect = utils::customAppRect_, + .rect = Utils::customAppRect_, .type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, .mode = WindowMode::WINDOW_MODE_FULLSCREEN, .needAvoid = true, @@ -64,7 +64,7 @@ void WindowSplitImmersiveTest::SetUp() splitInfo_ = { .name = "primary.1", - .rect = utils::customAppRect_, + .rect = Utils::customAppRect_, .type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, .mode = WindowMode::WINDOW_MODE_FULLSCREEN, .needAvoid = true, @@ -92,14 +92,14 @@ namespace { HWTEST_F(WindowSplitImmersiveTest, SplitImmersive01, Function | MediumTest | Level3) { // create fullscreen win and show - const sptr& fullWindow = utils::CreateTestWindow(fullInfo_); + const sptr& fullWindow = Utils::CreateTestWindow(fullInfo_); activeWindows_.push_back(fullWindow); ASSERT_EQ(WMError::WM_OK, fullWindow->Show()); sleep(SPLIT_TEST_SLEEP_S); // enter split mode splitInfo_.mode = WindowMode::WINDOW_MODE_SPLIT_PRIMARY; - const sptr& priWindow = utils::CreateTestWindow(splitInfo_); + const sptr& priWindow = Utils::CreateTestWindow(splitInfo_); activeWindows_.push_back(priWindow); ASSERT_EQ(WMError::WM_OK, priWindow->Show()); sleep(SPLIT_TEST_SLEEP_S); diff --git a/wm/test/systemtest/window_split_test.cpp b/wm/test/systemtest/window_split_test.cpp index 4bb0413f..18ce4183 100644 --- a/wm/test/systemtest/window_split_test.cpp +++ b/wm/test/systemtest/window_split_test.cpp @@ -21,7 +21,7 @@ using namespace testing::ext; namespace OHOS { namespace Rosen { -using utils = WindowTestUtils; +using Utils = WindowTestUtils; class WindowSplitTest : public testing::Test { public: static void SetUpTestCase(); @@ -29,8 +29,8 @@ public: virtual void SetUp() override; virtual void TearDown() override; std::vector> activeWindows_; - utils::TestWindowInfo fullInfo_; - utils::TestWindowInfo splitInfo_; + Utils::TestWindowInfo fullInfo_; + Utils::TestWindowInfo splitInfo_; private: static constexpr uint32_t SPLIT_TEST_SLEEP_S = 1; // split test sleep time @@ -48,7 +48,7 @@ void WindowSplitTest::SetUp() { fullInfo_ = { .name = "", - .rect = utils::customAppRect_, + .rect = Utils::customAppRect_, .type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, .mode = WindowMode::WINDOW_MODE_FULLSCREEN, .needAvoid = true, @@ -58,7 +58,7 @@ void WindowSplitTest::SetUp() splitInfo_ = { .name = "", - .rect = utils::customAppRect_, + .rect = Utils::customAppRect_, .type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, .mode = WindowMode::WINDOW_MODE_FULLSCREEN, .needAvoid = true, @@ -89,12 +89,12 @@ HWTEST_F(WindowSplitTest, SplitWindow01, Function | MediumTest | Level3) splitInfo_.name = "primary.1"; splitInfo_.mode = WindowMode::WINDOW_MODE_SPLIT_PRIMARY; - const sptr& fullWindow = utils::CreateTestWindow(fullInfo_); + const sptr& fullWindow = Utils::CreateTestWindow(fullInfo_); activeWindows_.push_back(fullWindow); ASSERT_EQ(WMError::WM_OK, fullWindow->Show()); sleep(SPLIT_TEST_SLEEP_S); - const sptr& priWindow = utils::CreateTestWindow(splitInfo_); + const sptr& priWindow = Utils::CreateTestWindow(splitInfo_); activeWindows_.push_back(priWindow); ASSERT_EQ(WMError::WM_OK, priWindow->Show()); sleep(SPLIT_TEST_SLEEP_S); @@ -120,11 +120,11 @@ HWTEST_F(WindowSplitTest, SplitWindow02, Function | MediumTest | Level3) splitInfo_.name = "secondary.2"; splitInfo_.mode = WindowMode::WINDOW_MODE_SPLIT_SECONDARY; - const sptr& fullWindow = utils::CreateTestWindow(fullInfo_); + const sptr& fullWindow = Utils::CreateTestWindow(fullInfo_); activeWindows_.push_back(fullWindow); ASSERT_EQ(WMError::WM_OK, fullWindow->Show()); sleep(SPLIT_TEST_SLEEP_S); - const sptr& secWindow = utils::CreateTestWindow(splitInfo_); + const sptr& secWindow = Utils::CreateTestWindow(splitInfo_); activeWindows_.push_back(secWindow); ASSERT_EQ(WMError::WM_OK, secWindow->Show()); sleep(SPLIT_TEST_SLEEP_S); @@ -150,21 +150,21 @@ HWTEST_F(WindowSplitTest, SplitScreen03, Function | MediumTest | Level3) splitInfo_.name = "primary.3"; splitInfo_.mode = WindowMode::WINDOW_MODE_SPLIT_PRIMARY; - ASSERT_TRUE(utils::InitSplitRects()); + ASSERT_TRUE(Utils::InitSplitRects()); - const sptr& fullWindow = utils::CreateTestWindow(fullInfo_); + const sptr& fullWindow = Utils::CreateTestWindow(fullInfo_); activeWindows_.push_back(fullWindow); ASSERT_EQ(WMError::WM_OK, fullWindow->Show()); sleep(SPLIT_TEST_SLEEP_S); - const sptr& priWindow = utils::CreateTestWindow(splitInfo_); + const sptr& priWindow = Utils::CreateTestWindow(splitInfo_); activeWindows_.push_back(priWindow); ASSERT_EQ(WMError::WM_OK, priWindow->Show()); sleep(SPLIT_TEST_SLEEP_S); - utils::UpdateSplitRects(fullWindow); + Utils::UpdateSplitRects(fullWindow); - ASSERT_TRUE(utils::RectEqualTo(fullWindow, utils::splitRects_.secondaryRect)); - ASSERT_TRUE(utils::RectEqualTo(priWindow, utils::splitRects_.primaryRect)); + ASSERT_TRUE(Utils::RectEqualTo(fullWindow, Utils::splitRects_.secondaryRect)); + ASSERT_TRUE(Utils::RectEqualTo(priWindow, Utils::splitRects_.primaryRect)); ASSERT_EQ(WMError::WM_OK, fullWindow->Hide()); sleep(SPLIT_TEST_SLEEP_S); @@ -183,21 +183,21 @@ HWTEST_F(WindowSplitTest, SplitScreen04, Function | MediumTest | Level3) splitInfo_.name = "secondary.4"; splitInfo_.mode = WindowMode::WINDOW_MODE_SPLIT_SECONDARY; - ASSERT_TRUE(utils::InitSplitRects()); + ASSERT_TRUE(Utils::InitSplitRects()); - const sptr& fullWindow = utils::CreateTestWindow(fullInfo_); + const sptr& fullWindow = Utils::CreateTestWindow(fullInfo_); activeWindows_.push_back(fullWindow); ASSERT_EQ(WMError::WM_OK, fullWindow->Show()); sleep(SPLIT_TEST_SLEEP_S); - const sptr& secWindow = utils::CreateTestWindow(splitInfo_); + const sptr& secWindow = Utils::CreateTestWindow(splitInfo_); activeWindows_.push_back(secWindow); ASSERT_EQ(WMError::WM_OK, secWindow->Show()); sleep(SPLIT_TEST_SLEEP_S); - utils::UpdateSplitRects(fullWindow); + Utils::UpdateSplitRects(fullWindow); - ASSERT_TRUE(utils::RectEqualTo(fullWindow, utils::splitRects_.primaryRect)); - ASSERT_TRUE(utils::RectEqualTo(secWindow, utils::splitRects_.secondaryRect)); + ASSERT_TRUE(Utils::RectEqualTo(fullWindow, Utils::splitRects_.primaryRect)); + ASSERT_TRUE(Utils::RectEqualTo(secWindow, Utils::splitRects_.secondaryRect)); ASSERT_EQ(WMError::WM_OK, fullWindow->Hide()); sleep(SPLIT_TEST_SLEEP_S); @@ -216,12 +216,12 @@ HWTEST_F(WindowSplitTest, SplitScreen05, Function | MediumTest | Level3) splitInfo_.name = "primary.5"; splitInfo_.mode = WindowMode::WINDOW_MODE_SPLIT_PRIMARY; - const sptr& fullWindow = utils::CreateTestWindow(fullInfo_); + const sptr& fullWindow = Utils::CreateTestWindow(fullInfo_); activeWindows_.push_back(fullWindow); ASSERT_EQ(WMError::WM_OK, fullWindow->Show()); sleep(SPLIT_TEST_SLEEP_S); - const sptr& priWindow = utils::CreateTestWindow(splitInfo_); + const sptr& priWindow = Utils::CreateTestWindow(splitInfo_); activeWindows_.push_back(priWindow); ASSERT_EQ(WMError::WM_OK, priWindow->Show()); sleep(SPLIT_TEST_SLEEP_S); @@ -229,13 +229,13 @@ HWTEST_F(WindowSplitTest, SplitScreen05, Function | MediumTest | Level3) ASSERT_EQ(WindowMode::WINDOW_MODE_SPLIT_PRIMARY, priWindow->GetMode()); ASSERT_EQ(WindowMode::WINDOW_MODE_SPLIT_SECONDARY, fullWindow->GetMode()); - utils::TestWindowInfo dividerInfo; + Utils::TestWindowInfo dividerInfo; dividerInfo.name = "divider0"; dividerInfo.type = WindowType::WINDOW_TYPE_DOCK_SLICE; dividerInfo.mode = WindowMode::WINDOW_MODE_FLOATING; dividerInfo.focusable_ = false; - const sptr& divider = utils::CreateTestWindow(dividerInfo); + const sptr& divider = Utils::CreateTestWindow(dividerInfo); activeWindows_.push_back(divider); ASSERT_EQ(WMError::WM_OK, divider->Show()); sleep(SPLIT_TEST_SLEEP_S); @@ -271,23 +271,23 @@ HWTEST_F(WindowSplitTest, SplitScreen06, Function | MediumTest | Level3) splitInfo_.name = "primary.6"; splitInfo_.mode = WindowMode::WINDOW_MODE_SPLIT_PRIMARY; - const sptr& fullWindow = utils::CreateTestWindow(fullInfo_); + const sptr& fullWindow = Utils::CreateTestWindow(fullInfo_); activeWindows_.push_back(fullWindow); ASSERT_EQ(WMError::WM_OK, fullWindow->Show()); sleep(SPLIT_TEST_SLEEP_S); - const sptr& priWindow = utils::CreateTestWindow(splitInfo_); + const sptr& priWindow = Utils::CreateTestWindow(splitInfo_); activeWindows_.push_back(priWindow); ASSERT_EQ(WMError::WM_OK, priWindow->Show()); sleep(SPLIT_TEST_SLEEP_S); - utils::TestWindowInfo dividerInfo; + Utils::TestWindowInfo dividerInfo; dividerInfo.name = "divider0"; dividerInfo.type = WindowType::WINDOW_TYPE_DOCK_SLICE; dividerInfo.mode = WindowMode::WINDOW_MODE_FLOATING; dividerInfo.focusable_ = false; - const sptr& divider = utils::CreateTestWindow(dividerInfo); + const sptr& divider = Utils::CreateTestWindow(dividerInfo); activeWindows_.push_back(divider); ASSERT_EQ(WMError::WM_OK, divider->Show()); sleep(SPLIT_TEST_SLEEP_S); @@ -297,7 +297,7 @@ HWTEST_F(WindowSplitTest, SplitScreen06, Function | MediumTest | Level3) int32_t posX, posY; posX = posY = 0; std::shared_ptr pointerEvent = - utils::CreatePointerEvent(posX, posY, pointerId, MMI::PointerEvent::POINTER_ACTION_DOWN); + Utils::CreatePointerEvent(posX, posY, pointerId, MMI::PointerEvent::POINTER_ACTION_DOWN); divider->ConsumePointerEvent(pointerEvent); sleep(SPLIT_TEST_SLEEP_S); @@ -306,13 +306,13 @@ HWTEST_F(WindowSplitTest, SplitScreen06, Function | MediumTest | Level3) } else { posY += 10; } - pointerEvent = utils::CreatePointerEvent(posX, posY, pointerId, MMI::PointerEvent::POINTER_ACTION_MOVE); + pointerEvent = Utils::CreatePointerEvent(posX, posY, pointerId, MMI::PointerEvent::POINTER_ACTION_MOVE); divider->ConsumePointerEvent(pointerEvent); sleep(SPLIT_TEST_SLEEP_S); Rect moveRect = divider->GetRect(); ASSERT_TRUE(rect.posX_ != moveRect.posX_ || rect.posY_ != moveRect.posY_); - pointerEvent = utils::CreatePointerEvent(posX, posY, pointerId, MMI::PointerEvent::POINTER_ACTION_UP); + pointerEvent = Utils::CreatePointerEvent(posX, posY, pointerId, MMI::PointerEvent::POINTER_ACTION_UP); divider->ConsumePointerEvent(pointerEvent); sleep(SPLIT_TEST_SLEEP_S); Rect newRect = divider->GetRect(); diff --git a/wm/test/systemtest/window_touch_outside_test.cpp b/wm/test/systemtest/window_touch_outside_test.cpp index 0a4e197f..39b076e2 100644 --- a/wm/test/systemtest/window_touch_outside_test.cpp +++ b/wm/test/systemtest/window_touch_outside_test.cpp @@ -26,7 +26,7 @@ using namespace testing::ext; namespace OHOS { namespace Rosen { -using utils = WindowTestUtils; +using Utils = WindowTestUtils; const int WAIT_CALLBACK_US = 10000; // 10000 us class WindowTouchOutsideTestListener : public ITouchOutsideListener { @@ -47,9 +47,9 @@ public: static sptr windowlistener1_; static sptr windowlistener2_; - utils::TestWindowInfo firstWindowInfo_; - utils::TestWindowInfo secondWindowInfo_; - utils::TestWindowInfo thirdWindowInfo_; + Utils::TestWindowInfo firstWindowInfo_; + Utils::TestWindowInfo secondWindowInfo_; + Utils::TestWindowInfo thirdWindowInfo_; }; sptr WindowTouchOutsideTest::windowlistener1_ = @@ -112,7 +112,7 @@ namespace { */ HWTEST_F(WindowTouchOutsideTest, onTouchIutside, Function | MediumTest | Level3) { - const sptr &firstWindow = utils::CreateTestWindow(firstWindowInfo_); + const sptr &firstWindow = Utils::CreateTestWindow(firstWindowInfo_); firstWindow->RegisterTouchOutsideListener(windowlistener1_); firstWindow->Show(); SingletonContainer::Get().ProcessPointDown(firstWindow->GetWindowId()); @@ -128,9 +128,9 @@ HWTEST_F(WindowTouchOutsideTest, onTouchIutside, Function | MediumTest | Level3) */ HWTEST_F(WindowTouchOutsideTest, onTouchOutside, Function | MediumTest | Level3) { - const sptr &firstWindow = utils::CreateTestWindow(firstWindowInfo_); + const sptr &firstWindow = Utils::CreateTestWindow(firstWindowInfo_); firstWindow->RegisterTouchOutsideListener(windowlistener1_); - const sptr &secondWindow = utils::CreateTestWindow(secondWindowInfo_); + const sptr &secondWindow = Utils::CreateTestWindow(secondWindowInfo_); firstWindow->Show(); secondWindow->Show(); SingletonContainer::Get().ProcessPointDown(secondWindow->GetWindowId()); @@ -147,9 +147,9 @@ HWTEST_F(WindowTouchOutsideTest, onTouchOutside, Function | MediumTest | Level3) */ HWTEST_F(WindowTouchOutsideTest, onTouchOutsideNotShow, Function | MediumTest | Level3) { - const sptr &firstWindow = utils::CreateTestWindow(firstWindowInfo_); + const sptr &firstWindow = Utils::CreateTestWindow(firstWindowInfo_); firstWindow->RegisterTouchOutsideListener(windowlistener1_); - const sptr &secondWindow = utils::CreateTestWindow(secondWindowInfo_); + const sptr &secondWindow = Utils::CreateTestWindow(secondWindowInfo_); secondWindow->Show(); SingletonContainer::Get().ProcessPointDown(secondWindow->GetWindowId()); usleep(WAIT_CALLBACK_US); @@ -165,13 +165,13 @@ HWTEST_F(WindowTouchOutsideTest, onTouchOutsideNotShow, Function | MediumTest | */ HWTEST_F(WindowTouchOutsideTest, onTouchOutsideForAllWindow, Function | MediumTest | Level3) { - const sptr &firstWindow = utils::CreateTestWindow(firstWindowInfo_); + const sptr &firstWindow = Utils::CreateTestWindow(firstWindowInfo_); firstWindow->RegisterTouchOutsideListener(windowlistener1_); - const sptr &secondWindow = utils::CreateTestWindow(secondWindowInfo_); + const sptr &secondWindow = Utils::CreateTestWindow(secondWindowInfo_); firstWindow->RegisterTouchOutsideListener(windowlistener2_); firstWindow->Show(); secondWindow->Show(); - const sptr &thirdWindow = utils::CreateTestWindow(thirdWindowInfo_); + const sptr &thirdWindow = Utils::CreateTestWindow(thirdWindowInfo_); thirdWindow->Show(); SingletonContainer::Get().ProcessPointDown(thirdWindow->GetWindowId()); usleep(WAIT_CALLBACK_US); diff --git a/wm/test/systemtest/window_visibility_info_test.cpp b/wm/test/systemtest/window_visibility_info_test.cpp index 085583c8..1286ba4b 100644 --- a/wm/test/systemtest/window_visibility_info_test.cpp +++ b/wm/test/systemtest/window_visibility_info_test.cpp @@ -35,7 +35,7 @@ namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowVisibilityInfoTest"}; } -using utils = WindowTestUtils; +using Utils = WindowTestUtils; constexpr int WAIT_ASYNC_MS_TIME_OUT = 2000; // 2000ms #define CHECK_DISPLAY_POWER_STATE_RETURN() \ @@ -110,9 +110,9 @@ public: } static void WaitForCallback(); - utils::TestWindowInfo fullScreenAppInfo_; - utils::TestWindowInfo floatAppInfo_; - utils::TestWindowInfo subAppInfo_; + Utils::TestWindowInfo fullScreenAppInfo_; + Utils::TestWindowInfo floatAppInfo_; + Utils::TestWindowInfo subAppInfo_; }; void WindowVisibilityInfoTest::SetUpTestCase() @@ -123,7 +123,7 @@ void WindowVisibilityInfoTest::SetUpTestCase() display->GetId(), display->GetWidth(), display->GetHeight(), display->GetRefreshRate()); Rect displayRect = {0, 0, static_cast(display->GetWidth()), static_cast(display->GetHeight())}; - utils::InitByDisplayRect(displayRect); + Utils::InitByDisplayRect(displayRect); WindowManager::GetInstance().RegisterVisibilityChangedListener(visibilityChangedListener_); DisplayManager::GetInstance().RegisterDisplayPowerEventListener(displayPowerEventListener_); } @@ -138,7 +138,7 @@ void WindowVisibilityInfoTest::SetUp() { fullScreenAppInfo_ = { .name = "FullWindow", - .rect = utils::customAppRect_, + .rect = Utils::customAppRect_, .type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, .mode = WindowMode::WINDOW_MODE_FULLSCREEN, .needAvoid = false, @@ -147,7 +147,7 @@ void WindowVisibilityInfoTest::SetUp() }; floatAppInfo_ = { .name = "ParentWindow", - .rect = utils::customAppRect_, + .rect = Utils::customAppRect_, .type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, .mode = WindowMode::WINDOW_MODE_FLOATING, .needAvoid = false, @@ -156,7 +156,7 @@ void WindowVisibilityInfoTest::SetUp() }; subAppInfo_ = { .name = "SubWindow", - .rect = utils::customAppRect_, + .rect = Utils::customAppRect_, .type = WindowType::WINDOW_TYPE_APP_SUB_WINDOW, .mode = WindowMode::WINDOW_MODE_FLOATING, .needAvoid = false, @@ -189,12 +189,12 @@ HWTEST_F(WindowVisibilityInfoTest, WindowVisibilityInfoTest01, Function | Medium { floatAppInfo_.name = "window1"; floatAppInfo_.rect = {250, 150, 300, 500}; - sptr window1 = utils::CreateTestWindow(floatAppInfo_); + sptr window1 = Utils::CreateTestWindow(floatAppInfo_); subAppInfo_.name = "subWindow1"; subAppInfo_.rect = {400, 200, 100, 100}; subAppInfo_.parentName = window1->GetWindowName(); - sptr subWindow1 = utils::CreateTestWindow(subAppInfo_); + sptr subWindow1 = Utils::CreateTestWindow(subAppInfo_); ASSERT_EQ(WMError::WM_OK, window1->Show()); WaitForCallback(); @@ -251,10 +251,10 @@ end: HWTEST_F(WindowVisibilityInfoTest, WindowVisibilityInfoTest02, Function | MediumTest | Level1) { fullScreenAppInfo_.name = "window1"; - sptr window1 = utils::CreateTestWindow(fullScreenAppInfo_); + sptr window1 = Utils::CreateTestWindow(fullScreenAppInfo_); fullScreenAppInfo_.name = "window2"; - sptr window2 = utils::CreateTestWindow(fullScreenAppInfo_); + sptr window2 = Utils::CreateTestWindow(fullScreenAppInfo_); ASSERT_EQ(WMError::WM_OK, window1->Show()); WaitForCallback(); @@ -282,20 +282,20 @@ HWTEST_F(WindowVisibilityInfoTest, WindowVisibilityInfoTest03, Function | Medium { floatAppInfo_.name = "window1"; floatAppInfo_.rect = {0, 0, 300, 600}; - sptr window1 = utils::CreateTestWindow(floatAppInfo_); + sptr window1 = Utils::CreateTestWindow(floatAppInfo_); subAppInfo_.name = "subWindow1"; subAppInfo_.rect = {400, 200, 100, 100}; subAppInfo_.parentName = window1->GetWindowName(); - sptr subWindow1 = utils::CreateTestWindow(subAppInfo_); + sptr subWindow1 = Utils::CreateTestWindow(subAppInfo_); floatAppInfo_.name = "window2"; - sptr window2 = utils::CreateTestWindow(floatAppInfo_); + sptr window2 = Utils::CreateTestWindow(floatAppInfo_); subAppInfo_.name = "subWindow2"; subAppInfo_.type = WindowType::WINDOW_TYPE_MEDIA; subAppInfo_.parentName = window2->GetWindowName(); - sptr subWindow2 = utils::CreateTestWindow(subAppInfo_); + sptr subWindow2 = Utils::CreateTestWindow(subAppInfo_); ASSERT_EQ(WMError::WM_OK, window2->Show()); WaitForCallback(); @@ -337,15 +337,15 @@ HWTEST_F(WindowVisibilityInfoTest, WindowVisibilityInfoTest04, Function | Medium { floatAppInfo_.name = "window1"; floatAppInfo_.rect = {0, 0, 300, 600}; - sptr window1 = utils::CreateTestWindow(floatAppInfo_); + sptr window1 = Utils::CreateTestWindow(floatAppInfo_); floatAppInfo_.name = "window2"; floatAppInfo_.rect = {0, 0, 300, 300}; - sptr window2 = utils::CreateTestWindow(floatAppInfo_); + sptr window2 = Utils::CreateTestWindow(floatAppInfo_); floatAppInfo_.name = "window3"; floatAppInfo_.rect = {0, 300, 300, 300}; - sptr window3 = utils::CreateTestWindow(floatAppInfo_); + sptr window3 = Utils::CreateTestWindow(floatAppInfo_); ASSERT_EQ(WMError::WM_OK, window1->Show()); WaitForCallback(); From 20fe7a211102e1a498de27beb32ac810efa0df58 Mon Sep 17 00:00:00 2001 From: chyyy0213 Date: Thu, 23 Jun 2022 15:17:56 +0800 Subject: [PATCH 43/81] add animation property config Signed-off-by: chyyy0213 Change-Id: I867f7189636ae398753848bd4f09bcb10317602b Signed-off-by: chyyy0213 --- interfaces/innerkits/wm/window.h | 8 +- interfaces/innerkits/wm/window_option.h | 3 - interfaces/innerkits/wm/wm_common.h | 19 ++ interfaces/kits/napi/window_runtime/BUILD.gn | 1 + .../napi/window_runtime/api/@ohos.window.d.ts | 110 +++++++- .../window_runtime/window_napi/js_window.cpp | 239 +++++++++++++++++- .../window_runtime/window_napi/js_window.h | 13 + .../window_napi/js_window_utils.cpp | 15 ++ .../window_napi/js_window_utils.h | 1 + utils/include/window_property.h | 11 +- utils/include/wm_common_inner.h | 1 + utils/src/window_property.cpp | 49 +++- wm/include/window_adapter.h | 1 - wm/include/window_impl.h | 8 +- wm/src/window_adapter.cpp | 7 - wm/src/window_impl.cpp | 36 ++- wm/src/window_option.cpp | 10 - .../windowscene_fuzzer/windowscene_fuzzer.cpp | 3 - wm/test/systemtest/window_effect_test.cpp | 2 +- wm/test/unittest/mock_window_adapter.h | 1 - wm/test/unittest/window_effect_test.cpp | 55 +--- wmserver/include/window_manager_service.h | 1 - wmserver/include/window_node.h | 3 +- .../include/zidl/window_manager_interface.h | 1 - wmserver/include/zidl/window_manager_proxy.h | 1 - wmserver/src/window_controller.cpp | 16 +- wmserver/src/window_manager_service.cpp | 13 +- wmserver/src/window_node.cpp | 11 +- wmserver/src/window_node_container.cpp | 6 +- wmserver/src/zidl/window_manager_proxy.cpp | 26 -- wmserver/src/zidl/window_manager_stub.cpp | 7 - 31 files changed, 508 insertions(+), 170 deletions(-) diff --git a/interfaces/innerkits/wm/window.h b/interfaces/innerkits/wm/window.h index c1451688..b850114b 100644 --- a/interfaces/innerkits/wm/window.h +++ b/interfaces/innerkits/wm/window.h @@ -169,7 +169,9 @@ public: virtual WMError SetWindowType(WindowType type) = 0; virtual WMError SetWindowMode(WindowMode mode) = 0; virtual WMError SetWindowBackgroundBlur(WindowBlurLevel level) = 0; - virtual WMError SetAlpha(float alpha) = 0; + virtual void SetAlpha(float alpha) = 0; + virtual void SetTransform(const Transform& trans) = 0; + virtual Transform GetTransform() const = 0; virtual WMError AddWindowFlag(WindowFlag flag) = 0; virtual WMError RemoveWindowFlag(WindowFlag flag) = 0; virtual WMError SetWindowFlags(uint32_t flags) = 0; @@ -178,8 +180,8 @@ public: virtual WMError SetLayoutFullScreen(bool status) = 0; virtual WMError SetFullScreen(bool status) = 0; virtual WMError Destroy() = 0; - virtual WMError Show(uint32_t reason = 0) = 0; - virtual WMError Hide(uint32_t reason = 0) = 0; + virtual WMError Show(uint32_t reason = 0, bool isCustomAnimation = false) = 0; + virtual WMError Hide(uint32_t reason = 0, bool isCustomAnimation = false) = 0; virtual WMError MoveTo(int32_t x, int32_t y) = 0; virtual WMError Resize(uint32_t width, uint32_t height) = 0; diff --git a/interfaces/innerkits/wm/window_option.h b/interfaces/innerkits/wm/window_option.h index fb2dd7ed..83dffb17 100644 --- a/interfaces/innerkits/wm/window_option.h +++ b/interfaces/innerkits/wm/window_option.h @@ -33,7 +33,6 @@ public: void SetWindowType(WindowType type); void SetWindowMode(WindowMode mode); void SetWindowBackgroundBlur(WindowBlurLevel level); - void SetAlpha(float alpha); void SetFocusable(bool isFocusable); void SetTouchable(bool isTouchable); void SetDisplayId(DisplayId displayId); @@ -58,7 +57,6 @@ public: WindowType GetWindowType() const; WindowMode GetWindowMode() const; WindowBlurLevel GetWindowBackgroundBlur() const; - float GetAlpha() const; bool GetFocusable() const; bool GetTouchable() const; DisplayId GetDisplayId() const; @@ -75,7 +73,6 @@ private: WindowType type_ { WindowType::WINDOW_TYPE_APP_MAIN_WINDOW }; WindowMode mode_ { WindowMode::WINDOW_MODE_FULLSCREEN }; WindowBlurLevel level_ { WindowBlurLevel::WINDOW_BLUR_OFF }; - float alpha_ { 1.0f }; bool focusable_ { true }; bool touchable_ { true }; DisplayId displayId_ { 0 }; diff --git a/interfaces/innerkits/wm/wm_common.h b/interfaces/innerkits/wm/wm_common.h index 24da28ce..487edcc2 100644 --- a/interfaces/innerkits/wm/wm_common.h +++ b/interfaces/innerkits/wm/wm_common.h @@ -172,6 +172,25 @@ namespace { constexpr int32_t INVALID_UID = -1; } +class Transform { +public: + Transform() + : pivotX_(0.5f), pivotY_(0.5f), scaleX_(1.f), scaleY_(1.f), rotationX_(0.f), rotationY_(0.f), rotationZ_(0.f), + translateX_(0.f), translateY_(0.f), translateZ_(0.f) + {} + ~Transform() {} + float pivotX_; + float pivotY_; + float scaleX_; + float scaleY_; + float rotationX_; + float rotationY_; + float rotationZ_; + float translateX_; + float translateY_; + float translateZ_; +}; + struct SystemBarProperty { bool enable_; uint32_t backgroundColor_; diff --git a/interfaces/kits/napi/window_runtime/BUILD.gn b/interfaces/kits/napi/window_runtime/BUILD.gn index 2d3c1a75..c06c8e0a 100644 --- a/interfaces/kits/napi/window_runtime/BUILD.gn +++ b/interfaces/kits/napi/window_runtime/BUILD.gn @@ -50,6 +50,7 @@ ohos_shared_library("window_native_kit") { configs = [ ":window_native_kit_config" ] deps = [ + "//foundation/graphic/graphic_2d/rosen/modules/render_service_client:librender_service_client", "//foundation/windowmanager/utils:libwmutil", "//foundation/windowmanager/wm:libwm", "//foundation/windowmanager/wmserver:libwms", diff --git a/interfaces/kits/napi/window_runtime/api/@ohos.window.d.ts b/interfaces/kits/napi/window_runtime/api/@ohos.window.d.ts index dfd3821b..55fe7e34 100644 --- a/interfaces/kits/napi/window_runtime/api/@ohos.window.d.ts +++ b/interfaces/kits/napi/window_runtime/api/@ohos.window.d.ts @@ -91,6 +91,82 @@ declare namespace window { */ TYPE_KEYBOARD } + + /** + * Describes the scale Transition Options of window + * @syscap SystemCapability.WindowManager.WindowManager.Core + * @since 9 + * @systemapi + */ + declare interface ScaleOptions { + /** + * The scale param of x direction. Default is 1.f + */ + x?: number; + /** + * The scale param of y direction. Default is 1.f + */ + y?: number; + /** + * The scale param of pivot point of x. Default is 0.5f, Interval is 0.f - 1.f + */ + pivotX?: number; + /** + * The scale param of pivot point of y. Default is 0.5f, Interval is 0.f - 1.f + */ + pivotY?: number; + } + + /** + * Describes the rotate Transition Options of window + * @syscap SystemCapability.WindowManager.WindowManager.Core + * @since 9 + * @systemapi + */ + declare interface RotateOptions { + /** + * The rotate degree of x direction. Default value is 0.f + */ + x?: number; + /** + * The rotate degree of y direction. Default value is 0.f + */ + y?: number; + /** + * The rotate degree of z direction. Default value is 0.f + */ + z?: number; + /** + * The param of pivot point of x. Default is 0.5f, Interval is 0.f - 1.f + */ + pivotX?: number; + /** + * The param of pivot point of y. Default is 0.5f, Interval is 0.f - 1.f + */ + pivotY?: number; + } + + /** + * Describes the translate Transition Options of window + * @syscap SystemCapability.WindowManager.WindowManager.Core + * @since 9 + * @systemapi + */ + declare interface TranslateOptions { + /** + * The translate pixel param of x direction. Default is 0.f + */ + x?: number; + /** + * The translate pixel param of y direction. Default is 0.f + */ + y?: number; + /** + * The translate pixel param of z direction. Default is 0.f + */ + z?: number; + } + /** * Describes the window mode of an application * @systemapi Hide this for inner system use. @@ -961,7 +1037,7 @@ declare namespace window { * @since 9 */ setPreferredOrientation(orientation: Orientation, callback: AsyncCallback): void; - + /** * disable window decoration. It must be called before loadContent. * @systemapi @@ -985,7 +1061,7 @@ declare namespace window { * @systemapi * @since 9 */ - setForbidSplitMove(isForbidSplitMove: boolean, callback: AsyncCallback): void; + setForbidSplitMove(isForbidSplitMove: boolean, callback: AsyncCallback): void; /** * set the flag of the window is forbidden to move in split screen mode @@ -994,7 +1070,35 @@ declare namespace window { * @systemapi * @since 9 */ - setForbidSplitMove(isForbidSplitMove: boolean): Promise; + setForbidSplitMove(isForbidSplitMove: boolean): Promise; + /** + * Sets opacity of window + * @param opacity Interval is 0.f-1.f. + * @systemapi + * @since 9 + */ + setOpacitySync(opacity: number): void; + /** + * Sets scale options of window. + * @param scaleOptions scale param of window. + * @systemapi + * @since 9 + */ + setScaleSync(scaleOptions: ScaleOptions): void; + /** + * Sets rotate options of window. + * @param rotateOptions rotate param of window. + * @systemapi + * @since 9 + */ + setRotateSync(rotateOptions: RotateOptions): void; + /** + * Sets whether is transparent or not. + * @param translateOptions translate param of window. + * @systemapi + * @since 9 + */ + setTranslateSync(translateOptions: TranslateOptions): void; } enum WindowStageEventType { diff --git a/interfaces/kits/napi/window_runtime/window_napi/js_window.cpp b/interfaces/kits/napi/window_runtime/window_napi/js_window.cpp index a2df4b41..cb8148f0 100644 --- a/interfaces/kits/napi/window_runtime/window_napi/js_window.cpp +++ b/interfaces/kits/napi/window_runtime/window_napi/js_window.cpp @@ -15,8 +15,10 @@ #include "js_window.h" #include +#include #include "js_window_utils.h" #include "window.h" +#include "window_helper.h" #include "window_manager_hilog.h" #include "window_option.h" namespace OHOS { @@ -29,24 +31,28 @@ namespace { static thread_local std::map> g_jsWindowMap; std::recursive_mutex g_mutex; +static int ctorCnt = 0; +static int dtorCnt = 0; +static int finalizerCnt = 0; JsWindow::JsWindow(const sptr& window) : windowToken_(window), registerManager_(std::make_unique()) { NotifyNativeWinDestroyFunc func = [](std::string windowName) { std::lock_guard lock(g_mutex); if (windowName.empty() || g_jsWindowMap.count(windowName) == 0) { - WLOGE("[NAPI]Can not find window %{public}s ", windowName.c_str()); + WLOGFE("[NAPI]Can not find window %{public}s ", windowName.c_str()); return; } g_jsWindowMap.erase(windowName); - WLOGE("[NAPI]Destroy window %{public}s in js window", windowName.c_str()); + WLOGFI("[NAPI]Destroy window %{public}s in js window", windowName.c_str()); }; windowToken_->RegisterWindowDestroyedListener(func); + WLOGFI("[NAPI] JsWindow constructor Count: %{public}d", ++ctorCnt); } JsWindow::~JsWindow() { - WLOGFI("[NAPI]~JsWindow"); + WLOGFI("[NAPI]~JsWindow deconstructor Count:%{public}d", ++dtorCnt); windowToken_ = nullptr; } @@ -60,7 +66,7 @@ std::string JsWindow::GetWindowName() void JsWindow::Finalizer(NativeEngine* engine, void* data, void* hint) { - WLOGFI("[NAPI]Finalizer"); + WLOGFI("[NAPI]Finalizer Count:%{public}d", ++finalizerCnt); auto jsWin = std::unique_ptr(static_cast(data)); if (jsWin == nullptr) { WLOGFE("[NAPI]jsWin is nullptr"); @@ -313,6 +319,34 @@ NativeValue* JsWindow::SetForbidSplitMove(NativeEngine* engine, NativeCallbackIn return (me != nullptr) ? me->OnSetForbidSplitMove(*engine, *info) : nullptr; } +NativeValue* JsWindow::SetOpacitySync(NativeEngine* engine, NativeCallbackInfo* info) +{ + WLOGFI("[NAPI]SetOpacitySync"); + JsWindow* me = CheckParamsAndGetThis(engine, info); + return (me != nullptr) ? me->OnSetOpacitySync(*engine, *info) : nullptr; +} + +NativeValue* JsWindow::SetScaleSync(NativeEngine* engine, NativeCallbackInfo* info) +{ + WLOGFI("[NAPI]SetScaleSync"); + JsWindow* me = CheckParamsAndGetThis(engine, info); + return (me != nullptr) ? me->OnSetScaleSync(*engine, *info) : nullptr; +} + +NativeValue* JsWindow::SetRotateSync(NativeEngine* engine, NativeCallbackInfo* info) +{ + WLOGFI("[NAPI]SetRotateSync"); + JsWindow* me = CheckParamsAndGetThis(engine, info); + return (me != nullptr) ? me->OnSetRotateSync(*engine, *info) : nullptr; +} + +NativeValue* JsWindow::SetTranslateSync(NativeEngine* engine, NativeCallbackInfo* info) +{ + WLOGFI("[NAPI]SetTranslateSync"); + JsWindow* me = CheckParamsAndGetThis(engine, info); + return (me != nullptr) ? me->OnSetTranslateSync(*engine, *info) : nullptr; +} + NativeValue* JsWindow::OnShow(NativeEngine& engine, NativeCallbackInfo& info) { WMError errCode = WMError::WM_OK; @@ -1643,6 +1677,199 @@ NativeValue* JsWindow::OnSetForbidSplitMove(NativeEngine& engine, NativeCallback return result; } +NativeValue* JsWindow::OnSetOpacitySync(NativeEngine& engine, NativeCallbackInfo& info) +{ + if (info.argc != 1 || windowToken_ == nullptr) { + WLOGFE("[NAPI]Argc is invalid: %{public}zu or windowToken_ is nullptr", info.argc); + return engine.CreateUndefined(); + } + if (!WindowHelper::IsSystemWindow(windowToken_->GetType())) { + WLOGFE("[NAPI]SetOpacitySync is not allowed since window is not system window"); + return engine.CreateUndefined(); + } + NativeNumber* nativeVal = ConvertNativeValueTo(info.argv[0]); + if (nativeVal == nullptr) { + WLOGFE("[NAPI]Failed to convert parameter to alpha"); + return engine.CreateUndefined(); + } + float alpha = static_cast(*nativeVal); + windowToken_->SetAlpha(alpha); + WLOGFI("[NAPI]Window [%{public}u, %{public}s] SetOpacitySync end, alpha = %{public}f", + windowToken_->GetWindowId(), windowToken_->GetWindowName().c_str(), alpha); + return engine.CreateUndefined(); +} + +bool JsWindow::ParseScaleOption(NativeEngine& engine, NativeObject* jsObject, Transform& trans) +{ + auto surfaceNode = windowToken_->GetSurfaceNode(); + if (surfaceNode == nullptr) { + WLOGFE("[NAPI] surfaceNode is nullptr"); + return false; + } + double data = 0.0f; + if (ParseJsDoubleValue(jsObject, engine, "pivotX", data)) { + surfaceNode->SetPivotX(data); + trans.pivotX_ = data; + } + if (ParseJsDoubleValue(jsObject, engine, "pivotY", data)) { + surfaceNode->SetPivotY(data); + trans.pivotY_ = data; + } + if (ParseJsDoubleValue(jsObject, engine, "x", data)) { + surfaceNode->SetScaleX(data); + trans.scaleX_ = data; + } + if (ParseJsDoubleValue(jsObject, engine, "y", data)) { + surfaceNode->SetScaleY(data); + trans.scaleY_ = data; + } + return true; +} + +NativeValue* JsWindow::OnSetScaleSync(NativeEngine& engine, NativeCallbackInfo& info) +{ + if (info.argc != 1 || windowToken_ == nullptr) { + WLOGFE("[NAPI]Argc is invalid: %{public}zu or windowToken_ is nullptr", info.argc); + return engine.CreateUndefined(); + } + if (!WindowHelper::IsSystemWindow(windowToken_->GetType())) { + WLOGFE("[NAPI]SetScaleSync is not allowed since window is not system window"); + return engine.CreateUndefined(); + } + NativeObject* nativeObj = ConvertNativeValueTo(info.argv[0]); + if (nativeObj == nullptr) { + WLOGFE("[NAPI]Failed to convert object to ScaleOptions"); + return engine.CreateUndefined(); + } + auto trans = windowToken_->GetTransform(); + if (!ParseScaleOption(engine, nativeObj, trans)) { + return engine.CreateUndefined(); + } + windowToken_->SetTransform(trans); + WLOGFI("[NAPI]Window [%{public}u, %{public}s] SetScaleSync end", + windowToken_->GetWindowId(), windowToken_->GetWindowName().c_str()); + WLOGFI("[NAPI]scaleX = %{public}f, scaleY = %{public}f, pivotX = %{public}f pivotY = %{public}f", + trans.scaleX_, trans.scaleY_, trans.pivotX_, trans.pivotY_); + return engine.CreateUndefined(); +} + +bool JsWindow::ParseRotateOption(NativeEngine& engine, NativeObject* jsObject, Transform& trans) +{ + auto surfaceNode = windowToken_->GetSurfaceNode(); + if (surfaceNode == nullptr) { + WLOGFE("[NAPI] surfaceNode is nullptr"); + return false; + } + double data = 0.0f; + if (ParseJsDoubleValue(jsObject, engine, "pivotX", data)) { + surfaceNode->SetPivotX(data); + trans.pivotX_ = data; + } + if (ParseJsDoubleValue(jsObject, engine, "pivotY", data)) { + surfaceNode->SetPivotY(data); + trans.pivotY_ = data; + } + double coeff = 0.5 * 3.14 / 180; // 0.5 means half; 3.14 means pi; 180 means degree + if (ParseJsDoubleValue(jsObject, engine, "x", data)) { + float w = std::cos(data * coeff); + float x = std::sin(data * coeff); + surfaceNode->SetRotation(Quaternion(x, 0, 0, w)); + trans.rotationX_ = data; + } + if (ParseJsDoubleValue(jsObject, engine, "y", data)) { + float w = std::cos(data * coeff); + float y = std::sin(data * coeff); + surfaceNode->SetRotation(Quaternion(0, y, 0, w)); + trans.rotationY_ = data; + } + if (ParseJsDoubleValue(jsObject, engine, "z", data)) { + float w = std::cos(data * coeff); + float z = std::sin(data * coeff); + surfaceNode->SetRotation(Quaternion(0, 0, z, w)); + trans.rotationZ_ = data; + } + return true; +} + +NativeValue* JsWindow::OnSetRotateSync(NativeEngine& engine, NativeCallbackInfo& info) +{ + if (info.argc != 1 || windowToken_ == nullptr) { + WLOGFE("[NAPI]Argc is invalid: %{public}zu or windowToken_ is nullptr", info.argc); + return engine.CreateUndefined(); + } + if (!WindowHelper::IsSystemWindow(windowToken_->GetType())) { + WLOGFE("[NAPI]SetRotateSync is not allowed since window is not system window"); + return engine.CreateUndefined(); + } + NativeObject* nativeObj = ConvertNativeValueTo(info.argv[0]); + if (nativeObj == nullptr) { + WLOGFE("[NAPI]Failed to convert object to RotateOptions"); + return engine.CreateUndefined(); + } + // cannot use sync task since next transform base on current transform + auto trans = windowToken_->GetTransform(); + if (!ParseRotateOption(engine, nativeObj, trans)) { + return engine.CreateUndefined(); + } + windowToken_->SetTransform(trans); + WLOGFI("[NAPI]Window [%{public}u, %{public}s] SetRotateSync end", + windowToken_->GetWindowId(), windowToken_->GetWindowName().c_str()); + WLOGFI("[NAPI]rotateX = %{public}f, rotateY = %{public}f," \ + "rotateZ = %{public}f pivotX = %{public}f pivotY = %{public}f", + trans.rotationX_, trans.rotationY_, trans.rotationZ_, trans.pivotX_, trans.pivotY_); + return engine.CreateUndefined(); +} + +bool JsWindow::ParseTranslateOption(NativeEngine& engine, NativeObject* jsObject, Transform& trans) +{ + auto surfaceNode = windowToken_->GetSurfaceNode(); + if (surfaceNode == nullptr) { + WLOGFE("[NAPI] surfaceNode is nullptr"); + return false; + } + double data = 0.0f; + if (ParseJsDoubleValue(jsObject, engine, "x", data)) { + surfaceNode->SetTranslateX(data); + trans.translateX_ = data; + } + if (ParseJsDoubleValue(jsObject, engine, "y", data)) { + surfaceNode->SetTranslateY(data); + trans.translateY_ = data; + } + if (ParseJsDoubleValue(jsObject, engine, "z", data)) { + surfaceNode->SetTranslateZ(data); + trans.translateZ_ = data; + } + return true; +} + +NativeValue* JsWindow::OnSetTranslateSync(NativeEngine& engine, NativeCallbackInfo& info) +{ + if (info.argc != 1 || windowToken_ == nullptr) { + WLOGFE("[NAPI]Argc is invalid: %{public}zu or windowToken_ is nullptr", info.argc); + return engine.CreateUndefined(); + } + if (!WindowHelper::IsSystemWindow(windowToken_->GetType())) { + WLOGFE("[NAPI]SetTranslateSync is not allowed since window is not system window"); + return engine.CreateUndefined(); + } + NativeObject* nativeObj = ConvertNativeValueTo(info.argv[0]); + if (nativeObj == nullptr) { + WLOGFE("[NAPI]Failed to convert object to TranslateOptions"); + return engine.CreateUndefined(); + } + auto trans = windowToken_->GetTransform(); + if (!ParseTranslateOption(engine, nativeObj, trans)) { + return engine.CreateUndefined(); + } + windowToken_->SetTransform(trans); + WLOGFI("[NAPI]Window [%{public}u, %{public}s] SetRotateSync end," \ + "translateX = %{public}f, translateY = %{public}f, translateZ = %{public}f", + windowToken_->GetWindowId(), windowToken_->GetWindowName().c_str(), + trans.translateX_, trans.translateY_, trans.translateZ_); + return engine.CreateUndefined(); +} + std::shared_ptr FindJsWindowObject(std::string windowName) { WLOGFI("[NAPI]Try to find window %{public}s in g_jsWindowMap", windowName.c_str()); @@ -1716,6 +1943,10 @@ void BindFunctions(NativeEngine& engine, NativeObject* object) BindNativeFunction(engine, *object, "dump", JsWindow::Dump); BindNativeFunction(engine, *object, "setForbidSplitMove", JsWindow::SetForbidSplitMove); BindNativeFunction(engine, *object, "setPreferredOrientation", JsWindow::SetPreferredOrientation); + BindNativeFunction(engine, *object, "setOpacitySync", JsWindow::SetOpacitySync); + BindNativeFunction(engine, *object, "setScaleSync", JsWindow::SetScaleSync); + BindNativeFunction(engine, *object, "setRotateSync", JsWindow::SetRotateSync); + BindNativeFunction(engine, *object, "setTranslateSync", JsWindow::SetTranslateSync); } } // namespace Rosen } // namespace OHOS diff --git a/interfaces/kits/napi/window_runtime/window_napi/js_window.h b/interfaces/kits/napi/window_runtime/window_napi/js_window.h index 6a83610f..e6c2296f 100644 --- a/interfaces/kits/napi/window_runtime/window_napi/js_window.h +++ b/interfaces/kits/napi/window_runtime/window_napi/js_window.h @@ -69,8 +69,16 @@ public: static NativeValue* Dump(NativeEngine* engine, NativeCallbackInfo* info); static NativeValue* SetForbidSplitMove(NativeEngine* engine, NativeCallbackInfo* info); + // animation config + static NativeValue* SetOpacitySync(NativeEngine* engine, NativeCallbackInfo* info); + static NativeValue* SetScaleSync(NativeEngine* engine, NativeCallbackInfo* info); + static NativeValue* SetRotateSync(NativeEngine* engine, NativeCallbackInfo* info); + static NativeValue* SetTranslateSync(NativeEngine* engine, NativeCallbackInfo* info); private: std::string GetWindowName(); + bool ParseScaleOption(NativeEngine& engine, NativeObject* jsObject, Transform& trans); + bool ParseRotateOption(NativeEngine& engine, NativeObject* jsObject, Transform& trans); + bool ParseTranslateOption(NativeEngine& engine, NativeObject* jsObject, Transform& trans); NativeValue* OnShow(NativeEngine& engine, NativeCallbackInfo& info); NativeValue* OnDestroy(NativeEngine& engine, NativeCallbackInfo& info); NativeValue* OnHide(NativeEngine& engine, NativeCallbackInfo& info); @@ -108,6 +116,11 @@ private: NativeValue* OnDump(NativeEngine& engine, NativeCallbackInfo& info); NativeValue* OnSetForbidSplitMove(NativeEngine& engine, NativeCallbackInfo& info); + // animation Config + NativeValue* OnSetOpacitySync(NativeEngine& engine, NativeCallbackInfo& info); + NativeValue* OnSetScaleSync(NativeEngine& engine, NativeCallbackInfo& info); + NativeValue* OnSetRotateSync(NativeEngine& engine, NativeCallbackInfo& info); + NativeValue* OnSetTranslateSync(NativeEngine& engine, NativeCallbackInfo& info); sptr windowToken_ = nullptr; std::unique_ptr registerManager_ = nullptr; }; diff --git a/interfaces/kits/napi/window_runtime/window_napi/js_window_utils.cpp b/interfaces/kits/napi/window_runtime/window_napi/js_window_utils.cpp index 9253f519..7baa240e 100644 --- a/interfaces/kits/napi/window_runtime/window_napi/js_window_utils.cpp +++ b/interfaces/kits/napi/window_runtime/window_napi/js_window_utils.cpp @@ -484,5 +484,20 @@ bool GetAPI7Ability(NativeEngine& engine, AppExecFwk::Ability* &ability) } return true; } + +bool ParseJsDoubleValue(NativeObject* jsObject, NativeEngine& engine, const std::string& name, double data) +{ + NativeValue* value = jsObject->GetProperty(name.c_str()); + if (value->TypeOf() != NATIVE_UNDEFINED) { + if (!ConvertFromJsValue(engine, value, data)) { + WLOGFE("[NAPI]Failed to convert parameter to scale %{public}s", name.c_str()); + return false; + } + } else { + WLOGFI("[NAPI]no property with: %{public}s", name.c_str()); + return false; + } + return true; +} } // namespace Rosen } // namespace OHOS diff --git a/interfaces/kits/napi/window_runtime/window_napi/js_window_utils.h b/interfaces/kits/napi/window_runtime/window_napi/js_window_utils.h index 4765a8ad..b8c5c77a 100644 --- a/interfaces/kits/napi/window_runtime/window_napi/js_window_utils.h +++ b/interfaces/kits/napi/window_runtime/window_napi/js_window_utils.h @@ -165,6 +165,7 @@ const std::map JS_TO_NATIVE_ORIENTATION_MAP { NativeValue* WindowStageEventTypeInit(NativeEngine* engine); NativeValue* WindowLayoutModeInit(NativeEngine* engine); bool GetAPI7Ability(NativeEngine& engine, AppExecFwk::Ability* &ability); + bool ParseJsDoubleValue(NativeObject* jsObject, NativeEngine& engine, const std::string& name, double data); template inline bool ConvertNativeValueToVector(NativeEngine& engine, NativeValue* nativeValue, std::vector& out) { diff --git a/utils/include/window_property.h b/utils/include/window_property.h index 7aec8721..32cc6e85 100644 --- a/utils/include/window_property.h +++ b/utils/include/window_property.h @@ -19,8 +19,7 @@ #include #include #include -#include "parcel.h" - +#include #include "class_var_definition.h" #include "dm_common.h" #include "wm_common.h" @@ -74,6 +73,7 @@ public: void SetTouchHotAreas(const std::vector& rects); void SetAccessTokenId(uint32_t accessTokenId); WindowSizeChangeReason GetWindowSizeChangeReason() const; + void SetTransform(const Transform& trans); const std::string& GetWindowName() const; Rect GetRequestRect() const; @@ -109,7 +109,7 @@ public: const Rect& GetOriginRect() const; void GetTouchHotAreas(std::vector& rects) const; uint32_t GetAccessTokenId() const; - + Transform GetTransform() const; virtual bool Marshalling(Parcel& parcel) const override; static WindowProperty* Unmarshalling(Parcel& parcel); @@ -120,7 +120,8 @@ private: static void MapUnmarshalling(Parcel& parcel, WindowProperty* property); bool MarshallingTouchHotAreas(Parcel& parcel) const; static void UnmarshallingTouchHotAreas(Parcel& parcel, WindowProperty* property); - + bool MarshallingTransform(Parcel& parcel) const; + static void UnmarshallingTransform(Parcel& parcel, WindowProperty* property); std::string windowName_; Rect requestRect_ { 0, 0, 0, 0 }; // window rect requested by the client (without decoration size) Rect windowRect_ { 0, 0, 0, 0 }; // actual window rect @@ -158,7 +159,9 @@ private: DragType dragType_ = DragType::DRAG_UNDEFINED; std::vector touchHotAreas_; // coordinates relative to window. uint32_t accessTokenId_ { 0 }; + Transform trans_; DEFINE_VAR_DEFAULT_FUNC_GET_SET(Orientation, RequestedOrientation, requestedOrientation, Orientation::UNSPECIFIED); + DEFINE_VAR_DEFAULT_FUNC_GET_SET(bool, CustomAnimation, isCustomAnimation, false); }; } } diff --git a/utils/include/wm_common_inner.h b/utils/include/wm_common_inner.h index 2e95688c..f5b0808c 100644 --- a/utils/include/wm_common_inner.h +++ b/utils/include/wm_common_inner.h @@ -84,6 +84,7 @@ enum class PropertyChangeAction : uint32_t { ACTION_UPDATE_SET_BRIGHTNESS = 1 << 10, ACTION_UPDATE_MODE_SUPPORT_INFO = 1 << 11, ACTION_UPDATE_TOUCH_HOT_AREA = 1 << 12, + ACTION_UPDATE_TRANSFORM_PROPERTY = 1 << 13, }; struct ModeChangeHotZonesConfig { diff --git a/utils/src/window_property.cpp b/utils/src/window_property.cpp index fa4f73d9..49a03836 100644 --- a/utils/src/window_property.cpp +++ b/utils/src/window_property.cpp @@ -103,6 +103,11 @@ void WindowProperty::SetAlpha(float alpha) alpha_ = alpha; } +void WindowProperty::SetTransform(const Transform& trans) +{ + trans_ = trans; +} + void WindowProperty::SetBrightness(float brightness) { brightness_ = brightness; @@ -270,6 +275,11 @@ float WindowProperty::GetAlpha() const return alpha_; } +Transform WindowProperty::GetTransform() const +{ + return trans_; +} + float WindowProperty::GetBrightness() const { return brightness_; @@ -407,7 +417,6 @@ bool WindowProperty::MapMarshalling(Parcel& parcel) const void WindowProperty::MapUnmarshalling(Parcel& parcel, WindowProperty* property) { - std::unordered_map sysBarPropMap; uint32_t size = parcel.ReadUint32(); for (uint32_t i = 0; i < size; i++) { WindowType type = static_cast(parcel.ReadUint32()); @@ -440,6 +449,31 @@ void WindowProperty::UnmarshallingTouchHotAreas(Parcel& parcel, WindowProperty* } } +bool WindowProperty::MarshallingTransform(Parcel& parcel) const +{ + return parcel.WriteFloat(trans_.pivotX_) && parcel.WriteFloat(trans_.pivotY_) && + parcel.WriteFloat(trans_.scaleX_) && parcel.WriteFloat(trans_.scaleY_) && + parcel.WriteFloat(trans_.rotationX_) && parcel.WriteFloat(trans_.rotationY_) && + parcel.WriteFloat(trans_.rotationZ_) && parcel.WriteFloat(trans_.translateX_) && + parcel.WriteFloat(trans_.translateY_) && parcel.WriteFloat(trans_.translateZ_); +} + +void WindowProperty::UnmarshallingTransform(Parcel& parcel, WindowProperty* property) +{ + Transform trans; + trans.pivotX_ = parcel.ReadFloat(); + trans.pivotY_ = parcel.ReadFloat(); + trans.scaleX_ = parcel.ReadFloat(); + trans.scaleY_ = parcel.ReadFloat(); + trans.rotationX_ = parcel.ReadFloat(); + trans.rotationY_ = parcel.ReadFloat(); + trans.rotationZ_ = parcel.ReadFloat(); + trans.translateX_ = parcel.ReadFloat(); + trans.translateY_ = parcel.ReadFloat(); + trans.translateZ_ = parcel.ReadFloat(); + property->SetTransform(trans); +} + bool WindowProperty::Marshalling(Parcel& parcel) const { return parcel.WriteString(windowName_) && parcel.WriteInt32(windowRect_.posX_) && @@ -460,7 +494,8 @@ bool WindowProperty::Marshalling(Parcel& parcel) const parcel.WriteBool(turnScreenOn_) && parcel.WriteBool(keepScreenOn_) && parcel.WriteUint32(modeSupportInfo_) && parcel.WriteUint32(static_cast(dragType_)) && parcel.WriteUint32(originRect_.width_) && parcel.WriteUint32(originRect_.height_) && - parcel.WriteBool(isStretchable_) && MarshallingTouchHotAreas(parcel) && parcel.WriteUint32(accessTokenId_); + parcel.WriteBool(isStretchable_) && MarshallingTouchHotAreas(parcel) && parcel.WriteUint32(accessTokenId_) && + parcel.WriteBool(isCustomAnimation_) && MarshallingTransform(parcel); } WindowProperty* WindowProperty::Unmarshalling(Parcel& parcel) @@ -509,6 +544,8 @@ WindowProperty* WindowProperty::Unmarshalling(Parcel& parcel) property->SetStretchable(parcel.ReadBool()); UnmarshallingTouchHotAreas(parcel, property); property->SetAccessTokenId(parcel.ReadUint32()); + property->SetCustomAnimation(parcel.ReadBool()); + UnmarshallingTransform(parcel, property); return property; } @@ -560,6 +597,9 @@ bool WindowProperty::Write(Parcel& parcel, PropertyChangeAction action) case PropertyChangeAction::ACTION_UPDATE_TOUCH_HOT_AREA: ret &= MarshallingTouchHotAreas(parcel); break; + case PropertyChangeAction::ACTION_UPDATE_TRANSFORM_PROPERTY: + ret &= MarshallingTransform(parcel); + break; default: break; } @@ -613,6 +653,9 @@ void WindowProperty::Read(Parcel& parcel, PropertyChangeAction action) case PropertyChangeAction::ACTION_UPDATE_TOUCH_HOT_AREA: UnmarshallingTouchHotAreas(parcel, this); break; + case PropertyChangeAction::ACTION_UPDATE_TRANSFORM_PROPERTY: + UnmarshallingTransform(parcel, this); + break; default: break; } @@ -655,6 +698,8 @@ void WindowProperty::CopyFrom(const sptr& property) isStretchable_ = property->isStretchable_; touchHotAreas_ = property->touchHotAreas_; accessTokenId_ = property->accessTokenId_; + isCustomAnimation_ = property->isCustomAnimation_; + trans_ = property->trans_; } } } diff --git a/wm/include/window_adapter.h b/wm/include/window_adapter.h index 2be221d5..f749dc9e 100644 --- a/wm/include/window_adapter.h +++ b/wm/include/window_adapter.h @@ -43,7 +43,6 @@ public: virtual WMError RequestFocus(uint32_t windowId); virtual WMError GetAvoidAreaByType(uint32_t windowId, AvoidAreaType type, AvoidArea& avoidRect); virtual WMError SetWindowBackgroundBlur(uint32_t windowId, WindowBlurLevel level); - virtual WMError SetAlpha(uint32_t windowId, float alpha); virtual WMError GetTopWindowId(uint32_t mainWinId, uint32_t& topWinId); virtual void ProcessPointDown(uint32_t windowId, bool isStartDrag = false); virtual void ProcessPointUp(uint32_t windowId); diff --git a/wm/include/window_impl.h b/wm/include/window_impl.h index 0ac4b1cb..b2f78193 100644 --- a/wm/include/window_impl.h +++ b/wm/include/window_impl.h @@ -127,13 +127,15 @@ public: virtual WMError SetWindowType(WindowType type) override; virtual WMError SetWindowMode(WindowMode mode) override; virtual WMError SetWindowBackgroundBlur(WindowBlurLevel level) override; - virtual WMError SetAlpha(float alpha) override; + virtual void SetAlpha(float alpha) override; + virtual void SetTransform(const Transform& trans) override; virtual WMError AddWindowFlag(WindowFlag flag) override; virtual WMError RemoveWindowFlag(WindowFlag flag) override; virtual WMError SetWindowFlags(uint32_t flags) override; virtual WMError SetSystemBarProperty(WindowType type, const SystemBarProperty& property) override; virtual WMError SetLayoutFullScreen(bool status) override; virtual WMError SetFullScreen(bool status) override; + virtual Transform GetTransform() const override; inline void SetWindowState(WindowState state) { state_ = state; @@ -143,8 +145,8 @@ public: WMError Create(const std::string& parentName, const std::shared_ptr& context = nullptr); virtual WMError Destroy() override; - virtual WMError Show(uint32_t reason = 0) override; - virtual WMError Hide(uint32_t reason = 0) override; + virtual WMError Show(uint32_t reason = 0, bool isCustomAnimation = false) override; + virtual WMError Hide(uint32_t reason = 0, bool isCustomAnimation = false) override; virtual WMError MoveTo(int32_t x, int32_t y) override; virtual WMError Resize(uint32_t width, uint32_t height) override; virtual WMError SetKeepScreenOn(bool keepScreenOn) override; diff --git a/wm/src/window_adapter.cpp b/wm/src/window_adapter.cpp index 2d2285a5..c044c26c 100644 --- a/wm/src/window_adapter.cpp +++ b/wm/src/window_adapter.cpp @@ -113,13 +113,6 @@ WMError WindowAdapter::SetWindowBackgroundBlur(uint32_t windowId, WindowBlurLeve return windowManagerServiceProxy_->SetWindowBackgroundBlur(windowId, level); } -WMError WindowAdapter::SetAlpha(uint32_t windowId, float alpha) -{ - INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR); - - return windowManagerServiceProxy_->SetAlpha(windowId, alpha); -} - void WindowAdapter::ProcessPointDown(uint32_t windowId, bool isStartDrag) { INIT_PROXY_CHECK_RETURN(); diff --git a/wm/src/window_impl.cpp b/wm/src/window_impl.cpp index 0dcecf56..eae5470c 100644 --- a/wm/src/window_impl.cpp +++ b/wm/src/window_impl.cpp @@ -48,7 +48,8 @@ const WindowImpl::ColorSpaceConvertMap WindowImpl::colorSpaceConvertMap[] = { std::map>> WindowImpl::windowMap_; std::map>> WindowImpl::subWindowMap_; std::map>> WindowImpl::appFloatingWindowMap_; - +static int ctorCnt = 0; +static int dtorCnt = 0; WindowImpl::WindowImpl(const sptr& option) { property_ = new (std::nothrow) WindowProperty(); @@ -57,7 +58,6 @@ WindowImpl::WindowImpl(const sptr& option) property_->SetWindowType(option->GetWindowType()); property_->SetWindowMode(option->GetWindowMode()); property_->SetWindowBackgroundBlur(option->GetWindowBackgroundBlur()); - property_->SetAlpha(option->GetAlpha()); property_->SetFullScreen(option->GetWindowMode() == WindowMode::WINDOW_MODE_FULLSCREEN); property_->SetFocusable(option->GetFocusable()); property_->SetTouchable(option->GetTouchable()); @@ -81,6 +81,7 @@ WindowImpl::WindowImpl(const sptr& option) struct RSSurfaceNodeConfig rsSurfaceNodeConfig; rsSurfaceNodeConfig.SurfaceNodeName = property_->GetWindowName(); surfaceNode_ = RSSurfaceNode::Create(rsSurfaceNodeConfig); + WLOGFI("WindowImpl constructor Count: %{public}d name: %{public}s", ++ctorCnt, property_->GetWindowName().c_str()); } void WindowImpl::InitListenerHandler() @@ -104,7 +105,8 @@ WindowImpl::~WindowImpl() if (eventHandler_ != nullptr) { eventHandler_.reset(); } - WLOGFI("windowName: %{public}s, windowId: %{public}d", GetWindowName().c_str(), GetWindowId()); + WLOGFI("windowName: %{public}s, windowId: %{public}d, dtorCnt: %{public}d, surfaceNode:%{public}d", + GetWindowName().c_str(), GetWindowId(), ++dtorCnt, static_cast(surfaceNode_.use_count())); Destroy(); } @@ -364,14 +366,29 @@ WMError WindowImpl::SetWindowBackgroundBlur(WindowBlurLevel level) return SingletonContainer::Get().SetWindowBackgroundBlur(property_->GetWindowId(), level); } -WMError WindowImpl::SetAlpha(float alpha) +void WindowImpl::SetAlpha(float alpha) { WLOGFI("[Client] Window %{public}u alpha %{public}f", property_->GetWindowId(), alpha); if (!IsWindowValid()) { - return WMError::WM_ERROR_INVALID_WINDOW; + return; } property_->SetAlpha(alpha); - return SingletonContainer::Get().SetAlpha(property_->GetWindowId(), alpha); + surfaceNode_->SetAlpha(alpha); +} + +void WindowImpl::SetTransform(const Transform& trans) +{ + WLOGFI("[Client] Window %{public}u SetTransform", property_->GetWindowId()); + if (!IsWindowValid()) { + return; + } + property_->SetTransform(trans); + UpdateProperty(PropertyChangeAction::ACTION_UPDATE_TRANSFORM_PROPERTY); +} + +Transform WindowImpl::GetTransform() const +{ + return property_->GetTransform(); } WMError WindowImpl::AddWindowFlag(WindowFlag flag) @@ -833,7 +850,7 @@ WMError WindowImpl::Destroy(bool needNotifyServer) return ret; } -WMError WindowImpl::Show(uint32_t reason) +WMError WindowImpl::Show(uint32_t reason, bool isCustomAnimation) { WLOGFI("[Client] Window [name:%{public}s, id:%{public}u] Show, reason:%{public}u", name_.c_str(), property_->GetWindowId(), reason); @@ -864,6 +881,8 @@ WMError WindowImpl::Show(uint32_t reason) return WMError::WM_OK; } SetDefaultOption(); + // set true success when transitionController exist; set false when complete transition + property_->SetCustomAnimation(isCustomAnimation); WMError ret = SingletonContainer::Get().AddWindow(property_); RecordLifeCycleExceptionEvent(LifeCycleEvent::SHOW_EVENT, ret); if (ret == WMError::WM_OK || ret == WMError::WM_ERROR_DEATH_RECIPIENT) { @@ -876,7 +895,7 @@ WMError WindowImpl::Show(uint32_t reason) return ret; } -WMError WindowImpl::Hide(uint32_t reason) +WMError WindowImpl::Hide(uint32_t reason, bool isCustomAnimation) { WLOGFI("[Client] Window [name:%{public}s, id:%{public}u] Hide", name_.c_str(), property_->GetWindowId()); if (!IsWindowValid()) { @@ -892,6 +911,7 @@ WMError WindowImpl::Hide(uint32_t reason) WLOGFI("window is already hidden id: %{public}u", property_->GetWindowId()); return WMError::WM_OK; } + property_->SetCustomAnimation(isCustomAnimation); WMError ret = SingletonContainer::Get().RemoveWindow(property_->GetWindowId()); RecordLifeCycleExceptionEvent(LifeCycleEvent::HIDE_EVENT, ret); if (ret != WMError::WM_OK) { diff --git a/wm/src/window_option.cpp b/wm/src/window_option.cpp index 9c7011d2..60477a89 100644 --- a/wm/src/window_option.cpp +++ b/wm/src/window_option.cpp @@ -50,11 +50,6 @@ void WindowOption::SetWindowBackgroundBlur(WindowBlurLevel level) level_ = level; } -void WindowOption::SetAlpha(float alpha) -{ - alpha_ = alpha; -} - void WindowOption::SetFocusable(bool isFocusable) { focusable_ = isFocusable; @@ -122,11 +117,6 @@ WindowBlurLevel WindowOption::GetWindowBackgroundBlur() const return level_; } -float WindowOption::GetAlpha() const -{ - return alpha_; -} - bool WindowOption::GetFocusable() const { return focusable_; diff --git a/wm/test/fuzztest/windowscene_fuzzer/windowscene_fuzzer.cpp b/wm/test/fuzztest/windowscene_fuzzer/windowscene_fuzzer.cpp index c0faa60d..3acf1b7d 100644 --- a/wm/test/fuzztest/windowscene_fuzzer/windowscene_fuzzer.cpp +++ b/wm/test/fuzztest/windowscene_fuzzer/windowscene_fuzzer.cpp @@ -77,9 +77,6 @@ size_t InitWindowOption1(WindowOption &windowOption, const uint8_t *data, size_t uint32_t level; startPos += GetObject(level, data + startPos, size - startPos); windowOption.SetWindowBackgroundBlur(static_cast(level)); - float alpha; - startPos += GetObject(alpha, data + startPos, size - startPos); - windowOption.SetAlpha(alpha); bool focusable; startPos += GetObject(focusable, data + startPos, size - startPos); windowOption.SetFocusable(focusable); diff --git a/wm/test/systemtest/window_effect_test.cpp b/wm/test/systemtest/window_effect_test.cpp index 8d13f28b..47bbb564 100644 --- a/wm/test/systemtest/window_effect_test.cpp +++ b/wm/test/systemtest/window_effect_test.cpp @@ -80,7 +80,7 @@ HWTEST_F(WindowEffectTest, WindowEffect02, Function | MediumTest | Level3) { const sptr& window = utils::CreateTestWindow(fullScreenAppInfo_); - ASSERT_EQ(WMError::WM_OK, window->SetAlpha(1.0f)); + window->SetAlpha(1.0f); ASSERT_EQ(1.0f, window->GetAlpha()); window->Destroy(); diff --git a/wm/test/unittest/mock_window_adapter.h b/wm/test/unittest/mock_window_adapter.h index 4b7d529a..02feff5a 100644 --- a/wm/test/unittest/mock_window_adapter.h +++ b/wm/test/unittest/mock_window_adapter.h @@ -30,7 +30,6 @@ public: MOCK_METHOD0(ClearWindowAdapter, void()); MOCK_METHOD1(DestroyWindow, WMError(uint32_t windowId)); MOCK_METHOD2(SetWindowBackgroundBlur, WMError(uint32_t windowId, WindowBlurLevel level)); - MOCK_METHOD2(SetAlpha, WMError(uint32_t windowId, float alpha)); MOCK_METHOD2(UpdateProperty, WMError(sptr& windowProperty, PropertyChangeAction action)); }; } diff --git a/wm/test/unittest/window_effect_test.cpp b/wm/test/unittest/window_effect_test.cpp index 655a2105..5c38abfe 100644 --- a/wm/test/unittest/window_effect_test.cpp +++ b/wm/test/unittest/window_effect_test.cpp @@ -57,26 +57,10 @@ HWTEST_F(WindowEffectTest, WindowEffect01, Function | SmallTest | Level2) /** * @tc.name: WindowEffect02 - * @tc.desc: windowOption: set window alpha/ get window alpha - * @tc.type: FUNC - */ -HWTEST_F(WindowEffectTest, WindowEffect02, Function | SmallTest | Level2) -{ - sptr option = new WindowOption(); - option->SetAlpha(0.0f); - ASSERT_EQ(0.0f, option->GetAlpha()); - option->SetAlpha(0.5f); - ASSERT_EQ(0.5f, option->GetAlpha()); - option->SetAlpha(1.0f); - ASSERT_EQ(1.0f, option->GetAlpha()); -} - -/** - * @tc.name: WindowEffect03 * @tc.desc: WindowImp: Create window with no default option, get and check Property * @tc.type: FUNC */ -HWTEST_F(WindowEffectTest, WindowEffect03, Function | SmallTest | Level2) +HWTEST_F(WindowEffectTest, WindowEffect02, Function | SmallTest | Level2) { std::unique_ptr m = std::make_unique(); sptr option = new WindowOption(); @@ -92,20 +76,18 @@ HWTEST_F(WindowEffectTest, WindowEffect03, Function | SmallTest | Level2) } /** - * @tc.name: WindowEffect04 + * @tc.name: WindowEffect03 * @tc.desc: Create window with no default option, get and check Property * @tc.type: FUNC */ -HWTEST_F(WindowEffectTest, WindowEffect04, Function | SmallTest | Level2) +HWTEST_F(WindowEffectTest, WindowEffect03, Function | SmallTest | Level2) { std::unique_ptr m = std::make_unique(); sptr option = new WindowOption(); - option->SetAlpha(0.1f); - sptr window = new WindowImpl(option); EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK)); ASSERT_EQ(WMError::WM_OK, window->Create("")); - + window->SetAlpha(0.1f); ASSERT_EQ(0.1f, window->GetAlpha()); EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK)); @@ -113,11 +95,11 @@ HWTEST_F(WindowEffectTest, WindowEffect04, Function | SmallTest | Level2) } /** - * @tc.name: WindowEffect05 + * @tc.name: WindowEffect04 * @tc.desc: set window effect parameters throw window, and check parameters. * @tc.type: FUNC */ -HWTEST_F(WindowEffectTest, WindowEffect05, Function | SmallTest | Level2) +HWTEST_F(WindowEffectTest, WindowEffect04, Function | SmallTest | Level2) { std::unique_ptr m = std::make_unique(); sptr option = new WindowOption(); @@ -135,32 +117,11 @@ HWTEST_F(WindowEffectTest, WindowEffect05, Function | SmallTest | Level2) } /** - * @tc.name: WindowEffect06 - * @tc.desc: set window effect parameters throw window, and check parameters. - * @tc.type: FUNC - */ -HWTEST_F(WindowEffectTest, WindowEffect06, Function | SmallTest | Level2) -{ - std::unique_ptr m = std::make_unique(); - sptr option = new WindowOption(); - sptr window = new WindowImpl(option); - - EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK)); - ASSERT_EQ(WMError::WM_OK, window->Create("")); - EXPECT_CALL(m->Mock(), SetAlpha(_, _)).Times(1).WillOnce(Return(WMError::WM_OK)); - ASSERT_EQ(WMError::WM_OK, window->SetAlpha(0.1f)); - ASSERT_EQ(0.1f, window->GetAlpha()); - - EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK)); - window->Destroy(); -} - -/** - * @tc.name: WindowEffect07 + * @tc.name: WindowEffect05 * @tc.desc: WindowImp: Create window with default option, get and check Property * @tc.type: FUNC */ -HWTEST_F(WindowEffectTest, WindowEffect07, Function | SmallTest | Level2) +HWTEST_F(WindowEffectTest, WindowEffect05, Function | SmallTest | Level2) { std::unique_ptr m = std::make_unique(); sptr option = new WindowOption(); diff --git a/wmserver/include/window_manager_service.h b/wmserver/include/window_manager_service.h index 0366f24c..b8fc7d3e 100644 --- a/wmserver/include/window_manager_service.h +++ b/wmserver/include/window_manager_service.h @@ -77,7 +77,6 @@ public: WMError DestroyWindow(uint32_t windowId, bool onlySelf = false) override; WMError RequestFocus(uint32_t windowId) override; WMError SetWindowBackgroundBlur(uint32_t windowId, WindowBlurLevel level) override; - WMError SetAlpha(uint32_t windowId, float alpha) override; AvoidArea GetAvoidAreaByType(uint32_t windowId, AvoidAreaType avoidAreaType) override; void ProcessPointDown(uint32_t windowId, bool isStartDrag) override; void ProcessPointUp(uint32_t windowId) override; diff --git a/wmserver/include/window_node.h b/wmserver/include/window_node.h index b955e0da..72c76b75 100644 --- a/wmserver/include/window_node.h +++ b/wmserver/include/window_node.h @@ -54,7 +54,6 @@ public: void SetSystemBarProperty(WindowType type, const SystemBarProperty& property); void SetWindowMode(WindowMode mode); void SetWindowBackgroundBlur(WindowBlurLevel level); - void SetAlpha(float alpha); void SetBrightness(float brightness); void SetFocusable(bool focusable); void SetTouchable(bool touchable); @@ -85,7 +84,6 @@ public: WindowType GetWindowType() const; WindowMode GetWindowMode() const; WindowBlurLevel GetWindowBackgroundBlur() const; - float GetAlpha() const; float GetBrightness() const; bool IsTurnScreenOn() const; bool IsKeepScreenOn() const; @@ -106,6 +104,7 @@ public: void GetTouchHotAreas(std::vector& rects) const; uint32_t GetAccessTokenId() const; + bool EnableDefaultAnimation(bool propertyEnabled, bool animationPlayed); sptr parent_; std::vector> children_; std::shared_ptr surfaceNode_; diff --git a/wmserver/include/zidl/window_manager_interface.h b/wmserver/include/zidl/window_manager_interface.h index 6a2576b6..1280b14a 100644 --- a/wmserver/include/zidl/window_manager_interface.h +++ b/wmserver/include/zidl/window_manager_interface.h @@ -69,7 +69,6 @@ public: virtual WMError DestroyWindow(uint32_t windowId, bool onlySelf = false) = 0; virtual WMError RequestFocus(uint32_t windowId) = 0; virtual WMError SetWindowBackgroundBlur(uint32_t windowId, WindowBlurLevel level) = 0; - virtual WMError SetAlpha(uint32_t windowId, float alpha) = 0; virtual AvoidArea GetAvoidAreaByType(uint32_t windowId, AvoidAreaType type) = 0; virtual WMError GetTopWindowId(uint32_t mainWinId, uint32_t& topWinId) = 0; virtual void ProcessPointDown(uint32_t windowId, bool isStartDrag) = 0; diff --git a/wmserver/include/zidl/window_manager_proxy.h b/wmserver/include/zidl/window_manager_proxy.h index 4d58628b..2ee5d352 100644 --- a/wmserver/include/zidl/window_manager_proxy.h +++ b/wmserver/include/zidl/window_manager_proxy.h @@ -37,7 +37,6 @@ public: WMError DestroyWindow(uint32_t windowId, bool onlySelf = false) override; WMError RequestFocus(uint32_t windowId) override; WMError SetWindowBackgroundBlur(uint32_t windowId, WindowBlurLevel level) override; - WMError SetAlpha(uint32_t windowId, float alpha) override; AvoidArea GetAvoidAreaByType(uint32_t windowId, AvoidAreaType type) override; WMError GetTopWindowId(uint32_t mainWinId, uint32_t& topWinId) override; void ProcessPointDown(uint32_t windowId, bool isStartDrag) override; diff --git a/wmserver/src/window_controller.cpp b/wmserver/src/window_controller.cpp index 93b36835..bebe2bd3 100644 --- a/wmserver/src/window_controller.cpp +++ b/wmserver/src/window_controller.cpp @@ -397,21 +397,6 @@ WMError WindowController::SetWindowBackgroundBlur(uint32_t windowId, WindowBlurL return WMError::WM_OK; } -WMError WindowController::SetAlpha(uint32_t windowId, float dstAlpha) -{ - auto node = windowRoot_->GetWindowNode(windowId); - if (node == nullptr) { - WLOGFE("could not find window"); - return WMError::WM_ERROR_NULLPTR; - } - - WLOGFI("WindowEffect WindowController SetAlpha alpha: %{public}f", dstAlpha); - node->SetAlpha(dstAlpha); - - FlushWindowInfo(windowId); - return WMError::WM_OK; -} - void WindowController::NotifyDisplayStateChange(DisplayId defaultDisplayId, sptr displayInfo, const std::map>& displayInfoMap, DisplayStateChangeType type) { @@ -847,6 +832,7 @@ WMError WindowController::UpdateProperty(sptr& property, Propert property->GetTouchHotAreas(rects); return UpdateTouchHotAreas(node, rects); } + case PropertyChangeAction::ACTION_UPDATE_TRANSFORM_PROPERTY: default: break; } diff --git a/wmserver/src/window_manager_service.cpp b/wmserver/src/window_manager_service.cpp index 73838370..246b9f14 100644 --- a/wmserver/src/window_manager_service.cpp +++ b/wmserver/src/window_manager_service.cpp @@ -455,13 +455,6 @@ WMError WindowManagerService::SetWindowBackgroundBlur(uint32_t windowId, WindowB }).get(); } -WMError WindowManagerService::SetAlpha(uint32_t windowId, float alpha) -{ - return wmsTaskLooper_->ScheduleTask([this, windowId, alpha]() { - return windowController_->SetAlpha(windowId, alpha); - }).get(); -} - AvoidArea WindowManagerService::GetAvoidAreaByType(uint32_t windowId, AvoidAreaType avoidAreaType) { return wmsTaskLooper_->ScheduleTask([this, windowId, avoidAreaType]() { @@ -613,6 +606,12 @@ WMError WindowManagerService::UpdateProperty(sptr& windowPropert WLOGFE("property is invalid"); return WMError::WM_ERROR_NULLPTR; } + if (action == PropertyChangeAction::ACTION_UPDATE_TRANSFORM_PROPERTY) { + wmsTaskLooper_->PostTask([this, windowProperty, action]() mutable { + windowController_->UpdateProperty(windowProperty, action); + }); + return WMError::WM_OK; + } return wmsTaskLooper_->ScheduleTask([this, &windowProperty, action]() { WM_SCOPED_TRACE("wms:UpdateProperty"); WMError res = windowController_->UpdateProperty(windowProperty, action); diff --git a/wmserver/src/window_node.cpp b/wmserver/src/window_node.cpp index fbbb02e2..e4d89d49 100644 --- a/wmserver/src/window_node.cpp +++ b/wmserver/src/window_node.cpp @@ -100,13 +100,6 @@ void WindowNode::SetWindowBackgroundBlur(WindowBlurLevel level) surfaceNode_->SetBackgroundFilter(RSFilter::CreateBlurFilter(blurRadiusX, blurRadiusY)); } -void WindowNode::SetAlpha(float alpha) -{ - property_->SetAlpha(alpha); - WLOGFI("WindowEffect WinodwNode SetAlpha alpha:%{public}f", alpha); - surfaceNode_->SetAlpha(alpha); -} - void WindowNode::SetBrightness(float brightness) { property_->SetBrightness(brightness); @@ -273,9 +266,9 @@ WindowBlurLevel WindowNode::GetWindowBackgroundBlur() const return property_->GetWindowBackgroundBlur(); } -float WindowNode::GetAlpha() const +bool WindowNode::EnableDefaultAnimation(bool propertyEnabled, bool animationPlayed) { - return property_->GetAlpha(); + return (propertyEnabled && (!animationPlayed) && (!property_->GetCustomAnimation()) && (!isAppCrash_)); } float WindowNode::GetBrightness() const diff --git a/wmserver/src/window_node_container.cpp b/wmserver/src/window_node_container.cpp index a2e77c39..e31230e1 100644 --- a/wmserver/src/window_node_container.cpp +++ b/wmserver/src/window_node_container.cpp @@ -387,6 +387,10 @@ void WindowNodeContainer::UpdateWindowTree(sptr& node) bool WindowNodeContainer::UpdateRSTree(sptr& node, DisplayId displayId, bool isAdd, bool animationPlayed) { WM_FUNCTION_TRACE(); + if (node->GetWindowProperty()->GetCustomAnimation()) { + WLOGFI("not need to update RsTree since SystemWindowAnimation is playing"); + return false; + } if (node->GetWindowType() == WindowType::WINDOW_TYPE_APP_COMPONENT) { WLOGFI("WINDOW_TYPE_APP_COMPONENT not need to update RsTree"); return true; @@ -413,7 +417,7 @@ bool WindowNodeContainer::UpdateRSTree(sptr& node, DisplayId display } }; - if (IsWindowAnimationEnabled && !animationPlayed && !node->isAppCrash_) { + if (node->EnableDefaultAnimation(IsWindowAnimationEnabled, animationPlayed)) { WLOGFI("add or remove window with animation"); // default transition duration: 350ms static const RSAnimationTimingProtocol timingProtocol(350); diff --git a/wmserver/src/zidl/window_manager_proxy.cpp b/wmserver/src/zidl/window_manager_proxy.cpp index db85b1e8..93449f2f 100644 --- a/wmserver/src/zidl/window_manager_proxy.cpp +++ b/wmserver/src/zidl/window_manager_proxy.cpp @@ -187,32 +187,6 @@ WMError WindowManagerProxy::SetWindowBackgroundBlur(uint32_t windowId, WindowBlu return static_cast(ret); } -WMError WindowManagerProxy::SetAlpha(uint32_t windowId, float alpha) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - if (!data.WriteInterfaceToken(GetDescriptor())) { - WLOGFE("WriteInterfaceToken failed"); - return WMError::WM_ERROR_IPC_FAILED; - } - if (!data.WriteUint32(windowId)) { - WLOGFE("Write windowId failed"); - return WMError::WM_ERROR_IPC_FAILED; - } - if (!data.WriteFloat(alpha)) { - WLOGFE("Write alpha failed"); - return WMError::WM_ERROR_IPC_FAILED; - } - if (Remote()->SendRequest(static_cast(WindowManagerMessage::TRANS_ID_SET_ALPHA), - data, reply, option) != ERR_NONE) { - return WMError::WM_ERROR_IPC_FAILED; - } - - int32_t ret = reply.ReadInt32(); - return static_cast(ret); -} - AvoidArea WindowManagerProxy::GetAvoidAreaByType(uint32_t windowId, AvoidAreaType type) { MessageParcel data; diff --git a/wmserver/src/zidl/window_manager_stub.cpp b/wmserver/src/zidl/window_manager_stub.cpp index 2ae7c7cf..24cb813b 100644 --- a/wmserver/src/zidl/window_manager_stub.cpp +++ b/wmserver/src/zidl/window_manager_stub.cpp @@ -81,13 +81,6 @@ int32_t WindowManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, M reply.WriteInt32(static_cast(errCode)); break; } - case WindowManagerMessage::TRANS_ID_SET_ALPHA: { - uint32_t windowId = data.ReadUint32(); - float alpha = data.ReadFloat(); - WMError errCode = SetAlpha(windowId, alpha); - reply.WriteInt32(static_cast(errCode)); - break; - } case WindowManagerMessage::TRANS_ID_GET_AVOID_AREA: { uint32_t windowId = data.ReadUint32(); AvoidAreaType avoidAreaType = static_cast(data.ReadUint32()); From 36f7770a1b7c24ec2c70e67756b96df4b5d3791a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=AD=8F=E7=AB=8B=E6=B3=A2?= <“leowei80@qq.com”> Date: Tue, 28 Jun 2022 19:45:42 -0700 Subject: [PATCH 44/81] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dbug:=E9=94=80=E6=AF=81?= =?UTF-8?q?=E7=88=B6=E7=AA=97=E5=8F=A3=E6=97=B6=E5=AD=90=E7=AA=97=E5=8F=A3?= =?UTF-8?q?=E6=B2=A1=E6=9C=89=E9=94=80=E6=AF=81=E5=B9=B2=E5=87=80.=20leowe?= =?UTF-8?q?i80@qq.com?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 魏立波 --- wm/src/window_impl.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/wm/src/window_impl.cpp b/wm/src/window_impl.cpp index 51ab9274..2eef9e36 100644 --- a/wm/src/window_impl.cpp +++ b/wm/src/window_impl.cpp @@ -728,12 +728,13 @@ void WindowImpl::DestroyFloatingWindow() // Destroy app floating window if exist if (appFloatingWindowMap_.count(GetWindowId()) > 0) { - auto floatingWindows = appFloatingWindowMap_.at(GetWindowId()); - for (auto& floatingWindow : floatingWindows) { - if (floatingWindow == nullptr) { + auto& floatingWindows = appFloatingWindowMap_.at(GetWindowId()); + for (auto iter = floatingWindows.begin(); iter != floatingWindows.end(); iter = floatingWindows.begin()) { + if ((*iter) == nullptr) { + floatingWindows.erase(iter); continue; } - floatingWindow->Destroy(); + (*iter)->Destroy(); } appFloatingWindowMap_.erase(GetWindowId()); } @@ -755,12 +756,13 @@ void WindowImpl::DestroySubWindow() } if (subWindowMap_.count(GetWindowId()) > 0) { // remove from subWindowMap_ and windowMap_ - std::vector>& subWindows = subWindowMap_.at(GetWindowId()); - for (auto& subWindow : subWindows) { - if (subWindow == nullptr) { + auto& subWindows = subWindowMap_.at(GetWindowId()); + for (auto iter = subWindows.begin(); iter != subWindows.end(); iter = subWindows.begin()) { + if ((*iter) == nullptr) { + subWindows.erase(iter); continue; } - subWindow->Destroy(false); + (*iter)->Destroy(false); } subWindowMap_[GetWindowId()].clear(); subWindowMap_.erase(GetWindowId()); From 8dfe22908aa416757135e9de06dd05bc788c4a6d Mon Sep 17 00:00:00 2001 From: l00574490 Date: Thu, 23 Jun 2022 21:50:29 +0800 Subject: [PATCH 45/81] =?UTF-8?q?=E8=AF=BB=E5=8F=96=E5=8C=85=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: l00574490 Change-Id: I210656846119aaa4d9179f0d9cb9c70597f9909b --- interfaces/innerkits/wm/window.h | 4 +- utils/include/window_helper.h | 24 +++ utils/include/window_property.h | 12 ++ utils/include/window_transition_info.h | 3 + utils/include/wm_common_inner.h | 12 +- utils/src/window_property.cpp | 55 ++++- utils/src/window_transition_info.cpp | 11 + wm/include/window_agent.h | 1 + wm/include/window_impl.h | 10 +- wm/include/zidl/window_interface.h | 2 + wm/include/zidl/window_proxy.h | 1 + wm/src/window_agent.cpp | 9 + wm/src/window_impl.cpp | 153 +++++++++---- wm/src/zidl/window_proxy.cpp | 21 ++ wm/src/zidl/window_stub.cpp | 5 + .../window_mode_support_info_test.cpp | 72 ++----- wmserver/include/minimize_app.h | 1 + wmserver/include/starting_window.h | 3 +- wmserver/include/window_layout_policy.h | 11 +- wmserver/include/window_manager_service.h | 1 - wmserver/include/window_node.h | 2 + wmserver/include/window_node_container.h | 2 + wmserver/include/window_root.h | 3 +- wmserver/src/starting_window.cpp | 21 +- wmserver/src/window_controller.cpp | 3 +- wmserver/src/window_layout_policy.cpp | 204 ++++++++---------- wmserver/src/window_layout_policy_cascade.cpp | 23 +- wmserver/src/window_layout_policy_tile.cpp | 15 +- wmserver/src/window_manager_config.cpp | 6 +- wmserver/src/window_manager_service.cpp | 29 --- wmserver/src/window_node.cpp | 10 + wmserver/src/window_node_container.cpp | 29 ++- wmserver/src/window_pair.cpp | 10 +- wmserver/src/window_root.cpp | 12 +- 34 files changed, 481 insertions(+), 299 deletions(-) diff --git a/interfaces/innerkits/wm/window.h b/interfaces/innerkits/wm/window.h index b850114b..adc85481 100644 --- a/interfaces/innerkits/wm/window.h +++ b/interfaces/innerkits/wm/window.h @@ -232,8 +232,8 @@ public: virtual void OnNewWant(const AAFwk::Want& want) = 0; virtual void SetRequestedOrientation(Orientation) = 0; virtual Orientation GetRequestedOrientation() = 0; - virtual void SetModeSupportInfo(uint32_t modeSupportInfo) = 0; - virtual uint32_t GetModeSupportInfo() const = 0; + virtual void SetRequestModeSupportInfo(uint32_t modeSupportInfo) = 0; + virtual uint32_t GetRequestModeSupportInfo() const = 0; virtual WMError SetTouchHotAreas(const std::vector& rects) = 0; virtual void GetRequestedTouchHotAreas(std::vector& rects) const = 0; diff --git a/utils/include/window_helper.h b/utils/include/window_helper.h index f1653100..c879ce70 100644 --- a/utils/include/window_helper.h +++ b/utils/include/window_helper.h @@ -332,6 +332,30 @@ public: return isOk; } + static bool IsRectSatisfiedWithSizeLimits(const Rect& rect, const WindowSizeLimits& sizeLimits) + { + if (rect.height_ == 0) { + return false; + } + auto curRatio = static_cast(rect.width_) / static_cast(rect.height_); + if (sizeLimits.minWidth_ <= rect.width_ && rect.width_ <= sizeLimits.maxWidth_ && + sizeLimits.minHeight_ <= rect.height_ && rect.height_ <= sizeLimits.maxHeight_ && + sizeLimits.minRatio_ <= curRatio && curRatio <= sizeLimits.maxRatio_) { + return true; + } + return false; + } + + static bool IsOnlySupportSplitAndShowWhenLocked(bool isShowWhenLocked, uint32_t modeSupportInfo) + { + uint32_t splitModeInfo = (WindowModeSupport::WINDOW_MODE_SUPPORT_SPLIT_PRIMARY | + WindowModeSupport::WINDOW_MODE_SUPPORT_SPLIT_SECONDARY); + if (isShowWhenLocked && (splitModeInfo == modeSupportInfo)) { + return true; + } + return false; + } + private: WindowHelper() = default; ~WindowHelper() = default; diff --git a/utils/include/window_property.h b/utils/include/window_property.h index 32cc6e85..9244d2e0 100644 --- a/utils/include/window_property.h +++ b/utils/include/window_property.h @@ -67,11 +67,13 @@ public: void SetWindowSizeChangeReason(WindowSizeChangeReason reason); void SetTokenState(bool hasToken); void SetModeSupportInfo(uint32_t modeSupportInfo); + void SetRequestModeSupportInfo(uint32_t requestModeSupportInfo); void SetDragType(DragType dragType); void SetStretchable(bool stretchable); void SetOriginRect(const Rect& rect); void SetTouchHotAreas(const std::vector& rects); void SetAccessTokenId(uint32_t accessTokenId); + void SetSizeLimits(const WindowSizeLimits& sizeLimits); WindowSizeChangeReason GetWindowSizeChangeReason() const; void SetTransform(const Transform& trans); @@ -104,12 +106,15 @@ public: const PointInfo& GetHitOffset() const; uint32_t GetAnimationFlag() const; uint32_t GetModeSupportInfo() const; + uint32_t GetRequestModeSupportInfo() const; DragType GetDragType() const; bool GetStretchable() const; const Rect& GetOriginRect() const; void GetTouchHotAreas(std::vector& rects) const; uint32_t GetAccessTokenId() const; Transform GetTransform() const; + WindowSizeLimits GetSizeLimits() const; + virtual bool Marshalling(Parcel& parcel) const override; static WindowProperty* Unmarshalling(Parcel& parcel); @@ -122,6 +127,9 @@ private: static void UnmarshallingTouchHotAreas(Parcel& parcel, WindowProperty* property); bool MarshallingTransform(Parcel& parcel) const; static void UnmarshallingTransform(Parcel& parcel, WindowProperty* property); + bool MarshallingWindowSizeLimits(Parcel& parcel) const; + static void UnmarshallingWindowSizeLimits(Parcel& parcel, WindowProperty* property); + std::string windowName_; Rect requestRect_ { 0, 0, 0, 0 }; // window rect requested by the client (without decoration size) Rect windowRect_ { 0, 0, 0, 0 }; // actual window rect @@ -147,7 +155,10 @@ private: uint32_t parentId_ { 0 }; PointInfo hitOffset_ { 0, 0 }; uint32_t animationFlag_ { static_cast(WindowAnimation::DEFAULT) }; + // modeSupportInfo_ means supported modes in runtime, which can be changed uint32_t modeSupportInfo_ {WindowModeSupport::WINDOW_MODE_SUPPORT_ALL}; + // requestModeSupportInfo_ is configured in abilityInfo, usually can't be changed + uint32_t requestModeSupportInfo_ {WindowModeSupport::WINDOW_MODE_SUPPORT_ALL}; WindowSizeChangeReason windowSizeChangeReason_ = WindowSizeChangeReason::UNDEFINED; std::unordered_map sysBarPropMap_ { { WindowType::WINDOW_TYPE_STATUS_BAR, SystemBarProperty() }, @@ -162,6 +173,7 @@ private: Transform trans_; DEFINE_VAR_DEFAULT_FUNC_GET_SET(Orientation, RequestedOrientation, requestedOrientation, Orientation::UNSPECIFIED); DEFINE_VAR_DEFAULT_FUNC_GET_SET(bool, CustomAnimation, isCustomAnimation, false); + WindowSizeLimits sizeLimits_; }; } } diff --git a/utils/include/window_transition_info.h b/utils/include/window_transition_info.h index 3d4de65c..ad959acf 100644 --- a/utils/include/window_transition_info.h +++ b/utils/include/window_transition_info.h @@ -52,6 +52,8 @@ public: void SetWindowType(WindowType windowType); WindowType GetWindowType(); void SetShowFlagWhenLocked(bool isShow); + void SetWindowSupportModes(const std::vector supportModes); + std::vector GetWindowSupportModes(); bool GetShowFlagWhenLocked(); void SetTransitionReason(TransitionReason reason); TransitionReason GetTransitionReason(); @@ -68,6 +70,7 @@ private: bool isShowWhenLocked_ = false; bool isRecent_ = false; TransitionReason reason_ = TransitionReason::ABILITY_TRANSITION; + std::vector supportWindowModes_; }; } // Rosen } // OHOS diff --git a/utils/include/wm_common_inner.h b/utils/include/wm_common_inner.h index f5b0808c..18287c1f 100644 --- a/utils/include/wm_common_inner.h +++ b/utils/include/wm_common_inner.h @@ -16,6 +16,7 @@ #ifndef OHOS_ROSEN_WM_COMMON_INNER_H #define OHOS_ROSEN_WM_COMMON_INNER_H +#include #include #include "wm_common.h" @@ -94,16 +95,19 @@ struct ModeChangeHotZonesConfig { uint32_t secondaryRange_; }; -struct FloatingWindowLimitsConfig { - bool isFloatingWindowLimitsConfigured_; +struct WindowSizeLimits { uint32_t maxWidth_; uint32_t maxHeight_; uint32_t minWidth_; uint32_t minHeight_; float maxRatio_; float minRatio_; - FloatingWindowLimitsConfig() : isFloatingWindowLimitsConfigured_(false), maxWidth_(0), maxHeight_(0), minWidth_(0), - minHeight_(0), maxRatio_(0.0f), minRatio_(0.0f) {} + WindowSizeLimits() : maxWidth_(UINT32_MAX), maxHeight_(UINT32_MAX), minWidth_(0), + minHeight_(0), maxRatio_(FLT_MAX), minRatio_(0.0f) {} + WindowSizeLimits(uint32_t maxWidth, uint32_t maxHeight, uint32_t minWidth, + uint32_t minHeight, float maxRatio, float minRatio) + : maxWidth_(maxWidth), maxHeight_(maxHeight), minWidth_(minWidth), + minHeight_(minHeight), maxRatio_(maxRatio), minRatio_(minRatio) {} }; struct ModeChangeHotZones { diff --git a/utils/src/window_property.cpp b/utils/src/window_property.cpp index 49a03836..046c7ac3 100644 --- a/utils/src/window_property.cpp +++ b/utils/src/window_property.cpp @@ -51,7 +51,7 @@ void WindowProperty::SetWindowType(WindowType type) void WindowProperty::SetWindowMode(WindowMode mode) { - if (!WindowHelper::IsValidWindowMode(mode)) { + if (!WindowHelper::IsValidWindowMode(mode) || !WindowHelper::IsWindowModeSupported(modeSupportInfo_, mode)) { return; } if (!WindowHelper::IsSplitWindowMode(mode_)) { @@ -62,6 +62,9 @@ void WindowProperty::SetWindowMode(WindowMode mode) void WindowProperty::SetLastWindowMode(WindowMode mode) { + if (!WindowHelper::IsWindowModeSupported(modeSupportInfo_, mode)) { + return; + } lastMode_ = mode; } @@ -138,6 +141,11 @@ void WindowProperty::SetWindowFlags(uint32_t flags) flags_ = flags; } +void WindowProperty::SetSizeLimits(const WindowSizeLimits& sizeLimits) +{ + sizeLimits_ = sizeLimits; +} + void WindowProperty::AddWindowFlag(WindowFlag flag) { flags_ |= static_cast(flag); @@ -197,6 +205,9 @@ WindowSizeChangeReason WindowProperty::GetWindowSizeChangeReason() const void WindowProperty::ResumeLastWindowMode() { + if (!WindowHelper::IsWindowModeSupported(modeSupportInfo_, lastMode_)) { + return; + } mode_ = lastMode_; } @@ -335,6 +346,11 @@ void WindowProperty::SetModeSupportInfo(uint32_t modeSupportInfo) modeSupportInfo_ = modeSupportInfo; } +void WindowProperty::SetRequestModeSupportInfo(uint32_t requestModeSupportInfo) +{ + requestModeSupportInfo_ = requestModeSupportInfo; +} + uint32_t WindowProperty::GetWindowId() const { return windowId_; @@ -360,6 +376,11 @@ uint32_t WindowProperty::GetModeSupportInfo() const return modeSupportInfo_; } +uint32_t WindowProperty::GetRequestModeSupportInfo() const +{ + return requestModeSupportInfo_; +} + bool WindowProperty::GetTokenState() const { return tokenState_; @@ -380,6 +401,11 @@ bool WindowProperty::GetStretchable() const return isStretchable_; } +WindowSizeLimits WindowProperty::GetSizeLimits() const +{ + return sizeLimits_; +} + void WindowProperty::SetTouchHotAreas(const std::vector& rects) { touchHotAreas_ = rects; @@ -474,6 +500,23 @@ void WindowProperty::UnmarshallingTransform(Parcel& parcel, WindowProperty* prop property->SetTransform(trans); } +bool WindowProperty::MarshallingWindowSizeLimits(Parcel& parcel) const +{ + if (parcel.WriteUint32(sizeLimits_.maxWidth_) && parcel.WriteUint32(sizeLimits_.maxHeight_) && + parcel.WriteUint32(sizeLimits_.minWidth_) && parcel.WriteUint32(sizeLimits_.minHeight_) && + parcel.WriteFloat(sizeLimits_.maxRatio_) && parcel.WriteFloat(sizeLimits_.minRatio_)) { + return true; + } + return false; +} + +void WindowProperty::UnmarshallingWindowSizeLimits(Parcel& parcel, WindowProperty* property) +{ + WindowSizeLimits sizeLimits = { parcel.ReadUint32(), parcel.ReadUint32(), parcel.ReadUint32(), parcel.ReadUint32(), + parcel.ReadFloat(), parcel.ReadFloat() }; + property->SetSizeLimits(sizeLimits); +} + bool WindowProperty::Marshalling(Parcel& parcel) const { return parcel.WriteString(windowName_) && parcel.WriteInt32(windowRect_.posX_) && @@ -492,10 +535,12 @@ bool WindowProperty::Marshalling(Parcel& parcel) const parcel.WriteUint32(static_cast(windowSizeChangeReason_)) && parcel.WriteBool(tokenState_) && parcel.WriteUint32(callingWindow_) && parcel.WriteUint32(static_cast(requestedOrientation_)) && parcel.WriteBool(turnScreenOn_) && parcel.WriteBool(keepScreenOn_) && - parcel.WriteUint32(modeSupportInfo_) && parcel.WriteUint32(static_cast(dragType_)) && + parcel.WriteUint32(modeSupportInfo_) && parcel.WriteUint32(requestModeSupportInfo_) && + parcel.WriteUint32(static_cast(dragType_)) && parcel.WriteUint32(originRect_.width_) && parcel.WriteUint32(originRect_.height_) && parcel.WriteBool(isStretchable_) && MarshallingTouchHotAreas(parcel) && parcel.WriteUint32(accessTokenId_) && - parcel.WriteBool(isCustomAnimation_) && MarshallingTransform(parcel); + parcel.WriteBool(isCustomAnimation_) && MarshallingTransform(parcel) && + MarshallingWindowSizeLimits(parcel); } WindowProperty* WindowProperty::Unmarshalling(Parcel& parcel) @@ -537,6 +582,7 @@ WindowProperty* WindowProperty::Unmarshalling(Parcel& parcel) property->SetTurnScreenOn(parcel.ReadBool()); property->SetKeepScreenOn(parcel.ReadBool()); property->SetModeSupportInfo(parcel.ReadUint32()); + property->SetRequestModeSupportInfo(parcel.ReadUint32()); property->SetDragType(static_cast(parcel.ReadUint32())); uint32_t w = parcel.ReadUint32(); uint32_t h = parcel.ReadUint32(); @@ -546,6 +592,7 @@ WindowProperty* WindowProperty::Unmarshalling(Parcel& parcel) property->SetAccessTokenId(parcel.ReadUint32()); property->SetCustomAnimation(parcel.ReadBool()); UnmarshallingTransform(parcel, property); + UnmarshallingWindowSizeLimits(parcel, property); return property; } @@ -693,6 +740,7 @@ void WindowProperty::CopyFrom(const sptr& property) turnScreenOn_ = property->turnScreenOn_; keepScreenOn_ = property->keepScreenOn_; modeSupportInfo_ = property->modeSupportInfo_; + requestModeSupportInfo_ = property->requestModeSupportInfo_; dragType_ = property->dragType_; originRect_ = property->originRect_; isStretchable_ = property->isStretchable_; @@ -700,6 +748,7 @@ void WindowProperty::CopyFrom(const sptr& property) accessTokenId_ = property->accessTokenId_; isCustomAnimation_ = property->isCustomAnimation_; trans_ = property->trans_; + sizeLimits_ = property->sizeLimits_; } } } diff --git a/utils/src/window_transition_info.cpp b/utils/src/window_transition_info.cpp index e8784341..6774fb1e 100644 --- a/utils/src/window_transition_info.cpp +++ b/utils/src/window_transition_info.cpp @@ -26,6 +26,7 @@ WindowTransitionInfo::WindowTransitionInfo(sptr in displayId_ = info->displayId_; isShowWhenLocked_ = info->isShowWhenLocked_; isRecent_ = info->isRecent_; + supportWindowModes_ = { 0, 1, 2 }; // 0:fullScreen 1:split 2:floating } void WindowTransitionInfo::SetBundleName(std::string name) @@ -103,6 +104,16 @@ void WindowTransitionInfo::SetShowFlagWhenLocked(bool isShow) isShowWhenLocked_ = isShow; } +void WindowTransitionInfo::SetWindowSupportModes(const std::vector supportModes) +{ + supportWindowModes_.assign(supportModes.begin(), supportModes.end()); +} + +std::vector WindowTransitionInfo::GetWindowSupportModes() +{ + return supportWindowModes_; +} + bool WindowTransitionInfo::GetShowFlagWhenLocked() { return isShowWhenLocked_; diff --git a/wm/include/window_agent.h b/wm/include/window_agent.h index 818accd6..78a350bf 100644 --- a/wm/include/window_agent.h +++ b/wm/include/window_agent.h @@ -29,6 +29,7 @@ public: ~WindowAgent() = default; void UpdateWindowRect(const struct Rect& rect, bool decoStatus, WindowSizeChangeReason reason) override; void UpdateWindowMode(WindowMode mode) override; + void UpdateWindowModeSupportInfo(uint32_t modeSupportInfo) override; void UpdateFocusStatus(bool focused) override; void UpdateAvoidArea(const sptr& avoidArea, AvoidAreaType type) override; void UpdateWindowState(WindowState state) override; diff --git a/wm/include/window_impl.h b/wm/include/window_impl.h index b2f78193..f15d6bd1 100644 --- a/wm/include/window_impl.h +++ b/wm/include/window_impl.h @@ -116,7 +116,7 @@ public: virtual const std::string& GetWindowName() const override; virtual uint32_t GetWindowId() const override; virtual uint32_t GetWindowFlags() const override; - uint32_t GetModeSupportInfo() const override; + uint32_t GetRequestModeSupportInfo() const override; inline NotifyNativeWinDestroyFunc GetNativeDestroyCallback() { return notifyNativefunc_; @@ -191,9 +191,10 @@ public: virtual void RegisterTouchOutsideListener(const sptr& listener) override; virtual void UnregisterTouchOutsideListener(const sptr& listener) override; virtual void SetAceAbilityHandler(const sptr& handler) override; - virtual void SetModeSupportInfo(uint32_t modeSupportInfo) override; + virtual void SetRequestModeSupportInfo(uint32_t modeSupportInfo) override; void UpdateRect(const struct Rect& rect, bool decoStatus, WindowSizeChangeReason reason); void UpdateMode(WindowMode mode); + void UpdateModeSupportInfo(uint32_t modeSupportInfo); virtual void ConsumeKeyEvent(std::shared_ptr& inputEvent) override; virtual void ConsumePointerEvent(std::shared_ptr& inputEvent) override; virtual void RequestFrame() override; @@ -339,7 +340,10 @@ private: void UpdateDragType(); void InitListenerHandler(); bool CheckCameraFloatingWindowMultiCreated(WindowType type); - void SetOrientationFromAbility(); + void GetConfigurationFromAbilityInfo(); + void UpdateTitleButtonVisibility(); + void SetModeSupportInfo(uint32_t modeSupportInfo); + uint32_t GetModeSupportInfo() const; // colorspace, gamut using ColorSpaceConvertMap = struct { diff --git a/wm/include/zidl/window_interface.h b/wm/include/zidl/window_interface.h index bb516d18..e8836552 100644 --- a/wm/include/zidl/window_interface.h +++ b/wm/include/zidl/window_interface.h @@ -31,6 +31,7 @@ public: enum class WindowMessage : uint32_t { TRANS_ID_UPDATE_WINDOW_RECT, TRANS_ID_UPDATE_WINDOW_MODE, + TRANS_ID_UPDATE_MODE_SUPPORT_INFO, TRANS_ID_UPDATE_FOCUS_STATUS, TRANS_ID_UPDATE_AVOID_AREA, TRANS_ID_UPDATE_WINDOW_STATE, @@ -45,6 +46,7 @@ public: virtual void UpdateWindowRect(const struct Rect& rect, bool decoStatus, WindowSizeChangeReason reason) = 0; virtual void UpdateWindowMode(WindowMode mode) = 0; + virtual void UpdateWindowModeSupportInfo(uint32_t modeSupportInfo) = 0; virtual void UpdateFocusStatus(bool focused) = 0; virtual void UpdateAvoidArea(const sptr& avoidArea, AvoidAreaType type) = 0; virtual void UpdateWindowState(WindowState state) = 0; diff --git a/wm/include/zidl/window_proxy.h b/wm/include/zidl/window_proxy.h index ac492560..c0990ada 100644 --- a/wm/include/zidl/window_proxy.h +++ b/wm/include/zidl/window_proxy.h @@ -30,6 +30,7 @@ public: void UpdateWindowRect(const struct Rect& rect, bool decoStatus, WindowSizeChangeReason reason) override; void UpdateWindowMode(WindowMode mode) override; + void UpdateWindowModeSupportInfo(uint32_t modeSupportInfo) override; void UpdateFocusStatus(bool focused) override; void UpdateAvoidArea(const sptr& avoidArea, AvoidAreaType type) override; void UpdateWindowState(WindowState state) override; diff --git a/wm/src/window_agent.cpp b/wm/src/window_agent.cpp index e99a5966..46c91c3d 100644 --- a/wm/src/window_agent.cpp +++ b/wm/src/window_agent.cpp @@ -46,6 +46,15 @@ void WindowAgent::UpdateWindowMode(WindowMode mode) window_->UpdateMode(mode); } +void WindowAgent::UpdateWindowModeSupportInfo(uint32_t modeSupportInfo) +{ + if (window_ == nullptr) { + WLOGFE("window_ is nullptr"); + return; + } + window_->UpdateModeSupportInfo(modeSupportInfo); +} + void WindowAgent::UpdateFocusStatus(bool focused) { if (window_ == nullptr) { diff --git a/wm/src/window_impl.cpp b/wm/src/window_impl.cpp index 105a29e5..90edd807 100644 --- a/wm/src/window_impl.cpp +++ b/wm/src/window_impl.cpp @@ -278,6 +278,11 @@ uint32_t WindowImpl::GetWindowFlags() const return property_->GetWindowFlags(); } +uint32_t WindowImpl::GetRequestModeSupportInfo() const +{ + return property_->GetRequestModeSupportInfo(); +} + uint32_t WindowImpl::GetModeSupportInfo() const { return property_->GetModeSupportInfo(); @@ -465,9 +470,11 @@ WMError WindowImpl::SetUIContent(const std::string& contentInfo, } else { uiContent->Initialize(this, contentInfo, storage); } - // make uiContent_ available after Initialize/Restore + // make uiContent available after Initialize/Restore uiContent_ = std::move(uiContent); + if (state_ == WindowState::STATE_SHOWN) { + UpdateTitleButtonVisibility(); Ace::ViewportConfig config; Rect rect = GetRect(); config.SetSize(rect.width_, rect.height_); @@ -578,7 +585,9 @@ WMError WindowImpl::SetSystemBarProperty(WindowType type, const SystemBarPropert WMError WindowImpl::SetLayoutFullScreen(bool status) { WLOGFI("[Client] Window %{public}u SetLayoutFullScreen: %{public}u", property_->GetWindowId(), status); - if (!IsWindowValid()) { + if (!IsWindowValid() || + !WindowHelper::IsWindowModeSupported(GetModeSupportInfo(), WindowMode::WINDOW_MODE_FULLSCREEN)) { + WLOGFE("invalid window or fullscreen mode is not be supported, winId:%{public}u", property_->GetWindowId()); return WMError::WM_ERROR_INVALID_WINDOW; } WMError ret = SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN); @@ -608,6 +617,11 @@ WMError WindowImpl::SetLayoutFullScreen(bool status) WMError WindowImpl::SetFullScreen(bool status) { WLOGFI("[Client] Window %{public}u SetFullScreen: %{public}d", property_->GetWindowId(), status); + if (!IsWindowValid() || + !WindowHelper::IsWindowModeSupported(GetModeSupportInfo(), WindowMode::WINDOW_MODE_FULLSCREEN)) { + WLOGFE("invalid window or fullscreen mode is not be supported, winId:%{public}u", property_->GetWindowId()); + return WMError::WM_ERROR_INVALID_WINDOW; + } SystemBarProperty statusProperty = GetSystemBarPropertyByType( WindowType::WINDOW_TYPE_STATUS_BAR); SystemBarProperty naviProperty = GetSystemBarPropertyByType( @@ -660,6 +674,68 @@ WMError WindowImpl::UpdateProperty(PropertyChangeAction action) return SingletonContainer::Get().UpdateProperty(property_, action); } +void WindowImpl::GetConfigurationFromAbilityInfo() +{ + auto abilityContext = AbilityRuntime::Context::ConvertTo(context_); + if (abilityContext == nullptr) { + WLOGFE("id:%{public}u is not ability Window", property_->GetWindowId()); + return; + } + auto abilityInfo = abilityContext->GetAbilityInfo(); + if (abilityInfo == nullptr) { + WLOGFE("id:%{public}u Ability window get ability info failed", property_->GetWindowId()); + return; + } + + // get support modes configuration + uint32_t modeSupportInfo = 0; + const auto& supportModes = abilityInfo->windowModes; + for (auto& mode : supportModes) { + if (static_cast(mode) == static_cast(0)) { // 0 : fullScreen + modeSupportInfo |= WindowModeSupport::WINDOW_MODE_SUPPORT_FULLSCREEN; + } else if (static_cast(mode) == static_cast(1)) { // 1 : split + modeSupportInfo |= (WindowModeSupport::WINDOW_MODE_SUPPORT_SPLIT_PRIMARY | + WindowModeSupport::WINDOW_MODE_SUPPORT_SPLIT_SECONDARY); + } else if (static_cast(mode) == static_cast(2)) { // 2 : floating + modeSupportInfo |= WindowModeSupport::WINDOW_MODE_SUPPORT_FLOATING; + } + } + if (modeSupportInfo == 0) { + WLOGFI("mode config param is 0, set all modes"); + modeSupportInfo = WindowModeSupport::WINDOW_MODE_SUPPORT_ALL; + } + SetRequestModeSupportInfo(modeSupportInfo); + + // get window size limits configuration + WindowSizeLimits sizeLimits; + sizeLimits.maxWidth_ = abilityInfo->maxWindowWidth; + sizeLimits.maxHeight_ = abilityInfo->maxWindowHeight; + sizeLimits.minWidth_ = abilityInfo->minWindowWidth; + sizeLimits.minHeight_ = abilityInfo->minWindowHeight; + sizeLimits.maxRatio_ = static_cast(abilityInfo->maxWindowRatio); + sizeLimits.minRatio_ = static_cast(abilityInfo->minWindowRatio); + property_->SetSizeLimits(sizeLimits); + + // get orientation configuration + DisplayOrientation displayOrientation = static_cast( + static_cast(abilityInfo->orientation)); + if (ABILITY_TO_WMS_ORIENTATION_MAP.count(displayOrientation) == 0) { + WLOGFE("id:%{public}u Do not support this Orientation type", property_->GetWindowId()); + return; + } + Orientation orientation = ABILITY_TO_WMS_ORIENTATION_MAP.at(displayOrientation); + if (orientation < Orientation::BEGIN || orientation > Orientation::END) { + WLOGFE("Set orientation from ability failed"); + return; + } + property_->SetRequestedOrientation(orientation); +} + +void WindowImpl::UpdateTitleButtonVisibility() +{ + WLOGFI("[Client] UpdateTitleButtonVisibility"); +} + WMError WindowImpl::Create(const std::string& parentName, const std::shared_ptr& context) { WLOGFI("[Client] Window [name:%{public}s] Create", name_.c_str()); @@ -705,7 +781,7 @@ WMError WindowImpl::Create(const std::string& parentName, const std::shared_ptr< WLOGFI("get stretchable enable:%{public}d", windowSystemConfig_.isStretchable_); property_->SetStretchable(windowSystemConfig_.isStretchable_); } - SetOrientationFromAbility(); + GetConfigurationFromAbilityInfo(); } WMError ret = SingletonContainer::Get().CreateWindow(windowAgent, property_, surfaceNode_, windowId, token); @@ -883,6 +959,19 @@ WMError WindowImpl::Show(uint32_t reason, bool isCustomAnimation) SetDefaultOption(); // set true success when transitionController exist; set false when complete transition property_->SetCustomAnimation(isCustomAnimation); + + // show failed when current mode is not support or window only supports split mode and can show when locked + bool isShowWhenLocked = GetWindowFlags() & static_cast(WindowFlag::WINDOW_FLAG_SHOW_WHEN_LOCKED); + if (!WindowHelper::IsWindowModeSupported(GetModeSupportInfo(), GetMode()) || + WindowHelper::IsOnlySupportSplitAndShowWhenLocked(isShowWhenLocked, GetModeSupportInfo())) { + WLOGFE("current mode is not be supported, windowId: %{public}u", property_->GetWindowId()); + NotifyForegroundFailed(); + return WMError::WM_ERROR_INVALID_WINDOW; + } + + // update title button visibility when show + UpdateTitleButtonVisibility(); + WMError ret = SingletonContainer::Get().AddWindow(property_); RecordLifeCycleExceptionEvent(LifeCycleEvent::SHOW_EVENT, ret); if (ret == WMError::WM_OK || ret == WMError::WM_ERROR_DEATH_RECIPIENT) { @@ -1216,6 +1305,9 @@ WMError WindowImpl::NotifyWindowTransition(TransitionReason reason) return WMError::WM_ERROR_NO_MEM; } auto abilityInfo = abilityContext->GetAbilityInfo(); + if (abilityInfo == nullptr) { + return WMError::WM_ERROR_NULLPTR; + } fromInfo->SetBundleName(context_->GetBundleName()); fromInfo->SetAbilityName(abilityInfo->name); fromInfo->SetWindowMode(property_->GetWindowMode()); @@ -1227,32 +1319,6 @@ WMError WindowImpl::NotifyWindowTransition(TransitionReason reason) return SingletonContainer::Get().NotifyWindowTransition(fromInfo, toInfo); } -void WindowImpl::SetOrientationFromAbility() -{ - auto abilityContext = AbilityRuntime::Context::ConvertTo(context_); - if (abilityContext == nullptr) { - WLOGFE("id:%{public}d is not ability Window", property_->GetWindowId()); - return; - } - auto abilityInfo = abilityContext->GetAbilityInfo(); - if (abilityInfo == nullptr) { - WLOGFE("id:%{public}d Ability window get ability info failed", property_->GetWindowId()); - return; - } - DisplayOrientation displayOrientation = static_cast( - static_cast(abilityInfo->orientation)); - if (ABILITY_TO_WMS_ORIENTATION_MAP.count(displayOrientation) == 0) { - WLOGFE("id:%{public}d Do not support this Orientation type", property_->GetWindowId()); - return; - } - Orientation orientation = ABILITY_TO_WMS_ORIENTATION_MAP.at(displayOrientation); - if (orientation < Orientation::BEGIN || orientation > Orientation::END) { - WLOGFE("Set orientation from ability failed"); - return; - } - property_->SetRequestedOrientation(orientation); -} - WMError WindowImpl::Minimize() { WLOGFI("[Client] Window %{public}u Minimize", property_->GetWindowId()); @@ -1546,20 +1612,15 @@ void WindowImpl::SetAceAbilityHandler(const sptr& handler) aceAbilityHandler_ = handler; } +void WindowImpl::SetRequestModeSupportInfo(uint32_t modeSupportInfo) +{ + property_->SetRequestModeSupportInfo(modeSupportInfo); + SetModeSupportInfo(modeSupportInfo); +} + void WindowImpl::SetModeSupportInfo(uint32_t modeSupportInfo) { property_->SetModeSupportInfo(modeSupportInfo); - UpdateProperty(PropertyChangeAction::ACTION_UPDATE_MODE_SUPPORT_INFO); - if (!WindowHelper::IsWindowModeSupported(modeSupportInfo, GetMode())) { - WLOGFI("current window mode is not supported, force to transform to appropriate mode. window id:%{public}u", - GetWindowId()); - WindowMode mode = WindowHelper::GetWindowModeFromModeSupportInfo(modeSupportInfo); - if (mode != WindowMode::WINDOW_MODE_UNDEFINED) { - SetWindowMode(mode); - } else { - WLOGFE("invalid modeSupportInfo %{public}u", modeSupportInfo); - } - } } void WindowImpl::UpdateRect(const struct Rect& rect, bool decoStatus, WindowSizeChangeReason reason) @@ -1579,7 +1640,7 @@ void WindowImpl::UpdateRect(const struct Rect& rect, bool decoStatus, WindowSize return; } property_->SetWindowRect(rect); - const Rect& originRect = property_->GetOriginRect(); + // update originRect when floating window show for the first time. if (!isOriginRectSet_ && WindowHelper::IsMainFloatingWindow(GetType(), GetMode())) { property_->SetOriginRect(rect); @@ -1591,12 +1652,13 @@ void WindowImpl::UpdateRect(const struct Rect& rect, bool decoStatus, WindowSize if (reason == WindowSizeChangeReason::DRAG || reason == WindowSizeChangeReason::DRAG_END || reason == WindowSizeChangeReason::DRAG_START || reason == WindowSizeChangeReason::RECOVER || reason == WindowSizeChangeReason::MOVE) { - rectToAce = originRect; + rectToAce = property_->GetOriginRect(); } else { property_->SetOriginRect(rect); } } WLOGFI("sizeChange callback size: %{public}lu", (unsigned long)windowChangeListeners_.size()); + NotifySizeChange(rectToAce, reason); if (uiContent_ != nullptr) { Ace::ViewportConfig config; @@ -1621,6 +1683,13 @@ void WindowImpl::UpdateMode(WindowMode mode) } } +void WindowImpl::UpdateModeSupportInfo(uint32_t modeSupportInfo) +{ + WLOGI("modeSupportInfo: %{public}u, winId: %{public}u", modeSupportInfo, GetWindowId()); + SetModeSupportInfo(modeSupportInfo); + UpdateTitleButtonVisibility(); +} + void WindowImpl::ConsumeKeyEvent(std::shared_ptr& keyEvent) { NotifyKeyEvent(keyEvent); diff --git a/wm/src/zidl/window_proxy.cpp b/wm/src/zidl/window_proxy.cpp index 5b3a448c..1d3cd3e4 100644 --- a/wm/src/zidl/window_proxy.cpp +++ b/wm/src/zidl/window_proxy.cpp @@ -76,6 +76,27 @@ void WindowProxy::UpdateWindowMode(WindowMode mode) return; } +void WindowProxy::UpdateWindowModeSupportInfo(uint32_t modeSupportInfo) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_ASYNC); + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("WriteInterfaceToken failed"); + return; + } + if (!data.WriteUint32(modeSupportInfo)) { + WLOGFE("Write WindowMode failed"); + return; + } + + if (Remote()->SendRequest(static_cast(WindowMessage::TRANS_ID_UPDATE_MODE_SUPPORT_INFO), + data, reply, option) != ERR_NONE) { + WLOGFE("SendRequest failed"); + } + return; +} + void WindowProxy::UpdateFocusStatus(bool focused) { MessageParcel data; diff --git a/wm/src/zidl/window_stub.cpp b/wm/src/zidl/window_stub.cpp index c8d00110..fdb2ae7d 100644 --- a/wm/src/zidl/window_stub.cpp +++ b/wm/src/zidl/window_stub.cpp @@ -45,6 +45,11 @@ int WindowStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParce UpdateWindowMode(mode); break; } + case WindowMessage::TRANS_ID_UPDATE_MODE_SUPPORT_INFO: { + uint32_t modeSupportInfo = data.ReadUint32(); + UpdateWindowModeSupportInfo(modeSupportInfo); + break; + } case WindowMessage::TRANS_ID_UPDATE_FOCUS_STATUS: { bool focused = data.ReadBool(); UpdateFocusStatus(focused); diff --git a/wm/test/systemtest/window_mode_support_info_test.cpp b/wm/test/systemtest/window_mode_support_info_test.cpp index 10222bae..a6289f2e 100644 --- a/wm/test/systemtest/window_mode_support_info_test.cpp +++ b/wm/test/systemtest/window_mode_support_info_test.cpp @@ -76,15 +76,15 @@ void WindowModeSupportInfoTest::TearDown() namespace { /** * @tc.name: WindowModeSupportInfo01 - * @tc.desc: SetModeSupportInfo | GetModeSupportInfo + * @tc.desc: SetRequestModeSupportInfo | GetRequestModeSupportInfo * @tc.type: FUNC */ HWTEST_F(WindowModeSupportInfoTest, WindowModeSupportInfo01, Function | MediumTest | Level3) { const sptr& window = Utils::CreateTestWindow(fullAppInfo_1_); - window->SetModeSupportInfo(WindowModeSupport::WINDOW_MODE_SUPPORT_FULLSCREEN); - ASSERT_EQ(WindowModeSupport::WINDOW_MODE_SUPPORT_FULLSCREEN, window->GetModeSupportInfo()); + window->SetRequestModeSupportInfo(WindowModeSupport::WINDOW_MODE_SUPPORT_FULLSCREEN); + ASSERT_EQ(WindowModeSupport::WINDOW_MODE_SUPPORT_FULLSCREEN, window->GetRequestModeSupportInfo()); window->Destroy(); } @@ -97,26 +97,20 @@ HWTEST_F(WindowModeSupportInfoTest, WindowModeSupportInfo02, Function | MediumTe { const sptr& window = Utils::CreateTestWindow(fullAppInfo_1_); - window->SetModeSupportInfo(WindowModeSupport::WINDOW_MODE_SUPPORT_FULLSCREEN); + window->SetRequestModeSupportInfo(WindowModeSupport::WINDOW_MODE_SUPPORT_FULLSCREEN); ASSERT_EQ(WMError::WM_OK, window->Show()); ASSERT_EQ(WindowMode::WINDOW_MODE_FULLSCREEN, window->GetMode()); - ASSERT_EQ(WMError::WM_OK, window->Hide()); window->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING); - ASSERT_EQ(WMError::WM_OK, window->Show()); ASSERT_EQ(WindowMode::WINDOW_MODE_FULLSCREEN, window->GetMode()); - ASSERT_EQ(WMError::WM_OK, window->Hide()); window->SetWindowMode(WindowMode::WINDOW_MODE_SPLIT_PRIMARY); - ASSERT_EQ(WMError::WM_OK, window->Show()); ASSERT_EQ(WindowMode::WINDOW_MODE_FULLSCREEN, window->GetMode()); - ASSERT_EQ(WMError::WM_OK, window->Hide()); window->SetWindowMode(WindowMode::WINDOW_MODE_SPLIT_SECONDARY); - ASSERT_EQ(WMError::WM_OK, window->Show()); ASSERT_EQ(WindowMode::WINDOW_MODE_FULLSCREEN, window->GetMode()); - ASSERT_EQ(WMError::WM_OK, window->Hide()); + ASSERT_EQ(WMError::WM_OK, window->Hide()); window->Destroy(); } @@ -129,56 +123,40 @@ HWTEST_F(WindowModeSupportInfoTest, WindowModeSupportInfo03, Function | MediumTe { const sptr& window = Utils::CreateTestWindow(fullAppInfo_1_); - window->SetModeSupportInfo(WindowModeSupport::WINDOW_MODE_SUPPORT_FULLSCREEN | + window->SetRequestModeSupportInfo(WindowModeSupport::WINDOW_MODE_SUPPORT_FULLSCREEN | WindowModeSupport::WINDOW_MODE_SUPPORT_FLOATING); ASSERT_EQ(WMError::WM_OK, window->Show()); ASSERT_EQ(WindowMode::WINDOW_MODE_FULLSCREEN, window->GetMode()); - ASSERT_EQ(WMError::WM_OK, window->Hide()); window->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING); - ASSERT_EQ(WMError::WM_OK, window->Show()); ASSERT_EQ(WindowMode::WINDOW_MODE_FLOATING, window->GetMode()); - ASSERT_EQ(WMError::WM_OK, window->Hide()); window->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN); - ASSERT_EQ(WMError::WM_OK, window->Show()); ASSERT_EQ(WindowMode::WINDOW_MODE_FULLSCREEN, window->GetMode()); - ASSERT_EQ(WMError::WM_OK, window->Hide()); window->SetWindowMode(WindowMode::WINDOW_MODE_SPLIT_PRIMARY); - ASSERT_EQ(WMError::WM_OK, window->Show()); ASSERT_EQ(WindowMode::WINDOW_MODE_FULLSCREEN, window->GetMode()); - ASSERT_EQ(WMError::WM_OK, window->Hide()); window->SetWindowMode(WindowMode::WINDOW_MODE_SPLIT_SECONDARY); - ASSERT_EQ(WMError::WM_OK, window->Show()); ASSERT_EQ(WindowMode::WINDOW_MODE_FULLSCREEN, window->GetMode()); - ASSERT_EQ(WMError::WM_OK, window->Hide()); + ASSERT_EQ(WMError::WM_OK, window->Hide()); window->Destroy(); } /** * @tc.name: WindowModeSupportInfo04 - * @tc.desc: modeSupportInfo test for single window in case current window mode is not supported. + * @tc.desc: modeSupportInfo test for single window, window mode is not supported when show, show failed * @tc.type: FUNC */ HWTEST_F(WindowModeSupportInfoTest, WindowModeSupportInfo04, Function | MediumTest | Level3) { const sptr& window = Utils::CreateTestWindow(fullAppInfo_1_); - window->SetModeSupportInfo(WindowModeSupport::WINDOW_MODE_SUPPORT_FLOATING | + window->SetRequestModeSupportInfo(WindowModeSupport::WINDOW_MODE_SUPPORT_FLOATING | WindowModeSupport::WINDOW_MODE_SUPPORT_SPLIT_PRIMARY | WindowModeSupport::WINDOW_MODE_SUPPORT_SPLIT_SECONDARY); - ASSERT_EQ(WMError::WM_OK, window->Show()); - ASSERT_EQ(WindowMode::WINDOW_MODE_FLOATING, window->GetMode()); + ASSERT_NE(WMError::WM_OK, window->Show()); ASSERT_EQ(WMError::WM_OK, window->Hide()); - - window->SetModeSupportInfo(WindowModeSupport::WINDOW_MODE_SUPPORT_SPLIT_PRIMARY | - WindowModeSupport::WINDOW_MODE_SUPPORT_SPLIT_SECONDARY); - ASSERT_EQ(WMError::WM_OK, window->Show()); - ASSERT_EQ(WindowMode::WINDOW_MODE_SPLIT_PRIMARY, window->GetMode()); - ASSERT_EQ(WMError::WM_OK, window->Hide()); - window->Destroy(); } @@ -190,9 +168,9 @@ HWTEST_F(WindowModeSupportInfoTest, WindowModeSupportInfo04, Function | MediumTe HWTEST_F(WindowModeSupportInfoTest, WindowModeSupportInfo05, Function | MediumTest | Level3) { const sptr& window1 = Utils::CreateTestWindow(fullAppInfo_1_); - window1->SetModeSupportInfo(WindowModeSupport::WINDOW_MODE_SUPPORT_FULLSCREEN); + window1->SetRequestModeSupportInfo(WindowModeSupport::WINDOW_MODE_SUPPORT_FULLSCREEN); const sptr& window2 = Utils::CreateTestWindow(fullAppInfo_2_); - window2->SetModeSupportInfo(WindowModeSupport::WINDOW_MODE_SUPPORT_ALL); + window2->SetRequestModeSupportInfo(WindowModeSupport::WINDOW_MODE_SUPPORT_ALL); ASSERT_EQ(WMError::WM_OK, window1->Show()); ASSERT_EQ(WMError::WM_OK, window2->Show()); WindowManager::GetInstance().SetWindowLayoutMode(WindowLayoutMode::CASCADE); @@ -213,7 +191,7 @@ HWTEST_F(WindowModeSupportInfoTest, WindowModeSupportInfo05, Function | MediumTe HWTEST_F(WindowModeSupportInfoTest, WindowModeSupportInfo06, Function | MediumTest | Level3) { const sptr& window = Utils::CreateTestWindow(fullAppInfo_1_); - window->SetModeSupportInfo(WindowModeSupport::WINDOW_MODE_SUPPORT_FULLSCREEN); + window->SetRequestModeSupportInfo(WindowModeSupport::WINDOW_MODE_SUPPORT_FULLSCREEN); ASSERT_EQ(WMError::WM_OK, window->Show()); WindowManager::GetInstance().SetWindowLayoutMode(WindowLayoutMode::TILE); usleep(WAIT_SYANC_US); @@ -224,30 +202,6 @@ HWTEST_F(WindowModeSupportInfoTest, WindowModeSupportInfo06, Function | MediumTe WindowManager::GetInstance().SetWindowLayoutMode(WindowLayoutMode::CASCADE); usleep(WAIT_SYANC_US); } - -/** - * @tc.name: WindowModeSupportInfo07 - * @tc.desc: modeSupportInfo test for split - * @tc.type: FUNC - */ -HWTEST_F(WindowModeSupportInfoTest, WindowModeSupportInfo07, Function | MediumTest | Level3) -{ - const sptr& window1 = Utils::CreateTestWindow(fullAppInfo_1_); - window1->SetModeSupportInfo(WindowModeSupport::WINDOW_MODE_SUPPORT_ALL); - const sptr& window2 = Utils::CreateTestWindow(fullAppInfo_2_); - window2->SetModeSupportInfo(WindowModeSupport::WINDOW_MODE_SUPPORT_FULLSCREEN); - ASSERT_EQ(WMError::WM_OK, window1->Show()); - ASSERT_EQ(WMError::WM_OK, window2->Show()); - usleep(WAIT_SYANC_US); - - window1->SetWindowMode(WindowMode::WINDOW_MODE_SPLIT_PRIMARY); - - ASSERT_EQ(WindowMode::WINDOW_MODE_SPLIT_PRIMARY, window1->GetMode()); - ASSERT_EQ(WindowMode::WINDOW_MODE_FULLSCREEN, window2->GetMode()); - - window1->Destroy(); - window2->Destroy(); -} } // namespace } // namespace Rosen } // namespace OHOS \ No newline at end of file diff --git a/wmserver/include/minimize_app.h b/wmserver/include/minimize_app.h index 0d0c0f8e..af827c69 100644 --- a/wmserver/include/minimize_app.h +++ b/wmserver/include/minimize_app.h @@ -29,6 +29,7 @@ enum class MinimizeReason : uint32_t { MINIMIZE_BUTTON, MINIMIZE_ALL, LAYOUT_TILE, + LAYOUT_CASCADE, MAX_APP_COUNT, SPLIT_REPLACE, SPLIT_QUIT, diff --git a/wmserver/include/starting_window.h b/wmserver/include/starting_window.h index fff19014..da718e8a 100644 --- a/wmserver/include/starting_window.h +++ b/wmserver/include/starting_window.h @@ -30,7 +30,8 @@ public: StartingWindow() = delete; ~StartingWindow() = default; - static sptr CreateWindowNode(sptr info, uint32_t winId); + static sptr CreateWindowNode(sptr info, + uint32_t winId, WindowLayoutMode layoutMode); static void HandleClientWindowCreate(sptr& node, sptr& window, uint32_t& windowId, const std::shared_ptr& surfaceNode, sptr& property, int32_t pid, int32_t uid); diff --git a/wmserver/include/window_layout_policy.h b/wmserver/include/window_layout_policy.h index c9f178a3..5421d22b 100644 --- a/wmserver/include/window_layout_policy.h +++ b/wmserver/include/window_layout_policy.h @@ -61,7 +61,6 @@ public: void ProcessDisplayCreate(DisplayId displayId, const std::map& displayRectMap); void ProcessDisplayDestroy(DisplayId displayId, const std::map& displayRectMap); void ProcessDisplaySizeChangeOrRotation(DisplayId displayId, const std::map& displayRectMap); - void SetFloatingWindowLimitsConfig(const FloatingWindowLimitsConfig& floatingWindowLimitsConfig); void SetSplitRatioConfig(const SplitRatioConfig& splitRatioConfig); protected: @@ -91,16 +90,15 @@ protected: void UpdateFloatingWindowSizeForStretchableWindow(const sptr& node, const Rect& displayRect, Rect& winRect) const; - void UpdateFloatingWindowSizeByCustomizedLimits(const sptr& node, + void UpdateFloatingWindowSizeBySizeLimits(const sptr& node, const Rect& displayRect, Rect& winRect) const; void UpdateFloatingWindowSizeBySystemLimits(const sptr& node, const Rect& displayRect, Rect& winRect) const; void LimitWindowPositionWhenInitRectOrMove(const sptr& node, Rect& winRect) const; void LimitWindowPositionWhenDrag(const sptr& node, Rect& winRect) const; - void FixWindowSizeByRatioIfDragBeyondLimitRegion(const sptr& node, Rect& winRect, - const FloatingWindowLimitsConfig& limitConfig); - FloatingWindowLimitsConfig GetCustomizedLimitsConfig(const Rect& displayRect, float virtualPixelRatio); - FloatingWindowLimitsConfig GetSystemLimitsConfig(const Rect& displayRect, float virtualPixelRatio); + void FixWindowSizeByRatioIfDragBeyondLimitRegion(const sptr& node, Rect& winRect); + void UpdateWindowSizeLimits(const sptr& node); + WindowSizeLimits GetSystemSizeLimits(const Rect& displayRect, float virtualPixelRatio); const std::set avoidTypes_ { WindowType::WINDOW_TYPE_STATUS_BAR, @@ -122,7 +120,6 @@ protected: Rect displayGroupRect_; Rect displayGroupLimitRect_; bool isMultiDisplay_ = false; - FloatingWindowLimitsConfig floatingWindowLimitsConfig_; SplitRatioConfig splitRatioConfig_; }; } diff --git a/wmserver/include/window_manager_service.h b/wmserver/include/window_manager_service.h index 34c2bbfe..536c9812 100644 --- a/wmserver/include/window_manager_service.h +++ b/wmserver/include/window_manager_service.h @@ -118,7 +118,6 @@ private: const std::map>& displayInfoMap, DisplayStateChangeType type); WMError GetFocusWindowInfo(sptr& abilityToken); void ConfigureWindowManagerService(); - void ConfigFloatWindowLimits(); static inline SingletonDelegator delegator; std::map accessTokenIdMaps_; diff --git a/wmserver/include/window_node.h b/wmserver/include/window_node.h index 72c76b75..8fb948f1 100644 --- a/wmserver/include/window_node.h +++ b/wmserver/include/window_node.h @@ -71,6 +71,7 @@ public: void SetDragType(DragType dragType); void SetOriginRect(const Rect& rect); void SetTouchHotAreas(const std::vector& rects); + void SetWindowSizeLimits(const WindowSizeLimits& sizeLimits); const sptr& GetWindowToken() const; uint32_t GetWindowId() const; @@ -103,6 +104,7 @@ public: void ResetWindowSizeChangeReason(); void GetTouchHotAreas(std::vector& rects) const; uint32_t GetAccessTokenId() const; + WindowSizeLimits GetWindowSizeLimits() const; bool EnableDefaultAnimation(bool propertyEnabled, bool animationPlayed); sptr parent_; diff --git a/wmserver/include/window_node_container.h b/wmserver/include/window_node_container.h index 849a29d6..c98da05e 100644 --- a/wmserver/include/window_node_container.h +++ b/wmserver/include/window_node_container.h @@ -109,6 +109,7 @@ public: void UpdateAvoidAreaListener(sptr& windowNode, bool haveAvoidAreaListener); void BeforeProcessWindowAvoidAreaChangeWhenDisplayChange() const; void ProcessWindowAvoidAreaChangeWhenDisplayChange() const; + WindowLayoutMode GetCurrentLayoutMode() const; private: void TraverseWindowNode(sptr& root, std::vector>& windowNodes) const; @@ -150,6 +151,7 @@ private: const std::vector& curShowingDisplays); void FillWindowInfo(sptr& windowInfo, const sptr& node) const; bool CheckWindowNodeWhetherInWindowTree(const sptr& node) const; + void UpdateModeSupportInfoWhenKeyguardChange(const sptr& node, bool up); float displayBrightness_ = UNDEFINED_BRIGHTNESS; uint32_t brightnessWindow_ = INVALID_WINDOW_ID; diff --git a/wmserver/include/window_root.h b/wmserver/include/window_root.h index 660802fd..8e7128e9 100644 --- a/wmserver/include/window_root.h +++ b/wmserver/include/window_root.h @@ -93,10 +93,10 @@ public: uint32_t GetWindowIdByObject(const sptr& remoteObject); sptr GetWindowForDumpAceHelpInfo() const; void DestroyLeakStartingWindow(); - void SetFloatingWindowLimitsConfig(const FloatingWindowLimitsConfig& floatingWindowLimitsConfig); void SetSplitRatios(const std::vector& splitRatioNumbers); void SetExitSplitRatios(const std::vector& exitSplitRatios); void MinimizeTargetWindows(std::vector& windowIds); + WindowLayoutMode GetCurrentLayoutMode(DisplayId displayId); private: void OnRemoteDied(const sptr& remoteObject); WMError DestroyWindowInner(sptr& node); @@ -134,7 +134,6 @@ private: this, std::placeholders::_1)); Callback callback_; uint32_t maxAppWindowNumber_ = 100; - FloatingWindowLimitsConfig floatingWindowLimitsConfig_; SplitRatioConfig splitRatioConfig_ = {0.1, 0.9, {}}; }; } diff --git a/wmserver/src/starting_window.cpp b/wmserver/src/starting_window.cpp index c183d372..ca88a923 100644 --- a/wmserver/src/starting_window.cpp +++ b/wmserver/src/starting_window.cpp @@ -32,12 +32,28 @@ SurfaceDraw StartingWindow::surfaceDraw_; static bool g_hasInit = false; std::recursive_mutex StartingWindow::mutex_; -sptr StartingWindow::CreateWindowNode(sptr info, uint32_t winId) +sptr StartingWindow::CreateWindowNode(sptr info, + uint32_t winId, WindowLayoutMode layoutMode) { sptr property = new(std::nothrow) WindowProperty(); - if (property == nullptr) { + if (property == nullptr || info == nullptr) { return nullptr; } + + uint32_t modeSupportInfo = 0; + for (auto mode : info->GetWindowSupportModes()) { + modeSupportInfo |= mode; + } + + // if mode isn't be supported or don't support floating mode in tile mode, create starting window failed + if ((!WindowHelper::IsWindowModeSupported(modeSupportInfo, info->GetWindowMode())) || + ((!WindowHelper::IsWindowModeSupported(modeSupportInfo, WindowMode::WINDOW_MODE_FLOATING)) && + (layoutMode == WindowLayoutMode::TILE)) || + (WindowHelper::IsOnlySupportSplitAndShowWhenLocked(info->GetShowFlagWhenLocked(), modeSupportInfo))) { + WLOGFI("window mode is not be supported or not support floating mode in tile, cancel starting window"); + return nullptr; + } + property->SetRequestRect(info->GetWindowRect()); property->SetWindowMode(info->GetWindowMode()); property->SetDisplayId(info->GetDisplayId()); @@ -56,7 +72,6 @@ sptr StartingWindow::CreateWindowNode(sptr inf if (CreateLeashAndStartingSurfaceNode(node) != WMError::WM_OK) { return nullptr; } - return node; } diff --git a/wmserver/src/window_controller.cpp b/wmserver/src/window_controller.cpp index 1bfb4cda..fa65c722 100644 --- a/wmserver/src/window_controller.cpp +++ b/wmserver/src/window_controller.cpp @@ -52,12 +52,13 @@ void WindowController::StartingWindow(sptr info, sptr(TraceTaskId::STARTING_WINDOW), "wms:async:ShowStartingWindow"); auto node = windowRoot_->FindWindowNodeWithToken(info->GetAbilityToken()); + auto layoutMode = windowRoot_->GetCurrentLayoutMode(info->GetDisplayId()); if (node == nullptr) { if (!isColdStart) { WLOGFE("no windowNode exists but is hot start!"); return; } - node = StartingWindow::CreateWindowNode(info, GenWindowId()); + node = StartingWindow::CreateWindowNode(info, GenWindowId(), layoutMode); if (node == nullptr) { return; } diff --git a/wmserver/src/window_layout_policy.cpp b/wmserver/src/window_layout_policy.cpp index 60e76d18..7e11e7cf 100644 --- a/wmserver/src/window_layout_policy.cpp +++ b/wmserver/src/window_layout_policy.cpp @@ -455,16 +455,20 @@ void WindowLayoutPolicy::CalcAndSetNodeHotZone(const Rect& winRect, const sptrSetTouchHotAreas(hotAreas); } -void WindowLayoutPolicy::FixWindowSizeByRatioIfDragBeyondLimitRegion(const sptr& node, Rect& winRect, - const FloatingWindowLimitsConfig& limitConfig) +void WindowLayoutPolicy::FixWindowSizeByRatioIfDragBeyondLimitRegion(const sptr& node, Rect& winRect) { - if (limitConfig.maxWidth_ == limitConfig.minWidth_ && - limitConfig.maxHeight_ == limitConfig.minHeight_) { + const auto& sizeLimits = node->GetWindowSizeLimits(); + if (sizeLimits.maxWidth_ == sizeLimits.minWidth_ && + sizeLimits.maxHeight_ == sizeLimits.minHeight_) { WLOGFI("window rect can not be changed"); return; } + if (winRect.height_ == 0) { + WLOGFE("the height of window is zero"); + return; + } float curRatio = static_cast(winRect.width_) / static_cast(winRect.height_); - if (limitConfig.minRatio_ <= curRatio && curRatio <= limitConfig.maxRatio_) { + if (sizeLimits.minRatio_ <= curRatio && curRatio <= sizeLimits.maxRatio_) { WLOGFI("window ratio is satisfied with limit ratio, curRatio: %{public}f", curRatio); return; } @@ -490,10 +494,10 @@ void WindowLayoutPolicy::FixWindowSizeByRatioIfDragBeyondLimitRegion(const sptr< limitMaxPosX = dockWinRect.posX_ - static_cast(windowTitleBarH); } - float newRatio = curRatio < limitConfig.minRatio_ ? limitConfig.minRatio_ : limitConfig.maxRatio_; + float newRatio = curRatio < sizeLimits.minRatio_ ? sizeLimits.minRatio_ : sizeLimits.maxRatio_; if ((winRect.posX_ + static_cast(winRect.width_) == limitMinPosX) || (winRect.posX_ == limitMaxPosX)) { // height can not be changed - if (limitConfig.maxHeight_ == limitConfig.minHeight_) { + if (sizeLimits.maxHeight_ == sizeLimits.minHeight_) { return; } winRect.height_ = static_cast(static_cast(winRect.width_) / newRatio); @@ -501,7 +505,7 @@ void WindowLayoutPolicy::FixWindowSizeByRatioIfDragBeyondLimitRegion(const sptr< if ((winRect.posY_ == limitMinPosY) || (winRect.posX_ == limitMaxPosY)) { // width can not be changed - if (limitConfig.maxWidth_ == limitConfig.minWidth_) { + if (sizeLimits.maxWidth_ == sizeLimits.minWidth_) { return; } winRect.width_ = static_cast(static_cast(winRect.height_) * newRatio); @@ -510,79 +514,76 @@ void WindowLayoutPolicy::FixWindowSizeByRatioIfDragBeyondLimitRegion(const sptr< winRect.posX_, winRect.posY_, winRect.width_, winRect.height_); } -FloatingWindowLimitsConfig WindowLayoutPolicy::GetSystemLimitsConfig(const Rect& displayRect, float virtualPixelRatio) +WindowSizeLimits WindowLayoutPolicy::GetSystemSizeLimits(const Rect& displayRect, float virtualPixelRatio) { - FloatingWindowLimitsConfig limitConfig; - limitConfig.maxWidth_ = static_cast(MAX_FLOATING_SIZE * virtualPixelRatio); - limitConfig.maxHeight_ = static_cast(MAX_FLOATING_SIZE * virtualPixelRatio); - limitConfig.minWidth_ = static_cast(MIN_VERTICAL_FLOATING_WIDTH * virtualPixelRatio); - limitConfig.minHeight_ = static_cast(MIN_VERTICAL_FLOATING_HEIGHT * virtualPixelRatio); + WindowSizeLimits systemLimits; + systemLimits.maxWidth_ = static_cast(MAX_FLOATING_SIZE * virtualPixelRatio); + systemLimits.maxHeight_ = static_cast(MAX_FLOATING_SIZE * virtualPixelRatio); + systemLimits.minWidth_ = static_cast(MIN_VERTICAL_FLOATING_WIDTH * virtualPixelRatio); + systemLimits.minHeight_ = static_cast(MIN_VERTICAL_FLOATING_HEIGHT * virtualPixelRatio); if (displayRect.width_ > displayRect.height_) { - std::swap(limitConfig.minWidth_, limitConfig.minHeight_); + std::swap(systemLimits.minWidth_, systemLimits.minHeight_); } WLOGFI("maxWidth: %{public}u, maxHeight: %{public}u, minWidth: %{public}u, minHeight: %{public}u " - "maxRatio: %{public}f, minRatio: %{public}f", limitConfig.maxWidth_, limitConfig.maxHeight_, - limitConfig.minWidth_, limitConfig.minHeight_, limitConfig.maxRatio_, limitConfig.minRatio_); - return limitConfig; + "maxRatio: %{public}f, minRatio: %{public}f", systemLimits.maxWidth_, systemLimits.maxHeight_, + systemLimits.minWidth_, systemLimits.minHeight_, systemLimits.maxRatio_, systemLimits.minRatio_); + return systemLimits; } -FloatingWindowLimitsConfig WindowLayoutPolicy::GetCustomizedLimitsConfig(const Rect& displayRect, - float virtualPixelRatio) +void WindowLayoutPolicy::UpdateWindowSizeLimits(const sptr& node) { - const auto& systemLimits = GetSystemLimitsConfig(displayRect, virtualPixelRatio); - FloatingWindowLimitsConfig newLimitConfig = systemLimits; + const auto& displayRect = displayGroupInfo_->GetDisplayRect(node->GetDisplayId()); + const auto& virtualPixelRatio = GetVirtualPixelRatio(node->GetDisplayId()); + const auto& systemLimits = GetSystemSizeLimits(displayRect, virtualPixelRatio); + const auto& customizedLimits = node->GetWindowSizeLimits(); + WindowSizeLimits newLimits = systemLimits; + // configured limits of floating window - uint32_t configuredMaxWidth = static_cast(floatingWindowLimitsConfig_.maxWidth_ * virtualPixelRatio); - uint32_t configuredMaxHeight = static_cast(floatingWindowLimitsConfig_.maxHeight_ * virtualPixelRatio); - uint32_t configuredMinWidth = static_cast(floatingWindowLimitsConfig_.minWidth_ * virtualPixelRatio); - uint32_t configuredMinHeight = static_cast(floatingWindowLimitsConfig_.minHeight_ * virtualPixelRatio); - float configuredMaxRatio = floatingWindowLimitsConfig_.maxRatio_; - float configuredMinRatio = floatingWindowLimitsConfig_.minRatio_; + uint32_t configuredMaxWidth = static_cast(customizedLimits.maxWidth_ * virtualPixelRatio); + uint32_t configuredMaxHeight = static_cast(customizedLimits.maxHeight_ * virtualPixelRatio); + uint32_t configuredMinWidth = static_cast(customizedLimits.minWidth_ * virtualPixelRatio); + uint32_t configuredMinHeight = static_cast(customizedLimits.minHeight_ * virtualPixelRatio); + float configuerdMaxRatio = customizedLimits.maxRatio_; + float configuerdMinRatio = customizedLimits.minRatio_; // calculate new limit size if (systemLimits.minWidth_ <= configuredMaxWidth && configuredMaxWidth <= systemLimits.maxWidth_) { - newLimitConfig.maxWidth_ = configuredMaxWidth; + newLimits.maxWidth_ = configuredMaxWidth; } if (systemLimits.minHeight_ <= configuredMaxHeight && configuredMaxHeight <= systemLimits.maxHeight_) { - newLimitConfig.maxHeight_ = configuredMaxHeight; + newLimits.maxHeight_ = configuredMaxHeight; } - if (systemLimits.minWidth_ <= configuredMinWidth && configuredMinWidth <= newLimitConfig.maxWidth_) { - newLimitConfig.minWidth_ = configuredMinWidth; + if (systemLimits.minWidth_ <= configuredMinWidth && configuredMinWidth <= newLimits.maxWidth_) { + newLimits.minWidth_ = configuredMinWidth; } - if (systemLimits.minHeight_ <= configuredMinHeight && configuredMinHeight <= newLimitConfig.maxHeight_) { - newLimitConfig.minHeight_ = configuredMinHeight; + if (systemLimits.minHeight_ <= configuredMinHeight && configuredMinHeight <= newLimits.maxHeight_) { + newLimits.minHeight_ = configuredMinHeight; } // calculate new limit ratio - newLimitConfig.maxRatio_ = static_cast(newLimitConfig.maxWidth_) / - static_cast(newLimitConfig.minHeight_); - newLimitConfig.minRatio_ = static_cast(newLimitConfig.minWidth_) / - static_cast(newLimitConfig.maxHeight_); - if (newLimitConfig.minRatio_ <= configuredMaxRatio && configuredMaxRatio <= newLimitConfig.maxRatio_) { - newLimitConfig.maxRatio_ = configuredMaxRatio; + newLimits.maxRatio_ = static_cast(newLimits.maxWidth_) / static_cast(newLimits.minHeight_); + newLimits.minRatio_ = static_cast(newLimits.minWidth_) / static_cast(newLimits.maxHeight_); + if (newLimits.minRatio_ <= configuerdMaxRatio && configuerdMaxRatio <= newLimits.maxRatio_) { + newLimits.maxRatio_ = configuerdMaxRatio; } - if (newLimitConfig.minRatio_ <= configuredMinRatio && configuredMinRatio <= newLimitConfig.maxRatio_) { - newLimitConfig.minRatio_ = configuredMinRatio; + if (newLimits.minRatio_ <= configuerdMinRatio && configuerdMinRatio <= newLimits.maxRatio_) { + newLimits.minRatio_ = configuerdMinRatio; } // recalculate limit size by new ratio - uint32_t newMaxWidth = static_cast(static_cast(newLimitConfig.maxHeight_) * - newLimitConfig.maxRatio_); - newLimitConfig.maxWidth_ = std::min(newMaxWidth, newLimitConfig.maxWidth_); - uint32_t newMinWidth = static_cast(static_cast(newLimitConfig.minHeight_) * - newLimitConfig.minRatio_); - newLimitConfig.minWidth_ = std::max(newMinWidth, newLimitConfig.minWidth_); - uint32_t newMaxHeight = static_cast(static_cast(newLimitConfig.maxWidth_) / - newLimitConfig.minRatio_); - newLimitConfig.maxHeight_ = std::min(newMaxHeight, newLimitConfig.maxHeight_); - uint32_t newMinHeight = static_cast(static_cast(newLimitConfig.minWidth_) / - newLimitConfig.maxRatio_); - newLimitConfig.minHeight_ = std::max(newMinHeight, newLimitConfig.minHeight_); + uint32_t newMaxWidth = static_cast(static_cast(newLimits.maxHeight_) * newLimits.maxRatio_); + newLimits.maxWidth_ = std::min(newMaxWidth, newLimits.maxWidth_); + uint32_t newMinWidth = static_cast(static_cast(newLimits.minHeight_) * newLimits.minRatio_); + newLimits.minWidth_ = std::max(newMinWidth, newLimits.minWidth_); + uint32_t newMaxHeight = static_cast(static_cast(newLimits.maxWidth_) / newLimits.minRatio_); + newLimits.maxHeight_ = std::min(newMaxHeight, newLimits.maxHeight_); + uint32_t newMinHeight = static_cast(static_cast(newLimits.minWidth_) / newLimits.maxRatio_); + newLimits.minHeight_ = std::max(newMinHeight, newLimits.minHeight_); WLOGFI("maxWidth: %{public}u, maxHeight: %{public}u, minWidth: %{public}u, minHeight: %{public}u, " - "maxRatio: %{public}f, minRatio: %{public}f", newLimitConfig.maxWidth_, newLimitConfig.maxHeight_, - newLimitConfig.minWidth_, newLimitConfig.minHeight_, newLimitConfig.maxRatio_, newLimitConfig.minRatio_); - return newLimitConfig; + "maxRatio: %{public}f, minRatio: %{public}f", newLimits.maxWidth_, newLimits.maxHeight_, + newLimits.minWidth_, newLimits.minHeight_, newLimits.maxRatio_, newLimits.minRatio_); + node->SetWindowSizeLimits(newLimits); } void WindowLayoutPolicy::UpdateFloatingWindowSizeForStretchableWindow(const sptr& node, @@ -604,12 +605,12 @@ void WindowLayoutPolicy::UpdateFloatingWindowSizeForStretchableWindow(const sptr } } // limit minimum size of window - const auto& systemLimits = const_cast(this)-> - GetSystemLimitsConfig(displayRect, GetVirtualPixelRatio(node->GetDisplayId())); - float scale = std::min(static_cast(winRect.width_) / systemLimits.minWidth_, - static_cast(winRect.height_) / systemLimits.minHeight_); + + const auto& sizeLimits = node->GetWindowSizeLimits(); + float scale = std::min(static_cast(winRect.width_) / sizeLimits.minWidth_, + static_cast(winRect.height_) / sizeLimits.minHeight_); if (scale == 0) { - WLOGE("invalid systemLimits"); + WLOGE("invalid sizeLimits"); return; } if (scale < 1.0f) { @@ -618,45 +619,47 @@ void WindowLayoutPolicy::UpdateFloatingWindowSizeForStretchableWindow(const sptr } } -void WindowLayoutPolicy::UpdateFloatingWindowSizeByCustomizedLimits(const sptr& node, +void WindowLayoutPolicy::UpdateFloatingWindowSizeBySizeLimits(const sptr& node, const Rect& displayRect, Rect& winRect) const { // get new limit config with the settings of system and app - const auto& customizedLimits = const_cast(this)-> - GetCustomizedLimitsConfig(displayRect, GetVirtualPixelRatio(node->GetDisplayId())); + const auto& sizeLimits = node->GetWindowSizeLimits(); - // limit minimum and maximum size of floating (not system type) window - winRect.width_ = std::max(customizedLimits.minWidth_, winRect.width_); - winRect.height_ = std::max(customizedLimits.minHeight_, winRect.height_); - winRect.width_ = std::min(customizedLimits.maxWidth_, winRect.width_); - winRect.height_ = std::min(customizedLimits.maxHeight_, winRect.height_); + // limit minimum size of floating (not system type) window + if (!WindowHelper::IsSystemWindow(node->GetWindowType()) || + node->GetWindowType() == WindowType::WINDOW_TYPE_FLOAT_CAMERA) { + winRect.width_ = std::max(sizeLimits.minWidth_, winRect.width_); + winRect.height_ = std::max(sizeLimits.minHeight_, winRect.height_); + } + winRect.width_ = std::min(sizeLimits.maxWidth_, winRect.width_); + winRect.height_ = std::min(sizeLimits.maxHeight_, winRect.height_); WLOGFD("After limit by size, winRect: %{public}d %{public}d %{public}u %{public}u", winRect.posX_, winRect.posY_, winRect.width_, winRect.height_); // width and height can not be changed - if (customizedLimits.maxWidth_ == customizedLimits.minWidth_ && - customizedLimits.maxHeight_ == customizedLimits.minHeight_) { - winRect.width_ = customizedLimits.maxWidth_; - winRect.height_ = customizedLimits.maxHeight_; + if (sizeLimits.maxWidth_ == sizeLimits.minWidth_ && + sizeLimits.maxHeight_ == sizeLimits.minHeight_) { + winRect.width_ = sizeLimits.maxWidth_; + winRect.height_ = sizeLimits.maxHeight_; WLOGFD("window rect can not be changed"); return; } float curRatio = static_cast(winRect.width_) / static_cast(winRect.height_); - if ((customizedLimits.minWidth_ <= winRect.width_ && winRect.width_ <= customizedLimits.maxWidth_) && - (customizedLimits.minHeight_ <= winRect.height_ && winRect.height_ <= customizedLimits.maxHeight_) && - (customizedLimits.minRatio_ <= curRatio && curRatio <= customizedLimits.maxRatio_)) { - WLOGFD("window size and ratio is satisfied with limit ratio, curSize: [%{public}d, %{public}d], " + // there is no need to fix size by ratio if this is not main floating window + if (!WindowHelper::IsMainFloatingWindow(node->GetWindowType(), node->GetWindowMode()) || + (sizeLimits.minRatio_ <= curRatio && curRatio <= sizeLimits.maxRatio_)) { + WLOGFD("window is system window or ratio is satisfied with limits, curSize: [%{public}d, %{public}d], " "curRatio: %{public}f", winRect.width_, winRect.height_, curRatio); return; } - float newRatio = curRatio < customizedLimits.minRatio_ ? customizedLimits.minRatio_ : customizedLimits.maxRatio_; - if (customizedLimits.maxWidth_ == customizedLimits.minWidth_) { + float newRatio = curRatio < sizeLimits.minRatio_ ? sizeLimits.minRatio_ : sizeLimits.maxRatio_; + if (sizeLimits.maxWidth_ == sizeLimits.minWidth_) { winRect.height_ = static_cast(static_cast(winRect.width_) / newRatio); return; } - if (customizedLimits.maxHeight_ == customizedLimits.minHeight_) { + if (sizeLimits.maxHeight_ == sizeLimits.minHeight_) { winRect.width_ = static_cast(static_cast(winRect.height_) * newRatio); return; } @@ -673,25 +676,6 @@ void WindowLayoutPolicy::UpdateFloatingWindowSizeByCustomizedLimits(const sptr& node, - const Rect& displayRect, Rect& winRect) const -{ - const auto& systemLimits = const_cast(this)-> - GetSystemLimitsConfig(displayRect, GetVirtualPixelRatio(node->GetDisplayId())); - - // limit minimum size of floating (not system type) window - if (!WindowHelper::IsSystemWindow(node->GetWindowType()) || - node->GetWindowType() == WindowType::WINDOW_TYPE_FLOAT_CAMERA) { - winRect.width_ = std::max(systemLimits.minWidth_, winRect.width_); - winRect.height_ = std::max(systemLimits.minHeight_, winRect.height_); - } - // limit maximum size of all floating window - winRect.width_ = std::min(systemLimits.maxWidth_, winRect.width_); - winRect.height_ = std::min(systemLimits.maxHeight_, winRect.height_); - WLOGFI("After limit by system config, winRect: %{public}d %{public}d %{public}u %{public}u", - winRect.posX_, winRect.posY_, winRect.width_, winRect.height_); -} - void WindowLayoutPolicy::LimitFloatingWindowSize(const sptr& node, const Rect& displayRect, Rect& winRect) const @@ -700,12 +684,7 @@ void WindowLayoutPolicy::LimitFloatingWindowSize(const sptr& node, return; } Rect oriWinRect = winRect; - if (floatingWindowLimitsConfig_.isFloatingWindowLimitsConfigured_ && - (WindowHelper::IsMainFloatingWindow(node->GetWindowType(), node->GetWindowMode()))) { - UpdateFloatingWindowSizeByCustomizedLimits(node, displayRect, winRect); - } else { - UpdateFloatingWindowSizeBySystemLimits(node, displayRect, winRect); - } + UpdateFloatingWindowSizeBySizeLimits(node, displayRect, winRect); if (node->GetStretchable() && WindowHelper::IsMainFloatingWindow(node->GetWindowType(), node->GetWindowMode())) { @@ -736,12 +715,8 @@ void WindowLayoutPolicy::LimitMainFloatingWindowPosition(const sptr& // if drag or move window, limit size and position if (reason == WindowSizeChangeReason::DRAG) { LimitWindowPositionWhenDrag(node, winRect); - if (floatingWindowLimitsConfig_.isFloatingWindowLimitsConfigured_ && - (WindowHelper::IsMainFloatingWindow(node->GetWindowType(), node->GetWindowMode()))) { - const auto& limitConfig = const_cast(this)-> GetCustomizedLimitsConfig( - displayGroupInfo_->GetDisplayRect(node->GetDisplayId()), GetVirtualPixelRatio(node->GetDisplayId())); - const_cast(this)-> - FixWindowSizeByRatioIfDragBeyondLimitRegion(node, winRect, limitConfig); + if (WindowHelper::IsMainFloatingWindow(node->GetWindowType(), node->GetWindowMode())) { + const_cast(this)->FixWindowSizeByRatioIfDragBeyondLimitRegion(node, winRect); } } else { // Limit window position, such as init window rect when show @@ -989,11 +964,6 @@ void WindowLayoutPolicy::SetSplitRatioConfig(const SplitRatioConfig& splitRatioC splitRatioConfig_ = splitRatioConfig; } -void WindowLayoutPolicy::SetFloatingWindowLimitsConfig(const FloatingWindowLimitsConfig& floatingWindowLimitsConfig) -{ - floatingWindowLimitsConfig_ = floatingWindowLimitsConfig; -} - Rect WindowLayoutPolicy::GetInitalDividerRect(DisplayId displayId) const { return INVALID_EMPTY_RECT; diff --git a/wmserver/src/window_layout_policy_cascade.cpp b/wmserver/src/window_layout_policy_cascade.cpp index 5b5bc0a1..e0a68fc0 100644 --- a/wmserver/src/window_layout_policy_cascade.cpp +++ b/wmserver/src/window_layout_policy_cascade.cpp @@ -14,6 +14,8 @@ */ #include "window_layout_policy_cascade.h" + +#include "minimize_app.h" #include "window_helper.h" #include "window_inner_manager.h" #include "window_manager_hilog.h" @@ -179,6 +181,10 @@ void WindowLayoutPolicyCascade::AddWindowNode(const sptr& node) WLOGFE("window property is nullptr."); return; } + + // update window size limits when add window + UpdateWindowSizeLimits(node); + if (WindowHelper::IsEmptyRect(property->GetRequestRect())) { SetCascadeRect(node); } @@ -466,6 +472,12 @@ void WindowLayoutPolicyCascade::Reorder() WLOGFI("get node failed or not app window."); continue; } + // if window don't support floating mode, or default rect of cascade is not satisfied with limits + if (!WindowHelper::IsWindowModeSupported(node->GetModeSupportInfo(), WindowMode::WINDOW_MODE_FLOATING) || + !WindowHelper::IsRectSatisfiedWithSizeLimits(rect, node->GetWindowSizeLimits())) { + MinimizeApp::AddNeedMinimizeApp(node, MinimizeReason::LAYOUT_CASCADE); + continue; + } if (isFirstReorderedWindow) { isFirstReorderedWindow = false; } else { @@ -473,13 +485,12 @@ void WindowLayoutPolicyCascade::Reorder() } node->SetRequestRect(rect); node->SetDecoStatus(true); - if (node->GetWindowMode() != WindowMode::WINDOW_MODE_FLOATING && - WindowHelper::IsWindowModeSupported(node->GetModeSupportInfo(), WindowMode::WINDOW_MODE_FLOATING)) { - node->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING); - if (node->GetWindowToken()) { - node->GetWindowToken()->UpdateWindowMode(WindowMode::WINDOW_MODE_FLOATING); - } + if (node->GetWindowMode() != WindowMode::WINDOW_MODE_FLOATING) { + node->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING); + if (node->GetWindowToken()) { + node->GetWindowToken()->UpdateWindowMode(WindowMode::WINDOW_MODE_FLOATING); } + } WLOGFI("Cascade reorder Id: %{public}d, rect:[%{public}d, %{public}d, %{public}d, %{public}d]", node->GetWindowId(), rect.posX_, rect.posY_, rect.width_, rect.height_); } diff --git a/wmserver/src/window_layout_policy_tile.cpp b/wmserver/src/window_layout_policy_tile.cpp index 87423252..438099bf 100644 --- a/wmserver/src/window_layout_policy_tile.cpp +++ b/wmserver/src/window_layout_policy_tile.cpp @@ -118,6 +118,10 @@ void WindowLayoutPolicyTile::InitTileWindowRects(DisplayId displayId) void WindowLayoutPolicyTile::AddWindowNode(const sptr& node) { WM_FUNCTION_TRACE(); + + // update window size limits when add window + UpdateWindowSizeLimits(node); + if (WindowHelper::IsMainWindow(node->GetWindowType())) { DisplayId displayId = node->GetDisplayId(); ForegroundNodeQueuePushBack(node, displayId); @@ -206,6 +210,12 @@ void WindowLayoutPolicyTile::ForegroundNodeQueuePushBack(const sptr& if (iter != foregroundNodes.end()) { return; } + + if (!WindowHelper::IsWindowModeSupported(node->GetModeSupportInfo(), WindowMode::WINDOW_MODE_FLOATING)) { + WLOGFD("window don't support tile mode, winId: %{public}d", node->GetWindowId()); + MinimizeApp::AddNeedMinimizeApp(node, MinimizeReason::LAYOUT_TILE); + return; + } WLOGFI("add win in tile, displayId: %{public}" PRIu64", winId: %{public}d", displayId, node->GetWindowId()); while (foregroundNodes.size() >= maxTileWinNumMap_[displayId]) { auto removeNode = foregroundNodes.front(); @@ -247,7 +257,8 @@ void WindowLayoutPolicyTile::AssignNodePropertyForTileWindows(DisplayId displayI auto rectIt = presetRect.begin(); for (auto node : foregroundNodesMap_[displayId]) { auto& rect = (*rectIt); - if (WindowHelper::IsWindowModeSupported(node->GetModeSupportInfo(), WindowMode::WINDOW_MODE_FLOATING)) { + if (WindowHelper::IsWindowModeSupported(node->GetModeSupportInfo(), WindowMode::WINDOW_MODE_FLOATING) && + WindowHelper::IsRectSatisfiedWithSizeLimits(rect, node->GetWindowSizeLimits())) { node->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING); if (node->GetWindowToken()) { node->GetWindowToken()->UpdateWindowMode(WindowMode::WINDOW_MODE_FLOATING); @@ -257,6 +268,8 @@ void WindowLayoutPolicyTile::AssignNodePropertyForTileWindows(DisplayId displayI WLOGFI("set rect for qwin id: %{public}d [%{public}d %{public}d %{public}d %{public}d]", node->GetWindowId(), rect.posX_, rect.posY_, rect.width_, rect.height_); rectIt++; + } else { + MinimizeApp::AddNeedMinimizeApp(node, MinimizeReason::LAYOUT_TILE); } } } diff --git a/wmserver/src/window_manager_config.cpp b/wmserver/src/window_manager_config.cpp index f958df33..f217047d 100644 --- a/wmserver/src/window_manager_config.cpp +++ b/wmserver/src/window_manager_config.cpp @@ -73,14 +73,12 @@ bool WindowManagerConfig::LoadConfigXml() continue; } if (!xmlStrcmp(nodeName, reinterpret_cast("maxAppWindowNumber")) || - !xmlStrcmp(nodeName, reinterpret_cast("modeChangeHotZones")) || - !xmlStrcmp(nodeName, reinterpret_cast("floatingWindowLimitSize"))) { + !xmlStrcmp(nodeName, reinterpret_cast("modeChangeHotZones"))) { ReadIntNumbersConfigInfo(curNodePtr); continue; } - if (!xmlStrcmp(nodeName, reinterpret_cast("floatingWindowLimitRatio")) || - !xmlStrcmp(nodeName, reinterpret_cast("splitRatios")) || + if (!xmlStrcmp(nodeName, reinterpret_cast("splitRatios")) || !xmlStrcmp(nodeName, reinterpret_cast("exitSplitRatios"))) { ReadFloatNumbersConfigInfo(curNodePtr); continue; diff --git a/wmserver/src/window_manager_service.cpp b/wmserver/src/window_manager_service.cpp index 3cff8032..7421b291 100644 --- a/wmserver/src/window_manager_service.cpp +++ b/wmserver/src/window_manager_service.cpp @@ -237,33 +237,6 @@ int WindowManagerService::Dump(int fd, const std::vector& args) }).get(); } -void WindowManagerService::ConfigFloatWindowLimits() -{ - const auto& intNumbersConfig = WindowManagerConfig::GetIntNumbersConfig(); - const auto& floatNumbersConfig = WindowManagerConfig::GetFloatNumbersConfig(); - - FloatingWindowLimitsConfig floatingWindowLimitsConfig; - if (intNumbersConfig.count("floatingWindowLimitSize") != 0) { - auto numbers = intNumbersConfig.at("floatingWindowLimitSize"); - if (numbers.size() == 4) { // 4, limitSize - floatingWindowLimitsConfig.maxWidth_ = static_cast(numbers[0]); // 0 max width - floatingWindowLimitsConfig.maxHeight_ = static_cast(numbers[1]); // 1 max height - floatingWindowLimitsConfig.minWidth_ = static_cast(numbers[2]); // 2 min width - floatingWindowLimitsConfig.minHeight_ = static_cast(numbers[3]); // 3 min height - floatingWindowLimitsConfig.isFloatingWindowLimitsConfigured_ = true; - } - } - if (floatNumbersConfig.count("floatingWindowLimitRatio") != 0) { - auto numbers = floatNumbersConfig.at("floatingWindowLimitRatio"); - if (numbers.size() == 2) { // 2, limitRatio - floatingWindowLimitsConfig.maxRatio_ = static_cast(numbers[0]); // 0 max ratio - floatingWindowLimitsConfig.minRatio_ = static_cast(numbers[1]); // 1 min ratio - floatingWindowLimitsConfig.isFloatingWindowLimitsConfigured_ = true; - } - } - windowRoot_->SetFloatingWindowLimitsConfig(floatingWindowLimitsConfig); -} - void WindowManagerService::ConfigureWindowManagerService() { const auto& enableConfig = WindowManagerConfig::GetEnableConfig(); @@ -301,8 +274,6 @@ void WindowManagerService::ConfigureWindowManagerService() } } - ConfigFloatWindowLimits(); - if (floatNumbersConfig.count("splitRatios") != 0) { windowRoot_->SetSplitRatios(floatNumbersConfig.at("splitRatios")); } diff --git a/wmserver/src/window_node.cpp b/wmserver/src/window_node.cpp index e4d89d49..ebe6e0d9 100644 --- a/wmserver/src/window_node.cpp +++ b/wmserver/src/window_node.cpp @@ -196,6 +196,16 @@ void WindowNode::SetTouchHotAreas(const std::vector& rects) touchHotAreas_ = rects; } +void WindowNode::SetWindowSizeLimits(const WindowSizeLimits& sizeLimits) +{ + property_->SetSizeLimits(sizeLimits); +} + +WindowSizeLimits WindowNode::GetWindowSizeLimits() const +{ + return property_->GetSizeLimits(); +} + DragType WindowNode::GetDragType() const { return property_->GetDragType(); diff --git a/wmserver/src/window_node_container.cpp b/wmserver/src/window_node_container.cpp index a1ec32f2..0a26923b 100644 --- a/wmserver/src/window_node_container.cpp +++ b/wmserver/src/window_node_container.cpp @@ -1562,6 +1562,25 @@ WMError WindowNodeContainer::SwitchLayoutPolicy(WindowLayoutMode dstMode, Displa return WMError::WM_OK; } +void WindowNodeContainer::UpdateModeSupportInfoWhenKeyguardChange(const sptr& node, bool up) +{ + if (!WindowHelper::IsWindowModeSupported(node->GetWindowProperty()->GetRequestModeSupportInfo(), + WindowMode::WINDOW_MODE_SPLIT_PRIMARY)) { + WLOGFD("window doesn't support split mode, winId: %{public}d", node->GetWindowId()); + return; + } + uint32_t modeSupportInfo; + if (up) { + modeSupportInfo = node->GetModeSupportInfo() & (~WindowModeSupport::WINDOW_MODE_SUPPORT_SPLIT_PRIMARY); + } else { + modeSupportInfo = node->GetModeSupportInfo() | WindowModeSupport::WINDOW_MODE_SUPPORT_SPLIT_PRIMARY; + } + node->SetModeSupportInfo(modeSupportInfo); + if (node->GetWindowToken() != nullptr) { + node->GetWindowToken()->UpdateWindowModeSupportInfo(modeSupportInfo); + } +} + void WindowNodeContainer::RaiseInputMethodWindowPriorityIfNeeded(const sptr& node) const { if (node->GetWindowType() != WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT || !isScreenLocked_) { @@ -1604,6 +1623,8 @@ void WindowNodeContainer::ReZOrderShowWhenLockedWindows(bool up) } } + UpdateModeSupportInfoWhenKeyguardChange(needReZOrderNode, up); + parentNode->children_.insert(position, needReZOrderNode); if (up && WindowHelper::IsSplitWindowMode(needReZOrderNode->GetWindowMode())) { needReZOrderNode->GetWindowProperty()->ResumeLastWindowMode(); @@ -1617,8 +1638,7 @@ void WindowNodeContainer::ReZOrderShowWhenLockedWindows(bool up) } windowPair->UpdateIfSplitRelated(needReZOrderNode); } - WLOGFI("ShowWhenLocked window %{public}u re-zorder when keyguard change %{public}u", - needReZOrderNode->GetWindowId(), up); + WLOGFI("window %{public}u re-zorder when keyguard change %{public}u", needReZOrderNode->GetWindowId(), up); } } @@ -1867,5 +1887,10 @@ void WindowNodeContainer::UpdateCameraFloatWindowStatus(const sptr& WindowManagerAgentController::GetInstance().UpdateCameraFloatWindowStatus(node->GetAccessTokenId(), isShowing); } } + +WindowLayoutMode WindowNodeContainer::GetCurrentLayoutMode() const +{ + return layoutMode_; +} } // namespace Rosen } // namespace OHOS diff --git a/wmserver/src/window_pair.cpp b/wmserver/src/window_pair.cpp index 359b17ac..7b853be6 100644 --- a/wmserver/src/window_pair.cpp +++ b/wmserver/src/window_pair.cpp @@ -183,10 +183,6 @@ void WindowPair::ExitSplitMode() hideWindow = secondary_; fullScreenWindow = primary_; } - if (WindowHelper::IsWindowModeSupported(fullScreenWindow->GetModeSupportInfo(), - WindowMode::WINDOW_MODE_FULLSCREEN)) { - fullScreenWindow->GetWindowProperty()->SetLastWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN); - } MinimizeApp::AddNeedMinimizeApp(hideWindow, MinimizeReason::SPLIT_QUIT); MinimizeApp::ExecuteMinimizeTargetReason(MinimizeReason::SPLIT_QUIT); WLOGFI("Exit Split Mode, Minimize Window %{public}u", hideWindow->GetWindowId()); @@ -385,16 +381,14 @@ void WindowPair::SwitchPosition() WLOGFI("Switch the pair pos, pri: %{public}u pri-mode: %{public}u, sec: %{public}u sec-mode: %{public}u,", primary_->GetWindowId(), primary_->GetWindowMode(), secondary_->GetWindowId(), secondary_->GetWindowMode()); if (primary_->GetWindowMode() == secondary_->GetWindowMode() && - primary_->GetWindowMode() == WindowMode::WINDOW_MODE_SPLIT_PRIMARY && - WindowHelper::IsWindowModeSupported(primary_->GetModeSupportInfo(), WindowMode::WINDOW_MODE_SPLIT_SECONDARY)) { + primary_->GetWindowMode() == WindowMode::WINDOW_MODE_SPLIT_PRIMARY) { primary_->SetWindowMode(WindowMode::WINDOW_MODE_SPLIT_SECONDARY); if (primary_->GetWindowToken() != nullptr) { primary_->GetWindowToken()->UpdateWindowMode(WindowMode::WINDOW_MODE_SPLIT_SECONDARY); } std::swap(primary_, secondary_); } else if (primary_->GetWindowMode() == secondary_->GetWindowMode() && - primary_->GetWindowMode() == WindowMode::WINDOW_MODE_SPLIT_SECONDARY && - WindowHelper::IsWindowModeSupported(secondary_->GetModeSupportInfo(), WindowMode::WINDOW_MODE_SPLIT_PRIMARY)) { + primary_->GetWindowMode() == WindowMode::WINDOW_MODE_SPLIT_SECONDARY) { secondary_->SetWindowMode(WindowMode::WINDOW_MODE_SPLIT_PRIMARY); if (secondary_->GetWindowToken() != nullptr) { secondary_->GetWindowToken()->UpdateWindowMode(WindowMode::WINDOW_MODE_SPLIT_PRIMARY); diff --git a/wmserver/src/window_root.cpp b/wmserver/src/window_root.cpp index f71a2973..d13e9626 100644 --- a/wmserver/src/window_root.cpp +++ b/wmserver/src/window_root.cpp @@ -117,7 +117,6 @@ sptr WindowRoot::CreateWindowNodeContainer(sptrGetLayoutPolicy()->SetFloatingWindowLimitsConfig(floatingWindowLimitsConfig_); container->GetLayoutPolicy()->SetSplitRatioConfig(splitRatioConfig_); return container; } @@ -481,7 +480,7 @@ WMError WindowRoot::AddWindowNode(uint32_t parentId, sptr& node, boo return res; } // limit number of main window - int mainWindowNumber = container->GetWindowCountByType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW); + uint32_t mainWindowNumber = container->GetWindowCountByType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW); if (mainWindowNumber >= maxAppWindowNumber_ && node->GetWindowType() == WindowType::WINDOW_TYPE_APP_MAIN_WINDOW) { container->MinimizeOldestAppWindow(); } @@ -1310,9 +1309,14 @@ WMError WindowRoot::GetModeChangeHotZones(DisplayId displayId, return WMError::WM_OK; } -void WindowRoot::SetFloatingWindowLimitsConfig(const FloatingWindowLimitsConfig& floatingWindowLimitsConfig) +WindowLayoutMode WindowRoot::GetCurrentLayoutMode(DisplayId displayId) { - floatingWindowLimitsConfig_ = floatingWindowLimitsConfig; + auto container = GetOrCreateWindowNodeContainer(displayId); + if (container == nullptr) { + WLOGFE("GetCurrentLayoutMode failed, window container could not be found"); + return WindowLayoutMode::BASE; + } + return container->GetCurrentLayoutMode(); } } // namespace Rosen } // namespace OHOS From 9fb19f94d6ca7cad81dc382129885bc25a7a328a Mon Sep 17 00:00:00 2001 From: xingyanan Date: Mon, 27 Jun 2022 21:30:52 +0800 Subject: [PATCH 46/81] split start window Signed-off-by: xingyanan Change-Id: I9cfbd934932be339cd4381bc541cc4cac658e77b Signed-off-by: xingyanan --- 0001-split-start-window.patch | 1002 +++++++++++++++++ interfaces/innerkits/wm/window.h | 8 +- interfaces/innerkits/wm/wm_common.h | 1 + .../config/rk3568/window_manager_config.xml | 2 +- resources/media/BUILD.gn | 14 +- resources/media/img/bg_place_holder.png | Bin 0 -> 3500 bytes utils/BUILD.gn | 2 + utils/include/draw_surface.h | 48 + utils/include/surface_draw.h | 14 + utils/src/draw_surface.cpp | 195 ++++ utils/src/surface_draw.cpp | 172 +++ wm/include/window_impl.h | 8 +- wm/src/window_impl.cpp | 12 +- wmserver/BUILD.gn | 2 + wmserver/include/inner_window.h | 99 ++ wmserver/include/window_inner_manager.h | 33 +- wmserver/include/window_pair.h | 1 + wmserver/include/window_zorder_policy.h | 1 + wmserver/src/inner_window.cpp | 201 ++++ wmserver/src/window_inner_manager.cpp | 53 +- wmserver/src/window_pair.cpp | 29 +- 21 files changed, 1830 insertions(+), 67 deletions(-) create mode 100644 0001-split-start-window.patch create mode 100644 resources/media/img/bg_place_holder.png create mode 100644 utils/include/draw_surface.h create mode 100644 utils/src/draw_surface.cpp create mode 100644 wmserver/include/inner_window.h create mode 100644 wmserver/src/inner_window.cpp diff --git a/0001-split-start-window.patch b/0001-split-start-window.patch new file mode 100644 index 00000000..ceca8499 --- /dev/null +++ b/0001-split-start-window.patch @@ -0,0 +1,1002 @@ +From a61cddfc9b4601dcbd0486e43fc3c33653c01c88 Mon Sep 17 00:00:00 2001 +From: xingyanan +Date: Mon, 27 Jun 2022 21:30:52 +0800 +Subject: [PATCH] split start window + +Signed-off-by: xingyanan +Change-Id: I9cfbd934932be339cd4381bc541cc4cac658e77b +--- + interfaces/innerkits/wm/wm_common.h | 1 + + .../config/rk3568/window_manager_config.xml | 2 +- + resources/media/BUILD.gn | 12 +- + resources/media/img/bg_place_holder.png | Bin 0 -> 3500 bytes + utils/BUILD.gn | 2 + + utils/draw_surface.cpp | 195 ++++++++++++++++++ + utils/include/draw_surface.h | 48 +++++ + utils/include/surface_draw.h | 18 ++ + utils/src/surface_draw.cpp | 170 +++++++++++++++ + wm/src/window_impl.cpp | 4 + + wmserver/BUILD.gn | 1 + + wmserver/include/window_inner_manager.h | 33 +++ + wmserver/include/window_pair.h | 1 + + wmserver/include/window_zorder_policy.h | 1 + + wmserver/src/window_inner_manager.cpp | 183 +++++++++++++++- + wmserver/src/window_pair.cpp | 20 +- + 16 files changed, 685 insertions(+), 6 deletions(-) + create mode 100644 resources/media/img/bg_place_holder.png + create mode 100644 utils/draw_surface.cpp + create mode 100644 utils/include/draw_surface.h + +diff --git a/interfaces/innerkits/wm/wm_common.h b/interfaces/innerkits/wm/wm_common.h +index 24da28ce..bf4a8ccf 100644 +--- a/interfaces/innerkits/wm/wm_common.h ++++ b/interfaces/innerkits/wm/wm_common.h +@@ -43,6 +43,7 @@ enum class WindowType : uint32_t { + ABOVE_APP_SYSTEM_WINDOW_BASE = 2100, + WINDOW_TYPE_APP_LAUNCHING = ABOVE_APP_SYSTEM_WINDOW_BASE, + WINDOW_TYPE_DOCK_SLICE, ++ WINDOW_TYPE_PLACE_HOLDER, + WINDOW_TYPE_INCOMING_CALL, + WINDOW_TYPE_SEARCHING_BAR, + WINDOW_TYPE_SYSTEM_ALARM_WINDOW, +diff --git a/resources/config/rk3568/window_manager_config.xml b/resources/config/rk3568/window_manager_config.xml +index 70ca77e2..9c11c5a9 100644 +--- a/resources/config/rk3568/window_manager_config.xml ++++ b/resources/config/rk3568/window_manager_config.xml +@@ -15,7 +15,7 @@ + --> + + +- ++ + + 100 + +diff --git a/resources/media/BUILD.gn b/resources/media/BUILD.gn +index 1f2b8c85..6d152d78 100644 +--- a/resources/media/BUILD.gn ++++ b/resources/media/BUILD.gn +@@ -19,6 +19,16 @@ ohos_prebuilt_etc("window_divider_image") { + relative_install_dir = "window/resources" + } + ++ohos_prebuilt_etc("window_place_holder_image") { ++ source = "//foundation/windowmanager/resources/media/img/bg_place_holder.png" ++ part_name = "window_manager" ++ subsystem_name = "window" ++ relative_install_dir = "window/resources" ++} ++ ++ + group("window_resources_media") { +- deps = [ ":window_divider_image" ] ++ deps = [ ":window_divider_image", ++ ":window_place_holder_image" ++ ] + } +diff --git a/resources/media/img/bg_place_holder.png b/resources/media/img/bg_place_holder.png +new file mode 100644 +index 0000000000000000000000000000000000000000..9936aee1a38039dba2ddfacaf56ce9d8c94a1f59 +GIT binary patch +literal 3500 +zcmeH~k55xa9Ker?ii(mfnUINK+>EJHV2sg*m0zM$>I71M01padt|~SyqSykZ1%JUd +z9cXA+#-L1H!Htyq>$O0kW$U2P1}ma1Qr;{0<~sH))v~tK(ss{3V+qOKeJ|hp=DwHv +z-re_e-{fTNS-bkZ)c}CCnR|CJ03Z=v5(rsAh<_`eydlJ@lY8?|0}%86+Zt3UP2~~B +zMVY(O4_3C>ko`>?b9d@yPXGE)cpH&WcWj|g+#+4OvR_d{Qh#`|yq-`*TZGCvo{AquG0d|HOioJ+%QLFrXv0z$A9a={ +zNeot>f|FqvE@;D|!9udLJW^?#tf59`d3~ay7M9SIuD??Vmqa{>3uWcE@KQRWk*TS| +z&&MmK6r6-*0EFer;3tsMC#u~h4aKNMP1r<3$pp%qiVKy>aL9OOV^`^9F_XzGEG|xM +zw|Z`I%z5m00eF?>M7?pLW}3mvG1r$wD9R&E{N-t6>AhI>!u6Vf&uyznN>=yv^-X<(oIE9{9WtB<4-eORYEWWvG)d>|{r;W?#)C)R +zCY=-2(+onUNht{dy?j{AI3YX2=4g6wHJtd;?R^Xh@UxuO&Y7B&=!e$%8?1bnRQzUq +zxYn$QH_W@99qX_)>9DdJ08~=Bxi6bk$lOUk9{UmOb{tj?U8R3R+a)c}0?sDRZ85 +zXJ{21=iJAEuJKauKizVX^ZD?l;fv8Ag$5gOR=&R`qMlKdj|T4Nh}v9o`P@KnZv+>y +z>TWtd1%1_^6y$YiO +z!Xf(XW&lz|8Eg(>;~ikz3hCvs00c)6#_Jli_bm2oj2Z(UzDt1T)n4D1fys-)<1!9G +zb2YRmIbVg0QXBPmwiAG#LV}Ht1*sMUm8909#KW2gQ~3nMD;>AgDq5V*UJTVFNAM6<|tlM_vzLuVn$0NwjhU%TZc~p +zK>G?7$H(d&cC*3>;eKn%f)Vs4k6{E`-pC_?y0G5}k58ZmrSNZNP!63eHC8XOMuGt? +zxJ}s#52*ycqUIg@BW(#Qrz)s;WFc668ED3|j$uqw)Tpz?zB+d0T$>pN5F< +P7s%Y5wX0|67w7&1Q$p_} + +literal 0 +HcmV?d00001 + +diff --git a/utils/BUILD.gn b/utils/BUILD.gn +index a04be886..6723a668 100644 +--- a/utils/BUILD.gn ++++ b/utils/BUILD.gn +@@ -45,6 +45,7 @@ ohos_shared_library("libwmutil") { + "src/window_property.cpp", + "src/window_transition_info.cpp", + "src/wm_trace.cpp", ++ "draw_surface.cpp" + ] + + configs = [ ":libwmutil_private_config" ] +@@ -54,6 +55,7 @@ ohos_shared_library("libwmutil") { + deps = [ + "//foundation/graphic/graphic_2d/rosen/modules/render_service_base:librender_service_base", + "//foundation/graphic/graphic_2d/rosen/modules/render_service_client:librender_service_client", ++ "//foundation/graphic/graphic_2d/rosen/modules/2d_graphics:2d_graphics", + "//third_party/flutter/build/skia:ace_skia_ohos", + ] + +diff --git a/utils/draw_surface.cpp b/utils/draw_surface.cpp +new file mode 100644 +index 00000000..06a0aa5a +--- /dev/null ++++ b/utils/draw_surface.cpp +@@ -0,0 +1,195 @@ ++/* ++ * Copyright (c) 2022-2022 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 "draw_surface.h" ++#include "image/bitmap.h" ++#include "image_source.h" ++#include "image_type.h" ++#include "image_utils.h" ++#include "pixel_map.h" ++#include "window_manager_hilog.h" ++ ++namespace OHOS { ++namespace Rosen { ++namespace { ++ constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "DrawSurface"}; ++} // namespace ++ ++bool DrawSurface::DrawImage(std::shared_ptr surfaceNode, int32_t bufferWidth, int32_t bufferHeight, ++ const std::string& imagePath) ++{ ++ sptr layer = GetLayer(surfaceNode); ++ if (layer == nullptr) { ++ WLOGFE("layer is nullptr"); ++ return false; ++ } ++ sptr buffer = GetSurfaceBuffer(layer, bufferWidth, bufferHeight); ++ if (buffer == nullptr || buffer->GetVirAddr() == nullptr) { ++ return false; ++ } ++ auto addr = static_cast(buffer->GetVirAddr()); ++ if (!DoDraw(addr, buffer->GetWidth(), buffer->GetHeight(), imagePath)) { ++ WLOGE("draw window pixel failed"); ++ return false; ++ } ++ OHOS::BufferFlushConfig flushConfig = { ++ .damage = { ++ .w = buffer->GetWidth(), ++ .h = buffer->GetHeight(), ++ }, ++ }; ++ OHOS::SurfaceError ret = layer->FlushBuffer(buffer, -1, flushConfig); ++ if (ret != OHOS::SurfaceError::SURFACE_ERROR_OK) { ++ WLOGFE("draw pointer FlushBuffer ret:%{public}s", SurfaceErrorStr(ret).c_str()); ++ return false; ++ } ++ return true; ++} ++ ++bool DrawSurface::DrawColor(std::shared_ptr surfaceNode, int32_t bufferWidth, int32_t bufferHeight, ++ uint32_t color) ++{ ++ sptr layer = GetLayer(surfaceNode); ++ if (layer == nullptr) { ++ WLOGFE("layer is nullptr"); ++ return false; ++ } ++ sptr buffer = GetSurfaceBuffer(layer, bufferWidth, bufferHeight); ++ if (buffer == nullptr || buffer->GetVirAddr() == nullptr) { ++ return false; ++ } ++ auto addr = static_cast(buffer->GetVirAddr()); ++ if (!DoDraw(addr, buffer->GetWidth(), buffer->GetHeight(), color)) { ++ WLOGE("draw window color failed"); ++ return false; ++ } ++ OHOS::BufferFlushConfig flushConfig = { ++ .damage = { ++ .w = buffer->GetWidth(), ++ .h = buffer->GetHeight(), ++ }, ++ }; ++ OHOS::SurfaceError ret = layer->FlushBuffer(buffer, -1, flushConfig); ++ if (ret != OHOS::SurfaceError::SURFACE_ERROR_OK) { ++ WLOGFE("draw pointer FlushBuffer ret:%{public}s", SurfaceErrorStr(ret).c_str()); ++ return false; ++ } ++ return true; ++} ++ ++sptr DrawSurface::GetLayer(std::shared_ptr surfaceNode) ++{ ++ if (surfaceNode == nullptr) { ++ return nullptr; ++ } ++ return surfaceNode->GetSurface(); ++} ++ ++sptr DrawSurface::GetSurfaceBuffer(sptr layer, ++ int32_t bufferWidth, int32_t bufferHeight) ++{ ++ sptr buffer; ++ int32_t releaseFence = 0; ++ OHOS::BufferRequestConfig config = { ++ .width = bufferWidth, ++ .height = bufferHeight, ++ .strideAlignment = 0x8, ++ .format = PIXEL_FMT_RGBA_8888, ++ .usage = HBM_USE_CPU_READ | HBM_USE_CPU_WRITE | HBM_USE_MEM_DMA, ++ }; ++ ++ OHOS::SurfaceError ret = layer->RequestBuffer(buffer, releaseFence, config); ++ if (ret != OHOS::SURFACE_ERROR_OK) { ++ WLOGFE("request buffer ret:%{public}s", SurfaceErrorStr(ret).c_str()); ++ return nullptr; ++ } ++ return buffer; ++} ++ ++std::unique_ptr DrawSurface::DecodeImageToPixelMap(const std::string &imagePath) ++{ ++ OHOS::Media::SourceOptions opts; ++ opts.formatHint = "image/png"; ++ uint32_t ret = 0; ++ auto imageSource = OHOS::Media::ImageSource::CreateImageSource(imagePath, opts, ret); ++ // CHKPP(imageSource); ++ std::set formats; ++ ret = imageSource->GetSupportedFormats(formats); ++ WLOGFD("get supported format ret:%{public}u", ret); ++ ++ OHOS::Media::DecodeOptions decodeOpts; ++ std::unique_ptr pixelMap = imageSource->CreatePixelMap(decodeOpts, ret); ++ if (pixelMap == nullptr) { ++ WLOGFE("pixelMap is nullptr"); ++ } ++ return pixelMap; ++} ++ ++void DrawSurface::DrawPixelmap(OHOS::Rosen::Drawing::Canvas &canvas, const std::string& imagePath) ++{ ++ std::unique_ptr pixelmap = DecodeImageToPixelMap(imagePath); ++ if (pixelmap == nullptr) { ++ WLOGFE("drawing pixel map is nullptr"); ++ return; ++ } ++ OHOS::Rosen::Drawing::Pen pen; ++ pen.SetAntiAlias(true); ++ pen.SetColor(OHOS::Rosen::Drawing::Color::COLOR_BLUE); ++ OHOS::Rosen::Drawing::scalar penWidth = 1; ++ pen.SetWidth(penWidth); ++ canvas.AttachPen(pen); ++ canvas.DrawBitmap(*pixelmap, 0, 0); ++} ++ ++bool DrawSurface::DoDraw(uint8_t *addr, uint32_t width, uint32_t height, const std::string& imagePath) ++{ ++ OHOS::Rosen::Drawing::Bitmap bitmap; ++ OHOS::Rosen::Drawing::BitmapFormat format { OHOS::Rosen::Drawing::COLORTYPE_RGBA_8888, ++ OHOS::Rosen::Drawing::ALPHATYPE_OPAQUYE }; ++ bitmap.Build(width, height, format); ++ OHOS::Rosen::Drawing::Canvas canvas; ++ canvas.Bind(bitmap); ++ canvas.Clear(OHOS::Rosen::Drawing::Color::COLOR_TRANSPARENT); ++ DrawPixelmap(canvas, imagePath); ++ static constexpr uint32_t stride = 4; ++ uint32_t addrSize = width * height * stride; ++ errno_t ret = memcpy_s(addr, addrSize, bitmap.GetPixels(), addrSize); ++ if (ret != EOK) { ++ WLOGFE("draw failed"); ++ return false; ++ } ++ return true; ++} ++bool DrawSurface::DoDraw(uint8_t *addr, uint32_t width, uint32_t height, uint32_t color) ++{ ++ OHOS::Rosen::Drawing::Bitmap bitmap; ++ OHOS::Rosen::Drawing::BitmapFormat format { OHOS::Rosen::Drawing::COLORTYPE_RGBA_8888, ++ OHOS::Rosen::Drawing::ALPHATYPE_OPAQUYE }; ++ bitmap.Build(width, height, format); ++ OHOS::Rosen::Drawing::Canvas canvas; ++ canvas.Bind(bitmap); ++ canvas.Clear(color); ++ ++ static constexpr uint32_t stride = 4; ++ uint32_t addrSize = width * height * stride; ++ errno_t ret = memcpy_s(addr, addrSize, bitmap.GetPixels(), addrSize); ++ if (ret != EOK) { ++ WLOGFE("draw failed"); ++ return false; ++ } ++ return true; ++} ++} // Rosen ++} // OHOS +\ No newline at end of file +diff --git a/utils/include/draw_surface.h b/utils/include/draw_surface.h +new file mode 100644 +index 00000000..1dd19395 +--- /dev/null ++++ b/utils/include/draw_surface.h +@@ -0,0 +1,48 @@ ++/* ++ * Copyright (c) 2022-2022 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 DRAW_SURFACE_H ++#define DRAW_SURFACE_H ++ ++#include "draw/canvas.h" ++#include "nocopyable.h" ++#include "pixel_map.h" ++#include "refbase.h" ++#include "ui/rs_surface_node.h" ++#include "wm_common.h" ++#include "window.h" ++ ++namespace OHOS { ++namespace Rosen { ++class DrawSurface { ++public: ++ ~DrawSurface() = default; ++ static bool DrawColor(std::shared_ptr surfaceNode, int32_t bufferWidth, ++ int32_t bufferHeight, uint32_t color); ++ static bool DrawImage(std::shared_ptr surfaceNode, int32_t bufferWidth, ++ int32_t bufferHeight,const std::string& imagePath); ++private: ++ DrawSurface() {}; ++ static bool DoDraw(uint8_t *addr, uint32_t width, uint32_t height, const std::string& imagePath); ++ static bool DoDraw(uint8_t *addr, uint32_t width, uint32_t height, uint32_t color); ++ static sptr GetLayer(std::shared_ptr surfaceNode); ++ static sptr GetSurfaceBuffer(sptr layer, ++ int32_t bufferWidth, int32_t bufferHeight); ++ static void DrawPixelmap(OHOS::Rosen::Drawing::Canvas &canvas, const std::string& imagePath); ++ static std::unique_ptr DecodeImageToPixelMap(const std::string &imagePath); ++}; ++} // Rosen ++} // OHOS ++#endif // DRAW_SURFACE_H +\ No newline at end of file +diff --git a/utils/include/surface_draw.h b/utils/include/surface_draw.h +index b312159f..8db73f64 100644 +--- a/utils/include/surface_draw.h ++++ b/utils/include/surface_draw.h +@@ -23,6 +23,11 @@ + #endif + #include "refbase.h" + #include "wm_common.h" ++#include "window.h" ++ ++#include "draw/canvas.h" ++#include "nocopyable.h" ++#include "pixel_map.h" + + namespace OHOS { + namespace Rosen { +@@ -37,6 +42,19 @@ public: + bool DecodeImageFile(const char* filename, SkBitmap& bitmap); + void DrawSkImage(std::shared_ptr surfaceNode, Rect winRect, + sptr pixelMap, uint32_t bkgColor); ++ ++ bool DrawWindow(std::shared_ptr surfaceNode, int32_t bufferWidth, int32_t bufferHeight, ++ uint32_t color); ++ bool DrawWindow(std::shared_ptr surfaceNode, int32_t bufferWidth, int32_t bufferHeight, ++ const std::string& imagePath); ++ bool DoDraw(uint8_t *addr, uint32_t width, uint32_t height, const std::string& imagePath); ++ bool DoDraw(uint8_t *addr, uint32_t width, uint32_t height, uint32_t color); ++ sptr GetLayer(std::shared_ptr surfaceNode); ++ sptr GetSurfaceBuffer(sptr layer, ++ int32_t bufferWidth, int32_t bufferHeight) const; ++ ++ void DrawPixelmap(OHOS::Rosen::Drawing::Canvas &canvas, const std::string& imagePath); ++ std::unique_ptr DecodeImageToPixelMap(const std::string &imagePath); + private: + + std::shared_ptr PrepareDraw(std::shared_ptr surfaceNode, +diff --git a/utils/src/surface_draw.cpp b/utils/src/surface_draw.cpp +index d4ebc775..70c0fa83 100644 +--- a/utils/src/surface_draw.cpp ++++ b/utils/src/surface_draw.cpp +@@ -24,6 +24,12 @@ + #include "include/core/SkData.h" + #include "include/core/SkImage.h" + #include "include/core/SkPixmap.h" ++ ++#include "image/bitmap.h" ++#include "image_source.h" ++#include "image_type.h" ++#include "image_utils.h" ++#include "pixel_map.h" + namespace OHOS { + namespace Rosen { + namespace { +@@ -234,5 +240,169 @@ void SurfaceDraw::DrawSkImage(std::shared_ptr surfaceNode, Rect w + } + return; + } ++ ++bool SurfaceDraw::DrawWindow(std::shared_ptr surfaceNode, int32_t bufferWidth, int32_t bufferHeight, ++ const std::string& imagePath) ++{ ++ sptr layer = GetLayer(surfaceNode); ++ if (layer == nullptr) { ++ WLOGFE("layer is nullptr"); ++ return false; ++ } ++ sptr buffer = GetSurfaceBuffer(layer, bufferWidth, bufferHeight); ++ if (buffer == nullptr || buffer->GetVirAddr() == nullptr) { ++ return false; ++ } ++ auto addr = static_cast(buffer->GetVirAddr()); ++ if (!DoDraw(addr, buffer->GetWidth(), buffer->GetHeight(), imagePath)) { ++ WLOGE("draw window pixel failed"); ++ return false; ++ } ++ OHOS::BufferFlushConfig flushConfig = { ++ .damage = { ++ .w = buffer->GetWidth(), ++ .h = buffer->GetHeight(), ++ }, ++ }; ++ OHOS::SurfaceError ret = layer->FlushBuffer(buffer, -1, flushConfig); ++ if (ret != OHOS::SurfaceError::SURFACE_ERROR_OK) { ++ WLOGFE("draw pointer FlushBuffer ret:%{public}s", SurfaceErrorStr(ret).c_str()); ++ return false; ++ } ++ return true; ++} ++ ++bool SurfaceDraw::DrawWindow(std::shared_ptr surfaceNode, int32_t bufferWidth, int32_t bufferHeight, ++ uint32_t color) ++{ ++ sptr layer = GetLayer(surfaceNode); ++ if (layer == nullptr) { ++ WLOGFE("layer is nullptr"); ++ return false; ++ } ++ sptr buffer = GetSurfaceBuffer(layer, bufferWidth, bufferHeight); ++ if (buffer == nullptr || buffer->GetVirAddr() == nullptr) { ++ return false; ++ } ++ auto addr = static_cast(buffer->GetVirAddr()); ++ if (!DoDraw(addr, buffer->GetWidth(), buffer->GetHeight(), color)) { ++ WLOGE("draw window color failed"); ++ return false; ++ } ++ OHOS::BufferFlushConfig flushConfig = { ++ .damage = { ++ .w = buffer->GetWidth(), ++ .h = buffer->GetHeight(), ++ }, ++ }; ++ OHOS::SurfaceError ret = layer->FlushBuffer(buffer, -1, flushConfig); ++ if (ret != OHOS::SurfaceError::SURFACE_ERROR_OK) { ++ WLOGFE("draw pointer FlushBuffer ret:%{public}s", SurfaceErrorStr(ret).c_str()); ++ return false; ++ } ++ return true; ++} ++ ++sptr SurfaceDraw::GetLayer(std::shared_ptr surfaceNode) ++{ ++ if (surfaceNode == nullptr) { ++ return nullptr; ++ } ++ return surfaceNode->GetSurface(); ++} ++ ++sptr SurfaceDraw::GetSurfaceBuffer(sptr layer, int32_t bufferWidth, ++ int32_t bufferHeight) const ++{ ++ sptr buffer; ++ int32_t releaseFence = 0; ++ OHOS::BufferRequestConfig config = { ++ .width = bufferWidth, ++ .height = bufferHeight, ++ .strideAlignment = 0x8, ++ .format = PIXEL_FMT_RGBA_8888, ++ .usage = HBM_USE_CPU_READ | HBM_USE_CPU_WRITE | HBM_USE_MEM_DMA, ++ }; ++ ++ OHOS::SurfaceError ret = layer->RequestBuffer(buffer, releaseFence, config); ++ if (ret != OHOS::SURFACE_ERROR_OK) { ++ WLOGFE("request buffer ret:%{public}s", SurfaceErrorStr(ret).c_str()); ++ return nullptr; ++ } ++ return buffer; ++} ++ ++std::unique_ptr SurfaceDraw::DecodeImageToPixelMap(const std::string &imagePath) ++{ ++ OHOS::Media::SourceOptions opts; ++ opts.formatHint = "image/png"; ++ uint32_t ret = 0; ++ auto imageSource = OHOS::Media::ImageSource::CreateImageSource(imagePath, opts, ret); ++ // CHKPP(imageSource); ++ std::set formats; ++ ret = imageSource->GetSupportedFormats(formats); ++ WLOGFD("get supported format ret:%{public}u", ret); ++ ++ OHOS::Media::DecodeOptions decodeOpts; ++ std::unique_ptr pixelMap = imageSource->CreatePixelMap(decodeOpts, ret); ++ if (pixelMap == nullptr) { ++ WLOGFE("pixelMap is nullptr"); ++ } ++ return pixelMap; ++} ++ ++void SurfaceDraw::DrawPixelmap(OHOS::Rosen::Drawing::Canvas &canvas, const std::string& imagePath) ++{ ++ std::unique_ptr pixelmap = DecodeImageToPixelMap(imagePath); ++ if (pixelmap == nullptr) { ++ WLOGFE("drawing pixel map is nullptr"); ++ return; ++ } ++ OHOS::Rosen::Drawing::Pen pen; ++ pen.SetAntiAlias(true); ++ pen.SetColor(OHOS::Rosen::Drawing::Color::COLOR_BLUE); ++ OHOS::Rosen::Drawing::scalar penWidth = 1; ++ pen.SetWidth(penWidth); ++ canvas.AttachPen(pen); ++ canvas.DrawBitmap(*pixelmap, 0, 0); ++} ++ ++bool SurfaceDraw::DoDraw(uint8_t *addr, uint32_t width, uint32_t height, const std::string& imagePath) ++{ ++ OHOS::Rosen::Drawing::Bitmap bitmap; ++ OHOS::Rosen::Drawing::BitmapFormat format { OHOS::Rosen::Drawing::COLORTYPE_RGBA_8888, ++ OHOS::Rosen::Drawing::ALPHATYPE_OPAQUYE }; ++ bitmap.Build(width, height, format); ++ OHOS::Rosen::Drawing::Canvas canvas; ++ canvas.Bind(bitmap); ++ canvas.Clear(OHOS::Rosen::Drawing::Color::COLOR_TRANSPARENT); ++ DrawPixelmap(canvas, imagePath); ++ static constexpr uint32_t stride = 4; ++ uint32_t addrSize = width * height * stride; ++ errno_t ret = memcpy_s(addr, addrSize, bitmap.GetPixels(), addrSize); ++ if (ret != EOK) { ++ WLOGFE("draw failed"); ++ return false; ++ } ++ return true; ++} ++bool SurfaceDraw::DoDraw(uint8_t *addr, uint32_t width, uint32_t height, uint32_t color) ++{ ++ OHOS::Rosen::Drawing::Bitmap bitmap; ++ OHOS::Rosen::Drawing::BitmapFormat format { OHOS::Rosen::Drawing::COLORTYPE_RGBA_8888, ++ OHOS::Rosen::Drawing::ALPHATYPE_OPAQUYE }; ++ bitmap.Build(width, height, format); ++ OHOS::Rosen::Drawing::Canvas canvas; ++ canvas.Bind(bitmap); ++ canvas.Clear(color); ++ static constexpr uint32_t stride = 4; ++ uint32_t addrSize = width * height * stride; ++ errno_t ret = memcpy_s(addr, addrSize, bitmap.GetPixels(), addrSize); ++ if (ret != EOK) { ++ WLOGFE("draw failed"); ++ return false; ++ } ++ return true; ++} + } // Rosen + } // OHOS +\ No newline at end of file +diff --git a/wm/src/window_impl.cpp b/wm/src/window_impl.cpp +index 0dcecf56..03d40f2f 100644 +--- a/wm/src/window_impl.cpp ++++ b/wm/src/window_impl.cpp +@@ -2305,6 +2305,10 @@ void WindowImpl::SetDefaultOption() + property_->SetFocusable(false); + break; + } ++ case WindowType::WINDOW_TYPE_PLACE_HOLDER: { ++ AddWindowFlag(WindowFlag::WINDOW_FLAG_FORBID_SPLIT_MOVE); ++ break; ++ } + default: + break; + } +diff --git a/wmserver/BUILD.gn b/wmserver/BUILD.gn +index 6637bc4c..e76a11db 100644 +--- a/wmserver/BUILD.gn ++++ b/wmserver/BUILD.gn +@@ -73,6 +73,7 @@ ohos_shared_library("libwms") { + + deps = [ + "//foundation/arkui/ace_engine/interfaces/inner_api/ui_service_manager:ui_service_mgr", ++ "//foundation/graphic/graphic_2d/rosen/modules/2d_graphics:2d_graphics", + "//foundation/graphic/graphic_2d/rosen/modules/render_service_client:librender_service_client", + "//foundation/windowmanager/dm:libdm", + "//foundation/windowmanager/dmserver:libdms", +diff --git a/wmserver/include/window_inner_manager.h b/wmserver/include/window_inner_manager.h +index 3ab54045..b8a40e95 100644 +--- a/wmserver/include/window_inner_manager.h ++++ b/wmserver/include/window_inner_manager.h +@@ -20,12 +20,35 @@ + #include "event_handler.h" + #include "event_runner.h" + ++#include ++#include "draw/canvas.h" ++#include "nocopyable.h" ++#include "pixel_map.h" ++ + #include "wm_common.h" + #include "wm_single_instance.h" ++#include "window.h" + + namespace OHOS { + namespace Rosen { ++class TouchOutsideListener : public ITouchOutsideListener { ++ virtual void OnTouchOutside(); ++}; ++class InputListener : public IInputEventListener { ++ virtual void OnKeyEvent(std::shared_ptr& keyEvent); ++ virtual void OnPointerInputEvent(std::shared_ptr& pointerEvent); ++}; ++class LifeCycle : public IWindowLifeCycle { ++ virtual void AfterForeground() {}; ++ virtual void AfterBackground() {}; ++ virtual void AfterFocused() {}; ++ virtual void AfterInactive(); ++ virtual void AfterUnfocused() {}; ++}; + class WindowInnerManager : public RefBase { ++friend class TouchOutsideListener; ++friend class InputListener; ++friend class LifeCycle; + WM_DECLARE_SINGLE_INSTANCE_BASE(WindowInnerManager); + using EventRunner = OHOS::AppExecFwk::EventRunner; + using EventHandler = OHOS::AppExecFwk::EventHandler; +@@ -34,6 +57,8 @@ public: + void Stop(); + void CreateWindow(std::string name, WindowType type, Rect rect); + void DestroyWindow(); ++ void CreatePlaceHolderWindow(WindowMode mode, DisplayId displayId); ++ void DestroyPlaceHolderWindow(); + public: + enum class InnerWMRunningState { + STATE_NOT_START, +@@ -45,8 +70,15 @@ private: + WindowInnerManager(); + bool Init(); + void HandleCreateWindow(std::string name, WindowType type, Rect rect); ++ void HandleCreatePlaceHolderWindow(WindowMode mode, DisplayId displayId); + void HandleDestroyWindow(); + ++ sptr GetLayer(); ++ sptr GetSurfaceBuffer(sptr layer) const; ++ void DoDraw(uint8_t *addr, uint32_t width, uint32_t height); ++ void DrawPixelmap(OHOS::Rosen::Drawing::Canvas &canvas); ++ std::unique_ptr DecodeImageToPixelMap(const std::string &imagePath); ++ + private: + int32_t dialogId_ = -1; + std::shared_ptr eventHandler_; +@@ -54,6 +86,7 @@ private: + InnerWMRunningState state_; + std::string dividerParams_ = ""; + const std::string INNER_WM_THREAD_NAME = "inner_window_manager"; ++ sptr placeHolderwindow_ = nullptr; + }; + } // namespace Rosen + } // namespace OHOS +diff --git a/wmserver/include/window_pair.h b/wmserver/include/window_pair.h +index 86d8391c..237cdc4a 100644 +--- a/wmserver/include/window_pair.h ++++ b/wmserver/include/window_pair.h +@@ -250,6 +250,7 @@ private: + sptr primary_; + sptr secondary_; + sptr divider_; ++ // sptr placeholder_; + WindowPairStatus status_ = {WindowPairStatus::STATUS_EMPTY}; + DisplayGroupWindowTree& displayGroupWindowTree_; + bool isAllAppWindowsRestoring_ { false }; +diff --git a/wmserver/include/window_zorder_policy.h b/wmserver/include/window_zorder_policy.h +index 8df41594..4f52082f 100644 +--- a/wmserver/include/window_zorder_policy.h ++++ b/wmserver/include/window_zorder_policy.h +@@ -45,6 +45,7 @@ private: + { WindowType::WINDOW_TYPE_APP_COMPONENT, 2 }, + { WindowType::WINDOW_TYPE_APP_LAUNCHING, 101 }, + { WindowType::WINDOW_TYPE_DOCK_SLICE, 0 }, ++ { WindowType::WINDOW_TYPE_PLACE_HOLDER, 0 }, + { WindowType::WINDOW_TYPE_LAUNCHER_RECENT, 102 }, + { WindowType::WINDOW_TYPE_LAUNCHER_DOCK, 103 }, + { WindowType::WINDOW_TYPE_INCOMING_CALL, 104 }, +diff --git a/wmserver/src/window_inner_manager.cpp b/wmserver/src/window_inner_manager.cpp +index 5cddc9f0..c4e35708 100644 +--- a/wmserver/src/window_inner_manager.cpp ++++ b/wmserver/src/window_inner_manager.cpp +@@ -15,14 +15,22 @@ + + #include "window_inner_manager.h" + ++#include "draw_surface.h" + #include "ui_service_mgr_client.h" + #include "window_manager_hilog.h" +-#include "window.h" ++#include "image/bitmap.h" ++#include "image_source.h" ++#include "image_type.h" ++#include "image_utils.h" ++#include "pixel_map.h" + + namespace OHOS { + namespace Rosen { + namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowInnerManager"}; ++ const std::string IMAGE_PLACE_HOLDER_PNG_PATH = "/etc/window/resources/bg_place_holder.png"; ++ const int32_t IMAGE_WIDTH = 512; ++ const int32_t IMAGE_HEIGHT = 512; + } + WM_IMPLEMENT_SINGLE_INSTANCE(WindowInnerManager) + +@@ -90,6 +98,179 @@ void WindowInnerManager::HandleCreateWindow(std::string name, WindowType type, R + return; + } + ++std::unique_ptr WindowInnerManager::DecodeImageToPixelMap(const std::string &imagePath) ++{ ++ OHOS::Media::SourceOptions opts; ++ opts.formatHint = "image/png"; ++ uint32_t ret = 0; ++ auto imageSource = OHOS::Media::ImageSource::CreateImageSource(imagePath, opts, ret); ++ // CHKPP(imageSource); ++ std::set formats; ++ ret = imageSource->GetSupportedFormats(formats); ++ WLOGFD("get supported format ret:%{public}u", ret); ++ ++ OHOS::Media::DecodeOptions decodeOpts; ++ std::unique_ptr pixelMap = imageSource->CreatePixelMap(decodeOpts, ret); ++ if (pixelMap == nullptr) { ++ WLOGFE("pixelMap is nullptr"); ++ } ++ return pixelMap; ++} ++ ++void WindowInnerManager::DrawPixelmap(OHOS::Rosen::Drawing::Canvas &canvas) ++{ ++ std::unique_ptr pixelmap = DecodeImageToPixelMap(IMAGE_PLACE_HOLDER_PNG_PATH); ++ OHOS::Rosen::Drawing::Pen pen; ++ pen.SetAntiAlias(true); ++ pen.SetColor(OHOS::Rosen::Drawing::Color::COLOR_BLUE); ++ OHOS::Rosen::Drawing::scalar penWidth = 1; ++ pen.SetWidth(penWidth); ++ canvas.AttachPen(pen); ++ canvas.DrawBitmap(*pixelmap, 0, 0); ++} ++ ++void WindowInnerManager::DoDraw(uint8_t *addr, uint32_t width, uint32_t height) ++{ ++ OHOS::Rosen::Drawing::Bitmap bitmap; ++ OHOS::Rosen::Drawing::BitmapFormat format { OHOS::Rosen::Drawing::COLORTYPE_RGBA_8888, ++ OHOS::Rosen::Drawing::ALPHATYPE_OPAQUYE }; ++ bitmap.Build(width, height, format); ++ OHOS::Rosen::Drawing::Canvas canvas; ++ canvas.Bind(bitmap); ++ canvas.Clear(OHOS::Rosen::Drawing::Color::COLOR_TRANSPARENT); ++ DrawPixelmap(canvas); ++ static constexpr uint32_t stride = 4; ++ uint32_t addrSize = width * height * stride; ++ errno_t ret = memcpy_s(addr, addrSize, bitmap.GetPixels(), addrSize); ++ if (ret != EOK) { ++ return; ++ } ++} ++void WindowInnerManager::DestroyPlaceHolderWindow() ++{ ++ if (placeHolderwindow_ != nullptr) { ++ placeHolderwindow_->Destroy(); ++ placeHolderwindow_ = nullptr; ++ } ++} ++ ++void WindowInnerManager::CreatePlaceHolderWindow(WindowMode mode, DisplayId displayId) ++{ ++ eventHandler_->PostTask([this, mode, displayId]() { ++ HandleCreatePlaceHolderWindow(mode, displayId); ++ }); ++ return; ++} ++ ++void TouchOutsideListener::OnTouchOutside() ++{ ++ WindowInnerManager::GetInstance().DestroyPlaceHolderWindow(); ++} ++ ++void InputListener::OnKeyEvent(std::shared_ptr& keyEvent) ++{ ++ WindowInnerManager::GetInstance().DestroyPlaceHolderWindow(); ++} ++ ++void InputListener::OnPointerInputEvent(std::shared_ptr& pointerEvent) ++{ ++ WindowInnerManager::GetInstance().DestroyPlaceHolderWindow(); ++} ++ ++void LifeCycle::AfterInactive() ++{ ++ WindowInnerManager::GetInstance().DestroyPlaceHolderWindow(); ++} ++ ++void WindowInnerManager::HandleCreatePlaceHolderWindow(WindowMode mode, DisplayId displayId) ++{ ++ if (placeHolderwindow_ != nullptr) { ++ return; ++ } ++ sptr opt = new (std::nothrow) WindowOption(); ++ if (opt == nullptr) { ++ WLOGFE("Window option is nullptr."); ++ return; ++ } ++ opt->SetWindowType(WindowType::WINDOW_TYPE_PLACE_HOLDER); ++ opt->SetFocusable(false); ++ opt->SetWindowMode(mode); ++ placeHolderwindow_ = Window::Create("place_holder" + std::to_string(displayId), opt); ++ if (placeHolderwindow_ == nullptr) { ++ WLOGFE("Window is nullptr."); ++ return; ++ } ++ sptr touchOutsideListener = new TouchOutsideListener(); ++ // sptr inputListener = new InputListener(); ++ sptr lifeCycleListener = new LifeCycle(); ++ placeHolderwindow_->RegisterTouchOutsideListener(touchOutsideListener); ++ // placeHolderwindow_->RegisterInputEventListener(inputListener); ++ placeHolderwindow_->RegisterLifeCycleListener(lifeCycleListener); ++ // placeHolderwindow_->Show(); ++ if (!OHOS::Rosen::DrawSurface::DrawImage(placeHolderwindow_->GetSurfaceNode(), ++ IMAGE_WIDTH, IMAGE_HEIGHT, IMAGE_PLACE_HOLDER_PNG_PATH)) { ++ WLOGE("draw surface failed"); ++ return; ++ } ++ // sptr layer = GetLayer(); ++ // if (layer == nullptr) { ++ // placeHolderwindow_->Destroy(); ++ // placeHolderwindow_ = nullptr; ++ // return; ++ // } ++ ++ // sptr buffer = GetSurfaceBuffer(layer); ++ // if (buffer == nullptr || buffer->GetVirAddr() == nullptr) { ++ // placeHolderwindow_->Destroy(); ++ // placeHolderwindow_ = nullptr; ++ // return; ++ // } ++ ++ // auto addr = static_cast(buffer->GetVirAddr()); ++ // DoDraw(addr, buffer->GetWidth(), buffer->GetHeight()); ++ // OHOS::BufferFlushConfig flushConfig = { ++ // .damage = { ++ // .w = buffer->GetWidth(), ++ // .h = buffer->GetHeight(), ++ // }, ++ // }; ++ // OHOS::SurfaceError ret = layer->FlushBuffer(buffer, -1, flushConfig); ++ // WLOGFD("draw pointer FlushBuffer ret:%{public}s", SurfaceErrorStr(ret).c_str()); ++ placeHolderwindow_->Show(); ++ return; ++} ++ ++sptr WindowInnerManager::GetLayer() ++{ ++ std::shared_ptr surfaceNode = placeHolderwindow_->GetSurfaceNode(); ++ if (surfaceNode == nullptr) { ++ placeHolderwindow_->Destroy(); ++ placeHolderwindow_ = nullptr; ++ return nullptr; ++ } ++ return surfaceNode->GetSurface(); ++} ++ ++sptr WindowInnerManager::GetSurfaceBuffer(sptr layer) const ++{ ++ sptr buffer; ++ int32_t releaseFence = 0; ++ OHOS::BufferRequestConfig config = { ++ .width = IMAGE_WIDTH, ++ .height = IMAGE_HEIGHT, ++ .strideAlignment = 0x8, ++ .format = PIXEL_FMT_RGBA_8888, ++ .usage = HBM_USE_CPU_READ | HBM_USE_CPU_WRITE | HBM_USE_MEM_DMA, ++ }; ++ ++ OHOS::SurfaceError ret = layer->RequestBuffer(buffer, releaseFence, config); ++ if (ret != OHOS::SURFACE_ERROR_OK) { ++ WLOGFE("request buffer ret:%{public}s", SurfaceErrorStr(ret).c_str()); ++ return nullptr; ++ } ++ return buffer; ++} ++ + void WindowInnerManager::HandleDestroyWindow() + { + if (dialogId_ == -1) { +diff --git a/wmserver/src/window_pair.cpp b/wmserver/src/window_pair.cpp +index 095b4add..3b018ba3 100644 +--- a/wmserver/src/window_pair.cpp ++++ b/wmserver/src/window_pair.cpp +@@ -327,15 +327,21 @@ void WindowPair::UpdateIfSplitRelated(sptr& node) + WLOGI("Window id: %{public}u is not split related and paired.", node->GetWindowId()); + return; + } ++ if ((node->GetWindowType() == WindowType::WINDOW_TYPE_PLACE_HOLDER) && ++ ((primary_ != nullptr && primary_->GetWindowMode() == node->GetWindowMode()) || ++ (secondary_ != nullptr && secondary_->GetWindowMode() == node->GetWindowMode()))) { ++ WindowInnerManager::GetInstance().DestroyPlaceHolderWindow(); ++ return; ++ } + WLOGI("Current status: %{public}u, window id: %{public}u mode: %{public}u", + status_, node->GetWindowId(), node->GetWindowMode()); + if (status_ == WindowPairStatus::STATUS_EMPTY) { + Insert(node); + if (!isAllAppWindowsRestoring_) { + // find pairable window from trees or send broadcast +- sptr pairableNode = GetPairableWindow(node); +- // insert pairable node +- Insert(pairableNode); ++ WindowMode holderMode = node->GetWindowMode() == WindowMode::WINDOW_MODE_SPLIT_PRIMARY ? ++ WindowMode::WINDOW_MODE_SPLIT_SECONDARY : WindowMode::WINDOW_MODE_SPLIT_PRIMARY; ++ WindowInnerManager::GetInstance().CreatePlaceHolderWindow(holderMode, displayId_); + } + } else { + if (Find(node) == nullptr) { +@@ -432,6 +438,10 @@ void WindowPair::Insert(sptr& node) + if (node == nullptr) { + return; + } ++ // if (node->GetWindowType() == WindowType::WINDOW_TYPE_PLACE_HOLDER) { ++ // placeholder_ = node; ++ // return; ++ // } + WLOGI("Insert a window to pair id: %{public}u", node->GetWindowId()); + sptr pairedNode; + if (node->GetWindowMode() == WindowMode::WINDOW_MODE_SPLIT_PRIMARY) { +@@ -448,6 +458,10 @@ void WindowPair::Insert(sptr& node) + if (pairedNode != nullptr && pairedNode->abilityToken_ != nullptr) { + MinimizeApp::AddNeedMinimizeApp(pairedNode, MinimizeReason::SPLIT_REPLACE); + } ++ // if (placeholder_ != nullptr) { ++ // WindowInnerManager::GetInstance().DestroyPlaceHolderWindow(); ++ // placeholder_ = nullptr; ++ // } + UpdateWindowPairStatus(); + } + +-- +2.25.1 + diff --git a/interfaces/innerkits/wm/window.h b/interfaces/innerkits/wm/window.h index c1451688..cc4b6510 100644 --- a/interfaces/innerkits/wm/window.h +++ b/interfaces/innerkits/wm/window.h @@ -205,9 +205,9 @@ public: virtual void RequestFrame() = 0; virtual void UpdateConfiguration(const std::shared_ptr& configuration) = 0; - virtual void RegisterLifeCycleListener(sptr& listener) = 0; + virtual void RegisterLifeCycleListener(const sptr& listener) = 0; virtual void RegisterWindowChangeListener(sptr& listener) = 0; - virtual void UnregisterLifeCycleListener(sptr& listener) = 0; + virtual void UnregisterLifeCycleListener(const sptr& listener) = 0; virtual void UnregisterWindowChangeListener(sptr& listener) = 0; virtual void RegisterAvoidAreaChangeListener(sptr& listener) = 0; virtual void UnregisterAvoidAreaChangeListener(sptr& listener) = 0; @@ -215,8 +215,8 @@ public: virtual void UnregisterDragListener(const sptr& listener) = 0; virtual void RegisterDisplayMoveListener(sptr& listener) = 0; virtual void UnregisterDisplayMoveListener(sptr& listener) = 0; - virtual void RegisterInputEventListener(sptr& listener) = 0; - virtual void UnregisterInputEventListener(sptr& listener) = 0; + virtual void RegisterInputEventListener(const sptr& listener) = 0; + virtual void UnregisterInputEventListener(const sptr& listener) = 0; virtual void RegisterWindowDestroyedListener(const NotifyNativeWinDestroyFunc& func) = 0; virtual void RegisterOccupiedAreaChangeListener(const sptr& listener) = 0; virtual void UnregisterOccupiedAreaChangeListener(const sptr& listener) = 0; diff --git a/interfaces/innerkits/wm/wm_common.h b/interfaces/innerkits/wm/wm_common.h index 24da28ce..bf4a8ccf 100644 --- a/interfaces/innerkits/wm/wm_common.h +++ b/interfaces/innerkits/wm/wm_common.h @@ -43,6 +43,7 @@ enum class WindowType : uint32_t { ABOVE_APP_SYSTEM_WINDOW_BASE = 2100, WINDOW_TYPE_APP_LAUNCHING = ABOVE_APP_SYSTEM_WINDOW_BASE, WINDOW_TYPE_DOCK_SLICE, + WINDOW_TYPE_PLACE_HOLDER, WINDOW_TYPE_INCOMING_CALL, WINDOW_TYPE_SEARCHING_BAR, WINDOW_TYPE_SYSTEM_ALARM_WINDOW, diff --git a/resources/config/rk3568/window_manager_config.xml b/resources/config/rk3568/window_manager_config.xml index 70ca77e2..9c11c5a9 100644 --- a/resources/config/rk3568/window_manager_config.xml +++ b/resources/config/rk3568/window_manager_config.xml @@ -15,7 +15,7 @@ --> - + 100 diff --git a/resources/media/BUILD.gn b/resources/media/BUILD.gn index 1f2b8c85..6d152d78 100644 --- a/resources/media/BUILD.gn +++ b/resources/media/BUILD.gn @@ -19,6 +19,16 @@ ohos_prebuilt_etc("window_divider_image") { relative_install_dir = "window/resources" } -group("window_resources_media") { - deps = [ ":window_divider_image" ] +ohos_prebuilt_etc("window_place_holder_image") { + source = "//foundation/windowmanager/resources/media/img/bg_place_holder.png" + part_name = "window_manager" + subsystem_name = "window" + relative_install_dir = "window/resources" +} + + +group("window_resources_media") { + deps = [ ":window_divider_image", + ":window_place_holder_image" + ] } diff --git a/resources/media/img/bg_place_holder.png b/resources/media/img/bg_place_holder.png new file mode 100644 index 0000000000000000000000000000000000000000..9936aee1a38039dba2ddfacaf56ce9d8c94a1f59 GIT binary patch literal 3500 zcmeH~k55xa9Ker?ii(mfnUINK+>EJHV2sg*m0zM$>I71M01padt|~SyqSykZ1%JUd z9cXA+#-L1H!Htyq>$O0kW$U2P1}ma1Qr;{0<~sH))v~tK(ss{3V+qOKeJ|hp=DwHv z-re_e-{fTNS-bkZ)c}CCnR|CJ03Z=v5(rsAh<_`eydlJ@lY8?|0}%86+Zt3UP2~~B zMVY(O4_3C>ko`>?b9d@yPXGE)cpH&WcWj|g+#+4OvR_d{Qh#`|yq-`*TZGCvo{AquG0d|HOioJ+%QLFrXv0z$A9a={ zNeot>f|FqvE@;D|!9udLJW^?#tf59`d3~ay7M9SIuD??Vmqa{>3uWcE@KQRWk*TS| z&&MmK6r6-*0EFer;3tsMC#u~h4aKNMP1r<3$pp%qiVKy>aL9OOV^`^9F_XzGEG|xM zw|Z`I%z5m00eF?>M7?pLW}3mvG1r$wD9R&E{N-t6>AhI>!u6Vf&uyznN>=yv^-X<(oIE9{9WtB<4-eORYEWWvG)d>|{r;W?#)C)R zCY=-2(+onUNht{dy?j{AI3YX2=4g6wHJtd;?R^Xh@UxuO&Y7B&=!e$%8?1bnRQzUq zxYn$QH_W@99qX_)>9DdJ08~=Bxi6bk$lOUk9{UmOb{tj?U8R3R+a)c}0?sDRZ85 zXJ{21=iJAEuJKauKizVX^ZD?l;fv8Ag$5gOR=&R`qMlKdj|T4Nh}v9o`P@KnZv+>y z>TWtd1%1_^6y$YiO z!Xf(XW&lz|8Eg(>;~ikz3hCvs00c)6#_Jli_bm2oj2Z(UzDt1T)n4D1fys-)<1!9G zb2YRmIbVg0QXBPmwiAG#LV}Ht1*sMUm8909#KW2gQ~3nMD;>AgDq5V*UJTVFNAM6<|tlM_vzLuVn$0NwjhU%TZc~p zK>G?7$H(d&cC*3>;eKn%f)Vs4k6{E`-pC_?y0G5}k58ZmrSNZNP!63eHC8XOMuGt? zxJ}s#52*ycqUIg@BW(#Qrz)s;WFc668ED3|j$uqw)Tpz?zB+d0T$>pN5F< P7s%Y5wX0|67w7&1Q$p_} literal 0 HcmV?d00001 diff --git a/utils/BUILD.gn b/utils/BUILD.gn index a04be886..92a89935 100644 --- a/utils/BUILD.gn +++ b/utils/BUILD.gn @@ -45,6 +45,7 @@ ohos_shared_library("libwmutil") { "src/window_property.cpp", "src/window_transition_info.cpp", "src/wm_trace.cpp", + "src/draw_surface.cpp" ] configs = [ ":libwmutil_private_config" ] @@ -54,6 +55,7 @@ ohos_shared_library("libwmutil") { deps = [ "//foundation/graphic/graphic_2d/rosen/modules/render_service_base:librender_service_base", "//foundation/graphic/graphic_2d/rosen/modules/render_service_client:librender_service_client", + "//foundation/graphic/graphic_2d/rosen/modules/2d_graphics:2d_graphics", "//third_party/flutter/build/skia:ace_skia_ohos", ] diff --git a/utils/include/draw_surface.h b/utils/include/draw_surface.h new file mode 100644 index 00000000..1dd19395 --- /dev/null +++ b/utils/include/draw_surface.h @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2022-2022 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 DRAW_SURFACE_H +#define DRAW_SURFACE_H + +#include "draw/canvas.h" +#include "nocopyable.h" +#include "pixel_map.h" +#include "refbase.h" +#include "ui/rs_surface_node.h" +#include "wm_common.h" +#include "window.h" + +namespace OHOS { +namespace Rosen { +class DrawSurface { +public: + ~DrawSurface() = default; + static bool DrawColor(std::shared_ptr surfaceNode, int32_t bufferWidth, + int32_t bufferHeight, uint32_t color); + static bool DrawImage(std::shared_ptr surfaceNode, int32_t bufferWidth, + int32_t bufferHeight,const std::string& imagePath); +private: + DrawSurface() {}; + static bool DoDraw(uint8_t *addr, uint32_t width, uint32_t height, const std::string& imagePath); + static bool DoDraw(uint8_t *addr, uint32_t width, uint32_t height, uint32_t color); + static sptr GetLayer(std::shared_ptr surfaceNode); + static sptr GetSurfaceBuffer(sptr layer, + int32_t bufferWidth, int32_t bufferHeight); + static void DrawPixelmap(OHOS::Rosen::Drawing::Canvas &canvas, const std::string& imagePath); + static std::unique_ptr DecodeImageToPixelMap(const std::string &imagePath); +}; +} // Rosen +} // OHOS +#endif // DRAW_SURFACE_H \ No newline at end of file diff --git a/utils/include/surface_draw.h b/utils/include/surface_draw.h index b312159f..f44ac6e5 100644 --- a/utils/include/surface_draw.h +++ b/utils/include/surface_draw.h @@ -23,6 +23,9 @@ #endif #include "refbase.h" #include "wm_common.h" +#include "draw/canvas.h" +#include "nocopyable.h" +#include "pixel_map.h" namespace OHOS { namespace Rosen { @@ -37,10 +40,21 @@ public: bool DecodeImageFile(const char* filename, SkBitmap& bitmap); void DrawSkImage(std::shared_ptr surfaceNode, Rect winRect, sptr pixelMap, uint32_t bkgColor); + static bool DrawColor(std::shared_ptr surfaceNode, int32_t bufferWidth, + int32_t bufferHeight, uint32_t color); + static bool DrawImage(std::shared_ptr surfaceNode, int32_t bufferWidth, + int32_t bufferHeight,const std::string& imagePath); private: std::shared_ptr PrepareDraw(std::shared_ptr surfaceNode, std::unique_ptr& frame, SkCanvas*& canvas, uint32_t width, uint32_t height); + static bool DoDraw(uint8_t *addr, uint32_t width, uint32_t height, const std::string& imagePath); + static bool DoDraw(uint8_t *addr, uint32_t width, uint32_t height, uint32_t color); + static sptr GetLayer(std::shared_ptr surfaceNode); + static sptr GetSurfaceBuffer(sptr layer, + int32_t bufferWidth, int32_t bufferHeight); + static void DrawPixelmap(OHOS::Rosen::Drawing::Canvas &canvas, const std::string& imagePath); + static std::unique_ptr DecodeImageToPixelMap(const std::string &imagePath); #ifdef ACE_ENABLE_GL std::unique_ptr rc_ = nullptr; diff --git a/utils/src/draw_surface.cpp b/utils/src/draw_surface.cpp new file mode 100644 index 00000000..06a0aa5a --- /dev/null +++ b/utils/src/draw_surface.cpp @@ -0,0 +1,195 @@ +/* + * Copyright (c) 2022-2022 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 "draw_surface.h" +#include "image/bitmap.h" +#include "image_source.h" +#include "image_type.h" +#include "image_utils.h" +#include "pixel_map.h" +#include "window_manager_hilog.h" + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "DrawSurface"}; +} // namespace + +bool DrawSurface::DrawImage(std::shared_ptr surfaceNode, int32_t bufferWidth, int32_t bufferHeight, + const std::string& imagePath) +{ + sptr layer = GetLayer(surfaceNode); + if (layer == nullptr) { + WLOGFE("layer is nullptr"); + return false; + } + sptr buffer = GetSurfaceBuffer(layer, bufferWidth, bufferHeight); + if (buffer == nullptr || buffer->GetVirAddr() == nullptr) { + return false; + } + auto addr = static_cast(buffer->GetVirAddr()); + if (!DoDraw(addr, buffer->GetWidth(), buffer->GetHeight(), imagePath)) { + WLOGE("draw window pixel failed"); + return false; + } + OHOS::BufferFlushConfig flushConfig = { + .damage = { + .w = buffer->GetWidth(), + .h = buffer->GetHeight(), + }, + }; + OHOS::SurfaceError ret = layer->FlushBuffer(buffer, -1, flushConfig); + if (ret != OHOS::SurfaceError::SURFACE_ERROR_OK) { + WLOGFE("draw pointer FlushBuffer ret:%{public}s", SurfaceErrorStr(ret).c_str()); + return false; + } + return true; +} + +bool DrawSurface::DrawColor(std::shared_ptr surfaceNode, int32_t bufferWidth, int32_t bufferHeight, + uint32_t color) +{ + sptr layer = GetLayer(surfaceNode); + if (layer == nullptr) { + WLOGFE("layer is nullptr"); + return false; + } + sptr buffer = GetSurfaceBuffer(layer, bufferWidth, bufferHeight); + if (buffer == nullptr || buffer->GetVirAddr() == nullptr) { + return false; + } + auto addr = static_cast(buffer->GetVirAddr()); + if (!DoDraw(addr, buffer->GetWidth(), buffer->GetHeight(), color)) { + WLOGE("draw window color failed"); + return false; + } + OHOS::BufferFlushConfig flushConfig = { + .damage = { + .w = buffer->GetWidth(), + .h = buffer->GetHeight(), + }, + }; + OHOS::SurfaceError ret = layer->FlushBuffer(buffer, -1, flushConfig); + if (ret != OHOS::SurfaceError::SURFACE_ERROR_OK) { + WLOGFE("draw pointer FlushBuffer ret:%{public}s", SurfaceErrorStr(ret).c_str()); + return false; + } + return true; +} + +sptr DrawSurface::GetLayer(std::shared_ptr surfaceNode) +{ + if (surfaceNode == nullptr) { + return nullptr; + } + return surfaceNode->GetSurface(); +} + +sptr DrawSurface::GetSurfaceBuffer(sptr layer, + int32_t bufferWidth, int32_t bufferHeight) +{ + sptr buffer; + int32_t releaseFence = 0; + OHOS::BufferRequestConfig config = { + .width = bufferWidth, + .height = bufferHeight, + .strideAlignment = 0x8, + .format = PIXEL_FMT_RGBA_8888, + .usage = HBM_USE_CPU_READ | HBM_USE_CPU_WRITE | HBM_USE_MEM_DMA, + }; + + OHOS::SurfaceError ret = layer->RequestBuffer(buffer, releaseFence, config); + if (ret != OHOS::SURFACE_ERROR_OK) { + WLOGFE("request buffer ret:%{public}s", SurfaceErrorStr(ret).c_str()); + return nullptr; + } + return buffer; +} + +std::unique_ptr DrawSurface::DecodeImageToPixelMap(const std::string &imagePath) +{ + OHOS::Media::SourceOptions opts; + opts.formatHint = "image/png"; + uint32_t ret = 0; + auto imageSource = OHOS::Media::ImageSource::CreateImageSource(imagePath, opts, ret); + // CHKPP(imageSource); + std::set formats; + ret = imageSource->GetSupportedFormats(formats); + WLOGFD("get supported format ret:%{public}u", ret); + + OHOS::Media::DecodeOptions decodeOpts; + std::unique_ptr pixelMap = imageSource->CreatePixelMap(decodeOpts, ret); + if (pixelMap == nullptr) { + WLOGFE("pixelMap is nullptr"); + } + return pixelMap; +} + +void DrawSurface::DrawPixelmap(OHOS::Rosen::Drawing::Canvas &canvas, const std::string& imagePath) +{ + std::unique_ptr pixelmap = DecodeImageToPixelMap(imagePath); + if (pixelmap == nullptr) { + WLOGFE("drawing pixel map is nullptr"); + return; + } + OHOS::Rosen::Drawing::Pen pen; + pen.SetAntiAlias(true); + pen.SetColor(OHOS::Rosen::Drawing::Color::COLOR_BLUE); + OHOS::Rosen::Drawing::scalar penWidth = 1; + pen.SetWidth(penWidth); + canvas.AttachPen(pen); + canvas.DrawBitmap(*pixelmap, 0, 0); +} + +bool DrawSurface::DoDraw(uint8_t *addr, uint32_t width, uint32_t height, const std::string& imagePath) +{ + OHOS::Rosen::Drawing::Bitmap bitmap; + OHOS::Rosen::Drawing::BitmapFormat format { OHOS::Rosen::Drawing::COLORTYPE_RGBA_8888, + OHOS::Rosen::Drawing::ALPHATYPE_OPAQUYE }; + bitmap.Build(width, height, format); + OHOS::Rosen::Drawing::Canvas canvas; + canvas.Bind(bitmap); + canvas.Clear(OHOS::Rosen::Drawing::Color::COLOR_TRANSPARENT); + DrawPixelmap(canvas, imagePath); + static constexpr uint32_t stride = 4; + uint32_t addrSize = width * height * stride; + errno_t ret = memcpy_s(addr, addrSize, bitmap.GetPixels(), addrSize); + if (ret != EOK) { + WLOGFE("draw failed"); + return false; + } + return true; +} +bool DrawSurface::DoDraw(uint8_t *addr, uint32_t width, uint32_t height, uint32_t color) +{ + OHOS::Rosen::Drawing::Bitmap bitmap; + OHOS::Rosen::Drawing::BitmapFormat format { OHOS::Rosen::Drawing::COLORTYPE_RGBA_8888, + OHOS::Rosen::Drawing::ALPHATYPE_OPAQUYE }; + bitmap.Build(width, height, format); + OHOS::Rosen::Drawing::Canvas canvas; + canvas.Bind(bitmap); + canvas.Clear(color); + + static constexpr uint32_t stride = 4; + uint32_t addrSize = width * height * stride; + errno_t ret = memcpy_s(addr, addrSize, bitmap.GetPixels(), addrSize); + if (ret != EOK) { + WLOGFE("draw failed"); + return false; + } + return true; +} +} // Rosen +} // OHOS \ No newline at end of file diff --git a/utils/src/surface_draw.cpp b/utils/src/surface_draw.cpp index d4ebc775..26488bfe 100644 --- a/utils/src/surface_draw.cpp +++ b/utils/src/surface_draw.cpp @@ -24,6 +24,12 @@ #include "include/core/SkData.h" #include "include/core/SkImage.h" #include "include/core/SkPixmap.h" +#include "image/bitmap.h" +#include "image_source.h" +#include "image_type.h" +#include "image_utils.h" +#include "pixel_map.h" + namespace OHOS { namespace Rosen { namespace { @@ -234,5 +240,171 @@ void SurfaceDraw::DrawSkImage(std::shared_ptr surfaceNode, Rect w } return; } + +bool SurfaceDraw::DrawImage(std::shared_ptr surfaceNode, int32_t bufferWidth, int32_t bufferHeight, + const std::string& imagePath) +{ + sptr layer = GetLayer(surfaceNode); + if (layer == nullptr) { + WLOGFE("layer is nullptr"); + return false; + } + sptr buffer = GetSurfaceBuffer(layer, bufferWidth, bufferHeight); + if (buffer == nullptr || buffer->GetVirAddr() == nullptr) { + return false; + } + auto addr = static_cast(buffer->GetVirAddr()); + if (!DoDraw(addr, buffer->GetWidth(), buffer->GetHeight(), imagePath)) { + WLOGE("draw window pixel failed"); + return false; + } + OHOS::BufferFlushConfig flushConfig = { + .damage = { + .w = buffer->GetWidth(), + .h = buffer->GetHeight(), + }, + }; + OHOS::SurfaceError ret = layer->FlushBuffer(buffer, -1, flushConfig); + if (ret != OHOS::SurfaceError::SURFACE_ERROR_OK) { + WLOGFE("draw pointer FlushBuffer ret:%{public}s", SurfaceErrorStr(ret).c_str()); + return false; + } + return true; +} + +bool SurfaceDraw::DrawColor(std::shared_ptr surfaceNode, int32_t bufferWidth, int32_t bufferHeight, + uint32_t color) +{ + sptr layer = GetLayer(surfaceNode); + if (layer == nullptr) { + WLOGFE("layer is nullptr"); + return false; + } + sptr buffer = GetSurfaceBuffer(layer, bufferWidth, bufferHeight); + if (buffer == nullptr || buffer->GetVirAddr() == nullptr) { + return false; + } + auto addr = static_cast(buffer->GetVirAddr()); + if (!DoDraw(addr, buffer->GetWidth(), buffer->GetHeight(), color)) { + WLOGE("draw window color failed"); + return false; + } + OHOS::BufferFlushConfig flushConfig = { + .damage = { + .w = buffer->GetWidth(), + .h = buffer->GetHeight(), + }, + }; + OHOS::SurfaceError ret = layer->FlushBuffer(buffer, -1, flushConfig); + if (ret != OHOS::SurfaceError::SURFACE_ERROR_OK) { + WLOGFE("draw pointer FlushBuffer ret:%{public}s", SurfaceErrorStr(ret).c_str()); + return false; + } + return true; +} + +sptr SurfaceDraw::GetLayer(std::shared_ptr surfaceNode) +{ + if (surfaceNode == nullptr) { + return nullptr; + } + return surfaceNode->GetSurface(); +} + +sptr SurfaceDraw::GetSurfaceBuffer(sptr layer, + int32_t bufferWidth, int32_t bufferHeight) +{ + sptr buffer; + int32_t releaseFence = 0; + OHOS::BufferRequestConfig config = { + .width = bufferWidth, + .height = bufferHeight, + .strideAlignment = 0x8, + .format = PIXEL_FMT_RGBA_8888, + .usage = HBM_USE_CPU_READ | HBM_USE_CPU_WRITE | HBM_USE_MEM_DMA, + }; + + OHOS::SurfaceError ret = layer->RequestBuffer(buffer, releaseFence, config); + if (ret != OHOS::SURFACE_ERROR_OK) { + WLOGFE("request buffer ret:%{public}s", SurfaceErrorStr(ret).c_str()); + return nullptr; + } + return buffer; +} + +std::unique_ptr SurfaceDraw::DecodeImageToPixelMap(const std::string &imagePath) +{ + OHOS::Media::SourceOptions opts; + opts.formatHint = "image/png"; + uint32_t ret = 0; + auto imageSource = OHOS::Media::ImageSource::CreateImageSource(imagePath, opts, ret); + // CHKPP(imageSource); + std::set formats; + ret = imageSource->GetSupportedFormats(formats); + WLOGFD("get supported format ret:%{public}u", ret); + + OHOS::Media::DecodeOptions decodeOpts; + std::unique_ptr pixelMap = imageSource->CreatePixelMap(decodeOpts, ret); + if (pixelMap == nullptr) { + WLOGFE("pixelMap is nullptr"); + } + return pixelMap; +} + +void SurfaceDraw::DrawPixelmap(OHOS::Rosen::Drawing::Canvas &canvas, const std::string& imagePath) +{ + std::unique_ptr pixelmap = DecodeImageToPixelMap(imagePath); + if (pixelmap == nullptr) { + WLOGFE("drawing pixel map is nullptr"); + return; + } + OHOS::Rosen::Drawing::Pen pen; + pen.SetAntiAlias(true); + pen.SetColor(OHOS::Rosen::Drawing::Color::COLOR_BLUE); + OHOS::Rosen::Drawing::scalar penWidth = 1; + pen.SetWidth(penWidth); + canvas.AttachPen(pen); + canvas.DrawBitmap(*pixelmap, 0, 0); +} + +bool SurfaceDraw::DoDraw(uint8_t *addr, uint32_t width, uint32_t height, const std::string& imagePath) +{ + OHOS::Rosen::Drawing::Bitmap bitmap; + OHOS::Rosen::Drawing::BitmapFormat format { OHOS::Rosen::Drawing::COLORTYPE_RGBA_8888, + OHOS::Rosen::Drawing::ALPHATYPE_OPAQUYE }; + bitmap.Build(width, height, format); + OHOS::Rosen::Drawing::Canvas canvas; + canvas.Bind(bitmap); + canvas.Clear(OHOS::Rosen::Drawing::Color::COLOR_TRANSPARENT); + DrawPixelmap(canvas, imagePath); + static constexpr uint32_t stride = 4; + uint32_t addrSize = width * height * stride; + errno_t ret = memcpy_s(addr, addrSize, bitmap.GetPixels(), addrSize); + if (ret != EOK) { + WLOGFE("draw failed"); + return false; + } + return true; +} + +bool SurfaceDraw::DoDraw(uint8_t *addr, uint32_t width, uint32_t height, uint32_t color) +{ + OHOS::Rosen::Drawing::Bitmap bitmap; + OHOS::Rosen::Drawing::BitmapFormat format { OHOS::Rosen::Drawing::COLORTYPE_RGBA_8888, + OHOS::Rosen::Drawing::ALPHATYPE_OPAQUYE }; + bitmap.Build(width, height, format); + OHOS::Rosen::Drawing::Canvas canvas; + canvas.Bind(bitmap); + canvas.Clear(color); + + static constexpr uint32_t stride = 4; + uint32_t addrSize = width * height * stride; + errno_t ret = memcpy_s(addr, addrSize, bitmap.GetPixels(), addrSize); + if (ret != EOK) { + WLOGFE("draw failed"); + return false; + } + return true; +} } // Rosen } // OHOS \ No newline at end of file diff --git a/wm/include/window_impl.h b/wm/include/window_impl.h index 0ac4b1cb..b046dd4b 100644 --- a/wm/include/window_impl.h +++ b/wm/include/window_impl.h @@ -171,9 +171,9 @@ public: virtual WMError RequestFocus() const override; virtual void AddInputEventListener(const std::shared_ptr& inputEventListener) override; - virtual void RegisterLifeCycleListener(sptr& listener) override; + virtual void RegisterLifeCycleListener(const sptr& listener) override; virtual void RegisterWindowChangeListener(sptr& listener) override; - virtual void UnregisterLifeCycleListener(sptr& listener) override; + virtual void UnregisterLifeCycleListener(const sptr& listener) override; virtual void UnregisterWindowChangeListener(sptr& listener) override; virtual void RegisterAvoidAreaChangeListener(sptr& listener) override; virtual void UnregisterAvoidAreaChangeListener(sptr& listener) override; @@ -181,8 +181,8 @@ public: virtual void UnregisterDragListener(const sptr& listener) override; virtual void RegisterDisplayMoveListener(sptr& listener) override; virtual void UnregisterDisplayMoveListener(sptr& listener) override; - virtual void RegisterInputEventListener(sptr& listener) override; - virtual void UnregisterInputEventListener(sptr& listener) override; + virtual void RegisterInputEventListener(const sptr& listener) override; + virtual void UnregisterInputEventListener(const sptr& listener) override; virtual void RegisterWindowDestroyedListener(const NotifyNativeWinDestroyFunc& func) override; virtual void RegisterOccupiedAreaChangeListener(const sptr& listener) override; virtual void UnregisterOccupiedAreaChangeListener(const sptr& listener) override; diff --git a/wm/src/window_impl.cpp b/wm/src/window_impl.cpp index 0dcecf56..84cf23b1 100644 --- a/wm/src/window_impl.cpp +++ b/wm/src/window_impl.cpp @@ -1311,7 +1311,7 @@ void WindowImpl::AddInputEventListener(const std::shared_ptr& listener) +void WindowImpl::RegisterLifeCycleListener(const sptr& listener) { if (listener == nullptr) { return; @@ -1338,7 +1338,7 @@ void WindowImpl::RegisterWindowChangeListener(sptr& liste windowChangeListeners_.emplace_back(listener); } -void WindowImpl::UnregisterLifeCycleListener(sptr& listener) +void WindowImpl::UnregisterLifeCycleListener(const sptr& listener) { std::lock_guard lock(mutex_); lifecycleListeners_.erase(std::remove_if(lifecycleListeners_.begin(), lifecycleListeners_.end(), @@ -1440,7 +1440,7 @@ void WindowImpl::UnregisterDisplayMoveListener(sptr& liste displayMoveListeners_.erase(iter); } -void WindowImpl::RegisterInputEventListener(sptr& listener) +void WindowImpl::RegisterInputEventListener(const sptr& listener) { if (listener == nullptr) { return; @@ -1453,7 +1453,7 @@ void WindowImpl::RegisterInputEventListener(sptr& listener) inputEventListeners_.emplace_back(listener); } -void WindowImpl::UnregisterInputEventListener(sptr& listener) +void WindowImpl::UnregisterInputEventListener(const sptr& listener) { std::lock_guard lock(mutex_); auto iter = std::find(inputEventListeners_.begin(), inputEventListeners_.end(), listener); @@ -2305,6 +2305,10 @@ void WindowImpl::SetDefaultOption() property_->SetFocusable(false); break; } + case WindowType::WINDOW_TYPE_PLACE_HOLDER: { + AddWindowFlag(WindowFlag::WINDOW_FLAG_FORBID_SPLIT_MOVE); + break; + } default: break; } diff --git a/wmserver/BUILD.gn b/wmserver/BUILD.gn index 6637bc4c..c6cd4bee 100644 --- a/wmserver/BUILD.gn +++ b/wmserver/BUILD.gn @@ -67,12 +67,14 @@ ohos_shared_library("libwms") { "src/window_task_looper.cpp", "src/window_zorder_policy.cpp", "src/zidl/window_manager_stub.cpp", + "src/inner_window.cpp" ] configs = [ ":libwms_config" ] deps = [ "//foundation/arkui/ace_engine/interfaces/inner_api/ui_service_manager:ui_service_mgr", + "//foundation/graphic/graphic_2d/rosen/modules/2d_graphics:2d_graphics", "//foundation/graphic/graphic_2d/rosen/modules/render_service_client:librender_service_client", "//foundation/windowmanager/dm:libdm", "//foundation/windowmanager/dmserver:libdms", diff --git a/wmserver/include/inner_window.h b/wmserver/include/inner_window.h new file mode 100644 index 00000000..73fb4228 --- /dev/null +++ b/wmserver/include/inner_window.h @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2022 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_INNER_WINDOW_H +#define OHOS_ROSEN_INNER_WINDOW_H + +#include +#include +#include "window.h" +#include "window_manager_hilog.h" +#include "wm_single_instance.h" + +namespace OHOS { +namespace Rosen { +enum class InnerWindowState : uint32_t { + INNER_WINDOW_STATE_NLL, + INNER_WINDOW_STATE_CRATED, + INNER_WINDOW_STATE_DESTROYED +}; +class IInnerWindow : virtual public RefBase { +public: + virtual void Create() = 0; + virtual void Destroy() = 0; + InnerWindowState GetState() { + return state_; + }; +protected: + InnerWindowState state_ = InnerWindowState::INNER_WINDOW_STATE_NLL; +}; + +class PlaceHolderWindow : public IInnerWindow, public IWindowLifeCycle, public ITouchOutsideListener, + public IInputEventListener { +public: + PlaceHolderWindow(std::string name, DisplayId displyId, const Rect& rect, WindowMode mode) : name_(name), + displayId_(displyId), rect_(rect), mode_(mode) {}; + ~PlaceHolderWindow(); + void Create(); + void Destroy(); + +private: + virtual void OnTouchOutside(); + virtual void OnKeyEvent(std::shared_ptr& keyEvent); + virtual void OnPointerInputEvent(std::shared_ptr& pointerEvent); + virtual void AfterForeground() {}; + virtual void AfterBackground() {}; + virtual void AfterFocused() {}; + virtual void AfterInactive() {}; + virtual void AfterUnfocused(); + void UnRegitsterWindowListener(); + void RegitsterWindowListener(); + +private: + std::string name_; + DisplayId displayId_; + Rect rect_; + WindowMode mode_; + sptr window_; + std::string contentImgPath_ = "/etc/window/resources/bg_place_holder.png"; +}; + +class DividerWindow : public IInnerWindow { +public: + DividerWindow(std::string name, DisplayId displyId, const Rect& rect) : name_(name), + displayId_(displyId), rect_(rect) {}; + ~DividerWindow(); + void Create(); + void Destroy(); + +private: + std::string name_; + DisplayId displayId_; + Rect rect_; + int32_t dialogId_ = -1; + +}; + +class InnerWindowFactory : public RefBase { +WM_DECLARE_SINGLE_INSTANCE(InnerWindowFactory); +public: + WMError CreateInnerWindow(std::string name, DisplayId displyId, Rect rect, WindowType type, WindowMode mode); + WMError DestroyInnerWindow(DisplayId displyId, WindowType type); +private: + std::unordered_map> innerWindowMap_; +}; +} // namespace Rosen +} // namespace OHOS +#endif // OHOS_ROSEN_INNER_WINDOW_H \ No newline at end of file diff --git a/wmserver/include/window_inner_manager.h b/wmserver/include/window_inner_manager.h index 3ab54045..30221d04 100644 --- a/wmserver/include/window_inner_manager.h +++ b/wmserver/include/window_inner_manager.h @@ -20,20 +20,45 @@ #include "event_handler.h" #include "event_runner.h" +#include +#include "draw/canvas.h" +#include "nocopyable.h" +#include "pixel_map.h" + #include "wm_common.h" #include "wm_single_instance.h" +#include "window.h" +#include "inner_window.h" namespace OHOS { namespace Rosen { +class TouchOutsideListener : public ITouchOutsideListener { + virtual void OnTouchOutside(); +}; +class InputListener : public IInputEventListener { + virtual void OnKeyEvent(std::shared_ptr& keyEvent); + virtual void OnPointerInputEvent(std::shared_ptr& pointerEvent); +}; +class LifeCycle : public IWindowLifeCycle { + virtual void AfterForeground() {}; + virtual void AfterBackground() {}; + virtual void AfterFocused() {}; + virtual void AfterInactive() {}; + virtual void AfterUnfocused(); +}; class WindowInnerManager : public RefBase { +friend class TouchOutsideListener; +friend class InputListener; +friend class LifeCycle; WM_DECLARE_SINGLE_INSTANCE_BASE(WindowInnerManager); using EventRunner = OHOS::AppExecFwk::EventRunner; using EventHandler = OHOS::AppExecFwk::EventHandler; public: void Start(); void Stop(); - void CreateWindow(std::string name, WindowType type, Rect rect); - void DestroyWindow(); + void CreteInnerWindow(std::string name, DisplayId displyId, Rect rect, + WindowType type, WindowMode mode); + void DestroyInnerWindow(DisplayId displyId, WindowType type); public: enum class InnerWMRunningState { STATE_NOT_START, @@ -44,15 +69,11 @@ public: private: WindowInnerManager(); bool Init(); - void HandleCreateWindow(std::string name, WindowType type, Rect rect); - void HandleDestroyWindow(); private: - int32_t dialogId_ = -1; std::shared_ptr eventHandler_; std::shared_ptr eventLoop_; InnerWMRunningState state_; - std::string dividerParams_ = ""; const std::string INNER_WM_THREAD_NAME = "inner_window_manager"; }; } // namespace Rosen diff --git a/wmserver/include/window_pair.h b/wmserver/include/window_pair.h index 86d8391c..237cdc4a 100644 --- a/wmserver/include/window_pair.h +++ b/wmserver/include/window_pair.h @@ -250,6 +250,7 @@ private: sptr primary_; sptr secondary_; sptr divider_; + // sptr placeholder_; WindowPairStatus status_ = {WindowPairStatus::STATUS_EMPTY}; DisplayGroupWindowTree& displayGroupWindowTree_; bool isAllAppWindowsRestoring_ { false }; diff --git a/wmserver/include/window_zorder_policy.h b/wmserver/include/window_zorder_policy.h index 8df41594..4f52082f 100644 --- a/wmserver/include/window_zorder_policy.h +++ b/wmserver/include/window_zorder_policy.h @@ -45,6 +45,7 @@ private: { WindowType::WINDOW_TYPE_APP_COMPONENT, 2 }, { WindowType::WINDOW_TYPE_APP_LAUNCHING, 101 }, { WindowType::WINDOW_TYPE_DOCK_SLICE, 0 }, + { WindowType::WINDOW_TYPE_PLACE_HOLDER, 0 }, { WindowType::WINDOW_TYPE_LAUNCHER_RECENT, 102 }, { WindowType::WINDOW_TYPE_LAUNCHER_DOCK, 103 }, { WindowType::WINDOW_TYPE_INCOMING_CALL, 104 }, diff --git a/wmserver/src/inner_window.cpp b/wmserver/src/inner_window.cpp new file mode 100644 index 00000000..6d333879 --- /dev/null +++ b/wmserver/src/inner_window.cpp @@ -0,0 +1,201 @@ +/* + * Copyright (c) 2022 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 "inner_window.h" + +#include "ui_service_mgr_client.h" +#include "window_manager_hilog.h" +#include "surface_draw.h" + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "InnerWindow"}; + const std::string IMAGE_PLACE_HOLDER_PNG_PATH = "/etc/window/resources/bg_place_holder.png"; +} +WM_IMPLEMENT_SINGLE_INSTANCE(InnerWindowFactory) +WMError InnerWindowFactory::CreateInnerWindow(std::string name, DisplayId displyId, Rect rect, + WindowType type, WindowMode mode) +{ + WLOGFI("createInnerWindow begin type: %{public}u", type); + if ((type != WindowType::WINDOW_TYPE_DOCK_SLICE) && (type != WindowType::WINDOW_TYPE_PLACE_HOLDER)) { + WLOGFE("create inner window failed, current type: %{public}u not surpport.", type); + return WMError::WM_ERROR_INVALID_TYPE; + } + if (innerWindowMap_.find(type) != std::end(innerWindowMap_)) { + if (innerWindowMap_[type] != nullptr && innerWindowMap_[type]->GetState() == + InnerWindowState::INNER_WINDOW_STATE_CRATED) { + WLOGFW("create inner window failed, current inner window type %{public}u has created.", type); + return WMError::WM_ERROR_INVALID_TYPE; + } + innerWindowMap_.erase(type); + } + switch (type) { + case WindowType::WINDOW_TYPE_DOCK_SLICE : { + innerWindowMap_[type] = std::make_unique(name, displyId, rect); + innerWindowMap_[type]->Create(); + break; + } + case WindowType::WINDOW_TYPE_PLACE_HOLDER : { + innerWindowMap_[type] = std::make_unique(name, displyId, rect, mode); + innerWindowMap_[type]->Create(); + break; + } + default : + break; + } + WLOGFI("createInnerWindow end"); + return WMError::WM_OK; +} + +WMError InnerWindowFactory::DestroyInnerWindow(DisplayId displyId, WindowType type) +{ + WLOGFI("destroy inner window type: %{public}u begin.", type); + if (innerWindowMap_.find(type) == std::end(innerWindowMap_)) { + WLOGFW("current inner window has created"); + return WMError::WM_ERROR_NULLPTR; + } + if (innerWindowMap_[type] != nullptr) { + innerWindowMap_[type]->Destroy(); + } + innerWindowMap_.erase(type); + WLOGFI("destroy inner window type: %{public}u end.", type); + return WMError::WM_OK; +} + +PlaceHolderWindow::~PlaceHolderWindow() +{ + Destroy(); +} + +void PlaceHolderWindow::OnTouchOutside() +{ + Destroy(); +} + +void PlaceHolderWindow::OnKeyEvent(std::shared_ptr& keyEvent) +{ + Destroy(); +} + +void PlaceHolderWindow::OnPointerInputEvent(std::shared_ptr& pointerEvent) +{ + Destroy(); +} + +void PlaceHolderWindow::AfterUnfocused() +{ + Destroy(); +} + +void PlaceHolderWindow::Create() +{ + WLOGFI("create inner display id: %{public}" PRIu64"", displayId_); + if (window_ != nullptr) { + WLOGFW("window has created."); + window_->Show(); + return; + } + WLOGFD("create palce holder Window start"); + sptr option = new (std::nothrow) WindowOption(); + if (option == nullptr) { + WLOGFE("window option is nullptr."); + return; + } + option->SetWindowType(WindowType::WINDOW_TYPE_PLACE_HOLDER); + option->SetWindowMode(mode_); + option->SetFocusable(false); + option->SetWindowRect(rect_); + window_ = Window::Create(name_, option); + if (window_ == nullptr) { + WLOGFE("window is nullptr."); + return; + } + RegitsterWindowListener(); + if (!OHOS::Rosen::SurfaceDraw::DrawImage(window_->GetSurfaceNode(), rect_.width_, rect_.height_, + IMAGE_PLACE_HOLDER_PNG_PATH)) { + WLOGE("draw surface failed"); + return; + } + window_->Show(); + state_ = InnerWindowState::INNER_WINDOW_STATE_CRATED; + WLOGFD("create palce holder Window end"); +} + +void PlaceHolderWindow::RegitsterWindowListener() +{ + if (window_ == nullptr) { + WLOGFE("Window is nullptr, regitster window listener failed."); + return; + } + window_->RegisterTouchOutsideListener(this); + window_->RegisterInputEventListener(this); + window_->RegisterLifeCycleListener(this); +} + +void PlaceHolderWindow::UnRegitsterWindowListener() +{ + if (window_ == nullptr) { + WLOGFE("Window is nullptr, unregitster window listener failed."); + return; + } + window_->UnregisterTouchOutsideListener(this); + window_->UnregisterInputEventListener(this); + window_->UnregisterLifeCycleListener(this); +} + +void PlaceHolderWindow::Destroy() +{ + UnRegitsterWindowListener(); + if (window_ != nullptr) { + window_->Destroy(); + } + window_ = nullptr; + state_ = InnerWindowState::INNER_WINDOW_STATE_DESTROYED; +} + +DividerWindow::~DividerWindow() +{ + Destroy(); +} + +void DividerWindow::Create() +{ + WLOGFI("create inner display id: %{public}" PRIu64"", displayId_); + auto dialogCallback = [this](int32_t id, const std::string& event, const std::string& params) { + if (params == "EVENT_CANCEL_CODE") { + Ace::UIServiceMgrClient::GetInstance()->CancelDialog(id); + } + }; + std::string params; + Ace::UIServiceMgrClient::GetInstance()->ShowDialog(name_, params, WindowType::WINDOW_TYPE_DOCK_SLICE, + rect_.posX_, rect_.posY_, rect_.width_, rect_.height_, dialogCallback, &dialogId_); + state_ = InnerWindowState::INNER_WINDOW_STATE_CRATED; + WLOGFI("create inner window id: %{public}d success", dialogId_); +} + +void DividerWindow::Destroy() +{ + if (dialogId_ == -1) { + state_ = InnerWindowState::INNER_WINDOW_STATE_DESTROYED; + return; + } + WLOGFI("destroy inner window id:: %{public}d.", dialogId_); + Ace::UIServiceMgrClient::GetInstance()->CancelDialog(dialogId_); + dialogId_ = -1; + state_ = InnerWindowState::INNER_WINDOW_STATE_DESTROYED; +} +} // Rosen +} // OHOS \ No newline at end of file diff --git a/wmserver/src/window_inner_manager.cpp b/wmserver/src/window_inner_manager.cpp index 5cddc9f0..597c65c2 100644 --- a/wmserver/src/window_inner_manager.cpp +++ b/wmserver/src/window_inner_manager.cpp @@ -15,9 +15,14 @@ #include "window_inner_manager.h" +#include "surface_draw.h" #include "ui_service_mgr_client.h" #include "window_manager_hilog.h" -#include "window.h" +#include "image/bitmap.h" +#include "image_source.h" +#include "image_type.h" +#include "image_utils.h" +#include "pixel_map.h" namespace OHOS { namespace Rosen { @@ -77,51 +82,19 @@ void WindowInnerManager::Stop() state_ = InnerWMRunningState::STATE_NOT_START; } -void WindowInnerManager::HandleCreateWindow(std::string name, WindowType type, Rect rect) +void WindowInnerManager::CreteInnerWindow(std::string name, DisplayId displyId, Rect rect, + WindowType type, WindowMode mode) { - auto dialogCallback = [this](int32_t id, const std::string& event, const std::string& params) { - if (params == "EVENT_CANCEL_CODE") { - Ace::UIServiceMgrClient::GetInstance()->CancelDialog(id); - } - }; - Ace::UIServiceMgrClient::GetInstance()->ShowDialog(name, dividerParams_, type, - rect.posX_, rect.posY_, rect.width_, rect.height_, dialogCallback, &dialogId_); - WLOGFI("create inner window id: %{public}d success", dialogId_); - return; -} - -void WindowInnerManager::HandleDestroyWindow() -{ - if (dialogId_ == -1) { - return; - } - WLOGFI("destroy inner window id:: %{public}d.", dialogId_); - Ace::UIServiceMgrClient::GetInstance()->CancelDialog(dialogId_); - dialogId_ = -1; - return; -} - -void WindowInnerManager::CreateWindow(std::string name, WindowType type, Rect rect) -{ - if (dialogId_ != -1) { - return; - } - eventHandler_->PostTask([this, name, type, rect]() { - HandleCreateWindow(name, type, rect); + eventHandler_->PostTask([name, displyId, rect, type, mode]() { + InnerWindowFactory::GetInstance().CreateInnerWindow(name, displyId, rect, type, mode); }); - return; } -void WindowInnerManager::DestroyWindow() +void WindowInnerManager::DestroyInnerWindow(DisplayId displyId, WindowType type) { - if (dialogId_ == -1) { - WLOGFI("inner window has destroyed."); - return; - } - eventHandler_->PostTask([this]() { - HandleDestroyWindow(); + eventHandler_->PostTask([displyId, type]() { + InnerWindowFactory::GetInstance().DestroyInnerWindow(displyId, type); }); - return; } } // Rosen } // OHOS \ No newline at end of file diff --git a/wmserver/src/window_pair.cpp b/wmserver/src/window_pair.cpp index 095b4add..87e27926 100644 --- a/wmserver/src/window_pair.cpp +++ b/wmserver/src/window_pair.cpp @@ -209,7 +209,8 @@ void WindowPair::Clear() primary_ = nullptr; secondary_ = nullptr; if (divider_ != nullptr) { - WindowInnerManager::GetInstance().DestroyWindow(); + // WindowInnerManager::GetInstance().DestroyWindow(); + WindowInnerManager::GetInstance().DestroyInnerWindow(displayId_, WindowType::WINDOW_TYPE_DOCK_SLICE); divider_ = nullptr; } status_ = WindowPairStatus::STATUS_EMPTY; @@ -327,15 +328,29 @@ void WindowPair::UpdateIfSplitRelated(sptr& node) WLOGI("Window id: %{public}u is not split related and paired.", node->GetWindowId()); return; } + if ((node->GetWindowType() == WindowType::WINDOW_TYPE_PLACE_HOLDER) && + ((primary_ != nullptr && primary_->GetWindowMode() == node->GetWindowMode()) || + (secondary_ != nullptr && secondary_->GetWindowMode() == node->GetWindowMode()))) { + // WindowInnerManager::GetInstance().DestroyPlaceHolderWindow(); + WindowInnerManager::GetInstance().DestroyInnerWindow(displayId_, WindowType::WINDOW_TYPE_PLACE_HOLDER); + return; + } WLOGI("Current status: %{public}u, window id: %{public}u mode: %{public}u", status_, node->GetWindowId(), node->GetWindowMode()); if (status_ == WindowPairStatus::STATUS_EMPTY) { Insert(node); if (!isAllAppWindowsRestoring_) { // find pairable window from trees or send broadcast - sptr pairableNode = GetPairableWindow(node); - // insert pairable node - Insert(pairableNode); + // sptr pairableNode = GetPairableWindow(node); + // // insert pairable node + // Insert(pairableNode); + WindowMode holderMode = node->GetWindowMode() == WindowMode::WINDOW_MODE_SPLIT_PRIMARY ? + WindowMode::WINDOW_MODE_SPLIT_SECONDARY : WindowMode::WINDOW_MODE_SPLIT_PRIMARY; + WindowInnerManager::GetInstance().CreteInnerWindow("place_holder", displayId_, + {0, 0, 512, 512}, + WindowType::WINDOW_TYPE_PLACE_HOLDER, holderMode); + // WindowInnerManager::GetInstance().CreatePlaceHolderWindow(holderMode, displayId_); + // SendBroadcastMsg(node); } } else { if (Find(node) == nullptr) { @@ -367,8 +382,10 @@ void WindowPair::UpdateWindowPairStatus() prevStatus == WindowPairStatus::STATUS_SINGLE_SECONDARY || prevStatus == WindowPairStatus::STATUS_EMPTY) && status_ == WindowPairStatus::STATUS_PAIRING) { // create divider - WindowInnerManager::GetInstance().CreateWindow("dialog_divider_ui", WindowType::WINDOW_TYPE_DOCK_SLICE, - initalDividerRect_); + // WindowInnerManager::GetInstance().CreateWindow("dialog_divider_ui", WindowType::WINDOW_TYPE_DOCK_SLICE, + // initalDividerRect_); + WindowInnerManager::GetInstance().CreteInnerWindow("divider", displayId_, initalDividerRect_, + WindowType::WINDOW_TYPE_DOCK_SLICE, WindowMode::WINDOW_MODE_FLOATING); } else if ((prevStatus == WindowPairStatus::STATUS_PAIRED_DONE || prevStatus == WindowPairStatus::STATUS_PAIRING) && (status_ != WindowPairStatus::STATUS_PAIRED_DONE && status_ != WindowPairStatus::STATUS_PAIRING)) { // clear pair From 18d25b68a1b65377717aedcf9317ceebea4ef354 Mon Sep 17 00:00:00 2001 From: dubj Date: Wed, 29 Jun 2022 14:40:30 +0800 Subject: [PATCH 47/81] =?UTF-8?q?touchOutside=E6=8E=A5=E5=8F=A3=E5=8A=A0co?= =?UTF-8?q?nst?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: dubj Change-Id: If2005b0e9453be985b3931f4d13981c749480b30 --- interfaces/innerkits/wm/window.h | 2 +- .../window_napi/js_window_listener.cpp | 15 ++++++++------- .../window_napi/js_window_listener.h | 5 +++-- wm/test/systemtest/window_touch_outside_test.cpp | 8 ++++---- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/interfaces/innerkits/wm/window.h b/interfaces/innerkits/wm/window.h index b850114b..58205233 100644 --- a/interfaces/innerkits/wm/window.h +++ b/interfaces/innerkits/wm/window.h @@ -122,7 +122,7 @@ public: class ITouchOutsideListener : virtual public RefBase { public: - virtual void OnTouchOutside() = 0; + virtual void OnTouchOutside() const = 0; }; class Window : public RefBase { diff --git a/interfaces/kits/napi/window_runtime/window_napi/js_window_listener.cpp b/interfaces/kits/napi/window_runtime/window_napi/js_window_listener.cpp index cdbc05b4..e9e9954a 100644 --- a/interfaces/kits/napi/window_runtime/window_napi/js_window_listener.cpp +++ b/interfaces/kits/napi/window_runtime/window_napi/js_window_listener.cpp @@ -15,6 +15,7 @@ #include "js_window_listener.h" #include "js_runtime_utils.h" #include "window_manager_hilog.h" + namespace OHOS { namespace Rosen { using namespace AbilityRuntime; @@ -47,7 +48,7 @@ void JsWindowListener::OnSizeChange(Rect rect, WindowSizeChangeReason reason) WLOGFI("[NAPI]OnSizeChange, wh[%{public}u, %{public}u], reason = %{public}u", rect.width_, rect.height_, reason); // js callback should run in js thread std::unique_ptr complete = std::make_unique ( - [self = wptr(this), rect, eng = engine_] (NativeEngine &engine, + [self = weakRef_, rect, eng = engine_] (NativeEngine &engine, AsyncTask &task, int32_t status) { auto thisListener = self.promote(); if (thisListener == nullptr || eng == nullptr) { @@ -83,7 +84,7 @@ void JsWindowListener::OnSystemBarPropertyChange(DisplayId displayId, const Syst WLOGFI("[NAPI]OnSystemBarPropertyChange"); // js callback should run in js thread std::unique_ptr complete = std::make_unique ( - [self = wptr(this), displayId, tints, eng = engine_] (NativeEngine &engine, + [self = weakRef_, displayId, tints, eng = engine_] (NativeEngine &engine, AsyncTask &task, int32_t status) { auto thisListener = self.promote(); if (thisListener == nullptr || eng == nullptr) { @@ -114,7 +115,7 @@ void JsWindowListener::OnAvoidAreaChanged(const AvoidArea avoidArea, AvoidAreaTy WLOGFI("[NAPI]OnAvoidAreaChanged"); // js callback should run in js thread std::unique_ptr complete = std::make_unique ( - [self = wptr(this), avoidArea, type, eng = engine_] (NativeEngine &engine, + [self = weakRef_, avoidArea, type, eng = engine_] (NativeEngine &engine, AsyncTask &task, int32_t status) { auto thisListener = self.promote(); if (thisListener == nullptr || eng == nullptr) { @@ -145,7 +146,7 @@ void JsWindowListener::LifeCycleCallBack(LifeCycleEventType eventType) { WLOGFI("[NAPI]LifeCycleCallBack, envent type: %{public}u", eventType); std::unique_ptr complete = std::make_unique( - [self = wptr(this), eventType, eng = engine_] (NativeEngine &engine, + [self = weakRef_, eventType, eng = engine_] (NativeEngine &engine, AsyncTask &task, int32_t status) { auto thisListener = self.promote(); if (thisListener == nullptr || eng == nullptr) { @@ -189,7 +190,7 @@ void JsWindowListener::OnSizeChange(const sptr& info) info->rect_.posX_, info->rect_.posY_, info->rect_.width_, info->rect_.height_); // js callback should run in js thread std::unique_ptr complete = std::make_unique ( - [self = wptr(this), info, eng = engine_] (NativeEngine &engine, + [self = weakRef_, info, eng = engine_] (NativeEngine &engine, AsyncTask &task, int32_t status) { auto thisListener = self.promote(); if (thisListener == nullptr || eng == nullptr) { @@ -207,10 +208,10 @@ void JsWindowListener::OnSizeChange(const sptr& info) *engine_, std::make_unique(callback, std::move(execute), std::move(complete))); } -void JsWindowListener::OnTouchOutside() +void JsWindowListener::OnTouchOutside() const { std::unique_ptr complete = std::make_unique ( - [self = wptr(this)] (NativeEngine &engine, AsyncTask &task, int32_t status) { + [self = weakRef_] (NativeEngine &engine, AsyncTask &task, int32_t status) { auto thisListener = self.promote(); if (thisListener == nullptr) { WLOGFE("[NAPI]this listener is nullptr"); diff --git a/interfaces/kits/napi/window_runtime/window_napi/js_window_listener.h b/interfaces/kits/napi/window_runtime/window_napi/js_window_listener.h index 8a39f121..617a1be2 100644 --- a/interfaces/kits/napi/window_runtime/window_napi/js_window_listener.h +++ b/interfaces/kits/napi/window_runtime/window_napi/js_window_listener.h @@ -47,7 +47,7 @@ class JsWindowListener : public IWindowChangeListener, public ITouchOutsideListener { public: JsWindowListener(NativeEngine* engine, std::shared_ptr callback) - : engine_(engine), jsCallBack_(callback) {} + : engine_(engine), jsCallBack_(callback), weakRef_(wptr (this)) {} ~JsWindowListener(); void OnSystemBarPropertyChange(DisplayId displayId, const SystemBarRegionTints& tints) override; void OnSizeChange(Rect rect, WindowSizeChangeReason reason) override; @@ -58,12 +58,13 @@ public: void AfterFocused() override; void AfterUnfocused() override; void OnSizeChange(const sptr& info) override; - void OnTouchOutside() override; + void OnTouchOutside() const override; void CallJsMethod(const char* methodName, NativeValue* const* argv = nullptr, size_t argc = 0); private: void LifeCycleCallBack(LifeCycleEventType eventType); NativeEngine* engine_ = nullptr; std::shared_ptr jsCallBack_ = nullptr; + wptr weakRef_ = nullptr; DEFINE_VAR_DEFAULT_FUNC_SET(bool, IsDeprecatedInterface, isDeprecatedInterface, false) }; } // namespace Rosen diff --git a/wm/test/systemtest/window_touch_outside_test.cpp b/wm/test/systemtest/window_touch_outside_test.cpp index 39b076e2..89727851 100644 --- a/wm/test/systemtest/window_touch_outside_test.cpp +++ b/wm/test/systemtest/window_touch_outside_test.cpp @@ -31,11 +31,11 @@ const int WAIT_CALLBACK_US = 10000; // 10000 us class WindowTouchOutsideTestListener : public ITouchOutsideListener { public: - void OnTouchOutside() override + void OnTouchOutside() const override { isTouchOutside_ = true; } - bool isTouchOutside_ { false }; + mutable bool isTouchOutside_ { false }; }; class WindowTouchOutsideTest : public testing::Test { @@ -106,11 +106,11 @@ void WindowTouchOutsideTest::TearDownTestCase() namespace { /** - * @tc.name: onTouchIutside + * @tc.name: onTouchInside * @tc.desc: can't not receive a inside touch event * @tc.type: FUNC */ -HWTEST_F(WindowTouchOutsideTest, onTouchIutside, Function | MediumTest | Level3) +HWTEST_F(WindowTouchOutsideTest, onTouchInside, Function | MediumTest | Level3) { const sptr &firstWindow = Utils::CreateTestWindow(firstWindowInfo_); firstWindow->RegisterTouchOutsideListener(windowlistener1_); From 94b8845abac19ec225dff68d59ecafcf2ccf595f Mon Sep 17 00:00:00 2001 From: xiaojianfeng Date: Wed, 29 Jun 2022 20:05:18 +0800 Subject: [PATCH 48/81] fix avoid_area_controller_test bug Signed-off-by: xiaojianfeng Change-Id: I85e37864aeb8a2d5402fd3704d05b03317165928 --- utils/include/window_helper.h | 16 +- wm/test/unittest/BUILD.gn | 1 + .../unittest/avoid_area_controller_test.cpp | 608 ++++++++++-------- wm/test/unittest/avoid_area_controller_test.h | 12 +- wmserver/src/avoid_area_controller.cpp | 15 +- 5 files changed, 378 insertions(+), 274 deletions(-) diff --git a/utils/include/window_helper.h b/utils/include/window_helper.h index c879ce70..e3e552c0 100644 --- a/utils/include/window_helper.h +++ b/utils/include/window_helper.h @@ -127,17 +127,19 @@ public: return !(r1XEnd < r2.posX_ || r1.posX_ > r2XEnd || r1YEnd < r2.posY_ || r1.posY_ > r2YEnd); } - static inline Rect GetOverlap(const Rect& rect1, const Rect& rect2, const int offsetX, const int offsetY) + static Rect GetOverlap(const Rect& rect1, const Rect& rect2, const int offsetX, const int offsetY) { - const static Rect noOverlapRect = { 0, 0, 0, 0 }; int32_t x_begin = std::max(rect1.posX_, rect2.posX_); - int32_t x_end = std::min(rect1.posX_ + rect1.width_ - 1, rect2.posX_ + rect2.width_ - 1); + int32_t x_end = std::min(rect1.posX_ + static_cast(rect1.width_), + rect2.posX_ + static_cast(rect2.width_)); int32_t y_begin = std::max(rect1.posY_, rect2.posY_); - int32_t y_end = std::min(rect1.posY_ + rect1.height_ - 1, rect2.posY_ + rect2.height_ - 1); - if (y_begin > y_end || x_begin > x_end) { - return noOverlapRect; + int32_t y_end = std::min(rect1.posY_ + static_cast(rect1.height_), + rect2.posY_ + static_cast(rect2.height_)); + if (y_begin >= y_end || x_begin >= x_end) { + return { 0, 0, 0, 0 }; } - return { x_begin - offsetX, y_begin - offsetY, x_end - x_begin + 1, y_end - y_begin + 1 }; + return { x_begin - offsetX, y_begin - offsetY, + static_cast(x_end - x_begin), static_cast(y_end - y_begin) }; } static bool IsWindowModeSupported(uint32_t modeSupportInfo, WindowMode mode) diff --git a/wm/test/unittest/BUILD.gn b/wm/test/unittest/BUILD.gn index 48d9f1fc..a0b90166 100644 --- a/wm/test/unittest/BUILD.gn +++ b/wm/test/unittest/BUILD.gn @@ -19,6 +19,7 @@ group("unittest") { testonly = true deps = [ + ":avoid_area_controller_test", ":wm_input_transfer_station_test", ":wm_window_effect_test", ":wm_window_impl_test", diff --git a/wm/test/unittest/avoid_area_controller_test.cpp b/wm/test/unittest/avoid_area_controller_test.cpp index d213b5f9..96700164 100644 --- a/wm/test/unittest/avoid_area_controller_test.cpp +++ b/wm/test/unittest/avoid_area_controller_test.cpp @@ -16,7 +16,8 @@ #include "avoid_area_controller_test.h" #include "avoid_area_controller.h" #include "display_manager.h" -#include "mock_window_adapter.h" +#include "display_manager_config.h" +#include "future.h" #include "singleton_mocker.h" #include "window_node.h" @@ -29,45 +30,101 @@ namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "AvoidAreaControllerTest"}; const Rect EMPTY_RECT = {0, 0, 0, 0}; - const uint32_t LEFT = 0; - const uint32_t TOP = 1; - const uint32_t RIGHT = 2; - const uint32_t BOTTOM = 3; const float BARRATIO = 0.3; + const long TIME_OUT = 1000; + const AvoidArea EMPTY_AVOID_AREA = {}; } -Rect AvoidAreaControllerTest::topAvoidRect_ = EMPTY_RECT; -Rect AvoidAreaControllerTest::leftAvoidRect_ = EMPTY_RECT; +sptr AvoidAreaControllerTest::statusbarWindowNode = nullptr; +sptr AvoidAreaControllerTest::navigationBarWindowNode = nullptr; +sptr AvoidAreaControllerTest::keyboardWindowNode = nullptr; +Rect AvoidAreaControllerTest::screenRect; +Rect AvoidAreaControllerTest::cut_out_rect = { 10, 10, 100, 20 }; -static bool RectEqualToRect(const Rect& l, const Rect& r) -{ - bool res = ((l.posX_ == r.posX_) && (l.posY_ == r.posY_) && (l.width_ == r.width_) && (l.height_ == r.height_)); - if (!res) { - WLOGFE(" [ x y w h]"); - WLOGFE("Expect:%{public}4d %{public}4d %{public}4u %{public}4u ", l.posX_, l.posY_, l.width_, l.height_); - WLOGFE("Get: %{public}4d %{public}4d %{public}4u %{public}4u ", r.posX_, r.posY_, r.width_, r.height_); +class WindowListener : public IWindow { +public: + void UpdateWindowRect(const struct Rect& rect, bool decoStatus, WindowSizeChangeReason reason) override {} + void UpdateWindowMode(WindowMode mode) override {} + void UpdateFocusStatus(bool focused) override {} + void UpdateAvoidArea(const sptr& avoidArea, AvoidAreaType type) override + { + if (type == AvoidAreaType::TYPE_SYSTEM) { + statusBarAvoidAreaFuture_.SetValue(*avoidArea); + } + if (type == AvoidAreaType::TYPE_CUTOUT) { + cutoutAvoidAreaFuture_.SetValue(*avoidArea); + } + if (type == AvoidAreaType::TYPE_KEYBOARD) { + keyboardAvoidAreaFuture_.SetValue(*avoidArea); + } } - return res; -} + void UpdateWindowModeSupportInfo(uint32_t modeSupportInfo) override {} + void UpdateWindowState(WindowState state) override {} + void UpdateWindowDragInfo(const PointInfo& point, DragEvent event) override {} + void UpdateDisplayId(DisplayId from, DisplayId to) override {} + void UpdateOccupiedAreaChangeInfo(const sptr& info) override {} + void UpdateActiveStatus(bool isActive) override {} + sptr GetWindowProperty() override + { + return nullptr; + } + void NotifyTouchOutside() override {} + void DumpInfo(const std::vector& params, std::vector& info) override {} + RunnableFuture statusBarAvoidAreaFuture_; + RunnableFuture keyboardAvoidAreaFuture_; + RunnableFuture cutoutAvoidAreaFuture_; -void AvoidAreaControllerTest::InitByScreenRect(const Rect& screenRect) -{ - topAvoidRect_ = {0, 0, screenRect.width_, - std::min(static_cast(screenRect.height_), static_cast(screenRect.width_ * BARRATIO))}; - // make sure leftAvoidRect h > w and w < screen.width. And use a bigger ratio to cover origin topAvoid - leftAvoidRect_ = {0, 0, - std::min(static_cast(screenRect.width_), static_cast(screenRect.height_ * BARRATIO)), - screenRect.height_}; -} + sptr AsObject() override + { + return nullptr; + } +}; void AvoidAreaControllerTest::SetUpTestCase() { - auto display = DisplayManager::GetInstance().GetDisplayById(0); + DisplayManagerConfig::LoadConfigXml(); + auto numbersConfig = DisplayManagerConfig::GetIntNumbersConfig(); + if (numbersConfig.count("cutoutArea") > 0) { + std::vector cutoutArea = numbersConfig["cutoutArea"]; + // 0, 1, 2, 3 means the index in the vector. + cut_out_rect = { cutoutArea[0], cutoutArea[1], (uint32_t)cutoutArea[2], (uint32_t)cutoutArea[3] }; + } + auto display = DisplayManager::GetInstance().GetDefaultDisplay(); ASSERT_TRUE((display != nullptr)); WLOGFI("GetDefaultDisplay: id %{public}" PRIu64", w %{public}d, h %{public}d, fps %{public}u", display->GetId(), display->GetWidth(), display->GetHeight(), display->GetRefreshRate()); - Rect screenRect = {0, 0, display->GetWidth(), display->GetHeight()}; - AvoidAreaControllerTest::InitByScreenRect(screenRect); + screenRect = { 0, 0, static_cast(display->GetWidth()), static_cast(display->GetHeight()) }; + auto barHeight = static_cast(screenRect.height_ * BARRATIO); + Rect statusBarRect = { 0, 0, screenRect.width_, barHeight }; + Rect navigationRect = { 0, static_cast(screenRect.height_ - barHeight), screenRect.width_, barHeight }; + + sptr statusbarProperty = new WindowProperty(); + statusbarProperty->SetWindowId(100u); + statusbarProperty->SetWindowName("status bar"); + statusbarProperty->SetWindowType(WindowType::WINDOW_TYPE_STATUS_BAR); + statusbarProperty->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING); + statusbarProperty->SetWindowRect(statusBarRect); + sptr windowListener = new WindowListener(); + statusbarWindowNode = new WindowNode(statusbarProperty, windowListener, nullptr); + + sptr navigationBarProperty = new WindowProperty(); + navigationBarProperty->SetWindowId(101u); + navigationBarProperty->SetWindowName("navigation bar"); + navigationBarProperty->SetWindowType(WindowType::WINDOW_TYPE_NAVIGATION_BAR); + navigationBarProperty->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING); + navigationBarProperty->SetWindowRect(navigationRect); + windowListener = new WindowListener(); + navigationBarWindowNode = new WindowNode(navigationBarProperty, windowListener, nullptr); + + sptr keyboardProperty = new WindowProperty(); + keyboardProperty->SetWindowId(101u); + keyboardProperty->SetWindowName("navigation bar"); + keyboardProperty->SetWindowType(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT); + keyboardProperty->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING); + Rect keyboardRect = { 0, static_cast(screenRect.height_ / 2), screenRect.width_, screenRect.height_ / 2 }; + keyboardProperty->SetWindowRect(keyboardRect); + windowListener = new WindowListener(); + keyboardWindowNode = new WindowNode(keyboardProperty, windowListener, nullptr); } void AvoidAreaControllerTest::TearDownTestCase() @@ -82,275 +139,324 @@ void AvoidAreaControllerTest::TearDown() { } +#define CHECK_AVOID_AREA(avoidArea, topRect, leftRect, rightRect, bottomRect) \ + do { \ + ASSERT_EQ(avoidArea.topRect_, topRect); \ + ASSERT_EQ(avoidArea.bottomRect_, bottomRect); \ + ASSERT_EQ(avoidArea.leftRect_, leftRect); \ + ASSERT_EQ(avoidArea.rightRect_, rightRect); \ + } while (false) + + namespace { /** - * @tc.name: IsAvoidAreaNode01 - * @tc.desc: Create a APP Window. Test IsAvoidAreaNode + * @tc.name: SystemBarAndCutOutAvoidArea01 + * @tc.desc: Get avoid areas with TYPE_SYSTEM and TYPE_CUTOUT * @tc.type: FUNC */ -HWTEST_F(AvoidAreaControllerTest, IsAvoidAreaNode01, Function | SmallTest | Level2) +HWTEST_F(AvoidAreaControllerTest, SystemBarAndCutOutAvoidArea01, Function | SmallTest | Level2) { - auto avoidAreaController = new AvoidAreaController(0, nullptr); - - sptr node = new WindowNode(); sptr property = new WindowProperty(); - property->SetWindowId(100u); + property->SetWindowId(110u); + property->SetWindowName("test"); property->SetWindowType(WindowType::APP_WINDOW_BASE); - node->SetWindowProperty(property); + property->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN); + property->SetWindowRect(screenRect); + sptr listener = new WindowListener(); + sptr appWindow = new WindowNode(property, listener, nullptr); + uint32_t focusedWindow = appWindow->GetWindowId(); + sptr avoidAreaController = new AvoidAreaController(focusedWindow); + avoidAreaController->ProcessWindowChange(statusbarWindowNode, AvoidControlType::AVOID_NODE_ADD, nullptr); + avoidAreaController->ProcessWindowChange(navigationBarWindowNode, AvoidControlType::AVOID_NODE_ADD, nullptr); + avoidAreaController->ProcessWindowChange(appWindow, AvoidControlType::AVOID_NODE_ADD, nullptr); + auto avoidArea = avoidAreaController->GetAvoidAreaByType(appWindow, AvoidAreaType::TYPE_SYSTEM); + CHECK_AVOID_AREA(avoidArea, statusbarWindowNode->GetWindowRect(), + EMPTY_RECT, EMPTY_RECT, navigationBarWindowNode->GetWindowRect()); + avoidArea = avoidAreaController->GetAvoidAreaByType(appWindow, AvoidAreaType::TYPE_CUTOUT); + CHECK_AVOID_AREA(avoidArea, cut_out_rect, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT); - ASSERT_EQ(false, avoidAreaController->IsAvoidAreaNode(node)); + // set rect + Rect statusBarRect = statusbarWindowNode->GetWindowRect(); + Rect navigationBarRect = navigationBarWindowNode->GetWindowRect(); + Rect windowRect = { 0, static_cast(statusBarRect.height_), statusBarRect.width_, + static_cast(navigationBarRect.posY_ - statusBarRect.height_) }; + property->SetWindowRect(windowRect); + avoidArea = avoidAreaController->GetAvoidAreaByType(appWindow, AvoidAreaType::TYPE_SYSTEM); + CHECK_AVOID_AREA(avoidArea, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT); + avoidArea = avoidAreaController->GetAvoidAreaByType(appWindow, AvoidAreaType::TYPE_CUTOUT); + CHECK_AVOID_AREA(avoidArea, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT); + + // restore rect + property->SetWindowRect(screenRect); + avoidArea = avoidAreaController->GetAvoidAreaByType(appWindow, AvoidAreaType::TYPE_SYSTEM); + CHECK_AVOID_AREA(avoidArea, statusbarWindowNode->GetWindowRect(), + EMPTY_RECT, EMPTY_RECT, navigationBarWindowNode->GetWindowRect()); + avoidArea = avoidAreaController->GetAvoidAreaByType(appWindow, AvoidAreaType::TYPE_CUTOUT); + CHECK_AVOID_AREA(avoidArea, cut_out_rect, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT); + + avoidAreaController->ProcessWindowChange(statusbarWindowNode, AvoidControlType::AVOID_NODE_REMOVE, nullptr); + avoidAreaController->ProcessWindowChange(navigationBarWindowNode, AvoidControlType::AVOID_NODE_REMOVE, nullptr); + avoidAreaController->ProcessWindowChange(appWindow, AvoidControlType::AVOID_NODE_REMOVE, nullptr); + avoidArea = avoidAreaController->GetAvoidAreaByType(appWindow, AvoidAreaType::TYPE_SYSTEM); + CHECK_AVOID_AREA(avoidArea, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT); } /** - * @tc.name: IsAvoidAreaNode02 - * @tc.desc: Create a Status Bar Window. Test IsAvoidAreaNode + * @tc.name: SystemBarAndCutOutAvoidArea02 + * @tc.desc: Get avoid areas with listener, TYPE_SYSTEM and TYPE_CUTOUT. * @tc.type: FUNC */ -HWTEST_F(AvoidAreaControllerTest, IsAvoidAreaNode02, Function | SmallTest | Level2) +HWTEST_F(AvoidAreaControllerTest, SystemBarAndCutOutAvoidArea02, Function | SmallTest | Level2) { - auto avoidAreaController = new AvoidAreaController(0, nullptr); - - sptr node = new WindowNode(); sptr property = new WindowProperty(); - property->SetWindowType(WindowType::WINDOW_TYPE_STATUS_BAR); - node->SetWindowProperty(property); + property->SetWindowId(110u); + property->SetWindowName("test"); + property->SetWindowType(WindowType::APP_WINDOW_BASE); + property->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN); + property->SetWindowRect(screenRect); + sptr windowListener = new WindowListener(); + sptr appWindow = new WindowNode(property, windowListener, nullptr); + uint32_t focusedWindow = appWindow->GetWindowId(); + sptr avoidAreaController = new AvoidAreaController(focusedWindow); + avoidAreaController->ProcessWindowChange(appWindow, AvoidControlType::AVOID_NODE_ADD, nullptr); + avoidAreaController->UpdateAvoidAreaListener(appWindow, true); - ASSERT_TRUE(avoidAreaController->IsAvoidAreaNode(node)); + // add status bar + avoidAreaController->ProcessWindowChange(statusbarWindowNode, AvoidControlType::AVOID_NODE_ADD, nullptr); + auto avoidArea = windowListener->statusBarAvoidAreaFuture_.GetResult(TIME_OUT); + windowListener->statusBarAvoidAreaFuture_.Reset(EMPTY_AVOID_AREA); + CHECK_AVOID_AREA(avoidArea, statusbarWindowNode->GetWindowRect(), EMPTY_RECT, EMPTY_RECT, EMPTY_RECT); + + // add navigation bar + avoidAreaController->ProcessWindowChange(navigationBarWindowNode, AvoidControlType::AVOID_NODE_ADD, nullptr); + avoidArea = windowListener->statusBarAvoidAreaFuture_.GetResult(TIME_OUT); + windowListener->statusBarAvoidAreaFuture_.Reset(EMPTY_AVOID_AREA); + CHECK_AVOID_AREA(avoidArea, statusbarWindowNode->GetWindowRect(), EMPTY_RECT, + EMPTY_RECT, navigationBarWindowNode->GetWindowRect()); + + // update appWindow rect + Rect statusBarRect = statusbarWindowNode->GetWindowRect(); + Rect navigationBarRect = navigationBarWindowNode->GetWindowRect(); + Rect windowRect = { 0, static_cast(statusBarRect.height_), statusBarRect.width_, + static_cast(navigationBarRect.posY_ - statusBarRect.height_) }; + property->SetWindowRect(windowRect); + avoidAreaController->ProcessWindowChange(appWindow, AvoidControlType::AVOID_NODE_UPDATE, nullptr); + avoidArea = windowListener->statusBarAvoidAreaFuture_.GetResult(TIME_OUT); + windowListener->statusBarAvoidAreaFuture_.Reset(EMPTY_AVOID_AREA); + CHECK_AVOID_AREA(avoidArea, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT); + avoidArea = windowListener->cutoutAvoidAreaFuture_.GetResult(TIME_OUT); + windowListener->cutoutAvoidAreaFuture_.Reset(EMPTY_AVOID_AREA); + CHECK_AVOID_AREA(avoidArea, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT); + + // restore appWindow rect + property->SetWindowRect(screenRect); + avoidAreaController->ProcessWindowChange(appWindow, AvoidControlType::AVOID_NODE_UPDATE, nullptr); + avoidArea = windowListener->statusBarAvoidAreaFuture_.GetResult(TIME_OUT); + windowListener->statusBarAvoidAreaFuture_.Reset(EMPTY_AVOID_AREA); + CHECK_AVOID_AREA(avoidArea, statusbarWindowNode->GetWindowRect(), + EMPTY_RECT, EMPTY_RECT, navigationBarWindowNode->GetWindowRect()); + avoidArea = windowListener->cutoutAvoidAreaFuture_.GetResult(TIME_OUT); + windowListener->cutoutAvoidAreaFuture_.Reset(EMPTY_AVOID_AREA); + CHECK_AVOID_AREA(avoidArea, cut_out_rect, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT); + + avoidAreaController->ProcessWindowChange(statusbarWindowNode, AvoidControlType::AVOID_NODE_REMOVE, nullptr); + avoidAreaController->ProcessWindowChange(navigationBarWindowNode, AvoidControlType::AVOID_NODE_REMOVE, nullptr); + avoidAreaController->ProcessWindowChange(appWindow, AvoidControlType::AVOID_NODE_REMOVE, nullptr); } /** - * @tc.name: IsAvoidAreaNode03 - * @tc.desc: Create a Dock_Slice Window. Test IsAvoidAreaNode + * @tc.name: SystemBarAndCutOutAvoidArea03 + * @tc.desc: Get avoid areas with listener, TYPE_SYSTEM and TYPE_CUTOUT. * @tc.type: FUNC */ -HWTEST_F(AvoidAreaControllerTest, IsAvoidAreaNode03, Function | SmallTest | Level2) +HWTEST_F(AvoidAreaControllerTest, SystemBarAndCutOutAvoidArea03, Function | SmallTest | Level2) { - auto avoidAreaController = new AvoidAreaController(0, nullptr); - - sptr node = new WindowNode(); sptr property = new WindowProperty(); - property->SetWindowType(WindowType::WINDOW_TYPE_DOCK_SLICE); - node->SetWindowProperty(property); + property->SetWindowId(110u); + property->SetWindowName("test"); + property->SetWindowType(WindowType::APP_WINDOW_BASE); + property->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN); + property->SetWindowRect(screenRect); + sptr windowListener = new WindowListener(); + sptr appWindow = new WindowNode(property, windowListener, nullptr); + uint32_t focusedWindow = appWindow->GetWindowId(); + sptr avoidAreaController = new AvoidAreaController(focusedWindow); + avoidAreaController->ProcessWindowChange(appWindow, AvoidControlType::AVOID_NODE_ADD, nullptr); + avoidAreaController->UpdateAvoidAreaListener(appWindow, true); - ASSERT_EQ(false, avoidAreaController->IsAvoidAreaNode(node)); + // add status bar + avoidAreaController->ProcessWindowChange(statusbarWindowNode, AvoidControlType::AVOID_NODE_ADD, nullptr); + auto avoidArea = windowListener->statusBarAvoidAreaFuture_.GetResult(TIME_OUT); + windowListener->statusBarAvoidAreaFuture_.Reset(EMPTY_AVOID_AREA); + CHECK_AVOID_AREA(avoidArea, statusbarWindowNode->GetWindowRect(), EMPTY_RECT, EMPTY_RECT, EMPTY_RECT); + + // add navigation bar + avoidAreaController->ProcessWindowChange(navigationBarWindowNode, AvoidControlType::AVOID_NODE_ADD, nullptr); + avoidArea = windowListener->statusBarAvoidAreaFuture_.GetResult(TIME_OUT); + windowListener->statusBarAvoidAreaFuture_.Reset(EMPTY_AVOID_AREA); + CHECK_AVOID_AREA(avoidArea, statusbarWindowNode->GetWindowRect(), EMPTY_RECT, + EMPTY_RECT, navigationBarWindowNode->GetWindowRect()); + + // remove status bar + avoidAreaController->ProcessWindowChange(statusbarWindowNode, AvoidControlType::AVOID_NODE_REMOVE, nullptr); + avoidArea = windowListener->statusBarAvoidAreaFuture_.GetResult(TIME_OUT); + windowListener->statusBarAvoidAreaFuture_.Reset(EMPTY_AVOID_AREA); + CHECK_AVOID_AREA(avoidArea, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT, navigationBarWindowNode->GetWindowRect()); + avoidArea = windowListener->cutoutAvoidAreaFuture_.GetResult(TIME_OUT); + windowListener->cutoutAvoidAreaFuture_.Reset(EMPTY_AVOID_AREA); + CHECK_AVOID_AREA(avoidArea, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT); + + // remove navigation bar + avoidAreaController->ProcessWindowChange(navigationBarWindowNode, AvoidControlType::AVOID_NODE_REMOVE, nullptr); + avoidArea = windowListener->statusBarAvoidAreaFuture_.GetResult(TIME_OUT); + windowListener->statusBarAvoidAreaFuture_.Reset(EMPTY_AVOID_AREA); + CHECK_AVOID_AREA(avoidArea, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT); + avoidAreaController->ProcessWindowChange(appWindow, AvoidControlType::AVOID_NODE_REMOVE, nullptr); } /** - * @tc.name: IsAvoidAreaNode04 - * @tc.desc: Create a Dock_Slice Window. Test IsAvoidAreaNode + * @tc.name: SystemBarAvoidArea01 + * @tc.desc: Get avoid areas with listener, TYPE_SYSTEM. * @tc.type: FUNC */ -HWTEST_F(AvoidAreaControllerTest, IsAvoidAreaNode04, Function | SmallTest | Level2) +HWTEST_F(AvoidAreaControllerTest, SystemBarAvoidArea01, Function | SmallTest | Level2) { - auto avoidAreaController = new AvoidAreaController(0, nullptr); - - ASSERT_EQ(false, avoidAreaController->IsAvoidAreaNode(nullptr)); -} - -/** - * @tc.name: AddAvoidAreaNode01 - * @tc.desc: Add a new avoid area Node - * @tc.type: FUNC - */ -HWTEST_F(AvoidAreaControllerTest, AddAvoidAreaNode01, Function | SmallTest | Level2) -{ - sptr node = new WindowNode(); - sptr property = new WindowProperty(); - property->SetWindowId(100u); - property->SetWindowType(WindowType::WINDOW_TYPE_STATUS_BAR); - node->SetWindowProperty(property); - node->SetWindowRect(topAvoidRect_); + property->SetWindowId(110u); + property->SetWindowName("test"); + property->SetWindowType(WindowType::APP_WINDOW_BASE); + property->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN); + property->SetWindowRect(screenRect); + sptr windowListener = new WindowListener(); + sptr appWindow = new WindowNode(property, windowListener, nullptr); + uint32_t focusedWindow = appWindow->GetWindowId(); + sptr avoidAreaController = new AvoidAreaController(focusedWindow); + avoidAreaController->ProcessWindowChange(statusbarWindowNode, AvoidControlType::AVOID_NODE_ADD, nullptr); + avoidAreaController->ProcessWindowChange(navigationBarWindowNode, AvoidControlType::AVOID_NODE_ADD, nullptr); + avoidAreaController->ProcessWindowChange(appWindow, AvoidControlType::AVOID_NODE_ADD, nullptr); + avoidAreaController->UpdateAvoidAreaListener(appWindow, true); - sptr avoidAreaController = new AvoidAreaController(0, nullptr); - ASSERT_EQ(WMError::WM_OK, avoidAreaController->AvoidControl(node, AvoidControlType::AVOID_NODE_ADD)); + // update status bar window Rect + Rect statusbarWindowNodeRect = statusbarWindowNode->GetWindowRect(); + statusbarWindowNode->SetWindowRect(EMPTY_RECT); + avoidAreaController->ProcessWindowChange(statusbarWindowNode, AvoidControlType::AVOID_NODE_UPDATE, + [](sptr windowNode) { return true; }); + auto avoidArea = windowListener->statusBarAvoidAreaFuture_.GetResult(TIME_OUT); + windowListener->statusBarAvoidAreaFuture_.Reset(EMPTY_AVOID_AREA); + CHECK_AVOID_AREA(avoidArea, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT, navigationBarWindowNode->GetWindowRect()); + + // update navigation bar window Rect + Rect navigationBarWindowNodeRect = navigationBarWindowNode->GetWindowRect(); + navigationBarWindowNode->SetWindowRect(EMPTY_RECT); + avoidAreaController->ProcessWindowChange(navigationBarWindowNode, AvoidControlType::AVOID_NODE_UPDATE, + [](sptr windowNode) { return true; }); + avoidArea = windowListener->statusBarAvoidAreaFuture_.GetResult(TIME_OUT); + windowListener->statusBarAvoidAreaFuture_.Reset(EMPTY_AVOID_AREA); + CHECK_AVOID_AREA(avoidArea, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT); + + // restore status bar window Rect + statusbarWindowNode->SetWindowRect(statusbarWindowNodeRect); + avoidAreaController->ProcessWindowChange(appWindow, AvoidControlType::AVOID_NODE_UPDATE, nullptr); + avoidArea = windowListener->statusBarAvoidAreaFuture_.GetResult(TIME_OUT); + windowListener->statusBarAvoidAreaFuture_.Reset(EMPTY_AVOID_AREA); + CHECK_AVOID_AREA(avoidArea, statusbarWindowNode->GetWindowRect(), EMPTY_RECT, EMPTY_RECT, EMPTY_RECT); + + // restore navigation bar window Rect + navigationBarWindowNode->SetWindowRect(navigationBarWindowNodeRect); + avoidAreaController->ProcessWindowChange(appWindow, AvoidControlType::AVOID_NODE_UPDATE, nullptr); + avoidArea = windowListener->statusBarAvoidAreaFuture_.GetResult(TIME_OUT); + windowListener->statusBarAvoidAreaFuture_.Reset(EMPTY_AVOID_AREA); + CHECK_AVOID_AREA(avoidArea, statusbarWindowNode->GetWindowRect(), EMPTY_RECT, + EMPTY_RECT, navigationBarWindowNode->GetWindowRect()); + + // remove status bar + avoidAreaController->ProcessWindowChange(statusbarWindowNode, AvoidControlType::AVOID_NODE_REMOVE, nullptr); + avoidArea = windowListener->statusBarAvoidAreaFuture_.GetResult(TIME_OUT); + windowListener->statusBarAvoidAreaFuture_.Reset(EMPTY_AVOID_AREA); + CHECK_AVOID_AREA(avoidArea, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT, navigationBarWindowNode->GetWindowRect()); + + // remove navigation bar + avoidAreaController->ProcessWindowChange(navigationBarWindowNode, AvoidControlType::AVOID_NODE_REMOVE, nullptr); + avoidArea = windowListener->statusBarAvoidAreaFuture_.GetResult(TIME_OUT); + windowListener->statusBarAvoidAreaFuture_.Reset(EMPTY_AVOID_AREA); + CHECK_AVOID_AREA(avoidArea, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT); } /** - * @tc.name: AddAvoidAreaNode02 - * @tc.desc: Add a exist avoid area Node + * @tc.name: KeyboardAvoidArea01 + * @tc.desc: Get avoid areas with TYPE_KEYBOARD. * @tc.type: FUNC */ -HWTEST_F(AvoidAreaControllerTest, AddAvoidAreaNode02, Function | SmallTest | Level2) +HWTEST_F(AvoidAreaControllerTest, KeyboardAvoidArea01, Function | SmallTest | Level2) { - sptr avoidAreaController = new AvoidAreaController(0, nullptr); - - sptr node1 = new WindowNode(); - sptr property1 = new WindowProperty(); - property1->SetWindowId(100u); - property1->SetWindowType(WindowType::WINDOW_TYPE_STATUS_BAR); - property1->SetWindowRect(topAvoidRect_); - node1->SetWindowProperty(property1); - node1->SetWindowRect(topAvoidRect_); - ASSERT_EQ(WMError::WM_OK, avoidAreaController->AvoidControl(node1, AvoidControlType::AVOID_NODE_ADD)); - - sptr node2 = new WindowNode(); - sptr property2 = new WindowProperty(); - property2->SetWindowId(100u); - property2->SetWindowType(WindowType::WINDOW_TYPE_STATUS_BAR); - node2->SetWindowProperty(property2); - node2->SetWindowRect(topAvoidRect_); - ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, - avoidAreaController->AvoidControl(node2, AvoidControlType::AVOID_NODE_ADD)); -} - -/** - * @tc.name: AddAvoidAreaNode03 - * @tc.desc: Add two new avoid area Nodes - * @tc.type: FUNC - */ -HWTEST_F(AvoidAreaControllerTest, AddAvoidAreaNode03, Function | SmallTest | Level2) -{ - sptr avoidAreaController = new AvoidAreaController(0, nullptr); - - sptr node1 = new WindowNode(); - sptr property1 = new WindowProperty(); - property1->SetWindowId(100u); - property1->SetWindowType(WindowType::WINDOW_TYPE_STATUS_BAR); - node1->SetWindowProperty(property1); - node1->SetWindowRect(topAvoidRect_); - ASSERT_EQ(WMError::WM_OK, avoidAreaController->AvoidControl(node1, AvoidControlType::AVOID_NODE_ADD)); - - sptr node2 = new WindowNode(); - sptr property2 = new WindowProperty(); - property2->SetWindowId(101u); - property2->SetWindowType(WindowType::WINDOW_TYPE_STATUS_BAR); - node2->SetWindowProperty(property2); - node2->SetWindowRect(leftAvoidRect_); - ASSERT_EQ(WMError::WM_OK, avoidAreaController->AvoidControl(node2, AvoidControlType::AVOID_NODE_ADD)); -} - -/** - * @tc.name: AddAvoidAreaNode04 - * @tc.desc: Add nullptr - * @tc.type: FUNC - */ -HWTEST_F(AvoidAreaControllerTest, AddAvoidAreaNode04, Function | SmallTest | Level2) -{ - sptr avoidAreaController = new AvoidAreaController(0, nullptr); - ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, - avoidAreaController->AvoidControl(nullptr, AvoidControlType::AVOID_NODE_ADD)); -} - -/** - * @tc.name: RemoveAvoidAreaNode01 - * @tc.desc: Add a new avoid area. And Remove this. - * @tc.type: FUNC - */ -HWTEST_F(AvoidAreaControllerTest, RemoveAvoidAreaNode01, Function | SmallTest | Level2) -{ - sptr avoidAreaController = new AvoidAreaController(0, nullptr); - - sptr node1 = new WindowNode(); - sptr property1 = new WindowProperty(); - property1->SetWindowId(100u); - property1->SetWindowType(WindowType::WINDOW_TYPE_STATUS_BAR); - node1->SetWindowProperty(property1); - node1->SetWindowRect(leftAvoidRect_); - ASSERT_EQ(WMError::WM_OK, avoidAreaController->AvoidControl(node1, AvoidControlType::AVOID_NODE_ADD)); - - ASSERT_EQ(WMError::WM_OK, avoidAreaController->AvoidControl(node1, AvoidControlType::AVOID_NODE_REMOVE)); -} - -/** - * @tc.name: RemoveAvoidAreaNode02 - * @tc.desc: Remove a unexist avoid area. - * @tc.type: FUNC - */ -HWTEST_F(AvoidAreaControllerTest, RemoveAvoidAreaNode02, Function | SmallTest | Level2) -{ - sptr avoidAreaController = new AvoidAreaController(0, nullptr); - - sptr node = new WindowNode(); sptr property = new WindowProperty(); - property->SetWindowId(100u); - property->SetWindowType(WindowType::WINDOW_TYPE_STATUS_BAR); - node->SetWindowRect(topAvoidRect_); - node->SetWindowProperty(property); - ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, - avoidAreaController->AvoidControl(node, AvoidControlType::AVOID_NODE_REMOVE)); + property->SetWindowId(110u); + property->SetWindowName("test"); + property->SetWindowType(WindowType::APP_WINDOW_BASE); + property->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN); + property->SetWindowRect(screenRect); + sptr listener = new WindowListener(); + sptr appWindow = new WindowNode(property, listener, nullptr); + uint32_t focusedWindow = 0u; + sptr avoidAreaController = new AvoidAreaController(focusedWindow); + avoidAreaController->ProcessWindowChange(appWindow, AvoidControlType::AVOID_NODE_ADD, nullptr); + + uint32_t start = static_cast(WindowMode::WINDOW_MODE_FULLSCREEN); + uint32_t end = static_cast(WindowMode::WINDOW_MODE_FLOATING); + for (uint32_t i = start; i <= end; i++) { + focusedWindow = 0u; + appWindow->SetWindowMode(static_cast(i)); + avoidAreaController->ProcessWindowChange(keyboardWindowNode, AvoidControlType::AVOID_NODE_ADD, nullptr); + auto avoidArea = avoidAreaController->GetAvoidAreaByType(appWindow, AvoidAreaType::TYPE_KEYBOARD); + CHECK_AVOID_AREA(avoidArea, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT); + + keyboardWindowNode->SetCallingWindow(appWindow->GetWindowId()); + avoidArea = avoidAreaController->GetAvoidAreaByType(appWindow, AvoidAreaType::TYPE_KEYBOARD); + CHECK_AVOID_AREA(avoidArea, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT, keyboardWindowNode->GetWindowRect()); + + keyboardWindowNode->SetCallingWindow(0); + focusedWindow = appWindow->GetWindowId(); + avoidArea = avoidAreaController->GetAvoidAreaByType(appWindow, AvoidAreaType::TYPE_KEYBOARD); + CHECK_AVOID_AREA(avoidArea, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT, keyboardWindowNode->GetWindowRect()); + + avoidAreaController->ProcessWindowChange(keyboardWindowNode, AvoidControlType::AVOID_NODE_REMOVE, nullptr); + avoidArea = avoidAreaController->GetAvoidAreaByType(appWindow, AvoidAreaType::TYPE_KEYBOARD); + CHECK_AVOID_AREA(avoidArea, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT); + } } /** - * @tc.name: RemoveAvoidAreaNode03 - * @tc.desc: Remove nullptr + * @tc.name: KeyboardAvoidArea02 + * @tc.desc: Get avoid areas with listener, TYPE_KEYBOARD. * @tc.type: FUNC */ -HWTEST_F(AvoidAreaControllerTest, RemoveAvoidAreaNode03, Function | SmallTest | Level2) +HWTEST_F(AvoidAreaControllerTest, KeyboardAvoidArea02, Function | SmallTest | Level2) { - sptr avoidAreaController = new AvoidAreaController(0, nullptr); - ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, - avoidAreaController->AvoidControl(nullptr, AvoidControlType::AVOID_NODE_REMOVE)); -} - -/** - * @tc.name: UpdateAvoidAreaNode01 - * @tc.desc: Add a new avoid area node and update this - * @tc.type: FUNC - */ -HWTEST_F(AvoidAreaControllerTest, UpdateAvoidAreaNode01, Function | SmallTest | Level2) -{ - sptr avoidAreaController = new AvoidAreaController(0, nullptr); - - sptr node = new WindowNode(); sptr property = new WindowProperty(); - property->SetWindowId(100u); - property->SetWindowType(WindowType::WINDOW_TYPE_STATUS_BAR); - node->SetWindowProperty(property); - node->SetWindowRect(topAvoidRect_); - ASSERT_EQ(WMError::WM_OK, avoidAreaController->AvoidControl(node, AvoidControlType::AVOID_NODE_ADD)); - - property->SetWindowRect(leftAvoidRect_); - ASSERT_EQ(WMError::WM_OK, avoidAreaController->AvoidControl(node, AvoidControlType::AVOID_NODE_UPDATE)); -} - -/** - * @tc.name: UpdateAvoidAreaNode02 - * @tc.desc: update a unexist avoid area node - * @tc.type: FUNC - */ -HWTEST_F(AvoidAreaControllerTest, UpdateAvoidAreaNode02, Function | SmallTest | Level2) -{ - sptr avoidAreaController = new AvoidAreaController(0, nullptr); - - sptr node = new WindowNode(); - sptr property = new WindowProperty(); - property->SetWindowId(100u); - property->SetWindowType(WindowType::WINDOW_TYPE_STATUS_BAR); - node->SetWindowProperty(property); - node->SetWindowRect(topAvoidRect_); - - ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, - avoidAreaController->AvoidControl(node, AvoidControlType::AVOID_NODE_UPDATE)); -} - -/** - * @tc.name: UpdateAvoidAreaNode03 - * @tc.desc: Update nullptr - * @tc.type: FUNC - */ -HWTEST_F(AvoidAreaControllerTest, UpdateAvoidAreaNode03, Function | SmallTest | Level2) -{ - sptr avoidAreaController = new AvoidAreaController(0, nullptr); - ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, - avoidAreaController->AvoidControl(nullptr, AvoidControlType::AVOID_NODE_UPDATE)); -} - -/** - * @tc.name: GetAvoidAreaByType01 - * @tc.desc: Search a unexist AvoidAreaType. And GetAvoidAreaByType - * @tc.type: FUNC - */ -HWTEST_F(AvoidAreaControllerTest, GetAvoidAreaByType01, Function | SmallTest | Level2) -{ - sptr avoidAreaController = new AvoidAreaController(0, nullptr); - std::vector avoidArea = avoidAreaController->GetAvoidAreaByType(AvoidAreaType::TYPE_CUTOUT, displayId_); - - ASSERT_EQ(4u, static_cast(avoidArea.size())); - ASSERT_TRUE(RectEqualToRect(EMPTY_RECT, avoidArea[LEFT])); - ASSERT_TRUE(RectEqualToRect(EMPTY_RECT, avoidArea[TOP])); - ASSERT_TRUE(RectEqualToRect(EMPTY_RECT, avoidArea[RIGHT])); - ASSERT_TRUE(RectEqualToRect(EMPTY_RECT, avoidArea[BOTTOM])); + property->SetWindowId(110u); + property->SetWindowName("test"); + property->SetWindowType(WindowType::APP_WINDOW_BASE); + property->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN); + property->SetWindowRect(screenRect); + sptr listener = new WindowListener(); + sptr appWindow = new WindowNode(property, listener, nullptr); + uint32_t focusedWindow = appWindow->GetWindowId(); + sptr avoidAreaController = new AvoidAreaController(focusedWindow); + avoidAreaController->ProcessWindowChange(appWindow, AvoidControlType::AVOID_NODE_ADD, nullptr); + avoidAreaController->UpdateAvoidAreaListener(appWindow, true); + uint32_t start = static_cast(WindowMode::WINDOW_MODE_FULLSCREEN); + uint32_t end = static_cast(WindowMode::WINDOW_MODE_FLOATING); + for (uint32_t i = start; i <= end; i++) { + avoidAreaController->ProcessWindowChange(keyboardWindowNode, AvoidControlType::AVOID_NODE_ADD, nullptr); + auto avoidArea = listener->keyboardAvoidAreaFuture_.GetResult(TIME_OUT); + listener->keyboardAvoidAreaFuture_.Reset(EMPTY_AVOID_AREA); + CHECK_AVOID_AREA(avoidArea, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT, keyboardWindowNode->GetWindowRect()); + avoidAreaController->ProcessWindowChange(keyboardWindowNode, AvoidControlType::AVOID_NODE_REMOVE, nullptr); + avoidArea = listener->keyboardAvoidAreaFuture_.GetResult(TIME_OUT); + listener->keyboardAvoidAreaFuture_.Reset(EMPTY_AVOID_AREA); + CHECK_AVOID_AREA(avoidArea, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT); + } + avoidAreaController->ProcessWindowChange(appWindow, AvoidControlType::AVOID_NODE_REMOVE, nullptr); } } } // namespace Rosen diff --git a/wm/test/unittest/avoid_area_controller_test.h b/wm/test/unittest/avoid_area_controller_test.h index 91ed6623..4d5f6fed 100644 --- a/wm/test/unittest/avoid_area_controller_test.h +++ b/wm/test/unittest/avoid_area_controller_test.h @@ -17,6 +17,7 @@ #define FRAMEWORKS_WM_TEST_UT_AVOID_AREA_CONTROLLER_TEST_H #include +#include "window_node.h" #include "wm_common.h" namespace OHOS { @@ -28,12 +29,11 @@ public: virtual void SetUp() override; virtual void TearDown() override; - static Rect topAvoidRect_; - static Rect leftAvoidRect_; - -private: - static void InitByScreenRect(const Rect& screenRect); - DisplayId displayId_ = 0; + static sptr statusbarWindowNode; + static sptr navigationBarWindowNode; + static sptr keyboardWindowNode; + static Rect screenRect; + static Rect cut_out_rect; }; } // namespace ROSEN } // namespace OHOS diff --git a/wmserver/src/avoid_area_controller.cpp b/wmserver/src/avoid_area_controller.cpp index a173696c..40a8869f 100644 --- a/wmserver/src/avoid_area_controller.cpp +++ b/wmserver/src/avoid_area_controller.cpp @@ -121,10 +121,8 @@ void AvoidAreaController::AddOrRemoveKeyboard(const sptr& keyboardNo } if (lastKeyboardAreaUpdatedWindow != nullptr && lastKeyboardAreaUpdatedWindow != callingWindow) { const WindowMode windowMode = lastKeyboardAreaUpdatedWindow->GetWindowMode(); - if (windowMode == WindowMode::WINDOW_MODE_FULLSCREEN || - windowMode == WindowMode::WINDOW_MODE_SPLIT_PRIMARY || - windowMode == WindowMode::WINDOW_MODE_SPLIT_SECONDARY || - windowMode == WindowMode::WINDOW_MODE_FLOATING) { + if (windowMode == WindowMode::WINDOW_MODE_FULLSCREEN || windowMode == WindowMode::WINDOW_MODE_SPLIT_PRIMARY || + windowMode == WindowMode::WINDOW_MODE_SPLIT_SECONDARY || windowMode == WindowMode::WINDOW_MODE_FLOATING) { auto avoidArea = GetAvoidAreaByType(lastKeyboardAreaUpdatedWindow, AvoidAreaType::TYPE_KEYBOARD); UpdateAvoidAreaIfNeed(avoidArea, lastKeyboardAreaUpdatedWindow, AvoidAreaType::TYPE_KEYBOARD); } @@ -171,7 +169,7 @@ void AvoidAreaController::UpdateOverlayWindowIfNeed(const sptr& node } uint32_t start = static_cast(AvoidAreaType::TYPE_SYSTEM); uint32_t end = static_cast(AvoidAreaType::TYPE_KEYBOARD); - for (int type = start; type <= end; type++) { + for (uint32_t type = start; type <= end; type++) { AvoidArea systemAvoidArea = GetAvoidAreaByType(node, static_cast(type)); bool res = UpdateAvoidAreaIfNeed(systemAvoidArea, node, static_cast(type)); if (res && type == static_cast(AvoidAreaType::TYPE_KEYBOARD)) { @@ -292,6 +290,7 @@ AvoidArea AvoidAreaController::GetAvoidAreaByType(const sptr& node, case AvoidAreaType::TYPE_CUTOUT : { auto numbersConfig = DisplayManagerConfig::GetIntNumbersConfig(); if (numbersConfig.count("cutoutArea") == 0) { + WLOGFE("there is no cutout"); return {}; } std::vector cutoutArea = numbersConfig["cutoutArea"]; @@ -335,10 +334,6 @@ AvoidArea AvoidAreaController::GetAvoidAreaSystemType(const sptr& no AvoidArea AvoidAreaController::GetAvoidAreaKeyboardType(const sptr& node) const { - if (focusedWindow_ != node->GetWindowId()) { - WLOGFI("focusedWindow: %{public}u is not windowId: %{public}u", focusedWindow_, node->GetWindowId()); - return {}; - } for (auto& iter : overlayWindowMap_) { if (iter.second != nullptr && iter.second->GetWindowType() == WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT) { @@ -348,7 +343,7 @@ AvoidArea AvoidAreaController::GetAvoidAreaKeyboardType(const sptr& node->GetWindowId(), focusedWindow_, callingWindowId); continue; } - Rect avoidAreaRect; + Rect avoidAreaRect { 0, 0, 0, 0 }; AvoidPosType avoidPosType = CalculateOverlayRect(node, iter.second, avoidAreaRect); AvoidArea avoidArea; SetAvoidAreaRect(avoidArea, avoidAreaRect, avoidPosType); From 0460d02b3b13cd3bd9763c9fca717a3ff3ac41e0 Mon Sep 17 00:00:00 2001 From: yangzhou Date: Thu, 30 Jun 2022 07:16:39 +0000 Subject: [PATCH 49/81] =?UTF-8?q?pointer=E4=BA=8B=E4=BB=B6global=E5=9D=90?= =?UTF-8?q?=E6=A0=87=EF=BC=8Clocal=E5=9D=90=E6=A0=87=E5=91=BD=E5=90=8D?= =?UTF-8?q?=E6=94=B9=E4=B8=BAdisplay=E3=80=81window?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yangzhou --- wm/src/window_impl.cpp | 16 ++++++++-------- wm/test/systemtest/window_move_drag_test.cpp | 4 ++-- wm/test/systemtest/window_test_utils.cpp | 4 ++-- 3 files changed, 12 insertions(+), 12 deletions(-) mode change 100644 => 100755 wm/src/window_impl.cpp mode change 100644 => 100755 wm/test/systemtest/window_move_drag_test.cpp mode change 100644 => 100755 wm/test/systemtest/window_test_utils.cpp diff --git a/wm/src/window_impl.cpp b/wm/src/window_impl.cpp old mode 100644 new mode 100755 index 5145bbf8..697eba5f --- a/wm/src/window_impl.cpp +++ b/wm/src/window_impl.cpp @@ -1828,11 +1828,11 @@ void WindowImpl::UpdatePointerEventForStretchableWindow(std::shared_ptrGetOriginRect(); PointInfo originPos = WindowHelper::CalculateOriginPosition(originRect, GetRect(), - { pointerItem.GetGlobalX(), pointerItem.GetGlobalY() }); - pointerItem.SetGlobalX(originPos.x); - pointerItem.SetGlobalY(originPos.y); - pointerItem.SetLocalX(originPos.x - originRect.posX_); - pointerItem.SetLocalY(originPos.y - originRect.posY_); + { pointerItem.GetDisplayX(), pointerItem.GetDisplayY() }); + pointerItem.SetDisplayX(originPos.x); + pointerItem.SetDisplayY(originPos.y); + pointerItem.SetWindowX(originPos.x - originRect.posX_); + pointerItem.SetWindowY(originPos.y - originRect.posY_); pointerEvent->UpdatePointerItem(pointerEvent->GetPointerId(), pointerItem); } @@ -1936,8 +1936,8 @@ void WindowImpl::ConsumeMoveOrDragEvent(std::shared_ptr& poin WLOGFW("Point item is invalid"); return; } - int32_t pointGlobalX = pointerItem.GetGlobalX(); - int32_t pointGlobalY = pointerItem.GetGlobalY(); + int32_t pointGlobalX = pointerItem.GetDisplayX(); + int32_t pointGlobalY = pointerItem.GetDisplayY(); int32_t action = pointerEvent->GetPointerAction(); switch (action) { // Ready to move or drag @@ -1997,7 +1997,7 @@ void WindowImpl::ConsumePointerEvent(std::shared_ptr& pointer WLOGFW("Point item is invalid"); return; } - if (!WindowHelper::IsPointInTargetRect(pointerItem.GetGlobalX(), pointerItem.GetGlobalY(), GetRect())) { + if (!WindowHelper::IsPointInTargetRect(pointerItem.GetDisplayX(), pointerItem.GetDisplayY(), GetRect())) { NotifyListenerAfterUnfocused(); return; } diff --git a/wm/test/systemtest/window_move_drag_test.cpp b/wm/test/systemtest/window_move_drag_test.cpp old mode 100644 new mode 100755 index 6b0de20f..cbcff597 --- a/wm/test/systemtest/window_move_drag_test.cpp +++ b/wm/test/systemtest/window_move_drag_test.cpp @@ -110,8 +110,8 @@ std::shared_ptr WindowMoveDragTest::CreatePointerEvent(int32_ { MMI::PointerEvent::PointerItem pointerItem; pointerItem.SetPointerId(pointerId); - pointerItem.SetGlobalX(posX); - pointerItem.SetGlobalY(posY); + pointerItem.SetDisplayX(posX); + pointerItem.SetDisplayY(posY); std::shared_ptr pointerEvent = MMI::PointerEvent::Create(); pointerEvent->AddPointerItem(pointerItem); diff --git a/wm/test/systemtest/window_test_utils.cpp b/wm/test/systemtest/window_test_utils.cpp old mode 100644 new mode 100755 index ff7e6299..b9159953 --- a/wm/test/systemtest/window_test_utils.cpp +++ b/wm/test/systemtest/window_test_utils.cpp @@ -224,8 +224,8 @@ std::shared_ptr WindowTestUtils::CreatePointerEvent(int32_t p { MMI::PointerEvent::PointerItem pointerItem; pointerItem.SetPointerId(pointerId); - pointerItem.SetGlobalX(posX); - pointerItem.SetGlobalY(posY); + pointerItem.SetDisplayX(posX); + pointerItem.SetDisplayY(posY); std::shared_ptr pointerEvent = MMI::PointerEvent::Create(); pointerEvent->AddPointerItem(pointerItem); From e46adbf53f38209f9e64fa4428221ef2d0825b97 Mon Sep 17 00:00:00 2001 From: xiahaiqin Date: Thu, 30 Jun 2022 16:44:11 +0800 Subject: [PATCH 50/81] modify deps for bundle.json Signed-off-by: xiahaiqin Change-Id: I9e1c6930f83d72e1c19bf9c78895df7d8eda00e1 --- bundle.json | 43 ++++++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/bundle.json b/bundle.json index 6021f903..eda53562 100644 --- a/bundle.json +++ b/bundle.json @@ -22,27 +22,36 @@ ], "deps": { "components": [ + "inputmethod_native", + "sensor", "ability_base", - "libhilog", - "ipc_core", - "system_ability_fwk", - "samgr_proxy", - "image_native", - "utils", - "bytrace_core", - "surface", - "ability_context_native", + "graphic_standard", + "hisysevent_native", "ability_runtime", - "want", - "ace_uicontent", - "appexecfwk_base", - "appexecfwk_core", - "inputmethod_client", - "libmmi-client", - "ace_napi", - "resource_management" + "napi", + "common_event_service", + "hilog_native", + "access_token", + "init", + "bundle_framework", + "hiviewdfx_hilog_native", + "ipc", + "power_manager_native", + "utils_base", + "hitrace_native", + "resource_management", + "samgr_standard", + "input", + "safwk", + "display_manager_native", + "config_policy", + "ace_engine", + "multimedia_image_standard" ], "third_party": [ + "flutter", + "libxml2", + "libpng" ] }, "build": { From 4a07d3a9a003bc4ddc3ec571988d302a22e031a1 Mon Sep 17 00:00:00 2001 From: leafly2021 Date: Thu, 30 Jun 2022 16:02:58 +0800 Subject: [PATCH 51/81] modify codedex Signed-off-by: leafly2021 Change-Id: Ia5880ced5f4869c5a96fde32ca8fa680bdbf50fc --- dmserver/src/abstract_screen.cpp | 2 +- .../kits/napi/screen_recorder/napi/screen_recorder.cpp | 2 +- wm/src/window_impl.cpp | 8 ++++---- wmserver/src/window_controller.cpp | 3 +-- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/dmserver/src/abstract_screen.cpp b/dmserver/src/abstract_screen.cpp index fd008e0d..e085ecdf 100644 --- a/dmserver/src/abstract_screen.cpp +++ b/dmserver/src/abstract_screen.cpp @@ -37,7 +37,7 @@ AbstractScreen::~AbstractScreen() sptr AbstractScreen::GetActiveScreenMode() const { - if (activeIdx_ < 0 || activeIdx_ >= modes_.size()) { + if (activeIdx_ < 0 || activeIdx_ >= static_cast(modes_.size())) { WLOGE("active mode index is wrong: %{public}d", activeIdx_); return nullptr; } diff --git a/interfaces/kits/napi/screen_recorder/napi/screen_recorder.cpp b/interfaces/kits/napi/screen_recorder/napi/screen_recorder.cpp index d85e40ba..885add7e 100644 --- a/interfaces/kits/napi/screen_recorder/napi/screen_recorder.cpp +++ b/interfaces/kits/napi/screen_recorder/napi/screen_recorder.cpp @@ -81,7 +81,7 @@ DMError ScreenRecorder::Start(std::vector fds) void ScreenRecorder::Record() { WLOGFE("Record"); - if (stop_ || fileIndex_ >= fds_.size()) { + if (stop_ || fileIndex_ >= static_cast(fds_.size())) { isStarting_ = false; return; } diff --git a/wm/src/window_impl.cpp b/wm/src/window_impl.cpp index 5145bbf8..571f532c 100644 --- a/wm/src/window_impl.cpp +++ b/wm/src/window_impl.cpp @@ -1633,9 +1633,7 @@ void WindowImpl::UpdateRect(const struct Rect& rect, bool decoStatus, WindowSize property_->GetWindowId()); return; } - float virtualPixelRatio = display->GetVirtualPixelRatio(); - WLOGFI("winId:%{public}u, rect[%{public}d, %{public}d, %{public}u, %{public}u], vpr:%{public}f, reason:%{public}u", - GetWindowId(), rect.posX_, rect.posY_, rect.width_, rect.height_, virtualPixelRatio, reason); + property_->SetDecoStatus(decoStatus); if (reason == WindowSizeChangeReason::HIDE) { property_->SetRequestRect(rect); @@ -1648,6 +1646,8 @@ void WindowImpl::UpdateRect(const struct Rect& rect, bool decoStatus, WindowSize property_->SetOriginRect(rect); isOriginRectSet_ = true; } + WLOGFI("winId:%{public}u, rect[%{public}d, %{public}d, %{public}u, %{public}u], reason:%{public}u", + property_->GetWindowId(), rect.posX_, rect.posY_, rect.width_, rect.height_, reason); Rect rectToAce = rect; // update rectToAce for stretchable window if (windowSystemConfig_.isStretchable_ && WindowHelper::IsMainFloatingWindow(GetType(), GetMode())) { @@ -1668,7 +1668,7 @@ void WindowImpl::UpdateRect(const struct Rect& rect, bool decoStatus, WindowSize property_->GetWindowId(), rectToAce.posX_, rectToAce.posY_, rectToAce.width_, rectToAce.height_); config.SetSize(rectToAce.width_, rectToAce.height_); config.SetPosition(rectToAce.posX_, rectToAce.posY_); - config.SetDensity(virtualPixelRatio); + config.SetDensity(display->GetVirtualPixelRatio()); uiContent_->UpdateViewportConfig(config, reason); WLOGFI("notify uiContent window size change end"); } diff --git a/wmserver/src/window_controller.cpp b/wmserver/src/window_controller.cpp index fa65c722..3bd19faa 100644 --- a/wmserver/src/window_controller.cpp +++ b/wmserver/src/window_controller.cpp @@ -806,8 +806,7 @@ WMError WindowController::UpdateProperty(sptr& property, Propert } case PropertyChangeAction::ACTION_UPDATE_ORIENTATION: { node->SetRequestedOrientation(property->GetRequestedOrientation()); - if (WindowHelper::IsMainWindow(node->GetWindowType()) && - node->GetWindowMode() == WindowMode::WINDOW_MODE_FULLSCREEN) { + if (WindowHelper::IsMainFullScreenWindow(node->GetWindowType(), node->GetWindowMode())) { DisplayManagerServiceInner::GetInstance(). SetOrientationFromWindow(node->GetDisplayId(), property->GetRequestedOrientation()); } From 1778bed66772597c8b9b2b7a8f5abf0267034eb3 Mon Sep 17 00:00:00 2001 From: xiaojianfeng Date: Thu, 30 Jun 2022 16:40:13 +0800 Subject: [PATCH 52/81] fix window_layout_test bug Signed-off-by: xiaojianfeng Change-Id: I43ad6e77b5830241a5d77fdc9294f1620bf7730e --- wm/test/systemtest/BUILD.gn | 1 + wm/test/systemtest/window_layout_test.cpp | 22 +++++++++++++++++++ wm/test/systemtest/window_test_utils.cpp | 6 ++--- wm/test/systemtest/window_test_utils.h | 1 + .../unittest/avoid_area_controller_test.cpp | 4 ++-- 5 files changed, 28 insertions(+), 6 deletions(-) diff --git a/wm/test/systemtest/BUILD.gn b/wm/test/systemtest/BUILD.gn index f05745d1..392b70df 100644 --- a/wm/test/systemtest/BUILD.gn +++ b/wm/test/systemtest/BUILD.gn @@ -28,6 +28,7 @@ group("systemtest") { ":wm_window_immersive_test", ":wm_window_input_method_test", ":wm_window_input_test", + ":wm_window_layout_test", ":wm_window_mode_support_info_test", ":wm_window_move_drag_test", ":wm_window_multi_ability_test", diff --git a/wm/test/systemtest/window_layout_test.cpp b/wm/test/systemtest/window_layout_test.cpp index d84a018b..7ec70f89 100644 --- a/wm/test/systemtest/window_layout_test.cpp +++ b/wm/test/systemtest/window_layout_test.cpp @@ -35,6 +35,7 @@ public: static inline float virtualPixelRatio_ = 0.0; private: static constexpr uint32_t WAIT_SYANC_US = 100000; + static void InitAvoidArea(); }; vector WindowLayoutTest::fullScreenExpecteds_; @@ -70,6 +71,26 @@ void WindowLayoutTest::SetUpTestCase() Utils::displayRect_.height_ - Utils::naviBarRect_.height_, }; fullScreenExpecteds_.push_back(expected); + InitAvoidArea(); +} + +void WindowLayoutTest::InitAvoidArea() +{ + Utils::TestWindowInfo info = { + .name = "avoidArea", + .rect = {0, 0, 0, 0}, + .type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, + .mode = WindowMode::WINDOW_MODE_FLOATING, + .needAvoid = true, + .parentLimit = false, + .parentName = "", + }; + const sptr& window = Utils::CreateTestWindow(info); + window->Show(); + window->SetLayoutFullScreen(true); + window->GetAvoidAreaByType(AvoidAreaType::TYPE_SYSTEM, WindowTestUtils::systemAvoidArea_); + window->Hide(); + window->Destroy(); } void WindowLayoutTest::TearDownTestCase() @@ -112,6 +133,7 @@ HWTEST_F(WindowLayoutTest, LayoutWindow01, Function | MediumTest | Level3) .parentName = "", }; const sptr& window = Utils::CreateTestWindow(info); + ASSERT_EQ(true, window != nullptr); activeWindows_.push_back(window); Rect expect = Utils::GetDefaultFloatingRect(window); ASSERT_EQ(WMError::WM_OK, window->Show()); diff --git a/wm/test/systemtest/window_test_utils.cpp b/wm/test/systemtest/window_test_utils.cpp index ff7e6299..43c0a97d 100644 --- a/wm/test/systemtest/window_test_utils.cpp +++ b/wm/test/systemtest/window_test_utils.cpp @@ -39,6 +39,7 @@ SplitRects WindowTestUtils::splitRects_ = { Rect WindowTestUtils::singleTileRect_ = {0, 0, 0, 0}; std::vector WindowTestUtils::doubleTileRects_ = std::vector(2); std::vector WindowTestUtils::tripleTileRects_ = std::vector(3); +AvoidArea WindowTestUtils::systemAvoidArea_ = {}; bool WindowTestUtils::isVerticalDisplay_ = false; @@ -355,10 +356,7 @@ bool WindowTestUtils::InitSplitRects() void WindowTestUtils::UpdateSplitRects(const sptr& window) { std::unique_ptr testUtils = std::make_unique(); - auto res = window->GetAvoidAreaByType(AvoidAreaType::TYPE_SYSTEM, testUtils->avoidArea_); - if (res != WMError::WM_OK) { - WLOGFE("Get avoid type failed"); - } + testUtils->avoidArea_ = systemAvoidArea_; testUtils->UpdateLimitDisplayRect(testUtils->avoidArea_.leftRect_); testUtils->UpdateLimitDisplayRect(testUtils->avoidArea_.topRect_); testUtils->UpdateLimitDisplayRect(testUtils->avoidArea_.rightRect_); diff --git a/wm/test/systemtest/window_test_utils.h b/wm/test/systemtest/window_test_utils.h index dfa29bbd..aad59e4e 100644 --- a/wm/test/systemtest/window_test_utils.h +++ b/wm/test/systemtest/window_test_utils.h @@ -58,6 +58,7 @@ public: static Rect singleTileRect_; static std::vector doubleTileRects_; static std::vector tripleTileRects_; + static AvoidArea systemAvoidArea_; static void InitByDisplayRect(const Rect& screenRect); static sptr CreateTestWindow(const TestWindowInfo& info); diff --git a/wm/test/unittest/avoid_area_controller_test.cpp b/wm/test/unittest/avoid_area_controller_test.cpp index 96700164..84cce068 100644 --- a/wm/test/unittest/avoid_area_controller_test.cpp +++ b/wm/test/unittest/avoid_area_controller_test.cpp @@ -29,7 +29,7 @@ namespace Rosen { namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "AvoidAreaControllerTest"}; - const Rect EMPTY_RECT = {0, 0, 0, 0}; + const Rect EMPTY_RECT = { 0, 0, 0, 0 }; const float BARRATIO = 0.3; const long TIME_OUT = 1000; const AvoidArea EMPTY_AVOID_AREA = {}; @@ -39,7 +39,7 @@ sptr AvoidAreaControllerTest::statusbarWindowNode = nullptr; sptr AvoidAreaControllerTest::navigationBarWindowNode = nullptr; sptr AvoidAreaControllerTest::keyboardWindowNode = nullptr; Rect AvoidAreaControllerTest::screenRect; -Rect AvoidAreaControllerTest::cut_out_rect = { 10, 10, 100, 20 }; +Rect AvoidAreaControllerTest::cut_out_rect = { 0, 0, 0, 0 }; class WindowListener : public IWindow { public: From 7da59d5319807a84b4101b7afaecce60677e75a0 Mon Sep 17 00:00:00 2001 From: maojiangping Date: Thu, 30 Jun 2022 17:37:02 +0800 Subject: [PATCH 53/81] Fix back key event issue. Signed-off-by: maojiangping Change-Id: Iaef0a6dd0608500b9a6d4456c23ab40193748728 Signed-off-by: maojiangping --- interfaces/innerkits/wm/window.h | 9 +++ wm/include/window_impl.h | 3 + wm/src/window_impl.cpp | 108 ++++++++++++++++++++++--------- wm/src/window_input_channel.cpp | 2 +- 4 files changed, 90 insertions(+), 32 deletions(-) diff --git a/interfaces/innerkits/wm/window.h b/interfaces/innerkits/wm/window.h index 58e185ba..fb9dc854 100644 --- a/interfaces/innerkits/wm/window.h +++ b/interfaces/innerkits/wm/window.h @@ -28,6 +28,7 @@ namespace OHOS::MMI { struct IInputEventConsumer; class PointerEvent; class KeyEvent; + class AxisEvent; } namespace OHOS::AppExecFwk { class Configuration; @@ -120,6 +121,13 @@ public: virtual void OnPointerInputEvent(std::shared_ptr& pointerEvent) = 0; }; +class IInputEventConsumer { +public: + virtual bool OnInputEvent(const std::shared_ptr& keyEvent) const = 0; + virtual bool OnInputEvent(const std::shared_ptr& pointerEvent) const = 0; + virtual bool OnInputEvent(const std::shared_ptr& axisEvent) const = 0; +}; + class ITouchOutsideListener : virtual public RefBase { public: virtual void OnTouchOutside() const = 0; @@ -201,6 +209,7 @@ public: virtual WMError RequestFocus() const = 0; // AddInputEventListener is for api 7 + virtual void SetInputEventConsumer(const std::shared_ptr& inputEventConsumer) = 0; virtual void AddInputEventListener(const std::shared_ptr& inputEventListener) = 0; virtual void ConsumeKeyEvent(std::shared_ptr& inputEvent) = 0; virtual void ConsumePointerEvent(std::shared_ptr& inputEvent) = 0; diff --git a/wm/include/window_impl.h b/wm/include/window_impl.h index f15d6bd1..409206d2 100644 --- a/wm/include/window_impl.h +++ b/wm/include/window_impl.h @@ -172,6 +172,7 @@ public: virtual WMError RequestFocus() const override; virtual void AddInputEventListener(const std::shared_ptr& inputEventListener) override; + virtual void SetInputEventConsumer(const std::shared_ptr& inputEventConsumer) override; virtual void RegisterLifeCycleListener(sptr& listener) override; virtual void RegisterWindowChangeListener(sptr& listener) override; @@ -339,6 +340,7 @@ private: void UpdatePointerEventForStretchableWindow(std::shared_ptr& pointerEvent); void UpdateDragType(); void InitListenerHandler(); + void HandleBackKeyEvent(const std::shared_ptr& keyEvent); bool CheckCameraFloatingWindowMultiCreated(WindowType type); void GetConfigurationFromAbilityInfo(); void UpdateTitleButtonVisibility(); @@ -371,6 +373,7 @@ private: std::vector> displayMoveListeners_; std::vector> occupiedAreaChangeListeners_; std::vector> inputEventListeners_; + std::shared_ptr inputEventConsumer_; NotifyNativeWinDestroyFunc notifyNativefunc_; std::shared_ptr surfaceNode_; std::string name_; diff --git a/wm/src/window_impl.cpp b/wm/src/window_impl.cpp index 5145bbf8..cd59f7c2 100644 --- a/wm/src/window_impl.cpp +++ b/wm/src/window_impl.cpp @@ -1394,6 +1394,12 @@ WMError WindowImpl::RequestFocus() const return SingletonContainer::Get().RequestFocus(property_->GetWindowId()); } +void WindowImpl::SetInputEventConsumer(const std::shared_ptr& inputEventConsumer) +{ + std::lock_guard lock(mutex_); + inputEventConsumer_ = inputEventConsumer; +} + void WindowImpl::AddInputEventListener(const std::shared_ptr& inputEventListener) { InputTransferStation::GetInstance().SetInputListener(GetWindowId(), inputEventListener); @@ -1692,39 +1698,71 @@ void WindowImpl::UpdateModeSupportInfo(uint32_t modeSupportInfo) UpdateTitleButtonVisibility(); } +void WindowImpl::HandleBackKeyEvent(const std::shared_ptr& keyEvent) +{ + int32_t keyAction = keyEvent->GetKeyAction(); + if (keyAction != MMI::KeyEvent::KEY_ACTION_UP) { + return; + } + std::shared_ptr inputEventConsumer; + { + std::lock_guard lock(mutex_); + inputEventConsumer = inputEventConsumer_; + } + bool isConsumed = false; + if (inputEventConsumer != nullptr) { + WLOGFI("Transfer back key event to inputEventConsumer"); + isConsumed = inputEventConsumer->OnInputEvent(keyEvent); + } else if (uiContent_ != nullptr) { + WLOGFI("Transfer back key event to uiContent"); + isConsumed = uiContent_->ProcessBackPressed(); + } else { + WLOGFE("There is no back key event consumer"); + } + if (isConsumed || !WindowHelper::IsMainWindow(property_->GetWindowType())) { + return; + } + auto abilityContext = AbilityRuntime::Context::ConvertTo(context_); + if (abilityContext == nullptr) { + WLOGFE("abilityContext is null"); + return; + } + // TerminateAbility will invoke last ability, CloseAbility will not. + bool shouldCloseAbility = WindowHelper::IsFullScreenWindow(property_->GetWindowMode()); + WMError ret = NotifyWindowTransition(shouldCloseAbility ? TransitionReason::CLOSE : TransitionReason::BACK); + if (ret != WMError::WM_OK) { + WLOGFI("Window %{public}u is closed without remote animation, ret:%{public}u", + property_->GetWindowId(), static_cast(ret)); + if (shouldCloseAbility) { + abilityContext->CloseAbility(); + } else { + abilityContext->TerminateSelf(); + } + } +} + void WindowImpl::ConsumeKeyEvent(std::shared_ptr& keyEvent) { NotifyKeyEvent(keyEvent); - if (uiContent_ == nullptr) { - WLOGE("ConsumeKeyEvent uiContent is nullptr"); - return; - } int32_t keyCode = keyEvent->GetKeyCode(); int32_t keyAction = keyEvent->GetKeyAction(); - WLOGFI("ConsumeKeyEvent: enter GetKeyCode: %{public}d, action: %{public}d", keyCode, keyAction); + WLOGFI("KeyCode: %{public}d, action: %{public}d", keyCode, keyAction); if (keyCode == MMI::KeyEvent::KEYCODE_BACK) { - if (keyAction != MMI::KeyEvent::KEY_ACTION_UP) { - return; - } - if (uiContent_->ProcessBackPressed()) { - WLOGI("ConsumeKeyEvent keyEvent is consumed"); - return; - } - auto abilityContext = AbilityRuntime::Context::ConvertTo(context_); - if (abilityContext != nullptr) { - WMError ret = NotifyWindowTransition(TransitionReason::BACK); - if (ret != WMError::WM_OK) { - WLOGFI("[Client] Window %{public}u terminate without remote animation ret:%{public}u", - property_->GetWindowId(), static_cast(ret)); - abilityContext->TerminateSelf(); - } - } else { - WLOGI("ConsumeKeyEvent destroy window"); - Destroy(); - } + HandleBackKeyEvent(keyEvent); } else { - if (!uiContent_->ProcessKeyEvent(keyEvent)) { - WLOGI("ConsumeKeyEvent no consumer window exit"); + std::shared_ptr inputEventConsumer; + { + std::lock_guard lock(mutex_); + inputEventConsumer = inputEventConsumer_; + } + if (inputEventConsumer != nullptr) { + WLOGFI("Transfer key event to inputEventConsumer"); + (void)inputEventConsumer->OnInputEvent(keyEvent); + } else if (uiContent_ != nullptr) { + WLOGFI("Transfer key event to uiContent"); + (void)uiContent_->ProcessKeyEvent(keyEvent); + } else { + WLOGFE("There is no key event consumer"); } } } @@ -2021,12 +2059,20 @@ void WindowImpl::ConsumePointerEvent(std::shared_ptr& pointer UpdatePointerEventForStretchableWindow(pointerEvent); } NotifyPointEvent(pointerEvent); - if (uiContent_ == nullptr) { - WLOGE("ConsumePointerEvent uiContent is nullptr, windowId: %{public}u", GetWindowId()); - return; + std::shared_ptr inputEventConsumer; + { + std::lock_guard lock(mutex_); + inputEventConsumer = inputEventConsumer_; + } + if (inputEventConsumer != nullptr) { + WLOGFI("Transfer pointer event to inputEventConsumer"); + (void)inputEventConsumer->OnInputEvent(pointerEvent); + } else if (uiContent_ != nullptr) { + WLOGFI("Transfer pointer event to uiContent"); + (void)uiContent_->ProcessPointerEvent(pointerEvent); + } else { + WLOGE("pointerEvent is not consumed, windowId: %{public}u", GetWindowId()); } - WLOGFI("Transfer pointer event to ACE"); - uiContent_->ProcessPointerEvent(pointerEvent); } void WindowImpl::OnVsync(int64_t timeStamp) diff --git a/wm/src/window_input_channel.cpp b/wm/src/window_input_channel.cpp index c4683f7a..7b0fd9c3 100644 --- a/wm/src/window_input_channel.cpp +++ b/wm/src/window_input_channel.cpp @@ -47,7 +47,7 @@ void WindowInputChannel::HandleKeyEvent(std::shared_ptr& keyEvent WLOGFI("dispatch keyEvent to input method"); inputMethodHasProcessed = MiscServices::InputMethodController::GetInstance()->dispatchKeyEvent(keyEvent); } - if (!isKeyboardEvent || !inputMethodHasProcessed) { + if (!inputMethodHasProcessed) { WLOGFI("dispatch keyEvent to ACE"); if (inputListener_ != nullptr) { inputListener_->OnInputEvent(keyEvent); From 4635b3db4560c2112c3924a3b2e10e22d4fa9b78 Mon Sep 17 00:00:00 2001 From: xiaojianfeng Date: Fri, 1 Jul 2022 15:32:28 +0800 Subject: [PATCH 54/81] fix systemBar rect bug when rotation Signed-off-by: xiaojianfeng Change-Id: Iabd5f61a46bee943ddb09ea46c49ef5aba1b021c --- wmserver/include/window_controller.h | 3 -- wmserver/src/window_controller.cpp | 70 +++++++--------------------- 2 files changed, 17 insertions(+), 56 deletions(-) diff --git a/wmserver/include/window_controller.h b/wmserver/include/window_controller.h index e63af51a..83526c1f 100644 --- a/wmserver/include/window_controller.h +++ b/wmserver/include/window_controller.h @@ -92,9 +92,6 @@ private: { WindowType::WINDOW_TYPE_STATUS_BAR, INVALID_WINDOW_ID }, { WindowType::WINDOW_TYPE_NAVIGATION_BAR, INVALID_WINDOW_ID }, }; - std::unordered_map>> systemBarRect_; - std::unordered_map> curDisplayInfo_; - constexpr static float SYSTEM_BAR_HEIGHT_RATIO = 0.08; bool isScreenLocked_ { false }; }; } // Rosen diff --git a/wmserver/src/window_controller.cpp b/wmserver/src/window_controller.cpp index fa65c722..829e6bb4 100644 --- a/wmserver/src/window_controller.cpp +++ b/wmserver/src/window_controller.cpp @@ -237,28 +237,18 @@ void WindowController::ResizeSystemBarPropertySizeIfNeed(const sptr& WLOGFE("displayInfo is null"); return; } - uint32_t displayWidth = static_cast(displayInfo->GetWidth()); - uint32_t displayHeight = static_cast(displayInfo->GetHeight()); - Rect targetRect = node->GetWindowRect(); + auto width = static_cast(displayInfo->GetWidth()); + auto height = static_cast(displayInfo->GetHeight()); + Rect newRect = node->GetWindowRect(); if (node->GetWindowType() == WindowType::WINDOW_TYPE_STATUS_BAR) { - auto statusBarRectIter = - systemBarRect_[WindowType::WINDOW_TYPE_STATUS_BAR][displayWidth].find(displayHeight); - if (statusBarRectIter != systemBarRect_[WindowType::WINDOW_TYPE_STATUS_BAR][displayWidth].end()) { - targetRect = statusBarRectIter->second; - } + auto statusBarHeight = newRect.height_; + newRect = { 0, 0, width, statusBarHeight }; } else if (node->GetWindowType() == WindowType::WINDOW_TYPE_NAVIGATION_BAR) { - auto navigationBarRectIter = - systemBarRect_[WindowType::WINDOW_TYPE_NAVIGATION_BAR][displayWidth].find(displayHeight); - if (navigationBarRectIter != systemBarRect_[WindowType::WINDOW_TYPE_NAVIGATION_BAR][displayWidth].end()) { - targetRect = navigationBarRectIter->second; - } + auto naviBarHeight = newRect.height_; + newRect = { 0, static_cast(height - naviBarHeight), width, naviBarHeight }; } - if (curDisplayInfo_.find(displayInfo->GetDisplayId()) == curDisplayInfo_.end()) { - curDisplayInfo_[displayInfo->GetDisplayId()] = displayInfo; - } - Rect propertyRect = node->GetWindowRect(); - if (propertyRect != targetRect) { - ResizeRect(node->GetWindowId(), targetRect, WindowSizeChangeReason::DRAG); + if (newRect != node->GetWindowRect()) { + ResizeRect(node->GetWindowId(), newRect, WindowSizeChangeReason::DRAG); } } @@ -437,44 +427,18 @@ void WindowController::NotifyDisplayStateChange(DisplayId defaultDisplayId, sptr void WindowController::ProcessSystemBarChange(const sptr& displayInfo) { DisplayId displayId = displayInfo->GetDisplayId(); - auto iter = curDisplayInfo_.find(displayId); - if (iter != curDisplayInfo_.end()) { - auto lastDisplayInfo = iter->second; - uint32_t lastDisplayWidth = static_cast(lastDisplayInfo->GetWidth()); - uint32_t lastDisplayHeight = static_cast(lastDisplayInfo->GetHeight()); - auto statusBarNode = windowRoot_->GetWindowNode(sysBarWinId_[WindowType::WINDOW_TYPE_STATUS_BAR]); - auto navigationBarNode = - windowRoot_->GetWindowNode(sysBarWinId_[WindowType::WINDOW_TYPE_NAVIGATION_BAR]); - systemBarRect_[WindowType::WINDOW_TYPE_STATUS_BAR][lastDisplayWidth][lastDisplayHeight] - = statusBarNode->GetWindowProperty()->GetWindowRect(); - systemBarRect_[WindowType::WINDOW_TYPE_NAVIGATION_BAR][lastDisplayWidth][lastDisplayHeight] - = navigationBarNode->GetWindowProperty()->GetWindowRect(); - } - curDisplayInfo_[displayId] = displayInfo; - // Remove 'sysBarWinId_' after SystemUI resize 'systembar' - uint32_t width = static_cast(displayInfo->GetWidth()); - uint32_t height = static_cast(displayInfo->GetHeight() * SYSTEM_BAR_HEIGHT_RATIO); - Rect newRect = { 0, 0, width, height }; - uint32_t displayWidth = static_cast(displayInfo->GetWidth()); - uint32_t displayHeight = static_cast(displayInfo->GetHeight()); - auto statusBarRectIter = - systemBarRect_[WindowType::WINDOW_TYPE_STATUS_BAR][displayWidth].find(displayHeight); - if (statusBarRectIter != systemBarRect_[WindowType::WINDOW_TYPE_STATUS_BAR][displayWidth].end()) { - newRect = statusBarRectIter->second; - } + auto width = static_cast(displayInfo->GetWidth()); + auto height = static_cast(displayInfo->GetHeight()); const auto& statusBarNode = windowRoot_->GetWindowNode(sysBarWinId_[WindowType::WINDOW_TYPE_STATUS_BAR]); - if (statusBarNode->GetDisplayId() == displayId) { + if (statusBarNode != nullptr && statusBarNode->GetDisplayId() == displayId) { + auto statusBarHeight = statusBarNode->GetWindowRect().height_; + Rect newRect = { 0, 0, width, statusBarHeight }; ResizeRect(sysBarWinId_[WindowType::WINDOW_TYPE_STATUS_BAR], newRect, WindowSizeChangeReason::DRAG); } - - newRect = { 0, displayInfo->GetHeight() - static_cast(height), width, height }; - auto navigationBarRectIter = - systemBarRect_[WindowType::WINDOW_TYPE_NAVIGATION_BAR][displayWidth].find(displayHeight); - if (navigationBarRectIter != systemBarRect_[WindowType::WINDOW_TYPE_NAVIGATION_BAR][displayWidth].end()) { - newRect = navigationBarRectIter->second; - } const auto& naviBarNode = windowRoot_->GetWindowNode(sysBarWinId_[WindowType::WINDOW_TYPE_NAVIGATION_BAR]); - if (naviBarNode->GetDisplayId() == displayId) { + if (naviBarNode != nullptr && naviBarNode->GetDisplayId() == displayId) { + auto naviBarHeight = naviBarNode->GetWindowRect().height_; + Rect newRect = { 0, static_cast(height - naviBarHeight), width, naviBarHeight }; ResizeRect(sysBarWinId_[WindowType::WINDOW_TYPE_NAVIGATION_BAR], newRect, WindowSizeChangeReason::DRAG); } } From a51d022d7bc172ebd8bec96162a462761f2d234a Mon Sep 17 00:00:00 2001 From: xpeng Date: Sat, 2 Jul 2022 21:00:15 +0800 Subject: [PATCH 55/81] rebuild rotation logic Signed-off-by: xpeng Change-Id: If2a46ad9b959ad923eff0c92689241e479ec3c7b --- dmserver/include/screen_rotation_controller.h | 58 +++- dmserver/src/abstract_screen_controller.cpp | 6 +- dmserver/src/screen_rotation_controller.cpp | 296 +++++++++++++----- 3 files changed, 260 insertions(+), 100 deletions(-) diff --git a/dmserver/include/screen_rotation_controller.h b/dmserver/include/screen_rotation_controller.h index 0494feb7..8793ee4d 100644 --- a/dmserver/include/screen_rotation_controller.h +++ b/dmserver/include/screen_rotation_controller.h @@ -16,6 +16,7 @@ #ifndef OHOS_ROSEN_SCREEN_ROTATION_CONTROLLER_H #define OHOS_ROSEN_SCREEN_ROTATION_CONTROLLER_H +#include #include #include "sensor_agent.h" @@ -25,6 +26,23 @@ namespace OHOS { namespace Rosen { + +enum class SensorRotation: int32_t { + INVALID = -1, + ROTATION_0 = 0, + ROTATION_90, + ROTATION_180, + ROTATION_270, +}; + +enum class DeviceRotation: int32_t { + INVALID = -1, + ROTATION_PORTRAIT = 0, + ROTATION_LANDSCAPE, + ROTATION_PORTRAIT_INVERTED, + ROTATION_LANDSCAPE_INVERTED, +}; + class ScreenRotationController : public RefBase { public: ScreenRotationController() = delete; @@ -34,31 +52,43 @@ public: static bool IsScreenRotationLocked(); static void SetScreenRotationLocked(bool isLocked); static void SetDefaultDeviceRotationOffset(uint32_t defaultDeviceRotationOffset); + static bool IsGravitySensorEnabled(); private: static void HandleGravitySensorEventCallback(SensorEvent *event); static Rotation GetCurrentDisplayRotation(); - static Orientation GetRequestedOrientation(); + static Orientation GetPreferredOrientation(); static int CalcRotationDegree(GravityData* gravityData); - static Rotation CalcTargetDisplayRotation(Orientation requestedOrientation, Rotation sensorRotation); - static Rotation ProcessAutoRotationPortraitOrientation(Rotation sensorRotation); - static Rotation ProcessAutoRotationLandscapeOrientation(Rotation sensorRotation); + static Rotation CalcTargetDisplayRotation(Orientation requestedOrientation, + DeviceRotation sensorRotationConverted); + static Rotation ProcessAutoRotationPortraitOrientation(DeviceRotation sensorRotationConveted); + static Rotation ProcessAutoRotationLandscapeOrientation(DeviceRotation sensorRotationConveted); static void SetScreenRotation(Rotation targetRotation); static bool CheckCallbackTimeInterval(); - static int CalcSensorDisplayRotation(int orientationDegree); - static Rotation ConvertToDeviceRotation(Rotation sensorRotation); + static DeviceRotation CalcDeviceRotation(SensorRotation sensorRotation); + static bool ProcessOrientationSwitch(Orientation orientation, DeviceRotation deviceRotation); + static SensorRotation CalcSensorRotation(int sensorDegree); + static DeviceRotation ConvertSensorToDeviceRotation(SensorRotation sensorRotation); + static Rotation ConvertDeviceToDisplayRotation(DeviceRotation sensorRotationConverted); + static void ProcessRotationMapping(); + static bool IsDeviceRotationVertical(DeviceRotation deviceRotation); + static bool IsDeviceRotationHorizontal(DeviceRotation deviceRotation); + static bool IsCurrentDisplayVertical(); + static bool IsCurrentDisplayHorizontal(); static bool IsSensorRelatedOrientation(Orientation orientation); - static void ProcessRotationWhenSensorDataNotValid(Orientation orientation); - static void HandleUnspecifiedOrientation(Orientation orientation); static DisplayId defaultDisplayId_; + static SensorUser user_; + static uint32_t defaultDeviceRotationOffset_; + static uint32_t defaultDeviceRotation_; // 0 means PORTRAIT, 1 means LANDSCAPE, use 0 in default. + static std::map sensorToDeviceRotationMap_; + static std::map deviceToDisplayRotationMap_; + static long lastCallbackTime_; + static Orientation lastOrientationType_; + static Rotation currentDisplayRotation_; + static Rotation lastSensorDecidedRotation_; + static Rotation rotationLockedRotation_; static bool isGravitySensorSubscribed_; static bool isScreenRotationLocked_; - static SensorUser user_; - static Rotation currentDisplayRotation_; - static long lastCallbackTime_; - static uint32_t defaultDeviceRotationOffset_; - static Orientation lastOrientationType_; - static Rotation defaultLandscapeDisplayRotation_; }; } // Rosen } // OHOS diff --git a/dmserver/src/abstract_screen_controller.cpp b/dmserver/src/abstract_screen_controller.cpp index 551a0d60..673ff4ec 100644 --- a/dmserver/src/abstract_screen_controller.cpp +++ b/dmserver/src/abstract_screen_controller.cpp @@ -24,6 +24,7 @@ #include "display_manager_agent_controller.h" #include "display_manager_service.h" #include "event_runner.h" +#include "screen_rotation_controller.h" #include "window_manager_hilog.h" #include "wm_trace.h" @@ -620,10 +621,11 @@ bool AbstractScreenController::SetOrientation(ScreenId screenId, Orientation new WLOGI("skip setting orientation. screen %{public}" PRIu64" orientation %{public}u", screenId, newOrientation); return true; } - if (newOrientation >= Orientation::BEGIN && newOrientation <= Orientation::REVERSE_HORIZONTAL) { + if ((newOrientation >= Orientation::VERTICAL+ && newOrientation <= Orientation::REVERSE_HORIZONTAL) || + (newOrientation == Orientation::UNSPECIFIED && !ScreenRotationController::IsGravitySensorEnabled())) { Rotation rotationAfter = screen->CalcRotation(newOrientation); SetRotation(screenId, rotationAfter, false); - screen->rotation_ = rotationAfter; + screen->rotation_ = rotationAfter;; } if (!screen->SetOrientation(newOrientation)) { diff --git a/dmserver/src/screen_rotation_controller.cpp b/dmserver/src/screen_rotation_controller.cpp index d4c414fb..8e65eb18 100644 --- a/dmserver/src/screen_rotation_controller.cpp +++ b/dmserver/src/screen_rotation_controller.cpp @@ -30,8 +30,6 @@ namespace { constexpr int VALID_INCLINATION_ANGLE_THRESHOLD_COEFFICIENT = 3; } -enum class ROTATION_DEGREE_RANGE { }; - DisplayId ScreenRotationController::defaultDisplayId_ = 0; bool ScreenRotationController::isGravitySensorSubscribed_ = false; SensorUser ScreenRotationController::user_; @@ -40,7 +38,13 @@ bool ScreenRotationController::isScreenRotationLocked_ = true; long ScreenRotationController::lastCallbackTime_ = 0; uint32_t ScreenRotationController::defaultDeviceRotationOffset_ = 0; Orientation ScreenRotationController::lastOrientationType_ = Orientation::UNSPECIFIED; -Rotation ScreenRotationController::defaultLandscapeDisplayRotation_ = Rotation::ROTATION_90; +Rotation ScreenRotationController::lastSensorDecidedRotation_; +Rotation ScreenRotationController::rotationLockedRotation_; + +uint32_t ScreenRotationController::defaultDeviceRotation_ = 0; +std::map ScreenRotationController::sensorToDeviceRotationMap_; +std::map ScreenRotationController::deviceToDisplayRotationMap_; + void ScreenRotationController::SubscribeGravitySensor() { @@ -53,18 +57,22 @@ void ScreenRotationController::SubscribeGravitySensor() WLOGFE("dms strcpy_s error"); return; } + ProcessRotationMapping(); user_.userData = nullptr; user_.callback = &HandleGravitySensorEventCallback; if (SubscribeSensor(SENSOR_TYPE_ID_GRAVITY, &user_) != 0) { - WLOGFE("Subscribe gravity sensor failed"); + WLOGFE("dms: Subscribe gravity sensor failed"); return; } SetBatch(SENSOR_TYPE_ID_GRAVITY, &user_, ORIENTATION_SENSOR_SAMPLING_RATE, ORIENTATION_SENSOR_REPORTING_RATE); SetMode(SENSOR_TYPE_ID_GRAVITY, &user_, SENSOR_ON_CHANGE); if (ActivateSensor(SENSOR_TYPE_ID_GRAVITY, &user_) != 0) { - WLOGFE("Activate gravity sensor failed"); + WLOGFE("dms: Activate gravity sensor failed"); return; } + currentDisplayRotation_ = GetCurrentDisplayRotation(); + lastSensorDecidedRotation_ = currentDisplayRotation_; + rotationLockedRotation_ = currentDisplayRotation_; isGravitySensorSubscribed_ = true; } @@ -75,8 +83,14 @@ void ScreenRotationController::UnsubscribeGravitySensor() WLOGFE("dms: Orientation Sensor is not subscribed"); return; } - DeactivateSensor(SENSOR_TYPE_ID_GRAVITY, &user_); - UnsubscribeSensor(SENSOR_TYPE_ID_GRAVITY, &user_); + if (DeactivateSensor(SENSOR_TYPE_ID_GRAVITY, &user_) != 0) { + WLOGFE("dms: Deactivate gravity sensor failed"); + return; + } + if (UnsubscribeSensor(SENSOR_TYPE_ID_GRAVITY, &user_) != 0) { + WLOGFE("dms: Unsubscribe gravity sensor failed"); + return; + } isGravitySensorSubscribed_ = false; } @@ -87,6 +101,9 @@ bool ScreenRotationController::IsScreenRotationLocked() void ScreenRotationController::SetScreenRotationLocked(bool isLocked) { + if (isLocked) { + rotationLockedRotation_ = GetCurrentDisplayRotation(); + } isScreenRotationLocked_ = isLocked; } @@ -97,9 +114,6 @@ void ScreenRotationController::SetDefaultDeviceRotationOffset(uint32_t defaultDe return; } defaultDeviceRotationOffset_ = defaultDeviceRotationOffset; - defaultLandscapeDisplayRotation_ = static_cast( - // divided by 90 to get bias, %4 to normalize the values into the range 0~3 - (static_cast(Rotation::ROTATION_90) + (defaultDeviceRotationOffset_ / 90)) % 4); } void ScreenRotationController::HandleGravitySensorEventCallback(SensorEvent *event) @@ -111,41 +125,29 @@ void ScreenRotationController::HandleGravitySensorEventCallback(SensorEvent *eve WLOGE("dms: Orientation Sensor Callback is not SENSOR_TYPE_ID_GRAVITY"); return; } - Orientation orientation = GetRequestedOrientation(); - currentDisplayRotation_ = GetCurrentDisplayRotation(); - HandleUnspecifiedOrientation(orientation); + Orientation orientation = GetPreferredOrientation(); if (!IsSensorRelatedOrientation(orientation)) { lastOrientationType_ = orientation; return; } - + + currentDisplayRotation_ = GetCurrentDisplayRotation(); GravityData* gravityData = reinterpret_cast(event->data); int sensorDegree = CalcRotationDegree(gravityData); - Rotation currentSensorRotation; - // Use ROTATION_0 when degree range is [0, 30]∪[330, 359] - if (sensorDegree >= 0 && (sensorDegree <= 30 || sensorDegree >= 330)) { - currentSensorRotation = Rotation::ROTATION_0; - } else if (sensorDegree >= 60 && sensorDegree <= 120) { // Use ROTATION_90 when degree range is [60, 120] - currentSensorRotation = Rotation::ROTATION_90; - } else if (sensorDegree >= 150 && sensorDegree <= 210) { // Use ROTATION_180 when degree range is [150, 210] - currentSensorRotation = Rotation::ROTATION_180; - } else if (sensorDegree >= 240 && sensorDegree <= 300) { // Use ROTATION_270 when degree range is [240, 300] - currentSensorRotation = Rotation::ROTATION_270; - } else { - ProcessRotationWhenSensorDataNotValid(orientation); - return; - } - lastOrientationType_ = orientation; - if ((ConvertToDeviceRotation(currentSensorRotation) == currentDisplayRotation_) && - (orientation == Orientation::SENSOR || orientation == Orientation::AUTO_ROTATION_RESTRICTED)) { + DeviceRotation sensorRotationConverted = ConvertSensorToDeviceRotation(CalcSensorRotation(sensorDegree)); + + // retrun true to continue, return false to end callback event. + if (!ProcessOrientationSwitch(orientation, sensorRotationConverted)) { return; } - Rotation targetDisplayRotation = CalcTargetDisplayRotation(orientation, currentSensorRotation); - if (targetDisplayRotation == currentDisplayRotation_) { + if (sensorRotationConverted == DeviceRotation::INVALID) { return; } - + if (currentDisplayRotation_ == ConvertDeviceToDisplayRotation(sensorRotationConverted)) { + return; + } + Rotation targetDisplayRotation = CalcTargetDisplayRotation(orientation, sensorRotationConverted); SetScreenRotation(targetDisplayRotation); } @@ -169,7 +171,7 @@ Rotation ScreenRotationController::GetCurrentDisplayRotation() return DisplayManagerServiceInner::GetInstance().GetDisplayById(defaultDisplayId_)->GetRotation(); } -Orientation ScreenRotationController::GetRequestedOrientation() +Orientation ScreenRotationController::GetPreferredOrientation() { Orientation orientation = Orientation::UNSPECIFIED; DisplayManagerServiceInner::GetInstance().GetWindowPreferredOrientation(defaultDisplayId_, orientation); @@ -177,36 +179,38 @@ Orientation ScreenRotationController::GetRequestedOrientation() } Rotation ScreenRotationController::CalcTargetDisplayRotation( - Orientation requestedOrientation, Rotation sensorRotation) + Orientation requestedOrientation, DeviceRotation sensorRotationConverted) { switch (requestedOrientation) { case Orientation::SENSOR: { - return ConvertToDeviceRotation(sensorRotation); + lastSensorDecidedRotation_ = ConvertDeviceToDisplayRotation(sensorRotationConverted); + return ConvertDeviceToDisplayRotation(sensorRotationConverted); } case Orientation::SENSOR_VERTICAL: { - return ProcessAutoRotationPortraitOrientation(sensorRotation); + return ProcessAutoRotationPortraitOrientation(sensorRotationConverted); } case Orientation::SENSOR_HORIZONTAL: { - return ProcessAutoRotationLandscapeOrientation(sensorRotation); + return ProcessAutoRotationLandscapeOrientation(sensorRotationConverted); } case Orientation::UNSPECIFIED: case Orientation::AUTO_ROTATION_RESTRICTED: { if (isScreenRotationLocked_) { return currentDisplayRotation_; } - return ConvertToDeviceRotation(sensorRotation); + lastSensorDecidedRotation_ = ConvertDeviceToDisplayRotation(sensorRotationConverted); + return ConvertDeviceToDisplayRotation(sensorRotationConverted); } case Orientation::AUTO_ROTATION_PORTRAIT_RESTRICTED: { if (isScreenRotationLocked_) { return currentDisplayRotation_; } - return ProcessAutoRotationPortraitOrientation(sensorRotation); + return ProcessAutoRotationPortraitOrientation(sensorRotationConverted); } case Orientation::AUTO_ROTATION_LANDSCAPE_RESTRICTED: { if (isScreenRotationLocked_) { return currentDisplayRotation_; } - return ProcessAutoRotationLandscapeOrientation(sensorRotation); + return ProcessAutoRotationLandscapeOrientation(sensorRotationConverted); } default: { return currentDisplayRotation_; @@ -214,34 +218,32 @@ Rotation ScreenRotationController::CalcTargetDisplayRotation( } } -Rotation ScreenRotationController::ProcessAutoRotationPortraitOrientation(Rotation sensorRotation) +Rotation ScreenRotationController::ProcessAutoRotationPortraitOrientation(DeviceRotation sensorRotationConverted) { - if (sensorRotation == Rotation::ROTATION_0 || sensorRotation == Rotation::ROTATION_180) { - return ConvertToDeviceRotation(sensorRotation); - } - if (currentDisplayRotation_ == ConvertToDeviceRotation(Rotation::ROTATION_0) || - currentDisplayRotation_ == ConvertToDeviceRotation(Rotation::ROTATION_180)) { + if (IsDeviceRotationHorizontal(sensorRotationConverted)) { return currentDisplayRotation_; } - return ConvertToDeviceRotation(Rotation::ROTATION_0); + lastSensorDecidedRotation_ = ConvertDeviceToDisplayRotation(sensorRotationConverted); + return ConvertDeviceToDisplayRotation(sensorRotationConverted); } -Rotation ScreenRotationController::ProcessAutoRotationLandscapeOrientation(Rotation sensorRotation) +Rotation ScreenRotationController::ProcessAutoRotationLandscapeOrientation(DeviceRotation sensorRotationConverted) { - if (sensorRotation == Rotation::ROTATION_90 || sensorRotation == Rotation::ROTATION_270) { - return ConvertToDeviceRotation(sensorRotation); - } - if (currentDisplayRotation_ == ConvertToDeviceRotation(Rotation::ROTATION_90) || - currentDisplayRotation_ == ConvertToDeviceRotation(Rotation::ROTATION_270)) { + if (IsDeviceRotationVertical(sensorRotationConverted)) { return currentDisplayRotation_; } - return defaultLandscapeDisplayRotation_; + lastSensorDecidedRotation_ = ConvertDeviceToDisplayRotation(sensorRotationConverted); + return ConvertDeviceToDisplayRotation(sensorRotationConverted); } void ScreenRotationController::SetScreenRotation(Rotation targetRotation) { + if (targetRotation == GetCurrentDisplayRotation()) { + return; + } DisplayManagerServiceInner::GetInstance().GetDefaultDisplay()->SetRotation(targetRotation); DisplayManagerServiceInner::GetInstance().SetRotationFromWindow(defaultDisplayId_, targetRotation); + WLOGFI("dms: Set screen rotation: %{public}u", targetRotation); } bool ScreenRotationController::CheckCallbackTimeInterval() @@ -256,15 +258,23 @@ bool ScreenRotationController::CheckCallbackTimeInterval() return true; } -Rotation ScreenRotationController::ConvertToDeviceRotation(Rotation sensorRotation) +DeviceRotation ScreenRotationController::CalcDeviceRotation(SensorRotation sensorRotation) { + if (sensorRotation == SensorRotation::INVALID) { + return DeviceRotation::INVALID; + } int32_t bias = defaultDeviceRotationOffset_ / 90; // offset(in degree) divided by 90 to get rotation bias int32_t deviceRotationValue = static_cast(sensorRotation) - bias; while (deviceRotationValue < 0) { // +4 is used to normalize the values into the range 0~3, corresponding to the four rotations. deviceRotationValue += 4; } - return static_cast(deviceRotationValue); + if (defaultDeviceRotation_ == 1) { + deviceRotationValue += defaultDeviceRotation_; + // if device's default rotation is landscape, swap 0 and 90, 180 and 270, use %2 to adjust range. + (deviceRotationValue % 2 == 0) && (deviceRotationValue -= 2); + } + return static_cast(deviceRotationValue); } bool ScreenRotationController::IsSensorRelatedOrientation(Orientation orientation) @@ -276,44 +286,162 @@ bool ScreenRotationController::IsSensorRelatedOrientation(Orientation orientatio return true; } -void ScreenRotationController::HandleUnspecifiedOrientation(Orientation orientation) +bool ScreenRotationController::ProcessOrientationSwitch(Orientation orientation, DeviceRotation sensorRotationConverted) { if (lastOrientationType_ == orientation) { - return; - } - if (orientation == Orientation::UNSPECIFIED && isScreenRotationLocked_) { - SetScreenRotation(Rotation::ROTATION_0); - lastOrientationType_ = orientation; - } -} - -void ScreenRotationController::ProcessRotationWhenSensorDataNotValid(Orientation orientation) -{ - if (lastOrientationType_ == orientation) { - return; + return true; } lastOrientationType_ = orientation; switch (orientation) { - case Orientation::SENSOR_VERTICAL: - case Orientation::AUTO_ROTATION_PORTRAIT_RESTRICTED: { - if (currentDisplayRotation_ == ConvertToDeviceRotation(Rotation::ROTATION_90) || - currentDisplayRotation_ == ConvertToDeviceRotation(Rotation::ROTATION_270)) { - SetScreenRotation(ConvertToDeviceRotation(Rotation::ROTATION_0)); + case Orientation::SENSOR: { + if (sensorRotationConverted != DeviceRotation::INVALID) { + return true; } - break; + SetScreenRotation(lastSensorDecidedRotation_); + return false; } - case Orientation::SENSOR_HORIZONTAL: - case Orientation::AUTO_ROTATION_LANDSCAPE_RESTRICTED: { - if (currentDisplayRotation_ == ConvertToDeviceRotation(Rotation::ROTATION_0) || - currentDisplayRotation_ == ConvertToDeviceRotation(Rotation::ROTATION_180)) { - SetScreenRotation(defaultLandscapeDisplayRotation_); + case Orientation::UNSPECIFIED: + case Orientation::AUTO_ROTATION_RESTRICTED: { + if (isScreenRotationLocked_) { + SetScreenRotation(rotationLockedRotation_); + } else { + if (sensorRotationConverted != DeviceRotation::INVALID) { + return true; + } + SetScreenRotation(lastSensorDecidedRotation_); } - break; + return false; + } + case Orientation::AUTO_ROTATION_PORTRAIT_RESTRICTED: { + if (isScreenRotationLocked_) { + if (IsCurrentDisplayVertical()) { + return false; + } + SetScreenRotation(ConvertDeviceToDisplayRotation(DeviceRotation::ROTATION_PORTRAIT)); + return false; + } + [[fallthrough]]; + } + case Orientation::SENSOR_VERTICAL: { + if (IsCurrentDisplayVertical()) { + return true; + } + if (IsDeviceRotationVertical(sensorRotationConverted)) { + return true; + } + SetScreenRotation(ConvertDeviceToDisplayRotation(DeviceRotation::ROTATION_PORTRAIT)); + return false; + } + case Orientation::AUTO_ROTATION_LANDSCAPE_RESTRICTED: { + if (isScreenRotationLocked_) { + if (IsCurrentDisplayHorizontal()) { + return false; + } + SetScreenRotation(ConvertDeviceToDisplayRotation(DeviceRotation::ROTATION_LANDSCAPE)); + return false; + } + [[fallthrough]]; + } + case Orientation::SENSOR_HORIZONTAL: { + if (IsCurrentDisplayHorizontal()) { + return true; + } + if (IsDeviceRotationHorizontal(sensorRotationConverted)) { + return true; + } + SetScreenRotation(ConvertDeviceToDisplayRotation(DeviceRotation::ROTATION_LANDSCAPE)); + return false; } default: { - return; + return true; } } } + +SensorRotation ScreenRotationController::CalcSensorRotation(int sensorDegree) +{ + // Use ROTATION_0 when degree range is [0, 30]∪[330, 359] + if (sensorDegree >= 0 && (sensorDegree <= 30 || sensorDegree >= 330)) { + return SensorRotation::ROTATION_0; + } else if (sensorDegree >= 60 && sensorDegree <= 120) { // Use ROTATION_90 when degree range is [60, 120] + return SensorRotation::ROTATION_90; + } else if (sensorDegree >= 150 && sensorDegree <= 210) { // Use ROTATION_180 when degree range is [150, 210] + return SensorRotation::ROTATION_180; + } else if (sensorDegree >= 240 && sensorDegree <= 300) { // Use ROTATION_270 when degree range is [240, 300] + return SensorRotation::ROTATION_270; + } else { + return SensorRotation::INVALID; + } +} + +DeviceRotation ScreenRotationController::ConvertSensorToDeviceRotation(SensorRotation sensorRotation) +{ + return sensorToDeviceRotationMap_.at(sensorRotation); +} + +Rotation ScreenRotationController::ConvertDeviceToDisplayRotation(DeviceRotation deviceRotation) +{ + if (deviceRotation == DeviceRotation::INVALID) { + return GetCurrentDisplayRotation(); + } + return deviceToDisplayRotationMap_.at(deviceRotation); +} + +void ScreenRotationController::ProcessRotationMapping() +{ + sptr modes = + DisplayManagerServiceInner::GetInstance().GetScreenModesByDisplayId(defaultDisplayId_); + defaultDeviceRotation_ = modes->width_ < modes->height_ ? 0 : 1; + if (deviceToDisplayRotationMap_.empty()) { + deviceToDisplayRotationMap_ = { + {DeviceRotation::ROTATION_PORTRAIT, + defaultDeviceRotation_ == 0 ? Rotation::ROTATION_0 : Rotation::ROTATION_90}, + {DeviceRotation::ROTATION_LANDSCAPE, + defaultDeviceRotation_ == 1 ? Rotation::ROTATION_0 : Rotation::ROTATION_90}, + {DeviceRotation::ROTATION_PORTRAIT_INVERTED, + defaultDeviceRotation_ == 0 ? Rotation::ROTATION_180 : Rotation::ROTATION_270}, + {DeviceRotation::ROTATION_LANDSCAPE_INVERTED, + defaultDeviceRotation_ == 1 ? Rotation::ROTATION_180 : Rotation::ROTATION_270}, + }; + } + if (sensorToDeviceRotationMap_.empty()) { + sensorToDeviceRotationMap_ = { + {SensorRotation::ROTATION_0, CalcDeviceRotation(SensorRotation::ROTATION_0)}, + {SensorRotation::ROTATION_90, CalcDeviceRotation(SensorRotation::ROTATION_90)}, + {SensorRotation::ROTATION_180, CalcDeviceRotation(SensorRotation::ROTATION_180)}, + {SensorRotation::ROTATION_270, CalcDeviceRotation(SensorRotation::ROTATION_270)}, + {SensorRotation::INVALID, DeviceRotation::INVALID}, + }; + } +} + +bool ScreenRotationController::IsDeviceRotationVertical(DeviceRotation deviceRotation) +{ + return (deviceRotation == DeviceRotation::ROTATION_PORTRAIT) || + (deviceRotation == DeviceRotation::ROTATION_PORTRAIT_INVERTED); +} + +bool ScreenRotationController::IsDeviceRotationHorizontal(DeviceRotation deviceRotation) +{ + return (deviceRotation == DeviceRotation::ROTATION_LANDSCAPE) || + (deviceRotation == DeviceRotation::ROTATION_LANDSCAPE_INVERTED); +} + +bool ScreenRotationController::IsCurrentDisplayVertical() +{ + return (currentDisplayRotation_ == ConvertDeviceToDisplayRotation(DeviceRotation::ROTATION_PORTRAIT)) || + (currentDisplayRotation_ == ConvertDeviceToDisplayRotation(DeviceRotation::ROTATION_PORTRAIT_INVERTED)); +} + +bool ScreenRotationController::IsCurrentDisplayHorizontal() +{ + return (currentDisplayRotation_ == ConvertDeviceToDisplayRotation(DeviceRotation::ROTATION_LANDSCAPE)) || + (currentDisplayRotation_ == ConvertDeviceToDisplayRotation(DeviceRotation::ROTATION_LANDSCAPE_INVERTED)); +} + +bool ScreenRotationController::IsGravitySensorEnabled() +{ + return isGravitySensorSubscribed_; +} } // Rosen } // OHOS \ No newline at end of file From bc55247326dea2f6cc3cfa47cc547f7014903887 Mon Sep 17 00:00:00 2001 From: xiaojianfeng Date: Mon, 4 Jul 2022 10:26:46 +0800 Subject: [PATCH 56/81] fix ui bug for float window when calling soft input keyboard Signed-off-by: xiaojianfeng Change-Id: I84c5f7bd55454c33a000354a667349978d53f4a9 --- wmserver/src/window_node_container.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/wmserver/src/window_node_container.cpp b/wmserver/src/window_node_container.cpp index 0a26923b..432ab94a 100644 --- a/wmserver/src/window_node_container.cpp +++ b/wmserver/src/window_node_container.cpp @@ -850,8 +850,7 @@ void WindowNodeContainer::NotifyIfKeyboardRegionChanged(const sptr& const WindowMode callingWindowMode = callingWindow->GetWindowMode(); if (callingWindowMode == WindowMode::WINDOW_MODE_FULLSCREEN || callingWindowMode == WindowMode::WINDOW_MODE_SPLIT_PRIMARY || - callingWindowMode == WindowMode::WINDOW_MODE_SPLIT_SECONDARY || - callingWindowMode == WindowMode::WINDOW_MODE_FLOATING) { + callingWindowMode == WindowMode::WINDOW_MODE_SPLIT_SECONDARY) { const Rect keyRect = node->GetWindowRect(); const Rect callingRect = callingWindow->GetWindowRect(); if (!WindowHelper::HasOverlap(callingRect, keyRect)) { From 973e3c96d200adb0cd5ebe7969f34651ca6d8993 Mon Sep 17 00:00:00 2001 From: l00574490 Date: Wed, 29 Jun 2022 18:27:13 +0800 Subject: [PATCH 57/81] =?UTF-8?q?=E5=BC=82=E5=B8=B8=E7=AA=97=E5=8F=A3?= =?UTF-8?q?=E6=A8=A1=E5=BC=8F=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: l00574490 Change-Id: I885b149cd2ee3423a194862ef18564ae2f0f521a --- interfaces/innerkits/wm/window.h | 1 + interfaces/innerkits/wm/wm_common.h | 1 + utils/include/window_helper.h | 29 ++++++++++++++++++-- utils/include/window_transition_info.h | 8 +++--- utils/include/wm_common_inner.h | 13 ++++----- utils/src/window_property.cpp | 11 ++++---- utils/src/window_transition_info.cpp | 6 ++--- wm/include/window_impl.h | 6 +++++ wm/src/window_impl.cpp | 37 +++++++++++++++----------- wmserver/include/starting_window.h | 7 +++-- wmserver/src/starting_window.cpp | 26 +++++++++++------- wmserver/src/window_controller.cpp | 8 ++++++ wmserver/src/window_layout_policy.cpp | 5 ++++ wmserver/src/window_pair.cpp | 20 +++++++++++--- 14 files changed, 128 insertions(+), 50 deletions(-) diff --git a/interfaces/innerkits/wm/window.h b/interfaces/innerkits/wm/window.h index 58e185ba..49f21431 100644 --- a/interfaces/innerkits/wm/window.h +++ b/interfaces/innerkits/wm/window.h @@ -59,6 +59,7 @@ public: virtual void AfterFocused() = 0; virtual void AfterUnfocused() = 0; virtual void ForegroundFailed() {} + virtual void ForegroundInvalidMode() {} virtual void AfterActive() {} virtual void AfterInactive() {} }; diff --git a/interfaces/innerkits/wm/wm_common.h b/interfaces/innerkits/wm/wm_common.h index 50f6dc65..83f8ff98 100644 --- a/interfaces/innerkits/wm/wm_common.h +++ b/interfaces/innerkits/wm/wm_common.h @@ -102,6 +102,7 @@ enum class WMError : int32_t { WM_ERROR_DESTROYED_OBJECT, WM_ERROR_DEATH_RECIPIENT, WM_ERROR_INVALID_WINDOW, + WM_ERROR_INVALID_WINDOW_MODE, WM_ERROR_INVALID_OPERATION, WM_ERROR_INVALID_PERMISSION, WM_ERROR_NO_REMOTE_ANIMATION, diff --git a/utils/include/window_helper.h b/utils/include/window_helper.h index e3e552c0..ff3be69c 100644 --- a/utils/include/window_helper.h +++ b/utils/include/window_helper.h @@ -17,8 +17,9 @@ #define OHOS_WM_INCLUDE_WM_HELPER_H #include -#include -#include +#include "ability_info.h" +#include "wm_common.h" +#include "wm_common_inner.h" namespace OHOS { namespace Rosen { @@ -181,6 +182,21 @@ public: } } + static void ConvertSupportModesToSupportInfo(uint32_t& modeSupportInfo, + const std::vector& supportModes) + { + for (auto& mode : supportModes) { + if (mode == AppExecFwk::SupportWindowMode::FULLSCREEN) { + modeSupportInfo |= WindowModeSupport::WINDOW_MODE_SUPPORT_FULLSCREEN; + } else if (mode == AppExecFwk::SupportWindowMode::SPLIT) { + modeSupportInfo |= (WindowModeSupport::WINDOW_MODE_SUPPORT_SPLIT_PRIMARY | + WindowModeSupport::WINDOW_MODE_SUPPORT_SPLIT_SECONDARY); + } else if (mode == AppExecFwk::SupportWindowMode::FLOATING) { + modeSupportInfo |= WindowModeSupport::WINDOW_MODE_SUPPORT_FLOATING; + } + } + } + static Rect GetFixedWindowRectByLimitSize(const Rect& oriDstRect, const Rect& lastRect, bool isVertical, float virtualPixelRatio) { @@ -358,6 +374,15 @@ public: return false; } + static bool IsInvalidWindowInTileLayoutMode(uint32_t supportModeInfo, WindowLayoutMode layoutMode) + { + if ((!IsWindowModeSupported(supportModeInfo, WindowMode::WINDOW_MODE_FLOATING)) && + (layoutMode == WindowLayoutMode::TILE)) { + return true; + } + return false; + } + private: WindowHelper() = default; ~WindowHelper() = default; diff --git a/utils/include/window_transition_info.h b/utils/include/window_transition_info.h index ad959acf..f2424a67 100644 --- a/utils/include/window_transition_info.h +++ b/utils/include/window_transition_info.h @@ -17,6 +17,8 @@ #define OHOS_ROSEN_WINDOW_TRANSITION_INFO_H #include #include + +#include "ability_info.h" #include "window_info.h" #include "wm_common.h" @@ -52,8 +54,8 @@ public: void SetWindowType(WindowType windowType); WindowType GetWindowType(); void SetShowFlagWhenLocked(bool isShow); - void SetWindowSupportModes(const std::vector supportModes); - std::vector GetWindowSupportModes(); + void SetWindowSupportModes(const std::vector supportModes); + std::vector GetWindowSupportModes(); bool GetShowFlagWhenLocked(); void SetTransitionReason(TransitionReason reason); TransitionReason GetTransitionReason(); @@ -70,7 +72,7 @@ private: bool isShowWhenLocked_ = false; bool isRecent_ = false; TransitionReason reason_ = TransitionReason::ABILITY_TRANSITION; - std::vector supportWindowModes_; + std::vector supportWindowModes_; }; } // Rosen } // OHOS diff --git a/utils/include/wm_common_inner.h b/utils/include/wm_common_inner.h index 18287c1f..2461417f 100644 --- a/utils/include/wm_common_inner.h +++ b/utils/include/wm_common_inner.h @@ -96,18 +96,19 @@ struct ModeChangeHotZonesConfig { }; struct WindowSizeLimits { + bool isSizeLimitsUpdated_; uint32_t maxWidth_; uint32_t maxHeight_; uint32_t minWidth_; uint32_t minHeight_; float maxRatio_; float minRatio_; - WindowSizeLimits() : maxWidth_(UINT32_MAX), maxHeight_(UINT32_MAX), minWidth_(0), - minHeight_(0), maxRatio_(FLT_MAX), minRatio_(0.0f) {} - WindowSizeLimits(uint32_t maxWidth, uint32_t maxHeight, uint32_t minWidth, - uint32_t minHeight, float maxRatio, float minRatio) - : maxWidth_(maxWidth), maxHeight_(maxHeight), minWidth_(minWidth), - minHeight_(minHeight), maxRatio_(maxRatio), minRatio_(minRatio) {} + WindowSizeLimits() : isSizeLimitsUpdated_(false), maxWidth_(UINT32_MAX), maxHeight_(UINT32_MAX), + minWidth_(0), minHeight_(0), maxRatio_(FLT_MAX), minRatio_(0.0f) {} + WindowSizeLimits(bool isSizeLimitsUpdated, uint32_t maxWidth, uint32_t maxHeight, + uint32_t minWidth, uint32_t minHeight, float maxRatio, float minRatio) + : isSizeLimitsUpdated_(isSizeLimitsUpdated), maxWidth_(maxWidth), maxHeight_(maxHeight), + minWidth_(minWidth), minHeight_(minHeight), maxRatio_(maxRatio), minRatio_(minRatio) {} }; struct ModeChangeHotZones { diff --git a/utils/src/window_property.cpp b/utils/src/window_property.cpp index 046c7ac3..fdf652d5 100644 --- a/utils/src/window_property.cpp +++ b/utils/src/window_property.cpp @@ -502,9 +502,10 @@ void WindowProperty::UnmarshallingTransform(Parcel& parcel, WindowProperty* prop bool WindowProperty::MarshallingWindowSizeLimits(Parcel& parcel) const { - if (parcel.WriteUint32(sizeLimits_.maxWidth_) && parcel.WriteUint32(sizeLimits_.maxHeight_) && - parcel.WriteUint32(sizeLimits_.minWidth_) && parcel.WriteUint32(sizeLimits_.minHeight_) && - parcel.WriteFloat(sizeLimits_.maxRatio_) && parcel.WriteFloat(sizeLimits_.minRatio_)) { + if (parcel.WriteBool(sizeLimits_.isSizeLimitsUpdated_) && parcel.WriteUint32(sizeLimits_.maxWidth_) && + parcel.WriteUint32(sizeLimits_.maxHeight_) && parcel.WriteUint32(sizeLimits_.minWidth_) && + parcel.WriteUint32(sizeLimits_.minHeight_) && parcel.WriteFloat(sizeLimits_.maxRatio_) && + parcel.WriteFloat(sizeLimits_.minRatio_)) { return true; } return false; @@ -512,8 +513,8 @@ bool WindowProperty::MarshallingWindowSizeLimits(Parcel& parcel) const void WindowProperty::UnmarshallingWindowSizeLimits(Parcel& parcel, WindowProperty* property) { - WindowSizeLimits sizeLimits = { parcel.ReadUint32(), parcel.ReadUint32(), parcel.ReadUint32(), parcel.ReadUint32(), - parcel.ReadFloat(), parcel.ReadFloat() }; + WindowSizeLimits sizeLimits = { parcel.ReadBool(), parcel.ReadUint32(), parcel.ReadUint32(), parcel.ReadUint32(), + parcel.ReadUint32(), parcel.ReadFloat(), parcel.ReadFloat() }; property->SetSizeLimits(sizeLimits); } diff --git a/utils/src/window_transition_info.cpp b/utils/src/window_transition_info.cpp index 6774fb1e..3a0d1bb4 100644 --- a/utils/src/window_transition_info.cpp +++ b/utils/src/window_transition_info.cpp @@ -26,7 +26,7 @@ WindowTransitionInfo::WindowTransitionInfo(sptr in displayId_ = info->displayId_; isShowWhenLocked_ = info->isShowWhenLocked_; isRecent_ = info->isRecent_; - supportWindowModes_ = { 0, 1, 2 }; // 0:fullScreen 1:split 2:floating + supportWindowModes_.assign(info->windowModes_.begin(), info->windowModes_.end()); } void WindowTransitionInfo::SetBundleName(std::string name) @@ -104,12 +104,12 @@ void WindowTransitionInfo::SetShowFlagWhenLocked(bool isShow) isShowWhenLocked_ = isShow; } -void WindowTransitionInfo::SetWindowSupportModes(const std::vector supportModes) +void WindowTransitionInfo::SetWindowSupportModes(const std::vector supportModes) { supportWindowModes_.assign(supportModes.begin(), supportModes.end()); } -std::vector WindowTransitionInfo::GetWindowSupportModes() +std::vector WindowTransitionInfo::GetWindowSupportModes() { return supportWindowModes_; } diff --git a/wm/include/window_impl.h b/wm/include/window_impl.h index f15d6bd1..78b96ea7 100644 --- a/wm/include/window_impl.h +++ b/wm/include/window_impl.h @@ -312,6 +312,12 @@ private: CALL_LIFECYCLE_LISTENER(ForegroundFailed); }); } + inline void NotifyForegroundInvalidWindowMode() + { + PostListenerTask([this]() { + CALL_LIFECYCLE_LISTENER(ForegroundInvalidMode); + }); + } void DestroyFloatingWindow(); void DestroySubWindow(); void SetDefaultOption(); // for api7 diff --git a/wm/src/window_impl.cpp b/wm/src/window_impl.cpp index 571f532c..888377c6 100644 --- a/wm/src/window_impl.cpp +++ b/wm/src/window_impl.cpp @@ -689,21 +689,12 @@ void WindowImpl::GetConfigurationFromAbilityInfo() // get support modes configuration uint32_t modeSupportInfo = 0; - const auto& supportModes = abilityInfo->windowModes; - for (auto& mode : supportModes) { - if (static_cast(mode) == static_cast(0)) { // 0 : fullScreen - modeSupportInfo |= WindowModeSupport::WINDOW_MODE_SUPPORT_FULLSCREEN; - } else if (static_cast(mode) == static_cast(1)) { // 1 : split - modeSupportInfo |= (WindowModeSupport::WINDOW_MODE_SUPPORT_SPLIT_PRIMARY | - WindowModeSupport::WINDOW_MODE_SUPPORT_SPLIT_SECONDARY); - } else if (static_cast(mode) == static_cast(2)) { // 2 : floating - modeSupportInfo |= WindowModeSupport::WINDOW_MODE_SUPPORT_FLOATING; - } - } + WindowHelper::ConvertSupportModesToSupportInfo(modeSupportInfo, abilityInfo->windowModes); if (modeSupportInfo == 0) { - WLOGFI("mode config param is 0, set all modes"); + WLOGFI("mode config param is 0, all modes is supported"); modeSupportInfo = WindowModeSupport::WINDOW_MODE_SUPPORT_ALL; } + WLOGFI("winId: %{public}u, modeSupportInfo: %{public}u", GetWindowId(), modeSupportInfo); SetRequestModeSupportInfo(modeSupportInfo); // get window size limits configuration @@ -734,6 +725,18 @@ void WindowImpl::GetConfigurationFromAbilityInfo() void WindowImpl::UpdateTitleButtonVisibility() { WLOGFI("[Client] UpdateTitleButtonVisibility"); + if (uiContent_ == nullptr || !isAppDecorEnable_) { + return; + } + auto modeSupportInfo = GetModeSupportInfo(); + bool hideSplitButton = !(modeSupportInfo & WindowModeSupport::WINDOW_MODE_SUPPORT_SPLIT_PRIMARY); + // not support fullscreen in split and floating mode, or not support float in fullscreen mode + bool hideMaximizeButton = (!(modeSupportInfo & WindowModeSupport::WINDOW_MODE_SUPPORT_FULLSCREEN) && + (GetMode() == WindowMode::WINDOW_MODE_FLOATING || WindowHelper::IsSplitWindowMode(GetMode()))) || + (!(modeSupportInfo & WindowModeSupport::WINDOW_MODE_SUPPORT_FLOATING) && + GetMode() == WindowMode::WINDOW_MODE_FULLSCREEN); + WLOGFI("[Client] [hideSplit, hideMaximize]: [%{public}d, %{public}d]", hideSplitButton, hideMaximizeButton); + uiContent_->HideWindowTitleButton(hideSplitButton, hideMaximizeButton, false); } WMError WindowImpl::Create(const std::string& parentName, const std::shared_ptr& context) @@ -966,9 +969,10 @@ WMError WindowImpl::Show(uint32_t reason, bool isCustomAnimation) bool isShowWhenLocked = GetWindowFlags() & static_cast(WindowFlag::WINDOW_FLAG_SHOW_WHEN_LOCKED); if (!WindowHelper::IsWindowModeSupported(GetModeSupportInfo(), GetMode()) || WindowHelper::IsOnlySupportSplitAndShowWhenLocked(isShowWhenLocked, GetModeSupportInfo())) { - WLOGFE("current mode is not be supported, windowId: %{public}u", property_->GetWindowId()); - NotifyForegroundFailed(); - return WMError::WM_ERROR_INVALID_WINDOW; + WLOGFE("current mode is not supported, windowId: %{public}u, modeSupportInfo: %{public}u, winMode: %{public}u", + property_->GetWindowId(), GetModeSupportInfo(), GetMode()); + NotifyForegroundInvalidWindowMode(); + return WMError::WM_ERROR_INVALID_WINDOW_MODE; } // update title button visibility when show @@ -979,6 +983,8 @@ WMError WindowImpl::Show(uint32_t reason, bool isCustomAnimation) if (ret == WMError::WM_OK || ret == WMError::WM_ERROR_DEATH_RECIPIENT) { state_ = WindowState::STATE_SHOWN; NotifyAfterForeground(); + } else if (ret == WMError::WM_ERROR_INVALID_WINDOW_MODE) { + NotifyForegroundInvalidWindowMode(); } else { NotifyForegroundFailed(); WLOGFE("show window id:%{public}u errCode:%{public}d", property_->GetWindowId(), static_cast(ret)); @@ -1678,6 +1684,7 @@ void WindowImpl::UpdateMode(WindowMode mode) { WLOGI("UpdateMode %{public}u", mode); property_->SetWindowMode(mode); + UpdateTitleButtonVisibility(); NotifyModeChange(mode); if (uiContent_ != nullptr) { uiContent_->UpdateWindowMode(mode); diff --git a/wmserver/include/starting_window.h b/wmserver/include/starting_window.h index da718e8a..93223a0b 100644 --- a/wmserver/include/starting_window.h +++ b/wmserver/include/starting_window.h @@ -30,7 +30,7 @@ public: StartingWindow() = delete; ~StartingWindow() = default; - static sptr CreateWindowNode(sptr info, + static sptr CreateWindowNode(const sptr& info, uint32_t winId, WindowLayoutMode layoutMode); static void HandleClientWindowCreate(sptr& node, sptr& window, uint32_t& windowId, const std::shared_ptr& surfaceNode, sptr& property, @@ -39,9 +39,12 @@ public: bool isColdStart); static void UpdateRSTree(sptr& node); static void ReleaseStartWinSurfaceNode(sptr& node); + private: - static SurfaceDraw surfaceDraw_; static WMError CreateLeashAndStartingSurfaceNode(sptr& node); + static bool NeedCancelStartingWindow(uint32_t modeSupportInfo, + WindowLayoutMode layoutMode, const sptr& info); + static SurfaceDraw surfaceDraw_; static std::recursive_mutex mutex_; }; } // Rosen diff --git a/wmserver/src/starting_window.cpp b/wmserver/src/starting_window.cpp index ca88a923..bd749752 100644 --- a/wmserver/src/starting_window.cpp +++ b/wmserver/src/starting_window.cpp @@ -32,7 +32,19 @@ SurfaceDraw StartingWindow::surfaceDraw_; static bool g_hasInit = false; std::recursive_mutex StartingWindow::mutex_; -sptr StartingWindow::CreateWindowNode(sptr info, +bool StartingWindow::NeedCancelStartingWindow(uint32_t modeSupportInfo, + WindowLayoutMode layoutMode, const sptr& info) +{ + if ((!WindowHelper::IsWindowModeSupported(modeSupportInfo, info->GetWindowMode())) || + (WindowHelper::IsInvalidWindowInTileLayoutMode(modeSupportInfo, layoutMode)) || + (WindowHelper::IsOnlySupportSplitAndShowWhenLocked(info->GetShowFlagWhenLocked(), modeSupportInfo))) { + WLOGFI("window mode is not be supported or not support floating mode in tile, cancel starting window"); + return true; + } + return false; +} + +sptr StartingWindow::CreateWindowNode(const sptr& info, uint32_t winId, WindowLayoutMode layoutMode) { sptr property = new(std::nothrow) WindowProperty(); @@ -40,16 +52,10 @@ sptr StartingWindow::CreateWindowNode(sptr inf return nullptr; } - uint32_t modeSupportInfo = 0; - for (auto mode : info->GetWindowSupportModes()) { - modeSupportInfo |= mode; - } - // if mode isn't be supported or don't support floating mode in tile mode, create starting window failed - if ((!WindowHelper::IsWindowModeSupported(modeSupportInfo, info->GetWindowMode())) || - ((!WindowHelper::IsWindowModeSupported(modeSupportInfo, WindowMode::WINDOW_MODE_FLOATING)) && - (layoutMode == WindowLayoutMode::TILE)) || - (WindowHelper::IsOnlySupportSplitAndShowWhenLocked(info->GetShowFlagWhenLocked(), modeSupportInfo))) { + uint32_t modeSupportInfo = 0; + WindowHelper::ConvertSupportModesToSupportInfo(modeSupportInfo, info->GetWindowSupportModes()); + if (NeedCancelStartingWindow(modeSupportInfo, layoutMode, info)) { WLOGFI("window mode is not be supported or not support floating mode in tile, cancel starting window"); return nullptr; } diff --git a/wmserver/src/window_controller.cpp b/wmserver/src/window_controller.cpp index 3bd19faa..483799c9 100644 --- a/wmserver/src/window_controller.cpp +++ b/wmserver/src/window_controller.cpp @@ -197,10 +197,18 @@ WMError WindowController::AddWindowNode(sptr& property) WLOGFE("could not find window"); return WMError::WM_ERROR_NULLPTR; } + if (node->currentVisibility_ && !node->startingWindowShown_) { WLOGFE("current window is visible, windowId: %{public}u", node->GetWindowId()); return WMError::WM_ERROR_INVALID_OPERATION; } + + auto layoutMode = windowRoot_->GetCurrentLayoutMode(property->GetDisplayId()); + if (WindowHelper::IsInvalidWindowInTileLayoutMode(node->GetModeSupportInfo(), layoutMode)) { + WLOGFE("window doesn't support floating mode in tile, windowId: %{public}u", node->GetWindowId()); + return WMError::WM_ERROR_INVALID_WINDOW_MODE; + } + // using starting window rect if client rect is empty if (WindowHelper::IsEmptyRect(property->GetRequestRect()) && node->startingWindowShown_) { // for tile and cascade property->SetRequestRect(node->GetRequestRect()); diff --git a/wmserver/src/window_layout_policy.cpp b/wmserver/src/window_layout_policy.cpp index 7e11e7cf..07fbc7e5 100644 --- a/wmserver/src/window_layout_policy.cpp +++ b/wmserver/src/window_layout_policy.cpp @@ -536,6 +536,10 @@ void WindowLayoutPolicy::UpdateWindowSizeLimits(const sptr& node) const auto& virtualPixelRatio = GetVirtualPixelRatio(node->GetDisplayId()); const auto& systemLimits = GetSystemSizeLimits(displayRect, virtualPixelRatio); const auto& customizedLimits = node->GetWindowSizeLimits(); + if (customizedLimits.isSizeLimitsUpdated_) { + WLOGFI("size limits have been updated"); + return; + } WindowSizeLimits newLimits = systemLimits; // configured limits of floating window @@ -580,6 +584,7 @@ void WindowLayoutPolicy::UpdateWindowSizeLimits(const sptr& node) uint32_t newMinHeight = static_cast(static_cast(newLimits.minWidth_) / newLimits.maxRatio_); newLimits.minHeight_ = std::max(newMinHeight, newLimits.minHeight_); + newLimits.isSizeLimitsUpdated_ = true; WLOGFI("maxWidth: %{public}u, maxHeight: %{public}u, minWidth: %{public}u, minHeight: %{public}u, " "maxRatio: %{public}f, minRatio: %{public}f", newLimits.maxWidth_, newLimits.maxHeight_, newLimits.minWidth_, newLimits.minHeight_, newLimits.maxRatio_, newLimits.minRatio_); diff --git a/wmserver/src/window_pair.cpp b/wmserver/src/window_pair.cpp index 7b853be6..0b5f32c7 100644 --- a/wmserver/src/window_pair.cpp +++ b/wmserver/src/window_pair.cpp @@ -192,15 +192,27 @@ void WindowPair::Clear() { WLOGI("Clear window pair."); DumpPairInfo(); + auto splitModeInfo = (WindowModeSupport::WINDOW_MODE_SUPPORT_SPLIT_PRIMARY | + WindowModeSupport::WINDOW_MODE_SUPPORT_SPLIT_SECONDARY); if (primary_ != nullptr && primary_->GetWindowProperty() != nullptr && primary_->GetWindowToken() != nullptr) { - primary_->GetWindowProperty()->ResumeLastWindowMode(); - primary_->GetWindowToken()->UpdateWindowMode(primary_->GetWindowMode()); + if (primary_->GetModeSupportInfo() == splitModeInfo) { + MinimizeApp::AddNeedMinimizeApp(primary_, MinimizeReason::SPLIT_QUIT); + MinimizeApp::ExecuteMinimizeTargetReason(MinimizeReason::SPLIT_QUIT); + } else { + primary_->GetWindowProperty()->ResumeLastWindowMode(); + primary_->GetWindowToken()->UpdateWindowMode(primary_->GetWindowMode()); + } } if (secondary_ != nullptr && secondary_->GetWindowProperty() != nullptr && secondary_->GetWindowToken() != nullptr) { - secondary_->GetWindowProperty()->ResumeLastWindowMode(); - secondary_->GetWindowToken()->UpdateWindowMode(secondary_->GetWindowMode()); + if (secondary_->GetModeSupportInfo() == splitModeInfo) { + MinimizeApp::AddNeedMinimizeApp(secondary_, MinimizeReason::SPLIT_QUIT); + MinimizeApp::ExecuteMinimizeTargetReason(MinimizeReason::SPLIT_QUIT); + } else { + secondary_->GetWindowProperty()->ResumeLastWindowMode(); + secondary_->GetWindowToken()->UpdateWindowMode(secondary_->GetWindowMode()); + } } primary_ = nullptr; secondary_ = nullptr; From e62f81ce877947c786b7d74a8291502e5ccccff7 Mon Sep 17 00:00:00 2001 From: xpeng Date: Mon, 4 Jul 2022 09:13:15 +0800 Subject: [PATCH 58/81] fix code check problem Signed-off-by: xpeng Change-Id: I525120a711f732290e04bcb145ffd5c6ac4a2388 --- dmserver/include/screen_rotation_controller.h | 24 ++-- dmserver/src/abstract_screen_controller.cpp | 4 +- dmserver/src/screen_rotation_controller.cpp | 131 +++++++++++------- 3 files changed, 101 insertions(+), 58 deletions(-) diff --git a/dmserver/include/screen_rotation_controller.h b/dmserver/include/screen_rotation_controller.h index 8793ee4d..cfe75e30 100644 --- a/dmserver/include/screen_rotation_controller.h +++ b/dmserver/include/screen_rotation_controller.h @@ -26,7 +26,6 @@ namespace OHOS { namespace Rosen { - enum class SensorRotation: int32_t { INVALID = -1, ROTATION_0 = 0, @@ -55,31 +54,40 @@ public: static bool IsGravitySensorEnabled(); private: static void HandleGravitySensorEventCallback(SensorEvent *event); + static bool CheckCallbackTimeInterval(); static Rotation GetCurrentDisplayRotation(); static Orientation GetPreferredOrientation(); + static void SetScreenRotation(Rotation targetRotation); static int CalcRotationDegree(GravityData* gravityData); static Rotation CalcTargetDisplayRotation(Orientation requestedOrientation, DeviceRotation sensorRotationConverted); - static Rotation ProcessAutoRotationPortraitOrientation(DeviceRotation sensorRotationConveted); - static Rotation ProcessAutoRotationLandscapeOrientation(DeviceRotation sensorRotationConveted); - static void SetScreenRotation(Rotation targetRotation); - static bool CheckCallbackTimeInterval(); static DeviceRotation CalcDeviceRotation(SensorRotation sensorRotation); - static bool ProcessOrientationSwitch(Orientation orientation, DeviceRotation deviceRotation); static SensorRotation CalcSensorRotation(int sensorDegree); static DeviceRotation ConvertSensorToDeviceRotation(SensorRotation sensorRotation); static Rotation ConvertDeviceToDisplayRotation(DeviceRotation sensorRotationConverted); - static void ProcessRotationMapping(); + static bool IsDeviceRotationVertical(DeviceRotation deviceRotation); static bool IsDeviceRotationHorizontal(DeviceRotation deviceRotation); static bool IsCurrentDisplayVertical(); static bool IsCurrentDisplayHorizontal(); + static bool IsDisplayRotationVertical(Rotation rotation); + static bool IsDisplayRotationHorizontal(Rotation rotation); static bool IsSensorRelatedOrientation(Orientation orientation); + + static void ProcessRotationMapping(); + static bool ProcessOrientationSwitch(Orientation orientation, DeviceRotation deviceRotation); + static bool ProcessSwitchToAutoRotationPortrait(DeviceRotation rotation); + static bool ProcessSwitchToAutoRotationLandscape(DeviceRotation rotation); + static bool ProcessSwitchToAutoRotation(DeviceRotation rotation); + static void ProcessSwitchToAutoRotationPortraitRestricted(); + static void ProcessSwitchToAutoRotationLandscapeRestricted(); + static Rotation ProcessAutoRotationPortraitOrientation(DeviceRotation sensorRotationConveted); + static Rotation ProcessAutoRotationLandscapeOrientation(DeviceRotation sensorRotationConveted); static DisplayId defaultDisplayId_; static SensorUser user_; static uint32_t defaultDeviceRotationOffset_; - static uint32_t defaultDeviceRotation_; // 0 means PORTRAIT, 1 means LANDSCAPE, use 0 in default. + static uint32_t defaultDeviceRotation_; static std::map sensorToDeviceRotationMap_; static std::map deviceToDisplayRotationMap_; static long lastCallbackTime_; diff --git a/dmserver/src/abstract_screen_controller.cpp b/dmserver/src/abstract_screen_controller.cpp index 673ff4ec..8283556f 100644 --- a/dmserver/src/abstract_screen_controller.cpp +++ b/dmserver/src/abstract_screen_controller.cpp @@ -621,11 +621,11 @@ bool AbstractScreenController::SetOrientation(ScreenId screenId, Orientation new WLOGI("skip setting orientation. screen %{public}" PRIu64" orientation %{public}u", screenId, newOrientation); return true; } - if ((newOrientation >= Orientation::VERTICAL+ && newOrientation <= Orientation::REVERSE_HORIZONTAL) || + if ((newOrientation >= Orientation::VERTICAL && newOrientation <= Orientation::REVERSE_HORIZONTAL) || (newOrientation == Orientation::UNSPECIFIED && !ScreenRotationController::IsGravitySensorEnabled())) { Rotation rotationAfter = screen->CalcRotation(newOrientation); SetRotation(screenId, rotationAfter, false); - screen->rotation_ = rotationAfter;; + screen->rotation_ = rotationAfter; } if (!screen->SetOrientation(newOrientation)) { diff --git a/dmserver/src/screen_rotation_controller.cpp b/dmserver/src/screen_rotation_controller.cpp index 8e65eb18..b38c44fe 100644 --- a/dmserver/src/screen_rotation_controller.cpp +++ b/dmserver/src/screen_rotation_controller.cpp @@ -40,12 +40,10 @@ uint32_t ScreenRotationController::defaultDeviceRotationOffset_ = 0; Orientation ScreenRotationController::lastOrientationType_ = Orientation::UNSPECIFIED; Rotation ScreenRotationController::lastSensorDecidedRotation_; Rotation ScreenRotationController::rotationLockedRotation_; - uint32_t ScreenRotationController::defaultDeviceRotation_ = 0; std::map ScreenRotationController::sensorToDeviceRotationMap_; std::map ScreenRotationController::deviceToDisplayRotationMap_; - void ScreenRotationController::SubscribeGravitySensor() { WLOGFI("dms: Subscribe gravity Sensor"); @@ -102,7 +100,7 @@ bool ScreenRotationController::IsScreenRotationLocked() void ScreenRotationController::SetScreenRotationLocked(bool isLocked) { if (isLocked) { - rotationLockedRotation_ = GetCurrentDisplayRotation(); + rotationLockedRotation_ = GetCurrentDisplayRotation(); } isScreenRotationLocked_ = isLocked; } @@ -135,12 +133,9 @@ void ScreenRotationController::HandleGravitySensorEventCallback(SensorEvent *eve GravityData* gravityData = reinterpret_cast(event->data); int sensorDegree = CalcRotationDegree(gravityData); DeviceRotation sensorRotationConverted = ConvertSensorToDeviceRotation(CalcSensorRotation(sensorDegree)); - - // retrun true to continue, return false to end callback event. if (!ProcessOrientationSwitch(orientation, sensorRotationConverted)) { return; } - if (sensorRotationConverted == DeviceRotation::INVALID) { return; } @@ -293,64 +288,36 @@ bool ScreenRotationController::ProcessOrientationSwitch(Orientation orientation, } lastOrientationType_ = orientation; switch (orientation) { - case Orientation::SENSOR: { - if (sensorRotationConverted != DeviceRotation::INVALID) { - return true; - } - SetScreenRotation(lastSensorDecidedRotation_); - return false; - } - case Orientation::UNSPECIFIED: + case Orientation::UNSPECIFIED: case Orientation::AUTO_ROTATION_RESTRICTED: { if (isScreenRotationLocked_) { SetScreenRotation(rotationLockedRotation_); - } else { - if (sensorRotationConverted != DeviceRotation::INVALID) { - return true; - } - SetScreenRotation(lastSensorDecidedRotation_); + return false; } - return false; + [[fallthrough]]; + } + case Orientation::SENSOR: { + return ProcessSwitchToAutoRotation(sensorRotationConverted); } case Orientation::AUTO_ROTATION_PORTRAIT_RESTRICTED: { if (isScreenRotationLocked_) { - if (IsCurrentDisplayVertical()) { - return false; - } - SetScreenRotation(ConvertDeviceToDisplayRotation(DeviceRotation::ROTATION_PORTRAIT)); + ProcessSwitchToAutoRotationPortraitRestricted(); return false; } [[fallthrough]]; } case Orientation::SENSOR_VERTICAL: { - if (IsCurrentDisplayVertical()) { - return true; - } - if (IsDeviceRotationVertical(sensorRotationConverted)) { - return true; - } - SetScreenRotation(ConvertDeviceToDisplayRotation(DeviceRotation::ROTATION_PORTRAIT)); - return false; + return ProcessSwitchToAutoRotationPortrait(sensorRotationConverted); } case Orientation::AUTO_ROTATION_LANDSCAPE_RESTRICTED: { if (isScreenRotationLocked_) { - if (IsCurrentDisplayHorizontal()) { - return false; - } - SetScreenRotation(ConvertDeviceToDisplayRotation(DeviceRotation::ROTATION_LANDSCAPE)); + ProcessSwitchToAutoRotationLandscapeRestricted(); return false; } [[fallthrough]]; } case Orientation::SENSOR_HORIZONTAL: { - if (IsCurrentDisplayHorizontal()) { - return true; - } - if (IsDeviceRotationHorizontal(sensorRotationConverted)) { - return true; - } - SetScreenRotation(ConvertDeviceToDisplayRotation(DeviceRotation::ROTATION_LANDSCAPE)); - return false; + return ProcessSwitchToAutoRotationLandscape(sensorRotationConverted); } default: { return true; @@ -358,6 +325,63 @@ bool ScreenRotationController::ProcessOrientationSwitch(Orientation orientation, } } +bool ScreenRotationController::ProcessSwitchToAutoRotation(DeviceRotation rotation) +{ + if (rotation != DeviceRotation::INVALID) { + return true; + } + SetScreenRotation(lastSensorDecidedRotation_); + return false; +} + +bool ScreenRotationController::ProcessSwitchToAutoRotationPortrait(DeviceRotation rotation) +{ + if (IsCurrentDisplayVertical()) { + return true; + } + if (IsDeviceRotationVertical(rotation)) { + return true; + } + SetScreenRotation(ConvertDeviceToDisplayRotation(DeviceRotation::ROTATION_PORTRAIT)); + return false; +} + +bool ScreenRotationController::ProcessSwitchToAutoRotationLandscape(DeviceRotation rotation) +{ + if (IsCurrentDisplayHorizontal()) { + return true; + } + if (IsDeviceRotationHorizontal(rotation)) { + return true; + } + SetScreenRotation(ConvertDeviceToDisplayRotation(DeviceRotation::ROTATION_LANDSCAPE)); + return false; +} + +void ScreenRotationController::ProcessSwitchToAutoRotationPortraitRestricted() +{ + if (IsCurrentDisplayVertical()) { + return; + } + if (IsDisplayRotationVertical(rotationLockedRotation_)) { + SetScreenRotation(rotationLockedRotation_); + return; + } + SetScreenRotation(ConvertDeviceToDisplayRotation(DeviceRotation::ROTATION_PORTRAIT)); +} + +void ScreenRotationController::ProcessSwitchToAutoRotationLandscapeRestricted() +{ + if (IsCurrentDisplayHorizontal()) { + return; + } + if (IsDisplayRotationHorizontal(rotationLockedRotation_)) { + SetScreenRotation(rotationLockedRotation_); + return; + } + SetScreenRotation(ConvertDeviceToDisplayRotation(DeviceRotation::ROTATION_LANDSCAPE)); +} + SensorRotation ScreenRotationController::CalcSensorRotation(int sensorDegree) { // Use ROTATION_0 when degree range is [0, 30]∪[330, 359] @@ -391,6 +415,7 @@ void ScreenRotationController::ProcessRotationMapping() { sptr modes = DisplayManagerServiceInner::GetInstance().GetScreenModesByDisplayId(defaultDisplayId_); + // 0 means PORTRAIT, 1 means LANDSCAPE. defaultDeviceRotation_ = modes->width_ < modes->height_ ? 0 : 1; if (deviceToDisplayRotationMap_.empty()) { deviceToDisplayRotationMap_ = { @@ -429,14 +454,24 @@ bool ScreenRotationController::IsDeviceRotationHorizontal(DeviceRotation deviceR bool ScreenRotationController::IsCurrentDisplayVertical() { - return (currentDisplayRotation_ == ConvertDeviceToDisplayRotation(DeviceRotation::ROTATION_PORTRAIT)) || - (currentDisplayRotation_ == ConvertDeviceToDisplayRotation(DeviceRotation::ROTATION_PORTRAIT_INVERTED)); + return IsDisplayRotationVertical(currentDisplayRotation_); } bool ScreenRotationController::IsCurrentDisplayHorizontal() { - return (currentDisplayRotation_ == ConvertDeviceToDisplayRotation(DeviceRotation::ROTATION_LANDSCAPE)) || - (currentDisplayRotation_ == ConvertDeviceToDisplayRotation(DeviceRotation::ROTATION_LANDSCAPE_INVERTED)); + return IsDisplayRotationHorizontal(currentDisplayRotation_); +} + +bool ScreenRotationController::IsDisplayRotationVertical(Rotation rotation) +{ + return (rotation == ConvertDeviceToDisplayRotation(DeviceRotation::ROTATION_PORTRAIT)) || + (rotation == ConvertDeviceToDisplayRotation(DeviceRotation::ROTATION_PORTRAIT_INVERTED)); +} + +bool ScreenRotationController::IsDisplayRotationHorizontal(Rotation rotation) +{ + return (rotation == ConvertDeviceToDisplayRotation(DeviceRotation::ROTATION_LANDSCAPE)) || + (rotation == ConvertDeviceToDisplayRotation(DeviceRotation::ROTATION_LANDSCAPE_INVERTED)); } bool ScreenRotationController::IsGravitySensorEnabled() From a25b45344f3ec7862e9d1d334cc92e60f858678e Mon Sep 17 00:00:00 2001 From: maojiangping Date: Mon, 4 Jul 2022 15:25:54 +0800 Subject: [PATCH 59/81] Fix an issue that application is closed instead of going back to the previous page. Signed-off-by: maojiangping Change-Id: Ic129feeddda753641f93d0a842af0db64a32c756 --- wm/src/window_impl.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/wm/src/window_impl.cpp b/wm/src/window_impl.cpp index d2b19927..8c7949cc 100644 --- a/wm/src/window_impl.cpp +++ b/wm/src/window_impl.cpp @@ -1713,6 +1713,9 @@ void WindowImpl::HandleBackKeyEvent(const std::shared_ptr& keyEve if (inputEventConsumer != nullptr) { WLOGFI("Transfer back key event to inputEventConsumer"); isConsumed = inputEventConsumer->OnInputEvent(keyEvent); + } else if (!inputEventListeners_.empty()) { + WLOGFI("inputEventListeners_ is not empty"); + return; } else if (uiContent_ != nullptr) { WLOGFI("Transfer back key event to uiContent"); isConsumed = uiContent_->ProcessBackPressed(); From accd184b0da35deff4edbc0ec3533c0f32167a2f Mon Sep 17 00:00:00 2001 From: xingyanan Date: Mon, 4 Jul 2022 16:00:08 +0800 Subject: [PATCH 60/81] =?UTF-8?q?=E5=88=86=E5=B1=8F=E5=90=AF=E5=8A=A8?= =?UTF-8?q?=E7=AA=97=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xingyanan Change-Id: I8855490ed62addd7afa135798e16823457e59a68 Signed-off-by: xingyanan --- interfaces/innerkits/wm/window.h | 2 +- interfaces/innerkits/wm/wm_common.h | 2 +- .../napi/window_runtime/window_napi/js_window_listener.cpp | 2 +- .../napi/window_runtime/window_napi/js_window_listener.h | 2 +- resources/config/rk3568/window_manager_config.xml | 2 +- utils/src/surface_draw.cpp | 6 +++--- wmserver/include/inner_window.h | 2 +- wmserver/src/inner_window.cpp | 2 +- 8 files changed, 10 insertions(+), 10 deletions(-) diff --git a/interfaces/innerkits/wm/window.h b/interfaces/innerkits/wm/window.h index 8ce88d05..7ca06962 100644 --- a/interfaces/innerkits/wm/window.h +++ b/interfaces/innerkits/wm/window.h @@ -131,7 +131,7 @@ public: class ITouchOutsideListener : virtual public RefBase { public: - virtual void OnTouchOutside() = 0; + virtual void OnTouchOutside() const = 0; }; class Window : public RefBase { diff --git a/interfaces/innerkits/wm/wm_common.h b/interfaces/innerkits/wm/wm_common.h index 3d652068..ae02c4dd 100644 --- a/interfaces/innerkits/wm/wm_common.h +++ b/interfaces/innerkits/wm/wm_common.h @@ -43,7 +43,6 @@ enum class WindowType : uint32_t { ABOVE_APP_SYSTEM_WINDOW_BASE = 2100, WINDOW_TYPE_APP_LAUNCHING = ABOVE_APP_SYSTEM_WINDOW_BASE, WINDOW_TYPE_DOCK_SLICE, - WINDOW_TYPE_PLACEHOLDER, WINDOW_TYPE_INCOMING_CALL, WINDOW_TYPE_SEARCHING_BAR, WINDOW_TYPE_SYSTEM_ALARM_WINDOW, @@ -63,6 +62,7 @@ enum class WindowType : uint32_t { WINDOW_TYPE_FREEZE_DISPLAY, WINDOW_TYPE_VOICE_INTERACTION, WINDOW_TYPE_FLOAT_CAMERA, + WINDOW_TYPE_PLACEHOLDER, ABOVE_APP_SYSTEM_WINDOW_END, SYSTEM_WINDOW_END = ABOVE_APP_SYSTEM_WINDOW_END, }; diff --git a/interfaces/kits/napi/window_runtime/window_napi/js_window_listener.cpp b/interfaces/kits/napi/window_runtime/window_napi/js_window_listener.cpp index 926627e3..e9e9954a 100644 --- a/interfaces/kits/napi/window_runtime/window_napi/js_window_listener.cpp +++ b/interfaces/kits/napi/window_runtime/window_napi/js_window_listener.cpp @@ -208,7 +208,7 @@ void JsWindowListener::OnSizeChange(const sptr& info) *engine_, std::make_unique(callback, std::move(execute), std::move(complete))); } -void JsWindowListener::OnTouchOutside() +void JsWindowListener::OnTouchOutside() const { std::unique_ptr complete = std::make_unique ( [self = weakRef_] (NativeEngine &engine, AsyncTask &task, int32_t status) { diff --git a/interfaces/kits/napi/window_runtime/window_napi/js_window_listener.h b/interfaces/kits/napi/window_runtime/window_napi/js_window_listener.h index e1d59458..617a1be2 100644 --- a/interfaces/kits/napi/window_runtime/window_napi/js_window_listener.h +++ b/interfaces/kits/napi/window_runtime/window_napi/js_window_listener.h @@ -58,7 +58,7 @@ public: void AfterFocused() override; void AfterUnfocused() override; void OnSizeChange(const sptr& info) override; - void OnTouchOutside() override; + void OnTouchOutside() const override; void CallJsMethod(const char* methodName, NativeValue* const* argv = nullptr, size_t argc = 0); private: void LifeCycleCallBack(LifeCycleEventType eventType); diff --git a/resources/config/rk3568/window_manager_config.xml b/resources/config/rk3568/window_manager_config.xml index a0489639..db2b08f9 100644 --- a/resources/config/rk3568/window_manager_config.xml +++ b/resources/config/rk3568/window_manager_config.xml @@ -15,7 +15,7 @@ --> - + 100 diff --git a/utils/src/surface_draw.cpp b/utils/src/surface_draw.cpp index 0cdc7827..cb6a44dc 100644 --- a/utils/src/surface_draw.cpp +++ b/utils/src/surface_draw.cpp @@ -165,7 +165,7 @@ bool SurfaceDraw::DoDraw(uint8_t *addr, uint32_t width, uint32_t height, const s { OHOS::Rosen::Drawing::Bitmap bitmap; OHOS::Rosen::Drawing::BitmapFormat format { OHOS::Rosen::Drawing::ColorType::COLORTYPE_RGBA_8888, - OHOS::Rosen::Drawing::AlphaType::ALPHATYPE_OPAQUYE }; + OHOS::Rosen::Drawing::AlphaType::ALPHATYPE_OPAQUE }; bitmap.Build(width, height, format); OHOS::Rosen::Drawing::Canvas canvas; canvas.Bind(bitmap); @@ -185,7 +185,7 @@ bool SurfaceDraw::DoDraw(uint8_t *addr, uint32_t width, uint32_t height, uint32_ { OHOS::Rosen::Drawing::Bitmap bitmap; OHOS::Rosen::Drawing::BitmapFormat format { OHOS::Rosen::Drawing::ColorType::COLORTYPE_RGBA_8888, - OHOS::Rosen::Drawing::AlphaType::ALPHATYPE_OPAQUYE }; + OHOS::Rosen::Drawing::AlphaType::ALPHATYPE_OPAQUE }; bitmap.Build(width, height, format); OHOS::Rosen::Drawing::Canvas canvas; canvas.Bind(bitmap); @@ -239,7 +239,7 @@ bool SurfaceDraw::DoDrawImageRect(uint8_t *addr, int32_t winWidth, int32_t winHe { OHOS::Rosen::Drawing::Bitmap bitmap; OHOS::Rosen::Drawing::BitmapFormat format { OHOS::Rosen::Drawing::ColorType::COLORTYPE_RGBA_8888, - OHOS::Rosen::Drawing::AlphaType::ALPHATYPE_OPAQUYE }; + OHOS::Rosen::Drawing::AlphaType::ALPHATYPE_OPAQUE }; bitmap.Build(winWidth, winHeight, format); OHOS::Rosen::Drawing::Canvas canvas; canvas.Bind(bitmap); diff --git a/wmserver/include/inner_window.h b/wmserver/include/inner_window.h index ec85ff94..3fb48622 100644 --- a/wmserver/include/inner_window.h +++ b/wmserver/include/inner_window.h @@ -31,7 +31,7 @@ public: class PlaceholderWindowListener : public IWindowLifeCycle, public ITouchOutsideListener, public IInputEventListener { public: // touch outside listener - virtual void OnTouchOutside(); + virtual void OnTouchOutside() const; // input event listener virtual void OnKeyEvent(std::shared_ptr& keyEvent); virtual void OnPointerInputEvent(std::shared_ptr& pointerEvent); diff --git a/wmserver/src/inner_window.cpp b/wmserver/src/inner_window.cpp index e5d1a0e2..5033e6e6 100644 --- a/wmserver/src/inner_window.cpp +++ b/wmserver/src/inner_window.cpp @@ -28,7 +28,7 @@ namespace { WM_IMPLEMENT_SINGLE_INSTANCE(PlaceHolderWindow) WM_IMPLEMENT_SINGLE_INSTANCE(DividerWindow) -void PlaceholderWindowListener::OnTouchOutside() +void PlaceholderWindowListener::OnTouchOutside() const { WLOGFD("place holder touch outside"); PlaceHolderWindow::GetInstance().Destroy(); From b3a0900f28a3a4d65b06232b6c00784a0a073ea8 Mon Sep 17 00:00:00 2001 From: sufeng6 Date: Mon, 4 Jul 2022 18:14:50 +0800 Subject: [PATCH 61/81] fix:change graphic_standard to graphic_graphic_2d Signed-off-by: sufeng6 --- bundle.json | 2 +- dmserver/BUILD.gn | 2 +- extension/window_extension/BUILD.gn | 2 +- utils/BUILD.gn | 2 +- wm/BUILD.gn | 4 ++-- wmserver/BUILD.gn | 4 ++-- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/bundle.json b/bundle.json index eda53562..c73bd4ba 100644 --- a/bundle.json +++ b/bundle.json @@ -25,7 +25,7 @@ "inputmethod_native", "sensor", "ability_base", - "graphic_standard", + "graphic_graphic_2d", "hisysevent_native", "ability_runtime", "napi", diff --git a/dmserver/BUILD.gn b/dmserver/BUILD.gn index 846ca4dc..288da229 100644 --- a/dmserver/BUILD.gn +++ b/dmserver/BUILD.gn @@ -58,7 +58,7 @@ ohos_shared_library("libdms") { external_deps = [ "access_token:libaccesstoken_sdk", "config_policy:configpolicy_util", - "graphic_standard:surface", + "graphic_graphic_2d:surface", "hilog_native:libhilog", "hitrace_native:hitrace_meter", "ipc:ipc_core", diff --git a/extension/window_extension/BUILD.gn b/extension/window_extension/BUILD.gn index d6121baf..47b496d8 100644 --- a/extension/window_extension/BUILD.gn +++ b/extension/window_extension/BUILD.gn @@ -56,7 +56,7 @@ ohos_shared_library("libwindow_extension") { "ability_runtime:ability_manager", "ability_runtime:abilitykit_native", "ability_runtime:runtime", - "graphic_standard:surface", + "graphic_graphic_2d:surface", "hilog_native:libhilog", "input:libmmi-client", "utils_base:utils", diff --git a/utils/BUILD.gn b/utils/BUILD.gn index a04be886..3808c317 100644 --- a/utils/BUILD.gn +++ b/utils/BUILD.gn @@ -60,7 +60,7 @@ ohos_shared_library("libwmutil") { external_deps = [ "ability_runtime:ability_manager", "access_token:libaccesstoken_sdk", - "graphic_standard:surface", + "graphic_graphic_2d:surface", "hilog_native:libhilog", "hitrace_native:hitrace_meter", "ipc:ipc_core", diff --git a/wm/BUILD.gn b/wm/BUILD.gn index b8f2ee18..e70d627c 100644 --- a/wm/BUILD.gn +++ b/wm/BUILD.gn @@ -76,8 +76,8 @@ ohos_shared_library("libwm") { "ace_engine:ace_uicontent", "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", - "graphic_standard:surface", - "graphic_standard:window_animation", + "graphic_graphic_2d:surface", + "graphic_graphic_2d:window_animation", "hilog_native:libhilog", "hisysevent_native:libhisysevent", "input:libmmi-client", diff --git a/wmserver/BUILD.gn b/wmserver/BUILD.gn index 6637bc4c..3f014e52 100644 --- a/wmserver/BUILD.gn +++ b/wmserver/BUILD.gn @@ -93,8 +93,8 @@ ohos_shared_library("libwms") { "common_event_service:cesfwk_innerkits", "config_policy:configpolicy_util", "display_manager_native:displaymgr", - "graphic_standard:surface", - "graphic_standard:window_animation", + "graphic_graphic_2d:surface", + "graphic_graphic_2d:window_animation", "hilog_native:libhilog", "hisysevent_native:libhisysevent", "hitrace_native:hitrace_meter", From 2de97043eb5b98898b5596892e34a87478f88284 Mon Sep 17 00:00:00 2001 From: l00574490 Date: Mon, 4 Jul 2022 18:30:51 +0800 Subject: [PATCH 62/81] set supported modes Signed-off-by: l00574490 Change-Id: I06ee4eb90d5c3a6331a355fea49ef8a758c6e3c2 --- utils/src/window_transition_info.cpp | 10 +++++++++- wm/test/systemtest/BUILD.gn | 2 -- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/utils/src/window_transition_info.cpp b/utils/src/window_transition_info.cpp index 3a0d1bb4..d95cf8b4 100644 --- a/utils/src/window_transition_info.cpp +++ b/utils/src/window_transition_info.cpp @@ -26,7 +26,15 @@ WindowTransitionInfo::WindowTransitionInfo(sptr in displayId_ = info->displayId_; isShowWhenLocked_ = info->isShowWhenLocked_; isRecent_ = info->isRecent_; - supportWindowModes_.assign(info->windowModes_.begin(), info->windowModes_.end()); + if (info->windowModes_.empty()) { + supportWindowModes_ = { + AppExecFwk::SupportWindowMode::FULLSCREEN, + AppExecFwk::SupportWindowMode::SPLIT, + AppExecFwk::SupportWindowMode::FLOATING + }; + } else { + supportWindowModes_.assign(info->windowModes_.begin(), info->windowModes_.end()); + } } void WindowTransitionInfo::SetBundleName(std::string name) diff --git a/wm/test/systemtest/BUILD.gn b/wm/test/systemtest/BUILD.gn index 5d2a0fcd..3b239fec 100644 --- a/wm/test/systemtest/BUILD.gn +++ b/wm/test/systemtest/BUILD.gn @@ -34,8 +34,6 @@ group("systemtest") { ":wm_window_multi_ability_test", ":wm_window_occupied_area_change_test", ":wm_window_rotation_test", - ":wm_window_split_immersive_test", - ":wm_window_split_test", ":wm_window_subwindow_test", ":wm_window_touch_outside_test", ":wm_window_visibility_info_test", From 7b41f80edae472d0beecd7271701adc62727171c Mon Sep 17 00:00:00 2001 From: xpeng Date: Mon, 4 Jul 2022 19:59:27 +0800 Subject: [PATCH 63/81] add logic to process sensor unrelated orientation Signed-off-by: xpeng Change-Id: If0e2bf067f81d965f3b90090ad877c00944a3a61 --- dmserver/include/screen_rotation_controller.h | 1 + dmserver/src/screen_rotation_controller.cpp | 31 ++++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/dmserver/include/screen_rotation_controller.h b/dmserver/include/screen_rotation_controller.h index cfe75e30..1d9071e8 100644 --- a/dmserver/include/screen_rotation_controller.h +++ b/dmserver/include/screen_rotation_controller.h @@ -81,6 +81,7 @@ private: static bool ProcessSwitchToAutoRotation(DeviceRotation rotation); static void ProcessSwitchToAutoRotationPortraitRestricted(); static void ProcessSwitchToAutoRotationLandscapeRestricted(); + static void ProcessSwitchToSensorUnrelatedOrientation(Orientation orientation); static Rotation ProcessAutoRotationPortraitOrientation(DeviceRotation sensorRotationConveted); static Rotation ProcessAutoRotationLandscapeOrientation(DeviceRotation sensorRotationConveted); diff --git a/dmserver/src/screen_rotation_controller.cpp b/dmserver/src/screen_rotation_controller.cpp index b38c44fe..3e363c54 100644 --- a/dmserver/src/screen_rotation_controller.cpp +++ b/dmserver/src/screen_rotation_controller.cpp @@ -125,7 +125,7 @@ void ScreenRotationController::HandleGravitySensorEventCallback(SensorEvent *eve } Orientation orientation = GetPreferredOrientation(); if (!IsSensorRelatedOrientation(orientation)) { - lastOrientationType_ = orientation; + ProcessSwitchToSensorUnrelatedOrientation(orientation); return; } @@ -478,5 +478,34 @@ bool ScreenRotationController::IsGravitySensorEnabled() { return isGravitySensorSubscribed_; } + +void ScreenRotationController::ProcessSwitchToSensorUnrelatedOrientation(Orientation orientation) +{ + if (lastOrientationType_ == orientation) { + return; + } + lastOrientationType_ = orientation; + switch (orientation) { + case Orientation::VERTICAL: { + SetScreenRotation(ConvertDeviceToDisplayRotation(DeviceRotation::ROTATION_PORTRAIT)); + break; + } + case Orientation::REVERSE_VERTICAL: { + SetScreenRotation(ConvertDeviceToDisplayRotation(DeviceRotation::ROTATION_PORTRAIT_INVERTED)); + break; + } + case Orientation::HORIZONTAL: { + SetScreenRotation(ConvertDeviceToDisplayRotation(DeviceRotation::ROTATION_LANDSCAPE)); + break; + } + case Orientation::REVERSE_HORIZONTAL: { + SetScreenRotation(ConvertDeviceToDisplayRotation(DeviceRotation::ROTATION_LANDSCAPE_INVERTED)); + break; + } + default: { + return; + } + } +} } // Rosen } // OHOS \ No newline at end of file From 97b9306d85bb530735bc427f27ef70b17d858674 Mon Sep 17 00:00:00 2001 From: zhoushicheng Date: Tue, 5 Jul 2022 10:41:08 +0800 Subject: [PATCH 64/81] =?UTF-8?q?ability=5Fruntime=E4=BB=93frameworks?= =?UTF-8?q?=E7=9B=AE=E5=BD=95=E6=95=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhoushicheng Change-Id: Id765896c71ac034d42e89659f82cb89478869b1c --- extension/window_extension/BUILD.gn | 2 +- windowmanager_aafwk.gni | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/extension/window_extension/BUILD.gn b/extension/window_extension/BUILD.gn index d6121baf..900cebb6 100644 --- a/extension/window_extension/BUILD.gn +++ b/extension/window_extension/BUILD.gn @@ -42,7 +42,7 @@ ohos_shared_library("libwindow_extension") { configs = [ ":libwindow_extension_private_config" ] deps = [ - "${ability_runtime_path}/frameworks/js/napi/aafwk/inner/napi_common:napi_common", + "${ability_runtime_napi_path}/inner/napi_common:napi_common", "${ability_runtime_path}/frameworks/native/appkit:app_context", "//foundation/graphic/graphic_2d/rosen/modules/render_service_client:librender_service_client", "//foundation/windowmanager/interfaces/kits/napi/window_runtime:window_native_kit", diff --git a/windowmanager_aafwk.gni b/windowmanager_aafwk.gni index 3bb6624d..09da8da2 100644 --- a/windowmanager_aafwk.gni +++ b/windowmanager_aafwk.gni @@ -15,4 +15,4 @@ ability_runtime_path = "//foundation/ability/ability_runtime" ability_runtime_inner_api_path = "${ability_runtime_path}/interfaces/inner_api" ability_runtime_kits_path = "${ability_runtime_path}/frameworks/kits" ability_runtime_services_path = "${ability_runtime_path}/services" -ability_runtime_napi_path = "${ability_runtime_path}/frameworks/js/napi/aafwk" +ability_runtime_napi_path = "${ability_runtime_path}/frameworks/js/napi" From 7b7aa4ffe5bf1bea9acdaf4352b529cf5cf8d475 Mon Sep 17 00:00:00 2001 From: chyyy0213 Date: Tue, 5 Jul 2022 12:43:25 +0800 Subject: [PATCH 65/81] add mode check for startingWindow Signed-off-by: chyyy0213 Change-Id: I98844166f19e3aa721870f26f2dd7ec8d169bfc8 --- wmserver/src/starting_window.cpp | 5 ++++- wmserver/src/window_controller.cpp | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/wmserver/src/starting_window.cpp b/wmserver/src/starting_window.cpp index 5ee378f3..97e96d00 100644 --- a/wmserver/src/starting_window.cpp +++ b/wmserver/src/starting_window.cpp @@ -59,7 +59,10 @@ sptr StartingWindow::CreateWindowNode(const sptrSetRequestRect(info->GetWindowRect()); - property->SetWindowMode(info->GetWindowMode()); + if (WindowHelper::IsValidWindowMode(info->GetWindowMode())) { + property->SetWindowMode(info->GetWindowMode()); + } + property->SetDisplayId(info->GetDisplayId()); property->SetWindowType(info->GetWindowType()); property->AddWindowFlag(WindowFlag::WINDOW_FLAG_NEED_AVOID); diff --git a/wmserver/src/window_controller.cpp b/wmserver/src/window_controller.cpp index 3c6c77ba..12379fe7 100644 --- a/wmserver/src/window_controller.cpp +++ b/wmserver/src/window_controller.cpp @@ -73,7 +73,9 @@ void WindowController::StartingWindow(sptr info, sptrGetWindowMode() != info->GetWindowMode()) { + + if (WindowHelper::IsValidWindowMode(info->GetWindowMode()) && + (node->GetWindowMode() != info->GetWindowMode())) { WLOGFW("set starting window mode. starting mode is: %{public}u, window mode is:%{public}u.", node->GetWindowMode(), info->GetWindowMode()); node->SetWindowMode(info->GetWindowMode()); From b2438fc05d7cfc3b0712236e899d2acdc7285c5d Mon Sep 17 00:00:00 2001 From: xingyanan Date: Tue, 5 Jul 2022 11:54:53 +0800 Subject: [PATCH 66/81] =?UTF-8?q?wms=E8=87=AA=E7=BB=98=E5=88=B6=E4=B8=8D?= =?UTF-8?q?=E5=86=8D=E4=BE=9D=E8=B5=96RenderContext?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xingyanan Change-Id: Idee2234c1ccaf6371db50d9ff864fed8e2359ab2 Signed-off-by: xingyanan --- utils/BUILD.gn | 6 - utils/include/surface_draw.h | 19 ++-- utils/src/surface_draw.cpp | 104 ++++++++++++++---- wmserver/BUILD.gn | 8 -- wmserver/include/freeze_controller.h | 18 +-- wmserver/src/freeze_controller.cpp | 94 +--------------- wmserver/src/window_layout_policy_cascade.cpp | 2 +- 7 files changed, 103 insertions(+), 148 deletions(-) diff --git a/utils/BUILD.gn b/utils/BUILD.gn index 6c867581..23e0a36f 100644 --- a/utils/BUILD.gn +++ b/utils/BUILD.gn @@ -12,7 +12,6 @@ # limitations under the License. import("//build/ohos.gni") -import("//foundation/graphic/graphic_2d/graphic_config.gni") config("libwmutil_private_config") { include_dirs = [ "include", @@ -20,10 +19,6 @@ config("libwmutil_private_config") { "../interfaces/innerkits/dm", "../interfaces/innerkits/wm", ] - defines = [] - - # Get gpu defines - defines += gpu_defines } config("libwmutil_public_config") { @@ -55,7 +50,6 @@ ohos_shared_library("libwmutil") { "//foundation/graphic/graphic_2d/rosen/modules/2d_graphics:2d_graphics", "//foundation/graphic/graphic_2d/rosen/modules/render_service_base:librender_service_base", "//foundation/graphic/graphic_2d/rosen/modules/render_service_client:librender_service_client", - "//third_party/flutter/build/skia:ace_skia_ohos", ] external_deps = [ diff --git a/utils/include/surface_draw.h b/utils/include/surface_draw.h index da7a8ceb..2b740766 100644 --- a/utils/include/surface_draw.h +++ b/utils/include/surface_draw.h @@ -31,20 +31,23 @@ class SurfaceDraw { public: SurfaceDraw() = default; ~SurfaceDraw() = default; - static bool DrawColor(std::shared_ptr surfaceNode, int32_t bufferWidth, + static bool DrawColor(std::shared_ptr surfaceNode, int32_t bufferWidth, int32_t bufferHeight, uint32_t color); - static bool DrawImage(std::shared_ptr surfaceNode, int32_t bufferWidth, + static bool DrawImage(std::shared_ptr surfaceNode, int32_t bufferWidth, int32_t bufferHeight, const std::string& imagePath); - static bool DrawImageRect(std::shared_ptr surfaceNode, Rect winRect, - sptr pixelMap, uint32_t bkgColor); + static bool DrawImage(std::shared_ptr surfaceNode, int32_t bufferWidth, + int32_t bufferHeight, std::shared_ptr pixelMap); + static bool DrawImageRect(std::shared_ptr surfaceNode, Rect winRect, sptr pixelMap, + uint32_t bkgColor); private: static bool DoDraw(uint8_t *addr, uint32_t width, uint32_t height, const std::string& imagePath); static bool DoDraw(uint8_t *addr, uint32_t width, uint32_t height, uint32_t color); - static sptr GetLayer(std::shared_ptr surfaceNode); - static sptr GetSurfaceBuffer(sptr layer, - int32_t bufferWidth, int32_t bufferHeight); - static void DrawPixelmap(OHOS::Rosen::Drawing::Canvas &canvas, const std::string& imagePath); + static bool DoDraw(uint8_t *addr, uint32_t width, uint32_t height, std::shared_ptr pixelMap); + static sptr GetLayer(std::shared_ptr surfaceNode); + static sptr GetSurfaceBuffer(sptr layer, int32_t bufferWidth, + int32_t bufferHeight); + static void DrawPixelmap(Drawing::Canvas &canvas, const std::string& imagePath); static std::unique_ptr DecodeImageToPixelMap(const std::string &imagePath); static bool DoDrawImageRect(uint8_t *addr, int32_t winWidth, int32_t winHeight, sptr pixelMap, uint32_t color); diff --git a/utils/src/surface_draw.cpp b/utils/src/surface_draw.cpp index cb6a44dc..ef0d794c 100644 --- a/utils/src/surface_draw.cpp +++ b/utils/src/surface_draw.cpp @@ -32,7 +32,7 @@ namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "SurfaceDraw"}; } // namespace -bool SurfaceDraw::DrawImage(std::shared_ptr surfaceNode, int32_t bufferWidth, +bool SurfaceDraw::DrawImage(std::shared_ptr surfaceNode, int32_t bufferWidth, int32_t bufferHeight, const std::string& imagePath) { sptr layer = GetLayer(surfaceNode); @@ -63,7 +63,38 @@ bool SurfaceDraw::DrawImage(std::shared_ptr surfaceN return true; } -bool SurfaceDraw::DrawColor(std::shared_ptr surfaceNode, int32_t bufferWidth, +bool SurfaceDraw::DrawImage(std::shared_ptr surfaceNode, int32_t bufferWidth, + int32_t bufferHeight, std::shared_ptr pixelMap) +{ + sptr layer = GetLayer(surfaceNode); + if (layer == nullptr) { + WLOGFE("layer is nullptr"); + return false; + } + sptr buffer = GetSurfaceBuffer(layer, bufferWidth, bufferHeight); + if (buffer == nullptr || buffer->GetVirAddr() == nullptr) { + return false; + } + auto addr = static_cast(buffer->GetVirAddr()); + if (!DoDraw(addr, buffer->GetWidth(), buffer->GetHeight(), pixelMap)) { + WLOGE("draw window pixel failed"); + return false; + } + OHOS::BufferFlushConfig flushConfig = { + .damage = { + .w = buffer->GetWidth(), + .h = buffer->GetHeight(), + }, + }; + OHOS::SurfaceError ret = layer->FlushBuffer(buffer, -1, flushConfig); + if (ret != OHOS::SurfaceError::SURFACE_ERROR_OK) { + WLOGFE("draw pointer FlushBuffer ret:%{public}s", SurfaceErrorStr(ret).c_str()); + return false; + } + return true; +} + +bool SurfaceDraw::DrawColor(std::shared_ptr surfaceNode, int32_t bufferWidth, int32_t bufferHeight, uint32_t color) { sptr layer = GetLayer(surfaceNode); @@ -94,7 +125,7 @@ bool SurfaceDraw::DrawColor(std::shared_ptr surfaceN return true; } -sptr SurfaceDraw::GetLayer(std::shared_ptr surfaceNode) +sptr SurfaceDraw::GetLayer(std::shared_ptr surfaceNode) { if (surfaceNode == nullptr) { return nullptr; @@ -145,17 +176,17 @@ std::unique_ptr SurfaceDraw::DecodeImageToPixelMap(const return pixelMap; } -void SurfaceDraw::DrawPixelmap(OHOS::Rosen::Drawing::Canvas &canvas, const std::string& imagePath) +void SurfaceDraw::DrawPixelmap(Drawing::Canvas &canvas, const std::string& imagePath) { std::unique_ptr pixelmap = DecodeImageToPixelMap(imagePath); if (pixelmap == nullptr) { WLOGFE("drawing pixel map is nullptr"); return; } - OHOS::Rosen::Drawing::Pen pen; + Drawing::Pen pen; pen.SetAntiAlias(true); - pen.SetColor(OHOS::Rosen::Drawing::Color::COLOR_BLUE); - OHOS::Rosen::Drawing::scalar penWidth = 1; + pen.SetColor(Drawing::Color::COLOR_BLUE); + Drawing::scalar penWidth = 1; pen.SetWidth(penWidth); canvas.AttachPen(pen); canvas.DrawBitmap(*pixelmap, 0, 0); @@ -163,13 +194,13 @@ void SurfaceDraw::DrawPixelmap(OHOS::Rosen::Drawing::Canvas &canvas, const std:: bool SurfaceDraw::DoDraw(uint8_t *addr, uint32_t width, uint32_t height, const std::string& imagePath) { - OHOS::Rosen::Drawing::Bitmap bitmap; - OHOS::Rosen::Drawing::BitmapFormat format { OHOS::Rosen::Drawing::ColorType::COLORTYPE_RGBA_8888, - OHOS::Rosen::Drawing::AlphaType::ALPHATYPE_OPAQUE }; + Drawing::Bitmap bitmap; + Drawing::BitmapFormat format { Drawing::ColorType::COLORTYPE_RGBA_8888, + Drawing::AlphaType::ALPHATYPE_OPAQUE }; bitmap.Build(width, height, format); - OHOS::Rosen::Drawing::Canvas canvas; + Drawing::Canvas canvas; canvas.Bind(bitmap); - canvas.Clear(OHOS::Rosen::Drawing::Color::COLOR_TRANSPARENT); + canvas.Clear(Drawing::Color::COLOR_TRANSPARENT); DrawPixelmap(canvas, imagePath); static constexpr uint32_t stride = 4; uint32_t addrSize = width * height * stride; @@ -181,13 +212,44 @@ bool SurfaceDraw::DoDraw(uint8_t *addr, uint32_t width, uint32_t height, const s return true; } +bool SurfaceDraw::DoDraw(uint8_t *addr, uint32_t width, uint32_t height, std::shared_ptr pixelMap) +{ + Drawing::Bitmap bitmap; + Drawing::Canvas canvas; + Drawing::BitmapFormat format { Drawing::ColorType::COLORTYPE_RGBA_8888, Drawing::AlphaType::ALPHATYPE_OPAQUE }; + bitmap.Build(width, height, format); + canvas.Bind(bitmap); + canvas.Clear(Drawing::Color::COLOR_TRANSPARENT); + + Drawing::Image image; + Drawing::Bitmap imageBitmap; + Drawing::SamplingOptions sampling = Drawing::SamplingOptions(Drawing::FilterMode::NEAREST, + Drawing::MipmapMode::NEAREST); + imageBitmap.Build(pixelMap->GetWidth(), pixelMap->GetHeight(), format); + imageBitmap.SetPixels(const_cast(pixelMap->GetPixels())); + image.BuildFromBitmap(imageBitmap); + + Drawing::Rect dst(0, 0, width, height); + Drawing::Rect src(0, 0, pixelMap->GetWidth(), pixelMap->GetHeight()); + canvas.DrawImageRect(image, src, dst, sampling); + + static constexpr uint32_t stride = 4; + uint32_t addrSize = width * height * stride; + errno_t ret = memcpy_s(addr, addrSize, bitmap.GetPixels(), addrSize); + if (ret != EOK) { + WLOGFE("draw failed"); + return false; + } + return true; +} + bool SurfaceDraw::DoDraw(uint8_t *addr, uint32_t width, uint32_t height, uint32_t color) { - OHOS::Rosen::Drawing::Bitmap bitmap; - OHOS::Rosen::Drawing::BitmapFormat format { OHOS::Rosen::Drawing::ColorType::COLORTYPE_RGBA_8888, - OHOS::Rosen::Drawing::AlphaType::ALPHATYPE_OPAQUE }; + Drawing::Bitmap bitmap; + Drawing::BitmapFormat format { Drawing::ColorType::COLORTYPE_RGBA_8888, + Drawing::AlphaType::ALPHATYPE_OPAQUE }; bitmap.Build(width, height, format); - OHOS::Rosen::Drawing::Canvas canvas; + Drawing::Canvas canvas; canvas.Bind(bitmap); canvas.Clear(color); @@ -237,11 +299,11 @@ bool SurfaceDraw::DrawImageRect(std::shared_ptr surfaceNode, Rect bool SurfaceDraw::DoDrawImageRect(uint8_t *addr, int32_t winWidth, int32_t winHeight, sptr pixelMap, uint32_t color) { - OHOS::Rosen::Drawing::Bitmap bitmap; - OHOS::Rosen::Drawing::BitmapFormat format { OHOS::Rosen::Drawing::ColorType::COLORTYPE_RGBA_8888, - OHOS::Rosen::Drawing::AlphaType::ALPHATYPE_OPAQUE }; + Drawing::Bitmap bitmap; + Drawing::BitmapFormat format { Drawing::ColorType::COLORTYPE_RGBA_8888, + Drawing::AlphaType::ALPHATYPE_OPAQUE }; bitmap.Build(winWidth, winHeight, format); - OHOS::Rosen::Drawing::Canvas canvas; + Drawing::Canvas canvas; canvas.Bind(bitmap); canvas.Clear(color); if (pixelMap == nullptr) { @@ -251,7 +313,7 @@ bool SurfaceDraw::DoDrawImageRect(uint8_t *addr, int32_t winWidth, int32_t winHe uint32_t iconHeight = pixelMap->GetHeight(); uint32_t iconWidth = pixelMap->GetWidth(); Drawing::Image image; - OHOS::Rosen::Drawing::Bitmap iconBitmap; + Drawing::Bitmap iconBitmap; iconBitmap.Build(iconWidth, iconHeight, format); iconBitmap.SetPixels(const_cast(pixelMap->GetPixels())); image.BuildFromBitmap(iconBitmap); diff --git a/wmserver/BUILD.gn b/wmserver/BUILD.gn index 7133c30e..c58f3fc0 100644 --- a/wmserver/BUILD.gn +++ b/wmserver/BUILD.gn @@ -12,9 +12,6 @@ # limitations under the License. import("//build/ohos.gni") -import("//foundation/graphic/graphic_2d/graphic_config.gni") - -## Build libwms.so config("libwms_config") { visibility = [ ":*" ] @@ -29,10 +26,6 @@ config("libwms_config") { "//foundation/windowmanager/dm/include", "//foundation/windowmanager/dmserver/include", ] - defines = [] - - # Get gpu defines - defines += gpu_defines } ohos_shared_library("libwms") { @@ -80,7 +73,6 @@ ohos_shared_library("libwms") { "//foundation/windowmanager/dmserver:libdms", "//foundation/windowmanager/utils:libwmutil", "//foundation/windowmanager/wm:libwm", - "//third_party/flutter/build/skia:ace_skia_ohos", "//third_party/libxml2:xml2", ] diff --git a/wmserver/include/freeze_controller.h b/wmserver/include/freeze_controller.h index 77203a22..d5c2ffd6 100644 --- a/wmserver/include/freeze_controller.h +++ b/wmserver/include/freeze_controller.h @@ -17,14 +17,7 @@ #define OHOS_ROSEN_FREEZE_CONTROLLER_H #include - -#include -#include -#ifdef ACE_ENABLE_GL -#include -#endif -#include -#include +#include #include "display.h" #include "window.h" @@ -33,7 +26,7 @@ namespace OHOS { namespace Rosen { class FreezeController : public RefBase { public: - FreezeController() {}; + FreezeController() = default; ~FreezeController() = default; bool FreezeDisplay(DisplayId displayId); @@ -41,14 +34,7 @@ public: private: sptr CreateCoverWindow(DisplayId displayId); - SkImageInfo MakeSkImageInfoFromPixelMap(std::shared_ptr& pixmap); - bool DrawSkImage(std::shared_ptr& rsSurface, - uint32_t width, uint32_t height, std::shared_ptr pixelMap); - std::map> coverWindowMap_; -#ifdef ACE_ENABLE_GL - std::unique_ptr renderContext_; -#endif }; } } diff --git a/wmserver/src/freeze_controller.cpp b/wmserver/src/freeze_controller.cpp index 69a22e8c..b5725196 100644 --- a/wmserver/src/freeze_controller.cpp +++ b/wmserver/src/freeze_controller.cpp @@ -17,11 +17,9 @@ #include -#include -#include -#include - #include "display_manager_service_inner.h" +#include "pixel_map.h" +#include "surface_draw.h" #include "window_manager_hilog.h" #include "window_option.h" #include "wm_common.h" @@ -44,39 +42,13 @@ bool FreezeController::FreezeDisplay(DisplayId displayId) WLOGFE("Show window failed"); return false; } - -#ifdef ACE_ENABLE_GL - if (renderContext_ == nullptr) { - renderContext_ = std::make_unique(); - renderContext_->InitializeEglContext(); - } -#endif - - std::shared_ptr surfaceNode = window->GetSurfaceNode(); - if (surfaceNode == nullptr) { - WLOGFE("RSSurfaceNode is null"); - return false; - } - Rect winRect = window->GetRect(); - WLOGFI("freeze window rect, x : %{public}d, y : %{public}d, width: %{public}u, height: %{public}u", - winRect.posX_, winRect.posY_, winRect.width_, winRect.height_); - - std::shared_ptr rsSurface = RSSurfaceExtractor::ExtractRSSurface(surfaceNode); - if (rsSurface == nullptr) { - WLOGFE("RSSurface is null"); - return false; - } - -#ifdef ACE_ENABLE_GL - rsSurface->SetRenderContext(renderContext_.get()); -#endif - std::shared_ptr pixelMap = DisplayManagerServiceInner::GetInstance().GetDisplaySnapshot(displayId); if (pixelMap == nullptr) { WLOGE("freeze display fail, pixel map is null. display %{public}" PRIu64"", displayId); return false; } - return DrawSkImage(rsSurface, winRect.width_, winRect.height_, pixelMap); + return SurfaceDraw::DrawImage(window->GetSurfaceNode(), window->GetRect().width_, + window->GetRect().height_, pixelMap); } bool FreezeController::UnfreezeDisplay(DisplayId displayId) @@ -113,59 +85,5 @@ sptr FreezeController::CreateCoverWindow(DisplayId displayId) coverWindowMap_[displayId] = window; return window; } - -bool FreezeController::DrawSkImage(std::shared_ptr& rsSurface, - uint32_t width, uint32_t height, std::shared_ptr pixelmap) -{ - // Get canvas - WLOGFD("start to draw bitmap"); - std::unique_ptr frame = rsSurface->RequestFrame(width, height); - if (frame == nullptr) { - WLOGFE("fail to request frame"); - return false; - } - auto canvas = frame->GetCanvas(); - if (canvas == nullptr) { - WLOGFE("fail to get canvas"); - return false; - } - canvas->clear(SK_ColorTRANSPARENT); - - // Create SkPixmap from PixelMap - auto imageInfo = MakeSkImageInfoFromPixelMap(pixelmap); - SkPixmap imagePixmap(imageInfo, reinterpret_cast(pixelmap->GetPixels()), pixelmap->GetRowBytes()); - - // Create SkImage from SkPixmap - sk_sp skImage = SkImage::MakeFromRaster(imagePixmap, nullptr, nullptr); - if (!skImage) { - WLOGFE("sk image is null"); - return false; - } - - SkPaint paint; - sk_sp colorSpace = skImage->refColorSpace(); -#ifdef USE_SYSTEM_SKIA - paint.setColor4f(paint.getColor4f(), colorSpace.get()); -#else - paint.setColor(paint.getColor4f(), colorSpace.get()); -#endif - auto skSrcRect = SkRect::MakeXYWH(0, 0, pixelmap->GetWidth(), pixelmap->GetHeight()); - auto skDstRect = SkRect::MakeXYWH(0, 0, width, height); - canvas->drawImageRect(skImage, skSrcRect, skDstRect, &paint); - frame->SetDamageRegion(0, 0, width, height); - if (!rsSurface->FlushFrame(frame)) { - WLOGFE("fail to flush frame"); - return false; - } - return true; -} - -SkImageInfo FreezeController::MakeSkImageInfoFromPixelMap(std::shared_ptr& pixmap) -{ - SkColorType colorType = kN32_SkColorType; - SkAlphaType alphaType = SkAlphaType::kOpaque_SkAlphaType; - sk_sp colorSpace = SkColorSpace::MakeSRGB(); - return SkImageInfo::Make(pixmap->GetWidth(), pixmap->GetHeight(), colorType, alphaType, colorSpace); -} -} -} \ No newline at end of file +} // Rosen +} // OHOS \ No newline at end of file diff --git a/wmserver/src/window_layout_policy_cascade.cpp b/wmserver/src/window_layout_policy_cascade.cpp index e0a68fc0..4e766fb3 100644 --- a/wmserver/src/window_layout_policy_cascade.cpp +++ b/wmserver/src/window_layout_policy_cascade.cpp @@ -515,7 +515,7 @@ Rect WindowLayoutPolicyCascade::GetCurCascadeRect(const sptr& node) (*iter)->GetWindowId() != node->GetWindowId()) { auto property = (*iter)->GetWindowProperty(); if (property != nullptr) { - cascadeRect = property->GetRequestRect(); + cascadeRect = property->GetWindowRect(); } WLOGFI("Get current cascadeRect: %{public}u [%{public}d, %{public}d, %{public}u, %{public}u]", (*iter)->GetWindowId(), cascadeRect.posX_, cascadeRect.posY_, From 3a6e73f1f0536cf2b7e329e40796832ead1da612 Mon Sep 17 00:00:00 2001 From: xpeng Date: Tue, 5 Jul 2022 19:23:52 +0800 Subject: [PATCH 67/81] optimize orientation switch logic Signed-off-by: xpeng Change-Id: Ib1f1f5e5a76584c0f5784241366088f1ee741564 --- dmserver/include/screen_rotation_controller.h | 10 ++- dmserver/src/abstract_screen_controller.cpp | 13 +-- dmserver/src/screen_rotation_controller.cpp | 79 +++++++++++-------- 3 files changed, 58 insertions(+), 44 deletions(-) diff --git a/dmserver/include/screen_rotation_controller.h b/dmserver/include/screen_rotation_controller.h index 1d9071e8..22e72c80 100644 --- a/dmserver/include/screen_rotation_controller.h +++ b/dmserver/include/screen_rotation_controller.h @@ -52,6 +52,7 @@ public: static void SetScreenRotationLocked(bool isLocked); static void SetDefaultDeviceRotationOffset(uint32_t defaultDeviceRotationOffset); static bool IsGravitySensorEnabled(); + static void ProcessOrientationSwitch(Orientation orientation); private: static void HandleGravitySensorEventCallback(SensorEvent *event); static bool CheckCallbackTimeInterval(); @@ -75,12 +76,12 @@ private: static bool IsSensorRelatedOrientation(Orientation orientation); static void ProcessRotationMapping(); - static bool ProcessOrientationSwitch(Orientation orientation, DeviceRotation deviceRotation); - static bool ProcessSwitchToAutoRotationPortrait(DeviceRotation rotation); - static bool ProcessSwitchToAutoRotationLandscape(DeviceRotation rotation); - static bool ProcessSwitchToAutoRotation(DeviceRotation rotation); + static void ProcessSwitchToAutoRotationPortrait(DeviceRotation rotation); + static void ProcessSwitchToAutoRotationLandscape(DeviceRotation rotation); + static void ProcessSwitchToAutoRotation(DeviceRotation rotation); static void ProcessSwitchToAutoRotationPortraitRestricted(); static void ProcessSwitchToAutoRotationLandscapeRestricted(); + static void ProcessSwitchToSensorRelatedOrientation(Orientation orientation, DeviceRotation deviceRotation); static void ProcessSwitchToSensorUnrelatedOrientation(Orientation orientation); static Rotation ProcessAutoRotationPortraitOrientation(DeviceRotation sensorRotationConveted); static Rotation ProcessAutoRotationLandscapeOrientation(DeviceRotation sensorRotationConveted); @@ -98,6 +99,7 @@ private: static Rotation rotationLockedRotation_; static bool isGravitySensorSubscribed_; static bool isScreenRotationLocked_; + static DeviceRotation lastSensorRotationConverted_; }; } // Rosen } // OHOS diff --git a/dmserver/src/abstract_screen_controller.cpp b/dmserver/src/abstract_screen_controller.cpp index 8283556f..b064ab6a 100644 --- a/dmserver/src/abstract_screen_controller.cpp +++ b/dmserver/src/abstract_screen_controller.cpp @@ -611,22 +611,17 @@ bool AbstractScreenController::SetOrientation(ScreenId screenId, Orientation new return false; } if (isFromWindow) { - if (newOrientation == Orientation::UNSPECIFIED) { - newOrientation = screen->screenRequestedOrientation_; - } + ScreenRotationController::ProcessOrientationSwitch(newOrientation); } else { screen->screenRequestedOrientation_ = newOrientation; + Rotation rotationAfter = screen->CalcRotation(newOrientation); + SetRotation(screenId, rotationAfter, false); + screen->rotation_ = rotationAfter; } if (screen->orientation_ == newOrientation) { WLOGI("skip setting orientation. screen %{public}" PRIu64" orientation %{public}u", screenId, newOrientation); return true; } - if ((newOrientation >= Orientation::VERTICAL && newOrientation <= Orientation::REVERSE_HORIZONTAL) || - (newOrientation == Orientation::UNSPECIFIED && !ScreenRotationController::IsGravitySensorEnabled())) { - Rotation rotationAfter = screen->CalcRotation(newOrientation); - SetRotation(screenId, rotationAfter, false); - screen->rotation_ = rotationAfter; - } if (!screen->SetOrientation(newOrientation)) { WLOGE("fail to set rotation, screen %{public}" PRIu64"", screenId); diff --git a/dmserver/src/screen_rotation_controller.cpp b/dmserver/src/screen_rotation_controller.cpp index 3e363c54..cb09fa43 100644 --- a/dmserver/src/screen_rotation_controller.cpp +++ b/dmserver/src/screen_rotation_controller.cpp @@ -43,6 +43,7 @@ Rotation ScreenRotationController::rotationLockedRotation_; uint32_t ScreenRotationController::defaultDeviceRotation_ = 0; std::map ScreenRotationController::sensorToDeviceRotationMap_; std::map ScreenRotationController::deviceToDisplayRotationMap_; +DeviceRotation ScreenRotationController::lastSensorRotationConverted_ = DeviceRotation::INVALID; void ScreenRotationController::SubscribeGravitySensor() { @@ -124,16 +125,13 @@ void ScreenRotationController::HandleGravitySensorEventCallback(SensorEvent *eve return; } Orientation orientation = GetPreferredOrientation(); - if (!IsSensorRelatedOrientation(orientation)) { - ProcessSwitchToSensorUnrelatedOrientation(orientation); - return; - } currentDisplayRotation_ = GetCurrentDisplayRotation(); GravityData* gravityData = reinterpret_cast(event->data); int sensorDegree = CalcRotationDegree(gravityData); DeviceRotation sensorRotationConverted = ConvertSensorToDeviceRotation(CalcSensorRotation(sensorDegree)); - if (!ProcessOrientationSwitch(orientation, sensorRotationConverted)) { + lastSensorRotationConverted_ = sensorRotationConverted; + if (!IsSensorRelatedOrientation(orientation)) { return; } if (sensorRotationConverted == DeviceRotation::INVALID) { @@ -163,14 +161,23 @@ int ScreenRotationController::CalcRotationDegree(GravityData* gravityData) Rotation ScreenRotationController::GetCurrentDisplayRotation() { - return DisplayManagerServiceInner::GetInstance().GetDisplayById(defaultDisplayId_)->GetRotation(); + sptr defaultDisplayInfo = DisplayManagerServiceInner::GetInstance().GetDefaultDisplay(); + if (defaultDisplayInfo == nullptr) { + WLOGFE("Cannot get default display info"); + return defaultDeviceRotation_ == 0 ? ConvertDeviceToDisplayRotation(DeviceRotation::ROTATION_PORTRAIT) : + ConvertDeviceToDisplayRotation(DeviceRotation::ROTATION_LANDSCAPE); + } + return defaultDisplayInfo->GetRotation(); } Orientation ScreenRotationController::GetPreferredOrientation() { - Orientation orientation = Orientation::UNSPECIFIED; - DisplayManagerServiceInner::GetInstance().GetWindowPreferredOrientation(defaultDisplayId_, orientation); - return orientation; + sptr screenInfo = DisplayManagerServiceInner::GetInstance().GetScreenInfoByDisplayId(defaultDisplayId_); + if (screenInfo == nullptr) { + WLOGFE("Cannot get default screen info"); + return Orientation::UNSPECIFIED; + } + return screenInfo->GetOrientation(); } Rotation ScreenRotationController::CalcTargetDisplayRotation( @@ -281,10 +288,11 @@ bool ScreenRotationController::IsSensorRelatedOrientation(Orientation orientatio return true; } -bool ScreenRotationController::ProcessOrientationSwitch(Orientation orientation, DeviceRotation sensorRotationConverted) +void ScreenRotationController::ProcessSwitchToSensorRelatedOrientation( + Orientation orientation, DeviceRotation sensorRotationConverted) { if (lastOrientationType_ == orientation) { - return true; + return; } lastOrientationType_ = orientation; switch (orientation) { @@ -292,70 +300,70 @@ bool ScreenRotationController::ProcessOrientationSwitch(Orientation orientation, case Orientation::AUTO_ROTATION_RESTRICTED: { if (isScreenRotationLocked_) { SetScreenRotation(rotationLockedRotation_); - return false; + return; } [[fallthrough]]; } case Orientation::SENSOR: { - return ProcessSwitchToAutoRotation(sensorRotationConverted); + ProcessSwitchToAutoRotation(sensorRotationConverted); + return; } case Orientation::AUTO_ROTATION_PORTRAIT_RESTRICTED: { if (isScreenRotationLocked_) { ProcessSwitchToAutoRotationPortraitRestricted(); - return false; + return; } [[fallthrough]]; } case Orientation::SENSOR_VERTICAL: { - return ProcessSwitchToAutoRotationPortrait(sensorRotationConverted); + ProcessSwitchToAutoRotationPortrait(sensorRotationConverted); + return; } case Orientation::AUTO_ROTATION_LANDSCAPE_RESTRICTED: { if (isScreenRotationLocked_) { ProcessSwitchToAutoRotationLandscapeRestricted(); - return false; + return; } [[fallthrough]]; } case Orientation::SENSOR_HORIZONTAL: { - return ProcessSwitchToAutoRotationLandscape(sensorRotationConverted); + ProcessSwitchToAutoRotationLandscape(sensorRotationConverted); + return; } default: { - return true; + return; } } } -bool ScreenRotationController::ProcessSwitchToAutoRotation(DeviceRotation rotation) +void ScreenRotationController::ProcessSwitchToAutoRotation(DeviceRotation rotation) { if (rotation != DeviceRotation::INVALID) { - return true; + return; } SetScreenRotation(lastSensorDecidedRotation_); - return false; } -bool ScreenRotationController::ProcessSwitchToAutoRotationPortrait(DeviceRotation rotation) +void ScreenRotationController::ProcessSwitchToAutoRotationPortrait(DeviceRotation rotation) { if (IsCurrentDisplayVertical()) { - return true; + return; } if (IsDeviceRotationVertical(rotation)) { - return true; + return; } SetScreenRotation(ConvertDeviceToDisplayRotation(DeviceRotation::ROTATION_PORTRAIT)); - return false; } -bool ScreenRotationController::ProcessSwitchToAutoRotationLandscape(DeviceRotation rotation) +void ScreenRotationController::ProcessSwitchToAutoRotationLandscape(DeviceRotation rotation) { if (IsCurrentDisplayHorizontal()) { - return true; + return; } if (IsDeviceRotationHorizontal(rotation)) { - return true; + return; } SetScreenRotation(ConvertDeviceToDisplayRotation(DeviceRotation::ROTATION_LANDSCAPE)); - return false; } void ScreenRotationController::ProcessSwitchToAutoRotationPortraitRestricted() @@ -454,12 +462,12 @@ bool ScreenRotationController::IsDeviceRotationHorizontal(DeviceRotation deviceR bool ScreenRotationController::IsCurrentDisplayVertical() { - return IsDisplayRotationVertical(currentDisplayRotation_); + return IsDisplayRotationVertical(GetCurrentDisplayRotation()); } bool ScreenRotationController::IsCurrentDisplayHorizontal() { - return IsDisplayRotationHorizontal(currentDisplayRotation_); + return IsDisplayRotationHorizontal(GetCurrentDisplayRotation()); } bool ScreenRotationController::IsDisplayRotationVertical(Rotation rotation) @@ -507,5 +515,14 @@ void ScreenRotationController::ProcessSwitchToSensorUnrelatedOrientation(Orienta } } } + +void ScreenRotationController::ProcessOrientationSwitch(Orientation orientation) +{ + if (!IsSensorRelatedOrientation(orientation)) { + ProcessSwitchToSensorUnrelatedOrientation(orientation); + } else { + ProcessSwitchToSensorRelatedOrientation(orientation, lastSensorRotationConverted_); + } +} } // Rosen } // OHOS \ No newline at end of file From 8c808d013e38e9cfbf36cb099c2554712914cccb Mon Sep 17 00:00:00 2001 From: Zhang Peng Date: Fri, 1 Jul 2022 17:13:23 +0800 Subject: [PATCH 68/81] fix csec, add support for animation callback Signed-off-by: Zhang Peng Change-Id: Ia4a6d78cc4aa17badfac24466a05b06b9312ef40 --- dmserver/include/abstract_screen_controller.h | 2 +- dmserver/src/abstract_screen_controller.cpp | 21 +++++------- .../zidl/window_extension_client_proxy.cpp | 4 +-- .../src/zidl/window_extension_client_stub.cpp | 2 +- wm/src/window_manager.cpp | 22 ++++++------ wmserver/include/window_manager_service.h | 6 ++-- wmserver/src/window_manager_service.cpp | 10 ++++-- wmserver/src/window_root.cpp | 34 +++++++++---------- wmserver/src/zidl/window_manager_proxy.cpp | 12 +++---- wmserver/src/zidl/window_manager_stub.cpp | 16 ++++----- 10 files changed, 66 insertions(+), 63 deletions(-) diff --git a/dmserver/include/abstract_screen_controller.h b/dmserver/include/abstract_screen_controller.h index 88f708f1..ec8eb71b 100644 --- a/dmserver/include/abstract_screen_controller.h +++ b/dmserver/include/abstract_screen_controller.h @@ -63,7 +63,7 @@ public: bool SetRotation(ScreenId screenId, Rotation rotationAfter, bool isFromWindow); bool SetScreenActiveMode(ScreenId screenId, uint32_t modeId); - std::shared_ptr GetRSDisplayNodeByScreenId(ScreenId dmsScreenId) const; + const std::shared_ptr& GetRSDisplayNodeByScreenId(ScreenId dmsScreenId) const; void UpdateRSTree(ScreenId dmsScreenId, std::shared_ptr& surfaceNode, bool isAdd); bool MakeMirror(ScreenId, std::vector screens); bool MakeExpand(std::vector screenIds, std::vector startPoints); diff --git a/dmserver/src/abstract_screen_controller.cpp b/dmserver/src/abstract_screen_controller.cpp index 8283556f..ab352278 100644 --- a/dmserver/src/abstract_screen_controller.cpp +++ b/dmserver/src/abstract_screen_controller.cpp @@ -41,9 +41,7 @@ AbstractScreenController::AbstractScreenController(std::recursive_mutex& mutex) controllerHandler_ = std::make_shared(runner); } -AbstractScreenController::~AbstractScreenController() -{ -} +AbstractScreenController::~AbstractScreenController() = default; void AbstractScreenController::Init() { @@ -55,8 +53,7 @@ void AbstractScreenController::RegisterRsScreenConnectionChangeListener() { WLOGFD("RegisterRsScreenConnectionChangeListener"); auto res = rsInterface_.SetScreenChangeCallback( - std::bind(&AbstractScreenController::OnRsScreenConnectionChange, - this, std::placeholders::_1, std::placeholders::_2)); + [this](ScreenId rsScreenId, ScreenEvent screenEvent) { OnRsScreenConnectionChange(rsScreenId, screenEvent); }); if (res != StatusCode::SUCCESS) { auto task = [this] { RegisterRsScreenConnectionChangeListener(); @@ -76,8 +73,8 @@ std::vector AbstractScreenController::GetAllScreenIds() const { std::lock_guard lock(mutex_); std::vector res; - for (auto iter = dmsScreenMap_.begin(); iter != dmsScreenMap_.end(); iter++) { - res.emplace_back(iter->first); + for (const auto& iter : dmsScreenMap_) { + res.emplace_back(iter.first); } return res; } @@ -133,7 +130,7 @@ std::vector AbstractScreenController::GetAllExpandOrMirrorScreenIds( return screenIds; } -std::shared_ptr AbstractScreenController::GetRSDisplayNodeByScreenId(ScreenId dmsScreenId) const +const std::shared_ptr& AbstractScreenController::GetRSDisplayNodeByScreenId(ScreenId dmsScreenId) const { sptr screen = GetAbstractScreen(dmsScreenId); if (screen == nullptr) { @@ -175,7 +172,7 @@ sptr AbstractScreenController::GetAbstractScreenGroup(Scree std::lock_guard lock(mutex_); auto iter = dmsScreenGroupMap_.find(dmsScreenId); if (iter == dmsScreenGroupMap_.end()) { - WLOGE("didnot find screen:%{public}" PRIu64"", dmsScreenId); + WLOGE("did not find screen:%{public}" PRIu64"", dmsScreenId); return nullptr; } return iter->second; @@ -498,7 +495,7 @@ ScreenId AbstractScreenController::CreateVirtualScreen(VirtualScreenOption optio } std::vector virtualScreenIds; std::lock_guard lock(mutex_); - std::map, std::vector>::iterator agIter = screenAgentMap_.find(displayManagerAgent); + auto agIter = screenAgentMap_.find(displayManagerAgent); if (agIter == screenAgentMap_.end()) { if (!RegisterVirtualScreenAgent(displayManagerAgent)) { return SCREEN_ID_INVALID; @@ -557,7 +554,7 @@ DMError AbstractScreenController::DestroyVirtualScreen(ScreenId screenId) } } - std::map>::iterator iter = displayNodeMap_.find(rsScreenId); + auto iter = displayNodeMap_.find(rsScreenId); if (iter == displayNodeMap_.end()) { WLOGFI("displayNode is nullptr"); } else { @@ -970,7 +967,7 @@ bool AbstractScreenController::OnRemoteDied(const sptr& agent) if (agent == nullptr) { return false; } - std::map, std::vector>::iterator agentIter = screenAgentMap_.find(agent); + auto agentIter = screenAgentMap_.find(agent); if (agentIter != screenAgentMap_.end()) { while (screenAgentMap_[agent].size() > 0) { auto diedId = screenAgentMap_[agent][0]; diff --git a/extension/extension_connection/src/zidl/window_extension_client_proxy.cpp b/extension/extension_connection/src/zidl/window_extension_client_proxy.cpp index d9b6d056..98821797 100644 --- a/extension/extension_connection/src/zidl/window_extension_client_proxy.cpp +++ b/extension/extension_connection/src/zidl/window_extension_client_proxy.cpp @@ -35,8 +35,8 @@ void WindowExtensionClientProxy::OnWindowReady(const std::shared_ptrMarshalling(data))) { WLOGFE("write surfaceNode failed"); return; } diff --git a/extension/extension_connection/src/zidl/window_extension_client_stub.cpp b/extension/extension_connection/src/zidl/window_extension_client_stub.cpp index 5534e146..111f1532 100644 --- a/extension/extension_connection/src/zidl/window_extension_client_stub.cpp +++ b/extension/extension_connection/src/zidl/window_extension_client_stub.cpp @@ -32,7 +32,7 @@ int WindowExtensionClientStub::OnRemoteRequest(uint32_t code, MessageParcel& dat WLOGFI(" code is %{public}d", code); switch (code) { case TRANS_ID_ON_WINDOW_READY: { - std::shared_ptr surfaceNode(data.ReadParcelable()); + std::shared_ptr surfaceNode = RSSurfaceNode::Unmarshalling(data); OnWindowReady(surfaceNode); break; } diff --git a/wm/src/window_manager.cpp b/wm/src/window_manager.cpp index e16ff519..2afa8c76 100644 --- a/wm/src/window_manager.cpp +++ b/wm/src/window_manager.cpp @@ -42,7 +42,7 @@ bool WindowVisibilityInfo::Marshalling(Parcel &parcel) const WindowVisibilityInfo* WindowVisibilityInfo::Unmarshalling(Parcel &parcel) { - WindowVisibilityInfo* windowVisibilityInfo = new (std::nothrow) WindowVisibilityInfo(); + auto* windowVisibilityInfo = new (std::nothrow) WindowVisibilityInfo(); if (windowVisibilityInfo == nullptr) { WLOGFE("window visibility info is nullptr."); return nullptr; @@ -68,7 +68,7 @@ bool WindowInfo::Marshalling(Parcel &parcel) const WindowInfo* WindowInfo::Unmarshalling(Parcel &parcel) { - WindowInfo* windowInfo = new (std::nothrow) WindowInfo(); + auto* windowInfo = new (std::nothrow) WindowInfo(); if (windowInfo == nullptr) { WLOGFE("window info is nullptr."); return nullptr; @@ -94,7 +94,7 @@ bool AccessibilityWindowInfo::Marshalling(Parcel &parcel) const AccessibilityWindowInfo* AccessibilityWindowInfo::Unmarshalling(Parcel &parcel) { - AccessibilityWindowInfo* accessibilityWindowInfo = new (std::nothrow) AccessibilityWindowInfo(); + auto* accessibilityWindowInfo = new (std::nothrow) AccessibilityWindowInfo(); if (accessibilityWindowInfo == nullptr) { WLOGFE("accessibility window info is nullptr."); return nullptr; @@ -117,7 +117,7 @@ bool FocusChangeInfo::Marshalling(Parcel &parcel) const FocusChangeInfo* FocusChangeInfo::Unmarshalling(Parcel &parcel) { - FocusChangeInfo* focusChangeInfo = new FocusChangeInfo(); + auto* focusChangeInfo = new FocusChangeInfo(); bool res = parcel.ReadUint32(focusChangeInfo->windowId_) && parcel.ReadUint64(focusChangeInfo->displayId_) && parcel.ReadInt32(focusChangeInfo->pid_) && parcel.ReadInt32(focusChangeInfo->uid_); if (!res) { @@ -150,7 +150,7 @@ public: static inline SingletonDelegator delegator_; bool isHandlerRunning_ = false; - std::shared_ptr listenertHandler_; + std::shared_ptr listenerHandler_; std::recursive_mutex mutex_; std::vector> focusChangedListeners_; sptr focusChangedListenerAgent_; @@ -170,11 +170,11 @@ void WindowManager::Impl::PostTask(ListenerTaskCallback &&callback, EventPriorit if (!isHandlerRunning_) { InitListenerHandler(); } - if (listenertHandler_ == nullptr) { + if (listenerHandler_ == nullptr) { WLOGFE("listener handler is nullptr"); return; } - bool ret = listenertHandler_->PostTask([this, callback]() { + bool ret = listenerHandler_->PostTask([this, callback]() { callback(); }, name, 0, priority); // 0 is task delay time if (!ret) { @@ -191,8 +191,8 @@ void WindowManager::Impl::InitListenerHandler() WLOGFE("init window manager callback runner failed."); return; } - listenertHandler_ = std::make_shared(runner); - if (listenertHandler_ == nullptr) { + listenerHandler_ = std::make_shared(runner); + if (listenerHandler_ == nullptr) { WLOGFE("init window manager callback handler failed."); return; } @@ -287,9 +287,7 @@ WindowManager::WindowManager() : pImpl_(std::make_unique()) { } -WindowManager::~WindowManager() -{ -} +WindowManager::~WindowManager() = default; void WindowManager::RegisterFocusChangedListener(const sptr& listener) { diff --git a/wmserver/include/window_manager_service.h b/wmserver/include/window_manager_service.h index 536c9812..889da52f 100644 --- a/wmserver/include/window_manager_service.h +++ b/wmserver/include/window_manager_service.h @@ -56,6 +56,7 @@ public: virtual void CancelStartingWindow(sptr abilityToken) override; }; +class RSUIDirector; class WindowManagerService : public SystemAbility, public WindowManagerStub { friend class DisplayChangeListener; friend class WindowManagerServiceHandler; @@ -134,7 +135,8 @@ private: std::unique_ptr wmsTaskLooper_; RSInterfaces& rsInterface_; bool startingOpen_ = true; + std::shared_ptr rsUiDirector_; }; -} -} +} // namespace Rosen +} // namespace OHOS #endif // OHOS_WINDOW_MANAGER_SERVICE_H diff --git a/wmserver/src/window_manager_service.cpp b/wmserver/src/window_manager_service.cpp index f884bbfe..ea4df4b1 100644 --- a/wmserver/src/window_manager_service.cpp +++ b/wmserver/src/window_manager_service.cpp @@ -28,6 +28,7 @@ #include "drag_controller.h" #include "remote_animation.h" #include "minimize_app.h" +#include "ui/rs_ui_director.h" #include "singleton_container.h" #include "window_helper.h" #include "window_inner_manager.h" @@ -50,7 +51,7 @@ WindowManagerService::WindowManagerService() : SystemAbility(WINDOW_MANAGER_SERV rsInterface_(RSInterfaces::GetInstance()) { windowRoot_ = new WindowRoot( - std::bind(&WindowManagerService::OnWindowEvent, this, std::placeholders::_1, std::placeholders::_2)); + [this](Event event, const sptr& remoteObject) { OnWindowEvent(event, remoteObject); }); inputWindowMonitor_ = new InputWindowMonitor(windowRoot_); windowController_ = new WindowController(windowRoot_, inputWindowMonitor_); snapshotController_ = new SnapshotController(windowRoot_); @@ -59,6 +60,11 @@ WindowManagerService::WindowManagerService() : SystemAbility(WINDOW_MANAGER_SERV freezeDisplayController_ = new FreezeController(); wmsTaskLooper_ = std::make_unique(); startingOpen_ = system::GetParameter("persist.window.sw.enabled", "1") == "1"; // startingWin default enabled + + // init RSUIDirector, it will handle animation callback + rsUiDirector_ = RSUIDirector::Create(); + rsUiDirector_->SetUITaskRunner([this](const std::function& task) { wmsTaskLooper_->PostTask(task); }); + rsUiDirector_->Init(false); } void WindowManagerService::OnStart() @@ -654,4 +660,4 @@ WMError WindowManagerService::UpdateAvoidAreaListener(uint32_t windowId, bool ha }).get(); } } // namespace Rosen -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/wmserver/src/window_root.cpp b/wmserver/src/window_root.cpp index d13e9626..41cf89c9 100644 --- a/wmserver/src/window_root.cpp +++ b/wmserver/src/window_root.cpp @@ -277,7 +277,7 @@ void WindowRoot::AddSurfaceNodeIdWindowNodePair(uint64_t surfaceNodeId, sptr> WindowRoot::GetWindowVisibilityChangeInfo( std::shared_ptr occlusionData) { - std::vector> visibityChangeInfo; + std::vector> visibilityChangeInfo; VisibleData& currentVisibleWindow = occlusionData->GetVisibleData(); std::sort(currentVisibleWindow.begin(), currentVisibleWindow.end()); VisibleData& lastVisibleWindow = lastOcclusionData_->GetVisibleData(); @@ -285,10 +285,10 @@ std::vector> WindowRoot::GetWindowVisibilityChangeInfo i = j = 0; for (; i < lastVisibleWindow.size() && j < currentVisibleWindow.size();) { if (lastVisibleWindow[i] < currentVisibleWindow[j]) { - visibityChangeInfo.push_back(std::make_pair(lastVisibleWindow[i], false)); + visibilityChangeInfo.emplace_back(lastVisibleWindow[i], false); i++; } else if (lastVisibleWindow[i] > currentVisibleWindow[j]) { - visibityChangeInfo.push_back(std::make_pair(currentVisibleWindow[j], true)); + visibilityChangeInfo.emplace_back(currentVisibleWindow[j], true); j++; } else { i++; @@ -296,20 +296,20 @@ std::vector> WindowRoot::GetWindowVisibilityChangeInfo } } for (; i < lastVisibleWindow.size(); ++i) { - visibityChangeInfo.push_back(std::make_pair(lastVisibleWindow[i], false)); + visibilityChangeInfo.emplace_back(lastVisibleWindow[i], false); } for (; j < currentVisibleWindow.size(); ++j) { - visibityChangeInfo.push_back(std::make_pair(currentVisibleWindow[j], true)); + visibilityChangeInfo.emplace_back(currentVisibleWindow[j], true); } lastOcclusionData_ = occlusionData; - return visibityChangeInfo; + return visibilityChangeInfo; } void WindowRoot::NotifyWindowVisibilityChange(std::shared_ptr occlusionData) { - std::vector> visibityChangeInfo = GetWindowVisibilityChangeInfo(occlusionData); + std::vector> visibilityChangeInfo = GetWindowVisibilityChangeInfo(occlusionData); std::vector> windowVisibilityInfos; - for (const auto& elem : visibityChangeInfo) { + for (const auto& elem : visibilityChangeInfo) { uint64_t surfaceId = elem.first; bool isVisible = elem.second; auto iter = surfaceIdWindowNodeMap_.find(surfaceId); @@ -868,13 +868,13 @@ WMError WindowRoot::RequestActiveWindow(uint32_t windowId) return res; } -std::shared_ptr WindowRoot::GetSurfaceNodeByAbilityToken(const sptr &abilityToken) const +std::shared_ptr WindowRoot::GetSurfaceNodeByAbilityToken(const sptr& abilityToken) const { - for (auto iter = windowNodeMap_.begin(); iter != windowNodeMap_.end(); iter++) { - if (iter->second->abilityToken_ != abilityToken) { + for (const auto& iter : windowNodeMap_) { + if (iter.second->abilityToken_ != abilityToken) { continue; } - return iter->second->surfaceNode_; + return iter.second->surfaceNode_; } WLOGFE("could not find required abilityToken!"); return nullptr; @@ -980,7 +980,7 @@ std::vector WindowRoot::GetAllDisplayIds() const std::vector displayIds; for (auto& it : windowNodeContainerMap_) { if (!it.second) { - return std::vector(); + return {}; } std::vector& displayIdVec = const_cast(this)->displayIdMap_[it.first]; for (auto displayId : displayIdVec) { @@ -1240,19 +1240,19 @@ float WindowRoot::GetVirtualPixelRatio(DisplayId displayId) const Rect WindowRoot::GetDisplayGroupRect(DisplayId displayId) const { - Rect fulldisplayRect; + Rect fullDisplayRect; auto container = const_cast(this)->GetOrCreateWindowNodeContainer(displayId); if (container == nullptr) { WLOGFE("window container could not be found"); - return fulldisplayRect; + return fullDisplayRect; } return container->GetDisplayGroupRect(); } WMError WindowRoot::GetAccessibilityWindowInfo(sptr& windowInfo) { - for (auto iter = windowNodeContainerMap_.begin(); iter != windowNodeContainerMap_.end(); ++iter) { - auto container = iter->second; + for (auto& iter : windowNodeContainerMap_) { + auto container = iter.second; std::vector> windowList; container->GetWindowList(windowList); for (auto window : windowList) { diff --git a/wmserver/src/zidl/window_manager_proxy.cpp b/wmserver/src/zidl/window_manager_proxy.cpp index 93449f2f..40fab55f 100644 --- a/wmserver/src/zidl/window_manager_proxy.cpp +++ b/wmserver/src/zidl/window_manager_proxy.cpp @@ -46,7 +46,7 @@ WMError WindowManagerProxy::CreateWindow(sptr& window, sptrMarshalling(data)) { WLOGFE("Write windowProperty failed"); return WMError::WM_ERROR_IPC_FAILED; } @@ -537,7 +537,7 @@ WMError WindowManagerProxy::NotifyWindowTransition(sptr& f WLOGFE("Send request error: %{public}d", static_cast(error)); return WMError::WM_ERROR_IPC_FAILED; } - WMError ret = static_cast(reply.ReadInt32()); + auto ret = static_cast(reply.ReadInt32()); return ret; } @@ -560,7 +560,7 @@ WMError WindowManagerProxy::GetModeChangeHotZones(DisplayId displayId, ModeChang return WMError::WM_ERROR_IPC_FAILED; } - WMError ret = static_cast(reply.ReadInt32()); + auto ret = static_cast(reply.ReadInt32()); if (ret == WMError::WM_OK) { hotZones.fullscreen_.posX_ = reply.ReadInt32(); hotZones.fullscreen_.posY_ = reply.ReadInt32(); @@ -590,7 +590,7 @@ void WindowManagerProxy::MinimizeWindowsByLauncher(std::vector windowI WLOGFE("WriteInterfaceToken failed"); return; } - uint32_t size = static_cast(windowIds.size()); + auto size = static_cast(windowIds.size()); const uint32_t maxWindowNum = 100; if (size > maxWindowNum) { WLOGFE("windowNum cannot exceeds than 100"); @@ -617,8 +617,8 @@ void WindowManagerProxy::MinimizeWindowsByLauncher(std::vector windowI } ; if (reply.ReadBool()) { - sptr finishcallbackObject = reply.ReadRemoteObject(); - finishCallback = iface_cast(finishcallbackObject); + sptr finishCallbackObject = reply.ReadRemoteObject(); + finishCallback = iface_cast(finishCallbackObject); } else { finishCallback = nullptr; } diff --git a/wmserver/src/zidl/window_manager_stub.cpp b/wmserver/src/zidl/window_manager_stub.cpp index 24cb813b..d32fb6ea 100644 --- a/wmserver/src/zidl/window_manager_stub.cpp +++ b/wmserver/src/zidl/window_manager_stub.cpp @@ -31,13 +31,13 @@ int32_t WindowManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, M WLOGFE("InterfaceToken check failed"); return -1; } - WindowManagerMessage msgId = static_cast(code); + auto msgId = static_cast(code); switch (msgId) { case WindowManagerMessage::TRANS_ID_CREATE_WINDOW: { sptr windowObject = data.ReadRemoteObject(); sptr windowProxy = iface_cast(windowObject); sptr windowProperty = data.ReadStrongParcelable(); - std::shared_ptr surfaceNode(data.ReadParcelable()); + std::shared_ptr surfaceNode = RSSurfaceNode::Unmarshalling(data); uint32_t windowId; sptr token = nullptr; if (windowProperty && windowProperty->GetTokenState()) { @@ -76,21 +76,21 @@ int32_t WindowManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, M } case WindowManagerMessage::TRANS_ID_SET_BACKGROUND_BLUR: { uint32_t windowId = data.ReadUint32(); - WindowBlurLevel level = static_cast(data.ReadUint32()); + auto level = static_cast(data.ReadUint32()); WMError errCode = SetWindowBackgroundBlur(windowId, level); reply.WriteInt32(static_cast(errCode)); break; } case WindowManagerMessage::TRANS_ID_GET_AVOID_AREA: { uint32_t windowId = data.ReadUint32(); - AvoidAreaType avoidAreaType = static_cast(data.ReadUint32()); + auto avoidAreaType = static_cast(data.ReadUint32()); AvoidArea avoidArea = GetAvoidAreaByType(windowId, avoidAreaType); reply.WriteParcelable(&avoidArea); break; } case WindowManagerMessage::TRANS_ID_REGISTER_WINDOW_MANAGER_AGENT: { - WindowManagerAgentType type = static_cast(data.ReadUint32()); + auto type = static_cast(data.ReadUint32()); sptr windowManagerAgentObject = data.ReadRemoteObject(); sptr windowManagerAgentProxy = iface_cast(windowManagerAgentObject); @@ -98,7 +98,7 @@ int32_t WindowManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, M break; } case WindowManagerMessage::TRANS_ID_UNREGISTER_WINDOW_MANAGER_AGENT: { - WindowManagerAgentType type = static_cast(data.ReadUint32()); + auto type = static_cast(data.ReadUint32()); sptr windowManagerAgentObject = data.ReadRemoteObject(); sptr windowManagerAgentProxy = iface_cast(windowManagerAgentObject); @@ -134,13 +134,13 @@ int32_t WindowManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, M break; } case WindowManagerMessage::TRANS_ID_UPDATE_LAYOUT_MODE: { - WindowLayoutMode mode = static_cast(data.ReadUint32()); + auto mode = static_cast(data.ReadUint32()); WMError errCode = SetWindowLayoutMode(mode); reply.WriteInt32(static_cast(errCode)); break; } case WindowManagerMessage::TRANS_ID_UPDATE_PROPERTY: { - PropertyChangeAction action = static_cast(data.ReadUint32()); + auto action = static_cast(data.ReadUint32()); sptr windowProperty = new WindowProperty(); windowProperty->Read(data, action); WMError errCode = UpdateProperty(windowProperty, action); From 5dcd308fc9d155a235346d7045969910c6e2c2d0 Mon Sep 17 00:00:00 2001 From: Zhang Peng Date: Mon, 4 Jul 2022 15:08:37 +0800 Subject: [PATCH 69/81] trigger window size change animation Signed-off-by: Zhang Peng Change-Id: I50c0b916a2f09e8ee6ac8badfaad59fe0c6c5a34 --- wmserver/include/window_layout_policy.h | 2 +- .../include/window_layout_policy_cascade.h | 1 + wmserver/src/window_layout_policy_cascade.cpp | 20 +++++++++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/wmserver/include/window_layout_policy.h b/wmserver/include/window_layout_policy.h index 5421d22b..ae69a4da 100644 --- a/wmserver/include/window_layout_policy.h +++ b/wmserver/include/window_layout_policy.h @@ -73,7 +73,7 @@ protected: bool IsVerticalDisplay(DisplayId displayId) const; bool IsFullScreenRecentWindowExist(const std::vector>& nodeVec) const; void LayoutWindowNodesByRootType(const std::vector>& nodeVec); - void UpdateSurfaceBounds(const sptr& node, const Rect& winRect, const Rect& preRect); + virtual void UpdateSurfaceBounds(const sptr& node, const Rect& winRect, const Rect& preRect); void UpdateRectInDisplayGroupForAllNodes(DisplayId displayId, const Rect& oriDisplayRect, const Rect& newDisplayRect); void UpdateRectInDisplayGroup(const sptr& node, diff --git a/wmserver/include/window_layout_policy_cascade.h b/wmserver/include/window_layout_policy_cascade.h index 45a5f47b..db3ca76e 100644 --- a/wmserver/include/window_layout_policy_cascade.h +++ b/wmserver/include/window_layout_policy_cascade.h @@ -59,6 +59,7 @@ private: void InitCascadeRect(DisplayId displayId); void SetCascadeRect(const sptr& node); void ApplyWindowRectConstraints(const sptr& node, Rect& winRect) const; + void UpdateSurfaceBounds(const sptr& node, const Rect& winRect, const Rect& preRect) override; Rect GetRectByWindowMode(const WindowMode& mode) const; Rect GetLimitRect(const WindowMode mode, DisplayId displayId) const; diff --git a/wmserver/src/window_layout_policy_cascade.cpp b/wmserver/src/window_layout_policy_cascade.cpp index 4e766fb3..5db1c692 100644 --- a/wmserver/src/window_layout_policy_cascade.cpp +++ b/wmserver/src/window_layout_policy_cascade.cpp @@ -19,6 +19,7 @@ #include "window_helper.h" #include "window_inner_manager.h" #include "window_manager_hilog.h" +#include "wm_common.h" #include "wm_common_inner.h" #include "wm_trace.h" @@ -317,11 +318,30 @@ void WindowLayoutPolicyCascade::UpdateLayoutRect(const sptr& node) CalcAndSetNodeHotZone(winRect, node); UpdateClientRectAndResetReason(node, lastWinRect, winRect); + // update node bounds UpdateSurfaceBounds(node, winRect, lastWinRect); } +void WindowLayoutPolicyCascade::UpdateSurfaceBounds( + const sptr& node, const Rect& winRect, const Rect& preRect) +{ + switch (node->GetWindowSizeChangeReason()) { + case WindowSizeChangeReason::MAXIMIZE: + case WindowSizeChangeReason::RECOVER: { + const RSAnimationTimingProtocol timingProtocol(400); + RSNode::Animate(timingProtocol, RSAnimationTimingCurve::EASE_OUT, + [=]() { WindowLayoutPolicy::UpdateSurfaceBounds(node, winRect, preRect); }); + break; + } + case WindowSizeChangeReason::ROTATION: + case WindowSizeChangeReason::UNDEFINED: + default: + WindowLayoutPolicy::UpdateSurfaceBounds(node, winRect, preRect); + } +} + void WindowLayoutPolicyCascade::InitLimitRects(DisplayId displayId) { limitRectMap_[displayId] = displayGroupInfo_->GetDisplayRect(displayId); From 8f31cf9844c8e91f67b0dcc84688bbb19338c4fc Mon Sep 17 00:00:00 2001 From: Zhang Peng Date: Tue, 5 Jul 2022 22:24:33 +0800 Subject: [PATCH 70/81] fix csec: sort header files and others Signed-off-by: Zhang Peng Change-Id: I4a414a5cc7c58c22e8d083027f6b1ac5c57b993c --- interfaces/innerkits/wm/window.h | 2 +- interfaces/innerkits/wm/window_manager.h | 2 +- wm/src/window_manager.cpp | 14 +++++--------- wmserver/src/window_layout_policy_cascade.cpp | 2 -- wmserver/src/window_manager_service.cpp | 11 +++++------ 5 files changed, 12 insertions(+), 19 deletions(-) diff --git a/interfaces/innerkits/wm/window.h b/interfaces/innerkits/wm/window.h index 7ca06962..5cba7ed1 100644 --- a/interfaces/innerkits/wm/window.h +++ b/interfaces/innerkits/wm/window.h @@ -236,7 +236,7 @@ public: virtual void UnregisterTouchOutsideListener(const sptr& listener) = 0; virtual void SetAceAbilityHandler(const sptr& handler) = 0; virtual WMError SetUIContent(const std::string& contentInfo, NativeEngine* engine, - NativeValue* storage, bool isdistributed = false, AppExecFwk::Ability* ability = nullptr) = 0; + NativeValue* storage, bool isDistributed = false, AppExecFwk::Ability* ability = nullptr) = 0; virtual std::string GetContentInfo() = 0; virtual Ace::UIContent* GetUIContent() const = 0; virtual void OnNewWant(const AAFwk::Want& want) = 0; diff --git a/interfaces/innerkits/wm/window_manager.h b/interfaces/innerkits/wm/window_manager.h index fcc8b41c..09aae692 100644 --- a/interfaces/innerkits/wm/window_manager.h +++ b/interfaces/innerkits/wm/window_manager.h @@ -151,7 +151,7 @@ public: private: WindowManager(); - ~WindowManager(); + ~WindowManager() = default; class Impl; std::unique_ptr pImpl_; diff --git a/wm/src/window_manager.cpp b/wm/src/window_manager.cpp index 2afa8c76..b956b03d 100644 --- a/wm/src/window_manager.cpp +++ b/wm/src/window_manager.cpp @@ -42,7 +42,7 @@ bool WindowVisibilityInfo::Marshalling(Parcel &parcel) const WindowVisibilityInfo* WindowVisibilityInfo::Unmarshalling(Parcel &parcel) { - auto* windowVisibilityInfo = new (std::nothrow) WindowVisibilityInfo(); + auto windowVisibilityInfo = new (std::nothrow) WindowVisibilityInfo(); if (windowVisibilityInfo == nullptr) { WLOGFE("window visibility info is nullptr."); return nullptr; @@ -68,7 +68,7 @@ bool WindowInfo::Marshalling(Parcel &parcel) const WindowInfo* WindowInfo::Unmarshalling(Parcel &parcel) { - auto* windowInfo = new (std::nothrow) WindowInfo(); + auto windowInfo = new (std::nothrow) WindowInfo(); if (windowInfo == nullptr) { WLOGFE("window info is nullptr."); return nullptr; @@ -94,7 +94,7 @@ bool AccessibilityWindowInfo::Marshalling(Parcel &parcel) const AccessibilityWindowInfo* AccessibilityWindowInfo::Unmarshalling(Parcel &parcel) { - auto* accessibilityWindowInfo = new (std::nothrow) AccessibilityWindowInfo(); + auto accessibilityWindowInfo = new (std::nothrow) AccessibilityWindowInfo(); if (accessibilityWindowInfo == nullptr) { WLOGFE("accessibility window info is nullptr."); return nullptr; @@ -117,7 +117,7 @@ bool FocusChangeInfo::Marshalling(Parcel &parcel) const FocusChangeInfo* FocusChangeInfo::Unmarshalling(Parcel &parcel) { - auto* focusChangeInfo = new FocusChangeInfo(); + auto focusChangeInfo = new FocusChangeInfo(); bool res = parcel.ReadUint32(focusChangeInfo->windowId_) && parcel.ReadUint64(focusChangeInfo->displayId_) && parcel.ReadInt32(focusChangeInfo->pid_) && parcel.ReadInt32(focusChangeInfo->uid_); if (!res) { @@ -283,11 +283,7 @@ void WindowManager::Impl::UpdateCameraFloatWindowStatus(uint32_t accessTokenId, }, EventPriority::LOW, "CameraFloatWindowStatus"); } -WindowManager::WindowManager() : pImpl_(std::make_unique()) -{ -} - -WindowManager::~WindowManager() = default; +WindowManager::WindowManager() : pImpl_(std::make_unique()) {} void WindowManager::RegisterFocusChangedListener(const sptr& listener) { diff --git a/wmserver/src/window_layout_policy_cascade.cpp b/wmserver/src/window_layout_policy_cascade.cpp index 5db1c692..87a36314 100644 --- a/wmserver/src/window_layout_policy_cascade.cpp +++ b/wmserver/src/window_layout_policy_cascade.cpp @@ -19,8 +19,6 @@ #include "window_helper.h" #include "window_inner_manager.h" #include "window_manager_hilog.h" -#include "wm_common.h" -#include "wm_common_inner.h" #include "wm_trace.h" namespace OHOS { diff --git a/wmserver/src/window_manager_service.cpp b/wmserver/src/window_manager_service.cpp index ea4df4b1..c3896bb1 100644 --- a/wmserver/src/window_manager_service.cpp +++ b/wmserver/src/window_manager_service.cpp @@ -15,21 +15,21 @@ #include "window_manager_service.h" -#include - #include +#include #include #include #include #include -#include "dm_common.h" #include "display_manager_service_inner.h" +#include "dm_common.h" #include "drag_controller.h" -#include "remote_animation.h" #include "minimize_app.h" -#include "ui/rs_ui_director.h" +#include "permission.h" +#include "remote_animation.h" #include "singleton_container.h" +#include "ui/rs_ui_director.h" #include "window_helper.h" #include "window_inner_manager.h" #include "window_manager_agent_controller.h" @@ -37,7 +37,6 @@ #include "window_manager_hilog.h" #include "wm_common.h" #include "wm_trace.h" -#include "permission.h" namespace OHOS { namespace Rosen { namespace { From e72a5135b20dcfe2c39387eb98032eaf0614032c Mon Sep 17 00:00:00 2001 From: xingyanan Date: Wed, 6 Jul 2022 11:47:47 +0800 Subject: [PATCH 71/81] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=B1=82=E5=8F=A0bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xingyanan Change-Id: Ic62458b02b8d8e0f6f1d215f0e3c6df22ac170a9 Signed-off-by: xingyanan --- dm/test/systemtest/display_power_test.cpp | 13 ----- dm/test/systemtest/screen_manager_test.cpp | 50 ------------------- wmserver/src/window_layout_policy_cascade.cpp | 3 +- 3 files changed, 2 insertions(+), 64 deletions(-) diff --git a/dm/test/systemtest/display_power_test.cpp b/dm/test/systemtest/display_power_test.cpp index 54c29739..6c1553d3 100644 --- a/dm/test/systemtest/display_power_test.cpp +++ b/dm/test/systemtest/display_power_test.cpp @@ -409,19 +409,6 @@ HWTEST_F(DisplayPowerTest, set_screen_brightness_001, Function | MediumTest | Le ASSERT_EQ(level, brightnessLevel_); } -/** -* @tc.name: set_screen_brightness_002 -* @tc.desc: Call SetScreenBrightness with an invalid value and check the GetScreenBrightness return value -* @tc.type: FUNC -*/ -HWTEST_F(DisplayPowerTest, set_screen_brightness_002, Function | MediumTest | Level2) -{ - bool ret = DisplayManager::GetInstance().SetScreenBrightness(defaultId_, invalidBrightnessLevel_); - ASSERT_EQ(true, ret); - uint32_t level = DisplayManager::GetInstance().GetScreenBrightness(defaultId_); - ASSERT_NE(level, invalidBrightnessLevel_); -} - /** * @tc.name: window_life_cycle_001 * @tc.desc: Add a window and then call SuspendEnd and check window state; Notify unlock and check window state diff --git a/dm/test/systemtest/screen_manager_test.cpp b/dm/test/systemtest/screen_manager_test.cpp index 489a3ee8..04d98fe6 100644 --- a/dm/test/systemtest/screen_manager_test.cpp +++ b/dm/test/systemtest/screen_manager_test.cpp @@ -425,56 +425,6 @@ HWTEST_F(ScreenManagerTest, ScreenManager08, Function | MediumTest | Level2) ScreenManager::GetInstance().UnregisterScreenGroupListener(screenGroupChangeListener); } -/** - * @tc.name: ScreenManager09 - * @tc.desc: Create a virtual screen as expansion of default screen, create windowNode on virtual screen, - * and destroy virtual screen - * @tc.type: FUNC - */ -HWTEST_F(ScreenManagerTest, ScreenManager09, Function | MediumTest | Level2) -{ - DisplayTestUtils utils; - ASSERT_TRUE(utils.CreateSurface()); - defaultOption_.surface_ = utils.psurface_; - defaultOption_.isForShot_ = false; - CHECK_TEST_INIT_SCREEN_STATE - ScreenId virtualScreenId = ScreenManager::GetInstance().CreateVirtualScreen(defaultOption_); - CHECK_SCREEN_STATE_AFTER_CREATE_VIRTUAL_SCREEN - CheckScreenStateInGroup(false, group, groupId, virtualScreen, virtualScreenId); - sleep(TEST_SLEEP_S); - std::vector options = {{defaultScreenId_, 0, 0}, {virtualScreenId, defaultWidth_, 0}}; - ScreenId expansionId = ScreenManager::GetInstance().MakeExpand(options); - CheckScreenGroupState(ScreenCombination::SCREEN_EXPAND, ScreenGroupChangeEvent::ADD_TO_GROUP, - virtualScreenId, group, screenGroupChangeListener); - CheckScreenStateInGroup(true, group, groupId, virtualScreen, virtualScreenId); - sleep(TEST_SLEEP_S); - ASSERT_NE(SCREEN_ID_INVALID, expansionId); - DisplayId virtualDisplayId = DisplayManager::GetInstance().GetDisplayByScreen(virtualScreenId)->GetId(); - ASSERT_NE(DISPLAY_ID_INVALID, virtualDisplayId); - sptr window = CreateWindowByDisplayId(virtualDisplayId); - ASSERT_NE(nullptr, window); - sleep(TEST_SLEEP_S); - auto surfaceNode = window->GetSurfaceNode(); - auto rsUiDirector = RSUIDirector::Create(); - rsUiDirector->Init(); - RSTransaction::FlushImplicitTransaction(); - sleep(TEST_SLEEP_S); - rsUiDirector->SetRSSurfaceNode(surfaceNode); - RootNodeInit(rsUiDirector, 200, 400); - rsUiDirector->SendMessages(); - sleep(TEST_SLEEP_S); - ASSERT_EQ(DMError::DM_OK, ScreenManager::GetInstance().DestroyVirtualScreen(virtualScreenId)); - CHECK_SCREEN_STATE_AFTER_DESTROY_VIRTUAL_SCREEN - CheckScreenGroupState(ScreenCombination::SCREEN_EXPAND, ScreenGroupChangeEvent::REMOVE_FROM_GROUP, - virtualScreenId, group, screenGroupChangeListener); - CheckScreenStateInGroup(false, group, groupId, virtualScreen, virtualScreenId); - ScreenManager::GetInstance().UnregisterScreenListener(screenListener); - ScreenManager::GetInstance().UnregisterScreenGroupListener(screenGroupChangeListener); - sleep(TEST_SLEEP_S); - window->Show(); - sleep(TEST_SLEEP_S_LONG); - window->Destroy(); -} /** * @tc.name: ScreenManager10 diff --git a/wmserver/src/window_layout_policy_cascade.cpp b/wmserver/src/window_layout_policy_cascade.cpp index 4e766fb3..e4fa8dc3 100644 --- a/wmserver/src/window_layout_policy_cascade.cpp +++ b/wmserver/src/window_layout_policy_cascade.cpp @@ -515,7 +515,8 @@ Rect WindowLayoutPolicyCascade::GetCurCascadeRect(const sptr& node) (*iter)->GetWindowId() != node->GetWindowId()) { auto property = (*iter)->GetWindowProperty(); if (property != nullptr) { - cascadeRect = property->GetWindowRect(); + cascadeRect = ((*iter)->GetWindowMode() == WindowMode::WINDOW_MODE_FLOATING ? + property->GetWindowRect() : property->GetRequestRect()); } WLOGFI("Get current cascadeRect: %{public}u [%{public}d, %{public}d, %{public}u, %{public}u]", (*iter)->GetWindowId(), cascadeRect.posX_, cascadeRect.posY_, From d01cabf16c6b5564acc9728e221226ec1f1734b9 Mon Sep 17 00:00:00 2001 From: xiahaiqin Date: Wed, 6 Jul 2022 10:01:28 +0800 Subject: [PATCH 72/81] delete wm trace template Signed-off-by: xiahaiqin Change-Id: I056aebee417a70f2417e3ef37126f74de2ff9def --- dm/test/systemtest/BUILD.gn | 2 + dm/test/unittest/BUILD.gn | 2 + dmserver/src/abstract_display_controller.cpp | 8 +- dmserver/src/abstract_screen_controller.cpp | 4 +- dmserver/src/display_manager_service.cpp | 27 ++-- extension/extension_connection/BUILD.gn | 1 + .../src/window_extension_connection.cpp | 6 +- extension/window_extension/BUILD.gn | 1 + .../src/js_window_extension.cpp | 8 +- interfaces/kits/napi/screen_recorder/BUILD.gn | 1 + snapshot/BUILD.gn | 2 + snapshot/snapshot_utils.cpp | 4 +- utils/BUILD.gn | 2 - utils/include/wm_trace.h | 64 --------- utils/src/wm_trace.cpp | 131 ------------------ wmserver/src/avoid_area_controller.cpp | 8 +- wmserver/src/remote_animation.cpp | 13 +- wmserver/src/starting_window.cpp | 8 +- wmserver/src/window_controller.cpp | 14 +- wmserver/src/window_layout_policy.cpp | 1 - wmserver/src/window_layout_policy_cascade.cpp | 9 +- wmserver/src/window_layout_policy_tile.cpp | 9 +- wmserver/src/window_manager_service.cpp | 21 +-- wmserver/src/window_node_container.cpp | 19 +-- wmserver/src/window_pair.cpp | 1 - wmserver/src/window_root.cpp | 4 +- .../window_snapshot/snapshot_controller.cpp | 6 +- 27 files changed, 101 insertions(+), 275 deletions(-) delete mode 100644 utils/include/wm_trace.h delete mode 100644 utils/src/wm_trace.cpp diff --git a/dm/test/systemtest/BUILD.gn b/dm/test/systemtest/BUILD.gn index 17887aa2..fcd59432 100644 --- a/dm/test/systemtest/BUILD.gn +++ b/dm/test/systemtest/BUILD.gn @@ -83,6 +83,8 @@ ohos_systemtest("dm_screenshot_cmd_test") { ] deps = [ ":dm_systemtest_common" ] + + external_deps = [ "hitrace_native:hitrace_meter" ] } ## SystemTest dm_screenshot_cmd_test }}} diff --git a/dm/test/unittest/BUILD.gn b/dm/test/unittest/BUILD.gn index 0f532fa6..c4cd8f5f 100644 --- a/dm/test/unittest/BUILD.gn +++ b/dm/test/unittest/BUILD.gn @@ -60,6 +60,8 @@ ohos_unittest("dm_snapshot_utils_test") { ] deps = [ ":dm_unittest_common" ] + + external_deps = [ "hitrace_native:hitrace_meter" ] } ## UnitTest dm_snapshot_utils_test }}} diff --git a/dmserver/src/abstract_display_controller.cpp b/dmserver/src/abstract_display_controller.cpp index 5a5fe602..86abf0f6 100644 --- a/dmserver/src/abstract_display_controller.cpp +++ b/dmserver/src/abstract_display_controller.cpp @@ -16,13 +16,13 @@ #include "abstract_display_controller.h" #include +#include #include #include "display_manager_agent_controller.h" #include "display_manager_service.h" #include "screen_group.h" #include "window_manager_hilog.h" -#include "wm_trace.h" namespace OHOS::Rosen { namespace { @@ -357,7 +357,7 @@ void AbstractDisplayController::ProcessDisplayUpdateOrientation(sptr absScreen) { - WM_SCOPED_TRACE("dms:ProcessDisplaySizeChange(%" PRIu64")", absScreen->dmsId_); + HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "dms:ProcessDisplaySizeChange(%" PRIu64")", absScreen->dmsId_); sptr info = absScreen->GetActiveScreenMode(); if (info == nullptr) { WLOGE("cannot get active screen info."); @@ -531,13 +531,13 @@ void AbstractDisplayController::AddScreenToExpandLocked(sptr abs void AbstractDisplayController::SetFreeze(std::vector displayIds, bool toFreeze) { - WM_SCOPED_TRACE("dms:SetAllFreeze"); + HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "dms:SetAllFreeze"); DisplayStateChangeType type = toFreeze ? DisplayStateChangeType::FREEZE : DisplayStateChangeType::UNFREEZE; DisplayChangeEvent event = toFreeze ? DisplayChangeEvent::DISPLAY_FREEZED : DisplayChangeEvent::DISPLAY_UNFREEZED; for (DisplayId displayId : displayIds) { sptr abstractDisplay; - WM_SCOPED_TRACE("dms:SetFreeze(%" PRIu64")", displayId); + HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "dms:SetFreeze(%" PRIu64")", displayId); { WLOGI("setfreeze display %{public}" PRIu64"", displayId); std::lock_guard lock(mutex_); diff --git a/dmserver/src/abstract_screen_controller.cpp b/dmserver/src/abstract_screen_controller.cpp index f7ed37db..2beabd3c 100644 --- a/dmserver/src/abstract_screen_controller.cpp +++ b/dmserver/src/abstract_screen_controller.cpp @@ -16,6 +16,7 @@ #include "abstract_screen_controller.h" #include +#include #include #include #include @@ -26,7 +27,6 @@ #include "event_runner.h" #include "screen_rotation_controller.h" #include "window_manager_hilog.h" -#include "wm_trace.h" namespace OHOS::Rosen { namespace { @@ -756,7 +756,7 @@ bool AbstractScreenController::SetScreenActiveMode(ScreenId screenId, uint32_t m void AbstractScreenController::ProcessScreenModeChanged(ScreenId dmsScreenId) { - WM_SCOPED_TRACE("dms:ProcessScreenModeChanged(%" PRIu64")", dmsScreenId); + HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "dms:ProcessScreenModeChanged(%" PRIu64")", dmsScreenId); sptr absScreen = nullptr; sptr absScreenCallback = nullptr; { diff --git a/dmserver/src/display_manager_service.cpp b/dmserver/src/display_manager_service.cpp index 21153b61..d3052bd0 100644 --- a/dmserver/src/display_manager_service.cpp +++ b/dmserver/src/display_manager_service.cpp @@ -16,6 +16,7 @@ #include "display_manager_service.h" #include +#include #include #include #include @@ -28,7 +29,6 @@ #include "screen_rotation_controller.h" #include "transaction/rs_interfaces.h" #include "window_manager_hilog.h" -#include "wm_trace.h" namespace OHOS::Rosen { namespace { @@ -175,7 +175,7 @@ sptr DisplayManagerService::GetDisplayInfoByScreen(ScreenId screenI ScreenId DisplayManagerService::CreateVirtualScreen(VirtualScreenOption option, const sptr& displayManagerAgent) { - WM_SCOPED_TRACE("dms:CreateVirtualScreen(%s)", option.name_.c_str()); + HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "dms:CreateVirtualScreen(%s)", option.name_.c_str()); ScreenId screenId = abstractScreenController_->CreateVirtualScreen(option, displayManagerAgent); CHECK_SCREEN_AND_RETURN(SCREEN_ID_INVALID); accessTokenIdMaps_[screenId] = IPCSkeleton::GetCallingTokenID(); @@ -191,7 +191,7 @@ DMError DisplayManagerService::DestroyVirtualScreen(ScreenId screenId) WLOGFI("DestroyVirtualScreen::ScreenId: %{public}" PRIu64 "", screenId); CHECK_SCREEN_AND_RETURN(DMError::DM_ERROR_INVALID_PARAM); - WM_SCOPED_TRACE("dms:DestroyVirtualScreen(%" PRIu64")", screenId); + HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "dms:DestroyVirtualScreen(%" PRIu64")", screenId); return abstractScreenController_->DestroyVirtualScreen(screenId); } @@ -204,25 +204,25 @@ DMError DisplayManagerService::SetVirtualScreenSurface(ScreenId screenId, sptrSetOrientation(screenId, orientation, false); } bool DisplayManagerService::SetOrientationFromWindow(ScreenId screenId, Orientation orientation) { - WM_SCOPED_TRACE("dms:SetOrientationFromWindow(%" PRIu64")", screenId); + HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "dms:SetOrientationFromWindow(%" PRIu64")", screenId); return abstractScreenController_->SetOrientation(screenId, orientation, true); } bool DisplayManagerService::SetRotationFromWindow(ScreenId screenId, Rotation targetRotation) { - WM_SCOPED_TRACE("dms:SetRotationFromWindow(%" PRIu64")", screenId); + HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "dms:SetRotationFromWindow(%" PRIu64")", screenId); return abstractScreenController_->SetRotation(screenId, targetRotation, true); } std::shared_ptr DisplayManagerService::GetDisplaySnapshot(DisplayId displayId) { - WM_SCOPED_TRACE("dms:GetDisplaySnapshot(%" PRIu64")", displayId); + HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "dms:GetDisplaySnapshot(%" PRIu64")", displayId); if (Permission::CheckCallingPermission("ohos.permission.CAPTURE_SCREEN") || Permission::IsStartByHdcd()) { return abstractDisplayController_->GetScreenSnapshot(displayId); @@ -307,7 +307,7 @@ bool DisplayManagerService::UnregisterDisplayManagerAgent(const sptrSetShotScreen(mainScreenId, shotScreenIds); - WM_SCOPED_TRACE("dms:MakeMirror"); + HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "dms:MakeMirror"); if (!allMirrorScreenIds.empty() && !abstractScreenController_->MakeMirror(mainScreenId, allMirrorScreenIds)) { WLOGFE("make mirror failed."); return SCREEN_ID_INVALID; @@ -540,7 +540,7 @@ ScreenId DisplayManagerService::MakeExpand(std::vector expandScreenIds startPoints.erase(startPointIter); } abstractScreenController_->SetShotScreen(defaultScreenId, shotScreenIds); - WM_SCOPED_TRACE("dms:MakeExpand"); + HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "dms:MakeExpand"); if (!allExpandScreenIds.empty() && !abstractScreenController_->MakeExpand(allExpandScreenIds, startPoints)) { WLOGFE("make expand failed."); return SCREEN_ID_INVALID; @@ -555,13 +555,14 @@ ScreenId DisplayManagerService::MakeExpand(std::vector expandScreenIds bool DisplayManagerService::SetScreenActiveMode(ScreenId screenId, uint32_t modeId) { - WM_SCOPED_TRACE("dms:SetScreenActiveMode(%" PRIu64", %u)", screenId, modeId); + HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "dms:SetScreenActiveMode(%" PRIu64", %u)", screenId, modeId); return abstractScreenController_->SetScreenActiveMode(screenId, modeId); } bool DisplayManagerService::SetVirtualPixelRatio(ScreenId screenId, float virtualPixelRatio) { - WM_SCOPED_TRACE("dms:SetVirtualPixelRatio(%" PRIu64", %f)", screenId, virtualPixelRatio); + HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "dms:SetVirtualPixelRatio(%" PRIu64", %f)", screenId, + virtualPixelRatio); return abstractScreenController_->SetVirtualPixelRatio(screenId, virtualPixelRatio); } diff --git a/extension/extension_connection/BUILD.gn b/extension/extension_connection/BUILD.gn index 7a0d527e..90160069 100644 --- a/extension/extension_connection/BUILD.gn +++ b/extension/extension_connection/BUILD.gn @@ -50,6 +50,7 @@ ohos_shared_library("libwindow_extension_client") { external_deps = [ "ability_base:want", "ability_runtime:ability_manager", + "hitrace_native:hitrace_meter", "input:libmmi-client", ] diff --git a/extension/extension_connection/src/window_extension_connection.cpp b/extension/extension_connection/src/window_extension_connection.cpp index 2659baca..faebd31b 100644 --- a/extension/extension_connection/src/window_extension_connection.cpp +++ b/extension/extension_connection/src/window_extension_connection.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include "window_extension_proxy.h" @@ -25,7 +26,6 @@ #include "window_manager_hilog.h" #include "wm_common.h" #include "wm_common_inner.h" -#include "wm_trace.h" namespace OHOS { namespace Rosen { @@ -106,7 +106,7 @@ int WindowExtensionConnection::Impl::ConnectExtension(const AppExecFwk::ElementN { AAFwk::Want want; want.SetElement(element); - WM_SCOPED_ASYNC_TRACE_BEGIN(static_cast(TraceTaskId::CONNECT_EXTENSION), + StartAsyncTraceArgs(HITRACE_TAG_WINDOW_MANAGER, static_cast(TraceTaskId::CONNECT_EXTENSION), "WindowExtension %s-%s", element.GetBundleName().c_str(), element.GetAbilityName().c_str()); want.SetParam(RECT_FORM_KEY_POS_X, rect.posX_); want.SetParam(RECT_FORM_KEY_POS_Y, rect.posY_); @@ -189,7 +189,7 @@ void WindowExtensionConnection::Impl::OnAbilityConnectDone(const AppExecFwk::Ele WLOGFI("GetExtensionWindow"); } WLOGFI("call end"); - WM_SCOPED_ASYNC_END(static_cast(TraceTaskId::CONNECT_EXTENSION), + FinishAsyncTraceArgs(HITRACE_TAG_WINDOW_MANAGER, static_cast(TraceTaskId::CONNECT_EXTENSION), "WindowExtension %s-%s", element.GetBundleName().c_str(), element.GetAbilityName().c_str()); } diff --git a/extension/window_extension/BUILD.gn b/extension/window_extension/BUILD.gn index 900cebb6..627a5e8f 100644 --- a/extension/window_extension/BUILD.gn +++ b/extension/window_extension/BUILD.gn @@ -58,6 +58,7 @@ ohos_shared_library("libwindow_extension") { "ability_runtime:runtime", "graphic_standard:surface", "hilog_native:libhilog", + "hitrace_native:hitrace_meter", "input:libmmi-client", "utils_base:utils", ] diff --git a/extension/window_extension/src/js_window_extension.cpp b/extension/window_extension/src/js_window_extension.cpp index 412fd70e..cc3cde91 100644 --- a/extension/window_extension/src/js_window_extension.cpp +++ b/extension/window_extension/src/js_window_extension.cpp @@ -15,6 +15,7 @@ #include "js_window_extension.h" +#include #include #include #include @@ -27,7 +28,6 @@ #include "window_manager_hilog.h" #include "wm_common.h" #include "wm_common_inner.h" -#include "wm_trace.h" namespace OHOS { namespace Rosen { @@ -61,7 +61,7 @@ void JsWindowExtension::Init(const std::shared_ptr& handler, const sptr& token) { - WM_SCOPED_TRACE("WindowExtension Init"); + HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "WindowExtension Init"); WindowExtension::Init(record, application, handler, token); std::string srcPath; GetSrcPath(srcPath); @@ -143,7 +143,7 @@ void JsWindowExtension::GetSrcPath(std::string& srcPath) const sptr JsWindowExtension::OnConnect(const AAFwk::Want& want) { - WM_SCOPED_TRACE("WindowExtension Init %s-%s", + HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "WindowExtension OnConnect %s-%s", want.GetElement().GetAbilityName().c_str(), want.GetElement().GetAbilityName().c_str()); WLOGFI("called."); Extension::OnConnect(want); @@ -194,7 +194,7 @@ void JsWindowExtension::OnDisconnect(const AAFwk::Want& want) void JsWindowExtension::OnStart(const AAFwk::Want& want) { - WM_SCOPED_TRACE("WindowExtension OnStart %s-%s", + HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "WindowExtension OnStart %s-%s", want.GetElement().GetAbilityName().c_str(), want.GetElement().GetAbilityName().c_str()); Extension::OnStart(want); diff --git a/interfaces/kits/napi/screen_recorder/BUILD.gn b/interfaces/kits/napi/screen_recorder/BUILD.gn index 73f262fb..be89b195 100644 --- a/interfaces/kits/napi/screen_recorder/BUILD.gn +++ b/interfaces/kits/napi/screen_recorder/BUILD.gn @@ -52,6 +52,7 @@ ohos_shared_library("screenrecorder_napi") { "ability_base:want", "ability_runtime:ability_manager", "ability_runtime:runtime", + "hitrace_native:hitrace_meter", "hiviewdfx_hilog_native:libhilog", "napi:ace_napi", ] diff --git a/snapshot/BUILD.gn b/snapshot/BUILD.gn index 3c5f8073..a5218dd2 100644 --- a/snapshot/BUILD.gn +++ b/snapshot/BUILD.gn @@ -35,6 +35,7 @@ ohos_executable("snapshot_display") { ] external_deps = [ + "hitrace_native:hitrace_meter", "multimedia_image_standard:image_native", "utils_base:utils", ] @@ -61,6 +62,7 @@ ohos_executable("snapshot_virtual_screen") { ] external_deps = [ + "hitrace_native:hitrace_meter", "multimedia_image_standard:image_native", "utils_base:utils", ] diff --git a/snapshot/snapshot_utils.cpp b/snapshot/snapshot_utils.cpp index d4d2ba51..db085cae 100644 --- a/snapshot/snapshot_utils.cpp +++ b/snapshot/snapshot_utils.cpp @@ -16,11 +16,11 @@ #include "snapshot_utils.h" #include +#include #include #include #include #include -#include "wm_trace.h" using namespace OHOS::Media; using namespace OHOS::Rosen; @@ -142,7 +142,7 @@ bool SnapShotUtils::WriteToPng(const std::string &fileName, const WriteToPngPara return false; } - WM_SCOPED_TRACE("snapshot:WriteToPng(%s)", fileName.c_str()); + HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "snapshot:WriteToPng(%s)", fileName.c_str()); png_structp pngStruct = png_create_write_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr); if (pngStruct == nullptr) { diff --git a/utils/BUILD.gn b/utils/BUILD.gn index 23e0a36f..1f88f5f9 100644 --- a/utils/BUILD.gn +++ b/utils/BUILD.gn @@ -39,7 +39,6 @@ ohos_shared_library("libwmutil") { "src/surface_reader_handler_impl.cpp", "src/window_property.cpp", "src/window_transition_info.cpp", - "src/wm_trace.cpp", ] configs = [ ":libwmutil_private_config" ] @@ -57,7 +56,6 @@ ohos_shared_library("libwmutil") { "access_token:libaccesstoken_sdk", "graphic_standard:surface", "hilog_native:libhilog", - "hitrace_native:hitrace_meter", "ipc:ipc_core", "multimedia_image_standard:image_native", "safwk:system_ability_fwk", diff --git a/utils/include/wm_trace.h b/utils/include/wm_trace.h deleted file mode 100644 index 0d7d0507..00000000 --- a/utils/include/wm_trace.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (c) 2021-2022 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_WM_INCLUDE_WM_TRACE_H -#define OHOS_WM_INCLUDE_WM_TRACE_H - -#include -#include -#include - -#include "noncopyable.h" - -#define WM_SCOPED_TRACE(fmt, ...) WmScopedTrace wmScopedTrace(fmt, ##__VA_ARGS__) -#ifdef WM_DEBUG -#define WM_DEBUG_SCOPED_TRACE(fmt, ...) WmScopedTrace wmScopedTrace(fmt, ##__VA_ARGS__) -#else -#define WM_DEBUG_SCOPED_TRACE(fmt, ...) -#endif - -#define WM_FUNCTION_TRACE() WM_SCOPED_TRACE(__func__) -#define WM_SCOPED_TRACE_BEGIN(fmt, ...) WmTraceBeginWithArgs(fmt, ##__VA_ARGS__) -#define WM_SCOPED_TRACE_END() WmTraceEnd() - -#define WM_SCOPED_ASYNC_TRACE_BEGIN(taskId, fmt, ...) WmAsyncTraceWithArgs(true, taskId, fmt, ##__VA_ARGS__) -#define WM_SCOPED_ASYNC_END(taskId, fmt, ...) WmAsyncTraceWithArgs(false, taskId, fmt, ##__VA_ARGS__) - -namespace OHOS { -namespace Rosen { -bool WmTraceEnabled(); -void WmTraceBegin(const char* name); -bool WmTraceBeginWithArgs(const char* format, ...) __attribute__((__format__(printf, 1, 2))); -bool WmTraceBeginWithArgv(const char* format, va_list args); -void WmTraceEnd(); -void WmAsyncTraceBegin(int32_t taskId, const char* name); -void WmAsyncTraceEnd(int32_t taskId, const char* name); -void WmAsyncTraceWithArgs(bool isBegin, int32_t taskId, - const char* format, ...) __attribute__((__format__(printf, 3, 4))); -void WmAsyncTraceWithArgv(bool isBegin, int32_t taskId, const char* format, va_list args); - -class WmScopedTrace final { -public: - explicit WmScopedTrace(const char* format, ...) __attribute__((__format__(printf, 2, 3))); - ~WmScopedTrace(); - - WM_DISALLOW_COPY_AND_MOVE(WmScopedTrace); - -private: - bool traceEnabled_ { false }; -}; -} // namespace OHOS -} -#endif // OHOS_WM_INCLUDE_WM_TRACE_H \ No newline at end of file diff --git a/utils/src/wm_trace.cpp b/utils/src/wm_trace.cpp deleted file mode 100644 index 2858f5bd..00000000 --- a/utils/src/wm_trace.cpp +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Copyright (c) 2021-2022 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 "wm_trace.h" - -#include - -#ifndef WINDOWS_PLATFORM -#include -#endif - -namespace OHOS { -namespace Rosen { -namespace { -const size_t MAX_STRING_SIZE = 128; -} - -bool WmTraceEnabled() -{ - return true; -} - -void WmTraceBegin(const char* name) -{ - if (name == nullptr) { - return; - } - std::string nameStr(name); - StartTrace(HITRACE_TAG_WINDOW_MANAGER, nameStr); -} - -void WmTraceEnd() -{ - if (WmTraceEnabled()) { - FinishTrace(HITRACE_TAG_WINDOW_MANAGER); - } -} - -void WmAsyncTraceBegin(int32_t taskId, const char* name) -{ - if (name == nullptr) { - return; - } - std::string nameStr(name); - StartAsyncTrace(HITRACE_TAG_WINDOW_MANAGER, nameStr, taskId); -} - -void WmAsyncTraceEnd(int32_t taskId, const char* name) -{ - if (name == nullptr) { - return; - } - std::string nameStr(name); - FinishAsyncTrace(HITRACE_TAG_WINDOW_MANAGER, nameStr, taskId); -} - -void WmAsyncTraceWithArgs(bool isBegin, int32_t taskId, const char* format, ...) -{ - if (WmTraceEnabled()) { - va_list args; - va_start(args, format); - WmAsyncTraceWithArgv(isBegin, taskId, format, args); - va_end(args); - } -} - -void WmAsyncTraceWithArgv(bool isBegin, int32_t taskId, const char* format, va_list args) -{ - char name[MAX_STRING_SIZE] = { 0 }; - if (vsnprintf_s(name, sizeof(name), sizeof(name) - 1, format, args) < 0) { - return; - } - if (isBegin) { - WmAsyncTraceBegin(taskId, name); - } else { - WmAsyncTraceEnd(taskId, name); - } -} - -bool WmTraceBeginWithArgv(const char* format, va_list args) -{ - char name[MAX_STRING_SIZE] = { 0 }; - if (vsnprintf_s(name, sizeof(name), sizeof(name) - 1, format, args) < 0) { - return false; - } - WmTraceBegin(name); - return true; -} - -bool WmTraceBeginWithArgs(const char* format, ...) -{ - if (WmTraceEnabled()) { - va_list args; - va_start(args, format); - bool retVal = WmTraceBeginWithArgv(format, args); - va_end(args); - return retVal; - } - return false; -} - -WmScopedTrace::WmScopedTrace(const char* format, ...) : traceEnabled_(WmTraceEnabled()) -{ - if (traceEnabled_) { - va_list args; - va_start(args, format); - traceEnabled_ = WmTraceBeginWithArgv(format, args); - va_end(args); - } -} - -WmScopedTrace::~WmScopedTrace() -{ - if (traceEnabled_) { - WmTraceEnd(); - } -} -} // namespace Rosen -} // namespace OHOS diff --git a/wmserver/src/avoid_area_controller.cpp b/wmserver/src/avoid_area_controller.cpp index 40a8869f..36558263 100644 --- a/wmserver/src/avoid_area_controller.cpp +++ b/wmserver/src/avoid_area_controller.cpp @@ -14,10 +14,12 @@ */ #include "avoid_area_controller.h" + +#include + #include "display_manager_config.h" #include "window_helper.h" #include "window_manager_hilog.h" -#include "wm_trace.h" namespace OHOS { namespace Rosen { @@ -70,7 +72,7 @@ void AvoidAreaController::AddOrRemoveOverlayWindowIfNeed(const sptr& WLOGFE("IsOverlayWindow Failed."); return; } - WM_FUNCTION_TRACE(); + HITRACE_METER(HITRACE_TAG_WINDOW_MANAGER); uint32_t overlayId = overlayNode->GetWindowId(); bool isRecorded = (overlayWindowMap_.find(overlayId) != overlayWindowMap_.end()); @@ -150,7 +152,7 @@ void AvoidAreaController::AddOrRemoveKeyboard(const sptr& keyboardNo void AvoidAreaController::UpdateOverlayWindowIfNeed(const sptr& node, const std::function)>& checkFunc) { - WM_FUNCTION_TRACE(); + HITRACE_METER(HITRACE_TAG_WINDOW_MANAGER); if (WindowHelper::IsOverlayWindow(node->GetWindowType())) { AvoidAreaType type = WindowHelper::IsSystemBarWindow(node->GetWindowType()) ? AvoidAreaType::TYPE_SYSTEM : AvoidAreaType::TYPE_KEYBOARD; diff --git a/wmserver/src/remote_animation.cpp b/wmserver/src/remote_animation.cpp index 47021891..33427ef6 100644 --- a/wmserver/src/remote_animation.cpp +++ b/wmserver/src/remote_animation.cpp @@ -17,11 +17,12 @@ #include #include +#include #include #include "minimize_app.h" #include "window_helper.h" #include "window_manager_hilog.h" -#include "wm_trace.h" + namespace OHOS { namespace Rosen { namespace { @@ -120,7 +121,7 @@ WMError RemoteAnimation::NotifyAnimationTransition(sptr sr []() { WLOGFI("RSWindowAnimation: on finish transition with minimizeAll!"); MinimizeApp::ExecuteMinimizeAll(); - WM_SCOPED_ASYNC_END(static_cast(TraceTaskId::REMOTE_ANIMATION), + FinishAsyncTraceArgs(HITRACE_TAG_WINDOW_MANAGER, static_cast(TraceTaskId::REMOTE_ANIMATION), "wms:async:ShowRemoteAnimation"); } ); @@ -181,7 +182,7 @@ WMError RemoteAnimation::NotifyAnimationMinimize(sptr srcI if (weakNode != nullptr && weakNode->abilityToken_ != nullptr) { WLOGFI("minimize windowId: %{public}u, name:%{public}s", weakNode->GetWindowId(), weakNode->GetWindowName().c_str()); - WM_SCOPED_ASYNC_END(static_cast(TraceTaskId::REMOTE_ANIMATION), + FinishAsyncTraceArgs(HITRACE_TAG_WINDOW_MANAGER, static_cast(TraceTaskId::REMOTE_ANIMATION), "wms:async:ShowRemoteAnimation"); AAFwk::AbilityManagerClient::GetInstance()->MinimizeAbility(weakNode->abilityToken_, true); } @@ -218,7 +219,8 @@ WMError RemoteAnimation::NotifyAnimationClose(sptr srcInfo weakNode->GetWindowId(), weakNode->GetWindowName().c_str()); AAFwk::AbilityManagerClient::GetInstance()->TerminateAbility(weakNode->abilityToken_, -1); } - WM_SCOPED_ASYNC_END(static_cast(TraceTaskId::REMOTE_ANIMATION), "wms:async:ShowRemoteAnimation"); + FinishAsyncTraceArgs(HITRACE_TAG_WINDOW_MANAGER, static_cast(TraceTaskId::REMOTE_ANIMATION), + "wms:async:ShowRemoteAnimation"); } }; sptr finishedCallback = new(std::nothrow) RSWindowAnimationFinishedCallback( @@ -252,7 +254,8 @@ WMError RemoteAnimation::NotifyAnimationByHome() auto func = []() { WLOGFI("NotifyAnimationByHome in animation callback"); MinimizeApp::ExecuteMinimizeAll(); - WM_SCOPED_ASYNC_END(static_cast(TraceTaskId::REMOTE_ANIMATION), "wms:async:ShowRemoteAnimation"); + FinishAsyncTraceArgs(HITRACE_TAG_WINDOW_MANAGER, static_cast(TraceTaskId::REMOTE_ANIMATION), + "wms:async:ShowRemoteAnimation"); }; sptr finishedCallback = new(std::nothrow) RSWindowAnimationFinishedCallback( func); diff --git a/wmserver/src/starting_window.cpp b/wmserver/src/starting_window.cpp index 97e96d00..718eaf16 100644 --- a/wmserver/src/starting_window.cpp +++ b/wmserver/src/starting_window.cpp @@ -16,11 +16,12 @@ #include "starting_window.h" #include #include +#include #include #include "remote_animation.h" #include "window_helper.h" #include "window_manager_hilog.h" -#include "wm_trace.h" + namespace OHOS { namespace Rosen { namespace { @@ -107,7 +108,7 @@ void StartingWindow::DrawStartingWindow(sptr& node, sptr pixelMap, uint32_t bkgColor, bool isColdStart) { // using snapshot to support hot start since node destroy when hide - WM_SCOPED_TRACE("wms:DrawStartingWindow(%u)", node->GetWindowId()); + HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "wms:DrawStartingWindow(%u)", node->GetWindowId()); if (!isColdStart) { return; } @@ -143,7 +144,8 @@ void StartingWindow::HandleClientWindowCreate(sptr& node, sptr weak = node; auto firstFrameCompleteCallback = [weak]() { std::lock_guard lock(mutex_); - WM_SCOPED_ASYNC_END(static_cast(TraceTaskId::STARTING_WINDOW), "wms:async:ShowStartingWindow"); + FinishAsyncTraceArgs(HITRACE_TAG_WINDOW_MANAGER, static_cast(TraceTaskId::STARTING_WINDOW), + "wms:async:ShowStartingWindow"); auto weakNode = weak.promote(); if (weakNode == nullptr || weakNode->leashWinSurfaceNode_ == nullptr) { WLOGFE("windowNode or leashWinSurfaceNode_ is nullptr"); diff --git a/wmserver/src/window_controller.cpp b/wmserver/src/window_controller.cpp index 12379fe7..2ad37893 100644 --- a/wmserver/src/window_controller.cpp +++ b/wmserver/src/window_controller.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -29,7 +30,6 @@ #include "window_manager_hilog.h" #include "window_helper.h" #include "wm_common.h" -#include "wm_trace.h" namespace OHOS { namespace Rosen { @@ -50,7 +50,8 @@ void WindowController::StartingWindow(sptr info, sptr(TraceTaskId::STARTING_WINDOW), "wms:async:ShowStartingWindow"); + StartAsyncTraceArgs(HITRACE_TAG_WINDOW_MANAGER, static_cast(TraceTaskId::STARTING_WINDOW), + "wms:async:ShowStartingWindow"); auto node = windowRoot_->FindWindowNodeWithToken(info->GetAbilityToken()); auto layoutMode = windowRoot_->GetCurrentLayoutMode(info->GetDisplayId()); if (node == nullptr) { @@ -101,8 +102,9 @@ void WindowController::CancelStartingWindow(sptr abilityToken) WLOGFE("CancelStartingWindow failed because client window has shown id:%{public}u", node->GetWindowId()); return; } - WM_SCOPED_TRACE("wms:CancelStartingWindow(%u)", node->GetWindowId()); - WM_SCOPED_ASYNC_END(static_cast(TraceTaskId::STARTING_WINDOW), "wms:async:ShowStartingWindow"); + HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "wms:CancelStartingWindow(%u)", node->GetWindowId()); + FinishAsyncTraceArgs(HITRACE_TAG_WINDOW_MANAGER, static_cast(TraceTaskId::STARTING_WINDOW), + "wms:async:ShowStartingWindow"); WLOGFI("CancelStartingWindow with id:%{public}u!", node->GetWindowId()); node->isAppCrash_ = true; WMError res = windowRoot_->DestroyWindow(node->GetWindowId(), false); @@ -124,7 +126,7 @@ WMError WindowController::NotifyWindowTransition(sptr& src if (!RemoteAnimation::CheckTransition(srcInfo, srcNode, dstInfo, dstNode)) { return WMError::WM_ERROR_NO_REMOTE_ANIMATION; } - WM_SCOPED_ASYNC_TRACE_BEGIN(static_cast(TraceTaskId::REMOTE_ANIMATION), + StartAsyncTraceArgs(HITRACE_TAG_WINDOW_MANAGER, static_cast(TraceTaskId::REMOTE_ANIMATION), "wms:async:ShowRemoteAnimation"); auto transitionEvent = RemoteAnimation::GetTransitionEvent(srcInfo, dstInfo, srcNode, dstNode); switch (transitionEvent) { @@ -369,7 +371,7 @@ WMError WindowController::RequestFocus(uint32_t windowId) WMError WindowController::SetWindowMode(uint32_t windowId, WindowMode dstMode) { - WM_FUNCTION_TRACE(); + HITRACE_METER(HITRACE_TAG_WINDOW_MANAGER); auto node = windowRoot_->GetWindowNode(windowId); if (node == nullptr) { WLOGFE("could not find window"); diff --git a/wmserver/src/window_layout_policy.cpp b/wmserver/src/window_layout_policy.cpp index 07fbc7e5..7bd0f8a4 100644 --- a/wmserver/src/window_layout_policy.cpp +++ b/wmserver/src/window_layout_policy.cpp @@ -18,7 +18,6 @@ #include "window_helper.h" #include "window_manager_hilog.h" #include "wm_common_inner.h" -#include "wm_trace.h" namespace OHOS { namespace Rosen { diff --git a/wmserver/src/window_layout_policy_cascade.cpp b/wmserver/src/window_layout_policy_cascade.cpp index 87a36314..2c51aafa 100644 --- a/wmserver/src/window_layout_policy_cascade.cpp +++ b/wmserver/src/window_layout_policy_cascade.cpp @@ -15,11 +15,12 @@ #include "window_layout_policy_cascade.h" +#include + #include "minimize_app.h" #include "window_helper.h" #include "window_inner_manager.h" #include "window_manager_hilog.h" -#include "wm_trace.h" namespace OHOS { namespace Rosen { @@ -121,7 +122,7 @@ void WindowLayoutPolicyCascade::LayoutWindowTree(DisplayId displayId) void WindowLayoutPolicyCascade::RemoveWindowNode(const sptr& node) { - WM_FUNCTION_TRACE(); + HITRACE_METER(HITRACE_TAG_WINDOW_MANAGER); auto type = node->GetWindowType(); // affect other windows, trigger off global layout if (avoidTypes_.find(type) != avoidTypes_.end()) { @@ -143,7 +144,7 @@ std::vector WindowLayoutPolicyCascade::GetExitSplitPoints(DisplayId dis void WindowLayoutPolicyCascade::UpdateWindowNode(const sptr& node, bool isAddWindow) { - WM_FUNCTION_TRACE(); + HITRACE_METER(HITRACE_TAG_WINDOW_MANAGER); auto type = node->GetWindowType(); const DisplayId& displayId = node->GetDisplayId(); // affect other windows, trigger off global layout @@ -174,7 +175,7 @@ void WindowLayoutPolicyCascade::UpdateWindowNode(const sptr& node, b void WindowLayoutPolicyCascade::AddWindowNode(const sptr& node) { - WM_FUNCTION_TRACE(); + HITRACE_METER(HITRACE_TAG_WINDOW_MANAGER); auto property = node->GetWindowProperty(); if (property == nullptr) { WLOGFE("window property is nullptr."); diff --git a/wmserver/src/window_layout_policy_tile.cpp b/wmserver/src/window_layout_policy_tile.cpp index 438099bf..5a6f4c34 100644 --- a/wmserver/src/window_layout_policy_tile.cpp +++ b/wmserver/src/window_layout_policy_tile.cpp @@ -15,11 +15,12 @@ #include "window_layout_policy_tile.h" #include +#include + #include "minimize_app.h" #include "window_helper.h" #include "window_inner_manager.h" #include "window_manager_hilog.h" -#include "wm_trace.h" namespace OHOS { namespace Rosen { @@ -117,7 +118,7 @@ void WindowLayoutPolicyTile::InitTileWindowRects(DisplayId displayId) void WindowLayoutPolicyTile::AddWindowNode(const sptr& node) { - WM_FUNCTION_TRACE(); + HITRACE_METER(HITRACE_TAG_WINDOW_MANAGER); // update window size limits when add window UpdateWindowSizeLimits(node); @@ -134,7 +135,7 @@ void WindowLayoutPolicyTile::AddWindowNode(const sptr& node) void WindowLayoutPolicyTile::UpdateWindowNode(const sptr& node, bool isAddWindow) { - WM_FUNCTION_TRACE(); + HITRACE_METER(HITRACE_TAG_WINDOW_MANAGER); WindowLayoutPolicy::UpdateWindowNode(node); if (avoidTypes_.find(node->GetWindowType()) != avoidTypes_.end()) { DisplayId displayId = node->GetDisplayId(); @@ -146,7 +147,7 @@ void WindowLayoutPolicyTile::UpdateWindowNode(const sptr& node, bool void WindowLayoutPolicyTile::RemoveWindowNode(const sptr& node) { - WM_FUNCTION_TRACE(); + HITRACE_METER(HITRACE_TAG_WINDOW_MANAGER); WLOGFI("RemoveWindowNode %{public}u in tile", node->GetWindowId()); auto type = node->GetWindowType(); auto displayId = node->GetDisplayId(); diff --git a/wmserver/src/window_manager_service.cpp b/wmserver/src/window_manager_service.cpp index c3896bb1..b57f7524 100644 --- a/wmserver/src/window_manager_service.cpp +++ b/wmserver/src/window_manager_service.cpp @@ -17,6 +17,7 @@ #include #include +#include #include #include #include @@ -36,7 +37,7 @@ #include "window_manager_config.h" #include "window_manager_hilog.h" #include "wm_common.h" -#include "wm_trace.h" + namespace OHOS { namespace Rosen { namespace { @@ -356,7 +357,7 @@ WMError WindowManagerService::CreateWindow(sptr& window, sptrScheduleTask([this, pid, uid, &window, &property, &surfaceNode, &windowId, &token]() { - WM_SCOPED_TRACE("wms:CreateWindow(%u)", windowId); + HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "wms:CreateWindow(%u)", windowId); return windowController_->CreateWindow(window, property, surfaceNode, windowId, token, pid, uid); }).get(); accessTokenIdMaps_[windowId] = IPCSkeleton::GetCallingTokenID(); @@ -381,7 +382,7 @@ WMError WindowManagerService::HandleAddWindow(sptr& property) WLOGFI("[WMS] Add: %{public}5d %{public}4d %{public}4d %{public}4d [%{public}4d %{public}4d " \ "%{public}4d %{public}4d]", windowId, property->GetWindowType(), property->GetWindowMode(), property->GetWindowFlags(), rect.posX_, rect.posY_, rect.width_, rect.height_); - WM_SCOPED_TRACE("wms:AddWindow(%u)", windowId); + HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "wms:AddWindow(%u)", windowId); WMError res = windowController_->AddWindowNode(property); if (property->GetWindowType() == WindowType::WINDOW_TYPE_DRAGGING_EFFECT) { dragController_->StartDrag(windowId); @@ -393,7 +394,7 @@ WMError WindowManagerService::RemoveWindow(uint32_t windowId) { return wmsTaskLooper_->ScheduleTask([this, windowId]() { WLOGFI("[WMS] Remove: %{public}u", windowId); - WM_SCOPED_TRACE("wms:RemoveWindow(%u)", windowId); + HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "wms:RemoveWindow(%u)", windowId); return windowController_->RemoveWindowNode(windowId); }).get(); } @@ -407,7 +408,7 @@ WMError WindowManagerService::DestroyWindow(uint32_t windowId, bool onlySelf) accessTokenIdMaps_.erase(windowId); return wmsTaskLooper_->ScheduleTask([this, windowId, onlySelf]() { WLOGFI("[WMS] Destroy: %{public}u", windowId); - WM_SCOPED_TRACE("wms:DestroyWindow(%u)", windowId); + HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "wms:DestroyWindow(%u)", windowId); auto node = windowRoot_->GetWindowNode(windowId); if (node != nullptr && node->GetWindowType() == WindowType::WINDOW_TYPE_DRAGGING_EFFECT) { dragController_->FinishDrag(windowId); @@ -504,7 +505,7 @@ void WindowManagerService::OnWindowEvent(Event event, const sptr& void WindowManagerService::NotifyDisplayStateChange(DisplayId defaultDisplayId, sptr displayInfo, const std::map>& displayInfoMap, DisplayStateChangeType type) { - WM_SCOPED_TRACE("wms:NotifyDisplayStateChange(%u)", type); + HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "wms:NotifyDisplayStateChange(%u)", type); DisplayId displayId = (displayInfo == nullptr) ? DISPLAY_ID_INVALID : displayInfo->GetDisplayId(); if (type == DisplayStateChangeType::FREEZE) { freezeDisplayController_->FreezeDisplay(displayId); @@ -545,7 +546,7 @@ void WindowManagerService::ProcessPointUp(uint32_t windowId) void WindowManagerService::MinimizeAllAppWindows(DisplayId displayId) { return wmsTaskLooper_->PostTask([this, displayId]() { - WM_SCOPED_TRACE("wms:MinimizeAllAppWindows(%" PRIu64")", displayId); + HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "wms:MinimizeAllAppWindows(%" PRIu64")", displayId); WLOGFI("displayId %{public}" PRIu64"", displayId); windowController_->MinimizeAllAppWindows(displayId); }); @@ -554,7 +555,7 @@ void WindowManagerService::MinimizeAllAppWindows(DisplayId displayId) WMError WindowManagerService::ToggleShownStateForAllAppWindows() { wmsTaskLooper_->PostTask([this]() { - WM_SCOPED_TRACE("wms:ToggleShownStateForAllAppWindows"); + HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "wms:ToggleShownStateForAllAppWindows"); return windowController_->ToggleShownStateForAllAppWindows(); }); return WMError::WM_OK; @@ -571,7 +572,7 @@ WMError WindowManagerService::SetWindowLayoutMode(WindowLayoutMode mode) { return wmsTaskLooper_->ScheduleTask([this, mode]() { WLOGFI("layoutMode: %{public}u", mode); - WM_SCOPED_TRACE("wms:SetWindowLayoutMode"); + HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "wms:SetWindowLayoutMode"); return windowController_->SetWindowLayoutMode(mode); }).get(); } @@ -589,7 +590,7 @@ WMError WindowManagerService::UpdateProperty(sptr& windowPropert return WMError::WM_OK; } return wmsTaskLooper_->ScheduleTask([this, &windowProperty, action]() { - WM_SCOPED_TRACE("wms:UpdateProperty"); + HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "wms:UpdateProperty"); WMError res = windowController_->UpdateProperty(windowProperty, action); if (action == PropertyChangeAction::ACTION_UPDATE_RECT && res == WMError::WM_OK && windowProperty->GetWindowSizeChangeReason() == WindowSizeChangeReason::MOVE) { diff --git a/wmserver/src/window_node_container.cpp b/wmserver/src/window_node_container.cpp index cb94d529..d01eedc2 100644 --- a/wmserver/src/window_node_container.cpp +++ b/wmserver/src/window_node_container.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include "common_event_manager.h" @@ -32,7 +33,6 @@ #include "window_manager_hilog.h" #include "wm_common.h" #include "wm_common_inner.h" -#include "wm_trace.h" namespace OHOS { namespace Rosen { @@ -361,7 +361,7 @@ void WindowNodeContainer::UpdateSizeChangeReason(sptr& node, WindowS void WindowNodeContainer::UpdateWindowTree(sptr& node) { - WM_FUNCTION_TRACE(); + HITRACE_METER(HITRACE_TAG_WINDOW_MANAGER); node->priority_ = zorderPolicy_->GetWindowPriority(node->GetWindowType()); RaiseInputMethodWindowPriorityIfNeeded(node); RaiseShowWhenLockedWindowIfNeeded(node); @@ -386,7 +386,7 @@ void WindowNodeContainer::UpdateWindowTree(sptr& node) bool WindowNodeContainer::UpdateRSTree(sptr& node, DisplayId displayId, bool isAdd, bool animationPlayed) { - WM_FUNCTION_TRACE(); + HITRACE_METER(HITRACE_TAG_WINDOW_MANAGER); if (node->GetWindowProperty()->GetCustomAnimation()) { WLOGFI("not need to update RsTree since SystemWindowAnimation is playing"); return false; @@ -424,9 +424,9 @@ bool WindowNodeContainer::UpdateRSTree(sptr& node, DisplayId display // default transition curve: EASE OUT static const Rosen::RSAnimationTimingCurve curve = Rosen::RSAnimationTimingCurve::EASE_OUT; // add window with transition animation - WM_SCOPED_TRACE_BEGIN("Animate(%u)", node->GetWindowId()); + StartTraceArgs(HITRACE_TAG_WINDOW_MANAGER, "Animate(%u)", node->GetWindowId()); RSNode::Animate(timingProtocol, curve, updateRSTreeFunc); - WM_SCOPED_TRACE_END(); + FinishTrace(HITRACE_TAG_WINDOW_MANAGER); } else { // add or remove window without animation WLOGFI("add or remove window without animation"); @@ -686,7 +686,8 @@ void WindowNodeContainer::HandleKeepScreenOn(const sptr& node, bool return; } WLOGFI("handle keep screen on: [%{public}s, %{public}d]", node->GetWindowName().c_str(), requireLock); - WM_SCOPED_TRACE("container:HandleKeepScreenOn(%s, %d)", node->GetWindowName().c_str(), requireLock); + HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "container:HandleKeepScreenOn(%s, %d)", + node->GetWindowName().c_str(), requireLock); ErrCode res; // reset ipc identity std::string identity = IPCSkeleton::ResetCallingIdentity(); @@ -790,7 +791,7 @@ void WindowNodeContainer::ProcessWindowAvoidAreaChangeWhenDisplayChange() const void WindowNodeContainer::NotifyIfSystemBarTintChanged(DisplayId displayId) const { - WM_FUNCTION_TRACE(); + HITRACE_METER(HITRACE_TAG_WINDOW_MANAGER); auto expectSystemBarProp = GetExpectImmersiveProperty(); SystemBarRegionTints tints; SysBarTintMap& sysBarTintMap = displayGroupController_->sysBarTintMaps_[displayId]; @@ -810,7 +811,7 @@ void WindowNodeContainer::NotifyIfSystemBarTintChanged(DisplayId displayId) cons void WindowNodeContainer::NotifyIfSystemBarRegionChanged(DisplayId displayId) const { - WM_FUNCTION_TRACE(); + HITRACE_METER(HITRACE_TAG_WINDOW_MANAGER); SystemBarRegionTints tints; SysBarTintMap& sysBarTintMap = displayGroupController_->sysBarTintMaps_[displayId]; SysBarNodeMap& sysBarNodeMap = displayGroupController_->sysBarNodeMaps_[displayId]; @@ -899,7 +900,7 @@ void WindowNodeContainer::NotifySystemBarTints(std::vector displayIdV void WindowNodeContainer::NotifyDockWindowStateChanged(sptr& node, bool isEnable) { - WM_FUNCTION_TRACE(); + HITRACE_METER(HITRACE_TAG_WINDOW_MANAGER); WLOGFI("[Immersive] begin isEnable: %{public}d", isEnable); if (isEnable) { for (auto& windowNode : appWindowNode_->children_) { diff --git a/wmserver/src/window_pair.cpp b/wmserver/src/window_pair.cpp index fc1f1962..4aafd31b 100644 --- a/wmserver/src/window_pair.cpp +++ b/wmserver/src/window_pair.cpp @@ -20,7 +20,6 @@ #include "minimize_app.h" #include "window_manager_hilog.h" #include "window_helper.h" -#include "wm_trace.h" #include "window_inner_manager.h" diff --git a/wmserver/src/window_root.cpp b/wmserver/src/window_root.cpp index 41cf89c9..1532d56b 100644 --- a/wmserver/src/window_root.cpp +++ b/wmserver/src/window_root.cpp @@ -18,12 +18,12 @@ #include #include #include +#include #include #include "display_manager_service_inner.h" #include "window_helper.h" #include "window_manager_hilog.h" #include "window_manager_service.h" -#include "wm_trace.h" #include "window_manager_agent_controller.h" namespace OHOS { @@ -215,7 +215,7 @@ WMError WindowRoot::SaveWindow(const sptr& node) WMError WindowRoot::MinimizeStructuredAppWindowsExceptSelf(sptr& node) { - WM_SCOPED_TRACE("root:MinimizeStructuredAppWindowsExceptSelf"); + HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "root:MinimizeStructuredAppWindowsExceptSelf"); auto container = GetOrCreateWindowNodeContainer(node->GetDisplayId()); if (container == nullptr) { WLOGFE("MinimizeAbility failed, window container could not be found"); diff --git a/wmserver/src/window_snapshot/snapshot_controller.cpp b/wmserver/src/window_snapshot/snapshot_controller.cpp index 82977585..c11638be 100644 --- a/wmserver/src/window_snapshot/snapshot_controller.cpp +++ b/wmserver/src/window_snapshot/snapshot_controller.cpp @@ -14,9 +14,11 @@ */ #include "snapshot_controller.h" + +#include + #include "window_manager_hilog.h" #include "wm_common.h" -#include "wm_trace.h" namespace OHOS { namespace Rosen { @@ -46,7 +48,7 @@ WMError SnapshotController::TakeSnapshot(const std::shared_ptr& s int32_t SnapshotController::GetSnapshot(const sptr &token, Snapshot& snapshot) { - WM_SCOPED_TRACE("wms:GetSnapshot"); + HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "wms:GetSnapshot"); if (token == nullptr) { WLOGFE("Get ailityToken failed!"); return static_cast(WMError::WM_ERROR_NULLPTR); From 294151fb22078e5ab908f7e262f66d15dc8540f5 Mon Sep 17 00:00:00 2001 From: dubj Date: Mon, 4 Jul 2022 17:33:46 +0800 Subject: [PATCH 73/81] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E5=88=87=E6=8D=A2=E5=8E=9F=E7=94=A8=E6=88=B7=E7=AA=97=E5=8F=A3?= =?UTF-8?q?=E4=B8=8D=E6=B6=88=E5=A4=B1=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: dubj Change-Id: I4d6983bd670944ef80795ca0557f005a04c7602d --- wmserver/BUILD.gn | 1 + wmserver/include/window_common_event.h | 61 ++++++++++++++ wmserver/include/window_manager_service.h | 4 + wmserver/include/window_node_container.h | 1 + wmserver/include/window_root.h | 1 + wmserver/src/window_common_event.cpp | 96 +++++++++++++++++++++++ wmserver/src/window_manager_service.cpp | 19 +++++ wmserver/src/window_node_container.cpp | 19 +++++ wmserver/src/window_root.cpp | 14 ++++ 9 files changed, 216 insertions(+) create mode 100644 wmserver/include/window_common_event.h create mode 100644 wmserver/src/window_common_event.cpp diff --git a/wmserver/BUILD.gn b/wmserver/BUILD.gn index 6637bc4c..f56c3b65 100644 --- a/wmserver/BUILD.gn +++ b/wmserver/BUILD.gn @@ -48,6 +48,7 @@ ohos_shared_library("libwms") { "src/minimize_app.cpp", "src/remote_animation.cpp", "src/starting_window.cpp", + "src/window_common_event.cpp", "src/window_controller.cpp", "src/window_dumper.cpp", "src/window_inner_manager.cpp", diff --git a/wmserver/include/window_common_event.h b/wmserver/include/window_common_event.h new file mode 100644 index 00000000..273a1170 --- /dev/null +++ b/wmserver/include/window_common_event.h @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2022 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 WINDOW_COMMON_EVENT_H +#define WINDOW_COMMON_EVENT_H + +#include +#include +#include +#include + +#include "window_root.h" +#include "window_task_looper.h" + +namespace OHOS { +namespace Rosen { +class WindowCommonEvent : public RefBase, public std::enable_shared_from_this { +public: + WindowCommonEvent(); + ~WindowCommonEvent(); + void SubscriberEvent(); + void UnSubscriberEvent(); + void OnReceiveEvent(const EventFwk::CommonEventData& data); +private: + class EventSubscriber : public EventFwk::CommonEventSubscriber { + public: + EventSubscriber(const EventFwk::CommonEventSubscribeInfo &subscriberInfo, + const std::shared_ptr& eventHandler) + : EventFwk::CommonEventSubscriber(subscriberInfo), eventHandler_(eventHandler) {}; + ~EventSubscriber() = default; + void OnReceiveEvent(const EventFwk::CommonEventData& data) override + { + eventHandler_->OnReceiveEvent(data); + } + private: + std::shared_ptr eventHandler_; + }; + void SubscriberEventInner(int retry); + void HandleAccountSwitched(const EventFwk::CommonEventData& data) const; + + typedef void (WindowCommonEvent::*HandleCommonEventFunc)(const EventFwk::CommonEventData& data) const; + + std::map handleCommonEventFuncs_; + std::shared_ptr subscriber_; + std::shared_ptr eventHandler_; +}; +} // Rosen +} // OHOS +#endif // WINDOW_COMMON_EVENT_H \ No newline at end of file diff --git a/wmserver/include/window_manager_service.h b/wmserver/include/window_manager_service.h index 536c9812..87e762e0 100644 --- a/wmserver/include/window_manager_service.h +++ b/wmserver/include/window_manager_service.h @@ -29,6 +29,7 @@ #include "freeze_controller.h" #include "singleton_delegator.h" #include "wm_single_instance.h" +#include "window_common_event.h" #include "window_controller.h" #include "zidl/window_manager_stub.h" #include "window_dumper.h" @@ -65,6 +66,7 @@ WM_DECLARE_SINGLE_INSTANCE_BASE(WindowManagerService); public: void OnStart() override; void OnStop() override; + void OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override; int Dump(int fd, const std::vector& args) override; WMError CreateWindow(sptr& window, sptr& property, @@ -103,6 +105,7 @@ public: void MinimizeWindowsByLauncher(std::vector windowIds, bool isAnimated, sptr& finishCallback) override; void GetWindowPreferredOrientation(DisplayId displayId, Orientation &orientation); + void OnAccountSwitched() const; protected: WindowManagerService(); virtual ~WindowManagerService() = default; @@ -132,6 +135,7 @@ private: SystemConfig systemConfig_; ModeChangeHotZonesConfig hotZonesConfig_ { false, 0, 0, 0 }; std::unique_ptr wmsTaskLooper_; + std::shared_ptr windowCommonEvent_; RSInterfaces& rsInterface_; bool startingOpen_ = true; }; diff --git a/wmserver/include/window_node_container.h b/wmserver/include/window_node_container.h index c98da05e..f4d55f91 100644 --- a/wmserver/include/window_node_container.h +++ b/wmserver/include/window_node_container.h @@ -110,6 +110,7 @@ public: void BeforeProcessWindowAvoidAreaChangeWhenDisplayChange() const; void ProcessWindowAvoidAreaChangeWhenDisplayChange() const; WindowLayoutMode GetCurrentLayoutMode() const; + void RemoveSingleUserWindowNodes(); private: void TraverseWindowNode(sptr& root, std::vector>& windowNodes) const; diff --git a/wmserver/include/window_root.h b/wmserver/include/window_root.h index 8e7128e9..c22d5969 100644 --- a/wmserver/include/window_root.h +++ b/wmserver/include/window_root.h @@ -97,6 +97,7 @@ public: void SetExitSplitRatios(const std::vector& exitSplitRatios); void MinimizeTargetWindows(std::vector& windowIds); WindowLayoutMode GetCurrentLayoutMode(DisplayId displayId); + void RemoveSingleUserWindowNodes(); private: void OnRemoteDied(const sptr& remoteObject); WMError DestroyWindowInner(sptr& node); diff --git a/wmserver/src/window_common_event.cpp b/wmserver/src/window_common_event.cpp new file mode 100644 index 00000000..3d15bcfa --- /dev/null +++ b/wmserver/src/window_common_event.cpp @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2022 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_common_event.h" + +#include +#include +#include "common_event_subscribe_info.h" +#include "event_runner.h" +#include "skills.h" +#include "window_manager_hilog.h" +#include "window_manager_service.h" + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowCommonEvent"}; + constexpr int RETRY_MAX_COUNT = 3; + const std::string THREAD_ID = "window_common_event_handler"; +} + +WindowCommonEvent::WindowCommonEvent() +{ + handleCommonEventFuncs_.insert(make_pair(EventFwk::CommonEventSupport::COMMON_EVENT_USER_SWITCHED, + &WindowCommonEvent::HandleAccountSwitched)); + auto runner = AppExecFwk::EventRunner::Create(THREAD_ID); + eventHandler_ = std::make_shared(runner); +} + +WindowCommonEvent::~WindowCommonEvent() +{ +} + +void WindowCommonEvent::SubscriberEvent() +{ + EventFwk::MatchingSkills skills; + skills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_USER_SWITCHED); + EventFwk::CommonEventSubscribeInfo info(skills); + subscriber_ = std::make_shared(info, shared_from_this()); + int retry = RETRY_MAX_COUNT; + SubscriberEventInner(retry); +} + +void WindowCommonEvent::SubscriberEventInner(int retry) +{ + if (retry <= 0) { + return; + } + retry--; + WLOGFI("called action = %{public}d", retry); + if (EventFwk::CommonEventManager::SubscribeCommonEvent(subscriber_)) { + return; + } + std::function func = std::bind(&WindowCommonEvent::SubscriberEventInner, this, retry); + // post task delay 500ms + eventHandler_->PostTask(func, 500, AppExecFwk::EventQueue::Priority::HIGH); +} + +void WindowCommonEvent::UnSubscriberEvent() +{ + auto task = [this] { + EventFwk::CommonEventManager::UnSubscribeCommonEvent(subscriber_); + }; + eventHandler_->PostTask(task, AppExecFwk::EventQueue::Priority::HIGH); +} + +void WindowCommonEvent::OnReceiveEvent(const EventFwk::CommonEventData& data) +{ + auto task = [this, data] { + std::string action = data.GetWant().GetAction(); + WLOGFI("called action = %{public}s", action.c_str()); + if (handleCommonEventFuncs_.count(action)) { + (this->*handleCommonEventFuncs_[action])(data); + } + }; + eventHandler_->PostTask(task, AppExecFwk::EventQueue::Priority::HIGH); +} + +void WindowCommonEvent::HandleAccountSwitched(const EventFwk::CommonEventData& data) const +{ + WindowManagerService::GetInstance().OnAccountSwitched(); +} +} // Rosen +} // OHOS \ No newline at end of file diff --git a/wmserver/src/window_manager_service.cpp b/wmserver/src/window_manager_service.cpp index 7421b291..a477013b 100644 --- a/wmserver/src/window_manager_service.cpp +++ b/wmserver/src/window_manager_service.cpp @@ -57,6 +57,7 @@ WindowManagerService::WindowManagerService() : SystemAbility(WINDOW_MANAGER_SERV dragController_ = new DragController(windowRoot_); windowDumper_ = new WindowDumper(windowRoot_); freezeDisplayController_ = new FreezeController(); + windowCommonEvent_ = std::make_shared(); wmsTaskLooper_ = std::make_unique(); startingOpen_ = system::GetParameter("persist.window.sw.enabled", "1") == "1"; // startingWin default enabled } @@ -74,9 +75,26 @@ void WindowManagerService::OnStart() RegisterWindowManagerServiceHandler(); RegisterWindowVisibilityChangeCallback(); wmsTaskLooper_->Start(); + AddSystemAbilityListener(COMMON_EVENT_SERVICE_ID); } +void WindowManagerService::OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId) +{ + WLOGFI(" %{public}d", systemAbilityId); + if (systemAbilityId == COMMON_EVENT_SERVICE_ID) { + windowCommonEvent_->SubscriberEvent(); + } +} + +void WindowManagerService::OnAccountSwitched() const +{ + wmsTaskLooper_->PostTask([this]() { + windowRoot_->RemoveSingleUserWindowNodes(); + }); + WLOGFI("called"); +} + void WindowManagerService::WindowVisibilityChangeCallback(std::shared_ptr occlusionData) { WLOGFD("NotifyWindowVisibilityChange: enter"); @@ -285,6 +303,7 @@ void WindowManagerService::ConfigureWindowManagerService() void WindowManagerService::OnStop() { + windowCommonEvent_->UnSubscriberEvent(); WindowInnerManager::GetInstance().Stop(); WLOGFI("ready to stop service."); } diff --git a/wmserver/src/window_node_container.cpp b/wmserver/src/window_node_container.cpp index 0a26923b..45750ac7 100644 --- a/wmserver/src/window_node_container.cpp +++ b/wmserver/src/window_node_container.cpp @@ -1892,5 +1892,24 @@ WindowLayoutMode WindowNodeContainer::GetCurrentLayoutMode() const { return layoutMode_; } + +void WindowNodeContainer::RemoveSingleUserWindowNodes() +{ + std::vector> windowNodes; + TraverseContainer(windowNodes); + for (auto& windowNode : windowNodes) { + if (windowNode->GetWindowType() == WindowType::WINDOW_TYPE_DESKTOP || + windowNode->GetWindowType() == WindowType::WINDOW_TYPE_STATUS_BAR || + windowNode->GetWindowType() == WindowType::WINDOW_TYPE_NAVIGATION_BAR || + windowNode->GetWindowType() == WindowType::WINDOW_TYPE_KEYGUARD || + windowNode->GetWindowType() == WindowType::WINDOW_TYPE_POINTER) { + continue; + } + WLOGFI("remove window %{public}s, windowId %{public}d", + windowNode->GetWindowName().c_str(), windowNode->GetWindowId()); + windowNode->GetWindowProperty()->SetAnimationFlag(static_cast(WindowAnimation::NONE)); + RemoveWindowNode(windowNode); + } +} } // namespace Rosen } // namespace OHOS diff --git a/wmserver/src/window_root.cpp b/wmserver/src/window_root.cpp index d13e9626..02fccb5a 100644 --- a/wmserver/src/window_root.cpp +++ b/wmserver/src/window_root.cpp @@ -19,6 +19,7 @@ #include #include #include + #include "display_manager_service_inner.h" #include "window_helper.h" #include "window_manager_hilog.h" @@ -1318,5 +1319,18 @@ WindowLayoutMode WindowRoot::GetCurrentLayoutMode(DisplayId displayId) } return container->GetCurrentLayoutMode(); } + +void WindowRoot::RemoveSingleUserWindowNodes() +{ + std::vector displayIds = GetAllDisplayIds(); + for (auto id : displayIds) { + sptr container = GetOrCreateWindowNodeContainer(id); + if (container == nullptr) { + WLOGFI("get container failed %{public}" PRIu64"", id); + continue; + } + container->RemoveSingleUserWindowNodes(); + } +} } // namespace Rosen } // namespace OHOS From 6711b144fb13b5188bd584d1c38b99fa65551b54 Mon Sep 17 00:00:00 2001 From: l00574490 Date: Wed, 6 Jul 2022 17:06:00 +0800 Subject: [PATCH 74/81] fix resume mode when exit spli Signed-off-by: l00574490 Change-Id: I447cdcc2b652eda2ea2b0fafbd159f72ca4154e1 --- utils/src/window_property.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/utils/src/window_property.cpp b/utils/src/window_property.cpp index fdf652d5..2b9f8033 100644 --- a/utils/src/window_property.cpp +++ b/utils/src/window_property.cpp @@ -205,7 +205,12 @@ WindowSizeChangeReason WindowProperty::GetWindowSizeChangeReason() const void WindowProperty::ResumeLastWindowMode() { + // if lastMode isn't supported, get supported mode from supportModeInfo if (!WindowHelper::IsWindowModeSupported(modeSupportInfo_, lastMode_)) { + auto mode = WindowHelper::GetWindowModeFromModeSupportInfo(modeSupportInfo_); + if (!WindowHelper::IsSplitWindowMode(mode)) { + mode_ = mode; + } return; } mode_ = lastMode_; From f976c54551cb6549cd22142d1480b3a8b259f7b8 Mon Sep 17 00:00:00 2001 From: maojiangping Date: Wed, 6 Jul 2022 20:02:09 +0800 Subject: [PATCH 75/81] Optimize the handling of the back key. Signed-off-by: maojiangping Change-Id: Ib199df9f170283c7288a8d297982617890c15cf3 --- wm/include/window_impl.h | 2 +- wm/src/window_impl.cpp | 25 +++++++++++-------------- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/wm/include/window_impl.h b/wm/include/window_impl.h index 3d315995..f7250c2a 100644 --- a/wm/include/window_impl.h +++ b/wm/include/window_impl.h @@ -346,7 +346,7 @@ private: void UpdatePointerEventForStretchableWindow(std::shared_ptr& pointerEvent); void UpdateDragType(); void InitListenerHandler(); - void HandleBackKeyEvent(const std::shared_ptr& keyEvent); + void HandleBackKeyPressedEvent(const std::shared_ptr& keyEvent); bool CheckCameraFloatingWindowMultiCreated(WindowType type); void GetConfigurationFromAbilityInfo(); void UpdateTitleButtonVisibility(); diff --git a/wm/src/window_impl.cpp b/wm/src/window_impl.cpp index 666b9e8e..ce625c30 100644 --- a/wm/src/window_impl.cpp +++ b/wm/src/window_impl.cpp @@ -1705,12 +1705,8 @@ void WindowImpl::UpdateModeSupportInfo(uint32_t modeSupportInfo) UpdateTitleButtonVisibility(); } -void WindowImpl::HandleBackKeyEvent(const std::shared_ptr& keyEvent) +void WindowImpl::HandleBackKeyPressedEvent(const std::shared_ptr& keyEvent) { - int32_t keyAction = keyEvent->GetKeyAction(); - if (keyAction != MMI::KeyEvent::KEY_ACTION_UP) { - return; - } std::shared_ptr inputEventConsumer; { std::lock_guard lock(mutex_); @@ -1730,6 +1726,7 @@ void WindowImpl::HandleBackKeyEvent(const std::shared_ptr& keyEve WLOGFE("There is no back key event consumer"); } if (isConsumed || !WindowHelper::IsMainWindow(property_->GetWindowType())) { + WLOGFI("Back key event is consumed or it is not a main window"); return; } auto abilityContext = AbilityRuntime::Context::ConvertTo(context_); @@ -1738,17 +1735,17 @@ void WindowImpl::HandleBackKeyEvent(const std::shared_ptr& keyEve return; } // TerminateAbility will invoke last ability, CloseAbility will not. - bool shouldCloseAbility = WindowHelper::IsFullScreenWindow(property_->GetWindowMode()); - WMError ret = NotifyWindowTransition(shouldCloseAbility ? TransitionReason::CLOSE : TransitionReason::BACK); + bool shouldTerminateAbility = WindowHelper::IsFullScreenWindow(property_->GetWindowMode()); + WMError ret = NotifyWindowTransition(shouldTerminateAbility ? TransitionReason::BACK : TransitionReason::CLOSE); if (ret != WMError::WM_OK) { - WLOGFI("Window %{public}u is closed without remote animation, ret:%{public}u", - property_->GetWindowId(), static_cast(ret)); - if (shouldCloseAbility) { - abilityContext->CloseAbility(); - } else { + if (shouldTerminateAbility) { abilityContext->TerminateSelf(); + } else { + abilityContext->CloseAbility(); } } + WLOGFI("Window %{public}u will be closed, WindowTransition ret: %{public}u, shouldTerminateAbility: %{public}u", + property_->GetWindowId(), static_cast(ret), static_cast(shouldTerminateAbility)); } void WindowImpl::ConsumeKeyEvent(std::shared_ptr& keyEvent) @@ -1757,8 +1754,8 @@ void WindowImpl::ConsumeKeyEvent(std::shared_ptr& keyEvent) int32_t keyCode = keyEvent->GetKeyCode(); int32_t keyAction = keyEvent->GetKeyAction(); WLOGFI("KeyCode: %{public}d, action: %{public}d", keyCode, keyAction); - if (keyCode == MMI::KeyEvent::KEYCODE_BACK) { - HandleBackKeyEvent(keyEvent); + if (keyCode == MMI::KeyEvent::KEYCODE_BACK && keyAction == MMI::KeyEvent::KEY_ACTION_UP) { + HandleBackKeyPressedEvent(keyEvent); } else { std::shared_ptr inputEventConsumer; { From 0e0f752fc5b1eab93d6c921c07f9107a11f1fa1b Mon Sep 17 00:00:00 2001 From: xiaojianfeng Date: Wed, 6 Jul 2022 16:27:52 +0800 Subject: [PATCH 76/81] resize float calling window when call soft input Signed-off-by: xiaojianfeng Change-Id: I816cda27a3e1ec9f3f7ddc0470198dd4b606afaf --- wmserver/include/window_controller.h | 4 ++ wmserver/src/avoid_area_controller.cpp | 5 +- wmserver/src/window_controller.cpp | 79 +++++++++++++++++++++++++- wmserver/src/window_node_container.cpp | 2 +- 4 files changed, 83 insertions(+), 7 deletions(-) diff --git a/wmserver/include/window_controller.h b/wmserver/include/window_controller.h index 83526c1f..beb2a566 100644 --- a/wmserver/include/window_controller.h +++ b/wmserver/include/window_controller.h @@ -78,6 +78,8 @@ private: WMError ResizeRect(uint32_t windowId, const Rect& rect, WindowSizeChangeReason reason); WMError SetWindowMode(uint32_t windowId, WindowMode dstMode); void ResizeSystemBarPropertySizeIfNeed(const sptr& node); + void ResizeSoftInputCallingWindowIfNeed(const sptr& node); + void RestoreCallingWindowSizeIfNeed(); void HandleTurnScreenOn(const sptr& node); void ProcessSystemBarChange(const sptr& displayInfo); WMError UpdateTouchHotAreas(const sptr& node, const std::vector& rects); @@ -93,6 +95,8 @@ private: { WindowType::WINDOW_TYPE_NAVIGATION_BAR, INVALID_WINDOW_ID }, }; bool isScreenLocked_ { false }; + Rect callingWindowRestoringRect_ { 0, 0, 0, 0 }; + uint32_t callingWindowId_ = 0u; }; } // Rosen } // OHOS diff --git a/wmserver/src/avoid_area_controller.cpp b/wmserver/src/avoid_area_controller.cpp index 40a8869f..b5c3d5c8 100644 --- a/wmserver/src/avoid_area_controller.cpp +++ b/wmserver/src/avoid_area_controller.cpp @@ -122,7 +122,7 @@ void AvoidAreaController::AddOrRemoveKeyboard(const sptr& keyboardNo if (lastKeyboardAreaUpdatedWindow != nullptr && lastKeyboardAreaUpdatedWindow != callingWindow) { const WindowMode windowMode = lastKeyboardAreaUpdatedWindow->GetWindowMode(); if (windowMode == WindowMode::WINDOW_MODE_FULLSCREEN || windowMode == WindowMode::WINDOW_MODE_SPLIT_PRIMARY || - windowMode == WindowMode::WINDOW_MODE_SPLIT_SECONDARY || windowMode == WindowMode::WINDOW_MODE_FLOATING) { + windowMode == WindowMode::WINDOW_MODE_SPLIT_SECONDARY) { auto avoidArea = GetAvoidAreaByType(lastKeyboardAreaUpdatedWindow, AvoidAreaType::TYPE_KEYBOARD); UpdateAvoidAreaIfNeed(avoidArea, lastKeyboardAreaUpdatedWindow, AvoidAreaType::TYPE_KEYBOARD); } @@ -135,8 +135,7 @@ void AvoidAreaController::AddOrRemoveKeyboard(const sptr& keyboardNo const WindowMode callingWindowMode = callingWindow->GetWindowMode(); if (callingWindowMode == WindowMode::WINDOW_MODE_FULLSCREEN || callingWindowMode == WindowMode::WINDOW_MODE_SPLIT_PRIMARY || - callingWindowMode == WindowMode::WINDOW_MODE_SPLIT_SECONDARY || - callingWindowMode == WindowMode::WINDOW_MODE_FLOATING) { + callingWindowMode == WindowMode::WINDOW_MODE_SPLIT_SECONDARY) { auto avoidArea = GetAvoidAreaByType(callingWindow, AvoidAreaType::TYPE_KEYBOARD); bool res = UpdateAvoidAreaIfNeed(avoidArea, callingWindow, AvoidAreaType::TYPE_KEYBOARD); if (res) { diff --git a/wmserver/src/window_controller.cpp b/wmserver/src/window_controller.cpp index 12379fe7..bcfe6aac 100644 --- a/wmserver/src/window_controller.cpp +++ b/wmserver/src/window_controller.cpp @@ -235,11 +235,67 @@ WMError WindowController::AddWindowNode(sptr& property) sysBarWinId_[node->GetWindowType()] = node->GetWindowId(); ResizeSystemBarPropertySizeIfNeed(node); } + if (node->GetWindowType() == WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT) { + ResizeSoftInputCallingWindowIfNeed(node); + } StopBootAnimationIfNeed(node->GetWindowType()); MinimizeApp::ExecuteMinimizeAll(); return WMError::WM_OK; } +void WindowController::ResizeSoftInputCallingWindowIfNeed(const sptr& node) +{ + auto callingWindowId = node->GetCallingWindow(); + auto callingWindow = windowRoot_->GetWindowNode(callingWindowId); + if (callingWindow == nullptr) { + auto windowNodeContainer = windowRoot_->GetOrCreateWindowNodeContainer(node->GetDisplayId()); + if (windowNodeContainer == nullptr) { + WLOGFE("windowNodeContainer is null, displayId:%{public}" PRIu64"", node->GetDisplayId()); + return; + } + callingWindowId = windowNodeContainer->GetFocusWindow(); + callingWindow = windowRoot_->GetWindowNode(callingWindowId); + } + if (callingWindow == nullptr || !callingWindow->currentVisibility_ || + callingWindow->GetWindowMode() != WindowMode::WINDOW_MODE_FLOATING) { + WLOGFE("callingWindow is null or invisible or not float window, callingWindowId:%{public}u", callingWindowId); + return; + } + Rect softInputWindowRect = node->GetWindowRect(); + Rect callingWindowRect = callingWindow->GetWindowRect(); + Rect rect = WindowHelper::GetOverlap(softInputWindowRect, callingWindowRect, 0, 0); + if (WindowHelper::IsEmptyRect(rect)) { + WLOGFE("there is no overlap"); + return; + } + Rect requestedRect = callingWindowRect; + requestedRect.posY_ = softInputWindowRect.posY_ - static_cast(requestedRect.height_); + Rect statusBarWindowRect = { 0, 0, 0, 0 }; + auto statusbarWindow = windowRoot_->GetWindowNode(sysBarWinId_[WindowType::WINDOW_TYPE_STATUS_BAR]); + if (statusbarWindow != nullptr && statusbarWindow->parent_ != nullptr) { + statusBarWindowRect = statusbarWindow->GetWindowRect(); + } + int32_t posY = std::max(requestedRect.posY_, static_cast(statusBarWindowRect.height_)); + if (posY != requestedRect.posY_) { + requestedRect.height_ = softInputWindowRect.posY_ - posY; + requestedRect.posY_ = posY; + } + callingWindowRestoringRect_ = callingWindowRect; + callingWindowId_ = callingWindow->GetWindowId(); + ResizeRect(callingWindowId_, requestedRect, WindowSizeChangeReason::DRAG); +} + +void WindowController::RestoreCallingWindowSizeIfNeed() +{ + auto callingWindow = windowRoot_->GetWindowNode(callingWindowId_); + if (!WindowHelper::IsEmptyRect(callingWindowRestoringRect_) && callingWindow != nullptr && + callingWindow->GetWindowMode() == WindowMode::WINDOW_MODE_FLOATING) { + ResizeRect(callingWindowId_, callingWindowRestoringRect_, WindowSizeChangeReason::DRAG); + } + callingWindowRestoringRect_ = { 0, 0, 0, 0 }; + callingWindowId_ = 0u; +} + void WindowController::ResizeSystemBarPropertySizeIfNeed(const sptr& node) { auto displayInfo = DisplayManagerServiceInner::GetInstance().GetDisplayById(node->GetDisplayId()); @@ -292,14 +348,20 @@ WMError WindowController::RemoveWindowNode(uint32_t windowId) return res; }; auto windowNode = windowRoot_->GetWindowNode(windowId); + WMError res = WMError::WM_ERROR_NO_REMOTE_ANIMATION; if (windowNode && windowNode->GetWindowType() == WindowType::WINDOW_TYPE_KEYGUARD) { if (RemoteAnimation::NotifyAnimationScreenUnlock(removeFunc) == WMError::WM_OK) { WLOGFI("NotifyAnimationScreenUnlock with remote animation"); - return WMError::WM_OK; + res = WMError::WM_OK; } } - - return removeFunc(); + if (res != WMError::WM_OK) { + res = removeFunc(); + } + if (windowNode->GetWindowType() == WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT) { + RestoreCallingWindowSizeIfNeed(); + } + return res; } WMError WindowController::DestroyWindow(uint32_t windowId, bool onlySelf) @@ -746,6 +808,17 @@ WMError WindowController::UpdateProperty(sptr& property, Propert node->SetOriginRect(property->GetOriginRect()); node->SetDragType(property->GetDragType()); ret = ResizeRect(windowId, property->GetRequestRect(), property->GetWindowSizeChangeReason()); + if (node->GetWindowMode() == WindowMode::WINDOW_MODE_FLOATING && ret == WMError::WM_OK && + callingWindowId_ != 0u && !WindowHelper::IsEmptyRect(callingWindowRestoringRect_)) { + if (property->GetWindowSizeChangeReason() != WindowSizeChangeReason::MOVE) { + callingWindowId_ = 0u; + callingWindowRestoringRect_ = { 0, 0, 0, 0 }; + } else { + auto windowRect = node->GetWindowRect(); + callingWindowRestoringRect_.posX_ = windowRect.posX_; + callingWindowRestoringRect_.posY_ = windowRect.posY_; + } + } break; } case PropertyChangeAction::ACTION_UPDATE_MODE: { diff --git a/wmserver/src/window_node_container.cpp b/wmserver/src/window_node_container.cpp index cb94d529..8b545c9e 100644 --- a/wmserver/src/window_node_container.cpp +++ b/wmserver/src/window_node_container.cpp @@ -1398,7 +1398,7 @@ WMError WindowNodeContainer::ToggleShownStateForAllAppWindows( if (node->GetWindowType() == WindowType::WINDOW_TYPE_LAUNCHER_RECENT) { recentWindowNode = node; if (node->GetWindowMode() == WindowMode::WINDOW_MODE_FULLSCREEN) { - return WMError::WM_OK; + return WMError::WM_DO_NOTHING; } } } From 09d74d69a2b9519c080954c7060c4714d08f54a4 Mon Sep 17 00:00:00 2001 From: maojiangping Date: Thu, 7 Jul 2022 10:16:43 +0800 Subject: [PATCH 77/81] Adjust library dependencies. Signed-off-by: maojiangping Change-Id: Ice7ed71ce686aed468d748dde50f0def2f53f089 Signed-off-by: maojiangping --- dm/test/systemtest/BUILD.gn | 1 - dm/test/unittest/BUILD.gn | 1 - interfaces/kits/napi/window_runtime/BUILD.gn | 4 +--- wm/test/fuzztest/window_fuzzer/BUILD.gn | 3 ++- wm/test/fuzztest/windowmanager_fuzzer/BUILD.gn | 3 ++- wm/test/fuzztest/windowscene_fuzzer/BUILD.gn | 3 ++- wm/test/systemtest/BUILD.gn | 2 +- wm/test/unittest/BUILD.gn | 1 + wmserver/BUILD.gn | 6 ------ 9 files changed, 9 insertions(+), 15 deletions(-) diff --git a/dm/test/systemtest/BUILD.gn b/dm/test/systemtest/BUILD.gn index 17887aa2..d315a00d 100644 --- a/dm/test/systemtest/BUILD.gn +++ b/dm/test/systemtest/BUILD.gn @@ -143,7 +143,6 @@ ohos_static_library("dm_systemtest_common") { "//foundation/windowmanager/dmserver:libdms", "//foundation/windowmanager/utils:libwmutil", "//foundation/windowmanager/wm:libwm", - "//foundation/windowmanager/wmserver:libwms", "//third_party/googletest:gmock", "//third_party/googletest:gtest_main", "//utils/native/base:utils", diff --git a/dm/test/unittest/BUILD.gn b/dm/test/unittest/BUILD.gn index 0f532fa6..63443328 100644 --- a/dm/test/unittest/BUILD.gn +++ b/dm/test/unittest/BUILD.gn @@ -130,7 +130,6 @@ ohos_static_library("dm_unittest_common") { "//foundation/windowmanager/snapshot:snapshot_display", "//foundation/windowmanager/utils:libwmutil", "//foundation/windowmanager/wm:libwm", - "//foundation/windowmanager/wmserver:libwms", "//third_party/googletest:gmock", "//third_party/googletest:gtest_main", "//third_party/libpng:libpng", # png diff --git a/interfaces/kits/napi/window_runtime/BUILD.gn b/interfaces/kits/napi/window_runtime/BUILD.gn index b077157a..cf31cde7 100644 --- a/interfaces/kits/napi/window_runtime/BUILD.gn +++ b/interfaces/kits/napi/window_runtime/BUILD.gn @@ -53,7 +53,6 @@ ohos_shared_library("window_native_kit") { "//foundation/graphic/graphic_2d/rosen/modules/render_service_client:librender_service_client", "//foundation/windowmanager/utils:libwmutil", "//foundation/windowmanager/wm:libwm", - "//foundation/windowmanager/wmserver:libwms", ] external_deps = [ @@ -83,7 +82,6 @@ ohos_shared_library("window_napi") { "${ability_runtime_path}/frameworks/native/appkit:appkit_native", "//foundation/windowmanager/utils:libwmutil", "//foundation/windowmanager/wm:libwm", - "//foundation/windowmanager/wmserver:libwms", "//utils/native/base:utils", ] @@ -111,13 +109,13 @@ ohos_shared_library("windowstage_kit") { ":window_native_kit", "//foundation/windowmanager/utils:libwmutil", "//foundation/windowmanager/wm:libwm", - "//foundation/windowmanager/wmserver:libwms", ] external_deps = [ "ability_runtime:ability_manager", "ability_runtime:runtime", "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", "napi:ace_napi", "utils_base:utils", ] diff --git a/wm/test/fuzztest/window_fuzzer/BUILD.gn b/wm/test/fuzztest/window_fuzzer/BUILD.gn index 67190c9f..c2fac720 100644 --- a/wm/test/fuzztest/window_fuzzer/BUILD.gn +++ b/wm/test/fuzztest/window_fuzzer/BUILD.gn @@ -34,9 +34,10 @@ ohos_fuzztest("WindowFuzzTest") { sources = [ "window_fuzzer.cpp" ] deps = [ "//foundation/windowmanager/wm:libwm", - "//foundation/windowmanager/wmserver:libwms", "//utils/native/base:utils", ] + + external_deps = [ "ipc:ipc_core" ] } ############################################################################### diff --git a/wm/test/fuzztest/windowmanager_fuzzer/BUILD.gn b/wm/test/fuzztest/windowmanager_fuzzer/BUILD.gn index 0e637c9a..80149263 100644 --- a/wm/test/fuzztest/windowmanager_fuzzer/BUILD.gn +++ b/wm/test/fuzztest/windowmanager_fuzzer/BUILD.gn @@ -35,9 +35,10 @@ ohos_fuzztest("WindowManagerFuzzTest") { sources = [ "windowmanager_fuzzer.cpp" ] deps = [ "//foundation/windowmanager/wm:libwm", - "//foundation/windowmanager/wmserver:libwms", "//utils/native/base:utils", ] + + external_deps = [ "ipc:ipc_core" ] } ############################################################################### diff --git a/wm/test/fuzztest/windowscene_fuzzer/BUILD.gn b/wm/test/fuzztest/windowscene_fuzzer/BUILD.gn index 50840542..129b5673 100644 --- a/wm/test/fuzztest/windowscene_fuzzer/BUILD.gn +++ b/wm/test/fuzztest/windowscene_fuzzer/BUILD.gn @@ -39,9 +39,10 @@ ohos_fuzztest("WindowSceneFuzzTest") { "//foundation/graphic/graphic_2d/rosen/modules/render_service_client:librender_service_client", "//foundation/windowmanager/dm:libdm", "//foundation/windowmanager/wm:libwm", - "//foundation/windowmanager/wmserver:libwms", "//utils/native/base:utils", ] + + external_deps = [ "ipc:ipc_core" ] } ############################################################################### diff --git a/wm/test/systemtest/BUILD.gn b/wm/test/systemtest/BUILD.gn index 3b239fec..b1bb29c5 100644 --- a/wm/test/systemtest/BUILD.gn +++ b/wm/test/systemtest/BUILD.gn @@ -308,7 +308,6 @@ ohos_static_library("wm_systemtest_common") { "//foundation/windowmanager/dmserver:libdms", "//foundation/windowmanager/utils:libwmutil", "//foundation/windowmanager/wm:libwm", - "//foundation/windowmanager/wmserver:libwms", "//third_party/googletest:gmock", "//third_party/googletest:gtest_main", "//utils/native/base:utils", @@ -319,6 +318,7 @@ ohos_static_library("wm_systemtest_common") { "ability_base:zuri", "ability_runtime:ability_context_native", "bundle_framework:appexecfwk_base", + "ipc:ipc_core", ] } ## Build wm_systemtest_common.a }}} diff --git a/wm/test/unittest/BUILD.gn b/wm/test/unittest/BUILD.gn index 961d0a97..3da98492 100644 --- a/wm/test/unittest/BUILD.gn +++ b/wm/test/unittest/BUILD.gn @@ -195,6 +195,7 @@ ohos_static_library("wm_unittest_common") { "ability_base:want", "ability_runtime:ability_context_native", "bundle_framework:appexecfwk_base", + "ipc:ipc_core", ] } ## Build wm_unittest_common.a }}} diff --git a/wmserver/BUILD.gn b/wmserver/BUILD.gn index c58f3fc0..4576e0ba 100644 --- a/wmserver/BUILD.gn +++ b/wmserver/BUILD.gn @@ -73,12 +73,6 @@ ohos_shared_library("libwms") { "//foundation/windowmanager/dmserver:libdms", "//foundation/windowmanager/utils:libwmutil", "//foundation/windowmanager/wm:libwm", - "//third_party/libxml2:xml2", - ] - - public_deps = [ - # IMS libdms need delete it - "//foundation/multimodalinput/input/frameworks/proxy:libmmi-client", ] external_deps = [ From c795a018e4e84c23c1eda8a4d474ef8f334e0de3 Mon Sep 17 00:00:00 2001 From: xpeng Date: Thu, 7 Jul 2022 14:56:37 +0800 Subject: [PATCH 78/81] Add orientation enum bind Signed-off-by: xpeng Change-Id: I034ed7cf05c85e2655b902a9ab98b1300d560504 --- .../window_manager_napi/js_window_manager.cpp | 1 + .../window_napi/js_window_utils.cpp | 43 +++++++++++++++++++ .../window_napi/js_window_utils.h | 1 + 3 files changed, 45 insertions(+) diff --git a/interfaces/kits/napi/window_runtime/window_manager_napi/js_window_manager.cpp b/interfaces/kits/napi/window_runtime/window_manager_napi/js_window_manager.cpp index e0e4e4c6..b4feccc0 100644 --- a/interfaces/kits/napi/window_runtime/window_manager_napi/js_window_manager.cpp +++ b/interfaces/kits/napi/window_runtime/window_manager_napi/js_window_manager.cpp @@ -586,6 +586,7 @@ NativeValue* JsWindowManagerInit(NativeEngine* engine, NativeValue* exportObj) object->SetProperty("ColorSpace", ColorSpaceInit(engine)); object->SetProperty("WindowStageEventType", WindowStageEventTypeInit(engine)); object->SetProperty("WindowLayoutMode", WindowLayoutModeInit(engine)); + object->SetProperty("Orientation", OrientationInit(engine)); BindNativeFunction(*engine, *object, "create", JsWindowManager::CreateWindow); BindNativeFunction(*engine, *object, "find", JsWindowManager::FindWindow); BindNativeFunction(*engine, *object, "on", JsWindowManager::RegisterWindowManagerCallback); diff --git a/interfaces/kits/napi/window_runtime/window_napi/js_window_utils.cpp b/interfaces/kits/napi/window_runtime/window_napi/js_window_utils.cpp index 7baa240e..00dd8614 100644 --- a/interfaces/kits/napi/window_runtime/window_napi/js_window_utils.cpp +++ b/interfaces/kits/napi/window_runtime/window_napi/js_window_utils.cpp @@ -158,6 +158,49 @@ NativeValue* ColorSpaceInit(NativeEngine* engine) return objValue; } +NativeValue* OrientationInit(NativeEngine* engine) +{ + WLOGFI("[NAPI]OrientationInit"); + + if (engine == nullptr) { + WLOGFE("[NAPI]Engine is nullptr"); + return nullptr; + } + + NativeValue *objValue = engine->CreateObject(); + NativeObject *object = ConvertNativeValueTo(objValue); + if (object == nullptr) { + WLOGFE("[NAPI]Failed to get object"); + return nullptr; + } + + object->SetProperty("UNSPECIFIED", CreateJsValue(*engine, + static_cast(Orientation::UNSPECIFIED))); + object->SetProperty("PORTRAIT", CreateJsValue(*engine, + static_cast(Orientation::VERTICAL))); + object->SetProperty("LANDSCAPE", CreateJsValue(*engine, + static_cast(Orientation::HORIZONTAL))); + object->SetProperty("PORTRAIT_INVERTED", CreateJsValue(*engine, + static_cast(Orientation::REVERSE_VERTICAL))); + object->SetProperty("LANDSCAPE_INVERTED", CreateJsValue(*engine, + static_cast(Orientation::REVERSE_HORIZONTAL))); + object->SetProperty("AUTO_ROTATION", CreateJsValue(*engine, + static_cast(Orientation::SENSOR))); + object->SetProperty("AUTO_ROTATION_PORTRAIT", CreateJsValue(*engine, + static_cast(Orientation::SENSOR_VERTICAL))); + object->SetProperty("AUTO_ROTATION_LANDSCAPE", CreateJsValue(*engine, + static_cast(Orientation::SENSOR_HORIZONTAL))); + object->SetProperty("AUTO_ROTATION_RESTRICTED", CreateJsValue(*engine, + static_cast(Orientation::AUTO_ROTATION_RESTRICTED))); + object->SetProperty("AUTO_ROTATION_PORTRAIT_RESTRICTED", CreateJsValue(*engine, + static_cast(Orientation::AUTO_ROTATION_PORTRAIT_RESTRICTED))); + object->SetProperty("AUTO_ROTATION_LANDSCAPE_RESTRICTED", CreateJsValue(*engine, + static_cast(Orientation::AUTO_ROTATION_LANDSCAPE_RESTRICTED))); + object->SetProperty("LOCKED", CreateJsValue(*engine, + static_cast(Orientation::LOCKED))); + return objValue; +} + NativeValue* WindowStageEventTypeInit(NativeEngine* engine) { WLOGFI("[NAPI]WindowStageEventTypeInit"); diff --git a/interfaces/kits/napi/window_runtime/window_napi/js_window_utils.h b/interfaces/kits/napi/window_runtime/window_napi/js_window_utils.h index b8c5c77a..b8ba7106 100644 --- a/interfaces/kits/napi/window_runtime/window_napi/js_window_utils.h +++ b/interfaces/kits/napi/window_runtime/window_napi/js_window_utils.h @@ -162,6 +162,7 @@ const std::map JS_TO_NATIVE_ORIENTATION_MAP { NativeValue* AvoidAreaTypeInit(NativeEngine* engine); NativeValue* WindowModeInit(NativeEngine* engine); NativeValue* ColorSpaceInit(NativeEngine* engine); + NativeValue* OrientationInit(NativeEngine* engine); NativeValue* WindowStageEventTypeInit(NativeEngine* engine); NativeValue* WindowLayoutModeInit(NativeEngine* engine); bool GetAPI7Ability(NativeEngine& engine, AppExecFwk::Ability* &ability); From deefdd3dee7f46aca327fad9941af6d12b633d85 Mon Sep 17 00:00:00 2001 From: dubj Date: Thu, 7 Jul 2022 16:53:10 +0800 Subject: [PATCH 79/81] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E9=87=8D=E5=90=AF?= =?UTF-8?q?=E8=BF=87=E7=A8=8B=E4=B8=AD=E5=BC=80=E6=9C=BA=E5=8A=A8=E7=94=BB?= =?UTF-8?q?=E6=B6=88=E5=A4=B1=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: dubj Change-Id: Ia7b12512c4baa3abcfd7ea365f8aae2e0cd2ee7f --- wmserver/src/window_node_container.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/wmserver/src/window_node_container.cpp b/wmserver/src/window_node_container.cpp index 775a9fc9..a9e97e79 100644 --- a/wmserver/src/window_node_container.cpp +++ b/wmserver/src/window_node_container.cpp @@ -1902,7 +1902,8 @@ void WindowNodeContainer::RemoveSingleUserWindowNodes() windowNode->GetWindowType() == WindowType::WINDOW_TYPE_STATUS_BAR || windowNode->GetWindowType() == WindowType::WINDOW_TYPE_NAVIGATION_BAR || windowNode->GetWindowType() == WindowType::WINDOW_TYPE_KEYGUARD || - windowNode->GetWindowType() == WindowType::WINDOW_TYPE_POINTER) { + windowNode->GetWindowType() == WindowType::WINDOW_TYPE_POINTER || + windowNode->GetWindowType() == WindowType::WINDOW_TYPE_BOOT_ANIMATION) { continue; } WLOGFI("remove window %{public}s, windowId %{public}d", From 291ac40c6268b233cd3587687b4c340b41754719 Mon Sep 17 00:00:00 2001 From: chyyy0213 Date: Thu, 7 Jul 2022 21:57:41 +0800 Subject: [PATCH 80/81] add custom anmation config Signed-off-by: chyyy0213 Change-Id: I04b009087a09575eacbbb560bf690021e221efce Signed-off-by: chyyy0213 --- interfaces/innerkits/wm/window.h | 12 +- interfaces/innerkits/wm/wm_common.h | 1 + utils/include/window_property.h | 1 - utils/include/wm_common_inner.h | 1 + utils/src/window_property.cpp | 12 +- wm/include/window_adapter.h | 2 +- wm/include/window_impl.h | 11 +- wm/src/window_adapter.cpp | 6 + wm/src/window_impl.cpp | 109 +++++++++++++++--- wmserver/include/window_manager_service.h | 1 + wmserver/include/window_root.h | 1 + .../include/zidl/window_manager_interface.h | 2 + wmserver/include/zidl/window_manager_proxy.h | 1 + wmserver/src/window_controller.cpp | 7 +- wmserver/src/window_manager_service.cpp | 7 ++ wmserver/src/window_node.cpp | 3 +- wmserver/src/window_node_container.cpp | 7 +- wmserver/src/window_root.cpp | 19 +++ wmserver/src/zidl/window_manager_proxy.cpp | 25 ++++ wmserver/src/zidl/window_manager_stub.cpp | 7 ++ 20 files changed, 199 insertions(+), 36 deletions(-) diff --git a/interfaces/innerkits/wm/window.h b/interfaces/innerkits/wm/window.h index 5cba7ed1..939913fa 100644 --- a/interfaces/innerkits/wm/window.h +++ b/interfaces/innerkits/wm/window.h @@ -134,6 +134,12 @@ public: virtual void OnTouchOutside() const = 0; }; +class IAnimationTransitionController : virtual public RefBase { +public: + virtual void AnimationForShown() = 0; + virtual void AnimationForHidden() = 0; +}; + class Window : public RefBase { public: /** @@ -189,8 +195,8 @@ public: virtual WMError SetLayoutFullScreen(bool status) = 0; virtual WMError SetFullScreen(bool status) = 0; virtual WMError Destroy() = 0; - virtual WMError Show(uint32_t reason = 0, bool isCustomAnimation = false) = 0; - virtual WMError Hide(uint32_t reason = 0, bool isCustomAnimation = false) = 0; + virtual WMError Show(uint32_t reason = 0, bool withAnimation = false) = 0; + virtual WMError Hide(uint32_t reason = 0, bool withAnimation = false) = 0; virtual WMError MoveTo(int32_t x, int32_t y) = 0; virtual WMError Resize(uint32_t width, uint32_t height) = 0; @@ -209,6 +215,7 @@ public: virtual void DisableAppWindowDecor() = 0; virtual WMError RequestFocus() const = 0; + virtual WMError UpdateSurfaceNodeAfterCustomAnimation(bool isAdd) = 0; // AddInputEventListener is for api 7 virtual void SetInputEventConsumer(const std::shared_ptr& inputEventConsumer) = 0; virtual void AddInputEventListener(const std::shared_ptr& inputEventListener) = 0; @@ -234,6 +241,7 @@ public: virtual void UnregisterOccupiedAreaChangeListener(const sptr& listener) = 0; virtual void RegisterTouchOutsideListener(const sptr& listener) = 0; virtual void UnregisterTouchOutsideListener(const sptr& listener) = 0; + virtual void RegisterAnimationTransitionController(const sptr& listener) = 0; virtual void SetAceAbilityHandler(const sptr& handler) = 0; virtual WMError SetUIContent(const std::string& contentInfo, NativeEngine* engine, NativeValue* storage, bool isDistributed = false, AppExecFwk::Ability* ability = nullptr) = 0; diff --git a/interfaces/innerkits/wm/wm_common.h b/interfaces/innerkits/wm/wm_common.h index ae02c4dd..e7b5805b 100644 --- a/interfaces/innerkits/wm/wm_common.h +++ b/interfaces/innerkits/wm/wm_common.h @@ -253,6 +253,7 @@ enum class ColorSpace : uint32_t { enum class WindowAnimation : uint32_t { NONE, DEFAULT, + CUSTOM, }; class AvoidArea : public Parcelable { diff --git a/utils/include/window_property.h b/utils/include/window_property.h index 9244d2e0..d3716143 100644 --- a/utils/include/window_property.h +++ b/utils/include/window_property.h @@ -172,7 +172,6 @@ private: uint32_t accessTokenId_ { 0 }; Transform trans_; DEFINE_VAR_DEFAULT_FUNC_GET_SET(Orientation, RequestedOrientation, requestedOrientation, Orientation::UNSPECIFIED); - DEFINE_VAR_DEFAULT_FUNC_GET_SET(bool, CustomAnimation, isCustomAnimation, false); WindowSizeLimits sizeLimits_; }; } diff --git a/utils/include/wm_common_inner.h b/utils/include/wm_common_inner.h index 64906ba4..808f4083 100644 --- a/utils/include/wm_common_inner.h +++ b/utils/include/wm_common_inner.h @@ -86,6 +86,7 @@ enum class PropertyChangeAction : uint32_t { ACTION_UPDATE_MODE_SUPPORT_INFO = 1 << 11, ACTION_UPDATE_TOUCH_HOT_AREA = 1 << 12, ACTION_UPDATE_TRANSFORM_PROPERTY = 1 << 13, + ACTION_UPDATE_ANIMATION_FLAG = 1 << 14, }; struct ModeChangeHotZonesConfig { diff --git a/utils/src/window_property.cpp b/utils/src/window_property.cpp index 2b9f8033..98b04ef7 100644 --- a/utils/src/window_property.cpp +++ b/utils/src/window_property.cpp @@ -545,8 +545,7 @@ bool WindowProperty::Marshalling(Parcel& parcel) const parcel.WriteUint32(static_cast(dragType_)) && parcel.WriteUint32(originRect_.width_) && parcel.WriteUint32(originRect_.height_) && parcel.WriteBool(isStretchable_) && MarshallingTouchHotAreas(parcel) && parcel.WriteUint32(accessTokenId_) && - parcel.WriteBool(isCustomAnimation_) && MarshallingTransform(parcel) && - MarshallingWindowSizeLimits(parcel); + MarshallingTransform(parcel) && MarshallingWindowSizeLimits(parcel); } WindowProperty* WindowProperty::Unmarshalling(Parcel& parcel) @@ -596,7 +595,6 @@ WindowProperty* WindowProperty::Unmarshalling(Parcel& parcel) property->SetStretchable(parcel.ReadBool()); UnmarshallingTouchHotAreas(parcel, property); property->SetAccessTokenId(parcel.ReadUint32()); - property->SetCustomAnimation(parcel.ReadBool()); UnmarshallingTransform(parcel, property); UnmarshallingWindowSizeLimits(parcel, property); return property; @@ -653,6 +651,9 @@ bool WindowProperty::Write(Parcel& parcel, PropertyChangeAction action) case PropertyChangeAction::ACTION_UPDATE_TRANSFORM_PROPERTY: ret &= MarshallingTransform(parcel); break; + case PropertyChangeAction::ACTION_UPDATE_ANIMATION_FLAG: + ret &= parcel.WriteUint32(animationFlag_); + break; default: break; } @@ -709,6 +710,10 @@ void WindowProperty::Read(Parcel& parcel, PropertyChangeAction action) case PropertyChangeAction::ACTION_UPDATE_TRANSFORM_PROPERTY: UnmarshallingTransform(parcel, this); break; + case PropertyChangeAction::ACTION_UPDATE_ANIMATION_FLAG: { + SetAnimationFlag(parcel.ReadUint32()); + break; + } default: break; } @@ -752,7 +757,6 @@ void WindowProperty::CopyFrom(const sptr& property) isStretchable_ = property->isStretchable_; touchHotAreas_ = property->touchHotAreas_; accessTokenId_ = property->accessTokenId_; - isCustomAnimation_ = property->isCustomAnimation_; trans_ = property->trans_; sizeLimits_ = property->sizeLimits_; } diff --git a/wm/include/window_adapter.h b/wm/include/window_adapter.h index f749dc9e..13ff1fad 100644 --- a/wm/include/window_adapter.h +++ b/wm/include/window_adapter.h @@ -52,7 +52,7 @@ public: virtual WMError UpdateProperty(sptr& windowProperty, PropertyChangeAction action); virtual WMError GetSystemConfig(SystemConfig& systemConfig); virtual WMError GetModeChangeHotZones(DisplayId displayId, ModeChangeHotZones& hotZones); - + virtual WMError UpdateRsTree(uint32_t windowId, bool isAdd); virtual void RegisterWindowManagerAgent(WindowManagerAgentType type, const sptr& windowManagerAgent); virtual void UnregisterWindowManagerAgent(WindowManagerAgentType type, diff --git a/wm/include/window_impl.h b/wm/include/window_impl.h index f7250c2a..a17d05a6 100644 --- a/wm/include/window_impl.h +++ b/wm/include/window_impl.h @@ -136,6 +136,7 @@ public: virtual WMError SetLayoutFullScreen(bool status) override; virtual WMError SetFullScreen(bool status) override; virtual Transform GetTransform() const override; + virtual WMError UpdateSurfaceNodeAfterCustomAnimation(bool isAdd) override; inline void SetWindowState(WindowState state) { state_ = state; @@ -145,8 +146,8 @@ public: WMError Create(const std::string& parentName, const std::shared_ptr& context = nullptr); virtual WMError Destroy() override; - virtual WMError Show(uint32_t reason = 0, bool isCustomAnimation = false) override; - virtual WMError Hide(uint32_t reason = 0, bool isCustomAnimation = false) override; + virtual WMError Show(uint32_t reason = 0, bool withAnimation = false) override; + virtual WMError Hide(uint32_t reason = 0, bool withAnimation = false) override; virtual WMError MoveTo(int32_t x, int32_t y) override; virtual WMError Resize(uint32_t width, uint32_t height) override; virtual WMError SetKeepScreenOn(bool keepScreenOn) override; @@ -191,6 +192,7 @@ public: virtual void UnregisterOccupiedAreaChangeListener(const sptr& listener) override; virtual void RegisterTouchOutsideListener(const sptr& listener) override; virtual void UnregisterTouchOutsideListener(const sptr& listener) override; + virtual void RegisterAnimationTransitionController(const sptr& listener) override; virtual void SetAceAbilityHandler(const sptr& handler) override; virtual void SetRequestModeSupportInfo(uint32_t modeSupportInfo) override; void UpdateRect(const struct Rect& rect, bool decoStatus, WindowSizeChangeReason reason); @@ -332,7 +334,7 @@ private: void ReadyToMoveOrDragWindow(int32_t globalX, int32_t globalY, int32_t pointId, const Rect& rect); void EndMoveOrDragWindow(int32_t posX, int32_t posY, int32_t pointId); bool IsPointerEventConsumed(); - void AdjustWindowAnimationFlag(); + void AdjustWindowAnimationFlag(bool withAnimation = false); void MapFloatingWindowToAppIfNeeded(); WMError UpdateProperty(PropertyChangeAction action); WMError Destroy(bool needNotifyServer); @@ -352,7 +354,7 @@ private: void UpdateTitleButtonVisibility(); void SetModeSupportInfo(uint32_t modeSupportInfo); uint32_t GetModeSupportInfo() const; - + WMError PreProcessShow(uint32_t reason, bool withAnimation); // colorspace, gamut using ColorSpaceConvertMap = struct { ColorSpace colorSpace; @@ -380,6 +382,7 @@ private: std::vector> occupiedAreaChangeListeners_; std::vector> inputEventListeners_; std::shared_ptr inputEventConsumer_; + sptr animationTranistionController_; NotifyNativeWinDestroyFunc notifyNativefunc_; std::shared_ptr surfaceNode_; std::string name_; diff --git a/wm/src/window_adapter.cpp b/wm/src/window_adapter.cpp index c044c26c..6fc05cb9 100644 --- a/wm/src/window_adapter.cpp +++ b/wm/src/window_adapter.cpp @@ -256,5 +256,11 @@ WMError WindowAdapter::UpdateAvoidAreaListener(uint32_t windowId, bool haveListe INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR); return windowManagerServiceProxy_->UpdateAvoidAreaListener(windowId, haveListener); } + +WMError WindowAdapter::UpdateRsTree(uint32_t windowId, bool isAdd) +{ + INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR); + return windowManagerServiceProxy_->UpdateRsTree(windowId, isAdd); +} } // namespace Rosen } // namespace OHOS \ No newline at end of file diff --git a/wm/src/window_impl.cpp b/wm/src/window_impl.cpp index 5930c66b..72ad62d1 100755 --- a/wm/src/window_impl.cpp +++ b/wm/src/window_impl.cpp @@ -48,8 +48,8 @@ const WindowImpl::ColorSpaceConvertMap WindowImpl::colorSpaceConvertMap[] = { std::map>> WindowImpl::windowMap_; std::map>> WindowImpl::subWindowMap_; std::map>> WindowImpl::appFloatingWindowMap_; -static int ctorCnt = 0; -static int dtorCnt = 0; +static int constructorCnt = 0; +static int deConstructorCnt = 0; WindowImpl::WindowImpl(const sptr& option) { property_ = new (std::nothrow) WindowProperty(); @@ -81,7 +81,8 @@ WindowImpl::WindowImpl(const sptr& option) struct RSSurfaceNodeConfig rsSurfaceNodeConfig; rsSurfaceNodeConfig.SurfaceNodeName = property_->GetWindowName(); surfaceNode_ = RSSurfaceNode::Create(rsSurfaceNodeConfig); - WLOGFI("WindowImpl constructor Count: %{public}d name: %{public}s", ++ctorCnt, property_->GetWindowName().c_str()); + WLOGFI("WindowImpl constructorCnt: %{public}d name: %{public}s", + ++constructorCnt, property_->GetWindowName().c_str()); } void WindowImpl::InitListenerHandler() @@ -105,8 +106,8 @@ WindowImpl::~WindowImpl() if (eventHandler_ != nullptr) { eventHandler_.reset(); } - WLOGFI("windowName: %{public}s, windowId: %{public}d, dtorCnt: %{public}d, surfaceNode:%{public}d", - GetWindowName().c_str(), GetWindowId(), ++dtorCnt, static_cast(surfaceNode_.use_count())); + WLOGFI("windowName: %{public}s, windowId: %{public}d, deConstructorCnt: %{public}d, surfaceNode:%{public}d", + GetWindowName().c_str(), GetWindowId(), ++deConstructorCnt, static_cast(surfaceNode_.use_count())); Destroy(); } @@ -931,14 +932,34 @@ WMError WindowImpl::Destroy(bool needNotifyServer) return ret; } -WMError WindowImpl::Show(uint32_t reason, bool isCustomAnimation) +WMError WindowImpl::UpdateSurfaceNodeAfterCustomAnimation(bool isAdd) { - WLOGFI("[Client] Window [name:%{public}s, id:%{public}u] Show, reason:%{public}u", - name_.c_str(), property_->GetWindowId(), reason); + WLOGFI("[Client] Window [name:%{public}s, id:%{public}u] UpdateRsTree, isAdd:%{public}u", + name_.c_str(), property_->GetWindowId(), isAdd); if (!IsWindowValid()) { return WMError::WM_ERROR_INVALID_WINDOW; } + if (!WindowHelper::IsSystemWindow(property_->GetWindowType())) { + WLOGFE("only system window can set"); + return WMError::WM_ERROR_INVALID_OPERATION; + } + AdjustWindowAnimationFlag(false); // false means update rs tree with default option + // need time out check + WMError ret = UpdateProperty(PropertyChangeAction::ACTION_UPDATE_ANIMATION_FLAG); + if (ret != WMError::WM_OK) { + WLOGFE("UpdateProperty failed with errCode:%{public}d", static_cast(ret)); + return ret; + } + ret = SingletonContainer::Get().UpdateRsTree(property_->GetWindowId(), isAdd); + if (ret != WMError::WM_OK) { + WLOGFE("UpdateRsTree failed with errCode:%{public}d", static_cast(ret)); + return ret; + } + return WMError::WM_OK; +} +WMError WindowImpl::PreProcessShow(uint32_t reason, bool withAnimation) +{ WindowStateChangeReason stateChangeReason = static_cast(reason); if (stateChangeReason == WindowStateChangeReason::KEYGUARD || stateChangeReason == WindowStateChangeReason::TOGGLING) { @@ -962,9 +983,7 @@ WMError WindowImpl::Show(uint32_t reason, bool isCustomAnimation) return WMError::WM_OK; } SetDefaultOption(); - // set true success when transitionController exist; set false when complete transition - property_->SetCustomAnimation(isCustomAnimation); - + AdjustWindowAnimationFlag(withAnimation); // show failed when current mode is not support or window only supports split mode and can show when locked bool isShowWhenLocked = GetWindowFlags() & static_cast(WindowFlag::WINDOW_FLAG_SHOW_WHEN_LOCKED); if (!WindowHelper::IsWindowModeSupported(GetModeSupportInfo(), GetMode()) || @@ -974,15 +993,34 @@ WMError WindowImpl::Show(uint32_t reason, bool isCustomAnimation) NotifyForegroundInvalidWindowMode(); return WMError::WM_ERROR_INVALID_WINDOW_MODE; } - // update title button visibility when show UpdateTitleButtonVisibility(); + return WMError::WM_OK; +} - WMError ret = SingletonContainer::Get().AddWindow(property_); +WMError WindowImpl::Show(uint32_t reason, bool withAnimation) +{ + WLOGFI("[Client] Window [name:%{public}s, id:%{public}u] Show, reason:%{public}u, withAnimation:%{public}d", + name_.c_str(), property_->GetWindowId(), reason, withAnimation); + if (!IsWindowValid()) { + return WMError::WM_ERROR_INVALID_WINDOW; + } + + WMError ret = PreProcessShow(reason, withAnimation); + if (ret != WMError::WM_OK) { + return ret; + } + + ret = SingletonContainer::Get().AddWindow(property_); RecordLifeCycleExceptionEvent(LifeCycleEvent::SHOW_EVENT, ret); if (ret == WMError::WM_OK || ret == WMError::WM_ERROR_DEATH_RECIPIENT) { state_ = WindowState::STATE_SHOWN; NotifyAfterForeground(); + uint32_t animationFlag = property_->GetAnimationFlag(); + if (animationFlag == static_cast(WindowAnimation::CUSTOM)) { + // CustomAnimation is enabled when animationTranistionController_ exists + animationTranistionController_->AnimationForShown(); + } } else if (ret == WMError::WM_ERROR_INVALID_WINDOW_MODE) { NotifyForegroundInvalidWindowMode(); } else { @@ -992,9 +1030,10 @@ WMError WindowImpl::Show(uint32_t reason, bool isCustomAnimation) return ret; } -WMError WindowImpl::Hide(uint32_t reason, bool isCustomAnimation) +WMError WindowImpl::Hide(uint32_t reason, bool withAnimation) { - WLOGFI("[Client] Window [name:%{public}s, id:%{public}u] Hide", name_.c_str(), property_->GetWindowId()); + WLOGFI("[Client] Window [name:%{public}s, id:%{public}u] Hide, reason:%{public}u, withAnimation:%{public}d", + name_.c_str(), property_->GetWindowId(), reason, withAnimation); if (!IsWindowValid()) { return WMError::WM_ERROR_INVALID_WINDOW; } @@ -1008,8 +1047,17 @@ WMError WindowImpl::Hide(uint32_t reason, bool isCustomAnimation) WLOGFI("window is already hidden id: %{public}u", property_->GetWindowId()); return WMError::WM_OK; } - property_->SetCustomAnimation(isCustomAnimation); - WMError ret = SingletonContainer::Get().RemoveWindow(property_->GetWindowId()); + WMError ret = WMError::WM_OK; + if (WindowHelper::IsSystemWindow(property_->GetWindowType())) { + AdjustWindowAnimationFlag(withAnimation); + // when show(true) with default, hide() with None, to adjust animationFlag to disabled default animation + WMError ret = UpdateProperty(PropertyChangeAction::ACTION_UPDATE_ANIMATION_FLAG); + if (ret != WMError::WM_OK) { + WLOGFE("UpdateProperty failed with errCode:%{public}d", static_cast(ret)); + return ret; + } + } + ret = SingletonContainer::Get().RemoveWindow(property_->GetWindowId()); RecordLifeCycleExceptionEvent(LifeCycleEvent::HIDE_EVENT, ret); if (ret != WMError::WM_OK) { WLOGFE("hide errCode:%{public}d for winId:%{public}u", static_cast(ret), property_->GetWindowId()); @@ -1017,6 +1065,10 @@ WMError WindowImpl::Hide(uint32_t reason, bool isCustomAnimation) } state_ = WindowState::STATE_HIDDEN; NotifyAfterBackground(); + uint32_t animationFlag = property_->GetAnimationFlag(); + if (animationFlag == static_cast(WindowAnimation::CUSTOM)) { + animationTranistionController_->AnimationForHidden(); + } return ret; } @@ -1617,6 +1669,15 @@ void WindowImpl::UnregisterTouchOutsideListener(const sptr& listener) +{ + if (listener == nullptr) { + WLOGFE("listener is nullptr"); + return; + } + animationTranistionController_ = listener; +} + void WindowImpl::SetAceAbilityHandler(const sptr& handler) { if (handler == nullptr) { @@ -2022,10 +2083,20 @@ bool WindowImpl::IsPointerEventConsumed() return startDragFlag_ || startMoveFlag_; } -void WindowImpl::AdjustWindowAnimationFlag() +void WindowImpl::AdjustWindowAnimationFlag(bool withAnimation) { + // when show/hide with animation + // use custom animation when transitionController exists; else use default animation WindowType winType = property_->GetWindowType(); - if (!WindowHelper::IsAppWindow(winType)) { + bool isAppWindow = WindowHelper::IsAppWindow(winType); + if (withAnimation && !isAppWindow && animationTranistionController_) { + // use custom animation + property_->SetAnimationFlag(static_cast(WindowAnimation::CUSTOM)); + } else if (isAppWindow || (withAnimation && !animationTranistionController_)) { + // use default animation + property_->SetAnimationFlag(static_cast(WindowAnimation::DEFAULT)); + } else { + // with no animation property_->SetAnimationFlag(static_cast(WindowAnimation::NONE)); } } diff --git a/wmserver/include/window_manager_service.h b/wmserver/include/window_manager_service.h index eebc793e..d59ef1c6 100644 --- a/wmserver/include/window_manager_service.h +++ b/wmserver/include/window_manager_service.h @@ -107,6 +107,7 @@ public: sptr& finishCallback) override; void GetWindowPreferredOrientation(DisplayId displayId, Orientation &orientation); void OnAccountSwitched() const; + WMError UpdateRsTree(uint32_t windowId, bool isAdd) override; protected: WindowManagerService(); virtual ~WindowManagerService() = default; diff --git a/wmserver/include/window_root.h b/wmserver/include/window_root.h index c22d5969..4fc7e816 100644 --- a/wmserver/include/window_root.h +++ b/wmserver/include/window_root.h @@ -98,6 +98,7 @@ public: void MinimizeTargetWindows(std::vector& windowIds); WindowLayoutMode GetCurrentLayoutMode(DisplayId displayId); void RemoveSingleUserWindowNodes(); + WMError UpdateRsTree(uint32_t windowId, bool isAdd); private: void OnRemoteDied(const sptr& remoteObject); WMError DestroyWindowInner(sptr& node); diff --git a/wmserver/include/zidl/window_manager_interface.h b/wmserver/include/zidl/window_manager_interface.h index 1280b14a..45aab805 100644 --- a/wmserver/include/zidl/window_manager_interface.h +++ b/wmserver/include/zidl/window_manager_interface.h @@ -60,6 +60,7 @@ public: TRANS_ID_GET_FULLSCREEN_AND_SPLIT_HOT_ZONE, TRANS_ID_GET_ANIMATION_CALLBACK, TRANS_ID_UPDATE_AVOIDAREA_LISTENER, + TRANS_ID_UPDATE_RS_TREE, }; virtual WMError CreateWindow(sptr& window, sptr& property, const std::shared_ptr& surfaceNode, @@ -90,6 +91,7 @@ public: virtual void MinimizeWindowsByLauncher(std::vector windowIds, bool isAnimated, sptr& finishCallback) = 0; virtual WMError UpdateAvoidAreaListener(uint32_t windowId, bool haveListener) = 0; + virtual WMError UpdateRsTree(uint32_t windowId, bool isAdd) = 0; }; } } diff --git a/wmserver/include/zidl/window_manager_proxy.h b/wmserver/include/zidl/window_manager_proxy.h index 2ee5d352..047a7ecc 100644 --- a/wmserver/include/zidl/window_manager_proxy.h +++ b/wmserver/include/zidl/window_manager_proxy.h @@ -58,6 +58,7 @@ public: void MinimizeWindowsByLauncher(std::vector windowIds, bool isAnimated, sptr& finishCallback) override; WMError UpdateAvoidAreaListener(uint32_t windowId, bool haveListener) override; + WMError UpdateRsTree(uint32_t windowId, bool isAdd) override; private: static inline BrokerDelegator delegator_; }; diff --git a/wmserver/src/window_controller.cpp b/wmserver/src/window_controller.cpp index ec0e3dd5..04f37893 100644 --- a/wmserver/src/window_controller.cpp +++ b/wmserver/src/window_controller.cpp @@ -223,6 +223,7 @@ WMError WindowController::AddWindowNode(sptr& property) // Need 'check permission' // Need 'adjust property' + UpdateWindowAnimation(node); WMError res = windowRoot_->AddWindowNode(property->GetParentId(), node); if (res != WMError::WM_OK) { MinimizeApp::ClearNodesWithReason(MinimizeReason::OTHER_WINDOW); @@ -885,7 +886,11 @@ WMError WindowController::UpdateProperty(sptr& property, Propert property->GetTouchHotAreas(rects); return UpdateTouchHotAreas(node, rects); } - case PropertyChangeAction::ACTION_UPDATE_TRANSFORM_PROPERTY: + case PropertyChangeAction::ACTION_UPDATE_ANIMATION_FLAG: { + node->GetWindowProperty()->SetAnimationFlag(property->GetAnimationFlag()); + UpdateWindowAnimation(node); + break; + } default: break; } diff --git a/wmserver/src/window_manager_service.cpp b/wmserver/src/window_manager_service.cpp index 4416df19..2e92fcb5 100644 --- a/wmserver/src/window_manager_service.cpp +++ b/wmserver/src/window_manager_service.cpp @@ -678,5 +678,12 @@ WMError WindowManagerService::UpdateAvoidAreaListener(uint32_t windowId, bool ha return WMError::WM_OK; }).get(); } + +WMError WindowManagerService::UpdateRsTree(uint32_t windowId, bool isAdd) +{ + return wmsTaskLooper_->ScheduleTask([this, windowId, isAdd]() { + return windowRoot_->UpdateRsTree(windowId, isAdd); + }).get(); +} } // namespace Rosen } // namespace OHOS diff --git a/wmserver/src/window_node.cpp b/wmserver/src/window_node.cpp index ebe6e0d9..d7b87473 100644 --- a/wmserver/src/window_node.cpp +++ b/wmserver/src/window_node.cpp @@ -278,7 +278,8 @@ WindowBlurLevel WindowNode::GetWindowBackgroundBlur() const bool WindowNode::EnableDefaultAnimation(bool propertyEnabled, bool animationPlayed) { - return (propertyEnabled && (!animationPlayed) && (!property_->GetCustomAnimation()) && (!isAppCrash_)); + bool defaultAnimation = property_->GetAnimationFlag() == (static_cast(WindowAnimation::DEFAULT)); + return (propertyEnabled && (!animationPlayed) && (defaultAnimation) && (!isAppCrash_)); } float WindowNode::GetBrightness() const diff --git a/wmserver/src/window_node_container.cpp b/wmserver/src/window_node_container.cpp index a9e97e79..841ae680 100644 --- a/wmserver/src/window_node_container.cpp +++ b/wmserver/src/window_node_container.cpp @@ -387,9 +387,10 @@ void WindowNodeContainer::UpdateWindowTree(sptr& node) bool WindowNodeContainer::UpdateRSTree(sptr& node, DisplayId displayId, bool isAdd, bool animationPlayed) { HITRACE_METER(HITRACE_TAG_WINDOW_MANAGER); - if (node->GetWindowProperty()->GetCustomAnimation()) { - WLOGFI("not need to update RsTree since SystemWindowAnimation is playing"); - return false; + uint32_t animationFlag = node->GetWindowProperty()->GetAnimationFlag(); + if (animationFlag == static_cast(WindowAnimation::CUSTOM)) { + WLOGFI("not need to update RsTree since SystemWindow CustomAnimation is playing"); + return true; } if (node->GetWindowType() == WindowType::WINDOW_TYPE_APP_COMPONENT) { WLOGFI("WINDOW_TYPE_APP_COMPONENT not need to update RsTree"); diff --git a/wmserver/src/window_root.cpp b/wmserver/src/window_root.cpp index 66551850..08b859d6 100644 --- a/wmserver/src/window_root.cpp +++ b/wmserver/src/window_root.cpp @@ -1332,5 +1332,24 @@ void WindowRoot::RemoveSingleUserWindowNodes() container->RemoveSingleUserWindowNodes(); } } + +WMError WindowRoot::UpdateRsTree(uint32_t windowId, bool isAdd) +{ + sptr node = GetWindowNode(windowId); + if (node == nullptr) { + WLOGFE("could not find window"); + return WMError::WM_ERROR_NULLPTR; + } + auto container = GetOrCreateWindowNodeContainer(node->GetDisplayId()); + if (container == nullptr) { + WLOGFE("window container could not be found"); + return WMError::WM_ERROR_NULLPTR; + } + for (auto& displayId : node->GetShowingDisplays()) { + container->UpdateRSTree(node, displayId, isAdd); + } + RSTransaction::FlushImplicitTransaction(); + return WMError::WM_OK; +} } // namespace Rosen } // namespace OHOS diff --git a/wmserver/src/zidl/window_manager_proxy.cpp b/wmserver/src/zidl/window_manager_proxy.cpp index 40fab55f..b1c0fe00 100644 --- a/wmserver/src/zidl/window_manager_proxy.cpp +++ b/wmserver/src/zidl/window_manager_proxy.cpp @@ -649,5 +649,30 @@ WMError WindowManagerProxy::UpdateAvoidAreaListener(uint32_t windowId, bool have } return static_cast(reply.ReadInt32()); } + +WMError WindowManagerProxy::UpdateRsTree(uint32_t windowId, bool isAdd) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("WriteInterfaceToken failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + if (!data.WriteUint32(windowId)) { + WLOGFE("Write windowId failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + if (!data.WriteBool(isAdd)) { + WLOGFE("Write avoid area listener failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + if (Remote()->SendRequest(static_cast(WindowManagerMessage::TRANS_ID_UPDATE_RS_TREE), + data, reply, option) != ERR_NONE) { + return WMError::WM_ERROR_IPC_FAILED; + } + return static_cast(reply.ReadInt32()); +} } // namespace Rosen } // namespace OHOS \ No newline at end of file diff --git a/wmserver/src/zidl/window_manager_stub.cpp b/wmserver/src/zidl/window_manager_stub.cpp index d32fb6ea..cee4a0e3 100644 --- a/wmserver/src/zidl/window_manager_stub.cpp +++ b/wmserver/src/zidl/window_manager_stub.cpp @@ -228,6 +228,13 @@ int32_t WindowManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, M reply.WriteInt32(static_cast(errCode)); break; } + case WindowManagerMessage::TRANS_ID_UPDATE_RS_TREE: { + uint32_t windowId = data.ReadUint32(); + bool isAdd = data.ReadBool(); + WMError errCode = UpdateRsTree(windowId, isAdd); + reply.WriteInt32(static_cast(errCode)); + break; + } default: WLOGFW("unknown transaction code %{public}d", code); return IPCObjectStub::OnRemoteRequest(code, data, reply, option); From ca69db75057f45d31bc48dad8e112b0d2fb8cb47 Mon Sep 17 00:00:00 2001 From: zhirong <215782872@qq.com> Date: Thu, 7 Jul 2022 19:29:34 +0800 Subject: [PATCH 81/81] enable window property transform Signed-off-by: zhirong <215782872@qq.com> Change-Id: I24e1790cefe5d11e29f9e9e2862effb79803603f Signed-off-by: zhirong <215782872@qq.com> --- interfaces/innerkits/wm/wm_common.h | 21 ++ .../window_napi/js_window_utils.cpp | 2 +- .../window_napi/js_window_utils.h | 2 +- utils/BUILD.gn | 1 + utils/include/window_helper.h | 90 +++++ utils/include/window_property.h | 8 + utils/include/wm_common_inner.h | 1 + utils/include/wm_math.h | 222 ++++++++++++ utils/src/window_property.cpp | 27 ++ utils/src/wm_math.cpp | 319 ++++++++++++++++++ wm/include/window_impl.h | 1 + wm/src/window_impl.cpp | 50 ++- wmserver/include/window_controller.h | 1 + wmserver/include/window_node.h | 2 + wmserver/src/input_window_monitor.cpp | 18 +- wmserver/src/window_controller.cpp | 16 + wmserver/src/window_layout_policy.cpp | 28 +- wmserver/src/window_node.cpp | 10 + 18 files changed, 796 insertions(+), 23 deletions(-) create mode 100644 utils/include/wm_math.h create mode 100644 utils/src/wm_math.cpp diff --git a/interfaces/innerkits/wm/wm_common.h b/interfaces/innerkits/wm/wm_common.h index e7b5805b..6763f76f 100644 --- a/interfaces/innerkits/wm/wm_common.h +++ b/interfaces/innerkits/wm/wm_common.h @@ -136,6 +136,7 @@ enum class WindowSizeChangeReason : uint32_t { RESIZE, MOVE, HIDE, + TRANSFORM, }; enum class WindowLayoutMode : uint32_t { @@ -181,6 +182,20 @@ public: translateX_(0.f), translateY_(0.f), translateZ_(0.f) {} ~Transform() {} + + bool operator!=(const Transform& right) const + { + return (pivotX_ - right.pivotX_) || (pivotY_ - right.pivotY_) || (scaleX_ - right.scaleX_) || + (scaleY_ - right.scaleY_) || (rotationX_ - right.rotationX_) || (rotationY_ - right.rotationY_) || + (rotationZ_ - right.rotationZ_) || (translateX_ - right.translateX_) || + (translateY_ - right.translateY_) || (translateZ_ - right.translateZ_); + } + + bool operator==(const Transform& right) const + { + return !(*this != right); + } + float pivotX_; float pivotY_; float scaleX_; @@ -191,6 +206,12 @@ public: float translateX_; float translateY_; float translateZ_; + + static const Transform& Identity() + { + static Transform I; + return I; + } }; struct SystemBarProperty { diff --git a/interfaces/kits/napi/window_runtime/window_napi/js_window_utils.cpp b/interfaces/kits/napi/window_runtime/window_napi/js_window_utils.cpp index 00dd8614..d9104d03 100644 --- a/interfaces/kits/napi/window_runtime/window_napi/js_window_utils.cpp +++ b/interfaces/kits/napi/window_runtime/window_napi/js_window_utils.cpp @@ -528,7 +528,7 @@ bool GetAPI7Ability(NativeEngine& engine, AppExecFwk::Ability* &ability) return true; } -bool ParseJsDoubleValue(NativeObject* jsObject, NativeEngine& engine, const std::string& name, double data) +bool ParseJsDoubleValue(NativeObject* jsObject, NativeEngine& engine, const std::string& name, double& data) { NativeValue* value = jsObject->GetProperty(name.c_str()); if (value->TypeOf() != NATIVE_UNDEFINED) { diff --git a/interfaces/kits/napi/window_runtime/window_napi/js_window_utils.h b/interfaces/kits/napi/window_runtime/window_napi/js_window_utils.h index b8ba7106..9a2fabeb 100644 --- a/interfaces/kits/napi/window_runtime/window_napi/js_window_utils.h +++ b/interfaces/kits/napi/window_runtime/window_napi/js_window_utils.h @@ -166,7 +166,7 @@ const std::map JS_TO_NATIVE_ORIENTATION_MAP { NativeValue* WindowStageEventTypeInit(NativeEngine* engine); NativeValue* WindowLayoutModeInit(NativeEngine* engine); bool GetAPI7Ability(NativeEngine& engine, AppExecFwk::Ability* &ability); - bool ParseJsDoubleValue(NativeObject* jsObject, NativeEngine& engine, const std::string& name, double data); + bool ParseJsDoubleValue(NativeObject* jsObject, NativeEngine& engine, const std::string& name, double& data); template inline bool ConvertNativeValueToVector(NativeEngine& engine, NativeValue* nativeValue, std::vector& out) { diff --git a/utils/BUILD.gn b/utils/BUILD.gn index 657637b7..1a184d87 100644 --- a/utils/BUILD.gn +++ b/utils/BUILD.gn @@ -39,6 +39,7 @@ ohos_shared_library("libwmutil") { "src/surface_reader_handler_impl.cpp", "src/window_property.cpp", "src/window_transition_info.cpp", + "src/wm_math.cpp", ] configs = [ ":libwmutil_private_config" ] diff --git a/utils/include/window_helper.h b/utils/include/window_helper.h index ff3be69c..d24bee50 100644 --- a/utils/include/window_helper.h +++ b/utils/include/window_helper.h @@ -20,6 +20,7 @@ #include "ability_info.h" #include "wm_common.h" #include "wm_common_inner.h" +#include "wm_math.h" namespace OHOS { namespace Rosen { @@ -325,6 +326,95 @@ public: return ret; } + // Transform a point at screen to its oringin position in 3D world and project to xy plane + // A screen point only has x and y component, so we need a plane to calculate its z component. + // | -- -- -- 0 | + // | -- -- -- 0 | + // There is no need to unify w component since the matrix is like | -- -- -- 0 | + // | -- -- -- 1 | + static PointInfo CalculateOriginPosition(const TransformHelper::Matrix4& transformMat, + const TransformHelper::Plane& plane, const PointInfo& pointPos) + { + TransformHelper::Matrix4 invertMat = transformMat; + invertMat.Invert(); + TransformHelper::Vector3 pointAtPlane; + pointAtPlane.x_ = static_cast(pointPos.x); + pointAtPlane.y_ = static_cast(pointPos.y); + pointAtPlane.z_ = plane.ComponentZ(pointAtPlane.x_, pointAtPlane.y_); + TransformHelper::Vector3 originPos = TransformHelper::Transform(pointAtPlane, invertMat); + return PointInfo { static_cast(originPos.x_), static_cast(originPos.y_) }; + } + + static TransformHelper::Matrix4 ComputeRectTransformMat4(const Transform& transform, const Rect& rect) + { + TransformHelper::Vector3 pivotPos = { + rect.posX_ + transform.pivotX_ * rect.width_, rect.posY_ + transform.pivotY_ * rect.height_, 0 }; + // move pivot point to (0,0,0) + TransformHelper::Matrix4 ret = TransformHelper::CreateTranslation(-pivotPos); + // set scale + if ((transform.scaleX_ - 1) || (transform.scaleY_ - 1)) { + ret *= TransformHelper::CreateScale(transform.scaleX_, transform.scaleY_, 1.0f); + } + // set rotation + if (transform.rotationX_) { + ret *= TransformHelper::CreateRotationX(MathHelper::ToRadians(transform.rotationX_)); + } + if (transform.rotationY_) { + ret *= TransformHelper::CreateRotationY(MathHelper::ToRadians(transform.rotationY_)); + } + if (transform.rotationZ_) { + ret *= TransformHelper::CreateRotationZ(MathHelper::ToRadians(transform.rotationZ_)); + } + // set translation + if (transform.translateX_ || transform.translateY_ || transform.translateZ_) { + ret *= TransformHelper::CreateTranslation(TransformHelper::Vector3(transform.translateX_, + transform.translateY_, transform.translateZ_)); + } + // move pivot point to old position + ret *= TransformHelper::CreateTranslation(pivotPos); + return ret; + } + + // Transform rect by matrix and get the circumscribed rect + static Rect TransformRect(const TransformHelper::Matrix4& transformMat, const Rect& rect) + { + TransformHelper::Vector3 a = TransformHelper::Transform( + TransformHelper::Vector3(rect.posX_, rect.posY_, 0), transformMat); + TransformHelper::Vector3 b = TransformHelper::Transform( + TransformHelper::Vector3(rect.posX_ + rect.width_, rect.posY_, 0), transformMat); + TransformHelper::Vector3 c = TransformHelper::Transform( + TransformHelper::Vector3(rect.posX_, rect.posY_ + rect.height_, 0), transformMat); + TransformHelper::Vector3 d = b + c - a; + // Return smallest rect involve transformed rect(abcd) + int32_t xmin = MathHelper::Min(a.x_, b.x_, c.x_, d.x_); + int32_t ymin = MathHelper::Min(a.y_, b.y_, c.y_, d.y_); + int32_t xmax = MathHelper::Max(a.x_, b.x_, c.x_, d.x_); + int32_t ymax = MathHelper::Max(a.y_, b.y_, c.y_, d.y_); + uint32_t w = xmax - xmin; + uint32_t h = ymax - ymin; + return Rect { xmin, ymin, w, h }; + } + + static TransformHelper::Vector2 CalculateHotZoneScale(const TransformHelper::Matrix4& transformMat, + const TransformHelper::Plane& plane) + { + TransformHelper::Vector2 hotZoneScale; + TransformHelper::Vector3 a = TransformHelper::Transform(TransformHelper::Vector3(0, 0, 0), + transformMat); + TransformHelper::Vector3 b = TransformHelper::Transform(TransformHelper::Vector3(1, 0, 0), + transformMat); + TransformHelper::Vector3 c = TransformHelper::Transform(TransformHelper::Vector3(0, 1, 0), + transformMat); + TransformHelper::Vector3 scale = transformMat.GetScale(); + hotZoneScale.x_ = scale.x_ * plane.ParallelDistanceGrad(a, c); + hotZoneScale.y_ = scale.y_ * plane.ParallelDistanceGrad(a, b); + if (std::isnan(hotZoneScale.x_) || std::isnan(hotZoneScale.y_)) { + return TransformHelper::Vector2(1, 1); + } else { + return hotZoneScale; + } + } + static bool CalculateTouchHotAreas(const Rect& windowRect, const std::vector& requestRects, std::vector& outRects) { diff --git a/utils/include/window_property.h b/utils/include/window_property.h index d3716143..dc6fb03a 100644 --- a/utils/include/window_property.h +++ b/utils/include/window_property.h @@ -24,6 +24,7 @@ #include "dm_common.h" #include "wm_common.h" #include "wm_common_inner.h" +#include "wm_math.h" namespace OHOS { namespace Rosen { @@ -76,6 +77,7 @@ public: void SetSizeLimits(const WindowSizeLimits& sizeLimits); WindowSizeChangeReason GetWindowSizeChangeReason() const; void SetTransform(const Transform& trans); + void ComputeTransform(); const std::string& GetWindowName() const; Rect GetRequestRect() const; @@ -114,6 +116,7 @@ public: uint32_t GetAccessTokenId() const; Transform GetTransform() const; WindowSizeLimits GetSizeLimits() const; + const TransformHelper::Matrix4& GetTransformMat() const; virtual bool Marshalling(Parcel& parcel) const override; static WindowProperty* Unmarshalling(Parcel& parcel); @@ -170,8 +173,13 @@ private: DragType dragType_ = DragType::DRAG_UNDEFINED; std::vector touchHotAreas_; // coordinates relative to window. uint32_t accessTokenId_ { 0 }; + // Transform info Transform trans_; + bool recomputeTransformMat_ { false }; + TransformHelper::Matrix4 transformMat_ = TransformHelper::Matrix4::Identity; + DEFINE_VAR_DEFAULT_FUNC_GET_SET(Orientation, RequestedOrientation, requestedOrientation, Orientation::UNSPECIFIED); + DEFINE_VAR_FUNC_GET_SET(TransformHelper::Plane, Plane, windowPlane); WindowSizeLimits sizeLimits_; }; } diff --git a/utils/include/wm_common_inner.h b/utils/include/wm_common_inner.h index 808f4083..0c5694f4 100644 --- a/utils/include/wm_common_inner.h +++ b/utils/include/wm_common_inner.h @@ -55,6 +55,7 @@ enum class WindowUpdateReason : uint32_t { UPDATE_TYPE, NEED_SWITCH_CASCADE_END, UPDATE_OTHER_PROPS, + UPDATE_TRANSFORM, }; enum class AvoidPosType : uint32_t { diff --git a/utils/include/wm_math.h b/utils/include/wm_math.h new file mode 100644 index 00000000..6fab826b --- /dev/null +++ b/utils/include/wm_math.h @@ -0,0 +1,222 @@ +/* + * Copyright (c) 2022 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_WM_MATH_H +#define OHOS_ROSEN_WM_MATH_H + +#include +#include + +namespace OHOS { +namespace Rosen { +namespace MathHelper { +constexpr float PI = 3.14159265f; +constexpr float INF = std::numeric_limits::infinity(); +constexpr float NAG_INF = -std::numeric_limits::infinity(); +constexpr float POS_ZERO = 0.001f; +constexpr float NAG_ZERO = -POS_ZERO; +inline bool NearZero(float val) +{ + return val < POS_ZERO && val > NAG_ZERO; +} + +inline float ToRadians(float degrees) +{ + return degrees * PI / 180.0f; +} + +inline float ToDegrees(float radians) +{ + return radians * 180.0f / PI; +} + +template +T Max(const T& a, const T& b) +{ + return (a < b ? b : a); +} + +template +T Max(const T& a, Ts... bs) +{ + T b = Max(bs...); + return (a > b ? a : b); +} + +template +T Min(const T& a, const T& b) +{ + return (a < b ? a : b); +} + +template +T Min(const T& a, Ts... bs) +{ + T b = Min(bs...); + return (a < b ? a : b); +} + +template +T Clamp(const T& value, const T& lower, const T& upper) +{ + return Min(upper, Max(lower, value)); +} +} // namespace MathHelper + +namespace TransformHelper { +struct Vector2 { + float x_, y_; + Vector2() : x_(0.0f), y_(0.0f) {} + Vector2(float inX, float inY) + : x_(inX), y_(inY) {} + friend Vector2 operator-(const Vector2& v) + { + return Vector2 { -v.x_, -v.y_ }; + } + friend Vector2 operator+(const Vector2& a, const Vector2& b) + { + return Vector2 { a.x_ + b.x_, a.y_ + b.y_ }; + } + friend Vector2 operator-(const Vector2& a, const Vector2& b) + { + return Vector2 { a.x_ - b.x_, a.y_ - b.y_ }; + } + float LengthSq() const + { + return (x_ * x_ + y_ * y_); + } + float Length() const + { + return (std::sqrt(LengthSq())); + } +}; + +struct Vector3 { + float x_, y_, z_; + Vector3() : x_(0.0f), y_(0.0f), z_(0.0f) {} + Vector3(float inX, float inY, float inZ) + : x_(inX), y_(inY), z_(inZ) {} + friend Vector3 operator-(const Vector3& v) + { + return Vector3 { -v.x_, -v.y_, -v.z_ }; + } + friend Vector3 operator+(const Vector3& a, const Vector3& b) + { + return Vector3 { a.x_ + b.x_, a.y_ + b.y_, a.z_ + b.z_ }; + } + friend Vector3 operator-(const Vector3& a, const Vector3& b) + { + return Vector3 { a.x_ - b.x_, a.y_ - b.y_, a.z_ - b.z_ }; + } + float LengthSq() const + { + return (x_ * x_ + y_ * y_ + z_ * z_); + } + float Length() const + { + return (std::sqrt(LengthSq())); + } + void Normalize() + { + float length = Length(); + if (length > MathHelper::POS_ZERO) { + x_ /= length; + y_ /= length; + z_ /= length; + } + } + static Vector3 Normalize(const Vector3& vec) + { + Vector3 temp = vec; + temp.Normalize(); + return temp; + } + static float Dot(const Vector3& a, const Vector3& b) + { + return (a.x_ * b.x_ + a.y_ * b.y_ + a.z_ * b.z_); + } + static Vector3 Cross(const Vector3& a, const Vector3& b) + { + Vector3 temp; + temp.x_ = a.y_ * b.z_ - a.z_ * b.y_; + temp.y_ = a.z_ * b.x_ - a.x_ * b.z_; + temp.z_ = a.x_ * b.y_ - a.y_ * b.x_; + return temp; + } +}; + +struct Matrix3 { + float mat_[3][3]; + + friend Matrix3 operator*(const Matrix3& left, const Matrix3& right); + Matrix3& operator*=(const Matrix3& right); + static const Matrix3 Identity; +}; + +struct Matrix4 { + float mat_[4][4]; + + friend Matrix4 operator*(const Matrix4& left, const Matrix4& right); + Matrix4& operator*=(const Matrix4& right); + void SwapRow(int row1, int row2); + // Inverse matrix with Gauss-Jordan method + void Invert(); + // Extract the scale component from the matrix + Vector3 GetScale() const; + static const Matrix4 Identity; + static constexpr int MAT_SIZE = 4; +}; + +struct Plane { + Plane() : normal_ { 0, 0, 1 }, d_ { 0 } {} + Plane(const Vector3& normal, float d); + Plane(const Vector3& a, const Vector3& b, const Vector3& c); + float ComponentZ(float x, float y) const; + // Compute the distance of parallel lines projected from this plane to xy plane + // it is assumed that distance of parallel lines in this plane is 1 + // a, b determine a line in this plane + float ParallelDistanceGrad(const Vector3& a, const Vector3& b) const; + + Vector3 normal_; // Normal vector of plane + float d_; // Signed distance from (0,0,0) to plane +}; +// Create a scale matrix with x and y scales(in xy-plane) +Matrix3 CreateScale(float xScale, float yScale); +// Create a rotation matrix about the Z axis +// theta is in radians +Matrix3 CreateRotation(float theta); +// Create a translation matrix (on the xy-plane) +Matrix3 CreateTranslation(const Vector2& trans); +// Create a scale matrix with x, y, and z scales +Matrix4 CreateScale(float xScale, float yScale, float zScale); +// Create a rotation matrix about X axis +// theta is in radians +Matrix4 CreateRotationX(float theta); +// Create a rotation matrix about Y axis +// theta is in radians +Matrix4 CreateRotationY(float theta); +// Create a rotation matrix about Z axis +// theta is in radians +Matrix4 CreateRotationZ(float theta); +// Create a 3D translation matrix +Matrix4 CreateTranslation(const Vector3& trans); +// Transform a Vector2 in xy-plane by matrix3 +Vector2 Transform(const Vector2& vec, const Matrix3& mat); +// Transform a Vector3 in 3D world by matrix4 +Vector3 Transform(const Vector3& vec, const Matrix4& mat); +} // namespace TransformHelper +} // namespace OHOS +} // namespace Rosen +#endif // OHOS_ROSEN_WM_MATH_H \ No newline at end of file diff --git a/utils/src/window_property.cpp b/utils/src/window_property.cpp index 98b04ef7..1a01e002 100644 --- a/utils/src/window_property.cpp +++ b/utils/src/window_property.cpp @@ -31,6 +31,7 @@ void WindowProperty::SetWindowName(const std::string& name) void WindowProperty::SetWindowRect(const struct Rect& rect) { + recomputeTransformMat_ = true; windowRect_ = rect; } @@ -108,9 +109,30 @@ void WindowProperty::SetAlpha(float alpha) void WindowProperty::SetTransform(const Transform& trans) { + recomputeTransformMat_ = true; trans_ = trans; } +void WindowProperty::ComputeTransform() +{ + if (recomputeTransformMat_ && (trans_ != Transform::Identity())) { + // Update transform matrix + transformMat_ = WindowHelper::ComputeRectTransformMat4(trans_, windowRect_); + // Update window plane + TransformHelper::Vector3 a = TransformHelper::Transform( + TransformHelper::Vector3 { static_cast(windowRect_.posX_), + static_cast(windowRect_.posY_), 0 }, transformMat_); + TransformHelper::Vector3 b = TransformHelper::Transform( + TransformHelper::Vector3 { static_cast(windowRect_.posX_ + windowRect_.width_), + static_cast(windowRect_.posY_), 0 }, transformMat_); + TransformHelper::Vector3 c = TransformHelper::Transform( + TransformHelper::Vector3 { static_cast(windowRect_.posX_), + static_cast(windowRect_.posY_+ windowRect_.height_), 0 }, transformMat_); + windowPlane_ = TransformHelper::Plane(a, b, c); + recomputeTransformMat_ = false; + } +} + void WindowProperty::SetBrightness(float brightness) { brightness_ = brightness; @@ -411,6 +433,11 @@ WindowSizeLimits WindowProperty::GetSizeLimits() const return sizeLimits_; } +const TransformHelper::Matrix4& WindowProperty::GetTransformMat() const +{ + return transformMat_; +} + void WindowProperty::SetTouchHotAreas(const std::vector& rects) { touchHotAreas_ = rects; diff --git a/utils/src/wm_math.cpp b/utils/src/wm_math.cpp new file mode 100644 index 00000000..e46143d5 --- /dev/null +++ b/utils/src/wm_math.cpp @@ -0,0 +1,319 @@ +/* + * Copyright (c) 2022 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 "wm_math.h" +#include + +namespace OHOS { +namespace Rosen { +namespace TransformHelper { +const Matrix3 Matrix3::Identity = { { + { 1, 0, 0 }, + { 0, 1, 0 }, + { 0, 0, 1 }, +} }; +const Matrix4 Matrix4::Identity = { { + { 1, 0, 0, 0 }, + { 0, 1, 0, 0 }, + { 0, 0, 1, 0 }, + { 0, 0, 0, 1 }, +} }; + +Matrix3 operator*(const Matrix3& left, const Matrix3& right) +{ + return { { + // row 0 + { left.mat_[0][0] * right.mat_[0][0] + left.mat_[0][1] * right.mat_[1][0] + left.mat_[0][2] * right.mat_[2][0], + left.mat_[0][0] * right.mat_[0][1] + left.mat_[0][1] * right.mat_[1][1] + left.mat_[0][2] * right.mat_[2][1], + left.mat_[0][0] * right.mat_[0][2] + left.mat_[0][1] * right.mat_[1][2] + left.mat_[0][2] * right.mat_[2][2] }, + + // row 1 + { left.mat_[1][0] * right.mat_[0][0] + left.mat_[1][1] * right.mat_[1][0] + left.mat_[1][2] * right.mat_[2][0], + left.mat_[1][0] * right.mat_[0][1] + left.mat_[1][1] * right.mat_[1][1] + left.mat_[1][2] * right.mat_[2][1], + left.mat_[1][0] * right.mat_[0][2] + left.mat_[1][1] * right.mat_[1][2] + left.mat_[1][2] * right.mat_[2][2] }, + + // row 2 + { left.mat_[2][0] * right.mat_[0][0] + left.mat_[2][1] * right.mat_[1][0] + left.mat_[2][2] * right.mat_[2][0], + left.mat_[2][0] * right.mat_[0][1] + left.mat_[2][1] * right.mat_[1][1] + left.mat_[2][2] * right.mat_[2][1], + left.mat_[2][0] * right.mat_[0][2] + left.mat_[2][1] * right.mat_[1][2] + left.mat_[2][2] * right.mat_[2][2] } + } }; +} + +Matrix3& Matrix3::operator*=(const Matrix3& right) +{ + *this = *this * right; + return *this; +} + +Matrix4 operator*(const Matrix4& left, const Matrix4& right) +{ + return { { + // row 0 + { left.mat_[0][0] * right.mat_[0][0] + left.mat_[0][1] * right.mat_[1][0] + + left.mat_[0][2] * right.mat_[2][0] + left.mat_[0][3] * right.mat_[3][0], + left.mat_[0][0] * right.mat_[0][1] + left.mat_[0][1] * right.mat_[1][1] + + left.mat_[0][2] * right.mat_[2][1] + left.mat_[0][3] * right.mat_[3][1], + left.mat_[0][0] * right.mat_[0][2] + left.mat_[0][1] * right.mat_[1][2] + + left.mat_[0][2] * right.mat_[2][2] + left.mat_[0][3] * right.mat_[3][2], + left.mat_[0][0] * right.mat_[0][3] + left.mat_[0][1] * right.mat_[1][3] + + left.mat_[0][2] * right.mat_[2][3] + left.mat_[0][3] * right.mat_[3][3] }, + + // row 1 + { left.mat_[1][0] * right.mat_[0][0] + left.mat_[1][1] * right.mat_[1][0] + + left.mat_[1][2] * right.mat_[2][0] + left.mat_[1][3] * right.mat_[3][0], + left.mat_[1][0] * right.mat_[0][1] + left.mat_[1][1] * right.mat_[1][1] + + left.mat_[1][2] * right.mat_[2][1] + left.mat_[1][3] * right.mat_[3][1], + left.mat_[1][0] * right.mat_[0][2] + left.mat_[1][1] * right.mat_[1][2] + + left.mat_[1][2] * right.mat_[2][2] + left.mat_[1][3] * right.mat_[3][2], + left.mat_[1][0] * right.mat_[0][3] + left.mat_[1][1] * right.mat_[1][3] + + left.mat_[1][2] * right.mat_[2][3] + left.mat_[1][3] * right.mat_[3][3] }, + + // row 2 + { left.mat_[2][0] * right.mat_[0][0] + left.mat_[2][1] * right.mat_[1][0] + + left.mat_[2][2] * right.mat_[2][0] + left.mat_[2][3] * right.mat_[3][0], + left.mat_[2][0] * right.mat_[0][1] + left.mat_[2][1] * right.mat_[1][1] + + left.mat_[2][2] * right.mat_[2][1] + left.mat_[2][3] * right.mat_[3][1], + left.mat_[2][0] * right.mat_[0][2] + left.mat_[2][1] * right.mat_[1][2] + + left.mat_[2][2] * right.mat_[2][2] + left.mat_[2][3] * right.mat_[3][2], + left.mat_[2][0] * right.mat_[0][3] + left.mat_[2][1] * right.mat_[1][3] + + left.mat_[2][2] * right.mat_[2][3] + left.mat_[2][3] * right.mat_[3][3] }, + + // row 3 + { left.mat_[3][0] * right.mat_[0][0] + left.mat_[3][1] * right.mat_[1][0] + + left.mat_[3][2] * right.mat_[2][0] + left.mat_[3][3] * right.mat_[3][0], + left.mat_[3][0] * right.mat_[0][1] + left.mat_[3][1] * right.mat_[1][1] + + left.mat_[3][2] * right.mat_[2][1] + left.mat_[3][3] * right.mat_[3][1], + left.mat_[3][0] * right.mat_[0][2] + left.mat_[3][1] * right.mat_[1][2] + + left.mat_[3][2] * right.mat_[2][2] + left.mat_[3][3] * right.mat_[3][2], + left.mat_[3][0] * right.mat_[0][3] + left.mat_[3][1] * right.mat_[1][3] + + left.mat_[3][2] * right.mat_[2][3] + left.mat_[3][3] * right.mat_[3][3] } + } }; +} + +Matrix4& Matrix4::operator*=(const Matrix4& right) +{ + *this = *this * right; + return *this; +} + +void Matrix4::SwapRow(int row1, int row2) +{ + float *p = mat_[row1]; + float *q = mat_[row2]; + float tmp = p[0]; + p[0] = q[0]; + q[0] = tmp; + + tmp = p[1]; + p[1] = q[1]; + q[1] = tmp; + + tmp = p[2]; + p[2] = q[2]; + q[2] = tmp; + + tmp = p[3]; + p[3] = q[3]; + q[3] = tmp; +} + +void Matrix4::Invert() +{ + // Inverse matrix with Gauss-Jordan method + Matrix4 tmp = Matrix4::Identity; + int i, j, k; + float t, u; + for (k = 0; k < MAT_SIZE; k++) { + t = mat_[k][k]; + if (t < MathHelper::POS_ZERO && t > MathHelper::NAG_ZERO) { + for (i = k + 1; i < MAT_SIZE; i++) { + if (mat_[i][k] < MathHelper::NAG_ZERO || mat_[i][k] > MathHelper::POS_ZERO) { + SwapRow(k, i); + tmp.SwapRow(k, i); + break; + } + } + t = mat_[k][k]; + } + for (j = 0; j <= k; j++) { + tmp.mat_[k][j] /= t; + } + for (; j < MAT_SIZE; j++) { + mat_[k][j] /= t; + tmp.mat_[k][j] /= t; + } + for (i = 0; i < MAT_SIZE; i++) { + if (i == k) { + continue; + } + u = mat_[i][k]; + for (j = 0; j <= k; j++) { + tmp.mat_[i][j] -= tmp.mat_[k][j] * u; + } + for (; j < MAT_SIZE; j++) { + mat_[i][j] -= mat_[k][j] * u; + tmp.mat_[i][j] -= tmp.mat_[k][j] * u; + } + } + } + *this = tmp; +} + +Vector3 Matrix4::GetScale() const +{ + Vector3 retVal; + retVal.x_ = Vector3(mat_[0][0], mat_[0][1], mat_[0][2]).Length(); + retVal.y_ = Vector3(mat_[1][0], mat_[1][1], mat_[1][2]).Length(); + retVal.z_ = Vector3(mat_[2][0], mat_[2][1], mat_[2][2]).Length(); + return retVal; +} + +Plane::Plane(const Vector3& normal, float d) + : normal_(normal), d_(d) +{ +} + +Plane::Plane(const Vector3& a, const Vector3& b, const Vector3& c) +{ + Vector3 ab = b - a; + Vector3 ac = c - a; + normal_ = Vector3::Cross(ab, ac); + normal_.Normalize(); + d_ = -Vector3::Dot(a, normal_); +} + +float Plane::ComponentZ(float x, float y) const +{ + return (-d_ - normal_.x_ * x - normal_.y_ * y) / normal_.z_; +} + +float Plane::ParallelDistanceGrad(const Vector3& a, const Vector3& b) const +{ + Vector2 axy(a.x_, a.y_), bxy(b.x_, b.y_); + return (b - a).Length() * std::abs(normal_.z_) / (bxy - axy).Length(); +} + +// Create a scale matrix with x and y scales +Matrix3 CreateScale(float xScale, float yScale) +{ + return { { + { xScale, 0.0f, 0.0f }, + { 0.0f, yScale, 0.0f }, + { 0.0f, 0.0f, 1.0f }, + } }; +} + +// Create a rotation matrix about the Z axis +// theta is in radians +Matrix3 CreateRotation(float theta) +{ + return { { + { std::cos(theta), std::sin(theta), 0.0f }, + { -std::sin(theta), std::cos(theta), 0.0f }, + { 0.0f, 0.0f, 1.0f }, + } }; +} + +// Create a translation matrix (on the xy-plane) +Matrix3 CreateTranslation(const Vector2& trans) +{ + return { { + { 1.0f, 0.0f, 0.0f }, + { 0.0f, 1.0f, 0.0f }, + { trans.x_, trans.y_, 1.0f }, + } }; +} + +// Create a scale matrix with x, y, and z scales +Matrix4 CreateScale(float xScale, float yScale, float zScale) +{ + return { { + { xScale, 0.0f, 0.0f, 0.0f }, + { 0.0f, yScale, 0.0f, 0.0f }, + { 0.0f, 0.0f, zScale, 0.0f }, + { 0.0f, 0.0f, 0.0f, 1.0f }, + } }; +} + +// Create a rotation matrix about X axis +// theta is in radians +Matrix4 CreateRotationX(float theta) +{ + return { { + { 1.0f, 0.0f, 0.0f, 0.0f }, + { 0.0f, std::cos(theta), std::sin(theta), 0.0f }, + { 0.0f, -std::sin(theta), std::cos(theta), 0.0f }, + { 0.0f, 0.0f, 0.0f, 1.0f }, + } }; +} + +// Create a rotation matrix about Y axis +// theta is in radians +Matrix4 CreateRotationY(float theta) +{ + return { { + { std::cos(theta), 0.0f, -std::sin(theta), 0.0f }, + { 0.0f, 1.0f, 0.0f, 0.0f }, + { std::sin(theta), 0.0f, std::cos(theta), 0.0f }, + { 0.0f, 0.0f, 0.0f, 1.0f }, + } }; +} + +// Create a rotation matrix about Z axis +// theta is in radians +Matrix4 CreateRotationZ(float theta) +{ + return { { + { std::cos(theta), std::sin(theta), 0.0f, 0.0f }, + { -std::sin(theta), std::cos(theta), 0.0f, 0.0f }, + { 0.0f, 0.0f, 1.0f, 0.0f }, + { 0.0f, 0.0f, 0.0f, 1.0f }, + } }; +} + +// Create a 3D translation matrix +Matrix4 CreateTranslation(const Vector3& trans) +{ + return { { + { 1.0f, 0.0f, 0.0f, 0.0f }, + { 0.0f, 1.0f, 0.0f, 0.0f }, + { 0.0f, 0.0f, 1.0f, 0.0f }, + { trans.x_, trans.y_, trans.z_, 1.0f }, + } }; +} + +// Transform a Vector2 in xy-plane by matrix3 +Vector2 Transform(const Vector2& vec, const Matrix3& mat) +{ + Vector2 retVal; + retVal.x_ = vec.x_ * mat.mat_[0][0] + vec.y_ * mat.mat_[1][0] + mat.mat_[2][0]; + retVal.y_ = vec.x_ * mat.mat_[0][1] + vec.y_ * mat.mat_[1][1] + mat.mat_[2][1]; + return retVal; +} + +// Transform a Vector3 in 3D world by matrix4 +Vector3 Transform(const Vector3& vec, const Matrix4& mat) +{ + Vector3 retVal; + retVal.x_ = vec.x_ * mat.mat_[0][0] + vec.y_ * mat.mat_[1][0] + + vec.z_ * mat.mat_[2][0] + mat.mat_[3][0]; + retVal.y_ = vec.x_ * mat.mat_[0][1] + vec.y_ * mat.mat_[1][1] + + vec.z_ * mat.mat_[2][1] + mat.mat_[3][1]; + retVal.z_ = vec.x_ * mat.mat_[0][2] + vec.y_ * mat.mat_[1][2] + + vec.z_ * mat.mat_[2][2] + mat.mat_[3][2]; + return retVal; +} +} // namespace TransformHelper +} // namespace Rosen +} // namespace OHOS diff --git a/wm/include/window_impl.h b/wm/include/window_impl.h index a17d05a6..581ecb71 100644 --- a/wm/include/window_impl.h +++ b/wm/include/window_impl.h @@ -345,6 +345,7 @@ private: Rect GetSystemAlarmWindowDefaultSize(Rect defaultRect); void HandleModeChangeHotZones(int32_t posX, int32_t posY); WMError NotifyWindowTransition(TransitionReason reason); + void UpdatePointerEvent(std::shared_ptr& pointerEvent); void UpdatePointerEventForStretchableWindow(std::shared_ptr& pointerEvent); void UpdateDragType(); void InitListenerHandler(); diff --git a/wm/src/window_impl.cpp b/wm/src/window_impl.cpp index 72ad62d1..95d71e6d 100755 --- a/wm/src/window_impl.cpp +++ b/wm/src/window_impl.cpp @@ -1924,6 +1924,28 @@ void WindowImpl::HandleModeChangeHotZones(int32_t posX, int32_t posY) } } +void WindowImpl::UpdatePointerEvent(std::shared_ptr& pointerEvent) +{ + property_->ComputeTransform(); + MMI::PointerEvent::PointerItem pointerItem; + if (!pointerEvent->GetPointerItem(pointerEvent->GetPointerId(), pointerItem)) { + WLOGFW("Point item is invalid"); + return; + } + Rect winRect = GetRect(); + PointInfo originPos = + WindowHelper::CalculateOriginPosition(property_->GetTransformMat(), property_->GetPlane(), + { pointerItem.GetDisplayX(), pointerItem.GetDisplayY() }); + WLOGI("Pointer event has been updated,window id:%{public}u, before->now:" + "[%{public}d,%{public}d]->[%{public}d,%{public}d]", + property_->GetWindowId(), pointerItem.GetDisplayX(), pointerItem.GetDisplayY(), originPos.x, originPos.y); + pointerItem.SetDisplayX(originPos.x); + pointerItem.SetDisplayY(originPos.y); + pointerItem.SetWindowX(originPos.x - winRect.posX_); + pointerItem.SetWindowY(originPos.y - winRect.posY_); + pointerEvent->UpdatePointerItem(pointerEvent->GetPointerId(), pointerItem); +} + void WindowImpl::UpdatePointerEventForStretchableWindow(std::shared_ptr& pointerEvent) { MMI::PointerEvent::PointerItem pointerItem; @@ -1986,6 +2008,12 @@ void WindowImpl::ReadyToMoveOrDragWindow(int32_t globalX, int32_t globalY, int32 if (pointEventStarted_) { return; } + TransformHelper::Vector2 hotZoneScale(1, 1); + if (property_->GetTransform() != Transform::Identity()) { + property_->ComputeTransform(); + hotZoneScale = WindowHelper::CalculateHotZoneScale(property_->GetTransformMat(), + property_->GetPlane()); + } startPointRect_ = rect; startPointPosX_ = globalX; startPointPosY_ = globalY; @@ -2002,22 +2030,24 @@ void WindowImpl::ReadyToMoveOrDragWindow(int32_t globalX, int32_t globalY, int32 float virtualPixelRatio = display->GetVirtualPixelRatio(); startRectExceptFrame_.posX_ = startPointRect_.posX_ + - static_cast(WINDOW_FRAME_WIDTH * virtualPixelRatio); + static_cast(WINDOW_FRAME_WIDTH * virtualPixelRatio / hotZoneScale.x_); startRectExceptFrame_.posY_ = startPointRect_.posY_ + - static_cast(WINDOW_FRAME_WIDTH * virtualPixelRatio); + static_cast(WINDOW_FRAME_WIDTH * virtualPixelRatio / hotZoneScale.y_); startRectExceptFrame_.width_ = startPointRect_.width_ - - static_cast((WINDOW_FRAME_WIDTH + WINDOW_FRAME_WIDTH) * virtualPixelRatio); + static_cast((WINDOW_FRAME_WIDTH + WINDOW_FRAME_WIDTH) * virtualPixelRatio / hotZoneScale.x_); startRectExceptFrame_.height_ = startPointRect_.height_ - - static_cast((WINDOW_FRAME_WIDTH + WINDOW_FRAME_WIDTH) * virtualPixelRatio); + static_cast((WINDOW_FRAME_WIDTH + WINDOW_FRAME_WIDTH) * virtualPixelRatio / hotZoneScale.y_); startRectExceptCorner_.posX_ = startPointRect_.posX_ + - static_cast(WINDOW_FRAME_CORNER_WIDTH * virtualPixelRatio); + static_cast(WINDOW_FRAME_CORNER_WIDTH * virtualPixelRatio / hotZoneScale.x_); startRectExceptCorner_.posY_ = startPointRect_.posY_ + - static_cast(WINDOW_FRAME_CORNER_WIDTH * virtualPixelRatio); + static_cast(WINDOW_FRAME_CORNER_WIDTH * virtualPixelRatio / hotZoneScale.y_); startRectExceptCorner_.width_ = startPointRect_.width_ - - static_cast((WINDOW_FRAME_CORNER_WIDTH + WINDOW_FRAME_CORNER_WIDTH) * virtualPixelRatio); + static_cast((WINDOW_FRAME_CORNER_WIDTH + WINDOW_FRAME_CORNER_WIDTH) * + virtualPixelRatio / hotZoneScale.x_); startRectExceptCorner_.height_ = startPointRect_.height_ - - static_cast((WINDOW_FRAME_CORNER_WIDTH + WINDOW_FRAME_CORNER_WIDTH) * virtualPixelRatio); + static_cast((WINDOW_FRAME_CORNER_WIDTH + WINDOW_FRAME_CORNER_WIDTH) * + virtualPixelRatio / hotZoneScale.y_); if (GetType() == WindowType::WINDOW_TYPE_DOCK_SLICE) { startMoveFlag_ = true; @@ -2103,6 +2133,10 @@ void WindowImpl::AdjustWindowAnimationFlag(bool withAnimation) void WindowImpl::ConsumePointerEvent(std::shared_ptr& pointerEvent) { + // If windowRect transformed, transform event back to its origin position + if (property_->GetTransform() != Transform::Identity()) { + UpdatePointerEvent(pointerEvent); + } int32_t action = pointerEvent->GetPointerAction(); if (action == MMI::PointerEvent::POINTER_ACTION_DOWN || action == MMI::PointerEvent::POINTER_ACTION_BUTTON_DOWN) { WLOGI("WMS process point down, window: [name:%{public}s, id:%{public}u], action: %{public}d", diff --git a/wmserver/include/window_controller.h b/wmserver/include/window_controller.h index beb2a566..1308713c 100644 --- a/wmserver/include/window_controller.h +++ b/wmserver/include/window_controller.h @@ -83,6 +83,7 @@ private: void HandleTurnScreenOn(const sptr& node); void ProcessSystemBarChange(const sptr& displayInfo); WMError UpdateTouchHotAreas(const sptr& node, const std::vector& rects); + WMError UpdateTransform(uint32_t windowId); void NotifyTouchOutside(const sptr& node); uint32_t GetEmbedNodeId(const std::vector>& windowNodes, const sptr& node); void NotifyWindowPropertyChanged(const sptr& node); diff --git a/wmserver/include/window_node.h b/wmserver/include/window_node.h index 8fb948f1..ade0feea 100644 --- a/wmserver/include/window_node.h +++ b/wmserver/include/window_node.h @@ -72,6 +72,8 @@ public: void SetOriginRect(const Rect& rect); void SetTouchHotAreas(const std::vector& rects); void SetWindowSizeLimits(const WindowSizeLimits& sizeLimits); + void ComputeTransform(); + void SetTransform(const Transform& trans); const sptr& GetWindowToken() const; uint32_t GetWindowId() const; diff --git a/wmserver/src/input_window_monitor.cpp b/wmserver/src/input_window_monitor.cpp index cb53ec26..b971670e 100644 --- a/wmserver/src/input_window_monitor.cpp +++ b/wmserver/src/input_window_monitor.cpp @@ -19,6 +19,7 @@ #include "display_manager_service_inner.h" #include "dm_common.h" +#include "window_helper.h" #include "window_manager_hilog.h" namespace OHOS { @@ -128,13 +129,24 @@ void InputWindowMonitor::TraverseWindowNodes(const std::vector> } std::vector touchHotAreas; windowNode->GetTouchHotAreas(touchHotAreas); - Rect windowRect = windowNode->GetWindowRect(); + Rect areaRect = windowNode->GetWindowRect(); + if (windowNode->GetWindowProperty()->GetTransform() != Transform::Identity()) { + windowNode->ComputeTransform(); + for (Rect& rect : touchHotAreas) { + rect = WindowHelper::TransformRect(windowNode->GetWindowProperty()->GetTransformMat(), rect); + } + WLOGFI("area rect befoe tranform: [%{public}d, %{public}d, %{public}u, %{public}u]", + areaRect.posX_, areaRect.posY_, areaRect.width_, areaRect.height_); + areaRect = WindowHelper::TransformRect(windowNode->GetWindowProperty()->GetTransformMat(), areaRect); + WLOGFI("area rect after tranform: [%{public}d, %{public}d, %{public}u, %{public}u]", + areaRect.posX_, areaRect.posY_, areaRect.width_, areaRect.height_); + } MMI::WindowInfo windowInfo = { .id = static_cast(windowNode->GetWindowId()), .pid = windowNode->GetCallingPid(), .uid = windowNode->GetCallingUid(), - .area = MMI::Rect{ windowRect.posX_, windowRect.posY_, - static_cast(windowRect.width_), static_cast(windowRect.height_) }, + .area = MMI::Rect { areaRect.posX_, areaRect.posY_, + static_cast(areaRect.width_), static_cast(areaRect.height_) }, .agentWindowId = static_cast(windowNode->GetWindowId()), }; convertRectsToMmiRects(touchHotAreas, windowInfo.defaultHotAreas); diff --git a/wmserver/src/window_controller.cpp b/wmserver/src/window_controller.cpp index 04f37893..f62a70d8 100644 --- a/wmserver/src/window_controller.cpp +++ b/wmserver/src/window_controller.cpp @@ -891,6 +891,12 @@ WMError WindowController::UpdateProperty(sptr& property, Propert UpdateWindowAnimation(node); break; } + case PropertyChangeAction::ACTION_UPDATE_TRANSFORM_PROPERTY: { + node->SetTransform(property->GetTransform()); + node->SetWindowSizeChangeReason(WindowSizeChangeReason::TRANSFORM); + ret = UpdateTransform(windowId); + break; + } default: break; } @@ -950,6 +956,16 @@ WMError WindowController::UpdateTouchHotAreas(const sptr& node, cons return WMError::WM_OK; } +WMError WindowController::UpdateTransform(uint32_t windowId) +{ + WMError res = windowRoot_->UpdateWindowNode(windowId, WindowUpdateReason::UPDATE_TRANSFORM); + if (res != WMError::WM_OK) { + return res; + } + FlushWindowInfo(windowId); + return WMError::WM_OK; +} + void WindowController::NotifyTouchOutside(const sptr& node) { auto windowNodeContainer = windowRoot_->GetOrCreateWindowNodeContainer(node->GetDisplayId()); diff --git a/wmserver/src/window_layout_policy.cpp b/wmserver/src/window_layout_policy.cpp index 7bd0f8a4..b88caec3 100644 --- a/wmserver/src/window_layout_policy.cpp +++ b/wmserver/src/window_layout_policy.cpp @@ -422,23 +422,30 @@ void WindowLayoutPolicy::CalcAndSetNodeHotZone(const Rect& winRect, const sptrGetDisplayId()); - uint32_t hotZone = static_cast(HOTZONE * virtualPixelRatio); + TransformHelper::Vector2 hotZoneScale(1, 1); + if (node->GetWindowProperty()->GetTransform() != Transform::Identity()) { + node->ComputeTransform(); + hotZoneScale = WindowHelper::CalculateHotZoneScale(node->GetWindowProperty()->GetTransformMat(), + node->GetWindowProperty()->GetPlane()); + } + uint32_t hotZoneX = static_cast(HOTZONE * virtualPixelRatio / hotZoneScale.x_); + uint32_t hotZoneY = static_cast(HOTZONE * virtualPixelRatio / hotZoneScale.y_); if (node->GetWindowType() == WindowType::WINDOW_TYPE_DOCK_SLICE) { if (rect.width_ < rect.height_) { - rect.posX_ -= hotZone; - rect.width_ += (hotZone + hotZone); + rect.posX_ -= hotZoneX; + rect.width_ += (hotZoneX + hotZoneX); } else { - rect.posY_ -= hotZone; - rect.height_ += (hotZone + hotZone); + rect.posY_ -= hotZoneY; + rect.height_ += (hotZoneY + hotZoneY); } } else if (node->GetWindowType() == WindowType::WINDOW_TYPE_LAUNCHER_RECENT) { rect = displayGroupInfo_->GetDisplayRect(node->GetDisplayId()); } else if (WindowHelper::IsMainFloatingWindow(node->GetWindowType(), node->GetWindowMode())) { - rect.posX_ -= hotZone; - rect.posY_ -= hotZone; - rect.width_ += (hotZone + hotZone); - rect.height_ += (hotZone + hotZone); + rect.posX_ -= hotZoneX; + rect.posY_ -= hotZoneY; + rect.width_ += (hotZoneX + hotZoneX); + rect.height_ += (hotZoneY + hotZoneY); } node->SetFullWindowHotArea(rect); std::vector requestedHotAreas; @@ -938,7 +945,8 @@ bool WindowLayoutPolicy::IsFullScreenRecentWindowExist(const std::vector& node, const Rect& winRect, const Rect& preRect) { - if (node->GetWindowType() == WindowType::WINDOW_TYPE_APP_COMPONENT) { + if (node->GetWindowType() == WindowType::WINDOW_TYPE_APP_COMPONENT || + node->GetWindowSizeChangeReason() == WindowSizeChangeReason::TRANSFORM) { WLOGFI("not need to update bounds"); return; } diff --git a/wmserver/src/window_node.cpp b/wmserver/src/window_node.cpp index d7b87473..5fb8d7c9 100644 --- a/wmserver/src/window_node.cpp +++ b/wmserver/src/window_node.cpp @@ -201,6 +201,16 @@ void WindowNode::SetWindowSizeLimits(const WindowSizeLimits& sizeLimits) property_->SetSizeLimits(sizeLimits); } +void WindowNode::ComputeTransform() +{ + property_->ComputeTransform(); +} + +void WindowNode::SetTransform(const Transform& trans) +{ + property_->SetTransform(trans); +} + WindowSizeLimits WindowNode::GetWindowSizeLimits() const { return property_->GetSizeLimits();