• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_node_command.h"
25 #include "command/rs_display_node_command.h"
26 #include "command/rs_node_command.h"
27 #include "command/rs_proxy_node_command.h"
28 #include "command/rs_root_node_command.h"
29 #include "command/rs_surface_node_command.h"
30 // animation
31 #include "command/rs_animation_command.h"
32 #undef ROSEN_INSTANTIATE_COMMAND_TEMPLATE
33 
34 namespace OHOS {
35 namespace Rosen {
36 
37 namespace {
MakeKey(uint16_t commandType,uint16_t commandSubType)38 inline uint32_t MakeKey(uint16_t commandType, uint16_t commandSubType)
39 {
40     // 16: concat two uint16 into uint32
41     return ((uint32_t)commandType << 16) | commandSubType;
42 }
43 } // namespace
44 
Instance()45 RSCommandFactory& RSCommandFactory::Instance()
46 {
47     static RSCommandFactory instance;
48     return instance;
49 }
50 
Register(uint16_t type,uint16_t subtype,UnmarshallingFunc func)51 void RSCommandFactory::Register(uint16_t type, uint16_t subtype, UnmarshallingFunc func)
52 {
53     auto result = unmarshallingFuncLUT_.try_emplace(MakeKey(type, subtype), func);
54     if (!result.second) {
55         ROSEN_LOGE("RSCommandFactory::Register, Duplicate command & sub_command detected! type: %d subtype: %d", type,
56             subtype);
57     }
58 }
59 
GetUnmarshallingFunc(uint16_t type,uint16_t subtype)60 UnmarshallingFunc RSCommandFactory::GetUnmarshallingFunc(uint16_t type, uint16_t subtype)
61 {
62     auto it = unmarshallingFuncLUT_.find(MakeKey(type, subtype));
63     if (it == unmarshallingFuncLUT_.end()) {
64         ROSEN_LOGE("RSCommandFactory::GetUnmarshallingFunc, Func is not found, type=%d subtype=%d", type, subtype);
65         return nullptr;
66     }
67     return it->second;
68 }
69 } // namespace Rosen
70 } // namespace OHOS
71