mirror of
https://gitee.com/openharmony/window_window_manager
synced 2024-11-23 15:00:12 +00:00
!5771 Screensession代码优化及displayNode日志打点
Merge pull request !5771 from cloud_nine/master
This commit is contained in:
commit
7dd6f4e26c
@ -100,9 +100,14 @@ void ScreenSessionManagerClient::OnScreenConnectionChanged(ScreenId screenId, Sc
|
|||||||
WLOGFE("There is no need to connect the screen");
|
WLOGFE("There is no need to connect the screen");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto screenProperty = screenSessionManager_->GetScreenProperty(screenId);
|
ScreenSessionConfig config = {
|
||||||
auto displayNode = screenSessionManager_->GetDisplayNode(screenId);
|
.screenId = screenId,
|
||||||
sptr<ScreenSession> screenSession = new ScreenSession(screenId, rsId, name, screenProperty, displayNode);
|
.rsId = rsId,
|
||||||
|
.name = name,
|
||||||
|
};
|
||||||
|
config.property = screenSessionManager_->GetScreenProperty(screenId);
|
||||||
|
config.displayNode = screenSessionManager_->GetDisplayNode(screenId);
|
||||||
|
sptr<ScreenSession> screenSession = new ScreenSession(config, ScreenSessionReason::CREATE_SESSION_FOR_CLIENT);
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(screenSessionMapMutex_);
|
std::lock_guard<std::mutex> lock(screenSessionMapMutex_);
|
||||||
screenSessionMap_.emplace(screenId, screenSession);
|
screenSessionMap_.emplace(screenId, screenSession);
|
||||||
|
@ -53,9 +53,28 @@ enum class ScreenState : int32_t {
|
|||||||
DISCONNECTION,
|
DISCONNECTION,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct ScreenSessionConfig {
|
||||||
|
ScreenId screenId {0};
|
||||||
|
ScreenId rsId {0};
|
||||||
|
ScreenId defaultScreenId {0};
|
||||||
|
ScreenId mirrorNodeId {0};
|
||||||
|
std::string name = "UNKNOWN";
|
||||||
|
ScreenProperty property;
|
||||||
|
std::shared_ptr<RSDisplayNode> displayNode;
|
||||||
|
};
|
||||||
|
|
||||||
|
enum class ScreenSessionReason : int32_t {
|
||||||
|
CREATE_SESSION_FOR_CLIENT,
|
||||||
|
CREATE_SESSION_FOR_VIRTUAL,
|
||||||
|
CREATE_SESSION_FOR_MIRROR,
|
||||||
|
CREATE_SESSION_FOR_REAL,
|
||||||
|
INVALID,
|
||||||
|
};
|
||||||
|
|
||||||
class ScreenSession : public RefBase {
|
class ScreenSession : public RefBase {
|
||||||
public:
|
public:
|
||||||
ScreenSession() = default;
|
ScreenSession() = default;
|
||||||
|
ScreenSession(const ScreenSessionConfig& config, ScreenSessionReason reason);
|
||||||
ScreenSession(ScreenId screenId, ScreenId rsId, const std::string& name,
|
ScreenSession(ScreenId screenId, ScreenId rsId, const std::string& name,
|
||||||
const ScreenProperty& property, const std::shared_ptr<RSDisplayNode>& displayNode);
|
const ScreenProperty& property, const std::shared_ptr<RSDisplayNode>& displayNode);
|
||||||
ScreenSession(ScreenId screenId, const ScreenProperty& property, ScreenId defaultScreenId);
|
ScreenSession(ScreenId screenId, const ScreenProperty& property, ScreenId defaultScreenId);
|
||||||
@ -63,6 +82,7 @@ public:
|
|||||||
ScreenSession(const std::string& name, ScreenId smsId, ScreenId rsId, ScreenId defaultScreenId);
|
ScreenSession(const std::string& name, ScreenId smsId, ScreenId rsId, ScreenId defaultScreenId);
|
||||||
virtual ~ScreenSession() = default;
|
virtual ~ScreenSession() = default;
|
||||||
|
|
||||||
|
void CreateDisplayNode(const Rosen::RSDisplayNodeConfig& config);
|
||||||
void SetDisplayNodeScreenId(ScreenId screenId);
|
void SetDisplayNodeScreenId(ScreenId screenId);
|
||||||
void RegisterScreenChangeListener(IScreenChangeListener* screenChangeListener);
|
void RegisterScreenChangeListener(IScreenChangeListener* screenChangeListener);
|
||||||
void UnregisterScreenChangeListener(IScreenChangeListener* screenChangeListener);
|
void UnregisterScreenChangeListener(IScreenChangeListener* screenChangeListener);
|
||||||
|
@ -27,6 +27,63 @@ namespace {
|
|||||||
constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, HILOG_DOMAIN_DMS_SCREEN_SESSION, "ScreenSession" };
|
constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, HILOG_DOMAIN_DMS_SCREEN_SESSION, "ScreenSession" };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ScreenSession::ScreenSession(const ScreenSessionConfig& config, ScreenSessionReason reason)
|
||||||
|
: name_(config.name), screenId_(config.screenId), rsId_(config.rsId), defaultScreenId_(config.defaultScreenId),
|
||||||
|
property_(config.property), displayNode_(config.displayNode)
|
||||||
|
{
|
||||||
|
TLOGI(WmsLogTag::DMS,
|
||||||
|
"[DPNODE]Create Session, reason: %{public}d, screenId: %{public}" PRIu64", rsId: %{public}" PRIu64"",
|
||||||
|
reason, screenId_, rsId_);
|
||||||
|
TLOGI(WmsLogTag::DMS,
|
||||||
|
"[DPNODE]Config name: %{public}s, defaultId: %{public}" PRIu64", mirrorNodeId: %{public}" PRIu64"",
|
||||||
|
name_.c_str(), defaultScreenId_, config.mirrorNodeId);
|
||||||
|
Rosen::RSDisplayNodeConfig rsConfig;
|
||||||
|
switch (reason) {
|
||||||
|
case ScreenSessionReason::CREATE_SESSION_FOR_CLIENT: {
|
||||||
|
TLOGI(WmsLogTag::DMS, "create screen session for client. noting to do.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
case ScreenSessionReason::CREATE_SESSION_FOR_VIRTUAL: {
|
||||||
|
// create virtual screen should use rsid
|
||||||
|
rsConfig.screenId = rsId_;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case ScreenSessionReason::CREATE_SESSION_FOR_MIRROR: {
|
||||||
|
rsConfig.screenId = screenId_;
|
||||||
|
rsConfig.isMirrored = true;
|
||||||
|
rsConfig.mirrorNodeId = config.mirrorNodeId;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case ScreenSessionReason::CREATE_SESSION_FOR_REAL: {
|
||||||
|
rsConfig.screenId = screenId_;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default : {
|
||||||
|
TLOGE(WmsLogTag::DMS, "INVALID invalid screen session config.");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
CreateDisplayNode(rsConfig);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScreenSession::CreateDisplayNode(const Rosen::RSDisplayNodeConfig& config)
|
||||||
|
{
|
||||||
|
TLOGI(WmsLogTag::DMS, "[DPNODE]config screenId: %{public}d, isMirrored: %{public}d, mirrorNodeId: %{public}d ",
|
||||||
|
static_cast<int32_t>(config.screenId),
|
||||||
|
static_cast<int32_t>(config.isMirrored),
|
||||||
|
static_cast<int32_t>(config.mirrorNodeId));
|
||||||
|
displayNode_ = Rosen::RSDisplayNode::Create(config);
|
||||||
|
if (displayNode_) {
|
||||||
|
displayNode_->SetFrame(property_.GetBounds().rect_.left_, property_.GetBounds().rect_.top_,
|
||||||
|
property_.GetBounds().rect_.width_, property_.GetBounds().rect_.height_);
|
||||||
|
displayNode_->SetBounds(property_.GetBounds().rect_.left_, property_.GetBounds().rect_.top_,
|
||||||
|
property_.GetBounds().rect_.width_, property_.GetBounds().rect_.height_);
|
||||||
|
} else {
|
||||||
|
TLOGE(WmsLogTag::DMS, "Failed to create displayNode, displayNode is null!");
|
||||||
|
}
|
||||||
|
RSTransaction::FlushImplicitTransaction();
|
||||||
|
}
|
||||||
|
|
||||||
ScreenSession::ScreenSession(ScreenId screenId, ScreenId rsId, const std::string& name,
|
ScreenSession::ScreenSession(ScreenId screenId, ScreenId rsId, const std::string& name,
|
||||||
const ScreenProperty& property, const std::shared_ptr<RSDisplayNode>& displayNode)
|
const ScreenProperty& property, const std::shared_ptr<RSDisplayNode>& displayNode)
|
||||||
: name_(name), screenId_(screenId), rsId_(rsId), property_(property), displayNode_(displayNode)
|
: name_(name), screenId_(screenId), rsId_(rsId), property_(property), displayNode_(displayNode)
|
||||||
|
@ -775,7 +775,13 @@ sptr<ScreenSession> ScreenSessionManager::GetScreenSessionInner(ScreenId screenI
|
|||||||
nodeId = sIt->second->GetDisplayNode()->GetId();
|
nodeId = sIt->second->GetDisplayNode()->GetId();
|
||||||
}
|
}
|
||||||
WLOGFI("GetScreenSessionInner: nodeId:%{public}" PRIu64 "", nodeId);
|
WLOGFI("GetScreenSessionInner: nodeId:%{public}" PRIu64 "", nodeId);
|
||||||
session = new ScreenSession(screenId, property, nodeId, defScreenId);
|
ScreenSessionConfig config = {
|
||||||
|
.screenId = screenId,
|
||||||
|
.property = property,
|
||||||
|
.mirrorNodeId = nodeId,
|
||||||
|
.defaultScreenId = defScreenId,
|
||||||
|
};
|
||||||
|
session = new ScreenSession(config, ScreenSessionReason::CREATE_SESSION_FOR_MIRROR);
|
||||||
session->SetVirtualScreenFlag(VirtualScreenFlag::CAST);
|
session->SetVirtualScreenFlag(VirtualScreenFlag::CAST);
|
||||||
session->SetName("CastEngine");
|
session->SetName("CastEngine");
|
||||||
session->SetScreenCombination(ScreenCombination::SCREEN_MIRROR);
|
session->SetScreenCombination(ScreenCombination::SCREEN_MIRROR);
|
||||||
@ -783,7 +789,12 @@ sptr<ScreenSession> ScreenSessionManager::GetScreenSessionInner(ScreenId screenI
|
|||||||
isHdmiScreen_ = true;
|
isHdmiScreen_ = true;
|
||||||
NotifyCaptureStatusChanged();
|
NotifyCaptureStatusChanged();
|
||||||
} else {
|
} else {
|
||||||
session = new ScreenSession(screenId, property, defScreenId);
|
ScreenSessionConfig config = {
|
||||||
|
.screenId = screenId,
|
||||||
|
.property = property,
|
||||||
|
.defaultScreenId = defScreenId,
|
||||||
|
};
|
||||||
|
session = new ScreenSession(config, ScreenSessionReason::CREATE_SESSION_FOR_REAL);
|
||||||
}
|
}
|
||||||
return session;
|
return session;
|
||||||
}
|
}
|
||||||
@ -2413,8 +2424,14 @@ sptr<ScreenSession> ScreenSessionManager::InitVirtualScreen(ScreenId smsScreenId
|
|||||||
VirtualScreenOption option)
|
VirtualScreenOption option)
|
||||||
{
|
{
|
||||||
WLOGFI("InitVirtualScreen: Enter");
|
WLOGFI("InitVirtualScreen: Enter");
|
||||||
|
ScreenSessionConfig config = {
|
||||||
|
.name = option.name_,
|
||||||
|
.screenId = smsScreenId,
|
||||||
|
.rsId = rsId,
|
||||||
|
.defaultScreenId = GetDefaultScreenId(),
|
||||||
|
};
|
||||||
sptr<ScreenSession> screenSession =
|
sptr<ScreenSession> screenSession =
|
||||||
new(std::nothrow) ScreenSession(option.name_, smsScreenId, rsId, GetDefaultScreenId());
|
new(std::nothrow) ScreenSession(config, ScreenSessionReason::CREATE_SESSION_FOR_VIRTUAL);
|
||||||
sptr<SupportedScreenModes> info = new(std::nothrow) SupportedScreenModes();
|
sptr<SupportedScreenModes> info = new(std::nothrow) SupportedScreenModes();
|
||||||
if (screenSession == nullptr || info == nullptr) {
|
if (screenSession == nullptr || info == nullptr) {
|
||||||
WLOGFI("InitVirtualScreen: new screenSession or info failed");
|
WLOGFI("InitVirtualScreen: new screenSession or info failed");
|
||||||
@ -2477,8 +2494,14 @@ sptr<ScreenSession> ScreenSessionManager::InitAndGetScreen(ScreenId rsScreenId)
|
|||||||
RSScreenCapability screenCapability = rsInterface_.GetScreenCapability(rsScreenId);
|
RSScreenCapability screenCapability = rsInterface_.GetScreenCapability(rsScreenId);
|
||||||
WLOGFI("Screen name is %{public}s, phyWidth is %{public}u, phyHeight is %{public}u",
|
WLOGFI("Screen name is %{public}s, phyWidth is %{public}u, phyHeight is %{public}u",
|
||||||
screenCapability.GetName().c_str(), screenCapability.GetPhyWidth(), screenCapability.GetPhyHeight());
|
screenCapability.GetName().c_str(), screenCapability.GetPhyWidth(), screenCapability.GetPhyHeight());
|
||||||
|
ScreenSessionConfig config = {
|
||||||
|
.name = screenCapability.GetName(),
|
||||||
|
.screenId = smsScreenId,
|
||||||
|
.rsId = rsScreenId,
|
||||||
|
.defaultScreenId = GetDefaultScreenId(),
|
||||||
|
};
|
||||||
sptr<ScreenSession> screenSession =
|
sptr<ScreenSession> screenSession =
|
||||||
new(std::nothrow) ScreenSession(screenCapability.GetName(), smsScreenId, rsScreenId, GetDefaultScreenId());
|
new(std::nothrow) ScreenSession(config, ScreenSessionReason::CREATE_SESSION_FOR_VIRTUAL);
|
||||||
if (screenSession == nullptr) {
|
if (screenSession == nullptr) {
|
||||||
WLOGFE("InitAndGetScreen: screenSession == nullptr.");
|
WLOGFE("InitAndGetScreen: screenSession == nullptr.");
|
||||||
screenIdManager_.DeleteScreenId(smsScreenId);
|
screenIdManager_.DeleteScreenId(smsScreenId);
|
||||||
|
@ -27,6 +27,23 @@ class ScreenSessionTest : public testing::Test {
|
|||||||
};
|
};
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @tc.name: create ScreenSession
|
||||||
|
* @tc.desc: normal function
|
||||||
|
* @tc.type: FUNC
|
||||||
|
*/
|
||||||
|
HWTEST_F(ScreenSessionTest, ScreenSession, Function | SmallTest | Level2)
|
||||||
|
{
|
||||||
|
ScreenSessionConfig config = {
|
||||||
|
.screenId = 0,
|
||||||
|
.rsId = 0,
|
||||||
|
.name = "OpenHarmony",
|
||||||
|
};
|
||||||
|
sptr<ScreenSession> screenSession = new ScreenSession(config, ScreenSessionReason::CREATE_SESSION_FOR_CLIENT);
|
||||||
|
EXPECT_NE(nullptr, screenSession);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @tc.name: SetDisplayNodeScreenId
|
* @tc.name: SetDisplayNodeScreenId
|
||||||
* @tc.desc: normal function
|
* @tc.desc: normal function
|
||||||
|
Loading…
Reference in New Issue
Block a user