• 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_WINDOW_MANAGER_IMPL_H
17 #define FRAMEWORKS_WM_INCLUDE_WINDOW_MANAGER_IMPL_H
18 
19 #include <mutex>
20 #include <thread>
21 
22 #include <window_manager.h>
23 
24 #include <window_manager_service_client.h>
25 
26 #include "singleton_delegator.h"
27 #include "wayland_service.h"
28 #include "window_manager_server.h"
29 #include "wl_buffer_cache.h"
30 #include "wl_display.h"
31 #include "wl_dma_buffer_factory.h"
32 #include "wl_shm_buffer_factory.h"
33 #include "wl_subsurface_factory.h"
34 #include "wl_surface_factory.h"
35 
36 namespace OHOS {
37 class WindowManagerImpl : public WindowManager {
38 public:
39     static sptr<WindowManagerImpl> GetInstance();
40 
41     virtual GSError Init() override;
42 
43     virtual GSError GetDisplays(std::vector<struct WMDisplayInfo> &displays) const override;
44     virtual sptr<Window> GetWindowByID(int32_t wid) override;
45 
46     virtual GSError CreateWindow(sptr<Window> &window, const sptr<WindowOption> &option) override;
47     virtual GSError CreateSubwindow(sptr<Subwindow> &subwindow,
48                                     const sptr<Window> &window,
49                                     const sptr<SubwindowOption> &option) override;
50 
51     virtual GSError ListenNextScreenShot(int32_t id, IScreenShotCallback *cb) override;
52     virtual GSError ListenNextWindowShot(const sptr<Window> &window, IWindowShotCallback *cb) override;
53 
54     virtual GSError CreateVirtualDisplay(const sptr<VirtualDisplayOption> &option) override;
55     virtual GSError DestroyVirtualDisplay(uint32_t did) override;
56     virtual GSError SetDisplayMode(WMSDisplayMode mode) override;
57 
58 private:
59     WindowManagerImpl();
60     virtual ~WindowManagerImpl() override;
61     static inline sptr<WindowManagerImpl> instance = nullptr;
62     static inline SingletonDelegator<WindowManagerServiceClient> wmscDelegator;
63 
64     void InitSingleton();
65     void DeinitSingleton();
66 
67     void Deinit();
68 
69     std::mutex initMutex;
70     bool init = false;
71     bool initSingleton = false;
72     sptr<IWindowManagerService> wmservice = nullptr;
73 
74     using WptrWindow = wptr<Window>;
75     std::vector<WptrWindow> windowCache;
76 
77     sptr<WlDisplay> display = nullptr;
78     sptr<WlBufferCache> wlBufferCache = nullptr;
79     sptr<WlDMABufferFactory> wlDMABufferFactory = nullptr;
80     sptr<WlSHMBufferFactory> wlSHMBufferFactory = nullptr;
81     sptr<WlSubsurfaceFactory> wlSubsurfaceFactory = nullptr;
82     sptr<WlSurfaceFactory> wlSurfaceFactory = nullptr;
83     sptr<WindowManagerServer> windowManagerServer = nullptr;
84     sptr<WaylandService> waylandService = nullptr;
85     sptr<WindowManagerServiceClient> wmsc = nullptr;
86 };
87 } // namespace OHOS
88 
89 #endif // FRAMEWORKS_WM_INCLUDE_WINDOW_MANAGER_IMPL_H
90