将surfaceNode创建移至应用端

Signed-off-by: chyyy0213 <chenhaiying3@huawei.com>
Change-Id: I4876776547e2bbd3b526dcc905463a1d1786331f
Signed-off-by: chyyy0213 <chenhaiying3@huawei.com>
This commit is contained in:
chyyy0213 2023-05-06 18:17:14 +08:00
parent e711265b24
commit 1526b3ee4d
15 changed files with 47 additions and 74 deletions

View File

@ -35,12 +35,12 @@ public:
};
static std::shared_ptr<UIWindow> CreateWindowScene(const std::shared_ptr<AbilityRuntime::Context>& context,
const sptr<Rosen::ISession>& iSession, const std::shared_ptr<Rosen::RSSurfaceNode>& surfaceNode) {
const sptr<Rosen::ISession>& iSession) {
return nullptr;
};
static std::shared_ptr<UIWindow> CreateWindowExtension(const std::shared_ptr<AbilityRuntime::Context>& context,
const sptr<Rosen::ISession>& iSession, const std::shared_ptr<Rosen::RSSurfaceNode>& surfaceNode) {
const sptr<Rosen::ISession>& iSession) {
return nullptr;
};

View File

@ -25,8 +25,6 @@ class ExtensionSessionStage : public SessionStage {
public:
ExtensionSessionStage(const sptr<ISession>& extensionSession);
~ExtensionSessionStage() = default;
WSError Connect() override;
};
} // namespace OHOS::Rosen

View File

@ -25,7 +25,6 @@ public:
SceneSessionStage(const sptr<ISession>& sceneSession);
~SceneSessionStage() = default;
WSError Connect() override;
WSError Recover() override;
WSError Maximize() override;
};

View File

@ -75,7 +75,7 @@ public:
explicit SessionStage(const sptr<ISession>& session);
virtual ~SessionStage() = default;
virtual WSError Connect();
virtual WSError Connect(const std::shared_ptr<RSSurfaceNode>& surfaceNode);
virtual WSError Foreground();
virtual WSError Background();
virtual WSError Disconnect();

View File

@ -15,24 +15,8 @@
#include "session/container/include/extension_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, "ExtensionSessionStage" };
}
ExtensionSessionStage::ExtensionSessionStage(const sptr<ISession>& extensionSession) : SessionStage(extensionSession) {}
WSError ExtensionSessionStage::Connect()
ExtensionSessionStage::ExtensionSessionStage(const sptr<ISession>& extensionSession) : SessionStage(extensionSession)
{
if (session_ == nullptr) {
WLOGFE("session is invalid");
return WSError::WS_ERROR_NULLPTR;
}
sptr<ExtensionSessionStage> extensionSessionStage(this);
sptr<IWindowEventChannel> eventChannel(new WindowEventChannel(extensionSessionStage));
return session_->Connect(extensionSessionStage, eventChannel);
}
} // namespace OHOS::Rosen

View File

@ -24,17 +24,6 @@ constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, HILOG_DOMAIN_WINDOW, "SceneS
SceneSessionStage::SceneSessionStage(const sptr<ISession>& sceneSession) : SessionStage(sceneSession) {}
WSError SceneSessionStage::Connect()
{
if (session_ == nullptr) {
WLOGFE("session is invalid");
return WSError::WS_ERROR_NULLPTR;
}
sptr<SceneSessionStage> sceneSessionStage(this);
sptr<IWindowEventChannel> eventChannel(new WindowEventChannel(sceneSessionStage));
return session_->Connect(sceneSessionStage, eventChannel);
}
WSError SceneSessionStage::Recover()
{
if (session_ == nullptr) {
@ -52,4 +41,4 @@ WSError SceneSessionStage::Maximize()
}
return session_->Maximize();
}
} // namespace OHOS::Rosen
} // namespace OHOS::Rosen

View File

@ -85,7 +85,7 @@ bool SessionStage::UnregisterListenerLocked(std::vector<std::shared_ptr<T>>& hol
return true;
}
WSError SessionStage::Connect()
WSError SessionStage::Connect(const std::shared_ptr<RSSurfaceNode>& surfaceNode)
{
if (session_ == nullptr) {
WLOGFE("session is invalid");
@ -93,7 +93,7 @@ WSError SessionStage::Connect()
}
sptr<SessionStage> sessionStage(this);
sptr<IWindowEventChannel> eventChannel(new WindowEventChannel(sessionStage));
return session_->Connect(sessionStage, eventChannel);
return session_->Connect(sessionStage, eventChannel, surfaceNode);
}
WSError SessionStage::Foreground()

View File

