1 /* 2 * Copyright (c) 2021-2023 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 OHOS_ROSEN_WINDOW_NODE_H 17 #define OHOS_ROSEN_WINDOW_NODE_H 18 19 #include <ipc_skeleton.h> 20 #include <refbase.h> 21 #include <ui/rs_surface_node.h> 22 #include <ui/rs_ui_context.h> 23 #include "zidl/window_interface.h" 24 #include "window_manager_hilog.h" 25 #include "window_node_state_machine.h" 26 #include "window_visibility_info.h" 27 28 #ifdef POWER_MANAGER_ENABLE 29 #include <running_lock.h> 30 #endif 31 32 namespace OHOS { 33 namespace Rosen { 34 class WindowNode : public RefBase { 35 public: WindowNode(const sptr<WindowProperty> & property,const sptr<IWindow> & window,std::shared_ptr<RSSurfaceNode> surfaceNode)36 WindowNode(const sptr<WindowProperty>& property, const sptr<IWindow>& window, 37 std::shared_ptr<RSSurfaceNode> surfaceNode) 38 : surfaceNode_(surfaceNode), property_(property), windowToken_(window) 39 { 40 if (property != nullptr) { 41 abilityInfo_ = property->GetAbilityInfo(); 42 } 43 } WindowNode(const sptr<WindowProperty> & property,const sptr<IWindow> & window,std::shared_ptr<RSSurfaceNode> surfaceNode,int32_t pid,int32_t uid)44 WindowNode(const sptr<WindowProperty>& property, const sptr<IWindow>& window, 45 std::shared_ptr<RSSurfaceNode> surfaceNode, int32_t pid, int32_t uid) 46 : surfaceNode_(surfaceNode), property_(property), windowToken_(window), callingPid_(pid), callingUid_(uid) 47 { 48 inputCallingPid_ = pid; 49 if (property != nullptr) { 50 abilityInfo_ = property->GetAbilityInfo(); 51 } 52 } WindowNode()53 WindowNode() : property_(new WindowProperty()) 54 { 55 } WindowNode(const sptr<WindowProperty> & property)56 explicit WindowNode(const sptr<WindowProperty>& property) : property_(property) 57 { 58 } 59 ~WindowNode(); 60 61 void SetDisplayId(DisplayId displayId); 62 void SetEntireWindowTouchHotArea(const Rect& rect); 63 void SetEntireWindowPointerHotArea(const Rect& rect); 64 void SetWindowRect(const Rect& rect); 65 void SetDecorEnable(bool decorEnable); 66 void SetDecoStatus(bool decoStatus); 67 void SetRequestRect(const Rect& rect); 68 void SetWindowProperty(const sptr<WindowProperty>& property); 69 void SetSystemBarProperty(WindowType type, const SystemBarProperty& property); 70 void SetWindowMode(WindowMode mode); 71 void SetBrightness(float brightness); 72 void SetFocusable(bool focusable); 73 void SetTouchable(bool touchable); 74 void SetTurnScreenOn(bool turnScreenOn); 75 void SetKeepScreenOn(bool keepScreenOn); 76 void SetCallingWindow(uint32_t windowId); 77 void SetInputEventCallingPid(int32_t pid); 78 void SetCallingPid(int32_t pid); 79 void SetCallingUid(int32_t uid); 80 void SetWindowToken(sptr<IWindow> window); 81 uint32_t GetCallingWindow() const; 82 void SetWindowSizeChangeReason(WindowSizeChangeReason reason); 83 void SetRequestedOrientation(Orientation orientation); 84 void SetShowingDisplays(const std::vector<DisplayId>& displayIdVec); 85 void SetWindowModeSupportType(uint32_t windowModeSupportType); 86 void SetDragType(DragType dragType); 87 void SetOriginRect(const Rect& rect); 88 void SetTouchHotAreas(const std::vector<Rect>& rects); 89 void SetPointerHotAreas(const std::vector<Rect>& rects); 90 void SetWindowSizeLimits(const WindowLimits& sizeLimits); 91 void SetWindowUpdatedSizeLimits(const WindowLimits& sizeLimits); 92 void ComputeTransform(); 93 void SetTransform(const Transform& trans); 94 void SetSnapshot(std::shared_ptr<Media::PixelMap> pixelMap); 95 std::shared_ptr<Media::PixelMap> GetSnapshot(); 96 Transform GetZoomTransform() const; 97 void UpdateZoomTransform(const Transform& trans, bool isDisplayZoomOn); 98 void SetAspectRatio(float ratio); 99 void SetWindowGravity(WindowGravity gravity, uint32_t percent); 100 void SetVisibilityState(WindowVisibilityState state); 101 102 const sptr<IWindow>& GetWindowToken() const; 103 uint32_t GetWindowId() const; 104 uint32_t GetParentId() const; 105 const std::string& GetWindowName() const; 106 DisplayId GetDisplayId() const; 107 Rect GetEntireWindowTouchHotArea() const; 108 Rect GetEntireWindowPointerHotArea() const; 109 Rect GetWindowRect() const; 110 bool GetDecoStatus() const; 111 Rect GetRequestRect() const; 112 WindowType GetWindowType() const; 113 WindowMode GetWindowMode() const; 114 float GetBrightness() const; 115 bool IsTurnScreenOn() const; 116 bool IsKeepScreenOn() const; 117 uint32_t GetWindowFlags() const; 118 const sptr<WindowProperty>& GetWindowProperty() const; 119 int32_t GetInputEventCallingPid() const; 120 int32_t GetCallingPid() const; 121 int32_t GetCallingUid() const; 122 const std::unordered_map<WindowType, SystemBarProperty>& GetSystemBarProperty() const; 123 bool IsSplitMode() const; 124 WindowSizeChangeReason GetWindowSizeChangeReason() const; 125 Orientation GetRequestedOrientation() const; 126 std::vector<DisplayId> GetShowingDisplays() const; 127 uint32_t GetWindowModeSupportType() const; 128 DragType GetDragType() const; 129 bool GetStretchable() const; 130 const Rect& GetOriginRect() const; 131 void ResetWindowSizeChangeReason(); 132 void GetTouchHotAreas(std::vector<Rect>& rects) const; 133 void GetPointerHotAreas(std::vector<Rect>& rects) const; 134 uint32_t GetAccessTokenId() const; 135 WindowLimits GetWindowSizeLimits() const; 136 WindowLimits GetWindowUpdatedSizeLimits() const; 137 float GetAspectRatio() const; 138 void GetWindowGravity(WindowGravity& gravity, uint32_t& percent) const; 139 WindowVisibilityState GetVisibilityState() const; 140 bool GetTouchable() const; 141 142 bool EnableDefaultAnimation(bool animationPlayed); 143 144 /* 145 * RS Client Multi Instance 146 */ 147 std::shared_ptr<RSUIContext> GetRSUIContext() const; 148 149 sptr<WindowNode> parent_; 150 std::vector<sptr<WindowNode>> children_; 151 std::shared_ptr<RSSurfaceNode> surfaceNode_; 152 std::shared_ptr<RSSurfaceNode> leashWinSurfaceNode_ = nullptr; 153 std::shared_ptr<RSSurfaceNode> startingWinSurfaceNode_ = nullptr; 154 std::shared_ptr<RSSurfaceNode> closeWinSurfaceNode_ = nullptr; 155 sptr<IRemoteObject> dialogTargetToken_ = nullptr; 156 sptr<IRemoteObject> abilityToken_ = nullptr; 157 158 #ifdef POWER_MANAGER_ENABLE 159 std::shared_ptr<PowerMgr::RunningLock> keepScreenLock_ = nullptr; 160 #endif 161 162 int32_t priority_ { 0 }; 163 uint32_t zOrder_ { 0 }; 164 bool requestedVisibility_ { false }; 165 bool currentVisibility_ { false }; 166 WindowVisibilityState visibilityState_ { WINDOW_LAYER_STATE_MAX }; 167 bool isAppCrash_ { false }; 168 bool isPlayAnimationShow_ { false }; // delete when enable state machine 169 bool isPlayAnimationHide_ { false }; // delete when enable state machine 170 bool startingWindowShown_ { false }; 171 bool firstFrameAvailable_ { false }; 172 bool isShowingOnMultiDisplays_ { false }; 173 std::vector<DisplayId> showingDisplays_; 174 AbilityInfo abilityInfo_; 175 WindowNodeStateMachine stateMachine_; 176 bool isFocused_ { false }; 177 178 private: 179 sptr<WindowProperty> property_ = nullptr; 180 sptr<IWindow> windowToken_ = nullptr; 181 Rect entireWindowTouchHotArea_ { 0, 0, 0, 0 }; 182 Rect entireWindowPointerHotArea_ { 0, 0, 0, 0 }; 183 std::vector<Rect> touchHotAreas_; // coordinates relative to display. 184 std::vector<Rect> pointerHotAreas_; // coordinates relative to display. 185 std::shared_ptr<Media::PixelMap> snapshot_; 186 int32_t callingPid_ = { 0 }; 187 int32_t inputCallingPid_ = { 0 }; 188 int32_t callingUid_ = { 0 }; 189 WindowSizeChangeReason windowSizeChangeReason_ {WindowSizeChangeReason::UNDEFINED}; 190 }; 191 } // Rosen 192 } // OHOS 193 #endif // OHOS_ROSEN_WINDOW_NODE_H 194