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 #include "command/rs_command_factory.h"
17
18 #include "platform/common/rs_log.h"
19
20 // manually instantiate all RScommands (this is when the registry happens)
21 #define ROSEN_INSTANTIATE_COMMAND_TEMPLATE
22 // node
23 #include "command/rs_base_node_command.h"
24 #include "command/rs_canvas_drawing_node_command.h"
25 #include "command/rs_canvas_node_command.h"
26 #ifndef ROSEN_ARKUI_X
27 #include "command/rs_display_node_command.h"
28 #endif
29 #include "command/rs_effect_node_command.h"
30 #include "command/rs_node_command.h"
31 #include "command/rs_proxy_node_command.h"
32 #include "command/rs_root_node_command.h"
33 #include "command/rs_surface_node_command.h"
34 // animation
35 #include "command/rs_animation_command.h"
36 // read showing property commands
37 #include "command/rs_node_showing_command.h"
38
39 #include "command/rs_frame_rate_linker_command.h"
40
41 #undef ROSEN_INSTANTIATE_COMMAND_TEMPLATE
42
43 namespace OHOS {
44 namespace Rosen {
45
46 namespace {
MakeKey(uint16_t commandType,uint16_t commandSubType)47 inline uint32_t MakeKey(uint16_t commandType, uint16_t commandSubType)
48 {
49 // 16: concat two uint16 into uint32
50 return ((uint32_t)commandType << 16) | commandSubType;
51 }
52 } // namespace
53
Instance()54 RSCommandFactory& RSCommandFactory::Instance()
55 {
56 static RSCommandFactory instance;
57 return instance;
58 }
59
Register(uint16_t type,uint16_t subtype,UnmarshallingFunc func)60 void RSCommandFactory::Register(uint16_t type, uint16_t subtype, UnmarshallingFunc func)
61 {
62 auto result = unmarshallingFuncLUT_.try_emplace(MakeKey(type, subtype), func);
63 if (!result.second) {
64 ROSEN_LOGD("RSCommandFactory::Register, Duplicate command & sub_command detected!"
65 " type: %{public}d subtype: %{public}d", type, subtype);
66 }
67 }
68
GetUnmarshallingFunc(uint16_t type,uint16_t subtype)69 UnmarshallingFunc RSCommandFactory::GetUnmarshallingFunc(uint16_t type, uint16_t subtype)
70 {
71 auto it = unmarshallingFuncLUT_.find(MakeKey(type, subtype));
72 if (it == unmarshallingFuncLUT_.end()) {
73 ROSEN_LOGE("RSCommandFactory::GetUnmarshallingFunc, Func is not found,"
74 " type=%{public}d subtype=%{public}d", type, subtype);
75 return nullptr;
76 }
77 return it->second;
78 }
79 } // namespace Rosen
80 } // namespace OHOS
81