1 /*
2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "pipeline/rs_context.h"
17
18 #include "pipeline/rs_render_node.h"
19 #include "platform/common/rs_log.h"
20
21 namespace OHOS::Rosen {
RegisterAnimatingRenderNode(const std::shared_ptr<RSRenderNode> & nodePtr)22 void RSContext::RegisterAnimatingRenderNode(const std::shared_ptr<RSRenderNode>& nodePtr)
23 {
24 NodeId id = nodePtr->GetId();
25 animatingNodeList_.emplace(id, nodePtr);
26 nodePtr->ActivateDisplaySync();
27 ROSEN_LOGD("RSContext::RegisterAnimatingRenderNode, register node id: %{public}" PRIu64, id);
28 }
29
UnregisterAnimatingRenderNode(NodeId id)30 void RSContext::UnregisterAnimatingRenderNode(NodeId id)
31 {
32 animatingNodeList_.erase(id);
33 ROSEN_LOGD("RSContext::UnregisterAnimatingRenderNode, unregister node id: %{public}" PRIu64, id);
34 }
35
AddActiveNode(const std::shared_ptr<RSRenderNode> & node)36 void RSContext::AddActiveNode(const std::shared_ptr<RSRenderNode>& node)
37 {
38 if (node == nullptr || node->GetId() == INVALID_NODEID) {
39 return;
40 }
41 auto rootNodeId = node->GetInstanceRootNodeId();
42 std::lock_guard<std::mutex> lock(activeNodesInRootMutex_);
43 activeNodesInRoot_[rootNodeId].emplace(node->GetId(), node);
44 }
45
HasActiveNode(const std::shared_ptr<RSRenderNode> & node)46 bool RSContext::HasActiveNode(const std::shared_ptr<RSRenderNode>& node)
47 {
48 if (node == nullptr || node->GetId() == INVALID_NODEID) {
49 return false;
50 }
51 auto rootNodeId = node->GetInstanceRootNodeId();
52 std::lock_guard<std::mutex> lock(activeNodesInRootMutex_);
53 return activeNodesInRoot_[rootNodeId].count(node->GetId()) > 0;
54 }
55
AddPendingSyncNode(const std::shared_ptr<RSRenderNode> node)56 void RSContext::AddPendingSyncNode(const std::shared_ptr<RSRenderNode> node)
57 {
58 if (node == nullptr || node->GetId() == INVALID_NODEID) {
59 return;
60 }
61 pendingSyncNodes_.emplace(node->GetId(), node);
62 }
63
MarkNeedPurge(ClearMemoryMoment moment,PurgeType purgeType)64 void RSContext::MarkNeedPurge(ClearMemoryMoment moment, PurgeType purgeType)
65 {
66 clearMoment_ = moment;
67 purgeType_ = purgeType;
68 }
69
SetClearMoment(ClearMemoryMoment moment)70 void RSContext::SetClearMoment(ClearMemoryMoment moment)
71 {
72 clearMoment_ = moment;
73 }
74
GetClearMoment() const75 ClearMemoryMoment RSContext::GetClearMoment() const
76 {
77 return clearMoment_;
78 }
79
Initialize()80 void RSContext::Initialize()
81 {
82 nodeMap.Initialize(weak_from_this());
83 globalRootRenderNode_->OnRegister(weak_from_this());
84 }
85
AddSyncFinishAnimationList(NodeId nodeId,AnimationId animationId)86 void RSContext::AddSyncFinishAnimationList(NodeId nodeId, AnimationId animationId)
87 {
88 needSyncFinishAnimationList_.push_back({nodeId, animationId});
89 }
90 } // namespace OHOS::Rosen
91