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_WMSERVICE_INCLUDE_WINDOW_MANAGER_SERVICE_PROXY_H 17 #define FRAMEWORKS_WMSERVICE_INCLUDE_WINDOW_MANAGER_SERVICE_PROXY_H 18 19 #include <iwindow_manager_service.h> 20 21 #include <ianimation_service.h> 22 #include <map> 23 #include <mutex> 24 #include <queue> 25 #include <wms-client-protocol.h> 26 27 namespace OHOS { 28 class WindowManagerServiceProxy : public IWindowManagerService { 29 public: 30 WindowManagerServiceProxy(struct wms *wms, struct wl_display *display, sptr<IAnimationService> &as); 31 virtual ~WindowManagerServiceProxy() = default; 32 33 virtual GSError GetDisplays(std::vector<struct WMDisplayInfo> &displays) override; 34 virtual sptr<PromisePowerStatus> GetDisplayPower(int32_t did) override; 35 virtual sptr<PromiseGSError> SetDisplayPower(int32_t did, DispPowerStatus status) override; 36 virtual sptr<PromiseBacklight> GetDisplayBacklight(int32_t did) override; 37 virtual sptr<PromiseGSError> SetDisplayBacklight(int32_t did, uint32_t level) override; 38 virtual GSError GetDisplayModes(uint32_t &displayModes) override; 39 virtual sptr<PromiseGSError> SetDisplayMode(WMSDisplayMode modes) override; 40 virtual GSError AddDisplayChangeListener(IWindowManagerDisplayListenerClazz *listener) override; 41 virtual sptr<PromiseGSError> OnWindowListChange(IWindowChangeListenerClazz *listener) override; 42 43 virtual GSError SetDisplayDirection(WMSDisplayDirection direction) override; 44 virtual GSError OnDisplayDirectionChange(DisplayDirectionChangeFunc func) override; 45 46 virtual sptr<PromiseWMSImageInfo> ShotScreen(int32_t did) override; 47 virtual sptr<PromiseWMSImageInfo> ShotWindow(int32_t wid) override; 48 49 virtual sptr<PromiseGSError> SetStatusBarVisibility(bool visibility) override; 50 virtual sptr<PromiseGSError> SetNavigationBarVisibility(bool visibility) override; 51 52 virtual sptr<PromiseGSError> DestroyWindow(int32_t wid) override; 53 virtual sptr<PromiseGSError> SwitchTop(int32_t wid) override; 54 virtual sptr<PromiseGSError> Show(int32_t wid) override; 55 virtual sptr<PromiseGSError> Hide(int32_t wid) override; 56 virtual sptr<PromiseGSError> Move(int32_t wid, int32_t x, int32_t y) override; 57 virtual sptr<PromiseGSError> Resize(int32_t wid, uint32_t width, uint32_t height) override; 58 virtual sptr<PromiseGSError> ScaleTo(int32_t wid, uint32_t width, uint32_t height) override; 59 virtual sptr<PromiseGSError> SetWindowType(int32_t wid, WindowType type) override; 60 virtual sptr<PromiseGSError> SetWindowMode(int32_t wid, WindowMode mode) override; 61 62 virtual sptr<PromiseGSError> CreateVirtualDisplay(int32_t x, int32_t y, int32_t width, int32_t height) override; 63 virtual sptr<PromiseGSError> DestroyVirtualDisplay(uint32_t did) override; 64 65 virtual GSError StartRotationAnimation(uint32_t did, int32_t degree) override; 66 67 virtual sptr<PromiseGSError> SetSplitMode(SplitMode mode, int32_t x, int32_t y) override; 68 69 virtual GSError CreateLaunchPage(const std::string &filename) override; 70 virtual GSError CancelLaunchPage() override; 71 72 static void OnReply(wms_error); 73 static void OnDisplayChange(uint32_t, const char *, wms_screen_status, int32_t, int32_t, wms_screen_type type); 74 static void OnDisplayPower(uint32_t, int32_t); 75 static void OnDisplayBacklight(uint32_t, uint32_t); 76 static void OnDisplayModeChange(uint32_t); 77 static void OnGlobalWindowStatus(uint32_t pid, uint32_t wid, uint32_t status); 78 static void OnScreenShot(wms_error, uint32_t, int32_t, int32_t, int32_t, int32_t, uint32_t, uint32_t, uint32_t); 79 static void OnWindowShot(wms_error, uint32_t, int32_t, int32_t, int32_t, int32_t, uint32_t, uint32_t, uint32_t); 80 81 private: 82 struct wms *wms = nullptr; 83 struct wl_display *display = nullptr; 84 sptr<IAnimationService> as = nullptr; 85 static inline IWindowManagerDisplayListenerClazz *displayListener = nullptr; 86 static inline IWindowChangeListenerClazz *globalWindowChangeListener = nullptr; 87 88 using SptrPromiseGSError = sptr<PromiseGSError>; 89 using SptrPromiseWMSImageInfo = sptr<PromiseWMSImageInfo>; 90 using SptrPromiseBacklight = sptr<PromiseBacklight>; 91 using SptrPromisePowerStatus = sptr<PromisePowerStatus>; 92 93 static inline std::vector<struct WMDisplayInfo> displays; 94 static inline uint32_t displayModes = 0; 95 96 static inline std::queue<SptrPromiseBacklight> backlightPromiseQueue; 97 static inline std::mutex backlightPromiseQueueMutex; 98 99 static inline std::queue<SptrPromisePowerStatus> powerStatusPromiseQueue; 100 static inline std::mutex powerStatusPromiseQueueMutex; 101 102 static inline std::queue<SptrPromiseGSError> promiseQueue; 103 static inline std::mutex promiseQueueMutex; 104 105 static inline std::map<int32_t, SptrPromiseWMSImageInfo> screenShotPromises; 106 static inline std::mutex screenShotPromisesMutex; 107 108 static inline std::map<int32_t, SptrPromiseWMSImageInfo> windowShotPromises; 109 static inline std::mutex windowShotPromisesMutex; 110 }; 111 } // namespace OHOS 112 113 #endif // FRAMEWORKS_WMSERVICE_INCLUDE_WINDOW_MANAGER_SERVICE_PROXY_H 114