• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 "ui_effect/mask/include/mask_unmarshalling_singleton.h"
17 #include "platform/common/rs_log.h"
18 
19 namespace OHOS {
20 namespace Rosen {
21 
GetInstance()22 MaskUnmarshallingSingleton& MaskUnmarshallingSingleton::GetInstance()
23 {
24     static MaskUnmarshallingSingleton instance;
25     return instance;
26 }
27 
RegisterCallback(uint16_t type,MaskUnmarshallingSingleton::UnmarshallingFunc func)28 void MaskUnmarshallingSingleton::RegisterCallback(
29     uint16_t type, MaskUnmarshallingSingleton::UnmarshallingFunc func)
30 {
31     std::lock_guard<std::mutex> lock(mutex_);
32     unmarshallingFuncs_.insert_or_assign(type, func);
33     RS_LOGD("[ui_effect] Mask register unmarshalling callback, type is %{public}hu", type);
34 }
35 
UnregisterCallback(uint16_t type)36 void MaskUnmarshallingSingleton::UnregisterCallback(uint16_t type)
37 {
38     std::lock_guard<std::mutex> lock(mutex_);
39     unmarshallingFuncs_.erase(type);
40     RS_LOGD("[ui_effect] Mask unregister unmarshalling callback, type is %{public}hu", type);
41 }
42 
GetCallback(uint16_t type)43 MaskUnmarshallingSingleton::UnmarshallingFunc MaskUnmarshallingSingleton::GetCallback(uint16_t type)
44 {
45     std::lock_guard<std::mutex> lock(mutex_);
46     auto it = unmarshallingFuncs_.find(type);
47     if (it != unmarshallingFuncs_.end()) {
48         return it->second;
49     }
50     RS_LOGE("[ui_effect] MaskUnmarshallingSingleton GetCallback find failed, type is %{public}hu", type);
51     return nullptr;
52 }
53 
54 } // namespace Rosen
55 } // namespace OHOS