Skip to content

Commit ff80e30

Browse files
Liana Kazanova (xWF)Android (Google) Code Review
authored andcommitted
Revert "Enable cursor to transition across multiple displays"
Revert submission 30111126-cd-cursor Reason for revert: DroidMonitor: Potential culprit for http://b/379706345 - verifying through ABTD before revert submission. This is part of the standard investigation process, and does not mean your CL will be reverted. Reverted changes: /q/submissionid:30111126-cd-cursor Change-Id: I103ede77057d5586faba00efffbe160e5ffa845a
1 parent a5ba9f1 commit ff80e30

5 files changed

Lines changed: 43 additions & 217 deletions

File tree

services/inputflinger/PointerChoreographer.cpp

Lines changed: 38 additions & 177 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,6 @@ std::unordered_set<ui::LogicalDisplayId> getPrivacySensitiveDisplaysFromWindowIn
103103

104104
// --- PointerChoreographer ---
105105

106-
const bool PointerChoreographer::IS_TOPOLOGY_AWARE =
107-
com::android::input::flags::connected_displays_cursor();
108-
109106
PointerChoreographer::PointerChoreographer(InputListenerInterface& inputListener,
110107
PointerChoreographerPolicyInterface& policy)
111108
: PointerChoreographer(
@@ -207,30 +204,20 @@ void PointerChoreographer::fadeMouseCursorOnKeyPress(const android::NotifyKeyArg
207204
}
208205

209206
NotifyMotionArgs PointerChoreographer::processMotion(const NotifyMotionArgs& args) {
210-
NotifyMotionArgs newArgs(args);
211-
PointerDisplayChange pointerDisplayChange;
212-
{ // acquire lock
213-
std::scoped_lock _l(mLock);
214-
if (isFromMouse(args)) {
215-
newArgs = processMouseEventLocked(args);
216-
pointerDisplayChange = calculatePointerDisplayChangeToNotify();
217-
} else if (isFromTouchpad(args)) {
218-
newArgs = processTouchpadEventLocked(args);
219-
pointerDisplayChange = calculatePointerDisplayChangeToNotify();
220-
} else if (isFromDrawingTablet(args)) {
221-
processDrawingTabletEventLocked(args);
222-
} else if (mStylusPointerIconEnabled && isStylusHoverEvent(args)) {
223-
processStylusHoverEventLocked(args);
224-
} else if (isFromSource(args.source, AINPUT_SOURCE_TOUCHSCREEN)) {
225-
processTouchscreenAndStylusEventLocked(args);
226-
}
227-
} // release lock
207+
std::scoped_lock _l(mLock);
228208

229-
if (pointerDisplayChange) {
230-
// pointer display may have changed if mouse crossed display boundary
231-
notifyPointerDisplayChange(pointerDisplayChange, mPolicy);
209+
if (isFromMouse(args)) {
210+
return processMouseEventLocked(args);
211+
} else if (isFromTouchpad(args)) {
212+
return processTouchpadEventLocked(args);
213+
} else if (isFromDrawingTablet(args)) {
214+
processDrawingTabletEventLocked(args);
215+
} else if (mStylusPointerIconEnabled && isStylusHoverEvent(args)) {
216+
processStylusHoverEventLocked(args);
217+
} else if (isFromSource(args.source, AINPUT_SOURCE_TOUCHSCREEN)) {
218+
processTouchscreenAndStylusEventLocked(args);
232219
}
233-
return newArgs;
220+
return args;
234221
}
235222

236223
NotifyMotionArgs PointerChoreographer::processMouseEventLocked(const NotifyMotionArgs& args) {
@@ -255,10 +242,16 @@ NotifyMotionArgs PointerChoreographer::processMouseEventLocked(const NotifyMotio
255242
pc.setPosition(args.xCursorPosition, args.yCursorPosition);
256243
} else {
257244
// This is a relative mouse, so move the cursor by the specified amount.
258-
processPointerDeviceMotionEventLocked(/*byref*/ newArgs, /*byref*/ pc);
245+
const float deltaX = args.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_RELATIVE_X);
246+
const float deltaY = args.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_RELATIVE_Y);
247+
pc.move(deltaX, deltaY);
248+
const auto [x, y] = pc.getPosition();
249+
newArgs.pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_X, x);
250+
newArgs.pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_Y, y);
251+
newArgs.xCursorPosition = x;
252+
newArgs.yCursorPosition = y;
259253
}
260-
// Note displayId may have changed if the cursor moved to a different display
261-
if (canUnfadeOnDisplay(newArgs.displayId)) {
254+
if (canUnfadeOnDisplay(displayId)) {
262255
pc.unfade(PointerControllerInterface::Transition::IMMEDIATE);
263256
}
264257
return newArgs;
@@ -272,9 +265,24 @@ NotifyMotionArgs PointerChoreographer::processTouchpadEventLocked(const NotifyMo
272265
newArgs.displayId = displayId;
273266
if (args.getPointerCount() == 1 && args.classification == MotionClassification::NONE) {
274267
// This is a movement of the mouse pointer.
275-
processPointerDeviceMotionEventLocked(/*byref*/ newArgs, /*byref*/ pc);
268+
const float deltaX = args.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_RELATIVE_X);
269+
const float deltaY = args.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_RELATIVE_Y);
270+
pc.move(deltaX, deltaY);
271+
if (canUnfadeOnDisplay(displayId)) {
272+
pc.unfade(PointerControllerInterface::Transition::IMMEDIATE);
273+
}
274+
275+
const auto [x, y] = pc.getPosition();
276+
newArgs.pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_X, x);
277+
newArgs.pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_Y, y);
278+
newArgs.xCursorPosition = x;
279+
newArgs.yCursorPosition = y;
276280
} else {
277281
// This is a trackpad gesture with fake finger(s) that should not move the mouse pointer.
282+
if (canUnfadeOnDisplay(displayId)) {
283+
pc.unfade(PointerControllerInterface::Transition::IMMEDIATE);
284+
}
285+
278286
const auto [x, y] = pc.getPosition();
279287
for (uint32_t i = 0; i < newArgs.getPointerCount(); i++) {
280288
newArgs.pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_X,
@@ -285,61 +293,9 @@ NotifyMotionArgs PointerChoreographer::processTouchpadEventLocked(const NotifyMo
285293
newArgs.xCursorPosition = x;
286294
newArgs.yCursorPosition = y;
287295
}
288-
289-
// Note displayId may have changed if the cursor moved to a different display
290-
if (canUnfadeOnDisplay(newArgs.displayId)) {
291-
pc.unfade(PointerControllerInterface::Transition::IMMEDIATE);
292-
}
293296
return newArgs;
294297
}
295298

296-
void PointerChoreographer::processPointerDeviceMotionEventLocked(NotifyMotionArgs& newArgs,
297-
PointerControllerInterface& pc) {
298-
const float deltaX = newArgs.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_RELATIVE_X);
299-
const float deltaY = newArgs.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_RELATIVE_Y);
300-
vec2 unconsumedDelta = pc.move(deltaX, deltaY);
301-
if (IS_TOPOLOGY_AWARE && (std::abs(unconsumedDelta.x) > 0 || std::abs(unconsumedDelta.y) > 0)) {
302-
handleUnconsumedDeltaLocked(pc, unconsumedDelta);
303-
// pointer may have moved to a different viewport
304-
newArgs.displayId = pc.getDisplayId();
305-
}
306-
const auto [x, y] = pc.getPosition();
307-
newArgs.pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_X, x);
308-
newArgs.pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_Y, y);
309-
newArgs.xCursorPosition = x;
310-
newArgs.yCursorPosition = y;
311-
}
312-
313-
void PointerChoreographer::handleUnconsumedDeltaLocked(PointerControllerInterface& pc,
314-
const vec2& unconsumedDelta) {
315-
const ui::LogicalDisplayId sourceDisplayId = pc.getDisplayId();
316-
const auto& sourceViewport = *findViewportByIdLocked(sourceDisplayId);
317-
std::optional<AdjacentDisplay> destinationDisplay =
318-
findDestinationDisplayLocked(sourceViewport, unconsumedDelta);
319-
if (!destinationDisplay) {
320-
// no adjacent display
321-
return;
322-
}
323-
324-
const DisplayViewport* destinationViewport =
325-
findViewportByIdLocked(destinationDisplay->displayId);
326-
if (destinationViewport == nullptr) {
327-
// Topology is likely out of sync with viewport info, wait for them to be updated
328-
LOG(WARNING) << "Cannot find viewport for adjacent display "
329-
<< destinationDisplay->displayId << "of source display " << sourceDisplayId;
330-
return;
331-
}
332-
333-
mDefaultMouseDisplayId = destinationDisplay->displayId;
334-
auto pcNode = mMousePointersByDisplay.extract(sourceDisplayId);
335-
pcNode.key() = destinationDisplay->displayId;
336-
mMousePointersByDisplay.insert(std::move(pcNode));
337-
338-
// This will place cursor at the center of the target display for now
339-
// TODO (b/367660694) place the cursor at the appropriate position in destination display
340-
pc.setDisplayViewport(*destinationViewport);
341-
}
342-
343299
void PointerChoreographer::processDrawingTabletEventLocked(const android::NotifyMotionArgs& args) {
344300
if (args.displayId == ui::LogicalDisplayId::INVALID) {
345301
return;
@@ -485,8 +441,7 @@ void PointerChoreographer::processDeviceReset(const NotifyDeviceResetArgs& args)
485441
}
486442

487443
void PointerChoreographer::onControllerAddedOrRemovedLocked() {
488-
if (!com::android::input::flags::hide_pointer_indicators_for_secure_windows() &&
489-
!IS_TOPOLOGY_AWARE) {
444+
if (!com::android::input::flags::hide_pointer_indicators_for_secure_windows()) {
490445
return;
491446
}
492447
bool requireListener = !mTouchPointersByDevice.empty() || !mMousePointersByDisplay.empty() ||
@@ -719,10 +674,6 @@ PointerChoreographer::calculatePointerDisplayChangeToNotify() {
719674
}
720675

721676
void PointerChoreographer::setDefaultMouseDisplayId(ui::LogicalDisplayId displayId) {
722-
if (IS_TOPOLOGY_AWARE) {
723-
// default display will be set based on the topology
724-
return;
725-
}
726677
PointerDisplayChange pointerDisplayChange;
727678

728679
{ // acquire lock
@@ -936,7 +887,6 @@ void PointerChoreographer::PointerChoreographerDisplayInfoListener::onWindowInfo
936887
mPrivacySensitiveDisplays = std::move(newPrivacySensitiveDisplays);
937888
mPointerChoreographer->onPrivacySensitiveDisplaysChanged(mPrivacySensitiveDisplays);
938889
}
939-
mPointerChoreographer->populateFakeDisplayTopology(windowInfosUpdate.displayInfos);
940890
}
941891

942892
void PointerChoreographer::PointerChoreographerDisplayInfoListener::setInitialDisplayInfos(
@@ -957,93 +907,4 @@ void PointerChoreographer::PointerChoreographerDisplayInfoListener::
957907
mPointerChoreographer = nullptr;
958908
}
959909

960-
void PointerChoreographer::populateFakeDisplayTopology(
961-
const std::vector<gui::DisplayInfo>& displayInfos) {
962-
if (!IS_TOPOLOGY_AWARE) {
963-
return;
964-
}
965-
std::scoped_lock _lock(mLock);
966-
967-
if (displayInfos.size() == mTopology.size()) {
968-
bool displaysChanged = false;
969-
for (const auto& displayInfo : displayInfos) {
970-
if (mTopology.find(displayInfo.displayId) == mTopology.end()) {
971-
displaysChanged = true;
972-
break;
973-
}
974-
}
975-
976-
if (!displaysChanged) {
977-
return;
978-
}
979-
}
980-
981-
// create a fake topology assuming following order
982-
// default-display (top-edge) -> next-display (right-edge) -> next-display (right-edge) ...
983-
// ┌─────────┬─────────┐
984-
// │ next │ next 2 │ ...
985-
// ├─────────┼─────────┘
986-
// │ default │
987-
// └─────────┘
988-
mTopology.clear();
989-
990-
// treat default display as base, in real topology it should be the primary-display
991-
ui::LogicalDisplayId previousDisplay = ui::LogicalDisplayId::DEFAULT;
992-
for (const auto& displayInfo : displayInfos) {
993-
if (displayInfo.displayId == ui::LogicalDisplayId::DEFAULT) {
994-
continue;
995-
}
996-
if (previousDisplay == ui::LogicalDisplayId::DEFAULT) {
997-
mTopology[previousDisplay].push_back({displayInfo.displayId, DisplayPosition::TOP, 0});
998-
mTopology[displayInfo.displayId].push_back(
999-
{previousDisplay, DisplayPosition::BOTTOM, 0});
1000-
} else {
1001-
mTopology[previousDisplay].push_back(
1002-
{displayInfo.displayId, DisplayPosition::RIGHT, 0});
1003-
mTopology[displayInfo.displayId].push_back({previousDisplay, DisplayPosition::LEFT, 0});
1004-
}
1005-
previousDisplay = displayInfo.displayId;
1006-
}
1007-
1008-
// update default pointer display. In real topology it should be the primary-display
1009-
if (mTopology.find(mDefaultMouseDisplayId) == mTopology.end()) {
1010-
mDefaultMouseDisplayId = ui::LogicalDisplayId::DEFAULT;
1011-
}
1012-
}
1013-
1014-
std::optional<PointerChoreographer::AdjacentDisplay>
1015-
PointerChoreographer::findDestinationDisplayLocked(const DisplayViewport& sourceViewport,
1016-
const vec2& unconsumedDelta) const {
1017-
DisplayPosition sourceBoundary;
1018-
if (unconsumedDelta.x > 0) {
1019-
sourceBoundary = DisplayPosition::RIGHT;
1020-
} else if (unconsumedDelta.x < 0) {
1021-
sourceBoundary = DisplayPosition::LEFT;
1022-
} else if (unconsumedDelta.y > 0) {
1023-
sourceBoundary = DisplayPosition::BOTTOM;
1024-
} else {
1025-
sourceBoundary = DisplayPosition::TOP;
1026-
}
1027-
1028-
// Choreographer works in un-rotate coordinate space so we need to rotate boundary by viewport
1029-
// orientation to find the rotated boundary
1030-
constexpr int MOD = ftl::to_underlying(ui::Rotation::ftl_last) + 1;
1031-
sourceBoundary = static_cast<DisplayPosition>(
1032-
(ftl::to_underlying(sourceBoundary) + ftl::to_underlying(sourceViewport.orientation)) %
1033-
MOD);
1034-
1035-
if (mTopology.find(sourceViewport.displayId) == mTopology.end()) {
1036-
// Topology is likely out of sync with viewport info, wait for them to be updated
1037-
LOG(WARNING) << "Source display missing from topology " << sourceViewport.displayId;
1038-
return std::nullopt;
1039-
}
1040-
1041-
for (const auto& adjacentDisplay : mTopology.at(sourceViewport.displayId)) {
1042-
if (adjacentDisplay.position == sourceBoundary) {
1043-
return adjacentDisplay;
1044-
}
1045-
}
1046-
return std::nullopt;
1047-
}
1048-
1049910
} // namespace android

services/inputflinger/PointerChoreographer.h

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -137,41 +137,13 @@ class PointerChoreographer : public PointerChoreographerInterface {
137137
void processTouchscreenAndStylusEventLocked(const NotifyMotionArgs& args) REQUIRES(mLock);
138138
void processStylusHoverEventLocked(const NotifyMotionArgs& args) REQUIRES(mLock);
139139
void processDeviceReset(const NotifyDeviceResetArgs& args);
140-
void processPointerDeviceMotionEventLocked(NotifyMotionArgs& newArgs,
141-
PointerControllerInterface& pc) REQUIRES(mLock);
142140
void onControllerAddedOrRemovedLocked() REQUIRES(mLock);
143141
void onPrivacySensitiveDisplaysChangedLocked(
144142
const std::unordered_set<ui::LogicalDisplayId>& privacySensitiveDisplays)
145143
REQUIRES(mLock);
146144
void onPrivacySensitiveDisplaysChanged(
147145
const std::unordered_set<ui::LogicalDisplayId>& privacySensitiveDisplays);
148146

149-
void handleUnconsumedDeltaLocked(PointerControllerInterface& pc, const vec2& unconsumedDelta)
150-
REQUIRES(mLock);
151-
152-
// TODO(b/362719483) remove these when real topology is available
153-
enum class DisplayPosition : int32_t {
154-
RIGHT = 0,
155-
TOP = 1,
156-
LEFT = 2,
157-
BOTTOM = 3,
158-
ftl_last = BOTTOM,
159-
};
160-
161-
struct AdjacentDisplay {
162-
ui::LogicalDisplayId displayId;
163-
DisplayPosition position;
164-
float offsetPx;
165-
};
166-
void populateFakeDisplayTopology(const std::vector<gui::DisplayInfo>& displayInfos);
167-
168-
std::optional<AdjacentDisplay> findDestinationDisplayLocked(
169-
const DisplayViewport& sourceViewport, const vec2& unconsumedDelta) const
170-
REQUIRES(mLock);
171-
172-
std::unordered_map<ui::LogicalDisplayId, std::vector<AdjacentDisplay>> mTopology
173-
GUARDED_BY(mLock);
174-
175147
/* This listener keeps tracks of visible privacy sensitive displays and updates the
176148
* choreographer if there are any changes.
177149
*
@@ -239,7 +211,6 @@ class PointerChoreographer : public PointerChoreographerInterface {
239211
const WindowListenerUnregisterConsumer& unregisterListener);
240212

241213
private:
242-
const static bool IS_TOPOLOGY_AWARE;
243214
const WindowListenerRegisterConsumer mRegisterListener;
244215
const WindowListenerUnregisterConsumer mUnregisterListener;
245216
};

services/inputflinger/include/PointerControllerInterface.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,8 @@ class PointerControllerInterface {
7272
/* Dumps the state of the pointer controller. */
7373
virtual std::string dump() = 0;
7474

75-
/* Move the pointer and return unconsumed delta if the pointer has crossed the current
76-
* viewport bounds .
77-
*
78-
* Return value may be used to move pointer to corresponding adjacent display, if it exists in
79-
* the display-topology */
80-
[[nodiscard]] virtual vec2 move(float deltaX, float deltaY) = 0;
75+
/* Move the pointer. */
76+
virtual void move(float deltaX, float deltaY) = 0;
8177

8278
/* Sets the absolute location of the pointer. */
8379
virtual void setPosition(float x, float y) = 0;

services/inputflinger/tests/FakePointerController.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,17 +148,15 @@ bool FakePointerController::isPointerShown() {
148148
return mIsPointerShown;
149149
}
150150

151-
vec2 FakePointerController::move(float deltaX, float deltaY) {
152-
if (!mEnabled) return {};
151+
void FakePointerController::move(float deltaX, float deltaY) {
152+
if (!mEnabled) return;
153153

154154
mX += deltaX;
155155
if (mX < mMinX) mX = mMinX;
156156
if (mX > mMaxX) mX = mMaxX;
157157
mY += deltaY;
158158
if (mY < mMinY) mY = mMinY;
159159
if (mY > mMaxY) mY = mMaxY;
160-
161-
return {};
162160
}
163161

164162
void FakePointerController::fade(Transition) {

services/inputflinger/tests/FakePointerController.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class FakePointerController : public PointerControllerInterface {
6565

6666
private:
6767
std::string dump() override { return ""; }
68-
vec2 move(float deltaX, float deltaY) override;
68+
void move(float deltaX, float deltaY) override;
6969
void unfade(Transition) override;
7070
void setPresentation(Presentation) override {}
7171
void setSpots(const PointerCoords*, const uint32_t*, BitSet32 spotIdBits,

0 commit comments

Comments
 (0)