@ -41,6 +41,7 @@ using NotifyPendingSessionActivationFunc = std::function<void(const SessionInfo&
class ILifecycleListener {
public:
virtual void OnConnect() = 0;
virtual void OnForeground() = 0;
virtual void OnBackground() = 0;
};
@ -60,7 +61,8 @@ public:
virtual WSError SetActive(bool active);
virtual WSError UpdateRect(const WSRect& rect, SizeChangeReason reason);
WSError Connect(const sptr<ISessionStage>& sessionStage, const sptr<IWindowEventChannel>& eventChannel) override;
WSError Connect(const sptr<ISessionStage>& sessionStage, const sptr<IWindowEventChannel>& eventChannel,
const std::shared_ptr<RSSurfaceNode>& surfaceNode) override;
WSError Foreground() override;
WSError Background() override;
WSError Disconnect() override;
@ -69,8 +71,9 @@ public:
WSError Recover() override;
WSError Maximize() override;
virtual void NotifyForeground();
virtual void NotifyBackground();
void NotifyConnect();
void NotifyForeground();
void NotifyBackground();
WSError TransferPointerEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent);
WSError TransferKeyEvent(const std::shared_ptr<MMI::KeyEvent>& keyEvent);

View File

@ -17,12 +17,12 @@
#define OHOS_ROSEN_WINDOW_SCENE_SESSION_INTERFACE_H
#include <iremote_broker.h>
#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"
namespace OHOS::Rosen {
class RSSurfaceNode;
class ISession : public IRemoteBroker {
public:
DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.ISession");
@ -39,7 +39,8 @@ public:
TRANS_ID_RECOVER = 100,
TRANS_ID_MAXIMIZE,
};
virtual WSError Connect(const sptr<ISessionStage>& sessionStage, const sptr<IWindowEventChannel>& eventChannel) = 0;
virtual WSError Connect(const sptr<ISessionStage>& sessionStage, const sptr<IWindowEventChannel>& eventChannel,
const std::shared_ptr<RSSurfaceNode>& surfaceNode) = 0;
virtual WSError Foreground() = 0;
virtual WSError Background() = 0;
virtual WSError Disconnect() = 0;
@ -50,4 +51,4 @@ public:
virtual WSError Maximize() = 0;
};
} // namespace OHOS::Rosen
#endif // OHOS_ROSEN_WINDOW_SCENE_SESSION_INTERFACE_H
#endif // OHOS_ROSEN_WINDOW_SCENE_SESSION_INTERFACE_H

View File

@ -30,8 +30,8 @@ public:
WSError Foreground() override;
WSError Background() override;
WSError Disconnect() override;
WSError Connect(const sptr<ISessionStage>& sessionStage,
const sptr<IWindowEventChannel>& eventChannel) override;
WSError Connect(const sptr<ISessionStage>& sessionStage, const sptr<IWindowEventChannel>& eventChannel,
const std::shared_ptr<RSSurfaceNode>& surfaceNode) override;
WSError PendingSessionActivation(const SessionInfo& info) override;
WSError Recover() override;

View File

