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 INTERFACES_INNERKITS_WM_WINDOW_MANAGER_H 17 #define INTERFACES_INNERKITS_WM_WINDOW_MANAGER_H 18 19 #include "window_manager_common.h" 20 21 #include <cstdio> 22 #include <memory> 23 24 #include <refbase.h> 25 #include <surface.h> 26 #include <../wmclient/iscreen_shot_callback.h> 27 #include <../wmclient/iwindow_shot_callback.h> 28 29 namespace OHOS { 30 /** 31 * @brief The IWindowManager class is an abstract definition of windows manager. 32 * Provides a series of client/interfaces for window management, event processing, etc. 33 */ 34 35 class WindowBase { 36 public: 37 WindowBase(int32_t windowid, sptr<Surface>& surface); 38 virtual ~WindowBase(); 39 40 void GetRequestConfig(BufferRequestConfig &config); 41 void SetRequestConfig(BufferRequestConfig &config); 42 void RegistWindowInfoChangeCb(funcWindowInfoChange cb); 43 44 int32_t GetWindowID(); 45 virtual sptr<Surface> GetSurface(); 46 47 protected: 48 int32_t m_windowid; 49 sptr<Surface> surface_; 50 BufferRequestConfig config_; 51 }; 52 53 class Window : public WindowBase { 54 public: 55 Window(int32_t windowid, sptr<Surface>& surface); 56 ~Window(); 57 58 void Show(); 59 void Hide(); 60 void Move(int32_t x, int32_t y); 61 void SwitchTop(); 62 void ChangeWindowType(WindowType type); 63 void ReSize(int32_t width, int32_t height); 64 void Rotate(rotateType type); 65 void RegistOnWindowCreateCb(void(* cb)(uint32_t pid)); 66 }; 67 68 class SubWindow : public WindowBase { 69 public: 70 SubWindow(int32_t windowid, sptr<Surface>& surface); 71 virtual ~SubWindow(); 72 73 virtual void Move(int32_t x, int32_t y); 74 virtual void SetSubWindowSize(int32_t width, int32_t height); 75 }; 76 77 class ScreenShotCallback : public RefBase { 78 public: OnScreenShot(const struct WMImageInfo & info)79 virtual void OnScreenShot(const struct WMImageInfo &info){} 80 }; 81 82 class WindowShotCallback : public RefBase { 83 public: OnWindowShot(const struct WMImageInfo & info)84 virtual void OnWindowShot(const struct WMImageInfo &info){} 85 }; 86 87 class WindowManager : public RefBase { 88 public: 89 static sptr<WindowManager> GetInstance(); 90 91 std::unique_ptr<Window> CreateWindow(WindowConfig *config); 92 std::unique_ptr<SubWindow> CreateSubWindow(int32_t parentid, WindowConfig *config); 93 void StartShotScreen(IScreenShotCallback *cb); 94 void StartShotWindow(int32_t id, IWindowShotCallback *cb); 95 int32_t GetMaxWidth(); 96 int32_t GetMaxHeight(); 97 void SwitchTop(int windowId); 98 void DestroyWindow(int windowId); 99 private: 100 static sptr<WindowManager> instance; 101 WindowManager(); 102 virtual ~WindowManager(); 103 104 void init(); 105 }; 106 } 107 108 #endif // INTERFACES_INNERKITS_WM_WINDOW_MANAGER_H 109