• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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_SCENE_SESSION_DIRTY_MANAGER_H
17 #define OHOS_ROSEN_SCENE_SESSION_DIRTY_MANAGER_H
18 
19 
20 #include <map>
21 
22 #include "common/rs_vector4.h"
23 #include "display_manager.h"
24 #include "session/host/include/scene_session.h"
25 #include "session/screen/include/screen_session.h"
26 #include "screen_session_manager/include/screen_session_manager.h"
27 #include "input_manager.h"
28 
29 namespace OHOS::Rosen {
30 struct SecSurfaceInfo;
31 struct SecRectInfo;
32 MMI::Direction ConvertDegreeToMMIRotation(float degree);
33 MMI::Rotation ConvertToMMIRotation(float degree);
34 std::string DumpWindowInfo(const MMI::WindowInfo& info);
35 std::string DumpRect(const std::vector<MMI::Rect>& rects);
36 
37 struct SingleHandData {
38     float scaleX = 1.0f;
39     float scaleY = 1.0f;
40     float singleHandX = 0.f;
41     float singleHandY = 0.f;
42     float pivotX = 0.f;
43     float pivotY = 0.f;
44     SingleHandMode mode = SingleHandMode::MIDDLE;
45 };
46 
47 class SceneSessionDirtyManager {
48 private:
49     enum WindowAction : uint32_t {
50         UNKNOWN = 0,
51         WINDOW_ADD,
52         WINDOW_DELETE,
53         WINDOW_CHANGE,
54         WINDOW_ADD_END
55     };
56 
57 using ScreenInfoChangeListener = std::function<void(int32_t)>;
58 using FlushWindowInfoCallback = std::function<void()>;
59 public:
60     SceneSessionDirtyManager() = default;
61     virtual ~SceneSessionDirtyManager() = default;
62 
63     void NotifyWindowInfoChange(const sptr<SceneSession>& sceneSession,
64         const WindowUpdateType& type, const bool startMoving = false);
65     std::pair<std::vector<MMI::WindowInfo>, std::vector<std::shared_ptr<Media::PixelMap>>>
66         GetFullWindowInfoList();
67     void RegisterFlushWindowInfoCallback(FlushWindowInfoCallback&& callback);
68     void ResetSessionDirty();
69     void UpdateSecSurfaceInfo(const std::map<uint64_t, std::vector<SecSurfaceInfo>>& secSurfaceInfoMap);
70     void UpdateConstrainedModalUIExtInfo(const std::map<uint64_t,
71         std::vector<SecSurfaceInfo>>& constrainedModalUIExtInfoMap);
72     bool GetLastConstrainedModalUIExtInfo(const sptr<SceneSession>& sceneSession,
73         SecSurfaceInfo& constrainedModalUIExtInfo);
74 
75 private:
76     std::vector<MMI::WindowInfo> FullSceneSessionInfoUpdate() const;
77     bool IsFilterSession(const sptr<SceneSession>& sceneSession) const;
78     std::pair<MMI::WindowInfo, std::shared_ptr<Media::PixelMap>>
79         GetWindowInfo(const sptr<SceneSession>& sceneSession, const WindowAction& action) const;
80     SingleHandData GetSingleHandData(const sptr<SceneSession>& sceneSession) const;
81     void CalNotRotateTransform(const sptr<SceneSession>& sceneSession, Matrix3f& transform,
82         bool useUIExtension = false) const;
83     void CalTransform(const sptr<SceneSession>& sceneSession, Matrix3f& transform,
84         const SingleHandData& singleHandData, bool useUIExtension = false) const;
85     void UpdatePrivacyMode(const sptr<SceneSession>& sceneSession,
86         MMI::WindowInfo& windowInfo) const;
87     std::map<int32_t, sptr<SceneSession>> GetDialogSessionMap(
88         const std::map<int32_t, sptr<SceneSession>>& sessionMap) const;
89     void UpdateHotAreas(const sptr<SceneSession>& sceneSession, std::vector<MMI::Rect>& touchHotAreas,
90         std::vector<MMI::Rect>& pointerHotAreas) const;
91     void UpdateDefaultHotAreas(sptr<SceneSession> sceneSession, std::vector<MMI::Rect>& touchHotAreas,
92         std::vector<MMI::Rect>& pointerHotAreas) const;
93     void UpdatePointerAreas(sptr<SceneSession> sceneSession, std::vector<int32_t>& pointerChangeAreas) const;
94     void UpdateWindowFlags(DisplayId displayId, const sptr<SceneSession>& sceneSession,
95         MMI::WindowInfo& windowInfo) const;
96     void AddModalExtensionWindowInfo(std::vector<MMI::WindowInfo>& windowInfoList, MMI::WindowInfo windowInfo,
97         const sptr<SceneSession>& sceneSession, const ExtensionWindowEventInfo& extensionInfo);
98     void GetModalUIExtensionInfo(std::vector<MMI::WindowInfo>& windowInfoList,
99         const sptr<SceneSession>& sceneSession, const MMI::WindowInfo& hostWindowInfo);
100     std::vector<MMI::WindowInfo> GetSecSurfaceWindowinfoList(const sptr<SceneSession>& sceneSession,
101         const MMI::WindowInfo& hostWindowinfo, const Matrix3f& hostTransform) const;
102     MMI::WindowInfo GetSecComponentWindowInfo(const SecSurfaceInfo& secSurfaceInfo,
103         const MMI::WindowInfo& hostWindowinfo, const sptr<SceneSession>& sceneSession,
104         const Matrix3f hostTransform) const;
105     MMI::WindowInfo GetHostComponentWindowInfo(const SecSurfaceInfo& secSurfaceInfo,
106         const MMI::WindowInfo& hostWindowinfo, const Matrix3f hostTransform) const;
107     MMI::WindowInfo MakeWindowInfoFormHostWindow(const MMI::WindowInfo& hostWindowinfo) const;
108     void ResetFlushWindowInfoTask();
109     void CheckIfUpdatePointAreas(WindowType windowType, const sptr<SceneSession>& sceneSession,
110         const sptr<WindowSessionProperty>& windowSessionProperty, std::vector<int32_t>& pointerChangeAreas) const;
111 
112     /*
113      * Compatible Mode
114      */
115     bool UpdateModalExtensionInCompatStatus(const sptr<SceneSession>& sceneSession, Matrix3f& transform) const;
116 
117     std::mutex mutexlock_;
118     mutable std::shared_mutex secSurfaceInfoMutex_;
119     mutable std::shared_mutex constrainedModalUIExtInfoMutex_;
120     FlushWindowInfoCallback flushWindowInfoCallback_;
121     std::atomic_bool sessionDirty_ { false };
122     std::atomic_bool hasPostTask_ { false };
123     std::map<uint64_t, std::vector<SecSurfaceInfo>> secSurfaceInfoMap_;
124     std::map<uint64_t, std::vector<SecSurfaceInfo>> constrainedModalUIExtInfoMap_;
125 };
126 } //namespace OHOS::Rosen
127 
128 #endif