1 /*
2  * Copyright (c) 2024 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 "native_pixel_map_manager.h"
17 
GetInstance()18 NativePixelMapManager& NativePixelMapManager::GetInstance()
19 {
20     static NativePixelMapManager instance;
21     return instance;
22 }
23 
Register(void * handle,NativePixelMapType type)24 void NativePixelMapManager::Register(void* handle, NativePixelMapType type)
25 {
26     std::lock_guard<std::mutex> lck(mutex_);
27     mapper_.emplace(handle, type);
28 }
29 
Unregister(void * handle)30 void NativePixelMapManager::Unregister(void* handle)
31 {
32     std::lock_guard<std::mutex> lck(mutex_);
33     mapper_.erase(handle);
34 }
35 
GetNativePixelMapType(void * handle)36 NativePixelMapType NativePixelMapManager::GetNativePixelMapType(void* handle)
37 {
38     std::lock_guard<std::mutex> lck(mutex_);
39     auto iter = mapper_.find(handle);
40     if (iter == mapper_.end()) {
41         return NativePixelMapType::OBJECT_UNKNOWN;
42     }
43     return iter->second;
44 }