• 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_CLIENT_WINDOW_MANAGER_CONTROLLER_CLIENT_H
17 #define FRAMEWORKS_WM_INCLUDE_CLIENT_WINDOW_MANAGER_CONTROLLER_CLIENT_H
18 
19 #include <list>
20 #include <pthread.h>
21 #include <vector>
22 
23 #include <refbase.h>
24 #include <surface.h>
25 #include <window_manager_service_client.h>
26 
27 #include "wayland_service.h"
28 #include "window_manager_server.h"
29 #include "wl_buffer_cache.h"
30 #include "wl_buffer.h"
31 #include "wl_display.h"
32 #include "wl_dma_buffer_factory.h"
33 #include "wl_shm_buffer_factory.h"
34 #include "wl_subsurface_factory.h"
35 #include "wl_surface_factory.h"
36 
37 namespace OHOS {
38 struct InnerWindowInfo {
39     sptr<WlSurface> wlSurface;
40     sptr<WlSubsurface> wlSubsurf;
41     sptr<WlBuffer> wlBuffer;
42     WindowConfig windowconfig;
43     uint32_t windowid;
44     uint32_t layerid;
45     uint32_t parentid;
46     uint32_t voLayerId;
47     sptr<Surface> surf;
48     sptr<IBufferConsumerListener> listener;
49     std::list<uint32_t> childIDList;
50     bool subwidow;
51     int32_t width;
52     int32_t height;
53     int32_t pos_x;
54     int32_t pos_y;
55     funcWindowInfoChange windowInfoChangeCb;
56     void (* onWindowCreateCb)(uint32_t pid);
57 
58     bool operator ==(const InnerWindowInfo &other) const
59     {
60         return windowid == other.windowid;
61     }
62 };
63 
64 class LayerControllerClient : public RefBase, public IWlBufferReleaseClazz {
65 public:
66     static sptr<LayerControllerClient> GetInstance();
67 
68     bool init(sptr<IWindowManagerService> &service);
69 
70     InnerWindowInfo *CreateWindow(int32_t id, WindowConfig &config);
71     InnerWindowInfo *CreateSubWindow(int32_t subid, int32_t parentid, WindowConfig &config);
72     void CreateWlBuffer(sptr<Surface>& surf, uint32_t id);
73     void DestroyWindow(int32_t id);
74     void Move(int32_t id, int32_t x, int32_t y);
75     void Show(int32_t id);
76     void Hide(int32_t id);
77     void ReSize(int32_t id, int32_t width, int32_t height);
78     void Rotate(int32_t id, int32_t type);
79     int32_t GetMaxWidth();
80     int32_t GetMaxHeight();
81     void ChangeWindowType(int32_t id, WindowType type);
82     void RegistWindowInfoChangeCb(int id, funcWindowInfoChange cb);
83     void RegistOnWindowCreateCb(int32_t id, void(* cb)(uint32_t pid));
84     void SendWindowCreate(uint32_t pid);
85 
86     InnerWindowInfo *GetInnerWindowInfoFromId(uint32_t windowid);
87     void RemoveInnerWindowInfo(uint32_t id);
88     static void *thread_display_dispatch(void *param);
89 
90 protected:
91     bool CreateSurface(int32_t id);
92     bool initScreen();
93 
94 private:
95     void SetSubSurfaceSize(int32_t id, int32_t width, int32_t height);
96 
97     static inline sptr<LayerControllerClient> instance = nullptr;
98     LayerControllerClient();
99     virtual ~LayerControllerClient();
100     virtual void OnWlBufferRelease(struct wl_buffer *wbuffer, int32_t fence) override;
101 
102     sptr<IWindowManagerService> wms = nullptr;
103     bool isInit = false;
104     std::mutex mutex;
105     std::mutex windowListMutex;
106     std::list<InnerWindowInfo> m_windowList;
107     uint32_t m_screenId = 0;
108     int32_t m_screenWidth = 0;
109     int32_t m_screenHeight = 0;
110 };
111 
112 class SurfaceListener : public IBufferConsumerListener {
113 public:
114     SurfaceListener(sptr<Surface>& surf, uint32_t windowid);
115     virtual ~SurfaceListener();
116 
117     virtual void OnBufferAvailable() override;
118 
119 private:
120     wptr<Surface> surface_;
121     uint32_t windowid_;
122 };
123 }
124 
125 #endif // FRAMEWORKS_WM_INCLUDE_CLIENT_WINDOW_MANAGER_CONTROLLER_CLIENT_H
126