From 0a4d4c93fa1e89a0ad47b5b4926ee0b1ed5424d3 Mon Sep 17 00:00:00 2001 From: abbuu Date: Fri, 31 Dec 2021 17:19:28 +0800 Subject: [PATCH] Enable windowmangaer Signed-off-by: abbuu --- README.md | 730 +++++++++++++++++- README_zh.md | 361 +++++++++ adapter/BUILD.gn | 98 +++ adapter/include/adapter.h | 63 ++ adapter/src/adapter.cpp | 327 ++++++++ dm/include/README.md | 1 + dm/include/display_manager_adapter.h | 54 ++ dm/src/README.md | 1 + dm/src/display.cpp | 68 ++ dm/src/display_manager.cpp | 97 +++ dm/src/display_manager_adapter.cpp | 143 ++++ dm/src/monitor.cpp | 19 + dmserver/include/README.md | 1 + dmserver/include/display_info.h | 43 ++ dmserver/include/display_manager_interface.h | 41 + dmserver/include/display_manager_proxy.h | 39 + dmserver/include/display_manager_service.h | 57 ++ .../include/display_manager_service_inner.h | 39 + dmserver/include/display_manager_stub.h | 33 + dmserver/include/display_node_control.h | 25 + dmserver/include/display_screen.h | 45 ++ dmserver/include/display_screen_manager.h | 44 ++ dmserver/include/rs_adapter.h | 48 ++ dmserver/include/screen.h | 25 + dmserver/src/README.md | 1 + dmserver/src/display_info.cpp | 56 ++ dmserver/src/display_manager_proxy.cpp | 104 +++ dmserver/src/display_manager_service.cpp | 113 +++ .../src/display_manager_service_inner.cpp | 89 +++ dmserver/src/display_manager_stub.cpp | 59 ++ dmserver/src/display_node_control.cpp | 19 + dmserver/src/display_screen.cpp | 66 ++ dmserver/src/display_screen_manager.cpp | 51 ++ dmserver/src/rs_adapter.cpp | 99 +++ dmserver/src/screen.cpp | 19 + figures/graphic.png | Bin 0 -> 46331 bytes interfaces/innerkits/BUILD.gn | 35 + interfaces/innerkits/dm/README.md | 1 + interfaces/innerkits/dm/display.h | 56 ++ interfaces/innerkits/dm/display_manager.h | 48 ++ interfaces/innerkits/dm/display_property.h | 38 + interfaces/innerkits/dm/monitor.h | 24 + interfaces/innerkits/dmserver/README.md | 1 + interfaces/innerkits/wm/README.md | 1 + interfaces/innerkits/wm/window.h | 81 ++ .../wm/window_life_cycle_interface.h | 32 + interfaces/innerkits/wm/window_option.h | 63 ++ interfaces/innerkits/wm/window_scene.h | 57 ++ interfaces/innerkits/wm/wm_common.h | 96 +++ interfaces/innerkits/wmserver/README.md | 1 + interfaces/kits/README.md | 1 + interfaces/kits/js/declaration/BUILD.gn | 29 + .../js/declaration/api/@ohos.display.d.ts | 135 ++++ .../kits/js/declaration/api/@ohos.window.d.ts | 79 ++ interfaces/kits/napi/BUILD.gn | 58 ++ interfaces/kits/napi/common/BUILD.gn | 46 ++ .../kits/napi/common/wm_napi_common.cpp | 44 ++ interfaces/kits/napi/common/wm_napi_common.h | 111 +++ interfaces/kits/napi/display/BUILD.gn | 30 + .../napi/display/native_display_module.cpp | 116 +++ .../kits/napi/display/native_display_module.h | 19 + interfaces/kits/napi/window/BUILD.gn | 40 + .../kits/napi/window/native_window_module.cpp | 233 ++++++ .../kits/napi/window/native_window_module.h | 19 + interfaces/kits/napi/window_stage.js | 26 + interfaces/kits/napi/window_stage_module.cpp | 58 ++ ohos.build | 22 + sa_profile/4605.xml | 26 + sa_profile/4606.xml | 26 + sa_profile/BUILD.gn | 22 + utils/include/single_instance.h | 44 ++ utils/include/singleton_container.h | 81 ++ utils/include/singleton_delegator.h | 57 ++ utils/include/static_call.h | 39 + utils/include/window_manager_hilog.h | 50 ++ utils/src/singleton_container.cpp | 110 +++ utils/src/static_call.cpp | 28 + wm/BUILD.gn | 161 ++++ wm/include/README.md | 1 + wm/include/input_transfer_station.h | 55 ++ wm/include/vsync_station.h | 59 ++ wm/include/window_adapter.h | 61 ++ wm/include/window_agent.h | 39 + wm/include/window_impl.h | 122 +++ wm/include/window_input_channel.h | 44 ++ wm/include/window_interface.h | 42 + wm/include/window_property.h | 79 ++ wm/include/window_proxy.h | 40 + wm/include/window_stub.h | 34 + wm/src/README.md | 1 + wm/src/input_transfer_station.cpp | 114 +++ wm/src/vsync_station.cpp | 69 ++ wm/src/window.cpp | 49 ++ wm/src/window_adapter.cpp | 171 ++++ wm/src/window_agent.cpp | 61 ++ wm/src/window_impl.cpp | 428 ++++++++++ wm/src/window_input_channel.cpp | 83 ++ wm/src/window_option.cpp | 126 +++ wm/src/window_property.cpp | 238 ++++++ wm/src/window_proxy.cpp | 97 +++ wm/src/window_scene.cpp | 127 +++ wm/src/window_stub.cpp | 59 ++ wmserver/BUILD.gn | 85 ++ wmserver/include/README.md | 1 + wmserver/include/input_window_monitor.h | 72 ++ wmserver/include/window_controller.h | 48 ++ wmserver/include/window_layout_policy.h | 53 ++ wmserver/include/window_manager_interface.h | 52 ++ wmserver/include/window_manager_proxy.h | 45 ++ wmserver/include/window_manager_service.h | 63 ++ wmserver/include/window_manager_stub.h | 32 + wmserver/include/window_node.h | 82 ++ wmserver/include/window_node_container.h | 76 ++ wmserver/include/window_root.h | 65 ++ wmserver/include/window_zorder_policy.h | 63 ++ wmserver/src/README.md | 1 + wmserver/src/input_window_monitor.cpp | 87 +++ wmserver/src/window_controller.cpp | 153 ++++ wmserver/src/window_layout_policy.cpp | 184 +++++ wmserver/src/window_manager_proxy.cpp | 247 ++++++ wmserver/src/window_manager_service.cpp | 134 ++++ wmserver/src/window_manager_stub.cpp | 101 +++ wmserver/src/window_node.cpp | 86 +++ wmserver/src/window_node_container.cpp | 366 +++++++++ wmserver/src/window_root.cpp | 219 ++++++ wmserver/src/window_zorder_policy.cpp | 34 + wmtest/BUILD.gn | 84 ++ wmtest/README.en.md | 36 + wmtest/README.md | 39 + wmtest/adapter/BUILD.gn | 98 +++ wmtest/adapter/include/adapter.h | 63 ++ wmtest/adapter/src/adapter.cpp | 327 ++++++++ wmtest/dm/include/README.md | 1 + wmtest/dm/include/display_manager_adapter.h | 54 ++ wmtest/dm/src/README.md | 1 + wmtest/dm/src/display.cpp | 68 ++ wmtest/dm/src/display_manager.cpp | 97 +++ wmtest/dm/src/display_manager_adapter.cpp | 143 ++++ wmtest/dm/src/monitor.cpp | 19 + wmtest/dmserver/include/README.md | 1 + wmtest/dmserver/include/display_info.h | 43 ++ .../include/display_manager_interface.h | 41 + .../dmserver/include/display_manager_proxy.h | 39 + .../include/display_manager_service.h | 57 ++ .../include/display_manager_service_inner.h | 39 + .../dmserver/include/display_manager_stub.h | 33 + .../dmserver/include/display_node_control.h | 25 + wmtest/dmserver/include/display_screen.h | 45 ++ .../dmserver/include/display_screen_manager.h | 44 ++ wmtest/dmserver/include/rs_adapter.h | 48 ++ wmtest/dmserver/include/screen.h | 25 + wmtest/dmserver/src/README.md | 1 + wmtest/dmserver/src/display_info.cpp | 56 ++ wmtest/dmserver/src/display_manager_proxy.cpp | 104 +++ .../dmserver/src/display_manager_service.cpp | 113 +++ .../src/display_manager_service_inner.cpp | 89 +++ wmtest/dmserver/src/display_manager_stub.cpp | 59 ++ wmtest/dmserver/src/display_node_control.cpp | 19 + wmtest/dmserver/src/display_screen.cpp | 66 ++ .../dmserver/src/display_screen_manager.cpp | 51 ++ wmtest/dmserver/src/rs_adapter.cpp | 99 +++ wmtest/dmserver/src/screen.cpp | 19 + wmtest/frameworks/inative_test.cpp | 41 + wmtest/frameworks/inative_test.h | 48 ++ wmtest/frameworks/main.cpp | 88 +++ wmtest/interfaces/innerkits/BUILD.gn | 35 + wmtest/interfaces/innerkits/dm/README.md | 1 + wmtest/interfaces/innerkits/dm/display.h | 56 ++ .../interfaces/innerkits/dm/display_manager.h | 48 ++ .../innerkits/dm/display_property.h | 38 + wmtest/interfaces/innerkits/dm/monitor.h | 24 + .../interfaces/innerkits/dmserver/README.md | 1 + wmtest/interfaces/innerkits/wm/README.md | 1 + wmtest/interfaces/innerkits/wm/window.h | 81 ++ .../wm/window_life_cycle_interface.h | 32 + .../interfaces/innerkits/wm/window_option.h | 63 ++ wmtest/interfaces/innerkits/wm/window_scene.h | 57 ++ wmtest/interfaces/innerkits/wm/wm_common.h | 96 +++ .../interfaces/innerkits/wmserver/README.md | 1 + wmtest/interfaces/kits/README.md | 1 + .../interfaces/kits/js/declaration/BUILD.gn | 29 + .../js/declaration/api/@ohos.display.d.ts | 135 ++++ .../kits/js/declaration/api/@ohos.window.d.ts | 79 ++ wmtest/interfaces/kits/napi/BUILD.gn | 58 ++ wmtest/interfaces/kits/napi/common/BUILD.gn | 46 ++ .../kits/napi/common/wm_napi_common.cpp | 44 ++ .../kits/napi/common/wm_napi_common.h | 111 +++ wmtest/interfaces/kits/napi/display/BUILD.gn | 30 + .../napi/display/native_display_module.cpp | 116 +++ .../kits/napi/display/native_display_module.h | 19 + wmtest/interfaces/kits/napi/window/BUILD.gn | 40 + .../kits/napi/window/native_window_module.cpp | 233 ++++++ .../kits/napi/window/native_window_module.h | 19 + wmtest/interfaces/kits/napi/window_stage.js | 26 + .../kits/napi/window_stage_module.cpp | 58 ++ wmtest/ohos.build | 22 + wmtest/sa_profile/4605.xml | 26 + wmtest/sa_profile/4606.xml | 26 + wmtest/sa_profile/BUILD.gn | 22 + wmtest/test/dm_native_test.cpp | 96 +++ wmtest/test/dm_native_test.h | 40 + wmtest/test/wm_native_test.cpp | 74 ++ wmtest/test/wm_native_test.h | 39 + wmtest/unittest/BUILD.gn | 85 ++ .../include/mock/mock_window_adapter.h | 35 + .../unittest/include/mock/singleton_mocker.h | 54 ++ wmtest/unittest/include/test_header.h | 43 ++ wmtest/unittest/include/window_impl_test.h | 37 + wmtest/unittest/src/window_impl_test.cpp | 47 ++ wmtest/utils/include/single_instance.h | 44 ++ wmtest/utils/include/singleton_container.h | 81 ++ wmtest/utils/include/singleton_delegator.h | 57 ++ wmtest/utils/include/static_call.h | 39 + wmtest/utils/include/window_manager_hilog.h | 50 ++ wmtest/utils/src/singleton_container.cpp | 110 +++ wmtest/utils/src/static_call.cpp | 28 + wmtest/wm/BUILD.gn | 161 ++++ wmtest/wm/include/README.md | 1 + wmtest/wm/include/input_transfer_station.h | 55 ++ wmtest/wm/include/vsync_station.h | 59 ++ wmtest/wm/include/window_adapter.h | 61 ++ wmtest/wm/include/window_agent.h | 39 + wmtest/wm/include/window_impl.h | 122 +++ wmtest/wm/include/window_input_channel.h | 44 ++ wmtest/wm/include/window_interface.h | 42 + wmtest/wm/include/window_property.h | 79 ++ wmtest/wm/include/window_proxy.h | 40 + wmtest/wm/include/window_stub.h | 34 + wmtest/wm/src/README.md | 1 + wmtest/wm/src/input_transfer_station.cpp | 114 +++ wmtest/wm/src/vsync_station.cpp | 69 ++ wmtest/wm/src/window.cpp | 49 ++ wmtest/wm/src/window_adapter.cpp | 171 ++++ wmtest/wm/src/window_agent.cpp | 61 ++ wmtest/wm/src/window_impl.cpp | 428 ++++++++++ wmtest/wm/src/window_input_channel.cpp | 83 ++ wmtest/wm/src/window_option.cpp | 126 +++ wmtest/wm/src/window_property.cpp | 238 ++++++ wmtest/wm/src/window_proxy.cpp | 97 +++ wmtest/wm/src/window_scene.cpp | 127 +++ wmtest/wm/src/window_stub.cpp | 59 ++ wmtest/wmserver/BUILD.gn | 85 ++ wmtest/wmserver/include/README.md | 1 + .../wmserver/include/input_window_monitor.h | 72 ++ wmtest/wmserver/include/window_controller.h | 48 ++ .../wmserver/include/window_layout_policy.h | 53 ++ .../include/window_manager_interface.h | 52 ++ .../wmserver/include/window_manager_proxy.h | 45 ++ .../wmserver/include/window_manager_service.h | 63 ++ wmtest/wmserver/include/window_manager_stub.h | 32 + wmtest/wmserver/include/window_node.h | 82 ++ .../wmserver/include/window_node_container.h | 76 ++ wmtest/wmserver/include/window_root.h | 65 ++ .../wmserver/include/window_zorder_policy.h | 63 ++ wmtest/wmserver/src/README.md | 1 + wmtest/wmserver/src/input_window_monitor.cpp | 87 +++ wmtest/wmserver/src/window_controller.cpp | 153 ++++ wmtest/wmserver/src/window_layout_policy.cpp | 184 +++++ wmtest/wmserver/src/window_manager_proxy.cpp | 247 ++++++ .../wmserver/src/window_manager_service.cpp | 134 ++++ wmtest/wmserver/src/window_manager_stub.cpp | 101 +++ wmtest/wmserver/src/window_node.cpp | 86 +++ wmtest/wmserver/src/window_node_container.cpp | 366 +++++++++ wmtest/wmserver/src/window_root.cpp | 219 ++++++ wmtest/wmserver/src/window_zorder_policy.cpp | 34 + 265 files changed, 19508 insertions(+), 27 deletions(-) create mode 100644 README_zh.md create mode 100644 adapter/BUILD.gn create mode 100644 adapter/include/adapter.h create mode 100644 adapter/src/adapter.cpp create mode 100644 dm/include/README.md create mode 100644 dm/include/display_manager_adapter.h create mode 100644 dm/src/README.md create mode 100644 dm/src/display.cpp create mode 100644 dm/src/display_manager.cpp create mode 100644 dm/src/display_manager_adapter.cpp create mode 100644 dm/src/monitor.cpp create mode 100644 dmserver/include/README.md create mode 100644 dmserver/include/display_info.h create mode 100644 dmserver/include/display_manager_interface.h create mode 100644 dmserver/include/display_manager_proxy.h create mode 100644 dmserver/include/display_manager_service.h create mode 100644 dmserver/include/display_manager_service_inner.h create mode 100644 dmserver/include/display_manager_stub.h create mode 100644 dmserver/include/display_node_control.h create mode 100644 dmserver/include/display_screen.h create mode 100644 dmserver/include/display_screen_manager.h create mode 100644 dmserver/include/rs_adapter.h create mode 100644 dmserver/include/screen.h create mode 100644 dmserver/src/README.md create mode 100644 dmserver/src/display_info.cpp create mode 100644 dmserver/src/display_manager_proxy.cpp create mode 100644 dmserver/src/display_manager_service.cpp create mode 100644 dmserver/src/display_manager_service_inner.cpp create mode 100644 dmserver/src/display_manager_stub.cpp create mode 100644 dmserver/src/display_node_control.cpp create mode 100644 dmserver/src/display_screen.cpp create mode 100644 dmserver/src/display_screen_manager.cpp create mode 100644 dmserver/src/rs_adapter.cpp create mode 100644 dmserver/src/screen.cpp create mode 100644 figures/graphic.png create mode 100644 interfaces/innerkits/BUILD.gn create mode 100644 interfaces/innerkits/dm/README.md create mode 100644 interfaces/innerkits/dm/display.h create mode 100644 interfaces/innerkits/dm/display_manager.h create mode 100644 interfaces/innerkits/dm/display_property.h create mode 100644 interfaces/innerkits/dm/monitor.h create mode 100644 interfaces/innerkits/dmserver/README.md create mode 100644 interfaces/innerkits/wm/README.md create mode 100644 interfaces/innerkits/wm/window.h create mode 100644 interfaces/innerkits/wm/window_life_cycle_interface.h create mode 100644 interfaces/innerkits/wm/window_option.h create mode 100644 interfaces/innerkits/wm/window_scene.h create mode 100644 interfaces/innerkits/wm/wm_common.h create mode 100644 interfaces/innerkits/wmserver/README.md create mode 100644 interfaces/kits/README.md create mode 100644 interfaces/kits/js/declaration/BUILD.gn create mode 100644 interfaces/kits/js/declaration/api/@ohos.display.d.ts create mode 100644 interfaces/kits/js/declaration/api/@ohos.window.d.ts create mode 100644 interfaces/kits/napi/BUILD.gn create mode 100644 interfaces/kits/napi/common/BUILD.gn create mode 100644 interfaces/kits/napi/common/wm_napi_common.cpp create mode 100644 interfaces/kits/napi/common/wm_napi_common.h create mode 100644 interfaces/kits/napi/display/BUILD.gn create mode 100644 interfaces/kits/napi/display/native_display_module.cpp create mode 100644 interfaces/kits/napi/display/native_display_module.h create mode 100644 interfaces/kits/napi/window/BUILD.gn create mode 100644 interfaces/kits/napi/window/native_window_module.cpp create mode 100644 interfaces/kits/napi/window/native_window_module.h create mode 100644 interfaces/kits/napi/window_stage.js create mode 100644 interfaces/kits/napi/window_stage_module.cpp create mode 100644 ohos.build create mode 100644 sa_profile/4605.xml create mode 100644 sa_profile/4606.xml create mode 100644 sa_profile/BUILD.gn create mode 100644 utils/include/single_instance.h create mode 100644 utils/include/singleton_container.h create mode 100644 utils/include/singleton_delegator.h create mode 100644 utils/include/static_call.h create mode 100644 utils/include/window_manager_hilog.h create mode 100644 utils/src/singleton_container.cpp create mode 100644 utils/src/static_call.cpp create mode 100644 wm/BUILD.gn create mode 100644 wm/include/README.md create mode 100644 wm/include/input_transfer_station.h create mode 100644 wm/include/vsync_station.h create mode 100644 wm/include/window_adapter.h create mode 100644 wm/include/window_agent.h create mode 100644 wm/include/window_impl.h create mode 100644 wm/include/window_input_channel.h create mode 100644 wm/include/window_interface.h create mode 100644 wm/include/window_property.h create mode 100644 wm/include/window_proxy.h create mode 100644 wm/include/window_stub.h create mode 100644 wm/src/README.md create mode 100644 wm/src/input_transfer_station.cpp create mode 100644 wm/src/vsync_station.cpp create mode 100644 wm/src/window.cpp create mode 100644 wm/src/window_adapter.cpp create mode 100644 wm/src/window_agent.cpp create mode 100644 wm/src/window_impl.cpp create mode 100644 wm/src/window_input_channel.cpp create mode 100644 wm/src/window_option.cpp create mode 100644 wm/src/window_property.cpp create mode 100644 wm/src/window_proxy.cpp create mode 100644 wm/src/window_scene.cpp create mode 100644 wm/src/window_stub.cpp create mode 100644 wmserver/BUILD.gn create mode 100644 wmserver/include/README.md create mode 100644 wmserver/include/input_window_monitor.h create mode 100644 wmserver/include/window_controller.h create mode 100644 wmserver/include/window_layout_policy.h create mode 100644 wmserver/include/window_manager_interface.h create mode 100644 wmserver/include/window_manager_proxy.h create mode 100644 wmserver/include/window_manager_service.h create mode 100644 wmserver/include/window_manager_stub.h create mode 100644 wmserver/include/window_node.h create mode 100644 wmserver/include/window_node_container.h create mode 100644 wmserver/include/window_root.h create mode 100644 wmserver/include/window_zorder_policy.h create mode 100644 wmserver/src/README.md create mode 100644 wmserver/src/input_window_monitor.cpp create mode 100644 wmserver/src/window_controller.cpp create mode 100644 wmserver/src/window_layout_policy.cpp create mode 100644 wmserver/src/window_manager_proxy.cpp create mode 100644 wmserver/src/window_manager_service.cpp create mode 100644 wmserver/src/window_manager_stub.cpp create mode 100644 wmserver/src/window_node.cpp create mode 100644 wmserver/src/window_node_container.cpp create mode 100644 wmserver/src/window_root.cpp create mode 100644 wmserver/src/window_zorder_policy.cpp create mode 100644 wmtest/BUILD.gn create mode 100644 wmtest/README.en.md create mode 100644 wmtest/README.md create mode 100644 wmtest/adapter/BUILD.gn create mode 100644 wmtest/adapter/include/adapter.h create mode 100644 wmtest/adapter/src/adapter.cpp create mode 100644 wmtest/dm/include/README.md create mode 100644 wmtest/dm/include/display_manager_adapter.h create mode 100644 wmtest/dm/src/README.md create mode 100644 wmtest/dm/src/display.cpp create mode 100644 wmtest/dm/src/display_manager.cpp create mode 100644 wmtest/dm/src/display_manager_adapter.cpp create mode 100644 wmtest/dm/src/monitor.cpp create mode 100644 wmtest/dmserver/include/README.md create mode 100644 wmtest/dmserver/include/display_info.h create mode 100644 wmtest/dmserver/include/display_manager_interface.h create mode 100644 wmtest/dmserver/include/display_manager_proxy.h create mode 100644 wmtest/dmserver/include/display_manager_service.h create mode 100644 wmtest/dmserver/include/display_manager_service_inner.h create mode 100644 wmtest/dmserver/include/display_manager_stub.h create mode 100644 wmtest/dmserver/include/display_node_control.h create mode 100644 wmtest/dmserver/include/display_screen.h create mode 100644 wmtest/dmserver/include/display_screen_manager.h create mode 100644 wmtest/dmserver/include/rs_adapter.h create mode 100644 wmtest/dmserver/include/screen.h create mode 100644 wmtest/dmserver/src/README.md create mode 100644 wmtest/dmserver/src/display_info.cpp create mode 100644 wmtest/dmserver/src/display_manager_proxy.cpp create mode 100644 wmtest/dmserver/src/display_manager_service.cpp create mode 100644 wmtest/dmserver/src/display_manager_service_inner.cpp create mode 100644 wmtest/dmserver/src/display_manager_stub.cpp create mode 100644 wmtest/dmserver/src/display_node_control.cpp create mode 100644 wmtest/dmserver/src/display_screen.cpp create mode 100644 wmtest/dmserver/src/display_screen_manager.cpp create mode 100644 wmtest/dmserver/src/rs_adapter.cpp create mode 100644 wmtest/dmserver/src/screen.cpp create mode 100644 wmtest/frameworks/inative_test.cpp create mode 100644 wmtest/frameworks/inative_test.h create mode 100644 wmtest/frameworks/main.cpp create mode 100644 wmtest/interfaces/innerkits/BUILD.gn create mode 100644 wmtest/interfaces/innerkits/dm/README.md create mode 100644 wmtest/interfaces/innerkits/dm/display.h create mode 100644 wmtest/interfaces/innerkits/dm/display_manager.h create mode 100644 wmtest/interfaces/innerkits/dm/display_property.h create mode 100644 wmtest/interfaces/innerkits/dm/monitor.h create mode 100644 wmtest/interfaces/innerkits/dmserver/README.md create mode 100644 wmtest/interfaces/innerkits/wm/README.md create mode 100644 wmtest/interfaces/innerkits/wm/window.h create mode 100644 wmtest/interfaces/innerkits/wm/window_life_cycle_interface.h create mode 100644 wmtest/interfaces/innerkits/wm/window_option.h create mode 100644 wmtest/interfaces/innerkits/wm/window_scene.h create mode 100644 wmtest/interfaces/innerkits/wm/wm_common.h create mode 100644 wmtest/interfaces/innerkits/wmserver/README.md create mode 100644 wmtest/interfaces/kits/README.md create mode 100644 wmtest/interfaces/kits/js/declaration/BUILD.gn create mode 100644 wmtest/interfaces/kits/js/declaration/api/@ohos.display.d.ts create mode 100644 wmtest/interfaces/kits/js/declaration/api/@ohos.window.d.ts create mode 100644 wmtest/interfaces/kits/napi/BUILD.gn create mode 100644 wmtest/interfaces/kits/napi/common/BUILD.gn create mode 100644 wmtest/interfaces/kits/napi/common/wm_napi_common.cpp create mode 100644 wmtest/interfaces/kits/napi/common/wm_napi_common.h create mode 100644 wmtest/interfaces/kits/napi/display/BUILD.gn create mode 100644 wmtest/interfaces/kits/napi/display/native_display_module.cpp create mode 100644 wmtest/interfaces/kits/napi/display/native_display_module.h create mode 100644 wmtest/interfaces/kits/napi/window/BUILD.gn create mode 100644 wmtest/interfaces/kits/napi/window/native_window_module.cpp create mode 100644 wmtest/interfaces/kits/napi/window/native_window_module.h create mode 100644 wmtest/interfaces/kits/napi/window_stage.js create mode 100644 wmtest/interfaces/kits/napi/window_stage_module.cpp create mode 100644 wmtest/ohos.build create mode 100644 wmtest/sa_profile/4605.xml create mode 100644 wmtest/sa_profile/4606.xml create mode 100644 wmtest/sa_profile/BUILD.gn create mode 100644 wmtest/test/dm_native_test.cpp create mode 100644 wmtest/test/dm_native_test.h create mode 100644 wmtest/test/wm_native_test.cpp create mode 100644 wmtest/test/wm_native_test.h create mode 100644 wmtest/unittest/BUILD.gn create mode 100644 wmtest/unittest/include/mock/mock_window_adapter.h create mode 100644 wmtest/unittest/include/mock/singleton_mocker.h create mode 100644 wmtest/unittest/include/test_header.h create mode 100644 wmtest/unittest/include/window_impl_test.h create mode 100644 wmtest/unittest/src/window_impl_test.cpp create mode 100644 wmtest/utils/include/single_instance.h create mode 100644 wmtest/utils/include/singleton_container.h create mode 100644 wmtest/utils/include/singleton_delegator.h create mode 100644 wmtest/utils/include/static_call.h create mode 100644 wmtest/utils/include/window_manager_hilog.h create mode 100644 wmtest/utils/src/singleton_container.cpp create mode 100644 wmtest/utils/src/static_call.cpp create mode 100644 wmtest/wm/BUILD.gn create mode 100644 wmtest/wm/include/README.md create mode 100644 wmtest/wm/include/input_transfer_station.h create mode 100644 wmtest/wm/include/vsync_station.h create mode 100644 wmtest/wm/include/window_adapter.h create mode 100644 wmtest/wm/include/window_agent.h create mode 100644 wmtest/wm/include/window_impl.h create mode 100644 wmtest/wm/include/window_input_channel.h create mode 100644 wmtest/wm/include/window_interface.h create mode 100644 wmtest/wm/include/window_property.h create mode 100644 wmtest/wm/include/window_proxy.h create mode 100644 wmtest/wm/include/window_stub.h create mode 100644 wmtest/wm/src/README.md create mode 100644 wmtest/wm/src/input_transfer_station.cpp create mode 100644 wmtest/wm/src/vsync_station.cpp create mode 100644 wmtest/wm/src/window.cpp create mode 100644 wmtest/wm/src/window_adapter.cpp create mode 100644 wmtest/wm/src/window_agent.cpp create mode 100644 wmtest/wm/src/window_impl.cpp create mode 100644 wmtest/wm/src/window_input_channel.cpp create mode 100644 wmtest/wm/src/window_option.cpp create mode 100644 wmtest/wm/src/window_property.cpp create mode 100644 wmtest/wm/src/window_proxy.cpp create mode 100644 wmtest/wm/src/window_scene.cpp create mode 100644 wmtest/wm/src/window_stub.cpp create mode 100644 wmtest/wmserver/BUILD.gn create mode 100644 wmtest/wmserver/include/README.md create mode 100644 wmtest/wmserver/include/input_window_monitor.h create mode 100644 wmtest/wmserver/include/window_controller.h create mode 100644 wmtest/wmserver/include/window_layout_policy.h create mode 100644 wmtest/wmserver/include/window_manager_interface.h create mode 100644 wmtest/wmserver/include/window_manager_proxy.h create mode 100644 wmtest/wmserver/include/window_manager_service.h create mode 100644 wmtest/wmserver/include/window_manager_stub.h create mode 100644 wmtest/wmserver/include/window_node.h create mode 100644 wmtest/wmserver/include/window_node_container.h create mode 100644 wmtest/wmserver/include/window_root.h create mode 100644 wmtest/wmserver/include/window_zorder_policy.h create mode 100644 wmtest/wmserver/src/README.md create mode 100644 wmtest/wmserver/src/input_window_monitor.cpp create mode 100644 wmtest/wmserver/src/window_controller.cpp create mode 100644 wmtest/wmserver/src/window_layout_policy.cpp create mode 100644 wmtest/wmserver/src/window_manager_proxy.cpp create mode 100644 wmtest/wmserver/src/window_manager_service.cpp create mode 100644 wmtest/wmserver/src/window_manager_stub.cpp create mode 100644 wmtest/wmserver/src/window_node.cpp create mode 100644 wmtest/wmserver/src/window_node_container.cpp create mode 100644 wmtest/wmserver/src/window_root.cpp create mode 100644 wmtest/wmserver/src/window_zorder_policy.cpp diff --git a/README.md b/README.md index 098e283c85..cf45c01755 100644 --- a/README.md +++ b/README.md @@ -1,39 +1,715 @@ -# windowmanager +# Graphics -#### 介绍 -{**以下是 Gitee 平台说明,您可以替换此简介** -Gitee 是 OSCHINA 推出的基于 Git 的代码托管平台(同时支持 SVN)。专为开发者提供稳定、高效、安全的云端软件开发协作平台 -无论是个人、团队、或是企业,都能够用 Gitee 实现代码托管、项目管理、协作开发。企业项目请看 [https://gitee.com/enterprises](https://gitee.com/enterprises)} +- [Introduction](#section1333751883213) +- [Directory Structure](#section1882912343) +- [Constraints](#section68982123611) +- [Compilation and Building](#section671864110372) +- [Available APIs](#section197399520386) + - [WindowManager](#section5851104093816) + - [Window](#section3483122273912) + - [SubWindow](#section96481249183913) + - [Surface](#section12366161544010) + - [SurfaceBuffer](#section12001640184711) + - [VsyncHelper](#section1392116294211) -#### 软件架构 -软件架构说明 +- [Usage](#section18359134910422) + - [Transferring a Producer Surface](#section193464304411) + - [Creating a Producer Surface](#section1276823075112) + - [Producing a SurfaceBuffer](#section614545716513) + - [Consuming a SurfaceBuffer](#section315285412535) + - [Adding Custom Data to a SurfaceBuffer](#section612412125616) + - [Registering a Vsync Callback Listener](#section1148115214576) +- [\#EN-US\_TOPIC\_0000001105482134/section1939493174420](#section1939493174420) +- [Repositories Involved](#section6488145313) -#### 安装教程 +## Introduction -1. xxxx -2. xxxx -3. xxxx +The Graphics subsystem provides graphics and window management capabilities, which can be invoked by using Java or JS APIs. It can be used for UI development for all standard-system devices. -#### 使用说明 +The following figure shows the architecture of the Graphics subsystem. -1. xxxx -2. xxxx -3. xxxx +![](figures/graphic.png) -#### 参与贡献 +- Surface -1. Fork 本仓库 -2. 新建 Feat_xxx 分支 -3. 提交代码 -4. 新建 Pull Request + Provides APIs for managing the graphics buffer and the efficient and convenient rotation buffer. +- Vsync -#### 特技 + Provides APIs for managing registration and response of all vertical sync signals. + +- WindowManager + + Provides APIs for creating and managing windows. + +- WaylandProtocols + + Provides the communication protocols between the window manager and synthesizer. + +- Compositor + + Implements synthesis of layers. + +- Renderer + + Functions as the back-end rendering module of the synthesizer. + +- Wayland protocols + + Provides Wayland inter-process communication protocols. + +- Shell + + Provides multi-window capabilities. + +- Input Manger + + Functions as the multimodal input module that receives input events. + + +## Directory Structure + +``` +foundation/graphic/standard/ +├── frameworks # Framework code +│ ├── bootanimation # Boot Animation code +│ ├── surface # Surface code +│ ├── vsync # Vsync code +│ └── wm # WindowManager code +├── interfaces # External APIs +│ ├── innerkits # Native APIs +│ └── kits # JS APIs and NAPIs +└── utils # Utilities +``` + +## Constraints + +- Language version: C++ 11 or later + +## Compilation and Building + +The dependent APIs include the following: + +- graphic\_standard:libwms\_client +- graphic\_standard:libsurface +- graphic\_standard:libvsync\_client + +## Available APIs + +### WindowManager + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

API

+

Description

+

GetInstance

+

Obtains the pointer to a singleton WindowManager instance.

+

GetMaxWidth

+

Obtains the width of the screen.

+

GetMaxHeight

+

Obtains the height of the screen.

+

CreateWindow

+

Creates a standard window.

+

CreateSubWindow

+

Creates a child window.

+

StartShotScreen

+

Takes a screenshot.

+

StartShotWindow

+

Captures a window.

+

SwitchTop

+

Moves the specified window to the top.

+
+ +### Window + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

API

+

Description

+

Show

+

Displays the current window.

+

Hide

+

Hides the current window.

+

Move

+

Moves the current window to a specified position.

+

SwitchTop

+

Moves the current window to the top.

+

ChangeWindowType

+

Changes the type of the current window.

+

ReSize

+

Resizes the current window.

+

Rotate

+

Rotates the current window.

+

RegistPointerButtonCb

+

Registers the callback for Button events of the mouse.

+

RegistPointerEnterCb

+

Registers the callback for Enter events of the mouse.

+

RegistPointerLeaveCb

+

Registers the callback for Leave events of the mouse.

+

RegistPointerMotionCb

+

Registers the callback for Motion events of the mouse.

+

RegistPointerAxisDiscreteCb

+

Registers the callback for AxisDiscrete events of the mouse.

+

RegistPointerAxisSourceCb

+

Registers the callback for AxisSource events of the mouse.

+

RegistPointerAxisStopCb

+

Registers the callback for AxisStop events of the mouse.

+

RegistPointerAxisCb

+

Registers the callback for Axis events of the mouse.

+

RegistTouchUpCb

+

Registers the callback for TouchUp events.

+

RegistTouchDownCb

+

Registers the callback for TouchDown events.

+

RegistTouchEmotionCb

+

Registers the callback for TouchEmotion events.

+

RegistTouchFrameCb

+

Registers the callback for TouchFrame events.

+

RegistTouchCancelCb

+

Registers the callback for TouchCancel events.

+

RegistTouchShapeCb

+

Registers the callback for TouchShape events.

+

RegistTouchOrientationCb

+

Registers the callback for TouchOrientation events.

+

RegistKeyboardKeyCb

+

Registers the callback for Key events of the keyboard.

+

RegistKeyboardKeyMapCb

+

Registers the callback for KeyMap events of the keyboard.

+

RegistKeyboardLeaveCb

+

Registers the callback for Leave events of the keyboard.

+

RegistKeyboardEnterCb

+

Registers the callback for Enter events of the keyboard.

+

RegistKeyboardRepeatInfoCb

+

Registers the callback for RepeatInfo events of the keyboard.

+
+ +### SubWindow + + + + + + + + + + + + + +

API

+

Description

+

Move

+

Moves the current child window.

+

SetSubWindowSize

+

Sets the size of the current child window.

+
+ +### Surface + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

API

+

Description

+

CreateSurfaceAsConsumer

+

Creates a surface for the buffer consumer.

+

CreateSurfaceAsProducer

+

Creates a surface for the buffer producer. Only production-related APIs can be used.

+

GetProducer

+

Obtains an internal IBufferProducer object of Surface.

+

RequestBuffer

+

Requests a SurfaceBuffer object to be produced.

+

CancelBuffer

+

Cancels a SurfaceBuffer object to be produced.

+

FlushBuffer

+

Flushes a produced SurfaceBuffer object with certain information.

+

AcquireBuffer

+

Requests a SurfaceBuffer object to be consumed.

+

ReleaseBuffer

+

Returns a consumed SurfaceBuffer object.

+

GetQueueSize

+

Obtains the number of concurrent buffers.

+

SetQueueSize

+

Sets the number of concurrent buffers.

+

SetDefaultWidthAndHeight

+

Sets the default width and height.

+

GetDefaultWidth

+

Obtains the default width.

+

GetDefaultHeight

+

Obtains the default height.

+

SetUserData

+

Stores string data, which will not be transferred through IPC.

+

GetUserData

+

Obtains string data.

+

RegisterConsumerListener

+

Registers a consumer listener to listen for buffer flush events.

+

UnregisterConsumerListener

+

Unregiseters a consumer listener.

+
+ +### SurfaceBuffer + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

API

+

Description

+

GetBufferHandle

+

Obtains the BufferHandle pointer to the SurfaceBuffer object.

+

GetWidth

+

Obtains the width of the SurfaceBuffer object.

+

GetHeight

+

Obtains the height of the SurfaceBuffer object.

+

GetFormat

+

Obtains the color format of the SurfaceBuffer object.

+

GetUsage

+

Obtains the usage of the SurfaceBuffer object.

+

GetPhyAddr

+

Obtains the physical address of the SurfaceBuffer object.

+

GetKey

+

Obtains the key of the SurfaceBuffer object.

+

GetVirAddr

+

Obtains the virtual address of the SurfaceBuffer object.

+

GetSize

+

Obtains the size of the SurfaceBuffer object.

+

SetInt32

+

Sets the 32-bit integer for the SurfaceBuffer object.

+

GetInt32

+

Obtains the 32-bit integer for the SurfaceBuffer object.

+

SetInt64

+

Sets the 64-bit integer for the SurfaceBuffer object.

+

GetInt64

+

Obtains the 64-bit integer for the SurfaceBuffer object.

+
+ +### VsyncHelper + + + + + + + + + + + + + + + + +

API

+

Description

+

Current

+

Obtains the VsyncHelper object of the current runner.

+

VsyncHelper

+

Constructs a VsyncHelper object using an EventHandler object.

+

RequestFrameCallback

+

Registers a frame callback.

+
+ +## Usage + +### Transferring a Producer Surface + +1. Named service + - Service registration: + + ``` + // Obtain a consumer surface. + sptr surface = Surface::CreateSurfaceAsConsumer(); + // Extract the producer object. + sptr producer = surface->GetProducer(); + // Register the service. + auto sm = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + sm->AddSystemAbility(IPC_SA_ID, producer->AsObject()); + ``` + + - Construction of a producer surface: + + ``` + // Obtain a producer object. + auto sm = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + sptr robj = sm->GetSystemAbility(IPC_SA_ID); + // Construct a surface. + sptr bp = iface_cast(robj); + sptr surface = Surface::CreateSurfaceAsProducer(bp); + ``` + + +2. Anonymous service + - Sending of a surface: + + ``` + // Obtain a consumer surface. + sptr surface = CreateSurfaceAsConsumer(); + // Extract the producer object. + sptr producer = surface->GetProducer(); + // Return the producer object to the client. + parcel.WriteRemoteObject(producer); + ``` + + + +### Creating a Producer Surface + +``` +// Obtain a producer object. +sptr remoteObject = parcel.ReadRemoteObject(); +// Construct a surface. +sptr bp = iface_cast(robj); +sptr surface = Surface::CreateSurfaceAsProducer(bp); +``` + +### Producing a SurfaceBuffer + +``` +// Prerequisite: a producer surface +BufferRequestConfig requestConfig = { + .width = 1920, // Screen width + .height = 1080, // Screen height + .strideAlignment = 8, // Stride alignment byte + .format = PIXEL_FMT_RGBA_8888, // Color format + .usage = HBM_USE_CPU_READ | HBM_USE_CPU_WRITE | HBM_USE_MEM_DMA, // Usage + .timeout = 0, // Delay +}; + +sptr buffer; +int32_t releaseFence; + +SurfaceError ret = surface->RequestBuffer(buffer, releaseFence, requestConfig); +if (ret != SURFACE_ERROR_OK) { + // failed +} + +BufferFlushConfig flushConfig = { + .damage = { // Redrawing buffer zone + .x = 0, // Horizontal coordinate of the start point + .y = 0, // Vertical coordinate of the start point + .w = buffer->GetWidth(), // Width of the buffer zone + .h = buffer->GetHeight(), // Height of the buffer zone + }, + .timestamp = 0 // Time displayed to consumers. Value 0 indicates the current time. +}; + +ret = surface->FlushBuffer(buffer, -1, flushConfig); +if (ret != SURFACE_ERROR_OK) { + // failed +} +``` + +### Consuming a SurfaceBuffer + +``` +// Prerequisite: a consumer surface +class TestConsumerListener : public IBufferConsumerListener { +public: + void OnBufferAvailable() override { + sptr buffer; + int32_t flushFence; + SurfaceError ret = surface->AcquireBuffer(buffer, flushFence, timestamp, damage); + if (ret != SURFACE_ERROR_OK) { + // failed + } + // ... + ret = surface->ReleaseBuffer(buffer, -1); + if (ret != SURFACE_ERROR_OK) { + // failed + } + } +}; + +sptr listener = new TestConsumerListener(); +SurfaceError ret = surface->RegisterConsumerListener(listener); +if (ret != SURFACE_ERROR_OK) { + // failed +} +``` + +### Adding Custom Data to a SurfaceBuffer + +``` +sptr buffer; +SurfaceError ret = buffer->SetInt32(1, 3); +if (ret != SURFACE_ERROR_OK) { +// failed +} + +int32_t val; +ret = buffer->GetInt32(1, val); +if (ret != SURFACE_ERROR_OK) { +// failed +} +``` + +### Registering a Vsync Callback Listener + +1. Construct a **VsyncHelper** object using **handler**. + + ``` + auto runner = AppExecFwk::EventRunner::Create(true); + auto handler = std::make_shared(runner); + auto helper = new VsyncHelper(handler); + runner->Run(); + + struct FrameCallback cb = { + .timestamp_ = 0, + .userdata_ = nullptr, + .callback_ = [](int64_t timestamp, void* userdata) { + }, + }; + + VsyncError ret = helper->RequestFrameCallback(cb); + if (ret != VSYNC_ERROR_OK) { + // failed + } + ``` + +2. Use **Current** in **handler**. + + ``` + auto runner = AppExecFwk::EventRunner::Create(true); + auto handler = std::make_shared(runner); + handler->PostTask([]() { + auto helper = VsyncHelper::Current(); + struct FrameCallback cb = { + .timestamp_ = 0, + .userdata_ = nullptr, + .callback_ = [](int64_t timestamp, void* userdata) { + }, + }; + VsyncError ret = helper->RequestFrameCallback(cb); + if (ret != VSYNC_ERROR_OK) { + // failed + } + }); + + runner->Run(); + ``` + + +## Repositories Involved + +Graphics subsystem + +**graphic\_standard** + +ace\_ace\_engine + +aafwk\_L2 + +multimedia\_media\_standard + +multimedia\_camera\_standard -1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md -2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com) -3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目 -4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目 -5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help) -6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/) diff --git a/README_zh.md b/README_zh.md new file mode 100644 index 0000000000..3ffb0ca2f2 --- /dev/null +++ b/README_zh.md @@ -0,0 +1,361 @@ +# graphic_standard + +- [简介](#简介) +- [目录](#目录) +- [约束](#约束) +- [编译构建](#编译构建) +- [接口说明](#接口说明) +- [使用说明](#使用说明) +- [相关仓](#相关仓) + +## 简介 + +**Graphic子系统** 提供了图形接口能力和窗口管理接口能力, + +其主要的结构如下图所示: + +![Graphic子系统架构图](./figures/graphic.png) + +- **Surface** + + 图形缓冲区管理接口,负责管理图形缓冲区和高效便捷的轮转缓冲区。 + +- **Vsync** + + 垂直同步信号管理接口,负责管理所有垂直同步信号注册和响应。 + +- **WindowManager** + + 窗口管理器接口,负责创建和管理窗口。 + +- **WaylandProtocols** + + 窗口管理器和合成器的通信协议。 + +- **Compositor** + + 合成器,负责合成各个图层。 + +- **Renderer** + + 合成器的后端渲染模块。 + +- **Wayland protocols** + + Wayland 进程间通信协议 + +- **Shell** + + 提供多窗口能力 + +- **Input Manger** + + 多模输入模块,负责接收事件输入 + + +## 目录 +``` +foundation/graphic/standard/ +├── frameworks # 框架代码目录 +│ ├── bootanimation # 开机动画目录 +│   ├── surface # Surface代码 +│   ├── vsync # Vsync代码 +│   └── wm # WindowManager代码 +├── interfaces # 对外接口存放目录 +│   ├── innerkits # native接口存放目录 +│   └── kits # js/napi接口存放目录 +└── utils # 小部件存放目录 +``` + +## 约束 +- 语言版本 + - C++11或以上 + +## 编译构建 +可以依赖的接口有: +- graphic_standard:libwms_client +- graphic_standard:libsurface +- graphic_standard:libvsync_client + +## 接口说明 + +### WindowManager + +| 接口名 | 职责 | +|-----------------|-----------------------------| +| GetInstance | 获取WindowManager的单例指针 | +| GetMaxWidth | 获取当前屏幕宽度 | +| GetMaxHeight | 获取当前屏幕高度 | +| CreateWindow | 创建一个标准窗口 | +| CreateSubWindow | 创建一个子窗口 | +| StartShotScreen | 截屏操作 | +| StartShotWindow | 截取窗口操作 | +| SwitchTop | 将指定窗口调整至最上层显示 | + +### Window +| 接口名 | 职责 | +|-----------------------------|------------------------------| +| Show | 显示当前窗口 | +| Hide | 隐藏当前窗口 | +| Move | 移动当前窗口至指定位置 | +| SwitchTop | 将当前窗口调整到最上层显示 | +| ChangeWindowType | 更改当前窗口类型 | +| ReSize | 调整当前窗口至指定大小 | +| Rotate | 旋转当前窗口 | +| RegistPointerButtonCb | 注册鼠标Button事件回调 | +| RegistPointerEnterCb | 注册鼠标Enter事件回调 | +| RegistPointerLeaveCb | 注册鼠标Leave事件回调 | +| RegistPointerMotionCb | 注册鼠标Motion事件回调 | +| RegistPointerAxisDiscreteCb | 注册鼠标AxisDiscrete事件回调 | +| RegistPointerAxisSourceCb | 注册鼠标AxisSource事件回调 | +| RegistPointerAxisStopCb | 注册鼠标AxisStop事件回调 | +| RegistPointerAxisCb | 注册鼠标Axis事件回调 | +| RegistTouchUpCb | 注册TouchUp事件回调 | +| RegistTouchDownCb | 注册TouchDown事件回调 | +| RegistTouchEmotionCb | 注册TouchEmotion事件回调 | +| RegistTouchFrameCb | 注册TouchFrame事件回调 | +| RegistTouchCancelCb | 注册TouchCancel事件回调 | +| RegistTouchShapeCb | 注册TouchShape事件回调 | +| RegistTouchOrientationCb | 注册TouchOrientation事件回调 | +| RegistKeyboardKeyCb | 注册键盘Key事件回调 | +| RegistKeyboardKeyMapCb | 注册键盘KeyMap事件回调 | +| RegistKeyboardLeaveCb | 注册键盘Leave事件回调 | +| RegistKeyboardEnterCb | 注册键盘Enter事件回调 | +| RegistKeyboardRepeatInfoCb | 注册键盘RepeatInfo事件回调 | + +### SubWindow +| 接口名 | 职责 | +|------------------|--------------------| +| Move | 移动当前子窗口 | +| SetSubWindowSize | 调整当前子窗口位置 | + +### Surface +| 接口名 | 职责 | +|----------------------------|-------------------------------------------------------------------| +| CreateSurfaceAsConsumer | Buffer的消费者来使用该函数创建一个Surface | +| CreateSurfaceAsProducer | Buffer的生产者使用该函数创建一个Surface,只能使用与生产相关的接口 | +| GetProducer | 获得一个Surface内部的IBufferProducer对象 | +| RequestBuffer | 请求一个待生产的SurfaceBuffer对象 | +| CancelBuffer | 取消、归还一个待生产的SurfaceBuffer对象 | +| FlushBuffer | 归还一个生产好的SurfaceBuffer对象并携带一些信息 | +| AcquireBuffer | 请求一个待消费的SurfaceBuffer对象 | +| ReleaseBuffer | 归还一个已消费的SurfaceBuffer对象 | +| GetQueueSize | 获得当前同时能并存buffer的数量 | +| SetQueueSize | 设置当前同时能并存buffer的数量 | +| SetDefaultWidthAndHeight | 设置默认宽和高 | +| GetDefaultWidth | 获得默认宽度 | +| GetDefaultHeight | 获得默认高度 | +| SetUserData | 存贮字符串数据,不随着IPC传递 | +| GetUserData | 取出字符串数据 | +| RegisterConsumerListener | 注册一个消费监听器,监听Buffer的Flush事件 | +| UnregisterConsumerListener | 取消监听 | + +### SurfaceBuffer +| 接口名 | 职责 | +|-----------------|-------------------------------------| +| GetBufferHandle | 获得SurfaceBuffer的BufferHandle指针 | +| GetWidth | 获得SurfaceBuffer的宽度 | +| GetHeight | 获得SurfaceBuffer的高度 | +| GetFormat | 获得SurfaceBuffer的颜色格式 | +| GetUsage | 获得SurfaceBuffer的用途 | +| GetPhyAddr | 获得SurfaceBuffer的物理地址 | +| GetKey | 获得SurfaceBuffer的key | +| GetVirAddr | 获得SurfaceBuffer的虚拟地址 | +| GetSize | 获得SurfaceBuffer的文件句柄 | +| SetInt32 | 获得SurfaceBuffer的缓冲区大小 | +| GetInt32 | 设置SurfaceBuffer的32位整数 | +| SetInt64 | 获得SurfaceBuffer的32位整数 | +| GetInt64 | 设置SurfaceBuffer的64位整数 | + +### VsyncHelper +| 接口名 | 职责 | +|----------------------|-----------------------------------| +| Current | 获取当前runner对应的VsyncHelper | +| VsyncHelper | 用EventHandler对象构造VsyncHelper | +| RequestFrameCallback | 注册一个帧回调 | + +## 使用说明 + +### 具名服务-传递一个生产型Surface + +#### 注册 +```cpp +// 拿到一个消费型Surface +sptr surface = Surface::CreateSurfaceAsConsumer(); + +// 拿出里面的生产者对象 +sptr producer = surface->GetProducer(); + +// 注册服务 +auto sm = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); +sm->AddSystemAbility(IPC_SA_ID, producer->AsObject()); +``` + +#### 客户端获得生产型Surface +```cpp +// 获得远程对象 +auto sm = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); +sptr robj = sm->GetSystemAbility(IPC_SA_ID); + +// 构造Surface +sptr bp = iface_cast(robj); +sptr surface = Surface::CreateSurfaceAsProducer(bp); +``` + +### 匿名服务-传递一个生产型Surface +场景: 在一次IPC过程中 + +#### 发送 +```cpp +// 拿到一个消费型Surface +sptr surface = CreateSurfaceAsConsumer(); + +// 拿出里面的生产者对象 +sptr producer = surface->GetProducer(); + +// 返回给客户端 +parcel.WriteRemoteObject(producer); +``` + +#### 接受并获得生产型Surface +```cpp +// 获得远程对象 +sptr remoteObject = parcel.ReadRemoteObject(); + +// 构造Surface +sptr bp = iface_cast(robj); +sptr surface = Surface::CreateSurfaceAsProducer(bp); +``` + +### 生产一个SurfaceBuffer +条件: 一个生产型Surface + +```cpp +BufferRequestConfig requestConfig = { + .width = 1920, // 屏幕宽度 + .height = 1080, // 屏幕高度 + .strideAlignment = 8, // stride对齐字节 + .format = PIXEL_FMT_RGBA_8888, // 颜色格式 + .usage = HBM_USE_CPU_READ | HBM_USE_CPU_WRITE | HBM_USE_MEM_DMA, // 用法 + .timeout = 0, // 时延 +}; + +sptr buffer; +int32_t releaseFence; + +SurfaceError ret = surface->RequestBuffer(buffer, releaseFence, requestConfig); +if (ret != SURFACE_ERROR_OK) { + // failed +} + +BufferFlushConfig flushConfig = { + .damage = { // 重绘区域 + .x = 0, // 起点横坐标 + .y = 0, // 起点纵坐标 + .w = buffer->GetWidth(), // 区域宽度 + .h = buffer->GetHeight(), // 区域高度 + }, + .timestamp = 0 // 给消费者看的时间,0为使用当前时间 +}; + +ret = surface->FlushBuffer(buffer, -1, flushConfig); +if (ret != SURFACE_ERROR_OK) { + // failed +} +``` + +### 消费一个SurfaceBuffer +条件: 一个消费型Surface + +```cpp +class TestConsumerListener : public IBufferConsumerListener { +public: + void OnBufferAvailable() override { + sptr buffer; + int32_t flushFence; + + SurfaceError ret = surface->AcquireBuffer(buffer, flushFence, timestamp, damage); + if (ret != SURFACE_ERROR_OK) { + // failed + } + + // ... + + ret = surface->ReleaseBuffer(buffer, -1); + if (ret != SURFACE_ERROR_OK) { + // failed + } + } +}; + +sptr listener = new TestConsumerListener(); +SurfaceError ret = surface->RegisterConsumerListener(listener); +if (ret != SURFACE_ERROR_OK) { + // failed +} +``` + +### 给SurfaceBuffer带上自定义数据 +```cpp +sptr buffer; +SurfaceError ret = buffer->SetInt32(1, 3); +if (ret != SURFACE_ERROR_OK) { + // failed +} + +int32_t val; +ret = buffer->GetInt32(1, val); +if (ret != SURFACE_ERROR_OK) { + // failed +} +``` + +### 注册一个Vsync回调事件 +#### 用handler构造VsyncHelper +```cpp +auto runner = AppExecFwk::EventRunner::Create(true); +auto handler = std::make_shared(runner); +auto helper = new VsyncHelper(handler); +runner->Run(); + +struct FrameCallback cb = { + .timestamp_ = 0, + .userdata_ = nullptr, + .callback_ = [](int64_t timestamp, void* userdata) { + }, +}; + +VsyncError ret = helper->RequestFrameCallback(cb); +if (ret != VSYNC_ERROR_OK) { + // failed +} +``` + +#### 在handler里用Current +```cpp +auto runner = AppExecFwk::EventRunner::Create(true); +auto handler = std::make_shared(runner); +handler->PostTask([]() { + auto helper = VsyncHelper::Current(); + struct FrameCallback cb = { + .timestamp_ = 0, + .userdata_ = nullptr, + .callback_ = [](int64_t timestamp, void* userdata) { + }, + }; + + VsyncError ret = helper->RequestFrameCallback(cb); + if (ret != VSYNC_ERROR_OK) { + // failed + } +}); + +runner->Run(); +``` + +## 相关仓 +- **graphic_standard** +- ace_ace_engine +- aafwk_standard +- multimedia_media_standard +- multimedia_camera_standard diff --git a/adapter/BUILD.gn b/adapter/BUILD.gn new file mode 100644 index 0000000000..0efe554275 --- /dev/null +++ b/adapter/BUILD.gn @@ -0,0 +1,98 @@ +# 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("//build/ohos.gni") + +## Build libwmadaptertest.so {{{ +config("libwmadaptertest_config") { + visibility = [ ":*" ] + + include_dirs = [ + "include", + "//utils/system/safwk/native/include", + "//foundation/windowmanager/wmserver/include", + "//foundation/windowmanager/interfaces/innerkits/wm", + "//foundation/windowmanager/wm/include", + "//foundation/windowmanager/utils/include", + "//foundation/graphic/standard/interfaces/innerkits/wmclient", + "//foundation/graphic/standard/interfaces/innerkits/common", + "//foundation/graphic/standard/interfaces/innerkits/surface", + + # 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", + "//third_party/node/deps/icu-small/source/common", + "//foundation/aafwk/standard/interfaces/innerkits/ability_manager/include", + "//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", + ] +} + +config("libwmadaptertest_public_config") { + include_dirs = [ + "//foundation/graphic/standard/interfaces/innerkits/wmclient", + "//foundation/windowmanager/interfaces/innerkits/wm", + "//foundation/multimodalinput/input/interfaces/native/innerkits/proxy/include", + "//foundation/multimodalinput/input/interfaces/native/innerkits/event/include", + "//foundation/multimodalinput/input/common/include", + ] +} + +ohos_shared_library("libwmadaptertest") { + sources = [ "src/adapter.cpp" ] + + configs = [ ":libwmadaptertest_config" ] + + public_configs = [ ":libwmadaptertest_public_config" ] + + deps = [ + "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog", + "//foundation/graphic/standard:libwmclient", + "//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", + + # native value + "//foundation/ace/napi:ace_napi", + + # ace + "//foundation/ace/ace_engine/interfaces/innerkits/ace:ace_uicontent", + + # aafwk + "//foundation/aafwk/standard/interfaces/innerkits/want:want", + ] + + public_deps = [ + "//foundation/communication/ipc/interfaces/innerkits/ipc_core:ipc_core", + "//foundation/graphic/standard:libsurface", + "//foundation/graphic/standard/utils:promise", + "//utils/native/base:utils", + + # IMS + "//foundation/multimodalinput/input/frameworks/proxy:libmmi-client", + "//foundation/multimodalinput/input/frameworks/proxy:libmmi-common", + ] + + part_name = "window_manager" + subsystem_name = "window" +} diff --git a/adapter/include/adapter.h b/adapter/include/adapter.h new file mode 100644 index 0000000000..c387a88d0f --- /dev/null +++ b/adapter/include/adapter.h @@ -0,0 +1,63 @@ +/* + * 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_ADAPTER_H +#define OHOS_ROSEN_WINDOW_ADAPTER_H +#define _NEW_RENDERSERVER_ +#include +#include +#include +#include +#include +#include +#include +#include "foundation/windowmanager/interfaces/innerkits/wm/window_option.h" +#include "wm_common.h" +#include "window.h" +#include "foundation/graphic/standard/interfaces/innerkits/wmclient/window_option.h" +#include "window_manager.h" +#include "window_manager_hilog.h" + +namespace OHOS { +namespace Rosen { +class Adapter { +public: + Adapter(); + ~Adapter(); + + static WMError Init(); + static bool CreateWestonWindow(sptr& option); + static void DestroyWestonWindow(); + static bool GetMainWindowRect(OHOS::Rosen::Rect &rect); + static OHOS::Rosen::WMError Show(); + static OHOS::Rosen::WMError Hide(); + static OHOS::Rosen::WMError MoveTo(int32_t x, int32_t y); + static OHOS::Rosen::WMError Resize(uint32_t width, uint32_t height); + +private: + static bool WindowOptionConvertToWeston(sptr& option, + sptr& config); + static bool GetSurfaceBuffer(sptr &surface, + sptr &buffer, + OHOS::BufferRequestConfig &rconfig); + static void WriteDataToSurface(); + static void ColorDraw(void *vaddr, uint32_t width, uint32_t height, uint32_t count); + static void BlackDraw(void *vaddr, uint32_t width, uint32_t height, uint32_t count); + static void FlushDraw(void *vaddr, uint32_t width, uint32_t height, uint32_t count); + static void set(void *vaddr, char ch, size_t len); +}; +} +} +#endif // OHOS_ROSEN_WINDOW_ADAPTER_H diff --git a/adapter/src/adapter.cpp b/adapter/src/adapter.cpp new file mode 100644 index 0000000000..f705b49023 --- /dev/null +++ b/adapter/src/adapter.cpp @@ -0,0 +1,327 @@ +/* + * 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 "adapter.h" +#include "window_impl.h" + +namespace OHOS { +namespace Rosen { + +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, 0, "Adapter" }; + +static inline sptr westonMainWindow_ = nullptr; + +Adapter::Adapter() +{ +} + +Adapter::~Adapter() +{ +} + +OHOS::Rosen::WMError Adapter::Init() +{ + // "AbilityWindow::Init()" + auto wmi = WindowManager::GetInstance(); + if (wmi == nullptr) { + WLOGFE("Adapter::Init WindowManager::GetInstance() is nullptr."); + return OHOS::Rosen::WMError::WM_ERROR_WINDOWMANAGER_GETINSTANCE; + } + + auto wret = wmi->Init(); + if (wret != OHOS::WM_OK) { + WLOGFE("Adapter::Init WindowManager::Init() return %d", wret); + return OHOS::Rosen::WMError::WM_ERROR_WINDOWMANAGER_INIT; + } + WLOGFI("%{public}s end.", __func__); + return OHOS::Rosen::WMError::WM_OK; +} + +bool Adapter::CreateWestonWindow(sptr& option) +{ + sptr config = OHOS::WindowOption::Get(); + if (!WindowOptionConvertToWeston(option, config)) { + WLOGFE("Adapter::CreateWindow convert windowOption fail"); + return false; + } + + auto wmi = OHOS::WindowManager::GetInstance(); + if (wmi == nullptr) { + WLOGFE("Adapter::ConvertToWindowOption WindowManager::GetInstance() is nullptr."); + return false; + } + + WLOGFI("%{public}s begin wms->CreateWindow.", __func__); + auto retvalCreate = wmi->CreateWindow(westonMainWindow_, config); + WLOGFI("%{public}s end wms->CreateWindow.", __func__); + + WriteDataToSurface(); + + if (retvalCreate != OHOS::WMError::WM_OK) { + WLOGFE("Adapter::ConvertToWindowOption WindowManager::CreateWindow() return %d", retvalCreate); + return false; + } + return true; +} + +void Adapter::DestroyWestonWindow() +{ + if (westonMainWindow_ != nullptr) { + OHOS::WMError err = westonMainWindow_->Destroy(); + westonMainWindow_ = nullptr; + if (err == OHOS::WMError::WM_OK) { + WLOGFI("DestroyWestonWindow OK"); + return; + } + WLOGFE("DestroyWestonWindow errorcode=%d", static_cast(err)); + } + WLOGFE("DestroyWestonWindow westonMainWindow_ is null"); +} + +bool Adapter::WindowOptionConvertToWeston(sptr& option, sptr& config) +{ + // window type + config->SetWindowType(OHOS::WindowType::WINDOW_TYPE_NORMAL); + config->SetWindowMode(OHOS::WindowMode::WINDOW_MODE_FULL); + return true; +} + +bool Adapter::GetMainWindowRect(OHOS::Rosen::Rect &rect) +{ + if (westonMainWindow_ == nullptr) { + return false; + } + rect.posX_ = westonMainWindow_->GetX(); + rect.posY_ = westonMainWindow_->GetY(); + rect.width_ = westonMainWindow_->GetWidth(); + rect.height_ = westonMainWindow_->GetHeight(); + return true; +} + +static inline bool hide = false; + +OHOS::Rosen::WMError Adapter::Show() +{ + if (westonMainWindow_ == nullptr) { + WLOGFE("Adapter::Show westonMainWindow_ is null"); + return OHOS::Rosen::WMError::WM_ERROR_WINDOWMANAGER_SHOW; + } + + if (!hide) { + auto promise = westonMainWindow_->Show(); + if (promise == nullptr) { + WLOGFE("Adapter::Show Show error"); + return OHOS::Rosen::WMError::WM_ERROR_WINDOWMANAGER_SHOW; + } + auto error = promise->Await(); + if (error != OHOS::WMError::WM_OK) { + WLOGFE("Adapter::Show Show error=%d", static_cast(error)); + return OHOS::Rosen::WMError::WM_ERROR_WINDOWMANAGER_SHOW; + } + } + + auto promise2 = westonMainWindow_->SwitchTop(); + if (promise2 == nullptr) { + WLOGFE("Adapter::Show SwitchTop error"); + return OHOS::Rosen::WMError::WM_ERROR_WINDOWMANAGER_SHOW; + } + auto error2 = promise2->Await(); + if (error2 != OHOS::WMError::WM_OK) { + WLOGFE("Adapter::Show SwitchTop error=%d", static_cast(error2)); + return OHOS::Rosen::WMError::WM_ERROR_WINDOWMANAGER_SHOW; + } + + return OHOS::Rosen::WMError::WM_OK; +} + +void Adapter::WriteDataToSurface() +{ + /* write data to surface */ + sptr surface = westonMainWindow_->GetSurface(); + sptr buffer; + BufferRequestConfig rconfig; + if (GetSurfaceBuffer(surface, buffer, rconfig)) { + BlackDraw(buffer->GetVirAddr(), rconfig.width, rconfig.height, 1); + } else { + WLOGFE("Adapter::WriteDataToSurface GetSurfaceBuffer fail"); + } + BufferFlushConfig fconfig = { + .damage = { + .w = rconfig.width, + .h = rconfig.height, + }, + }; + surface->FlushBuffer(buffer, -1, fconfig); +} + +OHOS::Rosen::WMError Adapter::Hide() +{ + if (westonMainWindow_ == nullptr) { + WLOGFE("Adapter::Hide westonMainWindow_ is null"); + return OHOS::Rosen::WMError::WM_ERROR_WINDOWMANAGER_HIDE; + } + auto promise = westonMainWindow_->Hide(); + if (promise == nullptr) { + WLOGFE("Adapter::Hide Hide error"); + return OHOS::Rosen::WMError::WM_ERROR_WINDOWMANAGER_HIDE; + } + auto error = promise->Await(); + if (error != OHOS::WMError::WM_OK) { + WLOGFE("Adapter::Hide Hide error=%d", static_cast(error)); + return OHOS::Rosen::WMError::WM_ERROR_WINDOWMANAGER_HIDE; + } + hide = true; + return OHOS::Rosen::WMError::WM_OK; +} + +OHOS::Rosen::WMError Adapter::MoveTo(int32_t x, int32_t y) +{ + if (westonMainWindow_ == nullptr) { + WLOGFE("Adapter::MoveTo westonMainWindow_ is null"); + return OHOS::Rosen::WMError::WM_ERROR_WINDOWMANAGER_MOVE; + } + auto promise = westonMainWindow_->Move(x, y); + if (promise == nullptr) { + WLOGFE("Adapter::MoveTo promise is null"); + return OHOS::Rosen::WMError::WM_ERROR_WINDOWMANAGER_MOVE; + } + return OHOS::Rosen::WMError::WM_OK; +} + +OHOS::Rosen::WMError Adapter::Resize(uint32_t width, uint32_t height) +{ + if (westonMainWindow_ == nullptr) { + WLOGFE("Adapter::Resize westonMainWindow_ is null"); + return OHOS::Rosen::WMError::WM_ERROR_WINDOWMANAGER_RESIZE; + } + auto promise = westonMainWindow_->Resize(width, height); + if (promise == nullptr) { + WLOGFE("Adapter::Resize promise is null"); + return OHOS::Rosen::WMError::WM_ERROR_WINDOWMANAGER_RESIZE; + } + return OHOS::Rosen::WMError::WM_OK; +} + +bool Adapter::GetSurfaceBuffer(sptr &surface, sptr &buffer, BufferRequestConfig &rconfig) +{ + int32_t releaseFence; + rconfig = { + .width = surface->GetDefaultWidth(), + .height = surface->GetDefaultHeight(), + .strideAlignment = 0x8, + .format = 12, // PIXEL_FMT_RGBA_8888, + .usage = surface->GetDefaultUsage(), + .timeout = 0, + }; + OHOS::SurfaceError ret = surface->RequestBuffer(buffer, releaseFence, rconfig); + if (ret == 40601000) { // OHOS::SurfaceError::SURFACE_ERROR_NO_BUFFER + WLOGFE("Adapter::GetSurfaceBuffer RequestBuffer error=%d", static_cast(ret)); + return false; + } else if (ret != 0) { // OHOS::SurfaceError::SURFACE_ERROR_OK + WLOGFE("Adapter::GetSurfaceBuffer RequestBuffer is NG error=%d", static_cast(ret)); + return false; + } else if (buffer == nullptr) { + WLOGFE("Adapter::GetSurfaceBuffer buffer is nullptr"); + return false; + } + return true; +} + +void Adapter::ColorDraw(void *vaddr, uint32_t width, uint32_t height, uint32_t count) +{ + auto addr = static_cast(vaddr); + if (addr == nullptr) { + return; + } + + constexpr uint32_t wdiv = 2; + constexpr uint32_t colorTable[][wdiv] = { + {0xffff0000, 0xffff00ff}, + {0xffff0000, 0xffffff00}, + {0xff00ff00, 0xffffff00}, + {0xff00ff00, 0xff00ffff}, + {0xff0000ff, 0xff00ffff}, + {0xff0000ff, 0xffff00ff}, + {0xff777777, 0xff777777}, + {0xff777777, 0xff777777}, + }; + const uint32_t hdiv = sizeof(colorTable) / sizeof(*colorTable); + + for (uint32_t i = 0; i < height; i++) { + auto table = colorTable[i / (height / hdiv)]; + for (uint32_t j = 0; j < wdiv; j++) { + auto color = table[j]; + for (uint32_t k = j * width / wdiv; k < (j + 1) * width / wdiv; k++) { + addr[i * width + k] = color; + } + } + } +} + +void Adapter::BlackDraw(void *vaddr, uint32_t width, uint32_t height, uint32_t count) +{ + auto addr = static_cast(vaddr); + if (addr == nullptr) { + return; + } + + for (uint32_t i = 0; i < width * height; i++) { + addr[i] = 0xff00ff00; + } +} + +void Adapter::FlushDraw(void *vaddr, uint32_t width, uint32_t height, uint32_t count) +{ + auto addr = static_cast(vaddr); + if (addr == nullptr) { + return; + } + + constexpr uint32_t bpp = 4; + constexpr uint32_t color1 = 0xff / 3 * 0; + constexpr uint32_t color2 = 0xff / 3 * 1; + constexpr uint32_t color3 = 0xff / 3 * 2; + constexpr uint32_t color4 = 0xff / 3 * 3; + constexpr uint32_t bigDiv = 7; + constexpr uint32_t smallDiv = 10; + uint32_t c = count % (bigDiv * smallDiv); + uint32_t stride = width * bpp; + uint32_t beforeCount = height * c / bigDiv / smallDiv; + uint32_t afterCount = height - beforeCount - 1; + + size_t len = ((stride * height) < (beforeCount * stride) ? (stride * height) : (beforeCount * stride)); + set(addr, color3, len); + + len = ((stride * height) < (afterCount * stride) ? (stride * height) : (afterCount * stride)); + set(addr + (beforeCount + 1) * stride, color1, len); + + for (uint32_t i = 0; i < bigDiv; i++) { + len = ((stride * height) < (stride) ? (stride * height) : (stride)); + set(addr + (i * height / bigDiv) * stride, color4, len); + } + + len = ((stride * height) < (stride) ? (stride * height) : (stride)); + set(addr + beforeCount * stride, color2, len); +} + +void Adapter::set(void *vaddr, char ch, size_t len) +{ + char *ptr = static_cast(vaddr); + for (size_t i = 0; i < len; i++) { + ptr[i] = ch; + } +} +} +} diff --git a/dm/include/README.md b/dm/include/README.md new file mode 100644 index 0000000000..bda91e7389 --- /dev/null +++ b/dm/include/README.md @@ -0,0 +1 @@ +Store code of display client inner header files diff --git a/dm/include/display_manager_adapter.h b/dm/include/display_manager_adapter.h new file mode 100644 index 0000000000..61882fd0db --- /dev/null +++ b/dm/include/display_manager_adapter.h @@ -0,0 +1,54 @@ +/* + * 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_DM_DISPLAY_MANAGER_ADAPTER_H +#define FOUNDATION_DM_DISPLAY_MANAGER_ADAPTER_H + +#include +#include + +#include "display.h" +#include "display_manager_interface.h" +#include "single_instance.h" +#include "singleton_delegator.h" + +namespace OHOS::Rosen { +class DMSDeathRecipient : public IRemoteObject::DeathRecipient { +public: + virtual void OnRemoteDied(const wptr& wptrDeath) override; +}; + +class DisplayManagerAdapter : public RefBase { + DECLARE_SINGLE_INSTANCE_BASE(DisplayManagerAdapter); +public: + sptr GetDisplay(DisplayType type); + DisplayId GetDefaultDisplayId(); + sptr GetDisplayById(DisplayId displayId); + + void Clear(); +private: + DisplayManagerAdapter() = default; + ~DisplayManagerAdapter() = default; + bool InitDMSProxyLocked(); + static inline SingletonDelegator delegator; + + std::mutex mutex_; + sptr displayManagerServiceProxy_ = nullptr; + sptr dmsDeath_ = nullptr; + std::map> displayMap_; + DisplayId defaultDisplayId_; +}; +} // namespace OHOS::Rosen +#endif // FOUNDATION_DM_DISPLAY_MANAGER_ADAPTER_H diff --git a/dm/src/README.md b/dm/src/README.md new file mode 100644 index 0000000000..8eb6cfc677 --- /dev/null +++ b/dm/src/README.md @@ -0,0 +1 @@ +Store code of display source files diff --git a/dm/src/display.cpp b/dm/src/display.cpp new file mode 100644 index 0000000000..73655b9404 --- /dev/null +++ b/dm/src/display.cpp @@ -0,0 +1,68 @@ +/* + * 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.h" +#include "display_info.h" + +namespace OHOS::Rosen { +Display::Display(const std::string& name, DisplayInfo* info) + : name_(name), + id_(info->id_), + width_(info->width_), + height_(info->height_), + freshRate_(info->freshRate_) +{ +} + +DisplayId Display::GetId() const +{ + return id_; +} + +int32_t Display::GetWidth() const +{ + return width_; +} + +int32_t Display::GetHeight() const +{ + return height_; +} + +uint32_t Display::GetFreshRate() const +{ + return freshRate_; +} + +void Display::SetWidth(int32_t width) +{ + width_ = width; +} + +void Display::SetHeight(int32_t height) +{ + height_ = height; +} + +void Display::SetFreshRate(uint32_t freshRate) +{ + freshRate_ = freshRate; +} + +void Display::SetId(DisplayId id) +{ + id_ = id; +} +} // namespace OHOS::Rosen \ No newline at end of file diff --git a/dm/src/display_manager.cpp b/dm/src/display_manager.cpp new file mode 100644 index 0000000000..57b8ac1b0a --- /dev/null +++ b/dm/src/display_manager.cpp @@ -0,0 +1,97 @@ +/* + * 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_manager.h" +#include "display_manager_adapter.h" +#include "window_manager_hilog.h" + +namespace OHOS::Rosen { +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(); +} + +const sptr DisplayManager::GetDisplayById(DisplayId displayId) +{ + if (dmsAdapter_ == nullptr) { + WLOGFE("DisplayManager::GetDisplayById null!\n"); + return nullptr; + } + + sptr display = dmsAdapter_->GetDisplayById(displayId); + if (display == nullptr) { + WLOGFE("DisplayManager::GetDisplayById failed!\n"); + return nullptr; + } + return display; +} + + +const sptr DisplayManager::GetDefaultDisplay() +{ + return GetDisplayById(GetDefaultDisplayId()); +} + +std::vector DisplayManager::GetAllDisplayIds() +{ + std::vector res; + res.push_back(GetDefaultDisplayId()); + // 获取所有displayIds + return res; +} + +std::vector> DisplayManager::GetAllDisplays() +{ + std::vector> res; + auto displayIds = GetAllDisplayIds(); + for (auto displayId: displayIds) { + const sptr display = GetDisplayById(displayId); + if (display != nullptr) { + res.push_back(display); + } else { + WLOGFE("DisplayManager::GetAllDisplays display %llu nullptr!", displayId); + } + } + return res; +} +} // 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 new file mode 100644 index 0000000000..675bb97b8b --- /dev/null +++ b/dm/src/display_manager_adapter.cpp @@ -0,0 +1,143 @@ +/* + * 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_manager_adapter.h" + +#include +#include +#include + +#include "window_manager_hilog.h" +#include "wm_common.h" + +namespace OHOS::Rosen { +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_); + + if (defaultDisplayId_ != DISPLAY_ID_INVALD) { + return defaultDisplayId_; + } + + if (!InitDMSProxyLocked()) { + WLOGFE("displayManagerAdapter::GetDefaultDisplayId: InitDMSProxyLocked failed!"); + return DISPLAY_ID_INVALD; + } + defaultDisplayId_ = displayManagerServiceProxy_->GetDefaultDisplayId(); + return defaultDisplayId_; +} + +sptr DisplayManagerAdapter::GetDisplayById(DisplayId displayId) +{ + std::lock_guard lock(mutex_); + + auto iter = displayMap_.find(displayId); + if (iter != displayMap_.end()) { + return iter->second; + } + + if (!InitDMSProxyLocked()) { + WLOGFE("displayManagerAdapter::GetDisplayById: InitDMSProxyLocked failed!"); + return nullptr; + } + DisplayInfo displayInfo = displayManagerServiceProxy_->GetDisplayInfoById(displayId); + sptr display = new Display("", &displayInfo); + if (display->GetId() != DISPLAY_ID_INVALD) { + displayMap_[display->GetId()] = display; + } + return display; +} + +bool DisplayManagerAdapter::InitDMSProxyLocked() +{ + WLOGFI("InitDMSProxy"); + if (!displayManagerServiceProxy_) { + sptr systemAbilityManager = + SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (!systemAbilityManager) { + WLOGFE("Failed to get system ability mgr."); + return false; + } + + sptr remoteObject + = systemAbilityManager->GetSystemAbility(DISPLAY_MANAGER_SERVICE_SA_ID); + if (!remoteObject) { + WLOGFE("Failed to get display manager service."); + return false; + } + + displayManagerServiceProxy_ = iface_cast(remoteObject); + if ((!displayManagerServiceProxy_) || (!displayManagerServiceProxy_->AsObject())) { + WLOGFE("Failed to get system display manager services"); + return false; + } + + dmsDeath_ = new DMSDeathRecipient(); + if (!dmsDeath_) { + WLOGFE("Failed to create death Recipient ptr DMSDeathRecipient"); + return false; + } + if (!remoteObject->AddDeathRecipient(dmsDeath_)) { + WLOGFE("Failed to add death recipient"); + return false; + } + } + return true; +} + +void DMSDeathRecipient::OnRemoteDied(const wptr& wptrDeath) +{ + if (wptrDeath == nullptr) { + WLOGFE("wptrDeath is null"); + return; + } + + sptr object = wptrDeath.promote(); + if (!object) { + WLOGFE("object is null"); + return; + } + SingletonContainer::Get().GetRefPtr()->Clear(); + return; +} + +void DisplayManagerAdapter::Clear() +{ + std::lock_guard lock(mutex_); + if ((displayManagerServiceProxy_ != nullptr) && (displayManagerServiceProxy_->AsObject() != nullptr)) { + displayManagerServiceProxy_->AsObject()->RemoveDeathRecipient(dmsDeath_); + } + displayManagerServiceProxy_ = nullptr; +} +} // namespace OHOS::Rosen \ No newline at end of file diff --git a/dm/src/monitor.cpp b/dm/src/monitor.cpp new file mode 100644 index 0000000000..ca8933d58b --- /dev/null +++ b/dm/src/monitor.cpp @@ -0,0 +1,19 @@ +/* + * 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 "monitor.h" + +namespace OHOS::Rosen { +} // namespace OHOS::Rosen \ No newline at end of file diff --git a/dmserver/include/README.md b/dmserver/include/README.md new file mode 100644 index 0000000000..92b3669bdd --- /dev/null +++ b/dmserver/include/README.md @@ -0,0 +1 @@ +Store code of display manager service inner header files diff --git a/dmserver/include/display_info.h b/dmserver/include/display_info.h new file mode 100644 index 0000000000..72edc10998 --- /dev/null +++ b/dmserver/include/display_info.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 p ermissions and + * limitations under the License. + */ + +#ifndef FOUNDATION_DMSERVER_DISPLAY_INFO_H +#define FOUNDATION_DMSERVER_DISPLAY_INFO_H + +#include + +#include "display.h" + +namespace OHOS::Rosen { +class DisplayInfo : public Parcelable { +public: + DisplayInfo() = default; + ~DisplayInfo() = default; + + void Update(DisplayInfo* info); + + virtual bool Marshalling(Parcel& parcel) const override; + static DisplayInfo *Unmarshalling(Parcel& parcel); + + DisplayId id_ {DISPLAY_ID_INVALD}; + DisplayType type_ {DisplayType::DEFAULT}; + int32_t width_ {0}; + int32_t height_ {0}; + uint32_t freshRate_ {0}; + float xDpi_ {0.0}; + float yDpi_ {0.0}; +}; +} // namespace OHOS::Rosen +#endif // FOUNDATION_DMSERVER_DISPLAY_INFO_H \ No newline at end of file diff --git a/dmserver/include/display_manager_interface.h b/dmserver/include/display_manager_interface.h new file mode 100644 index 0000000000..8a7d71fc5e --- /dev/null +++ b/dmserver/include/display_manager_interface.h @@ -0,0 +1,41 @@ +/* + * 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_DMSERVER_DISPLAY_MANAGER_INTERFACE_H +#define FOUNDATION_DMSERVER_DISPLAY_MANAGER_INTERFACE_H + +#include + +#include "display_info.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, + }; + + virtual const sptr& GetDisplayInfo(const DisplayType type) = 0; + + virtual DisplayId GetDefaultDisplayId() = 0; + virtual DisplayInfo GetDisplayInfoById(DisplayId displayId) = 0; +}; +} // namespace OHOS::Rosen + +#endif // FOUNDATION_DMSERVER_DISPLAY_MANAGER_INTERFACE_H \ No newline at end of file diff --git a/dmserver/include/display_manager_proxy.h b/dmserver/include/display_manager_proxy.h new file mode 100644 index 0000000000..519107124d --- /dev/null +++ b/dmserver/include/display_manager_proxy.h @@ -0,0 +1,39 @@ +/* + * 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_DMSERVER_DISPLAY_MANAGER_PROXY_H +#define FOUNDATION_DMSERVER_DISPLAY_MANAGER_PROXY_H + +#include "display_manager_interface.h" + +#include + +namespace OHOS::Rosen { +class DisplayManagerProxy : public IRemoteProxy { +public: + explicit DisplayManagerProxy(const sptr &impl) + : IRemoteProxy(impl) {}; + ~DisplayManagerProxy() {}; + + const sptr& GetDisplayInfo(const DisplayType type) override; + + DisplayId GetDefaultDisplayId() override; + DisplayInfo GetDisplayInfoById(DisplayId displayId) override; +private: + static inline BrokerDelegator delegator_; +}; +} // namespace OHOS::Rosen + +#endif // FOUNDATION_DMSERVER_DISPLAY_MANAGER_PROXY_H \ No newline at end of file diff --git a/dmserver/include/display_manager_service.h b/dmserver/include/display_manager_service.h new file mode 100644 index 0000000000..83ffbbe94a --- /dev/null +++ b/dmserver/include/display_manager_service.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 FOUNDATION_DMSERVER_DISPLAY_MANAGER_SERVICE_H +#define FOUNDATION_DMSERVER_DISPLAY_MANAGER_SERVICE_H + +#include +#include + +#include + +#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 { +DECLARE_SYSTEM_ABILITY(DisplayManagerService); + +DECLARE_SINGLE_INSTANCE_BASE(DisplayManagerService); + +public: + void OnStart() override; + void OnStop() override; + const sptr& GetDisplayInfo(const DisplayType type) override; + + DisplayId GetDefaultDisplayId() override; + DisplayInfo GetDisplayInfoById(DisplayId displayId) override; + +private: + DisplayManagerService(); + ~DisplayManagerService() = default; + bool Init(); + DisplayId GetDisplayIdFromScreenId(ScreenId screenId); + ScreenId GetScreenIdFromDisplayId(DisplayId displayId); + + static inline SingletonDelegator delegator_; + std::map> displayScreenMap_; + sptr displayScreenManager_; +}; +} // namespace OHOS::Rosen + +#endif // FOUNDATION_DMSERVER_DISPLAY_MANAGER_SERVICE_H \ No newline at end of file diff --git a/dmserver/include/display_manager_service_inner.h b/dmserver/include/display_manager_service_inner.h new file mode 100644 index 0000000000..6051c80443 --- /dev/null +++ b/dmserver/include/display_manager_service_inner.h @@ -0,0 +1,39 @@ +/* + * 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_DMSERVER_DISPLAY_MANAGER_SERVICE_INNER_H +#define FOUNDATION_DMSERVER_DISPLAY_MANAGER_SERVICE_INNER_H + +#include +#include + +#include "display_screen.h" +#include "single_instance.h" +#include "singleton_delegator.h" + +namespace OHOS::Rosen { +class DisplayManagerServiceInner : public RefBase { +DECLARE_SINGLE_INSTANCE(DisplayManagerServiceInner); + +public: + std::vector> GetAllDisplays(); + DisplayId GetDefaultDisplayId(); + const sptr GetDefaultDisplay(); + const sptr GetDisplayById(DisplayId displayId); + std::vector GetAllDisplayIds(); +}; +} // namespace OHOS::Rosen + +#endif // FOUNDATION_DMSERVER_DISPLAY_MANAGER_SERVICE_H \ No newline at end of file diff --git a/dmserver/include/display_manager_stub.h b/dmserver/include/display_manager_stub.h new file mode 100644 index 0000000000..d88c4a0c65 --- /dev/null +++ b/dmserver/include/display_manager_stub.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 FOUNDATION_DMSERVER_DISPLAY_MANAGER_STUB_H +#define FOUNDATION_DMSERVER_DISPLAY_MANAGER_STUB_H + +#include "display_manager_interface.h" + +#include + +namespace OHOS::Rosen { +class DisplayManagerStub : public IRemoteStub { +public: + DisplayManagerStub() = default; + ~DisplayManagerStub() = default; + virtual int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, + MessageOption &option) override; +}; +} // namespace OHOS::Rosen + +#endif // FOUNDATION_DMSERVER_DISPLAY_MANAGER_STUB_H \ No newline at end of file diff --git a/dmserver/include/display_node_control.h b/dmserver/include/display_node_control.h new file mode 100644 index 0000000000..5da96a2081 --- /dev/null +++ b/dmserver/include/display_node_control.h @@ -0,0 +1,25 @@ +/* + * 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_DMSERVER_DISPLAY_NODE_CONTROL_H +#define FOUNDATION_DMSERVER_DISPLAY_NODE_CONTROL_H + +#include + +namespace OHOS::Rosen { +class DisplayNodeControl : public RefBase { +}; +} // namespace OHOS::Rosen +#endif // FOUNDATION_DMSERVER_DISPLAY_NODE_CONTROL_H \ No newline at end of file diff --git a/dmserver/include/display_screen.h b/dmserver/include/display_screen.h new file mode 100644 index 0000000000..d656621953 --- /dev/null +++ b/dmserver/include/display_screen.h @@ -0,0 +1,45 @@ +/* + * 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_DMSERVER_DISPLAY_SCREEN_H +#define FOUNDATION_DMSERVER_DISPLAY_SCREEN_H + +#include +#include "display_info.h" + +namespace OHOS::Rosen { +class DisplayScreen : public RefBase { +public: + DisplayScreen(const DisplayInfo& info); + ~DisplayScreen() = default; + + DisplayId GetId() const; + int32_t GetWidth() const; + int32_t GetHeight() const; + uint32_t GetFreshRate() const; + + void SetId(DisplayId displayId); + void SetWidth(int32_t width); + void SetHeight(int32_t height); + void SetFreshRate(uint32_t freshRate); + +private: + DisplayId id_ {DISPLAY_ID_INVALD}; + int32_t width_ {0}; + int32_t height_ {0}; + uint32_t freshRate_ {0}; +}; +} // namespace OHOS::Rosen +#endif // FOUNDATION_DMSERVER_DISPLAY_SCREEN_H \ No newline at end of file diff --git a/dmserver/include/display_screen_manager.h b/dmserver/include/display_screen_manager.h new file mode 100644 index 0000000000..0c1df9b379 --- /dev/null +++ b/dmserver/include/display_screen_manager.h @@ -0,0 +1,44 @@ +/* + * 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_DMSERVER_DISPLAY_SCREEN_MANAGER_H +#define FOUNDATION_DMSERVER_DISPLAY_SCREEN_MANAGER_H + +#include +#include + +#include "display_screen.h" +#include "single_instance.h" +#include "transaction/rs_interfaces.h" + +namespace OHOS::Rosen { +class DisplayScreenManager : public RefBase { +DECLARE_SINGLE_INSTANCE_BASE(DisplayScreenManager); +public: + std::map> displayScreenMap_; + + ScreenId GetDefaultScreenId(); + RSScreenModeInfo GetScreenActiveMode(ScreenId id); + +private: + DisplayScreenManager(); + ~DisplayScreenManager(); + void parepareRSScreenManger(); + + OHOS::Rosen::RSInterfaces *rsInterface_; +}; + +} // namespace OHOS::Rosen +#endif // FOUNDATION_DMSERVER_DISPLAY_SCREEN_MANAGER_H \ No newline at end of file diff --git a/dmserver/include/rs_adapter.h b/dmserver/include/rs_adapter.h new file mode 100644 index 0000000000..9f19e344c9 --- /dev/null +++ b/dmserver/include/rs_adapter.h @@ -0,0 +1,48 @@ +/* + * 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_DMSERVER_RS_ADAPTER_H +#define FOUNDATION_DMSERVER_RS_ADAPTER_H + +#include +#include + +#include + +#include "single_instance.h" + +namespace OHOS::Rosen { +class DMSDeathRecipient : public IRemoteObject::DeathRecipient { +public: + virtual void OnRemoteDied(const wptr& wptrDeath) override; +private: + sptr& rsAdatper_; +}; + +class RsAdapter : public RefBase { + DECLARE_SINGLE_INSTANCE_BASE(RsAdapter); +public: + void Clear(); +private: + RsAdapter() = default; + ~RsAdapter() = default; + bool InitRSProxyLocked(); + + std::mutex mutex_; + sptr rsProxy_ = nullptr; + sptr rsDeath_ = nullptr; +}; +} // namespace OHOS::Rosen +#endif // FOUNDATION_DMSERVER_RS_ADAPTER_H diff --git a/dmserver/include/screen.h b/dmserver/include/screen.h new file mode 100644 index 0000000000..bbe436d55b --- /dev/null +++ b/dmserver/include/screen.h @@ -0,0 +1,25 @@ +/* + * 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_DMSERVER_SCREEN_H +#define FOUNDATION_DMSERVER_SCREEN_H + +#include + +namespace OHOS::Rosen { +class Screen : public RefBase { +}; +} // namespace OHOS::Rosen +#endif // FOUNDATION_DMSERVER_SCREEN_H \ No newline at end of file diff --git a/dmserver/src/README.md b/dmserver/src/README.md new file mode 100644 index 0000000000..acfe633cd7 --- /dev/null +++ b/dmserver/src/README.md @@ -0,0 +1 @@ +Store code of display manager service source files diff --git a/dmserver/src/display_info.cpp b/dmserver/src/display_info.cpp new file mode 100644 index 0000000000..e26ebf2f44 --- /dev/null +++ b/dmserver/src/display_info.cpp @@ -0,0 +1,56 @@ +/* + * 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_info.h" + +namespace OHOS::Rosen { +void DisplayInfo::Update(DisplayInfo* info) +{ + id_ = info->id_; + type_ = info->type_; + width_ = info->width_; + height_ = info->height_; + freshRate_ = info->freshRate_; + xDpi_ = info->xDpi_; + yDpi_ = info->yDpi_; +} + +bool DisplayInfo::Marshalling(Parcel &parcel) const +{ + return parcel.WriteUint64(id_) && parcel.WriteUint32(type_) && + parcel.WriteInt32(width_) && parcel.WriteInt32(height_) && + parcel.WriteUint32(freshRate_) && + parcel.WriteFloat(xDpi_) && parcel.WriteFloat(yDpi_); +} + +DisplayInfo *DisplayInfo::Unmarshalling(Parcel &parcel) +{ + DisplayInfo *displayInfo = new DisplayInfo(); + if (displayInfo == nullptr) { + return nullptr; + } + uint32_t type = (uint32_t)DisplayType::DEFAULT; + bool res = parcel.ReadUint64(displayInfo->id_) && parcel.ReadUint32(type) && + parcel.ReadInt32(displayInfo->width_) && parcel.ReadInt32(displayInfo->height_) && + parcel.ReadUint32(displayInfo->freshRate_) && + parcel.ReadFloat(displayInfo->xDpi_) && parcel.ReadFloat(displayInfo->yDpi_); + if (!res) { + displayInfo = nullptr; + } else { + displayInfo->type_ = (DisplayType)type; + } + return displayInfo; +} +} // 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 new file mode 100644 index 0000000000..87c482a3e6 --- /dev/null +++ b/dmserver/src/display_manager_proxy.cpp @@ -0,0 +1,104 @@ +/* + * 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_manager_proxy.h" + +#include + +#include "window_manager_hilog.h" + +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(); + if (remote == nullptr) { + WLOGFW("GetDefaultDisplayId: remote is nullptr"); + return DISPLAY_ID_INVALD; + } + + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("GetDefaultDisplayId: WriteInterfaceToken failed"); + return DISPLAY_ID_INVALD; + } + if (remote->SendRequest(TRANS_ID_GET_DEFAULT_DISPLAY_ID, data, reply, option) != ERR_NONE) { + WLOGFW("GetDefaultDisplayId: SendRequest failed"); + return DISPLAY_ID_INVALD; + } + + DisplayId displayId = reply.ReadUint64(); + WLOGFI("DisplayManagerProxy::GetDefaultDisplayId %llu", displayId); + return displayId; +} + +DisplayInfo DisplayManagerProxy::GetDisplayInfoById(DisplayId displayId) +{ + sptr remote = Remote(); + if (remote == nullptr) { + WLOGFW("GetDisplayInfoById: remote is nullptr"); + return DisplayInfo(); + } + + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("GetDisplayInfoById: WriteInterfaceToken failed"); + return DisplayInfo(); + } + data.WriteUint64(static_cast(displayId)); + if (remote->SendRequest(TRANS_ID_GET_DISPLAY_BY_ID, data, reply, option) != ERR_NONE) { + WLOGFW("GetDisplayInfoById: SendRequest failed"); + return DisplayInfo(); + } + + sptr info = reply.ReadParcelable(); + if (info == nullptr) { + WLOGFW("DisplayManagerProxy::GetDisplayInfoById SendRequest nullptr."); + return DisplayInfo(); + } + return *info; +} +} // 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 new file mode 100644 index 0000000000..93ca0d2d6a --- /dev/null +++ b/dmserver/src/display_manager_service.cpp @@ -0,0 +1,113 @@ +/* + * 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_manager_service.h" + +#include +#include + +#include +#include +#include + +#include "window_manager_hilog.h" + +namespace OHOS::Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "DisplayManagerService"}; +} + +IMPLEMENT_SINGLE_INSTANCE(DisplayManagerService); + +const bool REGISTER_RESULT = + SystemAbility::MakeAndRegisterAbility(SingletonContainer::Get().GetRefPtr()); + +DisplayManagerService::DisplayManagerService() : SystemAbility(DISPLAY_MANAGER_SERVICE_SA_ID, true) +{ +} + +void DisplayManagerService::OnStart() +{ + WLOGFI("DisplayManagerService::OnStart start"); + if (!Init()) { + return; + } +} + +bool DisplayManagerService::Init() +{ + WLOGFI("DisplayManagerService::Init start"); + bool ret = Publish(this); + if (!ret) { + 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; +} + +ScreenId DisplayManagerService::GetScreenIdFromDisplayId(DisplayId displayId) +{ + return (ScreenId)displayId; +} + +DisplayId DisplayManagerService::GetDefaultDisplayId() +{ + if (displayScreenManager_ == nullptr) { + return DISPLAY_ID_INVALD; + } + ScreenId screenId = displayScreenManager_->GetDefaultScreenId(); + WLOGFI("GetDefaultDisplayId %{public}llu", screenId); + return GetDisplayIdFromScreenId(screenId); +} + +DisplayInfo DisplayManagerService::GetDisplayInfoById(DisplayId displayId) +{ + DisplayInfo displayInfo; + if (displayScreenManager_ == nullptr) { + return displayInfo; + } + ScreenId screenId = GetScreenIdFromDisplayId(displayId); + auto screenModeInfo = displayScreenManager_->GetScreenActiveMode(screenId); + displayInfo.id_ = displayId; + displayInfo.width_ = screenModeInfo.GetScreenWidth(); + displayInfo.height_ = screenModeInfo.GetScreenHeight(); + displayInfo.freshRate_ = screenModeInfo.GetScreenFreshRate(); + return displayInfo; +} + +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 new file mode 100644 index 0000000000..61a9c3f6f8 --- /dev/null +++ b/dmserver/src/display_manager_service_inner.cpp @@ -0,0 +1,89 @@ +/* + * 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_manager_service_inner.h" + +#include +#include + +#include +#include +#include + +#include "display_screen_manager.h" +#include "display_manager_service.h" +#include "window_manager_hilog.h" + +namespace OHOS::Rosen { +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(); +} + +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); + if (display == nullptr) { + WLOGFE("GetDisplayById failed!\n"); + return nullptr; + } + return display; +} + +const sptr DisplayManagerServiceInner::GetDefaultDisplay() +{ + return GetDisplayById(GetDefaultDisplayId()); +} + +std::vector DisplayManagerServiceInner::GetAllDisplayIds() +{ + std::vector res; + res.push_back(GetDefaultDisplayId()); + return res; +} + +std::vector> DisplayManagerServiceInner::GetAllDisplays() +{ + std::vector> res; + auto displayIds = GetAllDisplayIds(); + for (auto displayId: displayIds) { + const sptr display = GetDisplayById(displayId); + if (display != nullptr) { + res.push_back(display); + } else { + WLOGFE("GetAllDisplays display %llu nullptr!", displayId); + } + } + return res; +} +} // namespace OHOS::Rosen \ No newline at end of file diff --git a/dmserver/src/display_manager_stub.cpp b/dmserver/src/display_manager_stub.cpp new file mode 100644 index 0000000000..0e065619c8 --- /dev/null +++ b/dmserver/src/display_manager_stub.cpp @@ -0,0 +1,59 @@ +/* + * 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_manager_stub.h" + +#include + +#include "window_manager_hilog.h" + +namespace OHOS::Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "DisplayManagerStub"}; +} + +int32_t DisplayManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, + MessageOption &option) +{ + WLOGFI("OnRemoteRequest code is %{public}d", code); + if (data.ReadInterfaceToken() != GetDescriptor()) { + WLOGFE("InterfaceToken check failed"); + 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); + break; + } + case TRANS_ID_GET_DISPLAY_BY_ID: { + DisplayId displayId = static_cast(data.ReadUint64()); + auto info = GetDisplayInfoById(displayId); + reply.WriteParcelable(&info); + break; + } + default: + WLOGFW("unknown transaction code"); + return IPCObjectStub::OnRemoteRequest(code, data, reply, option); + } + return 0; +} +} // namespace OHOS::Rosen \ No newline at end of file diff --git a/dmserver/src/display_node_control.cpp b/dmserver/src/display_node_control.cpp new file mode 100644 index 0000000000..8f821aca74 --- /dev/null +++ b/dmserver/src/display_node_control.cpp @@ -0,0 +1,19 @@ +/* + * 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_node_control.h" + +namespace OHOS::Rosen { +} // namespace OHOS::Rosen \ No newline at end of file diff --git a/dmserver/src/display_screen.cpp b/dmserver/src/display_screen.cpp new file mode 100644 index 0000000000..bbc1876a17 --- /dev/null +++ b/dmserver/src/display_screen.cpp @@ -0,0 +1,66 @@ +/* + * 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.h" + +namespace OHOS::Rosen { +DisplayScreen::DisplayScreen(const DisplayInfo& info) + : id_(info.id_), + width_(info.width_), + height_(info.height_), + freshRate_(info.freshRate_) +{ +} + +DisplayId DisplayScreen::GetId() const +{ + return id_; +} + +int32_t DisplayScreen::GetWidth() const +{ + return width_; +} + +int32_t DisplayScreen::GetHeight() const +{ + return height_; +} + +uint32_t DisplayScreen::GetFreshRate() const +{ + return freshRate_; +} + +void DisplayScreen::SetWidth(int32_t width) +{ + width_ = width; +} + +void DisplayScreen::SetHeight(int32_t height) +{ + height_ = height; +} + +void DisplayScreen::SetFreshRate(uint32_t freshRate) +{ + freshRate_ = freshRate; +} + +void DisplayScreen::SetId(DisplayId id) +{ + id_ = id; +} +} // namespace OHOS::Rosen \ No newline at end of file diff --git a/dmserver/src/display_screen_manager.cpp b/dmserver/src/display_screen_manager.cpp new file mode 100644 index 0000000000..91620c7493 --- /dev/null +++ b/dmserver/src/display_screen_manager.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 "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 new file mode 100644 index 0000000000..5e5d66581d --- /dev/null +++ b/dmserver/src/rs_adapter.cpp @@ -0,0 +1,99 @@ +/* + * 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 "rs_adapter.h" + +#include +#include +#include + +#include "window_manager_hilog.h" + +namespace OHOS::Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "RsAdapter"}; +} + +IMPLEMENT_SINGLE_INSTANCE(RsAdapter); + +bool RsAdapter::InitRSProxyLocked() +{ + WLOGFI("InitRProxy"); + if (!rsProxy_) { + sptr systemAbilityManager = + SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (!systemAbilityManager) { + WLOGFE("Failed to get system ability mgr."); + return false; + } + + sptr remoteObject + = systemAbilityManager->GetSystemAbility(); + if (!remoteObject) { + WLOGFE("Failed to get display manager service."); + return false; + } + + rsProxy_ = iface_cast(remoteObject); + if ((!rsProxy_) || (!rsProxy_->AsObject())) { + WLOGFE("Failed to get system display manager services"); + return false; + } + + rsDeath_ = new RSDeathRecipient(this); + if (!rsDeath_) { + WLOGFE("Failed to create death Recipient ptr RSDeathRecipient"); + return false; + } + if (!remoteObject->AddDeathRecipient(rsDeath_)) { + WLOGFE("Failed to add death recipient"); + return false; + } + } + return true; +} + +RSDeathRecipient::RSDeathRecipient(sptr& rsAdapter) +{ + rsAdatper_ = rsAdapter; +} + +void RSDeathRecipient::OnRemoteDied(const wptr& wptrDeath) +{ + if (wptrDeath == nullptr) { + WLOGFE("wptrDeath is null"); + return; + } + + sptr object = wptrDeath.promote(); + if (!object) { + WLOGFE("object is null"); + return; + } + if (rsAdapter_ != null) { + rsAdatper_.Clear(); + rsAdatper_ = nullptr; + } +} + +void RsAdapter::Clear() +{ + std::lock_guard lock(mutex_); + if ((rsProxy_ != nullptr) && (rsProxy_->AsObject() != nullptr)) { + rsProxy_->AsObject()->RemoveDeathRecipient(rsDeath_); + } + rsProxy_ = nullptr; +} +} // namespace OHOS::Rosen diff --git a/dmserver/src/screen.cpp b/dmserver/src/screen.cpp new file mode 100644 index 0000000000..11c222d130 --- /dev/null +++ b/dmserver/src/screen.cpp @@ -0,0 +1,19 @@ +/* + * 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 "screen.h" + +namespace OHOS::Rosen { +} // namespace OHOS::Rosen \ No newline at end of file diff --git a/figures/graphic.png b/figures/graphic.png new file mode 100644 index 0000000000000000000000000000000000000000..b72003f5221553d66ae4b4183f92bcfcac595bc2 GIT binary patch literal 46331 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 literal 0 HcmV?d00001 diff --git a/interfaces/innerkits/BUILD.gn b/interfaces/innerkits/BUILD.gn new file mode 100644 index 0000000000..19b8475396 --- /dev/null +++ b/interfaces/innerkits/BUILD.gn @@ -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. + +import("//build/ohos.gni") + +config("wm_interface_config") { + visibility = [ ":*" ] + include_dirs = [ "//foundation/windowmanager/interfaces/innerkits" ] +} + +ohos_shared_library("wm_interface") { + public_configs = [ ":wm_interface_config" ] + + include_dirs = [ "//foundation/windowmanager/interfaces/innerkits" ] + + public_deps = [ + "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", + "//foundation/graphic/standard/rosen/modules/render_service_client:librender_service_client", + "//foundation/multimodalinput/input/frameworks/proxy:libmmi-client", + "//utils/native/base:utils", + ] + + part_name = "window_manager" + subsystem_name = "window" +} diff --git a/interfaces/innerkits/dm/README.md b/interfaces/innerkits/dm/README.md new file mode 100644 index 0000000000..bf79d11158 --- /dev/null +++ b/interfaces/innerkits/dm/README.md @@ -0,0 +1 @@ +Store code of display client out header files diff --git a/interfaces/innerkits/dm/display.h b/interfaces/innerkits/dm/display.h new file mode 100644 index 0000000000..64b1bac72c --- /dev/null +++ b/interfaces/innerkits/dm/display.h @@ -0,0 +1,56 @@ +/* + * 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 p ermissions and + * limitations under the License. + */ + +#ifndef FOUNDATION_DM_DISPLAY_H +#define FOUNDATION_DM_DISPLAY_H + +#include + +#include + +namespace OHOS::Rosen { +class DisplayInfo; +using DisplayId = uint64_t; +static constexpr DisplayId DISPLAY_ID_INVALD = -1ULL; + +typedef enum DisplayType { + DEFAULT = 0, +} DisplayType; + +class Display : public RefBase { +public: + Display(const std::string& name, DisplayInfo* info); + ~Display() = default; + + DisplayId GetId() const; + int32_t GetWidth() const; + int32_t GetHeight() const; + uint32_t GetFreshRate() const; + + void SetId(DisplayId displayId); + void SetWidth(int32_t width); + void SetHeight(int32_t height); + void SetFreshRate(uint32_t freshRate); + +private: + std::string name_; + DisplayId id_ {DISPLAY_ID_INVALD}; + int32_t width_ {0}; + int32_t height_ {0}; + uint32_t freshRate_ {0}; +}; +} // namespace OHOS::Rosen + +#endif // FOUNDATION_DM_DISPLAY_H \ No newline at end of file diff --git a/interfaces/innerkits/dm/display_manager.h b/interfaces/innerkits/dm/display_manager.h new file mode 100644 index 0000000000..ed91aba1d3 --- /dev/null +++ b/interfaces/innerkits/dm/display_manager.h @@ -0,0 +1,48 @@ +/* + * 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_DM_DISPLAY_MANAGER_H +#define FOUNDATION_DM_DISPLAY_MANAGER_H + +#include +#include + +#include "display.h" +#include "single_instance.h" + +namespace OHOS::Rosen { +class DisplayManagerAdapter; + +class DisplayManager : public RefBase { +DECLARE_SINGLE_INSTANCE_BASE(DisplayManager); +public: + const sptr& GetDisplay(const DisplayType type); + std::vector> GetAllDisplays(); + + DisplayId GetDefaultDisplayId(); + const sptr GetDefaultDisplay(); + + const sptr GetDisplayById(DisplayId displayId); + + std::vector GetAllDisplayIds(); + +private: + DisplayManager(); + ~DisplayManager(); + sptr dmsAdapter_; +}; +} // namespace OHOS::Rosen + +#endif // FOUNDATION_DM_DISPLAY_MANAGER_H \ No newline at end of file diff --git a/interfaces/innerkits/dm/display_property.h b/interfaces/innerkits/dm/display_property.h new file mode 100644 index 0000000000..7409c0d12d --- /dev/null +++ b/interfaces/innerkits/dm/display_property.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 FOUNDATION_DM_DISPLAY_PROPERTY_H +#define FOUNDATION_DM_DISPLAY_PROPERTY_H + +#include + +namespace OHOS::Rosen { +class DisplayProperty : public RefBase { +public: + DisplayProperty() = default; + ~DisplayProperty() = default; + + DisplayType type_; + std::string name_; + + int width_; + int height_; + float xDpi_; + float yDpi_; + // Surface surface_; +}; +} // namespace OHOS::Rosen + +#endif // FOUNDATION_DM_DISPLAY_PROPERTY_H \ No newline at end of file diff --git a/interfaces/innerkits/dm/monitor.h b/interfaces/innerkits/dm/monitor.h new file mode 100644 index 0000000000..0cb2b16475 --- /dev/null +++ b/interfaces/innerkits/dm/monitor.h @@ -0,0 +1,24 @@ +/* + * 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_DM_MONITOR_H +#define FOUNDATION_DM_MONITOR_H + +namespace OHOS::Rosen { +class Monitor { +}; +} // namespace OHOS::Rosen + +#endif // FOUNDATION_DM_MONITOR_H \ No newline at end of file diff --git a/interfaces/innerkits/dmserver/README.md b/interfaces/innerkits/dmserver/README.md new file mode 100644 index 0000000000..24e92014b9 --- /dev/null +++ b/interfaces/innerkits/dmserver/README.md @@ -0,0 +1 @@ +Store code of display server out header files diff --git a/interfaces/innerkits/wm/README.md b/interfaces/innerkits/wm/README.md new file mode 100644 index 0000000000..9702ea7e24 --- /dev/null +++ b/interfaces/innerkits/wm/README.md @@ -0,0 +1 @@ +Store code of window client out header files diff --git a/interfaces/innerkits/wm/window.h b/interfaces/innerkits/wm/window.h new file mode 100644 index 0000000000..7b7d89eae0 --- /dev/null +++ b/interfaces/innerkits/wm/window.h @@ -0,0 +1,81 @@ +/* + * 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_H +#define OHOS_ROSEN_WINDOW_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include "wm_common.h" +#include "window_option.h" +#include "window_life_cycle_interface.h" + +class NativeValue; +class NativeEngine; + +namespace OHOS::AbilityRuntime { +class AbilityContext; +} + +namespace OHOS { +namespace Rosen { +class IWindowChangeListener : public RefBase { +public: + virtual void OnSizeChange(Rect rect) = 0; +}; + +class Window : public RefBase { +public: + static sptr Create(const std::string& windowName, + sptr& option, const sptr& abilityToken = nullptr); + static sptr Find(const std::string& windowName); + + virtual std::shared_ptr GetSurfaceNode() const = 0; + + virtual Rect GetRect() const = 0; + virtual WindowType GetType() const = 0; + virtual WindowMode GetMode() const = 0; + virtual const std::string& GetWindowName() const = 0; + virtual uint32_t GetWindowId() = 0; + + virtual WMError SetWindowType(WindowType type) = 0; + virtual WMError SetWindowMode(WindowMode mode) = 0; + + virtual WMError Destroy() = 0; + virtual WMError Show() = 0; + virtual WMError Hide() = 0; + + virtual WMError MoveTo(int32_t x, int32_t y) = 0; + virtual WMError Resize(uint32_t width, uint32_t height) = 0; + + virtual WMError RequestFocus() const = 0; + 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 RegisterLifeCycleListener(sptr& listener) = 0; + virtual void RegisterWindowChangeListener(sptr& listener) = 0; + virtual WMError SetUIContent(std::shared_ptr context, + std::string& url, NativeEngine* engine, NativeValue* storage) = 0; +}; +} +} +#endif // OHOS_ROSEN_WINDOW_H diff --git a/interfaces/innerkits/wm/window_life_cycle_interface.h b/interfaces/innerkits/wm/window_life_cycle_interface.h new file mode 100644 index 0000000000..c9fa54b2a3 --- /dev/null +++ b/interfaces/innerkits/wm/window_life_cycle_interface.h @@ -0,0 +1,32 @@ +/* + * 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_LIFE_CYCLE_H +#define OHOS_ROSEN_WINDOW_LIFE_CYCLE_H + +#include + +namespace OHOS { +namespace Rosen { +class IWindowLifeCycle : public RefBase { +public: + virtual void AfterForeground() = 0; + virtual void AfterBackground() = 0; + virtual void AfterFocused() = 0; + virtual void AfterUnFocused() = 0; +}; +} +} +#endif // OHOS_ROSEN_WINDOW_LIFE_CYCLE_H diff --git a/interfaces/innerkits/wm/window_option.h b/interfaces/innerkits/wm/window_option.h new file mode 100644 index 0000000000..9f695dae2f --- /dev/null +++ b/interfaces/innerkits/wm/window_option.h @@ -0,0 +1,63 @@ +/* + * 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_OPTION_H +#define OHOS_ROSEN_WINDOW_OPTION_H +#include +#include +#include "wm_common.h" + +namespace OHOS { +namespace Rosen { +class WindowOption : public RefBase { +public: + WindowOption(); + virtual ~WindowOption() = default; + + void SetWindowRect(const struct Rect& rect); + void SetWindowType(WindowType type); + void SetWindowMode(WindowMode mode); + void SetFocusable(bool isFocusable); + void SetTouchable(bool isTouchable); + void SetDisplayId(int32_t displayId); + void SetParentName(const std::string& parentName); + void SetWindowName(const std::string& windowName); + void AddWindowFlag(WindowFlag flag); + void RemoveWindowFlag(WindowFlag flag); + void SetWindowFlags(uint32_t flags); + + Rect GetWindowRect() const; + WindowType GetWindowType() const; + WindowMode GetWindowMode() const; + bool GetFocusable() const; + bool GetTouchable() const; + int32_t GetDisplayId() const; + const std::string& GetParentName() const; + const std::string& GetWindowName() const; + uint32_t GetWindowFlags() const; +private: + Rect windowRect_ { 0, 0, 0, 0 }; + WindowType type_ { WindowType::WINDOW_TYPE_APP_MAIN_WINDOW }; + WindowMode mode_ { WindowMode::WINDOW_MODE_FULLSCREEN }; + bool focusable_ { true }; + bool touchable_ { true }; + int32_t displayId_ { 0 }; + std::string parentName_ { "" }; + std::string windowName_ { "" }; + uint32_t flags_ { 0 }; +}; +} +} +#endif // OHOS_ROSEN_WINDOW_OPTION_H diff --git a/interfaces/innerkits/wm/window_scene.h b/interfaces/innerkits/wm/window_scene.h new file mode 100644 index 0000000000..dc984b01f9 --- /dev/null +++ b/interfaces/innerkits/wm/window_scene.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 INTERFACES_INNERKITS_WINDOW_SCENE_H +#define INTERFACES_INNERKITS_WINDOW_SCENE_H + +#include +#include +#include + +#include "window.h" +#include "window_option.h" + +namespace OHOS { +namespace Rosen { +class WindowScene : public RefBase { +public: + static const int32_t DEFAULT_DISPLAY_ID = 0; + static const std::string MAIN_WINDOW_ID; + + WindowScene() = default; + ~WindowScene(); + + WMError Init(int32_t displayId, std::shared_ptr& abilityContext, + sptr& listener); + + sptr CreateWindow(const std::string& windowName, sptr& option) const; + + const sptr& GetMainWindow() const; + + WMError GoForeground(); + WMError GoBackground() const; + + WMError RequestFocus() const; + +private: + static inline std::atomic count { 0 }; + sptr mainWindow_ = nullptr; + int32_t displayId_ = DEFAULT_DISPLAY_ID; + + std::shared_ptr abilityContext_ = nullptr; +}; +} // namespace Rosen +} // namespace OHOS +#endif // INTERFACES_INNERKITS_WINDOW_SCENE_H diff --git a/interfaces/innerkits/wm/wm_common.h b/interfaces/innerkits/wm/wm_common.h new file mode 100644 index 0000000000..cd472f88b1 --- /dev/null +++ b/interfaces/innerkits/wm/wm_common.h @@ -0,0 +1,96 @@ +/* + * 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_WM_COMMON_H +#define OHOS_ROSEN_WM_COMMON_H + +#include + +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_SUB_WINDOW_BASE = 1000, + WINDOW_TYPE_MEDIA = APP_SUB_WINDOW_BASE, + WINDOW_TYPE_APP_SUB_WINDOW, + APP_SUB_WINDOW_END = 1999, + + SYSTEM_WINDOW_BASE = 2000, + WINDOW_TYPE_WALLPAPER = SYSTEM_WINDOW_BASE, + ABOVE_APP_SYSTEM_WINDOW_BASE = 2100, + WINDOW_TYPE_APP_LAUNCHING, + 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, + SYSTEM_WINDOW_END = 2999, +}; + +enum class WindowMode : uint32_t { + WINDOW_MODE_FULLSCREEN, + WINDOW_MODE_SPLIT, + WINDOW_MODE_FLOATING, + WINDOW_MODE_PIP +}; + +enum class WMError : int32_t { + WM_OK = 0, + WM_ERROR_SAMGR = 100, + WM_ERROR_IPC_FAILED = 101, + WM_ERROR_NO_MEM = 110, + WM_ERROR_NULLPTR = 120, + WM_ERROR_INVALID_PARAM = 130, + WM_ERROR_DESTROYED_OBJECT = 140, + WM_ERROR_DEATH_RECIPIENT = 150, + WM_ERROR_INVALID_WINDOW = 160, + WM_ERROR_UNKNOWN, + + /* weston adater */ + WM_ERROR_WINDOWMANAGER_GETINSTANCE = 100000, + WM_ERROR_WINDOWMANAGER_INIT = 100001, + WM_ERROR_WINDOWMANAGER_SHOW = 100002, + WM_ERROR_WINDOWMANAGER_HIDE = 100003, + WM_ERROR_WINDOWMANAGER_MOVE = 100004, + WM_ERROR_WINDOWMANAGER_RESIZE = 100005, +}; + +enum class WindowFlag : uint32_t { + WINDOW_FLAG_NEED_AVOID = 1, + WINDOW_FLAG_PARENT_LIMIT = 1 << 1, + WINDOW_FLAG_END = 1 << 2, +}; + +struct Rect { + int32_t posX_; + int32_t posY_; + uint32_t width_; + uint32_t height_; +}; +} +} +#endif // OHOS_ROSEN_WM_COMMON_H diff --git a/interfaces/innerkits/wmserver/README.md b/interfaces/innerkits/wmserver/README.md new file mode 100644 index 0000000000..449c0fe9fd --- /dev/null +++ b/interfaces/innerkits/wmserver/README.md @@ -0,0 +1 @@ +Store code of window server out header files diff --git a/interfaces/kits/README.md b/interfaces/kits/README.md new file mode 100644 index 0000000000..033c7c544c --- /dev/null +++ b/interfaces/kits/README.md @@ -0,0 +1 @@ +Store code of window js api diff --git a/interfaces/kits/js/declaration/BUILD.gn b/interfaces/kits/js/declaration/BUILD.gn new file mode 100644 index 0000000000..d63c1a22e0 --- /dev/null +++ b/interfaces/kits/js/declaration/BUILD.gn @@ -0,0 +1,29 @@ +# 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("//build/ohos.gni") + +js_declaration("window") { + sources = [ "./api" ] + + part_name = "window_manager" +} + +ohos_copy("window_declaration") { + sources = [ "./api" ] + + outputs = [ target_out_dir + "/$target_name/" ] + + module_source_dir = target_out_dir + "/$target_name" + module_install_name = "" +} diff --git a/interfaces/kits/js/declaration/api/@ohos.display.d.ts b/interfaces/kits/js/declaration/api/@ohos.display.d.ts new file mode 100644 index 0000000000..17ac54ae5d --- /dev/null +++ b/interfaces/kits/js/declaration/api/@ohos.display.d.ts @@ -0,0 +1,135 @@ +/* +* 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. +*/ + +/** + * interface of display manager + * @devices tv, phone, tablet, wearable + */ +declare namespace display { + /** + * get the default display + * @devices tv, phone, tablet, wearable + */ + function getDefaultDisplay(): Promise; + + /** + /** + * the state of display + * @devices tv, phone, tablet, wearable + */ + enum DisplayState { + /** + * unknown + */ + STATE_UNKNOWN = 0, + /** + * screen off + */ + STATE_OFF, + /** + * screen on + */ + STATE_ON, + /** + * doze, but it will update for some important system messages + */ + STATE_DOZE, + /** + * doze and not update + */ + STATE_DOZE_SUSPEND, + /** + * VR node + */ + STATE_VR, + /** + * screen on and not update + */ + STATE_ON_SUSPEND, + } + + /** + * Properties of display, it couldn't update automatically + * @devices tv, phone, tablet, wearable + */ + interface Display { + /** + * display id + */ + id: number; + + /** + * display name + */ + name: string; + + /** + * the display is alive + */ + alive: boolean; + + /** + * the state of display + */ + state: DisplayState; + + /** + * refresh rate, unit: Hz + */ + refreshRate: number; + + /** + * the rotation degrees of the display + */ + rotation: number; + + /** + * the width of display, unit: pixel + */ + width: number; + + /** + * the height of display, unit: pixel + */ + height: number; + + /** + * indicates the display resolution. + */ + densityDPI: number; + + /** + * indicates the display density in pixels. The value of a low-resolution display is 1.0 + */ + densityPixels: number; + + /** + * indicates the text scale density of a display. + */ + scaledDensity: number; + + /** + * the DPI on X-axis. + */ + xDPI: number; + + /** + * the DPI on Y-axis. + */ + yDPI: number; + } +} + +export default display; diff --git a/interfaces/kits/js/declaration/api/@ohos.window.d.ts b/interfaces/kits/js/declaration/api/@ohos.window.d.ts new file mode 100644 index 0000000000..3872e90048 --- /dev/null +++ b/interfaces/kits/js/declaration/api/@ohos.window.d.ts @@ -0,0 +1,79 @@ +/* +* 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 window { + /** + * Obtain the top window of the current application. + * @devices tv, phone, tablet, wearable. + */ + function getTopWindow(): Promise; + + /** + * The type of a window. + * @devices tv, phone, tablet, wearable. + */ + enum WindowType { + /** + * App. + */ + TYPE_APP = 0, + /** + * System alert. + */ + TYPE_SYSTEM_ALERT = 30, + /** + * System volume. + */ + TYPE_SYSTEM_VOLUME = 70, + /** + * System panel. + */ + TYPE_SYSTEM_PANEL = 90, + } + + /** + * The interface of window. + */ + interface Window { + /** + * 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. + */ + resetSize(width: number, height: number): Promise; + + /** + * Set the type of a window. + * @param type Indicate the type of a window. + * @devices tv, phone, tablet, wearable, liteWearable. + */ + setWindowType(type: WindowType): Promise; + } +} + +export default window; diff --git a/interfaces/kits/napi/BUILD.gn b/interfaces/kits/napi/BUILD.gn new file mode 100644 index 0000000000..00c0281a28 --- /dev/null +++ b/interfaces/kits/napi/BUILD.gn @@ -0,0 +1,58 @@ +# 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") + +ts2abc_gen_abc("gen_window_stage_abc") { + src_js = rebase_path("window_stage.js") + dst_file = rebase_path(target_out_dir + "/window_stage.abc") + in_puts = [ "window_stage.js" ] + out_puts = [ target_out_dir + "/window_stage.abc" ] + extra_args = [ "--module" ] +} + +gen_js_obj("window_stage_js") { + input = "window_stage.js" + output = target_out_dir + "/window_stage.o" +} + +gen_js_obj("window_stage_abc") { + input = get_label_info(":gen_window_stage_abc", "target_out_dir") + + "/window_stage.abc" + output = target_out_dir + "/window_stage_abc.o" + dep = ":gen_window_stage_abc" +} + +ohos_shared_library("windowstage") { + sources = [ "window_stage_module.cpp" ] + + deps = [ + ":window_stage_abc", + ":window_stage_js", + ] + + external_deps = [ "napi:ace_napi" ] + + relative_install_dir = "module/application" + + part_name = "window_manager" + subsystem_name = "window" +} + +group("napi_packages") { + deps = [ + "display:display", + "window:window", + ] +} diff --git a/interfaces/kits/napi/common/BUILD.gn b/interfaces/kits/napi/common/BUILD.gn new file mode 100644 index 0000000000..081352bd7b --- /dev/null +++ b/interfaces/kits/napi/common/BUILD.gn @@ -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. + +import("//build/ohos.gni") + +## Build wm_napi_common.a {{{ +config("wm_napi_common_config") { + visibility = [ ":*" ] + + cflags = [ + "-Wall", + "-Werror", + "-g3", + ] +} + +config("wm_napi_common_public_config") { + include_dirs = [ + ".", + "//third_party/node/src", + ] +} + +ohos_static_library("wm_napi_common") { + sources = [ "wm_napi_common.cpp" ] + + configs = [ ":wm_napi_common_config" ] + + public_configs = [ ":wm_napi_common_public_config" ] + + public_deps = [ + "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog", + "//foundation/ace/napi:ace_napi", + ] +} +## Build wm_napi_common.a }}} diff --git a/interfaces/kits/napi/common/wm_napi_common.cpp b/interfaces/kits/napi/common/wm_napi_common.cpp new file mode 100644 index 0000000000..16b5e6ef53 --- /dev/null +++ b/interfaces/kits/napi/common/wm_napi_common.cpp @@ -0,0 +1,44 @@ +/* + * 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_napi_common.h" + +#include + +namespace OHOS { +napi_status SetMemberInt32(napi_env env, napi_value result, const char *key, int32_t value) +{ + napi_value num; + GNAPI_INNER(napi_create_int32(env, value, &num)); + GNAPI_INNER(napi_set_named_property(env, result, key, num)); + return napi_ok; +} + +napi_status SetMemberUint32(napi_env env, napi_value result, const char *key, uint32_t value) +{ + napi_value num; + GNAPI_INNER(napi_create_uint32(env, value, &num)); + GNAPI_INNER(napi_set_named_property(env, result, key, num)); + return napi_ok; +} + +napi_status SetMemberUndefined(napi_env env, napi_value result, const char *key) +{ + napi_value undefined; + GNAPI_INNER(napi_get_undefined(env, &undefined)); + GNAPI_INNER(napi_set_named_property(env, result, key, undefined)); + return napi_ok; +} +} // namespace OHOS diff --git a/interfaces/kits/napi/common/wm_napi_common.h b/interfaces/kits/napi/common/wm_napi_common.h new file mode 100644 index 0000000000..480c511de1 --- /dev/null +++ b/interfaces/kits/napi/common/wm_napi_common.h @@ -0,0 +1,111 @@ +/* + * 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 INTERFACES_KITS_NAPI_GRAPHIC_COMMON_COMMON_H +#define INTERFACES_KITS_NAPI_GRAPHIC_COMMON_COMMON_H + +#include +#include + +#include +#include +#include +#include + +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, 0, "NapiWindowManagerCommonLayer" }; + +#define GNAPI_LOG(fmt, ...) OHOS::HiviewDFX::HiLog::Info(LABEL, \ + "%{public}s:%{public}d " fmt, __func__, __LINE__, ##__VA_ARGS__) + +#define GNAPI_ASSERT(env, assertion, fmt, ...) \ + do { \ + if (assertion) { \ + GNAPI_LOG(fmt, ##__VA_ARGS__); \ + return nullptr; \ + } \ + } while (0) + +#define GNAPI_INNER(call) \ + do { \ + napi_status s = (call); \ + if (s != napi_ok) { \ + GNAPI_LOG(#call " is %{public}d", s); \ + return s; \ + } \ + } while (0) + +namespace OHOS { +napi_status SetMemberInt32(napi_env env, napi_value result, const char *key, int32_t value); +napi_status SetMemberUint32(napi_env env, napi_value result, const char *key, uint32_t value); +napi_status SetMemberUndefined(napi_env env, napi_value result, const char *key); + +template +napi_value CreatePromise(napi_env env, + std::string funcname, + void(*async)(napi_env env, std::unique_ptr& param), + napi_value(*resolve)(napi_env env, std::unique_ptr& param), + std::unique_ptr& param) +{ + struct AsyncCallbackInfo { + napi_async_work asyncWork; + napi_deferred deferred; + void (*async)(napi_env env, std::unique_ptr& param); + napi_value (*resolve)(napi_env env, std::unique_ptr& param); + std::unique_ptr param; + }; + + AsyncCallbackInfo *info = new AsyncCallbackInfo { + .async = async, + .resolve = resolve, + .param = std::move(param), + }; + + napi_value resourceName; + NAPI_CALL(env, napi_create_string_latin1(env, + funcname.c_str(), NAPI_AUTO_LENGTH, &resourceName)); + + napi_value promise; + NAPI_CALL(env, napi_create_promise(env, &info->deferred, &promise)); + + auto asyncFunc = [](napi_env env, void *data) { + AsyncCallbackInfo *info = reinterpret_cast(data); + if (info->async) { + info->async(env, info->param); + } + }; + + auto completeFunc = [](napi_env env, napi_status status, void *data) { + AsyncCallbackInfo *info = reinterpret_cast(data); + napi_value resolveValue; + if (info->resolve) { + resolveValue = info->resolve(env, info->param); + } else { + napi_get_undefined(env, &resolveValue); + } + + napi_resolve_deferred(env, info->deferred, resolveValue); + napi_delete_async_work(env, info->asyncWork); + delete info; + }; + + NAPI_CALL(env, napi_create_async_work(env, nullptr, resourceName, asyncFunc, completeFunc, + reinterpret_cast(info), &info->asyncWork)); + + NAPI_CALL(env, napi_queue_async_work(env, info->asyncWork)); + return promise; +}; +} // namespace OHOS + +#endif // INTERFACES_KITS_NAPI_GRAPHIC_COMMON_COMMON_H diff --git a/interfaces/kits/napi/display/BUILD.gn b/interfaces/kits/napi/display/BUILD.gn new file mode 100644 index 0000000000..574ecb8a1c --- /dev/null +++ b/interfaces/kits/napi/display/BUILD.gn @@ -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. + +import("//build/ohos.gni") + +## Build display.so {{{ +ohos_shared_library("display") { + sources = [ "native_display_module.cpp" ] + + deps = [ + "../common:wm_napi_common", + "//foundation/windowmanager/wm:libwm", + "//foundation/windowmanager/wmserver:libwms", + ] + + relative_install_dir = "module" + part_name = "window_manager" + subsystem_name = "window" +} +## Build display.so }}} diff --git a/interfaces/kits/napi/display/native_display_module.cpp b/interfaces/kits/napi/display/native_display_module.cpp new file mode 100644 index 0000000000..613ffaa0de --- /dev/null +++ b/interfaces/kits/napi/display/native_display_module.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 "display_manager.h" +#include "native_display_module.h" +#include "wm_common.h" +#include "wm_napi_common.h" + +namespace OHOS { +namespace Rosen { +namespace getDefaultDisplay { +struct Param { + WMError wret; + sptr display; +}; + +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(); + if (param->display == nullptr) { + GNAPI_LOG("Get display failed!"); + param->wret = WMError::WM_ERROR_NULLPTR; + return; + } + GNAPI_LOG("GetDefaultDisplay: id %llu, w %d, h %d", + param->display->GetId(), param->display->GetWidth(), param->display->GetHeight()); + param->wret = WMError::WM_OK; +} + +napi_value Resolve(napi_env env, std::unique_ptr ¶m) +{ + napi_value result; + if (param->wret != WMError::WM_OK) { + NAPI_CALL(env, napi_get_undefined(env, &result)); + return result; + } + + DisplayId id = param->display->GetId(); + int32_t width = param->display->GetWidth(); + int32_t height = param->display->GetHeight(); + GNAPI_LOG("id : %{public}llu", id); + GNAPI_LOG("width : %{public}d", width); + GNAPI_LOG("height : %{public}d", height); + + NAPI_CALL(env, napi_create_object(env, &result)); + NAPI_CALL(env, SetMemberInt32(env, result, "id", id)); + NAPI_CALL(env, SetMemberUndefined(env, result, "name")); + NAPI_CALL(env, SetMemberUndefined(env, result, "alive")); + NAPI_CALL(env, SetMemberUndefined(env, result, "state")); + NAPI_CALL(env, SetMemberUndefined(env, result, "refreshRate")); + NAPI_CALL(env, SetMemberUndefined(env, result, "rotation")); + NAPI_CALL(env, SetMemberUint32(env, result, "width", width)); + NAPI_CALL(env, SetMemberUint32(env, result, "height", height)); + NAPI_CALL(env, SetMemberUndefined(env, result, "densityDPI")); + NAPI_CALL(env, SetMemberUndefined(env, result, "densityPixels")); + NAPI_CALL(env, SetMemberUndefined(env, result, "scaledDensity")); + NAPI_CALL(env, SetMemberUndefined(env, result, "xDPI")); + NAPI_CALL(env, SetMemberUndefined(env, result, "yDPI")); + + return result; +} + +napi_value MainFunc(napi_env env, napi_callback_info info) +{ + GNAPI_LOG("Display Interface: getDefaultDisplay()"); + GNAPI_LOG("%{public}s called", __PRETTY_FUNCTION__); + auto param = std::make_unique(); + return CreatePromise(env, __PRETTY_FUNCTION__, Async, Resolve, param); +} +} // namespace getDefaultDisplay + +napi_value DisplayModuleInit(napi_env env, napi_value exports) +{ + GNAPI_LOG("%{public}s called", __PRETTY_FUNCTION__); + + napi_property_descriptor properties[] = { + DECLARE_NAPI_FUNCTION("getDefaultDisplay", getDefaultDisplay::MainFunc), + }; + + NAPI_CALL(env, napi_define_properties(env, + exports, sizeof(properties) / sizeof(properties[0]), properties)); + return exports; +} +} // namespace Rosen +} // namespace OHOS + +extern "C" __attribute__((constructor)) void RegisterModule(void) +{ + napi_module displayModule = { + .nm_version = 1, // NAPI v1 + .nm_flags = 0, // normal + .nm_filename = nullptr, + .nm_register_func = OHOS::Rosen::DisplayModuleInit, + .nm_modname = "display", + .nm_priv = nullptr, + }; + napi_module_register(&displayModule); +} diff --git a/interfaces/kits/napi/display/native_display_module.h b/interfaces/kits/napi/display/native_display_module.h new file mode 100644 index 0000000000..a24c7026ab --- /dev/null +++ b/interfaces/kits/napi/display/native_display_module.h @@ -0,0 +1,19 @@ +/* + * 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 INTERFACES_KITS_NAPI_GRAPHIC_DISPLAY_NATIVE_MODULE_H +#define INTERFACES_KITS_NAPI_GRAPHIC_DISPLAY_NATIVE_MODULE_H + +#endif // INTERFACES_KITS_NAPI_GRAPHIC_DISPLAY_NATIVE_MODULE_H diff --git a/interfaces/kits/napi/window/BUILD.gn b/interfaces/kits/napi/window/BUILD.gn new file mode 100644 index 0000000000..449bfb7fb4 --- /dev/null +++ b/interfaces/kits/napi/window/BUILD.gn @@ -0,0 +1,40 @@ +# 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("//build/ohos.gni") + +## Build window.so {{{ +ohos_shared_library("window") { + sources = [ "native_window_module.cpp" ] + + configs = [ + "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_core:bundlemgr_sdk_config", + "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base:appexecfwk_base_sdk_config", + "//foundation/aafwk/standard/interfaces/innerkits/want:want_public_config", + "//foundation/aafwk/standard/interfaces/innerkits/ability_manager:ability_manager_public_config", + "//foundation/aafwk/standard/services/abilitymgr:abilityms_config", + ] + + deps = [ + "../common:wm_napi_common", + "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native", + "//foundation/appexecfwk/standard/kits:appkit_native", + "//foundation/windowmanager/wm:libwm", + "//foundation/windowmanager/wmserver:libwms", + ] + + relative_install_dir = "module" + part_name = "window_manager" + subsystem_name = "window" +} +## Build window.so }}} diff --git a/interfaces/kits/napi/window/native_window_module.cpp b/interfaces/kits/napi/window/native_window_module.cpp new file mode 100644 index 0000000000..c009e2aa99 --- /dev/null +++ b/interfaces/kits/napi/window/native_window_module.cpp @@ -0,0 +1,233 @@ +/* + * 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 + +#include "native_window_module.h" +#include "window.h" +#include "window_scene.h" +#include "wm_common.h" +#include "wm_napi_common.h" + +namespace OHOS { +namespace Rosen { +namespace { +napi_value g_classWindow; +napi_status GetAbility(napi_env env, napi_callback_info info, AppExecFwk::Ability* &pAbility) +{ + napi_value global; + GNAPI_INNER(napi_get_global(env, &global)); + + napi_value jsAbility; + GNAPI_INNER(napi_get_named_property(env, global, "ability", &jsAbility)); + + GNAPI_INNER(napi_get_value_external(env, jsAbility, reinterpret_cast(&pAbility))); + + return napi_ok; +} +} // namespace + + +namespace NAPIWindow { +napi_value WindowConstructor(napi_env env, napi_callback_info info) +{ + napi_value jsthis = nullptr; + NAPI_CALL(env, napi_get_cb_info(env, info, nullptr, nullptr, &jsthis, nullptr)); + return jsthis; +} + +namespace ResetSize { +struct Param { + ::OHOS::AppExecFwk::Ability *ability; + int width; + int height; +}; + +void Async(napi_env env, std::unique_ptr& param) +{ + param->ability->GetScene()->GetMainWindow()->Resize(param->width, param->height); +} + +napi_value MainFunc(napi_env env, napi_callback_info info) +{ + GNAPI_LOG("Window Interface: ResetSize()"); + GNAPI_LOG("%{public}s called", __PRETTY_FUNCTION__); + constexpr int argumentSize = 2; + size_t argc = argumentSize; + napi_value argv[argc]; + + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr)); + + GNAPI_ASSERT(env, argc < argumentSize, "ResetSize need %{public}d arguments", argumentSize); + + auto param = std::make_unique(); + NAPI_CALL(env, GetAbility(env, info, param->ability)); + NAPI_CALL(env, napi_get_value_int32(env, argv[0], ¶m->width)); + NAPI_CALL(env, napi_get_value_int32(env, argv[1], ¶m->height)); + + return CreatePromise(env, __PRETTY_FUNCTION__, Async, nullptr, param); +} +} // namespace ResetSize + +namespace MoveTo { +struct Param { + ::OHOS::AppExecFwk::Ability *ability; + int x; + int y; +}; + +void Async(napi_env env, std::unique_ptr& param) +{ + param->ability->GetScene()->GetMainWindow()->MoveTo(param->x, param->y); +} + +napi_value MainFunc(napi_env env, napi_callback_info info) +{ + GNAPI_LOG("Window Interface: MoveTo()"); + GNAPI_LOG("%{public}s called", __PRETTY_FUNCTION__); + constexpr int argumentSize = 2; + size_t argc = argumentSize; + napi_value argv[argc]; + + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr)); + + GNAPI_ASSERT(env, argc < argumentSize, "MoveTo need %{public}d arguments", argumentSize); + + auto param = std::make_unique(); + NAPI_CALL(env, GetAbility(env, info, param->ability)); + NAPI_CALL(env, napi_get_value_int32(env, argv[0], ¶m->x)); + NAPI_CALL(env, napi_get_value_int32(env, argv[1], ¶m->y)); + + return CreatePromise(env, __PRETTY_FUNCTION__, Async, nullptr, param); +} +} // namespace MoveTo + +namespace SetWindowType { +struct Param { + ::OHOS::AppExecFwk::Ability *ability; + int windowType; +}; + +void Async(napi_env env, std::unique_ptr& param) +{ + param->ability->GetScene()->GetMainWindow()->SetWindowType(static_cast(param->windowType)); +} + +void CreateWindowTypeObject(napi_env env, napi_value value) +{ + SetMemberInt32(env, value, "TYPE_APP", static_cast(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW)); + SetMemberInt32(env, value, "TYPE_SYSTEM_ALERT", static_cast(WindowType::WINDOW_TYPE_SYSTEM_ALARM_WINDOW)); + SetMemberInt32(env, value, "TYPE_SYSTEM_VOLUME", static_cast(WindowType::WINDOW_TYPE_VOLUME_OVERLAY)); + SetMemberInt32(env, value, "TYPE_SYSTEM_PANEL", static_cast(WindowType::WINDOW_TYPE_PANEL)); +} + +napi_value MainFunc(napi_env env, napi_callback_info info) +{ + GNAPI_LOG("Window Interface: SetWindowType()"); + GNAPI_LOG("%{public}s called", __PRETTY_FUNCTION__); + constexpr int argumentSize = 1; + size_t argc = argumentSize; + napi_value argv[argc]; + + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr)); + + GNAPI_ASSERT(env, argc < argumentSize, "SetWindowType need %{public}d arguments", argumentSize); + + auto param = std::make_unique(); + NAPI_CALL(env, GetAbility(env, info, param->ability)); + NAPI_CALL(env, napi_get_value_int32(env, argv[0], ¶m->windowType)); + + return CreatePromise(env, __PRETTY_FUNCTION__, Async, nullptr, param); +} +} // namespace SetWindowType +} // namespace NAPIWindow + +namespace getTopWindow { +struct Param { + ::OHOS::AppExecFwk::Ability *ability; + WMError wret; + sptr window; +}; + +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!"); + param->wret = WMError::WM_ERROR_NULLPTR; + return; + } + param->wret = WMError::WM_OK; +} + +napi_value Resolve(napi_env env, std::unique_ptr& userdata) +{ + napi_value ret; + NAPI_CALL(env, napi_new_instance(env, g_classWindow, 0, nullptr, &ret)); + return ret; +} + +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(); + return CreatePromise(env, __PRETTY_FUNCTION__, Async, Resolve, param); +} +} // namespace getTopWindow + +napi_value WindowModuleInit(napi_env env, napi_value exports) +{ + GNAPI_LOG("%{public}s called", __PRETTY_FUNCTION__); + + napi_value nWindowType = nullptr; + NAPI_CALL(env, napi_create_object(env, &nWindowType)); + NAPIWindow::SetWindowType::CreateWindowTypeObject(env, nWindowType); + + napi_property_descriptor desc[] = { + DECLARE_NAPI_FUNCTION("resetSize", NAPIWindow::ResetSize::MainFunc), + DECLARE_NAPI_FUNCTION("moveTo", NAPIWindow::MoveTo::MainFunc), + DECLARE_NAPI_FUNCTION("setWindowType", NAPIWindow::SetWindowType::MainFunc), + }; + + NAPI_CALL(env, napi_define_class(env, "Window", NAPI_AUTO_LENGTH, + NAPIWindow::WindowConstructor, nullptr, + sizeof(desc) / sizeof(*desc), desc, &g_classWindow)); + + napi_property_descriptor exportFuncs[] = { + DECLARE_NAPI_FUNCTION("getTopWindow", getTopWindow::MainFunc), + DECLARE_NAPI_PROPERTY("WindowType", nWindowType), + DECLARE_NAPI_PROPERTY("Window", g_classWindow), + }; + + NAPI_CALL(env, napi_define_properties(env, + exports, sizeof(exportFuncs) / sizeof(*exportFuncs), exportFuncs)); + return exports; +} +} // namespace Rosen +} // namespace OHOS + +extern "C" __attribute__((constructor)) void RegisterModule(void) +{ + napi_module windowModule = { + .nm_version = 1, // NAPI v1 + .nm_flags = 0, // normal + .nm_filename = nullptr, + .nm_register_func = OHOS::Rosen::WindowModuleInit, + .nm_modname = "window", + .nm_priv = nullptr, + }; + napi_module_register(&windowModule); +} diff --git a/interfaces/kits/napi/window/native_window_module.h b/interfaces/kits/napi/window/native_window_module.h new file mode 100644 index 0000000000..c4a21c440c --- /dev/null +++ b/interfaces/kits/napi/window/native_window_module.h @@ -0,0 +1,19 @@ +/* + * 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 INTERFACES_KITS_NAPI_GRAPHIC_WINDOW_NATIVE_WINDOW_MODULE_H +#define INTERFACES_KITS_NAPI_GRAPHIC_WINDOW_NATIVE_WINDOW_MODULE_H + +#endif // INTERFACES_KITS_NAPI_GRAPHIC_WINDOW_NATIVE_WINDOW_MODULE_H diff --git a/interfaces/kits/napi/window_stage.js b/interfaces/kits/napi/window_stage.js new file mode 100644 index 0000000000..43af79d1a0 --- /dev/null +++ b/interfaces/kits/napi/window_stage.js @@ -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. + */ + +class WindowStage { + constructor(obj) { + this.__window_stage__ = obj + } + + setUIContent(context, url, storage) { + return this.__window_stage__.setUIContent(context, url, storage) + } +} + +export default WindowStage diff --git a/interfaces/kits/napi/window_stage_module.cpp b/interfaces/kits/napi/window_stage_module.cpp new file mode 100644 index 0000000000..b6ad1d3a65 --- /dev/null +++ b/interfaces/kits/napi/window_stage_module.cpp @@ -0,0 +1,58 @@ +/* + * 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" + +extern const char _binary_window_stage_js_start[]; +extern const char _binary_window_stage_js_end[]; +extern const char _binary_window_stage_abc_start[]; +extern const char _binary_window_stage_abc_end[]; + +extern "C" __attribute__((constructor)) +void NAPI_application_WindowStage_AutoRegister() +{ + auto moduleManager = NativeModuleManager::GetInstance(); + NativeModule newModuleInfo = { + .name = "application.WindowStage", + .fileName = "application/libwindowstage.so/window_stage.js", + }; + + moduleManager->Register(&newModuleInfo); +} + +extern "C" __attribute__((visibility("default"))) +void NAPI_application_WindowStage_GetJSCode(const char **buf, int *bufLen) +{ + if (buf != nullptr) { + *buf = _binary_window_stage_js_start; + } + + if (bufLen != nullptr) { + *bufLen = _binary_window_stage_js_end - _binary_window_stage_js_start; + } +} + +// window_stage JS register +extern "C" __attribute__((visibility("default"))) +void NAPI_application_WindowStage_GetABCCode(const char **buf, int *buflen) +{ + if (buf != nullptr) { + *buf = _binary_window_stage_abc_start; + } + if (buflen != nullptr) { + *buflen = _binary_window_stage_abc_end - _binary_window_stage_abc_start; + } +} + diff --git a/ohos.build b/ohos.build new file mode 100644 index 0000000000..49aaabd0f0 --- /dev/null +++ b/ohos.build @@ -0,0 +1,22 @@ +{ + "subsystem": "window", + "parts": { + "window_manager": { + "module_list": [ + "//foundation/windowmanager/interfaces/kits/js/declaration:window", + "//foundation/windowmanager/sa_profile:wms_sa_profile", + "//foundation/windowmanager/adapter:libwmadaptertest", + "//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" + ], + + "test_list": [ + ] + } + } +} diff --git a/sa_profile/4605.xml b/sa_profile/4605.xml new file mode 100644 index 0000000000..9197521b84 --- /dev/null +++ b/sa_profile/4605.xml @@ -0,0 +1,26 @@ + + + + foundation + + 4605 + libwms.z.so + + + true + false + 1 + + \ No newline at end of file diff --git a/sa_profile/4606.xml b/sa_profile/4606.xml new file mode 100644 index 0000000000..7a02c334da --- /dev/null +++ b/sa_profile/4606.xml @@ -0,0 +1,26 @@ + + + + foundation + + 4606 + libwms.z.so + + + true + false + 1 + + diff --git a/sa_profile/BUILD.gn b/sa_profile/BUILD.gn new file mode 100644 index 0000000000..f3a586d781 --- /dev/null +++ b/sa_profile/BUILD.gn @@ -0,0 +1,22 @@ +# 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("//build/ohos/sa_profile/sa_profile.gni") + +ohos_sa_profile("wms_sa_profile") { + sources = [ + "4605.xml", + "4606.xml", + ] + part_name = "window_manager" +} diff --git a/utils/include/single_instance.h b/utils/include/single_instance.h new file mode 100644 index 0000000000..b255caf73d --- /dev/null +++ b/utils/include/single_instance.h @@ -0,0 +1,44 @@ +/* + * 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_SINGLE_INSTANCE_H +#define OHOS_SINGLE_INSTANCE_H +namespace OHOS { +namespace Rosen { +#define DECLARE_SINGLE_INSTANCE_BASE(className) \ +public: \ + static sptr GetInstance(); \ +private: \ + className(const className&) = delete; \ + className& operator= (const className&) = delete; \ + className(className&&) = delete; \ + className& operator= (className&&) = delete; \ + + +#define DECLARE_SINGLE_INSTANCE(className) \ + DECLARE_SINGLE_INSTANCE_BASE(className) \ +private: \ + className() = default; \ + ~className() = default; \ + +#define IMPLEMENT_SINGLE_INSTANCE(className) \ +sptr className::GetInstance() \ +{ \ + static sptr instance = new className(); \ + return instance; \ +} +} // namespace OHOS +} +#endif // OHOS_SINGLE_INSTANCE_H diff --git a/utils/include/singleton_container.h b/utils/include/singleton_container.h new file mode 100644 index 0000000000..68d6d7e8ec --- /dev/null +++ b/utils/include/singleton_container.h @@ -0,0 +1,81 @@ +/* + * 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_SINGLETON_CONTAINER_H +#define OHOS_SINGLETON_CONTAINER_H + +#include +#include +#include +#include +#include + +#include + +namespace OHOS { +namespace Rosen { +class SingletonContainer : public RefBase { +public: + static sptr GetInstance(); + + 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); + + template + static sptr 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; + } + + template + static void Set(const sptr &ptr) + { + 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); + } + +private: + SingletonContainer() = default; + virtual ~SingletonContainer() override; + static inline sptr instance = nullptr; + + struct Singleton { + std::any value; + int32_t refCount; + }; + std::map stringMap; + std::map singletonMap; + std::map> dependencySetMap; +}; +} // 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 new file mode 100644 index 0000000000..dae000468f --- /dev/null +++ b/utils/include/singleton_delegator.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_SINGLETON_DELEGATOR_H +#define OHOS_SINGLETON_DELEGATOR_H + +#include "singleton_container.h" + +#define MOCKABLE virtual + +namespace OHOS { +namespace Rosen { +template +class SingletonDelegator { +public: + SingletonDelegator() + { + nameT = __PRETTY_FUNCTION__; + nameT = nameT.substr(nameT.find("T = ")); + nameT = nameT.substr(sizeof("T ="), nameT.length() - sizeof("T = ")); + SingletonContainer::GetInstance()->AddSingleton(nameT, T::GetInstance()); + } + ~SingletonDelegator() = default; + + template + sptr 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); + } + return ret; + } + +private: + std::string nameT; +}; +} // namespace Rosen +} // namespace OHOS + +#endif // FRAMEWORKS_WM_INCLUDE_SINGLETON_DELEGATOR_H diff --git a/utils/include/static_call.h b/utils/include/static_call.h new file mode 100644 index 0000000000..e505d2b7ab --- /dev/null +++ b/utils/include/static_call.h @@ -0,0 +1,39 @@ +/* + * 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_STATIC_CALL_H +#define OHOS_STATIC_CALL_H + +#include +#include "singleton_delegator.h" +#include "single_instance.h" +#include "window.h" +#include "window_option.h" +namespace OHOS { +namespace Rosen { +class StaticCall : public RefBase { + DECLARE_SINGLE_INSTANCE_BASE(StaticCall); +public: + virtual sptr CreateWindow(const std::string& windowName, + sptr& option, const sptr& abilityToken = nullptr); +protected: + StaticCall() = default; +private: + static inline SingletonDelegator delegator_; +}; +} // namespace ROSEN +} // namespace OHOS + +#endif // FRAMEWORKS_WM_TEST_UT_STATIC_CALL_H \ No newline at end of file diff --git a/utils/include/window_manager_hilog.h b/utils/include/window_manager_hilog.h new file mode 100644 index 0000000000..bf790ce888 --- /dev/null +++ b/utils/include/window_manager_hilog.h @@ -0,0 +1,50 @@ +/* + * 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_WINDOW_MANAGER_HILOG_H +#define OHOS_WM_INCLUDE_WINDOW_MANAGER_HILOG_H + +#include "hilog/log.h" +namespace OHOS { +namespace Rosen { +static constexpr OHOS::HiviewDFX::HiLogLabel LOG_LABEL = {LOG_CORE, 0, "WindowManager"}; + +#define WLOG_F(...) (void)OHOS::HiviewDFX::HiLog::Fatal(LOG_LABEL, __VA_ARGS__) +#define WLOG_E(...) (void)OHOS::HiviewDFX::HiLog::Error(LOG_LABEL, __VA_ARGS__) +#define WLOG_W(...) (void)OHOS::HiviewDFX::HiLog::Warn(LOG_LABEL, __VA_ARGS__) +#define WLOG_I(...) (void)OHOS::HiviewDFX::HiLog::Info(LOG_LABEL, __VA_ARGS__) +#define WLOG_D(...) (void)OHOS::HiviewDFX::HiLog::Debug(LOG_LABEL, __VA_ARGS__) + +#define _W_DFUNC HiviewDFX::HiLog::Debug +#define _W_IFUNC HiviewDFX::HiLog::Info +#define _W_WFUNC HiviewDFX::HiLog::Warn +#define _W_EFUNC HiviewDFX::HiLog::Error + +#define _W_CPRINTF(func, fmt, ...) func(LABEL, "<%{public}d>" fmt, __LINE__, ##__VA_ARGS__) + +#define WLOGD(fmt, ...) _W_CPRINTF(_W_DFUNC, fmt, ##__VA_ARGS__) +#define WLOGI(fmt, ...) _W_CPRINTF(_W_IFUNC, fmt, ##__VA_ARGS__) +#define WLOGW(fmt, ...) _W_CPRINTF(_W_WFUNC, fmt, ##__VA_ARGS__) +#define WLOGE(fmt, ...) _W_CPRINTF(_W_EFUNC, fmt, ##__VA_ARGS__) + +#define _W_FUNC __func__ + +#define WLOGFD(fmt, ...) WLOGD("%{public}s: " fmt, _W_FUNC, ##__VA_ARGS__) +#define WLOGFI(fmt, ...) WLOGI("%{public}s: " fmt, _W_FUNC, ##__VA_ARGS__) +#define WLOGFW(fmt, ...) WLOGW("%{public}s: " fmt, _W_FUNC, ##__VA_ARGS__) +#define WLOGFE(fmt, ...) WLOGE("%{public}s: " fmt, _W_FUNC, ##__VA_ARGS__) +} // namespace OHOS +} +#endif // FRAMEWORKS_WM_INCLUDE_WINDOW_MANAGER_HILOG_H diff --git a/utils/src/singleton_container.cpp b/utils/src/singleton_container.cpp new file mode 100644 index 0000000000..0b851fdae2 --- /dev/null +++ b/utils/src/singleton_container.cpp @@ -0,0 +1,110 @@ +/* + * 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 "singleton_container.h" +#include +#include "window_manager_hilog.h" + +namespace OHOS { +namespace Rosen { +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) { + auto it = singletonMap.begin(); + while (it != singletonMap.end()) { + if (it->second.refCount > 0) { + it++; + continue; + } + + if (dependencySetMap.find(it->first) != dependencySetMap.end()) { + for (auto mid : dependencySetMap[it->first]) { + singletonMap[mid].refCount--; + } + dependencySetMap.erase(it->first); + } + + for (const auto &[k, v] : stringMap) { + if (v == it->first) { + WLOGFD("remove %{public}s", k.c_str()); + break; + } + } + singletonMap.erase(it++); + } + } +} + +void SingletonContainer::AddSingleton(const std::string &name, const std::any &instance) +{ + if (stringMap.find(name) == stringMap.end()) { + static int32_t nextId = 0; + singletonMap[nextId].value = instance; + singletonMap[nextId].refCount = 0; + WLOGFD("add %{public}s", name.c_str()); + stringMap[name] = nextId++; + } else { + WLOGFE("add failed: %{public}s", name.c_str()); + } +} + +void SingletonContainer::SetSingleton(const std::string &name, const std::any &instance) +{ + if (stringMap.find(name) == stringMap.end()) { + AddSingleton(name, instance); + } else { + WLOGFD("set %{public}s", name.c_str()); + singletonMap[stringMap[name]].value = instance; + } +} + +const std::any &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 singletonMap[stringMap[name]].value; +} + +const std::any &SingletonContainer::DependOn(const std::string &instance, const std::string &name) +{ + auto &instanceDependencySet = dependencySetMap[stringMap[instance]]; + if (instanceDependencySet.find(stringMap[name]) == instanceDependencySet.end()) { + WLOGFD("%{public}s dependon %{public}s", instance.c_str(), name.c_str()); + instanceDependencySet.insert(stringMap[name]); + singletonMap[stringMap[name]].refCount++; + } + return GetSingleton(name); +} +} // namespace Rosen +} // namespace OHOS diff --git a/utils/src/static_call.cpp b/utils/src/static_call.cpp new file mode 100644 index 0000000000..5b8797a3b1 --- /dev/null +++ b/utils/src/static_call.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 "static_call.h" + +namespace OHOS { +namespace Rosen { +IMPLEMENT_SINGLE_INSTANCE(StaticCall); + +sptr StaticCall::CreateWindow(const std::string& windowName, + sptr& option, const sptr& abilityToken) +{ + return Window::Create(windowName, option, abilityToken); +} +} // namespace Rosen +} // namespace OHOS \ No newline at end of file diff --git a/wm/BUILD.gn b/wm/BUILD.gn new file mode 100644 index 0000000000..a517968506 --- /dev/null +++ b/wm/BUILD.gn @@ -0,0 +1,161 @@ +# 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("//build/ohos.gni") + +config("libwm_config") { + visibility = [ ":*" ] + + include_dirs = [ + "include", + "//utils/system/safwk/native/include", + "//foundation/windowmanager/wmserver/include", + "//foundation/windowmanager/dm/include", + "//foundation/windowmanager/dmserver/include", + "//foundation/windowmanager/utils/include", + + # 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", + "//third_party/node/deps/icu-small/source/common", + "//foundation/aafwk/standard/interfaces/innerkits/ability_manager/include", + "//foundation/aafwk/standard/interfaces/innerkits/want/include/ohos/aafwk/content", + "//foundation/distributedschedule/dmsfwk/services/dtbschedmgr/include", + "//foundation/aafwk/standard/interfaces/innerkits/base/include", + + # abilityContext end + + # weston adapter + "//foundation/windowmanager/adapter/include", + "//foundation/graphic/standard/interfaces/innerkits", + "//foundation/graphic/standard/interfaces/innerkits/wm", + "//foundation/graphic/standard/interfaces/innerkits/common", + + # weston adapter end + ] + + cflags = [ + "-Wall", + "-Werror", + "-g3", + ] +} + +config("libwm_public_config") { + include_dirs = [ + "//foundation/windowmanager/interfaces/innerkits/wm", + "//foundation/windowmanager/wmserver/include", + "//foundation/windowmanager/dmserver/include", + "//foundation/windowmanager/utils/include", + "../interfaces/innerkits/dm", + ] +} + +## Build libwmutil.so +ohos_shared_library("libwmutil") { + sources = [ + "../dmserver/src/display_info.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", + ] + + configs = [ ":libwm_config" ] + + public_configs = [ ":libwm_public_config" ] + + deps = [ + "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog", + "//utils/native/base:utils", + ] + + public_deps = [ + # 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 = [ "ipc:ipc_core" ] + + part_name = "window_manager" + subsystem_name = "window" +} + +## Build libwm.so +ohos_shared_library("libwm") { + sources = [ + "../dm/src/display.cpp", + "../dm/src/display_manager.cpp", + "../dm/src/display_manager_adapter.cpp", + "../dm/src/monitor.cpp", + "../utils/src/static_call.cpp", + "src/input_transfer_station.cpp", + "src/vsync_station.cpp", + "src/window.cpp", + "src/window_adapter.cpp", + "src/window_agent.cpp", + "src/window_impl.cpp", + "src/window_input_channel.cpp", + "src/window_scene.cpp", + "src/window_stub.cpp", + ] + + configs = [ ":libwm_config" ] + + public_configs = [ ":libwm_public_config" ] + + 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", + + # weston adapter + "//foundation/windowmanager/adapter:libwmadaptertest", + + # ace + "//foundation/ace/ace_engine/interfaces/innerkits/ace:ace_uicontent", + ] + + public_deps = [ + # native value + # RSSurface + "//foundation/ace/napi:ace_napi", + + # vsync + "//foundation/graphic/standard:libvsync_client", + "//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", + "//foundation/multimodalinput/input/frameworks/proxy:libmmi-common", + + # weston adapter + "//foundation/windowmanager/adapter:libwmadaptertest", + ] + + external_deps = [ + "aafwk_standard:ability_context_native", + "ipc:ipc_core", + ] + + part_name = "window_manager" + subsystem_name = "window" +} diff --git a/wm/include/README.md b/wm/include/README.md new file mode 100644 index 0000000000..f0321dc5d0 --- /dev/null +++ b/wm/include/README.md @@ -0,0 +1 @@ +Store code of window client inner header files diff --git a/wm/include/input_transfer_station.h b/wm/include/input_transfer_station.h new file mode 100644 index 0000000000..5c8fa1466f --- /dev/null +++ b/wm/include/input_transfer_station.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_INPUT_TRANSFER_STATION +#define OHOS_INPUT_TRANSFER_STATION + + +#include +#include +#include "input_manager.h" +#include "pointer_event.h" +#include "window.h" +#include "window_input_channel.h" +#include "vsync_station.h" + +namespace OHOS { +namespace Rosen { +class InputEventListener; +class InputTransferStation : public RefBase { +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_; +}; +class InputEventListener: public RefBase, public MMI::IInputEventConsumer { +public: + InputEventListener() = default; + void OnInputEvent(std::shared_ptr pointerEvent) const override; + void OnInputEvent(std::shared_ptr keyEvent) const override; + void OnInputEvent(std::shared_ptr axisEvent) const override; +}; +} +} + + +#endif // OHOS_INPUT_TRANSFER_STATION diff --git a/wm/include/vsync_station.h b/wm/include/vsync_station.h new file mode 100644 index 0000000000..eba3a26caf --- /dev/null +++ b/wm/include/vsync_station.h @@ -0,0 +1,59 @@ +/* + * 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_VSYNC_STATION_H +#define OHOS_VSYNC_STATION_H + +#include +#include +#include +#include +#include + +#include +#include + +#include "single_instance.h" + +namespace OHOS { +namespace Rosen { +class VsyncStation : public RefBase { +DECLARE_SINGLE_INSTANCE_BASE(VsyncStation); +using OnCallback = std::function; +public: + enum class CallbackType { + CALLBACK_INPUT = 0, + CALLBACK_FRAME = 1, + }; + struct VsyncCallback { + OnCallback onCallback; + }; + ~VsyncStation() = default; + void RequestVsync(CallbackType type, std::shared_ptr vsyncCallback); + +private: + FrameCallback callback_; + VsyncStation() = default; + static void OnVsync(int64_t nanoTimestamp, void* client); + void VsyncCallbackInner(int64_t nanoTimestamp); + std::atomic_bool hasRequestedVsync_ {false}; + std::map>> vsyncCallbacks_ = { + {CallbackType::CALLBACK_INPUT, {}}, + {CallbackType::CALLBACK_FRAME, {}}, + }; +}; +} // namespace Rosen +} // namespace OHOS +#endif // OHOS_VSYNC_STATION_H \ No newline at end of file diff --git a/wm/include/window_adapter.h b/wm/include/window_adapter.h new file mode 100644 index 0000000000..49ca563360 --- /dev/null +++ b/wm/include/window_adapter.h @@ -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. + */ + +#ifndef OHOS_WINDOW_ADAPTER_H +#define OHOS_WINDOW_ADAPTER_H + +#include + +#include "window.h" +#include "window_proxy.h" +#include "single_instance.h" +#include "singleton_delegator.h" +#include "window_property.h" +#include "window_manager_interface.h" +namespace OHOS { +namespace Rosen { +class WMSDeathRecipient : public IRemoteObject::DeathRecipient { +public: + virtual void OnRemoteDied(const wptr& wptrDeath) override; +}; + +class WindowAdapter : public RefBase { + DECLARE_SINGLE_INSTANCE_BASE(WindowAdapter); +public: + ~WindowAdapter() = default; + virtual WMError CreateWindow(sptr& window, sptr& windowProperty, + std::shared_ptr surfaceNode, uint32_t& windowId); + virtual WMError AddWindow(sptr& windowProperty); + virtual WMError RemoveWindow(uint32_t windowId); + virtual WMError DestroyWindow(uint32_t windowId); + virtual WMError SaveAbilityToken(const sptr& abilityToken, uint32_t windowId); + 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 void ClearWindowAdapter(); +protected: + WindowAdapter() = default; +private: + static inline SingletonDelegator delegator; + bool InitWMSProxyLocked(); + + std::mutex mutex_; + sptr windowManagerServiceProxy_ = nullptr; + sptr wmsDeath_ = nullptr; +}; +} // namespace Rosen +} // namespace OHOS +#endif // OHOS_WINDOW_ADAPTER_H diff --git a/wm/include/window_agent.h b/wm/include/window_agent.h new file mode 100644 index 0000000000..31bd1ccd4b --- /dev/null +++ b/wm/include/window_agent.h @@ -0,0 +1,39 @@ +/* + * 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_AGENT_H +#define OHOS_WINDOW_AGENT_H + +#include "window_stub.h" +#include "window_impl.h" +#include "window_property.h" + +namespace OHOS { +namespace Rosen { +class WindowAgent : public WindowStub { +public: + WindowAgent(sptr& window); + ~WindowAgent() = default; + void UpdateWindowProperty(const WindowProperty& windowProperty) override; + void UpdateWindowRect(const struct Rect& rect) override; + void UpdateWindowMode(WindowMode mode) override; + void UpdateFocusStatus(bool focused) override; + +private: + sptr window_; +}; +} // namespace Rosen +} // namespace OHOS +#endif // OHOS_WINDOW_AGENT_H diff --git a/wm/include/window_impl.h b/wm/include/window_impl.h new file mode 100644 index 0000000000..17766e3f10 --- /dev/null +++ b/wm/include/window_impl.h @@ -0,0 +1,122 @@ +/* + * 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_IMPL_H +#define OHOS_ROSEN_WINDOW_IMPL_H +#include +#include +#include +#include +#include "window.h" +#include "input_transfer_station.h" +#include "window_property.h" + +namespace OHOS { +namespace Rosen { +class WindowImpl : public Window { +#define CALL_LIFECYCLE_LISTENER(windowLifecycleCb, uiContentCb) \ + do { \ + if (lifecycleListener_ != nullptr) { \ + lifecycleListener_->windowLifecycleCb(); \ + } \ + if (uiContent_ != nullptr) { \ + uiContent_->uiContentCb(); \ + } \ + } while (0); + +public: + WindowImpl(const sptr& option); + ~WindowImpl(); + + static sptr Find(const std::string& id); + + virtual std::shared_ptr GetSurfaceNode() const override; + virtual Rect GetRect() const override; + virtual WindowType GetType() const override; + virtual WindowMode GetMode() const override; + virtual const std::string& GetWindowName() const override; + virtual uint32_t GetWindowId() override; + virtual WMError SetWindowType(WindowType type) override; + virtual WMError SetWindowMode(WindowMode mode) override; + + WMError Create(const std::string& parentName, const sptr& abilityToken = nullptr); + virtual WMError Destroy() override; + virtual WMError Show() override; + virtual WMError Hide() override; + virtual WMError MoveTo(int32_t x, int32_t y) override; + virtual WMError Resize(uint32_t width, uint32_t height) override; + + virtual WMError RequestFocus() const override; + virtual void AddInputEventListener(std::shared_ptr& inputEventListener) override; + + virtual void RegisterLifeCycleListener(sptr& listener) override; + virtual void RegisterWindowChangeListener(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; + void UpdateFocusStatus(bool focused); + + virtual WMError SetUIContent(std::shared_ptr context, + std::string& url, NativeEngine* engine, NativeValue* storage) override; + +private: + inline void NotifyAfterForeground() const + { + CALL_LIFECYCLE_LISTENER(AfterForeground, Foreground); + } + inline void NotifyAfterBackground() const + { + CALL_LIFECYCLE_LISTENER(AfterBackground, Background); + } + inline void NotifyAfterFocused() const + { + CALL_LIFECYCLE_LISTENER(AfterFocused, Focus); + } + inline void NotifyAfterUnFocused() const + { + CALL_LIFECYCLE_LISTENER(AfterUnFocused, UnFocus); + } + inline void NotifyBeforeDestroy() const + { + if (uiContent_ != nullptr) { + uiContent_->Destroy(); + } + } + void SetDefaultOption(); // for api7 + bool IsWindowValid() const; + + enum WindowState { + STATE_INITIAL, + STATE_CREATED, + STATE_SHOWN, + STATE_HIDDEN, + STATE_DESTROYED, + STATE_BOTTOM = STATE_DESTROYED, + }; + + static std::map>> windowMap_; + sptr property_; + WindowState state_ { STATE_INITIAL }; + sptr lifecycleListener_; + sptr windowChangeListener_; + std::shared_ptr surfaceNode_; + std::string name_; + std::unique_ptr uiContent_; +}; +} +} +#endif // OHOS_ROSEN_WINDOW_IMPL_H diff --git a/wm/include/window_input_channel.h b/wm/include/window_input_channel.h new file mode 100644 index 0000000000..fb700a1d54 --- /dev/null +++ b/wm/include/window_input_channel.h @@ -0,0 +1,44 @@ +/* + * 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 +#include "refbase.h" +#include "vsync_station.h" +#ifndef OHOS_WINDOW_INPUT_CHANNEL +#define OHOS_WINDOW_INPUT_CHANNEL + +namespace OHOS { +namespace Rosen { +class WindowInputChannel : public RefBase { +public: + WindowInputChannel(const sptr& window); + ~WindowInputChannel() = default; + void HandlePointerEvent(std::shared_ptr& pointerEvent); + void HandleKeyEvent(std::shared_ptr& keyEvent); + void SetInputListener(std::shared_ptr& listener); +private: + void OnVsync(int64_t timeStamp); + std::vector> pointerEventPool_; + sptr window_; + std::shared_ptr callback_ = + std::make_shared(VsyncStation::VsyncCallback()); + static const int32_t MAX_INPUT_NUM = 100; + std::shared_ptr inputListener_; +}; +} +} + + +#endif // OHOS_WINDOW_INPUT_CHANNEL diff --git a/wm/include/window_interface.h b/wm/include/window_interface.h new file mode 100644 index 0000000000..846ded8652 --- /dev/null +++ b/wm/include/window_interface.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_WINDOW_INTERFACE_H +#define OHOS_WINDOW_INTERFACE_H + +#include "iremote_broker.h" +#include "window_property.h" + +namespace OHOS { +namespace Rosen { +class IWindow : public IRemoteBroker { +public: + DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.IWindow"); + + enum { + TRANS_ID_UPDATE_WINDOW_PROPERTY = 1, + TRANS_ID_UPDATE_WINDOW_RECT, + TRANS_ID_UPDATE_WINDOW_MODE, + TRANS_ID_UPDATE_FOCUS_STATUS, + }; + + 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; +}; +} // namespace Rosen +} // namespace OHOS +#endif // OHOS_WINDOW_INTERFACE_H diff --git a/wm/include/window_property.h b/wm/include/window_property.h new file mode 100644 index 0000000000..f8b9ed4ca0 --- /dev/null +++ b/wm/include/window_property.h @@ -0,0 +1,79 @@ +/* + * 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_PROPERTY_H +#define OHOS_ROSEN_WINDOW_PROPERTY_H + +#include +#include +#include "parcel.h" +#include "wm_common.h" + +namespace OHOS { +namespace Rosen { +class WindowProperty : public Parcelable { +public: + WindowProperty() = default; + ~WindowProperty() = default; + + void SetWindowRect(const struct Rect& rect); + void SetWindowType(WindowType type); + void SetWindowMode(WindowMode mode); + void SetFullScreen(bool isFullScreen); + void SetFocusable(bool isFocusable); + void SetTouchable(bool isTouchable); + void SetPrivacyMode(bool isPrivate); + void SetTransparent(bool isTransparent); + void SetAlpha(float alpha); + void SetDisplayId(int32_t displayId); + void SetWindowId(uint32_t windowId); + void SetParentId(uint32_t parentId); + void SetWindowFlags(uint32_t flags); + + Rect GetWindowRect() const; + WindowType GetWindowType() const; + WindowMode GetWindowMode() const; + bool GetFullScreen() const; + bool GetFocusable() const; + bool GetTouchable() const; + bool GetPrivacyMode() const; + bool GetTransparent() const; + float GetAlpha() const; + int32_t GetDisplayId() const; + uint32_t GetWindowId() const; + uint32_t GetParentId() const; + uint32_t GetWindowFlags() 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 }; + WindowMode mode_ { WindowMode::WINDOW_MODE_FULLSCREEN }; + uint32_t flags_ { 0 }; + bool isFullScreen_ { true }; + bool focusable_ { true }; + bool touchable_ { true }; + bool isPrivacyMode_ { false }; + bool isTransparent_ { false }; + float alpha_ { 1.0f }; + int32_t displayId_ { 0 }; + uint32_t windowId_ { 0 }; + uint32_t parentId_ { 0 }; +}; +} +} +#endif // OHOS_ROSEN_WINDOW_PROPERTY_H diff --git a/wm/include/window_proxy.h b/wm/include/window_proxy.h new file mode 100644 index 0000000000..8e1ea4a52e --- /dev/null +++ b/wm/include/window_proxy.h @@ -0,0 +1,40 @@ +/* + * 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_PROXY_H +#define OHOS_WINDOW_PROXY_H + +#include "window_interface.h" +#include "iremote_proxy.h" + +namespace OHOS { +namespace Rosen { +class WindowProxy : public IRemoteProxy { +public: + explicit WindowProxy(const sptr& impl) : IRemoteProxy(impl) {}; + + ~WindowProxy() {}; + + void UpdateWindowProperty(const WindowProperty& windowProperty) override; + void UpdateWindowRect(const struct Rect& rect) override; + void UpdateWindowMode(WindowMode mode) override; + void UpdateFocusStatus(bool focused) override; + +private: + static inline BrokerDelegator delegator_; +}; +} // namespace Rosen +} // namespace OHOS +#endif // OHOS_WINDOW_PROXY_H diff --git a/wm/include/window_stub.h b/wm/include/window_stub.h new file mode 100644 index 0000000000..efc29d3b50 --- /dev/null +++ b/wm/include/window_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_STUB_H +#define OHOS_WINDOW_STUB_H + +#include "window_interface.h" +#include "iremote_stub.h" + +namespace OHOS { +namespace Rosen { +class WindowStub : public IRemoteStub { +public: + WindowStub() = default; + ~WindowStub() = default; + + virtual int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, + MessageOption &option) override; +}; +} // namespace Rosen +} // namespace OHOS +#endif // OHOS_WINDOW_STUB_H diff --git a/wm/src/README.md b/wm/src/README.md new file mode 100644 index 0000000000..2a99b4a2c9 --- /dev/null +++ b/wm/src/README.md @@ -0,0 +1 @@ +Store code of window client source files diff --git a/wm/src/input_transfer_station.cpp b/wm/src/input_transfer_station.cpp new file mode 100644 index 0000000000..43adc731bc --- /dev/null +++ b/wm/src/input_transfer_station.cpp @@ -0,0 +1,114 @@ +/* + * 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 "input_transfer_station.h" +#include + +namespace OHOS { +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"); + if (keyEvent == nullptr) { + WLOGE("OnInputEvent receive KeyEvent is nullptr"); + return; + } + uint32_t windowId = keyEvent->GetAgentWindowId(); + auto channel = InputTransferStation::GetInstance()->GetInputChannel(windowId); + if (channel == nullptr) { + WLOGE("OnInputEvent channel is nullptr"); + return; + } + channel->HandleKeyEvent(keyEvent); +} + +void InputEventListener::OnInputEvent(std::shared_ptr axisEvent) const +{ + WLOGFI("OnInputEvent: receive axisEvent"); + if (axisEvent == nullptr) { + WLOGE("OnInputEvent receive axisEvent is nullptr"); + return; + } + axisEvent->MarkProcessed(); +} + +void InputEventListener::OnInputEvent(std::shared_ptr pointerEvent) const +{ + WLOGFI("OnInputEvent: receive pointerEvent"); + if (pointerEvent == nullptr) { + WLOGE("OnInputEvent receive pointerEvent is nullptr"); + return; + } + uint32_t windowId = pointerEvent->GetAgentWindowId(); + auto channel = InputTransferStation::GetInstance()->GetInputChannel(windowId); + if (channel == nullptr) { + WLOGE("OnInputEvent channel is nullptr"); + return; + } + channel->HandlePointerEvent(pointerEvent); +} + +void InputTransferStation::AddInputWindow(const sptr& window) +{ + WLOGFI("AddInputWindow: add window"); + uint32_t windowId = window->GetWindowId(); + sptr inputChannel = new WindowInputChannel(window); + windowInputChannels_.insert(std::make_pair(windowId, inputChannel)); + if (!initInputListener_) { + WLOGFI("init input listener"); + std::shared_ptr listener = std::make_shared(InputEventListener()); + MMI::InputManager::GetInstance()->SetWindowInputEventConsumer(listener); + inputListener_ = listener; + initInputListener_ = true; + } +} + +void InputTransferStation::RemoveInputWindow(const sptr& window) +{ + WLOGFI("RemoveInputWindow: remove window"); + uint32_t windowId = window->GetWindowId(); + auto iter = windowInputChannels_.find(windowId); + if (iter != windowInputChannels_.end()) { + windowInputChannels_.erase(windowId); + } else { + WLOGE("RemoveInputWindow do not find windowId: %{public}d", windowId); + } +} + +void InputTransferStation::SetInputListener(uint32_t windowId, std::shared_ptr &listener) +{ + auto channel = GetInputChannel(windowId); + if (channel == nullptr) { + WLOGE("SetInputListener channel is nullptr"); + return; + } + channel->SetInputListener(listener); +} + +sptr InputTransferStation::GetInputChannel(uint32_t windowId) +{ + auto iter = windowInputChannels_.find(windowId); + if (iter == windowInputChannels_.end()) { + WLOGE("GetInputChannel do not find channel according to windowId: %{public}d", windowId); + return nullptr; + } + return iter->second; +} +} +} diff --git a/wm/src/vsync_station.cpp b/wm/src/vsync_station.cpp new file mode 100644 index 0000000000..4cc4439827 --- /dev/null +++ b/wm/src/vsync_station.cpp @@ -0,0 +1,69 @@ +/* + * 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 + +#include "window_manager_hilog.h" + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "VsyncStation"}; +} + +IMPLEMENT_SINGLE_INSTANCE(VsyncStation); + +void VsyncStation::RequestVsync(CallbackType type, std::shared_ptr vsyncCallback) +{ + 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()); + } + } +} + +void VsyncStation::VsyncCallbackInner(int64_t timestamp) +{ + for (auto& vsyncCallbacksSet: vsyncCallbacks_) { + for (const auto& callback: vsyncCallbacksSet.second) { + callback->onCallback(timestamp); + } + vsyncCallbacksSet.second.clear(); + } + hasRequestedVsync_.store(false); +} + +void VsyncStation::OnVsync(int64_t timestamp, void* client) +{ + auto vsyncClient = static_cast(client); + if (vsyncClient) { + vsyncClient->VsyncCallbackInner(timestamp); + } else { + WLOGFE("VsyncStation::OnVsync vsyncClient is null"); + } +} +} +} \ No newline at end of file diff --git a/wm/src/window.cpp b/wm/src/window.cpp new file mode 100644 index 0000000000..e1ac8e3139 --- /dev/null +++ b/wm/src/window.cpp @@ -0,0 +1,49 @@ +/* + * 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.h" +#include "window_impl.h" +#include "window_manager_hilog.h" + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowImpl"}; +} +sptr Window::Create(const std::string& windowName, sptr& option, + const sptr& abilityToken) +{ + if (windowName.empty()) { + WLOGFE("window name is empty"); + return nullptr; + } + if (option == nullptr) { + option = new WindowOption(); + } + option->SetWindowName(windowName); + sptr windowImpl = new WindowImpl(option); + WMError error = windowImpl->Create(option->GetParentName(), abilityToken); + if (error != WMError::WM_OK) { + return nullptr; + } + return windowImpl; +} + +sptr Window::Find(const std::string& windowName) +{ + return WindowImpl::Find(windowName); +} +} +} diff --git a/wm/src/window_adapter.cpp b/wm/src/window_adapter.cpp new file mode 100644 index 0000000000..81b169617e --- /dev/null +++ b/wm/src/window_adapter.cpp @@ -0,0 +1,171 @@ +/* + * 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_adapter.h" +#include +#include +#include "window_manager_hilog.h" +#include "wm_common.h" + +namespace OHOS { +namespace Rosen { +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_); + + if (!InitWMSProxyLocked()) { + return WMError::WM_ERROR_SAMGR; + } + return windowManagerServiceProxy_->SaveAbilityToken(abilityToken, windowId); +} + +WMError WindowAdapter::CreateWindow(sptr& window, sptr& windowProperty, + std::shared_ptr surfaceNode, uint32_t& windowId) +{ + std::lock_guard lock(mutex_); + + if (!InitWMSProxyLocked()) { + return WMError::WM_ERROR_SAMGR; + } + return windowManagerServiceProxy_->CreateWindow(window, windowProperty, surfaceNode, windowId); +} + +WMError WindowAdapter::AddWindow(sptr& windowProperty) +{ + std::lock_guard lock(mutex_); + + if (!InitWMSProxyLocked()) { + return WMError::WM_ERROR_SAMGR; + } + return windowManagerServiceProxy_->AddWindow(windowProperty); +} + +WMError WindowAdapter::RemoveWindow(uint32_t windowId) +{ + std::lock_guard lock(mutex_); + + if (!InitWMSProxyLocked()) { + return WMError::WM_ERROR_SAMGR; + } + return windowManagerServiceProxy_->RemoveWindow(windowId); +} + +WMError WindowAdapter::DestroyWindow(uint32_t windowId) +{ + std::lock_guard lock(mutex_); + + if (!InitWMSProxyLocked()) { + return WMError::WM_ERROR_SAMGR; + } + return windowManagerServiceProxy_->DestroyWindow(windowId); +} + +WMError WindowAdapter::MoveTo(uint32_t windowId, int32_t x, int32_t y) +{ + std::lock_guard lock(mutex_); + + if (!InitWMSProxyLocked()) { + return WMError::WM_ERROR_SAMGR; + } + return windowManagerServiceProxy_->MoveTo(windowId, x, y); +} + +WMError WindowAdapter::Resize(uint32_t windowId, uint32_t width, uint32_t height) +{ + std::lock_guard lock(mutex_); + + if (!InitWMSProxyLocked()) { + return WMError::WM_ERROR_SAMGR; + } + return windowManagerServiceProxy_->Resize(windowId, width, height); +} + +WMError WindowAdapter::RequestFocus(uint32_t windowId) +{ + std::lock_guard lock(mutex_); + + if (!InitWMSProxyLocked()) { + return WMError::WM_ERROR_SAMGR; + } + return windowManagerServiceProxy_->RequestFocus(windowId); +} + +bool WindowAdapter::InitWMSProxyLocked() +{ + if (!windowManagerServiceProxy_) { + sptr systemAbilityManager = + SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (!systemAbilityManager) { + WLOGFE("Failed to get system ability mgr."); + return false; + } + + sptr remoteObject = systemAbilityManager->GetSystemAbility(WINDOW_MANAGER_SERVICE_ID); + if (!remoteObject) { + WLOGFE("Failed to get window manager service."); + return false; + } + + windowManagerServiceProxy_ = iface_cast(remoteObject); + if ((!windowManagerServiceProxy_) || (!windowManagerServiceProxy_->AsObject())) { + WLOGFE("Failed to get system window manager services"); + return false; + } + + wmsDeath_ = new WMSDeathRecipient(); + if (!wmsDeath_) { + WLOGFE("Failed to create death Recipient ptr WMSDeathRecipient"); + return false; + } + if (!remoteObject->AddDeathRecipient(wmsDeath_)) { + WLOGFE("Failed to add death recipient"); + return false; + } + } + return true; +} + +void WindowAdapter::ClearWindowAdapter() +{ + std::lock_guard lock(mutex_); + if ((windowManagerServiceProxy_ != nullptr) && (windowManagerServiceProxy_->AsObject() != nullptr)) { + windowManagerServiceProxy_->AsObject()->RemoveDeathRecipient(wmsDeath_); + } + windowManagerServiceProxy_ = nullptr; +} + +void WMSDeathRecipient::OnRemoteDied(const wptr& wptrDeath) +{ + if (wptrDeath == nullptr) { + WLOGFE("wptrDeath is null"); + return; + } + + sptr object = wptrDeath.promote(); + if (!object) { + WLOGFE("object is null"); + return; + } + SingletonContainer::Get()->ClearWindowAdapter(); + return; +} +} // namespace Rosen +} // namespace OHOS \ No newline at end of file diff --git a/wm/src/window_agent.cpp b/wm/src/window_agent.cpp new file mode 100644 index 0000000000..79f7a28536 --- /dev/null +++ b/wm/src/window_agent.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 "window_agent.h" +#include "window_manager_hilog.h" + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowAgent"}; +} + +WindowAgent::WindowAgent(sptr& windowImpl) +{ + window_ = windowImpl; +} + +void WindowAgent::UpdateWindowProperty(const WindowProperty& windowProperty) +{ +} + +void WindowAgent::UpdateWindowRect(const struct Rect& rect) +{ + if (window_ == nullptr) { + WLOGFE("window_ is nullptr"); + return; + } + window_->UpdateRect(rect); +} + +void WindowAgent::UpdateWindowMode(WindowMode mode) +{ + if (window_ == nullptr) { + WLOGFE("window_ is nullptr"); + return; + } + window_->UpdateMode(mode); +} + +void WindowAgent::UpdateFocusStatus(bool focused) +{ + if (window_ == nullptr) { + WLOGFE("window_ is nullptr"); + return; + } + window_->UpdateFocusStatus(focused); +} +} // namespace Rosen +} // namespace OHOS diff --git a/wm/src/window_impl.cpp b/wm/src/window_impl.cpp new file mode 100644 index 0000000000..6f5d980a75 --- /dev/null +++ b/wm/src/window_impl.cpp @@ -0,0 +1,428 @@ +/* + * 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_impl.h" +#include "display_manager.h" +#include "singleton_container.h" +#include "window_adapter.h" +#include "window_agent.h" +#include "window_manager_hilog.h" +#ifndef _NEW_RENDERSERVER_ +#include "adapter.h" +#endif + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowImpl"}; +} + +std::map>> WindowImpl::windowMap_; + +WindowImpl::WindowImpl(const sptr& option) +{ + property_ = new WindowProperty(); + property_->SetWindowRect(option->GetWindowRect()); + property_->SetWindowType(option->GetWindowType()); + property_->SetWindowMode(option->GetWindowMode()); + property_->SetFullScreen(option->GetWindowMode() == WindowMode::WINDOW_MODE_FULLSCREEN); + property_->SetFocusable(option->GetFocusable()); + property_->SetTouchable(option->GetTouchable()); + property_->SetDisplayId(option->GetDisplayId()); + property_->SetWindowFlags(option->GetWindowFlags()); + name_ = option->GetWindowName(); + +#ifdef _NEW_RENDERSERVER_ + struct RSSurfaceNodeConfig rsSurfaceNodeConfig; + surfaceNode_ = RSSurfaceNode::Create(rsSurfaceNodeConfig); +#endif +} + +WindowImpl::~WindowImpl() +{ + Destroy(); +} + +sptr WindowImpl::Find(const std::string& name) +{ + auto iter = windowMap_.find(name); + if (iter == windowMap_.end()) { + return nullptr; + } + return iter->second.second; +} + +std::shared_ptr WindowImpl::GetSurfaceNode() const +{ + return surfaceNode_; +} + +Rect WindowImpl::GetRect() const +{ + return property_->GetWindowRect(); +} + +WindowType WindowImpl::GetType() const +{ + return property_->GetWindowType(); +} + +WindowMode WindowImpl::GetMode() const +{ + return property_->GetWindowMode(); +} + +const std::string& WindowImpl::GetWindowName() const +{ + return name_; +} + +uint32_t WindowImpl::GetWindowId() +{ + return property_->GetWindowId(); +} + +WMError WindowImpl::SetWindowType(WindowType 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) { + property_->SetWindowType(type); + return WMError::WM_OK; + } + if (property_->GetWindowType() != type) { + return WMError::WM_ERROR_INVALID_PARAM; + } + return WMError::WM_OK; +} + +WMError WindowImpl::SetWindowMode(WindowMode mode) +{ + 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 || state_ == STATE_HIDDEN) { + property_->SetWindowMode(mode); + return WMError::WM_OK; + } + if (property_->GetWindowMode() != mode) { + // TODO + } + return WMError::WM_OK; +} + +WMError WindowImpl::SetUIContent(std::shared_ptr context, + std::string& url, NativeEngine* engine, NativeValue* storage) +{ + WLOGFI("SetUIContent"); + uiContent_ = Ace::UIContent::Create(context.get(), engine); + if (uiContent_ == nullptr) { + WLOGFE("fail to SetUIContent id: %{public}d", property_->GetWindowId()); + return WMError::WM_ERROR_NULLPTR; + } + uiContent_->Initialize(this, url, storage); + return WMError::WM_OK; +} + +WMError WindowImpl::Create(const std::string& parentName, const sptr& abilityToken) +{ +#ifdef _NEW_RENDERSERVER_ + // check window name, same window names are forbidden + if (windowMap_.find(name_) != windowMap_.end()) { + WLOGFE("WindowName(%{public}s) already exists.", name_.c_str()); + return WMError::WM_ERROR_INVALID_PARAM; + } + // check parent name, if create sub window and there is not exist parent Window, then return + if (parentName != "") { + if (windowMap_.find(parentName) == windowMap_.end()) { + WLOGFE("ParentName is empty or valid. ParentName is %{public}s", parentName.c_str()); + return WMError::WM_ERROR_INVALID_PARAM; + } else { + uint32_t parentId = windowMap_[parentName].first; + property_->SetParentId(parentId); + } + } + + sptr window(this); + sptr windowAgent(new WindowAgent(window)); + uint32_t windowId = 0; + WMError ret = SingletonContainer::Get()->CreateWindow(windowAgent, property_, surfaceNode_, + windowId); + property_->SetWindowId(windowId); + + if (ret != WMError::WM_OK) { + WLOGFE("create window failed with errCode:%{public}d", static_cast(ret)); + return ret; + } + if (abilityToken != nullptr) { + ret = SingletonContainer::Get()->SaveAbilityToken(abilityToken, windowId); + if (ret != WMError::WM_OK) { + WLOGFE("SaveAbilityToken failed with errCode:%{public}d", static_cast(ret)); + return ret; + } + } + windowMap_.insert({ name_, std::pair>(windowId, this) }); + state_ = STATE_CREATED; + WLOGFI("create window success with winId:%{public}d", windowId); + InputTransferStation::GetInstance()->AddInputWindow(this); + return ret; +#else + /* weston adapter */ + return WMError::WM_OK; +#endif +} + +WMError WindowImpl::Destroy() +{ + NotifyBeforeDestroy(); +#ifdef _NEW_RENDERSERVER_ + // 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()); + windowMap_.erase(GetWindowName()); + state_ = STATE_DESTROYED; + InputTransferStation::GetInstance()->RemoveInputWindow(this); + return ret; +#else + InputTransferStation::GetInstance()->RemoveInputWindow(this); + Adapter::DestroyWestonWindow(); +#endif + return WMError::WM_OK; +} + +WMError WindowImpl::Show() +{ +#ifdef _NEW_RENDERSERVER_ + if (!IsWindowValid()) { + WLOGFI("window is already destroyed or not created! id: %{public}d", property_->GetWindowId()); + return WMError::WM_ERROR_INVALID_WINDOW; + } + if (state_ == STATE_SHOWN) { + WLOGFI("window is already shown id: %{public}d", property_->GetWindowId()); + return WMError::WM_OK; + } + SetDefaultOption(); + 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(); + } + WLOGFE("show errCode:%{public}d for winId:%{public}d", static_cast(ret), property_->GetWindowId()); + return ret; +#else + /* weston adapter */ + WMError rtn = Adapter::Show(); + if (rtn == WMError::WM_OK) { + NotifyAfterForeground(); + NotifyAfterFocused(); + WLOGFI("Show AfterForeground was invoked"); + } else { + WLOGFE("Show error=%d", static_cast(rtn)); + } + InputTransferStation::GetInstance()->AddInputWindow(this); + return rtn; +#endif +} + +WMError WindowImpl::Hide() +{ +#ifdef _NEW_RENDERSERVER_ + if (!IsWindowValid()) { + WLOGFI("window is already destroyed or not created! id: %{public}d", property_->GetWindowId()); + return WMError::WM_ERROR_INVALID_WINDOW; + } + if (state_ == STATE_HIDDEN || state_ == STATE_CREATED) { + 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()); + if (ret != WMError::WM_OK) { + return ret; + } + state_ = STATE_HIDDEN; + NotifyAfterBackground(); + return ret; +#else + /* weston adapter */ + WMError rtn = Adapter::Hide(); + if (rtn == WMError::WM_OK) { + NotifyAfterUnFocused(); + NotifyAfterBackground(); + WLOGFI("WindowImpl::Show AfterBackground was ivoked"); + } else { + WLOGFE("WindowImpl::Show error=%d", static_cast(rtn)); + } + InputTransferStation::GetInstance()->RemoveInputWindow(this); + return rtn; +#endif +} + +WMError WindowImpl::MoveTo(int32_t x, int32_t y) +{ + /* weston adapter */ +#ifdef _NEW_RENDERSERVER_ + if (!IsWindowValid()) { + WLOGFI("window is already destroyed or not created! id: %{public}d", property_->GetWindowId()); + return WMError::WM_ERROR_INVALID_WINDOW; + } + if (state_ == STATE_HIDDEN || state_ == STATE_CREATED) { + Rect rect = GetRect(); + property_->SetWindowRect({ x, y, rect.width_, rect.height_ }); + WLOGFI("window is hidden or created! id: %{public}d, rect: [%{public}d, %{public}d, %{public}d, %{public}d]", + property_->GetWindowId(), rect.posX_, rect.posY_, x, y); + return WMError::WM_OK; + } + return SingletonContainer::Get()->MoveTo(property_->GetWindowId(), x, y); +#else + return Adapter::MoveTo(x, y); +#endif +} + +WMError WindowImpl::Resize(uint32_t width, uint32_t height) +{ + /* weston adapter */ +#ifdef _NEW_RENDERSERVER_ + if (!IsWindowValid()) { + WLOGFI("window is already destroyed or not created! id: %{public}d", property_->GetWindowId()); + return WMError::WM_ERROR_INVALID_WINDOW; + } + if (state_ == STATE_HIDDEN || state_ == STATE_CREATED) { + Rect rect = GetRect(); + property_->SetWindowRect({ rect.posX_, rect.posY_, width, height }); + WLOGFI("window is hidden or created! id: %{public}d, rect: [%{public}d, %{public}d, %{public}d, %{public}d]", + property_->GetWindowId(), rect.posX_, rect.posY_, width, height); + return WMError::WM_OK; + } + return SingletonContainer::Get()->Resize(property_->GetWindowId(), width, height); +#else + return Adapter::Resize(width, height); +#endif +} + +WMError WindowImpl::RequestFocus() const +{ + if (!IsWindowValid()) { + 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()); +} + +void WindowImpl::AddInputEventListener(std::shared_ptr& inputEventListener) +{ + InputTransferStation::GetInstance()->SetInputListener(GetWindowId(), inputEventListener); +} + +void WindowImpl::RegisterLifeCycleListener(sptr& listener) +{ + lifecycleListener_ = listener; +} + +void WindowImpl::RegisterWindowChangeListener(sptr& listener) +{ + windowChangeListener_ = listener; +} + +void WindowImpl::UpdateRect(const struct Rect& rect) +{ + property_->SetWindowRect(rect); + if (windowChangeListener_ != nullptr) { + windowChangeListener_->OnSizeChange(rect); + } +} + +void WindowImpl::UpdateMode(WindowMode mode) +{ + property_->SetWindowMode(mode); +} + +void WindowImpl::ConsumeKeyEvent(std::shared_ptr& keyEvent) +{ + uiContent_->ProcessKeyEvent(keyEvent); +} +void WindowImpl::ConsumePointerEvent(std::shared_ptr& pointerEvent) +{ + uiContent_->ProcessPointerEvent(pointerEvent); +} + +void WindowImpl::UpdateFocusStatus(bool focused) +{ + WLOGFI("window focus status: %{public}d, id: %{public}d", focused, property_->GetWindowId()); + if (focused) { + NotifyAfterFocused(); + } else { + NotifyAfterUnFocused(); + } +} + +void WindowImpl::SetDefaultOption() +{ + 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()); + return; + } + uint32_t width = display->GetWidth(); + uint32_t height = display->GetHeight(); + WLOGFI("width:%{public}u, height:%{public}u, displayId:%{public}d", width, height, property_->GetDisplayId()); + + Rect rect; + switch (property_->GetWindowType()) { + case WindowType::WINDOW_TYPE_STATUS_BAR: { + rect = { 0, 0, width, static_cast((static_cast(height) * 0.07)) }; + 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)); + 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)); + + rect = { static_cast((width - alarmWidth) / 2), static_cast((height - alarmHeight) / 2), + alarmWidth, alarmHeight }; + property_->SetWindowRect(rect); + property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING); + break; + } + default: + break; + } + +} +bool WindowImpl::IsWindowValid() const +{ + return ((state_ > STATE_INITIAL) && (state_ < STATE_BOTTOM)); +} +} +} \ No newline at end of file diff --git a/wm/src/window_input_channel.cpp b/wm/src/window_input_channel.cpp new file mode 100644 index 0000000000..952270f3aa --- /dev/null +++ b/wm/src/window_input_channel.cpp @@ -0,0 +1,83 @@ +/* + * 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_input_channel.h" +#include + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowInputChannel"}; +} +WindowInputChannel::WindowInputChannel(const sptr& window) +{ + window_ = window; + callback_->onCallback = std::bind(&WindowInputChannel::OnVsync, this, std::placeholders::_1); +} + +void WindowInputChannel::HandleKeyEvent(std::shared_ptr& keyEvent) +{ + if (keyEvent == nullptr) { + WLOGE("HandleKeyEvent keyEvent is nullptr"); + return; + } + if (inputListener_ != nullptr) { + inputListener_->OnInputEvent(keyEvent); + return; + } + window_->ConsumeKeyEvent(keyEvent); + keyEvent->MarkProcessed(); +} + +void WindowInputChannel::HandlePointerEvent(std::shared_ptr& pointerEvent) +{ + if (pointerEvent == nullptr) { + WLOGE("HandlePointerEvent pointerEvent is nullptr"); + return; + } + if (inputListener_ != nullptr) { + inputListener_->OnInputEvent(pointerEvent); + return; + } + if (pointerEvent->GetPointerAction() == MMI::PointerEvent::POINTER_ACTION_MOVE) { + if (pointerEventPool_.size() > MAX_INPUT_NUM) { + pointerEventPool_.clear(); + } + pointerEventPool_.emplace_back(pointerEvent); + VsyncStation::GetInstance()->RequestVsync(VsyncStation::CallbackType::CALLBACK_INPUT, callback_); + } else { + window_->ConsumePointerEvent(pointerEvent); + pointerEvent->MarkProcessed(); + } +} + +void WindowInputChannel::OnVsync(int64_t timeStamp) +{ + if (pointerEventPool_.empty()) { + WLOGE("pointerEventPool_ is empty"); + return; + } + auto pointerEvent = pointerEventPool_.back(); + HandlePointerEvent(pointerEvent); + pointerEvent->MarkProcessed(); + pointerEventPool_.clear(); +} + +void WindowInputChannel::SetInputListener(std::shared_ptr& listener) +{ + inputListener_ = listener; +} +} +} \ No newline at end of file diff --git a/wm/src/window_option.cpp b/wm/src/window_option.cpp new file mode 100644 index 0000000000..d116dd9789 --- /dev/null +++ b/wm/src/window_option.cpp @@ -0,0 +1,126 @@ +/* + * 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_option.h" + +namespace OHOS { +namespace Rosen { +WindowOption::WindowOption() +{ + AddWindowFlag(WindowFlag::WINDOW_FLAG_NEED_AVOID); +} + +void WindowOption::SetWindowRect(const struct Rect& rect) +{ + windowRect_ = rect; +} + +void WindowOption::SetWindowType(WindowType type) +{ + type_ = type; +} + +void WindowOption::SetWindowMode(WindowMode mode) +{ + mode_ = mode; +} + +void WindowOption::SetFocusable(bool isFocusable) +{ + focusable_ = isFocusable; +} + +void WindowOption::SetTouchable(bool isTouchable) +{ + touchable_ = isTouchable; +} + +void WindowOption::SetDisplayId(int32_t displayId) +{ + displayId_ = displayId; +} + +void WindowOption::SetParentName(const std::string& parentName) +{ + parentName_ = parentName; +} + +void WindowOption::SetWindowName(const std::string& windowName) +{ + windowName_ = windowName; +} + +void WindowOption::AddWindowFlag(WindowFlag flag) +{ + flags_ |= static_cast(flag); +} + +void WindowOption::RemoveWindowFlag(WindowFlag flag) +{ + flags_ &= ~(static_cast(flag)); +} + +void WindowOption::SetWindowFlags(uint32_t flags) +{ + flags_ = flags; +} + +Rect WindowOption::GetWindowRect() const +{ + return windowRect_; +} + +WindowType WindowOption::GetWindowType() const +{ + return type_; +} + +WindowMode WindowOption::GetWindowMode() const +{ + return mode_; +} + +bool WindowOption::GetFocusable() const +{ + return focusable_; +} + +bool WindowOption::GetTouchable() const +{ + return touchable_; +} + +int32_t WindowOption::GetDisplayId() const +{ + return displayId_; +} + +const std::string& WindowOption::GetParentName() const +{ + return parentName_; +} + +const std::string& WindowOption::GetWindowName() const +{ + return windowName_; +} + +uint32_t WindowOption::GetWindowFlags() const +{ + return flags_; +} +} +} + diff --git a/wm/src/window_property.cpp b/wm/src/window_property.cpp new file mode 100644 index 0000000000..3ee405db3e --- /dev/null +++ b/wm/src/window_property.cpp @@ -0,0 +1,238 @@ +/* + * 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_property.h" + +namespace OHOS { +namespace Rosen { +void WindowProperty::SetWindowRect(const struct Rect& rect) +{ + windowRect_ = rect; +} + +void WindowProperty::SetWindowType(WindowType type) +{ + type_ = type; +} + +void WindowProperty::SetWindowMode(WindowMode mode) +{ + mode_ = mode; +} + +void WindowProperty::SetFullScreen(bool isFullScreen) +{ + isFullScreen_ = isFullScreen; +} + +void WindowProperty::SetFocusable(bool isFocusable) +{ + focusable_ = isFocusable; +} + +void WindowProperty::SetTouchable(bool isTouchable) +{ + touchable_ = isTouchable; +} + +void WindowProperty::SetPrivacyMode(bool isPrivate) +{ + isPrivacyMode_ = isPrivate; +} + +void WindowProperty::SetTransparent(bool isTransparent) +{ + isTransparent_ = isTransparent; +} + +void WindowProperty::SetAlpha(float alpha) +{ + alpha_ = alpha; +} + +void WindowProperty::SetDisplayId(int32_t displayId) +{ + displayId_ = displayId; +} + +void WindowProperty::SetWindowFlags(uint32_t flags) +{ + flags_ = flags; +} + +Rect WindowProperty::GetWindowRect() const +{ + return windowRect_; +} + +WindowType WindowProperty::GetWindowType() const +{ + return type_; +} + +WindowMode WindowProperty::GetWindowMode() const +{ + return mode_; +} + +bool WindowProperty::GetFullScreen() const +{ + return isFullScreen_; +} + +bool WindowProperty::GetFocusable() const +{ + return focusable_; +} + +bool WindowProperty::GetTouchable() const +{ + return touchable_; +} + +bool WindowProperty::GetPrivacyMode() const +{ + return isPrivacyMode_; +} + +bool WindowProperty::GetTransparent() const +{ + return isTransparent_; +} + +float WindowProperty::GetAlpha() const +{ + return alpha_; +} + +int32_t WindowProperty::GetDisplayId() const +{ + return displayId_; +} + +uint32_t WindowProperty::GetWindowFlags() const +{ + return flags_; +} + +// TODO +void WindowProperty::SetWindowId(uint32_t windowId) +{ + windowId_ = windowId; +} +void WindowProperty::SetParentId(uint32_t parentId) +{ + parentId_ = parentId; +} +uint32_t WindowProperty::GetWindowId() const +{ + return windowId_; +} +uint32_t WindowProperty::GetParentId() const +{ + return parentId_; +} + +bool WindowProperty::Marshalling(Parcel& parcel) const +{ + // write windowRect_ + if (!(parcel.WriteInt32(windowRect_.posX_) && parcel.WriteInt32(windowRect_.posY_) && + parcel.WriteUint32(windowRect_.width_) && parcel.WriteUint32(windowRect_.height_))) { + return false; + } + + // write type_ + if (!parcel.WriteUint32(static_cast(type_))) { + return false; + } + + // write mode_ + if (!parcel.WriteUint32(static_cast(mode_))) { + return false; + } + + // write flags_ + if (!parcel.WriteUint32(flags_)) { + return false; + } + + // write isFullScreen_ + if (!parcel.WriteBool(isFullScreen_)) { + return false; + } + + // write focusable_ + if (!parcel.WriteBool(focusable_)) { + return false; + } + + // write touchable_ + if (!parcel.WriteBool(touchable_)) { + return false; + } + + // write isPrivacyMode_ + if (!parcel.WriteBool(isPrivacyMode_)) { + return false; + } + + // write isTransparent_ + if (!parcel.WriteBool(isTransparent_)) { + return false; + } + + // write alpha_ + if (!parcel.WriteFloat(alpha_)) { + return false; + } + + // write displayId_ + if (!parcel.WriteInt32(displayId_)) { + return false; + } + + // write windowId_ + if (!parcel.WriteUint32(windowId_)) { + return false; + } + + // write parentId_ + if (!parcel.WriteUint32(parentId_)) { + return false; + } + return true; +} + +sptr WindowProperty::Unmarshalling(Parcel& parcel) +{ + sptr property(new WindowProperty()); + Rect rect = { parcel.ReadInt32(), parcel.ReadInt32(), parcel.ReadUint32(), parcel.ReadUint32() }; + property->SetWindowRect(rect); + property->SetWindowType(static_cast(parcel.ReadUint32())); + property->SetWindowMode(static_cast(parcel.ReadUint32())); + property->SetWindowFlags(parcel.ReadUint32()); + property->SetFullScreen(parcel.ReadBool()); + property->SetFocusable(parcel.ReadBool()); + property->SetTouchable(parcel.ReadBool()); + property->SetPrivacyMode(parcel.ReadBool()); + property->SetTransparent(parcel.ReadBool()); + property->SetAlpha(parcel.ReadFloat()); + property->SetDisplayId(parcel.ReadInt32()); + property->SetWindowId(parcel.ReadUint32()); + property->SetParentId(parcel.ReadUint32()); + return property; +} +} +} diff --git a/wm/src/window_proxy.cpp b/wm/src/window_proxy.cpp new file mode 100644 index 0000000000..7334d6bb60 --- /dev/null +++ b/wm/src/window_proxy.cpp @@ -0,0 +1,97 @@ +/* + * 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_proxy.h" +#include +#include "window_manager_hilog.h" + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowProxy"}; +} + +void WindowProxy::UpdateWindowProperty(const WindowProperty& windowProperty) +{ + sptr remote = Remote(); + if (remote == nullptr) { + WLOGFW("remote is nullptr"); + return; + } +} + +void WindowProxy::UpdateWindowRect(const struct Rect& rect) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("WriteInterfaceToken failed"); + return; + } + if (!(data.WriteInt32(rect.posX_) && data.WriteInt32(rect.posY_) && + data.WriteUint32(rect.width_) && data.WriteUint32(rect.height_))) { + WLOGFE("Write WindowRect failed"); + return; + } + + if (Remote()->SendRequest(TRANS_ID_UPDATE_WINDOW_RECT, data, reply, option) != ERR_NONE) { + WLOGFE("SendRequest failed"); + } + return; +} + +void WindowProxy::UpdateWindowMode(WindowMode mode) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("WriteInterfaceToken failed"); + return; + } + if (!data.WriteUint32(static_cast(mode))) { + WLOGFE("Write WindowMode failed"); + return; + } + + if (Remote()->SendRequest(TRANS_ID_UPDATE_WINDOW_MODE, data, reply, option) != ERR_NONE) { + WLOGFE("SendRequest failed"); + } + return; +} + +void WindowProxy::UpdateFocusStatus(bool focused) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("WriteInterfaceToken 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"); + } + return; +} +} // namespace Rosen +} // namespace OHOS + diff --git a/wm/src/window_scene.cpp b/wm/src/window_scene.cpp new file mode 100644 index 0000000000..3281d77428 --- /dev/null +++ b/wm/src/window_scene.cpp @@ -0,0 +1,127 @@ +/* + * 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_scene.h" +#include "static_call.h" +#include "window_impl.h" +#include "window_manager_hilog.h" +#ifndef _NEW_RENDERSERVER_ +#include "adapter.h" +#endif + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowScene"}; +} + +const std::string WindowScene::MAIN_WINDOW_ID = "main window"; + +WindowScene::~WindowScene() +{ + WLOGFI("~WindowScene"); + if (mainWindow_ != nullptr) { + mainWindow_->Destroy(); + mainWindow_ = nullptr; + } +} + +WMError WindowScene::Init(int32_t displayId, std::shared_ptr& abilityContext, + sptr& listener) +{ + displayId_ = displayId; + abilityContext_ = abilityContext; + sptr option = new WindowOption(); + option->SetDisplayId(displayId); + +#ifndef _NEW_RENDERSERVER_ + /* weston adapter */ + Adapter::Init(); + mainWindow_ = CreateWindow(MAIN_WINDOW_ID, option); +#else + if (abilityContext_ != nullptr) { + mainWindow_ = SingletonContainer::Get()->CreateWindow( + MAIN_WINDOW_ID + std::to_string(count++), option, abilityContext_->GetAbilityToken()); + } else { + mainWindow_ = SingletonContainer::Get()->CreateWindow( + MAIN_WINDOW_ID + std::to_string(count++), option); + } + +#endif + if (mainWindow_ == nullptr) { + return WMError::WM_ERROR_NULLPTR; + } + mainWindow_->RegisterLifeCycleListener(listener); + + return WMError::WM_OK; +} + +sptr WindowScene::CreateWindow(const std::string& windowName, sptr& option) const +{ +#ifdef _NEW_RENDERSERVER_ + if (windowName.empty() || mainWindow_ == nullptr || option == nullptr) { + WLOGFE("WindowScene Name: %{public}s", windowName.c_str()); + return nullptr; + } + option->SetParentName(mainWindow_->GetWindowName()); + return SingletonContainer::Get()->CreateWindow(windowName, option); +#else + /* weston adapter */ + if (!Adapter::CreateWestonWindow(option)) { + WLOGFE("WindowScene::CreateWindow fail to CreateWestonWindow"); + return nullptr; + } + Rect rect; + if (!Adapter::GetMainWindowRect(rect)) { + WLOGFE("WindowScene::CreateWindow fail to GetMainWindowRect"); + return nullptr; + } + option->SetWindowName(windowName); + option->SetWindowRect(rect); + sptr window = new WindowImpl(option); + return window; +#endif +} + +const sptr& WindowScene::GetMainWindow() const +{ + return mainWindow_; +} + +WMError WindowScene::GoForeground() +{ + if (mainWindow_ == nullptr) { + return WMError::WM_ERROR_NULLPTR; + } + return mainWindow_->Show(); +} + +WMError WindowScene::GoBackground() const +{ + if (mainWindow_ == nullptr) { + return WMError::WM_ERROR_NULLPTR; + } + return mainWindow_->Hide(); +} + +WMError WindowScene::RequestFocus() const +{ + if (mainWindow_ == nullptr) { + return WMError::WM_ERROR_NULLPTR; + } + return mainWindow_->RequestFocus(); +} +} // namespace Rosen +} // namespace OHOS diff --git a/wm/src/window_stub.cpp b/wm/src/window_stub.cpp new file mode 100644 index 0000000000..e7640726e2 --- /dev/null +++ b/wm/src/window_stub.cpp @@ -0,0 +1,59 @@ +/* + * 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_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, "WindowStub"}; +} + +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; + } + switch (code) { + case TRANS_ID_UPDATE_WINDOW_PROPERTY: { + break; + } + case TRANS_ID_UPDATE_WINDOW_RECT: { + struct Rect rect{ data.ReadInt32(), data.ReadInt32(), data.ReadUint32(), data.ReadUint32() }; + UpdateWindowRect(rect); + break; + } + case TRANS_ID_UPDATE_WINDOW_MODE: { + WindowMode mode = static_cast(data.ReadUint32()); + UpdateWindowMode(mode); + break; + } + case TRANS_ID_UPDATE_FOCUS_STATUS: { + bool focused = data.ReadBool(); + UpdateFocusStatus(focused); + break; + } + default: + break; + } + return 0; +} +} // namespace Rosen +} // namespace OHOS diff --git a/wmserver/BUILD.gn b/wmserver/BUILD.gn new file mode 100644 index 0000000000..6db3713751 --- /dev/null +++ b/wmserver/BUILD.gn @@ -0,0 +1,85 @@ +# 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("//build/ohos.gni") + +## Build libwms.so +config("libwms_config") { + visibility = [ ":*" ] + + include_dirs = [ + "include", + "//utils/system/safwk/native/include", + "//foundation/windowmanager/interfaces/innerkits/wm", + "//foundation/windowmanager/interfaces/innerkits/dm", + "//foundation/windowmanager/wm/include", + "//foundation/windowmanager/utils/include", + "//foundation/windowmanager/dm/include", + "//foundation/windowmanager/dmserver/include", + ] + + cflags = [ + "-Wall", + "-Werror", + "-g3", + ] +} + +ohos_shared_library("libwms") { + sources = [ + "../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", + "src/input_window_monitor.cpp", + "src/window_controller.cpp", + "src/window_layout_policy.cpp", + "src/window_manager_service.cpp", + "src/window_manager_stub.cpp", + "src/window_node.cpp", + "src/window_node_container.cpp", + "src/window_root.cpp", + "src/window_zorder_policy.cpp", + ] + + configs = [ ":libwms_config" ] + + deps = [ + "//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", + ] + + external_deps = [ "ipc:ipc_core" ] + + part_name = "window_manager" + subsystem_name = "window" +} diff --git a/wmserver/include/README.md b/wmserver/include/README.md new file mode 100644 index 0000000000..539249966b --- /dev/null +++ b/wmserver/include/README.md @@ -0,0 +1 @@ +Store code of window sever inner header files \ No newline at end of file diff --git a/wmserver/include/input_window_monitor.h b/wmserver/include/input_window_monitor.h new file mode 100644 index 0000000000..ed44650580 --- /dev/null +++ b/wmserver/include/input_window_monitor.h @@ -0,0 +1,72 @@ +/* + * 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_INPUT_WINDOW_MONITOR_H +#define OHOS_INPUT_WINDOW_MONITOR_H + +#include +#include + +#include "window_root.h" + +namespace OHOS { +namespace Rosen { +class InputWindowMonitor : public RefBase { +public: + InputWindowMonitor(sptr& root) : windowRoot_(root) + { + MMI::PhysicalDisplayInfo physicalDisplayInfo = { + .id = 0, //todo: update when DMS is ready + .leftDisplayId = -1, // todo: invalid displayId for testing + .upDisplayId = -1, // todo: invalid displayId for testing + .topLeftX = 0, // todo: use wgn info for testing + .topLeftY = 0, // todo: use wgn info for testing + .width = 2560, // todo: use wgn info for testing + .height = 1600, // todo: use wgn info for testing + .name = "physical_display0", // todo: wait for DMS + .seatId = "seat0", // todo: update seatId + .seatName = "default0", // todo: update seatId + .logicWidth = 2560, // todo: use wgn info for testing + .logicHeight = 1600, // todo: use wgn info for testing + .direction = MMI::Direction0 // todo: use direction 0 for testing + }; + physicalDisplays_.emplace_back(physicalDisplayInfo); + MMI::LogicalDisplayInfo logicalDisplayInfo = { + .id = 0, //todo: update when DMS is ready + .topLeftX = 0, // todo: use wgn info for testing + .topLeftY = 0, // todo: use wgn info for testing + .width = 2560, // todo: use wgn info for testing + .height = 1600, // todo: use wgn info for testing + .name = "logical_display0", // todo: wait for DMS + .seatId = "seat0", // todo: update seatId + .seatName = "default0", // todo: update seatName + .focusWindowId = -1, + .windowsInfo_ = {}, + }; + logicalDisplays_.emplace_back(logicalDisplayInfo); + } + ~InputWindowMonitor() = default; + void UpdateInputWindow(uint32_t windowId); + +private: + sptr windowRoot_; + std::vector physicalDisplays_; + std::vector logicalDisplays_; + void TraverseWindowNodes(const std::vector>& windowNodes, + std::vector::iterator& iter); +}; +} +} +#endif // OHOS_INPUT_WINDOW_MONITOR_H diff --git a/wmserver/include/window_controller.h b/wmserver/include/window_controller.h new file mode 100644 index 0000000000..043cad3d49 --- /dev/null +++ b/wmserver/include/window_controller.h @@ -0,0 +1,48 @@ +/* + * 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_CONTROLLER_H +#define OHOS_ROSEN_WINDOW_CONTROLLER_H + +#include +#include "window_root.h" + +namespace OHOS { +namespace Rosen { +class WindowController : public RefBase { +public: + WindowController(sptr& root) : windowRoot_(root) {} + ~WindowController() = default; + + WMError CreateWindow(sptr& window, sptr& property, + const std::shared_ptr& surfaceNode, uint32_t& windowId); + WMError AddWindowNode(sptr& property); + WMError RemoveWindowNode(uint32_t windowId); + WMError DestroyWindow(uint32_t windowId); + WMError MoveTo(uint32_t windowId, int32_t x, int32_t y); + WMError Resize(uint32_t windowId, uint32_t width, uint32_t height); + WMError RequestFocus(uint32_t windowId); + WMError SaveAbilityToken(const sptr& abilityToken, uint32_t windowId); + +private: + uint32_t GenWindowId(); + WMError LayoutWindowNodeTrees(); + + sptr windowRoot_; + std::atomic windowId_ { 0 }; +}; +} +} +#endif // OHOS_ROSEN_WINDOW_CONTROLLER_H diff --git a/wmserver/include/window_layout_policy.h b/wmserver/include/window_layout_policy.h new file mode 100644 index 0000000000..350b8c0e2a --- /dev/null +++ b/wmserver/include/window_layout_policy.h @@ -0,0 +1,53 @@ +/* + * 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_LAYOUT_POLICY_H +#define OHOS_ROSEN_WINDOW_LAYOUT_POLICY_H + +#include +#include +#include + +#include "window_node.h" +#include "wm_common.h" + +namespace OHOS { +namespace Rosen { +class WindowLayoutPolicy : public RefBase { +public: + WindowLayoutPolicy() = default; + ~WindowLayoutPolicy() = default; + WMError UpdateDisplayInfo(const Rect& displayRect); + WMError LayoutWindow(sptr& node); + +private: + Rect displayRect_ = {0, 0, 0, 0}; + Rect limitRect_ = {0, 0, 0, 0}; + std::map> aviodNodes_; + const std::set aviodTypes_ { + 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); +}; +} +} +#endif // OHOS_ROSEN_WINDOW_LAYOUT_POLICY_H diff --git a/wmserver/include/window_manager_interface.h b/wmserver/include/window_manager_interface.h new file mode 100644 index 0000000000..e1d9d4d494 --- /dev/null +++ b/wmserver/include/window_manager_interface.h @@ -0,0 +1,52 @@ +/* + * 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_INTERFACE_H +#define OHOS_WINDOW_MANAGER_INTERFACE_H + +#include +#include +#include "window_property.h" +#include "window_interface.h" + +namespace OHOS { +namespace Rosen { +class IWindowManager : public IRemoteBroker { +public: + DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.IWindowManager"); + + enum { + TRANS_ID_CREATE_WINDOW, + TRANS_ID_ADD_WINDOW, + TRANS_ID_REMOVE_WINDOW, + TRANS_ID_DESTROY_WINDOW, + TRANS_ID_MOVE, + TRANS_ID_RESIZE, + TRANS_ID_REQUEST_FOCUS, + TRANS_ID_SEND_ABILITY_TOKEN, + }; + virtual WMError CreateWindow(sptr& window, sptr& property, + const std::shared_ptr& surfaceNode, uint32_t& windowId) = 0; + virtual WMError AddWindow(sptr& property) = 0; + virtual WMError RemoveWindow(uint32_t windowId) = 0; + virtual WMError DestroyWindow(uint32_t windowId) = 0; + 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 SaveAbilityToken(const sptr& abilityToken, uint32_t windowId) = 0; +}; +} +} +#endif // OHOS_WINDOW_MANAGER_INTERFACE_H diff --git a/wmserver/include/window_manager_proxy.h b/wmserver/include/window_manager_proxy.h new file mode 100644 index 0000000000..60e89fd3cf --- /dev/null +++ b/wmserver/include/window_manager_proxy.h @@ -0,0 +1,45 @@ +/* + * 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_PROXY_H +#define OHOS_WINDOW_MANAGER_PROXY_H + +#include "window_manager_interface.h" +#include + +namespace OHOS { +namespace Rosen { +class WindowManagerProxy : public IRemoteProxy { +public: + explicit WindowManagerProxy(const sptr& impl) : IRemoteProxy(impl) {}; + + ~WindowManagerProxy() {}; + + WMError CreateWindow(sptr& window, sptr& property, + const std::shared_ptr& surfaceNode, uint32_t& windowId) override; + WMError AddWindow(sptr& property) override; + WMError RemoveWindow(uint32_t windowId) override; + WMError DestroyWindow(uint32_t windowId) override; + WMError MoveTo(uint32_t windowId, int32_t x, int32_t y) override; + 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: + static inline BrokerDelegator delegator_; +}; +} +} +#endif // OHOS_WINDOW_MANAGER_PROXY_H diff --git a/wmserver/include/window_manager_service.h b/wmserver/include/window_manager_service.h new file mode 100644 index 0000000000..b722b16469 --- /dev/null +++ b/wmserver/include/window_manager_service.h @@ -0,0 +1,63 @@ +/* + * 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_SERVICE_H +#define OHOS_WINDOW_MANAGER_SERVICE_H + +#include +#include + +#include +#include +#include +#include "singleton_delegator.h" +#include "single_instance.h" +#include "window_controller.h" +#include "window_manager_stub.h" +#include "window_root.h" + +namespace OHOS { +namespace Rosen { +class WindowManagerService : public SystemAbility, public WindowManagerStub { +DECLARE_SYSTEM_ABILITY(WindowManagerService); + +DECLARE_SINGLE_INSTANCE_BASE(WindowManagerService); + +public: + ~WindowManagerService() = default; + void OnStart() override; + void OnStop() override; + + WMError CreateWindow(sptr& window, sptr& property, + const std::shared_ptr& surfaceNode, uint32_t& windowId) override; + WMError AddWindow(sptr& property) override; + WMError RemoveWindow(uint32_t windowId) override; + WMError DestroyWindow(uint32_t windowId) override; + WMError MoveTo(uint32_t windowId, int32_t x, int32_t y) override; + 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: + WindowManagerService(); + bool Init(); + static inline SingletonDelegator delegator; + std::mutex mutex_; + sptr windowRoot_; + sptr windowController_; + sptr inputWindowMonitor_; +}; +} +} +#endif // OHOS_WINDOW_MANAGER_SERVICE_H diff --git a/wmserver/include/window_manager_stub.h b/wmserver/include/window_manager_stub.h new file mode 100644 index 0000000000..4fa7df0aa9 --- /dev/null +++ b/wmserver/include/window_manager_stub.h @@ -0,0 +1,32 @@ +/* + * 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_STUB_H +#define OHOS_WINDOW_MANAGER_STUB_H + +#include "window_manager_interface.h" +#include +namespace OHOS { +namespace Rosen { +class WindowManagerStub : public IRemoteStub { +public: + WindowManagerStub() = default; + ~WindowManagerStub() = default; + virtual int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, + MessageOption &option) override; +}; +} +} +#endif // OHOS_WINDOW_MANAGER_STUB_H diff --git a/wmserver/include/window_node.h b/wmserver/include/window_node.h new file mode 100644 index 0000000000..0684ebe71d --- /dev/null +++ b/wmserver/include/window_node.h @@ -0,0 +1,82 @@ +/* + * 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_NODE_H +#define OHOS_ROSEN_WINDOW_NODE_H + +#include +#include +#include +#include "window_interface.h" +#include "window_manager_hilog.h" + +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, + std::shared_ptr surfaceNode) + : surfaceNode_(surfaceNode), property_(property), windowToken_(window) + { + callingPid_ = IPCSkeleton::GetCallingPid(); + callingUid_ = IPCSkeleton::GetCallingUid(); + } + WindowNode() : property_(new WindowProperty()) + { + callingPid_ = IPCSkeleton::GetCallingPid(); + callingUid_ = IPCSkeleton::GetCallingUid(); + } + ~WindowNode() = default; + + void SetDisplayId(int32_t displayId); + void UpdateLayoutRects(const LayoutRects& rects); + void SetWindowProperty(const sptr& property); + + const sptr& GetWindowToken() const; + uint32_t GetWindowId() const; + int32_t GetDisplayId() const; + const LayoutRects& GetLayoutRects() const; + WindowType GetWindowType() const; + WindowMode GetWindowMode() const; + uint32_t GetWindowFlags() const; + const sptr& GetWindowProperty() const; + int32_t GetCallingPid() const; + int32_t GetCallingUid() const; + + sptr parent_; + std::vector> children_; + std::shared_ptr surfaceNode_; + sptr abilityToken_ = nullptr; + int32_t priority_ { 0 }; + bool requestedVisibility_ { false }; + bool currentVisibility_ { false }; + +private: + sptr property_; + sptr windowToken_; + LayoutRects layoutRects_; + int32_t callingPid_; + int32_t callingUid_; +}; +} +} +#endif // OHOS_ROSEN_WINDOW_NODE_H diff --git a/wmserver/include/window_node_container.h b/wmserver/include/window_node_container.h new file mode 100644 index 0000000000..251683b665 --- /dev/null +++ b/wmserver/include/window_node_container.h @@ -0,0 +1,76 @@ +/* + * 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_NODE_CONTAINER_H +#define OHOS_ROSEN_WINDOW_NODE_CONTAINER_H + +#include +#include "window_layout_policy.h" +#include "window_node.h" +#include "window_zorder_policy.h" +#include "wm_common.h" + +namespace OHOS { +namespace Rosen { +class WindowNodeContainer : public RefBase { +public: + WindowNodeContainer(uint64_t screenId, uint32_t width, uint32_t height) + { + struct RSDisplayNodeConfig config = {screenId}; + displayNode_ = RSDisplayNode::Create(config); + displayRect_ = { + .posX_ = 0, + .posY_ = 0, + .width_ = width, + .height_ = height + }; + } + + ~WindowNodeContainer(); + WMError AddWindowNode(sptr& node, sptr& parentNode); + WMError RemoveWindowNode(sptr& node); + WMError DestroyWindowNode(sptr& node, std::vector& windowIds); + const std::vector& Destroy(); + void AssignZOrder(); + WMError SetFocusWindow(uint32_t windowId); + uint32_t GetFocusWindow() const; + WMError MinimizeOtherFullScreenAbility(); // adapt to api7 + void TraverseContainer(std::vector>& windowNodes); + WMError LayoutWindowNodes(); + +private: + void AssignZOrder(sptr& node); + void TraverseWindowNode(sptr& root, std::vector>& windowNodes); + sptr FindRoot(WindowType type) const; + void UpdateFocusWindow(); + sptr FindWindowNodeById(uint32_t id) const; + void UpdateFocusStatus(uint32_t id, bool focused) const; + 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(); + std::shared_ptr displayNode_; + std::vector removedIds_; + uint32_t zOrder_ { 0 }; + uint32_t focusedWindow_ { 0 }; + Rect displayRect_; + WMError LayoutWindowNode(sptr& node); +}; +} +} +#endif // OHOS_ROSEN_WINDOW_NODE_CONTAINER_H diff --git a/wmserver/include/window_root.h b/wmserver/include/window_root.h new file mode 100644 index 0000000000..9a86234686 --- /dev/null +++ b/wmserver/include/window_root.h @@ -0,0 +1,65 @@ +/* + * 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_ROOT_H +#define OHOS_ROSEN_WINDOW_ROOT_H + +#include +#include +#include "window_node_container.h" + +namespace OHOS { +namespace Rosen { +class WindowDeathRecipient : public IRemoteObject::DeathRecipient { +public: + WindowDeathRecipient(std::function&)> callback) : callback_(callback) {} + ~WindowDeathRecipient() = default; + + virtual void OnRemoteDied(const wptr& wptrDeath) override; + + std::function&)> callback_; +}; + +class WindowRoot : public RefBase { +public: + WindowRoot() = default; + ~WindowRoot() = default; + + sptr GetOrCreateWindowNodeContainer(int32_t displayId); + void NotifyDisplayRemoved(int32_t displayId); + sptr GetWindowNode(uint32_t windowId) const; + + WMError SaveWindow(const sptr& node); + WMError AddWindowNode(uint32_t parentId, sptr& node); + WMError RemoveWindowNode(uint32_t windowId); + WMError DestroyWindow(uint32_t windowId); + const std::map>& GetWindowNodeContainerMap() const; + + WMError RequestFocus(uint32_t windowId); + WMError MinimizeOtherFullScreenAbility(sptr& node); + +private: + void ClearWindow(const sptr& remoteObject); + WMError DestroyWindowInner(sptr& node); + + std::map> windowNodeContainerMap_; + std::map> windowNodeMap_; + std::map, uint32_t> windowIdMap_; + + sptr windowDeath_ = new WindowDeathRecipient(std::bind(&WindowRoot::ClearWindow, + this, std::placeholders::_1)); +}; +} +} +#endif // OHOS_ROSEN_WINDOW_ROOT_H diff --git a/wmserver/include/window_zorder_policy.h b/wmserver/include/window_zorder_policy.h new file mode 100644 index 0000000000..8e91d3d664 --- /dev/null +++ b/wmserver/include/window_zorder_policy.h @@ -0,0 +1,63 @@ +/* + * 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_ZORDER_POLICY_H +#define OHOS_ROSEN_WINDOW_ZORDER_POLICY_H + +#include +#include + +#include "wm_common.h" + +namespace OHOS { +namespace Rosen { +class WindowZorderPolicy : public RefBase { +public: + WindowZorderPolicy() = default; + ~WindowZorderPolicy() = default; + + int32_t GetWindowPriority(WindowType type) const; + +private: + const std::map windowPriorityMap_ { + // sub-windows types + { WindowType::WINDOW_TYPE_MEDIA, -1 }, + { WindowType::WINDOW_TYPE_APP_SUB_WINDOW, 1 }, + + // main window + { WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, 0 }, + + // system-specific window + { WindowType::WINDOW_TYPE_WALLPAPER, 101 }, + { WindowType::WINDOW_TYPE_APP_LAUNCHING, 102 }, + { WindowType::WINDOW_TYPE_DOCK_SLICE, 103 }, + { WindowType::WINDOW_TYPE_INCOMING_CALL, 104 }, + { WindowType::WINDOW_TYPE_SEARCHING_BAR, 105 }, + { WindowType::WINDOW_TYPE_SYSTEM_ALARM_WINDOW, 106 }, + { WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT, 107 }, + { WindowType::WINDOW_TYPE_FLOAT, 108 }, + { WindowType::WINDOW_TYPE_TOAST, 109 }, + { WindowType::WINDOW_TYPE_STATUS_BAR, 110 }, + { WindowType::WINDOW_TYPE_PANEL, 111 }, + { WindowType::WINDOW_TYPE_KEYGUARD, 112 }, + { WindowType::WINDOW_TYPE_VOLUME_OVERLAY, 113 }, + { WindowType::WINDOW_TYPE_NAVIGATION_BAR, 114 }, + { WindowType::WINDOW_TYPE_DRAGGING_EFFECT, 115 }, + { WindowType::WINDOW_TYPE_POINTER, 116 }, + }; +}; +} +} +#endif // OHOS_ROSEN_WINDOW_STATE_H diff --git a/wmserver/src/README.md b/wmserver/src/README.md new file mode 100644 index 0000000000..6aa13c7e6a --- /dev/null +++ b/wmserver/src/README.md @@ -0,0 +1 @@ +Store code of window server source files diff --git a/wmserver/src/input_window_monitor.cpp b/wmserver/src/input_window_monitor.cpp new file mode 100644 index 0000000000..9dc6ff82a8 --- /dev/null +++ b/wmserver/src/input_window_monitor.cpp @@ -0,0 +1,87 @@ +/* + * 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 "input_window_monitor.h" + +#include + +#include + +#include "window_manager_hilog.h" + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "InputWindowMonitor"}; +} + +void InputWindowMonitor::UpdateInputWindow(uint32_t windowId) +{ + if (windowRoot_ == nullptr) { + WLOGFE("windowRoot is null."); + return; + } + sptr windowNode = windowRoot_->GetWindowNode(windowId); + if (windowNode == nullptr) { + WLOGFE("window node could not be found."); + return; + } + int32_t displayId = windowNode->GetDisplayId(); + auto container = windowRoot_->GetOrCreateWindowNodeContainer(displayId); + if (container == nullptr) { + WLOGFE("can not get window node container."); + return; + } + std::vector> windowNodes; + container->TraverseContainer(windowNodes); + + auto iter = std::find_if(logicalDisplays_.begin(), logicalDisplays_.end(), + [displayId](MMI::LogicalDisplayInfo& logicalDisplay) { + return logicalDisplay.id == displayId; + }); + if (iter != logicalDisplays_.end()) { + TraverseWindowNodes(windowNodes, iter); + if (!iter->windowsInfo_.empty()) { + iter->focusWindowId = container->GetFocusWindow(); + } + } else { + WLOGFE("There is no display for this window action."); + return; + } + WLOGFI("update display info to IMS."); + MMI::InputManager::GetInstance()->UpdateDisplayInfo(physicalDisplays_, logicalDisplays_); +} + +void InputWindowMonitor::TraverseWindowNodes(const std::vector> &windowNodes, + std::vector::iterator& iter) +{ + iter->windowsInfo_.clear(); + for (auto& windowNode: windowNodes) { + MMI::WindowInfo windowInfo = { + .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_), + .displayId = windowNode->GetDisplayId(), + .agentWindowId = static_cast(windowNode->GetWindowId()), + }; + iter->windowsInfo_.emplace_back(windowInfo); + } +} +} +} \ No newline at end of file diff --git a/wmserver/src/window_controller.cpp b/wmserver/src/window_controller.cpp new file mode 100644 index 0000000000..9f3dbe1ead --- /dev/null +++ b/wmserver/src/window_controller.cpp @@ -0,0 +1,153 @@ +/* + * 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_controller.h" +#include +#include "window_manager_hilog.h" + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowController"}; +} +uint32_t WindowController::GenWindowId() +{ + return ++windowId_; +} + +WMError WindowController::CreateWindow(sptr& window, sptr& property, + const std::shared_ptr& surfaceNode, uint32_t& windowId) +{ + windowId = GenWindowId(); + property->SetWindowId(windowId); + + sptr node = new WindowNode(property, window, surfaceNode); + return windowRoot_->SaveWindow(node); +} + +WMError WindowController::SaveAbilityToken(const sptr& abilityToken, uint32_t windowId) +{ + auto node = windowRoot_->GetWindowNode(windowId); + if (node == nullptr) { + WLOGFE("could not find window"); + return WMError::WM_ERROR_NULLPTR; + } + node->abilityToken_ = abilityToken; + return WMError::WM_OK; +} + +WMError WindowController::AddWindowNode(sptr& property) +{ + auto node = windowRoot_->GetWindowNode(property->GetWindowId()); + if (node == nullptr) { + WLOGFE("could not find window"); + return WMError::WM_ERROR_NULLPTR; + } + node->SetWindowProperty(property); + // TODO: check permission + // TODO: adjust property + + WMError res = windowRoot_->AddWindowNode(property->GetParentId(), node); + 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"); + WMError res = windowRoot_->MinimizeOtherFullScreenAbility(node); + if (res != WMError::WM_OK) { + WLOGFE("Minimize other fullscreen window failed"); + } + } + 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; +} + +WMError WindowController::DestroyWindow(uint32_t windowId) +{ + WMError res = windowRoot_->DestroyWindow(windowId); + if (res != WMError::WM_OK) { + return res; + } + res = LayoutWindowNodeTrees(); + RSTransaction::FlushImplicitTransaction(); + WLOGFI("DestroyWindow FlushImplicitTransaction end"); + return res; +} + +WMError WindowController::MoveTo(uint32_t windowId, int32_t x, int32_t y) +{ + auto node = windowRoot_->GetWindowNode(windowId); + if (node == nullptr) { + WLOGFE("could not find window"); + return WMError::WM_ERROR_NULLPTR; + } + Vector2f pos(x, y); + node->surfaceNode_->SetBoundsPosition(pos); + RSTransaction::FlushImplicitTransaction(); + WLOGFI("MoveTo FlushImplicitTransaction end"); + return WMError::WM_OK; +} + +WMError WindowController::Resize(uint32_t windowId, uint32_t width, uint32_t height) +{ + auto node = windowRoot_->GetWindowNode(windowId); + if (node == nullptr) { + WLOGFE("could not find window"); + return WMError::WM_ERROR_NULLPTR; + } + node->surfaceNode_->SetBoundsSize(width, height); + RSTransaction::FlushImplicitTransaction(); + WLOGFI("Resize FlushImplicitTransaction end"); + return WMError::WM_OK; +} + +WMError WindowController::RequestFocus(uint32_t windowId) +{ + return windowRoot_->RequestFocus(windowId); +} +} +} diff --git a/wmserver/src/window_layout_policy.cpp b/wmserver/src/window_layout_policy.cpp new file mode 100644 index 0000000000..c90a5f030e --- /dev/null +++ b/wmserver/src/window_layout_policy.cpp @@ -0,0 +1,184 @@ +/* + * 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_layout_policy.h" +#include "window_manager_hilog.h" + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowLayoutPolicy"}; +} + +WMError 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; +} + +WMError WindowLayoutPolicy::LayoutWindow(sptr& node) +{ + if (node->GetWindowType() >= WindowType::SYSTEM_WINDOW_END) { + WLOGFE("unknown window type!"); + return WMError::WM_ERROR_INVALID_PARAM; + } + UpdateLayoutRects(node); + if (aviodTypes_.find(node->GetWindowType()) != aviodTypes_.end()) { + RecordAvoidRect(node); + } + return WMError::WM_OK; +} + +bool WindowLayoutPolicy::IsRectChanged(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) +{ + 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_; + Rect winRect = node->GetWindowProperty()->GetWindowRect(); + + if (needAvoid) { + dRect = limitRect_; + } else { + dRect = displayRect_; + } + + if (subWindow) { + pRect = node->parent_->GetLayoutRects().rect_; + } else { + pRect = dRect; + } + + 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)) { + 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(); + 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 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_; + 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_); +} + +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)); + UpdateLimitRect(node); + } else { // update existing avoid rect + limitRect_ = displayRect_; + aviodNodes_[id] = node; + for (auto item : aviodNodes_) { + 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 new file mode 100644 index 0000000000..f1f2da589e --- /dev/null +++ b/wmserver/src/window_manager_proxy.cpp @@ -0,0 +1,247 @@ +/* + * 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_proxy.h" +#include +#include "window_manager_hilog.h" + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowManagerProxy"}; +} + + +WMError WindowManagerProxy::CreateWindow(sptr& window, sptr& property, + const std::shared_ptr& surfaceNode, uint32_t& windowId) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("WriteInterfaceToken failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + + if (!data.WriteRemoteObject(window->AsObject())) { + WLOGFE("Write IWindow failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + + if (!data.WriteParcelable(property.GetRefPtr())) { + WLOGFE("Write windowProperty failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + + if (!data.WriteParcelable(surfaceNode.get())) { + WLOGFE("Write windowProperty failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + + if (Remote()->SendRequest(TRANS_ID_CREATE_WINDOW, data, reply, option) != ERR_NONE) { + return WMError::WM_ERROR_IPC_FAILED; + } + windowId = reply.ReadUint32(); + int32_t ret = reply.ReadInt32(); + return static_cast(ret); +} + +WMError WindowManagerProxy::AddWindow(sptr& property) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("WriteInterfaceToken failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + + if (!data.WriteParcelable(property.GetRefPtr())) { + WLOGFE("Write windowProperty failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + + if (Remote()->SendRequest(TRANS_ID_ADD_WINDOW, data, reply, option) != ERR_NONE) { + return WMError::WM_ERROR_IPC_FAILED; + } + + int32_t ret = reply.ReadInt32(); + return static_cast(ret); +} + +WMError WindowManagerProxy::RemoveWindow(uint32_t windowId) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("WriteInterfaceToken failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + + if (!data.WriteUint32(windowId)) { + WLOGFE("Write windowId failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + + if (Remote()->SendRequest(TRANS_ID_REMOVE_WINDOW, data, reply, option) != ERR_NONE) { + return WMError::WM_ERROR_IPC_FAILED; + } + + int32_t ret = reply.ReadInt32(); + return static_cast(ret); +} + +WMError WindowManagerProxy::DestroyWindow(uint32_t windowId) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("WriteInterfaceToken failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + + if (!data.WriteUint32(windowId)) { + WLOGFE("Write windowId failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + + if (Remote()->SendRequest(TRANS_ID_DESTROY_WINDOW, data, reply, option) != ERR_NONE) { + return WMError::WM_ERROR_IPC_FAILED; + } + + int32_t ret = reply.ReadInt32(); + return static_cast(ret); +} + +WMError WindowManagerProxy::MoveTo(uint32_t windowId, int32_t x, int32_t y) +{ + 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.WriteInt32(x)) { + WLOGFE("Write posX failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + + if (!data.WriteInt32(y)) { + WLOGFE("Write posY failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + + if (Remote()->SendRequest(TRANS_ID_MOVE, data, reply, option) != ERR_NONE) { + return WMError::WM_ERROR_IPC_FAILED; + } + + int32_t ret = reply.ReadInt32(); + return static_cast(ret); +} + +WMError WindowManagerProxy::Resize(uint32_t windowId, uint32_t width, uint32_t height) +{ + 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(width)) { + WLOGFE("Write width failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + + if (!data.WriteUint32(height)) { + WLOGFE("Write height failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + + if (Remote()->SendRequest(TRANS_ID_RESIZE, data, reply, option) != ERR_NONE) { + return WMError::WM_ERROR_IPC_FAILED; + } + + int32_t ret = reply.ReadInt32(); + return static_cast(ret); +} + +WMError WindowManagerProxy::RequestFocus(uint32_t windowId) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("WriteInterfaceToken failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + + if (!data.WriteUint32(windowId)) { + WLOGFE("Write windowId failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + if (Remote()->SendRequest(TRANS_ID_REQUEST_FOCUS, 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; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("WriteInterfaceToken failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + + if (!data.WriteRemoteObject(abilityToken)) { + WLOGFE("Write abilityToken failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + + if (!data.WriteUint32(windowId)) { + WLOGFE("Write windowId failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + + if (Remote()->SendRequest(TRANS_ID_SEND_ABILITY_TOKEN, data, reply, option) != ERR_NONE) { + return WMError::WM_ERROR_IPC_FAILED; + } + + int32_t ret = reply.ReadInt32(); + return static_cast(ret); +} +} +} + diff --git a/wmserver/src/window_manager_service.cpp b/wmserver/src/window_manager_service.cpp new file mode 100644 index 0000000000..7c70a580ba --- /dev/null +++ b/wmserver/src/window_manager_service.cpp @@ -0,0 +1,134 @@ +/* + * 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_service.h" + +#include + +#include +#include + +#include "window_manager_hilog.h" + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowManagerService"}; +} + +IMPLEMENT_SINGLE_INSTANCE(WindowManagerService); + +const bool REGISTER_RESULT = SystemAbility::MakeAndRegisterAbility( + SingletonContainer::Get().GetRefPtr()); + +WindowManagerService::WindowManagerService() : SystemAbility(WINDOW_MANAGER_SERVICE_ID, true) +{ + windowRoot_ = new WindowRoot(); + windowController_ = new WindowController(windowRoot_); + inputWindowMonitor_ = new InputWindowMonitor(windowRoot_); +} + +void WindowManagerService::OnStart() +{ + WLOGFI("WindowManagerService::OnStart start"); + if (!Init()) { + return; + } +} + +bool WindowManagerService::Init() +{ + WLOGFI("WindowManagerService::Init start"); + bool ret = Publish(this); + if (!ret) { + WLOGFW("WindowManagerService::Init failed"); + return false; + } + WLOGFI("WindowManagerService::Init success"); + sleep(10); // for RS temporary + return true; +} + +void WindowManagerService::OnStop() +{ + WLOGFI("ready to stop service."); +} + +WMError WindowManagerService::CreateWindow(sptr& window, sptr& property, + const std::shared_ptr& surfaceNode, uint32_t& windowId) +{ + if (window == nullptr || property == nullptr || surfaceNode == nullptr) { + WLOGFE("window is invalid"); + 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_); + WMError res = windowController_->AddWindowNode(property); + if (res == WMError::WM_OK) { + inputWindowMonitor_->UpdateInputWindow(property->GetWindowId()); + } + return res; +} + +WMError WindowManagerService::RemoveWindow(uint32_t windowId) +{ + std::lock_guard lock(mutex_); + WMError res = windowController_->RemoveWindowNode(windowId); + if (res == WMError::WM_OK) { + inputWindowMonitor_->UpdateInputWindow(windowId); + } + return res; +} + +WMError WindowManagerService::DestroyWindow(uint32_t windowId) +{ + std::lock_guard lock(mutex_); + WMError res = windowController_->DestroyWindow(windowId); + if (res == WMError::WM_OK) { + inputWindowMonitor_->UpdateInputWindow(windowId); + } + return res; +} + +WMError WindowManagerService::MoveTo(uint32_t windowId, int32_t x, int32_t y) +{ + 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_); + return windowController_->Resize(windowId, width, height); +} + +WMError WindowManagerService::RequestFocus(uint32_t windowId) +{ + std::lock_guard lock(mutex_); + return windowController_->RequestFocus(windowId); +} + +WMError WindowManagerService::SaveAbilityToken(const sptr& abilityToken, uint32_t windowId) +{ + std::lock_guard lock(mutex_); + return windowController_->SaveAbilityToken(abilityToken, windowId); +} +} +} \ No newline at end of file diff --git a/wmserver/src/window_manager_stub.cpp b/wmserver/src/window_manager_stub.cpp new file mode 100644 index 0000000000..cd18fed9f4 --- /dev/null +++ b/wmserver/src/window_manager_stub.cpp @@ -0,0 +1,101 @@ +/* + * 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_stub.h" +#include +#include "window_manager_hilog.h" + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowManagerStub"}; +} + +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; + } + switch (code) { + case TRANS_ID_CREATE_WINDOW: { + sptr windowObject = data.ReadRemoteObject(); + sptr windowProxy = iface_cast(windowObject); + sptr windowProperty = data.ReadStrongParcelable(); + std::shared_ptr surfaceNode(data.ReadParcelable()); + uint32_t windowId; + WMError errCode = CreateWindow(windowProxy, windowProperty, surfaceNode, windowId); + reply.WriteUint32(windowId); + reply.WriteInt32(static_cast(errCode)); + break; + } + case TRANS_ID_ADD_WINDOW: { + sptr windowProperty = data.ReadStrongParcelable(); + WMError errCode = AddWindow(windowProperty); + reply.WriteInt32(static_cast(errCode)); + break; + } + case TRANS_ID_REMOVE_WINDOW: { + uint32_t windowId = data.ReadUint32(); + WMError errCode = RemoveWindow(windowId); + reply.WriteInt32(static_cast(errCode)); + break; + } + case TRANS_ID_DESTROY_WINDOW: { + uint32_t windowId = data.ReadUint32(); + WMError errCode = DestroyWindow(windowId); + reply.WriteInt32(static_cast(errCode)); + break; + } + case TRANS_ID_MOVE: { + uint32_t windowId = data.ReadUint32(); + int32_t x = data.ReadInt32(); + int32_t y = data.ReadInt32(); + WMError errCode = MoveTo(windowId, x, y); + reply.WriteInt32(static_cast(errCode)); + break; + } + case TRANS_ID_RESIZE: { + uint32_t windowId = data.ReadUint32(); + uint32_t width = data.ReadUint32(); + uint32_t height = data.ReadUint32(); + WMError errCode = Resize(windowId, width, height); + reply.WriteInt32(static_cast(errCode)); + break; + } + case TRANS_ID_REQUEST_FOCUS: { + uint32_t windowId = data.ReadUint32(); + WMError errCode = RequestFocus(windowId); + reply.WriteInt32(static_cast(errCode)); + break; + } + + case TRANS_ID_SEND_ABILITY_TOKEN: { + sptr abilityToken = data.ReadRemoteObject(); + uint32_t windowId = data.ReadUint32(); + WMError errCode = SaveAbilityToken(abilityToken, windowId); + reply.WriteInt32(static_cast(errCode)); + break; + } + default: + WLOGFW("unknown transaction code"); + return IPCObjectStub::OnRemoteRequest(code, data, reply, option); + } + return 0; +} +} +} diff --git a/wmserver/src/window_node.cpp b/wmserver/src/window_node.cpp new file mode 100644 index 0000000000..389d4f3677 --- /dev/null +++ b/wmserver/src/window_node.cpp @@ -0,0 +1,86 @@ +/* + * 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_node.h" +#include "window_manager_hilog.h" + +namespace OHOS { +namespace Rosen { +void WindowNode::SetDisplayId(int32_t displayId) +{ + property_->SetDisplayId(displayId); +} + +void WindowNode::UpdateLayoutRects(const LayoutRects& rects) +{ + layoutRects_ = rects; +} + +void WindowNode::SetWindowProperty(const sptr& property) +{ + property_ = property; +} + +const sptr& WindowNode::GetWindowToken() const +{ + return windowToken_; +} + +int32_t WindowNode::GetDisplayId() const +{ + return property_->GetDisplayId(); +} + +uint32_t WindowNode::GetWindowId() const +{ + return property_->GetWindowId(); +} + +const LayoutRects& WindowNode::GetLayoutRects() const +{ + return layoutRects_; +} + +WindowType WindowNode::GetWindowType() const +{ + return property_->GetWindowType(); +} + +WindowMode WindowNode::GetWindowMode() const +{ + return property_->GetWindowMode(); +} + +uint32_t WindowNode::GetWindowFlags() const +{ + return property_->GetWindowFlags(); +} + +const sptr& WindowNode::GetWindowProperty() const +{ + return property_; +} + +int32_t WindowNode::GetCallingPid() const +{ + return callingPid_; +} + +int32_t WindowNode::GetCallingUid() const +{ + return callingUid_; +} +} +} diff --git a/wmserver/src/window_node_container.cpp b/wmserver/src/window_node_container.cpp new file mode 100644 index 0000000000..f4ed70a0c0 --- /dev/null +++ b/wmserver/src/window_node_container.cpp @@ -0,0 +1,366 @@ +/* + * 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_node_container.h" +#include +#include +#include "window_manager_hilog.h" + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowNodeContainer"}; +} + +WindowNodeContainer::~WindowNodeContainer() +{ + Destroy(); +} + +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"); + AAFwk::AbilityManagerClient::GetInstance()->MinimizeAbility((*iter)->abilityToken_); + } + } + return WMError::WM_OK; +} + +WMError WindowNodeContainer::AddWindowNode(sptr& node, sptr& parentNode) +{ + if (!node->surfaceNode_ || !displayNode_) { + WLOGFE("surface node or display node is nullptr!"); + return WMError::WM_ERROR_NULLPTR; + } + sptr root = FindRoot(node->GetWindowType()); + if (root == nullptr) { + WLOGFE("root window node is nullptr!"); + return WMError::WM_ERROR_NULLPTR; + } + node->requestedVisibility_ = true; + if (parentNode != nullptr) { // subwindow + if (parentNode->parent_ != root) { + WLOGFE("window type and parent window not match or try to add subwindow to subwindow, which is forbidden"); + return WMError::WM_ERROR_INVALID_PARAM; + } + node->currentVisibility_ = parentNode->currentVisibility_; + } else { // mainwindow + parentNode = root; + node->currentVisibility_ = true; + for (auto& child : node->children_) { + child->currentVisibility_ = child->requestedVisibility_; + } + } + node->parent_ = parentNode; + + UpdateWindowTree(node); + UpdateRSTree(node, true); + AssignZOrder(); + UpdateFocusWindow(); + WLOGFI("AddWindowNode windowId: %{public}d end", node->GetWindowId()); + return WMError::WM_OK; +} + +void WindowNodeContainer::UpdateWindowTree(sptr& node) +{ + node->priority_ = zorderPolicy_->GetWindowPriority(node->GetWindowType()); + auto parentNode = node->parent_; + auto position = parentNode->children_.end(); + for (auto iter = parentNode->children_.begin(); iter < parentNode->children_.end(); ++iter) { + if ((*iter)->priority_ > node->priority_) { + position = iter; + break; + } + } + parentNode->children_.insert(position, node); +} + +bool WindowNodeContainer::UpdateRSTree(sptr& node, bool isAdd) +{ + if (displayNode_ == nullptr) { + WLOGFE("displayNode_ is nullptr"); + return false; + } + if (isAdd) { + displayNode_->AddChild(node->surfaceNode_, -1); + for (auto& child : node->children_) { + if (child->currentVisibility_) { + displayNode_->AddChild(child->surfaceNode_, -1); + } + } + } else { + displayNode_->RemoveChild(node->surfaceNode_); + for (auto& child : node->children_) { + displayNode_->RemoveChild(child->surfaceNode_); + } + } + return true; +} + +WMError WindowNodeContainer::DestroyWindowNode(sptr& node, std::vector& windowIds) +{ + WMError ret = RemoveWindowNode(node); + if (ret != WMError::WM_OK) { + return ret; + } + node->surfaceNode_ = nullptr; + windowIds.push_back(node->GetWindowId()); + + for (auto& child : node->children_) { // destroy sub window if exists + windowIds.push_back(child->GetWindowId()); + child->parent_ = nullptr; + if (child->surfaceNode_ != nullptr && displayNode_ != nullptr) { + displayNode_->RemoveChild(child->surfaceNode_); + child->surfaceNode_ = nullptr; + } + } + 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_) { + WLOGFE("window node or surface node is nullptr, invalid"); + return WMError::WM_ERROR_DESTROYED_OBJECT; + } + + if (node->parent_ == nullptr) { + WLOGFW("can't find parent of this node"); + } else { + // remove this node from parent + auto iter = std::find(node->parent_->children_.begin(), node->parent_->children_.end(), node); + if (iter != node->parent_->children_.end()) { + node->parent_->children_.erase(iter); + } else { + WLOGFE("can't find this node in parent"); + } + node->parent_ = nullptr; + } + node->requestedVisibility_ = false; + node->currentVisibility_ = false; + for (auto& child : node->children_) { + child->currentVisibility_ = false; + } + UpdateRSTree(node, false); + UpdateFocusWindow(); + WLOGFI("RemoveWindowNode windowId: %{public}d end", node->GetWindowId()); + return WMError::WM_OK; +} + +const std::vector& WindowNodeContainer::Destroy() +{ + removedIds_.clear(); + for (auto& node : belowAppWindowNode_->children_) { + DestroyWindowNode(node, removedIds_); + } + for (auto& node : appWindowNode_->children_) { + DestroyWindowNode(node, removedIds_); + } + for (auto& node : aboveAppWindowNode_->children_) { + DestroyWindowNode(node, removedIds_); + } + displayNode_ = nullptr; + return removedIds_; +} + +sptr WindowNodeContainer::FindRoot(WindowType type) const +{ + if (type >= WindowType::APP_WINDOW_BASE && type <= WindowType::APP_SUB_WINDOW_END) { + return appWindowNode_; + } else if (type < WindowType::ABOVE_APP_SYSTEM_WINDOW_BASE) { + return belowAppWindowNode_; + } else { + return aboveAppWindowNode_; + } +} + +void WindowNodeContainer::UpdateFocusWindow() +{ + for (auto iter = appWindowNode_->children_.rbegin(); iter < appWindowNode_->children_.rend(); iter++) { + if ((*iter)->GetWindowProperty()->GetFocusable()) { + WLOGFI("find focused id %{public}d;", (*iter)->GetWindowId()); + SetFocusWindow((*iter)->GetWindowId()); + break; + } + } +} + +sptr WindowNodeContainer::FindWindowNodeById(uint32_t id) const +{ + std::vector> rootNodes = { aboveAppWindowNode_, appWindowNode_, belowAppWindowNode_ }; + for (auto& rootNode : rootNodes) { + for (auto& node : rootNode->children_) { + if (node->GetWindowId() == id) { + return node; + } + for (auto& subNode : node->children_) { + if (subNode->GetWindowId() == id) { + return subNode; + } + } + } + } + return nullptr; +} + +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); + } else { + node->GetWindowToken()->UpdateFocusStatus(focused); + } +} + +void WindowNodeContainer::AssignZOrder() +{ + zOrder_ = 0; + for (auto& node : belowAppWindowNode_->children_) { + AssignZOrder(node); + } + for (auto& node : appWindowNode_->children_) { + AssignZOrder(node); + } + for (auto& node : aboveAppWindowNode_->children_) { + AssignZOrder(node); + } +} + +void WindowNodeContainer::AssignZOrder(sptr& node) +{ + if (node == nullptr) { + return; + } + auto iter = node->children_.begin(); + for (; iter < node->children_.end(); ++iter) { + 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 { + break; + } + } + 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_; + } + } +} + +WMError WindowNodeContainer::SetFocusWindow(uint32_t windowId) +{ + if (focusedWindow_ == windowId) { + return WMError::WM_OK; + } + UpdateFocusStatus(focusedWindow_, false); + focusedWindow_ = windowId; + UpdateFocusStatus(focusedWindow_, true); + return WMError::WM_OK; +} + +uint32_t WindowNodeContainer::GetFocusWindow() const +{ + return focusedWindow_; +} + +void WindowNodeContainer::TraverseContainer(std::vector>& windowNodes) +{ + for (auto& node : belowAppWindowNode_->children_) { + TraverseWindowNode(node, windowNodes); + } + for (auto& node : appWindowNode_->children_) { + TraverseWindowNode(node, windowNodes); + } + for (auto& node : aboveAppWindowNode_->children_) { + TraverseWindowNode(node, windowNodes); + } + std::reverse(windowNodes.begin(), windowNodes.end()); +} + +void WindowNodeContainer::TraverseWindowNode(sptr& node, std::vector>& windowNodes) +{ + if (node == nullptr) { + return; + } + auto iter = node->children_.begin(); + for (; iter < node->children_.end(); ++iter) { + if ((*iter)->priority_ < 0) { + windowNodes.emplace_back(*iter); + } else { + break; + } + } + windowNodes.emplace_back(node); + for (; iter < node->children_.end(); ++iter) { + windowNodes.emplace_back(*iter); + } +} +} +} diff --git a/wmserver/src/window_root.cpp b/wmserver/src/window_root.cpp new file mode 100644 index 0000000000..ac62642792 --- /dev/null +++ b/wmserver/src/window_root.cpp @@ -0,0 +1,219 @@ +/* + * 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_root.h" +#include "display_manager_service_inner.h" +#include "window_manager_hilog.h" + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowRoot"}; +} +sptr WindowRoot::GetOrCreateWindowNodeContainer(int32_t displayId) +{ + auto iter = windowNodeContainerMap_.find(displayId); + if (iter != windowNodeContainerMap_.end()) { + return iter->second; + } + auto displayScreen = DisplayManagerServiceInner::GetInstance()->GetDisplayById(displayId); + if (displayScreen == 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())); + windowNodeContainerMap_.insert({ displayId, container }); + return container; +} + +const std::map>& WindowRoot::GetWindowNodeContainerMap() const +{ + return windowNodeContainerMap_; +} + +void WindowRoot::NotifyDisplayRemoved(int32_t displayId) +{ + auto container = GetOrCreateWindowNodeContainer(displayId); + if (container == nullptr) { + WLOGFI("this display does not have any window"); + return; + } + std::vector windowIds = container->Destroy(); + for (auto id : windowIds) { + auto node = GetWindowNode(id); + DestroyWindowInner(node); + } + windowNodeContainerMap_.erase(displayId); +} + +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; +} + +WMError WindowRoot::SaveWindow(const sptr& node) +{ + if (node == nullptr) { + WLOGFE("add window failed, node is nullptr"); + return WMError::WM_ERROR_NULLPTR; + } + WLOGFI("save windowId %{public}d", node->GetWindowId()); + windowNodeMap_.insert({ node->GetWindowId(), node }); + auto remoteObject = node->GetWindowToken()->AsObject(); + windowIdMap_.insert({ remoteObject, node->GetWindowId() }); + + if (windowDeath_ == nullptr) { + WLOGFI("failed to create death Recipient ptr WindowDeathRecipient"); + } + if (!remoteObject->AddDeathRecipient(windowDeath_)) { + WLOGFI("failed to add death recipient"); + } + return WMError::WM_OK; +} + +WMError WindowRoot::MinimizeOtherFullScreenAbility(sptr& node) +{ + auto container = GetOrCreateWindowNodeContainer(node->GetDisplayId()); + if (container == nullptr) { + WLOGFE("MinimizeAbility failed, window container could not be found"); + return WMError::WM_ERROR_NULLPTR; + } + return container->MinimizeOtherFullScreenAbility(); +} + +WMError WindowRoot::AddWindowNode(uint32_t parentId, sptr& node) +{ + if (node == nullptr) { + WLOGFE("add window failed, node is nullptr"); + return WMError::WM_ERROR_NULLPTR; + } + auto parentNode = GetWindowNode(parentId); + + 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->AddWindowNode(node, parentNode); +} + +WMError WindowRoot::RemoveWindowNode(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->RemoveWindowNode(node); +} + +WMError WindowRoot::DestroyWindow(uint32_t windowId) +{ + auto node = GetWindowNode(windowId); + if (node == nullptr) { + return WMError::WM_ERROR_DESTROYED_OBJECT; + } + WMError res; + auto container = GetOrCreateWindowNodeContainer(node->GetDisplayId()); + if (container != nullptr) { + std::vector windowIds; + res = container->DestroyWindowNode(node, windowIds); + for (auto id : windowIds) { + node = GetWindowNode(id); + DestroyWindowInner(node); + } + return res; + } + res = DestroyWindowInner(node); + WLOGFI("destroy window failed, window container could not be found"); + return res; +} + +WMError WindowRoot::DestroyWindowInner(sptr& node) +{ + if (node == nullptr) { + 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->AsObject() != nullptr) { + window->AsObject()->RemoveDeathRecipient(windowDeath_); + } + windowIdMap_.erase(window->AsObject()); + windowNodeMap_.erase(node->GetWindowId()); + return WMError::WM_OK; +} + +WMError WindowRoot::RequestFocus(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("window container could not be found"); + return WMError::WM_ERROR_NULLPTR; + } + return container->SetFocusWindow(windowId); +} + +void WindowRoot::ClearWindow(const sptr& remoteObject) +{ + auto iter = windowIdMap_.find(remoteObject); + if (iter == windowIdMap_.end()) { + WLOGFE("window id could not be found"); + return; + } + uint32_t windowId = iter->second; + DestroyWindow(windowId); +} + +void WindowDeathRecipient::OnRemoteDied(const wptr& wptrDeath) +{ + if (wptrDeath == nullptr) { + WLOGFE("wptrDeath is null"); + return; + } + + sptr object = wptrDeath.promote(); + if (!object) { + WLOGFE("object is null"); + return; + } + callback_(object); +} +} +} diff --git a/wmserver/src/window_zorder_policy.cpp b/wmserver/src/window_zorder_policy.cpp new file mode 100644 index 0000000000..1a41d6fb18 --- /dev/null +++ b/wmserver/src/window_zorder_policy.cpp @@ -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. + */ + +#include "window_manager_hilog.h" +#include "window_zorder_policy.h" + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowZorderPolicy"}; +} + +int32_t WindowZorderPolicy::GetWindowPriority(WindowType type) const +{ + if (windowPriorityMap_.count(type) == 0) { + WLOGFE("invalid window type"); + return windowPriorityMap_.at(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW); + } + return windowPriorityMap_.at(type); +} +} +} \ No newline at end of file diff --git a/wmtest/BUILD.gn b/wmtest/BUILD.gn new file mode 100644 index 0000000000..2d2d77b669 --- /dev/null +++ b/wmtest/BUILD.gn @@ -0,0 +1,84 @@ +# 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("//build/ohos.gni") + +## Build rosenwmtest {{{ +config("rosenwmtest_config") { + visibility = [ ":*" ] + + include_dirs = [ + "frameworks", + + # 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", + "//third_party/node/deps/icu-small/source/common", + "//foundation/aafwk/standard/interfaces/innerkits/ability_manager/include", + "//foundation/aafwk/standard/interfaces/innerkits/want/include/ohos/aafwk/content", + "//foundation/distributedschedule/dmsfwk/services/dtbschedmgr/include", + "//foundation/aafwk/standard/interfaces/innerkits/base/include", + + # RSSurface + "//foundation/graphic/standard/rosen/modules/render_service_client:librender_service_client", + "//foundation/graphic/standard/rosen/modules/render_service_base:librender_service_base", + ] + + cflags = [ + "-Wall", + "-Werror", + "-g3", + ] +} + +ohos_executable("rosenwmtest") { + install_enable = false + + sources = [ + "frameworks/inative_test.cpp", + "frameworks/main.cpp", + "test/dm_native_test.cpp", + "test/wm_native_test.cpp", + ] + + configs = [ ":rosenwmtest_config" ] + + deps = [ + "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", + "//foundation/graphic/standard:libvsync_client", + "//foundation/graphic/standard:libwmclient", + "//foundation/graphic/standard:libwmservice", + "//foundation/windowmanager/adapter:libwmadaptertest", + "//foundation/windowmanager/wm:libwm", + "//foundation/windowmanager/wm:libwmutil", + "//foundation/windowmanager/wmserver:libwms", + "//third_party/zlib:libz", + + # ace + # native value + "//foundation/ace/ace_engine/interfaces/innerkits/ace:ace_uicontent", + "//foundation/ace/napi:ace_napi", + ] + + part_name = "window_manager" + subsystem_name = "window" +} + +## Build rosenwmtest }}} + +group("test") { + testonly = true + + deps = [ "unittest:unittest" ] +} diff --git a/wmtest/README.en.md b/wmtest/README.en.md new file mode 100644 index 0000000000..996c312405 --- /dev/null +++ b/wmtest/README.en.md @@ -0,0 +1,36 @@ +# windowmanager + +#### Description +{**When you're done, you can delete the content in this README and update the file with details for others getting started with your repository**} + +#### Software Architecture +Software architecture description + +#### Installation + +1. xxxx +2. xxxx +3. xxxx + +#### Instructions + +1. xxxx +2. xxxx +3. xxxx + +#### Contribution + +1. Fork the repository +2. Create Feat_xxx branch +3. Commit your code +4. Create Pull Request + + +#### Gitee Feature + +1. You can use Readme\_XXX.md to support different languages, such as Readme\_en.md, Readme\_zh.md +2. Gitee blog [blog.gitee.com](https://blog.gitee.com) +3. Explore open source project [https://gitee.com/explore](https://gitee.com/explore) +4. The most valuable open source project [GVP](https://gitee.com/gvp) +5. The manual of Gitee [https://gitee.com/help](https://gitee.com/help) +6. The most popular members [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/) diff --git a/wmtest/README.md b/wmtest/README.md new file mode 100644 index 0000000000..098e283c85 --- /dev/null +++ b/wmtest/README.md @@ -0,0 +1,39 @@ +# windowmanager + +#### 介绍 +{**以下是 Gitee 平台说明,您可以替换此简介** +Gitee 是 OSCHINA 推出的基于 Git 的代码托管平台(同时支持 SVN)。专为开发者提供稳定、高效、安全的云端软件开发协作平台 +无论是个人、团队、或是企业,都能够用 Gitee 实现代码托管、项目管理、协作开发。企业项目请看 [https://gitee.com/enterprises](https://gitee.com/enterprises)} + +#### 软件架构 +软件架构说明 + + +#### 安装教程 + +1. xxxx +2. xxxx +3. xxxx + +#### 使用说明 + +1. xxxx +2. xxxx +3. xxxx + +#### 参与贡献 + +1. Fork 本仓库 +2. 新建 Feat_xxx 分支 +3. 提交代码 +4. 新建 Pull Request + + +#### 特技 + +1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md +2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com) +3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目 +4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目 +5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help) +6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/) diff --git a/wmtest/adapter/BUILD.gn b/wmtest/adapter/BUILD.gn new file mode 100644 index 0000000000..0efe554275 --- /dev/null +++ b/wmtest/adapter/BUILD.gn @@ -0,0 +1,98 @@ +# 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("//build/ohos.gni") + +## Build libwmadaptertest.so {{{ +config("libwmadaptertest_config") { + visibility = [ ":*" ] + + include_dirs = [ + "include", + "//utils/system/safwk/native/include", + "//foundation/windowmanager/wmserver/include", + "//foundation/windowmanager/interfaces/innerkits/wm", + "//foundation/windowmanager/wm/include", + "//foundation/windowmanager/utils/include", + "//foundation/graphic/standard/interfaces/innerkits/wmclient", + "//foundation/graphic/standard/interfaces/innerkits/common", + "//foundation/graphic/standard/interfaces/innerkits/surface", + + # 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", + "//third_party/node/deps/icu-small/source/common", + "//foundation/aafwk/standard/interfaces/innerkits/ability_manager/include", + "//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", + ] +} + +config("libwmadaptertest_public_config") { + include_dirs = [ + "//foundation/graphic/standard/interfaces/innerkits/wmclient", + "//foundation/windowmanager/interfaces/innerkits/wm", + "//foundation/multimodalinput/input/interfaces/native/innerkits/proxy/include", + "//foundation/multimodalinput/input/interfaces/native/innerkits/event/include", + "//foundation/multimodalinput/input/common/include", + ] +} + +ohos_shared_library("libwmadaptertest") { + sources = [ "src/adapter.cpp" ] + + configs = [ ":libwmadaptertest_config" ] + + public_configs = [ ":libwmadaptertest_public_config" ] + + deps = [ + "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog", + "//foundation/graphic/standard:libwmclient", + "//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", + + # native value + "//foundation/ace/napi:ace_napi", + + # ace + "//foundation/ace/ace_engine/interfaces/innerkits/ace:ace_uicontent", + + # aafwk + "//foundation/aafwk/standard/interfaces/innerkits/want:want", + ] + + public_deps = [ + "//foundation/communication/ipc/interfaces/innerkits/ipc_core:ipc_core", + "//foundation/graphic/standard:libsurface", + "//foundation/graphic/standard/utils:promise", + "//utils/native/base:utils", + + # IMS + "//foundation/multimodalinput/input/frameworks/proxy:libmmi-client", + "//foundation/multimodalinput/input/frameworks/proxy:libmmi-common", + ] + + part_name = "window_manager" + subsystem_name = "window" +} diff --git a/wmtest/adapter/include/adapter.h b/wmtest/adapter/include/adapter.h new file mode 100644 index 0000000000..c387a88d0f --- /dev/null +++ b/wmtest/adapter/include/adapter.h @@ -0,0 +1,63 @@ +/* + * 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_ADAPTER_H +#define OHOS_ROSEN_WINDOW_ADAPTER_H +#define _NEW_RENDERSERVER_ +#include +#include +#include +#include +#include +#include +#include +#include "foundation/windowmanager/interfaces/innerkits/wm/window_option.h" +#include "wm_common.h" +#include "window.h" +#include "foundation/graphic/standard/interfaces/innerkits/wmclient/window_option.h" +#include "window_manager.h" +#include "window_manager_hilog.h" + +namespace OHOS { +namespace Rosen { +class Adapter { +public: + Adapter(); + ~Adapter(); + + static WMError Init(); + static bool CreateWestonWindow(sptr& option); + static void DestroyWestonWindow(); + static bool GetMainWindowRect(OHOS::Rosen::Rect &rect); + static OHOS::Rosen::WMError Show(); + static OHOS::Rosen::WMError Hide(); + static OHOS::Rosen::WMError MoveTo(int32_t x, int32_t y); + static OHOS::Rosen::WMError Resize(uint32_t width, uint32_t height); + +private: + static bool WindowOptionConvertToWeston(sptr& option, + sptr& config); + static bool GetSurfaceBuffer(sptr &surface, + sptr &buffer, + OHOS::BufferRequestConfig &rconfig); + static void WriteDataToSurface(); + static void ColorDraw(void *vaddr, uint32_t width, uint32_t height, uint32_t count); + static void BlackDraw(void *vaddr, uint32_t width, uint32_t height, uint32_t count); + static void FlushDraw(void *vaddr, uint32_t width, uint32_t height, uint32_t count); + static void set(void *vaddr, char ch, size_t len); +}; +} +} +#endif // OHOS_ROSEN_WINDOW_ADAPTER_H diff --git a/wmtest/adapter/src/adapter.cpp b/wmtest/adapter/src/adapter.cpp new file mode 100644 index 0000000000..f705b49023 --- /dev/null +++ b/wmtest/adapter/src/adapter.cpp @@ -0,0 +1,327 @@ +/* + * 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 "adapter.h" +#include "window_impl.h" + +namespace OHOS { +namespace Rosen { + +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, 0, "Adapter" }; + +static inline sptr westonMainWindow_ = nullptr; + +Adapter::Adapter() +{ +} + +Adapter::~Adapter() +{ +} + +OHOS::Rosen::WMError Adapter::Init() +{ + // "AbilityWindow::Init()" + auto wmi = WindowManager::GetInstance(); + if (wmi == nullptr) { + WLOGFE("Adapter::Init WindowManager::GetInstance() is nullptr."); + return OHOS::Rosen::WMError::WM_ERROR_WINDOWMANAGER_GETINSTANCE; + } + + auto wret = wmi->Init(); + if (wret != OHOS::WM_OK) { + WLOGFE("Adapter::Init WindowManager::Init() return %d", wret); + return OHOS::Rosen::WMError::WM_ERROR_WINDOWMANAGER_INIT; + } + WLOGFI("%{public}s end.", __func__); + return OHOS::Rosen::WMError::WM_OK; +} + +bool Adapter::CreateWestonWindow(sptr& option) +{ + sptr config = OHOS::WindowOption::Get(); + if (!WindowOptionConvertToWeston(option, config)) { + WLOGFE("Adapter::CreateWindow convert windowOption fail"); + return false; + } + + auto wmi = OHOS::WindowManager::GetInstance(); + if (wmi == nullptr) { + WLOGFE("Adapter::ConvertToWindowOption WindowManager::GetInstance() is nullptr."); + return false; + } + + WLOGFI("%{public}s begin wms->CreateWindow.", __func__); + auto retvalCreate = wmi->CreateWindow(westonMainWindow_, config); + WLOGFI("%{public}s end wms->CreateWindow.", __func__); + + WriteDataToSurface(); + + if (retvalCreate != OHOS::WMError::WM_OK) { + WLOGFE("Adapter::ConvertToWindowOption WindowManager::CreateWindow() return %d", retvalCreate); + return false; + } + return true; +} + +void Adapter::DestroyWestonWindow() +{ + if (westonMainWindow_ != nullptr) { + OHOS::WMError err = westonMainWindow_->Destroy(); + westonMainWindow_ = nullptr; + if (err == OHOS::WMError::WM_OK) { + WLOGFI("DestroyWestonWindow OK"); + return; + } + WLOGFE("DestroyWestonWindow errorcode=%d", static_cast(err)); + } + WLOGFE("DestroyWestonWindow westonMainWindow_ is null"); +} + +bool Adapter::WindowOptionConvertToWeston(sptr& option, sptr& config) +{ + // window type + config->SetWindowType(OHOS::WindowType::WINDOW_TYPE_NORMAL); + config->SetWindowMode(OHOS::WindowMode::WINDOW_MODE_FULL); + return true; +} + +bool Adapter::GetMainWindowRect(OHOS::Rosen::Rect &rect) +{ + if (westonMainWindow_ == nullptr) { + return false; + } + rect.posX_ = westonMainWindow_->GetX(); + rect.posY_ = westonMainWindow_->GetY(); + rect.width_ = westonMainWindow_->GetWidth(); + rect.height_ = westonMainWindow_->GetHeight(); + return true; +} + +static inline bool hide = false; + +OHOS::Rosen::WMError Adapter::Show() +{ + if (westonMainWindow_ == nullptr) { + WLOGFE("Adapter::Show westonMainWindow_ is null"); + return OHOS::Rosen::WMError::WM_ERROR_WINDOWMANAGER_SHOW; + } + + if (!hide) { + auto promise = westonMainWindow_->Show(); + if (promise == nullptr) { + WLOGFE("Adapter::Show Show error"); + return OHOS::Rosen::WMError::WM_ERROR_WINDOWMANAGER_SHOW; + } + auto error = promise->Await(); + if (error != OHOS::WMError::WM_OK) { + WLOGFE("Adapter::Show Show error=%d", static_cast(error)); + return OHOS::Rosen::WMError::WM_ERROR_WINDOWMANAGER_SHOW; + } + } + + auto promise2 = westonMainWindow_->SwitchTop(); + if (promise2 == nullptr) { + WLOGFE("Adapter::Show SwitchTop error"); + return OHOS::Rosen::WMError::WM_ERROR_WINDOWMANAGER_SHOW; + } + auto error2 = promise2->Await(); + if (error2 != OHOS::WMError::WM_OK) { + WLOGFE("Adapter::Show SwitchTop error=%d", static_cast(error2)); + return OHOS::Rosen::WMError::WM_ERROR_WINDOWMANAGER_SHOW; + } + + return OHOS::Rosen::WMError::WM_OK; +} + +void Adapter::WriteDataToSurface() +{ + /* write data to surface */ + sptr surface = westonMainWindow_->GetSurface(); + sptr buffer; + BufferRequestConfig rconfig; + if (GetSurfaceBuffer(surface, buffer, rconfig)) { + BlackDraw(buffer->GetVirAddr(), rconfig.width, rconfig.height, 1); + } else { + WLOGFE("Adapter::WriteDataToSurface GetSurfaceBuffer fail"); + } + BufferFlushConfig fconfig = { + .damage = { + .w = rconfig.width, + .h = rconfig.height, + }, + }; + surface->FlushBuffer(buffer, -1, fconfig); +} + +OHOS::Rosen::WMError Adapter::Hide() +{ + if (westonMainWindow_ == nullptr) { + WLOGFE("Adapter::Hide westonMainWindow_ is null"); + return OHOS::Rosen::WMError::WM_ERROR_WINDOWMANAGER_HIDE; + } + auto promise = westonMainWindow_->Hide(); + if (promise == nullptr) { + WLOGFE("Adapter::Hide Hide error"); + return OHOS::Rosen::WMError::WM_ERROR_WINDOWMANAGER_HIDE; + } + auto error = promise->Await(); + if (error != OHOS::WMError::WM_OK) { + WLOGFE("Adapter::Hide Hide error=%d", static_cast(error)); + return OHOS::Rosen::WMError::WM_ERROR_WINDOWMANAGER_HIDE; + } + hide = true; + return OHOS::Rosen::WMError::WM_OK; +} + +OHOS::Rosen::WMError Adapter::MoveTo(int32_t x, int32_t y) +{ + if (westonMainWindow_ == nullptr) { + WLOGFE("Adapter::MoveTo westonMainWindow_ is null"); + return OHOS::Rosen::WMError::WM_ERROR_WINDOWMANAGER_MOVE; + } + auto promise = westonMainWindow_->Move(x, y); + if (promise == nullptr) { + WLOGFE("Adapter::MoveTo promise is null"); + return OHOS::Rosen::WMError::WM_ERROR_WINDOWMANAGER_MOVE; + } + return OHOS::Rosen::WMError::WM_OK; +} + +OHOS::Rosen::WMError Adapter::Resize(uint32_t width, uint32_t height) +{ + if (westonMainWindow_ == nullptr) { + WLOGFE("Adapter::Resize westonMainWindow_ is null"); + return OHOS::Rosen::WMError::WM_ERROR_WINDOWMANAGER_RESIZE; + } + auto promise = westonMainWindow_->Resize(width, height); + if (promise == nullptr) { + WLOGFE("Adapter::Resize promise is null"); + return OHOS::Rosen::WMError::WM_ERROR_WINDOWMANAGER_RESIZE; + } + return OHOS::Rosen::WMError::WM_OK; +} + +bool Adapter::GetSurfaceBuffer(sptr &surface, sptr &buffer, BufferRequestConfig &rconfig) +{ + int32_t releaseFence; + rconfig = { + .width = surface->GetDefaultWidth(), + .height = surface->GetDefaultHeight(), + .strideAlignment = 0x8, + .format = 12, // PIXEL_FMT_RGBA_8888, + .usage = surface->GetDefaultUsage(), + .timeout = 0, + }; + OHOS::SurfaceError ret = surface->RequestBuffer(buffer, releaseFence, rconfig); + if (ret == 40601000) { // OHOS::SurfaceError::SURFACE_ERROR_NO_BUFFER + WLOGFE("Adapter::GetSurfaceBuffer RequestBuffer error=%d", static_cast(ret)); + return false; + } else if (ret != 0) { // OHOS::SurfaceError::SURFACE_ERROR_OK + WLOGFE("Adapter::GetSurfaceBuffer RequestBuffer is NG error=%d", static_cast(ret)); + return false; + } else if (buffer == nullptr) { + WLOGFE("Adapter::GetSurfaceBuffer buffer is nullptr"); + return false; + } + return true; +} + +void Adapter::ColorDraw(void *vaddr, uint32_t width, uint32_t height, uint32_t count) +{ + auto addr = static_cast(vaddr); + if (addr == nullptr) { + return; + } + + constexpr uint32_t wdiv = 2; + constexpr uint32_t colorTable[][wdiv] = { + {0xffff0000, 0xffff00ff}, + {0xffff0000, 0xffffff00}, + {0xff00ff00, 0xffffff00}, + {0xff00ff00, 0xff00ffff}, + {0xff0000ff, 0xff00ffff}, + {0xff0000ff, 0xffff00ff}, + {0xff777777, 0xff777777}, + {0xff777777, 0xff777777}, + }; + const uint32_t hdiv = sizeof(colorTable) / sizeof(*colorTable); + + for (uint32_t i = 0; i < height; i++) { + auto table = colorTable[i / (height / hdiv)]; + for (uint32_t j = 0; j < wdiv; j++) { + auto color = table[j]; + for (uint32_t k = j * width / wdiv; k < (j + 1) * width / wdiv; k++) { + addr[i * width + k] = color; + } + } + } +} + +void Adapter::BlackDraw(void *vaddr, uint32_t width, uint32_t height, uint32_t count) +{ + auto addr = static_cast(vaddr); + if (addr == nullptr) { + return; + } + + for (uint32_t i = 0; i < width * height; i++) { + addr[i] = 0xff00ff00; + } +} + +void Adapter::FlushDraw(void *vaddr, uint32_t width, uint32_t height, uint32_t count) +{ + auto addr = static_cast(vaddr); + if (addr == nullptr) { + return; + } + + constexpr uint32_t bpp = 4; + constexpr uint32_t color1 = 0xff / 3 * 0; + constexpr uint32_t color2 = 0xff / 3 * 1; + constexpr uint32_t color3 = 0xff / 3 * 2; + constexpr uint32_t color4 = 0xff / 3 * 3; + constexpr uint32_t bigDiv = 7; + constexpr uint32_t smallDiv = 10; + uint32_t c = count % (bigDiv * smallDiv); + uint32_t stride = width * bpp; + uint32_t beforeCount = height * c / bigDiv / smallDiv; + uint32_t afterCount = height - beforeCount - 1; + + size_t len = ((stride * height) < (beforeCount * stride) ? (stride * height) : (beforeCount * stride)); + set(addr, color3, len); + + len = ((stride * height) < (afterCount * stride) ? (stride * height) : (afterCount * stride)); + set(addr + (beforeCount + 1) * stride, color1, len); + + for (uint32_t i = 0; i < bigDiv; i++) { + len = ((stride * height) < (stride) ? (stride * height) : (stride)); + set(addr + (i * height / bigDiv) * stride, color4, len); + } + + len = ((stride * height) < (stride) ? (stride * height) : (stride)); + set(addr + beforeCount * stride, color2, len); +} + +void Adapter::set(void *vaddr, char ch, size_t len) +{ + char *ptr = static_cast(vaddr); + for (size_t i = 0; i < len; i++) { + ptr[i] = ch; + } +} +} +} diff --git a/wmtest/dm/include/README.md b/wmtest/dm/include/README.md new file mode 100644 index 0000000000..bda91e7389 --- /dev/null +++ b/wmtest/dm/include/README.md @@ -0,0 +1 @@ +Store code of display client inner header files diff --git a/wmtest/dm/include/display_manager_adapter.h b/wmtest/dm/include/display_manager_adapter.h new file mode 100644 index 0000000000..61882fd0db --- /dev/null +++ b/wmtest/dm/include/display_manager_adapter.h @@ -0,0 +1,54 @@ +/* + * 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_DM_DISPLAY_MANAGER_ADAPTER_H +#define FOUNDATION_DM_DISPLAY_MANAGER_ADAPTER_H + +#include +#include + +#include "display.h" +#include "display_manager_interface.h" +#include "single_instance.h" +#include "singleton_delegator.h" + +namespace OHOS::Rosen { +class DMSDeathRecipient : public IRemoteObject::DeathRecipient { +public: + virtual void OnRemoteDied(const wptr& wptrDeath) override; +}; + +class DisplayManagerAdapter : public RefBase { + DECLARE_SINGLE_INSTANCE_BASE(DisplayManagerAdapter); +public: + sptr GetDisplay(DisplayType type); + DisplayId GetDefaultDisplayId(); + sptr GetDisplayById(DisplayId displayId); + + void Clear(); +private: + DisplayManagerAdapter() = default; + ~DisplayManagerAdapter() = default; + bool InitDMSProxyLocked(); + static inline SingletonDelegator delegator; + + std::mutex mutex_; + sptr displayManagerServiceProxy_ = nullptr; + sptr dmsDeath_ = nullptr; + std::map> displayMap_; + DisplayId defaultDisplayId_; +}; +} // namespace OHOS::Rosen +#endif // FOUNDATION_DM_DISPLAY_MANAGER_ADAPTER_H diff --git a/wmtest/dm/src/README.md b/wmtest/dm/src/README.md new file mode 100644 index 0000000000..8eb6cfc677 --- /dev/null +++ b/wmtest/dm/src/README.md @@ -0,0 +1 @@ +Store code of display source files diff --git a/wmtest/dm/src/display.cpp b/wmtest/dm/src/display.cpp new file mode 100644 index 0000000000..73655b9404 --- /dev/null +++ b/wmtest/dm/src/display.cpp @@ -0,0 +1,68 @@ +/* + * 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.h" +#include "display_info.h" + +namespace OHOS::Rosen { +Display::Display(const std::string& name, DisplayInfo* info) + : name_(name), + id_(info->id_), + width_(info->width_), + height_(info->height_), + freshRate_(info->freshRate_) +{ +} + +DisplayId Display::GetId() const +{ + return id_; +} + +int32_t Display::GetWidth() const +{ + return width_; +} + +int32_t Display::GetHeight() const +{ + return height_; +} + +uint32_t Display::GetFreshRate() const +{ + return freshRate_; +} + +void Display::SetWidth(int32_t width) +{ + width_ = width; +} + +void Display::SetHeight(int32_t height) +{ + height_ = height; +} + +void Display::SetFreshRate(uint32_t freshRate) +{ + freshRate_ = freshRate; +} + +void Display::SetId(DisplayId id) +{ + id_ = id; +} +} // namespace OHOS::Rosen \ No newline at end of file diff --git a/wmtest/dm/src/display_manager.cpp b/wmtest/dm/src/display_manager.cpp new file mode 100644 index 0000000000..57b8ac1b0a --- /dev/null +++ b/wmtest/dm/src/display_manager.cpp @@ -0,0 +1,97 @@ +/* + * 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_manager.h" +#include "display_manager_adapter.h" +#include "window_manager_hilog.h" + +namespace OHOS::Rosen { +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(); +} + +const sptr DisplayManager::GetDisplayById(DisplayId displayId) +{ + if (dmsAdapter_ == nullptr) { + WLOGFE("DisplayManager::GetDisplayById null!\n"); + return nullptr; + } + + sptr display = dmsAdapter_->GetDisplayById(displayId); + if (display == nullptr) { + WLOGFE("DisplayManager::GetDisplayById failed!\n"); + return nullptr; + } + return display; +} + + +const sptr DisplayManager::GetDefaultDisplay() +{ + return GetDisplayById(GetDefaultDisplayId()); +} + +std::vector DisplayManager::GetAllDisplayIds() +{ + std::vector res; + res.push_back(GetDefaultDisplayId()); + // 获取所有displayIds + return res; +} + +std::vector> DisplayManager::GetAllDisplays() +{ + std::vector> res; + auto displayIds = GetAllDisplayIds(); + for (auto displayId: displayIds) { + const sptr display = GetDisplayById(displayId); + if (display != nullptr) { + res.push_back(display); + } else { + WLOGFE("DisplayManager::GetAllDisplays display %llu nullptr!", displayId); + } + } + return res; +} +} // namespace OHOS::Rosen \ No newline at end of file diff --git a/wmtest/dm/src/display_manager_adapter.cpp b/wmtest/dm/src/display_manager_adapter.cpp new file mode 100644 index 0000000000..675bb97b8b --- /dev/null +++ b/wmtest/dm/src/display_manager_adapter.cpp @@ -0,0 +1,143 @@ +/* + * 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_manager_adapter.h" + +#include +#include +#include + +#include "window_manager_hilog.h" +#include "wm_common.h" + +namespace OHOS::Rosen { +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_); + + if (defaultDisplayId_ != DISPLAY_ID_INVALD) { + return defaultDisplayId_; + } + + if (!InitDMSProxyLocked()) { + WLOGFE("displayManagerAdapter::GetDefaultDisplayId: InitDMSProxyLocked failed!"); + return DISPLAY_ID_INVALD; + } + defaultDisplayId_ = displayManagerServiceProxy_->GetDefaultDisplayId(); + return defaultDisplayId_; +} + +sptr DisplayManagerAdapter::GetDisplayById(DisplayId displayId) +{ + std::lock_guard lock(mutex_); + + auto iter = displayMap_.find(displayId); + if (iter != displayMap_.end()) { + return iter->second; + } + + if (!InitDMSProxyLocked()) { + WLOGFE("displayManagerAdapter::GetDisplayById: InitDMSProxyLocked failed!"); + return nullptr; + } + DisplayInfo displayInfo = displayManagerServiceProxy_->GetDisplayInfoById(displayId); + sptr display = new Display("", &displayInfo); + if (display->GetId() != DISPLAY_ID_INVALD) { + displayMap_[display->GetId()] = display; + } + return display; +} + +bool DisplayManagerAdapter::InitDMSProxyLocked() +{ + WLOGFI("InitDMSProxy"); + if (!displayManagerServiceProxy_) { + sptr systemAbilityManager = + SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (!systemAbilityManager) { + WLOGFE("Failed to get system ability mgr."); + return false; + } + + sptr remoteObject + = systemAbilityManager->GetSystemAbility(DISPLAY_MANAGER_SERVICE_SA_ID); + if (!remoteObject) { + WLOGFE("Failed to get display manager service."); + return false; + } + + displayManagerServiceProxy_ = iface_cast(remoteObject); + if ((!displayManagerServiceProxy_) || (!displayManagerServiceProxy_->AsObject())) { + WLOGFE("Failed to get system display manager services"); + return false; + } + + dmsDeath_ = new DMSDeathRecipient(); + if (!dmsDeath_) { + WLOGFE("Failed to create death Recipient ptr DMSDeathRecipient"); + return false; + } + if (!remoteObject->AddDeathRecipient(dmsDeath_)) { + WLOGFE("Failed to add death recipient"); + return false; + } + } + return true; +} + +void DMSDeathRecipient::OnRemoteDied(const wptr& wptrDeath) +{ + if (wptrDeath == nullptr) { + WLOGFE("wptrDeath is null"); + return; + } + + sptr object = wptrDeath.promote(); + if (!object) { + WLOGFE("object is null"); + return; + } + SingletonContainer::Get().GetRefPtr()->Clear(); + return; +} + +void DisplayManagerAdapter::Clear() +{ + std::lock_guard lock(mutex_); + if ((displayManagerServiceProxy_ != nullptr) && (displayManagerServiceProxy_->AsObject() != nullptr)) { + displayManagerServiceProxy_->AsObject()->RemoveDeathRecipient(dmsDeath_); + } + displayManagerServiceProxy_ = nullptr; +} +} // namespace OHOS::Rosen \ No newline at end of file diff --git a/wmtest/dm/src/monitor.cpp b/wmtest/dm/src/monitor.cpp new file mode 100644 index 0000000000..ca8933d58b --- /dev/null +++ b/wmtest/dm/src/monitor.cpp @@ -0,0 +1,19 @@ +/* + * 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 "monitor.h" + +namespace OHOS::Rosen { +} // namespace OHOS::Rosen \ No newline at end of file diff --git a/wmtest/dmserver/include/README.md b/wmtest/dmserver/include/README.md new file mode 100644 index 0000000000..92b3669bdd --- /dev/null +++ b/wmtest/dmserver/include/README.md @@ -0,0 +1 @@ +Store code of display manager service inner header files diff --git a/wmtest/dmserver/include/display_info.h b/wmtest/dmserver/include/display_info.h new file mode 100644 index 0000000000..72edc10998 --- /dev/null +++ b/wmtest/dmserver/include/display_info.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 p ermissions and + * limitations under the License. + */ + +#ifndef FOUNDATION_DMSERVER_DISPLAY_INFO_H +#define FOUNDATION_DMSERVER_DISPLAY_INFO_H + +#include + +#include "display.h" + +namespace OHOS::Rosen { +class DisplayInfo : public Parcelable { +public: + DisplayInfo() = default; + ~DisplayInfo() = default; + + void Update(DisplayInfo* info); + + virtual bool Marshalling(Parcel& parcel) const override; + static DisplayInfo *Unmarshalling(Parcel& parcel); + + DisplayId id_ {DISPLAY_ID_INVALD}; + DisplayType type_ {DisplayType::DEFAULT}; + int32_t width_ {0}; + int32_t height_ {0}; + uint32_t freshRate_ {0}; + float xDpi_ {0.0}; + float yDpi_ {0.0}; +}; +} // namespace OHOS::Rosen +#endif // FOUNDATION_DMSERVER_DISPLAY_INFO_H \ No newline at end of file diff --git a/wmtest/dmserver/include/display_manager_interface.h b/wmtest/dmserver/include/display_manager_interface.h new file mode 100644 index 0000000000..8a7d71fc5e --- /dev/null +++ b/wmtest/dmserver/include/display_manager_interface.h @@ -0,0 +1,41 @@ +/* + * 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_DMSERVER_DISPLAY_MANAGER_INTERFACE_H +#define FOUNDATION_DMSERVER_DISPLAY_MANAGER_INTERFACE_H + +#include + +#include "display_info.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, + }; + + virtual const sptr& GetDisplayInfo(const DisplayType type) = 0; + + virtual DisplayId GetDefaultDisplayId() = 0; + virtual DisplayInfo GetDisplayInfoById(DisplayId displayId) = 0; +}; +} // namespace OHOS::Rosen + +#endif // FOUNDATION_DMSERVER_DISPLAY_MANAGER_INTERFACE_H \ No newline at end of file diff --git a/wmtest/dmserver/include/display_manager_proxy.h b/wmtest/dmserver/include/display_manager_proxy.h new file mode 100644 index 0000000000..519107124d --- /dev/null +++ b/wmtest/dmserver/include/display_manager_proxy.h @@ -0,0 +1,39 @@ +/* + * 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_DMSERVER_DISPLAY_MANAGER_PROXY_H +#define FOUNDATION_DMSERVER_DISPLAY_MANAGER_PROXY_H + +#include "display_manager_interface.h" + +#include + +namespace OHOS::Rosen { +class DisplayManagerProxy : public IRemoteProxy { +public: + explicit DisplayManagerProxy(const sptr &impl) + : IRemoteProxy(impl) {}; + ~DisplayManagerProxy() {}; + + const sptr& GetDisplayInfo(const DisplayType type) override; + + DisplayId GetDefaultDisplayId() override; + DisplayInfo GetDisplayInfoById(DisplayId displayId) override; +private: + static inline BrokerDelegator delegator_; +}; +} // namespace OHOS::Rosen + +#endif // FOUNDATION_DMSERVER_DISPLAY_MANAGER_PROXY_H \ No newline at end of file diff --git a/wmtest/dmserver/include/display_manager_service.h b/wmtest/dmserver/include/display_manager_service.h new file mode 100644 index 0000000000..83ffbbe94a --- /dev/null +++ b/wmtest/dmserver/include/display_manager_service.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 FOUNDATION_DMSERVER_DISPLAY_MANAGER_SERVICE_H +#define FOUNDATION_DMSERVER_DISPLAY_MANAGER_SERVICE_H + +#include +#include + +#include + +#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 { +DECLARE_SYSTEM_ABILITY(DisplayManagerService); + +DECLARE_SINGLE_INSTANCE_BASE(DisplayManagerService); + +public: + void OnStart() override; + void OnStop() override; + const sptr& GetDisplayInfo(const DisplayType type) override; + + DisplayId GetDefaultDisplayId() override; + DisplayInfo GetDisplayInfoById(DisplayId displayId) override; + +private: + DisplayManagerService(); + ~DisplayManagerService() = default; + bool Init(); + DisplayId GetDisplayIdFromScreenId(ScreenId screenId); + ScreenId GetScreenIdFromDisplayId(DisplayId displayId); + + static inline SingletonDelegator delegator_; + std::map> displayScreenMap_; + sptr displayScreenManager_; +}; +} // namespace OHOS::Rosen + +#endif // FOUNDATION_DMSERVER_DISPLAY_MANAGER_SERVICE_H \ No newline at end of file diff --git a/wmtest/dmserver/include/display_manager_service_inner.h b/wmtest/dmserver/include/display_manager_service_inner.h new file mode 100644 index 0000000000..6051c80443 --- /dev/null +++ b/wmtest/dmserver/include/display_manager_service_inner.h @@ -0,0 +1,39 @@ +/* + * 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_DMSERVER_DISPLAY_MANAGER_SERVICE_INNER_H +#define FOUNDATION_DMSERVER_DISPLAY_MANAGER_SERVICE_INNER_H + +#include +#include + +#include "display_screen.h" +#include "single_instance.h" +#include "singleton_delegator.h" + +namespace OHOS::Rosen { +class DisplayManagerServiceInner : public RefBase { +DECLARE_SINGLE_INSTANCE(DisplayManagerServiceInner); + +public: + std::vector> GetAllDisplays(); + DisplayId GetDefaultDisplayId(); + const sptr GetDefaultDisplay(); + const sptr GetDisplayById(DisplayId displayId); + std::vector GetAllDisplayIds(); +}; +} // namespace OHOS::Rosen + +#endif // FOUNDATION_DMSERVER_DISPLAY_MANAGER_SERVICE_H \ No newline at end of file diff --git a/wmtest/dmserver/include/display_manager_stub.h b/wmtest/dmserver/include/display_manager_stub.h new file mode 100644 index 0000000000..d88c4a0c65 --- /dev/null +++ b/wmtest/dmserver/include/display_manager_stub.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 FOUNDATION_DMSERVER_DISPLAY_MANAGER_STUB_H +#define FOUNDATION_DMSERVER_DISPLAY_MANAGER_STUB_H + +#include "display_manager_interface.h" + +#include + +namespace OHOS::Rosen { +class DisplayManagerStub : public IRemoteStub { +public: + DisplayManagerStub() = default; + ~DisplayManagerStub() = default; + virtual int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, + MessageOption &option) override; +}; +} // namespace OHOS::Rosen + +#endif // FOUNDATION_DMSERVER_DISPLAY_MANAGER_STUB_H \ No newline at end of file diff --git a/wmtest/dmserver/include/display_node_control.h b/wmtest/dmserver/include/display_node_control.h new file mode 100644 index 0000000000..5da96a2081 --- /dev/null +++ b/wmtest/dmserver/include/display_node_control.h @@ -0,0 +1,25 @@ +/* + * 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_DMSERVER_DISPLAY_NODE_CONTROL_H +#define FOUNDATION_DMSERVER_DISPLAY_NODE_CONTROL_H + +#include + +namespace OHOS::Rosen { +class DisplayNodeControl : public RefBase { +}; +} // namespace OHOS::Rosen +#endif // FOUNDATION_DMSERVER_DISPLAY_NODE_CONTROL_H \ No newline at end of file diff --git a/wmtest/dmserver/include/display_screen.h b/wmtest/dmserver/include/display_screen.h new file mode 100644 index 0000000000..d656621953 --- /dev/null +++ b/wmtest/dmserver/include/display_screen.h @@ -0,0 +1,45 @@ +/* + * 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_DMSERVER_DISPLAY_SCREEN_H +#define FOUNDATION_DMSERVER_DISPLAY_SCREEN_H + +#include +#include "display_info.h" + +namespace OHOS::Rosen { +class DisplayScreen : public RefBase { +public: + DisplayScreen(const DisplayInfo& info); + ~DisplayScreen() = default; + + DisplayId GetId() const; + int32_t GetWidth() const; + int32_t GetHeight() const; + uint32_t GetFreshRate() const; + + void SetId(DisplayId displayId); + void SetWidth(int32_t width); + void SetHeight(int32_t height); + void SetFreshRate(uint32_t freshRate); + +private: + DisplayId id_ {DISPLAY_ID_INVALD}; + int32_t width_ {0}; + int32_t height_ {0}; + uint32_t freshRate_ {0}; +}; +} // namespace OHOS::Rosen +#endif // FOUNDATION_DMSERVER_DISPLAY_SCREEN_H \ No newline at end of file diff --git a/wmtest/dmserver/include/display_screen_manager.h b/wmtest/dmserver/include/display_screen_manager.h new file mode 100644 index 0000000000..0c1df9b379 --- /dev/null +++ b/wmtest/dmserver/include/display_screen_manager.h @@ -0,0 +1,44 @@ +/* + * 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_DMSERVER_DISPLAY_SCREEN_MANAGER_H +#define FOUNDATION_DMSERVER_DISPLAY_SCREEN_MANAGER_H + +#include +#include + +#include "display_screen.h" +#include "single_instance.h" +#include "transaction/rs_interfaces.h" + +namespace OHOS::Rosen { +class DisplayScreenManager : public RefBase { +DECLARE_SINGLE_INSTANCE_BASE(DisplayScreenManager); +public: + std::map> displayScreenMap_; + + ScreenId GetDefaultScreenId(); + RSScreenModeInfo GetScreenActiveMode(ScreenId id); + +private: + DisplayScreenManager(); + ~DisplayScreenManager(); + void parepareRSScreenManger(); + + OHOS::Rosen::RSInterfaces *rsInterface_; +}; + +} // namespace OHOS::Rosen +#endif // FOUNDATION_DMSERVER_DISPLAY_SCREEN_MANAGER_H \ No newline at end of file diff --git a/wmtest/dmserver/include/rs_adapter.h b/wmtest/dmserver/include/rs_adapter.h new file mode 100644 index 0000000000..9f19e344c9 --- /dev/null +++ b/wmtest/dmserver/include/rs_adapter.h @@ -0,0 +1,48 @@ +/* + * 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_DMSERVER_RS_ADAPTER_H +#define FOUNDATION_DMSERVER_RS_ADAPTER_H + +#include +#include + +#include + +#include "single_instance.h" + +namespace OHOS::Rosen { +class DMSDeathRecipient : public IRemoteObject::DeathRecipient { +public: + virtual void OnRemoteDied(const wptr& wptrDeath) override; +private: + sptr& rsAdatper_; +}; + +class RsAdapter : public RefBase { + DECLARE_SINGLE_INSTANCE_BASE(RsAdapter); +public: + void Clear(); +private: + RsAdapter() = default; + ~RsAdapter() = default; + bool InitRSProxyLocked(); + + std::mutex mutex_; + sptr rsProxy_ = nullptr; + sptr rsDeath_ = nullptr; +}; +} // namespace OHOS::Rosen +#endif // FOUNDATION_DMSERVER_RS_ADAPTER_H diff --git a/wmtest/dmserver/include/screen.h b/wmtest/dmserver/include/screen.h new file mode 100644 index 0000000000..bbe436d55b --- /dev/null +++ b/wmtest/dmserver/include/screen.h @@ -0,0 +1,25 @@ +/* + * 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_DMSERVER_SCREEN_H +#define FOUNDATION_DMSERVER_SCREEN_H + +#include + +namespace OHOS::Rosen { +class Screen : public RefBase { +}; +} // namespace OHOS::Rosen +#endif // FOUNDATION_DMSERVER_SCREEN_H \ No newline at end of file diff --git a/wmtest/dmserver/src/README.md b/wmtest/dmserver/src/README.md new file mode 100644 index 0000000000..acfe633cd7 --- /dev/null +++ b/wmtest/dmserver/src/README.md @@ -0,0 +1 @@ +Store code of display manager service source files diff --git a/wmtest/dmserver/src/display_info.cpp b/wmtest/dmserver/src/display_info.cpp new file mode 100644 index 0000000000..e26ebf2f44 --- /dev/null +++ b/wmtest/dmserver/src/display_info.cpp @@ -0,0 +1,56 @@ +/* + * 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_info.h" + +namespace OHOS::Rosen { +void DisplayInfo::Update(DisplayInfo* info) +{ + id_ = info->id_; + type_ = info->type_; + width_ = info->width_; + height_ = info->height_; + freshRate_ = info->freshRate_; + xDpi_ = info->xDpi_; + yDpi_ = info->yDpi_; +} + +bool DisplayInfo::Marshalling(Parcel &parcel) const +{ + return parcel.WriteUint64(id_) && parcel.WriteUint32(type_) && + parcel.WriteInt32(width_) && parcel.WriteInt32(height_) && + parcel.WriteUint32(freshRate_) && + parcel.WriteFloat(xDpi_) && parcel.WriteFloat(yDpi_); +} + +DisplayInfo *DisplayInfo::Unmarshalling(Parcel &parcel) +{ + DisplayInfo *displayInfo = new DisplayInfo(); + if (displayInfo == nullptr) { + return nullptr; + } + uint32_t type = (uint32_t)DisplayType::DEFAULT; + bool res = parcel.ReadUint64(displayInfo->id_) && parcel.ReadUint32(type) && + parcel.ReadInt32(displayInfo->width_) && parcel.ReadInt32(displayInfo->height_) && + parcel.ReadUint32(displayInfo->freshRate_) && + parcel.ReadFloat(displayInfo->xDpi_) && parcel.ReadFloat(displayInfo->yDpi_); + if (!res) { + displayInfo = nullptr; + } else { + displayInfo->type_ = (DisplayType)type; + } + return displayInfo; +} +} // namespace OHOS::Rosen \ No newline at end of file diff --git a/wmtest/dmserver/src/display_manager_proxy.cpp b/wmtest/dmserver/src/display_manager_proxy.cpp new file mode 100644 index 0000000000..87c482a3e6 --- /dev/null +++ b/wmtest/dmserver/src/display_manager_proxy.cpp @@ -0,0 +1,104 @@ +/* + * 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_manager_proxy.h" + +#include + +#include "window_manager_hilog.h" + +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(); + if (remote == nullptr) { + WLOGFW("GetDefaultDisplayId: remote is nullptr"); + return DISPLAY_ID_INVALD; + } + + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("GetDefaultDisplayId: WriteInterfaceToken failed"); + return DISPLAY_ID_INVALD; + } + if (remote->SendRequest(TRANS_ID_GET_DEFAULT_DISPLAY_ID, data, reply, option) != ERR_NONE) { + WLOGFW("GetDefaultDisplayId: SendRequest failed"); + return DISPLAY_ID_INVALD; + } + + DisplayId displayId = reply.ReadUint64(); + WLOGFI("DisplayManagerProxy::GetDefaultDisplayId %llu", displayId); + return displayId; +} + +DisplayInfo DisplayManagerProxy::GetDisplayInfoById(DisplayId displayId) +{ + sptr remote = Remote(); + if (remote == nullptr) { + WLOGFW("GetDisplayInfoById: remote is nullptr"); + return DisplayInfo(); + } + + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("GetDisplayInfoById: WriteInterfaceToken failed"); + return DisplayInfo(); + } + data.WriteUint64(static_cast(displayId)); + if (remote->SendRequest(TRANS_ID_GET_DISPLAY_BY_ID, data, reply, option) != ERR_NONE) { + WLOGFW("GetDisplayInfoById: SendRequest failed"); + return DisplayInfo(); + } + + sptr info = reply.ReadParcelable(); + if (info == nullptr) { + WLOGFW("DisplayManagerProxy::GetDisplayInfoById SendRequest nullptr."); + return DisplayInfo(); + } + return *info; +} +} // namespace OHOS::Rosen \ No newline at end of file diff --git a/wmtest/dmserver/src/display_manager_service.cpp b/wmtest/dmserver/src/display_manager_service.cpp new file mode 100644 index 0000000000..93ca0d2d6a --- /dev/null +++ b/wmtest/dmserver/src/display_manager_service.cpp @@ -0,0 +1,113 @@ +/* + * 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_manager_service.h" + +#include +#include + +#include +#include +#include + +#include "window_manager_hilog.h" + +namespace OHOS::Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "DisplayManagerService"}; +} + +IMPLEMENT_SINGLE_INSTANCE(DisplayManagerService); + +const bool REGISTER_RESULT = + SystemAbility::MakeAndRegisterAbility(SingletonContainer::Get().GetRefPtr()); + +DisplayManagerService::DisplayManagerService() : SystemAbility(DISPLAY_MANAGER_SERVICE_SA_ID, true) +{ +} + +void DisplayManagerService::OnStart() +{ + WLOGFI("DisplayManagerService::OnStart start"); + if (!Init()) { + return; + } +} + +bool DisplayManagerService::Init() +{ + WLOGFI("DisplayManagerService::Init start"); + bool ret = Publish(this); + if (!ret) { + 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; +} + +ScreenId DisplayManagerService::GetScreenIdFromDisplayId(DisplayId displayId) +{ + return (ScreenId)displayId; +} + +DisplayId DisplayManagerService::GetDefaultDisplayId() +{ + if (displayScreenManager_ == nullptr) { + return DISPLAY_ID_INVALD; + } + ScreenId screenId = displayScreenManager_->GetDefaultScreenId(); + WLOGFI("GetDefaultDisplayId %{public}llu", screenId); + return GetDisplayIdFromScreenId(screenId); +} + +DisplayInfo DisplayManagerService::GetDisplayInfoById(DisplayId displayId) +{ + DisplayInfo displayInfo; + if (displayScreenManager_ == nullptr) { + return displayInfo; + } + ScreenId screenId = GetScreenIdFromDisplayId(displayId); + auto screenModeInfo = displayScreenManager_->GetScreenActiveMode(screenId); + displayInfo.id_ = displayId; + displayInfo.width_ = screenModeInfo.GetScreenWidth(); + displayInfo.height_ = screenModeInfo.GetScreenHeight(); + displayInfo.freshRate_ = screenModeInfo.GetScreenFreshRate(); + return displayInfo; +} + +void DisplayManagerService::OnStop() +{ + WLOGFI("ready to stop display service."); + displayScreenManager_ = nullptr; +} +} // namespace OHOS::Rosen \ No newline at end of file diff --git a/wmtest/dmserver/src/display_manager_service_inner.cpp b/wmtest/dmserver/src/display_manager_service_inner.cpp new file mode 100644 index 0000000000..61a9c3f6f8 --- /dev/null +++ b/wmtest/dmserver/src/display_manager_service_inner.cpp @@ -0,0 +1,89 @@ +/* + * 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_manager_service_inner.h" + +#include +#include + +#include +#include +#include + +#include "display_screen_manager.h" +#include "display_manager_service.h" +#include "window_manager_hilog.h" + +namespace OHOS::Rosen { +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(); +} + +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); + if (display == nullptr) { + WLOGFE("GetDisplayById failed!\n"); + return nullptr; + } + return display; +} + +const sptr DisplayManagerServiceInner::GetDefaultDisplay() +{ + return GetDisplayById(GetDefaultDisplayId()); +} + +std::vector DisplayManagerServiceInner::GetAllDisplayIds() +{ + std::vector res; + res.push_back(GetDefaultDisplayId()); + return res; +} + +std::vector> DisplayManagerServiceInner::GetAllDisplays() +{ + std::vector> res; + auto displayIds = GetAllDisplayIds(); + for (auto displayId: displayIds) { + const sptr display = GetDisplayById(displayId); + if (display != nullptr) { + res.push_back(display); + } else { + WLOGFE("GetAllDisplays display %llu nullptr!", displayId); + } + } + return res; +} +} // namespace OHOS::Rosen \ No newline at end of file diff --git a/wmtest/dmserver/src/display_manager_stub.cpp b/wmtest/dmserver/src/display_manager_stub.cpp new file mode 100644 index 0000000000..0e065619c8 --- /dev/null +++ b/wmtest/dmserver/src/display_manager_stub.cpp @@ -0,0 +1,59 @@ +/* + * 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_manager_stub.h" + +#include + +#include "window_manager_hilog.h" + +namespace OHOS::Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "DisplayManagerStub"}; +} + +int32_t DisplayManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, + MessageOption &option) +{ + WLOGFI("OnRemoteRequest code is %{public}d", code); + if (data.ReadInterfaceToken() != GetDescriptor()) { + WLOGFE("InterfaceToken check failed"); + 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); + break; + } + case TRANS_ID_GET_DISPLAY_BY_ID: { + DisplayId displayId = static_cast(data.ReadUint64()); + auto info = GetDisplayInfoById(displayId); + reply.WriteParcelable(&info); + break; + } + default: + WLOGFW("unknown transaction code"); + return IPCObjectStub::OnRemoteRequest(code, data, reply, option); + } + return 0; +} +} // namespace OHOS::Rosen \ No newline at end of file diff --git a/wmtest/dmserver/src/display_node_control.cpp b/wmtest/dmserver/src/display_node_control.cpp new file mode 100644 index 0000000000..8f821aca74 --- /dev/null +++ b/wmtest/dmserver/src/display_node_control.cpp @@ -0,0 +1,19 @@ +/* + * 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_node_control.h" + +namespace OHOS::Rosen { +} // namespace OHOS::Rosen \ No newline at end of file diff --git a/wmtest/dmserver/src/display_screen.cpp b/wmtest/dmserver/src/display_screen.cpp new file mode 100644 index 0000000000..bbc1876a17 --- /dev/null +++ b/wmtest/dmserver/src/display_screen.cpp @@ -0,0 +1,66 @@ +/* + * 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.h" + +namespace OHOS::Rosen { +DisplayScreen::DisplayScreen(const DisplayInfo& info) + : id_(info.id_), + width_(info.width_), + height_(info.height_), + freshRate_(info.freshRate_) +{ +} + +DisplayId DisplayScreen::GetId() const +{ + return id_; +} + +int32_t DisplayScreen::GetWidth() const +{ + return width_; +} + +int32_t DisplayScreen::GetHeight() const +{ + return height_; +} + +uint32_t DisplayScreen::GetFreshRate() const +{ + return freshRate_; +} + +void DisplayScreen::SetWidth(int32_t width) +{ + width_ = width; +} + +void DisplayScreen::SetHeight(int32_t height) +{ + height_ = height; +} + +void DisplayScreen::SetFreshRate(uint32_t freshRate) +{ + freshRate_ = freshRate; +} + +void DisplayScreen::SetId(DisplayId id) +{ + id_ = id; +} +} // namespace OHOS::Rosen \ No newline at end of file diff --git a/wmtest/dmserver/src/display_screen_manager.cpp b/wmtest/dmserver/src/display_screen_manager.cpp new file mode 100644 index 0000000000..91620c7493 --- /dev/null +++ b/wmtest/dmserver/src/display_screen_manager.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 "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/wmtest/dmserver/src/rs_adapter.cpp b/wmtest/dmserver/src/rs_adapter.cpp new file mode 100644 index 0000000000..5e5d66581d --- /dev/null +++ b/wmtest/dmserver/src/rs_adapter.cpp @@ -0,0 +1,99 @@ +/* + * 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 "rs_adapter.h" + +#include +#include +#include + +#include "window_manager_hilog.h" + +namespace OHOS::Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "RsAdapter"}; +} + +IMPLEMENT_SINGLE_INSTANCE(RsAdapter); + +bool RsAdapter::InitRSProxyLocked() +{ + WLOGFI("InitRProxy"); + if (!rsProxy_) { + sptr systemAbilityManager = + SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (!systemAbilityManager) { + WLOGFE("Failed to get system ability mgr."); + return false; + } + + sptr remoteObject + = systemAbilityManager->GetSystemAbility(); + if (!remoteObject) { + WLOGFE("Failed to get display manager service."); + return false; + } + + rsProxy_ = iface_cast(remoteObject); + if ((!rsProxy_) || (!rsProxy_->AsObject())) { + WLOGFE("Failed to get system display manager services"); + return false; + } + + rsDeath_ = new RSDeathRecipient(this); + if (!rsDeath_) { + WLOGFE("Failed to create death Recipient ptr RSDeathRecipient"); + return false; + } + if (!remoteObject->AddDeathRecipient(rsDeath_)) { + WLOGFE("Failed to add death recipient"); + return false; + } + } + return true; +} + +RSDeathRecipient::RSDeathRecipient(sptr& rsAdapter) +{ + rsAdatper_ = rsAdapter; +} + +void RSDeathRecipient::OnRemoteDied(const wptr& wptrDeath) +{ + if (wptrDeath == nullptr) { + WLOGFE("wptrDeath is null"); + return; + } + + sptr object = wptrDeath.promote(); + if (!object) { + WLOGFE("object is null"); + return; + } + if (rsAdapter_ != null) { + rsAdatper_.Clear(); + rsAdatper_ = nullptr; + } +} + +void RsAdapter::Clear() +{ + std::lock_guard lock(mutex_); + if ((rsProxy_ != nullptr) && (rsProxy_->AsObject() != nullptr)) { + rsProxy_->AsObject()->RemoveDeathRecipient(rsDeath_); + } + rsProxy_ = nullptr; +} +} // namespace OHOS::Rosen diff --git a/wmtest/dmserver/src/screen.cpp b/wmtest/dmserver/src/screen.cpp new file mode 100644 index 0000000000..11c222d130 --- /dev/null +++ b/wmtest/dmserver/src/screen.cpp @@ -0,0 +1,19 @@ +/* + * 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 "screen.h" + +namespace OHOS::Rosen { +} // namespace OHOS::Rosen \ No newline at end of file diff --git a/wmtest/frameworks/inative_test.cpp b/wmtest/frameworks/inative_test.cpp new file mode 100644 index 0000000000..62b5316df5 --- /dev/null +++ b/wmtest/frameworks/inative_test.cpp @@ -0,0 +1,41 @@ +/* + * 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 "inative_test.h" + +#include +#include + +namespace OHOS::Rosen { +void INativeTest::VisitTests(VisitTestFunc func) +{ + auto sortFunc = [](const auto &it, const auto &jt) { + if (it->GetDomain() == jt->GetDomain()) { + return it->GetID() < jt->GetID(); + } + return it->GetDomain() < jt->GetDomain(); + }; + std::sort(nativeTest_.begin(), nativeTest_.end(), sortFunc); + + for (auto &test : nativeTest_) { + func(test); + } +} + +INativeTest::INativeTest() +{ + nativeTest_.push_back(this); +} +} // namespace OHOS::Rosen diff --git a/wmtest/frameworks/inative_test.h b/wmtest/frameworks/inative_test.h new file mode 100644 index 0000000000..4a0ade056c --- /dev/null +++ b/wmtest/frameworks/inative_test.h @@ -0,0 +1,48 @@ +/* + * 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_INATIVE_TEST_H +#define OHOS_ROSEN_INATIVE_TEST_H + +#include +#include +#include +#include + +namespace OHOS::Rosen { +class INativeTest; +using VisitTestFunc = std::function; + +class INativeTest { +public: + enum { + LAST_TIME_FOREVER = 999999999, + }; + + static void VisitTests(VisitTestFunc func); + INativeTest(); + virtual ~INativeTest() = default; + + virtual std::string GetDescription() const = 0; + virtual std::string GetDomain() const = 0; + virtual int32_t GetID() const = 0; + virtual uint32_t GetLastTime() const = 0; + virtual void Run(int32_t argc, const char **argv) = 0; +private: + static inline std::vector nativeTest_; +}; +} // namespace OHOS::Rosen + +#endif // OHOS_ROSEN_INATIVE_TEST_H diff --git a/wmtest/frameworks/main.cpp b/wmtest/frameworks/main.cpp new file mode 100644 index 0000000000..cd38311459 --- /dev/null +++ b/wmtest/frameworks/main.cpp @@ -0,0 +1,88 @@ +/* + * 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 +#include +#include +#include +#include +#include + +#include + +#include "inative_test.h" + +using namespace OHOS::Rosen; + +namespace { +void Usage(const char *argv0) +{ + printf("Usage: %s type id\n", argv0); + auto visitFunc = [](const INativeTest *test) { + std::stringstream ss; + ss << test->GetDomain() << ", id="; + ss << test->GetID() << ": "; + ss << test->GetDescription(); + if (test->GetLastTime() != INativeTest::LAST_TIME_FOREVER) { + constexpr double msecToSec = 1000.0; + ss << " (last " << std::setprecision(1) << test->GetLastTime() / msecToSec << "s)"; + } + std::cout << ss.str() << std::endl; + }; + INativeTest::VisitTests(visitFunc); +} +} // namespace + +int32_t main(int32_t argc, const char **argv) +{ + constexpr int32_t argNumber = 2; + if (argc <= argNumber) { + Usage(argv[0]); + return 0; + } + + int32_t testcase = -1; + constexpr int32_t domainIndex = 1; + constexpr int32_t idIndex = 2; + std::stringstream ss(argv[idIndex]); + ss >> testcase; + if (ss.fail() == true || testcase == -1) { + Usage(argv[0]); + return 1; + } + + INativeTest *found = nullptr; + auto visitFunc = [argv, testcase, &found](INativeTest *test) { + if (test->GetDomain() == argv[domainIndex] && test->GetID() == testcase) { + found = test; + } + }; + INativeTest::VisitTests(visitFunc); + //if (found == nullptr) { + // printf("not found test %d\n", testcase); + // return 1; + //} + + auto runner = OHOS::AppExecFwk::EventRunner::Create(false); + auto handler = std::make_shared(runner); + handler->PostTask(std::bind(&INativeTest::Run, found, argc - 1, argv + 1)); + if (found->GetLastTime() != INativeTest::LAST_TIME_FOREVER) { + handler->PostTask(std::bind(&OHOS::AppExecFwk::EventRunner::Stop, runner), found->GetLastTime()); + } + + printf("%d %s run! pid=%d\n", found->GetID(), found->GetDescription().c_str(), getpid()); + runner->Run(); + return 0; +} diff --git a/wmtest/interfaces/innerkits/BUILD.gn b/wmtest/interfaces/innerkits/BUILD.gn new file mode 100644 index 0000000000..19b8475396 --- /dev/null +++ b/wmtest/interfaces/innerkits/BUILD.gn @@ -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. + +import("//build/ohos.gni") + +config("wm_interface_config") { + visibility = [ ":*" ] + include_dirs = [ "//foundation/windowmanager/interfaces/innerkits" ] +} + +ohos_shared_library("wm_interface") { + public_configs = [ ":wm_interface_config" ] + + include_dirs = [ "//foundation/windowmanager/interfaces/innerkits" ] + + public_deps = [ + "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", + "//foundation/graphic/standard/rosen/modules/render_service_client:librender_service_client", + "//foundation/multimodalinput/input/frameworks/proxy:libmmi-client", + "//utils/native/base:utils", + ] + + part_name = "window_manager" + subsystem_name = "window" +} diff --git a/wmtest/interfaces/innerkits/dm/README.md b/wmtest/interfaces/innerkits/dm/README.md new file mode 100644 index 0000000000..bf79d11158 --- /dev/null +++ b/wmtest/interfaces/innerkits/dm/README.md @@ -0,0 +1 @@ +Store code of display client out header files diff --git a/wmtest/interfaces/innerkits/dm/display.h b/wmtest/interfaces/innerkits/dm/display.h new file mode 100644 index 0000000000..64b1bac72c --- /dev/null +++ b/wmtest/interfaces/innerkits/dm/display.h @@ -0,0 +1,56 @@ +/* + * 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 p ermissions and + * limitations under the License. + */ + +#ifndef FOUNDATION_DM_DISPLAY_H +#define FOUNDATION_DM_DISPLAY_H + +#include + +#include + +namespace OHOS::Rosen { +class DisplayInfo; +using DisplayId = uint64_t; +static constexpr DisplayId DISPLAY_ID_INVALD = -1ULL; + +typedef enum DisplayType { + DEFAULT = 0, +} DisplayType; + +class Display : public RefBase { +public: + Display(const std::string& name, DisplayInfo* info); + ~Display() = default; + + DisplayId GetId() const; + int32_t GetWidth() const; + int32_t GetHeight() const; + uint32_t GetFreshRate() const; + + void SetId(DisplayId displayId); + void SetWidth(int32_t width); + void SetHeight(int32_t height); + void SetFreshRate(uint32_t freshRate); + +private: + std::string name_; + DisplayId id_ {DISPLAY_ID_INVALD}; + int32_t width_ {0}; + int32_t height_ {0}; + uint32_t freshRate_ {0}; +}; +} // namespace OHOS::Rosen + +#endif // FOUNDATION_DM_DISPLAY_H \ No newline at end of file diff --git a/wmtest/interfaces/innerkits/dm/display_manager.h b/wmtest/interfaces/innerkits/dm/display_manager.h new file mode 100644 index 0000000000..ed91aba1d3 --- /dev/null +++ b/wmtest/interfaces/innerkits/dm/display_manager.h @@ -0,0 +1,48 @@ +/* + * 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_DM_DISPLAY_MANAGER_H +#define FOUNDATION_DM_DISPLAY_MANAGER_H + +#include +#include + +#include "display.h" +#include "single_instance.h" + +namespace OHOS::Rosen { +class DisplayManagerAdapter; + +class DisplayManager : public RefBase { +DECLARE_SINGLE_INSTANCE_BASE(DisplayManager); +public: + const sptr& GetDisplay(const DisplayType type); + std::vector> GetAllDisplays(); + + DisplayId GetDefaultDisplayId(); + const sptr GetDefaultDisplay(); + + const sptr GetDisplayById(DisplayId displayId); + + std::vector GetAllDisplayIds(); + +private: + DisplayManager(); + ~DisplayManager(); + sptr dmsAdapter_; +}; +} // namespace OHOS::Rosen + +#endif // FOUNDATION_DM_DISPLAY_MANAGER_H \ No newline at end of file diff --git a/wmtest/interfaces/innerkits/dm/display_property.h b/wmtest/interfaces/innerkits/dm/display_property.h new file mode 100644 index 0000000000..7409c0d12d --- /dev/null +++ b/wmtest/interfaces/innerkits/dm/display_property.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 FOUNDATION_DM_DISPLAY_PROPERTY_H +#define FOUNDATION_DM_DISPLAY_PROPERTY_H + +#include + +namespace OHOS::Rosen { +class DisplayProperty : public RefBase { +public: + DisplayProperty() = default; + ~DisplayProperty() = default; + + DisplayType type_; + std::string name_; + + int width_; + int height_; + float xDpi_; + float yDpi_; + // Surface surface_; +}; +} // namespace OHOS::Rosen + +#endif // FOUNDATION_DM_DISPLAY_PROPERTY_H \ No newline at end of file diff --git a/wmtest/interfaces/innerkits/dm/monitor.h b/wmtest/interfaces/innerkits/dm/monitor.h new file mode 100644 index 0000000000..0cb2b16475 --- /dev/null +++ b/wmtest/interfaces/innerkits/dm/monitor.h @@ -0,0 +1,24 @@ +/* + * 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_DM_MONITOR_H +#define FOUNDATION_DM_MONITOR_H + +namespace OHOS::Rosen { +class Monitor { +}; +} // namespace OHOS::Rosen + +#endif // FOUNDATION_DM_MONITOR_H \ No newline at end of file diff --git a/wmtest/interfaces/innerkits/dmserver/README.md b/wmtest/interfaces/innerkits/dmserver/README.md new file mode 100644 index 0000000000..24e92014b9 --- /dev/null +++ b/wmtest/interfaces/innerkits/dmserver/README.md @@ -0,0 +1 @@ +Store code of display server out header files diff --git a/wmtest/interfaces/innerkits/wm/README.md b/wmtest/interfaces/innerkits/wm/README.md new file mode 100644 index 0000000000..9702ea7e24 --- /dev/null +++ b/wmtest/interfaces/innerkits/wm/README.md @@ -0,0 +1 @@ +Store code of window client out header files diff --git a/wmtest/interfaces/innerkits/wm/window.h b/wmtest/interfaces/innerkits/wm/window.h new file mode 100644 index 0000000000..7b7d89eae0 --- /dev/null +++ b/wmtest/interfaces/innerkits/wm/window.h @@ -0,0 +1,81 @@ +/* + * 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_H +#define OHOS_ROSEN_WINDOW_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include "wm_common.h" +#include "window_option.h" +#include "window_life_cycle_interface.h" + +class NativeValue; +class NativeEngine; + +namespace OHOS::AbilityRuntime { +class AbilityContext; +} + +namespace OHOS { +namespace Rosen { +class IWindowChangeListener : public RefBase { +public: + virtual void OnSizeChange(Rect rect) = 0; +}; + +class Window : public RefBase { +public: + static sptr Create(const std::string& windowName, + sptr& option, const sptr& abilityToken = nullptr); + static sptr Find(const std::string& windowName); + + virtual std::shared_ptr GetSurfaceNode() const = 0; + + virtual Rect GetRect() const = 0; + virtual WindowType GetType() const = 0; + virtual WindowMode GetMode() const = 0; + virtual const std::string& GetWindowName() const = 0; + virtual uint32_t GetWindowId() = 0; + + virtual WMError SetWindowType(WindowType type) = 0; + virtual WMError SetWindowMode(WindowMode mode) = 0; + + virtual WMError Destroy() = 0; + virtual WMError Show() = 0; + virtual WMError Hide() = 0; + + virtual WMError MoveTo(int32_t x, int32_t y) = 0; + virtual WMError Resize(uint32_t width, uint32_t height) = 0; + + virtual WMError RequestFocus() const = 0; + 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 RegisterLifeCycleListener(sptr& listener) = 0; + virtual void RegisterWindowChangeListener(sptr& listener) = 0; + virtual WMError SetUIContent(std::shared_ptr context, + std::string& url, NativeEngine* engine, NativeValue* storage) = 0; +}; +} +} +#endif // OHOS_ROSEN_WINDOW_H diff --git a/wmtest/interfaces/innerkits/wm/window_life_cycle_interface.h b/wmtest/interfaces/innerkits/wm/window_life_cycle_interface.h new file mode 100644 index 0000000000..c9fa54b2a3 --- /dev/null +++ b/wmtest/interfaces/innerkits/wm/window_life_cycle_interface.h @@ -0,0 +1,32 @@ +/* + * 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_LIFE_CYCLE_H +#define OHOS_ROSEN_WINDOW_LIFE_CYCLE_H + +#include + +namespace OHOS { +namespace Rosen { +class IWindowLifeCycle : public RefBase { +public: + virtual void AfterForeground() = 0; + virtual void AfterBackground() = 0; + virtual void AfterFocused() = 0; + virtual void AfterUnFocused() = 0; +}; +} +} +#endif // OHOS_ROSEN_WINDOW_LIFE_CYCLE_H diff --git a/wmtest/interfaces/innerkits/wm/window_option.h b/wmtest/interfaces/innerkits/wm/window_option.h new file mode 100644 index 0000000000..9f695dae2f --- /dev/null +++ b/wmtest/interfaces/innerkits/wm/window_option.h @@ -0,0 +1,63 @@ +/* + * 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_OPTION_H +#define OHOS_ROSEN_WINDOW_OPTION_H +#include +#include +#include "wm_common.h" + +namespace OHOS { +namespace Rosen { +class WindowOption : public RefBase { +public: + WindowOption(); + virtual ~WindowOption() = default; + + void SetWindowRect(const struct Rect& rect); + void SetWindowType(WindowType type); + void SetWindowMode(WindowMode mode); + void SetFocusable(bool isFocusable); + void SetTouchable(bool isTouchable); + void SetDisplayId(int32_t displayId); + void SetParentName(const std::string& parentName); + void SetWindowName(const std::string& windowName); + void AddWindowFlag(WindowFlag flag); + void RemoveWindowFlag(WindowFlag flag); + void SetWindowFlags(uint32_t flags); + + Rect GetWindowRect() const; + WindowType GetWindowType() const; + WindowMode GetWindowMode() const; + bool GetFocusable() const; + bool GetTouchable() const; + int32_t GetDisplayId() const; + const std::string& GetParentName() const; + const std::string& GetWindowName() const; + uint32_t GetWindowFlags() const; +private: + Rect windowRect_ { 0, 0, 0, 0 }; + WindowType type_ { WindowType::WINDOW_TYPE_APP_MAIN_WINDOW }; + WindowMode mode_ { WindowMode::WINDOW_MODE_FULLSCREEN }; + bool focusable_ { true }; + bool touchable_ { true }; + int32_t displayId_ { 0 }; + std::string parentName_ { "" }; + std::string windowName_ { "" }; + uint32_t flags_ { 0 }; +}; +} +} +#endif // OHOS_ROSEN_WINDOW_OPTION_H diff --git a/wmtest/interfaces/innerkits/wm/window_scene.h b/wmtest/interfaces/innerkits/wm/window_scene.h new file mode 100644 index 0000000000..dc984b01f9 --- /dev/null +++ b/wmtest/interfaces/innerkits/wm/window_scene.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 INTERFACES_INNERKITS_WINDOW_SCENE_H +#define INTERFACES_INNERKITS_WINDOW_SCENE_H + +#include +#include +#include + +#include "window.h" +#include "window_option.h" + +namespace OHOS { +namespace Rosen { +class WindowScene : public RefBase { +public: + static const int32_t DEFAULT_DISPLAY_ID = 0; + static const std::string MAIN_WINDOW_ID; + + WindowScene() = default; + ~WindowScene(); + + WMError Init(int32_t displayId, std::shared_ptr& abilityContext, + sptr& listener); + + sptr CreateWindow(const std::string& windowName, sptr& option) const; + + const sptr& GetMainWindow() const; + + WMError GoForeground(); + WMError GoBackground() const; + + WMError RequestFocus() const; + +private: + static inline std::atomic count { 0 }; + sptr mainWindow_ = nullptr; + int32_t displayId_ = DEFAULT_DISPLAY_ID; + + std::shared_ptr abilityContext_ = nullptr; +}; +} // namespace Rosen +} // namespace OHOS +#endif // INTERFACES_INNERKITS_WINDOW_SCENE_H diff --git a/wmtest/interfaces/innerkits/wm/wm_common.h b/wmtest/interfaces/innerkits/wm/wm_common.h new file mode 100644 index 0000000000..cd472f88b1 --- /dev/null +++ b/wmtest/interfaces/innerkits/wm/wm_common.h @@ -0,0 +1,96 @@ +/* + * 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_WM_COMMON_H +#define OHOS_ROSEN_WM_COMMON_H + +#include + +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_SUB_WINDOW_BASE = 1000, + WINDOW_TYPE_MEDIA = APP_SUB_WINDOW_BASE, + WINDOW_TYPE_APP_SUB_WINDOW, + APP_SUB_WINDOW_END = 1999, + + SYSTEM_WINDOW_BASE = 2000, + WINDOW_TYPE_WALLPAPER = SYSTEM_WINDOW_BASE, + ABOVE_APP_SYSTEM_WINDOW_BASE = 2100, + WINDOW_TYPE_APP_LAUNCHING, + 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, + SYSTEM_WINDOW_END = 2999, +}; + +enum class WindowMode : uint32_t { + WINDOW_MODE_FULLSCREEN, + WINDOW_MODE_SPLIT, + WINDOW_MODE_FLOATING, + WINDOW_MODE_PIP +}; + +enum class WMError : int32_t { + WM_OK = 0, + WM_ERROR_SAMGR = 100, + WM_ERROR_IPC_FAILED = 101, + WM_ERROR_NO_MEM = 110, + WM_ERROR_NULLPTR = 120, + WM_ERROR_INVALID_PARAM = 130, + WM_ERROR_DESTROYED_OBJECT = 140, + WM_ERROR_DEATH_RECIPIENT = 150, + WM_ERROR_INVALID_WINDOW = 160, + WM_ERROR_UNKNOWN, + + /* weston adater */ + WM_ERROR_WINDOWMANAGER_GETINSTANCE = 100000, + WM_ERROR_WINDOWMANAGER_INIT = 100001, + WM_ERROR_WINDOWMANAGER_SHOW = 100002, + WM_ERROR_WINDOWMANAGER_HIDE = 100003, + WM_ERROR_WINDOWMANAGER_MOVE = 100004, + WM_ERROR_WINDOWMANAGER_RESIZE = 100005, +}; + +enum class WindowFlag : uint32_t { + WINDOW_FLAG_NEED_AVOID = 1, + WINDOW_FLAG_PARENT_LIMIT = 1 << 1, + WINDOW_FLAG_END = 1 << 2, +}; + +struct Rect { + int32_t posX_; + int32_t posY_; + uint32_t width_; + uint32_t height_; +}; +} +} +#endif // OHOS_ROSEN_WM_COMMON_H diff --git a/wmtest/interfaces/innerkits/wmserver/README.md b/wmtest/interfaces/innerkits/wmserver/README.md new file mode 100644 index 0000000000..449c0fe9fd --- /dev/null +++ b/wmtest/interfaces/innerkits/wmserver/README.md @@ -0,0 +1 @@ +Store code of window server out header files diff --git a/wmtest/interfaces/kits/README.md b/wmtest/interfaces/kits/README.md new file mode 100644 index 0000000000..033c7c544c --- /dev/null +++ b/wmtest/interfaces/kits/README.md @@ -0,0 +1 @@ +Store code of window js api diff --git a/wmtest/interfaces/kits/js/declaration/BUILD.gn b/wmtest/interfaces/kits/js/declaration/BUILD.gn new file mode 100644 index 0000000000..d63c1a22e0 --- /dev/null +++ b/wmtest/interfaces/kits/js/declaration/BUILD.gn @@ -0,0 +1,29 @@ +# 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("//build/ohos.gni") + +js_declaration("window") { + sources = [ "./api" ] + + part_name = "window_manager" +} + +ohos_copy("window_declaration") { + sources = [ "./api" ] + + outputs = [ target_out_dir + "/$target_name/" ] + + module_source_dir = target_out_dir + "/$target_name" + module_install_name = "" +} diff --git a/wmtest/interfaces/kits/js/declaration/api/@ohos.display.d.ts b/wmtest/interfaces/kits/js/declaration/api/@ohos.display.d.ts new file mode 100644 index 0000000000..17ac54ae5d --- /dev/null +++ b/wmtest/interfaces/kits/js/declaration/api/@ohos.display.d.ts @@ -0,0 +1,135 @@ +/* +* 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. +*/ + +/** + * interface of display manager + * @devices tv, phone, tablet, wearable + */ +declare namespace display { + /** + * get the default display + * @devices tv, phone, tablet, wearable + */ + function getDefaultDisplay(): Promise; + + /** + /** + * the state of display + * @devices tv, phone, tablet, wearable + */ + enum DisplayState { + /** + * unknown + */ + STATE_UNKNOWN = 0, + /** + * screen off + */ + STATE_OFF, + /** + * screen on + */ + STATE_ON, + /** + * doze, but it will update for some important system messages + */ + STATE_DOZE, + /** + * doze and not update + */ + STATE_DOZE_SUSPEND, + /** + * VR node + */ + STATE_VR, + /** + * screen on and not update + */ + STATE_ON_SUSPEND, + } + + /** + * Properties of display, it couldn't update automatically + * @devices tv, phone, tablet, wearable + */ + interface Display { + /** + * display id + */ + id: number; + + /** + * display name + */ + name: string; + + /** + * the display is alive + */ + alive: boolean; + + /** + * the state of display + */ + state: DisplayState; + + /** + * refresh rate, unit: Hz + */ + refreshRate: number; + + /** + * the rotation degrees of the display + */ + rotation: number; + + /** + * the width of display, unit: pixel + */ + width: number; + + /** + * the height of display, unit: pixel + */ + height: number; + + /** + * indicates the display resolution. + */ + densityDPI: number; + + /** + * indicates the display density in pixels. The value of a low-resolution display is 1.0 + */ + densityPixels: number; + + /** + * indicates the text scale density of a display. + */ + scaledDensity: number; + + /** + * the DPI on X-axis. + */ + xDPI: number; + + /** + * the DPI on Y-axis. + */ + yDPI: number; + } +} + +export default display; diff --git a/wmtest/interfaces/kits/js/declaration/api/@ohos.window.d.ts b/wmtest/interfaces/kits/js/declaration/api/@ohos.window.d.ts new file mode 100644 index 0000000000..3872e90048 --- /dev/null +++ b/wmtest/interfaces/kits/js/declaration/api/@ohos.window.d.ts @@ -0,0 +1,79 @@ +/* +* 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 window { + /** + * Obtain the top window of the current application. + * @devices tv, phone, tablet, wearable. + */ + function getTopWindow(): Promise; + + /** + * The type of a window. + * @devices tv, phone, tablet, wearable. + */ + enum WindowType { + /** + * App. + */ + TYPE_APP = 0, + /** + * System alert. + */ + TYPE_SYSTEM_ALERT = 30, + /** + * System volume. + */ + TYPE_SYSTEM_VOLUME = 70, + /** + * System panel. + */ + TYPE_SYSTEM_PANEL = 90, + } + + /** + * The interface of window. + */ + interface Window { + /** + * 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. + */ + resetSize(width: number, height: number): Promise; + + /** + * Set the type of a window. + * @param type Indicate the type of a window. + * @devices tv, phone, tablet, wearable, liteWearable. + */ + setWindowType(type: WindowType): Promise; + } +} + +export default window; diff --git a/wmtest/interfaces/kits/napi/BUILD.gn b/wmtest/interfaces/kits/napi/BUILD.gn new file mode 100644 index 0000000000..00c0281a28 --- /dev/null +++ b/wmtest/interfaces/kits/napi/BUILD.gn @@ -0,0 +1,58 @@ +# 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") + +ts2abc_gen_abc("gen_window_stage_abc") { + src_js = rebase_path("window_stage.js") + dst_file = rebase_path(target_out_dir + "/window_stage.abc") + in_puts = [ "window_stage.js" ] + out_puts = [ target_out_dir + "/window_stage.abc" ] + extra_args = [ "--module" ] +} + +gen_js_obj("window_stage_js") { + input = "window_stage.js" + output = target_out_dir + "/window_stage.o" +} + +gen_js_obj("window_stage_abc") { + input = get_label_info(":gen_window_stage_abc", "target_out_dir") + + "/window_stage.abc" + output = target_out_dir + "/window_stage_abc.o" + dep = ":gen_window_stage_abc" +} + +ohos_shared_library("windowstage") { + sources = [ "window_stage_module.cpp" ] + + deps = [ + ":window_stage_abc", + ":window_stage_js", + ] + + external_deps = [ "napi:ace_napi" ] + + relative_install_dir = "module/application" + + part_name = "window_manager" + subsystem_name = "window" +} + +group("napi_packages") { + deps = [ + "display:display", + "window:window", + ] +} diff --git a/wmtest/interfaces/kits/napi/common/BUILD.gn b/wmtest/interfaces/kits/napi/common/BUILD.gn new file mode 100644 index 0000000000..081352bd7b --- /dev/null +++ b/wmtest/interfaces/kits/napi/common/BUILD.gn @@ -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. + +import("//build/ohos.gni") + +## Build wm_napi_common.a {{{ +config("wm_napi_common_config") { + visibility = [ ":*" ] + + cflags = [ + "-Wall", + "-Werror", + "-g3", + ] +} + +config("wm_napi_common_public_config") { + include_dirs = [ + ".", + "//third_party/node/src", + ] +} + +ohos_static_library("wm_napi_common") { + sources = [ "wm_napi_common.cpp" ] + + configs = [ ":wm_napi_common_config" ] + + public_configs = [ ":wm_napi_common_public_config" ] + + public_deps = [ + "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog", + "//foundation/ace/napi:ace_napi", + ] +} +## Build wm_napi_common.a }}} diff --git a/wmtest/interfaces/kits/napi/common/wm_napi_common.cpp b/wmtest/interfaces/kits/napi/common/wm_napi_common.cpp new file mode 100644 index 0000000000..16b5e6ef53 --- /dev/null +++ b/wmtest/interfaces/kits/napi/common/wm_napi_common.cpp @@ -0,0 +1,44 @@ +/* + * 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_napi_common.h" + +#include + +namespace OHOS { +napi_status SetMemberInt32(napi_env env, napi_value result, const char *key, int32_t value) +{ + napi_value num; + GNAPI_INNER(napi_create_int32(env, value, &num)); + GNAPI_INNER(napi_set_named_property(env, result, key, num)); + return napi_ok; +} + +napi_status SetMemberUint32(napi_env env, napi_value result, const char *key, uint32_t value) +{ + napi_value num; + GNAPI_INNER(napi_create_uint32(env, value, &num)); + GNAPI_INNER(napi_set_named_property(env, result, key, num)); + return napi_ok; +} + +napi_status SetMemberUndefined(napi_env env, napi_value result, const char *key) +{ + napi_value undefined; + GNAPI_INNER(napi_get_undefined(env, &undefined)); + GNAPI_INNER(napi_set_named_property(env, result, key, undefined)); + return napi_ok; +} +} // namespace OHOS diff --git a/wmtest/interfaces/kits/napi/common/wm_napi_common.h b/wmtest/interfaces/kits/napi/common/wm_napi_common.h new file mode 100644 index 0000000000..480c511de1 --- /dev/null +++ b/wmtest/interfaces/kits/napi/common/wm_napi_common.h @@ -0,0 +1,111 @@ +/* + * 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 INTERFACES_KITS_NAPI_GRAPHIC_COMMON_COMMON_H +#define INTERFACES_KITS_NAPI_GRAPHIC_COMMON_COMMON_H + +#include +#include + +#include +#include +#include +#include + +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, 0, "NapiWindowManagerCommonLayer" }; + +#define GNAPI_LOG(fmt, ...) OHOS::HiviewDFX::HiLog::Info(LABEL, \ + "%{public}s:%{public}d " fmt, __func__, __LINE__, ##__VA_ARGS__) + +#define GNAPI_ASSERT(env, assertion, fmt, ...) \ + do { \ + if (assertion) { \ + GNAPI_LOG(fmt, ##__VA_ARGS__); \ + return nullptr; \ + } \ + } while (0) + +#define GNAPI_INNER(call) \ + do { \ + napi_status s = (call); \ + if (s != napi_ok) { \ + GNAPI_LOG(#call " is %{public}d", s); \ + return s; \ + } \ + } while (0) + +namespace OHOS { +napi_status SetMemberInt32(napi_env env, napi_value result, const char *key, int32_t value); +napi_status SetMemberUint32(napi_env env, napi_value result, const char *key, uint32_t value); +napi_status SetMemberUndefined(napi_env env, napi_value result, const char *key); + +template +napi_value CreatePromise(napi_env env, + std::string funcname, + void(*async)(napi_env env, std::unique_ptr& param), + napi_value(*resolve)(napi_env env, std::unique_ptr& param), + std::unique_ptr& param) +{ + struct AsyncCallbackInfo { + napi_async_work asyncWork; + napi_deferred deferred; + void (*async)(napi_env env, std::unique_ptr& param); + napi_value (*resolve)(napi_env env, std::unique_ptr& param); + std::unique_ptr param; + }; + + AsyncCallbackInfo *info = new AsyncCallbackInfo { + .async = async, + .resolve = resolve, + .param = std::move(param), + }; + + napi_value resourceName; + NAPI_CALL(env, napi_create_string_latin1(env, + funcname.c_str(), NAPI_AUTO_LENGTH, &resourceName)); + + napi_value promise; + NAPI_CALL(env, napi_create_promise(env, &info->deferred, &promise)); + + auto asyncFunc = [](napi_env env, void *data) { + AsyncCallbackInfo *info = reinterpret_cast(data); + if (info->async) { + info->async(env, info->param); + } + }; + + auto completeFunc = [](napi_env env, napi_status status, void *data) { + AsyncCallbackInfo *info = reinterpret_cast(data); + napi_value resolveValue; + if (info->resolve) { + resolveValue = info->resolve(env, info->param); + } else { + napi_get_undefined(env, &resolveValue); + } + + napi_resolve_deferred(env, info->deferred, resolveValue); + napi_delete_async_work(env, info->asyncWork); + delete info; + }; + + NAPI_CALL(env, napi_create_async_work(env, nullptr, resourceName, asyncFunc, completeFunc, + reinterpret_cast(info), &info->asyncWork)); + + NAPI_CALL(env, napi_queue_async_work(env, info->asyncWork)); + return promise; +}; +} // namespace OHOS + +#endif // INTERFACES_KITS_NAPI_GRAPHIC_COMMON_COMMON_H diff --git a/wmtest/interfaces/kits/napi/display/BUILD.gn b/wmtest/interfaces/kits/napi/display/BUILD.gn new file mode 100644 index 0000000000..574ecb8a1c --- /dev/null +++ b/wmtest/interfaces/kits/napi/display/BUILD.gn @@ -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. + +import("//build/ohos.gni") + +## Build display.so {{{ +ohos_shared_library("display") { + sources = [ "native_display_module.cpp" ] + + deps = [ + "../common:wm_napi_common", + "//foundation/windowmanager/wm:libwm", + "//foundation/windowmanager/wmserver:libwms", + ] + + relative_install_dir = "module" + part_name = "window_manager" + subsystem_name = "window" +} +## Build display.so }}} diff --git a/wmtest/interfaces/kits/napi/display/native_display_module.cpp b/wmtest/interfaces/kits/napi/display/native_display_module.cpp new file mode 100644 index 0000000000..613ffaa0de --- /dev/null +++ b/wmtest/interfaces/kits/napi/display/native_display_module.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 "display_manager.h" +#include "native_display_module.h" +#include "wm_common.h" +#include "wm_napi_common.h" + +namespace OHOS { +namespace Rosen { +namespace getDefaultDisplay { +struct Param { + WMError wret; + sptr display; +}; + +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(); + if (param->display == nullptr) { + GNAPI_LOG("Get display failed!"); + param->wret = WMError::WM_ERROR_NULLPTR; + return; + } + GNAPI_LOG("GetDefaultDisplay: id %llu, w %d, h %d", + param->display->GetId(), param->display->GetWidth(), param->display->GetHeight()); + param->wret = WMError::WM_OK; +} + +napi_value Resolve(napi_env env, std::unique_ptr ¶m) +{ + napi_value result; + if (param->wret != WMError::WM_OK) { + NAPI_CALL(env, napi_get_undefined(env, &result)); + return result; + } + + DisplayId id = param->display->GetId(); + int32_t width = param->display->GetWidth(); + int32_t height = param->display->GetHeight(); + GNAPI_LOG("id : %{public}llu", id); + GNAPI_LOG("width : %{public}d", width); + GNAPI_LOG("height : %{public}d", height); + + NAPI_CALL(env, napi_create_object(env, &result)); + NAPI_CALL(env, SetMemberInt32(env, result, "id", id)); + NAPI_CALL(env, SetMemberUndefined(env, result, "name")); + NAPI_CALL(env, SetMemberUndefined(env, result, "alive")); + NAPI_CALL(env, SetMemberUndefined(env, result, "state")); + NAPI_CALL(env, SetMemberUndefined(env, result, "refreshRate")); + NAPI_CALL(env, SetMemberUndefined(env, result, "rotation")); + NAPI_CALL(env, SetMemberUint32(env, result, "width", width)); + NAPI_CALL(env, SetMemberUint32(env, result, "height", height)); + NAPI_CALL(env, SetMemberUndefined(env, result, "densityDPI")); + NAPI_CALL(env, SetMemberUndefined(env, result, "densityPixels")); + NAPI_CALL(env, SetMemberUndefined(env, result, "scaledDensity")); + NAPI_CALL(env, SetMemberUndefined(env, result, "xDPI")); + NAPI_CALL(env, SetMemberUndefined(env, result, "yDPI")); + + return result; +} + +napi_value MainFunc(napi_env env, napi_callback_info info) +{ + GNAPI_LOG("Display Interface: getDefaultDisplay()"); + GNAPI_LOG("%{public}s called", __PRETTY_FUNCTION__); + auto param = std::make_unique(); + return CreatePromise(env, __PRETTY_FUNCTION__, Async, Resolve, param); +} +} // namespace getDefaultDisplay + +napi_value DisplayModuleInit(napi_env env, napi_value exports) +{ + GNAPI_LOG("%{public}s called", __PRETTY_FUNCTION__); + + napi_property_descriptor properties[] = { + DECLARE_NAPI_FUNCTION("getDefaultDisplay", getDefaultDisplay::MainFunc), + }; + + NAPI_CALL(env, napi_define_properties(env, + exports, sizeof(properties) / sizeof(properties[0]), properties)); + return exports; +} +} // namespace Rosen +} // namespace OHOS + +extern "C" __attribute__((constructor)) void RegisterModule(void) +{ + napi_module displayModule = { + .nm_version = 1, // NAPI v1 + .nm_flags = 0, // normal + .nm_filename = nullptr, + .nm_register_func = OHOS::Rosen::DisplayModuleInit, + .nm_modname = "display", + .nm_priv = nullptr, + }; + napi_module_register(&displayModule); +} diff --git a/wmtest/interfaces/kits/napi/display/native_display_module.h b/wmtest/interfaces/kits/napi/display/native_display_module.h new file mode 100644 index 0000000000..a24c7026ab --- /dev/null +++ b/wmtest/interfaces/kits/napi/display/native_display_module.h @@ -0,0 +1,19 @@ +/* + * 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 INTERFACES_KITS_NAPI_GRAPHIC_DISPLAY_NATIVE_MODULE_H +#define INTERFACES_KITS_NAPI_GRAPHIC_DISPLAY_NATIVE_MODULE_H + +#endif // INTERFACES_KITS_NAPI_GRAPHIC_DISPLAY_NATIVE_MODULE_H diff --git a/wmtest/interfaces/kits/napi/window/BUILD.gn b/wmtest/interfaces/kits/napi/window/BUILD.gn new file mode 100644 index 0000000000..449bfb7fb4 --- /dev/null +++ b/wmtest/interfaces/kits/napi/window/BUILD.gn @@ -0,0 +1,40 @@ +# 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("//build/ohos.gni") + +## Build window.so {{{ +ohos_shared_library("window") { + sources = [ "native_window_module.cpp" ] + + configs = [ + "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_core:bundlemgr_sdk_config", + "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base:appexecfwk_base_sdk_config", + "//foundation/aafwk/standard/interfaces/innerkits/want:want_public_config", + "//foundation/aafwk/standard/interfaces/innerkits/ability_manager:ability_manager_public_config", + "//foundation/aafwk/standard/services/abilitymgr:abilityms_config", + ] + + deps = [ + "../common:wm_napi_common", + "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native", + "//foundation/appexecfwk/standard/kits:appkit_native", + "//foundation/windowmanager/wm:libwm", + "//foundation/windowmanager/wmserver:libwms", + ] + + relative_install_dir = "module" + part_name = "window_manager" + subsystem_name = "window" +} +## Build window.so }}} diff --git a/wmtest/interfaces/kits/napi/window/native_window_module.cpp b/wmtest/interfaces/kits/napi/window/native_window_module.cpp new file mode 100644 index 0000000000..c009e2aa99 --- /dev/null +++ b/wmtest/interfaces/kits/napi/window/native_window_module.cpp @@ -0,0 +1,233 @@ +/* + * 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 + +#include "native_window_module.h" +#include "window.h" +#include "window_scene.h" +#include "wm_common.h" +#include "wm_napi_common.h" + +namespace OHOS { +namespace Rosen { +namespace { +napi_value g_classWindow; +napi_status GetAbility(napi_env env, napi_callback_info info, AppExecFwk::Ability* &pAbility) +{ + napi_value global; + GNAPI_INNER(napi_get_global(env, &global)); + + napi_value jsAbility; + GNAPI_INNER(napi_get_named_property(env, global, "ability", &jsAbility)); + + GNAPI_INNER(napi_get_value_external(env, jsAbility, reinterpret_cast(&pAbility))); + + return napi_ok; +} +} // namespace + + +namespace NAPIWindow { +napi_value WindowConstructor(napi_env env, napi_callback_info info) +{ + napi_value jsthis = nullptr; + NAPI_CALL(env, napi_get_cb_info(env, info, nullptr, nullptr, &jsthis, nullptr)); + return jsthis; +} + +namespace ResetSize { +struct Param { + ::OHOS::AppExecFwk::Ability *ability; + int width; + int height; +}; + +void Async(napi_env env, std::unique_ptr& param) +{ + param->ability->GetScene()->GetMainWindow()->Resize(param->width, param->height); +} + +napi_value MainFunc(napi_env env, napi_callback_info info) +{ + GNAPI_LOG("Window Interface: ResetSize()"); + GNAPI_LOG("%{public}s called", __PRETTY_FUNCTION__); + constexpr int argumentSize = 2; + size_t argc = argumentSize; + napi_value argv[argc]; + + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr)); + + GNAPI_ASSERT(env, argc < argumentSize, "ResetSize need %{public}d arguments", argumentSize); + + auto param = std::make_unique(); + NAPI_CALL(env, GetAbility(env, info, param->ability)); + NAPI_CALL(env, napi_get_value_int32(env, argv[0], ¶m->width)); + NAPI_CALL(env, napi_get_value_int32(env, argv[1], ¶m->height)); + + return CreatePromise(env, __PRETTY_FUNCTION__, Async, nullptr, param); +} +} // namespace ResetSize + +namespace MoveTo { +struct Param { + ::OHOS::AppExecFwk::Ability *ability; + int x; + int y; +}; + +void Async(napi_env env, std::unique_ptr& param) +{ + param->ability->GetScene()->GetMainWindow()->MoveTo(param->x, param->y); +} + +napi_value MainFunc(napi_env env, napi_callback_info info) +{ + GNAPI_LOG("Window Interface: MoveTo()"); + GNAPI_LOG("%{public}s called", __PRETTY_FUNCTION__); + constexpr int argumentSize = 2; + size_t argc = argumentSize; + napi_value argv[argc]; + + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr)); + + GNAPI_ASSERT(env, argc < argumentSize, "MoveTo need %{public}d arguments", argumentSize); + + auto param = std::make_unique(); + NAPI_CALL(env, GetAbility(env, info, param->ability)); + NAPI_CALL(env, napi_get_value_int32(env, argv[0], ¶m->x)); + NAPI_CALL(env, napi_get_value_int32(env, argv[1], ¶m->y)); + + return CreatePromise(env, __PRETTY_FUNCTION__, Async, nullptr, param); +} +} // namespace MoveTo + +namespace SetWindowType { +struct Param { + ::OHOS::AppExecFwk::Ability *ability; + int windowType; +}; + +void Async(napi_env env, std::unique_ptr& param) +{ + param->ability->GetScene()->GetMainWindow()->SetWindowType(static_cast(param->windowType)); +} + +void CreateWindowTypeObject(napi_env env, napi_value value) +{ + SetMemberInt32(env, value, "TYPE_APP", static_cast(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW)); + SetMemberInt32(env, value, "TYPE_SYSTEM_ALERT", static_cast(WindowType::WINDOW_TYPE_SYSTEM_ALARM_WINDOW)); + SetMemberInt32(env, value, "TYPE_SYSTEM_VOLUME", static_cast(WindowType::WINDOW_TYPE_VOLUME_OVERLAY)); + SetMemberInt32(env, value, "TYPE_SYSTEM_PANEL", static_cast(WindowType::WINDOW_TYPE_PANEL)); +} + +napi_value MainFunc(napi_env env, napi_callback_info info) +{ + GNAPI_LOG("Window Interface: SetWindowType()"); + GNAPI_LOG("%{public}s called", __PRETTY_FUNCTION__); + constexpr int argumentSize = 1; + size_t argc = argumentSize; + napi_value argv[argc]; + + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr)); + + GNAPI_ASSERT(env, argc < argumentSize, "SetWindowType need %{public}d arguments", argumentSize); + + auto param = std::make_unique(); + NAPI_CALL(env, GetAbility(env, info, param->ability)); + NAPI_CALL(env, napi_get_value_int32(env, argv[0], ¶m->windowType)); + + return CreatePromise(env, __PRETTY_FUNCTION__, Async, nullptr, param); +} +} // namespace SetWindowType +} // namespace NAPIWindow + +namespace getTopWindow { +struct Param { + ::OHOS::AppExecFwk::Ability *ability; + WMError wret; + sptr window; +}; + +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!"); + param->wret = WMError::WM_ERROR_NULLPTR; + return; + } + param->wret = WMError::WM_OK; +} + +napi_value Resolve(napi_env env, std::unique_ptr& userdata) +{ + napi_value ret; + NAPI_CALL(env, napi_new_instance(env, g_classWindow, 0, nullptr, &ret)); + return ret; +} + +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(); + return CreatePromise(env, __PRETTY_FUNCTION__, Async, Resolve, param); +} +} // namespace getTopWindow + +napi_value WindowModuleInit(napi_env env, napi_value exports) +{ + GNAPI_LOG("%{public}s called", __PRETTY_FUNCTION__); + + napi_value nWindowType = nullptr; + NAPI_CALL(env, napi_create_object(env, &nWindowType)); + NAPIWindow::SetWindowType::CreateWindowTypeObject(env, nWindowType); + + napi_property_descriptor desc[] = { + DECLARE_NAPI_FUNCTION("resetSize", NAPIWindow::ResetSize::MainFunc), + DECLARE_NAPI_FUNCTION("moveTo", NAPIWindow::MoveTo::MainFunc), + DECLARE_NAPI_FUNCTION("setWindowType", NAPIWindow::SetWindowType::MainFunc), + }; + + NAPI_CALL(env, napi_define_class(env, "Window", NAPI_AUTO_LENGTH, + NAPIWindow::WindowConstructor, nullptr, + sizeof(desc) / sizeof(*desc), desc, &g_classWindow)); + + napi_property_descriptor exportFuncs[] = { + DECLARE_NAPI_FUNCTION("getTopWindow", getTopWindow::MainFunc), + DECLARE_NAPI_PROPERTY("WindowType", nWindowType), + DECLARE_NAPI_PROPERTY("Window", g_classWindow), + }; + + NAPI_CALL(env, napi_define_properties(env, + exports, sizeof(exportFuncs) / sizeof(*exportFuncs), exportFuncs)); + return exports; +} +} // namespace Rosen +} // namespace OHOS + +extern "C" __attribute__((constructor)) void RegisterModule(void) +{ + napi_module windowModule = { + .nm_version = 1, // NAPI v1 + .nm_flags = 0, // normal + .nm_filename = nullptr, + .nm_register_func = OHOS::Rosen::WindowModuleInit, + .nm_modname = "window", + .nm_priv = nullptr, + }; + napi_module_register(&windowModule); +} diff --git a/wmtest/interfaces/kits/napi/window/native_window_module.h b/wmtest/interfaces/kits/napi/window/native_window_module.h new file mode 100644 index 0000000000..c4a21c440c --- /dev/null +++ b/wmtest/interfaces/kits/napi/window/native_window_module.h @@ -0,0 +1,19 @@ +/* + * 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 INTERFACES_KITS_NAPI_GRAPHIC_WINDOW_NATIVE_WINDOW_MODULE_H +#define INTERFACES_KITS_NAPI_GRAPHIC_WINDOW_NATIVE_WINDOW_MODULE_H + +#endif // INTERFACES_KITS_NAPI_GRAPHIC_WINDOW_NATIVE_WINDOW_MODULE_H diff --git a/wmtest/interfaces/kits/napi/window_stage.js b/wmtest/interfaces/kits/napi/window_stage.js new file mode 100644 index 0000000000..43af79d1a0 --- /dev/null +++ b/wmtest/interfaces/kits/napi/window_stage.js @@ -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. + */ + +class WindowStage { + constructor(obj) { + this.__window_stage__ = obj + } + + setUIContent(context, url, storage) { + return this.__window_stage__.setUIContent(context, url, storage) + } +} + +export default WindowStage diff --git a/wmtest/interfaces/kits/napi/window_stage_module.cpp b/wmtest/interfaces/kits/napi/window_stage_module.cpp new file mode 100644 index 0000000000..b6ad1d3a65 --- /dev/null +++ b/wmtest/interfaces/kits/napi/window_stage_module.cpp @@ -0,0 +1,58 @@ +/* + * 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" + +extern const char _binary_window_stage_js_start[]; +extern const char _binary_window_stage_js_end[]; +extern const char _binary_window_stage_abc_start[]; +extern const char _binary_window_stage_abc_end[]; + +extern "C" __attribute__((constructor)) +void NAPI_application_WindowStage_AutoRegister() +{ + auto moduleManager = NativeModuleManager::GetInstance(); + NativeModule newModuleInfo = { + .name = "application.WindowStage", + .fileName = "application/libwindowstage.so/window_stage.js", + }; + + moduleManager->Register(&newModuleInfo); +} + +extern "C" __attribute__((visibility("default"))) +void NAPI_application_WindowStage_GetJSCode(const char **buf, int *bufLen) +{ + if (buf != nullptr) { + *buf = _binary_window_stage_js_start; + } + + if (bufLen != nullptr) { + *bufLen = _binary_window_stage_js_end - _binary_window_stage_js_start; + } +} + +// window_stage JS register +extern "C" __attribute__((visibility("default"))) +void NAPI_application_WindowStage_GetABCCode(const char **buf, int *buflen) +{ + if (buf != nullptr) { + *buf = _binary_window_stage_abc_start; + } + if (buflen != nullptr) { + *buflen = _binary_window_stage_abc_end - _binary_window_stage_abc_start; + } +} + diff --git a/wmtest/ohos.build b/wmtest/ohos.build new file mode 100644 index 0000000000..49aaabd0f0 --- /dev/null +++ b/wmtest/ohos.build @@ -0,0 +1,22 @@ +{ + "subsystem": "window", + "parts": { + "window_manager": { + "module_list": [ + "//foundation/windowmanager/interfaces/kits/js/declaration:window", + "//foundation/windowmanager/sa_profile:wms_sa_profile", + "//foundation/windowmanager/adapter:libwmadaptertest", + "//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" + ], + + "test_list": [ + ] + } + } +} diff --git a/wmtest/sa_profile/4605.xml b/wmtest/sa_profile/4605.xml new file mode 100644 index 0000000000..9197521b84 --- /dev/null +++ b/wmtest/sa_profile/4605.xml @@ -0,0 +1,26 @@ + + + + foundation + + 4605 + libwms.z.so + + + true + false + 1 + + \ No newline at end of file diff --git a/wmtest/sa_profile/4606.xml b/wmtest/sa_profile/4606.xml new file mode 100644 index 0000000000..7a02c334da --- /dev/null +++ b/wmtest/sa_profile/4606.xml @@ -0,0 +1,26 @@ + + + + foundation + + 4606 + libwms.z.so + + + true + false + 1 + + diff --git a/wmtest/sa_profile/BUILD.gn b/wmtest/sa_profile/BUILD.gn new file mode 100644 index 0000000000..f3a586d781 --- /dev/null +++ b/wmtest/sa_profile/BUILD.gn @@ -0,0 +1,22 @@ +# 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("//build/ohos/sa_profile/sa_profile.gni") + +ohos_sa_profile("wms_sa_profile") { + sources = [ + "4605.xml", + "4606.xml", + ] + part_name = "window_manager" +} diff --git a/wmtest/test/dm_native_test.cpp b/wmtest/test/dm_native_test.cpp new file mode 100644 index 0000000000..3373ab11ed --- /dev/null +++ b/wmtest/test/dm_native_test.cpp @@ -0,0 +1,96 @@ +/* + * 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 "dm_native_test.h" + +#include +#include +#include "wm_common.h" +#include "display_manager.h" +#include "singleton_container.h" + +using namespace OHOS::Rosen; + +namespace { +DMNativeTest g_autoload; +} // namespace + +std::string DMNativeTest::GetDescription() const +{ + constexpr const char *desc = "normal display"; + return desc; +} + +std::string DMNativeTest::GetDomain() const +{ + constexpr const char *desc = "dmclient"; + return desc; +} + +int32_t DMNativeTest::GetID() const +{ + constexpr int32_t id = 1; + return id; +} + +uint32_t DMNativeTest::GetLastTime() const +{ + constexpr uint32_t lastTime = LAST_TIME_FOREVER; + return lastTime; +} + +void DMNativeTest::Run(int32_t argc, const char **argv) +{ + printf("DMNativeTest run begin\n"); + sptr dms = DisplayManager::GetInstance(); + if (dms == nullptr) { + printf("dms error!\n"); + return; + } + + DisplayId displayId = dms->GetDefaultDisplayId(); + printf("defaultDisplayId: %llu\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(), + display->GetHeight(), display->GetFreshRate()); + } + + auto ids = dms->GetAllDisplayIds(); + for (auto id: ids) { + display = dms->GetDisplayById(displayId); + if (display == nullptr) { + printf("GetDisplayById(%llu): 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()); + } + } + + auto displays = dms->GetAllDisplays(); + for (auto disp: displays) { + if (disp == nullptr) { + printf("GetAllDisplays: failed!\n"); + } else { + printf("GetAllDisplays: id %llu, w %d, h %d, fps %u\n", disp->GetId(), disp->GetWidth(), + disp->GetHeight(), disp->GetFreshRate()); + } + } + + printf("DMNativeTest run finish\n"); +} diff --git a/wmtest/test/dm_native_test.h b/wmtest/test/dm_native_test.h new file mode 100644 index 0000000000..7b325bf81d --- /dev/null +++ b/wmtest/test/dm_native_test.h @@ -0,0 +1,40 @@ +/* + * 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_DM_NATIVE_TEST_H +#define OHOS_ROSEN_DM_NATIVE_TEST_H + +#include +#include "inative_test.h" + +namespace OHOS::Rosen { +class DMNativeTest : public INativeTest { +public: + virtual ~DMNativeTest() = default; + virtual std::string GetDescription() const override; + virtual std::string GetDomain() const override; + virtual int32_t GetID() const override; + virtual uint32_t GetLastTime() const override; + + virtual void Run(int32_t argc, const char **argv) override; + +private: + void PostTask(std::function func, uint32_t delayTime = 0); + void ExitTest(); + int64_t GetNowTime(); +}; +} + +#endif // OHOS_ROSEN_DM_NATIVE_TEST_H diff --git a/wmtest/test/wm_native_test.cpp b/wmtest/test/wm_native_test.cpp new file mode 100644 index 0000000000..6d63a5e21b --- /dev/null +++ b/wmtest/test/wm_native_test.cpp @@ -0,0 +1,74 @@ +/* + * 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_native_test.h" + +#include +#include +#include +#include "window.h" +#include "window_life_cycle_interface.h" +#include "window_option.h" +#include "window_scene.h" +#include "wm_common.h" + +using namespace OHOS::Rosen; + +namespace { +WMNativeTest g_autoload; +} // namespace + +std::string WMNativeTest::GetDescription() const +{ + constexpr const char *desc = "normal window"; + return desc; +} + +std::string WMNativeTest::GetDomain() const +{ + constexpr const char *desc = "wmclient"; + return desc; +} + +int32_t WMNativeTest::GetID() const +{ + constexpr int32_t id = 1; + return id; +} + +uint32_t WMNativeTest::GetLastTime() const +{ + constexpr uint32_t lastTime = LAST_TIME_FOREVER; + return lastTime; +} + +void WMNativeTest::Run(int32_t argc, const char **argv) +{ + int displayId = 0; + sptr listener = nullptr; + sptr scene = new WindowScene(); + std::shared_ptr abilityContext = nullptr; + WMError rtn = scene->Init(displayId, abilityContext, listener); + if (rtn != OHOS::Rosen::WMError::WM_OK) { + return; + } + + while(true) { + scene->GoForeground(); + sleep(3); + scene->GoBackground(); + sleep(3); + } +} diff --git a/wmtest/test/wm_native_test.h b/wmtest/test/wm_native_test.h new file mode 100644 index 0000000000..6b978531e6 --- /dev/null +++ b/wmtest/test/wm_native_test.h @@ -0,0 +1,39 @@ +/* + * 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_WM_NATIVE_TEST_H +#define OHOS_ROSEN_WM_NATIVE_TEST_H + +#include "inative_test.h" + +namespace OHOS::Rosen { +class WMNativeTest : public INativeTest { +public: + virtual ~WMNativeTest() = default; + virtual std::string GetDescription() const override; + virtual std::string GetDomain() const override; + virtual int32_t GetID() const override; + virtual uint32_t GetLastTime() const override; + + virtual void Run(int32_t argc, const char **argv) override; + +private: + void PostTask(std::function func, uint32_t delayTime = 0); + void ExitTest(); + int64_t GetNowTime(); +}; +} + +#endif // OHOS_ROSEN_WM_NATIVE_TEST_H diff --git a/wmtest/unittest/BUILD.gn b/wmtest/unittest/BUILD.gn new file mode 100644 index 0000000000..b034b6997b --- /dev/null +++ b/wmtest/unittest/BUILD.gn @@ -0,0 +1,85 @@ +# 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("//build/test.gni") +module_out_path = "window_manager/" + +group("unittest") { + testonly = true + + deps = [ ":ut_window_impl_test" ] +} + +## UnitTest ut_window_impl_test {{{ +ohos_unittest("ut_window_impl_test") { + module_out_path = module_out_path + + sources = [ "src/window_impl_test.cpp" ] + + deps = [ ":unittest_wmtest_common" ] +} + +## UnitTest ut_window_impl_test }}} + +## Build unittest_wmtest_common.a {{{ +config("unittest_wmtest_common_public_config") { + include_dirs = [ + "//foundation/windowmanager/wm/include", + "//foundation/windowmanager/wmserver/include", + "include", + "//foundation/windowmanager/interfaces/innerkits/wm", + "//utils/native/base/include", + "//foundation/communication/ipc/interfaces/innerkits/ipc_core/include", + "//base/hiviewdfx/hilog/interfaces/native/innerkits/include", + "//foundation/windowmanager/utils/include", + "//third_party/googletest/googlemock/include", + + #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", + "-Werror", + "-g3", + "-Dprivate=public", + "-Dprotected=public", + ] +} + +ohos_static_library("unittest_wmtest_common") { + visibility = [ ":*" ] + testonly = true + + public_configs = [ ":unittest_wmtest_common_public_config" ] + + deps = [ + "//foundation/windowmanager/wm:libwm", + "//foundation/windowmanager/wm:libwmutil", + "//foundation/windowmanager/wmserver:libwms", + "//third_party/googletest:gmock", + "//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", + ] + + external_deps = [ + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + ] +} +## Build unittest_wmtest_common.a }}} diff --git a/wmtest/unittest/include/mock/mock_window_adapter.h b/wmtest/unittest/include/mock/mock_window_adapter.h new file mode 100644 index 0000000000..b839fe7819 --- /dev/null +++ b/wmtest/unittest/include/mock/mock_window_adapter.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 UNITTEST_MOCK_WINDOW_ADAPTER_H +#define UNITTEST_MOCK_WINDOW_ADAPTER_H + +#include + +#include "window_adapter.h" + +namespace OHOS { +namespace Rosen { +class MockWindowAdapter : public WindowAdapter { +public: + MOCK_METHOD1(AddWindow, WMError(sptr& windowProperty)); + MOCK_METHOD1(RemoveWindow, WMError(uint32_t windowId)); + MOCK_METHOD0(ClearWindowAdapter, void()); +}; +} +} // namespace OHOS + + +#endif \ No newline at end of file diff --git a/wmtest/unittest/include/mock/singleton_mocker.h b/wmtest/unittest/include/mock/singleton_mocker.h new file mode 100644 index 0000000000..c3bce98c20 --- /dev/null +++ b/wmtest/unittest/include/mock/singleton_mocker.h @@ -0,0 +1,54 @@ +/* + * 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 UNITTEST_MOCK_SINGLETON_MOCKER_H +#define UNITTEST_MOCK_SINGLETON_MOCKER_H + +#include "singleton_container.h" +namespace OHOS { +namespace Rosen { +template +class SingletonMocker { +public: + SingletonMocker() + { + origin = SingletonContainer::Get(); + mock = new MockT(); + SingletonContainer::Set(mock); + } + + ~SingletonMocker() + { + SingletonContainer::Set(origin); + } + + sptr Origin() + { + return origin; + } + + sptr Mock() + { + return mock; + } + +private: + sptr origin = nullptr; + sptr mock = nullptr; +}; +} // namespace Rosen +} // namespace OHOS + +#endif // FRAMEWORKS_WM_TEST_UNITTEST_MOCK_SINGLETON_MOCKER_H diff --git a/wmtest/unittest/include/test_header.h b/wmtest/unittest/include/test_header.h new file mode 100644 index 0000000000..31f8bfbd0a --- /dev/null +++ b/wmtest/unittest/include/test_header.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 UNITTEST_TEST_HEADER_H +#define UNITTEST_TEST_HEADER_H + +#include "window_manager_hilog.h" + +namespace OHOS { +namespace Rosen { +#define _WMT_CPRINTF(color, func, fmt, ...) \ + func({LOG_CORE, 0, "WM_UINTTEST"}, "\033[" #color "m" "<%{public}d>" fmt "\033[0m", __LINE__, ##__VA_ARGS__) +#define WMTLOGI(color, fmt, ...) \ + _WMT_CPRINTF(color, HiviewDFX::HiLog::Info, "%{public}s: " fmt, __func__, ##__VA_ARGS__) + +#define PART(part) WMTLOGI(33, part); if (const char *strPart = part) +#define STEP(desc) WMTLOGI(34, desc); if (const char *strDesc = desc) + +#define STEP_CONDITION(condition) strPart << ": " << strDesc << " (" << condition << ")" + +#define STEP_ASSERT_(l, r, func, opstr) ASSERT_##func(l, r) << STEP_CONDITION(#l " " opstr " " #r) + +#define STEP_ASSERT_EQ(l, r) STEP_ASSERT_(l, r, EQ, "==") +#define STEP_ASSERT_NE(l, r) STEP_ASSERT_(l, r, NE, "!=") +#define STEP_ASSERT_GE(l, r) STEP_ASSERT_(l, r, GE, ">=") +#define STEP_ASSERT_LE(l, r) STEP_ASSERT_(l, r, LE, "<=") +#define STEP_ASSERT_GT(l, r) STEP_ASSERT_(l, r, GT, ">") +#define STEP_ASSERT_LT(l, r) STEP_ASSERT_(l, r, LT, "<") +} // namespace Rosen +} // namespace OHOS +#endif // UNITTEST_TEST_HEADER_H diff --git a/wmtest/unittest/include/window_impl_test.h b/wmtest/unittest/include/window_impl_test.h new file mode 100644 index 0000000000..f9adbf5f59 --- /dev/null +++ b/wmtest/unittest/include/window_impl_test.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 UNITTEST_WINDOW_IMPL_TEST_H +#define UNITTEST_WINDOW_IMPL_TEST_H + +#include +#include "window_impl.h" + +namespace OHOS { +namespace Rosen { +class WindowImplTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + virtual void SetUp() override; + virtual void TearDown() override; + + static inline sptr window_ = nullptr; + static inline sptr property_ = nullptr; +}; +} // namespace ROSEN +} // namespace OHOS + +#endif // FRAMEWORKS_WM_TEST_UNITTEST_WINDOW_IMPL_TEST_H \ No newline at end of file diff --git a/wmtest/unittest/src/window_impl_test.cpp b/wmtest/unittest/src/window_impl_test.cpp new file mode 100644 index 0000000000..52d585fb80 --- /dev/null +++ b/wmtest/unittest/src/window_impl_test.cpp @@ -0,0 +1,47 @@ +/* + * 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_impl_test.h" +#include "mock/mock_window_adapter.h" +#include "mock/singleton_mocker.h" +#include "test_header.h" +#include "window_property.h" + + +namespace OHOS { +namespace Rosen { +using namespace testing; + +void WindowImplTest::SetUpTestCase() +{ + property_ = sptr(new WindowProperty()); + property_->SetWindowId(0); + window_ = sptr(new WindowImpl(property_)); +} + +void WindowImplTest::TearDownTestCase() +{ +} + +void WindowImplTest::SetUp() +{ +} + +void WindowImplTest::TearDown() +{ +} + +} // namespace Rosen +} // namespace OHOS diff --git a/wmtest/utils/include/single_instance.h b/wmtest/utils/include/single_instance.h new file mode 100644 index 0000000000..b255caf73d --- /dev/null +++ b/wmtest/utils/include/single_instance.h @@ -0,0 +1,44 @@ +/* + * 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_SINGLE_INSTANCE_H +#define OHOS_SINGLE_INSTANCE_H +namespace OHOS { +namespace Rosen { +#define DECLARE_SINGLE_INSTANCE_BASE(className) \ +public: \ + static sptr GetInstance(); \ +private: \ + className(const className&) = delete; \ + className& operator= (const className&) = delete; \ + className(className&&) = delete; \ + className& operator= (className&&) = delete; \ + + +#define DECLARE_SINGLE_INSTANCE(className) \ + DECLARE_SINGLE_INSTANCE_BASE(className) \ +private: \ + className() = default; \ + ~className() = default; \ + +#define IMPLEMENT_SINGLE_INSTANCE(className) \ +sptr className::GetInstance() \ +{ \ + static sptr instance = new className(); \ + return instance; \ +} +} // namespace OHOS +} +#endif // OHOS_SINGLE_INSTANCE_H diff --git a/wmtest/utils/include/singleton_container.h b/wmtest/utils/include/singleton_container.h new file mode 100644 index 0000000000..68d6d7e8ec --- /dev/null +++ b/wmtest/utils/include/singleton_container.h @@ -0,0 +1,81 @@ +/* + * 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_SINGLETON_CONTAINER_H +#define OHOS_SINGLETON_CONTAINER_H + +#include +#include +#include +#include +#include + +#include + +namespace OHOS { +namespace Rosen { +class SingletonContainer : public RefBase { +public: + static sptr GetInstance(); + + 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); + + template + static sptr 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; + } + + template + static void Set(const sptr &ptr) + { + 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); + } + +private: + SingletonContainer() = default; + virtual ~SingletonContainer() override; + static inline sptr instance = nullptr; + + struct Singleton { + std::any value; + int32_t refCount; + }; + std::map stringMap; + std::map singletonMap; + std::map> dependencySetMap; +}; +} // namespace Rosen +} // namespace OHOS + +#endif // FRAMEWORKS_WM_INCLUDE_SINGLETON_CONTAINER_H diff --git a/wmtest/utils/include/singleton_delegator.h b/wmtest/utils/include/singleton_delegator.h new file mode 100644 index 0000000000..dae000468f --- /dev/null +++ b/wmtest/utils/include/singleton_delegator.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_SINGLETON_DELEGATOR_H +#define OHOS_SINGLETON_DELEGATOR_H + +#include "singleton_container.h" + +#define MOCKABLE virtual + +namespace OHOS { +namespace Rosen { +template +class SingletonDelegator { +public: + SingletonDelegator() + { + nameT = __PRETTY_FUNCTION__; + nameT = nameT.substr(nameT.find("T = ")); + nameT = nameT.substr(sizeof("T ="), nameT.length() - sizeof("T = ")); + SingletonContainer::GetInstance()->AddSingleton(nameT, T::GetInstance()); + } + ~SingletonDelegator() = default; + + template + sptr 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); + } + return ret; + } + +private: + std::string nameT; +}; +} // namespace Rosen +} // namespace OHOS + +#endif // FRAMEWORKS_WM_INCLUDE_SINGLETON_DELEGATOR_H diff --git a/wmtest/utils/include/static_call.h b/wmtest/utils/include/static_call.h new file mode 100644 index 0000000000..e505d2b7ab --- /dev/null +++ b/wmtest/utils/include/static_call.h @@ -0,0 +1,39 @@ +/* + * 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_STATIC_CALL_H +#define OHOS_STATIC_CALL_H + +#include +#include "singleton_delegator.h" +#include "single_instance.h" +#include "window.h" +#include "window_option.h" +namespace OHOS { +namespace Rosen { +class StaticCall : public RefBase { + DECLARE_SINGLE_INSTANCE_BASE(StaticCall); +public: + virtual sptr CreateWindow(const std::string& windowName, + sptr& option, const sptr& abilityToken = nullptr); +protected: + StaticCall() = default; +private: + static inline SingletonDelegator delegator_; +}; +} // namespace ROSEN +} // namespace OHOS + +#endif // FRAMEWORKS_WM_TEST_UT_STATIC_CALL_H \ No newline at end of file diff --git a/wmtest/utils/include/window_manager_hilog.h b/wmtest/utils/include/window_manager_hilog.h new file mode 100644 index 0000000000..bf790ce888 --- /dev/null +++ b/wmtest/utils/include/window_manager_hilog.h @@ -0,0 +1,50 @@ +/* + * 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_WINDOW_MANAGER_HILOG_H +#define OHOS_WM_INCLUDE_WINDOW_MANAGER_HILOG_H + +#include "hilog/log.h" +namespace OHOS { +namespace Rosen { +static constexpr OHOS::HiviewDFX::HiLogLabel LOG_LABEL = {LOG_CORE, 0, "WindowManager"}; + +#define WLOG_F(...) (void)OHOS::HiviewDFX::HiLog::Fatal(LOG_LABEL, __VA_ARGS__) +#define WLOG_E(...) (void)OHOS::HiviewDFX::HiLog::Error(LOG_LABEL, __VA_ARGS__) +#define WLOG_W(...) (void)OHOS::HiviewDFX::HiLog::Warn(LOG_LABEL, __VA_ARGS__) +#define WLOG_I(...) (void)OHOS::HiviewDFX::HiLog::Info(LOG_LABEL, __VA_ARGS__) +#define WLOG_D(...) (void)OHOS::HiviewDFX::HiLog::Debug(LOG_LABEL, __VA_ARGS__) + +#define _W_DFUNC HiviewDFX::HiLog::Debug +#define _W_IFUNC HiviewDFX::HiLog::Info +#define _W_WFUNC HiviewDFX::HiLog::Warn +#define _W_EFUNC HiviewDFX::HiLog::Error + +#define _W_CPRINTF(func, fmt, ...) func(LABEL, "<%{public}d>" fmt, __LINE__, ##__VA_ARGS__) + +#define WLOGD(fmt, ...) _W_CPRINTF(_W_DFUNC, fmt, ##__VA_ARGS__) +#define WLOGI(fmt, ...) _W_CPRINTF(_W_IFUNC, fmt, ##__VA_ARGS__) +#define WLOGW(fmt, ...) _W_CPRINTF(_W_WFUNC, fmt, ##__VA_ARGS__) +#define WLOGE(fmt, ...) _W_CPRINTF(_W_EFUNC, fmt, ##__VA_ARGS__) + +#define _W_FUNC __func__ + +#define WLOGFD(fmt, ...) WLOGD("%{public}s: " fmt, _W_FUNC, ##__VA_ARGS__) +#define WLOGFI(fmt, ...) WLOGI("%{public}s: " fmt, _W_FUNC, ##__VA_ARGS__) +#define WLOGFW(fmt, ...) WLOGW("%{public}s: " fmt, _W_FUNC, ##__VA_ARGS__) +#define WLOGFE(fmt, ...) WLOGE("%{public}s: " fmt, _W_FUNC, ##__VA_ARGS__) +} // namespace OHOS +} +#endif // FRAMEWORKS_WM_INCLUDE_WINDOW_MANAGER_HILOG_H diff --git a/wmtest/utils/src/singleton_container.cpp b/wmtest/utils/src/singleton_container.cpp new file mode 100644 index 0000000000..0b851fdae2 --- /dev/null +++ b/wmtest/utils/src/singleton_container.cpp @@ -0,0 +1,110 @@ +/* + * 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 "singleton_container.h" +#include +#include "window_manager_hilog.h" + +namespace OHOS { +namespace Rosen { +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) { + auto it = singletonMap.begin(); + while (it != singletonMap.end()) { + if (it->second.refCount > 0) { + it++; + continue; + } + + if (dependencySetMap.find(it->first) != dependencySetMap.end()) { + for (auto mid : dependencySetMap[it->first]) { + singletonMap[mid].refCount--; + } + dependencySetMap.erase(it->first); + } + + for (const auto &[k, v] : stringMap) { + if (v == it->first) { + WLOGFD("remove %{public}s", k.c_str()); + break; + } + } + singletonMap.erase(it++); + } + } +} + +void SingletonContainer::AddSingleton(const std::string &name, const std::any &instance) +{ + if (stringMap.find(name) == stringMap.end()) { + static int32_t nextId = 0; + singletonMap[nextId].value = instance; + singletonMap[nextId].refCount = 0; + WLOGFD("add %{public}s", name.c_str()); + stringMap[name] = nextId++; + } else { + WLOGFE("add failed: %{public}s", name.c_str()); + } +} + +void SingletonContainer::SetSingleton(const std::string &name, const std::any &instance) +{ + if (stringMap.find(name) == stringMap.end()) { + AddSingleton(name, instance); + } else { + WLOGFD("set %{public}s", name.c_str()); + singletonMap[stringMap[name]].value = instance; + } +} + +const std::any &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 singletonMap[stringMap[name]].value; +} + +const std::any &SingletonContainer::DependOn(const std::string &instance, const std::string &name) +{ + auto &instanceDependencySet = dependencySetMap[stringMap[instance]]; + if (instanceDependencySet.find(stringMap[name]) == instanceDependencySet.end()) { + WLOGFD("%{public}s dependon %{public}s", instance.c_str(), name.c_str()); + instanceDependencySet.insert(stringMap[name]); + singletonMap[stringMap[name]].refCount++; + } + return GetSingleton(name); +} +} // namespace Rosen +} // namespace OHOS diff --git a/wmtest/utils/src/static_call.cpp b/wmtest/utils/src/static_call.cpp new file mode 100644 index 0000000000..5b8797a3b1 --- /dev/null +++ b/wmtest/utils/src/static_call.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 "static_call.h" + +namespace OHOS { +namespace Rosen { +IMPLEMENT_SINGLE_INSTANCE(StaticCall); + +sptr StaticCall::CreateWindow(const std::string& windowName, + sptr& option, const sptr& abilityToken) +{ + return Window::Create(windowName, option, abilityToken); +} +} // namespace Rosen +} // namespace OHOS \ No newline at end of file diff --git a/wmtest/wm/BUILD.gn b/wmtest/wm/BUILD.gn new file mode 100644 index 0000000000..a517968506 --- /dev/null +++ b/wmtest/wm/BUILD.gn @@ -0,0 +1,161 @@ +# 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("//build/ohos.gni") + +config("libwm_config") { + visibility = [ ":*" ] + + include_dirs = [ + "include", + "//utils/system/safwk/native/include", + "//foundation/windowmanager/wmserver/include", + "//foundation/windowmanager/dm/include", + "//foundation/windowmanager/dmserver/include", + "//foundation/windowmanager/utils/include", + + # 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", + "//third_party/node/deps/icu-small/source/common", + "//foundation/aafwk/standard/interfaces/innerkits/ability_manager/include", + "//foundation/aafwk/standard/interfaces/innerkits/want/include/ohos/aafwk/content", + "//foundation/distributedschedule/dmsfwk/services/dtbschedmgr/include", + "//foundation/aafwk/standard/interfaces/innerkits/base/include", + + # abilityContext end + + # weston adapter + "//foundation/windowmanager/adapter/include", + "//foundation/graphic/standard/interfaces/innerkits", + "//foundation/graphic/standard/interfaces/innerkits/wm", + "//foundation/graphic/standard/interfaces/innerkits/common", + + # weston adapter end + ] + + cflags = [ + "-Wall", + "-Werror", + "-g3", + ] +} + +config("libwm_public_config") { + include_dirs = [ + "//foundation/windowmanager/interfaces/innerkits/wm", + "//foundation/windowmanager/wmserver/include", + "//foundation/windowmanager/dmserver/include", + "//foundation/windowmanager/utils/include", + "../interfaces/innerkits/dm", + ] +} + +## Build libwmutil.so +ohos_shared_library("libwmutil") { + sources = [ + "../dmserver/src/display_info.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", + ] + + configs = [ ":libwm_config" ] + + public_configs = [ ":libwm_public_config" ] + + deps = [ + "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog", + "//utils/native/base:utils", + ] + + public_deps = [ + # 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 = [ "ipc:ipc_core" ] + + part_name = "window_manager" + subsystem_name = "window" +} + +## Build libwm.so +ohos_shared_library("libwm") { + sources = [ + "../dm/src/display.cpp", + "../dm/src/display_manager.cpp", + "../dm/src/display_manager_adapter.cpp", + "../dm/src/monitor.cpp", + "../utils/src/static_call.cpp", + "src/input_transfer_station.cpp", + "src/vsync_station.cpp", + "src/window.cpp", + "src/window_adapter.cpp", + "src/window_agent.cpp", + "src/window_impl.cpp", + "src/window_input_channel.cpp", + "src/window_scene.cpp", + "src/window_stub.cpp", + ] + + configs = [ ":libwm_config" ] + + public_configs = [ ":libwm_public_config" ] + + 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", + + # weston adapter + "//foundation/windowmanager/adapter:libwmadaptertest", + + # ace + "//foundation/ace/ace_engine/interfaces/innerkits/ace:ace_uicontent", + ] + + public_deps = [ + # native value + # RSSurface + "//foundation/ace/napi:ace_napi", + + # vsync + "//foundation/graphic/standard:libvsync_client", + "//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", + "//foundation/multimodalinput/input/frameworks/proxy:libmmi-common", + + # weston adapter + "//foundation/windowmanager/adapter:libwmadaptertest", + ] + + external_deps = [ + "aafwk_standard:ability_context_native", + "ipc:ipc_core", + ] + + part_name = "window_manager" + subsystem_name = "window" +} diff --git a/wmtest/wm/include/README.md b/wmtest/wm/include/README.md new file mode 100644 index 0000000000..f0321dc5d0 --- /dev/null +++ b/wmtest/wm/include/README.md @@ -0,0 +1 @@ +Store code of window client inner header files diff --git a/wmtest/wm/include/input_transfer_station.h b/wmtest/wm/include/input_transfer_station.h new file mode 100644 index 0000000000..5c8fa1466f --- /dev/null +++ b/wmtest/wm/include/input_transfer_station.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_INPUT_TRANSFER_STATION +#define OHOS_INPUT_TRANSFER_STATION + + +#include +#include +#include "input_manager.h" +#include "pointer_event.h" +#include "window.h" +#include "window_input_channel.h" +#include "vsync_station.h" + +namespace OHOS { +namespace Rosen { +class InputEventListener; +class InputTransferStation : public RefBase { +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_; +}; +class InputEventListener: public RefBase, public MMI::IInputEventConsumer { +public: + InputEventListener() = default; + void OnInputEvent(std::shared_ptr pointerEvent) const override; + void OnInputEvent(std::shared_ptr keyEvent) const override; + void OnInputEvent(std::shared_ptr axisEvent) const override; +}; +} +} + + +#endif // OHOS_INPUT_TRANSFER_STATION diff --git a/wmtest/wm/include/vsync_station.h b/wmtest/wm/include/vsync_station.h new file mode 100644 index 0000000000..eba3a26caf --- /dev/null +++ b/wmtest/wm/include/vsync_station.h @@ -0,0 +1,59 @@ +/* + * 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_VSYNC_STATION_H +#define OHOS_VSYNC_STATION_H + +#include +#include +#include +#include +#include + +#include +#include + +#include "single_instance.h" + +namespace OHOS { +namespace Rosen { +class VsyncStation : public RefBase { +DECLARE_SINGLE_INSTANCE_BASE(VsyncStation); +using OnCallback = std::function; +public: + enum class CallbackType { + CALLBACK_INPUT = 0, + CALLBACK_FRAME = 1, + }; + struct VsyncCallback { + OnCallback onCallback; + }; + ~VsyncStation() = default; + void RequestVsync(CallbackType type, std::shared_ptr vsyncCallback); + +private: + FrameCallback callback_; + VsyncStation() = default; + static void OnVsync(int64_t nanoTimestamp, void* client); + void VsyncCallbackInner(int64_t nanoTimestamp); + std::atomic_bool hasRequestedVsync_ {false}; + std::map>> vsyncCallbacks_ = { + {CallbackType::CALLBACK_INPUT, {}}, + {CallbackType::CALLBACK_FRAME, {}}, + }; +}; +} // namespace Rosen +} // namespace OHOS +#endif // OHOS_VSYNC_STATION_H \ No newline at end of file diff --git a/wmtest/wm/include/window_adapter.h b/wmtest/wm/include/window_adapter.h new file mode 100644 index 0000000000..49ca563360 --- /dev/null +++ b/wmtest/wm/include/window_adapter.h @@ -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. + */ + +#ifndef OHOS_WINDOW_ADAPTER_H +#define OHOS_WINDOW_ADAPTER_H + +#include + +#include "window.h" +#include "window_proxy.h" +#include "single_instance.h" +#include "singleton_delegator.h" +#include "window_property.h" +#include "window_manager_interface.h" +namespace OHOS { +namespace Rosen { +class WMSDeathRecipient : public IRemoteObject::DeathRecipient { +public: + virtual void OnRemoteDied(const wptr& wptrDeath) override; +}; + +class WindowAdapter : public RefBase { + DECLARE_SINGLE_INSTANCE_BASE(WindowAdapter); +public: + ~WindowAdapter() = default; + virtual WMError CreateWindow(sptr& window, sptr& windowProperty, + std::shared_ptr surfaceNode, uint32_t& windowId); + virtual WMError AddWindow(sptr& windowProperty); + virtual WMError RemoveWindow(uint32_t windowId); + virtual WMError DestroyWindow(uint32_t windowId); + virtual WMError SaveAbilityToken(const sptr& abilityToken, uint32_t windowId); + 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 void ClearWindowAdapter(); +protected: + WindowAdapter() = default; +private: + static inline SingletonDelegator delegator; + bool InitWMSProxyLocked(); + + std::mutex mutex_; + sptr windowManagerServiceProxy_ = nullptr; + sptr wmsDeath_ = nullptr; +}; +} // namespace Rosen +} // namespace OHOS +#endif // OHOS_WINDOW_ADAPTER_H diff --git a/wmtest/wm/include/window_agent.h b/wmtest/wm/include/window_agent.h new file mode 100644 index 0000000000..31bd1ccd4b --- /dev/null +++ b/wmtest/wm/include/window_agent.h @@ -0,0 +1,39 @@ +/* + * 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_AGENT_H +#define OHOS_WINDOW_AGENT_H + +#include "window_stub.h" +#include "window_impl.h" +#include "window_property.h" + +namespace OHOS { +namespace Rosen { +class WindowAgent : public WindowStub { +public: + WindowAgent(sptr& window); + ~WindowAgent() = default; + void UpdateWindowProperty(const WindowProperty& windowProperty) override; + void UpdateWindowRect(const struct Rect& rect) override; + void UpdateWindowMode(WindowMode mode) override; + void UpdateFocusStatus(bool focused) override; + +private: + sptr window_; +}; +} // namespace Rosen +} // namespace OHOS +#endif // OHOS_WINDOW_AGENT_H diff --git a/wmtest/wm/include/window_impl.h b/wmtest/wm/include/window_impl.h new file mode 100644 index 0000000000..17766e3f10 --- /dev/null +++ b/wmtest/wm/include/window_impl.h @@ -0,0 +1,122 @@ +/* + * 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_IMPL_H +#define OHOS_ROSEN_WINDOW_IMPL_H +#include +#include +#include +#include +#include "window.h" +#include "input_transfer_station.h" +#include "window_property.h" + +namespace OHOS { +namespace Rosen { +class WindowImpl : public Window { +#define CALL_LIFECYCLE_LISTENER(windowLifecycleCb, uiContentCb) \ + do { \ + if (lifecycleListener_ != nullptr) { \ + lifecycleListener_->windowLifecycleCb(); \ + } \ + if (uiContent_ != nullptr) { \ + uiContent_->uiContentCb(); \ + } \ + } while (0); + +public: + WindowImpl(const sptr& option); + ~WindowImpl(); + + static sptr Find(const std::string& id); + + virtual std::shared_ptr GetSurfaceNode() const override; + virtual Rect GetRect() const override; + virtual WindowType GetType() const override; + virtual WindowMode GetMode() const override; + virtual const std::string& GetWindowName() const override; + virtual uint32_t GetWindowId() override; + virtual WMError SetWindowType(WindowType type) override; + virtual WMError SetWindowMode(WindowMode mode) override; + + WMError Create(const std::string& parentName, const sptr& abilityToken = nullptr); + virtual WMError Destroy() override; + virtual WMError Show() override; + virtual WMError Hide() override; + virtual WMError MoveTo(int32_t x, int32_t y) override; + virtual WMError Resize(uint32_t width, uint32_t height) override; + + virtual WMError RequestFocus() const override; + virtual void AddInputEventListener(std::shared_ptr& inputEventListener) override; + + virtual void RegisterLifeCycleListener(sptr& listener) override; + virtual void RegisterWindowChangeListener(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; + void UpdateFocusStatus(bool focused); + + virtual WMError SetUIContent(std::shared_ptr context, + std::string& url, NativeEngine* engine, NativeValue* storage) override; + +private: + inline void NotifyAfterForeground() const + { + CALL_LIFECYCLE_LISTENER(AfterForeground, Foreground); + } + inline void NotifyAfterBackground() const + { + CALL_LIFECYCLE_LISTENER(AfterBackground, Background); + } + inline void NotifyAfterFocused() const + { + CALL_LIFECYCLE_LISTENER(AfterFocused, Focus); + } + inline void NotifyAfterUnFocused() const + { + CALL_LIFECYCLE_LISTENER(AfterUnFocused, UnFocus); + } + inline void NotifyBeforeDestroy() const + { + if (uiContent_ != nullptr) { + uiContent_->Destroy(); + } + } + void SetDefaultOption(); // for api7 + bool IsWindowValid() const; + + enum WindowState { + STATE_INITIAL, + STATE_CREATED, + STATE_SHOWN, + STATE_HIDDEN, + STATE_DESTROYED, + STATE_BOTTOM = STATE_DESTROYED, + }; + + static std::map>> windowMap_; + sptr property_; + WindowState state_ { STATE_INITIAL }; + sptr lifecycleListener_; + sptr windowChangeListener_; + std::shared_ptr surfaceNode_; + std::string name_; + std::unique_ptr uiContent_; +}; +} +} +#endif // OHOS_ROSEN_WINDOW_IMPL_H diff --git a/wmtest/wm/include/window_input_channel.h b/wmtest/wm/include/window_input_channel.h new file mode 100644 index 0000000000..fb700a1d54 --- /dev/null +++ b/wmtest/wm/include/window_input_channel.h @@ -0,0 +1,44 @@ +/* + * 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 +#include "refbase.h" +#include "vsync_station.h" +#ifndef OHOS_WINDOW_INPUT_CHANNEL +#define OHOS_WINDOW_INPUT_CHANNEL + +namespace OHOS { +namespace Rosen { +class WindowInputChannel : public RefBase { +public: + WindowInputChannel(const sptr& window); + ~WindowInputChannel() = default; + void HandlePointerEvent(std::shared_ptr& pointerEvent); + void HandleKeyEvent(std::shared_ptr& keyEvent); + void SetInputListener(std::shared_ptr& listener); +private: + void OnVsync(int64_t timeStamp); + std::vector> pointerEventPool_; + sptr window_; + std::shared_ptr callback_ = + std::make_shared(VsyncStation::VsyncCallback()); + static const int32_t MAX_INPUT_NUM = 100; + std::shared_ptr inputListener_; +}; +} +} + + +#endif // OHOS_WINDOW_INPUT_CHANNEL diff --git a/wmtest/wm/include/window_interface.h b/wmtest/wm/include/window_interface.h new file mode 100644 index 0000000000..846ded8652 --- /dev/null +++ b/wmtest/wm/include/window_interface.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_WINDOW_INTERFACE_H +#define OHOS_WINDOW_INTERFACE_H + +#include "iremote_broker.h" +#include "window_property.h" + +namespace OHOS { +namespace Rosen { +class IWindow : public IRemoteBroker { +public: + DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.IWindow"); + + enum { + TRANS_ID_UPDATE_WINDOW_PROPERTY = 1, + TRANS_ID_UPDATE_WINDOW_RECT, + TRANS_ID_UPDATE_WINDOW_MODE, + TRANS_ID_UPDATE_FOCUS_STATUS, + }; + + 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; +}; +} // namespace Rosen +} // namespace OHOS +#endif // OHOS_WINDOW_INTERFACE_H diff --git a/wmtest/wm/include/window_property.h b/wmtest/wm/include/window_property.h new file mode 100644 index 0000000000..f8b9ed4ca0 --- /dev/null +++ b/wmtest/wm/include/window_property.h @@ -0,0 +1,79 @@ +/* + * 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_PROPERTY_H +#define OHOS_ROSEN_WINDOW_PROPERTY_H + +#include +#include +#include "parcel.h" +#include "wm_common.h" + +namespace OHOS { +namespace Rosen { +class WindowProperty : public Parcelable { +public: + WindowProperty() = default; + ~WindowProperty() = default; + + void SetWindowRect(const struct Rect& rect); + void SetWindowType(WindowType type); + void SetWindowMode(WindowMode mode); + void SetFullScreen(bool isFullScreen); + void SetFocusable(bool isFocusable); + void SetTouchable(bool isTouchable); + void SetPrivacyMode(bool isPrivate); + void SetTransparent(bool isTransparent); + void SetAlpha(float alpha); + void SetDisplayId(int32_t displayId); + void SetWindowId(uint32_t windowId); + void SetParentId(uint32_t parentId); + void SetWindowFlags(uint32_t flags); + + Rect GetWindowRect() const; + WindowType GetWindowType() const; + WindowMode GetWindowMode() const; + bool GetFullScreen() const; + bool GetFocusable() const; + bool GetTouchable() const; + bool GetPrivacyMode() const; + bool GetTransparent() const; + float GetAlpha() const; + int32_t GetDisplayId() const; + uint32_t GetWindowId() const; + uint32_t GetParentId() const; + uint32_t GetWindowFlags() 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 }; + WindowMode mode_ { WindowMode::WINDOW_MODE_FULLSCREEN }; + uint32_t flags_ { 0 }; + bool isFullScreen_ { true }; + bool focusable_ { true }; + bool touchable_ { true }; + bool isPrivacyMode_ { false }; + bool isTransparent_ { false }; + float alpha_ { 1.0f }; + int32_t displayId_ { 0 }; + uint32_t windowId_ { 0 }; + uint32_t parentId_ { 0 }; +}; +} +} +#endif // OHOS_ROSEN_WINDOW_PROPERTY_H diff --git a/wmtest/wm/include/window_proxy.h b/wmtest/wm/include/window_proxy.h new file mode 100644 index 0000000000..8e1ea4a52e --- /dev/null +++ b/wmtest/wm/include/window_proxy.h @@ -0,0 +1,40 @@ +/* + * 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_PROXY_H +#define OHOS_WINDOW_PROXY_H + +#include "window_interface.h" +#include "iremote_proxy.h" + +namespace OHOS { +namespace Rosen { +class WindowProxy : public IRemoteProxy { +public: + explicit WindowProxy(const sptr& impl) : IRemoteProxy(impl) {}; + + ~WindowProxy() {}; + + void UpdateWindowProperty(const WindowProperty& windowProperty) override; + void UpdateWindowRect(const struct Rect& rect) override; + void UpdateWindowMode(WindowMode mode) override; + void UpdateFocusStatus(bool focused) override; + +private: + static inline BrokerDelegator delegator_; +}; +} // namespace Rosen +} // namespace OHOS +#endif // OHOS_WINDOW_PROXY_H diff --git a/wmtest/wm/include/window_stub.h b/wmtest/wm/include/window_stub.h new file mode 100644 index 0000000000..efc29d3b50 --- /dev/null +++ b/wmtest/wm/include/window_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_STUB_H +#define OHOS_WINDOW_STUB_H + +#include "window_interface.h" +#include "iremote_stub.h" + +namespace OHOS { +namespace Rosen { +class WindowStub : public IRemoteStub { +public: + WindowStub() = default; + ~WindowStub() = default; + + virtual int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, + MessageOption &option) override; +}; +} // namespace Rosen +} // namespace OHOS +#endif // OHOS_WINDOW_STUB_H diff --git a/wmtest/wm/src/README.md b/wmtest/wm/src/README.md new file mode 100644 index 0000000000..2a99b4a2c9 --- /dev/null +++ b/wmtest/wm/src/README.md @@ -0,0 +1 @@ +Store code of window client source files diff --git a/wmtest/wm/src/input_transfer_station.cpp b/wmtest/wm/src/input_transfer_station.cpp new file mode 100644 index 0000000000..43adc731bc --- /dev/null +++ b/wmtest/wm/src/input_transfer_station.cpp @@ -0,0 +1,114 @@ +/* + * 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 "input_transfer_station.h" +#include + +namespace OHOS { +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"); + if (keyEvent == nullptr) { + WLOGE("OnInputEvent receive KeyEvent is nullptr"); + return; + } + uint32_t windowId = keyEvent->GetAgentWindowId(); + auto channel = InputTransferStation::GetInstance()->GetInputChannel(windowId); + if (channel == nullptr) { + WLOGE("OnInputEvent channel is nullptr"); + return; + } + channel->HandleKeyEvent(keyEvent); +} + +void InputEventListener::OnInputEvent(std::shared_ptr axisEvent) const +{ + WLOGFI("OnInputEvent: receive axisEvent"); + if (axisEvent == nullptr) { + WLOGE("OnInputEvent receive axisEvent is nullptr"); + return; + } + axisEvent->MarkProcessed(); +} + +void InputEventListener::OnInputEvent(std::shared_ptr pointerEvent) const +{ + WLOGFI("OnInputEvent: receive pointerEvent"); + if (pointerEvent == nullptr) { + WLOGE("OnInputEvent receive pointerEvent is nullptr"); + return; + } + uint32_t windowId = pointerEvent->GetAgentWindowId(); + auto channel = InputTransferStation::GetInstance()->GetInputChannel(windowId); + if (channel == nullptr) { + WLOGE("OnInputEvent channel is nullptr"); + return; + } + channel->HandlePointerEvent(pointerEvent); +} + +void InputTransferStation::AddInputWindow(const sptr& window) +{ + WLOGFI("AddInputWindow: add window"); + uint32_t windowId = window->GetWindowId(); + sptr inputChannel = new WindowInputChannel(window); + windowInputChannels_.insert(std::make_pair(windowId, inputChannel)); + if (!initInputListener_) { + WLOGFI("init input listener"); + std::shared_ptr listener = std::make_shared(InputEventListener()); + MMI::InputManager::GetInstance()->SetWindowInputEventConsumer(listener); + inputListener_ = listener; + initInputListener_ = true; + } +} + +void InputTransferStation::RemoveInputWindow(const sptr& window) +{ + WLOGFI("RemoveInputWindow: remove window"); + uint32_t windowId = window->GetWindowId(); + auto iter = windowInputChannels_.find(windowId); + if (iter != windowInputChannels_.end()) { + windowInputChannels_.erase(windowId); + } else { + WLOGE("RemoveInputWindow do not find windowId: %{public}d", windowId); + } +} + +void InputTransferStation::SetInputListener(uint32_t windowId, std::shared_ptr &listener) +{ + auto channel = GetInputChannel(windowId); + if (channel == nullptr) { + WLOGE("SetInputListener channel is nullptr"); + return; + } + channel->SetInputListener(listener); +} + +sptr InputTransferStation::GetInputChannel(uint32_t windowId) +{ + auto iter = windowInputChannels_.find(windowId); + if (iter == windowInputChannels_.end()) { + WLOGE("GetInputChannel do not find channel according to windowId: %{public}d", windowId); + return nullptr; + } + return iter->second; +} +} +} diff --git a/wmtest/wm/src/vsync_station.cpp b/wmtest/wm/src/vsync_station.cpp new file mode 100644 index 0000000000..4cc4439827 --- /dev/null +++ b/wmtest/wm/src/vsync_station.cpp @@ -0,0 +1,69 @@ +/* + * 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 + +#include "window_manager_hilog.h" + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "VsyncStation"}; +} + +IMPLEMENT_SINGLE_INSTANCE(VsyncStation); + +void VsyncStation::RequestVsync(CallbackType type, std::shared_ptr vsyncCallback) +{ + 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()); + } + } +} + +void VsyncStation::VsyncCallbackInner(int64_t timestamp) +{ + for (auto& vsyncCallbacksSet: vsyncCallbacks_) { + for (const auto& callback: vsyncCallbacksSet.second) { + callback->onCallback(timestamp); + } + vsyncCallbacksSet.second.clear(); + } + hasRequestedVsync_.store(false); +} + +void VsyncStation::OnVsync(int64_t timestamp, void* client) +{ + auto vsyncClient = static_cast(client); + if (vsyncClient) { + vsyncClient->VsyncCallbackInner(timestamp); + } else { + WLOGFE("VsyncStation::OnVsync vsyncClient is null"); + } +} +} +} \ No newline at end of file diff --git a/wmtest/wm/src/window.cpp b/wmtest/wm/src/window.cpp new file mode 100644 index 0000000000..e1ac8e3139 --- /dev/null +++ b/wmtest/wm/src/window.cpp @@ -0,0 +1,49 @@ +/* + * 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.h" +#include "window_impl.h" +#include "window_manager_hilog.h" + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowImpl"}; +} +sptr Window::Create(const std::string& windowName, sptr& option, + const sptr& abilityToken) +{ + if (windowName.empty()) { + WLOGFE("window name is empty"); + return nullptr; + } + if (option == nullptr) { + option = new WindowOption(); + } + option->SetWindowName(windowName); + sptr windowImpl = new WindowImpl(option); + WMError error = windowImpl->Create(option->GetParentName(), abilityToken); + if (error != WMError::WM_OK) { + return nullptr; + } + return windowImpl; +} + +sptr Window::Find(const std::string& windowName) +{ + return WindowImpl::Find(windowName); +} +} +} diff --git a/wmtest/wm/src/window_adapter.cpp b/wmtest/wm/src/window_adapter.cpp new file mode 100644 index 0000000000..81b169617e --- /dev/null +++ b/wmtest/wm/src/window_adapter.cpp @@ -0,0 +1,171 @@ +/* + * 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_adapter.h" +#include +#include +#include "window_manager_hilog.h" +#include "wm_common.h" + +namespace OHOS { +namespace Rosen { +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_); + + if (!InitWMSProxyLocked()) { + return WMError::WM_ERROR_SAMGR; + } + return windowManagerServiceProxy_->SaveAbilityToken(abilityToken, windowId); +} + +WMError WindowAdapter::CreateWindow(sptr& window, sptr& windowProperty, + std::shared_ptr surfaceNode, uint32_t& windowId) +{ + std::lock_guard lock(mutex_); + + if (!InitWMSProxyLocked()) { + return WMError::WM_ERROR_SAMGR; + } + return windowManagerServiceProxy_->CreateWindow(window, windowProperty, surfaceNode, windowId); +} + +WMError WindowAdapter::AddWindow(sptr& windowProperty) +{ + std::lock_guard lock(mutex_); + + if (!InitWMSProxyLocked()) { + return WMError::WM_ERROR_SAMGR; + } + return windowManagerServiceProxy_->AddWindow(windowProperty); +} + +WMError WindowAdapter::RemoveWindow(uint32_t windowId) +{ + std::lock_guard lock(mutex_); + + if (!InitWMSProxyLocked()) { + return WMError::WM_ERROR_SAMGR; + } + return windowManagerServiceProxy_->RemoveWindow(windowId); +} + +WMError WindowAdapter::DestroyWindow(uint32_t windowId) +{ + std::lock_guard lock(mutex_); + + if (!InitWMSProxyLocked()) { + return WMError::WM_ERROR_SAMGR; + } + return windowManagerServiceProxy_->DestroyWindow(windowId); +} + +WMError WindowAdapter::MoveTo(uint32_t windowId, int32_t x, int32_t y) +{ + std::lock_guard lock(mutex_); + + if (!InitWMSProxyLocked()) { + return WMError::WM_ERROR_SAMGR; + } + return windowManagerServiceProxy_->MoveTo(windowId, x, y); +} + +WMError WindowAdapter::Resize(uint32_t windowId, uint32_t width, uint32_t height) +{ + std::lock_guard lock(mutex_); + + if (!InitWMSProxyLocked()) { + return WMError::WM_ERROR_SAMGR; + } + return windowManagerServiceProxy_->Resize(windowId, width, height); +} + +WMError WindowAdapter::RequestFocus(uint32_t windowId) +{ + std::lock_guard lock(mutex_); + + if (!InitWMSProxyLocked()) { + return WMError::WM_ERROR_SAMGR; + } + return windowManagerServiceProxy_->RequestFocus(windowId); +} + +bool WindowAdapter::InitWMSProxyLocked() +{ + if (!windowManagerServiceProxy_) { + sptr systemAbilityManager = + SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (!systemAbilityManager) { + WLOGFE("Failed to get system ability mgr."); + return false; + } + + sptr remoteObject = systemAbilityManager->GetSystemAbility(WINDOW_MANAGER_SERVICE_ID); + if (!remoteObject) { + WLOGFE("Failed to get window manager service."); + return false; + } + + windowManagerServiceProxy_ = iface_cast(remoteObject); + if ((!windowManagerServiceProxy_) || (!windowManagerServiceProxy_->AsObject())) { + WLOGFE("Failed to get system window manager services"); + return false; + } + + wmsDeath_ = new WMSDeathRecipient(); + if (!wmsDeath_) { + WLOGFE("Failed to create death Recipient ptr WMSDeathRecipient"); + return false; + } + if (!remoteObject->AddDeathRecipient(wmsDeath_)) { + WLOGFE("Failed to add death recipient"); + return false; + } + } + return true; +} + +void WindowAdapter::ClearWindowAdapter() +{ + std::lock_guard lock(mutex_); + if ((windowManagerServiceProxy_ != nullptr) && (windowManagerServiceProxy_->AsObject() != nullptr)) { + windowManagerServiceProxy_->AsObject()->RemoveDeathRecipient(wmsDeath_); + } + windowManagerServiceProxy_ = nullptr; +} + +void WMSDeathRecipient::OnRemoteDied(const wptr& wptrDeath) +{ + if (wptrDeath == nullptr) { + WLOGFE("wptrDeath is null"); + return; + } + + sptr object = wptrDeath.promote(); + if (!object) { + WLOGFE("object is null"); + return; + } + SingletonContainer::Get()->ClearWindowAdapter(); + return; +} +} // namespace Rosen +} // namespace OHOS \ No newline at end of file diff --git a/wmtest/wm/src/window_agent.cpp b/wmtest/wm/src/window_agent.cpp new file mode 100644 index 0000000000..79f7a28536 --- /dev/null +++ b/wmtest/wm/src/window_agent.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 "window_agent.h" +#include "window_manager_hilog.h" + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowAgent"}; +} + +WindowAgent::WindowAgent(sptr& windowImpl) +{ + window_ = windowImpl; +} + +void WindowAgent::UpdateWindowProperty(const WindowProperty& windowProperty) +{ +} + +void WindowAgent::UpdateWindowRect(const struct Rect& rect) +{ + if (window_ == nullptr) { + WLOGFE("window_ is nullptr"); + return; + } + window_->UpdateRect(rect); +} + +void WindowAgent::UpdateWindowMode(WindowMode mode) +{ + if (window_ == nullptr) { + WLOGFE("window_ is nullptr"); + return; + } + window_->UpdateMode(mode); +} + +void WindowAgent::UpdateFocusStatus(bool focused) +{ + if (window_ == nullptr) { + WLOGFE("window_ is nullptr"); + return; + } + window_->UpdateFocusStatus(focused); +} +} // namespace Rosen +} // namespace OHOS diff --git a/wmtest/wm/src/window_impl.cpp b/wmtest/wm/src/window_impl.cpp new file mode 100644 index 0000000000..6f5d980a75 --- /dev/null +++ b/wmtest/wm/src/window_impl.cpp @@ -0,0 +1,428 @@ +/* + * 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_impl.h" +#include "display_manager.h" +#include "singleton_container.h" +#include "window_adapter.h" +#include "window_agent.h" +#include "window_manager_hilog.h" +#ifndef _NEW_RENDERSERVER_ +#include "adapter.h" +#endif + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowImpl"}; +} + +std::map>> WindowImpl::windowMap_; + +WindowImpl::WindowImpl(const sptr& option) +{ + property_ = new WindowProperty(); + property_->SetWindowRect(option->GetWindowRect()); + property_->SetWindowType(option->GetWindowType()); + property_->SetWindowMode(option->GetWindowMode()); + property_->SetFullScreen(option->GetWindowMode() == WindowMode::WINDOW_MODE_FULLSCREEN); + property_->SetFocusable(option->GetFocusable()); + property_->SetTouchable(option->GetTouchable()); + property_->SetDisplayId(option->GetDisplayId()); + property_->SetWindowFlags(option->GetWindowFlags()); + name_ = option->GetWindowName(); + +#ifdef _NEW_RENDERSERVER_ + struct RSSurfaceNodeConfig rsSurfaceNodeConfig; + surfaceNode_ = RSSurfaceNode::Create(rsSurfaceNodeConfig); +#endif +} + +WindowImpl::~WindowImpl() +{ + Destroy(); +} + +sptr WindowImpl::Find(const std::string& name) +{ + auto iter = windowMap_.find(name); + if (iter == windowMap_.end()) { + return nullptr; + } + return iter->second.second; +} + +std::shared_ptr WindowImpl::GetSurfaceNode() const +{ + return surfaceNode_; +} + +Rect WindowImpl::GetRect() const +{ + return property_->GetWindowRect(); +} + +WindowType WindowImpl::GetType() const +{ + return property_->GetWindowType(); +} + +WindowMode WindowImpl::GetMode() const +{ + return property_->GetWindowMode(); +} + +const std::string& WindowImpl::GetWindowName() const +{ + return name_; +} + +uint32_t WindowImpl::GetWindowId() +{ + return property_->GetWindowId(); +} + +WMError WindowImpl::SetWindowType(WindowType 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) { + property_->SetWindowType(type); + return WMError::WM_OK; + } + if (property_->GetWindowType() != type) { + return WMError::WM_ERROR_INVALID_PARAM; + } + return WMError::WM_OK; +} + +WMError WindowImpl::SetWindowMode(WindowMode mode) +{ + 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 || state_ == STATE_HIDDEN) { + property_->SetWindowMode(mode); + return WMError::WM_OK; + } + if (property_->GetWindowMode() != mode) { + // TODO + } + return WMError::WM_OK; +} + +WMError WindowImpl::SetUIContent(std::shared_ptr context, + std::string& url, NativeEngine* engine, NativeValue* storage) +{ + WLOGFI("SetUIContent"); + uiContent_ = Ace::UIContent::Create(context.get(), engine); + if (uiContent_ == nullptr) { + WLOGFE("fail to SetUIContent id: %{public}d", property_->GetWindowId()); + return WMError::WM_ERROR_NULLPTR; + } + uiContent_->Initialize(this, url, storage); + return WMError::WM_OK; +} + +WMError WindowImpl::Create(const std::string& parentName, const sptr& abilityToken) +{ +#ifdef _NEW_RENDERSERVER_ + // check window name, same window names are forbidden + if (windowMap_.find(name_) != windowMap_.end()) { + WLOGFE("WindowName(%{public}s) already exists.", name_.c_str()); + return WMError::WM_ERROR_INVALID_PARAM; + } + // check parent name, if create sub window and there is not exist parent Window, then return + if (parentName != "") { + if (windowMap_.find(parentName) == windowMap_.end()) { + WLOGFE("ParentName is empty or valid. ParentName is %{public}s", parentName.c_str()); + return WMError::WM_ERROR_INVALID_PARAM; + } else { + uint32_t parentId = windowMap_[parentName].first; + property_->SetParentId(parentId); + } + } + + sptr window(this); + sptr windowAgent(new WindowAgent(window)); + uint32_t windowId = 0; + WMError ret = SingletonContainer::Get()->CreateWindow(windowAgent, property_, surfaceNode_, + windowId); + property_->SetWindowId(windowId); + + if (ret != WMError::WM_OK) { + WLOGFE("create window failed with errCode:%{public}d", static_cast(ret)); + return ret; + } + if (abilityToken != nullptr) { + ret = SingletonContainer::Get()->SaveAbilityToken(abilityToken, windowId); + if (ret != WMError::WM_OK) { + WLOGFE("SaveAbilityToken failed with errCode:%{public}d", static_cast(ret)); + return ret; + } + } + windowMap_.insert({ name_, std::pair>(windowId, this) }); + state_ = STATE_CREATED; + WLOGFI("create window success with winId:%{public}d", windowId); + InputTransferStation::GetInstance()->AddInputWindow(this); + return ret; +#else + /* weston adapter */ + return WMError::WM_OK; +#endif +} + +WMError WindowImpl::Destroy() +{ + NotifyBeforeDestroy(); +#ifdef _NEW_RENDERSERVER_ + // 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()); + windowMap_.erase(GetWindowName()); + state_ = STATE_DESTROYED; + InputTransferStation::GetInstance()->RemoveInputWindow(this); + return ret; +#else + InputTransferStation::GetInstance()->RemoveInputWindow(this); + Adapter::DestroyWestonWindow(); +#endif + return WMError::WM_OK; +} + +WMError WindowImpl::Show() +{ +#ifdef _NEW_RENDERSERVER_ + if (!IsWindowValid()) { + WLOGFI("window is already destroyed or not created! id: %{public}d", property_->GetWindowId()); + return WMError::WM_ERROR_INVALID_WINDOW; + } + if (state_ == STATE_SHOWN) { + WLOGFI("window is already shown id: %{public}d", property_->GetWindowId()); + return WMError::WM_OK; + } + SetDefaultOption(); + 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(); + } + WLOGFE("show errCode:%{public}d for winId:%{public}d", static_cast(ret), property_->GetWindowId()); + return ret; +#else + /* weston adapter */ + WMError rtn = Adapter::Show(); + if (rtn == WMError::WM_OK) { + NotifyAfterForeground(); + NotifyAfterFocused(); + WLOGFI("Show AfterForeground was invoked"); + } else { + WLOGFE("Show error=%d", static_cast(rtn)); + } + InputTransferStation::GetInstance()->AddInputWindow(this); + return rtn; +#endif +} + +WMError WindowImpl::Hide() +{ +#ifdef _NEW_RENDERSERVER_ + if (!IsWindowValid()) { + WLOGFI("window is already destroyed or not created! id: %{public}d", property_->GetWindowId()); + return WMError::WM_ERROR_INVALID_WINDOW; + } + if (state_ == STATE_HIDDEN || state_ == STATE_CREATED) { + 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()); + if (ret != WMError::WM_OK) { + return ret; + } + state_ = STATE_HIDDEN; + NotifyAfterBackground(); + return ret; +#else + /* weston adapter */ + WMError rtn = Adapter::Hide(); + if (rtn == WMError::WM_OK) { + NotifyAfterUnFocused(); + NotifyAfterBackground(); + WLOGFI("WindowImpl::Show AfterBackground was ivoked"); + } else { + WLOGFE("WindowImpl::Show error=%d", static_cast(rtn)); + } + InputTransferStation::GetInstance()->RemoveInputWindow(this); + return rtn; +#endif +} + +WMError WindowImpl::MoveTo(int32_t x, int32_t y) +{ + /* weston adapter */ +#ifdef _NEW_RENDERSERVER_ + if (!IsWindowValid()) { + WLOGFI("window is already destroyed or not created! id: %{public}d", property_->GetWindowId()); + return WMError::WM_ERROR_INVALID_WINDOW; + } + if (state_ == STATE_HIDDEN || state_ == STATE_CREATED) { + Rect rect = GetRect(); + property_->SetWindowRect({ x, y, rect.width_, rect.height_ }); + WLOGFI("window is hidden or created! id: %{public}d, rect: [%{public}d, %{public}d, %{public}d, %{public}d]", + property_->GetWindowId(), rect.posX_, rect.posY_, x, y); + return WMError::WM_OK; + } + return SingletonContainer::Get()->MoveTo(property_->GetWindowId(), x, y); +#else + return Adapter::MoveTo(x, y); +#endif +} + +WMError WindowImpl::Resize(uint32_t width, uint32_t height) +{ + /* weston adapter */ +#ifdef _NEW_RENDERSERVER_ + if (!IsWindowValid()) { + WLOGFI("window is already destroyed or not created! id: %{public}d", property_->GetWindowId()); + return WMError::WM_ERROR_INVALID_WINDOW; + } + if (state_ == STATE_HIDDEN || state_ == STATE_CREATED) { + Rect rect = GetRect(); + property_->SetWindowRect({ rect.posX_, rect.posY_, width, height }); + WLOGFI("window is hidden or created! id: %{public}d, rect: [%{public}d, %{public}d, %{public}d, %{public}d]", + property_->GetWindowId(), rect.posX_, rect.posY_, width, height); + return WMError::WM_OK; + } + return SingletonContainer::Get()->Resize(property_->GetWindowId(), width, height); +#else + return Adapter::Resize(width, height); +#endif +} + +WMError WindowImpl::RequestFocus() const +{ + if (!IsWindowValid()) { + 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()); +} + +void WindowImpl::AddInputEventListener(std::shared_ptr& inputEventListener) +{ + InputTransferStation::GetInstance()->SetInputListener(GetWindowId(), inputEventListener); +} + +void WindowImpl::RegisterLifeCycleListener(sptr& listener) +{ + lifecycleListener_ = listener; +} + +void WindowImpl::RegisterWindowChangeListener(sptr& listener) +{ + windowChangeListener_ = listener; +} + +void WindowImpl::UpdateRect(const struct Rect& rect) +{ + property_->SetWindowRect(rect); + if (windowChangeListener_ != nullptr) { + windowChangeListener_->OnSizeChange(rect); + } +} + +void WindowImpl::UpdateMode(WindowMode mode) +{ + property_->SetWindowMode(mode); +} + +void WindowImpl::ConsumeKeyEvent(std::shared_ptr& keyEvent) +{ + uiContent_->ProcessKeyEvent(keyEvent); +} +void WindowImpl::ConsumePointerEvent(std::shared_ptr& pointerEvent) +{ + uiContent_->ProcessPointerEvent(pointerEvent); +} + +void WindowImpl::UpdateFocusStatus(bool focused) +{ + WLOGFI("window focus status: %{public}d, id: %{public}d", focused, property_->GetWindowId()); + if (focused) { + NotifyAfterFocused(); + } else { + NotifyAfterUnFocused(); + } +} + +void WindowImpl::SetDefaultOption() +{ + 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()); + return; + } + uint32_t width = display->GetWidth(); + uint32_t height = display->GetHeight(); + WLOGFI("width:%{public}u, height:%{public}u, displayId:%{public}d", width, height, property_->GetDisplayId()); + + Rect rect; + switch (property_->GetWindowType()) { + case WindowType::WINDOW_TYPE_STATUS_BAR: { + rect = { 0, 0, width, static_cast((static_cast(height) * 0.07)) }; + 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)); + 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)); + + rect = { static_cast((width - alarmWidth) / 2), static_cast((height - alarmHeight) / 2), + alarmWidth, alarmHeight }; + property_->SetWindowRect(rect); + property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING); + break; + } + default: + break; + } + +} +bool WindowImpl::IsWindowValid() const +{ + return ((state_ > STATE_INITIAL) && (state_ < STATE_BOTTOM)); +} +} +} \ No newline at end of file diff --git a/wmtest/wm/src/window_input_channel.cpp b/wmtest/wm/src/window_input_channel.cpp new file mode 100644 index 0000000000..952270f3aa --- /dev/null +++ b/wmtest/wm/src/window_input_channel.cpp @@ -0,0 +1,83 @@ +/* + * 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_input_channel.h" +#include + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowInputChannel"}; +} +WindowInputChannel::WindowInputChannel(const sptr& window) +{ + window_ = window; + callback_->onCallback = std::bind(&WindowInputChannel::OnVsync, this, std::placeholders::_1); +} + +void WindowInputChannel::HandleKeyEvent(std::shared_ptr& keyEvent) +{ + if (keyEvent == nullptr) { + WLOGE("HandleKeyEvent keyEvent is nullptr"); + return; + } + if (inputListener_ != nullptr) { + inputListener_->OnInputEvent(keyEvent); + return; + } + window_->ConsumeKeyEvent(keyEvent); + keyEvent->MarkProcessed(); +} + +void WindowInputChannel::HandlePointerEvent(std::shared_ptr& pointerEvent) +{ + if (pointerEvent == nullptr) { + WLOGE("HandlePointerEvent pointerEvent is nullptr"); + return; + } + if (inputListener_ != nullptr) { + inputListener_->OnInputEvent(pointerEvent); + return; + } + if (pointerEvent->GetPointerAction() == MMI::PointerEvent::POINTER_ACTION_MOVE) { + if (pointerEventPool_.size() > MAX_INPUT_NUM) { + pointerEventPool_.clear(); + } + pointerEventPool_.emplace_back(pointerEvent); + VsyncStation::GetInstance()->RequestVsync(VsyncStation::CallbackType::CALLBACK_INPUT, callback_); + } else { + window_->ConsumePointerEvent(pointerEvent); + pointerEvent->MarkProcessed(); + } +} + +void WindowInputChannel::OnVsync(int64_t timeStamp) +{ + if (pointerEventPool_.empty()) { + WLOGE("pointerEventPool_ is empty"); + return; + } + auto pointerEvent = pointerEventPool_.back(); + HandlePointerEvent(pointerEvent); + pointerEvent->MarkProcessed(); + pointerEventPool_.clear(); +} + +void WindowInputChannel::SetInputListener(std::shared_ptr& listener) +{ + inputListener_ = listener; +} +} +} \ No newline at end of file diff --git a/wmtest/wm/src/window_option.cpp b/wmtest/wm/src/window_option.cpp new file mode 100644 index 0000000000..d116dd9789 --- /dev/null +++ b/wmtest/wm/src/window_option.cpp @@ -0,0 +1,126 @@ +/* + * 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_option.h" + +namespace OHOS { +namespace Rosen { +WindowOption::WindowOption() +{ + AddWindowFlag(WindowFlag::WINDOW_FLAG_NEED_AVOID); +} + +void WindowOption::SetWindowRect(const struct Rect& rect) +{ + windowRect_ = rect; +} + +void WindowOption::SetWindowType(WindowType type) +{ + type_ = type; +} + +void WindowOption::SetWindowMode(WindowMode mode) +{ + mode_ = mode; +} + +void WindowOption::SetFocusable(bool isFocusable) +{ + focusable_ = isFocusable; +} + +void WindowOption::SetTouchable(bool isTouchable) +{ + touchable_ = isTouchable; +} + +void WindowOption::SetDisplayId(int32_t displayId) +{ + displayId_ = displayId; +} + +void WindowOption::SetParentName(const std::string& parentName) +{ + parentName_ = parentName; +} + +void WindowOption::SetWindowName(const std::string& windowName) +{ + windowName_ = windowName; +} + +void WindowOption::AddWindowFlag(WindowFlag flag) +{ + flags_ |= static_cast(flag); +} + +void WindowOption::RemoveWindowFlag(WindowFlag flag) +{ + flags_ &= ~(static_cast(flag)); +} + +void WindowOption::SetWindowFlags(uint32_t flags) +{ + flags_ = flags; +} + +Rect WindowOption::GetWindowRect() const +{ + return windowRect_; +} + +WindowType WindowOption::GetWindowType() const +{ + return type_; +} + +WindowMode WindowOption::GetWindowMode() const +{ + return mode_; +} + +bool WindowOption::GetFocusable() const +{ + return focusable_; +} + +bool WindowOption::GetTouchable() const +{ + return touchable_; +} + +int32_t WindowOption::GetDisplayId() const +{ + return displayId_; +} + +const std::string& WindowOption::GetParentName() const +{ + return parentName_; +} + +const std::string& WindowOption::GetWindowName() const +{ + return windowName_; +} + +uint32_t WindowOption::GetWindowFlags() const +{ + return flags_; +} +} +} + diff --git a/wmtest/wm/src/window_property.cpp b/wmtest/wm/src/window_property.cpp new file mode 100644 index 0000000000..3ee405db3e --- /dev/null +++ b/wmtest/wm/src/window_property.cpp @@ -0,0 +1,238 @@ +/* + * 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_property.h" + +namespace OHOS { +namespace Rosen { +void WindowProperty::SetWindowRect(const struct Rect& rect) +{ + windowRect_ = rect; +} + +void WindowProperty::SetWindowType(WindowType type) +{ + type_ = type; +} + +void WindowProperty::SetWindowMode(WindowMode mode) +{ + mode_ = mode; +} + +void WindowProperty::SetFullScreen(bool isFullScreen) +{ + isFullScreen_ = isFullScreen; +} + +void WindowProperty::SetFocusable(bool isFocusable) +{ + focusable_ = isFocusable; +} + +void WindowProperty::SetTouchable(bool isTouchable) +{ + touchable_ = isTouchable; +} + +void WindowProperty::SetPrivacyMode(bool isPrivate) +{ + isPrivacyMode_ = isPrivate; +} + +void WindowProperty::SetTransparent(bool isTransparent) +{ + isTransparent_ = isTransparent; +} + +void WindowProperty::SetAlpha(float alpha) +{ + alpha_ = alpha; +} + +void WindowProperty::SetDisplayId(int32_t displayId) +{ + displayId_ = displayId; +} + +void WindowProperty::SetWindowFlags(uint32_t flags) +{ + flags_ = flags; +} + +Rect WindowProperty::GetWindowRect() const +{ + return windowRect_; +} + +WindowType WindowProperty::GetWindowType() const +{ + return type_; +} + +WindowMode WindowProperty::GetWindowMode() const +{ + return mode_; +} + +bool WindowProperty::GetFullScreen() const +{ + return isFullScreen_; +} + +bool WindowProperty::GetFocusable() const +{ + return focusable_; +} + +bool WindowProperty::GetTouchable() const +{ + return touchable_; +} + +bool WindowProperty::GetPrivacyMode() const +{ + return isPrivacyMode_; +} + +bool WindowProperty::GetTransparent() const +{ + return isTransparent_; +} + +float WindowProperty::GetAlpha() const +{ + return alpha_; +} + +int32_t WindowProperty::GetDisplayId() const +{ + return displayId_; +} + +uint32_t WindowProperty::GetWindowFlags() const +{ + return flags_; +} + +// TODO +void WindowProperty::SetWindowId(uint32_t windowId) +{ + windowId_ = windowId; +} +void WindowProperty::SetParentId(uint32_t parentId) +{ + parentId_ = parentId; +} +uint32_t WindowProperty::GetWindowId() const +{ + return windowId_; +} +uint32_t WindowProperty::GetParentId() const +{ + return parentId_; +} + +bool WindowProperty::Marshalling(Parcel& parcel) const +{ + // write windowRect_ + if (!(parcel.WriteInt32(windowRect_.posX_) && parcel.WriteInt32(windowRect_.posY_) && + parcel.WriteUint32(windowRect_.width_) && parcel.WriteUint32(windowRect_.height_))) { + return false; + } + + // write type_ + if (!parcel.WriteUint32(static_cast(type_))) { + return false; + } + + // write mode_ + if (!parcel.WriteUint32(static_cast(mode_))) { + return false; + } + + // write flags_ + if (!parcel.WriteUint32(flags_)) { + return false; + } + + // write isFullScreen_ + if (!parcel.WriteBool(isFullScreen_)) { + return false; + } + + // write focusable_ + if (!parcel.WriteBool(focusable_)) { + return false; + } + + // write touchable_ + if (!parcel.WriteBool(touchable_)) { + return false; + } + + // write isPrivacyMode_ + if (!parcel.WriteBool(isPrivacyMode_)) { + return false; + } + + // write isTransparent_ + if (!parcel.WriteBool(isTransparent_)) { + return false; + } + + // write alpha_ + if (!parcel.WriteFloat(alpha_)) { + return false; + } + + // write displayId_ + if (!parcel.WriteInt32(displayId_)) { + return false; + } + + // write windowId_ + if (!parcel.WriteUint32(windowId_)) { + return false; + } + + // write parentId_ + if (!parcel.WriteUint32(parentId_)) { + return false; + } + return true; +} + +sptr WindowProperty::Unmarshalling(Parcel& parcel) +{ + sptr property(new WindowProperty()); + Rect rect = { parcel.ReadInt32(), parcel.ReadInt32(), parcel.ReadUint32(), parcel.ReadUint32() }; + property->SetWindowRect(rect); + property->SetWindowType(static_cast(parcel.ReadUint32())); + property->SetWindowMode(static_cast(parcel.ReadUint32())); + property->SetWindowFlags(parcel.ReadUint32()); + property->SetFullScreen(parcel.ReadBool()); + property->SetFocusable(parcel.ReadBool()); + property->SetTouchable(parcel.ReadBool()); + property->SetPrivacyMode(parcel.ReadBool()); + property->SetTransparent(parcel.ReadBool()); + property->SetAlpha(parcel.ReadFloat()); + property->SetDisplayId(parcel.ReadInt32()); + property->SetWindowId(parcel.ReadUint32()); + property->SetParentId(parcel.ReadUint32()); + return property; +} +} +} diff --git a/wmtest/wm/src/window_proxy.cpp b/wmtest/wm/src/window_proxy.cpp new file mode 100644 index 0000000000..7334d6bb60 --- /dev/null +++ b/wmtest/wm/src/window_proxy.cpp @@ -0,0 +1,97 @@ +/* + * 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_proxy.h" +#include +#include "window_manager_hilog.h" + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowProxy"}; +} + +void WindowProxy::UpdateWindowProperty(const WindowProperty& windowProperty) +{ + sptr remote = Remote(); + if (remote == nullptr) { + WLOGFW("remote is nullptr"); + return; + } +} + +void WindowProxy::UpdateWindowRect(const struct Rect& rect) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("WriteInterfaceToken failed"); + return; + } + if (!(data.WriteInt32(rect.posX_) && data.WriteInt32(rect.posY_) && + data.WriteUint32(rect.width_) && data.WriteUint32(rect.height_))) { + WLOGFE("Write WindowRect failed"); + return; + } + + if (Remote()->SendRequest(TRANS_ID_UPDATE_WINDOW_RECT, data, reply, option) != ERR_NONE) { + WLOGFE("SendRequest failed"); + } + return; +} + +void WindowProxy::UpdateWindowMode(WindowMode mode) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("WriteInterfaceToken failed"); + return; + } + if (!data.WriteUint32(static_cast(mode))) { + WLOGFE("Write WindowMode failed"); + return; + } + + if (Remote()->SendRequest(TRANS_ID_UPDATE_WINDOW_MODE, data, reply, option) != ERR_NONE) { + WLOGFE("SendRequest failed"); + } + return; +} + +void WindowProxy::UpdateFocusStatus(bool focused) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("WriteInterfaceToken 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"); + } + return; +} +} // namespace Rosen +} // namespace OHOS + diff --git a/wmtest/wm/src/window_scene.cpp b/wmtest/wm/src/window_scene.cpp new file mode 100644 index 0000000000..3281d77428 --- /dev/null +++ b/wmtest/wm/src/window_scene.cpp @@ -0,0 +1,127 @@ +/* + * 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_scene.h" +#include "static_call.h" +#include "window_impl.h" +#include "window_manager_hilog.h" +#ifndef _NEW_RENDERSERVER_ +#include "adapter.h" +#endif + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowScene"}; +} + +const std::string WindowScene::MAIN_WINDOW_ID = "main window"; + +WindowScene::~WindowScene() +{ + WLOGFI("~WindowScene"); + if (mainWindow_ != nullptr) { + mainWindow_->Destroy(); + mainWindow_ = nullptr; + } +} + +WMError WindowScene::Init(int32_t displayId, std::shared_ptr& abilityContext, + sptr& listener) +{ + displayId_ = displayId; + abilityContext_ = abilityContext; + sptr option = new WindowOption(); + option->SetDisplayId(displayId); + +#ifndef _NEW_RENDERSERVER_ + /* weston adapter */ + Adapter::Init(); + mainWindow_ = CreateWindow(MAIN_WINDOW_ID, option); +#else + if (abilityContext_ != nullptr) { + mainWindow_ = SingletonContainer::Get()->CreateWindow( + MAIN_WINDOW_ID + std::to_string(count++), option, abilityContext_->GetAbilityToken()); + } else { + mainWindow_ = SingletonContainer::Get()->CreateWindow( + MAIN_WINDOW_ID + std::to_string(count++), option); + } + +#endif + if (mainWindow_ == nullptr) { + return WMError::WM_ERROR_NULLPTR; + } + mainWindow_->RegisterLifeCycleListener(listener); + + return WMError::WM_OK; +} + +sptr WindowScene::CreateWindow(const std::string& windowName, sptr& option) const +{ +#ifdef _NEW_RENDERSERVER_ + if (windowName.empty() || mainWindow_ == nullptr || option == nullptr) { + WLOGFE("WindowScene Name: %{public}s", windowName.c_str()); + return nullptr; + } + option->SetParentName(mainWindow_->GetWindowName()); + return SingletonContainer::Get()->CreateWindow(windowName, option); +#else + /* weston adapter */ + if (!Adapter::CreateWestonWindow(option)) { + WLOGFE("WindowScene::CreateWindow fail to CreateWestonWindow"); + return nullptr; + } + Rect rect; + if (!Adapter::GetMainWindowRect(rect)) { + WLOGFE("WindowScene::CreateWindow fail to GetMainWindowRect"); + return nullptr; + } + option->SetWindowName(windowName); + option->SetWindowRect(rect); + sptr window = new WindowImpl(option); + return window; +#endif +} + +const sptr& WindowScene::GetMainWindow() const +{ + return mainWindow_; +} + +WMError WindowScene::GoForeground() +{ + if (mainWindow_ == nullptr) { + return WMError::WM_ERROR_NULLPTR; + } + return mainWindow_->Show(); +} + +WMError WindowScene::GoBackground() const +{ + if (mainWindow_ == nullptr) { + return WMError::WM_ERROR_NULLPTR; + } + return mainWindow_->Hide(); +} + +WMError WindowScene::RequestFocus() const +{ + if (mainWindow_ == nullptr) { + return WMError::WM_ERROR_NULLPTR; + } + return mainWindow_->RequestFocus(); +} +} // namespace Rosen +} // namespace OHOS diff --git a/wmtest/wm/src/window_stub.cpp b/wmtest/wm/src/window_stub.cpp new file mode 100644 index 0000000000..e7640726e2 --- /dev/null +++ b/wmtest/wm/src/window_stub.cpp @@ -0,0 +1,59 @@ +/* + * 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_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, "WindowStub"}; +} + +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; + } + switch (code) { + case TRANS_ID_UPDATE_WINDOW_PROPERTY: { + break; + } + case TRANS_ID_UPDATE_WINDOW_RECT: { + struct Rect rect{ data.ReadInt32(), data.ReadInt32(), data.ReadUint32(), data.ReadUint32() }; + UpdateWindowRect(rect); + break; + } + case TRANS_ID_UPDATE_WINDOW_MODE: { + WindowMode mode = static_cast(data.ReadUint32()); + UpdateWindowMode(mode); + break; + } + case TRANS_ID_UPDATE_FOCUS_STATUS: { + bool focused = data.ReadBool(); + UpdateFocusStatus(focused); + break; + } + default: + break; + } + return 0; +} +} // namespace Rosen +} // namespace OHOS diff --git a/wmtest/wmserver/BUILD.gn b/wmtest/wmserver/BUILD.gn new file mode 100644 index 0000000000..6db3713751 --- /dev/null +++ b/wmtest/wmserver/BUILD.gn @@ -0,0 +1,85 @@ +# 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("//build/ohos.gni") + +## Build libwms.so +config("libwms_config") { + visibility = [ ":*" ] + + include_dirs = [ + "include", + "//utils/system/safwk/native/include", + "//foundation/windowmanager/interfaces/innerkits/wm", + "//foundation/windowmanager/interfaces/innerkits/dm", + "//foundation/windowmanager/wm/include", + "//foundation/windowmanager/utils/include", + "//foundation/windowmanager/dm/include", + "//foundation/windowmanager/dmserver/include", + ] + + cflags = [ + "-Wall", + "-Werror", + "-g3", + ] +} + +ohos_shared_library("libwms") { + sources = [ + "../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", + "src/input_window_monitor.cpp", + "src/window_controller.cpp", + "src/window_layout_policy.cpp", + "src/window_manager_service.cpp", + "src/window_manager_stub.cpp", + "src/window_node.cpp", + "src/window_node_container.cpp", + "src/window_root.cpp", + "src/window_zorder_policy.cpp", + ] + + configs = [ ":libwms_config" ] + + deps = [ + "//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", + ] + + external_deps = [ "ipc:ipc_core" ] + + part_name = "window_manager" + subsystem_name = "window" +} diff --git a/wmtest/wmserver/include/README.md b/wmtest/wmserver/include/README.md new file mode 100644 index 0000000000..539249966b --- /dev/null +++ b/wmtest/wmserver/include/README.md @@ -0,0 +1 @@ +Store code of window sever inner header files \ No newline at end of file diff --git a/wmtest/wmserver/include/input_window_monitor.h b/wmtest/wmserver/include/input_window_monitor.h new file mode 100644 index 0000000000..ed44650580 --- /dev/null +++ b/wmtest/wmserver/include/input_window_monitor.h @@ -0,0 +1,72 @@ +/* + * 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_INPUT_WINDOW_MONITOR_H +#define OHOS_INPUT_WINDOW_MONITOR_H + +#include +#include + +#include "window_root.h" + +namespace OHOS { +namespace Rosen { +class InputWindowMonitor : public RefBase { +public: + InputWindowMonitor(sptr& root) : windowRoot_(root) + { + MMI::PhysicalDisplayInfo physicalDisplayInfo = { + .id = 0, //todo: update when DMS is ready + .leftDisplayId = -1, // todo: invalid displayId for testing + .upDisplayId = -1, // todo: invalid displayId for testing + .topLeftX = 0, // todo: use wgn info for testing + .topLeftY = 0, // todo: use wgn info for testing + .width = 2560, // todo: use wgn info for testing + .height = 1600, // todo: use wgn info for testing + .name = "physical_display0", // todo: wait for DMS + .seatId = "seat0", // todo: update seatId + .seatName = "default0", // todo: update seatId + .logicWidth = 2560, // todo: use wgn info for testing + .logicHeight = 1600, // todo: use wgn info for testing + .direction = MMI::Direction0 // todo: use direction 0 for testing + }; + physicalDisplays_.emplace_back(physicalDisplayInfo); + MMI::LogicalDisplayInfo logicalDisplayInfo = { + .id = 0, //todo: update when DMS is ready + .topLeftX = 0, // todo: use wgn info for testing + .topLeftY = 0, // todo: use wgn info for testing + .width = 2560, // todo: use wgn info for testing + .height = 1600, // todo: use wgn info for testing + .name = "logical_display0", // todo: wait for DMS + .seatId = "seat0", // todo: update seatId + .seatName = "default0", // todo: update seatName + .focusWindowId = -1, + .windowsInfo_ = {}, + }; + logicalDisplays_.emplace_back(logicalDisplayInfo); + } + ~InputWindowMonitor() = default; + void UpdateInputWindow(uint32_t windowId); + +private: + sptr windowRoot_; + std::vector physicalDisplays_; + std::vector logicalDisplays_; + void TraverseWindowNodes(const std::vector>& windowNodes, + std::vector::iterator& iter); +}; +} +} +#endif // OHOS_INPUT_WINDOW_MONITOR_H diff --git a/wmtest/wmserver/include/window_controller.h b/wmtest/wmserver/include/window_controller.h new file mode 100644 index 0000000000..043cad3d49 --- /dev/null +++ b/wmtest/wmserver/include/window_controller.h @@ -0,0 +1,48 @@ +/* + * 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_CONTROLLER_H +#define OHOS_ROSEN_WINDOW_CONTROLLER_H + +#include +#include "window_root.h" + +namespace OHOS { +namespace Rosen { +class WindowController : public RefBase { +public: + WindowController(sptr& root) : windowRoot_(root) {} + ~WindowController() = default; + + WMError CreateWindow(sptr& window, sptr& property, + const std::shared_ptr& surfaceNode, uint32_t& windowId); + WMError AddWindowNode(sptr& property); + WMError RemoveWindowNode(uint32_t windowId); + WMError DestroyWindow(uint32_t windowId); + WMError MoveTo(uint32_t windowId, int32_t x, int32_t y); + WMError Resize(uint32_t windowId, uint32_t width, uint32_t height); + WMError RequestFocus(uint32_t windowId); + WMError SaveAbilityToken(const sptr& abilityToken, uint32_t windowId); + +private: + uint32_t GenWindowId(); + WMError LayoutWindowNodeTrees(); + + sptr windowRoot_; + std::atomic windowId_ { 0 }; +}; +} +} +#endif // OHOS_ROSEN_WINDOW_CONTROLLER_H diff --git a/wmtest/wmserver/include/window_layout_policy.h b/wmtest/wmserver/include/window_layout_policy.h new file mode 100644 index 0000000000..350b8c0e2a --- /dev/null +++ b/wmtest/wmserver/include/window_layout_policy.h @@ -0,0 +1,53 @@ +/* + * 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_LAYOUT_POLICY_H +#define OHOS_ROSEN_WINDOW_LAYOUT_POLICY_H + +#include +#include +#include + +#include "window_node.h" +#include "wm_common.h" + +namespace OHOS { +namespace Rosen { +class WindowLayoutPolicy : public RefBase { +public: + WindowLayoutPolicy() = default; + ~WindowLayoutPolicy() = default; + WMError UpdateDisplayInfo(const Rect& displayRect); + WMError LayoutWindow(sptr& node); + +private: + Rect displayRect_ = {0, 0, 0, 0}; + Rect limitRect_ = {0, 0, 0, 0}; + std::map> aviodNodes_; + const std::set aviodTypes_ { + 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); +}; +} +} +#endif // OHOS_ROSEN_WINDOW_LAYOUT_POLICY_H diff --git a/wmtest/wmserver/include/window_manager_interface.h b/wmtest/wmserver/include/window_manager_interface.h new file mode 100644 index 0000000000..e1d9d4d494 --- /dev/null +++ b/wmtest/wmserver/include/window_manager_interface.h @@ -0,0 +1,52 @@ +/* + * 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_INTERFACE_H +#define OHOS_WINDOW_MANAGER_INTERFACE_H + +#include +#include +#include "window_property.h" +#include "window_interface.h" + +namespace OHOS { +namespace Rosen { +class IWindowManager : public IRemoteBroker { +public: + DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.IWindowManager"); + + enum { + TRANS_ID_CREATE_WINDOW, + TRANS_ID_ADD_WINDOW, + TRANS_ID_REMOVE_WINDOW, + TRANS_ID_DESTROY_WINDOW, + TRANS_ID_MOVE, + TRANS_ID_RESIZE, + TRANS_ID_REQUEST_FOCUS, + TRANS_ID_SEND_ABILITY_TOKEN, + }; + virtual WMError CreateWindow(sptr& window, sptr& property, + const std::shared_ptr& surfaceNode, uint32_t& windowId) = 0; + virtual WMError AddWindow(sptr& property) = 0; + virtual WMError RemoveWindow(uint32_t windowId) = 0; + virtual WMError DestroyWindow(uint32_t windowId) = 0; + 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 SaveAbilityToken(const sptr& abilityToken, uint32_t windowId) = 0; +}; +} +} +#endif // OHOS_WINDOW_MANAGER_INTERFACE_H diff --git a/wmtest/wmserver/include/window_manager_proxy.h b/wmtest/wmserver/include/window_manager_proxy.h new file mode 100644 index 0000000000..60e89fd3cf --- /dev/null +++ b/wmtest/wmserver/include/window_manager_proxy.h @@ -0,0 +1,45 @@ +/* + * 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_PROXY_H +#define OHOS_WINDOW_MANAGER_PROXY_H + +#include "window_manager_interface.h" +#include + +namespace OHOS { +namespace Rosen { +class WindowManagerProxy : public IRemoteProxy { +public: + explicit WindowManagerProxy(const sptr& impl) : IRemoteProxy(impl) {}; + + ~WindowManagerProxy() {}; + + WMError CreateWindow(sptr& window, sptr& property, + const std::shared_ptr& surfaceNode, uint32_t& windowId) override; + WMError AddWindow(sptr& property) override; + WMError RemoveWindow(uint32_t windowId) override; + WMError DestroyWindow(uint32_t windowId) override; + WMError MoveTo(uint32_t windowId, int32_t x, int32_t y) override; + 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: + static inline BrokerDelegator delegator_; +}; +} +} +#endif // OHOS_WINDOW_MANAGER_PROXY_H diff --git a/wmtest/wmserver/include/window_manager_service.h b/wmtest/wmserver/include/window_manager_service.h new file mode 100644 index 0000000000..b722b16469 --- /dev/null +++ b/wmtest/wmserver/include/window_manager_service.h @@ -0,0 +1,63 @@ +/* + * 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_SERVICE_H +#define OHOS_WINDOW_MANAGER_SERVICE_H + +#include +#include + +#include +#include +#include +#include "singleton_delegator.h" +#include "single_instance.h" +#include "window_controller.h" +#include "window_manager_stub.h" +#include "window_root.h" + +namespace OHOS { +namespace Rosen { +class WindowManagerService : public SystemAbility, public WindowManagerStub { +DECLARE_SYSTEM_ABILITY(WindowManagerService); + +DECLARE_SINGLE_INSTANCE_BASE(WindowManagerService); + +public: + ~WindowManagerService() = default; + void OnStart() override; + void OnStop() override; + + WMError CreateWindow(sptr& window, sptr& property, + const std::shared_ptr& surfaceNode, uint32_t& windowId) override; + WMError AddWindow(sptr& property) override; + WMError RemoveWindow(uint32_t windowId) override; + WMError DestroyWindow(uint32_t windowId) override; + WMError MoveTo(uint32_t windowId, int32_t x, int32_t y) override; + 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: + WindowManagerService(); + bool Init(); + static inline SingletonDelegator delegator; + std::mutex mutex_; + sptr windowRoot_; + sptr windowController_; + sptr inputWindowMonitor_; +}; +} +} +#endif // OHOS_WINDOW_MANAGER_SERVICE_H diff --git a/wmtest/wmserver/include/window_manager_stub.h b/wmtest/wmserver/include/window_manager_stub.h new file mode 100644 index 0000000000..4fa7df0aa9 --- /dev/null +++ b/wmtest/wmserver/include/window_manager_stub.h @@ -0,0 +1,32 @@ +/* + * 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_STUB_H +#define OHOS_WINDOW_MANAGER_STUB_H + +#include "window_manager_interface.h" +#include +namespace OHOS { +namespace Rosen { +class WindowManagerStub : public IRemoteStub { +public: + WindowManagerStub() = default; + ~WindowManagerStub() = default; + virtual int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, + MessageOption &option) override; +}; +} +} +#endif // OHOS_WINDOW_MANAGER_STUB_H diff --git a/wmtest/wmserver/include/window_node.h b/wmtest/wmserver/include/window_node.h new file mode 100644 index 0000000000..0684ebe71d --- /dev/null +++ b/wmtest/wmserver/include/window_node.h @@ -0,0 +1,82 @@ +/* + * 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_NODE_H +#define OHOS_ROSEN_WINDOW_NODE_H + +#include +#include +#include +#include "window_interface.h" +#include "window_manager_hilog.h" + +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, + std::shared_ptr surfaceNode) + : surfaceNode_(surfaceNode), property_(property), windowToken_(window) + { + callingPid_ = IPCSkeleton::GetCallingPid(); + callingUid_ = IPCSkeleton::GetCallingUid(); + } + WindowNode() : property_(new WindowProperty()) + { + callingPid_ = IPCSkeleton::GetCallingPid(); + callingUid_ = IPCSkeleton::GetCallingUid(); + } + ~WindowNode() = default; + + void SetDisplayId(int32_t displayId); + void UpdateLayoutRects(const LayoutRects& rects); + void SetWindowProperty(const sptr& property); + + const sptr& GetWindowToken() const; + uint32_t GetWindowId() const; + int32_t GetDisplayId() const; + const LayoutRects& GetLayoutRects() const; + WindowType GetWindowType() const; + WindowMode GetWindowMode() const; + uint32_t GetWindowFlags() const; + const sptr& GetWindowProperty() const; + int32_t GetCallingPid() const; + int32_t GetCallingUid() const; + + sptr parent_; + std::vector> children_; + std::shared_ptr surfaceNode_; + sptr abilityToken_ = nullptr; + int32_t priority_ { 0 }; + bool requestedVisibility_ { false }; + bool currentVisibility_ { false }; + +private: + sptr property_; + sptr windowToken_; + LayoutRects layoutRects_; + int32_t callingPid_; + int32_t callingUid_; +}; +} +} +#endif // OHOS_ROSEN_WINDOW_NODE_H diff --git a/wmtest/wmserver/include/window_node_container.h b/wmtest/wmserver/include/window_node_container.h new file mode 100644 index 0000000000..251683b665 --- /dev/null +++ b/wmtest/wmserver/include/window_node_container.h @@ -0,0 +1,76 @@ +/* + * 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_NODE_CONTAINER_H +#define OHOS_ROSEN_WINDOW_NODE_CONTAINER_H + +#include +#include "window_layout_policy.h" +#include "window_node.h" +#include "window_zorder_policy.h" +#include "wm_common.h" + +namespace OHOS { +namespace Rosen { +class WindowNodeContainer : public RefBase { +public: + WindowNodeContainer(uint64_t screenId, uint32_t width, uint32_t height) + { + struct RSDisplayNodeConfig config = {screenId}; + displayNode_ = RSDisplayNode::Create(config); + displayRect_ = { + .posX_ = 0, + .posY_ = 0, + .width_ = width, + .height_ = height + }; + } + + ~WindowNodeContainer(); + WMError AddWindowNode(sptr& node, sptr& parentNode); + WMError RemoveWindowNode(sptr& node); + WMError DestroyWindowNode(sptr& node, std::vector& windowIds); + const std::vector& Destroy(); + void AssignZOrder(); + WMError SetFocusWindow(uint32_t windowId); + uint32_t GetFocusWindow() const; + WMError MinimizeOtherFullScreenAbility(); // adapt to api7 + void TraverseContainer(std::vector>& windowNodes); + WMError LayoutWindowNodes(); + +private: + void AssignZOrder(sptr& node); + void TraverseWindowNode(sptr& root, std::vector>& windowNodes); + sptr FindRoot(WindowType type) const; + void UpdateFocusWindow(); + sptr FindWindowNodeById(uint32_t id) const; + void UpdateFocusStatus(uint32_t id, bool focused) const; + 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(); + std::shared_ptr displayNode_; + std::vector removedIds_; + uint32_t zOrder_ { 0 }; + uint32_t focusedWindow_ { 0 }; + Rect displayRect_; + WMError LayoutWindowNode(sptr& node); +}; +} +} +#endif // OHOS_ROSEN_WINDOW_NODE_CONTAINER_H diff --git a/wmtest/wmserver/include/window_root.h b/wmtest/wmserver/include/window_root.h new file mode 100644 index 0000000000..9a86234686 --- /dev/null +++ b/wmtest/wmserver/include/window_root.h @@ -0,0 +1,65 @@ +/* + * 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_ROOT_H +#define OHOS_ROSEN_WINDOW_ROOT_H + +#include +#include +#include "window_node_container.h" + +namespace OHOS { +namespace Rosen { +class WindowDeathRecipient : public IRemoteObject::DeathRecipient { +public: + WindowDeathRecipient(std::function&)> callback) : callback_(callback) {} + ~WindowDeathRecipient() = default; + + virtual void OnRemoteDied(const wptr& wptrDeath) override; + + std::function&)> callback_; +}; + +class WindowRoot : public RefBase { +public: + WindowRoot() = default; + ~WindowRoot() = default; + + sptr GetOrCreateWindowNodeContainer(int32_t displayId); + void NotifyDisplayRemoved(int32_t displayId); + sptr GetWindowNode(uint32_t windowId) const; + + WMError SaveWindow(const sptr& node); + WMError AddWindowNode(uint32_t parentId, sptr& node); + WMError RemoveWindowNode(uint32_t windowId); + WMError DestroyWindow(uint32_t windowId); + const std::map>& GetWindowNodeContainerMap() const; + + WMError RequestFocus(uint32_t windowId); + WMError MinimizeOtherFullScreenAbility(sptr& node); + +private: + void ClearWindow(const sptr& remoteObject); + WMError DestroyWindowInner(sptr& node); + + std::map> windowNodeContainerMap_; + std::map> windowNodeMap_; + std::map, uint32_t> windowIdMap_; + + sptr windowDeath_ = new WindowDeathRecipient(std::bind(&WindowRoot::ClearWindow, + this, std::placeholders::_1)); +}; +} +} +#endif // OHOS_ROSEN_WINDOW_ROOT_H diff --git a/wmtest/wmserver/include/window_zorder_policy.h b/wmtest/wmserver/include/window_zorder_policy.h new file mode 100644 index 0000000000..8e91d3d664 --- /dev/null +++ b/wmtest/wmserver/include/window_zorder_policy.h @@ -0,0 +1,63 @@ +/* + * 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_ZORDER_POLICY_H +#define OHOS_ROSEN_WINDOW_ZORDER_POLICY_H + +#include +#include + +#include "wm_common.h" + +namespace OHOS { +namespace Rosen { +class WindowZorderPolicy : public RefBase { +public: + WindowZorderPolicy() = default; + ~WindowZorderPolicy() = default; + + int32_t GetWindowPriority(WindowType type) const; + +private: + const std::map windowPriorityMap_ { + // sub-windows types + { WindowType::WINDOW_TYPE_MEDIA, -1 }, + { WindowType::WINDOW_TYPE_APP_SUB_WINDOW, 1 }, + + // main window + { WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, 0 }, + + // system-specific window + { WindowType::WINDOW_TYPE_WALLPAPER, 101 }, + { WindowType::WINDOW_TYPE_APP_LAUNCHING, 102 }, + { WindowType::WINDOW_TYPE_DOCK_SLICE, 103 }, + { WindowType::WINDOW_TYPE_INCOMING_CALL, 104 }, + { WindowType::WINDOW_TYPE_SEARCHING_BAR, 105 }, + { WindowType::WINDOW_TYPE_SYSTEM_ALARM_WINDOW, 106 }, + { WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT, 107 }, + { WindowType::WINDOW_TYPE_FLOAT, 108 }, + { WindowType::WINDOW_TYPE_TOAST, 109 }, + { WindowType::WINDOW_TYPE_STATUS_BAR, 110 }, + { WindowType::WINDOW_TYPE_PANEL, 111 }, + { WindowType::WINDOW_TYPE_KEYGUARD, 112 }, + { WindowType::WINDOW_TYPE_VOLUME_OVERLAY, 113 }, + { WindowType::WINDOW_TYPE_NAVIGATION_BAR, 114 }, + { WindowType::WINDOW_TYPE_DRAGGING_EFFECT, 115 }, + { WindowType::WINDOW_TYPE_POINTER, 116 }, + }; +}; +} +} +#endif // OHOS_ROSEN_WINDOW_STATE_H diff --git a/wmtest/wmserver/src/README.md b/wmtest/wmserver/src/README.md new file mode 100644 index 0000000000..6aa13c7e6a --- /dev/null +++ b/wmtest/wmserver/src/README.md @@ -0,0 +1 @@ +Store code of window server source files diff --git a/wmtest/wmserver/src/input_window_monitor.cpp b/wmtest/wmserver/src/input_window_monitor.cpp new file mode 100644 index 0000000000..9dc6ff82a8 --- /dev/null +++ b/wmtest/wmserver/src/input_window_monitor.cpp @@ -0,0 +1,87 @@ +/* + * 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 "input_window_monitor.h" + +#include + +#include + +#include "window_manager_hilog.h" + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "InputWindowMonitor"}; +} + +void InputWindowMonitor::UpdateInputWindow(uint32_t windowId) +{ + if (windowRoot_ == nullptr) { + WLOGFE("windowRoot is null."); + return; + } + sptr windowNode = windowRoot_->GetWindowNode(windowId); + if (windowNode == nullptr) { + WLOGFE("window node could not be found."); + return; + } + int32_t displayId = windowNode->GetDisplayId(); + auto container = windowRoot_->GetOrCreateWindowNodeContainer(displayId); + if (container == nullptr) { + WLOGFE("can not get window node container."); + return; + } + std::vector> windowNodes; + container->TraverseContainer(windowNodes); + + auto iter = std::find_if(logicalDisplays_.begin(), logicalDisplays_.end(), + [displayId](MMI::LogicalDisplayInfo& logicalDisplay) { + return logicalDisplay.id == displayId; + }); + if (iter != logicalDisplays_.end()) { + TraverseWindowNodes(windowNodes, iter); + if (!iter->windowsInfo_.empty()) { + iter->focusWindowId = container->GetFocusWindow(); + } + } else { + WLOGFE("There is no display for this window action."); + return; + } + WLOGFI("update display info to IMS."); + MMI::InputManager::GetInstance()->UpdateDisplayInfo(physicalDisplays_, logicalDisplays_); +} + +void InputWindowMonitor::TraverseWindowNodes(const std::vector> &windowNodes, + std::vector::iterator& iter) +{ + iter->windowsInfo_.clear(); + for (auto& windowNode: windowNodes) { + MMI::WindowInfo windowInfo = { + .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_), + .displayId = windowNode->GetDisplayId(), + .agentWindowId = static_cast(windowNode->GetWindowId()), + }; + iter->windowsInfo_.emplace_back(windowInfo); + } +} +} +} \ No newline at end of file diff --git a/wmtest/wmserver/src/window_controller.cpp b/wmtest/wmserver/src/window_controller.cpp new file mode 100644 index 0000000000..9f3dbe1ead --- /dev/null +++ b/wmtest/wmserver/src/window_controller.cpp @@ -0,0 +1,153 @@ +/* + * 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_controller.h" +#include +#include "window_manager_hilog.h" + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowController"}; +} +uint32_t WindowController::GenWindowId() +{ + return ++windowId_; +} + +WMError WindowController::CreateWindow(sptr& window, sptr& property, + const std::shared_ptr& surfaceNode, uint32_t& windowId) +{ + windowId = GenWindowId(); + property->SetWindowId(windowId); + + sptr node = new WindowNode(property, window, surfaceNode); + return windowRoot_->SaveWindow(node); +} + +WMError WindowController::SaveAbilityToken(const sptr& abilityToken, uint32_t windowId) +{ + auto node = windowRoot_->GetWindowNode(windowId); + if (node == nullptr) { + WLOGFE("could not find window"); + return WMError::WM_ERROR_NULLPTR; + } + node->abilityToken_ = abilityToken; + return WMError::WM_OK; +} + +WMError WindowController::AddWindowNode(sptr& property) +{ + auto node = windowRoot_->GetWindowNode(property->GetWindowId()); + if (node == nullptr) { + WLOGFE("could not find window"); + return WMError::WM_ERROR_NULLPTR; + } + node->SetWindowProperty(property); + // TODO: check permission + // TODO: adjust property + + WMError res = windowRoot_->AddWindowNode(property->GetParentId(), node); + 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"); + WMError res = windowRoot_->MinimizeOtherFullScreenAbility(node); + if (res != WMError::WM_OK) { + WLOGFE("Minimize other fullscreen window failed"); + } + } + 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; +} + +WMError WindowController::DestroyWindow(uint32_t windowId) +{ + WMError res = windowRoot_->DestroyWindow(windowId); + if (res != WMError::WM_OK) { + return res; + } + res = LayoutWindowNodeTrees(); + RSTransaction::FlushImplicitTransaction(); + WLOGFI("DestroyWindow FlushImplicitTransaction end"); + return res; +} + +WMError WindowController::MoveTo(uint32_t windowId, int32_t x, int32_t y) +{ + auto node = windowRoot_->GetWindowNode(windowId); + if (node == nullptr) { + WLOGFE("could not find window"); + return WMError::WM_ERROR_NULLPTR; + } + Vector2f pos(x, y); + node->surfaceNode_->SetBoundsPosition(pos); + RSTransaction::FlushImplicitTransaction(); + WLOGFI("MoveTo FlushImplicitTransaction end"); + return WMError::WM_OK; +} + +WMError WindowController::Resize(uint32_t windowId, uint32_t width, uint32_t height) +{ + auto node = windowRoot_->GetWindowNode(windowId); + if (node == nullptr) { + WLOGFE("could not find window"); + return WMError::WM_ERROR_NULLPTR; + } + node->surfaceNode_->SetBoundsSize(width, height); + RSTransaction::FlushImplicitTransaction(); + WLOGFI("Resize FlushImplicitTransaction end"); + return WMError::WM_OK; +} + +WMError WindowController::RequestFocus(uint32_t windowId) +{ + return windowRoot_->RequestFocus(windowId); +} +} +} diff --git a/wmtest/wmserver/src/window_layout_policy.cpp b/wmtest/wmserver/src/window_layout_policy.cpp new file mode 100644 index 0000000000..c90a5f030e --- /dev/null +++ b/wmtest/wmserver/src/window_layout_policy.cpp @@ -0,0 +1,184 @@ +/* + * 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_layout_policy.h" +#include "window_manager_hilog.h" + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowLayoutPolicy"}; +} + +WMError 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; +} + +WMError WindowLayoutPolicy::LayoutWindow(sptr& node) +{ + if (node->GetWindowType() >= WindowType::SYSTEM_WINDOW_END) { + WLOGFE("unknown window type!"); + return WMError::WM_ERROR_INVALID_PARAM; + } + UpdateLayoutRects(node); + if (aviodTypes_.find(node->GetWindowType()) != aviodTypes_.end()) { + RecordAvoidRect(node); + } + return WMError::WM_OK; +} + +bool WindowLayoutPolicy::IsRectChanged(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) +{ + 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_; + Rect winRect = node->GetWindowProperty()->GetWindowRect(); + + if (needAvoid) { + dRect = limitRect_; + } else { + dRect = displayRect_; + } + + if (subWindow) { + pRect = node->parent_->GetLayoutRects().rect_; + } else { + pRect = dRect; + } + + 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)) { + 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(); + 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 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_; + 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_); +} + +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)); + UpdateLimitRect(node); + } else { // update existing avoid rect + limitRect_ = displayRect_; + aviodNodes_[id] = node; + for (auto item : aviodNodes_) { + 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/wmtest/wmserver/src/window_manager_proxy.cpp b/wmtest/wmserver/src/window_manager_proxy.cpp new file mode 100644 index 0000000000..f1f2da589e --- /dev/null +++ b/wmtest/wmserver/src/window_manager_proxy.cpp @@ -0,0 +1,247 @@ +/* + * 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_proxy.h" +#include +#include "window_manager_hilog.h" + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowManagerProxy"}; +} + + +WMError WindowManagerProxy::CreateWindow(sptr& window, sptr& property, + const std::shared_ptr& surfaceNode, uint32_t& windowId) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("WriteInterfaceToken failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + + if (!data.WriteRemoteObject(window->AsObject())) { + WLOGFE("Write IWindow failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + + if (!data.WriteParcelable(property.GetRefPtr())) { + WLOGFE("Write windowProperty failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + + if (!data.WriteParcelable(surfaceNode.get())) { + WLOGFE("Write windowProperty failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + + if (Remote()->SendRequest(TRANS_ID_CREATE_WINDOW, data, reply, option) != ERR_NONE) { + return WMError::WM_ERROR_IPC_FAILED; + } + windowId = reply.ReadUint32(); + int32_t ret = reply.ReadInt32(); + return static_cast(ret); +} + +WMError WindowManagerProxy::AddWindow(sptr& property) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("WriteInterfaceToken failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + + if (!data.WriteParcelable(property.GetRefPtr())) { + WLOGFE("Write windowProperty failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + + if (Remote()->SendRequest(TRANS_ID_ADD_WINDOW, data, reply, option) != ERR_NONE) { + return WMError::WM_ERROR_IPC_FAILED; + } + + int32_t ret = reply.ReadInt32(); + return static_cast(ret); +} + +WMError WindowManagerProxy::RemoveWindow(uint32_t windowId) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("WriteInterfaceToken failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + + if (!data.WriteUint32(windowId)) { + WLOGFE("Write windowId failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + + if (Remote()->SendRequest(TRANS_ID_REMOVE_WINDOW, data, reply, option) != ERR_NONE) { + return WMError::WM_ERROR_IPC_FAILED; + } + + int32_t ret = reply.ReadInt32(); + return static_cast(ret); +} + +WMError WindowManagerProxy::DestroyWindow(uint32_t windowId) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("WriteInterfaceToken failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + + if (!data.WriteUint32(windowId)) { + WLOGFE("Write windowId failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + + if (Remote()->SendRequest(TRANS_ID_DESTROY_WINDOW, data, reply, option) != ERR_NONE) { + return WMError::WM_ERROR_IPC_FAILED; + } + + int32_t ret = reply.ReadInt32(); + return static_cast(ret); +} + +WMError WindowManagerProxy::MoveTo(uint32_t windowId, int32_t x, int32_t y) +{ + 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.WriteInt32(x)) { + WLOGFE("Write posX failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + + if (!data.WriteInt32(y)) { + WLOGFE("Write posY failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + + if (Remote()->SendRequest(TRANS_ID_MOVE, data, reply, option) != ERR_NONE) { + return WMError::WM_ERROR_IPC_FAILED; + } + + int32_t ret = reply.ReadInt32(); + return static_cast(ret); +} + +WMError WindowManagerProxy::Resize(uint32_t windowId, uint32_t width, uint32_t height) +{ + 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(width)) { + WLOGFE("Write width failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + + if (!data.WriteUint32(height)) { + WLOGFE("Write height failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + + if (Remote()->SendRequest(TRANS_ID_RESIZE, data, reply, option) != ERR_NONE) { + return WMError::WM_ERROR_IPC_FAILED; + } + + int32_t ret = reply.ReadInt32(); + return static_cast(ret); +} + +WMError WindowManagerProxy::RequestFocus(uint32_t windowId) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("WriteInterfaceToken failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + + if (!data.WriteUint32(windowId)) { + WLOGFE("Write windowId failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + if (Remote()->SendRequest(TRANS_ID_REQUEST_FOCUS, 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; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("WriteInterfaceToken failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + + if (!data.WriteRemoteObject(abilityToken)) { + WLOGFE("Write abilityToken failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + + if (!data.WriteUint32(windowId)) { + WLOGFE("Write windowId failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + + if (Remote()->SendRequest(TRANS_ID_SEND_ABILITY_TOKEN, data, reply, option) != ERR_NONE) { + return WMError::WM_ERROR_IPC_FAILED; + } + + int32_t ret = reply.ReadInt32(); + return static_cast(ret); +} +} +} + diff --git a/wmtest/wmserver/src/window_manager_service.cpp b/wmtest/wmserver/src/window_manager_service.cpp new file mode 100644 index 0000000000..7c70a580ba --- /dev/null +++ b/wmtest/wmserver/src/window_manager_service.cpp @@ -0,0 +1,134 @@ +/* + * 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_service.h" + +#include + +#include +#include + +#include "window_manager_hilog.h" + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowManagerService"}; +} + +IMPLEMENT_SINGLE_INSTANCE(WindowManagerService); + +const bool REGISTER_RESULT = SystemAbility::MakeAndRegisterAbility( + SingletonContainer::Get().GetRefPtr()); + +WindowManagerService::WindowManagerService() : SystemAbility(WINDOW_MANAGER_SERVICE_ID, true) +{ + windowRoot_ = new WindowRoot(); + windowController_ = new WindowController(windowRoot_); + inputWindowMonitor_ = new InputWindowMonitor(windowRoot_); +} + +void WindowManagerService::OnStart() +{ + WLOGFI("WindowManagerService::OnStart start"); + if (!Init()) { + return; + } +} + +bool WindowManagerService::Init() +{ + WLOGFI("WindowManagerService::Init start"); + bool ret = Publish(this); + if (!ret) { + WLOGFW("WindowManagerService::Init failed"); + return false; + } + WLOGFI("WindowManagerService::Init success"); + sleep(10); // for RS temporary + return true; +} + +void WindowManagerService::OnStop() +{ + WLOGFI("ready to stop service."); +} + +WMError WindowManagerService::CreateWindow(sptr& window, sptr& property, + const std::shared_ptr& surfaceNode, uint32_t& windowId) +{ + if (window == nullptr || property == nullptr || surfaceNode == nullptr) { + WLOGFE("window is invalid"); + 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_); + WMError res = windowController_->AddWindowNode(property); + if (res == WMError::WM_OK) { + inputWindowMonitor_->UpdateInputWindow(property->GetWindowId()); + } + return res; +} + +WMError WindowManagerService::RemoveWindow(uint32_t windowId) +{ + std::lock_guard lock(mutex_); + WMError res = windowController_->RemoveWindowNode(windowId); + if (res == WMError::WM_OK) { + inputWindowMonitor_->UpdateInputWindow(windowId); + } + return res; +} + +WMError WindowManagerService::DestroyWindow(uint32_t windowId) +{ + std::lock_guard lock(mutex_); + WMError res = windowController_->DestroyWindow(windowId); + if (res == WMError::WM_OK) { + inputWindowMonitor_->UpdateInputWindow(windowId); + } + return res; +} + +WMError WindowManagerService::MoveTo(uint32_t windowId, int32_t x, int32_t y) +{ + 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_); + return windowController_->Resize(windowId, width, height); +} + +WMError WindowManagerService::RequestFocus(uint32_t windowId) +{ + std::lock_guard lock(mutex_); + return windowController_->RequestFocus(windowId); +} + +WMError WindowManagerService::SaveAbilityToken(const sptr& abilityToken, uint32_t windowId) +{ + std::lock_guard lock(mutex_); + return windowController_->SaveAbilityToken(abilityToken, windowId); +} +} +} \ No newline at end of file diff --git a/wmtest/wmserver/src/window_manager_stub.cpp b/wmtest/wmserver/src/window_manager_stub.cpp new file mode 100644 index 0000000000..cd18fed9f4 --- /dev/null +++ b/wmtest/wmserver/src/window_manager_stub.cpp @@ -0,0 +1,101 @@ +/* + * 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_stub.h" +#include +#include "window_manager_hilog.h" + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowManagerStub"}; +} + +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; + } + switch (code) { + case TRANS_ID_CREATE_WINDOW: { + sptr windowObject = data.ReadRemoteObject(); + sptr windowProxy = iface_cast(windowObject); + sptr windowProperty = data.ReadStrongParcelable(); + std::shared_ptr surfaceNode(data.ReadParcelable()); + uint32_t windowId; + WMError errCode = CreateWindow(windowProxy, windowProperty, surfaceNode, windowId); + reply.WriteUint32(windowId); + reply.WriteInt32(static_cast(errCode)); + break; + } + case TRANS_ID_ADD_WINDOW: { + sptr windowProperty = data.ReadStrongParcelable(); + WMError errCode = AddWindow(windowProperty); + reply.WriteInt32(static_cast(errCode)); + break; + } + case TRANS_ID_REMOVE_WINDOW: { + uint32_t windowId = data.ReadUint32(); + WMError errCode = RemoveWindow(windowId); + reply.WriteInt32(static_cast(errCode)); + break; + } + case TRANS_ID_DESTROY_WINDOW: { + uint32_t windowId = data.ReadUint32(); + WMError errCode = DestroyWindow(windowId); + reply.WriteInt32(static_cast(errCode)); + break; + } + case TRANS_ID_MOVE: { + uint32_t windowId = data.ReadUint32(); + int32_t x = data.ReadInt32(); + int32_t y = data.ReadInt32(); + WMError errCode = MoveTo(windowId, x, y); + reply.WriteInt32(static_cast(errCode)); + break; + } + case TRANS_ID_RESIZE: { + uint32_t windowId = data.ReadUint32(); + uint32_t width = data.ReadUint32(); + uint32_t height = data.ReadUint32(); + WMError errCode = Resize(windowId, width, height); + reply.WriteInt32(static_cast(errCode)); + break; + } + case TRANS_ID_REQUEST_FOCUS: { + uint32_t windowId = data.ReadUint32(); + WMError errCode = RequestFocus(windowId); + reply.WriteInt32(static_cast(errCode)); + break; + } + + case TRANS_ID_SEND_ABILITY_TOKEN: { + sptr abilityToken = data.ReadRemoteObject(); + uint32_t windowId = data.ReadUint32(); + WMError errCode = SaveAbilityToken(abilityToken, windowId); + reply.WriteInt32(static_cast(errCode)); + break; + } + default: + WLOGFW("unknown transaction code"); + return IPCObjectStub::OnRemoteRequest(code, data, reply, option); + } + return 0; +} +} +} diff --git a/wmtest/wmserver/src/window_node.cpp b/wmtest/wmserver/src/window_node.cpp new file mode 100644 index 0000000000..389d4f3677 --- /dev/null +++ b/wmtest/wmserver/src/window_node.cpp @@ -0,0 +1,86 @@ +/* + * 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_node.h" +#include "window_manager_hilog.h" + +namespace OHOS { +namespace Rosen { +void WindowNode::SetDisplayId(int32_t displayId) +{ + property_->SetDisplayId(displayId); +} + +void WindowNode::UpdateLayoutRects(const LayoutRects& rects) +{ + layoutRects_ = rects; +} + +void WindowNode::SetWindowProperty(const sptr& property) +{ + property_ = property; +} + +const sptr& WindowNode::GetWindowToken() const +{ + return windowToken_; +} + +int32_t WindowNode::GetDisplayId() const +{ + return property_->GetDisplayId(); +} + +uint32_t WindowNode::GetWindowId() const +{ + return property_->GetWindowId(); +} + +const LayoutRects& WindowNode::GetLayoutRects() const +{ + return layoutRects_; +} + +WindowType WindowNode::GetWindowType() const +{ + return property_->GetWindowType(); +} + +WindowMode WindowNode::GetWindowMode() const +{ + return property_->GetWindowMode(); +} + +uint32_t WindowNode::GetWindowFlags() const +{ + return property_->GetWindowFlags(); +} + +const sptr& WindowNode::GetWindowProperty() const +{ + return property_; +} + +int32_t WindowNode::GetCallingPid() const +{ + return callingPid_; +} + +int32_t WindowNode::GetCallingUid() const +{ + return callingUid_; +} +} +} diff --git a/wmtest/wmserver/src/window_node_container.cpp b/wmtest/wmserver/src/window_node_container.cpp new file mode 100644 index 0000000000..f4ed70a0c0 --- /dev/null +++ b/wmtest/wmserver/src/window_node_container.cpp @@ -0,0 +1,366 @@ +/* + * 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_node_container.h" +#include +#include +#include "window_manager_hilog.h" + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowNodeContainer"}; +} + +WindowNodeContainer::~WindowNodeContainer() +{ + Destroy(); +} + +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"); + AAFwk::AbilityManagerClient::GetInstance()->MinimizeAbility((*iter)->abilityToken_); + } + } + return WMError::WM_OK; +} + +WMError WindowNodeContainer::AddWindowNode(sptr& node, sptr& parentNode) +{ + if (!node->surfaceNode_ || !displayNode_) { + WLOGFE("surface node or display node is nullptr!"); + return WMError::WM_ERROR_NULLPTR; + } + sptr root = FindRoot(node->GetWindowType()); + if (root == nullptr) { + WLOGFE("root window node is nullptr!"); + return WMError::WM_ERROR_NULLPTR; + } + node->requestedVisibility_ = true; + if (parentNode != nullptr) { // subwindow + if (parentNode->parent_ != root) { + WLOGFE("window type and parent window not match or try to add subwindow to subwindow, which is forbidden"); + return WMError::WM_ERROR_INVALID_PARAM; + } + node->currentVisibility_ = parentNode->currentVisibility_; + } else { // mainwindow + parentNode = root; + node->currentVisibility_ = true; + for (auto& child : node->children_) { + child->currentVisibility_ = child->requestedVisibility_; + } + } + node->parent_ = parentNode; + + UpdateWindowTree(node); + UpdateRSTree(node, true); + AssignZOrder(); + UpdateFocusWindow(); + WLOGFI("AddWindowNode windowId: %{public}d end", node->GetWindowId()); + return WMError::WM_OK; +} + +void WindowNodeContainer::UpdateWindowTree(sptr& node) +{ + node->priority_ = zorderPolicy_->GetWindowPriority(node->GetWindowType()); + auto parentNode = node->parent_; + auto position = parentNode->children_.end(); + for (auto iter = parentNode->children_.begin(); iter < parentNode->children_.end(); ++iter) { + if ((*iter)->priority_ > node->priority_) { + position = iter; + break; + } + } + parentNode->children_.insert(position, node); +} + +bool WindowNodeContainer::UpdateRSTree(sptr& node, bool isAdd) +{ + if (displayNode_ == nullptr) { + WLOGFE("displayNode_ is nullptr"); + return false; + } + if (isAdd) { + displayNode_->AddChild(node->surfaceNode_, -1); + for (auto& child : node->children_) { + if (child->currentVisibility_) { + displayNode_->AddChild(child->surfaceNode_, -1); + } + } + } else { + displayNode_->RemoveChild(node->surfaceNode_); + for (auto& child : node->children_) { + displayNode_->RemoveChild(child->surfaceNode_); + } + } + return true; +} + +WMError WindowNodeContainer::DestroyWindowNode(sptr& node, std::vector& windowIds) +{ + WMError ret = RemoveWindowNode(node); + if (ret != WMError::WM_OK) { + return ret; + } + node->surfaceNode_ = nullptr; + windowIds.push_back(node->GetWindowId()); + + for (auto& child : node->children_) { // destroy sub window if exists + windowIds.push_back(child->GetWindowId()); + child->parent_ = nullptr; + if (child->surfaceNode_ != nullptr && displayNode_ != nullptr) { + displayNode_->RemoveChild(child->surfaceNode_); + child->surfaceNode_ = nullptr; + } + } + 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_) { + WLOGFE("window node or surface node is nullptr, invalid"); + return WMError::WM_ERROR_DESTROYED_OBJECT; + } + + if (node->parent_ == nullptr) { + WLOGFW("can't find parent of this node"); + } else { + // remove this node from parent + auto iter = std::find(node->parent_->children_.begin(), node->parent_->children_.end(), node); + if (iter != node->parent_->children_.end()) { + node->parent_->children_.erase(iter); + } else { + WLOGFE("can't find this node in parent"); + } + node->parent_ = nullptr; + } + node->requestedVisibility_ = false; + node->currentVisibility_ = false; + for (auto& child : node->children_) { + child->currentVisibility_ = false; + } + UpdateRSTree(node, false); + UpdateFocusWindow(); + WLOGFI("RemoveWindowNode windowId: %{public}d end", node->GetWindowId()); + return WMError::WM_OK; +} + +const std::vector& WindowNodeContainer::Destroy() +{ + removedIds_.clear(); + for (auto& node : belowAppWindowNode_->children_) { + DestroyWindowNode(node, removedIds_); + } + for (auto& node : appWindowNode_->children_) { + DestroyWindowNode(node, removedIds_); + } + for (auto& node : aboveAppWindowNode_->children_) { + DestroyWindowNode(node, removedIds_); + } + displayNode_ = nullptr; + return removedIds_; +} + +sptr WindowNodeContainer::FindRoot(WindowType type) const +{ + if (type >= WindowType::APP_WINDOW_BASE && type <= WindowType::APP_SUB_WINDOW_END) { + return appWindowNode_; + } else if (type < WindowType::ABOVE_APP_SYSTEM_WINDOW_BASE) { + return belowAppWindowNode_; + } else { + return aboveAppWindowNode_; + } +} + +void WindowNodeContainer::UpdateFocusWindow() +{ + for (auto iter = appWindowNode_->children_.rbegin(); iter < appWindowNode_->children_.rend(); iter++) { + if ((*iter)->GetWindowProperty()->GetFocusable()) { + WLOGFI("find focused id %{public}d;", (*iter)->GetWindowId()); + SetFocusWindow((*iter)->GetWindowId()); + break; + } + } +} + +sptr WindowNodeContainer::FindWindowNodeById(uint32_t id) const +{ + std::vector> rootNodes = { aboveAppWindowNode_, appWindowNode_, belowAppWindowNode_ }; + for (auto& rootNode : rootNodes) { + for (auto& node : rootNode->children_) { + if (node->GetWindowId() == id) { + return node; + } + for (auto& subNode : node->children_) { + if (subNode->GetWindowId() == id) { + return subNode; + } + } + } + } + return nullptr; +} + +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); + } else { + node->GetWindowToken()->UpdateFocusStatus(focused); + } +} + +void WindowNodeContainer::AssignZOrder() +{ + zOrder_ = 0; + for (auto& node : belowAppWindowNode_->children_) { + AssignZOrder(node); + } + for (auto& node : appWindowNode_->children_) { + AssignZOrder(node); + } + for (auto& node : aboveAppWindowNode_->children_) { + AssignZOrder(node); + } +} + +void WindowNodeContainer::AssignZOrder(sptr& node) +{ + if (node == nullptr) { + return; + } + auto iter = node->children_.begin(); + for (; iter < node->children_.end(); ++iter) { + 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 { + break; + } + } + 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_; + } + } +} + +WMError WindowNodeContainer::SetFocusWindow(uint32_t windowId) +{ + if (focusedWindow_ == windowId) { + return WMError::WM_OK; + } + UpdateFocusStatus(focusedWindow_, false); + focusedWindow_ = windowId; + UpdateFocusStatus(focusedWindow_, true); + return WMError::WM_OK; +} + +uint32_t WindowNodeContainer::GetFocusWindow() const +{ + return focusedWindow_; +} + +void WindowNodeContainer::TraverseContainer(std::vector>& windowNodes) +{ + for (auto& node : belowAppWindowNode_->children_) { + TraverseWindowNode(node, windowNodes); + } + for (auto& node : appWindowNode_->children_) { + TraverseWindowNode(node, windowNodes); + } + for (auto& node : aboveAppWindowNode_->children_) { + TraverseWindowNode(node, windowNodes); + } + std::reverse(windowNodes.begin(), windowNodes.end()); +} + +void WindowNodeContainer::TraverseWindowNode(sptr& node, std::vector>& windowNodes) +{ + if (node == nullptr) { + return; + } + auto iter = node->children_.begin(); + for (; iter < node->children_.end(); ++iter) { + if ((*iter)->priority_ < 0) { + windowNodes.emplace_back(*iter); + } else { + break; + } + } + windowNodes.emplace_back(node); + for (; iter < node->children_.end(); ++iter) { + windowNodes.emplace_back(*iter); + } +} +} +} diff --git a/wmtest/wmserver/src/window_root.cpp b/wmtest/wmserver/src/window_root.cpp new file mode 100644 index 0000000000..ac62642792 --- /dev/null +++ b/wmtest/wmserver/src/window_root.cpp @@ -0,0 +1,219 @@ +/* + * 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_root.h" +#include "display_manager_service_inner.h" +#include "window_manager_hilog.h" + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowRoot"}; +} +sptr WindowRoot::GetOrCreateWindowNodeContainer(int32_t displayId) +{ + auto iter = windowNodeContainerMap_.find(displayId); + if (iter != windowNodeContainerMap_.end()) { + return iter->second; + } + auto displayScreen = DisplayManagerServiceInner::GetInstance()->GetDisplayById(displayId); + if (displayScreen == 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())); + windowNodeContainerMap_.insert({ displayId, container }); + return container; +} + +const std::map>& WindowRoot::GetWindowNodeContainerMap() const +{ + return windowNodeContainerMap_; +} + +void WindowRoot::NotifyDisplayRemoved(int32_t displayId) +{ + auto container = GetOrCreateWindowNodeContainer(displayId); + if (container == nullptr) { + WLOGFI("this display does not have any window"); + return; + } + std::vector windowIds = container->Destroy(); + for (auto id : windowIds) { + auto node = GetWindowNode(id); + DestroyWindowInner(node); + } + windowNodeContainerMap_.erase(displayId); +} + +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; +} + +WMError WindowRoot::SaveWindow(const sptr& node) +{ + if (node == nullptr) { + WLOGFE("add window failed, node is nullptr"); + return WMError::WM_ERROR_NULLPTR; + } + WLOGFI("save windowId %{public}d", node->GetWindowId()); + windowNodeMap_.insert({ node->GetWindowId(), node }); + auto remoteObject = node->GetWindowToken()->AsObject(); + windowIdMap_.insert({ remoteObject, node->GetWindowId() }); + + if (windowDeath_ == nullptr) { + WLOGFI("failed to create death Recipient ptr WindowDeathRecipient"); + } + if (!remoteObject->AddDeathRecipient(windowDeath_)) { + WLOGFI("failed to add death recipient"); + } + return WMError::WM_OK; +} + +WMError WindowRoot::MinimizeOtherFullScreenAbility(sptr& node) +{ + auto container = GetOrCreateWindowNodeContainer(node->GetDisplayId()); + if (container == nullptr) { + WLOGFE("MinimizeAbility failed, window container could not be found"); + return WMError::WM_ERROR_NULLPTR; + } + return container->MinimizeOtherFullScreenAbility(); +} + +WMError WindowRoot::AddWindowNode(uint32_t parentId, sptr& node) +{ + if (node == nullptr) { + WLOGFE("add window failed, node is nullptr"); + return WMError::WM_ERROR_NULLPTR; + } + auto parentNode = GetWindowNode(parentId); + + 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->AddWindowNode(node, parentNode); +} + +WMError WindowRoot::RemoveWindowNode(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->RemoveWindowNode(node); +} + +WMError WindowRoot::DestroyWindow(uint32_t windowId) +{ + auto node = GetWindowNode(windowId); + if (node == nullptr) { + return WMError::WM_ERROR_DESTROYED_OBJECT; + } + WMError res; + auto container = GetOrCreateWindowNodeContainer(node->GetDisplayId()); + if (container != nullptr) { + std::vector windowIds; + res = container->DestroyWindowNode(node, windowIds); + for (auto id : windowIds) { + node = GetWindowNode(id); + DestroyWindowInner(node); + } + return res; + } + res = DestroyWindowInner(node); + WLOGFI("destroy window failed, window container could not be found"); + return res; +} + +WMError WindowRoot::DestroyWindowInner(sptr& node) +{ + if (node == nullptr) { + 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->AsObject() != nullptr) { + window->AsObject()->RemoveDeathRecipient(windowDeath_); + } + windowIdMap_.erase(window->AsObject()); + windowNodeMap_.erase(node->GetWindowId()); + return WMError::WM_OK; +} + +WMError WindowRoot::RequestFocus(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("window container could not be found"); + return WMError::WM_ERROR_NULLPTR; + } + return container->SetFocusWindow(windowId); +} + +void WindowRoot::ClearWindow(const sptr& remoteObject) +{ + auto iter = windowIdMap_.find(remoteObject); + if (iter == windowIdMap_.end()) { + WLOGFE("window id could not be found"); + return; + } + uint32_t windowId = iter->second; + DestroyWindow(windowId); +} + +void WindowDeathRecipient::OnRemoteDied(const wptr& wptrDeath) +{ + if (wptrDeath == nullptr) { + WLOGFE("wptrDeath is null"); + return; + } + + sptr object = wptrDeath.promote(); + if (!object) { + WLOGFE("object is null"); + return; + } + callback_(object); +} +} +} diff --git a/wmtest/wmserver/src/window_zorder_policy.cpp b/wmtest/wmserver/src/window_zorder_policy.cpp new file mode 100644 index 0000000000..1a41d6fb18 --- /dev/null +++ b/wmtest/wmserver/src/window_zorder_policy.cpp @@ -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. + */ + +#include "window_manager_hilog.h" +#include "window_zorder_policy.h" + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowZorderPolicy"}; +} + +int32_t WindowZorderPolicy::GetWindowPriority(WindowType type) const +{ + if (windowPriorityMap_.count(type) == 0) { + WLOGFE("invalid window type"); + return windowPriorityMap_.at(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW); + } + return windowPriorityMap_.at(type); +} +} +} \ No newline at end of file -- Gitee