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_input_manager.h"
17 
18 #include <hitrace_meter.h>
19 #include "scene_session_dirty_manager.h"
20 #include "screen_session_manager/include/screen_session_manager_client.h"
21 #include "session_manager/include/scene_session_manager.h"
22 
23 namespace OHOS {
24 namespace Rosen {
25 
26 namespace {
27 constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, HILOG_DOMAIN_WINDOW, "SceneInputManager" };
28 const std::string SCENE_INPUT_MANAGER_THREAD = "SceneInputManager";
29 const std::string FLUSH_DISPLAY_INFO_THREAD = "OS_FlushDisplayInfoThread";
30 
31 constexpr int MAX_WINDOWINFO_NUM = 15;
32 constexpr int DEFALUT_DISPLAYID = 0;
33 constexpr int EMPTY_FOCUS_WINDOW_ID = -1;
34 
35 bool IsEqualUiExtentionWindowInfo(const std::vector<MMI::WindowInfo>& a, const std::vector<MMI::WindowInfo>& b);
36 constexpr unsigned int TRANSFORM_DATA_LEN = 9;
37 
operator !=(const MMI::Rect & a,const MMI::Rect & b)38 bool operator!=(const MMI::Rect& a, const MMI::Rect& b)
39 {
40     if (a.x != b.x || a.y != b.y || a.width != b.width || a.height != b.height) {
41         return true;
42     }
43     return false;
44 }
45 
operator ==(const MMI::DisplayInfo & a,const MMI::DisplayInfo & b)46 bool operator==(const MMI::DisplayInfo& a, const MMI::DisplayInfo& b)
47 {
48     if (a.id != b.id || a.x != b.x || a.y != b.y || a.width != b.width ||
49         a.height != b.height || a.dpi != b.dpi || a.name != b.name || a.uniq != b.uniq ||
50         static_cast<int32_t>(a.direction) != static_cast<int32_t>(b.direction) ||
51         static_cast<int32_t>(a.displayDirection) != static_cast<int32_t>(b.displayDirection) ||
52         static_cast<int32_t>(a.displayMode) != static_cast<int32_t>(b.displayMode) ||
53         a.transform != b.transform) {
54         return false;
55     }
56     return true;
57 }
58 
operator !=(const std::vector<float> & a,const std::vector<float> & b)59 bool operator!=(const std::vector<float>& a, const std::vector<float>& b)
60 {
61     if (a.size() != b.size()) {
62         return true;
63     }
64     int sizeOfA = static_cast<int>(a.size());
65     for (int index = 0; index < sizeOfA; index++) {
66         if (a[index] != b[index]) {
67             return true;
68         }
69     }
70     return false;
71 }
72 
IsEqualWindowInfo(const MMI::WindowInfo & a,const MMI::WindowInfo & b)73 bool IsEqualWindowInfo(const MMI::WindowInfo& a, const MMI::WindowInfo& b)
74 {
75     if (a.id != b.id || a.pid != b.pid || a.uid != b.uid || a.agentWindowId != b.agentWindowId || a.flags != b.flags ||
76         a.displayId != b.displayId || a.zOrder != b.zOrder) {
77         return false;
78     }
79 
80     if (a.windowInputType != b.windowInputType || a.privacyMode != b.privacyMode ||
81         a.windowType != b.windowType || a.pixelMap != b.pixelMap) {
82         return false;
83     }
84     return true;
85 }
86 
operator ==(const MMI::WindowInfo & a,const MMI::WindowInfo & b)87 bool operator==(const MMI::WindowInfo& a, const MMI::WindowInfo& b)
88 {
89     if (!IsEqualWindowInfo(a, b)) {
90         return false;
91     }
92 
93     if (a.area != b.area || a.defaultHotAreas.size() != b.defaultHotAreas.size() ||
94         a.pointerHotAreas.size() != b.pointerHotAreas.size() ||
95         a.pointerChangeAreas.size() != b.pointerChangeAreas.size() || a.transform.size() != b.transform.size()) {
96         return false;
97     }
98 
99     int sizeOfDefaultHotAreas = static_cast<int>(a.defaultHotAreas.size());
100     for (int index = 0; index < sizeOfDefaultHotAreas; index++) {
101         if (a.defaultHotAreas[index] != b.defaultHotAreas[index]) {
102             return false;
103         }
104     }
105     int sizeOfPointerHotAreas = static_cast<int>(a.pointerHotAreas.size());
106     for (int index = 0; index < sizeOfPointerHotAreas; index++) {
107         if (a.pointerHotAreas[index] != b.pointerHotAreas[index]) {
108             return false;
109         }
110     }
111     int sizeOfPointerChangeAreas = static_cast<int>(a.pointerChangeAreas.size());
112     for (int index = 0; index < sizeOfPointerChangeAreas; index++) {
113         if (a.pointerChangeAreas[index] != b.pointerChangeAreas[index]) {
114             return false;
115         }
116     }
117 
118     if (a.transform != b.transform) {
119         return false;
120     }
121     if (!IsEqualUiExtentionWindowInfo(a.uiExtentionWindowInfo, b.uiExtentionWindowInfo)) {
122         return false;
123     }
124     return true;
125 }
126 
operator !=(const MMI::WindowInfo & a,const MMI::WindowInfo & b)127 bool operator!=(const MMI::WindowInfo& a, const MMI::WindowInfo& b)
128 {
129     if (a == b) {
130         return false;
131     }
132     return true;
133 }
134 
IsEqualUiExtentionWindowInfo(const std::vector<MMI::WindowInfo> & a,const std::vector<MMI::WindowInfo> & b)135 bool IsEqualUiExtentionWindowInfo(const std::vector<MMI::WindowInfo>& a, const std::vector<MMI::WindowInfo>& b)
136 {
137     if (a.size() != b.size()) {
138         return false;
139     }
140     int size = static_cast<int>(a.size());
141     for (int i = 0; i < size; i++) {
142         if (a[i] != b[i]) {
143             return false;
144         }
145     }
146     return true;
147 }
148 
DumpTransformInDisplayInfo(const std::vector<float> & transform)149 std::string DumpTransformInDisplayInfo(const std::vector<float>& transform)
150 {
151     std::stringstream stream("[");
152     for (float transformItem : transform) {
153         stream << transformItem << ",";
154     }
155     stream << "]";
156     return stream.str();
157 }
158 
DumpDisplayInfo(const MMI::DisplayInfo & info)159 std::string DumpDisplayInfo(const MMI::DisplayInfo& info)
160 {
161     std::string infoStr =  "DisplayInfo: ";
162     infoStr = infoStr + " id: " + std::to_string(info.id) + " x: " + std::to_string(info.x) +
163         "y: " + std::to_string(info.y) + " width: " + std::to_string(info.width) +
164         "height: " + std::to_string(info.height) + " dpi: " + std::to_string(info.dpi) + " name:" + info.name +
165         " uniq: " + info.uniq + " displayMode: " + std::to_string(static_cast<int>(info.displayMode)) +
166         " direction: " + std::to_string(static_cast<int>(info.direction)) +
167         " transform: " + DumpTransformInDisplayInfo(info.transform);
168     return infoStr;
169 }
170 } //namespace
171 
172 
WM_IMPLEMENT_SINGLE_INSTANCE(SceneInputManager)173 WM_IMPLEMENT_SINGLE_INSTANCE(SceneInputManager)
174 
175 void SceneInputManager::Init()
176 {
177     sceneSessionDirty_ = std::make_shared<SceneSessionDirtyManager>();
178     eventLoop_ = AppExecFwk::EventRunner::Create(FLUSH_DISPLAY_INFO_THREAD);
179     eventHandler_ = std::make_shared<AppExecFwk::EventHandler>(eventLoop_);
180     auto callback = [this]() {
181         FlushDisplayInfoToMMI();
182     };
183     sceneSessionDirty_->RegisterFlushWindowInfoCallback(callback);
184 }
185 
ConstructDisplayInfos(std::vector<MMI::DisplayInfo> & displayInfos)186 void SceneInputManager::ConstructDisplayInfos(std::vector<MMI::DisplayInfo>& displayInfos)
187 {
188     std::map<ScreenId, ScreenProperty> screensProperties =
189         Rosen::ScreenSessionManagerClient::GetInstance().GetAllScreensProperties();
190     auto displayMode = Rosen::ScreenSessionManagerClient::GetInstance().GetFoldDisplayMode();
191     for (auto& iter: screensProperties) {
192         auto screenId = iter.first;
193         auto& screenProperty = iter.second;
194         auto screenSession = Rosen::ScreenSessionManagerClient::GetInstance().GetScreenSessionById(screenId);
195         MMI::Direction displayRotation;
196         if (screenSession && screenSession->GetDisplayNode()) {
197             displayRotation = ConvertDegreeToMMIRotation(
198                 screenSession->GetDisplayNode()->GetStagingProperties().GetRotation(),
199                 static_cast<MMI::DisplayMode>(displayMode));
200         } else {
201             displayRotation = ConvertDegreeToMMIRotation(screenProperty.GetRotation(),
202                 static_cast<MMI::DisplayMode>(displayMode));
203         }
204         auto screenWidth = screenProperty.GetBounds().rect_.GetWidth();
205         auto screenHeight = screenProperty.GetBounds().rect_.GetHeight();
206         auto transform = Matrix3f::IDENTITY;
207         Vector2f scale(screenProperty.GetScaleX(), screenProperty.GetScaleY());
208         transform = transform.Scale(scale, screenProperty.GetPivotX() * screenWidth,
209             screenProperty.GetPivotY() * screenHeight);
210         transform = transform.Inverse();
211         std::vector<float> transformData(transform.GetData(), transform.GetData() + TRANSFORM_DATA_LEN);
212         MMI::DisplayInfo displayInfo = {
213             .id = screenId,
214             .x = screenProperty.GetOffsetX(),
215             .y = screenProperty.GetOffsetY(),
216             .width = screenWidth,
217             .height = screenHeight,
218             .dpi = screenProperty.GetDensity() *  DOT_PER_INCH,
219             .name = "display" + std::to_string(screenId),
220             .uniq = "default" + std::to_string(screenId),
221             .direction = ConvertDegreeToMMIRotation(screenProperty.GetRotation(),
222                 static_cast<MMI::DisplayMode>(displayMode)),
223             .displayDirection = displayRotation,
224             .displayMode = static_cast<MMI::DisplayMode>(displayMode),
225             .transform = transformData};
226         displayInfos.emplace_back(displayInfo);
227     }
228 }
229 
FlushFullInfoToMMI(const std::vector<MMI::DisplayInfo> & displayInfos,const std::vector<MMI::WindowInfo> & windowInfoList)230 void SceneInputManager::FlushFullInfoToMMI(const std::vector<MMI::DisplayInfo>& displayInfos,
231     const std::vector<MMI::WindowInfo>& windowInfoList)
232 {
233     int mainScreenWidth = 0;
234     int mainScreenHeight = 0;
235     if (!displayInfos.empty()) {
236         mainScreenWidth = displayInfos[0].width;
237         mainScreenHeight = displayInfos[0].height;
238     }
239     if (sceneSessionDirty_ == nullptr) {
240         WLOGFE("scene session dirty is null");
241         return;
242     }
243 
244     MMI::DisplayGroupInfo displayGroupInfo = {
245         .width = mainScreenWidth,
246         .height = mainScreenHeight,
247         .focusWindowId = focusedSessionId_,
248         .currentUserId = currentUserId_,
249         .windowsInfo = windowInfoList,
250         .displaysInfo = displayInfos};
251     for (const auto& displayInfo : displayGroupInfo.displaysInfo) {
252         TLOGD(WmsLogTag::WMS_EVENT, "[EventDispatch] - %{public}s", DumpDisplayInfo(displayInfo).c_str());
253     }
254     std::string windowInfoListDump = "windowinfo  ";
255     for (const auto& windowInfo : displayGroupInfo.windowsInfo) {
256         windowInfoListDump.append(DumpWindowInfo(windowInfo).append("  ||  "));
257     }
258     TLOGD(WmsLogTag::WMS_EVENT, "[EventDispatch] - %{public}s", windowInfoListDump.c_str());
259     MMI::InputManager::GetInstance()->UpdateDisplayInfo(displayGroupInfo);
260 }
261 
FlushEmptyInfoToMMI()262 void SceneInputManager::FlushEmptyInfoToMMI()
263 {
264     auto task = [this]() {
265         std::vector<MMI::DisplayInfo> displayInfos;
266         ConstructDisplayInfos(displayInfos);
267         int mainScreenWidth = 0;
268         int mainScreenHeight = 0;
269         if (!displayInfos.empty()) {
270             mainScreenWidth = displayInfos[0].width;
271             mainScreenHeight = displayInfos[0].height;
272         }
273         MMI::DisplayGroupInfo displayGroupInfo = {
274             .width = mainScreenWidth,
275             .height = mainScreenHeight,
276             .focusWindowId = EMPTY_FOCUS_WINDOW_ID,
277             .currentUserId = currentUserId_,
278             .displaysInfo = displayInfos
279         };
280         TLOGI(WmsLogTag::WMS_EVENT, "currUserId:%{public}d width:%{public}d height:%{public}d",
281             currentUserId_, mainScreenWidth, mainScreenHeight);
282         MMI::InputManager::GetInstance()->UpdateDisplayInfo(displayGroupInfo);
283     };
284     if (eventHandler_) {
285         eventHandler_->PostTask(task);
286     }
287 }
288 
NotifyWindowInfoChange(const sptr<SceneSession> & sceneSession,const WindowUpdateType & type)289 void SceneInputManager::NotifyWindowInfoChange(const sptr<SceneSession>& sceneSession, const WindowUpdateType& type)
290 {
291     if (sceneSessionDirty_) {
292         sceneSessionDirty_->NotifyWindowInfoChange(sceneSession, type);
293     }
294 }
295 
NotifyMMIWindowPidChange(const sptr<SceneSession> & sceneSession,const bool startMoving)296 void SceneInputManager::NotifyMMIWindowPidChange(const sptr<SceneSession>& sceneSession, const bool startMoving)
297 {
298     if (sceneSessionDirty_) {
299         sceneSessionDirty_->NotifyWindowInfoChange(sceneSession,
300             WindowUpdateType::WINDOW_UPDATE_PROPERTY, startMoving);
301         if (sceneSession == nullptr) {
302             return;
303         }
304         sceneSession->SetIsStartMoving(startMoving);
305     }
306 }
307 
NotifyWindowInfoChangeFromSession(const sptr<SceneSession> & sceneSesion)308 void SceneInputManager::NotifyWindowInfoChangeFromSession(const sptr<SceneSession>& sceneSesion)
309 {
310     if (sceneSessionDirty_) {
311         sceneSessionDirty_->NotifyWindowInfoChange(sceneSesion, WindowUpdateType::WINDOW_UPDATE_PROPERTY);
312     }
313 }
314 
FlushChangeInfoToMMI(const std::map<uint64_t,std::vector<MMI::WindowInfo>> & screenId2Windows)315 void SceneInputManager::FlushChangeInfoToMMI(const std::map<uint64_t, std::vector<MMI::WindowInfo>>& screenId2Windows)
316 {
317     for (auto& iter : screenId2Windows) {
318         auto displayId = iter.first;
319         auto& windowInfos = iter.second;
320         std::string windowInfoListDump = "windowinfo  ";
321         for (auto& windowInfo : windowInfos) {
322             windowInfoListDump.append(DumpWindowInfo(windowInfo).append("  ||  "));
323         }
324         TLOGD(WmsLogTag::WMS_EVENT, "[EventDispatch] --- %{public}s", windowInfoListDump.c_str());
325         MMI::WindowGroupInfo windowGroup = {focusedSessionId_, displayId, windowInfos};
326         MMI::InputManager::GetInstance()->UpdateWindowInfo(windowGroup);
327     }
328 }
329 
CheckNeedUpdate(const std::vector<MMI::DisplayInfo> & displayInfos,const std::vector<MMI::WindowInfo> & windowInfoList)330 bool SceneInputManager::CheckNeedUpdate(const std::vector<MMI::DisplayInfo>& displayInfos,
331     const std::vector<MMI::WindowInfo>& windowInfoList)
332 {
333     int32_t focusId = SceneSessionManager::GetInstance().GetFocusedSessionId();
334     if (focusId != lastFocusId_) {
335         lastFocusId_ = focusId;
336         lastDisplayInfos_ = displayInfos;
337         lastWindowInfoList_ = windowInfoList;
338         return true;
339     }
340 
341     if (displayInfos.size() != lastDisplayInfos_.size() || windowInfoList.size() != lastWindowInfoList_.size()) {
342         lastDisplayInfos_ = displayInfos;
343         lastWindowInfoList_ = windowInfoList;
344         return true;
345     }
346 
347     int sizeOfDisplayInfos = static_cast<int>(displayInfos.size());
348     for (int index = 0; index < sizeOfDisplayInfos; index++) {
349         if (!(displayInfos[index] == lastDisplayInfos_[index])) {
350             lastDisplayInfos_ = displayInfos;
351             lastWindowInfoList_ = windowInfoList;
352             return true;
353         }
354     }
355 
356     int sizeOfWindowInfoList = static_cast<int>(windowInfoList.size());
357     for (int index = 0; index < sizeOfWindowInfoList; index++) {
358         if (!(windowInfoList[index] == lastWindowInfoList_[index])) {
359             lastWindowInfoList_ = windowInfoList;
360             return true;
361         }
362     }
363     return false;
364 }
365 
UpdateFocusedSessionId(int32_t focusedSessionId)366 void SceneInputManager::UpdateFocusedSessionId(int32_t focusedSessionId)
367 {
368     auto focusedSceneSession = SceneSessionManager::GetInstance().GetSceneSession(focusedSessionId);
369     if (focusedSceneSession == nullptr) {
370         TLOGE(WmsLogTag::WMS_EVENT, "focusedSceneSession is null");
371         return;
372     }
373     if (auto modalUIExtensionEventInfo = focusedSceneSession->GetLastModalUIExtensionEventInfo()) {
374         focusedSessionId_ = modalUIExtensionEventInfo.value().persistentId;
375     }
376 }
377 
DumpUIExtentionWindowInfo(const MMI::WindowInfo & windowInfo)378 void DumpUIExtentionWindowInfo(const MMI::WindowInfo& windowInfo)
379 {
380     auto sceneSession = SceneSessionManager::GetInstance().GetSceneSession(windowInfo.id);
381     if (sceneSession == nullptr) {
382         TLOGE(WmsLogTag::WMS_EVENT, "sceneSession is null");
383         return;
384     }
385     auto surfaceNode = sceneSession->GetSurfaceNode();
386     if (surfaceNode == nullptr) {
387         TLOGE(WmsLogTag::WMS_EVENT, "surfaceNode is null");
388         return;
389     }
390     auto surfaceId = surfaceNode->GetId();
391     TLOGI(WmsLogTag::WMS_EVENT, "HostId:%{public}d surfaceId:%{public}" PRIu64
392         " uiExtentionWindowInfo:%{public}d",
393         windowInfo.id, surfaceId, static_cast<int>(windowInfo.uiExtentionWindowInfo.size()));
394     for (auto uiExWindowinfo : windowInfo.uiExtentionWindowInfo) {
395         auto str = DumpWindowInfo(uiExWindowinfo);
396         str = "sec:" + std::to_string(uiExWindowinfo.privacyUIFlag) + " " + str;
397         TLOGI(WmsLogTag::WMS_EVENT, "uiExWindowinfo:%{public}s", str.c_str());
398     }
399 }
400 
PrintWindowInfo(const std::vector<MMI::WindowInfo> & windowInfoList)401 void SceneInputManager::PrintWindowInfo(const std::vector<MMI::WindowInfo>& windowInfoList)
402 {
403     int windowListSize = static_cast<int>(windowInfoList.size());
404     std::string idList;
405     static std::string lastIdList;
406     static uint32_t windowEventID = 0;
407     if (windowEventID == UINT32_MAX) {
408         windowEventID = 0;
409     }
410     focusedSessionId_ = SceneSessionManager::GetInstance().GetFocusedSessionId();
411     std::unordered_map<int32_t, MMI::Rect> currWindowDefaultHotArea;
412     static std::unordered_map<int32_t, MMI::Rect> lastWindowDefaultHotArea;
413     for (auto& e : windowInfoList) {
414         idList += std::to_string(e.id) + "|" + std::to_string(e.flags) + "|" +
415             std::to_string(static_cast<int32_t>(e.zOrder)) + "|" +
416             std::to_string(e.pid) + "|" +
417             std::to_string(e.defaultHotAreas.size());
418 
419         if (e.defaultHotAreas.size() > 0) {
420             auto iter = lastWindowDefaultHotArea.find(e.id);
421             if (iter == lastWindowDefaultHotArea.end() || iter->second != e.defaultHotAreas[0]) {
422                 idList += "|" + std::to_string(e.defaultHotAreas[0].x) + "|" +
423                     std::to_string(e.defaultHotAreas[0].y) + "|" +
424                     std::to_string(e.defaultHotAreas[0].width) + "|" +
425                     std::to_string(e.defaultHotAreas[0].height);
426             }
427             currWindowDefaultHotArea.insert({e.id, e.defaultHotAreas[0]});
428         }
429         idList += ",";
430         if ((focusedSessionId_ == e.id) && (e.id == e.agentWindowId)) {
431             UpdateFocusedSessionId(focusedSessionId_);
432         }
433         if (e.uiExtentionWindowInfo.size() > 0) {
434             DumpUIExtentionWindowInfo(e);
435         }
436     }
437     lastWindowDefaultHotArea = currWindowDefaultHotArea;
438     idList += std::to_string(focusedSessionId_);
439     if (lastIdList != idList) {
440         windowEventID++;
441         TLOGI(WmsLogTag::WMS_EVENT, "eid:%{public}d,size:%{public}d,idList:%{public}s",
442             windowEventID, windowListSize, idList.c_str());
443         lastIdList = idList;
444     }
445 }
446 
SetUserBackground(bool userBackground)447 void SceneInputManager::SetUserBackground(bool userBackground)
448 {
449     TLOGI(WmsLogTag::WMS_MULTI_USER, "userBackground = %{public}d", userBackground);
450     isUserBackground_.store(userBackground);
451 }
452 
SetCurrentUserId(int32_t userId)453 void SceneInputManager::SetCurrentUserId(int32_t userId)
454 {
455     TLOGI(WmsLogTag::WMS_MULTI_USER, "Current userId = %{public}d", userId);
456     currentUserId_ = userId;
457     MMI::InputManager::GetInstance()->SetCurrentUser(userId);
458 }
459 
UpdateDisplayAndWindowInfo(const std::vector<MMI::DisplayInfo> & displayInfos,std::vector<MMI::WindowInfo> windowInfoList)460 void SceneInputManager::UpdateDisplayAndWindowInfo(const std::vector<MMI::DisplayInfo>& displayInfos,
461     std::vector<MMI::WindowInfo> windowInfoList)
462 {
463     if (windowInfoList.size() == 0) {
464         return;
465     }
466     int32_t windowBatchSize = MAX_WINDOWINFO_NUM;
467     if (windowInfoList[0].defaultHotAreas.size() > MMI::WindowInfo::DEFAULT_HOTAREA_COUNT) {
468         windowBatchSize = MMI::InputManager::GetInstance()->GetWinSyncBatchSize(
469             static_cast<int32_t>(windowInfoList[0].defaultHotAreas.size()),
470             static_cast<int32_t>(displayInfos.size()));
471     }
472     windowInfoList.back().action = MMI::WINDOW_UPDATE_ACTION::ADD_END;
473     int32_t windowListSize = static_cast<int32_t>(windowInfoList.size());
474     if (windowListSize <= windowBatchSize) {
475         FlushFullInfoToMMI(displayInfos, windowInfoList);
476         return;
477     }
478     auto iterBegin = windowInfoList.begin();
479     auto iterEnd = windowInfoList.end();
480     auto iterNext = std::next(iterBegin, windowBatchSize);
481     FlushFullInfoToMMI(displayInfos, std::vector<MMI::WindowInfo>(iterBegin, iterNext));
482     while (iterNext != iterEnd) {
483         auto iterNewBegin = iterNext;
484         if (iterNewBegin->defaultHotAreas.size() <= MMI::WindowInfo::DEFAULT_HOTAREA_COUNT) {
485             windowBatchSize = MAX_WINDOWINFO_NUM;
486         }
487         if (std::distance(iterNewBegin, iterEnd) <= windowBatchSize) {
488             iterNext = iterEnd;
489         } else {
490             iterNext = std::next(iterNewBegin, windowBatchSize);
491         }
492         std::map<uint64_t, std::vector<MMI::WindowInfo>> screenToWindowInfoList;
493         screenToWindowInfoList.emplace(DEFALUT_DISPLAYID, std::vector<MMI::WindowInfo>(iterNewBegin, iterNext));
494         FlushChangeInfoToMMI(screenToWindowInfoList);
495     }
496 }
497 
FlushDisplayInfoToMMI(const bool forceFlush)498 void SceneInputManager::FlushDisplayInfoToMMI(const bool forceFlush)
499 {
500     auto task = [this, forceFlush]() {
501         HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "FlushDisplayInfoToMMI");
502         if (isUserBackground_.load()) {
503             TLOGD(WmsLogTag::WMS_MULTI_USER, "User in background, no need to flush display info");
504             return;
505         }
506         if (sceneSessionDirty_ == nullptr) {
507             TLOGE(WmsLogTag::WMS_EVENT, "sceneSessionDirty_ is nullptr");
508             return;
509         }
510         sceneSessionDirty_->ResetSessionDirty();
511         std::vector<MMI::DisplayInfo> displayInfos;
512         ConstructDisplayInfos(displayInfos);
513         auto [windowInfoList, pixelMapList] = sceneSessionDirty_->GetFullWindowInfoList();
514         if (!forceFlush && !CheckNeedUpdate(displayInfos, windowInfoList)) {
515             return;
516         }
517         PrintWindowInfo(windowInfoList);
518         if (windowInfoList.size() == 0) {
519             FlushFullInfoToMMI(displayInfos, windowInfoList);
520             return;
521         }
522         UpdateDisplayAndWindowInfo(displayInfos, std::move(windowInfoList));
523     };
524     if (eventHandler_) {
525         eventHandler_->PostTask(task);
526     }
527 }
528 
UpdateSecSurfaceInfo(const std::map<uint64_t,std::vector<SecSurfaceInfo>> & secSurfaceInfoMap)529 void SceneInputManager::UpdateSecSurfaceInfo(const std::map<uint64_t, std::vector<SecSurfaceInfo>>& secSurfaceInfoMap)
530 {
531     if (sceneSessionDirty_ == nullptr) {
532         TLOGE(WmsLogTag::WMS_EVENT, "sceneSessionDirty_ is nullptr");
533         return;
534     }
535     sceneSessionDirty_->UpdateSecSurfaceInfo(secSurfaceInfoMap);
536 }
537 }
538 } // namespace OHOS::Rosen
539