• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 FRAMEWORKS_WM_INCLUDE_WL_SHM_BUFFER_FACTORY_H
17 #define FRAMEWORKS_WM_INCLUDE_WL_SHM_BUFFER_FACTORY_H
18 
19 #include <refbase.h>
20 
21 #include "singleton_delegator.h"
22 #include "wayland_service.h"
23 #include "wl_buffer.h"
24 
25 namespace OHOS {
26 class WlSHMBufferFactory : public RefBase {
27 public:
28     static sptr<WlSHMBufferFactory> GetInstance();
29 
30     MOCKABLE void Init();
31     MOCKABLE void Deinit();
32 
33     MOCKABLE sptr<WlBuffer> Create(uint32_t w, uint32_t h, int32_t format);
34 
35 private:
36     WlSHMBufferFactory() = default;
37     MOCKABLE ~WlSHMBufferFactory() = default;
38     static inline sptr<WlSHMBufferFactory> instance = nullptr;
39     static inline SingletonDelegator<WlSHMBufferFactory> delegator;
40 
41     static void OnAppear(const GetServiceFunc get, const std::string &iname, uint32_t ver);
42     static inline struct wl_shm *shmbuf = nullptr;
43 
44     wl_shm_pool *CreatePool(uint32_t mmapSize, int32_t &fd, void *&mmapPtr);
45 };
46 } // namespace OHOS
47 
48 #endif // FRAMEWORKS_WM_INCLUDE_WL_SHM_BUFFER_FACTORY_H
49