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 #include "scene_session_dirty_manager.h"
17
18 #include <parameters.h>
19 #include "screen_session_manager/include/screen_session_manager_client.h"
20 #include "session_manager/include/scene_session_manager.h"
21 #include "window_helper.h"
22 #include "fold_screen_state_internel.h"
23
24 namespace OHOS::Rosen {
25 namespace {
26 constexpr float DIRECTION0 = 0 ;
27 constexpr float DIRECTION90 = 90 ;
28 constexpr float DIRECTION180 = 180 ;
29 constexpr float DIRECTION270 = 270 ;
30 constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "SceneSessionDirtyManager"};
31 constexpr unsigned int POINTER_CHANGE_AREA_COUNT = 8;
32 constexpr int POINTER_CHANGE_AREA_SIXTEEN = 16;
33 constexpr int POINTER_CHANGE_AREA_DEFAULT = 0;
34 constexpr int POINTER_CHANGE_AREA_FIVE = 5;
35 constexpr unsigned int TRANSFORM_DATA_LEN = 9;
36 constexpr int UPDATE_TASK_DURATION = 10;
37 const std::string UPDATE_WINDOW_INFO_TASK = "UpdateWindowInfoTask";
38 static int32_t g_screenRotationOffset = system::GetIntParameter<int32_t>("const.fold.screen_rotation.offset", 0);
39 constexpr float ZORDER_UIEXTENSION_INDEX = 0.1;
40
AdjustMMIRotationFromDisplayMode(MMI::DisplayMode displayMode,MMI::Direction & rotation)41 void AdjustMMIRotationFromDisplayMode(MMI::DisplayMode displayMode, MMI::Direction& rotation)
42 {
43 if (displayMode == MMI::DisplayMode::FULL && g_screenRotationOffset != 0) {
44 switch (rotation) {
45 case MMI::DIRECTION0:
46 rotation = MMI::DIRECTION90;
47 break;
48 case MMI::DIRECTION90:
49 rotation = MMI::DIRECTION180;
50 break;
51 case MMI::DIRECTION180:
52 rotation = MMI::DIRECTION270;
53 break;
54 case MMI::DIRECTION270:
55 rotation = MMI::DIRECTION0;
56 break;
57 default:
58 rotation = MMI::DIRECTION0;
59 break;
60 }
61 } else if (displayMode == MMI::DisplayMode::MAIN && FoldScreenStateInternel::IsSingleDisplayPocketFoldDevice()) {
62 switch (rotation) {
63 case MMI::DIRECTION0:
64 rotation = MMI::DIRECTION270;
65 break;
66 case MMI::DIRECTION90:
67 rotation = MMI::DIRECTION0;
68 break;
69 case MMI::DIRECTION180:
70 rotation = MMI::DIRECTION90;
71 break;
72 case MMI::DIRECTION270:
73 rotation = MMI::DIRECTION180;
74 break;
75 default:
76 rotation = MMI::DIRECTION0;
77 break;
78 }
79 }
80 }
81 } // namespace
82
operator ==(const MMI::Rect & left,const MMI::Rect & right)83 static bool operator==(const MMI::Rect& left, const MMI::Rect& right)
84 {
85 return ((left.x == right.x) && (left.y == right.y) && (left.width == right.width) && (left.height == right.height));
86 }
87
ConvertDegreeToMMIRotation(float degree,MMI::DisplayMode displayMode)88 MMI::Direction ConvertDegreeToMMIRotation(float degree, MMI::DisplayMode displayMode)
89 {
90 MMI::Direction rotation = MMI::DIRECTION0;
91 if (NearEqual(degree, DIRECTION0)) {
92 rotation = MMI::DIRECTION0;
93 } else if (NearEqual(degree, DIRECTION90)) {
94 rotation = MMI::DIRECTION90;
95 } else if (NearEqual(degree, DIRECTION180)) {
96 rotation = MMI::DIRECTION180;
97 } else if (NearEqual(degree, DIRECTION270)) {
98 rotation = MMI::DIRECTION270;
99 }
100 AdjustMMIRotationFromDisplayMode(displayMode, rotation);
101 return rotation;
102 }
103
CmpMMIWindowInfo(const MMI::WindowInfo & a,const MMI::WindowInfo & b)104 bool CmpMMIWindowInfo(const MMI::WindowInfo& a, const MMI::WindowInfo& b)
105 {
106 return a.defaultHotAreas.size() > b.defaultHotAreas.size();
107 }
108
CalRotationToTranslate(const MMI::Direction & displayRotation,float width,float height,const Vector2f & offset,float & rotate)109 Vector2f CalRotationToTranslate(const MMI::Direction& displayRotation, float width, float height,
110 const Vector2f& offset, float& rotate)
111 {
112 Vector2f translate = offset;
113 switch (displayRotation) {
114 case MMI::DIRECTION0: {
115 break;
116 }
117 case MMI::DIRECTION270: {
118 translate.x_ = offset.y_;
119 translate.y_ = height - offset.x_;
120 rotate = -M_PI_2;
121 break;
122 }
123 case MMI::DIRECTION180:
124 translate.x_ = width - offset.x_;
125 translate.y_ = height - offset.y_;
126 rotate = M_PI;
127 break;
128 case MMI::DIRECTION90: {
129 translate.x_ = width - offset.y_;
130 translate.y_ = offset.x_;
131 rotate = M_PI_2;
132 break;
133 }
134 default:
135 break;
136 }
137 return translate;
138 }
139
CalNotRotateTransform(const sptr<SceneSession> & sceneSession,Matrix3f & transform,bool useUIExtension) const140 void SceneSessionDirtyManager::CalNotRotateTransform(const sptr<SceneSession>& sceneSession, Matrix3f& transform,
141 bool useUIExtension) const
142 {
143 if (sceneSession == nullptr) {
144 WLOGFE("sceneSession is nullptr");
145 return;
146 }
147 auto sessionProperty = sceneSession->GetSessionProperty();
148 if (sessionProperty == nullptr) {
149 WLOGFE("sessionProperty is nullptr");
150 return;
151 }
152 auto displayId = sessionProperty->GetDisplayId();
153 auto displayMode = Rosen::ScreenSessionManagerClient::GetInstance().GetFoldDisplayMode();
154 std::map<ScreenId, ScreenProperty> screensProperties =
155 Rosen::ScreenSessionManagerClient::GetInstance().GetAllScreensProperties();
156 if (screensProperties.find(displayId) == screensProperties.end()) {
157 return;
158 }
159 auto screenProperty = screensProperties[displayId];
160 MMI::Direction displayRotation = ConvertDegreeToMMIRotation(screenProperty.GetRotation(),
161 static_cast<MMI::DisplayMode>(displayMode));
162 float width = screenProperty.GetBounds().rect_.GetWidth();
163 float height = screenProperty.GetBounds().rect_.GetHeight();
164 Vector2f scale(sceneSession->GetScaleX(), sceneSession->GetScaleY());
165 Vector2f offset = sceneSession->GetSessionGlobalPosition(useUIExtension);
166 float rotate = 0.0f;
167 Vector2f translate = CalRotationToTranslate(displayRotation, width, height, offset, rotate);
168 transform = transform.Translate(translate).Rotate(rotate).Scale(scale, sceneSession->GetPivotX(),
169 sceneSession->GetPivotY());
170 transform = transform.Inverse();
171 }
172
CalTransform(const sptr<SceneSession> & sceneSession,Matrix3f & transform,bool useUIExtension) const173 void SceneSessionDirtyManager::CalTransform(const sptr<SceneSession>& sceneSession, Matrix3f& transform,
174 bool useUIExtension) const
175 {
176 if (sceneSession == nullptr) {
177 WLOGFE("sceneSession is nullptr");
178 return;
179 }
180 transform = Matrix3f::IDENTITY;
181 bool isRotate = sceneSession->GetSessionInfo().isRotable_;
182 auto displayMode = ScreenSessionManagerClient::GetInstance().GetFoldDisplayMode();
183 if (isRotate || !sceneSession->GetSessionInfo().isSystem_ ||
184 static_cast<MMI::DisplayMode>(displayMode) == MMI::DisplayMode::FULL ||
185 (static_cast<MMI::DisplayMode>(displayMode) == MMI::DisplayMode::MAIN &&
186 FoldScreenStateInternel::IsSingleDisplayPocketFoldDevice())) {
187 Vector2f scale(sceneSession->GetScaleX(), sceneSession->GetScaleY());
188 Vector2f translate = sceneSession->GetSessionGlobalPosition(useUIExtension);
189 transform = transform.Translate(translate);
190 transform = transform.Scale(scale, sceneSession->GetPivotX(), sceneSession->GetPivotY());
191 transform = transform.Inverse();
192 return;
193 }
194 CalNotRotateTransform(sceneSession, transform, useUIExtension);
195 }
196
197
UpdateDefaultHotAreas(sptr<SceneSession> sceneSession,std::vector<MMI::Rect> & touchHotAreas,std::vector<MMI::Rect> & pointerHotAreas) const198 void SceneSessionDirtyManager::UpdateDefaultHotAreas(sptr<SceneSession> sceneSession,
199 std::vector<MMI::Rect>& touchHotAreas,
200 std::vector<MMI::Rect>& pointerHotAreas) const
201 {
202 if (sceneSession == nullptr) {
203 WLOGFE("sceneSession is nullptr");
204 return;
205 }
206 WSRect windowRect = sceneSession->GetSessionGlobalRect();
207 uint32_t touchOffset = 0;
208 uint32_t pointerOffset = 0;
209 bool isMidScene = sceneSession->GetIsMidScene();
210 bool isAppMainWindowOrPip = sceneSession->GetWindowType() == WindowType::WINDOW_TYPE_APP_MAIN_WINDOW ||
211 sceneSession->GetWindowType() == WindowType::WINDOW_TYPE_PIP;
212 if (isAppMainWindowOrPip && !isMidScene) {
213 float vpr = 1.5f; // 1.5: default vp
214 auto sessionProperty = sceneSession->GetSessionProperty();
215 if (sessionProperty != nullptr) {
216 auto displayId = sessionProperty->GetDisplayId();
217 auto screenSession = ScreenSessionManagerClient::GetInstance().GetScreenSession(displayId);
218 if (screenSession != nullptr) {
219 vpr = screenSession->GetScreenProperty().GetDensity();
220 }
221 }
222 touchOffset = static_cast<uint32_t>(HOTZONE_TOUCH * vpr);
223 pointerOffset = static_cast<uint32_t>(HOTZONE_POINTER * vpr);
224 }
225
226 MMI::Rect touchRect = {
227 .x = -touchOffset,
228 .y = -touchOffset,
229 .width = windowRect.width_ + static_cast<int32_t>(touchOffset * 2), // 2 : double touchOffset
230 .height = windowRect.height_ + static_cast<int32_t>(touchOffset * 2) // 2 : double touchOffset
231 };
232
233 MMI::Rect pointerRect = {
234 .x = -pointerOffset,
235 .y = -pointerOffset,
236 .width = windowRect.width_ + static_cast<int32_t>(pointerOffset * 2), // 2 : double pointerOffset
237 .height = windowRect.height_ + static_cast<int32_t>(pointerOffset * 2) // 2 : double pointerOffset
238 };
239
240 touchHotAreas.emplace_back(touchRect);
241 pointerHotAreas.emplace_back(pointerRect);
242 }
243
UpdateHotAreas(sptr<SceneSession> sceneSession,std::vector<MMI::Rect> & touchHotAreas,std::vector<MMI::Rect> & pointerHotAreas) const244 void SceneSessionDirtyManager::UpdateHotAreas(sptr<SceneSession> sceneSession, std::vector<MMI::Rect>& touchHotAreas,
245 std::vector<MMI::Rect>& pointerHotAreas) const
246 {
247 if (sceneSession == nullptr) {
248 WLOGFE("sceneSession is nullptr");
249 return;
250 }
251 WSRect windowRect = sceneSession->GetSessionGlobalRect();
252 const std::vector<Rect>& hotAreas = sceneSession->GetTouchHotAreas();
253 for (auto area : hotAreas) {
254 MMI::Rect rect;
255 rect.x = area.posX_;
256 rect.y = area.posY_;
257 rect.width = static_cast<int32_t>(area.width_);
258 rect.height = static_cast<int32_t>(area.height_);
259 auto iter = std::find_if(touchHotAreas.begin(), touchHotAreas.end(),
260 [&rect](const MMI::Rect& var) { return rect == var; });
261 if (iter != touchHotAreas.end()) {
262 continue;
263 }
264 touchHotAreas.emplace_back(rect);
265 pointerHotAreas.emplace_back(rect);
266 if (touchHotAreas.size() == static_cast<uint32_t>(MMI::WindowInfo::MAX_HOTAREA_COUNT)) {
267 auto sessionid = sceneSession->GetWindowId();
268 WLOGFE("id = %{public}d hotAreas size > %{public}d", sessionid, static_cast<int>(hotAreas.size()));
269 break;
270 }
271 }
272 if (touchHotAreas.empty()) {
273 return UpdateDefaultHotAreas(sceneSession, touchHotAreas, pointerHotAreas);
274 }
275 }
276
AddDialogSessionMapItem(const sptr<SceneSession> & session,std::map<int32_t,sptr<SceneSession>> & dialogMap)277 static void AddDialogSessionMapItem(const sptr<SceneSession>& session,
278 std::map<int32_t, sptr<SceneSession>>& dialogMap)
279 {
280 const auto& mainSession = session->GetMainSession();
281 if (mainSession == nullptr) {
282 return;
283 }
284 bool isTopmostModalWindow = false;
285 const auto& property = session->GetSessionProperty();
286 if (property != nullptr && property->IsTopmost()) {
287 isTopmostModalWindow = true;
288 }
289 if (auto iter = dialogMap.find(mainSession->GetPersistentId());
290 iter != dialogMap.end() && iter->second != nullptr) {
291 auto& targetSession = iter->second;
292 if (session->IsApplicationModal() == targetSession->IsApplicationModal()) {
293 if (targetSession->GetSessionProperty() &&
294 targetSession->GetSessionProperty()->IsTopmost() &&
295 !isTopmostModalWindow) {
296 return;
297 }
298 if (targetSession->GetZOrder() > session->GetZOrder()) {
299 return;
300 }
301 } else if (!session->IsApplicationModal() && targetSession->IsApplicationModal()) {
302 return;
303 }
304 }
305 dialogMap[mainSession->GetPersistentId()] = session;
306 TLOGD(WmsLogTag::WMS_DIALOG, "Add dialog session, id: %{public}d, mainSessionId: %{public}d",
307 session->GetPersistentId(), mainSession->GetPersistentId());
308 }
309
UpdateCallingPidMapItem(const sptr<SceneSession> & session,std::unordered_map<int32_t,sptr<SceneSession>> & callingPidMap)310 static void UpdateCallingPidMapItem(const sptr<SceneSession>& session,
311 std::unordered_map<int32_t, sptr<SceneSession>>& callingPidMap)
312 {
313 auto sessionPid = session->GetCallingPid();
314 auto parentSession = session->GetParentSession();
315 while (parentSession) {
316 auto parentSessionPid = parentSession->GetCallingPid();
317 if (sessionPid != parentSessionPid) {
318 callingPidMap[parentSessionPid] = session;
319 }
320 parentSession = parentSession->GetParentSession();
321 }
322 }
323
AddCallingPidMapItem(const sptr<SceneSession> & session,std::unordered_map<int32_t,sptr<SceneSession>> & callingPidMap)324 static void AddCallingPidMapItem(const sptr<SceneSession>& session,
325 std::unordered_map<int32_t, sptr<SceneSession>>& callingPidMap)
326 {
327 auto sessionCallingPid = session->GetCallingPid();
328 auto iter = callingPidMap.find(sessionCallingPid);
329 if (iter == callingPidMap.end()) {
330 if (!session->IsApplicationModal()) {
331 return;
332 }
333 callingPidMap.emplace(std::make_pair(sessionCallingPid, session));
334 UpdateCallingPidMapItem(session, callingPidMap);
335 TLOGD(WmsLogTag::WMS_DIALOG,
336 "Add callingPid session, sessionCallingPid: %{public}d, sessionId: %{public}d",
337 sessionCallingPid, session->GetPersistentId());
338 } else {
339 if (iter->second->GetZOrder() < session->GetZOrder()) {
340 callingPidMap[sessionCallingPid] = session;
341 UpdateCallingPidMapItem(session, callingPidMap);
342 TLOGD(WmsLogTag::WMS_DIALOG,
343 "Update callingPid session, sessionCallingPid: %{public}d, sessionId: %{public}d",
344 sessionCallingPid, session->GetPersistentId());
345 }
346 }
347 }
348
UpdateDialogSessionMap(const std::map<int32_t,sptr<SceneSession>> & sessionMap,const std::unordered_map<int32_t,sptr<SceneSession>> & callingPidMap,std::map<int32_t,sptr<SceneSession>> & dialogMap)349 static void UpdateDialogSessionMap(
350 const std::map<int32_t, sptr<SceneSession>>& sessionMap,
351 const std::unordered_map<int32_t, sptr<SceneSession>>& callingPidMap,
352 std::map<int32_t, sptr<SceneSession>>& dialogMap)
353 {
354 for (const auto& [_, session] : sessionMap) {
355 if (session == nullptr || session->GetForceHideState() != ForceHideState::NOT_HIDDEN) {
356 continue;
357 }
358 auto iter = callingPidMap.find(session->GetCallingPid());
359 if (iter != callingPidMap.end()) {
360 dialogMap[session->GetPersistentId()] = iter->second;
361 TLOGD(WmsLogTag::WMS_DIALOG,
362 "Update dialog session, sessionId: %{public}d, callingPidSessionId: %{public}d",
363 session->GetPersistentId(), iter->second->GetPersistentId());
364 }
365 }
366 }
367
GetDialogSessionMap(const std::map<int32_t,sptr<SceneSession>> & sessionMap) const368 std::map<int32_t, sptr<SceneSession>> SceneSessionDirtyManager::GetDialogSessionMap(
369 const std::map<int32_t, sptr<SceneSession>>& sessionMap) const
370 {
371 std::map<int32_t, sptr<SceneSession>> dialogMap;
372 std::unordered_map<int32_t, sptr<SceneSession>> callingPidMap;
373 bool hasModalApplication = false;
374 for (const auto& [_, session] : sessionMap) {
375 if (session == nullptr || session->GetForceHideState() != ForceHideState::NOT_HIDDEN) {
376 continue;
377 }
378 if (!session->IsModal() && !session->IsDialogWindow()) {
379 continue;
380 }
381 AddDialogSessionMapItem(session, dialogMap);
382 AddCallingPidMapItem(session, callingPidMap);
383 if (session->IsApplicationModal()) {
384 hasModalApplication = true;
385 }
386 }
387 if (hasModalApplication) {
388 UpdateDialogSessionMap(sessionMap, callingPidMap, dialogMap);
389 }
390 return dialogMap;
391 }
392
IsFilterSession(const sptr<SceneSession> & sceneSession) const393 bool SceneSessionDirtyManager::IsFilterSession(const sptr<SceneSession>& sceneSession) const
394 {
395 if (sceneSession == nullptr) {
396 return true;
397 }
398
399 if (sceneSession->IsSystemInput()) {
400 return false;
401 } else if (sceneSession->IsSystemSession() && sceneSession->IsVisible() && sceneSession->IsSystemActive()) {
402 return false;
403 }
404 if (!SceneSessionManager::GetInstance().IsSessionVisible(sceneSession)) {
405 return true;
406 }
407 return false;
408 }
409
NotifyWindowInfoChange(const sptr<SceneSession> & sceneSession,const WindowUpdateType & type,const bool startMoving)410 void SceneSessionDirtyManager::NotifyWindowInfoChange(const sptr<SceneSession>& sceneSession,
411 const WindowUpdateType& type, const bool startMoving)
412 {
413 if (sceneSession == nullptr) {
414 WLOGFW("sceneSession is null");
415 return;
416 }
417
418 if (type == WindowUpdateType::WINDOW_UPDATE_ADDED || type == WindowUpdateType::WINDOW_UPDATE_REMOVED||
419 type == WindowUpdateType::WINDOW_UPDATE_ACTIVE) {
420 WLOGFD("[EventDispatch] wid = %{public}d, winType = %{public}d",
421 sceneSession->GetWindowId(), static_cast<int>(type));
422 }
423 ResetFlushWindowInfoTask();
424 }
425
ResetFlushWindowInfoTask()426 void SceneSessionDirtyManager::ResetFlushWindowInfoTask()
427 {
428 sessionDirty_.store(true);
429 bool hasPostTask = false;
430 if (hasPostTask_.compare_exchange_strong(hasPostTask, true)) {
431 auto task = [this]() {
432 hasPostTask_.store(false);
433 if (!sessionDirty_.load() || flushWindowInfoCallback_ == nullptr) {
434 return;
435 }
436 flushWindowInfoCallback_();
437 };
438 SceneSessionManager::GetInstance().PostFlushWindowInfoTask(task,
439 UPDATE_WINDOW_INFO_TASK, UPDATE_TASK_DURATION);
440 }
441 }
442
AddModalExtensionWindowInfo(std::vector<MMI::WindowInfo> & windowInfoList,MMI::WindowInfo windowInfo,const sptr<SceneSession> & sceneSession,const ExtensionWindowEventInfo & extensionInfo)443 void SceneSessionDirtyManager::AddModalExtensionWindowInfo(std::vector<MMI::WindowInfo>& windowInfoList,
444 MMI::WindowInfo windowInfo, const sptr<SceneSession>& sceneSession,
445 const ExtensionWindowEventInfo& extensionInfo)
446 {
447 if (sceneSession == nullptr) {
448 TLOGE(WmsLogTag::WMS_EVENT, "sceneSession is nullptr");
449 return;
450 }
451
452 windowInfo.id = extensionInfo.persistentId;
453 if (extensionInfo.windowRect.width_ != 0 || extensionInfo.windowRect.height_ != 0) {
454 MMI::Rect windowRect = {
455 .x = extensionInfo.windowRect.posX_,
456 .y = extensionInfo.windowRect.posY_,
457 .width = extensionInfo.windowRect.width_,
458 .height = extensionInfo.windowRect.height_
459 };
460 windowInfo.area = windowRect;
461 std::vector<MMI::Rect> touchHotAreas;
462 MMI::Rect touchRect = {
463 .x = 0,
464 .y = 0,
465 .width = extensionInfo.windowRect.width_,
466 .height = extensionInfo.windowRect.height_
467 };
468 touchHotAreas.emplace_back(touchRect);
469 windowInfo.defaultHotAreas = touchHotAreas;
470 windowInfo.pointerHotAreas = touchHotAreas;
471 Matrix3f transform;
472 CalTransform(sceneSession, transform, true);
473 std::vector<float> transformData(transform.GetData(), transform.GetData() + TRANSFORM_DATA_LEN);
474 windowInfo.transform = transformData;
475 }
476
477 windowInfo.agentWindowId = extensionInfo.persistentId;
478 windowInfo.pid = extensionInfo.pid;
479 std::vector<int32_t> pointerChangeAreas(POINTER_CHANGE_AREA_COUNT, 0);
480 windowInfo.pointerChangeAreas = pointerChangeAreas;
481 windowInfo.zOrder = windowInfo.zOrder + ZORDER_UIEXTENSION_INDEX;
482
483 windowInfoList.emplace_back(windowInfo);
484 }
485
GetFullWindowInfoList()486 auto SceneSessionDirtyManager::GetFullWindowInfoList() ->
487 std::pair<std::vector<MMI::WindowInfo>, std::vector<std::shared_ptr<Media::PixelMap>>>
488 {
489 std::vector<MMI::WindowInfo> windowInfoList;
490 std::vector<std::shared_ptr<Media::PixelMap>> pixelMapList;
491 const auto sceneSessionMap = SceneSessionManager::GetInstance().GetSceneSessionMap();
492 // all input event should trans to dialog window if dialog exists
493 const auto dialogMap = GetDialogSessionMap(sceneSessionMap);
494 uint32_t maxHotAreasNum = 0;
495 for (const auto& sceneSessionValuePair : sceneSessionMap) {
496 const auto& sceneSessionValue = sceneSessionValuePair.second;
497 if (sceneSessionValue == nullptr) {
498 continue;
499 }
500 WLOGFD("[EventDispatch] FullSceneSessionInfoUpdate windowName = %{public}s bundleName = %{public}s"
501 " windowId = %{public}d activeStatus = %{public}d", sceneSessionValue->GetWindowName().c_str(),
502 sceneSessionValue->GetSessionInfo().bundleName_.c_str(), sceneSessionValue->GetWindowId(),
503 sceneSessionValue->GetForegroundInteractiveStatus());
504 auto [windowInfo, pixelMap] = GetWindowInfo(sceneSessionValue, WindowAction::WINDOW_ADD);
505 auto iter = (sceneSessionValue->GetMainSessionId() == INVALID_SESSION_ID) ?
506 dialogMap.find(sceneSessionValue->GetPersistentId()) :
507 dialogMap.find(sceneSessionValue->GetMainSessionId());
508 if (iter != dialogMap.end() && iter->second != nullptr &&
509 sceneSessionValue->GetPersistentId() != iter->second->GetPersistentId() &&
510 iter->second->GetZOrder() > sceneSessionValue->GetZOrder()) {
511 windowInfo.agentWindowId = static_cast<int32_t>(iter->second->GetPersistentId());
512 windowInfo.pid = static_cast<int32_t>(iter->second->GetCallingPid());
513 } else if (auto modalUIExtensionEventInfo = sceneSessionValue->GetLastModalUIExtensionEventInfo()) {
514 AddModalExtensionWindowInfo(windowInfoList, windowInfo, sceneSessionValue, *modalUIExtensionEventInfo);
515 }
516 TLOGD(WmsLogTag::WMS_EVENT, "windowId = %{public}d, agentWindowId = %{public}d, zOrder = %{public}f",
517 windowInfo.id, windowInfo.agentWindowId, windowInfo.zOrder);
518 windowInfoList.emplace_back(windowInfo);
519 pixelMapList.emplace_back(pixelMap);
520 // set the number of hot areas to the maximum number of hot areas when it exceeds the maximum number
521 // to avoid exceeding socket buff limits
522 if (windowInfo.defaultHotAreas.size() > maxHotAreasNum) {
523 maxHotAreasNum = windowInfo.defaultHotAreas.size();
524 }
525 }
526 if (maxHotAreasNum > MMI::WindowInfo::DEFAULT_HOTAREA_COUNT) {
527 std::sort(windowInfoList.begin(), windowInfoList.end(), CmpMMIWindowInfo);
528 }
529 return {windowInfoList, pixelMapList};
530 }
531
UpdatePointerAreas(sptr<SceneSession> sceneSession,std::vector<int32_t> & pointerChangeAreas) const532 void SceneSessionDirtyManager::UpdatePointerAreas(sptr<SceneSession> sceneSession,
533 std::vector<int32_t>& pointerChangeAreas) const
534 {
535 if (!sceneSession) {
536 TLOGE(WmsLogTag::WMS_EVENT, "sceneSession is null");
537 return;
538 }
539 auto sessionProperty = sceneSession->GetSessionProperty();
540 if (!sessionProperty) {
541 TLOGE(WmsLogTag::WMS_EVENT, "sessionProperty is null");
542 return;
543 }
544 bool dragEnabled = sessionProperty->GetDragEnabled();
545 TLOGD(WmsLogTag::WMS_EVENT, "window %{public}s dragEnabled: %{public}d", sceneSession->GetWindowName().c_str(),
546 dragEnabled);
547 if (dragEnabled) {
548 float vpr = 1.5f; // 1.5: default vp
549 auto displayId = sessionProperty->GetDisplayId();
550 auto screenSession = ScreenSessionManagerClient::GetInstance().GetScreenSession(displayId);
551 if (screenSession != nullptr) {
552 vpr = screenSession->GetScreenProperty().GetDensity();
553 }
554 int32_t pointerAreaFivePx = static_cast<int32_t>(POINTER_CHANGE_AREA_FIVE * vpr);
555 int32_t pointerAreaSixteenPx = static_cast<int32_t>(POINTER_CHANGE_AREA_SIXTEEN * vpr);
556 if (sceneSession->GetSessionInfo().isSetPointerAreas_) {
557 pointerChangeAreas = {POINTER_CHANGE_AREA_DEFAULT, POINTER_CHANGE_AREA_DEFAULT,
558 POINTER_CHANGE_AREA_DEFAULT, pointerAreaFivePx, pointerAreaSixteenPx,
559 pointerAreaFivePx, pointerAreaSixteenPx, pointerAreaFivePx};
560 return;
561 }
562 auto limits = sessionProperty->GetWindowLimits();
563 TLOGD(WmsLogTag::WMS_EVENT, "%{public}s [minWidth,maxWidth,minHeight,maxHeight]: %{public}d,"
564 " %{public}d, %{public}d, %{public}d", sceneSession->GetWindowName().c_str(), limits.minWidth_,
565 limits.maxWidth_, limits.minHeight_, limits.maxHeight_);
566 if (limits.minWidth_ == limits.maxWidth_ && limits.minHeight_ != limits.maxHeight_) {
567 pointerChangeAreas = {POINTER_CHANGE_AREA_DEFAULT, pointerAreaFivePx,
568 POINTER_CHANGE_AREA_DEFAULT, POINTER_CHANGE_AREA_DEFAULT, POINTER_CHANGE_AREA_DEFAULT,
569 pointerAreaFivePx, POINTER_CHANGE_AREA_DEFAULT, POINTER_CHANGE_AREA_DEFAULT};
570 } else if (limits.minWidth_ != limits.maxWidth_ && limits.minHeight_ == limits.maxHeight_) {
571 pointerChangeAreas = {POINTER_CHANGE_AREA_DEFAULT, POINTER_CHANGE_AREA_DEFAULT,
572 POINTER_CHANGE_AREA_DEFAULT, pointerAreaFivePx, POINTER_CHANGE_AREA_DEFAULT,
573 POINTER_CHANGE_AREA_DEFAULT, POINTER_CHANGE_AREA_DEFAULT, pointerAreaFivePx};
574 } else if (limits.minWidth_ != limits.maxWidth_ && limits.minHeight_ != limits.maxHeight_) {
575 pointerChangeAreas = {pointerAreaSixteenPx, pointerAreaFivePx,
576 pointerAreaSixteenPx, pointerAreaFivePx, pointerAreaSixteenPx,
577 pointerAreaFivePx, pointerAreaSixteenPx, pointerAreaFivePx};
578 }
579 } else {
580 TLOGD(WmsLogTag::WMS_EVENT, "sceneSession is: %{public}d dragEnabled is false",
581 sceneSession->GetPersistentId());
582 }
583 }
584
UpdatePrivacyMode(const sptr<SceneSession> & sceneSession,MMI::WindowInfo & windowInfo) const585 void SceneSessionDirtyManager::UpdatePrivacyMode(const sptr<SceneSession>& sceneSession,
586 MMI::WindowInfo& windowInfo) const
587 {
588 if (sceneSession == nullptr) {
589 TLOGE(WmsLogTag::WMS_EVENT, "sceneSession is nullptr");
590 return;
591 }
592 windowInfo.privacyMode = MMI::SecureFlag::DEFAULT_MODE;
593 sptr<WindowSessionProperty> windowSessionProperty = sceneSession->GetSessionProperty();
594 if (windowSessionProperty == nullptr) {
595 TLOGE(WmsLogTag::WMS_EVENT, "windowSessionProperty is nullptr");
596 return;
597 }
598 if (windowSessionProperty->GetPrivacyMode() || windowSessionProperty->GetSystemPrivacyMode() ||
599 sceneSession->GetCombinedExtWindowFlags().privacyModeFlag) {
600 windowInfo.privacyMode = MMI::SecureFlag::PRIVACY_MODE;
601 }
602 }
603
UpdateWindowFlags(DisplayId displayId,const sptr<SceneSession> & sceneSession,MMI::WindowInfo & windowInfo) const604 void SceneSessionDirtyManager::UpdateWindowFlags(DisplayId displayId, const sptr<SceneSession>& sceneSession,
605 MMI::WindowInfo& windowInfo) const
606 {
607 windowInfo.flags = 0;
608 auto screenSession = ScreenSessionManagerClient::GetInstance().GetScreenSession(displayId);
609 if (screenSession != nullptr) {
610 if (!screenSession->IsTouchEnabled() || !sceneSession->GetSystemTouchable() ||
611 !sceneSession->GetForegroundInteractiveStatus()) {
612 windowInfo.flags |= MMI::WindowInfo::FLAG_BIT_UNTOUCHABLE;
613 }
614 }
615 }
616
GetWindowInfo(const sptr<SceneSession> & sceneSession,const SceneSessionDirtyManager::WindowAction & action) const617 std::pair<MMI::WindowInfo, std::shared_ptr<Media::PixelMap>> SceneSessionDirtyManager::GetWindowInfo(
618 const sptr<SceneSession>& sceneSession, const SceneSessionDirtyManager::WindowAction& action) const
619 {
620 if (sceneSession == nullptr) {
621 WLOGFE("sceneSession is nullptr");
622 return {};
623 }
624 sptr<WindowSessionProperty> windowSessionProperty = sceneSession->GetSessionProperty();
625 if (windowSessionProperty == nullptr) {
626 TLOGE(WmsLogTag::WMS_EVENT, "GetSessionProperty is nullptr");
627 return {};
628 }
629 Matrix3f transform;
630 WSRect windowRect = sceneSession->GetSessionGlobalRect();
631 auto pid = sceneSession->GetCallingPid();
632 auto uid = sceneSession->GetCallingUid();
633 auto windowId = sceneSession->GetWindowId();
634 auto displayId = windowSessionProperty->GetDisplayId();
635 CalTransform(sceneSession, transform);
636 std::vector<float> transformData(transform.GetData(), transform.GetData() + TRANSFORM_DATA_LEN);
637
638 auto agentWindowId = sceneSession->GetWindowId();
639 auto zOrder = sceneSession->GetZOrder();
640 std::vector<int32_t> pointerChangeAreas(POINTER_CHANGE_AREA_COUNT, 0);
641 WindowType windowType = windowSessionProperty->GetWindowType();
642 CheckIfUpdatePointAreas(sceneSession, windowSessionProperty, windowType, pointerChangeAreas);
643 std::vector<MMI::Rect> touchHotAreas;
644 std::vector<MMI::Rect> pointerHotAreas;
645 UpdateHotAreas(sceneSession, touchHotAreas, pointerHotAreas);
646 auto pixelMap = windowSessionProperty->GetWindowMask();
647 MMI::WindowInfo windowInfo = {
648 .id = windowId,
649 .pid = sceneSession->IsStartMoving() ? static_cast<int32_t>(getpid()) : pid,
650 .uid = uid,
651 .area = { windowRect.posX_, windowRect.posY_, windowRect.width_, windowRect.height_ },
652 .defaultHotAreas = touchHotAreas,
653 .pointerHotAreas = pointerHotAreas,
654 .agentWindowId = agentWindowId,
655 .action = static_cast<MMI::WINDOW_UPDATE_ACTION>(action),
656 .displayId = displayId,
657 .zOrder = zOrder,
658 .pointerChangeAreas = pointerChangeAreas,
659 .transform = transformData,
660 .pixelMap = pixelMap.get(),
661 .windowInputType = static_cast<MMI::WindowInputType>(sceneSession->GetSessionInfo().windowInputType_),
662 .windowType = static_cast<int32_t>(windowType),
663 };
664 UpdateWindowFlags(displayId, sceneSession, windowInfo);
665 if (windowSessionProperty->GetWindowFlags() & static_cast<uint32_t>(WindowFlag::WINDOW_FLAG_HANDWRITING)) {
666 windowInfo.flags |= MMI::WindowInfo::FLAG_BIT_HANDWRITING;
667 }
668 UpdatePrivacyMode(sceneSession, windowInfo);
669 windowInfo.uiExtentionWindowInfo = GetSecSurfaceWindowinfoList(sceneSession, windowInfo, transform);
670 return {windowInfo, pixelMap};
671 }
672
CheckIfUpdatePointAreas(const sptr<SceneSession> & sceneSession,const sptr<WindowSessionProperty> & windowSessionProperty,WindowType windowType,std::vector<int32_t> & pointerChangeAreas) const673 void SceneSessionDirtyManager::CheckIfUpdatePointAreas(const sptr<SceneSession>& sceneSession,
674 const sptr<WindowSessionProperty>& windowSessionProperty, WindowType windowType,
675 std::vector<int32_t>& pointerChangeAreas) const
676 {
677 auto windowMode = windowSessionProperty->GetWindowMode();
678 auto maxMode = windowSessionProperty->GetMaximizeMode();
679 bool isMainWindow = WindowHelper::IsMainWindow(windowType);
680 bool isDecorDialog = WindowHelper::IsDialogWindow(windowType) && windowSessionProperty->IsDecorEnable();
681 bool isNoDialogAndDragEnabledSystemWindow = WindowHelper::IsSystemWindow(windowType) &&
682 !WindowHelper::IsDialogWindow(windowType) && windowSessionProperty->GetDragEnabled();
683 bool isDecorSubWindow = WindowHelper::IsSubWindow(windowType) && windowSessionProperty->IsDecorEnable();
684 if ((windowMode == WindowMode::WINDOW_MODE_FLOATING &&
685 (isMainWindow || isDecorDialog || isDecorSubWindow || isNoDialogAndDragEnabledSystemWindow) &&
686 maxMode != MaximizeMode::MODE_AVOID_SYSTEM_BAR) ||
687 sceneSession->GetSessionInfo().isSetPointerAreas_) {
688 UpdatePointerAreas(sceneSession, pointerChangeAreas);
689 }
690 }
691
RegisterFlushWindowInfoCallback(const FlushWindowInfoCallback && callback)692 void SceneSessionDirtyManager::RegisterFlushWindowInfoCallback(const FlushWindowInfoCallback &&callback)
693 {
694 flushWindowInfoCallback_ = std::move(callback);
695 }
696
ResetSessionDirty()697 void SceneSessionDirtyManager::ResetSessionDirty()
698 {
699 sessionDirty_.store(false);
700 }
701
DumpRect(const std::vector<MMI::Rect> & rects)702 std::string DumpRect(const std::vector<MMI::Rect>& rects)
703 {
704 std::string rectStr = "";
705 for (const auto& rect : rects) {
706 rectStr = rectStr + " hot : [ " + std::to_string(rect.x) +" , " + std::to_string(rect.y) +
707 " , " + std::to_string(rect.width) + " , " + std::to_string(rect.height) + "]";
708 }
709 return rectStr;
710 }
711
DumpWindowInfo(const MMI::WindowInfo & info)712 std::string DumpWindowInfo(const MMI::WindowInfo& info)
713 {
714 std::string infoStr = "windowInfo:";
715 infoStr = infoStr + "windowId: " + std::to_string(info.id) + " pid : " + std::to_string(info.pid) +
716 " uid: " + std::to_string(info.uid) + " area: [ " + std::to_string(info.area.x) + " , " +
717 std::to_string(info.area.y) + " , " + std::to_string(info.area.width) + " , " +
718 std::to_string(info.area.height) + "] agentWindowId:" + std::to_string(info.agentWindowId) + " flags:" +
719 std::to_string(info.flags) +" displayId: " + std::to_string(info.displayId) +
720 " action: " + std::to_string(static_cast<int>(info.action)) + " zOrder: " + std::to_string(info.zOrder);
721 return infoStr + DumpRect(info.defaultHotAreas);
722 }
723
DumpSecRectInfo(const SecRectInfo & secRectInfo)724 std::string DumpSecRectInfo(const SecRectInfo & secRectInfo)
725 {
726 std::string infoStr = " area: [ " + std::to_string(secRectInfo.relativeCoords.GetLeft()) + " , " +
727 std::to_string(secRectInfo.relativeCoords.GetTop()) + " , " +
728 std::to_string(secRectInfo.relativeCoords.GetWidth()) + " , " +
729 std::to_string(secRectInfo.relativeCoords.GetHeight()) + "]" +
730 " scaleX:" + std::to_string(secRectInfo.scale[0]) + " scaleY:" + std::to_string(secRectInfo.scale[1]) +
731 " anchorX:" + std::to_string(secRectInfo.anchor[0]) + " anchorY:" + std::to_string(secRectInfo.anchor[1]);
732 return infoStr;
733 }
734
DumpSecSurfaceInfo(const SecSurfaceInfo & secSurfaceInfo)735 std::string DumpSecSurfaceInfo(const SecSurfaceInfo& secSurfaceInfo)
736 {
737 std::string infoStr = "hostPid:" + std::to_string(secSurfaceInfo.hostPid) +
738 " uiExtensionPid:" + std::to_string(secSurfaceInfo.uiExtensionPid) +
739 " hostNodeId:" + std::to_string(secSurfaceInfo.hostNodeId) +
740 " uiExtensionNodeId:" + std::to_string(secSurfaceInfo.uiExtensionNodeId);
741 return infoStr;
742 }
743
MakeWindowInfoFormHostWindow(const SecRectInfo & secRectInfo,const MMI::WindowInfo & hostWindowinfo) const744 MMI::WindowInfo SceneSessionDirtyManager::MakeWindowInfoFormHostWindow(const SecRectInfo& secRectInfo,
745 const MMI::WindowInfo& hostWindowinfo) const
746 {
747 MMI::WindowInfo windowinfo;
748 windowinfo.id = hostWindowinfo.id;
749 windowinfo.pid = hostWindowinfo.pid;
750 windowinfo.uid = hostWindowinfo.uid;
751 windowinfo.area = hostWindowinfo.area;
752 windowinfo.agentWindowId = hostWindowinfo.agentWindowId;
753 windowinfo.action = hostWindowinfo.action;
754 windowinfo.displayId = hostWindowinfo.displayId;
755 windowinfo.flags = hostWindowinfo.flags;
756 windowinfo.privacyMode = hostWindowinfo.privacyMode;
757 windowinfo.transform = hostWindowinfo.transform;
758 return windowinfo;
759 }
760
CoordinateSystemHostWindowToScreen(const Matrix3f hostTransform,const SecRectInfo & secRectInfo)761 Matrix3f CoordinateSystemHostWindowToScreen(const Matrix3f hostTransform, const SecRectInfo& secRectInfo)
762 {
763 Matrix3f transform = Matrix3f::IDENTITY;
764 Vector2f translate(secRectInfo.relativeCoords.GetLeft(), secRectInfo.relativeCoords.GetTop());
765 transform = transform.Translate(translate);
766 Vector2f scale(secRectInfo.scale[0], secRectInfo.scale[1]);
767 transform = transform.Scale(scale, secRectInfo.anchor[0], secRectInfo.anchor[1]);
768 transform = hostTransform.Inverse() * transform;
769 return transform;
770 }
771
CalRectInScreen(const Matrix3f & transform,const SecRectInfo & secRectInfo)772 MMI::Rect CalRectInScreen(const Matrix3f& transform, const SecRectInfo& secRectInfo)
773 {
774 auto topLeft = transform * Vector3f(0, 0, 1.0);
775 auto bottomRight = transform * Vector3f(secRectInfo.relativeCoords.GetWidth(),
776 secRectInfo.relativeCoords.GetHeight(), 1.0);
777 auto left = std::min(topLeft[0], bottomRight[0]);
778 auto top = std::min(topLeft[1], bottomRight[1]);
779 auto topLeftX = static_cast<int32_t>(topLeft[0]);
780 auto topLeftY = static_cast<int32_t>(topLeft[1]);
781 auto bottomRightX = static_cast<int32_t>(bottomRight[0]);
782 auto bottomRightY = static_cast<int32_t>(bottomRight[1]);
783 if ((topLeftX > 0 && bottomRightX < INT32_MIN + topLeftX) ||
784 (topLeftX < 0 && bottomRightX > INT32_MAX + topLeftX)) {
785 TLOGE(WmsLogTag::WMS_EVENT, "data overflows topLeftX:%{public}d bottomRightX:%{public}d",
786 topLeftX, bottomRightX);
787 }
788 if ((topLeftY > 0 && bottomRightY < INT32_MIN + topLeftY) ||
789 (topLeftY < 0 && bottomRightY > INT32_MAX + topLeftY)) {
790 TLOGE(WmsLogTag::WMS_EVENT, "data overflows topLeftY:%{public}d bottomRightY:%{public}d",
791 topLeftY, bottomRightY);
792 }
793 auto width = std::abs(topLeftX - bottomRightX);
794 auto height = std::abs(topLeftY - bottomRightY);
795 return MMI::Rect{ left, top, width, height};
796 }
797
798
GetHostComponentWindowInfo(const SecSurfaceInfo & secSurfaceInfo,const MMI::WindowInfo & hostWindowinfo,const Matrix3f hostTransform) const799 MMI::WindowInfo SceneSessionDirtyManager::GetHostComponentWindowInfo(const SecSurfaceInfo& secSurfaceInfo,
800 const MMI::WindowInfo& hostWindowinfo, const Matrix3f hostTransform) const
801 {
802 MMI::WindowInfo windowinfo;
803 const auto& secRectInfoList = secSurfaceInfo.upperNodes;
804 if (secRectInfoList.size() > 0) {
805 windowinfo = MakeWindowInfoFormHostWindow(secRectInfoList[0], hostWindowinfo);
806 }
807 for (const auto& secRectInfo : secRectInfoList) {
808 windowinfo.pid = secSurfaceInfo.hostPid;
809 MMI::Rect hotArea = { secRectInfo.relativeCoords.GetLeft(), secRectInfo.relativeCoords.GetTop(),
810 secRectInfo.relativeCoords.GetWidth(), secRectInfo.relativeCoords.GetHeight() };
811 windowinfo.defaultHotAreas.emplace_back(hotArea);
812 windowinfo.pointerHotAreas.emplace_back(hotArea);
813 }
814 return windowinfo;
815 }
816
GetSecComponentWindowInfo(const SecSurfaceInfo & secSurfaceInfo,const MMI::WindowInfo & hostWindowinfo,const sptr<SceneSession> & sceneSession,const Matrix3f hostTransform) const817 MMI::WindowInfo SceneSessionDirtyManager::GetSecComponentWindowInfo(const SecSurfaceInfo& secSurfaceInfo,
818 const MMI::WindowInfo& hostWindowinfo, const sptr<SceneSession>& sceneSession, const Matrix3f hostTransform) const
819 {
820 if (sceneSession == nullptr) {
821 TLOGE(WmsLogTag::WMS_EVENT, "sceneSession is nullptr");
822 return {};
823 }
824 MMI::WindowInfo windowinfo;
825 const auto& secRectInfo = secSurfaceInfo.uiExtensionRectInfo;
826 windowinfo = MakeWindowInfoFormHostWindow(secRectInfo, hostWindowinfo);
827 windowinfo.id = sceneSession->GetUIExtPersistentIdBySurfaceNodeId(secSurfaceInfo.uiExtensionNodeId);
828 if (windowinfo.id == 0) {
829 TLOGE(WmsLogTag::WMS_EVENT, "GetUIExtPersistentId ERROR");
830 return {};
831 }
832 windowinfo.agentWindowId = windowinfo.id;
833 windowinfo.pid = secSurfaceInfo.uiExtensionPid;
834 windowinfo.privacyUIFlag = true;
835 auto transform = CoordinateSystemHostWindowToScreen(hostTransform, secRectInfo);
836 windowinfo.area = CalRectInScreen(transform, secRectInfo);
837 MMI::Rect hotArea = { 0, 0, secRectInfo.relativeCoords.GetWidth(), secRectInfo.relativeCoords.GetHeight() };
838 windowinfo.defaultHotAreas.emplace_back(hotArea);
839 windowinfo.pointerHotAreas.emplace_back(hotArea);
840 // 屏幕坐标系到控件坐标系转换
841 transform = transform.Inverse();
842 std::vector<float> transformData(transform.GetData(), transform.GetData() + TRANSFORM_DATA_LEN);
843 windowinfo.transform = transformData;
844 return windowinfo;
845 }
846
operator ==(const SecRectInfo & a,const SecRectInfo & b)847 bool operator==(const SecRectInfo& a, const SecRectInfo& b)
848 {
849 return (a.relativeCoords == b.relativeCoords && a.scale == b.scale && a.anchor == b.anchor);
850 }
851
operator !=(const SecRectInfo & a,const SecRectInfo & b)852 bool operator!=(const SecRectInfo& a, const SecRectInfo& b)
853 {
854 return !(a == b);
855 }
856
operator ==(const SecSurfaceInfo & a,const SecSurfaceInfo & b)857 bool operator==(const SecSurfaceInfo& a, const SecSurfaceInfo& b)
858 {
859 return (a.uiExtensionRectInfo == b.uiExtensionRectInfo && a.hostPid == b.hostPid &&
860 a.uiExtensionNodeId == b.uiExtensionNodeId && a.uiExtensionPid == b.uiExtensionPid &&
861 a.hostNodeId == b.hostNodeId && a.upperNodes == b.upperNodes);
862 }
863
DumpSecSurfaceInfoMap(const std::map<uint64_t,std::vector<SecSurfaceInfo>> & secSurfaceInfoMap)864 void DumpSecSurfaceInfoMap(const std::map<uint64_t, std::vector<SecSurfaceInfo>>& secSurfaceInfoMap)
865 {
866 TLOGI(WmsLogTag::WMS_EVENT, "secSurfaceInfoMap size:%{public}d", static_cast<int>(secSurfaceInfoMap.size()));
867 for (auto& e : secSurfaceInfoMap) {
868 auto hostNodeId = e.first;
869 TLOGI(WmsLogTag::WMS_EVENT, "hostNodeId:%{public}" PRIu64 " secSurfaceInfoList size:%{public}d",
870 hostNodeId, static_cast<int>(e.second.size()));
871 for (const auto& secSurfaceInfo : e.second) {
872 auto surfaceInfoStr = DumpSecSurfaceInfo(secSurfaceInfo);
873 auto rectInfoStr = DumpSecRectInfo(secSurfaceInfo.uiExtensionRectInfo);
874 TLOGI(WmsLogTag::WMS_EVENT, "secSurfaceInfo:%{public}s secRectInfo:%{public}s", surfaceInfoStr.c_str(),
875 rectInfoStr.c_str());
876 for (const auto& secRectInfo : secSurfaceInfo.upperNodes) {
877 auto infoStr = DumpSecRectInfo(secRectInfo);
878 TLOGI(WmsLogTag::WMS_EVENT, "hostRectInfo:%{public}s", infoStr.c_str());
879 }
880 }
881 }
882 }
883
UpdateSecSurfaceInfo(const std::map<uint64_t,std::vector<SecSurfaceInfo>> & secSurfaceInfoMap)884 void SceneSessionDirtyManager::UpdateSecSurfaceInfo(const std::map<uint64_t,
885 std::vector<SecSurfaceInfo>>& secSurfaceInfoMap)
886 {
887 std::unique_lock<std::shared_mutex> lock(secSurfaceInfoMutex_);
888 if (secSurfaceInfoMap.size() != secSurfaceInfoMap_.size() || secSurfaceInfoMap_ != secSurfaceInfoMap) {
889 secSurfaceInfoMap_ = secSurfaceInfoMap;
890 ResetFlushWindowInfoTask();
891 DumpSecSurfaceInfoMap(secSurfaceInfoMap_);
892 }
893 }
894
GetSecSurfaceWindowinfoList(const sptr<SceneSession> & sceneSession,const MMI::WindowInfo & hostWindowinfo,const Matrix3f & hostTransform) const895 std::vector<MMI::WindowInfo> SceneSessionDirtyManager::GetSecSurfaceWindowinfoList(
896 const sptr<SceneSession>& sceneSession, const MMI::WindowInfo& hostWindowinfo, const Matrix3f& hostTransform) const
897 {
898 if (secSurfaceInfoMap_.size() == 0) {
899 return {};
900 }
901 if (sceneSession == nullptr) {
902 TLOGE(WmsLogTag::WMS_EVENT, "sceneSession is nullptr");
903 return {};
904 }
905 auto surfaceNode = sceneSession->GetSurfaceNode();
906 if (surfaceNode == nullptr) {
907 TLOGE(WmsLogTag::WMS_EVENT, "surfaceNode is nullptr");
908 return {};
909 }
910 std::vector<SecSurfaceInfo> secSurfaceInfoList;
911 auto surfaceNodeId = surfaceNode->GetId();
912 {
913 std::shared_lock<std::shared_mutex> lock(secSurfaceInfoMutex_);
914 auto iter = secSurfaceInfoMap_.find(surfaceNodeId);
915 if (iter == secSurfaceInfoMap_.end()) {
916 return {};
917 }
918 secSurfaceInfoList = iter->second;
919 }
920 std::vector<MMI::WindowInfo> windowinfoList;
921 int seczOrder = 0;
922 MMI::WindowInfo windowinfo;
923 for (const auto& secSurfaceInfo : secSurfaceInfoList) {
924 windowinfo = GetSecComponentWindowInfo(secSurfaceInfo, hostWindowinfo, sceneSession, hostTransform);
925 windowinfo.zOrder = seczOrder++;
926 windowinfoList.emplace_back(windowinfo);
927 windowinfo = GetHostComponentWindowInfo(secSurfaceInfo, hostWindowinfo, hostTransform);
928 windowinfo.zOrder = seczOrder++;
929 windowinfoList.emplace_back(windowinfo);
930 }
931 return windowinfoList;
932 }
933 } //namespace OHOS::Rosen
934