cleanup on proxynode cleanup

Signed-off-by: Zhang Peng <zhangpeng280@huawei.com>
Change-Id: I3320daab63474de764c47abdeb21404d1a25662c
This commit is contained in:
Zhang Peng 2023-02-22 20:45:22 +08:00
parent 876ef10db5
commit 3f59ca863b
No known key found for this signature in database
GPG Key ID: 735EEEEEEEEEEEEE
6 changed files with 29 additions and 42 deletions

View File

@ -32,14 +32,11 @@ class RSB_EXPORT ProxyNodeCommandHelper {
public:
static void Create(RSContext& context, NodeId id, NodeId target);
static void ResetContextVariableCache(RSContext& context, NodeId id);
static void RemoveModifiers(RSContext& context, NodeId nodeId, std::vector<PropertyId> propertyId);
};
ADD_COMMAND(RSProxyNodeCreate, ARG(PROXY_NODE, PROXY_NODE_CREATE, ProxyNodeCommandHelper::Create, NodeId, NodeId))
ADD_COMMAND(RSProxyNodeResetContextVariableCache,
ARG(PROXY_NODE, PROXY_NODE_RESET_CONTEXT_VARIABLE_CACHE, ProxyNodeCommandHelper::ResetContextVariableCache, NodeId))
ADD_COMMAND(RSProxyNodeRemoveModifiers,
ARG(PROXY_NODE, REMOVE_MODIFIERS, ProxyNodeCommandHelper::RemoveModifiers, NodeId, std::vector<PropertyId>))
} // namespace Rosen
} // namespace OHOS

View File

@ -35,17 +35,5 @@ void ProxyNodeCommandHelper::ResetContextVariableCache(RSContext& context, NodeI
node->ResetContextVariableCache();
}
}
void ProxyNodeCommandHelper::RemoveModifiers(RSContext& context, NodeId nodeId, std::vector<PropertyId> propertyIds)
{
auto& nodeMap = context.GetNodeMap();
auto node = nodeMap.GetRenderNode<RSRenderNode>(nodeId);
if (node == nullptr) {
return;
}
for (auto propertyId : propertyIds) {
node->RemoveModifier(propertyId);
}
}
} // namespace Rosen
} // namespace OHOS

View File

@ -29,7 +29,22 @@ RSProxyRenderNode::RSProxyRenderNode(
RSProxyRenderNode::~RSProxyRenderNode()
{
// clear target node context properties
ROSEN_LOGD("RSProxyRenderNode::~RSProxyRenderNode, proxy id:%" PRIu64 " target:%" PRIu64, GetId(), targetId_);
// if target do not exist (in RT) or already destroyed (in RS), skip reset
auto target = target_.lock();
if (target == nullptr) {
return;
}
// reset target node context properties
target->SetContextAlpha(1, false);
target->SetContextMatrix(SkMatrix::I(), false);
// remove all modifiers and animations added via proxy node
const auto pid_of_this_node = ExtractPid(GetId());
target->FilterModifiersByPid(pid_of_this_node);
target->GetAnimationManager().FilterAnimationByPid(pid_of_this_node);
}
void RSProxyRenderNode::Prepare(const std::shared_ptr<RSNodeVisitor>& visitor)

View File

@ -41,6 +41,12 @@ RSProxyNode::SharedPtr RSProxyNode::Create(NodeId targetNodeId, std::string name
std::unique_ptr<RSCommand> command = std::make_unique<RSProxyNodeCreate>(proxyNodeId, targetNodeId);
transactionProxy->AddCommand(command, node->IsUniRenderEnabled());
// create proxy node in RS even if uni render not enabled.
if (!node->IsUniRenderEnabled()) {
std::unique_ptr<RSCommand> command = std::make_unique<RSProxyNodeCreate>(proxyNodeId, targetNodeId);
transactionProxy->AddCommand(command, true);
}
ROSEN_LOGD("RSProxyNode::Create, target node id:%" PRIu64 ", name %s proxy node id %" PRIu64, node->GetId(),
node->GetName().c_str(), proxyNodeId);
@ -49,6 +55,8 @@ RSProxyNode::SharedPtr RSProxyNode::Create(NodeId targetNodeId, std::string name
RSProxyNode::~RSProxyNode()
{
ROSEN_LOGD("RSProxyNode::~RSProxyNode, proxy id:%" PRIu64 " target:%" PRIu64, proxyNodeId_, GetId());
auto transactionProxy = RSTransactionProxy::GetInstance();
if (transactionProxy == nullptr) {
return;
@ -58,9 +66,11 @@ RSProxyNode::~RSProxyNode()
std::unique_ptr<RSCommand> command = std::make_unique<RSBaseNodeDestroy>(proxyNodeId_);
transactionProxy->AddCommand(command, IsUniRenderEnabled());
auto ids = GetModifierIds();
command = std::make_unique<RSProxyNodeRemoveModifiers>(GetId(), ids);
transactionProxy->AddCommand(command, true, GetFollowType(), GetId());
// destroy corresponding RSProxyRenderNode in RS even if uni render not enabled.
if (!IsUniRenderEnabled()) {
command = std::make_unique<RSBaseNodeDestroy>(proxyNodeId_);
transactionProxy->AddCommand(command, true);
}
ROSEN_LOGD("RSProxyNode::~RSProxyNode, id:%" PRIu64, GetId());
}

View File

@ -198,15 +198,11 @@ bool RSProxyNodeCommandFuzzTest(const uint8_t* data, size_t size)
// get data
uint64_t id = GetData<uint64_t>();
uint64_t target = GetData<uint64_t>();
uint64_t nodeId = GetData<uint64_t>();
uint64_t propertyId = GetData<uint64_t>();
std::vector<PropertyId> propertyIds = {static_cast<PropertyId>(propertyId)};
// test
RSContext context;
ProxyNodeCommandHelper::Create(context, static_cast<NodeId>(id), static_cast<NodeId>(target));
ProxyNodeCommandHelper::ResetContextVariableCache(context, static_cast<NodeId>(id));
ProxyNodeCommandHelper::RemoveModifiers(context, static_cast<NodeId>(nodeId), propertyIds);
return true;
}

View File

@ -44,23 +44,4 @@ HWTEST_F(RSProxyNodeCommandTest, TestRSProxyNodeCommand001, TestSize.Level1)
NodeId id = static_cast<NodeId>(-1);
ProxyNodeCommandHelper::ResetContextVariableCache(context, id);
}
/**
* @tc.name: TestRSProxyNodeCommand002
* @tc.desc: RemoveModifiers test.
* @tc.type: FUNC
*/
HWTEST_F(RSProxyNodeCommandTest, TestRSProxyNodeCommand002, TestSize.Level1)
{
RSContext context;
NodeId nodeId = static_cast<NodeId>(-1);
std::vector<PropertyId> propertyIds;
ProxyNodeCommandHelper::RemoveModifiers(context, nodeId, propertyIds);
NodeId id2 = 11;
auto context2 = std::make_shared<RSContext>();
ProxyNodeCommandHelper::Create(*context2, id2, 10);
propertyIds.push_back(10);
propertyIds.push_back(11);
ProxyNodeCommandHelper::RemoveModifiers(*context2, id2, propertyIds);
}
} // namespace OHOS::Rosen