• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef DRAWING_NATIVE_PIXEL_MAP_MANAGER_H
17 #define DRAWING_NATIVE_PIXEL_MAP_MANAGER_H
18 #include <mutex>
19 #include <unordered_map>
20 #include <memory>
21 
22 #ifdef OHOS_PLATFORM
23 #include "drawing_types.h"
24 #include "pixel_map.h"
25 #endif
26 
27 enum class NativePixelMapType : uint8_t {
28     OBJECT_UNKNOWN,
29     OBJECT_FROM_JS,
30     OBJECT_FROM_C
31 };
32 
33 class NativePixelMapManager {
34 public:
35     static NativePixelMapManager& GetInstance();
36     ~NativePixelMapManager() = default;
37 
38     void Register(void* handle, NativePixelMapType type);
39     void Unregister(void* handle);
40     NativePixelMapType GetNativePixelMapType(void* handle);
41 
42     NativePixelMapManager(const NativePixelMapManager&) = delete;
43     NativePixelMapManager(const NativePixelMapManager&&) = delete;
44     NativePixelMapManager& operator=(const NativePixelMapManager&) = delete;
45     NativePixelMapManager& operator=(const NativePixelMapManager&&) = delete;
46 private:
47     NativePixelMapManager() = default;
48     std::unordered_map<void*, NativePixelMapType> mapper_;
49     std::mutex mutex_;
50 };
51 
52 namespace OHOS {
53 namespace Rosen {
54 #ifdef OHOS_PLATFORM
55 std::shared_ptr<OHOS::Media::PixelMap> GetPixelMapFromNativePixelMap(OH_Drawing_PixelMap* pixelMap);
56 #endif
57 } // namespace Rosen
58 } // namespace OHOS
59 #endif // DRAWING_NATIVE_PIXEL_MAP_MANAGER_H