From 37c1b992d923106d79f4b299b2661a5fde0892cc Mon Sep 17 00:00:00 2001 From: Linnan Li Date: Fri, 24 Nov 2023 13:05:13 +0800 Subject: PointerController: Get initial DisplayInfos from SurfaceComposerClient After the PointerController is created, if SurfaceFlinger hasn't called back to notify DisplayInfo,the PointerController won't have DisplayInfo, if the actual display exists and transforms at this time, using the display touch position will result in the wrong actual display position. Steps to reproduce the problem. 1. Switch the device to landscape. 2. Execute `adb shell settings put system show_touch 1`. 3. Touch the screen. 4. At this point, you can observe that the screen flashes an incorrect touch point location. How to fix it The addWindowInfosListener method has a parameter to get the initial position, which we use to get the current DisplayInfo at creation time. Even though this information would not exist if there were no other listeners, it doesn't matter here because the InputDispatcher was created long before the PointerController, and the InputDispatcher already added a listener, so the DisplayInfo information must exist, so we don't have to worry about this. Bug: 313033164 Test: Manual Change-Id: Ia942c85d1b2204690f69e6a2ba43cfb7542af27c Signed-off-by: Linnan Li --- libs/input/PointerController.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'libs/input/PointerController.cpp') diff --git a/libs/input/PointerController.cpp b/libs/input/PointerController.cpp index bba9c9764eee..1604ba2968db 100644 --- a/libs/input/PointerController.cpp +++ b/libs/input/PointerController.cpp @@ -111,7 +111,11 @@ PointerController::PointerController(const sp& : PointerController( policy, looper, spriteController, enabled, [](const sp& listener) { - SurfaceComposerClient::getDefault()->addWindowInfosListener(listener); + auto initialInfo = std::make_pair(std::vector{}, + std::vector{}); + SurfaceComposerClient::getDefault()->addWindowInfosListener(listener, + &initialInfo); + return initialInfo; }, [](const sp& listener) { SurfaceComposerClient::getDefault()->removeWindowInfosListener(listener); @@ -119,8 +123,9 @@ PointerController::PointerController(const sp& PointerController::PointerController(const sp& policy, const sp& looper, SpriteController& spriteController, - bool enabled, WindowListenerConsumer registerListener, - WindowListenerConsumer unregisterListener) + bool enabled, + const WindowListenerRegisterConsumer& registerListener, + WindowListenerUnregisterConsumer unregisterListener) : mEnabled(enabled), mContext(policy, looper, spriteController, *this), mCursorController(mContext), @@ -128,7 +133,8 @@ PointerController::PointerController(const sp& mUnregisterWindowInfosListener(std::move(unregisterListener)) { std::scoped_lock lock(getLock()); mLocked.presentation = Presentation::SPOT; - registerListener(mDisplayInfoListener); + const auto& [_, initialDisplayInfos] = registerListener(mDisplayInfoListener); + onDisplayInfosChangedLocked(initialDisplayInfos); } PointerController::~PointerController() { -- cgit v1.2.3-59-g8ed1b