diff --git a/adapter/BUILD.gn b/adapter/BUILD.gn index 0efe55427523b7ac4c2afb8462c470d7dce8efe8..f1ceabcd949434cfaa0407afc5abcde145688185 100644 --- a/adapter/BUILD.gn +++ b/adapter/BUILD.gn @@ -13,8 +13,8 @@ import("//build/ohos.gni") -## Build libwmadaptertest.so {{{ -config("libwmadaptertest_config") { +## Build libwmadapter.so {{{ +config("libwmadapter_config") { visibility = [ ":*" ] include_dirs = [ @@ -37,16 +37,12 @@ config("libwmadaptertest_config") { "//foundation/aafwk/standard/interfaces/innerkits/want/include/ohos/aafwk/content", "//foundation/distributedschedule/dmsfwk/services/dtbschedmgr/include", "//foundation/aafwk/standard/interfaces/innerkits/base/include", - ] - - cflags = [ - "-Wall", - "-Werror", - "-g3", + "//third_party/jsoncpp/include", + "//third_party/json/include", ] } -config("libwmadaptertest_public_config") { +config("libwmadapter_public_config") { include_dirs = [ "//foundation/graphic/standard/interfaces/innerkits/wmclient", "//foundation/windowmanager/interfaces/innerkits/wm", @@ -56,12 +52,12 @@ config("libwmadaptertest_public_config") { ] } -ohos_shared_library("libwmadaptertest") { +ohos_shared_library("libwmadapter") { sources = [ "src/adapter.cpp" ] - configs = [ ":libwmadaptertest_config" ] + configs = [ ":libwmadapter_config" ] - public_configs = [ ":libwmadaptertest_public_config" ] + public_configs = [ ":libwmadapter_public_config" ] deps = [ "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog", @@ -77,9 +73,6 @@ ohos_shared_library("libwmadaptertest") { # ace "//foundation/ace/ace_engine/interfaces/innerkits/ace:ace_uicontent", - - # aafwk - "//foundation/aafwk/standard/interfaces/innerkits/want:want", ] public_deps = [ diff --git a/adapter/include/adapter.h b/adapter/include/adapter.h index c387a88d0feadcecb9318025c9e453a45b0dfe7c..229c9dd6d6aead131ab066c5023b1924cb9278f8 100644 --- a/adapter/include/adapter.h +++ b/adapter/include/adapter.h @@ -27,7 +27,7 @@ #include "wm_common.h" #include "window.h" #include "foundation/graphic/standard/interfaces/innerkits/wmclient/window_option.h" -#include "window_manager.h" +#include "foundation/graphic/standard/interfaces/innerkits/wmclient/window_manager.h" #include "window_manager_hilog.h" namespace OHOS { diff --git a/dm/include/display_manager_adapter.h b/dm/include/display_manager_adapter.h index 61882fd0dba9c134c7fb798b7565ac8652682c33..53e1c8d30d47048812a1b844fafe936a302229b6 100644 --- a/dm/include/display_manager_adapter.h +++ b/dm/include/display_manager_adapter.h @@ -17,7 +17,7 @@ #define FOUNDATION_DM_DISPLAY_MANAGER_ADAPTER_H #include -#include +#include #include "display.h" #include "display_manager_interface.h" @@ -30,13 +30,16 @@ public: virtual void OnRemoteDied(const wptr& wptrDeath) override; }; -class DisplayManagerAdapter : public RefBase { - DECLARE_SINGLE_INSTANCE_BASE(DisplayManagerAdapter); +class DisplayManagerAdapter { +DECLARE_SINGLE_INSTANCE_BASE(DisplayManagerAdapter); public: - sptr GetDisplay(DisplayType type); DisplayId GetDefaultDisplayId(); sptr GetDisplayById(DisplayId displayId); - + DisplayId CreateVirtualDisplay(const VirtualDisplayInfo &virtualDisplayInfo, + sptr surface); + bool DestroyVirtualDisplay(DisplayId displayId); + // TODO: fix me + // sptr GetDisplaySnapshot(DisplayId displayId); void Clear(); private: DisplayManagerAdapter() = default; diff --git a/dm/src/display_manager.cpp b/dm/src/display_manager.cpp index 8c6c34fee2b0b0957e7856861698e663be020ace..6ec0eb691009bf810c5635e3815aa0b3d16fe592 100644 --- a/dm/src/display_manager.cpp +++ b/dm/src/display_manager.cpp @@ -15,7 +15,7 @@ #include "display_manager.h" -#include +#include #include "display_manager_adapter.h" #include "window_manager_hilog.h" @@ -25,43 +25,14 @@ namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "DisplayManager"}; } -IMPLEMENT_SINGLE_INSTANCE(DisplayManager); - -DisplayManager::DisplayManager() -{ - dmsAdapter_ = SingletonContainer::Get(); -} - -DisplayManager::~DisplayManager() -{ -} - -const sptr& DisplayManager::GetDisplay(const DisplayType type) -{ - if (dmsAdapter_ == nullptr) { - WLOGFE("DisplayManager::GetDisplay null!"); - return nullptr; - } - return dmsAdapter_->GetDisplay(type); -} - DisplayId DisplayManager::GetDefaultDisplayId() { - if (dmsAdapter_ == nullptr) { - WLOGFE("DisplayManager::GetDefaultDisplayId null!\n"); - return DISPLAY_ID_INVALD; - } - return dmsAdapter_->GetDefaultDisplayId(); + return SingletonContainer::Get().GetDefaultDisplayId(); } const sptr DisplayManager::GetDisplayById(DisplayId displayId) { - if (dmsAdapter_ == nullptr) { - WLOGFE("DisplayManager::GetDisplayById null!\n"); - return nullptr; - } - - sptr display = dmsAdapter_->GetDisplayById(displayId); + sptr display = SingletonContainer::Get().GetDisplayById(displayId); if (display == nullptr) { WLOGFE("DisplayManager::GetDisplayById failed!\n"); return nullptr; @@ -69,6 +40,40 @@ const sptr DisplayManager::GetDisplayById(DisplayId displayId) return display; } +// TODO: fix me +// sptr DisplayManager::GetScreenshot(DisplayId displayId) +// { +// sptr screenShot = SingletonContainer::Get().GetDisplaySnapshot(displayId); +// if (screenShot == nullptr) { +// WLOGFE("DisplayManager::GetScreenshot failed!\n"); +// return nullptr; +// } + +// return screenShot; +// } + +// sptr DisplayManager::GetScreenshot(DisplayId displayId, const Media::Rect &rect, +// const Media::Size &size, int rotation) +// { +// sptr screenShot = SingletonContainer::Get().GetDisplaySnapshot(displayId); +// if (screenShot == nullptr) { +// WLOGFE("DisplayManager::GetScreenshot failed!\n"); +// return nullptr; +// } + +// // create crop dest pixelmap +// Media::InitializationOptions opt; +// opt.size.width = size.width; +// opt.size.height = size.height; +// opt.scaleMode = Media::ScaleMode::FIT_TARGET_SIZE; +// opt.editable = false; +// opt.useSourceIfMatch = true; + +// auto dstScreenshot = Media::PixelMap::Create(*screenShot, rect, opt); +// sptr dstScreenshot_ = dstScreenshot.release(); + +// return dstScreenshot_; +// } const sptr DisplayManager::GetDefaultDisplay() { @@ -97,4 +102,18 @@ std::vector> DisplayManager::GetAllDisplays() } return res; } + +DisplayId DisplayManager::CreateVirtualDisplay(const std::string &name, uint32_t width, uint32_t height, + sptr surface, DisplayId displayIdToMirror, int32_t flags) +{ + WLOGFI("DisplayManager::CreateVirtualDisplay multi params"); + VirtualDisplayInfo info(name, width, height, displayIdToMirror, flags); + return SingletonContainer::Get().CreateVirtualDisplay(info, surface); +} + +bool DisplayManager::DestroyVirtualDisplay(DisplayId displayId) +{ + WLOGFI("DisplayManager::DestroyVirtualDisplay override params"); + return SingletonContainer::Get().DestroyVirtualDisplay(displayId); +} } // namespace OHOS::Rosen \ No newline at end of file diff --git a/dm/src/display_manager_adapter.cpp b/dm/src/display_manager_adapter.cpp index 675bb97b8be1212aae57e403fc8d248196b2eae6..e9d4949d1af8e01431324206399f2c4e8bd98f9e 100644 --- a/dm/src/display_manager_adapter.cpp +++ b/dm/src/display_manager_adapter.cpp @@ -27,21 +27,6 @@ namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "DisplayManagerAdapter"}; } -IMPLEMENT_SINGLE_INSTANCE(DisplayManagerAdapter); - -sptr DisplayManagerAdapter::GetDisplay(DisplayType type) -{ - std::lock_guard lock(mutex_); - - if (!InitDMSProxyLocked()) { - WLOGFE("displayManagerAdapter::GetDisplay: InitDMSProxyLocked failed!"); - return nullptr; - } - sptr info = displayManagerServiceProxy_->GetDisplayInfo(type); - // TODO DisplayInfo内容更新到对应的Display.displayInfo_. auto iter = displayMap_.find(info.id_); - return nullptr; -} - DisplayId DisplayManagerAdapter::GetDefaultDisplayId() { std::lock_guard lock(mutex_); @@ -79,6 +64,40 @@ sptr DisplayManagerAdapter::GetDisplayById(DisplayId displayId) return display; } +// TODO: fix me +// sptr DisplayManagerAdapter::GetDisplaySnapshot(DisplayId displayId) +// { +// std::lock_guard lock(mutex_); + +// if (!InitDMSProxyLocked()) { +// WLOGFE("displayManagerAdapter::GetDisplaySnapshot: InitDMSProxyLocked failed!"); +// return nullptr; +// } + +// sptr dispalySnapshot = displayManagerServiceProxy_->GetDispalySnapshot(displayId); + +// return dispalySnapshot; +// } + +DisplayId DisplayManagerAdapter::CreateVirtualDisplay(const VirtualDisplayInfo &virtualDisplayInfo, + sptr surface) +{ + if (!InitDMSProxyLocked()) { + return DISPLAY_ID_INVALD; + } + WLOGFI("DisplayManagerAdapter::CreateVirtualDisplay"); + return displayManagerServiceProxy_->CreateVirtualDisplay(virtualDisplayInfo, surface); +} + +bool DisplayManagerAdapter::DestroyVirtualDisplay(DisplayId displayId) +{ + if (!InitDMSProxyLocked()) { + return false; + } + WLOGFI("DisplayManagerAdapter::DestroyVirtualDisplay"); + return displayManagerServiceProxy_->DestroyVirtualDisplay(displayId); +} + bool DisplayManagerAdapter::InitDMSProxyLocked() { WLOGFI("InitDMSProxy"); @@ -128,7 +147,7 @@ void DMSDeathRecipient::OnRemoteDied(const wptr& wptrDeath) WLOGFE("object is null"); return; } - SingletonContainer::Get().GetRefPtr()->Clear(); + SingletonContainer::Get().Clear(); return; } diff --git a/dmserver/include/display_screen.h b/dmserver/include/abstract_display.h similarity index 78% rename from dmserver/include/display_screen.h rename to dmserver/include/abstract_display.h index d656621953e85274d62a4dd0670693a0150d32b9..ef288bfa7293d7d6aebff82a43d9cfdd82bb2921 100644 --- a/dmserver/include/display_screen.h +++ b/dmserver/include/abstract_display.h @@ -13,17 +13,17 @@ * limitations under the License. */ -#ifndef FOUNDATION_DMSERVER_DISPLAY_SCREEN_H -#define FOUNDATION_DMSERVER_DISPLAY_SCREEN_H +#ifndef FOUNDATION_DMSERVER_ABSTRACT_DISPLAY_H +#define FOUNDATION_DMSERVER_ABSTRACT_DISPLAY_H #include #include "display_info.h" namespace OHOS::Rosen { -class DisplayScreen : public RefBase { +class AbstractDisplay : public RefBase { public: - DisplayScreen(const DisplayInfo& info); - ~DisplayScreen() = default; + AbstractDisplay(const DisplayInfo& info); + ~AbstractDisplay() = default; DisplayId GetId() const; int32_t GetWidth() const; @@ -42,4 +42,4 @@ private: uint32_t freshRate_ {0}; }; } // namespace OHOS::Rosen -#endif // FOUNDATION_DMSERVER_DISPLAY_SCREEN_H \ No newline at end of file +#endif // FOUNDATION_DMSERVER_ABSTRACT_DISPLAY_H \ No newline at end of file diff --git a/wmtest/dmserver/include/display_screen_manager.h b/dmserver/include/abstract_display_manager.h similarity index 55% rename from wmtest/dmserver/include/display_screen_manager.h rename to dmserver/include/abstract_display_manager.h index 0c1df9b379a1c28c9827bd1533d8aae263b9980a..e18dbbaa1780856bf79a979360e19debfdef3073 100644 --- a/wmtest/dmserver/include/display_screen_manager.h +++ b/dmserver/include/abstract_display_manager.h @@ -13,32 +13,36 @@ * limitations under the License. */ -#ifndef FOUNDATION_DMSERVER_DISPLAY_SCREEN_MANAGER_H -#define FOUNDATION_DMSERVER_DISPLAY_SCREEN_MANAGER_H +#ifndef FOUNDATION_DMSERVER_ABSTRACT_DISPLAY_MANAGER_H +#define FOUNDATION_DMSERVER_ABSTRACT_DISPLAY_MANAGER_H #include -#include +#include -#include "display_screen.h" +#include "abstract_display.h" #include "single_instance.h" #include "transaction/rs_interfaces.h" +#include "virtual_display_info.h" namespace OHOS::Rosen { -class DisplayScreenManager : public RefBase { -DECLARE_SINGLE_INSTANCE_BASE(DisplayScreenManager); +class AbstractDisplayManager { +DECLARE_SINGLE_INSTANCE_BASE(AbstractDisplayManager); public: - std::map> displayScreenMap_; + std::map> abstractDisplayMap_; ScreenId GetDefaultScreenId(); RSScreenModeInfo GetScreenActiveMode(ScreenId id); + ScreenId CreateVirtualScreen(const VirtualDisplayInfo &virtualDisplayInfo, sptr surface); + bool DestroyVirtualScreen(ScreenId screenId); + // TODO: fix me + // sptr GetScreenSnapshot(ScreenId screenId); private: - DisplayScreenManager(); - ~DisplayScreenManager(); + AbstractDisplayManager(); + ~AbstractDisplayManager(); void parepareRSScreenManger(); OHOS::Rosen::RSInterfaces *rsInterface_; }; - } // namespace OHOS::Rosen -#endif // FOUNDATION_DMSERVER_DISPLAY_SCREEN_MANAGER_H \ No newline at end of file +#endif // FOUNDATION_DMSERVER_ABSTRACT_DISPLAY_MANAGER_H \ No newline at end of file diff --git a/dmserver/include/display_manager_interface.h b/dmserver/include/display_manager_interface.h index 8a7d71fc5e46fca2ae133a6cd13e1d60c236bc87..aff799ad3342a6bb296ee2f9d6d5d49ab06c5fef 100644 --- a/dmserver/include/display_manager_interface.h +++ b/dmserver/include/display_manager_interface.h @@ -18,23 +18,36 @@ #include +#include + #include "display_info.h" +#include "virtual_display_info.h" +// #include "pixel_map.h" + namespace OHOS::Rosen { class IDisplayManager : public IRemoteBroker { public: DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.IDisplayManager"); enum { - TRANS_ID_GET_DISPLAY_INFO = 1, - TRANS_ID_GET_DEFAULT_DISPLAY_ID = 2, - TRANS_ID_GET_DISPLAY_BY_ID = 3, + TRANS_ID_GET_DEFAULT_DISPLAY_ID = 0, + TRANS_ID_GET_DISPLAY_BY_ID, + TRANS_ID_CREATE_VIRTUAL_DISPLAY, + TRANS_ID_DESTROY_VIRTUAL_DISPLAY, + // TODO: fix me + // TRANS_ID_GET_DISPLAY_SNAPSHOT, }; - virtual const sptr& GetDisplayInfo(const DisplayType type) = 0; - virtual DisplayId GetDefaultDisplayId() = 0; virtual DisplayInfo GetDisplayInfoById(DisplayId displayId) = 0; + + virtual DisplayId CreateVirtualDisplay(const VirtualDisplayInfo &virtualDisplayInfo, + sptr surface) = 0; + virtual bool DestroyVirtualDisplay(DisplayId displayId) = 0; + + // TODO: fix me + // virtual sptr GetDispalySnapshot(DisplayId displayId) = 0; }; } // namespace OHOS::Rosen diff --git a/dmserver/include/display_manager_proxy.h b/dmserver/include/display_manager_proxy.h index 519107124d52720ced4aa4842d79c5f5d989dd01..141bb41156691123513823a8e0b9caa2a6e8bc8e 100644 --- a/dmserver/include/display_manager_proxy.h +++ b/dmserver/include/display_manager_proxy.h @@ -27,10 +27,14 @@ public: : IRemoteProxy(impl) {}; ~DisplayManagerProxy() {}; - const sptr& GetDisplayInfo(const DisplayType type) override; - DisplayId GetDefaultDisplayId() override; DisplayInfo GetDisplayInfoById(DisplayId displayId) override; + + DisplayId CreateVirtualDisplay(const VirtualDisplayInfo &virtualDisplayInfo, + sptr surface) override; + bool DestroyVirtualDisplay(DisplayId displayId) override; + // TODO: fix me + // sptr GetDispalySnapshot(DisplayId displayId) override; private: static inline BrokerDelegator delegator_; }; diff --git a/dmserver/include/display_manager_service.h b/dmserver/include/display_manager_service.h index 83ffbbe94abfeb64d7f4b3d7e7cb2f32ad044cc5..2a07d16bd591e6454eb8752c9ac0d4dbc560353c 100644 --- a/dmserver/include/display_manager_service.h +++ b/dmserver/include/display_manager_service.h @@ -20,12 +20,13 @@ #include #include +#include +#include "abstract_display.h" +#include "abstract_display_manager.h" #include "display_manager_stub.h" -#include "display_screen.h" #include "single_instance.h" #include "singleton_delegator.h" -#include "display_screen_manager.h" namespace OHOS::Rosen { class DisplayManagerService : public SystemAbility, public DisplayManagerStub { @@ -36,11 +37,14 @@ DECLARE_SINGLE_INSTANCE_BASE(DisplayManagerService); public: void OnStart() override; void OnStop() override; - const sptr& GetDisplayInfo(const DisplayType type) override; + DisplayId CreateVirtualDisplay(const VirtualDisplayInfo &virtualDisplayInfo, + sptr surface) override; + bool DestroyVirtualDisplay(DisplayId displayId) override; DisplayId GetDefaultDisplayId() override; DisplayInfo GetDisplayInfoById(DisplayId displayId) override; - + // TODO: fix me + // sptr GetDispalySnapshot(DisplayId displayId) override; private: DisplayManagerService(); ~DisplayManagerService() = default; @@ -49,8 +53,7 @@ private: ScreenId GetScreenIdFromDisplayId(DisplayId displayId); static inline SingletonDelegator delegator_; - std::map> displayScreenMap_; - sptr displayScreenManager_; + std::map> abstractDisplayMap_; }; } // namespace OHOS::Rosen diff --git a/dmserver/include/display_manager_service_inner.h b/dmserver/include/display_manager_service_inner.h index 6051c8044364b94d4bccda04b9d4d5e2c08b2c03..9be2dbfbd9e852ec64f785572829961f711e05fc 100644 --- a/dmserver/include/display_manager_service_inner.h +++ b/dmserver/include/display_manager_service_inner.h @@ -19,19 +19,19 @@ #include #include -#include "display_screen.h" +#include "abstract_display.h" #include "single_instance.h" #include "singleton_delegator.h" namespace OHOS::Rosen { -class DisplayManagerServiceInner : public RefBase { +class DisplayManagerServiceInner { DECLARE_SINGLE_INSTANCE(DisplayManagerServiceInner); public: - std::vector> GetAllDisplays(); + std::vector> GetAllDisplays(); DisplayId GetDefaultDisplayId(); - const sptr GetDefaultDisplay(); - const sptr GetDisplayById(DisplayId displayId); + const sptr GetDefaultDisplay(); + const sptr GetDisplayById(DisplayId displayId); std::vector GetAllDisplayIds(); }; } // namespace OHOS::Rosen diff --git a/dmserver/include/display_screen_manager.h b/dmserver/include/display_screen_manager.h deleted file mode 100644 index 0c1df9b379a1c28c9827bd1533d8aae263b9980a..0000000000000000000000000000000000000000 --- a/dmserver/include/display_screen_manager.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#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/interfaces/innerkits/dm/display_property.h b/dmserver/include/virtual_display_info.h similarity index 50% rename from wmtest/interfaces/innerkits/dm/display_property.h rename to dmserver/include/virtual_display_info.h index 7409c0d12d8f142e7e12ce354150b81d387f04e4..cb45bc7803455d30bb7df4e3f34a1788af78b160 100644 --- a/wmtest/interfaces/innerkits/dm/display_property.h +++ b/dmserver/include/virtual_display_info.h @@ -13,26 +13,34 @@ * limitations under the License. */ -#ifndef FOUNDATION_DM_DISPLAY_PROPERTY_H -#define FOUNDATION_DM_DISPLAY_PROPERTY_H +#ifndef FOUNDATION_VIRTUAL_DISPLAY_INFO_H +#define FOUNDATION_VIRTUAL_DISPLAY_INFO_H #include +#include + +#include + +#include "display.h" + namespace OHOS::Rosen { -class DisplayProperty : public RefBase { +class VirtualDisplayInfo : public Parcelable { public: - DisplayProperty() = default; - ~DisplayProperty() = default; + VirtualDisplayInfo(); + VirtualDisplayInfo(const std::string &name, uint32_t width, uint32_t height, + DisplayId displayIdToMirror, int32_t flags); + ~VirtualDisplayInfo() = default; - DisplayType type_; - std::string name_; + virtual bool Marshalling(Parcel& parcel) const override; + static VirtualDisplayInfo* Unmarshalling(Parcel& parcel); - int width_; - int height_; - float xDpi_; - float yDpi_; - // Surface surface_; + std::string name_; + uint32_t width_; + uint32_t height_; + DisplayId displayIdToMirror_; + int32_t flags_; }; } // namespace OHOS::Rosen -#endif // FOUNDATION_DM_DISPLAY_PROPERTY_H \ No newline at end of file +#endif // FOUNDATION_VIRTUAL_DISPLAY_INFO_H \ No newline at end of file diff --git a/wmtest/dmserver/src/display_screen.cpp b/dmserver/src/abstract_display.cpp similarity index 65% rename from wmtest/dmserver/src/display_screen.cpp rename to dmserver/src/abstract_display.cpp index bbc1876a1708a3f7c781c82e9acde37b060f6a4c..32d748df43dda5e7a84c69d0710ebb9958e3d71b 100644 --- a/wmtest/dmserver/src/display_screen.cpp +++ b/dmserver/src/abstract_display.cpp @@ -13,10 +13,10 @@ * limitations under the License. */ -#include "display_screen.h" +#include "abstract_display.h" namespace OHOS::Rosen { -DisplayScreen::DisplayScreen(const DisplayInfo& info) +AbstractDisplay::AbstractDisplay(const DisplayInfo& info) : id_(info.id_), width_(info.width_), height_(info.height_), @@ -24,42 +24,42 @@ DisplayScreen::DisplayScreen(const DisplayInfo& info) { } -DisplayId DisplayScreen::GetId() const +DisplayId AbstractDisplay::GetId() const { return id_; } -int32_t DisplayScreen::GetWidth() const +int32_t AbstractDisplay::GetWidth() const { return width_; } -int32_t DisplayScreen::GetHeight() const +int32_t AbstractDisplay::GetHeight() const { return height_; } -uint32_t DisplayScreen::GetFreshRate() const +uint32_t AbstractDisplay::GetFreshRate() const { return freshRate_; } -void DisplayScreen::SetWidth(int32_t width) +void AbstractDisplay::SetWidth(int32_t width) { width_ = width; } -void DisplayScreen::SetHeight(int32_t height) +void AbstractDisplay::SetHeight(int32_t height) { height_ = height; } -void DisplayScreen::SetFreshRate(uint32_t freshRate) +void AbstractDisplay::SetFreshRate(uint32_t freshRate) { freshRate_ = freshRate; } -void DisplayScreen::SetId(DisplayId id) +void AbstractDisplay::SetId(DisplayId id) { id_ = id; } diff --git a/dmserver/src/abstract_display_manager.cpp b/dmserver/src/abstract_display_manager.cpp new file mode 100644 index 0000000000000000000000000000000000000000..06cadffaeaa1d18d2fe8af141f3c26bf4aa8d878 --- /dev/null +++ b/dmserver/src/abstract_display_manager.cpp @@ -0,0 +1,136 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "abstract_display_manager.h" + +#include "window_manager_hilog.h" + +#include + +namespace OHOS::Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "AbstractDisplayManager"}; +} + +#define SCREENSHOT_GENERATOR + +AbstractDisplayManager::AbstractDisplayManager() : rsInterface_(&(RSInterfaces::GetInstance())) +{ + parepareRSScreenManger(); +} + +AbstractDisplayManager::~AbstractDisplayManager() +{ + rsInterface_ = nullptr; +} + +void AbstractDisplayManager::parepareRSScreenManger() +{ +} + +ScreenId AbstractDisplayManager::GetDefaultScreenId() +{ + if (rsInterface_ == nullptr) { + return INVALID_SCREEN_ID; + } + return rsInterface_->GetDefaultScreenId(); +} + +RSScreenModeInfo AbstractDisplayManager::GetScreenActiveMode(ScreenId id) +{ + RSScreenModeInfo screenModeInfo; + if (rsInterface_ == nullptr) { + return screenModeInfo; + } + return rsInterface_->GetScreenActiveMode(id); +} + +ScreenId AbstractDisplayManager::CreateVirtualScreen(const VirtualDisplayInfo &virtualDisplayInfo, + sptr surface) +{ + if (rsInterface_ == nullptr) { + return INVALID_SCREEN_ID; + } + ScreenId result = rsInterface_->CreateVirtualScreen(virtualDisplayInfo.name_, virtualDisplayInfo.width_, + virtualDisplayInfo.height_, surface, virtualDisplayInfo.displayIdToMirror_, virtualDisplayInfo.flags_); + WLOGFI("AbstractDisplayManager::CreateVirtualDisplay id: %{public}llu", result >> 32); + return result; +} + +bool AbstractDisplayManager::DestroyVirtualScreen(ScreenId screenId) +{ + if (rsInterface_ == nullptr) { + return false; + } + WLOGFI("AbstractDisplayManager::DestroyVirtualScreen"); + rsInterface_->RemoveVirtualScreen(screenId); + return true; +} + +// TODO: fix me +// #ifdef SCREENSHOT_GENERATOR +// sptr TempCreatePixelMap() +// { +// // pixel_map testing code +// Media::InitializationOptions opt; +// opt.size.width = 1920; +// opt.size.height = 1080; +// opt.pixelFormat = Media::PixelFormat::RGBA_8888; +// opt.alphaType = Media::AlphaType::IMAGE_ALPHA_TYPE_OPAQUE; +// opt.scaleMode = Media::ScaleMode::FIT_TARGET_SIZE; +// opt.editable = false; +// opt.useSourceIfMatch = false; + +// const int bitmapDepth = 8; // color depth +// const int bpp = 4; // bytes per pixel +// const int maxByteNum = 256; + +// auto data = (uint32_t *)malloc(opt.size.width * opt.size.height * bpp); +// uint8_t *pic = (uint8_t *)data; +// for (uint32_t i = 0; i < opt.size.width; i++) { +// for (uint32_t j = 0; j < opt.size.height; j++) { +// for (uint32_t k = 0; k < bpp; k++) { +// pic[0] = rand() % maxByteNum; +// pic++; +// } +// } +// } +// uint32_t colorLen = opt.size.width * opt.size.height * bpp * bitmapDepth; +// auto newPixelMap = Media::PixelMap::Create(data, colorLen, opt); +// sptr pixelMap_ = newPixelMap.release(); +// if (pixelMap_ == nullptr) { +// WLOGFE("Failed to get pixelMap"); +// return nullptr; +// } + +// return pixelMap_; +// } +// #endif + +// sptr AbstractDisplayManager::GetScreenSnapshot(ScreenId screenId) +// { +// if (rsInterface_ == nullptr) { +// return nullptr; +// } + +// #ifdef SCREENSHOT_GENERATOR +// sptr screenshot = TempCreatePixelMap(); +// #else +// sptr screenshot = rsInterface_->GetScreenSnapshot(screenId); +// #endif + +// return screenshot; +// } +} // namespace OHOS::Rosen \ No newline at end of file diff --git a/dmserver/src/display_manager_proxy.cpp b/dmserver/src/display_manager_proxy.cpp index a286f6fae44ff740aeed888e34e4cdc4e72d1e78..53c309942803fa82bd7a7399032630b9dc2726f3 100644 --- a/dmserver/src/display_manager_proxy.cpp +++ b/dmserver/src/display_manager_proxy.cpp @@ -15,40 +15,18 @@ #include "display_manager_proxy.h" -#include +#include #include #include "window_manager_hilog.h" +#include + namespace OHOS::Rosen { namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "DisplayManagerProxy"}; } -const sptr& DisplayManagerProxy::GetDisplayInfo(const DisplayType type) -{ - sptr remote = Remote(); - if (remote == nullptr) { - WLOGFW("get display: remote is nullptr"); - return nullptr; - } - - MessageParcel data; - MessageParcel reply; - MessageOption option; - if (!data.WriteInterfaceToken(GetDescriptor())) { - WLOGFE("get display: WriteInterfaceToken failed"); - return nullptr; - } - data.WriteInt32(static_cast(type)); - if (remote->SendRequest(TRANS_ID_GET_DISPLAY_INFO, data, reply, option) != ERR_NONE) { - WLOGFW("get display: SendRequest failed"); - return nullptr; - } - // TODO: decode reply - return nullptr; -} - DisplayId DisplayManagerProxy::GetDefaultDisplayId() { sptr remote = Remote(); @@ -102,4 +80,93 @@ DisplayInfo DisplayManagerProxy::GetDisplayInfoById(DisplayId displayId) } return *info; } + +DisplayId DisplayManagerProxy::CreateVirtualDisplay(const VirtualDisplayInfo &virtualDisplayInfo, + sptr surface) +{ + sptr remote = Remote(); + if (remote == nullptr) { + WLOGFW("create virtual display: remote is nullptr"); + return DISPLAY_ID_INVALD; + } + + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("create virtual display: WriteInterfaceToken failed"); + return DISPLAY_ID_INVALD; + } + bool res = data.WriteParcelable(&virtualDisplayInfo) && + data.WriteRemoteObject(surface->GetProducer()->AsObject()); + if (!res) { + return DISPLAY_ID_INVALD; + } + if (remote->SendRequest(TRANS_ID_CREATE_VIRTUAL_DISPLAY, data, reply, option) != ERR_NONE) { + WLOGFW("create virtual display: SendRequest failed"); + return DISPLAY_ID_INVALD; + } + + DisplayId displayId = reply.ReadUint64(); + WLOGFI("DisplayManagerProxy::CreateVirtualDisplay %" PRIu64"", displayId); + return displayId; +} + +bool DisplayManagerProxy::DestroyVirtualDisplay(DisplayId displayId) +{ + sptr remote = Remote(); + if (remote == nullptr) { + WLOGFW("destroy virtual display: remote is nullptr"); + return false; + } + + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("destroy virtual display: WriteInterfaceToken failed"); + return false; + } + data.WriteUint64(static_cast(displayId)); + if (remote->SendRequest(TRANS_ID_DESTROY_VIRTUAL_DISPLAY, data, reply, option) != ERR_NONE) { + WLOGFW("destroy virtual display: SendRequest failed"); + return false; + } + return reply.ReadBool(); +} + +// TODO: fix me +// sptr DisplayManagerProxy::GetDispalySnapshot(DisplayId displayId) +// { +// sptr remote = Remote(); +// if (remote == nullptr) { +// WLOGFW("GetDispalySnapshot: remote is nullptr"); +// return nullptr; +// } + +// MessageParcel data; +// MessageParcel reply; +// MessageOption option; +// if (!data.WriteInterfaceToken(GetDescriptor())) { +// WLOGFE("GetDispalySnapshot: WriteInterfaceToken failed"); +// return nullptr; +// } + +// if (!data.WriteUint64(displayId)) { +// WLOGFE("Write dispalyId failed"); +// return nullptr; +// } + +// if (remote->SendRequest(TRANS_ID_GET_DISPLAY_SNAPSHOT, data, reply, option) != ERR_NONE) { +// WLOGFW("GetDispalySnapshot: SendRequest failed"); +// return nullptr; +// } + +// sptr pixelMap = reply.ReadParcelable(); +// if (pixelMap == nullptr) { +// WLOGFW("DisplayManagerProxy::GetDispalySnapshot SendRequest nullptr."); +// return nullptr; +// } +// return pixelMap; +// } } // namespace OHOS::Rosen \ No newline at end of file diff --git a/dmserver/src/display_manager_service.cpp b/dmserver/src/display_manager_service.cpp index 93ca0d2d6a4a53e56cdbeb91ffdb52e7f38c56aa..ef9aff6428ccc5311f63e393c962a88a8397979d 100644 --- a/dmserver/src/display_manager_service.cpp +++ b/dmserver/src/display_manager_service.cpp @@ -29,10 +29,7 @@ namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "DisplayManagerService"}; } -IMPLEMENT_SINGLE_INSTANCE(DisplayManagerService); - -const bool REGISTER_RESULT = - SystemAbility::MakeAndRegisterAbility(SingletonContainer::Get().GetRefPtr()); +const bool REGISTER_RESULT = SystemAbility::MakeAndRegisterAbility(&SingletonContainer::Get()); DisplayManagerService::DisplayManagerService() : SystemAbility(DISPLAY_MANAGER_SERVICE_SA_ID, true) { @@ -54,22 +51,10 @@ bool DisplayManagerService::Init() WLOGFW("DisplayManagerService::Init failed"); return false; } - displayScreenManager_ = DisplayScreenManager::GetInstance(); - if (displayScreenManager_ == nullptr) { - WLOGFW("Get DisplayScreenManager failed"); - return false; - } WLOGFI("DisplayManagerService::Init success"); return true; } -const sptr& DisplayManagerService::GetDisplayInfo(const DisplayType type) -{ - // TODO 从displayScreenMap_得到DisplayInfo - WLOGFI("DisplayManagerService::GetDisplayInfo"); - return new DisplayInfo(); -} - DisplayId DisplayManagerService::GetDisplayIdFromScreenId(ScreenId screenId) { return (DisplayId)screenId; @@ -82,10 +67,7 @@ ScreenId DisplayManagerService::GetScreenIdFromDisplayId(DisplayId displayId) DisplayId DisplayManagerService::GetDefaultDisplayId() { - if (displayScreenManager_ == nullptr) { - return DISPLAY_ID_INVALD; - } - ScreenId screenId = displayScreenManager_->GetDefaultScreenId(); + ScreenId screenId = AbstractDisplayManager::GetInstance().GetDefaultScreenId(); WLOGFI("GetDefaultDisplayId %{public}llu", screenId); return GetDisplayIdFromScreenId(screenId); } @@ -93,11 +75,8 @@ DisplayId DisplayManagerService::GetDefaultDisplayId() DisplayInfo DisplayManagerService::GetDisplayInfoById(DisplayId displayId) { DisplayInfo displayInfo; - if (displayScreenManager_ == nullptr) { - return displayInfo; - } ScreenId screenId = GetScreenIdFromDisplayId(displayId); - auto screenModeInfo = displayScreenManager_->GetScreenActiveMode(screenId); + auto screenModeInfo = AbstractDisplayManager::GetInstance().GetScreenActiveMode(screenId); displayInfo.id_ = displayId; displayInfo.width_ = screenModeInfo.GetScreenWidth(); displayInfo.height_ = screenModeInfo.GetScreenHeight(); @@ -105,9 +84,33 @@ DisplayInfo DisplayManagerService::GetDisplayInfoById(DisplayId displayId) return displayInfo; } +DisplayId DisplayManagerService::CreateVirtualDisplay(const VirtualDisplayInfo &virtualDisplayInfo, + sptr surface) +{ + WLOGFI("name %{public}s, width %{public}u, height %{public}u, mirrotId %{public}llu, flags %{public}d", + virtualDisplayInfo.name_.c_str(), virtualDisplayInfo.width_, virtualDisplayInfo.height_, + virtualDisplayInfo.displayIdToMirror_, virtualDisplayInfo.flags_); + ScreenId screenId = AbstractDisplayManager::GetInstance().CreateVirtualScreen(virtualDisplayInfo, surface); + return GetDisplayIdFromScreenId(screenId); +} + +bool DisplayManagerService::DestroyVirtualDisplay(DisplayId displayId) +{ + WLOGFI("DisplayManagerService::DestroyVirtualDisplay"); + ScreenId screenId = GetScreenIdFromDisplayId(displayId); + return AbstractDisplayManager::GetInstance().DestroyVirtualScreen(screenId); +} + +// TODO: fix me +// sptr DisplayManagerService::GetDispalySnapshot(DisplayId displayId) +// { +// ScreenId screenId = GetScreenIdFromDisplayId(displayId); +// sptr screenSnapshot = AbstractDisplayManager::GetInstance().GetScreenSnapshot(screenId); +// return screenSnapshot; +// } + void DisplayManagerService::OnStop() { WLOGFI("ready to stop display service."); - displayScreenManager_ = nullptr; } } // namespace OHOS::Rosen \ No newline at end of file diff --git a/dmserver/src/display_manager_service_inner.cpp b/dmserver/src/display_manager_service_inner.cpp index 9b53ac1cfb0768c6cbaee5f18465a7bbcf374d62..6b65413d81694550c5b212a3bee7113ff60eb2a3 100644 --- a/dmserver/src/display_manager_service_inner.cpp +++ b/dmserver/src/display_manager_service_inner.cpp @@ -16,14 +16,13 @@ #include "display_manager_service_inner.h" #include -#include #include #include #include #include -#include "display_screen_manager.h" +#include "abstract_display_manager.h" #include "display_manager_service.h" #include "window_manager_hilog.h" @@ -32,28 +31,15 @@ namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "DisplayManagerServiceInner"}; } -IMPLEMENT_SINGLE_INSTANCE(DisplayManagerServiceInner); - DisplayId DisplayManagerServiceInner::GetDefaultDisplayId() { - auto dms = DisplayManagerService::GetInstance(); - if (dms == nullptr) { - WLOGFE("GetDefaultDisplayId null!\n"); - return DISPLAY_ID_INVALD; - } - return dms->GetDefaultDisplayId(); + return DisplayManagerService::GetInstance().GetDefaultDisplayId(); } -const sptr DisplayManagerServiceInner::GetDisplayById(DisplayId displayId) +const sptr DisplayManagerServiceInner::GetDisplayById(DisplayId displayId) { - auto dms = DisplayManagerService::GetInstance(); - if (dms == nullptr) { - WLOGFE("GetDisplayById null!\n"); - return nullptr; - } - DisplayInfo displayInfo = dms->GetDisplayInfoById(displayId); - - sptr display = new DisplayScreen(displayInfo); + DisplayInfo displayInfo = DisplayManagerService::GetInstance().GetDisplayInfoById(displayId); + sptr display = new AbstractDisplay(displayInfo); if (display == nullptr) { WLOGFE("GetDisplayById failed!\n"); return nullptr; @@ -61,7 +47,7 @@ const sptr DisplayManagerServiceInner::GetDisplayById(DisplayId d return display; } -const sptr DisplayManagerServiceInner::GetDefaultDisplay() +const sptr DisplayManagerServiceInner::GetDefaultDisplay() { return GetDisplayById(GetDefaultDisplayId()); } @@ -73,12 +59,12 @@ std::vector DisplayManagerServiceInner::GetAllDisplayIds() return res; } -std::vector> DisplayManagerServiceInner::GetAllDisplays() +std::vector> DisplayManagerServiceInner::GetAllDisplays() { - std::vector> res; + std::vector> res; auto displayIds = GetAllDisplayIds(); for (auto displayId: displayIds) { - const sptr display = GetDisplayById(displayId); + const sptr display = GetDisplayById(displayId); if (display != nullptr) { res.push_back(display); } else { diff --git a/dmserver/src/display_manager_stub.cpp b/dmserver/src/display_manager_stub.cpp index 0e065619c8ef8c51af5aa8e3dc6db07f0e6fe872..260a1416bdf11b61422718dac8fa35000a57dc01 100644 --- a/dmserver/src/display_manager_stub.cpp +++ b/dmserver/src/display_manager_stub.cpp @@ -19,6 +19,8 @@ #include "window_manager_hilog.h" +#include "transaction/rs_interfaces.h" + namespace OHOS::Rosen { namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "DisplayManagerStub"}; @@ -33,12 +35,6 @@ int32_t DisplayManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, return -1; } switch (code) { - case TRANS_ID_GET_DISPLAY_INFO: { - DisplayType type = static_cast(data.ReadInt32()); - sptr info = GetDisplayInfo(type); - reply.WriteParcelable(info.GetRefPtr()); - break; - } case TRANS_ID_GET_DEFAULT_DISPLAY_ID: { DisplayId displayId = GetDefaultDisplayId(); reply.WriteUint64(displayId); @@ -50,6 +46,30 @@ int32_t DisplayManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, reply.WriteParcelable(&info); break; } + case TRANS_ID_CREATE_VIRTUAL_DISPLAY: { + VirtualDisplayInfo* virtualDisplayInfo = data.ReadParcelable(); + sptr surfaceObject = data.ReadRemoteObject(); + sptr bp = iface_cast(surfaceObject); + sptr surface = Surface::CreateSurfaceAsProducer(bp); + DisplayId virtualId = CreateVirtualDisplay(*virtualDisplayInfo, surface); + reply.WriteUint64(virtualId); + virtualDisplayInfo = nullptr; + break; + } + case TRANS_ID_DESTROY_VIRTUAL_DISPLAY: { + DisplayId virtualId = static_cast(data.ReadUint64()); + bool result = DestroyVirtualDisplay(virtualId); + reply.WriteBool(result); + break; + } + // TODO: fix me + // case TRANS_ID_GET_DISPLAY_SNAPSHOT: { + // DisplayId displayId = data.ReadUint64(); + + // sptr dispalySnapshot = GetDispalySnapshot(displayId); + // reply.WriteParcelable(dispalySnapshot.GetRefPtr()); + // break; + // } default: WLOGFW("unknown transaction code"); return IPCObjectStub::OnRemoteRequest(code, data, reply, option); diff --git a/dmserver/src/display_screen.cpp b/dmserver/src/display_screen.cpp deleted file mode 100644 index bbc1876a1708a3f7c781c82e9acde37b060f6a4c..0000000000000000000000000000000000000000 --- a/dmserver/src/display_screen.cpp +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "display_screen.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 deleted file mode 100644 index 91620c7493cc2452158a5080a8ccd0385f80d1aa..0000000000000000000000000000000000000000 --- a/dmserver/src/display_screen_manager.cpp +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "display_screen_manager.h" - -namespace OHOS::Rosen { -IMPLEMENT_SINGLE_INSTANCE(DisplayScreenManager); - -DisplayScreenManager::DisplayScreenManager() : rsInterface_(&(RSInterfaces::GetInstance())) -{ - parepareRSScreenManger(); -} - -DisplayScreenManager::~DisplayScreenManager() -{ - rsInterface_ = nullptr; -} - -void DisplayScreenManager::parepareRSScreenManger() -{ -} - -ScreenId DisplayScreenManager::GetDefaultScreenId() -{ - if (rsInterface_ == nullptr) { - return INVALID_SCREEN_ID; - } - return rsInterface_->GetDefaultScreenId(); -} - -RSScreenModeInfo DisplayScreenManager::GetScreenActiveMode(ScreenId id) -{ - RSScreenModeInfo screenModeInfo; - if (rsInterface_ == nullptr) { - return screenModeInfo; - } - return rsInterface_->GetScreenActiveMode(id); -} -} // namespace OHOS::Rosen \ No newline at end of file diff --git a/dmserver/src/rs_adapter.cpp b/dmserver/src/rs_adapter.cpp index 5e5d66581dbf3064e666305cfc936108183dcf5f..3b5e59a25ead06bf229a7d07344c22dae78c1e8b 100644 --- a/dmserver/src/rs_adapter.cpp +++ b/dmserver/src/rs_adapter.cpp @@ -26,8 +26,6 @@ namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "RsAdapter"}; } -IMPLEMENT_SINGLE_INSTANCE(RsAdapter); - bool RsAdapter::InitRSProxyLocked() { WLOGFI("InitRProxy"); diff --git a/wmtest/dmserver/src/display_info.cpp b/dmserver/src/virtual_display_info.cpp similarity index 36% rename from wmtest/dmserver/src/display_info.cpp rename to dmserver/src/virtual_display_info.cpp index e26ebf2f44aa87ca28df1fddbdcafc8e37f864d8..9542f71511d6453964647345297c156b02b34049 100644 --- a/wmtest/dmserver/src/display_info.cpp +++ b/dmserver/src/virtual_display_info.cpp @@ -1,56 +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 "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; -} +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "virtual_display_info.h" + +namespace OHOS::Rosen { +VirtualDisplayInfo::VirtualDisplayInfo() +{ + name_ = ""; + width_ = 0; + height_ = 0; + displayIdToMirror_ = 0; + flags_ = 0; +} + +VirtualDisplayInfo::VirtualDisplayInfo(const std::string &name, uint32_t width, uint32_t height, + DisplayId displayIdToMirror, int32_t flags) +{ + name_ = name; + width_ = width; + height_ = height; + displayIdToMirror_ = displayIdToMirror; + flags_ = flags; +} + +bool VirtualDisplayInfo::Marshalling(Parcel &parcel) const +{ + return parcel.WriteString(name_) && parcel.WriteUint32(width_) && + parcel.WriteUint32(height_) && parcel.WriteUint64(displayIdToMirror_) && + parcel.WriteInt32(flags_); +} + +VirtualDisplayInfo* VirtualDisplayInfo::Unmarshalling(Parcel &parcel) +{ + VirtualDisplayInfo *virtualDisplayInfo = new VirtualDisplayInfo(); + if (virtualDisplayInfo == nullptr) { + return nullptr; + } + bool res = parcel.ReadString(virtualDisplayInfo->name_) && + parcel.ReadUint32(virtualDisplayInfo->width_) && + parcel.ReadUint32(virtualDisplayInfo->height_) && + parcel.ReadUint64(virtualDisplayInfo->displayIdToMirror_) && + parcel.ReadInt32(virtualDisplayInfo->flags_); + if (!res) { + return nullptr; + } + return virtualDisplayInfo; +} } // namespace OHOS::Rosen \ No newline at end of file diff --git a/interfaces/innerkits/BUILD.gn b/interfaces/innerkits/BUILD.gn index 19b84753960f4359d913ec18436188ede1b46b63..6c913281dde56ffa5d202b6cd182a856ee8566f1 100644 --- a/interfaces/innerkits/BUILD.gn +++ b/interfaces/innerkits/BUILD.gn @@ -26,6 +26,7 @@ ohos_shared_library("wm_interface") { public_deps = [ "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", "//foundation/graphic/standard/rosen/modules/render_service_client:librender_service_client", + "//foundation/multimedia/image_standard/interfaces/innerkits:image_native", "//foundation/multimodalinput/input/frameworks/proxy:libmmi-client", "//utils/native/base:utils", ] diff --git a/interfaces/innerkits/dm/display_manager.h b/interfaces/innerkits/dm/display_manager.h index ed91aba1d3324c2cd3a802664bd5ee07ac7cf201..7db69d16d697357260494f2e3c3b32ed453bcb59 100644 --- a/interfaces/innerkits/dm/display_manager.h +++ b/interfaces/innerkits/dm/display_manager.h @@ -16,19 +16,22 @@ #ifndef FOUNDATION_DM_DISPLAY_MANAGER_H #define FOUNDATION_DM_DISPLAY_MANAGER_H -#include #include +#include #include "display.h" #include "single_instance.h" +#include "virtual_display_info.h" +// #include "pixel_map.h" +// #include "wm_common.h" + namespace OHOS::Rosen { class DisplayManagerAdapter; -class DisplayManager : public RefBase { -DECLARE_SINGLE_INSTANCE_BASE(DisplayManager); +class DisplayManager { +DECLARE_SINGLE_INSTANCE(DisplayManager); public: - const sptr& GetDisplay(const DisplayType type); std::vector> GetAllDisplays(); DisplayId GetDefaultDisplayId(); @@ -38,10 +41,14 @@ public: std::vector GetAllDisplayIds(); -private: - DisplayManager(); - ~DisplayManager(); - sptr dmsAdapter_; + DisplayId CreateVirtualDisplay(const std::string &name, uint32_t width, uint32_t height, + sptr surface, DisplayId displayIdToMirror, int32_t flags); + + bool DestroyVirtualDisplay(DisplayId displayId); + // TODO: fix me + // sptr GetScreenshot(DisplayId displayId); + // sptr GetScreenshot(DisplayId displayId, const Media::Rect &rect, + // const Media::Size &size, int rotation); }; } // namespace OHOS::Rosen diff --git a/interfaces/innerkits/wm/window.h b/interfaces/innerkits/wm/window.h index 7b7d89eae0dba0f01fc89f7163a96d88215c5b24..e20e0f7b6bfdbd8b4e264ee877bbaaa977b05a2d 100644 --- a/interfaces/innerkits/wm/window.h +++ b/interfaces/innerkits/wm/window.h @@ -30,6 +30,9 @@ class NativeValue; class NativeEngine; +namespace OHOS::AppExecFwk { + class Configuration; +} namespace OHOS::AbilityRuntime { class AbilityContext; @@ -42,10 +45,15 @@ public: virtual void OnSizeChange(Rect rect) = 0; }; +class IWindowSystemBarChangeListener : public RefBase { +public: + virtual void OnSystemBarPropertyChange(uint32_t displayId, WindowType type, const SystemBarProperty& prop) = 0; +}; + class Window : public RefBase { public: static sptr Create(const std::string& windowName, - sptr& option, const sptr& abilityToken = nullptr); + sptr& option, const std::shared_ptr& abilityContext = nullptr); static sptr Find(const std::string& windowName); virtual std::shared_ptr GetSurfaceNode() const = 0; @@ -55,9 +63,15 @@ public: virtual WindowMode GetMode() const = 0; virtual const std::string& GetWindowName() const = 0; virtual uint32_t GetWindowId() = 0; + virtual uint32_t GetWindowFlags() = 0; + virtual SystemBarProperty GetSystemBarPropertyByType(WindowType type) = 0; virtual WMError SetWindowType(WindowType type) = 0; virtual WMError SetWindowMode(WindowMode mode) = 0; + virtual WMError AddWindowFlag(WindowFlag flag) = 0; + virtual WMError RemoveWindowFlag(WindowFlag flag) = 0; + virtual WMError SetWindowFlags(uint32_t flags) = 0; + virtual WMError SetSystemBarProperty(WindowType type, const SystemBarProperty& property) = 0; virtual WMError Destroy() = 0; virtual WMError Show() = 0; @@ -70,11 +84,15 @@ public: virtual void AddInputEventListener(std::shared_ptr& inputEventListener) = 0; // for api 7 virtual void ConsumeKeyEvent(std::shared_ptr& inputEvent) = 0; virtual void ConsumePointerEvent(std::shared_ptr& inputEvent) = 0; + virtual void RequestFrame() = 0; + virtual void UpdateConfiguration(const std::shared_ptr& configuration) = 0; virtual void RegisterLifeCycleListener(sptr& listener) = 0; virtual void RegisterWindowChangeListener(sptr& listener) = 0; + virtual void RegisterWindowSystemBarChangeListener(sptr& listener) = 0; virtual WMError SetUIContent(std::shared_ptr context, - std::string& url, NativeEngine* engine, NativeValue* storage) = 0; + std::string& contentInfo, NativeEngine* engine, NativeValue* storage, bool isdistributed = false) = 0; + virtual const std::string& GetContentInfo() = 0; }; } } diff --git a/interfaces/innerkits/wm/window_life_cycle_interface.h b/interfaces/innerkits/wm/window_life_cycle_interface.h index c9fa54b2a31bea26eb9c97cf72802c04fa9e71b3..c03d77e6049c4745f050c12152f8e89965c1baac 100644 --- a/interfaces/innerkits/wm/window_life_cycle_interface.h +++ b/interfaces/innerkits/wm/window_life_cycle_interface.h @@ -25,7 +25,9 @@ public: virtual void AfterForeground() = 0; virtual void AfterBackground() = 0; virtual void AfterFocused() = 0; - virtual void AfterUnFocused() = 0; + // TODO: need rename AfterUnFocused to AfterUnfocused + virtual void AfterUnFocused() {} + virtual void AfterUnfocused() {} }; } } diff --git a/wmtest/wm/include/vsync_station.h b/interfaces/innerkits/wm/window_manager.h similarity index 41% rename from wmtest/wm/include/vsync_station.h rename to interfaces/innerkits/wm/window_manager.h index eba3a26caf4b038270233b5aa7cc8e1d0c927d5a..618c0c8c651a013d1bdcdd40d75cf6d143571839 100644 --- a/wmtest/wm/include/vsync_station.h +++ b/interfaces/innerkits/wm/window_manager.h @@ -13,47 +13,45 @@ * limitations under the License. */ -#ifndef OHOS_VSYNC_STATION_H -#define OHOS_VSYNC_STATION_H +#ifndef OHOS_ROSEN_WINDOW_MANAGER_H +#define OHOS_ROSEN_WINDOW_MANAGER_H -#include -#include -#include #include -#include - #include -#include - +#include +#include #include "single_instance.h" +#include "singleton_delegator.h" +#include "wm_common.h" namespace OHOS { namespace Rosen { -class VsyncStation : public RefBase { -DECLARE_SINGLE_INSTANCE_BASE(VsyncStation); -using OnCallback = std::function; +class IFocusChangedListener : public RefBase { +public: + virtual void OnFocused(uint32_t windowId, sptr abilityToken, + WindowType windowType, int32_t displayId) = 0; + + virtual void OnUnfocused(uint32_t windowId, sptr abilityToken, + WindowType windowType, int32_t displayId) = 0; +}; + +class WindowManager : public RefBase { +DECLARE_SINGLE_INSTANCE_BASE(WindowManager); +friend class WindowManagerAgent; public: - enum class CallbackType { - CALLBACK_INPUT = 0, - CALLBACK_FRAME = 1, - }; - struct VsyncCallback { - OnCallback onCallback; - }; - ~VsyncStation() = default; - void RequestVsync(CallbackType type, std::shared_ptr vsyncCallback); + void RegisterFocusChangedListener(const sptr& listener); + void UnregisterFocusChangedListener(const sptr& listener); 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, {}}, - }; + WindowManager(); + ~WindowManager(); + class Impl; + std::unique_ptr pImpl_; + + void UpdateFocusStatus(uint32_t windowId, const sptr& abilityToken, WindowType windowType, + int32_t displayId, bool focused) const; }; } // namespace Rosen } // namespace OHOS -#endif // OHOS_VSYNC_STATION_H \ No newline at end of file + +#endif // OHOS_ROSEN_WINDOW_MANAGER_H \ No newline at end of file diff --git a/interfaces/innerkits/wm/window_option.h b/interfaces/innerkits/wm/window_option.h index 9f695dae2fa222d3ccf217bfa0d3f8ab56d63c69..e2794660ef6c4489146b40ad517268a1f57453f7 100644 --- a/interfaces/innerkits/wm/window_option.h +++ b/interfaces/innerkits/wm/window_option.h @@ -15,8 +15,9 @@ #ifndef OHOS_ROSEN_WINDOW_OPTION_H #define OHOS_ROSEN_WINDOW_OPTION_H -#include #include +#include +#include #include "wm_common.h" namespace OHOS { @@ -37,6 +38,7 @@ public: void AddWindowFlag(WindowFlag flag); void RemoveWindowFlag(WindowFlag flag); void SetWindowFlags(uint32_t flags); + void SetSystemBarProperty(WindowType type, const SystemBarProperty& property); Rect GetWindowRect() const; WindowType GetWindowType() const; @@ -47,6 +49,7 @@ public: const std::string& GetParentName() const; const std::string& GetWindowName() const; uint32_t GetWindowFlags() const; + const std::unordered_map& GetSystemBarProperty() const; private: Rect windowRect_ { 0, 0, 0, 0 }; WindowType type_ { WindowType::WINDOW_TYPE_APP_MAIN_WINDOW }; @@ -57,6 +60,10 @@ private: std::string parentName_ { "" }; std::string windowName_ { "" }; uint32_t flags_ { 0 }; + std::unordered_map sysBarPropMap_ { + { WindowType::WINDOW_TYPE_STATUS_BAR, SystemBarProperty() }, + { WindowType::WINDOW_TYPE_NAVIGATION_BAR, SystemBarProperty() }, + }; }; } } diff --git a/interfaces/innerkits/wm/window_scene.h b/interfaces/innerkits/wm/window_scene.h index dc984b01f9d773d4a610611e1ccf66babde93c7e..fb647ebe02cf79489482d1dfa1e7cf883ac583af 100644 --- a/interfaces/innerkits/wm/window_scene.h +++ b/interfaces/innerkits/wm/window_scene.h @@ -19,6 +19,7 @@ #include #include #include +#include #include "window.h" #include "window_option.h" @@ -34,7 +35,7 @@ public: ~WindowScene(); WMError Init(int32_t displayId, std::shared_ptr& abilityContext, - sptr& listener); + sptr& listener, sptr option = nullptr); sptr CreateWindow(const std::string& windowName, sptr& option) const; @@ -44,6 +45,10 @@ public: WMError GoBackground() const; WMError RequestFocus() const; + void UpdateConfiguration(const std::shared_ptr& configuration); + WMError SetSystemBarProperty(WindowType type, const SystemBarProperty& property) const; + + const std::string& GetContentInfo() const; private: static inline std::atomic count { 0 }; diff --git a/interfaces/innerkits/wm/wm_common.h b/interfaces/innerkits/wm/wm_common.h index cd472f88b15a46170d649a5e40ae70761e52ddaf..388086cd90acf8ed6c32961e4528271049eb94ad 100644 --- a/interfaces/innerkits/wm/wm_common.h +++ b/interfaces/innerkits/wm/wm_common.h @@ -22,18 +22,23 @@ namespace OHOS { namespace Rosen { enum class WindowType : uint32_t { APP_WINDOW_BASE = 1, - WINDOW_TYPE_APP_MAIN_WINDOW = APP_WINDOW_BASE, - APP_WINDOW_END = 999, + APP_MAIN_WINDOW_BASE = APP_WINDOW_BASE, + WINDOW_TYPE_APP_MAIN_WINDOW = APP_MAIN_WINDOW_BASE, + APP_MAIN_WINDOW_END = WINDOW_TYPE_APP_MAIN_WINDOW, // equals last window type APP_SUB_WINDOW_BASE = 1000, WINDOW_TYPE_MEDIA = APP_SUB_WINDOW_BASE, WINDOW_TYPE_APP_SUB_WINDOW, - APP_SUB_WINDOW_END = 1999, + APP_SUB_WINDOW_END = WINDOW_TYPE_APP_SUB_WINDOW, // equals last window type + APP_WINDOW_END = APP_SUB_WINDOW_END, SYSTEM_WINDOW_BASE = 2000, + BELOW_APP_SYSTEM_WINDOW_BASE = SYSTEM_WINDOW_BASE, WINDOW_TYPE_WALLPAPER = SYSTEM_WINDOW_BASE, + BELOW_APP_SYSTEM_WINDOW_END = WINDOW_TYPE_WALLPAPER, // equals last window type + ABOVE_APP_SYSTEM_WINDOW_BASE = 2100, - WINDOW_TYPE_APP_LAUNCHING, + WINDOW_TYPE_APP_LAUNCHING = ABOVE_APP_SYSTEM_WINDOW_BASE, WINDOW_TYPE_DOCK_SLICE, WINDOW_TYPE_INCOMING_CALL, WINDOW_TYPE_SEARCHING_BAR, @@ -48,12 +53,14 @@ enum class WindowType : uint32_t { WINDOW_TYPE_NAVIGATION_BAR, WINDOW_TYPE_DRAGGING_EFFECT, WINDOW_TYPE_POINTER, - SYSTEM_WINDOW_END = 2999, + ABOVE_APP_SYSTEM_WINDOW_END = WINDOW_TYPE_POINTER, // equals last window type + SYSTEM_WINDOW_END = ABOVE_APP_SYSTEM_WINDOW_END, }; enum class WindowMode : uint32_t { WINDOW_MODE_FULLSCREEN, - WINDOW_MODE_SPLIT, + WINDOW_MODE_SPLIT_PRIMARY, + WINDOW_MODE_SPLIT_SECONDARY, WINDOW_MODE_FLOATING, WINDOW_MODE_PIP }; @@ -68,6 +75,7 @@ enum class WMError : int32_t { WM_ERROR_DESTROYED_OBJECT = 140, WM_ERROR_DEATH_RECIPIENT = 150, WM_ERROR_INVALID_WINDOW = 160, + WM_ERROR_INVALID_OPERATION = 170, WM_ERROR_UNKNOWN, /* weston adater */ @@ -85,6 +93,24 @@ enum class WindowFlag : uint32_t { WINDOW_FLAG_END = 1 << 2, }; +namespace { + constexpr uint32_t SYSTEM_COLOR_WHITE = 0xE5FFFFFF; + constexpr uint32_t SYSTEM_COLOR_BLACK = 0x66000000; +} + +struct SystemBarProperty { + bool enable_; + uint32_t backgroundColor_; + uint32_t contentColor_; + SystemBarProperty() : enable_(true), backgroundColor_(SYSTEM_COLOR_WHITE), contentColor_(SYSTEM_COLOR_BLACK) {} + SystemBarProperty(bool enable, uint32_t background, uint32_t content) + : enable_(enable), backgroundColor_(background), contentColor_(content) {} + bool operator == (const SystemBarProperty& a) const + { + return (enable_ == a.enable_ && backgroundColor_ == a.backgroundColor_ && contentColor_ == a.contentColor_); + } +}; + struct Rect { int32_t posX_; int32_t posY_; diff --git a/interfaces/kits/napi/BUILD.gn b/interfaces/kits/napi/BUILD.gn index 00c0281a28413ee05cff7e7ff7c4b94be2da7bdd..325093f0def890efe269902a105708f694a1b8c2 100644 --- a/interfaces/kits/napi/BUILD.gn +++ b/interfaces/kits/napi/BUILD.gn @@ -54,5 +54,6 @@ group("napi_packages") { deps = [ "display:display", "window:window", + "window_runtime:windowmanager_napi", ] } diff --git a/interfaces/kits/napi/display/native_display_module.cpp b/interfaces/kits/napi/display/native_display_module.cpp index 127326b9e449026db4778019da438286c416ed09..e319bb9471e51d3f05880f52d57465b001f948d3 100644 --- a/interfaces/kits/napi/display/native_display_module.cpp +++ b/interfaces/kits/napi/display/native_display_module.cpp @@ -13,11 +13,8 @@ * limitations under the License. */ -#include "native_display_module.h" - -#include - #include "display_manager.h" +#include "native_display_module.h" #include "wm_common.h" #include "wm_napi_common.h" @@ -31,19 +28,13 @@ struct Param { void Async(napi_env env, std::unique_ptr ¶m) { - sptr dm = DisplayManager::GetInstance(); - if (dm == nullptr) { - GNAPI_LOG("dm error!\n"); - return; - } - - param->display = dm->GetDefaultDisplay(); + param->display = DisplayManager::GetInstance().GetDefaultDisplay(); if (param->display == nullptr) { GNAPI_LOG("Get display failed!"); param->wret = WMError::WM_ERROR_NULLPTR; return; } - GNAPI_LOG("GetDefaultDisplay: id %" PRIu64", w %d, h %d", + GNAPI_LOG("GetDefaultDisplay: id %{public}llu, w %{public}d, h %{public}d", param->display->GetId(), param->display->GetWidth(), param->display->GetHeight()); param->wret = WMError::WM_OK; } diff --git a/interfaces/kits/napi/window/native_window_module.cpp b/interfaces/kits/napi/window/native_window_module.cpp index 46d9254c58f40801d19c19f2a8c4af53a395c90b..288fe190e51c088c864d19107d0fcfacffd03324 100644 --- a/interfaces/kits/napi/window/native_window_module.cpp +++ b/interfaces/kits/napi/window/native_window_module.cpp @@ -57,7 +57,11 @@ struct Param { void Async(napi_env env, std::unique_ptr& param) { - param->ability->GetScene()->GetMainWindow()->Resize(param->width, param->height); + if (param == nullptr || param->ability == nullptr || param->ability->GetWindow() == nullptr) { + GNAPI_LOG("Error, use nullptr!)"); + return; + } + param->ability->GetWindow()->Resize(param->width, param->height); } napi_value MainFunc(napi_env env, napi_callback_info info) @@ -90,7 +94,11 @@ struct Param { void Async(napi_env env, std::unique_ptr& param) { - param->ability->GetScene()->GetMainWindow()->MoveTo(param->x, param->y); + if (param == nullptr || param->ability == nullptr || param->ability->GetWindow() == nullptr) { + GNAPI_LOG("Error, use nullptr!)"); + return; + } + param->ability->GetWindow()->MoveTo(param->x, param->y); } napi_value MainFunc(napi_env env, napi_callback_info info) @@ -122,7 +130,11 @@ struct Param { void Async(napi_env env, std::unique_ptr& param) { - param->ability->GetScene()->GetMainWindow()->SetWindowType(static_cast(param->windowType)); + if (param == nullptr || param->ability == nullptr || param->ability->GetWindow() == nullptr) { + GNAPI_LOG("Error, use nullptr!)"); + return; + } + param->ability->GetWindow()->SetWindowType(static_cast(param->windowType)); } void CreateWindowTypeObject(napi_env env, napi_value value) @@ -163,12 +175,12 @@ struct Param { void Async(napi_env env, std::unique_ptr ¶m) { - param->window = param->ability->GetScene()->GetMainWindow(); - if (param->window == nullptr) { - GNAPI_LOG("Get main-window failed!"); + if (param == nullptr || param->ability == nullptr) { + GNAPI_LOG("Get top window failed!"); param->wret = WMError::WM_ERROR_NULLPTR; return; } + param->window = param->ability->GetWindow(); param->wret = WMError::WM_OK; } @@ -184,6 +196,7 @@ napi_value MainFunc(napi_env env, napi_callback_info info) GNAPI_LOG("Window Interface: getTopWindow()"); GNAPI_LOG("%{public}s called", __PRETTY_FUNCTION__); auto param = std::make_unique(); + NAPI_CALL(env, GetAbility(env, info, param->ability)); return CreatePromise(env, __PRETTY_FUNCTION__, Async, Resolve, param); } } // namespace getTopWindow diff --git a/wmtest/interfaces/kits/napi/BUILD.gn b/interfaces/kits/napi/window_runtime/BUILD.gn similarity index 48% rename from wmtest/interfaces/kits/napi/BUILD.gn rename to interfaces/kits/napi/window_runtime/BUILD.gn index 00c0281a28413ee05cff7e7ff7c4b94be2da7bdd..4c58fe36ec65cb51f5be993adeae20658b5a8b3e 100644 --- a/wmtest/interfaces/kits/napi/BUILD.gn +++ b/interfaces/kits/napi/window_runtime/BUILD.gn @@ -9,50 +9,47 @@ # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and -# limitations under the License. +# 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" -} +config("window_manager_napi_config") { + visibility = [ ":*" ] -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" + include_dirs = [ + "//foundation/windowmanager/interfaces/kits/napi/window_runtime", + "//foundation/windowmanager/interfaces/innerkits/wm", + "//foundation/windowmanager/interfaces/innerkits/dm", + "//foundation/windowmanager/wm/include", + "//foundation/windowmanager/utils/include", + ] } -ohos_shared_library("windowstage") { - sources = [ "window_stage_module.cpp" ] +ohos_shared_library("windowmanager_napi") { + sources = [ + "js_window.cpp", + "js_window_listener.cpp", + "js_window_manager.cpp", + "js_window_utils.cpp", + "window_manager_module.cpp", + ] + configs = [ ":window_manager_napi_config" ] deps = [ - ":window_stage_abc", - ":window_stage_js", + "//foundation/windowmanager/wm:libwm", + "//foundation/windowmanager/wm:libwmutil", + "//foundation/windowmanager/wmserver:libwms", ] - external_deps = [ "napi:ace_napi" ] + external_deps = [ + "aafwk_standard:runtime", + "hiviewdfx_hilog_native:libhilog", + "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/window_runtime/api/@ohos.window.d.ts b/interfaces/kits/napi/window_runtime/api/@ohos.window.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..b486f75714591151d4ee840e2660e4700ca54d32 --- /dev/null +++ b/interfaces/kits/napi/window_runtime/api/@ohos.window.d.ts @@ -0,0 +1,249 @@ +/* +* Copyright (c) 2021 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/** + * Window manager. + * @devices tv, phone, tablet, wearable. +*/ +declare namespace windowmanager { + enum WindowType { + APP_WINDOW_BASE = 1, + APP_MAIN_WINDOW_BASE = APP_WINDOW_BASE, + WINDOW_TYPE_APP_MAIN_WINDOW = APP_MAIN_WINDOW_BASE, + APP_MAIN_WINDOW_END = WINDOW_TYPE_APP_MAIN_WINDOW, // equals last window type + + APP_SUB_WINDOW_BASE = 1000, + WINDOW_TYPE_MEDIA = APP_SUB_WINDOW_BASE, + WINDOW_TYPE_APP_SUB_WINDOW, + APP_SUB_WINDOW_END = WINDOW_TYPE_APP_SUB_WINDOW, // equals last window type + APP_WINDOW_END = APP_SUB_WINDOW_END, + + SYSTEM_WINDOW_BASE = 2000, + BELOW_APP_SYSTEM_WINDOW_BASE = SYSTEM_WINDOW_BASE, + WINDOW_TYPE_WALLPAPER = SYSTEM_WINDOW_BASE, + BELOW_APP_SYSTEM_WINDOW_END = WINDOW_TYPE_WALLPAPER, // equals last window type + + ABOVE_APP_SYSTEM_WINDOW_BASE = 2100, + WINDOW_TYPE_APP_LAUNCHING = ABOVE_APP_SYSTEM_WINDOW_BASE, + WINDOW_TYPE_DOCK_SLICE, + WINDOW_TYPE_INCOMING_CALL, + WINDOW_TYPE_SEARCHING_BAR, + WINDOW_TYPE_SYSTEM_ALARM_WINDOW, + WINDOW_TYPE_INPUT_METHOD_FLOAT, + WINDOW_TYPE_FLOAT, + WINDOW_TYPE_TOAST, + WINDOW_TYPE_STATUS_BAR, + WINDOW_TYPE_PANEL, + WINDOW_TYPE_KEYGUARD, + WINDOW_TYPE_VOLUME_OVERLAY, + WINDOW_TYPE_NAVIGATION_BAR, + WINDOW_TYPE_DRAGGING_EFFECT, + WINDOW_TYPE_POINTER, + ABOVE_APP_SYSTEM_WINDOW_END = WINDOW_TYPE_POINTER, // equals last window type + SYSTEM_WINDOW_END = ABOVE_APP_SYSTEM_WINDOW_END, + } + + enum WindowMode { + /** + * FullSCREEN. + */ + WINDOW_MODE_FULLSCREEN, + + /** + * SPLIT. + */ + WINDOW_MODE_SPLIT, + + /** + * FREEFORM. + */ + WINDOW_MODE_FLOATING, + + /** + * PIP. + */ + WINDOW_MODE_PIP + } + interface WindowManager { + /** + * Create a sub window with a specific id and type. + * @param id Indicates window id. + * @param type Indicates window type. + * @permission ohos.permission.SYSTEM_FLOAT_WINDOW + * @since 7 + */ + create(id: string, type: WindowType, callback: AsyncCallback): void; + /** + * Create a sub window with a specific id and type. + * @param id Indicates window id. + * @param type Indicates window type. + * @permission ohos.permission.SYSTEM_FLOAT_WINDOW + * @since 7 + */ + create(id: string, type: WindowType): Promise; + /** + * Find the sub window by id. + * @param id Indicates window id. + * @since 7 + */ + find(id: string, callback: AsyncCallback): void; + /** + * Find the sub window by id. + * @param id Indicates window id. + * @since 7 + */ + find(id: string): Promise; + + } + /** + * Rectangle + * @devices tv, phone, tablet, wearable, car + * @since 7 + */ + interface Rect { + left: number; + top: number; + width: number; + height: number; + } + + /** + * window size + * @devices tv, phone, tablet, wearable, car + * @since 7 + */ + interface Size { + /** + * the width of the window. + */ + width: number; + + /** + * the height of the window. + */ + height: number; + } + + /** + * Properties of window, it couldn't update automatically + * @devices tv, phone, tablet, wearable, car + * @since 6 + */ + interface WindowProperties { + /** + * the position and size of the window + * @since 7 + */ + windowRect: Rect; + + /** + * window type + * @since 7 + */ + type: WindowType; + } + + interface Window { + /** + * hide sub window. + * @systemapi Hide this for inner system use. + * @since 7 + */ + hide (callback: AsyncCallback): void; + /** + * hide sub window. + * @systemapi Hide this for inner system use. + * @since 7 + */ + hide(): Promise; + + /** + * show sub window. + * @since 7 + */ + show(callback: AsyncCallback): void; + /** + * show sub window. + * @since 7 + */ + show(): Promise; + /** + * Destroy the sub window. + * @since 7 + */ + destroy(callback: AsyncCallback): void; + /** + * Destroy the sub window. + * @since 7 + */ + destroy(): Promise; + /** + * Set the position of a window. + * @param x Indicate the X-coordinate of the window. + * @param y Indicate the Y-coordinate of the window. + * @devices tv, phone, tablet, wearable, liteWearable. + */ + moveTo(x:number, y:number): Promise; + /** + * Set the size of a window . + * @param width Indicates the width of the window. + * @param height Indicates the height of the window. + * @devices tv, phone, tablet, wearable, liteWearable. + */ + resize(width:number, height:number): Promise; + /** + * Set the type of a window. + * @param windowType Indicate the type of a window. + * @devices tv, phone, tablet, wearable, liteWearable. + */ + setWindowType(windowType: WindowType): Promise; + /** + * Set the type of a window. + * @param windowMode Indicate the mode of a window. + * @devices tv, phone, tablet, wearable, liteWearable. + */ + setWindowMode(windowMode: WindowMode): Promise; + /** + * get the properties of current window + * @devices tv, phone, tablet, wearable, car + * @since 6 + */ + getProperties(callback: AsyncCallback): void; + /** + * get the properties of current window + * @devices tv, phone, tablet, wearable, car + * @since 6 + */ + getProperties(): Promise; + + /** + * register the callback of windowSizeChange + * @param type: 'windowSizeChange' + * @devices tv, phone, tablet, wearable, car + * @since 7 + */ + on(type: 'windowSizeChange', callback: Callback): void; + + /** + * unregister the callback of windowSizeChange + * @param type: 'windowSizeChange' + * @devices tv, phone, tablet, wearable, car + * @since 7 + */ + off(type: 'windowSizeChange', callback?: Callback): void; + } +} + +export default windowmanager; diff --git a/interfaces/kits/napi/window_runtime/js_window.cpp b/interfaces/kits/napi/window_runtime/js_window.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1d9f66cc668a82de51875a2bdecbb6ade56c7a71 --- /dev/null +++ b/interfaces/kits/napi/window_runtime/js_window.cpp @@ -0,0 +1,420 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "js_window.h" +#include "window.h" +#include "window_manager_hilog.h" +#include "window_option.h" +namespace OHOS { +namespace Rosen { +using namespace AbilityRuntime; +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "JsWindow"}; +} +JsWindow::JsWindow(const sptr& window, NativeEngine& engine) : windowToken_(window) +{ + windowListener_ = new JsWindowListener(&engine); +} + +void JsWindow::Finalizer(NativeEngine* engine, void* data, void* hint) +{ + WLOGFI("JsWindow::Finalizer is called"); + std::unique_ptr(static_cast(data)); +} + +NativeValue* JsWindow::Show(NativeEngine* engine, NativeCallbackInfo* info) +{ + WLOGFI("JsWindow::Show is called"); + JsWindow* me = CheckParamsAndGetThis(engine, info); + return (me != nullptr) ? me->OnShow(*engine, *info) : nullptr; +} + +NativeValue* JsWindow::Destroy(NativeEngine* engine, NativeCallbackInfo* info) +{ + WLOGFI("JsWindow::Destroy is called"); + JsWindow* me = CheckParamsAndGetThis(engine, info); + return (me != nullptr) ? me->OnDestroy(*engine, *info) : nullptr; +} + +NativeValue* JsWindow::Hide(NativeEngine* engine, NativeCallbackInfo* info) +{ + WLOGFI("JsWindow::Hide is called"); + JsWindow* me = CheckParamsAndGetThis(engine, info); + return (me != nullptr) ? me->OnHide(*engine, *info) : nullptr; +} + +NativeValue* JsWindow::MoveTo(NativeEngine* engine, NativeCallbackInfo* info) +{ + WLOGFI("JsWindow::MoveTo is called"); + JsWindow* me = CheckParamsAndGetThis(engine, info); + return (me != nullptr) ? me->OnMoveTo(*engine, *info) : nullptr; +} + +NativeValue* JsWindow::Resize(NativeEngine* engine, NativeCallbackInfo* info) +{ + WLOGFI("JsWindow::Resize is called"); + JsWindow* me = CheckParamsAndGetThis(engine, info); + return (me != nullptr) ? me->OnResize(*engine, *info) : nullptr; +} + +NativeValue* JsWindow::SetWindowType(NativeEngine* engine, NativeCallbackInfo* info) +{ + WLOGFI("JsWindow::SetWindowType is called"); + JsWindow* me = CheckParamsAndGetThis(engine, info); + return (me != nullptr) ? me->OnSetWindowType(*engine, *info) : nullptr; +} + +NativeValue* JsWindow::SetWindowMode(NativeEngine* engine, NativeCallbackInfo* info) +{ + WLOGFI("JsWindow::SetWindowMode is called"); + JsWindow* me = CheckParamsAndGetThis(engine, info); + return (me != nullptr) ? me->OnSetWindowMode(*engine, *info) : nullptr; +} + +NativeValue* JsWindow::GetProperties(NativeEngine* engine, NativeCallbackInfo* info) +{ + WLOGFI("JsWindow::GetProperties is called"); + JsWindow* me = CheckParamsAndGetThis(engine, info); + return (me != nullptr) ? me->OnGetProperties(*engine, *info) : nullptr; +} + +NativeValue* JsWindow::RegisterWindowCallback(NativeEngine* engine, NativeCallbackInfo* info) +{ + WLOGFI("JsWindow::RegisterWindowCallback is called"); + JsWindow* me = CheckParamsAndGetThis(engine, info); + return (me != nullptr) ? me->OnRegisterWindowCallback(*engine, *info) : nullptr; +} + +NativeValue* JsWindow::UnRegisterWindowCallback(NativeEngine* engine, NativeCallbackInfo* info) +{ + WLOGFI("JsWindow::UnRegisterWindowCallback is called"); + JsWindow* me = CheckParamsAndGetThis(engine, info); + return (me != nullptr) ? me->OnUnRegisterWindowCallback(*engine, *info) : nullptr; +} + +NativeValue* JsWindow::OnShow(NativeEngine& engine, NativeCallbackInfo& info) +{ + WLOGFI("JsWindow::OnShow is called"); + if (windowToken_ == nullptr) { + WLOGFE("JsWindow windowToken_ is nullptr"); + return engine.CreateUndefined(); + } + AsyncTask::CompleteCallback complete = + [this](NativeEngine& engine, AsyncTask& task, int32_t status) { + WMError ret = windowToken_->Show(); + if (ret == WMError::WM_OK) { + task.Resolve(engine, engine.CreateUndefined()); + WLOGFI("JsWindow::OnShow success"); + } else { + task.Reject(engine, CreateJsError(engine, static_cast(ret), "ShowWindow failed.")); + } + }; + + NativeValue* lastParam = (info.argc == 0) ? nullptr : info.argv[0]; + NativeValue* result = nullptr; + AsyncTask::Schedule( + engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result)); + return result; +} + +NativeValue* JsWindow::OnDestroy(NativeEngine& engine, NativeCallbackInfo& info) +{ + WLOGFI("JsWindow::OnDestroy is called"); + if (windowToken_ == nullptr) { + WLOGFE("JsWindow windowToken_ is nullptr"); + return engine.CreateUndefined(); + } + AsyncTask::CompleteCallback complete = + [this](NativeEngine& engine, AsyncTask& task, int32_t status) { + WMError ret = windowToken_->Destroy(); + windowToken_ = nullptr; + if (ret == WMError::WM_OK) { + task.Resolve(engine, engine.CreateUndefined()); + WLOGFI("JsWindow::OnDestroy success"); + } else { + task.Reject(engine, CreateJsError(engine, static_cast(ret), "JsWindow::OnDestroy failed.")); + } + }; + + NativeValue* lastParam = (info.argc == 0) ? nullptr : info.argv[0]; + NativeValue* result = nullptr; + AsyncTask::Schedule( + engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result)); + return result; +} + +NativeValue* JsWindow::OnHide(NativeEngine& engine, NativeCallbackInfo& info) +{ + WLOGFI("JsWindow::OnHide is called"); + if (windowToken_ == nullptr) { + WLOGFE("JsWindow windowToken_ is nullptr"); + return engine.CreateUndefined(); + } + AsyncTask::CompleteCallback complete = + [this](NativeEngine& engine, AsyncTask& task, int32_t status) { + WMError ret = windowToken_->Hide(); + if (ret == WMError::WM_OK) { + task.Resolve(engine, engine.CreateUndefined()); + WLOGFI("JsWindow::OnHide success"); + } else { + task.Reject(engine, CreateJsError(engine, static_cast(ret), "JsWindow::OnHide failed.")); + } + }; + + NativeValue* lastParam = (info.argc == 0) ? nullptr : info.argv[0]; + NativeValue* result = nullptr; + AsyncTask::Schedule( + engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result)); + return result; +} + +NativeValue* JsWindow::OnMoveTo(NativeEngine& engine, NativeCallbackInfo& info) +{ + WLOGFI("JsWindow::OnMoveTo is called"); + if (windowToken_ == nullptr) { + WLOGFE("JsWindow windowToken_ is nullptr"); + return engine.CreateUndefined(); + } + int32_t x; + if (!ConvertFromJsValue(engine, info.argv[0], x)) { + WLOGFE("Failed to convert parameter to x"); + return engine.CreateUndefined(); + } + + int32_t y; + if (!ConvertFromJsValue(engine, info.argv[1], y)) { + WLOGFE("Failed to convert parameter to y"); + return engine.CreateUndefined(); + } + AsyncTask::CompleteCallback complete = + [this, x, y](NativeEngine& engine, AsyncTask& task, int32_t status) { + WMError ret = windowToken_->MoveTo(x, y); + if (ret == WMError::WM_OK) { + task.Resolve(engine, engine.CreateUndefined()); + WLOGFI("JsWindow::OnMoveTo success"); + } else { + task.Reject(engine, CreateJsError(engine, static_cast(ret), "JsWindow::OnMoveTo failed.")); + } + }; + + NativeValue* lastParam = (info.argc == ARGC_TWO) ? nullptr : info.argv[INDEX_TWO]; + NativeValue* result = nullptr; + AsyncTask::Schedule( + engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result)); + return result; +} + +NativeValue* JsWindow::OnResize(NativeEngine& engine, NativeCallbackInfo& info) +{ + WLOGFI("JsWindow::OnResize is called"); + if (windowToken_ == nullptr) { + WLOGFE("JsWindow windowToken_ is nullptr"); + return engine.CreateUndefined(); + } + uint32_t width; + if (!ConvertFromJsValue(engine, info.argv[0], width)) { + WLOGFE("Failed to convert parameter to width"); + return engine.CreateUndefined(); + } + + uint32_t height; + if (!ConvertFromJsValue(engine, info.argv[1], height)) { + WLOGFE("Failed to convert parameter to height"); + return engine.CreateUndefined(); + } + AsyncTask::CompleteCallback complete = + [this, width, height](NativeEngine& engine, AsyncTask& task, int32_t status) { + WMError ret = windowToken_->Resize(width, height); + if (ret == WMError::WM_OK) { + task.Resolve(engine, engine.CreateUndefined()); + } else { + task.Reject(engine, CreateJsError(engine, static_cast(ret), "JsWindow::OnResize failed.")); + } + }; + NativeValue* lastParam = (info.argc == ARGC_TWO) ? nullptr : info.argv[INDEX_TWO]; + NativeValue* result = nullptr; + AsyncTask::Schedule( + engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result)); + return result; +} + +NativeValue* JsWindow::OnSetWindowType(NativeEngine& engine, NativeCallbackInfo& info) +{ + WLOGFI("JsWindow::OnSetWindowType is called"); + if (windowToken_ == nullptr) { + WLOGFE("JsWindow windowToken_ is nullptr"); + return engine.CreateUndefined(); + } + NativeNumber* nativeType = ConvertNativeValueTo(info.argv[0]); + if (nativeType == nullptr) { + WLOGFE("Failed to convert parameter to windowType"); + return engine.CreateUndefined(); + } + WindowType winType = static_cast(static_cast(*nativeType)); + AsyncTask::CompleteCallback complete = + [this, winType](NativeEngine& engine, AsyncTask& task, int32_t status) { + WMError ret = windowToken_->SetWindowType(winType); + if (ret == WMError::WM_OK) { + task.Resolve(engine, engine.CreateUndefined()); + WLOGFI("JsWindow::OnSetWindowType success"); + } else { + task.Reject(engine, CreateJsError(engine, + static_cast(ret), "JsWindow::OnSetWindowType failed.")); + } + }; + + NativeValue* lastParam = (info.argc == ARGC_ONE) ? nullptr : info.argv[INDEX_ONE]; + NativeValue* result = nullptr; + AsyncTask::Schedule( + engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result)); + return result; +} + +NativeValue* JsWindow::OnSetWindowMode(NativeEngine& engine, NativeCallbackInfo& info) +{ + WLOGFI("JsWindow::OnSetWindowMode is called"); + if (windowToken_ == nullptr) { + WLOGFE("JsWindow windowToken_ is nullptr"); + return engine.CreateUndefined(); + } + NativeNumber* nativeMode = ConvertNativeValueTo(info.argv[0]); + if (nativeMode == nullptr) { + WLOGFE("Failed to convert parameter to windowMode"); + return engine.CreateUndefined(); + } + WindowMode winMode = static_cast(static_cast(*nativeMode)); + AsyncTask::CompleteCallback complete = + [this, winMode](NativeEngine& engine, AsyncTask& task, int32_t status) { + WMError ret = windowToken_->SetWindowMode(winMode); + if (ret == WMError::WM_OK) { + task.Resolve(engine, engine.CreateUndefined()); + WLOGFI("JsWindow::OnSetWindowMode success"); + } else { + task.Reject(engine, + CreateJsError(engine, static_cast(ret), "JsWindow::OnSetWindowMode failed.")); + } + }; + + NativeValue* lastParam = (info.argc == ARGC_ONE) ? nullptr : info.argv[INDEX_ONE]; + NativeValue* result = nullptr; + AsyncTask::Schedule( + engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result)); + return result; +} + +NativeValue* JsWindow::OnGetProperties(NativeEngine& engine, NativeCallbackInfo& info) +{ + WLOGFI("JsWindow::OnGetProperties is called"); + if (windowToken_ == nullptr) { + WLOGFE("JsWindow windowToken_ is nullptr"); + return engine.CreateUndefined(); + } + AsyncTask::CompleteCallback complete = + [this](NativeEngine& engine, AsyncTask& task, int32_t status) { + auto objValue = CreateJsWindowPropertiesObject(engine, windowToken_); + WLOGFI("JsWindow::OnGetProperties objValue %{public}p", objValue); + if (objValue != nullptr) { + task.Resolve(engine, objValue); + WLOGFI("JsWindow::OnGetProperties success"); + } else { + task.Reject(engine, CreateJsError(engine, + static_cast(WMError::WM_ERROR_NULLPTR), "JsWindow::OnGetProperties failed.")); + } + }; + + NativeValue* lastParam = (info.argc == 0) ? nullptr : info.argv[0]; + NativeValue* result = nullptr; + AsyncTask::Schedule( + engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result)); + return result; +} + +NativeValue* JsWindow::OnRegisterWindowCallback(NativeEngine& engine, NativeCallbackInfo& info) +{ + WLOGFI("JsWindow::OnRegisterWindowCallback is called"); + if (windowToken_ == nullptr || windowListener_ == nullptr) { + WLOGFE("JsWindow windowToken_ or windowListener_ is nullptr"); + return engine.CreateUndefined(); + } + if (info.argc != ARGC_TWO) { + WLOGFE("Params not match"); + return engine.CreateUndefined(); + } + std::string cbType; + if (!ConvertFromJsValue(engine, info.argv[0], cbType)) { + WLOGFE("Failed to convert parameter to callbackType"); + return engine.CreateUndefined(); + } + NativeValue* value = info.argv[1]; + if (!value->IsCallable()) { + WLOGFI("JsWindow::OnRegisterWindowCallback info->argv[1] is not callable"); + return engine.CreateUndefined(); + } + if (!windowListener_->AddJsListenerObject(cbType, info.argv[1])) { + WLOGFI("JsWindow::OnRegisterWindowCallback failed"); + return engine.CreateUndefined(); + } + if (cbType.compare("windowSizeChange") == 0) { + sptr thisListener(windowListener_); + windowToken_->RegisterWindowChangeListener(thisListener); + WLOGFI("JsWindow::OnRegisterWindowCallback success"); + } + return engine.CreateUndefined(); +} + +NativeValue* JsWindow::OnUnRegisterWindowCallback(NativeEngine& engine, NativeCallbackInfo& info) +{ + WLOGFI("JsWindow::OnUnRegisterWindowCallback is called"); + if (windowToken_ == nullptr || windowListener_ == nullptr) { + WLOGFE("JsWindow windowToken_ or windowListener_ is nullptr"); + return engine.CreateUndefined(); + } + if (info.argc == 0) { + WLOGFE("Params not match"); + return engine.CreateUndefined(); + } + std::string cbType; + if (!ConvertFromJsValue(engine, info.argv[0], cbType)) { + WLOGFE("Failed to convert parameter to callbackType"); + return engine.CreateUndefined(); + } + NativeValue* lastParam = (info.argc == 1) ? nullptr : info.argv[1]; + windowListener_->RemoveJsListenerObject(cbType, lastParam); + return engine.CreateUndefined(); +} + +NativeValue* CreateJsWindowObject(NativeEngine& engine, sptr& window) +{ + WLOGFI("JsWindow::CreateJsWindow is called"); + NativeValue* objValue = engine.CreateObject(); + NativeObject* object = ConvertNativeValueTo(objValue); + + std::unique_ptr jsWindow = std::make_unique(window, engine); + object->SetNativePointer(jsWindow.release(), JsWindow::Finalizer, nullptr); + + BindNativeFunction(engine, *object, "show", JsWindow::Show); + BindNativeFunction(engine, *object, "destroy", JsWindow::Destroy); + BindNativeFunction(engine, *object, "hide", JsWindow::Hide); + BindNativeFunction(engine, *object, "moveTo", JsWindow::MoveTo); + BindNativeFunction(engine, *object, "resetSize", JsWindow::Resize); + BindNativeFunction(engine, *object, "setWindowType", JsWindow::SetWindowType); + BindNativeFunction(engine, *object, "setWindowMode", JsWindow::SetWindowMode); + BindNativeFunction(engine, *object, "getProperties", JsWindow::GetProperties); + BindNativeFunction(engine, *object, "on", JsWindow::RegisterWindowCallback); + BindNativeFunction(engine, *object, "off", JsWindow::UnRegisterWindowCallback); + return objValue; +} +} // namespace Rosen +} // namespace OHOS diff --git a/interfaces/kits/napi/window_runtime/js_window.h b/interfaces/kits/napi/window_runtime/js_window.h new file mode 100644 index 0000000000000000000000000000000000000000..dceeea194a9f5fd47ca8a11d3a71197a30905a07 --- /dev/null +++ b/interfaces/kits/napi/window_runtime/js_window.h @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_JS_WINDOW_H +#define OHOS_JS_WINDOW_H +#include "js_runtime_utils.h" +#include "js_window_listener.h" +#include "js_window_utils.h" +#include "native_engine/native_engine.h" +#include "native_engine/native_value.h" +#include "window.h" +namespace OHOS { +namespace Rosen { +NativeValue* CreateJsWindowObject(NativeEngine& engine, sptr& window); + +class JsWindow final { +public: + JsWindow(const sptr& window, NativeEngine& engine); + ~JsWindow() = default; + static void Finalizer(NativeEngine* engine, void* data, void* hint); + static NativeValue* Show(NativeEngine* engine, NativeCallbackInfo* info); + static NativeValue* Destroy(NativeEngine* engine, NativeCallbackInfo* info); + static NativeValue* Hide(NativeEngine* engine, NativeCallbackInfo* info); + static NativeValue* MoveTo(NativeEngine* engine, NativeCallbackInfo* info); + static NativeValue* Resize(NativeEngine* engine, NativeCallbackInfo* info); + static NativeValue* SetWindowType(NativeEngine* engine, NativeCallbackInfo* info); + static NativeValue* SetWindowMode(NativeEngine* engine, NativeCallbackInfo* info); + static NativeValue* GetProperties(NativeEngine* engine, NativeCallbackInfo* info); + static NativeValue* RegisterWindowCallback(NativeEngine* engine, NativeCallbackInfo* info); + static NativeValue* UnRegisterWindowCallback(NativeEngine* engine, NativeCallbackInfo* info); + +private: + NativeValue* OnShow(NativeEngine& engine, NativeCallbackInfo& info); + NativeValue* OnDestroy(NativeEngine& engine, NativeCallbackInfo& info); + NativeValue* OnHide(NativeEngine& engine, NativeCallbackInfo& info); + NativeValue* OnMoveTo(NativeEngine& engine, NativeCallbackInfo& info); + NativeValue* OnResize(NativeEngine& engine, NativeCallbackInfo& info); + NativeValue* OnSetWindowType(NativeEngine& engine, NativeCallbackInfo& info); + NativeValue* OnSetWindowMode(NativeEngine& engine, NativeCallbackInfo& info); + NativeValue* OnGetProperties(NativeEngine& engine, NativeCallbackInfo& info); + NativeValue* OnRegisterWindowCallback(NativeEngine& engine, NativeCallbackInfo& info); + NativeValue* OnUnRegisterWindowCallback(NativeEngine& engine, NativeCallbackInfo& info); + sptr windowToken_ = nullptr; + sptr windowListener_ = nullptr; +}; +} // namespace Rosen +} // namespace OHOS +#endif \ No newline at end of file diff --git a/interfaces/kits/napi/window_runtime/js_window_listener.cpp b/interfaces/kits/napi/window_runtime/js_window_listener.cpp new file mode 100644 index 0000000000000000000000000000000000000000..686be374fb75f9bd45b99b02ab234179896f7f1a --- /dev/null +++ b/interfaces/kits/napi/window_runtime/js_window_listener.cpp @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "js_window_listener.h" +#include "js_runtime_utils.h" +#include "window_manager_hilog.h" +namespace OHOS { +namespace Rosen { +using namespace AbilityRuntime; +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "JsWindowListener"}; +} +bool JsWindowListener::IsCallbackExists(std::string type, NativeValue* jsListenerObject) +{ + if (jsWinodwListenerObjectMap_.find(type) == jsWinodwListenerObjectMap_.end()) { + WLOGFE("JsWindowListener::IsCallbackExists methodName %{public}s not exist!", type.c_str()); + return false; + } + for (auto iter = jsWinodwListenerObjectMap_[type].begin(); + iter != jsWinodwListenerObjectMap_[type].end(); iter++) { + if (jsListenerObject->StrictEquals((*iter)->Get())) { + WLOGFI("JsWindowListener::AddJsListenerObject callback already exists!"); + return true; + } + } + return false; +} + +bool JsWindowListener::AddJsListenerObject(std::string type, NativeValue* jsListenerObject) +{ + WLOGFI("JsWindowListener::AddJsListenerObject is called"); + std::lock_guard lock(listenerMutex_); + std::unique_ptr callbackRef; + callbackRef.reset(engine_->CreateReference(jsListenerObject, 1)); + if (IsCallbackExists(type, jsListenerObject)) { + WLOGFI("JsWindowListener::AddJsListenerObject jsWinodwListenerObjectMap_ size: %{public}d!", + jsWinodwListenerObjectMap_[type].size()); + return false; + } + jsWinodwListenerObjectMap_[type].insert(std::move(callbackRef)); + WLOGFI("JsWindowListener::AddJsListenerObject failed jsWinodwListenerObjectMap_ size: %{public}d!", + jsWinodwListenerObjectMap_[type].size()); + return true; +} + +void JsWindowListener::RemoveJsListenerObject(std::string type, NativeValue* jsListenerObject) +{ + WLOGFI("JsWindowListener::RemoveJsListenerObject is called"); + std::lock_guard lock(listenerMutex_); + if (jsWinodwListenerObjectMap_.find(type) == jsWinodwListenerObjectMap_.end()) { + WLOGFE("methodName %{public}s not exist!", type.c_str()); + return; + } + if (jsListenerObject == nullptr) { + jsWinodwListenerObjectMap_.erase(type); + } else { + for (auto iter = jsWinodwListenerObjectMap_[type].begin(); + iter != jsWinodwListenerObjectMap_[type].end(); iter++) { + if (jsListenerObject->StrictEquals((*iter)->Get())) { + jsWinodwListenerObjectMap_[type].erase(iter); + } + } + } + WLOGFI("JsWindowListener::RemoveJsListenerObject jsWinodwListenerObjectMap_ size: %{public}d!", + jsWinodwListenerObjectMap_[type].size()); + WLOGFI("JsWindowListener::RemoveJsListenerObject success!"); +} + +void JsWindowListener::OnSizeChange(Rect rect) +{ + WLOGFI("JsWindowListener::OnSizeChange is called"); + NativeValue* sizeValue = engine_->CreateObject(); + NativeObject* object = ConvertNativeValueTo(sizeValue); + if (object == nullptr) { + WLOGFE("Failed to convert rect to jsObject"); + return; + } + object->SetProperty("width", CreateJsValue(*engine_, rect.width_)); + object->SetProperty("height", CreateJsValue(*engine_, rect.height_)); + NativeValue* argv[] = {sizeValue}; + CallJsMethod("windowSizeChange", argv, ArraySize(argv)); +} + +void JsWindowListener::CallJsMethod(const char* methodName, NativeValue* const* argv, size_t argc) +{ + WLOGFI("CallJsMethod methodName = %{public}s", methodName); + if (engine_ == nullptr) { + WLOGFE("engine_ nullptr"); + return; + } + std::lock_guard lock(listenerMutex_); + std::string type(methodName); + if (jsWinodwListenerObjectMap_.find(type) == jsWinodwListenerObjectMap_.end()) { + WLOGFE("methodName %{public}s not exist!", methodName); + return; + } + for (auto iter = jsWinodwListenerObjectMap_[type].begin(); iter != jsWinodwListenerObjectMap_[type].end(); iter++) { + NativeValue* method = (*iter)->Get(); + if (method == nullptr) { + WLOGFE("Failed to get method callback from object"); + return; + } + engine_->CallFunction(engine_->CreateUndefined(), method, argv, argc); + } +} +} // namespace Rosen +} // namespace OHOS \ No newline at end of file diff --git a/wmtest/utils/include/static_call.h b/interfaces/kits/napi/window_runtime/js_window_listener.h similarity index 39% rename from wmtest/utils/include/static_call.h rename to interfaces/kits/napi/window_runtime/js_window_listener.h index e505d2b7aba755d5649597ec593f175261555217..19ba2d834dd2a654aaf2dcdb9d54e2d72f788df7 100644 --- a/wmtest/utils/include/static_call.h +++ b/interfaces/kits/napi/window_runtime/js_window_listener.h @@ -13,27 +13,31 @@ * limitations under the License. */ -#ifndef OHOS_STATIC_CALL_H -#define OHOS_STATIC_CALL_H +#ifndef OHOS_JS_WINDOW_LISTENER_H +#define OHOS_JS_WINDOW_LISTENER_H -#include -#include "singleton_delegator.h" -#include "single_instance.h" +#include +#include +#include +#include "native_engine/native_engine.h" +#include "native_engine/native_value.h" #include "window.h" -#include "window_option.h" namespace OHOS { namespace Rosen { -class StaticCall : public RefBase { - DECLARE_SINGLE_INSTANCE_BASE(StaticCall); +class JsWindowListener : public IWindowChangeListener { public: - virtual sptr CreateWindow(const std::string& windowName, - sptr& option, const sptr& abilityToken = nullptr); -protected: - StaticCall() = default; + explicit JsWindowListener(NativeEngine* engine) : engine_(engine) {} + virtual ~JsWindowListener() = default; + void OnSizeChange(Rect rect) override; + bool AddJsListenerObject(std::string type, NativeValue* jsListenerObject); + void RemoveJsListenerObject(std::string type, NativeValue* jsListenerObject); private: - static inline SingletonDelegator delegator_; + void CallJsMethod(const char* methodName, NativeValue* const* argv = nullptr, size_t argc = 0); + bool IsCallbackExists(std::string type, NativeValue* jsListenerObject); + NativeEngine* engine_ = nullptr; + std::map>> jsWinodwListenerObjectMap_; + std::mutex listenerMutex_; }; -} // namespace ROSEN -} // namespace OHOS - -#endif // FRAMEWORKS_WM_TEST_UT_STATIC_CALL_H \ No newline at end of file +} // namespace Rosen +} // namespace OHOS +#endif /* OHOS_JS_WINDOW_LISTENER_H */ \ No newline at end of file diff --git a/interfaces/kits/napi/window_runtime/js_window_manager.cpp b/interfaces/kits/napi/window_runtime/js_window_manager.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1e883acb1b896edf40dae8569ccebed283983fde --- /dev/null +++ b/interfaces/kits/napi/window_runtime/js_window_manager.cpp @@ -0,0 +1,149 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "js_window_manager.h" +#include "js_runtime_utils.h" +#include "js_window.h" +#include "js_window_utils.h" +#include "native_engine/native_reference.h" +#include "window_manager_hilog.h" +#include "window_option.h" + +namespace OHOS { +namespace Rosen { +using namespace AbilityRuntime; +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "JsWindowManager"}; +} + +class JsWindowManager { +public: + JsWindowManager() = default; + ~JsWindowManager() = default; + + static void Finalizer(NativeEngine* engine, void* data, void* hint) + { + WLOGFI("JsWindowManager::Finalizer is called"); + std::unique_ptr(static_cast(data)); + } + + static NativeValue* CreateWindow(NativeEngine* engine, NativeCallbackInfo* info) + { + JsWindowManager* me = CheckParamsAndGetThis(engine, info); + return (me != nullptr) ? me->OnCreateWindow(*engine, *info) : nullptr; + } + + static NativeValue* FindWindow(NativeEngine* engine, NativeCallbackInfo* info) + { + JsWindowManager* me = CheckParamsAndGetThis(engine, info); + return (me != nullptr) ? me->OnFindWindow(*engine, *info) : nullptr; + } + +private: + + NativeValue* OnCreateWindow(NativeEngine& engine, NativeCallbackInfo& info) + { + WLOGFI("JsOnCreateWindow is called"); + + if (info.argc < ARGC_TWO) { + WLOGFE("OnCreateWindow MUST set windowname"); + return engine.CreateUndefined(); + } + std::string windowName; + if (!ConvertFromJsValue(engine, info.argv[0], windowName)) { + WLOGFE("Failed to convert parameter to windowName"); + return engine.CreateUndefined(); + } + NativeNumber* nativeType = ConvertNativeValueTo(info.argv[1]); + if (nativeType == nullptr) { + WLOGFE("Failed to convert parameter to windowType"); + return engine.CreateUndefined(); + } + WindowType winType = static_cast(static_cast(*nativeType)); + AsyncTask::CompleteCallback complete = + [windowName, winType](NativeEngine& engine, AsyncTask& task, int32_t status) { + sptr windowOption = new WindowOption(); + windowOption->SetWindowType(winType); + sptr window = Window::Create(windowName, windowOption); + if (window != nullptr) { + task.Resolve(engine, CreateJsWindowObject(engine, window)); + WLOGFI("JsWindowManager::OnCreateWindow success"); + } else { + task.Reject(engine, CreateJsError(engine, + static_cast(WMError::WM_ERROR_NULLPTR), "JsWindowManager::OnCreateWindow failed.")); + } + }; + NativeValue* lastParam = (info.argc == ARGC_TWO) ? nullptr : info.argv[INDEX_TWO]; + NativeValue* result = nullptr; + AsyncTask::Schedule( + engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result)); + return result; + } + + NativeValue* OnFindWindow(NativeEngine& engine, NativeCallbackInfo& info) + { + std::string windowName; + if (!ConvertFromJsValue(engine, info.argv[0], windowName)) { + WLOGFE("Failed to convert parameter to windowName"); + return engine.CreateUndefined(); + } + + AsyncTask::CompleteCallback complete = + [windowName](NativeEngine& engine, AsyncTask& task, int32_t status) { + sptr window = Window::Find(windowName); + if (window != nullptr) { + task.Resolve(engine, CreateJsWindowObject(engine, window)); + WLOGFI("JsWindowManager::OnFindWindow success"); + } else { + task.Reject(engine, CreateJsError(engine, + static_cast(WMError::WM_ERROR_NULLPTR), "JsWindow::OnFindWindow failed.")); + } + }; + + NativeValue* lastParam = (info.argc == ARGC_ONE) ? nullptr : info.argv[INDEX_ONE]; + if (lastParam == nullptr) { + WLOGFI("JsWindowManager::OnFindWindow lastParam is nullptr"); + } + NativeValue* result = nullptr; + AsyncTask::Schedule( + engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result)); + return result; + } +}; + +NativeValue* JsWindowManagerInit(NativeEngine* engine, NativeValue* exportObj) +{ + WLOGFI("JsWindowManagerInit is called"); + + if (engine == nullptr || exportObj == nullptr) { + WLOGFE("JsWindowManagerInit engine or exportObj is nullptr"); + return nullptr; + } + + NativeObject* object = ConvertNativeValueTo(exportObj); + if (object == nullptr) { + WLOGFE("JsWindowManagerInit object is nullptr"); + return nullptr; + } + + std::unique_ptr jsWinManager = std::make_unique(); + object->SetNativePointer(jsWinManager.release(), JsWindowManager::Finalizer, nullptr); + + BindNativeFunction(*engine, *object, "create", JsWindowManager::CreateWindow); + BindNativeFunction(*engine, *object, "find", JsWindowManager::FindWindow); + + return engine->CreateUndefined(); +} +} // namespace Rosen +} // namespace OHOS \ No newline at end of file diff --git a/wmtest/utils/src/static_call.cpp b/interfaces/kits/napi/window_runtime/js_window_manager.h similarity index 65% rename from wmtest/utils/src/static_call.cpp rename to interfaces/kits/napi/window_runtime/js_window_manager.h index 5b8797a3b166161f559f06339418113c8469df98..8944eebe432874858d2004099551f3d5818e44a9 100644 --- a/wmtest/utils/src/static_call.cpp +++ b/interfaces/kits/napi/window_runtime/js_window_manager.h @@ -13,16 +13,14 @@ * limitations under the License. */ -#include "static_call.h" - +#include "native_engine/native_engine.h" +#include "native_engine/native_value.h" +#ifndef OHOS_JS_WINDOW_MANAGER_H +#define OHOS_JS_WINDOW_MANAGER_H namespace OHOS { namespace Rosen { -IMPLEMENT_SINGLE_INSTANCE(StaticCall); +NativeValue* JsWindowManagerInit(NativeEngine* engine, NativeValue* exportObj); +} // namespace Rosen +} // namespace OHOS -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 +#endif diff --git a/wmtest/wm/src/window.cpp b/interfaces/kits/napi/window_runtime/js_window_utils.cpp similarity index 31% rename from wmtest/wm/src/window.cpp rename to interfaces/kits/napi/window_runtime/js_window_utils.cpp index e1ac8e3139040df9eb8482218d52dbe4b7edae6b..0dfe19d8a7b7785d5d38de763cc7d905c40af76e 100644 --- a/wmtest/wm/src/window.cpp +++ b/interfaces/kits/napi/window_runtime/js_window_utils.cpp @@ -1,49 +1,60 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "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); -} -} -} +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "js_window_utils.h" +#include "js_runtime_utils.h" +#include "window_manager_hilog.h" +namespace OHOS { +namespace Rosen { +using namespace AbilityRuntime; +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "JsWindowUtils"}; +} + +static NativeValue* GetRectAndConvertToJsValue(NativeEngine& engine, const Rect& rect) +{ + NativeValue* objValue = engine.CreateObject(); + NativeObject* object = ConvertNativeValueTo(objValue); + if (object == nullptr) { + WLOGFE("Failed to convert rect to jsObject"); + return engine.CreateUndefined(); + } + object->SetProperty("left", CreateJsValue(engine, rect.posX_)); + object->SetProperty("top", CreateJsValue(engine, rect.posY_)); + object->SetProperty("width", CreateJsValue(engine, rect.width_)); + object->SetProperty("height", CreateJsValue(engine, rect.height_)); + return objValue; +} + +NativeValue* CreateJsWindowPropertiesObject(NativeEngine& engine, sptr& window) +{ + WLOGFI("JsWindow::CreateJsWindowPropertiesObject is called"); + NativeValue* objValue = engine.CreateObject(); + NativeObject* object = ConvertNativeValueTo(objValue); + if (object == nullptr) { + WLOGFE("Failed to convert windowProperties to jsObject"); + return nullptr; + } + + Rect rect = window->GetRect(); + NativeValue* rectObj = GetRectAndConvertToJsValue(engine, rect); + if (rectObj == nullptr) { + WLOGFE("GetRect failed!"); + } + object->SetProperty("windowRect", rectObj); + object->SetProperty("type", CreateJsValue(engine, window->GetType())); + return objValue; +} +} // namespace Rosen +} // namespace OHOS \ No newline at end of file diff --git a/wmtest/wmserver/include/window_manager_stub.h b/interfaces/kits/napi/window_runtime/js_window_utils.h similarity index 56% rename from wmtest/wmserver/include/window_manager_stub.h rename to interfaces/kits/napi/window_runtime/js_window_utils.h index 4fa7df0aa9b7335b9d08cbae98396157f10e7cb3..a00c712ddcebd6a0b2070c41f769aa4768e3a926 100644 --- a/wmtest/wmserver/include/window_manager_stub.h +++ b/interfaces/kits/napi/window_runtime/js_window_utils.h @@ -1,32 +1,35 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OHOS_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 +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_JS_WINDOW_UTILS_H +#define OHOS_JS_WINDOW_UTILS_H +#include "native_engine/native_engine.h" +#include "native_engine/native_value.h" +#include "window.h" +#include "window_option.h" +#include "wm_common.h" +namespace OHOS { +namespace Rosen { +namespace { + constexpr size_t ARGC_ONE = 1; + constexpr size_t ARGC_TWO = 2; + constexpr int32_t INDEX_ONE = 1; + constexpr int32_t INDEX_TWO = 2; +} + + NativeValue* CreateJsWindowPropertiesObject(NativeEngine& engine, sptr& window); +} +} +#endif \ No newline at end of file diff --git a/wmtest/interfaces/kits/napi/window_stage.js b/interfaces/kits/napi/window_runtime/window_manager_module.cpp similarity index 53% rename from wmtest/interfaces/kits/napi/window_stage.js rename to interfaces/kits/napi/window_runtime/window_manager_module.cpp index 43af79d1a0e23162632d56776f0ad82a123019d9..70c3b95e44db93e0be4fab48a1421fbd7148082f 100644 --- a/wmtest/interfaces/kits/napi/window_stage.js +++ b/interfaces/kits/napi/window_runtime/window_manager_module.cpp @@ -1,26 +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. - */ - -class WindowStage { - constructor(obj) { - this.__window_stage__ = obj - } - - setUIContent(context, url, storage) { - return this.__window_stage__.setUIContent(context, url, storage) - } -} - -export default WindowStage +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "js_window_manager.h" +#include "native_engine/native_engine.h" + +extern "C" __attribute__((constructor)) +void NAPI_application_windowmanager_AutoRegister() +{ + auto moduleManager = NativeModuleManager::GetInstance(); + NativeModule newModuleInfo = { + .name = "application.windowmanager", + .fileName = "application/libwindowmanager_napi.so/windowmanager.js", + .registerCallback = OHOS::Rosen::JsWindowManagerInit, + }; + + moduleManager->Register(&newModuleInfo); +} diff --git a/interfaces/kits/napi/window_stage.js b/interfaces/kits/napi/window_stage.js index 43af79d1a0e23162632d56776f0ad82a123019d9..339f5b910b800ffb9fa1af16115176af9dfa170d 100644 --- a/interfaces/kits/napi/window_stage.js +++ b/interfaces/kits/napi/window_stage.js @@ -21,6 +21,22 @@ class WindowStage { setUIContent(context, url, storage) { return this.__window_stage__.setUIContent(context, url, storage) } + + getMainWindow() { + return this.__window_stage__.getMainWindow() + } + + on(type, callback) { + return this.__window_stage__.on(type, callback) + } + + off(type) { + return this.__window_stage__.off(type) + } + + off(type, callback) { + return this.__window_stage__.off(type, callback) + } } export default WindowStage diff --git a/ohos.build b/ohos.build index 49aaabd0f0d5fd7588fae9c0a98ceacf02323b83..0887e15a4f8e0fc97abaf62048a9b953a55edb95 100644 --- a/ohos.build +++ b/ohos.build @@ -5,11 +5,10 @@ "module_list": [ "//foundation/windowmanager/interfaces/kits/js/declaration:window", "//foundation/windowmanager/sa_profile:wms_sa_profile", - "//foundation/windowmanager/adapter:libwmadaptertest", + "//foundation/windowmanager/adapter:libwmadapter", "//foundation/windowmanager/wm:libwm", "//foundation/windowmanager/wmserver:libwms", "//foundation/windowmanager/wm:libwmutil", - "//foundation/windowmanager/wmtest:rosenwmtest", "//foundation/windowmanager/interfaces/kits/napi:windowstage", "//foundation/windowmanager/interfaces/kits/napi:napi_packages" diff --git a/sa_profile/4606.xml b/sa_profile/4606.xml index aa7248817946bb7fa7eec11c21d3fb778428488a..7a02c334da51c72dd7275991b7f5fe9b667c4f74 100644 --- a/sa_profile/4606.xml +++ b/sa_profile/4606.xml @@ -23,4 +23,4 @@ false 1 - \ No newline at end of file + diff --git a/wmtest/dmserver/include/display_manager_stub.h b/utils/include/noncopyable.h similarity index 50% rename from wmtest/dmserver/include/display_manager_stub.h rename to utils/include/noncopyable.h index d88c4a0c652f4591b600a1e4b2f5ed339502127e..12d3ed7bb1389109be5912cb85559e0393663668 100644 --- a/wmtest/dmserver/include/display_manager_stub.h +++ b/utils/include/noncopyable.h @@ -1,33 +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 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 +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_WM_INCLUDE_NONCOPYABLE_H +#define OHOS_WM_INCLUDE_NONCOPYABLE_H + +#define WM_DISALLOW_COPY_AND_MOVE(className) \ + WM_DISALLOW_COPY(className); \ + WM_DISALLOW_MOVE(className) + +#define WM_DISALLOW_COPY(className) \ + className(const className&) = delete; \ + className& operator=(const className&) = delete + +#define WM_DISALLOW_MOVE(className) \ + className(className&&) = delete; \ + className& operator=(className&&) = delete + +namespace OHOS::Rosen { +class NonCopyable { +protected: + NonCopyable() = default; + virtual ~NonCopyable() = default; + +private: + WM_DISALLOW_COPY_AND_MOVE(NonCopyable); +}; +} // namespace OHOS::Rosen + +#endif // OHOS_WM_INCLUDE_NONCOPYABLE_H diff --git a/utils/include/single_instance.h b/utils/include/single_instance.h index b255caf73d94d65f85c9e98eaad4207333caa372..9c675b66db62c2e370c79018ca1955ab7db75eed 100644 --- a/utils/include/single_instance.h +++ b/utils/include/single_instance.h @@ -19,26 +19,21 @@ namespace OHOS { namespace Rosen { #define DECLARE_SINGLE_INSTANCE_BASE(className) \ public: \ - static sptr GetInstance(); \ -private: \ + static className& GetInstance() \ + { \ + static className instance; \ + return instance; \ + } \ className(const className&) = delete; \ className& operator= (const className&) = delete; \ className(className&&) = delete; \ - className& operator= (className&&) = delete; \ - + className& operator= (className&&) = delete; #define DECLARE_SINGLE_INSTANCE(className) \ DECLARE_SINGLE_INSTANCE_BASE(className) \ -private: \ +protected: \ className() = default; \ - ~className() = default; \ - -#define IMPLEMENT_SINGLE_INSTANCE(className) \ -sptr className::GetInstance() \ -{ \ - static sptr instance = new className(); \ - return instance; \ -} + virtual ~className() = default; } // namespace OHOS } #endif // OHOS_SINGLE_INSTANCE_H diff --git a/utils/include/singleton_container.h b/utils/include/singleton_container.h index 68d6d7e8ec60101761646726b6f38ec9af720958..106ebd3033ccb41b10a4e9d2e27946c01194cc05 100644 --- a/utils/include/singleton_container.h +++ b/utils/include/singleton_container.h @@ -22,53 +22,46 @@ #include #include -#include - +#include "single_instance.h" namespace OHOS { namespace Rosen { -class SingletonContainer : public RefBase { +class SingletonContainer { +DECLARE_SINGLE_INSTANCE_BASE(SingletonContainer); + public: - static sptr GetInstance(); + void AddSingleton(const std::string& name, void* instance); + + void SetSingleton(const std::string& name, void* instance); + + void* GetSingleton(const std::string& name); - 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); + void* DependOn(const std::string& instance, const std::string& name); template - static sptr Get() + static T& Get() { std::string nameT = __PRETTY_FUNCTION__; nameT = nameT.substr(nameT.find("T = ")); nameT = nameT.substr(sizeof("T ="), nameT.length() - sizeof("T = ")); - - using sptrT = sptr; - sptrT ret = nullptr; - const std::any &instance = SingletonContainer::GetInstance()->GetSingleton(nameT); - auto pRet = std::any_cast(&instance); - if (pRet != nullptr) { - ret = *pRet; - } - return ret; + return *(reinterpret_cast(SingletonContainer::GetInstance().GetSingleton(nameT))); } template - static void Set(const sptr &ptr) + static void Set(T& instance) { std::string nameT = __PRETTY_FUNCTION__; nameT = nameT.substr(nameT.find("T = ")); nameT = nameT.substr(sizeof("T ="), nameT.length() - sizeof("T = ")); - - SingletonContainer::GetInstance()->SetSingleton(nameT, ptr); + SingletonContainer::GetInstance().SetSingleton(nameT, &instance); } private: SingletonContainer() = default; - virtual ~SingletonContainer() override; - static inline sptr instance = nullptr; + + virtual ~SingletonContainer(); struct Singleton { - std::any value; + void* value; int32_t refCount; }; std::map stringMap; @@ -77,5 +70,4 @@ private: }; } // namespace Rosen } // namespace OHOS - #endif // FRAMEWORKS_WM_INCLUDE_SINGLETON_CONTAINER_H diff --git a/utils/include/singleton_delegator.h b/utils/include/singleton_delegator.h index dae000468f0385e443135a54846f1c6d05feefe9..7c6b6d11c316ce7c34ef8aef56f5ebaf269918fc 100644 --- a/utils/include/singleton_delegator.h +++ b/utils/include/singleton_delegator.h @@ -30,21 +30,19 @@ public: nameT = __PRETTY_FUNCTION__; nameT = nameT.substr(nameT.find("T = ")); nameT = nameT.substr(sizeof("T ="), nameT.length() - sizeof("T = ")); - SingletonContainer::GetInstance()->AddSingleton(nameT, T::GetInstance()); + SingletonContainer::GetInstance().AddSingleton(nameT, &T::GetInstance()); } ~SingletonDelegator() = default; template - sptr Dep() + S& Dep() { std::string nameS = __PRETTY_FUNCTION__; nameS = nameS.substr(nameS.find("S = ")); nameS = nameS.substr(sizeof("S ="), nameS.length() - sizeof("S = ")); auto ret = SingletonContainer::Get(); - if (ret != nullptr) { - SingletonContainer::GetInstance()->DependOn(nameT, nameS); - } + SingletonContainer::GetInstance().DependOn(nameT, nameS); return ret; } diff --git a/utils/include/static_call.h b/utils/include/static_call.h index e505d2b7aba755d5649597ec593f175261555217..adf68eefb231f20a8945e5596a3639565e46b01b 100644 --- a/utils/include/static_call.h +++ b/utils/include/static_call.h @@ -23,11 +23,11 @@ #include "window_option.h" namespace OHOS { namespace Rosen { -class StaticCall : public RefBase { - DECLARE_SINGLE_INSTANCE_BASE(StaticCall); +class StaticCall { +DECLARE_SINGLE_INSTANCE_BASE(StaticCall); public: virtual sptr CreateWindow(const std::string& windowName, - sptr& option, const sptr& abilityToken = nullptr); + sptr& option, std::shared_ptr abilityContext = nullptr); protected: StaticCall() = default; private: diff --git a/wmtest/utils/include/singleton_delegator.h b/utils/include/window_helper.h similarity index 38% rename from wmtest/utils/include/singleton_delegator.h rename to utils/include/window_helper.h index dae000468f0385e443135a54846f1c6d05feefe9..b2054d8ecd8736589e41cb6f4b4482481466dbfe 100644 --- a/wmtest/utils/include/singleton_delegator.h +++ b/utils/include/window_helper.h @@ -13,45 +13,48 @@ * limitations under the License. */ -#ifndef OHOS_SINGLETON_DELEGATOR_H -#define OHOS_SINGLETON_DELEGATOR_H +#ifndef OHOS_WM_INCLUDE_WM_HELPER_H +#define OHOS_WM_INCLUDE_WM_HELPER_H -#include "singleton_container.h" - -#define MOCKABLE virtual +#include namespace OHOS { namespace Rosen { -template -class SingletonDelegator { +class WindowHelper { public: - SingletonDelegator() + static inline bool IsMainWindow(WindowType type) + { + return (type >= WindowType::APP_MAIN_WINDOW_BASE && type <= WindowType::APP_MAIN_WINDOW_END); + } + + static inline bool IsSubWindow(WindowType type) + { + return (type >= WindowType::APP_SUB_WINDOW_BASE && type <= WindowType::APP_SUB_WINDOW_END); + } + + static inline bool IsAppWindow(WindowType type) + { + return (IsMainWindow(type) || IsSubWindow(type)); + } + + static inline bool IsBelowSystemWindow(WindowType type) + { + return (type >= WindowType::BELOW_APP_SYSTEM_WINDOW_BASE && type <= WindowType::BELOW_APP_SYSTEM_WINDOW_END); + } + + static inline bool IsAboveSystemWindow(WindowType type) { - nameT = __PRETTY_FUNCTION__; - nameT = nameT.substr(nameT.find("T = ")); - nameT = nameT.substr(sizeof("T ="), nameT.length() - sizeof("T = ")); - SingletonContainer::GetInstance()->AddSingleton(nameT, T::GetInstance()); + return (type >= WindowType::ABOVE_APP_SYSTEM_WINDOW_BASE && type <= WindowType::ABOVE_APP_SYSTEM_WINDOW_END); } - ~SingletonDelegator() = default; - template - sptr Dep() + static inline bool IsSystemWindow(WindowType type) { - 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; + return (IsBelowSystemWindow(type) || IsAboveSystemWindow(type)); } -private: - std::string nameT; + WindowHelper() = default; + ~WindowHelper() = default; }; -} // namespace Rosen } // namespace OHOS - -#endif // FRAMEWORKS_WM_INCLUDE_SINGLETON_DELEGATOR_H +} // namespace Rosen +#endif // OHOS_WM_INCLUDE_WM_HELPER_H \ No newline at end of file diff --git a/wmtest/wmserver/include/window_manager_proxy.h b/utils/include/wm_trace.h similarity index 40% rename from wmtest/wmserver/include/window_manager_proxy.h rename to utils/include/wm_trace.h index 60e89fd3cfd206b25681127a72a77c0f2d4864a0..33c15032ce9996460d8f8501e266ffadd4a01bbd 100644 --- a/wmtest/wmserver/include/window_manager_proxy.h +++ b/utils/include/wm_trace.h @@ -13,33 +13,43 @@ * limitations under the License. */ -#ifndef OHOS_WINDOW_MANAGER_PROXY_H -#define OHOS_WINDOW_MANAGER_PROXY_H +#ifndef OHOS_WM_INCLUDE_WM_TRACE_H +#define OHOS_WM_INCLUDE_WM_TRACE_H -#include "window_manager_interface.h" -#include +#include +#include + +#include "noncopyable.h" + +#define WM_SCOPED_TRACE(fmt, ...) WmScopedTrace wmScopedTrace(fmt, ##__VA_ARGS__) +#ifdef WM_DEBUG +#define WM_DEBUG_SCOPED_TRACE(fmt, ...) WmScopedTrace wmScopedTrace(fmt, ##__VA_ARGS__) +#else +#define WM_DEBUG_SCOPED_TRACE(fmt, ...) +#endif + +#define WM_FUNCTION_TRACE() WM_SCOPED_TRACE(__func__) +#define WM_SCOPED_TRACE_BEGIN(fmt, ...) WmTraceBeginWithArgs(fmt, ##__VA_ARGS__) +#define WM_SCOPED_TRACE_END() WmTraceEnd() namespace OHOS { namespace Rosen { -class WindowManagerProxy : public IRemoteProxy { -public: - explicit WindowManagerProxy(const sptr& impl) : IRemoteProxy(impl) {}; +bool WmTraceEnabled(); +void WmTraceBegin(const char* name); +bool WmTraceBeginWithArgs(const char* format, ...) __attribute__((__format__(printf, 1, 2))); +bool WmTraceBeginWithArgv(const char* format, va_list args); +void WmTraceEnd(); - ~WindowManagerProxy() {}; +class WmScopedTrace final { +public: + explicit WmScopedTrace(const char* format, ...) __attribute__((__format__(printf, 2, 3))); + ~WmScopedTrace(); - 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; + WM_DISALLOW_COPY_AND_MOVE(WmScopedTrace); private: - static inline BrokerDelegator delegator_; + bool traceEnabled_ { false }; }; +} // namespace OHOS } -} -#endif // OHOS_WINDOW_MANAGER_PROXY_H +#endif // OHOS_WM_INCLUDE_WM_TRACE_H \ No newline at end of file diff --git a/utils/src/singleton_container.cpp b/utils/src/singleton_container.cpp index 0b851fdae250c59a4b7fc65bf13f346d042c7bb7..09eeb22a2ec4eaaf60450c3393d897366325a0ad 100644 --- a/utils/src/singleton_container.cpp +++ b/utils/src/singleton_container.cpp @@ -23,18 +23,6 @@ namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowManager_SingletonContainer"}; } // namespace -sptr SingletonContainer::GetInstance() -{ - if (instance == nullptr) { - static std::mutex mutex; - std::lock_guard lock(mutex); - if (instance == nullptr) { - instance = new SingletonContainer(); - } - } - return instance; -} - SingletonContainer::~SingletonContainer() { while (singletonMap.empty() == false) { @@ -63,7 +51,7 @@ SingletonContainer::~SingletonContainer() } } -void SingletonContainer::AddSingleton(const std::string &name, const std::any &instance) +void SingletonContainer::AddSingleton(const std::string& name, void* instance) { if (stringMap.find(name) == stringMap.end()) { static int32_t nextId = 0; @@ -76,7 +64,7 @@ void SingletonContainer::AddSingleton(const std::string &name, const std::any &i } } -void SingletonContainer::SetSingleton(const std::string &name, const std::any &instance) +void SingletonContainer::SetSingleton(const std::string& name, void* instance) { if (stringMap.find(name) == stringMap.end()) { AddSingleton(name, instance); @@ -86,21 +74,20 @@ void SingletonContainer::SetSingleton(const std::string &name, const std::any &i } } -const std::any &SingletonContainer::GetSingleton(const std::string &name) +void* SingletonContainer::GetSingleton(const std::string& name) { if (stringMap.find(name) == stringMap.end()) { WLOGFD("cannot get %{public}s", name.c_str()); - static std::any voidAny; - return voidAny; + return nullptr; } return singletonMap[stringMap[name]].value; } -const std::any &SingletonContainer::DependOn(const std::string &instance, const std::string &name) +void* SingletonContainer::DependOn(const std::string& instance, const std::string& name) { - auto &instanceDependencySet = dependencySetMap[stringMap[instance]]; + auto& instanceDependencySet = dependencySetMap[stringMap[instance]]; if (instanceDependencySet.find(stringMap[name]) == instanceDependencySet.end()) { - WLOGFD("%{public}s dependon %{public}s", instance.c_str(), name.c_str()); + WLOGFD("%{public}s DependOn %{public}s", instance.c_str(), name.c_str()); instanceDependencySet.insert(stringMap[name]); singletonMap[stringMap[name]].refCount++; } diff --git a/utils/src/static_call.cpp b/utils/src/static_call.cpp index 5b8797a3b166161f559f06339418113c8469df98..1e8153217ce657f15b5ca105cc74ccc599ac9362 100644 --- a/utils/src/static_call.cpp +++ b/utils/src/static_call.cpp @@ -17,12 +17,10 @@ namespace OHOS { namespace Rosen { -IMPLEMENT_SINGLE_INSTANCE(StaticCall); - sptr StaticCall::CreateWindow(const std::string& windowName, - sptr& option, const sptr& abilityToken) + sptr& option, std::shared_ptr abilityContext) { - return Window::Create(windowName, option, abilityToken); + return Window::Create(windowName, option, abilityContext); } } // namespace Rosen } // namespace OHOS \ No newline at end of file diff --git a/wmtest/wm/src/window_agent.cpp b/utils/src/wm_trace.cpp similarity index 35% rename from wmtest/wm/src/window_agent.cpp rename to utils/src/wm_trace.cpp index 79f7a28536838460c6cf5c47cf718df47f170212..16736968cd972661c437ba486160c98cfcf7c86e 100644 --- a/wmtest/wm/src/window_agent.cpp +++ b/utils/src/wm_trace.cpp @@ -13,49 +13,80 @@ * limitations under the License. */ -#include "window_agent.h" -#include "window_manager_hilog.h" +#include "wm_trace.h" + +#include + +#ifndef WINDOWS_PLATFORM +#include +#endif namespace OHOS { namespace Rosen { namespace { - constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowAgent"}; +const size_t MAX_STRING_SIZE = 128; } -WindowAgent::WindowAgent(sptr& windowImpl) +bool WmTraceEnabled() { - window_ = windowImpl; + return true; } -void WindowAgent::UpdateWindowProperty(const WindowProperty& windowProperty) +void WmTraceBegin(const char* name) { + if (name == nullptr) { + return; + } + std::string nameStr(name); + // TODO:need BYTRACE_TAG_WINDOW_MANAGER + StartTrace(BYTRACE_TAG_GRAPHIC_AGP, nameStr); } -void WindowAgent::UpdateWindowRect(const struct Rect& rect) +void WmTraceEnd() { - if (window_ == nullptr) { - WLOGFE("window_ is nullptr"); - return; + if (WmTraceEnabled()) { + // TODO:need BYTRACE_TAG_WINDOW_MANAGER + FinishTrace(BYTRACE_TAG_GRAPHIC_AGP); } - window_->UpdateRect(rect); } -void WindowAgent::UpdateWindowMode(WindowMode mode) +bool WmTraceBeginWithArgv(const char* format, va_list args) { - if (window_ == nullptr) { - WLOGFE("window_ is nullptr"); - return; + char name[MAX_STRING_SIZE] = { 0 }; + if (vsnprintf_s(name, sizeof(name), sizeof(name) - 1, format, args) < 0) { + return false; } - window_->UpdateMode(mode); + WmTraceBegin(name); + return true; } -void WindowAgent::UpdateFocusStatus(bool focused) +bool WmTraceBeginWithArgs(const char* format, ...) { - if (window_ == nullptr) { - WLOGFE("window_ is nullptr"); - return; + if (WmTraceEnabled()) { + va_list args; + va_start(args, format); + bool retVal = WmTraceBeginWithArgv(format, args); + va_end(args); + return retVal; + } + return false; +} + +WmScopedTrace::WmScopedTrace(const char* format, ...) : traceEnabled_(WmTraceEnabled()) +{ + if (traceEnabled_) { + va_list args; + va_start(args, format); + traceEnabled_ = WmTraceBeginWithArgv(format, args); + va_end(args); + } +} + +WmScopedTrace::~WmScopedTrace() +{ + if (traceEnabled_) { + WmTraceEnd(); } - window_->UpdateFocusStatus(focused); } } // namespace Rosen } // namespace OHOS diff --git a/wm/BUILD.gn b/wm/BUILD.gn index a517968506f142873b301717c63dbc94d2715c82..6d7293a9b242d1b90f6c90445f67eadb4a8646e7 100644 --- a/wm/BUILD.gn +++ b/wm/BUILD.gn @@ -43,12 +43,8 @@ config("libwm_config") { "//foundation/graphic/standard/interfaces/innerkits/common", # weston adapter end - ] - - cflags = [ - "-Wall", - "-Werror", - "-g3", + "//third_party/jsoncpp/include", + "//third_party/json/include", ] } @@ -66,11 +62,12 @@ config("libwm_public_config") { ohos_shared_library("libwmutil") { sources = [ "../dmserver/src/display_info.cpp", + "../dmserver/src/virtual_display_info.cpp", + "../utils/src/wm_trace.cpp", "//foundation/windowmanager/dmserver/src/display_manager_proxy.cpp", "//foundation/windowmanager/utils/src/singleton_container.cpp", "//foundation/windowmanager/wm/src/window_proxy.cpp", "//foundation/windowmanager/wmserver/src/window_manager_proxy.cpp", - "src/window_option.cpp", "src/window_property.cpp", ] @@ -85,11 +82,16 @@ ohos_shared_library("libwmutil") { public_deps = [ # RSSurface + "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_core:appexecfwk_core", + "//foundation/graphic/standard:libsurface", "//foundation/graphic/standard/rosen/modules/render_service_base:librender_service_base", "//foundation/graphic/standard/rosen/modules/render_service_client:librender_service_client", ] - external_deps = [ "ipc:ipc_core" ] + external_deps = [ + "bytrace_standard:bytrace_core", + "ipc:ipc_core", + ] part_name = "window_manager" subsystem_name = "window" @@ -110,8 +112,12 @@ ohos_shared_library("libwm") { "src/window_agent.cpp", "src/window_impl.cpp", "src/window_input_channel.cpp", + "src/window_manager.cpp", + "src/window_manager_agent.cpp", + "src/window_option.cpp", "src/window_scene.cpp", "src/window_stub.cpp", + "src/zidl/window_manager_agent_stub.cpp", ] configs = [ ":libwm_config" ] @@ -120,14 +126,15 @@ ohos_shared_library("libwm") { deps = [ "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog", - "//foundation/aafwk/standard/interfaces/innerkits/want:want", "//foundation/distributedschedule/safwk/interfaces/innerkits/safwk:system_ability_fwk", "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", - "//foundation/windowmanager/wm:libwmutil", "//utils/native/base:utils", + # TODO: fix me + # "//foundation/multimedia/image_standard/interfaces/innerkits:image_native", + # weston adapter - "//foundation/windowmanager/adapter:libwmadaptertest", + "//foundation/windowmanager/adapter:libwmadapter", # ace "//foundation/ace/ace_engine/interfaces/innerkits/ace:ace_uicontent", @@ -137,6 +144,7 @@ ohos_shared_library("libwm") { # native value # RSSurface "//foundation/ace/napi:ace_napi", + "//foundation/graphic/standard:libsurface", # vsync "//foundation/graphic/standard:libvsync_client", @@ -148,11 +156,13 @@ ohos_shared_library("libwm") { "//foundation/multimodalinput/input/frameworks/proxy:libmmi-common", # weston adapter - "//foundation/windowmanager/adapter:libwmadaptertest", + "//foundation/windowmanager/adapter:libwmadapter", + "//foundation/windowmanager/wm:libwmutil", ] external_deps = [ "aafwk_standard:ability_context_native", + "bytrace_standard:bytrace_core", "ipc:ipc_core", ] diff --git a/wm/include/input_transfer_station.h b/wm/include/input_transfer_station.h index 5c8fa1466fa3733fda488952225800566cc4b2ad..2e1335c3019ace1a56efbc1d28a9e6b987f1f537 100644 --- a/wm/include/input_transfer_station.h +++ b/wm/include/input_transfer_station.h @@ -17,7 +17,6 @@ #define OHOS_INPUT_TRANSFER_STATION -#include #include #include "input_manager.h" #include "pointer_event.h" @@ -28,20 +27,23 @@ namespace OHOS { namespace Rosen { class InputEventListener; -class InputTransferStation : public RefBase { + +class InputTransferStation { DECLARE_SINGLE_INSTANCE(InputTransferStation); friend class InputEventListener; public: void AddInputWindow(const sptr& window); void RemoveInputWindow(const sptr& window); void SetInputListener(uint32_t windowId, std::shared_ptr& listener); + private: sptr GetInputChannel(uint32_t windowId); bool initInputListener_ = false; std::unordered_map> windowInputChannels_; - std::shared_ptr inputListener_; + std::shared_ptr inputListener_ = nullptr; }; -class InputEventListener: public RefBase, public MMI::IInputEventConsumer { + +class InputEventListener : public RefBase, public MMI::IInputEventConsumer { public: InputEventListener() = default; void OnInputEvent(std::shared_ptr pointerEvent) const override; diff --git a/wm/include/vsync_station.h b/wm/include/vsync_station.h index eba3a26caf4b038270233b5aa7cc8e1d0c927d5a..4fe4720771ec6edd6dfb1137b20f88706b7e76f5 100644 --- a/wm/include/vsync_station.h +++ b/wm/include/vsync_station.h @@ -29,7 +29,7 @@ namespace OHOS { namespace Rosen { -class VsyncStation : public RefBase { +class VsyncStation { DECLARE_SINGLE_INSTANCE_BASE(VsyncStation); using OnCallback = std::function; public: @@ -48,6 +48,8 @@ private: VsyncStation() = default; static void OnVsync(int64_t nanoTimestamp, void* client); void VsyncCallbackInner(int64_t nanoTimestamp); + std::shared_ptr mainHandler_ = nullptr; + std::mutex lock_; std::atomic_bool hasRequestedVsync_ {false}; std::map>> vsyncCallbacks_ = { {CallbackType::CALLBACK_INPUT, {}}, diff --git a/wm/include/window_adapter.h b/wm/include/window_adapter.h index 49ca563360fb9356485d8b259b79331d7fae6dbc..d92b87806bb5ddf433aff1ae05c9f2f9284de2d4 100644 --- a/wm/include/window_adapter.h +++ b/wm/include/window_adapter.h @@ -17,6 +17,7 @@ #define OHOS_WINDOW_ADAPTER_H #include +#include #include "window.h" #include "window_proxy.h" @@ -31,10 +32,9 @@ public: virtual void OnRemoteDied(const wptr& wptrDeath) override; }; -class WindowAdapter : public RefBase { - DECLARE_SINGLE_INSTANCE_BASE(WindowAdapter); +class WindowAdapter { +DECLARE_SINGLE_INSTANCE(WindowAdapter); public: - ~WindowAdapter() = default; virtual WMError CreateWindow(sptr& window, sptr& windowProperty, std::shared_ptr surfaceNode, uint32_t& windowId); virtual WMError AddWindow(sptr& windowProperty); @@ -44,10 +44,13 @@ public: virtual WMError MoveTo(uint32_t windowId, int32_t x, int32_t y); virtual WMError Resize(uint32_t windowId, uint32_t width, uint32_t height); virtual WMError RequestFocus(uint32_t windowId); + virtual WMError SetWindowFlags(uint32_t windowId, uint32_t flags); + virtual WMError SetSystemBarProperty(uint32_t windowId, WindowType type, const SystemBarProperty& property); + + virtual void RegisterFocusChangedListener(const sptr& windowManagerAgent); + virtual void UnregisterFocusChangedListener(const sptr& windowManagerAgent); virtual void ClearWindowAdapter(); -protected: - WindowAdapter() = default; private: static inline SingletonDelegator delegator; bool InitWMSProxyLocked(); diff --git a/wm/include/window_agent.h b/wm/include/window_agent.h index 31bd1ccd4b41deea54d6d0291044660fdbdbe808..60130bdb30790821717efa645ae081a32bc715b0 100644 --- a/wm/include/window_agent.h +++ b/wm/include/window_agent.h @@ -30,6 +30,7 @@ public: void UpdateWindowRect(const struct Rect& rect) override; void UpdateWindowMode(WindowMode mode) override; void UpdateFocusStatus(bool focused) override; + void UpdateSystemBarProperty(const SystemBarProperty& prop) override; private: sptr window_; diff --git a/wm/include/window_impl.h b/wm/include/window_impl.h index 17766e3f105bbffe6812bcd7dc21c28405f31e0b..53e1941759f1e4bee2db6b0387408441874397e3 100644 --- a/wm/include/window_impl.h +++ b/wm/include/window_impl.h @@ -21,6 +21,7 @@ #include #include "window.h" #include "input_transfer_station.h" +#include "vsync_station.h" #include "window_property.h" namespace OHOS { @@ -48,10 +49,17 @@ public: virtual WindowMode GetMode() const override; virtual const std::string& GetWindowName() const override; virtual uint32_t GetWindowId() override; + virtual uint32_t GetWindowFlags() override; + virtual SystemBarProperty GetSystemBarPropertyByType(WindowType type) override; virtual WMError SetWindowType(WindowType type) override; virtual WMError SetWindowMode(WindowMode mode) override; + virtual WMError AddWindowFlag(WindowFlag flag) override; + virtual WMError RemoveWindowFlag(WindowFlag flag) override; + virtual WMError SetWindowFlags(uint32_t flags) override; + virtual WMError SetSystemBarProperty(WindowType type, const SystemBarProperty& property) override; - WMError Create(const std::string& parentName, const sptr& abilityToken = nullptr); + WMError Create(const std::string& parentName, + const std::shared_ptr& abilityContext = nullptr); virtual WMError Destroy() override; virtual WMError Show() override; virtual WMError Hide() override; @@ -63,15 +71,20 @@ public: virtual void RegisterLifeCycleListener(sptr& listener) override; virtual void RegisterWindowChangeListener(sptr& listener) override; + virtual void RegisterWindowSystemBarChangeListener(sptr& listener) override; void UpdateRect(const struct Rect& rect); void UpdateMode(WindowMode mode); virtual void ConsumeKeyEvent(std::shared_ptr& inputEvent) override; virtual void ConsumePointerEvent(std::shared_ptr& inputEvent) override; + virtual void RequestFrame() override; void UpdateFocusStatus(bool focused); + void UpdateSystemBarProperty(const SystemBarProperty& prop); + virtual void UpdateConfiguration(const std::shared_ptr& configuration) override; virtual WMError SetUIContent(std::shared_ptr context, - std::string& url, NativeEngine* engine, NativeValue* storage) override; + std::string& contentInfo, NativeEngine* engine, NativeValue* storage, bool isdistributed) override; + virtual const std::string& GetContentInfo() override; private: inline void NotifyAfterForeground() const @@ -88,7 +101,7 @@ private: } inline void NotifyAfterUnFocused() const { - CALL_LIFECYCLE_LISTENER(AfterUnFocused, UnFocus); + CALL_LIFECYCLE_LISTENER(AfterUnfocused, UnFocus); } inline void NotifyBeforeDestroy() const { @@ -98,6 +111,7 @@ private: } void SetDefaultOption(); // for api7 bool IsWindowValid() const; + void OnVsync(int64_t timeStamp); enum WindowState { STATE_INITIAL, @@ -108,14 +122,23 @@ private: STATE_BOTTOM = STATE_DESTROYED, }; + std::shared_ptr callback_ = + std::make_shared(VsyncStation::VsyncCallback()); static std::map>> windowMap_; + static std::map>> subWindowMap_; sptr property_; WindowState state_ { STATE_INITIAL }; sptr lifecycleListener_; sptr windowChangeListener_; + sptr systemBarChangeListener_; std::shared_ptr surfaceNode_; std::string name_; std::unique_ptr uiContent_; + std::shared_ptr abilityContext_; + const float STATUS_BAR_RATIO = 0.07; + const float NAVIGATION_BAR_RATIO = 0.07; + const float SYSTEM_ALARM_WINDOW_WIDTH_RATIO = 0.8; + const float SYSTEM_ALARM_WINDOW_HEIGHT_RATIO = 0.3; }; } } diff --git a/wm/include/window_interface.h b/wm/include/window_interface.h index 846ded865285ddb6bf00841e5411b64335fd3911..f3f03c0f020f1e594207d7e780e286f2819081ea 100644 --- a/wm/include/window_interface.h +++ b/wm/include/window_interface.h @@ -30,12 +30,14 @@ public: TRANS_ID_UPDATE_WINDOW_RECT, TRANS_ID_UPDATE_WINDOW_MODE, TRANS_ID_UPDATE_FOCUS_STATUS, + TRANS_ID_UPDATE_SYSTEM_BAR_PROPERTY, }; virtual void UpdateWindowProperty(const WindowProperty& windowProperty) = 0; virtual void UpdateWindowRect(const struct Rect& rect) = 0; virtual void UpdateWindowMode(WindowMode mode) = 0; virtual void UpdateFocusStatus(bool focused) = 0; + virtual void UpdateSystemBarProperty(const SystemBarProperty& prop) = 0; }; } // namespace Rosen } // namespace OHOS diff --git a/wmtest/interfaces/innerkits/wm/window_life_cycle_interface.h b/wm/include/window_manager_agent.h similarity index 57% rename from wmtest/interfaces/innerkits/wm/window_life_cycle_interface.h rename to wm/include/window_manager_agent.h index c9fa54b2a31bea26eb9c97cf72802c04fa9e71b3..60318d51185d394aa92484541e36825cc4e1fd47 100644 --- a/wmtest/interfaces/innerkits/wm/window_life_cycle_interface.h +++ b/wm/include/window_manager_agent.h @@ -13,20 +13,21 @@ * limitations under the License. */ -#ifndef OHOS_ROSEN_WINDOW_LIFE_CYCLE_H -#define OHOS_ROSEN_WINDOW_LIFE_CYCLE_H +#ifndef OHOS_WINDOW_MANAGER_AGENT_H +#define OHOS_WINDOW_MANAGER_AGENT_H -#include +#include "zidl/window_manager_agent_stub.h" namespace OHOS { namespace Rosen { -class IWindowLifeCycle : public RefBase { +class WindowManagerAgent : public WindowManagerAgentStub { public: - virtual void AfterForeground() = 0; - virtual void AfterBackground() = 0; - virtual void AfterFocused() = 0; - virtual void AfterUnFocused() = 0; + WindowManagerAgent() = default; + ~WindowManagerAgent() = default; + + void UpdateFocusStatus(uint32_t windowId, const sptr& abilityToken, WindowType windowType, + int32_t displayId, bool focused) override; }; -} -} -#endif // OHOS_ROSEN_WINDOW_LIFE_CYCLE_H +} // namespace Rosen +} // namespace OHOS +#endif // OHOS_WINDOW_MANAGER_AGENT_H diff --git a/wm/include/window_property.h b/wm/include/window_property.h index f8b9ed4ca0d6fa47458baeec987794856c72559d..b9887da3a392181ed11c2f09b6298d276dfdaeff 100644 --- a/wm/include/window_property.h +++ b/wm/include/window_property.h @@ -18,6 +18,7 @@ #include #include +#include #include "parcel.h" #include "wm_common.h" @@ -41,6 +42,7 @@ public: void SetWindowId(uint32_t windowId); void SetParentId(uint32_t parentId); void SetWindowFlags(uint32_t flags); + void SetSystemBarProperty(WindowType type, const SystemBarProperty& state); Rect GetWindowRect() const; WindowType GetWindowType() const; @@ -55,10 +57,10 @@ public: uint32_t GetWindowId() const; uint32_t GetParentId() const; uint32_t GetWindowFlags() const; + const std::unordered_map& GetSystemBarProperty() const; virtual bool Marshalling(Parcel& parcel) const override; static sptr Unmarshalling(Parcel& parcel); - private: Rect windowRect_ { 0, 0, 0, 0 }; WindowType type_ { WindowType::WINDOW_TYPE_APP_MAIN_WINDOW }; @@ -73,6 +75,12 @@ private: int32_t displayId_ { 0 }; uint32_t windowId_ { 0 }; uint32_t parentId_ { 0 }; + std::unordered_map sysBarPropMap_ { + { WindowType::WINDOW_TYPE_STATUS_BAR, SystemBarProperty() }, + { WindowType::WINDOW_TYPE_NAVIGATION_BAR, SystemBarProperty() }, + }; + bool MapMarshalling(Parcel& parcel) const; + static void MapUnmarshalling(Parcel& parcel, sptr& property); }; } } diff --git a/wm/include/window_proxy.h b/wm/include/window_proxy.h index 8e1ea4a52e6aa791451abb05dd5f1dcaf4c8618e..b76759503e48ca75f643efb597a28973b66e7e0a 100644 --- a/wm/include/window_proxy.h +++ b/wm/include/window_proxy.h @@ -31,6 +31,7 @@ public: void UpdateWindowRect(const struct Rect& rect) override; void UpdateWindowMode(WindowMode mode) override; void UpdateFocusStatus(bool focused) override; + void UpdateSystemBarProperty(const SystemBarProperty& prop) override; private: static inline BrokerDelegator delegator_; diff --git a/wmtest/wm/include/window_agent.h b/wm/include/zidl/window_manager_agent_interface.h similarity index 55% rename from wmtest/wm/include/window_agent.h rename to wm/include/zidl/window_manager_agent_interface.h index 31bd1ccd4b41deea54d6d0291044660fdbdbe808..5f12fc61014d33bef2ae4f7fb364f608500cf1a3 100644 --- a/wmtest/wm/include/window_agent.h +++ b/wm/include/zidl/window_manager_agent_interface.h @@ -13,27 +13,25 @@ * limitations under the License. */ -#ifndef OHOS_WINDOW_AGENT_H -#define OHOS_WINDOW_AGENT_H +#ifndef OHOS_WINDOW_MANAGER_AGENT_INTERFACE_H +#define OHOS_WINDOW_MANAGER_AGENT_INTERFACE_H -#include "window_stub.h" -#include "window_impl.h" -#include "window_property.h" +#include +#include "wm_common.h" namespace OHOS { namespace Rosen { -class WindowAgent : public WindowStub { +class IWindowManagerAgent : public IRemoteBroker { 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; + DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.IWindowManagerAgent"); -private: - sptr window_; + enum { + TRANS_ID_UPDATE_FOCUS_STATUS = 1, + }; + + virtual void UpdateFocusStatus(uint32_t windowId, const sptr& abilityToken, WindowType windowType, + int32_t displayId, bool focused) = 0; }; } // namespace Rosen } // namespace OHOS -#endif // OHOS_WINDOW_AGENT_H +#endif // OHOS_WINDOW_MANAGER_AGENT_INTERFACE_H diff --git a/wmtest/wm/include/window_proxy.h b/wm/include/zidl/window_manager_agent_proxy.h similarity index 54% rename from wmtest/wm/include/window_proxy.h rename to wm/include/zidl/window_manager_agent_proxy.h index 8e1ea4a52e6aa791451abb05dd5f1dcaf4c8618e..4798dde4922fe47165ed145a828fc43e0369906c 100644 --- a/wmtest/wm/include/window_proxy.h +++ b/wm/include/zidl/window_manager_agent_proxy.h @@ -13,28 +13,26 @@ * limitations under the License. */ -#ifndef OHOS_WINDOW_PROXY_H -#define OHOS_WINDOW_PROXY_H +#ifndef OHOS_WINDOW_MANAGER_AGENT_PROXY_H +#define OHOS_WINDOW_MANAGER_AGENT_PROXY_H -#include "window_interface.h" +#include "window_manager_agent_interface.h" #include "iremote_proxy.h" namespace OHOS { namespace Rosen { -class WindowProxy : public IRemoteProxy { +class WindowManagerAgentProxy : public IRemoteProxy { public: - explicit WindowProxy(const sptr& impl) : IRemoteProxy(impl) {}; + explicit WindowManagerAgentProxy(const sptr& impl) : IRemoteProxy(impl) {}; - ~WindowProxy() {}; + ~WindowManagerAgentProxy() {}; - void UpdateWindowProperty(const WindowProperty& windowProperty) override; - void UpdateWindowRect(const struct Rect& rect) override; - void UpdateWindowMode(WindowMode mode) override; - void UpdateFocusStatus(bool focused) override; + void UpdateFocusStatus(uint32_t windowId, const sptr& abilityToken, WindowType windowType, + int32_t displayId, bool focused) override; private: - static inline BrokerDelegator delegator_; + static inline BrokerDelegator delegator_; }; } // namespace Rosen } // namespace OHOS -#endif // OHOS_WINDOW_PROXY_H +#endif // OHOS_WINDOW_MANAGER_PROXY_H diff --git a/wmtest/wm/include/window_stub.h b/wm/include/zidl/window_manager_agent_stub.h similarity index 61% rename from wmtest/wm/include/window_stub.h rename to wm/include/zidl/window_manager_agent_stub.h index efc29d3b5081f72df4dd93873e6b03d4a598a5aa..b463e671c734804efa731e50e17d350f72159dfb 100644 --- a/wmtest/wm/include/window_stub.h +++ b/wm/include/zidl/window_manager_agent_stub.h @@ -13,22 +13,22 @@ * limitations under the License. */ -#ifndef OHOS_WINDOW_STUB_H -#define OHOS_WINDOW_STUB_H +#ifndef OHOS_WINDOW_MANAGER_AGENT_STUB_H +#define OHOS_WINDOW_MANAGER_AGENT_STUB_H -#include "window_interface.h" +#include "window_manager_agent_interface.h" #include "iremote_stub.h" namespace OHOS { namespace Rosen { -class WindowStub : public IRemoteStub { +class WindowManagerAgentStub : public IRemoteStub { public: - WindowStub() = default; - ~WindowStub() = default; + WindowManagerAgentStub() = default; + ~WindowManagerAgentStub() = default; - virtual int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, - MessageOption &option) override; + virtual int OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, + MessageOption& option) override; }; } // namespace Rosen } // namespace OHOS -#endif // OHOS_WINDOW_STUB_H +#endif // OHOS_WINDOW_MANAGER_AGENT_STUB_H diff --git a/wm/src/input_transfer_station.cpp b/wm/src/input_transfer_station.cpp index 43adc731bc68971b9c7203896bcd3bf78d55e693..8c5e4521a8966d6336bf27f163ed9c4e602132dd 100644 --- a/wm/src/input_transfer_station.cpp +++ b/wm/src/input_transfer_station.cpp @@ -21,7 +21,6 @@ namespace Rosen { namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "InputTransferStation"}; } -IMPLEMENT_SINGLE_INSTANCE(InputTransferStation) void InputEventListener::OnInputEvent(std::shared_ptr keyEvent) const { WLOGFI("OnInputEvent: receive keyEvent"); @@ -30,7 +29,7 @@ void InputEventListener::OnInputEvent(std::shared_ptr keyEvent) c return; } uint32_t windowId = keyEvent->GetAgentWindowId(); - auto channel = InputTransferStation::GetInstance()->GetInputChannel(windowId); + auto channel = InputTransferStation::GetInstance().GetInputChannel(windowId); if (channel == nullptr) { WLOGE("OnInputEvent channel is nullptr"); return; @@ -56,7 +55,7 @@ void InputEventListener::OnInputEvent(std::shared_ptr pointer return; } uint32_t windowId = pointerEvent->GetAgentWindowId(); - auto channel = InputTransferStation::GetInstance()->GetInputChannel(windowId); + auto channel = InputTransferStation::GetInstance().GetInputChannel(windowId); if (channel == nullptr) { WLOGE("OnInputEvent channel is nullptr"); return; diff --git a/wm/src/vsync_station.cpp b/wm/src/vsync_station.cpp index 4cc44398270977ea9fbb6e77b86547e007e5056b..a55d17d6cc91de15cb4713fe9f171d9241a65b11 100644 --- a/wm/src/vsync_station.cpp +++ b/wm/src/vsync_station.cpp @@ -23,25 +23,34 @@ namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "VsyncStation"}; } -IMPLEMENT_SINGLE_INSTANCE(VsyncStation); - void VsyncStation::RequestVsync(CallbackType type, std::shared_ptr vsyncCallback) { + std::lock_guard lock_l(lock_); auto iter = vsyncCallbacks_.find(type); if (iter == vsyncCallbacks_.end()) { WLOGFE("wrong callback type."); return; } iter->second.insert(vsyncCallback); + if (mainHandler_ == nullptr) { + if (AppExecFwk::EventRunner::GetMainEventRunner() == nullptr) { + WLOGFE("can not get main event runner."); + return; + } + mainHandler_ = std::make_shared(AppExecFwk::EventRunner::GetMainEventRunner()); + } if (!hasRequestedVsync_) { + mainHandler_->PostTask([this]() { + callback_.timestamp_ = 0; + callback_.userdata_ = this; + callback_.callback_ = OnVsync; + WLOGFI("request vsync start."); + VsyncError ret = VsyncHelper::Current()->RequestFrameCallback(callback_); + if (ret != VSYNC_ERROR_OK) { + WLOGFE("VsyncStation::RequestNextVsync fail: %{public}s", VsyncErrorStr(ret).c_str()); + } + }); hasRequestedVsync_.store(true); - 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()); - } } } @@ -58,6 +67,7 @@ void VsyncStation::VsyncCallbackInner(int64_t timestamp) void VsyncStation::OnVsync(int64_t timestamp, void* client) { + WLOGFI("on vsync callback."); auto vsyncClient = static_cast(client); if (vsyncClient) { vsyncClient->VsyncCallbackInner(timestamp); diff --git a/wm/src/window.cpp b/wm/src/window.cpp index e1ac8e3139040df9eb8482218d52dbe4b7edae6b..b054d938847887141819c0483e6498cb2c45ffbb 100644 --- a/wm/src/window.cpp +++ b/wm/src/window.cpp @@ -14,6 +14,7 @@ */ #include "window.h" +#include "window_helper.h" #include "window_impl.h" #include "window_manager_hilog.h" @@ -23,7 +24,7 @@ namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowImpl"}; } sptr Window::Create(const std::string& windowName, sptr& option, - const sptr& abilityToken) + const std::shared_ptr& abilityContext) { if (windowName.empty()) { WLOGFE("window name is empty"); @@ -32,9 +33,14 @@ sptr Window::Create(const std::string& windowName, sptr& o if (option == nullptr) { option = new WindowOption(); } + WindowType type = option->GetWindowType(); + if (!(WindowHelper::IsAppWindow(type) || WindowHelper::IsSystemWindow(type))) { + WLOGFE("window type is invalid %{public}d", type); + return nullptr; + } option->SetWindowName(windowName); sptr windowImpl = new WindowImpl(option); - WMError error = windowImpl->Create(option->GetParentName(), abilityToken); + WMError error = windowImpl->Create(option->GetParentName(), abilityContext); if (error != WMError::WM_OK) { return nullptr; } diff --git a/wm/src/window_adapter.cpp b/wm/src/window_adapter.cpp index 81b169617ed63d643d9299114f6bdfc4bfa5cae3..08d1f93cbbd62571c6216a24acf5e4a796a10d34 100644 --- a/wm/src/window_adapter.cpp +++ b/wm/src/window_adapter.cpp @@ -25,8 +25,6 @@ namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowAdapter"}; } -IMPLEMENT_SINGLE_INSTANCE(WindowAdapter); - WMError WindowAdapter::SaveAbilityToken(const sptr& abilityToken, uint32_t windowId) { std::lock_guard lock(mutex_); @@ -108,6 +106,46 @@ WMError WindowAdapter::RequestFocus(uint32_t windowId) return windowManagerServiceProxy_->RequestFocus(windowId); } +WMError WindowAdapter::SetWindowFlags(uint32_t windowId, uint32_t flags) +{ + std::lock_guard lock(mutex_); + + if (!InitWMSProxyLocked()) { + return WMError::WM_ERROR_SAMGR; + } + return windowManagerServiceProxy_->SetWindowFlags(windowId, flags); +} + +WMError WindowAdapter::SetSystemBarProperty(uint32_t windowId, WindowType type, const SystemBarProperty& property) +{ + std::lock_guard lock(mutex_); + + if (!InitWMSProxyLocked()) { + return WMError::WM_ERROR_SAMGR; + } + return windowManagerServiceProxy_->SetSystemBarProperty(windowId, type, property); +} + +void WindowAdapter::RegisterFocusChangedListener(const sptr& windowManagerAgent) +{ + std::lock_guard lock(mutex_); + + if (!InitWMSProxyLocked()) { + return; + } + return windowManagerServiceProxy_->RegisterFocusChangedListener(windowManagerAgent); +} + +void WindowAdapter::UnregisterFocusChangedListener(const sptr& windowManagerAgent) +{ + std::lock_guard lock(mutex_); + + if (!InitWMSProxyLocked()) { + return; + } + return windowManagerServiceProxy_->UnregisterFocusChangedListener(windowManagerAgent); +} + bool WindowAdapter::InitWMSProxyLocked() { if (!windowManagerServiceProxy_) { @@ -136,8 +174,7 @@ bool WindowAdapter::InitWMSProxyLocked() return false; } if (!remoteObject->AddDeathRecipient(wmsDeath_)) { - WLOGFE("Failed to add death recipient"); - return false; + WLOGFI("Failed to add death recipient"); } } return true; @@ -164,7 +201,7 @@ void WMSDeathRecipient::OnRemoteDied(const wptr& wptrDeath) WLOGFE("object is null"); return; } - SingletonContainer::Get()->ClearWindowAdapter(); + SingletonContainer::Get().ClearWindowAdapter(); return; } } // namespace Rosen diff --git a/wm/src/window_agent.cpp b/wm/src/window_agent.cpp index 79f7a28536838460c6cf5c47cf718df47f170212..ad337d124bd4138efecf77c1542cf854c0c84601 100644 --- a/wm/src/window_agent.cpp +++ b/wm/src/window_agent.cpp @@ -57,5 +57,14 @@ void WindowAgent::UpdateFocusStatus(bool focused) } window_->UpdateFocusStatus(focused); } + +void WindowAgent::UpdateSystemBarProperty(const SystemBarProperty& prop) +{ + if (window_ == nullptr) { + WLOGFE("window_ is nullptr"); + return; + } + window_->UpdateSystemBarProperty(prop); +} } // namespace Rosen } // namespace OHOS diff --git a/wm/src/window_impl.cpp b/wm/src/window_impl.cpp index 6f5d980a75727f90abdebdfa1142db444acee58a..b3cacc1a3f52710db23171a33b660c2957a302fc 100644 --- a/wm/src/window_impl.cpp +++ b/wm/src/window_impl.cpp @@ -18,6 +18,7 @@ #include "singleton_container.h" #include "window_adapter.h" #include "window_agent.h" +#include "window_helper.h" #include "window_manager_hilog.h" #ifndef _NEW_RENDERSERVER_ #include "adapter.h" @@ -30,6 +31,7 @@ namespace { } std::map>> WindowImpl::windowMap_; +std::map>> WindowImpl::subWindowMap_; WindowImpl::WindowImpl(const sptr& option) { @@ -42,7 +44,12 @@ WindowImpl::WindowImpl(const sptr& option) property_->SetTouchable(option->GetTouchable()); property_->SetDisplayId(option->GetDisplayId()); property_->SetWindowFlags(option->GetWindowFlags()); + auto& sysBarPropMap = option->GetSystemBarProperty(); + for (auto it : sysBarPropMap) { + property_->SetSystemBarProperty(it.first, it.second); + } name_ = option->GetWindowName(); + callback_->onCallback = std::bind(&WindowImpl::OnVsync, this, std::placeholders::_1); #ifdef _NEW_RENDERSERVER_ struct RSSurfaceNodeConfig rsSurfaceNodeConfig; @@ -94,13 +101,29 @@ uint32_t WindowImpl::GetWindowId() return property_->GetWindowId(); } +uint32_t WindowImpl::GetWindowFlags() +{ + return property_->GetWindowFlags(); +} + +SystemBarProperty WindowImpl::GetSystemBarPropertyByType(WindowType type) +{ + auto curProperties = property_->GetSystemBarProperty(); + return curProperties[type]; +} + WMError WindowImpl::SetWindowType(WindowType type) { + WLOGFI("window id: %{public}d, type:%{public}d", property_->GetWindowId(), static_cast(type)); if (!IsWindowValid()) { WLOGFI("window is already destroyed or not created! id: %{public}d", property_->GetWindowId()); return WMError::WM_ERROR_INVALID_WINDOW; } if (state_ == STATE_CREATED) { + if (!(WindowHelper::IsAppWindow(type) || WindowHelper::IsSystemWindow(type))) { + WLOGFE("window type is invalid %{public}d", type); + return WMError::WM_ERROR_INVALID_PARAM; + } property_->SetWindowType(type); return WMError::WM_OK; } @@ -126,8 +149,41 @@ WMError WindowImpl::SetWindowMode(WindowMode mode) return WMError::WM_OK; } +WMError WindowImpl::AddWindowFlag(WindowFlag flag) +{ + uint32_t updateFlags = property_->GetWindowFlags() | (static_cast(flag)); + return SetWindowFlags(updateFlags); +} + +WMError WindowImpl::RemoveWindowFlag(WindowFlag flag) +{ + uint32_t updateFlags = property_->GetWindowFlags() & (~(static_cast(flag))); + return SetWindowFlags(updateFlags); +} + +WMError WindowImpl::SetWindowFlags(uint32_t flags) +{ + if (!IsWindowValid()) { + WLOGFI("window is already destroyed or not created! id: %{public}d", property_->GetWindowId()); + return WMError::WM_ERROR_INVALID_WINDOW; + } + if (property_->GetWindowFlags() == flags) { + return WMError::WM_OK; + } + property_->SetWindowFlags(flags); + if (state_ == STATE_CREATED || state_ == STATE_HIDDEN) { + return WMError::WM_OK; + } + WMError ret = SingletonContainer::Get().SetWindowFlags(property_->GetWindowId(), flags); + if (ret != WMError::WM_OK) { + WLOGFE("SetWindowFlags errCode:%{public}d winId:%{public}d", + static_cast(ret), property_->GetWindowId()); + } + return ret; +} + WMError WindowImpl::SetUIContent(std::shared_ptr context, - std::string& url, NativeEngine* engine, NativeValue* storage) + std::string& contentInfo, NativeEngine* engine, NativeValue* storage, bool isdistributed) { WLOGFI("SetUIContent"); uiContent_ = Ace::UIContent::Create(context.get(), engine); @@ -135,12 +191,52 @@ WMError WindowImpl::SetUIContent(std::shared_ptr WLOGFE("fail to SetUIContent id: %{public}d", property_->GetWindowId()); return WMError::WM_ERROR_NULLPTR; } - uiContent_->Initialize(this, url, storage); + // TODO: fix me + // if (isdistributed) { + // uiContent_->Restore(this, contentInfo, storage); + // } else { + // uiContent_->Initialize(this, contentInfo, storage); + // } return WMError::WM_OK; } -WMError WindowImpl::Create(const std::string& parentName, const sptr& abilityToken) +const std::string& WindowImpl::GetContentInfo() +{ + WLOGFI("GetContentInfo"); + if (uiContent_ == nullptr) { + WLOGFE("fail to GetContentInfo id: %{public}d", property_->GetWindowId()); + return ""; + } + // TODO: fix me - uiContent_->GetContentInfo() + return ""; +} + +WMError WindowImpl::SetSystemBarProperty(WindowType type, const SystemBarProperty& property) +{ + if (!IsWindowValid()) { + WLOGFI("window is already destroyed or not created! id: %{public}d", property_->GetWindowId()); + return WMError::WM_ERROR_INVALID_WINDOW; + } + if (GetSystemBarPropertyByType(type) == property) { + return WMError::WM_OK; + } + property_->SetSystemBarProperty(type, property); + if (state_ == STATE_CREATED || state_ == STATE_HIDDEN) { + return WMError::WM_OK; + } + WMError ret = SingletonContainer::Get().SetSystemBarProperty(property_->GetWindowId(), + type, property); + if (ret != WMError::WM_OK) { + WLOGFE("SetSystemBarProperty errCode:%{public}d winId:%{public}d", + static_cast(ret), property_->GetWindowId()); + } + return ret; +} + +WMError WindowImpl::Create(const std::string& parentName, + const std::shared_ptr& abilityContext) { + WLOGFI("[Client] Window Create"); #ifdef _NEW_RENDERSERVER_ // check window name, same window names are forbidden if (windowMap_.find(name_) != windowMap_.end()) { @@ -161,7 +257,7 @@ WMError WindowImpl::Create(const std::string& parentName, const sptr window(this); sptr windowAgent(new WindowAgent(window)); uint32_t windowId = 0; - WMError ret = SingletonContainer::Get()->CreateWindow(windowAgent, property_, surfaceNode_, + WMError ret = SingletonContainer::Get().CreateWindow(windowAgent, property_, surfaceNode_, windowId); property_->SetWindowId(windowId); @@ -169,17 +265,20 @@ WMError WindowImpl::Create(const std::string& parentName, const sptr(ret)); return ret; } - if (abilityToken != nullptr) { - ret = SingletonContainer::Get()->SaveAbilityToken(abilityToken, windowId); + if (abilityContext != nullptr) { + ret = SingletonContainer::Get().SaveAbilityToken(abilityContext->GetAbilityToken(), windowId); + abilityContext_ = abilityContext; if (ret != WMError::WM_OK) { WLOGFE("SaveAbilityToken failed with errCode:%{public}d", static_cast(ret)); return ret; } } windowMap_.insert({ name_, std::pair>(windowId, this) }); + if (parentName != "") { // add to subWindowMap_ + subWindowMap_[property_->GetParentId()].push_back(this); + } state_ = STATE_CREATED; - WLOGFI("create window success with winId:%{public}d", windowId); - InputTransferStation::GetInstance()->AddInputWindow(this); + InputTransferStation::GetInstance().AddInputWindow(this); return ret; #else /* weston adapter */ @@ -191,19 +290,30 @@ WMError WindowImpl::Destroy() { NotifyBeforeDestroy(); #ifdef _NEW_RENDERSERVER_ + WLOGFI("[Client] Window %{public}d Destroy", property_->GetWindowId()); // should destroy surface here if (!IsWindowValid()) { WLOGFI("window is already destroyed or not created! id: %{public}d", property_->GetWindowId()); return WMError::WM_OK; } WLOGFI("destroy window id: %{public}d", property_->GetWindowId()); - WMError ret = SingletonContainer::Get()->DestroyWindow(property_->GetWindowId()); + WMError ret = SingletonContainer::Get().DestroyWindow(property_->GetWindowId()); windowMap_.erase(GetWindowName()); + if (subWindowMap_.count(property_->GetParentId()) > 0) { // remove from subWindowMap_ + std::vector>& subWindows = subWindowMap_.at(property_->GetParentId()); + for (auto iter = subWindows.begin(); iter < subWindows.end(); ++iter) { + if ((*iter)->GetWindowId() == GetWindowId()) { + subWindows.erase(iter); + break; + } + } + } + subWindowMap_.erase(GetWindowId()); state_ = STATE_DESTROYED; - InputTransferStation::GetInstance()->RemoveInputWindow(this); + InputTransferStation::GetInstance().RemoveInputWindow(this); return ret; #else - InputTransferStation::GetInstance()->RemoveInputWindow(this); + InputTransferStation::GetInstance().RemoveInputWindow(this); Adapter::DestroyWestonWindow(); #endif return WMError::WM_OK; @@ -212,6 +322,7 @@ WMError WindowImpl::Destroy() WMError WindowImpl::Show() { #ifdef _NEW_RENDERSERVER_ + WLOGFI("[Client] Window %{public}d Show", property_->GetWindowId()); if (!IsWindowValid()) { WLOGFI("window is already destroyed or not created! id: %{public}d", property_->GetWindowId()); return WMError::WM_ERROR_INVALID_WINDOW; @@ -221,15 +332,13 @@ WMError WindowImpl::Show() return WMError::WM_OK; } SetDefaultOption(); - WMError ret = SingletonContainer::Get()->AddWindow(property_); + WMError ret = SingletonContainer::Get().AddWindow(property_); if (ret == WMError::WM_OK || ret == WMError::WM_ERROR_DEATH_RECIPIENT) { - Rect rect = property_->GetWindowRect(); - WLOGFI("show x: %{public}d ; y: %{public}d; width: %{public}d; height: %{public}d, winId:%{public}d;", - rect.posX_, rect.posY_, rect.width_, rect.height_, property_->GetWindowId()); state_ = STATE_SHOWN; NotifyAfterForeground(); + } else { + WLOGFE("show errCode:%{public}d for winId:%{public}d", static_cast(ret), property_->GetWindowId()); } - WLOGFE("show errCode:%{public}d for winId:%{public}d", static_cast(ret), property_->GetWindowId()); return ret; #else /* weston adapter */ @@ -241,7 +350,7 @@ WMError WindowImpl::Show() } else { WLOGFE("Show error=%d", static_cast(rtn)); } - InputTransferStation::GetInstance()->AddInputWindow(this); + InputTransferStation::GetInstance().AddInputWindow(this); return rtn; #endif } @@ -249,6 +358,7 @@ WMError WindowImpl::Show() WMError WindowImpl::Hide() { #ifdef _NEW_RENDERSERVER_ + WLOGFI("[Client] Window %{public}d Hide", property_->GetWindowId()); if (!IsWindowValid()) { WLOGFI("window is already destroyed or not created! id: %{public}d", property_->GetWindowId()); return WMError::WM_ERROR_INVALID_WINDOW; @@ -257,9 +367,9 @@ WMError WindowImpl::Hide() WLOGFI("window is already hidden id: %{public}d", property_->GetWindowId()); return WMError::WM_OK; } - WMError ret = SingletonContainer::Get()->RemoveWindow(property_->GetWindowId()); - WLOGFI("hide errCode:%{public}d for winId:%{public}d", static_cast(ret), property_->GetWindowId()); + WMError ret = SingletonContainer::Get().RemoveWindow(property_->GetWindowId()); if (ret != WMError::WM_OK) { + WLOGFE("hide errCode:%{public}d for winId:%{public}d", static_cast(ret), property_->GetWindowId()); return ret; } state_ = STATE_HIDDEN; @@ -275,7 +385,7 @@ WMError WindowImpl::Hide() } else { WLOGFE("WindowImpl::Show error=%d", static_cast(rtn)); } - InputTransferStation::GetInstance()->RemoveInputWindow(this); + InputTransferStation::GetInstance().RemoveInputWindow(this); return rtn; #endif } @@ -295,7 +405,7 @@ WMError WindowImpl::MoveTo(int32_t x, int32_t y) property_->GetWindowId(), rect.posX_, rect.posY_, x, y); return WMError::WM_OK; } - return SingletonContainer::Get()->MoveTo(property_->GetWindowId(), x, y); + return SingletonContainer::Get().MoveTo(property_->GetWindowId(), x, y); #else return Adapter::MoveTo(x, y); #endif @@ -316,7 +426,7 @@ WMError WindowImpl::Resize(uint32_t width, uint32_t height) property_->GetWindowId(), rect.posX_, rect.posY_, width, height); return WMError::WM_OK; } - return SingletonContainer::Get()->Resize(property_->GetWindowId(), width, height); + return SingletonContainer::Get().Resize(property_->GetWindowId(), width, height); #else return Adapter::Resize(width, height); #endif @@ -328,12 +438,12 @@ WMError WindowImpl::RequestFocus() const WLOGFI("window is already destroyed or not created! id: %{public}d", property_->GetWindowId()); return WMError::WM_ERROR_INVALID_WINDOW; } - return SingletonContainer::Get()->RequestFocus(property_->GetWindowId()); + return SingletonContainer::Get().RequestFocus(property_->GetWindowId()); } void WindowImpl::AddInputEventListener(std::shared_ptr& inputEventListener) { - InputTransferStation::GetInstance()->SetInputListener(GetWindowId(), inputEventListener); + InputTransferStation::GetInstance().SetInputListener(GetWindowId(), inputEventListener); } void WindowImpl::RegisterLifeCycleListener(sptr& listener) @@ -346,12 +456,24 @@ void WindowImpl::RegisterWindowChangeListener(sptr& liste windowChangeListener_ = listener; } +void WindowImpl::RegisterWindowSystemBarChangeListener(sptr& listener) +{ + systemBarChangeListener_ = listener; +} void WindowImpl::UpdateRect(const struct Rect& rect) { + WLOGFI("winId:%{public}d, rect[%{public}d, %{public}d, %{public}d, %{public}d]", GetWindowId(), rect.posX_, + rect.posY_, rect.width_, rect.height_); property_->SetWindowRect(rect); if (windowChangeListener_ != nullptr) { windowChangeListener_->OnSizeChange(rect); } + if (uiContent_ != nullptr) { + Ace::ViewportConfig config; + config.SetSize(rect.width_, rect.height_); + uiContent_->UpdateViewportConfig(config); + WLOGFI("notify uiContent window size change end"); + } } void WindowImpl::UpdateMode(WindowMode mode) @@ -361,13 +483,53 @@ void WindowImpl::UpdateMode(WindowMode mode) void WindowImpl::ConsumeKeyEvent(std::shared_ptr& keyEvent) { - uiContent_->ProcessKeyEvent(keyEvent); + int32_t keyCode = keyEvent->GetKeyCode(); + int32_t keyAction = keyEvent->GetKeyAction(); + WLOGFI("ConsumeKeyEvent: enter GetKeyCode: %{public}d, action: %{public}d", keyCode, keyAction); + if (keyCode == MMI::KeyEvent::KEYCODE_BACK) { + if (keyAction != MMI::KeyEvent::KEY_ACTION_UP) { + return; + } + if (uiContent_ != nullptr && uiContent_->ProcessBackPressed()) { + WLOGI("ConsumeKeyEvent keyEvent is consumed"); + return; + } + if (abilityContext_ != nullptr) { + WLOGI("ConsumeKeyEvent ability TerminateSelf"); + abilityContext_->TerminateSelf(); + } else { + WLOGI("ConsumeKeyEvent destroy window"); + Destroy(); + } + } else { + if (uiContent_ == nullptr) { + WLOGE("ConsumeKeyEvent uiContent is nullptr"); + return; + } + if (!uiContent_->ProcessKeyEvent(keyEvent)) { + WLOGI("ConsumeKeyEvent no comsumer window exit"); + } + } } void WindowImpl::ConsumePointerEvent(std::shared_ptr& pointerEvent) { + if (uiContent_ == nullptr) { + WLOGE("ConsumePointerEvent uiContent is nullptr"); + return; + } uiContent_->ProcessPointerEvent(pointerEvent); } +void WindowImpl::OnVsync(int64_t timeStamp) +{ + uiContent_->ProcessVsyncEvent(timeStamp); +} + +void WindowImpl::RequestFrame() +{ + VsyncStation::GetInstance().RequestVsync(VsyncStation::CallbackType::CALLBACK_FRAME, callback_); +} + void WindowImpl::UpdateFocusStatus(bool focused) { WLOGFI("window focus status: %{public}d, id: %{public}d", focused, property_->GetWindowId()); @@ -378,9 +540,34 @@ void WindowImpl::UpdateFocusStatus(bool focused) } } +void WindowImpl::UpdateSystemBarProperty(const SystemBarProperty& prop) +{ + WLOGFI("winId:%{public}d, enable:%{public}d, backgroundColor:%{public}x, contentColor:%{public}x", GetWindowId(), + prop.enable_, prop.backgroundColor_, prop.contentColor_); + if (systemBarChangeListener_ != nullptr) { + systemBarChangeListener_->OnSystemBarPropertyChange(property_->GetDisplayId(), + property_->GetWindowType(), prop); + } +} + +void WindowImpl::UpdateConfiguration(const std::shared_ptr& configuration) +{ + if (uiContent_ != nullptr) { + WLOGFD("notify ace winId:%{public}d", GetWindowId()); + // TODO: fix me + // uiContent_->UpdateConfiguration(configuration); + } + if (subWindowMap_.count(GetWindowId()) == 0) { + return; + } + for (auto& subWindow : subWindowMap_.at(GetWindowId())) { + subWindow->UpdateConfiguration(configuration); + } +} + void WindowImpl::SetDefaultOption() { - auto display = DisplayManager::GetInstance()->GetDisplayById(property_->GetDisplayId()); + auto display = DisplayManager::GetInstance().GetDisplayById(property_->GetDisplayId()); if (display == nullptr) { WLOGFE("get display failed displayId:%{public}d, window id:%{public}u", property_->GetDisplayId(), property_->GetWindowId()); @@ -393,21 +580,23 @@ void WindowImpl::SetDefaultOption() Rect rect; switch (property_->GetWindowType()) { case WindowType::WINDOW_TYPE_STATUS_BAR: { - rect = { 0, 0, width, static_cast((static_cast(height) * 0.07)) }; + rect = { 0, 0, width, static_cast((static_cast(height) * STATUS_BAR_RATIO)) }; property_->SetWindowRect(rect); property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING); break; } case WindowType::WINDOW_TYPE_NAVIGATION_BAR: { - uint32_t navHeight = static_cast((static_cast(height) * 0.07)); + uint32_t navHeight = static_cast((static_cast(height) * NAVIGATION_BAR_RATIO)); rect = { 0, static_cast(height - navHeight), width, navHeight }; property_->SetWindowRect(rect); property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING); break; } case WindowType::WINDOW_TYPE_SYSTEM_ALARM_WINDOW: { - uint32_t alarmWidth = static_cast((static_cast(width) * 0.8)); - uint32_t alarmHeight = static_cast((static_cast(height) * 0.3)); + uint32_t alarmWidth = static_cast((static_cast(width) * + SYSTEM_ALARM_WINDOW_WIDTH_RATIO)); + uint32_t alarmHeight = static_cast((static_cast(height) * + SYSTEM_ALARM_WINDOW_HEIGHT_RATIO)); rect = { static_cast((width - alarmWidth) / 2), static_cast((height - alarmHeight) / 2), alarmWidth, alarmHeight }; @@ -415,10 +604,13 @@ void WindowImpl::SetDefaultOption() property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING); break; } + case WindowType::WINDOW_TYPE_DRAGGING_EFFECT: { + property_->SetWindowFlags(0); + break; + } default: break; } - } bool WindowImpl::IsWindowValid() const { diff --git a/wm/src/window_input_channel.cpp b/wm/src/window_input_channel.cpp index 952270f3aae386b0e806e51e282bc49c89c533c9..c436a5c6a2d1f964d18d8ddada32c869628be83e 100644 --- a/wm/src/window_input_channel.cpp +++ b/wm/src/window_input_channel.cpp @@ -56,8 +56,10 @@ void WindowInputChannel::HandlePointerEvent(std::shared_ptr& pointerEventPool_.clear(); } pointerEventPool_.emplace_back(pointerEvent); - VsyncStation::GetInstance()->RequestVsync(VsyncStation::CallbackType::CALLBACK_INPUT, callback_); + WLOGI("HandlePointerEvent RequestVsync"); + VsyncStation::GetInstance().RequestVsync(VsyncStation::CallbackType::CALLBACK_INPUT, callback_); } else { + WLOGI("HandlePointerEvent cosume non-move"); window_->ConsumePointerEvent(pointerEvent); pointerEvent->MarkProcessed(); } @@ -70,7 +72,8 @@ void WindowInputChannel::OnVsync(int64_t timeStamp) return; } auto pointerEvent = pointerEventPool_.back(); - HandlePointerEvent(pointerEvent); + WLOGI("HandlePointerEvent onVsync consume move"); + window_->ConsumePointerEvent(pointerEvent); pointerEvent->MarkProcessed(); pointerEventPool_.clear(); } diff --git a/wm/src/window_manager.cpp b/wm/src/window_manager.cpp new file mode 100644 index 0000000000000000000000000000000000000000..45713eb6b4f5488951f05a1904b7acdad0ca59c4 --- /dev/null +++ b/wm/src/window_manager.cpp @@ -0,0 +1,116 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "foundation/windowmanager/interfaces/innerkits/wm/window_manager.h" +#include + +#include "window_adapter.h" +#include "window_manager_agent.h" +#include "window_manager_hilog.h" + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowManager"}; +} + +class WindowManager::Impl { +public: + void NotifyFocused(uint32_t windowId, const sptr& abilityToken, + WindowType windowType, int32_t displayId) const; + void NotifyUnfocused(uint32_t windowId, const sptr& abilityToken, + WindowType windowType, int32_t displayId) const; + + static inline SingletonDelegator delegator_; + + std::mutex mutex_; + std::vector> focusChangedListeners_; + sptr focusChangedListenerAgent_; +}; + +void WindowManager::Impl::NotifyFocused(uint32_t windowId, const sptr& abilityToken, + WindowType windowType, int32_t displayId) const +{ + WLOGFI("NotifyFocused [%{public}d; %{public}p; %{public}d; %{public}d]", windowId, abilityToken.GetRefPtr(), + static_cast(windowType), displayId); + for (auto& listener : focusChangedListeners_) { + listener->OnFocused(windowId, abilityToken, windowType, displayId); + } +} + +void WindowManager::Impl::NotifyUnfocused(uint32_t windowId, const sptr& abilityToken, + WindowType windowType, int32_t displayId) const +{ + WLOGFI("NotifyUnfocused [%{public}d; %{public}p; %{public}d; %{public}d]", windowId, abilityToken.GetRefPtr(), + static_cast(windowType), displayId); + for (auto& listener : focusChangedListeners_) { + listener->OnUnfocused(windowId, abilityToken, windowType, displayId); + } +} + +WindowManager::WindowManager() : pImpl_(std::make_unique()) +{ +} + +WindowManager::~WindowManager() +{ +} + +void WindowManager::RegisterFocusChangedListener(const sptr& listener) +{ + if (listener == nullptr) { + WLOGFE("listener could not be null"); + return; + } + + std::lock_guard lock(pImpl_->mutex_); + pImpl_->focusChangedListeners_.push_back(listener); + if (pImpl_->focusChangedListenerAgent_ == nullptr) { + pImpl_->focusChangedListenerAgent_ = new WindowManagerAgent(); + SingletonContainer::Get().RegisterFocusChangedListener(pImpl_->focusChangedListenerAgent_); + } +} + +void WindowManager::UnregisterFocusChangedListener(const sptr& listener) +{ + if (listener == nullptr) { + WLOGFE("listener could not be null"); + return; + } + + std::lock_guard lock(pImpl_->mutex_); + auto iter = std::find(pImpl_->focusChangedListeners_.begin(), pImpl_->focusChangedListeners_.end(), listener); + if (iter == pImpl_->focusChangedListeners_.end()) { + WLOGFE("could not find this listener"); + return; + } + pImpl_->focusChangedListeners_.erase(iter); + if (pImpl_->focusChangedListeners_.empty() && pImpl_->focusChangedListenerAgent_ != nullptr) { + SingletonContainer::Get().UnregisterFocusChangedListener(pImpl_->focusChangedListenerAgent_); + } +} + +void WindowManager::UpdateFocusStatus(uint32_t windowId, const sptr& abilityToken, WindowType windowType, + int32_t displayId, bool focused) const +{ + WLOGFI("window focus status: %{public}d, id: %{public}d", focused, windowId); + if (focused) { + pImpl_->NotifyFocused(windowId, abilityToken, windowType, displayId); + } else { + pImpl_->NotifyUnfocused(windowId, abilityToken, windowType, displayId); + } +} +} // namespace Rosen +} // namespace OHOS \ No newline at end of file diff --git a/wmtest/wmserver/src/window_zorder_policy.cpp b/wm/src/window_manager_agent.cpp similarity index 58% rename from wmtest/wmserver/src/window_zorder_policy.cpp rename to wm/src/window_manager_agent.cpp index 1a41d6fb18aaff3f0dc09c8b4acc582df2834f3d..83c1334811602896e86a03c4cf873c4c1e35bc50 100644 --- a/wmtest/wmserver/src/window_zorder_policy.cpp +++ b/wm/src/window_manager_agent.cpp @@ -13,22 +13,16 @@ * limitations under the License. */ -#include "window_manager_hilog.h" -#include "window_zorder_policy.h" +#include "window_manager_agent.h" +#include "foundation/windowmanager/interfaces/innerkits/wm/window_manager.h" +#include "singleton_container.h" namespace OHOS { namespace Rosen { -namespace { - constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowZorderPolicy"}; -} - -int32_t WindowZorderPolicy::GetWindowPriority(WindowType type) const +void WindowManagerAgent::UpdateFocusStatus(uint32_t windowId, const sptr& abilityToken, + WindowType windowType, int32_t displayId, bool focused) { - if (windowPriorityMap_.count(type) == 0) { - WLOGFE("invalid window type"); - return windowPriorityMap_.at(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW); - } - return windowPriorityMap_.at(type); -} + SingletonContainer::Get().UpdateFocusStatus(windowId, abilityToken, windowType, displayId, focused); } -} \ No newline at end of file +} // namespace Rosen +} // namespace OHOS diff --git a/wm/src/window_option.cpp b/wm/src/window_option.cpp index d116dd97893bdb8e80421372db91aa1b1a38144d..1b7e4dc721044457d72948bf47a3b94950943136 100644 --- a/wm/src/window_option.cpp +++ b/wm/src/window_option.cpp @@ -77,6 +77,13 @@ void WindowOption::SetWindowFlags(uint32_t flags) flags_ = flags; } +void WindowOption::SetSystemBarProperty(WindowType type, const SystemBarProperty& property) +{ + if (type == WindowType::WINDOW_TYPE_STATUS_BAR || type == WindowType::WINDOW_TYPE_NAVIGATION_BAR) { + sysBarPropMap_[type] = property; + } +} + Rect WindowOption::GetWindowRect() const { return windowRect_; @@ -121,6 +128,11 @@ uint32_t WindowOption::GetWindowFlags() const { return flags_; } + +const std::unordered_map& WindowOption::GetSystemBarProperty() const +{ + return sysBarPropMap_; +} } } diff --git a/wm/src/window_property.cpp b/wm/src/window_property.cpp index 3ee405db3ebb870d75f5b17093ae8433474b74bb..6b22e7cbc85b8586aa5a214f130cfe04e633bfdc 100644 --- a/wm/src/window_property.cpp +++ b/wm/src/window_property.cpp @@ -72,6 +72,13 @@ void WindowProperty::SetWindowFlags(uint32_t flags) flags_ = flags; } +void WindowProperty::SetSystemBarProperty(WindowType type, const SystemBarProperty& property) +{ + if (type == WindowType::WINDOW_TYPE_STATUS_BAR || type == WindowType::WINDOW_TYPE_NAVIGATION_BAR) { + sysBarPropMap_[type] = property; + } +} + Rect WindowProperty::GetWindowRect() const { return windowRect_; @@ -127,6 +134,11 @@ uint32_t WindowProperty::GetWindowFlags() const return flags_; } +const std::unordered_map& WindowProperty::GetSystemBarProperty() const +{ + return sysBarPropMap_; +} + // TODO void WindowProperty::SetWindowId(uint32_t windowId) { @@ -145,6 +157,37 @@ uint32_t WindowProperty::GetParentId() const return parentId_; } +bool WindowProperty::MapMarshalling(Parcel& parcel) const +{ + auto size = sysBarPropMap_.size(); + if (!parcel.WriteUint32(static_cast(size))) { + return false; + } + for (auto it : sysBarPropMap_) { + // write key(type) + if (!parcel.WriteUint32(static_cast(it.first))) { + return false; + } + // write val(UIState) + if (!(parcel.WriteBool(it.second.enable_) && parcel.WriteUint32(it.second.backgroundColor_) && + parcel.WriteUint32(it.second.contentColor_))) { + return false; + } + } + return true; +} + +void WindowProperty::MapUnmarshalling(Parcel& parcel, sptr& property) +{ + std::unordered_map sysBarPropMap; + uint32_t size = parcel.ReadUint32(); + for (uint32_t i = 0; i < size; i++) { + WindowType type = static_cast(parcel.ReadUint32()); + SystemBarProperty prop = { parcel.ReadBool(), parcel.ReadUint32(), parcel.ReadUint32() }; + property->SetSystemBarProperty(type, prop); + } +} + bool WindowProperty::Marshalling(Parcel& parcel) const { // write windowRect_ @@ -212,6 +255,11 @@ bool WindowProperty::Marshalling(Parcel& parcel) const if (!parcel.WriteUint32(parentId_)) { return false; } + + // write sysUIStateMap_ + if (!MapMarshalling(parcel)) { + return false; + } return true; } @@ -232,6 +280,7 @@ sptr WindowProperty::Unmarshalling(Parcel& parcel) property->SetDisplayId(parcel.ReadInt32()); property->SetWindowId(parcel.ReadUint32()); property->SetParentId(parcel.ReadUint32()); + MapUnmarshalling(parcel, property); return property; } } diff --git a/wm/src/window_proxy.cpp b/wm/src/window_proxy.cpp index 7334d6bb601df3801b650e5950f985b6a985f72c..fe12a88f4ee71c2b28dce2a660d14cc2d6cecd71 100644 --- a/wm/src/window_proxy.cpp +++ b/wm/src/window_proxy.cpp @@ -53,6 +53,26 @@ void WindowProxy::UpdateWindowRect(const struct Rect& rect) return; } +void WindowProxy::UpdateSystemBarProperty(const SystemBarProperty& prop) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("WriteInterfaceToken failed"); + return; + } + if (!(data.WriteBool(prop.enable_) && data.WriteUint32(prop.backgroundColor_) && + data.WriteUint32(prop.contentColor_))) { + WLOGFE("Write property failed"); + return; + } + if (Remote()->SendRequest(TRANS_ID_UPDATE_SYSTEM_BAR_PROPERTY, data, reply, option) != ERR_NONE) { + WLOGFE("SendRequest failed"); + } + return; +} + void WindowProxy::UpdateWindowMode(WindowMode mode) { MessageParcel data; diff --git a/wm/src/window_scene.cpp b/wm/src/window_scene.cpp index 3281d774287eb59dfd8df0b1bd053d8cc46ffc42..5215694fee2aad55ff9d590be6ffd8e9e94c67ca 100644 --- a/wm/src/window_scene.cpp +++ b/wm/src/window_scene.cpp @@ -39,11 +39,13 @@ WindowScene::~WindowScene() } WMError WindowScene::Init(int32_t displayId, std::shared_ptr& abilityContext, - sptr& listener) + sptr& listener, sptr option) { displayId_ = displayId; abilityContext_ = abilityContext; - sptr option = new WindowOption(); + if (option == nullptr) { + option = new WindowOption(); + } option->SetDisplayId(displayId); #ifndef _NEW_RENDERSERVER_ @@ -51,14 +53,8 @@ WMError WindowScene::Init(int32_t displayId, std::shared_ptr()->CreateWindow( - MAIN_WINDOW_ID + std::to_string(count++), option, abilityContext_->GetAbilityToken()); - } else { - mainWindow_ = SingletonContainer::Get()->CreateWindow( - MAIN_WINDOW_ID + std::to_string(count++), option); - } - + mainWindow_ = SingletonContainer::Get().CreateWindow( + MAIN_WINDOW_ID + std::to_string(count++), option, abilityContext_); #endif if (mainWindow_ == nullptr) { return WMError::WM_ERROR_NULLPTR; @@ -76,7 +72,7 @@ sptr WindowScene::CreateWindow(const std::string& windowName, sptrSetParentName(mainWindow_->GetWindowName()); - return SingletonContainer::Get()->CreateWindow(windowName, option); + return SingletonContainer::Get().CreateWindow(windowName, option); #else /* weston adapter */ if (!Adapter::CreateWestonWindow(option)) { @@ -116,6 +112,14 @@ WMError WindowScene::GoBackground() const return mainWindow_->Hide(); } +WMError WindowScene::SetSystemBarProperty(WindowType type, const SystemBarProperty& property) const +{ + if (mainWindow_ == nullptr) { + return WMError::WM_ERROR_NULLPTR; + } + return mainWindow_->SetSystemBarProperty(type, property); +} + WMError WindowScene::RequestFocus() const { if (mainWindow_ == nullptr) { @@ -123,5 +127,20 @@ WMError WindowScene::RequestFocus() const } return mainWindow_->RequestFocus(); } + +void WindowScene::UpdateConfiguration(const std::shared_ptr& configuration) +{ + WLOGFI("notify mainWindow winId:%{public}d", mainWindow_->GetWindowId()); + mainWindow_->UpdateConfiguration(configuration); +} + +const std::string& WindowScene::GetContentInfo() const +{ + if (mainWindow_ == nullptr) { + WLOGFE("WindowScene::GetContentInfo mainWindow_ is null"); + return ""; + } + return mainWindow_->GetContentInfo(); +} } // namespace Rosen } // namespace OHOS diff --git a/wm/src/window_stub.cpp b/wm/src/window_stub.cpp index e7640726e2dd92bf8714057c2947f8806991bc23..c0b6485f5e6f31860c5bc8431497eaacd3b8b033 100644 --- a/wm/src/window_stub.cpp +++ b/wm/src/window_stub.cpp @@ -26,7 +26,6 @@ namespace { int WindowStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - WLOGFI("WindowStub::OnRemoteRequest code is %{public}d", code); if (data.ReadInterfaceToken() != GetDescriptor()) { WLOGFE("InterfaceToken check failed"); return -1; @@ -50,6 +49,11 @@ int WindowStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParce UpdateFocusStatus(focused); break; } + case TRANS_ID_UPDATE_SYSTEM_BAR_PROPERTY: { + SystemBarProperty property = { data.ReadBool(), data.ReadUint32(), data.ReadUint32() }; + UpdateSystemBarProperty(property); + break; + } default: break; } diff --git a/wmtest/wm/src/window_proxy.cpp b/wm/src/zidl/window_manager_agent_proxy.cpp similarity index 48% rename from wmtest/wm/src/window_proxy.cpp rename to wm/src/zidl/window_manager_agent_proxy.cpp index 7334d6bb601df3801b650e5950f985b6a985f72c..eea58411aa8b4f78774ce8d333a1c2319ca64ac2 100644 --- a/wmtest/wm/src/window_proxy.cpp +++ b/wm/src/zidl/window_manager_agent_proxy.cpp @@ -13,75 +13,46 @@ * limitations under the License. */ -#include "window_proxy.h" +#include "zidl/window_manager_agent_proxy.h" #include #include "window_manager_hilog.h" namespace OHOS { namespace Rosen { namespace { - constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowProxy"}; + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowManagerAgentProxy"}; } -void WindowProxy::UpdateWindowProperty(const WindowProperty& windowProperty) -{ - sptr remote = Remote(); - if (remote == nullptr) { - WLOGFW("remote is nullptr"); - return; - } -} - -void WindowProxy::UpdateWindowRect(const struct Rect& rect) +void WindowManagerAgentProxy::UpdateFocusStatus(uint32_t windowId, const sptr& abilityToken, + WindowType windowType, int32_t displayId, bool focused) { MessageParcel data; MessageParcel reply; - MessageOption option; + MessageOption option(MessageOption::TF_ASYNC); 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"); + + if (!data.WriteUint32(windowId)) { + WLOGFE("Write windowId failed"); return; } - if (Remote()->SendRequest(TRANS_ID_UPDATE_WINDOW_RECT, data, reply, option) != ERR_NONE) { - WLOGFE("SendRequest failed"); + if (!data.WriteRemoteObject(abilityToken)) { + WLOGFI("Write abilityToken failed"); } - return; -} -void WindowProxy::UpdateWindowMode(WindowMode mode) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - if (!data.WriteInterfaceToken(GetDescriptor())) { - WLOGFE("WriteInterfaceToken failed"); + if (!data.WriteUint32(static_cast(windowType))) { + WLOGFE("Write windowType 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"); + if (!data.WriteInt32(displayId)) { + WLOGFE("Write displayId failed"); return; } + if (!data.WriteBool(focused)) { WLOGFE("Write Focus failed"); return; @@ -90,7 +61,6 @@ void WindowProxy::UpdateFocusStatus(bool focused) 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_stub.cpp b/wm/src/zidl/window_manager_agent_stub.cpp similarity index 61% rename from wmtest/wm/src/window_stub.cpp rename to wm/src/zidl/window_manager_agent_stub.cpp index e7640726e2dd92bf8714057c2947f8806991bc23..9ac69ed93695f7664c89655ff4ce83b8ed31bb3f 100644 --- a/wmtest/wm/src/window_stub.cpp +++ b/wm/src/zidl/window_manager_agent_stub.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "window_stub.h" +#include "zidl/window_manager_agent_stub.h" #include "ipc_skeleton.h" #include "window_manager_hilog.h" #include "wm_common.h" @@ -21,33 +21,25 @@ namespace OHOS { namespace Rosen { namespace { - constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowStub"}; + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowManagerAgentStub"}; } -int WindowStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) +int WindowManagerAgentStub::OnRemoteRequest(uint32_t code, MessageParcel& data, + MessageParcel& reply, MessageOption& option) { - WLOGFI("WindowStub::OnRemoteRequest code is %{public}d", code); + WLOGFI("WindowManagerAgentStub::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: { + uint32_t windowId = data.ReadUint32(); + sptr abilityToken = data.ReadRemoteObject(); + WindowType windowType = static_cast(data.ReadUint32()); + int32_t displayId = data.ReadInt32(); bool focused = data.ReadBool(); - UpdateFocusStatus(focused); + UpdateFocusStatus(windowId, abilityToken, windowType, displayId, focused); break; } default: diff --git a/wmserver/BUILD.gn b/wmserver/BUILD.gn index 6db371375123cae1b8cc078d6aaefe8f41908413..e38eb6257b9542f73f4ceb51e1e52053be0b8ec0 100644 --- a/wmserver/BUILD.gn +++ b/wmserver/BUILD.gn @@ -27,23 +27,18 @@ config("libwms_config") { "//foundation/windowmanager/dm/include", "//foundation/windowmanager/dmserver/include", ] - - cflags = [ - "-Wall", - "-Werror", - "-g3", - ] } ohos_shared_library("libwms") { sources = [ + "../dmserver/src/abstract_display.cpp", + "../dmserver/src/abstract_display_manager.cpp", "../dmserver/src/display_manager_service.cpp", "../dmserver/src/display_manager_service_inner.cpp", "../dmserver/src/display_manager_stub.cpp", "../dmserver/src/display_node_control.cpp", - "../dmserver/src/display_screen.cpp", - "../dmserver/src/display_screen_manager.cpp", "../dmserver/src/screen.cpp", + "../wm/src/zidl/window_manager_agent_proxy.cpp", "src/input_window_monitor.cpp", "src/window_controller.cpp", "src/window_layout_policy.cpp", @@ -61,25 +56,29 @@ ohos_shared_library("libwms") { "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog", "//foundation/distributedschedule/safwk/interfaces/innerkits/safwk:system_ability_fwk", "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", - "//foundation/windowmanager/wm:libwmutil", "//utils/native/base:utils", + ] - # RSSurface + public_deps = [ + # ability manager + "//foundation/aafwk/standard/interfaces/innerkits/ability_manager:ability_manager", + "//foundation/aafwk/standard/interfaces/innerkits/want:want", + "//foundation/graphic/standard:libsurface", "//foundation/graphic/standard/rosen/modules/render_service_base:librender_service_base", + + # RSSurface "//foundation/graphic/standard/rosen/modules/render_service_client:librender_service_client", # IMS "//foundation/multimodalinput/input/frameworks/proxy:libmmi-client", + "//foundation/windowmanager/wm:libwmutil", ] - public_deps = [ - # ability manager - "//foundation/aafwk/standard/interfaces/innerkits/ability_manager:ability_manager", - "//foundation/aafwk/standard/interfaces/innerkits/want:want", + external_deps = [ + "bytrace_standard:bytrace_core", + "ipc:ipc_core", ] - external_deps = [ "ipc:ipc_core" ] - part_name = "window_manager" subsystem_name = "window" } diff --git a/wmserver/include/input_window_monitor.h b/wmserver/include/input_window_monitor.h index 9ea20b1f80cc14521b73b36f9f5222de803db9fb..15fa9d61c996c5258c8dc49249225173973c6324 100644 --- a/wmserver/include/input_window_monitor.h +++ b/wmserver/include/input_window_monitor.h @@ -34,7 +34,7 @@ private: sptr windowRoot_; std::vector physicalDisplays_; std::vector logicalDisplays_; - std::unordered_set windowTypeSkipped_ { WindowType::WINDOW_TYPE_POINTER}; + std::unordered_set windowTypeSkipped_ { WindowType::WINDOW_TYPE_POINTER }; const int INVALID_DISPLAY_ID = -1; const int INVALID_WINDOW_ID = -1; void TraverseWindowNodes(const std::vector>& windowNodes, diff --git a/wmserver/include/window_controller.h b/wmserver/include/window_controller.h index 043cad3d49d9773c55b9202279e2d919ac75a265..f54f7c0781d63fefef0a5764d258c82c2c630972 100644 --- a/wmserver/include/window_controller.h +++ b/wmserver/include/window_controller.h @@ -17,6 +17,7 @@ #define OHOS_ROSEN_WINDOW_CONTROLLER_H #include +#include "zidl/window_manager_agent_interface.h" #include "window_root.h" namespace OHOS { @@ -35,10 +36,16 @@ public: WMError Resize(uint32_t windowId, uint32_t width, uint32_t height); WMError RequestFocus(uint32_t windowId); WMError SaveAbilityToken(const sptr& abilityToken, uint32_t windowId); + WMError SetWindowMode(uint32_t windowId, WindowMode mode); + WMError SetWindowType(uint32_t windowId, WindowType type); + WMError SetWindowFlags(uint32_t windowId, uint32_t flags); + WMError SetSystemBarProperty(uint32_t windowId, WindowType type, const SystemBarProperty& property); + + void RegisterFocusChangedListener(const sptr& windowManagerAgent); + void UnregisterFocusChangedListener(const sptr& windowManagerAgent); private: uint32_t GenWindowId(); - WMError LayoutWindowNodeTrees(); sptr windowRoot_; std::atomic windowId_ { 0 }; diff --git a/wmserver/include/window_layout_policy.h b/wmserver/include/window_layout_policy.h index 350b8c0e2a0515e50004b60413486a84cf46055d..957881850ff0417ec19d6ebdd2a17507e6c9c9c4 100644 --- a/wmserver/include/window_layout_policy.h +++ b/wmserver/include/window_layout_policy.h @@ -28,25 +28,30 @@ namespace Rosen { class WindowLayoutPolicy : public RefBase { public: WindowLayoutPolicy() = default; + WindowLayoutPolicy(const sptr& belowAppNode, + const sptr& appNode, const sptr& aboveAppNode); ~WindowLayoutPolicy() = default; - WMError UpdateDisplayInfo(const Rect& displayRect); - WMError LayoutWindow(sptr& node); + void UpdateDisplayInfo(const Rect& displayRect); + void AddWindowNode(sptr& node); + void RemoveWindowNode(sptr& node); + void UpdateWindowNode(sptr& node); private: Rect displayRect_ = {0, 0, 0, 0}; + sptr belowAppWindowNode_ = new WindowNode(); + sptr appWindowNode_ = new WindowNode(); + sptr aboveAppWindowNode_ = new WindowNode(); Rect limitRect_ = {0, 0, 0, 0}; - std::map> aviodNodes_; - const std::set aviodTypes_ { + std::map> avoidNodes_; + const std::set avoidTypes_ { WindowType::WINDOW_TYPE_STATUS_BAR, WindowType::WINDOW_TYPE_NAVIGATION_BAR, }; void UpdateLimitRect(const sptr& node); void RecordAvoidRect(const sptr& node); - bool UpdateLayoutRects(sptr& node); - bool IsNeedAvoidNode(const sptr& node); - bool IsFullScreenNode(const sptr& node); - bool IsParentLimitNode(const sptr& node); - bool IsRectChanged(const Rect& l, const Rect& r); + void UpdateLayoutRect(sptr& node); + void LayoutWindowTree(); + void LayoutWindowNode(sptr& node); }; } } diff --git a/wmserver/include/window_manager_interface.h b/wmserver/include/window_manager_interface.h index e1d9d4d49443a9937fc7d525f719bd287aef4549..4285e24067ece61b0945d71df0ded2e8f2a9e661 100644 --- a/wmserver/include/window_manager_interface.h +++ b/wmserver/include/window_manager_interface.h @@ -20,6 +20,7 @@ #include #include "window_property.h" #include "window_interface.h" +#include "zidl/window_manager_agent_interface.h" namespace OHOS { namespace Rosen { @@ -35,7 +36,13 @@ public: TRANS_ID_MOVE, TRANS_ID_RESIZE, TRANS_ID_REQUEST_FOCUS, + TRANS_ID_UPDATE_TYPE, + TRANS_ID_UPDATE_MODE, + TRANS_ID_UPDATE_FLAGS, + TRANS_ID_UPDATE_SYSTEM_BAR_PROPERTY, TRANS_ID_SEND_ABILITY_TOKEN, + TRANS_ID_REGISTER_FOCUS_CHANGED_LISTENER, + TRANS_ID_UNREGISTER_FOCUS_CHANGED_LISTENER, }; virtual WMError CreateWindow(sptr& window, sptr& property, const std::shared_ptr& surfaceNode, uint32_t& windowId) = 0; @@ -45,7 +52,14 @@ public: virtual WMError MoveTo(uint32_t windowId, int32_t x, int32_t y) = 0; virtual WMError Resize(uint32_t windowId, uint32_t width, uint32_t height) = 0; virtual WMError RequestFocus(uint32_t windowId) = 0; + virtual WMError SetWindowMode(uint32_t windowId, WindowMode mode) = 0; + virtual WMError SetWindowType(uint32_t windowId, WindowType type) = 0; + virtual WMError SetWindowFlags(uint32_t windowId, uint32_t flags) = 0; + virtual WMError SetSystemBarProperty(uint32_t windowId, WindowType type, const SystemBarProperty& prop) = 0; virtual WMError SaveAbilityToken(const sptr& abilityToken, uint32_t windowId) = 0; + + virtual void RegisterFocusChangedListener(const sptr& windowManagerAgent) = 0; + virtual void UnregisterFocusChangedListener(const sptr& windowManagerAgent) = 0; }; } } diff --git a/wmserver/include/window_manager_proxy.h b/wmserver/include/window_manager_proxy.h index 60e89fd3cfd206b25681127a72a77c0f2d4864a0..fbca792c22186eeab0134e0baa202a0fb80c61b1 100644 --- a/wmserver/include/window_manager_proxy.h +++ b/wmserver/include/window_manager_proxy.h @@ -36,6 +36,13 @@ public: WMError Resize(uint32_t windowId, uint32_t width, uint32_t height) override; WMError RequestFocus(uint32_t windowId) override; WMError SaveAbilityToken(const sptr& abilityToken, uint32_t windowId) override; + WMError SetWindowMode(uint32_t windowId, WindowMode mode) override; + WMError SetWindowType(uint32_t windowId, WindowType type) override; + WMError SetWindowFlags(uint32_t windowId, uint32_t flags) override; + WMError SetSystemBarProperty(uint32_t windowId, WindowType type, const SystemBarProperty& prop) override; + + void RegisterFocusChangedListener(const sptr& windowManagerAgent) override; + void UnregisterFocusChangedListener(const sptr& windowManagerAgent) override; private: static inline BrokerDelegator delegator_; diff --git a/wmserver/include/window_manager_service.h b/wmserver/include/window_manager_service.h index b722b1646912b283861a259a1854d3aff4d0648f..9d7f1d23f1ea7729e09dc4c2039245d108cd1931 100644 --- a/wmserver/include/window_manager_service.h +++ b/wmserver/include/window_manager_service.h @@ -36,7 +36,6 @@ DECLARE_SYSTEM_ABILITY(WindowManagerService); DECLARE_SINGLE_INSTANCE_BASE(WindowManagerService); public: - ~WindowManagerService() = default; void OnStart() override; void OnStop() override; @@ -49,14 +48,26 @@ public: WMError Resize(uint32_t windowId, uint32_t width, uint32_t height) override; WMError RequestFocus(uint32_t windowId) override; WMError SaveAbilityToken(const sptr& abilityToken, uint32_t windowId) override; -private: + WMError SetWindowMode(uint32_t windowId, WindowMode mode) override; + WMError SetWindowType(uint32_t windowId, WindowType type) override; + WMError SetWindowFlags(uint32_t windowId, uint32_t flags) override; + WMError SetSystemBarProperty(uint32_t windowId, WindowType type, const SystemBarProperty& prop) override; + + void RegisterFocusChangedListener(const sptr& windowManagerAgent) override; + void UnregisterFocusChangedListener(const sptr& windowManagerAgent) override; + +protected: WindowManagerService(); + virtual ~WindowManagerService() = default; + +private: bool Init(); static inline SingletonDelegator delegator; - std::mutex mutex_; + std::recursive_mutex mutex_; sptr windowRoot_; sptr windowController_; sptr inputWindowMonitor_; + const int WAITING_RS_TIME = 10; }; } } diff --git a/wmserver/include/window_node.h b/wmserver/include/window_node.h index 0684ebe71db850c6ea4e5753a8df58c1590c35c4..b1f8fd8ef2758148ad301a11461a18370e8d0b49 100644 --- a/wmserver/include/window_node.h +++ b/wmserver/include/window_node.h @@ -24,13 +24,6 @@ namespace OHOS { namespace Rosen { -struct LayoutRects { - Rect displayRect_ = { 0, 0, 0, 0 }; - Rect parentRect_ = { 0, 0, 0, 0 }; - Rect limitRect_ = { 0, 0, 0, 0 }; - Rect rect_ = { 0, 0, 0, 0 }; -}; - class WindowNode : public RefBase { public: WindowNode(const sptr& property, const sptr& window, @@ -48,19 +41,21 @@ public: ~WindowNode() = default; void SetDisplayId(int32_t displayId); - void UpdateLayoutRects(const LayoutRects& rects); + void SetLayoutRect(const Rect& rect); void SetWindowProperty(const sptr& property); + void SetSystemBarProperty(WindowType type, const SystemBarProperty& property); const sptr& GetWindowToken() const; uint32_t GetWindowId() const; int32_t GetDisplayId() const; - const LayoutRects& GetLayoutRects() const; + const Rect& GetLayoutRect() const; WindowType GetWindowType() const; WindowMode GetWindowMode() const; uint32_t GetWindowFlags() const; const sptr& GetWindowProperty() const; int32_t GetCallingPid() const; int32_t GetCallingUid() const; + const std::unordered_map& GetSystemBarProperty() const; sptr parent_; std::vector> children_; @@ -73,7 +68,7 @@ public: private: sptr property_; sptr windowToken_; - LayoutRects layoutRects_; + Rect layoutRect_ { 0, 0, 0, 0 }; int32_t callingPid_; int32_t callingUid_; }; diff --git a/wmserver/include/window_node_container.h b/wmserver/include/window_node_container.h index 7c8f77e83f68d3add4cc9088bd094f39664b430f..04430981cf25d6a0acc1192053eabdbad8fa45fa 100644 --- a/wmserver/include/window_node_container.h +++ b/wmserver/include/window_node_container.h @@ -24,23 +24,16 @@ namespace OHOS { namespace Rosen { +using UpdateFocusStatusFunc = std::function& abilityToken, + WindowType windowType, int32_t displayId, bool focused)>; + class WindowNodeContainer : public RefBase { public: - WindowNodeContainer(uint64_t screenId, uint32_t width, uint32_t height) : screenId_(screenId) - { - struct RSDisplayNodeConfig config = {screenId}; - displayNode_ = RSDisplayNode::Create(config); - displayRect_ = { - .posX_ = 0, - .posY_ = 0, - .width_ = width, - .height_ = height - }; - } - + WindowNodeContainer(uint64_t screenId, uint32_t width, uint32_t height, UpdateFocusStatusFunc callback); ~WindowNodeContainer(); WMError AddWindowNode(sptr& node, sptr& parentNode); WMError RemoveWindowNode(sptr& node); + WMError UpdateWindowNode(sptr& node); WMError DestroyWindowNode(sptr& node, std::vector& windowIds); const std::vector& Destroy(); void AssignZOrder(); @@ -48,9 +41,10 @@ public: uint32_t GetFocusWindow() const; WMError MinimizeOtherFullScreenAbility(); // adapt to api7 void TraverseContainer(std::vector>& windowNodes); - WMError LayoutWindowNodes(); uint64_t GetScreenId() const; Rect GetDisplayRect() const; + sptr GetTopImmersiveNode() const; + void NotifySystemBarIfChanged(); private: void AssignZOrder(sptr& node); @@ -62,17 +56,27 @@ private: void UpdateWindowTree(sptr& node); bool UpdateRSTree(sptr& node, bool isAdd); sptr zorderPolicy_ = new WindowZorderPolicy(); - sptr layoutPolicy_ = new WindowLayoutPolicy(); sptr belowAppWindowNode_ = new WindowNode(); sptr appWindowNode_ = new WindowNode(); sptr aboveAppWindowNode_ = new WindowNode(); + sptr layoutPolicy_ = + new WindowLayoutPolicy(belowAppWindowNode_, appWindowNode_, aboveAppWindowNode_); std::shared_ptr displayNode_; std::vector removedIds_; + std::unordered_map> sysBarNodeMap_ { + { WindowType::WINDOW_TYPE_STATUS_BAR, nullptr }, + { WindowType::WINDOW_TYPE_NAVIGATION_BAR, nullptr }, + }; + std::unordered_map sysBarPropMap_ { + { WindowType::WINDOW_TYPE_STATUS_BAR, SystemBarProperty() }, + { WindowType::WINDOW_TYPE_NAVIGATION_BAR, SystemBarProperty() }, + }; uint32_t zOrder_ { 0 }; - uint64_t screenId_ = 0; uint32_t focusedWindow_ { 0 }; Rect displayRect_; - WMError LayoutWindowNode(sptr& node); + uint64_t screenId_ = 0; + UpdateFocusStatusFunc focusStatusCallBack_; + void DumpScreenWindowTree(); }; } } diff --git a/wmserver/include/window_root.h b/wmserver/include/window_root.h index 9a86234686cc8e5504f1129d0896986d87b26bda..136537fbf99767234538e8ba3c799b59813ef4e8 100644 --- a/wmserver/include/window_root.h +++ b/wmserver/include/window_root.h @@ -17,6 +17,7 @@ #include #include +#include "zidl/window_manager_agent_interface.h" #include "window_node_container.h" namespace OHOS { @@ -28,12 +29,24 @@ public: virtual void OnRemoteDied(const wptr& wptrDeath) override; +private: + std::function&)> callback_; +}; + +class WindowManagerAgentDeathRecipient : public IRemoteObject::DeathRecipient { +public: + WindowManagerAgentDeathRecipient(std::function&)> callback) : callback_(callback) {} + ~WindowManagerAgentDeathRecipient() = default; + + virtual void OnRemoteDied(const wptr& wptrDeath) override; + +private: std::function&)> callback_; }; class WindowRoot : public RefBase { public: - WindowRoot() = default; + WindowRoot(std::recursive_mutex& mutex) : mutex_(mutex) {} ~WindowRoot() = default; sptr GetOrCreateWindowNodeContainer(int32_t displayId); @@ -44,21 +57,33 @@ public: WMError AddWindowNode(uint32_t parentId, sptr& node); WMError RemoveWindowNode(uint32_t windowId); WMError DestroyWindow(uint32_t windowId); - const std::map>& GetWindowNodeContainerMap() const; + WMError UpdateWindowNode(uint32_t windowId); WMError RequestFocus(uint32_t windowId); WMError MinimizeOtherFullScreenAbility(sptr& node); + void RegisterFocusChangedListener(const sptr& windowManagerAgent); + void UnregisterFocusChangedListener(const sptr& windowManagerAgent); + private: void ClearWindow(const sptr& remoteObject); + void ClearWindowManagerAgent(const sptr& remoteObject); + void UnregisterFocusChangedListener(const sptr& windowManagerAgent); + void UpdateFocusStatus(uint32_t windowId, const sptr& abilityToken, WindowType windowType, + int32_t displayId, bool focused); WMError DestroyWindowInner(sptr& node); + std::recursive_mutex& mutex_; std::map> windowNodeContainerMap_; std::map> windowNodeMap_; std::map, uint32_t> windowIdMap_; + std::vector> focusChangedListenerAgents_; + sptr windowDeath_ = new WindowDeathRecipient(std::bind(&WindowRoot::ClearWindow, this, std::placeholders::_1)); + sptr windowManagerAgentDeath_ = new WindowManagerAgentDeathRecipient( + std::bind(&WindowRoot::ClearWindowManagerAgent, this, std::placeholders::_1)); }; } } diff --git a/wmserver/src/input_window_monitor.cpp b/wmserver/src/input_window_monitor.cpp index 8a71df9d2267f4c61bb92484ce604378c6c10405..6a960cba4afa5a6a38164eb9f17cf5e8c6f4f163 100644 --- a/wmserver/src/input_window_monitor.cpp +++ b/wmserver/src/input_window_monitor.cpp @@ -47,7 +47,6 @@ void InputWindowMonitor::UpdateInputWindow(uint32_t windowId) UpdateDisplaysInfo(container); std::vector> windowNodes; container->TraverseContainer(windowNodes); - auto iter = std::find_if(logicalDisplays_.begin(), logicalDisplays_.end(), [displayId](MMI::LogicalDisplayInfo& logicalDisplay) { return logicalDisplay.id == displayId; @@ -84,7 +83,7 @@ void InputWindowMonitor::UpdateDisplaysInfo(const sptr& con }; auto physicalDisplayIter = std::find_if(physicalDisplays_.begin(), physicalDisplays_.end(), [&physicalDisplayInfo](MMI::PhysicalDisplayInfo& physicalDisplay) { - return physicalDisplay.id = physicalDisplayInfo.id; + return physicalDisplay.id == physicalDisplayInfo.id; }); if (physicalDisplayIter != physicalDisplays_.end()) { *physicalDisplayIter = physicalDisplayInfo; @@ -106,7 +105,7 @@ void InputWindowMonitor::UpdateDisplaysInfo(const sptr& con }; auto logicalDisplayIter = std::find_if(logicalDisplays_.begin(), logicalDisplays_.end(), [&logicalDisplayInfo](MMI::LogicalDisplayInfo& logicalDisplay) { - return logicalDisplay.id = logicalDisplayInfo.id; + return logicalDisplay.id == logicalDisplayInfo.id; }); if (logicalDisplayIter != logicalDisplays_.end()) { *logicalDisplayIter = logicalDisplayInfo; @@ -116,7 +115,7 @@ void InputWindowMonitor::UpdateDisplaysInfo(const sptr& con } void InputWindowMonitor::TraverseWindowNodes(const std::vector> &windowNodes, - std::vector::iterator& iter) + std::vector::iterator& iter) { iter->windowsInfo_.clear(); for (auto& windowNode: windowNodes) { @@ -129,10 +128,10 @@ void InputWindowMonitor::TraverseWindowNodes(const std::vector> .id = static_cast(windowNode->GetWindowId()), .pid = windowNode->GetCallingPid(), .uid = windowNode->GetCallingUid(), - .topLeftX = windowNode->GetLayoutRects().rect_.posX_, - .topLeftY = windowNode->GetLayoutRects().rect_.posY_, - .width = static_cast(windowNode->GetLayoutRects().rect_.width_), - .height = static_cast(windowNode->GetLayoutRects().rect_.height_), + .topLeftX = windowNode->GetLayoutRect().posX_, + .topLeftY = windowNode->GetLayoutRect().posY_, + .width = static_cast(windowNode->GetLayoutRect().width_), + .height = static_cast(windowNode->GetLayoutRect().height_), .displayId = windowNode->GetDisplayId(), .agentWindowId = static_cast(windowNode->GetWindowId()), }; diff --git a/wmserver/src/window_controller.cpp b/wmserver/src/window_controller.cpp index 9f3dbe1ead73a03774e74706da4f41afca68733e..a26a7fd86fe67e935a15cfee9021d5a7624eefa1 100644 --- a/wmserver/src/window_controller.cpp +++ b/wmserver/src/window_controller.cpp @@ -16,6 +16,7 @@ #include "window_controller.h" #include #include "window_manager_hilog.h" +#include "wm_trace.h" namespace OHOS { namespace Rosen { @@ -63,13 +64,12 @@ WMError WindowController::AddWindowNode(sptr& property) if (res != WMError::WM_OK) { return res; } - res = LayoutWindowNodeTrees(); RSTransaction::FlushImplicitTransaction(); - WLOGFI("AddWindowNode FlushImplicitTransaction end"); if (node->GetWindowMode() == WindowMode::WINDOW_MODE_FULLSCREEN) { - WLOGFI("need minimize previous fullscreen window if exists"); + WM_SCOPED_TRACE_BEGIN("controller:MinimizeOtherFullScreenAbility"); WMError res = windowRoot_->MinimizeOtherFullScreenAbility(node); + WM_SCOPED_TRACE_END(); if (res != WMError::WM_OK) { WLOGFE("Minimize other fullscreen window failed"); } @@ -77,32 +77,13 @@ WMError WindowController::AddWindowNode(sptr& property) return res; } -WMError WindowController::LayoutWindowNodeTrees() -{ - auto& windowContainerMap = windowRoot_->GetWindowNodeContainerMap(); - if (windowContainerMap.empty()) { - WLOGFE("could not find window container"); - return WMError::WM_ERROR_INVALID_PARAM; - } - for (auto& iter : windowContainerMap) { - const sptr& windowContainer = iter.second; - WMError ret = windowContainer->LayoutWindowNodes(); - if (ret != WMError::WM_OK) { - return ret; - } - } - return WMError::WM_OK; -} - WMError WindowController::RemoveWindowNode(uint32_t windowId) { WMError res = windowRoot_->RemoveWindowNode(windowId); if (res != WMError::WM_OK) { return res; } - res = LayoutWindowNodeTrees(); RSTransaction::FlushImplicitTransaction(); - WLOGFI("RemoveWindowNode FlushImplicitTransaction end"); return res; } @@ -112,9 +93,7 @@ WMError WindowController::DestroyWindow(uint32_t windowId) if (res != WMError::WM_OK) { return res; } - res = LayoutWindowNodeTrees(); RSTransaction::FlushImplicitTransaction(); - WLOGFI("DestroyWindow FlushImplicitTransaction end"); return res; } @@ -125,10 +104,15 @@ WMError WindowController::MoveTo(uint32_t windowId, int32_t x, int32_t y) WLOGFE("could not find window"); return WMError::WM_ERROR_NULLPTR; } - Vector2f pos(x, y); - node->surfaceNode_->SetBoundsPosition(pos); + auto property = node->GetWindowProperty(); + Rect lastRect = property->GetWindowRect(); + Rect newRect = { x, y, lastRect.width_, lastRect.height_ }; + property->SetWindowRect(newRect); + WMError res = windowRoot_->UpdateWindowNode(windowId); + if (res != WMError::WM_OK) { + return res; + } RSTransaction::FlushImplicitTransaction(); - WLOGFI("MoveTo FlushImplicitTransaction end"); return WMError::WM_OK; } @@ -139,9 +123,15 @@ WMError WindowController::Resize(uint32_t windowId, uint32_t width, uint32_t hei WLOGFE("could not find window"); return WMError::WM_ERROR_NULLPTR; } - node->surfaceNode_->SetBoundsSize(width, height); + auto property = node->GetWindowProperty(); + Rect lastRect = property->GetWindowRect(); + Rect newRect = { lastRect.posX_, lastRect.posY_, width, height }; + property->SetWindowRect(newRect); + WMError res = windowRoot_->UpdateWindowNode(windowId); + if (res != WMError::WM_OK) { + return res; + } RSTransaction::FlushImplicitTransaction(); - WLOGFI("Resize FlushImplicitTransaction end"); return WMError::WM_OK; } @@ -149,5 +139,86 @@ WMError WindowController::RequestFocus(uint32_t windowId) { return windowRoot_->RequestFocus(windowId); } + +WMError WindowController::SetWindowMode(uint32_t windowId, WindowMode mode) +{ + auto node = windowRoot_->GetWindowNode(windowId); + if (node == nullptr) { + WLOGFE("could not find window"); + return WMError::WM_ERROR_NULLPTR; + } + auto property = node->GetWindowProperty(); + property->SetWindowMode(mode); + WMError res = windowRoot_->UpdateWindowNode(windowId); + if (res != WMError::WM_OK) { + return res; + } + RSTransaction::FlushImplicitTransaction(); + WLOGFI("SetWindowMode FlushImplicitTransaction end"); + return res; +} + +WMError WindowController::SetWindowType(uint32_t windowId, WindowType type) +{ + auto node = windowRoot_->GetWindowNode(windowId); + if (node == nullptr) { + WLOGFE("could not find window"); + return WMError::WM_ERROR_NULLPTR; + } + auto property = node->GetWindowProperty(); + property->SetWindowType(type); + WMError res = windowRoot_->UpdateWindowNode(windowId); + if (res != WMError::WM_OK) { + return res; + } + RSTransaction::FlushImplicitTransaction(); + WLOGFI("SetWindowType FlushImplicitTransaction end"); + return res; +} + +WMError WindowController::SetWindowFlags(uint32_t windowId, uint32_t flags) +{ + auto node = windowRoot_->GetWindowNode(windowId); + if (node == nullptr) { + WLOGFE("could not find window"); + return WMError::WM_ERROR_NULLPTR; + } + auto property = node->GetWindowProperty(); + property->SetWindowFlags(flags); + WMError res = windowRoot_->UpdateWindowNode(windowId); + if (res != WMError::WM_OK) { + return res; + } + RSTransaction::FlushImplicitTransaction(); + WLOGFI("SetWindowFlags FlushImplicitTransaction end"); + return res; +} + +WMError WindowController::SetSystemBarProperty(uint32_t windowId, WindowType type, const SystemBarProperty& property) +{ + auto node = windowRoot_->GetWindowNode(windowId); + if (node == nullptr) { + WLOGFE("could not find window"); + return WMError::WM_ERROR_NULLPTR; + } + node->SetSystemBarProperty(type, property); + WMError res = windowRoot_->UpdateWindowNode(windowId); + if (res != WMError::WM_OK) { + return res; + } + RSTransaction::FlushImplicitTransaction(); + WLOGFI("SetSystemBarProperty FlushImplicitTransaction end"); + return res; +} + +void WindowController::RegisterFocusChangedListener(const sptr& windowManagerAgent) +{ + windowRoot_->RegisterFocusChangedListener(windowManagerAgent); +} + +void WindowController::UnregisterFocusChangedListener(const sptr& windowManagerAgent) +{ + windowRoot_->UnregisterFocusChangedListener(windowManagerAgent); +} } } diff --git a/wmserver/src/window_layout_policy.cpp b/wmserver/src/window_layout_policy.cpp index c90a5f030e760c1592fbb39b7276fb0ab9569b62..75b497a652fca92142e81f1cfdccd5def19f3e43 100644 --- a/wmserver/src/window_layout_policy.cpp +++ b/wmserver/src/window_layout_policy.cpp @@ -14,7 +14,9 @@ */ #include "window_layout_policy.h" +#include "window_helper.h" #include "window_manager_hilog.h" +#include "wm_trace.h" namespace OHOS { namespace Rosen { @@ -22,163 +24,167 @@ namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowLayoutPolicy"}; } -WMError WindowLayoutPolicy::UpdateDisplayInfo(const Rect& displayRect) +WindowLayoutPolicy::WindowLayoutPolicy(const sptr& belowAppNode, + const sptr& appNode, const sptr& aboveAppNode) +{ + belowAppWindowNode_ = belowAppNode; + appWindowNode_ = appNode; + aboveAppWindowNode_ = aboveAppNode; +} + +void WindowLayoutPolicy::UpdateDisplayInfo(const Rect& displayRect) { - if (displayRect.height_ == 0 || displayRect.width_ == 0) { - return WMError::WM_ERROR_INVALID_PARAM; - } displayRect_ = displayRect; - limitRect_ = displayRect; - aviodNodes_.clear(); - return WMError::WM_OK; + limitRect_ = displayRect_; + avoidNodes_.clear(); } -WMError WindowLayoutPolicy::LayoutWindow(sptr& node) +void WindowLayoutPolicy::LayoutWindowTree() { - if (node->GetWindowType() >= WindowType::SYSTEM_WINDOW_END) { - WLOGFE("unknown window type!"); - return WMError::WM_ERROR_INVALID_PARAM; + limitRect_ = displayRect_; + avoidNodes_.clear(); + std::vector> rootNodes = { aboveAppWindowNode_, appWindowNode_, belowAppWindowNode_ }; + for (auto& node : rootNodes) { // ensure that the avoid area windows are traversed first + LayoutWindowNode(node); } - UpdateLayoutRects(node); - if (aviodTypes_.find(node->GetWindowType()) != aviodTypes_.end()) { - RecordAvoidRect(node); - } - return WMError::WM_OK; } -bool WindowLayoutPolicy::IsRectChanged(const Rect& l, const Rect& r) +void WindowLayoutPolicy::LayoutWindowNode(sptr& node) { - return !((l.posX_ == r.posX_) && (l.posY_ == r.posY_) && (l.width_ == r.width_) && (l.height_ == r.height_)); + if (node == nullptr) { + return; + } + if (node->parent_ != nullptr) { // isn't root node + UpdateLayoutRect(node); + if (avoidTypes_.find(node->GetWindowType()) != avoidTypes_.end()) { + RecordAvoidRect(node); + } + } + for (auto& childNode : node->children_) { + LayoutWindowNode(childNode); + } } -bool WindowLayoutPolicy::UpdateLayoutRects(sptr& node) +void WindowLayoutPolicy::AddWindowNode(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(); + WM_FUNCTION_TRACE(); + UpdateWindowNode(node); // currently, update and add do the same process +} - if (needAvoid) { - dRect = limitRect_; - } else { - dRect = displayRect_; +void WindowLayoutPolicy::RemoveWindowNode(sptr& node) +{ + WM_FUNCTION_TRACE(); + auto type = node->GetWindowType(); + // affect other windows, trigger off global layout + if (type == WindowType::WINDOW_TYPE_STATUS_BAR || type == WindowType::WINDOW_TYPE_NAVIGATION_BAR) { + LayoutWindowTree(); + } else if (type == WindowType::WINDOW_TYPE_DOCK_SLICE) { // split screen mode + // TODO: change split screen + LayoutWindowTree(); } +} - if (subWindow) { - pRect = node->parent_->GetLayoutRects().rect_; - } else { - pRect = dRect; +void WindowLayoutPolicy::UpdateWindowNode(sptr& node) +{ + WM_FUNCTION_TRACE(); + auto type = node->GetWindowType(); + // affect other windows, trigger off global layout + if (type == WindowType::WINDOW_TYPE_STATUS_BAR || type == WindowType::WINDOW_TYPE_NAVIGATION_BAR) { + LayoutWindowTree(); + } else if (type == WindowType::WINDOW_TYPE_DOCK_SLICE) { // split screen mode + // TODO: change split screen + LayoutWindowTree(); + } else { // layout single window + LayoutWindowNode(node); } +} - if (parentLimit) { - lRect = pRect; - } else { - lRect = dRect; - } +static bool IsLayoutChanged(const Rect& l, const Rect& r) +{ + return !((l.posX_ == r.posX_) && (l.posY_ == r.posY_) && (l.width_ == r.width_) && (l.height_ == r.height_)); +} - 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_); +void WindowLayoutPolicy::UpdateLayoutRect(sptr& node) +{ + auto type = node->GetWindowType(); + auto mode = node->GetWindowMode(); + auto flags = node->GetWindowFlags(); + bool needAvoid = (flags & static_cast(WindowFlag::WINDOW_FLAG_NEED_AVOID)); + bool parentLimit = (flags & static_cast(WindowFlag::WINDOW_FLAG_PARENT_LIMIT)); + bool subWindow = WindowHelper::IsSubWindow(type); + bool floatingWindow = (mode == WindowMode::WINDOW_MODE_FLOATING); + const Rect& layoutRect = node->GetLayoutRect(); + Rect lastRect = layoutRect; + Rect limitRect = displayRect_; + Rect winRect = node->GetWindowProperty()->GetWindowRect(); + WLOGFI("Id:%{public}d, avoid:%{public}d parLimit:%{public}d floating:%{public}d, sub:%{public}d," \ + "type:%{public}d, requestRect:[%{public}d, %{public}d, %{public}d, %{public}d]", + node->GetWindowId(), needAvoid, parentLimit, floatingWindow, subWindow, + static_cast(type), winRect.posX_, winRect.posY_, winRect.width_, winRect.height_); + + if (needAvoid) { + limitRect = limitRect_; } - node->UpdateLayoutRects({ dRect, pRect, lRect, winRect }); - if (IsRectChanged(lastRect, winRect)) { + if (!floatingWindow) { // fullscreen window + winRect = limitRect; + } else { // floating window + if (subWindow && parentLimit) { // subwidow and limited by parent + limitRect = node->parent_->GetLayoutRect(); + winRect.width_ = std::min(limitRect.width_, winRect.width_); + winRect.height_ = std::min(limitRect.height_, winRect.height_); + winRect.posX_ = std::max(limitRect.posX_, winRect.posX_); + winRect.posY_ = std::max(limitRect.posY_, winRect.posY_); + winRect.posX_ = std::min( + limitRect.posX_ + static_cast(limitRect.width_) - static_cast(winRect.width_), + winRect.posX_); + winRect.posY_ = std::min( + limitRect.posY_ + static_cast(limitRect.height_) - static_cast(winRect.height_), + winRect.posY_); + } + } + // Limit window to the maximum window size + winRect.width_ = std::min(displayRect_.width_, winRect.width_); + winRect.height_ = std::min(displayRect_.height_, winRect.height_); + winRect.width_ = std::max(1u, winRect.width_); + winRect.height_ = std::max(1u, winRect.height_); + node->SetLayoutRect(winRect); + if (IsLayoutChanged(lastRect, winRect)) { node->GetWindowToken()->UpdateWindowRect(winRect); node->surfaceNode_->SetBounds(winRect.posX_, winRect.posY_, winRect.width_, winRect.height_); - WLOGFI("UpdateLayoutRects for winId: %{public}d, Rect: %{public}d %{public}d %{public}d %{public}d", - node->GetWindowId(), winRect.posX_, winRect.posY_, winRect.width_, winRect.height_); - return true; } - WLOGFI("UpdateLayoutRects rect not changed for winId: %{public}d", node->GetWindowId()); - return false; } void WindowLayoutPolicy::UpdateLimitRect(const sptr& node) { - auto& layoutRects = node->GetLayoutRects(); + auto& layoutRect = node->GetLayoutRect(); if (node->GetWindowType() == WindowType::WINDOW_TYPE_STATUS_BAR) { // STATUS_BAR int32_t boundTop = limitRect_.posY_; - int32_t rectBottom = layoutRects.rect_.posY_ + layoutRects.rect_.height_; + int32_t rectBottom = layoutRect.posY_ + layoutRect.height_; int32_t offsetH = rectBottom - boundTop; limitRect_.posY_ += offsetH; limitRect_.height_ -= offsetH; } else if (node->GetWindowType() == WindowType::WINDOW_TYPE_NAVIGATION_BAR) { // NAVIGATION_BAR int32_t boundBottom = limitRect_.posY_ + limitRect_.height_; - int32_t offsetH = boundBottom - layoutRects.rect_.posY_; + int32_t offsetH = boundBottom - layoutRect.posY_; limitRect_.height_ -= offsetH; } - WLOGFI("after add WinId: %{public}d, limitRect: %{public}d %{public}d %{public}d %{public}d", - node->GetWindowId(), limitRect_.posX_, limitRect_.posY_, limitRect_.width_, limitRect_.height_); + WLOGFI("Type: %{public}d, limitRect: %{public}d %{public}d %{public}d %{public}d", + node->GetWindowType(), limitRect_.posX_, limitRect_.posY_, limitRect_.width_, limitRect_.height_); } void WindowLayoutPolicy::RecordAvoidRect(const sptr& node) { uint32_t id = node->GetWindowId(); - if (aviodNodes_.find(id) == aviodNodes_.end()) { // new avoid rect - aviodNodes_.insert(std::pair>(id, node)); + if (avoidNodes_.find(id) == avoidNodes_.end()) { // new avoid rect + avoidNodes_.insert(std::pair>(id, node)); UpdateLimitRect(node); } else { // update existing avoid rect limitRect_ = displayRect_; - aviodNodes_[id] = node; - for (auto item : aviodNodes_) { + avoidNodes_[id] = node; + for (auto item : avoidNodes_) { UpdateLimitRect(item.second); } } } - -bool WindowLayoutPolicy::IsNeedAvoidNode(const sptr& node) -{ - auto type = node->GetWindowType(); - auto mode = node->GetWindowMode(); - auto flags = node->GetWindowFlags(); - if (mode == WindowMode::WINDOW_MODE_FLOATING) { - return false; - } - if (type >= WindowType::APP_WINDOW_BASE && - type <= WindowType::APP_SUB_WINDOW_END && - (flags & static_cast(WindowFlag::WINDOW_FLAG_NEED_AVOID))) { - return true; - } - return false; -} - -bool WindowLayoutPolicy::IsFullScreenNode(const sptr& node) -{ - auto mode = node->GetWindowMode(); - if (mode == WindowMode::WINDOW_MODE_FULLSCREEN || mode == WindowMode::WINDOW_MODE_SPLIT) { - return true; - } - return false; -} - -bool WindowLayoutPolicy::IsParentLimitNode(const sptr& node) -{ - auto mode = node->GetWindowMode(); - auto flags = node->GetWindowFlags(); - if (mode != WindowMode::WINDOW_MODE_FLOATING && - (flags & static_cast(WindowFlag::WINDOW_FLAG_PARENT_LIMIT))) { - return true; - } - return false; -} } } diff --git a/wmserver/src/window_manager_proxy.cpp b/wmserver/src/window_manager_proxy.cpp index f1f2da589e9d5dfbfddf5c866bbe454f542d8c45..04270b7b60479de6ede26e500980cfb46219b76a 100644 --- a/wmserver/src/window_manager_proxy.cpp +++ b/wmserver/src/window_manager_proxy.cpp @@ -215,6 +215,111 @@ WMError WindowManagerProxy::RequestFocus(uint32_t windowId) return static_cast(ret); } +WMError WindowManagerProxy::SetWindowMode(uint32_t windowId, WindowMode mode) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("WriteInterfaceToken failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + if (!data.WriteUint32(windowId)) { + WLOGFE("Write windowId failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + if (!data.WriteUint32(static_cast(mode))) { + WLOGFE("Write type failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + if (Remote()->SendRequest(TRANS_ID_UPDATE_MODE, data, reply, option) != ERR_NONE) { + return WMError::WM_ERROR_IPC_FAILED; + } + + int32_t ret = reply.ReadInt32(); + return static_cast(ret); +} + +WMError WindowManagerProxy::SetWindowType(uint32_t windowId, WindowType type) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("WriteInterfaceToken failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + if (!data.WriteUint32(windowId)) { + WLOGFE("Write windowId failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + if (!data.WriteUint32(static_cast(type))) { + WLOGFE("Write type failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + if (Remote()->SendRequest(TRANS_ID_UPDATE_TYPE, data, reply, option) != ERR_NONE) { + return WMError::WM_ERROR_IPC_FAILED; + } + + int32_t ret = reply.ReadInt32(); + return static_cast(ret); +} + +WMError WindowManagerProxy::SetWindowFlags(uint32_t windowId, uint32_t flags) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("WriteInterfaceToken failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + if (!data.WriteUint32(windowId)) { + WLOGFE("Write windowId failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + if (!data.WriteUint32(flags)) { + WLOGFE("Write type failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + if (Remote()->SendRequest(TRANS_ID_UPDATE_FLAGS, data, reply, option) != ERR_NONE) { + return WMError::WM_ERROR_IPC_FAILED; + } + + int32_t ret = reply.ReadInt32(); + return static_cast(ret); +} + +WMError WindowManagerProxy::SetSystemBarProperty(uint32_t windowId, WindowType type, const SystemBarProperty& prop) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("WriteInterfaceToken failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + if (!data.WriteUint32(windowId)) { + WLOGFE("Write windowId failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + if (!data.WriteUint32(static_cast(type))) { + WLOGFE("Write type failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + if (!(data.WriteBool(prop.enable_) && data.WriteUint32(prop.backgroundColor_) && + data.WriteUint32(prop.contentColor_))) { + WLOGFE("Write property failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + if (Remote()->SendRequest(TRANS_ID_UPDATE_SYSTEM_BAR_PROPERTY, data, reply, option) != ERR_NONE) { + return WMError::WM_ERROR_IPC_FAILED; + } + + int32_t ret = reply.ReadInt32(); + return static_cast(ret); +} + WMError WindowManagerProxy::SaveAbilityToken(const sptr& abilityToken, uint32_t windowId) { MessageParcel data; @@ -242,6 +347,45 @@ WMError WindowManagerProxy::SaveAbilityToken(const sptr& abilityT int32_t ret = reply.ReadInt32(); return static_cast(ret); } -} + +void WindowManagerProxy::RegisterFocusChangedListener(const sptr& windowManagerAgent) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("WriteInterfaceToken failed"); + return; + } + + if (!data.WriteRemoteObject(windowManagerAgent->AsObject())) { + WLOGFE("Write IWindowManagerAgent failed"); + return; + } + + if (Remote()->SendRequest(TRANS_ID_REGISTER_FOCUS_CHANGED_LISTENER, data, reply, option) != ERR_NONE) { + WLOGFE("SendRequest failed"); + } } +void WindowManagerProxy::UnregisterFocusChangedListener(const sptr& windowManagerAgent) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("WriteInterfaceToken failed"); + return; + } + + if (!data.WriteRemoteObject(windowManagerAgent->AsObject())) { + WLOGFE("Write IWindowManagerAgent failed"); + return; + } + + if (Remote()->SendRequest(TRANS_ID_UNREGISTER_FOCUS_CHANGED_LISTENER, data, reply, option) != ERR_NONE) { + WLOGFE("SendRequest failed"); + } +} +} +} diff --git a/wmserver/src/window_manager_service.cpp b/wmserver/src/window_manager_service.cpp index 7c70a580ba2556d99dc3417daa42011c34f95781..2f7542f4839f7a6542321a547802b33b55de6185 100644 --- a/wmserver/src/window_manager_service.cpp +++ b/wmserver/src/window_manager_service.cpp @@ -21,6 +21,7 @@ #include #include "window_manager_hilog.h" +#include "wm_trace.h" namespace OHOS { namespace Rosen { @@ -28,14 +29,11 @@ namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowManagerService"}; } -IMPLEMENT_SINGLE_INSTANCE(WindowManagerService); - -const bool REGISTER_RESULT = SystemAbility::MakeAndRegisterAbility( - SingletonContainer::Get().GetRefPtr()); +const bool REGISTER_RESULT = SystemAbility::MakeAndRegisterAbility(&SingletonContainer::Get()); WindowManagerService::WindowManagerService() : SystemAbility(WINDOW_MANAGER_SERVICE_ID, true) { - windowRoot_ = new WindowRoot(); + windowRoot_ = new WindowRoot(mutex_); windowController_ = new WindowController(windowRoot_); inputWindowMonitor_ = new InputWindowMonitor(windowRoot_); } @@ -57,7 +55,7 @@ bool WindowManagerService::Init() return false; } WLOGFI("WindowManagerService::Init success"); - sleep(10); // for RS temporary + sleep(WAITING_RS_TIME); // for RS temporary return true; } @@ -69,17 +67,28 @@ void WindowManagerService::OnStop() WMError WindowManagerService::CreateWindow(sptr& window, sptr& property, const std::shared_ptr& surfaceNode, uint32_t& windowId) { + WM_SCOPED_TRACE("wms:CreateWindow(%d)", windowId); if (window == nullptr || property == nullptr || surfaceNode == nullptr) { WLOGFE("window is invalid"); return WMError::WM_ERROR_NULLPTR; } - std::lock_guard lock(mutex_); + if ((!window) || (!window->AsObject())) { + WLOGFE("failed to get window agent"); + return WMError::WM_ERROR_NULLPTR; + } + std::lock_guard lock(mutex_); return windowController_->CreateWindow(window, property, surfaceNode, windowId); } WMError WindowManagerService::AddWindow(sptr& property) { - std::lock_guard lock(mutex_); + Rect rect = property->GetWindowRect(); + WLOGFI("[WMS] Add: %{public}5d %{public}4d %{public}4d %{public}4d [%{public}4d %{public}4d " \ + "%{public}4d %{public}4d]", property->GetWindowId(), property->GetWindowType(), property->GetWindowMode(), + property->GetWindowFlags(), rect.posX_, rect.posY_, rect.width_, rect.height_); + + WM_SCOPED_TRACE("wms:AddWindow(%d)", property->GetWindowId()); + std::lock_guard lock(mutex_); WMError res = windowController_->AddWindowNode(property); if (res == WMError::WM_OK) { inputWindowMonitor_->UpdateInputWindow(property->GetWindowId()); @@ -89,7 +98,9 @@ WMError WindowManagerService::AddWindow(sptr& property) WMError WindowManagerService::RemoveWindow(uint32_t windowId) { - std::lock_guard lock(mutex_); + WLOGFI("[WMS] Remove: %{public}d", windowId); + WM_SCOPED_TRACE("wms:RemoveWindow(%d)", windowId); + std::lock_guard lock(mutex_); WMError res = windowController_->RemoveWindowNode(windowId); if (res == WMError::WM_OK) { inputWindowMonitor_->UpdateInputWindow(windowId); @@ -99,7 +110,9 @@ WMError WindowManagerService::RemoveWindow(uint32_t windowId) WMError WindowManagerService::DestroyWindow(uint32_t windowId) { - std::lock_guard lock(mutex_); + WLOGFI("[WMS] Destroy: %{public}d", windowId); + WM_SCOPED_TRACE("wms:DestroyWindow(%d)", windowId); + std::lock_guard lock(mutex_); WMError res = windowController_->DestroyWindow(windowId); if (res == WMError::WM_OK) { inputWindowMonitor_->UpdateInputWindow(windowId); @@ -109,26 +122,81 @@ WMError WindowManagerService::DestroyWindow(uint32_t windowId) WMError WindowManagerService::MoveTo(uint32_t windowId, int32_t x, int32_t y) { - std::lock_guard lock(mutex_); + WLOGFI("[WMS] MoveTo: %{public}d [%{public}d, %{public}d]", windowId, x, y); + WM_SCOPED_TRACE("wms:MoveTo"); + std::lock_guard lock(mutex_); return windowController_->MoveTo(windowId, x, y); } WMError WindowManagerService::Resize(uint32_t windowId, uint32_t width, uint32_t height) { - std::lock_guard lock(mutex_); + WLOGFI("[WMS] Resize: %{public}d [%{public}d, %{public}d]", windowId, width, height); + WM_SCOPED_TRACE("wms:Resize"); + std::lock_guard lock(mutex_); return windowController_->Resize(windowId, width, height); } WMError WindowManagerService::RequestFocus(uint32_t windowId) { - std::lock_guard lock(mutex_); + WLOGFI("[WMS] RequestFocus: %{public}d", windowId); + WM_SCOPED_TRACE("wms:RequestFocus"); + std::lock_guard lock(mutex_); return windowController_->RequestFocus(windowId); } +WMError WindowManagerService::SetWindowMode(uint32_t windowId, WindowMode mode) +{ + WM_SCOPED_TRACE("wms:SetWindowMode"); + std::lock_guard lock(mutex_); + return windowController_->SetWindowMode(windowId, mode); +} + +WMError WindowManagerService::SetWindowType(uint32_t windowId, WindowType type) +{ + WM_SCOPED_TRACE("wms:SetWindowType"); + std::lock_guard lock(mutex_); + return windowController_->SetWindowType(windowId, type); +} + +WMError WindowManagerService::SetWindowFlags(uint32_t windowId, uint32_t flags) +{ + WM_SCOPED_TRACE("wms:SetWindowFlags"); + std::lock_guard lock(mutex_); + return windowController_->SetWindowFlags(windowId, flags); +} + +WMError WindowManagerService::SetSystemBarProperty(uint32_t windowId, WindowType type, const SystemBarProperty& prop) +{ + WM_SCOPED_TRACE("wms:SetSystemBarProperty"); + std::lock_guard lock(mutex_); + return windowController_->SetSystemBarProperty(windowId, type, prop); +} + WMError WindowManagerService::SaveAbilityToken(const sptr& abilityToken, uint32_t windowId) { - std::lock_guard lock(mutex_); + WLOGFI("[WMS] SaveAbilityToken: %{public}d", windowId); + std::lock_guard lock(mutex_); return windowController_->SaveAbilityToken(abilityToken, windowId); } + +void WindowManagerService::RegisterFocusChangedListener(const sptr& windowManagerAgent) +{ + if ((windowManagerAgent == nullptr) || (windowManagerAgent->AsObject() == nullptr)) { + WLOGFE("failed to get window manager agent"); + return; + } + std::lock_guard lock(mutex_); + windowController_->RegisterFocusChangedListener(windowManagerAgent); +} + +void WindowManagerService::UnregisterFocusChangedListener(const sptr& windowManagerAgent) +{ + if ((windowManagerAgent == nullptr) || (windowManagerAgent->AsObject() == nullptr)) { + WLOGFE("windowManagerAgent is null"); + return; + } + std::lock_guard lock(mutex_); + windowController_->UnregisterFocusChangedListener(windowManagerAgent); +} } } \ No newline at end of file diff --git a/wmserver/src/window_manager_stub.cpp b/wmserver/src/window_manager_stub.cpp index cd18fed9f453d28c2d7cf2daab8ce8e8780da4d1..795f04696127645e99828a5f63d7999790198165 100644 --- a/wmserver/src/window_manager_stub.cpp +++ b/wmserver/src/window_manager_stub.cpp @@ -26,7 +26,6 @@ namespace { int32_t WindowManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - WLOGFI("WindowManagerStub::OnRemoteRequest code is %{public}d", code); if (data.ReadInterfaceToken() != GetDescriptor()) { WLOGFE("InterfaceToken check failed"); return -1; @@ -83,7 +82,35 @@ int32_t WindowManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, M reply.WriteInt32(static_cast(errCode)); break; } - + case TRANS_ID_UPDATE_MODE: { + uint32_t windowId = data.ReadUint32(); + WindowMode mode = static_cast(data.ReadUint32()); + WMError errCode = SetWindowMode(windowId, mode); + reply.WriteInt32(static_cast(errCode)); + break; + } + case TRANS_ID_UPDATE_TYPE: { + uint32_t windowId = data.ReadUint32(); + WindowType type = static_cast(data.ReadUint32()); + WMError errCode = SetWindowType(windowId, type); + reply.WriteInt32(static_cast(errCode)); + break; + } + case TRANS_ID_UPDATE_FLAGS: { + uint32_t windowId = data.ReadUint32(); + uint32_t flags = data.ReadUint32(); + WMError errCode = SetWindowFlags(windowId, flags); + reply.WriteInt32(static_cast(errCode)); + break; + } + case TRANS_ID_UPDATE_SYSTEM_BAR_PROPERTY: { + uint32_t windowId = data.ReadUint32(); + WindowType type = static_cast(data.ReadUint32()); + SystemBarProperty property = { data.ReadBool(), data.ReadUint32(), data.ReadUint32() }; + WMError errCode = SetSystemBarProperty(windowId, type, property); + reply.WriteInt32(static_cast(errCode)); + break; + } case TRANS_ID_SEND_ABILITY_TOKEN: { sptr abilityToken = data.ReadRemoteObject(); uint32_t windowId = data.ReadUint32(); @@ -91,6 +118,20 @@ int32_t WindowManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, M reply.WriteInt32(static_cast(errCode)); break; } + case TRANS_ID_REGISTER_FOCUS_CHANGED_LISTENER: { + sptr windowManagerAgentObject = data.ReadRemoteObject(); + sptr windowManagerAgentProxy = + iface_cast(windowManagerAgentObject); + RegisterFocusChangedListener(windowManagerAgentProxy); + break; + } + case TRANS_ID_UNREGISTER_FOCUS_CHANGED_LISTENER: { + sptr windowManagerAgentObject = data.ReadRemoteObject(); + sptr windowManagerAgentProxy = + iface_cast(windowManagerAgentObject); + UnregisterFocusChangedListener(windowManagerAgentProxy); + break; + } default: WLOGFW("unknown transaction code"); return IPCObjectStub::OnRemoteRequest(code, data, reply, option); diff --git a/wmserver/src/window_node.cpp b/wmserver/src/window_node.cpp index 389d4f367782c55b13a7622c7f03a38459e66649..c81bcd8e1ff7bf34ffdcd17dc1f4b7cc5465296f 100644 --- a/wmserver/src/window_node.cpp +++ b/wmserver/src/window_node.cpp @@ -23,9 +23,9 @@ void WindowNode::SetDisplayId(int32_t displayId) property_->SetDisplayId(displayId); } -void WindowNode::UpdateLayoutRects(const LayoutRects& rects) +void WindowNode::SetLayoutRect(const Rect& rect) { - layoutRects_ = rects; + layoutRect_ = rect; } void WindowNode::SetWindowProperty(const sptr& property) @@ -33,6 +33,11 @@ void WindowNode::SetWindowProperty(const sptr& property) property_ = property; } +void WindowNode::SetSystemBarProperty(WindowType type, const SystemBarProperty& property) +{ + property_->SetSystemBarProperty(type, property); +} + const sptr& WindowNode::GetWindowToken() const { return windowToken_; @@ -48,9 +53,9 @@ uint32_t WindowNode::GetWindowId() const return property_->GetWindowId(); } -const LayoutRects& WindowNode::GetLayoutRects() const +const Rect& WindowNode::GetLayoutRect() const { - return layoutRects_; + return layoutRect_; } WindowType WindowNode::GetWindowType() const @@ -82,5 +87,10 @@ int32_t WindowNode::GetCallingUid() const { return callingUid_; } + +const std::unordered_map& WindowNode::GetSystemBarProperty() const +{ + return property_->GetSystemBarProperty(); +} } } diff --git a/wmserver/src/window_node_container.cpp b/wmserver/src/window_node_container.cpp index 564cb4a5a766f5c1de106bf95b5f92919ce9d5f9..38dc36447ef356b971a101b09dae80f0f90dc7bc 100644 --- a/wmserver/src/window_node_container.cpp +++ b/wmserver/src/window_node_container.cpp @@ -16,7 +16,9 @@ #include "window_node_container.h" #include #include +#include "window_helper.h" #include "window_manager_hilog.h" +#include "wm_trace.h" namespace OHOS { namespace Rosen { @@ -24,6 +26,20 @@ namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowNodeContainer"}; } +WindowNodeContainer::WindowNodeContainer(uint64_t screenId, uint32_t width, uint32_t height, + UpdateFocusStatusFunc callback) : screenId_(screenId), focusStatusCallBack_(callback) +{ + struct RSDisplayNodeConfig config = {screenId}; + displayNode_ = RSDisplayNode::Create(config); + displayRect_ = { + .posX_ = 0, + .posY_ = 0, + .width_ = width, + .height_ = height + }; + layoutPolicy_->UpdateDisplayInfo(displayRect_); +} + WindowNodeContainer::~WindowNodeContainer() { Destroy(); @@ -32,16 +48,14 @@ WindowNodeContainer::~WindowNodeContainer() WMError WindowNodeContainer::MinimizeOtherFullScreenAbility() { if (appWindowNode_->children_.empty()) { - WLOGFI("no appWindowNode, return"); return WMError::WM_OK; } for (auto iter = appWindowNode_->children_.begin(); iter < appWindowNode_->children_.end() - 1; ++iter) { if ((*iter)->GetWindowMode() != WindowMode::WINDOW_MODE_FULLSCREEN) { continue; } - WLOGFI("find previous fullscreen window"); if ((*iter)->abilityToken_ != nullptr) { - WLOGFI("notify ability to minimize"); + WLOGFI("Find previous fullscreen window, notify ability to minimize"); AAFwk::AbilityManagerClient::GetInstance()->MinimizeAbility((*iter)->abilityToken_); } } @@ -72,19 +86,38 @@ WMError WindowNodeContainer::AddWindowNode(sptr& node, sptrchildren_) { child->currentVisibility_ = child->requestedVisibility_; } + if (node->GetWindowType() == WindowType::WINDOW_TYPE_STATUS_BAR || + node->GetWindowType() == WindowType::WINDOW_TYPE_NAVIGATION_BAR) { + sysBarNodeMap_[node->GetWindowType()] = node; + } } node->parent_ = parentNode; UpdateWindowTree(node); UpdateRSTree(node, true); AssignZOrder(); + layoutPolicy_->AddWindowNode(node); UpdateFocusWindow(); + NotifySystemBarIfChanged(); WLOGFI("AddWindowNode windowId: %{public}d end", node->GetWindowId()); return WMError::WM_OK; } +WMError WindowNodeContainer::UpdateWindowNode(sptr& node) +{ + if (!node->surfaceNode_ || !displayNode_) { + WLOGFE("surface node or display node is nullptr!"); + return WMError::WM_ERROR_NULLPTR; + } + layoutPolicy_->UpdateWindowNode(node); + NotifySystemBarIfChanged(); + WLOGFI("UpdateWindowNode windowId: %{public}d end", node->GetWindowId()); + return WMError::WM_OK; +} + void WindowNodeContainer::UpdateWindowTree(sptr& node) { + WM_FUNCTION_TRACE(); node->priority_ = zorderPolicy_->GetWindowPriority(node->GetWindowType()); auto parentNode = node->parent_; auto position = parentNode->children_.end(); @@ -99,6 +132,7 @@ void WindowNodeContainer::UpdateWindowTree(sptr& node) bool WindowNodeContainer::UpdateRSTree(sptr& node, bool isAdd) { + WM_FUNCTION_TRACE(); if (displayNode_ == nullptr) { WLOGFE("displayNode_ is nullptr"); return false; @@ -123,6 +157,7 @@ WMError WindowNodeContainer::DestroyWindowNode(sptr& node, std::vect { WMError ret = RemoveWindowNode(node); if (ret != WMError::WM_OK) { + WLOGFE("RemoveWindowNode failed"); return ret; } node->surfaceNode_ = nullptr; @@ -137,42 +172,9 @@ WMError WindowNodeContainer::DestroyWindowNode(sptr& node, std::vect } } node->children_.clear(); - WLOGFI("DestroyWindowNode windowId: %{public}d end", node->GetWindowId()); return WMError::WM_OK; } -WMError WindowNodeContainer::LayoutWindowNodes() -{ - WMError ret = WMError::WM_OK; - layoutPolicy_->UpdateDisplayInfo(displayRect_); - std::vector> rootNodes = { aboveAppWindowNode_, appWindowNode_, belowAppWindowNode_ }; - for (auto& node : rootNodes) { // ensure that the avoid area windows are traversed first - ret = LayoutWindowNode(node); - if (ret != WMError::WM_OK) { - return ret; - } - } - return ret; -} - -WMError WindowNodeContainer::LayoutWindowNode(sptr& node) -{ - WMError ret = WMError::WM_OK; - if (node->parent_ != nullptr) { // isn't root node - ret = layoutPolicy_->LayoutWindow(node); - if (ret != WMError::WM_OK) { - return ret; - } - } - for (auto& childNode : node->children_) { - ret = LayoutWindowNode(childNode); - if (ret != WMError::WM_OK) { - return ret; - } - } - return ret; -} - WMError WindowNodeContainer::RemoveWindowNode(sptr& node) { if (node == nullptr || !node->surfaceNode_) { @@ -199,6 +201,8 @@ WMError WindowNodeContainer::RemoveWindowNode(sptr& node) } UpdateRSTree(node, false); UpdateFocusWindow(); + layoutPolicy_->RemoveWindowNode(node); + NotifySystemBarIfChanged(); WLOGFI("RemoveWindowNode windowId: %{public}d end", node->GetWindowId()); return WMError::WM_OK; } @@ -221,13 +225,16 @@ const std::vector& WindowNodeContainer::Destroy() sptr WindowNodeContainer::FindRoot(WindowType type) const { - if (type >= WindowType::APP_WINDOW_BASE && type <= WindowType::APP_SUB_WINDOW_END) { + if (WindowHelper::IsAppWindow(type)) { return appWindowNode_; - } else if (type < WindowType::ABOVE_APP_SYSTEM_WINDOW_BASE) { + } + if (WindowHelper::IsBelowSystemWindow(type)) { return belowAppWindowNode_; - } else { + } + if (WindowHelper::IsAboveSystemWindow(type)) { return aboveAppWindowNode_; } + return nullptr; } void WindowNodeContainer::UpdateFocusWindow() @@ -263,9 +270,14 @@ void WindowNodeContainer::UpdateFocusStatus(uint32_t id, bool focused) const { auto node = FindWindowNodeById(id); if (node == nullptr) { - WLOGFW("cannot find old focused window id:%{public}d", id); + WLOGFW("cannot find focused window id:%{public}d", id); } else { node->GetWindowToken()->UpdateFocusStatus(focused); + if (node->abilityToken_ == nullptr) { + WLOGFI("abilityToken is null, window : %{public}d", id); + } + focusStatusCallBack_(node->GetWindowId(), node->abilityToken_, node->GetWindowType(), + node->GetDisplayId(), focused); } } @@ -293,7 +305,6 @@ void WindowNodeContainer::AssignZOrder(sptr& node) if ((*iter)->priority_ < 0) { if ((*iter)->surfaceNode_) { (*iter)->surfaceNode_->SetPositionZ(zOrder_); - WLOGFI("for subWindow id %{public}d; zOrder:%{public}d", (*iter)->GetWindowId(), zOrder_); ++zOrder_; } } else { @@ -302,13 +313,11 @@ void WindowNodeContainer::AssignZOrder(sptr& node) } if (node->surfaceNode_) { node->surfaceNode_->SetPositionZ(zOrder_); - WLOGFI("window id:%{public}d; zOrder:%{public}d", node->GetWindowId(), zOrder_); ++zOrder_; } for (; iter < node->children_.end(); ++iter) { if ((*iter)->surfaceNode_) { (*iter)->surfaceNode_->SetPositionZ(zOrder_); - WLOGFI("for subWindow id %{public}d; zOrder:%{public}d", (*iter)->GetWindowId(), zOrder_); ++zOrder_; } } @@ -317,6 +326,7 @@ void WindowNodeContainer::AssignZOrder(sptr& node) WMError WindowNodeContainer::SetFocusWindow(uint32_t windowId) { if (focusedWindow_ == windowId) { + WLOGFI("focused window do not change"); return WMError::WM_OK; } UpdateFocusStatus(focusedWindow_, false); @@ -330,6 +340,59 @@ uint32_t WindowNodeContainer::GetFocusWindow() const return focusedWindow_; } +sptr WindowNodeContainer::GetTopImmersiveNode() const +{ + if (appWindowNode_->children_.empty()) { + return nullptr; + } + auto iter = appWindowNode_->children_.rbegin(); + for (; iter < appWindowNode_->children_.rend(); ++iter) { + auto mode = (*iter)->GetWindowMode(); + auto flags = (*iter)->GetWindowFlags(); + if (mode == WindowMode::WINDOW_MODE_FULLSCREEN && + !(flags & static_cast(WindowFlag::WINDOW_FLAG_NEED_AVOID))) { + return (*iter); + } + } + return nullptr; +} + +void WindowNodeContainer::NotifySystemBarIfChanged() +{ + DumpScreenWindowTree(); + auto node = GetTopImmersiveNode(); + if (node == nullptr) { // use default system bar + for (auto it : sysBarPropMap_) { + if (it.second == SystemBarProperty()) { + continue; + } + sysBarPropMap_[it.first] = SystemBarProperty(); + if (sysBarNodeMap_[it.first] != nullptr) { + sysBarNodeMap_[it.first]->GetWindowToken()->UpdateSystemBarProperty(SystemBarProperty()); + } + } + } else { // use node-defined system bar + auto& sysBarPropMap = node->GetSystemBarProperty(); + for (auto it : sysBarPropMap_) { + if (sysBarPropMap.find(it.first) == sysBarPropMap.end()) { + return; + } + auto& prop = sysBarPropMap.find(it.first)->second; + if (it.second == prop) { + continue; + } + WLOGFI("Set systemBar prop winId: %{public}d, type: %{public}d" \ + "visible: %{public}d, Color: %{public}x | %{public}x", + node->GetWindowId(), static_cast(it.first), + prop.enable_, prop.backgroundColor_, prop.contentColor_); + sysBarPropMap_[it.first] = prop; + if (sysBarNodeMap_[it.first] != nullptr) { + sysBarNodeMap_[it.first]->GetWindowToken()->UpdateSystemBarProperty(prop); + } + } + } +} + void WindowNodeContainer::TraverseContainer(std::vector>& windowNodes) { for (auto& node : belowAppWindowNode_->children_) { @@ -363,6 +426,22 @@ void WindowNodeContainer::TraverseWindowNode(sptr& node, std::vector } } +void WindowNodeContainer::DumpScreenWindowTree() +{ + WLOGFI("-------- Screen %{public}llu dump window info begin---------", screenId_); + WLOGFI("WinId Type Mode Flag ZOrd [ x y w h]"); + std::vector> windowNodes; + TraverseContainer(windowNodes); + int zOrder = windowNodes.size(); + for (auto node : windowNodes) { + Rect rect = node->GetLayoutRect(); + WLOGFI("%{public}5d %{public}4d %{public}4d %{public}4d %{public}4d [%{public}4d %{public}4d " \ + "%{public}4d %{public}4d]", node->GetWindowId(), node->GetWindowType(), node->GetWindowMode(), + node->GetWindowFlags(), --zOrder, rect.posX_, rect.posY_, rect.width_, rect.height_); + } + WLOGFI("-------- Screen %{public}llu dump window info end ---------", screenId_); +} + uint64_t WindowNodeContainer::GetScreenId() const { return screenId_; diff --git a/wmserver/src/window_root.cpp b/wmserver/src/window_root.cpp index ac626427923ab10c2b54dcf0e55686fcff4ca5d5..4b20ff0cb81662c3940db4b093a27c366224a68e 100644 --- a/wmserver/src/window_root.cpp +++ b/wmserver/src/window_root.cpp @@ -28,24 +28,23 @@ sptr WindowRoot::GetOrCreateWindowNodeContainer(int32_t dis if (iter != windowNodeContainerMap_.end()) { return iter->second; } - auto displayScreen = DisplayManagerServiceInner::GetInstance()->GetDisplayById(displayId); - if (displayScreen == nullptr) { + auto abstractDisplay = DisplayManagerServiceInner::GetInstance().GetDisplayById(displayId); + if (abstractDisplay == nullptr) { WLOGFE("get display failed displayId:%{public}d", displayId); return nullptr; } WLOGFI("create new window node container display width:%{public}d, height:%{public}d, screenId:%{public}llu", - displayScreen->GetWidth(), displayScreen->GetHeight(), displayScreen->GetId()); - sptr container = new WindowNodeContainer(displayScreen->GetId(), - static_cast(displayScreen->GetWidth()), static_cast(displayScreen->GetHeight())); + abstractDisplay->GetWidth(), abstractDisplay->GetHeight(), abstractDisplay->GetId()); + + UpdateFocusStatusFunc focusStatusFunc = std::bind(&WindowRoot::UpdateFocusStatus, this, std::placeholders::_1, + std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5); + sptr container = new WindowNodeContainer(abstractDisplay->GetId(), + static_cast(abstractDisplay->GetWidth()), static_cast(abstractDisplay->GetHeight()), + focusStatusFunc); windowNodeContainerMap_.insert({ displayId, container }); return container; } -const std::map>& WindowRoot::GetWindowNodeContainerMap() const -{ - return windowNodeContainerMap_; -} - void WindowRoot::NotifyDisplayRemoved(int32_t displayId) { auto container = GetOrCreateWindowNodeContainer(displayId); @@ -65,7 +64,6 @@ sptr WindowRoot::GetWindowNode(uint32_t windowId) const { auto iter = windowNodeMap_.find(windowId); if (iter == windowNodeMap_.end()) { - WLOGFE("window node could not be found"); return nullptr; } return iter->second; @@ -84,6 +82,7 @@ WMError WindowRoot::SaveWindow(const sptr& node) if (windowDeath_ == nullptr) { WLOGFI("failed to create death Recipient ptr WindowDeathRecipient"); + return WMError::WM_OK; } if (!remoteObject->AddDeathRecipient(windowDeath_)) { WLOGFI("failed to add death recipient"); @@ -133,6 +132,21 @@ WMError WindowRoot::RemoveWindowNode(uint32_t windowId) return container->RemoveWindowNode(node); } +WMError WindowRoot::UpdateWindowNode(uint32_t windowId) +{ + auto node = GetWindowNode(windowId); + if (node == nullptr) { + WLOGFE("could not find window"); + return WMError::WM_ERROR_NULLPTR; + } + auto container = GetOrCreateWindowNodeContainer(node->GetDisplayId()); + if (container == nullptr) { + WLOGFE("add window failed, window container could not be found"); + return WMError::WM_ERROR_NULLPTR; + } + return container->UpdateWindowNode(node); +} + WMError WindowRoot::DestroyWindow(uint32_t windowId) { auto node = GetWindowNode(windowId); @@ -161,16 +175,20 @@ WMError WindowRoot::DestroyWindowInner(sptr& node) WLOGFE("window has been destroyed"); return WMError::WM_ERROR_DESTROYED_OBJECT; } + sptr window = node->GetWindowToken(); - if (windowIdMap_.count(window->AsObject()) == 0) { - WLOGFI("window remote object has been destroyed"); - return WMError::WM_ERROR_DESTROYED_OBJECT; - } + if ((window != nullptr) && (window->AsObject() != nullptr)) { + if (windowIdMap_.count(window->AsObject()) == 0) { + WLOGFI("window remote object has been destroyed"); + return WMError::WM_ERROR_DESTROYED_OBJECT; + } - if (window->AsObject() != nullptr) { - window->AsObject()->RemoveDeathRecipient(windowDeath_); + if (window->AsObject() != nullptr) { + window->AsObject()->RemoveDeathRecipient(windowDeath_); + } + windowIdMap_.erase(window->AsObject()); } - windowIdMap_.erase(window->AsObject()); + windowNodeMap_.erase(node->GetWindowId()); return WMError::WM_OK; } @@ -182,6 +200,10 @@ WMError WindowRoot::RequestFocus(uint32_t windowId) WLOGFE("could not find window"); return WMError::WM_ERROR_NULLPTR; } + if (!node->currentVisibility_) { + WLOGFE("could not request focus before it has shown"); + return WMError::WM_ERROR_INVALID_OPERATION; + } auto container = GetOrCreateWindowNodeContainer(node->GetDisplayId()); if (container == nullptr) { WLOGFE("window container could not be found"); @@ -190,8 +212,48 @@ WMError WindowRoot::RequestFocus(uint32_t windowId) return container->SetFocusWindow(windowId); } +void WindowRoot::RegisterFocusChangedListener(const sptr& windowManagerAgent) +{ + focusChangedListenerAgents_.push_back(windowManagerAgent); + if (windowManagerAgentDeath_ == nullptr) { + WLOGFI("failed to create death Recipient ptr WindowManagerAgentDeathRecipient"); + return; + } + if (!windowManagerAgent->AsObject()->AddDeathRecipient(windowManagerAgentDeath_)) { + WLOGFI("failed to add death recipient"); + } +} + +void WindowRoot::UnregisterFocusChangedListener(const sptr& windowManagerAgent) +{ + auto iter = std::find(focusChangedListenerAgents_.begin(), focusChangedListenerAgents_.end(), windowManagerAgent); + if (iter == focusChangedListenerAgents_.end()) { + WLOGFE("could not find this listener"); + return; + } + focusChangedListenerAgents_.erase(iter); +} + +void WindowRoot::UnregisterFocusChangedListener(const sptr& object) +{ + for (auto iter = focusChangedListenerAgents_.begin(); iter < focusChangedListenerAgents_.end(); ++iter) { + if ((*iter)->AsObject() != nullptr && (*iter)->AsObject() == object) { + iter = focusChangedListenerAgents_.erase(iter); + } + } +} + +void WindowRoot::UpdateFocusStatus(uint32_t windowId, const sptr& abilityToken, WindowType windowType, + int32_t displayId, bool focused) +{ + for (auto& windowManagerAgent : focusChangedListenerAgents_) { + windowManagerAgent->UpdateFocusStatus(windowId, abilityToken, windowType, displayId, focused); + } +} + void WindowRoot::ClearWindow(const sptr& remoteObject) { + std::lock_guard lock(mutex_); auto iter = windowIdMap_.find(remoteObject); if (iter == windowIdMap_.end()) { WLOGFE("window id could not be found"); @@ -201,6 +263,16 @@ void WindowRoot::ClearWindow(const sptr& remoteObject) DestroyWindow(windowId); } +void WindowRoot::ClearWindowManagerAgent(const sptr& remoteObject) +{ + if (remoteObject == nullptr) { + WLOGFI("remoteObject is null"); + return; + } + std::lock_guard lock(mutex_); + UnregisterFocusChangedListener(remoteObject); +} + void WindowDeathRecipient::OnRemoteDied(const wptr& wptrDeath) { if (wptrDeath == nullptr) { @@ -213,6 +285,23 @@ void WindowDeathRecipient::OnRemoteDied(const wptr& wptrDeath) WLOGFE("object is null"); return; } + WLOGFI("WindowDeathRecipient callback"); + callback_(object); +} + +void WindowManagerAgentDeathRecipient::OnRemoteDied(const wptr& wptrDeath) +{ + if (wptrDeath == nullptr) { + WLOGFE("wptrDeath is null"); + return; + } + + sptr object = wptrDeath.promote(); + if (!object) { + WLOGFE("object is null"); + return; + } + WLOGFI("WindowManagerAgentDeathRecipient callback"); callback_(object); } } diff --git a/wmtest/README.en.md b/wmtest/README.en.md deleted file mode 100644 index 996c31240565f10647e77d11019ba0da47036d65..0000000000000000000000000000000000000000 --- a/wmtest/README.en.md +++ /dev/null @@ -1,36 +0,0 @@ -# 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 deleted file mode 100644 index 098e283c85d26c345b28f5cad4c9131158304209..0000000000000000000000000000000000000000 --- a/wmtest/README.md +++ /dev/null @@ -1,39 +0,0 @@ -# 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 deleted file mode 100644 index 0efe55427523b7ac4c2afb8462c470d7dce8efe8..0000000000000000000000000000000000000000 --- a/wmtest/adapter/BUILD.gn +++ /dev/null @@ -1,98 +0,0 @@ -# Copyright (c) 2021 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -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 deleted file mode 100644 index c387a88d0feadcecb9318025c9e453a45b0dfe7c..0000000000000000000000000000000000000000 --- a/wmtest/adapter/include/adapter.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#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 deleted file mode 100644 index f705b490235b00f8dda6535abf4dc5a1d04e0643..0000000000000000000000000000000000000000 --- a/wmtest/adapter/src/adapter.cpp +++ /dev/null @@ -1,327 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "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 deleted file mode 100644 index bda91e7389908403060ac7266cf998451a5aee85..0000000000000000000000000000000000000000 --- a/wmtest/dm/include/README.md +++ /dev/null @@ -1 +0,0 @@ -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 deleted file mode 100644 index 61882fd0dba9c134c7fb798b7565ac8652682c33..0000000000000000000000000000000000000000 --- a/wmtest/dm/include/display_manager_adapter.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#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 deleted file mode 100644 index 8eb6cfc677dd9bd5133781d11e412945a4bb96fd..0000000000000000000000000000000000000000 --- a/wmtest/dm/src/README.md +++ /dev/null @@ -1 +0,0 @@ -Store code of display source files diff --git a/wmtest/dm/src/display.cpp b/wmtest/dm/src/display.cpp deleted file mode 100644 index 73655b9404a87e6eba3d41f0159244c642e34c83..0000000000000000000000000000000000000000 --- a/wmtest/dm/src/display.cpp +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "display.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 deleted file mode 100644 index 8c6c34fee2b0b0957e7856861698e663be020ace..0000000000000000000000000000000000000000 --- a/wmtest/dm/src/display_manager.cpp +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "display_manager.h" - -#include - -#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 %" PRIu64" 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 deleted file mode 100644 index 675bb97b8be1212aae57e403fc8d248196b2eae6..0000000000000000000000000000000000000000 --- a/wmtest/dm/src/display_manager_adapter.cpp +++ /dev/null @@ -1,143 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "display_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 deleted file mode 100644 index ca8933d58b4aea5bdbe2f9de8a475c0c61fbe738..0000000000000000000000000000000000000000 --- a/wmtest/dm/src/monitor.cpp +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "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 deleted file mode 100644 index 92b3669bdd6971bac668e392d46d0439ec732390..0000000000000000000000000000000000000000 --- a/wmtest/dmserver/include/README.md +++ /dev/null @@ -1 +0,0 @@ -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 deleted file mode 100644 index 72edc10998d20f9ae0370453fd2bcbf68d2a4fcc..0000000000000000000000000000000000000000 --- a/wmtest/dmserver/include/display_info.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing 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 deleted file mode 100644 index 8a7d71fc5e46fca2ae133a6cd13e1d60c236bc87..0000000000000000000000000000000000000000 --- a/wmtest/dmserver/include/display_manager_interface.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#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 deleted file mode 100644 index 519107124d52720ced4aa4842d79c5f5d989dd01..0000000000000000000000000000000000000000 --- a/wmtest/dmserver/include/display_manager_proxy.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#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 deleted file mode 100644 index 83ffbbe94abfeb64d7f4b3d7e7cb2f32ad044cc5..0000000000000000000000000000000000000000 --- a/wmtest/dmserver/include/display_manager_service.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#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 deleted file mode 100644 index 6051c8044364b94d4bccda04b9d4d5e2c08b2c03..0000000000000000000000000000000000000000 --- a/wmtest/dmserver/include/display_manager_service_inner.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#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_node_control.h b/wmtest/dmserver/include/display_node_control.h deleted file mode 100644 index 5da96a208147911f1bc9f74bf9fdb5752f816528..0000000000000000000000000000000000000000 --- a/wmtest/dmserver/include/display_node_control.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#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 deleted file mode 100644 index d656621953e85274d62a4dd0670693a0150d32b9..0000000000000000000000000000000000000000 --- a/wmtest/dmserver/include/display_screen.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#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/rs_adapter.h b/wmtest/dmserver/include/rs_adapter.h deleted file mode 100644 index 9f19e344c929afbdb13a1e3f866dfb29d07ecf13..0000000000000000000000000000000000000000 --- a/wmtest/dmserver/include/rs_adapter.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#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 deleted file mode 100644 index bbe436d55bb515aab342fe883f3b6155eedad961..0000000000000000000000000000000000000000 --- a/wmtest/dmserver/include/screen.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#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 deleted file mode 100644 index acfe633cd715263cb8c9f3795589fe28071660b5..0000000000000000000000000000000000000000 --- a/wmtest/dmserver/src/README.md +++ /dev/null @@ -1 +0,0 @@ -Store code of display manager service source files diff --git a/wmtest/dmserver/src/display_manager_proxy.cpp b/wmtest/dmserver/src/display_manager_proxy.cpp deleted file mode 100644 index a286f6fae44ff740aeed888e34e4cdc4e72d1e78..0000000000000000000000000000000000000000 --- a/wmtest/dmserver/src/display_manager_proxy.cpp +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "display_manager_proxy.h" - -#include -#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 %" PRIu64"", 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 deleted file mode 100644 index 93ca0d2d6a4a53e56cdbeb91ffdb52e7f38c56aa..0000000000000000000000000000000000000000 --- a/wmtest/dmserver/src/display_manager_service.cpp +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "display_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 deleted file mode 100644 index 9b53ac1cfb0768c6cbaee5f18465a7bbcf374d62..0000000000000000000000000000000000000000 --- a/wmtest/dmserver/src/display_manager_service_inner.cpp +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "display_manager_service_inner.h" - -#include -#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 %" PRIu64" 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 deleted file mode 100644 index 0e065619c8ef8c51af5aa8e3dc6db07f0e6fe872..0000000000000000000000000000000000000000 --- a/wmtest/dmserver/src/display_manager_stub.cpp +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "display_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 deleted file mode 100644 index 8f821aca7424aef573194937f43a09eb8439dc3c..0000000000000000000000000000000000000000 --- a/wmtest/dmserver/src/display_node_control.cpp +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "display_node_control.h" - -namespace OHOS::Rosen { -} // 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 deleted file mode 100644 index 91620c7493cc2452158a5080a8ccd0385f80d1aa..0000000000000000000000000000000000000000 --- a/wmtest/dmserver/src/display_screen_manager.cpp +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "display_screen_manager.h" - -namespace OHOS::Rosen { -IMPLEMENT_SINGLE_INSTANCE(DisplayScreenManager); - -DisplayScreenManager::DisplayScreenManager() : rsInterface_(&(RSInterfaces::GetInstance())) -{ - parepareRSScreenManger(); -} - -DisplayScreenManager::~DisplayScreenManager() -{ - rsInterface_ = nullptr; -} - -void DisplayScreenManager::parepareRSScreenManger() -{ -} - -ScreenId DisplayScreenManager::GetDefaultScreenId() -{ - if (rsInterface_ == nullptr) { - return INVALID_SCREEN_ID; - } - return rsInterface_->GetDefaultScreenId(); -} - -RSScreenModeInfo DisplayScreenManager::GetScreenActiveMode(ScreenId id) -{ - RSScreenModeInfo screenModeInfo; - if (rsInterface_ == nullptr) { - return screenModeInfo; - } - return rsInterface_->GetScreenActiveMode(id); -} -} // namespace OHOS::Rosen \ No newline at end of file diff --git a/wmtest/dmserver/src/rs_adapter.cpp b/wmtest/dmserver/src/rs_adapter.cpp deleted file mode 100644 index 5e5d66581dbf3064e666305cfc936108183dcf5f..0000000000000000000000000000000000000000 --- a/wmtest/dmserver/src/rs_adapter.cpp +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "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 deleted file mode 100644 index 11c222d130b9cbf29974b32080f165bd769e71ca..0000000000000000000000000000000000000000 --- a/wmtest/dmserver/src/screen.cpp +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "screen.h" - -namespace OHOS::Rosen { -} // namespace OHOS::Rosen \ No newline at end of file diff --git a/wmtest/frameworks/main.cpp b/wmtest/frameworks/main.cpp index cd38311459c022d0ba927088682c80234959c369..70e7840177f726e3c02436aec25add4e93c1f9ed 100644 --- a/wmtest/frameworks/main.cpp +++ b/wmtest/frameworks/main.cpp @@ -70,10 +70,10 @@ int32_t main(int32_t argc, const char **argv) } }; INativeTest::VisitTests(visitFunc); - //if (found == nullptr) { - // printf("not found test %d\n", testcase); - // return 1; - //} + 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); diff --git a/wmtest/interfaces/innerkits/BUILD.gn b/wmtest/interfaces/innerkits/BUILD.gn deleted file mode 100644 index 19b84753960f4359d913ec18436188ede1b46b63..0000000000000000000000000000000000000000 --- a/wmtest/interfaces/innerkits/BUILD.gn +++ /dev/null @@ -1,35 +0,0 @@ -# Copyright (c) 2021 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -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 deleted file mode 100644 index bf79d111584d69930e9ec5dcb1e8e8d1015fd7a5..0000000000000000000000000000000000000000 --- a/wmtest/interfaces/innerkits/dm/README.md +++ /dev/null @@ -1 +0,0 @@ -Store code of display client out header files diff --git a/wmtest/interfaces/innerkits/dm/display.h b/wmtest/interfaces/innerkits/dm/display.h deleted file mode 100644 index 64b1bac72c3843938cd2bf5765fe6972ec144127..0000000000000000000000000000000000000000 --- a/wmtest/interfaces/innerkits/dm/display.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing 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 deleted file mode 100644 index ed91aba1d3324c2cd3a802664bd5ee07ac7cf201..0000000000000000000000000000000000000000 --- a/wmtest/interfaces/innerkits/dm/display_manager.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#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/monitor.h b/wmtest/interfaces/innerkits/dm/monitor.h deleted file mode 100644 index 0cb2b1647509a91ac75a018a971d70879186ebf3..0000000000000000000000000000000000000000 --- a/wmtest/interfaces/innerkits/dm/monitor.h +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#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 deleted file mode 100644 index 24e92014b98eebf446e3a87d2b5a7b29398866ab..0000000000000000000000000000000000000000 --- a/wmtest/interfaces/innerkits/dmserver/README.md +++ /dev/null @@ -1 +0,0 @@ -Store code of display server out header files diff --git a/wmtest/interfaces/innerkits/wm/README.md b/wmtest/interfaces/innerkits/wm/README.md deleted file mode 100644 index 9702ea7e24e8e307993e40fa9d6b443c59d7672a..0000000000000000000000000000000000000000 --- a/wmtest/interfaces/innerkits/wm/README.md +++ /dev/null @@ -1 +0,0 @@ -Store code of window client out header files diff --git a/wmtest/interfaces/innerkits/wm/window.h b/wmtest/interfaces/innerkits/wm/window.h deleted file mode 100644 index 7b7d89eae0dba0f01fc89f7163a96d88215c5b24..0000000000000000000000000000000000000000 --- a/wmtest/interfaces/innerkits/wm/window.h +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#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_option.h b/wmtest/interfaces/innerkits/wm/window_option.h deleted file mode 100644 index 9f695dae2fa222d3ccf217bfa0d3f8ab56d63c69..0000000000000000000000000000000000000000 --- a/wmtest/interfaces/innerkits/wm/window_option.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#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 deleted file mode 100644 index dc984b01f9d773d4a610611e1ccf66babde93c7e..0000000000000000000000000000000000000000 --- a/wmtest/interfaces/innerkits/wm/window_scene.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#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 deleted file mode 100644 index cd472f88b15a46170d649a5e40ae70761e52ddaf..0000000000000000000000000000000000000000 --- a/wmtest/interfaces/innerkits/wm/wm_common.h +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#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 deleted file mode 100644 index 449c0fe9fdd851fbe5f3d56ede74b9bb3a196347..0000000000000000000000000000000000000000 --- a/wmtest/interfaces/innerkits/wmserver/README.md +++ /dev/null @@ -1 +0,0 @@ -Store code of window server out header files diff --git a/wmtest/interfaces/kits/README.md b/wmtest/interfaces/kits/README.md deleted file mode 100644 index 033c7c544c454719ab8ccb97c8d75305486c54a3..0000000000000000000000000000000000000000 --- a/wmtest/interfaces/kits/README.md +++ /dev/null @@ -1 +0,0 @@ -Store code of window js api diff --git a/wmtest/interfaces/kits/js/declaration/BUILD.gn b/wmtest/interfaces/kits/js/declaration/BUILD.gn deleted file mode 100644 index d63c1a22e0d716adef76adb82b6577df0f0e1604..0000000000000000000000000000000000000000 --- a/wmtest/interfaces/kits/js/declaration/BUILD.gn +++ /dev/null @@ -1,29 +0,0 @@ -# Copyright (c) 2021 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -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 deleted file mode 100644 index 17ac54ae5dab238b0214df8be4b7e55f3be58573..0000000000000000000000000000000000000000 --- a/wmtest/interfaces/kits/js/declaration/api/@ohos.display.d.ts +++ /dev/null @@ -1,135 +0,0 @@ -/* -* Copyright (c) 2021 Huawei Device Co., Ltd. -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/** - * 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 deleted file mode 100644 index 3872e90048735e3fa1ea9da9dce0769e4ba149fb..0000000000000000000000000000000000000000 --- a/wmtest/interfaces/kits/js/declaration/api/@ohos.window.d.ts +++ /dev/null @@ -1,79 +0,0 @@ -/* -* Copyright (c) 2021 Huawei Device Co., Ltd. -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/** - * 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/common/BUILD.gn b/wmtest/interfaces/kits/napi/common/BUILD.gn deleted file mode 100644 index 081352bd7b0e40125324ae1282ee56dea13bf13e..0000000000000000000000000000000000000000 --- a/wmtest/interfaces/kits/napi/common/BUILD.gn +++ /dev/null @@ -1,46 +0,0 @@ -# Copyright (c) 2021 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -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 deleted file mode 100644 index 16b5e6ef53e5ecfd58fe299b3a1c92e3564c9ea7..0000000000000000000000000000000000000000 --- a/wmtest/interfaces/kits/napi/common/wm_napi_common.cpp +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "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 deleted file mode 100644 index 480c511de12f56c776c31b05345df24facf900a8..0000000000000000000000000000000000000000 --- a/wmtest/interfaces/kits/napi/common/wm_napi_common.h +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#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 deleted file mode 100644 index 574ecb8a1c87b32f9c8b3050e80d78af543cb53b..0000000000000000000000000000000000000000 --- a/wmtest/interfaces/kits/napi/display/BUILD.gn +++ /dev/null @@ -1,30 +0,0 @@ -# Copyright (c) 2021 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -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 deleted file mode 100644 index 127326b9e449026db4778019da438286c416ed09..0000000000000000000000000000000000000000 --- a/wmtest/interfaces/kits/napi/display/native_display_module.cpp +++ /dev/null @@ -1,119 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "native_display_module.h" - -#include - -#include "display_manager.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 %" PRIu64", 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 deleted file mode 100644 index a24c7026abc00fa5964b264b278e9f9ba75770d1..0000000000000000000000000000000000000000 --- a/wmtest/interfaces/kits/napi/display/native_display_module.h +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#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 deleted file mode 100644 index 449bfb7fb414b0ae53027a0a39827a18e469061c..0000000000000000000000000000000000000000 --- a/wmtest/interfaces/kits/napi/window/BUILD.gn +++ /dev/null @@ -1,40 +0,0 @@ -# Copyright (c) 2021 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -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 deleted file mode 100644 index c009e2aa996ee8520d8559a3f14d39a2da37b0ec..0000000000000000000000000000000000000000 --- a/wmtest/interfaces/kits/napi/window/native_window_module.cpp +++ /dev/null @@ -1,233 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -#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 deleted file mode 100644 index c4a21c440cb040305c15a5816fceba2824d6ec7d..0000000000000000000000000000000000000000 --- a/wmtest/interfaces/kits/napi/window/native_window_module.h +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#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_module.cpp b/wmtest/interfaces/kits/napi/window_stage_module.cpp deleted file mode 100644 index b6ad1d3a6524d736975e43ebb38086998b678766..0000000000000000000000000000000000000000 --- a/wmtest/interfaces/kits/napi/window_stage_module.cpp +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "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 deleted file mode 100644 index 49aaabd0f0d5fd7588fae9c0a98ceacf02323b83..0000000000000000000000000000000000000000 --- a/wmtest/ohos.build +++ /dev/null @@ -1,22 +0,0 @@ -{ - "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/4606.xml b/wmtest/sa_profile/4606.xml deleted file mode 100644 index 7a02c334da51c72dd7275991b7f5fe9b667c4f74..0000000000000000000000000000000000000000 --- a/wmtest/sa_profile/4606.xml +++ /dev/null @@ -1,26 +0,0 @@ - - - - foundation - - 4606 - libwms.z.so - - - true - false - 1 - - diff --git a/wmtest/sa_profile/4607.xml b/wmtest/sa_profile/4607.xml deleted file mode 100644 index c505c2360d6f0967b11ede68c59e9371a28675da..0000000000000000000000000000000000000000 --- a/wmtest/sa_profile/4607.xml +++ /dev/null @@ -1,26 +0,0 @@ - - - - foundation - - 4607 - libwms.z.so - - - true - false - 1 - - diff --git a/wmtest/sa_profile/BUILD.gn b/wmtest/sa_profile/BUILD.gn deleted file mode 100644 index 616acf799ec507286577a67f3bbeb4e0068b6507..0000000000000000000000000000000000000000 --- a/wmtest/sa_profile/BUILD.gn +++ /dev/null @@ -1,22 +0,0 @@ -# Copyright (c) 2021 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import("//build/ohos/sa_profile/sa_profile.gni") - -ohos_sa_profile("wms_sa_profile") { - sources = [ - "4606.xml", - "4607.xml", - ] - part_name = "window_manager" -} diff --git a/wmtest/test/dm_native_test.cpp b/wmtest/test/dm_native_test.cpp index 8bd616a8efba348091a6b772f103a399b0d82cd3..3c1a9711f93859d7f1c24f6c24dac4c53be00493 100644 --- a/wmtest/test/dm_native_test.cpp +++ b/wmtest/test/dm_native_test.cpp @@ -15,13 +15,12 @@ #include "dm_native_test.h" +#include #include -#include #include - -#include "wm_common.h" #include "display_manager.h" #include "singleton_container.h" +#include "wm_common.h" using namespace OHOS::Rosen; @@ -79,8 +78,8 @@ void DMNativeTest::Run(int32_t argc, const char **argv) if (display == nullptr) { printf("GetDisplayById(%" PRIu64"): failed!\n", id); } else { - printf("GetDisplayById(%" PRIu64"): id %" PRIu64", w %d, h %d, fps %u\n", id, display->GetId(), display->GetWidth(), - display->GetHeight(), display->GetFreshRate()); + printf("GetDisplayById(%" PRIu64"): id %" PRIu64", w %d, h %d, fps %u\n", id, display->GetId(), + display->GetWidth(), display->GetHeight(), display->GetFreshRate()); } } diff --git a/wmtest/unittest/include/mock/singleton_mocker.h b/wmtest/unittest/include/mock/singleton_mocker.h index c3bce98c20d39c139086e188f4a34f2a898642b4..e593e5fbd1034e30e033097b7d783b2f1eaa2c91 100644 --- a/wmtest/unittest/include/mock/singleton_mocker.h +++ b/wmtest/unittest/include/mock/singleton_mocker.h @@ -24,29 +24,21 @@ class SingletonMocker { public: SingletonMocker() { - origin = SingletonContainer::Get(); - mock = new MockT(); SingletonContainer::Set(mock); } ~SingletonMocker() { - SingletonContainer::Set(origin); + SingletonContainer::Set(T::GetInstance()); } - sptr Origin() - { - return origin; - } - - sptr Mock() + MockT& Mock() { return mock; } private: - sptr origin = nullptr; - sptr mock = nullptr; + MockT mock; }; } // namespace Rosen } // namespace OHOS diff --git a/wmtest/unittest/src/window_impl_test.cpp b/wmtest/unittest/src/window_impl_test.cpp index 52d585fb806edd253582ec27f523951449f9c56d..3e6bd8b3a1f39b1f8a0e07705c36972e0967c051 100644 --- a/wmtest/unittest/src/window_impl_test.cpp +++ b/wmtest/unittest/src/window_impl_test.cpp @@ -43,5 +43,88 @@ void WindowImplTest::TearDown() { } +namespace { +/* + * Function: Show + * Type: Reliability + * Rank: Important(2) + * EnvConditions: N/A + * CaseDescription: 1. mock WindowAdapter + * 2. mock AddWindow return WM_OK + * 3. call Show to AddWindow and check return is WM_OK + * 4. call Show with isAdded_=true and check return is WM_OK + * 5. mock RemoveWindow return WM_OK + * 6. call Destroy check return is WM_OK + */ +HWTEST_F(WindowImplTest, ShowWindow01, testing::ext::TestSize.Level0) +{ + PART("CaseShow01") { +#ifdef _NEW_RENDERSERVER_ + using Mocker = SingletonMocker; + std::unique_ptr m = nullptr; + STEP("1. mock WindowAdapter") { + m = std::make_unique(); + } + + STEP("2. mock AddWindow return WM_OK") { + EXPECT_CALL(m->Mock(), AddWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK)); + } + + STEP("3. call Show and check return is WM_OK") { + STEP_ASSERT_EQ(WMError::WM_OK, window_->Show()); + } + + STEP("4. mock RemoveWindow return WM_OK") { + EXPECT_CALL(m->Mock(), RemoveWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK)); + } + + STEP("5. call Destroy check return is WM_OK") { + STEP_ASSERT_EQ(WMError::WM_OK, window_->Destroy()); + } +#endif + } +} + +/* + * Function: Show + * Type: Reliability + * Rank: Important(2) + * EnvConditions: N/A + * CaseDescription: 1. mock WindowAdapter + * 2. mock AddWindow return WM_ERROR_DEATH_RECIPIENT + * 3. call Show to AddWindow and check return is WM_ERROR_DEATH_RECIPIENT + * 4. call Show with isAdded_=true and check return is WM_ERROR_DEATH_RECIPIENT + * 5. mock RemoveWindow return WM_OK + * 6. call Destroy check return is WM_OK + */ +HWTEST_F(WindowImplTest, ShowWindow02, testing::ext::TestSize.Level0) +{ + PART("CaseShow02") { +#ifdef _NEW_RENDERSERVER_ + using Mocker = SingletonMocker; + std::unique_ptr m = nullptr; + STEP("1. mock WindowAdapter") { + m = std::make_unique(); + } + + STEP("2. mock AddWindow return WM_ERROR_DEATH_RECIPIENT") { + EXPECT_CALL(m->Mock(), AddWindow(_)).Times(1).WillOnce(Return(WMError::WM_ERROR_DEATH_RECIPIENT)); + } + + STEP("3. call Show and check return is WM_ERROR_DEATH_RECIPIENT") { + STEP_ASSERT_EQ(WMError::WM_ERROR_DEATH_RECIPIENT, window_->Show()); + } + + STEP("4. mock RemoveWindow return WM_OK") { + EXPECT_CALL(m->Mock(), RemoveWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK)); + } + + STEP("5. call Destroy check return is WM_OK") { + STEP_ASSERT_EQ(WMError::WM_OK, window_->Destroy()); + } +#endif + } +} +} } // namespace Rosen -} // namespace OHOS +} // namespace OHOS \ No newline at end of file diff --git a/wmtest/utils/include/single_instance.h b/wmtest/utils/include/single_instance.h deleted file mode 100644 index b255caf73d94d65f85c9e98eaad4207333caa372..0000000000000000000000000000000000000000 --- a/wmtest/utils/include/single_instance.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#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 deleted file mode 100644 index 68d6d7e8ec60101761646726b6f38ec9af720958..0000000000000000000000000000000000000000 --- a/wmtest/utils/include/singleton_container.h +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#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/window_manager_hilog.h b/wmtest/utils/include/window_manager_hilog.h deleted file mode 100644 index bf790ce8880a48f8f70b000ba8e26d293381a71a..0000000000000000000000000000000000000000 --- a/wmtest/utils/include/window_manager_hilog.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#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 deleted file mode 100644 index 0b851fdae250c59a4b7fc65bf13f346d042c7bb7..0000000000000000000000000000000000000000 --- a/wmtest/utils/src/singleton_container.cpp +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "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/wm/BUILD.gn b/wmtest/wm/BUILD.gn deleted file mode 100644 index a517968506f142873b301717c63dbc94d2715c82..0000000000000000000000000000000000000000 --- a/wmtest/wm/BUILD.gn +++ /dev/null @@ -1,161 +0,0 @@ -# Copyright (c) 2021 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -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 deleted file mode 100644 index f0321dc5d0e30b1a50abc177befda0f70cb81358..0000000000000000000000000000000000000000 --- a/wmtest/wm/include/README.md +++ /dev/null @@ -1 +0,0 @@ -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 deleted file mode 100644 index 5c8fa1466fa3733fda488952225800566cc4b2ad..0000000000000000000000000000000000000000 --- a/wmtest/wm/include/input_transfer_station.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#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/window_adapter.h b/wmtest/wm/include/window_adapter.h deleted file mode 100644 index 49ca563360fb9356485d8b259b79331d7fae6dbc..0000000000000000000000000000000000000000 --- a/wmtest/wm/include/window_adapter.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#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_impl.h b/wmtest/wm/include/window_impl.h deleted file mode 100644 index 17766e3f105bbffe6812bcd7dc21c28405f31e0b..0000000000000000000000000000000000000000 --- a/wmtest/wm/include/window_impl.h +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#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 deleted file mode 100644 index fb700a1d5464032c5d913eb3d82783ce53f580fe..0000000000000000000000000000000000000000 --- a/wmtest/wm/include/window_input_channel.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#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 deleted file mode 100644 index 846ded865285ddb6bf00841e5411b64335fd3911..0000000000000000000000000000000000000000 --- a/wmtest/wm/include/window_interface.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#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 deleted file mode 100644 index f8b9ed4ca0d6fa47458baeec987794856c72559d..0000000000000000000000000000000000000000 --- a/wmtest/wm/include/window_property.h +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#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/src/README.md b/wmtest/wm/src/README.md deleted file mode 100644 index 2a99b4a2c9cf32ca8a28ce0857c95758c2cbde42..0000000000000000000000000000000000000000 --- a/wmtest/wm/src/README.md +++ /dev/null @@ -1 +0,0 @@ -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 deleted file mode 100644 index 43adc731bc68971b9c7203896bcd3bf78d55e693..0000000000000000000000000000000000000000 --- a/wmtest/wm/src/input_transfer_station.cpp +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "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 deleted file mode 100644 index 4cc44398270977ea9fbb6e77b86547e007e5056b..0000000000000000000000000000000000000000 --- a/wmtest/wm/src/vsync_station.cpp +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -#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_adapter.cpp b/wmtest/wm/src/window_adapter.cpp deleted file mode 100644 index 81b169617ed63d643d9299114f6bdfc4bfa5cae3..0000000000000000000000000000000000000000 --- a/wmtest/wm/src/window_adapter.cpp +++ /dev/null @@ -1,171 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "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_impl.cpp b/wmtest/wm/src/window_impl.cpp deleted file mode 100644 index 6f5d980a75727f90abdebdfa1142db444acee58a..0000000000000000000000000000000000000000 --- a/wmtest/wm/src/window_impl.cpp +++ /dev/null @@ -1,428 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "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 deleted file mode 100644 index 952270f3aae386b0e806e51e282bc49c89c533c9..0000000000000000000000000000000000000000 --- a/wmtest/wm/src/window_input_channel.cpp +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "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 deleted file mode 100644 index d116dd97893bdb8e80421372db91aa1b1a38144d..0000000000000000000000000000000000000000 --- a/wmtest/wm/src/window_option.cpp +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "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 deleted file mode 100644 index 3ee405db3ebb870d75f5b17093ae8433474b74bb..0000000000000000000000000000000000000000 --- a/wmtest/wm/src/window_property.cpp +++ /dev/null @@ -1,238 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "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_scene.cpp b/wmtest/wm/src/window_scene.cpp deleted file mode 100644 index 3281d774287eb59dfd8df0b1bd053d8cc46ffc42..0000000000000000000000000000000000000000 --- a/wmtest/wm/src/window_scene.cpp +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "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/wmserver/BUILD.gn b/wmtest/wmserver/BUILD.gn deleted file mode 100644 index 6db371375123cae1b8cc078d6aaefe8f41908413..0000000000000000000000000000000000000000 --- a/wmtest/wmserver/BUILD.gn +++ /dev/null @@ -1,85 +0,0 @@ -# Copyright (c) 2021 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -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 deleted file mode 100644 index 539249966b4bf441daae568854d04f8f8b0e5029..0000000000000000000000000000000000000000 --- a/wmtest/wmserver/include/README.md +++ /dev/null @@ -1 +0,0 @@ -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 deleted file mode 100644 index ed446505805590d1edc8f2f1891476daa8c7a677..0000000000000000000000000000000000000000 --- a/wmtest/wmserver/include/input_window_monitor.h +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#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 deleted file mode 100644 index 043cad3d49d9773c55b9202279e2d919ac75a265..0000000000000000000000000000000000000000 --- a/wmtest/wmserver/include/window_controller.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#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 deleted file mode 100644 index 350b8c0e2a0515e50004b60413486a84cf46055d..0000000000000000000000000000000000000000 --- a/wmtest/wmserver/include/window_layout_policy.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#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 deleted file mode 100644 index e1d9d4d49443a9937fc7d525f719bd287aef4549..0000000000000000000000000000000000000000 --- a/wmtest/wmserver/include/window_manager_interface.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#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_service.h b/wmtest/wmserver/include/window_manager_service.h deleted file mode 100644 index b722b1646912b283861a259a1854d3aff4d0648f..0000000000000000000000000000000000000000 --- a/wmtest/wmserver/include/window_manager_service.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#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_node.h b/wmtest/wmserver/include/window_node.h deleted file mode 100644 index 0684ebe71db850c6ea4e5753a8df58c1590c35c4..0000000000000000000000000000000000000000 --- a/wmtest/wmserver/include/window_node.h +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#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 deleted file mode 100644 index 251683b665fea1a812bf9b756845b8193cf00ba6..0000000000000000000000000000000000000000 --- a/wmtest/wmserver/include/window_node_container.h +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#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 deleted file mode 100644 index 9a86234686cc8e5504f1129d0896986d87b26bda..0000000000000000000000000000000000000000 --- a/wmtest/wmserver/include/window_root.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#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 deleted file mode 100644 index 8e91d3d664faa9e906e395d4d497652ae7d1ad99..0000000000000000000000000000000000000000 --- a/wmtest/wmserver/include/window_zorder_policy.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#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 deleted file mode 100644 index 6aa13c7e6a88bfb1eafe50621b24c3d17b1c9acb..0000000000000000000000000000000000000000 --- a/wmtest/wmserver/src/README.md +++ /dev/null @@ -1 +0,0 @@ -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 deleted file mode 100644 index 9dc6ff82a8cd355eebe41612d650631eec262bbd..0000000000000000000000000000000000000000 --- a/wmtest/wmserver/src/input_window_monitor.cpp +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "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 deleted file mode 100644 index 9f3dbe1ead73a03774e74706da4f41afca68733e..0000000000000000000000000000000000000000 --- a/wmtest/wmserver/src/window_controller.cpp +++ /dev/null @@ -1,153 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "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 deleted file mode 100644 index c90a5f030e760c1592fbb39b7276fb0ab9569b62..0000000000000000000000000000000000000000 --- a/wmtest/wmserver/src/window_layout_policy.cpp +++ /dev/null @@ -1,184 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "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 deleted file mode 100644 index f1f2da589e9d5dfbfddf5c866bbe454f542d8c45..0000000000000000000000000000000000000000 --- a/wmtest/wmserver/src/window_manager_proxy.cpp +++ /dev/null @@ -1,247 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "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 deleted file mode 100644 index 7c70a580ba2556d99dc3417daa42011c34f95781..0000000000000000000000000000000000000000 --- a/wmtest/wmserver/src/window_manager_service.cpp +++ /dev/null @@ -1,134 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "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 deleted file mode 100644 index cd18fed9f453d28c2d7cf2daab8ce8e8780da4d1..0000000000000000000000000000000000000000 --- a/wmtest/wmserver/src/window_manager_stub.cpp +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "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 deleted file mode 100644 index 389d4f367782c55b13a7622c7f03a38459e66649..0000000000000000000000000000000000000000 --- a/wmtest/wmserver/src/window_node.cpp +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "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 deleted file mode 100644 index f4ed70a0c0ba6898056e4fe2075e8e8081495be3..0000000000000000000000000000000000000000 --- a/wmtest/wmserver/src/window_node_container.cpp +++ /dev/null @@ -1,366 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "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 deleted file mode 100644 index ac626427923ab10c2b54dcf0e55686fcff4ca5d5..0000000000000000000000000000000000000000 --- a/wmtest/wmserver/src/window_root.cpp +++ /dev/null @@ -1,219 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "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); -} -} -}