@@ -798,20 +798,6 @@ bool shouldSplitTouch(int32_t source) {
798798 return !isFromSource (source, AINPUT_SOURCE_MOUSE);
799799}
800800
801- /* *
802- * Return true if stylus is currently down anywhere on the specified display, and false otherwise.
803- */
804- bool isStylusActiveInDisplay (ui::LogicalDisplayId displayId,
805- const std::unordered_map<ui::LogicalDisplayId /* displayId*/ ,
806- TouchState>& touchStatesByDisplay) {
807- const auto it = touchStatesByDisplay.find (displayId);
808- if (it == touchStatesByDisplay.end ()) {
809- return false ;
810- }
811- const TouchState& state = it->second ;
812- return state.hasActiveStylus ();
813- }
814-
815801Result<void > validateWindowInfosUpdate (const gui::WindowInfosUpdate& update) {
816802 std::unordered_set<int32_t > windowIds;
817803 for (const WindowInfo& info : update.windowInfos ) {
@@ -1350,9 +1336,8 @@ bool InputDispatcher::shouldPruneInboundQueueLocked(const MotionEntry& motionEnt
13501336
13511337 // Alternatively, maybe there's a spy window that could handle this event.
13521338 const std::vector<sp<WindowInfoHandle>> touchedSpies =
1353- mWindowInfos .findTouchedSpyWindowsAt (displayId, x, y, isStylus,
1354- motionEntry.deviceId ,
1355- mTouchStates .mTouchStatesByDisplay );
1339+ findTouchedSpyWindowsAt (displayId, x, y, isStylus, motionEntry.deviceId ,
1340+ mWindowInfos );
13561341 for (const auto & windowHandle : touchedSpies) {
13571342 const std::shared_ptr<Connection> connection =
13581343 mConnectionManager .getConnection (windowHandle->getToken ());
@@ -1510,16 +1495,16 @@ std::vector<InputTarget> InputDispatcher::DispatcherTouchState::findOutsideTarge
15101495 return outsideTargets;
15111496}
15121497
1513- std::vector<sp<WindowInfoHandle>> InputDispatcher::DispatcherWindowInfo:: findTouchedSpyWindowsAt (
1498+ std::vector<sp<WindowInfoHandle>> InputDispatcher::findTouchedSpyWindowsAt (
15141499 ui::LogicalDisplayId displayId, float x, float y, bool isStylus, DeviceId deviceId,
1515- const std::unordered_map<ui::LogicalDisplayId, TouchState>& touchStatesByDisplay) const {
1500+ const DispatcherWindowInfo& windowInfos) {
15161501 // Traverse windows from front to back and gather the touched spy windows.
15171502 std::vector<sp<WindowInfoHandle>> spyWindows;
1518- const auto & windowHandles = getWindowHandlesForDisplay (displayId);
1503+ const ui::Transform displayTransform = windowInfos.getDisplayTransform (displayId);
1504+ const auto & windowHandles = windowInfos.getWindowHandlesForDisplay (displayId);
15191505 for (const sp<WindowInfoHandle>& windowHandle : windowHandles) {
15201506 const WindowInfo& info = *windowHandle->getInfo ();
1521- if (!windowAcceptsTouchAt (info, displayId, x, y, isStylus,
1522- getDisplayTransform (displayId))) {
1507+ if (!windowAcceptsTouchAt (info, displayId, x, y, isStylus, displayTransform)) {
15231508 // Skip if the pointer is outside of the window.
15241509 continue ;
15251510 }
@@ -2480,8 +2465,7 @@ InputDispatcher::DispatcherTouchState::findTouchedWindowTargets(
24802465 }
24812466
24822467 std::vector<sp<WindowInfoHandle>> newTouchedWindows =
2483- windowInfos.findTouchedSpyWindowsAt (displayId, x, y, isStylus, entry.deviceId ,
2484- mTouchStatesByDisplay );
2468+ findTouchedSpyWindowsAt (displayId, x, y, isStylus, entry.deviceId , windowInfos);
24852469 if (newTouchedWindowHandle != nullptr ) {
24862470 // Process the foreground window first so that it is the first to receive the event.
24872471 newTouchedWindows.insert (newTouchedWindows.begin (), newTouchedWindowHandle);
@@ -2494,8 +2478,7 @@ InputDispatcher::DispatcherTouchState::findTouchedWindowTargets(
24942478 }
24952479
24962480 for (const sp<WindowInfoHandle>& windowHandle : newTouchedWindows) {
2497- if (!canWindowReceiveMotion (windowHandle, entry, connections, windowInfos,
2498- mTouchStatesByDisplay )) {
2481+ if (!canWindowReceiveMotion (windowHandle, entry, connections, windowInfos)) {
24992482 continue ;
25002483 }
25012484
@@ -2618,8 +2601,7 @@ InputDispatcher::DispatcherTouchState::findTouchedWindowTargets(
26182601
26192602 // Do not slide events to the window which can not receive motion event
26202603 if (newTouchedWindowHandle != nullptr &&
2621- !canWindowReceiveMotion (newTouchedWindowHandle, entry, connections, windowInfos,
2622- mTouchStatesByDisplay )) {
2604+ !canWindowReceiveMotion (newTouchedWindowHandle, entry, connections, windowInfos)) {
26232605 newTouchedWindowHandle = nullptr ;
26242606 }
26252607
@@ -5277,11 +5259,10 @@ std::string InputDispatcher::DispatcherWindowInfo::dumpDisplayAndWindowInfo() co
52775259 return dump;
52785260}
52795261
5280- bool InputDispatcher::canWindowReceiveMotion (
5262+ bool InputDispatcher::DispatcherTouchState:: canWindowReceiveMotion (
52815263 const sp<android::gui::WindowInfoHandle>& window,
52825264 const android::inputdispatcher::MotionEntry& motionEntry,
5283- const ConnectionManager& connections, const DispatcherWindowInfo& windowInfos,
5284- const std::unordered_map<ui::LogicalDisplayId, TouchState>& touchStates) {
5265+ const ConnectionManager& connections, const DispatcherWindowInfo& windowInfos) const {
52855266 const WindowInfo& info = *window->getInfo ();
52865267
52875268 // Skip spy window targets that are not valid for targeted injection.
@@ -5335,7 +5316,7 @@ bool InputDispatcher::canWindowReceiveMotion(
53355316
53365317 // Ignore touches if stylus is down anywhere on screen
53375318 if (info.inputConfig .test (WindowInfo::InputConfig::GLOBAL_STYLUS_BLOCKS_TOUCH) &&
5338- isStylusActiveInDisplay (info.displayId , touchStates )) {
5319+ isStylusActiveInDisplay (info.displayId )) {
53395320 LOG (INFO) << " Dropping touch from " << window->getName () << " because stylus is active" ;
53405321 return false ;
53415322 }
@@ -7539,4 +7520,14 @@ InputDispatcher::DispatcherTouchState::findTouchStateWindowAndDisplay(
75397520 return std::nullopt ;
75407521}
75417522
7523+ bool InputDispatcher::DispatcherTouchState::isStylusActiveInDisplay (
7524+ ui::LogicalDisplayId displayId) const {
7525+ const auto it = mTouchStatesByDisplay .find (displayId);
7526+ if (it == mTouchStatesByDisplay .end ()) {
7527+ return false ;
7528+ }
7529+ const TouchState& state = it->second ;
7530+ return state.hasActiveStylus ();
7531+ }
7532+
75427533} // namespace android::inputdispatcher
0 commit comments