@ -23,15 +23,10 @@
namespace OHOS::Rosen {
namespace {
constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, HILOG_DOMAIN_WINDOW, "Session" };
const std::string UNDEFINED = "undefined";
} // namespace
Session::Session(const SessionInfo& info) : sessionInfo_(info)
{
surfaceNode_ = CreateSurfaceNode(info.bundleName_);
if (surfaceNode_ == nullptr) {
WLOGFE("create surface node failed");
}
}
void Session::SetPersistentId(uint64_t persistentId)
@ -94,6 +89,16 @@ bool Session::UnregisterListenerLocked(std::vector<std::shared_ptr<T>>& holder,
return true;
}
void Session::NotifyConnect()
{
auto lifecycleListeners = GetListeners<ILifecycleListener>();
for (auto& listener : lifecycleListeners) {
if (!listener.expired()) {
listener.lock()->OnConnect();
}
}
}
void Session::NotifyForeground()
{
auto lifecycleListeners = GetListeners<ILifecycleListener>();
@ -134,22 +139,6 @@ bool Session::IsSessionValid() const
return res;
}
RSSurfaceNode::SharedPtr Session::CreateSurfaceNode(std::string name)
{
// expect one session with one surfaceNode
if (name.empty()) {
WLOGFI("name is empty");
name = UNDEFINED + std::to_string(persistentId_);
} else {
std::string surfaceNodeName = name + std::to_string(persistentId_);
std::size_t pos = surfaceNodeName.find_last_of('.');
name = (pos == std::string::npos) ? surfaceNodeName : surfaceNodeName.substr(pos + 1); // skip '.'
}
struct RSSurfaceNodeConfig rsSurfaceNodeConfig;
rsSurfaceNodeConfig.SurfaceNodeName = name;
return RSSurfaceNode::Create(rsSurfaceNodeConfig);
}
WSError Session::UpdateRect(const WSRect& rect, SizeChangeReason reason)
{
WLOGFI("session update rect: id: %{public}" PRIu64 ", rect[%{public}d, %{public}d, %{public}u, %{public}u], "\
@ -162,7 +151,8 @@ WSError Session::UpdateRect(const WSRect& rect, SizeChangeReason reason)
return WSError::WS_OK;
}
WSError Session::Connect(const sptr<ISessionStage>& sessionStage, const sptr<IWindowEventChannel>& eventChannel)
WSError Session::Connect(const sptr<ISessionStage>& sessionStage, const sptr<IWindowEventChannel>& eventChannel,
const std::shared_ptr<RSSurfaceNode>& surfaceNode)
{
WLOGFI("Connect session, id: %{public}" PRIu64 ", state: %{public}u", GetPersistentId(),
static_cast<uint32_t>(GetSessionState()));
@ -176,10 +166,12 @@ WSError Session::Connect(const sptr<ISessionStage>& sessionStage, const sptr<IWi
}
sessionStage_ = sessionStage;
windowEventChannel_ = eventChannel;
surfaceNode_ = surfaceNode;
UpdateSessionState(SessionState::STATE_CONNECT);
// once update rect before connect, update again when connect
UpdateRect(winRect_, SizeChangeReason::SHOW);
NotifyConnect();
return WSError::WS_OK;
}

View File

@ -18,6 +18,7 @@
#include <ipc_types.h>
#include <message_option.h>
#include <message_parcel.h>
#include <ui/rs_surface_node.h>
#include "window_manager_hilog.h"
@ -83,7 +84,8 @@ WSError SessionProxy::Disconnect()
return static_cast<WSError>(ret);
}
WSError SessionProxy::Connect(const sptr<ISessionStage>& sessionStage, const sptr<IWindowEventChannel>& eventChannel)
WSError SessionProxy::Connect(const sptr<ISessionStage>& sessionStage, const sptr<IWindowEventChannel>& eventChannel,
const std::shared_ptr<RSSurfaceNode>& surfaceNode)
{
MessageParcel data;
MessageParcel reply;
@ -100,6 +102,10 @@ WSError SessionProxy::Connect(const sptr<ISessionStage>& sessionStage, const spt
WLOGFE("Write IWindowEventChannel failed");
return WSError::WS_ERROR_IPC_FAILED;
}
if (!surfaceNode->Marshalling(data)) {
WLOGFE("Write surfaceNode failed");
return WSError::WS_ERROR_IPC_FAILED;
}
if (Remote()->SendRequest(static_cast<uint32_t>(SessionMessage::TRANS_ID_CONNECT),
data, reply, option) != ERR_NONE) {
WLOGFE("SendRequest failed");

View File

@ -14,7 +14,9 @@
*/
#include "session/host/include/zidl/session_stub.h"
#include <ipc_types.h>
#include <ui/rs_surface_node.h>
#include "window_manager_hilog.h"
namespace OHOS::Rosen {
@ -80,14 +82,15 @@ int SessionStub::HandleConnect(MessageParcel& data, MessageParcel& reply)
{
WLOGFD("Connect!");
sptr<IRemoteObject> sessionStageObject = data.ReadRemoteObject();
sptr<ISessionStage> sessionStageProxy = iface_cast<ISessionStage>(sessionStageObject);
sptr<ISessionStage> sessionStage = iface_cast<ISessionStage>(sessionStageObject);
sptr<IRemoteObject> eventChannelObject = data.ReadRemoteObject();
sptr<IWindowEventChannel> eventChannelProxy = iface_cast<IWindowEventChannel>(eventChannelObject);
if (sessionStageProxy == nullptr || eventChannelProxy == nullptr) {
sptr<IWindowEventChannel> eventChannel = iface_cast<IWindowEventChannel>(eventChannelObject);
std::shared_ptr<RSSurfaceNode> surfaceNode = RSSurfaceNode::Unmarshalling(data);
if (sessionStage == nullptr || eventChannel == nullptr || surfaceNode == nullptr) {
WLOGFE("Failed to read scene session stage object or event channel object!");
return ERR_INVALID_DATA;
}
WSError errCode = Connect(sessionStageProxy, eventChannelProxy);
WSError errCode = Connect(sessionStage, eventChannel, surfaceNode);
reply.WriteUint32(static_cast<uint32_t>(errCode));
return ERR_NONE;
}

View File

@ -60,7 +60,6 @@ sptr<AAFwk::SessionInfo> ExtensionSessionManager::SetAbilitySessionInfo(const sp
}
auto sessionInfo = extSession->GetSessionInfo();
abilitySessionInfo->sessionToken = extSession;
abilitySessionInfo->surfaceNode = extSession->GetSurfaceNode();
abilitySessionInfo->callerToken = sessionInfo.callerToken_;
abilitySessionInfo->persistentId = extSession->GetPersistentId();
return abilitySessionInfo;

View File

@ -105,7 +105,6 @@ sptr<AAFwk::SessionInfo> SceneSessionManager::SetAbilitySessionInfo(const sptr<S
}
auto sessionInfo = scnSession->GetSessionInfo();
abilitySessionInfo->sessionToken = scnSession;
abilitySessionInfo->surfaceNode = scnSession->GetSurfaceNode();
abilitySessionInfo->callerToken = sessionInfo.callerToken_;
abilitySessionInfo->persistentId = scnSession->GetPersistentId();
return abilitySessionInfo;