1 /*
2  * Copyright (c) 2021-2023 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 #ifndef ROSEN_RENDER_SERVICE_BASE_COMMAND_RS_BASE_NODE_COMMAND_H
17 #define ROSEN_RENDER_SERVICE_BASE_COMMAND_RS_BASE_NODE_COMMAND_H
18 
19 #include "command/rs_command_templates.h"
20 #include "common/rs_macros.h"
21 
22 namespace OHOS {
23 namespace Rosen {
24 
25 enum RSBaseNodeCommandType : uint16_t {
26     BASE_NODE_DESTROY,
27     BASE_NODE_ADD_CHILD,
28     BASE_NODE_MOVE_CHILD,
29     BASE_NODE_ADD_CROSS_PARENT_CHILD,
30     BASE_NODE_REMOVE_CHILD,
31     BASE_NODE_REMOVE_CROSS_PARENT_CHILD,
32     BASE_NODE_REMOVE_FROM_TREE,
33     BASE_NODE_CLEAR_CHILDREN,
34 };
35 
36 class RSB_EXPORT BaseNodeCommandHelper {
37 public:
38     static void Destroy(RSContext& context, NodeId nodeId);
39     static void AddChild(RSContext& context, NodeId nodeId, NodeId childNodeId, int32_t index);
40     static void MoveChild(RSContext& context, NodeId nodeId, NodeId childNodeId, int32_t index);
41     static void RemoveChild(RSContext& context, NodeId nodeId, NodeId childNodeId);
42     static void AddCrossParentChild(RSContext& context, NodeId nodeId, NodeId childNodeId, int32_t index);
43     static void RemoveCrossParentChild(RSContext& context, NodeId nodeId, NodeId childNodeId, NodeId newParentId);
44     static void RemoveFromTree(RSContext& context, NodeId nodeId);
45     static void ClearChildren(RSContext& context, NodeId nodeId);
46 };
47 
48 ADD_COMMAND(RSBaseNodeDestroy, ARG(BASE_NODE, BASE_NODE_DESTROY, BaseNodeCommandHelper::Destroy, NodeId))
49 ADD_COMMAND(
50     RSBaseNodeAddChild, ARG(BASE_NODE, BASE_NODE_ADD_CHILD, BaseNodeCommandHelper::AddChild, NodeId, NodeId, int32_t))
51 ADD_COMMAND(RSBaseNodeMoveChild,
52     ARG(BASE_NODE, BASE_NODE_MOVE_CHILD, BaseNodeCommandHelper::MoveChild, NodeId, NodeId, int32_t))
53 ADD_COMMAND(
54     RSBaseNodeRemoveChild, ARG(BASE_NODE, BASE_NODE_REMOVE_CHILD, BaseNodeCommandHelper::RemoveChild, NodeId, NodeId))
55 ADD_COMMAND(
56     RSBaseNodeAddCrossParentChild, ARG(BASE_NODE, BASE_NODE_ADD_CROSS_PARENT_CHILD,
57     BaseNodeCommandHelper::AddCrossParentChild, NodeId, NodeId, int32_t))
58 ADD_COMMAND(
59     RSBaseNodeRemoveCrossParentChild, ARG(BASE_NODE, BASE_NODE_REMOVE_CROSS_PARENT_CHILD,
60     BaseNodeCommandHelper::RemoveCrossParentChild, NodeId, NodeId, NodeId))
61 ADD_COMMAND(
62     RSBaseNodeRemoveFromTree, ARG(BASE_NODE, BASE_NODE_REMOVE_FROM_TREE, BaseNodeCommandHelper::RemoveFromTree, NodeId))
63 ADD_COMMAND(
64     RSBaseNodeClearChild, ARG(BASE_NODE, BASE_NODE_CLEAR_CHILDREN, BaseNodeCommandHelper::ClearChildren, NodeId))
65 } // namespace Rosen
66 } // namespace OHOS
67 
68 #endif // ROSEN_RENDER_SERVICE_BASE_COMMAND_RS_BASE_NODE_COMMAND_H
69