diff --git a/dmserver/BUILD.gn b/dmserver/BUILD.gn index 3e64871510a194fde2a7f3f9ce74e717965c0976..d447d0aeb20ec1b0fc4ebbcc85986e2b5857e02a 100644 --- a/dmserver/BUILD.gn +++ b/dmserver/BUILD.gn @@ -68,6 +68,7 @@ ohos_shared_library("libdms") { "ipc:ipc_single", "safwk:system_ability_fwk", "sensor:sensor_interface_native", + "window_manager:libwsutils", ] if (defined(use_new_skia) && use_new_skia) { diff --git a/dmserver/src/display_manager_service.cpp b/dmserver/src/display_manager_service.cpp index ffc10f3002ede0ec2089add7ac3f9ab8712d5223..63e31051628239eb0047bcf2feb3939fe1df6c30 100644 --- a/dmserver/src/display_manager_service.cpp +++ b/dmserver/src/display_manager_service.cpp @@ -19,6 +19,7 @@ #include #include #include +#include "scene_board_judgement.h" #include #include "display_manager_agent_controller.h" @@ -36,7 +37,8 @@ namespace { const std::string SCREEN_CAPTURE_PERMISSION = "ohos.permission.CAPTURE_SCREEN"; } WM_IMPLEMENT_SINGLE_INSTANCE(DisplayManagerService) -const bool REGISTER_RESULT = SystemAbility::MakeAndRegisterAbility(&SingletonContainer::Get()); +const bool REGISTER_RESULT = SceneBoardJudgement::IsSceneBoardEnabled() ? false : + SystemAbility::MakeAndRegisterAbility(&SingletonContainer::Get()); #define CHECK_SCREEN_AND_RETURN(screenId, ret) \ do { \ diff --git a/interfaces/kits/napi/window_runtime/BUILD.gn b/interfaces/kits/napi/window_runtime/BUILD.gn index 4179dc4d64febe996d053d705a5e0f893bafc47c..4e9031a48f26bd5326bd01affb12863a57f7768b 100644 --- a/interfaces/kits/napi/window_runtime/BUILD.gn +++ b/interfaces/kits/napi/window_runtime/BUILD.gn @@ -133,6 +133,7 @@ ohos_shared_library("windowstage_kit") { external_deps = [ "ability_runtime:runtime", + "ace_engine:ace_uicontent", "c_utils:utils", "hiviewdfx_hilog_native:libhilog", "napi:ace_napi", diff --git a/interfaces/kits/napi/window_runtime/window_stage_napi/js_window_stage.cpp b/interfaces/kits/napi/window_runtime/window_stage_napi/js_window_stage.cpp index df11c3eb30f2e34212df759de73c20065da541e2..66d3a959c8fc7bf1d5d5fe5ea05d40231cbda378 100644 --- a/interfaces/kits/napi/window_runtime/window_stage_napi/js_window_stage.cpp +++ b/interfaces/kits/napi/window_runtime/window_stage_napi/js_window_stage.cpp @@ -31,8 +31,9 @@ constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "JsWindo } // namespace std::unique_ptr g_listenerManager = std::make_unique(); -JsWindowStage::JsWindowStage(const std::shared_ptr& windowScene) - : windowScene_(windowScene) +JsWindowStage::JsWindowStage(const std::shared_ptr& windowScene, + const std::shared_ptr& uiWindow) + : windowScene_(windowScene), uiWindow_(uiWindow) { } @@ -129,11 +130,6 @@ NativeValue* JsWindowStage::OnSetUIContent(NativeEngine& engine, NativeCallbackI WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc); return engine.CreateUndefined(); } - auto weakScene = windowScene_.lock(); - if (weakScene == nullptr || weakScene->GetMainWindow() == nullptr) { - WLOGFE("[NAPI]WindowScene is null or window is null"); - return engine.CreateUndefined(); - } // Parse info->argv[0] as abilitycontext auto objContext = ConvertNativeValueTo(info.argv[0]); @@ -148,6 +144,19 @@ NativeValue* JsWindowStage::OnSetUIContent(NativeEngine& engine, NativeCallbackI WLOGFE("[NAPI]Failed to convert parameter to url"); return engine.CreateUndefined(); } + + auto uiWindow = uiWindow_.lock(); + if (uiWindow) { + uiWindow->LoadContent(contextUrl, &engine, nullptr); + uiWindow->Connect(); + return engine.CreateUndefined(); + } + + auto weakScene = windowScene_.lock(); + if (weakScene == nullptr || weakScene->GetMainWindow() == nullptr) { + WLOGFE("[NAPI]WindowScene is null or window is null"); + return engine.CreateUndefined(); + } weakScene->GetMainWindow()->SetUIContent(contextUrl, &engine, info.argv[CONTENT_STORAGE_ARG]); return engine.CreateUndefined(); } @@ -336,16 +345,16 @@ NativeValue* JsWindowStage::OnLoadContent(NativeEngine& engine, NativeCallbackIn std::shared_ptr contentStorage = (storage == nullptr) ? nullptr : std::shared_ptr(engine.CreateReference(storage, 1)); AsyncTask::CompleteCallback complete = - [weak = windowScene_, contentStorage, contextUrl, errCode]( + [weak = windowScene_, contentStorage, contextUrl, weakUIWindow = uiWindow_]( NativeEngine& engine, AsyncTask& task, int32_t status) { - auto weakScene = weak.lock(); - if (weakScene == nullptr) { - WLOGFE("[NAPI]Window scene is null"); - task.Reject(engine, CreateJsError(engine, - static_cast(WmErrorCode::WM_ERROR_STAGE_ABNORMALLY))); + if (auto uiWindow = weakUIWindow.lock()) { + NativeValue* nativeStorage = contentStorage ? contentStorage->Get() : nullptr; + uiWindow->LoadContent(contextUrl, &engine, nativeStorage); + task.Resolve(engine, engine.CreateUndefined()); return; } - auto win = weakScene->GetMainWindow(); + auto weakScene = weak.lock(); + sptr win = weakScene ? weakScene->GetMainWindow() : nullptr; if (win == nullptr) { task.Reject(engine, CreateJsError(engine, static_cast(WmErrorCode::WM_ERROR_STATE_ABNORMALLY))); @@ -545,13 +554,13 @@ NativeValue* JsWindowStage::OnDisableWindowDecor(NativeEngine& engine, NativeCal } NativeValue* CreateJsWindowStage(NativeEngine& engine, - std::shared_ptr windowScene) + std::shared_ptr windowScene, std::shared_ptr uiWindow) { WLOGFD("[NAPI]CreateJsWindowStage"); NativeValue* objValue = engine.CreateObject(); NativeObject* object = ConvertNativeValueTo(objValue); - std::unique_ptr jsWindowStage = std::make_unique(windowScene); + std::unique_ptr jsWindowStage = std::make_unique(windowScene, uiWindow); object->SetNativePointer(jsWindowStage.release(), JsWindowStage::Finalizer, nullptr); const char *moduleName = "JsWindowStage"; diff --git a/interfaces/kits/napi/window_runtime/window_stage_napi/js_window_stage.h b/interfaces/kits/napi/window_runtime/window_stage_napi/js_window_stage.h index b7fc775676ee8624c97894808af39d82b1e2329f..13358c97f61b4416e4dd08e8422d4f50ed2a44ce 100644 --- a/interfaces/kits/napi/window_runtime/window_stage_napi/js_window_stage.h +++ b/interfaces/kits/napi/window_runtime/window_stage_napi/js_window_stage.h @@ -21,12 +21,15 @@ #include "native_engine/native_reference.h" #include "native_engine/native_value.h" #include "window_scene.h" +#include "ui_window.h" namespace OHOS { namespace Rosen { -NativeValue* CreateJsWindowStage(NativeEngine& engine, std::shared_ptr windowScene); +NativeValue* CreateJsWindowStage(NativeEngine& engine, std::shared_ptr windowScene, + std::shared_ptr uiWindow = nullptr); class JsWindowStage { public: - explicit JsWindowStage(const std::shared_ptr& windowScene); + explicit JsWindowStage(const std::shared_ptr& windowScene, + const std::shared_ptr& uiWindow); ~JsWindowStage(); static void Finalizer(NativeEngine* engine, void* data, void* hint); static NativeValue* SetUIContent(NativeEngine* engine, NativeCallbackInfo* info); @@ -55,6 +58,7 @@ private: NativeValue* OnDisableWindowDecor(NativeEngine& engine, NativeCallbackInfo& info); std::weak_ptr windowScene_; + std::weak_ptr uiWindow_; }; } // namespace Rosen } // namespace OHOS diff --git a/previewer/mock/ui_window.h b/previewer/mock/ui_window.h new file mode 100644 index 0000000000000000000000000000000000000000..b6bee30feb5822dd08b08cf51c90bef00652b83a --- /dev/null +++ b/previewer/mock/ui_window.h @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FOUNDATION_ACE_INTERFACE_INNER_API_UI_WINDOW_H +#define FOUNDATION_ACE_INTERFACE_INNER_API_UI_WINDOW_H + +#include + +#include "ui_content.h" + +namespace OHOS::Rosen { +class RSSurfaceNode; +class ISession; +class ISessionStageStateListener; +} + +namespace OHOS::Ace::NG { + +class ACE_EXPORT UIWindow { +public: + static std::shared_ptr CreateRootScene() { + return nullptr; + }; + + static std::shared_ptr CreateWindowScene(const std::shared_ptr& context, + const sptr& iSession, const std::shared_ptr& surfaceNode) { + return nullptr; + }; + + static std::shared_ptr CreateWindowExtension(const std::shared_ptr& context, + const sptr& iSession, const std::shared_ptr& surfaceNode) { + return nullptr; + }; + + virtual ~UIWindow() = default; + + virtual void LoadContent(const std::string& contentUrl, NativeEngine* engine, NativeValue* storage, + AbilityRuntime::Context* context = nullptr) = 0; + + // for lifecycle + virtual void RegisterSessionStageStateListener( + const std::shared_ptr& listener) = 0; + + virtual void Connect() = 0; + virtual void Foreground() = 0; + virtual void Background() = 0; + virtual void Disconnect() = 0; +}; + +} // namespace OHOS::Ace::NG + +#endif // FOUNDATION_ACE_INTERFACE_INNER_API_UI_WINDOW_H diff --git a/window_scene/common/BUILD.gn b/window_scene/common/BUILD.gn index 3a6e7c908dff18da4717d4fe18b8a60da9b1ed1c..daaa6651a685d292ff1511ed78f3978ece2dffdb 100644 --- a/window_scene/common/BUILD.gn +++ b/window_scene/common/BUILD.gn @@ -13,7 +13,8 @@ import("//build/ohos.gni") import("//foundation/window/window_manager/windowmanager_aafwk.gni") -config("libwscommon_public_config") { + +config("window_scene_common_public_config") { include_dirs = [ "${window_base_path}/window_scene", @@ -26,12 +27,13 @@ config("libwscommon_public_config") { ohos_shared_library("window_scene_common") { sources = [ "src/message_scheduler.cpp" ] - public_configs = [ ":libwscommon_public_config" ] + public_configs = [ ":window_scene_common_public_config" ] external_deps = [ "eventhandler:libeventhandler", "hilog_native:libhilog", ] + part_name = "window_manager" subsystem_name = "window" } diff --git a/window_scene/session/BUILD.gn b/window_scene/session/BUILD.gn index 7a4c3c2263cc3f742b16ea816b01f368cffd0a33..8ce08f99c9d0de3cf86b8b5ddade3c0663bd6704 100644 --- a/window_scene/session/BUILD.gn +++ b/window_scene/session/BUILD.gn @@ -26,6 +26,7 @@ config("session_public_config") { ohos_shared_library("scene_session") { sources = [ "container/src/extension_session_stage.cpp", + "container/src/scene_session_stage.cpp", "container/src/session_stage.cpp", "container/src/window_event_channel.cpp", "container/src/zidl/session_stage_proxy.cpp", @@ -33,24 +34,42 @@ ohos_shared_library("scene_session") { "container/src/zidl/window_event_channel_proxy.cpp", "container/src/zidl/window_event_channel_stub.cpp", "host/src/extension_session.cpp", + "host/src/root_scene_session.cpp", + "host/src/scene_session.cpp", "host/src/session.cpp", "host/src/zidl/session_proxy.cpp", "host/src/zidl/session_stub.cpp", ] - cflags_cc = [ "-std=c++17" ] - public_configs = [ ":session_public_config" ] deps = [ "${graphic_base_path}/graphic_2d/rosen/modules/render_service_client:librender_service_client" ] + public_deps = + [ "${window_base_path}/window_scene/interfaces/innerkits:libwsutils" ] + external_deps = [ "c_utils:utils", "hilog_native:libhilog", "input:libmmi-client", "ipc:ipc_single", + "multimedia_image_framework:image_native", ] part_name = "window_manager" subsystem_name = "window" } + +ohos_shared_library("screen_session") { + sources = [ + "screen/src/screen_property.cpp", + "screen/src/screen_session.cpp", + ] + + public_configs = [ ":session_public_config" ] + + deps = [ "${graphic_base_path}/graphic_2d/rosen/modules/render_service_client:librender_service_client" ] + + part_name = "window_manager" + subsystem_name = "window" +} diff --git a/window_scene/session/container/include/scene_session_stage.h b/window_scene/session/container/include/scene_session_stage.h new file mode 100644 index 0000000000000000000000000000000000000000..8c3de122bdf404b3d244af54c8c11bf3b47438d9 --- /dev/null +++ b/window_scene/session/container/include/scene_session_stage.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_ROSEN_WINDOW_SCENE_SCENE_SESSION_STAGE_H +#define OHOS_ROSEN_WINDOW_SCENE_SCENE_SESSION_STAGE_H + +#include "interfaces/include/ws_common.h" +#include "session/container/include/session_stage.h" + +namespace OHOS::Rosen { +class SceneSessionStage : public SessionStage { +public: + SceneSessionStage(const sptr& sceneSession); + ~SceneSessionStage() = default; + + WSError Connect() override; + WSError Recover() override; + WSError Maximize() override; +}; +} // namespace OHOS::Rosen + +#endif // OHOS_ROSEN_WINDOW_SCENE_SCENE_SESSION_STAGE_H diff --git a/window_scene/session/container/include/session_stage.h b/window_scene/session/container/include/session_stage.h index e8bcd48c82ad1b3bd83fcb5195602734e5bc6504..c8d4f0a6742f725cd5202c4a833f90627dd982fb 100644 --- a/window_scene/session/container/include/session_stage.h +++ b/window_scene/session/container/include/session_stage.h @@ -18,7 +18,6 @@ #include #include -#include #include #include "interfaces/include/ws_common.h" @@ -35,25 +34,22 @@ class AxisEvent; namespace OHOS::Rosen { class ISessionStageStateListener { public: - virtual void AfterForeground() {}; - virtual void AfterBackground() {}; - virtual void AfterActive() {}; - virtual void AfterInactive() {}; + virtual void AfterForeground() = 0; + virtual void AfterBackground() = 0; + virtual void AfterActive() = 0; + virtual void AfterInactive() = 0; }; class ISizeChangeListener { public: - virtual void OnSizeChange(WSRect rect, SizeChangeReason reason) = 0; + virtual void OnSizeChange(const WSRect& rect, SizeChangeReason reason) = 0; }; -class IPointerEventListener { +class IInputEventListener { public: virtual void OnPointerEvent(const std::shared_ptr& pointerEvent) = 0; -}; - -class IKeyEventListener { -public: virtual void OnKeyEvent(const std::shared_ptr& keyEvent) = 0; + virtual void OnAxisEvent(const std::shared_ptr& axisEvent) = 0; }; class SessionStage : public SessionStageStub, public virtual RefBase { @@ -66,6 +62,15 @@ class SessionStage : public SessionStageStub, public virtual RefBase { } \ } while (0) +#define CALL_INPUT_EVENT_LISTENER(listeners, inputCb, event) \ + do { \ + for (auto& listener : (listeners)) { \ + if (!listener.expired()) { \ + listener.lock()->inputCb(event); \ + } \ + } \ + } while (0) + public: explicit SessionStage(const sptr& session); virtual ~SessionStage() = default; @@ -79,26 +84,47 @@ public: virtual WSError Recover(); virtual WSError Maximize(); - // IPC WSError SetActive(bool active) override; WSError UpdateRect(const WSRect& rect, SizeChangeReason reason) override; bool RegisterSessionStageStateListener(const std::shared_ptr& listener); bool UnregisterSessionStageStateListener(const std::shared_ptr& listener); + bool RegisterSizeChangeListener(const std::shared_ptr& listener); bool UnregisterSizeChangeListener(const std::shared_ptr& listener); - bool RegisterPointerEventListener(const std::shared_ptr& listener); - bool UnregisterPointerEventListener(const std::shared_ptr& listener); - bool RegisterKeyEventListener(const std::shared_ptr& listener); - bool UnregisterKeyEventListener(const std::shared_ptr& listener); + bool RegisterInputEventListener(const std::shared_ptr& listener); + bool UnregisterInputEventListener(const std::shared_ptr& listener); - // for window event - void NotifyPointerEvent(const std::shared_ptr& pointerEvent); - void NotifyKeyEvent(const std::shared_ptr& keyEvent); + inline void NotifyPointerEvent(const std::shared_ptr& pointerEvent) + { + auto listeners = GetListeners(); + CALL_INPUT_EVENT_LISTENER(listeners, OnPointerEvent, pointerEvent); + } + + inline void NotifyKeyEvent(const std::shared_ptr& keyEvent) + { + auto listeners = GetListeners(); + CALL_INPUT_EVENT_LISTENER(listeners, OnKeyEvent, keyEvent); + } + + inline void NotifyAxisEvent(const std::shared_ptr& axisEvent) + { + auto listeners = GetListeners(); + CALL_INPUT_EVENT_LISTENER(listeners, OnAxisEvent, axisEvent); + } protected: - void NotifySizeChange(const WSRect& rect, SizeChangeReason reason); + void NotifySizeChange(const WSRect& rect, SizeChangeReason reason) + { + auto sizeChangeListeners = GetListeners(); + for (auto& listener : sizeChangeListeners) { + if (!listener.expired()) { + listener.lock()->OnSizeChange(rect, reason); + } + } + } + inline void NotifyAfterForeground() { auto sessionStateListeners = GetListeners(); @@ -133,6 +159,7 @@ private: template using EnableIfSame = typename std::enable_if, Ret>::type; + template inline EnableIfSame>> GetListeners() @@ -161,36 +188,23 @@ private: } template - inline EnableIfSame>> GetListeners() - { - std::vector> pointerEventListeners; - { - std::lock_guard lock(mutex_); - for (auto& listener : pointerEventListeners_) { - pointerEventListeners.push_back(listener); - } - } - return pointerEventListeners; - } - - template - inline EnableIfSame>> GetListeners() + inline EnableIfSame>> GetListeners() { - std::vector> keyEventListeners; + std::vector> inputEventListeners; { std::lock_guard lock(mutex_); - for (auto& listener : keyEventListeners_) { - keyEventListeners.push_back(listener); + for (auto& listener : inputEventListeners_) { + inputEventListeners.push_back(listener); } } - return keyEventListeners; + return inputEventListeners; } std::recursive_mutex mutex_; - std::vector> pointerEventListeners_; - std::vector> keyEventListeners_; std::vector> sessionStageStateListeners_; std::vector> sizeChangeListeners_; + std::vector> inputEventListeners_; }; } // namespace OHOS::Rosen + #endif // OHOS_ROSEN_WINDOW_SCENE_SESSION_STAGE_H diff --git a/window_scene/session/container/src/extension_session_stage.cpp b/window_scene/session/container/src/extension_session_stage.cpp index 3cc072df617a04bd8467ecb21607305880d5990a..8c8388b9bc6cc6e79eaf3358b2b0685d12737e87 100644 --- a/window_scene/session/container/src/extension_session_stage.cpp +++ b/window_scene/session/container/src/extension_session_stage.cpp @@ -19,7 +19,7 @@ #include "window_manager_hilog.h" namespace OHOS::Rosen { namespace { - constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, HILOG_DOMAIN_WINDOW, "ExtensionSessionStage" }; +constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, HILOG_DOMAIN_WINDOW, "ExtensionSessionStage" }; } ExtensionSessionStage::ExtensionSessionStage(const sptr& extensionSession) : SessionStage(extensionSession) {} diff --git a/window_scene/session/container/src/scene_session_stage.cpp b/window_scene/session/container/src/scene_session_stage.cpp new file mode 100644 index 0000000000000000000000000000000000000000..99eeb94ee51d5b4f5a5ec753f01e121816b4448c --- /dev/null +++ b/window_scene/session/container/src/scene_session_stage.cpp @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "session/container/include/scene_session_stage.h" + +#include "session/container/include/window_event_channel.h" +#include "window_manager_hilog.h" +namespace OHOS::Rosen { +namespace { +constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, HILOG_DOMAIN_WINDOW, "SceneSessionStage" }; +} + +SceneSessionStage::SceneSessionStage(const sptr& sceneSession) : SessionStage(sceneSession) {} + +WSError SceneSessionStage::Connect() +{ + if (session_ == nullptr) { + WLOGFE("session is invalid"); + return WSError::WS_ERROR_NULLPTR; + } + sptr sceneSessionStage(this); + sptr eventChannel(new WindowEventChannel(sceneSessionStage)); + return session_->Connect(sceneSessionStage, eventChannel); +} + +WSError SceneSessionStage::Recover() +{ + if (session_ == nullptr) { + WLOGFE("sceneSession is invalid"); + return WSError::WS_ERROR_NULLPTR; + } + return session_->Recover(); +} + +WSError SceneSessionStage::Maximize() +{ + if (session_ == nullptr) { + WLOGFE("sceneSession is invalid"); + return WSError::WS_ERROR_NULLPTR; + } + return session_->Maximize(); +} +} // namespace OHOS::Rosen \ No newline at end of file diff --git a/window_scene/session/container/src/session_stage.cpp b/window_scene/session/container/src/session_stage.cpp index 585aa03664cea6000193b272783d8bb855c9d926..b2983ba4753b61122aacdb9835e8f3c1d077f492 100644 --- a/window_scene/session/container/src/session_stage.cpp +++ b/window_scene/session/container/src/session_stage.cpp @@ -20,8 +20,9 @@ namespace OHOS::Rosen { namespace { - constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "SessionStage"}; +constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, HILOG_DOMAIN_WINDOW, "SessionStage" }; } + SessionStage::SessionStage(const sptr& session) : session_(session) {} bool SessionStage::RegisterSessionStageStateListener(const std::shared_ptr& listener) @@ -44,24 +45,14 @@ bool SessionStage::UnregisterSizeChangeListener(const std::shared_ptr& listener) -{ - return RegisterListenerLocked(pointerEventListeners_, listener); -} - -bool SessionStage::UnregisterPointerEventListener(const std::shared_ptr& listener) -{ - return UnregisterListenerLocked(pointerEventListeners_, listener); -} - -bool SessionStage::RegisterKeyEventListener(const std::shared_ptr& listener) +bool SessionStage::RegisterInputEventListener(const std::shared_ptr& listener) { - return RegisterListenerLocked(keyEventListeners_, listener); + return RegisterListenerLocked(inputEventListeners_, listener); } -bool SessionStage::UnregisterKeyEventListener(const std::shared_ptr& listener) +bool SessionStage::UnregisterInputEventListener(const std::shared_ptr& listener) { - return UnregisterListenerLocked(keyEventListeners_, listener); + return UnregisterListenerLocked(inputEventListeners_, listener); } template @@ -74,7 +65,7 @@ bool SessionStage::RegisterListenerLocked(std::vector>& holde std::lock_guard lock(mutex_); if (std::find(holder.begin(), holder.end(), listener) != holder.end()) { WLOGFW("Listener already registered"); - return true; + return false; } holder.emplace_back(listener); return true; @@ -94,36 +85,6 @@ bool SessionStage::UnregisterListenerLocked(std::vector>& hol return true; } -void SessionStage::NotifySizeChange(const WSRect& rect, SizeChangeReason reason) -{ - auto sizeChangeListeners = GetListeners(); - for (auto& listener : sizeChangeListeners) { - if (!listener.expired()) { - listener.lock()->OnSizeChange(rect, reason); - } - } -} - -void SessionStage::NotifyPointerEvent(const std::shared_ptr& pointerEvent) -{ - auto pointerEventListeners = GetListeners(); - for (auto& listener : pointerEventListeners) { - if (!listener.expired()) { - listener.lock()->OnPointerEvent(pointerEvent); - } - } -} - -void SessionStage::NotifyKeyEvent(const std::shared_ptr& keyEvent) -{ - auto keyEventListeners = GetListeners(); - for (auto& listener : keyEventListeners) { - if (!listener.expired()) { - listener.lock()->OnKeyEvent(keyEvent); - } - } -} - WSError SessionStage::Connect() { if (session_ == nullptr) { diff --git a/window_scene/session/container/src/zidl/session_stage_proxy.cpp b/window_scene/session/container/src/zidl/session_stage_proxy.cpp index 431a2e197f6cec9cbf7caea725e72d49f157be55..09adad1ee56f7be69cc010be54733d97efce4697 100644 --- a/window_scene/session/container/src/zidl/session_stage_proxy.cpp +++ b/window_scene/session/container/src/zidl/session_stage_proxy.cpp @@ -23,7 +23,7 @@ namespace OHOS::Rosen { namespace { - constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "SessionStageProxy"}; +constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "SessionStageProxy"}; } WSError SessionStageProxy::SetActive(bool active) diff --git a/window_scene/session/container/src/zidl/session_stage_stub.cpp b/window_scene/session/container/src/zidl/session_stage_stub.cpp index 57b84e0cb26f05efe42d1ac2bee2b82b0d21873c..ac2ba8b1f822cb271fa9796e463ea2d5111e7dcd 100644 --- a/window_scene/session/container/src/zidl/session_stage_stub.cpp +++ b/window_scene/session/container/src/zidl/session_stage_stub.cpp @@ -21,7 +21,7 @@ namespace OHOS::Rosen { namespace { - constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "SessionStageStub"}; +constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "SessionStageStub"}; } const std::map SessionStageStub::stubFuncMap_{ diff --git a/window_scene/session/container/src/zidl/window_event_channel_proxy.cpp b/window_scene/session/container/src/zidl/window_event_channel_proxy.cpp index 9be8bb61cecd23ed397e14ce44f4e84edbff2df4..f29648bd35d776c4badfdd3fdeeb2486b8f3a091 100644 --- a/window_scene/session/container/src/zidl/window_event_channel_proxy.cpp +++ b/window_scene/session/container/src/zidl/window_event_channel_proxy.cpp @@ -26,7 +26,7 @@ namespace OHOS::Rosen { namespace { - constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowEventChannelProxy"}; +constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowEventChannelProxy"}; } WSError WindowEventChannelProxy::TransferKeyEvent(const std::shared_ptr& keyEvent) diff --git a/window_scene/session/container/src/zidl/window_event_channel_stub.cpp b/window_scene/session/container/src/zidl/window_event_channel_stub.cpp index 2cd0c358b46c267d6ad543897002c1fa58c0b9bd..496054c4fca56113435b54237aa9c67dfb219e6d 100644 --- a/window_scene/session/container/src/zidl/window_event_channel_stub.cpp +++ b/window_scene/session/container/src/zidl/window_event_channel_stub.cpp @@ -24,7 +24,7 @@ namespace OHOS::Rosen { namespace { - constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowEventChannelStub"}; +constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowEventChannelStub"}; } const std::map WindowEventChannelStub::stubFuncMap_{ diff --git a/window_scene/session/host/include/root_scene_session.h b/window_scene/session/host/include/root_scene_session.h new file mode 100644 index 0000000000000000000000000000000000000000..a49de2c158d68846093a43ee1c0a15d4ea70123d --- /dev/null +++ b/window_scene/session/host/include/root_scene_session.h @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_ROSEN_WINDOW_SCENE_ROOT_SCENE_SESSION_H +#define OHOS_ROSEN_WINDOW_SCENE_ROOT_SCENE_SESSION_H + +#include "interfaces/include/ws_common.h" +#include "scene_session.h" + +namespace OHOS::AbilityRuntime { +class Context; +} + +class NativeEngine; +class NativeValue; + +namespace OHOS::Rosen { +class RootSceneSession : public RefBase { +public: + using LoadContentFunc = + std::function; + RootSceneSession() = default; + ~RootSceneSession() = default; + + void SetPendingSessionActivationEventListener(const NotifyPendingSessionActivationFunc& func); + void SetLoadContentFunc(const LoadContentFunc& loadContentFunc); + void LoadContent( + const std::string& contentUrl, NativeEngine* engine, NativeValue* storage, AbilityRuntime::Context* context); + +private: + LoadContentFunc loadContentFunc_; + NotifyPendingSessionActivationFunc pendingSessionActivationFunc_; +}; +} // namespace OHOS::Rosen + +#endif // OHOS_ROSEN_WINDOW_SCENE_ROOT_SCENE_SESSION_H diff --git a/window_scene/session/host/include/scene_session.h b/window_scene/session/host/include/scene_session.h new file mode 100644 index 0000000000000000000000000000000000000000..aa54ff44e77568fe483b65897b4f0a55ba0b79bf --- /dev/null +++ b/window_scene/session/host/include/scene_session.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_ROSEN_WINDOW_SCENE_SCENE_SESSION_H +#define OHOS_ROSEN_WINDOW_SCENE_SCENE_SESSION_H + +#include "interfaces/include/ws_common.h" +#include "session/host/include/session.h" + +namespace OHOS::Rosen { +class SceneSession : public Session { +public: + SceneSession(const SessionInfo& info); + ~SceneSession() = default; + + WSError Recover() override; + WSError Maximize() override; +}; +} // namespace OHOS::Rosen + +#endif // OHOS_ROSEN_WINDOW_SCENE_SCENE_SESSION_H diff --git a/window_scene/session/host/include/session.h b/window_scene/session/host/include/session.h index 8385ce862d4ebc1f0a4a05e587c71c1227e9d89a..a585d50f90549adbaee88023b889e359796ea8f7 100644 --- a/window_scene/session/host/include/session.h +++ b/window_scene/session/host/include/session.h @@ -31,15 +31,20 @@ class KeyEvent; class AxisEvent; } // namespace OHOS::MMI +namespace OHOS::Media { +class PixelMap; +} + namespace OHOS::Rosen { class RSSurfaceNode; using NotifyPendingSessionActivationFunc = std::function; class ILifecycleListener { public: - virtual void OnForeground() {}; - virtual void OnBackground() {}; + virtual void OnForeground() = 0; + virtual void OnBackground() = 0; }; + class Session : public SessionStub, public virtual RefBase { public: explicit Session(const SessionInfo& info); @@ -47,13 +52,15 @@ public: void SetPersistentId(uint64_t persistentId); uint64_t GetPersistentId() const; + std::shared_ptr GetSurfaceNode() const; + std::shared_ptr GetSnapshot() const; + SessionState GetSessionState() const; virtual WSError SetActive(bool active); virtual WSError UpdateRect(const WSRect& rect, SizeChangeReason reason); - WSError Connect( - const sptr& sessionStage, const sptr& eventChannel) override; + WSError Connect(const sptr& sessionStage, const sptr& eventChannel) override; WSError Foreground() override; WSError Background() override; WSError Disconnect() override; @@ -62,15 +69,19 @@ public: WSError Recover() override; WSError Maximize() override; - // for window event + virtual void NotifyForeground(); + virtual void NotifyBackground(); + WSError TransferPointerEvent(const std::shared_ptr& pointerEvent); WSError TransferKeyEvent(const std::shared_ptr& keyEvent); + bool RegisterLifecycleListener(const std::shared_ptr& listener); + bool UnregisterLifecycleListener(const std::shared_ptr& listener); + const SessionInfo& GetSessionInfo() const; void SetPendingSessionActivationEventListener(const NotifyPendingSessionActivationFunc& func); protected: - SessionState GetSessionState() const; void UpdateSessionState(SessionState state); bool IsSessionValid() const; bool isActive_ = false; @@ -80,13 +91,38 @@ protected: NotifyPendingSessionActivationFunc pendingSessionActivationFunc_; private: + template + bool RegisterListenerLocked(std::vector>& holder, const std::shared_ptr& listener); + template + bool UnregisterListenerLocked(std::vector>& holder, const std::shared_ptr& listener); + + template + using EnableIfSame = typename std::enable_if, Ret>::type; + template + inline EnableIfSame>> GetListeners() + { + std::vector> lifecycleListeners; + { + std::lock_guard lock(mutex_); + for (auto& listener : lifecycleListeners_) { + lifecycleListeners.push_back(listener); + } + } + return lifecycleListeners; + } + std::shared_ptr CreateSurfaceNode(std::string name); + std::shared_ptr Snapshot(); uint64_t persistentId_ = INVALID_SESSION_ID; std::shared_ptr surfaceNode_ = nullptr; SessionState state_ = SessionState::STATE_DISCONNECT; + std::recursive_mutex mutex_; + std::vector> lifecycleListeners_; sptr windowEventChannel_ = nullptr; + + std::shared_ptr snapshot_; }; } // namespace OHOS::Rosen #endif // OHOS_ROSEN_WINDOW_SCENE_SESSION_H diff --git a/window_scene/session/host/include/zidl/session_interface.h b/window_scene/session/host/include/zidl/session_interface.h index f23581c0891cddf6c06702abd3a344e665ee1fa0..53bad049b41cd612889fcd7f3b6ce7f83be9386e 100644 --- a/window_scene/session/host/include/zidl/session_interface.h +++ b/window_scene/session/host/include/zidl/session_interface.h @@ -17,6 +17,7 @@ #define OHOS_ROSEN_WINDOW_SCENE_SESSION_INTERFACE_H #include + #include "interfaces/include/ws_common.h" #include "session/container/include/zidl/session_stage_interface.h" #include "session/container/include/zidl/window_event_channel_interface.h" diff --git a/window_scene/session/host/src/root_scene_session.cpp b/window_scene/session/host/src/root_scene_session.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ba8c2eabae1aaff3ed817c01120ee0072866982f --- /dev/null +++ b/window_scene/session/host/src/root_scene_session.cpp @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "session/host/include/root_scene_session.h" + +namespace OHOS::Rosen { +void RootSceneSession::SetPendingSessionActivationEventListener(const NotifyPendingSessionActivationFunc& func) +{ + pendingSessionActivationFunc_ = func; +} + +void RootSceneSession::SetLoadContentFunc(const LoadContentFunc& loadContentFunc) +{ + loadContentFunc_ = loadContentFunc; +} + +void RootSceneSession::LoadContent( + const std::string& contentUrl, NativeEngine* engine, NativeValue* storage, AbilityRuntime::Context* context) +{ + if (loadContentFunc_) { + loadContentFunc_(contentUrl, engine, storage, context); + } +} +} // namespace OHOS::Rosen diff --git a/window_scene/session/host/src/scene_session.cpp b/window_scene/session/host/src/scene_session.cpp new file mode 100644 index 0000000000000000000000000000000000000000..247f28d2d940c7384883d608ff5d9386ef39f92d --- /dev/null +++ b/window_scene/session/host/src/scene_session.cpp @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "session/host/include/scene_session.h" + +#include "window_manager_hilog.h" + +namespace OHOS::Rosen { +namespace { +constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, HILOG_DOMAIN_WINDOW, "SceneSession" }; +} + +SceneSession::SceneSession(const SessionInfo& info) : Session(info) {} + +WSError SceneSession::Recover() +{ + WLOGFI("Recover session, id: %{public}" PRIu64 ", state: %{public}u", GetPersistentId(), + static_cast(GetSessionState())); + if (!IsSessionValid()) { + return WSError::WS_ERROR_INVALID_SESSION; + } + return WSError::WS_OK; +} + +WSError SceneSession::Maximize() +{ + WLOGFI("Maximum session id: %{public}" PRIu64 " state: %{public}u", GetPersistentId(), + static_cast(GetSessionState())); + if (!IsSessionValid()) { + return WSError::WS_ERROR_INVALID_SESSION; + } + return WSError::WS_OK; +} +} // namespace OHOS::Rosen \ No newline at end of file diff --git a/window_scene/session/host/src/session.cpp b/window_scene/session/host/src/session.cpp index 91425ff860798ff1ab80c9323d6947891980e985..b0bcf1a61af3a438eb42dcefa01e3d11d3182266 100644 --- a/window_scene/session/host/src/session.cpp +++ b/window_scene/session/host/src/session.cpp @@ -15,8 +15,9 @@ #include "session/host/include/session.h" +#include "surface_capture_future.h" +#include #include - #include "window_manager_hilog.h" namespace OHOS::Rosen { @@ -53,6 +54,66 @@ const SessionInfo& Session::GetSessionInfo() const return sessionInfo_; } +bool Session::RegisterLifecycleListener(const std::shared_ptr& listener) +{ + return RegisterListenerLocked(lifecycleListeners_, listener); +} + +bool Session::UnregisterLifecycleListener(const std::shared_ptr& listener) +{ + return UnregisterListenerLocked(lifecycleListeners_, listener); +} + +template +bool Session::RegisterListenerLocked(std::vector>& holder, const std::shared_ptr& listener) +{ + if (listener == nullptr) { + WLOGFE("listener is nullptr"); + return false; + } + std::lock_guard lock(mutex_); + if (std::find(holder.begin(), holder.end(), listener) != holder.end()) { + WLOGFE("Listener already registered"); + return false; + } + holder.emplace_back(listener); + return true; +} + +template +bool Session::UnregisterListenerLocked(std::vector>& holder, const std::shared_ptr& listener) +{ + if (listener == nullptr) { + WLOGFE("listener could not be null"); + return false; + } + std::lock_guard lock(mutex_); + holder.erase(std::remove_if(holder.begin(), holder.end(), + [listener](std::shared_ptr registeredListener) { return registeredListener == listener; }), + holder.end()); + return true; +} + +void Session::NotifyForeground() +{ + auto lifecycleListeners = GetListeners(); + for (auto& listener : lifecycleListeners) { + if (!listener.expired()) { + listener.lock()->OnForeground(); + } + } +} + +void Session::NotifyBackground() +{ + auto lifecycleListeners = GetListeners(); + for (auto& listener : lifecycleListeners) { + if (!listener.expired()) { + listener.lock()->OnBackground(); + } + } +} + SessionState Session::GetSessionState() const { return state_; @@ -86,7 +147,7 @@ RSSurfaceNode::SharedPtr Session::CreateSurfaceNode(std::string name) } struct RSSurfaceNodeConfig rsSurfaceNodeConfig; rsSurfaceNodeConfig.SurfaceNodeName = name; - return RSSurfaceNode::Create(rsSurfaceNodeConfig, RSSurfaceNodeType::EXTENSION_ABILITY_NODE); + return RSSurfaceNode::Create(rsSurfaceNodeConfig); } WSError Session::UpdateRect(const WSRect& rect, SizeChangeReason reason) @@ -98,7 +159,6 @@ WSError Session::UpdateRect(const WSRect& rect, SizeChangeReason reason) return WSError::WS_ERROR_INVALID_SESSION; } sessionStage_->UpdateRect(rect, reason); - winRect_ = rect; return WSError::WS_OK; } @@ -133,12 +193,11 @@ WSError Session::Foreground() return WSError::WS_ERROR_INVALID_SESSION; } + UpdateSessionState(SessionState::STATE_FOREGROUND); if (!isActive_) { SetActive(true); - UpdateSessionState(SessionState::STATE_ACTIVE); - } else { - UpdateSessionState(SessionState::STATE_FOREGROUND); } + NotifyForeground(); return WSError::WS_OK; } @@ -152,6 +211,9 @@ WSError Session::Background() return WSError::WS_ERROR_INVALID_SESSION; } UpdateSessionState(SessionState::STATE_BACKGROUND); + + snapshot_ = Snapshot(); + NotifyBackground(); return WSError::WS_OK; } @@ -215,7 +277,6 @@ WSError Session::Maximize() return WSError::WS_OK; } -// for window event WSError Session::TransferPointerEvent(const std::shared_ptr& pointerEvent) { WLOGFD("Session TransferPointEvent"); @@ -223,18 +284,34 @@ WSError Session::TransferPointerEvent(const std::shared_ptr& WLOGFE("windowEventChannel_ is null"); return WSError::WS_ERROR_NULLPTR; } - windowEventChannel_->TransferPointerEvent(pointerEvent); - return WSError::WS_OK; + return windowEventChannel_->TransferPointerEvent(pointerEvent); } WSError Session::TransferKeyEvent(const std::shared_ptr& keyEvent) { - WLOGFD("Session TransferPointEvent"); + WLOGFD("Session TransferKeyEvent"); if (!windowEventChannel_) { WLOGFE("windowEventChannel_ is null"); return WSError::WS_ERROR_NULLPTR; } - windowEventChannel_->TransferKeyEvent(keyEvent); - return WSError::WS_OK; + return windowEventChannel_->TransferKeyEvent(keyEvent); +} + +std::shared_ptr Session::GetSnapshot() const +{ + return snapshot_; +} + +std::shared_ptr Session::Snapshot() +{ + auto callback = std::make_shared(); + RSInterfaces::GetInstance().TakeSurfaceCapture(surfaceNode_, callback); + auto pixelMap = callback->GetResult(2000); // wait for <= 2000ms + if (pixelMap != nullptr) { + WLOGFD("Save pixelMap WxH = %{public}dx%{public}d", pixelMap->GetWidth(), pixelMap->GetHeight()); + } else { + WLOGFE("Failed to get pixelMap, return nullptr"); + } + return pixelMap; } } // namespace OHOS::Rosen diff --git a/window_scene/session/screen/include/screen_property.h b/window_scene/session/screen/include/screen_property.h new file mode 100644 index 0000000000000000000000000000000000000000..132de619ec33face968b4627f86c42acb4760674 --- /dev/null +++ b/window_scene/session/screen/include/screen_property.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_ROSEN_WINDOW_SCENE_SCREEN_PROPERTY_H +#define OHOS_ROSEN_WINDOW_SCENE_SCREEN_PROPERTY_H + +#include "common/rs_rect.h" + +namespace OHOS::Rosen { +class ScreenProperty { +public: + ScreenProperty() = default; + ~ScreenProperty() = default; + + void SetRotation(float rotation); + float GetRotation() const; + + void SetBounds(const RRect& bounds); + RRect GetBounds() const; + +private: + float rotation_ { 0.0f }; + RRect bounds_; +}; +} // namespace OHOS::Rosen + +#endif // OHOS_ROSEN_WINDOW_SCENE_SCREEN_PROPERTY_H diff --git a/window_scene/session/screen/include/screen_session.h b/window_scene/session/screen/include/screen_session.h new file mode 100644 index 0000000000000000000000000000000000000000..0f34908059a9918ed46d73fd3727fdaf003dae1c --- /dev/null +++ b/window_scene/session/screen/include/screen_session.h @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_ROSEN_WINDOW_SCENE_SCREEN_SESSION_H +#define OHOS_ROSEN_WINDOW_SCENE_SCREEN_SESSION_H + +#include +#include +#include + +#include "screen_property.h" + +namespace OHOS::Rosen { +class IScreenChangeListener : public RefBase { +public: + IScreenChangeListener() = default; + virtual ~IScreenChangeListener() = default; + + virtual void OnConnect() = 0; + virtual void OnDisconnect() = 0; + virtual void OnPropertyChange(const ScreenProperty& newProperty) = 0; +}; + +enum class ScreenState : int32_t { + INIT, + CONNECTION, + DISCONNECTION, +}; + +class ScreenSession : public RefBase { +public: + explicit ScreenSession(ScreenId screenId, const ScreenProperty& property); + ~ScreenSession() = default; + + void RegisterScreenChangeListener(IScreenChangeListener* screenChangeListener); + void UnregisterScreenChangeListener(IScreenChangeListener* screenChangeListener); + + ScreenId GetScreenId(); + ScreenProperty GetScreenProperty() const; + + void Connect(); + void Disconnect(); + +private: + ScreenId screenId_; + ScreenProperty property_; + ScreenState screenState_ { ScreenState::INIT }; + std::vector screenChangeListenerList_; +}; +} // namespace OHOS::Rosen + +#endif // OHOS_ROSEN_WINDOW_SCENE_SCREEN_SESSION_H diff --git a/window_scene/session/screen/src/screen_property.cpp b/window_scene/session/screen/src/screen_property.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f2ba5d003f166db5ce850fb6754cfd3980e3f3c6 --- /dev/null +++ b/window_scene/session/screen/src/screen_property.cpp @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "session/screen/include/screen_property.h" + +namespace OHOS::Rosen { +void ScreenProperty::SetRotation(float rotation) +{ + rotation_ = rotation; +} + +float ScreenProperty::GetRotation() const +{ + return rotation_; +} + +void ScreenProperty::SetBounds(const RRect& bounds) +{ + bounds_ = bounds; +} + +RRect ScreenProperty::GetBounds() const +{ + return bounds_; +} +} // namespace OHOS::Rosen diff --git a/window_scene/session/screen/src/screen_session.cpp b/window_scene/session/screen/src/screen_session.cpp new file mode 100644 index 0000000000000000000000000000000000000000..68df6f71cf0de63a3f670869388d0b025b429428 --- /dev/null +++ b/window_scene/session/screen/src/screen_session.cpp @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "session/screen/include/screen_session.h" + +#include "window_manager_hilog.h" + +namespace OHOS::Rosen { +namespace { +constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, HILOG_DOMAIN_WINDOW, "ScreenSession" }; +} + +ScreenSession::ScreenSession(ScreenId screenId, const ScreenProperty& property) + : screenId_(screenId), property_(property) +{} + +void ScreenSession::RegisterScreenChangeListener(IScreenChangeListener* screenChangeListener) +{ + if (screenChangeListener == nullptr) { + WLOGFE("Failed to register screen change listener, listener is null!"); + return; + } + + if (std::find(screenChangeListenerList_.begin(), screenChangeListenerList_.end(), screenChangeListener) != + screenChangeListenerList_.end()) { + WLOGFE("Repeat to register screen change listener!"); + return; + } + + screenChangeListenerList_.emplace_back(screenChangeListener); + if (screenState_ == ScreenState::CONNECTION) { + screenChangeListener->OnConnect(); + } +} + +void ScreenSession::UnregisterScreenChangeListener(IScreenChangeListener* screenChangeListener) +{ + if (screenChangeListener == nullptr) { + WLOGFE("Failed to unregister screen change listener, listener is null!"); + return; + } + + screenChangeListenerList_.erase( + std::remove_if(screenChangeListenerList_.begin(), screenChangeListenerList_.end(), + [screenChangeListener](IScreenChangeListener* listener) { return screenChangeListener == listener; }), + screenChangeListenerList_.end()); +} + +ScreenId ScreenSession::GetScreenId() +{ + return screenId_; +} + +ScreenProperty ScreenSession::GetScreenProperty() const +{ + return property_; +} + +void ScreenSession::Connect() +{ + screenState_ = ScreenState::CONNECTION; + for (auto& listener : screenChangeListenerList_) { + listener->OnConnect(); + } +} + +void ScreenSession::Disconnect() +{ + screenState_ = ScreenState::DISCONNECTION; + for (auto& listener : screenChangeListenerList_) { + listener->OnDisconnect(); + } +} + +} // namespace OHOS::Rosen diff --git a/window_scene/session_manager/include/session_manager_base.h b/window_scene/session_manager/include/session_manager_base.h index eb4fc4c753b2bc405d1aa8df0ace3fce3b983bd4..bdecef186c7ae94ec4b9b1f185fc4caf83e999a7 100644 --- a/window_scene/session_manager/include/session_manager_base.h +++ b/window_scene/session_manager/include/session_manager_base.h @@ -16,6 +16,8 @@ #ifndef OHOS_ROSEN_WINDOW_SCENE_SESSION_MANAGER_BASE_H #define OHOS_ROSEN_WINDOW_SCENE_SESSION_MANAGER_BASE_H +#include + #include "common/include/message_scheduler.h" #include "interfaces/include/ws_common.h" namespace OHOS::Rosen { diff --git a/wmserver/BUILD.gn b/wmserver/BUILD.gn index bf8beadd814c91ad39418664c7d5a2e04b6d2514..0300258242cc32de415a80866bcf4c1ab06636dc 100644 --- a/wmserver/BUILD.gn +++ b/wmserver/BUILD.gn @@ -12,6 +12,8 @@ # limitations under the License. import("//build/ohos.gni") +import("//foundation/window/window_manager/windowmanager_aafwk.gni") + config("libwms_config") { visibility = [ ":*" ] @@ -109,6 +111,7 @@ ohos_shared_library("libwms") { "ipc:ipc_single", "power_manager:powermgr_client", "safwk:system_ability_fwk", + "window_manager:libwsutils", ] if (is_standard_system) { diff --git a/wmserver/src/window_manager_service.cpp b/wmserver/src/window_manager_service.cpp index 628f1eb658546a3f337934d0ab8ae125140b3b50..2716dacbd6cb605394bdceb75352ac360b0d567b 100644 --- a/wmserver/src/window_manager_service.cpp +++ b/wmserver/src/window_manager_service.cpp @@ -25,6 +25,7 @@ #include #include #include +#include "scene_board_judgement.h" #include #include #include "xcollie/watchdog.h" @@ -55,7 +56,8 @@ namespace { } WM_IMPLEMENT_SINGLE_INSTANCE(WindowManagerService) -const bool REGISTER_RESULT = SystemAbility::MakeAndRegisterAbility(&SingletonContainer::Get()); +const bool REGISTER_RESULT = SceneBoardJudgement::IsSceneBoardEnabled() ? false : + SystemAbility::MakeAndRegisterAbility(&SingletonContainer::Get()); WindowManagerService::WindowManagerService() : SystemAbility(WINDOW_MANAGER_SERVICE_ID, true), rsInterface_(RSInterfaces::GetInstance()),