xref: /aosp_15_r20/frameworks/native/services/inputflinger/PointerChoreographer.h (revision 38e8c45f13ce32b0dcecb25141ffecaf386fa17f)
1*38e8c45fSAndroid Build Coastguard Worker /*
2*38e8c45fSAndroid Build Coastguard Worker  * Copyright 2023 The Android Open Source Project
3*38e8c45fSAndroid Build Coastguard Worker  *
4*38e8c45fSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*38e8c45fSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*38e8c45fSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*38e8c45fSAndroid Build Coastguard Worker  *
8*38e8c45fSAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
9*38e8c45fSAndroid Build Coastguard Worker  *
10*38e8c45fSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*38e8c45fSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*38e8c45fSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*38e8c45fSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*38e8c45fSAndroid Build Coastguard Worker  * limitations under the License.
15*38e8c45fSAndroid Build Coastguard Worker  */
16*38e8c45fSAndroid Build Coastguard Worker 
17*38e8c45fSAndroid Build Coastguard Worker #pragma once
18*38e8c45fSAndroid Build Coastguard Worker 
19*38e8c45fSAndroid Build Coastguard Worker #include "InputListener.h"
20*38e8c45fSAndroid Build Coastguard Worker #include "NotifyArgs.h"
21*38e8c45fSAndroid Build Coastguard Worker #include "PointerChoreographerPolicyInterface.h"
22*38e8c45fSAndroid Build Coastguard Worker 
23*38e8c45fSAndroid Build Coastguard Worker #include <android-base/thread_annotations.h>
24*38e8c45fSAndroid Build Coastguard Worker #include <gui/WindowInfosListener.h>
25*38e8c45fSAndroid Build Coastguard Worker #include <type_traits>
26*38e8c45fSAndroid Build Coastguard Worker #include <unordered_set>
27*38e8c45fSAndroid Build Coastguard Worker 
28*38e8c45fSAndroid Build Coastguard Worker namespace android {
29*38e8c45fSAndroid Build Coastguard Worker 
30*38e8c45fSAndroid Build Coastguard Worker struct SpriteIcon;
31*38e8c45fSAndroid Build Coastguard Worker 
32*38e8c45fSAndroid Build Coastguard Worker /**
33*38e8c45fSAndroid Build Coastguard Worker  * A helper class that wraps a factory method that acts as a constructor for the type returned
34*38e8c45fSAndroid Build Coastguard Worker  * by the factory method.
35*38e8c45fSAndroid Build Coastguard Worker  */
36*38e8c45fSAndroid Build Coastguard Worker template <typename Factory>
37*38e8c45fSAndroid Build Coastguard Worker struct ConstructorDelegate {
ConstructorDelegateConstructorDelegate38*38e8c45fSAndroid Build Coastguard Worker     constexpr ConstructorDelegate(Factory&& factory) : mFactory(std::move(factory)) {}
39*38e8c45fSAndroid Build Coastguard Worker 
40*38e8c45fSAndroid Build Coastguard Worker     using ConstructedType = std::invoke_result_t<const Factory&>;
ConstructedTypeConstructorDelegate41*38e8c45fSAndroid Build Coastguard Worker     constexpr operator ConstructedType() const { return mFactory(); }
42*38e8c45fSAndroid Build Coastguard Worker 
43*38e8c45fSAndroid Build Coastguard Worker     Factory mFactory;
44*38e8c45fSAndroid Build Coastguard Worker };
45*38e8c45fSAndroid Build Coastguard Worker 
46*38e8c45fSAndroid Build Coastguard Worker /**
47*38e8c45fSAndroid Build Coastguard Worker  * PointerChoreographer manages the icons shown by the system for input interactions.
48*38e8c45fSAndroid Build Coastguard Worker  * This includes showing the mouse cursor, stylus hover icons, and touch spots.
49*38e8c45fSAndroid Build Coastguard Worker  * It is responsible for accumulating the location of the mouse cursor, and populating
50*38e8c45fSAndroid Build Coastguard Worker  * the cursor position for incoming events, if necessary.
51*38e8c45fSAndroid Build Coastguard Worker  */
52*38e8c45fSAndroid Build Coastguard Worker class PointerChoreographerInterface : public InputListenerInterface {
53*38e8c45fSAndroid Build Coastguard Worker public:
54*38e8c45fSAndroid Build Coastguard Worker     /**
55*38e8c45fSAndroid Build Coastguard Worker      * Set the display that pointers, like the mouse cursor and drawing tablets,
56*38e8c45fSAndroid Build Coastguard Worker      * should be drawn on.
57*38e8c45fSAndroid Build Coastguard Worker      */
58*38e8c45fSAndroid Build Coastguard Worker     virtual void setDefaultMouseDisplayId(ui::LogicalDisplayId displayId) = 0;
59*38e8c45fSAndroid Build Coastguard Worker     virtual void setDisplayViewports(const std::vector<DisplayViewport>& viewports) = 0;
60*38e8c45fSAndroid Build Coastguard Worker     virtual std::optional<DisplayViewport> getViewportForPointerDevice(
61*38e8c45fSAndroid Build Coastguard Worker             ui::LogicalDisplayId associatedDisplayId = ui::LogicalDisplayId::INVALID) = 0;
62*38e8c45fSAndroid Build Coastguard Worker     virtual vec2 getMouseCursorPosition(ui::LogicalDisplayId displayId) = 0;
63*38e8c45fSAndroid Build Coastguard Worker     virtual void setShowTouchesEnabled(bool enabled) = 0;
64*38e8c45fSAndroid Build Coastguard Worker     virtual void setStylusPointerIconEnabled(bool enabled) = 0;
65*38e8c45fSAndroid Build Coastguard Worker     /**
66*38e8c45fSAndroid Build Coastguard Worker      * Set the icon that is shown for the given pointer. The request may fail in some cases, such
67*38e8c45fSAndroid Build Coastguard Worker      * as if the device or display was removed, or if the cursor was moved to a different display.
68*38e8c45fSAndroid Build Coastguard Worker      * Returns true if the icon was changed successfully, false otherwise.
69*38e8c45fSAndroid Build Coastguard Worker      */
70*38e8c45fSAndroid Build Coastguard Worker     virtual bool setPointerIcon(std::variant<std::unique_ptr<SpriteIcon>, PointerIconStyle> icon,
71*38e8c45fSAndroid Build Coastguard Worker                                 ui::LogicalDisplayId displayId, DeviceId deviceId) = 0;
72*38e8c45fSAndroid Build Coastguard Worker     /**
73*38e8c45fSAndroid Build Coastguard Worker      * Set whether pointer icons for mice, touchpads, and styluses should be visible on the
74*38e8c45fSAndroid Build Coastguard Worker      * given display.
75*38e8c45fSAndroid Build Coastguard Worker      */
76*38e8c45fSAndroid Build Coastguard Worker     virtual void setPointerIconVisibility(ui::LogicalDisplayId displayId, bool visible) = 0;
77*38e8c45fSAndroid Build Coastguard Worker 
78*38e8c45fSAndroid Build Coastguard Worker     /**
79*38e8c45fSAndroid Build Coastguard Worker      * Used by Dispatcher to notify changes in the current focused display.
80*38e8c45fSAndroid Build Coastguard Worker      */
81*38e8c45fSAndroid Build Coastguard Worker     virtual void setFocusedDisplay(ui::LogicalDisplayId displayId) = 0;
82*38e8c45fSAndroid Build Coastguard Worker 
83*38e8c45fSAndroid Build Coastguard Worker     /**
84*38e8c45fSAndroid Build Coastguard Worker      * This method may be called on any thread (usually by the input manager on a binder thread).
85*38e8c45fSAndroid Build Coastguard Worker      */
86*38e8c45fSAndroid Build Coastguard Worker     virtual void dump(std::string& dump) = 0;
87*38e8c45fSAndroid Build Coastguard Worker };
88*38e8c45fSAndroid Build Coastguard Worker 
89*38e8c45fSAndroid Build Coastguard Worker class PointerChoreographer : public PointerChoreographerInterface {
90*38e8c45fSAndroid Build Coastguard Worker public:
91*38e8c45fSAndroid Build Coastguard Worker     explicit PointerChoreographer(InputListenerInterface& listener,
92*38e8c45fSAndroid Build Coastguard Worker                                   PointerChoreographerPolicyInterface&);
93*38e8c45fSAndroid Build Coastguard Worker     ~PointerChoreographer() override;
94*38e8c45fSAndroid Build Coastguard Worker 
95*38e8c45fSAndroid Build Coastguard Worker     void setDefaultMouseDisplayId(ui::LogicalDisplayId displayId) override;
96*38e8c45fSAndroid Build Coastguard Worker     void setDisplayViewports(const std::vector<DisplayViewport>& viewports) override;
97*38e8c45fSAndroid Build Coastguard Worker     std::optional<DisplayViewport> getViewportForPointerDevice(
98*38e8c45fSAndroid Build Coastguard Worker             ui::LogicalDisplayId associatedDisplayId) override;
99*38e8c45fSAndroid Build Coastguard Worker     vec2 getMouseCursorPosition(ui::LogicalDisplayId displayId) override;
100*38e8c45fSAndroid Build Coastguard Worker     void setShowTouchesEnabled(bool enabled) override;
101*38e8c45fSAndroid Build Coastguard Worker     void setStylusPointerIconEnabled(bool enabled) override;
102*38e8c45fSAndroid Build Coastguard Worker     bool setPointerIcon(std::variant<std::unique_ptr<SpriteIcon>, PointerIconStyle> icon,
103*38e8c45fSAndroid Build Coastguard Worker                         ui::LogicalDisplayId displayId, DeviceId deviceId) override;
104*38e8c45fSAndroid Build Coastguard Worker     void setPointerIconVisibility(ui::LogicalDisplayId displayId, bool visible) override;
105*38e8c45fSAndroid Build Coastguard Worker     void setFocusedDisplay(ui::LogicalDisplayId displayId) override;
106*38e8c45fSAndroid Build Coastguard Worker 
107*38e8c45fSAndroid Build Coastguard Worker     void notifyInputDevicesChanged(const NotifyInputDevicesChangedArgs& args) override;
108*38e8c45fSAndroid Build Coastguard Worker     void notifyKey(const NotifyKeyArgs& args) override;
109*38e8c45fSAndroid Build Coastguard Worker     void notifyMotion(const NotifyMotionArgs& args) override;
110*38e8c45fSAndroid Build Coastguard Worker     void notifySwitch(const NotifySwitchArgs& args) override;
111*38e8c45fSAndroid Build Coastguard Worker     void notifySensor(const NotifySensorArgs& args) override;
112*38e8c45fSAndroid Build Coastguard Worker     void notifyVibratorState(const NotifyVibratorStateArgs& args) override;
113*38e8c45fSAndroid Build Coastguard Worker     void notifyDeviceReset(const NotifyDeviceResetArgs& args) override;
114*38e8c45fSAndroid Build Coastguard Worker     void notifyPointerCaptureChanged(const NotifyPointerCaptureChangedArgs& args) override;
115*38e8c45fSAndroid Build Coastguard Worker 
116*38e8c45fSAndroid Build Coastguard Worker     // TODO(b/362719483) remove these when real topology is available
117*38e8c45fSAndroid Build Coastguard Worker     enum class DisplayPosition {
118*38e8c45fSAndroid Build Coastguard Worker         RIGHT,
119*38e8c45fSAndroid Build Coastguard Worker         TOP,
120*38e8c45fSAndroid Build Coastguard Worker         LEFT,
121*38e8c45fSAndroid Build Coastguard Worker         BOTTOM,
122*38e8c45fSAndroid Build Coastguard Worker         ftl_last = BOTTOM,
123*38e8c45fSAndroid Build Coastguard Worker     };
124*38e8c45fSAndroid Build Coastguard Worker 
125*38e8c45fSAndroid Build Coastguard Worker     struct AdjacentDisplay {
126*38e8c45fSAndroid Build Coastguard Worker         ui::LogicalDisplayId displayId;
127*38e8c45fSAndroid Build Coastguard Worker         DisplayPosition position;
128*38e8c45fSAndroid Build Coastguard Worker         float offsetPx;
129*38e8c45fSAndroid Build Coastguard Worker     };
130*38e8c45fSAndroid Build Coastguard Worker     void setDisplayTopology(
131*38e8c45fSAndroid Build Coastguard Worker             const std::unordered_map<ui::LogicalDisplayId, std::vector<AdjacentDisplay>>&
132*38e8c45fSAndroid Build Coastguard Worker                     displayTopology);
133*38e8c45fSAndroid Build Coastguard Worker 
134*38e8c45fSAndroid Build Coastguard Worker     void dump(std::string& dump) override;
135*38e8c45fSAndroid Build Coastguard Worker 
136*38e8c45fSAndroid Build Coastguard Worker private:
137*38e8c45fSAndroid Build Coastguard Worker     using PointerDisplayChange =
138*38e8c45fSAndroid Build Coastguard Worker             std::optional<std::tuple<ui::LogicalDisplayId /*displayId*/, vec2 /*cursorPosition*/>>;
139*38e8c45fSAndroid Build Coastguard Worker 
140*38e8c45fSAndroid Build Coastguard Worker     // PointerChoreographer's DisplayInfoListener can outlive the PointerChoreographer because when
141*38e8c45fSAndroid Build Coastguard Worker     // the listener is registered and called from display thread, a strong pointer to the listener
142*38e8c45fSAndroid Build Coastguard Worker     // (which can extend its lifecycle) is given away.
143*38e8c45fSAndroid Build Coastguard Worker     // If we use two locks it can also cause deadlocks due to race in acquiring them between the
144*38e8c45fSAndroid Build Coastguard Worker     // display and reader thread.
145*38e8c45fSAndroid Build Coastguard Worker     // To avoid these problems we use DisplayInfoListener's lock in PointerChoreographer.
146*38e8c45fSAndroid Build Coastguard Worker     std::mutex& getLock() const;
147*38e8c45fSAndroid Build Coastguard Worker 
148*38e8c45fSAndroid Build Coastguard Worker     [[nodiscard]] PointerDisplayChange updatePointerControllersLocked() REQUIRES(getLock());
149*38e8c45fSAndroid Build Coastguard Worker     [[nodiscard]] PointerDisplayChange calculatePointerDisplayChangeToNotify() REQUIRES(getLock());
150*38e8c45fSAndroid Build Coastguard Worker     const DisplayViewport* findViewportByIdLocked(ui::LogicalDisplayId displayId) const
151*38e8c45fSAndroid Build Coastguard Worker             REQUIRES(getLock());
152*38e8c45fSAndroid Build Coastguard Worker     ui::LogicalDisplayId getTargetMouseDisplayLocked(ui::LogicalDisplayId associatedDisplayId) const
153*38e8c45fSAndroid Build Coastguard Worker             REQUIRES(getLock());
154*38e8c45fSAndroid Build Coastguard Worker     std::pair<ui::LogicalDisplayId /*displayId*/, PointerControllerInterface&>
155*38e8c45fSAndroid Build Coastguard Worker     ensureMouseControllerLocked(ui::LogicalDisplayId associatedDisplayId) REQUIRES(getLock());
156*38e8c45fSAndroid Build Coastguard Worker     InputDeviceInfo* findInputDeviceLocked(DeviceId deviceId) REQUIRES(getLock());
157*38e8c45fSAndroid Build Coastguard Worker     bool canUnfadeOnDisplay(ui::LogicalDisplayId displayId) REQUIRES(getLock());
158*38e8c45fSAndroid Build Coastguard Worker 
159*38e8c45fSAndroid Build Coastguard Worker     void fadeMouseCursorOnKeyPress(const NotifyKeyArgs& args);
160*38e8c45fSAndroid Build Coastguard Worker     NotifyMotionArgs processMotion(const NotifyMotionArgs& args);
161*38e8c45fSAndroid Build Coastguard Worker     NotifyMotionArgs processMouseEventLocked(const NotifyMotionArgs& args) REQUIRES(getLock());
162*38e8c45fSAndroid Build Coastguard Worker     NotifyMotionArgs processTouchpadEventLocked(const NotifyMotionArgs& args) REQUIRES(getLock());
163*38e8c45fSAndroid Build Coastguard Worker     void processDrawingTabletEventLocked(const NotifyMotionArgs& args) REQUIRES(getLock());
164*38e8c45fSAndroid Build Coastguard Worker     void processTouchscreenAndStylusEventLocked(const NotifyMotionArgs& args) REQUIRES(getLock());
165*38e8c45fSAndroid Build Coastguard Worker     void processStylusHoverEventLocked(const NotifyMotionArgs& args) REQUIRES(getLock());
166*38e8c45fSAndroid Build Coastguard Worker     void processPointerDeviceMotionEventLocked(NotifyMotionArgs& newArgs,
167*38e8c45fSAndroid Build Coastguard Worker                                                PointerControllerInterface& pc) REQUIRES(getLock());
168*38e8c45fSAndroid Build Coastguard Worker     void processDeviceReset(const NotifyDeviceResetArgs& args);
169*38e8c45fSAndroid Build Coastguard Worker     void onControllerAddedOrRemovedLocked() REQUIRES(getLock());
170*38e8c45fSAndroid Build Coastguard Worker     void onPrivacySensitiveDisplaysChangedLocked(
171*38e8c45fSAndroid Build Coastguard Worker             const std::unordered_set<ui::LogicalDisplayId>& privacySensitiveDisplays)
172*38e8c45fSAndroid Build Coastguard Worker             REQUIRES(getLock());
173*38e8c45fSAndroid Build Coastguard Worker 
174*38e8c45fSAndroid Build Coastguard Worker     void handleUnconsumedDeltaLocked(PointerControllerInterface& pc, const vec2& unconsumedDelta)
175*38e8c45fSAndroid Build Coastguard Worker             REQUIRES(getLock());
176*38e8c45fSAndroid Build Coastguard Worker 
177*38e8c45fSAndroid Build Coastguard Worker     void populateFakeDisplayTopologyLocked(const std::vector<gui::DisplayInfo>& displayInfos)
178*38e8c45fSAndroid Build Coastguard Worker             REQUIRES(getLock());
179*38e8c45fSAndroid Build Coastguard Worker 
180*38e8c45fSAndroid Build Coastguard Worker     std::optional<std::pair<const DisplayViewport*, float /*offset*/>> findDestinationDisplayLocked(
181*38e8c45fSAndroid Build Coastguard Worker             const ui::LogicalDisplayId sourceDisplayId, const DisplayPosition sourceBoundary,
182*38e8c45fSAndroid Build Coastguard Worker             float cursorOffset) const REQUIRES(getLock());
183*38e8c45fSAndroid Build Coastguard Worker 
184*38e8c45fSAndroid Build Coastguard Worker     static vec2 calculateDestinationPosition(const DisplayViewport& destinationViewport,
185*38e8c45fSAndroid Build Coastguard Worker                                              float pointerOffset, DisplayPosition sourceBoundary);
186*38e8c45fSAndroid Build Coastguard Worker 
187*38e8c45fSAndroid Build Coastguard Worker     std::unordered_map<ui::LogicalDisplayId, std::vector<AdjacentDisplay>> mTopology
188*38e8c45fSAndroid Build Coastguard Worker             GUARDED_BY(getLock());
189*38e8c45fSAndroid Build Coastguard Worker 
190*38e8c45fSAndroid Build Coastguard Worker     /* This listener keeps tracks of visible privacy sensitive displays and updates the
191*38e8c45fSAndroid Build Coastguard Worker      * choreographer if there are any changes.
192*38e8c45fSAndroid Build Coastguard Worker      *
193*38e8c45fSAndroid Build Coastguard Worker      * Listener uses mListenerLock to guard all private data as choreographer and SurfaceComposer
194*38e8c45fSAndroid Build Coastguard Worker      * both can call into the listener. To prevent deadlocks Choreographer can call listener with
195*38e8c45fSAndroid Build Coastguard Worker      * its lock held, but listener must not call choreographer with its lock.
196*38e8c45fSAndroid Build Coastguard Worker      */
197*38e8c45fSAndroid Build Coastguard Worker     class PointerChoreographerDisplayInfoListener : public gui::WindowInfosListener {
198*38e8c45fSAndroid Build Coastguard Worker     public:
PointerChoreographerDisplayInfoListener(PointerChoreographer * pc)199*38e8c45fSAndroid Build Coastguard Worker         explicit PointerChoreographerDisplayInfoListener(PointerChoreographer* pc)
200*38e8c45fSAndroid Build Coastguard Worker               : mPointerChoreographer(pc){};
201*38e8c45fSAndroid Build Coastguard Worker         void onWindowInfosChanged(const gui::WindowInfosUpdate&) override;
202*38e8c45fSAndroid Build Coastguard Worker         void setInitialDisplayInfosLocked(const std::vector<gui::WindowInfo>& windowInfos)
203*38e8c45fSAndroid Build Coastguard Worker                 REQUIRES(mLock);
204*38e8c45fSAndroid Build Coastguard Worker         std::unordered_set<ui::LogicalDisplayId> getPrivacySensitiveDisplaysLocked()
205*38e8c45fSAndroid Build Coastguard Worker                 REQUIRES(mLock);
206*38e8c45fSAndroid Build Coastguard Worker         void onPointerChoreographerDestroyed();
207*38e8c45fSAndroid Build Coastguard Worker 
208*38e8c45fSAndroid Build Coastguard Worker         // This lock is also used by PointerChoreographer. See PointerChoreographer::getLock().
209*38e8c45fSAndroid Build Coastguard Worker         std::mutex mLock;
210*38e8c45fSAndroid Build Coastguard Worker 
211*38e8c45fSAndroid Build Coastguard Worker     private:
212*38e8c45fSAndroid Build Coastguard Worker         PointerChoreographer* mPointerChoreographer GUARDED_BY(mLock);
213*38e8c45fSAndroid Build Coastguard Worker         std::unordered_set<ui::LogicalDisplayId /*displayId*/> mPrivacySensitiveDisplays
214*38e8c45fSAndroid Build Coastguard Worker                 GUARDED_BY(mLock);
215*38e8c45fSAndroid Build Coastguard Worker     };
216*38e8c45fSAndroid Build Coastguard Worker 
217*38e8c45fSAndroid Build Coastguard Worker     using ControllerConstructor =
218*38e8c45fSAndroid Build Coastguard Worker             ConstructorDelegate<std::function<std::shared_ptr<PointerControllerInterface>()>>;
219*38e8c45fSAndroid Build Coastguard Worker     ControllerConstructor mTouchControllerConstructor GUARDED_BY(getLock());
220*38e8c45fSAndroid Build Coastguard Worker     ControllerConstructor getMouseControllerConstructor(ui::LogicalDisplayId displayId)
221*38e8c45fSAndroid Build Coastguard Worker             REQUIRES(getLock());
222*38e8c45fSAndroid Build Coastguard Worker     ControllerConstructor getStylusControllerConstructor(ui::LogicalDisplayId displayId)
223*38e8c45fSAndroid Build Coastguard Worker             REQUIRES(getLock());
224*38e8c45fSAndroid Build Coastguard Worker 
225*38e8c45fSAndroid Build Coastguard Worker     InputListenerInterface& mNextListener;
226*38e8c45fSAndroid Build Coastguard Worker     PointerChoreographerPolicyInterface& mPolicy;
227*38e8c45fSAndroid Build Coastguard Worker 
228*38e8c45fSAndroid Build Coastguard Worker     std::map<ui::LogicalDisplayId, std::shared_ptr<PointerControllerInterface>>
229*38e8c45fSAndroid Build Coastguard Worker             mMousePointersByDisplay GUARDED_BY(getLock());
230*38e8c45fSAndroid Build Coastguard Worker     std::map<DeviceId, std::shared_ptr<PointerControllerInterface>> mTouchPointersByDevice
231*38e8c45fSAndroid Build Coastguard Worker             GUARDED_BY(getLock());
232*38e8c45fSAndroid Build Coastguard Worker     std::map<DeviceId, std::shared_ptr<PointerControllerInterface>> mStylusPointersByDevice
233*38e8c45fSAndroid Build Coastguard Worker             GUARDED_BY(getLock());
234*38e8c45fSAndroid Build Coastguard Worker     std::map<DeviceId, std::shared_ptr<PointerControllerInterface>> mDrawingTabletPointersByDevice
235*38e8c45fSAndroid Build Coastguard Worker             GUARDED_BY(getLock());
236*38e8c45fSAndroid Build Coastguard Worker 
237*38e8c45fSAndroid Build Coastguard Worker     ui::LogicalDisplayId mDefaultMouseDisplayId GUARDED_BY(getLock());
238*38e8c45fSAndroid Build Coastguard Worker     ui::LogicalDisplayId mNotifiedPointerDisplayId GUARDED_BY(getLock());
239*38e8c45fSAndroid Build Coastguard Worker     std::vector<InputDeviceInfo> mInputDeviceInfos GUARDED_BY(getLock());
240*38e8c45fSAndroid Build Coastguard Worker     std::set<DeviceId> mMouseDevices GUARDED_BY(getLock());
241*38e8c45fSAndroid Build Coastguard Worker     std::vector<DisplayViewport> mViewports GUARDED_BY(getLock());
242*38e8c45fSAndroid Build Coastguard Worker     bool mShowTouchesEnabled GUARDED_BY(getLock());
243*38e8c45fSAndroid Build Coastguard Worker     bool mStylusPointerIconEnabled GUARDED_BY(getLock());
244*38e8c45fSAndroid Build Coastguard Worker     std::set<ui::LogicalDisplayId /*displayId*/> mDisplaysWithPointersHidden;
245*38e8c45fSAndroid Build Coastguard Worker     ui::LogicalDisplayId mCurrentFocusedDisplay GUARDED_BY(getLock());
246*38e8c45fSAndroid Build Coastguard Worker 
247*38e8c45fSAndroid Build Coastguard Worker protected:
248*38e8c45fSAndroid Build Coastguard Worker     using WindowListenerRegisterConsumer = std::function<std::vector<gui::WindowInfo>(
249*38e8c45fSAndroid Build Coastguard Worker             const sp<android::gui::WindowInfosListener>&)>;
250*38e8c45fSAndroid Build Coastguard Worker     using WindowListenerUnregisterConsumer =
251*38e8c45fSAndroid Build Coastguard Worker             std::function<void(const sp<android::gui::WindowInfosListener>&)>;
252*38e8c45fSAndroid Build Coastguard Worker     explicit PointerChoreographer(InputListenerInterface& listener,
253*38e8c45fSAndroid Build Coastguard Worker                                   PointerChoreographerPolicyInterface&,
254*38e8c45fSAndroid Build Coastguard Worker                                   const WindowListenerRegisterConsumer& registerListener,
255*38e8c45fSAndroid Build Coastguard Worker                                   const WindowListenerUnregisterConsumer& unregisterListener);
256*38e8c45fSAndroid Build Coastguard Worker 
257*38e8c45fSAndroid Build Coastguard Worker private:
258*38e8c45fSAndroid Build Coastguard Worker     // WindowInfoListener object should always exist while PointerChoreographer exists, because we
259*38e8c45fSAndroid Build Coastguard Worker     // need to use the lock from it. But we don't always need to register the listener.
260*38e8c45fSAndroid Build Coastguard Worker     bool mIsWindowInfoListenerRegistered GUARDED_BY(getLock());
261*38e8c45fSAndroid Build Coastguard Worker     const sp<PointerChoreographerDisplayInfoListener> mWindowInfoListener;
262*38e8c45fSAndroid Build Coastguard Worker     const WindowListenerRegisterConsumer mRegisterListener;
263*38e8c45fSAndroid Build Coastguard Worker     const WindowListenerUnregisterConsumer mUnregisterListener;
264*38e8c45fSAndroid Build Coastguard Worker };
265*38e8c45fSAndroid Build Coastguard Worker 
266*38e8c45fSAndroid Build Coastguard Worker } // namespace android
267