!10139 RendeService支持单帧合成

Merge pull request !10139 from wangyaming/master
This commit is contained in:
openharmony_ci 2024-04-20 08:39:17 +00:00 committed by Gitee
commit dec45830b4
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
8 changed files with 185 additions and 6 deletions

View File

@ -2386,18 +2386,57 @@ void RSMainThread::Animate(uint64_t timestamp)
PerfAfterAnim(needRequestNextVsync);
}
bool RSMainThread::IsNeedProcessBySingleFrameComposer(std::unique_ptr<RSTransactionData>& rsTransactionData)
{
if (!isUniRender_ || !rsTransactionData) {
return false;
}
if (!RSSingleFrameComposer::IsShouldProcessByIpcThread(rsTransactionData->GetSendingPid()) &&
!RSSystemProperties::GetSingleFrameComposerEnabled()) {
return false;
}
// animation node will call RequestNextVsync() in mainLoop_, here we simply ignore animation scenario
if (!context_->animatingNodeList_.empty()) {
return false;
}
// ignore mult-window scenario
auto currentVisibleLeashWindowCount = context_->GetNodeMap().GetVisibleLeashWindowCount();
if (currentVisibleLeashWindowCount >= MULTI_WINDOW_PERF_START_NUM) {
return false;
}
return true;
}
void RSMainThread::ProcessDataBySingleFrameComposer(std::unique_ptr<RSTransactionData>& rsTransactionData)
{
if (!rsTransactionData || !RSSystemProperties::GetSingleFrameComposerEnabled() ||
!RSSingleFrameComposer::IsShouldProcessByIpcThread(rsTransactionData->GetSendingPid())) {
if (!rsTransactionData || !isUniRender_) {
return;
}
RSSingleFrameComposer::SetSingleFrameFlag(std::this_thread::get_id());
if (isUniRender_) {
if (RSSystemProperties::GetSingleFrameComposerEnabled()) {
RSSingleFrameComposer::SetSingleFrameFlag(std::this_thread::get_id());
context_->transactionTimestamp_ = rsTransactionData->GetTimestamp();
rsTransactionData->ProcessBySingleFrameComposer(*context_);
}
RecvAndProcessRSTransactionDataImmediately(rsTransactionData);
}
void RSMainThread::RecvAndProcessRSTransactionDataImmediately(std::unique_ptr<RSTransactionData>& rsTransactionData)
{
if (!rsTransactionData || !isUniRender_) {
return;
}
RS_TRACE_NAME("ProcessBySingleFrameComposer");
{
std::lock_guard<std::mutex> lock(transitionDataMutex_);
cachedTransactionDataMap_[rsTransactionData->GetSendingPid()].emplace_back(std::move(rsTransactionData));
}
ForceRefreshForUni();
}
void RSMainThread::RecvRSTransactionData(std::unique_ptr<RSTransactionData>& rsTransactionData)

View File

@ -87,7 +87,9 @@ public:
void Init();
void Start();
bool IsNeedProcessBySingleFrameComposer(std::unique_ptr<RSTransactionData>& rsTransactionData);
void ProcessDataBySingleFrameComposer(std::unique_ptr<RSTransactionData>& rsTransactionData);
void RecvAndProcessRSTransactionDataImmediately(std::unique_ptr<RSTransactionData>& rsTransactionData);
void RecvRSTransactionData(std::unique_ptr<RSTransactionData>& rsTransactionData);
void RequestNextVSync(const std::string& fromWhom = "unknown", int64_t lastVSyncTS = 0);
void PostTask(RSTaskMessage::RSTask task);

View File

@ -252,8 +252,12 @@ void RSRenderServiceConnection::RSApplicationRenderThreadDeathRecipient::OnRemot
void RSRenderServiceConnection::CommitTransaction(std::unique_ptr<RSTransactionData>& transactionData)
{
mainThread_->ProcessDataBySingleFrameComposer(transactionData);
mainThread_->RecvRSTransactionData(transactionData);
bool isProcessBySingleFrame = mainThread_->IsNeedProcessBySingleFrameComposer(transactionData);
if (isProcessBySingleFrame) {
mainThread_->ProcessDataBySingleFrameComposer(transactionData);
} else {
mainThread_->RecvRSTransactionData(transactionData);
}
}
void RSRenderServiceConnection::ExecuteSynchronousTask(const std::shared_ptr<RSSyncTask>& task)

View File

@ -63,6 +63,8 @@ public:
NodeId GetScreenLockWindowNodeId() const;
void ObtainScreenLockWindowNodeId(const std::shared_ptr<RSSurfaceRenderNode> surfaceNode);
void ObtainLauncherNodeId(const std::shared_ptr<RSSurfaceRenderNode> surfaceNode);
uint32_t GetVisibleLeashWindowCount() const;
private:
explicit RSRenderNodeMap();
void EraseAbilityComponentNumsInProcess(NodeId id);

View File

@ -337,6 +337,8 @@ public:
void MarkUIHidden(bool isHidden);
bool IsUIHidden() const;
bool IsLeashWindowSurfaceNodeVisible();
const std::string& GetName() const
{
return name_;

View File

@ -97,6 +97,18 @@ void RSRenderNodeMap::CalCulateAbilityComponentNumsInProcess(NodeId id)
abilityComponentNumsInProcess_[ExtractPid(id)]++;
}
uint32_t RSRenderNodeMap::GetVisibleLeashWindowCount() const
{
if (surfaceNodeMap_.empty()) {
return 0;
}
return std::count_if(surfaceNodeMap_.begin(), surfaceNodeMap_.end(),
[](const auto& pair) -> bool {
return pair.second && pair.second->IsLeashWindowSurfaceNodeVisible();
});
}
bool RSRenderNodeMap::IsResidentProcessNode(NodeId id) const
{
auto nodePid = ExtractPid(id);

View File

@ -554,6 +554,18 @@ bool RSSurfaceRenderNode::IsUIHidden() const
return isUIHidden_;
}
bool RSSurfaceRenderNode::IsLeashWindowSurfaceNodeVisible()
{
if (!IsLeashWindow()) {
return false;
}
auto nestedSurfaces = GetLeashWindowNestedSurfaces();
return std::any_of(nestedSurfaces.begin(), nestedSurfaces.end(),
[](const auto& node) -> bool {
return node && !node->IsUIHidden();
});
}
void RSSurfaceRenderNode::SetContextMatrix(const std::optional<Drawing::Matrix>& matrix, bool sendMsg)
{
if (contextMatrix_ == matrix) {

View File

@ -549,6 +549,112 @@ HWTEST_F(RSMainThreadTest, CheckAndUpdateInstanceContentStaticStatus02, TestSize
ASSERT_EQ(node->GetSurfaceCacheContentStatic(), false);
}
/**
* @tc.name: IsNeedProcessBySingleFrameComposerTest001
* @tc.desc: Test IsNeedProcessBySingleFrameComposerTest when TransactionData is null
* @tc.type: FUNC
* @tc.require: issueI9HPBS
*/
HWTEST_F(RSMainThreadTest, IsNeedProcessBySingleFrameComposerTest001, TestSize.Level1)
{
auto mainThread = RSMainThread::Instance();
std::unique_ptr<RSTransactionData> transactionData = nullptr;
ASSERT_FALSE(mainThread->IsNeedProcessBySingleFrameComposer(transactionData));
transactionData = std::make_unique<RSTransactionData>();
mainThread->isUniRender_ = true;
ASSERT_FALSE(mainThread->IsNeedProcessBySingleFrameComposer(transactionData));
}
/**
* @tc.name: IsNeedProcessBySingleFrameComposerTest002
* @tc.desc: Test IsNeedProcessBySingleFrameComposerTest when SingleFrameComposer enabled by app process
* @tc.type: FUNC
* @tc.require: issueI9HPBS
*/
HWTEST_F(RSMainThreadTest, IsNeedProcessBySingleFrameComposerTest002, TestSize.Level1)
{
auto mainThread = RSMainThread::Instance();
auto transactionData = std::make_unique<RSTransactionData>();
mainThread->isUniRender_ = true;
pid_t pid = 1;
transactionData->SetSendingPid(pid);
RSSingleFrameComposer::AddOrRemoveAppPidToMap(true, pid);
ASSERT_TRUE(mainThread->IsNeedProcessBySingleFrameComposer(transactionData));
}
/**
* @tc.name: IsNeedProcessBySingleFrameComposerTest003
* @tc.desc: Test IsNeedProcessBySingleFrameComposerTest when animation node exists
* @tc.type: FUNC
* @tc.require: issueI9HPBS
*/
HWTEST_F(RSMainThreadTest, IsNeedProcessBySingleFrameComposerTest003, TestSize.Level1)
{
auto mainThread = RSMainThread::Instance();
auto transactionData = std::make_unique<RSTransactionData>();
mainThread->isUniRender_ = true;
pid_t pid = 1;
transactionData->SetSendingPid(pid);
RSSingleFrameComposer::AddOrRemoveAppPidToMap(true, pid);
NodeId id = 1;
auto node = std::make_shared<RSRenderNode>(id, mainThread->context_);
mainThread->context_->RegisterAnimatingRenderNode(node);
ASSERT_FALSE(mainThread->IsNeedProcessBySingleFrameComposer(transactionData));
}
/**
* @tc.name: IsNeedProcessBySingleFrameComposerTest004
* @tc.desc: Test IsNeedProcessBySingleFrameComposerTest when multi-window shown on screen
* @tc.type: FUNC
* @tc.require: issueI9HPBS
*/
HWTEST_F(RSMainThreadTest, IsNeedProcessBySingleFrameComposerTest004, TestSize.Level1)
{
auto mainThread = RSMainThread::Instance();
auto transactionData = std::make_unique<RSTransactionData>();
mainThread->isUniRender_ = true;
pid_t pid = 1;
transactionData->SetSendingPid(pid);
RSSingleFrameComposer::AddOrRemoveAppPidToMap(true, pid);
NodeId firstWindowNodeId = 2;
auto firstWindowNode = std::make_shared<RSSurfaceRenderNode>(firstWindowNodeId, mainThread->context_);
firstWindowNode->SetSurfaceNodeType(RSSurfaceNodeType::LEASH_WINDOW_NODE);
NodeId firstWindowChildNodeId = 3;
auto firstWindowChildNode = std::make_shared<RSSurfaceRenderNode>(firstWindowChildNodeId, mainThread->context_);
firstWindowChildNode->MarkUIHidden(false);
firstWindowNode->AddChild(firstWindowChildNode);
firstWindowNode->GenerateFullChildrenList();
mainThread->context_->nodeMap.RegisterRenderNode(firstWindowNode);
NodeId secondWindowNodeId = 2;
auto secondWindowNode = std::make_shared<RSSurfaceRenderNode>(secondWindowNodeId, mainThread->context_);
secondWindowNode->SetSurfaceNodeType(RSSurfaceNodeType::LEASH_WINDOW_NODE);
NodeId secondWindowChildNodeId = 3;
auto secondWindowChildNode = std::make_shared<RSSurfaceRenderNode>(secondWindowChildNodeId, mainThread->context_);
secondWindowChildNode->MarkUIHidden(false);
secondWindowNode->AddChild(secondWindowChildNode);
secondWindowNode->GenerateFullChildrenList();
mainThread->context_->nodeMap.RegisterRenderNode(secondWindowNode);
ASSERT_FALSE(mainThread->IsNeedProcessBySingleFrameComposer(transactionData));
}
/**
* @tc.name: RecvAndProcessRSTransactionDataImmediatelyTest
* @tc.desc: Test ecvAndProcessRSTransactionDataImmediately when transactionData is null
* @tc.type: FUNC
* @tc.require: issueI9HPBS
*/
HWTEST_F(RSMainThreadTest, RecvAndProcessRSTransactionDataImmediatelyTest, TestSize.Level1)
{
auto mainThread = RSMainThread::Instance();
std::unique_ptr<RSTransactionData> transactionData = nullptr;
mainThread->RecvAndProcessRSTransactionDataImmediately(transactionData);
ASSERT_EQ(transactionData, nullptr);
}
/**
* @tc.name: RecvRSTransactionData
* @tc.desc: Test RecvRSTransactionData, when TransactionData is null