From 49486f0153cf8990601f327ee7c0b503f1f1f8a8 Mon Sep 17 00:00:00 2001 From: laiguizhong Date: Thu, 6 Jan 2022 21:01:15 +0800 Subject: [PATCH] add windowmanager & add window js api Signed-off-by: laiguizhong Change-Id: Ia303d155a0d30da4736e96b009125f40d4c3837a --- adapter/BUILD.gn | 23 +- adapter/include/adapter.h | 2 +- dm/include/display_manager_adapter.h | 13 +- dm/src/display_manager.cpp | 83 ++-- dm/src/display_manager_adapter.cpp | 51 ++- .../{display_screen.h => abstract_display.h} | 12 +- ...n_manager.h => abstract_display_manager.h} | 26 +- dmserver/include/display_manager_interface.h | 23 +- dmserver/include/display_manager_proxy.h | 8 +- dmserver/include/display_manager_service.h | 15 +- .../include/display_manager_service_inner.h | 10 +- dmserver/include/virtual_display_info.h | 46 ++ ...isplay_screen.cpp => abstract_display.cpp} | 20 +- dmserver/src/abstract_display_manager.cpp | 136 ++++++ dmserver/src/display_manager_proxy.cpp | 117 +++-- dmserver/src/display_manager_service.cpp | 53 +-- .../src/display_manager_service_inner.cpp | 32 +- dmserver/src/display_manager_stub.cpp | 32 +- dmserver/src/display_screen_manager.cpp | 51 --- dmserver/src/rs_adapter.cpp | 2 - dmserver/src/virtual_display_info.cpp | 61 +++ interfaces/innerkits/BUILD.gn | 1 + interfaces/innerkits/dm/display_manager.h | 23 +- interfaces/innerkits/wm/window.h | 22 +- .../wm/window_life_cycle_interface.h | 4 +- interfaces/innerkits/wm/window_manager.h | 57 +++ interfaces/innerkits/wm/window_option.h | 9 +- interfaces/innerkits/wm/window_scene.h | 7 +- interfaces/innerkits/wm/wm_common.h | 38 +- interfaces/kits/napi/BUILD.gn | 1 + .../napi/display/native_display_module.cpp | 15 +- .../kits/napi/window/native_window_module.cpp | 25 +- interfaces/kits/napi/window_runtime/BUILD.gn | 55 +++ .../napi/window_runtime/api/@ohos.window.d.ts | 249 +++++++++++ .../kits/napi/window_runtime/js_window.cpp | 420 ++++++++++++++++++ .../kits/napi/window_runtime/js_window.h | 60 +++ .../window_runtime/js_window_listener.cpp | 118 +++++ .../napi/window_runtime/js_window_listener.h | 43 ++ .../napi/window_runtime/js_window_manager.cpp | 149 +++++++ .../napi/window_runtime/js_window_manager.h | 26 ++ .../napi/window_runtime/js_window_utils.cpp | 60 +++ .../napi/window_runtime/js_window_utils.h | 35 ++ .../window_runtime/window_manager_module.cpp | 30 ++ interfaces/kits/napi/window_stage.js | 16 + ohos.build | 3 +- sa_profile/4606.xml | 2 +- utils/include/noncopyable.h | 42 ++ utils/include/single_instance.h | 21 +- utils/include/singleton_container.h | 44 +- utils/include/singleton_delegator.h | 8 +- utils/include/static_call.h | 6 +- utils/include/window_helper.h | 60 +++ utils/include/wm_trace.h | 55 +++ utils/src/singleton_container.cpp | 27 +- utils/src/static_call.cpp | 6 +- utils/src/wm_trace.cpp | 92 ++++ wm/BUILD.gn | 34 +- wm/include/input_transfer_station.h | 10 +- wm/include/vsync_station.h | 4 +- wm/include/window_adapter.h | 13 +- wm/include/window_agent.h | 1 + wm/include/window_impl.h | 29 +- wm/include/window_interface.h | 2 + wm/include/window_manager_agent.h | 33 ++ wm/include/window_property.h | 10 +- wm/include/window_proxy.h | 1 + .../zidl/window_manager_agent_interface.h | 37 ++ wm/include/zidl/window_manager_agent_proxy.h | 38 ++ wm/include/zidl/window_manager_agent_stub.h | 34 ++ wm/src/input_transfer_station.cpp | 5 +- wm/src/vsync_station.cpp | 30 +- wm/src/window.cpp | 10 +- wm/src/window_adapter.cpp | 47 +- wm/src/window_agent.cpp | 9 + wm/src/window_impl.cpp | 254 +++++++++-- wm/src/window_input_channel.cpp | 7 +- wm/src/window_manager.cpp | 116 +++++ wm/src/window_manager_agent.cpp | 28 ++ wm/src/window_option.cpp | 12 + wm/src/window_property.cpp | 49 ++ wm/src/window_proxy.cpp | 20 + wm/src/window_scene.cpp | 41 +- wm/src/window_stub.cpp | 6 +- wm/src/zidl/window_manager_agent_proxy.cpp | 67 +++ wm/src/zidl/window_manager_agent_stub.cpp | 51 +++ wmserver/BUILD.gn | 33 +- wmserver/include/input_window_monitor.h | 2 +- wmserver/include/window_controller.h | 9 +- wmserver/include/window_layout_policy.h | 23 +- wmserver/include/window_manager_interface.h | 14 + wmserver/include/window_manager_proxy.h | 7 + wmserver/include/window_manager_service.h | 17 +- wmserver/include/window_node.h | 15 +- wmserver/include/window_node_container.h | 36 +- wmserver/include/window_root.h | 29 +- wmserver/src/input_window_monitor.cpp | 15 +- wmserver/src/window_controller.cpp | 129 ++++-- wmserver/src/window_layout_policy.cpp | 230 +++++----- wmserver/src/window_manager_proxy.cpp | 146 +++++- wmserver/src/window_manager_service.cpp | 96 +++- wmserver/src/window_manager_stub.cpp | 45 +- wmserver/src/window_node.cpp | 18 +- wmserver/src/window_node_container.cpp | 165 +++++-- wmserver/src/window_root.cpp | 125 +++++- wmtest/BUILD.gn | 16 +- wmtest/test/dm_native_test.cpp | 13 +- wmtest/unittest/BUILD.gn | 18 +- 107 files changed, 4081 insertions(+), 763 deletions(-) rename dmserver/include/{display_screen.h => abstract_display.h} (78%) rename dmserver/include/{display_screen_manager.h => abstract_display_manager.h} (55%) create mode 100644 dmserver/include/virtual_display_info.h rename dmserver/src/{display_screen.cpp => abstract_display.cpp} (65%) create mode 100644 dmserver/src/abstract_display_manager.cpp delete mode 100644 dmserver/src/display_screen_manager.cpp create mode 100644 dmserver/src/virtual_display_info.cpp create mode 100644 interfaces/innerkits/wm/window_manager.h create mode 100644 interfaces/kits/napi/window_runtime/BUILD.gn create mode 100644 interfaces/kits/napi/window_runtime/api/@ohos.window.d.ts create mode 100644 interfaces/kits/napi/window_runtime/js_window.cpp create mode 100644 interfaces/kits/napi/window_runtime/js_window.h create mode 100644 interfaces/kits/napi/window_runtime/js_window_listener.cpp create mode 100644 interfaces/kits/napi/window_runtime/js_window_listener.h create mode 100644 interfaces/kits/napi/window_runtime/js_window_manager.cpp create mode 100644 interfaces/kits/napi/window_runtime/js_window_manager.h create mode 100644 interfaces/kits/napi/window_runtime/js_window_utils.cpp create mode 100644 interfaces/kits/napi/window_runtime/js_window_utils.h create mode 100644 interfaces/kits/napi/window_runtime/window_manager_module.cpp create mode 100644 utils/include/noncopyable.h create mode 100644 utils/include/window_helper.h create mode 100644 utils/include/wm_trace.h create mode 100644 utils/src/wm_trace.cpp create mode 100644 wm/include/window_manager_agent.h create mode 100644 wm/include/zidl/window_manager_agent_interface.h create mode 100644 wm/include/zidl/window_manager_agent_proxy.h create mode 100644 wm/include/zidl/window_manager_agent_stub.h create mode 100644 wm/src/window_manager.cpp create mode 100644 wm/src/window_manager_agent.cpp create mode 100644 wm/src/zidl/window_manager_agent_proxy.cpp create mode 100644 wm/src/zidl/window_manager_agent_stub.cpp diff --git a/adapter/BUILD.gn b/adapter/BUILD.gn index 0efe5542..f1ceabcd 100644 --- a/adapter/BUILD.gn +++ b/adapter/BUILD.gn @@ -13,8 +13,8 @@ import("//build/ohos.gni") -## Build libwmadaptertest.so {{{ -config("libwmadaptertest_config") { +## Build libwmadapter.so {{{ +config("libwmadapter_config") { visibility = [ ":*" ] include_dirs = [ @@ -37,16 +37,12 @@ config("libwmadaptertest_config") { "//foundation/aafwk/standard/interfaces/innerkits/want/include/ohos/aafwk/content", "//foundation/distributedschedule/dmsfwk/services/dtbschedmgr/include", "//foundation/aafwk/standard/interfaces/innerkits/base/include", - ] - - cflags = [ - "-Wall", - "-Werror", - "-g3", + "//third_party/jsoncpp/include", + "//third_party/json/include", ] } -config("libwmadaptertest_public_config") { +config("libwmadapter_public_config") { include_dirs = [ "//foundation/graphic/standard/interfaces/innerkits/wmclient", "//foundation/windowmanager/interfaces/innerkits/wm", @@ -56,12 +52,12 @@ config("libwmadaptertest_public_config") { ] } -ohos_shared_library("libwmadaptertest") { +ohos_shared_library("libwmadapter") { sources = [ "src/adapter.cpp" ] - configs = [ ":libwmadaptertest_config" ] + configs = [ ":libwmadapter_config" ] - public_configs = [ ":libwmadaptertest_public_config" ] + public_configs = [ ":libwmadapter_public_config" ] deps = [ "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog", @@ -77,9 +73,6 @@ ohos_shared_library("libwmadaptertest") { # ace "//foundation/ace/ace_engine/interfaces/innerkits/ace:ace_uicontent", - - # aafwk - "//foundation/aafwk/standard/interfaces/innerkits/want:want", ] public_deps = [ diff --git a/adapter/include/adapter.h b/adapter/include/adapter.h index c387a88d..229c9dd6 100644 --- a/adapter/include/adapter.h +++ b/adapter/include/adapter.h @@ -27,7 +27,7 @@ #include "wm_common.h" #include "window.h" #include "foundation/graphic/standard/interfaces/innerkits/wmclient/window_option.h" -#include "window_manager.h" +#include "foundation/graphic/standard/interfaces/innerkits/wmclient/window_manager.h" #include "window_manager_hilog.h" namespace OHOS { diff --git a/dm/include/display_manager_adapter.h b/dm/include/display_manager_adapter.h index 61882fd0..53e1c8d3 100644 --- a/dm/include/display_manager_adapter.h +++ b/dm/include/display_manager_adapter.h @@ -17,7 +17,7 @@ #define FOUNDATION_DM_DISPLAY_MANAGER_ADAPTER_H #include -#include +#include #include "display.h" #include "display_manager_interface.h" @@ -30,13 +30,16 @@ public: virtual void OnRemoteDied(const wptr& wptrDeath) override; }; -class DisplayManagerAdapter : public RefBase { - DECLARE_SINGLE_INSTANCE_BASE(DisplayManagerAdapter); +class DisplayManagerAdapter { +DECLARE_SINGLE_INSTANCE_BASE(DisplayManagerAdapter); public: - sptr GetDisplay(DisplayType type); DisplayId GetDefaultDisplayId(); sptr GetDisplayById(DisplayId displayId); - + DisplayId CreateVirtualDisplay(const VirtualDisplayInfo &virtualDisplayInfo, + sptr surface); + bool DestroyVirtualDisplay(DisplayId displayId); + // TODO: fix me + // sptr GetDisplaySnapshot(DisplayId displayId); void Clear(); private: DisplayManagerAdapter() = default; diff --git a/dm/src/display_manager.cpp b/dm/src/display_manager.cpp index 8c6c34fe..6ec0eb69 100644 --- a/dm/src/display_manager.cpp +++ b/dm/src/display_manager.cpp @@ -15,7 +15,7 @@ #include "display_manager.h" -#include +#include #include "display_manager_adapter.h" #include "window_manager_hilog.h" @@ -25,43 +25,14 @@ namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "DisplayManager"}; } -IMPLEMENT_SINGLE_INSTANCE(DisplayManager); - -DisplayManager::DisplayManager() -{ - dmsAdapter_ = SingletonContainer::Get(); -} - -DisplayManager::~DisplayManager() -{ -} - -const sptr& DisplayManager::GetDisplay(const DisplayType type) -{ - if (dmsAdapter_ == nullptr) { - WLOGFE("DisplayManager::GetDisplay null!"); - return nullptr; - } - return dmsAdapter_->GetDisplay(type); -} - DisplayId DisplayManager::GetDefaultDisplayId() { - if (dmsAdapter_ == nullptr) { - WLOGFE("DisplayManager::GetDefaultDisplayId null!\n"); - return DISPLAY_ID_INVALD; - } - return dmsAdapter_->GetDefaultDisplayId(); + return SingletonContainer::Get().GetDefaultDisplayId(); } const sptr DisplayManager::GetDisplayById(DisplayId displayId) { - if (dmsAdapter_ == nullptr) { - WLOGFE("DisplayManager::GetDisplayById null!\n"); - return nullptr; - } - - sptr display = dmsAdapter_->GetDisplayById(displayId); + sptr display = SingletonContainer::Get().GetDisplayById(displayId); if (display == nullptr) { WLOGFE("DisplayManager::GetDisplayById failed!\n"); return nullptr; @@ -69,6 +40,40 @@ const sptr DisplayManager::GetDisplayById(DisplayId displayId) return display; } +// TODO: fix me +// sptr DisplayManager::GetScreenshot(DisplayId displayId) +// { +// sptr screenShot = SingletonContainer::Get().GetDisplaySnapshot(displayId); +// if (screenShot == nullptr) { +// WLOGFE("DisplayManager::GetScreenshot failed!\n"); +// return nullptr; +// } + +// return screenShot; +// } + +// sptr DisplayManager::GetScreenshot(DisplayId displayId, const Media::Rect &rect, +// const Media::Size &size, int rotation) +// { +// sptr screenShot = SingletonContainer::Get().GetDisplaySnapshot(displayId); +// if (screenShot == nullptr) { +// WLOGFE("DisplayManager::GetScreenshot failed!\n"); +// return nullptr; +// } + +// // create crop dest pixelmap +// Media::InitializationOptions opt; +// opt.size.width = size.width; +// opt.size.height = size.height; +// opt.scaleMode = Media::ScaleMode::FIT_TARGET_SIZE; +// opt.editable = false; +// opt.useSourceIfMatch = true; + +// auto dstScreenshot = Media::PixelMap::Create(*screenShot, rect, opt); +// sptr dstScreenshot_ = dstScreenshot.release(); + +// return dstScreenshot_; +// } const sptr DisplayManager::GetDefaultDisplay() { @@ -97,4 +102,18 @@ std::vector> DisplayManager::GetAllDisplays() } return res; } + +DisplayId DisplayManager::CreateVirtualDisplay(const std::string &name, uint32_t width, uint32_t height, + sptr surface, DisplayId displayIdToMirror, int32_t flags) +{ + WLOGFI("DisplayManager::CreateVirtualDisplay multi params"); + VirtualDisplayInfo info(name, width, height, displayIdToMirror, flags); + return SingletonContainer::Get().CreateVirtualDisplay(info, surface); +} + +bool DisplayManager::DestroyVirtualDisplay(DisplayId displayId) +{ + WLOGFI("DisplayManager::DestroyVirtualDisplay override params"); + return SingletonContainer::Get().DestroyVirtualDisplay(displayId); +} } // namespace OHOS::Rosen \ No newline at end of file diff --git a/dm/src/display_manager_adapter.cpp b/dm/src/display_manager_adapter.cpp index 675bb97b..e9d4949d 100644 --- a/dm/src/display_manager_adapter.cpp +++ b/dm/src/display_manager_adapter.cpp @@ -27,21 +27,6 @@ namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "DisplayManagerAdapter"}; } -IMPLEMENT_SINGLE_INSTANCE(DisplayManagerAdapter); - -sptr DisplayManagerAdapter::GetDisplay(DisplayType type) -{ - std::lock_guard lock(mutex_); - - if (!InitDMSProxyLocked()) { - WLOGFE("displayManagerAdapter::GetDisplay: InitDMSProxyLocked failed!"); - return nullptr; - } - sptr info = displayManagerServiceProxy_->GetDisplayInfo(type); - // TODO DisplayInfo内容更新到对应的Display.displayInfo_. auto iter = displayMap_.find(info.id_); - return nullptr; -} - DisplayId DisplayManagerAdapter::GetDefaultDisplayId() { std::lock_guard lock(mutex_); @@ -79,6 +64,40 @@ sptr DisplayManagerAdapter::GetDisplayById(DisplayId displayId) return display; } +// TODO: fix me +// sptr DisplayManagerAdapter::GetDisplaySnapshot(DisplayId displayId) +// { +// std::lock_guard lock(mutex_); + +// if (!InitDMSProxyLocked()) { +// WLOGFE("displayManagerAdapter::GetDisplaySnapshot: InitDMSProxyLocked failed!"); +// return nullptr; +// } + +// sptr dispalySnapshot = displayManagerServiceProxy_->GetDispalySnapshot(displayId); + +// return dispalySnapshot; +// } + +DisplayId DisplayManagerAdapter::CreateVirtualDisplay(const VirtualDisplayInfo &virtualDisplayInfo, + sptr surface) +{ + if (!InitDMSProxyLocked()) { + return DISPLAY_ID_INVALD; + } + WLOGFI("DisplayManagerAdapter::CreateVirtualDisplay"); + return displayManagerServiceProxy_->CreateVirtualDisplay(virtualDisplayInfo, surface); +} + +bool DisplayManagerAdapter::DestroyVirtualDisplay(DisplayId displayId) +{ + if (!InitDMSProxyLocked()) { + return false; + } + WLOGFI("DisplayManagerAdapter::DestroyVirtualDisplay"); + return displayManagerServiceProxy_->DestroyVirtualDisplay(displayId); +} + bool DisplayManagerAdapter::InitDMSProxyLocked() { WLOGFI("InitDMSProxy"); @@ -128,7 +147,7 @@ void DMSDeathRecipient::OnRemoteDied(const wptr& wptrDeath) WLOGFE("object is null"); return; } - SingletonContainer::Get().GetRefPtr()->Clear(); + SingletonContainer::Get().Clear(); return; } diff --git a/dmserver/include/display_screen.h b/dmserver/include/abstract_display.h similarity index 78% rename from dmserver/include/display_screen.h rename to dmserver/include/abstract_display.h index d6566219..ef288bfa 100644 --- a/dmserver/include/display_screen.h +++ b/dmserver/include/abstract_display.h @@ -13,17 +13,17 @@ * limitations under the License. */ -#ifndef FOUNDATION_DMSERVER_DISPLAY_SCREEN_H -#define FOUNDATION_DMSERVER_DISPLAY_SCREEN_H +#ifndef FOUNDATION_DMSERVER_ABSTRACT_DISPLAY_H +#define FOUNDATION_DMSERVER_ABSTRACT_DISPLAY_H #include #include "display_info.h" namespace OHOS::Rosen { -class DisplayScreen : public RefBase { +class AbstractDisplay : public RefBase { public: - DisplayScreen(const DisplayInfo& info); - ~DisplayScreen() = default; + AbstractDisplay(const DisplayInfo& info); + ~AbstractDisplay() = default; DisplayId GetId() const; int32_t GetWidth() const; @@ -42,4 +42,4 @@ private: uint32_t freshRate_ {0}; }; } // namespace OHOS::Rosen -#endif // FOUNDATION_DMSERVER_DISPLAY_SCREEN_H \ No newline at end of file +#endif // FOUNDATION_DMSERVER_ABSTRACT_DISPLAY_H \ No newline at end of file diff --git a/dmserver/include/display_screen_manager.h b/dmserver/include/abstract_display_manager.h similarity index 55% rename from dmserver/include/display_screen_manager.h rename to dmserver/include/abstract_display_manager.h index 0c1df9b3..e18dbbaa 100644 --- a/dmserver/include/display_screen_manager.h +++ b/dmserver/include/abstract_display_manager.h @@ -13,32 +13,36 @@ * limitations under the License. */ -#ifndef FOUNDATION_DMSERVER_DISPLAY_SCREEN_MANAGER_H -#define FOUNDATION_DMSERVER_DISPLAY_SCREEN_MANAGER_H +#ifndef FOUNDATION_DMSERVER_ABSTRACT_DISPLAY_MANAGER_H +#define FOUNDATION_DMSERVER_ABSTRACT_DISPLAY_MANAGER_H #include -#include +#include -#include "display_screen.h" +#include "abstract_display.h" #include "single_instance.h" #include "transaction/rs_interfaces.h" +#include "virtual_display_info.h" namespace OHOS::Rosen { -class DisplayScreenManager : public RefBase { -DECLARE_SINGLE_INSTANCE_BASE(DisplayScreenManager); +class AbstractDisplayManager { +DECLARE_SINGLE_INSTANCE_BASE(AbstractDisplayManager); public: - std::map> displayScreenMap_; + std::map> abstractDisplayMap_; ScreenId GetDefaultScreenId(); RSScreenModeInfo GetScreenActiveMode(ScreenId id); + ScreenId CreateVirtualScreen(const VirtualDisplayInfo &virtualDisplayInfo, sptr surface); + bool DestroyVirtualScreen(ScreenId screenId); + // TODO: fix me + // sptr GetScreenSnapshot(ScreenId screenId); private: - DisplayScreenManager(); - ~DisplayScreenManager(); + AbstractDisplayManager(); + ~AbstractDisplayManager(); void parepareRSScreenManger(); OHOS::Rosen::RSInterfaces *rsInterface_; }; - } // namespace OHOS::Rosen -#endif // FOUNDATION_DMSERVER_DISPLAY_SCREEN_MANAGER_H \ No newline at end of file +#endif // FOUNDATION_DMSERVER_ABSTRACT_DISPLAY_MANAGER_H \ No newline at end of file diff --git a/dmserver/include/display_manager_interface.h b/dmserver/include/display_manager_interface.h index 8a7d71fc..aff799ad 100644 --- a/dmserver/include/display_manager_interface.h +++ b/dmserver/include/display_manager_interface.h @@ -18,23 +18,36 @@ #include +#include + #include "display_info.h" +#include "virtual_display_info.h" +// #include "pixel_map.h" + namespace OHOS::Rosen { class IDisplayManager : public IRemoteBroker { public: DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.IDisplayManager"); enum { - TRANS_ID_GET_DISPLAY_INFO = 1, - TRANS_ID_GET_DEFAULT_DISPLAY_ID = 2, - TRANS_ID_GET_DISPLAY_BY_ID = 3, + TRANS_ID_GET_DEFAULT_DISPLAY_ID = 0, + TRANS_ID_GET_DISPLAY_BY_ID, + TRANS_ID_CREATE_VIRTUAL_DISPLAY, + TRANS_ID_DESTROY_VIRTUAL_DISPLAY, + // TODO: fix me + // TRANS_ID_GET_DISPLAY_SNAPSHOT, }; - virtual const sptr& GetDisplayInfo(const DisplayType type) = 0; - virtual DisplayId GetDefaultDisplayId() = 0; virtual DisplayInfo GetDisplayInfoById(DisplayId displayId) = 0; + + virtual DisplayId CreateVirtualDisplay(const VirtualDisplayInfo &virtualDisplayInfo, + sptr surface) = 0; + virtual bool DestroyVirtualDisplay(DisplayId displayId) = 0; + + // TODO: fix me + // virtual sptr GetDispalySnapshot(DisplayId displayId) = 0; }; } // namespace OHOS::Rosen diff --git a/dmserver/include/display_manager_proxy.h b/dmserver/include/display_manager_proxy.h index 51910712..141bb411 100644 --- a/dmserver/include/display_manager_proxy.h +++ b/dmserver/include/display_manager_proxy.h @@ -27,10 +27,14 @@ public: : IRemoteProxy(impl) {}; ~DisplayManagerProxy() {}; - const sptr& GetDisplayInfo(const DisplayType type) override; - DisplayId GetDefaultDisplayId() override; DisplayInfo GetDisplayInfoById(DisplayId displayId) override; + + DisplayId CreateVirtualDisplay(const VirtualDisplayInfo &virtualDisplayInfo, + sptr surface) override; + bool DestroyVirtualDisplay(DisplayId displayId) override; + // TODO: fix me + // sptr GetDispalySnapshot(DisplayId displayId) override; private: static inline BrokerDelegator delegator_; }; diff --git a/dmserver/include/display_manager_service.h b/dmserver/include/display_manager_service.h index 83ffbbe9..2a07d16b 100644 --- a/dmserver/include/display_manager_service.h +++ b/dmserver/include/display_manager_service.h @@ -20,12 +20,13 @@ #include #include +#include +#include "abstract_display.h" +#include "abstract_display_manager.h" #include "display_manager_stub.h" -#include "display_screen.h" #include "single_instance.h" #include "singleton_delegator.h" -#include "display_screen_manager.h" namespace OHOS::Rosen { class DisplayManagerService : public SystemAbility, public DisplayManagerStub { @@ -36,11 +37,14 @@ DECLARE_SINGLE_INSTANCE_BASE(DisplayManagerService); public: void OnStart() override; void OnStop() override; - const sptr& GetDisplayInfo(const DisplayType type) override; + DisplayId CreateVirtualDisplay(const VirtualDisplayInfo &virtualDisplayInfo, + sptr surface) override; + bool DestroyVirtualDisplay(DisplayId displayId) override; DisplayId GetDefaultDisplayId() override; DisplayInfo GetDisplayInfoById(DisplayId displayId) override; - + // TODO: fix me + // sptr GetDispalySnapshot(DisplayId displayId) override; private: DisplayManagerService(); ~DisplayManagerService() = default; @@ -49,8 +53,7 @@ private: ScreenId GetScreenIdFromDisplayId(DisplayId displayId); static inline SingletonDelegator delegator_; - std::map> displayScreenMap_; - sptr displayScreenManager_; + std::map> abstractDisplayMap_; }; } // namespace OHOS::Rosen diff --git a/dmserver/include/display_manager_service_inner.h b/dmserver/include/display_manager_service_inner.h index 6051c804..9be2dbfb 100644 --- a/dmserver/include/display_manager_service_inner.h +++ b/dmserver/include/display_manager_service_inner.h @@ -19,19 +19,19 @@ #include #include -#include "display_screen.h" +#include "abstract_display.h" #include "single_instance.h" #include "singleton_delegator.h" namespace OHOS::Rosen { -class DisplayManagerServiceInner : public RefBase { +class DisplayManagerServiceInner { DECLARE_SINGLE_INSTANCE(DisplayManagerServiceInner); public: - std::vector> GetAllDisplays(); + std::vector> GetAllDisplays(); DisplayId GetDefaultDisplayId(); - const sptr GetDefaultDisplay(); - const sptr GetDisplayById(DisplayId displayId); + const sptr GetDefaultDisplay(); + const sptr GetDisplayById(DisplayId displayId); std::vector GetAllDisplayIds(); }; } // namespace OHOS::Rosen diff --git a/dmserver/include/virtual_display_info.h b/dmserver/include/virtual_display_info.h new file mode 100644 index 00000000..cb45bc78 --- /dev/null +++ b/dmserver/include/virtual_display_info.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2021 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 FOUNDATION_VIRTUAL_DISPLAY_INFO_H +#define FOUNDATION_VIRTUAL_DISPLAY_INFO_H + +#include + +#include + +#include + +#include "display.h" + +namespace OHOS::Rosen { +class VirtualDisplayInfo : public Parcelable { +public: + VirtualDisplayInfo(); + VirtualDisplayInfo(const std::string &name, uint32_t width, uint32_t height, + DisplayId displayIdToMirror, int32_t flags); + ~VirtualDisplayInfo() = default; + + virtual bool Marshalling(Parcel& parcel) const override; + static VirtualDisplayInfo* Unmarshalling(Parcel& parcel); + + std::string name_; + uint32_t width_; + uint32_t height_; + DisplayId displayIdToMirror_; + int32_t flags_; +}; +} // namespace OHOS::Rosen + +#endif // FOUNDATION_VIRTUAL_DISPLAY_INFO_H \ No newline at end of file diff --git a/dmserver/src/display_screen.cpp b/dmserver/src/abstract_display.cpp similarity index 65% rename from dmserver/src/display_screen.cpp rename to dmserver/src/abstract_display.cpp index bbc1876a..32d748df 100644 --- a/dmserver/src/display_screen.cpp +++ b/dmserver/src/abstract_display.cpp @@ -13,10 +13,10 @@ * limitations under the License. */ -#include "display_screen.h" +#include "abstract_display.h" namespace OHOS::Rosen { -DisplayScreen::DisplayScreen(const DisplayInfo& info) +AbstractDisplay::AbstractDisplay(const DisplayInfo& info) : id_(info.id_), width_(info.width_), height_(info.height_), @@ -24,42 +24,42 @@ DisplayScreen::DisplayScreen(const DisplayInfo& info) { } -DisplayId DisplayScreen::GetId() const +DisplayId AbstractDisplay::GetId() const { return id_; } -int32_t DisplayScreen::GetWidth() const +int32_t AbstractDisplay::GetWidth() const { return width_; } -int32_t DisplayScreen::GetHeight() const +int32_t AbstractDisplay::GetHeight() const { return height_; } -uint32_t DisplayScreen::GetFreshRate() const +uint32_t AbstractDisplay::GetFreshRate() const { return freshRate_; } -void DisplayScreen::SetWidth(int32_t width) +void AbstractDisplay::SetWidth(int32_t width) { width_ = width; } -void DisplayScreen::SetHeight(int32_t height) +void AbstractDisplay::SetHeight(int32_t height) { height_ = height; } -void DisplayScreen::SetFreshRate(uint32_t freshRate) +void AbstractDisplay::SetFreshRate(uint32_t freshRate) { freshRate_ = freshRate; } -void DisplayScreen::SetId(DisplayId id) +void AbstractDisplay::SetId(DisplayId id) { id_ = id; } diff --git a/dmserver/src/abstract_display_manager.cpp b/dmserver/src/abstract_display_manager.cpp new file mode 100644 index 00000000..06cadffa --- /dev/null +++ b/dmserver/src/abstract_display_manager.cpp @@ -0,0 +1,136 @@ +/* + * Copyright (c) 2021 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 "abstract_display_manager.h" + +#include "window_manager_hilog.h" + +#include + +namespace OHOS::Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "AbstractDisplayManager"}; +} + +#define SCREENSHOT_GENERATOR + +AbstractDisplayManager::AbstractDisplayManager() : rsInterface_(&(RSInterfaces::GetInstance())) +{ + parepareRSScreenManger(); +} + +AbstractDisplayManager::~AbstractDisplayManager() +{ + rsInterface_ = nullptr; +} + +void AbstractDisplayManager::parepareRSScreenManger() +{ +} + +ScreenId AbstractDisplayManager::GetDefaultScreenId() +{ + if (rsInterface_ == nullptr) { + return INVALID_SCREEN_ID; + } + return rsInterface_->GetDefaultScreenId(); +} + +RSScreenModeInfo AbstractDisplayManager::GetScreenActiveMode(ScreenId id) +{ + RSScreenModeInfo screenModeInfo; + if (rsInterface_ == nullptr) { + return screenModeInfo; + } + return rsInterface_->GetScreenActiveMode(id); +} + +ScreenId AbstractDisplayManager::CreateVirtualScreen(const VirtualDisplayInfo &virtualDisplayInfo, + sptr surface) +{ + if (rsInterface_ == nullptr) { + return INVALID_SCREEN_ID; + } + ScreenId result = rsInterface_->CreateVirtualScreen(virtualDisplayInfo.name_, virtualDisplayInfo.width_, + virtualDisplayInfo.height_, surface, virtualDisplayInfo.displayIdToMirror_, virtualDisplayInfo.flags_); + WLOGFI("AbstractDisplayManager::CreateVirtualDisplay id: %{public}llu", result >> 32); + return result; +} + +bool AbstractDisplayManager::DestroyVirtualScreen(ScreenId screenId) +{ + if (rsInterface_ == nullptr) { + return false; + } + WLOGFI("AbstractDisplayManager::DestroyVirtualScreen"); + rsInterface_->RemoveVirtualScreen(screenId); + return true; +} + +// TODO: fix me +// #ifdef SCREENSHOT_GENERATOR +// sptr TempCreatePixelMap() +// { +// // pixel_map testing code +// Media::InitializationOptions opt; +// opt.size.width = 1920; +// opt.size.height = 1080; +// opt.pixelFormat = Media::PixelFormat::RGBA_8888; +// opt.alphaType = Media::AlphaType::IMAGE_ALPHA_TYPE_OPAQUE; +// opt.scaleMode = Media::ScaleMode::FIT_TARGET_SIZE; +// opt.editable = false; +// opt.useSourceIfMatch = false; + +// const int bitmapDepth = 8; // color depth +// const int bpp = 4; // bytes per pixel +// const int maxByteNum = 256; + +// auto data = (uint32_t *)malloc(opt.size.width * opt.size.height * bpp); +// uint8_t *pic = (uint8_t *)data; +// for (uint32_t i = 0; i < opt.size.width; i++) { +// for (uint32_t j = 0; j < opt.size.height; j++) { +// for (uint32_t k = 0; k < bpp; k++) { +// pic[0] = rand() % maxByteNum; +// pic++; +// } +// } +// } +// uint32_t colorLen = opt.size.width * opt.size.height * bpp * bitmapDepth; +// auto newPixelMap = Media::PixelMap::Create(data, colorLen, opt); +// sptr pixelMap_ = newPixelMap.release(); +// if (pixelMap_ == nullptr) { +// WLOGFE("Failed to get pixelMap"); +// return nullptr; +// } + +// return pixelMap_; +// } +// #endif + +// sptr AbstractDisplayManager::GetScreenSnapshot(ScreenId screenId) +// { +// if (rsInterface_ == nullptr) { +// return nullptr; +// } + +// #ifdef SCREENSHOT_GENERATOR +// sptr screenshot = TempCreatePixelMap(); +// #else +// sptr screenshot = rsInterface_->GetScreenSnapshot(screenId); +// #endif + +// return screenshot; +// } +} // namespace OHOS::Rosen \ No newline at end of file diff --git a/dmserver/src/display_manager_proxy.cpp b/dmserver/src/display_manager_proxy.cpp index a286f6fa..53c30994 100644 --- a/dmserver/src/display_manager_proxy.cpp +++ b/dmserver/src/display_manager_proxy.cpp @@ -15,40 +15,18 @@ #include "display_manager_proxy.h" -#include +#include #include #include "window_manager_hilog.h" +#include + namespace OHOS::Rosen { namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "DisplayManagerProxy"}; } -const sptr& DisplayManagerProxy::GetDisplayInfo(const DisplayType type) -{ - sptr remote = Remote(); - if (remote == nullptr) { - WLOGFW("get display: remote is nullptr"); - return nullptr; - } - - MessageParcel data; - MessageParcel reply; - MessageOption option; - if (!data.WriteInterfaceToken(GetDescriptor())) { - WLOGFE("get display: WriteInterfaceToken failed"); - return nullptr; - } - data.WriteInt32(static_cast(type)); - if (remote->SendRequest(TRANS_ID_GET_DISPLAY_INFO, data, reply, option) != ERR_NONE) { - WLOGFW("get display: SendRequest failed"); - return nullptr; - } - // TODO: decode reply - return nullptr; -} - DisplayId DisplayManagerProxy::GetDefaultDisplayId() { sptr remote = Remote(); @@ -102,4 +80,93 @@ DisplayInfo DisplayManagerProxy::GetDisplayInfoById(DisplayId displayId) } return *info; } + +DisplayId DisplayManagerProxy::CreateVirtualDisplay(const VirtualDisplayInfo &virtualDisplayInfo, + sptr surface) +{ + sptr remote = Remote(); + if (remote == nullptr) { + WLOGFW("create virtual display: remote is nullptr"); + return DISPLAY_ID_INVALD; + } + + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("create virtual display: WriteInterfaceToken failed"); + return DISPLAY_ID_INVALD; + } + bool res = data.WriteParcelable(&virtualDisplayInfo) && + data.WriteRemoteObject(surface->GetProducer()->AsObject()); + if (!res) { + return DISPLAY_ID_INVALD; + } + if (remote->SendRequest(TRANS_ID_CREATE_VIRTUAL_DISPLAY, data, reply, option) != ERR_NONE) { + WLOGFW("create virtual display: SendRequest failed"); + return DISPLAY_ID_INVALD; + } + + DisplayId displayId = reply.ReadUint64(); + WLOGFI("DisplayManagerProxy::CreateVirtualDisplay %" PRIu64"", displayId); + return displayId; +} + +bool DisplayManagerProxy::DestroyVirtualDisplay(DisplayId displayId) +{ + sptr remote = Remote(); + if (remote == nullptr) { + WLOGFW("destroy virtual display: remote is nullptr"); + return false; + } + + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("destroy virtual display: WriteInterfaceToken failed"); + return false; + } + data.WriteUint64(static_cast(displayId)); + if (remote->SendRequest(TRANS_ID_DESTROY_VIRTUAL_DISPLAY, data, reply, option) != ERR_NONE) { + WLOGFW("destroy virtual display: SendRequest failed"); + return false; + } + return reply.ReadBool(); +} + +// TODO: fix me +// sptr DisplayManagerProxy::GetDispalySnapshot(DisplayId displayId) +// { +// sptr remote = Remote(); +// if (remote == nullptr) { +// WLOGFW("GetDispalySnapshot: remote is nullptr"); +// return nullptr; +// } + +// MessageParcel data; +// MessageParcel reply; +// MessageOption option; +// if (!data.WriteInterfaceToken(GetDescriptor())) { +// WLOGFE("GetDispalySnapshot: WriteInterfaceToken failed"); +// return nullptr; +// } + +// if (!data.WriteUint64(displayId)) { +// WLOGFE("Write dispalyId failed"); +// return nullptr; +// } + +// if (remote->SendRequest(TRANS_ID_GET_DISPLAY_SNAPSHOT, data, reply, option) != ERR_NONE) { +// WLOGFW("GetDispalySnapshot: SendRequest failed"); +// return nullptr; +// } + +// sptr pixelMap = reply.ReadParcelable(); +// if (pixelMap == nullptr) { +// WLOGFW("DisplayManagerProxy::GetDispalySnapshot SendRequest nullptr."); +// return nullptr; +// } +// return pixelMap; +// } } // 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 93ca0d2d..ef9aff64 100644 --- a/dmserver/src/display_manager_service.cpp +++ b/dmserver/src/display_manager_service.cpp @@ -29,10 +29,7 @@ namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "DisplayManagerService"}; } -IMPLEMENT_SINGLE_INSTANCE(DisplayManagerService); - -const bool REGISTER_RESULT = - SystemAbility::MakeAndRegisterAbility(SingletonContainer::Get().GetRefPtr()); +const bool REGISTER_RESULT = SystemAbility::MakeAndRegisterAbility(&SingletonContainer::Get()); DisplayManagerService::DisplayManagerService() : SystemAbility(DISPLAY_MANAGER_SERVICE_SA_ID, true) { @@ -54,22 +51,10 @@ bool DisplayManagerService::Init() WLOGFW("DisplayManagerService::Init failed"); return false; } - displayScreenManager_ = DisplayScreenManager::GetInstance(); - if (displayScreenManager_ == nullptr) { - WLOGFW("Get DisplayScreenManager failed"); - return false; - } WLOGFI("DisplayManagerService::Init success"); return true; } -const sptr& DisplayManagerService::GetDisplayInfo(const DisplayType type) -{ - // TODO 从displayScreenMap_得到DisplayInfo - WLOGFI("DisplayManagerService::GetDisplayInfo"); - return new DisplayInfo(); -} - DisplayId DisplayManagerService::GetDisplayIdFromScreenId(ScreenId screenId) { return (DisplayId)screenId; @@ -82,10 +67,7 @@ ScreenId DisplayManagerService::GetScreenIdFromDisplayId(DisplayId displayId) DisplayId DisplayManagerService::GetDefaultDisplayId() { - if (displayScreenManager_ == nullptr) { - return DISPLAY_ID_INVALD; - } - ScreenId screenId = displayScreenManager_->GetDefaultScreenId(); + ScreenId screenId = AbstractDisplayManager::GetInstance().GetDefaultScreenId(); WLOGFI("GetDefaultDisplayId %{public}llu", screenId); return GetDisplayIdFromScreenId(screenId); } @@ -93,11 +75,8 @@ DisplayId DisplayManagerService::GetDefaultDisplayId() DisplayInfo DisplayManagerService::GetDisplayInfoById(DisplayId displayId) { DisplayInfo displayInfo; - if (displayScreenManager_ == nullptr) { - return displayInfo; - } ScreenId screenId = GetScreenIdFromDisplayId(displayId); - auto screenModeInfo = displayScreenManager_->GetScreenActiveMode(screenId); + auto screenModeInfo = AbstractDisplayManager::GetInstance().GetScreenActiveMode(screenId); displayInfo.id_ = displayId; displayInfo.width_ = screenModeInfo.GetScreenWidth(); displayInfo.height_ = screenModeInfo.GetScreenHeight(); @@ -105,9 +84,33 @@ DisplayInfo DisplayManagerService::GetDisplayInfoById(DisplayId displayId) return displayInfo; } +DisplayId DisplayManagerService::CreateVirtualDisplay(const VirtualDisplayInfo &virtualDisplayInfo, + sptr surface) +{ + WLOGFI("name %{public}s, width %{public}u, height %{public}u, mirrotId %{public}llu, flags %{public}d", + virtualDisplayInfo.name_.c_str(), virtualDisplayInfo.width_, virtualDisplayInfo.height_, + virtualDisplayInfo.displayIdToMirror_, virtualDisplayInfo.flags_); + ScreenId screenId = AbstractDisplayManager::GetInstance().CreateVirtualScreen(virtualDisplayInfo, surface); + return GetDisplayIdFromScreenId(screenId); +} + +bool DisplayManagerService::DestroyVirtualDisplay(DisplayId displayId) +{ + WLOGFI("DisplayManagerService::DestroyVirtualDisplay"); + ScreenId screenId = GetScreenIdFromDisplayId(displayId); + return AbstractDisplayManager::GetInstance().DestroyVirtualScreen(screenId); +} + +// TODO: fix me +// sptr DisplayManagerService::GetDispalySnapshot(DisplayId displayId) +// { +// ScreenId screenId = GetScreenIdFromDisplayId(displayId); +// sptr screenSnapshot = AbstractDisplayManager::GetInstance().GetScreenSnapshot(screenId); +// return screenSnapshot; +// } + void DisplayManagerService::OnStop() { WLOGFI("ready to stop display service."); - displayScreenManager_ = nullptr; } } // 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 9b53ac1c..6b65413d 100644 --- a/dmserver/src/display_manager_service_inner.cpp +++ b/dmserver/src/display_manager_service_inner.cpp @@ -16,14 +16,13 @@ #include "display_manager_service_inner.h" #include -#include #include #include #include #include -#include "display_screen_manager.h" +#include "abstract_display_manager.h" #include "display_manager_service.h" #include "window_manager_hilog.h" @@ -32,28 +31,15 @@ namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "DisplayManagerServiceInner"}; } -IMPLEMENT_SINGLE_INSTANCE(DisplayManagerServiceInner); - DisplayId DisplayManagerServiceInner::GetDefaultDisplayId() { - auto dms = DisplayManagerService::GetInstance(); - if (dms == nullptr) { - WLOGFE("GetDefaultDisplayId null!\n"); - return DISPLAY_ID_INVALD; - } - return dms->GetDefaultDisplayId(); + return DisplayManagerService::GetInstance().GetDefaultDisplayId(); } -const sptr DisplayManagerServiceInner::GetDisplayById(DisplayId displayId) +const sptr DisplayManagerServiceInner::GetDisplayById(DisplayId displayId) { - auto dms = DisplayManagerService::GetInstance(); - if (dms == nullptr) { - WLOGFE("GetDisplayById null!\n"); - return nullptr; - } - DisplayInfo displayInfo = dms->GetDisplayInfoById(displayId); - - sptr display = new DisplayScreen(displayInfo); + DisplayInfo displayInfo = DisplayManagerService::GetInstance().GetDisplayInfoById(displayId); + sptr display = new AbstractDisplay(displayInfo); if (display == nullptr) { WLOGFE("GetDisplayById failed!\n"); return nullptr; @@ -61,7 +47,7 @@ const sptr DisplayManagerServiceInner::GetDisplayById(DisplayId d return display; } -const sptr DisplayManagerServiceInner::GetDefaultDisplay() +const sptr DisplayManagerServiceInner::GetDefaultDisplay() { return GetDisplayById(GetDefaultDisplayId()); } @@ -73,12 +59,12 @@ std::vector DisplayManagerServiceInner::GetAllDisplayIds() return res; } -std::vector> DisplayManagerServiceInner::GetAllDisplays() +std::vector> DisplayManagerServiceInner::GetAllDisplays() { - std::vector> res; + std::vector> res; auto displayIds = GetAllDisplayIds(); for (auto displayId: displayIds) { - const sptr display = GetDisplayById(displayId); + const sptr display = GetDisplayById(displayId); if (display != nullptr) { res.push_back(display); } else { diff --git a/dmserver/src/display_manager_stub.cpp b/dmserver/src/display_manager_stub.cpp index 0e065619..260a1416 100644 --- a/dmserver/src/display_manager_stub.cpp +++ b/dmserver/src/display_manager_stub.cpp @@ -19,6 +19,8 @@ #include "window_manager_hilog.h" +#include "transaction/rs_interfaces.h" + namespace OHOS::Rosen { namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "DisplayManagerStub"}; @@ -33,12 +35,6 @@ int32_t DisplayManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, return -1; } switch (code) { - case TRANS_ID_GET_DISPLAY_INFO: { - DisplayType type = static_cast(data.ReadInt32()); - sptr info = GetDisplayInfo(type); - reply.WriteParcelable(info.GetRefPtr()); - break; - } case TRANS_ID_GET_DEFAULT_DISPLAY_ID: { DisplayId displayId = GetDefaultDisplayId(); reply.WriteUint64(displayId); @@ -50,6 +46,30 @@ int32_t DisplayManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, reply.WriteParcelable(&info); break; } + case TRANS_ID_CREATE_VIRTUAL_DISPLAY: { + VirtualDisplayInfo* virtualDisplayInfo = data.ReadParcelable(); + sptr surfaceObject = data.ReadRemoteObject(); + sptr bp = iface_cast(surfaceObject); + sptr surface = Surface::CreateSurfaceAsProducer(bp); + DisplayId virtualId = CreateVirtualDisplay(*virtualDisplayInfo, surface); + reply.WriteUint64(virtualId); + virtualDisplayInfo = nullptr; + break; + } + case TRANS_ID_DESTROY_VIRTUAL_DISPLAY: { + DisplayId virtualId = static_cast(data.ReadUint64()); + bool result = DestroyVirtualDisplay(virtualId); + reply.WriteBool(result); + break; + } + // TODO: fix me + // case TRANS_ID_GET_DISPLAY_SNAPSHOT: { + // DisplayId displayId = data.ReadUint64(); + + // sptr dispalySnapshot = GetDispalySnapshot(displayId); + // reply.WriteParcelable(dispalySnapshot.GetRefPtr()); + // break; + // } default: WLOGFW("unknown transaction code"); return IPCObjectStub::OnRemoteRequest(code, data, reply, option); diff --git a/dmserver/src/display_screen_manager.cpp b/dmserver/src/display_screen_manager.cpp deleted file mode 100644 index 91620c74..00000000 --- a/dmserver/src/display_screen_manager.cpp +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2021 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 "display_screen_manager.h" - -namespace OHOS::Rosen { -IMPLEMENT_SINGLE_INSTANCE(DisplayScreenManager); - -DisplayScreenManager::DisplayScreenManager() : rsInterface_(&(RSInterfaces::GetInstance())) -{ - parepareRSScreenManger(); -} - -DisplayScreenManager::~DisplayScreenManager() -{ - rsInterface_ = nullptr; -} - -void DisplayScreenManager::parepareRSScreenManger() -{ -} - -ScreenId DisplayScreenManager::GetDefaultScreenId() -{ - if (rsInterface_ == nullptr) { - return INVALID_SCREEN_ID; - } - return rsInterface_->GetDefaultScreenId(); -} - -RSScreenModeInfo DisplayScreenManager::GetScreenActiveMode(ScreenId id) -{ - RSScreenModeInfo screenModeInfo; - if (rsInterface_ == nullptr) { - return screenModeInfo; - } - return rsInterface_->GetScreenActiveMode(id); -} -} // namespace OHOS::Rosen \ No newline at end of file diff --git a/dmserver/src/rs_adapter.cpp b/dmserver/src/rs_adapter.cpp index 5e5d6658..3b5e59a2 100644 --- a/dmserver/src/rs_adapter.cpp +++ b/dmserver/src/rs_adapter.cpp @@ -26,8 +26,6 @@ namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "RsAdapter"}; } -IMPLEMENT_SINGLE_INSTANCE(RsAdapter); - bool RsAdapter::InitRSProxyLocked() { WLOGFI("InitRProxy"); diff --git a/dmserver/src/virtual_display_info.cpp b/dmserver/src/virtual_display_info.cpp new file mode 100644 index 00000000..9542f715 --- /dev/null +++ b/dmserver/src/virtual_display_info.cpp @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2021 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 "virtual_display_info.h" + +namespace OHOS::Rosen { +VirtualDisplayInfo::VirtualDisplayInfo() +{ + name_ = ""; + width_ = 0; + height_ = 0; + displayIdToMirror_ = 0; + flags_ = 0; +} + +VirtualDisplayInfo::VirtualDisplayInfo(const std::string &name, uint32_t width, uint32_t height, + DisplayId displayIdToMirror, int32_t flags) +{ + name_ = name; + width_ = width; + height_ = height; + displayIdToMirror_ = displayIdToMirror; + flags_ = flags; +} + +bool VirtualDisplayInfo::Marshalling(Parcel &parcel) const +{ + return parcel.WriteString(name_) && parcel.WriteUint32(width_) && + parcel.WriteUint32(height_) && parcel.WriteUint64(displayIdToMirror_) && + parcel.WriteInt32(flags_); +} + +VirtualDisplayInfo* VirtualDisplayInfo::Unmarshalling(Parcel &parcel) +{ + VirtualDisplayInfo *virtualDisplayInfo = new VirtualDisplayInfo(); + if (virtualDisplayInfo == nullptr) { + return nullptr; + } + bool res = parcel.ReadString(virtualDisplayInfo->name_) && + parcel.ReadUint32(virtualDisplayInfo->width_) && + parcel.ReadUint32(virtualDisplayInfo->height_) && + parcel.ReadUint64(virtualDisplayInfo->displayIdToMirror_) && + parcel.ReadInt32(virtualDisplayInfo->flags_); + if (!res) { + return nullptr; + } + return virtualDisplayInfo; +} +} // namespace OHOS::Rosen \ No newline at end of file diff --git a/interfaces/innerkits/BUILD.gn b/interfaces/innerkits/BUILD.gn index 19b84753..6c913281 100644 --- a/interfaces/innerkits/BUILD.gn +++ b/interfaces/innerkits/BUILD.gn @@ -26,6 +26,7 @@ ohos_shared_library("wm_interface") { public_deps = [ "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", "//foundation/graphic/standard/rosen/modules/render_service_client:librender_service_client", + "//foundation/multimedia/image_standard/interfaces/innerkits:image_native", "//foundation/multimodalinput/input/frameworks/proxy:libmmi-client", "//utils/native/base:utils", ] diff --git a/interfaces/innerkits/dm/display_manager.h b/interfaces/innerkits/dm/display_manager.h index ed91aba1..7db69d16 100644 --- a/interfaces/innerkits/dm/display_manager.h +++ b/interfaces/innerkits/dm/display_manager.h @@ -16,19 +16,22 @@ #ifndef FOUNDATION_DM_DISPLAY_MANAGER_H #define FOUNDATION_DM_DISPLAY_MANAGER_H -#include #include +#include #include "display.h" #include "single_instance.h" +#include "virtual_display_info.h" +// #include "pixel_map.h" +// #include "wm_common.h" + namespace OHOS::Rosen { class DisplayManagerAdapter; -class DisplayManager : public RefBase { -DECLARE_SINGLE_INSTANCE_BASE(DisplayManager); +class DisplayManager { +DECLARE_SINGLE_INSTANCE(DisplayManager); public: - const sptr& GetDisplay(const DisplayType type); std::vector> GetAllDisplays(); DisplayId GetDefaultDisplayId(); @@ -38,10 +41,14 @@ public: std::vector GetAllDisplayIds(); -private: - DisplayManager(); - ~DisplayManager(); - sptr dmsAdapter_; + DisplayId CreateVirtualDisplay(const std::string &name, uint32_t width, uint32_t height, + sptr surface, DisplayId displayIdToMirror, int32_t flags); + + bool DestroyVirtualDisplay(DisplayId displayId); + // TODO: fix me + // sptr GetScreenshot(DisplayId displayId); + // sptr GetScreenshot(DisplayId displayId, const Media::Rect &rect, + // const Media::Size &size, int rotation); }; } // namespace OHOS::Rosen diff --git a/interfaces/innerkits/wm/window.h b/interfaces/innerkits/wm/window.h index 7b7d89ea..e20e0f7b 100644 --- a/interfaces/innerkits/wm/window.h +++ b/interfaces/innerkits/wm/window.h @@ -30,6 +30,9 @@ class NativeValue; class NativeEngine; +namespace OHOS::AppExecFwk { + class Configuration; +} namespace OHOS::AbilityRuntime { class AbilityContext; @@ -42,10 +45,15 @@ public: virtual void OnSizeChange(Rect rect) = 0; }; +class IWindowSystemBarChangeListener : public RefBase { +public: + virtual void OnSystemBarPropertyChange(uint32_t displayId, WindowType type, const SystemBarProperty& prop) = 0; +}; + class Window : public RefBase { public: static sptr Create(const std::string& windowName, - sptr& option, const sptr& abilityToken = nullptr); + sptr& option, const std::shared_ptr& abilityContext = nullptr); static sptr Find(const std::string& windowName); virtual std::shared_ptr GetSurfaceNode() const = 0; @@ -55,9 +63,15 @@ public: virtual WindowMode GetMode() const = 0; virtual const std::string& GetWindowName() const = 0; virtual uint32_t GetWindowId() = 0; + virtual uint32_t GetWindowFlags() = 0; + virtual SystemBarProperty GetSystemBarPropertyByType(WindowType type) = 0; virtual WMError SetWindowType(WindowType type) = 0; virtual WMError SetWindowMode(WindowMode mode) = 0; + virtual WMError AddWindowFlag(WindowFlag flag) = 0; + virtual WMError RemoveWindowFlag(WindowFlag flag) = 0; + virtual WMError SetWindowFlags(uint32_t flags) = 0; + virtual WMError SetSystemBarProperty(WindowType type, const SystemBarProperty& property) = 0; virtual WMError Destroy() = 0; virtual WMError Show() = 0; @@ -70,11 +84,15 @@ public: virtual void AddInputEventListener(std::shared_ptr& inputEventListener) = 0; // for api 7 virtual void ConsumeKeyEvent(std::shared_ptr& inputEvent) = 0; virtual void ConsumePointerEvent(std::shared_ptr& inputEvent) = 0; + virtual void RequestFrame() = 0; + virtual void UpdateConfiguration(const std::shared_ptr& configuration) = 0; virtual void RegisterLifeCycleListener(sptr& listener) = 0; virtual void RegisterWindowChangeListener(sptr& listener) = 0; + virtual void RegisterWindowSystemBarChangeListener(sptr& listener) = 0; virtual WMError SetUIContent(std::shared_ptr context, - std::string& url, NativeEngine* engine, NativeValue* storage) = 0; + std::string& contentInfo, NativeEngine* engine, NativeValue* storage, bool isdistributed = false) = 0; + virtual const std::string& GetContentInfo() = 0; }; } } diff --git a/interfaces/innerkits/wm/window_life_cycle_interface.h b/interfaces/innerkits/wm/window_life_cycle_interface.h index c9fa54b2..c03d77e6 100644 --- a/interfaces/innerkits/wm/window_life_cycle_interface.h +++ b/interfaces/innerkits/wm/window_life_cycle_interface.h @@ -25,7 +25,9 @@ public: virtual void AfterForeground() = 0; virtual void AfterBackground() = 0; virtual void AfterFocused() = 0; - virtual void AfterUnFocused() = 0; + // TODO: need rename AfterUnFocused to AfterUnfocused + virtual void AfterUnFocused() {} + virtual void AfterUnfocused() {} }; } } diff --git a/interfaces/innerkits/wm/window_manager.h b/interfaces/innerkits/wm/window_manager.h new file mode 100644 index 00000000..618c0c8c --- /dev/null +++ b/interfaces/innerkits/wm/window_manager.h @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_ROSEN_WINDOW_MANAGER_H +#define OHOS_ROSEN_WINDOW_MANAGER_H + +#include +#include +#include +#include +#include "single_instance.h" +#include "singleton_delegator.h" +#include "wm_common.h" + +namespace OHOS { +namespace Rosen { +class IFocusChangedListener : public RefBase { +public: + virtual void OnFocused(uint32_t windowId, sptr abilityToken, + WindowType windowType, int32_t displayId) = 0; + + virtual void OnUnfocused(uint32_t windowId, sptr abilityToken, + WindowType windowType, int32_t displayId) = 0; +}; + +class WindowManager : public RefBase { +DECLARE_SINGLE_INSTANCE_BASE(WindowManager); +friend class WindowManagerAgent; +public: + void RegisterFocusChangedListener(const sptr& listener); + void UnregisterFocusChangedListener(const sptr& listener); + +private: + WindowManager(); + ~WindowManager(); + class Impl; + std::unique_ptr pImpl_; + + void UpdateFocusStatus(uint32_t windowId, const sptr& abilityToken, WindowType windowType, + int32_t displayId, bool focused) const; +}; +} // namespace Rosen +} // namespace OHOS + +#endif // OHOS_ROSEN_WINDOW_MANAGER_H \ No newline at end of file diff --git a/interfaces/innerkits/wm/window_option.h b/interfaces/innerkits/wm/window_option.h index 9f695dae..e2794660 100644 --- a/interfaces/innerkits/wm/window_option.h +++ b/interfaces/innerkits/wm/window_option.h @@ -15,8 +15,9 @@ #ifndef OHOS_ROSEN_WINDOW_OPTION_H #define OHOS_ROSEN_WINDOW_OPTION_H -#include #include +#include +#include #include "wm_common.h" namespace OHOS { @@ -37,6 +38,7 @@ public: void AddWindowFlag(WindowFlag flag); void RemoveWindowFlag(WindowFlag flag); void SetWindowFlags(uint32_t flags); + void SetSystemBarProperty(WindowType type, const SystemBarProperty& property); Rect GetWindowRect() const; WindowType GetWindowType() const; @@ -47,6 +49,7 @@ public: const std::string& GetParentName() const; const std::string& GetWindowName() const; uint32_t GetWindowFlags() const; + const std::unordered_map& GetSystemBarProperty() const; private: Rect windowRect_ { 0, 0, 0, 0 }; WindowType type_ { WindowType::WINDOW_TYPE_APP_MAIN_WINDOW }; @@ -57,6 +60,10 @@ private: std::string parentName_ { "" }; std::string windowName_ { "" }; uint32_t flags_ { 0 }; + std::unordered_map sysBarPropMap_ { + { WindowType::WINDOW_TYPE_STATUS_BAR, SystemBarProperty() }, + { WindowType::WINDOW_TYPE_NAVIGATION_BAR, SystemBarProperty() }, + }; }; } } diff --git a/interfaces/innerkits/wm/window_scene.h b/interfaces/innerkits/wm/window_scene.h index dc984b01..fb647ebe 100644 --- a/interfaces/innerkits/wm/window_scene.h +++ b/interfaces/innerkits/wm/window_scene.h @@ -19,6 +19,7 @@ #include #include #include +#include #include "window.h" #include "window_option.h" @@ -34,7 +35,7 @@ public: ~WindowScene(); WMError Init(int32_t displayId, std::shared_ptr& abilityContext, - sptr& listener); + sptr& listener, sptr option = nullptr); sptr CreateWindow(const std::string& windowName, sptr& option) const; @@ -44,6 +45,10 @@ public: WMError GoBackground() const; WMError RequestFocus() const; + void UpdateConfiguration(const std::shared_ptr& configuration); + WMError SetSystemBarProperty(WindowType type, const SystemBarProperty& property) const; + + const std::string& GetContentInfo() const; private: static inline std::atomic count { 0 }; diff --git a/interfaces/innerkits/wm/wm_common.h b/interfaces/innerkits/wm/wm_common.h index cd472f88..388086cd 100644 --- a/interfaces/innerkits/wm/wm_common.h +++ b/interfaces/innerkits/wm/wm_common.h @@ -22,18 +22,23 @@ namespace OHOS { namespace Rosen { enum class WindowType : uint32_t { APP_WINDOW_BASE = 1, - WINDOW_TYPE_APP_MAIN_WINDOW = APP_WINDOW_BASE, - APP_WINDOW_END = 999, + APP_MAIN_WINDOW_BASE = APP_WINDOW_BASE, + WINDOW_TYPE_APP_MAIN_WINDOW = APP_MAIN_WINDOW_BASE, + APP_MAIN_WINDOW_END = WINDOW_TYPE_APP_MAIN_WINDOW, // equals last window type APP_SUB_WINDOW_BASE = 1000, WINDOW_TYPE_MEDIA = APP_SUB_WINDOW_BASE, WINDOW_TYPE_APP_SUB_WINDOW, - APP_SUB_WINDOW_END = 1999, + APP_SUB_WINDOW_END = WINDOW_TYPE_APP_SUB_WINDOW, // equals last window type + APP_WINDOW_END = APP_SUB_WINDOW_END, SYSTEM_WINDOW_BASE = 2000, + BELOW_APP_SYSTEM_WINDOW_BASE = SYSTEM_WINDOW_BASE, WINDOW_TYPE_WALLPAPER = SYSTEM_WINDOW_BASE, + BELOW_APP_SYSTEM_WINDOW_END = WINDOW_TYPE_WALLPAPER, // equals last window type + ABOVE_APP_SYSTEM_WINDOW_BASE = 2100, - WINDOW_TYPE_APP_LAUNCHING, + WINDOW_TYPE_APP_LAUNCHING = ABOVE_APP_SYSTEM_WINDOW_BASE, WINDOW_TYPE_DOCK_SLICE, WINDOW_TYPE_INCOMING_CALL, WINDOW_TYPE_SEARCHING_BAR, @@ -48,12 +53,14 @@ enum class WindowType : uint32_t { WINDOW_TYPE_NAVIGATION_BAR, WINDOW_TYPE_DRAGGING_EFFECT, WINDOW_TYPE_POINTER, - SYSTEM_WINDOW_END = 2999, + ABOVE_APP_SYSTEM_WINDOW_END = WINDOW_TYPE_POINTER, // equals last window type + SYSTEM_WINDOW_END = ABOVE_APP_SYSTEM_WINDOW_END, }; enum class WindowMode : uint32_t { WINDOW_MODE_FULLSCREEN, - WINDOW_MODE_SPLIT, + WINDOW_MODE_SPLIT_PRIMARY, + WINDOW_MODE_SPLIT_SECONDARY, WINDOW_MODE_FLOATING, WINDOW_MODE_PIP }; @@ -68,6 +75,7 @@ enum class WMError : int32_t { WM_ERROR_DESTROYED_OBJECT = 140, WM_ERROR_DEATH_RECIPIENT = 150, WM_ERROR_INVALID_WINDOW = 160, + WM_ERROR_INVALID_OPERATION = 170, WM_ERROR_UNKNOWN, /* weston adater */ @@ -85,6 +93,24 @@ enum class WindowFlag : uint32_t { WINDOW_FLAG_END = 1 << 2, }; +namespace { + constexpr uint32_t SYSTEM_COLOR_WHITE = 0xE5FFFFFF; + constexpr uint32_t SYSTEM_COLOR_BLACK = 0x66000000; +} + +struct SystemBarProperty { + bool enable_; + uint32_t backgroundColor_; + uint32_t contentColor_; + SystemBarProperty() : enable_(true), backgroundColor_(SYSTEM_COLOR_WHITE), contentColor_(SYSTEM_COLOR_BLACK) {} + SystemBarProperty(bool enable, uint32_t background, uint32_t content) + : enable_(enable), backgroundColor_(background), contentColor_(content) {} + bool operator == (const SystemBarProperty& a) const + { + return (enable_ == a.enable_ && backgroundColor_ == a.backgroundColor_ && contentColor_ == a.contentColor_); + } +}; + struct Rect { int32_t posX_; int32_t posY_; diff --git a/interfaces/kits/napi/BUILD.gn b/interfaces/kits/napi/BUILD.gn index 00c0281a..325093f0 100644 --- a/interfaces/kits/napi/BUILD.gn +++ b/interfaces/kits/napi/BUILD.gn @@ -54,5 +54,6 @@ group("napi_packages") { deps = [ "display:display", "window:window", + "window_runtime:windowmanager_napi", ] } diff --git a/interfaces/kits/napi/display/native_display_module.cpp b/interfaces/kits/napi/display/native_display_module.cpp index 127326b9..e319bb94 100644 --- a/interfaces/kits/napi/display/native_display_module.cpp +++ b/interfaces/kits/napi/display/native_display_module.cpp @@ -13,11 +13,8 @@ * limitations under the License. */ -#include "native_display_module.h" - -#include - #include "display_manager.h" +#include "native_display_module.h" #include "wm_common.h" #include "wm_napi_common.h" @@ -31,19 +28,13 @@ struct Param { void Async(napi_env env, std::unique_ptr ¶m) { - sptr dm = DisplayManager::GetInstance(); - if (dm == nullptr) { - GNAPI_LOG("dm error!\n"); - return; - } - - param->display = dm->GetDefaultDisplay(); + param->display = DisplayManager::GetInstance().GetDefaultDisplay(); if (param->display == nullptr) { GNAPI_LOG("Get display failed!"); param->wret = WMError::WM_ERROR_NULLPTR; return; } - GNAPI_LOG("GetDefaultDisplay: id %" PRIu64", w %d, h %d", + GNAPI_LOG("GetDefaultDisplay: id %{public}llu, w %{public}d, h %{public}d", param->display->GetId(), param->display->GetWidth(), param->display->GetHeight()); param->wret = WMError::WM_OK; } diff --git a/interfaces/kits/napi/window/native_window_module.cpp b/interfaces/kits/napi/window/native_window_module.cpp index 46d9254c..288fe190 100644 --- a/interfaces/kits/napi/window/native_window_module.cpp +++ b/interfaces/kits/napi/window/native_window_module.cpp @@ -57,7 +57,11 @@ struct Param { void Async(napi_env env, std::unique_ptr& param) { - param->ability->GetScene()->GetMainWindow()->Resize(param->width, param->height); + if (param == nullptr || param->ability == nullptr || param->ability->GetWindow() == nullptr) { + GNAPI_LOG("Error, use nullptr!)"); + return; + } + param->ability->GetWindow()->Resize(param->width, param->height); } napi_value MainFunc(napi_env env, napi_callback_info info) @@ -90,7 +94,11 @@ struct Param { void Async(napi_env env, std::unique_ptr& param) { - param->ability->GetScene()->GetMainWindow()->MoveTo(param->x, param->y); + if (param == nullptr || param->ability == nullptr || param->ability->GetWindow() == nullptr) { + GNAPI_LOG("Error, use nullptr!)"); + return; + } + param->ability->GetWindow()->MoveTo(param->x, param->y); } napi_value MainFunc(napi_env env, napi_callback_info info) @@ -122,7 +130,11 @@ struct Param { void Async(napi_env env, std::unique_ptr& param) { - param->ability->GetScene()->GetMainWindow()->SetWindowType(static_cast(param->windowType)); + if (param == nullptr || param->ability == nullptr || param->ability->GetWindow() == nullptr) { + GNAPI_LOG("Error, use nullptr!)"); + return; + } + param->ability->GetWindow()->SetWindowType(static_cast(param->windowType)); } void CreateWindowTypeObject(napi_env env, napi_value value) @@ -163,12 +175,12 @@ struct Param { void Async(napi_env env, std::unique_ptr ¶m) { - param->window = param->ability->GetScene()->GetMainWindow(); - if (param->window == nullptr) { - GNAPI_LOG("Get main-window failed!"); + if (param == nullptr || param->ability == nullptr) { + GNAPI_LOG("Get top window failed!"); param->wret = WMError::WM_ERROR_NULLPTR; return; } + param->window = param->ability->GetWindow(); param->wret = WMError::WM_OK; } @@ -184,6 +196,7 @@ napi_value MainFunc(napi_env env, napi_callback_info info) GNAPI_LOG("Window Interface: getTopWindow()"); GNAPI_LOG("%{public}s called", __PRETTY_FUNCTION__); auto param = std::make_unique(); + NAPI_CALL(env, GetAbility(env, info, param->ability)); return CreatePromise(env, __PRETTY_FUNCTION__, Async, Resolve, param); } } // namespace getTopWindow diff --git a/interfaces/kits/napi/window_runtime/BUILD.gn b/interfaces/kits/napi/window_runtime/BUILD.gn new file mode 100644 index 00000000..4c58fe36 --- /dev/null +++ b/interfaces/kits/napi/window_runtime/BUILD.gn @@ -0,0 +1,55 @@ +# Copyright (c) 2021 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. + +import("//ark/ts2abc/ts2panda/ts2abc_config.gni") +import("//build/ohos.gni") + +config("window_manager_napi_config") { + visibility = [ ":*" ] + + include_dirs = [ + "//foundation/windowmanager/interfaces/kits/napi/window_runtime", + "//foundation/windowmanager/interfaces/innerkits/wm", + "//foundation/windowmanager/interfaces/innerkits/dm", + "//foundation/windowmanager/wm/include", + "//foundation/windowmanager/utils/include", + ] +} + +ohos_shared_library("windowmanager_napi") { + sources = [ + "js_window.cpp", + "js_window_listener.cpp", + "js_window_manager.cpp", + "js_window_utils.cpp", + "window_manager_module.cpp", + ] + + configs = [ ":window_manager_napi_config" ] + deps = [ + "//foundation/windowmanager/wm:libwm", + "//foundation/windowmanager/wm:libwmutil", + "//foundation/windowmanager/wmserver:libwms", + ] + + external_deps = [ + "aafwk_standard:runtime", + "hiviewdfx_hilog_native:libhilog", + "napi:ace_napi", + ] + + relative_install_dir = "module/application" + + part_name = "window_manager" + subsystem_name = "window" +} diff --git a/interfaces/kits/napi/window_runtime/api/@ohos.window.d.ts b/interfaces/kits/napi/window_runtime/api/@ohos.window.d.ts new file mode 100644 index 00000000..b486f757 --- /dev/null +++ b/interfaces/kits/napi/window_runtime/api/@ohos.window.d.ts @@ -0,0 +1,249 @@ +/* +* Copyright (c) 2021 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. +*/ + +/** + * Window manager. + * @devices tv, phone, tablet, wearable. +*/ +declare namespace windowmanager { + enum WindowType { + APP_WINDOW_BASE = 1, + APP_MAIN_WINDOW_BASE = APP_WINDOW_BASE, + WINDOW_TYPE_APP_MAIN_WINDOW = APP_MAIN_WINDOW_BASE, + APP_MAIN_WINDOW_END = WINDOW_TYPE_APP_MAIN_WINDOW, // equals last window type + + APP_SUB_WINDOW_BASE = 1000, + WINDOW_TYPE_MEDIA = APP_SUB_WINDOW_BASE, + WINDOW_TYPE_APP_SUB_WINDOW, + APP_SUB_WINDOW_END = WINDOW_TYPE_APP_SUB_WINDOW, // equals last window type + APP_WINDOW_END = APP_SUB_WINDOW_END, + + SYSTEM_WINDOW_BASE = 2000, + BELOW_APP_SYSTEM_WINDOW_BASE = SYSTEM_WINDOW_BASE, + WINDOW_TYPE_WALLPAPER = SYSTEM_WINDOW_BASE, + BELOW_APP_SYSTEM_WINDOW_END = WINDOW_TYPE_WALLPAPER, // equals last window type + + ABOVE_APP_SYSTEM_WINDOW_BASE = 2100, + WINDOW_TYPE_APP_LAUNCHING = ABOVE_APP_SYSTEM_WINDOW_BASE, + WINDOW_TYPE_DOCK_SLICE, + WINDOW_TYPE_INCOMING_CALL, + WINDOW_TYPE_SEARCHING_BAR, + WINDOW_TYPE_SYSTEM_ALARM_WINDOW, + WINDOW_TYPE_INPUT_METHOD_FLOAT, + WINDOW_TYPE_FLOAT, + WINDOW_TYPE_TOAST, + WINDOW_TYPE_STATUS_BAR, + WINDOW_TYPE_PANEL, + WINDOW_TYPE_KEYGUARD, + WINDOW_TYPE_VOLUME_OVERLAY, + WINDOW_TYPE_NAVIGATION_BAR, + WINDOW_TYPE_DRAGGING_EFFECT, + WINDOW_TYPE_POINTER, + ABOVE_APP_SYSTEM_WINDOW_END = WINDOW_TYPE_POINTER, // equals last window type + SYSTEM_WINDOW_END = ABOVE_APP_SYSTEM_WINDOW_END, + } + + enum WindowMode { + /** + * FullSCREEN. + */ + WINDOW_MODE_FULLSCREEN, + + /** + * SPLIT. + */ + WINDOW_MODE_SPLIT, + + /** + * FREEFORM. + */ + WINDOW_MODE_FLOATING, + + /** + * PIP. + */ + WINDOW_MODE_PIP + } + interface WindowManager { + /** + * Create a sub window with a specific id and type. + * @param id Indicates window id. + * @param type Indicates window type. + * @permission ohos.permission.SYSTEM_FLOAT_WINDOW + * @since 7 + */ + create(id: string, type: WindowType, callback: AsyncCallback): void; + /** + * Create a sub window with a specific id and type. + * @param id Indicates window id. + * @param type Indicates window type. + * @permission ohos.permission.SYSTEM_FLOAT_WINDOW + * @since 7 + */ + create(id: string, type: WindowType): Promise; + /** + * Find the sub window by id. + * @param id Indicates window id. + * @since 7 + */ + find(id: string, callback: AsyncCallback): void; + /** + * Find the sub window by id. + * @param id Indicates window id. + * @since 7 + */ + find(id: string): Promise; + + } + /** + * Rectangle + * @devices tv, phone, tablet, wearable, car + * @since 7 + */ + interface Rect { + left: number; + top: number; + width: number; + height: number; + } + + /** + * window size + * @devices tv, phone, tablet, wearable, car + * @since 7 + */ + interface Size { + /** + * the width of the window. + */ + width: number; + + /** + * the height of the window. + */ + height: number; + } + + /** + * Properties of window, it couldn't update automatically + * @devices tv, phone, tablet, wearable, car + * @since 6 + */ + interface WindowProperties { + /** + * the position and size of the window + * @since 7 + */ + windowRect: Rect; + + /** + * window type + * @since 7 + */ + type: WindowType; + } + + interface Window { + /** + * hide sub window. + * @systemapi Hide this for inner system use. + * @since 7 + */ + hide (callback: AsyncCallback): void; + /** + * hide sub window. + * @systemapi Hide this for inner system use. + * @since 7 + */ + hide(): Promise; + + /** + * show sub window. + * @since 7 + */ + show(callback: AsyncCallback): void; + /** + * show sub window. + * @since 7 + */ + show(): Promise; + /** + * Destroy the sub window. + * @since 7 + */ + destroy(callback: AsyncCallback): void; + /** + * Destroy the sub window. + * @since 7 + */ + destroy(): Promise; + /** + * Set the position of a window. + * @param x Indicate the X-coordinate of the window. + * @param y Indicate the Y-coordinate of the window. + * @devices tv, phone, tablet, wearable, liteWearable. + */ + moveTo(x:number, y:number): Promise; + /** + * Set the size of a window . + * @param width Indicates the width of the window. + * @param height Indicates the height of the window. + * @devices tv, phone, tablet, wearable, liteWearable. + */ + resize(width:number, height:number): Promise; + /** + * Set the type of a window. + * @param windowType Indicate the type of a window. + * @devices tv, phone, tablet, wearable, liteWearable. + */ + setWindowType(windowType: WindowType): Promise; + /** + * Set the type of a window. + * @param windowMode Indicate the mode of a window. + * @devices tv, phone, tablet, wearable, liteWearable. + */ + setWindowMode(windowMode: WindowMode): Promise; + /** + * get the properties of current window + * @devices tv, phone, tablet, wearable, car + * @since 6 + */ + getProperties(callback: AsyncCallback): void; + /** + * get the properties of current window + * @devices tv, phone, tablet, wearable, car + * @since 6 + */ + getProperties(): Promise; + + /** + * register the callback of windowSizeChange + * @param type: 'windowSizeChange' + * @devices tv, phone, tablet, wearable, car + * @since 7 + */ + on(type: 'windowSizeChange', callback: Callback): void; + + /** + * unregister the callback of windowSizeChange + * @param type: 'windowSizeChange' + * @devices tv, phone, tablet, wearable, car + * @since 7 + */ + off(type: 'windowSizeChange', callback?: Callback): void; + } +} + +export default windowmanager; diff --git a/interfaces/kits/napi/window_runtime/js_window.cpp b/interfaces/kits/napi/window_runtime/js_window.cpp new file mode 100644 index 00000000..1d9f66cc --- /dev/null +++ b/interfaces/kits/napi/window_runtime/js_window.cpp @@ -0,0 +1,420 @@ +/* + * Copyright (c) 2021 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 "js_window.h" +#include "window.h" +#include "window_manager_hilog.h" +#include "window_option.h" +namespace OHOS { +namespace Rosen { +using namespace AbilityRuntime; +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "JsWindow"}; +} +JsWindow::JsWindow(const sptr& window, NativeEngine& engine) : windowToken_(window) +{ + windowListener_ = new JsWindowListener(&engine); +} + +void JsWindow::Finalizer(NativeEngine* engine, void* data, void* hint) +{ + WLOGFI("JsWindow::Finalizer is called"); + std::unique_ptr(static_cast(data)); +} + +NativeValue* JsWindow::Show(NativeEngine* engine, NativeCallbackInfo* info) +{ + WLOGFI("JsWindow::Show is called"); + JsWindow* me = CheckParamsAndGetThis(engine, info); + return (me != nullptr) ? me->OnShow(*engine, *info) : nullptr; +} + +NativeValue* JsWindow::Destroy(NativeEngine* engine, NativeCallbackInfo* info) +{ + WLOGFI("JsWindow::Destroy is called"); + JsWindow* me = CheckParamsAndGetThis(engine, info); + return (me != nullptr) ? me->OnDestroy(*engine, *info) : nullptr; +} + +NativeValue* JsWindow::Hide(NativeEngine* engine, NativeCallbackInfo* info) +{ + WLOGFI("JsWindow::Hide is called"); + JsWindow* me = CheckParamsAndGetThis(engine, info); + return (me != nullptr) ? me->OnHide(*engine, *info) : nullptr; +} + +NativeValue* JsWindow::MoveTo(NativeEngine* engine, NativeCallbackInfo* info) +{ + WLOGFI("JsWindow::MoveTo is called"); + JsWindow* me = CheckParamsAndGetThis(engine, info); + return (me != nullptr) ? me->OnMoveTo(*engine, *info) : nullptr; +} + +NativeValue* JsWindow::Resize(NativeEngine* engine, NativeCallbackInfo* info) +{ + WLOGFI("JsWindow::Resize is called"); + JsWindow* me = CheckParamsAndGetThis(engine, info); + return (me != nullptr) ? me->OnResize(*engine, *info) : nullptr; +} + +NativeValue* JsWindow::SetWindowType(NativeEngine* engine, NativeCallbackInfo* info) +{ + WLOGFI("JsWindow::SetWindowType is called"); + JsWindow* me = CheckParamsAndGetThis(engine, info); + return (me != nullptr) ? me->OnSetWindowType(*engine, *info) : nullptr; +} + +NativeValue* JsWindow::SetWindowMode(NativeEngine* engine, NativeCallbackInfo* info) +{ + WLOGFI("JsWindow::SetWindowMode is called"); + JsWindow* me = CheckParamsAndGetThis(engine, info); + return (me != nullptr) ? me->OnSetWindowMode(*engine, *info) : nullptr; +} + +NativeValue* JsWindow::GetProperties(NativeEngine* engine, NativeCallbackInfo* info) +{ + WLOGFI("JsWindow::GetProperties is called"); + JsWindow* me = CheckParamsAndGetThis(engine, info); + return (me != nullptr) ? me->OnGetProperties(*engine, *info) : nullptr; +} + +NativeValue* JsWindow::RegisterWindowCallback(NativeEngine* engine, NativeCallbackInfo* info) +{ + WLOGFI("JsWindow::RegisterWindowCallback is called"); + JsWindow* me = CheckParamsAndGetThis(engine, info); + return (me != nullptr) ? me->OnRegisterWindowCallback(*engine, *info) : nullptr; +} + +NativeValue* JsWindow::UnRegisterWindowCallback(NativeEngine* engine, NativeCallbackInfo* info) +{ + WLOGFI("JsWindow::UnRegisterWindowCallback is called"); + JsWindow* me = CheckParamsAndGetThis(engine, info); + return (me != nullptr) ? me->OnUnRegisterWindowCallback(*engine, *info) : nullptr; +} + +NativeValue* JsWindow::OnShow(NativeEngine& engine, NativeCallbackInfo& info) +{ + WLOGFI("JsWindow::OnShow is called"); + if (windowToken_ == nullptr) { + WLOGFE("JsWindow windowToken_ is nullptr"); + return engine.CreateUndefined(); + } + AsyncTask::CompleteCallback complete = + [this](NativeEngine& engine, AsyncTask& task, int32_t status) { + WMError ret = windowToken_->Show(); + if (ret == WMError::WM_OK) { + task.Resolve(engine, engine.CreateUndefined()); + WLOGFI("JsWindow::OnShow success"); + } else { + task.Reject(engine, CreateJsError(engine, static_cast(ret), "ShowWindow failed.")); + } + }; + + NativeValue* lastParam = (info.argc == 0) ? nullptr : info.argv[0]; + NativeValue* result = nullptr; + AsyncTask::Schedule( + engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result)); + return result; +} + +NativeValue* JsWindow::OnDestroy(NativeEngine& engine, NativeCallbackInfo& info) +{ + WLOGFI("JsWindow::OnDestroy is called"); + if (windowToken_ == nullptr) { + WLOGFE("JsWindow windowToken_ is nullptr"); + return engine.CreateUndefined(); + } + AsyncTask::CompleteCallback complete = + [this](NativeEngine& engine, AsyncTask& task, int32_t status) { + WMError ret = windowToken_->Destroy(); + windowToken_ = nullptr; + if (ret == WMError::WM_OK) { + task.Resolve(engine, engine.CreateUndefined()); + WLOGFI("JsWindow::OnDestroy success"); + } else { + task.Reject(engine, CreateJsError(engine, static_cast(ret), "JsWindow::OnDestroy failed.")); + } + }; + + NativeValue* lastParam = (info.argc == 0) ? nullptr : info.argv[0]; + NativeValue* result = nullptr; + AsyncTask::Schedule( + engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result)); + return result; +} + +NativeValue* JsWindow::OnHide(NativeEngine& engine, NativeCallbackInfo& info) +{ + WLOGFI("JsWindow::OnHide is called"); + if (windowToken_ == nullptr) { + WLOGFE("JsWindow windowToken_ is nullptr"); + return engine.CreateUndefined(); + } + AsyncTask::CompleteCallback complete = + [this](NativeEngine& engine, AsyncTask& task, int32_t status) { + WMError ret = windowToken_->Hide(); + if (ret == WMError::WM_OK) { + task.Resolve(engine, engine.CreateUndefined()); + WLOGFI("JsWindow::OnHide success"); + } else { + task.Reject(engine, CreateJsError(engine, static_cast(ret), "JsWindow::OnHide failed.")); + } + }; + + NativeValue* lastParam = (info.argc == 0) ? nullptr : info.argv[0]; + NativeValue* result = nullptr; + AsyncTask::Schedule( + engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result)); + return result; +} + +NativeValue* JsWindow::OnMoveTo(NativeEngine& engine, NativeCallbackInfo& info) +{ + WLOGFI("JsWindow::OnMoveTo is called"); + if (windowToken_ == nullptr) { + WLOGFE("JsWindow windowToken_ is nullptr"); + return engine.CreateUndefined(); + } + int32_t x; + if (!ConvertFromJsValue(engine, info.argv[0], x)) { + WLOGFE("Failed to convert parameter to x"); + return engine.CreateUndefined(); + } + + int32_t y; + if (!ConvertFromJsValue(engine, info.argv[1], y)) { + WLOGFE("Failed to convert parameter to y"); + return engine.CreateUndefined(); + } + AsyncTask::CompleteCallback complete = + [this, x, y](NativeEngine& engine, AsyncTask& task, int32_t status) { + WMError ret = windowToken_->MoveTo(x, y); + if (ret == WMError::WM_OK) { + task.Resolve(engine, engine.CreateUndefined()); + WLOGFI("JsWindow::OnMoveTo success"); + } else { + task.Reject(engine, CreateJsError(engine, static_cast(ret), "JsWindow::OnMoveTo failed.")); + } + }; + + NativeValue* lastParam = (info.argc == ARGC_TWO) ? nullptr : info.argv[INDEX_TWO]; + NativeValue* result = nullptr; + AsyncTask::Schedule( + engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result)); + return result; +} + +NativeValue* JsWindow::OnResize(NativeEngine& engine, NativeCallbackInfo& info) +{ + WLOGFI("JsWindow::OnResize is called"); + if (windowToken_ == nullptr) { + WLOGFE("JsWindow windowToken_ is nullptr"); + return engine.CreateUndefined(); + } + uint32_t width; + if (!ConvertFromJsValue(engine, info.argv[0], width)) { + WLOGFE("Failed to convert parameter to width"); + return engine.CreateUndefined(); + } + + uint32_t height; + if (!ConvertFromJsValue(engine, info.argv[1], height)) { + WLOGFE("Failed to convert parameter to height"); + return engine.CreateUndefined(); + } + AsyncTask::CompleteCallback complete = + [this, width, height](NativeEngine& engine, AsyncTask& task, int32_t status) { + WMError ret = windowToken_->Resize(width, height); + if (ret == WMError::WM_OK) { + task.Resolve(engine, engine.CreateUndefined()); + } else { + task.Reject(engine, CreateJsError(engine, static_cast(ret), "JsWindow::OnResize failed.")); + } + }; + NativeValue* lastParam = (info.argc == ARGC_TWO) ? nullptr : info.argv[INDEX_TWO]; + NativeValue* result = nullptr; + AsyncTask::Schedule( + engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result)); + return result; +} + +NativeValue* JsWindow::OnSetWindowType(NativeEngine& engine, NativeCallbackInfo& info) +{ + WLOGFI("JsWindow::OnSetWindowType is called"); + if (windowToken_ == nullptr) { + WLOGFE("JsWindow windowToken_ is nullptr"); + return engine.CreateUndefined(); + } + NativeNumber* nativeType = ConvertNativeValueTo(info.argv[0]); + if (nativeType == nullptr) { + WLOGFE("Failed to convert parameter to windowType"); + return engine.CreateUndefined(); + } + WindowType winType = static_cast(static_cast(*nativeType)); + AsyncTask::CompleteCallback complete = + [this, winType](NativeEngine& engine, AsyncTask& task, int32_t status) { + WMError ret = windowToken_->SetWindowType(winType); + if (ret == WMError::WM_OK) { + task.Resolve(engine, engine.CreateUndefined()); + WLOGFI("JsWindow::OnSetWindowType success"); + } else { + task.Reject(engine, CreateJsError(engine, + static_cast(ret), "JsWindow::OnSetWindowType failed.")); + } + }; + + NativeValue* lastParam = (info.argc == ARGC_ONE) ? nullptr : info.argv[INDEX_ONE]; + NativeValue* result = nullptr; + AsyncTask::Schedule( + engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result)); + return result; +} + +NativeValue* JsWindow::OnSetWindowMode(NativeEngine& engine, NativeCallbackInfo& info) +{ + WLOGFI("JsWindow::OnSetWindowMode is called"); + if (windowToken_ == nullptr) { + WLOGFE("JsWindow windowToken_ is nullptr"); + return engine.CreateUndefined(); + } + NativeNumber* nativeMode = ConvertNativeValueTo(info.argv[0]); + if (nativeMode == nullptr) { + WLOGFE("Failed to convert parameter to windowMode"); + return engine.CreateUndefined(); + } + WindowMode winMode = static_cast(static_cast(*nativeMode)); + AsyncTask::CompleteCallback complete = + [this, winMode](NativeEngine& engine, AsyncTask& task, int32_t status) { + WMError ret = windowToken_->SetWindowMode(winMode); + if (ret == WMError::WM_OK) { + task.Resolve(engine, engine.CreateUndefined()); + WLOGFI("JsWindow::OnSetWindowMode success"); + } else { + task.Reject(engine, + CreateJsError(engine, static_cast(ret), "JsWindow::OnSetWindowMode failed.")); + } + }; + + NativeValue* lastParam = (info.argc == ARGC_ONE) ? nullptr : info.argv[INDEX_ONE]; + NativeValue* result = nullptr; + AsyncTask::Schedule( + engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result)); + return result; +} + +NativeValue* JsWindow::OnGetProperties(NativeEngine& engine, NativeCallbackInfo& info) +{ + WLOGFI("JsWindow::OnGetProperties is called"); + if (windowToken_ == nullptr) { + WLOGFE("JsWindow windowToken_ is nullptr"); + return engine.CreateUndefined(); + } + AsyncTask::CompleteCallback complete = + [this](NativeEngine& engine, AsyncTask& task, int32_t status) { + auto objValue = CreateJsWindowPropertiesObject(engine, windowToken_); + WLOGFI("JsWindow::OnGetProperties objValue %{public}p", objValue); + if (objValue != nullptr) { + task.Resolve(engine, objValue); + WLOGFI("JsWindow::OnGetProperties success"); + } else { + task.Reject(engine, CreateJsError(engine, + static_cast(WMError::WM_ERROR_NULLPTR), "JsWindow::OnGetProperties failed.")); + } + }; + + NativeValue* lastParam = (info.argc == 0) ? nullptr : info.argv[0]; + NativeValue* result = nullptr; + AsyncTask::Schedule( + engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result)); + return result; +} + +NativeValue* JsWindow::OnRegisterWindowCallback(NativeEngine& engine, NativeCallbackInfo& info) +{ + WLOGFI("JsWindow::OnRegisterWindowCallback is called"); + if (windowToken_ == nullptr || windowListener_ == nullptr) { + WLOGFE("JsWindow windowToken_ or windowListener_ is nullptr"); + return engine.CreateUndefined(); + } + if (info.argc != ARGC_TWO) { + WLOGFE("Params not match"); + return engine.CreateUndefined(); + } + std::string cbType; + if (!ConvertFromJsValue(engine, info.argv[0], cbType)) { + WLOGFE("Failed to convert parameter to callbackType"); + return engine.CreateUndefined(); + } + NativeValue* value = info.argv[1]; + if (!value->IsCallable()) { + WLOGFI("JsWindow::OnRegisterWindowCallback info->argv[1] is not callable"); + return engine.CreateUndefined(); + } + if (!windowListener_->AddJsListenerObject(cbType, info.argv[1])) { + WLOGFI("JsWindow::OnRegisterWindowCallback failed"); + return engine.CreateUndefined(); + } + if (cbType.compare("windowSizeChange") == 0) { + sptr thisListener(windowListener_); + windowToken_->RegisterWindowChangeListener(thisListener); + WLOGFI("JsWindow::OnRegisterWindowCallback success"); + } + return engine.CreateUndefined(); +} + +NativeValue* JsWindow::OnUnRegisterWindowCallback(NativeEngine& engine, NativeCallbackInfo& info) +{ + WLOGFI("JsWindow::OnUnRegisterWindowCallback is called"); + if (windowToken_ == nullptr || windowListener_ == nullptr) { + WLOGFE("JsWindow windowToken_ or windowListener_ is nullptr"); + return engine.CreateUndefined(); + } + if (info.argc == 0) { + WLOGFE("Params not match"); + return engine.CreateUndefined(); + } + std::string cbType; + if (!ConvertFromJsValue(engine, info.argv[0], cbType)) { + WLOGFE("Failed to convert parameter to callbackType"); + return engine.CreateUndefined(); + } + NativeValue* lastParam = (info.argc == 1) ? nullptr : info.argv[1]; + windowListener_->RemoveJsListenerObject(cbType, lastParam); + return engine.CreateUndefined(); +} + +NativeValue* CreateJsWindowObject(NativeEngine& engine, sptr& window) +{ + WLOGFI("JsWindow::CreateJsWindow is called"); + NativeValue* objValue = engine.CreateObject(); + NativeObject* object = ConvertNativeValueTo(objValue); + + std::unique_ptr jsWindow = std::make_unique(window, engine); + object->SetNativePointer(jsWindow.release(), JsWindow::Finalizer, nullptr); + + BindNativeFunction(engine, *object, "show", JsWindow::Show); + BindNativeFunction(engine, *object, "destroy", JsWindow::Destroy); + BindNativeFunction(engine, *object, "hide", JsWindow::Hide); + BindNativeFunction(engine, *object, "moveTo", JsWindow::MoveTo); + BindNativeFunction(engine, *object, "resetSize", JsWindow::Resize); + BindNativeFunction(engine, *object, "setWindowType", JsWindow::SetWindowType); + BindNativeFunction(engine, *object, "setWindowMode", JsWindow::SetWindowMode); + BindNativeFunction(engine, *object, "getProperties", JsWindow::GetProperties); + BindNativeFunction(engine, *object, "on", JsWindow::RegisterWindowCallback); + BindNativeFunction(engine, *object, "off", JsWindow::UnRegisterWindowCallback); + return objValue; +} +} // namespace Rosen +} // namespace OHOS diff --git a/interfaces/kits/napi/window_runtime/js_window.h b/interfaces/kits/napi/window_runtime/js_window.h new file mode 100644 index 00000000..dceeea19 --- /dev/null +++ b/interfaces/kits/napi/window_runtime/js_window.h @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2021 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_JS_WINDOW_H +#define OHOS_JS_WINDOW_H +#include "js_runtime_utils.h" +#include "js_window_listener.h" +#include "js_window_utils.h" +#include "native_engine/native_engine.h" +#include "native_engine/native_value.h" +#include "window.h" +namespace OHOS { +namespace Rosen { +NativeValue* CreateJsWindowObject(NativeEngine& engine, sptr& window); + +class JsWindow final { +public: + JsWindow(const sptr& window, NativeEngine& engine); + ~JsWindow() = default; + static void Finalizer(NativeEngine* engine, void* data, void* hint); + static NativeValue* Show(NativeEngine* engine, NativeCallbackInfo* info); + static NativeValue* Destroy(NativeEngine* engine, NativeCallbackInfo* info); + static NativeValue* Hide(NativeEngine* engine, NativeCallbackInfo* info); + static NativeValue* MoveTo(NativeEngine* engine, NativeCallbackInfo* info); + static NativeValue* Resize(NativeEngine* engine, NativeCallbackInfo* info); + static NativeValue* SetWindowType(NativeEngine* engine, NativeCallbackInfo* info); + static NativeValue* SetWindowMode(NativeEngine* engine, NativeCallbackInfo* info); + static NativeValue* GetProperties(NativeEngine* engine, NativeCallbackInfo* info); + static NativeValue* RegisterWindowCallback(NativeEngine* engine, NativeCallbackInfo* info); + static NativeValue* UnRegisterWindowCallback(NativeEngine* engine, NativeCallbackInfo* info); + +private: + NativeValue* OnShow(NativeEngine& engine, NativeCallbackInfo& info); + NativeValue* OnDestroy(NativeEngine& engine, NativeCallbackInfo& info); + NativeValue* OnHide(NativeEngine& engine, NativeCallbackInfo& info); + NativeValue* OnMoveTo(NativeEngine& engine, NativeCallbackInfo& info); + NativeValue* OnResize(NativeEngine& engine, NativeCallbackInfo& info); + NativeValue* OnSetWindowType(NativeEngine& engine, NativeCallbackInfo& info); + NativeValue* OnSetWindowMode(NativeEngine& engine, NativeCallbackInfo& info); + NativeValue* OnGetProperties(NativeEngine& engine, NativeCallbackInfo& info); + NativeValue* OnRegisterWindowCallback(NativeEngine& engine, NativeCallbackInfo& info); + NativeValue* OnUnRegisterWindowCallback(NativeEngine& engine, NativeCallbackInfo& info); + sptr windowToken_ = nullptr; + sptr windowListener_ = nullptr; +}; +} // namespace Rosen +} // namespace OHOS +#endif \ No newline at end of file diff --git a/interfaces/kits/napi/window_runtime/js_window_listener.cpp b/interfaces/kits/napi/window_runtime/js_window_listener.cpp new file mode 100644 index 00000000..686be374 --- /dev/null +++ b/interfaces/kits/napi/window_runtime/js_window_listener.cpp @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2021 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 "js_window_listener.h" +#include "js_runtime_utils.h" +#include "window_manager_hilog.h" +namespace OHOS { +namespace Rosen { +using namespace AbilityRuntime; +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "JsWindowListener"}; +} +bool JsWindowListener::IsCallbackExists(std::string type, NativeValue* jsListenerObject) +{ + if (jsWinodwListenerObjectMap_.find(type) == jsWinodwListenerObjectMap_.end()) { + WLOGFE("JsWindowListener::IsCallbackExists methodName %{public}s not exist!", type.c_str()); + return false; + } + for (auto iter = jsWinodwListenerObjectMap_[type].begin(); + iter != jsWinodwListenerObjectMap_[type].end(); iter++) { + if (jsListenerObject->StrictEquals((*iter)->Get())) { + WLOGFI("JsWindowListener::AddJsListenerObject callback already exists!"); + return true; + } + } + return false; +} + +bool JsWindowListener::AddJsListenerObject(std::string type, NativeValue* jsListenerObject) +{ + WLOGFI("JsWindowListener::AddJsListenerObject is called"); + std::lock_guard lock(listenerMutex_); + std::unique_ptr callbackRef; + callbackRef.reset(engine_->CreateReference(jsListenerObject, 1)); + if (IsCallbackExists(type, jsListenerObject)) { + WLOGFI("JsWindowListener::AddJsListenerObject jsWinodwListenerObjectMap_ size: %{public}d!", + jsWinodwListenerObjectMap_[type].size()); + return false; + } + jsWinodwListenerObjectMap_[type].insert(std::move(callbackRef)); + WLOGFI("JsWindowListener::AddJsListenerObject failed jsWinodwListenerObjectMap_ size: %{public}d!", + jsWinodwListenerObjectMap_[type].size()); + return true; +} + +void JsWindowListener::RemoveJsListenerObject(std::string type, NativeValue* jsListenerObject) +{ + WLOGFI("JsWindowListener::RemoveJsListenerObject is called"); + std::lock_guard lock(listenerMutex_); + if (jsWinodwListenerObjectMap_.find(type) == jsWinodwListenerObjectMap_.end()) { + WLOGFE("methodName %{public}s not exist!", type.c_str()); + return; + } + if (jsListenerObject == nullptr) { + jsWinodwListenerObjectMap_.erase(type); + } else { + for (auto iter = jsWinodwListenerObjectMap_[type].begin(); + iter != jsWinodwListenerObjectMap_[type].end(); iter++) { + if (jsListenerObject->StrictEquals((*iter)->Get())) { + jsWinodwListenerObjectMap_[type].erase(iter); + } + } + } + WLOGFI("JsWindowListener::RemoveJsListenerObject jsWinodwListenerObjectMap_ size: %{public}d!", + jsWinodwListenerObjectMap_[type].size()); + WLOGFI("JsWindowListener::RemoveJsListenerObject success!"); +} + +void JsWindowListener::OnSizeChange(Rect rect) +{ + WLOGFI("JsWindowListener::OnSizeChange is called"); + NativeValue* sizeValue = engine_->CreateObject(); + NativeObject* object = ConvertNativeValueTo(sizeValue); + if (object == nullptr) { + WLOGFE("Failed to convert rect to jsObject"); + return; + } + object->SetProperty("width", CreateJsValue(*engine_, rect.width_)); + object->SetProperty("height", CreateJsValue(*engine_, rect.height_)); + NativeValue* argv[] = {sizeValue}; + CallJsMethod("windowSizeChange", argv, ArraySize(argv)); +} + +void JsWindowListener::CallJsMethod(const char* methodName, NativeValue* const* argv, size_t argc) +{ + WLOGFI("CallJsMethod methodName = %{public}s", methodName); + if (engine_ == nullptr) { + WLOGFE("engine_ nullptr"); + return; + } + std::lock_guard lock(listenerMutex_); + std::string type(methodName); + if (jsWinodwListenerObjectMap_.find(type) == jsWinodwListenerObjectMap_.end()) { + WLOGFE("methodName %{public}s not exist!", methodName); + return; + } + for (auto iter = jsWinodwListenerObjectMap_[type].begin(); iter != jsWinodwListenerObjectMap_[type].end(); iter++) { + NativeValue* method = (*iter)->Get(); + if (method == nullptr) { + WLOGFE("Failed to get method callback from object"); + return; + } + engine_->CallFunction(engine_->CreateUndefined(), method, argv, argc); + } +} +} // namespace Rosen +} // namespace OHOS \ No newline at end of file diff --git a/interfaces/kits/napi/window_runtime/js_window_listener.h b/interfaces/kits/napi/window_runtime/js_window_listener.h new file mode 100644 index 00000000..19ba2d83 --- /dev/null +++ b/interfaces/kits/napi/window_runtime/js_window_listener.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2021 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_JS_WINDOW_LISTENER_H +#define OHOS_JS_WINDOW_LISTENER_H + +#include +#include +#include +#include "native_engine/native_engine.h" +#include "native_engine/native_value.h" +#include "window.h" +namespace OHOS { +namespace Rosen { +class JsWindowListener : public IWindowChangeListener { +public: + explicit JsWindowListener(NativeEngine* engine) : engine_(engine) {} + virtual ~JsWindowListener() = default; + void OnSizeChange(Rect rect) override; + bool AddJsListenerObject(std::string type, NativeValue* jsListenerObject); + void RemoveJsListenerObject(std::string type, NativeValue* jsListenerObject); +private: + void CallJsMethod(const char* methodName, NativeValue* const* argv = nullptr, size_t argc = 0); + bool IsCallbackExists(std::string type, NativeValue* jsListenerObject); + NativeEngine* engine_ = nullptr; + std::map>> jsWinodwListenerObjectMap_; + std::mutex listenerMutex_; +}; +} // namespace Rosen +} // namespace OHOS +#endif /* OHOS_JS_WINDOW_LISTENER_H */ \ No newline at end of file diff --git a/interfaces/kits/napi/window_runtime/js_window_manager.cpp b/interfaces/kits/napi/window_runtime/js_window_manager.cpp new file mode 100644 index 00000000..1e883acb --- /dev/null +++ b/interfaces/kits/napi/window_runtime/js_window_manager.cpp @@ -0,0 +1,149 @@ +/* + * Copyright (c) 2021 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 "js_window_manager.h" +#include "js_runtime_utils.h" +#include "js_window.h" +#include "js_window_utils.h" +#include "native_engine/native_reference.h" +#include "window_manager_hilog.h" +#include "window_option.h" + +namespace OHOS { +namespace Rosen { +using namespace AbilityRuntime; +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "JsWindowManager"}; +} + +class JsWindowManager { +public: + JsWindowManager() = default; + ~JsWindowManager() = default; + + static void Finalizer(NativeEngine* engine, void* data, void* hint) + { + WLOGFI("JsWindowManager::Finalizer is called"); + std::unique_ptr(static_cast(data)); + } + + static NativeValue* CreateWindow(NativeEngine* engine, NativeCallbackInfo* info) + { + JsWindowManager* me = CheckParamsAndGetThis(engine, info); + return (me != nullptr) ? me->OnCreateWindow(*engine, *info) : nullptr; + } + + static NativeValue* FindWindow(NativeEngine* engine, NativeCallbackInfo* info) + { + JsWindowManager* me = CheckParamsAndGetThis(engine, info); + return (me != nullptr) ? me->OnFindWindow(*engine, *info) : nullptr; + } + +private: + + NativeValue* OnCreateWindow(NativeEngine& engine, NativeCallbackInfo& info) + { + WLOGFI("JsOnCreateWindow is called"); + + if (info.argc < ARGC_TWO) { + WLOGFE("OnCreateWindow MUST set windowname"); + return engine.CreateUndefined(); + } + std::string windowName; + if (!ConvertFromJsValue(engine, info.argv[0], windowName)) { + WLOGFE("Failed to convert parameter to windowName"); + return engine.CreateUndefined(); + } + NativeNumber* nativeType = ConvertNativeValueTo(info.argv[1]); + if (nativeType == nullptr) { + WLOGFE("Failed to convert parameter to windowType"); + return engine.CreateUndefined(); + } + WindowType winType = static_cast(static_cast(*nativeType)); + AsyncTask::CompleteCallback complete = + [windowName, winType](NativeEngine& engine, AsyncTask& task, int32_t status) { + sptr windowOption = new WindowOption(); + windowOption->SetWindowType(winType); + sptr window = Window::Create(windowName, windowOption); + if (window != nullptr) { + task.Resolve(engine, CreateJsWindowObject(engine, window)); + WLOGFI("JsWindowManager::OnCreateWindow success"); + } else { + task.Reject(engine, CreateJsError(engine, + static_cast(WMError::WM_ERROR_NULLPTR), "JsWindowManager::OnCreateWindow failed.")); + } + }; + NativeValue* lastParam = (info.argc == ARGC_TWO) ? nullptr : info.argv[INDEX_TWO]; + NativeValue* result = nullptr; + AsyncTask::Schedule( + engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result)); + return result; + } + + NativeValue* OnFindWindow(NativeEngine& engine, NativeCallbackInfo& info) + { + std::string windowName; + if (!ConvertFromJsValue(engine, info.argv[0], windowName)) { + WLOGFE("Failed to convert parameter to windowName"); + return engine.CreateUndefined(); + } + + AsyncTask::CompleteCallback complete = + [windowName](NativeEngine& engine, AsyncTask& task, int32_t status) { + sptr window = Window::Find(windowName); + if (window != nullptr) { + task.Resolve(engine, CreateJsWindowObject(engine, window)); + WLOGFI("JsWindowManager::OnFindWindow success"); + } else { + task.Reject(engine, CreateJsError(engine, + static_cast(WMError::WM_ERROR_NULLPTR), "JsWindow::OnFindWindow failed.")); + } + }; + + NativeValue* lastParam = (info.argc == ARGC_ONE) ? nullptr : info.argv[INDEX_ONE]; + if (lastParam == nullptr) { + WLOGFI("JsWindowManager::OnFindWindow lastParam is nullptr"); + } + NativeValue* result = nullptr; + AsyncTask::Schedule( + engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result)); + return result; + } +}; + +NativeValue* JsWindowManagerInit(NativeEngine* engine, NativeValue* exportObj) +{ + WLOGFI("JsWindowManagerInit is called"); + + if (engine == nullptr || exportObj == nullptr) { + WLOGFE("JsWindowManagerInit engine or exportObj is nullptr"); + return nullptr; + } + + NativeObject* object = ConvertNativeValueTo(exportObj); + if (object == nullptr) { + WLOGFE("JsWindowManagerInit object is nullptr"); + return nullptr; + } + + std::unique_ptr jsWinManager = std::make_unique(); + object->SetNativePointer(jsWinManager.release(), JsWindowManager::Finalizer, nullptr); + + BindNativeFunction(*engine, *object, "create", JsWindowManager::CreateWindow); + BindNativeFunction(*engine, *object, "find", JsWindowManager::FindWindow); + + return engine->CreateUndefined(); +} +} // namespace Rosen +} // namespace OHOS \ No newline at end of file diff --git a/interfaces/kits/napi/window_runtime/js_window_manager.h b/interfaces/kits/napi/window_runtime/js_window_manager.h new file mode 100644 index 00000000..8944eebe --- /dev/null +++ b/interfaces/kits/napi/window_runtime/js_window_manager.h @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2021 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 "native_engine/native_engine.h" +#include "native_engine/native_value.h" +#ifndef OHOS_JS_WINDOW_MANAGER_H +#define OHOS_JS_WINDOW_MANAGER_H +namespace OHOS { +namespace Rosen { +NativeValue* JsWindowManagerInit(NativeEngine* engine, NativeValue* exportObj); +} // namespace Rosen +} // namespace OHOS + +#endif diff --git a/interfaces/kits/napi/window_runtime/js_window_utils.cpp b/interfaces/kits/napi/window_runtime/js_window_utils.cpp new file mode 100644 index 00000000..0dfe19d8 --- /dev/null +++ b/interfaces/kits/napi/window_runtime/js_window_utils.cpp @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2021 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 "js_window_utils.h" +#include "js_runtime_utils.h" +#include "window_manager_hilog.h" +namespace OHOS { +namespace Rosen { +using namespace AbilityRuntime; +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "JsWindowUtils"}; +} + +static NativeValue* GetRectAndConvertToJsValue(NativeEngine& engine, const Rect& rect) +{ + NativeValue* objValue = engine.CreateObject(); + NativeObject* object = ConvertNativeValueTo(objValue); + if (object == nullptr) { + WLOGFE("Failed to convert rect to jsObject"); + return engine.CreateUndefined(); + } + object->SetProperty("left", CreateJsValue(engine, rect.posX_)); + object->SetProperty("top", CreateJsValue(engine, rect.posY_)); + object->SetProperty("width", CreateJsValue(engine, rect.width_)); + object->SetProperty("height", CreateJsValue(engine, rect.height_)); + return objValue; +} + +NativeValue* CreateJsWindowPropertiesObject(NativeEngine& engine, sptr& window) +{ + WLOGFI("JsWindow::CreateJsWindowPropertiesObject is called"); + NativeValue* objValue = engine.CreateObject(); + NativeObject* object = ConvertNativeValueTo(objValue); + if (object == nullptr) { + WLOGFE("Failed to convert windowProperties to jsObject"); + return nullptr; + } + + Rect rect = window->GetRect(); + NativeValue* rectObj = GetRectAndConvertToJsValue(engine, rect); + if (rectObj == nullptr) { + WLOGFE("GetRect failed!"); + } + object->SetProperty("windowRect", rectObj); + object->SetProperty("type", CreateJsValue(engine, window->GetType())); + return objValue; +} +} // namespace Rosen +} // namespace OHOS \ No newline at end of file diff --git a/interfaces/kits/napi/window_runtime/js_window_utils.h b/interfaces/kits/napi/window_runtime/js_window_utils.h new file mode 100644 index 00000000..a00c712d --- /dev/null +++ b/interfaces/kits/napi/window_runtime/js_window_utils.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2021 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_JS_WINDOW_UTILS_H +#define OHOS_JS_WINDOW_UTILS_H +#include "native_engine/native_engine.h" +#include "native_engine/native_value.h" +#include "window.h" +#include "window_option.h" +#include "wm_common.h" +namespace OHOS { +namespace Rosen { +namespace { + constexpr size_t ARGC_ONE = 1; + constexpr size_t ARGC_TWO = 2; + constexpr int32_t INDEX_ONE = 1; + constexpr int32_t INDEX_TWO = 2; +} + + NativeValue* CreateJsWindowPropertiesObject(NativeEngine& engine, sptr& window); +} +} +#endif \ No newline at end of file diff --git a/interfaces/kits/napi/window_runtime/window_manager_module.cpp b/interfaces/kits/napi/window_runtime/window_manager_module.cpp new file mode 100644 index 00000000..70c3b95e --- /dev/null +++ b/interfaces/kits/napi/window_runtime/window_manager_module.cpp @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2021 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 "js_window_manager.h" +#include "native_engine/native_engine.h" + +extern "C" __attribute__((constructor)) +void NAPI_application_windowmanager_AutoRegister() +{ + auto moduleManager = NativeModuleManager::GetInstance(); + NativeModule newModuleInfo = { + .name = "application.windowmanager", + .fileName = "application/libwindowmanager_napi.so/windowmanager.js", + .registerCallback = OHOS::Rosen::JsWindowManagerInit, + }; + + moduleManager->Register(&newModuleInfo); +} diff --git a/interfaces/kits/napi/window_stage.js b/interfaces/kits/napi/window_stage.js index 43af79d1..339f5b91 100644 --- a/interfaces/kits/napi/window_stage.js +++ b/interfaces/kits/napi/window_stage.js @@ -21,6 +21,22 @@ class WindowStage { setUIContent(context, url, storage) { return this.__window_stage__.setUIContent(context, url, storage) } + + getMainWindow() { + return this.__window_stage__.getMainWindow() + } + + on(type, callback) { + return this.__window_stage__.on(type, callback) + } + + off(type) { + return this.__window_stage__.off(type) + } + + off(type, callback) { + return this.__window_stage__.off(type, callback) + } } export default WindowStage diff --git a/ohos.build b/ohos.build index 49aaabd0..0887e15a 100644 --- a/ohos.build +++ b/ohos.build @@ -5,11 +5,10 @@ "module_list": [ "//foundation/windowmanager/interfaces/kits/js/declaration:window", "//foundation/windowmanager/sa_profile:wms_sa_profile", - "//foundation/windowmanager/adapter:libwmadaptertest", + "//foundation/windowmanager/adapter:libwmadapter", "//foundation/windowmanager/wm:libwm", "//foundation/windowmanager/wmserver:libwms", "//foundation/windowmanager/wm:libwmutil", - "//foundation/windowmanager/wmtest:rosenwmtest", "//foundation/windowmanager/interfaces/kits/napi:windowstage", "//foundation/windowmanager/interfaces/kits/napi:napi_packages" diff --git a/sa_profile/4606.xml b/sa_profile/4606.xml index aa724881..7a02c334 100644 --- a/sa_profile/4606.xml +++ b/sa_profile/4606.xml @@ -23,4 +23,4 @@ false 1 - \ No newline at end of file + diff --git a/utils/include/noncopyable.h b/utils/include/noncopyable.h new file mode 100644 index 00000000..12d3ed7b --- /dev/null +++ b/utils/include/noncopyable.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2021 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_NONCOPYABLE_H +#define OHOS_WM_INCLUDE_NONCOPYABLE_H + +#define WM_DISALLOW_COPY_AND_MOVE(className) \ + WM_DISALLOW_COPY(className); \ + WM_DISALLOW_MOVE(className) + +#define WM_DISALLOW_COPY(className) \ + className(const className&) = delete; \ + className& operator=(const className&) = delete + +#define WM_DISALLOW_MOVE(className) \ + className(className&&) = delete; \ + className& operator=(className&&) = delete + +namespace OHOS::Rosen { +class NonCopyable { +protected: + NonCopyable() = default; + virtual ~NonCopyable() = default; + +private: + WM_DISALLOW_COPY_AND_MOVE(NonCopyable); +}; +} // namespace OHOS::Rosen + +#endif // OHOS_WM_INCLUDE_NONCOPYABLE_H diff --git a/utils/include/single_instance.h b/utils/include/single_instance.h index b255caf7..9c675b66 100644 --- a/utils/include/single_instance.h +++ b/utils/include/single_instance.h @@ -19,26 +19,21 @@ namespace OHOS { namespace Rosen { #define DECLARE_SINGLE_INSTANCE_BASE(className) \ public: \ - static sptr GetInstance(); \ -private: \ + static className& GetInstance() \ + { \ + static className instance; \ + return instance; \ + } \ className(const className&) = delete; \ className& operator= (const className&) = delete; \ className(className&&) = delete; \ - className& operator= (className&&) = delete; \ - + className& operator= (className&&) = delete; #define DECLARE_SINGLE_INSTANCE(className) \ DECLARE_SINGLE_INSTANCE_BASE(className) \ -private: \ +protected: \ className() = default; \ - ~className() = default; \ - -#define IMPLEMENT_SINGLE_INSTANCE(className) \ -sptr className::GetInstance() \ -{ \ - static sptr instance = new className(); \ - return instance; \ -} + virtual ~className() = default; } // namespace OHOS } #endif // OHOS_SINGLE_INSTANCE_H diff --git a/utils/include/singleton_container.h b/utils/include/singleton_container.h index 68d6d7e8..106ebd30 100644 --- a/utils/include/singleton_container.h +++ b/utils/include/singleton_container.h @@ -22,53 +22,46 @@ #include #include -#include - +#include "single_instance.h" namespace OHOS { namespace Rosen { -class SingletonContainer : public RefBase { -public: - static sptr GetInstance(); +class SingletonContainer { +DECLARE_SINGLE_INSTANCE_BASE(SingletonContainer); - void AddSingleton(const std::string &name, const std::any &instance); - void SetSingleton(const std::string &name, const std::any &instance); - const std::any &GetSingleton(const std::string &name); - const std::any &DependOn(const std::string &instance, const std::string &name); +public: + void AddSingleton(const std::string& name, void* instance); + + void SetSingleton(const std::string& name, void* instance); + + void* GetSingleton(const std::string& name); + + void* DependOn(const std::string& instance, const std::string& name); template - static sptr Get() + static T& Get() { std::string nameT = __PRETTY_FUNCTION__; nameT = nameT.substr(nameT.find("T = ")); nameT = nameT.substr(sizeof("T ="), nameT.length() - sizeof("T = ")); - - using sptrT = sptr; - sptrT ret = nullptr; - const std::any &instance = SingletonContainer::GetInstance()->GetSingleton(nameT); - auto pRet = std::any_cast(&instance); - if (pRet != nullptr) { - ret = *pRet; - } - return ret; + return *(reinterpret_cast(SingletonContainer::GetInstance().GetSingleton(nameT))); } template - static void Set(const sptr &ptr) + static void Set(T& instance) { std::string nameT = __PRETTY_FUNCTION__; nameT = nameT.substr(nameT.find("T = ")); nameT = nameT.substr(sizeof("T ="), nameT.length() - sizeof("T = ")); - - SingletonContainer::GetInstance()->SetSingleton(nameT, ptr); + SingletonContainer::GetInstance().SetSingleton(nameT, &instance); } private: SingletonContainer() = default; - virtual ~SingletonContainer() override; - static inline sptr instance = nullptr; + + virtual ~SingletonContainer(); struct Singleton { - std::any value; + void* value; int32_t refCount; }; std::map stringMap; @@ -77,5 +70,4 @@ private: }; } // namespace Rosen } // namespace OHOS - #endif // FRAMEWORKS_WM_INCLUDE_SINGLETON_CONTAINER_H diff --git a/utils/include/singleton_delegator.h b/utils/include/singleton_delegator.h index dae00046..7c6b6d11 100644 --- a/utils/include/singleton_delegator.h +++ b/utils/include/singleton_delegator.h @@ -30,21 +30,19 @@ public: nameT = __PRETTY_FUNCTION__; nameT = nameT.substr(nameT.find("T = ")); nameT = nameT.substr(sizeof("T ="), nameT.length() - sizeof("T = ")); - SingletonContainer::GetInstance()->AddSingleton(nameT, T::GetInstance()); + SingletonContainer::GetInstance().AddSingleton(nameT, &T::GetInstance()); } ~SingletonDelegator() = default; template - sptr Dep() + S& Dep() { std::string nameS = __PRETTY_FUNCTION__; nameS = nameS.substr(nameS.find("S = ")); nameS = nameS.substr(sizeof("S ="), nameS.length() - sizeof("S = ")); auto ret = SingletonContainer::Get(); - if (ret != nullptr) { - SingletonContainer::GetInstance()->DependOn(nameT, nameS); - } + SingletonContainer::GetInstance().DependOn(nameT, nameS); return ret; } diff --git a/utils/include/static_call.h b/utils/include/static_call.h index e505d2b7..adf68eef 100644 --- a/utils/include/static_call.h +++ b/utils/include/static_call.h @@ -23,11 +23,11 @@ #include "window_option.h" namespace OHOS { namespace Rosen { -class StaticCall : public RefBase { - DECLARE_SINGLE_INSTANCE_BASE(StaticCall); +class StaticCall { +DECLARE_SINGLE_INSTANCE_BASE(StaticCall); public: virtual sptr CreateWindow(const std::string& windowName, - sptr& option, const sptr& abilityToken = nullptr); + sptr& option, std::shared_ptr abilityContext = nullptr); protected: StaticCall() = default; private: diff --git a/utils/include/window_helper.h b/utils/include/window_helper.h new file mode 100644 index 00000000..b2054d8e --- /dev/null +++ b/utils/include/window_helper.h @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2021 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_HELPER_H +#define OHOS_WM_INCLUDE_WM_HELPER_H + +#include + +namespace OHOS { +namespace Rosen { +class WindowHelper { +public: + static inline bool IsMainWindow(WindowType type) + { + return (type >= WindowType::APP_MAIN_WINDOW_BASE && type <= WindowType::APP_MAIN_WINDOW_END); + } + + static inline bool IsSubWindow(WindowType type) + { + return (type >= WindowType::APP_SUB_WINDOW_BASE && type <= WindowType::APP_SUB_WINDOW_END); + } + + static inline bool IsAppWindow(WindowType type) + { + return (IsMainWindow(type) || IsSubWindow(type)); + } + + static inline bool IsBelowSystemWindow(WindowType type) + { + return (type >= WindowType::BELOW_APP_SYSTEM_WINDOW_BASE && type <= WindowType::BELOW_APP_SYSTEM_WINDOW_END); + } + + static inline bool IsAboveSystemWindow(WindowType type) + { + return (type >= WindowType::ABOVE_APP_SYSTEM_WINDOW_BASE && type <= WindowType::ABOVE_APP_SYSTEM_WINDOW_END); + } + + static inline bool IsSystemWindow(WindowType type) + { + return (IsBelowSystemWindow(type) || IsAboveSystemWindow(type)); + } + + WindowHelper() = default; + ~WindowHelper() = default; +}; +} // namespace OHOS +} // namespace Rosen +#endif // OHOS_WM_INCLUDE_WM_HELPER_H \ No newline at end of file diff --git a/utils/include/wm_trace.h b/utils/include/wm_trace.h new file mode 100644 index 00000000..33c15032 --- /dev/null +++ b/utils/include/wm_trace.h @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2021 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 "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() + +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(); + +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/singleton_container.cpp b/utils/src/singleton_container.cpp index 0b851fda..09eeb22a 100644 --- a/utils/src/singleton_container.cpp +++ b/utils/src/singleton_container.cpp @@ -23,18 +23,6 @@ namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowManager_SingletonContainer"}; } // namespace -sptr SingletonContainer::GetInstance() -{ - if (instance == nullptr) { - static std::mutex mutex; - std::lock_guard lock(mutex); - if (instance == nullptr) { - instance = new SingletonContainer(); - } - } - return instance; -} - SingletonContainer::~SingletonContainer() { while (singletonMap.empty() == false) { @@ -63,7 +51,7 @@ SingletonContainer::~SingletonContainer() } } -void SingletonContainer::AddSingleton(const std::string &name, const std::any &instance) +void SingletonContainer::AddSingleton(const std::string& name, void* instance) { if (stringMap.find(name) == stringMap.end()) { static int32_t nextId = 0; @@ -76,7 +64,7 @@ void SingletonContainer::AddSingleton(const std::string &name, const std::any &i } } -void SingletonContainer::SetSingleton(const std::string &name, const std::any &instance) +void SingletonContainer::SetSingleton(const std::string& name, void* instance) { if (stringMap.find(name) == stringMap.end()) { AddSingleton(name, instance); @@ -86,21 +74,20 @@ void SingletonContainer::SetSingleton(const std::string &name, const std::any &i } } -const std::any &SingletonContainer::GetSingleton(const std::string &name) +void* SingletonContainer::GetSingleton(const std::string& name) { if (stringMap.find(name) == stringMap.end()) { WLOGFD("cannot get %{public}s", name.c_str()); - static std::any voidAny; - return voidAny; + return nullptr; } return singletonMap[stringMap[name]].value; } -const std::any &SingletonContainer::DependOn(const std::string &instance, const std::string &name) +void* SingletonContainer::DependOn(const std::string& instance, const std::string& name) { - auto &instanceDependencySet = dependencySetMap[stringMap[instance]]; + auto& instanceDependencySet = dependencySetMap[stringMap[instance]]; if (instanceDependencySet.find(stringMap[name]) == instanceDependencySet.end()) { - WLOGFD("%{public}s dependon %{public}s", instance.c_str(), name.c_str()); + WLOGFD("%{public}s DependOn %{public}s", instance.c_str(), name.c_str()); instanceDependencySet.insert(stringMap[name]); singletonMap[stringMap[name]].refCount++; } diff --git a/utils/src/static_call.cpp b/utils/src/static_call.cpp index 5b8797a3..1e815321 100644 --- a/utils/src/static_call.cpp +++ b/utils/src/static_call.cpp @@ -17,12 +17,10 @@ namespace OHOS { namespace Rosen { -IMPLEMENT_SINGLE_INSTANCE(StaticCall); - sptr StaticCall::CreateWindow(const std::string& windowName, - sptr& option, const sptr& abilityToken) + sptr& option, std::shared_ptr abilityContext) { - return Window::Create(windowName, option, abilityToken); + return Window::Create(windowName, option, abilityContext); } } // namespace Rosen } // namespace OHOS \ No newline at end of file diff --git a/utils/src/wm_trace.cpp b/utils/src/wm_trace.cpp new file mode 100644 index 00000000..16736968 --- /dev/null +++ b/utils/src/wm_trace.cpp @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2021 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); + // TODO:need BYTRACE_TAG_WINDOW_MANAGER + StartTrace(BYTRACE_TAG_GRAPHIC_AGP, nameStr); +} + +void WmTraceEnd() +{ + if (WmTraceEnabled()) { + // TODO:need BYTRACE_TAG_WINDOW_MANAGER + FinishTrace(BYTRACE_TAG_GRAPHIC_AGP); + } +} + +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/wm/BUILD.gn b/wm/BUILD.gn index a5179685..6d7293a9 100644 --- a/wm/BUILD.gn +++ b/wm/BUILD.gn @@ -43,12 +43,8 @@ config("libwm_config") { "//foundation/graphic/standard/interfaces/innerkits/common", # weston adapter end - ] - - cflags = [ - "-Wall", - "-Werror", - "-g3", + "//third_party/jsoncpp/include", + "//third_party/json/include", ] } @@ -66,11 +62,12 @@ config("libwm_public_config") { ohos_shared_library("libwmutil") { sources = [ "../dmserver/src/display_info.cpp", + "../dmserver/src/virtual_display_info.cpp", + "../utils/src/wm_trace.cpp", "//foundation/windowmanager/dmserver/src/display_manager_proxy.cpp", "//foundation/windowmanager/utils/src/singleton_container.cpp", "//foundation/windowmanager/wm/src/window_proxy.cpp", "//foundation/windowmanager/wmserver/src/window_manager_proxy.cpp", - "src/window_option.cpp", "src/window_property.cpp", ] @@ -85,11 +82,16 @@ ohos_shared_library("libwmutil") { public_deps = [ # RSSurface + "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_core:appexecfwk_core", + "//foundation/graphic/standard:libsurface", "//foundation/graphic/standard/rosen/modules/render_service_base:librender_service_base", "//foundation/graphic/standard/rosen/modules/render_service_client:librender_service_client", ] - external_deps = [ "ipc:ipc_core" ] + external_deps = [ + "bytrace_standard:bytrace_core", + "ipc:ipc_core", + ] part_name = "window_manager" subsystem_name = "window" @@ -110,8 +112,12 @@ ohos_shared_library("libwm") { "src/window_agent.cpp", "src/window_impl.cpp", "src/window_input_channel.cpp", + "src/window_manager.cpp", + "src/window_manager_agent.cpp", + "src/window_option.cpp", "src/window_scene.cpp", "src/window_stub.cpp", + "src/zidl/window_manager_agent_stub.cpp", ] configs = [ ":libwm_config" ] @@ -120,14 +126,15 @@ ohos_shared_library("libwm") { deps = [ "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog", - "//foundation/aafwk/standard/interfaces/innerkits/want:want", "//foundation/distributedschedule/safwk/interfaces/innerkits/safwk:system_ability_fwk", "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", - "//foundation/windowmanager/wm:libwmutil", "//utils/native/base:utils", + # TODO: fix me + # "//foundation/multimedia/image_standard/interfaces/innerkits:image_native", + # weston adapter - "//foundation/windowmanager/adapter:libwmadaptertest", + "//foundation/windowmanager/adapter:libwmadapter", # ace "//foundation/ace/ace_engine/interfaces/innerkits/ace:ace_uicontent", @@ -137,6 +144,7 @@ ohos_shared_library("libwm") { # native value # RSSurface "//foundation/ace/napi:ace_napi", + "//foundation/graphic/standard:libsurface", # vsync "//foundation/graphic/standard:libvsync_client", @@ -148,11 +156,13 @@ ohos_shared_library("libwm") { "//foundation/multimodalinput/input/frameworks/proxy:libmmi-common", # weston adapter - "//foundation/windowmanager/adapter:libwmadaptertest", + "//foundation/windowmanager/adapter:libwmadapter", + "//foundation/windowmanager/wm:libwmutil", ] external_deps = [ "aafwk_standard:ability_context_native", + "bytrace_standard:bytrace_core", "ipc:ipc_core", ] diff --git a/wm/include/input_transfer_station.h b/wm/include/input_transfer_station.h index 5c8fa146..2e1335c3 100644 --- a/wm/include/input_transfer_station.h +++ b/wm/include/input_transfer_station.h @@ -17,7 +17,6 @@ #define OHOS_INPUT_TRANSFER_STATION -#include #include #include "input_manager.h" #include "pointer_event.h" @@ -28,20 +27,23 @@ namespace OHOS { namespace Rosen { class InputEventListener; -class InputTransferStation : public RefBase { + +class InputTransferStation { DECLARE_SINGLE_INSTANCE(InputTransferStation); friend class InputEventListener; public: void AddInputWindow(const sptr& window); void RemoveInputWindow(const sptr& window); void SetInputListener(uint32_t windowId, std::shared_ptr& listener); + private: sptr GetInputChannel(uint32_t windowId); bool initInputListener_ = false; std::unordered_map> windowInputChannels_; - std::shared_ptr inputListener_; + std::shared_ptr inputListener_ = nullptr; }; -class InputEventListener: public RefBase, public MMI::IInputEventConsumer { + +class InputEventListener : public RefBase, public MMI::IInputEventConsumer { public: InputEventListener() = default; void OnInputEvent(std::shared_ptr pointerEvent) const override; diff --git a/wm/include/vsync_station.h b/wm/include/vsync_station.h index eba3a26c..4fe47207 100644 --- a/wm/include/vsync_station.h +++ b/wm/include/vsync_station.h @@ -29,7 +29,7 @@ namespace OHOS { namespace Rosen { -class VsyncStation : public RefBase { +class VsyncStation { DECLARE_SINGLE_INSTANCE_BASE(VsyncStation); using OnCallback = std::function; public: @@ -48,6 +48,8 @@ private: VsyncStation() = default; static void OnVsync(int64_t nanoTimestamp, void* client); void VsyncCallbackInner(int64_t nanoTimestamp); + std::shared_ptr mainHandler_ = nullptr; + std::mutex lock_; std::atomic_bool hasRequestedVsync_ {false}; std::map>> vsyncCallbacks_ = { {CallbackType::CALLBACK_INPUT, {}}, diff --git a/wm/include/window_adapter.h b/wm/include/window_adapter.h index 49ca5633..d92b8780 100644 --- a/wm/include/window_adapter.h +++ b/wm/include/window_adapter.h @@ -17,6 +17,7 @@ #define OHOS_WINDOW_ADAPTER_H #include +#include #include "window.h" #include "window_proxy.h" @@ -31,10 +32,9 @@ public: virtual void OnRemoteDied(const wptr& wptrDeath) override; }; -class WindowAdapter : public RefBase { - DECLARE_SINGLE_INSTANCE_BASE(WindowAdapter); +class WindowAdapter { +DECLARE_SINGLE_INSTANCE(WindowAdapter); public: - ~WindowAdapter() = default; virtual WMError CreateWindow(sptr& window, sptr& windowProperty, std::shared_ptr surfaceNode, uint32_t& windowId); virtual WMError AddWindow(sptr& windowProperty); @@ -44,10 +44,13 @@ public: virtual WMError MoveTo(uint32_t windowId, int32_t x, int32_t y); virtual WMError Resize(uint32_t windowId, uint32_t width, uint32_t height); virtual WMError RequestFocus(uint32_t windowId); + virtual WMError SetWindowFlags(uint32_t windowId, uint32_t flags); + virtual WMError SetSystemBarProperty(uint32_t windowId, WindowType type, const SystemBarProperty& property); + + virtual void RegisterFocusChangedListener(const sptr& windowManagerAgent); + virtual void UnregisterFocusChangedListener(const sptr& windowManagerAgent); virtual void ClearWindowAdapter(); -protected: - WindowAdapter() = default; private: static inline SingletonDelegator delegator; bool InitWMSProxyLocked(); diff --git a/wm/include/window_agent.h b/wm/include/window_agent.h index 31bd1ccd..60130bdb 100644 --- a/wm/include/window_agent.h +++ b/wm/include/window_agent.h @@ -30,6 +30,7 @@ public: void UpdateWindowRect(const struct Rect& rect) override; void UpdateWindowMode(WindowMode mode) override; void UpdateFocusStatus(bool focused) override; + void UpdateSystemBarProperty(const SystemBarProperty& prop) override; private: sptr window_; diff --git a/wm/include/window_impl.h b/wm/include/window_impl.h index 17766e3f..53e19417 100644 --- a/wm/include/window_impl.h +++ b/wm/include/window_impl.h @@ -21,6 +21,7 @@ #include #include "window.h" #include "input_transfer_station.h" +#include "vsync_station.h" #include "window_property.h" namespace OHOS { @@ -48,10 +49,17 @@ public: virtual WindowMode GetMode() const override; virtual const std::string& GetWindowName() const override; virtual uint32_t GetWindowId() override; + virtual uint32_t GetWindowFlags() override; + virtual SystemBarProperty GetSystemBarPropertyByType(WindowType type) override; virtual WMError SetWindowType(WindowType type) override; virtual WMError SetWindowMode(WindowMode mode) 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; - WMError Create(const std::string& parentName, const sptr& abilityToken = nullptr); + WMError Create(const std::string& parentName, + const std::shared_ptr& abilityContext = nullptr); virtual WMError Destroy() override; virtual WMError Show() override; virtual WMError Hide() override; @@ -63,15 +71,20 @@ public: virtual void RegisterLifeCycleListener(sptr& listener) override; virtual void RegisterWindowChangeListener(sptr& listener) override; + virtual void RegisterWindowSystemBarChangeListener(sptr& listener) override; void UpdateRect(const struct Rect& rect); void UpdateMode(WindowMode mode); virtual void ConsumeKeyEvent(std::shared_ptr& inputEvent) override; virtual void ConsumePointerEvent(std::shared_ptr& inputEvent) override; + virtual void RequestFrame() override; void UpdateFocusStatus(bool focused); + void UpdateSystemBarProperty(const SystemBarProperty& prop); + virtual void UpdateConfiguration(const std::shared_ptr& configuration) override; virtual WMError SetUIContent(std::shared_ptr context, - std::string& url, NativeEngine* engine, NativeValue* storage) override; + std::string& contentInfo, NativeEngine* engine, NativeValue* storage, bool isdistributed) override; + virtual const std::string& GetContentInfo() override; private: inline void NotifyAfterForeground() const @@ -88,7 +101,7 @@ private: } inline void NotifyAfterUnFocused() const { - CALL_LIFECYCLE_LISTENER(AfterUnFocused, UnFocus); + CALL_LIFECYCLE_LISTENER(AfterUnfocused, UnFocus); } inline void NotifyBeforeDestroy() const { @@ -98,6 +111,7 @@ private: } void SetDefaultOption(); // for api7 bool IsWindowValid() const; + void OnVsync(int64_t timeStamp); enum WindowState { STATE_INITIAL, @@ -108,14 +122,23 @@ private: STATE_BOTTOM = STATE_DESTROYED, }; + std::shared_ptr callback_ = + std::make_shared(VsyncStation::VsyncCallback()); static std::map>> windowMap_; + static std::map>> subWindowMap_; sptr property_; WindowState state_ { STATE_INITIAL }; sptr lifecycleListener_; sptr windowChangeListener_; + sptr systemBarChangeListener_; std::shared_ptr surfaceNode_; std::string name_; std::unique_ptr uiContent_; + std::shared_ptr abilityContext_; + const float STATUS_BAR_RATIO = 0.07; + const float NAVIGATION_BAR_RATIO = 0.07; + const float SYSTEM_ALARM_WINDOW_WIDTH_RATIO = 0.8; + const float SYSTEM_ALARM_WINDOW_HEIGHT_RATIO = 0.3; }; } } diff --git a/wm/include/window_interface.h b/wm/include/window_interface.h index 846ded86..f3f03c0f 100644 --- a/wm/include/window_interface.h +++ b/wm/include/window_interface.h @@ -30,12 +30,14 @@ public: TRANS_ID_UPDATE_WINDOW_RECT, TRANS_ID_UPDATE_WINDOW_MODE, TRANS_ID_UPDATE_FOCUS_STATUS, + TRANS_ID_UPDATE_SYSTEM_BAR_PROPERTY, }; virtual void UpdateWindowProperty(const WindowProperty& windowProperty) = 0; virtual void UpdateWindowRect(const struct Rect& rect) = 0; virtual void UpdateWindowMode(WindowMode mode) = 0; virtual void UpdateFocusStatus(bool focused) = 0; + virtual void UpdateSystemBarProperty(const SystemBarProperty& prop) = 0; }; } // namespace Rosen } // namespace OHOS diff --git a/wm/include/window_manager_agent.h b/wm/include/window_manager_agent.h new file mode 100644 index 00000000..60318d51 --- /dev/null +++ b/wm/include/window_manager_agent.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2021 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_WINDOW_MANAGER_AGENT_H +#define OHOS_WINDOW_MANAGER_AGENT_H + +#include "zidl/window_manager_agent_stub.h" + +namespace OHOS { +namespace Rosen { +class WindowManagerAgent : public WindowManagerAgentStub { +public: + WindowManagerAgent() = default; + ~WindowManagerAgent() = default; + + void UpdateFocusStatus(uint32_t windowId, const sptr& abilityToken, WindowType windowType, + int32_t displayId, bool focused) override; +}; +} // namespace Rosen +} // namespace OHOS +#endif // OHOS_WINDOW_MANAGER_AGENT_H diff --git a/wm/include/window_property.h b/wm/include/window_property.h index f8b9ed4c..b9887da3 100644 --- a/wm/include/window_property.h +++ b/wm/include/window_property.h @@ -18,6 +18,7 @@ #include #include +#include #include "parcel.h" #include "wm_common.h" @@ -41,6 +42,7 @@ public: void SetWindowId(uint32_t windowId); void SetParentId(uint32_t parentId); void SetWindowFlags(uint32_t flags); + void SetSystemBarProperty(WindowType type, const SystemBarProperty& state); Rect GetWindowRect() const; WindowType GetWindowType() const; @@ -55,10 +57,10 @@ public: uint32_t GetWindowId() const; uint32_t GetParentId() const; uint32_t GetWindowFlags() const; + const std::unordered_map& GetSystemBarProperty() const; virtual bool Marshalling(Parcel& parcel) const override; static sptr Unmarshalling(Parcel& parcel); - private: Rect windowRect_ { 0, 0, 0, 0 }; WindowType type_ { WindowType::WINDOW_TYPE_APP_MAIN_WINDOW }; @@ -73,6 +75,12 @@ private: int32_t displayId_ { 0 }; uint32_t windowId_ { 0 }; uint32_t parentId_ { 0 }; + std::unordered_map sysBarPropMap_ { + { WindowType::WINDOW_TYPE_STATUS_BAR, SystemBarProperty() }, + { WindowType::WINDOW_TYPE_NAVIGATION_BAR, SystemBarProperty() }, + }; + bool MapMarshalling(Parcel& parcel) const; + static void MapUnmarshalling(Parcel& parcel, sptr& property); }; } } diff --git a/wm/include/window_proxy.h b/wm/include/window_proxy.h index 8e1ea4a5..b7675950 100644 --- a/wm/include/window_proxy.h +++ b/wm/include/window_proxy.h @@ -31,6 +31,7 @@ public: void UpdateWindowRect(const struct Rect& rect) override; void UpdateWindowMode(WindowMode mode) override; void UpdateFocusStatus(bool focused) override; + void UpdateSystemBarProperty(const SystemBarProperty& prop) override; private: static inline BrokerDelegator delegator_; diff --git a/wm/include/zidl/window_manager_agent_interface.h b/wm/include/zidl/window_manager_agent_interface.h new file mode 100644 index 00000000..5f12fc61 --- /dev/null +++ b/wm/include/zidl/window_manager_agent_interface.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2021 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_WINDOW_MANAGER_AGENT_INTERFACE_H +#define OHOS_WINDOW_MANAGER_AGENT_INTERFACE_H + +#include +#include "wm_common.h" + +namespace OHOS { +namespace Rosen { +class IWindowManagerAgent : public IRemoteBroker { +public: + DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.IWindowManagerAgent"); + + enum { + TRANS_ID_UPDATE_FOCUS_STATUS = 1, + }; + + virtual void UpdateFocusStatus(uint32_t windowId, const sptr& abilityToken, WindowType windowType, + int32_t displayId, bool focused) = 0; +}; +} // namespace Rosen +} // namespace OHOS +#endif // OHOS_WINDOW_MANAGER_AGENT_INTERFACE_H diff --git a/wm/include/zidl/window_manager_agent_proxy.h b/wm/include/zidl/window_manager_agent_proxy.h new file mode 100644 index 00000000..4798dde4 --- /dev/null +++ b/wm/include/zidl/window_manager_agent_proxy.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2021 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_WINDOW_MANAGER_AGENT_PROXY_H +#define OHOS_WINDOW_MANAGER_AGENT_PROXY_H + +#include "window_manager_agent_interface.h" +#include "iremote_proxy.h" + +namespace OHOS { +namespace Rosen { +class WindowManagerAgentProxy : public IRemoteProxy { +public: + explicit WindowManagerAgentProxy(const sptr& impl) : IRemoteProxy(impl) {}; + + ~WindowManagerAgentProxy() {}; + + void UpdateFocusStatus(uint32_t windowId, const sptr& abilityToken, WindowType windowType, + int32_t displayId, bool focused) override; + +private: + static inline BrokerDelegator delegator_; +}; +} // namespace Rosen +} // namespace OHOS +#endif // OHOS_WINDOW_MANAGER_PROXY_H diff --git a/wm/include/zidl/window_manager_agent_stub.h b/wm/include/zidl/window_manager_agent_stub.h new file mode 100644 index 00000000..b463e671 --- /dev/null +++ b/wm/include/zidl/window_manager_agent_stub.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2021 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_WINDOW_MANAGER_AGENT_STUB_H +#define OHOS_WINDOW_MANAGER_AGENT_STUB_H + +#include "window_manager_agent_interface.h" +#include "iremote_stub.h" + +namespace OHOS { +namespace Rosen { +class WindowManagerAgentStub : public IRemoteStub { +public: + WindowManagerAgentStub() = default; + ~WindowManagerAgentStub() = default; + + virtual int OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, + MessageOption& option) override; +}; +} // namespace Rosen +} // namespace OHOS +#endif // OHOS_WINDOW_MANAGER_AGENT_STUB_H diff --git a/wm/src/input_transfer_station.cpp b/wm/src/input_transfer_station.cpp index 43adc731..8c5e4521 100644 --- a/wm/src/input_transfer_station.cpp +++ b/wm/src/input_transfer_station.cpp @@ -21,7 +21,6 @@ namespace Rosen { namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "InputTransferStation"}; } -IMPLEMENT_SINGLE_INSTANCE(InputTransferStation) void InputEventListener::OnInputEvent(std::shared_ptr keyEvent) const { WLOGFI("OnInputEvent: receive keyEvent"); @@ -30,7 +29,7 @@ void InputEventListener::OnInputEvent(std::shared_ptr keyEvent) c return; } uint32_t windowId = keyEvent->GetAgentWindowId(); - auto channel = InputTransferStation::GetInstance()->GetInputChannel(windowId); + auto channel = InputTransferStation::GetInstance().GetInputChannel(windowId); if (channel == nullptr) { WLOGE("OnInputEvent channel is nullptr"); return; @@ -56,7 +55,7 @@ void InputEventListener::OnInputEvent(std::shared_ptr pointer return; } uint32_t windowId = pointerEvent->GetAgentWindowId(); - auto channel = InputTransferStation::GetInstance()->GetInputChannel(windowId); + auto channel = InputTransferStation::GetInstance().GetInputChannel(windowId); if (channel == nullptr) { WLOGE("OnInputEvent channel is nullptr"); return; diff --git a/wm/src/vsync_station.cpp b/wm/src/vsync_station.cpp index 4cc44398..a55d17d6 100644 --- a/wm/src/vsync_station.cpp +++ b/wm/src/vsync_station.cpp @@ -23,25 +23,34 @@ namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "VsyncStation"}; } -IMPLEMENT_SINGLE_INSTANCE(VsyncStation); - void VsyncStation::RequestVsync(CallbackType type, std::shared_ptr vsyncCallback) { + std::lock_guard lock_l(lock_); auto iter = vsyncCallbacks_.find(type); if (iter == vsyncCallbacks_.end()) { WLOGFE("wrong callback type."); return; } iter->second.insert(vsyncCallback); - if (!hasRequestedVsync_) { - hasRequestedVsync_.store(true); - callback_.timestamp_ = 0; - callback_.userdata_ = this; - callback_.callback_ = OnVsync; - VsyncError ret = VsyncHelper::Current()->RequestFrameCallback(callback_); - if (ret != VSYNC_ERROR_OK) { - WLOGFE("VsyncStation::RequestNextVsync fail: %s", VsyncErrorStr(ret).c_str()); + if (mainHandler_ == nullptr) { + if (AppExecFwk::EventRunner::GetMainEventRunner() == nullptr) { + WLOGFE("can not get main event runner."); + return; } + mainHandler_ = std::make_shared(AppExecFwk::EventRunner::GetMainEventRunner()); + } + if (!hasRequestedVsync_) { + mainHandler_->PostTask([this]() { + callback_.timestamp_ = 0; + callback_.userdata_ = this; + callback_.callback_ = OnVsync; + WLOGFI("request vsync start."); + VsyncError ret = VsyncHelper::Current()->RequestFrameCallback(callback_); + if (ret != VSYNC_ERROR_OK) { + WLOGFE("VsyncStation::RequestNextVsync fail: %{public}s", VsyncErrorStr(ret).c_str()); + } + }); + hasRequestedVsync_.store(true); } } @@ -58,6 +67,7 @@ void VsyncStation::VsyncCallbackInner(int64_t timestamp) void VsyncStation::OnVsync(int64_t timestamp, void* client) { + WLOGFI("on vsync callback."); auto vsyncClient = static_cast(client); if (vsyncClient) { vsyncClient->VsyncCallbackInner(timestamp); diff --git a/wm/src/window.cpp b/wm/src/window.cpp index e1ac8e31..b054d938 100644 --- a/wm/src/window.cpp +++ b/wm/src/window.cpp @@ -14,6 +14,7 @@ */ #include "window.h" +#include "window_helper.h" #include "window_impl.h" #include "window_manager_hilog.h" @@ -23,7 +24,7 @@ namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowImpl"}; } sptr Window::Create(const std::string& windowName, sptr& option, - const sptr& abilityToken) + const std::shared_ptr& abilityContext) { if (windowName.empty()) { WLOGFE("window name is empty"); @@ -32,9 +33,14 @@ sptr Window::Create(const std::string& windowName, sptr& o if (option == nullptr) { option = new WindowOption(); } + WindowType type = option->GetWindowType(); + if (!(WindowHelper::IsAppWindow(type) || WindowHelper::IsSystemWindow(type))) { + WLOGFE("window type is invalid %{public}d", type); + return nullptr; + } option->SetWindowName(windowName); sptr windowImpl = new WindowImpl(option); - WMError error = windowImpl->Create(option->GetParentName(), abilityToken); + WMError error = windowImpl->Create(option->GetParentName(), abilityContext); if (error != WMError::WM_OK) { return nullptr; } diff --git a/wm/src/window_adapter.cpp b/wm/src/window_adapter.cpp index 81b16961..08d1f93c 100644 --- a/wm/src/window_adapter.cpp +++ b/wm/src/window_adapter.cpp @@ -25,8 +25,6 @@ namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowAdapter"}; } -IMPLEMENT_SINGLE_INSTANCE(WindowAdapter); - WMError WindowAdapter::SaveAbilityToken(const sptr& abilityToken, uint32_t windowId) { std::lock_guard lock(mutex_); @@ -108,6 +106,46 @@ WMError WindowAdapter::RequestFocus(uint32_t windowId) return windowManagerServiceProxy_->RequestFocus(windowId); } +WMError WindowAdapter::SetWindowFlags(uint32_t windowId, uint32_t flags) +{ + std::lock_guard lock(mutex_); + + if (!InitWMSProxyLocked()) { + return WMError::WM_ERROR_SAMGR; + } + return windowManagerServiceProxy_->SetWindowFlags(windowId, flags); +} + +WMError WindowAdapter::SetSystemBarProperty(uint32_t windowId, WindowType type, const SystemBarProperty& property) +{ + std::lock_guard lock(mutex_); + + if (!InitWMSProxyLocked()) { + return WMError::WM_ERROR_SAMGR; + } + return windowManagerServiceProxy_->SetSystemBarProperty(windowId, type, property); +} + +void WindowAdapter::RegisterFocusChangedListener(const sptr& windowManagerAgent) +{ + std::lock_guard lock(mutex_); + + if (!InitWMSProxyLocked()) { + return; + } + return windowManagerServiceProxy_->RegisterFocusChangedListener(windowManagerAgent); +} + +void WindowAdapter::UnregisterFocusChangedListener(const sptr& windowManagerAgent) +{ + std::lock_guard lock(mutex_); + + if (!InitWMSProxyLocked()) { + return; + } + return windowManagerServiceProxy_->UnregisterFocusChangedListener(windowManagerAgent); +} + bool WindowAdapter::InitWMSProxyLocked() { if (!windowManagerServiceProxy_) { @@ -136,8 +174,7 @@ bool WindowAdapter::InitWMSProxyLocked() return false; } if (!remoteObject->AddDeathRecipient(wmsDeath_)) { - WLOGFE("Failed to add death recipient"); - return false; + WLOGFI("Failed to add death recipient"); } } return true; @@ -164,7 +201,7 @@ void WMSDeathRecipient::OnRemoteDied(const wptr& wptrDeath) WLOGFE("object is null"); return; } - SingletonContainer::Get()->ClearWindowAdapter(); + SingletonContainer::Get().ClearWindowAdapter(); return; } } // namespace Rosen diff --git a/wm/src/window_agent.cpp b/wm/src/window_agent.cpp index 79f7a285..ad337d12 100644 --- a/wm/src/window_agent.cpp +++ b/wm/src/window_agent.cpp @@ -57,5 +57,14 @@ void WindowAgent::UpdateFocusStatus(bool focused) } window_->UpdateFocusStatus(focused); } + +void WindowAgent::UpdateSystemBarProperty(const SystemBarProperty& prop) +{ + if (window_ == nullptr) { + WLOGFE("window_ is nullptr"); + return; + } + window_->UpdateSystemBarProperty(prop); +} } // namespace Rosen } // namespace OHOS diff --git a/wm/src/window_impl.cpp b/wm/src/window_impl.cpp index 6f5d980a..b3cacc1a 100644 --- a/wm/src/window_impl.cpp +++ b/wm/src/window_impl.cpp @@ -18,6 +18,7 @@ #include "singleton_container.h" #include "window_adapter.h" #include "window_agent.h" +#include "window_helper.h" #include "window_manager_hilog.h" #ifndef _NEW_RENDERSERVER_ #include "adapter.h" @@ -30,6 +31,7 @@ namespace { } std::map>> WindowImpl::windowMap_; +std::map>> WindowImpl::subWindowMap_; WindowImpl::WindowImpl(const sptr& option) { @@ -42,7 +44,12 @@ WindowImpl::WindowImpl(const sptr& option) property_->SetTouchable(option->GetTouchable()); property_->SetDisplayId(option->GetDisplayId()); property_->SetWindowFlags(option->GetWindowFlags()); + auto& sysBarPropMap = option->GetSystemBarProperty(); + for (auto it : sysBarPropMap) { + property_->SetSystemBarProperty(it.first, it.second); + } name_ = option->GetWindowName(); + callback_->onCallback = std::bind(&WindowImpl::OnVsync, this, std::placeholders::_1); #ifdef _NEW_RENDERSERVER_ struct RSSurfaceNodeConfig rsSurfaceNodeConfig; @@ -94,13 +101,29 @@ uint32_t WindowImpl::GetWindowId() return property_->GetWindowId(); } +uint32_t WindowImpl::GetWindowFlags() +{ + return property_->GetWindowFlags(); +} + +SystemBarProperty WindowImpl::GetSystemBarPropertyByType(WindowType type) +{ + auto curProperties = property_->GetSystemBarProperty(); + return curProperties[type]; +} + WMError WindowImpl::SetWindowType(WindowType type) { + WLOGFI("window id: %{public}d, type:%{public}d", property_->GetWindowId(), static_cast(type)); if (!IsWindowValid()) { WLOGFI("window is already destroyed or not created! id: %{public}d", property_->GetWindowId()); return WMError::WM_ERROR_INVALID_WINDOW; } if (state_ == STATE_CREATED) { + if (!(WindowHelper::IsAppWindow(type) || WindowHelper::IsSystemWindow(type))) { + WLOGFE("window type is invalid %{public}d", type); + return WMError::WM_ERROR_INVALID_PARAM; + } property_->SetWindowType(type); return WMError::WM_OK; } @@ -126,8 +149,41 @@ WMError WindowImpl::SetWindowMode(WindowMode mode) return WMError::WM_OK; } +WMError WindowImpl::AddWindowFlag(WindowFlag flag) +{ + uint32_t updateFlags = property_->GetWindowFlags() | (static_cast(flag)); + return SetWindowFlags(updateFlags); +} + +WMError WindowImpl::RemoveWindowFlag(WindowFlag flag) +{ + uint32_t updateFlags = property_->GetWindowFlags() & (~(static_cast(flag))); + return SetWindowFlags(updateFlags); +} + +WMError WindowImpl::SetWindowFlags(uint32_t flags) +{ + if (!IsWindowValid()) { + WLOGFI("window is already destroyed or not created! id: %{public}d", property_->GetWindowId()); + return WMError::WM_ERROR_INVALID_WINDOW; + } + if (property_->GetWindowFlags() == flags) { + return WMError::WM_OK; + } + property_->SetWindowFlags(flags); + if (state_ == STATE_CREATED || state_ == STATE_HIDDEN) { + return WMError::WM_OK; + } + WMError ret = SingletonContainer::Get().SetWindowFlags(property_->GetWindowId(), flags); + if (ret != WMError::WM_OK) { + WLOGFE("SetWindowFlags errCode:%{public}d winId:%{public}d", + static_cast(ret), property_->GetWindowId()); + } + return ret; +} + WMError WindowImpl::SetUIContent(std::shared_ptr context, - std::string& url, NativeEngine* engine, NativeValue* storage) + std::string& contentInfo, NativeEngine* engine, NativeValue* storage, bool isdistributed) { WLOGFI("SetUIContent"); uiContent_ = Ace::UIContent::Create(context.get(), engine); @@ -135,12 +191,52 @@ WMError WindowImpl::SetUIContent(std::shared_ptr WLOGFE("fail to SetUIContent id: %{public}d", property_->GetWindowId()); return WMError::WM_ERROR_NULLPTR; } - uiContent_->Initialize(this, url, storage); + // TODO: fix me + // if (isdistributed) { + // uiContent_->Restore(this, contentInfo, storage); + // } else { + // uiContent_->Initialize(this, contentInfo, storage); + // } return WMError::WM_OK; } -WMError WindowImpl::Create(const std::string& parentName, const sptr& abilityToken) +const std::string& WindowImpl::GetContentInfo() { + WLOGFI("GetContentInfo"); + if (uiContent_ == nullptr) { + WLOGFE("fail to GetContentInfo id: %{public}d", property_->GetWindowId()); + return ""; + } + // TODO: fix me - uiContent_->GetContentInfo() + return ""; +} + +WMError WindowImpl::SetSystemBarProperty(WindowType type, const SystemBarProperty& property) +{ + if (!IsWindowValid()) { + WLOGFI("window is already destroyed or not created! id: %{public}d", property_->GetWindowId()); + return WMError::WM_ERROR_INVALID_WINDOW; + } + if (GetSystemBarPropertyByType(type) == property) { + return WMError::WM_OK; + } + property_->SetSystemBarProperty(type, property); + if (state_ == STATE_CREATED || state_ == STATE_HIDDEN) { + return WMError::WM_OK; + } + WMError ret = SingletonContainer::Get().SetSystemBarProperty(property_->GetWindowId(), + type, property); + if (ret != WMError::WM_OK) { + WLOGFE("SetSystemBarProperty errCode:%{public}d winId:%{public}d", + static_cast(ret), property_->GetWindowId()); + } + return ret; +} + +WMError WindowImpl::Create(const std::string& parentName, + const std::shared_ptr& abilityContext) +{ + WLOGFI("[Client] Window Create"); #ifdef _NEW_RENDERSERVER_ // check window name, same window names are forbidden if (windowMap_.find(name_) != windowMap_.end()) { @@ -161,7 +257,7 @@ WMError WindowImpl::Create(const std::string& parentName, const sptr window(this); sptr windowAgent(new WindowAgent(window)); uint32_t windowId = 0; - WMError ret = SingletonContainer::Get()->CreateWindow(windowAgent, property_, surfaceNode_, + WMError ret = SingletonContainer::Get().CreateWindow(windowAgent, property_, surfaceNode_, windowId); property_->SetWindowId(windowId); @@ -169,17 +265,20 @@ WMError WindowImpl::Create(const std::string& parentName, const sptr(ret)); return ret; } - if (abilityToken != nullptr) { - ret = SingletonContainer::Get()->SaveAbilityToken(abilityToken, windowId); + if (abilityContext != nullptr) { + ret = SingletonContainer::Get().SaveAbilityToken(abilityContext->GetAbilityToken(), windowId); + abilityContext_ = abilityContext; if (ret != WMError::WM_OK) { WLOGFE("SaveAbilityToken failed with errCode:%{public}d", static_cast(ret)); return ret; } } windowMap_.insert({ name_, std::pair>(windowId, this) }); + if (parentName != "") { // add to subWindowMap_ + subWindowMap_[property_->GetParentId()].push_back(this); + } state_ = STATE_CREATED; - WLOGFI("create window success with winId:%{public}d", windowId); - InputTransferStation::GetInstance()->AddInputWindow(this); + InputTransferStation::GetInstance().AddInputWindow(this); return ret; #else /* weston adapter */ @@ -191,19 +290,30 @@ WMError WindowImpl::Destroy() { NotifyBeforeDestroy(); #ifdef _NEW_RENDERSERVER_ + WLOGFI("[Client] Window %{public}d Destroy", property_->GetWindowId()); // should destroy surface here if (!IsWindowValid()) { WLOGFI("window is already destroyed or not created! id: %{public}d", property_->GetWindowId()); return WMError::WM_OK; } WLOGFI("destroy window id: %{public}d", property_->GetWindowId()); - WMError ret = SingletonContainer::Get()->DestroyWindow(property_->GetWindowId()); + WMError ret = SingletonContainer::Get().DestroyWindow(property_->GetWindowId()); windowMap_.erase(GetWindowName()); + if (subWindowMap_.count(property_->GetParentId()) > 0) { // remove from subWindowMap_ + std::vector>& subWindows = subWindowMap_.at(property_->GetParentId()); + for (auto iter = subWindows.begin(); iter < subWindows.end(); ++iter) { + if ((*iter)->GetWindowId() == GetWindowId()) { + subWindows.erase(iter); + break; + } + } + } + subWindowMap_.erase(GetWindowId()); state_ = STATE_DESTROYED; - InputTransferStation::GetInstance()->RemoveInputWindow(this); + InputTransferStation::GetInstance().RemoveInputWindow(this); return ret; #else - InputTransferStation::GetInstance()->RemoveInputWindow(this); + InputTransferStation::GetInstance().RemoveInputWindow(this); Adapter::DestroyWestonWindow(); #endif return WMError::WM_OK; @@ -212,6 +322,7 @@ WMError WindowImpl::Destroy() WMError WindowImpl::Show() { #ifdef _NEW_RENDERSERVER_ + WLOGFI("[Client] Window %{public}d Show", property_->GetWindowId()); if (!IsWindowValid()) { WLOGFI("window is already destroyed or not created! id: %{public}d", property_->GetWindowId()); return WMError::WM_ERROR_INVALID_WINDOW; @@ -221,15 +332,13 @@ WMError WindowImpl::Show() return WMError::WM_OK; } SetDefaultOption(); - WMError ret = SingletonContainer::Get()->AddWindow(property_); + WMError ret = SingletonContainer::Get().AddWindow(property_); if (ret == WMError::WM_OK || ret == WMError::WM_ERROR_DEATH_RECIPIENT) { - Rect rect = property_->GetWindowRect(); - WLOGFI("show x: %{public}d ; y: %{public}d; width: %{public}d; height: %{public}d, winId:%{public}d;", - rect.posX_, rect.posY_, rect.width_, rect.height_, property_->GetWindowId()); state_ = STATE_SHOWN; NotifyAfterForeground(); + } else { + WLOGFE("show errCode:%{public}d for winId:%{public}d", static_cast(ret), property_->GetWindowId()); } - WLOGFE("show errCode:%{public}d for winId:%{public}d", static_cast(ret), property_->GetWindowId()); return ret; #else /* weston adapter */ @@ -241,7 +350,7 @@ WMError WindowImpl::Show() } else { WLOGFE("Show error=%d", static_cast(rtn)); } - InputTransferStation::GetInstance()->AddInputWindow(this); + InputTransferStation::GetInstance().AddInputWindow(this); return rtn; #endif } @@ -249,6 +358,7 @@ WMError WindowImpl::Show() WMError WindowImpl::Hide() { #ifdef _NEW_RENDERSERVER_ + WLOGFI("[Client] Window %{public}d Hide", property_->GetWindowId()); if (!IsWindowValid()) { WLOGFI("window is already destroyed or not created! id: %{public}d", property_->GetWindowId()); return WMError::WM_ERROR_INVALID_WINDOW; @@ -257,9 +367,9 @@ WMError WindowImpl::Hide() WLOGFI("window is already hidden id: %{public}d", property_->GetWindowId()); return WMError::WM_OK; } - WMError ret = SingletonContainer::Get()->RemoveWindow(property_->GetWindowId()); - WLOGFI("hide errCode:%{public}d for winId:%{public}d", static_cast(ret), property_->GetWindowId()); + WMError ret = SingletonContainer::Get().RemoveWindow(property_->GetWindowId()); if (ret != WMError::WM_OK) { + WLOGFE("hide errCode:%{public}d for winId:%{public}d", static_cast(ret), property_->GetWindowId()); return ret; } state_ = STATE_HIDDEN; @@ -275,7 +385,7 @@ WMError WindowImpl::Hide() } else { WLOGFE("WindowImpl::Show error=%d", static_cast(rtn)); } - InputTransferStation::GetInstance()->RemoveInputWindow(this); + InputTransferStation::GetInstance().RemoveInputWindow(this); return rtn; #endif } @@ -295,7 +405,7 @@ WMError WindowImpl::MoveTo(int32_t x, int32_t y) property_->GetWindowId(), rect.posX_, rect.posY_, x, y); return WMError::WM_OK; } - return SingletonContainer::Get()->MoveTo(property_->GetWindowId(), x, y); + return SingletonContainer::Get().MoveTo(property_->GetWindowId(), x, y); #else return Adapter::MoveTo(x, y); #endif @@ -316,7 +426,7 @@ WMError WindowImpl::Resize(uint32_t width, uint32_t height) property_->GetWindowId(), rect.posX_, rect.posY_, width, height); return WMError::WM_OK; } - return SingletonContainer::Get()->Resize(property_->GetWindowId(), width, height); + return SingletonContainer::Get().Resize(property_->GetWindowId(), width, height); #else return Adapter::Resize(width, height); #endif @@ -328,12 +438,12 @@ WMError WindowImpl::RequestFocus() const WLOGFI("window is already destroyed or not created! id: %{public}d", property_->GetWindowId()); return WMError::WM_ERROR_INVALID_WINDOW; } - return SingletonContainer::Get()->RequestFocus(property_->GetWindowId()); + return SingletonContainer::Get().RequestFocus(property_->GetWindowId()); } void WindowImpl::AddInputEventListener(std::shared_ptr& inputEventListener) { - InputTransferStation::GetInstance()->SetInputListener(GetWindowId(), inputEventListener); + InputTransferStation::GetInstance().SetInputListener(GetWindowId(), inputEventListener); } void WindowImpl::RegisterLifeCycleListener(sptr& listener) @@ -346,12 +456,24 @@ void WindowImpl::RegisterWindowChangeListener(sptr& liste windowChangeListener_ = listener; } +void WindowImpl::RegisterWindowSystemBarChangeListener(sptr& listener) +{ + systemBarChangeListener_ = listener; +} void WindowImpl::UpdateRect(const struct Rect& rect) { + WLOGFI("winId:%{public}d, rect[%{public}d, %{public}d, %{public}d, %{public}d]", GetWindowId(), rect.posX_, + rect.posY_, rect.width_, rect.height_); property_->SetWindowRect(rect); if (windowChangeListener_ != nullptr) { windowChangeListener_->OnSizeChange(rect); } + if (uiContent_ != nullptr) { + Ace::ViewportConfig config; + config.SetSize(rect.width_, rect.height_); + uiContent_->UpdateViewportConfig(config); + WLOGFI("notify uiContent window size change end"); + } } void WindowImpl::UpdateMode(WindowMode mode) @@ -361,13 +483,53 @@ void WindowImpl::UpdateMode(WindowMode mode) void WindowImpl::ConsumeKeyEvent(std::shared_ptr& keyEvent) { - uiContent_->ProcessKeyEvent(keyEvent); + int32_t keyCode = keyEvent->GetKeyCode(); + int32_t keyAction = keyEvent->GetKeyAction(); + WLOGFI("ConsumeKeyEvent: enter GetKeyCode: %{public}d, action: %{public}d", keyCode, keyAction); + if (keyCode == MMI::KeyEvent::KEYCODE_BACK) { + if (keyAction != MMI::KeyEvent::KEY_ACTION_UP) { + return; + } + if (uiContent_ != nullptr && uiContent_->ProcessBackPressed()) { + WLOGI("ConsumeKeyEvent keyEvent is consumed"); + return; + } + if (abilityContext_ != nullptr) { + WLOGI("ConsumeKeyEvent ability TerminateSelf"); + abilityContext_->TerminateSelf(); + } else { + WLOGI("ConsumeKeyEvent destroy window"); + Destroy(); + } + } else { + if (uiContent_ == nullptr) { + WLOGE("ConsumeKeyEvent uiContent is nullptr"); + return; + } + if (!uiContent_->ProcessKeyEvent(keyEvent)) { + WLOGI("ConsumeKeyEvent no comsumer window exit"); + } + } } void WindowImpl::ConsumePointerEvent(std::shared_ptr& pointerEvent) { + if (uiContent_ == nullptr) { + WLOGE("ConsumePointerEvent uiContent is nullptr"); + return; + } uiContent_->ProcessPointerEvent(pointerEvent); } +void WindowImpl::OnVsync(int64_t timeStamp) +{ + uiContent_->ProcessVsyncEvent(timeStamp); +} + +void WindowImpl::RequestFrame() +{ + VsyncStation::GetInstance().RequestVsync(VsyncStation::CallbackType::CALLBACK_FRAME, callback_); +} + void WindowImpl::UpdateFocusStatus(bool focused) { WLOGFI("window focus status: %{public}d, id: %{public}d", focused, property_->GetWindowId()); @@ -378,9 +540,34 @@ void WindowImpl::UpdateFocusStatus(bool focused) } } +void WindowImpl::UpdateSystemBarProperty(const SystemBarProperty& prop) +{ + WLOGFI("winId:%{public}d, enable:%{public}d, backgroundColor:%{public}x, contentColor:%{public}x", GetWindowId(), + prop.enable_, prop.backgroundColor_, prop.contentColor_); + if (systemBarChangeListener_ != nullptr) { + systemBarChangeListener_->OnSystemBarPropertyChange(property_->GetDisplayId(), + property_->GetWindowType(), prop); + } +} + +void WindowImpl::UpdateConfiguration(const std::shared_ptr& configuration) +{ + if (uiContent_ != nullptr) { + WLOGFD("notify ace winId:%{public}d", GetWindowId()); + // TODO: fix me + // uiContent_->UpdateConfiguration(configuration); + } + if (subWindowMap_.count(GetWindowId()) == 0) { + return; + } + for (auto& subWindow : subWindowMap_.at(GetWindowId())) { + subWindow->UpdateConfiguration(configuration); + } +} + void WindowImpl::SetDefaultOption() { - auto display = DisplayManager::GetInstance()->GetDisplayById(property_->GetDisplayId()); + auto display = DisplayManager::GetInstance().GetDisplayById(property_->GetDisplayId()); if (display == nullptr) { WLOGFE("get display failed displayId:%{public}d, window id:%{public}u", property_->GetDisplayId(), property_->GetWindowId()); @@ -393,21 +580,23 @@ void WindowImpl::SetDefaultOption() Rect rect; switch (property_->GetWindowType()) { case WindowType::WINDOW_TYPE_STATUS_BAR: { - rect = { 0, 0, width, static_cast((static_cast(height) * 0.07)) }; + rect = { 0, 0, width, static_cast((static_cast(height) * STATUS_BAR_RATIO)) }; property_->SetWindowRect(rect); property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING); break; } case WindowType::WINDOW_TYPE_NAVIGATION_BAR: { - uint32_t navHeight = static_cast((static_cast(height) * 0.07)); + uint32_t navHeight = static_cast((static_cast(height) * NAVIGATION_BAR_RATIO)); rect = { 0, static_cast(height - navHeight), width, navHeight }; property_->SetWindowRect(rect); property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING); break; } case WindowType::WINDOW_TYPE_SYSTEM_ALARM_WINDOW: { - uint32_t alarmWidth = static_cast((static_cast(width) * 0.8)); - uint32_t alarmHeight = static_cast((static_cast(height) * 0.3)); + uint32_t alarmWidth = static_cast((static_cast(width) * + SYSTEM_ALARM_WINDOW_WIDTH_RATIO)); + uint32_t alarmHeight = static_cast((static_cast(height) * + SYSTEM_ALARM_WINDOW_HEIGHT_RATIO)); rect = { static_cast((width - alarmWidth) / 2), static_cast((height - alarmHeight) / 2), alarmWidth, alarmHeight }; @@ -415,10 +604,13 @@ void WindowImpl::SetDefaultOption() property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING); break; } + case WindowType::WINDOW_TYPE_DRAGGING_EFFECT: { + property_->SetWindowFlags(0); + break; + } default: break; } - } bool WindowImpl::IsWindowValid() const { diff --git a/wm/src/window_input_channel.cpp b/wm/src/window_input_channel.cpp index 952270f3..c436a5c6 100644 --- a/wm/src/window_input_channel.cpp +++ b/wm/src/window_input_channel.cpp @@ -56,8 +56,10 @@ void WindowInputChannel::HandlePointerEvent(std::shared_ptr& pointerEventPool_.clear(); } pointerEventPool_.emplace_back(pointerEvent); - VsyncStation::GetInstance()->RequestVsync(VsyncStation::CallbackType::CALLBACK_INPUT, callback_); + WLOGI("HandlePointerEvent RequestVsync"); + VsyncStation::GetInstance().RequestVsync(VsyncStation::CallbackType::CALLBACK_INPUT, callback_); } else { + WLOGI("HandlePointerEvent cosume non-move"); window_->ConsumePointerEvent(pointerEvent); pointerEvent->MarkProcessed(); } @@ -70,7 +72,8 @@ void WindowInputChannel::OnVsync(int64_t timeStamp) return; } auto pointerEvent = pointerEventPool_.back(); - HandlePointerEvent(pointerEvent); + WLOGI("HandlePointerEvent onVsync consume move"); + window_->ConsumePointerEvent(pointerEvent); pointerEvent->MarkProcessed(); pointerEventPool_.clear(); } diff --git a/wm/src/window_manager.cpp b/wm/src/window_manager.cpp new file mode 100644 index 00000000..45713eb6 --- /dev/null +++ b/wm/src/window_manager.cpp @@ -0,0 +1,116 @@ +/* + * Copyright (c) 2021 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 "foundation/windowmanager/interfaces/innerkits/wm/window_manager.h" +#include + +#include "window_adapter.h" +#include "window_manager_agent.h" +#include "window_manager_hilog.h" + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowManager"}; +} + +class WindowManager::Impl { +public: + void NotifyFocused(uint32_t windowId, const sptr& abilityToken, + WindowType windowType, int32_t displayId) const; + void NotifyUnfocused(uint32_t windowId, const sptr& abilityToken, + WindowType windowType, int32_t displayId) const; + + static inline SingletonDelegator delegator_; + + std::mutex mutex_; + std::vector> focusChangedListeners_; + sptr focusChangedListenerAgent_; +}; + +void WindowManager::Impl::NotifyFocused(uint32_t windowId, const sptr& abilityToken, + WindowType windowType, int32_t displayId) const +{ + WLOGFI("NotifyFocused [%{public}d; %{public}p; %{public}d; %{public}d]", windowId, abilityToken.GetRefPtr(), + static_cast(windowType), displayId); + for (auto& listener : focusChangedListeners_) { + listener->OnFocused(windowId, abilityToken, windowType, displayId); + } +} + +void WindowManager::Impl::NotifyUnfocused(uint32_t windowId, const sptr& abilityToken, + WindowType windowType, int32_t displayId) const +{ + WLOGFI("NotifyUnfocused [%{public}d; %{public}p; %{public}d; %{public}d]", windowId, abilityToken.GetRefPtr(), + static_cast(windowType), displayId); + for (auto& listener : focusChangedListeners_) { + listener->OnUnfocused(windowId, abilityToken, windowType, displayId); + } +} + +WindowManager::WindowManager() : pImpl_(std::make_unique()) +{ +} + +WindowManager::~WindowManager() +{ +} + +void WindowManager::RegisterFocusChangedListener(const sptr& listener) +{ + if (listener == nullptr) { + WLOGFE("listener could not be null"); + return; + } + + std::lock_guard lock(pImpl_->mutex_); + pImpl_->focusChangedListeners_.push_back(listener); + if (pImpl_->focusChangedListenerAgent_ == nullptr) { + pImpl_->focusChangedListenerAgent_ = new WindowManagerAgent(); + SingletonContainer::Get().RegisterFocusChangedListener(pImpl_->focusChangedListenerAgent_); + } +} + +void WindowManager::UnregisterFocusChangedListener(const sptr& listener) +{ + if (listener == nullptr) { + WLOGFE("listener could not be null"); + return; + } + + std::lock_guard lock(pImpl_->mutex_); + auto iter = std::find(pImpl_->focusChangedListeners_.begin(), pImpl_->focusChangedListeners_.end(), listener); + if (iter == pImpl_->focusChangedListeners_.end()) { + WLOGFE("could not find this listener"); + return; + } + pImpl_->focusChangedListeners_.erase(iter); + if (pImpl_->focusChangedListeners_.empty() && pImpl_->focusChangedListenerAgent_ != nullptr) { + SingletonContainer::Get().UnregisterFocusChangedListener(pImpl_->focusChangedListenerAgent_); + } +} + +void WindowManager::UpdateFocusStatus(uint32_t windowId, const sptr& abilityToken, WindowType windowType, + int32_t displayId, bool focused) const +{ + WLOGFI("window focus status: %{public}d, id: %{public}d", focused, windowId); + if (focused) { + pImpl_->NotifyFocused(windowId, abilityToken, windowType, displayId); + } else { + pImpl_->NotifyUnfocused(windowId, abilityToken, windowType, displayId); + } +} +} // namespace Rosen +} // namespace OHOS \ No newline at end of file diff --git a/wm/src/window_manager_agent.cpp b/wm/src/window_manager_agent.cpp new file mode 100644 index 00000000..83c13348 --- /dev/null +++ b/wm/src/window_manager_agent.cpp @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2021 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_manager_agent.h" +#include "foundation/windowmanager/interfaces/innerkits/wm/window_manager.h" +#include "singleton_container.h" + +namespace OHOS { +namespace Rosen { +void WindowManagerAgent::UpdateFocusStatus(uint32_t windowId, const sptr& abilityToken, + WindowType windowType, int32_t displayId, bool focused) +{ + SingletonContainer::Get().UpdateFocusStatus(windowId, abilityToken, windowType, displayId, focused); +} +} // namespace Rosen +} // namespace OHOS diff --git a/wm/src/window_option.cpp b/wm/src/window_option.cpp index d116dd97..1b7e4dc7 100644 --- a/wm/src/window_option.cpp +++ b/wm/src/window_option.cpp @@ -77,6 +77,13 @@ void WindowOption::SetWindowFlags(uint32_t flags) flags_ = flags; } +void WindowOption::SetSystemBarProperty(WindowType type, const SystemBarProperty& property) +{ + if (type == WindowType::WINDOW_TYPE_STATUS_BAR || type == WindowType::WINDOW_TYPE_NAVIGATION_BAR) { + sysBarPropMap_[type] = property; + } +} + Rect WindowOption::GetWindowRect() const { return windowRect_; @@ -121,6 +128,11 @@ uint32_t WindowOption::GetWindowFlags() const { return flags_; } + +const std::unordered_map& WindowOption::GetSystemBarProperty() const +{ + return sysBarPropMap_; +} } } diff --git a/wm/src/window_property.cpp b/wm/src/window_property.cpp index 3ee405db..6b22e7cb 100644 --- a/wm/src/window_property.cpp +++ b/wm/src/window_property.cpp @@ -72,6 +72,13 @@ void WindowProperty::SetWindowFlags(uint32_t flags) flags_ = flags; } +void WindowProperty::SetSystemBarProperty(WindowType type, const SystemBarProperty& property) +{ + if (type == WindowType::WINDOW_TYPE_STATUS_BAR || type == WindowType::WINDOW_TYPE_NAVIGATION_BAR) { + sysBarPropMap_[type] = property; + } +} + Rect WindowProperty::GetWindowRect() const { return windowRect_; @@ -127,6 +134,11 @@ uint32_t WindowProperty::GetWindowFlags() const return flags_; } +const std::unordered_map& WindowProperty::GetSystemBarProperty() const +{ + return sysBarPropMap_; +} + // TODO void WindowProperty::SetWindowId(uint32_t windowId) { @@ -145,6 +157,37 @@ uint32_t WindowProperty::GetParentId() const return parentId_; } +bool WindowProperty::MapMarshalling(Parcel& parcel) const +{ + auto size = sysBarPropMap_.size(); + if (!parcel.WriteUint32(static_cast(size))) { + return false; + } + for (auto it : sysBarPropMap_) { + // write key(type) + if (!parcel.WriteUint32(static_cast(it.first))) { + return false; + } + // write val(UIState) + if (!(parcel.WriteBool(it.second.enable_) && parcel.WriteUint32(it.second.backgroundColor_) && + parcel.WriteUint32(it.second.contentColor_))) { + return false; + } + } + return true; +} + +void WindowProperty::MapUnmarshalling(Parcel& parcel, sptr& property) +{ + std::unordered_map sysBarPropMap; + uint32_t size = parcel.ReadUint32(); + for (uint32_t i = 0; i < size; i++) { + WindowType type = static_cast(parcel.ReadUint32()); + SystemBarProperty prop = { parcel.ReadBool(), parcel.ReadUint32(), parcel.ReadUint32() }; + property->SetSystemBarProperty(type, prop); + } +} + bool WindowProperty::Marshalling(Parcel& parcel) const { // write windowRect_ @@ -212,6 +255,11 @@ bool WindowProperty::Marshalling(Parcel& parcel) const if (!parcel.WriteUint32(parentId_)) { return false; } + + // write sysUIStateMap_ + if (!MapMarshalling(parcel)) { + return false; + } return true; } @@ -232,6 +280,7 @@ sptr WindowProperty::Unmarshalling(Parcel& parcel) property->SetDisplayId(parcel.ReadInt32()); property->SetWindowId(parcel.ReadUint32()); property->SetParentId(parcel.ReadUint32()); + MapUnmarshalling(parcel, property); return property; } } diff --git a/wm/src/window_proxy.cpp b/wm/src/window_proxy.cpp index 7334d6bb..fe12a88f 100644 --- a/wm/src/window_proxy.cpp +++ b/wm/src/window_proxy.cpp @@ -53,6 +53,26 @@ void WindowProxy::UpdateWindowRect(const struct Rect& rect) return; } +void WindowProxy::UpdateSystemBarProperty(const SystemBarProperty& prop) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("WriteInterfaceToken failed"); + return; + } + if (!(data.WriteBool(prop.enable_) && data.WriteUint32(prop.backgroundColor_) && + data.WriteUint32(prop.contentColor_))) { + WLOGFE("Write property failed"); + return; + } + if (Remote()->SendRequest(TRANS_ID_UPDATE_SYSTEM_BAR_PROPERTY, data, reply, option) != ERR_NONE) { + WLOGFE("SendRequest failed"); + } + return; +} + void WindowProxy::UpdateWindowMode(WindowMode mode) { MessageParcel data; diff --git a/wm/src/window_scene.cpp b/wm/src/window_scene.cpp index 3281d774..5215694f 100644 --- a/wm/src/window_scene.cpp +++ b/wm/src/window_scene.cpp @@ -39,11 +39,13 @@ WindowScene::~WindowScene() } WMError WindowScene::Init(int32_t displayId, std::shared_ptr& abilityContext, - sptr& listener) + sptr& listener, sptr option) { displayId_ = displayId; abilityContext_ = abilityContext; - sptr option = new WindowOption(); + if (option == nullptr) { + option = new WindowOption(); + } option->SetDisplayId(displayId); #ifndef _NEW_RENDERSERVER_ @@ -51,14 +53,8 @@ WMError WindowScene::Init(int32_t displayId, std::shared_ptr()->CreateWindow( - MAIN_WINDOW_ID + std::to_string(count++), option, abilityContext_->GetAbilityToken()); - } else { - mainWindow_ = SingletonContainer::Get()->CreateWindow( - MAIN_WINDOW_ID + std::to_string(count++), option); - } - + mainWindow_ = SingletonContainer::Get().CreateWindow( + MAIN_WINDOW_ID + std::to_string(count++), option, abilityContext_); #endif if (mainWindow_ == nullptr) { return WMError::WM_ERROR_NULLPTR; @@ -76,7 +72,7 @@ sptr WindowScene::CreateWindow(const std::string& windowName, sptrSetParentName(mainWindow_->GetWindowName()); - return SingletonContainer::Get()->CreateWindow(windowName, option); + return SingletonContainer::Get().CreateWindow(windowName, option); #else /* weston adapter */ if (!Adapter::CreateWestonWindow(option)) { @@ -116,6 +112,14 @@ WMError WindowScene::GoBackground() const return mainWindow_->Hide(); } +WMError WindowScene::SetSystemBarProperty(WindowType type, const SystemBarProperty& property) const +{ + if (mainWindow_ == nullptr) { + return WMError::WM_ERROR_NULLPTR; + } + return mainWindow_->SetSystemBarProperty(type, property); +} + WMError WindowScene::RequestFocus() const { if (mainWindow_ == nullptr) { @@ -123,5 +127,20 @@ WMError WindowScene::RequestFocus() const } return mainWindow_->RequestFocus(); } + +void WindowScene::UpdateConfiguration(const std::shared_ptr& configuration) +{ + WLOGFI("notify mainWindow winId:%{public}d", mainWindow_->GetWindowId()); + mainWindow_->UpdateConfiguration(configuration); +} + +const std::string& WindowScene::GetContentInfo() const +{ + if (mainWindow_ == nullptr) { + WLOGFE("WindowScene::GetContentInfo mainWindow_ is null"); + return ""; + } + return mainWindow_->GetContentInfo(); +} } // namespace Rosen } // namespace OHOS diff --git a/wm/src/window_stub.cpp b/wm/src/window_stub.cpp index e7640726..c0b6485f 100644 --- a/wm/src/window_stub.cpp +++ b/wm/src/window_stub.cpp @@ -26,7 +26,6 @@ namespace { int WindowStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - WLOGFI("WindowStub::OnRemoteRequest code is %{public}d", code); if (data.ReadInterfaceToken() != GetDescriptor()) { WLOGFE("InterfaceToken check failed"); return -1; @@ -50,6 +49,11 @@ int WindowStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParce UpdateFocusStatus(focused); break; } + case TRANS_ID_UPDATE_SYSTEM_BAR_PROPERTY: { + SystemBarProperty property = { data.ReadBool(), data.ReadUint32(), data.ReadUint32() }; + UpdateSystemBarProperty(property); + break; + } default: break; } diff --git a/wm/src/zidl/window_manager_agent_proxy.cpp b/wm/src/zidl/window_manager_agent_proxy.cpp new file mode 100644 index 00000000..eea58411 --- /dev/null +++ b/wm/src/zidl/window_manager_agent_proxy.cpp @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2021 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 "zidl/window_manager_agent_proxy.h" +#include +#include "window_manager_hilog.h" + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowManagerAgentProxy"}; +} + +void WindowManagerAgentProxy::UpdateFocusStatus(uint32_t windowId, const sptr& abilityToken, + WindowType windowType, int32_t displayId, bool focused) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_ASYNC); + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("WriteInterfaceToken failed"); + return; + } + + if (!data.WriteUint32(windowId)) { + WLOGFE("Write windowId failed"); + return; + } + + if (!data.WriteRemoteObject(abilityToken)) { + WLOGFI("Write abilityToken failed"); + } + + if (!data.WriteUint32(static_cast(windowType))) { + WLOGFE("Write windowType failed"); + return; + } + + if (!data.WriteInt32(displayId)) { + WLOGFE("Write displayId failed"); + return; + } + + if (!data.WriteBool(focused)) { + WLOGFE("Write Focus failed"); + return; + } + + if (Remote()->SendRequest(TRANS_ID_UPDATE_FOCUS_STATUS, 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 new file mode 100644 index 00000000..9ac69ed9 --- /dev/null +++ b/wm/src/zidl/window_manager_agent_stub.cpp @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2021 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 "zidl/window_manager_agent_stub.h" +#include "ipc_skeleton.h" +#include "window_manager_hilog.h" +#include "wm_common.h" + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowManagerAgentStub"}; +} + +int WindowManagerAgentStub::OnRemoteRequest(uint32_t code, MessageParcel& data, + MessageParcel& reply, MessageOption& option) +{ + WLOGFI("WindowManagerAgentStub::OnRemoteRequest code is %{public}d", code); + if (data.ReadInterfaceToken() != GetDescriptor()) { + WLOGFE("InterfaceToken check failed"); + return -1; + } + switch (code) { + case TRANS_ID_UPDATE_FOCUS_STATUS: { + uint32_t windowId = data.ReadUint32(); + sptr abilityToken = data.ReadRemoteObject(); + WindowType windowType = static_cast(data.ReadUint32()); + int32_t displayId = data.ReadInt32(); + bool focused = data.ReadBool(); + UpdateFocusStatus(windowId, abilityToken, windowType, displayId, focused); + break; + } + default: + break; + } + return 0; +} +} // namespace Rosen +} // namespace OHOS diff --git a/wmserver/BUILD.gn b/wmserver/BUILD.gn index 6db37137..e38eb625 100644 --- a/wmserver/BUILD.gn +++ b/wmserver/BUILD.gn @@ -27,23 +27,18 @@ config("libwms_config") { "//foundation/windowmanager/dm/include", "//foundation/windowmanager/dmserver/include", ] - - cflags = [ - "-Wall", - "-Werror", - "-g3", - ] } ohos_shared_library("libwms") { sources = [ + "../dmserver/src/abstract_display.cpp", + "../dmserver/src/abstract_display_manager.cpp", "../dmserver/src/display_manager_service.cpp", "../dmserver/src/display_manager_service_inner.cpp", "../dmserver/src/display_manager_stub.cpp", "../dmserver/src/display_node_control.cpp", - "../dmserver/src/display_screen.cpp", - "../dmserver/src/display_screen_manager.cpp", "../dmserver/src/screen.cpp", + "../wm/src/zidl/window_manager_agent_proxy.cpp", "src/input_window_monitor.cpp", "src/window_controller.cpp", "src/window_layout_policy.cpp", @@ -61,24 +56,28 @@ ohos_shared_library("libwms") { "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog", "//foundation/distributedschedule/safwk/interfaces/innerkits/safwk:system_ability_fwk", "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", - "//foundation/windowmanager/wm:libwmutil", "//utils/native/base:utils", - - # RSSurface - "//foundation/graphic/standard/rosen/modules/render_service_base:librender_service_base", - "//foundation/graphic/standard/rosen/modules/render_service_client:librender_service_client", - - # IMS - "//foundation/multimodalinput/input/frameworks/proxy:libmmi-client", ] public_deps = [ # ability manager "//foundation/aafwk/standard/interfaces/innerkits/ability_manager:ability_manager", "//foundation/aafwk/standard/interfaces/innerkits/want:want", + "//foundation/graphic/standard:libsurface", + "//foundation/graphic/standard/rosen/modules/render_service_base:librender_service_base", + + # RSSurface + "//foundation/graphic/standard/rosen/modules/render_service_client:librender_service_client", + + # IMS + "//foundation/multimodalinput/input/frameworks/proxy:libmmi-client", + "//foundation/windowmanager/wm:libwmutil", ] - external_deps = [ "ipc:ipc_core" ] + external_deps = [ + "bytrace_standard:bytrace_core", + "ipc:ipc_core", + ] part_name = "window_manager" subsystem_name = "window" diff --git a/wmserver/include/input_window_monitor.h b/wmserver/include/input_window_monitor.h index 9ea20b1f..15fa9d61 100644 --- a/wmserver/include/input_window_monitor.h +++ b/wmserver/include/input_window_monitor.h @@ -34,7 +34,7 @@ private: sptr windowRoot_; std::vector physicalDisplays_; std::vector logicalDisplays_; - std::unordered_set windowTypeSkipped_ { WindowType::WINDOW_TYPE_POINTER}; + std::unordered_set windowTypeSkipped_ { WindowType::WINDOW_TYPE_POINTER }; const int INVALID_DISPLAY_ID = -1; const int INVALID_WINDOW_ID = -1; void TraverseWindowNodes(const std::vector>& windowNodes, diff --git a/wmserver/include/window_controller.h b/wmserver/include/window_controller.h index 043cad3d..f54f7c07 100644 --- a/wmserver/include/window_controller.h +++ b/wmserver/include/window_controller.h @@ -17,6 +17,7 @@ #define OHOS_ROSEN_WINDOW_CONTROLLER_H #include +#include "zidl/window_manager_agent_interface.h" #include "window_root.h" namespace OHOS { @@ -35,10 +36,16 @@ public: WMError Resize(uint32_t windowId, uint32_t width, uint32_t height); WMError RequestFocus(uint32_t windowId); WMError SaveAbilityToken(const sptr& abilityToken, uint32_t windowId); + WMError SetWindowMode(uint32_t windowId, WindowMode mode); + WMError SetWindowType(uint32_t windowId, WindowType type); + WMError SetWindowFlags(uint32_t windowId, uint32_t flags); + WMError SetSystemBarProperty(uint32_t windowId, WindowType type, const SystemBarProperty& property); + + void RegisterFocusChangedListener(const sptr& windowManagerAgent); + void UnregisterFocusChangedListener(const sptr& windowManagerAgent); private: uint32_t GenWindowId(); - WMError LayoutWindowNodeTrees(); sptr windowRoot_; std::atomic windowId_ { 0 }; diff --git a/wmserver/include/window_layout_policy.h b/wmserver/include/window_layout_policy.h index 350b8c0e..95788185 100644 --- a/wmserver/include/window_layout_policy.h +++ b/wmserver/include/window_layout_policy.h @@ -28,25 +28,30 @@ namespace Rosen { class WindowLayoutPolicy : public RefBase { public: WindowLayoutPolicy() = default; + WindowLayoutPolicy(const sptr& belowAppNode, + const sptr& appNode, const sptr& aboveAppNode); ~WindowLayoutPolicy() = default; - WMError UpdateDisplayInfo(const Rect& displayRect); - WMError LayoutWindow(sptr& node); + void UpdateDisplayInfo(const Rect& displayRect); + void AddWindowNode(sptr& node); + void RemoveWindowNode(sptr& node); + void UpdateWindowNode(sptr& node); private: Rect displayRect_ = {0, 0, 0, 0}; + sptr belowAppWindowNode_ = new WindowNode(); + sptr appWindowNode_ = new WindowNode(); + sptr aboveAppWindowNode_ = new WindowNode(); Rect limitRect_ = {0, 0, 0, 0}; - std::map> aviodNodes_; - const std::set aviodTypes_ { + std::map> avoidNodes_; + const std::set avoidTypes_ { WindowType::WINDOW_TYPE_STATUS_BAR, WindowType::WINDOW_TYPE_NAVIGATION_BAR, }; void UpdateLimitRect(const sptr& node); void RecordAvoidRect(const sptr& node); - bool UpdateLayoutRects(sptr& node); - bool IsNeedAvoidNode(const sptr& node); - bool IsFullScreenNode(const sptr& node); - bool IsParentLimitNode(const sptr& node); - bool IsRectChanged(const Rect& l, const Rect& r); + void UpdateLayoutRect(sptr& node); + void LayoutWindowTree(); + void LayoutWindowNode(sptr& node); }; } } diff --git a/wmserver/include/window_manager_interface.h b/wmserver/include/window_manager_interface.h index e1d9d4d4..4285e240 100644 --- a/wmserver/include/window_manager_interface.h +++ b/wmserver/include/window_manager_interface.h @@ -20,6 +20,7 @@ #include #include "window_property.h" #include "window_interface.h" +#include "zidl/window_manager_agent_interface.h" namespace OHOS { namespace Rosen { @@ -35,7 +36,13 @@ public: TRANS_ID_MOVE, TRANS_ID_RESIZE, TRANS_ID_REQUEST_FOCUS, + TRANS_ID_UPDATE_TYPE, + TRANS_ID_UPDATE_MODE, + TRANS_ID_UPDATE_FLAGS, + TRANS_ID_UPDATE_SYSTEM_BAR_PROPERTY, TRANS_ID_SEND_ABILITY_TOKEN, + TRANS_ID_REGISTER_FOCUS_CHANGED_LISTENER, + TRANS_ID_UNREGISTER_FOCUS_CHANGED_LISTENER, }; virtual WMError CreateWindow(sptr& window, sptr& property, const std::shared_ptr& surfaceNode, uint32_t& windowId) = 0; @@ -45,7 +52,14 @@ public: virtual WMError MoveTo(uint32_t windowId, int32_t x, int32_t y) = 0; virtual WMError Resize(uint32_t windowId, uint32_t width, uint32_t height) = 0; virtual WMError RequestFocus(uint32_t windowId) = 0; + virtual WMError SetWindowMode(uint32_t windowId, WindowMode mode) = 0; + virtual WMError SetWindowType(uint32_t windowId, WindowType type) = 0; + virtual WMError SetWindowFlags(uint32_t windowId, uint32_t flags) = 0; + virtual WMError SetSystemBarProperty(uint32_t windowId, WindowType type, const SystemBarProperty& prop) = 0; virtual WMError SaveAbilityToken(const sptr& abilityToken, uint32_t windowId) = 0; + + virtual void RegisterFocusChangedListener(const sptr& windowManagerAgent) = 0; + virtual void UnregisterFocusChangedListener(const sptr& windowManagerAgent) = 0; }; } } diff --git a/wmserver/include/window_manager_proxy.h b/wmserver/include/window_manager_proxy.h index 60e89fd3..fbca792c 100644 --- a/wmserver/include/window_manager_proxy.h +++ b/wmserver/include/window_manager_proxy.h @@ -36,6 +36,13 @@ public: WMError Resize(uint32_t windowId, uint32_t width, uint32_t height) override; WMError RequestFocus(uint32_t windowId) override; WMError SaveAbilityToken(const sptr& abilityToken, uint32_t windowId) override; + WMError SetWindowMode(uint32_t windowId, WindowMode mode) override; + WMError SetWindowType(uint32_t windowId, WindowType type) override; + WMError SetWindowFlags(uint32_t windowId, uint32_t flags) override; + WMError SetSystemBarProperty(uint32_t windowId, WindowType type, const SystemBarProperty& prop) override; + + void RegisterFocusChangedListener(const sptr& windowManagerAgent) override; + void UnregisterFocusChangedListener(const sptr& windowManagerAgent) override; private: static inline BrokerDelegator delegator_; diff --git a/wmserver/include/window_manager_service.h b/wmserver/include/window_manager_service.h index b722b164..9d7f1d23 100644 --- a/wmserver/include/window_manager_service.h +++ b/wmserver/include/window_manager_service.h @@ -36,7 +36,6 @@ DECLARE_SYSTEM_ABILITY(WindowManagerService); DECLARE_SINGLE_INSTANCE_BASE(WindowManagerService); public: - ~WindowManagerService() = default; void OnStart() override; void OnStop() override; @@ -49,14 +48,26 @@ public: WMError Resize(uint32_t windowId, uint32_t width, uint32_t height) override; WMError RequestFocus(uint32_t windowId) override; WMError SaveAbilityToken(const sptr& abilityToken, uint32_t windowId) override; -private: + WMError SetWindowMode(uint32_t windowId, WindowMode mode) override; + WMError SetWindowType(uint32_t windowId, WindowType type) override; + WMError SetWindowFlags(uint32_t windowId, uint32_t flags) override; + WMError SetSystemBarProperty(uint32_t windowId, WindowType type, const SystemBarProperty& prop) override; + + void RegisterFocusChangedListener(const sptr& windowManagerAgent) override; + void UnregisterFocusChangedListener(const sptr& windowManagerAgent) override; + +protected: WindowManagerService(); + virtual ~WindowManagerService() = default; + +private: bool Init(); static inline SingletonDelegator delegator; - std::mutex mutex_; + std::recursive_mutex mutex_; sptr windowRoot_; sptr windowController_; sptr inputWindowMonitor_; + const int WAITING_RS_TIME = 10; }; } } diff --git a/wmserver/include/window_node.h b/wmserver/include/window_node.h index 0684ebe7..b1f8fd8e 100644 --- a/wmserver/include/window_node.h +++ b/wmserver/include/window_node.h @@ -24,13 +24,6 @@ namespace OHOS { namespace Rosen { -struct LayoutRects { - Rect displayRect_ = { 0, 0, 0, 0 }; - Rect parentRect_ = { 0, 0, 0, 0 }; - Rect limitRect_ = { 0, 0, 0, 0 }; - Rect rect_ = { 0, 0, 0, 0 }; -}; - class WindowNode : public RefBase { public: WindowNode(const sptr& property, const sptr& window, @@ -48,19 +41,21 @@ public: ~WindowNode() = default; void SetDisplayId(int32_t displayId); - void UpdateLayoutRects(const LayoutRects& rects); + void SetLayoutRect(const Rect& rect); void SetWindowProperty(const sptr& property); + void SetSystemBarProperty(WindowType type, const SystemBarProperty& property); const sptr& GetWindowToken() const; uint32_t GetWindowId() const; int32_t GetDisplayId() const; - const LayoutRects& GetLayoutRects() const; + const Rect& GetLayoutRect() const; WindowType GetWindowType() const; WindowMode GetWindowMode() const; uint32_t GetWindowFlags() const; const sptr& GetWindowProperty() const; int32_t GetCallingPid() const; int32_t GetCallingUid() const; + const std::unordered_map& GetSystemBarProperty() const; sptr parent_; std::vector> children_; @@ -73,7 +68,7 @@ public: private: sptr property_; sptr windowToken_; - LayoutRects layoutRects_; + Rect layoutRect_ { 0, 0, 0, 0 }; int32_t callingPid_; int32_t callingUid_; }; diff --git a/wmserver/include/window_node_container.h b/wmserver/include/window_node_container.h index 7c8f77e8..04430981 100644 --- a/wmserver/include/window_node_container.h +++ b/wmserver/include/window_node_container.h @@ -24,23 +24,16 @@ namespace OHOS { namespace Rosen { +using UpdateFocusStatusFunc = std::function& abilityToken, + WindowType windowType, int32_t displayId, bool focused)>; + class WindowNodeContainer : public RefBase { public: - WindowNodeContainer(uint64_t screenId, uint32_t width, uint32_t height) : screenId_(screenId) - { - struct RSDisplayNodeConfig config = {screenId}; - displayNode_ = RSDisplayNode::Create(config); - displayRect_ = { - .posX_ = 0, - .posY_ = 0, - .width_ = width, - .height_ = height - }; - } - + WindowNodeContainer(uint64_t screenId, uint32_t width, uint32_t height, UpdateFocusStatusFunc callback); ~WindowNodeContainer(); WMError AddWindowNode(sptr& node, sptr& parentNode); WMError RemoveWindowNode(sptr& node); + WMError UpdateWindowNode(sptr& node); WMError DestroyWindowNode(sptr& node, std::vector& windowIds); const std::vector& Destroy(); void AssignZOrder(); @@ -48,9 +41,10 @@ public: uint32_t GetFocusWindow() const; WMError MinimizeOtherFullScreenAbility(); // adapt to api7 void TraverseContainer(std::vector>& windowNodes); - WMError LayoutWindowNodes(); uint64_t GetScreenId() const; Rect GetDisplayRect() const; + sptr GetTopImmersiveNode() const; + void NotifySystemBarIfChanged(); private: void AssignZOrder(sptr& node); @@ -62,17 +56,27 @@ private: void UpdateWindowTree(sptr& node); bool UpdateRSTree(sptr& node, bool isAdd); sptr zorderPolicy_ = new WindowZorderPolicy(); - sptr layoutPolicy_ = new WindowLayoutPolicy(); sptr belowAppWindowNode_ = new WindowNode(); sptr appWindowNode_ = new WindowNode(); sptr aboveAppWindowNode_ = new WindowNode(); + sptr layoutPolicy_ = + new WindowLayoutPolicy(belowAppWindowNode_, appWindowNode_, aboveAppWindowNode_); std::shared_ptr displayNode_; std::vector removedIds_; + std::unordered_map> sysBarNodeMap_ { + { WindowType::WINDOW_TYPE_STATUS_BAR, nullptr }, + { WindowType::WINDOW_TYPE_NAVIGATION_BAR, nullptr }, + }; + std::unordered_map sysBarPropMap_ { + { WindowType::WINDOW_TYPE_STATUS_BAR, SystemBarProperty() }, + { WindowType::WINDOW_TYPE_NAVIGATION_BAR, SystemBarProperty() }, + }; uint32_t zOrder_ { 0 }; - uint64_t screenId_ = 0; uint32_t focusedWindow_ { 0 }; Rect displayRect_; - WMError LayoutWindowNode(sptr& node); + uint64_t screenId_ = 0; + UpdateFocusStatusFunc focusStatusCallBack_; + void DumpScreenWindowTree(); }; } } diff --git a/wmserver/include/window_root.h b/wmserver/include/window_root.h index 9a862346..136537fb 100644 --- a/wmserver/include/window_root.h +++ b/wmserver/include/window_root.h @@ -17,6 +17,7 @@ #include #include +#include "zidl/window_manager_agent_interface.h" #include "window_node_container.h" namespace OHOS { @@ -28,12 +29,24 @@ public: virtual void OnRemoteDied(const wptr& wptrDeath) override; +private: + std::function&)> callback_; +}; + +class WindowManagerAgentDeathRecipient : public IRemoteObject::DeathRecipient { +public: + WindowManagerAgentDeathRecipient(std::function&)> callback) : callback_(callback) {} + ~WindowManagerAgentDeathRecipient() = default; + + virtual void OnRemoteDied(const wptr& wptrDeath) override; + +private: std::function&)> callback_; }; class WindowRoot : public RefBase { public: - WindowRoot() = default; + WindowRoot(std::recursive_mutex& mutex) : mutex_(mutex) {} ~WindowRoot() = default; sptr GetOrCreateWindowNodeContainer(int32_t displayId); @@ -44,21 +57,33 @@ public: WMError AddWindowNode(uint32_t parentId, sptr& node); WMError RemoveWindowNode(uint32_t windowId); WMError DestroyWindow(uint32_t windowId); - const std::map>& GetWindowNodeContainerMap() const; + WMError UpdateWindowNode(uint32_t windowId); WMError RequestFocus(uint32_t windowId); WMError MinimizeOtherFullScreenAbility(sptr& node); + void RegisterFocusChangedListener(const sptr& windowManagerAgent); + void UnregisterFocusChangedListener(const sptr& windowManagerAgent); + private: void ClearWindow(const sptr& remoteObject); + void ClearWindowManagerAgent(const sptr& remoteObject); + void UnregisterFocusChangedListener(const sptr& windowManagerAgent); + void UpdateFocusStatus(uint32_t windowId, const sptr& abilityToken, WindowType windowType, + int32_t displayId, bool focused); WMError DestroyWindowInner(sptr& node); + std::recursive_mutex& mutex_; std::map> windowNodeContainerMap_; std::map> windowNodeMap_; std::map, uint32_t> windowIdMap_; + std::vector> focusChangedListenerAgents_; + sptr windowDeath_ = new WindowDeathRecipient(std::bind(&WindowRoot::ClearWindow, this, std::placeholders::_1)); + sptr windowManagerAgentDeath_ = new WindowManagerAgentDeathRecipient( + std::bind(&WindowRoot::ClearWindowManagerAgent, this, std::placeholders::_1)); }; } } diff --git a/wmserver/src/input_window_monitor.cpp b/wmserver/src/input_window_monitor.cpp index 8a71df9d..6a960cba 100644 --- a/wmserver/src/input_window_monitor.cpp +++ b/wmserver/src/input_window_monitor.cpp @@ -47,7 +47,6 @@ void InputWindowMonitor::UpdateInputWindow(uint32_t windowId) UpdateDisplaysInfo(container); std::vector> windowNodes; container->TraverseContainer(windowNodes); - auto iter = std::find_if(logicalDisplays_.begin(), logicalDisplays_.end(), [displayId](MMI::LogicalDisplayInfo& logicalDisplay) { return logicalDisplay.id == displayId; @@ -84,7 +83,7 @@ void InputWindowMonitor::UpdateDisplaysInfo(const sptr& con }; auto physicalDisplayIter = std::find_if(physicalDisplays_.begin(), physicalDisplays_.end(), [&physicalDisplayInfo](MMI::PhysicalDisplayInfo& physicalDisplay) { - return physicalDisplay.id = physicalDisplayInfo.id; + return physicalDisplay.id == physicalDisplayInfo.id; }); if (physicalDisplayIter != physicalDisplays_.end()) { *physicalDisplayIter = physicalDisplayInfo; @@ -106,7 +105,7 @@ void InputWindowMonitor::UpdateDisplaysInfo(const sptr& con }; auto logicalDisplayIter = std::find_if(logicalDisplays_.begin(), logicalDisplays_.end(), [&logicalDisplayInfo](MMI::LogicalDisplayInfo& logicalDisplay) { - return logicalDisplay.id = logicalDisplayInfo.id; + return logicalDisplay.id == logicalDisplayInfo.id; }); if (logicalDisplayIter != logicalDisplays_.end()) { *logicalDisplayIter = logicalDisplayInfo; @@ -116,7 +115,7 @@ void InputWindowMonitor::UpdateDisplaysInfo(const sptr& con } void InputWindowMonitor::TraverseWindowNodes(const std::vector> &windowNodes, - std::vector::iterator& iter) + std::vector::iterator& iter) { iter->windowsInfo_.clear(); for (auto& windowNode: windowNodes) { @@ -129,10 +128,10 @@ void InputWindowMonitor::TraverseWindowNodes(const std::vector> .id = static_cast(windowNode->GetWindowId()), .pid = windowNode->GetCallingPid(), .uid = windowNode->GetCallingUid(), - .topLeftX = windowNode->GetLayoutRects().rect_.posX_, - .topLeftY = windowNode->GetLayoutRects().rect_.posY_, - .width = static_cast(windowNode->GetLayoutRects().rect_.width_), - .height = static_cast(windowNode->GetLayoutRects().rect_.height_), + .topLeftX = windowNode->GetLayoutRect().posX_, + .topLeftY = windowNode->GetLayoutRect().posY_, + .width = static_cast(windowNode->GetLayoutRect().width_), + .height = static_cast(windowNode->GetLayoutRect().height_), .displayId = windowNode->GetDisplayId(), .agentWindowId = static_cast(windowNode->GetWindowId()), }; diff --git a/wmserver/src/window_controller.cpp b/wmserver/src/window_controller.cpp index 9f3dbe1e..a26a7fd8 100644 --- a/wmserver/src/window_controller.cpp +++ b/wmserver/src/window_controller.cpp @@ -16,6 +16,7 @@ #include "window_controller.h" #include #include "window_manager_hilog.h" +#include "wm_trace.h" namespace OHOS { namespace Rosen { @@ -63,13 +64,12 @@ WMError WindowController::AddWindowNode(sptr& property) if (res != WMError::WM_OK) { return res; } - res = LayoutWindowNodeTrees(); RSTransaction::FlushImplicitTransaction(); - WLOGFI("AddWindowNode FlushImplicitTransaction end"); if (node->GetWindowMode() == WindowMode::WINDOW_MODE_FULLSCREEN) { - WLOGFI("need minimize previous fullscreen window if exists"); + WM_SCOPED_TRACE_BEGIN("controller:MinimizeOtherFullScreenAbility"); WMError res = windowRoot_->MinimizeOtherFullScreenAbility(node); + WM_SCOPED_TRACE_END(); if (res != WMError::WM_OK) { WLOGFE("Minimize other fullscreen window failed"); } @@ -77,32 +77,13 @@ WMError WindowController::AddWindowNode(sptr& property) return res; } -WMError WindowController::LayoutWindowNodeTrees() -{ - auto& windowContainerMap = windowRoot_->GetWindowNodeContainerMap(); - if (windowContainerMap.empty()) { - WLOGFE("could not find window container"); - return WMError::WM_ERROR_INVALID_PARAM; - } - for (auto& iter : windowContainerMap) { - const sptr& windowContainer = iter.second; - WMError ret = windowContainer->LayoutWindowNodes(); - if (ret != WMError::WM_OK) { - return ret; - } - } - return WMError::WM_OK; -} - WMError WindowController::RemoveWindowNode(uint32_t windowId) { WMError res = windowRoot_->RemoveWindowNode(windowId); if (res != WMError::WM_OK) { return res; } - res = LayoutWindowNodeTrees(); RSTransaction::FlushImplicitTransaction(); - WLOGFI("RemoveWindowNode FlushImplicitTransaction end"); return res; } @@ -112,9 +93,7 @@ WMError WindowController::DestroyWindow(uint32_t windowId) if (res != WMError::WM_OK) { return res; } - res = LayoutWindowNodeTrees(); RSTransaction::FlushImplicitTransaction(); - WLOGFI("DestroyWindow FlushImplicitTransaction end"); return res; } @@ -125,10 +104,15 @@ WMError WindowController::MoveTo(uint32_t windowId, int32_t x, int32_t y) WLOGFE("could not find window"); return WMError::WM_ERROR_NULLPTR; } - Vector2f pos(x, y); - node->surfaceNode_->SetBoundsPosition(pos); + auto property = node->GetWindowProperty(); + Rect lastRect = property->GetWindowRect(); + Rect newRect = { x, y, lastRect.width_, lastRect.height_ }; + property->SetWindowRect(newRect); + WMError res = windowRoot_->UpdateWindowNode(windowId); + if (res != WMError::WM_OK) { + return res; + } RSTransaction::FlushImplicitTransaction(); - WLOGFI("MoveTo FlushImplicitTransaction end"); return WMError::WM_OK; } @@ -139,9 +123,15 @@ WMError WindowController::Resize(uint32_t windowId, uint32_t width, uint32_t hei WLOGFE("could not find window"); return WMError::WM_ERROR_NULLPTR; } - node->surfaceNode_->SetBoundsSize(width, height); + auto property = node->GetWindowProperty(); + Rect lastRect = property->GetWindowRect(); + Rect newRect = { lastRect.posX_, lastRect.posY_, width, height }; + property->SetWindowRect(newRect); + WMError res = windowRoot_->UpdateWindowNode(windowId); + if (res != WMError::WM_OK) { + return res; + } RSTransaction::FlushImplicitTransaction(); - WLOGFI("Resize FlushImplicitTransaction end"); return WMError::WM_OK; } @@ -149,5 +139,86 @@ WMError WindowController::RequestFocus(uint32_t windowId) { return windowRoot_->RequestFocus(windowId); } + +WMError WindowController::SetWindowMode(uint32_t windowId, WindowMode mode) +{ + auto node = windowRoot_->GetWindowNode(windowId); + if (node == nullptr) { + WLOGFE("could not find window"); + return WMError::WM_ERROR_NULLPTR; + } + auto property = node->GetWindowProperty(); + property->SetWindowMode(mode); + WMError res = windowRoot_->UpdateWindowNode(windowId); + if (res != WMError::WM_OK) { + return res; + } + RSTransaction::FlushImplicitTransaction(); + WLOGFI("SetWindowMode FlushImplicitTransaction end"); + return res; +} + +WMError WindowController::SetWindowType(uint32_t windowId, WindowType type) +{ + auto node = windowRoot_->GetWindowNode(windowId); + if (node == nullptr) { + WLOGFE("could not find window"); + return WMError::WM_ERROR_NULLPTR; + } + auto property = node->GetWindowProperty(); + property->SetWindowType(type); + WMError res = windowRoot_->UpdateWindowNode(windowId); + if (res != WMError::WM_OK) { + return res; + } + RSTransaction::FlushImplicitTransaction(); + WLOGFI("SetWindowType FlushImplicitTransaction end"); + return res; +} + +WMError WindowController::SetWindowFlags(uint32_t windowId, uint32_t flags) +{ + auto node = windowRoot_->GetWindowNode(windowId); + if (node == nullptr) { + WLOGFE("could not find window"); + return WMError::WM_ERROR_NULLPTR; + } + auto property = node->GetWindowProperty(); + property->SetWindowFlags(flags); + WMError res = windowRoot_->UpdateWindowNode(windowId); + if (res != WMError::WM_OK) { + return res; + } + RSTransaction::FlushImplicitTransaction(); + WLOGFI("SetWindowFlags FlushImplicitTransaction end"); + return res; +} + +WMError WindowController::SetSystemBarProperty(uint32_t windowId, WindowType type, const SystemBarProperty& property) +{ + auto node = windowRoot_->GetWindowNode(windowId); + if (node == nullptr) { + WLOGFE("could not find window"); + return WMError::WM_ERROR_NULLPTR; + } + node->SetSystemBarProperty(type, property); + WMError res = windowRoot_->UpdateWindowNode(windowId); + if (res != WMError::WM_OK) { + return res; + } + RSTransaction::FlushImplicitTransaction(); + WLOGFI("SetSystemBarProperty FlushImplicitTransaction end"); + return res; +} + +void WindowController::RegisterFocusChangedListener(const sptr& windowManagerAgent) +{ + windowRoot_->RegisterFocusChangedListener(windowManagerAgent); +} + +void WindowController::UnregisterFocusChangedListener(const sptr& windowManagerAgent) +{ + windowRoot_->UnregisterFocusChangedListener(windowManagerAgent); +} } } diff --git a/wmserver/src/window_layout_policy.cpp b/wmserver/src/window_layout_policy.cpp index c90a5f03..75b497a6 100644 --- a/wmserver/src/window_layout_policy.cpp +++ b/wmserver/src/window_layout_policy.cpp @@ -14,7 +14,9 @@ */ #include "window_layout_policy.h" +#include "window_helper.h" #include "window_manager_hilog.h" +#include "wm_trace.h" namespace OHOS { namespace Rosen { @@ -22,163 +24,167 @@ namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowLayoutPolicy"}; } -WMError WindowLayoutPolicy::UpdateDisplayInfo(const Rect& displayRect) +WindowLayoutPolicy::WindowLayoutPolicy(const sptr& belowAppNode, + const sptr& appNode, const sptr& aboveAppNode) +{ + belowAppWindowNode_ = belowAppNode; + appWindowNode_ = appNode; + aboveAppWindowNode_ = aboveAppNode; +} + +void WindowLayoutPolicy::UpdateDisplayInfo(const Rect& displayRect) { - if (displayRect.height_ == 0 || displayRect.width_ == 0) { - return WMError::WM_ERROR_INVALID_PARAM; - } displayRect_ = displayRect; - limitRect_ = displayRect; - aviodNodes_.clear(); - return WMError::WM_OK; + limitRect_ = displayRect_; + avoidNodes_.clear(); } -WMError WindowLayoutPolicy::LayoutWindow(sptr& node) +void WindowLayoutPolicy::LayoutWindowTree() { - if (node->GetWindowType() >= WindowType::SYSTEM_WINDOW_END) { - WLOGFE("unknown window type!"); - return WMError::WM_ERROR_INVALID_PARAM; + limitRect_ = displayRect_; + avoidNodes_.clear(); + std::vector> rootNodes = { aboveAppWindowNode_, appWindowNode_, belowAppWindowNode_ }; + for (auto& node : rootNodes) { // ensure that the avoid area windows are traversed first + LayoutWindowNode(node); } - UpdateLayoutRects(node); - if (aviodTypes_.find(node->GetWindowType()) != aviodTypes_.end()) { - RecordAvoidRect(node); - } - return WMError::WM_OK; } -bool WindowLayoutPolicy::IsRectChanged(const Rect& l, const Rect& r) +void WindowLayoutPolicy::LayoutWindowNode(sptr& node) +{ + if (node == nullptr) { + return; + } + if (node->parent_ != nullptr) { // isn't root node + UpdateLayoutRect(node); + if (avoidTypes_.find(node->GetWindowType()) != avoidTypes_.end()) { + RecordAvoidRect(node); + } + } + for (auto& childNode : node->children_) { + LayoutWindowNode(childNode); + } +} + +void WindowLayoutPolicy::AddWindowNode(sptr& node) +{ + WM_FUNCTION_TRACE(); + UpdateWindowNode(node); // currently, update and add do the same process +} + +void WindowLayoutPolicy::RemoveWindowNode(sptr& node) +{ + WM_FUNCTION_TRACE(); + auto type = node->GetWindowType(); + // affect other windows, trigger off global layout + if (type == WindowType::WINDOW_TYPE_STATUS_BAR || type == WindowType::WINDOW_TYPE_NAVIGATION_BAR) { + LayoutWindowTree(); + } else if (type == WindowType::WINDOW_TYPE_DOCK_SLICE) { // split screen mode + // TODO: change split screen + LayoutWindowTree(); + } +} + +void WindowLayoutPolicy::UpdateWindowNode(sptr& node) +{ + WM_FUNCTION_TRACE(); + auto type = node->GetWindowType(); + // affect other windows, trigger off global layout + if (type == WindowType::WINDOW_TYPE_STATUS_BAR || type == WindowType::WINDOW_TYPE_NAVIGATION_BAR) { + LayoutWindowTree(); + } else if (type == WindowType::WINDOW_TYPE_DOCK_SLICE) { // split screen mode + // TODO: change split screen + LayoutWindowTree(); + } else { // layout single window + LayoutWindowNode(node); + } +} + +static bool IsLayoutChanged(const Rect& l, const Rect& r) { return !((l.posX_ == r.posX_) && (l.posY_ == r.posY_) && (l.width_ == r.width_) && (l.height_ == r.height_)); } -bool WindowLayoutPolicy::UpdateLayoutRects(sptr& node) +void WindowLayoutPolicy::UpdateLayoutRect(sptr& node) { - bool needAvoid = IsNeedAvoidNode(node); - bool fullScreen = IsFullScreenNode(node); - bool parentLimit = IsParentLimitNode(node); - bool subWindow = (node->GetWindowType() == WindowType::WINDOW_TYPE_APP_SUB_WINDOW); - bool floatingWindow = (node->GetWindowMode() == WindowMode::WINDOW_MODE_FLOATING); - WLOGFI("Id:%{public}d, avoid:%{public}d fullS:%{public}d parLimit:%{public}d float:%{public}d, types:%{public}d", - node->GetWindowId(), needAvoid, fullScreen, parentLimit, floatingWindow, - static_cast(node->GetWindowType())); - const LayoutRects& layoutRects = node->GetLayoutRects(); - Rect lastRect = layoutRects.rect_; - Rect dRect = layoutRects.displayRect_; - Rect pRect = layoutRects.parentRect_; - Rect lRect = layoutRects.limitRect_; + auto type = node->GetWindowType(); + auto mode = node->GetWindowMode(); + auto flags = node->GetWindowFlags(); + 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); + bool floatingWindow = (mode == WindowMode::WINDOW_MODE_FLOATING); + const Rect& layoutRect = node->GetLayoutRect(); + Rect lastRect = layoutRect; + Rect limitRect = displayRect_; Rect winRect = node->GetWindowProperty()->GetWindowRect(); + WLOGFI("Id:%{public}d, avoid:%{public}d parLimit:%{public}d floating:%{public}d, sub:%{public}d," \ + "type:%{public}d, requestRect:[%{public}d, %{public}d, %{public}d, %{public}d]", + node->GetWindowId(), needAvoid, parentLimit, floatingWindow, subWindow, + static_cast(type), winRect.posX_, winRect.posY_, winRect.width_, winRect.height_); if (needAvoid) { - dRect = limitRect_; - } else { - dRect = displayRect_; + limitRect = limitRect_; } - - if (subWindow) { - pRect = node->parent_->GetLayoutRects().rect_; - } else { - pRect = dRect; + if (!floatingWindow) { // fullscreen window + winRect = limitRect; + } else { // floating window + if (subWindow && parentLimit) { // subwidow and limited by parent + limitRect = node->parent_->GetLayoutRect(); + winRect.width_ = std::min(limitRect.width_, winRect.width_); + winRect.height_ = std::min(limitRect.height_, winRect.height_); + winRect.posX_ = std::max(limitRect.posX_, winRect.posX_); + winRect.posY_ = std::max(limitRect.posY_, winRect.posY_); + winRect.posX_ = std::min( + limitRect.posX_ + static_cast(limitRect.width_) - static_cast(winRect.width_), + winRect.posX_); + winRect.posY_ = std::min( + limitRect.posY_ + static_cast(limitRect.height_) - static_cast(winRect.height_), + winRect.posY_); + } } - - if (parentLimit) { - lRect = pRect; - } else { - lRect = dRect; - } - - if (fullScreen) { - winRect = lRect; - } else if (!floatingWindow) { - winRect.width_ = std::min(lRect.width_, winRect.width_); - winRect.height_ = std::min(lRect.height_, winRect.height_); - winRect.posX_ = std::max(lRect.posX_, winRect.posX_); - winRect.posY_ = std::max(lRect.posY_, winRect.posY_); - winRect.posX_ = std::min( - lRect.posX_ + static_cast(lRect.width_) - static_cast(winRect.width_), - winRect.posX_); - winRect.posY_ = std::min( - lRect.posY_ + static_cast(lRect.height_) - static_cast(winRect.height_), - winRect.posY_); - } - node->UpdateLayoutRects({ dRect, pRect, lRect, winRect }); - if (IsRectChanged(lastRect, winRect)) { + // Limit window to the maximum window size + winRect.width_ = std::min(displayRect_.width_, winRect.width_); + winRect.height_ = std::min(displayRect_.height_, winRect.height_); + winRect.width_ = std::max(1u, winRect.width_); + winRect.height_ = std::max(1u, winRect.height_); + node->SetLayoutRect(winRect); + if (IsLayoutChanged(lastRect, winRect)) { node->GetWindowToken()->UpdateWindowRect(winRect); node->surfaceNode_->SetBounds(winRect.posX_, winRect.posY_, winRect.width_, winRect.height_); - WLOGFI("UpdateLayoutRects for winId: %{public}d, Rect: %{public}d %{public}d %{public}d %{public}d", - node->GetWindowId(), winRect.posX_, winRect.posY_, winRect.width_, winRect.height_); - return true; } - WLOGFI("UpdateLayoutRects rect not changed for winId: %{public}d", node->GetWindowId()); - return false; } void WindowLayoutPolicy::UpdateLimitRect(const sptr& node) { - auto& layoutRects = node->GetLayoutRects(); + auto& layoutRect = node->GetLayoutRect(); if (node->GetWindowType() == WindowType::WINDOW_TYPE_STATUS_BAR) { // STATUS_BAR int32_t boundTop = limitRect_.posY_; - int32_t rectBottom = layoutRects.rect_.posY_ + layoutRects.rect_.height_; + int32_t rectBottom = layoutRect.posY_ + layoutRect.height_; int32_t offsetH = rectBottom - boundTop; limitRect_.posY_ += offsetH; limitRect_.height_ -= offsetH; } else if (node->GetWindowType() == WindowType::WINDOW_TYPE_NAVIGATION_BAR) { // NAVIGATION_BAR int32_t boundBottom = limitRect_.posY_ + limitRect_.height_; - int32_t offsetH = boundBottom - layoutRects.rect_.posY_; + int32_t offsetH = boundBottom - layoutRect.posY_; limitRect_.height_ -= offsetH; } - WLOGFI("after add WinId: %{public}d, limitRect: %{public}d %{public}d %{public}d %{public}d", - node->GetWindowId(), limitRect_.posX_, limitRect_.posY_, limitRect_.width_, limitRect_.height_); + WLOGFI("Type: %{public}d, limitRect: %{public}d %{public}d %{public}d %{public}d", + node->GetWindowType(), limitRect_.posX_, limitRect_.posY_, limitRect_.width_, limitRect_.height_); } void WindowLayoutPolicy::RecordAvoidRect(const sptr& node) { uint32_t id = node->GetWindowId(); - if (aviodNodes_.find(id) == aviodNodes_.end()) { // new avoid rect - aviodNodes_.insert(std::pair>(id, node)); + if (avoidNodes_.find(id) == avoidNodes_.end()) { // new avoid rect + avoidNodes_.insert(std::pair>(id, node)); UpdateLimitRect(node); } else { // update existing avoid rect limitRect_ = displayRect_; - aviodNodes_[id] = node; - for (auto item : aviodNodes_) { + avoidNodes_[id] = node; + for (auto item : avoidNodes_) { UpdateLimitRect(item.second); } } } - -bool WindowLayoutPolicy::IsNeedAvoidNode(const sptr& node) -{ - auto type = node->GetWindowType(); - auto mode = node->GetWindowMode(); - auto flags = node->GetWindowFlags(); - if (mode == WindowMode::WINDOW_MODE_FLOATING) { - return false; - } - if (type >= WindowType::APP_WINDOW_BASE && - type <= WindowType::APP_SUB_WINDOW_END && - (flags & static_cast(WindowFlag::WINDOW_FLAG_NEED_AVOID))) { - return true; - } - return false; -} - -bool WindowLayoutPolicy::IsFullScreenNode(const sptr& node) -{ - auto mode = node->GetWindowMode(); - if (mode == WindowMode::WINDOW_MODE_FULLSCREEN || mode == WindowMode::WINDOW_MODE_SPLIT) { - return true; - } - return false; -} - -bool WindowLayoutPolicy::IsParentLimitNode(const sptr& node) -{ - auto mode = node->GetWindowMode(); - auto flags = node->GetWindowFlags(); - if (mode != WindowMode::WINDOW_MODE_FLOATING && - (flags & static_cast(WindowFlag::WINDOW_FLAG_PARENT_LIMIT))) { - return true; - } - return false; -} } } diff --git a/wmserver/src/window_manager_proxy.cpp b/wmserver/src/window_manager_proxy.cpp index f1f2da58..04270b7b 100644 --- a/wmserver/src/window_manager_proxy.cpp +++ b/wmserver/src/window_manager_proxy.cpp @@ -215,6 +215,111 @@ WMError WindowManagerProxy::RequestFocus(uint32_t windowId) return static_cast(ret); } +WMError WindowManagerProxy::SetWindowMode(uint32_t windowId, WindowMode mode) +{ + 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.WriteUint32(static_cast(mode))) { + WLOGFE("Write type failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + if (Remote()->SendRequest(TRANS_ID_UPDATE_MODE, data, reply, option) != ERR_NONE) { + return WMError::WM_ERROR_IPC_FAILED; + } + + int32_t ret = reply.ReadInt32(); + return static_cast(ret); +} + +WMError WindowManagerProxy::SetWindowType(uint32_t windowId, WindowType type) +{ + 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.WriteUint32(static_cast(type))) { + WLOGFE("Write type failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + if (Remote()->SendRequest(TRANS_ID_UPDATE_TYPE, data, reply, option) != ERR_NONE) { + return WMError::WM_ERROR_IPC_FAILED; + } + + int32_t ret = reply.ReadInt32(); + return static_cast(ret); +} + +WMError WindowManagerProxy::SetWindowFlags(uint32_t windowId, uint32_t flags) +{ + 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.WriteUint32(flags)) { + WLOGFE("Write type failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + if (Remote()->SendRequest(TRANS_ID_UPDATE_FLAGS, data, reply, option) != ERR_NONE) { + return WMError::WM_ERROR_IPC_FAILED; + } + + int32_t ret = reply.ReadInt32(); + return static_cast(ret); +} + +WMError WindowManagerProxy::SetSystemBarProperty(uint32_t windowId, WindowType type, const SystemBarProperty& prop) +{ + 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.WriteUint32(static_cast(type))) { + WLOGFE("Write type failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + if (!(data.WriteBool(prop.enable_) && data.WriteUint32(prop.backgroundColor_) && + data.WriteUint32(prop.contentColor_))) { + WLOGFE("Write property failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + if (Remote()->SendRequest(TRANS_ID_UPDATE_SYSTEM_BAR_PROPERTY, data, reply, option) != ERR_NONE) { + return WMError::WM_ERROR_IPC_FAILED; + } + + int32_t ret = reply.ReadInt32(); + return static_cast(ret); +} + WMError WindowManagerProxy::SaveAbilityToken(const sptr& abilityToken, uint32_t windowId) { MessageParcel data; @@ -242,6 +347,45 @@ WMError WindowManagerProxy::SaveAbilityToken(const sptr& abilityT int32_t ret = reply.ReadInt32(); return static_cast(ret); } -} + +void WindowManagerProxy::RegisterFocusChangedListener(const sptr& windowManagerAgent) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("WriteInterfaceToken failed"); + return; + } + + if (!data.WriteRemoteObject(windowManagerAgent->AsObject())) { + WLOGFE("Write IWindowManagerAgent failed"); + return; + } + + if (Remote()->SendRequest(TRANS_ID_REGISTER_FOCUS_CHANGED_LISTENER, data, reply, option) != ERR_NONE) { + WLOGFE("SendRequest failed"); + } } +void WindowManagerProxy::UnregisterFocusChangedListener(const sptr& windowManagerAgent) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("WriteInterfaceToken failed"); + return; + } + + if (!data.WriteRemoteObject(windowManagerAgent->AsObject())) { + WLOGFE("Write IWindowManagerAgent failed"); + return; + } + + if (Remote()->SendRequest(TRANS_ID_UNREGISTER_FOCUS_CHANGED_LISTENER, data, reply, option) != ERR_NONE) { + WLOGFE("SendRequest failed"); + } +} +} +} diff --git a/wmserver/src/window_manager_service.cpp b/wmserver/src/window_manager_service.cpp index 7c70a580..2f7542f4 100644 --- a/wmserver/src/window_manager_service.cpp +++ b/wmserver/src/window_manager_service.cpp @@ -21,6 +21,7 @@ #include #include "window_manager_hilog.h" +#include "wm_trace.h" namespace OHOS { namespace Rosen { @@ -28,14 +29,11 @@ namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowManagerService"}; } -IMPLEMENT_SINGLE_INSTANCE(WindowManagerService); - -const bool REGISTER_RESULT = SystemAbility::MakeAndRegisterAbility( - SingletonContainer::Get().GetRefPtr()); +const bool REGISTER_RESULT = SystemAbility::MakeAndRegisterAbility(&SingletonContainer::Get()); WindowManagerService::WindowManagerService() : SystemAbility(WINDOW_MANAGER_SERVICE_ID, true) { - windowRoot_ = new WindowRoot(); + windowRoot_ = new WindowRoot(mutex_); windowController_ = new WindowController(windowRoot_); inputWindowMonitor_ = new InputWindowMonitor(windowRoot_); } @@ -57,7 +55,7 @@ bool WindowManagerService::Init() return false; } WLOGFI("WindowManagerService::Init success"); - sleep(10); // for RS temporary + sleep(WAITING_RS_TIME); // for RS temporary return true; } @@ -69,17 +67,28 @@ void WindowManagerService::OnStop() WMError WindowManagerService::CreateWindow(sptr& window, sptr& property, const std::shared_ptr& surfaceNode, uint32_t& windowId) { + WM_SCOPED_TRACE("wms:CreateWindow(%d)", windowId); if (window == nullptr || property == nullptr || surfaceNode == nullptr) { WLOGFE("window is invalid"); return WMError::WM_ERROR_NULLPTR; } - std::lock_guard lock(mutex_); + if ((!window) || (!window->AsObject())) { + WLOGFE("failed to get window agent"); + return WMError::WM_ERROR_NULLPTR; + } + std::lock_guard lock(mutex_); return windowController_->CreateWindow(window, property, surfaceNode, windowId); } WMError WindowManagerService::AddWindow(sptr& property) { - std::lock_guard lock(mutex_); + Rect rect = property->GetWindowRect(); + WLOGFI("[WMS] Add: %{public}5d %{public}4d %{public}4d %{public}4d [%{public}4d %{public}4d " \ + "%{public}4d %{public}4d]", property->GetWindowId(), property->GetWindowType(), property->GetWindowMode(), + property->GetWindowFlags(), rect.posX_, rect.posY_, rect.width_, rect.height_); + + WM_SCOPED_TRACE("wms:AddWindow(%d)", property->GetWindowId()); + std::lock_guard lock(mutex_); WMError res = windowController_->AddWindowNode(property); if (res == WMError::WM_OK) { inputWindowMonitor_->UpdateInputWindow(property->GetWindowId()); @@ -89,7 +98,9 @@ WMError WindowManagerService::AddWindow(sptr& property) WMError WindowManagerService::RemoveWindow(uint32_t windowId) { - std::lock_guard lock(mutex_); + WLOGFI("[WMS] Remove: %{public}d", windowId); + WM_SCOPED_TRACE("wms:RemoveWindow(%d)", windowId); + std::lock_guard lock(mutex_); WMError res = windowController_->RemoveWindowNode(windowId); if (res == WMError::WM_OK) { inputWindowMonitor_->UpdateInputWindow(windowId); @@ -99,7 +110,9 @@ WMError WindowManagerService::RemoveWindow(uint32_t windowId) WMError WindowManagerService::DestroyWindow(uint32_t windowId) { - std::lock_guard lock(mutex_); + WLOGFI("[WMS] Destroy: %{public}d", windowId); + WM_SCOPED_TRACE("wms:DestroyWindow(%d)", windowId); + std::lock_guard lock(mutex_); WMError res = windowController_->DestroyWindow(windowId); if (res == WMError::WM_OK) { inputWindowMonitor_->UpdateInputWindow(windowId); @@ -109,26 +122,81 @@ WMError WindowManagerService::DestroyWindow(uint32_t windowId) WMError WindowManagerService::MoveTo(uint32_t windowId, int32_t x, int32_t y) { - std::lock_guard lock(mutex_); + WLOGFI("[WMS] MoveTo: %{public}d [%{public}d, %{public}d]", windowId, x, y); + WM_SCOPED_TRACE("wms:MoveTo"); + std::lock_guard lock(mutex_); return windowController_->MoveTo(windowId, x, y); } WMError WindowManagerService::Resize(uint32_t windowId, uint32_t width, uint32_t height) { - std::lock_guard lock(mutex_); + WLOGFI("[WMS] Resize: %{public}d [%{public}d, %{public}d]", windowId, width, height); + WM_SCOPED_TRACE("wms:Resize"); + std::lock_guard lock(mutex_); return windowController_->Resize(windowId, width, height); } WMError WindowManagerService::RequestFocus(uint32_t windowId) { - std::lock_guard lock(mutex_); + WLOGFI("[WMS] RequestFocus: %{public}d", windowId); + WM_SCOPED_TRACE("wms:RequestFocus"); + std::lock_guard lock(mutex_); return windowController_->RequestFocus(windowId); } +WMError WindowManagerService::SetWindowMode(uint32_t windowId, WindowMode mode) +{ + WM_SCOPED_TRACE("wms:SetWindowMode"); + std::lock_guard lock(mutex_); + return windowController_->SetWindowMode(windowId, mode); +} + +WMError WindowManagerService::SetWindowType(uint32_t windowId, WindowType type) +{ + WM_SCOPED_TRACE("wms:SetWindowType"); + std::lock_guard lock(mutex_); + return windowController_->SetWindowType(windowId, type); +} + +WMError WindowManagerService::SetWindowFlags(uint32_t windowId, uint32_t flags) +{ + WM_SCOPED_TRACE("wms:SetWindowFlags"); + std::lock_guard lock(mutex_); + return windowController_->SetWindowFlags(windowId, flags); +} + +WMError WindowManagerService::SetSystemBarProperty(uint32_t windowId, WindowType type, const SystemBarProperty& prop) +{ + WM_SCOPED_TRACE("wms:SetSystemBarProperty"); + std::lock_guard lock(mutex_); + return windowController_->SetSystemBarProperty(windowId, type, prop); +} + WMError WindowManagerService::SaveAbilityToken(const sptr& abilityToken, uint32_t windowId) { - std::lock_guard lock(mutex_); + WLOGFI("[WMS] SaveAbilityToken: %{public}d", windowId); + std::lock_guard lock(mutex_); return windowController_->SaveAbilityToken(abilityToken, windowId); } + +void WindowManagerService::RegisterFocusChangedListener(const sptr& windowManagerAgent) +{ + if ((windowManagerAgent == nullptr) || (windowManagerAgent->AsObject() == nullptr)) { + WLOGFE("failed to get window manager agent"); + return; + } + std::lock_guard lock(mutex_); + windowController_->RegisterFocusChangedListener(windowManagerAgent); +} + +void WindowManagerService::UnregisterFocusChangedListener(const sptr& windowManagerAgent) +{ + if ((windowManagerAgent == nullptr) || (windowManagerAgent->AsObject() == nullptr)) { + WLOGFE("windowManagerAgent is null"); + return; + } + std::lock_guard lock(mutex_); + windowController_->UnregisterFocusChangedListener(windowManagerAgent); +} } } \ No newline at end of file diff --git a/wmserver/src/window_manager_stub.cpp b/wmserver/src/window_manager_stub.cpp index cd18fed9..795f0469 100644 --- a/wmserver/src/window_manager_stub.cpp +++ b/wmserver/src/window_manager_stub.cpp @@ -26,7 +26,6 @@ namespace { int32_t WindowManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - WLOGFI("WindowManagerStub::OnRemoteRequest code is %{public}d", code); if (data.ReadInterfaceToken() != GetDescriptor()) { WLOGFE("InterfaceToken check failed"); return -1; @@ -83,7 +82,35 @@ int32_t WindowManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, M reply.WriteInt32(static_cast(errCode)); break; } - + case TRANS_ID_UPDATE_MODE: { + uint32_t windowId = data.ReadUint32(); + WindowMode mode = static_cast(data.ReadUint32()); + WMError errCode = SetWindowMode(windowId, mode); + reply.WriteInt32(static_cast(errCode)); + break; + } + case TRANS_ID_UPDATE_TYPE: { + uint32_t windowId = data.ReadUint32(); + WindowType type = static_cast(data.ReadUint32()); + WMError errCode = SetWindowType(windowId, type); + reply.WriteInt32(static_cast(errCode)); + break; + } + case TRANS_ID_UPDATE_FLAGS: { + uint32_t windowId = data.ReadUint32(); + uint32_t flags = data.ReadUint32(); + WMError errCode = SetWindowFlags(windowId, flags); + reply.WriteInt32(static_cast(errCode)); + break; + } + case TRANS_ID_UPDATE_SYSTEM_BAR_PROPERTY: { + uint32_t windowId = data.ReadUint32(); + WindowType type = static_cast(data.ReadUint32()); + SystemBarProperty property = { data.ReadBool(), data.ReadUint32(), data.ReadUint32() }; + WMError errCode = SetSystemBarProperty(windowId, type, property); + reply.WriteInt32(static_cast(errCode)); + break; + } case TRANS_ID_SEND_ABILITY_TOKEN: { sptr abilityToken = data.ReadRemoteObject(); uint32_t windowId = data.ReadUint32(); @@ -91,6 +118,20 @@ int32_t WindowManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, M reply.WriteInt32(static_cast(errCode)); break; } + case TRANS_ID_REGISTER_FOCUS_CHANGED_LISTENER: { + sptr windowManagerAgentObject = data.ReadRemoteObject(); + sptr windowManagerAgentProxy = + iface_cast(windowManagerAgentObject); + RegisterFocusChangedListener(windowManagerAgentProxy); + break; + } + case TRANS_ID_UNREGISTER_FOCUS_CHANGED_LISTENER: { + sptr windowManagerAgentObject = data.ReadRemoteObject(); + sptr windowManagerAgentProxy = + iface_cast(windowManagerAgentObject); + UnregisterFocusChangedListener(windowManagerAgentProxy); + break; + } default: WLOGFW("unknown transaction code"); return IPCObjectStub::OnRemoteRequest(code, data, reply, option); diff --git a/wmserver/src/window_node.cpp b/wmserver/src/window_node.cpp index 389d4f36..c81bcd8e 100644 --- a/wmserver/src/window_node.cpp +++ b/wmserver/src/window_node.cpp @@ -23,9 +23,9 @@ void WindowNode::SetDisplayId(int32_t displayId) property_->SetDisplayId(displayId); } -void WindowNode::UpdateLayoutRects(const LayoutRects& rects) +void WindowNode::SetLayoutRect(const Rect& rect) { - layoutRects_ = rects; + layoutRect_ = rect; } void WindowNode::SetWindowProperty(const sptr& property) @@ -33,6 +33,11 @@ void WindowNode::SetWindowProperty(const sptr& property) property_ = property; } +void WindowNode::SetSystemBarProperty(WindowType type, const SystemBarProperty& property) +{ + property_->SetSystemBarProperty(type, property); +} + const sptr& WindowNode::GetWindowToken() const { return windowToken_; @@ -48,9 +53,9 @@ uint32_t WindowNode::GetWindowId() const return property_->GetWindowId(); } -const LayoutRects& WindowNode::GetLayoutRects() const +const Rect& WindowNode::GetLayoutRect() const { - return layoutRects_; + return layoutRect_; } WindowType WindowNode::GetWindowType() const @@ -82,5 +87,10 @@ int32_t WindowNode::GetCallingUid() const { return callingUid_; } + +const std::unordered_map& WindowNode::GetSystemBarProperty() const +{ + return property_->GetSystemBarProperty(); +} } } diff --git a/wmserver/src/window_node_container.cpp b/wmserver/src/window_node_container.cpp index 564cb4a5..38dc3644 100644 --- a/wmserver/src/window_node_container.cpp +++ b/wmserver/src/window_node_container.cpp @@ -16,7 +16,9 @@ #include "window_node_container.h" #include #include +#include "window_helper.h" #include "window_manager_hilog.h" +#include "wm_trace.h" namespace OHOS { namespace Rosen { @@ -24,6 +26,20 @@ namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowNodeContainer"}; } +WindowNodeContainer::WindowNodeContainer(uint64_t screenId, uint32_t width, uint32_t height, + UpdateFocusStatusFunc callback) : screenId_(screenId), focusStatusCallBack_(callback) +{ + struct RSDisplayNodeConfig config = {screenId}; + displayNode_ = RSDisplayNode::Create(config); + displayRect_ = { + .posX_ = 0, + .posY_ = 0, + .width_ = width, + .height_ = height + }; + layoutPolicy_->UpdateDisplayInfo(displayRect_); +} + WindowNodeContainer::~WindowNodeContainer() { Destroy(); @@ -32,16 +48,14 @@ WindowNodeContainer::~WindowNodeContainer() WMError WindowNodeContainer::MinimizeOtherFullScreenAbility() { if (appWindowNode_->children_.empty()) { - WLOGFI("no appWindowNode, return"); return WMError::WM_OK; } for (auto iter = appWindowNode_->children_.begin(); iter < appWindowNode_->children_.end() - 1; ++iter) { if ((*iter)->GetWindowMode() != WindowMode::WINDOW_MODE_FULLSCREEN) { continue; } - WLOGFI("find previous fullscreen window"); if ((*iter)->abilityToken_ != nullptr) { - WLOGFI("notify ability to minimize"); + WLOGFI("Find previous fullscreen window, notify ability to minimize"); AAFwk::AbilityManagerClient::GetInstance()->MinimizeAbility((*iter)->abilityToken_); } } @@ -72,19 +86,38 @@ WMError WindowNodeContainer::AddWindowNode(sptr& node, sptrchildren_) { child->currentVisibility_ = child->requestedVisibility_; } + if (node->GetWindowType() == WindowType::WINDOW_TYPE_STATUS_BAR || + node->GetWindowType() == WindowType::WINDOW_TYPE_NAVIGATION_BAR) { + sysBarNodeMap_[node->GetWindowType()] = node; + } } node->parent_ = parentNode; UpdateWindowTree(node); UpdateRSTree(node, true); AssignZOrder(); + layoutPolicy_->AddWindowNode(node); UpdateFocusWindow(); + NotifySystemBarIfChanged(); WLOGFI("AddWindowNode windowId: %{public}d end", node->GetWindowId()); return WMError::WM_OK; } +WMError WindowNodeContainer::UpdateWindowNode(sptr& node) +{ + if (!node->surfaceNode_ || !displayNode_) { + WLOGFE("surface node or display node is nullptr!"); + return WMError::WM_ERROR_NULLPTR; + } + layoutPolicy_->UpdateWindowNode(node); + NotifySystemBarIfChanged(); + WLOGFI("UpdateWindowNode windowId: %{public}d end", node->GetWindowId()); + return WMError::WM_OK; +} + void WindowNodeContainer::UpdateWindowTree(sptr& node) { + WM_FUNCTION_TRACE(); node->priority_ = zorderPolicy_->GetWindowPriority(node->GetWindowType()); auto parentNode = node->parent_; auto position = parentNode->children_.end(); @@ -99,6 +132,7 @@ void WindowNodeContainer::UpdateWindowTree(sptr& node) bool WindowNodeContainer::UpdateRSTree(sptr& node, bool isAdd) { + WM_FUNCTION_TRACE(); if (displayNode_ == nullptr) { WLOGFE("displayNode_ is nullptr"); return false; @@ -123,6 +157,7 @@ WMError WindowNodeContainer::DestroyWindowNode(sptr& node, std::vect { WMError ret = RemoveWindowNode(node); if (ret != WMError::WM_OK) { + WLOGFE("RemoveWindowNode failed"); return ret; } node->surfaceNode_ = nullptr; @@ -137,42 +172,9 @@ WMError WindowNodeContainer::DestroyWindowNode(sptr& node, std::vect } } node->children_.clear(); - WLOGFI("DestroyWindowNode windowId: %{public}d end", node->GetWindowId()); return WMError::WM_OK; } -WMError WindowNodeContainer::LayoutWindowNodes() -{ - WMError ret = WMError::WM_OK; - layoutPolicy_->UpdateDisplayInfo(displayRect_); - std::vector> rootNodes = { aboveAppWindowNode_, appWindowNode_, belowAppWindowNode_ }; - for (auto& node : rootNodes) { // ensure that the avoid area windows are traversed first - ret = LayoutWindowNode(node); - if (ret != WMError::WM_OK) { - return ret; - } - } - return ret; -} - -WMError WindowNodeContainer::LayoutWindowNode(sptr& node) -{ - WMError ret = WMError::WM_OK; - if (node->parent_ != nullptr) { // isn't root node - ret = layoutPolicy_->LayoutWindow(node); - if (ret != WMError::WM_OK) { - return ret; - } - } - for (auto& childNode : node->children_) { - ret = LayoutWindowNode(childNode); - if (ret != WMError::WM_OK) { - return ret; - } - } - return ret; -} - WMError WindowNodeContainer::RemoveWindowNode(sptr& node) { if (node == nullptr || !node->surfaceNode_) { @@ -199,6 +201,8 @@ WMError WindowNodeContainer::RemoveWindowNode(sptr& node) } UpdateRSTree(node, false); UpdateFocusWindow(); + layoutPolicy_->RemoveWindowNode(node); + NotifySystemBarIfChanged(); WLOGFI("RemoveWindowNode windowId: %{public}d end", node->GetWindowId()); return WMError::WM_OK; } @@ -221,13 +225,16 @@ const std::vector& WindowNodeContainer::Destroy() sptr WindowNodeContainer::FindRoot(WindowType type) const { - if (type >= WindowType::APP_WINDOW_BASE && type <= WindowType::APP_SUB_WINDOW_END) { + if (WindowHelper::IsAppWindow(type)) { return appWindowNode_; - } else if (type < WindowType::ABOVE_APP_SYSTEM_WINDOW_BASE) { + } + if (WindowHelper::IsBelowSystemWindow(type)) { return belowAppWindowNode_; - } else { + } + if (WindowHelper::IsAboveSystemWindow(type)) { return aboveAppWindowNode_; } + return nullptr; } void WindowNodeContainer::UpdateFocusWindow() @@ -263,9 +270,14 @@ void WindowNodeContainer::UpdateFocusStatus(uint32_t id, bool focused) const { auto node = FindWindowNodeById(id); if (node == nullptr) { - WLOGFW("cannot find old focused window id:%{public}d", id); + WLOGFW("cannot find focused window id:%{public}d", id); } else { node->GetWindowToken()->UpdateFocusStatus(focused); + if (node->abilityToken_ == nullptr) { + WLOGFI("abilityToken is null, window : %{public}d", id); + } + focusStatusCallBack_(node->GetWindowId(), node->abilityToken_, node->GetWindowType(), + node->GetDisplayId(), focused); } } @@ -293,7 +305,6 @@ void WindowNodeContainer::AssignZOrder(sptr& node) if ((*iter)->priority_ < 0) { if ((*iter)->surfaceNode_) { (*iter)->surfaceNode_->SetPositionZ(zOrder_); - WLOGFI("for subWindow id %{public}d; zOrder:%{public}d", (*iter)->GetWindowId(), zOrder_); ++zOrder_; } } else { @@ -302,13 +313,11 @@ void WindowNodeContainer::AssignZOrder(sptr& node) } if (node->surfaceNode_) { node->surfaceNode_->SetPositionZ(zOrder_); - WLOGFI("window id:%{public}d; zOrder:%{public}d", node->GetWindowId(), zOrder_); ++zOrder_; } for (; iter < node->children_.end(); ++iter) { if ((*iter)->surfaceNode_) { (*iter)->surfaceNode_->SetPositionZ(zOrder_); - WLOGFI("for subWindow id %{public}d; zOrder:%{public}d", (*iter)->GetWindowId(), zOrder_); ++zOrder_; } } @@ -317,6 +326,7 @@ void WindowNodeContainer::AssignZOrder(sptr& node) WMError WindowNodeContainer::SetFocusWindow(uint32_t windowId) { if (focusedWindow_ == windowId) { + WLOGFI("focused window do not change"); return WMError::WM_OK; } UpdateFocusStatus(focusedWindow_, false); @@ -330,6 +340,59 @@ uint32_t WindowNodeContainer::GetFocusWindow() const return focusedWindow_; } +sptr WindowNodeContainer::GetTopImmersiveNode() const +{ + if (appWindowNode_->children_.empty()) { + return nullptr; + } + auto iter = appWindowNode_->children_.rbegin(); + for (; iter < appWindowNode_->children_.rend(); ++iter) { + auto mode = (*iter)->GetWindowMode(); + auto flags = (*iter)->GetWindowFlags(); + if (mode == WindowMode::WINDOW_MODE_FULLSCREEN && + !(flags & static_cast(WindowFlag::WINDOW_FLAG_NEED_AVOID))) { + return (*iter); + } + } + return nullptr; +} + +void WindowNodeContainer::NotifySystemBarIfChanged() +{ + DumpScreenWindowTree(); + auto node = GetTopImmersiveNode(); + if (node == nullptr) { // use default system bar + for (auto it : sysBarPropMap_) { + if (it.second == SystemBarProperty()) { + continue; + } + sysBarPropMap_[it.first] = SystemBarProperty(); + if (sysBarNodeMap_[it.first] != nullptr) { + sysBarNodeMap_[it.first]->GetWindowToken()->UpdateSystemBarProperty(SystemBarProperty()); + } + } + } else { // use node-defined system bar + auto& sysBarPropMap = node->GetSystemBarProperty(); + for (auto it : sysBarPropMap_) { + if (sysBarPropMap.find(it.first) == sysBarPropMap.end()) { + return; + } + auto& prop = sysBarPropMap.find(it.first)->second; + if (it.second == prop) { + continue; + } + WLOGFI("Set systemBar prop winId: %{public}d, type: %{public}d" \ + "visible: %{public}d, Color: %{public}x | %{public}x", + node->GetWindowId(), static_cast(it.first), + prop.enable_, prop.backgroundColor_, prop.contentColor_); + sysBarPropMap_[it.first] = prop; + if (sysBarNodeMap_[it.first] != nullptr) { + sysBarNodeMap_[it.first]->GetWindowToken()->UpdateSystemBarProperty(prop); + } + } + } +} + void WindowNodeContainer::TraverseContainer(std::vector>& windowNodes) { for (auto& node : belowAppWindowNode_->children_) { @@ -363,6 +426,22 @@ void WindowNodeContainer::TraverseWindowNode(sptr& node, std::vector } } +void WindowNodeContainer::DumpScreenWindowTree() +{ + WLOGFI("-------- Screen %{public}llu dump window info begin---------", screenId_); + WLOGFI("WinId Type Mode Flag ZOrd [ x y w h]"); + std::vector> windowNodes; + TraverseContainer(windowNodes); + int zOrder = windowNodes.size(); + for (auto node : windowNodes) { + Rect rect = node->GetLayoutRect(); + WLOGFI("%{public}5d %{public}4d %{public}4d %{public}4d %{public}4d [%{public}4d %{public}4d " \ + "%{public}4d %{public}4d]", node->GetWindowId(), node->GetWindowType(), node->GetWindowMode(), + node->GetWindowFlags(), --zOrder, rect.posX_, rect.posY_, rect.width_, rect.height_); + } + WLOGFI("-------- Screen %{public}llu dump window info end ---------", screenId_); +} + uint64_t WindowNodeContainer::GetScreenId() const { return screenId_; diff --git a/wmserver/src/window_root.cpp b/wmserver/src/window_root.cpp index ac626427..4b20ff0c 100644 --- a/wmserver/src/window_root.cpp +++ b/wmserver/src/window_root.cpp @@ -28,24 +28,23 @@ sptr WindowRoot::GetOrCreateWindowNodeContainer(int32_t dis if (iter != windowNodeContainerMap_.end()) { return iter->second; } - auto displayScreen = DisplayManagerServiceInner::GetInstance()->GetDisplayById(displayId); - if (displayScreen == nullptr) { + auto abstractDisplay = DisplayManagerServiceInner::GetInstance().GetDisplayById(displayId); + if (abstractDisplay == nullptr) { WLOGFE("get display failed displayId:%{public}d", displayId); return nullptr; } WLOGFI("create new window node container display width:%{public}d, height:%{public}d, screenId:%{public}llu", - displayScreen->GetWidth(), displayScreen->GetHeight(), displayScreen->GetId()); - sptr container = new WindowNodeContainer(displayScreen->GetId(), - static_cast(displayScreen->GetWidth()), static_cast(displayScreen->GetHeight())); + abstractDisplay->GetWidth(), abstractDisplay->GetHeight(), abstractDisplay->GetId()); + + UpdateFocusStatusFunc focusStatusFunc = std::bind(&WindowRoot::UpdateFocusStatus, this, std::placeholders::_1, + std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5); + sptr container = new WindowNodeContainer(abstractDisplay->GetId(), + static_cast(abstractDisplay->GetWidth()), static_cast(abstractDisplay->GetHeight()), + focusStatusFunc); windowNodeContainerMap_.insert({ displayId, container }); return container; } -const std::map>& WindowRoot::GetWindowNodeContainerMap() const -{ - return windowNodeContainerMap_; -} - void WindowRoot::NotifyDisplayRemoved(int32_t displayId) { auto container = GetOrCreateWindowNodeContainer(displayId); @@ -65,7 +64,6 @@ sptr WindowRoot::GetWindowNode(uint32_t windowId) const { auto iter = windowNodeMap_.find(windowId); if (iter == windowNodeMap_.end()) { - WLOGFE("window node could not be found"); return nullptr; } return iter->second; @@ -84,6 +82,7 @@ WMError WindowRoot::SaveWindow(const sptr& node) if (windowDeath_ == nullptr) { WLOGFI("failed to create death Recipient ptr WindowDeathRecipient"); + return WMError::WM_OK; } if (!remoteObject->AddDeathRecipient(windowDeath_)) { WLOGFI("failed to add death recipient"); @@ -133,6 +132,21 @@ WMError WindowRoot::RemoveWindowNode(uint32_t windowId) return container->RemoveWindowNode(node); } +WMError WindowRoot::UpdateWindowNode(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; + } + return container->UpdateWindowNode(node); +} + WMError WindowRoot::DestroyWindow(uint32_t windowId) { auto node = GetWindowNode(windowId); @@ -161,16 +175,20 @@ WMError WindowRoot::DestroyWindowInner(sptr& node) WLOGFE("window has been destroyed"); return WMError::WM_ERROR_DESTROYED_OBJECT; } + sptr window = node->GetWindowToken(); - if (windowIdMap_.count(window->AsObject()) == 0) { - WLOGFI("window remote object has been destroyed"); - return WMError::WM_ERROR_DESTROYED_OBJECT; + if ((window != nullptr) && (window->AsObject() != nullptr)) { + if (windowIdMap_.count(window->AsObject()) == 0) { + WLOGFI("window remote object has been destroyed"); + return WMError::WM_ERROR_DESTROYED_OBJECT; + } + + if (window->AsObject() != nullptr) { + window->AsObject()->RemoveDeathRecipient(windowDeath_); + } + windowIdMap_.erase(window->AsObject()); } - if (window->AsObject() != nullptr) { - window->AsObject()->RemoveDeathRecipient(windowDeath_); - } - windowIdMap_.erase(window->AsObject()); windowNodeMap_.erase(node->GetWindowId()); return WMError::WM_OK; } @@ -182,6 +200,10 @@ WMError WindowRoot::RequestFocus(uint32_t windowId) WLOGFE("could not find window"); return WMError::WM_ERROR_NULLPTR; } + if (!node->currentVisibility_) { + WLOGFE("could not request focus before it has shown"); + return WMError::WM_ERROR_INVALID_OPERATION; + } auto container = GetOrCreateWindowNodeContainer(node->GetDisplayId()); if (container == nullptr) { WLOGFE("window container could not be found"); @@ -190,8 +212,48 @@ WMError WindowRoot::RequestFocus(uint32_t windowId) return container->SetFocusWindow(windowId); } +void WindowRoot::RegisterFocusChangedListener(const sptr& windowManagerAgent) +{ + focusChangedListenerAgents_.push_back(windowManagerAgent); + if (windowManagerAgentDeath_ == nullptr) { + WLOGFI("failed to create death Recipient ptr WindowManagerAgentDeathRecipient"); + return; + } + if (!windowManagerAgent->AsObject()->AddDeathRecipient(windowManagerAgentDeath_)) { + WLOGFI("failed to add death recipient"); + } +} + +void WindowRoot::UnregisterFocusChangedListener(const sptr& windowManagerAgent) +{ + auto iter = std::find(focusChangedListenerAgents_.begin(), focusChangedListenerAgents_.end(), windowManagerAgent); + if (iter == focusChangedListenerAgents_.end()) { + WLOGFE("could not find this listener"); + return; + } + focusChangedListenerAgents_.erase(iter); +} + +void WindowRoot::UnregisterFocusChangedListener(const sptr& object) +{ + for (auto iter = focusChangedListenerAgents_.begin(); iter < focusChangedListenerAgents_.end(); ++iter) { + if ((*iter)->AsObject() != nullptr && (*iter)->AsObject() == object) { + iter = focusChangedListenerAgents_.erase(iter); + } + } +} + +void WindowRoot::UpdateFocusStatus(uint32_t windowId, const sptr& abilityToken, WindowType windowType, + int32_t displayId, bool focused) +{ + for (auto& windowManagerAgent : focusChangedListenerAgents_) { + windowManagerAgent->UpdateFocusStatus(windowId, abilityToken, windowType, displayId, focused); + } +} + void WindowRoot::ClearWindow(const sptr& remoteObject) { + std::lock_guard lock(mutex_); auto iter = windowIdMap_.find(remoteObject); if (iter == windowIdMap_.end()) { WLOGFE("window id could not be found"); @@ -201,6 +263,16 @@ void WindowRoot::ClearWindow(const sptr& remoteObject) DestroyWindow(windowId); } +void WindowRoot::ClearWindowManagerAgent(const sptr& remoteObject) +{ + if (remoteObject == nullptr) { + WLOGFI("remoteObject is null"); + return; + } + std::lock_guard lock(mutex_); + UnregisterFocusChangedListener(remoteObject); +} + void WindowDeathRecipient::OnRemoteDied(const wptr& wptrDeath) { if (wptrDeath == nullptr) { @@ -213,6 +285,23 @@ void WindowDeathRecipient::OnRemoteDied(const wptr& wptrDeath) WLOGFE("object is null"); return; } + WLOGFI("WindowDeathRecipient callback"); + callback_(object); +} + +void WindowManagerAgentDeathRecipient::OnRemoteDied(const wptr& wptrDeath) +{ + if (wptrDeath == nullptr) { + WLOGFE("wptrDeath is null"); + return; + } + + sptr object = wptrDeath.promote(); + if (!object) { + WLOGFE("object is null"); + return; + } + WLOGFI("WindowManagerAgentDeathRecipient callback"); callback_(object); } } diff --git a/wmtest/BUILD.gn b/wmtest/BUILD.gn index 291691de..2d2d77b6 100644 --- a/wmtest/BUILD.gn +++ b/wmtest/BUILD.gn @@ -20,7 +20,7 @@ config("rosenwmtest_config") { include_dirs = [ "frameworks", -# for abilityContext + # for abilityContext "//foundation/aafwk/standard/frameworks/kits/ability/ability_runtime/include", "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base/include", "//base/global/resmgr_standard/interfaces/innerkits/include", @@ -30,7 +30,7 @@ config("rosenwmtest_config") { "//foundation/distributedschedule/dmsfwk/services/dtbschedmgr/include", "//foundation/aafwk/standard/interfaces/innerkits/base/include", -# RSSurface + # RSSurface "//foundation/graphic/standard/rosen/modules/render_service_client:librender_service_client", "//foundation/graphic/standard/rosen/modules/render_service_base:librender_service_base", ] @@ -48,8 +48,8 @@ ohos_executable("rosenwmtest") { sources = [ "frameworks/inative_test.cpp", "frameworks/main.cpp", - "test/wm_native_test.cpp", "test/dm_native_test.cpp", + "test/wm_native_test.cpp", ] configs = [ ":rosenwmtest_config" ] @@ -59,16 +59,16 @@ ohos_executable("rosenwmtest") { "//foundation/graphic/standard:libvsync_client", "//foundation/graphic/standard:libwmclient", "//foundation/graphic/standard:libwmservice", - "//third_party/zlib:libz", "//foundation/windowmanager/adapter:libwmadaptertest", "//foundation/windowmanager/wm:libwm", - "//foundation/windowmanager/wmserver:libwms", "//foundation/windowmanager/wm:libwmutil", + "//foundation/windowmanager/wmserver:libwms", + "//third_party/zlib:libz", -# native value - "//foundation/ace/napi:ace_napi", -# ace + # ace + # native value "//foundation/ace/ace_engine/interfaces/innerkits/ace:ace_uicontent", + "//foundation/ace/napi:ace_napi", ] part_name = "window_manager" diff --git a/wmtest/test/dm_native_test.cpp b/wmtest/test/dm_native_test.cpp index 8349b623..3c1a9711 100644 --- a/wmtest/test/dm_native_test.cpp +++ b/wmtest/test/dm_native_test.cpp @@ -15,6 +15,7 @@ #include "dm_native_test.h" +#include #include #include #include "display_manager.h" @@ -61,13 +62,13 @@ void DMNativeTest::Run(int32_t argc, const char **argv) } DisplayId displayId = dms->GetDefaultDisplayId(); - printf("defaultDisplayId: %llu\n", displayId); + printf("defaultDisplayId: %" PRIu64"\n", displayId); auto display = dms->GetDefaultDisplay(); if (display == nullptr) { printf("GetDefaultDisplay: failed!\n"); } else { - printf("GetDefaultDisplay: id %llu, w %d, h %d, fps %u\n", display->GetId(), display->GetWidth(), + printf("GetDefaultDisplay: id %" PRIu64", w %d, h %d, fps %u\n", display->GetId(), display->GetWidth(), display->GetHeight(), display->GetFreshRate()); } @@ -75,10 +76,10 @@ void DMNativeTest::Run(int32_t argc, const char **argv) for (auto id: ids) { display = dms->GetDisplayById(displayId); if (display == nullptr) { - printf("GetDisplayById(%llu): failed!\n", id); + printf("GetDisplayById(%" PRIu64"): failed!\n", id); } else { - printf("GetDisplayById(%llu): id %llu, w %d, h %d, fps %u\n", id, display->GetId(), display->GetWidth(), - display->GetHeight(), display->GetFreshRate()); + printf("GetDisplayById(%" PRIu64"): id %" PRIu64", w %d, h %d, fps %u\n", id, display->GetId(), + display->GetWidth(), display->GetHeight(), display->GetFreshRate()); } } @@ -87,7 +88,7 @@ void DMNativeTest::Run(int32_t argc, const char **argv) if (disp == nullptr) { printf("GetAllDisplays: failed!\n"); } else { - printf("GetAllDisplays: id %llu, w %d, h %d, fps %u\n", disp->GetId(), disp->GetWidth(), + printf("GetAllDisplays: id %" PRIu64", w %d, h %d, fps %u\n", disp->GetId(), disp->GetWidth(), disp->GetHeight(), disp->GetFreshRate()); } } diff --git a/wmtest/unittest/BUILD.gn b/wmtest/unittest/BUILD.gn index 0bc02493..b034b699 100644 --- a/wmtest/unittest/BUILD.gn +++ b/wmtest/unittest/BUILD.gn @@ -26,9 +26,7 @@ ohos_unittest("ut_window_impl_test") { sources = [ "src/window_impl_test.cpp" ] - deps = [ - ":unittest_wmtest_common" - ] + deps = [ ":unittest_wmtest_common" ] } ## UnitTest ut_window_impl_test }}} @@ -46,11 +44,11 @@ config("unittest_wmtest_common_public_config") { "//foundation/windowmanager/utils/include", "//third_party/googletest/googlemock/include", -#RSSurface + #RSSurface "//foundation/graphic/standard/rosen/modules/render_service_client/core", "//foundation/graphic/standard/rosen/modules/render_service_base/include", "//third_party/flutter/skia", - ] + ] cflags = [ "-Wall", @@ -69,21 +67,19 @@ ohos_static_library("unittest_wmtest_common") { deps = [ "//foundation/windowmanager/wm:libwm", + "//foundation/windowmanager/wm:libwmutil", "//foundation/windowmanager/wmserver:libwms", "//third_party/googletest:gmock", "//utils/native/base:utils", - "//foundation/windowmanager/wm:libwmutil", -# RSSurface - "//foundation/graphic/standard/rosen/modules/render_service_client:librender_service_client", + # RSSurface "//foundation/graphic/standard/rosen/modules/render_service_base:librender_service_base", + "//foundation/graphic/standard/rosen/modules/render_service_client:librender_service_client", ] external_deps = [ + "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", - "hiviewdfx_hilog_native:libhilog" ] - - } ## Build unittest_wmtest_common.a }}}